0001
0002
0003
0004
0005
0006 #ifndef HFI1_VERBS_H
0007 #define HFI1_VERBS_H
0008
0009 #include <linux/types.h>
0010 #include <linux/seqlock.h>
0011 #include <linux/kernel.h>
0012 #include <linux/interrupt.h>
0013 #include <linux/kref.h>
0014 #include <linux/workqueue.h>
0015 #include <linux/kthread.h>
0016 #include <linux/completion.h>
0017 #include <linux/slab.h>
0018 #include <rdma/ib_pack.h>
0019 #include <rdma/ib_user_verbs.h>
0020 #include <rdma/ib_mad.h>
0021 #include <rdma/ib_hdrs.h>
0022 #include <rdma/rdma_vt.h>
0023 #include <rdma/rdmavt_qp.h>
0024 #include <rdma/rdmavt_cq.h>
0025
0026 struct hfi1_ctxtdata;
0027 struct hfi1_pportdata;
0028 struct hfi1_devdata;
0029 struct hfi1_packet;
0030
0031 #include "iowait.h"
0032 #include "tid_rdma.h"
0033 #include "opfn.h"
0034
0035 #define HFI1_MAX_RDMA_ATOMIC 16
0036
0037
0038
0039
0040
0041 #define HFI1_UVERBS_ABI_VERSION 2
0042
0043
0044 #define IB_PMA_SAMPLE_STATUS_DONE 0x00
0045 #define IB_PMA_SAMPLE_STATUS_STARTED 0x01
0046 #define IB_PMA_SAMPLE_STATUS_RUNNING 0x02
0047
0048
0049 #define IB_PMA_PORT_XMIT_DATA cpu_to_be16(0x0001)
0050 #define IB_PMA_PORT_RCV_DATA cpu_to_be16(0x0002)
0051 #define IB_PMA_PORT_XMIT_PKTS cpu_to_be16(0x0003)
0052 #define IB_PMA_PORT_RCV_PKTS cpu_to_be16(0x0004)
0053 #define IB_PMA_PORT_XMIT_WAIT cpu_to_be16(0x0005)
0054
0055 #define HFI1_VENDOR_IPG cpu_to_be16(0xFFA0)
0056
0057 #define IB_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL)
0058 #define OPA_BTH_MIG_REQ BIT(31)
0059
0060 #define RC_OP(x) IB_OPCODE_RC_##x
0061 #define UC_OP(x) IB_OPCODE_UC_##x
0062
0063
0064 enum {
0065 HFI1_HAS_GRH = (1 << 0),
0066 };
0067
0068 #define LRH_16B_BYTES (sizeof_field(struct hfi1_16b_header, lrh))
0069 #define LRH_16B_DWORDS (LRH_16B_BYTES / sizeof(u32))
0070 #define LRH_9B_BYTES (sizeof_field(struct ib_header, lrh))
0071 #define LRH_9B_DWORDS (LRH_9B_BYTES / sizeof(u32))
0072
0073
0074 struct opa_16b_mgmt {
0075 __be32 dest_qpn;
0076 __be32 src_qpn;
0077 };
0078
0079 struct hfi1_16b_header {
0080 u32 lrh[4];
0081 union {
0082 struct {
0083 struct ib_grh grh;
0084 struct ib_other_headers oth;
0085 } l;
0086 struct ib_other_headers oth;
0087 struct opa_16b_mgmt mgmt;
0088 } u;
0089 } __packed;
0090
0091 struct hfi1_opa_header {
0092 union {
0093 struct ib_header ibh;
0094 struct hfi1_16b_header opah;
0095 };
0096 u8 hdr_type;
0097 } __packed;
0098
0099 struct hfi1_ahg_info {
0100 u32 ahgdesc[2];
0101 u16 tx_flags;
0102 u8 ahgcount;
0103 u8 ahgidx;
0104 };
0105
0106 struct hfi1_sdma_header {
0107 __le64 pbc;
0108 struct hfi1_opa_header hdr;
0109 } __packed;
0110
0111
0112
0113
0114
0115 struct hfi1_qp_priv {
0116 struct hfi1_ahg_info *s_ahg;
0117 struct sdma_engine *s_sde;
0118 struct send_context *s_sendcontext;
0119 struct hfi1_ctxtdata *rcd;
0120 struct page **pages;
0121 u32 tid_enqueue;
0122 u8 s_sc;
0123 struct iowait s_iowait;
0124 struct timer_list s_tid_timer;
0125 struct timer_list s_tid_retry_timer;
0126 struct list_head tid_wait;
0127 struct hfi1_opfn_data opfn;
0128 struct tid_flow_state flow_state;
0129 struct tid_rdma_qp_params tid_rdma;
0130 struct rvt_qp *owner;
0131 u16 s_running_pkt_size;
0132 u8 hdr_type;
0133 struct rvt_sge_state tid_ss;
0134 atomic_t n_requests;
0135
0136 atomic_t n_tid_requests;
0137 unsigned long tid_timer_timeout_jiffies;
0138 unsigned long tid_retry_timeout_jiffies;
0139
0140
0141 u8 s_state;
0142 u8 s_retry;
0143 u8 rnr_nak_state;
0144 u8 s_nak_state;
0145 u32 s_nak_psn;
0146 u32 s_flags;
0147 u32 s_tid_cur;
0148 u32 s_tid_head;
0149 u32 s_tid_tail;
0150 u32 r_tid_head;
0151 u32 r_tid_tail;
0152 u32 r_tid_ack;
0153 u32 r_tid_alloc;
0154 u32 pending_tid_w_segs;
0155 u32 pending_tid_w_resp;
0156 u32 alloc_w_segs;
0157
0158
0159
0160 u32 tid_r_reqs;
0161 u32 tid_r_comp;
0162 u32 pending_tid_r_segs;
0163 u16 pkts_ps;
0164 u8 timeout_shift;
0165
0166 u32 r_next_psn_kdeth;
0167 u32 r_next_psn_kdeth_save;
0168 u32 s_resync_psn;
0169 u8 sync_pt;
0170 u8 resync;
0171 };
0172
0173 #define HFI1_QP_WQE_INVALID ((u32)-1)
0174
0175 struct hfi1_swqe_priv {
0176 struct tid_rdma_request tid_req;
0177 struct rvt_sge_state ss;
0178 };
0179
0180 struct hfi1_ack_priv {
0181 struct rvt_sge_state ss;
0182 struct tid_rdma_request tid_req;
0183 };
0184
0185
0186
0187
0188
0189 struct iowait_work;
0190 struct hfi1_pkt_state {
0191 struct hfi1_ibdev *dev;
0192 struct hfi1_ibport *ibp;
0193 struct hfi1_pportdata *ppd;
0194 struct verbs_txreq *s_txreq;
0195 struct iowait_work *wait;
0196 unsigned long flags;
0197 unsigned long timeout;
0198 unsigned long timeout_int;
0199 int cpu;
0200 u8 opcode;
0201 bool in_thread;
0202 bool pkts_sent;
0203 };
0204
0205 #define HFI1_PSN_CREDIT 16
0206
0207 struct hfi1_opcode_stats {
0208 u64 n_packets;
0209 u64 n_bytes;
0210 };
0211
0212 struct hfi1_opcode_stats_perctx {
0213 struct hfi1_opcode_stats stats[256];
0214 };
0215
0216 static inline void inc_opstats(
0217 u32 tlen,
0218 struct hfi1_opcode_stats *stats)
0219 {
0220 #ifdef CONFIG_DEBUG_FS
0221 stats->n_bytes += tlen;
0222 stats->n_packets++;
0223 #endif
0224 }
0225
0226 struct hfi1_ibport {
0227 struct rvt_qp __rcu *qp[2];
0228 struct rvt_ibport rvp;
0229
0230
0231 u8 sl_to_sc[32];
0232 u8 sc_to_sl[32];
0233 };
0234
0235 struct hfi1_ibdev {
0236 struct rvt_dev_info rdi;
0237
0238
0239
0240 seqlock_t txwait_lock ____cacheline_aligned_in_smp;
0241 struct list_head txwait;
0242 struct list_head memwait;
0243 struct kmem_cache *verbs_txreq_cache;
0244 u64 n_txwait;
0245 u64 n_kmem_wait;
0246 u64 n_tidwait;
0247
0248
0249 seqlock_t iowait_lock ____cacheline_aligned_in_smp;
0250 u64 n_piowait;
0251 u64 n_piodrain;
0252 struct timer_list mem_timer;
0253
0254 #ifdef CONFIG_DEBUG_FS
0255
0256 struct dentry *hfi1_ibdev_dbg;
0257
0258 struct dentry *hfi1_ibdev_link;
0259 #ifdef CONFIG_FAULT_INJECTION
0260 struct fault *fault;
0261 #endif
0262 #endif
0263 };
0264
0265 static inline struct hfi1_ibdev *to_idev(struct ib_device *ibdev)
0266 {
0267 struct rvt_dev_info *rdi;
0268
0269 rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
0270 return container_of(rdi, struct hfi1_ibdev, rdi);
0271 }
0272
0273 static inline struct rvt_qp *iowait_to_qp(struct iowait *s_iowait)
0274 {
0275 struct hfi1_qp_priv *priv;
0276
0277 priv = container_of(s_iowait, struct hfi1_qp_priv, s_iowait);
0278 return priv->owner;
0279 }
0280
0281
0282
0283
0284 void hfi1_bad_pkey(struct hfi1_ibport *ibp, u32 key, u32 sl,
0285 u32 qp1, u32 qp2, u32 lid1, u32 lid2);
0286 void hfi1_cap_mask_chg(struct rvt_dev_info *rdi, u32 port_num);
0287 void hfi1_sys_guid_chg(struct hfi1_ibport *ibp);
0288 void hfi1_node_desc_chg(struct hfi1_ibport *ibp);
0289 int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u32 port,
0290 const struct ib_wc *in_wc, const struct ib_grh *in_grh,
0291 const struct ib_mad *in_mad, struct ib_mad *out_mad,
0292 size_t *out_mad_size, u16 *out_mad_pkey_index);
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304 #define PSN_MASK 0x7FFFFFFF
0305 #define PSN_SHIFT 1
0306 #define PSN_MODIFY_MASK 0xFFFFFF
0307
0308
0309
0310
0311
0312 static inline int cmp_psn(u32 a, u32 b)
0313 {
0314 return (((int)a) - ((int)b)) << PSN_SHIFT;
0315 }
0316
0317
0318
0319
0320 static inline u32 mask_psn(u32 a)
0321 {
0322 return a & PSN_MASK;
0323 }
0324
0325
0326
0327
0328 static inline u32 delta_psn(u32 a, u32 b)
0329 {
0330 return (((int)a - (int)b) << PSN_SHIFT) >> PSN_SHIFT;
0331 }
0332
0333 static inline struct tid_rdma_request *wqe_to_tid_req(struct rvt_swqe *wqe)
0334 {
0335 return &((struct hfi1_swqe_priv *)wqe->priv)->tid_req;
0336 }
0337
0338 static inline struct tid_rdma_request *ack_to_tid_req(struct rvt_ack_entry *e)
0339 {
0340 return &((struct hfi1_ack_priv *)e->priv)->tid_req;
0341 }
0342
0343
0344
0345
0346
0347 static inline u32 __full_flow_psn(struct flow_state *state, u32 psn)
0348 {
0349 return mask_psn((state->generation << HFI1_KDETH_BTH_SEQ_SHIFT) |
0350 (psn & HFI1_KDETH_BTH_SEQ_MASK));
0351 }
0352
0353 static inline u32 full_flow_psn(struct tid_rdma_flow *flow, u32 psn)
0354 {
0355 return __full_flow_psn(&flow->flow_state, psn);
0356 }
0357
0358 struct verbs_txreq;
0359 void hfi1_put_txreq(struct verbs_txreq *tx);
0360
0361 int hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
0362
0363 void hfi1_cnp_rcv(struct hfi1_packet *packet);
0364
0365 void hfi1_uc_rcv(struct hfi1_packet *packet);
0366
0367 void hfi1_rc_rcv(struct hfi1_packet *packet);
0368
0369 void hfi1_rc_hdrerr(
0370 struct hfi1_ctxtdata *rcd,
0371 struct hfi1_packet *packet,
0372 struct rvt_qp *qp);
0373
0374 u8 ah_to_sc(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr);
0375
0376 void hfi1_rc_verbs_aborted(struct rvt_qp *qp, struct hfi1_opa_header *opah);
0377 void hfi1_rc_send_complete(struct rvt_qp *qp, struct hfi1_opa_header *opah);
0378
0379 void hfi1_ud_rcv(struct hfi1_packet *packet);
0380
0381 int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey);
0382
0383 void hfi1_migrate_qp(struct rvt_qp *qp);
0384
0385 int hfi1_check_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
0386 int attr_mask, struct ib_udata *udata);
0387
0388 void hfi1_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
0389 int attr_mask, struct ib_udata *udata);
0390 void hfi1_restart_rc(struct rvt_qp *qp, u32 psn, int wait);
0391 int hfi1_setup_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe,
0392 bool *call_send);
0393
0394 extern const u32 rc_only_opcode;
0395 extern const u32 uc_only_opcode;
0396
0397 int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_packet *packet);
0398
0399 u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr,
0400 const struct ib_global_route *grh, u32 hwords, u32 nwords);
0401
0402 void hfi1_make_ruc_header(struct rvt_qp *qp, struct ib_other_headers *ohdr,
0403 u32 bth0, u32 bth1, u32 bth2, int middle,
0404 struct hfi1_pkt_state *ps);
0405
0406 bool hfi1_schedule_send_yield(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
0407 bool tid);
0408
0409 void _hfi1_do_send(struct work_struct *work);
0410
0411 void hfi1_do_send_from_rvt(struct rvt_qp *qp);
0412
0413 void hfi1_do_send(struct rvt_qp *qp, bool in_thread);
0414
0415 void hfi1_send_rc_ack(struct hfi1_packet *packet, bool is_fecn);
0416
0417 int hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
0418
0419 int hfi1_make_uc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
0420
0421 int hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
0422
0423 int hfi1_register_ib_device(struct hfi1_devdata *);
0424
0425 void hfi1_unregister_ib_device(struct hfi1_devdata *);
0426
0427 void hfi1_kdeth_eager_rcv(struct hfi1_packet *packet);
0428
0429 void hfi1_kdeth_expected_rcv(struct hfi1_packet *packet);
0430
0431 void hfi1_ib_rcv(struct hfi1_packet *packet);
0432
0433 void hfi1_16B_rcv(struct hfi1_packet *packet);
0434
0435 unsigned hfi1_get_npkeys(struct hfi1_devdata *);
0436
0437 int hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
0438 u64 pbc);
0439
0440 int hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
0441 u64 pbc);
0442
0443 static inline bool opa_bth_is_migration(struct ib_other_headers *ohdr)
0444 {
0445 return ohdr->bth[1] & cpu_to_be32(OPA_BTH_MIG_REQ);
0446 }
0447
0448 void hfi1_wait_kmem(struct rvt_qp *qp);
0449
0450 static inline void hfi1_trdma_send_complete(struct rvt_qp *qp,
0451 struct rvt_swqe *wqe,
0452 enum ib_wc_status status)
0453 {
0454 trdma_clean_swqe(qp, wqe);
0455 rvt_send_complete(qp, wqe, status);
0456 }
0457
0458 extern const enum ib_wc_opcode ib_hfi1_wc_opcode[];
0459
0460 extern const u8 hdr_len_by_opcode[];
0461
0462 extern const int ib_rvt_state_ops[];
0463
0464 extern __be64 ib_hfi1_sys_image_guid;
0465
0466 extern unsigned int hfi1_max_cqes;
0467
0468 extern unsigned int hfi1_max_cqs;
0469
0470 extern unsigned int hfi1_max_qp_wrs;
0471
0472 extern unsigned int hfi1_max_qps;
0473
0474 extern unsigned int hfi1_max_sges;
0475
0476 extern unsigned int hfi1_max_mcast_grps;
0477
0478 extern unsigned int hfi1_max_mcast_qp_attached;
0479
0480 extern unsigned int hfi1_max_srqs;
0481
0482 extern unsigned int hfi1_max_srq_sges;
0483
0484 extern unsigned int hfi1_max_srq_wrs;
0485
0486 extern unsigned short piothreshold;
0487
0488 extern const u32 ib_hfi1_rnr_table[];
0489
0490 #endif