1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#ifndef QIB_VERBS_H
36#define QIB_VERBS_H
37
38#include <linux/types.h>
39#include <linux/spinlock.h>
40#include <linux/kernel.h>
41#include <linux/interrupt.h>
42#include <linux/kref.h>
43#include <linux/workqueue.h>
44#include <linux/kthread.h>
45#include <linux/completion.h>
46#include <rdma/ib_pack.h>
47#include <rdma/ib_user_verbs.h>
48#include <rdma/ib_hdrs.h>
49#include <rdma/rdmavt_qp.h>
50#include <rdma/rdmavt_cq.h>
51
52struct qib_ctxtdata;
53struct qib_pportdata;
54struct qib_devdata;
55struct qib_verbs_txreq;
56
57#define QIB_MAX_RDMA_ATOMIC 16
58#define QIB_GUIDS_PER_PORT 5
59#define QIB_PSN_SHIFT 8
60
61
62
63
64
65#define QIB_UVERBS_ABI_VERSION 2
66
67
68#define IB_PMA_SAMPLE_STATUS_DONE 0x00
69#define IB_PMA_SAMPLE_STATUS_STARTED 0x01
70#define IB_PMA_SAMPLE_STATUS_RUNNING 0x02
71
72
73#define IB_PMA_PORT_XMIT_DATA cpu_to_be16(0x0001)
74#define IB_PMA_PORT_RCV_DATA cpu_to_be16(0x0002)
75#define IB_PMA_PORT_XMIT_PKTS cpu_to_be16(0x0003)
76#define IB_PMA_PORT_RCV_PKTS cpu_to_be16(0x0004)
77#define IB_PMA_PORT_XMIT_WAIT cpu_to_be16(0x0005)
78
79#define QIB_VENDOR_IPG cpu_to_be16(0xFFA0)
80
81#define IB_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL)
82
83
84#define IB_VL_VL0 1
85#define IB_VL_VL0_1 2
86#define IB_VL_VL0_3 3
87#define IB_VL_VL0_7 4
88#define IB_VL_VL0_14 5
89
90static inline int qib_num_vls(int vls)
91{
92 switch (vls) {
93 default:
94 case IB_VL_VL0:
95 return 1;
96 case IB_VL_VL0_1:
97 return 2;
98 case IB_VL_VL0_3:
99 return 4;
100 case IB_VL_VL0_7:
101 return 8;
102 case IB_VL_VL0_14:
103 return 15;
104 }
105}
106
107struct qib_pio_header {
108 __le32 pbc[2];
109 struct ib_header hdr;
110} __packed;
111
112
113
114
115
116struct qib_qp_priv {
117 struct ib_header *s_hdr;
118 struct list_head iowait;
119 atomic_t s_dma_busy;
120 struct qib_verbs_txreq *s_tx;
121 struct work_struct s_work;
122 wait_queue_head_t wait_dma;
123 struct rvt_qp *owner;
124};
125
126#define QIB_PSN_CREDIT 16
127
128struct qib_opcode_stats {
129 u64 n_packets;
130 u64 n_bytes;
131};
132
133struct qib_opcode_stats_perctx {
134 struct qib_opcode_stats stats[128];
135};
136
137struct qib_pma_counters {
138 u64 n_unicast_xmit;
139 u64 n_unicast_rcv;
140 u64 n_multicast_xmit;
141 u64 n_multicast_rcv;
142};
143
144struct qib_ibport {
145 struct rvt_ibport rvp;
146 struct rvt_ah *smi_ah;
147 __be64 guids[QIB_GUIDS_PER_PORT - 1];
148 struct qib_pma_counters __percpu *pmastats;
149 u64 z_unicast_xmit;
150 u64 z_unicast_rcv;
151 u64 z_multicast_xmit;
152 u64 z_multicast_rcv;
153 u64 z_symbol_error_counter;
154 u64 z_link_error_recovery_counter;
155 u64 z_link_downed_counter;
156 u64 z_port_rcv_errors;
157 u64 z_port_rcv_remphys_errors;
158 u64 z_port_xmit_discards;
159 u64 z_port_xmit_data;
160 u64 z_port_rcv_data;
161 u64 z_port_xmit_packets;
162 u64 z_port_rcv_packets;
163 u32 z_local_link_integrity_errors;
164 u32 z_excessive_buffer_overrun_errors;
165 u32 z_vl15_dropped;
166 u8 sl_to_vl[16];
167};
168
169struct qib_ibdev {
170 struct rvt_dev_info rdi;
171
172 struct list_head piowait;
173 struct list_head dmawait;
174 struct list_head txwait;
175 struct list_head memwait;
176 struct list_head txreq_free;
177 struct timer_list mem_timer;
178 struct qib_pio_header *pio_hdrs;
179 dma_addr_t pio_hdrs_phys;
180
181 u32 n_piowait;
182 u32 n_txwait;
183
184#ifdef CONFIG_DEBUG_FS
185
186 struct dentry *qib_ibdev_dbg;
187#endif
188};
189
190struct qib_verbs_counters {
191 u64 symbol_error_counter;
192 u64 link_error_recovery_counter;
193 u64 link_downed_counter;
194 u64 port_rcv_errors;
195 u64 port_rcv_remphys_errors;
196 u64 port_xmit_discards;
197 u64 port_xmit_data;
198 u64 port_rcv_data;
199 u64 port_xmit_packets;
200 u64 port_rcv_packets;
201 u32 local_link_integrity_errors;
202 u32 excessive_buffer_overrun_errors;
203 u32 vl15_dropped;
204};
205
206static inline struct qib_ibdev *to_idev(struct ib_device *ibdev)
207{
208 struct rvt_dev_info *rdi;
209
210 rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
211 return container_of(rdi, struct qib_ibdev, rdi);
212}
213
214
215
216
217
218static inline int qib_send_ok(struct rvt_qp *qp)
219{
220 return !(qp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT_IO)) &&
221 (qp->s_hdrwords || (qp->s_flags & RVT_S_RESP_PENDING) ||
222 !(qp->s_flags & RVT_S_ANY_WAIT_SEND));
223}
224
225bool _qib_schedule_send(struct rvt_qp *qp);
226bool qib_schedule_send(struct rvt_qp *qp);
227
228static inline int qib_pkey_ok(u16 pkey1, u16 pkey2)
229{
230 u16 p1 = pkey1 & 0x7FFF;
231 u16 p2 = pkey2 & 0x7FFF;
232
233
234
235
236
237 return p1 && p1 == p2 && ((__s16)pkey1 < 0 || (__s16)pkey2 < 0);
238}
239
240void qib_bad_pkey(struct qib_ibport *ibp, u32 key, u32 sl,
241 u32 qp1, u32 qp2, __be16 lid1, __be16 lid2);
242void qib_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num);
243void qib_sys_guid_chg(struct qib_ibport *ibp);
244void qib_node_desc_chg(struct qib_ibport *ibp);
245int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
246 const struct ib_wc *in_wc, const struct ib_grh *in_grh,
247 const struct ib_mad *in, struct ib_mad *out,
248 size_t *out_mad_size, u16 *out_mad_pkey_index);
249void qib_notify_create_mad_agent(struct rvt_dev_info *rdi, int port_idx);
250void qib_notify_free_mad_agent(struct rvt_dev_info *rdi, int port_idx);
251
252
253
254
255
256static inline int qib_cmp24(u32 a, u32 b)
257{
258 return (((int) a) - ((int) b)) << 8;
259}
260
261int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
262 u64 *rwords, u64 *spkts, u64 *rpkts,
263 u64 *xmit_wait);
264
265int qib_get_counters(struct qib_pportdata *ppd,
266 struct qib_verbs_counters *cntrs);
267
268
269
270
271unsigned qib_free_all_qps(struct rvt_dev_info *rdi);
272void *qib_qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp);
273void qib_qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp);
274void qib_notify_qp_reset(struct rvt_qp *qp);
275int qib_alloc_qpn(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
276 enum ib_qp_type type, u8 port);
277void qib_restart_rc(struct rvt_qp *qp, u32 psn, int wait);
278#ifdef CONFIG_DEBUG_FS
279
280void qib_qp_iter_print(struct seq_file *s, struct rvt_qp_iter *iter);
281
282#endif
283
284unsigned qib_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult);
285
286void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail);
287
288void qib_put_txreq(struct qib_verbs_txreq *tx);
289
290int qib_verbs_send(struct rvt_qp *qp, struct ib_header *hdr,
291 u32 hdrwords, struct rvt_sge_state *ss, u32 len);
292
293void qib_uc_rcv(struct qib_ibport *ibp, struct ib_header *hdr,
294 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
295
296void qib_rc_rcv(struct qib_ctxtdata *rcd, struct ib_header *hdr,
297 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
298
299int qib_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr);
300
301int qib_check_send_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe,
302 bool *call_send);
303
304struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid);
305
306void qib_rc_rnr_retry(unsigned long arg);
307
308void qib_rc_send_complete(struct rvt_qp *qp, struct ib_header *hdr);
309
310int qib_post_ud_send(struct rvt_qp *qp, const struct ib_send_wr *wr);
311
312void qib_ud_rcv(struct qib_ibport *ibp, struct ib_header *hdr,
313 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
314
315void mr_rcu_callback(struct rcu_head *list);
316
317void qib_migrate_qp(struct rvt_qp *qp);
318
319int qib_ruc_check_hdr(struct qib_ibport *ibp, struct ib_header *hdr,
320 int has_grh, struct rvt_qp *qp, u32 bth0);
321
322u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
323 const struct ib_global_route *grh, u32 hwords, u32 nwords);
324
325void qib_make_ruc_header(struct rvt_qp *qp, struct ib_other_headers *ohdr,
326 u32 bth0, u32 bth2);
327
328void _qib_do_send(struct work_struct *work);
329
330void qib_do_send(struct rvt_qp *qp);
331
332void qib_send_rc_ack(struct rvt_qp *qp);
333
334int qib_make_rc_req(struct rvt_qp *qp, unsigned long *flags);
335
336int qib_make_uc_req(struct rvt_qp *qp, unsigned long *flags);
337
338int qib_make_ud_req(struct rvt_qp *qp, unsigned long *flags);
339
340int qib_register_ib_device(struct qib_devdata *);
341
342void qib_unregister_ib_device(struct qib_devdata *);
343
344void qib_ib_rcv(struct qib_ctxtdata *, void *, void *, u32);
345
346void qib_ib_piobufavail(struct qib_devdata *);
347
348unsigned qib_get_npkeys(struct qib_devdata *);
349
350unsigned qib_get_pkey(struct qib_ibport *, unsigned);
351
352extern const enum ib_wc_opcode ib_qib_wc_opcode[];
353
354
355
356
357
358#define IB_PHYSPORTSTATE_SLEEP 1
359#define IB_PHYSPORTSTATE_POLL 2
360#define IB_PHYSPORTSTATE_DISABLED 3
361#define IB_PHYSPORTSTATE_CFG_TRAIN 4
362#define IB_PHYSPORTSTATE_LINKUP 5
363#define IB_PHYSPORTSTATE_LINK_ERR_RECOVER 6
364#define IB_PHYSPORTSTATE_CFG_DEBOUNCE 8
365#define IB_PHYSPORTSTATE_CFG_IDLE 0xB
366#define IB_PHYSPORTSTATE_RECOVERY_RETRAIN 0xC
367#define IB_PHYSPORTSTATE_RECOVERY_WAITRMT 0xE
368#define IB_PHYSPORTSTATE_RECOVERY_IDLE 0xF
369#define IB_PHYSPORTSTATE_CFG_ENH 0x10
370#define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13
371
372extern const int ib_rvt_state_ops[];
373
374extern __be64 ib_qib_sys_image_guid;
375
376extern unsigned int ib_rvt_lkey_table_size;
377
378extern unsigned int ib_qib_max_cqes;
379
380extern unsigned int ib_qib_max_cqs;
381
382extern unsigned int ib_qib_max_qp_wrs;
383
384extern unsigned int ib_qib_max_qps;
385
386extern unsigned int ib_qib_max_sges;
387
388extern unsigned int ib_qib_max_mcast_grps;
389
390extern unsigned int ib_qib_max_mcast_qp_attached;
391
392extern unsigned int ib_qib_max_srqs;
393
394extern unsigned int ib_qib_max_srq_sges;
395
396extern unsigned int ib_qib_max_srq_wrs;
397
398extern const u32 ib_qib_rnr_table[];
399
400extern const struct rvt_operation_params qib_post_parms[];
401
402#endif
403