staging: dgnc: add SPDX identifier.
[linux-block.git] / drivers / staging / dgnc / dgnc_driver.h
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  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  * PURPOSE.  See the GNU General Public License for more details.
15  */
16
17 #ifndef _DGNC_DRIVER_H
18 #define _DGNC_DRIVER_H
19
20 #include <linux/types.h>
21 #include <linux/tty.h>
22 #include <linux/interrupt.h>
23
24 #include "digi.h"               /* Digi specific ioctl header */
25
26 /* Driver identification and error statements */
27 #define PROCSTR         "dgnc"                  /* /proc entries */
28 #define DEVSTR          "/dev/dg/dgnc"          /* /dev entries */
29 #define DRVSTR          "dgnc"                  /* Driver name string */
30 #define DG_PART         "40002369_F"            /* RPM part number */
31
32 #define TRC_TO_CONSOLE 1
33
34 /* Number of boards we support at once. */
35 #define MAXBOARDS       20
36 #define MAXPORTS        8
37 #define MAXTTYNAMELEN   200
38
39 /* Serial port types */
40 #define DGNC_SERIAL             0
41 #define DGNC_PRINT              1
42
43 #define SERIAL_TYPE_NORMAL      1
44
45 #define PORT_NUM(dev)   ((dev) & 0x7f)
46 #define IS_PRINT(dev)   (((dev) & 0xff) >= 0x80)
47
48 /* MAX number of stop characters sent when our read queue is getting full */
49 #define MAX_STOPS_SENT 5
50
51 /* 4 extra for alignment play space */
52 #define WRITEBUFLEN             ((4096) + 4)
53
54 #define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
55
56 #ifndef _POSIX_VDISABLE
57 #define   _POSIX_VDISABLE '\0'
58 #endif
59
60 /* All the possible states the driver can be while being loaded. */
61 enum {
62         DRIVER_INITIALIZED = 0,
63         DRIVER_READY
64 };
65
66 /* All the possible states the board can be while booting up. */
67 enum {
68         BOARD_FAILED = 0,
69         BOARD_FOUND,
70         BOARD_READY
71 };
72
73 struct dgnc_board;
74 struct channel_t;
75
76 /**
77  * struct board_ops - Per board operations.
78  */
79 struct board_ops {
80         void (*tasklet)(unsigned long data);
81         irqreturn_t (*intr)(int irq, void *voidbrd);
82         void (*uart_init)(struct channel_t *ch);
83         void (*uart_off)(struct channel_t *ch);
84         int  (*drain)(struct tty_struct *tty, uint seconds);
85         void (*param)(struct tty_struct *tty);
86         void (*vpd)(struct dgnc_board *brd);
87         void (*assert_modem_signals)(struct channel_t *ch);
88         void (*flush_uart_write)(struct channel_t *ch);
89         void (*flush_uart_read)(struct channel_t *ch);
90         void (*disable_receiver)(struct channel_t *ch);
91         void (*enable_receiver)(struct channel_t *ch);
92         void (*send_break)(struct channel_t *ch, int msec);
93         void (*send_start_character)(struct channel_t *ch);
94         void (*send_stop_character)(struct channel_t *ch);
95         void (*copy_data_from_queue_to_uart)(struct channel_t *ch);
96         uint (*get_uart_bytes_left)(struct channel_t *ch);
97         void (*send_immediate_char)(struct channel_t *ch, unsigned char c);
98 };
99
100 /* Device flag definitions for bd_flags. */
101
102 #define BD_IS_PCI_EXPRESS     0x0001      /* Is a PCI Express board */
103
104 /**
105  * struct dgnc_board - Per board information.
106  * @boardnum: Board number (0 - 32).
107  *
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  */
144 struct dgnc_board {
145         int             boardnum;
146         char            *name;
147         struct pci_dev  *pdev;
148         unsigned long   bd_flags;
149         u16             vendor;
150         u16             device;
151         u16             subvendor;
152         u16             subdevice;
153         unsigned char   rev;
154         uint            pci_bus;
155         uint            pci_slot;
156         uint            maxports;
157         unsigned char   dvid;
158         unsigned char   vpd[128];
159         unsigned char   serial_num[20];
160
161         /* used to protect the board */
162         spinlock_t      bd_lock;
163
164         /*  Protect poller tasklet and interrupt routine from each other. */
165         spinlock_t      bd_intr_lock;
166
167         uint            state;
168         wait_queue_head_t state_wait;
169
170         struct tasklet_struct helper_tasklet;
171
172         uint            nasync;
173
174         uint            irq;
175
176         ulong           membase;
177         ulong           membase_end;
178
179         u8 __iomem      *re_map_membase;
180
181         ulong           iobase;
182         ulong           iobase_end;
183
184         uint            bd_uart_offset;
185
186         struct channel_t *channels[MAXPORTS];
187
188         struct tty_driver *serial_driver;
189         char            serial_name[200];
190         struct tty_driver *print_driver;
191         char            print_name[200];
192
193         u16             dpatype;
194         u16             dpastatus;
195
196         uint            bd_dividend;
197
198         struct board_ops *bd_ops;
199 };
200
201 /* Unit flag definitions for un_flags. */
202 #define UN_ISOPEN       0x0001          /* Device is open */
203 #define UN_CLOSING      0x0002          /* Line is being closed */
204 #define UN_IMM          0x0004          /* Service immediately */
205 #define UN_BUSY         0x0008          /* Some work this channel */
206 #define UN_BREAKI       0x0010          /* Input break received */
207 #define UN_PWAIT        0x0020          /* Printer waiting for terminal */
208 #define UN_TIME         0x0040          /* Waiting on time */
209 #define UN_EMPTY        0x0080          /* Waiting output queue empty */
210 #define UN_LOW          0x0100          /* Waiting output low water mark*/
211 #define UN_EXCL_OPEN    0x0200          /* Open for exclusive use */
212 #define UN_WOPEN        0x0400          /* Device waiting for open */
213 #define UN_WIOCTL       0x0800          /* Device waiting for open */
214 #define UN_HANGUP       0x8000          /* Carrier lost */
215
216 struct device;
217
218 /**
219  * struct un_t - terminal or printer unit
220  * @un_open_count: Counter of opens to port.
221  * @un_tty: Pointer to unit tty structure.
222  * @un_flags: Unit flags.
223  * @un_flags_wait: Place to sleep to wait on unit.
224  * @un_dev: Minor device number.
225  */
226 struct un_t {
227         struct  channel_t *un_ch;
228         uint    un_type;
229         uint    un_open_count;
230         struct tty_struct *un_tty;
231         uint    un_flags;
232         wait_queue_head_t un_flags_wait;
233         uint    un_dev;
234         struct device *un_sysfs;
235 };
236
237 /* Device flag definitions for ch_flags. */
238 #define CH_PRON         0x0001          /* Printer on string */
239 #define CH_STOP         0x0002          /* Output is stopped */
240 #define CH_STOPI        0x0004          /* Input is stopped */
241 #define CH_CD           0x0008          /* Carrier is present */
242 #define CH_FCAR         0x0010          /* Carrier forced on */
243 #define CH_HANGUP       0x0020          /* Hangup received */
244
245 #define CH_RECEIVER_OFF 0x0040          /* Receiver is off */
246 #define CH_OPENING      0x0080          /* Port in fragile open state */
247 #define CH_CLOSING      0x0100          /* Port in fragile close state */
248 #define CH_FIFO_ENABLED 0x0200          /* Port has FIFOs enabled */
249 #define CH_TX_FIFO_EMPTY 0x0400         /* TX Fifo is completely empty */
250 #define CH_TX_FIFO_LWM  0x0800          /* TX Fifo is below Low Water */
251 #define CH_BREAK_SENDING 0x1000         /* Break is being sent */
252 #define CH_LOOPBACK     0x2000          /* Channel is in lookback mode */
253 #define CH_BAUD0        0x08000         /* Used for checking B0 transitions */
254 #define CH_FORCED_STOP  0x20000         /* Output is forcibly stopped */
255 #define CH_FORCED_STOPI 0x40000         /* Input is forcibly stopped */
256
257 /* Our Read/Error/Write queue sizes */
258 #define RQUEUEMASK      0x1FFF          /* 8 K - 1 */
259 #define EQUEUEMASK      0x1FFF          /* 8 K - 1 */
260 #define WQUEUEMASK      0x0FFF          /* 4 K - 1 */
261 #define RQUEUESIZE      (RQUEUEMASK + 1)
262 #define EQUEUESIZE      RQUEUESIZE
263 #define WQUEUESIZE      (WQUEUEMASK + 1)
264
265 /**
266  * struct channel_t - Channel information.
267  * @dgnc_board: Pointer to board structure.
268  * @ch_bd: Transparent print structure.
269  * @ch_tun: Terminal unit information.
270  * @ch_pun: Printer unit information.
271  * @ch_lock: Provide for serialization.
272  * @ch_flags_wait: Channel flags wait queue.
273  * @ch_portnum: Port number, 0 offset.
274  * @ch_open_count: Open count.
275  * @ch_flags: Channel flags.
276  * @ch_close_delay: How long we should drop RTS/DTR for.
277  * @ch_cpstime: Time for CPS calculations.
278  * @ch_c_iflag: Channel iflags.
279  * @ch_c_cflag: Channel cflags.
280  * @ch_c_oflag: Channel oflags.
281  * @ch_c_lflag: Channel lflags.
282  * @ch_stopc: Stop character.
283  * @ch_startc: Start character.
284  * @ch_old_baud: Cache of the current baud rate.
285  * @ch_custom_speed: Custom baud rate, if set.
286  * @ch_wopen: Waiting for open process count.
287  * @ch_mostat: FEP output modem status.
288  * @ch_mistat: FEP input modem status.
289  * @chc_neo_uart: Pointer to the mapped neo UART struct
290  * @ch_cls_uart:  Pointer to the mapped cls UART struct
291  * @ch_cached_lsr: Cached value of the LSR register.
292  * @ch_rqueue: Read queue buffer, malloc'ed.
293  * @ch_r_head: Head location of the read queue.
294  * @ch_r_tail: Tail location of the read queue.
295  * @ch_equeue: Error queue buffer, malloc'ed.
296  * @ch_e_head: Head location of the error queue.
297  * @ch_e_tail: Tail location of the error queue.
298  * @ch_wqueue: Write queue buffer, malloc'ed.
299  * @ch_w_head: Head location of the write queue.
300  * @ch_w_tail: Tail location of the write queue.
301  * @ch_rxcount: Total of data received so far.
302  * @ch_txcount: Total of data transmitted so far.
303  * @ch_r_tlevel: Receive trigger level.
304  * @ch_t_tlevel: Transmit trigger level.
305  * @ch_r_watermark: Receive water mark.
306  * @ch_stop_sending_break: Time we should STOP sending a break.
307  * @ch_stops_sent: How many times I have send a stop character to try
308  *                 to stop the other guy sending.
309  * @ch_err_parity: Count of parity
310  * @ch_err_frame: Count of framing errors on channel.
311  * @ch_err_break: Count of breaks on channel.
312  * @ch_err_overrun: Count of overruns on channel.
313  * @ch_xon_sends: Count of xons transmitted.
314  * @ch_xoff_sends: Count of xoffs transmitted.
315  */
316 struct channel_t {
317         struct dgnc_board *ch_bd;
318         struct digi_t   ch_digi;
319         struct un_t     ch_tun;
320         struct un_t     ch_pun;
321
322         spinlock_t      ch_lock; /* provide for serialization */
323         wait_queue_head_t ch_flags_wait;
324
325         uint            ch_portnum;
326         uint            ch_open_count;
327         uint            ch_flags;
328
329         ulong           ch_close_delay;
330
331         ulong           ch_cpstime;
332
333         tcflag_t        ch_c_iflag;
334         tcflag_t        ch_c_cflag;
335         tcflag_t        ch_c_oflag;
336         tcflag_t        ch_c_lflag;
337         unsigned char   ch_stopc;
338         unsigned char   ch_startc;
339
340         uint            ch_old_baud;
341         uint            ch_custom_speed;
342
343         uint            ch_wopen;
344
345         unsigned char   ch_mostat;
346         unsigned char   ch_mistat;
347
348         struct neo_uart_struct __iomem *ch_neo_uart;
349         struct cls_uart_struct __iomem *ch_cls_uart;
350
351         unsigned char   ch_cached_lsr;
352
353         unsigned char   *ch_rqueue;
354         ushort          ch_r_head;
355         ushort          ch_r_tail;
356
357         unsigned char   *ch_equeue;
358         ushort          ch_e_head;
359         ushort          ch_e_tail;
360
361         unsigned char   *ch_wqueue;
362         ushort          ch_w_head;
363         ushort          ch_w_tail;
364
365         ulong           ch_rxcount;
366         ulong           ch_txcount;
367
368         unsigned char   ch_r_tlevel;
369         unsigned char   ch_t_tlevel;
370
371         unsigned char   ch_r_watermark;
372
373         ulong           ch_stop_sending_break;
374         uint            ch_stops_sent;
375
376         ulong           ch_err_parity;
377         ulong           ch_err_frame;
378         ulong           ch_err_break;
379         ulong           ch_err_overrun;
380
381         ulong           ch_xon_sends;
382         ulong           ch_xoff_sends;
383 };
384
385 extern uint             dgnc_major;             /* Our driver/mgmt major */
386 extern int              dgnc_poll_tick;         /* Poll interval - 20 ms */
387 extern spinlock_t       dgnc_global_lock;       /* Driver global spinlock */
388 extern spinlock_t       dgnc_poll_lock;         /* Poll scheduling lock */
389 extern uint             dgnc_num_boards;        /* Total number of boards */
390 extern struct dgnc_board *dgnc_board[MAXBOARDS];/* Array of boards */
391
392 #endif  /* _DGNC_DRIVER_H */