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 __DGNC_DRIVER_H
28 #define __DGNC_DRIVER_H
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 */
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 */
39 /*************************************************************************
43 *************************************************************************/
46 * Driver identification, error and debugging statments
48 * In theory, you can change all occurrences of "digi" in the next
49 * three lines, and the driver printk's will all automagically change.
51 * APR((fmt, args, ...)); Always prints message
52 * DPR((fmt, args, ...)); Only prints if DGNC_TRACER is defined at
53 * compile time and dgnc_debug!=0
55 #define PROCSTR "dgnc" /* /proc entries */
56 #define DEVSTR "/dev/dg/dgnc" /* /dev entries */
57 #define DRVSTR "dgnc" /* Driver name string
59 #define APR(args) do { PRINTF_TO_KMEM(args); printk(DRVSTR": "); printk args; \
61 #define RAPR(args) do { PRINTF_TO_KMEM(args); printk args; } while (0)
63 #define TRC_TO_CONSOLE 1
66 * Debugging levels can be set using debug insmod variable
67 * They can also be compiled out completely.
70 #define DBG_INIT (dgnc_debug & 0x01)
71 #define DBG_BASIC (dgnc_debug & 0x02)
72 #define DBG_CORE (dgnc_debug & 0x04)
74 #define DBG_OPEN (dgnc_debug & 0x08)
75 #define DBG_CLOSE (dgnc_debug & 0x10)
76 #define DBG_READ (dgnc_debug & 0x20)
77 #define DBG_WRITE (dgnc_debug & 0x40)
79 #define DBG_IOCTL (dgnc_debug & 0x80)
81 #define DBG_PROC (dgnc_debug & 0x100)
82 #define DBG_PARAM (dgnc_debug & 0x200)
83 #define DBG_PSCAN (dgnc_debug & 0x400)
84 #define DBG_EVENT (dgnc_debug & 0x800)
86 #define DBG_DRAIN (dgnc_debug & 0x1000)
87 #define DBG_MSIGS (dgnc_debug & 0x2000)
89 #define DBG_MGMT (dgnc_debug & 0x4000)
90 #define DBG_INTR (dgnc_debug & 0x8000)
92 #define DBG_CARR (dgnc_debug & 0x10000)
95 #if defined(DGNC_TRACER)
97 # if defined(TRC_TO_KMEM)
99 # define TRC_ON_OVERFLOW_WRAP_AROUND
100 # undef TRC_ON_OVERFLOW_SHIFT_BUFFER
101 # endif //TRC_TO_KMEM
103 # define TRC_MAXMSG 1024
104 # define TRC_OVERFLOW "(OVERFLOW)"
105 # define TRC_DTRC "/usr/bin/dtrc"
107 #if defined TRC_TO_CONSOLE
108 #define PRINTF_TO_CONSOLE(args) { printk(DRVSTR": "); printk args; }
109 #else //!defined TRACE_TO_CONSOLE
110 #define PRINTF_TO_CONSOLE(args)
113 #if defined TRC_TO_KMEM
114 #define PRINTF_TO_KMEM(args) dgnc_tracef args
115 #else //!defined TRC_TO_KMEM
116 #define PRINTF_TO_KMEM(args)
119 #define TRC(args) { PRINTF_TO_KMEM(args); PRINTF_TO_CONSOLE(args) }
121 # define DPR_INIT(ARGS) if (DBG_INIT) TRC(ARGS)
122 # define DPR_BASIC(ARGS) if (DBG_BASIC) TRC(ARGS)
123 # define DPR_CORE(ARGS) if (DBG_CORE) TRC(ARGS)
124 # define DPR_OPEN(ARGS) if (DBG_OPEN) TRC(ARGS)
125 # define DPR_CLOSE(ARGS) if (DBG_CLOSE) TRC(ARGS)
126 # define DPR_READ(ARGS) if (DBG_READ) TRC(ARGS)
127 # define DPR_WRITE(ARGS) if (DBG_WRITE) TRC(ARGS)
128 # define DPR_IOCTL(ARGS) if (DBG_IOCTL) TRC(ARGS)
129 # define DPR_PROC(ARGS) if (DBG_PROC) TRC(ARGS)
130 # define DPR_PARAM(ARGS) if (DBG_PARAM) TRC(ARGS)
131 # define DPR_PSCAN(ARGS) if (DBG_PSCAN) TRC(ARGS)
132 # define DPR_EVENT(ARGS) if (DBG_EVENT) TRC(ARGS)
133 # define DPR_DRAIN(ARGS) if (DBG_DRAIN) TRC(ARGS)
134 # define DPR_CARR(ARGS) if (DBG_CARR) TRC(ARGS)
135 # define DPR_MGMT(ARGS) if (DBG_MGMT) TRC(ARGS)
136 # define DPR_INTR(ARGS) if (DBG_INTR) TRC(ARGS)
137 # define DPR_MSIGS(ARGS) if (DBG_MSIGS) TRC(ARGS)
139 # define DPR(ARGS) if (dgnc_debug) TRC(ARGS)
140 # define P(X) dgnc_tracef(#X "=%p\n", X)
141 # define X(X) dgnc_tracef(#X "=%x\n", X)
143 #else//!defined DGNC_TRACER
145 #define PRINTF_TO_KMEM(args)
147 # define DPR_INIT(ARGS)
148 # define DPR_BASIC(ARGS)
149 # define DPR_CORE(ARGS)
150 # define DPR_OPEN(ARGS)
151 # define DPR_CLOSE(ARGS)
152 # define DPR_READ(ARGS)
153 # define DPR_WRITE(ARGS)
154 # define DPR_IOCTL(ARGS)
155 # define DPR_PROC(ARGS)
156 # define DPR_PARAM(ARGS)
157 # define DPR_PSCAN(ARGS)
158 # define DPR_EVENT(ARGS)
159 # define DPR_DRAIN(ARGS)
160 # define DPR_CARR(ARGS)
161 # define DPR_MGMT(ARGS)
162 # define DPR_INTR(ARGS)
163 # define DPR_MSIGS(ARGS)
169 /* Number of boards we support at once. */
172 #define MAXTTYNAMELEN 200
174 /* Our 3 magic numbers for our board, channel and unit structs */
175 #define DGNC_BOARD_MAGIC 0x5c6df104
176 #define DGNC_CHANNEL_MAGIC 0x6c6df104
177 #define DGNC_UNIT_MAGIC 0x7c6df104
179 /* Serial port types */
180 #define DGNC_SERIAL 0
183 #define SERIAL_TYPE_NORMAL 1
185 #define PORT_NUM(dev) ((dev) & 0x7f)
186 #define IS_PRINT(dev) (((dev) & 0xff) >= 0x80)
188 /* MAX number of stop characters we will send when our read queue is getting full */
189 #define MAX_STOPS_SENT 5
191 /* 4 extra for alignment play space */
192 #define WRITEBUFLEN ((4096) + 4)
193 #define MYFLIPLEN N_TTY_BUF_SIZE
195 #define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
198 * Define a local default termios struct. All ports will be created
199 * with this termios initially. This is the same structure that is defined
200 * as the default in tty_io.c with the same settings overriden as in serial.c
202 * In short, this should match the internal serial ports' defaults.
204 #define DEFAULT_IFLAGS (ICRNL | IXON)
205 #define DEFAULT_OFLAGS (OPOST | ONLCR)
206 #define DEFAULT_CFLAGS (B9600 | CS8 | CREAD | HUPCL | CLOCAL)
207 #define DEFAULT_LFLAGS (ISIG | ICANON | ECHO | ECHOE | ECHOK | \
208 ECHOCTL | ECHOKE | IEXTEN)
210 #ifndef _POSIX_VDISABLE
211 #define _POSIX_VDISABLE '\0'
214 #define SNIFF_MAX 65536 /* Sniff buffer size (2^n) */
215 #define SNIFF_MASK (SNIFF_MAX - 1) /* Sniff wrap mask */
218 * Lock function/defines.
219 * Makes spotting lock/unlock locations easier.
221 # define DGNC_SPINLOCK_INIT(x) spin_lock_init(&(x))
222 # define DGNC_LOCK(x,y) spin_lock_irqsave(&(x), y)
223 # define DGNC_UNLOCK(x,y) spin_unlock_irqrestore(&(x), y)
226 * All the possible states the driver can be while being loaded.
229 DRIVER_INITIALIZED = 0,
234 * All the possible states the board can be while booting up.
243 /*************************************************************************
245 * Structures and closely related defines.
247 *************************************************************************/
252 /************************************************************************
253 * Per board operations structure *
254 ************************************************************************/
256 void (*tasklet) (unsigned long data);
257 irqreturn_t (*intr) (int irq, void *voidbrd);
258 void (*uart_init) (struct channel_t *ch);
259 void (*uart_off) (struct channel_t *ch);
260 int (*drain) (struct tty_struct *tty, uint seconds);
261 void (*param) (struct tty_struct *tty);
262 void (*vpd) (struct dgnc_board *brd);
263 void (*assert_modem_signals) (struct channel_t *ch);
264 void (*flush_uart_write) (struct channel_t *ch);
265 void (*flush_uart_read) (struct channel_t *ch);
266 void (*disable_receiver) (struct channel_t *ch);
267 void (*enable_receiver) (struct channel_t *ch);
268 void (*send_break) (struct channel_t *ch, int);
269 void (*send_start_character) (struct channel_t *ch);
270 void (*send_stop_character) (struct channel_t *ch);
271 void (*copy_data_from_queue_to_uart) (struct channel_t *ch);
272 uint (*get_uart_bytes_left) (struct channel_t *ch);
273 void (*send_immediate_char) (struct channel_t *ch, unsigned char);
276 /************************************************************************
277 * Device flag definitions for bd_flags.
278 ************************************************************************/
279 #define BD_IS_PCI_EXPRESS 0x0001 /* Is a PCI Express board */
283 * Per-board information
286 int magic; /* Board Magic number. */
287 int boardnum; /* Board number: 0-32 */
289 int type; /* Type of board */
290 char *name; /* Product Name */
291 struct pci_dev *pdev; /* Pointer to the pci_dev struct */
292 unsigned long bd_flags; /* Board flags */
293 u16 vendor; /* PCI vendor ID */
294 u16 device; /* PCI device ID */
295 u16 subvendor; /* PCI subsystem vendor ID */
296 u16 subdevice; /* PCI subsystem device ID */
297 uchar rev; /* PCI revision ID */
298 uint pci_bus; /* PCI bus value */
299 uint pci_slot; /* PCI slot value */
300 uint maxports; /* MAX ports this board can handle */
301 uchar dvid; /* Board specific device id */
302 uchar vpd[128]; /* VPD of board, if found */
303 uchar serial_num[20]; /* Serial number of board, if found in VPD */
305 spinlock_t bd_lock; /* Used to protect board */
307 spinlock_t bd_intr_lock; /* Used to protect the poller tasklet and
308 * the interrupt routine from each other.
311 uint state; /* State of card. */
312 wait_queue_head_t state_wait; /* Place to sleep on for state change */
314 struct tasklet_struct helper_tasklet; /* Poll helper tasklet */
316 uint nasync; /* Number of ports on card */
318 uint irq; /* Interrupt request number */
319 ulong intr_count; /* Count of interrupts */
320 ulong intr_modem; /* Count of interrupts */
321 ulong intr_tx; /* Count of interrupts */
322 ulong intr_rx; /* Count of interrupts */
324 ulong membase; /* Start of base memory of the card */
325 ulong membase_end; /* End of base memory of the card */
327 u8 __iomem *re_map_membase;/* Remapped memory of the card */
329 ulong iobase; /* Start of io base of the card */
330 ulong iobase_end; /* End of io base of the card */
332 uint bd_uart_offset; /* Space between each UART */
334 struct channel_t *channels[MAXPORTS]; /* array of pointers to our channels. */
336 struct tty_driver SerialDriver;
337 char SerialName[200];
338 struct tty_driver PrintDriver;
341 uint dgnc_Major_Serial_Registered;
342 uint dgnc_Major_TransparentPrint_Registered;
344 uint dgnc_Serial_Major;
345 uint dgnc_TransparentPrint_Major;
349 char *flipbuf; /* Our flip buffer, alloced if board is found */
351 u16 dpatype; /* The board "type", as defined by DPA */
352 u16 dpastatus; /* The board "status", as defined by DPA */
360 uint bd_dividend; /* Board/UARTs specific dividend */
362 struct board_ops *bd_ops;
364 /* /proc/<board> entries */
365 struct proc_dir_entry *proc_entry_pointer;
366 struct dgnc_proc_entry *dgnc_board_table;
371 /************************************************************************
372 * Unit flag definitions for un_flags.
373 ************************************************************************/
374 #define UN_ISOPEN 0x0001 /* Device is open */
375 #define UN_CLOSING 0x0002 /* Line is being closed */
376 #define UN_IMM 0x0004 /* Service immediately */
377 #define UN_BUSY 0x0008 /* Some work this channel */
378 #define UN_BREAKI 0x0010 /* Input break received */
379 #define UN_PWAIT 0x0020 /* Printer waiting for terminal */
380 #define UN_TIME 0x0040 /* Waiting on time */
381 #define UN_EMPTY 0x0080 /* Waiting output queue empty */
382 #define UN_LOW 0x0100 /* Waiting output low water mark*/
383 #define UN_EXCL_OPEN 0x0200 /* Open for exclusive use */
384 #define UN_WOPEN 0x0400 /* Device waiting for open */
385 #define UN_WIOCTL 0x0800 /* Device waiting for open */
386 #define UN_HANGUP 0x8000 /* Carrier lost */
390 /************************************************************************
391 * Structure for terminal or printer unit.
392 ************************************************************************/
394 int magic; /* Unit Magic Number. */
395 struct channel_t *un_ch;
398 uint un_open_count; /* Counter of opens to port */
399 struct tty_struct *un_tty;/* Pointer to unit tty structure */
400 uint un_flags; /* Unit flags */
401 wait_queue_head_t un_flags_wait; /* Place to sleep to wait on unit */
402 uint un_dev; /* Minor device number */
403 struct device *un_sysfs;
407 /************************************************************************
408 * Device flag definitions for ch_flags.
409 ************************************************************************/
410 #define CH_PRON 0x0001 /* Printer on string */
411 #define CH_STOP 0x0002 /* Output is stopped */
412 #define CH_STOPI 0x0004 /* Input is stopped */
413 #define CH_CD 0x0008 /* Carrier is present */
414 #define CH_FCAR 0x0010 /* Carrier forced on */
415 #define CH_HANGUP 0x0020 /* Hangup received */
417 #define CH_RECEIVER_OFF 0x0040 /* Receiver is off */
418 #define CH_OPENING 0x0080 /* Port in fragile open state */
419 #define CH_CLOSING 0x0100 /* Port in fragile close state */
420 #define CH_FIFO_ENABLED 0x0200 /* Port has FIFOs enabled */
421 #define CH_TX_FIFO_EMPTY 0x0400 /* TX Fifo is completely empty */
422 #define CH_TX_FIFO_LWM 0x0800 /* TX Fifo is below Low Water */
423 #define CH_BREAK_SENDING 0x1000 /* Break is being sent */
424 #define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */
425 #define CH_FLIPBUF_IN_USE 0x4000 /* Channel's flipbuf is in use */
426 #define CH_BAUD0 0x08000 /* Used for checking B0 transitions */
427 #define CH_FORCED_STOP 0x20000 /* Output is forcibly stopped */
428 #define CH_FORCED_STOPI 0x40000 /* Input is forcibly stopped */
431 * Definitions for ch_sniff_flags
433 #define SNIFF_OPEN 0x1
434 #define SNIFF_WAIT_DATA 0x2
435 #define SNIFF_WAIT_SPACE 0x4
438 /* Our Read/Error/Write queue sizes */
439 #define RQUEUEMASK 0x1FFF /* 8 K - 1 */
440 #define EQUEUEMASK 0x1FFF /* 8 K - 1 */
441 #define WQUEUEMASK 0x0FFF /* 4 K - 1 */
442 #define RQUEUESIZE (RQUEUEMASK + 1)
443 #define EQUEUESIZE RQUEUESIZE
444 #define WQUEUESIZE (WQUEUEMASK + 1)
447 /************************************************************************
448 * Channel information structure.
449 ************************************************************************/
451 int magic; /* Channel Magic Number */
452 struct dgnc_board *ch_bd; /* Board structure pointer */
453 struct digi_t ch_digi; /* Transparent Print structure */
454 struct un_t ch_tun; /* Terminal unit info */
455 struct un_t ch_pun; /* Printer unit info */
457 spinlock_t ch_lock; /* provide for serialization */
458 wait_queue_head_t ch_flags_wait;
460 uint ch_portnum; /* Port number, 0 offset. */
461 uint ch_open_count; /* open count */
462 uint ch_flags; /* Channel flags */
464 ulong ch_close_delay; /* How long we should drop RTS/DTR for */
466 ulong ch_cpstime; /* Time for CPS calculations */
468 tcflag_t ch_c_iflag; /* channel iflags */
469 tcflag_t ch_c_cflag; /* channel cflags */
470 tcflag_t ch_c_oflag; /* channel oflags */
471 tcflag_t ch_c_lflag; /* channel lflags */
472 uchar ch_stopc; /* Stop character */
473 uchar ch_startc; /* Start character */
475 uint ch_old_baud; /* Cache of the current baud */
476 uint ch_custom_speed;/* Custom baud, if set */
478 uint ch_wopen; /* Waiting for open process cnt */
480 uchar ch_mostat; /* FEP output modem status */
481 uchar ch_mistat; /* FEP input modem status */
483 struct neo_uart_struct __iomem *ch_neo_uart; /* Pointer to the "mapped" UART struct */
484 struct cls_uart_struct __iomem *ch_cls_uart; /* Pointer to the "mapped" UART struct */
486 uchar ch_cached_lsr; /* Cached value of the LSR register */
488 uchar *ch_rqueue; /* Our read queue buffer - malloc'ed */
489 ushort ch_r_head; /* Head location of the read queue */
490 ushort ch_r_tail; /* Tail location of the read queue */
492 uchar *ch_equeue; /* Our error queue buffer - malloc'ed */
493 ushort ch_e_head; /* Head location of the error queue */
494 ushort ch_e_tail; /* Tail location of the error queue */
496 uchar *ch_wqueue; /* Our write queue buffer - malloc'ed */
497 ushort ch_w_head; /* Head location of the write queue */
498 ushort ch_w_tail; /* Tail location of the write queue */
500 ulong ch_rxcount; /* total of data received so far */
501 ulong ch_txcount; /* total of data transmitted so far */
503 uchar ch_r_tlevel; /* Receive Trigger level */
504 uchar ch_t_tlevel; /* Transmit Trigger level */
506 uchar ch_r_watermark; /* Receive Watermark */
508 ulong ch_stop_sending_break; /* Time we should STOP sending a break */
510 uint ch_stops_sent; /* How many times I have sent a stop character
511 * to try to stop the other guy sending.
513 ulong ch_err_parity; /* Count of parity errors on channel */
514 ulong ch_err_frame; /* Count of framing errors on channel */
515 ulong ch_err_break; /* Count of breaks on channel */
516 ulong ch_err_overrun; /* Count of overruns on channel */
518 ulong ch_xon_sends; /* Count of xons transmitted */
519 ulong ch_xoff_sends; /* Count of xoffs transmitted */
521 ulong ch_intr_modem; /* Count of interrupts */
522 ulong ch_intr_tx; /* Count of interrupts */
523 ulong ch_intr_rx; /* Count of interrupts */
526 /* /proc/<board>/<channel> entries */
527 struct proc_dir_entry *proc_entry_pointer;
528 struct dgnc_proc_entry *dgnc_channel_table;
532 char *ch_sniff_buf; /* Sniff buffer for proc */
533 ulong ch_sniff_flags; /* Channel flags */
534 wait_queue_head_t ch_sniff_wait;
538 /*************************************************************************
540 * Prototypes for non-static functions used in more than one module
542 *************************************************************************/
544 extern int dgnc_ms_sleep(ulong ms);
545 extern char *dgnc_ioctl_name(int cmd);
548 * Our Global Variables.
550 extern int dgnc_driver_state; /* The state of the driver */
551 extern uint dgnc_Major; /* Our driver/mgmt major */
552 extern int dgnc_debug; /* Debug variable */
553 extern int dgnc_rawreadok; /* Set if user wants rawreads */
554 extern int dgnc_poll_tick; /* Poll interval - 20 ms */
555 extern int dgnc_trcbuf_size; /* Size of the ringbuffer */
556 extern spinlock_t dgnc_global_lock; /* Driver global spinlock */
557 extern uint dgnc_NumBoards; /* Total number of boards */
558 extern struct dgnc_board *dgnc_Board[MAXBOARDS]; /* Array of board structs */
559 extern ulong dgnc_poll_counter; /* Times the poller has run */
560 extern char *dgnc_state_text[]; /* Array of state text */
561 extern char *dgnc_driver_state_text[];/* Array of driver state text */