xref: /onnv-gate/usr/src/uts/common/io/bge/bge_ndd.c (revision 7678:279095cadf81)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51369Sdduvall  * Common Development and Distribution License (the "License").
61369Sdduvall  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211369Sdduvall 
220Sstevel@tonic-gate /*
235903Ssowmini  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
272675Szh199473 #include "bge_impl.h"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #define	BGE_DBG		BGE_DBG_NDD	/* debug flag for this code	*/
310Sstevel@tonic-gate /*
320Sstevel@tonic-gate  * Property names
330Sstevel@tonic-gate  */
340Sstevel@tonic-gate static char transfer_speed_propname[] = "transfer-speed";
350Sstevel@tonic-gate static char speed_propname[] = "speed";
360Sstevel@tonic-gate static char duplex_propname[] = "full-duplex";
372135Szh199473 static char supported_net[] = "supported-network-types";
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /*
405903Ssowmini  * synchronize the  adv* and en* parameters.
415903Ssowmini  *
425903Ssowmini  * See comments in <sys/dld.h> for details of the *_en_*
435903Ssowmini  * parameters.  The usage of ndd for setting adv parameters will
445903Ssowmini  * synchronize all the en parameters with the bge parameters,
455903Ssowmini  * implicitly disabling any settings made via dladm.
465903Ssowmini  */
475903Ssowmini static void
bge_param_sync(bge_t * bgep)485903Ssowmini bge_param_sync(bge_t *bgep)
495903Ssowmini {
505903Ssowmini 	bgep->param_en_pause = bgep->param_adv_pause;
515903Ssowmini 	bgep->param_en_asym_pause = bgep->param_adv_asym_pause;
525903Ssowmini 	bgep->param_en_1000fdx = bgep->param_adv_1000fdx;
535903Ssowmini 	bgep->param_en_1000hdx = bgep->param_adv_1000hdx;
545903Ssowmini 	bgep->param_en_100fdx = bgep->param_adv_100fdx;
555903Ssowmini 	bgep->param_en_100hdx = bgep->param_adv_100hdx;
565903Ssowmini 	bgep->param_en_10fdx = bgep->param_adv_10fdx;
575903Ssowmini 	bgep->param_en_10hdx = bgep->param_adv_10hdx;
585903Ssowmini }
595903Ssowmini 
606512Ssowmini boolean_t
bge_nd_get_prop_val(dev_info_t * dip,char * nm,long min,long max,int * pval)616512Ssowmini bge_nd_get_prop_val(dev_info_t *dip, char *nm, long min, long max, int *pval)
620Sstevel@tonic-gate {
636512Ssowmini 	/*
646512Ssowmini 	 * If there is a driver.conf setting for the prop, we use
656512Ssowmini 	 * it to initialise the parameter.  If it exists but is
666512Ssowmini 	 * out of range, it's ignored.
676512Ssowmini 	 */
686512Ssowmini 	if (BGE_PROP_EXISTS(dip, nm)) {
696512Ssowmini 		*pval = BGE_PROP_GET_INT(dip, nm);
706512Ssowmini 		if (*pval >= min && *pval <= max)
716512Ssowmini 			return (B_TRUE);
726512Ssowmini 	}
736512Ssowmini 	return (B_FALSE);
740Sstevel@tonic-gate }
750Sstevel@tonic-gate 
766512Ssowmini #define	BGE_INIT_PROP(propname, fieldname, initval) {		\
776512Ssowmini 	if (bge_nd_get_prop_val(dip, propname, 0, 1, &propval)) \
786512Ssowmini 		bgep->fieldname = propval;			\
796512Ssowmini 	else							\
806512Ssowmini 		bgep->fieldname = initval;			\
816512Ssowmini }
826512Ssowmini 
836512Ssowmini static void
bge_nd_param_init(bge_t * bgep)846512Ssowmini bge_nd_param_init(bge_t *bgep)
850Sstevel@tonic-gate {
860Sstevel@tonic-gate 	dev_info_t *dip;
876512Ssowmini 	int flags = bgep->chipid.flags;
886512Ssowmini 	int propval;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	dip = bgep->devinfo;
910Sstevel@tonic-gate 
926512Ssowmini 	/*
936512Ssowmini 	 * initialize values to those from driver.conf (if available)
946512Ssowmini 	 * or the default value otherwise.
956512Ssowmini 	 */
966512Ssowmini 	BGE_INIT_PROP("adv_autoneg_cap", param_adv_autoneg, 1);
97*7678SYong.Tan@Sun.COM 	if (DEVICE_5906_SERIES_CHIPSETS(bgep)) {
98*7678SYong.Tan@Sun.COM 		BGE_INIT_PROP("adv_1000fdx_cap", param_adv_1000fdx, 0);
99*7678SYong.Tan@Sun.COM 		BGE_INIT_PROP("adv_1000hdx_cap", param_adv_1000hdx, 0);
100*7678SYong.Tan@Sun.COM 	} else {
101*7678SYong.Tan@Sun.COM 		BGE_INIT_PROP("adv_1000fdx_cap", param_adv_1000fdx, 1);
102*7678SYong.Tan@Sun.COM 		BGE_INIT_PROP("adv_1000hdx_cap", param_adv_1000hdx, 1);
103*7678SYong.Tan@Sun.COM 	}
1047557SSowmini.Varadhan@Sun.COM 	BGE_INIT_PROP("adv_pause_cap", param_adv_pause, 1);
1057557SSowmini.Varadhan@Sun.COM 	BGE_INIT_PROP("adv_asym_pause_cap", param_adv_asym_pause, 1);
1060Sstevel@tonic-gate 
1076512Ssowmini 	if (flags & CHIP_FLAG_SERDES) {
1086512Ssowmini 		bgep->param_adv_100fdx = 0;
1096512Ssowmini 		bgep->param_adv_100hdx = 0;
1106512Ssowmini 		bgep->param_adv_10fdx = 0;
1116512Ssowmini 		bgep->param_adv_10hdx = 0;
1126512Ssowmini 	} else {
1136512Ssowmini 		BGE_INIT_PROP("adv_100fdx_cap", param_adv_100fdx, 1);
1146512Ssowmini 		BGE_INIT_PROP("adv_100hdx_cap", param_adv_100hdx, 1);
1156512Ssowmini 		BGE_INIT_PROP("adv_10fdx_cap", param_adv_10fdx, 1);
1166512Ssowmini 		BGE_INIT_PROP("adv_10hdx_cap", param_adv_10hdx, 1);
1170Sstevel@tonic-gate 	}
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate }
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate int
bge_nd_init(bge_t * bgep)1220Sstevel@tonic-gate bge_nd_init(bge_t *bgep)
1230Sstevel@tonic-gate {
1240Sstevel@tonic-gate 	dev_info_t *dip;
1250Sstevel@tonic-gate 	int duplex;
1260Sstevel@tonic-gate 	int speed;
1272135Szh199473 	char **options, *prop;
1282135Szh199473 	uint_t  noptions;
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	BGE_TRACE(("bge_nd_init($%p)", (void *)bgep));
1316512Ssowmini 	bge_nd_param_init(bgep);
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	/*
1346512Ssowmini 	 * initialize from .conf file, if appropriate.
1350Sstevel@tonic-gate 	 */
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate 	/*
1382135Szh199473 	 * check the OBP property "supported-network-types"
1392135Szh199473 	 */
1402135Szh199473 	if (BGE_PROP_EXISTS(bgep->devinfo, supported_net)) {
1412135Szh199473 		if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, bgep->devinfo,
1425903Ssowmini 		    DDI_PROP_DONTPASS, supported_net,
1435903Ssowmini 		    &options, &noptions) == DDI_PROP_SUCCESS) {
1442135Szh199473 
1452135Szh199473 			bgep->param_adv_autoneg = 0;
1462135Szh199473 			bgep->param_adv_1000fdx = 0;
1472135Szh199473 			bgep->param_adv_1000hdx = 0;
1482135Szh199473 			bgep->param_adv_100fdx = 0;
1492135Szh199473 			bgep->param_adv_100hdx = 0;
1502135Szh199473 			bgep->param_adv_10fdx = 0;
1512135Szh199473 			bgep->param_adv_10hdx = 0;
1522135Szh199473 
1532135Szh199473 			for (; noptions > 0; noptions--) {
1542135Szh199473 				prop = options[noptions-1];
1552135Szh199473 				if (strstr(prop, "ethernet") == NULL)
1562135Szh199473 					continue;
1572135Szh199473 				if (strstr(prop, "1000")) {
1582135Szh199473 					if (strstr(prop, "auto")) {
1592135Szh199473 						bgep->param_adv_1000fdx = 1;
1602135Szh199473 						bgep->param_adv_1000hdx = 1;
1612135Szh199473 						bgep->param_adv_autoneg = 1;
1622135Szh199473 					} else if (strstr(prop, "full"))
1632135Szh199473 						bgep->param_adv_1000fdx = 1;
1642135Szh199473 					else if (strstr(prop, "half"))
1652135Szh199473 						bgep->param_adv_1000hdx = 1;
1662135Szh199473 				} else if (strstr(prop, "100")) {
1672135Szh199473 					if (strstr(prop, "auto")) {
1682135Szh199473 						bgep->param_adv_100fdx = 1;
1692135Szh199473 						bgep->param_adv_100hdx = 1;
1702135Szh199473 						bgep->param_adv_autoneg = 1;
1712135Szh199473 					} else if (strstr(prop, "full"))
1722135Szh199473 						bgep->param_adv_100fdx = 1;
1732135Szh199473 					else if (strstr(prop, "half"))
1742135Szh199473 						bgep->param_adv_100hdx = 1;
1752135Szh199473 				} else if (strstr(prop, "10")) {
1762135Szh199473 					if (strstr(prop, "auto")) {
1772135Szh199473 						bgep->param_adv_10fdx = 1;
1782135Szh199473 						bgep->param_adv_10hdx = 1;
1792135Szh199473 						bgep->param_adv_autoneg = 1;
1802135Szh199473 					} else if (strstr(prop, "full"))
1812135Szh199473 						bgep->param_adv_10fdx = 1;
1822135Szh199473 					else if (strstr(prop, "half"))
1832135Szh199473 						bgep->param_adv_10hdx = 1;
1842135Szh199473 				}
1852135Szh199473 			}
1862135Szh199473 
1872135Szh199473 			ddi_prop_free(options);
1882135Szh199473 		}
1892135Szh199473 	}
1902135Szh199473 
1912135Szh199473 	/*
1920Sstevel@tonic-gate 	 * The link speed may be forced to 10, 100 or 1000 Mbps using
1930Sstevel@tonic-gate 	 * the property "transfer-speed". This may be done in OBP by
1940Sstevel@tonic-gate 	 * using the command "apply transfer-speed=<speed> <device>".
1950Sstevel@tonic-gate 	 * The speed may be 10, 100 or 1000 - any other value will be
1960Sstevel@tonic-gate 	 * ignored.  Note that this does *enables* autonegotiation, but
1970Sstevel@tonic-gate 	 * restricts it to the speed specified by the property.
1980Sstevel@tonic-gate 	 */
1990Sstevel@tonic-gate 	dip = bgep->devinfo;
2000Sstevel@tonic-gate 	if (BGE_PROP_EXISTS(dip, transfer_speed_propname)) {
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate 		speed = BGE_PROP_GET_INT(dip, transfer_speed_propname);
2030Sstevel@tonic-gate 		bge_log(bgep, "%s property is %d",
2045903Ssowmini 		    transfer_speed_propname, speed);
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate 		switch (speed) {
2070Sstevel@tonic-gate 		case 1000:
2080Sstevel@tonic-gate 			bgep->param_adv_autoneg = 1;
2090Sstevel@tonic-gate 			bgep->param_adv_1000fdx = 1;
2100Sstevel@tonic-gate 			bgep->param_adv_1000hdx = 1;
2110Sstevel@tonic-gate 			bgep->param_adv_100fdx = 0;
2120Sstevel@tonic-gate 			bgep->param_adv_100hdx = 0;
2130Sstevel@tonic-gate 			bgep->param_adv_10fdx = 0;
2140Sstevel@tonic-gate 			bgep->param_adv_10hdx = 0;
2150Sstevel@tonic-gate 			break;
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 		case 100:
2180Sstevel@tonic-gate 			bgep->param_adv_autoneg = 1;
2190Sstevel@tonic-gate 			bgep->param_adv_1000fdx = 0;
2200Sstevel@tonic-gate 			bgep->param_adv_1000hdx = 0;
2210Sstevel@tonic-gate 			bgep->param_adv_100fdx = 1;
2220Sstevel@tonic-gate 			bgep->param_adv_100hdx = 1;
2230Sstevel@tonic-gate 			bgep->param_adv_10fdx = 0;
2240Sstevel@tonic-gate 			bgep->param_adv_10hdx = 0;
2250Sstevel@tonic-gate 			break;
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate 		case 10:
2280Sstevel@tonic-gate 			bgep->param_adv_autoneg = 1;
2290Sstevel@tonic-gate 			bgep->param_adv_1000fdx = 0;
2300Sstevel@tonic-gate 			bgep->param_adv_1000hdx = 0;
2310Sstevel@tonic-gate 			bgep->param_adv_100fdx = 0;
2320Sstevel@tonic-gate 			bgep->param_adv_100hdx = 0;
2330Sstevel@tonic-gate 			bgep->param_adv_10fdx = 1;
2340Sstevel@tonic-gate 			bgep->param_adv_10hdx = 1;
2350Sstevel@tonic-gate 			break;
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 		default:
2380Sstevel@tonic-gate 			break;
2390Sstevel@tonic-gate 		}
2400Sstevel@tonic-gate 	}
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate 	/*
2430Sstevel@tonic-gate 	 * Also check the "speed" and "full-duplex" properties.  Setting
2440Sstevel@tonic-gate 	 * these properties will override all other settings and *disable*
2450Sstevel@tonic-gate 	 * autonegotiation, so both should be specified if either one is.
2460Sstevel@tonic-gate 	 * Otherwise, the unspecified parameter will be set to a default
2470Sstevel@tonic-gate 	 * value (1000Mb/s, full-duplex).
2480Sstevel@tonic-gate 	 */
2490Sstevel@tonic-gate 	if (BGE_PROP_EXISTS(dip, speed_propname) ||
2500Sstevel@tonic-gate 	    BGE_PROP_EXISTS(dip, duplex_propname)) {
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate 		bgep->param_adv_autoneg = 0;
2530Sstevel@tonic-gate 		bgep->param_adv_1000fdx = 1;
2540Sstevel@tonic-gate 		bgep->param_adv_1000hdx = 1;
2550Sstevel@tonic-gate 		bgep->param_adv_100fdx = 1;
2560Sstevel@tonic-gate 		bgep->param_adv_100hdx = 1;
2570Sstevel@tonic-gate 		bgep->param_adv_10fdx = 1;
2580Sstevel@tonic-gate 		bgep->param_adv_10hdx = 1;
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate 		speed = BGE_PROP_GET_INT(dip, speed_propname);
2610Sstevel@tonic-gate 		duplex = BGE_PROP_GET_INT(dip, duplex_propname);
2620Sstevel@tonic-gate 		bge_log(bgep, "%s property is %d",
2635903Ssowmini 		    speed_propname, speed);
2640Sstevel@tonic-gate 		bge_log(bgep, "%s property is %d",
2655903Ssowmini 		    duplex_propname, duplex);
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 		switch (speed) {
2680Sstevel@tonic-gate 		case 1000:
2690Sstevel@tonic-gate 		default:
2700Sstevel@tonic-gate 			bgep->param_adv_100fdx = 0;
2710Sstevel@tonic-gate 			bgep->param_adv_100hdx = 0;
2720Sstevel@tonic-gate 			bgep->param_adv_10fdx = 0;
2730Sstevel@tonic-gate 			bgep->param_adv_10hdx = 0;
2740Sstevel@tonic-gate 			break;
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate 		case 100:
2770Sstevel@tonic-gate 			bgep->param_adv_1000fdx = 0;
2780Sstevel@tonic-gate 			bgep->param_adv_1000hdx = 0;
2790Sstevel@tonic-gate 			bgep->param_adv_10fdx = 0;
2800Sstevel@tonic-gate 			bgep->param_adv_10hdx = 0;
2810Sstevel@tonic-gate 			break;
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 		case 10:
2840Sstevel@tonic-gate 			bgep->param_adv_1000fdx = 0;
2850Sstevel@tonic-gate 			bgep->param_adv_1000hdx = 0;
2860Sstevel@tonic-gate 			bgep->param_adv_100fdx = 0;
2870Sstevel@tonic-gate 			bgep->param_adv_100hdx = 0;
2880Sstevel@tonic-gate 			break;
2890Sstevel@tonic-gate 		}
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate 		switch (duplex) {
2920Sstevel@tonic-gate 		default:
2930Sstevel@tonic-gate 		case 1:
2940Sstevel@tonic-gate 			bgep->param_adv_1000hdx = 0;
2950Sstevel@tonic-gate 			bgep->param_adv_100hdx = 0;
2960Sstevel@tonic-gate 			bgep->param_adv_10hdx = 0;
2970Sstevel@tonic-gate 			break;
2980Sstevel@tonic-gate 
2990Sstevel@tonic-gate 		case 0:
3000Sstevel@tonic-gate 			bgep->param_adv_1000fdx = 0;
3010Sstevel@tonic-gate 			bgep->param_adv_100fdx = 0;
3020Sstevel@tonic-gate 			bgep->param_adv_10fdx = 0;
3030Sstevel@tonic-gate 			break;
3040Sstevel@tonic-gate 		}
3050Sstevel@tonic-gate 	}
3060Sstevel@tonic-gate 
3075903Ssowmini 	bge_param_sync(bgep);
3080Sstevel@tonic-gate 
3090Sstevel@tonic-gate 	return (0);
3100Sstevel@tonic-gate }
311