GNU Linux-libre 4.14.251-gnu1
[releases.git] / drivers / staging / dgnc / dgnc_driver.h
1 /*
2  * Copyright 2003 Digi International (www.digi.com)
3  *      Scott H Kilau <Scott_Kilau at digi dot com>
4  *
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)
8  * any later version.
9  *
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.
14  */
15
16 #ifndef _DGNC_DRIVER_H
17 #define _DGNC_DRIVER_H
18
19 #include <linux/types.h>
20 #include <linux/tty.h>
21 #include <linux/interrupt.h>
22
23 #include "digi.h"               /* Digi specific ioctl header */
24
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 */
30
31 #define TRC_TO_CONSOLE 1
32
33 /* Number of boards we support at once. */
34 #define MAXBOARDS       20
35 #define MAXPORTS        8
36 #define MAXTTYNAMELEN   200
37
38 /* Serial port types */
39 #define DGNC_SERIAL             0
40 #define DGNC_PRINT              1
41
42 #define SERIAL_TYPE_NORMAL      1
43
44 #define PORT_NUM(dev)   ((dev) & 0x7f)
45 #define IS_PRINT(dev)   (((dev) & 0xff) >= 0x80)
46
47 /* MAX number of stop characters sent when our read queue is getting full */
48 #define MAX_STOPS_SENT 5
49
50 /* 4 extra for alignment play space */
51 #define WRITEBUFLEN             ((4096) + 4)
52
53 #define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
54
55 #ifndef _POSIX_VDISABLE
56 #define   _POSIX_VDISABLE '\0'
57 #endif
58
59 /* All the possible states the driver can be while being loaded. */
60 enum {
61         DRIVER_INITIALIZED = 0,
62         DRIVER_READY
63 };
64
65 /* All the possible states the board can be while booting up. */
66 enum {
67         BOARD_FAILED = 0,
68         BOARD_FOUND,
69         BOARD_READY
70 };
71
72 struct dgnc_board;
73 struct channel_t;
74
75 /**
76  * struct board_ops - Per board operations.
77  */
78 struct board_ops {
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);
97 };
98
99 /* Device flag definitions for bd_flags. */
100
101 #define BD_IS_PCI_EXPRESS     0x0001      /* Is a PCI Express board */
102
103 /**
104  * struct dgnc_board - Per board information.
105  * @boardnum: Board number (0 - 32).
106  *
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
145  */
146 struct dgnc_board {
147         int             boardnum;
148
149         int             type;
150         char            *name;
151         struct pci_dev  *pdev;
152         unsigned long   bd_flags;
153         u16             vendor;
154         u16             device;
155         u16             subvendor;
156         u16             subdevice;
157         unsigned char   rev;
158         uint            pci_bus;
159         uint            pci_slot;
160         uint            maxports;
161         unsigned char   dvid;
162         unsigned char   vpd[128];
163         unsigned char   serial_num[20];
164
165         /* used to protect the board */
166         spinlock_t      bd_lock;
167
168         /*  Protect poller tasklet and interrupt routine from each other. */
169         spinlock_t      bd_intr_lock;
170
171         uint            state;
172         wait_queue_head_t state_wait;
173
174         struct tasklet_struct helper_tasklet;
175
176         uint            nasync;
177
178         uint            irq;
179
180         ulong           membase;
181         ulong           membase_end;
182
183         u8 __iomem      *re_map_membase;
184
185         ulong           iobase;
186         ulong           iobase_end;
187
188         uint            bd_uart_offset;
189
190         struct channel_t *channels[MAXPORTS];
191
192         struct tty_driver *serial_driver;
193         char            serial_name[200];
194         struct tty_driver *print_driver;
195         char            print_name[200];
196
197         u16             dpatype;
198         u16             dpastatus;
199
200         uint            bd_dividend;
201
202         struct board_ops *bd_ops;
203
204         struct proc_dir_entry *proc_entry_pointer;
205         struct dgnc_proc_entry *dgnc_board_table;
206
207 };
208
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 */
223
224 struct device;
225
226 /**
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.
233  */
234 struct un_t {
235         struct  channel_t *un_ch;
236         ulong   un_time;
237         uint    un_type;
238         uint    un_open_count;
239         struct tty_struct *un_tty;
240         uint    un_flags;
241         wait_queue_head_t un_flags_wait;
242         uint    un_dev;
243         struct device *un_sysfs;
244 };
245
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 */
253
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 */
265
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)
273
274 /**
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.
326  */
327 struct channel_t {
328         struct dgnc_board *ch_bd;
329         struct digi_t   ch_digi;
330         struct un_t     ch_tun;
331         struct un_t     ch_pun;
332
333         spinlock_t      ch_lock; /* provide for serialization */
334         wait_queue_head_t ch_flags_wait;
335
336         uint            ch_portnum;
337         uint            ch_open_count;
338         uint            ch_flags;
339
340         ulong           ch_close_delay;
341
342         ulong           ch_cpstime;
343
344         tcflag_t        ch_c_iflag;
345         tcflag_t        ch_c_cflag;
346         tcflag_t        ch_c_oflag;
347         tcflag_t        ch_c_lflag;
348         unsigned char   ch_stopc;
349         unsigned char   ch_startc;
350
351         uint            ch_old_baud;
352         uint            ch_custom_speed;
353
354         uint            ch_wopen;
355
356         unsigned char   ch_mostat;
357         unsigned char   ch_mistat;
358
359         struct neo_uart_struct __iomem *ch_neo_uart;
360         struct cls_uart_struct __iomem *ch_cls_uart;
361
362         unsigned char   ch_cached_lsr;
363
364         unsigned char   *ch_rqueue;
365         ushort          ch_r_head;
366         ushort          ch_r_tail;
367
368         unsigned char   *ch_equeue;
369         ushort          ch_e_head;
370         ushort          ch_e_tail;
371
372         unsigned char   *ch_wqueue;
373         ushort          ch_w_head;
374         ushort          ch_w_tail;
375
376         ulong           ch_rxcount;
377         ulong           ch_txcount;
378
379         unsigned char   ch_r_tlevel;
380         unsigned char   ch_t_tlevel;
381
382         unsigned char   ch_r_watermark;
383
384         ulong           ch_stop_sending_break;
385         uint            ch_stops_sent;
386
387         ulong           ch_err_parity;
388         ulong           ch_err_frame;
389         ulong           ch_err_break;
390         ulong           ch_err_overrun;
391
392         ulong           ch_xon_sends;
393         ulong           ch_xoff_sends;
394
395         struct proc_dir_entry *proc_entry_pointer;
396         struct dgnc_proc_entry *dgnc_channel_table;
397
398 };
399
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 */
406
407 #endif  /* _DGNC_DRIVER_H */