Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004, Instant802 Networks, Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/netdevice.h> |
| 10 | #include <linux/skbuff.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/if_arp.h> |
| 13 | #include <linux/types.h> |
| 14 | #include <net/ip.h> |
| 15 | #include <net/pkt_sched.h> |
| 16 | |
| 17 | #include <net/mac80211.h> |
| 18 | #include "ieee80211_i.h" |
| 19 | #include "wme.h" |
| 20 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 21 | /* maximum number of hardware queues we support. */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 22 | #define QD_MAX_QUEUES (IEEE80211_MAX_AMPDU_QUEUES + IEEE80211_MAX_QUEUES) |
| 23 | /* current number of hardware queues we support. */ |
| 24 | #define QD_NUM(hw) ((hw)->queues + (hw)->ampdu_queues) |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 25 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 26 | /* |
| 27 | * Default mapping in classifier to work with default |
| 28 | * queue setup. |
| 29 | */ |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 30 | const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 }; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 31 | |
| 32 | struct ieee80211_sched_data |
| 33 | { |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 34 | unsigned long qdisc_pool[BITS_TO_LONGS(QD_MAX_QUEUES)]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 35 | struct tcf_proto *filter_list; |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 36 | struct Qdisc *queues[QD_MAX_QUEUES]; |
| 37 | struct sk_buff_head requeued[QD_MAX_QUEUES]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Guy Cohen | a8bdf29 | 2008-01-09 19:12:48 +0200 | [diff] [blame] | 40 | static const char llc_ip_hdr[8] = {0xAA, 0xAA, 0x3, 0, 0, 0, 0x08, 0}; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 41 | |
| 42 | /* given a data frame determine the 802.1p/1d tag to use */ |
| 43 | static inline unsigned classify_1d(struct sk_buff *skb, struct Qdisc *qd) |
| 44 | { |
| 45 | struct iphdr *ip; |
| 46 | int dscp; |
| 47 | int offset; |
| 48 | |
| 49 | struct ieee80211_sched_data *q = qdisc_priv(qd); |
| 50 | struct tcf_result res = { -1, 0 }; |
| 51 | |
| 52 | /* if there is a user set filter list, call out to that */ |
| 53 | if (q->filter_list) { |
| 54 | tc_classify(skb, q->filter_list, &res); |
| 55 | if (res.class != -1) |
| 56 | return res.class; |
| 57 | } |
| 58 | |
| 59 | /* skb->priority values from 256->263 are magic values to |
| 60 | * directly indicate a specific 802.1d priority. |
| 61 | * This is used to allow 802.1d priority to be passed directly in |
| 62 | * from VLAN tags, etc. */ |
| 63 | if (skb->priority >= 256 && skb->priority <= 263) |
| 64 | return skb->priority - 256; |
| 65 | |
| 66 | /* check there is a valid IP header present */ |
Guy Cohen | a8bdf29 | 2008-01-09 19:12:48 +0200 | [diff] [blame] | 67 | offset = ieee80211_get_hdrlen_from_skb(skb); |
| 68 | if (skb->len < offset + sizeof(llc_ip_hdr) + sizeof(*ip) || |
| 69 | memcmp(skb->data + offset, llc_ip_hdr, sizeof(llc_ip_hdr))) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 70 | return 0; |
| 71 | |
Guy Cohen | a8bdf29 | 2008-01-09 19:12:48 +0200 | [diff] [blame] | 72 | ip = (struct iphdr *) (skb->data + offset + sizeof(llc_ip_hdr)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 73 | |
| 74 | dscp = ip->tos & 0xfc; |
| 75 | if (dscp & 0x1c) |
| 76 | return 0; |
| 77 | return dscp >> 5; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | static inline int wme_downgrade_ac(struct sk_buff *skb) |
| 82 | { |
| 83 | switch (skb->priority) { |
| 84 | case 6: |
| 85 | case 7: |
| 86 | skb->priority = 5; /* VO -> VI */ |
| 87 | return 0; |
| 88 | case 4: |
| 89 | case 5: |
| 90 | skb->priority = 3; /* VI -> BE */ |
| 91 | return 0; |
| 92 | case 0: |
| 93 | case 3: |
| 94 | skb->priority = 2; /* BE -> BK */ |
| 95 | return 0; |
| 96 | default: |
| 97 | return -1; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
| 102 | /* positive return value indicates which queue to use |
| 103 | * negative return value indicates to drop the frame */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 104 | static int classify80211(struct sk_buff *skb, struct Qdisc *qd) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 105 | { |
| 106 | struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 107 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 108 | unsigned short fc = le16_to_cpu(hdr->frame_control); |
| 109 | int qos; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 110 | |
| 111 | /* see if frame is data or non data frame */ |
| 112 | if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) { |
| 113 | /* management frames go on AC_VO queue, but are sent |
| 114 | * without QoS control fields */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 115 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Johannes Berg | f9d540e | 2007-09-28 14:02:09 +0200 | [diff] [blame] | 118 | if (0 /* injected */) { |
| 119 | /* use AC from radiotap */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /* is this a QoS frame? */ |
| 123 | qos = fc & IEEE80211_STYPE_QOS_DATA; |
| 124 | |
| 125 | if (!qos) { |
| 126 | skb->priority = 0; /* required for correct WPA/11i MIC */ |
| 127 | return ieee802_1d_to_ac[skb->priority]; |
| 128 | } |
| 129 | |
| 130 | /* use the data classifier to determine what 802.1d tag the |
Johannes Berg | 3c3b00c | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 131 | * data frame has */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 132 | skb->priority = classify_1d(skb, qd); |
| 133 | |
Johannes Berg | 3c3b00c | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 134 | /* in case we are a client verify acm is not set for this ac */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 135 | while (unlikely(local->wmm_acm & BIT(skb->priority))) { |
| 136 | if (wme_downgrade_ac(skb)) { |
Johannes Berg | 3c3b00c | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 137 | /* No AC with lower priority has acm=0, drop packet. */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 138 | return -1; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /* look up which queue to use for frames with this 1d tag */ |
| 143 | return ieee802_1d_to_ac[skb->priority]; |
| 144 | } |
| 145 | |
| 146 | |
| 147 | static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd) |
| 148 | { |
| 149 | struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr); |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 150 | struct ieee80211_hw *hw = &local->hw; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 151 | struct ieee80211_sched_data *q = qdisc_priv(qd); |
| 152 | struct ieee80211_tx_packet_data *pkt_data = |
| 153 | (struct ieee80211_tx_packet_data *) skb->cb; |
| 154 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 155 | unsigned short fc = le16_to_cpu(hdr->frame_control); |
| 156 | struct Qdisc *qdisc; |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 157 | struct sta_info *sta; |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 158 | int err; |
| 159 | u16 queue; |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 160 | u8 tid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 161 | |
Jiri Slaby | e8bf964 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 162 | if (pkt_data->flags & IEEE80211_TXPD_REQUEUE) { |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 163 | queue = pkt_data->queue; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 164 | rcu_read_lock(); |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 165 | sta = sta_info_get(local, hdr->addr1); |
| 166 | tid = skb->priority & QOS_CONTROL_TAG1D_MASK; |
| 167 | if (sta) { |
| 168 | int ampdu_queue = sta->tid_to_tx_q[tid]; |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 169 | if ((ampdu_queue < QD_NUM(hw)) && |
Ron Rindjunsky | a9af201 | 2008-01-30 12:58:45 +0200 | [diff] [blame] | 170 | test_bit(ampdu_queue, q->qdisc_pool)) { |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 171 | queue = ampdu_queue; |
| 172 | pkt_data->flags |= IEEE80211_TXPD_AMPDU; |
| 173 | } else { |
| 174 | pkt_data->flags &= ~IEEE80211_TXPD_AMPDU; |
| 175 | } |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 176 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 177 | rcu_read_unlock(); |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 178 | skb_queue_tail(&q->requeued[queue], skb); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 179 | qd->q.qlen++; |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | queue = classify80211(skb, qd); |
| 184 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 185 | if (unlikely(queue >= local->hw.queues)) |
| 186 | queue = local->hw.queues - 1; |
| 187 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 188 | /* now we know the 1d priority, fill in the QoS header if there is one |
| 189 | */ |
| 190 | if (WLAN_FC_IS_QOS_DATA(fc)) { |
| 191 | u8 *p = skb->data + ieee80211_get_hdrlen(fc) - 2; |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 192 | u8 ack_policy = 0; |
| 193 | tid = skb->priority & QOS_CONTROL_TAG1D_MASK; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 194 | if (local->wifi_wme_noack_test) |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 195 | ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK << |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 196 | QOS_CONTROL_ACK_POLICY_SHIFT; |
| 197 | /* qos header is 2 bytes, second reserved */ |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 198 | *p = ack_policy | tid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 199 | p++; |
| 200 | *p = 0; |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 201 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 202 | rcu_read_lock(); |
| 203 | |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 204 | sta = sta_info_get(local, hdr->addr1); |
| 205 | if (sta) { |
| 206 | int ampdu_queue = sta->tid_to_tx_q[tid]; |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 207 | if ((ampdu_queue < QD_NUM(hw)) && |
| 208 | test_bit(ampdu_queue, q->qdisc_pool)) { |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 209 | queue = ampdu_queue; |
| 210 | pkt_data->flags |= IEEE80211_TXPD_AMPDU; |
| 211 | } else { |
| 212 | pkt_data->flags &= ~IEEE80211_TXPD_AMPDU; |
| 213 | } |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 214 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 215 | |
| 216 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 219 | if (unlikely(queue < 0)) { |
| 220 | kfree_skb(skb); |
| 221 | err = NET_XMIT_DROP; |
| 222 | } else { |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 223 | tid = skb->priority & QOS_CONTROL_TAG1D_MASK; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 224 | pkt_data->queue = (unsigned int) queue; |
| 225 | qdisc = q->queues[queue]; |
| 226 | err = qdisc->enqueue(skb, qdisc); |
| 227 | if (err == NET_XMIT_SUCCESS) { |
| 228 | qd->q.qlen++; |
| 229 | qd->bstats.bytes += skb->len; |
| 230 | qd->bstats.packets++; |
| 231 | return NET_XMIT_SUCCESS; |
| 232 | } |
| 233 | } |
| 234 | qd->qstats.drops++; |
| 235 | return err; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /* TODO: clean up the cases where master_hard_start_xmit |
| 240 | * returns non 0 - it shouldn't ever do that. Once done we |
| 241 | * can remove this function */ |
| 242 | static int wme_qdiscop_requeue(struct sk_buff *skb, struct Qdisc* qd) |
| 243 | { |
| 244 | struct ieee80211_sched_data *q = qdisc_priv(qd); |
| 245 | struct ieee80211_tx_packet_data *pkt_data = |
| 246 | (struct ieee80211_tx_packet_data *) skb->cb; |
| 247 | struct Qdisc *qdisc; |
| 248 | int err; |
| 249 | |
| 250 | /* we recorded which queue to use earlier! */ |
| 251 | qdisc = q->queues[pkt_data->queue]; |
| 252 | |
| 253 | if ((err = qdisc->ops->requeue(skb, qdisc)) == 0) { |
| 254 | qd->q.qlen++; |
| 255 | return 0; |
| 256 | } |
| 257 | qd->qstats.drops++; |
| 258 | return err; |
| 259 | } |
| 260 | |
| 261 | |
| 262 | static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd) |
| 263 | { |
| 264 | struct ieee80211_sched_data *q = qdisc_priv(qd); |
| 265 | struct net_device *dev = qd->dev; |
| 266 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 267 | struct ieee80211_hw *hw = &local->hw; |
| 268 | struct sk_buff *skb; |
| 269 | struct Qdisc *qdisc; |
| 270 | int queue; |
| 271 | |
| 272 | /* check all the h/w queues in numeric/priority order */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 273 | for (queue = 0; queue < QD_NUM(hw); queue++) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 274 | /* see if there is room in this hardware queue */ |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 275 | if ((test_bit(IEEE80211_LINK_STATE_XOFF, |
| 276 | &local->state[queue])) || |
| 277 | (test_bit(IEEE80211_LINK_STATE_PENDING, |
| 278 | &local->state[queue])) || |
Ron Rindjunsky | a9af201 | 2008-01-30 12:58:45 +0200 | [diff] [blame] | 279 | (!test_bit(queue, q->qdisc_pool))) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 280 | continue; |
| 281 | |
| 282 | /* there is space - try and get a frame */ |
| 283 | skb = skb_dequeue(&q->requeued[queue]); |
| 284 | if (skb) { |
| 285 | qd->q.qlen--; |
| 286 | return skb; |
| 287 | } |
| 288 | |
| 289 | qdisc = q->queues[queue]; |
| 290 | skb = qdisc->dequeue(qdisc); |
| 291 | if (skb) { |
| 292 | qd->q.qlen--; |
| 293 | return skb; |
| 294 | } |
| 295 | } |
| 296 | /* returning a NULL here when all the h/w queues are full means we |
| 297 | * never need to call netif_stop_queue in the driver */ |
| 298 | return NULL; |
| 299 | } |
| 300 | |
| 301 | |
| 302 | static void wme_qdiscop_reset(struct Qdisc* qd) |
| 303 | { |
| 304 | struct ieee80211_sched_data *q = qdisc_priv(qd); |
| 305 | struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr); |
| 306 | struct ieee80211_hw *hw = &local->hw; |
| 307 | int queue; |
| 308 | |
| 309 | /* QUESTION: should we have some hardware flush functionality here? */ |
| 310 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 311 | for (queue = 0; queue < QD_NUM(hw); queue++) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 312 | skb_queue_purge(&q->requeued[queue]); |
| 313 | qdisc_reset(q->queues[queue]); |
| 314 | } |
| 315 | qd->q.qlen = 0; |
| 316 | } |
| 317 | |
| 318 | |
| 319 | static void wme_qdiscop_destroy(struct Qdisc* qd) |
| 320 | { |
| 321 | struct ieee80211_sched_data *q = qdisc_priv(qd); |
| 322 | struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr); |
| 323 | struct ieee80211_hw *hw = &local->hw; |
| 324 | int queue; |
| 325 | |
| 326 | tcf_destroy_chain(q->filter_list); |
| 327 | q->filter_list = NULL; |
| 328 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 329 | for (queue = 0; queue < QD_NUM(hw); queue++) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 330 | skb_queue_purge(&q->requeued[queue]); |
| 331 | qdisc_destroy(q->queues[queue]); |
| 332 | q->queues[queue] = &noop_qdisc; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | |
| 337 | /* called whenever parameters are updated on existing qdisc */ |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 338 | static int wme_qdiscop_tune(struct Qdisc *qd, struct nlattr *opt) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 339 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | |
| 344 | /* called during initial creation of qdisc on device */ |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 345 | static int wme_qdiscop_init(struct Qdisc *qd, struct nlattr *opt) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 346 | { |
| 347 | struct ieee80211_sched_data *q = qdisc_priv(qd); |
| 348 | struct net_device *dev = qd->dev; |
| 349 | struct ieee80211_local *local; |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 350 | struct ieee80211_hw *hw; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 351 | int err = 0, i; |
| 352 | |
| 353 | /* check that device is a mac80211 device */ |
| 354 | if (!dev->ieee80211_ptr || |
| 355 | dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid) |
| 356 | return -EINVAL; |
| 357 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 358 | local = wdev_priv(dev->ieee80211_ptr); |
| 359 | hw = &local->hw; |
| 360 | |
| 361 | /* only allow on master dev */ |
| 362 | if (dev != local->mdev) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 363 | return -EINVAL; |
| 364 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 365 | /* ensure that we are root qdisc */ |
| 366 | if (qd->parent != TC_H_ROOT) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 367 | return -EINVAL; |
| 368 | |
| 369 | if (qd->flags & TCQ_F_INGRESS) |
| 370 | return -EINVAL; |
| 371 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 372 | /* if options were passed in, set them */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 373 | if (opt) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 374 | err = wme_qdiscop_tune(qd, opt); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 375 | |
| 376 | /* create child queues */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 377 | for (i = 0; i < QD_NUM(hw); i++) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 378 | skb_queue_head_init(&q->requeued[i]); |
| 379 | q->queues[i] = qdisc_create_dflt(qd->dev, &pfifo_qdisc_ops, |
| 380 | qd->handle); |
Johannes Berg | 136e83d | 2007-09-10 13:55:08 +0200 | [diff] [blame] | 381 | if (!q->queues[i]) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 382 | q->queues[i] = &noop_qdisc; |
| 383 | printk(KERN_ERR "%s child qdisc %i creation failed", dev->name, i); |
| 384 | } |
| 385 | } |
| 386 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 387 | /* non-aggregation queues: reserve/mark as used */ |
| 388 | for (i = 0; i < local->hw.queues; i++) |
Ron Rindjunsky | a9af201 | 2008-01-30 12:58:45 +0200 | [diff] [blame] | 389 | set_bit(i, q->qdisc_pool); |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 390 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 391 | return err; |
| 392 | } |
| 393 | |
| 394 | static int wme_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb) |
| 395 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 396 | return -1; |
| 397 | } |
| 398 | |
| 399 | |
| 400 | static int wme_classop_graft(struct Qdisc *qd, unsigned long arg, |
| 401 | struct Qdisc *new, struct Qdisc **old) |
| 402 | { |
| 403 | struct ieee80211_sched_data *q = qdisc_priv(qd); |
| 404 | struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr); |
| 405 | struct ieee80211_hw *hw = &local->hw; |
| 406 | unsigned long queue = arg - 1; |
| 407 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 408 | if (queue >= QD_NUM(hw)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 409 | return -EINVAL; |
| 410 | |
| 411 | if (!new) |
| 412 | new = &noop_qdisc; |
| 413 | |
| 414 | sch_tree_lock(qd); |
| 415 | *old = q->queues[queue]; |
| 416 | q->queues[queue] = new; |
| 417 | qdisc_reset(*old); |
| 418 | sch_tree_unlock(qd); |
| 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | |
| 424 | static struct Qdisc * |
| 425 | wme_classop_leaf(struct Qdisc *qd, unsigned long arg) |
| 426 | { |
| 427 | struct ieee80211_sched_data *q = qdisc_priv(qd); |
| 428 | struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr); |
| 429 | struct ieee80211_hw *hw = &local->hw; |
| 430 | unsigned long queue = arg - 1; |
| 431 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 432 | if (queue >= QD_NUM(hw)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 433 | return NULL; |
| 434 | |
| 435 | return q->queues[queue]; |
| 436 | } |
| 437 | |
| 438 | |
| 439 | static unsigned long wme_classop_get(struct Qdisc *qd, u32 classid) |
| 440 | { |
| 441 | struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr); |
| 442 | struct ieee80211_hw *hw = &local->hw; |
| 443 | unsigned long queue = TC_H_MIN(classid); |
| 444 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 445 | if (queue - 1 >= QD_NUM(hw)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 446 | return 0; |
| 447 | |
| 448 | return queue; |
| 449 | } |
| 450 | |
| 451 | |
| 452 | static unsigned long wme_classop_bind(struct Qdisc *qd, unsigned long parent, |
| 453 | u32 classid) |
| 454 | { |
| 455 | return wme_classop_get(qd, classid); |
| 456 | } |
| 457 | |
| 458 | |
| 459 | static void wme_classop_put(struct Qdisc *q, unsigned long cl) |
| 460 | { |
| 461 | } |
| 462 | |
| 463 | |
| 464 | static int wme_classop_change(struct Qdisc *qd, u32 handle, u32 parent, |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 465 | struct nlattr **tca, unsigned long *arg) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 466 | { |
| 467 | unsigned long cl = *arg; |
| 468 | struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr); |
| 469 | struct ieee80211_hw *hw = &local->hw; |
| 470 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 471 | if (cl - 1 > QD_NUM(hw)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 472 | return -ENOENT; |
| 473 | |
| 474 | /* TODO: put code to program hardware queue parameters here, |
| 475 | * to allow programming from tc command line */ |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | |
| 481 | /* we don't support deleting hardware queues |
| 482 | * when we add WMM-SA support - TSPECs may be deleted here */ |
| 483 | static int wme_classop_delete(struct Qdisc *qd, unsigned long cl) |
| 484 | { |
| 485 | struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr); |
| 486 | struct ieee80211_hw *hw = &local->hw; |
| 487 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 488 | if (cl - 1 > QD_NUM(hw)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 489 | return -ENOENT; |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | |
| 494 | static int wme_classop_dump_class(struct Qdisc *qd, unsigned long cl, |
| 495 | struct sk_buff *skb, struct tcmsg *tcm) |
| 496 | { |
| 497 | struct ieee80211_sched_data *q = qdisc_priv(qd); |
| 498 | struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr); |
| 499 | struct ieee80211_hw *hw = &local->hw; |
| 500 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 501 | if (cl - 1 > QD_NUM(hw)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 502 | return -ENOENT; |
| 503 | tcm->tcm_handle = TC_H_MIN(cl); |
| 504 | tcm->tcm_parent = qd->handle; |
| 505 | tcm->tcm_info = q->queues[cl-1]->handle; /* do we need this? */ |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | |
| 510 | static void wme_classop_walk(struct Qdisc *qd, struct qdisc_walker *arg) |
| 511 | { |
| 512 | struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr); |
| 513 | struct ieee80211_hw *hw = &local->hw; |
| 514 | int queue; |
| 515 | |
| 516 | if (arg->stop) |
| 517 | return; |
| 518 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 519 | for (queue = 0; queue < QD_NUM(hw); queue++) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 520 | if (arg->count < arg->skip) { |
| 521 | arg->count++; |
| 522 | continue; |
| 523 | } |
| 524 | /* we should return classids for our internal queues here |
| 525 | * as well as the external ones */ |
| 526 | if (arg->fn(qd, queue+1, arg) < 0) { |
| 527 | arg->stop = 1; |
| 528 | break; |
| 529 | } |
| 530 | arg->count++; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | |
| 535 | static struct tcf_proto ** wme_classop_find_tcf(struct Qdisc *qd, |
| 536 | unsigned long cl) |
| 537 | { |
| 538 | struct ieee80211_sched_data *q = qdisc_priv(qd); |
| 539 | |
| 540 | if (cl) |
| 541 | return NULL; |
| 542 | |
| 543 | return &q->filter_list; |
| 544 | } |
| 545 | |
| 546 | |
| 547 | /* this qdisc is classful (i.e. has classes, some of which may have leaf qdiscs attached) |
| 548 | * - these are the operations on the classes */ |
Eric Dumazet | 20fea08 | 2007-11-14 01:44:41 -0800 | [diff] [blame] | 549 | static const struct Qdisc_class_ops class_ops = |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 550 | { |
| 551 | .graft = wme_classop_graft, |
| 552 | .leaf = wme_classop_leaf, |
| 553 | |
| 554 | .get = wme_classop_get, |
| 555 | .put = wme_classop_put, |
| 556 | .change = wme_classop_change, |
| 557 | .delete = wme_classop_delete, |
| 558 | .walk = wme_classop_walk, |
| 559 | |
| 560 | .tcf_chain = wme_classop_find_tcf, |
| 561 | .bind_tcf = wme_classop_bind, |
| 562 | .unbind_tcf = wme_classop_put, |
| 563 | |
| 564 | .dump = wme_classop_dump_class, |
| 565 | }; |
| 566 | |
| 567 | |
| 568 | /* queueing discipline operations */ |
Eric Dumazet | 20fea08 | 2007-11-14 01:44:41 -0800 | [diff] [blame] | 569 | static struct Qdisc_ops wme_qdisc_ops __read_mostly = |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 570 | { |
| 571 | .next = NULL, |
| 572 | .cl_ops = &class_ops, |
| 573 | .id = "ieee80211", |
| 574 | .priv_size = sizeof(struct ieee80211_sched_data), |
| 575 | |
| 576 | .enqueue = wme_qdiscop_enqueue, |
| 577 | .dequeue = wme_qdiscop_dequeue, |
| 578 | .requeue = wme_qdiscop_requeue, |
| 579 | .drop = NULL, /* drop not needed since we are always the root qdisc */ |
| 580 | |
| 581 | .init = wme_qdiscop_init, |
| 582 | .reset = wme_qdiscop_reset, |
| 583 | .destroy = wme_qdiscop_destroy, |
| 584 | .change = wme_qdiscop_tune, |
| 585 | |
| 586 | .dump = wme_qdiscop_dump, |
| 587 | }; |
| 588 | |
| 589 | |
| 590 | void ieee80211_install_qdisc(struct net_device *dev) |
| 591 | { |
| 592 | struct Qdisc *qdisc; |
| 593 | |
| 594 | qdisc = qdisc_create_dflt(dev, &wme_qdisc_ops, TC_H_ROOT); |
| 595 | if (!qdisc) { |
| 596 | printk(KERN_ERR "%s: qdisc installation failed\n", dev->name); |
| 597 | return; |
| 598 | } |
| 599 | |
| 600 | /* same handle as would be allocated by qdisc_alloc_handle() */ |
| 601 | qdisc->handle = 0x80010000; |
| 602 | |
| 603 | qdisc_lock_tree(dev); |
| 604 | list_add_tail(&qdisc->list, &dev->qdisc_list); |
| 605 | dev->qdisc_sleeping = qdisc; |
| 606 | qdisc_unlock_tree(dev); |
| 607 | } |
| 608 | |
| 609 | |
| 610 | int ieee80211_qdisc_installed(struct net_device *dev) |
| 611 | { |
| 612 | return dev->qdisc_sleeping->ops == &wme_qdisc_ops; |
| 613 | } |
| 614 | |
| 615 | |
| 616 | int ieee80211_wme_register(void) |
| 617 | { |
| 618 | return register_qdisc(&wme_qdisc_ops); |
| 619 | } |
| 620 | |
| 621 | |
| 622 | void ieee80211_wme_unregister(void) |
| 623 | { |
| 624 | unregister_qdisc(&wme_qdisc_ops); |
| 625 | } |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 626 | |
| 627 | int ieee80211_ht_agg_queue_add(struct ieee80211_local *local, |
| 628 | struct sta_info *sta, u16 tid) |
| 629 | { |
| 630 | int i; |
| 631 | struct ieee80211_sched_data *q = |
| 632 | qdisc_priv(local->mdev->qdisc_sleeping); |
| 633 | DECLARE_MAC_BUF(mac); |
| 634 | |
| 635 | /* prepare the filter and save it for the SW queue |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 636 | * matching the received HW queue */ |
| 637 | |
| 638 | if (!local->hw.ampdu_queues) |
| 639 | return -EPERM; |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 640 | |
| 641 | /* try to get a Qdisc from the pool */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 642 | for (i = local->hw.queues; i < QD_NUM(&local->hw); i++) |
Ron Rindjunsky | a9af201 | 2008-01-30 12:58:45 +0200 | [diff] [blame] | 643 | if (!test_and_set_bit(i, q->qdisc_pool)) { |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 644 | ieee80211_stop_queue(local_to_hw(local), i); |
| 645 | sta->tid_to_tx_q[tid] = i; |
| 646 | |
| 647 | /* IF there are already pending packets |
| 648 | * on this tid first we need to drain them |
| 649 | * on the previous queue |
| 650 | * since HT is strict in order */ |
| 651 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 652 | if (net_ratelimit()) |
| 653 | printk(KERN_DEBUG "allocated aggregation queue" |
Ron Rindjunsky | a9af201 | 2008-01-30 12:58:45 +0200 | [diff] [blame] | 654 | " %d tid %d addr %s pool=0x%lX", |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 655 | i, tid, print_mac(mac, sta->addr), |
Ron Rindjunsky | a9af201 | 2008-01-30 12:58:45 +0200 | [diff] [blame] | 656 | q->qdisc_pool[0]); |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 657 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | return -EAGAIN; |
| 662 | } |
| 663 | |
| 664 | /** |
| 665 | * the caller needs to hold local->mdev->queue_lock |
| 666 | */ |
| 667 | void ieee80211_ht_agg_queue_remove(struct ieee80211_local *local, |
| 668 | struct sta_info *sta, u16 tid, |
| 669 | u8 requeue) |
| 670 | { |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 671 | struct ieee80211_hw *hw = &local->hw; |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 672 | struct ieee80211_sched_data *q = |
| 673 | qdisc_priv(local->mdev->qdisc_sleeping); |
| 674 | int agg_queue = sta->tid_to_tx_q[tid]; |
| 675 | |
| 676 | /* return the qdisc to the pool */ |
Ron Rindjunsky | a9af201 | 2008-01-30 12:58:45 +0200 | [diff] [blame] | 677 | clear_bit(agg_queue, q->qdisc_pool); |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame^] | 678 | sta->tid_to_tx_q[tid] = QD_NUM(hw); |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 679 | |
| 680 | if (requeue) |
| 681 | ieee80211_requeue(local, agg_queue); |
| 682 | else |
| 683 | q->queues[agg_queue]->ops->reset(q->queues[agg_queue]); |
| 684 | } |
| 685 | |
| 686 | void ieee80211_requeue(struct ieee80211_local *local, int queue) |
| 687 | { |
| 688 | struct Qdisc *root_qd = local->mdev->qdisc_sleeping; |
| 689 | struct ieee80211_sched_data *q = qdisc_priv(root_qd); |
| 690 | struct Qdisc *qdisc = q->queues[queue]; |
| 691 | struct sk_buff *skb = NULL; |
Ron Rindjunsky | 0da926f | 2008-04-23 13:45:12 +0300 | [diff] [blame] | 692 | u32 len; |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 693 | |
| 694 | if (!qdisc || !qdisc->dequeue) |
| 695 | return; |
| 696 | |
| 697 | printk(KERN_DEBUG "requeue: qlen = %d\n", qdisc->q.qlen); |
| 698 | for (len = qdisc->q.qlen; len > 0; len--) { |
| 699 | skb = qdisc->dequeue(qdisc); |
| 700 | root_qd->q.qlen--; |
| 701 | /* packet will be classified again and */ |
| 702 | /* skb->packet_data->queue will be overridden if needed */ |
| 703 | if (skb) |
| 704 | wme_qdiscop_enqueue(skb, root_qd); |
| 705 | } |
| 706 | } |