summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/io/softmac
diff options
context:
space:
mode:
authorCathy Zhou <Cathy.Zhou@Sun.COM>2009-03-17 20:14:50 -0700
committerCathy Zhou <Cathy.Zhou@Sun.COM>2009-03-17 20:14:50 -0700
commit5d460eafffba936e81c4dd5ebe0f59b238f09121 (patch)
treeec942dd0b37946b807039b9f42e69a8f54c30b7d /usr/src/uts/common/io/softmac
parentf91909144addd198e09d1842e5354bfa62d96691 (diff)
downloadillumos-gate-5d460eafffba936e81c4dd5ebe0f59b238f09121.tar.gz
PSARC/2008/242 Data Fast-Path for Softmac
6649224 fast-path needed to improve legacy network interface performance after UV 6649898 the smac_lock and smac_mutex fields in softmac_t should be given a more descriptive name 6799767 DLD capability is not correctly updated if it is renegotiated
Diffstat (limited to 'usr/src/uts/common/io/softmac')
-rw-r--r--usr/src/uts/common/io/softmac/softmac_ctl.c96
-rw-r--r--usr/src/uts/common/io/softmac/softmac_dev.c355
-rw-r--r--usr/src/uts/common/io/softmac/softmac_fp.c1252
-rw-r--r--usr/src/uts/common/io/softmac/softmac_main.c345
-rw-r--r--usr/src/uts/common/io/softmac/softmac_pkt.c19
5 files changed, 1919 insertions, 148 deletions
diff --git a/usr/src/uts/common/io/softmac/softmac_ctl.c b/usr/src/uts/common/io/softmac/softmac_ctl.c
index 99c665aae6..d4c8afa8ce 100644
--- a/usr/src/uts/common/io/softmac/softmac_ctl.c
+++ b/usr/src/uts/common/io/softmac/softmac_ctl.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -70,6 +70,22 @@ softmac_send_bind_req(softmac_lower_t *slp, uint_t sap)
}
int
+softmac_send_unbind_req(softmac_lower_t *slp)
+{
+ mblk_t *reqmp;
+
+ /*
+ * create unbind req message and send it down
+ */
+ reqmp = mexchange(NULL, NULL, DL_UNBIND_REQ_SIZE, M_PROTO,
+ DL_UNBIND_REQ);
+ if (reqmp == NULL)
+ return (ENOMEM);
+
+ return (softmac_proto_tx(slp, reqmp, NULL));
+}
+
+int
softmac_send_promisc_req(softmac_lower_t *slp, t_uscalar_t level, boolean_t on)
{
mblk_t *reqmp;
@@ -105,6 +121,7 @@ softmac_m_promisc(void *arg, boolean_t on)
softmac_t *softmac = arg;
softmac_lower_t *slp = softmac->smac_lower;
+ ASSERT(MAC_PERIM_HELD(softmac->smac_mh));
ASSERT(slp != NULL);
return (softmac_send_promisc_req(slp, DL_PROMISC_PHYS, on));
}
@@ -120,6 +137,7 @@ softmac_m_multicst(void *arg, boolean_t add, const uint8_t *mca)
t_uscalar_t dl_prim;
uint32_t size, addr_length;
+ ASSERT(MAC_PERIM_HELD(softmac->smac_mh));
/*
* create multicst message and send it down
*/
@@ -162,6 +180,7 @@ softmac_m_unicst(void *arg, const uint8_t *macaddr)
mblk_t *reqmp;
size_t size;
+ ASSERT(MAC_PERIM_HELD(softmac->smac_mh));
/*
* create set_phys_addr message and send it down
*/
@@ -425,16 +444,72 @@ runt:
}
void
-softmac_rput_process_notdata(queue_t *rq, mblk_t *mp)
+softmac_rput_process_notdata(queue_t *rq, softmac_upper_t *sup, mblk_t *mp)
{
- softmac_lower_t *slp = rq->q_ptr;
+ softmac_lower_t *slp = rq->q_ptr;
+ union DL_primitives *dlp;
+ ssize_t len = MBLKL(mp);
switch (DB_TYPE(mp)) {
case M_PROTO:
case M_PCPROTO:
- softmac_rput_process_proto(rq, mp);
- break;
+ /*
+ * If this is a shared-lower-stream, pass it to softmac to
+ * process.
+ */
+ if (sup == NULL) {
+ softmac_rput_process_proto(rq, mp);
+ break;
+ }
+ /*
+ * Dedicated-lower-stream.
+ */
+ dlp = (union DL_primitives *)mp->b_rptr;
+ ASSERT(len >= sizeof (dlp->dl_primitive));
+ switch (dlp->dl_primitive) {
+ case DL_OK_ACK:
+ if (len < DL_OK_ACK_SIZE)
+ goto runt;
+
+ /*
+ * If this is a DL_OK_ACK for a DL_UNBIND_REQ, pass it
+ * to softmac to process, otherwise directly pass it to
+ * the upper stream.
+ */
+ if (dlp->ok_ack.dl_correct_primitive == DL_UNBIND_REQ) {
+ softmac_rput_process_proto(rq, mp);
+ break;
+ }
+
+ putnext(sup->su_rq, mp);
+ break;
+ case DL_ERROR_ACK:
+ if (len < DL_ERROR_ACK_SIZE)
+ goto runt;
+
+ /*
+ * If this is a DL_ERROR_ACK for a DL_UNBIND_REQ, pass
+ * it to softmac to process, otherwise directly pass it
+ * to the upper stream.
+ */
+ if (dlp->error_ack.dl_error_primitive ==
+ DL_UNBIND_REQ) {
+ softmac_rput_process_proto(rq, mp);
+ break;
+ }
+
+ putnext(sup->su_rq, mp);
+ break;
+ case DL_BIND_ACK:
+ case DL_CAPABILITY_ACK:
+ softmac_rput_process_proto(rq, mp);
+ break;
+ default:
+ putnext(sup->su_rq, mp);
+ break;
+ }
+ break;
case M_FLUSH:
if (*mp->b_rptr & FLUSHR)
flushq(rq, FLUSHDATA);
@@ -447,6 +522,11 @@ softmac_rput_process_notdata(queue_t *rq, mblk_t *mp)
case M_IOCNAK:
case M_COPYIN:
case M_COPYOUT:
+ if (sup != NULL) {
+ putnext(sup->su_rq, mp);
+ break;
+ }
+
mutex_enter(&slp->sl_mutex);
if (!slp->sl_pending_ioctl) {
mutex_exit(&slp->sl_mutex);
@@ -460,7 +540,7 @@ softmac_rput_process_notdata(queue_t *rq, mblk_t *mp)
slp->sl_ack_mp = mp;
cv_broadcast(&slp->sl_cv);
mutex_exit(&slp->sl_mutex);
- return;
+ break;
default:
cmn_err(CE_NOTE, "softmac: got unsupported mblk type 0x%x",
@@ -468,4 +548,8 @@ softmac_rput_process_notdata(queue_t *rq, mblk_t *mp)
freemsg(mp);
break;
}
+ return;
+runt:
+ cmn_err(CE_WARN, "softmac: got runt %s", dl_primstr(dlp->dl_primitive));
+ freemsg(mp);
}
diff --git a/usr/src/uts/common/io/softmac/softmac_dev.c b/usr/src/uts/common/io/softmac/softmac_dev.c
index f548df055d..37c5740846 100644
--- a/usr/src/uts/common/io/softmac/softmac_dev.c
+++ b/usr/src/uts/common/io/softmac/softmac_dev.c
@@ -19,28 +19,45 @@
* CDDL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/types.h>
-#include <sys/dld.h>
#include <inet/common.h>
#include <sys/stropts.h>
#include <sys/modctl.h>
-#include <sys/avl.h>
+#include <sys/dld.h>
#include <sys/softmac_impl.h>
-#include <sys/softmac.h>
dev_info_t *softmac_dip = NULL;
+static kmem_cache_t *softmac_upper_cachep;
+
+/*
+ * This function is a generic open(9E) entry point into the softmac for
+ * both the softmac module and the softmac driver.
+ */
+static int softmac_cmn_open(queue_t *, dev_t *, int, int, cred_t *);
+
+/*
+ * The following softmac_mod_xxx() functions are (9E) entry point functions for
+ * the softmac module.
+ */
+static int softmac_mod_close(queue_t *);
+static void softmac_mod_rput(queue_t *, mblk_t *);
+static void softmac_mod_wput(queue_t *, mblk_t *);
+static void softmac_mod_wsrv(queue_t *);
+
+/*
+ * The following softmac_drv_xxx() functions are (9E) entry point functions for
+ * the softmac driver.
+ */
+static int softmac_drv_open(queue_t *, dev_t *, int, int, cred_t *);
+static int softmac_drv_close(queue_t *);
+static void softmac_drv_wput(queue_t *, mblk_t *);
+static void softmac_drv_wsrv(queue_t *);
-static int softmac_open(queue_t *, dev_t *, int, int, cred_t *);
-static int softmac_close(queue_t *);
-static void softmac_rput(queue_t *, mblk_t *);
-static void softmac_rsrv(queue_t *);
-static void softmac_wput(queue_t *, mblk_t *);
-static void softmac_wsrv(queue_t *);
static int softmac_attach(dev_info_t *, ddi_attach_cmd_t);
static int softmac_detach(dev_info_t *, ddi_detach_cmd_t);
static int softmac_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
@@ -68,21 +85,21 @@ static struct module_info softmac_dld_modinfo = {
};
static struct qinit softmac_urinit = {
- (pfi_t)softmac_rput, /* qi_putp */
- (pfi_t)softmac_rsrv, /* qi_srvp */
- softmac_open, /* qi_qopen */
- softmac_close, /* qi_qclose */
- NULL, /* qi_qadmin */
- &softmac_modinfo /* qi_minfo */
+ (pfi_t)softmac_mod_rput, /* qi_putp */
+ (pfi_t)NULL, /* qi_srvp */
+ softmac_cmn_open, /* qi_qopen */
+ softmac_mod_close, /* qi_qclose */
+ NULL, /* qi_qadmin */
+ &softmac_modinfo /* qi_minfo */
};
static struct qinit softmac_uwinit = {
- (pfi_t)softmac_wput, /* qi_putp */
- (pfi_t)softmac_wsrv, /* qi_srvp */
- NULL, /* qi_qopen */
- NULL, /* qi_qclose */
- NULL, /* qi_qadmin */
- &softmac_modinfo /* qi_minfo */
+ (pfi_t)softmac_mod_wput, /* qi_putp */
+ (pfi_t)softmac_mod_wsrv, /* qi_srvp */
+ NULL, /* qi_qopen */
+ NULL, /* qi_qclose */
+ NULL, /* qi_qadmin */
+ &softmac_modinfo /* qi_minfo */
};
static struct streamtab softmac_tab = {
@@ -95,11 +112,12 @@ DDI_DEFINE_STREAM_OPS(softmac_ops, nulldev, nulldev, softmac_attach,
ddi_quiesce_not_supported);
static struct qinit softmac_dld_r_qinit = {
- NULL, NULL, dld_open, dld_close, NULL, &softmac_dld_modinfo
+ NULL, NULL, softmac_drv_open, softmac_drv_close, NULL,
+ &softmac_dld_modinfo
};
static struct qinit softmac_dld_w_qinit = {
- (pfi_t)dld_wput, (pfi_t)dld_wsrv, NULL, NULL, NULL,
+ (pfi_t)softmac_drv_wput, (pfi_t)softmac_drv_wsrv, NULL, NULL, NULL,
&softmac_dld_modinfo
};
@@ -128,6 +146,49 @@ static struct modlinkage softmac_modlinkage = {
NULL
};
+/*ARGSUSED*/
+static int
+softmac_upper_constructor(void *buf, void *arg, int kmflag)
+{
+ softmac_upper_t *sup = buf;
+
+ bzero(buf, sizeof (softmac_upper_t));
+
+ mutex_init(&sup->su_mutex, NULL, MUTEX_DEFAULT, NULL);
+ cv_init(&sup->su_cv, NULL, CV_DEFAULT, NULL);
+ mutex_init(&sup->su_disp_mutex, NULL, MUTEX_DEFAULT, NULL);
+ cv_init(&sup->su_disp_cv, NULL, CV_DEFAULT, NULL);
+ list_create(&sup->su_req_list, sizeof (softmac_switch_req_t),
+ offsetof(softmac_switch_req_t, ssq_req_list_node));
+ return (0);
+}
+
+/*ARGSUSED*/
+static void
+softmac_upper_destructor(void *buf, void *arg)
+{
+ softmac_upper_t *sup = buf;
+
+ ASSERT(sup->su_slp == NULL);
+ ASSERT(sup->su_pending_head == NULL && sup->su_pending_tail == NULL);
+ ASSERT(!sup->su_dlpi_pending);
+ ASSERT(!sup->su_active);
+ ASSERT(!sup->su_closing);
+ ASSERT(sup->su_tx_flow_mp == NULL);
+ ASSERT(sup->su_tx_inprocess == 0);
+ ASSERT(sup->su_mode == SOFTMAC_UNKNOWN);
+ ASSERT(!sup->su_tx_busy);
+ ASSERT(!sup->su_bound);
+ ASSERT(!sup->su_taskq_scheduled);
+ ASSERT(list_is_empty(&sup->su_req_list));
+
+ list_destroy(&sup->su_req_list);
+ mutex_destroy(&sup->su_mutex);
+ cv_destroy(&sup->su_cv);
+ mutex_destroy(&sup->su_disp_mutex);
+ cv_destroy(&sup->su_disp_cv);
+}
+
int
_init(void)
{
@@ -135,6 +196,11 @@ _init(void)
softmac_init();
+ softmac_upper_cachep = kmem_cache_create("softmac_upper_cache",
+ sizeof (softmac_upper_t), 0, softmac_upper_constructor,
+ softmac_upper_destructor, NULL, NULL, NULL, 0);
+ ASSERT(softmac_upper_cachep != NULL);
+
if ((err = mod_install(&softmac_modlinkage)) != 0) {
softmac_fini();
return (err);
@@ -154,6 +220,7 @@ _fini(void)
if ((err = mod_remove(&softmac_modlinkage)) != 0)
return (err);
+ kmem_cache_destroy(softmac_upper_cachep);
softmac_fini();
return (0);
@@ -166,7 +233,7 @@ _info(struct modinfo *modinfop)
}
static int
-softmac_open(queue_t *rq, dev_t *devp, int flag, int sflag, cred_t *credp)
+softmac_cmn_open(queue_t *rq, dev_t *devp, int flag, int sflag, cred_t *credp)
{
softmac_lower_t *slp;
/*
@@ -198,16 +265,15 @@ softmac_open(queue_t *rq, dev_t *devp, int flag, int sflag, cred_t *credp)
/*
* Regular device open of a softmac DLPI node. We modify
* the queues' q_qinfo pointer such that all future STREAMS
- * operations will go through dld's entry points (including
- * dld_close()).
+ * operations will go through another set of entry points
*/
rq->q_qinfo = &softmac_dld_r_qinit;
WR(rq)->q_qinfo = &softmac_dld_w_qinit;
- return (dld_open(rq, devp, flag, sflag, credp));
+ return (softmac_drv_open(rq, devp, flag, sflag, credp));
}
static int
-softmac_close(queue_t *rq)
+softmac_mod_close(queue_t *rq)
{
softmac_lower_t *slp = rq->q_ptr;
@@ -237,10 +303,11 @@ softmac_close(queue_t *rq)
}
static void
-softmac_rput(queue_t *rq, mblk_t *mp)
+softmac_mod_rput(queue_t *rq, mblk_t *mp)
{
- softmac_lower_t *slp = rq->q_ptr;
- union DL_primitives *dlp;
+ softmac_lower_t *slp = rq->q_ptr;
+ softmac_lower_rxinfo_t *rxinfo;
+ union DL_primitives *dlp;
/*
* This is the softmac module.
@@ -249,11 +316,21 @@ softmac_rput(queue_t *rq, mblk_t *mp)
ASSERT((mp->b_next == NULL) && (mp->b_prev == NULL));
switch (DB_TYPE(mp)) {
- case M_DATA:
+ case M_DATA: {
+
+ /*
+ * If sl_rxinfo is non-NULL. This is dedicated-lower-stream
+ * created for fastpath. Directly call the rx callback.
+ */
+ if ((rxinfo = slp->sl_rxinfo) != NULL) {
+ rxinfo->slr_rx(rxinfo->slr_arg, NULL, mp, NULL);
+ break;
+ }
+
/*
- * Some drivers start to send up packets even if not in the
- * DL_IDLE state, where sl_softmac is not set yet. Drop the
- * packet in this case.
+ * A shared-lower-stream. Some driver starts to send up
+ * packets even it not in the DL_IDLE state, where
+ * sl_softmac is not set yet. Drop the packet in this case.
*/
if (slp->sl_softmac == NULL) {
freemsg(mp);
@@ -275,18 +352,13 @@ softmac_rput(queue_t *rq, mblk_t *mp)
*/
if (DB_REF(mp) == 1) {
ASSERT(slp->sl_softmac != NULL);
- /*
- * We don't need any locks to protect sl_handle
- * because ip_input() can tolerate if sl_handle
- * is reset to NULL when DL_CAPAB_POLL is
- * disabled.
- */
mac_rx(slp->sl_softmac->smac_mh, NULL, mp);
return;
} else {
softmac_rput_process_data(slp, mp);
}
break;
+ }
case M_PROTO:
case M_PCPROTO:
if (MBLKL(mp) < sizeof (dlp->dl_primitive)) {
@@ -295,6 +367,12 @@ softmac_rput(queue_t *rq, mblk_t *mp)
}
dlp = (union DL_primitives *)mp->b_rptr;
if (dlp->dl_primitive == DL_UNITDATA_IND) {
+
+ if ((rxinfo = slp->sl_rxinfo) != NULL) {
+ rxinfo->slr_rx(rxinfo->slr_arg, NULL, mp, NULL);
+ break;
+ }
+
cmn_err(CE_WARN, "got unexpected %s message",
dl_primstr(DL_UNITDATA_IND));
freemsg(mp);
@@ -302,19 +380,13 @@ softmac_rput(queue_t *rq, mblk_t *mp)
}
/*FALLTHROUGH*/
default:
- softmac_rput_process_notdata(rq, mp);
+ softmac_rput_process_notdata(rq, slp->sl_sup, mp);
break;
}
}
-/* ARGSUSED */
-static void
-softmac_rsrv(queue_t *rq)
-{
-}
-
static void
-softmac_wput(queue_t *wq, mblk_t *mp)
+softmac_mod_wput(queue_t *wq, mblk_t *mp)
{
/*
* This is the softmac module
@@ -342,7 +414,6 @@ softmac_wput(queue_t *wq, mblk_t *mp)
*/
arg = (smac_ioc_start_t *)mp->b_cont->b_rptr;
arg->si_slp = slp;
-
miocack(wq, mp, sizeof (*arg), 0);
break;
}
@@ -359,7 +430,7 @@ softmac_wput(queue_t *wq, mblk_t *mp)
}
static void
-softmac_wsrv(queue_t *wq)
+softmac_mod_wsrv(queue_t *wq)
{
softmac_lower_t *slp = wq->q_ptr;
@@ -372,7 +443,9 @@ softmac_wsrv(queue_t *wq)
* Inform that the tx resource is available; mac_tx_update() will
* inform all the upper streams sharing this lower stream.
*/
- if (slp->sl_softmac != NULL)
+ if (slp->sl_sup != NULL)
+ qenable(slp->sl_sup->su_wq);
+ else if (slp->sl_softmac != NULL)
mac_tx_update(slp->sl_softmac->smac_mh);
}
@@ -420,3 +493,179 @@ softmac_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
return (DDI_FAILURE);
}
+
+/*ARGSUSED*/
+static void
+softmac_dedicated_rx(void *arg, mac_resource_handle_t mrh, mblk_t *mp,
+ mac_header_info_t *mhip)
+{
+ queue_t *rq = ((softmac_upper_t *)arg)->su_rq;
+
+ if (canputnext(rq))
+ putnext(rq, mp);
+ else
+ freemsg(mp);
+}
+
+/*ARGSUSED*/
+static int
+softmac_drv_open(queue_t *rq, dev_t *devp, int flag, int sflag, cred_t *credp)
+{
+ softmac_upper_t *sup = NULL;
+ softmac_t *softmac;
+ int err = 0;
+
+ /*
+ * This is a softmac device created for a legacy device, find the
+ * associated softmac and initialize the softmac_upper_t structure.
+ */
+ if ((err = softmac_hold(*devp, &softmac)) != 0)
+ return (err);
+
+ sup = kmem_cache_alloc(softmac_upper_cachep, KM_NOSLEEP);
+ if (sup == NULL) {
+ err = ENOMEM;
+ goto fail;
+ }
+
+ ASSERT(list_is_empty(&sup->su_req_list));
+
+ if ((sup->su_tx_flow_mp = allocb(1, BPRI_HI)) == NULL) {
+ err = ENOMEM;
+ goto fail;
+ }
+
+ sup->su_rq = rq;
+ sup->su_wq = WR(rq);
+ sup->su_softmac = softmac;
+ sup->su_mode = SOFTMAC_UNKNOWN;
+
+ sup->su_rxinfo.slr_arg = sup;
+ sup->su_rxinfo.slr_rx = softmac_dedicated_rx;
+ sup->su_direct_rxinfo.slr_arg = sup;
+ sup->su_direct_rxinfo.slr_rx = softmac_dedicated_rx;
+
+ if ((err = dld_str_open(rq, devp, sup)) != 0) {
+ freeb(sup->su_tx_flow_mp);
+ sup->su_tx_flow_mp = NULL;
+ goto fail;
+ }
+
+ return (0);
+
+fail:
+ if (sup != NULL)
+ kmem_cache_free(softmac_upper_cachep, sup);
+ softmac_rele(softmac);
+ return (err);
+}
+
+static int
+softmac_drv_close(queue_t *rq)
+{
+ softmac_upper_t *sup = dld_str_private(rq);
+ softmac_t *softmac = sup->su_softmac;
+
+ ASSERT(WR(rq)->q_next == NULL);
+
+ qprocsoff(rq);
+
+ ASSERT(sup->su_tx_inprocess == 0);
+
+ /*
+ * Wait until the pending request are processed by the worker thread.
+ */
+ mutex_enter(&sup->su_disp_mutex);
+ sup->su_closing = B_TRUE;
+ while (sup->su_dlpi_pending)
+ cv_wait(&sup->su_disp_cv, &sup->su_disp_mutex);
+ mutex_exit(&sup->su_disp_mutex);
+
+ softmac_upperstream_close(sup);
+
+ if (sup->su_tx_flow_mp != NULL) {
+ freeb(sup->su_tx_flow_mp);
+ sup->su_tx_flow_mp = NULL;
+ }
+
+ if (sup->su_active) {
+ mutex_enter(&softmac->smac_active_mutex);
+ softmac->smac_nactive--;
+ mutex_exit(&softmac->smac_active_mutex);
+ sup->su_active = B_FALSE;
+ }
+
+ sup->su_bound = B_FALSE;
+ sup->su_softmac = NULL;
+ sup->su_closing = B_FALSE;
+
+ kmem_cache_free(softmac_upper_cachep, sup);
+
+ softmac_rele(softmac);
+ return (dld_str_close(rq));
+}
+
+static void
+softmac_drv_wput(queue_t *wq, mblk_t *mp)
+{
+ softmac_upper_t *sup = dld_str_private(wq);
+ t_uscalar_t prim;
+
+ ASSERT(wq->q_next == NULL);
+
+ switch (DB_TYPE(mp)) {
+ case M_DATA:
+ case M_MULTIDATA:
+ softmac_wput_data(sup, mp);
+ break;
+ case M_PROTO:
+ case M_PCPROTO:
+
+ if (MBLKL(mp) < sizeof (t_uscalar_t)) {
+ freemsg(mp);
+ return;
+ }
+
+ prim = ((union DL_primitives *)mp->b_rptr)->dl_primitive;
+ if (prim == DL_UNITDATA_REQ) {
+ softmac_wput_data(sup, mp);
+ return;
+ }
+
+ softmac_wput_nondata(sup, mp);
+ break;
+ default:
+ softmac_wput_nondata(sup, mp);
+ break;
+ }
+}
+
+static void
+softmac_drv_wsrv(queue_t *wq)
+{
+ softmac_upper_t *sup = dld_str_private(wq);
+
+ ASSERT(wq->q_next == NULL);
+
+ mutex_enter(&sup->su_mutex);
+ if (sup->su_mode != SOFTMAC_FASTPATH) {
+ /*
+ * Bump su_tx_inprocess so that su_mode won't change.
+ */
+ sup->su_tx_inprocess++;
+ mutex_exit(&sup->su_mutex);
+ dld_wsrv(wq);
+ mutex_enter(&sup->su_mutex);
+ if (--sup->su_tx_inprocess == 0)
+ cv_signal(&sup->su_cv);
+ } else if (sup->su_tx_busy && SOFTMAC_CANPUTNEXT(sup->su_slp->sl_wq)) {
+ /*
+ * The flow-conctol of the dedicated-lower-stream is
+ * relieved, relieve the flow-control of the
+ * upper-stream too.
+ */
+ sup->su_tx_flow_mp = getq(wq);
+ sup->su_tx_busy = B_FALSE;
+ }
+ mutex_exit(&sup->su_mutex);
+}
diff --git a/usr/src/uts/common/io/softmac/softmac_fp.c b/usr/src/uts/common/io/softmac/softmac_fp.c
new file mode 100644
index 0000000000..a012aa32a4
--- /dev/null
+++ b/usr/src/uts/common/io/softmac/softmac_fp.c
@@ -0,0 +1,1252 @@
+/*
+ * 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
+ * or http://www.opensolaris.org/os/licensing.
+ * 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 2009 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Softmac data-path switching:
+ *
+ * - Fast-path model
+ *
+ * When the softmac fast-path is used, a dedicated lower-stream
+ * will be opened over the legacy device for each IP/ARP (upper-)stream
+ * over the softMAC, and all DLPI messages (including control messages
+ * and data messages) will be exchanged between the upper-stream and
+ * the corresponding lower-stream directly. Therefore, the data
+ * demultiplexing, filtering and classification processing will be done
+ * by the lower-stream, and the GLDv3 DLS/MAC layer processing will be
+ * no longer needed.
+ *
+ * - Slow-path model
+ *
+ * Some GLDv3 features requires the GLDv3 DLS/MAC layer processing to
+ * not be bypassed to assure its function correctness. For example,
+ * softmac fast-path must be disabled to support GLDv3 VNIC functionality.
+ * In this case, a shared lower-stream will be opened over the legacy
+ * device, which is responsible for implementing the GLDv3 callbacks
+ * and passing RAW data messages between the legacy devices and the GLDv3
+ * framework.
+ *
+ * By default, the softmac fast-path mode will be used to assure the
+ * performance; MAC clients will be able to request to disable the softmac
+ * fast-path mode to support certain features, and if that succeeds,
+ * the system will fallback to the slow-path softmac data-path model.
+ *
+ *
+ * The details of the softmac data fast-path model is stated as below
+ *
+ * 1. When a stream is opened on a softMAC, the softmac module will takes
+ * over the DLPI processing on this stream;
+ *
+ * 2. For IP/ARP streams over a softMAC, softmac data fast-path will be
+ * used by default, unless fast-path is disabled by any MAC client
+ * explicitly. The softmac module first identifies an IP/ARP stream
+ * by seeing whether there is a SIOCSLIFNAME ioctl sent from upstream,
+ * if there is one, this stream is either an IP or an ARP stream
+ * and will use fast-path potentially;
+ *
+ * 3. When the softmac fast-path is used, an dedicated lower-stream will
+ * be setup for each IP/ARP stream (1-1 mapping). From that point on,
+ * all control and data messages will be exchanged between the IP/ARP
+ * upper-stream and the legacy device through this dedicated
+ * lower-stream. As a result, the DLS/MAC layer processing in GLDv3
+ * will be skipped, and this greatly improves the performance;
+ *
+ * 4. When the softmac data fast-path is disabled by a MAC client (e.g.,
+ * by a VNIC), all the IP/ARP upper streams will try to switch from
+ * the fast-path to the slow-path. The dedicated lower-stream will be
+ * destroyed, and all the control and data-messages will go through the
+ * existing GLDv3 code path and (in the end) the shared lower-stream;
+ *
+ * 5. On the other hand, when the last MAC client cancels its fast-path
+ * disable request, all the IP/ARP streams will try to switch back to
+ * the fast-path mode;
+ *
+ * Step 5 and 6 both rely on the data-path mode switching process
+ * described below:
+ *
+ * 1) To switch the softmac data-path mode (between fast-path and slow-path),
+ * softmac will first send a DL_NOTE_REPLUMB DL_NOTIFY_IND message
+ * upstream over each IP/ARP streams that needs data-path mode switching;
+ *
+ * 2) When IP receives this DL_NOTE_REPLUMB message, it will bring down
+ * all the IP interfaces on the corresponding ill (IP Lower level
+ * structure), and bring up those interfaces over again; this will in
+ * turn cause the ARP to "replumb" the interface.
+ *
+ * During the replumb process, both IP and ARP will send downstream the
+ * necessary DL_DISABMULTI_REQ and DL_UNBIND_REQ messages and cleanup
+ * the old state of the underlying softMAC, following with the necessary
+ * DL_BIND_REQ and DL_ENABMULTI_REQ messages to setup the new state.
+ * Between the cleanup and re-setup process, IP/ARP will also send down
+ * a DL_NOTE_REPLUMB_DONE DL_NOTIFY_CONF messages to the softMAC to
+ * indicate the *switching point*;
+ *
+ * 3) When softmac receives the DL_NOTE_REPLUMB_DONE message, it either
+ * creates or destroys the dedicated lower-stream (depending on which
+ * data-path mode the softMAC switches to), and change the softmac
+ * data-path mode. From then on, softmac will process all the succeeding
+ * control messages (including the DL_BIND_REQ and DL_ENABMULTI_REQ
+ * messages) and data messages based on new data-path mode.
+ */
+
+#include <sys/types.h>
+#include <sys/disp.h>
+#include <sys/callb.h>
+#include <sys/sysmacros.h>
+#include <sys/file.h>
+#include <sys/vlan.h>
+#include <sys/dld.h>
+#include <sys/sockio.h>
+#include <sys/softmac_impl.h>
+
+static kmutex_t softmac_taskq_lock;
+static kcondvar_t softmac_taskq_cv;
+static list_t softmac_taskq_list; /* List of softmac_upper_t */
+boolean_t softmac_taskq_quit;
+boolean_t softmac_taskq_done;
+
+static void softmac_taskq_dispatch();
+static int softmac_fastpath_setup(softmac_upper_t *);
+static mac_tx_cookie_t softmac_fastpath_wput_data(softmac_upper_t *, mblk_t *,
+ uintptr_t, uint16_t);
+static void softmac_datapath_switch_done(softmac_upper_t *);
+
+void
+softmac_fp_init()
+{
+ mutex_init(&softmac_taskq_lock, NULL, MUTEX_DRIVER, NULL);
+ cv_init(&softmac_taskq_cv, NULL, CV_DRIVER, NULL);
+
+ softmac_taskq_quit = B_FALSE;
+ softmac_taskq_done = B_FALSE;
+ list_create(&softmac_taskq_list, sizeof (softmac_upper_t),
+ offsetof(softmac_upper_t, su_taskq_list_node));
+ (void) thread_create(NULL, 0, softmac_taskq_dispatch, NULL, 0,
+ &p0, TS_RUN, minclsyspri);
+}
+
+void
+softmac_fp_fini()
+{
+ /*
+ * Request the softmac_taskq thread to quit and wait for it to be done.
+ */
+ mutex_enter(&softmac_taskq_lock);
+ softmac_taskq_quit = B_TRUE;
+ cv_signal(&softmac_taskq_cv);
+ while (!softmac_taskq_done)
+ cv_wait(&softmac_taskq_cv, &softmac_taskq_lock);
+ mutex_exit(&softmac_taskq_lock);
+ list_destroy(&softmac_taskq_list);
+
+ mutex_destroy(&softmac_taskq_lock);
+ cv_destroy(&softmac_taskq_cv);
+}
+
+static boolean_t
+check_ip_above(queue_t *q)
+{
+ queue_t *next_q;
+ boolean_t ret = B_TRUE;
+
+ claimstr(q);
+ next_q = q->q_next;
+ if (strcmp(next_q->q_qinfo->qi_minfo->mi_idname, "ip") != 0)
+ ret = B_FALSE;
+ releasestr(q);
+ return (ret);
+}
+
+/* ARGSUSED */
+static int
+softmac_capab_perim(softmac_upper_t *sup, void *data, uint_t flags)
+{
+ switch (flags) {
+ case DLD_ENABLE:
+ mutex_enter(&sup->su_mutex);
+ break;
+ case DLD_DISABLE:
+ mutex_exit(&sup->su_mutex);
+ break;
+ case DLD_QUERY:
+ return (MUTEX_HELD(&sup->su_mutex));
+ }
+ return (0);
+}
+
+/* ARGSUSED */
+static mac_tx_notify_handle_t
+softmac_client_tx_notify(void *txcb, mac_tx_notify_t func, void *arg)
+{
+ return (NULL);
+}
+
+static int
+softmac_capab_direct(softmac_upper_t *sup, void *data, uint_t flags)
+{
+ dld_capab_direct_t *direct = data;
+ softmac_lower_t *slp = sup->su_slp;
+
+ ASSERT(MUTEX_HELD(&sup->su_mutex));
+
+ ASSERT(sup->su_mode == SOFTMAC_FASTPATH);
+
+ switch (flags) {
+ case DLD_ENABLE:
+ if (sup->su_direct)
+ return (0);
+
+ sup->su_direct_rxinfo.slr_rx = (softmac_rx_t)direct->di_rx_cf;
+ sup->su_direct_rxinfo.slr_arg = direct->di_rx_ch;
+ slp->sl_rxinfo = &sup->su_direct_rxinfo;
+ direct->di_tx_df = (uintptr_t)softmac_fastpath_wput_data;
+ direct->di_tx_dh = sup;
+
+ /*
+ * We relying on the STREAM flow-control to backenable
+ * the IP stream. Therefore, no notify callback needs to
+ * be registered. But IP requires this to be a valid function
+ * pointer.
+ */
+ direct->di_tx_cb_df = (uintptr_t)softmac_client_tx_notify;
+ direct->di_tx_cb_dh = NULL;
+ sup->su_direct = B_TRUE;
+ return (0);
+
+ case DLD_DISABLE:
+ if (!sup->su_direct)
+ return (0);
+
+ slp->sl_rxinfo = &sup->su_rxinfo;
+ sup->su_direct = B_FALSE;
+ return (0);
+ }
+ return (ENOTSUP);
+}
+
+static int
+softmac_dld_capab(softmac_upper_t *sup, uint_t type, void *data, uint_t flags)
+{
+ int err;
+
+ /*
+ * Don't enable direct callback capabilities unless the caller is
+ * the IP client. When a module is inserted in a stream (_I_INSERT)
+ * the stack initiates capability disable, but due to races, the
+ * module insertion may complete before the capability disable
+ * completes. So we limit the check to DLD_ENABLE case.
+ */
+ if ((flags == DLD_ENABLE && type != DLD_CAPAB_PERIM) &&
+ !check_ip_above(sup->su_rq)) {
+ return (ENOTSUP);
+ }
+
+ switch (type) {
+ case DLD_CAPAB_DIRECT:
+ err = softmac_capab_direct(sup, data, flags);
+ break;
+
+ case DLD_CAPAB_PERIM:
+ err = softmac_capab_perim(sup, data, flags);
+ break;
+
+ default:
+ err = ENOTSUP;
+ break;
+ }
+ return (err);
+}
+
+static void
+softmac_capability_advertise(softmac_upper_t *sup, mblk_t *mp)
+{
+ dl_capability_ack_t *dlap;
+ dl_capability_sub_t *dlsp;
+ t_uscalar_t subsize;
+ uint8_t *ptr;
+ queue_t *q = sup->su_wq;
+ mblk_t *mp1;
+ softmac_t *softmac = sup->su_softmac;
+ boolean_t dld_capable = B_FALSE;
+ boolean_t hcksum_capable = B_FALSE;
+ boolean_t zcopy_capable = B_FALSE;
+ boolean_t mdt_capable = B_FALSE;
+
+ ASSERT(sup->su_mode == SOFTMAC_FASTPATH);
+
+ /*
+ * Initially assume no capabilities.
+ */
+ subsize = 0;
+
+ /*
+ * Direct capability negotiation interface between IP and softmac
+ */
+ if (check_ip_above(sup->su_rq)) {
+ dld_capable = B_TRUE;
+ subsize += sizeof (dl_capability_sub_t) +
+ sizeof (dl_capab_dld_t);
+ }
+
+ /*
+ * Check if checksum offload is supported on this MAC.
+ */
+ if (softmac->smac_capab_flags & MAC_CAPAB_HCKSUM) {
+ hcksum_capable = B_TRUE;
+ subsize += sizeof (dl_capability_sub_t) +
+ sizeof (dl_capab_hcksum_t);
+ }
+
+ /*
+ * Check if zerocopy is supported on this interface.
+ */
+ if (!(softmac->smac_capab_flags & MAC_CAPAB_NO_ZCOPY)) {
+ zcopy_capable = B_TRUE;
+ subsize += sizeof (dl_capability_sub_t) +
+ sizeof (dl_capab_zerocopy_t);
+ }
+
+ if (softmac->smac_mdt) {
+ mdt_capable = B_TRUE;
+ subsize += sizeof (dl_capability_sub_t) +
+ sizeof (dl_capab_mdt_t);
+ }
+
+ /*
+ * If there are no capabilities to advertise or if we
+ * can't allocate a response, send a DL_ERROR_ACK.
+ */
+ if ((subsize == 0) || (mp1 = reallocb(mp,
+ sizeof (dl_capability_ack_t) + subsize, 0)) == NULL) {
+ dlerrorack(q, mp, DL_CAPABILITY_REQ, DL_NOTSUPPORTED, 0);
+ return;
+ }
+
+ mp = mp1;
+ DB_TYPE(mp) = M_PROTO;
+ mp->b_wptr = mp->b_rptr + sizeof (dl_capability_ack_t) + subsize;
+ bzero(mp->b_rptr, MBLKL(mp));
+ dlap = (dl_capability_ack_t *)mp->b_rptr;
+ dlap->dl_primitive = DL_CAPABILITY_ACK;
+ dlap->dl_sub_offset = sizeof (dl_capability_ack_t);
+ dlap->dl_sub_length = subsize;
+ ptr = (uint8_t *)&dlap[1];
+
+ /*
+ * IP polling interface.
+ */
+ if (dld_capable) {
+ dl_capab_dld_t dld;
+
+ dlsp = (dl_capability_sub_t *)ptr;
+ dlsp->dl_cap = DL_CAPAB_DLD;
+ dlsp->dl_length = sizeof (dl_capab_dld_t);
+ ptr += sizeof (dl_capability_sub_t);
+
+ bzero(&dld, sizeof (dl_capab_dld_t));
+ dld.dld_version = DLD_CURRENT_VERSION;
+ dld.dld_capab = (uintptr_t)softmac_dld_capab;
+ dld.dld_capab_handle = (uintptr_t)sup;
+
+ dlcapabsetqid(&(dld.dld_mid), sup->su_rq);
+ bcopy(&dld, ptr, sizeof (dl_capab_dld_t));
+ ptr += sizeof (dl_capab_dld_t);
+ }
+
+ /*
+ * TCP/IP checksum offload.
+ */
+ if (hcksum_capable) {
+ dl_capab_hcksum_t hcksum;
+
+ dlsp = (dl_capability_sub_t *)ptr;
+
+ dlsp->dl_cap = DL_CAPAB_HCKSUM;
+ dlsp->dl_length = sizeof (dl_capab_hcksum_t);
+ ptr += sizeof (dl_capability_sub_t);
+
+ bzero(&hcksum, sizeof (dl_capab_hcksum_t));
+ hcksum.hcksum_version = HCKSUM_VERSION_1;
+ hcksum.hcksum_txflags = softmac->smac_hcksum_txflags;
+ dlcapabsetqid(&(hcksum.hcksum_mid), sup->su_rq);
+ bcopy(&hcksum, ptr, sizeof (dl_capab_hcksum_t));
+ ptr += sizeof (dl_capab_hcksum_t);
+ }
+
+ /*
+ * Zero copy
+ */
+ if (zcopy_capable) {
+ dl_capab_zerocopy_t zcopy;
+
+ dlsp = (dl_capability_sub_t *)ptr;
+
+ dlsp->dl_cap = DL_CAPAB_ZEROCOPY;
+ dlsp->dl_length = sizeof (dl_capab_zerocopy_t);
+ ptr += sizeof (dl_capability_sub_t);
+
+ bzero(&zcopy, sizeof (dl_capab_zerocopy_t));
+ zcopy.zerocopy_version = ZEROCOPY_VERSION_1;
+ zcopy.zerocopy_flags = DL_CAPAB_VMSAFE_MEM;
+ dlcapabsetqid(&(zcopy.zerocopy_mid), sup->su_rq);
+ bcopy(&zcopy, ptr, sizeof (dl_capab_zerocopy_t));
+ ptr += sizeof (dl_capab_zerocopy_t);
+ }
+
+ /*
+ * MDT
+ */
+ if (mdt_capable) {
+ dl_capab_mdt_t mdt;
+
+ dlsp = (dl_capability_sub_t *)ptr;
+
+ dlsp->dl_cap = DL_CAPAB_MDT;
+ dlsp->dl_length = sizeof (dl_capab_mdt_t);
+ ptr += sizeof (dl_capability_sub_t);
+
+ bzero(&mdt, sizeof (dl_capab_mdt_t));
+ mdt.mdt_version = MDT_VERSION_2;
+ mdt.mdt_flags = DL_CAPAB_MDT_ENABLE;
+ mdt.mdt_hdr_head = softmac->smac_mdt_capab.mdt_hdr_head;
+ mdt.mdt_hdr_tail = softmac->smac_mdt_capab.mdt_hdr_tail;
+ mdt.mdt_max_pld = softmac->smac_mdt_capab.mdt_max_pld;
+ mdt.mdt_span_limit = softmac->smac_mdt_capab.mdt_span_limit;
+ dlcapabsetqid(&(mdt.mdt_mid), sup->su_rq);
+ bcopy(&mdt, ptr, sizeof (dl_capab_mdt_t));
+ ptr += sizeof (dl_capab_mdt_t);
+ }
+
+ ASSERT(ptr == mp->b_rptr + sizeof (dl_capability_ack_t) + subsize);
+ qreply(q, mp);
+}
+
+static void
+softmac_capability_req(softmac_upper_t *sup, mblk_t *mp)
+{
+ dl_capability_req_t *dlp = (dl_capability_req_t *)mp->b_rptr;
+ dl_capability_sub_t *sp;
+ size_t size, len;
+ offset_t off, end;
+ t_uscalar_t dl_err;
+ queue_t *q = sup->su_wq;
+
+ ASSERT(sup->su_mode == SOFTMAC_FASTPATH);
+ if (MBLKL(mp) < sizeof (dl_capability_req_t)) {
+ dl_err = DL_BADPRIM;
+ goto failed;
+ }
+
+ if (!sup->su_bound) {
+ dl_err = DL_OUTSTATE;
+ goto failed;
+ }
+
+ /*
+ * This request is overloaded. If there are no requested capabilities
+ * then we just want to acknowledge with all the capabilities we
+ * support. Otherwise we enable the set of capabilities requested.
+ */
+ if (dlp->dl_sub_length == 0) {
+ softmac_capability_advertise(sup, mp);
+ return;
+ }
+
+ if (!MBLKIN(mp, dlp->dl_sub_offset, dlp->dl_sub_length)) {
+ dl_err = DL_BADPRIM;
+ goto failed;
+ }
+
+ dlp->dl_primitive = DL_CAPABILITY_ACK;
+
+ off = dlp->dl_sub_offset;
+ len = dlp->dl_sub_length;
+
+ /*
+ * Walk the list of capabilities to be enabled.
+ */
+ for (end = off + len; off < end; ) {
+ sp = (dl_capability_sub_t *)(mp->b_rptr + off);
+ size = sizeof (dl_capability_sub_t) + sp->dl_length;
+
+ if (off + size > end ||
+ !IS_P2ALIGNED(off, sizeof (uint32_t))) {
+ dl_err = DL_BADPRIM;
+ goto failed;
+ }
+
+ switch (sp->dl_cap) {
+ /*
+ * TCP/IP checksum offload to hardware.
+ */
+ case DL_CAPAB_HCKSUM: {
+ dl_capab_hcksum_t *hcksump;
+ dl_capab_hcksum_t hcksum;
+
+ hcksump = (dl_capab_hcksum_t *)&sp[1];
+ /*
+ * Copy for alignment.
+ */
+ bcopy(hcksump, &hcksum, sizeof (dl_capab_hcksum_t));
+ dlcapabsetqid(&(hcksum.hcksum_mid), sup->su_rq);
+ bcopy(&hcksum, hcksump, sizeof (dl_capab_hcksum_t));
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ off += size;
+ }
+ qreply(q, mp);
+ return;
+failed:
+ dlerrorack(q, mp, DL_CAPABILITY_REQ, dl_err, 0);
+}
+
+static void
+softmac_bind_req(softmac_upper_t *sup, mblk_t *mp)
+{
+ softmac_lower_t *slp = sup->su_slp;
+ softmac_t *softmac = sup->su_softmac;
+ mblk_t *ackmp, *mp1;
+ int err;
+
+ if (MBLKL(mp) < DL_BIND_REQ_SIZE) {
+ freemsg(mp);
+ return;
+ }
+
+ /*
+ * Allocate ackmp incase the underlying driver does not ack timely.
+ */
+ if ((mp1 = allocb(sizeof (dl_error_ack_t), BPRI_HI)) == NULL) {
+ dlerrorack(sup->su_wq, mp, DL_BIND_REQ, DL_SYSERR, ENOMEM);
+ return;
+ }
+
+ err = softmac_output(slp, mp, DL_BIND_REQ, DL_BIND_ACK, &ackmp);
+ if (ackmp != NULL) {
+ freemsg(mp1);
+ } else {
+ /*
+ * The driver does not ack timely.
+ */
+ ASSERT(err == ENOMSG);
+ ackmp = mp1;
+ }
+ if (err != 0)
+ goto failed;
+
+ /*
+ * Enable capabilities the underlying driver claims to support.
+ */
+ if ((err = softmac_capab_enable(slp)) != 0)
+ goto failed;
+
+ /*
+ * Check whether this softmac is already marked as exclusively used,
+ * e.g., an aggregation is created over it. Fail the BIND_REQ if so.
+ */
+ mutex_enter(&softmac->smac_active_mutex);
+ if (softmac->smac_active) {
+ mutex_exit(&softmac->smac_active_mutex);
+ err = EBUSY;
+ goto failed;
+ }
+ softmac->smac_nactive++;
+ sup->su_active = B_TRUE;
+ mutex_exit(&softmac->smac_active_mutex);
+ sup->su_bound = B_TRUE;
+
+ qreply(sup->su_wq, ackmp);
+ return;
+failed:
+ if (err != 0) {
+ dlerrorack(sup->su_wq, ackmp, DL_BIND_REQ, DL_SYSERR, err);
+ return;
+ }
+}
+
+static void
+softmac_unbind_req(softmac_upper_t *sup, mblk_t *mp)
+{
+ softmac_lower_t *slp = sup->su_slp;
+ softmac_t *softmac = sup->su_softmac;
+ mblk_t *ackmp, *mp1;
+ int err;
+
+ if (MBLKL(mp) < DL_UNBIND_REQ_SIZE) {
+ freemsg(mp);
+ return;
+ }
+
+ if (!sup->su_bound) {
+ dlerrorack(sup->su_wq, mp, DL_UNBIND_REQ, DL_OUTSTATE, 0);
+ return;
+ }
+
+ /*
+ * Allocate ackmp incase the underlying driver does not ack timely.
+ */
+ if ((mp1 = allocb(sizeof (dl_error_ack_t), BPRI_HI)) == NULL) {
+ dlerrorack(sup->su_wq, mp, DL_UNBIND_REQ, DL_SYSERR, ENOMEM);
+ return;
+ }
+
+ err = softmac_output(slp, mp, DL_UNBIND_REQ, DL_OK_ACK, &ackmp);
+ if (ackmp != NULL) {
+ freemsg(mp1);
+ } else {
+ /*
+ * The driver does not ack timely.
+ */
+ ASSERT(err == ENOMSG);
+ ackmp = mp1;
+ }
+ if (err != 0) {
+ dlerrorack(sup->su_wq, ackmp, DL_UNBIND_REQ, DL_SYSERR, err);
+ return;
+ }
+
+ sup->su_bound = B_FALSE;
+
+ mutex_enter(&softmac->smac_active_mutex);
+ if (sup->su_active) {
+ ASSERT(!softmac->smac_active);
+ softmac->smac_nactive--;
+ sup->su_active = B_FALSE;
+ }
+ mutex_exit(&softmac->smac_active_mutex);
+
+done:
+ qreply(sup->su_wq, ackmp);
+}
+
+/*
+ * Process the non-data mblk.
+ */
+static void
+softmac_wput_single_nondata(softmac_upper_t *sup, mblk_t *mp)
+{
+ softmac_t *softmac = sup->su_softmac;
+ softmac_lower_t *slp = sup->su_slp;
+ unsigned char dbtype;
+ t_uscalar_t prim;
+
+ dbtype = DB_TYPE(mp);
+ switch (dbtype) {
+ case M_IOCTL:
+ case M_CTL: {
+ uint32_t expected_mode;
+
+ if (((struct iocblk *)(mp->b_rptr))->ioc_cmd != SIOCSLIFNAME)
+ break;
+
+ /*
+ * Nak the M_IOCTL based on the STREAMS specification.
+ */
+ if (dbtype == M_IOCTL)
+ miocnak(sup->su_wq, mp, 0, EINVAL);
+
+ /*
+ * This stream is either IP or ARP. See whether
+ * we need to setup a dedicated-lower-stream for it.
+ */
+ mutex_enter(&softmac->smac_fp_mutex);
+
+ expected_mode = DATAPATH_MODE(softmac);
+ if (expected_mode == SOFTMAC_SLOWPATH)
+ sup->su_mode = SOFTMAC_SLOWPATH;
+ list_insert_head(&softmac->smac_sup_list, sup);
+ mutex_exit(&softmac->smac_fp_mutex);
+
+ /*
+ * Setup the fast-path dedicated lower stream if fast-path
+ * is expected. Note that no lock is held here, and if
+ * smac_expected_mode is changed from SOFTMAC_FASTPATH to
+ * SOFTMAC_SLOWPATH, the DL_NOTE_REPLUMB message used for
+ * data-path switching would already be queued and will
+ * be processed by softmac_wput_single_nondata() later.
+ */
+ if (expected_mode == SOFTMAC_FASTPATH)
+ (void) softmac_fastpath_setup(sup);
+ return;
+ }
+ case M_PROTO:
+ case M_PCPROTO:
+ if (MBLKL(mp) < sizeof (t_uscalar_t)) {
+ freemsg(mp);
+ return;
+ }
+ prim = ((union DL_primitives *)mp->b_rptr)->dl_primitive;
+ switch (prim) {
+ case DL_NOTIFY_IND:
+ if (MBLKL(mp) < sizeof (dl_notify_ind_t) ||
+ ((dl_notify_ind_t *)mp->b_rptr)->dl_notification !=
+ DL_NOTE_REPLUMB) {
+ freemsg(mp);
+ return;
+ }
+ /*
+ * This DL_NOTE_REPLUMB message is initiated
+ * and queued by the softmac itself, when the
+ * sup is trying to switching its datapath mode
+ * between SOFTMAC_SLOWPATH and SOFTMAC_FASTPATH.
+ * Send this message upstream.
+ */
+ qreply(sup->su_wq, mp);
+ return;
+ case DL_NOTIFY_CONF:
+ if (MBLKL(mp) < sizeof (dl_notify_conf_t) ||
+ ((dl_notify_conf_t *)mp->b_rptr)->dl_notification !=
+ DL_NOTE_REPLUMB_DONE) {
+ freemsg(mp);
+ return;
+ }
+ /*
+ * This is an indication from IP/ARP that the
+ * fastpath->slowpath switch is done.
+ */
+ freemsg(mp);
+ softmac_datapath_switch_done(sup);
+ return;
+ }
+ break;
+ }
+
+ /*
+ * No need to hold lock to check su_mode, since su_mode updating only
+ * operation is is serialized by softmac_wput_nondata_task().
+ */
+ if (sup->su_mode != SOFTMAC_FASTPATH) {
+ dld_wput(sup->su_wq, mp);
+ return;
+ }
+
+ /*
+ * Fastpath non-data message processing. Most of non-data messages
+ * can be directly passed down to the dedicated-lower-stream, aside
+ * from the following M_PROTO/M_PCPROTO messages.
+ */
+ switch (dbtype) {
+ case M_PROTO:
+ case M_PCPROTO:
+ switch (prim) {
+ case DL_BIND_REQ:
+ softmac_bind_req(sup, mp);
+ break;
+ case DL_UNBIND_REQ:
+ softmac_unbind_req(sup, mp);
+ break;
+ case DL_CAPABILITY_REQ:
+ softmac_capability_req(sup, mp);
+ break;
+ default:
+ putnext(slp->sl_wq, mp);
+ break;
+ }
+ break;
+ default:
+ putnext(slp->sl_wq, mp);
+ break;
+ }
+}
+
+/*
+ * The worker thread which processes non-data messages. Note we only process
+ * one message at one time in order to be able to "flush" the queued message
+ * and serialize the processing.
+ */
+static void
+softmac_wput_nondata_task(void *arg)
+{
+ softmac_upper_t *sup = arg;
+ mblk_t *mp;
+
+ mutex_enter(&sup->su_disp_mutex);
+
+ while (sup->su_pending_head != NULL) {
+ if (sup->su_closing)
+ break;
+
+ SOFTMAC_DQ_PENDING(sup, &mp);
+ mutex_exit(&sup->su_disp_mutex);
+ softmac_wput_single_nondata(sup, mp);
+ mutex_enter(&sup->su_disp_mutex);
+ }
+
+ /*
+ * If the stream is closing, flush all queued messages and inform
+ * the stream to be closed.
+ */
+ freemsgchain(sup->su_pending_head);
+ sup->su_pending_head = sup->su_pending_tail = NULL;
+ sup->su_dlpi_pending = B_FALSE;
+ cv_signal(&sup->su_disp_cv);
+ mutex_exit(&sup->su_disp_mutex);
+}
+
+/*
+ * Kernel thread to handle taskq dispatch failures in softmac_wput_nondata().
+ * This thread is started when the softmac module is first loaded.
+ */
+static void
+softmac_taskq_dispatch(void)
+{
+ callb_cpr_t cprinfo;
+ softmac_upper_t *sup;
+
+ CALLB_CPR_INIT(&cprinfo, &softmac_taskq_lock, callb_generic_cpr,
+ "softmac_taskq_dispatch");
+ mutex_enter(&softmac_taskq_lock);
+
+ while (!softmac_taskq_quit) {
+ sup = list_head(&softmac_taskq_list);
+ while (sup != NULL) {
+ list_remove(&softmac_taskq_list, sup);
+ sup->su_taskq_scheduled = B_FALSE;
+ mutex_exit(&softmac_taskq_lock);
+ VERIFY(taskq_dispatch(system_taskq,
+ softmac_wput_nondata_task, sup, TQ_SLEEP) != NULL);
+ mutex_enter(&softmac_taskq_lock);
+ sup = list_head(&softmac_taskq_list);
+ }
+
+ CALLB_CPR_SAFE_BEGIN(&cprinfo);
+ cv_wait(&softmac_taskq_cv, &softmac_taskq_lock);
+ CALLB_CPR_SAFE_END(&cprinfo, &softmac_taskq_lock);
+ }
+
+ softmac_taskq_done = B_TRUE;
+ cv_signal(&softmac_taskq_cv);
+ CALLB_CPR_EXIT(&cprinfo);
+ thread_exit();
+}
+
+void
+softmac_wput_nondata(softmac_upper_t *sup, mblk_t *mp)
+{
+ /*
+ * The processing of the message might block. Enqueue the
+ * message for later processing.
+ */
+ mutex_enter(&sup->su_disp_mutex);
+
+ if (sup->su_closing) {
+ mutex_exit(&sup->su_disp_mutex);
+ freemsg(mp);
+ return;
+ }
+
+ SOFTMAC_EQ_PENDING(sup, mp);
+
+ if (sup->su_dlpi_pending) {
+ mutex_exit(&sup->su_disp_mutex);
+ return;
+ }
+ sup->su_dlpi_pending = B_TRUE;
+ mutex_exit(&sup->su_disp_mutex);
+
+ if (taskq_dispatch(system_taskq, softmac_wput_nondata_task,
+ sup, TQ_NOSLEEP) != NULL) {
+ return;
+ }
+
+ mutex_enter(&softmac_taskq_lock);
+ if (!sup->su_taskq_scheduled) {
+ list_insert_tail(&softmac_taskq_list, sup);
+ cv_signal(&softmac_taskq_cv);
+ }
+ sup->su_taskq_scheduled = B_TRUE;
+ mutex_exit(&softmac_taskq_lock);
+}
+
+/*
+ * Setup the dedicated-lower-stream (fast-path) for the IP/ARP upperstream.
+ */
+static int
+softmac_fastpath_setup(softmac_upper_t *sup)
+{
+ softmac_t *softmac = sup->su_softmac;
+ softmac_lower_t *slp;
+ int err;
+
+ err = softmac_lower_setup(softmac, sup, &slp);
+
+ mutex_enter(&sup->su_mutex);
+ /*
+ * Wait for all data messages to be processed so that we can change
+ * the su_mode.
+ */
+ while (sup->su_tx_inprocess != 0)
+ cv_wait(&sup->su_cv, &sup->su_mutex);
+
+ ASSERT(sup->su_mode != SOFTMAC_FASTPATH);
+ ASSERT(sup->su_slp == NULL);
+ if (err != 0) {
+ sup->su_mode = SOFTMAC_SLOWPATH;
+ } else {
+ sup->su_slp = slp;
+ sup->su_mode = SOFTMAC_FASTPATH;
+ }
+ mutex_exit(&sup->su_mutex);
+ return (err);
+}
+
+/*
+ * Tear down the dedicated-lower-stream (fast-path) for the IP/ARP upperstream.
+ */
+static void
+softmac_fastpath_tear(softmac_upper_t *sup)
+{
+ mutex_enter(&sup->su_mutex);
+ /*
+ * Wait for all data messages in the dedicated-lower-stream
+ * to be processed.
+ */
+ while (sup->su_tx_inprocess != 0)
+ cv_wait(&sup->su_cv, &sup->su_mutex);
+
+ if (sup->su_tx_busy) {
+ ASSERT(sup->su_tx_flow_mp == NULL);
+ sup->su_tx_flow_mp = getq(sup->su_wq);
+ sup->su_tx_busy = B_FALSE;
+ }
+
+ sup->su_mode = SOFTMAC_SLOWPATH;
+
+ /*
+ * Destroy the dedicated-lower-stream. Note that slp is destroyed
+ * when lh is closed.
+ */
+ (void) ldi_close(sup->su_slp->sl_lh, FREAD|FWRITE, kcred);
+ sup->su_slp = NULL;
+ mutex_exit(&sup->su_mutex);
+}
+
+void
+softmac_wput_data(softmac_upper_t *sup, mblk_t *mp)
+{
+ /*
+ * No lock is required to access the su_mode field since the data
+ * traffic is quiesce by IP when the data-path mode is in the
+ * process of switching.
+ */
+ if (sup->su_mode != SOFTMAC_FASTPATH)
+ dld_wput(sup->su_wq, mp);
+ else
+ (void) softmac_fastpath_wput_data(sup, mp, NULL, 0);
+}
+
+/*ARGSUSED*/
+static mac_tx_cookie_t
+softmac_fastpath_wput_data(softmac_upper_t *sup, mblk_t *mp, uintptr_t f_hint,
+ uint16_t flag)
+{
+ queue_t *wq = sup->su_slp->sl_wq;
+
+ /*
+ * This function is called from IP, only the MAC_DROP_ON_NO_DESC
+ * flag can be specified.
+ */
+ ASSERT((flag & ~MAC_DROP_ON_NO_DESC) == 0);
+ ASSERT(mp->b_next == NULL);
+
+ /*
+ * Check wether the dedicated-lower-stream is able to handle more
+ * messages, and enable the flow-control if it is not.
+ *
+ * Note that in order not to introduce any packet reordering, we
+ * always send the message down to the dedicated-lower-stream:
+ *
+ * If the flow-control is already enabled, but we still get
+ * the messages from the upper-stream, it means that the upper
+ * stream does not respect STREAMS flow-control (e.g., TCP). Simply
+ * pass the message down to the lower-stream in that case.
+ */
+ if (SOFTMAC_CANPUTNEXT(wq)) {
+ putnext(wq, mp);
+ return (NULL);
+ }
+
+ if ((flag & MAC_DROP_ON_NO_DESC) != 0) {
+ freemsg(mp);
+ return ((mac_tx_cookie_t)wq);
+ }
+
+ if (sup->su_tx_busy) {
+ putnext(wq, mp);
+ return ((mac_tx_cookie_t)wq);
+ }
+
+ mutex_enter(&sup->su_mutex);
+ if (!sup->su_tx_busy) {
+ ASSERT(sup->su_tx_flow_mp != NULL);
+ (void) putq(sup->su_wq, sup->su_tx_flow_mp);
+ sup->su_tx_flow_mp = NULL;
+ sup->su_tx_busy = B_TRUE;
+ qenable(wq);
+ }
+ mutex_exit(&sup->su_mutex);
+ putnext(wq, mp);
+ return ((mac_tx_cookie_t)wq);
+}
+
+boolean_t
+softmac_active_set(void *arg)
+{
+ softmac_t *softmac = arg;
+
+ mutex_enter(&softmac->smac_active_mutex);
+ if (softmac->smac_nactive != 0) {
+ mutex_exit(&softmac->smac_active_mutex);
+ return (B_FALSE);
+ }
+ softmac->smac_active = B_TRUE;
+ mutex_exit(&softmac->smac_active_mutex);
+ return (B_TRUE);
+}
+
+void
+softmac_active_clear(void *arg)
+{
+ softmac_t *softmac = arg;
+
+ mutex_enter(&softmac->smac_active_mutex);
+ ASSERT(softmac->smac_active && (softmac->smac_nactive == 0));
+ softmac->smac_active = B_FALSE;
+ mutex_exit(&softmac->smac_active_mutex);
+}
+
+/*
+ * Disable/reenable fastpath on given softmac. This request could come from a
+ * MAC client or directly from administrators.
+ */
+int
+softmac_datapath_switch(softmac_t *softmac, boolean_t disable, boolean_t admin)
+{
+ softmac_upper_t *sup;
+ mblk_t *head = NULL, *tail = NULL, *mp;
+ list_t reqlist;
+ softmac_switch_req_t *req;
+ uint32_t current_mode, expected_mode;
+ int err = 0;
+
+ mutex_enter(&softmac->smac_fp_mutex);
+
+ current_mode = DATAPATH_MODE(softmac);
+ if (admin) {
+ if (softmac->smac_fastpath_admin_disabled == disable) {
+ mutex_exit(&softmac->smac_fp_mutex);
+ return (0);
+ }
+ softmac->smac_fastpath_admin_disabled = disable;
+ } else if (disable) {
+ softmac->smac_fp_disable_clients++;
+ } else {
+ ASSERT(softmac->smac_fp_disable_clients != 0);
+ softmac->smac_fp_disable_clients--;
+ }
+
+ expected_mode = DATAPATH_MODE(softmac);
+ if (current_mode == expected_mode) {
+ mutex_exit(&softmac->smac_fp_mutex);
+ return (0);
+ }
+
+ /*
+ * The expected mode is different from whatever datapath mode
+ * this softmac is expected from last request, enqueue the data-path
+ * switch request.
+ */
+ list_create(&reqlist, sizeof (softmac_switch_req_t),
+ offsetof(softmac_switch_req_t, ssq_req_list_node));
+
+ /*
+ * Allocate all DL_NOTIFY_IND messages and request structures that
+ * are required to switch each IP/ARP stream to the expected mode.
+ */
+ for (sup = list_head(&softmac->smac_sup_list); sup != NULL;
+ sup = list_next(&softmac->smac_sup_list, sup)) {
+ dl_notify_ind_t *dlip;
+
+ req = kmem_alloc(sizeof (softmac_switch_req_t), KM_NOSLEEP);
+ if (req == NULL)
+ break;
+
+ req->ssq_expected_mode = expected_mode;
+
+ /*
+ * Allocate the DL_NOTE_REPLUMB message.
+ */
+ if ((mp = allocb(sizeof (dl_notify_ind_t), BPRI_LO)) == NULL) {
+ kmem_free(req, sizeof (softmac_switch_req_t));
+ break;
+ }
+
+ list_insert_tail(&reqlist, req);
+
+ mp->b_wptr = mp->b_rptr + sizeof (dl_notify_ind_t);
+ mp->b_datap->db_type = M_PROTO;
+ bzero(mp->b_rptr, sizeof (dl_notify_ind_t));
+ dlip = (dl_notify_ind_t *)mp->b_rptr;
+ dlip->dl_primitive = DL_NOTIFY_IND;
+ dlip->dl_notification = DL_NOTE_REPLUMB;
+ if (head == NULL) {
+ head = tail = mp;
+ } else {
+ tail->b_next = mp;
+ tail = mp;
+ }
+ }
+
+ /*
+ * Note that it is fine if the expected data-path mode is fast-path
+ * and some of streams fails to switch. Only return failure if we
+ * are expected to switch to the slow-path.
+ */
+ if (sup != NULL && expected_mode == SOFTMAC_SLOWPATH) {
+ err = ENOMEM;
+ goto fail;
+ }
+
+ /*
+ * Start switching for each IP/ARP stream. The switching operation
+ * will eventually succeed and there is no need to wait for it
+ * to finish.
+ */
+ for (sup = list_head(&softmac->smac_sup_list); sup != NULL;
+ sup = list_next(&softmac->smac_sup_list, sup)) {
+ mp = head->b_next;
+ head->b_next = NULL;
+
+ /*
+ * Add the swtich request to the requests list of the stream.
+ */
+ req = list_head(&reqlist);
+ ASSERT(req != NULL);
+ list_remove(&reqlist, req);
+ list_insert_tail(&sup->su_req_list, req);
+ softmac_wput_nondata(sup, head);
+ head = mp;
+ }
+
+ mutex_exit(&softmac->smac_fp_mutex);
+ ASSERT(list_is_empty(&reqlist));
+ list_destroy(&reqlist);
+ return (0);
+fail:
+ if (admin) {
+ softmac->smac_fastpath_admin_disabled = !disable;
+ } else if (disable) {
+ softmac->smac_fp_disable_clients--;
+ } else {
+ softmac->smac_fp_disable_clients++;
+ }
+
+ mutex_exit(&softmac->smac_fp_mutex);
+ while ((req = list_head(&reqlist)) != NULL) {
+ list_remove(&reqlist, req);
+ kmem_free(req, sizeof (softmac_switch_req_t));
+ }
+ freemsgchain(head);
+ list_destroy(&reqlist);
+ return (err);
+}
+
+int
+softmac_fastpath_disable(void *arg)
+{
+ return (softmac_datapath_switch((softmac_t *)arg, B_TRUE, B_FALSE));
+}
+
+void
+softmac_fastpath_enable(void *arg)
+{
+ VERIFY(softmac_datapath_switch((softmac_t *)arg, B_FALSE,
+ B_FALSE) == 0);
+}
+
+void
+softmac_upperstream_close(softmac_upper_t *sup)
+{
+ softmac_t *softmac = sup->su_softmac;
+ softmac_switch_req_t *req;
+
+ mutex_enter(&softmac->smac_fp_mutex);
+
+ if (sup->su_mode == SOFTMAC_FASTPATH)
+ softmac_fastpath_tear(sup);
+
+ if (sup->su_mode != SOFTMAC_UNKNOWN) {
+ list_remove(&softmac->smac_sup_list, sup);
+ sup->su_mode = SOFTMAC_UNKNOWN;
+ }
+
+ /*
+ * Cleanup all the switch requests queueed on this stream.
+ */
+ while ((req = list_head(&sup->su_req_list)) != NULL) {
+ list_remove(&sup->su_req_list, req);
+ kmem_free(req, sizeof (softmac_switch_req_t));
+ }
+ mutex_exit(&softmac->smac_fp_mutex);
+}
+
+/*
+ * Handle the DL_NOTE_REPLUMB_DONE indication from IP/ARP. Change the upper
+ * stream from the fastpath mode to the slowpath mode.
+ */
+static void
+softmac_datapath_switch_done(softmac_upper_t *sup)
+{
+ softmac_t *softmac = sup->su_softmac;
+ softmac_switch_req_t *req;
+ uint32_t expected_mode;
+
+ mutex_enter(&softmac->smac_fp_mutex);
+ req = list_head(&sup->su_req_list);
+ list_remove(&sup->su_req_list, req);
+ expected_mode = req->ssq_expected_mode;
+ kmem_free(req, sizeof (softmac_switch_req_t));
+
+ if (expected_mode == sup->su_mode) {
+ mutex_exit(&softmac->smac_fp_mutex);
+ return;
+ }
+
+ ASSERT(!sup->su_bound);
+ mutex_exit(&softmac->smac_fp_mutex);
+
+ /*
+ * It is fine if the expected mode is fast-path and we fail
+ * to enable fastpath on this stream.
+ */
+ if (expected_mode == SOFTMAC_SLOWPATH)
+ softmac_fastpath_tear(sup);
+ else
+ (void) softmac_fastpath_setup(sup);
+}
diff --git a/usr/src/uts/common/io/softmac/softmac_main.c b/usr/src/uts/common/io/softmac/softmac_main.c
index a44856c849..bfdf3ee851 100644
--- a/usr/src/uts/common/io/softmac/softmac_main.c
+++ b/usr/src/uts/common/io/softmac/softmac_main.c
@@ -69,6 +69,8 @@ static mod_hash_t *softmac_hash;
static kmutex_t smac_global_lock;
static kcondvar_t smac_global_cv;
+static kmem_cache_t *softmac_cachep;
+
#define SOFTMAC_HASHSZ 64
static void softmac_create_task(void *);
@@ -79,9 +81,14 @@ static void softmac_m_stop(void *);
static int softmac_m_open(void *);
static void softmac_m_close(void *);
static boolean_t softmac_m_getcapab(void *, mac_capab_t, void *);
+static int softmac_m_setprop(void *, const char *, mac_prop_id_t,
+ uint_t, const void *);
+static int softmac_m_getprop(void *, const char *, mac_prop_id_t,
+ uint_t, uint_t, void *, uint_t *);
+
#define SOFTMAC_M_CALLBACK_FLAGS \
- (MC_IOCTL | MC_GETCAPAB | MC_OPEN | MC_CLOSE)
+ (MC_IOCTL | MC_GETCAPAB | MC_OPEN | MC_CLOSE | MC_SETPROP | MC_GETPROP)
static mac_callbacks_t softmac_m_callbacks = {
SOFTMAC_M_CALLBACK_FLAGS,
@@ -95,9 +102,57 @@ static mac_callbacks_t softmac_m_callbacks = {
softmac_m_ioctl,
softmac_m_getcapab,
softmac_m_open,
- softmac_m_close
+ softmac_m_close,
+ softmac_m_setprop,
+ softmac_m_getprop
};
+/*ARGSUSED*/
+static int
+softmac_constructor(void *buf, void *arg, int kmflag)
+{
+ softmac_t *softmac = buf;
+
+ bzero(buf, sizeof (softmac_t));
+ mutex_init(&softmac->smac_mutex, NULL, MUTEX_DEFAULT, NULL);
+ mutex_init(&softmac->smac_active_mutex, NULL, MUTEX_DEFAULT, NULL);
+ mutex_init(&softmac->smac_fp_mutex, NULL, MUTEX_DEFAULT, NULL);
+ cv_init(&softmac->smac_cv, NULL, CV_DEFAULT, NULL);
+ cv_init(&softmac->smac_fp_cv, NULL, CV_DEFAULT, NULL);
+ list_create(&softmac->smac_sup_list, sizeof (softmac_upper_t),
+ offsetof(softmac_upper_t, su_list_node));
+ return (0);
+}
+
+/*ARGSUSED*/
+static void
+softmac_destructor(void *buf, void *arg)
+{
+ softmac_t *softmac = buf;
+
+ ASSERT(softmac->smac_fp_disable_clients == 0);
+ ASSERT(!softmac->smac_fastpath_admin_disabled);
+
+ ASSERT(!(softmac->smac_flags & SOFTMAC_ATTACH_DONE));
+ ASSERT(softmac->smac_hold_cnt == 0);
+ ASSERT(softmac->smac_attachok_cnt == 0);
+ ASSERT(softmac->smac_mh == NULL);
+ ASSERT(softmac->smac_softmac[0] == NULL &&
+ softmac->smac_softmac[1] == NULL);
+ ASSERT(softmac->smac_state == SOFTMAC_INITIALIZED);
+ ASSERT(softmac->smac_lower == NULL);
+ ASSERT(softmac->smac_active == B_FALSE);
+ ASSERT(softmac->smac_nactive == 0);
+ ASSERT(list_is_empty(&softmac->smac_sup_list));
+
+ list_destroy(&softmac->smac_sup_list);
+ mutex_destroy(&softmac->smac_mutex);
+ mutex_destroy(&softmac->smac_active_mutex);
+ mutex_destroy(&softmac->smac_fp_mutex);
+ cv_destroy(&softmac->smac_cv);
+ cv_destroy(&softmac->smac_fp_cv);
+}
+
void
softmac_init()
{
@@ -108,11 +163,19 @@ softmac_init()
rw_init(&softmac_hash_lock, NULL, RW_DEFAULT, NULL);
mutex_init(&smac_global_lock, NULL, MUTEX_DRIVER, NULL);
cv_init(&smac_global_cv, NULL, CV_DRIVER, NULL);
+
+ softmac_cachep = kmem_cache_create("softmac_cache",
+ sizeof (softmac_t), 0, softmac_constructor,
+ softmac_destructor, NULL, NULL, NULL, 0);
+ ASSERT(softmac_cachep != NULL);
+ softmac_fp_init();
}
void
softmac_fini()
{
+ softmac_fp_fini();
+ kmem_cache_destroy(softmac_cachep);
rw_destroy(&softmac_hash_lock);
mod_hash_destroy_hash(softmac_hash);
mutex_destroy(&smac_global_lock);
@@ -281,16 +344,12 @@ softmac_create(dev_info_t *dip, dev_t dev)
* Check whether the softmac for the specified device already exists
*/
rw_enter(&softmac_hash_lock, RW_WRITER);
- if ((err = mod_hash_find(softmac_hash, (mod_hash_key_t)devname,
+ if ((mod_hash_find(softmac_hash, (mod_hash_key_t)devname,
(mod_hash_val_t *)&softmac)) != 0) {
- softmac = kmem_zalloc(sizeof (softmac_t), KM_SLEEP);
- mutex_init(&softmac->smac_mutex, NULL, MUTEX_DRIVER, NULL);
- cv_init(&softmac->smac_cv, NULL, CV_DRIVER, NULL);
+ softmac = kmem_cache_alloc(softmac_cachep, KM_SLEEP);
(void) strlcpy(softmac->smac_devname, devname, MAXNAMELEN);
- /*
- * Insert the softmac into the hash table.
- */
+
err = mod_hash_insert(softmac_hash,
(mod_hash_key_t)softmac->smac_devname,
(mod_hash_val_t)softmac);
@@ -413,8 +472,18 @@ softmac_m_getcapab(void *arg, mac_capab_t cap, void *cap_data)
case MAC_CAPAB_LEGACY: {
mac_capab_legacy_t *legacy = cap_data;
+ /*
+ * The caller is not interested in the details.
+ */
+ if (legacy == NULL)
+ break;
+
legacy->ml_unsup_note = ~softmac->smac_notifications &
(DL_NOTE_LINK_UP | DL_NOTE_LINK_DOWN | DL_NOTE_SPEED);
+ legacy->ml_active_set = softmac_active_set;
+ legacy->ml_active_clear = softmac_active_clear;
+ legacy->ml_fastpath_disable = softmac_fastpath_disable;
+ legacy->ml_fastpath_enable = softmac_fastpath_enable;
legacy->ml_dev = makedevice(softmac->smac_umajor,
softmac->smac_uppa + 1);
break;
@@ -816,22 +885,23 @@ softmac_mac_register(softmac_t *softmac)
* Try to create the datalink for this softmac.
*/
if ((err = softmac_create_datalink(softmac)) != 0) {
- if (!(softmac->smac_flags & SOFTMAC_NOSUPP)) {
+ if (!(softmac->smac_flags & SOFTMAC_NOSUPP))
(void) mac_unregister(softmac->smac_mh);
- softmac->smac_mh = NULL;
- }
+ mutex_enter(&softmac->smac_mutex);
+ softmac->smac_mh = NULL;
+ goto done;
}
/*
* If succeed, create the thread which handles the DL_NOTIFY_IND from
* the lower stream.
*/
+ mutex_enter(&softmac->smac_mutex);
if (softmac->smac_mh != NULL) {
softmac->smac_notify_thread = thread_create(NULL, 0,
softmac_notify_thread, softmac, 0, &p0,
TS_RUN, minclsyspri);
}
- mutex_enter(&softmac->smac_mutex);
done:
ASSERT(softmac->smac_state == SOFTMAC_ATTACH_INPROG &&
softmac->smac_attachok_cnt == softmac->smac_cnt);
@@ -967,7 +1037,6 @@ softmac_destroy(dev_info_t *dip, dev_t dev)
rw_exit(&softmac_hash_lock);
return (0);
}
-
err = mod_hash_remove(softmac_hash,
(mod_hash_key_t)devname,
(mod_hash_val_t *)&hashval);
@@ -975,10 +1044,9 @@ softmac_destroy(dev_info_t *dip, dev_t dev)
mutex_exit(&softmac->smac_mutex);
rw_exit(&softmac_hash_lock);
-
- mutex_destroy(&softmac->smac_mutex);
- cv_destroy(&softmac->smac_cv);
- kmem_free(softmac, sizeof (softmac_t));
+ ASSERT(softmac->smac_fp_disable_clients == 0);
+ softmac->smac_fastpath_admin_disabled = B_FALSE;
+ kmem_cache_free(softmac_cachep, softmac);
return (0);
}
mutex_exit(&softmac->smac_mutex);
@@ -1119,27 +1187,84 @@ softmac_recreate()
} while (smw.smw_retry);
}
-/* ARGSUSED */
static int
softmac_m_start(void *arg)
{
- return (0);
+ softmac_t *softmac = arg;
+ softmac_lower_t *slp = softmac->smac_lower;
+ int err;
+
+ ASSERT(MAC_PERIM_HELD(softmac->smac_mh));
+ /*
+ * Bind to SAP 2 on token ring, 0 on other interface types.
+ * (SAP 0 has special significance on token ring).
+ * Note that the receive-side packets could come anytime after bind.
+ */
+ err = softmac_send_bind_req(slp, softmac->smac_media == DL_TPR ? 2 : 0);
+ if (err != 0)
+ return (err);
+
+ /*
+ * Put the lower stream to the DL_PROMISC_SAP mode in order to receive
+ * all packets of interest.
+ *
+ * some driver (e.g. the old legacy eri driver) incorrectly passes up
+ * packets to DL_PROMISC_SAP stream when the lower stream is not bound,
+ * so that we send DL_PROMISON_REQ after DL_BIND_REQ.
+ */
+ err = softmac_send_promisc_req(slp, DL_PROMISC_SAP, B_TRUE);
+ if (err != 0) {
+ (void) softmac_send_unbind_req(slp);
+ return (err);
+ }
+
+ /*
+ * Enable capabilities the underlying driver claims to support.
+ * Some driver requires this being called after the stream is bound.
+ */
+ if ((err = softmac_capab_enable(slp)) != 0) {
+ (void) softmac_send_promisc_req(slp, DL_PROMISC_SAP, B_FALSE);
+ (void) softmac_send_unbind_req(slp);
+ }
+
+ return (err);
}
/* ARGSUSED */
static void
softmac_m_stop(void *arg)
{
+ softmac_t *softmac = arg;
+ softmac_lower_t *slp = softmac->smac_lower;
+
+ ASSERT(MAC_PERIM_HELD(softmac->smac_mh));
+
+ /*
+ * It is not needed to reset zerocopy, MDT or HCKSUM capabilities.
+ */
+ (void) softmac_send_promisc_req(slp, DL_PROMISC_SAP, B_FALSE);
+ (void) softmac_send_unbind_req(slp);
}
/*
- * Set up the lower stream above the legacy device which is shared by
- * GLDv3 MAC clients. Put the lower stream into DLIOCRAW mode to send
- * and receive the raw data. Further, put the lower stream into
+ * Set up the lower stream above the legacy device. There are two different
+ * type of lower streams:
+ *
+ * - Shared lower-stream
+ *
+ * Shared by all GLDv3 MAC clients. Put the lower stream to the DLIOCRAW
+ * mode to send and receive the raw data. Further, put the lower stream into
* DL_PROMISC_SAP mode to receive all packets of interest.
+ *
+ * - Dedicated lower-stream
+ *
+ * The lower-stream which is dedicated to upper IP/ARP stream. This is used
+ * as fast-path for IP. In this case, the second argument is the pointer to
+ * the softmac upper-stream.
*/
-static int
-softmac_lower_setup(softmac_t *softmac, softmac_lower_t **slpp)
+int
+softmac_lower_setup(softmac_t *softmac, softmac_upper_t *sup,
+ softmac_lower_t **slpp)
{
ldi_ident_t li;
dev_t dev;
@@ -1153,7 +1278,13 @@ softmac_lower_setup(softmac_t *softmac, softmac_lower_t **slpp)
if ((err = ldi_ident_from_dip(softmac_dip, &li)) != 0)
return (err);
+ /*
+ * The GLDv3 framework makes sure that mac_unregister(), mac_open(),
+ * and mac_close() cannot be called at the same time. So we don't
+ * need any protection to access softmac here.
+ */
dev = softmac->smac_dev;
+
err = ldi_open_by_dev(&dev, OTYP_CHR, FREAD|FWRITE, kcred, &lh, li);
ldi_ident_release(li);
if (err != 0)
@@ -1172,10 +1303,13 @@ softmac_lower_setup(softmac_t *softmac, softmac_lower_t **slpp)
}
/*
- * Put the lower stream into DLIOCRAW mode to send/receive raw data.
+ * If this is the shared-lower-stream, put the lower stream to
+ * the DLIOCRAW mode to send/receive raw data.
*/
- if ((err = ldi_ioctl(lh, DLIOCRAW, 0, FKIOCTL, kcred, &rval)) != 0)
+ if ((sup == NULL) && (err = ldi_ioctl(lh, DLIOCRAW, 0, FKIOCTL,
+ kcred, &rval)) != 0) {
goto done;
+ }
/*
* Then push the softmac shim layer atop the lower stream.
@@ -1198,50 +1332,25 @@ softmac_lower_setup(softmac_t *softmac, softmac_lower_t **slpp)
goto done;
}
slp = start_arg.si_slp;
+ slp->sl_sup = sup;
slp->sl_lh = lh;
slp->sl_softmac = softmac;
*slpp = slp;
- /*
- * Bind to SAP 2 on token ring, 0 on other interface types.
- * (SAP 0 has special significance on token ring).
- * Note that the receive-side packets could come anytime after bind.
- */
- if (softmac->smac_media == DL_TPR)
- err = softmac_send_bind_req(slp, 2);
- else
- err = softmac_send_bind_req(slp, 0);
- if (err != 0)
- goto done;
-
- /*
- * Put the lower stream into DL_PROMISC_SAP mode to receive all
- * packets of interest.
- *
- * Some drivers (e.g. the old legacy eri driver) incorrectly pass up
- * packets to DL_PROMISC_SAP stream when the lower stream is not bound,
- * so we send DL_PROMISON_REQ after DL_BIND_REQ.
- */
- if ((err = softmac_send_promisc_req(slp, DL_PROMISC_SAP, B_TRUE)) != 0)
- goto done;
-
- /*
- * Enable the capabilities the underlying driver claims to support.
- * Some drivers require this to be called after the stream is bound.
- */
- if ((err = softmac_capab_enable(slp)) != 0)
- goto done;
-
- /*
- * Send the DL_NOTIFY_REQ to enable certain DL_NOTIFY_IND.
- * We don't have to wait for the ack.
- */
- notifications = DL_NOTE_PHYS_ADDR | DL_NOTE_LINK_UP |
- DL_NOTE_LINK_DOWN | DL_NOTE_PROMISC_ON_PHYS |
- DL_NOTE_PROMISC_OFF_PHYS;
+ if (sup != NULL) {
+ slp->sl_rxinfo = &sup->su_rxinfo;
+ } else {
+ /*
+ * Send DL_NOTIFY_REQ to enable certain DL_NOTIFY_IND.
+ * We don't have to wait for the ack.
+ */
+ notifications = DL_NOTE_PHYS_ADDR | DL_NOTE_LINK_UP |
+ DL_NOTE_LINK_DOWN | DL_NOTE_PROMISC_ON_PHYS |
+ DL_NOTE_PROMISC_OFF_PHYS;
- (void) softmac_send_notify_req(slp,
- (notifications & softmac->smac_notifications));
+ (void) softmac_send_notify_req(slp,
+ (notifications & softmac->smac_notifications));
+ }
done:
if (err != 0)
@@ -1257,13 +1366,11 @@ softmac_m_open(void *arg)
int err;
ASSERT(MAC_PERIM_HELD(softmac->smac_mh));
- ASSERT(softmac->smac_lower_state == SOFTMAC_INITIALIZED);
- if ((err = softmac_lower_setup(softmac, &slp)) != 0)
+ if ((err = softmac_lower_setup(softmac, NULL, &slp)) != 0)
return (err);
softmac->smac_lower = slp;
- softmac->smac_lower_state = SOFTMAC_READY;
return (0);
}
@@ -1274,7 +1381,6 @@ softmac_m_close(void *arg)
softmac_lower_t *slp;
ASSERT(MAC_PERIM_HELD(softmac->smac_mh));
- ASSERT(softmac->smac_lower_state == SOFTMAC_READY);
slp = softmac->smac_lower;
ASSERT(slp != NULL);
@@ -1282,10 +1388,74 @@ softmac_m_close(void *arg)
* Note that slp is destroyed when lh is closed.
*/
(void) ldi_close(slp->sl_lh, FREAD|FWRITE, kcred);
- softmac->smac_lower_state = SOFTMAC_INITIALIZED;
softmac->smac_lower = NULL;
}
+/*
+ * Softmac supports two priviate link properteis:
+ *
+ * - "_fastpath"
+ *
+ * This is a read-only link property which points out the current data-path
+ * model of the given legacy link. The possible values are "disabled" and
+ * "enabled".
+ *
+ * - "_disable_fastpath"
+ *
+ * This is a read-write link property which can be used to disable or enable
+ * the fast-path of the given legacy link. The possible values are "true"
+ * and "false". Note that even when "_disable_fastpath" is set to be
+ * "false", the fast-path may still not be enabled since there may be
+ * other mac cleints that request the fast-path to be disabled.
+ */
+/* ARGSUSED */
+static int
+softmac_m_setprop(void *arg, const char *name, mac_prop_id_t id,
+ uint_t valsize, const void *val)
+{
+ softmac_t *softmac = arg;
+
+ if (id != MAC_PROP_PRIVATE || strcmp(name, "_disable_fastpath") != 0)
+ return (ENOTSUP);
+
+ if (strcmp(val, "true") == 0)
+ return (softmac_datapath_switch(softmac, B_TRUE, B_TRUE));
+ else if (strcmp(val, "false") == 0)
+ return (softmac_datapath_switch(softmac, B_FALSE, B_TRUE));
+ else
+ return (EINVAL);
+}
+
+static int
+softmac_m_getprop(void *arg, const char *name, mac_prop_id_t id, uint_t flags,
+ uint_t valsize, void *val, uint_t *perm)
+{
+ softmac_t *softmac = arg;
+ char *fpstr;
+
+ if (id != MAC_PROP_PRIVATE)
+ return (ENOTSUP);
+
+ if (strcmp(name, "_fastpath") == 0) {
+ if ((flags & MAC_PROP_DEFAULT) != 0)
+ return (ENOTSUP);
+
+ *perm = MAC_PROP_PERM_READ;
+ mutex_enter(&softmac->smac_fp_mutex);
+ fpstr = (DATAPATH_MODE(softmac) == SOFTMAC_SLOWPATH) ?
+ "disabled" : "enabled";
+ mutex_exit(&softmac->smac_fp_mutex);
+ } else if (strcmp(name, "_disable_fastpath") == 0) {
+ *perm = MAC_PROP_PERM_RW;
+ fpstr = ((flags & MAC_PROP_DEFAULT) != 0) ? "false" :
+ (softmac->smac_fastpath_admin_disabled ? "true" : "false");
+ } else {
+ return (ENOTSUP);
+ }
+
+ return (strlcpy(val, fpstr, valsize) >= valsize ? EINVAL : 0);
+}
+
int
softmac_hold_device(dev_t dev, dls_dev_handle_t *ddhp)
{
@@ -1367,12 +1537,39 @@ again:
void
softmac_rele_device(dls_dev_handle_t ddh)
{
+ if (ddh != NULL)
+ softmac_rele((softmac_t *)ddh);
+}
+
+int
+softmac_hold(dev_t dev, softmac_t **softmacp)
+{
softmac_t *softmac;
+ char *drv;
+ mac_handle_t mh;
+ char mac[MAXNAMELEN];
+ int err;
- if (ddh == NULL)
- return;
+ if ((drv = ddi_major_to_name(getmajor(dev))) == NULL)
+ return (EINVAL);
- softmac = (softmac_t *)ddh;
+ (void) snprintf(mac, MAXNAMELEN, "%s%d", drv, getminor(dev) - 1);
+ if ((err = mac_open(mac, &mh)) != 0)
+ return (err);
+
+ softmac = (softmac_t *)mac_driver(mh);
+
+ mutex_enter(&softmac->smac_mutex);
+ softmac->smac_hold_cnt++;
+ mutex_exit(&softmac->smac_mutex);
+ mac_close(mh);
+ *softmacp = softmac;
+ return (0);
+}
+
+void
+softmac_rele(softmac_t *softmac)
+{
mutex_enter(&softmac->smac_mutex);
softmac->smac_hold_cnt--;
mutex_exit(&softmac->smac_mutex);
diff --git a/usr/src/uts/common/io/softmac/softmac_pkt.c b/usr/src/uts/common/io/softmac/softmac_pkt.c
index 4a856f4f58..b0d613b9be 100644
--- a/usr/src/uts/common/io/softmac/softmac_pkt.c
+++ b/usr/src/uts/common/io/softmac/softmac_pkt.c
@@ -27,16 +27,6 @@
#include <inet/led.h>
#include <sys/softmac_impl.h>
-/*
- * Macro to check whether the write-queue of the lower stream is full.
- *
- * Because softmac is pushed right above the underlying device and
- * _I_INSERT/_I_REMOVE is not processed in the lower stream, it is
- * safe to directly access the q_next pointer.
- */
-#define CANPUTNEXT(q) \
- (!((q)->q_next->q_nfsrv->q_flag & QFULL) || canput((q)->q_next))
-
mblk_t *
softmac_m_tx(void *arg, mblk_t *mp)
{
@@ -46,7 +36,7 @@ softmac_m_tx(void *arg, mblk_t *mp)
* Optimize for the most common case.
*/
if (mp->b_next == NULL) {
- if (!CANPUTNEXT(wq))
+ if (!SOFTMAC_CANPUTNEXT(wq))
return (mp);
mp->b_flag |= MSGNOLOOP;
@@ -57,7 +47,7 @@ softmac_m_tx(void *arg, mblk_t *mp)
while (mp != NULL) {
mblk_t *next = mp->b_next;
- if (!CANPUTNEXT(wq))
+ if (!SOFTMAC_CANPUTNEXT(wq))
break;
mp->b_next = NULL;
mp->b_flag |= MSGNOLOOP;
@@ -67,7 +57,6 @@ softmac_m_tx(void *arg, mblk_t *mp)
return (mp);
}
-
void
softmac_rput_process_data(softmac_lower_t *slp, mblk_t *mp)
{
@@ -141,7 +130,7 @@ dlpi_get_errno(t_uscalar_t error, t_uscalar_t unix_errno)
return (error == DL_SYSERR ? unix_errno : EINVAL);
}
-static int
+int
softmac_output(softmac_lower_t *slp, mblk_t *mp, t_uscalar_t dl_prim,
t_uscalar_t ack, mblk_t **mpp)
{
@@ -227,7 +216,7 @@ softmac_ioctl_tx(softmac_lower_t *slp, mblk_t *mp, mblk_t **mpp)
softmac_serialize_exit(slp);
}
-static int
+int
softmac_mexchange_error_ack(mblk_t **mpp, t_uscalar_t error_primitive,
t_uscalar_t error, t_uscalar_t unix_errno)
{