io_ionsp.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /************************************************************************
  2. *
  3. * IONSP.H Definitions for I/O Networks Serial Protocol
  4. *
  5. * Copyright (C) 1997-1998 Inside Out Networks, Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * These definitions are used by both kernel-mode driver and the
  13. * peripheral firmware and MUST be kept in sync.
  14. *
  15. ************************************************************************/
  16. /************************************************************************
  17. The data to and from all ports on the peripheral is multiplexed
  18. through a single endpoint pair (EP1 since it supports 64-byte
  19. MaxPacketSize). Therefore, the data, commands, and status for
  20. each port must be preceded by a short header identifying the
  21. destination port. The header also identifies the bytes that follow
  22. as data or as command/status info.
  23. Header format, first byte:
  24. CLLLLPPP
  25. --------
  26. | | |------ Port Number: 0-7
  27. | |--------- Length: MSB bits of length
  28. |----------- Data/Command: 0 = Data header
  29. 1 = Cmd / Status (Cmd if OUT, Status if IN)
  30. This gives 2 possible formats:
  31. Data header: 0LLLLPPP LLLLLLLL
  32. ============
  33. Where (LLLL,LLLLLLL) is 12-bit length of data that follows for
  34. port number (PPP). The length is 0-based (0-FFF means 0-4095
  35. bytes). The ~4K limit allows the host driver (which deals in
  36. transfer requests instead of individual packets) to write a
  37. large chunk of data in a single request. Note, however, that
  38. the length must always be <= the current TxCredits for a given
  39. port due to buffering limitations on the peripheral.
  40. Cmd/Status header: 1ccccPPP [ CCCCCCCC, Params ]...
  41. ==================
  42. Where (cccc) or (cccc,CCCCCCCC) is the cmd or status identifier.
  43. Frequently-used values are encoded as (cccc), longer ones using
  44. (cccc,CCCCCCCC). Subsequent bytes are optional parameters and are
  45. specific to the cmd or status code. This may include a length
  46. for command and status codes that need variable-length parameters.
  47. In addition, we use another interrupt pipe (endpoint) which the host polls
  48. periodically for flow control information. The peripheral, when there has
  49. been a change, sends the following 10-byte packet:
  50. RRRRRRRRRRRRRRRR
  51. T0T0T0T0T0T0T0T0
  52. T1T1T1T1T1T1T1T1
  53. T2T2T2T2T2T2T2T2
  54. T3T3T3T3T3T3T3T3
  55. The first field is the 16-bit RxBytesAvail field, which indicates the
  56. number of bytes which may be read by the host from EP1. This is necessary:
  57. (a) because OSR2.1 has a bug which causes data loss if the peripheral returns
  58. fewer bytes than the host expects to read, and (b) because, on Microsoft
  59. platforms at least, an outstanding read posted on EP1 consumes about 35% of
  60. the CPU just polling the device for data.
  61. The next 4 fields are the 16-bit TxCredits for each port, which indicate how
  62. many bytes the host is allowed to send on EP1 for transmit to a given port.
  63. After an OPEN_PORT command, the Edgeport sends the initial TxCredits for that
  64. port.
  65. All 16-bit fields are sent in little-endian (Intel) format.
  66. ************************************************************************/
  67. //
  68. // Define format of InterruptStatus packet returned from the
  69. // Interrupt pipe
  70. //
  71. struct int_status_pkt {
  72. __u16 RxBytesAvail; // Additional bytes available to
  73. // be read from Bulk IN pipe
  74. __u16 TxCredits[MAX_RS232_PORTS]; // Additional space available in
  75. // given port's TxBuffer
  76. };
  77. #define GET_INT_STATUS_SIZE(NumPorts) (sizeof(__u16) + (sizeof(__u16) * (NumPorts)))
  78. //
  79. // Define cmd/status header values and macros to extract them.
  80. //
  81. // Data: 0LLLLPPP LLLLLLLL
  82. // Cmd/Stat: 1ccccPPP CCCCCCCC
  83. #define IOSP_DATA_HDR_SIZE 2
  84. #define IOSP_CMD_HDR_SIZE 2
  85. #define IOSP_MAX_DATA_LENGTH 0x0FFF // 12 bits -> 4K
  86. #define IOSP_PORT_MASK 0x07 // Mask to isolate port number
  87. #define IOSP_CMD_STAT_BIT 0x80 // If set, this is command/status header
  88. #define IS_CMD_STAT_HDR(Byte1) ((Byte1) & IOSP_CMD_STAT_BIT)
  89. #define IS_DATA_HDR(Byte1) (!IS_CMD_STAT_HDR(Byte1))
  90. #define IOSP_GET_HDR_PORT(Byte1) ((__u8) ((Byte1) & IOSP_PORT_MASK))
  91. #define IOSP_GET_HDR_DATA_LEN(Byte1, Byte2) ((__u16) (((__u16)((Byte1) & 0x78)) << 5) | (Byte2))
  92. #define IOSP_GET_STATUS_CODE(Byte1) ((__u8) (((Byte1) & 0x78) >> 3))
  93. //
  94. // These macros build the 1st and 2nd bytes for a data header
  95. //
  96. #define IOSP_BUILD_DATA_HDR1(Port, Len) ((__u8) (((Port) | ((__u8) (((__u16) (Len)) >> 5) & 0x78))))
  97. #define IOSP_BUILD_DATA_HDR2(Port, Len) ((__u8) (Len))
  98. //
  99. // These macros build the 1st and 2nd bytes for a command header
  100. //
  101. #define IOSP_BUILD_CMD_HDR1(Port, Cmd) ((__u8) (IOSP_CMD_STAT_BIT | (Port) | ((__u8) ((Cmd) << 3))))
  102. //--------------------------------------------------------------
  103. //
  104. // Define values for commands and command parameters
  105. // (sent from Host to Edgeport)
  106. //
  107. // 1ccccPPP P1P1P1P1 [ P2P2P2P2P2 ]...
  108. //
  109. // cccc: 00-07 2-byte commands. Write UART register 0-7 with
  110. // value in P1. See 16650.H for definitions of
  111. // UART register numbers and contents.
  112. //
  113. // 08-0B 3-byte commands: ==== P1 ==== ==== P2 ====
  114. // 08 available for expansion
  115. // 09 1-param commands Command Code Param
  116. // 0A available for expansion
  117. // 0B available for expansion
  118. //
  119. // 0C-0D 4-byte commands. P1 = extended cmd and P2,P3 = params
  120. // Currently unimplemented.
  121. //
  122. // 0E-0F N-byte commands: P1 = num bytes after P1 (ie, TotalLen - 2)
  123. // P2 = extended cmd, P3..Pn = parameters.
  124. // Currently unimplemented.
  125. //
  126. #define IOSP_WRITE_UART_REG(n) ((n) & 0x07) // UartReg[ n ] := P1
  127. // Register numbers and contents
  128. // defined in 16554.H.
  129. // 0x08 // Available for expansion.
  130. #define IOSP_EXT_CMD 0x09 // P1 = Command code (defined below)
  131. // P2 = Parameter
  132. //
  133. // Extended Command values, used with IOSP_EXT_CMD, may
  134. // or may not use parameter P2.
  135. //
  136. #define IOSP_CMD_OPEN_PORT 0x00 // Enable ints, init UART. (NO PARAM)
  137. #define IOSP_CMD_CLOSE_PORT 0x01 // Disable ints, flush buffers. (NO PARAM)
  138. #define IOSP_CMD_CHASE_PORT 0x02 // Wait for Edgeport TX buffers to empty. (NO PARAM)
  139. #define IOSP_CMD_SET_RX_FLOW 0x03 // Set Rx Flow Control in Edgeport
  140. #define IOSP_CMD_SET_TX_FLOW 0x04 // Set Tx Flow Control in Edgeport
  141. #define IOSP_CMD_SET_XON_CHAR 0x05 // Set XON Character in Edgeport
  142. #define IOSP_CMD_SET_XOFF_CHAR 0x06 // Set XOFF Character in Edgeport
  143. #define IOSP_CMD_RX_CHECK_REQ 0x07 // Request Edgeport to insert a Checkpoint into
  144. // the receive data stream (Parameter = 1 byte sequence number)
  145. #define IOSP_CMD_SET_BREAK 0x08 // Turn on the BREAK (LCR bit 6)
  146. #define IOSP_CMD_CLEAR_BREAK 0x09 // Turn off the BREAK (LCR bit 6)
  147. //
  148. // Define macros to simplify building of IOSP cmds
  149. //
  150. #define MAKE_CMD_WRITE_REG(ppBuf, pLen, Port, Reg, Val) \
  151. do { \
  152. (*(ppBuf))[0] = IOSP_BUILD_CMD_HDR1((Port), \
  153. IOSP_WRITE_UART_REG(Reg)); \
  154. (*(ppBuf))[1] = (Val); \
  155. \
  156. *ppBuf += 2; \
  157. *pLen += 2; \
  158. } while (0)
  159. #define MAKE_CMD_EXT_CMD(ppBuf, pLen, Port, ExtCmd, Param) \
  160. do { \
  161. (*(ppBuf))[0] = IOSP_BUILD_CMD_HDR1((Port), IOSP_EXT_CMD); \
  162. (*(ppBuf))[1] = (ExtCmd); \
  163. (*(ppBuf))[2] = (Param); \
  164. \
  165. *ppBuf += 3; \
  166. *pLen += 3; \
  167. } while (0)
  168. //--------------------------------------------------------------
  169. //
  170. // Define format of flow control commands
  171. // (sent from Host to Edgeport)
  172. //
  173. // 11001PPP FlowCmd FlowTypes
  174. //
  175. // Note that the 'FlowTypes' parameter is a bit mask; that is,
  176. // more than one flow control type can be active at the same time.
  177. // FlowTypes = 0 means 'no flow control'.
  178. //
  179. //
  180. // IOSP_CMD_SET_RX_FLOW
  181. //
  182. // Tells Edgeport how it can stop incoming UART data
  183. //
  184. // Example for Port 0
  185. // P0 = 11001000
  186. // P1 = IOSP_CMD_SET_RX_FLOW
  187. // P2 = Bit mask as follows:
  188. #define IOSP_RX_FLOW_RTS 0x01 // Edgeport drops RTS to stop incoming data
  189. #define IOSP_RX_FLOW_DTR 0x02 // Edgeport drops DTR to stop incoming data
  190. #define IOSP_RX_FLOW_DSR_SENSITIVITY 0x04 // Ignores Rx data unless DSR high
  191. // Not currently implemented by firmware.
  192. #define IOSP_RX_FLOW_XON_XOFF 0x08 // Edgeport sends XOFF char to stop incoming data.
  193. // Host must have previously programmed the
  194. // XON/XOFF values with SET_XON/SET_XOFF
  195. // before enabling this bit.
  196. //
  197. // IOSP_CMD_SET_TX_FLOW
  198. //
  199. // Tells Edgeport what signal(s) will stop it from transmitting UART data
  200. //
  201. // Example for Port 0
  202. // P0 = 11001000
  203. // P1 = IOSP_CMD_SET_TX_FLOW
  204. // P2 = Bit mask as follows:
  205. #define IOSP_TX_FLOW_CTS 0x01 // Edgeport stops Tx if CTS low
  206. #define IOSP_TX_FLOW_DSR 0x02 // Edgeport stops Tx if DSR low
  207. #define IOSP_TX_FLOW_DCD 0x04 // Edgeport stops Tx if DCD low
  208. #define IOSP_TX_FLOW_XON_XOFF 0x08 // Edgeport stops Tx upon receiving XOFF char.
  209. // Host must have previously programmed the
  210. // XON/XOFF values with SET_XON/SET_XOFF
  211. // before enabling this bit.
  212. #define IOSP_TX_FLOW_XOFF_CONTINUE 0x10 // If not set, Edgeport stops Tx when
  213. // sending XOFF in order to fix broken
  214. // systems that interpret the next
  215. // received char as XON.
  216. // If set, Edgeport continues Tx
  217. // normally after transmitting XOFF.
  218. // Not currently implemented by firmware.
  219. #define IOSP_TX_TOGGLE_RTS 0x20 // Edgeport drives RTS as a true half-duplex
  220. // Request-to-Send signal: it is raised before
  221. // beginning transmission and lowered after
  222. // the last Tx char leaves the UART.
  223. // Not currently implemented by firmware.
  224. //
  225. // IOSP_CMD_SET_XON_CHAR
  226. //
  227. // Sets the character which Edgeport transmits/interprets as XON.
  228. // Note: This command MUST be sent before sending a SET_RX_FLOW or
  229. // SET_TX_FLOW with the XON_XOFF bit set.
  230. //
  231. // Example for Port 0
  232. // P0 = 11001000
  233. // P1 = IOSP_CMD_SET_XON_CHAR
  234. // P2 = 0x11
  235. //
  236. // IOSP_CMD_SET_XOFF_CHAR
  237. //
  238. // Sets the character which Edgeport transmits/interprets as XOFF.
  239. // Note: This command must be sent before sending a SET_RX_FLOW or
  240. // SET_TX_FLOW with the XON_XOFF bit set.
  241. //
  242. // Example for Port 0
  243. // P0 = 11001000
  244. // P1 = IOSP_CMD_SET_XOFF_CHAR
  245. // P2 = 0x13
  246. //
  247. // IOSP_CMD_RX_CHECK_REQ
  248. //
  249. // This command is used to assist in the implementation of the
  250. // IOCTL_SERIAL_PURGE Windows IOCTL.
  251. // This IOSP command tries to place a marker at the end of the RX
  252. // queue in the Edgeport. If the Edgeport RX queue is full then
  253. // the Check will be discarded.
  254. // It is up to the device driver to timeout waiting for the
  255. // RX_CHECK_RSP. If a RX_CHECK_RSP is received, the driver is
  256. // sure that all data has been received from the edgeport and
  257. // may now purge any internal RX buffers.
  258. // Note tat the sequence numbers may be used to detect lost
  259. // CHECK_REQs.
  260. // Example for Port 0
  261. // P0 = 11001000
  262. // P1 = IOSP_CMD_RX_CHECK_REQ
  263. // P2 = Sequence number
  264. // Response will be:
  265. // P1 = IOSP_EXT_RX_CHECK_RSP
  266. // P2 = Request Sequence number
  267. //--------------------------------------------------------------
  268. //
  269. // Define values for status and status parameters
  270. // (received by Host from Edgeport)
  271. //
  272. // 1ssssPPP P1P1P1P1 [ P2P2P2P2P2 ]...
  273. //
  274. // ssss: 00-07 2-byte status. ssss identifies which UART register
  275. // has changed value, and the new value is in P1.
  276. // Note that the ssss values do not correspond to the
  277. // 16554 register numbers given in 16554.H. Instead,
  278. // see below for definitions of the ssss numbers
  279. // used in this status message.
  280. //
  281. // 08-0B 3-byte status: ==== P1 ==== ==== P2 ====
  282. // 08 LSR_DATA: New LSR Errored byte
  283. // 09 1-param responses Response Code Param
  284. // 0A OPEN_RSP: InitialMsr TxBufferSize
  285. // 0B available for expansion
  286. //
  287. // 0C-0D 4-byte status. P1 = extended status code and P2,P3 = params
  288. // Not currently implemented.
  289. //
  290. // 0E-0F N-byte status: P1 = num bytes after P1 (ie, TotalLen - 2)
  291. // P2 = extended status, P3..Pn = parameters.
  292. // Not currently implemented.
  293. //
  294. /****************************************************
  295. * SSSS values for 2-byte status messages (0-8)
  296. ****************************************************/
  297. #define IOSP_STATUS_LSR 0x00 // P1 is new value of LSR register.
  298. // Bits defined in 16554.H. Edgeport
  299. // returns this in order to report
  300. // line status errors (overrun,
  301. // parity, framing, break). This form
  302. // is used when a errored receive data
  303. // character was NOT present in the
  304. // UART when the LSR error occurred
  305. // (ie, when LSR bit 0 = 0).
  306. #define IOSP_STATUS_MSR 0x01 // P1 is new value of MSR register.
  307. // Bits defined in 16554.H. Edgeport
  308. // returns this in order to report
  309. // changes in modem status lines
  310. // (CTS, DSR, RI, CD)
  311. //
  312. // 0x02 // Available for future expansion
  313. // 0x03 //
  314. // 0x04 //
  315. // 0x05 //
  316. // 0x06 //
  317. // 0x07 //
  318. /****************************************************
  319. * SSSS values for 3-byte status messages (8-A)
  320. ****************************************************/
  321. #define IOSP_STATUS_LSR_DATA 0x08 // P1 is new value of LSR register (same as STATUS_LSR)
  322. // P2 is errored character read from
  323. // RxFIFO after LSR reported an error.
  324. #define IOSP_EXT_STATUS 0x09 // P1 is status/response code, param in P2.
  325. // Response Codes (P1 values) for 3-byte status messages
  326. #define IOSP_EXT_STATUS_CHASE_RSP 0 // Reply to CHASE_PORT cmd. P2 is outcome:
  327. #define IOSP_EXT_STATUS_CHASE_PASS 0 // P2 = 0: All Tx data drained successfully
  328. #define IOSP_EXT_STATUS_CHASE_FAIL 1 // P2 = 1: Timed out (stuck due to flow
  329. // control from remote device).
  330. #define IOSP_EXT_STATUS_RX_CHECK_RSP 1 // Reply to RX_CHECK cmd. P2 is sequence number
  331. #define IOSP_STATUS_OPEN_RSP 0x0A // Reply to OPEN_PORT cmd.
  332. // P1 is Initial MSR value
  333. // P2 is encoded TxBuffer Size:
  334. // TxBufferSize = (P2 + 1) * 64
  335. // 0x0B // Available for future expansion
  336. #define GET_TX_BUFFER_SIZE(P2) (((P2) + 1) * 64)
  337. /****************************************************
  338. * SSSS values for 4-byte status messages
  339. ****************************************************/
  340. #define IOSP_EXT4_STATUS 0x0C // Extended status code in P1,
  341. // Params in P2, P3
  342. // Currently unimplemented.
  343. // 0x0D // Currently unused, available.
  344. //
  345. // Macros to parse status messages
  346. //
  347. #define IOSP_GET_STATUS_LEN(code) ((code) < 8 ? 2 : ((code) < 0x0A ? 3 : 4))
  348. #define IOSP_STATUS_IS_2BYTE(code) ((code) < 0x08)
  349. #define IOSP_STATUS_IS_3BYTE(code) (((code) >= 0x08) && ((code) <= 0x0B))
  350. #define IOSP_STATUS_IS_4BYTE(code) (((code) >= 0x0C) && ((code) <= 0x0D))