#ifndef _NET_CLASSQ_IF_CLASSQ_H_
#define _NET_CLASSQ_IF_CLASSQ_H_
#ifdef PRIVATE
#define IFCQ_SC_MAX 10
#ifdef BSD_KERNEL_PRIVATE
#include <net/classq/classq.h>
#define IFCQ_DEFAULT_PKT_DROP_LIMIT 2048
typedef enum cqrq {
CLASSQRQ_PURGE = 1,
CLASSQRQ_PURGE_SC = 2,
CLASSQRQ_EVENT = 3,
CLASSQRQ_THROTTLE = 4,
CLASSQRQ_STAT_SC = 5,
} cqrq_t;
typedef struct cqrq_purge_sc {
mbuf_svc_class_t sc;
u_int32_t flow;
u_int32_t packets;
u_int32_t bytes;
} cqrq_purge_sc_t;
typedef struct cqrq_throttle {
u_int32_t set;
u_int32_t level;
} cqrq_throttle_t;
typedef struct cqrq_stat_sc {
mbuf_svc_class_t sc;
u_int32_t packets;
u_int32_t bytes;
} cqrq_stat_sc_t;
struct tb_regulator {
u_int64_t tbr_rate_raw;
u_int32_t tbr_percent;
int64_t tbr_rate;
int64_t tbr_depth;
int64_t tbr_token;
int64_t tbr_filluptime;
u_int64_t tbr_last;
};
struct tb_profile {
u_int64_t rate;
u_int32_t percent;
u_int32_t depth;
};
struct ifclassq;
enum cqdq_op;
enum cqrq;
typedef int (*ifclassq_enq_func)(struct ifclassq *, classq_pkt_t *,
boolean_t *);
typedef void (*ifclassq_deq_func)(struct ifclassq *, classq_pkt_t *);
typedef void (*ifclassq_deq_sc_func)(struct ifclassq *, mbuf_svc_class_t,
classq_pkt_t *);
typedef int (*ifclassq_deq_multi_func)(struct ifclassq *, u_int32_t,
u_int32_t, classq_pkt_t *, classq_pkt_t *, u_int32_t *, u_int32_t *);
typedef int (*ifclassq_deq_sc_multi_func)(struct ifclassq *,
mbuf_svc_class_t, u_int32_t, u_int32_t, classq_pkt_t *, classq_pkt_t *,
u_int32_t *, u_int32_t *);
typedef int (*ifclassq_req_func)(struct ifclassq *, enum cqrq, void *);
struct ifclassq {
decl_lck_mtx_data(, ifcq_lock);
struct ifnet *ifcq_ifp;
u_int32_t ifcq_len;
u_int32_t ifcq_maxlen;
struct pktcntr ifcq_xmitcnt;
struct pktcntr ifcq_dropcnt;
u_int32_t ifcq_type;
u_int32_t ifcq_flags;
u_int32_t ifcq_sflags;
u_int32_t ifcq_target_qdelay;
u_int32_t ifcq_bytes;
u_int32_t ifcq_pkt_drop_limit;
void *ifcq_disc;
struct ifclassq_disc_slot {
u_int32_t qid;
void *cl;
} ifcq_disc_slots[IFCQ_SC_MAX];
struct tb_regulator ifcq_tbr;
};
#define IFCQF_READY 0x01
#define IFCQF_ENABLED 0x02
#define IFCQF_TBR 0x04
#define IFCQ_IS_READY(_ifcq) ((_ifcq)->ifcq_flags & IFCQF_READY)
#define IFCQ_IS_ENABLED(_ifcq) ((_ifcq)->ifcq_flags & IFCQF_ENABLED)
#define IFCQ_TBR_IS_ENABLED(_ifcq) ((_ifcq)->ifcq_flags & IFCQF_TBR)
#define CLASSQEQ_DROP (-1)
#define CLASSQEQ_SUCCESS 0
#define CLASSQEQ_SUCCESS_FC 1
#define CLASSQEQ_DROP_FC 2
#define CLASSQEQ_DROP_SP 3
#define CLASSQEQ_COMPRESSED 4
typedef enum cqev {
CLASSQ_EV_INIT = 0,
CLASSQ_EV_LINK_BANDWIDTH = 1,
CLASSQ_EV_LINK_LATENCY = 2,
CLASSQ_EV_LINK_MTU = 3,
CLASSQ_EV_LINK_UP = 4,
CLASSQ_EV_LINK_DOWN = 5,
} cqev_t;
#endif
#include <net/classq/classq.h>
#include <net/pktsched/pktsched_fq_codel.h>
#ifdef __cplusplus
extern "C" {
#endif
struct if_ifclassq_stats {
u_int32_t ifqs_len;
u_int32_t ifqs_maxlen;
struct pktcntr ifqs_xmitcnt;
struct pktcntr ifqs_dropcnt;
u_int32_t ifqs_scheduler;
struct fq_codel_classstats ifqs_fq_codel_stats;
} __attribute__((aligned(8)));
#ifdef __cplusplus
}
#endif
#ifdef BSD_KERNEL_PRIVATE
#define IFCQ_LOCK_ASSERT_HELD(_ifcq) \
LCK_MTX_ASSERT(&(_ifcq)->ifcq_lock, LCK_MTX_ASSERT_OWNED)
#define IFCQ_LOCK_ASSERT_NOTHELD(_ifcq) \
LCK_MTX_ASSERT(&(_ifcq)->ifcq_lock, LCK_MTX_ASSERT_NOTOWNED)
#define IFCQ_LOCK(_ifcq) \
lck_mtx_lock(&(_ifcq)->ifcq_lock)
#define IFCQ_LOCK_SPIN(_ifcq) \
lck_mtx_lock_spin(&(_ifcq)->ifcq_lock)
#define IFCQ_CONVERT_LOCK(_ifcq) do { \
IFCQ_LOCK_ASSERT_HELD(_ifcq); \
lck_mtx_convert_spin(&(_ifcq)->ifcq_lock); \
} while (0)
#define IFCQ_UNLOCK(_ifcq) \
lck_mtx_unlock(&(_ifcq)->ifcq_lock)
#define IFCQ_TBR_DEQUEUE(_ifcq, _p) do { \
ifclassq_tbr_dequeue(_ifcq, _p); \
} while (0)
#define IFCQ_TBR_DEQUEUE_SC(_ifcq, _sc, _p) do { \
ifclassq_tbr_dequeue_sc(_ifcq, _sc, _p); \
} while (0)
#define IFCQ_LEN(_ifcq) ((_ifcq)->ifcq_len)
#define IFCQ_QFULL(_ifcq) (IFCQ_LEN(_ifcq) >= (_ifcq)->ifcq_maxlen)
#define IFCQ_IS_EMPTY(_ifcq) (IFCQ_LEN(_ifcq) == 0)
#define IFCQ_INC_LEN(_ifcq) (IFCQ_LEN(_ifcq)++)
#define IFCQ_DEC_LEN(_ifcq) (IFCQ_LEN(_ifcq)--)
#define IFCQ_ADD_LEN(_ifcq, _len) (IFCQ_LEN(_ifcq) += (_len))
#define IFCQ_SUB_LEN(_ifcq, _len) (IFCQ_LEN(_ifcq) -= (_len))
#define IFCQ_MAXLEN(_ifcq) ((_ifcq)->ifcq_maxlen)
#define IFCQ_SET_MAXLEN(_ifcq, _len) ((_ifcq)->ifcq_maxlen = (_len))
#define IFCQ_TARGET_QDELAY(_ifcq) ((_ifcq)->ifcq_target_qdelay)
#define IFCQ_BYTES(_ifcq) ((_ifcq)->ifcq_bytes)
#define IFCQ_INC_BYTES(_ifcq, _len) \
((_ifcq)->ifcq_bytes = (_ifcq)->ifcq_bytes + (_len))
#define IFCQ_DEC_BYTES(_ifcq, _len) \
((_ifcq)->ifcq_bytes = (_ifcq)->ifcq_bytes - (_len))
#define IFCQ_XMIT_ADD(_ifcq, _pkt, _len) do { \
PKTCNTR_ADD(&(_ifcq)->ifcq_xmitcnt, _pkt, _len); \
} while (0)
#define IFCQ_DROP_ADD(_ifcq, _pkt, _len) do { \
PKTCNTR_ADD(&(_ifcq)->ifcq_dropcnt, _pkt, _len); \
} while (0)
#define IFCQ_PKT_DROP_LIMIT(_ifcq) ((_ifcq)->ifcq_pkt_drop_limit)
extern int ifclassq_setup(struct ifnet *, u_int32_t, boolean_t);
extern void ifclassq_teardown(struct ifnet *);
extern int ifclassq_pktsched_setup(struct ifclassq *);
extern void ifclassq_set_maxlen(struct ifclassq *, u_int32_t);
extern u_int32_t ifclassq_get_maxlen(struct ifclassq *);
extern int ifclassq_get_len(struct ifclassq *, mbuf_svc_class_t,
u_int32_t *, u_int32_t *);
extern errno_t ifclassq_enqueue(struct ifclassq *, classq_pkt_t *,
classq_pkt_t *, u_int32_t, u_int32_t, boolean_t *);
extern errno_t ifclassq_dequeue(struct ifclassq *, u_int32_t, u_int32_t,
classq_pkt_t *, classq_pkt_t *, u_int32_t *, u_int32_t *);
extern errno_t ifclassq_dequeue_sc(struct ifclassq *, mbuf_svc_class_t,
u_int32_t, u_int32_t, classq_pkt_t *, classq_pkt_t *, u_int32_t *,
u_int32_t *);
extern void *ifclassq_poll(struct ifclassq *, classq_pkt_type_t *);
extern void *ifclassq_poll_sc(struct ifclassq *, mbuf_svc_class_t,
classq_pkt_type_t *);
extern void ifclassq_update(struct ifclassq *, cqev_t);
extern int ifclassq_attach(struct ifclassq *, u_int32_t, void *);
extern void ifclassq_detach(struct ifclassq *);
extern int ifclassq_getqstats(struct ifclassq *, u_int32_t,
void *, u_int32_t *);
extern const char *ifclassq_ev2str(cqev_t);
extern int ifclassq_tbr_set(struct ifclassq *, struct tb_profile *, boolean_t);
extern void ifclassq_tbr_dequeue(struct ifclassq *, classq_pkt_t *);
extern void ifclassq_tbr_dequeue_sc(struct ifclassq *, mbuf_svc_class_t,
classq_pkt_t *);
extern void ifclassq_calc_target_qdelay(struct ifnet *ifp,
u_int64_t *if_target_qdelay);
extern void ifclassq_calc_update_interval(u_int64_t *update_interval);
extern void ifclassq_set_packet_metadata(struct ifclassq *ifq,
struct ifnet *ifp, classq_pkt_t *p);
extern void ifclassq_reap_caches(boolean_t);
#endif
#endif
#endif