2
* zaphfc.c - Zaptel driver for HFC-S PCI A based ISDN BRI cards
4
* Copyright (C) 2004 Daniele Orlandi
5
* Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
7
* Daniele "Vihai" Orlandi <daniele@orlandi.com>
9
* Major rewrite of the driver made by
10
* Klaus-Peter Junghanns <kpj@junghanns.net>
12
* This program is free software and may be modified and
13
* distributed under the terms of the GNU Public License.
22
static inline u16 *Z1_F1(struct hfc_chan_simplex *chan)
24
return chan->z1_base + (*chan->f1 * 4);
27
static inline u16 *Z2_F1(struct hfc_chan_simplex *chan)
29
return chan->z2_base + (*chan->f1 * 4);
32
static inline u16 *Z1_F2(struct hfc_chan_simplex *chan)
34
return chan->z1_base + (*chan->f2 * 4);
37
static inline u16 *Z2_F2(struct hfc_chan_simplex *chan)
39
return chan->z2_base + (*chan->f2 * 4);
42
static inline u16 Z_inc(struct hfc_chan_simplex *chan, u16 z, u16 inc)
44
// declared as u32 in order to manage overflows
46
if (newz > chan->z_max)
47
newz -= chan->fifo_size;
52
static inline u8 F_inc(struct hfc_chan_simplex *chan, u8 f, u8 inc)
54
// declared as u16 in order to manage overflows
56
if (newf > chan->f_max)
62
static inline u16 hfc_fifo_used_rx(struct hfc_chan_simplex *chan)
64
return (*Z1_F2(chan) - *Z2_F2(chan) + chan->fifo_size) % chan->fifo_size;
67
static inline u16 hfc_fifo_get_frame_size(struct hfc_chan_simplex *chan)
69
// This +1 is needed because in frame mode the available bytes are Z2-Z1+1
70
// while in transparent mode I wouldn't consider the byte pointed by Z2 to
71
// be available, otherwise, the FIFO would always contain one byte, even
74
return hfc_fifo_used_rx(chan) + 1;
77
static inline u8 hfc_fifo_u8(struct hfc_chan_simplex *chan, u16 z)
79
return *((u8 *)(chan->z_base + z));
82
static inline u16 hfc_fifo_used_tx(struct hfc_chan_simplex *chan)
84
return (*Z1_F1(chan) - *Z2_F1(chan) + chan->fifo_size) % chan->fifo_size;
87
static inline u16 hfc_fifo_free_rx(struct hfc_chan_simplex *chan)
89
u16 free_bytes=*Z2_F1(chan) - *Z1_F1(chan);
94
return free_bytes + chan->fifo_size;
97
static inline u16 hfc_fifo_free_tx(struct hfc_chan_simplex *chan)
99
u16 free_bytes=*Z2_F1(chan) - *Z1_F1(chan);
104
return free_bytes + chan->fifo_size;
107
static inline int hfc_fifo_has_frames(struct hfc_chan_simplex *chan)
109
return *chan->f1 != *chan->f2;
112
static inline u8 hfc_fifo_used_frames(struct hfc_chan_simplex *chan)
114
return (*chan->f1 - *chan->f2 + chan->f_num) % chan->f_num;
117
static inline u8 hfc_fifo_free_frames(struct hfc_chan_simplex *chan)
119
return (*chan->f2 - *chan->f1 + chan->f_num) % chan->f_num;
122
int hfc_fifo_get(struct hfc_chan_simplex *chan, void *data, int size);
123
void hfc_fifo_put(struct hfc_chan_simplex *chan, void *data, int size);
124
void hfc_fifo_drop(struct hfc_chan_simplex *chan, int size);
125
int hfc_fifo_get_frame(struct hfc_chan_simplex *chan, void *data, int max_size);
126
void hfc_fifo_drop_frame(struct hfc_chan_simplex *chan);
127
void hfc_fifo_put_frame(struct hfc_chan_simplex *chan, void *data, int size);
128
void hfc_clear_fifo_rx(struct hfc_chan_simplex *chan);
129
void hfc_clear_fifo_tx(struct hfc_chan_simplex *chan);