root/drivers/isdn/icn/icn.h

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

INCLUDED FROM


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

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