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/rdma_vt.h>
49#include <rdma/rdmavt_cq.h>
50
51struct qib_ctxtdata;
52struct qib_pportdata;
53struct qib_devdata;
54struct qib_verbs_txreq;
55
56#define QIB_MAX_RDMA_ATOMIC 16
57#define QIB_GUIDS_PER_PORT 5
58#define QIB_PSN_SHIFT 8
59
60
61
62
63
64#define QIB_UVERBS_ABI_VERSION 2
65
66#define IB_SEQ_NAK (3 << 29)
67
68
69#define IB_RNR_NAK 0x20
70#define IB_NAK_PSN_ERROR 0x60
71#define IB_NAK_INVALID_REQUEST 0x61
72#define IB_NAK_REMOTE_ACCESS_ERROR 0x62
73#define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
74#define IB_NAK_INVALID_RD_REQUEST 0x64
75
76
77#define IB_PMA_SAMPLE_STATUS_DONE 0x00
78#define IB_PMA_SAMPLE_STATUS_STARTED 0x01
79#define IB_PMA_SAMPLE_STATUS_RUNNING 0x02
80
81
82#define IB_PMA_PORT_XMIT_DATA cpu_to_be16(0x0001)
83#define IB_PMA_PORT_RCV_DATA cpu_to_be16(0x0002)
84#define IB_PMA_PORT_XMIT_PKTS cpu_to_be16(0x0003)
85#define IB_PMA_PORT_RCV_PKTS cpu_to_be16(0x0004)
86#define IB_PMA_PORT_XMIT_WAIT cpu_to_be16(0x0005)
87
88#define QIB_VENDOR_IPG cpu_to_be16(0xFFA0)
89
90#define IB_BTH_REQ_ACK (1 << 31)
91#define IB_BTH_SOLICITED (1 << 23)
92#define IB_BTH_MIG_REQ (1 << 22)
93
94
95#define IB_PORT_OTHER_LOCAL_CHANGES_SUP (1 << 26)
96
97#define IB_GRH_VERSION 6
98#define IB_GRH_VERSION_MASK 0xF
99#define IB_GRH_VERSION_SHIFT 28
100#define IB_GRH_TCLASS_MASK 0xFF
101#define IB_GRH_TCLASS_SHIFT 20
102#define IB_GRH_FLOW_MASK 0xFFFFF
103#define IB_GRH_FLOW_SHIFT 0
104#define IB_GRH_NEXT_HDR 0x1B
105
106#define IB_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL)
107
108
109#define IB_VL_VL0 1
110#define IB_VL_VL0_1 2
111#define IB_VL_VL0_3 3
112#define IB_VL_VL0_7 4
113#define IB_VL_VL0_14 5
114
115static inline int qib_num_vls(int vls)
116{
117 switch (vls) {
118 default:
119 case IB_VL_VL0:
120 return 1;
121 case IB_VL_VL0_1:
122 return 2;
123 case IB_VL_VL0_3:
124 return 4;
125 case IB_VL_VL0_7:
126 return 8;
127 case IB_VL_VL0_14:
128 return 15;
129 }
130}
131
132struct ib_reth {
133 __be64 vaddr;
134 __be32 rkey;
135 __be32 length;
136} __packed;
137
138struct ib_atomic_eth {
139 __be32 vaddr[2];
140 __be32 rkey;
141 __be64 swap_data;
142 __be64 compare_data;
143} __packed;
144
145struct qib_other_headers {
146 __be32 bth[3];
147 union {
148 struct {
149 __be32 deth[2];
150 __be32 imm_data;
151 } ud;
152 struct {
153 struct ib_reth reth;
154 __be32 imm_data;
155 } rc;
156 struct {
157 __be32 aeth;
158 __be32 atomic_ack_eth[2];
159 } at;
160 __be32 imm_data;
161 __be32 aeth;
162 __be32 ieth;
163 struct ib_atomic_eth atomic_eth;
164 } u;
165} __packed;
166
167
168
169
170
171
172
173struct qib_ib_header {
174 __be16 lrh[4];
175 union {
176 struct {
177 struct ib_grh grh;
178 struct qib_other_headers oth;
179 } l;
180 struct qib_other_headers oth;
181 } u;
182} __packed;
183
184struct qib_pio_header {
185 __le32 pbc[2];
186 struct qib_ib_header hdr;
187} __packed;
188
189
190
191
192
193struct qib_qp_priv {
194 struct qib_ib_header *s_hdr;
195 struct list_head iowait;
196 atomic_t s_dma_busy;
197 struct qib_verbs_txreq *s_tx;
198 struct work_struct s_work;
199 wait_queue_head_t wait_dma;
200 struct rvt_qp *owner;
201};
202
203#define QIB_PSN_CREDIT 16
204
205struct qib_opcode_stats {
206 u64 n_packets;
207 u64 n_bytes;
208};
209
210struct qib_opcode_stats_perctx {
211 struct qib_opcode_stats stats[128];
212};
213
214struct qib_pma_counters {
215 u64 n_unicast_xmit;
216 u64 n_unicast_rcv;
217 u64 n_multicast_xmit;
218 u64 n_multicast_rcv;
219};
220
221struct qib_ibport {
222 struct rvt_ibport rvp;
223 struct rvt_ah *smi_ah;
224 __be64 guids[QIB_GUIDS_PER_PORT - 1];
225 struct qib_pma_counters __percpu *pmastats;
226 u64 z_unicast_xmit;
227 u64 z_unicast_rcv;
228 u64 z_multicast_xmit;
229 u64 z_multicast_rcv;
230 u64 z_symbol_error_counter;
231 u64 z_link_error_recovery_counter;
232 u64 z_link_downed_counter;
233 u64 z_port_rcv_errors;
234 u64 z_port_rcv_remphys_errors;
235 u64 z_port_xmit_discards;
236 u64 z_port_xmit_data;
237 u64 z_port_rcv_data;
238 u64 z_port_xmit_packets;
239 u64 z_port_rcv_packets;
240 u32 z_local_link_integrity_errors;
241 u32 z_excessive_buffer_overrun_errors;
242 u32 z_vl15_dropped;
243 u8 sl_to_vl[16];
244};
245
246struct qib_ibdev {
247 struct rvt_dev_info rdi;
248
249 struct list_head piowait;
250 struct list_head dmawait;
251 struct list_head txwait;
252 struct list_head memwait;
253 struct list_head txreq_free;
254 struct timer_list mem_timer;
255 struct qib_pio_header *pio_hdrs;
256 dma_addr_t pio_hdrs_phys;
257 u32 qp_rnd;
258
259 u32 n_piowait;
260 u32 n_txwait;
261
262#ifdef CONFIG_DEBUG_FS
263
264 struct dentry *qib_ibdev_dbg;
265#endif
266};
267
268struct qib_verbs_counters {
269 u64 symbol_error_counter;
270 u64 link_error_recovery_counter;
271 u64 link_downed_counter;
272 u64 port_rcv_errors;
273 u64 port_rcv_remphys_errors;
274 u64 port_xmit_discards;
275 u64 port_xmit_data;
276 u64 port_rcv_data;
277 u64 port_xmit_packets;
278 u64 port_rcv_packets;
279 u32 local_link_integrity_errors;
280 u32 excessive_buffer_overrun_errors;
281 u32 vl15_dropped;
282};
283
284static inline struct qib_ibdev *to_idev(struct ib_device *ibdev)
285{
286 struct rvt_dev_info *rdi;
287
288 rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
289 return container_of(rdi, struct qib_ibdev, rdi);
290}
291
292
293
294
295
296static inline int qib_send_ok(struct rvt_qp *qp)
297{
298 return !(qp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT_IO)) &&
299 (qp->s_hdrwords || (qp->s_flags & RVT_S_RESP_PENDING) ||
300 !(qp->s_flags & RVT_S_ANY_WAIT_SEND));
301}
302
303void _qib_schedule_send(struct rvt_qp *qp);
304void qib_schedule_send(struct rvt_qp *qp);
305
306static inline int qib_pkey_ok(u16 pkey1, u16 pkey2)
307{
308 u16 p1 = pkey1 & 0x7FFF;
309 u16 p2 = pkey2 & 0x7FFF;
310
311
312
313
314
315 return p1 && p1 == p2 && ((__s16)pkey1 < 0 || (__s16)pkey2 < 0);
316}
317
318void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
319 u32 qp1, u32 qp2, __be16 lid1, __be16 lid2);
320void qib_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num);
321void qib_sys_guid_chg(struct qib_ibport *ibp);
322void qib_node_desc_chg(struct qib_ibport *ibp);
323int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
324 const struct ib_wc *in_wc, const struct ib_grh *in_grh,
325 const struct ib_mad_hdr *in, size_t in_mad_size,
326 struct ib_mad_hdr *out, size_t *out_mad_size,
327 u16 *out_mad_pkey_index);
328void qib_notify_create_mad_agent(struct rvt_dev_info *rdi, int port_idx);
329void qib_notify_free_mad_agent(struct rvt_dev_info *rdi, int port_idx);
330
331
332
333
334
335static inline int qib_cmp24(u32 a, u32 b)
336{
337 return (((int) a) - ((int) b)) << 8;
338}
339
340int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
341 u64 *rwords, u64 *spkts, u64 *rpkts,
342 u64 *xmit_wait);
343
344int qib_get_counters(struct qib_pportdata *ppd,
345 struct qib_verbs_counters *cntrs);
346
347__be32 qib_compute_aeth(struct rvt_qp *qp);
348
349
350
351
352unsigned qib_free_all_qps(struct rvt_dev_info *rdi);
353void *qib_qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp, gfp_t gfp);
354void qib_qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp);
355void qib_notify_qp_reset(struct rvt_qp *qp);
356int qib_alloc_qpn(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
357 enum ib_qp_type type, u8 port, gfp_t gfp);
358
359#ifdef CONFIG_DEBUG_FS
360
361struct qib_qp_iter;
362
363struct qib_qp_iter *qib_qp_iter_init(struct qib_ibdev *dev);
364
365int qib_qp_iter_next(struct qib_qp_iter *iter);
366
367void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter);
368
369#endif
370
371void qib_get_credit(struct rvt_qp *qp, u32 aeth);
372
373unsigned qib_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult);
374
375void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail);
376
377void qib_put_txreq(struct qib_verbs_txreq *tx);
378
379int qib_verbs_send(struct rvt_qp *qp, struct qib_ib_header *hdr,
380 u32 hdrwords, struct rvt_sge_state *ss, u32 len);
381
382void qib_copy_sge(struct rvt_sge_state *ss, void *data, u32 length,
383 int release);
384
385void qib_skip_sge(struct rvt_sge_state *ss, u32 length, int release);
386
387void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
388 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
389
390void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
391 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
392
393int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
394
395int qib_check_send_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe);
396
397struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid);
398
399void qib_rc_rnr_retry(unsigned long arg);
400
401void qib_rc_send_complete(struct rvt_qp *qp, struct qib_ib_header *hdr);
402
403void qib_rc_error(struct rvt_qp *qp, enum ib_wc_status err);
404
405int qib_post_ud_send(struct rvt_qp *qp, struct ib_send_wr *wr);
406
407void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
408 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
409
410void mr_rcu_callback(struct rcu_head *list);
411
412int qib_get_rwqe(struct rvt_qp *qp, int wr_id_only);
413
414void qib_migrate_qp(struct rvt_qp *qp);
415
416int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
417 int has_grh, struct rvt_qp *qp, u32 bth0);
418
419u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
420 struct ib_global_route *grh, u32 hwords, u32 nwords);
421
422void qib_make_ruc_header(struct rvt_qp *qp, struct qib_other_headers *ohdr,
423 u32 bth0, u32 bth2);
424
425void _qib_do_send(struct work_struct *work);
426
427void qib_do_send(struct rvt_qp *qp);
428
429void qib_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
430 enum ib_wc_status status);
431
432void qib_send_rc_ack(struct rvt_qp *qp);
433
434int qib_make_rc_req(struct rvt_qp *qp, unsigned long *flags);
435
436int qib_make_uc_req(struct rvt_qp *qp, unsigned long *flags);
437
438int qib_make_ud_req(struct rvt_qp *qp, unsigned long *flags);
439
440int qib_register_ib_device(struct qib_devdata *);
441
442void qib_unregister_ib_device(struct qib_devdata *);
443
444void qib_ib_rcv(struct qib_ctxtdata *, void *, void *, u32);
445
446void qib_ib_piobufavail(struct qib_devdata *);
447
448unsigned qib_get_npkeys(struct qib_devdata *);
449
450unsigned qib_get_pkey(struct qib_ibport *, unsigned);
451
452extern const enum ib_wc_opcode ib_qib_wc_opcode[];
453
454
455
456
457
458#define IB_PHYSPORTSTATE_SLEEP 1
459#define IB_PHYSPORTSTATE_POLL 2
460#define IB_PHYSPORTSTATE_DISABLED 3
461#define IB_PHYSPORTSTATE_CFG_TRAIN 4
462#define IB_PHYSPORTSTATE_LINKUP 5
463#define IB_PHYSPORTSTATE_LINK_ERR_RECOVER 6
464#define IB_PHYSPORTSTATE_CFG_DEBOUNCE 8
465#define IB_PHYSPORTSTATE_CFG_IDLE 0xB
466#define IB_PHYSPORTSTATE_RECOVERY_RETRAIN 0xC
467#define IB_PHYSPORTSTATE_RECOVERY_WAITRMT 0xE
468#define IB_PHYSPORTSTATE_RECOVERY_IDLE 0xF
469#define IB_PHYSPORTSTATE_CFG_ENH 0x10
470#define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13
471
472extern const int ib_rvt_state_ops[];
473
474extern __be64 ib_qib_sys_image_guid;
475
476extern unsigned int ib_rvt_lkey_table_size;
477
478extern unsigned int ib_qib_max_cqes;
479
480extern unsigned int ib_qib_max_cqs;
481
482extern unsigned int ib_qib_max_qp_wrs;
483
484extern unsigned int ib_qib_max_qps;
485
486extern unsigned int ib_qib_max_sges;
487
488extern unsigned int ib_qib_max_mcast_grps;
489
490extern unsigned int ib_qib_max_mcast_qp_attached;
491
492extern unsigned int ib_qib_max_srqs;
493
494extern unsigned int ib_qib_max_srq_sges;
495
496extern unsigned int ib_qib_max_srq_wrs;
497
498extern const u32 ib_qib_rnr_table[];
499
500#endif
501