Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/sched/sch_gred.c Generic Random Early Detection queue. |
| 3 | * |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version |
| 8 | * 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * Authors: J Hadi Salim (hadi@cyberus.ca) 1998-2002 |
| 11 | * |
| 12 | * 991129: - Bug fix with grio mode |
| 13 | * - a better sing. AvgQ mode with Grio(WRED) |
| 14 | * - A finer grained VQ dequeue based on sugestion |
| 15 | * from Ren Liu |
| 16 | * - More error checks |
| 17 | * |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 18 | * For all the glorious comments look at include/net/red.h |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/types.h> |
| 24 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/skbuff.h> |
Jakub Kicinski | 890d8d2 | 2018-11-19 15:21:42 -0800 | [diff] [blame] | 26 | #include <net/pkt_cls.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <net/pkt_sched.h> |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 28 | #include <net/red.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 30 | #define GRED_DEF_PRIO (MAX_DPs / 2) |
Thomas Graf | 716a1b4 | 2005-11-05 21:14:20 +0100 | [diff] [blame] | 31 | #define GRED_VQ_MASK (MAX_DPs - 1) |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 32 | |
Jakub Kicinski | 25fc198 | 2018-11-14 22:23:50 -0800 | [diff] [blame] | 33 | #define GRED_VQ_RED_FLAGS (TC_RED_ECN | TC_RED_HARDDROP) |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | struct gred_sched_data; |
| 36 | struct gred_sched; |
| 37 | |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 38 | struct gred_sched_data { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | u32 limit; /* HARD maximal queue length */ |
Eric Dumazet | a73ed26 | 2011-12-09 02:46:45 +0000 | [diff] [blame] | 40 | u32 DP; /* the drop parameters */ |
Jakub Kicinski | 25fc198 | 2018-11-14 22:23:50 -0800 | [diff] [blame] | 41 | u32 red_flags; /* virtualQ version of red_flags */ |
Jakub Kicinski | 9f5cd0c | 2018-11-14 22:23:48 -0800 | [diff] [blame] | 42 | u64 bytesin; /* bytes seen on virtualQ so far*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | u32 packetsin; /* packets seen on virtualQ so far*/ |
| 44 | u32 backlog; /* bytes on the virtualQ */ |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 45 | u8 prio; /* the prio of this vq */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 47 | struct red_parms parms; |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 48 | struct red_vars vars; |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 49 | struct red_stats stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
Thomas Graf | dea3f62 | 2005-11-05 21:14:09 +0100 | [diff] [blame] | 52 | enum { |
| 53 | GRED_WRED_MODE = 1, |
Thomas Graf | d6fd4e9 | 2005-11-05 21:14:10 +0100 | [diff] [blame] | 54 | GRED_RIO_MODE, |
Thomas Graf | dea3f62 | 2005-11-05 21:14:09 +0100 | [diff] [blame] | 55 | }; |
| 56 | |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 57 | struct gred_sched { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | struct gred_sched_data *tab[MAX_DPs]; |
Thomas Graf | dea3f62 | 2005-11-05 21:14:09 +0100 | [diff] [blame] | 59 | unsigned long flags; |
Thomas Graf | b38c7ee | 2005-11-05 21:14:27 +0100 | [diff] [blame] | 60 | u32 red_flags; |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 61 | u32 DPs; |
| 62 | u32 def; |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 63 | struct red_vars wred_set; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Thomas Graf | dea3f62 | 2005-11-05 21:14:09 +0100 | [diff] [blame] | 66 | static inline int gred_wred_mode(struct gred_sched *table) |
| 67 | { |
| 68 | return test_bit(GRED_WRED_MODE, &table->flags); |
| 69 | } |
| 70 | |
| 71 | static inline void gred_enable_wred_mode(struct gred_sched *table) |
| 72 | { |
| 73 | __set_bit(GRED_WRED_MODE, &table->flags); |
| 74 | } |
| 75 | |
| 76 | static inline void gred_disable_wred_mode(struct gred_sched *table) |
| 77 | { |
| 78 | __clear_bit(GRED_WRED_MODE, &table->flags); |
| 79 | } |
| 80 | |
Thomas Graf | d6fd4e9 | 2005-11-05 21:14:10 +0100 | [diff] [blame] | 81 | static inline int gred_rio_mode(struct gred_sched *table) |
| 82 | { |
| 83 | return test_bit(GRED_RIO_MODE, &table->flags); |
| 84 | } |
| 85 | |
| 86 | static inline void gred_enable_rio_mode(struct gred_sched *table) |
| 87 | { |
| 88 | __set_bit(GRED_RIO_MODE, &table->flags); |
| 89 | } |
| 90 | |
| 91 | static inline void gred_disable_rio_mode(struct gred_sched *table) |
| 92 | { |
| 93 | __clear_bit(GRED_RIO_MODE, &table->flags); |
| 94 | } |
| 95 | |
Thomas Graf | dea3f62 | 2005-11-05 21:14:09 +0100 | [diff] [blame] | 96 | static inline int gred_wred_mode_check(struct Qdisc *sch) |
| 97 | { |
| 98 | struct gred_sched *table = qdisc_priv(sch); |
| 99 | int i; |
| 100 | |
| 101 | /* Really ugly O(n^2) but shouldn't be necessary too frequent. */ |
| 102 | for (i = 0; i < table->DPs; i++) { |
| 103 | struct gred_sched_data *q = table->tab[i]; |
| 104 | int n; |
| 105 | |
| 106 | if (q == NULL) |
| 107 | continue; |
| 108 | |
David Ward | c22e464 | 2012-09-13 05:22:33 +0000 | [diff] [blame] | 109 | for (n = i + 1; n < table->DPs; n++) |
| 110 | if (table->tab[n] && table->tab[n]->prio == q->prio) |
Thomas Graf | dea3f62 | 2005-11-05 21:14:09 +0100 | [diff] [blame] | 111 | return 1; |
| 112 | } |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 117 | static inline unsigned int gred_backlog(struct gred_sched *table, |
| 118 | struct gred_sched_data *q, |
| 119 | struct Qdisc *sch) |
| 120 | { |
| 121 | if (gred_wred_mode(table)) |
| 122 | return sch->qstats.backlog; |
| 123 | else |
| 124 | return q->backlog; |
| 125 | } |
| 126 | |
Thomas Graf | 716a1b4 | 2005-11-05 21:14:20 +0100 | [diff] [blame] | 127 | static inline u16 tc_index_to_dp(struct sk_buff *skb) |
| 128 | { |
| 129 | return skb->tc_index & GRED_VQ_MASK; |
| 130 | } |
| 131 | |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 132 | static inline void gred_load_wred_set(const struct gred_sched *table, |
Thomas Graf | 7051703 | 2005-11-05 21:14:23 +0100 | [diff] [blame] | 133 | struct gred_sched_data *q) |
| 134 | { |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 135 | q->vars.qavg = table->wred_set.qavg; |
| 136 | q->vars.qidlestart = table->wred_set.qidlestart; |
Thomas Graf | 7051703 | 2005-11-05 21:14:23 +0100 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | static inline void gred_store_wred_set(struct gred_sched *table, |
| 140 | struct gred_sched_data *q) |
| 141 | { |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 142 | table->wred_set.qavg = q->vars.qavg; |
David Ward | ba1bf47 | 2012-09-13 05:22:35 +0000 | [diff] [blame] | 143 | table->wred_set.qidlestart = q->vars.qidlestart; |
Thomas Graf | 7051703 | 2005-11-05 21:14:23 +0100 | [diff] [blame] | 144 | } |
| 145 | |
Jakub Kicinski | 25fc198 | 2018-11-14 22:23:50 -0800 | [diff] [blame] | 146 | static int gred_use_ecn(struct gred_sched_data *q) |
Thomas Graf | b38c7ee | 2005-11-05 21:14:27 +0100 | [diff] [blame] | 147 | { |
Jakub Kicinski | 25fc198 | 2018-11-14 22:23:50 -0800 | [diff] [blame] | 148 | return q->red_flags & TC_RED_ECN; |
Thomas Graf | b38c7ee | 2005-11-05 21:14:27 +0100 | [diff] [blame] | 149 | } |
| 150 | |
Jakub Kicinski | 25fc198 | 2018-11-14 22:23:50 -0800 | [diff] [blame] | 151 | static int gred_use_harddrop(struct gred_sched_data *q) |
Thomas Graf | bdc450a | 2005-11-05 21:14:28 +0100 | [diff] [blame] | 152 | { |
Jakub Kicinski | 25fc198 | 2018-11-14 22:23:50 -0800 | [diff] [blame] | 153 | return q->red_flags & TC_RED_HARDDROP; |
Thomas Graf | bdc450a | 2005-11-05 21:14:28 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Jakub Kicinski | 7211101 | 2018-11-14 22:23:51 -0800 | [diff] [blame] | 156 | static bool gred_per_vq_red_flags_used(struct gred_sched *table) |
| 157 | { |
| 158 | unsigned int i; |
| 159 | |
| 160 | /* Local per-vq flags couldn't have been set unless global are 0 */ |
| 161 | if (table->red_flags) |
| 162 | return false; |
| 163 | for (i = 0; i < MAX_DPs; i++) |
| 164 | if (table->tab[i] && table->tab[i]->red_flags) |
| 165 | return true; |
| 166 | return false; |
| 167 | } |
| 168 | |
Eric Dumazet | 520ac30 | 2016-06-21 23:16:49 -0700 | [diff] [blame] | 169 | static int gred_enqueue(struct sk_buff *skb, struct Qdisc *sch, |
| 170 | struct sk_buff **to_free) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 172 | struct gred_sched_data *q = NULL; |
| 173 | struct gred_sched *t = qdisc_priv(sch); |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 174 | unsigned long qavg = 0; |
Thomas Graf | 4a59183 | 2005-11-05 21:14:22 +0100 | [diff] [blame] | 175 | u16 dp = tc_index_to_dp(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 177 | if (dp >= t->DPs || (q = t->tab[dp]) == NULL) { |
Thomas Graf | 18e3fb84 | 2005-11-05 21:14:21 +0100 | [diff] [blame] | 178 | dp = t->def; |
| 179 | |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 180 | q = t->tab[dp]; |
| 181 | if (!q) { |
Thomas Graf | 18e3fb84 | 2005-11-05 21:14:21 +0100 | [diff] [blame] | 182 | /* Pass through packets not assigned to a DP |
| 183 | * if no default DP has been configured. This |
| 184 | * allows for DP flows to be left untouched. |
| 185 | */ |
David Ward | a3eb95f | 2015-05-09 22:01:46 -0400 | [diff] [blame] | 186 | if (likely(sch->qstats.backlog + qdisc_pkt_len(skb) <= |
| 187 | sch->limit)) |
Thomas Graf | 18e3fb84 | 2005-11-05 21:14:21 +0100 | [diff] [blame] | 188 | return qdisc_enqueue_tail(skb, sch); |
| 189 | else |
| 190 | goto drop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
Thomas Graf | 18e3fb84 | 2005-11-05 21:14:21 +0100 | [diff] [blame] | 192 | |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 193 | /* fix tc_index? --could be controversial but needed for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | requeueing */ |
Thomas Graf | 18e3fb84 | 2005-11-05 21:14:21 +0100 | [diff] [blame] | 195 | skb->tc_index = (skb->tc_index & ~GRED_VQ_MASK) | dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
| 197 | |
David Ward | e29fe83 | 2012-09-13 05:22:32 +0000 | [diff] [blame] | 198 | /* sum up all the qaves of prios < ours to get the new qave */ |
Thomas Graf | d6fd4e9 | 2005-11-05 21:14:10 +0100 | [diff] [blame] | 199 | if (!gred_wred_mode(t) && gred_rio_mode(t)) { |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 200 | int i; |
| 201 | |
| 202 | for (i = 0; i < t->DPs; i++) { |
| 203 | if (t->tab[i] && t->tab[i]->prio < q->prio && |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 204 | !red_is_idling(&t->tab[i]->vars)) |
| 205 | qavg += t->tab[i]->vars.qavg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | q->packetsin++; |
Jussi Kivilinna | 0abf77e | 2008-07-20 00:08:27 -0700 | [diff] [blame] | 211 | q->bytesin += qdisc_pkt_len(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 213 | if (gred_wred_mode(t)) |
Thomas Graf | 7051703 | 2005-11-05 21:14:23 +0100 | [diff] [blame] | 214 | gred_load_wred_set(t, q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 216 | q->vars.qavg = red_calc_qavg(&q->parms, |
| 217 | &q->vars, |
| 218 | gred_backlog(t, q, sch)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 220 | if (red_is_idling(&q->vars)) |
| 221 | red_end_of_idle_period(&q->vars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Thomas Graf | dea3f62 | 2005-11-05 21:14:09 +0100 | [diff] [blame] | 223 | if (gred_wred_mode(t)) |
Thomas Graf | 7051703 | 2005-11-05 21:14:23 +0100 | [diff] [blame] | 224 | gred_store_wred_set(t, q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 226 | switch (red_action(&q->parms, &q->vars, q->vars.qavg + qavg)) { |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 227 | case RED_DONT_MARK: |
| 228 | break; |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 229 | |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 230 | case RED_PROB_MARK: |
John Fastabend | 25331d6 | 2014-09-28 11:53:29 -0700 | [diff] [blame] | 231 | qdisc_qstats_overlimit(sch); |
Jakub Kicinski | 25fc198 | 2018-11-14 22:23:50 -0800 | [diff] [blame] | 232 | if (!gred_use_ecn(q) || !INET_ECN_set_ce(skb)) { |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 233 | q->stats.prob_drop++; |
| 234 | goto congestion_drop; |
| 235 | } |
Thomas Graf | b38c7ee | 2005-11-05 21:14:27 +0100 | [diff] [blame] | 236 | |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 237 | q->stats.prob_mark++; |
| 238 | break; |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 239 | |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 240 | case RED_HARD_MARK: |
John Fastabend | 25331d6 | 2014-09-28 11:53:29 -0700 | [diff] [blame] | 241 | qdisc_qstats_overlimit(sch); |
Jakub Kicinski | 25fc198 | 2018-11-14 22:23:50 -0800 | [diff] [blame] | 242 | if (gred_use_harddrop(q) || !gred_use_ecn(q) || |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 243 | !INET_ECN_set_ce(skb)) { |
| 244 | q->stats.forced_drop++; |
| 245 | goto congestion_drop; |
| 246 | } |
| 247 | q->stats.forced_mark++; |
| 248 | break; |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 249 | } |
| 250 | |
David Ward | 145a42b | 2015-05-09 22:01:47 -0400 | [diff] [blame] | 251 | if (gred_backlog(t, q, sch) + qdisc_pkt_len(skb) <= q->limit) { |
Jussi Kivilinna | 0abf77e | 2008-07-20 00:08:27 -0700 | [diff] [blame] | 252 | q->backlog += qdisc_pkt_len(skb); |
Thomas Graf | edf7a7b | 2005-11-05 21:14:19 +0100 | [diff] [blame] | 253 | return qdisc_enqueue_tail(skb, sch); |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 254 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 256 | q->stats.pdrop++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | drop: |
Eric Dumazet | 520ac30 | 2016-06-21 23:16:49 -0700 | [diff] [blame] | 258 | return qdisc_drop(skb, sch, to_free); |
Thomas Graf | c3b553c | 2005-11-05 21:14:18 +0100 | [diff] [blame] | 259 | |
| 260 | congestion_drop: |
Eric Dumazet | 520ac30 | 2016-06-21 23:16:49 -0700 | [diff] [blame] | 261 | qdisc_drop(skb, sch, to_free); |
Thomas Graf | c3b553c | 2005-11-05 21:14:18 +0100 | [diff] [blame] | 262 | return NET_XMIT_CN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 265 | static struct sk_buff *gred_dequeue(struct Qdisc *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | { |
| 267 | struct sk_buff *skb; |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 268 | struct gred_sched *t = qdisc_priv(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Thomas Graf | edf7a7b | 2005-11-05 21:14:19 +0100 | [diff] [blame] | 270 | skb = qdisc_dequeue_head(sch); |
| 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | if (skb) { |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 273 | struct gred_sched_data *q; |
Thomas Graf | 18e3fb84 | 2005-11-05 21:14:21 +0100 | [diff] [blame] | 274 | u16 dp = tc_index_to_dp(skb); |
| 275 | |
| 276 | if (dp >= t->DPs || (q = t->tab[dp]) == NULL) { |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 277 | net_warn_ratelimited("GRED: Unable to relocate VQ 0x%x after dequeue, screwing up backlog\n", |
| 278 | tc_index_to_dp(skb)); |
Thomas Graf | 18e3fb84 | 2005-11-05 21:14:21 +0100 | [diff] [blame] | 279 | } else { |
Jussi Kivilinna | 0abf77e | 2008-07-20 00:08:27 -0700 | [diff] [blame] | 280 | q->backlog -= qdisc_pkt_len(skb); |
Thomas Graf | 18e3fb84 | 2005-11-05 21:14:21 +0100 | [diff] [blame] | 281 | |
David Ward | ba1bf47 | 2012-09-13 05:22:35 +0000 | [diff] [blame] | 282 | if (gred_wred_mode(t)) { |
| 283 | if (!sch->qstats.backlog) |
| 284 | red_start_of_idle_period(&t->wred_set); |
| 285 | } else { |
| 286 | if (!q->backlog) |
| 287 | red_start_of_idle_period(&q->vars); |
| 288 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | } |
Thomas Graf | 18e3fb84 | 2005-11-05 21:14:21 +0100 | [diff] [blame] | 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | return skb; |
| 292 | } |
| 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | return NULL; |
| 295 | } |
| 296 | |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 297 | static void gred_reset(struct Qdisc *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
| 299 | int i; |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 300 | struct gred_sched *t = qdisc_priv(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Thomas Graf | edf7a7b | 2005-11-05 21:14:19 +0100 | [diff] [blame] | 302 | qdisc_reset_queue(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 304 | for (i = 0; i < t->DPs; i++) { |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 305 | struct gred_sched_data *q = t->tab[i]; |
| 306 | |
| 307 | if (!q) |
| 308 | continue; |
| 309 | |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 310 | red_restart(&q->vars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | q->backlog = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
Jakub Kicinski | 890d8d2 | 2018-11-19 15:21:42 -0800 | [diff] [blame] | 315 | static void gred_offload(struct Qdisc *sch, enum tc_gred_command command) |
| 316 | { |
| 317 | struct gred_sched *table = qdisc_priv(sch); |
| 318 | struct net_device *dev = qdisc_dev(sch); |
| 319 | struct tc_gred_qopt_offload opt = { |
| 320 | .command = command, |
| 321 | .handle = sch->handle, |
| 322 | .parent = sch->parent, |
| 323 | }; |
| 324 | |
| 325 | if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc) |
| 326 | return; |
| 327 | |
| 328 | if (command == TC_GRED_REPLACE) { |
| 329 | unsigned int i; |
| 330 | |
| 331 | opt.set.grio_on = gred_rio_mode(table); |
| 332 | opt.set.wred_on = gred_wred_mode(table); |
| 333 | opt.set.dp_cnt = table->DPs; |
| 334 | opt.set.dp_def = table->def; |
| 335 | |
| 336 | for (i = 0; i < table->DPs; i++) { |
| 337 | struct gred_sched_data *q = table->tab[i]; |
| 338 | |
| 339 | if (!q) |
| 340 | continue; |
| 341 | opt.set.tab[i].present = true; |
| 342 | opt.set.tab[i].limit = q->limit; |
| 343 | opt.set.tab[i].prio = q->prio; |
| 344 | opt.set.tab[i].min = q->parms.qth_min >> q->parms.Wlog; |
| 345 | opt.set.tab[i].max = q->parms.qth_max >> q->parms.Wlog; |
| 346 | opt.set.tab[i].is_ecn = gred_use_ecn(q); |
| 347 | opt.set.tab[i].is_harddrop = gred_use_harddrop(q); |
| 348 | opt.set.tab[i].probability = q->parms.max_P; |
| 349 | opt.set.tab[i].backlog = &q->backlog; |
| 350 | } |
| 351 | opt.set.qstats = &sch->qstats; |
| 352 | } |
| 353 | |
| 354 | dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_GRED, &opt); |
| 355 | } |
| 356 | |
Jakub Kicinski | e49efd5 | 2018-11-19 15:21:43 -0800 | [diff] [blame] | 357 | static int gred_offload_dump_stats(struct Qdisc *sch) |
| 358 | { |
| 359 | struct gred_sched *table = qdisc_priv(sch); |
| 360 | struct tc_gred_qopt_offload *hw_stats; |
| 361 | unsigned int i; |
| 362 | int ret; |
| 363 | |
| 364 | hw_stats = kzalloc(sizeof(*hw_stats), GFP_KERNEL); |
| 365 | if (!hw_stats) |
| 366 | return -ENOMEM; |
| 367 | |
| 368 | hw_stats->command = TC_GRED_STATS; |
| 369 | hw_stats->handle = sch->handle; |
| 370 | hw_stats->parent = sch->parent; |
| 371 | |
| 372 | for (i = 0; i < MAX_DPs; i++) |
| 373 | if (table->tab[i]) |
| 374 | hw_stats->stats.xstats[i] = &table->tab[i]->stats; |
| 375 | |
| 376 | ret = qdisc_offload_dump_helper(sch, TC_SETUP_QDISC_GRED, hw_stats); |
| 377 | /* Even if driver returns failure adjust the stats - in case offload |
| 378 | * ended but driver still wants to adjust the values. |
| 379 | */ |
| 380 | for (i = 0; i < MAX_DPs; i++) { |
| 381 | if (!table->tab[i]) |
| 382 | continue; |
| 383 | table->tab[i]->packetsin += hw_stats->stats.bstats[i].packets; |
| 384 | table->tab[i]->bytesin += hw_stats->stats.bstats[i].bytes; |
| 385 | table->tab[i]->backlog += hw_stats->stats.qstats[i].backlog; |
| 386 | |
| 387 | _bstats_update(&sch->bstats, |
| 388 | hw_stats->stats.bstats[i].bytes, |
| 389 | hw_stats->stats.bstats[i].packets); |
| 390 | sch->qstats.qlen += hw_stats->stats.qstats[i].qlen; |
| 391 | sch->qstats.backlog += hw_stats->stats.qstats[i].backlog; |
| 392 | sch->qstats.drops += hw_stats->stats.qstats[i].drops; |
| 393 | sch->qstats.requeues += hw_stats->stats.qstats[i].requeues; |
| 394 | sch->qstats.overlimits += hw_stats->stats.qstats[i].overlimits; |
| 395 | } |
| 396 | |
| 397 | kfree(hw_stats); |
| 398 | return ret; |
| 399 | } |
| 400 | |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 401 | static inline void gred_destroy_vq(struct gred_sched_data *q) |
| 402 | { |
| 403 | kfree(q); |
| 404 | } |
| 405 | |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 406 | static int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps, |
| 407 | struct netlink_ext_ack *extack) |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 408 | { |
| 409 | struct gred_sched *table = qdisc_priv(sch); |
| 410 | struct tc_gred_sopt *sopt; |
Jakub Kicinski | 25fc198 | 2018-11-14 22:23:50 -0800 | [diff] [blame] | 411 | bool red_flags_changed; |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 412 | int i; |
| 413 | |
Alexander Aring | ac8ef4a | 2017-12-20 12:35:11 -0500 | [diff] [blame] | 414 | if (!dps) |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 415 | return -EINVAL; |
| 416 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 417 | sopt = nla_data(dps); |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 418 | |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 419 | if (sopt->DPs > MAX_DPs) { |
| 420 | NL_SET_ERR_MSG_MOD(extack, "number of virtual queues too high"); |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 421 | return -EINVAL; |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 422 | } |
| 423 | if (sopt->DPs == 0) { |
| 424 | NL_SET_ERR_MSG_MOD(extack, |
| 425 | "number of virtual queues can't be 0"); |
| 426 | return -EINVAL; |
| 427 | } |
| 428 | if (sopt->def_DP >= sopt->DPs) { |
| 429 | NL_SET_ERR_MSG_MOD(extack, "default virtual queue above virtual queue count"); |
| 430 | return -EINVAL; |
| 431 | } |
Jakub Kicinski | 7211101 | 2018-11-14 22:23:51 -0800 | [diff] [blame] | 432 | if (sopt->flags && gred_per_vq_red_flags_used(table)) { |
| 433 | NL_SET_ERR_MSG_MOD(extack, "can't set per-Qdisc RED flags when per-virtual queue flags are used"); |
| 434 | return -EINVAL; |
| 435 | } |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 436 | |
| 437 | sch_tree_lock(sch); |
| 438 | table->DPs = sopt->DPs; |
| 439 | table->def = sopt->def_DP; |
Jakub Kicinski | 25fc198 | 2018-11-14 22:23:50 -0800 | [diff] [blame] | 440 | red_flags_changed = table->red_flags != sopt->flags; |
Thomas Graf | b38c7ee | 2005-11-05 21:14:27 +0100 | [diff] [blame] | 441 | table->red_flags = sopt->flags; |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 442 | |
| 443 | /* |
| 444 | * Every entry point to GRED is synchronized with the above code |
| 445 | * and the DP is checked against DPs, i.e. shadowed VQs can no |
| 446 | * longer be found so we can unlock right here. |
| 447 | */ |
| 448 | sch_tree_unlock(sch); |
| 449 | |
| 450 | if (sopt->grio) { |
| 451 | gred_enable_rio_mode(table); |
| 452 | gred_disable_wred_mode(table); |
| 453 | if (gred_wred_mode_check(sch)) |
| 454 | gred_enable_wred_mode(table); |
| 455 | } else { |
| 456 | gred_disable_rio_mode(table); |
| 457 | gred_disable_wred_mode(table); |
| 458 | } |
| 459 | |
Jakub Kicinski | 25fc198 | 2018-11-14 22:23:50 -0800 | [diff] [blame] | 460 | if (red_flags_changed) |
| 461 | for (i = 0; i < table->DPs; i++) |
| 462 | if (table->tab[i]) |
| 463 | table->tab[i]->red_flags = |
| 464 | table->red_flags & GRED_VQ_RED_FLAGS; |
| 465 | |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 466 | for (i = table->DPs; i < MAX_DPs; i++) { |
| 467 | if (table->tab[i]) { |
Yang Yingliang | c17988a | 2013-12-23 17:38:58 +0800 | [diff] [blame] | 468 | pr_warn("GRED: Warning: Destroying shadowed VQ 0x%x\n", |
| 469 | i); |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 470 | gred_destroy_vq(table->tab[i]); |
| 471 | table->tab[i] = NULL; |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 472 | } |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 473 | } |
| 474 | |
Jakub Kicinski | 890d8d2 | 2018-11-19 15:21:42 -0800 | [diff] [blame] | 475 | gred_offload(sch, TC_GRED_REPLACE); |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 476 | return 0; |
| 477 | } |
| 478 | |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 479 | static inline int gred_change_vq(struct Qdisc *sch, int dp, |
Eric Dumazet | a73ed26 | 2011-12-09 02:46:45 +0000 | [diff] [blame] | 480 | struct tc_gred_qopt *ctl, int prio, |
Eric Dumazet | 869aa41 | 2011-12-15 22:09:45 +0000 | [diff] [blame] | 481 | u8 *stab, u32 max_P, |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 482 | struct gred_sched_data **prealloc, |
| 483 | struct netlink_ext_ack *extack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | { |
| 485 | struct gred_sched *table = qdisc_priv(sch); |
Eric Dumazet | 869aa41 | 2011-12-15 22:09:45 +0000 | [diff] [blame] | 486 | struct gred_sched_data *q = table->tab[dp]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 488 | if (!red_check_params(ctl->qth_min, ctl->qth_max, ctl->Wlog)) { |
| 489 | NL_SET_ERR_MSG_MOD(extack, "invalid RED parameters"); |
Nogah Frankel | 8afa10c | 2017-12-04 13:31:11 +0200 | [diff] [blame] | 490 | return -EINVAL; |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 491 | } |
Nogah Frankel | 8afa10c | 2017-12-04 13:31:11 +0200 | [diff] [blame] | 492 | |
Eric Dumazet | 869aa41 | 2011-12-15 22:09:45 +0000 | [diff] [blame] | 493 | if (!q) { |
| 494 | table->tab[dp] = q = *prealloc; |
| 495 | *prealloc = NULL; |
| 496 | if (!q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | return -ENOMEM; |
Jakub Kicinski | 25fc198 | 2018-11-14 22:23:50 -0800 | [diff] [blame] | 498 | q->red_flags = table->red_flags & GRED_VQ_RED_FLAGS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 501 | q->DP = dp; |
| 502 | q->prio = prio; |
David Ward | a3eb95f | 2015-05-09 22:01:46 -0400 | [diff] [blame] | 503 | if (ctl->limit > sch->limit) |
| 504 | q->limit = sch->limit; |
| 505 | else |
| 506 | q->limit = ctl->limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 508 | if (q->backlog == 0) |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 509 | red_end_of_idle_period(&q->vars); |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 510 | |
| 511 | red_set_parms(&q->parms, |
| 512 | ctl->qth_min, ctl->qth_max, ctl->Wlog, ctl->Plog, |
Eric Dumazet | a73ed26 | 2011-12-09 02:46:45 +0000 | [diff] [blame] | 513 | ctl->Scell_log, stab, max_P); |
Eric Dumazet | eeca668 | 2012-01-05 02:25:16 +0000 | [diff] [blame] | 514 | red_set_vars(&q->vars); |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 515 | return 0; |
| 516 | } |
| 517 | |
Jakub Kicinski | 7211101 | 2018-11-14 22:23:51 -0800 | [diff] [blame] | 518 | static const struct nla_policy gred_vq_policy[TCA_GRED_VQ_MAX + 1] = { |
| 519 | [TCA_GRED_VQ_DP] = { .type = NLA_U32 }, |
| 520 | [TCA_GRED_VQ_FLAGS] = { .type = NLA_U32 }, |
| 521 | }; |
| 522 | |
| 523 | static const struct nla_policy gred_vqe_policy[TCA_GRED_VQ_ENTRY_MAX + 1] = { |
| 524 | [TCA_GRED_VQ_ENTRY] = { .type = NLA_NESTED }, |
| 525 | }; |
| 526 | |
Patrick McHardy | 27a3421 | 2008-01-23 20:35:39 -0800 | [diff] [blame] | 527 | static const struct nla_policy gred_policy[TCA_GRED_MAX + 1] = { |
| 528 | [TCA_GRED_PARMS] = { .len = sizeof(struct tc_gred_qopt) }, |
| 529 | [TCA_GRED_STAB] = { .len = 256 }, |
| 530 | [TCA_GRED_DPS] = { .len = sizeof(struct tc_gred_sopt) }, |
Eric Dumazet | a73ed26 | 2011-12-09 02:46:45 +0000 | [diff] [blame] | 531 | [TCA_GRED_MAX_P] = { .type = NLA_U32 }, |
David Ward | a3eb95f | 2015-05-09 22:01:46 -0400 | [diff] [blame] | 532 | [TCA_GRED_LIMIT] = { .type = NLA_U32 }, |
Jakub Kicinski | 7211101 | 2018-11-14 22:23:51 -0800 | [diff] [blame] | 533 | [TCA_GRED_VQ_LIST] = { .type = NLA_NESTED }, |
Patrick McHardy | 27a3421 | 2008-01-23 20:35:39 -0800 | [diff] [blame] | 534 | }; |
| 535 | |
Jakub Kicinski | 7211101 | 2018-11-14 22:23:51 -0800 | [diff] [blame] | 536 | static void gred_vq_apply(struct gred_sched *table, const struct nlattr *entry) |
| 537 | { |
| 538 | struct nlattr *tb[TCA_GRED_VQ_MAX + 1]; |
| 539 | u32 dp; |
| 540 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame^] | 541 | nla_parse_nested_deprecated(tb, TCA_GRED_VQ_MAX, entry, |
| 542 | gred_vq_policy, NULL); |
Jakub Kicinski | 7211101 | 2018-11-14 22:23:51 -0800 | [diff] [blame] | 543 | |
| 544 | dp = nla_get_u32(tb[TCA_GRED_VQ_DP]); |
| 545 | |
| 546 | if (tb[TCA_GRED_VQ_FLAGS]) |
| 547 | table->tab[dp]->red_flags = nla_get_u32(tb[TCA_GRED_VQ_FLAGS]); |
| 548 | } |
| 549 | |
| 550 | static void gred_vqs_apply(struct gred_sched *table, struct nlattr *vqs) |
| 551 | { |
| 552 | const struct nlattr *attr; |
| 553 | int rem; |
| 554 | |
| 555 | nla_for_each_nested(attr, vqs, rem) { |
| 556 | switch (nla_type(attr)) { |
| 557 | case TCA_GRED_VQ_ENTRY: |
| 558 | gred_vq_apply(table, attr); |
| 559 | break; |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | static int gred_vq_validate(struct gred_sched *table, u32 cdp, |
| 565 | const struct nlattr *entry, |
| 566 | struct netlink_ext_ack *extack) |
| 567 | { |
| 568 | struct nlattr *tb[TCA_GRED_VQ_MAX + 1]; |
| 569 | int err; |
| 570 | u32 dp; |
| 571 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame^] | 572 | err = nla_parse_nested_deprecated(tb, TCA_GRED_VQ_MAX, entry, |
| 573 | gred_vq_policy, extack); |
Jakub Kicinski | 7211101 | 2018-11-14 22:23:51 -0800 | [diff] [blame] | 574 | if (err < 0) |
| 575 | return err; |
| 576 | |
| 577 | if (!tb[TCA_GRED_VQ_DP]) { |
| 578 | NL_SET_ERR_MSG_MOD(extack, "Virtual queue with no index specified"); |
| 579 | return -EINVAL; |
| 580 | } |
| 581 | dp = nla_get_u32(tb[TCA_GRED_VQ_DP]); |
| 582 | if (dp >= table->DPs) { |
| 583 | NL_SET_ERR_MSG_MOD(extack, "Virtual queue with index out of bounds"); |
| 584 | return -EINVAL; |
| 585 | } |
| 586 | if (dp != cdp && !table->tab[dp]) { |
| 587 | NL_SET_ERR_MSG_MOD(extack, "Virtual queue not yet instantiated"); |
| 588 | return -EINVAL; |
| 589 | } |
| 590 | |
| 591 | if (tb[TCA_GRED_VQ_FLAGS]) { |
| 592 | u32 red_flags = nla_get_u32(tb[TCA_GRED_VQ_FLAGS]); |
| 593 | |
| 594 | if (table->red_flags && table->red_flags != red_flags) { |
| 595 | NL_SET_ERR_MSG_MOD(extack, "can't change per-virtual queue RED flags when per-Qdisc flags are used"); |
| 596 | return -EINVAL; |
| 597 | } |
| 598 | if (red_flags & ~GRED_VQ_RED_FLAGS) { |
| 599 | NL_SET_ERR_MSG_MOD(extack, |
| 600 | "invalid RED flags specified"); |
| 601 | return -EINVAL; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | static int gred_vqs_validate(struct gred_sched *table, u32 cdp, |
| 609 | struct nlattr *vqs, struct netlink_ext_ack *extack) |
| 610 | { |
| 611 | const struct nlattr *attr; |
| 612 | int rem, err; |
| 613 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame^] | 614 | err = nla_validate_nested_deprecated(vqs, TCA_GRED_VQ_ENTRY_MAX, |
| 615 | gred_vqe_policy, extack); |
Jakub Kicinski | 7211101 | 2018-11-14 22:23:51 -0800 | [diff] [blame] | 616 | if (err < 0) |
| 617 | return err; |
| 618 | |
| 619 | nla_for_each_nested(attr, vqs, rem) { |
| 620 | switch (nla_type(attr)) { |
| 621 | case TCA_GRED_VQ_ENTRY: |
| 622 | err = gred_vq_validate(table, cdp, attr, extack); |
| 623 | if (err) |
| 624 | return err; |
| 625 | break; |
| 626 | default: |
| 627 | NL_SET_ERR_MSG_MOD(extack, "GRED_VQ_LIST can contain only entry attributes"); |
| 628 | return -EINVAL; |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | if (rem > 0) { |
| 633 | NL_SET_ERR_MSG_MOD(extack, "Trailing data after parsing virtual queue list"); |
| 634 | return -EINVAL; |
| 635 | } |
| 636 | |
| 637 | return 0; |
| 638 | } |
| 639 | |
Alexander Aring | 2030721 | 2017-12-20 12:35:14 -0500 | [diff] [blame] | 640 | static int gred_change(struct Qdisc *sch, struct nlattr *opt, |
| 641 | struct netlink_ext_ack *extack) |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 642 | { |
| 643 | struct gred_sched *table = qdisc_priv(sch); |
| 644 | struct tc_gred_qopt *ctl; |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 645 | struct nlattr *tb[TCA_GRED_MAX + 1]; |
Patrick McHardy | cee6372 | 2008-01-23 20:33:32 -0800 | [diff] [blame] | 646 | int err, prio = GRED_DEF_PRIO; |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 647 | u8 *stab; |
Eric Dumazet | a73ed26 | 2011-12-09 02:46:45 +0000 | [diff] [blame] | 648 | u32 max_P; |
Eric Dumazet | 869aa41 | 2011-12-15 22:09:45 +0000 | [diff] [blame] | 649 | struct gred_sched_data *prealloc; |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 650 | |
Patrick McHardy | cee6372 | 2008-01-23 20:33:32 -0800 | [diff] [blame] | 651 | if (opt == NULL) |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 652 | return -EINVAL; |
| 653 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame^] | 654 | err = nla_parse_nested_deprecated(tb, TCA_GRED_MAX, opt, gred_policy, |
| 655 | extack); |
Patrick McHardy | cee6372 | 2008-01-23 20:33:32 -0800 | [diff] [blame] | 656 | if (err < 0) |
| 657 | return err; |
| 658 | |
David Ward | a3eb95f | 2015-05-09 22:01:46 -0400 | [diff] [blame] | 659 | if (tb[TCA_GRED_PARMS] == NULL && tb[TCA_GRED_STAB] == NULL) { |
| 660 | if (tb[TCA_GRED_LIMIT] != NULL) |
| 661 | sch->limit = nla_get_u32(tb[TCA_GRED_LIMIT]); |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 662 | return gred_change_table_def(sch, tb[TCA_GRED_DPS], extack); |
David Ward | a3eb95f | 2015-05-09 22:01:46 -0400 | [diff] [blame] | 663 | } |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 664 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 665 | if (tb[TCA_GRED_PARMS] == NULL || |
David Ward | a3eb95f | 2015-05-09 22:01:46 -0400 | [diff] [blame] | 666 | tb[TCA_GRED_STAB] == NULL || |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 667 | tb[TCA_GRED_LIMIT] != NULL) { |
| 668 | NL_SET_ERR_MSG_MOD(extack, "can't configure Qdisc and virtual queue at the same time"); |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 669 | return -EINVAL; |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 670 | } |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 671 | |
Eric Dumazet | a73ed26 | 2011-12-09 02:46:45 +0000 | [diff] [blame] | 672 | max_P = tb[TCA_GRED_MAX_P] ? nla_get_u32(tb[TCA_GRED_MAX_P]) : 0; |
| 673 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 674 | ctl = nla_data(tb[TCA_GRED_PARMS]); |
| 675 | stab = nla_data(tb[TCA_GRED_STAB]); |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 676 | |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 677 | if (ctl->DP >= table->DPs) { |
| 678 | NL_SET_ERR_MSG_MOD(extack, "virtual queue index above virtual queue count"); |
Jakub Kicinski | 255f480 | 2018-11-14 22:23:45 -0800 | [diff] [blame] | 679 | return -EINVAL; |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 680 | } |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 681 | |
Jakub Kicinski | 7211101 | 2018-11-14 22:23:51 -0800 | [diff] [blame] | 682 | if (tb[TCA_GRED_VQ_LIST]) { |
| 683 | err = gred_vqs_validate(table, ctl->DP, tb[TCA_GRED_VQ_LIST], |
| 684 | extack); |
| 685 | if (err) |
| 686 | return err; |
| 687 | } |
| 688 | |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 689 | if (gred_rio_mode(table)) { |
| 690 | if (ctl->prio == 0) { |
| 691 | int def_prio = GRED_DEF_PRIO; |
| 692 | |
| 693 | if (table->tab[table->def]) |
| 694 | def_prio = table->tab[table->def]->prio; |
| 695 | |
| 696 | printk(KERN_DEBUG "GRED: DP %u does not have a prio " |
| 697 | "setting default to %d\n", ctl->DP, def_prio); |
| 698 | |
| 699 | prio = def_prio; |
| 700 | } else |
| 701 | prio = ctl->prio; |
| 702 | } |
| 703 | |
Eric Dumazet | 869aa41 | 2011-12-15 22:09:45 +0000 | [diff] [blame] | 704 | prealloc = kzalloc(sizeof(*prealloc), GFP_KERNEL); |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 705 | sch_tree_lock(sch); |
| 706 | |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 707 | err = gred_change_vq(sch, ctl->DP, ctl, prio, stab, max_P, &prealloc, |
| 708 | extack); |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 709 | if (err < 0) |
Jakub Kicinski | 255f480 | 2018-11-14 22:23:45 -0800 | [diff] [blame] | 710 | goto err_unlock_free; |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 711 | |
Jakub Kicinski | 7211101 | 2018-11-14 22:23:51 -0800 | [diff] [blame] | 712 | if (tb[TCA_GRED_VQ_LIST]) |
| 713 | gred_vqs_apply(table, tb[TCA_GRED_VQ_LIST]); |
| 714 | |
Thomas Graf | d6fd4e9 | 2005-11-05 21:14:10 +0100 | [diff] [blame] | 715 | if (gred_rio_mode(table)) { |
Thomas Graf | dea3f62 | 2005-11-05 21:14:09 +0100 | [diff] [blame] | 716 | gred_disable_wred_mode(table); |
| 717 | if (gred_wred_mode_check(sch)) |
| 718 | gred_enable_wred_mode(table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 721 | sch_tree_unlock(sch); |
Eric Dumazet | 869aa41 | 2011-12-15 22:09:45 +0000 | [diff] [blame] | 722 | kfree(prealloc); |
Jakub Kicinski | 890d8d2 | 2018-11-19 15:21:42 -0800 | [diff] [blame] | 723 | |
| 724 | gred_offload(sch, TC_GRED_REPLACE); |
Jakub Kicinski | 255f480 | 2018-11-14 22:23:45 -0800 | [diff] [blame] | 725 | return 0; |
| 726 | |
| 727 | err_unlock_free: |
| 728 | sch_tree_unlock(sch); |
| 729 | kfree(prealloc); |
Thomas Graf | f62d6b9 | 2005-11-05 21:14:15 +0100 | [diff] [blame] | 730 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Alexander Aring | e63d7df | 2017-12-20 12:35:13 -0500 | [diff] [blame] | 733 | static int gred_init(struct Qdisc *sch, struct nlattr *opt, |
| 734 | struct netlink_ext_ack *extack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | { |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 736 | struct nlattr *tb[TCA_GRED_MAX + 1]; |
Patrick McHardy | cee6372 | 2008-01-23 20:33:32 -0800 | [diff] [blame] | 737 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Alexander Aring | ac8ef4a | 2017-12-20 12:35:11 -0500 | [diff] [blame] | 739 | if (!opt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | return -EINVAL; |
| 741 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame^] | 742 | err = nla_parse_nested_deprecated(tb, TCA_GRED_MAX, opt, gred_policy, |
| 743 | extack); |
Patrick McHardy | cee6372 | 2008-01-23 20:33:32 -0800 | [diff] [blame] | 744 | if (err < 0) |
| 745 | return err; |
| 746 | |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 747 | if (tb[TCA_GRED_PARMS] || tb[TCA_GRED_STAB]) { |
| 748 | NL_SET_ERR_MSG_MOD(extack, |
| 749 | "virtual queue configuration can't be specified at initialization time"); |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 750 | return -EINVAL; |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 751 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
David Ward | a3eb95f | 2015-05-09 22:01:46 -0400 | [diff] [blame] | 753 | if (tb[TCA_GRED_LIMIT]) |
| 754 | sch->limit = nla_get_u32(tb[TCA_GRED_LIMIT]); |
Phil Sutter | 348e343 | 2015-08-18 10:30:49 +0200 | [diff] [blame] | 755 | else |
| 756 | sch->limit = qdisc_dev(sch)->tx_queue_len |
| 757 | * psched_mtu(qdisc_dev(sch)); |
David Ward | a3eb95f | 2015-05-09 22:01:46 -0400 | [diff] [blame] | 758 | |
Jakub Kicinski | 4777be0 | 2018-11-14 22:23:47 -0800 | [diff] [blame] | 759 | return gred_change_table_def(sch, tb[TCA_GRED_DPS], extack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | static int gred_dump(struct Qdisc *sch, struct sk_buff *skb) |
| 763 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | struct gred_sched *table = qdisc_priv(sch); |
Jakub Kicinski | 80e22e9 | 2018-11-14 22:23:49 -0800 | [diff] [blame] | 765 | struct nlattr *parms, *vqs, *opts = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | int i; |
Eric Dumazet | a73ed26 | 2011-12-09 02:46:45 +0000 | [diff] [blame] | 767 | u32 max_p[MAX_DPs]; |
Thomas Graf | e063682 | 2005-11-05 21:14:12 +0100 | [diff] [blame] | 768 | struct tc_gred_sopt sopt = { |
| 769 | .DPs = table->DPs, |
| 770 | .def_DP = table->def, |
| 771 | .grio = gred_rio_mode(table), |
Thomas Graf | b38c7ee | 2005-11-05 21:14:27 +0100 | [diff] [blame] | 772 | .flags = table->red_flags, |
Thomas Graf | e063682 | 2005-11-05 21:14:12 +0100 | [diff] [blame] | 773 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Jakub Kicinski | e49efd5 | 2018-11-19 15:21:43 -0800 | [diff] [blame] | 775 | if (gred_offload_dump_stats(sch)) |
| 776 | goto nla_put_failure; |
| 777 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 778 | opts = nla_nest_start_noflag(skb, TCA_OPTIONS); |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 779 | if (opts == NULL) |
| 780 | goto nla_put_failure; |
David S. Miller | 1b34ec4 | 2012-03-29 05:11:39 -0400 | [diff] [blame] | 781 | if (nla_put(skb, TCA_GRED_DPS, sizeof(sopt), &sopt)) |
| 782 | goto nla_put_failure; |
Eric Dumazet | a73ed26 | 2011-12-09 02:46:45 +0000 | [diff] [blame] | 783 | |
| 784 | for (i = 0; i < MAX_DPs; i++) { |
| 785 | struct gred_sched_data *q = table->tab[i]; |
| 786 | |
| 787 | max_p[i] = q ? q->parms.max_P : 0; |
| 788 | } |
David S. Miller | 1b34ec4 | 2012-03-29 05:11:39 -0400 | [diff] [blame] | 789 | if (nla_put(skb, TCA_GRED_MAX_P, sizeof(max_p), max_p)) |
| 790 | goto nla_put_failure; |
Eric Dumazet | a73ed26 | 2011-12-09 02:46:45 +0000 | [diff] [blame] | 791 | |
David Ward | a3eb95f | 2015-05-09 22:01:46 -0400 | [diff] [blame] | 792 | if (nla_put_u32(skb, TCA_GRED_LIMIT, sch->limit)) |
| 793 | goto nla_put_failure; |
| 794 | |
Jakub Kicinski | 80e22e9 | 2018-11-14 22:23:49 -0800 | [diff] [blame] | 795 | /* Old style all-in-one dump of VQs */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 796 | parms = nla_nest_start_noflag(skb, TCA_GRED_PARMS); |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 797 | if (parms == NULL) |
| 798 | goto nla_put_failure; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
Thomas Graf | 05f1cc0 | 2005-11-05 21:14:11 +0100 | [diff] [blame] | 800 | for (i = 0; i < MAX_DPs; i++) { |
| 801 | struct gred_sched_data *q = table->tab[i]; |
| 802 | struct tc_gred_qopt opt; |
David Ward | 1fe37b1 | 2012-09-13 05:22:34 +0000 | [diff] [blame] | 803 | unsigned long qavg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
Thomas Graf | 05f1cc0 | 2005-11-05 21:14:11 +0100 | [diff] [blame] | 805 | memset(&opt, 0, sizeof(opt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
| 807 | if (!q) { |
| 808 | /* hack -- fix at some point with proper message |
| 809 | This is how we indicate to tc that there is no VQ |
| 810 | at this DP */ |
| 811 | |
Thomas Graf | 05f1cc0 | 2005-11-05 21:14:11 +0100 | [diff] [blame] | 812 | opt.DP = MAX_DPs + i; |
| 813 | goto append_opt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Thomas Graf | 05f1cc0 | 2005-11-05 21:14:11 +0100 | [diff] [blame] | 816 | opt.limit = q->limit; |
| 817 | opt.DP = q->DP; |
David Ward | 145a42b | 2015-05-09 22:01:47 -0400 | [diff] [blame] | 818 | opt.backlog = gred_backlog(table, q, sch); |
Thomas Graf | 05f1cc0 | 2005-11-05 21:14:11 +0100 | [diff] [blame] | 819 | opt.prio = q->prio; |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 820 | opt.qth_min = q->parms.qth_min >> q->parms.Wlog; |
| 821 | opt.qth_max = q->parms.qth_max >> q->parms.Wlog; |
| 822 | opt.Wlog = q->parms.Wlog; |
| 823 | opt.Plog = q->parms.Plog; |
| 824 | opt.Scell_log = q->parms.Scell_log; |
| 825 | opt.other = q->stats.other; |
| 826 | opt.early = q->stats.prob_drop; |
| 827 | opt.forced = q->stats.forced_drop; |
| 828 | opt.pdrop = q->stats.pdrop; |
Thomas Graf | 05f1cc0 | 2005-11-05 21:14:11 +0100 | [diff] [blame] | 829 | opt.packets = q->packetsin; |
| 830 | opt.bytesin = q->bytesin; |
| 831 | |
David Ward | 244b65d | 2012-04-15 12:31:45 +0000 | [diff] [blame] | 832 | if (gred_wred_mode(table)) |
| 833 | gred_load_wred_set(table, q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
David Ward | 1fe37b1 | 2012-09-13 05:22:34 +0000 | [diff] [blame] | 835 | qavg = red_calc_qavg(&q->parms, &q->vars, |
| 836 | q->vars.qavg >> q->parms.Wlog); |
| 837 | opt.qave = qavg >> q->parms.Wlog; |
Thomas Graf | 22b3342 | 2005-11-05 21:14:16 +0100 | [diff] [blame] | 838 | |
Thomas Graf | 05f1cc0 | 2005-11-05 21:14:11 +0100 | [diff] [blame] | 839 | append_opt: |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 840 | if (nla_append(skb, sizeof(opt), &opt) < 0) |
| 841 | goto nla_put_failure; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 844 | nla_nest_end(skb, parms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | |
Jakub Kicinski | 80e22e9 | 2018-11-14 22:23:49 -0800 | [diff] [blame] | 846 | /* Dump the VQs again, in more structured way */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 847 | vqs = nla_nest_start_noflag(skb, TCA_GRED_VQ_LIST); |
Jakub Kicinski | 80e22e9 | 2018-11-14 22:23:49 -0800 | [diff] [blame] | 848 | if (!vqs) |
| 849 | goto nla_put_failure; |
| 850 | |
| 851 | for (i = 0; i < MAX_DPs; i++) { |
| 852 | struct gred_sched_data *q = table->tab[i]; |
| 853 | struct nlattr *vq; |
| 854 | |
| 855 | if (!q) |
| 856 | continue; |
| 857 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 858 | vq = nla_nest_start_noflag(skb, TCA_GRED_VQ_ENTRY); |
Jakub Kicinski | 80e22e9 | 2018-11-14 22:23:49 -0800 | [diff] [blame] | 859 | if (!vq) |
| 860 | goto nla_put_failure; |
| 861 | |
| 862 | if (nla_put_u32(skb, TCA_GRED_VQ_DP, q->DP)) |
| 863 | goto nla_put_failure; |
| 864 | |
Jakub Kicinski | 7211101 | 2018-11-14 22:23:51 -0800 | [diff] [blame] | 865 | if (nla_put_u32(skb, TCA_GRED_VQ_FLAGS, q->red_flags)) |
| 866 | goto nla_put_failure; |
| 867 | |
Jakub Kicinski | 80e22e9 | 2018-11-14 22:23:49 -0800 | [diff] [blame] | 868 | /* Stats */ |
| 869 | if (nla_put_u64_64bit(skb, TCA_GRED_VQ_STAT_BYTES, q->bytesin, |
| 870 | TCA_GRED_VQ_PAD)) |
| 871 | goto nla_put_failure; |
| 872 | if (nla_put_u32(skb, TCA_GRED_VQ_STAT_PACKETS, q->packetsin)) |
| 873 | goto nla_put_failure; |
| 874 | if (nla_put_u32(skb, TCA_GRED_VQ_STAT_BACKLOG, |
| 875 | gred_backlog(table, q, sch))) |
| 876 | goto nla_put_failure; |
| 877 | if (nla_put_u32(skb, TCA_GRED_VQ_STAT_PROB_DROP, |
| 878 | q->stats.prob_drop)) |
| 879 | goto nla_put_failure; |
| 880 | if (nla_put_u32(skb, TCA_GRED_VQ_STAT_PROB_MARK, |
| 881 | q->stats.prob_mark)) |
| 882 | goto nla_put_failure; |
| 883 | if (nla_put_u32(skb, TCA_GRED_VQ_STAT_FORCED_DROP, |
| 884 | q->stats.forced_drop)) |
| 885 | goto nla_put_failure; |
| 886 | if (nla_put_u32(skb, TCA_GRED_VQ_STAT_FORCED_MARK, |
| 887 | q->stats.forced_mark)) |
| 888 | goto nla_put_failure; |
| 889 | if (nla_put_u32(skb, TCA_GRED_VQ_STAT_PDROP, q->stats.pdrop)) |
| 890 | goto nla_put_failure; |
| 891 | if (nla_put_u32(skb, TCA_GRED_VQ_STAT_OTHER, q->stats.other)) |
| 892 | goto nla_put_failure; |
| 893 | |
| 894 | nla_nest_end(skb, vq); |
| 895 | } |
| 896 | nla_nest_end(skb, vqs); |
| 897 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 898 | return nla_nest_end(skb, opts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 900 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 901 | nla_nest_cancel(skb, opts); |
| 902 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | static void gred_destroy(struct Qdisc *sch) |
| 906 | { |
| 907 | struct gred_sched *table = qdisc_priv(sch); |
| 908 | int i; |
| 909 | |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 910 | for (i = 0; i < table->DPs; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | if (table->tab[i]) |
Thomas Graf | 6639607 | 2005-11-05 21:14:13 +0100 | [diff] [blame] | 912 | gred_destroy_vq(table->tab[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
Jakub Kicinski | 890d8d2 | 2018-11-19 15:21:42 -0800 | [diff] [blame] | 914 | gred_offload(sch, TC_GRED_DESTROY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Eric Dumazet | 20fea08 | 2007-11-14 01:44:41 -0800 | [diff] [blame] | 917 | static struct Qdisc_ops gred_qdisc_ops __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | .id = "gred", |
| 919 | .priv_size = sizeof(struct gred_sched), |
| 920 | .enqueue = gred_enqueue, |
| 921 | .dequeue = gred_dequeue, |
Jarek Poplawski | 8e3af97 | 2008-10-31 00:45:55 -0700 | [diff] [blame] | 922 | .peek = qdisc_peek_head, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | .init = gred_init, |
| 924 | .reset = gred_reset, |
| 925 | .destroy = gred_destroy, |
| 926 | .change = gred_change, |
| 927 | .dump = gred_dump, |
| 928 | .owner = THIS_MODULE, |
| 929 | }; |
| 930 | |
| 931 | static int __init gred_module_init(void) |
| 932 | { |
| 933 | return register_qdisc(&gred_qdisc_ops); |
| 934 | } |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 935 | |
| 936 | static void __exit gred_module_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | { |
| 938 | unregister_qdisc(&gred_qdisc_ops); |
| 939 | } |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | module_init(gred_module_init) |
| 942 | module_exit(gred_module_exit) |
Thomas Graf | 1e4dfaf9 | 2005-11-05 21:14:25 +0100 | [diff] [blame] | 943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | MODULE_LICENSE("GPL"); |