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