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.
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.
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]
23 * Copyright 2008 NetXen, Inc. All rights reserved.
24 * Use is subject to license terms.
29 static char transfer_speed_propname
[] = "transfer-speed";
30 static char speed_propname
[] = "speed";
31 static char duplex_propname
[] = "full-duplex";
35 * The first character of the <name> field encodes the read/write
36 * status of the parameter:
41 * For writable parameters, we check for a driver property with the
42 * same name; if found, and its value is in range, we initialise
43 * the parameter from the property, overriding the default in the
46 * A NULL in the <name> field terminates the array.
48 * The <info> field is used here to provide the index of the
49 * parameter to be initialised; thus it doesn't matter whether
50 * this table is kept ordered or not.
52 * The <info> field in the per-instance copy, on the other hand,
53 * is used to count assignments so that we can tell when a magic
54 * parameter has been set via ndd (see unm_param_set()).
56 static const nd_param_t nd_template_10000
[] = {
57 /* info min max init r/w+name */
59 /* Our hardware capabilities */
60 { PARAM_AUTONEG_CAP
, 0, 1, 1, "-autoneg_cap" },
61 { PARAM_PAUSE_CAP
, 0, 1, 1, "-pause_cap" },
62 { PARAM_ASYM_PAUSE_CAP
, 0, 1, 1, "-asym_pause_cap" },
63 { PARAM_10000FDX_CAP
, 0, 1, 1, "-10000fdx_cap" },
64 { PARAM_1000FDX_CAP
, 0, 1, 0, "-1000fdx_cap" },
65 { PARAM_1000HDX_CAP
, 0, 1, 0, "-1000hdx_cap" },
66 { PARAM_100T4_CAP
, 0, 1, 0, "-100T4_cap" },
67 { PARAM_100FDX_CAP
, 0, 1, 0, "-100fdx_cap" },
68 { PARAM_100HDX_CAP
, 0, 1, 0, "-100hdx_cap" },
69 { PARAM_10FDX_CAP
, 0, 1, 0, "-10fdx_cap" },
70 { PARAM_10HDX_CAP
, 0, 1, 0, "-10hdx_cap" },
72 /* Our advertised capabilities */
73 { PARAM_ADV_AUTONEG_CAP
, 0, 1, 1, "-adv_autoneg_cap" },
74 { PARAM_ADV_PAUSE_CAP
, 0, 1, 1, "+adv_pause_cap" },
75 { PARAM_ADV_ASYM_PAUSE_CAP
, 0, 1, 1, "+adv_asym_pause_cap" },
76 { PARAM_ADV_10000FDX_CAP
, 0, 1, 1, "+adv_10000fdx_cap" },
77 { PARAM_ADV_1000FDX_CAP
, 0, 1, 0, "+adv_1000fdx_cap" },
78 { PARAM_ADV_1000HDX_CAP
, 0, 1, 0, "-adv_1000hdx_cap" },
79 { PARAM_ADV_100T4_CAP
, 0, 1, 0, "-adv_100T4_cap" },
80 { PARAM_ADV_100FDX_CAP
, 0, 1, 0, "+adv_100fdx_cap" },
81 { PARAM_ADV_100HDX_CAP
, 0, 1, 0, "+adv_100hdx_cap" },
82 { PARAM_ADV_10FDX_CAP
, 0, 1, 0, "+adv_10fdx_cap" },
83 { PARAM_ADV_10HDX_CAP
, 0, 1, 0, "+adv_10hdx_cap" },
85 /* Current operating modes */
86 { PARAM_LINK_STATUS
, 0, 1, 0, "-link_status" },
87 { PARAM_LINK_SPEED
, 0, 10000, 0, "-link_speed" },
88 { PARAM_LINK_DUPLEX
, 0, 2, 0, "-link_duplex" },
91 { PARAM_LOOP_MODE
, 0, 2, 0, "-loop_mode" },
94 { PARAM_COUNT
, 0, 0, 0, NULL
}
97 static const nd_param_t nd_template_1000
[] = {
98 /* info min max init r/w+name */
100 /* Our hardware capabilities */
101 { PARAM_AUTONEG_CAP
, 0, 1, 1, "-autoneg_cap" },
102 { PARAM_PAUSE_CAP
, 0, 1, 1, "-pause_cap" },
103 { PARAM_ASYM_PAUSE_CAP
, 0, 1, 1, "-asym_pause_cap" },
104 { PARAM_1000FDX_CAP
, 0, 1, 1, "-1000fdx_cap" },
105 { PARAM_1000HDX_CAP
, 0, 1, 0, "-1000hdx_cap" },
106 { PARAM_100T4_CAP
, 0, 1, 0, "-100T4_cap" },
107 { PARAM_100FDX_CAP
, 0, 1, 0, "-100fdx_cap" },
108 { PARAM_100HDX_CAP
, 0, 1, 0, "-100hdx_cap" },
109 { PARAM_10FDX_CAP
, 0, 1, 0, "-10fdx_cap" },
110 { PARAM_10HDX_CAP
, 0, 1, 0, "-10hdx_cap" },
112 /* Our advertised capabilities */
113 { PARAM_ADV_AUTONEG_CAP
, 0, 1, 1, "-adv_autoneg_cap" },
114 { PARAM_ADV_PAUSE_CAP
, 0, 1, 1, "+adv_pause_cap" },
115 { PARAM_ADV_ASYM_PAUSE_CAP
, 0, 1, 1, "+adv_asym_pause_cap" },
116 { PARAM_ADV_1000FDX_CAP
, 0, 1, 1, "+adv_1000fdx_cap" },
117 { PARAM_ADV_1000HDX_CAP
, 0, 1, 0, "-adv_1000hdx_cap" },
118 { PARAM_ADV_100T4_CAP
, 0, 1, 0, "-adv_100T4_cap" },
119 { PARAM_ADV_100FDX_CAP
, 0, 1, 0, "+adv_100fdx_cap" },
120 { PARAM_ADV_100HDX_CAP
, 0, 1, 0, "+adv_100hdx_cap" },
121 { PARAM_ADV_10FDX_CAP
, 0, 1, 0, "+adv_10fdx_cap" },
122 { PARAM_ADV_10HDX_CAP
, 0, 1, 0, "+adv_10hdx_cap" },
124 /* Current operating modes */
125 { PARAM_LINK_STATUS
, 0, 1, 0, "-link_status" },
126 { PARAM_LINK_SPEED
, 0, 1000, 0, "-link_speed" },
127 { PARAM_LINK_DUPLEX
, 0, 2, 0, "-link_duplex" },
129 /* Loopback status */
130 { PARAM_LOOP_MODE
, 0, 2, 0, "-loop_mode" },
133 { PARAM_COUNT
, 0, 0, 0, NULL
}
136 /* ============== NDD Support Functions =============== */
139 * Extracts the value from the unm parameter array and prints
140 * the parameter value. cp points to the required parameter.
144 unm_param_get(queue_t
*q
, mblk_t
*mp
, caddr_t cp
, cred_t
*credp
)
148 ndp
= (nd_param_t
*)(uintptr_t)cp
;
149 (void) mi_mpprintf(mp
, "%d", ndp
->ndp_val
);
155 * Validates the request to set a UNM parameter to a specific value.
156 * If the request is OK, the parameter is set. Also the <info> field
157 * is incremented to show that the parameter was touched, even though
158 * it may have been set to the same value it already had.
162 unm_param_set(queue_t
*q
, mblk_t
*mp
, char *value
, caddr_t cp
, cred_t
*credp
)
168 ndp
= (nd_param_t
*)(uintptr_t)cp
;
169 new_value
= mi_strtol(value
, &end
, 10);
172 if (new_value
< ndp
->ndp_min
|| new_value
> ndp
->ndp_max
)
175 ndp
->ndp_val
= new_value
;
181 * Initialise the per-instance parameter array from the global prototype,
182 * and register each element with the named dispatch handler using nd_load()
185 unm_param_register(unm_adapter
*adapter
)
187 const nd_param_t
*tmplp
;
196 nddpp
= &adapter
->nd_data_p
;
197 ASSERT(*nddpp
== NULL
);
199 if (adapter
->ahw
.board_type
== UNM_NIC_XGBE
)
200 tmplp
= nd_template_10000
;
202 tmplp
= nd_template_1000
;
204 for (; tmplp
->ndp_name
!= NULL
; ++tmplp
) {
206 * Copy the template from nd_template[] into the
207 * proper slot in the per-instance parameters,
208 * then register the parameter with nd_load()
210 ndp
= &adapter
->nd_params
[tmplp
->ndp_info
];
212 nm
= &ndp
->ndp_name
[0];
213 setfn
= unm_param_set
;
228 if (!nd_load(nddpp
, ++nm
, unm_param_get
, setfn
, (caddr_t
)ndp
))
232 * If the parameter is writable, and there's a property
233 * with the same name, and its value is in range, we use
234 * it to initialise the parameter. If it exists but is
235 * out of range, it's ignored.
237 if (setfn
&& UNM_PROP_EXISTS(dip
, nm
)) {
238 pval
= UNM_PROP_GET_INT(dip
, nm
);
239 if (pval
>= ndp
->ndp_min
&& pval
<= ndp
->ndp_max
)
244 DPRINTF(1, (CE_WARN
, "unm_param_register: OK"));
245 return (DDI_SUCCESS
);
248 if (adapter
->ahw
.board_type
== UNM_NIC_XGBE
) {
250 "unm_param_register: FAILED at index %d [info %d]",
251 (int)(tmplp
-nd_template_10000
), tmplp
->ndp_info
);
254 "unm_param_register: FAILED at index %d [info %d]",
255 (int)(tmplp
-nd_template_1000
), tmplp
->ndp_info
);
258 return (DDI_FAILURE
);
262 unm_nd_init(unm_adapter
*adapter
)
269 * Register all the per-instance properties, initialising
270 * them from the table above or from driver properties set
273 if (unm_param_register(adapter
) != DDI_SUCCESS
)
277 * The link speed may be forced to 1000 or 10000 Mbps using
278 * the property "transfer-speed". This may be done in OBP by
279 * using the command "apply transfer-speed=<speed> <device>".
280 * The speed may be 1000 or 10000 - any other value will be
281 * ignored. Note that this does *enables* autonegotiation, but
282 * restricts it to the speed specified by the property.
285 if (UNM_PROP_EXISTS(dip
, transfer_speed_propname
)) {
287 speed
= UNM_PROP_GET_INT(dip
, transfer_speed_propname
);
291 adapter
->param_adv_autoneg
= 1;
292 adapter
->param_adv_10000fdx
= 1;
293 adapter
->param_adv_1000fdx
= 0;
294 adapter
->param_adv_1000hdx
= 0;
295 adapter
->param_adv_100fdx
= 0;
296 adapter
->param_adv_100hdx
= 0;
297 adapter
->param_adv_10fdx
= 0;
298 adapter
->param_adv_10hdx
= 0;
302 adapter
->param_adv_autoneg
= 1;
303 adapter
->param_adv_1000fdx
= 1;
304 adapter
->param_adv_1000hdx
= 1;
305 adapter
->param_adv_100fdx
= 0;
306 adapter
->param_adv_100hdx
= 0;
307 adapter
->param_adv_10fdx
= 0;
308 adapter
->param_adv_10hdx
= 0;
312 adapter
->param_adv_autoneg
= 1;
313 adapter
->param_adv_1000fdx
= 0;
314 adapter
->param_adv_1000hdx
= 0;
315 adapter
->param_adv_100fdx
= 1;
316 adapter
->param_adv_100hdx
= 1;
317 adapter
->param_adv_10fdx
= 0;
318 adapter
->param_adv_10hdx
= 0;
322 adapter
->param_adv_autoneg
= 1;
323 adapter
->param_adv_1000fdx
= 0;
324 adapter
->param_adv_1000hdx
= 0;
325 adapter
->param_adv_100fdx
= 0;
326 adapter
->param_adv_100hdx
= 0;
327 adapter
->param_adv_10fdx
= 1;
328 adapter
->param_adv_10hdx
= 1;
337 * Also check the "speed" and "full-duplex" properties. Setting
338 * these properties will override all other settings and *disable*
339 * autonegotiation, so both should be specified if either one is.
340 * Otherwise, the unspecified parameter will be set to a default
341 * value (10000Mb/s, full-duplex).
343 if (UNM_PROP_EXISTS(dip
, speed_propname
) ||
344 UNM_PROP_EXISTS(dip
, duplex_propname
)) {
346 adapter
->param_adv_autoneg
= 0;
347 adapter
->param_adv_10000fdx
= 1;
348 adapter
->param_adv_1000fdx
= 1;
349 adapter
->param_adv_1000hdx
= 1;
350 adapter
->param_adv_100fdx
= 1;
351 adapter
->param_adv_100hdx
= 1;
352 adapter
->param_adv_10fdx
= 1;
353 adapter
->param_adv_10hdx
= 1;
355 speed
= UNM_PROP_GET_INT(dip
, speed_propname
);
356 duplex
= UNM_PROP_GET_INT(dip
, duplex_propname
);
361 adapter
->param_adv_1000fdx
= 0;
362 adapter
->param_adv_1000hdx
= 0;
363 adapter
->param_adv_100fdx
= 0;
364 adapter
->param_adv_100hdx
= 0;
365 adapter
->param_adv_10fdx
= 0;
366 adapter
->param_adv_10hdx
= 0;
370 adapter
->param_adv_10000fdx
= 0;
371 adapter
->param_adv_100fdx
= 0;
372 adapter
->param_adv_100hdx
= 0;
373 adapter
->param_adv_10fdx
= 0;
374 adapter
->param_adv_10hdx
= 0;
378 adapter
->param_adv_10000fdx
= 0;
379 adapter
->param_adv_1000fdx
= 0;
380 adapter
->param_adv_1000hdx
= 0;
381 adapter
->param_adv_10fdx
= 0;
382 adapter
->param_adv_10hdx
= 0;
386 adapter
->param_adv_10000fdx
= 0;
387 adapter
->param_adv_1000fdx
= 0;
388 adapter
->param_adv_1000hdx
= 0;
389 adapter
->param_adv_100fdx
= 0;
390 adapter
->param_adv_100hdx
= 0;
397 adapter
->param_adv_1000hdx
= 0;
398 adapter
->param_adv_100hdx
= 0;
399 adapter
->param_adv_10hdx
= 0;
403 adapter
->param_adv_10000fdx
= 0;
404 adapter
->param_adv_1000fdx
= 0;
405 adapter
->param_adv_100fdx
= 0;
406 adapter
->param_adv_10fdx
= 0;
411 DPRINTF(1, (CE_WARN
, "unm_nd_init: autoneg %d"
412 "pause %d asym_pause %d "
414 "1000fdx %d 1000hdx %d "
415 "100fdx %d 100hdx %d "
416 "10fdx %d 10hdx %d ",
417 adapter
->param_adv_autoneg
,
418 adapter
->param_adv_pause
, adapter
->param_adv_asym_pause
,
419 adapter
->param_adv_10000fdx
,
420 adapter
->param_adv_1000fdx
, adapter
->param_adv_1000hdx
,
421 adapter
->param_adv_100fdx
, adapter
->param_adv_100hdx
,
422 adapter
->param_adv_10fdx
, adapter
->param_adv_10hdx
));
428 unm_nd_ioctl(unm_adapter
*adapter
, queue_t
*wq
, mblk_t
*mp
, struct iocblk
*iocp
)
433 DPRINTF(1, (CE_WARN
, "unm_nd_ioctl($%p, $%p, $%p, $%p)",
434 (void *)adapter
, (void *)wq
, (void *)mp
, (void *)iocp
));
440 DPRINTF(-1, (CE_WARN
, "unm_nd_ioctl: invalid cmd 0x%x", cmd
));
445 * If nd_getset() returns B_FALSE, the command was
446 * not valid (e.g. unknown name), so we just tell the
447 * top-level ioctl code to send a NAK (with code EINVAL).
449 * Otherwise, nd_getset() will have built the reply to
450 * be sent (but not actually sent it), so we tell the
451 * caller to send the prepared reply.
453 ok
= nd_getset(wq
, adapter
->nd_data_p
, mp
);
454 DPRINTF(1, (CE_WARN
, "unm_nd_ioctl: get %s", ok
? "OK" :
456 return (ok
? IOC_REPLY
: IOC_INVAL
);
460 * All adv_* parameters are locked (read-only) while
461 * the device is in any sort of loopback mode ...
463 if (adapter
->param_loop_mode
!= UNM_LOOP_NONE
) {
464 iocp
->ioc_error
= EBUSY
;
468 ok
= nd_getset(wq
, adapter
->nd_data_p
, mp
);
471 * If nd_getset() returns B_FALSE, the command was
472 * not valid (e.g. unknown name), so we just tell
473 * the top-level ioctl code to send a NAK (with code
474 * EINVAL by default).
476 * Otherwise, nd_getset() will have built the reply to
477 * be sent - but that doesn't imply success! In some
478 * cases, the reply it's built will have a non-zero
479 * error code in it (e.g. EPERM if not superuser).
480 * So, we also drop out in that case ...
483 "unm_nd_ioctl: set %s err %d autoneg %d info %d",
484 ok
? "OK" : "FAIL", iocp
->ioc_error
,
485 adapter
->nd_params
[PARAM_ADV_AUTONEG_CAP
].ndp_val
,
486 adapter
->nd_params
[PARAM_ADV_AUTONEG_CAP
].ndp_info
));
492 return (IOC_RESTART_REPLY
);
496 /* Free the Named Dispatch Table by calling nd_free */
498 unm_nd_cleanup(unm_adapter
*adapter
)
500 nd_free(&adapter
->nd_data_p
);