18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * O(1) TX queue with built-in allocator for ST-Ericsson CW1200 drivers
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2010, ST-Ericsson
68c2ecf20Sopenharmony_ci * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef CW1200_QUEUE_H_INCLUDED
108c2ecf20Sopenharmony_ci#define CW1200_QUEUE_H_INCLUDED
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* private */ struct cw1200_queue_item;
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/* extern */ struct sk_buff;
158c2ecf20Sopenharmony_ci/* extern */ struct wsm_tx;
168c2ecf20Sopenharmony_ci/* extern */ struct cw1200_common;
178c2ecf20Sopenharmony_ci/* extern */ struct ieee80211_tx_queue_stats;
188c2ecf20Sopenharmony_ci/* extern */ struct cw1200_txpriv;
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/* forward */ struct cw1200_queue_stats;
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_citypedef void (*cw1200_queue_skb_dtor_t)(struct cw1200_common *priv,
238c2ecf20Sopenharmony_ci					struct sk_buff *skb,
248c2ecf20Sopenharmony_ci					const struct cw1200_txpriv *txpriv);
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistruct cw1200_queue {
278c2ecf20Sopenharmony_ci	struct cw1200_queue_stats *stats;
288c2ecf20Sopenharmony_ci	size_t			capacity;
298c2ecf20Sopenharmony_ci	size_t			num_queued;
308c2ecf20Sopenharmony_ci	size_t			num_pending;
318c2ecf20Sopenharmony_ci	size_t			num_sent;
328c2ecf20Sopenharmony_ci	struct cw1200_queue_item *pool;
338c2ecf20Sopenharmony_ci	struct list_head	queue;
348c2ecf20Sopenharmony_ci	struct list_head	free_pool;
358c2ecf20Sopenharmony_ci	struct list_head	pending;
368c2ecf20Sopenharmony_ci	int			tx_locked_cnt;
378c2ecf20Sopenharmony_ci	int			*link_map_cache;
388c2ecf20Sopenharmony_ci	bool			overfull;
398c2ecf20Sopenharmony_ci	spinlock_t		lock; /* Protect queue entry */
408c2ecf20Sopenharmony_ci	u8			queue_id;
418c2ecf20Sopenharmony_ci	u8			generation;
428c2ecf20Sopenharmony_ci	struct timer_list	gc;
438c2ecf20Sopenharmony_ci	unsigned long		ttl;
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct cw1200_queue_stats {
478c2ecf20Sopenharmony_ci	spinlock_t		lock; /* Protect stats entry */
488c2ecf20Sopenharmony_ci	int			*link_map_cache;
498c2ecf20Sopenharmony_ci	int			num_queued;
508c2ecf20Sopenharmony_ci	size_t			map_capacity;
518c2ecf20Sopenharmony_ci	wait_queue_head_t	wait_link_id_empty;
528c2ecf20Sopenharmony_ci	cw1200_queue_skb_dtor_t	skb_dtor;
538c2ecf20Sopenharmony_ci	struct cw1200_common	*priv;
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistruct cw1200_txpriv {
578c2ecf20Sopenharmony_ci	u8 link_id;
588c2ecf20Sopenharmony_ci	u8 raw_link_id;
598c2ecf20Sopenharmony_ci	u8 tid;
608c2ecf20Sopenharmony_ci	u8 rate_id;
618c2ecf20Sopenharmony_ci	u8 offset;
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ciint cw1200_queue_stats_init(struct cw1200_queue_stats *stats,
658c2ecf20Sopenharmony_ci			    size_t map_capacity,
668c2ecf20Sopenharmony_ci			    cw1200_queue_skb_dtor_t skb_dtor,
678c2ecf20Sopenharmony_ci			    struct cw1200_common *priv);
688c2ecf20Sopenharmony_ciint cw1200_queue_init(struct cw1200_queue *queue,
698c2ecf20Sopenharmony_ci		      struct cw1200_queue_stats *stats,
708c2ecf20Sopenharmony_ci		      u8 queue_id,
718c2ecf20Sopenharmony_ci		      size_t capacity,
728c2ecf20Sopenharmony_ci		      unsigned long ttl);
738c2ecf20Sopenharmony_ciint cw1200_queue_clear(struct cw1200_queue *queue);
748c2ecf20Sopenharmony_civoid cw1200_queue_stats_deinit(struct cw1200_queue_stats *stats);
758c2ecf20Sopenharmony_civoid cw1200_queue_deinit(struct cw1200_queue *queue);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_cisize_t cw1200_queue_get_num_queued(struct cw1200_queue *queue,
788c2ecf20Sopenharmony_ci				   u32 link_id_map);
798c2ecf20Sopenharmony_ciint cw1200_queue_put(struct cw1200_queue *queue,
808c2ecf20Sopenharmony_ci		     struct sk_buff *skb,
818c2ecf20Sopenharmony_ci		     struct cw1200_txpriv *txpriv);
828c2ecf20Sopenharmony_ciint cw1200_queue_get(struct cw1200_queue *queue,
838c2ecf20Sopenharmony_ci		     u32 link_id_map,
848c2ecf20Sopenharmony_ci		     struct wsm_tx **tx,
858c2ecf20Sopenharmony_ci		     struct ieee80211_tx_info **tx_info,
868c2ecf20Sopenharmony_ci		     const struct cw1200_txpriv **txpriv);
878c2ecf20Sopenharmony_ciint cw1200_queue_requeue(struct cw1200_queue *queue, u32 packet_id);
888c2ecf20Sopenharmony_ciint cw1200_queue_requeue_all(struct cw1200_queue *queue);
898c2ecf20Sopenharmony_ciint cw1200_queue_remove(struct cw1200_queue *queue,
908c2ecf20Sopenharmony_ci			u32 packet_id);
918c2ecf20Sopenharmony_ciint cw1200_queue_get_skb(struct cw1200_queue *queue, u32 packet_id,
928c2ecf20Sopenharmony_ci			 struct sk_buff **skb,
938c2ecf20Sopenharmony_ci			 const struct cw1200_txpriv **txpriv);
948c2ecf20Sopenharmony_civoid cw1200_queue_lock(struct cw1200_queue *queue);
958c2ecf20Sopenharmony_civoid cw1200_queue_unlock(struct cw1200_queue *queue);
968c2ecf20Sopenharmony_cibool cw1200_queue_get_xmit_timestamp(struct cw1200_queue *queue,
978c2ecf20Sopenharmony_ci				     unsigned long *timestamp,
988c2ecf20Sopenharmony_ci				     u32 pending_frame_id);
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cibool cw1200_queue_stats_is_empty(struct cw1200_queue_stats *stats,
1018c2ecf20Sopenharmony_ci				 u32 link_id_map);
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistatic inline u8 cw1200_queue_get_queue_id(u32 packet_id)
1048c2ecf20Sopenharmony_ci{
1058c2ecf20Sopenharmony_ci	return (packet_id >> 16) & 0xFF;
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cistatic inline u8 cw1200_queue_get_generation(u32 packet_id)
1098c2ecf20Sopenharmony_ci{
1108c2ecf20Sopenharmony_ci	return (packet_id >>  8) & 0xFF;
1118c2ecf20Sopenharmony_ci}
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci#endif /* CW1200_QUEUE_H_INCLUDED */
114