Lines Matching refs:queue

3  * O(1) TX queue with built-in allocator for ST-Ericsson CW1200 drivers
11 #include "queue.h"
26 static inline void __cw1200_queue_lock(struct cw1200_queue *queue)
28 struct cw1200_queue_stats *stats = queue->stats;
29 if (queue->tx_locked_cnt++ == 0) {
31 queue->queue_id);
32 ieee80211_stop_queue(stats->priv->hw, queue->queue_id);
36 static inline void __cw1200_queue_unlock(struct cw1200_queue *queue)
38 struct cw1200_queue_stats *stats = queue->stats;
39 BUG_ON(!queue->tx_locked_cnt);
40 if (--queue->tx_locked_cnt == 0) {
42 queue->queue_id);
43 ieee80211_wake_queue(stats->priv->hw, queue->queue_id);
88 static void __cw1200_queue_gc(struct cw1200_queue *queue,
92 struct cw1200_queue_stats *stats = queue->stats;
96 list_for_each_entry_safe(item, tmp, &queue->queue, head) {
97 if (jiffies - item->queue_timestamp < queue->ttl)
99 --queue->num_queued;
100 --queue->link_map_cache[item->txpriv.link_id];
109 list_move_tail(&item->head, &queue->free_pool);
115 if (queue->overfull) {
116 if (queue->num_queued <= (queue->capacity >> 1)) {
117 queue->overfull = false;
119 __cw1200_queue_unlock(queue);
121 unsigned long tmo = item->queue_timestamp + queue->ttl;
122 mod_timer(&queue->gc, tmo);
132 struct cw1200_queue *queue =
133 from_timer(queue, t, gc);
135 spin_lock_bh(&queue->lock);
136 __cw1200_queue_gc(queue, &list, true);
137 spin_unlock_bh(&queue->lock);
138 cw1200_queue_post_gc(queue->stats, &list);
161 int cw1200_queue_init(struct cw1200_queue *queue,
169 memset(queue, 0, sizeof(*queue));
170 queue->stats = stats;
171 queue->capacity = capacity;
172 queue->queue_id = queue_id;
173 queue->ttl = ttl;
174 INIT_LIST_HEAD(&queue->queue);
175 INIT_LIST_HEAD(&queue->pending);
176 INIT_LIST_HEAD(&queue->free_pool);
177 spin_lock_init(&queue->lock);
178 timer_setup(&queue->gc, cw1200_queue_gc, 0);
180 queue->pool = kcalloc(capacity, sizeof(struct cw1200_queue_item),
182 if (!queue->pool)
185 queue->link_map_cache = kcalloc(stats->map_capacity, sizeof(int),
187 if (!queue->link_map_cache) {
188 kfree(queue->pool);
189 queue->pool = NULL;
194 list_add_tail(&queue->pool[i].head, &queue->free_pool);
199 int cw1200_queue_clear(struct cw1200_queue *queue)
203 struct cw1200_queue_stats *stats = queue->stats;
206 spin_lock_bh(&queue->lock);
207 queue->generation++;
208 list_splice_tail_init(&queue->queue, &queue->pending);
209 list_for_each_entry_safe(item, tmp, &queue->pending, head) {
213 list_move_tail(&item->head, &queue->free_pool);
215 queue->num_queued = 0;
216 queue->num_pending = 0;
220 stats->num_queued -= queue->link_map_cache[i];
221 stats->link_map_cache[i] -= queue->link_map_cache[i];
222 queue->link_map_cache[i] = 0;
225 if (queue->overfull) {
226 queue->overfull = false;
227 __cw1200_queue_unlock(queue);
229 spin_unlock_bh(&queue->lock);
241 void cw1200_queue_deinit(struct cw1200_queue *queue)
243 cw1200_queue_clear(queue);
244 del_timer_sync(&queue->gc);
245 INIT_LIST_HEAD(&queue->free_pool);
246 kfree(queue->pool);
247 kfree(queue->link_map_cache);
248 queue->pool = NULL;
249 queue->link_map_cache = NULL;
250 queue->capacity = 0;
253 size_t cw1200_queue_get_num_queued(struct cw1200_queue *queue,
258 size_t map_capacity = queue->stats->map_capacity;
263 spin_lock_bh(&queue->lock);
265 ret = queue->num_queued - queue->num_pending;
270 ret += queue->link_map_cache[i];
273 spin_unlock_bh(&queue->lock);
277 int cw1200_queue_put(struct cw1200_queue *queue,
282 struct cw1200_queue_stats *stats = queue->stats;
284 if (txpriv->link_id >= queue->stats->map_capacity)
287 spin_lock_bh(&queue->lock);
288 if (!WARN_ON(list_empty(&queue->free_pool))) {
290 &queue->free_pool, struct cw1200_queue_item, head);
293 list_move_tail(&item->head, &queue->queue);
297 item->packet_id = cw1200_queue_mk_packet_id(queue->generation,
298 queue->queue_id,
300 item - queue->pool);
303 ++queue->num_queued;
304 ++queue->link_map_cache[txpriv->link_id];
312 * Leave extra queue slots so we don't overflow.
314 if (queue->overfull == false &&
315 queue->num_queued >=
316 (queue->capacity - (num_present_cpus() - 1))) {
317 queue->overfull = true;
318 __cw1200_queue_lock(queue);
319 mod_timer(&queue->gc, jiffies);
324 spin_unlock_bh(&queue->lock);
328 int cw1200_queue_get(struct cw1200_queue *queue,
336 struct cw1200_queue_stats *stats = queue->stats;
339 spin_lock_bh(&queue->lock);
340 list_for_each_entry(item, &queue->queue, head) {
352 list_move_tail(&item->head, &queue->pending);
353 ++queue->num_pending;
354 --queue->link_map_cache[item->txpriv.link_id];
363 spin_unlock_bh(&queue->lock);
369 int cw1200_queue_requeue(struct cw1200_queue *queue, u32 packet_id)
374 struct cw1200_queue_stats *stats = queue->stats;
379 item = &queue->pool[item_id];
381 spin_lock_bh(&queue->lock);
382 BUG_ON(queue_id != queue->queue_id);
383 if (queue_generation != queue->generation) {
385 } else if (item_id >= (unsigned) queue->capacity) {
392 --queue->num_pending;
393 ++queue->link_map_cache[item->txpriv.link_id];
405 list_move(&item->head, &queue->queue);
407 spin_unlock_bh(&queue->lock);
411 int cw1200_queue_requeue_all(struct cw1200_queue *queue)
414 struct cw1200_queue_stats *stats = queue->stats;
415 spin_lock_bh(&queue->lock);
417 list_for_each_entry_safe_reverse(item, tmp, &queue->pending, head) {
418 --queue->num_pending;
419 ++queue->link_map_cache[item->txpriv.link_id];
427 item->packet_id = cw1200_queue_mk_packet_id(queue->generation,
428 queue->queue_id,
430 item - queue->pool);
431 list_move(&item->head, &queue->queue);
433 spin_unlock_bh(&queue->lock);
438 int cw1200_queue_remove(struct cw1200_queue *queue, u32 packet_id)
443 struct cw1200_queue_stats *stats = queue->stats;
450 item = &queue->pool[item_id];
452 spin_lock_bh(&queue->lock);
453 BUG_ON(queue_id != queue->queue_id);
454 if (queue_generation != queue->generation) {
456 } else if (item_id >= (unsigned) queue->capacity) {
466 --queue->num_pending;
467 --queue->num_queued;
468 ++queue->num_sent;
473 list_move(&item->head, &queue->free_pool);
475 if (queue->overfull &&
476 (queue->num_queued <= (queue->capacity >> 1))) {
477 queue->overfull = false;
478 __cw1200_queue_unlock(queue);
481 spin_unlock_bh(&queue->lock);
489 int cw1200_queue_get_skb(struct cw1200_queue *queue, u32 packet_id,
499 item = &queue->pool[item_id];
501 spin_lock_bh(&queue->lock);
502 BUG_ON(queue_id != queue->queue_id);
503 if (queue_generation != queue->generation) {
505 } else if (item_id >= (unsigned) queue->capacity) {
515 spin_unlock_bh(&queue->lock);
519 void cw1200_queue_lock(struct cw1200_queue *queue)
521 spin_lock_bh(&queue->lock);
522 __cw1200_queue_lock(queue);
523 spin_unlock_bh(&queue->lock);
526 void cw1200_queue_unlock(struct cw1200_queue *queue)
528 spin_lock_bh(&queue->lock);
529 __cw1200_queue_unlock(queue);
530 spin_unlock_bh(&queue->lock);
533 bool cw1200_queue_get_xmit_timestamp(struct cw1200_queue *queue,
540 spin_lock_bh(&queue->lock);
541 ret = !list_empty(&queue->pending);
543 list_for_each_entry(item, &queue->pending, head) {
550 spin_unlock_bh(&queue->lock);