queue.h 3.2 KB

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