rge_ndd.c revision 27dcfa4c56aa595f49377fbd0272cd1752b94ad8
/*
* 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
* 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.
*/
#include "rge.h"
/*
* Property names
*/
static char transfer_speed_propname[] = "transfer-speed";
static char speed_propname[] = "speed";
static char duplex_propname[] = "full-duplex";
/*
* Notes:
* status of the parameter:
* '-' => read-only,
* '!' => invisible!
*
* For writable parameters, we check for a driver property with the
* same name; if found, and its value is in range, we initialise
* the parameter from the property, overriding the default in the
* table below.
*
* A NULL in the <name> field terminates the array.
*
* The <info> field is used here to provide the index of the
* parameter to be initialised; thus it doesn't matter whether
* this table is kept ordered or not.
*
* The <info> field in the per-instance copy, on the other hand,
* is used to count assignments so that we can tell when a magic
* parameter has been set via ndd (see rge_param_set()).
*/
static const nd_param_t nd_template_1000[] = {
/* info min max init r/w+name */
/* Our hardware capabilities */
/* Our advertised capabilities */
/* Current operating modes */
/* Loopback status */
/* Terminator */
{ PARAM_COUNT, 0, 0, 0, NULL }
};
/* nd_template for RTL8101E */
static const nd_param_t nd_template_100[] = {
/* info min max init r/w+name */
/* Our hardware capabilities */
/* Our advertised capabilities */
/* Current operating modes */
/* Loopback status */
/* Terminator */
{ PARAM_COUNT, 0, 0, 0, NULL }
};
/* ============== NDD Support Functions =============== */
/*
* Extracts the value from the rge parameter array and prints
* the parameter value. cp points to the required parameter.
*/
static int
{
return (0);
}
/*
* Validates the request to set a RGE parameter to a specific value.
* If the request is OK, the parameter is set. Also the <info> field
* is incremented to show that the parameter was touched, even though
* it may have been set to the same value it already had.
*/
static int
{
long new_value;
char *end;
return (EINVAL);
return (EINVAL);
return (0);
}
/*
* Initialise the per-instance parameter array from the global prototype,
* and register each element with the named dispatch handler using nd_load()
*/
static int
{
const nd_param_t *tmplp;
char *nm;
int pval;
else
/*
* Copy the template from nd_template[] into the
* proper slot in the per-instance parameters,
* then register the parameter with nd_load()
*/
switch (*nm) {
default:
case '!':
continue;
case '+':
break;
case '-':
break;
}
goto nd_fail;
/*
* 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.
*/
}
}
RGE_DEBUG(("rge_param_register: OK"));
return (DDI_SUCCESS);
RGE_DEBUG(("rge_param_register: FAILED at index %d [info %d]",
} else {
RGE_DEBUG(("rge_param_register: FAILED at index %d [info %d]",
}
return (DDI_FAILURE);
}
int
{
int duplex;
int speed;
/*
* Register all the per-instance properties, initialising
* them from the table above or from driver properties set
* in the .conf file
*/
return (-1);
/*
* 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.
*/
switch (speed) {
case 1000:
rgep->param_adv_100fdx = 0;
rgep->param_adv_100hdx = 0;
rgep->param_adv_10fdx = 0;
rgep->param_adv_10hdx = 0;
break;
case 100:
rgep->param_adv_1000fdx = 0;
rgep->param_adv_1000hdx = 0;
rgep->param_adv_10fdx = 0;
rgep->param_adv_10hdx = 0;
break;
case 10:
rgep->param_adv_1000fdx = 0;
rgep->param_adv_1000hdx = 0;
rgep->param_adv_100fdx = 0;
rgep->param_adv_100hdx = 0;
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).
*/
rgep->param_adv_autoneg = 0;
switch (speed) {
case 1000:
default:
rgep->param_adv_100fdx = 0;
rgep->param_adv_100hdx = 0;
rgep->param_adv_10fdx = 0;
rgep->param_adv_10hdx = 0;
break;
case 100:
rgep->param_adv_1000fdx = 0;
rgep->param_adv_1000hdx = 0;
rgep->param_adv_10fdx = 0;
rgep->param_adv_10hdx = 0;
break;
case 10:
rgep->param_adv_1000fdx = 0;
rgep->param_adv_1000hdx = 0;
rgep->param_adv_100fdx = 0;
rgep->param_adv_100hdx = 0;
break;
}
switch (duplex) {
default:
case 1:
rgep->param_adv_1000hdx = 0;
rgep->param_adv_100hdx = 0;
rgep->param_adv_10hdx = 0;
break;
case 0:
rgep->param_adv_1000fdx = 0;
rgep->param_adv_100fdx = 0;
rgep->param_adv_10fdx = 0;
break;
}
}
RGE_DEBUG(("rge_nd_init: autoneg %d"
"pause %d asym_pause %d "
"1000fdx %d 1000hdx %d "
"100fdx %d 100hdx %d "
"10fdx %d 10hdx %d ",
return (0);
}
enum ioc_reply
{
int info;
int cmd;
RGE_TRACE(("rge_nd_ioctl($%p, $%p, $%p, $%p)",
switch (cmd) {
default:
/* NOTREACHED */
return (IOC_INVAL);
case ND_GET:
/*
* If nd_getset() returns B_FALSE, the command was
* not valid (e.g. unknown name), so we just tell the
* top-level ioctl code to send a NAK (with code EINVAL).
*
* Otherwise, nd_getset() will have built the reply to
* be sent (but not actually sent it), so we tell the
* caller to send the prepared reply.
*/
case ND_SET:
/*
* All adv_* parameters are locked (read-only) while
* the device is in any sort of loopback mode ...
*/
return (IOC_INVAL);
}
/*
* Before calling nd_getset(), we save the <info> field
* of the 'autonegotiation' parameter so that we can tell
* whether it was assigned (even if its value doesn't
* actually change).
*/
/*
* If nd_getset() returns B_FALSE, the command was
* not valid (e.g. unknown name), so we just tell
* the top-level ioctl code to send a NAK (with code
* EINVAL by default).
*
* Otherwise, nd_getset() will have built the reply to
* be sent - but that doesn't imply success! In some
* cases, the reply it's built will have a non-zero
* error code in it (e.g. EPERM if not superuser).
* So, we also drop out in that case ...
*/
RGE_DEBUG(("rge_nd_ioctl: set %s err %d autoneg %d info %d/%d",
if (!ok)
return (IOC_INVAL);
return (IOC_REPLY);
return (IOC_RESTART_REPLY);
}
}
/* Free the Named Dispatch Table by calling nd_free */
void
{
}