1 /* -----------------------------------------------------------------------------
2  * Copyright (c) 2011 Ozmo Inc
3  * Released under the GNU General Public License Version 2 (GPLv2).
4  * -----------------------------------------------------------------------------
5  */
6 #ifndef _OZELTBUF_H
7 #define _OZELTBUF_H
8 
9 #include "ozprotocol.h"
10 
11 /*-----------------------------------------------------------------------------
12  */
13 struct oz_pd;
14 typedef void (*oz_elt_callback_t)(struct oz_pd *pd, long context);
15 
16 struct oz_elt_stream {
17 	struct list_head link;
18 	struct list_head elt_list;
19 	atomic_t ref_count;
20 	unsigned buf_count;
21 	unsigned max_buf_count;
22 	u8 frame_number;
23 	u8 id;
24 };
25 
26 #define OZ_MAX_ELT_PAYLOAD	255
27 struct oz_elt_info {
28 	struct list_head link;
29 	struct list_head link_order;
30 	u8 flags;
31 	u8 app_id;
32 	oz_elt_callback_t callback;
33 	long context;
34 	struct oz_elt_stream *stream;
35 	u8 data[sizeof(struct oz_elt) + OZ_MAX_ELT_PAYLOAD];
36 	int length;
37 	unsigned magic;
38 };
39 /* Flags values */
40 #define OZ_EI_F_MARKED		0x1
41 
42 struct oz_elt_buf {
43 	spinlock_t lock;
44 	struct list_head stream_list;
45 	struct list_head order_list;
46 	struct list_head isoc_list;
47 	struct list_head *elt_pool;
48 	int free_elts;
49 	int max_free_elts;
50 	u8 tx_seq_num[OZ_NB_APPS];
51 };
52 
53 int oz_elt_buf_init(struct oz_elt_buf *buf);
54 void oz_elt_buf_term(struct oz_elt_buf *buf);
55 struct oz_elt_info *oz_elt_info_alloc(struct oz_elt_buf *buf);
56 void oz_elt_info_free(struct oz_elt_buf *buf, struct oz_elt_info *ei);
57 void oz_elt_info_free_chain(struct oz_elt_buf *buf, struct list_head *list);
58 int oz_elt_stream_create(struct oz_elt_buf *buf, u8 id, int max_buf_count);
59 int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id);
60 void oz_elt_stream_get(struct oz_elt_stream *st);
61 void oz_elt_stream_put(struct oz_elt_stream *st);
62 int oz_queue_elt_info(struct oz_elt_buf *buf, u8 isoc, u8 id,
63 		struct oz_elt_info *ei);
64 int oz_select_elts_for_tx(struct oz_elt_buf *buf, u8 isoc, unsigned *len,
65 		unsigned max_len, struct list_head *list);
66 int oz_are_elts_available(struct oz_elt_buf *buf);
67 void oz_trim_elt_pool(struct oz_elt_buf *buf);
68 
69 #endif /* _OZELTBUF_H */
70 
71