xref: /titanic_52/usr/src/uts/common/io/nge/nge_ndd.c (revision 0a0e9771ca0211c15f3ac4466b661c145feeb9e4)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include "nge.h"
30 
31 #undef	NGE_DBG
32 #define	NGE_DBG		NGE_DBG_NDD
33 
34 static char transfer_speed_propname[] = "transfer-speed";
35 static char speed_propname[] = "speed";
36 static char duplex_propname[] = "full-duplex";
37 
38 /*
39  * synchronize the  adv* and en* parameters.
40  *
41  * See comments in <sys/dld.h> for details of the *_en_*
42  * parameters.  The usage of ndd for setting adv parameters will
43  * synchronize all the en parameters with the nge parameters,
44  * implicitly disabling any settings made via dladm.
45  */
46 static void
47 nge_param_sync(nge_t *ngep)
48 {
49 	ngep->param_en_pause = ngep->param_adv_pause;
50 	ngep->param_en_asym_pause = ngep->param_adv_asym_pause;
51 	ngep->param_en_1000fdx = ngep->param_adv_1000fdx;
52 	ngep->param_en_1000hdx = ngep->param_adv_1000hdx;
53 	ngep->param_en_100fdx = ngep->param_adv_100fdx;
54 	ngep->param_en_100hdx = ngep->param_adv_100hdx;
55 	ngep->param_en_10fdx = ngep->param_adv_10fdx;
56 	ngep->param_en_10hdx = ngep->param_adv_10hdx;
57 }
58 
59 
60 boolean_t
61 nge_nd_get_prop_val(dev_info_t *dip, char *nm, long min, long max, int *pval)
62 {
63 	/*
64 	 * If the parameter is writable, and there's a property
65 	 * with the same name, and its value is in range, we use
66 	 * it to initialise the parameter.  If it exists but is
67 	 * out of range, it's ignored.
68 	 */
69 	if (NGE_PROP_EXISTS(dip, nm)) {
70 		*pval = NGE_PROP_GET_INT(dip, nm);
71 		if (*pval >= min && *pval <= max)
72 			return (B_TRUE);
73 	}
74 	return (B_FALSE);
75 }
76 
77 #define	NGE_INIT_PROP(propname, fieldname, initval) {		\
78 	if (nge_nd_get_prop_val(dip, propname, 0, 1, &propval)) \
79 		ngep->fieldname = propval;			\
80 	else							\
81 		ngep->fieldname = initval;			\
82 }
83 
84 static void
85 nge_nd_param_init(nge_t *ngep)
86 {
87 	dev_info_t *dip;
88 	int propval;
89 
90 	dip = ngep->devinfo;
91 
92 	/*
93 	 * initialize values to those from driver.conf (if available)
94 	 * or the default value otherwise.
95 	 */
96 	NGE_INIT_PROP("adv_autoneg_cap", param_adv_autoneg, 1);
97 	NGE_INIT_PROP("adv_1000fdx_cap", param_adv_1000fdx, 1);
98 	NGE_INIT_PROP("adv_1000hdx_cap", param_adv_1000hdx, 0);
99 	NGE_INIT_PROP("adv_pause_cap", param_adv_pause, 1);
100 	NGE_INIT_PROP("adv_asym_pause_cap", param_adv_asym_pause, 1);
101 	NGE_INIT_PROP("adv_100fdx_cap", param_adv_100fdx, 1);
102 	NGE_INIT_PROP("adv_100hdx_cap", param_adv_100hdx, 1);
103 	NGE_INIT_PROP("adv_10fdx_cap", param_adv_10fdx, 1);
104 	NGE_INIT_PROP("adv_10hdx_cap", param_adv_10hdx, 1);
105 }
106 
107 int
108 nge_nd_init(nge_t *ngep)
109 {
110 	dev_info_t *dip;
111 	int duplex;
112 	int speed;
113 
114 	NGE_TRACE(("nge_nd_init($%p)", (void *)ngep));
115 
116 	/*
117 	 * initialize from .conf file, if appropriate.
118 	 */
119 	nge_nd_param_init(ngep);
120 
121 	/*
122 	 * The link speed may be forced to 10, 100 or 1000 Mbps using
123 	 * the property "transfer-speed". This may be done in OBP by
124 	 * using the command "apply transfer-speed=<speed> <device>".
125 	 * The speed may be 10, 100 or 1000 - any other value will be
126 	 * ignored.  Note that this does *enables* autonegotiation, but
127 	 * restricts it to the speed specified by the property.
128 	 */
129 	dip = ngep->devinfo;
130 	if (NGE_PROP_EXISTS(dip, transfer_speed_propname)) {
131 
132 		speed = NGE_PROP_GET_INT(dip, transfer_speed_propname);
133 		nge_log(ngep, "%s property is %d",
134 		    transfer_speed_propname, speed);
135 
136 		switch (speed) {
137 		case 1000:
138 			ngep->param_adv_autoneg = 1;
139 			ngep->param_adv_1000fdx = 1;
140 			ngep->param_adv_1000hdx = 0;
141 			ngep->param_adv_100fdx = 0;
142 			ngep->param_adv_100hdx = 0;
143 			ngep->param_adv_10fdx = 0;
144 			ngep->param_adv_10hdx = 0;
145 			break;
146 
147 		case 100:
148 			ngep->param_adv_autoneg = 1;
149 			ngep->param_adv_1000fdx = 0;
150 			ngep->param_adv_1000hdx = 0;
151 			ngep->param_adv_100fdx = 1;
152 			ngep->param_adv_100hdx = 1;
153 			ngep->param_adv_10fdx = 0;
154 			ngep->param_adv_10hdx = 0;
155 			break;
156 
157 		case 10:
158 			ngep->param_adv_autoneg = 1;
159 			ngep->param_adv_1000fdx = 0;
160 			ngep->param_adv_1000hdx = 0;
161 			ngep->param_adv_100fdx = 0;
162 			ngep->param_adv_100hdx = 0;
163 			ngep->param_adv_10fdx = 1;
164 			ngep->param_adv_10hdx = 1;
165 			break;
166 
167 		default:
168 			break;
169 		}
170 	}
171 
172 	/*
173 	 * Also check the "speed" and "full-duplex" properties.  Setting
174 	 * these properties will override all other settings and *disable*
175 	 * autonegotiation, so both should be specified if either one is.
176 	 * Otherwise, the unspecified parameter will be set to a default
177 	 * value (1000Mb/s, full-duplex).
178 	 */
179 	if (NGE_PROP_EXISTS(dip, speed_propname) ||
180 	    NGE_PROP_EXISTS(dip, duplex_propname)) {
181 
182 		ngep->param_adv_autoneg = 0;
183 		ngep->param_adv_1000fdx = 1;
184 		ngep->param_adv_1000hdx = 0;
185 		ngep->param_adv_100fdx = 1;
186 		ngep->param_adv_100hdx = 1;
187 		ngep->param_adv_10fdx = 1;
188 		ngep->param_adv_10hdx = 1;
189 
190 		speed = NGE_PROP_GET_INT(dip, speed_propname);
191 		duplex = NGE_PROP_GET_INT(dip, duplex_propname);
192 		nge_log(ngep, "%s property is %d",
193 		    speed_propname, speed);
194 		nge_log(ngep, "%s property is %d",
195 		    duplex_propname, duplex);
196 
197 		switch (speed) {
198 		case 1000:
199 		default:
200 			ngep->param_adv_100fdx = 0;
201 			ngep->param_adv_100hdx = 0;
202 			ngep->param_adv_10fdx = 0;
203 			ngep->param_adv_10hdx = 0;
204 			break;
205 
206 		case 100:
207 			ngep->param_adv_1000fdx = 0;
208 			ngep->param_adv_1000hdx = 0;
209 			ngep->param_adv_10fdx = 0;
210 			ngep->param_adv_10hdx = 0;
211 			break;
212 
213 		case 10:
214 			ngep->param_adv_1000fdx = 0;
215 			ngep->param_adv_1000hdx = 0;
216 			ngep->param_adv_100fdx = 0;
217 			ngep->param_adv_100hdx = 0;
218 			break;
219 		}
220 
221 		switch (duplex) {
222 		default:
223 		case 1:
224 			ngep->param_adv_1000hdx = 0;
225 			ngep->param_adv_100hdx = 0;
226 			ngep->param_adv_10hdx = 0;
227 			break;
228 
229 		case 0:
230 			ngep->param_adv_1000fdx = 0;
231 			ngep->param_adv_100fdx = 0;
232 			ngep->param_adv_10fdx = 0;
233 			break;
234 		}
235 	}
236 
237 
238 	nge_param_sync(ngep);
239 
240 	return (0);
241 }
242