8bd6416f274c897fb7acf24d84b299f5b47cc9b5
[firefly-linux-kernel-4.4.55.git] / drivers / staging / dgap / dgap_driver.h
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 __DGAP_DRIVER_H
28 #define __DGAP_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 "dgap_types.h"         /* Additional types needed by the Digi header files */
35 #include "digi.h"               /* Digi specific ioctl header */
36 #include "dgap_kcompat.h"       /* Kernel 2.4/2.6 compat includes */
37
38 /*************************************************************************
39  *
40  * Driver defines
41  *
42  *************************************************************************/
43
44 /*
45  * Driver identification, error and debugging statments
46  *
47  * In theory, you can change all occurrences of "digi" in the next
48  * three lines, and the driver printk's will all automagically change.
49  *
50  * APR((fmt, args, ...));       Always prints message
51  * DPR((fmt, args, ...));       Only prints if DGAP_TRACER is defined at
52  *                                compile time and dgap_debug!=0
53  */
54 #define DG_NAME         "dgap-1.3-16"
55 #define DG_PART         "40002347_C"
56
57 #define PROCSTR         "dgap"                  /* /proc entries         */
58 #define DEVSTR          "/dev/dg/dgap"          /* /dev entries          */
59 #define DRVSTR          "dgap"                  /* Driver name string
60                                                  * displayed by APR      */
61 #define APR(args)       do { PRINTF_TO_KMEM(args); printk(DRVSTR": "); printk args; \
62                            } while (0)
63 #define RAPR(args)      do { PRINTF_TO_KMEM(args); printk args; } while (0)
64
65 #define TRC_TO_CONSOLE 1
66
67 /*
68  * Debugging levels can be set using debug insmod variable
69  * They can also be compiled out completely.
70  */
71
72 #define DBG_INIT                (dgap_debug & 0x01)
73 #define DBG_BASIC               (dgap_debug & 0x02)
74 #define DBG_CORE                (dgap_debug & 0x04)
75
76 #define DBG_OPEN                (dgap_debug & 0x08)
77 #define DBG_CLOSE               (dgap_debug & 0x10)
78 #define DBG_READ                (dgap_debug & 0x20)
79 #define DBG_WRITE               (dgap_debug & 0x40)
80
81 #define DBG_IOCTL               (dgap_debug & 0x80)
82
83 #define DBG_PROC                (dgap_debug & 0x100)
84 #define DBG_PARAM               (dgap_debug & 0x200)
85 #define DBG_PSCAN               (dgap_debug & 0x400)
86 #define DBG_EVENT               (dgap_debug & 0x800)
87
88 #define DBG_DRAIN               (dgap_debug & 0x1000)
89 #define DBG_CARR                (dgap_debug & 0x2000)
90
91 #define DBG_MGMT                (dgap_debug & 0x4000)
92
93
94 #if defined(DGAP_TRACER)
95
96 # if defined(TRC_TO_KMEM)
97 /* Choose one: */
98 #  define TRC_ON_OVERFLOW_WRAP_AROUND
99 #  undef  TRC_ON_OVERFLOW_SHIFT_BUFFER
100 # endif //TRC_TO_KMEM
101
102 # define TRC_MAXMSG             1024
103 # define TRC_OVERFLOW           "(OVERFLOW)"
104 # define TRC_DTRC               "/usr/bin/dtrc"
105
106 #if defined TRC_TO_CONSOLE
107 #define PRINTF_TO_CONSOLE(args) { printk(DRVSTR": "); printk args; }
108 #else //!defined TRACE_TO_CONSOLE
109 #define PRINTF_TO_CONSOLE(args)
110 #endif
111
112 #if defined TRC_TO_KMEM
113 #define PRINTF_TO_KMEM(args) dgap_tracef args
114 #else //!defined TRC_TO_KMEM
115 #define PRINTF_TO_KMEM(args)
116 #endif
117
118 #define TRC(args)       { PRINTF_TO_KMEM(args); PRINTF_TO_CONSOLE(args) }
119
120 # define DPR_INIT(ARGS)         if (DBG_INIT) TRC(ARGS)
121 # define DPR_BASIC(ARGS)        if (DBG_BASIC) TRC(ARGS)
122 # define DPR_CORE(ARGS)         if (DBG_CORE) TRC(ARGS)
123 # define DPR_OPEN(ARGS)         if (DBG_OPEN)  TRC(ARGS)
124 # define DPR_CLOSE(ARGS)        if (DBG_CLOSE)  TRC(ARGS)
125 # define DPR_READ(ARGS)         if (DBG_READ)  TRC(ARGS)
126 # define DPR_WRITE(ARGS)        if (DBG_WRITE) TRC(ARGS)
127 # define DPR_IOCTL(ARGS)        if (DBG_IOCTL) TRC(ARGS)
128 # define DPR_PROC(ARGS)         if (DBG_PROC)  TRC(ARGS)
129 # define DPR_PARAM(ARGS)        if (DBG_PARAM)  TRC(ARGS)
130 # define DPR_PSCAN(ARGS)        if (DBG_PSCAN)  TRC(ARGS)
131 # define DPR_EVENT(ARGS)        if (DBG_EVENT)  TRC(ARGS)
132 # define DPR_DRAIN(ARGS)        if (DBG_DRAIN)  TRC(ARGS)
133 # define DPR_CARR(ARGS)         if (DBG_CARR)  TRC(ARGS)
134 # define DPR_MGMT(ARGS)         if (DBG_MGMT)  TRC(ARGS)
135
136 # define DPR(ARGS)              if (dgap_debug) TRC(ARGS)
137 # define P(X)                   dgap_tracef(#X "=%p\n", X)
138 # define X(X)                   dgap_tracef(#X "=%x\n", X)
139
140 #else//!defined DGAP_TRACER
141
142 #define PRINTF_TO_KMEM(args)
143 # define TRC(ARGS)
144 # define DPR_INIT(ARGS)
145 # define DPR_BASIC(ARGS)
146 # define DPR_CORE(ARGS)
147 # define DPR_OPEN(ARGS)
148 # define DPR_CLOSE(ARGS)
149 # define DPR_READ(ARGS)
150 # define DPR_WRITE(ARGS)
151 # define DPR_IOCTL(ARGS)
152 # define DPR_PROC(ARGS)
153 # define DPR_PARAM(ARGS)
154 # define DPR_PSCAN(ARGS)
155 # define DPR_EVENT(ARGS)
156 # define DPR_DRAIN(ARGS)
157 # define DPR_CARR(ARGS)
158 # define DPR_MGMT(ARGS)
159
160 # define DPR(args)
161
162 #endif//DGAP_TRACER
163
164 /* Number of boards we support at once. */
165 #define MAXBOARDS       32
166 #define MAXPORTS        224
167 #define MAXTTYNAMELEN   200
168
169 /* Our 3 magic numbers for our board, channel and unit structs */
170 #define DGAP_BOARD_MAGIC        0x5c6df104
171 #define DGAP_CHANNEL_MAGIC      0x6c6df104
172 #define DGAP_UNIT_MAGIC         0x7c6df104
173
174 /* Serial port types */
175 #define DGAP_SERIAL             0
176 #define DGAP_PRINT              1
177
178 #define SERIAL_TYPE_NORMAL      1
179
180 /* 4 extra for alignment play space */
181 #define WRITEBUFLEN             ((4096) + 4)
182 #define MYFLIPLEN               N_TTY_BUF_SIZE
183
184 #define SBREAK_TIME 0x25
185 #define U2BSIZE 0x400
186
187 #define dgap_jiffies_from_ms(a) (((a) * HZ) / 1000)
188
189 /*
190  * Our major for the mgmt devices.
191  *
192  * We can use 22, because Digi was allocated 22 and 23 for the epca driver.
193  * 22 has now become obsolete now that the "cu" devices have
194  * been removed from 2.6.
195  * Also, this *IS* the epca driver, just PCI only now.
196  */
197 #ifndef DIGI_DGAP_MAJOR
198 # define DIGI_DGAP_MAJOR         22
199 #endif
200
201 /*
202  * The parameters we use to define the periods of the moving averages.
203  */
204 #define         MA_PERIOD       (HZ / 10)
205 #define         SMA_DUR         (1 * HZ)
206 #define         EMA_DUR         (1 * HZ)
207 #define         SMA_NPERIODS    (SMA_DUR / MA_PERIOD)
208 #define         EMA_NPERIODS    (EMA_DUR / MA_PERIOD)
209
210 /*
211  * Define a local default termios struct. All ports will be created
212  * with this termios initially.  This is the same structure that is defined
213  * as the default in tty_io.c with the same settings overriden as in serial.c
214  *
215  * In short, this should match the internal serial ports' defaults.
216  */
217 #define DEFAULT_IFLAGS  (ICRNL | IXON)
218 #define DEFAULT_OFLAGS  (OPOST | ONLCR)
219 #define DEFAULT_CFLAGS  (B9600 | CS8 | CREAD | HUPCL | CLOCAL)
220 #define DEFAULT_LFLAGS  (ISIG | ICANON | ECHO | ECHOE | ECHOK | \
221                         ECHOCTL | ECHOKE | IEXTEN)
222
223 #ifndef _POSIX_VDISABLE
224 #define   _POSIX_VDISABLE '\0'
225 #endif
226
227 #define SNIFF_MAX       65536           /* Sniff buffer size (2^n) */
228 #define SNIFF_MASK      (SNIFF_MAX - 1) /* Sniff wrap mask */
229
230 #define VPDSIZE (512)
231
232 /*
233  * Lock function/defines.
234  * Makes spotting lock/unlock locations easier.
235  */
236 # define DGAP_SPINLOCK_INIT(x)          spin_lock_init(&(x))
237 # define DGAP_LOCK(x,y)                 spin_lock_irqsave(&(x), y)
238 # define DGAP_UNLOCK(x,y)               spin_unlock_irqrestore(&(x), y)
239 # define DGAP_TRYLOCK(x,y)              spin_trylock(&(x))
240
241 /************************************************************************
242  *      FEP memory offsets
243  ************************************************************************/
244 #define START           0x0004L         /* Execution start address      */
245
246 #define CMDBUF          0x0d10L         /* Command (cm_t) structure offset */
247 #define CMDSTART        0x0400L         /* Start of command buffer      */
248 #define CMDMAX          0x0800L         /* End of command buffer        */
249
250 #define EVBUF           0x0d18L         /* Event (ev_t) structure       */
251 #define EVSTART         0x0800L         /* Start of event buffer        */
252 #define EVMAX           0x0c00L         /* End of event buffer          */
253 #define FEP5_PLUS       0x0E40          /* ASCII '5' and ASCII 'A' is here  */
254 #define ECS_SEG         0x0E44          /* Segment of the extended channel structure */
255 #define LINE_SPEED      0x10            /* Offset into ECS_SEG for line speed   */
256                                         /* if the fep has extended capabilities */
257
258 /* BIOS MAGIC SPOTS */
259 #define ERROR           0x0C14L         /* BIOS error code              */
260 #define SEQUENCE        0x0C12L         /* BIOS sequence indicator      */
261 #define POSTAREA        0x0C00L         /* POST complete message area   */
262
263 /* FEP MAGIC SPOTS */
264 #define FEPSTAT         POSTAREA        /* OS here when FEP comes up    */
265 #define NCHAN           0x0C02L         /* number of ports FEP sees     */
266 #define PANIC           0x0C10L         /* PANIC area for FEP           */
267 #define KMEMEM          0x0C30L         /* Memory for KME use           */
268 #define CONFIG          0x0CD0L         /* Concentrator configuration info */
269 #define CONFIGSIZE      0x0030          /* configuration info size      */
270 #define DOWNREQ         0x0D00          /* Download request buffer pointer */
271
272 #define CHANBUF         0x1000L         /* Async channel (bs_t) structs */
273 #define FEPOSSIZE       0x1FFF          /* 8K FEPOS                     */
274
275 #define XEMPORTS    0xC02       /*
276                                  * Offset in board memory where FEP5 stores
277                                  * how many ports it has detected.
278                                  * NOTE: FEP5 reports 64 ports when the user
279                                  * has the cable in EBI OUT instead of EBI IN.
280                                  */
281
282 #define FEPCLR      0x00
283 #define FEPMEM      0x02
284 #define FEPRST      0x04
285 #define FEPINT      0x08
286 #define FEPMASK     0x0e
287 #define FEPWIN      0x80
288
289 #define LOWMEM      0x0100
290 #define HIGHMEM     0x7f00
291
292 #define FEPTIMEOUT 200000
293
294 #define ENABLE_INTR             0x0e04          /* Enable interrupts flag */
295 #define FEPPOLL_MIN             1               /* minimum of 1 millisecond */
296 #define FEPPOLL_MAX             20              /* maximum of 20 milliseconds */
297 #define FEPPOLL                 0x0c26          /* Fep event poll interval */
298
299 #define IALTPIN                 0x0080          /* Input flag to swap DSR <-> DCD */
300
301 /************************************************************************
302  * FEP supported functions
303  ************************************************************************/
304 #define SRLOW           0xe0            /* Set receive low water        */
305 #define SRHIGH          0xe1            /* Set receive high water       */
306 #define FLUSHTX         0xe2            /* Flush transmit buffer        */
307 #define PAUSETX         0xe3            /* Pause data transmission      */
308 #define RESUMETX        0xe4            /* Resume data transmission     */
309 #define SMINT           0xe5            /* Set Modem Interrupt          */
310 #define SAFLOWC         0xe6            /* Set Aux. flow control chars  */
311 #define SBREAK          0xe8            /* Send break                   */
312 #define SMODEM          0xe9            /* Set 8530 modem control lines */
313 #define SIFLAG          0xea            /* Set UNIX iflags              */
314 #define SFLOWC          0xeb            /* Set flow control characters  */
315 #define STLOW           0xec            /* Set transmit low water mark  */
316 #define RPAUSE          0xee            /* Pause receive                */
317 #define RRESUME         0xef            /* Resume receive               */
318 #define CHRESET         0xf0            /* Reset Channel                */
319 #define BUFSETALL       0xf2            /* Set Tx & Rx buffer size avail*/
320 #define SOFLAG          0xf3            /* Set UNIX oflags              */
321 #define SHFLOW          0xf4            /* Set hardware handshake       */
322 #define SCFLAG          0xf5            /* Set UNIX cflags              */
323 #define SVNEXT          0xf6            /* Set VNEXT character          */
324 #define SPINTFC         0xfc            /* Reserved                     */
325 #define SCOMMODE        0xfd            /* Set RS232/422 mode           */
326
327
328 /************************************************************************
329  *      Modes for SCOMMODE
330  ************************************************************************/
331 #define MODE_232        0x00
332 #define MODE_422        0x01
333
334
335 /************************************************************************
336  *      Event flags.
337  ************************************************************************/
338 #define IFBREAK         0x01            /* Break received               */
339 #define IFTLW           0x02            /* Transmit low water           */
340 #define IFTEM           0x04            /* Transmitter empty            */
341 #define IFDATA          0x08            /* Receive data present         */
342 #define IFMODEM         0x20            /* Modem status change          */
343
344 /************************************************************************
345  *      Modem flags
346  ************************************************************************/
347 #       define  DM_RTS          0x02    /* Request to send              */
348 #       define  DM_CD           0x80    /* Carrier detect               */
349 #       define  DM_DSR          0x20    /* Data set ready               */
350 #       define  DM_CTS          0x10    /* Clear to send                */
351 #       define  DM_RI           0x40    /* Ring indicator               */
352 #       define  DM_DTR          0x01    /* Data terminal ready          */
353
354 /*
355  * All the possible states the driver can be while being loaded.
356  */
357 enum {
358         DRIVER_INITIALIZED = 0,
359         DRIVER_NEED_CONFIG_LOAD,
360         DRIVER_REQUESTED_CONFIG,
361         DRIVER_READY
362 };
363
364 /*
365  * All the possible states the board can be while booting up.
366  */
367 enum {
368         BOARD_FAILED = 0,
369         CONFIG_NOT_FOUND,
370         BOARD_FOUND,
371         NEED_RESET,
372         FINISHED_RESET,
373         NEED_CONFIG,
374         FINISHED_CONFIG,
375         NEED_DEVICE_CREATION,
376         REQUESTED_DEVICE_CREATION,
377         FINISHED_DEVICE_CREATION,
378         NEED_BIOS_LOAD,
379         REQUESTED_BIOS,
380         WAIT_BIOS_LOAD,
381         FINISHED_BIOS_LOAD,
382         NEED_FEP_LOAD,
383         REQUESTED_FEP,
384         WAIT_FEP_LOAD,
385         FINISHED_FEP_LOAD,
386         NEED_PROC_CREATION,
387         FINISHED_PROC_CREATION,
388         BOARD_READY
389 };
390
391 /*
392  * All the possible states that a requested concentrator image can be in.
393  */
394 enum {
395         NO_PENDING_CONCENTRATOR_REQUESTS = 0,
396         NEED_CONCENTRATOR,
397         REQUESTED_CONCENTRATOR
398 };
399
400 extern char *dgap_state_text[];
401 extern char *dgap_driver_state_text[];
402
403
404 /*
405  * Modem line constants are defined as macros because DSR and
406  * DCD are swapable using the ditty altpin option.
407  */
408 #define D_CD(ch)        ch->ch_cd       /* Carrier detect       */
409 #define D_DSR(ch)       ch->ch_dsr      /* Data set ready       */
410 #define D_RTS(ch)       DM_RTS          /* Request to send      */
411 #define D_CTS(ch)       DM_CTS          /* Clear to send        */
412 #define D_RI(ch)        DM_RI           /* Ring indicator       */
413 #define D_DTR(ch)       DM_DTR          /* Data terminal ready  */
414
415
416 /*************************************************************************
417  *
418  * Structures and closely related defines.
419  *
420  *************************************************************************/
421
422
423 /*
424  * A structure to hold a statistics counter.  We also
425  * compute moving averages for this counter.
426  */
427 struct macounter
428 {
429         u32             cnt;    /* Total count */
430         ulong           accum;  /* Acuumulator per period */
431         ulong           sma;    /* Simple moving average */
432         ulong           ema;    /* Exponential moving average */
433 };
434
435
436 /************************************************************************
437  * Device flag definitions for bd_flags.
438  ************************************************************************/
439 #define BD_FEP5PLUS     0x0001          /* Supports FEP5 Plus commands */
440 #define BD_HAS_VPD      0x0002          /* Board has VPD info available */
441
442
443 /*
444  *      Per-board information
445  */
446 struct board_t
447 {
448         int             magic;          /* Board Magic number.  */
449         int             boardnum;       /* Board number: 0-3 */
450         int             firstminor;     /* First minor, e.g. 0, 30, 60 */
451
452         int             type;           /* Type of board */
453         char            *name;          /* Product Name */
454         struct pci_dev  *pdev;          /* Pointer to the pci_dev struct */
455         u16             vendor;         /* PCI vendor ID */
456         u16             device;         /* PCI device ID */
457         u16             subvendor;      /* PCI subsystem vendor ID */
458         u16             subdevice;      /* PCI subsystem device ID */
459         uchar           rev;            /* PCI revision ID */
460         uint            pci_bus;        /* PCI bus value */
461         uint            pci_slot;       /* PCI slot value */
462         u16             maxports;       /* MAX ports this board can handle */
463         uchar           vpd[VPDSIZE];   /* VPD of board, if found */
464         u32             bd_flags;       /* Board flags */
465
466         spinlock_t      bd_lock;        /* Used to protect board */
467
468         u32             state;          /* State of card. */
469         wait_queue_head_t state_wait;   /* Place to sleep on for state change */
470
471         struct          tasklet_struct helper_tasklet; /* Poll helper tasklet */
472
473         u32             wait_for_bios;
474         u32             wait_for_fep;
475
476         struct cnode *  bd_config;      /* Config of board */
477
478         u16             nasync;         /* Number of ports on card */
479
480         u32             use_interrupts; /* Should we be interrupt driven? */
481         ulong           irq;            /* Interrupt request number */
482         ulong           intr_count;     /* Count of interrupts */
483         u32             intr_used;      /* Non-zero if using interrupts */
484         u32             intr_running;   /* Non-zero if FEP knows its doing interrupts */
485
486         ulong           port;           /* Start of base io port of the card */
487         ulong           port_end;       /* End of base io port of the card */
488         ulong           membase;        /* Start of base memory of the card */
489         ulong           membase_end;    /* End of base memory of the card */
490
491         uchar           *re_map_port;   /* Remapped io port of the card */
492         uchar           *re_map_membase;/* Remapped memory of the card */
493
494         uchar           runwait;        /* # Processes waiting for FEP  */
495         uchar           inhibit_poller; /* Tells  the poller to leave us alone */
496
497         struct channel_t *channels[MAXPORTS]; /* array of pointers to our channels. */
498
499         struct tty_driver       *SerialDriver;
500         char            SerialName[200];
501         struct tty_driver       *PrintDriver;
502         char            PrintName[200];
503
504         u32             dgap_Major_Serial_Registered;
505         u32             dgap_Major_TransparentPrint_Registered;
506
507         u32             dgap_Serial_Major;
508         u32             dgap_TransparentPrint_Major;
509
510         struct bs_t     *bd_bs;                 /* Base structure pointer       */
511
512         char    *flipbuf;               /* Our flip buffer, alloced if board is found */
513         char    *flipflagbuf;           /* Our flip flag buffer, alloced if board is found */
514
515         u16             dpatype;        /* The board "type", as defined by DPA */
516         u16             dpastatus;      /* The board "status", as defined by DPA */
517         wait_queue_head_t kme_wait;     /* Needed for DPA support */
518
519         u32             conc_dl_status; /* Status of any pending conc download */
520         /*
521          *      Mgmt data.
522          */
523         char            *msgbuf_head;
524         char            *msgbuf;
525 };
526
527
528
529 /************************************************************************
530  * Unit flag definitions for un_flags.
531  ************************************************************************/
532 #define UN_ISOPEN       0x0001          /* Device is open               */
533 #define UN_CLOSING      0x0002          /* Line is being closed         */
534 #define UN_IMM          0x0004          /* Service immediately          */
535 #define UN_BUSY         0x0008          /* Some work this channel       */
536 #define UN_BREAKI       0x0010          /* Input break received         */
537 #define UN_PWAIT        0x0020          /* Printer waiting for terminal */
538 #define UN_TIME         0x0040          /* Waiting on time              */
539 #define UN_EMPTY        0x0080          /* Waiting output queue empty   */
540 #define UN_LOW          0x0100          /* Waiting output low water mark*/
541 #define UN_EXCL_OPEN    0x0200          /* Open for exclusive use       */
542 #define UN_WOPEN        0x0400          /* Device waiting for open      */
543 #define UN_WIOCTL       0x0800          /* Device waiting for open      */
544 #define UN_HANGUP       0x8000          /* Carrier lost                 */
545
546 struct device;
547
548 /************************************************************************
549  * Structure for terminal or printer unit.
550  ************************************************************************/
551 struct un_t {
552         int     magic;          /* Unit Magic Number.                   */
553         struct  channel_t *un_ch;
554         u32     un_time;
555         u32     un_type;
556         u32     un_open_count;  /* Counter of opens to port             */
557         struct tty_struct *un_tty;/* Pointer to unit tty structure      */
558         u32     un_flags;       /* Unit flags                           */
559         wait_queue_head_t un_flags_wait; /* Place to sleep to wait on unit */
560         u32     un_dev;         /* Minor device number                  */
561         tcflag_t un_oflag;      /* oflags being done on board           */
562         tcflag_t un_lflag;      /* lflags being done on board           */
563         struct device *un_sysfs;
564 };
565
566
567 /************************************************************************
568  * Device flag definitions for ch_flags.
569  ************************************************************************/
570 #define CH_PRON         0x0001          /* Printer on string                */
571 #define CH_OUT          0x0002          /* Dial-out device open             */
572 #define CH_STOP         0x0004          /* Output is stopped                */
573 #define CH_STOPI        0x0008          /* Input is stopped                 */
574 #define CH_CD           0x0010          /* Carrier is present               */
575 #define CH_FCAR         0x0020          /* Carrier forced on                */
576
577 #define CH_RXBLOCK      0x0080          /* Enable rx blocked flag           */
578 #define CH_WLOW         0x0100          /* Term waiting low event           */
579 #define CH_WEMPTY       0x0200          /* Term waiting empty event         */
580 #define CH_RENABLE      0x0400          /* Buffer just emptied          */
581 #define CH_RACTIVE      0x0800          /* Process active in xxread()   */
582 #define CH_RWAIT        0x1000          /* Process waiting in xxread()  */
583 #define CH_BAUD0        0x2000          /* Used for checking B0 transitions */
584 #define CH_HANGUP       0x8000          /* Hangup received                  */
585
586 /*
587  * Definitions for ch_sniff_flags
588  */
589 #define SNIFF_OPEN      0x1
590 #define SNIFF_WAIT_DATA 0x2
591 #define SNIFF_WAIT_SPACE 0x4
592
593
594 /************************************************************************
595  * Channel information structure.
596  ************************************************************************/
597 struct channel_t {
598         int magic;                      /* Channel Magic Number         */
599         struct bs_t     *ch_bs;         /* Base structure pointer       */
600         struct cm_t     *ch_cm;         /* Command queue pointer        */
601         struct board_t *ch_bd;          /* Board structure pointer      */
602         unsigned char *ch_vaddr;        /* FEP memory origin            */
603         unsigned char *ch_taddr;        /* Write buffer origin          */
604         unsigned char *ch_raddr;        /* Read buffer origin           */
605         struct digi_t  ch_digi;         /* Transparent Print structure  */
606         struct un_t ch_tun;             /* Terminal unit info           */
607         struct un_t ch_pun;             /* Printer unit info            */
608
609         spinlock_t      ch_lock;        /* provide for serialization */
610         wait_queue_head_t ch_flags_wait;
611
612         u32     pscan_state;
613         uchar   pscan_savechar;
614
615         u32 ch_portnum;                 /* Port number, 0 offset.       */
616         u32 ch_open_count;              /* open count                   */
617         u32     ch_flags;               /* Channel flags                */
618
619
620         u32     ch_close_delay;         /* How long we should drop RTS/DTR for */
621
622         u32     ch_cpstime;             /* Time for CPS calculations    */
623
624         tcflag_t ch_c_iflag;            /* channel iflags               */
625         tcflag_t ch_c_cflag;            /* channel cflags               */
626         tcflag_t ch_c_oflag;            /* channel oflags               */
627         tcflag_t ch_c_lflag;            /* channel lflags               */
628
629         u16  ch_fepiflag;            /* FEP tty iflags               */
630         u16  ch_fepcflag;               /* FEP tty cflags               */
631         u16  ch_fepoflag;               /* FEP tty oflags               */
632         u16  ch_wopen;                  /* Waiting for open process cnt */
633         u16  ch_tstart;                 /* Transmit buffer start        */
634         u16  ch_tsize;                  /* Transmit buffer size         */
635         u16  ch_rstart;                 /* Receive buffer start         */
636         u16  ch_rsize;                  /* Receive buffer size          */
637         u16  ch_rdelay;                 /* Receive delay time           */
638
639         u16     ch_tlw;                 /* Our currently set low water mark */
640
641         u16  ch_cook;                   /* Output character mask        */
642
643         uchar   ch_card;                /* Card channel is on           */
644         uchar   ch_stopc;               /* Stop character               */
645         uchar   ch_startc;              /* Start character              */
646
647         uchar   ch_mostat;              /* FEP output modem status      */
648         uchar   ch_mistat;              /* FEP input modem status       */
649         uchar   ch_mforce;              /* Modem values to be forced    */
650         uchar   ch_mval;                /* Force values                 */
651         uchar   ch_fepstopc;            /* FEP stop character           */
652         uchar   ch_fepstartc;           /* FEP start character          */
653
654         uchar   ch_astopc;              /* Auxiliary Stop character     */
655         uchar   ch_astartc;             /* Auxiliary Start character    */
656         uchar   ch_fepastopc;           /* Auxiliary FEP stop char      */
657         uchar   ch_fepastartc;          /* Auxiliary FEP start char     */
658
659         uchar   ch_hflow;               /* FEP hardware handshake       */
660         uchar   ch_dsr;                 /* stores real dsr value        */
661         uchar   ch_cd;                  /* stores real cd value         */
662         uchar   ch_tx_win;              /* channel tx buffer window     */
663         uchar   ch_rx_win;              /* channel rx buffer window     */
664         uint    ch_custom_speed;        /* Custom baud, if set          */
665         uint    ch_baud_info;           /* Current baud info for /proc output   */
666         ulong   ch_rxcount;             /* total of data received so far        */
667         ulong   ch_txcount;             /* total of data transmitted so far     */
668         ulong   ch_err_parity;          /* Count of parity errors on channel    */
669         ulong   ch_err_frame;           /* Count of framing errors on channel   */
670         ulong   ch_err_break;           /* Count of breaks on channel   */
671         ulong   ch_err_overrun;         /* Count of overruns on channel */
672
673         uint ch_sniff_in;
674         uint ch_sniff_out;
675         char *ch_sniff_buf;             /* Sniff buffer for proc */
676         ulong ch_sniff_flags;           /* Channel flags                */
677         wait_queue_head_t ch_sniff_wait;
678 };
679
680 /************************************************************************
681  * Command structure definition.
682  ************************************************************************/
683 struct cm_t {
684         volatile unsigned short cm_head;        /* Command buffer head offset   */
685         volatile unsigned short cm_tail;        /* Command buffer tail offset   */
686         volatile unsigned short cm_start;       /* start offset of buffer       */
687         volatile unsigned short cm_max;         /* last offset of buffer        */
688 };
689
690 /************************************************************************
691  * Event structure definition.
692  ************************************************************************/
693 struct ev_t {
694         volatile unsigned short ev_head;        /* Command buffer head offset   */
695         volatile unsigned short ev_tail;        /* Command buffer tail offset   */
696         volatile unsigned short ev_start;       /* start offset of buffer       */
697         volatile unsigned short ev_max;         /* last offset of buffer        */
698 };
699
700 /************************************************************************
701  * Download buffer structure.
702  ************************************************************************/
703 struct downld_t {
704         uchar   dl_type;                /* Header                       */
705         uchar   dl_seq;                 /* Download sequence            */
706         ushort  dl_srev;                /* Software revision number     */
707         ushort  dl_lrev;                /* Low revision number          */
708         ushort  dl_hrev;                /* High revision number         */
709         ushort  dl_seg;                 /* Start segment address        */
710         ushort  dl_size;                /* Number of bytes to download  */
711         uchar   dl_data[1024];          /* Download data                */
712 };
713
714 /************************************************************************
715  * Per channel buffer structure
716  ************************************************************************
717  *              Base Structure Entries Usage Meanings to Host           *
718  *                                                                      *
719  *        W = read write        R = read only                           *
720  *        C = changed by commands only                                  *
721  *        U = unknown (may be changed w/o notice)                       *
722  ************************************************************************/
723 struct bs_t {
724         volatile unsigned short  tp_jmp;        /* Transmit poll jump            */
725         volatile unsigned short  tc_jmp;        /* Cooked procedure jump         */
726         volatile unsigned short  ri_jmp;        /* Not currently used            */
727         volatile unsigned short  rp_jmp;        /* Receive poll jump             */
728
729         volatile unsigned short  tx_seg;        /* W  Tx segment         */
730         volatile unsigned short  tx_head;       /* W  Tx buffer head offset     */
731         volatile unsigned short  tx_tail;       /* R  Tx buffer tail offset     */
732         volatile unsigned short  tx_max;        /* W  Tx buffer size - 1         */
733
734         volatile unsigned short  rx_seg;        /* W  Rx segment                */
735         volatile unsigned short  rx_head;       /* W  Rx buffer head offset     */
736         volatile unsigned short  rx_tail;       /* R  Rx buffer tail offset     */
737         volatile unsigned short  rx_max;        /* W  Rx buffer size - 1         */
738
739         volatile unsigned short  tx_lw;         /* W  Tx buffer low water mark  */
740         volatile unsigned short  rx_lw;         /* W  Rx buffer low water mark  */
741         volatile unsigned short  rx_hw;         /* W  Rx buffer high water mark */
742         volatile unsigned short  incr;          /* W  Increment to next channel */
743
744         volatile unsigned short  fepdev;        /* U  SCC device base address    */
745         volatile unsigned short  edelay;        /* W  Exception delay            */
746         volatile unsigned short  blen;          /* W  Break length              */
747         volatile unsigned short  btime;         /* U  Break complete time       */
748
749         volatile unsigned short  iflag;         /* C  UNIX input flags          */
750         volatile unsigned short  oflag;         /* C  UNIX output flags         */
751         volatile unsigned short  cflag;         /* C  UNIX control flags        */
752         volatile unsigned short  wfill[13];     /* U  Reserved for expansion    */
753
754         volatile unsigned char   num;           /* U  Channel number            */
755         volatile unsigned char   ract;          /* U  Receiver active counter   */
756         volatile unsigned char   bstat;         /* U  Break status bits         */
757         volatile unsigned char   tbusy;         /* W  Transmit busy             */
758         volatile unsigned char   iempty;        /* W  Transmit empty event enable */
759         volatile unsigned char   ilow;          /* W  Transmit low-water event enable */
760         volatile unsigned char   idata;         /* W  Receive data interrupt enable */
761         volatile unsigned char   eflag;         /* U  Host event flags          */
762
763         volatile unsigned char   tflag;         /* U  Transmit flags            */
764         volatile unsigned char   rflag;         /* U  Receive flags             */
765         volatile unsigned char   xmask;         /* U  Transmit ready flags      */
766         volatile unsigned char   xval;          /* U  Transmit ready value      */
767         volatile unsigned char   m_stat;        /* RC Modem status bits          */
768         volatile unsigned char   m_change;      /* U  Modem bits which changed  */
769         volatile unsigned char   m_int;         /* W  Modem interrupt enable bits */
770         volatile unsigned char   m_last;        /* U  Last modem status         */
771
772         volatile unsigned char   mtran;         /* C   Unreported modem trans   */
773         volatile unsigned char   orun;          /* C   Buffer overrun occurred  */
774         volatile unsigned char   astartc;       /* W   Auxiliary Xon char       */
775         volatile unsigned char   astopc;        /* W   Auxiliary Xoff char      */
776         volatile unsigned char   startc;        /* W   Xon character             */
777         volatile unsigned char   stopc;         /* W   Xoff character           */
778         volatile unsigned char   vnextc;        /* W   Vnext character           */
779         volatile unsigned char   hflow;         /* C   Software flow control    */
780         
781         volatile unsigned char   fillc;         /* U   Delay Fill character     */
782         volatile unsigned char   ochar;         /* U   Saved output character   */
783         volatile unsigned char   omask;         /* U   Output character mask    */
784
785         volatile unsigned char   bfill[13];     /* U   Reserved for expansion   */
786
787         volatile unsigned char   scc[16];       /* U   SCC registers            */
788 };
789
790 /*************************************************************************
791  *
792  * Prototypes for non-static functions used in more than one module
793  *
794  *************************************************************************/
795
796 extern int              dgap_ms_sleep(ulong ms);
797 extern char             *dgap_ioctl_name(int cmd);
798 extern void             dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len);
799 extern void             dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len);
800 extern void             dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len);
801 extern void             dgap_do_config_load(uchar __user *uaddr, int len);
802 extern int              dgap_after_config_loaded(void);
803 extern int              dgap_finalize_board_init(struct board_t *brd);
804
805 /*
806  * Our Global Variables.
807  */
808 extern int              dgap_driver_state;      /* The state of the driver      */
809 extern int              dgap_debug;             /* Debug variable               */
810 extern int              dgap_rawreadok;         /* Set if user wants rawreads   */
811 extern int              dgap_poll_tick;         /* Poll interval - 20 ms        */
812 extern spinlock_t       dgap_global_lock;       /* Driver global spinlock       */
813 extern uint             dgap_NumBoards;         /* Total number of boards       */
814 extern struct board_t   *dgap_Board[MAXBOARDS]; /* Array of board structs       */
815 extern ulong            dgap_poll_counter;      /* Times the poller has run     */
816 extern char             *dgap_config_buf;       /* The config file buffer       */
817 extern spinlock_t       dgap_dl_lock;           /* Downloader spinlock          */
818 extern wait_queue_head_t dgap_dl_wait;          /* Wait queue for downloader    */
819 extern int              dgap_dl_action;         /* Action flag for downloader   */
820 extern int              dgap_registerttyswithsysfs; /* Should we register the   */
821                                                     /* ttys with sysfs or not   */
822
823 /*
824  * Global functions declared in dgap_fep5.c, but must be hidden from
825  * user space programs.
826  */
827 extern void     dgap_poll_tasklet(unsigned long data);
828 extern void     dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds);
829 extern void     dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds);
830 extern void     dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
831 extern int      dgap_param(struct tty_struct *tty);
832 extern void     dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len);
833 extern uint     dgap_get_custom_baud(struct channel_t *ch);
834 extern void     dgap_firmware_reset_port(struct channel_t *ch);
835
836 #endif