]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i4b/layer1/i4b_l1.h
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / sys / i4b / layer1 / i4b_l1.h
1 /*
2  * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  *---------------------------------------------------------------------------*
26  *
27  *      i4b_l1.h - isdn4bsd layer 1 header file
28  *      ---------------------------------------
29  *
30  *      $Id: i4b_l1.h,v 1.3 1999/12/13 21:25:26 hm Exp $ 
31  *
32  * $FreeBSD$
33  *
34  *      last edit-date: [Mon Dec 13 22:02:07 1999]
35  *
36  *---------------------------------------------------------------------------*/
37
38 #ifndef I4B_L1_H_
39 #define I4B_L1_H_
40
41 #include <sys/resource.h>
42 #include <sys/bus.h>
43 #include <i386/include/bus.h>
44 #include <sys/rman.h>
45 #include <i386/include/resource.h>
46
47 #include <i4b/include/i4b_l3l4.h>
48
49 /*---------------------------------------------------------------------------
50  *      kernel config file flags definition
51  *---------------------------------------------------------------------------*/
52 #define FLAG_TELES_S0_8         1
53 #define FLAG_TELES_S0_16        2
54 #define FLAG_TELES_S0_163       3
55 #define FLAG_AVM_A1             4
56 #define FLAG_TELES_S0_163_PnP   5
57 #define FLAG_CREATIX_S0_PnP     6
58 #define FLAG_USR_ISDN_TA_INT    7
59 #define FLAG_DRN_NGO            8
60 #define FLAG_SWS                9
61 #define FLAG_AVM_A1_PCMCIA      10
62 #define FLAG_DYNALINK           11
63 #define FLAG_BLMASTER           12
64 #define FLAG_ELSA_QS1P_ISA      13
65 #define FLAG_ELSA_QS1P_PCI      14
66 #define FLAG_SIEMENS_ITALK      15
67 #define FLAG_ELSA_MLIMC         16
68 #define FLAG_ELSA_MLMCALL       17
69 #define FLAG_ITK_IX1            18
70 #define FLAG_AVMA1PCI           19
71 #define FLAG_ELSA_PCC16         20
72 #define FLAG_AVM_PNP            21
73 #define FLAG_SIEMENS_ISURF2     22
74 #define FLAG_ASUSCOM_IPAC       23
75
76 #define SEC_DELAY               1000000 /* one second DELAY for DELAY*/
77
78 #define MAX_DFRAME_LEN          264     /* max length of a D frame */
79
80 #define min(a,b)                ((a)<(b)?(a):(b))
81
82 #define INFO_IO_BASES   50      /* 49 needed for USR */
83
84 struct i4b_info {
85         struct resource * io_base[INFO_IO_BASES];
86         int               io_rid [INFO_IO_BASES];
87         struct resource * irq;
88         int               irq_rid;
89         struct resource * mem;
90         int               mem_rid;
91 };
92
93 /*---------------------------------------------------------------------------*
94  *      l1_bchan_state: the state of one B channel
95  *---------------------------------------------------------------------------*/
96 typedef struct
97 {
98         int             unit;           /* cards unit number    */
99         int             channel;        /* which channel is this*/
100         caddr_t         hscx;           /* HSCX address         */
101         u_char          hscx_mask;      /* HSCX interrupt mask  */
102         int             bprot;          /* B channel protocol   */
103         int             state;          /* this channels state  */
104 #define HSCX_IDLE       0x00            /* channel idle         */
105 #define HSCX_TX_ACTIVE  0x01            /* tx running           */
106
107         /* receive data from ISDN */
108
109         struct ifqueue  rx_queue;       /* receiver queue       */
110
111         int             rxcount;        /* rx statistics counter*/
112
113         struct  mbuf    *in_mbuf;       /* rx input buffer      */
114         u_char          *in_cbptr;      /* curr buffer pointer  */
115         int             in_len;         /* rx input buffer len  */
116         
117         /* transmit data to ISDN */
118
119         struct ifqueue  tx_queue;       /* transmitter queue    */
120
121         int             txcount;        /* tx statistics counter*/
122
123         struct mbuf     *out_mbuf_head; /* first mbuf in possible chain */
124         struct mbuf     *out_mbuf_cur;  /* current mbuf in possbl chain */
125         unsigned char   *out_mbuf_cur_ptr; /* data pointer into mbuf    */
126         int             out_mbuf_cur_len; /* remaining bytes in mbuf    */      
127         
128         /* link between b channel and driver */
129         
130         isdn_link_t     isdn_linktab;   /* b channel addresses  */
131         drvr_link_t     *drvr_linktab;  /* ptr to driver linktab*/
132
133         /* statistics */
134
135         /* RSTA */
136         
137         int             stat_VFR;       /* HSCX RSTA Valid FRame */
138         int             stat_RDO;       /* HSCX RSTA Rx Data Overflow */        
139         int             stat_CRC;       /* HSCX RSTA CRC */
140         int             stat_RAB;       /* HSCX RSTA Rx message ABorted */
141
142         /* EXIR */
143
144         int             stat_XDU;       /* HSCX EXIR tx data underrun */
145         int             stat_RFO;       /* HSCX EXIR rx frame overflow */
146         
147 } l1_bchan_state_t;
148
149 /*---------------------------------------------------------------------------*
150  *      l1_softc: the state of the layer 1 of the D channel
151  *---------------------------------------------------------------------------*/
152 struct l1_softc
153 {
154         int             sc_unit;        /* unit number          */
155         int             sc_irq;         /* interrupt vector     */
156         struct i4b_info sc_resources;
157         int             sc_flags;
158
159         int             sc_port;        /* port base address    */
160
161         int             sc_cardtyp;     /* CARD_TYPEP_xxxx      */
162
163         int             sc_bustyp;      /* IOM1 or IOM2         */
164 #define BUS_TYPE_IOM1  0x01
165 #define BUS_TYPE_IOM2  0x02
166
167         int             sc_trace;       /* output protocol data for tracing */
168         unsigned int    sc_trace_dcount;/* d channel trace frame counter */
169         unsigned int    sc_trace_bcount;/* b channel trace frame counter */
170
171         int             sc_state;       /* ISAC state flag      */
172 #define ISAC_IDLE       0x00            /* state = idle */
173 #define ISAC_TX_ACTIVE  0x01            /* state = transmitter active */
174
175         int             sc_init_tries;  /* no of out tries to access S0 */
176         
177         caddr_t         sc_vmem_addr;   /* card RAM virtual memory base */
178         caddr_t         sc_isac;        /* ISAC port base addr  */
179 #define ISAC_BASE       (sc->sc_isac)
180
181         caddr_t         sc_ipacbase;    /* IPAC port base addr  */
182 #define IPAC_BASE       (sc->sc_ipacbase)
183
184         u_char          sc_isac_mask;   /* ISAC IRQ mask        */
185 #define ISAC_IMASK      (sc->sc_isac_mask)
186
187         l1_bchan_state_t        sc_chan[2];     /* B-channel state      */
188 #define HSCX_A_BASE     (sc->sc_chan[0].hscx)
189 #define HSCX_A_IMASK    (sc->sc_chan[0].hscx_mask)
190 #define HSCX_B_BASE     (sc->sc_chan[1].hscx)
191 #define HSCX_B_IMASK    (sc->sc_chan[1].hscx_mask)
192
193         struct mbuf     *sc_ibuf;       /* input buffer mgmt    */
194         u_short         sc_ilen;
195         u_char          *sc_ib;
196                                         /* this is for the irq TX routine */
197         struct mbuf     *sc_obuf;       /* pointer to an mbuf with TX frame */
198         u_char          *sc_op;         /* ptr to next chunk of frame to tx */
199         int             sc_ol;          /* length of remaining frame to tx */
200         int             sc_freeflag;    /* m_freem mbuf if set */
201
202         struct mbuf     *sc_obuf2;      /* pointer to an mbuf with TX frame */
203         int             sc_freeflag2;   /* m_freem mbuf if set */       
204         
205         int             sc_isac_version;        /* version number of ISAC */
206         int             sc_hscx_version;        /* version number of HSCX */
207
208         int             sc_I430state;   /* I.430 state F3 .... F8 */
209
210         int             sc_I430T3;      /* I.430 Timer T3 running */    
211
212         struct callout_handle sc_T3_callout;
213
214         int             sc_I430T4;      /* Timer T4 running */  
215
216         struct callout_handle sc_T4_callout;
217
218         /*
219          * byte fields for the AVM Fritz!Card PCI. These are packed into
220          * a u_int in the driver.
221          */
222         u_char          avma1pp_cmd;
223         u_char          avma1pp_txl;
224         u_char          avma1pp_prot;
225
226         int             sc_enabled;     /* daemon is running */
227
228         int             sc_ipac;        /* flag, running on ipac */
229         int             sc_bfifolen;    /* length of b channel fifos */
230
231 #define ISIC_WHAT_ISAC  0
232 #define ISIC_WHAT_HSCXA 1
233 #define ISIC_WHAT_HSCXB 2
234 #define ISIC_WHAT_IPAC  3
235
236         u_int8_t (*readreg)   (struct l1_softc *sc, int what, bus_size_t offs);
237         void     (*writereg)  (struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data);
238         void     (*readfifo)  (struct l1_softc *sc, int what, void *buf, size_t size);
239         void     (*writefifo) (struct l1_softc *sc, int what, void *data, size_t size);
240         void     (*clearirq)  (struct l1_softc *sc);
241
242 #define ISAC_READ(r)            (*sc->readreg)(sc, ISIC_WHAT_ISAC, (r))
243 #define ISAC_WRITE(r,v)         (*sc->writereg)(sc, ISIC_WHAT_ISAC, (r), (v))
244 #define ISAC_RDFIFO(b,s)        (*sc->readfifo)(sc, ISIC_WHAT_ISAC, (b), (s))
245 #define ISAC_WRFIFO(b,s)        (*sc->writefifo)(sc, ISIC_WHAT_ISAC, (b), (s))
246
247 #define HSCX_READ(n,r)          (*sc->readreg)(sc, ISIC_WHAT_HSCXA+(n), (r))
248 #define HSCX_WRITE(n,r,v)       (*sc->writereg)(sc, ISIC_WHAT_HSCXA+(n), (r), (v))
249 #define HSCX_RDFIFO(n,b,s)      (*sc->readfifo)(sc, ISIC_WHAT_HSCXA+(n), (b), (s))
250 #define HSCX_WRFIFO(n,b,s)      (*sc->writefifo)(sc, ISIC_WHAT_HSCXA+(n), (b), (s))
251
252 #define IPAC_READ(r)            (*sc->readreg)(sc, ISIC_WHAT_IPAC, (r))
253 #define IPAC_WRITE(r, v)        (*sc->writereg)(sc, ISIC_WHAT_IPAC, (r), (v))
254 };
255
256 /*---------------------------------------------------------------------------*
257  *      possible I.430/ISAC states
258  *---------------------------------------------------------------------------*/
259 enum I430states {
260         ST_F3,          /* F3 Deactivated       */
261         ST_F4,          /* F4 Awaiting Signal   */
262         ST_F5,          /* F5 Identifying Input */
263         ST_F6,          /* F6 Synchronized      */
264         ST_F7,          /* F7 Activated         */
265         ST_F8,          /* F8 Lost Framing      */
266         ST_ILL,         /* Illegal State        */      
267         N_STATES
268 };
269
270 /*---------------------------------------------------------------------------*
271  *      possible I.430/ISAC events
272  *---------------------------------------------------------------------------*/
273 enum I430events {
274         EV_PHAR,        /* PH ACTIVATE REQUEST          */
275         EV_T3,          /* Timer 3 expired              */
276         EV_INFO0,       /* receiving INFO0              */
277         EV_RSY,         /* receiving any signal         */
278         EV_INFO2,       /* receiving INFO2              */
279         EV_INFO48,      /* receiving INFO4 pri 8/9      */
280         EV_INFO410,     /* receiving INFO4 pri 10/11    */      
281         EV_DR,          /* Deactivate Request           */      
282         EV_PU,          /* Power UP                     */
283         EV_DIS,         /* Disconnected (only 2085)     */
284         EV_EI,          /* Error Indication             */
285         EV_ILL,         /* Illegal Event                */
286         N_EVENTS
287 };
288
289 enum I430commands {
290         CMD_TIM,        /*      Timing                          */
291         CMD_RS,         /*      Reset                           */
292         CMD_AR8,        /*      Activation request pri 8        */
293         CMD_AR10,       /*      Activation request pri 10       */
294         CMD_DIU,        /*      Deactivate Indication Upstream  */
295         CMD_ILL         /*      Illegal command                 */
296 };
297
298 #define N_COMMANDS CMD_ILL
299
300
301 extern struct l1_softc l1_sc[];
302
303 extern void isicintr(struct l1_softc *sc);
304 extern int  isic_attach_common(device_t dev);
305 extern void isic_detach_common(device_t dev);
306 extern void isic_recover(struct l1_softc *sc);
307
308 extern void isic_bchannel_setup (int unit, int hscx_channel, int bprot, int activate );
309
310 extern void isic_init_linktab ( struct l1_softc *sc );
311 extern int  isic_isac_init ( struct l1_softc *sc );
312 extern void isic_isac_irq ( struct l1_softc *sc, int r );
313 extern void isic_isac_l1_cmd ( struct l1_softc *sc, int command );
314 extern void isic_next_state ( struct l1_softc *sc, int event );
315 extern char *isic_printstate ( struct l1_softc *sc );
316
317 extern int  isic_hscx_fifo(l1_bchan_state_t *, struct l1_softc *);
318 extern void isic_hscx_init ( struct l1_softc *sc, int hscx_channel, int activate );
319 extern void isic_hscx_irq ( struct l1_softc *sc, u_char ista, int hscx_channel, u_char ex_irq );
320 extern int  isic_hscx_silence ( unsigned char *data, int len );
321 extern void isic_hscx_cmd( struct l1_softc *sc, int h_chan, unsigned char cmd );
322 extern void isic_hscx_waitxfw( struct l1_softc *sc, int h_chan );
323
324 extern int  isic_probe_s016 (device_t dev);
325 extern int  isic_attach_s016 (device_t dev);
326
327 extern int  isic_probe_s08 (device_t dev);
328 extern int  isic_attach_s08 (device_t dev);
329
330 extern int  isic_probe_Epcc16 (device_t dev);
331 extern int  isic_attach_Epcc16 (device_t dev);
332
333 extern int  isic_probe_s0163 (device_t dev);
334 extern int  isic_attach_s0163 (device_t dev);
335
336 extern int  isic_probe_avma1 (device_t dev);
337 extern int  isic_attach_avma1 (device_t dev);
338
339 extern int  isic_attach_drnngo (device_t dev);
340 extern int  isic_attach_Cs0P (device_t dev);
341 extern int  isic_attach_Eqs1pi(device_t dev);
342 extern int  isic_attach_sws(device_t dev);
343 extern int  isic_attach_siemens_isurf(device_t dev);
344 extern int  isic_attach_asi(device_t dev);
345
346
347 #endif /* I4B_L1_H_ */