linux/drivers/staging/dgnc/dgnc_driver.h
<<
>>
Prefs
   1/*
   2 * Copyright 2003 Digi International (www.digi.com)
   3 *      Scott H Kilau <Scott_Kilau at digi dot com>
   4 *
   5 * This program is free software; you can redistribute it and/or modify
   6 * it under the terms of the GNU General Public License as published by
   7 * the Free Software Foundation; either version 2, or (at your option)
   8 * any later version.
   9 *
  10 * This program is distributed in the hope that it will be useful,
  11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
  12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13 * PURPOSE.  See the GNU General Public License for more details.
  14 *
  15 * You should have received a copy of the GNU General Public License
  16 * along with this program; if not, write to the Free Software
  17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18 *
  19 *      NOTE: THIS IS A SHARED HEADER. DO NOT CHANGE CODING STYLE!!!
  20 *
  21 *************************************************************************
  22 *
  23 * Driver includes
  24 *
  25 *************************************************************************/
  26
  27#ifndef __DGNC_DRIVER_H
  28#define __DGNC_DRIVER_H
  29
  30#include <linux/types.h>        /* To pick up the varions Linux types */
  31#include <linux/tty.h>    /* To pick up the various tty structs/defines */
  32#include <linux/interrupt.h>    /* For irqreturn_t type */
  33
  34#include "dgnc_types.h"         /* Additional types needed by the Digi header files */
  35#include "digi.h"               /* Digi specific ioctl header */
  36#include "dgnc_kcompat.h"       /* Kernel 2.4/2.6 compat includes */
  37#include "dgnc_sysfs.h"         /* Support for SYSFS */
  38
  39/*************************************************************************
  40 *
  41 * Driver defines
  42 *
  43 *************************************************************************/
  44
  45/* Driver identification and error statments */
  46#define PROCSTR         "dgnc"                  /* /proc entries         */
  47#define DEVSTR          "/dev/dg/dgnc"          /* /dev entries          */
  48#define DRVSTR          "dgnc"                  /* Driver name string    */
  49
  50#define TRC_TO_CONSOLE 1
  51
  52/* Number of boards we support at once. */
  53#define MAXBOARDS       20
  54#define MAXPORTS        8
  55#define MAXTTYNAMELEN   200
  56
  57/* Our 3 magic numbers for our board, channel and unit structs */
  58#define DGNC_BOARD_MAGIC        0x5c6df104
  59#define DGNC_CHANNEL_MAGIC      0x6c6df104
  60#define DGNC_UNIT_MAGIC         0x7c6df104
  61
  62/* Serial port types */
  63#define DGNC_SERIAL             0
  64#define DGNC_PRINT              1
  65
  66#define SERIAL_TYPE_NORMAL      1
  67
  68#define PORT_NUM(dev)   ((dev) & 0x7f)
  69#define IS_PRINT(dev)   (((dev) & 0xff) >= 0x80)
  70
  71/* MAX number of stop characters we will send when our read queue is getting full */
  72#define MAX_STOPS_SENT 5
  73
  74/* 4 extra for alignment play space */
  75#define WRITEBUFLEN             ((4096) + 4)
  76#define MYFLIPLEN               N_TTY_BUF_SIZE
  77
  78#define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
  79
  80/*
  81 * Define a local default termios struct. All ports will be created
  82 * with this termios initially.  This is the same structure that is defined
  83 * as the default in tty_io.c with the same settings overriden as in serial.c
  84 *
  85 * In short, this should match the internal serial ports' defaults.
  86 */
  87#define DEFAULT_IFLAGS  (ICRNL | IXON)
  88#define DEFAULT_OFLAGS  (OPOST | ONLCR)
  89#define DEFAULT_CFLAGS  (B9600 | CS8 | CREAD | HUPCL | CLOCAL)
  90#define DEFAULT_LFLAGS  (ISIG | ICANON | ECHO | ECHOE | ECHOK | \
  91                        ECHOCTL | ECHOKE | IEXTEN)
  92
  93#ifndef _POSIX_VDISABLE
  94#define   _POSIX_VDISABLE '\0'
  95#endif
  96
  97
  98/*
  99 * All the possible states the driver can be while being loaded.
 100 */
 101enum {
 102        DRIVER_INITIALIZED = 0,
 103        DRIVER_READY
 104};
 105
 106/*
 107 * All the possible states the board can be while booting up.
 108 */
 109enum {
 110        BOARD_FAILED = 0,
 111        BOARD_FOUND,
 112        BOARD_READY
 113};
 114
 115
 116/*************************************************************************
 117 *
 118 * Structures and closely related defines.
 119 *
 120 *************************************************************************/
 121
 122struct dgnc_board;
 123struct channel_t;
 124
 125/************************************************************************
 126 * Per board operations structure                                      *
 127 ************************************************************************/
 128struct board_ops {
 129        void (*tasklet)(unsigned long data);
 130        irqreturn_t (*intr)(int irq, void *voidbrd);
 131        void (*uart_init)(struct channel_t *ch);
 132        void (*uart_off)(struct channel_t *ch);
 133        int  (*drain)(struct tty_struct *tty, uint seconds);
 134        void (*param)(struct tty_struct *tty);
 135        void (*vpd)(struct dgnc_board *brd);
 136        void (*assert_modem_signals)(struct channel_t *ch);
 137        void (*flush_uart_write)(struct channel_t *ch);
 138        void (*flush_uart_read)(struct channel_t *ch);
 139        void (*disable_receiver)(struct channel_t *ch);
 140        void (*enable_receiver)(struct channel_t *ch);
 141        void (*send_break)(struct channel_t *ch, int);
 142        void (*send_start_character)(struct channel_t *ch);
 143        void (*send_stop_character)(struct channel_t *ch);
 144        void (*copy_data_from_queue_to_uart)(struct channel_t *ch);
 145        uint (*get_uart_bytes_left)(struct channel_t *ch);
 146        void (*send_immediate_char)(struct channel_t *ch, unsigned char);
 147};
 148
 149/************************************************************************
 150 * Device flag definitions for bd_flags.
 151 ************************************************************************/
 152#define BD_IS_PCI_EXPRESS     0x0001      /* Is a PCI Express board */
 153
 154
 155/*
 156 *      Per-board information
 157 */
 158struct dgnc_board {
 159        int             magic;          /* Board Magic number.  */
 160        int             boardnum;       /* Board number: 0-32 */
 161
 162        int             type;           /* Type of board */
 163        char            *name;          /* Product Name */
 164        struct pci_dev  *pdev;          /* Pointer to the pci_dev struct */
 165        unsigned long   bd_flags;       /* Board flags */
 166        u16             vendor;         /* PCI vendor ID */
 167        u16             device;         /* PCI device ID */
 168        u16             subvendor;      /* PCI subsystem vendor ID */
 169        u16             subdevice;      /* PCI subsystem device ID */
 170        unsigned char   rev;            /* PCI revision ID */
 171        uint            pci_bus;        /* PCI bus value */
 172        uint            pci_slot;       /* PCI slot value */
 173        uint            maxports;       /* MAX ports this board can handle */
 174        unsigned char   dvid;           /* Board specific device id */
 175        unsigned char   vpd[128];       /* VPD of board, if found */
 176        unsigned char   serial_num[20]; /* Serial number of board, if found in VPD */
 177
 178        spinlock_t      bd_lock;        /* Used to protect board */
 179
 180        spinlock_t      bd_intr_lock;   /* Used to protect the poller tasklet and
 181                                         * the interrupt routine from each other.
 182                                         */
 183
 184        uint            state;          /* State of card. */
 185        wait_queue_head_t state_wait;   /* Place to sleep on for state change */
 186
 187        struct          tasklet_struct helper_tasklet; /* Poll helper tasklet */
 188
 189        uint            nasync;         /* Number of ports on card */
 190
 191        uint            irq;            /* Interrupt request number */
 192        ulong           intr_count;     /* Count of interrupts */
 193        ulong           intr_modem;     /* Count of interrupts */
 194        ulong           intr_tx;        /* Count of interrupts */
 195        ulong           intr_rx;        /* Count of interrupts */
 196
 197        ulong           membase;        /* Start of base memory of the card */
 198        ulong           membase_end;    /* End of base memory of the card */
 199
 200        u8 __iomem              *re_map_membase;/* Remapped memory of the card */
 201
 202        ulong           iobase;         /* Start of io base of the card */
 203        ulong           iobase_end;     /* End of io base of the card */
 204
 205        uint            bd_uart_offset; /* Space between each UART */
 206
 207        struct channel_t *channels[MAXPORTS]; /* array of pointers to our channels. */
 208
 209        struct tty_driver       SerialDriver;
 210        char            SerialName[200];
 211        struct tty_driver       PrintDriver;
 212        char            PrintName[200];
 213
 214        uint            dgnc_Major_Serial_Registered;
 215        uint            dgnc_Major_TransparentPrint_Registered;
 216
 217        uint            dgnc_Serial_Major;
 218        uint            dgnc_TransparentPrint_Major;
 219
 220        uint            TtyRefCnt;
 221
 222        char            *flipbuf;       /* Our flip buffer, alloced if board is found */
 223
 224        u16             dpatype;        /* The board "type", as defined by DPA */
 225        u16             dpastatus;      /* The board "status", as defined by DPA */
 226
 227        /*
 228         *      Mgmt data.
 229         */
 230        char            *msgbuf_head;
 231        char            *msgbuf;
 232
 233        uint            bd_dividend;    /* Board/UARTs specific dividend */
 234
 235        struct board_ops *bd_ops;
 236
 237        /* /proc/<board> entries */
 238        struct proc_dir_entry *proc_entry_pointer;
 239        struct dgnc_proc_entry *dgnc_board_table;
 240
 241};
 242
 243
 244/************************************************************************
 245 * Unit flag definitions for un_flags.
 246 ************************************************************************/
 247#define UN_ISOPEN       0x0001          /* Device is open               */
 248#define UN_CLOSING      0x0002          /* Line is being closed         */
 249#define UN_IMM          0x0004          /* Service immediately          */
 250#define UN_BUSY         0x0008          /* Some work this channel       */
 251#define UN_BREAKI       0x0010          /* Input break received         */
 252#define UN_PWAIT        0x0020          /* Printer waiting for terminal */
 253#define UN_TIME         0x0040          /* Waiting on time              */
 254#define UN_EMPTY        0x0080          /* Waiting output queue empty   */
 255#define UN_LOW          0x0100          /* Waiting output low water mark*/
 256#define UN_EXCL_OPEN    0x0200          /* Open for exclusive use       */
 257#define UN_WOPEN        0x0400          /* Device waiting for open      */
 258#define UN_WIOCTL       0x0800          /* Device waiting for open      */
 259#define UN_HANGUP       0x8000          /* Carrier lost                 */
 260
 261struct device;
 262
 263/************************************************************************
 264 * Structure for terminal or printer unit.
 265 ************************************************************************/
 266struct un_t {
 267        int     magic;          /* Unit Magic Number.                   */
 268        struct  channel_t *un_ch;
 269        ulong   un_time;
 270        uint    un_type;
 271        uint    un_open_count;  /* Counter of opens to port             */
 272        struct tty_struct *un_tty;/* Pointer to unit tty structure      */
 273        uint    un_flags;       /* Unit flags                           */
 274        wait_queue_head_t un_flags_wait; /* Place to sleep to wait on unit */
 275        uint    un_dev;         /* Minor device number                  */
 276        struct device *un_sysfs;
 277};
 278
 279
 280/************************************************************************
 281 * Device flag definitions for ch_flags.
 282 ************************************************************************/
 283#define CH_PRON         0x0001          /* Printer on string            */
 284#define CH_STOP         0x0002          /* Output is stopped            */
 285#define CH_STOPI        0x0004          /* Input is stopped             */
 286#define CH_CD           0x0008          /* Carrier is present           */
 287#define CH_FCAR         0x0010          /* Carrier forced on            */
 288#define CH_HANGUP       0x0020          /* Hangup received              */
 289
 290#define CH_RECEIVER_OFF 0x0040          /* Receiver is off              */
 291#define CH_OPENING      0x0080          /* Port in fragile open state   */
 292#define CH_CLOSING      0x0100          /* Port in fragile close state  */
 293#define CH_FIFO_ENABLED 0x0200          /* Port has FIFOs enabled       */
 294#define CH_TX_FIFO_EMPTY 0x0400         /* TX Fifo is completely empty  */
 295#define CH_TX_FIFO_LWM  0x0800          /* TX Fifo is below Low Water   */
 296#define CH_BREAK_SENDING 0x1000         /* Break is being sent          */
 297#define CH_LOOPBACK 0x2000              /* Channel is in lookback mode  */
 298#define CH_FLIPBUF_IN_USE 0x4000        /* Channel's flipbuf is in use  */
 299#define CH_BAUD0        0x08000         /* Used for checking B0 transitions */
 300#define CH_FORCED_STOP  0x20000         /* Output is forcibly stopped   */
 301#define CH_FORCED_STOPI 0x40000         /* Input is forcibly stopped    */
 302
 303
 304/* Our Read/Error/Write queue sizes */
 305#define RQUEUEMASK      0x1FFF          /* 8 K - 1 */
 306#define EQUEUEMASK      0x1FFF          /* 8 K - 1 */
 307#define WQUEUEMASK      0x0FFF          /* 4 K - 1 */
 308#define RQUEUESIZE      (RQUEUEMASK + 1)
 309#define EQUEUESIZE      RQUEUESIZE
 310#define WQUEUESIZE      (WQUEUEMASK + 1)
 311
 312
 313/************************************************************************
 314 * Channel information structure.
 315 ************************************************************************/
 316struct channel_t {
 317        int magic;                      /* Channel Magic Number         */
 318        struct dgnc_board       *ch_bd;         /* Board structure pointer      */
 319        struct digi_t   ch_digi;        /* Transparent Print structure  */
 320        struct un_t     ch_tun;         /* Terminal unit info      */
 321        struct un_t     ch_pun;         /* Printer unit info        */
 322
 323        spinlock_t      ch_lock;        /* provide for serialization */
 324        wait_queue_head_t ch_flags_wait;
 325
 326        uint            ch_portnum;     /* Port number, 0 offset.       */
 327        uint            ch_open_count;  /* open count                   */
 328        uint            ch_flags;       /* Channel flags                */
 329
 330        ulong           ch_close_delay; /* How long we should drop RTS/DTR for */
 331
 332        ulong           ch_cpstime;     /* Time for CPS calculations    */
 333
 334        tcflag_t        ch_c_iflag;     /* channel iflags              */
 335        tcflag_t        ch_c_cflag;     /* channel cflags              */
 336        tcflag_t        ch_c_oflag;     /* channel oflags              */
 337        tcflag_t        ch_c_lflag;     /* channel lflags              */
 338        unsigned char   ch_stopc;       /* Stop character              */
 339        unsigned char   ch_startc;      /* Start character            */
 340
 341        uint            ch_old_baud;    /* Cache of the current baud */
 342        uint            ch_custom_speed;/* Custom baud, if set */
 343
 344        uint            ch_wopen;       /* Waiting for open process cnt */
 345
 346        unsigned char           ch_mostat;      /* FEP output modem status      */
 347        unsigned char           ch_mistat;      /* FEP input modem status       */
 348
 349        struct neo_uart_struct __iomem *ch_neo_uart;    /* Pointer to the "mapped" UART struct */
 350        struct cls_uart_struct __iomem *ch_cls_uart;    /* Pointer to the "mapped" UART struct */
 351
 352        unsigned char   ch_cached_lsr;  /* Cached value of the LSR register */
 353
 354        unsigned char   *ch_rqueue;     /* Our read queue buffer - malloc'ed */
 355        ushort          ch_r_head;      /* Head location of the read queue */
 356        ushort          ch_r_tail;      /* Tail location of the read queue */
 357
 358        unsigned char   *ch_equeue;     /* Our error queue buffer - malloc'ed */
 359        ushort          ch_e_head;      /* Head location of the error queue */
 360        ushort          ch_e_tail;      /* Tail location of the error queue */
 361
 362        unsigned char   *ch_wqueue;     /* Our write queue buffer - malloc'ed */
 363        ushort          ch_w_head;      /* Head location of the write queue */
 364        ushort          ch_w_tail;      /* Tail location of the write queue */
 365
 366        ulong           ch_rxcount;     /* total of data received so far */
 367        ulong           ch_txcount;     /* total of data transmitted so far */
 368
 369        unsigned char           ch_r_tlevel;    /* Receive Trigger level */
 370        unsigned char           ch_t_tlevel;    /* Transmit Trigger level */
 371
 372        unsigned char           ch_r_watermark; /* Receive Watermark */
 373
 374        ulong           ch_stop_sending_break;  /* Time we should STOP sending a break */
 375
 376        uint            ch_stops_sent;  /* How many times I have sent a stop character
 377                                         * to try to stop the other guy sending.
 378                                         */
 379        ulong           ch_err_parity;  /* Count of parity errors on channel */
 380        ulong           ch_err_frame;   /* Count of framing errors on channel */
 381        ulong           ch_err_break;   /* Count of breaks on channel */
 382        ulong           ch_err_overrun; /* Count of overruns on channel */
 383
 384        ulong           ch_xon_sends;   /* Count of xons transmitted */
 385        ulong           ch_xoff_sends;  /* Count of xoffs transmitted */
 386
 387        ulong           ch_intr_modem;  /* Count of interrupts */
 388        ulong           ch_intr_tx;     /* Count of interrupts */
 389        ulong           ch_intr_rx;     /* Count of interrupts */
 390
 391
 392        /* /proc/<board>/<channel> entries */
 393        struct proc_dir_entry *proc_entry_pointer;
 394        struct dgnc_proc_entry *dgnc_channel_table;
 395
 396};
 397
 398/*
 399 * Our Global Variables.
 400 */
 401extern uint             dgnc_Major;             /* Our driver/mgmt major        */
 402extern int              dgnc_poll_tick;         /* Poll interval - 20 ms        */
 403extern spinlock_t       dgnc_global_lock;       /* Driver global spinlock       */
 404extern uint             dgnc_NumBoards;         /* Total number of boards       */
 405extern struct dgnc_board        *dgnc_Board[MAXBOARDS]; /* Array of board structs       */
 406extern char             *dgnc_state_text[];     /* Array of state text          */
 407
 408#endif
 409