io_ionsp.h 14 KB

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