Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/sched/sch_prio.c Simple 3-band priority "scheduler". |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 10 | * Fixes: 19990609: J Hadi Salim <hadi@nortelnetworks.com>: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * Init -- EINVAL when opt undefined |
| 12 | */ |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/types.h> |
| 16 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/skbuff.h> |
Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 20 | #include <net/netlink.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <net/pkt_sched.h> |
| 22 | |
| 23 | |
| 24 | struct prio_sched_data |
| 25 | { |
| 26 | int bands; |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 27 | int curband; /* for round-robin */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | struct tcf_proto *filter_list; |
| 29 | u8 prio2band[TC_PRIO_MAX+1]; |
| 30 | struct Qdisc *queues[TCQ_PRIO_BANDS]; |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 31 | int mq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | |
| 35 | static struct Qdisc * |
| 36 | prio_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr) |
| 37 | { |
| 38 | struct prio_sched_data *q = qdisc_priv(sch); |
| 39 | u32 band = skb->priority; |
| 40 | struct tcf_result res; |
Patrick McHardy | bdba91e | 2007-07-30 17:07:14 -0700 | [diff] [blame] | 41 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Jamal Hadi Salim | 29f1df6 | 2006-01-08 22:35:55 -0800 | [diff] [blame] | 43 | *qerr = NET_XMIT_BYPASS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | if (TC_H_MAJ(skb->priority) != sch->handle) { |
Patrick McHardy | bdba91e | 2007-07-30 17:07:14 -0700 | [diff] [blame] | 45 | err = tc_classify(skb, q->filter_list, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #ifdef CONFIG_NET_CLS_ACT |
| 47 | switch (tc_classify(skb, q->filter_list, &res)) { |
| 48 | case TC_ACT_STOLEN: |
| 49 | case TC_ACT_QUEUED: |
| 50 | *qerr = NET_XMIT_SUCCESS; |
| 51 | case TC_ACT_SHOT: |
| 52 | return NULL; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 53 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #endif |
Patrick McHardy | bdba91e | 2007-07-30 17:07:14 -0700 | [diff] [blame] | 55 | if (!q->filter_list || err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | if (TC_H_MAJ(band)) |
| 57 | band = 0; |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 58 | band = q->prio2band[band&TC_PRIO_MAX]; |
| 59 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
| 61 | band = res.classid; |
| 62 | } |
| 63 | band = TC_H_MIN(band) - 1; |
Jamal Hadi Salim | 3e5c2d3 | 2007-05-14 02:57:19 -0700 | [diff] [blame] | 64 | if (band >= q->bands) |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 65 | band = q->prio2band[0]; |
| 66 | out: |
| 67 | if (q->mq) |
| 68 | skb_set_queue_mapping(skb, band); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | return q->queues[band]; |
| 70 | } |
| 71 | |
| 72 | static int |
| 73 | prio_enqueue(struct sk_buff *skb, struct Qdisc *sch) |
| 74 | { |
| 75 | struct Qdisc *qdisc; |
| 76 | int ret; |
| 77 | |
| 78 | qdisc = prio_classify(skb, sch, &ret); |
| 79 | #ifdef CONFIG_NET_CLS_ACT |
| 80 | if (qdisc == NULL) { |
Jamal Hadi Salim | 29f1df6 | 2006-01-08 22:35:55 -0800 | [diff] [blame] | 81 | |
| 82 | if (ret == NET_XMIT_BYPASS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | sch->qstats.drops++; |
| 84 | kfree_skb(skb); |
| 85 | return ret; |
| 86 | } |
| 87 | #endif |
| 88 | |
| 89 | if ((ret = qdisc->enqueue(skb, qdisc)) == NET_XMIT_SUCCESS) { |
| 90 | sch->bstats.bytes += skb->len; |
| 91 | sch->bstats.packets++; |
| 92 | sch->q.qlen++; |
| 93 | return NET_XMIT_SUCCESS; |
| 94 | } |
| 95 | sch->qstats.drops++; |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 96 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | |
| 100 | static int |
| 101 | prio_requeue(struct sk_buff *skb, struct Qdisc* sch) |
| 102 | { |
| 103 | struct Qdisc *qdisc; |
| 104 | int ret; |
| 105 | |
| 106 | qdisc = prio_classify(skb, sch, &ret); |
| 107 | #ifdef CONFIG_NET_CLS_ACT |
| 108 | if (qdisc == NULL) { |
Jamal Hadi Salim | 29f1df6 | 2006-01-08 22:35:55 -0800 | [diff] [blame] | 109 | if (ret == NET_XMIT_BYPASS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | sch->qstats.drops++; |
| 111 | kfree_skb(skb); |
| 112 | return ret; |
| 113 | } |
| 114 | #endif |
| 115 | |
| 116 | if ((ret = qdisc->ops->requeue(skb, qdisc)) == NET_XMIT_SUCCESS) { |
| 117 | sch->q.qlen++; |
| 118 | sch->qstats.requeues++; |
| 119 | return 0; |
| 120 | } |
| 121 | sch->qstats.drops++; |
| 122 | return NET_XMIT_DROP; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | static struct sk_buff * |
| 127 | prio_dequeue(struct Qdisc* sch) |
| 128 | { |
| 129 | struct sk_buff *skb; |
| 130 | struct prio_sched_data *q = qdisc_priv(sch); |
| 131 | int prio; |
| 132 | struct Qdisc *qdisc; |
| 133 | |
| 134 | for (prio = 0; prio < q->bands; prio++) { |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 135 | /* Check if the target subqueue is available before |
| 136 | * pulling an skb. This way we avoid excessive requeues |
| 137 | * for slower queues. |
| 138 | */ |
| 139 | if (!netif_subqueue_stopped(sch->dev, (q->mq ? prio : 0))) { |
| 140 | qdisc = q->queues[prio]; |
| 141 | skb = qdisc->dequeue(qdisc); |
| 142 | if (skb) { |
| 143 | sch->q.qlen--; |
| 144 | return skb; |
| 145 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | return NULL; |
| 149 | |
| 150 | } |
| 151 | |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 152 | static struct sk_buff *rr_dequeue(struct Qdisc* sch) |
| 153 | { |
| 154 | struct sk_buff *skb; |
| 155 | struct prio_sched_data *q = qdisc_priv(sch); |
| 156 | struct Qdisc *qdisc; |
| 157 | int bandcount; |
| 158 | |
| 159 | /* Only take one pass through the queues. If nothing is available, |
| 160 | * return nothing. |
| 161 | */ |
| 162 | for (bandcount = 0; bandcount < q->bands; bandcount++) { |
| 163 | /* Check if the target subqueue is available before |
| 164 | * pulling an skb. This way we avoid excessive requeues |
| 165 | * for slower queues. If the queue is stopped, try the |
| 166 | * next queue. |
| 167 | */ |
| 168 | if (!netif_subqueue_stopped(sch->dev, |
| 169 | (q->mq ? q->curband : 0))) { |
| 170 | qdisc = q->queues[q->curband]; |
| 171 | skb = qdisc->dequeue(qdisc); |
| 172 | if (skb) { |
| 173 | sch->q.qlen--; |
| 174 | q->curband++; |
| 175 | if (q->curband >= q->bands) |
| 176 | q->curband = 0; |
| 177 | return skb; |
| 178 | } |
| 179 | } |
| 180 | q->curband++; |
| 181 | if (q->curband >= q->bands) |
| 182 | q->curband = 0; |
| 183 | } |
| 184 | return NULL; |
| 185 | } |
| 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | static unsigned int prio_drop(struct Qdisc* sch) |
| 188 | { |
| 189 | struct prio_sched_data *q = qdisc_priv(sch); |
| 190 | int prio; |
| 191 | unsigned int len; |
| 192 | struct Qdisc *qdisc; |
| 193 | |
| 194 | for (prio = q->bands-1; prio >= 0; prio--) { |
| 195 | qdisc = q->queues[prio]; |
Patrick McHardy | 6d037a2 | 2006-03-20 19:00:49 -0800 | [diff] [blame] | 196 | if (qdisc->ops->drop && (len = qdisc->ops->drop(qdisc)) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | sch->q.qlen--; |
| 198 | return len; |
| 199 | } |
| 200 | } |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | |
| 205 | static void |
| 206 | prio_reset(struct Qdisc* sch) |
| 207 | { |
| 208 | int prio; |
| 209 | struct prio_sched_data *q = qdisc_priv(sch); |
| 210 | |
| 211 | for (prio=0; prio<q->bands; prio++) |
| 212 | qdisc_reset(q->queues[prio]); |
| 213 | sch->q.qlen = 0; |
| 214 | } |
| 215 | |
| 216 | static void |
| 217 | prio_destroy(struct Qdisc* sch) |
| 218 | { |
| 219 | int prio; |
| 220 | struct prio_sched_data *q = qdisc_priv(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Patrick McHardy | a48b5a6 | 2007-03-23 11:29:43 -0700 | [diff] [blame] | 222 | tcf_destroy_chain(q->filter_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | for (prio=0; prio<q->bands; prio++) |
| 224 | qdisc_destroy(q->queues[prio]); |
| 225 | } |
| 226 | |
| 227 | static int prio_tune(struct Qdisc *sch, struct rtattr *opt) |
| 228 | { |
| 229 | struct prio_sched_data *q = qdisc_priv(sch); |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 230 | struct tc_prio_qopt *qopt; |
| 231 | struct rtattr *tb[TCA_PRIO_MAX]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | int i; |
| 233 | |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 234 | if (rtattr_parse_nested_compat(tb, TCA_PRIO_MAX, opt, qopt, |
| 235 | sizeof(*qopt))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | return -EINVAL; |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 237 | q->bands = qopt->bands; |
| 238 | /* If we're multiqueue, make sure the number of incoming bands |
| 239 | * matches the number of queues on the device we're associating with. |
| 240 | * If the number of bands requested is zero, then set q->bands to |
Peter P Waskiewicz Jr | 0773192 | 2007-07-30 17:13:45 -0700 | [diff] [blame] | 241 | * dev->egress_subqueue_count. Also, the root qdisc must be the |
| 242 | * only one that is enabled for multiqueue, since it's the only one |
| 243 | * that interacts with the underlying device. |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 244 | */ |
| 245 | q->mq = RTA_GET_FLAG(tb[TCA_PRIO_MQ - 1]); |
| 246 | if (q->mq) { |
Peter P Waskiewicz Jr | 0773192 | 2007-07-30 17:13:45 -0700 | [diff] [blame] | 247 | if (sch->parent != TC_H_ROOT) |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 248 | return -EINVAL; |
| 249 | if (netif_is_multiqueue(sch->dev)) { |
| 250 | if (q->bands == 0) |
| 251 | q->bands = sch->dev->egress_subqueue_count; |
| 252 | else if (q->bands != sch->dev->egress_subqueue_count) |
| 253 | return -EINVAL; |
| 254 | } else |
| 255 | return -EOPNOTSUPP; |
| 256 | } |
| 257 | |
| 258 | if (q->bands > TCQ_PRIO_BANDS || q->bands < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | return -EINVAL; |
| 260 | |
| 261 | for (i=0; i<=TC_PRIO_MAX; i++) { |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 262 | if (qopt->priomap[i] >= q->bands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | return -EINVAL; |
| 264 | } |
| 265 | |
| 266 | sch_tree_lock(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | memcpy(q->prio2band, qopt->priomap, TC_PRIO_MAX+1); |
| 268 | |
| 269 | for (i=q->bands; i<TCQ_PRIO_BANDS; i++) { |
| 270 | struct Qdisc *child = xchg(&q->queues[i], &noop_qdisc); |
Patrick McHardy | 5e50da0 | 2006-11-29 17:36:20 -0800 | [diff] [blame] | 271 | if (child != &noop_qdisc) { |
| 272 | qdisc_tree_decrease_qlen(child, child->q.qlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | qdisc_destroy(child); |
Patrick McHardy | 5e50da0 | 2006-11-29 17:36:20 -0800 | [diff] [blame] | 274 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
| 276 | sch_tree_unlock(sch); |
| 277 | |
Amnon Aaronsohn | dd914b4 | 2006-01-17 02:24:26 -0800 | [diff] [blame] | 278 | for (i=0; i<q->bands; i++) { |
| 279 | if (q->queues[i] == &noop_qdisc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | struct Qdisc *child; |
Patrick McHardy | 9f9afec | 2006-11-29 17:35:18 -0800 | [diff] [blame] | 281 | child = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, |
| 282 | TC_H_MAKE(sch->handle, i + 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | if (child) { |
| 284 | sch_tree_lock(sch); |
Amnon Aaronsohn | dd914b4 | 2006-01-17 02:24:26 -0800 | [diff] [blame] | 285 | child = xchg(&q->queues[i], child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Patrick McHardy | 5e50da0 | 2006-11-29 17:36:20 -0800 | [diff] [blame] | 287 | if (child != &noop_qdisc) { |
| 288 | qdisc_tree_decrease_qlen(child, |
| 289 | child->q.qlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | qdisc_destroy(child); |
Patrick McHardy | 5e50da0 | 2006-11-29 17:36:20 -0800 | [diff] [blame] | 291 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | sch_tree_unlock(sch); |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | static int prio_init(struct Qdisc *sch, struct rtattr *opt) |
| 300 | { |
| 301 | struct prio_sched_data *q = qdisc_priv(sch); |
| 302 | int i; |
| 303 | |
| 304 | for (i=0; i<TCQ_PRIO_BANDS; i++) |
| 305 | q->queues[i] = &noop_qdisc; |
| 306 | |
| 307 | if (opt == NULL) { |
| 308 | return -EINVAL; |
| 309 | } else { |
| 310 | int err; |
| 311 | |
| 312 | if ((err= prio_tune(sch, opt)) != 0) |
| 313 | return err; |
| 314 | } |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | static int prio_dump(struct Qdisc *sch, struct sk_buff *skb) |
| 319 | { |
| 320 | struct prio_sched_data *q = qdisc_priv(sch); |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 321 | unsigned char *b = skb_tail_pointer(skb); |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 322 | struct rtattr *nest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | struct tc_prio_qopt opt; |
| 324 | |
| 325 | opt.bands = q->bands; |
| 326 | memcpy(&opt.priomap, q->prio2band, TC_PRIO_MAX+1); |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 327 | |
| 328 | nest = RTA_NEST_COMPAT(skb, TCA_OPTIONS, sizeof(opt), &opt); |
| 329 | if (q->mq) |
| 330 | RTA_PUT_FLAG(skb, TCA_PRIO_MQ); |
| 331 | RTA_NEST_COMPAT_END(skb, nest); |
| 332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | return skb->len; |
| 334 | |
| 335 | rtattr_failure: |
Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 336 | nlmsg_trim(skb, b); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | return -1; |
| 338 | } |
| 339 | |
| 340 | static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, |
| 341 | struct Qdisc **old) |
| 342 | { |
| 343 | struct prio_sched_data *q = qdisc_priv(sch); |
| 344 | unsigned long band = arg - 1; |
| 345 | |
| 346 | if (band >= q->bands) |
| 347 | return -EINVAL; |
| 348 | |
| 349 | if (new == NULL) |
| 350 | new = &noop_qdisc; |
| 351 | |
| 352 | sch_tree_lock(sch); |
| 353 | *old = q->queues[band]; |
| 354 | q->queues[band] = new; |
Patrick McHardy | 5e50da0 | 2006-11-29 17:36:20 -0800 | [diff] [blame] | 355 | qdisc_tree_decrease_qlen(*old, (*old)->q.qlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | qdisc_reset(*old); |
| 357 | sch_tree_unlock(sch); |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | static struct Qdisc * |
| 363 | prio_leaf(struct Qdisc *sch, unsigned long arg) |
| 364 | { |
| 365 | struct prio_sched_data *q = qdisc_priv(sch); |
| 366 | unsigned long band = arg - 1; |
| 367 | |
| 368 | if (band >= q->bands) |
| 369 | return NULL; |
| 370 | |
| 371 | return q->queues[band]; |
| 372 | } |
| 373 | |
| 374 | static unsigned long prio_get(struct Qdisc *sch, u32 classid) |
| 375 | { |
| 376 | struct prio_sched_data *q = qdisc_priv(sch); |
| 377 | unsigned long band = TC_H_MIN(classid); |
| 378 | |
| 379 | if (band - 1 >= q->bands) |
| 380 | return 0; |
| 381 | return band; |
| 382 | } |
| 383 | |
| 384 | static unsigned long prio_bind(struct Qdisc *sch, unsigned long parent, u32 classid) |
| 385 | { |
| 386 | return prio_get(sch, classid); |
| 387 | } |
| 388 | |
| 389 | |
| 390 | static void prio_put(struct Qdisc *q, unsigned long cl) |
| 391 | { |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | static int prio_change(struct Qdisc *sch, u32 handle, u32 parent, struct rtattr **tca, unsigned long *arg) |
| 396 | { |
| 397 | unsigned long cl = *arg; |
| 398 | struct prio_sched_data *q = qdisc_priv(sch); |
| 399 | |
| 400 | if (cl - 1 > q->bands) |
| 401 | return -ENOENT; |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | static int prio_delete(struct Qdisc *sch, unsigned long cl) |
| 406 | { |
| 407 | struct prio_sched_data *q = qdisc_priv(sch); |
| 408 | if (cl - 1 > q->bands) |
| 409 | return -ENOENT; |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | |
| 414 | static int prio_dump_class(struct Qdisc *sch, unsigned long cl, struct sk_buff *skb, |
| 415 | struct tcmsg *tcm) |
| 416 | { |
| 417 | struct prio_sched_data *q = qdisc_priv(sch); |
| 418 | |
| 419 | if (cl - 1 > q->bands) |
| 420 | return -ENOENT; |
| 421 | tcm->tcm_handle |= TC_H_MIN(cl); |
| 422 | if (q->queues[cl-1]) |
| 423 | tcm->tcm_info = q->queues[cl-1]->handle; |
| 424 | return 0; |
| 425 | } |
| 426 | |
Jarek Poplawski | 2cf6c36 | 2007-01-31 12:21:24 -0800 | [diff] [blame] | 427 | static int prio_dump_class_stats(struct Qdisc *sch, unsigned long cl, |
| 428 | struct gnet_dump *d) |
| 429 | { |
| 430 | struct prio_sched_data *q = qdisc_priv(sch); |
| 431 | struct Qdisc *cl_q; |
| 432 | |
| 433 | cl_q = q->queues[cl - 1]; |
| 434 | if (gnet_stats_copy_basic(d, &cl_q->bstats) < 0 || |
| 435 | gnet_stats_copy_queue(d, &cl_q->qstats) < 0) |
| 436 | return -1; |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | static void prio_walk(struct Qdisc *sch, struct qdisc_walker *arg) |
| 442 | { |
| 443 | struct prio_sched_data *q = qdisc_priv(sch); |
| 444 | int prio; |
| 445 | |
| 446 | if (arg->stop) |
| 447 | return; |
| 448 | |
| 449 | for (prio = 0; prio < q->bands; prio++) { |
| 450 | if (arg->count < arg->skip) { |
| 451 | arg->count++; |
| 452 | continue; |
| 453 | } |
| 454 | if (arg->fn(sch, prio+1, arg) < 0) { |
| 455 | arg->stop = 1; |
| 456 | break; |
| 457 | } |
| 458 | arg->count++; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | static struct tcf_proto ** prio_find_tcf(struct Qdisc *sch, unsigned long cl) |
| 463 | { |
| 464 | struct prio_sched_data *q = qdisc_priv(sch); |
| 465 | |
| 466 | if (cl) |
| 467 | return NULL; |
| 468 | return &q->filter_list; |
| 469 | } |
| 470 | |
| 471 | static struct Qdisc_class_ops prio_class_ops = { |
| 472 | .graft = prio_graft, |
| 473 | .leaf = prio_leaf, |
| 474 | .get = prio_get, |
| 475 | .put = prio_put, |
| 476 | .change = prio_change, |
| 477 | .delete = prio_delete, |
| 478 | .walk = prio_walk, |
| 479 | .tcf_chain = prio_find_tcf, |
| 480 | .bind_tcf = prio_bind, |
| 481 | .unbind_tcf = prio_put, |
| 482 | .dump = prio_dump_class, |
Jarek Poplawski | 2cf6c36 | 2007-01-31 12:21:24 -0800 | [diff] [blame] | 483 | .dump_stats = prio_dump_class_stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | }; |
| 485 | |
| 486 | static struct Qdisc_ops prio_qdisc_ops = { |
| 487 | .next = NULL, |
| 488 | .cl_ops = &prio_class_ops, |
| 489 | .id = "prio", |
| 490 | .priv_size = sizeof(struct prio_sched_data), |
| 491 | .enqueue = prio_enqueue, |
| 492 | .dequeue = prio_dequeue, |
| 493 | .requeue = prio_requeue, |
| 494 | .drop = prio_drop, |
| 495 | .init = prio_init, |
| 496 | .reset = prio_reset, |
| 497 | .destroy = prio_destroy, |
| 498 | .change = prio_tune, |
| 499 | .dump = prio_dump, |
| 500 | .owner = THIS_MODULE, |
| 501 | }; |
| 502 | |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 503 | static struct Qdisc_ops rr_qdisc_ops = { |
| 504 | .next = NULL, |
| 505 | .cl_ops = &prio_class_ops, |
| 506 | .id = "rr", |
| 507 | .priv_size = sizeof(struct prio_sched_data), |
| 508 | .enqueue = prio_enqueue, |
| 509 | .dequeue = rr_dequeue, |
| 510 | .requeue = prio_requeue, |
| 511 | .drop = prio_drop, |
| 512 | .init = prio_init, |
| 513 | .reset = prio_reset, |
| 514 | .destroy = prio_destroy, |
| 515 | .change = prio_tune, |
| 516 | .dump = prio_dump, |
| 517 | .owner = THIS_MODULE, |
| 518 | }; |
| 519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | static int __init prio_module_init(void) |
| 521 | { |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 522 | int err; |
| 523 | |
| 524 | err = register_qdisc(&prio_qdisc_ops); |
| 525 | if (err < 0) |
| 526 | return err; |
| 527 | err = register_qdisc(&rr_qdisc_ops); |
| 528 | if (err < 0) |
| 529 | unregister_qdisc(&prio_qdisc_ops); |
| 530 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | } |
| 532 | |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 533 | static void __exit prio_module_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | { |
| 535 | unregister_qdisc(&prio_qdisc_ops); |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 536 | unregister_qdisc(&rr_qdisc_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | module_init(prio_module_init) |
| 540 | module_exit(prio_module_exit) |
| 541 | |
| 542 | MODULE_LICENSE("GPL"); |
Peter P Waskiewicz Jr | d62733c | 2007-06-28 21:04:31 -0700 | [diff] [blame] | 543 | MODULE_ALIAS("sch_rr"); |