dgnc_driver.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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. *
  17. * Driver includes
  18. *
  19. *************************************************************************/
  20. #ifndef __DGNC_DRIVER_H
  21. #define __DGNC_DRIVER_H
  22. #include <linux/types.h>
  23. #include <linux/tty.h>
  24. #include <linux/interrupt.h>
  25. #include "digi.h" /* Digi specific ioctl header */
  26. #include "dgnc_sysfs.h" /* Support for SYSFS */
  27. /*************************************************************************
  28. *
  29. * Driver defines
  30. *
  31. *************************************************************************/
  32. /* Driver identification and error statments */
  33. #define PROCSTR "dgnc" /* /proc entries */
  34. #define DEVSTR "/dev/dg/dgnc" /* /dev entries */
  35. #define DRVSTR "dgnc" /* Driver name string */
  36. #define DG_PART "40002369_F" /* RPM part number */
  37. #define TRC_TO_CONSOLE 1
  38. /* Number of boards we support at once. */
  39. #define MAXBOARDS 20
  40. #define MAXPORTS 8
  41. #define MAXTTYNAMELEN 200
  42. /* Our 3 magic numbers for our board, channel and unit structs */
  43. #define DGNC_BOARD_MAGIC 0x5c6df104
  44. #define DGNC_CHANNEL_MAGIC 0x6c6df104
  45. #define DGNC_UNIT_MAGIC 0x7c6df104
  46. /* Serial port types */
  47. #define DGNC_SERIAL 0
  48. #define DGNC_PRINT 1
  49. #define SERIAL_TYPE_NORMAL 1
  50. #define PORT_NUM(dev) ((dev) & 0x7f)
  51. #define IS_PRINT(dev) (((dev) & 0xff) >= 0x80)
  52. /* MAX number of stop characters we will send
  53. * when our read queue is getting full
  54. */
  55. #define MAX_STOPS_SENT 5
  56. /* 4 extra for alignment play space */
  57. #define WRITEBUFLEN ((4096) + 4)
  58. #define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
  59. /*
  60. * Define a local default termios struct. All ports will be created
  61. * with this termios initially. This is the same structure that is defined
  62. * as the default in tty_io.c with the same settings overridden as in serial.c
  63. *
  64. * In short, this should match the internal serial ports' defaults.
  65. */
  66. #define DEFAULT_IFLAGS (ICRNL | IXON)
  67. #define DEFAULT_OFLAGS (OPOST | ONLCR)
  68. #define DEFAULT_CFLAGS (B9600 | CS8 | CREAD | HUPCL | CLOCAL)
  69. #define DEFAULT_LFLAGS (ISIG | ICANON | ECHO | ECHOE | ECHOK | \
  70. ECHOCTL | ECHOKE | IEXTEN)
  71. #ifndef _POSIX_VDISABLE
  72. #define _POSIX_VDISABLE '\0'
  73. #endif
  74. /*
  75. * All the possible states the driver can be while being loaded.
  76. */
  77. enum {
  78. DRIVER_INITIALIZED = 0,
  79. DRIVER_READY
  80. };
  81. /*
  82. * All the possible states the board can be while booting up.
  83. */
  84. enum {
  85. BOARD_FAILED = 0,
  86. BOARD_FOUND,
  87. BOARD_READY
  88. };
  89. /*************************************************************************
  90. *
  91. * Structures and closely related defines.
  92. *
  93. *************************************************************************/
  94. struct dgnc_board;
  95. struct channel_t;
  96. /************************************************************************
  97. * Per board operations structure *
  98. ************************************************************************/
  99. struct board_ops {
  100. void (*tasklet)(unsigned long data);
  101. irqreturn_t (*intr)(int irq, void *voidbrd);
  102. void (*uart_init)(struct channel_t *ch);
  103. void (*uart_off)(struct channel_t *ch);
  104. int (*drain)(struct tty_struct *tty, uint seconds);
  105. void (*param)(struct tty_struct *tty);
  106. void (*vpd)(struct dgnc_board *brd);
  107. void (*assert_modem_signals)(struct channel_t *ch);
  108. void (*flush_uart_write)(struct channel_t *ch);
  109. void (*flush_uart_read)(struct channel_t *ch);
  110. void (*disable_receiver)(struct channel_t *ch);
  111. void (*enable_receiver)(struct channel_t *ch);
  112. void (*send_break)(struct channel_t *ch, int);
  113. void (*send_start_character)(struct channel_t *ch);
  114. void (*send_stop_character)(struct channel_t *ch);
  115. void (*copy_data_from_queue_to_uart)(struct channel_t *ch);
  116. uint (*get_uart_bytes_left)(struct channel_t *ch);
  117. void (*send_immediate_char)(struct channel_t *ch, unsigned char);
  118. };
  119. /************************************************************************
  120. * Device flag definitions for bd_flags.
  121. ************************************************************************/
  122. #define BD_IS_PCI_EXPRESS 0x0001 /* Is a PCI Express board */
  123. /*
  124. * Per-board information
  125. */
  126. struct dgnc_board {
  127. int magic; /* Board Magic number. */
  128. int boardnum; /* Board number: 0-32 */
  129. int type; /* Type of board */
  130. char *name; /* Product Name */
  131. struct pci_dev *pdev; /* Pointer to the pci_dev struct */
  132. unsigned long bd_flags; /* Board flags */
  133. u16 vendor; /* PCI vendor ID */
  134. u16 device; /* PCI device ID */
  135. u16 subvendor; /* PCI subsystem vendor ID */
  136. u16 subdevice; /* PCI subsystem device ID */
  137. unsigned char rev; /* PCI revision ID */
  138. uint pci_bus; /* PCI bus value */
  139. uint pci_slot; /* PCI slot value */
  140. uint maxports; /* MAX ports this board can handle */
  141. unsigned char dvid; /* Board specific device id */
  142. unsigned char vpd[128]; /* VPD of board, if found */
  143. unsigned char serial_num[20]; /* Serial number of board,
  144. * if found in VPD
  145. */
  146. spinlock_t bd_lock; /* Used to protect board */
  147. spinlock_t bd_intr_lock; /* Used to protect the poller tasklet
  148. * and the interrupt routine from each
  149. * other.
  150. */
  151. uint state; /* State of card. */
  152. wait_queue_head_t state_wait; /* Place to sleep on for state change */
  153. struct tasklet_struct helper_tasklet; /* Poll helper tasklet */
  154. uint nasync; /* Number of ports on card */
  155. uint irq; /* Interrupt request number */
  156. ulong intr_count; /* Count of interrupts */
  157. ulong intr_modem; /* Count of interrupts */
  158. ulong intr_tx; /* Count of interrupts */
  159. ulong intr_rx; /* Count of interrupts */
  160. ulong membase; /* Start of base memory of the card */
  161. ulong membase_end; /* End of base memory of the card */
  162. u8 __iomem *re_map_membase; /* Remapped memory of the card */
  163. ulong iobase; /* Start of io base of the card */
  164. ulong iobase_end; /* End of io base of the card */
  165. uint bd_uart_offset; /* Space between each UART */
  166. struct channel_t *channels[MAXPORTS]; /* array of pointers
  167. * to our channels.
  168. */
  169. struct tty_driver SerialDriver;
  170. char SerialName[200];
  171. struct tty_driver PrintDriver;
  172. char PrintName[200];
  173. bool dgnc_Major_Serial_Registered;
  174. bool dgnc_Major_TransparentPrint_Registered;
  175. uint dgnc_Serial_Major;
  176. uint dgnc_TransparentPrint_Major;
  177. uint TtyRefCnt;
  178. u16 dpatype; /* The board "type",
  179. * as defined by DPA
  180. */
  181. u16 dpastatus; /* The board "status",
  182. * as defined by DPA
  183. */
  184. /*
  185. * Mgmt data.
  186. */
  187. char *msgbuf_head;
  188. char *msgbuf;
  189. uint bd_dividend; /* Board/UARTs specific dividend */
  190. struct board_ops *bd_ops;
  191. /* /proc/<board> entries */
  192. struct proc_dir_entry *proc_entry_pointer;
  193. struct dgnc_proc_entry *dgnc_board_table;
  194. };
  195. /************************************************************************
  196. * Unit flag definitions for un_flags.
  197. ************************************************************************/
  198. #define UN_ISOPEN 0x0001 /* Device is open */
  199. #define UN_CLOSING 0x0002 /* Line is being closed */
  200. #define UN_IMM 0x0004 /* Service immediately */
  201. #define UN_BUSY 0x0008 /* Some work this channel */
  202. #define UN_BREAKI 0x0010 /* Input break received */
  203. #define UN_PWAIT 0x0020 /* Printer waiting for terminal */
  204. #define UN_TIME 0x0040 /* Waiting on time */
  205. #define UN_EMPTY 0x0080 /* Waiting output queue empty */
  206. #define UN_LOW 0x0100 /* Waiting output low water mark*/
  207. #define UN_EXCL_OPEN 0x0200 /* Open for exclusive use */
  208. #define UN_WOPEN 0x0400 /* Device waiting for open */
  209. #define UN_WIOCTL 0x0800 /* Device waiting for open */
  210. #define UN_HANGUP 0x8000 /* Carrier lost */
  211. struct device;
  212. /************************************************************************
  213. * Structure for terminal or printer unit.
  214. ************************************************************************/
  215. struct un_t {
  216. int magic; /* Unit Magic Number. */
  217. struct channel_t *un_ch;
  218. ulong un_time;
  219. uint un_type;
  220. uint un_open_count; /* Counter of opens to port */
  221. struct tty_struct *un_tty;/* Pointer to unit tty structure */
  222. uint un_flags; /* Unit flags */
  223. wait_queue_head_t un_flags_wait; /* Place to sleep to wait on unit */
  224. uint un_dev; /* Minor device number */
  225. struct device *un_sysfs;
  226. };
  227. /************************************************************************
  228. * Device flag definitions for ch_flags.
  229. ************************************************************************/
  230. #define CH_PRON 0x0001 /* Printer on string */
  231. #define CH_STOP 0x0002 /* Output is stopped */
  232. #define CH_STOPI 0x0004 /* Input is stopped */
  233. #define CH_CD 0x0008 /* Carrier is present */
  234. #define CH_FCAR 0x0010 /* Carrier forced on */
  235. #define CH_HANGUP 0x0020 /* Hangup received */
  236. #define CH_RECEIVER_OFF 0x0040 /* Receiver is off */
  237. #define CH_OPENING 0x0080 /* Port in fragile open state */
  238. #define CH_CLOSING 0x0100 /* Port in fragile close state */
  239. #define CH_FIFO_ENABLED 0x0200 /* Port has FIFOs enabled */
  240. #define CH_TX_FIFO_EMPTY 0x0400 /* TX Fifo is completely empty */
  241. #define CH_TX_FIFO_LWM 0x0800 /* TX Fifo is below Low Water */
  242. #define CH_BREAK_SENDING 0x1000 /* Break is being sent */
  243. #define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */
  244. #define CH_BAUD0 0x08000 /* Used for checking B0 transitions */
  245. #define CH_FORCED_STOP 0x20000 /* Output is forcibly stopped */
  246. #define CH_FORCED_STOPI 0x40000 /* Input is forcibly stopped */
  247. /* Our Read/Error/Write queue sizes */
  248. #define RQUEUEMASK 0x1FFF /* 8 K - 1 */
  249. #define EQUEUEMASK 0x1FFF /* 8 K - 1 */
  250. #define WQUEUEMASK 0x0FFF /* 4 K - 1 */
  251. #define RQUEUESIZE (RQUEUEMASK + 1)
  252. #define EQUEUESIZE RQUEUESIZE
  253. #define WQUEUESIZE (WQUEUEMASK + 1)
  254. /************************************************************************
  255. * Channel information structure.
  256. ************************************************************************/
  257. struct channel_t {
  258. int magic; /* Channel Magic Number */
  259. struct dgnc_board *ch_bd; /* Board structure pointer */
  260. struct digi_t ch_digi; /* Transparent Print structure */
  261. struct un_t ch_tun; /* Terminal unit info */
  262. struct un_t ch_pun; /* Printer unit info */
  263. spinlock_t ch_lock; /* provide for serialization */
  264. wait_queue_head_t ch_flags_wait;
  265. uint ch_portnum; /* Port number, 0 offset. */
  266. uint ch_open_count; /* open count */
  267. uint ch_flags; /* Channel flags */
  268. ulong ch_close_delay; /* How long we should
  269. * drop RTS/DTR for
  270. */
  271. ulong ch_cpstime; /* Time for CPS calculations */
  272. tcflag_t ch_c_iflag; /* channel iflags */
  273. tcflag_t ch_c_cflag; /* channel cflags */
  274. tcflag_t ch_c_oflag; /* channel oflags */
  275. tcflag_t ch_c_lflag; /* channel lflags */
  276. unsigned char ch_stopc; /* Stop character */
  277. unsigned char ch_startc; /* Start character */
  278. uint ch_old_baud; /* Cache of the current baud */
  279. uint ch_custom_speed;/* Custom baud, if set */
  280. uint ch_wopen; /* Waiting for open process cnt */
  281. unsigned char ch_mostat; /* FEP output modem status */
  282. unsigned char ch_mistat; /* FEP input modem status */
  283. struct neo_uart_struct __iomem *ch_neo_uart; /* Pointer to the
  284. * "mapped" UART struct
  285. */
  286. struct cls_uart_struct __iomem *ch_cls_uart; /* Pointer to the
  287. * "mapped" UART struct
  288. */
  289. unsigned char ch_cached_lsr; /* Cached value of the LSR register */
  290. unsigned char *ch_rqueue; /* Our read queue buffer - malloc'ed */
  291. ushort ch_r_head; /* Head location of the read queue */
  292. ushort ch_r_tail; /* Tail location of the read queue */
  293. unsigned char *ch_equeue; /* Our error queue buffer - malloc'ed */
  294. ushort ch_e_head; /* Head location of the error queue */
  295. ushort ch_e_tail; /* Tail location of the error queue */
  296. unsigned char *ch_wqueue; /* Our write queue buffer - malloc'ed */
  297. ushort ch_w_head; /* Head location of the write queue */
  298. ushort ch_w_tail; /* Tail location of the write queue */
  299. ulong ch_rxcount; /* total of data received so far */
  300. ulong ch_txcount; /* total of data transmitted so far */
  301. unsigned char ch_r_tlevel; /* Receive Trigger level */
  302. unsigned char ch_t_tlevel; /* Transmit Trigger level */
  303. unsigned char ch_r_watermark; /* Receive Watermark */
  304. ulong ch_stop_sending_break; /* Time we should STOP
  305. * sending a break
  306. */
  307. uint ch_stops_sent; /* How many times I have sent a stop
  308. * character to try to stop the other
  309. * guy sending.
  310. */
  311. ulong ch_err_parity; /* Count of parity errors on channel */
  312. ulong ch_err_frame; /* Count of framing errors on channel */
  313. ulong ch_err_break; /* Count of breaks on channel */
  314. ulong ch_err_overrun; /* Count of overruns on channel */
  315. ulong ch_xon_sends; /* Count of xons transmitted */
  316. ulong ch_xoff_sends; /* Count of xoffs transmitted */
  317. ulong ch_intr_modem; /* Count of interrupts */
  318. ulong ch_intr_tx; /* Count of interrupts */
  319. ulong ch_intr_rx; /* Count of interrupts */
  320. /* /proc/<board>/<channel> entries */
  321. struct proc_dir_entry *proc_entry_pointer;
  322. struct dgnc_proc_entry *dgnc_channel_table;
  323. };
  324. /*
  325. * Our Global Variables.
  326. */
  327. extern uint dgnc_Major; /* Our driver/mgmt major */
  328. extern int dgnc_poll_tick; /* Poll interval - 20 ms */
  329. extern spinlock_t dgnc_global_lock; /* Driver global spinlock */
  330. extern spinlock_t dgnc_poll_lock; /* Poll scheduling lock */
  331. extern uint dgnc_NumBoards; /* Total number of boards */
  332. extern struct dgnc_board *dgnc_Board[MAXBOARDS]; /* Array of board
  333. * structs
  334. */
  335. #endif