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.
16 #ifndef _DGNC_DRIVER_H
17 #define _DGNC_DRIVER_H
19 #include <linux/types.h>
20 #include <linux/tty.h>
21 #include <linux/interrupt.h>
23 #include "digi.h" /* Digi specific ioctl header */
25 /* Driver identification and error statements */
26 #define PROCSTR "dgnc" /* /proc entries */
27 #define DEVSTR "/dev/dg/dgnc" /* /dev entries */
28 #define DRVSTR "dgnc" /* Driver name string */
29 #define DG_PART "40002369_F" /* RPM part number */
31 #define TRC_TO_CONSOLE 1
33 /* Number of boards we support at once. */
36 #define MAXTTYNAMELEN 200
38 /* Serial port types */
42 #define SERIAL_TYPE_NORMAL 1
44 #define PORT_NUM(dev) ((dev) & 0x7f)
45 #define IS_PRINT(dev) (((dev) & 0xff) >= 0x80)
47 /* MAX number of stop characters sent when our read queue is getting full */
48 #define MAX_STOPS_SENT 5
50 /* 4 extra for alignment play space */
51 #define WRITEBUFLEN ((4096) + 4)
53 #define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
55 #ifndef _POSIX_VDISABLE
56 #define _POSIX_VDISABLE '\0'
59 /* All the possible states the driver can be while being loaded. */
61 DRIVER_INITIALIZED = 0,
65 /* All the possible states the board can be while booting up. */
76 * struct board_ops - Per board operations.
79 void (*tasklet)(unsigned long data);
80 irqreturn_t (*intr)(int irq, void *voidbrd);
81 void (*uart_init)(struct channel_t *ch);
82 void (*uart_off)(struct channel_t *ch);
83 int (*drain)(struct tty_struct *tty, uint seconds);
84 void (*param)(struct tty_struct *tty);
85 void (*vpd)(struct dgnc_board *brd);
86 void (*assert_modem_signals)(struct channel_t *ch);
87 void (*flush_uart_write)(struct channel_t *ch);
88 void (*flush_uart_read)(struct channel_t *ch);
89 void (*disable_receiver)(struct channel_t *ch);
90 void (*enable_receiver)(struct channel_t *ch);
91 void (*send_break)(struct channel_t *ch, int);
92 void (*send_start_character)(struct channel_t *ch);
93 void (*send_stop_character)(struct channel_t *ch);
94 void (*copy_data_from_queue_to_uart)(struct channel_t *ch);
95 uint (*get_uart_bytes_left)(struct channel_t *ch);
96 void (*send_immediate_char)(struct channel_t *ch, unsigned char);
99 /* Device flag definitions for bd_flags. */
101 #define BD_IS_PCI_EXPRESS 0x0001 /* Is a PCI Express board */
104 * struct dgnc_board - Per board information.
105 * @boardnum: Board number (0 - 32).
107 * @type: Type of board.
108 * @name: Product name.
109 * @pdev: Pointer to the pci_dev structure.
110 * @bd_flags: Board flags.
111 * @vendor: PCI vendor ID.
112 * @device: PCI device ID.
113 * @subvendor: PCI subsystem vendor ID.
114 * @subdevice: PCI subsystem device ID.
115 * @rev: PCI revision ID.
116 * @pci_bus: PCI bus value.
117 * @pci_slot: PCI slot value.
118 * @maxports: Maximum ports this board can handle.
119 * @dvid: Board specific device ID.
120 * @vpd: VPD of this board, if found.
121 * @serial_num: Serial number of this board, if found in VPD.
122 * @bd_lock: Used to protect board.
123 * @bd_intr_lock: Protect poller tasklet and interrupt routine from each other.
124 * @state: State of the card.
125 * @state_wait: Queue to sleep on for state change.
126 * @helper_tasklet: Poll helper tasklet.
127 * @nasync: Number of ports on card.
128 * @irq: Interrupt request number.
129 * @membase: Start of base memory of the card.
130 * @membase_end: End of base memory of the card.
131 * @iobase: Start of IO base of the card.
132 * @iobase_end: End of IO base of the card.
133 * @bd_uart_offset: Space between each UART.
134 * @channels: array of pointers to our channels.
135 * @serial_driver: Pointer to the serial driver.
136 * @serial_name: Serial driver name.
137 * @print_dirver: Pointer to the print driver.
138 * @print_name: Print driver name.
139 * @dpatype: Board type as defined by DPA.
140 * @dpastatus: Board status as defined by DPA.
141 * @bd_dividend: Board/UART's specific dividend.
142 * @bd_ops: Pointer to board operations structure.
143 * @proc_entry_pointer: Proc/<board> entry
144 * @dgnc_board_table: Proc/<board> entry
151 struct pci_dev *pdev;
152 unsigned long bd_flags;
162 unsigned char vpd[128];
163 unsigned char serial_num[20];
165 /* used to protect the board */
168 /* Protect poller tasklet and interrupt routine from each other. */
169 spinlock_t bd_intr_lock;
172 wait_queue_head_t state_wait;
174 struct tasklet_struct helper_tasklet;
183 u8 __iomem *re_map_membase;
190 struct channel_t *channels[MAXPORTS];
192 struct tty_driver *serial_driver;
193 char serial_name[200];
194 struct tty_driver *print_driver;
195 char print_name[200];
202 struct board_ops *bd_ops;
204 struct proc_dir_entry *proc_entry_pointer;
205 struct dgnc_proc_entry *dgnc_board_table;
209 /* Unit flag definitions for un_flags. */
210 #define UN_ISOPEN 0x0001 /* Device is open */
211 #define UN_CLOSING 0x0002 /* Line is being closed */
212 #define UN_IMM 0x0004 /* Service immediately */
213 #define UN_BUSY 0x0008 /* Some work this channel */
214 #define UN_BREAKI 0x0010 /* Input break received */
215 #define UN_PWAIT 0x0020 /* Printer waiting for terminal */
216 #define UN_TIME 0x0040 /* Waiting on time */
217 #define UN_EMPTY 0x0080 /* Waiting output queue empty */
218 #define UN_LOW 0x0100 /* Waiting output low water mark*/
219 #define UN_EXCL_OPEN 0x0200 /* Open for exclusive use */
220 #define UN_WOPEN 0x0400 /* Device waiting for open */
221 #define UN_WIOCTL 0x0800 /* Device waiting for open */
222 #define UN_HANGUP 0x8000 /* Carrier lost */
227 * struct un_t - terminal or printer unit
228 * @un_open_count: Counter of opens to port.
229 * @un_tty: Pointer to unit tty structure.
230 * @un_flags: Unit flags.
231 * @un_flags_wait: Place to sleep to wait on unit.
232 * @un_dev: Minor device number.
235 struct channel_t *un_ch;
239 struct tty_struct *un_tty;
241 wait_queue_head_t un_flags_wait;
243 struct device *un_sysfs;
246 /* Device flag definitions for ch_flags. */
247 #define CH_PRON 0x0001 /* Printer on string */
248 #define CH_STOP 0x0002 /* Output is stopped */
249 #define CH_STOPI 0x0004 /* Input is stopped */
250 #define CH_CD 0x0008 /* Carrier is present */
251 #define CH_FCAR 0x0010 /* Carrier forced on */
252 #define CH_HANGUP 0x0020 /* Hangup received */
254 #define CH_RECEIVER_OFF 0x0040 /* Receiver is off */
255 #define CH_OPENING 0x0080 /* Port in fragile open state */
256 #define CH_CLOSING 0x0100 /* Port in fragile close state */
257 #define CH_FIFO_ENABLED 0x0200 /* Port has FIFOs enabled */
258 #define CH_TX_FIFO_EMPTY 0x0400 /* TX Fifo is completely empty */
259 #define CH_TX_FIFO_LWM 0x0800 /* TX Fifo is below Low Water */
260 #define CH_BREAK_SENDING 0x1000 /* Break is being sent */
261 #define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */
262 #define CH_BAUD0 0x08000 /* Used for checking B0 transitions */
263 #define CH_FORCED_STOP 0x20000 /* Output is forcibly stopped */
264 #define CH_FORCED_STOPI 0x40000 /* Input is forcibly stopped */
266 /* Our Read/Error/Write queue sizes */
267 #define RQUEUEMASK 0x1FFF /* 8 K - 1 */
268 #define EQUEUEMASK 0x1FFF /* 8 K - 1 */
269 #define WQUEUEMASK 0x0FFF /* 4 K - 1 */
270 #define RQUEUESIZE (RQUEUEMASK + 1)
271 #define EQUEUESIZE RQUEUESIZE
272 #define WQUEUESIZE (WQUEUEMASK + 1)
275 * struct channel_t - Channel information.
276 * @dgnc_board: Pointer to board structure.
277 * @ch_bd: Transparent print structure.
278 * @ch_tun: Terminal unit information.
279 * @ch_pun: Printer unit information.
280 * @ch_lock: Provide for serialization.
281 * @ch_flags_wait: Channel flags wait queue.
282 * @ch_portnum: Port number, 0 offset.
283 * @ch_open_count: Open count.
284 * @ch_flags: Channel flags.
285 * @ch_close_delay: How long we should drop RTS/DTR for.
286 * @ch_cpstime: Time for CPS calculations.
287 * @ch_c_iflag: Channel iflags.
288 * @ch_c_cflag: Channel cflags.
289 * @ch_c_oflag: Channel oflags.
290 * @ch_c_lflag: Channel lflags.
291 * @ch_stopc: Stop character.
292 * @ch_startc: Start character.
293 * @ch_old_baud: Cache of the current baud rate.
294 * @ch_custom_speed: Custom baud rate, if set.
295 * @ch_wopen: Waiting for open process count.
296 * @ch_mostat: FEP output modem status.
297 * @ch_mistat: FEP input modem status.
298 * @chc_neo_uart: Pointer to the mapped neo UART struct
299 * @ch_cls_uart: Pointer to the mapped cls UART struct
300 * @ch_cached_lsr: Cached value of the LSR register.
301 * @ch_rqueue: Read queue buffer, malloc'ed.
302 * @ch_r_head: Head location of the read queue.
303 * @ch_r_tail: Tail location of the read queue.
304 * @ch_equeue: Error queue buffer, malloc'ed.
305 * @ch_e_head: Head location of the error queue.
306 * @ch_e_tail: Tail location of the error queue.
307 * @ch_wqueue: Write queue buffer, malloc'ed.
308 * @ch_w_head: Head location of the write queue.
309 * @ch_w_tail: Tail location of the write queue.
310 * @ch_rxcount: Total of data received so far.
311 * @ch_txcount: Total of data transmitted so far.
312 * @ch_r_tlevel: Receive trigger level.
313 * @ch_t_tlevel: Transmit trigger level.
314 * @ch_r_watermark: Receive water mark.
315 * @ch_stop_sending_break: Time we should STOP sending a break.
316 * @ch_stops_sent: How many times I have send a stop character to try
317 * to stop the other guy sending.
318 * @ch_err_parity: Count of parity
319 * @ch_err_frame: Count of framing errors on channel.
320 * @ch_err_break: Count of breaks on channel.
321 * @ch_err_overrun: Count of overruns on channel.
322 * @ch_xon_sends: Count of xons transmitted.
323 * @ch_xoff_sends: Count of xoffs transmitted.
324 * @proc_entry_pointer: Proc/<board>/<channel> entry.
325 * @dgnc_channel_table: Proc/<board>/<channel> entry.
328 struct dgnc_board *ch_bd;
329 struct digi_t ch_digi;
333 spinlock_t ch_lock; /* provide for serialization */
334 wait_queue_head_t ch_flags_wait;
340 ulong ch_close_delay;
348 unsigned char ch_stopc;
349 unsigned char ch_startc;
352 uint ch_custom_speed;
356 unsigned char ch_mostat;
357 unsigned char ch_mistat;
359 struct neo_uart_struct __iomem *ch_neo_uart;
360 struct cls_uart_struct __iomem *ch_cls_uart;
362 unsigned char ch_cached_lsr;
364 unsigned char *ch_rqueue;
368 unsigned char *ch_equeue;
372 unsigned char *ch_wqueue;
379 unsigned char ch_r_tlevel;
380 unsigned char ch_t_tlevel;
382 unsigned char ch_r_watermark;
384 ulong ch_stop_sending_break;
390 ulong ch_err_overrun;
395 struct proc_dir_entry *proc_entry_pointer;
396 struct dgnc_proc_entry *dgnc_channel_table;
400 extern uint dgnc_major; /* Our driver/mgmt major */
401 extern int dgnc_poll_tick; /* Poll interval - 20 ms */
402 extern spinlock_t dgnc_global_lock; /* Driver global spinlock */
403 extern spinlock_t dgnc_poll_lock; /* Poll scheduling lock */
404 extern uint dgnc_num_boards; /* Total number of boards */
405 extern struct dgnc_board *dgnc_board[MAXBOARDS];/* Array of boards */
407 #endif /* _DGNC_DRIVER_H */