verbs.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /*
  2. * Copyright(c) 2015, 2016 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. #ifndef HFI1_VERBS_H
  48. #define HFI1_VERBS_H
  49. #include <linux/types.h>
  50. #include <linux/seqlock.h>
  51. #include <linux/kernel.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/kref.h>
  54. #include <linux/workqueue.h>
  55. #include <linux/kthread.h>
  56. #include <linux/completion.h>
  57. #include <linux/slab.h>
  58. #include <rdma/ib_pack.h>
  59. #include <rdma/ib_user_verbs.h>
  60. #include <rdma/ib_mad.h>
  61. #include <rdma/rdma_vt.h>
  62. #include <rdma/rdmavt_qp.h>
  63. #include <rdma/rdmavt_cq.h>
  64. struct hfi1_ctxtdata;
  65. struct hfi1_pportdata;
  66. struct hfi1_devdata;
  67. struct hfi1_packet;
  68. #include "iowait.h"
  69. #define HFI1_MAX_RDMA_ATOMIC 16
  70. #define HFI1_GUIDS_PER_PORT 5
  71. /*
  72. * Increment this value if any changes that break userspace ABI
  73. * compatibility are made.
  74. */
  75. #define HFI1_UVERBS_ABI_VERSION 2
  76. #define IB_SEQ_NAK (3 << 29)
  77. /* AETH NAK opcode values */
  78. #define IB_RNR_NAK 0x20
  79. #define IB_NAK_PSN_ERROR 0x60
  80. #define IB_NAK_INVALID_REQUEST 0x61
  81. #define IB_NAK_REMOTE_ACCESS_ERROR 0x62
  82. #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
  83. #define IB_NAK_INVALID_RD_REQUEST 0x64
  84. /* IB Performance Manager status values */
  85. #define IB_PMA_SAMPLE_STATUS_DONE 0x00
  86. #define IB_PMA_SAMPLE_STATUS_STARTED 0x01
  87. #define IB_PMA_SAMPLE_STATUS_RUNNING 0x02
  88. /* Mandatory IB performance counter select values. */
  89. #define IB_PMA_PORT_XMIT_DATA cpu_to_be16(0x0001)
  90. #define IB_PMA_PORT_RCV_DATA cpu_to_be16(0x0002)
  91. #define IB_PMA_PORT_XMIT_PKTS cpu_to_be16(0x0003)
  92. #define IB_PMA_PORT_RCV_PKTS cpu_to_be16(0x0004)
  93. #define IB_PMA_PORT_XMIT_WAIT cpu_to_be16(0x0005)
  94. #define HFI1_VENDOR_IPG cpu_to_be16(0xFFA0)
  95. #define IB_BTH_REQ_ACK BIT(31)
  96. #define IB_BTH_SOLICITED BIT(23)
  97. #define IB_BTH_MIG_REQ BIT(22)
  98. #define IB_GRH_VERSION 6
  99. #define IB_GRH_VERSION_MASK 0xF
  100. #define IB_GRH_VERSION_SHIFT 28
  101. #define IB_GRH_TCLASS_MASK 0xFF
  102. #define IB_GRH_TCLASS_SHIFT 20
  103. #define IB_GRH_FLOW_MASK 0xFFFFF
  104. #define IB_GRH_FLOW_SHIFT 0
  105. #define IB_GRH_NEXT_HDR 0x1B
  106. #define IB_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL)
  107. /* flags passed by hfi1_ib_rcv() */
  108. enum {
  109. HFI1_HAS_GRH = (1 << 0),
  110. };
  111. struct ib_reth {
  112. __be64 vaddr;
  113. __be32 rkey;
  114. __be32 length;
  115. } __packed;
  116. struct ib_atomic_eth {
  117. __be32 vaddr[2]; /* unaligned so access as 2 32-bit words */
  118. __be32 rkey;
  119. __be64 swap_data;
  120. __be64 compare_data;
  121. } __packed;
  122. union ib_ehdrs {
  123. struct {
  124. __be32 deth[2];
  125. __be32 imm_data;
  126. } ud;
  127. struct {
  128. struct ib_reth reth;
  129. __be32 imm_data;
  130. } rc;
  131. struct {
  132. __be32 aeth;
  133. __be32 atomic_ack_eth[2];
  134. } at;
  135. __be32 imm_data;
  136. __be32 aeth;
  137. __be32 ieth;
  138. struct ib_atomic_eth atomic_eth;
  139. } __packed;
  140. struct hfi1_other_headers {
  141. __be32 bth[3];
  142. union ib_ehdrs u;
  143. } __packed;
  144. /*
  145. * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes
  146. * long (72 w/ imm_data). Only the first 56 bytes of the IB header
  147. * will be in the eager header buffer. The remaining 12 or 16 bytes
  148. * are in the data buffer.
  149. */
  150. struct hfi1_ib_header {
  151. __be16 lrh[4];
  152. union {
  153. struct {
  154. struct ib_grh grh;
  155. struct hfi1_other_headers oth;
  156. } l;
  157. struct hfi1_other_headers oth;
  158. } u;
  159. } __packed;
  160. struct hfi1_ahg_info {
  161. u32 ahgdesc[2];
  162. u16 tx_flags;
  163. u8 ahgcount;
  164. u8 ahgidx;
  165. };
  166. struct hfi1_sdma_header {
  167. __le64 pbc;
  168. struct hfi1_ib_header hdr;
  169. } __packed;
  170. /*
  171. * hfi1 specific data structures that will be hidden from rvt after the queue
  172. * pair is made common
  173. */
  174. struct hfi1_qp_priv {
  175. struct hfi1_ahg_info *s_ahg; /* ahg info for next header */
  176. struct sdma_engine *s_sde; /* current sde */
  177. struct send_context *s_sendcontext; /* current sendcontext */
  178. u8 s_sc; /* SC[0..4] for next packet */
  179. u8 r_adefered; /* number of acks defered */
  180. struct iowait s_iowait;
  181. struct timer_list s_rnr_timer;
  182. struct rvt_qp *owner;
  183. };
  184. /*
  185. * This structure is used to hold commonly lookedup and computed values during
  186. * the send engine progress.
  187. */
  188. struct hfi1_pkt_state {
  189. struct hfi1_ibdev *dev;
  190. struct hfi1_ibport *ibp;
  191. struct hfi1_pportdata *ppd;
  192. struct verbs_txreq *s_txreq;
  193. unsigned long flags;
  194. };
  195. #define HFI1_PSN_CREDIT 16
  196. struct hfi1_opcode_stats {
  197. u64 n_packets; /* number of packets */
  198. u64 n_bytes; /* total number of bytes */
  199. };
  200. struct hfi1_opcode_stats_perctx {
  201. struct hfi1_opcode_stats stats[256];
  202. };
  203. static inline void inc_opstats(
  204. u32 tlen,
  205. struct hfi1_opcode_stats *stats)
  206. {
  207. #ifdef CONFIG_DEBUG_FS
  208. stats->n_bytes += tlen;
  209. stats->n_packets++;
  210. #endif
  211. }
  212. struct hfi1_ibport {
  213. struct rvt_qp __rcu *qp[2];
  214. struct rvt_ibport rvp;
  215. __be64 guids[HFI1_GUIDS_PER_PORT - 1]; /* writable GUIDs */
  216. /* the first 16 entries are sl_to_vl for !OPA */
  217. u8 sl_to_sc[32];
  218. u8 sc_to_sl[32];
  219. };
  220. struct hfi1_ibdev {
  221. struct rvt_dev_info rdi; /* Must be first */
  222. /* QP numbers are shared by all IB ports */
  223. /* protect wait lists */
  224. seqlock_t iowait_lock;
  225. struct list_head txwait; /* list for wait verbs_txreq */
  226. struct list_head memwait; /* list for wait kernel memory */
  227. struct list_head txreq_free;
  228. struct kmem_cache *verbs_txreq_cache;
  229. struct timer_list mem_timer;
  230. u64 n_piowait;
  231. u64 n_piodrain;
  232. u64 n_txwait;
  233. u64 n_kmem_wait;
  234. #ifdef CONFIG_DEBUG_FS
  235. /* per HFI debugfs */
  236. struct dentry *hfi1_ibdev_dbg;
  237. /* per HFI symlinks to above */
  238. struct dentry *hfi1_ibdev_link;
  239. #endif
  240. };
  241. static inline struct hfi1_ibdev *to_idev(struct ib_device *ibdev)
  242. {
  243. struct rvt_dev_info *rdi;
  244. rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
  245. return container_of(rdi, struct hfi1_ibdev, rdi);
  246. }
  247. static inline struct rvt_qp *iowait_to_qp(struct iowait *s_iowait)
  248. {
  249. struct hfi1_qp_priv *priv;
  250. priv = container_of(s_iowait, struct hfi1_qp_priv, s_iowait);
  251. return priv->owner;
  252. }
  253. /*
  254. * Send if not busy or waiting for I/O and either
  255. * a RC response is pending or we can process send work requests.
  256. */
  257. static inline int hfi1_send_ok(struct rvt_qp *qp)
  258. {
  259. return !(qp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT_IO)) &&
  260. (qp->s_hdrwords || (qp->s_flags & RVT_S_RESP_PENDING) ||
  261. !(qp->s_flags & RVT_S_ANY_WAIT_SEND));
  262. }
  263. /*
  264. * This must be called with s_lock held.
  265. */
  266. void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
  267. u32 qp1, u32 qp2, u16 lid1, u16 lid2);
  268. void hfi1_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num);
  269. void hfi1_sys_guid_chg(struct hfi1_ibport *ibp);
  270. void hfi1_node_desc_chg(struct hfi1_ibport *ibp);
  271. int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u8 port,
  272. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  273. const struct ib_mad_hdr *in_mad, size_t in_mad_size,
  274. struct ib_mad_hdr *out_mad, size_t *out_mad_size,
  275. u16 *out_mad_pkey_index);
  276. /*
  277. * The PSN_MASK and PSN_SHIFT allow for
  278. * 1) comparing two PSNs
  279. * 2) returning the PSN with any upper bits masked
  280. * 3) returning the difference between to PSNs
  281. *
  282. * The number of significant bits in the PSN must
  283. * necessarily be at least one bit less than
  284. * the container holding the PSN.
  285. */
  286. #ifndef CONFIG_HFI1_VERBS_31BIT_PSN
  287. #define PSN_MASK 0xFFFFFF
  288. #define PSN_SHIFT 8
  289. #else
  290. #define PSN_MASK 0x7FFFFFFF
  291. #define PSN_SHIFT 1
  292. #endif
  293. #define PSN_MODIFY_MASK 0xFFFFFF
  294. /*
  295. * Compare the lower 24 bits of the msn values.
  296. * Returns an integer <, ==, or > than zero.
  297. */
  298. static inline int cmp_msn(u32 a, u32 b)
  299. {
  300. return (((int)a) - ((int)b)) << 8;
  301. }
  302. /*
  303. * Compare two PSNs
  304. * Returns an integer <, ==, or > than zero.
  305. */
  306. static inline int cmp_psn(u32 a, u32 b)
  307. {
  308. return (((int)a) - ((int)b)) << PSN_SHIFT;
  309. }
  310. /*
  311. * Return masked PSN
  312. */
  313. static inline u32 mask_psn(u32 a)
  314. {
  315. return a & PSN_MASK;
  316. }
  317. /*
  318. * Return delta between two PSNs
  319. */
  320. static inline u32 delta_psn(u32 a, u32 b)
  321. {
  322. return (((int)a - (int)b) << PSN_SHIFT) >> PSN_SHIFT;
  323. }
  324. struct verbs_txreq;
  325. void hfi1_put_txreq(struct verbs_txreq *tx);
  326. int hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
  327. void hfi1_copy_sge(struct rvt_sge_state *ss, void *data, u32 length,
  328. int release, int copy_last);
  329. void hfi1_skip_sge(struct rvt_sge_state *ss, u32 length, int release);
  330. void hfi1_cnp_rcv(struct hfi1_packet *packet);
  331. void hfi1_uc_rcv(struct hfi1_packet *packet);
  332. void hfi1_rc_rcv(struct hfi1_packet *packet);
  333. void hfi1_rc_hdrerr(
  334. struct hfi1_ctxtdata *rcd,
  335. struct hfi1_ib_header *hdr,
  336. u32 rcv_flags,
  337. struct rvt_qp *qp);
  338. u8 ah_to_sc(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
  339. struct ib_ah *hfi1_create_qp0_ah(struct hfi1_ibport *ibp, u16 dlid);
  340. void hfi1_rc_rnr_retry(unsigned long arg);
  341. void hfi1_add_rnr_timer(struct rvt_qp *qp, u32 to);
  342. void hfi1_rc_timeout(unsigned long arg);
  343. void hfi1_del_timers_sync(struct rvt_qp *qp);
  344. void hfi1_stop_rc_timers(struct rvt_qp *qp);
  345. void hfi1_rc_send_complete(struct rvt_qp *qp, struct hfi1_ib_header *hdr);
  346. void hfi1_rc_error(struct rvt_qp *qp, enum ib_wc_status err);
  347. void hfi1_ud_rcv(struct hfi1_packet *packet);
  348. int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey);
  349. int hfi1_rvt_get_rwqe(struct rvt_qp *qp, int wr_id_only);
  350. void hfi1_migrate_qp(struct rvt_qp *qp);
  351. int hfi1_check_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
  352. int attr_mask, struct ib_udata *udata);
  353. void hfi1_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
  354. int attr_mask, struct ib_udata *udata);
  355. int hfi1_check_send_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe);
  356. extern const u32 rc_only_opcode;
  357. extern const u32 uc_only_opcode;
  358. static inline u8 get_opcode(struct hfi1_ib_header *h)
  359. {
  360. u16 lnh = be16_to_cpu(h->lrh[0]) & 3;
  361. if (lnh == IB_LNH_IBA_LOCAL)
  362. return be32_to_cpu(h->u.oth.bth[0]) >> 24;
  363. else
  364. return be32_to_cpu(h->u.l.oth.bth[0]) >> 24;
  365. }
  366. int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_ib_header *hdr,
  367. int has_grh, struct rvt_qp *qp, u32 bth0);
  368. u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr,
  369. struct ib_global_route *grh, u32 hwords, u32 nwords);
  370. void hfi1_make_ruc_header(struct rvt_qp *qp, struct hfi1_other_headers *ohdr,
  371. u32 bth0, u32 bth2, int middle,
  372. struct hfi1_pkt_state *ps);
  373. void _hfi1_do_send(struct work_struct *work);
  374. void hfi1_do_send(struct rvt_qp *qp);
  375. void hfi1_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
  376. enum ib_wc_status status);
  377. void hfi1_send_rc_ack(struct hfi1_ctxtdata *, struct rvt_qp *qp, int is_fecn);
  378. int hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
  379. int hfi1_make_uc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
  380. int hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
  381. int hfi1_register_ib_device(struct hfi1_devdata *);
  382. void hfi1_unregister_ib_device(struct hfi1_devdata *);
  383. void hfi1_ib_rcv(struct hfi1_packet *packet);
  384. unsigned hfi1_get_npkeys(struct hfi1_devdata *);
  385. int hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
  386. u64 pbc);
  387. int hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
  388. u64 pbc);
  389. int hfi1_wss_init(void);
  390. void hfi1_wss_exit(void);
  391. /* platform specific: return the lowest level cache (llc) size, in KiB */
  392. static inline int wss_llc_size(void)
  393. {
  394. /* assume that the boot CPU value is universal for all CPUs */
  395. return boot_cpu_data.x86_cache_size;
  396. }
  397. /* platform specific: cacheless copy */
  398. static inline void cacheless_memcpy(void *dst, void *src, size_t n)
  399. {
  400. /*
  401. * Use the only available X64 cacheless copy. Add a __user cast
  402. * to quiet sparse. The src agument is already in the kernel so
  403. * there are no security issues. The extra fault recovery machinery
  404. * is not invoked.
  405. */
  406. __copy_user_nocache(dst, (void __user *)src, n, 0);
  407. }
  408. extern const enum ib_wc_opcode ib_hfi1_wc_opcode[];
  409. extern const u8 hdr_len_by_opcode[];
  410. extern const int ib_rvt_state_ops[];
  411. extern __be64 ib_hfi1_sys_image_guid; /* in network order */
  412. extern unsigned int hfi1_max_cqes;
  413. extern unsigned int hfi1_max_cqs;
  414. extern unsigned int hfi1_max_qp_wrs;
  415. extern unsigned int hfi1_max_qps;
  416. extern unsigned int hfi1_max_sges;
  417. extern unsigned int hfi1_max_mcast_grps;
  418. extern unsigned int hfi1_max_mcast_qp_attached;
  419. extern unsigned int hfi1_max_srqs;
  420. extern unsigned int hfi1_max_srq_sges;
  421. extern unsigned int hfi1_max_srq_wrs;
  422. extern unsigned short piothreshold;
  423. extern const u32 ib_hfi1_rnr_table[];
  424. #endif /* HFI1_VERBS_H */