xref: /illumos-gate/usr/src/uts/common/io/nge/nge_ndd.c (revision 2d6eb4a5)
16f3e57acSmx /*
247693af9Smx  * CDDL HEADER START
347693af9Smx  *
447693af9Smx  * The contents of this file are subject to the terms of the
547693af9Smx  * Common Development and Distribution License (the "License").
647693af9Smx  * You may not use this file except in compliance with the License.
747693af9Smx  *
847693af9Smx  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
947693af9Smx  * or http://www.opensolaris.org/os/licensing.
1047693af9Smx  * See the License for the specific language governing permissions
1147693af9Smx  * and limitations under the License.
1247693af9Smx  *
1347693af9Smx  * When distributing Covered Code, include this CDDL HEADER in each
1447693af9Smx  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1547693af9Smx  * If applicable, add the following below this CDDL HEADER, with the
1647693af9Smx  * fields enclosed by brackets "[]" replaced with your own identifying
1747693af9Smx  * information: Portions Copyright [yyyy] [name of copyright owner]
1847693af9Smx  *
1947693af9Smx  * CDDL HEADER END
206f3e57acSmx  */
216f3e57acSmx 
226f3e57acSmx /*
235a3d0718Smx  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
2447693af9Smx  * Use is subject to license terms.
256f3e57acSmx  */
266f3e57acSmx 
276f3e57acSmx #include "nge.h"
286f3e57acSmx 
296f3e57acSmx #undef	NGE_DBG
306f3e57acSmx #define	NGE_DBG		NGE_DBG_NDD
316f3e57acSmx 
326f3e57acSmx static char transfer_speed_propname[] = "transfer-speed";
336f3e57acSmx static char speed_propname[] = "speed";
346f3e57acSmx static char duplex_propname[] = "full-duplex";
356f3e57acSmx 
365a3d0718Smx /*
375a3d0718Smx  * synchronize the  adv* and en* parameters.
385a3d0718Smx  *
395a3d0718Smx  * See comments in <sys/dld.h> for details of the *_en_*
405a3d0718Smx  * parameters.  The usage of ndd for setting adv parameters will
415a3d0718Smx  * synchronize all the en parameters with the nge parameters,
425a3d0718Smx  * implicitly disabling any settings made via dladm.
435a3d0718Smx  */
445a3d0718Smx static void
nge_param_sync(nge_t * ngep)455a3d0718Smx nge_param_sync(nge_t *ngep)
465a3d0718Smx {
475a3d0718Smx 	ngep->param_en_pause = ngep->param_adv_pause;
485a3d0718Smx 	ngep->param_en_asym_pause = ngep->param_adv_asym_pause;
495a3d0718Smx 	ngep->param_en_1000fdx = ngep->param_adv_1000fdx;
505a3d0718Smx 	ngep->param_en_1000hdx = ngep->param_adv_1000hdx;
515a3d0718Smx 	ngep->param_en_100fdx = ngep->param_adv_100fdx;
525a3d0718Smx 	ngep->param_en_100hdx = ngep->param_adv_100hdx;
535a3d0718Smx 	ngep->param_en_10fdx = ngep->param_adv_10fdx;
545a3d0718Smx 	ngep->param_en_10hdx = ngep->param_adv_10hdx;
555a3d0718Smx }
565a3d0718Smx 
57*4045d941Ssowmini 
58*4045d941Ssowmini boolean_t
nge_nd_get_prop_val(dev_info_t * dip,char * nm,long min,long max,int * pval)59*4045d941Ssowmini nge_nd_get_prop_val(dev_info_t *dip, char *nm, long min, long max, int *pval)
606f3e57acSmx {
61*4045d941Ssowmini 	/*
62*4045d941Ssowmini 	 * If the parameter is writable, and there's a property
63*4045d941Ssowmini 	 * with the same name, and its value is in range, we use
64*4045d941Ssowmini 	 * it to initialise the parameter.  If it exists but is
65*4045d941Ssowmini 	 * out of range, it's ignored.
66*4045d941Ssowmini 	 */
67*4045d941Ssowmini 	if (NGE_PROP_EXISTS(dip, nm)) {
68*4045d941Ssowmini 		*pval = NGE_PROP_GET_INT(dip, nm);
69*4045d941Ssowmini 		if (*pval >= min && *pval <= max)
70*4045d941Ssowmini 			return (B_TRUE);
71*4045d941Ssowmini 	}
72*4045d941Ssowmini 	return (B_FALSE);
736f3e57acSmx }
746f3e57acSmx 
75*4045d941Ssowmini #define	NGE_INIT_PROP(propname, fieldname, initval) {		\
76*4045d941Ssowmini 	if (nge_nd_get_prop_val(dip, propname, 0, 1, &propval)) \
77*4045d941Ssowmini 		ngep->fieldname = propval;			\
78*4045d941Ssowmini 	else							\
79*4045d941Ssowmini 		ngep->fieldname = initval;			\
80*4045d941Ssowmini }
81*4045d941Ssowmini 
82*4045d941Ssowmini static void
nge_nd_param_init(nge_t * ngep)83*4045d941Ssowmini nge_nd_param_init(nge_t *ngep)
846f3e57acSmx {
856f3e57acSmx 	dev_info_t *dip;
86*4045d941Ssowmini 	int propval;
876f3e57acSmx 
886f3e57acSmx 	dip = ngep->devinfo;
896f3e57acSmx 
90*4045d941Ssowmini 	/*
91*4045d941Ssowmini 	 * initialize values to those from driver.conf (if available)
92*4045d941Ssowmini 	 * or the default value otherwise.
93*4045d941Ssowmini 	 */
94*4045d941Ssowmini 	NGE_INIT_PROP("adv_autoneg_cap", param_adv_autoneg, 1);
95*4045d941Ssowmini 	NGE_INIT_PROP("adv_1000fdx_cap", param_adv_1000fdx, 1);
96*4045d941Ssowmini 	NGE_INIT_PROP("adv_1000hdx_cap", param_adv_1000hdx, 0);
97*4045d941Ssowmini 	NGE_INIT_PROP("adv_pause_cap", param_adv_pause, 1);
98*4045d941Ssowmini 	NGE_INIT_PROP("adv_asym_pause_cap", param_adv_asym_pause, 1);
99*4045d941Ssowmini 	NGE_INIT_PROP("adv_100fdx_cap", param_adv_100fdx, 1);
100*4045d941Ssowmini 	NGE_INIT_PROP("adv_100hdx_cap", param_adv_100hdx, 1);
101*4045d941Ssowmini 	NGE_INIT_PROP("adv_10fdx_cap", param_adv_10fdx, 1);
102*4045d941Ssowmini 	NGE_INIT_PROP("adv_10hdx_cap", param_adv_10hdx, 1);
1036f3e57acSmx }
1046f3e57acSmx 
1056f3e57acSmx int
nge_nd_init(nge_t * ngep)1066f3e57acSmx nge_nd_init(nge_t *ngep)
1076f3e57acSmx {
108*4045d941Ssowmini 	dev_info_t *dip;
1096f3e57acSmx 	int duplex;
1106f3e57acSmx 	int speed;
1116f3e57acSmx 
1126f3e57acSmx 	NGE_TRACE(("nge_nd_init($%p)", (void *)ngep));
113*4045d941Ssowmini 
1146f3e57acSmx 	/*
115*4045d941Ssowmini 	 * initialize from .conf file, if appropriate.
1166f3e57acSmx 	 */
117*4045d941Ssowmini 	nge_nd_param_init(ngep);
1186f3e57acSmx 
1196f3e57acSmx 	/*
1206f3e57acSmx 	 * The link speed may be forced to 10, 100 or 1000 Mbps using
1216f3e57acSmx 	 * the property "transfer-speed". This may be done in OBP by
1226f3e57acSmx 	 * using the command "apply transfer-speed=<speed> <device>".
1236f3e57acSmx 	 * The speed may be 10, 100 or 1000 - any other value will be
1246f3e57acSmx 	 * ignored.  Note that this does *enables* autonegotiation, but
1256f3e57acSmx 	 * restricts it to the speed specified by the property.
1266f3e57acSmx 	 */
1276f3e57acSmx 	dip = ngep->devinfo;
1286f3e57acSmx 	if (NGE_PROP_EXISTS(dip, transfer_speed_propname)) {
1296f3e57acSmx 
1306f3e57acSmx 		speed = NGE_PROP_GET_INT(dip, transfer_speed_propname);
1316f3e57acSmx 		nge_log(ngep, "%s property is %d",
1326f3e57acSmx 		    transfer_speed_propname, speed);
1336f3e57acSmx 
1346f3e57acSmx 		switch (speed) {
1356f3e57acSmx 		case 1000:
1366f3e57acSmx 			ngep->param_adv_autoneg = 1;
1376f3e57acSmx 			ngep->param_adv_1000fdx = 1;
1386f3e57acSmx 			ngep->param_adv_1000hdx = 0;
1396f3e57acSmx 			ngep->param_adv_100fdx = 0;
1406f3e57acSmx 			ngep->param_adv_100hdx = 0;
1416f3e57acSmx 			ngep->param_adv_10fdx = 0;
1426f3e57acSmx 			ngep->param_adv_10hdx = 0;
1436f3e57acSmx 			break;
1446f3e57acSmx 
1456f3e57acSmx 		case 100:
1466f3e57acSmx 			ngep->param_adv_autoneg = 1;
1476f3e57acSmx 			ngep->param_adv_1000fdx = 0;
1486f3e57acSmx 			ngep->param_adv_1000hdx = 0;
1496f3e57acSmx 			ngep->param_adv_100fdx = 1;
1506f3e57acSmx 			ngep->param_adv_100hdx = 1;
1516f3e57acSmx 			ngep->param_adv_10fdx = 0;
1526f3e57acSmx 			ngep->param_adv_10hdx = 0;
1536f3e57acSmx 			break;
1546f3e57acSmx 
1556f3e57acSmx 		case 10:
1566f3e57acSmx 			ngep->param_adv_autoneg = 1;
1576f3e57acSmx 			ngep->param_adv_1000fdx = 0;
1586f3e57acSmx 			ngep->param_adv_1000hdx = 0;
1596f3e57acSmx 			ngep->param_adv_100fdx = 0;
1606f3e57acSmx 			ngep->param_adv_100hdx = 0;
1616f3e57acSmx 			ngep->param_adv_10fdx = 1;
1626f3e57acSmx 			ngep->param_adv_10hdx = 1;
1636f3e57acSmx 			break;
1646f3e57acSmx 
1656f3e57acSmx 		default:
1666f3e57acSmx 			break;
1676f3e57acSmx 		}
1686f3e57acSmx 	}
1696f3e57acSmx 
1706f3e57acSmx 	/*
1716f3e57acSmx 	 * Also check the "speed" and "full-duplex" properties.  Setting
1726f3e57acSmx 	 * these properties will override all other settings and *disable*
1736f3e57acSmx 	 * autonegotiation, so both should be specified if either one is.
1746f3e57acSmx 	 * Otherwise, the unspecified parameter will be set to a default
1756f3e57acSmx 	 * value (1000Mb/s, full-duplex).
1766f3e57acSmx 	 */
1776f3e57acSmx 	if (NGE_PROP_EXISTS(dip, speed_propname) ||
1786f3e57acSmx 	    NGE_PROP_EXISTS(dip, duplex_propname)) {
1796f3e57acSmx 
1806f3e57acSmx 		ngep->param_adv_autoneg = 0;
1816f3e57acSmx 		ngep->param_adv_1000fdx = 1;
1826f3e57acSmx 		ngep->param_adv_1000hdx = 0;
1836f3e57acSmx 		ngep->param_adv_100fdx = 1;
1846f3e57acSmx 		ngep->param_adv_100hdx = 1;
1856f3e57acSmx 		ngep->param_adv_10fdx = 1;
1866f3e57acSmx 		ngep->param_adv_10hdx = 1;
1876f3e57acSmx 
1886f3e57acSmx 		speed = NGE_PROP_GET_INT(dip, speed_propname);
1896f3e57acSmx 		duplex = NGE_PROP_GET_INT(dip, duplex_propname);
1906f3e57acSmx 		nge_log(ngep, "%s property is %d",
1916f3e57acSmx 		    speed_propname, speed);
1926f3e57acSmx 		nge_log(ngep, "%s property is %d",
1936f3e57acSmx 		    duplex_propname, duplex);
1946f3e57acSmx 
1956f3e57acSmx 		switch (speed) {
1966f3e57acSmx 		case 1000:
1976f3e57acSmx 		default:
1986f3e57acSmx 			ngep->param_adv_100fdx = 0;
1996f3e57acSmx 			ngep->param_adv_100hdx = 0;
2006f3e57acSmx 			ngep->param_adv_10fdx = 0;
2016f3e57acSmx 			ngep->param_adv_10hdx = 0;
2026f3e57acSmx 			break;
2036f3e57acSmx 
2046f3e57acSmx 		case 100:
2056f3e57acSmx 			ngep->param_adv_1000fdx = 0;
2066f3e57acSmx 			ngep->param_adv_1000hdx = 0;
2076f3e57acSmx 			ngep->param_adv_10fdx = 0;
2086f3e57acSmx 			ngep->param_adv_10hdx = 0;
2096f3e57acSmx 			break;
2106f3e57acSmx 
2116f3e57acSmx 		case 10:
2126f3e57acSmx 			ngep->param_adv_1000fdx = 0;
2136f3e57acSmx 			ngep->param_adv_1000hdx = 0;
2146f3e57acSmx 			ngep->param_adv_100fdx = 0;
2156f3e57acSmx 			ngep->param_adv_100hdx = 0;
2166f3e57acSmx 			break;
2176f3e57acSmx 		}
2186f3e57acSmx 
2196f3e57acSmx 		switch (duplex) {
2206f3e57acSmx 		default:
2216f3e57acSmx 		case 1:
2226f3e57acSmx 			ngep->param_adv_1000hdx = 0;
2236f3e57acSmx 			ngep->param_adv_100hdx = 0;
2246f3e57acSmx 			ngep->param_adv_10hdx = 0;
2256f3e57acSmx 			break;
2266f3e57acSmx 
2276f3e57acSmx 		case 0:
2286f3e57acSmx 			ngep->param_adv_1000fdx = 0;
2296f3e57acSmx 			ngep->param_adv_100fdx = 0;
2306f3e57acSmx 			ngep->param_adv_10fdx = 0;
2316f3e57acSmx 			break;
2326f3e57acSmx 		}
2336f3e57acSmx 	}
2346f3e57acSmx 
235*4045d941Ssowmini 
2365a3d0718Smx 	nge_param_sync(ngep);
2375a3d0718Smx 
2386f3e57acSmx 	return (0);
2396f3e57acSmx }
240