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