i2lib.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*******************************************************************************
  2. *
  3. * (c) 1998 by Computone Corporation
  4. *
  5. ********************************************************************************
  6. *
  7. *
  8. * PACKAGE: Linux tty Device Driver for IntelliPort II family of multiport
  9. * serial I/O controllers.
  10. *
  11. * DESCRIPTION: Header file for high level library functions
  12. *
  13. *******************************************************************************/
  14. #ifndef I2LIB_H
  15. #define I2LIB_H 1
  16. //------------------------------------------------------------------------------
  17. // I2LIB.H
  18. //
  19. // IntelliPort-II and IntelliPort-IIEX
  20. //
  21. // Defines, structure definitions, and external declarations for i2lib.c
  22. //------------------------------------------------------------------------------
  23. //--------------------------------------
  24. // Mandatory Includes:
  25. //--------------------------------------
  26. #include "ip2types.h"
  27. #include "i2ellis.h"
  28. #include "i2pack.h"
  29. #include "i2cmd.h"
  30. #include <linux/workqueue.h>
  31. //------------------------------------------------------------------------------
  32. // i2ChanStr -- Channel Structure:
  33. // Used to track per-channel information for the library routines using standard
  34. // loadware. Note also, a pointer to an array of these structures is patched
  35. // into the i2eBordStr (see i2ellis.h)
  36. //------------------------------------------------------------------------------
  37. //
  38. // If we make some limits on the maximum block sizes, we can avoid dealing with
  39. // buffer wrap. The wrapping of the buffer is based on where the start of the
  40. // packet is. Then there is always room for the packet contiguously.
  41. //
  42. // Maximum total length of an outgoing data or in-line command block. The limit
  43. // of 36 on data is quite arbitrary and based more on DOS memory limitations
  44. // than the board interface. However, for commands, the maximum packet length is
  45. // MAX_CMD_PACK_SIZE, because the field size for the count is only a few bits
  46. // (see I2PACK.H) in such packets. For data packets, the count field size is not
  47. // the limiting factor. As of this writing, MAX_OBUF_BLOCK < MAX_CMD_PACK_SIZE,
  48. // but be careful if wanting to modify either.
  49. //
  50. #define MAX_OBUF_BLOCK 36
  51. // Another note on maximum block sizes: we are buffering packets here. Data is
  52. // put into the buffer (if there is room) regardless of the credits from the
  53. // board. The board sends new credits whenever it has removed from his buffers a
  54. // number of characters equal to 80% of total buffer size. (Of course, the total
  55. // buffer size is what is reported when the very first set of flow control
  56. // status packets are received from the board. Therefore, to be robust, you must
  57. // always fill the board to at least 80% of the current credit limit, else you
  58. // might not give it enough to trigger a new report. These conditions are
  59. // obtained here so long as the maximum output block size is less than 20% the
  60. // size of the board's output buffers. This is true at present by "coincidence"
  61. // or "infernal knowledge": the board's output buffers are at least 700 bytes
  62. // long (20% = 140 bytes, at least). The 80% figure is "official", so the safest
  63. // strategy might be to trap the first flow control report and guarantee that
  64. // the effective maxObufBlock is the minimum of MAX_OBUF_BLOCK and 20% of first
  65. // reported buffer credit.
  66. //
  67. #define MAX_CBUF_BLOCK 6 // Maximum total length of a bypass command block
  68. #define IBUF_SIZE 512 // character capacity of input buffer per channel
  69. #define OBUF_SIZE 1024// character capacity of output buffer per channel
  70. #define CBUF_SIZE 10 // character capacity of output bypass buffer
  71. typedef struct _i2ChanStr
  72. {
  73. // First, back-pointers so that given a pointer to this structure, you can
  74. // determine the correct board and channel number to reference, (say, when
  75. // issuing commands, etc. (Note, channel number is in infl.hd.i2sChannel.)
  76. int port_index; // Index of port in channel structure array attached
  77. // to board structure.
  78. PTTY pTTY; // Pointer to tty structure for port (OS specific)
  79. USHORT validity; // Indicates whether the given channel has been
  80. // initialized, really exists (or is a missing
  81. // channel, e.g. channel 9 on an 8-port box.)
  82. i2eBordStrPtr pMyBord; // Back-pointer to this channel's board structure
  83. int wopen; // waiting fer carrier
  84. int throttled; // Set if upper layer can take no data
  85. int flags; // Defined in tty.h
  86. PWAITQ open_wait; // Pointer for OS sleep function.
  87. PWAITQ close_wait; // Pointer for OS sleep function.
  88. PWAITQ delta_msr_wait;// Pointer for OS sleep function.
  89. PWAITQ dss_now_wait; // Pointer for OS sleep function.
  90. struct timer_list BookmarkTimer; // Used by i2DrainOutput
  91. wait_queue_head_t pBookmarkWait; // Used by i2DrainOutput
  92. int BaudBase;
  93. int BaudDivisor;
  94. USHORT ClosingDelay;
  95. USHORT ClosingWaitTime;
  96. volatile
  97. flowIn infl; // This structure is initialized as a completely
  98. // formed flow-control command packet, and as such
  99. // has the channel number, also the capacity and
  100. // "as-of" data needed continuously.
  101. USHORT sinceLastFlow; // Counts the number of characters read from input
  102. // buffers, since the last time flow control info
  103. // was sent.
  104. USHORT whenSendFlow; // Determines when new flow control is to be sent to
  105. // the board. Note unlike earlier manifestations of
  106. // the driver, these packets can be sent from
  107. // in-place.
  108. USHORT channelNeeds; // Bit map of important things which must be done
  109. // for this channel. (See bits below )
  110. volatile
  111. flowStat outfl; // Same type of structure is used to hold current
  112. // flow control information used to control our
  113. // output. "asof" is kept updated as data is sent,
  114. // and "room" never goes to zero.
  115. // The incoming ring buffer
  116. // Unlike the outgoing buffers, this holds raw data, not packets. The two
  117. // extra bytes are used to hold the byte-padding when there is room for an
  118. // odd number of bytes before we must wrap.
  119. //
  120. UCHAR Ibuf[IBUF_SIZE + 2];
  121. volatile
  122. USHORT Ibuf_stuff; // Stuffing index
  123. volatile
  124. USHORT Ibuf_strip; // Stripping index
  125. // The outgoing ring-buffer: Holds Data and command packets. N.B., even
  126. // though these are in the channel structure, the channel is also written
  127. // here, the easier to send it to the fifo when ready. HOWEVER, individual
  128. // packets here are NOT padded to even length: the routines for writing
  129. // blocks to the fifo will pad to even byte counts.
  130. //
  131. UCHAR Obuf[OBUF_SIZE+MAX_OBUF_BLOCK+4];
  132. volatile
  133. USHORT Obuf_stuff; // Stuffing index
  134. volatile
  135. USHORT Obuf_strip; // Stripping index
  136. int Obuf_char_count;
  137. // The outgoing bypass-command buffer. Unlike earlier manifestations, the
  138. // flow control packets are sent directly from the structures. As above, the
  139. // channel number is included in the packet, but they are NOT padded to even
  140. // size.
  141. //
  142. UCHAR Cbuf[CBUF_SIZE+MAX_CBUF_BLOCK+2];
  143. volatile
  144. USHORT Cbuf_stuff; // Stuffing index
  145. volatile
  146. USHORT Cbuf_strip; // Stripping index
  147. // The temporary buffer for the Linux tty driver PutChar entry.
  148. //
  149. UCHAR Pbuf[MAX_OBUF_BLOCK - sizeof (i2DataHeader)];
  150. volatile
  151. USHORT Pbuf_stuff; // Stuffing index
  152. // The state of incoming data-set signals
  153. //
  154. USHORT dataSetIn; // Bit-mapped according to below. Also indicates
  155. // whether a break has been detected since last
  156. // inquiry.
  157. // The state of outcoming data-set signals (as far as we can tell!)
  158. //
  159. USHORT dataSetOut; // Bit-mapped according to below.
  160. // Most recent hot-key identifier detected
  161. //
  162. USHORT hotKeyIn; // Hot key as sent by the board, HOT_CLEAR indicates
  163. // no hot key detected since last examined.
  164. // Counter of outstanding requests for bookmarks
  165. //
  166. short bookMarks; // Number of outstanding bookmark requests, (+ive
  167. // whenever a bookmark request if queued up, -ive
  168. // whenever a bookmark is received).
  169. // Misc options
  170. //
  171. USHORT channelOptions; // See below
  172. // To store various incoming special packets
  173. //
  174. debugStat channelStatus;
  175. cntStat channelRcount;
  176. cntStat channelTcount;
  177. failStat channelFail;
  178. // To store the last values for line characteristics we sent to the board.
  179. //
  180. int speed;
  181. int flush_flags;
  182. void (*trace)(unsigned short,unsigned char,unsigned char,unsigned long,...);
  183. /*
  184. * Kernel counters for the 4 input interrupts
  185. */
  186. struct async_icount icount;
  187. /*
  188. * Task queues for processing input packets from the board.
  189. */
  190. struct work_struct tqueue_input;
  191. struct work_struct tqueue_status;
  192. struct work_struct tqueue_hangup;
  193. rwlock_t Ibuf_spinlock;
  194. rwlock_t Obuf_spinlock;
  195. rwlock_t Cbuf_spinlock;
  196. rwlock_t Pbuf_spinlock;
  197. } i2ChanStr, *i2ChanStrPtr;
  198. //---------------------------------------------------
  199. // Manifests and bit-maps for elements in i2ChanStr
  200. //---------------------------------------------------
  201. //
  202. // flush flags
  203. //
  204. #define STARTFL_FLAG 1
  205. #define STOPFL_FLAG 2
  206. // validity
  207. //
  208. #define CHANNEL_MAGIC_BITS 0xff00
  209. #define CHANNEL_MAGIC 0x5300 // (validity & CHANNEL_MAGIC_BITS) ==
  210. // CHANNEL_MAGIC --> structure good
  211. #define CHANNEL_SUPPORT 0x0001 // Indicates channel is supported, exists,
  212. // and passed P.O.S.T.
  213. // channelNeeds
  214. //
  215. #define NEED_FLOW 1 // Indicates flow control has been queued
  216. #define NEED_INLINE 2 // Indicates inline commands or data queued
  217. #define NEED_BYPASS 4 // Indicates bypass commands queued
  218. #define NEED_CREDIT 8 // Indicates would be sending except has not sufficient
  219. // credit. The data is still in the channel structure,
  220. // but the channel is not enqueued in the board
  221. // structure again until there is a credit received from
  222. // the board.
  223. // dataSetIn (Also the bits for i2GetStatus return value)
  224. //
  225. #define I2_DCD 1
  226. #define I2_CTS 2
  227. #define I2_DSR 4
  228. #define I2_RI 8
  229. // dataSetOut (Also the bits for i2GetStatus return value)
  230. //
  231. #define I2_DTR 1
  232. #define I2_RTS 2
  233. // i2GetStatus() can optionally clear these bits
  234. //
  235. #define I2_BRK 0x10 // A break was detected
  236. #define I2_PAR 0x20 // A parity error was received
  237. #define I2_FRA 0x40 // A framing error was received
  238. #define I2_OVR 0x80 // An overrun error was received
  239. // i2GetStatus() automatically clears these bits */
  240. //
  241. #define I2_DDCD 0x100 // DCD changed from its former value
  242. #define I2_DCTS 0x200 // CTS changed from its former value
  243. #define I2_DDSR 0x400 // DSR changed from its former value
  244. #define I2_DRI 0x800 // RI changed from its former value
  245. // hotKeyIn
  246. //
  247. #define HOT_CLEAR 0x1322 // Indicates that no hot-key has been detected
  248. // channelOptions
  249. //
  250. #define CO_NBLOCK_WRITE 1 // Writes don't block waiting for buffer. (Default
  251. // is, they do wait.)
  252. // fcmodes
  253. //
  254. #define I2_OUTFLOW_CTS 0x0001
  255. #define I2_INFLOW_RTS 0x0002
  256. #define I2_INFLOW_DSR 0x0004
  257. #define I2_INFLOW_DTR 0x0008
  258. #define I2_OUTFLOW_DSR 0x0010
  259. #define I2_OUTFLOW_DTR 0x0020
  260. #define I2_OUTFLOW_XON 0x0040
  261. #define I2_OUTFLOW_XANY 0x0080
  262. #define I2_INFLOW_XON 0x0100
  263. #define I2_CRTSCTS (I2_OUTFLOW_CTS|I2_INFLOW_RTS)
  264. #define I2_IXANY_MODE (I2_OUTFLOW_XON|I2_OUTFLOW_XANY)
  265. //-------------------------------------------
  266. // Macros used from user level like functions
  267. //-------------------------------------------
  268. // Macros to set and clear channel options
  269. //
  270. #define i2SetOption(pCh, option) pCh->channelOptions |= option
  271. #define i2ClrOption(pCh, option) pCh->channelOptions &= ~option
  272. // Macro to set fatal-error trap
  273. //
  274. #define i2SetFatalTrap(pB, routine) pB->i2eFatalTrap = routine
  275. //--------------------------------------------
  276. // Declarations and prototypes for i2lib.c
  277. //--------------------------------------------
  278. //
  279. static int i2InitChannels(i2eBordStrPtr, int, i2ChanStrPtr);
  280. static int i2QueueCommands(int, i2ChanStrPtr, int, int, cmdSyntaxPtr,...);
  281. static int i2GetStatus(i2ChanStrPtr, int);
  282. static int i2Input(i2ChanStrPtr);
  283. static int i2InputFlush(i2ChanStrPtr);
  284. static int i2Output(i2ChanStrPtr, const char *, int, int);
  285. static int i2OutputFree(i2ChanStrPtr);
  286. static int i2ServiceBoard(i2eBordStrPtr);
  287. static void i2DrainOutput(i2ChanStrPtr, int);
  288. #ifdef IP2DEBUG_TRACE
  289. void ip2trace(unsigned short,unsigned char,unsigned char,unsigned long,...);
  290. #else
  291. #define ip2trace(a,b,c,d...) do {} while (0)
  292. #endif
  293. // Argument to i2QueueCommands
  294. //
  295. #define C_IN_LINE 1
  296. #define C_BYPASS 0
  297. #endif // I2LIB_H