rio_mport_cdev.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
  2. /*
  3. * Copyright (c) 2015-2016, Integrated Device Technology Inc.
  4. * Copyright (c) 2015, Prodrive Technologies
  5. * Copyright (c) 2015, Texas Instruments Incorporated
  6. * Copyright (c) 2015, RapidIO Trade Association
  7. * All rights reserved.
  8. *
  9. * This software is available to you under a choice of one of two licenses.
  10. * You may choose to be licensed under the terms of the GNU General Public
  11. * License(GPL) Version 2, or the BSD-3 Clause license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. *
  23. * 3. Neither the name of the copyright holder nor the names of its contributors
  24. * may be used to endorse or promote products derived from this software without
  25. * specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  31. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  32. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  34. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  35. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  36. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  37. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. */
  39. #ifndef _RIO_MPORT_CDEV_H_
  40. #define _RIO_MPORT_CDEV_H_
  41. #include <linux/ioctl.h>
  42. #include <linux/types.h>
  43. struct rio_mport_maint_io {
  44. __u16 rioid; /* destID of remote device */
  45. __u8 hopcount; /* hopcount to remote device */
  46. __u8 pad0[5];
  47. __u32 offset; /* offset in register space */
  48. __u32 length; /* length in bytes */
  49. __u64 buffer; /* pointer to data buffer */
  50. };
  51. /*
  52. * Definitions for RapidIO data transfers:
  53. * - memory mapped (MAPPED)
  54. * - packet generation from memory (TRANSFER)
  55. */
  56. #define RIO_TRANSFER_MODE_MAPPED (1 << 0)
  57. #define RIO_TRANSFER_MODE_TRANSFER (1 << 1)
  58. #define RIO_CAP_DBL_SEND (1 << 2)
  59. #define RIO_CAP_DBL_RECV (1 << 3)
  60. #define RIO_CAP_PW_SEND (1 << 4)
  61. #define RIO_CAP_PW_RECV (1 << 5)
  62. #define RIO_CAP_MAP_OUTB (1 << 6)
  63. #define RIO_CAP_MAP_INB (1 << 7)
  64. struct rio_mport_properties {
  65. __u16 hdid;
  66. __u8 id; /* Physical port ID */
  67. __u8 index;
  68. __u32 flags;
  69. __u32 sys_size; /* Default addressing size */
  70. __u8 port_ok;
  71. __u8 link_speed;
  72. __u8 link_width;
  73. __u8 pad0;
  74. __u32 dma_max_sge;
  75. __u32 dma_max_size;
  76. __u32 dma_align;
  77. __u32 transfer_mode; /* Default transfer mode */
  78. __u32 cap_sys_size; /* Capable system sizes */
  79. __u32 cap_addr_size; /* Capable addressing sizes */
  80. __u32 cap_transfer_mode; /* Capable transfer modes */
  81. __u32 cap_mport; /* Mport capabilities */
  82. };
  83. /*
  84. * Definitions for RapidIO events;
  85. * - incoming port-writes
  86. * - incoming doorbells
  87. */
  88. #define RIO_DOORBELL (1 << 0)
  89. #define RIO_PORTWRITE (1 << 1)
  90. struct rio_doorbell {
  91. __u16 rioid;
  92. __u16 payload;
  93. };
  94. struct rio_doorbell_filter {
  95. __u16 rioid; /* Use RIO_INVALID_DESTID to match all ids */
  96. __u16 low;
  97. __u16 high;
  98. __u16 pad0;
  99. };
  100. struct rio_portwrite {
  101. __u32 payload[16];
  102. };
  103. struct rio_pw_filter {
  104. __u32 mask;
  105. __u32 low;
  106. __u32 high;
  107. __u32 pad0;
  108. };
  109. /* RapidIO base address for inbound requests set to value defined below
  110. * indicates that no specific RIO-to-local address translation is requested
  111. * and driver should use direct (one-to-one) address mapping.
  112. */
  113. #define RIO_MAP_ANY_ADDR (__u64)(~((__u64) 0))
  114. struct rio_mmap {
  115. __u16 rioid;
  116. __u16 pad0[3];
  117. __u64 rio_addr;
  118. __u64 length;
  119. __u64 handle;
  120. __u64 address;
  121. };
  122. struct rio_dma_mem {
  123. __u64 length; /* length of DMA memory */
  124. __u64 dma_handle; /* handle associated with this memory */
  125. __u64 address;
  126. };
  127. struct rio_event {
  128. __u32 header; /* event type RIO_DOORBELL or RIO_PORTWRITE */
  129. union {
  130. struct rio_doorbell doorbell; /* header for RIO_DOORBELL */
  131. struct rio_portwrite portwrite; /* header for RIO_PORTWRITE */
  132. } u;
  133. __u32 pad0;
  134. };
  135. enum rio_transfer_sync {
  136. RIO_TRANSFER_SYNC, /* synchronous transfer */
  137. RIO_TRANSFER_ASYNC, /* asynchronous transfer */
  138. RIO_TRANSFER_FAF, /* fire-and-forget transfer */
  139. };
  140. enum rio_transfer_dir {
  141. RIO_TRANSFER_DIR_READ, /* Read operation */
  142. RIO_TRANSFER_DIR_WRITE, /* Write operation */
  143. };
  144. /*
  145. * RapidIO data exchange transactions are lists of individual transfers. Each
  146. * transfer exchanges data between two RapidIO devices by remote direct memory
  147. * access and has its own completion code.
  148. *
  149. * The RapidIO specification defines four types of data exchange requests:
  150. * NREAD, NWRITE, SWRITE and NWRITE_R. The RapidIO DMA channel interface allows
  151. * to specify the required type of write operation or combination of them when
  152. * only the last data packet requires response.
  153. *
  154. * NREAD: read up to 256 bytes from remote device memory into local memory
  155. * NWRITE: write up to 256 bytes from local memory to remote device memory
  156. * without confirmation
  157. * SWRITE: as NWRITE, but all addresses and payloads must be 64-bit aligned
  158. * NWRITE_R: as NWRITE, but expect acknowledgment from remote device.
  159. *
  160. * The default exchange is chosen from NREAD and any of the WRITE modes as the
  161. * driver sees fit. For write requests the user can explicitly choose between
  162. * any of the write modes for each transaction.
  163. */
  164. enum rio_exchange {
  165. RIO_EXCHANGE_DEFAULT, /* Default method */
  166. RIO_EXCHANGE_NWRITE, /* All packets using NWRITE */
  167. RIO_EXCHANGE_SWRITE, /* All packets using SWRITE */
  168. RIO_EXCHANGE_NWRITE_R, /* Last packet NWRITE_R, others NWRITE */
  169. RIO_EXCHANGE_SWRITE_R, /* Last packet NWRITE_R, others SWRITE */
  170. RIO_EXCHANGE_NWRITE_R_ALL, /* All packets using NWRITE_R */
  171. };
  172. struct rio_transfer_io {
  173. __u64 rio_addr; /* Address in target's RIO mem space */
  174. __u64 loc_addr;
  175. __u64 handle;
  176. __u64 offset; /* Offset in buffer */
  177. __u64 length; /* Length in bytes */
  178. __u16 rioid; /* Target destID */
  179. __u16 method; /* Data exchange method, one of rio_exchange enum */
  180. __u32 completion_code; /* Completion code for this transfer */
  181. };
  182. struct rio_transaction {
  183. __u64 block; /* Pointer to array of <count> transfers */
  184. __u32 count; /* Number of transfers */
  185. __u32 transfer_mode; /* Data transfer mode */
  186. __u16 sync; /* Synch method, one of rio_transfer_sync enum */
  187. __u16 dir; /* Transfer direction, one of rio_transfer_dir enum */
  188. __u32 pad0;
  189. };
  190. struct rio_async_tx_wait {
  191. __u32 token; /* DMA transaction ID token */
  192. __u32 timeout; /* Wait timeout in msec, if 0 use default TO */
  193. };
  194. #define RIO_MAX_DEVNAME_SZ 20
  195. struct rio_rdev_info {
  196. __u16 destid;
  197. __u8 hopcount;
  198. __u8 pad0;
  199. __u32 comptag;
  200. char name[RIO_MAX_DEVNAME_SZ + 1];
  201. };
  202. /* Driver IOCTL codes */
  203. #define RIO_MPORT_DRV_MAGIC 'm'
  204. #define RIO_MPORT_MAINT_HDID_SET \
  205. _IOW(RIO_MPORT_DRV_MAGIC, 1, __u16)
  206. #define RIO_MPORT_MAINT_COMPTAG_SET \
  207. _IOW(RIO_MPORT_DRV_MAGIC, 2, __u32)
  208. #define RIO_MPORT_MAINT_PORT_IDX_GET \
  209. _IOR(RIO_MPORT_DRV_MAGIC, 3, __u32)
  210. #define RIO_MPORT_GET_PROPERTIES \
  211. _IOR(RIO_MPORT_DRV_MAGIC, 4, struct rio_mport_properties)
  212. #define RIO_MPORT_MAINT_READ_LOCAL \
  213. _IOR(RIO_MPORT_DRV_MAGIC, 5, struct rio_mport_maint_io)
  214. #define RIO_MPORT_MAINT_WRITE_LOCAL \
  215. _IOW(RIO_MPORT_DRV_MAGIC, 6, struct rio_mport_maint_io)
  216. #define RIO_MPORT_MAINT_READ_REMOTE \
  217. _IOR(RIO_MPORT_DRV_MAGIC, 7, struct rio_mport_maint_io)
  218. #define RIO_MPORT_MAINT_WRITE_REMOTE \
  219. _IOW(RIO_MPORT_DRV_MAGIC, 8, struct rio_mport_maint_io)
  220. #define RIO_ENABLE_DOORBELL_RANGE \
  221. _IOW(RIO_MPORT_DRV_MAGIC, 9, struct rio_doorbell_filter)
  222. #define RIO_DISABLE_DOORBELL_RANGE \
  223. _IOW(RIO_MPORT_DRV_MAGIC, 10, struct rio_doorbell_filter)
  224. #define RIO_ENABLE_PORTWRITE_RANGE \
  225. _IOW(RIO_MPORT_DRV_MAGIC, 11, struct rio_pw_filter)
  226. #define RIO_DISABLE_PORTWRITE_RANGE \
  227. _IOW(RIO_MPORT_DRV_MAGIC, 12, struct rio_pw_filter)
  228. #define RIO_SET_EVENT_MASK \
  229. _IOW(RIO_MPORT_DRV_MAGIC, 13, __u32)
  230. #define RIO_GET_EVENT_MASK \
  231. _IOR(RIO_MPORT_DRV_MAGIC, 14, __u32)
  232. #define RIO_MAP_OUTBOUND \
  233. _IOWR(RIO_MPORT_DRV_MAGIC, 15, struct rio_mmap)
  234. #define RIO_UNMAP_OUTBOUND \
  235. _IOW(RIO_MPORT_DRV_MAGIC, 16, struct rio_mmap)
  236. #define RIO_MAP_INBOUND \
  237. _IOWR(RIO_MPORT_DRV_MAGIC, 17, struct rio_mmap)
  238. #define RIO_UNMAP_INBOUND \
  239. _IOW(RIO_MPORT_DRV_MAGIC, 18, __u64)
  240. #define RIO_ALLOC_DMA \
  241. _IOWR(RIO_MPORT_DRV_MAGIC, 19, struct rio_dma_mem)
  242. #define RIO_FREE_DMA \
  243. _IOW(RIO_MPORT_DRV_MAGIC, 20, __u64)
  244. #define RIO_TRANSFER \
  245. _IOWR(RIO_MPORT_DRV_MAGIC, 21, struct rio_transaction)
  246. #define RIO_WAIT_FOR_ASYNC \
  247. _IOW(RIO_MPORT_DRV_MAGIC, 22, struct rio_async_tx_wait)
  248. #define RIO_DEV_ADD \
  249. _IOW(RIO_MPORT_DRV_MAGIC, 23, struct rio_rdev_info)
  250. #define RIO_DEV_DEL \
  251. _IOW(RIO_MPORT_DRV_MAGIC, 24, struct rio_rdev_info)
  252. #endif /* _RIO_MPORT_CDEV_H_ */