0001
0002
0003
0004
0005
0006 #ifndef _HFI1_USER_SDMA_H
0007 #define _HFI1_USER_SDMA_H
0008
0009 #include <linux/device.h>
0010 #include <linux/wait.h>
0011
0012 #include "common.h"
0013 #include "iowait.h"
0014 #include "user_exp_rcv.h"
0015 #include "mmu_rb.h"
0016
0017
0018 #define MAX_VECTORS_PER_REQ 8
0019
0020
0021
0022
0023 #define MAX_PKTS_PER_QUEUE 16
0024
0025 #define num_pages(x) (1 + ((((x) - 1) & PAGE_MASK) >> PAGE_SHIFT))
0026
0027 #define req_opcode(x) \
0028 (((x) >> HFI1_SDMA_REQ_OPCODE_SHIFT) & HFI1_SDMA_REQ_OPCODE_MASK)
0029 #define req_version(x) \
0030 (((x) >> HFI1_SDMA_REQ_VERSION_SHIFT) & HFI1_SDMA_REQ_OPCODE_MASK)
0031 #define req_iovcnt(x) \
0032 (((x) >> HFI1_SDMA_REQ_IOVCNT_SHIFT) & HFI1_SDMA_REQ_IOVCNT_MASK)
0033
0034
0035 #define BTH_SEQ_MASK 0x7ffull
0036
0037 #define AHG_KDETH_INTR_SHIFT 12
0038 #define AHG_KDETH_SH_SHIFT 13
0039 #define AHG_KDETH_ARRAY_SIZE 9
0040
0041 #define PBC2LRH(x) ((((x) & 0xfff) << 2) - 4)
0042 #define LRH2PBC(x) ((((x) >> 2) + 1) & 0xfff)
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 static inline int ahg_header_set(u32 *arr, int idx, size_t array_size,
0057 u8 dw, u8 bit, u8 width, u16 value)
0058 {
0059 if ((size_t)idx >= array_size)
0060 return -ERANGE;
0061 arr[idx++] = sdma_build_ahg_descriptor(value, dw, bit, width);
0062 return idx;
0063 }
0064
0065
0066 #define TXREQ_FLAGS_REQ_ACK BIT(0)
0067 #define TXREQ_FLAGS_REQ_DISABLE_SH BIT(1)
0068
0069 enum pkt_q_sdma_state {
0070 SDMA_PKT_Q_ACTIVE,
0071 SDMA_PKT_Q_DEFERRED,
0072 };
0073
0074 #define SDMA_IOWAIT_TIMEOUT 1000
0075
0076 #define SDMA_DBG(req, fmt, ...) \
0077 hfi1_cdbg(SDMA, "[%u:%u:%u:%u] " fmt, (req)->pq->dd->unit, \
0078 (req)->pq->ctxt, (req)->pq->subctxt, (req)->info.comp_idx, \
0079 ##__VA_ARGS__)
0080
0081 struct hfi1_user_sdma_pkt_q {
0082 u16 ctxt;
0083 u16 subctxt;
0084 u16 n_max_reqs;
0085 atomic_t n_reqs;
0086 u16 reqidx;
0087 struct hfi1_devdata *dd;
0088 struct kmem_cache *txreq_cache;
0089 struct user_sdma_request *reqs;
0090 unsigned long *req_in_use;
0091 struct iowait busy;
0092 enum pkt_q_sdma_state state;
0093 wait_queue_head_t wait;
0094 unsigned long unpinned;
0095 struct mmu_rb_handler *handler;
0096 atomic_t n_locked;
0097 };
0098
0099 struct hfi1_user_sdma_comp_q {
0100 u16 nentries;
0101 struct hfi1_sdma_comp_entry *comps;
0102 };
0103
0104 struct sdma_mmu_node {
0105 struct mmu_rb_node rb;
0106 struct hfi1_user_sdma_pkt_q *pq;
0107 atomic_t refcount;
0108 struct page **pages;
0109 unsigned int npages;
0110 };
0111
0112 struct user_sdma_iovec {
0113 struct list_head list;
0114 struct iovec iov;
0115
0116 unsigned int npages;
0117
0118 struct page **pages;
0119
0120
0121
0122
0123 u64 offset;
0124 struct sdma_mmu_node *node;
0125 };
0126
0127
0128 struct evict_data {
0129 u32 cleared;
0130 u32 target;
0131 };
0132
0133 struct user_sdma_request {
0134
0135 struct hfi1_pkt_header hdr;
0136
0137
0138 struct hfi1_user_sdma_pkt_q *pq ____cacheline_aligned_in_smp;
0139 struct hfi1_user_sdma_comp_q *cq;
0140
0141
0142
0143
0144
0145 struct sdma_engine *sde;
0146 struct sdma_req_info info;
0147
0148 u32 *tids;
0149
0150 u32 data_len;
0151
0152 u16 n_tids;
0153
0154
0155
0156
0157 u8 data_iovs;
0158 s8 ahg_idx;
0159
0160
0161 u16 seqcomp ____cacheline_aligned_in_smp;
0162 u16 seqsubmitted;
0163
0164
0165 struct list_head txps ____cacheline_aligned_in_smp;
0166 u16 seqnum;
0167
0168
0169
0170
0171
0172 u32 tidoffset;
0173
0174
0175
0176
0177
0178 u32 koffset;
0179 u32 sent;
0180
0181 u16 tididx;
0182
0183 u8 iov_idx;
0184 u8 has_error;
0185
0186 struct user_sdma_iovec iovs[MAX_VECTORS_PER_REQ];
0187 } ____cacheline_aligned_in_smp;
0188
0189
0190
0191
0192
0193
0194
0195 struct user_sdma_txreq {
0196
0197 struct hfi1_pkt_header hdr;
0198 struct sdma_txreq txreq;
0199 struct list_head list;
0200 struct user_sdma_request *req;
0201 u16 flags;
0202 u16 seqnum;
0203 };
0204
0205 int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt,
0206 struct hfi1_filedata *fd);
0207 int hfi1_user_sdma_free_queues(struct hfi1_filedata *fd,
0208 struct hfi1_ctxtdata *uctxt);
0209 int hfi1_user_sdma_process_request(struct hfi1_filedata *fd,
0210 struct iovec *iovec, unsigned long dim,
0211 unsigned long *count);
0212
0213 static inline struct mm_struct *mm_from_sdma_node(struct sdma_mmu_node *node)
0214 {
0215 return node->rb.handler->mn.mm;
0216 }
0217
0218 #endif