1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright 2003 Digi International (www.digi.com)
4 * Scott H Kilau <Scott_Kilau at digi dot com>
10 #include <linux/types.h>
11 #include <linux/tty.h>
12 #include <linux/interrupt.h>
14 #include "digi.h" /* Digi specific ioctl header */
16 /* Driver identification and error statements */
17 #define PROCSTR "dgnc" /* /proc entries */
18 #define DEVSTR "/dev/dg/dgnc" /* /dev entries */
19 #define DRVSTR "dgnc" /* Driver name string */
20 #define DG_PART "40002369_F" /* RPM part number */
22 #define TRC_TO_CONSOLE 1
24 /* Number of boards we support at once. */
27 #define MAXTTYNAMELEN 200
29 /* Serial port types */
33 #define SERIAL_TYPE_NORMAL 1
35 #define PORT_NUM(dev) ((dev) & 0x7f)
36 #define IS_PRINT(dev) (((dev) & 0xff) >= 0x80)
38 /* MAX number of stop characters sent when our read queue is getting full */
39 #define MAX_STOPS_SENT 5
41 /* 4 extra for alignment play space */
42 #define WRITEBUFLEN ((4096) + 4)
44 #define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
46 #ifndef _POSIX_VDISABLE
47 #define _POSIX_VDISABLE '\0'
50 /* All the possible states the driver can be while being loaded. */
52 DRIVER_INITIALIZED = 0,
56 /* All the possible states the board can be while booting up. */
67 * struct board_ops - Per board operations.
70 void (*tasklet)(unsigned long data);
71 irqreturn_t (*intr)(int irq, void *voidbrd);
72 void (*uart_init)(struct channel_t *ch);
73 void (*uart_off)(struct channel_t *ch);
74 int (*drain)(struct tty_struct *tty, uint seconds);
75 void (*param)(struct tty_struct *tty);
76 void (*assert_modem_signals)(struct channel_t *ch);
77 void (*flush_uart_write)(struct channel_t *ch);
78 void (*flush_uart_read)(struct channel_t *ch);
79 void (*disable_receiver)(struct channel_t *ch);
80 void (*enable_receiver)(struct channel_t *ch);
81 void (*send_break)(struct channel_t *ch, int msec);
82 void (*send_start_character)(struct channel_t *ch);
83 void (*send_stop_character)(struct channel_t *ch);
84 void (*copy_data_from_queue_to_uart)(struct channel_t *ch);
85 uint (*get_uart_bytes_left)(struct channel_t *ch);
86 void (*send_immediate_char)(struct channel_t *ch, unsigned char c);
90 * struct dgnc_board - Per board information.
91 * @boardnum: Board number (0 - 32).
93 * @name: Product name.
94 * @pdev: Pointer to the pci_dev structure.
95 * @device: PCI device ID.
96 * @maxports: Maximum ports this board can handle.
97 * @bd_lock: Used to protect board.
98 * @bd_intr_lock: Protect poller tasklet and interrupt routine from each other.
99 * @state: State of the card.
100 * @state_wait: Queue to sleep on for state change.
101 * @helper_tasklet: Poll helper tasklet.
102 * @nasync: Number of ports on card.
103 * @irq: Interrupt request number.
104 * @membase: Start of base memory of the card.
105 * @membase_end: End of base memory of the card.
106 * @iobase: Start of IO base of the card.
107 * @iobase_end: End of IO base of the card.
108 * @bd_uart_offset: Space between each UART.
109 * @channels: array of pointers to our channels.
110 * @serial_driver: Pointer to the serial driver.
111 * @serial_name: Serial driver name.
112 * @print_dirver: Pointer to the print driver.
113 * @print_name: Print driver name.
114 * @bd_dividend: Board/UART's specific dividend.
115 * @bd_ops: Pointer to board operations structure.
120 struct pci_dev *pdev;
124 /* used to protect the board */
127 /* Protect poller tasklet and interrupt routine from each other. */
128 spinlock_t bd_intr_lock;
131 wait_queue_head_t state_wait;
133 struct tasklet_struct helper_tasklet;
142 u8 __iomem *re_map_membase;
149 struct channel_t *channels[MAXPORTS];
151 struct tty_driver *serial_driver;
152 char serial_name[200];
153 struct tty_driver *print_driver;
154 char print_name[200];
158 struct board_ops *bd_ops;
161 /* Unit flag definitions for un_flags. */
162 #define UN_ISOPEN 0x0001 /* Device is open */
163 #define UN_CLOSING 0x0002 /* Line is being closed */
164 #define UN_IMM 0x0004 /* Service immediately */
165 #define UN_BUSY 0x0008 /* Some work this channel */
166 #define UN_BREAKI 0x0010 /* Input break received */
167 #define UN_PWAIT 0x0020 /* Printer waiting for terminal */
168 #define UN_TIME 0x0040 /* Waiting on time */
169 #define UN_EMPTY 0x0080 /* Waiting output queue empty */
170 #define UN_LOW 0x0100 /* Waiting output low water mark*/
171 #define UN_EXCL_OPEN 0x0200 /* Open for exclusive use */
172 #define UN_WOPEN 0x0400 /* Device waiting for open */
173 #define UN_WIOCTL 0x0800 /* Device waiting for open */
174 #define UN_HANGUP 0x8000 /* Carrier lost */
179 * struct un_t - terminal or printer unit
180 * @un_open_count: Counter of opens to port.
181 * @un_tty: Pointer to unit tty structure.
182 * @un_flags: Unit flags.
183 * @un_flags_wait: Place to sleep to wait on unit.
184 * @un_dev: Minor device number.
187 struct channel_t *un_ch;
190 struct tty_struct *un_tty;
192 wait_queue_head_t un_flags_wait;
194 struct device *un_sysfs;
197 /* Device flag definitions for ch_flags. */
198 #define CH_PRON 0x0001 /* Printer on string */
199 #define CH_STOP 0x0002 /* Output is stopped */
200 #define CH_STOPI 0x0004 /* Input is stopped */
201 #define CH_CD 0x0008 /* Carrier is present */
202 #define CH_FCAR 0x0010 /* Carrier forced on */
203 #define CH_HANGUP 0x0020 /* Hangup received */
205 #define CH_RECEIVER_OFF 0x0040 /* Receiver is off */
206 #define CH_OPENING 0x0080 /* Port in fragile open state */
207 #define CH_CLOSING 0x0100 /* Port in fragile close state */
208 #define CH_FIFO_ENABLED 0x0200 /* Port has FIFOs enabled */
209 #define CH_TX_FIFO_EMPTY 0x0400 /* TX Fifo is completely empty */
210 #define CH_TX_FIFO_LWM 0x0800 /* TX Fifo is below Low Water */
211 #define CH_BREAK_SENDING 0x1000 /* Break is being sent */
212 #define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */
213 #define CH_BAUD0 0x08000 /* Used for checking B0 transitions */
214 #define CH_FORCED_STOP 0x20000 /* Output is forcibly stopped */
215 #define CH_FORCED_STOPI 0x40000 /* Input is forcibly stopped */
217 /* Our Read/Error/Write queue sizes */
218 #define RQUEUEMASK 0x1FFF /* 8 K - 1 */
219 #define EQUEUEMASK 0x1FFF /* 8 K - 1 */
220 #define WQUEUEMASK 0x0FFF /* 4 K - 1 */
221 #define RQUEUESIZE (RQUEUEMASK + 1)
222 #define EQUEUESIZE RQUEUESIZE
223 #define WQUEUESIZE (WQUEUEMASK + 1)
226 * struct channel_t - Channel information.
227 * @dgnc_board: Pointer to board structure.
228 * @ch_bd: Transparent print structure.
229 * @ch_tun: Terminal unit information.
230 * @ch_pun: Printer unit information.
231 * @ch_lock: Provide for serialization.
232 * @ch_flags_wait: Channel flags wait queue.
233 * @ch_portnum: Port number, 0 offset.
234 * @ch_open_count: Open count.
235 * @ch_flags: Channel flags.
236 * @ch_close_delay: How long we should drop RTS/DTR for.
237 * @ch_cpstime: Time for CPS calculations.
238 * @ch_c_iflag: Channel iflags.
239 * @ch_c_cflag: Channel cflags.
240 * @ch_c_oflag: Channel oflags.
241 * @ch_c_lflag: Channel lflags.
242 * @ch_stopc: Stop character.
243 * @ch_startc: Start character.
244 * @ch_old_baud: Cache of the current baud rate.
245 * @ch_custom_speed: Custom baud rate, if set.
246 * @ch_wopen: Waiting for open process count.
247 * @ch_mostat: FEP output modem status.
248 * @ch_mistat: FEP input modem status.
249 * @ch_cls_uart: Pointer to the mapped cls UART struct
250 * @ch_cached_lsr: Cached value of the LSR register.
251 * @ch_rqueue: Read queue buffer, malloc'ed.
252 * @ch_r_head: Head location of the read queue.
253 * @ch_r_tail: Tail location of the read queue.
254 * @ch_equeue: Error queue buffer, malloc'ed.
255 * @ch_e_head: Head location of the error queue.
256 * @ch_e_tail: Tail location of the error queue.
257 * @ch_wqueue: Write queue buffer, malloc'ed.
258 * @ch_w_head: Head location of the write queue.
259 * @ch_w_tail: Tail location of the write queue.
260 * @ch_rxcount: Total of data received so far.
261 * @ch_txcount: Total of data transmitted so far.
262 * @ch_r_tlevel: Receive trigger level.
263 * @ch_t_tlevel: Transmit trigger level.
264 * @ch_r_watermark: Receive water mark.
265 * @ch_stop_sending_break: Time we should STOP sending a break.
266 * @ch_stops_sent: How many times I have send a stop character to try
267 * to stop the other guy sending.
268 * @ch_err_parity: Count of parity
269 * @ch_err_frame: Count of framing errors on channel.
270 * @ch_err_break: Count of breaks on channel.
271 * @ch_err_overrun: Count of overruns on channel.
272 * @ch_xon_sends: Count of xons transmitted.
273 * @ch_xoff_sends: Count of xoffs transmitted.
276 struct dgnc_board *ch_bd;
277 struct digi_t ch_digi;
281 spinlock_t ch_lock; /* provide for serialization */
282 wait_queue_head_t ch_flags_wait;
288 ulong ch_close_delay;
296 unsigned char ch_stopc;
297 unsigned char ch_startc;
300 uint ch_custom_speed;
304 unsigned char ch_mostat;
305 unsigned char ch_mistat;
307 struct cls_uart_struct __iomem *ch_cls_uart;
309 unsigned char ch_cached_lsr;
311 unsigned char *ch_rqueue;
315 unsigned char *ch_equeue;
319 unsigned char *ch_wqueue;
326 unsigned char ch_r_tlevel;
327 unsigned char ch_t_tlevel;
329 unsigned char ch_r_watermark;
331 ulong ch_stop_sending_break;
337 ulong ch_err_overrun;
343 extern struct dgnc_board *dgnc_board[MAXBOARDS];/* Array of boards */
345 #endif /* _DGNC_DRIVER_H */