2 * Copyright (c) 2001 Cubical Solutions Ltd. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * capi/iavc/iavc.h The AVM ISDN controllers' common declarations.
27 * $FreeBSD: src/sys/i4b/capi/iavc/iavc.h,v 1.2 2003/07/23 17:58:41 phk Exp $
28 * $DragonFly: src/sys/net/i4b/capi/iavc/iavc.h,v 1.4 2006/01/14 11:05:17 swildner Exp $
34 /* max 4 units supported per machine */
36 #define IAVC_MAXUNIT 4
40 // The software context of one AVM T1 controller.
43 #define IAVC_IO_BASES 1
45 typedef struct i4b_info {
46 struct resource * io_base[IAVC_IO_BASES];
47 int io_rid [IAVC_IO_BASES];
48 struct resource * irq;
50 struct resource * mem;
54 typedef struct iavc_softc {
60 bus_space_handle_t sc_mem_bh;
61 bus_space_tag_t sc_mem_bt;
63 bus_space_handle_t sc_io_bh;
64 bus_space_tag_t sc_io_bt;
78 char sc_sendbuf[128+2048];
79 char sc_recvbuf[128+2048];
82 struct ifqueue sc_txq;
84 i4b_info_t sc_resources;
87 extern iavc_softc_t iavc_sc[];
89 #define iavc_find_sc(unit) (&iavc_sc[(unit)])
92 // {b1,b1dma,t1}_{detect,reset}
93 // Routines to detect and manage the specific type of card.
96 extern int b1_detect(iavc_softc_t *sc);
97 extern void b1_disable_irq(iavc_softc_t *sc);
98 extern void b1_reset(iavc_softc_t *sc);
100 extern int b1dma_detect(iavc_softc_t *sc);
101 extern void b1dma_reset(iavc_softc_t *sc);
103 extern int t1_detect(iavc_softc_t *sc);
104 extern void t1_disable_irq(iavc_softc_t *sc);
105 extern void t1_reset(iavc_softc_t *sc);
109 // Routines to access the memory mapped registers of the
110 // S5933 DMA controller.
113 static __inline u_int32_t
114 AMCC_READ(iavc_softc_t *sc, int off)
116 return bus_space_read_4(sc->sc_mem_bt, sc->sc_mem_bh, off);
120 AMCC_WRITE(iavc_softc_t *sc, int off, u_int32_t value)
122 bus_space_write_4(sc->sc_mem_bt, sc->sc_mem_bh, off, value);
126 // amcc_{put,get}_{byte,word}
127 // Routines to access the DMA buffers byte- or wordwise.
130 static __inline u_int8_t *
131 amcc_put_byte(u_int8_t *buf, u_int8_t value)
137 static __inline u_int8_t *
138 amcc_get_byte(u_int8_t *buf, u_int8_t *value)
144 static __inline u_int8_t *
145 amcc_put_word(u_int8_t *buf, u_int32_t value)
147 *buf++ = (value & 0xff);
148 *buf++ = (value >> 8) & 0xff;
149 *buf++ = (value >> 16) & 0xff;
150 *buf++ = (value >> 24) & 0xff;
154 static __inline u_int8_t *
155 amcc_get_word(u_int8_t *buf, u_int32_t *value)
158 *value |= (*buf++ << 8);
159 *value |= (*buf++ << 16);
160 *value |= (*buf++ << 24);
165 // Controller LLI message numbers.
168 #define SEND_POLL 0x72
169 #define SEND_INIT 0x11
170 #define SEND_REGISTER 0x12
171 #define SEND_DATA_B3_REQ 0x13
172 #define SEND_RELEASE 0x14
173 #define SEND_MESSAGE 0x15
174 #define SEND_CONFIG 0x71
175 #define SEND_POLLACK 0x73
177 #define RECEIVE_POLL 0x32
178 #define RECEIVE_INIT 0x27
179 #define RECEIVE_MESSAGE 0x21
180 #define RECEIVE_DATA_B3_IND 0x22
181 #define RECEIVE_START 0x23
182 #define RECEIVE_STOP 0x24
183 #define RECEIVE_NEW_NCCI 0x25
184 #define RECEIVE_FREE_NCCI 0x26
185 #define RECEIVE_RELEASE 0x26
186 #define RECEIVE_TASK_READY 0x31
187 #define RECEIVE_DEBUGMSG 0x71
188 #define RECEIVE_POLLDWORD 0x75
190 /* Operation constants */
192 #define WRITE_REGISTER 0x00
193 #define READ_REGISTER 0x01
195 /* Port offsets in I/O space */
198 #define B1_WRITE 0x01
199 #define B1_INSTAT 0x02
200 #define B1_OUTSTAT 0x03
201 #define B1_ANALYSE 0x04
202 #define B1_REVISION 0x05
203 #define B1_RESET 0x10
205 #define T1_FASTLINK 0x00
206 #define T1_SLOWLINK 0x08
208 #define T1_READ B1_READ
209 #define T1_WRITE B1_WRITE
210 #define T1_INSTAT B1_INSTAT
211 #define T1_OUTSTAT B1_OUTSTAT
212 #define T1_IRQENABLE 0x05
213 #define T1_FIFOSTAT 0x06
214 #define T1_RESETLINK 0x10
215 #define T1_ANALYSE 0x11
216 #define T1_IRQMASTER 0x12
217 #define T1_IDENT 0x17
218 #define T1_RESETBOARD 0x1f
220 #define T1F_IREADY 0x01
221 #define T1F_IHALF 0x02
222 #define T1F_IFULL 0x04
223 #define T1F_IEMPTY 0x08
224 #define T1F_IFLAGS 0xf0
226 #define T1F_OREADY 0x10
227 #define T1F_OHALF 0x20
228 #define T1F_OEMPTY 0x40
229 #define T1F_OFULL 0x80
230 #define T1F_OFLAGS 0xf0
232 #define FIFO_OUTBSIZE 256
233 #define FIFO_INPBSIZE 512
235 #define HEMA_VERSION_ID 0
236 #define HEMA_PAL_ID 0
239 // S5933 DMA controller register offsets in memory, and bitmasks.
242 #define AMCC_RXPTR 0x24
243 #define AMCC_RXLEN 0x28
244 #define AMCC_TXPTR 0x2c
245 #define AMCC_TXLEN 0x30
247 #define AMCC_INTCSR 0x38
248 #define EN_READ_TC_INT 0x00008000
249 #define EN_WRITE_TC_INT 0x00004000
250 #define EN_TX_TC_INT EN_READ_TC_INT
251 #define EN_RX_TC_INT EN_WRITE_TC_INT
252 #define AVM_FLAG 0x30000000
254 #define ANY_S5933_INT 0x00800000
255 #define READ_TC_INT 0x00080000
256 #define WRITE_TC_INT 0x00040000
257 #define TX_TC_INT READ_TC_INT
258 #define RX_TC_INT WRITE_TC_INT
259 #define MASTER_ABORT_INT 0x00100000
260 #define TARGET_ABORT_INT 0x00200000
261 #define BUS_MASTER_INT 0x00200000
262 #define ALL_INT 0x000c0000
264 #define AMCC_MCSR 0x3c
265 #define A2P_HI_PRIORITY 0x00000100
266 #define EN_A2P_TRANSFERS 0x00000400
267 #define P2A_HI_PRIORITY 0x00001000
268 #define EN_P2A_TRANSFERS 0x00004000
269 #define RESET_A2P_FLAGS 0x04000000
270 #define RESET_P2A_FLAGS 0x02000000
273 // (B1IO_WAIT_MAX * B1IO_WAIT_DLY) is the max wait in us for the card
274 // to become ready after an I/O operation. The default is 1 ms.
277 #define B1IO_WAIT_MAX 1000
278 #define B1IO_WAIT_DLY 1
282 // Diagnostic output routine, returns the written value via
283 // the device's analysis register.
286 // Returns nonzero if data is readable from the card via the
290 // Returns nonzero if data can be written to the card via the
294 static __inline u_int8_t
295 b1io_outp(iavc_softc_t *sc, int off, u_int8_t val)
297 bus_space_write_1(sc->sc_io_bt, sc->sc_io_bh, off, val);
299 return bus_space_read_1(sc->sc_io_bt, sc->sc_io_bh, B1_ANALYSE);
303 b1io_rx_full(iavc_softc_t *sc)
305 u_int8_t val = bus_space_read_1(sc->sc_io_bt, sc->sc_io_bh, B1_INSTAT);
310 b1io_tx_empty(iavc_softc_t *sc)
312 u_int8_t val = bus_space_read_1(sc->sc_io_bt, sc->sc_io_bh, B1_OUTSTAT);
317 // b1io_{get,put}_{byte,word}
318 // Routines to read and write the device I/O registers byte- or
321 // b1io_{get,put}_slice
322 // Routines to read and write sequential bytes to the device
326 u_int8_t b1io_get_byte(iavc_softc_t *sc);
327 int b1io_put_byte(iavc_softc_t *sc, u_int8_t val);
329 int b1io_save_put_byte(iavc_softc_t *sc, u_int8_t val);
331 u_int32_t b1io_get_word(iavc_softc_t *sc);
332 void b1io_put_word(iavc_softc_t *sc, u_int32_t val);
334 int b1io_get_slice(iavc_softc_t *sc, u_int8_t *dp);
335 void b1io_put_slice(iavc_softc_t *sc, u_int8_t *dp, int len);
338 // b1io_{read,write}_reg
339 // Routines to read and write the device registers via the I/O
343 u_int32_t b1io_read_reg(iavc_softc_t *sc, int reg);
344 u_int32_t b1io_write_reg(iavc_softc_t *sc, int reg, u_int32_t val);
348 // I/O port write operation for the T1, which does not seem
349 // to have the analysis port.
353 t1io_outp(iavc_softc_t *sc, int off, u_int8_t val)
355 bus_space_write_1(sc->sc_io_bt, sc->sc_io_bh, off, val);
358 static __inline u_int8_t
359 t1io_inp(iavc_softc_t *sc, int off)
361 return bus_space_read_1(sc->sc_io_bt, sc->sc_io_bh, off);
365 t1io_isfastlink(iavc_softc_t *sc)
367 return ((bus_space_read_1(sc->sc_io_bt, sc->sc_io_bh, T1_IDENT) & ~0x82) == 1);
370 static __inline u_int8_t
371 t1io_fifostatus(iavc_softc_t *sc)
373 return bus_space_read_1(sc->sc_io_bt, sc->sc_io_bh, T1_FIFOSTAT);
376 int t1io_get_slice(iavc_softc_t *sc, u_int8_t *dp);
377 void t1io_put_slice(iavc_softc_t *sc, u_int8_t *dp, int len);
380 // An attempt to bring it all together:
381 // ------------------------------------
383 // iavc_{read,write}_reg
384 // Routines to access the device registers via the I/O port.
386 // iavc_{read,write}_port
387 // Routines to access the device I/O ports.
389 // iavc_tx_empty, iavc_rx_full
390 // Routines to check when the device has drained the last written
391 // byte, or produced a full byte to read.
393 // iavc_{get,put}_byte
394 // Routines to read/write byte values to the device via the I/O port.
396 // iavc_{get,put}_word
397 // Routines to read/write 32-bit words to the device via the I/O port.
399 // iavc_{get,put}_slice
400 // Routines to read/write {length, data} pairs to the device via the
401 // ubiquituous I/O port. Uses the HEMA FIFO on a T1.
404 #define iavc_read_reg(sc, reg) b1io_read_reg(sc, reg)
405 #define iavc_write_reg(sc, reg, val) b1io_write_reg(sc, reg, val)
407 #define iavc_read_port(sc, port) \
408 bus_space_read_1(sc->sc_io_bt, sc->sc_io_bh, (port))
409 #define iavc_write_port(sc, port, val) \
410 bus_space_write_1(sc->sc_io_bt, sc->sc_io_bh, (port), (val))
412 #define iavc_tx_empty(sc) b1io_tx_empty(sc)
413 #define iavc_rx_full(sc) b1io_rx_full(sc)
415 #define iavc_get_byte(sc) b1io_get_byte(sc)
416 #define iavc_put_byte(sc, val) b1io_put_byte(sc, val)
417 #define iavc_get_word(sc) b1io_get_word(sc)
418 #define iavc_put_word(sc, val) b1io_put_word(sc, val)
420 static __inline u_int32_t
421 iavc_get_slice(iavc_softc_t *sc, u_int8_t *dp)
423 if (sc->sc_t1) return t1io_get_slice(sc, dp);
424 else return b1io_get_slice(sc, dp);
428 iavc_put_slice(iavc_softc_t *sc, u_int8_t *dp, int len)
430 if (sc->sc_t1) t1io_put_slice(sc, dp, len);
431 else b1io_put_slice(sc, dp, len);
436 // Interrupt handler, called by the bus specific interrupt routine
437 // in iavc_<bustype>.c module.
440 // CAPI callback. Resets device and loads firmware.
443 // CAPI callback. Registers an application id.
446 // CAPI callback. Releases an application id.
449 // CAPI callback. Sends a CAPI message. A B3_DATA_REQ message has
450 // m_next point to a data mbuf.
453 extern void iavc_handle_intr(iavc_softc_t *);
454 extern int iavc_load(capi_softc_t *, int, u_int8_t *);
455 extern int iavc_register(capi_softc_t *, int, int);
456 extern int iavc_release(capi_softc_t *, int);
457 extern int iavc_send(capi_softc_t *, struct mbuf *);
459 extern void b1isa_setup_irq(struct iavc_softc *sc);
461 #endif /* _CAPI_IAVC_H_ */