static inline struct tcq_class *tcq_clh_to_clp(struct tcq_if *, u_int32_t);
static const char *tcq_style(struct tcq_if *);
-#define TCQ_ZONE_MAX 32 /* maximum elements in zone */
-#define TCQ_ZONE_NAME "pktsched_tcq" /* zone name */
+#define TCQ_ZONE_MAX 32 /* maximum elements in zone */
+#define TCQ_ZONE_NAME "pktsched_tcq" /* zone name */
-static unsigned int tcq_size; /* size of zone element */
-static struct zone *tcq_zone; /* zone for tcq */
+static unsigned int tcq_size; /* size of zone element */
+static struct zone *tcq_zone; /* zone for tcq */
-#define TCQ_CL_ZONE_MAX 32 /* maximum elements in zone */
-#define TCQ_CL_ZONE_NAME "pktsched_tcq_cl" /* zone name */
+#define TCQ_CL_ZONE_MAX 32 /* maximum elements in zone */
+#define TCQ_CL_ZONE_NAME "pktsched_tcq_cl" /* zone name */
-static unsigned int tcq_cl_size; /* size of zone element */
-static struct zone *tcq_cl_zone; /* zone for tcq_class */
+static unsigned int tcq_cl_size; /* size of zone element */
+static struct zone *tcq_cl_zone; /* zone for tcq_class */
void
tcq_init(void)
{
- tcq_size = sizeof (struct tcq_if);
+ tcq_size = sizeof(struct tcq_if);
tcq_zone = zinit(tcq_size, TCQ_ZONE_MAX * tcq_size,
0, TCQ_ZONE_NAME);
if (tcq_zone == NULL) {
zone_change(tcq_zone, Z_EXPAND, TRUE);
zone_change(tcq_zone, Z_CALLERACCT, TRUE);
- tcq_cl_size = sizeof (struct tcq_class);
+ tcq_cl_size = sizeof(struct tcq_class);
tcq_cl_zone = zinit(tcq_cl_size, TCQ_CL_ZONE_MAX * tcq_cl_size,
0, TCQ_CL_ZONE_NAME);
if (tcq_cl_zone == NULL) {
struct tcq_if *
tcq_alloc(struct ifnet *ifp, int how)
{
- struct tcq_if *tif;
+ struct tcq_if *tif;
tif = (how == M_WAITOK) ? zalloc(tcq_zone) : zalloc_noblock(tcq_zone);
- if (tif == NULL)
- return (NULL);
+ if (tif == NULL) {
+ return NULL;
+ }
bzero(tif, tcq_size);
tif->tif_maxpri = -1;
if_name(ifp), tcq_style(tif));
}
- return (tif);
+ return tif;
}
int
err = tcq_destroy_locked(tif);
IFCQ_UNLOCK(ifq);
- return (err);
+ return err;
}
static int
zfree(tcq_zone, tif);
- return (0);
+ return 0;
}
/*
static int
tcq_clear_interface(struct tcq_if *tif)
{
- struct tcq_class *cl;
+ struct tcq_class *cl;
int pri;
IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
/* clear out the classes */
- for (pri = 0; pri <= tif->tif_maxpri; pri++)
- if ((cl = tif->tif_classes[pri]) != NULL)
+ for (pri = 0; pri <= tif->tif_maxpri; pri++) {
+ if ((cl = tif->tif_classes[pri]) != NULL) {
tcq_class_destroy(tif, cl);
+ }
+ }
- return (0);
+ return 0;
}
/* discard all the queued packets on the interface */
IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
for (pri = 0; pri <= tif->tif_maxpri; pri++) {
- if ((cl = tif->tif_classes[pri]) != NULL && !qempty(&cl->cl_q))
+ if ((cl = tif->tif_classes[pri]) != NULL && !qempty(&cl->cl_q)) {
tcq_purgeq(tif, cl, 0, NULL, NULL);
+ }
}
VERIFY(IFCQ_LEN(tif->tif_ifq) == 0);
}
IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
- for (pri = 0; pri <= tif->tif_maxpri; pri++)
- if ((cl = tif->tif_classes[pri]) != NULL)
+ for (pri = 0; pri <= tif->tif_maxpri; pri++) {
+ if ((cl = tif->tif_classes[pri]) != NULL) {
tcq_updateq(tif, cl, ev);
+ }
+ }
}
int
IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
/* check parameters */
- if (priority >= TCQ_MAXPRI)
- return (EINVAL);
- if (tif->tif_classes[priority] != NULL)
- return (EBUSY);
- if (tcq_clh_to_clp(tif, qid) != NULL)
- return (EBUSY);
+ if (priority >= TCQ_MAXPRI) {
+ return EINVAL;
+ }
+ if (tif->tif_classes[priority] != NULL) {
+ return EBUSY;
+ }
+ if (tcq_clh_to_clp(tif, qid) != NULL) {
+ return EBUSY;
+ }
cl = tcq_class_create(tif, priority, qlimit, flags, qid, ptype);
- if (cl == NULL)
- return (ENOMEM);
+ if (cl == NULL) {
+ return ENOMEM;
+ }
- if (clp != NULL)
+ if (clp != NULL) {
*clp = cl;
+ }
- return (0);
+ return 0;
}
static struct tcq_class *
if ((cl = tif->tif_classes[pri]) != NULL) {
/* modify the class instead of creating a new one */
- if (!qempty(&cl->cl_q))
+ if (!qempty(&cl->cl_q)) {
tcq_purgeq(tif, cl, 0, NULL, NULL);
+ }
- if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
+ if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
sfb_destroy(cl->cl_sfb);
+ }
cl->cl_qalg.ptr = NULL;
qtype(&cl->cl_q) = Q_DROPTAIL;
qstate(&cl->cl_q) = QS_RUNNING;
VERIFY(qptype(&cl->cl_q) == ptype);
} else {
cl = zalloc(tcq_cl_zone);
- if (cl == NULL)
- return (NULL);
+ if (cl == NULL) {
+ return NULL;
+ }
bzero(cl, tcq_cl_size);
}
tif->tif_classes[pri] = cl;
- if (flags & TQCF_DEFAULTCLASS)
+ if (flags & TQCF_DEFAULTCLASS) {
tif->tif_default = cl;
+ }
if (qlimit == 0 || qlimit > IFCQ_MAXLEN(ifq)) {
qlimit = IFCQ_MAXLEN(ifq);
- if (qlimit == 0)
+ if (qlimit == 0) {
qlimit = DEFAULT_QLIMIT; /* use default */
+ }
}
_qinit(&cl->cl_q, Q_DROPTAIL, qlimit, ptype);
cl->cl_flags = flags;
cl->cl_pri = pri;
- if (pri > tif->tif_maxpri)
+ if (pri > tif->tif_maxpri) {
tif->tif_maxpri = pri;
+ }
cl->cl_tif = tif;
cl->cl_handle = qid;
if (flags & TQCF_DELAYBASED) {
cl->cl_qflags |= SFBF_DELAYBASED;
}
- if (!(cl->cl_flags & TQCF_LAZY))
+ if (!(cl->cl_flags & TQCF_LAZY)) {
cl->cl_sfb = sfb_alloc(ifp, cl->cl_handle,
qlimit(&cl->cl_q), cl->cl_qflags);
- if (cl->cl_sfb != NULL || (cl->cl_flags & TQCF_LAZY))
+ }
+ if (cl->cl_sfb != NULL || (cl->cl_flags & TQCF_LAZY)) {
qtype(&cl->cl_q) = Q_SFB;
+ }
}
if (pktsched_verbose) {
cl->cl_handle, cl->cl_pri, qlimit, flags, TQCF_BITS);
}
- return (cl);
+ return cl;
}
int
IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
- if ((cl = tcq_clh_to_clp(tif, qid)) == NULL)
- return (EINVAL);
+ if ((cl = tcq_clh_to_clp(tif, qid)) == NULL) {
+ return EINVAL;
+ }
- return (tcq_class_destroy(tif, cl));
+ return tcq_class_destroy(tif, cl);
}
static int
#endif
IFCQ_LOCK_ASSERT_HELD(ifq);
- if (!qempty(&cl->cl_q))
+ if (!qempty(&cl->cl_q)) {
tcq_purgeq(tif, cl, 0, NULL, NULL);
+ }
tif->tif_classes[cl->cl_pri] = NULL;
if (tif->tif_maxpri == cl->cl_pri) {
- for (pri = cl->cl_pri; pri >= 0; pri--)
+ for (pri = cl->cl_pri; pri >= 0; pri--) {
if (tif->tif_classes[pri] != NULL) {
tif->tif_maxpri = pri;
break;
}
- if (pri < 0)
+ }
+ if (pri < 0) {
tif->tif_maxpri = -1;
+ }
}
- if (tif->tif_default == cl)
+ if (tif->tif_default == cl) {
tif->tif_default = NULL;
+ }
if (cl->cl_qalg.ptr != NULL) {
- if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
+ if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
sfb_destroy(cl->cl_sfb);
+ }
cl->cl_qalg.ptr = NULL;
qtype(&cl->cl_q) = Q_DROPTAIL;
qstate(&cl->cl_q) = QS_RUNNING;
}
zfree(tcq_cl_zone, cl);
- return (0);
+ return 0;
}
int
cl = tif->tif_default;
if (cl == NULL) {
IFCQ_CONVERT_LOCK(ifq);
- return (CLASSQEQ_DROP);
+ return CLASSQEQ_DROP;
}
}
}
ret == CLASSQEQ_DROP_SP);
PKTCNTR_ADD(&cl->cl_dropcnt, 1, len);
IFCQ_DROP_ADD(ifq, 1, len);
- return (ret);
+ return ret;
}
IFCQ_INC_LEN(ifq);
IFCQ_INC_BYTES(ifq, len);
/* successfully queued. */
- return (ret);
+ return ret;
}
/*
len = pktsched_get_pkt_len(pkt);
IFCQ_DEC_LEN(ifq);
IFCQ_DEC_BYTES(ifq, len);
- if (qempty(&cl->cl_q))
+ if (qempty(&cl->cl_q)) {
cl->cl_period++;
+ }
PKTCNTR_ADD(&cl->cl_xmitcnt, 1, len);
IFCQ_XMIT_ADD(ifq, 1, len);
}
cqrq_throttle_t tr = { 1, tif->tif_throttle };
int err = tcq_throttle(tif, &tr);
- if (err == EALREADY)
+ if (err == EALREADY) {
err = 0;
+ }
if (err != 0) {
tr.level = IFNET_THROTTLE_OFF;
(void) tcq_throttle(tif, &tr);
}
}
}
- if (cl->cl_sfb != NULL)
- return (sfb_addq(cl->cl_sfb, &cl->cl_q, pkt, t));
+ if (cl->cl_sfb != NULL) {
+ return sfb_addq(cl->cl_sfb, &cl->cl_q, pkt, t);
+ }
} else if (qlen(&cl->cl_q) >= qlimit(&cl->cl_q)) {
IFCQ_CONVERT_LOCK(ifq);
- return (CLASSQEQ_DROP);
+ return CLASSQEQ_DROP;
}
#if PF_ECN
- if (cl->cl_flags & TQCF_CLEARDSCP)
+ if (cl->cl_flags & TQCF_CLEARDSCP) {
/* not supported for non-BSD stack packets */
VERIFY(pkt->pktsched_ptype == QP_MBUF);
- write_dsfield(m, t, 0);
+ }
+ write_dsfield(m, t, 0);
#endif /* PF_ECN */
VERIFY(pkt->pktsched_ptype == qptype(&cl->cl_q));
_addq(&cl->cl_q, pkt->pktsched_pkt);
- return (0);
+ return 0;
}
static inline void
IFCQ_LOCK_ASSERT_HELD(cl->cl_tif->tif_ifq);
if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
- return (sfb_getq(cl->cl_sfb, &cl->cl_q, pkt));
+ return sfb_getq(cl->cl_sfb, &cl->cl_q, pkt);
}
- return (pktsched_pkt_encap(pkt, qptype(&cl->cl_q), _getq(&cl->cl_q)));
+ return pktsched_pkt_encap(pkt, qptype(&cl->cl_q), _getq(&cl->cl_q));
}
static void
IFCQ_LOCK_ASSERT_HELD(ifq);
- if ((qlen = qlen(&cl->cl_q)) == 0)
+ if ((qlen = qlen(&cl->cl_q)) == 0) {
goto done;
+ }
IFCQ_CONVERT_LOCK(ifq);
- if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
+ if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
sfb_purgeq(cl->cl_sfb, &cl->cl_q, flow, &cnt, &len);
- else
+ } else {
_flushq_flow(&cl->cl_q, flow, &cnt, &len);
+ }
if (cnt > 0) {
VERIFY(qlen(&cl->cl_q) == (qlen - cnt));
}
}
done:
- if (packets != NULL)
+ if (packets != NULL) {
*packets = cnt;
- if (bytes != NULL)
+ }
+ if (bytes != NULL) {
*bytes = len;
+ }
}
static void
cl->cl_handle, cl->cl_pri, ifclassq_ev2str(ev));
}
- if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
- return (sfb_updateq(cl->cl_sfb, ev));
+ if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
+ return sfb_updateq(cl->cl_sfb, ev);
+ }
}
int
IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
- if ((cl = tcq_clh_to_clp(tif, qid)) == NULL)
- return (EINVAL);
+ if ((cl = tcq_clh_to_clp(tif, qid)) == NULL) {
+ return EINVAL;
+ }
sp->class_handle = cl->cl_handle;
sp->priority = cl->cl_pri;
sp->qtype = qtype(&cl->cl_q);
sp->qstate = qstate(&cl->cl_q);
- if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
+ if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
sfb_getstats(cl->cl_sfb, &sp->sfb);
+ }
- return (0);
+ return 0;
}
static int
sr->packets = qlen(&cl->cl_q);
sr->bytes = qsize(&cl->cl_q);
- return (0);
+ return 0;
}
/* convert a class handle to the corresponding class pointer */
IFCQ_LOCK_ASSERT_HELD(tif->tif_ifq);
- for (idx = tif->tif_maxpri; idx >= 0; idx--)
+ for (idx = tif->tif_maxpri; idx >= 0; idx--) {
if ((cl = tif->tif_classes[idx]) != NULL &&
- cl->cl_handle == chandle)
- return (cl);
+ cl->cl_handle == chandle) {
+ return cl;
+ }
+ }
- return (NULL);
+ return NULL;
}
static const char *
tcq_style(struct tcq_if *tif)
{
#pragma unused(tif)
- return ("TCQ");
+ return "TCQ";
}
/*
IFCQ_CONVERT_LOCK(ifq);
m_freem(m);
*pdrop = TRUE;
- return (ENOBUFS);
+ return ENOBUFS;
}
t = m_pftag(m);
i = MBUF_SCIDX(mbuf_get_service_class(m));
default:
VERIFY(0);
}
- return (ret);
+ return ret;
}
/*
VERIFY((u_int32_t)i < IFCQ_SC_MAX);
- bzero(&pkt, sizeof (pkt));
+ bzero(&pkt, sizeof(pkt));
(tcq_dequeue_cl(ifq->ifcq_disc, ifq->ifcq_disc_slots[i].cl, sc, &pkt));
*ptype = pkt.pktsched_ptype;
- return (pkt.pktsched_pkt);
+ return pkt.pktsched_pkt;
}
static int
tcq_request_ifclassq(struct ifclassq *ifq, cqrq_t req, void *arg)
{
- struct tcq_if *tif = (struct tcq_if *)ifq->ifcq_disc;
+ struct tcq_if *tif = (struct tcq_if *)ifq->ifcq_disc;
int err = 0;
IFCQ_LOCK_ASSERT_HELD(ifq);
err = tcq_stat_sc(tif, (cqrq_stat_sc_t *)arg);
break;
}
- return (err);
+ return err;
}
int
VERIFY(ifq->ifcq_disc == NULL);
VERIFY(ifq->ifcq_type == PKTSCHEDT_NONE);
- if (flags & PKTSCHEDF_QALG_SFB)
+ if (flags & PKTSCHEDF_QALG_SFB) {
qflags |= TQCF_SFB;
- if (flags & PKTSCHEDF_QALG_ECN)
+ }
+ if (flags & PKTSCHEDF_QALG_ECN) {
qflags |= TQCF_ECN;
- if (flags & PKTSCHEDF_QALG_FLOWCTL)
+ }
+ if (flags & PKTSCHEDF_QALG_FLOWCTL) {
qflags |= TQCF_FLOWCTL;
- if (flags & PKTSCHEDF_QALG_DELAYBASED)
+ }
+ if (flags & PKTSCHEDF_QALG_DELAYBASED) {
qflags |= TQCF_DELAYBASED;
+ }
tif = tcq_alloc(ifp, M_WAITOK);
- if (tif == NULL)
- return (ENOMEM);
+ if (tif == NULL) {
+ return ENOMEM;
+ }
- if ((maxlen = IFCQ_MAXLEN(ifq)) == 0)
+ if ((maxlen = IFCQ_MAXLEN(ifq)) == 0) {
maxlen = if_sndq_maxlen;
+ }
if ((err = tcq_add_queue(tif, 0, maxlen,
- qflags | TQCF_LAZY, SCIDX_BK, &cl0, ptype)) != 0)
+ qflags | TQCF_LAZY, SCIDX_BK, &cl0, ptype)) != 0) {
goto cleanup;
+ }
if ((err = tcq_add_queue(tif, 1, maxlen,
- qflags | TQCF_DEFAULTCLASS, SCIDX_BE, &cl1, ptype)) != 0)
+ qflags | TQCF_DEFAULTCLASS, SCIDX_BE, &cl1, ptype)) != 0) {
goto cleanup;
+ }
if ((err = tcq_add_queue(tif, 2, maxlen,
- qflags | TQCF_LAZY, SCIDX_VI, &cl2, ptype)) != 0)
+ qflags | TQCF_LAZY, SCIDX_VI, &cl2, ptype)) != 0) {
goto cleanup;
+ }
if ((err = tcq_add_queue(tif, 3, maxlen,
- qflags, SCIDX_VO, &cl3, ptype)) != 0)
+ qflags, SCIDX_VO, &cl3, ptype)) != 0) {
goto cleanup;
+ }
err = ifclassq_attach(ifq, PKTSCHEDT_TCQ, tif,
tcq_enqueue_ifclassq, NULL, tcq_dequeue_tc_ifclassq,
}
cleanup:
- if (err != 0)
+ if (err != 0) {
(void) tcq_destroy_locked(tif);
+ }
- return (err);
+ return err;
}
int
ifq->ifcq_disc_slots[i].cl = NULL;
}
- return (ifclassq_detach(ifq));
+ return ifclassq_detach(ifq);
}
int
IFCQ_LOCK_ASSERT_HELD(ifq);
VERIFY(ifq->ifcq_type == PKTSCHEDT_TCQ);
- if (slot >= IFCQ_SC_MAX)
- return (EINVAL);
+ if (slot >= IFCQ_SC_MAX) {
+ return EINVAL;
+ }
- return (tcq_get_class_stats(tif, ifq->ifcq_disc_slots[slot].qid,
- &ifqs->ifqs_tcq_stats));
+ return tcq_get_class_stats(tif, ifq->ifcq_disc_slots[slot].qid,
+ &ifqs->ifqs_tcq_stats);
}
static int
if (!tr->set) {
tr->level = tif->tif_throttle;
- return (0);
+ return 0;
}
- if (tr->level == tif->tif_throttle)
- return (EALREADY);
+ if (tr->level == tif->tif_throttle) {
+ return EALREADY;
+ }
/* Current throttling levels only involve BK_SYS class */
cl = ifq->ifcq_disc_slots[SCIDX_BK_SYS].cl;
tr->level);
}
tif->tif_throttle = tr->level;
- if (err != 0)
+ if (err != 0) {
err = 0;
- else
+ } else {
tcq_purgeq(tif, cl, 0, NULL, NULL);
+ }
} else {
log(LOG_ERR, "%s: %s unable to set throttling level "
"%d->%d [error=%d]\n", if_name(TCQIF_IFP(tif)),
tcq_style(tif), tif->tif_throttle, tr->level, err);
}
- return (err);
+ return err;
}
static int
#endif
IFCQ_LOCK_ASSERT_HELD(ifq);
- if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
+ if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL) {
err = sfb_suspendq(cl->cl_sfb, &cl->cl_q, FALSE);
+ }
- if (err == 0)
+ if (err == 0) {
qstate(&cl->cl_q) = QS_RUNNING;
+ }
- return (err);
+ return err;
}
static int
err = sfb_suspendq(cl->cl_sfb, &cl->cl_q, TRUE);
} else {
VERIFY(cl->cl_flags & TQCF_LAZY);
- err = ENXIO; /* delayed throttling */
+ err = ENXIO; /* delayed throttling */
}
}
- if (err == 0 || err == ENXIO)
+ if (err == 0 || err == ENXIO) {
qstate(&cl->cl_q) = QS_SUSPENDED;
+ }
- return (err);
+ return err;
}