Sync usage with man page.
[netbsd-mini2440.git] / sys / dev / ic / isic_l1.h
blob0d3dacf92181b78d5daa3dc89ff6ba5da6bb4391
1 /* $NetBSD: isic_l1.h,v 1.13.6.6 2005/11/10 14:04:14 skrll Exp $ */
3 /*
4 * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
29 #ifndef _ISIC_L1_H
30 #define _ISIC_L1_H
32 #include <netisdn/i4b_l3l4.h>
34 /*---------------------------------------------------------------------------
35 * kernel config file flags definition
36 *---------------------------------------------------------------------------*/
37 #define FLAG_TELES_S0_8 1
38 #define FLAG_TELES_S0_16 2
39 #define FLAG_TELES_S0_163 3
40 #define FLAG_AVM_A1 4
41 #define FLAG_TELES_S0_163_PnP 5
42 #define FLAG_CREATIX_S0_PnP 6
43 #define FLAG_USR_ISDN_TA_INT 7
44 #define FLAG_DRN_NGO 8
45 #define FLAG_SWS 9
46 #define FLAG_AVM_A1_PCMCIA 10
47 #define FLAG_DYNALINK 11
48 #define FLAG_BLMASTER 12
49 #define FLAG_ELSA_QS1P_ISA 13
50 #define FLAG_ELSA_QS1P_PCI 14
51 #define FLAG_SIEMENS_ITALK 15
52 #define FLAG_ELSA_MLIMC 16
53 #define FLAG_ELSA_MLMCALL 17
54 #define FLAG_ITK_IX1 18
55 #define FLAG_AVMA1PCI 19
56 #define FLAG_ELSA_PCC16 20
57 #define FLAG_AVM_PNP 21
58 #define FLAG_SIEMENS_ISURF2 22
59 #define FLAG_ASUSCOM_IPAC 23
61 #define SEC_DELAY 1000000 /* one second DELAY for DELAY*/
63 #define MAX_DFRAME_LEN 264 /* max length of a D frame */
65 #ifndef __bsdi__
66 #define min(a,b) ((a)<(b)?(a):(b))
67 #endif
69 /* We try to map as few as possible as small as possible io and/or
70 memory regions. Each card defines its own interpretation of this
71 mapping array. At probe time we have a fixed size array, later
72 (when the card type is known) we allocate a minimal array
73 dynamically. */
75 #define ISIC_MAX_IO_MAPS 49 /* no cardtype needs more yet */
77 /* one entry in mapping array */
78 struct isic_io_map {
79 bus_space_tag_t t; /* which bus-space is this? */
80 bus_space_handle_t h; /* handle of mapped bus space region */
81 bus_size_t offset; /* offset into region */
82 bus_size_t size; /* size of region, zero if not ours
83 (i.e.: don't ever unmap it!) */
86 /* this is passed around at probe time (no struct isic_softc yet) */
87 struct isic_attach_args {
88 int ia_flags; /* flags from config file */
89 int ia_num_mappings; /* number of io mappings provided */
90 struct isic_io_map ia_maps[ISIC_MAX_IO_MAPS];
93 /*---------------------------------------------------------------------------*
94 * isic_Bchan: the state of one B channel
95 *---------------------------------------------------------------------------*/
96 typedef struct
98 int channel; /* which channel is this*/
100 u_char hscx_mask; /* HSCX interrupt mask */
102 int bprot; /* B channel protocol */
104 int state; /* this channels state */
105 #define HSCX_IDLE 0x00 /* channel idle */
106 #define HSCX_TX_ACTIVE 0x01 /* tx running */
108 /* receive data from ISDN */
110 struct ifqueue rx_queue; /* receiver queue */
112 int rxcount; /* rx statistics counter*/
114 struct mbuf *in_mbuf; /* rx input buffer */
115 u_char *in_cbptr; /* curr buffer pointer */
116 int in_len; /* rx input buffer len */
118 /* transmit data to ISDN */
120 struct ifqueue tx_queue; /* transmitter queue */
122 int txcount; /* tx statistics counter*/
124 struct mbuf *out_mbuf_head; /* first mbuf in possible chain */
125 struct mbuf *out_mbuf_cur; /* current mbuf in possbl chain */
126 unsigned char *out_mbuf_cur_ptr; /* data pointer into mbuf */
127 int out_mbuf_cur_len; /* remaining bytes in mbuf */
129 /* link between b channel and driver */
131 isdn_link_t isdn_linktab; /* b channel driver data */
132 const struct isdn_l4_driver_functions
133 *l4_driver; /* layer 4 driver */
134 void *l4_driver_softc; /* layer 4 driver instance */
136 /* statistics */
138 /* RSTA */
140 int stat_VFR; /* HSCX RSTA Valid FRame */
141 int stat_RDO; /* HSCX RSTA Rx Data Overflow */
142 int stat_CRC; /* HSCX RSTA CRC */
143 int stat_RAB; /* HSCX RSTA Rx message ABorted */
145 /* EXIR */
147 int stat_XDU; /* HSCX EXIR tx data underrun */
148 int stat_RFO; /* HSCX EXIR rx frame overflow */
150 } l1_bchan_state_t;
152 /*---------------------------------------------------------------------------*
153 * isic_softc: the state of the layer 1 of the D channel
154 *---------------------------------------------------------------------------*/
155 struct isic_softc
157 struct device sc_dev;
158 void *sc_l3token; /* pointer to registered L3 instance */
159 struct l2_softc sc_l2; /* D-channel variables */
161 int sc_irq; /* interrupt vector */
162 int sc_intr_valid; /* set when card is detached or disable */
163 #define ISIC_INTR_VALID 0 /* normal operation */
164 #define ISIC_INTR_DISABLED 1 /* ISDN subsystem not opened */
165 #define ISIC_INTR_DYING 2 /* card is detaching */
167 int sc_num_mappings; /* number of io mappings provided */
168 struct isic_io_map *sc_maps;
170 #define MALLOC_MAPS(sc) \
171 (sc)->sc_maps = (struct isic_io_map*)malloc(sizeof((sc)->sc_maps[0])*(sc)->sc_num_mappings, M_DEVBUF, 0)
173 int sc_cardtyp; /* only needed for some cards */
174 #define CARD_TYPEP_UNK 0 /* unknown */
175 #define CARD_TYPEP_8 1 /* Teles, S0/8 */
176 #define CARD_TYPEP_16 2 /* Teles, S0/16 */
177 #define CARD_TYPEP_16_3 3 /* Teles, S0/16.3 */
178 #define CARD_TYPEP_AVMA1 4 /* AVM A1 or AVM Fritz!Card */
179 #define CARD_TYPEP_163P 5 /* Teles, S0/16.3 PnP */
180 #define CARD_TYPEP_CS0P 6 /* Creatix, S0 PnP */
181 #define CARD_TYPEP_USRTA 7 /* US Robotics ISDN TA internal */
182 #define CARD_TYPEP_DRNNGO 8 /* Dr. Neuhaus Niccy GO@ */
183 #define CARD_TYPEP_SWS 9 /* Sedlbauer Win Speed */
184 #define CARD_TYPEP_DYNALINK 10 /* Dynalink IS64PH */
185 #define CARD_TYPEP_BLMASTER 11 /* ISDN Blaster / ISDN Master */
186 #define CARD_TYPEP_PCFRITZ 12 /* AVM PCMCIA Fritz!Card */
187 #define CARD_TYPEP_ELSAQS1ISA 13 /* ELSA QuickStep 1000pro ISA */
188 #define CARD_TYPEP_ELSAQS1PCI 14 /* ELSA QuickStep 1000pro PCI */
189 #define CARD_TYPEP_SIEMENSITALK 15 /* Siemens I-Talk */
190 #define CARD_TYPEP_ELSAMLIMC 16 /* ELSA MicroLink ISDN/MC */
191 #define CARD_TYPEP_ELSAMLMCALL 17 /* ELSA MicroLink MCall */
192 #define CARD_TYPEP_ITKIX1 18 /* ITK ix1 micro */
193 #define CARD_TYPEP_AVMA1PCI 19 /* AVM FRITZ!CARD PCI */
194 #define CARD_TYPEP_PCC16 20 /* ELSA PCC-16 */
195 #define CARD_TYPEP_AVM_PNP 21 /* AVM FRITZ!CARD PnP */
196 #define CARD_TYPEP_SIE_ISURF2 22 /* Siemens I-Surf 2 PnP */
197 #define CARD_TYPEP_ASUSCOMIPAC 23 /* Asuscom ISDNlink 128 K PnP */
198 #define CARD_TYPEP_AVMA1PCIV2 24 /* AVM FRITZ!CARD V2 PCI */
200 int sc_bustyp; /* IOM1 or IOM2 */
201 #define BUS_TYPE_IOM1 0x01
202 #define BUS_TYPE_IOM2 0x02
204 int sc_trace; /* output protocol data for tracing */
205 unsigned int sc_trace_dcount;/* d channel trace frame counter */
206 unsigned int sc_trace_bcount;/* b channel trace frame counter */
208 int sc_state; /* ISAC state flag */
209 #define ISAC_IDLE 0x00 /* state = idle */
210 #define ISAC_TX_ACTIVE 0x01 /* state = transmitter active */
212 int sc_init_tries; /* no of out tries to access S0 */
213 int sc_maddr; /* some stupid ISA cards need this */
215 u_char sc_isac_mask; /* ISAC IRQ mask */
216 #define ISAC_IMASK (sc->sc_isac_mask)
218 l1_bchan_state_t sc_chan[2]; /* B-channel state */
219 #define HSCX_A_BASE (sc->sc_chan[0].hscx)
220 #define HSCX_A_IMASK (sc->sc_chan[0].hscx_mask)
221 #define HSCX_B_BASE (sc->sc_chan[1].hscx)
222 #define HSCX_B_IMASK (sc->sc_chan[1].hscx_mask)
224 struct mbuf *sc_ibuf; /* input buffer mgmt */
225 u_short sc_ilen;
226 u_char *sc_ib;
227 /* this is for the irq TX routine */
228 struct mbuf *sc_obuf; /* pointer to an mbuf with TX frame */
229 u_char *sc_op; /* ptr to next chunk of frame to tx */
230 int sc_ol; /* length of remaining frame to tx */
231 int sc_freeflag; /* m_freem mbuf if set */
233 struct mbuf *sc_obuf2; /* pointer to an mbuf with TX frame */
234 int sc_freeflag2; /* m_freem mbuf if set */
236 int sc_isac_version; /* version number of ISAC */
237 int sc_hscx_version; /* version number of HSCX */
238 int sc_ipac_version; /* version number of IPAC */
240 int sc_I430state; /* I.430 state F3 .... F8 */
242 int sc_I430T3; /* I.430 Timer T3 running */
243 struct callout sc_T3_callout;
245 int sc_I430T4; /* Timer T4 running */
246 struct callout sc_T4_callout;
248 int sc_driver_specific; /* used for LED values */
249 struct callout sc_driver_callout; /* used for LED timer */
252 * byte fields for the AVM Fritz!Card PCI. These are packed into
253 * a u_int in the driver.
255 u_char avma1pp_cmd;
256 u_char avma1pp_txl;
257 u_char avma1pp_prot;
259 int sc_ipac; /* flag, running on ipac */
260 int sc_bfifolen; /* length of b channel fifos */
262 #define ISIC_WHAT_ISAC 0
263 #define ISIC_WHAT_HSCXA 1
264 #define ISIC_WHAT_HSCXB 2
265 #define ISIC_WHAT_IPAC 3
267 u_int8_t (*readreg)(struct isic_softc *, int, bus_size_t);
268 void (*writereg)(struct isic_softc *, int, bus_size_t, u_int8_t);
269 void (*readfifo)(struct isic_softc *, int, void *, size_t);
270 void (*writefifo)(struct isic_softc *, int what,
271 const void *, size_t);
272 void (*clearirq)(struct isic_softc *);
274 void (*drv_command)(struct isic_softc *, int, void *);
276 #define ISAC_READ(r) (*sc->readreg)(sc, ISIC_WHAT_ISAC, (r))
277 #define ISAC_WRITE(r,v) (*sc->writereg)(sc, ISIC_WHAT_ISAC, (r), (v))
278 #define ISAC_RDFIFO(b,s) (*sc->readfifo)(sc, ISIC_WHAT_ISAC, (b), (s))
279 #define ISAC_WRFIFO(b,s) (*sc->writefifo)(sc, ISIC_WHAT_ISAC, (b), (s))
281 #define HSCX_READ(n,r) (*sc->readreg)(sc, ISIC_WHAT_HSCXA+(n), (r))
282 #define HSCX_WRITE(n,r,v) (*sc->writereg)(sc, ISIC_WHAT_HSCXA+(n), (r), (v))
283 #define HSCX_RDFIFO(n,b,s) (*sc->readfifo)(sc, ISIC_WHAT_HSCXA+(n), (b), (s))
284 #define HSCX_WRFIFO(n,b,s) (*sc->writefifo)(sc, ISIC_WHAT_HSCXA+(n), (b), (s))
286 #define IPAC_READ(r) (*sc->readreg)(sc, ISIC_WHAT_IPAC, (r))
287 #define IPAC_WRITE(r, v) (*sc->writereg)(sc, ISIC_WHAT_IPAC, (r), (v))
291 /*---------------------------------------------------------------------------*
292 * possible I.430/ISAC states
293 *---------------------------------------------------------------------------*/
294 enum I430states {
295 ST_F3, /* F3 Deactivated */
296 ST_F4, /* F4 Awaiting Signal */
297 ST_F5, /* F5 Identifying Input */
298 ST_F6, /* F6 Synchronized */
299 ST_F7, /* F7 Activated */
300 ST_F8, /* F8 Lost Framing */
301 ST_ILL, /* Illegal State */
302 N_STATES
305 /*---------------------------------------------------------------------------*
306 * possible I.430/ISAC events
307 *---------------------------------------------------------------------------*/
308 enum I430events {
309 EV_PHAR, /* PH ACTIVATE REQUEST */
310 EV_T3, /* Timer 3 expired */
311 EV_INFO0, /* receiving INFO0 */
312 EV_RSY, /* receiving any signal */
313 EV_INFO2, /* receiving INFO2 */
314 EV_INFO48, /* receiving INFO4 pri 8/9 */
315 EV_INFO410, /* receiving INFO4 pri 10/11 */
316 EV_DR, /* Deactivate Request */
317 EV_PU, /* Power UP */
318 EV_DIS, /* Disconnected (only 2085) */
319 EV_EI, /* Error Indication */
320 EV_ILL, /* Illegal Event */
321 N_EVENTS
324 enum I430commands {
325 CMD_TIM, /* Timing */
326 CMD_RS, /* Reset */
327 CMD_AR8, /* Activation request pri 8 */
328 CMD_AR10, /* Activation request pri 10 */
329 CMD_DIU, /* Deactivate Indication Upstream */
330 CMD_ILL /* Illegal command */
333 #define N_COMMANDS CMD_ILL
335 extern void isic_recover(struct isic_softc *);
336 extern int isicintr(void *);
337 extern int isicprobe(struct isic_attach_args *);
338 extern int isic_attach_avma1(struct isic_softc *);
339 extern int isic_attach_s016(struct isic_softc *);
340 extern int isic_attach_s0163(struct isic_softc *);
341 extern int isic_attach_s08(struct isic_softc *);
342 extern int isic_attach_usrtai(struct isic_softc *);
343 extern int isic_attach_itkix1(struct isic_softc *);
344 extern void isic_bchannel_setup(void *, int, int, int);
345 extern void isic_hscx_init(struct isic_softc *, int, int);
346 extern void isic_hscx_irq(struct isic_softc *, u_char ista, int, u_char);
347 extern void isic_hscx_cmd( struct isic_softc *, int, unsigned char);
348 extern void isic_hscx_waitxfw( struct isic_softc *, int);
349 extern void isic_init_linktab(struct isic_softc *);
350 extern int isic_isac_init(struct isic_softc *);
351 extern void isic_isac_irq(struct isic_softc *, int);
352 extern void isic_isac_l1_cmd(struct isic_softc *, int);
353 extern void isic_next_state(struct isic_softc *, int);
354 extern const char * isic_printstate(struct isic_softc *);
355 extern int isic_probe_avma1(struct isic_attach_args *);
356 extern int isic_probe_s016(struct isic_attach_args *);
357 extern int isic_probe_s0163(struct isic_attach_args *);
358 extern int isic_probe_s08(struct isic_attach_args *ia);
359 extern int isic_probe_usrtai(struct isic_attach_args *ia);
360 extern int isic_probe_itkix1(struct isic_attach_args *ia);
361 extern int isic_attach_bri(struct isic_softc *sc, const char *cardname, const struct isdn_layer1_isdnif_driver *dchan_driver);
362 extern int isic_detach_bri(struct isic_softc *sc);
364 extern void isic_isacsx_disable_intr(struct isic_softc *sc);
365 extern void isic_isacsx_recover(struct isic_softc *sc);
366 extern void isic_isacsx_irq(struct isic_softc *sc, int r);
367 extern void isic_isacsx_l1_cmd(struct isic_softc *sc, int command);
368 extern int isic_isacsx_init(struct isic_softc *sc);
370 #endif /* !_ISIC_L1_H */