queue.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * O(1) TX queue with built-in allocator for ST-Ericsson CW1200 drivers
  3. *
  4. * Copyright (c) 2010, ST-Ericsson
  5. * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef CW1200_QUEUE_H_INCLUDED
  12. #define CW1200_QUEUE_H_INCLUDED
  13. /* private */ struct cw1200_queue_item;
  14. /* extern */ struct sk_buff;
  15. /* extern */ struct wsm_tx;
  16. /* extern */ struct cw1200_common;
  17. /* extern */ struct ieee80211_tx_queue_stats;
  18. /* extern */ struct cw1200_txpriv;
  19. /* forward */ struct cw1200_queue_stats;
  20. typedef void (*cw1200_queue_skb_dtor_t)(struct cw1200_common *priv,
  21. struct sk_buff *skb,
  22. const struct cw1200_txpriv *txpriv);
  23. struct cw1200_queue {
  24. struct cw1200_queue_stats *stats;
  25. size_t capacity;
  26. size_t num_queued;
  27. size_t num_pending;
  28. size_t num_sent;
  29. struct cw1200_queue_item *pool;
  30. struct list_head queue;
  31. struct list_head free_pool;
  32. struct list_head pending;
  33. int tx_locked_cnt;
  34. int *link_map_cache;
  35. bool overfull;
  36. spinlock_t lock; /* Protect queue entry */
  37. u8 queue_id;
  38. u8 generation;
  39. struct timer_list gc;
  40. unsigned long ttl;
  41. };
  42. struct cw1200_queue_stats {
  43. spinlock_t lock; /* Protect stats entry */
  44. int *link_map_cache;
  45. int num_queued;
  46. size_t map_capacity;
  47. wait_queue_head_t wait_link_id_empty;
  48. cw1200_queue_skb_dtor_t skb_dtor;
  49. struct cw1200_common *priv;
  50. };
  51. struct cw1200_txpriv {
  52. u8 link_id;
  53. u8 raw_link_id;
  54. u8 tid;
  55. u8 rate_id;
  56. u8 offset;
  57. };
  58. int cw1200_queue_stats_init(struct cw1200_queue_stats *stats,
  59. size_t map_capacity,
  60. cw1200_queue_skb_dtor_t skb_dtor,
  61. struct cw1200_common *priv);
  62. int cw1200_queue_init(struct cw1200_queue *queue,
  63. struct cw1200_queue_stats *stats,
  64. u8 queue_id,
  65. size_t capacity,
  66. unsigned long ttl);
  67. int cw1200_queue_clear(struct cw1200_queue *queue);
  68. void cw1200_queue_stats_deinit(struct cw1200_queue_stats *stats);
  69. void cw1200_queue_deinit(struct cw1200_queue *queue);
  70. size_t cw1200_queue_get_num_queued(struct cw1200_queue *queue,
  71. u32 link_id_map);
  72. int cw1200_queue_put(struct cw1200_queue *queue,
  73. struct sk_buff *skb,
  74. struct cw1200_txpriv *txpriv);
  75. int cw1200_queue_get(struct cw1200_queue *queue,
  76. u32 link_id_map,
  77. struct wsm_tx **tx,
  78. struct ieee80211_tx_info **tx_info,
  79. const struct cw1200_txpriv **txpriv);
  80. int cw1200_queue_requeue(struct cw1200_queue *queue, u32 packet_id);
  81. int cw1200_queue_requeue_all(struct cw1200_queue *queue);
  82. int cw1200_queue_remove(struct cw1200_queue *queue,
  83. u32 packet_id);
  84. int cw1200_queue_get_skb(struct cw1200_queue *queue, u32 packet_id,
  85. struct sk_buff **skb,
  86. const struct cw1200_txpriv **txpriv);
  87. void cw1200_queue_lock(struct cw1200_queue *queue);
  88. void cw1200_queue_unlock(struct cw1200_queue *queue);
  89. bool cw1200_queue_get_xmit_timestamp(struct cw1200_queue *queue,
  90. unsigned long *timestamp,
  91. u32 pending_frame_id);
  92. bool cw1200_queue_stats_is_empty(struct cw1200_queue_stats *stats,
  93. u32 link_id_map);
  94. static inline u8 cw1200_queue_get_queue_id(u32 packet_id)
  95. {
  96. return (packet_id >> 16) & 0xFF;
  97. }
  98. static inline u8 cw1200_queue_get_generation(u32 packet_id)
  99. {
  100. return (packet_id >> 8) & 0xFF;
  101. }
  102. #endif /* CW1200_QUEUE_H_INCLUDED */