root/drivers/isdn/icn/icn.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /* $Id: icn.h,v 1.12 1996/01/22 05:01:22 fritz Exp fritz $
   2  *
   3  * ISDN lowlevel-module for the ICN active ISDN-Card.
   4  *
   5  * Copyright 1994 by Fritz Elfert (fritz@wuemaus.franken.de)
   6  *
   7  * This program is free software; you can redistribute it and/or modify
   8  * it under the terms of the GNU General Public License as published by
   9  * the Free Software Foundation; either version 2, or (at your option)
  10  * any later version.
  11  *
  12  * This program is distributed in the hope that it will be useful,
  13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  * GNU General Public License for more details.
  16  *
  17  * You should have received a copy of the GNU General Public License
  18  * along with this program; if not, write to the Free Software
  19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
  20  *
  21  * $Log: icn.h,v $
  22  * Revision 1.12  1996/01/22 05:01:22  fritz
  23  * Revert to GPL.
  24  *
  25  * Revision 1.11  1995/12/18  18:25:00  fritz
  26  * Support for ICN-2B Cards.
  27  * Change for supporting user-setable service-octet.
  28  *
  29  * Revision 1.10  1995/10/29  21:43:10  fritz
  30  * Added support for leased lines.
  31  *
  32  * Revision 1.9  1995/04/23  13:42:10  fritz
  33  * Added some constants for distingushing 1TR6 and DSS1
  34  *
  35  * Revision 1.8  1995/03/25  23:18:55  fritz
  36  * Changed ICN_PORTLEN to reflect correct number of ports.
  37  *
  38  * Revision 1.7  1995/03/15  12:52:06  fritz
  39  * Some cleanup
  40  *
  41  * Revision 1.6  1995/02/20  03:49:22  fritz
  42  * Fixed ICN_MAX_SQUEUE to correctly reflect outstanding bytes, not number
  43  * of buffers.
  44  *
  45  * Revision 1.5  1995/01/29  23:36:50  fritz
  46  * Minor cleanup.
  47  *
  48  * Revision 1.4  1995/01/09  07:41:20  fritz
  49  * Added GPL-Notice
  50  *
  51  * Revision 1.3  1995/01/04  05:14:20  fritz
  52  * removed include of linux/asm/string.h for compiling with Linux 1.1.76
  53  *
  54  * Revision 1.2  1995/01/02  02:15:57  fritz
  55  * Misc. Bugfixes
  56  *
  57  * Revision 1.1  1994/12/14  18:02:38  fritz
  58  * Initial revision
  59  *
  60  */
  61 
  62 #ifndef icn_h
  63 #define icn_h
  64 
  65 #define ICN_IOCTL_SETMMIO   0
  66 #define ICN_IOCTL_GETMMIO   1
  67 #define ICN_IOCTL_SETPORT   2
  68 #define ICN_IOCTL_GETPORT   3
  69 #define ICN_IOCTL_LOADBOOT  4
  70 #define ICN_IOCTL_LOADPROTO 5
  71 #define ICN_IOCTL_LEASEDCFG 6
  72 #define ICN_IOCTL_GETDOUBLE 7
  73 #define ICN_IOCTL_DEBUGVAR  8
  74 
  75 #if defined(__KERNEL__) || defined(__DEBUGVAR__)
  76 
  77 #ifdef __KERNEL__
  78 /* Kernel includes */
  79 
  80 #include <linux/module.h>
  81 #include <linux/version.h>
  82 #include <linux/errno.h>
  83 #include <linux/fs.h>
  84 #include <linux/major.h>
  85 #include <asm/segment.h>
  86 #include <asm/io.h>
  87 #include <linux/kernel.h>
  88 #include <linux/signal.h>
  89 #include <linux/malloc.h>
  90 #include <linux/mm.h>
  91 #include <linux/mman.h>
  92 #include <linux/ioport.h>
  93 #include <linux/timer.h>
  94 #include <linux/wait.h>
  95 #include <linux/isdnif.h>
  96 
  97 #endif                          /* __KERNEL__ */
  98 
  99 /* some useful macros for debugging */
 100 #ifdef ICN_DEBUG_PORT
 101 #define OUTB_P(v,p) {printk(KERN_DEBUG "icn: outb_p(0x%02x,0x%03x)\n",v,p); outb_p(v,p);}
 102 #else
 103 #define OUTB_P outb
 104 #endif
 105 
 106 /* Defaults for Port-Address and shared-memory */
 107 #define ICN_BASEADDR 0x320
 108 #define ICN_PORTLEN (0x04)
 109 #define ICN_MEMADDR 0x0d0000
 110 
 111 /* Macros for accessing ports */
 112 #define ICN_CFG    (dev->port)
 113 #define ICN_MAPRAM (dev->port+1)
 114 #define ICN_RUN    (dev->port+2)
 115 #define ICN_BANK   (dev->port+3)
 116 
 117 #define ICN_FLAGS_B1ACTIVE 1    /* B-Channel-1 is open                 */
 118 #define ICN_FLAGS_B2ACTIVE 2    /* B-Channel-2 is open                 */
 119 #define ICN_FLAGS_RBTIMER  8    /* cyclic scheduling of B-Channel-poll */
 120 
 121 #define ICN_BOOT_TIMEOUT1  100  /* Delay for Boot-download (jiffies)   */
 122 #define ICN_CHANLOCK_DELAY  10  /* Delay for Channel-mapping (jiffies) */
 123 
 124 #define ICN_TIMER_BCREAD 3      /* B-Channel poll-cycle                */
 125 #define ICN_TIMER_DCREAD 50     /* D-Channel poll-cycle                */
 126 
 127 #define ICN_CODE_STAGE1 4096    /* Size of bootcode                    */
 128 #define ICN_CODE_STAGE2 65536   /* Size of protocol-code               */
 129 
 130 #define ICN_MAX_SQUEUE 65536    /* Max. outstanding send-data          */
 131 #define ICN_FRAGSIZE (250)      /* Max. size of send-fragments         */
 132 #define ICN_BCH 2               /* Number of supported channels        */
 133 
 134 /* type-definitions for accessing the mmap-io-areas */
 135 
 136 #define SHM_DCTL_OFFSET (0)     /* Offset to data-controlstructures in shm */
 137 #define SHM_CCTL_OFFSET (0x1d2) /* Offset to comm-controlstructures in shm */
 138 #define SHM_CBUF_OFFSET (0x200) /* Offset to comm-buffers in shm           */
 139 #define SHM_DBUF_OFFSET (0x2000)        /* Offset to data-buffers in shm           */
 140 
 141 typedef struct {
 142         unsigned char length;   /* Bytecount of fragment (max 250)     */
 143         unsigned char endflag;  /* 0=last frag., 0xff=frag. continued  */
 144         unsigned char data[ICN_FRAGSIZE];       /* The data                            */
 145         /* Fill to 256 bytes */
 146         char unused[0x100 - ICN_FRAGSIZE - 2];
 147 } frag_buf;
 148 
 149 typedef union {
 150         struct {
 151                 unsigned char scns;     /* Index to free SendFrag.             */
 152                 unsigned char scnr;     /* Index to active SendFrag   READONLY */
 153                 unsigned char ecns;     /* Index to free RcvFrag.     READONLY */
 154                 unsigned char ecnr;     /* Index to valid RcvFrag              */
 155                 char unused[6];
 156                 unsigned short fuell1;  /* Internal Buf Bytecount              */
 157         } data_control;
 158         struct {
 159                 char unused[SHM_CCTL_OFFSET];
 160                 unsigned char iopc_i;   /* Read-Ptr Status-Queue      READONLY */
 161                 unsigned char iopc_o;   /* Write-Ptr Status-Queue              */
 162                 unsigned char pcio_i;   /* Write-Ptr Command-Queue             */
 163                 unsigned char pcio_o;   /* Read-Ptr Command Queue     READONLY */
 164         } comm_control;
 165         struct {
 166                 char unused[SHM_CBUF_OFFSET];
 167                 unsigned char pcio_buf[0x100];  /* Ring-Buffer Command-Queue           */
 168                 unsigned char iopc_buf[0x100];  /* Ring-Buffer Status-Queue            */
 169         } comm_buffers;
 170         struct {
 171                 char unused[SHM_DBUF_OFFSET];
 172                 frag_buf receive_buf[0x10];
 173                 frag_buf send_buf[0x10];
 174         } data_buffers;
 175 } icn_shmem;
 176 
 177 /* Sendbuffer-queue-element */
 178 typedef struct {
 179         char *next;
 180         short length;
 181         short size;
 182         u_char *rptr;
 183         u_char buffer[1];
 184 } pqueue;
 185 
 186 typedef struct {
 187         unsigned short port;    /* Base-port-adress                 */
 188         icn_shmem *shmem;       /* Pointer to memory-mapped-buffers */
 189         int myid;               /* Driver-Nr. assigned by linklevel */
 190         int rvalid;             /* IO-portregion has been requested */
 191         int mvalid;             /* IO-shmem has been requested      */
 192         int leased;             /* Flag: This Adapter is connected  */
 193         /*       to a leased line           */
 194         unsigned short flags;   /* Statusflags                      */
 195         int doubleS0;           /* Flag: Double-S0-Card             */
 196         int secondhalf;         /* Flag: Second half of a doubleS0  */
 197         int ptype;              /* Protocoltype (1TR6 or Euro)      */
 198         struct timer_list st_timer;     /* Timer for Status-Polls           */
 199         struct timer_list rb_timer;     /* Timer for B-Channel-Polls        */
 200         int channel;            /* Currently mapped Channel         */
 201         int chanlock;           /* Semaphore for Channel-Mapping    */
 202         u_char rcvbuf[ICN_BCH][4096];   /* B-Channel-Receive-Buffers      */
 203         int rcvidx[ICN_BCH];    /* Index for above buffers          */
 204         int l2_proto[ICN_BCH];  /* Current layer-2-protocol         */
 205         isdn_if interface;      /* Interface to upper layer         */
 206         int iptr;               /* Index to imsg-buffer             */
 207         char imsg[60];          /* Internal buf for status-parsing  */
 208         char msg_buf[2048];     /* Buffer for status-messages       */
 209         char *msg_buf_write;    /* Writepointer for statusbuffer    */
 210         char *msg_buf_read;     /* Readpointer for statusbuffer     */
 211         char *msg_buf_end;      /* Pointer to end of statusbuffer   */
 212         int sndcount[ICN_BCH];  /* Byte-counters for B-Ch.-send     */
 213         pqueue *spqueue[ICN_BCH];       /* Pointers to start of Send-Queue  */
 214 #ifdef DEBUG_RCVCALLBACK
 215         int akt_pending[ICN_BCH];
 216         int max_pending[ICN_BCH];
 217 #endif
 218 } icn_dev;
 219 
 220 typedef icn_dev *icn_devptr;
 221 
 222 #ifdef __KERNEL__
 223 static icn_dev *dev = (icn_dev *) 0;
 224 static icn_dev *dev2 = (icn_dev *) 0;
 225 
 226 /* With modutils >= 1.1.67 Integers can be changed while loading a
 227  * module. For this reason define the Port-Base an Shmem-Base as
 228  * integers.
 229  */
 230 int portbase = ICN_BASEADDR;
 231 int membase = ICN_MEMADDR;
 232 char *icn_id = "\0";
 233 char *icn_id2 = "\0";
 234 static char regname[35];        /* Name used for port/mem-registration */
 235 
 236 #endif                          /* __KERNEL__ */
 237 
 238 /* Utility-Macros */
 239 
 240 /* Return true, if there is a free transmit-buffer */
 241 #define sbfree (((dev->shmem->data_control.scns+1) & 0xf) != \
 242                 dev->shmem->data_control.scnr)
 243 
 244 /* Switch to next transmit-buffer */
 245 #define sbnext (dev->shmem->data_control.scns = \
 246                ((dev->shmem->data_control.scns+1) & 0xf))
 247 
 248 /* Shortcuts for transmit-buffer-access */
 249 #define sbuf_n dev->shmem->data_control.scns
 250 #define sbuf_d dev->shmem->data_buffers.send_buf[sbuf_n].data
 251 #define sbuf_l dev->shmem->data_buffers.send_buf[sbuf_n].length
 252 #define sbuf_f dev->shmem->data_buffers.send_buf[sbuf_n].endflag
 253 
 254 /* Return true, if there is receive-data is available */
 255 #define rbavl  (dev->shmem->data_control.ecnr != \
 256                 dev->shmem->data_control.ecns)
 257 
 258 /* Switch to next receive-buffer */
 259 #define rbnext (dev->shmem->data_control.ecnr = \
 260                ((dev->shmem->data_control.ecnr+1) & 0xf))
 261 
 262 /* Shortcuts for receive-buffer-access */
 263 #define rbuf_n dev->shmem->data_control.ecnr
 264 #define rbuf_d dev->shmem->data_buffers.receive_buf[rbuf_n].data
 265 #define rbuf_l dev->shmem->data_buffers.receive_buf[rbuf_n].length
 266 #define rbuf_f dev->shmem->data_buffers.receive_buf[rbuf_n].endflag
 267 
 268 /* Shortcuts for command-buffer-access */
 269 #define cmd_o (dev->shmem->comm_control.pcio_o)
 270 #define cmd_i (dev->shmem->comm_control.pcio_i)
 271 
 272 /* Return free space in command-buffer */
 273 #define cmd_free ((cmd_i>=cmd_o)?0x100-cmd_i+cmd_o:cmd_o-cmd_i)
 274 
 275 /* Shortcuts for message-buffer-access */
 276 #define msg_o (dev->shmem->comm_control.iopc_o)
 277 #define msg_i (dev->shmem->comm_control.iopc_i)
 278 
 279 /* Return length of Message, if avail. */
 280 #define msg_avail ((msg_o>msg_i)?0x100-msg_o+msg_i:msg_i-msg_o)
 281 
 282 #define MIN(a,b) ((a<b)?a:b)
 283 #define MAX(a,b) ((a>b)?a:b)
 284 
 285 /* Hopefully, a separate resource-registration-scheme for shared-memory
 286  * will be introduced into the kernel. Until then, we use the normal
 287  * routines, designed for port-registration.
 288  */
 289 #define check_shmem   check_region
 290 #define release_shmem release_region
 291 #define request_shmem request_region
 292 
 293 #endif                          /* defined(__KERNEL__) || defined(__DEBUGVAR__) */
 294 #endif                          /* icn_h */

/* [previous][next][first][last][top][bottom][index][help] */