2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
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)
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.
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.
19 * NOTE: THIS IS A SHARED HEADER. DO NOT CHANGE CODING STYLE!!!
21 *************************************************************************
25 *************************************************************************/
27 #ifndef __DGAP_DRIVER_H
28 #define __DGAP_DRIVER_H
30 #include <linux/version.h> /* To get the current Linux version */
31 #include <linux/types.h> /* To pick up the varions Linux types */
32 #include <linux/tty.h> /* To pick up the various tty structs/defines */
33 #include <linux/interrupt.h> /* For irqreturn_t type */
35 #include "dgap_types.h" /* Additional types needed by the Digi header files */
36 #include "digi.h" /* Digi specific ioctl header */
37 #include "dgap_kcompat.h" /* Kernel 2.4/2.6 compat includes */
38 #include "dgap_sysfs.h" /* Support for SYSFS */
40 /*************************************************************************
44 *************************************************************************/
47 * Driver identification, error and debugging statments
49 * In theory, you can change all occurances of "digi" in the next
50 * three lines, and the driver printk's will all automagically change.
52 * APR((fmt, args, ...)); Always prints message
53 * DPR((fmt, args, ...)); Only prints if DGAP_TRACER is defined at
54 * compile time and dgap_debug!=0
56 #define PROCSTR "dgap" /* /proc entries */
57 #define DEVSTR "/dev/dg/dgap" /* /dev entries */
58 #define DRVSTR "dgap" /* Driver name string
60 #define APR(args) do { PRINTF_TO_KMEM(args); printk(DRVSTR": "); printk args; \
62 #define RAPR(args) do { PRINTF_TO_KMEM(args); printk args; } while (0)
64 #define TRC_TO_CONSOLE 1
67 * Debugging levels can be set using debug insmod variable
68 * They can also be compiled out completely.
71 #define DBG_INIT (dgap_debug & 0x01)
72 #define DBG_BASIC (dgap_debug & 0x02)
73 #define DBG_CORE (dgap_debug & 0x04)
75 #define DBG_OPEN (dgap_debug & 0x08)
76 #define DBG_CLOSE (dgap_debug & 0x10)
77 #define DBG_READ (dgap_debug & 0x20)
78 #define DBG_WRITE (dgap_debug & 0x40)
80 #define DBG_IOCTL (dgap_debug & 0x80)
82 #define DBG_PROC (dgap_debug & 0x100)
83 #define DBG_PARAM (dgap_debug & 0x200)
84 #define DBG_PSCAN (dgap_debug & 0x400)
85 #define DBG_EVENT (dgap_debug & 0x800)
87 #define DBG_DRAIN (dgap_debug & 0x1000)
88 #define DBG_CARR (dgap_debug & 0x2000)
90 #define DBG_MGMT (dgap_debug & 0x4000)
93 #if defined(DGAP_TRACER)
95 # if defined(TRC_TO_KMEM)
97 # define TRC_ON_OVERFLOW_WRAP_AROUND
98 # undef TRC_ON_OVERFLOW_SHIFT_BUFFER
101 # define TRC_MAXMSG 1024
102 # define TRC_OVERFLOW "(OVERFLOW)"
103 # define TRC_DTRC "/usr/bin/dtrc"
105 #if defined TRC_TO_CONSOLE
106 #define PRINTF_TO_CONSOLE(args) { printk(DRVSTR": "); printk args; }
107 #else //!defined TRACE_TO_CONSOLE
108 #define PRINTF_TO_CONSOLE(args)
111 #if defined TRC_TO_KMEM
112 #define PRINTF_TO_KMEM(args) dgap_tracef args
113 #else //!defined TRC_TO_KMEM
114 #define PRINTF_TO_KMEM(args)
117 #define TRC(args) { PRINTF_TO_KMEM(args); PRINTF_TO_CONSOLE(args) }
119 # define DPR_INIT(ARGS) if (DBG_INIT) TRC(ARGS)
120 # define DPR_BASIC(ARGS) if (DBG_BASIC) TRC(ARGS)
121 # define DPR_CORE(ARGS) if (DBG_CORE) TRC(ARGS)
122 # define DPR_OPEN(ARGS) if (DBG_OPEN) TRC(ARGS)
123 # define DPR_CLOSE(ARGS) if (DBG_CLOSE) TRC(ARGS)
124 # define DPR_READ(ARGS) if (DBG_READ) TRC(ARGS)
125 # define DPR_WRITE(ARGS) if (DBG_WRITE) TRC(ARGS)
126 # define DPR_IOCTL(ARGS) if (DBG_IOCTL) TRC(ARGS)
127 # define DPR_PROC(ARGS) if (DBG_PROC) TRC(ARGS)
128 # define DPR_PARAM(ARGS) if (DBG_PARAM) TRC(ARGS)
129 # define DPR_PSCAN(ARGS) if (DBG_PSCAN) TRC(ARGS)
130 # define DPR_EVENT(ARGS) if (DBG_EVENT) TRC(ARGS)
131 # define DPR_DRAIN(ARGS) if (DBG_DRAIN) TRC(ARGS)
132 # define DPR_CARR(ARGS) if (DBG_CARR) TRC(ARGS)
133 # define DPR_MGMT(ARGS) if (DBG_MGMT) TRC(ARGS)
135 # define DPR(ARGS) if (dgap_debug) TRC(ARGS)
136 # define P(X) dgap_tracef(#X "=%p\n", X)
137 # define X(X) dgap_tracef(#X "=%x\n", X)
139 #else//!defined DGAP_TRACER
141 #define PRINTF_TO_KMEM(args)
143 # define DPR_INIT(ARGS)
144 # define DPR_BASIC(ARGS)
145 # define DPR_CORE(ARGS)
146 # define DPR_OPEN(ARGS)
147 # define DPR_CLOSE(ARGS)
148 # define DPR_READ(ARGS)
149 # define DPR_WRITE(ARGS)
150 # define DPR_IOCTL(ARGS)
151 # define DPR_PROC(ARGS)
152 # define DPR_PARAM(ARGS)
153 # define DPR_PSCAN(ARGS)
154 # define DPR_EVENT(ARGS)
155 # define DPR_DRAIN(ARGS)
156 # define DPR_CARR(ARGS)
157 # define DPR_MGMT(ARGS)
163 /* Number of boards we support at once. */
166 #define MAXTTYNAMELEN 200
168 /* Our 3 magic numbers for our board, channel and unit structs */
169 #define DGAP_BOARD_MAGIC 0x5c6df104
170 #define DGAP_CHANNEL_MAGIC 0x6c6df104
171 #define DGAP_UNIT_MAGIC 0x7c6df104
173 /* Serial port types */
174 #define DGAP_SERIAL 0
177 #define SERIAL_TYPE_NORMAL 1
179 /* 4 extra for alignment play space */
180 #define WRITEBUFLEN ((4096) + 4)
181 #define MYFLIPLEN N_TTY_BUF_SIZE
183 #define SBREAK_TIME 0x25
184 #define U2BSIZE 0x400
186 #define dgap_jiffies_from_ms(a) (((a) * HZ) / 1000)
189 * Our major for the mgmt devices.
191 * We can use 22, because Digi was allocated 22 and 23 for the epca driver.
192 * 22 has now become obsolete now that the "cu" devices have
193 * been removed from 2.6.
194 * Also, this *IS* the epca driver, just PCI only now.
196 #ifndef DIGI_DGAP_MAJOR
197 # define DIGI_DGAP_MAJOR 22
201 * The parameters we use to define the periods of the moving averages.
203 #define MA_PERIOD (HZ / 10)
204 #define SMA_DUR (1 * HZ)
205 #define EMA_DUR (1 * HZ)
206 #define SMA_NPERIODS (SMA_DUR / MA_PERIOD)
207 #define EMA_NPERIODS (EMA_DUR / MA_PERIOD)
210 * Define a local default termios struct. All ports will be created
211 * with this termios initially. This is the same structure that is defined
212 * as the default in tty_io.c with the same settings overriden as in serial.c
214 * In short, this should match the internal serial ports' defaults.
216 #define DEFAULT_IFLAGS (ICRNL | IXON)
217 #define DEFAULT_OFLAGS (OPOST | ONLCR)
218 #define DEFAULT_CFLAGS (B9600 | CS8 | CREAD | HUPCL | CLOCAL)
219 #define DEFAULT_LFLAGS (ISIG | ICANON | ECHO | ECHOE | ECHOK | \
220 ECHOCTL | ECHOKE | IEXTEN)
222 #ifndef _POSIX_VDISABLE
223 #define _POSIX_VDISABLE '\0'
226 #define SNIFF_MAX 65536 /* Sniff buffer size (2^n) */
227 #define SNIFF_MASK (SNIFF_MAX - 1) /* Sniff wrap mask */
229 #define VPDSIZE (512)
232 * Lock function/defines.
233 * Makes spotting lock/unlock locations easier.
235 # define DGAP_SPINLOCK_INIT(x) spin_lock_init(&(x))
236 # define DGAP_LOCK(x,y) spin_lock_irqsave(&(x), y)
237 # define DGAP_UNLOCK(x,y) spin_unlock_irqrestore(&(x), y)
238 # define DGAP_TRYLOCK(x,y) spin_trylock(&(x))
241 * All the possible states the driver can be while being loaded.
244 DRIVER_INITIALIZED = 0,
245 DRIVER_NEED_CONFIG_LOAD,
246 DRIVER_REQUESTED_CONFIG,
251 * All the possible states the board can be while booting up.
261 NEED_DEVICE_CREATION,
262 REQUESTED_DEVICE_CREATION,
263 FINISHED_DEVICE_CREATION,
273 FINISHED_PROC_CREATION,
278 * All the possible states that a requested concentrator image can be in.
281 NO_PENDING_CONCENTRATOR_REQUESTS = 0,
283 REQUESTED_CONCENTRATOR
286 extern char *dgap_state_text[];
287 extern char *dgap_driver_state_text[];
291 * Modem line constants are defined as macros because DSR and
292 * DCD are swapable using the ditty altpin option.
294 #define D_CD(ch) ch->ch_cd /* Carrier detect */
295 #define D_DSR(ch) ch->ch_dsr /* Data set ready */
296 #define D_RTS(ch) DM_RTS /* Request to send */
297 #define D_CTS(ch) DM_CTS /* Clear to send */
298 #define D_RI(ch) DM_RI /* Ring indicator */
299 #define D_DTR(ch) DM_DTR /* Data terminal ready */
302 /*************************************************************************
304 * Structures and closely related defines.
306 *************************************************************************/
310 * A structure to hold a statistics counter. We also
311 * compute moving averages for this counter.
315 u32 cnt; /* Total count */
316 ulong accum; /* Acuumulator per period */
317 ulong sma; /* Simple moving average */
318 ulong ema; /* Exponential moving average */
322 /************************************************************************
323 * Device flag definitions for bd_flags.
324 ************************************************************************/
325 #define BD_FEP5PLUS 0x0001 /* Supports FEP5 Plus commands */
326 #define BD_HAS_VPD 0x0002 /* Board has VPD info available */
330 * Per-board information
334 int magic; /* Board Magic number. */
335 int boardnum; /* Board number: 0-3 */
336 int firstminor; /* First minor, e.g. 0, 30, 60 */
338 int type; /* Type of board */
339 char *name; /* Product Name */
340 struct pci_dev *pdev; /* Pointer to the pci_dev struct */
341 u16 vendor; /* PCI vendor ID */
342 u16 device; /* PCI device ID */
343 u16 subvendor; /* PCI subsystem vendor ID */
344 u16 subdevice; /* PCI subsystem device ID */
345 uchar rev; /* PCI revision ID */
346 uint pci_bus; /* PCI bus value */
347 uint pci_slot; /* PCI slot value */
348 u16 maxports; /* MAX ports this board can handle */
349 uchar vpd[VPDSIZE]; /* VPD of board, if found */
350 u32 bd_flags; /* Board flags */
352 spinlock_t bd_lock; /* Used to protect board */
354 u32 state; /* State of card. */
355 wait_queue_head_t state_wait; /* Place to sleep on for state change */
357 struct tasklet_struct helper_tasklet; /* Poll helper tasklet */
362 struct cnode * bd_config; /* Config of board */
364 u16 nasync; /* Number of ports on card */
366 u32 use_interrupts; /* Should we be interrupt driven? */
367 ulong irq; /* Interrupt request number */
368 ulong intr_count; /* Count of interrupts */
369 u32 intr_used; /* Non-zero if using interrupts */
370 u32 intr_running; /* Non-zero if FEP knows its doing interrupts */
372 ulong port; /* Start of base io port of the card */
373 ulong port_end; /* End of base io port of the card */
374 ulong membase; /* Start of base memory of the card */
375 ulong membase_end; /* End of base memory of the card */
377 uchar *re_map_port; /* Remapped io port of the card */
378 uchar *re_map_membase;/* Remapped memory of the card */
380 uchar runwait; /* # Processes waiting for FEP */
381 uchar inhibit_poller; /* Tells the poller to leave us alone */
383 struct channel_t *channels[MAXPORTS]; /* array of pointers to our channels. */
385 struct tty_driver *SerialDriver;
386 char SerialName[200];
387 struct tty_driver *PrintDriver;
390 u32 dgap_Major_Serial_Registered;
391 u32 dgap_Major_TransparentPrint_Registered;
393 u32 dgap_Serial_Major;
394 u32 dgap_TransparentPrint_Major;
396 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
400 struct bs_t *bd_bs; /* Base structure pointer */
402 char *flipbuf; /* Our flip buffer, alloced if board is found */
403 char *flipflagbuf; /* Our flip flag buffer, alloced if board is found */
405 u16 dpatype; /* The board "type", as defined by DPA */
406 u16 dpastatus; /* The board "status", as defined by DPA */
407 wait_queue_head_t kme_wait; /* Needed for DPA support */
409 u32 conc_dl_status; /* Status of any pending conc download */
419 /************************************************************************
420 * Unit flag definitions for un_flags.
421 ************************************************************************/
422 #define UN_ISOPEN 0x0001 /* Device is open */
423 #define UN_CLOSING 0x0002 /* Line is being closed */
424 #define UN_IMM 0x0004 /* Service immediately */
425 #define UN_BUSY 0x0008 /* Some work this channel */
426 #define UN_BREAKI 0x0010 /* Input break received */
427 #define UN_PWAIT 0x0020 /* Printer waiting for terminal */
428 #define UN_TIME 0x0040 /* Waiting on time */
429 #define UN_EMPTY 0x0080 /* Waiting output queue empty */
430 #define UN_LOW 0x0100 /* Waiting output low water mark*/
431 #define UN_EXCL_OPEN 0x0200 /* Open for exclusive use */
432 #define UN_WOPEN 0x0400 /* Device waiting for open */
433 #define UN_WIOCTL 0x0800 /* Device waiting for open */
434 #define UN_HANGUP 0x8000 /* Carrier lost */
438 /************************************************************************
439 * Structure for terminal or printer unit.
440 ************************************************************************/
442 int magic; /* Unit Magic Number. */
443 struct channel_t *un_ch;
446 u32 un_open_count; /* Counter of opens to port */
447 struct tty_struct *un_tty;/* Pointer to unit tty structure */
448 u32 un_flags; /* Unit flags */
449 wait_queue_head_t un_flags_wait; /* Place to sleep to wait on unit */
450 u32 un_dev; /* Minor device number */
451 tcflag_t un_oflag; /* oflags being done on board */
452 tcflag_t un_lflag; /* lflags being done on board */
453 struct device *un_sysfs;
457 /************************************************************************
458 * Device flag definitions for ch_flags.
459 ************************************************************************/
460 #define CH_PRON 0x0001 /* Printer on string */
461 #define CH_OUT 0x0002 /* Dial-out device open */
462 #define CH_STOP 0x0004 /* Output is stopped */
463 #define CH_STOPI 0x0008 /* Input is stopped */
464 #define CH_CD 0x0010 /* Carrier is present */
465 #define CH_FCAR 0x0020 /* Carrier forced on */
467 #define CH_RXBLOCK 0x0080 /* Enable rx blocked flag */
468 #define CH_WLOW 0x0100 /* Term waiting low event */
469 #define CH_WEMPTY 0x0200 /* Term waiting empty event */
470 #define CH_RENABLE 0x0400 /* Buffer just emptied */
471 #define CH_RACTIVE 0x0800 /* Process active in xxread() */
472 #define CH_RWAIT 0x1000 /* Process waiting in xxread() */
473 #define CH_BAUD0 0x2000 /* Used for checking B0 transitions */
474 #define CH_HANGUP 0x8000 /* Hangup received */
477 * Definitions for ch_sniff_flags
479 #define SNIFF_OPEN 0x1
480 #define SNIFF_WAIT_DATA 0x2
481 #define SNIFF_WAIT_SPACE 0x4
484 /************************************************************************
485 * Channel information structure.
486 ************************************************************************/
488 int magic; /* Channel Magic Number */
489 struct bs_t *ch_bs; /* Base structure pointer */
490 struct cm_t *ch_cm; /* Command queue pointer */
491 struct board_t *ch_bd; /* Board structure pointer */
492 unsigned char *ch_vaddr; /* FEP memory origin */
493 unsigned char *ch_taddr; /* Write buffer origin */
494 unsigned char *ch_raddr; /* Read buffer origin */
495 struct digi_t ch_digi; /* Transparent Print structure */
496 struct un_t ch_tun; /* Terminal unit info */
497 struct un_t ch_pun; /* Printer unit info */
499 spinlock_t ch_lock; /* provide for serialization */
500 wait_queue_head_t ch_flags_wait;
503 uchar pscan_savechar;
505 u32 ch_portnum; /* Port number, 0 offset. */
506 u32 ch_open_count; /* open count */
507 u32 ch_flags; /* Channel flags */
510 u32 ch_close_delay; /* How long we should drop RTS/DTR for */
512 u32 ch_cpstime; /* Time for CPS calculations */
514 tcflag_t ch_c_iflag; /* channel iflags */
515 tcflag_t ch_c_cflag; /* channel cflags */
516 tcflag_t ch_c_oflag; /* channel oflags */
517 tcflag_t ch_c_lflag; /* channel lflags */
519 u16 ch_fepiflag; /* FEP tty iflags */
520 u16 ch_fepcflag; /* FEP tty cflags */
521 u16 ch_fepoflag; /* FEP tty oflags */
522 u16 ch_wopen; /* Waiting for open process cnt */
523 u16 ch_tstart; /* Transmit buffer start */
524 u16 ch_tsize; /* Transmit buffer size */
525 u16 ch_rstart; /* Receive buffer start */
526 u16 ch_rsize; /* Receive buffer size */
527 u16 ch_rdelay; /* Receive delay time */
529 u16 ch_tlw; /* Our currently set low water mark */
531 u16 ch_cook; /* Output character mask */
533 uchar ch_card; /* Card channel is on */
534 uchar ch_stopc; /* Stop character */
535 uchar ch_startc; /* Start character */
537 uchar ch_mostat; /* FEP output modem status */
538 uchar ch_mistat; /* FEP input modem status */
539 uchar ch_mforce; /* Modem values to be forced */
540 uchar ch_mval; /* Force values */
541 uchar ch_fepstopc; /* FEP stop character */
542 uchar ch_fepstartc; /* FEP start character */
544 uchar ch_astopc; /* Auxiliary Stop character */
545 uchar ch_astartc; /* Auxiliary Start character */
546 uchar ch_fepastopc; /* Auxiliary FEP stop char */
547 uchar ch_fepastartc; /* Auxiliary FEP start char */
549 uchar ch_hflow; /* FEP hardware handshake */
550 uchar ch_dsr; /* stores real dsr value */
551 uchar ch_cd; /* stores real cd value */
552 uchar ch_tx_win; /* channel tx buffer window */
553 uchar ch_rx_win; /* channel rx buffer window */
554 uint ch_custom_speed; /* Custom baud, if set */
555 uint ch_baud_info; /* Current baud info for /proc output */
556 ulong ch_rxcount; /* total of data received so far */
557 ulong ch_txcount; /* total of data transmitted so far */
558 ulong ch_err_parity; /* Count of parity errors on channel */
559 ulong ch_err_frame; /* Count of framing errors on channel */
560 ulong ch_err_break; /* Count of breaks on channel */
561 ulong ch_err_overrun; /* Count of overruns on channel */
565 char *ch_sniff_buf; /* Sniff buffer for proc */
566 ulong ch_sniff_flags; /* Channel flags */
567 wait_queue_head_t ch_sniff_wait;
571 /*************************************************************************
573 * Prototypes for non-static functions used in more than one module
575 *************************************************************************/
577 extern int dgap_ms_sleep(ulong ms);
578 extern void *dgap_driver_kzmalloc(size_t size, int priority);
579 extern char *dgap_ioctl_name(int cmd);
580 extern void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len);
581 extern void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len);
582 extern void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len);
583 extern void dgap_do_config_load(uchar __user *uaddr, int len);
584 extern int dgap_after_config_loaded(void);
585 extern int dgap_finalize_board_init(struct board_t *brd);
588 * Our Global Variables.
590 extern int dgap_driver_state; /* The state of the driver */
591 extern int dgap_debug; /* Debug variable */
592 extern int dgap_rawreadok; /* Set if user wants rawreads */
593 extern int dgap_poll_tick; /* Poll interval - 20 ms */
594 extern spinlock_t dgap_global_lock; /* Driver global spinlock */
595 extern uint dgap_NumBoards; /* Total number of boards */
596 extern struct board_t *dgap_Board[MAXBOARDS]; /* Array of board structs */
597 extern ulong dgap_poll_counter; /* Times the poller has run */
598 extern char *dgap_config_buf; /* The config file buffer */
599 extern spinlock_t dgap_dl_lock; /* Downloader spinlock */
600 extern wait_queue_head_t dgap_dl_wait; /* Wait queue for downloader */
601 extern int dgap_dl_action; /* Action flag for downloader */
602 extern int dgap_registerttyswithsysfs; /* Should we register the */
603 /* ttys with sysfs or not */
606 * Global functions declared in dgap_fep5.c, but must be hidden from
607 * user space programs.
609 extern void dgap_poll_tasklet(unsigned long data);
610 extern void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds);
611 extern void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds);
612 extern void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
613 extern int dgap_param(struct tty_struct *tty);
614 extern void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len);
615 extern uint dgap_get_custom_baud(struct channel_t *ch);
616 extern void dgap_firmware_reset_port(struct channel_t *ch);