icn.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* $Id: icn.h,v 1.30.6.5 2001/09/23 22:24:55 kai Exp $
  2. *
  3. * ISDN lowlevel-module for the ICN active ISDN-Card.
  4. *
  5. * Copyright 1994 by Fritz Elfert (fritz@isdn4linux.de)
  6. *
  7. * This software may be used and distributed according to the terms
  8. * of the GNU General Public License, incorporated herein by reference.
  9. *
  10. */
  11. #ifndef icn_h
  12. #define icn_h
  13. #define ICN_IOCTL_SETMMIO 0
  14. #define ICN_IOCTL_GETMMIO 1
  15. #define ICN_IOCTL_SETPORT 2
  16. #define ICN_IOCTL_GETPORT 3
  17. #define ICN_IOCTL_LOADBOOT 4
  18. #define ICN_IOCTL_LOADPROTO 5
  19. #define ICN_IOCTL_LEASEDCFG 6
  20. #define ICN_IOCTL_GETDOUBLE 7
  21. #define ICN_IOCTL_DEBUGVAR 8
  22. #define ICN_IOCTL_ADDCARD 9
  23. /* Struct for adding new cards */
  24. typedef struct icn_cdef {
  25. int port;
  26. char id1[10];
  27. char id2[10];
  28. } icn_cdef;
  29. #if defined(__KERNEL__) || defined(__DEBUGVAR__)
  30. #ifdef __KERNEL__
  31. /* Kernel includes */
  32. #include <linux/errno.h>
  33. #include <linux/fs.h>
  34. #include <linux/major.h>
  35. #include <linux/io.h>
  36. #include <linux/kernel.h>
  37. #include <linux/signal.h>
  38. #include <linux/slab.h>
  39. #include <linux/mm.h>
  40. #include <linux/mman.h>
  41. #include <linux/ioport.h>
  42. #include <linux/timer.h>
  43. #include <linux/wait.h>
  44. #include <linux/delay.h>
  45. #include <linux/isdnif.h>
  46. #endif /* __KERNEL__ */
  47. /* some useful macros for debugging */
  48. #ifdef ICN_DEBUG_PORT
  49. #define OUTB_P(v, p) {printk(KERN_DEBUG "icn: outb_p(0x%02x,0x%03x)\n", v, p); outb_p(v, p);}
  50. #else
  51. #define OUTB_P outb
  52. #endif
  53. /* Defaults for Port-Address and shared-memory */
  54. #define ICN_BASEADDR 0x320
  55. #define ICN_PORTLEN (0x04)
  56. #define ICN_MEMADDR 0x0d0000
  57. #define ICN_FLAGS_B1ACTIVE 1 /* B-Channel-1 is open */
  58. #define ICN_FLAGS_B2ACTIVE 2 /* B-Channel-2 is open */
  59. #define ICN_FLAGS_RUNNING 4 /* Cards driver activated */
  60. #define ICN_FLAGS_RBTIMER 8 /* cyclic scheduling of B-Channel-poll */
  61. #define ICN_BOOT_TIMEOUT1 1000 /* Delay for Boot-download (msecs) */
  62. #define ICN_TIMER_BCREAD (HZ / 100) /* B-Channel poll-cycle */
  63. #define ICN_TIMER_DCREAD (HZ / 2) /* D-Channel poll-cycle */
  64. #define ICN_CODE_STAGE1 4096 /* Size of bootcode */
  65. #define ICN_CODE_STAGE2 65536 /* Size of protocol-code */
  66. #define ICN_MAX_SQUEUE 8000 /* Max. outstanding send-data (2* hw-buf.) */
  67. #define ICN_FRAGSIZE (250) /* Max. size of send-fragments */
  68. #define ICN_BCH 2 /* Number of supported channels per card */
  69. /* type-definitions for accessing the mmap-io-areas */
  70. #define SHM_DCTL_OFFSET (0) /* Offset to data-controlstructures in shm */
  71. #define SHM_CCTL_OFFSET (0x1d2) /* Offset to comm-controlstructures in shm */
  72. #define SHM_CBUF_OFFSET (0x200) /* Offset to comm-buffers in shm */
  73. #define SHM_DBUF_OFFSET (0x2000) /* Offset to data-buffers in shm */
  74. /*
  75. * Layout of card's data buffers
  76. */
  77. typedef struct {
  78. unsigned char length; /* Bytecount of fragment (max 250) */
  79. unsigned char endflag; /* 0=last frag., 0xff=frag. continued */
  80. unsigned char data[ICN_FRAGSIZE]; /* The data */
  81. /* Fill to 256 bytes */
  82. char unused[0x100 - ICN_FRAGSIZE - 2];
  83. } frag_buf;
  84. /*
  85. * Layout of card's shared memory
  86. */
  87. typedef union {
  88. struct {
  89. unsigned char scns; /* Index to free SendFrag. */
  90. unsigned char scnr; /* Index to active SendFrag READONLY */
  91. unsigned char ecns; /* Index to free RcvFrag. READONLY */
  92. unsigned char ecnr; /* Index to valid RcvFrag */
  93. char unused[6];
  94. unsigned short fuell1; /* Internal Buf Bytecount */
  95. } data_control;
  96. struct {
  97. char unused[SHM_CCTL_OFFSET];
  98. unsigned char iopc_i; /* Read-Ptr Status-Queue READONLY */
  99. unsigned char iopc_o; /* Write-Ptr Status-Queue */
  100. unsigned char pcio_i; /* Write-Ptr Command-Queue */
  101. unsigned char pcio_o; /* Read-Ptr Command Queue READONLY */
  102. } comm_control;
  103. struct {
  104. char unused[SHM_CBUF_OFFSET];
  105. unsigned char pcio_buf[0x100]; /* Ring-Buffer Command-Queue */
  106. unsigned char iopc_buf[0x100]; /* Ring-Buffer Status-Queue */
  107. } comm_buffers;
  108. struct {
  109. char unused[SHM_DBUF_OFFSET];
  110. frag_buf receive_buf[0x10];
  111. frag_buf send_buf[0x10];
  112. } data_buffers;
  113. } icn_shmem;
  114. /*
  115. * Per card driver data
  116. */
  117. typedef struct icn_card {
  118. struct icn_card *next; /* Pointer to next device struct */
  119. struct icn_card *other; /* Pointer to other card for ICN4B */
  120. unsigned short port; /* Base-port-address */
  121. int myid; /* Driver-Nr. assigned by linklevel */
  122. int rvalid; /* IO-portregion has been requested */
  123. int leased; /* Flag: This Adapter is connected */
  124. /* to a leased line */
  125. unsigned short flags; /* Statusflags */
  126. int doubleS0; /* Flag: ICN4B */
  127. int secondhalf; /* Flag: Second half of a doubleS0 */
  128. int fw_rev; /* Firmware revision loaded */
  129. int ptype; /* Protocol type (1TR6 or Euro) */
  130. struct timer_list st_timer; /* Timer for Status-Polls */
  131. struct timer_list rb_timer; /* Timer for B-Channel-Polls */
  132. u_char rcvbuf[ICN_BCH][4096]; /* B-Channel-Receive-Buffers */
  133. int rcvidx[ICN_BCH]; /* Index for above buffers */
  134. int l2_proto[ICN_BCH]; /* Current layer-2-protocol */
  135. isdn_if interface; /* Interface to upper layer */
  136. int iptr; /* Index to imsg-buffer */
  137. char imsg[60]; /* Internal buf for status-parsing */
  138. char msg_buf[2048]; /* Buffer for status-messages */
  139. char *msg_buf_write; /* Writepointer for statusbuffer */
  140. char *msg_buf_read; /* Readpointer for statusbuffer */
  141. char *msg_buf_end; /* Pointer to end of statusbuffer */
  142. int sndcount[ICN_BCH]; /* Byte-counters for B-Ch.-send */
  143. int xlen[ICN_BCH]; /* Byte-counters/Flags for sent-ACK */
  144. struct sk_buff *xskb[ICN_BCH]; /* Current transmitted skb */
  145. struct sk_buff_head spqueue[ICN_BCH]; /* Sendqueue */
  146. char regname[35]; /* Name used for request_region */
  147. u_char xmit_lock[ICN_BCH]; /* Semaphore for pollbchan_send()*/
  148. spinlock_t lock; /* protect critical operations */
  149. } icn_card;
  150. /*
  151. * Main driver data
  152. */
  153. typedef struct icn_dev {
  154. spinlock_t devlock; /* spinlock to protect this struct */
  155. unsigned long memaddr; /* Address of memory mapped buffers */
  156. icn_shmem __iomem *shmem; /* Pointer to memory-mapped-buffers */
  157. int mvalid; /* IO-shmem has been requested */
  158. int channel; /* Currently mapped channel */
  159. struct icn_card *mcard; /* Currently mapped card */
  160. int chanlock; /* Semaphore for channel-mapping */
  161. int firstload; /* Flag: firmware never loaded */
  162. } icn_dev;
  163. typedef icn_dev *icn_devptr;
  164. #ifdef __KERNEL__
  165. static icn_card *cards = (icn_card *) 0;
  166. static u_char chan2bank[] =
  167. {0, 4, 8, 12}; /* for icn_map_channel() */
  168. static icn_dev dev;
  169. #endif /* __KERNEL__ */
  170. /* Utility-Macros */
  171. /* Macros for accessing ports */
  172. #define ICN_CFG (card->port)
  173. #define ICN_MAPRAM (card->port + 1)
  174. #define ICN_RUN (card->port + 2)
  175. #define ICN_BANK (card->port + 3)
  176. /* Return true, if there is a free transmit-buffer */
  177. #define sbfree (((readb(&dev.shmem->data_control.scns) + 1) & 0xf) != \
  178. readb(&dev.shmem->data_control.scnr))
  179. /* Switch to next transmit-buffer */
  180. #define sbnext (writeb((readb(&dev.shmem->data_control.scns) + 1) & 0xf, \
  181. &dev.shmem->data_control.scns))
  182. /* Shortcuts for transmit-buffer-access */
  183. #define sbuf_n dev.shmem->data_control.scns
  184. #define sbuf_d dev.shmem->data_buffers.send_buf[readb(&sbuf_n)].data
  185. #define sbuf_l dev.shmem->data_buffers.send_buf[readb(&sbuf_n)].length
  186. #define sbuf_f dev.shmem->data_buffers.send_buf[readb(&sbuf_n)].endflag
  187. /* Return true, if there is receive-data is available */
  188. #define rbavl (readb(&dev.shmem->data_control.ecnr) != \
  189. readb(&dev.shmem->data_control.ecns))
  190. /* Switch to next receive-buffer */
  191. #define rbnext (writeb((readb(&dev.shmem->data_control.ecnr) + 1) & 0xf, \
  192. &dev.shmem->data_control.ecnr))
  193. /* Shortcuts for receive-buffer-access */
  194. #define rbuf_n dev.shmem->data_control.ecnr
  195. #define rbuf_d dev.shmem->data_buffers.receive_buf[readb(&rbuf_n)].data
  196. #define rbuf_l dev.shmem->data_buffers.receive_buf[readb(&rbuf_n)].length
  197. #define rbuf_f dev.shmem->data_buffers.receive_buf[readb(&rbuf_n)].endflag
  198. /* Shortcuts for command-buffer-access */
  199. #define cmd_o (dev.shmem->comm_control.pcio_o)
  200. #define cmd_i (dev.shmem->comm_control.pcio_i)
  201. /* Return free space in command-buffer */
  202. #define cmd_free ((readb(&cmd_i) >= readb(&cmd_o)) ? \
  203. 0x100 - readb(&cmd_i) + readb(&cmd_o) : \
  204. readb(&cmd_o) - readb(&cmd_i))
  205. /* Shortcuts for message-buffer-access */
  206. #define msg_o (dev.shmem->comm_control.iopc_o)
  207. #define msg_i (dev.shmem->comm_control.iopc_i)
  208. /* Return length of Message, if avail. */
  209. #define msg_avail ((readb(&msg_o) > readb(&msg_i)) ? \
  210. 0x100 - readb(&msg_o) + readb(&msg_i) : \
  211. readb(&msg_i) - readb(&msg_o))
  212. #define CID (card->interface.id)
  213. #endif /* defined(__KERNEL__) || defined(__DEBUGVAR__) */
  214. #endif /* icn_h */