1 /* $Id: act2000.h,v 1.1.4.1 2001/11/20 14:19:34 kai Exp $
2  *
3  * ISDN lowlevel-module for the IBM ISDN-S0 Active 2000.
4  *
5  * Author       Fritz Elfert
6  * Copyright    by Fritz Elfert      <fritz@isdn4linux.de>
7  *
8  * This software may be used and distributed according to the terms
9  * of the GNU General Public License, incorporated herein by reference.
10  *
11  * Thanks to Friedemann Baitinger and IBM Germany
12  *
13  */
14 
15 #ifndef act2000_h
16 #define act2000_h
17 
18 #define ACT2000_IOCTL_SETPORT    1
19 #define ACT2000_IOCTL_GETPORT    2
20 #define ACT2000_IOCTL_SETIRQ     3
21 #define ACT2000_IOCTL_GETIRQ     4
22 #define ACT2000_IOCTL_SETBUS     5
23 #define ACT2000_IOCTL_GETBUS     6
24 #define ACT2000_IOCTL_SETPROTO   7
25 #define ACT2000_IOCTL_GETPROTO   8
26 #define ACT2000_IOCTL_SETMSN     9
27 #define ACT2000_IOCTL_GETMSN    10
28 #define ACT2000_IOCTL_LOADBOOT  11
29 #define ACT2000_IOCTL_ADDCARD   12
30 
31 #define ACT2000_IOCTL_TEST      98
32 #define ACT2000_IOCTL_DEBUGVAR  99
33 
34 #define ACT2000_BUS_ISA          1
35 #define ACT2000_BUS_MCA          2
36 #define ACT2000_BUS_PCMCIA       3
37 
38 /* Struct for adding new cards */
39 typedef struct act2000_cdef {
40 	int bus;
41         int port;
42         int irq;
43         char id[10];
44 } act2000_cdef;
45 
46 /* Struct for downloading firmware */
47 typedef struct act2000_ddef {
48         int length;             /* Length of code */
49         char *buffer;           /* Ptr. to code   */
50 } act2000_ddef;
51 
52 typedef struct act2000_fwid {
53         char isdn[4];
54         char revlen[2];
55         char revision[504];
56 } act2000_fwid;
57 
58 #if defined(__KERNEL__) || defined(__DEBUGVAR__)
59 
60 #ifdef __KERNEL__
61 /* Kernel includes */
62 
63 #include <linux/sched.h>
64 #include <linux/string.h>
65 #include <linux/tqueue.h>
66 #include <linux/interrupt.h>
67 #include <linux/skbuff.h>
68 #include <linux/errno.h>
69 #include <linux/fs.h>
70 #include <linux/major.h>
71 #include <asm/segment.h>
72 #include <asm/io.h>
73 #include <linux/kernel.h>
74 #include <linux/signal.h>
75 #include <linux/slab.h>
76 #include <linux/mm.h>
77 #include <linux/mman.h>
78 #include <linux/ioport.h>
79 #include <linux/timer.h>
80 #include <linux/wait.h>
81 #include <linux/delay.h>
82 #include <linux/ctype.h>
83 #include <linux/isdnif.h>
84 
85 #endif                           /* __KERNEL__ */
86 
87 #define ACT2000_PORTLEN        8
88 
89 #define ACT2000_FLAGS_RUNNING  1 /* Cards driver activated */
90 #define ACT2000_FLAGS_PVALID   2 /* Cards port is valid    */
91 #define ACT2000_FLAGS_IVALID   4 /* Cards irq is valid     */
92 #define ACT2000_FLAGS_LOADED   8 /* Firmware loaded        */
93 
94 #define ACT2000_BCH            2 /* # of channels per card */
95 
96 /* D-Channel states */
97 #define ACT2000_STATE_NULL     0
98 #define ACT2000_STATE_ICALL    1
99 #define ACT2000_STATE_OCALL    2
100 #define ACT2000_STATE_IWAIT    3
101 #define ACT2000_STATE_OWAIT    4
102 #define ACT2000_STATE_IBWAIT   5
103 #define ACT2000_STATE_OBWAIT   6
104 #define ACT2000_STATE_BWAIT    7
105 #define ACT2000_STATE_BHWAIT   8
106 #define ACT2000_STATE_BHWAIT2  9
107 #define ACT2000_STATE_DHWAIT  10
108 #define ACT2000_STATE_DHWAIT2 11
109 #define ACT2000_STATE_BSETUP  12
110 #define ACT2000_STATE_ACTIVE  13
111 
112 #define ACT2000_MAX_QUEUED  8000 /* 2 * maxbuff */
113 
114 #define ACT2000_LOCK_TX 0
115 #define ACT2000_LOCK_RX 1
116 
117 typedef struct act2000_chan {
118 	unsigned short callref;          /* Call Reference              */
119 	unsigned short fsm_state;        /* Current D-Channel state     */
120 	unsigned short eazmask;          /* EAZ-Mask for this Channel   */
121 	short queued;                    /* User-Data Bytes in TX queue */
122 	unsigned short plci;
123 	unsigned short ncci;
124 	unsigned char  l2prot;           /* Layer 2 protocol            */
125 	unsigned char  l3prot;           /* Layer 3 protocol            */
126 } act2000_chan;
127 
128 typedef struct msn_entry {
129 	char eaz;
130         char msn[16];
131         struct msn_entry * next;
132 } msn_entry;
133 
134 typedef struct irq_data_isa {
135 	__u8           *rcvptr;
136 	__u16           rcvidx;
137 	__u16           rcvlen;
138 	struct sk_buff *rcvskb;
139 	__u8            rcvignore;
140 	__u8            rcvhdr[8];
141 } irq_data_isa;
142 
143 typedef union irq_data {
144 	irq_data_isa isa;
145 } irq_data;
146 
147 /*
148  * Per card driver data
149  */
150 typedef struct act2000_card {
151         unsigned short port;             /* Base-port-address                */
152         unsigned short irq;              /* Interrupt                        */
153         u_char ptype;                    /* Protocol type (1TR6 or Euro)     */
154         u_char bus;                      /* Cardtype (ISA, MCA, PCMCIA)      */
155         struct act2000_card *next;	 /* Pointer to next device struct    */
156         int myid;                        /* Driver-Nr. assigned by linklevel */
157         unsigned long flags;             /* Statusflags                      */
158         unsigned long ilock;             /* Semaphores for IRQ-Routines      */
159 	struct sk_buff_head rcvq;        /* Receive-Message queue            */
160 	struct sk_buff_head sndq;        /* Send-Message queue               */
161 	struct sk_buff_head ackq;        /* Data-Ack-Message queue           */
162 	u_char *ack_msg;                 /* Ptr to User Data in User skb     */
163 	__u16 need_b3ack;                /* Flag: Need ACK for current skb   */
164 	struct sk_buff *sbuf;            /* skb which is currently sent      */
165 	struct timer_list ptimer;        /* Poll timer                       */
166 	struct tq_struct snd_tq;         /* Task struct for xmit bh          */
167 	struct tq_struct rcv_tq;         /* Task struct for rcv bh           */
168 	struct tq_struct poll_tq;        /* Task struct for polled rcv bh    */
169 	msn_entry *msn_list;
170 	unsigned short msgnum;           /* Message number fur sending       */
171 	act2000_chan bch[ACT2000_BCH];   /* B-Channel status/control         */
172 	char   status_buf[256];          /* Buffer for status messages       */
173 	char   *status_buf_read;
174 	char   *status_buf_write;
175 	char   *status_buf_end;
176 	irq_data idat;                   /* Data used for IRQ handler        */
177         isdn_if interface;               /* Interface to upper layer         */
178         char regname[35];                /* Name used for request_region     */
179 } act2000_card;
180 
act2000_schedule_tx(act2000_card * card)181 static inline void act2000_schedule_tx(act2000_card *card)
182 {
183         queue_task(&card->snd_tq, &tq_immediate);
184         mark_bh(IMMEDIATE_BH);
185 }
186 
act2000_schedule_rx(act2000_card * card)187 static inline void act2000_schedule_rx(act2000_card *card)
188 {
189         queue_task(&card->rcv_tq, &tq_immediate);
190         mark_bh(IMMEDIATE_BH);
191 }
192 
act2000_schedule_poll(act2000_card * card)193 static inline void act2000_schedule_poll(act2000_card *card)
194 {
195         queue_task(&card->poll_tq, &tq_immediate);
196         mark_bh(IMMEDIATE_BH);
197 }
198 
199 extern char *act2000_find_eaz(act2000_card *, char);
200 
201 #endif                          /* defined(__KERNEL__) || defined(__DEBUGVAR__) */
202 #endif                          /* act2000_h */
203