ocrdma.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*******************************************************************
  2. * This file is part of the Emulex RoCE Device Driver for *
  3. * RoCE (RDMA over Converged Ethernet) adapters. *
  4. * Copyright (C) 2008-2012 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * *
  8. * This program is free software; you can redistribute it and/or *
  9. * modify it under the terms of version 2 of the GNU General *
  10. * Public License as published by the Free Software Foundation. *
  11. * This program is distributed in the hope that it will be useful. *
  12. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  13. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  14. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  15. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  16. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  17. * more details, a copy of which can be found in the file COPYING *
  18. * included with this package. *
  19. *
  20. * Contact Information:
  21. * linux-drivers@emulex.com
  22. *
  23. * Emulex
  24. * 3333 Susan Street
  25. * Costa Mesa, CA 92626
  26. *******************************************************************/
  27. #ifndef __OCRDMA_H__
  28. #define __OCRDMA_H__
  29. #include <linux/mutex.h>
  30. #include <linux/list.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/pci.h>
  33. #include <rdma/ib_verbs.h>
  34. #include <rdma/ib_user_verbs.h>
  35. #include <rdma/ib_addr.h>
  36. #include <be_roce.h>
  37. #include "ocrdma_sli.h"
  38. #define OCRDMA_ROCE_DRV_VERSION "10.2.145.0u"
  39. #define OCRDMA_ROCE_DRV_DESC "Emulex OneConnect RoCE Driver"
  40. #define OCRDMA_NODE_DESC "Emulex OneConnect RoCE HCA"
  41. #define OC_NAME_SH OCRDMA_NODE_DESC "(Skyhawk)"
  42. #define OC_NAME_UNKNOWN OCRDMA_NODE_DESC "(Unknown)"
  43. #define OC_SKH_DEVICE_PF 0x720
  44. #define OC_SKH_DEVICE_VF 0x728
  45. #define OCRDMA_MAX_AH 512
  46. #define OCRDMA_UVERBS(CMD_NAME) (1ull << IB_USER_VERBS_CMD_##CMD_NAME)
  47. #define convert_to_64bit(lo, hi) ((u64)hi << 32 | (u64)lo)
  48. struct ocrdma_dev_attr {
  49. u8 fw_ver[32];
  50. u32 vendor_id;
  51. u32 device_id;
  52. u16 max_pd;
  53. u16 max_cq;
  54. u16 max_cqe;
  55. u16 max_qp;
  56. u16 max_wqe;
  57. u16 max_rqe;
  58. u16 max_srq;
  59. u32 max_inline_data;
  60. int max_send_sge;
  61. int max_recv_sge;
  62. int max_srq_sge;
  63. int max_rdma_sge;
  64. int max_mr;
  65. u64 max_mr_size;
  66. u32 max_num_mr_pbl;
  67. int max_mw;
  68. int max_fmr;
  69. int max_map_per_fmr;
  70. int max_pages_per_frmr;
  71. u16 max_ord_per_qp;
  72. u16 max_ird_per_qp;
  73. int device_cap_flags;
  74. u8 cq_overflow_detect;
  75. u8 srq_supported;
  76. u32 wqe_size;
  77. u32 rqe_size;
  78. u32 ird_page_size;
  79. u8 local_ca_ack_delay;
  80. u8 ird;
  81. u8 num_ird_pages;
  82. };
  83. struct ocrdma_dma_mem {
  84. void *va;
  85. dma_addr_t pa;
  86. u32 size;
  87. };
  88. struct ocrdma_pbl {
  89. void *va;
  90. dma_addr_t pa;
  91. };
  92. struct ocrdma_queue_info {
  93. void *va;
  94. dma_addr_t dma;
  95. u32 size;
  96. u16 len;
  97. u16 entry_size; /* Size of an element in the queue */
  98. u16 id; /* qid, where to ring the doorbell. */
  99. u16 head, tail;
  100. bool created;
  101. };
  102. struct ocrdma_eq {
  103. struct ocrdma_queue_info q;
  104. u32 vector;
  105. int cq_cnt;
  106. struct ocrdma_dev *dev;
  107. char irq_name[32];
  108. };
  109. struct ocrdma_mq {
  110. struct ocrdma_queue_info sq;
  111. struct ocrdma_queue_info cq;
  112. bool rearm_cq;
  113. };
  114. struct mqe_ctx {
  115. struct mutex lock; /* for serializing mailbox commands on MQ */
  116. wait_queue_head_t cmd_wait;
  117. u32 tag;
  118. u16 cqe_status;
  119. u16 ext_status;
  120. bool cmd_done;
  121. };
  122. struct ocrdma_hw_mr {
  123. u32 lkey;
  124. u8 fr_mr;
  125. u8 remote_atomic;
  126. u8 remote_rd;
  127. u8 remote_wr;
  128. u8 local_rd;
  129. u8 local_wr;
  130. u8 mw_bind;
  131. u8 rsvd;
  132. u64 len;
  133. struct ocrdma_pbl *pbl_table;
  134. u32 num_pbls;
  135. u32 num_pbes;
  136. u32 pbl_size;
  137. u32 pbe_size;
  138. u64 fbo;
  139. u64 va;
  140. };
  141. struct ocrdma_mr {
  142. struct ib_mr ibmr;
  143. struct ib_umem *umem;
  144. struct ocrdma_hw_mr hwmr;
  145. };
  146. struct ocrdma_stats {
  147. u8 type;
  148. struct ocrdma_dev *dev;
  149. };
  150. struct stats_mem {
  151. struct ocrdma_mqe mqe;
  152. void *va;
  153. dma_addr_t pa;
  154. u32 size;
  155. char *debugfs_mem;
  156. };
  157. struct phy_info {
  158. u16 auto_speeds_supported;
  159. u16 fixed_speeds_supported;
  160. u16 phy_type;
  161. u16 interface_type;
  162. };
  163. struct ocrdma_dev {
  164. struct ib_device ibdev;
  165. struct ocrdma_dev_attr attr;
  166. struct mutex dev_lock; /* provides syncronise access to device data */
  167. spinlock_t flush_q_lock ____cacheline_aligned;
  168. struct ocrdma_cq **cq_tbl;
  169. struct ocrdma_qp **qp_tbl;
  170. struct ocrdma_eq *eq_tbl;
  171. int eq_cnt;
  172. u16 base_eqid;
  173. u16 max_eq;
  174. union ib_gid *sgid_tbl;
  175. /* provided synchronization to sgid table for
  176. * updating gid entries triggered by notifier.
  177. */
  178. spinlock_t sgid_lock;
  179. int gsi_qp_created;
  180. struct ocrdma_cq *gsi_sqcq;
  181. struct ocrdma_cq *gsi_rqcq;
  182. struct {
  183. struct ocrdma_av *va;
  184. dma_addr_t pa;
  185. u32 size;
  186. u32 num_ah;
  187. /* provide synchronization for av
  188. * entry allocations.
  189. */
  190. spinlock_t lock;
  191. u32 ahid;
  192. struct ocrdma_pbl pbl;
  193. } av_tbl;
  194. void *mbx_cmd;
  195. struct ocrdma_mq mq;
  196. struct mqe_ctx mqe_ctx;
  197. struct be_dev_info nic_info;
  198. struct phy_info phy;
  199. char model_number[32];
  200. u32 hba_port_num;
  201. struct list_head entry;
  202. struct rcu_head rcu;
  203. int id;
  204. u64 stag_arr[OCRDMA_MAX_STAG];
  205. u16 pvid;
  206. u32 asic_id;
  207. ulong last_stats_time;
  208. struct mutex stats_lock; /* provide synch for debugfs operations */
  209. struct stats_mem stats_mem;
  210. struct ocrdma_stats rsrc_stats;
  211. struct ocrdma_stats rx_stats;
  212. struct ocrdma_stats wqe_stats;
  213. struct ocrdma_stats tx_stats;
  214. struct ocrdma_stats db_err_stats;
  215. struct ocrdma_stats tx_qp_err_stats;
  216. struct ocrdma_stats rx_qp_err_stats;
  217. struct ocrdma_stats tx_dbg_stats;
  218. struct ocrdma_stats rx_dbg_stats;
  219. struct dentry *dir;
  220. };
  221. struct ocrdma_cq {
  222. struct ib_cq ibcq;
  223. struct ocrdma_cqe *va;
  224. u32 phase;
  225. u32 getp; /* pointer to pending wrs to
  226. * return to stack, wrap arounds
  227. * at max_hw_cqe
  228. */
  229. u32 max_hw_cqe;
  230. bool phase_change;
  231. bool deferred_arm, deferred_sol;
  232. bool first_arm;
  233. spinlock_t cq_lock ____cacheline_aligned; /* provide synchronization
  234. * to cq polling
  235. */
  236. /* syncronizes cq completion handler invoked from multiple context */
  237. spinlock_t comp_handler_lock ____cacheline_aligned;
  238. u16 id;
  239. u16 eqn;
  240. struct ocrdma_ucontext *ucontext;
  241. dma_addr_t pa;
  242. u32 len;
  243. u32 cqe_cnt;
  244. /* head of all qp's sq and rq for which cqes need to be flushed
  245. * by the software.
  246. */
  247. struct list_head sq_head, rq_head;
  248. };
  249. struct ocrdma_pd {
  250. struct ib_pd ibpd;
  251. struct ocrdma_ucontext *uctx;
  252. u32 id;
  253. int num_dpp_qp;
  254. u32 dpp_page;
  255. bool dpp_enabled;
  256. };
  257. struct ocrdma_ah {
  258. struct ib_ah ibah;
  259. struct ocrdma_av *av;
  260. u16 sgid_index;
  261. u32 id;
  262. };
  263. struct ocrdma_qp_hwq_info {
  264. u8 *va; /* virtual address */
  265. u32 max_sges;
  266. u32 head, tail;
  267. u32 entry_size;
  268. u32 max_cnt;
  269. u32 max_wqe_idx;
  270. u16 dbid; /* qid, where to ring the doorbell. */
  271. u32 len;
  272. dma_addr_t pa;
  273. };
  274. struct ocrdma_srq {
  275. struct ib_srq ibsrq;
  276. u8 __iomem *db;
  277. struct ocrdma_qp_hwq_info rq;
  278. u64 *rqe_wr_id_tbl;
  279. u32 *idx_bit_fields;
  280. u32 bit_fields_len;
  281. /* provide synchronization to multiple context(s) posting rqe */
  282. spinlock_t q_lock ____cacheline_aligned;
  283. struct ocrdma_pd *pd;
  284. u32 id;
  285. };
  286. struct ocrdma_qp {
  287. struct ib_qp ibqp;
  288. struct ocrdma_dev *dev;
  289. u8 __iomem *sq_db;
  290. struct ocrdma_qp_hwq_info sq;
  291. struct {
  292. uint64_t wrid;
  293. uint16_t dpp_wqe_idx;
  294. uint16_t dpp_wqe;
  295. uint8_t signaled;
  296. uint8_t rsvd[3];
  297. } *wqe_wr_id_tbl;
  298. u32 max_inline_data;
  299. /* provide synchronization to multiple context(s) posting wqe, rqe */
  300. spinlock_t q_lock ____cacheline_aligned;
  301. struct ocrdma_cq *sq_cq;
  302. /* list maintained per CQ to flush SQ errors */
  303. struct list_head sq_entry;
  304. u8 __iomem *rq_db;
  305. struct ocrdma_qp_hwq_info rq;
  306. u64 *rqe_wr_id_tbl;
  307. struct ocrdma_cq *rq_cq;
  308. struct ocrdma_srq *srq;
  309. /* list maintained per CQ to flush RQ errors */
  310. struct list_head rq_entry;
  311. enum ocrdma_qp_state state; /* QP state */
  312. int cap_flags;
  313. u32 max_ord, max_ird;
  314. u32 id;
  315. struct ocrdma_pd *pd;
  316. enum ib_qp_type qp_type;
  317. int sgid_idx;
  318. u32 qkey;
  319. bool dpp_enabled;
  320. u8 *ird_q_va;
  321. bool signaled;
  322. };
  323. struct ocrdma_ucontext {
  324. struct ib_ucontext ibucontext;
  325. struct list_head mm_head;
  326. struct mutex mm_list_lock; /* protects list entries of mm type */
  327. struct ocrdma_pd *cntxt_pd;
  328. int pd_in_use;
  329. struct {
  330. u32 *va;
  331. dma_addr_t pa;
  332. u32 len;
  333. } ah_tbl;
  334. };
  335. struct ocrdma_mm {
  336. struct {
  337. u64 phy_addr;
  338. unsigned long len;
  339. } key;
  340. struct list_head entry;
  341. };
  342. static inline struct ocrdma_dev *get_ocrdma_dev(struct ib_device *ibdev)
  343. {
  344. return container_of(ibdev, struct ocrdma_dev, ibdev);
  345. }
  346. static inline struct ocrdma_ucontext *get_ocrdma_ucontext(struct ib_ucontext
  347. *ibucontext)
  348. {
  349. return container_of(ibucontext, struct ocrdma_ucontext, ibucontext);
  350. }
  351. static inline struct ocrdma_pd *get_ocrdma_pd(struct ib_pd *ibpd)
  352. {
  353. return container_of(ibpd, struct ocrdma_pd, ibpd);
  354. }
  355. static inline struct ocrdma_cq *get_ocrdma_cq(struct ib_cq *ibcq)
  356. {
  357. return container_of(ibcq, struct ocrdma_cq, ibcq);
  358. }
  359. static inline struct ocrdma_qp *get_ocrdma_qp(struct ib_qp *ibqp)
  360. {
  361. return container_of(ibqp, struct ocrdma_qp, ibqp);
  362. }
  363. static inline struct ocrdma_mr *get_ocrdma_mr(struct ib_mr *ibmr)
  364. {
  365. return container_of(ibmr, struct ocrdma_mr, ibmr);
  366. }
  367. static inline struct ocrdma_ah *get_ocrdma_ah(struct ib_ah *ibah)
  368. {
  369. return container_of(ibah, struct ocrdma_ah, ibah);
  370. }
  371. static inline struct ocrdma_srq *get_ocrdma_srq(struct ib_srq *ibsrq)
  372. {
  373. return container_of(ibsrq, struct ocrdma_srq, ibsrq);
  374. }
  375. static inline int is_cqe_valid(struct ocrdma_cq *cq, struct ocrdma_cqe *cqe)
  376. {
  377. int cqe_valid;
  378. cqe_valid = le32_to_cpu(cqe->flags_status_srcqpn) & OCRDMA_CQE_VALID;
  379. return (cqe_valid == cq->phase);
  380. }
  381. static inline int is_cqe_for_sq(struct ocrdma_cqe *cqe)
  382. {
  383. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  384. OCRDMA_CQE_QTYPE) ? 0 : 1;
  385. }
  386. static inline int is_cqe_invalidated(struct ocrdma_cqe *cqe)
  387. {
  388. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  389. OCRDMA_CQE_INVALIDATE) ? 1 : 0;
  390. }
  391. static inline int is_cqe_imm(struct ocrdma_cqe *cqe)
  392. {
  393. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  394. OCRDMA_CQE_IMM) ? 1 : 0;
  395. }
  396. static inline int is_cqe_wr_imm(struct ocrdma_cqe *cqe)
  397. {
  398. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  399. OCRDMA_CQE_WRITE_IMM) ? 1 : 0;
  400. }
  401. static inline int ocrdma_resolve_dmac(struct ocrdma_dev *dev,
  402. struct ib_ah_attr *ah_attr, u8 *mac_addr)
  403. {
  404. struct in6_addr in6;
  405. memcpy(&in6, ah_attr->grh.dgid.raw, sizeof(in6));
  406. if (rdma_is_multicast_addr(&in6))
  407. rdma_get_mcast_mac(&in6, mac_addr);
  408. else
  409. memcpy(mac_addr, ah_attr->dmac, ETH_ALEN);
  410. return 0;
  411. }
  412. static inline char *hca_name(struct ocrdma_dev *dev)
  413. {
  414. switch (dev->nic_info.pdev->device) {
  415. case OC_SKH_DEVICE_PF:
  416. case OC_SKH_DEVICE_VF:
  417. return OC_NAME_SH;
  418. default:
  419. return OC_NAME_UNKNOWN;
  420. }
  421. }
  422. static inline int ocrdma_get_eq_table_index(struct ocrdma_dev *dev,
  423. int eqid)
  424. {
  425. int indx;
  426. for (indx = 0; indx < dev->eq_cnt; indx++) {
  427. if (dev->eq_tbl[indx].q.id == eqid)
  428. return indx;
  429. }
  430. return -EINVAL;
  431. }
  432. static inline u8 ocrdma_get_asic_type(struct ocrdma_dev *dev)
  433. {
  434. if (dev->nic_info.dev_family == 0xF && !dev->asic_id) {
  435. pci_read_config_dword(
  436. dev->nic_info.pdev,
  437. OCRDMA_SLI_ASIC_ID_OFFSET, &dev->asic_id);
  438. }
  439. return (dev->asic_id & OCRDMA_SLI_ASIC_GEN_NUM_MASK) >>
  440. OCRDMA_SLI_ASIC_GEN_NUM_SHIFT;
  441. }
  442. #endif