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
53 #define PROCSTR "dgnc" /* /proc entries */
54 #define DEVSTR "/dev/dg/dgnc" /* /dev entries */
55 #define DRVSTR "dgnc" /* Driver name string
57 #define APR(args) do { printk(DRVSTR": "); printk args; \
59 #define RAPR(args) do { printk args; } while (0)
61 #define TRC_TO_CONSOLE 1
64 * Debugging levels can be set using debug insmod variable
65 * They can also be compiled out completely.
68 #define DBG_INIT (dgnc_debug & 0x01)
69 #define DBG_BASIC (dgnc_debug & 0x02)
70 #define DBG_CORE (dgnc_debug & 0x04)
72 #define DBG_OPEN (dgnc_debug & 0x08)
73 #define DBG_CLOSE (dgnc_debug & 0x10)
74 #define DBG_READ (dgnc_debug & 0x20)
75 #define DBG_WRITE (dgnc_debug & 0x40)
77 #define DBG_IOCTL (dgnc_debug & 0x80)
79 #define DBG_PROC (dgnc_debug & 0x100)
80 #define DBG_PARAM (dgnc_debug & 0x200)
81 #define DBG_PSCAN (dgnc_debug & 0x400)
82 #define DBG_EVENT (dgnc_debug & 0x800)
84 #define DBG_DRAIN (dgnc_debug & 0x1000)
85 #define DBG_MSIGS (dgnc_debug & 0x2000)
87 #define DBG_MGMT (dgnc_debug & 0x4000)
88 #define DBG_INTR (dgnc_debug & 0x8000)
90 #define DBG_CARR (dgnc_debug & 0x10000)
92 /* Number of boards we support at once. */
95 #define MAXTTYNAMELEN 200
97 /* Our 3 magic numbers for our board, channel and unit structs */
98 #define DGNC_BOARD_MAGIC 0x5c6df104
99 #define DGNC_CHANNEL_MAGIC 0x6c6df104
100 #define DGNC_UNIT_MAGIC 0x7c6df104
102 /* Serial port types */
103 #define DGNC_SERIAL 0
106 #define SERIAL_TYPE_NORMAL 1
108 #define PORT_NUM(dev) ((dev) & 0x7f)
109 #define IS_PRINT(dev) (((dev) & 0xff) >= 0x80)
111 /* MAX number of stop characters we will send when our read queue is getting full */
112 #define MAX_STOPS_SENT 5
114 /* 4 extra for alignment play space */
115 #define WRITEBUFLEN ((4096) + 4)
116 #define MYFLIPLEN N_TTY_BUF_SIZE
118 #define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
121 * Define a local default termios struct. All ports will be created
122 * with this termios initially. This is the same structure that is defined
123 * as the default in tty_io.c with the same settings overriden as in serial.c
125 * In short, this should match the internal serial ports' defaults.
127 #define DEFAULT_IFLAGS (ICRNL | IXON)
128 #define DEFAULT_OFLAGS (OPOST | ONLCR)
129 #define DEFAULT_CFLAGS (B9600 | CS8 | CREAD | HUPCL | CLOCAL)
130 #define DEFAULT_LFLAGS (ISIG | ICANON | ECHO | ECHOE | ECHOK | \
131 ECHOCTL | ECHOKE | IEXTEN)
133 #ifndef _POSIX_VDISABLE
134 #define _POSIX_VDISABLE '\0'
137 #define SNIFF_MAX 65536 /* Sniff buffer size (2^n) */
138 #define SNIFF_MASK (SNIFF_MAX - 1) /* Sniff wrap mask */
141 * All the possible states the driver can be while being loaded.
144 DRIVER_INITIALIZED = 0,
149 * All the possible states the board can be while booting up.
158 /*************************************************************************
160 * Structures and closely related defines.
162 *************************************************************************/
167 /************************************************************************
168 * Per board operations structure *
169 ************************************************************************/
171 void (*tasklet)(unsigned long data);
172 irqreturn_t (*intr)(int irq, void *voidbrd);
173 void (*uart_init)(struct channel_t *ch);
174 void (*uart_off)(struct channel_t *ch);
175 int (*drain)(struct tty_struct *tty, uint seconds);
176 void (*param)(struct tty_struct *tty);
177 void (*vpd)(struct dgnc_board *brd);
178 void (*assert_modem_signals)(struct channel_t *ch);
179 void (*flush_uart_write)(struct channel_t *ch);
180 void (*flush_uart_read)(struct channel_t *ch);
181 void (*disable_receiver)(struct channel_t *ch);
182 void (*enable_receiver)(struct channel_t *ch);
183 void (*send_break)(struct channel_t *ch, int);
184 void (*send_start_character)(struct channel_t *ch);
185 void (*send_stop_character)(struct channel_t *ch);
186 void (*copy_data_from_queue_to_uart)(struct channel_t *ch);
187 uint (*get_uart_bytes_left)(struct channel_t *ch);
188 void (*send_immediate_char)(struct channel_t *ch, unsigned char);
191 /************************************************************************
192 * Device flag definitions for bd_flags.
193 ************************************************************************/
194 #define BD_IS_PCI_EXPRESS 0x0001 /* Is a PCI Express board */
198 * Per-board information
201 int magic; /* Board Magic number. */
202 int boardnum; /* Board number: 0-32 */
204 int type; /* Type of board */
205 char *name; /* Product Name */
206 struct pci_dev *pdev; /* Pointer to the pci_dev struct */
207 unsigned long bd_flags; /* Board flags */
208 u16 vendor; /* PCI vendor ID */
209 u16 device; /* PCI device ID */
210 u16 subvendor; /* PCI subsystem vendor ID */
211 u16 subdevice; /* PCI subsystem device ID */
212 unsigned char rev; /* PCI revision ID */
213 uint pci_bus; /* PCI bus value */
214 uint pci_slot; /* PCI slot value */
215 uint maxports; /* MAX ports this board can handle */
216 unsigned char dvid; /* Board specific device id */
217 unsigned char vpd[128]; /* VPD of board, if found */
218 unsigned char serial_num[20]; /* Serial number of board, if found in VPD */
220 spinlock_t bd_lock; /* Used to protect board */
222 spinlock_t bd_intr_lock; /* Used to protect the poller tasklet and
223 * the interrupt routine from each other.
226 uint state; /* State of card. */
227 wait_queue_head_t state_wait; /* Place to sleep on for state change */
229 struct tasklet_struct helper_tasklet; /* Poll helper tasklet */
231 uint nasync; /* Number of ports on card */
233 uint irq; /* Interrupt request number */
234 ulong intr_count; /* Count of interrupts */
235 ulong intr_modem; /* Count of interrupts */
236 ulong intr_tx; /* Count of interrupts */
237 ulong intr_rx; /* Count of interrupts */
239 ulong membase; /* Start of base memory of the card */
240 ulong membase_end; /* End of base memory of the card */
242 u8 __iomem *re_map_membase;/* Remapped memory of the card */
244 ulong iobase; /* Start of io base of the card */
245 ulong iobase_end; /* End of io base of the card */
247 uint bd_uart_offset; /* Space between each UART */
249 struct channel_t *channels[MAXPORTS]; /* array of pointers to our channels. */
251 struct tty_driver SerialDriver;
252 char SerialName[200];
253 struct tty_driver PrintDriver;
256 uint dgnc_Major_Serial_Registered;
257 uint dgnc_Major_TransparentPrint_Registered;
259 uint dgnc_Serial_Major;
260 uint dgnc_TransparentPrint_Major;
264 char *flipbuf; /* Our flip buffer, alloced if board is found */
266 u16 dpatype; /* The board "type", as defined by DPA */
267 u16 dpastatus; /* The board "status", as defined by DPA */
275 uint bd_dividend; /* Board/UARTs specific dividend */
277 struct board_ops *bd_ops;
279 /* /proc/<board> entries */
280 struct proc_dir_entry *proc_entry_pointer;
281 struct dgnc_proc_entry *dgnc_board_table;
286 /************************************************************************
287 * Unit flag definitions for un_flags.
288 ************************************************************************/
289 #define UN_ISOPEN 0x0001 /* Device is open */
290 #define UN_CLOSING 0x0002 /* Line is being closed */
291 #define UN_IMM 0x0004 /* Service immediately */
292 #define UN_BUSY 0x0008 /* Some work this channel */
293 #define UN_BREAKI 0x0010 /* Input break received */
294 #define UN_PWAIT 0x0020 /* Printer waiting for terminal */
295 #define UN_TIME 0x0040 /* Waiting on time */
296 #define UN_EMPTY 0x0080 /* Waiting output queue empty */
297 #define UN_LOW 0x0100 /* Waiting output low water mark*/
298 #define UN_EXCL_OPEN 0x0200 /* Open for exclusive use */
299 #define UN_WOPEN 0x0400 /* Device waiting for open */
300 #define UN_WIOCTL 0x0800 /* Device waiting for open */
301 #define UN_HANGUP 0x8000 /* Carrier lost */
305 /************************************************************************
306 * Structure for terminal or printer unit.
307 ************************************************************************/
309 int magic; /* Unit Magic Number. */
310 struct channel_t *un_ch;
313 uint un_open_count; /* Counter of opens to port */
314 struct tty_struct *un_tty;/* Pointer to unit tty structure */
315 uint un_flags; /* Unit flags */
316 wait_queue_head_t un_flags_wait; /* Place to sleep to wait on unit */
317 uint un_dev; /* Minor device number */
318 struct device *un_sysfs;
322 /************************************************************************
323 * Device flag definitions for ch_flags.
324 ************************************************************************/
325 #define CH_PRON 0x0001 /* Printer on string */
326 #define CH_STOP 0x0002 /* Output is stopped */
327 #define CH_STOPI 0x0004 /* Input is stopped */
328 #define CH_CD 0x0008 /* Carrier is present */
329 #define CH_FCAR 0x0010 /* Carrier forced on */
330 #define CH_HANGUP 0x0020 /* Hangup received */
332 #define CH_RECEIVER_OFF 0x0040 /* Receiver is off */
333 #define CH_OPENING 0x0080 /* Port in fragile open state */
334 #define CH_CLOSING 0x0100 /* Port in fragile close state */
335 #define CH_FIFO_ENABLED 0x0200 /* Port has FIFOs enabled */
336 #define CH_TX_FIFO_EMPTY 0x0400 /* TX Fifo is completely empty */
337 #define CH_TX_FIFO_LWM 0x0800 /* TX Fifo is below Low Water */
338 #define CH_BREAK_SENDING 0x1000 /* Break is being sent */
339 #define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */
340 #define CH_FLIPBUF_IN_USE 0x4000 /* Channel's flipbuf is in use */
341 #define CH_BAUD0 0x08000 /* Used for checking B0 transitions */
342 #define CH_FORCED_STOP 0x20000 /* Output is forcibly stopped */
343 #define CH_FORCED_STOPI 0x40000 /* Input is forcibly stopped */
346 * Definitions for ch_sniff_flags
348 #define SNIFF_OPEN 0x1
349 #define SNIFF_WAIT_DATA 0x2
350 #define SNIFF_WAIT_SPACE 0x4
353 /* Our Read/Error/Write queue sizes */
354 #define RQUEUEMASK 0x1FFF /* 8 K - 1 */
355 #define EQUEUEMASK 0x1FFF /* 8 K - 1 */
356 #define WQUEUEMASK 0x0FFF /* 4 K - 1 */
357 #define RQUEUESIZE (RQUEUEMASK + 1)
358 #define EQUEUESIZE RQUEUESIZE
359 #define WQUEUESIZE (WQUEUEMASK + 1)
362 /************************************************************************
363 * Channel information structure.
364 ************************************************************************/
366 int magic; /* Channel Magic Number */
367 struct dgnc_board *ch_bd; /* Board structure pointer */
368 struct digi_t ch_digi; /* Transparent Print structure */
369 struct un_t ch_tun; /* Terminal unit info */
370 struct un_t ch_pun; /* Printer unit info */
372 spinlock_t ch_lock; /* provide for serialization */
373 wait_queue_head_t ch_flags_wait;
375 uint ch_portnum; /* Port number, 0 offset. */
376 uint ch_open_count; /* open count */
377 uint ch_flags; /* Channel flags */
379 ulong ch_close_delay; /* How long we should drop RTS/DTR for */
381 ulong ch_cpstime; /* Time for CPS calculations */
383 tcflag_t ch_c_iflag; /* channel iflags */
384 tcflag_t ch_c_cflag; /* channel cflags */
385 tcflag_t ch_c_oflag; /* channel oflags */
386 tcflag_t ch_c_lflag; /* channel lflags */
387 unsigned char ch_stopc; /* Stop character */
388 unsigned char ch_startc; /* Start character */
390 uint ch_old_baud; /* Cache of the current baud */
391 uint ch_custom_speed;/* Custom baud, if set */
393 uint ch_wopen; /* Waiting for open process cnt */
395 unsigned char ch_mostat; /* FEP output modem status */
396 unsigned char ch_mistat; /* FEP input modem status */
398 struct neo_uart_struct __iomem *ch_neo_uart; /* Pointer to the "mapped" UART struct */
399 struct cls_uart_struct __iomem *ch_cls_uart; /* Pointer to the "mapped" UART struct */
401 unsigned char ch_cached_lsr; /* Cached value of the LSR register */
403 unsigned char *ch_rqueue; /* Our read queue buffer - malloc'ed */
404 ushort ch_r_head; /* Head location of the read queue */
405 ushort ch_r_tail; /* Tail location of the read queue */
407 unsigned char *ch_equeue; /* Our error queue buffer - malloc'ed */
408 ushort ch_e_head; /* Head location of the error queue */
409 ushort ch_e_tail; /* Tail location of the error queue */
411 unsigned char *ch_wqueue; /* Our write queue buffer - malloc'ed */
412 ushort ch_w_head; /* Head location of the write queue */
413 ushort ch_w_tail; /* Tail location of the write queue */
415 ulong ch_rxcount; /* total of data received so far */
416 ulong ch_txcount; /* total of data transmitted so far */
418 unsigned char ch_r_tlevel; /* Receive Trigger level */
419 unsigned char ch_t_tlevel; /* Transmit Trigger level */
421 unsigned char ch_r_watermark; /* Receive Watermark */
423 ulong ch_stop_sending_break; /* Time we should STOP sending a break */
425 uint ch_stops_sent; /* How many times I have sent a stop character
426 * to try to stop the other guy sending.
428 ulong ch_err_parity; /* Count of parity errors on channel */
429 ulong ch_err_frame; /* Count of framing errors on channel */
430 ulong ch_err_break; /* Count of breaks on channel */
431 ulong ch_err_overrun; /* Count of overruns on channel */
433 ulong ch_xon_sends; /* Count of xons transmitted */
434 ulong ch_xoff_sends; /* Count of xoffs transmitted */
436 ulong ch_intr_modem; /* Count of interrupts */
437 ulong ch_intr_tx; /* Count of interrupts */
438 ulong ch_intr_rx; /* Count of interrupts */
441 /* /proc/<board>/<channel> entries */
442 struct proc_dir_entry *proc_entry_pointer;
443 struct dgnc_proc_entry *dgnc_channel_table;
447 char *ch_sniff_buf; /* Sniff buffer for proc */
448 ulong ch_sniff_flags; /* Channel flags */
449 wait_queue_head_t ch_sniff_wait;
453 * Our Global Variables.
455 extern uint dgnc_Major; /* Our driver/mgmt major */
456 extern int dgnc_debug; /* Debug variable */
457 extern int dgnc_rawreadok; /* Set if user wants rawreads */
458 extern int dgnc_poll_tick; /* Poll interval - 20 ms */
459 extern int dgnc_trcbuf_size; /* Size of the ringbuffer */
460 extern spinlock_t dgnc_global_lock; /* Driver global spinlock */
461 extern uint dgnc_NumBoards; /* Total number of boards */
462 extern struct dgnc_board *dgnc_Board[MAXBOARDS]; /* Array of board structs */
463 extern char *dgnc_state_text[]; /* Array of state text */