Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / net / i4b / layer1 / ihfc / i4b_ihfc.h
1 /*
2  * Copyright (c) 2000 Hans Petter Selasky. 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_ihfc.h - ihfc common header file
28  *      ------------------------------------
29  *
30  *      last edit-date: [Wed Jul 19 09:40:45 2000]
31  *
32  *      $Id: i4b_ihfc.h,v 1.9 2000/09/19 13:50:36 hm Exp $
33  *
34  * $FreeBSD: src/sys/i4b/layer1/ihfc/i4b_ihfc.h,v 1.1.2.1 2001/08/10 14:08:37 obrien Exp $
35  * $DragonFly: src/sys/net/i4b/layer1/ihfc/i4b_ihfc.h,v 1.2 2003/06/17 04:28:40 dillon Exp $
36  *
37  *---------------------------------------------------------------------------*/
38
39 #ifndef _I4B_IHFC_H_
40 #define _I4B_IHFC_H_
41
42 #include <i4b/include/i4b_l3l4.h>
43
44 /*---------------------------------------------------------------------------*
45  *      global stuff                                            (HFC-1/S/SP)
46  *---------------------------------------------------------------------------*/
47 #define DCH_MAX_LEN             264     /* max length of a D frame */
48
49 #define IHFC_ACTIVATION_TIMEOUT 3*hz    /* S0-bus must activate before this time */
50
51 #define IHFC_IO_BASES           1
52
53 #define IHFC_DISBUSYTO          500     /* do at least 500 inb's before giving up */
54 #define IHFC_NONBUSYTO          8000    /* do at least 8000 inb's before giving up */
55
56 #define IHFC_NTMODE             0       /* use TE-mode as default        */
57 #define IHFC_DLP                0       /* use (8/9) priority as default */
58
59 #define IHFC_MAXUNIT            4
60
61 /* #define IHFC_DEBUG   internal debugging enabled  *
62  * #undef  IHFC_DEBUG   internal debugging disabled */
63
64 /* chan:           *
65  * 0 - D1 (tx)     *
66  * 1 - D1 (rx)     *
67  * 2 - B1 (tx)     *
68  * 3 - B1 (rx)     *
69  * 4 - B2 (tx)     *
70  * 5 - B2 (rx)     */
71
72 #define HFC_1                   0x01    /* HFC          2B      */
73 #define HFC_S                   0x02    /* HFC - S      2BDS0   */
74 #define HFC_SP                  0x04    /* HFC - SP     2BDS0   */
75 #define HFC_SPCI                0x08    /* HFC - SPCI   2BDS0 X */
76 #define HFC_S2M                 0x10    /* HFC - S2M    2BDS0 X */
77 #define HFC_USB                 0x20    /* HFC - USB    2BDS0 X */
78
79 /*---------------------------------------------------------------------------*
80  *      "Help Fix Corruption" macros                            (HFC-1/S/SP)
81  *
82  *      NOTE: If the code does not run at splhigh, we will sporadically
83  *      lose bytes. On fast PC's (200 Mhz), this is very little noticable.
84  *---------------------------------------------------------------------------*/
85 #define HFC_VAR int _s_                 /* declare variable     */
86 #define HFC_BEG _s_ = splhigh()         /* save spl             */
87 #define HFC_END splx(_s_)               /* restore spl          */
88
89 /*---------------------------------------------------------------------------*
90  *      macros related to i4b linking                           (HFC-1/S/SP)
91  *---------------------------------------------------------------------------*/
92 #define S_BLINK         sc->sc_blinktab[(chan > 3) ? 1 : 0]
93 #define S_BDRVLINK      sc->sc_bdrvlinktab[(chan > 3) ? 1 : 0]
94
95 /*---------------------------------------------------------------------------*
96  *      macros related to ihfc_sc                               (HFC-1/S/SP)
97  *---------------------------------------------------------------------------*/
98
99 /* statemachine */
100
101 #define S_IOM2          (sc->sc_config.i_adf2 & 0x80)
102         /* 0x80: IOM2 mode selected */
103
104 #define S_DLP           (sc->sc_config.dlp)
105 #define S_NTMODE        (sc->sc_config.ntmode)
106 #define S_STDEL         (sc->sc_config.stdel)
107
108 #define S_PHSTATE       sc->sc_statemachine.state
109 #define S_STM_T3        sc->sc_statemachine.T3
110 #define S_STM_T3CALLOUT sc->sc_statemachine.T3callout
111
112 /* unitnumbers */
113
114 #define S_UNIT          sc->sc_unit
115 #define S_FLAG          sc->sc_flag
116 #define S_I4BUNIT       sc->sc_i4bunit
117 #define S_I4BFLAG       sc->sc_i4bflag
118
119 /* ISA bus setup */
120
121 #define S_IOBASE        sc->sc_resources.io_base
122 #define S_IORID         sc->sc_resources.io_rid
123 #define S_IRQ           sc->sc_resources.irq
124 #define S_IRQRID        sc->sc_resources.irq_rid
125
126 /* hardware setup */
127
128 #define S_HFC           sc->sc_config.chiptype
129 #define S_IIO           sc->sc_config.iio
130 #define S_IIRQ          sc->sc_config.iirq
131
132 /* registers of the HFC-S/SP    (write only) */
133
134 #define S_HFC_CONFIG    sc->sc_config.cirm
135
136 #define S_CIRM          sc->sc_config.cirm
137 #define S_CTMT          sc->sc_config.ctmt
138 #define S_TEST          sc->sc_config.test
139 #define S_SCTRL         sc->sc_config.sctrl
140 #define S_CLKDEL        sc->sc_config.clkdel
141 #define S_INT_M1        sc->sc_config.int_m1
142 #define S_INT_M2        sc->sc_config.int_m2
143 #define S_CONNECT       sc->sc_config.connect
144 #define S_SCTRL_R       sc->sc_config.sctrl_r
145 #define S_MST_MODE      sc->sc_config.mst_mode
146
147 /* registers of the HFC-S/SP    (read only) */
148
149 #define S_INT_S1        sc->sc_config.int_s1
150
151 /* registers of the ISAC        (write only) */
152
153 #define S_ISAC_CONFIG   sc->sc_config.i_adf2
154
155 #define S_ADF1          sc->sc_config.i_adf1
156 #define S_ADF2          sc->sc_config.i_adf2
157 #define S_MASK          sc->sc_config.i_mask
158 #define S_MODE          sc->sc_config.i_mode
159 #define S_SPCR          sc->sc_config.i_spcr
160 #define S_SQXR          sc->sc_config.i_sqxr
161 #define S_STCR          sc->sc_config.i_stcr
162 #define S_STAR2         sc->sc_config.i_star2
163
164 /* registers of the ISAC        (read only) */
165
166 #define S_ISTA          sc->sc_config.i_ista
167
168 /* state of the softc */
169
170 #define S_ENABLED       sc->sc_enabled
171 #define S_INTR_ACTIVE   sc->sc_intr_active
172
173 /* SOFT-HDLC */
174
175 #define S_HDLC_IB       sc->sc_fifo.chan[chan].hdlc.ib          /* u_short */
176 #define S_HDLC_CRC      sc->sc_fifo.chan[chan].hdlc.crc         /* u_short */
177 #define S_HDLC_TMP      sc->sc_fifo.chan[chan].hdlc.tmp         /* u_int   */
178 #define S_HDLC_FLAG     sc->sc_fifo.chan[chan].hdlc.flag        /* u_char  */
179 #define S_HDLC_BLEVEL   sc->sc_fifo.chan[chan].hdlc.blevel      /* u_short */
180
181 /* stats */
182
183 #define S_BYTES         sc->sc_fifo.chan[chan].bytes
184
185 /* "Z"-values */
186
187 #define S_HDLC_DZ_TAB   sc->sc_fifo.dztable
188
189 /* filters */
190
191 #define S_PROT          sc->sc_fifo.chan[chan].prot
192 #define S_FILTER        sc->sc_fifo.chan[chan].filter
193 #define S_ACTIVITY      sc->sc_fifo.chan[chan].activity
194 #define S_LAST_CHAN     sc->sc_fifo.last_chan
195
196 /* soft reset */
197
198 #define RESET_SOFT_CHAN(sc, chan)       bzero(&sc->sc_fifo.chan[chan], sizeof(sc->sc_fifo.chan[0]))
199
200 /* trace */
201
202 #define S_TRACE         sc->sc_trace
203 #define S_DTRACECOUNT   sc->sc_Dtracecount
204 #define S_BTRACECOUNT   sc->sc_Btracecount
205
206 /* mbuf */
207
208 #define S_MBUF          sc->sc_fifo.chan[chan].buffer.mbuf
209 #define S_MBUFDUMMY     sc->sc_fifo.chan[chan].buffer.mbufdummy
210 #define S_MBUFLEN       sc->sc_fifo.chan[chan].buffer.mbuf->m_len
211 #define S_MBUFPKTHDR    sc->sc_fifo.chan[chan].buffer.mbuf->m_pkthdr
212 #define S_MBUFDATA      sc->sc_fifo.chan[chan].buffer.mbuf->m_data
213 #define S_MBUFDAT       sc->sc_fifo.chan[chan].buffer.mbuf->m_dat
214
215 #define S_IFQUEUE       sc->sc_fifo.chan[chan].buffer.ifqueue
216
217 /* hfc control */
218
219 #define HFC_INIT        ihfc_init
220 #define HFC_INTR        ((S_HFC & HFC_1) ? ihfc_intr1 : ihfc_intr2)
221 #define HFC_FSM         ihfc_fsm
222 #define HFC_CONTROL     ihfc_control
223
224 /* softc parts */
225
226 struct ihfc_sc;
227
228 struct sc_resources {
229         struct resource * io_base[IHFC_IO_BASES];
230         int               io_rid [IHFC_IO_BASES];
231         struct resource * irq;
232         int               irq_rid;
233 };
234
235 struct hdlc {
236         u_char  flag;
237         u_short blevel;
238         u_short crc;
239         u_short ib;
240         u_int   tmp;
241 };
242
243 struct buffer {
244         struct ifqueue  ifqueue;        /* data queue   */
245         struct mbuf     *mbuf;          /* current mbuf */
246         struct mbuf     *mbufdummy;     /* temporary    */
247 };
248
249 struct chan {
250         struct hdlc     hdlc;
251         u_int           bytes;
252         u_int           prot;
253         struct buffer   buffer;
254         void (*filter)(struct ihfc_sc *sc, u_char chan);
255 };
256
257 struct sc_fifo {
258         struct  chan chan[6];
259         u_short dztable[16];
260         u_char  last_chan;
261 };
262
263 struct sc_config {
264         /* software only: */
265
266         u_short chiptype;       /* chiptype (eg. HFC_1) */
267         u_char  dlp;            /* D-priority           */
268         u_short iio;            /* internal IO          */
269         u_char  iirq;           /* internal IRQ         */
270         u_char  ntmode;         /* mode                 */
271         u_char  stdel;          /* S/T delay            */
272
273         /* write only: */
274         u_char cirm;
275         u_char ctmt;
276         u_char int_m1;
277         u_char int_m2;
278         u_char mst_mode;
279         u_char clkdel;
280         u_char sctrl;
281         u_char connect;
282         u_char test;
283         u_char sctrl_r;
284
285         /* isac write only - hfc-1: */
286         u_char i_adf2;
287         u_char i_spcr;
288         u_char i_sqxr;
289         u_char i_adf1;
290         u_char i_stcr;
291         u_char i_mode;
292         u_char i_mask;
293         u_char i_star2;
294
295         /* read only: */
296         u_char int_s1;
297
298         /* isac read only - hfc-1: */
299         u_char i_ista;
300 };
301
302 struct sc_statemachine {
303         u_char                  state;          /* see i4b_ihfc_drv.h */
304         u_char                  usync;
305         u_char                  T3;             /* T3 running         */
306         struct callout_handle   T3callout;
307 };
308
309 /*---------------------------------------------------------------------------*
310  *      HFC softc
311  *---------------------------------------------------------------------------*/
312 typedef struct  ihfc_sc
313 {       int                     sc_unit;
314         int                     sc_flag;
315
316         int                     sc_i4bunit;     /* L0IHFCUNIT(sc_unit)   */
317         int                     sc_i4bflag;     /* FLAG_TEL_S0_16_3C ..  */
318
319         u_char                  sc_enabled;     /* daemon running if set */
320         u_char                  sc_intr_active; /* interrupt is active   */
321
322         int                     sc_trace;
323         u_int                   sc_Btracecount;
324         u_int                   sc_Dtracecount;
325
326         struct sc_config        sc_config;
327         struct sc_resources     sc_resources;
328         struct sc_statemachine  sc_statemachine;
329
330         isdn_link_t             sc_blinktab[2];
331         drvr_link_t             *sc_bdrvlinktab[2];
332
333         struct sc_fifo          sc_fifo;
334 } ihfc_sc_t;
335
336 extern ihfc_sc_t        ihfc_softc[];
337
338 #endif /* _I4B_IHFC_H_ */