user_sdma.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */
  2. /*
  3. * Copyright(c) 2020 - Cornelis Networks, Inc.
  4. * Copyright(c) 2015 - 2018 Intel Corporation.
  5. */
  6. #ifndef _HFI1_USER_SDMA_H
  7. #define _HFI1_USER_SDMA_H
  8. #include <linux/device.h>
  9. #include <linux/wait.h>
  10. #include "common.h"
  11. #include "iowait.h"
  12. #include "user_exp_rcv.h"
  13. #include "mmu_rb.h"
  14. /* The maximum number of Data io vectors per message/request */
  15. #define MAX_VECTORS_PER_REQ 8
  16. /*
  17. * Maximum number of packet to send from each message/request
  18. * before moving to the next one.
  19. */
  20. #define MAX_PKTS_PER_QUEUE 16
  21. #define num_pages(x) (1 + ((((x) - 1) & PAGE_MASK) >> PAGE_SHIFT))
  22. #define req_opcode(x) \
  23. (((x) >> HFI1_SDMA_REQ_OPCODE_SHIFT) & HFI1_SDMA_REQ_OPCODE_MASK)
  24. #define req_version(x) \
  25. (((x) >> HFI1_SDMA_REQ_VERSION_SHIFT) & HFI1_SDMA_REQ_OPCODE_MASK)
  26. #define req_iovcnt(x) \
  27. (((x) >> HFI1_SDMA_REQ_IOVCNT_SHIFT) & HFI1_SDMA_REQ_IOVCNT_MASK)
  28. /* Number of BTH.PSN bits used for sequence number in expected rcvs */
  29. #define BTH_SEQ_MASK 0x7ffull
  30. #define AHG_KDETH_INTR_SHIFT 12
  31. #define AHG_KDETH_SH_SHIFT 13
  32. #define AHG_KDETH_ARRAY_SIZE 9
  33. #define PBC2LRH(x) ((((x) & 0xfff) << 2) - 4)
  34. #define LRH2PBC(x) ((((x) >> 2) + 1) & 0xfff)
  35. /**
  36. * Build an SDMA AHG header update descriptor and save it to an array.
  37. * @arr - Array to save the descriptor to.
  38. * @idx - Index of the array at which the descriptor will be saved.
  39. * @array_size - Size of the array arr.
  40. * @dw - Update index into the header in DWs.
  41. * @bit - Start bit.
  42. * @width - Field width.
  43. * @value - 16 bits of immediate data to write into the field.
  44. * Returns -ERANGE if idx is invalid. If successful, returns the next index
  45. * (idx + 1) of the array to be used for the next descriptor.
  46. */
  47. static inline int ahg_header_set(u32 *arr, int idx, size_t array_size,
  48. u8 dw, u8 bit, u8 width, u16 value)
  49. {
  50. if ((size_t)idx >= array_size)
  51. return -ERANGE;
  52. arr[idx++] = sdma_build_ahg_descriptor(value, dw, bit, width);
  53. return idx;
  54. }
  55. /* Tx request flag bits */
  56. #define TXREQ_FLAGS_REQ_ACK BIT(0) /* Set the ACK bit in the header */
  57. #define TXREQ_FLAGS_REQ_DISABLE_SH BIT(1) /* Disable header suppression */
  58. enum pkt_q_sdma_state {
  59. SDMA_PKT_Q_ACTIVE,
  60. SDMA_PKT_Q_DEFERRED,
  61. };
  62. #define SDMA_IOWAIT_TIMEOUT 1000 /* in milliseconds */
  63. #define SDMA_DBG(req, fmt, ...) \
  64. hfi1_cdbg(SDMA, "[%u:%u:%u:%u] " fmt, (req)->pq->dd->unit, \
  65. (req)->pq->ctxt, (req)->pq->subctxt, (req)->info.comp_idx, \
  66. ##__VA_ARGS__)
  67. struct hfi1_user_sdma_pkt_q {
  68. u16 ctxt;
  69. u16 subctxt;
  70. u16 n_max_reqs;
  71. atomic_t n_reqs;
  72. u16 reqidx;
  73. struct hfi1_devdata *dd;
  74. struct kmem_cache *txreq_cache;
  75. struct user_sdma_request *reqs;
  76. unsigned long *req_in_use;
  77. struct iowait busy;
  78. enum pkt_q_sdma_state state;
  79. wait_queue_head_t wait;
  80. unsigned long unpinned;
  81. struct mmu_rb_handler *handler;
  82. atomic_t n_locked;
  83. };
  84. struct hfi1_user_sdma_comp_q {
  85. u16 nentries;
  86. struct hfi1_sdma_comp_entry *comps;
  87. };
  88. struct sdma_mmu_node {
  89. struct mmu_rb_node rb;
  90. struct hfi1_user_sdma_pkt_q *pq;
  91. struct page **pages;
  92. unsigned int npages;
  93. };
  94. struct user_sdma_iovec {
  95. struct list_head list;
  96. struct iovec iov;
  97. /*
  98. * offset into the virtual address space of the vector at
  99. * which we last left off.
  100. */
  101. u64 offset;
  102. };
  103. /* evict operation argument */
  104. struct evict_data {
  105. u32 cleared; /* count evicted so far */
  106. u32 target; /* target count to evict */
  107. };
  108. struct user_sdma_request {
  109. /* This is the original header from user space */
  110. struct hfi1_pkt_header hdr;
  111. /* Read mostly fields */
  112. struct hfi1_user_sdma_pkt_q *pq ____cacheline_aligned_in_smp;
  113. struct hfi1_user_sdma_comp_q *cq;
  114. /*
  115. * Pointer to the SDMA engine for this request.
  116. * Since different request could be on different VLs,
  117. * each request will need it's own engine pointer.
  118. */
  119. struct sdma_engine *sde;
  120. struct sdma_req_info info;
  121. /* TID array values copied from the tid_iov vector */
  122. u32 *tids;
  123. /* total length of the data in the request */
  124. u32 data_len;
  125. /* number of elements copied to the tids array */
  126. u16 n_tids;
  127. /*
  128. * We copy the iovs for this request (based on
  129. * info.iovcnt). These are only the data vectors
  130. */
  131. u8 data_iovs;
  132. s8 ahg_idx;
  133. /* Writeable fields shared with interrupt */
  134. u16 seqcomp ____cacheline_aligned_in_smp;
  135. u16 seqsubmitted;
  136. /* Send side fields */
  137. struct list_head txps ____cacheline_aligned_in_smp;
  138. u16 seqnum;
  139. /*
  140. * KDETH.OFFSET (TID) field
  141. * The offset can cover multiple packets, depending on the
  142. * size of the TID entry.
  143. */
  144. u32 tidoffset;
  145. /*
  146. * KDETH.Offset (Eager) field
  147. * We need to remember the initial value so the headers
  148. * can be updated properly.
  149. */
  150. u32 koffset;
  151. u32 sent;
  152. /* TID index copied from the tid_iov vector */
  153. u16 tididx;
  154. /* progress index moving along the iovs array */
  155. u8 iov_idx;
  156. u8 has_error;
  157. struct user_sdma_iovec iovs[MAX_VECTORS_PER_REQ];
  158. } ____cacheline_aligned_in_smp;
  159. /*
  160. * A single txreq could span up to 3 physical pages when the MTU
  161. * is sufficiently large (> 4K). Each of the IOV pointers also
  162. * needs it's own set of flags so the vector has been handled
  163. * independently of each other.
  164. */
  165. struct user_sdma_txreq {
  166. /* Packet header for the txreq */
  167. struct hfi1_pkt_header hdr;
  168. struct sdma_txreq txreq;
  169. struct list_head list;
  170. struct user_sdma_request *req;
  171. u16 flags;
  172. u16 seqnum;
  173. };
  174. int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt,
  175. struct hfi1_filedata *fd);
  176. int hfi1_user_sdma_free_queues(struct hfi1_filedata *fd,
  177. struct hfi1_ctxtdata *uctxt);
  178. int hfi1_user_sdma_process_request(struct hfi1_filedata *fd,
  179. struct iovec *iovec, unsigned long dim,
  180. unsigned long *count);
  181. static inline struct mm_struct *mm_from_sdma_node(struct sdma_mmu_node *node)
  182. {
  183. return node->rb.handler->mn.mm;
  184. }
  185. #endif /* _HFI1_USER_SDMA_H */