nge_ndd.c revision 02d51d0d625c185ad277d9ad1ddf34b06f78b9b4
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "nge.h"
#define NGE_DBG NGE_DBG_NDD
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,
* '-' => read-only and forced to 0 on serdes
* '!' => 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 nge_param_set()).
*/
static const nd_param_t nd_template[] = {
/* info min max init r/w+name */
/* Our hardware capabilities */
/* Our advertised capabilities */
/* Partner's advertised capabilities */
/* Current operating modes */
/* Loopback status */
/* TX Bcopy threshold */
"+tx_bcopy_threshold" },
/* RX Bcopy threshold */
"+rx_bcopy_threshold" },
/* Max packet received per interrupt */
"+recv_max_packet" },
/* Quiet time switch from polling interrupt to per packet interrupt */
"+poll_quiet_time" },
/* Busy time switch from per packet interrupt to polling interrupt */
"+poll_busy_time" },
/* Packets received to trigger the poll_quiet_time counter */
"+rx_intr_hwater" },
/* Packets received to trigger the poll_busy_time counter */
"+rx_intr_lwater" },
/* Per N tx packets to do tx recycle in poll mode */
"+tx_n_intr" },
/* Terminator */
{ PARAM_COUNT, 0, 0, 0, NULL }
};
/* ============== NDD Support Functions =============== */
/*
* Extracts the value from the nge parameter array and prints
* the parameter value. cp points to the required parameter.
*/
static int
{
return (0);
}
/*
* Validates the request to set a NGE 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;
/*
* 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 '+':
case '?':
break;
case '=':
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.
*/
}
}
return (DDI_SUCCESS);
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:
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_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;
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).
*/
ngep->param_adv_autoneg = 0;
ngep->param_adv_1000hdx = 0;
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;
}
}
return (0);
}
enum ioc_reply
{
int cmd;
NGE_TRACE(("nge_nd_ioctl($%p, $%p, $%p, $%p)",
switch (cmd) {
default:
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);
}
/*
* 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 ...
*/
if (!ok)
return (IOC_INVAL);
return (IOC_REPLY);
/*
* OK, a successful 'set'. Return IOC_RESTART_REPLY,
* telling the top-level ioctl code to update the PHY
* and restart the chip before sending our prepared reply
*/
return (IOC_RESTART_REPLY);
}
}
/* Free the Named Dispatch Table by calling nd_free */
void
{
}