qib_verbs.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /*
  2. * Copyright (c) 2012, 2013 Intel Corporation. All rights reserved.
  3. * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
  4. * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #ifndef QIB_VERBS_H
  35. #define QIB_VERBS_H
  36. #include <linux/types.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/kernel.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/kref.h>
  41. #include <linux/workqueue.h>
  42. #include <linux/kthread.h>
  43. #include <linux/completion.h>
  44. #include <rdma/ib_pack.h>
  45. #include <rdma/ib_user_verbs.h>
  46. #include <rdma/rdma_vt.h>
  47. #include <rdma/rdmavt_cq.h>
  48. struct qib_ctxtdata;
  49. struct qib_pportdata;
  50. struct qib_devdata;
  51. struct qib_verbs_txreq;
  52. #define QIB_MAX_RDMA_ATOMIC 16
  53. #define QIB_GUIDS_PER_PORT 5
  54. #define QIB_PSN_SHIFT 8
  55. /*
  56. * Increment this value if any changes that break userspace ABI
  57. * compatibility are made.
  58. */
  59. #define QIB_UVERBS_ABI_VERSION 2
  60. #define IB_SEQ_NAK (3 << 29)
  61. /* AETH NAK opcode values */
  62. #define IB_RNR_NAK 0x20
  63. #define IB_NAK_PSN_ERROR 0x60
  64. #define IB_NAK_INVALID_REQUEST 0x61
  65. #define IB_NAK_REMOTE_ACCESS_ERROR 0x62
  66. #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
  67. #define IB_NAK_INVALID_RD_REQUEST 0x64
  68. /* IB Performance Manager status values */
  69. #define IB_PMA_SAMPLE_STATUS_DONE 0x00
  70. #define IB_PMA_SAMPLE_STATUS_STARTED 0x01
  71. #define IB_PMA_SAMPLE_STATUS_RUNNING 0x02
  72. /* Mandatory IB performance counter select values. */
  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. #define QIB_VENDOR_IPG cpu_to_be16(0xFFA0)
  79. #define IB_BTH_REQ_ACK (1 << 31)
  80. #define IB_BTH_SOLICITED (1 << 23)
  81. #define IB_BTH_MIG_REQ (1 << 22)
  82. /* XXX Should be defined in ib_verbs.h enum ib_port_cap_flags */
  83. #define IB_PORT_OTHER_LOCAL_CHANGES_SUP (1 << 26)
  84. #define IB_GRH_VERSION 6
  85. #define IB_GRH_VERSION_MASK 0xF
  86. #define IB_GRH_VERSION_SHIFT 28
  87. #define IB_GRH_TCLASS_MASK 0xFF
  88. #define IB_GRH_TCLASS_SHIFT 20
  89. #define IB_GRH_FLOW_MASK 0xFFFFF
  90. #define IB_GRH_FLOW_SHIFT 0
  91. #define IB_GRH_NEXT_HDR 0x1B
  92. #define IB_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL)
  93. /* Values for set/get portinfo VLCap OperationalVLs */
  94. #define IB_VL_VL0 1
  95. #define IB_VL_VL0_1 2
  96. #define IB_VL_VL0_3 3
  97. #define IB_VL_VL0_7 4
  98. #define IB_VL_VL0_14 5
  99. static inline int qib_num_vls(int vls)
  100. {
  101. switch (vls) {
  102. default:
  103. case IB_VL_VL0:
  104. return 1;
  105. case IB_VL_VL0_1:
  106. return 2;
  107. case IB_VL_VL0_3:
  108. return 4;
  109. case IB_VL_VL0_7:
  110. return 8;
  111. case IB_VL_VL0_14:
  112. return 15;
  113. }
  114. }
  115. struct ib_reth {
  116. __be64 vaddr;
  117. __be32 rkey;
  118. __be32 length;
  119. } __packed;
  120. struct ib_atomic_eth {
  121. __be32 vaddr[2]; /* unaligned so access as 2 32-bit words */
  122. __be32 rkey;
  123. __be64 swap_data;
  124. __be64 compare_data;
  125. } __packed;
  126. struct qib_other_headers {
  127. __be32 bth[3];
  128. union {
  129. struct {
  130. __be32 deth[2];
  131. __be32 imm_data;
  132. } ud;
  133. struct {
  134. struct ib_reth reth;
  135. __be32 imm_data;
  136. } rc;
  137. struct {
  138. __be32 aeth;
  139. __be32 atomic_ack_eth[2];
  140. } at;
  141. __be32 imm_data;
  142. __be32 aeth;
  143. struct ib_atomic_eth atomic_eth;
  144. } u;
  145. } __packed;
  146. /*
  147. * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes
  148. * long (72 w/ imm_data). Only the first 56 bytes of the IB header
  149. * will be in the eager header buffer. The remaining 12 or 16 bytes
  150. * are in the data buffer.
  151. */
  152. struct qib_ib_header {
  153. __be16 lrh[4];
  154. union {
  155. struct {
  156. struct ib_grh grh;
  157. struct qib_other_headers oth;
  158. } l;
  159. struct qib_other_headers oth;
  160. } u;
  161. } __packed;
  162. struct qib_pio_header {
  163. __le32 pbc[2];
  164. struct qib_ib_header hdr;
  165. } __packed;
  166. /*
  167. * qib specific data structure that will be hidden from rvt after the queue pair
  168. * is made common.
  169. */
  170. struct qib_qp_priv {
  171. struct qib_ib_header *s_hdr; /* next packet header to send */
  172. struct list_head iowait; /* link for wait PIO buf */
  173. atomic_t s_dma_busy;
  174. struct qib_verbs_txreq *s_tx;
  175. struct work_struct s_work;
  176. wait_queue_head_t wait_dma;
  177. struct rvt_qp *owner;
  178. };
  179. #define QIB_PSN_CREDIT 16
  180. struct qib_opcode_stats {
  181. u64 n_packets; /* number of packets */
  182. u64 n_bytes; /* total number of bytes */
  183. };
  184. struct qib_opcode_stats_perctx {
  185. struct qib_opcode_stats stats[128];
  186. };
  187. struct qib_pma_counters {
  188. u64 n_unicast_xmit; /* total unicast packets sent */
  189. u64 n_unicast_rcv; /* total unicast packets received */
  190. u64 n_multicast_xmit; /* total multicast packets sent */
  191. u64 n_multicast_rcv; /* total multicast packets received */
  192. };
  193. struct qib_ibport {
  194. struct rvt_ibport rvp;
  195. struct rvt_ah *smi_ah;
  196. __be64 guids[QIB_GUIDS_PER_PORT - 1]; /* writable GUIDs */
  197. struct qib_pma_counters __percpu *pmastats;
  198. u64 z_unicast_xmit; /* starting count for PMA */
  199. u64 z_unicast_rcv; /* starting count for PMA */
  200. u64 z_multicast_xmit; /* starting count for PMA */
  201. u64 z_multicast_rcv; /* starting count for PMA */
  202. u64 z_symbol_error_counter; /* starting count for PMA */
  203. u64 z_link_error_recovery_counter; /* starting count for PMA */
  204. u64 z_link_downed_counter; /* starting count for PMA */
  205. u64 z_port_rcv_errors; /* starting count for PMA */
  206. u64 z_port_rcv_remphys_errors; /* starting count for PMA */
  207. u64 z_port_xmit_discards; /* starting count for PMA */
  208. u64 z_port_xmit_data; /* starting count for PMA */
  209. u64 z_port_rcv_data; /* starting count for PMA */
  210. u64 z_port_xmit_packets; /* starting count for PMA */
  211. u64 z_port_rcv_packets; /* starting count for PMA */
  212. u32 z_local_link_integrity_errors; /* starting count for PMA */
  213. u32 z_excessive_buffer_overrun_errors; /* starting count for PMA */
  214. u32 z_vl15_dropped; /* starting count for PMA */
  215. u8 sl_to_vl[16];
  216. };
  217. struct qib_ibdev {
  218. struct rvt_dev_info rdi;
  219. struct list_head piowait; /* list for wait PIO buf */
  220. struct list_head dmawait; /* list for wait DMA */
  221. struct list_head txwait; /* list for wait qib_verbs_txreq */
  222. struct list_head memwait; /* list for wait kernel memory */
  223. struct list_head txreq_free;
  224. struct timer_list mem_timer;
  225. struct qib_pio_header *pio_hdrs;
  226. dma_addr_t pio_hdrs_phys;
  227. u32 qp_rnd; /* random bytes for hash */
  228. u32 n_piowait;
  229. u32 n_txwait;
  230. #ifdef CONFIG_DEBUG_FS
  231. /* per HCA debugfs */
  232. struct dentry *qib_ibdev_dbg;
  233. #endif
  234. };
  235. struct qib_verbs_counters {
  236. u64 symbol_error_counter;
  237. u64 link_error_recovery_counter;
  238. u64 link_downed_counter;
  239. u64 port_rcv_errors;
  240. u64 port_rcv_remphys_errors;
  241. u64 port_xmit_discards;
  242. u64 port_xmit_data;
  243. u64 port_rcv_data;
  244. u64 port_xmit_packets;
  245. u64 port_rcv_packets;
  246. u32 local_link_integrity_errors;
  247. u32 excessive_buffer_overrun_errors;
  248. u32 vl15_dropped;
  249. };
  250. static inline struct qib_ibdev *to_idev(struct ib_device *ibdev)
  251. {
  252. struct rvt_dev_info *rdi;
  253. rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
  254. return container_of(rdi, struct qib_ibdev, rdi);
  255. }
  256. /*
  257. * Send if not busy or waiting for I/O and either
  258. * a RC response is pending or we can process send work requests.
  259. */
  260. static inline int qib_send_ok(struct rvt_qp *qp)
  261. {
  262. return !(qp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT_IO)) &&
  263. (qp->s_hdrwords || (qp->s_flags & RVT_S_RESP_PENDING) ||
  264. !(qp->s_flags & RVT_S_ANY_WAIT_SEND));
  265. }
  266. void _qib_schedule_send(struct rvt_qp *qp);
  267. void qib_schedule_send(struct rvt_qp *qp);
  268. static inline int qib_pkey_ok(u16 pkey1, u16 pkey2)
  269. {
  270. u16 p1 = pkey1 & 0x7FFF;
  271. u16 p2 = pkey2 & 0x7FFF;
  272. /*
  273. * Low 15 bits must be non-zero and match, and
  274. * one of the two must be a full member.
  275. */
  276. return p1 && p1 == p2 && ((__s16)pkey1 < 0 || (__s16)pkey2 < 0);
  277. }
  278. void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
  279. u32 qp1, u32 qp2, __be16 lid1, __be16 lid2);
  280. void qib_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num);
  281. void qib_sys_guid_chg(struct qib_ibport *ibp);
  282. void qib_node_desc_chg(struct qib_ibport *ibp);
  283. int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
  284. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  285. const struct ib_mad_hdr *in, size_t in_mad_size,
  286. struct ib_mad_hdr *out, size_t *out_mad_size,
  287. u16 *out_mad_pkey_index);
  288. void qib_notify_create_mad_agent(struct rvt_dev_info *rdi, int port_idx);
  289. void qib_notify_free_mad_agent(struct rvt_dev_info *rdi, int port_idx);
  290. /*
  291. * Compare the lower 24 bits of the two values.
  292. * Returns an integer <, ==, or > than zero.
  293. */
  294. static inline int qib_cmp24(u32 a, u32 b)
  295. {
  296. return (((int) a) - ((int) b)) << 8;
  297. }
  298. int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
  299. u64 *rwords, u64 *spkts, u64 *rpkts,
  300. u64 *xmit_wait);
  301. int qib_get_counters(struct qib_pportdata *ppd,
  302. struct qib_verbs_counters *cntrs);
  303. __be32 qib_compute_aeth(struct rvt_qp *qp);
  304. /*
  305. * Functions provided by qib driver for rdmavt to use
  306. */
  307. unsigned qib_free_all_qps(struct rvt_dev_info *rdi);
  308. void *qib_qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp, gfp_t gfp);
  309. void qib_qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp);
  310. void qib_notify_qp_reset(struct rvt_qp *qp);
  311. int qib_alloc_qpn(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
  312. enum ib_qp_type type, u8 port, gfp_t gfp);
  313. #ifdef CONFIG_DEBUG_FS
  314. struct qib_qp_iter;
  315. struct qib_qp_iter *qib_qp_iter_init(struct qib_ibdev *dev);
  316. int qib_qp_iter_next(struct qib_qp_iter *iter);
  317. void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter);
  318. #endif
  319. void qib_get_credit(struct rvt_qp *qp, u32 aeth);
  320. unsigned qib_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult);
  321. void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail);
  322. void qib_put_txreq(struct qib_verbs_txreq *tx);
  323. int qib_verbs_send(struct rvt_qp *qp, struct qib_ib_header *hdr,
  324. u32 hdrwords, struct rvt_sge_state *ss, u32 len);
  325. void qib_copy_sge(struct rvt_sge_state *ss, void *data, u32 length,
  326. int release);
  327. void qib_skip_sge(struct rvt_sge_state *ss, u32 length, int release);
  328. void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
  329. int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
  330. void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
  331. int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
  332. int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
  333. int qib_check_send_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe);
  334. struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid);
  335. void qib_rc_rnr_retry(unsigned long arg);
  336. void qib_rc_send_complete(struct rvt_qp *qp, struct qib_ib_header *hdr);
  337. void qib_rc_error(struct rvt_qp *qp, enum ib_wc_status err);
  338. int qib_post_ud_send(struct rvt_qp *qp, struct ib_send_wr *wr);
  339. void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
  340. int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
  341. void mr_rcu_callback(struct rcu_head *list);
  342. int qib_get_rwqe(struct rvt_qp *qp, int wr_id_only);
  343. void qib_migrate_qp(struct rvt_qp *qp);
  344. int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
  345. int has_grh, struct rvt_qp *qp, u32 bth0);
  346. u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
  347. struct ib_global_route *grh, u32 hwords, u32 nwords);
  348. void qib_make_ruc_header(struct rvt_qp *qp, struct qib_other_headers *ohdr,
  349. u32 bth0, u32 bth2);
  350. void _qib_do_send(struct work_struct *work);
  351. void qib_do_send(struct rvt_qp *qp);
  352. void qib_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
  353. enum ib_wc_status status);
  354. void qib_send_rc_ack(struct rvt_qp *qp);
  355. int qib_make_rc_req(struct rvt_qp *qp);
  356. int qib_make_uc_req(struct rvt_qp *qp);
  357. int qib_make_ud_req(struct rvt_qp *qp);
  358. int qib_register_ib_device(struct qib_devdata *);
  359. void qib_unregister_ib_device(struct qib_devdata *);
  360. void qib_ib_rcv(struct qib_ctxtdata *, void *, void *, u32);
  361. void qib_ib_piobufavail(struct qib_devdata *);
  362. unsigned qib_get_npkeys(struct qib_devdata *);
  363. unsigned qib_get_pkey(struct qib_ibport *, unsigned);
  364. extern const enum ib_wc_opcode ib_qib_wc_opcode[];
  365. /*
  366. * Below HCA-independent IB PhysPortState values, returned
  367. * by the f_ibphys_portstate() routine.
  368. */
  369. #define IB_PHYSPORTSTATE_SLEEP 1
  370. #define IB_PHYSPORTSTATE_POLL 2
  371. #define IB_PHYSPORTSTATE_DISABLED 3
  372. #define IB_PHYSPORTSTATE_CFG_TRAIN 4
  373. #define IB_PHYSPORTSTATE_LINKUP 5
  374. #define IB_PHYSPORTSTATE_LINK_ERR_RECOVER 6
  375. #define IB_PHYSPORTSTATE_CFG_DEBOUNCE 8
  376. #define IB_PHYSPORTSTATE_CFG_IDLE 0xB
  377. #define IB_PHYSPORTSTATE_RECOVERY_RETRAIN 0xC
  378. #define IB_PHYSPORTSTATE_RECOVERY_WAITRMT 0xE
  379. #define IB_PHYSPORTSTATE_RECOVERY_IDLE 0xF
  380. #define IB_PHYSPORTSTATE_CFG_ENH 0x10
  381. #define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13
  382. extern const int ib_rvt_state_ops[];
  383. extern __be64 ib_qib_sys_image_guid; /* in network order */
  384. extern unsigned int ib_rvt_lkey_table_size;
  385. extern unsigned int ib_qib_max_cqes;
  386. extern unsigned int ib_qib_max_cqs;
  387. extern unsigned int ib_qib_max_qp_wrs;
  388. extern unsigned int ib_qib_max_qps;
  389. extern unsigned int ib_qib_max_sges;
  390. extern unsigned int ib_qib_max_mcast_grps;
  391. extern unsigned int ib_qib_max_mcast_qp_attached;
  392. extern unsigned int ib_qib_max_srqs;
  393. extern unsigned int ib_qib_max_srq_sges;
  394. extern unsigned int ib_qib_max_srq_wrs;
  395. extern const u32 ib_qib_rnr_table[];
  396. #endif /* QIB_VERBS_H */