ocrdma.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /* This file is part of the Emulex RoCE Device Driver for
  2. * RoCE (RDMA over Converged Ethernet) adapters.
  3. * Copyright (C) 2012-2015 Emulex. All rights reserved.
  4. * EMULEX and SLI are trademarks of Emulex.
  5. * www.emulex.com
  6. *
  7. * This software is available to you under a choice of one of two licenses.
  8. * You may choose to be licensed under the terms of the GNU General Public
  9. * License (GPL) Version 2, available from the file COPYING in the main
  10. * directory of this source tree, or the BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in
  21. * the documentation and/or other materials provided with the distribution.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  30. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  31. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  32. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  33. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * Contact Information:
  36. * linux-drivers@emulex.com
  37. *
  38. * Emulex
  39. * 3333 Susan Street
  40. * Costa Mesa, CA 92626
  41. */
  42. #ifndef __OCRDMA_H__
  43. #define __OCRDMA_H__
  44. #include <linux/mutex.h>
  45. #include <linux/list.h>
  46. #include <linux/spinlock.h>
  47. #include <linux/pci.h>
  48. #include <rdma/ib_verbs.h>
  49. #include <rdma/ib_user_verbs.h>
  50. #include <rdma/ib_addr.h>
  51. #include <be_roce.h>
  52. #include "ocrdma_sli.h"
  53. #define OCRDMA_ROCE_DRV_VERSION "11.0.0.0"
  54. #define OCRDMA_ROCE_DRV_DESC "Emulex OneConnect RoCE Driver"
  55. #define OCRDMA_NODE_DESC "Emulex OneConnect RoCE HCA"
  56. #define OC_NAME_SH OCRDMA_NODE_DESC "(Skyhawk)"
  57. #define OC_NAME_UNKNOWN OCRDMA_NODE_DESC "(Unknown)"
  58. #define OC_SKH_DEVICE_PF 0x720
  59. #define OC_SKH_DEVICE_VF 0x728
  60. #define OCRDMA_MAX_AH 512
  61. #define OCRDMA_UVERBS(CMD_NAME) (1ull << IB_USER_VERBS_CMD_##CMD_NAME)
  62. #define convert_to_64bit(lo, hi) ((u64)hi << 32 | (u64)lo)
  63. #define EQ_INTR_PER_SEC_THRSH_HI 150000
  64. #define EQ_INTR_PER_SEC_THRSH_LOW 100000
  65. #define EQ_AIC_MAX_EQD 20
  66. #define EQ_AIC_MIN_EQD 0
  67. void ocrdma_eqd_set_task(struct work_struct *work);
  68. struct ocrdma_dev_attr {
  69. u8 fw_ver[32];
  70. u32 vendor_id;
  71. u32 device_id;
  72. u16 max_pd;
  73. u16 max_dpp_pds;
  74. u16 max_cq;
  75. u16 max_cqe;
  76. u16 max_qp;
  77. u16 max_wqe;
  78. u16 max_rqe;
  79. u16 max_srq;
  80. u32 max_inline_data;
  81. int max_send_sge;
  82. int max_recv_sge;
  83. int max_srq_sge;
  84. int max_rdma_sge;
  85. int max_mr;
  86. u64 max_mr_size;
  87. u32 max_num_mr_pbl;
  88. int max_mw;
  89. int max_fmr;
  90. int max_map_per_fmr;
  91. int max_pages_per_frmr;
  92. u16 max_ord_per_qp;
  93. u16 max_ird_per_qp;
  94. int device_cap_flags;
  95. u8 cq_overflow_detect;
  96. u8 srq_supported;
  97. u32 wqe_size;
  98. u32 rqe_size;
  99. u32 ird_page_size;
  100. u8 local_ca_ack_delay;
  101. u8 ird;
  102. u8 num_ird_pages;
  103. u8 udp_encap;
  104. };
  105. struct ocrdma_dma_mem {
  106. void *va;
  107. dma_addr_t pa;
  108. u32 size;
  109. };
  110. struct ocrdma_pbl {
  111. void *va;
  112. dma_addr_t pa;
  113. };
  114. struct ocrdma_queue_info {
  115. void *va;
  116. dma_addr_t dma;
  117. u32 size;
  118. u16 len;
  119. u16 entry_size; /* Size of an element in the queue */
  120. u16 id; /* qid, where to ring the doorbell. */
  121. u16 head, tail;
  122. bool created;
  123. };
  124. struct ocrdma_aic_obj { /* Adaptive interrupt coalescing (AIC) info */
  125. u32 prev_eqd;
  126. u64 eq_intr_cnt;
  127. u64 prev_eq_intr_cnt;
  128. };
  129. struct ocrdma_eq {
  130. struct ocrdma_queue_info q;
  131. u32 vector;
  132. int cq_cnt;
  133. struct ocrdma_dev *dev;
  134. char irq_name[32];
  135. struct ocrdma_aic_obj aic_obj;
  136. };
  137. struct ocrdma_mq {
  138. struct ocrdma_queue_info sq;
  139. struct ocrdma_queue_info cq;
  140. bool rearm_cq;
  141. };
  142. struct mqe_ctx {
  143. struct mutex lock; /* for serializing mailbox commands on MQ */
  144. wait_queue_head_t cmd_wait;
  145. u32 tag;
  146. u16 cqe_status;
  147. u16 ext_status;
  148. bool cmd_done;
  149. bool fw_error_state;
  150. };
  151. struct ocrdma_hw_mr {
  152. u32 lkey;
  153. u8 fr_mr;
  154. u8 remote_atomic;
  155. u8 remote_rd;
  156. u8 remote_wr;
  157. u8 local_rd;
  158. u8 local_wr;
  159. u8 mw_bind;
  160. u8 rsvd;
  161. u64 len;
  162. struct ocrdma_pbl *pbl_table;
  163. u32 num_pbls;
  164. u32 num_pbes;
  165. u32 pbl_size;
  166. u32 pbe_size;
  167. u64 fbo;
  168. u64 va;
  169. };
  170. struct ocrdma_mr {
  171. struct ib_mr ibmr;
  172. struct ib_umem *umem;
  173. struct ocrdma_hw_mr hwmr;
  174. u64 *pages;
  175. u32 npages;
  176. };
  177. struct ocrdma_stats {
  178. u8 type;
  179. struct ocrdma_dev *dev;
  180. };
  181. struct ocrdma_pd_resource_mgr {
  182. u32 pd_norm_start;
  183. u16 pd_norm_count;
  184. u16 pd_norm_thrsh;
  185. u16 max_normal_pd;
  186. u32 pd_dpp_start;
  187. u16 pd_dpp_count;
  188. u16 pd_dpp_thrsh;
  189. u16 max_dpp_pd;
  190. u16 dpp_page_index;
  191. unsigned long *pd_norm_bitmap;
  192. unsigned long *pd_dpp_bitmap;
  193. bool pd_prealloc_valid;
  194. };
  195. struct stats_mem {
  196. struct ocrdma_mqe mqe;
  197. void *va;
  198. dma_addr_t pa;
  199. u32 size;
  200. char *debugfs_mem;
  201. };
  202. struct phy_info {
  203. u16 auto_speeds_supported;
  204. u16 fixed_speeds_supported;
  205. u16 phy_type;
  206. u16 interface_type;
  207. };
  208. enum ocrdma_flags {
  209. OCRDMA_FLAGS_LINK_STATUS_INIT = 0x01
  210. };
  211. struct ocrdma_dev {
  212. struct ib_device ibdev;
  213. struct ocrdma_dev_attr attr;
  214. struct mutex dev_lock; /* provides syncronise access to device data */
  215. spinlock_t flush_q_lock ____cacheline_aligned;
  216. struct ocrdma_cq **cq_tbl;
  217. struct ocrdma_qp **qp_tbl;
  218. struct ocrdma_eq *eq_tbl;
  219. int eq_cnt;
  220. struct delayed_work eqd_work;
  221. u16 base_eqid;
  222. u16 max_eq;
  223. /* provided synchronization to sgid table for
  224. * updating gid entries triggered by notifier.
  225. */
  226. spinlock_t sgid_lock;
  227. int gsi_qp_created;
  228. struct ocrdma_cq *gsi_sqcq;
  229. struct ocrdma_cq *gsi_rqcq;
  230. struct {
  231. struct ocrdma_av *va;
  232. dma_addr_t pa;
  233. u32 size;
  234. u32 num_ah;
  235. /* provide synchronization for av
  236. * entry allocations.
  237. */
  238. spinlock_t lock;
  239. u32 ahid;
  240. struct ocrdma_pbl pbl;
  241. } av_tbl;
  242. void *mbx_cmd;
  243. struct ocrdma_mq mq;
  244. struct mqe_ctx mqe_ctx;
  245. struct be_dev_info nic_info;
  246. struct phy_info phy;
  247. char model_number[32];
  248. u32 hba_port_num;
  249. struct list_head entry;
  250. int id;
  251. u64 *stag_arr;
  252. u8 sl; /* service level */
  253. bool pfc_state;
  254. atomic_t update_sl;
  255. u16 pvid;
  256. u32 asic_id;
  257. u32 flags;
  258. ulong last_stats_time;
  259. struct mutex stats_lock; /* provide synch for debugfs operations */
  260. struct stats_mem stats_mem;
  261. struct ocrdma_stats rsrc_stats;
  262. struct ocrdma_stats rx_stats;
  263. struct ocrdma_stats wqe_stats;
  264. struct ocrdma_stats tx_stats;
  265. struct ocrdma_stats db_err_stats;
  266. struct ocrdma_stats tx_qp_err_stats;
  267. struct ocrdma_stats rx_qp_err_stats;
  268. struct ocrdma_stats tx_dbg_stats;
  269. struct ocrdma_stats rx_dbg_stats;
  270. struct ocrdma_stats driver_stats;
  271. struct ocrdma_stats reset_stats;
  272. struct dentry *dir;
  273. atomic_t async_err_stats[OCRDMA_MAX_ASYNC_ERRORS];
  274. atomic_t cqe_err_stats[OCRDMA_MAX_CQE_ERR];
  275. struct ocrdma_pd_resource_mgr *pd_mgr;
  276. };
  277. struct ocrdma_cq {
  278. struct ib_cq ibcq;
  279. struct ocrdma_cqe *va;
  280. u32 phase;
  281. u32 getp; /* pointer to pending wrs to
  282. * return to stack, wrap arounds
  283. * at max_hw_cqe
  284. */
  285. u32 max_hw_cqe;
  286. bool phase_change;
  287. spinlock_t cq_lock ____cacheline_aligned; /* provide synchronization
  288. * to cq polling
  289. */
  290. /* syncronizes cq completion handler invoked from multiple context */
  291. spinlock_t comp_handler_lock ____cacheline_aligned;
  292. u16 id;
  293. u16 eqn;
  294. struct ocrdma_ucontext *ucontext;
  295. dma_addr_t pa;
  296. u32 len;
  297. u32 cqe_cnt;
  298. /* head of all qp's sq and rq for which cqes need to be flushed
  299. * by the software.
  300. */
  301. struct list_head sq_head, rq_head;
  302. };
  303. struct ocrdma_pd {
  304. struct ib_pd ibpd;
  305. struct ocrdma_ucontext *uctx;
  306. u32 id;
  307. int num_dpp_qp;
  308. u32 dpp_page;
  309. bool dpp_enabled;
  310. };
  311. struct ocrdma_ah {
  312. struct ib_ah ibah;
  313. struct ocrdma_av *av;
  314. u16 sgid_index;
  315. u32 id;
  316. u8 hdr_type;
  317. };
  318. struct ocrdma_qp_hwq_info {
  319. u8 *va; /* virtual address */
  320. u32 max_sges;
  321. u32 head, tail;
  322. u32 entry_size;
  323. u32 max_cnt;
  324. u32 max_wqe_idx;
  325. u16 dbid; /* qid, where to ring the doorbell. */
  326. u32 len;
  327. dma_addr_t pa;
  328. };
  329. struct ocrdma_srq {
  330. struct ib_srq ibsrq;
  331. u8 __iomem *db;
  332. struct ocrdma_qp_hwq_info rq;
  333. u64 *rqe_wr_id_tbl;
  334. u32 *idx_bit_fields;
  335. u32 bit_fields_len;
  336. /* provide synchronization to multiple context(s) posting rqe */
  337. spinlock_t q_lock ____cacheline_aligned;
  338. struct ocrdma_pd *pd;
  339. u32 id;
  340. };
  341. struct ocrdma_qp {
  342. struct ib_qp ibqp;
  343. u8 __iomem *sq_db;
  344. struct ocrdma_qp_hwq_info sq;
  345. struct {
  346. uint64_t wrid;
  347. uint16_t dpp_wqe_idx;
  348. uint16_t dpp_wqe;
  349. uint8_t signaled;
  350. uint8_t rsvd[3];
  351. } *wqe_wr_id_tbl;
  352. u32 max_inline_data;
  353. /* provide synchronization to multiple context(s) posting wqe, rqe */
  354. spinlock_t q_lock ____cacheline_aligned;
  355. struct ocrdma_cq *sq_cq;
  356. /* list maintained per CQ to flush SQ errors */
  357. struct list_head sq_entry;
  358. u8 __iomem *rq_db;
  359. struct ocrdma_qp_hwq_info rq;
  360. u64 *rqe_wr_id_tbl;
  361. struct ocrdma_cq *rq_cq;
  362. struct ocrdma_srq *srq;
  363. /* list maintained per CQ to flush RQ errors */
  364. struct list_head rq_entry;
  365. enum ocrdma_qp_state state; /* QP state */
  366. int cap_flags;
  367. u32 max_ord, max_ird;
  368. u32 id;
  369. struct ocrdma_pd *pd;
  370. enum ib_qp_type qp_type;
  371. int sgid_idx;
  372. u32 qkey;
  373. bool dpp_enabled;
  374. u8 *ird_q_va;
  375. bool signaled;
  376. };
  377. struct ocrdma_ucontext {
  378. struct ib_ucontext ibucontext;
  379. struct list_head mm_head;
  380. struct mutex mm_list_lock; /* protects list entries of mm type */
  381. struct ocrdma_pd *cntxt_pd;
  382. int pd_in_use;
  383. struct {
  384. u32 *va;
  385. dma_addr_t pa;
  386. u32 len;
  387. } ah_tbl;
  388. };
  389. struct ocrdma_mm {
  390. struct {
  391. u64 phy_addr;
  392. unsigned long len;
  393. } key;
  394. struct list_head entry;
  395. };
  396. static inline struct ocrdma_dev *get_ocrdma_dev(struct ib_device *ibdev)
  397. {
  398. return container_of(ibdev, struct ocrdma_dev, ibdev);
  399. }
  400. static inline struct ocrdma_ucontext *get_ocrdma_ucontext(struct ib_ucontext
  401. *ibucontext)
  402. {
  403. return container_of(ibucontext, struct ocrdma_ucontext, ibucontext);
  404. }
  405. static inline struct ocrdma_pd *get_ocrdma_pd(struct ib_pd *ibpd)
  406. {
  407. return container_of(ibpd, struct ocrdma_pd, ibpd);
  408. }
  409. static inline struct ocrdma_cq *get_ocrdma_cq(struct ib_cq *ibcq)
  410. {
  411. return container_of(ibcq, struct ocrdma_cq, ibcq);
  412. }
  413. static inline struct ocrdma_qp *get_ocrdma_qp(struct ib_qp *ibqp)
  414. {
  415. return container_of(ibqp, struct ocrdma_qp, ibqp);
  416. }
  417. static inline struct ocrdma_mr *get_ocrdma_mr(struct ib_mr *ibmr)
  418. {
  419. return container_of(ibmr, struct ocrdma_mr, ibmr);
  420. }
  421. static inline struct ocrdma_ah *get_ocrdma_ah(struct ib_ah *ibah)
  422. {
  423. return container_of(ibah, struct ocrdma_ah, ibah);
  424. }
  425. static inline struct ocrdma_srq *get_ocrdma_srq(struct ib_srq *ibsrq)
  426. {
  427. return container_of(ibsrq, struct ocrdma_srq, ibsrq);
  428. }
  429. static inline int is_cqe_valid(struct ocrdma_cq *cq, struct ocrdma_cqe *cqe)
  430. {
  431. int cqe_valid;
  432. cqe_valid = le32_to_cpu(cqe->flags_status_srcqpn) & OCRDMA_CQE_VALID;
  433. return (cqe_valid == cq->phase);
  434. }
  435. static inline int is_cqe_for_sq(struct ocrdma_cqe *cqe)
  436. {
  437. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  438. OCRDMA_CQE_QTYPE) ? 0 : 1;
  439. }
  440. static inline int is_cqe_invalidated(struct ocrdma_cqe *cqe)
  441. {
  442. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  443. OCRDMA_CQE_INVALIDATE) ? 1 : 0;
  444. }
  445. static inline int is_cqe_imm(struct ocrdma_cqe *cqe)
  446. {
  447. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  448. OCRDMA_CQE_IMM) ? 1 : 0;
  449. }
  450. static inline int is_cqe_wr_imm(struct ocrdma_cqe *cqe)
  451. {
  452. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  453. OCRDMA_CQE_WRITE_IMM) ? 1 : 0;
  454. }
  455. static inline int ocrdma_resolve_dmac(struct ocrdma_dev *dev,
  456. struct rdma_ah_attr *ah_attr, u8 *mac_addr)
  457. {
  458. struct in6_addr in6;
  459. memcpy(&in6, rdma_ah_read_grh(ah_attr)->dgid.raw, sizeof(in6));
  460. if (rdma_is_multicast_addr(&in6))
  461. rdma_get_mcast_mac(&in6, mac_addr);
  462. else if (rdma_link_local_addr(&in6))
  463. rdma_get_ll_mac(&in6, mac_addr);
  464. else
  465. memcpy(mac_addr, ah_attr->roce.dmac, ETH_ALEN);
  466. return 0;
  467. }
  468. static inline char *hca_name(struct ocrdma_dev *dev)
  469. {
  470. switch (dev->nic_info.pdev->device) {
  471. case OC_SKH_DEVICE_PF:
  472. case OC_SKH_DEVICE_VF:
  473. return OC_NAME_SH;
  474. default:
  475. return OC_NAME_UNKNOWN;
  476. }
  477. }
  478. static inline int ocrdma_get_eq_table_index(struct ocrdma_dev *dev,
  479. int eqid)
  480. {
  481. int indx;
  482. for (indx = 0; indx < dev->eq_cnt; indx++) {
  483. if (dev->eq_tbl[indx].q.id == eqid)
  484. return indx;
  485. }
  486. return -EINVAL;
  487. }
  488. static inline u8 ocrdma_get_asic_type(struct ocrdma_dev *dev)
  489. {
  490. if (dev->nic_info.dev_family == 0xF && !dev->asic_id) {
  491. pci_read_config_dword(
  492. dev->nic_info.pdev,
  493. OCRDMA_SLI_ASIC_ID_OFFSET, &dev->asic_id);
  494. }
  495. return (dev->asic_id & OCRDMA_SLI_ASIC_GEN_NUM_MASK) >>
  496. OCRDMA_SLI_ASIC_GEN_NUM_SHIFT;
  497. }
  498. static inline u8 ocrdma_get_pfc_prio(u8 *pfc, u8 prio)
  499. {
  500. return *(pfc + prio);
  501. }
  502. static inline u8 ocrdma_get_app_prio(u8 *app_prio, u8 prio)
  503. {
  504. return *(app_prio + prio);
  505. }
  506. static inline u8 ocrdma_is_enabled_and_synced(u32 state)
  507. { /* May also be used to interpret TC-state, QCN-state
  508. * Appl-state and Logical-link-state in future.
  509. */
  510. return (state & OCRDMA_STATE_FLAG_ENABLED) &&
  511. (state & OCRDMA_STATE_FLAG_SYNC);
  512. }
  513. static inline u8 ocrdma_get_ae_link_state(u32 ae_state)
  514. {
  515. return ((ae_state & OCRDMA_AE_LSC_LS_MASK) >> OCRDMA_AE_LSC_LS_SHIFT);
  516. }
  517. static inline bool ocrdma_is_udp_encap_supported(struct ocrdma_dev *dev)
  518. {
  519. return (dev->attr.udp_encap & OCRDMA_L3_TYPE_IPV4) ||
  520. (dev->attr.udp_encap & OCRDMA_L3_TYPE_IPV6);
  521. }
  522. #endif