summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/io/nge/nge_ndd.c
blob: 7c9a509a2b0a5005042ef1268f157bff19164017 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include "nge.h"

#undef	NGE_DBG
#define	NGE_DBG		NGE_DBG_NDD

static char transfer_speed_propname[] = "transfer-speed";
static char speed_propname[] = "speed";
static char duplex_propname[] = "full-duplex";

/*
 * synchronize the  adv* and en* parameters.
 *
 * See comments in <sys/dld.h> for details of the *_en_*
 * parameters.  The usage of ndd for setting adv parameters will
 * synchronize all the en parameters with the nge parameters,
 * implicitly disabling any settings made via dladm.
 */
static void
nge_param_sync(nge_t *ngep)
{
	ngep->param_en_pause = ngep->param_adv_pause;
	ngep->param_en_asym_pause = ngep->param_adv_asym_pause;
	ngep->param_en_1000fdx = ngep->param_adv_1000fdx;
	ngep->param_en_1000hdx = ngep->param_adv_1000hdx;
	ngep->param_en_100fdx = ngep->param_adv_100fdx;
	ngep->param_en_100hdx = ngep->param_adv_100hdx;
	ngep->param_en_10fdx = ngep->param_adv_10fdx;
	ngep->param_en_10hdx = ngep->param_adv_10hdx;
}


boolean_t
nge_nd_get_prop_val(dev_info_t *dip, char *nm, long min, long max, int *pval)
{
	/*
	 * If the parameter is writable, and there's a property
	 * with the same name, and its value is in range, we use
	 * it to initialise the parameter.  If it exists but is
	 * out of range, it's ignored.
	 */
	if (NGE_PROP_EXISTS(dip, nm)) {
		*pval = NGE_PROP_GET_INT(dip, nm);
		if (*pval >= min && *pval <= max)
			return (B_TRUE);
	}
	return (B_FALSE);
}

#define	NGE_INIT_PROP(propname, fieldname, initval) {		\
	if (nge_nd_get_prop_val(dip, propname, 0, 1, &propval)) \
		ngep->fieldname = propval;			\
	else							\
		ngep->fieldname = initval;			\
}

static void
nge_nd_param_init(nge_t *ngep)
{
	dev_info_t *dip;
	int propval;

	dip = ngep->devinfo;

	/*
	 * initialize values to those from driver.conf (if available)
	 * or the default value otherwise.
	 */
	NGE_INIT_PROP("adv_autoneg_cap", param_adv_autoneg, 1);
	NGE_INIT_PROP("adv_1000fdx_cap", param_adv_1000fdx, 1);
	NGE_INIT_PROP("adv_1000hdx_cap", param_adv_1000hdx, 0);
	NGE_INIT_PROP("adv_pause_cap", param_adv_pause, 1);
	NGE_INIT_PROP("adv_asym_pause_cap", param_adv_asym_pause, 1);
	NGE_INIT_PROP("adv_100fdx_cap", param_adv_100fdx, 1);
	NGE_INIT_PROP("adv_100hdx_cap", param_adv_100hdx, 1);
	NGE_INIT_PROP("adv_10fdx_cap", param_adv_10fdx, 1);
	NGE_INIT_PROP("adv_10hdx_cap", param_adv_10hdx, 1);
}

int
nge_nd_init(nge_t *ngep)
{
	dev_info_t *dip;
	int duplex;
	int speed;

	NGE_TRACE(("nge_nd_init($%p)", (void *)ngep));

	/*
	 * initialize from .conf file, if appropriate.
	 */
	nge_nd_param_init(ngep);

	/*
	 * The link speed may be forced to 10, 100 or 1000 Mbps using
	 * the property "transfer-speed". This may be done in OBP by
	 * using the command "apply transfer-speed=<speed> <device>".
	 * The speed may be 10, 100 or 1000 - any other value will be
	 * ignored.  Note that this does *enables* autonegotiation, but
	 * restricts it to the speed specified by the property.
	 */
	dip = ngep->devinfo;
	if (NGE_PROP_EXISTS(dip, transfer_speed_propname)) {

		speed = NGE_PROP_GET_INT(dip, transfer_speed_propname);
		nge_log(ngep, "%s property is %d",
		    transfer_speed_propname, speed);

		switch (speed) {
		case 1000:
			ngep->param_adv_autoneg = 1;
			ngep->param_adv_1000fdx = 1;
			ngep->param_adv_1000hdx = 0;
			ngep->param_adv_100fdx = 0;
			ngep->param_adv_100hdx = 0;
			ngep->param_adv_10fdx = 0;
			ngep->param_adv_10hdx = 0;
			break;

		case 100:
			ngep->param_adv_autoneg = 1;
			ngep->param_adv_1000fdx = 0;
			ngep->param_adv_1000hdx = 0;
			ngep->param_adv_100fdx = 1;
			ngep->param_adv_100hdx = 1;
			ngep->param_adv_10fdx = 0;
			ngep->param_adv_10hdx = 0;
			break;

		case 10:
			ngep->param_adv_autoneg = 1;
			ngep->param_adv_1000fdx = 0;
			ngep->param_adv_1000hdx = 0;
			ngep->param_adv_100fdx = 0;
			ngep->param_adv_100hdx = 0;
			ngep->param_adv_10fdx = 1;
			ngep->param_adv_10hdx = 1;
			break;

		default:
			break;
		}
	}

	/*
	 * Also check the "speed" and "full-duplex" properties.  Setting
	 * these properties will override all other settings and *disable*
	 * autonegotiation, so both should be specified if either one is.
	 * Otherwise, the unspecified parameter will be set to a default
	 * value (1000Mb/s, full-duplex).
	 */
	if (NGE_PROP_EXISTS(dip, speed_propname) ||
	    NGE_PROP_EXISTS(dip, duplex_propname)) {

		ngep->param_adv_autoneg = 0;
		ngep->param_adv_1000fdx = 1;
		ngep->param_adv_1000hdx = 0;
		ngep->param_adv_100fdx = 1;
		ngep->param_adv_100hdx = 1;
		ngep->param_adv_10fdx = 1;
		ngep->param_adv_10hdx = 1;

		speed = NGE_PROP_GET_INT(dip, speed_propname);
		duplex = NGE_PROP_GET_INT(dip, duplex_propname);
		nge_log(ngep, "%s property is %d",
		    speed_propname, speed);
		nge_log(ngep, "%s property is %d",
		    duplex_propname, duplex);

		switch (speed) {
		case 1000:
		default:
			ngep->param_adv_100fdx = 0;
			ngep->param_adv_100hdx = 0;
			ngep->param_adv_10fdx = 0;
			ngep->param_adv_10hdx = 0;
			break;

		case 100:
			ngep->param_adv_1000fdx = 0;
			ngep->param_adv_1000hdx = 0;
			ngep->param_adv_10fdx = 0;
			ngep->param_adv_10hdx = 0;
			break;

		case 10:
			ngep->param_adv_1000fdx = 0;
			ngep->param_adv_1000hdx = 0;
			ngep->param_adv_100fdx = 0;
			ngep->param_adv_100hdx = 0;
			break;
		}

		switch (duplex) {
		default:
		case 1:
			ngep->param_adv_1000hdx = 0;
			ngep->param_adv_100hdx = 0;
			ngep->param_adv_10hdx = 0;
			break;

		case 0:
			ngep->param_adv_1000fdx = 0;
			ngep->param_adv_100fdx = 0;
			ngep->param_adv_10fdx = 0;
			break;
		}
	}


	nge_param_sync(ngep);

	return (0);
}