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