1 /*
2 * PCBIT-D low-layer interface definitions
3 *
4 * Copyright (C) 1996 Universidade de Lisboa
5 *
6 * Written by Pedro Roque Marques (pedro_m@yahoo.com)
7 *
8 * This software may be used and distributed according to the terms of
9 * the GNU General Public License, incorporated herein by reference.
10 */
11
12 /*
13 * 19991203 - Fernando Carvalho - takion@superbofh.org
14 * Hacked to compile with egcs and run with current version of isdn modules
15 */
16
17 #ifndef LAYER2_H
18 #define LAYER2_H
19
20 #include <asm/byteorder.h>
21
22 #define BANK1 0x0000U /* PC -> Board */
23 #define BANK2 0x01ffU /* Board -> PC */
24 #define BANK3 0x03feU /* Att Board */
25 #define BANK4 0x03ffU /* Att PC */
26
27 #define BANKLEN 0x01FFU
28
29 #define LOAD_ZONE_START 0x03f8U
30 #define LOAD_ZONE_END 0x03fdU
31
32 #define LOAD_RETRY 18000000
33
34
35
36 /* TAM - XX - C - S - NUM */
37 #define PREHDR_LEN 8
38 /* TT - M - I - TH - TD */
39 #define FRAME_HDR_LEN 8
40
41 #define MSG_CONN_REQ 0x08000100
42 #define MSG_CONN_CONF 0x00000101
43 #define MSG_CONN_IND 0x00000102
44 #define MSG_CONN_RESP 0x08000103
45
46 #define MSG_CONN_ACTV_REQ 0x08000300
47 #define MSG_CONN_ACTV_CONF 0x00000301
48 #define MSG_CONN_ACTV_IND 0x00000302
49 #define MSG_CONN_ACTV_RESP 0x08000303
50
51 #define MSG_DISC_REQ 0x08000400
52 #define MSG_DISC_CONF 0x00000401
53 #define MSG_DISC_IND 0x00000402
54 #define MSG_DISC_RESP 0x08000403
55
56 #define MSG_TDATA_REQ 0x0908E200
57 #define MSG_TDATA_CONF 0x0000E201
58 #define MSG_TDATA_IND 0x0000E202
59 #define MSG_TDATA_RESP 0x0908E203
60
61 #define MSG_SELP_REQ 0x09004000
62 #define MSG_SELP_CONF 0x00004001
63
64 #define MSG_ACT_TRANSP_REQ 0x0908E000
65 #define MSG_ACT_TRANSP_CONF 0x0000E001
66
67 #define MSG_STPROT_REQ 0x09004100
68 #define MSG_STPROT_CONF 0x00004101
69
70 #define MSG_PING188_REQ 0x09030500
71 #define MSG_PING188_CONF 0x000005bc
72
73 #define MSG_WATCH188 0x09030400
74
75 #define MSG_API_ON 0x08020102
76 #define MSG_POOL_PCBIT 0x08020400
77 #define MSG_POOL_PCBIT_CONF 0x00000401
78
79 #define MSG_INFO_IND 0x00002602
80 #define MSG_INFO_RESP 0x08002603
81
82 #define MSG_DEBUG_188 0x0000ff00
83
84 /*
85
86 long 4 3 2 1
87 Intel 1 2 3 4
88 */
89
90 #ifdef __LITTLE_ENDIAN
91 #define SET_MSG_SCMD(msg, ch) (msg = (msg & 0xffffff00) | (((ch) & 0xff)))
92 #define SET_MSG_CMD(msg, ch) (msg = (msg & 0xffff00ff) | (((ch) & 0xff) << 8))
93 #define SET_MSG_PROC(msg, ch) (msg = (msg & 0xff00ffff) | (((ch) & 0xff) << 16))
94 #define SET_MSG_CPU(msg, ch) (msg = (msg & 0x00ffffff) | (((ch) & 0xff) << 24))
95
96 #define GET_MSG_SCMD(msg) ((msg) & 0xFF)
97 #define GET_MSG_CMD(msg) ((msg) >> 8 & 0xFF)
98 #define GET_MSG_PROC(msg) ((msg) >> 16 & 0xFF)
99 #define GET_MSG_CPU(msg) ((msg) >> 24)
100
101 #else
102 #error "Non-Intel CPU"
103 #endif
104
105 #define MAX_QUEUED 7
106
107 #define SCHED_READ 0x01
108 #define SCHED_WRITE 0x02
109
110 #define SET_RUN_TIMEOUT 2*HZ /* 2 seconds */
111
112 struct frame_buf {
113 ulong msg;
114 unsigned int refnum;
115 unsigned int dt_len;
116 unsigned int hdr_len;
117 struct sk_buff *skb;
118 unsigned int copied;
119 struct frame_buf * next;
120 };
121
122 extern int pcbit_l2_write(struct pcbit_dev * dev, ulong msg, ushort refnum,
123 struct sk_buff *skb, unsigned short hdr_len);
124
125 extern void pcbit_irq_handler(int interrupt, void *, struct pt_regs *regs);
126
127 extern struct pcbit_dev * dev_pcbit[MAX_PCBIT_CARDS];
128
129 #ifdef DEBUG
log_state(struct pcbit_dev * dev)130 static __inline__ void log_state(struct pcbit_dev *dev) {
131 printk(KERN_DEBUG "writeptr = %ld\n",
132 (ulong) (dev->writeptr - dev->sh_mem));
133 printk(KERN_DEBUG "readptr = %ld\n",
134 (ulong) (dev->readptr - (dev->sh_mem + BANK2)));
135 printk(KERN_DEBUG "{rcv_seq=%01x, send_seq=%01x, unack_seq=%01x}\n",
136 dev->rcv_seq, dev->send_seq, dev->unack_seq);
137 }
138 #endif
139
chan2dev(struct pcbit_chan * chan)140 static __inline__ struct pcbit_dev * chan2dev(struct pcbit_chan * chan)
141 {
142 struct pcbit_dev * dev;
143 int i;
144
145
146 for (i=0; i<MAX_PCBIT_CARDS; i++)
147 if ((dev=dev_pcbit[i]))
148 if (dev->b1 == chan || dev->b2 == chan)
149 return dev;
150 return NULL;
151
152 }
153
finddev(int id)154 static __inline__ struct pcbit_dev * finddev(int id)
155 {
156 struct pcbit_dev * dev;
157 int i;
158
159 for (i=0; i<MAX_PCBIT_CARDS; i++)
160 if ((dev=dev_pcbit[i]))
161 if (dev->id == id)
162 return dev;
163 return NULL;
164 }
165
166
167 /*
168 * Support routines for reading and writing in the board
169 */
170
pcbit_writeb(struct pcbit_dev * dev,unsigned char dt)171 static __inline__ void pcbit_writeb(struct pcbit_dev *dev, unsigned char dt)
172 {
173 writeb(dt, dev->writeptr++);
174 if (dev->writeptr == dev->sh_mem + BANKLEN)
175 dev->writeptr = dev->sh_mem;
176 }
177
pcbit_writew(struct pcbit_dev * dev,unsigned short dt)178 static __inline__ void pcbit_writew(struct pcbit_dev *dev, unsigned short dt)
179 {
180 int dist;
181
182 dist = BANKLEN - (dev->writeptr - dev->sh_mem);
183 switch (dist) {
184 case 2:
185 writew(dt, dev->writeptr);
186 dev->writeptr = dev->sh_mem;
187 break;
188 case 1:
189 writeb((u_char) (dt & 0x00ffU), dev->writeptr);
190 dev->writeptr = dev->sh_mem;
191 writeb((u_char) (dt >> 8), dev->writeptr++);
192 break;
193 default:
194 writew(dt, dev->writeptr);
195 dev->writeptr += 2;
196 break;
197 };
198 }
199
memcpy_topcbit(struct pcbit_dev * dev,u_char * data,int len)200 static __inline__ void memcpy_topcbit(struct pcbit_dev * dev, u_char * data,
201 int len)
202 {
203 int diff;
204
205 diff = len - (BANKLEN - (dev->writeptr - dev->sh_mem) );
206
207 if (diff > 0)
208 {
209 memcpy_toio(dev->writeptr, data, len - diff);
210 memcpy_toio(dev->sh_mem, data + (len - diff), diff);
211 dev->writeptr = dev->sh_mem + diff;
212 }
213 else
214 {
215 memcpy_toio(dev->writeptr, data, len);
216
217 dev->writeptr += len;
218 if (diff == 0)
219 dev->writeptr = dev->sh_mem;
220 }
221 }
222
pcbit_readb(struct pcbit_dev * dev)223 static __inline__ unsigned char pcbit_readb(struct pcbit_dev *dev)
224 {
225 unsigned char val;
226
227 val = readb(dev->readptr++);
228 if (dev->readptr == dev->sh_mem + BANK2 + BANKLEN)
229 dev->readptr = dev->sh_mem + BANK2;
230
231 return val;
232 }
233
pcbit_readw(struct pcbit_dev * dev)234 static __inline__ unsigned short pcbit_readw(struct pcbit_dev *dev)
235 {
236 int dist;
237 unsigned short val;
238
239 dist = BANKLEN - ( dev->readptr - (dev->sh_mem + BANK2 ) );
240 switch (dist) {
241 case 2:
242 val = readw(dev->readptr);
243 dev->readptr = dev->sh_mem + BANK2;
244 break;
245 case 1:
246 val = readb(dev->readptr);
247 dev->readptr = dev->sh_mem + BANK2;
248 val = (readb(dev->readptr++) << 8) | val;
249 break;
250 default:
251 val = readw(dev->readptr);
252 dev->readptr += 2;
253 break;
254 };
255 return val;
256 }
257
memcpy_frompcbit(struct pcbit_dev * dev,u_char * data,int len)258 static __inline__ void memcpy_frompcbit(struct pcbit_dev * dev, u_char * data, int len)
259 {
260 int diff;
261
262 diff = len - (BANKLEN - (dev->readptr - (dev->sh_mem + BANK2) ) );
263 if (diff > 0)
264 {
265 memcpy_fromio(data, dev->readptr, len - diff);
266 memcpy_fromio(data + (len - diff), dev->sh_mem + BANK2 , diff);
267 dev->readptr = dev->sh_mem + BANK2 + diff;
268 }
269 else
270 {
271 memcpy_fromio(data, dev->readptr, len);
272 dev->readptr += len;
273 if (diff == 0)
274 dev->readptr = dev->sh_mem + BANK2;
275 }
276 }
277
278
279 #endif
280
281
282
283
284
285
286
287