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