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 *************************************************************************
19 *************************************************************************/
21 #ifndef __DGNC_DRIVER_H
22 #define __DGNC_DRIVER_H
24 #include <linux/types.h> /* To pick up the varions Linux types */
25 #include <linux/tty.h> /* To pick up the various tty structs/defines */
26 #include <linux/interrupt.h> /* For irqreturn_t type */
28 #include "digi.h" /* Digi specific ioctl header */
29 #include "dgnc_sysfs.h" /* Support for SYSFS */
31 /*************************************************************************
35 *************************************************************************/
37 /* Driver identification and error statments */
38 #define PROCSTR "dgnc" /* /proc entries */
39 #define DEVSTR "/dev/dg/dgnc" /* /dev entries */
40 #define DRVSTR "dgnc" /* Driver name string */
41 #define DG_PART "40002369_F" /* RPM part number */
43 #define TRC_TO_CONSOLE 1
45 /* Number of boards we support at once. */
48 #define MAXTTYNAMELEN 200
50 /* Our 3 magic numbers for our board, channel and unit structs */
51 #define DGNC_BOARD_MAGIC 0x5c6df104
52 #define DGNC_CHANNEL_MAGIC 0x6c6df104
53 #define DGNC_UNIT_MAGIC 0x7c6df104
55 /* Serial port types */
59 #define SERIAL_TYPE_NORMAL 1
61 #define PORT_NUM(dev) ((dev) & 0x7f)
62 #define IS_PRINT(dev) (((dev) & 0xff) >= 0x80)
64 /* MAX number of stop characters we will send when our read queue is getting full */
65 #define MAX_STOPS_SENT 5
67 /* 4 extra for alignment play space */
68 #define WRITEBUFLEN ((4096) + 4)
70 #define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
73 * Define a local default termios struct. All ports will be created
74 * with this termios initially. This is the same structure that is defined
75 * as the default in tty_io.c with the same settings overridden as in serial.c
77 * In short, this should match the internal serial ports' defaults.
79 #define DEFAULT_IFLAGS (ICRNL | IXON)
80 #define DEFAULT_OFLAGS (OPOST | ONLCR)
81 #define DEFAULT_CFLAGS (B9600 | CS8 | CREAD | HUPCL | CLOCAL)
82 #define DEFAULT_LFLAGS (ISIG | ICANON | ECHO | ECHOE | ECHOK | \
83 ECHOCTL | ECHOKE | IEXTEN)
85 #ifndef _POSIX_VDISABLE
86 #define _POSIX_VDISABLE '\0'
91 * All the possible states the driver can be while being loaded.
94 DRIVER_INITIALIZED = 0,
99 * All the possible states the board can be while booting up.
108 /*************************************************************************
110 * Structures and closely related defines.
112 *************************************************************************/
117 /************************************************************************
118 * Per board operations structure *
119 ************************************************************************/
121 void (*tasklet)(unsigned long data);
122 irqreturn_t (*intr)(int irq, void *voidbrd);
123 void (*uart_init)(struct channel_t *ch);
124 void (*uart_off)(struct channel_t *ch);
125 int (*drain)(struct tty_struct *tty, uint seconds);
126 void (*param)(struct tty_struct *tty);
127 void (*vpd)(struct dgnc_board *brd);
128 void (*assert_modem_signals)(struct channel_t *ch);
129 void (*flush_uart_write)(struct channel_t *ch);
130 void (*flush_uart_read)(struct channel_t *ch);
131 void (*disable_receiver)(struct channel_t *ch);
132 void (*enable_receiver)(struct channel_t *ch);
133 void (*send_break)(struct channel_t *ch, int);
134 void (*send_start_character)(struct channel_t *ch);
135 void (*send_stop_character)(struct channel_t *ch);
136 void (*copy_data_from_queue_to_uart)(struct channel_t *ch);
137 uint (*get_uart_bytes_left)(struct channel_t *ch);
138 void (*send_immediate_char)(struct channel_t *ch, unsigned char);
141 /************************************************************************
142 * Device flag definitions for bd_flags.
143 ************************************************************************/
144 #define BD_IS_PCI_EXPRESS 0x0001 /* Is a PCI Express board */
148 * Per-board information
151 int magic; /* Board Magic number. */
152 int boardnum; /* Board number: 0-32 */
154 int type; /* Type of board */
155 char *name; /* Product Name */
156 struct pci_dev *pdev; /* Pointer to the pci_dev struct */
157 unsigned long bd_flags; /* Board flags */
158 u16 vendor; /* PCI vendor ID */
159 u16 device; /* PCI device ID */
160 u16 subvendor; /* PCI subsystem vendor ID */
161 u16 subdevice; /* PCI subsystem device ID */
162 unsigned char rev; /* PCI revision ID */
163 uint pci_bus; /* PCI bus value */
164 uint pci_slot; /* PCI slot value */
165 uint maxports; /* MAX ports this board can handle */
166 unsigned char dvid; /* Board specific device id */
167 unsigned char vpd[128]; /* VPD of board, if found */
168 unsigned char serial_num[20]; /* Serial number of board, if found in VPD */
170 spinlock_t bd_lock; /* Used to protect board */
172 spinlock_t bd_intr_lock; /* Used to protect the poller tasklet and
173 * the interrupt routine from each other.
176 uint state; /* State of card. */
177 wait_queue_head_t state_wait; /* Place to sleep on for state change */
179 struct tasklet_struct helper_tasklet; /* Poll helper tasklet */
181 uint nasync; /* Number of ports on card */
183 uint irq; /* Interrupt request number */
184 ulong intr_count; /* Count of interrupts */
185 ulong intr_modem; /* Count of interrupts */
186 ulong intr_tx; /* Count of interrupts */
187 ulong intr_rx; /* Count of interrupts */
189 ulong membase; /* Start of base memory of the card */
190 ulong membase_end; /* End of base memory of the card */
192 u8 __iomem *re_map_membase;/* Remapped memory of the card */
194 ulong iobase; /* Start of io base of the card */
195 ulong iobase_end; /* End of io base of the card */
197 uint bd_uart_offset; /* Space between each UART */
199 struct channel_t *channels[MAXPORTS]; /* array of pointers to our channels. */
201 struct tty_driver SerialDriver;
202 char SerialName[200];
203 struct tty_driver PrintDriver;
206 bool dgnc_Major_Serial_Registered;
207 bool dgnc_Major_TransparentPrint_Registered;
209 uint dgnc_Serial_Major;
210 uint dgnc_TransparentPrint_Major;
214 u16 dpatype; /* The board "type", as defined by DPA */
215 u16 dpastatus; /* The board "status", as defined by DPA */
223 uint bd_dividend; /* Board/UARTs specific dividend */
225 struct board_ops *bd_ops;
227 /* /proc/<board> entries */
228 struct proc_dir_entry *proc_entry_pointer;
229 struct dgnc_proc_entry *dgnc_board_table;
234 /************************************************************************
235 * Unit flag definitions for un_flags.
236 ************************************************************************/
237 #define UN_ISOPEN 0x0001 /* Device is open */
238 #define UN_CLOSING 0x0002 /* Line is being closed */
239 #define UN_IMM 0x0004 /* Service immediately */
240 #define UN_BUSY 0x0008 /* Some work this channel */
241 #define UN_BREAKI 0x0010 /* Input break received */
242 #define UN_PWAIT 0x0020 /* Printer waiting for terminal */
243 #define UN_TIME 0x0040 /* Waiting on time */
244 #define UN_EMPTY 0x0080 /* Waiting output queue empty */
245 #define UN_LOW 0x0100 /* Waiting output low water mark*/
246 #define UN_EXCL_OPEN 0x0200 /* Open for exclusive use */
247 #define UN_WOPEN 0x0400 /* Device waiting for open */
248 #define UN_WIOCTL 0x0800 /* Device waiting for open */
249 #define UN_HANGUP 0x8000 /* Carrier lost */
253 /************************************************************************
254 * Structure for terminal or printer unit.
255 ************************************************************************/
257 int magic; /* Unit Magic Number. */
258 struct channel_t *un_ch;
261 uint un_open_count; /* Counter of opens to port */
262 struct tty_struct *un_tty;/* Pointer to unit tty structure */
263 uint un_flags; /* Unit flags */
264 wait_queue_head_t un_flags_wait; /* Place to sleep to wait on unit */
265 uint un_dev; /* Minor device number */
266 struct device *un_sysfs;
270 /************************************************************************
271 * Device flag definitions for ch_flags.
272 ************************************************************************/
273 #define CH_PRON 0x0001 /* Printer on string */
274 #define CH_STOP 0x0002 /* Output is stopped */
275 #define CH_STOPI 0x0004 /* Input is stopped */
276 #define CH_CD 0x0008 /* Carrier is present */
277 #define CH_FCAR 0x0010 /* Carrier forced on */
278 #define CH_HANGUP 0x0020 /* Hangup received */
280 #define CH_RECEIVER_OFF 0x0040 /* Receiver is off */
281 #define CH_OPENING 0x0080 /* Port in fragile open state */
282 #define CH_CLOSING 0x0100 /* Port in fragile close state */
283 #define CH_FIFO_ENABLED 0x0200 /* Port has FIFOs enabled */
284 #define CH_TX_FIFO_EMPTY 0x0400 /* TX Fifo is completely empty */
285 #define CH_TX_FIFO_LWM 0x0800 /* TX Fifo is below Low Water */
286 #define CH_BREAK_SENDING 0x1000 /* Break is being sent */
287 #define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */
288 #define CH_BAUD0 0x08000 /* Used for checking B0 transitions */
289 #define CH_FORCED_STOP 0x20000 /* Output is forcibly stopped */
290 #define CH_FORCED_STOPI 0x40000 /* Input is forcibly stopped */
293 /* Our Read/Error/Write queue sizes */
294 #define RQUEUEMASK 0x1FFF /* 8 K - 1 */
295 #define EQUEUEMASK 0x1FFF /* 8 K - 1 */
296 #define WQUEUEMASK 0x0FFF /* 4 K - 1 */
297 #define RQUEUESIZE (RQUEUEMASK + 1)
298 #define EQUEUESIZE RQUEUESIZE
299 #define WQUEUESIZE (WQUEUEMASK + 1)
302 /************************************************************************
303 * Channel information structure.
304 ************************************************************************/
306 int magic; /* Channel Magic Number */
307 struct dgnc_board *ch_bd; /* Board structure pointer */
308 struct digi_t ch_digi; /* Transparent Print structure */
309 struct un_t ch_tun; /* Terminal unit info */
310 struct un_t ch_pun; /* Printer unit info */
312 spinlock_t ch_lock; /* provide for serialization */
313 wait_queue_head_t ch_flags_wait;
315 uint ch_portnum; /* Port number, 0 offset. */
316 uint ch_open_count; /* open count */
317 uint ch_flags; /* Channel flags */
319 ulong ch_close_delay; /* How long we should drop RTS/DTR for */
321 ulong ch_cpstime; /* Time for CPS calculations */
323 tcflag_t ch_c_iflag; /* channel iflags */
324 tcflag_t ch_c_cflag; /* channel cflags */
325 tcflag_t ch_c_oflag; /* channel oflags */
326 tcflag_t ch_c_lflag; /* channel lflags */
327 unsigned char ch_stopc; /* Stop character */
328 unsigned char ch_startc; /* Start character */
330 uint ch_old_baud; /* Cache of the current baud */
331 uint ch_custom_speed;/* Custom baud, if set */
333 uint ch_wopen; /* Waiting for open process cnt */
335 unsigned char ch_mostat; /* FEP output modem status */
336 unsigned char ch_mistat; /* FEP input modem status */
338 struct neo_uart_struct __iomem *ch_neo_uart; /* Pointer to the "mapped" UART struct */
339 struct cls_uart_struct __iomem *ch_cls_uart; /* Pointer to the "mapped" UART struct */
341 unsigned char ch_cached_lsr; /* Cached value of the LSR register */
343 unsigned char *ch_rqueue; /* Our read queue buffer - malloc'ed */
344 ushort ch_r_head; /* Head location of the read queue */
345 ushort ch_r_tail; /* Tail location of the read queue */
347 unsigned char *ch_equeue; /* Our error queue buffer - malloc'ed */
348 ushort ch_e_head; /* Head location of the error queue */
349 ushort ch_e_tail; /* Tail location of the error queue */
351 unsigned char *ch_wqueue; /* Our write queue buffer - malloc'ed */
352 ushort ch_w_head; /* Head location of the write queue */
353 ushort ch_w_tail; /* Tail location of the write queue */
355 ulong ch_rxcount; /* total of data received so far */
356 ulong ch_txcount; /* total of data transmitted so far */
358 unsigned char ch_r_tlevel; /* Receive Trigger level */
359 unsigned char ch_t_tlevel; /* Transmit Trigger level */
361 unsigned char ch_r_watermark; /* Receive Watermark */
363 ulong ch_stop_sending_break; /* Time we should STOP sending a break */
365 uint ch_stops_sent; /* How many times I have sent a stop character
366 * to try to stop the other guy sending.
368 ulong ch_err_parity; /* Count of parity errors on channel */
369 ulong ch_err_frame; /* Count of framing errors on channel */
370 ulong ch_err_break; /* Count of breaks on channel */
371 ulong ch_err_overrun; /* Count of overruns on channel */
373 ulong ch_xon_sends; /* Count of xons transmitted */
374 ulong ch_xoff_sends; /* Count of xoffs transmitted */
376 ulong ch_intr_modem; /* Count of interrupts */
377 ulong ch_intr_tx; /* Count of interrupts */
378 ulong ch_intr_rx; /* Count of interrupts */
381 /* /proc/<board>/<channel> entries */
382 struct proc_dir_entry *proc_entry_pointer;
383 struct dgnc_proc_entry *dgnc_channel_table;
388 * Our Global Variables.
390 extern uint dgnc_Major; /* Our driver/mgmt major */
391 extern int dgnc_poll_tick; /* Poll interval - 20 ms */
392 extern spinlock_t dgnc_global_lock; /* Driver global spinlock */
393 extern uint dgnc_NumBoards; /* Total number of boards */
394 extern struct dgnc_board *dgnc_Board[MAXBOARDS]; /* Array of board structs */