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