Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17231712 authored by Auke Kok's avatar Auke Kok Committed by Auke Kok
Browse files

e1000: rework module param code with uninitialized values



We can take uninitialized values into account which minimizes code
and allows us to simplify the parameter checking code greatly.

Signed-off-by: default avatarJesse Brandeburg <jesse.brandeburg@intel.com>
Signed-off-by: default avatarAuke Kok <auke-jan.h.kok@intel.com>
parent 864c4e45
Loading
Loading
Loading
Loading
+61 −106
Original line number Original line Diff line number Diff line
@@ -45,6 +45,16 @@
 */
 */


#define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
#define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
/* Module Parameters are always initialized to -1, so that the driver
 * can tell the difference between no user specified value or the
 * user asking for the default value.
 * The true default values are loaded in when e1000_check_options is called.
 *
 * This is a GCC extension to ANSI C.
 * See the item "Labeled Elements in Initializers" in the section
 * "Extensions to the C Language Family" of the GCC documentation.
 */

#define E1000_PARAM(X, desc) \
#define E1000_PARAM(X, desc) \
	static int __devinitdata X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
	static int __devinitdata X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
	static int num_##X = 0; \
	static int num_##X = 0; \
@@ -305,6 +315,7 @@ e1000_check_options(struct e1000_adapter *adapter)
		DPRINTK(PROBE, NOTICE,
		DPRINTK(PROBE, NOTICE,
		       "Warning: no configuration for board #%i\n", bd);
		       "Warning: no configuration for board #%i\n", bd);
		DPRINTK(PROBE, NOTICE, "Using defaults for all values\n");
		DPRINTK(PROBE, NOTICE, "Using defaults for all values\n");
		bd = E1000_MAX_NIC;
	}
	}


	{ /* Transmit Descriptor Count */
	{ /* Transmit Descriptor Count */
@@ -322,14 +333,9 @@ e1000_check_options(struct e1000_adapter *adapter)
		opt.arg.r.max = mac_type < e1000_82544 ?
		opt.arg.r.max = mac_type < e1000_82544 ?
			E1000_MAX_TXD : E1000_MAX_82544_TXD;
			E1000_MAX_TXD : E1000_MAX_82544_TXD;


		if (num_TxDescriptors > bd) {
		tx_ring->count = TxDescriptors[bd];
		tx_ring->count = TxDescriptors[bd];
		e1000_validate_option(&tx_ring->count, &opt, adapter);
		e1000_validate_option(&tx_ring->count, &opt, adapter);
			E1000_ROUNDUP(tx_ring->count,
		E1000_ROUNDUP(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
						REQ_TX_DESCRIPTOR_MULTIPLE);
		} else {
			tx_ring->count = opt.def;
		}
		for (i = 0; i < adapter->num_tx_queues; i++)
		for (i = 0; i < adapter->num_tx_queues; i++)
			tx_ring[i].count = tx_ring->count;
			tx_ring[i].count = tx_ring->count;
	}
	}
@@ -348,14 +354,9 @@ e1000_check_options(struct e1000_adapter *adapter)
		opt.arg.r.max = mac_type < e1000_82544 ? E1000_MAX_RXD :
		opt.arg.r.max = mac_type < e1000_82544 ? E1000_MAX_RXD :
			E1000_MAX_82544_RXD;
			E1000_MAX_82544_RXD;


		if (num_RxDescriptors > bd) {
		rx_ring->count = RxDescriptors[bd];
		rx_ring->count = RxDescriptors[bd];
		e1000_validate_option(&rx_ring->count, &opt, adapter);
		e1000_validate_option(&rx_ring->count, &opt, adapter);
			E1000_ROUNDUP(rx_ring->count,
		E1000_ROUNDUP(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
						REQ_RX_DESCRIPTOR_MULTIPLE);
		} else {
			rx_ring->count = opt.def;
		}
		for (i = 0; i < adapter->num_rx_queues; i++)
		for (i = 0; i < adapter->num_rx_queues; i++)
			rx_ring[i].count = rx_ring->count;
			rx_ring[i].count = rx_ring->count;
	}
	}
@@ -367,13 +368,9 @@ e1000_check_options(struct e1000_adapter *adapter)
			.def  = OPTION_ENABLED
			.def  = OPTION_ENABLED
		};
		};


		if (num_XsumRX > bd) {
		int rx_csum = XsumRX[bd];
		int rx_csum = XsumRX[bd];
		e1000_validate_option(&rx_csum, &opt, adapter);
		e1000_validate_option(&rx_csum, &opt, adapter);
		adapter->rx_csum = rx_csum;
		adapter->rx_csum = rx_csum;
		} else {
			adapter->rx_csum = opt.def;
		}
	}
	}
	{ /* Flow Control */
	{ /* Flow Control */


@@ -393,13 +390,9 @@ e1000_check_options(struct e1000_adapter *adapter)
					 .p = fc_list }}
					 .p = fc_list }}
		};
		};


		if (num_FlowControl > bd) {
		int fc = FlowControl[bd];
		int fc = FlowControl[bd];
		e1000_validate_option(&fc, &opt, adapter);
		e1000_validate_option(&fc, &opt, adapter);
		adapter->hw.fc = adapter->hw.original_fc = fc;
		adapter->hw.fc = adapter->hw.original_fc = fc;
		} else {
			adapter->hw.fc = adapter->hw.original_fc = opt.def;
		}
	}
	}
	{ /* Transmit Interrupt Delay */
	{ /* Transmit Interrupt Delay */
		struct e1000_option opt = {
		struct e1000_option opt = {
@@ -411,13 +404,8 @@ e1000_check_options(struct e1000_adapter *adapter)
					 .max = MAX_TXDELAY }}
					 .max = MAX_TXDELAY }}
		};
		};


		if (num_TxIntDelay > bd) {
		adapter->tx_int_delay = TxIntDelay[bd];
		adapter->tx_int_delay = TxIntDelay[bd];
			e1000_validate_option(&adapter->tx_int_delay, &opt,
		e1000_validate_option(&adapter->tx_int_delay, &opt, adapter);
								adapter);
		} else {
			adapter->tx_int_delay = opt.def;
		}
	}
	}
	{ /* Transmit Absolute Interrupt Delay */
	{ /* Transmit Absolute Interrupt Delay */
		struct e1000_option opt = {
		struct e1000_option opt = {
@@ -429,13 +417,9 @@ e1000_check_options(struct e1000_adapter *adapter)
					 .max = MAX_TXABSDELAY }}
					 .max = MAX_TXABSDELAY }}
		};
		};


		if (num_TxAbsIntDelay > bd) {
		adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
		adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
		e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
		e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
		                      adapter);
		                      adapter);
		} else {
			adapter->tx_abs_int_delay = opt.def;
		}
	}
	}
	{ /* Receive Interrupt Delay */
	{ /* Receive Interrupt Delay */
		struct e1000_option opt = {
		struct e1000_option opt = {
@@ -447,13 +431,8 @@ e1000_check_options(struct e1000_adapter *adapter)
					 .max = MAX_RXDELAY }}
					 .max = MAX_RXDELAY }}
		};
		};


		if (num_RxIntDelay > bd) {
		adapter->rx_int_delay = RxIntDelay[bd];
		adapter->rx_int_delay = RxIntDelay[bd];
			e1000_validate_option(&adapter->rx_int_delay, &opt,
		e1000_validate_option(&adapter->rx_int_delay, &opt, adapter);
								adapter);
		} else {
			adapter->rx_int_delay = opt.def;
		}
	}
	}
	{ /* Receive Absolute Interrupt Delay */
	{ /* Receive Absolute Interrupt Delay */
		struct e1000_option opt = {
		struct e1000_option opt = {
@@ -465,13 +444,9 @@ e1000_check_options(struct e1000_adapter *adapter)
					 .max = MAX_RXABSDELAY }}
					 .max = MAX_RXABSDELAY }}
		};
		};


		if (num_RxAbsIntDelay > bd) {
		adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
		adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
		e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
		e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
		                      adapter);
		                      adapter);
		} else {
			adapter->rx_abs_int_delay = opt.def;
		}
	}
	}
	{ /* Interrupt Throttling Rate */
	{ /* Interrupt Throttling Rate */
		struct e1000_option opt = {
		struct e1000_option opt = {
@@ -483,25 +458,19 @@ e1000_check_options(struct e1000_adapter *adapter)
					 .max = MAX_ITR }}
					 .max = MAX_ITR }}
		};
		};


		if (num_InterruptThrottleRate > bd) {
		adapter->itr = InterruptThrottleRate[bd];
		adapter->itr = InterruptThrottleRate[bd];
		switch (adapter->itr) {
		switch (adapter->itr) {
		case 0:
		case 0:
				DPRINTK(PROBE, INFO, "%s turned off\n",
			DPRINTK(PROBE, INFO, "%s turned off\n", opt.name);
					opt.name);
			break;
			break;
		case 1:
		case 1:
			DPRINTK(PROBE, INFO, "%s set to dynamic mode\n",
			DPRINTK(PROBE, INFO, "%s set to dynamic mode\n",
				opt.name);
				opt.name);
			break;
			break;
		default:
		default:
				e1000_validate_option(&adapter->itr, &opt,
			e1000_validate_option(&adapter->itr, &opt, adapter);
					adapter);
			break;
			break;
		}
		}
		} else {
			adapter->itr = opt.def;
		}
	}
	}
	{ /* Smart Power Down */
	{ /* Smart Power Down */
		struct e1000_option opt = {
		struct e1000_option opt = {
@@ -511,13 +480,9 @@ e1000_check_options(struct e1000_adapter *adapter)
			.def  = OPTION_DISABLED
			.def  = OPTION_DISABLED
		};
		};


		if (num_SmartPowerDownEnable > bd) {
		int spd = SmartPowerDownEnable[bd];
		int spd = SmartPowerDownEnable[bd];
		e1000_validate_option(&spd, &opt, adapter);
		e1000_validate_option(&spd, &opt, adapter);
		adapter->smart_power_down = spd;
		adapter->smart_power_down = spd;
		} else {
			adapter->smart_power_down = opt.def;
		}
	}
	}


	switch (adapter->hw.media_type) {
	switch (adapter->hw.media_type) {
@@ -544,17 +509,18 @@ static void __devinit
e1000_check_fiber_options(struct e1000_adapter *adapter)
e1000_check_fiber_options(struct e1000_adapter *adapter)
{
{
	int bd = adapter->bd_number;
	int bd = adapter->bd_number;
	if (num_Speed > bd) {
	bd = bd > E1000_MAX_NIC ? E1000_MAX_NIC : bd;
	if ((Speed[bd] != OPTION_UNSET)) {
		DPRINTK(PROBE, INFO, "Speed not valid for fiber adapters, "
		DPRINTK(PROBE, INFO, "Speed not valid for fiber adapters, "
		       "parameter ignored\n");
		       "parameter ignored\n");
	}
	}


	if (num_Duplex > bd) {
	if ((Duplex[bd] != OPTION_UNSET)) {
		DPRINTK(PROBE, INFO, "Duplex not valid for fiber adapters, "
		DPRINTK(PROBE, INFO, "Duplex not valid for fiber adapters, "
		       "parameter ignored\n");
		       "parameter ignored\n");
	}
	}


	if ((num_AutoNeg > bd) && (AutoNeg[bd] != 0x20)) {
	if ((AutoNeg[bd] != OPTION_UNSET) && (AutoNeg[bd] != 0x20)) {
		DPRINTK(PROBE, INFO, "AutoNeg other than 1000/Full is "
		DPRINTK(PROBE, INFO, "AutoNeg other than 1000/Full is "
				 "not valid for fiber adapters, "
				 "not valid for fiber adapters, "
				 "parameter ignored\n");
				 "parameter ignored\n");
@@ -573,6 +539,7 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
{
{
	int speed, dplx, an;
	int speed, dplx, an;
	int bd = adapter->bd_number;
	int bd = adapter->bd_number;
	bd = bd > E1000_MAX_NIC ? E1000_MAX_NIC : bd;


	{ /* Speed */
	{ /* Speed */
		struct e1000_opt_list speed_list[] = {{          0, "" },
		struct e1000_opt_list speed_list[] = {{          0, "" },
@@ -589,12 +556,8 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
					 .p = speed_list }}
					 .p = speed_list }}
		};
		};


		if (num_Speed > bd) {
		speed = Speed[bd];
		speed = Speed[bd];
		e1000_validate_option(&speed, &opt, adapter);
		e1000_validate_option(&speed, &opt, adapter);
		} else {
			speed = opt.def;
		}
	}
	}
	{ /* Duplex */
	{ /* Duplex */
		struct e1000_opt_list dplx_list[] = {{           0, "" },
		struct e1000_opt_list dplx_list[] = {{           0, "" },
@@ -616,15 +579,11 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
			        "Speed/Duplex/AutoNeg parameter ignored.\n");
			        "Speed/Duplex/AutoNeg parameter ignored.\n");
			return;
			return;
		}
		}
		if (num_Duplex > bd) {
		dplx = Duplex[bd];
		dplx = Duplex[bd];
		e1000_validate_option(&dplx, &opt, adapter);
		e1000_validate_option(&dplx, &opt, adapter);
		} else {
			dplx = opt.def;
		}
	}
	}


	if ((num_AutoNeg > bd) && (speed != 0 || dplx != 0)) {
	if (AutoNeg[bd] != OPTION_UNSET && (speed != 0 || dplx != 0)) {
		DPRINTK(PROBE, INFO,
		DPRINTK(PROBE, INFO,
		       "AutoNeg specified along with Speed or Duplex, "
		       "AutoNeg specified along with Speed or Duplex, "
		       "parameter ignored\n");
		       "parameter ignored\n");
@@ -673,19 +632,15 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
					 .p = an_list }}
					 .p = an_list }}
		};
		};


		if (num_AutoNeg > bd) {
		an = AutoNeg[bd];
		an = AutoNeg[bd];
		e1000_validate_option(&an, &opt, adapter);
		e1000_validate_option(&an, &opt, adapter);
		} else {
			an = opt.def;
		}
		adapter->hw.autoneg_advertised = an;
		adapter->hw.autoneg_advertised = an;
	}
	}


	switch (speed + dplx) {
	switch (speed + dplx) {
	case 0:
	case 0:
		adapter->hw.autoneg = adapter->fc_autoneg = 1;
		adapter->hw.autoneg = adapter->fc_autoneg = 1;
		if ((num_Speed > bd) && (speed != 0 || dplx != 0))
		if (Speed[bd] != OPTION_UNSET || Duplex[bd] != OPTION_UNSET)
			DPRINTK(PROBE, INFO,
			DPRINTK(PROBE, INFO,
			       "Speed and duplex autonegotiation enabled\n");
			       "Speed and duplex autonegotiation enabled\n");
		break;
		break;