~ubuntu-branches/ubuntu/quantal/zaptel/quantal

« back to all changes in this revision

Viewing changes to vzaphfc/vzaphfc.h

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2006-08-23 07:30:22 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20060823073022-nx352q7c5ih5hsdm
Tags: 1:1.2.8.dfsg-1
New Upstream Release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * zaphfc.c - Zaptel driver for HFC-S PCI A based ISDN BRI cards
 
3
 *
 
4
 * Copyright (C) 2006 headissue GmbH; Jens Wilke
 
5
 * Copyright (C) 2004 Daniele Orlandi
 
6
 * Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
 
7
 *
 
8
 * Jens Wilke <jw_vzaphfc@headissue.com>
 
9
 * 
 
10
 * Orginal author of this code is
 
11
 * Daniele "Vihai" Orlandi <daniele@orlandi.com> 
 
12
 *
 
13
 * Major rewrite of the driver made by
 
14
 * Klaus-Peter Junghanns <kpj@junghanns.net>
 
15
 *
 
16
 * This program is free software and may be modified and
 
17
 * distributed under the terms of the GNU Public License.
 
18
 *
 
19
 */
 
20
 
 
21
#ifndef _HFC_ZAPHFC_H
 
22
#define _HFC_ZAPHFC_H
 
23
 
 
24
#include <asm/io.h>
 
25
#include <linux/netdevice.h>
 
26
 
 
27
#include "../zaptel.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 Zaptel Driver"
 
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 LINUX26
 
38
#define IRQ_NONE
 
39
#define IRQ_HANDLED
 
40
#define irqreturn_t void
 
41
#endif
 
42
 
 
43
#ifndef PCI_DMA_32BIT
 
44
#define PCI_DMA_32BIT   0x00000000ffffffffULL
 
45
#endif
 
46
 
 
47
#ifndef PCI_VENDOR_ID_SITECOM
 
48
#define PCI_VENDOR_ID_SITECOM 0x182D
 
49
#endif
 
50
 
 
51
#ifndef PCI_DEVICE_ID_SITECOM_3069
 
52
#define PCI_DEVICE_ID_SITECOM_3069 0x3069
 
53
#endif
 
54
 
 
55
#define hfc_RESET_DELAY 20
 
56
 
 
57
#define hfc_CLKDEL_TE   0x0f    /* CLKDEL in TE mode */
 
58
#define hfc_CLKDEL_NT   0x6c    /* CLKDEL in NT mode */
 
59
 
 
60
/* PCI memory mapped I/O */
 
61
 
 
62
#define hfc_PCI_MEM_SIZE        0x0100
 
63
#define hfc_PCI_MWBA            0x80
 
64
 
 
65
/* GCI/IOM bus monitor registers */
 
66
 
 
67
#define hfc_C_I       0x08
 
68
#define hfc_TRxR      0x0C
 
69
#define hfc_MON1_D    0x28
 
70
#define hfc_MON2_D    0x2C
 
71
 
 
72
 
 
73
/* GCI/IOM bus timeslot registers */
 
74
 
 
75
#define hfc_B1_SSL    0x80
 
76
#define hfc_B2_SSL    0x84
 
77
#define hfc_AUX1_SSL  0x88
 
78
#define hfc_AUX2_SSL  0x8C
 
79
#define hfc_B1_RSL    0x90
 
80
#define hfc_B2_RSL    0x94
 
81
#define hfc_AUX1_RSL  0x98
 
82
#define hfc_AUX2_RSL  0x9C
 
83
 
 
84
/* GCI/IOM bus data registers */
 
85
 
 
86
#define hfc_B1_D      0xA0
 
87
#define hfc_B2_D      0xA4
 
88
#define hfc_AUX1_D    0xA8
 
89
#define hfc_AUX2_D    0xAC
 
90
 
 
91
/* GCI/IOM bus configuration registers */
 
92
 
 
93
#define hfc_MST_EMOD  0xB4
 
94
#define hfc_MST_MODE     0xB8
 
95
#define hfc_CONNECT      0xBC
 
96
 
 
97
 
 
98
/* Interrupt and status registers */
 
99
 
 
100
#define hfc_FIFO_EN   0x44
 
101
#define hfc_TRM       0x48
 
102
#define hfc_B_MODE    0x4C
 
103
#define hfc_CHIP_ID   0x58
 
104
#define hfc_CIRM         0x60
 
105
#define hfc_CTMT         0x64
 
106
#define hfc_INT_M1       0x68
 
107
#define hfc_INT_M2       0x6C
 
108
#define hfc_INT_S1       0x78
 
109
#define hfc_INT_S2       0x7C
 
110
#define hfc_STATUS       0x70
 
111
 
 
112
/* S/T section registers */
 
113
 
 
114
#define hfc_STATES       0xC0
 
115
#define hfc_SCTRL        0xC4
 
116
#define hfc_SCTRL_E   0xC8
 
117
#define hfc_SCTRL_R   0xCC
 
118
#define hfc_SQ           0xD0
 
119
#define hfc_CLKDEL       0xDC
 
120
#define hfc_B1_REC    0xF0
 
121
#define hfc_B1_SEND   0xF0
 
122
#define hfc_B2_REC    0xF4
 
123
#define hfc_B2_SEND   0xF4
 
124
#define hfc_D_REC     0xF8
 
125
#define hfc_D_SEND    0xF8
 
126
#define hfc_E_REC     0xFC
 
127
 
 
128
/* Bits and values in various HFC PCI registers */
 
129
 
 
130
/* bits in status register (READ) */
 
131
#define hfc_STATUS_PCI_PROC   0x02
 
132
#define hfc_STATUS_NBUSY          0x04 
 
133
#define hfc_STATUS_TIMER_ELAP 0x10
 
134
#define hfc_STATUS_STATINT        0x20
 
135
#define hfc_STATUS_FRAMEINT       0x40
 
136
#define hfc_STATUS_ANYINT         0x80
 
137
 
 
138
/* bits in CTMT (Write) */
 
139
#define hfc_CTMT_TRANSB1        0x01
 
140
#define hfc_CTMT_TRANSB2        0x02
 
141
#define hfc_CTMT_TIMER_CLEAR    0x80
 
142
#define hfc_CTMT_TIMER_MASK     0x1C
 
143
#define hfc_CTMT_TIMER_3_125    (0x01 << 2)
 
144
#define hfc_CTMT_TIMER_6_25     (0x02 << 2)
 
145
#define hfc_CTMT_TIMER_12_5     (0x03 << 2)
 
146
#define hfc_CTMT_TIMER_25       (0x04 << 2)
 
147
#define hfc_CTMT_TIMER_50       (0x05 << 2)
 
148
#define hfc_CTMT_TIMER_400      (0x06 << 2)
 
149
#define hfc_CTMT_TIMER_800      (0x07 << 2)
 
150
#define hfc_CTMT_AUTO_TIMER     0x20
 
151
 
 
152
/* bits in CIRM (Write) */
 
153
#define hfc_CIRM_AUX_MSK    0x07
 
154
#define hfc_CIRM_RESET            0x08
 
155
#define hfc_CIRM_B1_REV     0x40
 
156
#define hfc_CIRM_B2_REV     0x80
 
157
 
 
158
/* bits in INT_M1 and INT_S1 */
 
159
#define hfc_INTS_B1TRANS  0x01
 
160
#define hfc_INTS_B2TRANS  0x02
 
161
#define hfc_INTS_DTRANS   0x04
 
162
#define hfc_INTS_B1REC    0x08
 
163
#define hfc_INTS_B2REC    0x10
 
164
#define hfc_INTS_DREC     0x20
 
165
#define hfc_INTS_L1STATE  0x40
 
166
#define hfc_INTS_TIMER    0x80
 
167
 
 
168
/* bits in INT_M2 */
 
169
#define hfc_M2_PROC_TRANS    0x01
 
170
#define hfc_M2_GCI_I_CHG     0x02
 
171
#define hfc_M2_GCI_MON_REC   0x04
 
172
#define hfc_M2_IRQ_ENABLE    0x08
 
173
#define hfc_M2_PMESEL        0x80
 
174
 
 
175
/* bits in STATES */
 
176
#define hfc_STATES_STATE_MASK     0x0F
 
177
#define hfc_STATES_LOAD_STATE    0x10
 
178
#define hfc_STATES_ACTIVATE          0x20
 
179
#define hfc_STATES_DO_ACTION     0x40
 
180
#define hfc_STATES_NT_G2_G3      0x80
 
181
 
 
182
/* bits in HFCD_MST_MODE */
 
183
#define hfc_MST_MODE_MASTER          0x01
 
184
#define hfc_MST_MODE_SLAVE         0x00
 
185
/* remaining bits are for codecs control */
 
186
 
 
187
/* bits in HFCD_SCTRL */
 
188
#define hfc_SCTRL_B1_ENA             0x01
 
189
#define hfc_SCTRL_B2_ENA             0x02
 
190
#define hfc_SCTRL_MODE_TE        0x00
 
191
#define hfc_SCTRL_MODE_NT        0x04
 
192
#define hfc_SCTRL_LOW_PRIO           0x08
 
193
#define hfc_SCTRL_SQ_ENA             0x10
 
194
#define hfc_SCTRL_TEST       0x20
 
195
#define hfc_SCTRL_NONE_CAP           0x40
 
196
#define hfc_SCTRL_PWR_DOWN           0x80
 
197
 
 
198
/* bits in SCTRL_E  */
 
199
#define hfc_SCTRL_E_AUTO_AWAKE    0x01
 
200
#define hfc_SCTRL_E_DBIT_1        0x04
 
201
#define hfc_SCTRL_E_IGNORE_COL    0x08
 
202
#define hfc_SCTRL_E_CHG_B1_B2     0x80
 
203
 
 
204
/* bits in SCTRL_R  */
 
205
#define hfc_SCTRL_R_B1_ENA           0x01
 
206
#define hfc_SCTRL_R_B2_ENA           0x02
 
207
 
 
208
/* bits in FIFO_EN register */
 
209
#define hfc_FIFOEN_B1TX   0x01
 
210
#define hfc_FIFOEN_B1RX   0x02
 
211
#define hfc_FIFOEN_B2TX   0x04
 
212
#define hfc_FIFOEN_B2RX   0x08
 
213
#define hfc_FIFOEN_DTX    0x10
 
214
#define hfc_FIFOEN_DRX    0x20
 
215
 
 
216
#define hfc_FIFOEN_B1     (hfc_FIFOEN_B1TX|hfc_FIFOEN_B1RX)
 
217
#define hfc_FIFOEN_B2     (hfc_FIFOEN_B2TX|hfc_FIFOEN_B2RX)
 
218
#define hfc_FIFOEN_D      (hfc_FIFOEN_DTX|hfc_FIFOEN_DRX)
 
219
 
 
220
/* bits in the CONNECT register */
 
221
#define hfc_CONNECT_B1_HFC_from_ST              0x00
 
222
#define hfc_CONNECT_B1_HFC_from_GCI             0x01
 
223
#define hfc_CONNECT_B1_ST_from_HFC              0x00
 
224
#define hfc_CONNECT_B1_ST_from_GCI              0x02
 
225
#define hfc_CONNECT_B1_GCI_from_HFC             0x00
 
226
#define hfc_CONNECT_B1_GCI_from_ST              0x04
 
227
 
 
228
#define hfc_CONNECT_B2_HFC_from_ST              0x00
 
229
#define hfc_CONNECT_B2_HFC_from_GCI             0x08
 
230
#define hfc_CONNECT_B2_ST_from_HFC              0x00
 
231
#define hfc_CONNECT_B2_ST_from_GCI              0x10
 
232
#define hfc_CONNECT_B2_GCI_from_HFC             0x00
 
233
#define hfc_CONNECT_B2_GCI_from_ST              0x20
 
234
 
 
235
/* bits in the TRM register */
 
236
#define hfc_TRM_TRANS_INT_00    0x00
 
237
#define hfc_TRM_TRANS_INT_01    0x01
 
238
#define hfc_TRM_TRANS_INT_10    0x02
 
239
#define hfc_TRM_TRANS_INT_11    0x04
 
240
#define hfc_TRM_ECHO            0x20
 
241
#define hfc_TRM_B1_PLUS_B2      0x40
 
242
#define hfc_TRM_IOM_TEST_LOOP   0x80
 
243
 
 
244
/* bits in the __SSL and __RSL registers */
 
245
#define hfc_SRSL_STIO           0x40
 
246
#define hfc_SRSL_ENABLE         0x80
 
247
#define hfc_SRCL_SLOT_MASK      0x1f
 
248
 
 
249
/* FIFO memory definitions */
 
250
 
 
251
#define hfc_FIFO_SIZE   0x8000
 
252
 
 
253
#define hfc_UGLY_FRAMEBUF 0x2000
 
254
 
 
255
#define hfc_TX_FIFO_PRELOAD ZT_CHUNKSIZE + 2
 
256
#define hfc_RX_FIFO_PRELOAD 4
 
257
 
 
258
/* NOTE: FIFO pointers are not declared volatile because accesses to the
 
259
 *       FIFOs are inherently safe.
 
260
 */
 
261
 
 
262
#ifdef DEBUG
 
263
extern int debug_level;
 
264
#endif
 
265
 
 
266
struct hfc_chan;
 
267
 
 
268
struct hfc_chan_simplex {
 
269
        struct hfc_chan_duplex *chan;
 
270
 
 
271
        u8 zaptel_buffer[ZT_CHUNKSIZE];
 
272
 
 
273
        u8 ugly_framebuf[hfc_UGLY_FRAMEBUF];
 
274
        int ugly_framebuf_size;
 
275
        u16 ugly_framebuf_off;
 
276
 
 
277
        void *z1_base,*z2_base;
 
278
        void *fifo_base;
 
279
        void *z_base;
 
280
        u16 z_min;
 
281
        u16 z_max;
 
282
        u16 fifo_size;
 
283
 
 
284
        u8 *f1,*f2;
 
285
        u8 f_min;
 
286
        u8 f_max;
 
287
        u8 f_num;
 
288
        
 
289
        unsigned long long frames;
 
290
        unsigned long long bytes;
 
291
        unsigned long long fifo_full;
 
292
        unsigned long long crc;
 
293
        unsigned long long fifo_underrun;
 
294
};
 
295
 
 
296
enum hfc_chan_status {
 
297
        free,
 
298
        open_framed,
 
299
        open_voice,
 
300
        sniff_aux,
 
301
        loopback,
 
302
};
 
303
 
 
304
struct hfc_chan_duplex {
 
305
        struct hfc_card *card;
 
306
 
 
307
        char *name;
 
308
        int number;
 
309
 
 
310
        enum hfc_chan_status status;
 
311
        int open_by_netdev;
 
312
        int open_by_zaptel;
 
313
 
 
314
        unsigned short protocol;
 
315
 
 
316
        spinlock_t lock;
 
317
 
 
318
        struct hfc_chan_simplex rx;
 
319
        struct hfc_chan_simplex tx;
 
320
 
 
321
        struct net_device *netdev;
 
322
        struct net_device_stats net_device_stats;
 
323
};
 
324
 
 
325
typedef struct hfc_card {
 
326
        int cardnum;
 
327
        spinlock_t lock;
 
328
 
 
329
        int ticks;
 
330
 
 
331
        struct pci_dev *pcidev;
 
332
 
 
333
        struct proc_dir_entry *proc_dir;
 
334
        char proc_dir_name[32];
 
335
 
 
336
        struct proc_dir_entry *proc_info;
 
337
        struct proc_dir_entry *proc_fifos;
 
338
        struct proc_dir_entry *proc_bufs;
 
339
 
 
340
        unsigned long io_bus_mem;
 
341
        void *io_mem;
 
342
 
 
343
        dma_addr_t fifo_bus_mem;
 
344
        void *fifo_mem;
 
345
        void *fifos;
 
346
 
 
347
        int nt_mode;
 
348
        int sync_loss_reported;
 
349
        int late_irqs;
 
350
 
 
351
        u8 l1_state;
 
352
        int fifo_suspended;
 
353
        int ignore_first_timer_interrupt;
 
354
 
 
355
        struct {
 
356
                u8 m1;
 
357
                u8 m2;
 
358
                u8 fifo_en;
 
359
                u8 trm;
 
360
                u8 connect;
 
361
                u8 sctrl;
 
362
                u8 sctrl_r;
 
363
                u8 sctrl_e;
 
364
                u8 ctmt;
 
365
                u8 cirm;
 
366
        } regs;
 
367
 
 
368
        struct hfc_chan_duplex chans[3];
 
369
        int echo_enabled;
 
370
 
 
371
        struct zt_span zt_span;
 
372
        struct zt_chan zt_chans[3];
 
373
 
 
374
        int debug_event;
 
375
} hfc_card;
 
376
 
 
377
static inline u8 hfc_inb(struct hfc_card *card, int offset)
 
378
{
 
379
 return readb(card->io_mem + offset);
 
380
}
 
381
 
 
382
static inline void hfc_outb(struct hfc_card *card, int offset, u8 value)
 
383
{
 
384
 writeb(value, card->io_mem + offset);
 
385
}
 
386
 
 
387
#endif