icn.h 9.2 KB

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