1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * Copyright 2003 Digi International (www.digi.com) 4 * Scott H Kilau <Scott_Kilau at digi dot com> 5 */ 6 7 #ifndef _DGNC_DRIVER_H 8 #define _DGNC_DRIVER_H 9 10 #include <linux/types.h> 11 #include <linux/tty.h> 12 #include <linux/interrupt.h> 13 14 #include "digi.h" /* Digi specific ioctl header */ 15 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 */ 21 22 #define TRC_TO_CONSOLE 1 23 24 /* Number of boards we support at once. */ 25 #define MAXBOARDS 20 26 #define MAXPORTS 8 27 #define MAXTTYNAMELEN 200 28 29 /* Serial port types */ 30 #define DGNC_SERIAL 0 31 #define DGNC_PRINT 1 32 33 #define SERIAL_TYPE_NORMAL 1 34 35 #define PORT_NUM(dev) ((dev) & 0x7f) 36 #define IS_PRINT(dev) (((dev) & 0xff) >= 0x80) 37 38 /* MAX number of stop characters sent when our read queue is getting full */ 39 #define MAX_STOPS_SENT 5 40 41 /* 4 extra for alignment play space */ 42 #define WRITEBUFLEN ((4096) + 4) 43 44 #define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000) 45 46 #ifndef _POSIX_VDISABLE 47 #define _POSIX_VDISABLE '\0' 48 #endif 49 50 /* All the possible states the driver can be while being loaded. */ 51 enum { 52 DRIVER_INITIALIZED = 0, 53 DRIVER_READY 54 }; 55 56 /* All the possible states the board can be while booting up. */ 57 enum { 58 BOARD_FAILED = 0, 59 BOARD_FOUND, 60 BOARD_READY 61 }; 62 63 struct dgnc_board; 64 struct channel_t; 65 66 /** 67 * struct board_ops - Per board operations. 68 */ 69 struct board_ops { 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); 87 }; 88 89 /** 90 * struct dgnc_board - Per board information. 91 * @boardnum: Board number (0 - 32). 92 * 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. 116 */ 117 struct dgnc_board { 118 int boardnum; 119 char *name; 120 struct pci_dev *pdev; 121 u16 device; 122 uint maxports; 123 124 /* used to protect the board */ 125 spinlock_t bd_lock; 126 127 /* Protect poller tasklet and interrupt routine from each other. */ 128 spinlock_t bd_intr_lock; 129 130 uint state; 131 wait_queue_head_t state_wait; 132 133 struct tasklet_struct helper_tasklet; 134 135 uint nasync; 136 137 uint irq; 138 139 ulong membase; 140 ulong membase_end; 141 142 u8 __iomem *re_map_membase; 143 144 ulong iobase; 145 ulong iobase_end; 146 147 uint bd_uart_offset; 148 149 struct channel_t *channels[MAXPORTS]; 150 151 struct tty_driver *serial_driver; 152 char serial_name[200]; 153 struct tty_driver *print_driver; 154 char print_name[200]; 155 156 uint bd_dividend; 157 158 struct board_ops *bd_ops; 159 }; 160 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 */ 175 176 struct device; 177 178 /** 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. 185 */ 186 struct un_t { 187 struct channel_t *un_ch; 188 uint un_type; 189 uint un_open_count; 190 struct tty_struct *un_tty; 191 uint un_flags; 192 wait_queue_head_t un_flags_wait; 193 uint un_dev; 194 struct device *un_sysfs; 195 }; 196 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 */ 204 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 */ 216 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) 224 225 /** 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. 274 */ 275 struct channel_t { 276 struct dgnc_board *ch_bd; 277 struct digi_t ch_digi; 278 struct un_t ch_tun; 279 struct un_t ch_pun; 280 281 spinlock_t ch_lock; /* provide for serialization */ 282 wait_queue_head_t ch_flags_wait; 283 284 uint ch_portnum; 285 uint ch_open_count; 286 uint ch_flags; 287 288 ulong ch_close_delay; 289 290 ulong ch_cpstime; 291 292 tcflag_t ch_c_iflag; 293 tcflag_t ch_c_cflag; 294 tcflag_t ch_c_oflag; 295 tcflag_t ch_c_lflag; 296 unsigned char ch_stopc; 297 unsigned char ch_startc; 298 299 uint ch_old_baud; 300 uint ch_custom_speed; 301 302 uint ch_wopen; 303 304 unsigned char ch_mostat; 305 unsigned char ch_mistat; 306 307 struct cls_uart_struct __iomem *ch_cls_uart; 308 309 unsigned char ch_cached_lsr; 310 311 unsigned char *ch_rqueue; 312 ushort ch_r_head; 313 ushort ch_r_tail; 314 315 unsigned char *ch_equeue; 316 ushort ch_e_head; 317 ushort ch_e_tail; 318 319 unsigned char *ch_wqueue; 320 ushort ch_w_head; 321 ushort ch_w_tail; 322 323 ulong ch_rxcount; 324 ulong ch_txcount; 325 326 unsigned char ch_r_tlevel; 327 unsigned char ch_t_tlevel; 328 329 unsigned char ch_r_watermark; 330 331 ulong ch_stop_sending_break; 332 uint ch_stops_sent; 333 334 ulong ch_err_parity; 335 ulong ch_err_frame; 336 ulong ch_err_break; 337 ulong ch_err_overrun; 338 339 ulong ch_xon_sends; 340 ulong ch_xoff_sends; 341 }; 342 343 extern struct dgnc_board *dgnc_board[MAXBOARDS];/* Array of boards */ 344 345 #endif /* _DGNC_DRIVER_H */ 346