Debian Codegraph @

drivers/dahdi/zaphfc/fifo.h

raw symbols SCIP
1 /*
2 * fifo.h - Dahdi driver for HFC-S PCI A based ISDN BRI cards
3 *
4 * Copyright (C) 2004 Daniele Orlandi
5 * Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
6 *
7 * Daniele "Vihai" Orlandi <[email protected]>
8 *
9 * Major rewrite of the driver made by
10 * Klaus-Peter Junghanns <[email protected]>
11 *
12 * This program is free software and may be modified and
13 * distributed under the terms of the GNU General Public License.
14 *
15 */
16
17 #ifndef _HFC_FIFO_H
18 #define _HFC_FIFO_H
19
20 #include "zaphfc.h"
21
22 static inline u16 *Z1_F1(struct hfc_chan_simplex *chan)
23 {
24 return chan->z1_base + (*chan->f1 * 4);
25 }
26
27 static inline u16 *Z2_F1(struct hfc_chan_simplex *chan)
28 {
29 return chan->z2_base + (*chan->f1 * 4);
30 }
31
32 static inline u16 *Z1_F2(struct hfc_chan_simplex *chan)
33 {
34 return chan->z1_base + (*chan->f2 * 4);
35 }
36
37 static inline u16 *Z2_F2(struct hfc_chan_simplex *chan)
38 {
39 return chan->z2_base + (*chan->f2 * 4);
40 }
41
42 static inline u16 Z_inc(struct hfc_chan_simplex *chan, u16 z, u16 inc)
43 {
44 /*
45 * declared as u32 in order to manage overflows
46 */
47 u32 newz = z + inc;
48 if (newz > chan->z_max)
49 newz -= chan->fifo_size;
50
51 return newz;
52 }
53
54 static inline u8 F_inc(struct hfc_chan_simplex *chan, u8 f, u8 inc)
55 {
56 /*
57 * declared as u16 in order to manage overflows
58 */
59 u16 newf = f + inc;
60 if (newf > chan->f_max)
61 newf -= chan->f_num;
62
63 return newf;
64 }
65
66 static inline u16 hfc_fifo_used_rx(struct hfc_chan_simplex *chan)
67 {
68 return (*Z1_F2(chan) - *Z2_F2(chan) +
69 chan->fifo_size) % chan->fifo_size;
70 }
71
72 static inline u16 hfc_fifo_get_frame_size(struct hfc_chan_simplex *chan)
73 {
74 /*
75 * This +1 is needed because in frame mode the available bytes are Z2-Z1+1
76 * while in transparent mode I wouldn't consider the byte pointed by Z2 to
77 * be available, otherwise, the FIFO would always contain one byte, even
78 * when Z1==Z2
79 */
80
81 return hfc_fifo_used_rx(chan) + 1;
82 }
83
84 static inline u8 hfc_fifo_u8(struct hfc_chan_simplex *chan, u16 z)
85 {
86 return *((u8 *)(chan->z_base + z));
87 }
88
89 static inline u16 hfc_fifo_used_tx(struct hfc_chan_simplex *chan)
90 {
91 return (*Z1_F1(chan) - *Z2_F1(chan) +
92 chan->fifo_size) % chan->fifo_size;
93 }
94
95 static inline u16 hfc_fifo_free_rx(struct hfc_chan_simplex *chan)
96 {
97 u16 free_bytes = *Z2_F1(chan) - *Z1_F1(chan);
98
99 if (free_bytes > 0)
100 return free_bytes;
101 else
102 return free_bytes + chan->fifo_size;
103 }
104
105 static inline u16 hfc_fifo_free_tx(struct hfc_chan_simplex *chan)
106 {
107 u16 free_bytes = *Z2_F1(chan) - *Z1_F1(chan);
108
109 if (free_bytes > 0)
110 return free_bytes;
111 else
112 return free_bytes + chan->fifo_size;
113 }
114
115 static inline int hfc_fifo_has_frames(struct hfc_chan_simplex *chan)
116 {
117 return *chan->f1 != *chan->f2;
118 }
119
120 static inline u8 hfc_fifo_used_frames(struct hfc_chan_simplex *chan)
121 {
122 return (*chan->f1 - *chan->f2 + chan->f_num) % chan->f_num;
123 }
124
125 static inline u8 hfc_fifo_free_frames(struct hfc_chan_simplex *chan)
126 {
127 return (*chan->f2 - *chan->f1 + chan->f_num) % chan->f_num;
128 }
129
130 int hfc_fifo_get(struct hfc_chan_simplex *chan, void *data, int size);
131 void hfc_fifo_put(struct hfc_chan_simplex *chan, void *data, int size);
132 void hfc_fifo_drop(struct hfc_chan_simplex *chan, int size);
133 int hfc_fifo_get_frame(struct hfc_chan_simplex *chan, void *data, int max_size);
134 void hfc_fifo_drop_frame(struct hfc_chan_simplex *chan);
135 void hfc_fifo_put_frame(struct hfc_chan_simplex *chan, void *data, int size);
136 void hfc_clear_fifo_rx(struct hfc_chan_simplex *chan);
137 void hfc_clear_fifo_tx(struct hfc_chan_simplex *chan);
138
139 #endif