Initial import from FreeBSD RELENG_4:
[games.git] / sys / net / i4b / layer1 / iwic / i4b_iwic.h
1 /*
2  * Copyright (c) 1999, 2000 Dave Boyce. 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_iwic - isdn4bsd Winbond W6692 driver
28  *      ----------------------------------------
29  *
30  * $FreeBSD: src/sys/i4b/layer1/iwic/i4b_iwic.h,v 1.2.2.1 2001/08/10 14:08:40 obrien Exp $
31  *
32  *      last edit-date: [Sun Jan 21 11:08:44 2001]
33  *
34  *---------------------------------------------------------------------------*/
35
36 #ifndef _I4B_IWIC_H_
37 #define _I4B_IWIC_H_
38
39 #include <i4b/layer1/iwic/i4b_iwic_ext.h>
40
41 /*---------------------------------------------------------------------------*
42  *      PCI resources used
43  *---------------------------------------------------------------------------*/
44
45 #define INFO_IO_BASES   2
46
47 struct i4b_info {
48         struct resource * io_base[INFO_IO_BASES];
49         int               io_rid [INFO_IO_BASES];
50         struct resource * irq;
51         int               irq_rid;
52         struct resource * mem;
53         int               mem_rid;
54 };
55
56 /*---------------------------------------------------------------------------*
57  *      state of a B channel 
58  *---------------------------------------------------------------------------*/
59 struct iwic_bchan
60 {
61         int unit;                       /* unit number          */
62         int channel;                    /* channel number       */
63         int offset;                     /* offset from iobase   */
64         int bprot;                      /* b channel protocol used */
65         int state;                      /* transceiver state:   */
66 #define ST_IDLE         0x00            /* channel idle         */
67 #define ST_TX_ACTIVE    0x01            /* tx running           */
68
69         int sc_trace_bcount;
70         
71         /* receive data from ISDN */
72
73         struct ifqueue  rx_queue;       /* receiver queue       */
74         int             rxcount;        /* rx statistics counter*/
75         struct mbuf     *in_mbuf;       /* rx input buffer      */
76         u_char          *in_cbptr;      /* curr buffer pointer  */
77         int             in_len;         /* rx input buffer len  */
78
79         /* transmit data to ISDN */
80
81         struct ifqueue  tx_queue;       /* transmitter queue            */
82         int             txcount;        /* tx statistics counter        */
83         struct mbuf     *out_mbuf_head; /* first mbuf in possible chain */
84         struct mbuf     *out_mbuf_cur;  /* current mbuf in possbl chain */
85         unsigned char   *out_mbuf_cur_ptr; /* data pointer into mbuf    */
86         int             out_mbuf_cur_len; /* remaining bytes in mbuf    */
87         
88         /* linktab */
89         
90         isdn_link_t     iwic_isdn_linktab;
91         drvr_link_t     *iwic_drvr_linktab;
92 };
93
94 /*---------------------------------------------------------------------------*
95  *      state of a D channel
96  *---------------------------------------------------------------------------*/
97 struct iwic_dchan
98 {
99         int             enabled;
100         int             trace_count;
101         struct mbuf     *ibuf;
102         u_char          *ibuf_ptr;      /* Input buffer pointer */
103         int             ibuf_len;       /* Current length of input buffer */
104         int             ibuf_max_len;   /* Max length in input buffer */
105         int             rx_count;
106
107         int             tx_ready;       /* Can send next 64 bytes of data. */
108         int             tx_count;
109
110         struct mbuf     *obuf;
111         int             free_obuf;
112         u_char          *obuf_ptr;
113         int             obuf_len;
114
115         struct mbuf     *obuf2;
116         int             free_obuf2;
117 };
118
119 /*---------------------------------------------------------------------------*
120  *      state of one iwic unit
121  *---------------------------------------------------------------------------*/
122 struct iwic_softc
123 {
124         int             sc_unit;
125         u_int32_t       sc_iobase;
126         int             sc_trace;
127         int             sc_cardtyp;
128
129         int             sc_I430state;
130         int             sc_I430T3;
131
132         int             enabled;
133
134         struct iwic_dchan sc_dchan;
135         struct iwic_bchan sc_bchan[2];
136
137         struct i4b_info sc_resources;
138 };
139
140 /*---------------------------------------------------------------------------*
141  *      rd/wr register/fifo macros
142  *---------------------------------------------------------------------------*/
143 #define IWIC_READ(sc,reg)       (inb   ((sc)->sc_iobase + (u_int32_t)(reg)))
144 #define IWIC_WRITE(sc,reg,val)  (outb  ((sc)->sc_iobase + (u_int32_t)(reg), (val)))
145 #define IWIC_WRDFIFO(sc,p,l)    (outsb ((sc)->sc_iobase + D_XFIFO, (p), (l)))
146 #define IWIC_RDDFIFO(sc,p,l)    (insb  ((sc)->sc_iobase + D_RFIFO, (p), (l)))
147 #define IWIC_WRBFIFO(sc,b,p,l)  (outsb (((sc)->sc_iobase + (b)->offset + B_XFIFO), (p), (l)))
148 #define IWIC_RDBFIFO(sc,b,p,l)  (insb  (((sc)->sc_iobase + (b)->offset + B_RFIFO), (p), (l)))
149
150 /*---------------------------------------------------------------------------*
151  *      possible I.430 states
152  *---------------------------------------------------------------------------*/
153 enum I430states
154 {
155         ST_F3N,                 /* F3 Deactivated, no clock     */
156         ST_F3,                  /* F3 Deactivated               */
157         ST_F4,                  /* F4 Awaiting Signal           */
158         ST_F5,                  /* F5 Identifying Input         */
159         ST_F6,                  /* F6 Synchronized              */
160         ST_F7,                  /* F7 Activated                 */
161         ST_F8,                  /* F8 Lost Framing              */
162         ST_ILL,                 /* Illegal State                */
163         N_STATES
164 };
165
166 /*---------------------------------------------------------------------------*
167  *      possible I.430 events
168  *---------------------------------------------------------------------------*/
169 enum I430events
170 {
171         EV_PHAR,                /* PH ACTIVATE REQUEST          */
172         EV_CE,                  /* Clock enabled                */
173         EV_T3,                  /* Timer 3 expired              */
174         EV_INFO0,               /* receiving INFO0              */
175         EV_RSY,                 /* receiving any signal         */
176         EV_INFO2,               /* receiving INFO2              */
177         EV_INFO48,              /* receiving INFO4 pri 8/9      */
178         EV_INFO410,             /* receiving INFO4 pri 10/11    */
179         EV_DR,                  /* Deactivate Request           */
180         EV_PU,                  /* Power UP                     */
181         EV_DIS,                 /* Disconnected (only 2085)     */
182         EV_EI,                  /* Error Indication             */
183         EV_ILL,                 /* Illegal Event                */
184         N_EVENTS
185 };
186
187 /*---------------------------------------------------------------------------*
188  *      available commands
189  *---------------------------------------------------------------------------*/
190 enum I430commands
191 {
192         CMD_ECK,                /* Enable clock                 */
193         CMD_TIM,                /* Timing                       */
194         CMD_RT,                 /* Reset                        */
195         CMD_AR8,                /* Activation request pri 8     */
196         CMD_AR10,               /* Activation request pri 10    */
197         CMD_DIU,                /* Deactivate Indication Upstream */
198         CMD_ILL                 /* Illegal command              */
199 };
200
201
202 extern struct iwic_softc iwic_sc[];
203
204 #define iwic_find_sc(unit)      (&iwic_sc[(unit)])
205
206 extern void iwic_init(struct iwic_softc *);
207 extern void iwic_next_state(struct iwic_softc *, int);
208
209 extern void iwic_dchan_init(struct iwic_softc *);
210 extern void iwic_dchan_xirq(struct iwic_softc *);
211 extern void iwic_dchan_xfer_irq(struct iwic_softc *, int);
212 extern void iwic_dchan_disable(struct iwic_softc *sc);
213 extern int iwic_dchan_data_req(struct iwic_softc *sc, struct mbuf *m, int freeflag);
214 extern void iwic_dchan_transmit(struct iwic_softc *sc);
215
216 char *iwic_printstate(struct iwic_softc *sc);
217
218 void iwic_init_linktab(struct iwic_softc *sc);
219 void iwic_bchan_xirq(struct iwic_softc *, int);
220 void iwic_bchannel_setup(int unit, int h_chan, int bprot, int activate);
221
222 #endif /* _I4B_IWIC_H_ */