~ubuntu-branches/ubuntu/trusty/dahdi-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to drivers/dahdi/zaphfc/zaphfc.h

  • Committer: Stefan Lesicnik
  • Date: 2010-11-10 13:41:13 UTC
  • mfrom: (3.1.5 sid)
  • Revision ID: stefan@lsd.co.za-20101110134113-esykqtd368dxm2vp
bzr merge of Debian 1:2.3.0.1+dfsg-2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * zaphfc.h - Dahdi driver for HFC-S PCI A based ISDN BRI cards
 
3
 *
 
4
 * Dahdi port by Jose A. Deniz <odicha@hotmail.com>
 
5
 *
 
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
 
10
 *
 
11
 * Jens Wilke <jw_vzaphfc@headissue.com>
 
12
 *
 
13
 * Orginal author of this code is
 
14
 * Daniele "Vihai" Orlandi <daniele@orlandi.com>
 
15
 *
 
16
 * Major rewrite of the driver made by
 
17
 * Klaus-Peter Junghanns <kpj@junghanns.net>
 
18
 *
 
19
 * This program is free software and may be modified and
 
20
 * distributed under the terms of the GNU Public License.
 
21
 *
 
22
 */
 
23
 
 
24
#ifndef _HFC_ZAPHFC_H
 
25
#define _HFC_ZAPHFC_H
 
26
 
 
27
#include <asm/io.h>
 
28
 
 
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 ")"
 
34
 
 
35
#define hfc_MAX_BOARDS 32
 
36
 
 
37
#ifndef PCI_DMA_32BIT
 
38
#define PCI_DMA_32BIT   0x00000000ffffffffULL
 
39
#endif
 
40
 
 
41
#ifndef PCI_VENDOR_ID_SITECOM
 
42
#define PCI_VENDOR_ID_SITECOM 0x182D
 
43
#endif
 
44
 
 
45
#ifndef PCI_DEVICE_ID_SITECOM_3069
 
46
#define PCI_DEVICE_ID_SITECOM_3069 0x3069
 
47
#endif
 
48
 
 
49
#define hfc_RESET_DELAY 20
 
50
 
 
51
#define hfc_CLKDEL_TE   0x0f    /* CLKDEL in TE mode */
 
52
#define hfc_CLKDEL_NT   0x6c    /* CLKDEL in NT mode */
 
53
 
 
54
/* PCI memory mapped I/O */
 
55
 
 
56
#define hfc_PCI_MEM_SIZE        0x0100
 
57
#define hfc_PCI_MWBA            0x80
 
58
 
 
59
/* GCI/IOM bus monitor registers */
 
60
 
 
61
#define hfc_C_I       0x08
 
62
#define hfc_TRxR      0x0C
 
63
#define hfc_MON1_D    0x28
 
64
#define hfc_MON2_D    0x2C
 
65
 
 
66
 
 
67
/* GCI/IOM bus timeslot registers */
 
68
 
 
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
 
77
 
 
78
/* GCI/IOM bus data registers */
 
79
 
 
80
#define hfc_B1_D      0xA0
 
81
#define hfc_B2_D      0xA4
 
82
#define hfc_AUX1_D    0xA8
 
83
#define hfc_AUX2_D    0xAC
 
84
 
 
85
/* GCI/IOM bus configuration registers */
 
86
 
 
87
#define hfc_MST_EMOD  0xB4
 
88
#define hfc_MST_MODE     0xB8
 
89
#define hfc_CONNECT      0xBC
 
90
 
 
91
 
 
92
/* Interrupt and status registers */
 
93
 
 
94
#define hfc_FIFO_EN   0x44
 
95
#define hfc_TRM       0x48
 
96
#define hfc_B_MODE    0x4C
 
97
#define hfc_CHIP_ID   0x58
 
98
#define hfc_CIRM         0x60
 
99
#define hfc_CTMT         0x64
 
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
 
105
 
 
106
/* S/T section registers */
 
107
 
 
108
#define hfc_STATES       0xC0
 
109
#define hfc_SCTRL        0xC4
 
110
#define hfc_SCTRL_E   0xC8
 
111
#define hfc_SCTRL_R   0xCC
 
112
#define hfc_SQ           0xD0
 
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
 
121
 
 
122
/* Bits and values in various HFC PCI registers */
 
123
 
 
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
 
131
 
 
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
 
145
 
 
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
 
151
 
 
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
 
161
 
 
162
/* bits in INT_M2 */
 
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
 
168
 
 
169
/* bits in STATES */
 
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
 
175
 
 
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 */
 
180
 
 
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
 
191
 
 
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
 
197
 
 
198
/* bits in SCTRL_R  */
 
199
#define hfc_SCTRL_R_B1_ENA           0x01
 
200
#define hfc_SCTRL_R_B2_ENA           0x02
 
201
 
 
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
 
209
 
 
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)
 
213
 
 
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
 
221
 
 
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
 
228
 
 
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
 
237
 
 
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
 
242
 
 
243
/* FIFO memory definitions */
 
244
 
 
245
#define hfc_FIFO_SIZE   0x8000
 
246
 
 
247
#define hfc_UGLY_FRAMEBUF 0x2000
 
248
 
 
249
#define hfc_TX_FIFO_PRELOAD (DAHDI_CHUNKSIZE + 2)
 
250
#define hfc_RX_FIFO_PRELOAD 4
 
251
 
 
252
/* HDLC STUFF */
 
253
#define hfc_HDLC_BUF_LEN        32
 
254
/* arbitrary, just the max # of byts we will send to DAHDI per call */
 
255
 
 
256
 
 
257
/* NOTE: FIFO pointers are not declared volatile because accesses to the
 
258
 *       FIFOs are inherently safe.
 
259
 */
 
260
 
 
261
#ifdef DEBUG
 
262
extern int debug_level;
 
263
#endif
 
264
 
 
265
struct hfc_chan;
 
266
 
 
267
struct hfc_chan_simplex {
 
268
        struct hfc_chan_duplex *chan;
 
269
 
 
270
        u8 zaptel_buffer[DAHDI_CHUNKSIZE];
 
271
 
 
272
        u8 ugly_framebuf[hfc_UGLY_FRAMEBUF];
 
273
        int ugly_framebuf_size;
 
274
        u16 ugly_framebuf_off;
 
275
 
 
276
        void *z1_base, *z2_base;
 
277
        void *fifo_base;
 
278
        void *z_base;
 
279
        u16 z_min;
 
280
        u16 z_max;
 
281
        u16 fifo_size;
 
282
 
 
283
        u8 *f1, *f2;
 
284
        u8 f_min;
 
285
        u8 f_max;
 
286
        u8 f_num;
 
287
 
 
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;
 
293
};
 
294
 
 
295
enum hfc_chan_status {
 
296
        free,
 
297
        open_framed,
 
298
        open_voice,
 
299
        sniff_aux,
 
300
        loopback,
 
301
};
 
302
 
 
303
struct hfc_chan_duplex {
 
304
        struct hfc_card *card;
 
305
 
 
306
        char *name;
 
307
        int number;
 
308
 
 
309
        enum hfc_chan_status status;
 
310
        int open_by_netdev;
 
311
        int open_by_zaptel;
 
312
 
 
313
        unsigned short protocol;
 
314
 
 
315
        spinlock_t lock;
 
316
 
 
317
        struct hfc_chan_simplex rx;
 
318
        struct hfc_chan_simplex tx;
 
319
 
 
320
};
 
321
 
 
322
typedef struct hfc_card {
 
323
        int cardnum;
 
324
        struct pci_dev *pcidev;
 
325
        struct dahdi_hfc *ztdev;
 
326
        struct proc_dir_entry *proc_dir;
 
327
        char proc_dir_name[32];
 
328
 
 
329
        struct proc_dir_entry *proc_info;
 
330
        struct proc_dir_entry *proc_fifos;
 
331
        struct proc_dir_entry *proc_bufs;
 
332
 
 
333
        unsigned long io_bus_mem;
 
334
        void __iomem *io_mem;
 
335
 
 
336
        dma_addr_t fifo_bus_mem;
 
337
        void *fifo_mem;
 
338
        void *fifos;
 
339
 
 
340
        int nt_mode;
 
341
        int sync_loss_reported;
 
342
        int late_irqs;
 
343
 
 
344
        u8 l1_state;
 
345
        int fifo_suspended;
 
346
        int ignore_first_timer_interrupt;
 
347
 
 
348
        struct {
 
349
                u8 m1;
 
350
                u8 m2;
 
351
                u8 fifo_en;
 
352
                u8 trm;
 
353
                u8 connect;
 
354
                u8 sctrl;
 
355
                u8 sctrl_r;
 
356
                u8 sctrl_e;
 
357
                u8 ctmt;
 
358
                u8 cirm;
 
359
        } regs;
 
360
 
 
361
        struct hfc_chan_duplex chans[3];
 
362
        int echo_enabled;
 
363
 
 
364
 
 
365
 
 
366
        int debug_event;
 
367
 
 
368
    spinlock_t lock;
 
369
    unsigned int irq;
 
370
    unsigned int iomem;
 
371
    int ticks;
 
372
    int clicks;
 
373
    unsigned char *pci_io;
 
374
    void *fifomem;              /* start of the shared mem */
 
375
 
 
376
    unsigned int pcibus;
 
377
    unsigned int pcidevfn;
 
378
 
 
379
    int drecinframe;
 
380
 
 
381
    unsigned char cardno;
 
382
    struct hfc_card *next;
 
383
 
 
384
} hfc_card;
 
385
 
 
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;
 
392
 
 
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 */
 
396
    int sigactive;
 
397
    /* hdlc_hard_xmit() increments, hdlc_tx_frame() decrements */
 
398
    atomic_t hdlc_pending;
 
399
    int frames_out;
 
400
    int frames_in;
 
401
 
 
402
} dahdi_hfc;
 
403
 
 
404
static inline u8 hfc_inb(struct hfc_card *card, int offset)
 
405
{
 
406
 return readb(card->io_mem + offset);
 
407
}
 
408
 
 
409
static inline void hfc_outb(struct hfc_card *card, int offset, u8 value)
 
410
{
 
411
 writeb(value, card->io_mem + offset);
 
412
}
 
413
 
 
414
#endif