2
* zaphfc.h - Dahdi driver for HFC-S PCI A based ISDN BRI cards
4
* Dahdi port by Jose A. Deniz <odicha@hotmail.com>
6
* Copyright (C) 2009 Jose A. Deniz
7
* Copyright (C) 2006 headissue GmbH; Jens Wilke
8
* Copyright (C) 2004 Daniele Orlandi
9
* Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
11
* Jens Wilke <jw_vzaphfc@headissue.com>
13
* Orginal author of this code is
14
* Daniele "Vihai" Orlandi <daniele@orlandi.com>
16
* Major rewrite of the driver made by
17
* Klaus-Peter Junghanns <kpj@junghanns.net>
19
* This program is free software and may be modified and
20
* distributed under the terms of the GNU Public License.
29
#define hfc_DRIVER_NAME "vzaphfc"
30
#define hfc_DRIVER_PREFIX hfc_DRIVER_NAME ": "
31
#define hfc_DRIVER_DESCR "HFC-S PCI A ISDN"
32
#define hfc_DRIVER_VERSION "1.42"
33
#define hfc_DRIVER_STRING hfc_DRIVER_DESCR " (V" hfc_DRIVER_VERSION ")"
35
#define hfc_MAX_BOARDS 32
38
#define PCI_DMA_32BIT 0x00000000ffffffffULL
41
#ifndef PCI_VENDOR_ID_SITECOM
42
#define PCI_VENDOR_ID_SITECOM 0x182D
45
#ifndef PCI_DEVICE_ID_SITECOM_3069
46
#define PCI_DEVICE_ID_SITECOM_3069 0x3069
49
#define hfc_RESET_DELAY 20
51
#define hfc_CLKDEL_TE 0x0f /* CLKDEL in TE mode */
52
#define hfc_CLKDEL_NT 0x6c /* CLKDEL in NT mode */
54
/* PCI memory mapped I/O */
56
#define hfc_PCI_MEM_SIZE 0x0100
57
#define hfc_PCI_MWBA 0x80
59
/* GCI/IOM bus monitor registers */
63
#define hfc_MON1_D 0x28
64
#define hfc_MON2_D 0x2C
67
/* GCI/IOM bus timeslot registers */
69
#define hfc_B1_SSL 0x80
70
#define hfc_B2_SSL 0x84
71
#define hfc_AUX1_SSL 0x88
72
#define hfc_AUX2_SSL 0x8C
73
#define hfc_B1_RSL 0x90
74
#define hfc_B2_RSL 0x94
75
#define hfc_AUX1_RSL 0x98
76
#define hfc_AUX2_RSL 0x9C
78
/* GCI/IOM bus data registers */
82
#define hfc_AUX1_D 0xA8
83
#define hfc_AUX2_D 0xAC
85
/* GCI/IOM bus configuration registers */
87
#define hfc_MST_EMOD 0xB4
88
#define hfc_MST_MODE 0xB8
89
#define hfc_CONNECT 0xBC
92
/* Interrupt and status registers */
94
#define hfc_FIFO_EN 0x44
96
#define hfc_B_MODE 0x4C
97
#define hfc_CHIP_ID 0x58
100
#define hfc_INT_M1 0x68
101
#define hfc_INT_M2 0x6C
102
#define hfc_INT_S1 0x78
103
#define hfc_INT_S2 0x7C
104
#define hfc_STATUS 0x70
106
/* S/T section registers */
108
#define hfc_STATES 0xC0
109
#define hfc_SCTRL 0xC4
110
#define hfc_SCTRL_E 0xC8
111
#define hfc_SCTRL_R 0xCC
113
#define hfc_CLKDEL 0xDC
114
#define hfc_B1_REC 0xF0
115
#define hfc_B1_SEND 0xF0
116
#define hfc_B2_REC 0xF4
117
#define hfc_B2_SEND 0xF4
118
#define hfc_D_REC 0xF8
119
#define hfc_D_SEND 0xF8
120
#define hfc_E_REC 0xFC
122
/* Bits and values in various HFC PCI registers */
124
/* bits in status register (READ) */
125
#define hfc_STATUS_PCI_PROC 0x02
126
#define hfc_STATUS_NBUSY 0x04
127
#define hfc_STATUS_TIMER_ELAP 0x10
128
#define hfc_STATUS_STATINT 0x20
129
#define hfc_STATUS_FRAMEINT 0x40
130
#define hfc_STATUS_ANYINT 0x80
132
/* bits in CTMT (Write) */
133
#define hfc_CTMT_TRANSB1 0x01
134
#define hfc_CTMT_TRANSB2 0x02
135
#define hfc_CTMT_TIMER_CLEAR 0x80
136
#define hfc_CTMT_TIMER_MASK 0x1C
137
#define hfc_CTMT_TIMER_3_125 (0x01 << 2)
138
#define hfc_CTMT_TIMER_6_25 (0x02 << 2)
139
#define hfc_CTMT_TIMER_12_5 (0x03 << 2)
140
#define hfc_CTMT_TIMER_25 (0x04 << 2)
141
#define hfc_CTMT_TIMER_50 (0x05 << 2)
142
#define hfc_CTMT_TIMER_400 (0x06 << 2)
143
#define hfc_CTMT_TIMER_800 (0x07 << 2)
144
#define hfc_CTMT_AUTO_TIMER 0x20
146
/* bits in CIRM (Write) */
147
#define hfc_CIRM_AUX_MSK 0x07
148
#define hfc_CIRM_RESET 0x08
149
#define hfc_CIRM_B1_REV 0x40
150
#define hfc_CIRM_B2_REV 0x80
152
/* bits in INT_M1 and INT_S1 */
153
#define hfc_INTS_B1TRANS 0x01
154
#define hfc_INTS_B2TRANS 0x02
155
#define hfc_INTS_DTRANS 0x04
156
#define hfc_INTS_B1REC 0x08
157
#define hfc_INTS_B2REC 0x10
158
#define hfc_INTS_DREC 0x20
159
#define hfc_INTS_L1STATE 0x40
160
#define hfc_INTS_TIMER 0x80
163
#define hfc_M2_PROC_TRANS 0x01
164
#define hfc_M2_GCI_I_CHG 0x02
165
#define hfc_M2_GCI_MON_REC 0x04
166
#define hfc_M2_IRQ_ENABLE 0x08
167
#define hfc_M2_PMESEL 0x80
170
#define hfc_STATES_STATE_MASK 0x0F
171
#define hfc_STATES_LOAD_STATE 0x10
172
#define hfc_STATES_ACTIVATE 0x20
173
#define hfc_STATES_DO_ACTION 0x40
174
#define hfc_STATES_NT_G2_G3 0x80
176
/* bits in HFCD_MST_MODE */
177
#define hfc_MST_MODE_MASTER 0x01
178
#define hfc_MST_MODE_SLAVE 0x00
179
/* remaining bits are for codecs control */
181
/* bits in HFCD_SCTRL */
182
#define hfc_SCTRL_B1_ENA 0x01
183
#define hfc_SCTRL_B2_ENA 0x02
184
#define hfc_SCTRL_MODE_TE 0x00
185
#define hfc_SCTRL_MODE_NT 0x04
186
#define hfc_SCTRL_LOW_PRIO 0x08
187
#define hfc_SCTRL_SQ_ENA 0x10
188
#define hfc_SCTRL_TEST 0x20
189
#define hfc_SCTRL_NONE_CAP 0x40
190
#define hfc_SCTRL_PWR_DOWN 0x80
192
/* bits in SCTRL_E */
193
#define hfc_SCTRL_E_AUTO_AWAKE 0x01
194
#define hfc_SCTRL_E_DBIT_1 0x04
195
#define hfc_SCTRL_E_IGNORE_COL 0x08
196
#define hfc_SCTRL_E_CHG_B1_B2 0x80
198
/* bits in SCTRL_R */
199
#define hfc_SCTRL_R_B1_ENA 0x01
200
#define hfc_SCTRL_R_B2_ENA 0x02
202
/* bits in FIFO_EN register */
203
#define hfc_FIFOEN_B1TX 0x01
204
#define hfc_FIFOEN_B1RX 0x02
205
#define hfc_FIFOEN_B2TX 0x04
206
#define hfc_FIFOEN_B2RX 0x08
207
#define hfc_FIFOEN_DTX 0x10
208
#define hfc_FIFOEN_DRX 0x20
210
#define hfc_FIFOEN_B1 (hfc_FIFOEN_B1TX|hfc_FIFOEN_B1RX)
211
#define hfc_FIFOEN_B2 (hfc_FIFOEN_B2TX|hfc_FIFOEN_B2RX)
212
#define hfc_FIFOEN_D (hfc_FIFOEN_DTX|hfc_FIFOEN_DRX)
214
/* bits in the CONNECT register */
215
#define hfc_CONNECT_B1_HFC_from_ST 0x00
216
#define hfc_CONNECT_B1_HFC_from_GCI 0x01
217
#define hfc_CONNECT_B1_ST_from_HFC 0x00
218
#define hfc_CONNECT_B1_ST_from_GCI 0x02
219
#define hfc_CONNECT_B1_GCI_from_HFC 0x00
220
#define hfc_CONNECT_B1_GCI_from_ST 0x04
222
#define hfc_CONNECT_B2_HFC_from_ST 0x00
223
#define hfc_CONNECT_B2_HFC_from_GCI 0x08
224
#define hfc_CONNECT_B2_ST_from_HFC 0x00
225
#define hfc_CONNECT_B2_ST_from_GCI 0x10
226
#define hfc_CONNECT_B2_GCI_from_HFC 0x00
227
#define hfc_CONNECT_B2_GCI_from_ST 0x20
229
/* bits in the TRM register */
230
#define hfc_TRM_TRANS_INT_00 0x00
231
#define hfc_TRM_TRANS_INT_01 0x01
232
#define hfc_TRM_TRANS_INT_10 0x02
233
#define hfc_TRM_TRANS_INT_11 0x04
234
#define hfc_TRM_ECHO 0x20
235
#define hfc_TRM_B1_PLUS_B2 0x40
236
#define hfc_TRM_IOM_TEST_LOOP 0x80
238
/* bits in the __SSL and __RSL registers */
239
#define hfc_SRSL_STIO 0x40
240
#define hfc_SRSL_ENABLE 0x80
241
#define hfc_SRCL_SLOT_MASK 0x1f
243
/* FIFO memory definitions */
245
#define hfc_FIFO_SIZE 0x8000
247
#define hfc_UGLY_FRAMEBUF 0x2000
249
#define hfc_TX_FIFO_PRELOAD (DAHDI_CHUNKSIZE + 2)
250
#define hfc_RX_FIFO_PRELOAD 4
253
#define hfc_HDLC_BUF_LEN 32
254
/* arbitrary, just the max # of byts we will send to DAHDI per call */
257
/* NOTE: FIFO pointers are not declared volatile because accesses to the
258
* FIFOs are inherently safe.
262
extern int debug_level;
267
struct hfc_chan_simplex {
268
struct hfc_chan_duplex *chan;
270
u8 zaptel_buffer[DAHDI_CHUNKSIZE];
272
u8 ugly_framebuf[hfc_UGLY_FRAMEBUF];
273
int ugly_framebuf_size;
274
u16 ugly_framebuf_off;
276
void *z1_base, *z2_base;
288
unsigned long long frames;
289
unsigned long long bytes;
290
unsigned long long fifo_full;
291
unsigned long long crc;
292
unsigned long long fifo_underrun;
295
enum hfc_chan_status {
303
struct hfc_chan_duplex {
304
struct hfc_card *card;
309
enum hfc_chan_status status;
313
unsigned short protocol;
317
struct hfc_chan_simplex rx;
318
struct hfc_chan_simplex tx;
322
typedef struct hfc_card {
324
struct pci_dev *pcidev;
325
struct dahdi_hfc *ztdev;
326
struct proc_dir_entry *proc_dir;
327
char proc_dir_name[32];
329
struct proc_dir_entry *proc_info;
330
struct proc_dir_entry *proc_fifos;
331
struct proc_dir_entry *proc_bufs;
333
unsigned long io_bus_mem;
334
void __iomem *io_mem;
336
dma_addr_t fifo_bus_mem;
341
int sync_loss_reported;
346
int ignore_first_timer_interrupt;
361
struct hfc_chan_duplex chans[3];
373
unsigned char *pci_io;
374
void *fifomem; /* start of the shared mem */
377
unsigned int pcidevfn;
381
unsigned char cardno;
382
struct hfc_card *next;
386
typedef struct dahdi_hfc {
387
unsigned int usecount;
388
struct dahdi_span span;
389
struct dahdi_chan chans[3];
390
struct dahdi_chan *_chans[3];
391
struct hfc_card *card;
393
/* pointer to the signalling channel for this span */
394
struct dahdi_chan *sigchan;
395
/* nonzero means we're in the middle of sending an HDLC frame */
397
/* hdlc_hard_xmit() increments, hdlc_tx_frame() decrements */
398
atomic_t hdlc_pending;
404
static inline u8 hfc_inb(struct hfc_card *card, int offset)
406
return readb(card->io_mem + offset);
409
static inline void hfc_outb(struct hfc_card *card, int offset, u8 value)
411
writeb(value, card->io_mem + offset);