xref: /linux/net/sched/sch_prio.c (revision 3ff50b7997fe06cd5d276b229967bb52d6b3b6c1)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * net/sched/sch_prio.c	Simple 3-band priority "scheduler".
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *		This program is free software; you can redistribute it and/or
51da177e4SLinus Torvalds  *		modify it under the terms of the GNU General Public License
61da177e4SLinus Torvalds  *		as published by the Free Software Foundation; either version
71da177e4SLinus Torvalds  *		2 of the License, or (at your option) any later version.
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  * Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
101da177e4SLinus Torvalds  * Fixes:       19990609: J Hadi Salim <hadi@nortelnetworks.com>:
111da177e4SLinus Torvalds  *              Init --  EINVAL when opt undefined
121da177e4SLinus Torvalds  */
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds #include <linux/module.h>
151da177e4SLinus Torvalds #include <asm/uaccess.h>
161da177e4SLinus Torvalds #include <asm/system.h>
171da177e4SLinus Torvalds #include <linux/bitops.h>
181da177e4SLinus Torvalds #include <linux/types.h>
191da177e4SLinus Torvalds #include <linux/kernel.h>
201da177e4SLinus Torvalds #include <linux/string.h>
211da177e4SLinus Torvalds #include <linux/mm.h>
221da177e4SLinus Torvalds #include <linux/socket.h>
231da177e4SLinus Torvalds #include <linux/sockios.h>
241da177e4SLinus Torvalds #include <linux/in.h>
251da177e4SLinus Torvalds #include <linux/errno.h>
261da177e4SLinus Torvalds #include <linux/interrupt.h>
271da177e4SLinus Torvalds #include <linux/if_ether.h>
281da177e4SLinus Torvalds #include <linux/inet.h>
291da177e4SLinus Torvalds #include <linux/netdevice.h>
301da177e4SLinus Torvalds #include <linux/etherdevice.h>
311da177e4SLinus Torvalds #include <linux/notifier.h>
321da177e4SLinus Torvalds #include <net/ip.h>
331da177e4SLinus Torvalds #include <net/route.h>
341da177e4SLinus Torvalds #include <linux/skbuff.h>
35dc5fc579SArnaldo Carvalho de Melo #include <net/netlink.h>
361da177e4SLinus Torvalds #include <net/sock.h>
371da177e4SLinus Torvalds #include <net/pkt_sched.h>
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds 
401da177e4SLinus Torvalds struct prio_sched_data
411da177e4SLinus Torvalds {
421da177e4SLinus Torvalds 	int bands;
431da177e4SLinus Torvalds 	struct tcf_proto *filter_list;
441da177e4SLinus Torvalds 	u8  prio2band[TC_PRIO_MAX+1];
451da177e4SLinus Torvalds 	struct Qdisc *queues[TCQ_PRIO_BANDS];
461da177e4SLinus Torvalds };
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds static struct Qdisc *
501da177e4SLinus Torvalds prio_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)
511da177e4SLinus Torvalds {
521da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
531da177e4SLinus Torvalds 	u32 band = skb->priority;
541da177e4SLinus Torvalds 	struct tcf_result res;
551da177e4SLinus Torvalds 
5629f1df6cSJamal Hadi Salim 	*qerr = NET_XMIT_BYPASS;
571da177e4SLinus Torvalds 	if (TC_H_MAJ(skb->priority) != sch->handle) {
581da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_ACT
591da177e4SLinus Torvalds 		switch (tc_classify(skb, q->filter_list, &res)) {
601da177e4SLinus Torvalds 		case TC_ACT_STOLEN:
611da177e4SLinus Torvalds 		case TC_ACT_QUEUED:
621da177e4SLinus Torvalds 			*qerr = NET_XMIT_SUCCESS;
631da177e4SLinus Torvalds 		case TC_ACT_SHOT:
641da177e4SLinus Torvalds 			return NULL;
65*3ff50b79SStephen Hemminger 		}
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds 		if (!q->filter_list ) {
681da177e4SLinus Torvalds #else
691da177e4SLinus Torvalds 		if (!q->filter_list || tc_classify(skb, q->filter_list, &res)) {
701da177e4SLinus Torvalds #endif
711da177e4SLinus Torvalds 			if (TC_H_MAJ(band))
721da177e4SLinus Torvalds 				band = 0;
731da177e4SLinus Torvalds 			return q->queues[q->prio2band[band&TC_PRIO_MAX]];
741da177e4SLinus Torvalds 		}
751da177e4SLinus Torvalds 		band = res.classid;
761da177e4SLinus Torvalds 	}
771da177e4SLinus Torvalds 	band = TC_H_MIN(band) - 1;
781da177e4SLinus Torvalds 	if (band > q->bands)
791da177e4SLinus Torvalds 		return q->queues[q->prio2band[0]];
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds 	return q->queues[band];
821da177e4SLinus Torvalds }
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds static int
851da177e4SLinus Torvalds prio_enqueue(struct sk_buff *skb, struct Qdisc *sch)
861da177e4SLinus Torvalds {
871da177e4SLinus Torvalds 	struct Qdisc *qdisc;
881da177e4SLinus Torvalds 	int ret;
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds 	qdisc = prio_classify(skb, sch, &ret);
911da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_ACT
921da177e4SLinus Torvalds 	if (qdisc == NULL) {
9329f1df6cSJamal Hadi Salim 
9429f1df6cSJamal Hadi Salim 		if (ret == NET_XMIT_BYPASS)
951da177e4SLinus Torvalds 			sch->qstats.drops++;
961da177e4SLinus Torvalds 		kfree_skb(skb);
971da177e4SLinus Torvalds 		return ret;
981da177e4SLinus Torvalds 	}
991da177e4SLinus Torvalds #endif
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds 	if ((ret = qdisc->enqueue(skb, qdisc)) == NET_XMIT_SUCCESS) {
1021da177e4SLinus Torvalds 		sch->bstats.bytes += skb->len;
1031da177e4SLinus Torvalds 		sch->bstats.packets++;
1041da177e4SLinus Torvalds 		sch->q.qlen++;
1051da177e4SLinus Torvalds 		return NET_XMIT_SUCCESS;
1061da177e4SLinus Torvalds 	}
1071da177e4SLinus Torvalds 	sch->qstats.drops++;
1081da177e4SLinus Torvalds 	return ret;
1091da177e4SLinus Torvalds }
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds static int
1131da177e4SLinus Torvalds prio_requeue(struct sk_buff *skb, struct Qdisc* sch)
1141da177e4SLinus Torvalds {
1151da177e4SLinus Torvalds 	struct Qdisc *qdisc;
1161da177e4SLinus Torvalds 	int ret;
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds 	qdisc = prio_classify(skb, sch, &ret);
1191da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_ACT
1201da177e4SLinus Torvalds 	if (qdisc == NULL) {
12129f1df6cSJamal Hadi Salim 		if (ret == NET_XMIT_BYPASS)
1221da177e4SLinus Torvalds 			sch->qstats.drops++;
1231da177e4SLinus Torvalds 		kfree_skb(skb);
1241da177e4SLinus Torvalds 		return ret;
1251da177e4SLinus Torvalds 	}
1261da177e4SLinus Torvalds #endif
1271da177e4SLinus Torvalds 
1281da177e4SLinus Torvalds 	if ((ret = qdisc->ops->requeue(skb, qdisc)) == NET_XMIT_SUCCESS) {
1291da177e4SLinus Torvalds 		sch->q.qlen++;
1301da177e4SLinus Torvalds 		sch->qstats.requeues++;
1311da177e4SLinus Torvalds 		return 0;
1321da177e4SLinus Torvalds 	}
1331da177e4SLinus Torvalds 	sch->qstats.drops++;
1341da177e4SLinus Torvalds 	return NET_XMIT_DROP;
1351da177e4SLinus Torvalds }
1361da177e4SLinus Torvalds 
1371da177e4SLinus Torvalds 
1381da177e4SLinus Torvalds static struct sk_buff *
1391da177e4SLinus Torvalds prio_dequeue(struct Qdisc* sch)
1401da177e4SLinus Torvalds {
1411da177e4SLinus Torvalds 	struct sk_buff *skb;
1421da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
1431da177e4SLinus Torvalds 	int prio;
1441da177e4SLinus Torvalds 	struct Qdisc *qdisc;
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds 	for (prio = 0; prio < q->bands; prio++) {
1471da177e4SLinus Torvalds 		qdisc = q->queues[prio];
1481da177e4SLinus Torvalds 		skb = qdisc->dequeue(qdisc);
1491da177e4SLinus Torvalds 		if (skb) {
1501da177e4SLinus Torvalds 			sch->q.qlen--;
1511da177e4SLinus Torvalds 			return skb;
1521da177e4SLinus Torvalds 		}
1531da177e4SLinus Torvalds 	}
1541da177e4SLinus Torvalds 	return NULL;
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds }
1571da177e4SLinus Torvalds 
1581da177e4SLinus Torvalds static unsigned int prio_drop(struct Qdisc* sch)
1591da177e4SLinus Torvalds {
1601da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
1611da177e4SLinus Torvalds 	int prio;
1621da177e4SLinus Torvalds 	unsigned int len;
1631da177e4SLinus Torvalds 	struct Qdisc *qdisc;
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds 	for (prio = q->bands-1; prio >= 0; prio--) {
1661da177e4SLinus Torvalds 		qdisc = q->queues[prio];
1676d037a26SPatrick McHardy 		if (qdisc->ops->drop && (len = qdisc->ops->drop(qdisc)) != 0) {
1681da177e4SLinus Torvalds 			sch->q.qlen--;
1691da177e4SLinus Torvalds 			return len;
1701da177e4SLinus Torvalds 		}
1711da177e4SLinus Torvalds 	}
1721da177e4SLinus Torvalds 	return 0;
1731da177e4SLinus Torvalds }
1741da177e4SLinus Torvalds 
1751da177e4SLinus Torvalds 
1761da177e4SLinus Torvalds static void
1771da177e4SLinus Torvalds prio_reset(struct Qdisc* sch)
1781da177e4SLinus Torvalds {
1791da177e4SLinus Torvalds 	int prio;
1801da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
1811da177e4SLinus Torvalds 
1821da177e4SLinus Torvalds 	for (prio=0; prio<q->bands; prio++)
1831da177e4SLinus Torvalds 		qdisc_reset(q->queues[prio]);
1841da177e4SLinus Torvalds 	sch->q.qlen = 0;
1851da177e4SLinus Torvalds }
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds static void
1881da177e4SLinus Torvalds prio_destroy(struct Qdisc* sch)
1891da177e4SLinus Torvalds {
1901da177e4SLinus Torvalds 	int prio;
1911da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
1921da177e4SLinus Torvalds 
193a48b5a61SPatrick McHardy 	tcf_destroy_chain(q->filter_list);
1941da177e4SLinus Torvalds 	for (prio=0; prio<q->bands; prio++)
1951da177e4SLinus Torvalds 		qdisc_destroy(q->queues[prio]);
1961da177e4SLinus Torvalds }
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds static int prio_tune(struct Qdisc *sch, struct rtattr *opt)
1991da177e4SLinus Torvalds {
2001da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
2011da177e4SLinus Torvalds 	struct tc_prio_qopt *qopt = RTA_DATA(opt);
2021da177e4SLinus Torvalds 	int i;
2031da177e4SLinus Torvalds 
2041da177e4SLinus Torvalds 	if (opt->rta_len < RTA_LENGTH(sizeof(*qopt)))
2051da177e4SLinus Torvalds 		return -EINVAL;
2061da177e4SLinus Torvalds 	if (qopt->bands > TCQ_PRIO_BANDS || qopt->bands < 2)
2071da177e4SLinus Torvalds 		return -EINVAL;
2081da177e4SLinus Torvalds 
2091da177e4SLinus Torvalds 	for (i=0; i<=TC_PRIO_MAX; i++) {
2101da177e4SLinus Torvalds 		if (qopt->priomap[i] >= qopt->bands)
2111da177e4SLinus Torvalds 			return -EINVAL;
2121da177e4SLinus Torvalds 	}
2131da177e4SLinus Torvalds 
2141da177e4SLinus Torvalds 	sch_tree_lock(sch);
2151da177e4SLinus Torvalds 	q->bands = qopt->bands;
2161da177e4SLinus Torvalds 	memcpy(q->prio2band, qopt->priomap, TC_PRIO_MAX+1);
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds 	for (i=q->bands; i<TCQ_PRIO_BANDS; i++) {
2191da177e4SLinus Torvalds 		struct Qdisc *child = xchg(&q->queues[i], &noop_qdisc);
2205e50da01SPatrick McHardy 		if (child != &noop_qdisc) {
2215e50da01SPatrick McHardy 			qdisc_tree_decrease_qlen(child, child->q.qlen);
2221da177e4SLinus Torvalds 			qdisc_destroy(child);
2231da177e4SLinus Torvalds 		}
2245e50da01SPatrick McHardy 	}
2251da177e4SLinus Torvalds 	sch_tree_unlock(sch);
2261da177e4SLinus Torvalds 
227dd914b40SAmnon Aaronsohn 	for (i=0; i<q->bands; i++) {
228dd914b40SAmnon Aaronsohn 		if (q->queues[i] == &noop_qdisc) {
2291da177e4SLinus Torvalds 			struct Qdisc *child;
2309f9afec4SPatrick McHardy 			child = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops,
2319f9afec4SPatrick McHardy 						  TC_H_MAKE(sch->handle, i + 1));
2321da177e4SLinus Torvalds 			if (child) {
2331da177e4SLinus Torvalds 				sch_tree_lock(sch);
234dd914b40SAmnon Aaronsohn 				child = xchg(&q->queues[i], child);
2351da177e4SLinus Torvalds 
2365e50da01SPatrick McHardy 				if (child != &noop_qdisc) {
2375e50da01SPatrick McHardy 					qdisc_tree_decrease_qlen(child,
2385e50da01SPatrick McHardy 								 child->q.qlen);
2391da177e4SLinus Torvalds 					qdisc_destroy(child);
2405e50da01SPatrick McHardy 				}
2411da177e4SLinus Torvalds 				sch_tree_unlock(sch);
2421da177e4SLinus Torvalds 			}
2431da177e4SLinus Torvalds 		}
2441da177e4SLinus Torvalds 	}
2451da177e4SLinus Torvalds 	return 0;
2461da177e4SLinus Torvalds }
2471da177e4SLinus Torvalds 
2481da177e4SLinus Torvalds static int prio_init(struct Qdisc *sch, struct rtattr *opt)
2491da177e4SLinus Torvalds {
2501da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
2511da177e4SLinus Torvalds 	int i;
2521da177e4SLinus Torvalds 
2531da177e4SLinus Torvalds 	for (i=0; i<TCQ_PRIO_BANDS; i++)
2541da177e4SLinus Torvalds 		q->queues[i] = &noop_qdisc;
2551da177e4SLinus Torvalds 
2561da177e4SLinus Torvalds 	if (opt == NULL) {
2571da177e4SLinus Torvalds 		return -EINVAL;
2581da177e4SLinus Torvalds 	} else {
2591da177e4SLinus Torvalds 		int err;
2601da177e4SLinus Torvalds 
2611da177e4SLinus Torvalds 		if ((err= prio_tune(sch, opt)) != 0)
2621da177e4SLinus Torvalds 			return err;
2631da177e4SLinus Torvalds 	}
2641da177e4SLinus Torvalds 	return 0;
2651da177e4SLinus Torvalds }
2661da177e4SLinus Torvalds 
2671da177e4SLinus Torvalds static int prio_dump(struct Qdisc *sch, struct sk_buff *skb)
2681da177e4SLinus Torvalds {
2691da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
27027a884dcSArnaldo Carvalho de Melo 	unsigned char *b = skb_tail_pointer(skb);
2711da177e4SLinus Torvalds 	struct tc_prio_qopt opt;
2721da177e4SLinus Torvalds 
2731da177e4SLinus Torvalds 	opt.bands = q->bands;
2741da177e4SLinus Torvalds 	memcpy(&opt.priomap, q->prio2band, TC_PRIO_MAX+1);
2751da177e4SLinus Torvalds 	RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
2761da177e4SLinus Torvalds 	return skb->len;
2771da177e4SLinus Torvalds 
2781da177e4SLinus Torvalds rtattr_failure:
279dc5fc579SArnaldo Carvalho de Melo 	nlmsg_trim(skb, b);
2801da177e4SLinus Torvalds 	return -1;
2811da177e4SLinus Torvalds }
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
2841da177e4SLinus Torvalds 		      struct Qdisc **old)
2851da177e4SLinus Torvalds {
2861da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
2871da177e4SLinus Torvalds 	unsigned long band = arg - 1;
2881da177e4SLinus Torvalds 
2891da177e4SLinus Torvalds 	if (band >= q->bands)
2901da177e4SLinus Torvalds 		return -EINVAL;
2911da177e4SLinus Torvalds 
2921da177e4SLinus Torvalds 	if (new == NULL)
2931da177e4SLinus Torvalds 		new = &noop_qdisc;
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds 	sch_tree_lock(sch);
2961da177e4SLinus Torvalds 	*old = q->queues[band];
2971da177e4SLinus Torvalds 	q->queues[band] = new;
2985e50da01SPatrick McHardy 	qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
2991da177e4SLinus Torvalds 	qdisc_reset(*old);
3001da177e4SLinus Torvalds 	sch_tree_unlock(sch);
3011da177e4SLinus Torvalds 
3021da177e4SLinus Torvalds 	return 0;
3031da177e4SLinus Torvalds }
3041da177e4SLinus Torvalds 
3051da177e4SLinus Torvalds static struct Qdisc *
3061da177e4SLinus Torvalds prio_leaf(struct Qdisc *sch, unsigned long arg)
3071da177e4SLinus Torvalds {
3081da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
3091da177e4SLinus Torvalds 	unsigned long band = arg - 1;
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds 	if (band >= q->bands)
3121da177e4SLinus Torvalds 		return NULL;
3131da177e4SLinus Torvalds 
3141da177e4SLinus Torvalds 	return q->queues[band];
3151da177e4SLinus Torvalds }
3161da177e4SLinus Torvalds 
3171da177e4SLinus Torvalds static unsigned long prio_get(struct Qdisc *sch, u32 classid)
3181da177e4SLinus Torvalds {
3191da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
3201da177e4SLinus Torvalds 	unsigned long band = TC_H_MIN(classid);
3211da177e4SLinus Torvalds 
3221da177e4SLinus Torvalds 	if (band - 1 >= q->bands)
3231da177e4SLinus Torvalds 		return 0;
3241da177e4SLinus Torvalds 	return band;
3251da177e4SLinus Torvalds }
3261da177e4SLinus Torvalds 
3271da177e4SLinus Torvalds static unsigned long prio_bind(struct Qdisc *sch, unsigned long parent, u32 classid)
3281da177e4SLinus Torvalds {
3291da177e4SLinus Torvalds 	return prio_get(sch, classid);
3301da177e4SLinus Torvalds }
3311da177e4SLinus Torvalds 
3321da177e4SLinus Torvalds 
3331da177e4SLinus Torvalds static void prio_put(struct Qdisc *q, unsigned long cl)
3341da177e4SLinus Torvalds {
3351da177e4SLinus Torvalds 	return;
3361da177e4SLinus Torvalds }
3371da177e4SLinus Torvalds 
3381da177e4SLinus Torvalds static int prio_change(struct Qdisc *sch, u32 handle, u32 parent, struct rtattr **tca, unsigned long *arg)
3391da177e4SLinus Torvalds {
3401da177e4SLinus Torvalds 	unsigned long cl = *arg;
3411da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
3421da177e4SLinus Torvalds 
3431da177e4SLinus Torvalds 	if (cl - 1 > q->bands)
3441da177e4SLinus Torvalds 		return -ENOENT;
3451da177e4SLinus Torvalds 	return 0;
3461da177e4SLinus Torvalds }
3471da177e4SLinus Torvalds 
3481da177e4SLinus Torvalds static int prio_delete(struct Qdisc *sch, unsigned long cl)
3491da177e4SLinus Torvalds {
3501da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
3511da177e4SLinus Torvalds 	if (cl - 1 > q->bands)
3521da177e4SLinus Torvalds 		return -ENOENT;
3531da177e4SLinus Torvalds 	return 0;
3541da177e4SLinus Torvalds }
3551da177e4SLinus Torvalds 
3561da177e4SLinus Torvalds 
3571da177e4SLinus Torvalds static int prio_dump_class(struct Qdisc *sch, unsigned long cl, struct sk_buff *skb,
3581da177e4SLinus Torvalds 			   struct tcmsg *tcm)
3591da177e4SLinus Torvalds {
3601da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
3611da177e4SLinus Torvalds 
3621da177e4SLinus Torvalds 	if (cl - 1 > q->bands)
3631da177e4SLinus Torvalds 		return -ENOENT;
3641da177e4SLinus Torvalds 	tcm->tcm_handle |= TC_H_MIN(cl);
3651da177e4SLinus Torvalds 	if (q->queues[cl-1])
3661da177e4SLinus Torvalds 		tcm->tcm_info = q->queues[cl-1]->handle;
3671da177e4SLinus Torvalds 	return 0;
3681da177e4SLinus Torvalds }
3691da177e4SLinus Torvalds 
3702cf6c36cSJarek Poplawski static int prio_dump_class_stats(struct Qdisc *sch, unsigned long cl,
3712cf6c36cSJarek Poplawski 				 struct gnet_dump *d)
3722cf6c36cSJarek Poplawski {
3732cf6c36cSJarek Poplawski 	struct prio_sched_data *q = qdisc_priv(sch);
3742cf6c36cSJarek Poplawski 	struct Qdisc *cl_q;
3752cf6c36cSJarek Poplawski 
3762cf6c36cSJarek Poplawski 	cl_q = q->queues[cl - 1];
3772cf6c36cSJarek Poplawski 	if (gnet_stats_copy_basic(d, &cl_q->bstats) < 0 ||
3782cf6c36cSJarek Poplawski 	    gnet_stats_copy_queue(d, &cl_q->qstats) < 0)
3792cf6c36cSJarek Poplawski 		return -1;
3802cf6c36cSJarek Poplawski 
3812cf6c36cSJarek Poplawski 	return 0;
3822cf6c36cSJarek Poplawski }
3832cf6c36cSJarek Poplawski 
3841da177e4SLinus Torvalds static void prio_walk(struct Qdisc *sch, struct qdisc_walker *arg)
3851da177e4SLinus Torvalds {
3861da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
3871da177e4SLinus Torvalds 	int prio;
3881da177e4SLinus Torvalds 
3891da177e4SLinus Torvalds 	if (arg->stop)
3901da177e4SLinus Torvalds 		return;
3911da177e4SLinus Torvalds 
3921da177e4SLinus Torvalds 	for (prio = 0; prio < q->bands; prio++) {
3931da177e4SLinus Torvalds 		if (arg->count < arg->skip) {
3941da177e4SLinus Torvalds 			arg->count++;
3951da177e4SLinus Torvalds 			continue;
3961da177e4SLinus Torvalds 		}
3971da177e4SLinus Torvalds 		if (arg->fn(sch, prio+1, arg) < 0) {
3981da177e4SLinus Torvalds 			arg->stop = 1;
3991da177e4SLinus Torvalds 			break;
4001da177e4SLinus Torvalds 		}
4011da177e4SLinus Torvalds 		arg->count++;
4021da177e4SLinus Torvalds 	}
4031da177e4SLinus Torvalds }
4041da177e4SLinus Torvalds 
4051da177e4SLinus Torvalds static struct tcf_proto ** prio_find_tcf(struct Qdisc *sch, unsigned long cl)
4061da177e4SLinus Torvalds {
4071da177e4SLinus Torvalds 	struct prio_sched_data *q = qdisc_priv(sch);
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds 	if (cl)
4101da177e4SLinus Torvalds 		return NULL;
4111da177e4SLinus Torvalds 	return &q->filter_list;
4121da177e4SLinus Torvalds }
4131da177e4SLinus Torvalds 
4141da177e4SLinus Torvalds static struct Qdisc_class_ops prio_class_ops = {
4151da177e4SLinus Torvalds 	.graft		=	prio_graft,
4161da177e4SLinus Torvalds 	.leaf		=	prio_leaf,
4171da177e4SLinus Torvalds 	.get		=	prio_get,
4181da177e4SLinus Torvalds 	.put		=	prio_put,
4191da177e4SLinus Torvalds 	.change		=	prio_change,
4201da177e4SLinus Torvalds 	.delete		=	prio_delete,
4211da177e4SLinus Torvalds 	.walk		=	prio_walk,
4221da177e4SLinus Torvalds 	.tcf_chain	=	prio_find_tcf,
4231da177e4SLinus Torvalds 	.bind_tcf	=	prio_bind,
4241da177e4SLinus Torvalds 	.unbind_tcf	=	prio_put,
4251da177e4SLinus Torvalds 	.dump		=	prio_dump_class,
4262cf6c36cSJarek Poplawski 	.dump_stats	=	prio_dump_class_stats,
4271da177e4SLinus Torvalds };
4281da177e4SLinus Torvalds 
4291da177e4SLinus Torvalds static struct Qdisc_ops prio_qdisc_ops = {
4301da177e4SLinus Torvalds 	.next		=	NULL,
4311da177e4SLinus Torvalds 	.cl_ops		=	&prio_class_ops,
4321da177e4SLinus Torvalds 	.id		=	"prio",
4331da177e4SLinus Torvalds 	.priv_size	=	sizeof(struct prio_sched_data),
4341da177e4SLinus Torvalds 	.enqueue	=	prio_enqueue,
4351da177e4SLinus Torvalds 	.dequeue	=	prio_dequeue,
4361da177e4SLinus Torvalds 	.requeue	=	prio_requeue,
4371da177e4SLinus Torvalds 	.drop		=	prio_drop,
4381da177e4SLinus Torvalds 	.init		=	prio_init,
4391da177e4SLinus Torvalds 	.reset		=	prio_reset,
4401da177e4SLinus Torvalds 	.destroy	=	prio_destroy,
4411da177e4SLinus Torvalds 	.change		=	prio_tune,
4421da177e4SLinus Torvalds 	.dump		=	prio_dump,
4431da177e4SLinus Torvalds 	.owner		=	THIS_MODULE,
4441da177e4SLinus Torvalds };
4451da177e4SLinus Torvalds 
4461da177e4SLinus Torvalds static int __init prio_module_init(void)
4471da177e4SLinus Torvalds {
4481da177e4SLinus Torvalds 	return register_qdisc(&prio_qdisc_ops);
4491da177e4SLinus Torvalds }
4501da177e4SLinus Torvalds 
4511da177e4SLinus Torvalds static void __exit prio_module_exit(void)
4521da177e4SLinus Torvalds {
4531da177e4SLinus Torvalds 	unregister_qdisc(&prio_qdisc_ops);
4541da177e4SLinus Torvalds }
4551da177e4SLinus Torvalds 
4561da177e4SLinus Torvalds module_init(prio_module_init)
4571da177e4SLinus Torvalds module_exit(prio_module_exit)
4581da177e4SLinus Torvalds 
4591da177e4SLinus Torvalds MODULE_LICENSE("GPL");
460