1/* $NetBSD: daicvar.h,v 1.10 2008/04/28 20:23:49 martin Exp $ */
2
3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Martin Husemann <martin@NetBSD.org>.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef DIEHLISDNVAR
33#define DIEHLISDNVAR
34#if defined(KERNEL) || defined(_KERNEL)
35
36#define	DAIC_MAX_PORT		4
37#define	DAIC_ISA_MEMSIZE	2048
38#define	DAIC_ISA_QUADSIZE	(DAIC_MAX_PORT*DAIC_ISA_MEMSIZE)
39#define	DAIC_MAX_ACTIVE		(2*DAIC_MAX_PORT)	/* simlutaneous connections on one instance */
40
41/* A queue of pending outgoing calls */
42struct outcallentry {
43	TAILQ_ENTRY(outcallentry) queue;
44	unsigned int cdid;	/* call descriptor id for layer 4 */
45	u_int8_t dchan_id;	/* task id for microcode */
46	u_int8_t rc;		/* return code */
47};
48
49/* One active connection */
50struct daic_connection {
51	u_int cdid;			/* layer 4 call descriptor id */
52	struct ifqueue tx_queue;	/* outgoing data */
53	struct ifqueue rx_queue;	/* incoming data */
54	isdn_link_t isdn_linktab;	/* description of ourself */
55	const struct isdn_l4_driver_functions
56			*l4_driver;		/* layer 4 driver		*/
57	void		*l4_driver_softc;	/* layer 4 driver instance	*/
58	u_int8_t dchan_inst;		/* d-channel instance */
59	u_int8_t dchan_rc;		/* return code for dchannel requests */
60	u_int8_t bchan_inst;		/* b-channel instance */
61	u_int8_t bchan_rc;		/* return code for bchannel requests */
62};
63
64/*
65 * One BRI as exposed to the upper layers, with all the internal management
66 * information we need for it. A pointer to this is passed as the driver
67 * token.
68 */
69struct daic_unit {
70	struct daic_softc *du_sc;	/* pointer to softc */
71	const struct isdn_l3_driver *du_l3;
72	int du_port;			/* port number (on multi BRI cards) */
73	int du_state;			/* state of board, see below */
74#define	DAIC_STATE_COLD		0	/* nothing happened to the board */
75#define	DAIC_STATE_DOWNLOAD	1	/* the card is waiting for protocol code */
76#define DAIC_STATE_TESTING	2	/* waiting for first interrupt from card */
77#define	DAIC_STATE_RUNNING	3	/* the protocol is running */
78#define	DAIC_STATE_DIAGNOSTIC	4	/* temporary disabled for diagnostics */
79
80	int du_assign;			/* allocate new protocol instance */
81#define	DAIC_ASSIGN_PENDING	1	/* we are awaiting a new ID */
82#define	DAIC_ASSIGN_SLEEPING	2	/* somebody sleeping, wakeup after we got the ID */
83#define	DAIC_ASSIGN_GLOBAL	4	/* result is a global d-channel id */
84#define	DAIC_ASSIGN_NOGLOBAL	8	/* need to assign a global d-channel id */
85
86	u_int8_t du_global_dchan;	/* handle of global dchannel instance */
87	u_int8_t du_request_res;	/* result of requests */
88	u_int8_t du_assign_res;		/* result of assigns */
89};
90
91/* superclass of all softc structs for attachments, you should
92 * always be able to cast an attachments device_t self to this. */
93struct daic_softc {
94	struct device sc_dev;
95	bus_space_tag_t sc_iot;		/* bus identifier */
96	bus_space_handle_t sc_ioh;	/* mem handle */
97	int sc_cardtype;		/* variant of card */
98#define	DAIC_TYPE_S	0
99#define	DAIC_TYPE_SX	1
100#define	DAIC_TYPE_SCOM	2
101#define	DAIC_TYPE_QUAD	3
102
103	struct daic_unit sc_port[DAIC_MAX_PORT];
104
105	/* one record for each b-channel we could handle concurrently */
106	struct daic_connection sc_con[DAIC_MAX_ACTIVE];
107
108	/* a tailq of ougoing calls no yet assigned to any b-channel */
109	TAILQ_HEAD(outcallhead, outcallentry) sc_outcalls[DAIC_MAX_PORT];
110};
111
112/*
113 * functions exported from MI part
114 */
115extern int daic_probe(bus_space_tag_t bus, bus_space_handle_t io);
116extern void daic_attach(device_t self, struct daic_softc *sc);
117extern int daic_intr(struct daic_softc *);
118
119#endif
120#endif
121