#include "rge.h"
#define RGE_DBG RGE_DBG_NDD
static char transfer_speed_propname[] = "transfer-speed";
static char speed_propname[] = "speed";
static char duplex_propname[] = "full-duplex";
static const nd_param_t nd_template_1000[] = {
{ PARAM_AUTONEG_CAP, 0, 1, 1, "-autoneg_cap" },
{ PARAM_PAUSE_CAP, 0, 1, 1, "-pause_cap" },
{ PARAM_ASYM_PAUSE_CAP, 0, 1, 1, "-asym_pause_cap" },
{ PARAM_1000FDX_CAP, 0, 1, 1, "-1000fdx_cap" },
{ PARAM_1000HDX_CAP, 0, 1, 0, "-1000hdx_cap" },
{ PARAM_100T4_CAP, 0, 1, 0, "-100T4_cap" },
{ PARAM_100FDX_CAP, 0, 1, 1, "-100fdx_cap" },
{ PARAM_100HDX_CAP, 0, 1, 1, "-100hdx_cap" },
{ PARAM_10FDX_CAP, 0, 1, 1, "-10fdx_cap" },
{ PARAM_10HDX_CAP, 0, 1, 1, "-10hdx_cap" },
{ PARAM_ADV_AUTONEG_CAP, 0, 1, 1, "-adv_autoneg_cap" },
{ PARAM_ADV_PAUSE_CAP, 0, 1, 1, "+adv_pause_cap" },
{ PARAM_ADV_ASYM_PAUSE_CAP, 0, 1, 1, "+adv_asym_pause_cap" },
{ PARAM_ADV_1000FDX_CAP, 0, 1, 1, "+adv_1000fdx_cap" },
{ PARAM_ADV_1000HDX_CAP, 0, 1, 0, "-adv_1000hdx_cap" },
{ PARAM_ADV_100T4_CAP, 0, 1, 0, "-adv_100T4_cap" },
{ PARAM_ADV_100FDX_CAP, 0, 1, 1, "+adv_100fdx_cap" },
{ PARAM_ADV_100HDX_CAP, 0, 1, 1, "+adv_100hdx_cap" },
{ PARAM_ADV_10FDX_CAP, 0, 1, 1, "+adv_10fdx_cap" },
{ PARAM_ADV_10HDX_CAP, 0, 1, 1, "+adv_10hdx_cap" },
{ PARAM_LINK_STATUS, 0, 1, 0, "-link_status" },
{ PARAM_LINK_SPEED, 0, 1000, 0, "-link_speed" },
{ PARAM_LINK_DUPLEX, 0, 2, 0, "-link_duplex" },
{ PARAM_LOOP_MODE, 0, 2, 0, "-loop_mode" },
{ PARAM_COUNT, 0, 0, 0, NULL }
};
static const nd_param_t nd_template_100[] = {
{ PARAM_AUTONEG_CAP, 0, 1, 1, "-autoneg_cap" },
{ PARAM_PAUSE_CAP, 0, 1, 1, "-pause_cap" },
{ PARAM_ASYM_PAUSE_CAP, 0, 1, 1, "-asym_pause_cap" },
{ PARAM_1000FDX_CAP, 0, 1, 0, "-1000fdx_cap" },
{ PARAM_1000HDX_CAP, 0, 1, 0, "-1000hdx_cap" },
{ PARAM_100T4_CAP, 0, 1, 0, "-100T4_cap" },
{ PARAM_100FDX_CAP, 0, 1, 1, "-100fdx_cap" },
{ PARAM_100HDX_CAP, 0, 1, 1, "-100hdx_cap" },
{ PARAM_10FDX_CAP, 0, 1, 1, "-10fdx_cap" },
{ PARAM_10HDX_CAP, 0, 1, 1, "-10hdx_cap" },
{ PARAM_ADV_AUTONEG_CAP, 0, 1, 1, "-adv_autoneg_cap" },
{ PARAM_ADV_PAUSE_CAP, 0, 1, 1, "+adv_pause_cap" },
{ PARAM_ADV_ASYM_PAUSE_CAP, 0, 1, 1, "+adv_asym_pause_cap" },
{ PARAM_ADV_1000FDX_CAP, 0, 1, 0, "-adv_1000fdx_cap" },
{ PARAM_ADV_1000HDX_CAP, 0, 1, 0, "-adv_1000hdx_cap" },
{ PARAM_ADV_100T4_CAP, 0, 1, 0, "-adv_100T4_cap" },
{ PARAM_ADV_100FDX_CAP, 0, 1, 1, "+adv_100fdx_cap" },
{ PARAM_ADV_100HDX_CAP, 0, 1, 1, "+adv_100hdx_cap" },
{ PARAM_ADV_10FDX_CAP, 0, 1, 1, "+adv_10fdx_cap" },
{ PARAM_ADV_10HDX_CAP, 0, 1, 1, "+adv_10hdx_cap" },
{ PARAM_LINK_STATUS, 0, 1, 0, "-link_status" },
{ PARAM_LINK_SPEED, 0, 1000, 0, "-link_speed" },
{ PARAM_LINK_DUPLEX, 0, 2, 0, "-link_duplex" },
{ PARAM_LOOP_MODE, 0, 2, 0, "-loop_mode" },
{ PARAM_COUNT, 0, 0, 0, NULL }
};
static int
rge_param_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *credp)
{
nd_param_t *ndp;
_NOTE(ARGUNUSED(q, credp))
ndp = (nd_param_t *)cp;
(void) mi_mpprintf(mp, "%d", ndp->ndp_val);
return (0);
}
static int
rge_param_set(queue_t *q, mblk_t *mp, char *value, caddr_t cp, cred_t *credp)
{
nd_param_t *ndp;
long new_value;
_NOTE(ARGUNUSED(q, mp, credp))
ndp = (nd_param_t *)cp;
(void) ddi_strtol(value, (char **)NULL, 0, &new_value);
if (new_value < ndp->ndp_min || new_value > ndp->ndp_max)
return (EINVAL);
ndp->ndp_val = (int)new_value;
ndp->ndp_info += 1;
return (0);
}
static int
rge_param_register(rge_t *rgep)
{
const nd_param_t *tmplp;
dev_info_t *dip;
nd_param_t *ndp;
caddr_t *nddpp;
pfi_t setfn;
char *nm;
int pval;
dip = rgep->devinfo;
nddpp = &rgep->nd_data_p;
ASSERT(*nddpp == NULL);
if (rgep->chipid.mac_ver == MAC_VER_8101E)
tmplp = nd_template_100;
else
tmplp = nd_template_1000;
for (; tmplp->ndp_name != NULL; ++tmplp) {
ndp = &rgep->nd_params[tmplp->ndp_info];
*ndp = *tmplp;
nm = &ndp->ndp_name[0];
setfn = rge_param_set;
switch (*nm) {
default:
case '!':
continue;
case '+':
break;
case '-':
setfn = NULL;
break;
}
if (!nd_load(nddpp, ++nm, rge_param_get, setfn, (caddr_t)ndp))
goto nd_fail;
if (setfn && RGE_PROP_EXISTS(dip, nm)) {
pval = RGE_PROP_GET_INT(dip, nm);
if (pval >= ndp->ndp_min && pval <= ndp->ndp_max)
ndp->ndp_val = pval;
}
}
RGE_DEBUG(("rge_param_register: OK"));
return (DDI_SUCCESS);
nd_fail:
if (rgep->chipid.mac_ver == MAC_VER_8101E) {
RGE_DEBUG(("rge_param_register: FAILED at index %d [info %d]",
tmplp-nd_template_100, tmplp->ndp_info));
} else {
RGE_DEBUG(("rge_param_register: FAILED at index %d [info %d]",
tmplp-nd_template_1000, tmplp->ndp_info));
}
nd_free(nddpp);
return (DDI_FAILURE);
}
int
rge_nd_init(rge_t *rgep)
{
dev_info_t *dip;
int duplex;
int speed;
if (rge_param_register(rgep) != DDI_SUCCESS)
return (-1);
dip = rgep->devinfo;
if (RGE_PROP_EXISTS(dip, transfer_speed_propname)) {
speed = RGE_PROP_GET_INT(dip, transfer_speed_propname);
rge_log(rgep, "%s property is %d",
transfer_speed_propname, speed);
switch (speed) {
case 1000:
rgep->param_adv_autoneg = 1;
rgep->param_adv_1000fdx = 1;
rgep->param_adv_1000hdx = 1;
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_autoneg = 1;
rgep->param_adv_1000fdx = 0;
rgep->param_adv_1000hdx = 0;
rgep->param_adv_100fdx = 1;
rgep->param_adv_100hdx = 1;
rgep->param_adv_10fdx = 0;
rgep->param_adv_10hdx = 0;
break;
case 10:
rgep->param_adv_autoneg = 1;
rgep->param_adv_1000fdx = 0;
rgep->param_adv_1000hdx = 0;
rgep->param_adv_100fdx = 0;
rgep->param_adv_100hdx = 0;
rgep->param_adv_10fdx = 1;
rgep->param_adv_10hdx = 1;
break;
default:
break;
}
}
if (RGE_PROP_EXISTS(dip, speed_propname) ||
RGE_PROP_EXISTS(dip, duplex_propname)) {
rgep->param_adv_autoneg = 0;
rgep->param_adv_1000fdx = 1;
rgep->param_adv_1000hdx = 1;
rgep->param_adv_100fdx = 1;
rgep->param_adv_100hdx = 1;
rgep->param_adv_10fdx = 1;
rgep->param_adv_10hdx = 1;
speed = RGE_PROP_GET_INT(dip, speed_propname);
duplex = RGE_PROP_GET_INT(dip, duplex_propname);
rge_log(rgep, "%s property is %d",
speed_propname, speed);
rge_log(rgep, "%s property is %d",
duplex_propname, duplex);
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 ",
rgep->param_adv_autoneg,
rgep->param_adv_pause, rgep->param_adv_asym_pause,
rgep->param_adv_1000fdx, rgep->param_adv_1000hdx,
rgep->param_adv_100fdx, rgep->param_adv_100hdx,
rgep->param_adv_10fdx, rgep->param_adv_10hdx));
return (0);
}
enum ioc_reply
rge_nd_ioctl(rge_t *rgep, queue_t *wq, mblk_t *mp, struct iocblk *iocp)
{
nd_param_t *ndp;
boolean_t ok;
int info;
int cmd;
RGE_TRACE(("rge_nd_ioctl($%p, $%p, $%p, $%p)",
(void *)rgep, (void *)wq, (void *)mp, (void *)iocp));
ASSERT(mutex_owned(rgep->genlock));
cmd = iocp->ioc_cmd;
switch (cmd) {
default:
rge_error(rgep, "rge_nd_ioctl: invalid cmd 0x%x", cmd);
return (IOC_INVAL);
case ND_GET:
ok = nd_getset(wq, rgep->nd_data_p, mp);
RGE_DEBUG(("rge_nd_ioctl: get %s", ok ? "OK" : "FAIL"));
return (ok ? IOC_REPLY : IOC_INVAL);
case ND_SET:
if (rgep->param_loop_mode != RGE_LOOP_NONE) {
iocp->ioc_error = EBUSY;
return (IOC_INVAL);
}
ndp = &rgep->nd_params[PARAM_ADV_AUTONEG_CAP];
info = ndp->ndp_info;
ok = nd_getset(wq, rgep->nd_data_p, mp);
RGE_DEBUG(("rge_nd_ioctl: set %s err %d autoneg %d info %d/%d",
ok ? "OK" : "FAIL", iocp->ioc_error,
ndp->ndp_val, info, ndp->ndp_info));
if (!ok)
return (IOC_INVAL);
if (iocp->ioc_error)
return (IOC_REPLY);
return (IOC_RESTART_REPLY);
}
}
void
rge_nd_cleanup(rge_t *rgep)
{
nd_free(&rgep->nd_data_p);
}