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