fp@673: /*******************************************************************************
fp@673: 
fp@673:   
fp@673:   Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
fp@673:   
fp@673:   This program is free software; you can redistribute it and/or modify it 
fp@673:   under the terms of the GNU General Public License as published by the Free 
fp@673:   Software Foundation; either version 2 of the License, or (at your option) 
fp@673:   any later version.
fp@673:   
fp@673:   This program is distributed in the hope that it will be useful, but WITHOUT 
fp@673:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
fp@673:   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
fp@673:   more details.
fp@673:   
fp@673:   You should have received a copy of the GNU General Public License along with
fp@673:   this program; if not, write to the Free Software Foundation, Inc., 59 
fp@673:   Temple Place - Suite 330, Boston, MA  02111-1307, USA.
fp@673:   
fp@673:   The full GNU General Public License is included in this distribution in the
fp@673:   file called LICENSE.
fp@673:   
fp@673:   Contact Information:
fp@673:   Linux NICS <linux.nics@intel.com>
fp@673:   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
fp@673: 
fp@673: *******************************************************************************/
fp@673: 
fp@673: #include "e1000-2.6.13-ethercat.h"
fp@673: 
fp@673: /* This is the only thing that needs to be changed to adjust the
fp@673:  * maximum number of ports that the driver can manage.
fp@673:  */
fp@673: 
fp@673: #define E1000_MAX_NIC 32
fp@673: 
fp@673: #define OPTION_UNSET   -1
fp@673: #define OPTION_DISABLED 0
fp@673: #define OPTION_ENABLED  1
fp@673: 
fp@673: /* All parameters are treated the same, as an integer array of values.
fp@673:  * This macro just reduces the need to repeat the same declaration code
fp@673:  * over and over (plus this helps to avoid typo bugs).
fp@673:  */
fp@673: 
fp@673: #define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
fp@673: #define E1000_PARAM(X, desc) \
fp@673: 	static int __devinitdata X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
fp@673: 	static int num_##X = 0; \
fp@673: 	module_param_array_named(X, X, int, &num_##X, 0); \
fp@673: 	MODULE_PARM_DESC(X, desc);
fp@673: 
fp@673: /* Transmit Descriptor Count
fp@673:  *
fp@673:  * Valid Range: 80-256 for 82542 and 82543 gigabit ethernet controllers
fp@673:  * Valid Range: 80-4096 for 82544 and newer
fp@673:  *
fp@673:  * Default Value: 256
fp@673:  */
fp@673: 
fp@673: E1000_PARAM(TxDescriptors, "Number of transmit descriptors");
fp@673: 
fp@673: /* Receive Descriptor Count
fp@673:  *
fp@673:  * Valid Range: 80-256 for 82542 and 82543 gigabit ethernet controllers
fp@673:  * Valid Range: 80-4096 for 82544 and newer
fp@673:  *
fp@673:  * Default Value: 256
fp@673:  */
fp@673: 
fp@673: E1000_PARAM(RxDescriptors, "Number of receive descriptors");
fp@673: 
fp@673: /* User Specified Speed Override
fp@673:  *
fp@673:  * Valid Range: 0, 10, 100, 1000
fp@673:  *  - 0    - auto-negotiate at all supported speeds
fp@673:  *  - 10   - only link at 10 Mbps
fp@673:  *  - 100  - only link at 100 Mbps
fp@673:  *  - 1000 - only link at 1000 Mbps
fp@673:  *
fp@673:  * Default Value: 0
fp@673:  */
fp@673: 
fp@673: E1000_PARAM(Speed, "Speed setting");
fp@673: 
fp@673: /* User Specified Duplex Override
fp@673:  *
fp@673:  * Valid Range: 0-2
fp@673:  *  - 0 - auto-negotiate for duplex
fp@673:  *  - 1 - only link at half duplex
fp@673:  *  - 2 - only link at full duplex
fp@673:  *
fp@673:  * Default Value: 0
fp@673:  */
fp@673: 
fp@673: E1000_PARAM(Duplex, "Duplex setting");
fp@673: 
fp@673: /* Auto-negotiation Advertisement Override
fp@673:  *
fp@673:  * Valid Range: 0x01-0x0F, 0x20-0x2F (copper); 0x20 (fiber)
fp@673:  *
fp@673:  * The AutoNeg value is a bit mask describing which speed and duplex
fp@673:  * combinations should be advertised during auto-negotiation.
fp@673:  * The supported speed and duplex modes are listed below
fp@673:  *
fp@673:  * Bit           7     6     5      4      3     2     1      0
fp@673:  * Speed (Mbps)  N/A   N/A   1000   N/A    100   100   10     10
fp@673:  * Duplex                    Full          Full  Half  Full   Half
fp@673:  *
fp@673:  * Default Value: 0x2F (copper); 0x20 (fiber)
fp@673:  */
fp@673: 
fp@673: E1000_PARAM(AutoNeg, "Advertised auto-negotiation setting");
fp@673: 
fp@673: /* User Specified Flow Control Override
fp@673:  *
fp@673:  * Valid Range: 0-3
fp@673:  *  - 0 - No Flow Control
fp@673:  *  - 1 - Rx only, respond to PAUSE frames but do not generate them
fp@673:  *  - 2 - Tx only, generate PAUSE frames but ignore them on receive
fp@673:  *  - 3 - Full Flow Control Support
fp@673:  *
fp@673:  * Default Value: Read flow control settings from the EEPROM
fp@673:  */
fp@673: 
fp@673: E1000_PARAM(FlowControl, "Flow Control setting");
fp@673: 
fp@673: /* XsumRX - Receive Checksum Offload Enable/Disable
fp@673:  *
fp@673:  * Valid Range: 0, 1
fp@673:  *  - 0 - disables all checksum offload
fp@673:  *  - 1 - enables receive IP/TCP/UDP checksum offload
fp@673:  *        on 82543 and newer -based NICs
fp@673:  *
fp@673:  * Default Value: 1
fp@673:  */
fp@673: 
fp@673: E1000_PARAM(XsumRX, "Disable or enable Receive Checksum offload");
fp@673: 
fp@673: /* Transmit Interrupt Delay in units of 1.024 microseconds
fp@673:  *
fp@673:  * Valid Range: 0-65535
fp@673:  *
fp@673:  * Default Value: 64
fp@673:  */
fp@673: 
fp@673: E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
fp@673: 
fp@673: /* Transmit Absolute Interrupt Delay in units of 1.024 microseconds
fp@673:  *
fp@673:  * Valid Range: 0-65535
fp@673:  *
fp@673:  * Default Value: 0
fp@673:  */
fp@673: 
fp@673: E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
fp@673: 
fp@673: /* Receive Interrupt Delay in units of 1.024 microseconds
fp@673:  *
fp@673:  * Valid Range: 0-65535
fp@673:  *
fp@673:  * Default Value: 0
fp@673:  */
fp@673: 
fp@673: E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
fp@673: 
fp@673: /* Receive Absolute Interrupt Delay in units of 1.024 microseconds
fp@673:  *
fp@673:  * Valid Range: 0-65535
fp@673:  *
fp@673:  * Default Value: 128
fp@673:  */
fp@673: 
fp@673: E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
fp@673: 
fp@673: /* Interrupt Throttle Rate (interrupts/sec)
fp@673:  *
fp@673:  * Valid Range: 100-100000 (0=off, 1=dynamic)
fp@673:  *
fp@673:  * Default Value: 1
fp@673:  */
fp@673: 
fp@673: E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
fp@673: 
fp@673: #define AUTONEG_ADV_DEFAULT  0x2F
fp@673: #define AUTONEG_ADV_MASK     0x2F
fp@673: #define FLOW_CONTROL_DEFAULT FLOW_CONTROL_FULL
fp@673: 
fp@673: #define DEFAULT_RDTR                   0
fp@673: #define MAX_RXDELAY               0xFFFF
fp@673: #define MIN_RXDELAY                    0
fp@673: 
fp@673: #define DEFAULT_RADV                 128
fp@673: #define MAX_RXABSDELAY            0xFFFF
fp@673: #define MIN_RXABSDELAY                 0
fp@673: 
fp@673: #define DEFAULT_TIDV                  64
fp@673: #define MAX_TXDELAY               0xFFFF
fp@673: #define MIN_TXDELAY                    0
fp@673: 
fp@673: #define DEFAULT_TADV                  64
fp@673: #define MAX_TXABSDELAY            0xFFFF
fp@673: #define MIN_TXABSDELAY                 0
fp@673: 
fp@673: #define DEFAULT_ITR                 8000
fp@673: #define MAX_ITR                   100000
fp@673: #define MIN_ITR                      100
fp@673: 
fp@673: struct e1000_option {
fp@673: 	enum { enable_option, range_option, list_option } type;
fp@673: 	char *name;
fp@673: 	char *err;
fp@673: 	int  def;
fp@673: 	union {
fp@673: 		struct { /* range_option info */
fp@673: 			int min;
fp@673: 			int max;
fp@673: 		} r;
fp@673: 		struct { /* list_option info */
fp@673: 			int nr;
fp@673: 			struct e1000_opt_list { int i; char *str; } *p;
fp@673: 		} l;
fp@673: 	} arg;
fp@673: };
fp@673: 
fp@673: static int __devinit
fp@673: e1000_validate_option(int *value, struct e1000_option *opt,
fp@673: 		struct e1000_adapter *adapter)
fp@673: {
fp@673: 	if(*value == OPTION_UNSET) {
fp@673: 		*value = opt->def;
fp@673: 		return 0;
fp@673: 	}
fp@673: 
fp@673: 	switch (opt->type) {
fp@673: 	case enable_option:
fp@673: 		switch (*value) {
fp@673: 		case OPTION_ENABLED:
fp@673: 			DPRINTK(PROBE, INFO, "%s Enabled\n", opt->name);
fp@673: 			return 0;
fp@673: 		case OPTION_DISABLED:
fp@673: 			DPRINTK(PROBE, INFO, "%s Disabled\n", opt->name);
fp@673: 			return 0;
fp@673: 		}
fp@673: 		break;
fp@673: 	case range_option:
fp@673: 		if(*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
fp@673: 			DPRINTK(PROBE, INFO,
fp@673: 					"%s set to %i\n", opt->name, *value);
fp@673: 			return 0;
fp@673: 		}
fp@673: 		break;
fp@673: 	case list_option: {
fp@673: 		int i;
fp@673: 		struct e1000_opt_list *ent;
fp@673: 
fp@673: 		for(i = 0; i < opt->arg.l.nr; i++) {
fp@673: 			ent = &opt->arg.l.p[i];
fp@673: 			if(*value == ent->i) {
fp@673: 				if(ent->str[0] != '\0')
fp@673: 					DPRINTK(PROBE, INFO, "%s\n", ent->str);
fp@673: 				return 0;
fp@673: 			}
fp@673: 		}
fp@673: 	}
fp@673: 		break;
fp@673: 	default:
fp@673: 		BUG();
fp@673: 	}
fp@673: 
fp@673: 	DPRINTK(PROBE, INFO, "Invalid %s specified (%i) %s\n",
fp@673: 	       opt->name, *value, opt->err);
fp@673: 	*value = opt->def;
fp@673: 	return -1;
fp@673: }
fp@673: 
fp@673: static void e1000_check_fiber_options(struct e1000_adapter *adapter);
fp@673: static void e1000_check_copper_options(struct e1000_adapter *adapter);
fp@673: 
fp@673: /**
fp@673:  * e1000_check_options - Range Checking for Command Line Parameters
fp@673:  * @adapter: board private structure
fp@673:  *
fp@673:  * This routine checks all command line parameters for valid user
fp@673:  * input.  If an invalid value is given, or if no user specified
fp@673:  * value exists, a default value is used.  The final value is stored
fp@673:  * in a variable in the adapter structure.
fp@673:  **/
fp@673: 
fp@673: void __devinit
fp@673: e1000_check_options(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	int bd = adapter->bd_number;
fp@673: 	if(bd >= E1000_MAX_NIC) {
fp@673: 		DPRINTK(PROBE, NOTICE,
fp@673: 		       "Warning: no configuration for board #%i\n", bd);
fp@673: 		DPRINTK(PROBE, NOTICE, "Using defaults for all values\n");
fp@673: 	}
fp@673: 
fp@673: 	{ /* Transmit Descriptor Count */
fp@673: 		struct e1000_option opt = {
fp@673: 			.type = range_option,
fp@673: 			.name = "Transmit Descriptors",
fp@673: 			.err  = "using default of "
fp@673: 				__MODULE_STRING(E1000_DEFAULT_TXD),
fp@673: 			.def  = E1000_DEFAULT_TXD,
fp@673: 			.arg  = { .r = { .min = E1000_MIN_TXD }}
fp@673: 		};
fp@673: 		struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
fp@673: 		e1000_mac_type mac_type = adapter->hw.mac_type;
fp@673: 		opt.arg.r.max = mac_type < e1000_82544 ?
fp@673: 			E1000_MAX_TXD : E1000_MAX_82544_TXD;
fp@673: 
fp@673: 		if (num_TxDescriptors > bd) {
fp@673: 			tx_ring->count = TxDescriptors[bd];
fp@673: 			e1000_validate_option(&tx_ring->count, &opt, adapter);
fp@673: 			E1000_ROUNDUP(tx_ring->count, 
fp@673: 						REQ_TX_DESCRIPTOR_MULTIPLE);
fp@673: 		} else {
fp@673: 			tx_ring->count = opt.def;
fp@673: 		}
fp@673: 	}
fp@673: 	{ /* Receive Descriptor Count */
fp@673: 		struct e1000_option opt = {
fp@673: 			.type = range_option,
fp@673: 			.name = "Receive Descriptors",
fp@673: 			.err  = "using default of "
fp@673: 				__MODULE_STRING(E1000_DEFAULT_RXD),
fp@673: 			.def  = E1000_DEFAULT_RXD,
fp@673: 			.arg  = { .r = { .min = E1000_MIN_RXD }}
fp@673: 		};
fp@673: 		struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
fp@673: 		e1000_mac_type mac_type = adapter->hw.mac_type;
fp@673: 		opt.arg.r.max = mac_type < e1000_82544 ? E1000_MAX_RXD :
fp@673: 			E1000_MAX_82544_RXD;
fp@673: 
fp@673: 		if (num_RxDescriptors > bd) {
fp@673: 			rx_ring->count = RxDescriptors[bd];
fp@673: 			e1000_validate_option(&rx_ring->count, &opt, adapter);
fp@673: 			E1000_ROUNDUP(rx_ring->count, 
fp@673: 						REQ_RX_DESCRIPTOR_MULTIPLE);
fp@673: 		} else {
fp@673: 			rx_ring->count = opt.def;
fp@673: 		}
fp@673: 	}
fp@673: 	{ /* Checksum Offload Enable/Disable */
fp@673: 		struct e1000_option opt = {
fp@673: 			.type = enable_option,
fp@673: 			.name = "Checksum Offload",
fp@673: 			.err  = "defaulting to Enabled",
fp@673: 			.def  = OPTION_ENABLED
fp@673: 		};
fp@673: 
fp@673: 		if (num_XsumRX > bd) {
fp@673: 			int rx_csum = XsumRX[bd];
fp@673: 			e1000_validate_option(&rx_csum, &opt, adapter);
fp@673: 			adapter->rx_csum = rx_csum;
fp@673: 		} else {
fp@673: 			adapter->rx_csum = opt.def;
fp@673: 		}
fp@673: 	}
fp@673: 	{ /* Flow Control */
fp@673: 
fp@673: 		struct e1000_opt_list fc_list[] =
fp@673: 			{{ e1000_fc_none,    "Flow Control Disabled" },
fp@673: 			 { e1000_fc_rx_pause,"Flow Control Receive Only" },
fp@673: 			 { e1000_fc_tx_pause,"Flow Control Transmit Only" },
fp@673: 			 { e1000_fc_full,    "Flow Control Enabled" },
fp@673: 			 { e1000_fc_default, "Flow Control Hardware Default" }};
fp@673: 
fp@673: 		struct e1000_option opt = {
fp@673: 			.type = list_option,
fp@673: 			.name = "Flow Control",
fp@673: 			.err  = "reading default settings from EEPROM",
fp@673: 			.def  = e1000_fc_default,
fp@673: 			.arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
fp@673: 					 .p = fc_list }}
fp@673: 		};
fp@673: 
fp@673: 		if (num_FlowControl > bd) {
fp@673: 			int fc = FlowControl[bd];
fp@673: 			e1000_validate_option(&fc, &opt, adapter);
fp@673: 			adapter->hw.fc = adapter->hw.original_fc = fc;
fp@673: 		} else {
fp@673: 			adapter->hw.fc = opt.def;
fp@673: 		}
fp@673: 	}
fp@673: 	{ /* Transmit Interrupt Delay */
fp@673: 		struct e1000_option opt = {
fp@673: 			.type = range_option,
fp@673: 			.name = "Transmit Interrupt Delay",
fp@673: 			.err  = "using default of " __MODULE_STRING(DEFAULT_TIDV),
fp@673: 			.def  = DEFAULT_TIDV,
fp@673: 			.arg  = { .r = { .min = MIN_TXDELAY,
fp@673: 					 .max = MAX_TXDELAY }}
fp@673: 		};
fp@673: 
fp@673: 		if (num_TxIntDelay > bd) {
fp@673: 			adapter->tx_int_delay = TxIntDelay[bd];
fp@673: 			e1000_validate_option(&adapter->tx_int_delay, &opt, 
fp@673: 								adapter);
fp@673: 		} else {
fp@673: 			adapter->tx_int_delay = opt.def;
fp@673: 		}
fp@673: 	}
fp@673: 	{ /* Transmit Absolute Interrupt Delay */
fp@673: 		struct e1000_option opt = {
fp@673: 			.type = range_option,
fp@673: 			.name = "Transmit Absolute Interrupt Delay",
fp@673: 			.err  = "using default of " __MODULE_STRING(DEFAULT_TADV),
fp@673: 			.def  = DEFAULT_TADV,
fp@673: 			.arg  = { .r = { .min = MIN_TXABSDELAY,
fp@673: 					 .max = MAX_TXABSDELAY }}
fp@673: 		};
fp@673: 
fp@673: 		if (num_TxAbsIntDelay > bd) {
fp@673: 			adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
fp@673: 			e1000_validate_option(&adapter->tx_abs_int_delay, &opt, 
fp@673: 								adapter);
fp@673: 		} else {
fp@673: 			adapter->tx_abs_int_delay = opt.def;
fp@673: 		}
fp@673: 	}
fp@673: 	{ /* Receive Interrupt Delay */
fp@673: 		struct e1000_option opt = {
fp@673: 			.type = range_option,
fp@673: 			.name = "Receive Interrupt Delay",
fp@673: 			.err  = "using default of " __MODULE_STRING(DEFAULT_RDTR),
fp@673: 			.def  = DEFAULT_RDTR,
fp@673: 			.arg  = { .r = { .min = MIN_RXDELAY,
fp@673: 					 .max = MAX_RXDELAY }}
fp@673: 		};
fp@673: 
fp@673: 		if (num_RxIntDelay > bd) {
fp@673: 			adapter->rx_int_delay = RxIntDelay[bd];
fp@673: 			e1000_validate_option(&adapter->rx_int_delay, &opt, 
fp@673: 								adapter);
fp@673: 		} else {
fp@673: 			adapter->rx_int_delay = opt.def;
fp@673: 		}
fp@673: 	}
fp@673: 	{ /* Receive Absolute Interrupt Delay */
fp@673: 		struct e1000_option opt = {
fp@673: 			.type = range_option,
fp@673: 			.name = "Receive Absolute Interrupt Delay",
fp@673: 			.err  = "using default of " __MODULE_STRING(DEFAULT_RADV),
fp@673: 			.def  = DEFAULT_RADV,
fp@673: 			.arg  = { .r = { .min = MIN_RXABSDELAY,
fp@673: 					 .max = MAX_RXABSDELAY }}
fp@673: 		};
fp@673: 
fp@673: 		if (num_RxAbsIntDelay > bd) {
fp@673: 			adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
fp@673: 			e1000_validate_option(&adapter->rx_abs_int_delay, &opt, 
fp@673: 								adapter);
fp@673: 		} else {
fp@673: 			adapter->rx_abs_int_delay = opt.def;
fp@673: 		}
fp@673: 	}
fp@673: 	{ /* Interrupt Throttling Rate */
fp@673: 		struct e1000_option opt = {
fp@673: 			.type = range_option,
fp@673: 			.name = "Interrupt Throttling Rate (ints/sec)",
fp@673: 			.err  = "using default of " __MODULE_STRING(DEFAULT_ITR),
fp@673: 			.def  = DEFAULT_ITR,
fp@673: 			.arg  = { .r = { .min = MIN_ITR,
fp@673: 					 .max = MAX_ITR }}
fp@673: 		};
fp@673: 
fp@673: 		if (num_InterruptThrottleRate > bd) {
fp@673: 			adapter->itr = InterruptThrottleRate[bd];
fp@673: 			switch(adapter->itr) {
fp@673: 			case 0:
fp@673: 				DPRINTK(PROBE, INFO, "%s turned off\n", 
fp@673: 					opt.name);
fp@673: 				break;
fp@673: 			case 1:
fp@673: 				DPRINTK(PROBE, INFO, "%s set to dynamic mode\n", 
fp@673: 					opt.name);
fp@673: 				break;
fp@673: 			default:
fp@673: 				e1000_validate_option(&adapter->itr, &opt, 
fp@673: 					adapter);
fp@673: 				break;
fp@673: 			}
fp@673: 		} else {
fp@673: 			adapter->itr = opt.def;
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: 	switch(adapter->hw.media_type) {
fp@673: 	case e1000_media_type_fiber:
fp@673: 	case e1000_media_type_internal_serdes:
fp@673: 		e1000_check_fiber_options(adapter);
fp@673: 		break;
fp@673: 	case e1000_media_type_copper:
fp@673: 		e1000_check_copper_options(adapter);
fp@673: 		break;
fp@673: 	default:
fp@673: 		BUG();
fp@673: 	}
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_check_fiber_options - Range Checking for Link Options, Fiber Version
fp@673:  * @adapter: board private structure
fp@673:  *
fp@673:  * Handles speed and duplex options on fiber adapters
fp@673:  **/
fp@673: 
fp@673: static void __devinit
fp@673: e1000_check_fiber_options(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	int bd = adapter->bd_number;
fp@673: 	if(num_Speed > bd) {
fp@673: 		DPRINTK(PROBE, INFO, "Speed not valid for fiber adapters, "
fp@673: 		       "parameter ignored\n");
fp@673: 	}
fp@673: 
fp@673: 	if(num_Duplex > bd) {
fp@673: 		DPRINTK(PROBE, INFO, "Duplex not valid for fiber adapters, "
fp@673: 		       "parameter ignored\n");
fp@673: 	}
fp@673: 
fp@673: 	if((num_AutoNeg > bd) && (AutoNeg[bd] != 0x20)) {
fp@673: 		DPRINTK(PROBE, INFO, "AutoNeg other than 1000/Full is "
fp@673: 				 "not valid for fiber adapters, "
fp@673: 				 "parameter ignored\n");
fp@673: 	}
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_check_copper_options - Range Checking for Link Options, Copper Version
fp@673:  * @adapter: board private structure
fp@673:  *
fp@673:  * Handles speed and duplex options on copper adapters
fp@673:  **/
fp@673: 
fp@673: static void __devinit
fp@673: e1000_check_copper_options(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	int speed, dplx;
fp@673: 	int bd = adapter->bd_number;
fp@673: 
fp@673: 	{ /* Speed */
fp@673: 		struct e1000_opt_list speed_list[] = {{          0, "" },
fp@673: 						      {   SPEED_10, "" },
fp@673: 						      {  SPEED_100, "" },
fp@673: 						      { SPEED_1000, "" }};
fp@673: 
fp@673: 		struct e1000_option opt = {
fp@673: 			.type = list_option,
fp@673: 			.name = "Speed",
fp@673: 			.err  = "parameter ignored",
fp@673: 			.def  = 0,
fp@673: 			.arg  = { .l = { .nr = ARRAY_SIZE(speed_list),
fp@673: 					 .p = speed_list }}
fp@673: 		};
fp@673: 
fp@673: 		if (num_Speed > bd) {
fp@673: 			speed = Speed[bd];
fp@673: 			e1000_validate_option(&speed, &opt, adapter);
fp@673: 		} else {
fp@673: 			speed = opt.def;
fp@673: 		}
fp@673: 	}
fp@673: 	{ /* Duplex */
fp@673: 		struct e1000_opt_list dplx_list[] = {{           0, "" },
fp@673: 						     { HALF_DUPLEX, "" },
fp@673: 						     { FULL_DUPLEX, "" }};
fp@673: 
fp@673: 		struct e1000_option opt = {
fp@673: 			.type = list_option,
fp@673: 			.name = "Duplex",
fp@673: 			.err  = "parameter ignored",
fp@673: 			.def  = 0,
fp@673: 			.arg  = { .l = { .nr = ARRAY_SIZE(dplx_list),
fp@673: 					 .p = dplx_list }}
fp@673: 		};
fp@673: 
fp@673: 		if (num_Duplex > bd) {
fp@673: 			dplx = Duplex[bd];
fp@673: 			e1000_validate_option(&dplx, &opt, adapter);
fp@673: 		} else {
fp@673: 			dplx = opt.def;
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: 	if((num_AutoNeg > bd) && (speed != 0 || dplx != 0)) {
fp@673: 		DPRINTK(PROBE, INFO,
fp@673: 		       "AutoNeg specified along with Speed or Duplex, "
fp@673: 		       "parameter ignored\n");
fp@673: 		adapter->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT;
fp@673: 	} else { /* Autoneg */
fp@673: 		struct e1000_opt_list an_list[] =
fp@673: 			#define AA "AutoNeg advertising "
fp@673: 			{{ 0x01, AA "10/HD" },
fp@673: 			 { 0x02, AA "10/FD" },
fp@673: 			 { 0x03, AA "10/FD, 10/HD" },
fp@673: 			 { 0x04, AA "100/HD" },
fp@673: 			 { 0x05, AA "100/HD, 10/HD" },
fp@673: 			 { 0x06, AA "100/HD, 10/FD" },
fp@673: 			 { 0x07, AA "100/HD, 10/FD, 10/HD" },
fp@673: 			 { 0x08, AA "100/FD" },
fp@673: 			 { 0x09, AA "100/FD, 10/HD" },
fp@673: 			 { 0x0a, AA "100/FD, 10/FD" },
fp@673: 			 { 0x0b, AA "100/FD, 10/FD, 10/HD" },
fp@673: 			 { 0x0c, AA "100/FD, 100/HD" },
fp@673: 			 { 0x0d, AA "100/FD, 100/HD, 10/HD" },
fp@673: 			 { 0x0e, AA "100/FD, 100/HD, 10/FD" },
fp@673: 			 { 0x0f, AA "100/FD, 100/HD, 10/FD, 10/HD" },
fp@673: 			 { 0x20, AA "1000/FD" },
fp@673: 			 { 0x21, AA "1000/FD, 10/HD" },
fp@673: 			 { 0x22, AA "1000/FD, 10/FD" },
fp@673: 			 { 0x23, AA "1000/FD, 10/FD, 10/HD" },
fp@673: 			 { 0x24, AA "1000/FD, 100/HD" },
fp@673: 			 { 0x25, AA "1000/FD, 100/HD, 10/HD" },
fp@673: 			 { 0x26, AA "1000/FD, 100/HD, 10/FD" },
fp@673: 			 { 0x27, AA "1000/FD, 100/HD, 10/FD, 10/HD" },
fp@673: 			 { 0x28, AA "1000/FD, 100/FD" },
fp@673: 			 { 0x29, AA "1000/FD, 100/FD, 10/HD" },
fp@673: 			 { 0x2a, AA "1000/FD, 100/FD, 10/FD" },
fp@673: 			 { 0x2b, AA "1000/FD, 100/FD, 10/FD, 10/HD" },
fp@673: 			 { 0x2c, AA "1000/FD, 100/FD, 100/HD" },
fp@673: 			 { 0x2d, AA "1000/FD, 100/FD, 100/HD, 10/HD" },
fp@673: 			 { 0x2e, AA "1000/FD, 100/FD, 100/HD, 10/FD" },
fp@673: 			 { 0x2f, AA "1000/FD, 100/FD, 100/HD, 10/FD, 10/HD" }};
fp@673: 
fp@673: 		struct e1000_option opt = {
fp@673: 			.type = list_option,
fp@673: 			.name = "AutoNeg",
fp@673: 			.err  = "parameter ignored",
fp@673: 			.def  = AUTONEG_ADV_DEFAULT,
fp@673: 			.arg  = { .l = { .nr = ARRAY_SIZE(an_list),
fp@673: 					 .p = an_list }}
fp@673: 		};
fp@673: 
fp@673: 		int an = AutoNeg[bd];
fp@673: 		e1000_validate_option(&an, &opt, adapter);
fp@673: 		adapter->hw.autoneg_advertised = an;
fp@673: 	}
fp@673: 
fp@673: 	switch (speed + dplx) {
fp@673: 	case 0:
fp@673: 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
fp@673: 		if((num_Speed > bd) && (speed != 0 || dplx != 0))
fp@673: 			DPRINTK(PROBE, INFO,
fp@673: 			       "Speed and duplex autonegotiation enabled\n");
fp@673: 		break;
fp@673: 	case HALF_DUPLEX:
fp@673: 		DPRINTK(PROBE, INFO, "Half Duplex specified without Speed\n");
fp@673: 		DPRINTK(PROBE, INFO, "Using Autonegotiation at "
fp@673: 			"Half Duplex only\n");
fp@673: 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
fp@673: 		adapter->hw.autoneg_advertised = ADVERTISE_10_HALF |
fp@673: 		                                 ADVERTISE_100_HALF;
fp@673: 		break;
fp@673: 	case FULL_DUPLEX:
fp@673: 		DPRINTK(PROBE, INFO, "Full Duplex specified without Speed\n");
fp@673: 		DPRINTK(PROBE, INFO, "Using Autonegotiation at "
fp@673: 			"Full Duplex only\n");
fp@673: 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
fp@673: 		adapter->hw.autoneg_advertised = ADVERTISE_10_FULL |
fp@673: 		                                 ADVERTISE_100_FULL |
fp@673: 		                                 ADVERTISE_1000_FULL;
fp@673: 		break;
fp@673: 	case SPEED_10:
fp@673: 		DPRINTK(PROBE, INFO, "10 Mbps Speed specified "
fp@673: 			"without Duplex\n");
fp@673: 		DPRINTK(PROBE, INFO, "Using Autonegotiation at 10 Mbps only\n");
fp@673: 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
fp@673: 		adapter->hw.autoneg_advertised = ADVERTISE_10_HALF |
fp@673: 		                                 ADVERTISE_10_FULL;
fp@673: 		break;
fp@673: 	case SPEED_10 + HALF_DUPLEX:
fp@673: 		DPRINTK(PROBE, INFO, "Forcing to 10 Mbps Half Duplex\n");
fp@673: 		adapter->hw.autoneg = adapter->fc_autoneg = 0;
fp@673: 		adapter->hw.forced_speed_duplex = e1000_10_half;
fp@673: 		adapter->hw.autoneg_advertised = 0;
fp@673: 		break;
fp@673: 	case SPEED_10 + FULL_DUPLEX:
fp@673: 		DPRINTK(PROBE, INFO, "Forcing to 10 Mbps Full Duplex\n");
fp@673: 		adapter->hw.autoneg = adapter->fc_autoneg = 0;
fp@673: 		adapter->hw.forced_speed_duplex = e1000_10_full;
fp@673: 		adapter->hw.autoneg_advertised = 0;
fp@673: 		break;
fp@673: 	case SPEED_100:
fp@673: 		DPRINTK(PROBE, INFO, "100 Mbps Speed specified "
fp@673: 			"without Duplex\n");
fp@673: 		DPRINTK(PROBE, INFO, "Using Autonegotiation at "
fp@673: 			"100 Mbps only\n");
fp@673: 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
fp@673: 		adapter->hw.autoneg_advertised = ADVERTISE_100_HALF |
fp@673: 		                                 ADVERTISE_100_FULL;
fp@673: 		break;
fp@673: 	case SPEED_100 + HALF_DUPLEX:
fp@673: 		DPRINTK(PROBE, INFO, "Forcing to 100 Mbps Half Duplex\n");
fp@673: 		adapter->hw.autoneg = adapter->fc_autoneg = 0;
fp@673: 		adapter->hw.forced_speed_duplex = e1000_100_half;
fp@673: 		adapter->hw.autoneg_advertised = 0;
fp@673: 		break;
fp@673: 	case SPEED_100 + FULL_DUPLEX:
fp@673: 		DPRINTK(PROBE, INFO, "Forcing to 100 Mbps Full Duplex\n");
fp@673: 		adapter->hw.autoneg = adapter->fc_autoneg = 0;
fp@673: 		adapter->hw.forced_speed_duplex = e1000_100_full;
fp@673: 		adapter->hw.autoneg_advertised = 0;
fp@673: 		break;
fp@673: 	case SPEED_1000:
fp@673: 		DPRINTK(PROBE, INFO, "1000 Mbps Speed specified without "
fp@673: 			"Duplex\n");
fp@673: 		DPRINTK(PROBE, INFO,
fp@673: 			"Using Autonegotiation at 1000 Mbps "
fp@673: 			"Full Duplex only\n");
fp@673: 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
fp@673: 		adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
fp@673: 		break;
fp@673: 	case SPEED_1000 + HALF_DUPLEX:
fp@673: 		DPRINTK(PROBE, INFO,
fp@673: 			"Half Duplex is not supported at 1000 Mbps\n");
fp@673: 		DPRINTK(PROBE, INFO,
fp@673: 			"Using Autonegotiation at 1000 Mbps "
fp@673: 			"Full Duplex only\n");
fp@673: 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
fp@673: 		adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
fp@673: 		break;
fp@673: 	case SPEED_1000 + FULL_DUPLEX:
fp@673: 		DPRINTK(PROBE, INFO,
fp@673: 		       "Using Autonegotiation at 1000 Mbps Full Duplex only\n");
fp@673: 		adapter->hw.autoneg = adapter->fc_autoneg = 1;
fp@673: 		adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
fp@673: 		break;
fp@673: 	default:
fp@673: 		BUG();
fp@673: 	}
fp@673: 
fp@673: 	/* Speed, AutoNeg and MDI/MDI-X must all play nice */
fp@673: 	if (e1000_validate_mdi_setting(&(adapter->hw)) < 0) {
fp@673: 		DPRINTK(PROBE, INFO,
fp@673: 			"Speed, AutoNeg and MDI-X specifications are "
fp@673: 			"incompatible. Setting MDI-X to a compatible value.\n");
fp@673: 	}
fp@673: }
fp@673: