c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * CDDL HEADER START
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * The contents of this file are subject to the terms of the
aa81749390e332985277568edab1ee6132326b42gs * Common Development and Distribution License (the "License").
aa81749390e332985277568edab1ee6132326b42gs * You may not use this file except in compliance with the License.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * See the License for the specific language governing permissions
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * and limitations under the License.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * When distributing Covered Code, include this CDDL HEADER in each
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * If applicable, add the following below this CDDL HEADER, with the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * fields enclosed by brackets "[]" replaced with your own identifying
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * information: Portions Copyright [yyyy] [name of copyright owner]
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * CDDL HEADER END
9e1a9180bec2232328687ae8e96007921a6ed05dLi-Zhen You * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Use is subject to license terms.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#define RGE_DBG RGE_DBG_NDD /* debug flag for this code */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Property names
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * The first character of the <name> field encodes the read/write
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * status of the parameter:
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * '-' => read-only,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * '!' => invisible!
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * For writable parameters, we check for a driver property with the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * same name; if found, and its value is in range, we initialise
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * the parameter from the property, overriding the default in the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * table below.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * A NULL in the <name> field terminates the array.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * The <info> field is used here to provide the index of the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * parameter to be initialised; thus it doesn't matter whether
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * this table is kept ordered or not.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * The <info> field in the per-instance copy, on the other hand,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * is used to count assignments so that we can tell when a magic
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * parameter has been set via ndd (see rge_param_set()).
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs/* info min max init r/w+name */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs/* Our hardware capabilities */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs/* Our advertised capabilities */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs{ PARAM_ADV_ASYM_PAUSE_CAP, 0, 1, 1, "+adv_asym_pause_cap" },
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs/* Current operating modes */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs/* Loopback status */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs/* Terminator */
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx/* nd_template for RTL8101E */
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx/* info min max init r/w+name */
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx/* Our hardware capabilities */
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx/* Our advertised capabilities */
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx{ PARAM_ADV_ASYM_PAUSE_CAP, 0, 1, 1, "+adv_asym_pause_cap" },
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx/* Current operating modes */
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx/* Loopback status */
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx/* Terminator */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs/* ============== NDD Support Functions =============== */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Extracts the value from the rge parameter array and prints
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * the parameter value. cp points to the required parameter.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsrge_param_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *credp)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs return (0);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Validates the request to set a RGE parameter to a specific value.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * If the request is OK, the parameter is set. Also the <info> field
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * is incremented to show that the parameter was touched, even though
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * it may have been set to the same value it already had.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsrge_param_set(queue_t *q, mblk_t *mp, char *value, caddr_t cp, cred_t *credp)
9e1a9180bec2232328687ae8e96007921a6ed05dLi-Zhen You (void) ddi_strtol(value, (char **)NULL, 0, &new_value);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs if (new_value < ndp->ndp_min || new_value > ndp->ndp_max)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs return (0);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Initialise the per-instance parameter array from the global prototype,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * and register each element with the named dispatch handler using nd_load()
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Copy the template from nd_template[] into the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * proper slot in the per-instance parameters,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * then register the parameter with nd_load()
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs switch (*nm) {
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs if (!nd_load(nddpp, ++nm, rge_param_get, setfn, (caddr_t)ndp))
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * If the parameter is writable, and there's a property
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * with the same name, and its value is in range, we use
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * it to initialise the parameter. If it exists but is
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * out of range, it's ignored.
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx RGE_DEBUG(("rge_param_register: FAILED at index %d [info %d]",
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx RGE_DEBUG(("rge_param_register: FAILED at index %d [info %d]",
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Register all the per-instance properties, initialising
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * them from the table above or from driver properties set
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * in the .conf file
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs return (-1);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * The link speed may be forced to 10, 100 or 1000 Mbps using
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * the property "transfer-speed". This may be done in OBP by
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * using the command "apply transfer-speed=<speed> <device>".
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * The speed may be 10, 100 or 1000 - any other value will be
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * ignored. Note that this does *enables* autonegotiation, but
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * restricts it to the speed specified by the property.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs switch (speed) {
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs case 1000:
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Also check the "speed" and "full-duplex" properties. Setting
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * these properties will override all other settings and *disable*
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * autonegotiation, so both should be specified if either one is.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Otherwise, the unspecified parameter will be set to a default
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * value (1000Mb/s, full-duplex).
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs switch (speed) {
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs case 1000:
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs switch (duplex) {
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "pause %d asym_pause %d "
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "1000fdx %d 1000hdx %d "
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "100fdx %d 100hdx %d "
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "10fdx %d 10hdx %d ",
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs return (0);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsrge_nd_ioctl(rge_t *rgep, queue_t *wq, mblk_t *mp, struct iocblk *iocp)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs switch (cmd) {
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* NOTREACHED */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * If nd_getset() returns B_FALSE, the command was
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * not valid (e.g. unknown name), so we just tell the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * top-level ioctl code to send a NAK (with code EINVAL).
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Otherwise, nd_getset() will have built the reply to
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * be sent (but not actually sent it), so we tell the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * caller to send the prepared reply.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * All adv_* parameters are locked (read-only) while
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * the device is in any sort of loopback mode ...
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Before calling nd_getset(), we save the <info> field
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * of the 'autonegotiation' parameter so that we can tell
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * whether it was assigned (even if its value doesn't
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * actually change).
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * If nd_getset() returns B_FALSE, the command was
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * not valid (e.g. unknown name), so we just tell
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * the top-level ioctl code to send a NAK (with code
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * EINVAL by default).
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Otherwise, nd_getset() will have built the reply to
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * be sent - but that doesn't imply success! In some
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * cases, the reply it's built will have a non-zero
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * error code in it (e.g. EPERM if not superuser).
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * So, we also drop out in that case ...
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs RGE_DEBUG(("rge_nd_ioctl: set %s err %d autoneg %d info %d/%d",
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs/* Free the Named Dispatch Table by calling nd_free */