ocrdma.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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.6.0.0"
  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. #define EQ_INTR_PER_SEC_THRSH_HI 150000
  49. #define EQ_INTR_PER_SEC_THRSH_LOW 100000
  50. #define EQ_AIC_MAX_EQD 20
  51. #define EQ_AIC_MIN_EQD 0
  52. void ocrdma_eqd_set_task(struct work_struct *work);
  53. struct ocrdma_dev_attr {
  54. u8 fw_ver[32];
  55. u32 vendor_id;
  56. u32 device_id;
  57. u16 max_pd;
  58. u16 max_dpp_pds;
  59. u16 max_cq;
  60. u16 max_cqe;
  61. u16 max_qp;
  62. u16 max_wqe;
  63. u16 max_rqe;
  64. u16 max_srq;
  65. u32 max_inline_data;
  66. int max_send_sge;
  67. int max_recv_sge;
  68. int max_srq_sge;
  69. int max_rdma_sge;
  70. int max_mr;
  71. u64 max_mr_size;
  72. u32 max_num_mr_pbl;
  73. int max_mw;
  74. int max_fmr;
  75. int max_map_per_fmr;
  76. int max_pages_per_frmr;
  77. u16 max_ord_per_qp;
  78. u16 max_ird_per_qp;
  79. int device_cap_flags;
  80. u8 cq_overflow_detect;
  81. u8 srq_supported;
  82. u32 wqe_size;
  83. u32 rqe_size;
  84. u32 ird_page_size;
  85. u8 local_ca_ack_delay;
  86. u8 ird;
  87. u8 num_ird_pages;
  88. };
  89. struct ocrdma_dma_mem {
  90. void *va;
  91. dma_addr_t pa;
  92. u32 size;
  93. };
  94. struct ocrdma_pbl {
  95. void *va;
  96. dma_addr_t pa;
  97. };
  98. struct ocrdma_queue_info {
  99. void *va;
  100. dma_addr_t dma;
  101. u32 size;
  102. u16 len;
  103. u16 entry_size; /* Size of an element in the queue */
  104. u16 id; /* qid, where to ring the doorbell. */
  105. u16 head, tail;
  106. bool created;
  107. };
  108. struct ocrdma_aic_obj { /* Adaptive interrupt coalescing (AIC) info */
  109. u32 prev_eqd;
  110. u64 eq_intr_cnt;
  111. u64 prev_eq_intr_cnt;
  112. };
  113. struct ocrdma_eq {
  114. struct ocrdma_queue_info q;
  115. u32 vector;
  116. int cq_cnt;
  117. struct ocrdma_dev *dev;
  118. char irq_name[32];
  119. struct ocrdma_aic_obj aic_obj;
  120. };
  121. struct ocrdma_mq {
  122. struct ocrdma_queue_info sq;
  123. struct ocrdma_queue_info cq;
  124. bool rearm_cq;
  125. };
  126. struct mqe_ctx {
  127. struct mutex lock; /* for serializing mailbox commands on MQ */
  128. wait_queue_head_t cmd_wait;
  129. u32 tag;
  130. u16 cqe_status;
  131. u16 ext_status;
  132. bool cmd_done;
  133. bool fw_error_state;
  134. };
  135. struct ocrdma_hw_mr {
  136. u32 lkey;
  137. u8 fr_mr;
  138. u8 remote_atomic;
  139. u8 remote_rd;
  140. u8 remote_wr;
  141. u8 local_rd;
  142. u8 local_wr;
  143. u8 mw_bind;
  144. u8 rsvd;
  145. u64 len;
  146. struct ocrdma_pbl *pbl_table;
  147. u32 num_pbls;
  148. u32 num_pbes;
  149. u32 pbl_size;
  150. u32 pbe_size;
  151. u64 fbo;
  152. u64 va;
  153. };
  154. struct ocrdma_mr {
  155. struct ib_mr ibmr;
  156. struct ib_umem *umem;
  157. struct ocrdma_hw_mr hwmr;
  158. };
  159. struct ocrdma_stats {
  160. u8 type;
  161. struct ocrdma_dev *dev;
  162. };
  163. struct ocrdma_pd_resource_mgr {
  164. u32 pd_norm_start;
  165. u16 pd_norm_count;
  166. u16 pd_norm_thrsh;
  167. u16 max_normal_pd;
  168. u32 pd_dpp_start;
  169. u16 pd_dpp_count;
  170. u16 pd_dpp_thrsh;
  171. u16 max_dpp_pd;
  172. u16 dpp_page_index;
  173. unsigned long *pd_norm_bitmap;
  174. unsigned long *pd_dpp_bitmap;
  175. bool pd_prealloc_valid;
  176. };
  177. struct stats_mem {
  178. struct ocrdma_mqe mqe;
  179. void *va;
  180. dma_addr_t pa;
  181. u32 size;
  182. char *debugfs_mem;
  183. };
  184. struct phy_info {
  185. u16 auto_speeds_supported;
  186. u16 fixed_speeds_supported;
  187. u16 phy_type;
  188. u16 interface_type;
  189. };
  190. struct ocrdma_dev {
  191. struct ib_device ibdev;
  192. struct ocrdma_dev_attr attr;
  193. struct mutex dev_lock; /* provides syncronise access to device data */
  194. spinlock_t flush_q_lock ____cacheline_aligned;
  195. struct ocrdma_cq **cq_tbl;
  196. struct ocrdma_qp **qp_tbl;
  197. struct ocrdma_eq *eq_tbl;
  198. int eq_cnt;
  199. struct delayed_work eqd_work;
  200. u16 base_eqid;
  201. u16 max_eq;
  202. union ib_gid *sgid_tbl;
  203. /* provided synchronization to sgid table for
  204. * updating gid entries triggered by notifier.
  205. */
  206. spinlock_t sgid_lock;
  207. int gsi_qp_created;
  208. struct ocrdma_cq *gsi_sqcq;
  209. struct ocrdma_cq *gsi_rqcq;
  210. struct {
  211. struct ocrdma_av *va;
  212. dma_addr_t pa;
  213. u32 size;
  214. u32 num_ah;
  215. /* provide synchronization for av
  216. * entry allocations.
  217. */
  218. spinlock_t lock;
  219. u32 ahid;
  220. struct ocrdma_pbl pbl;
  221. } av_tbl;
  222. void *mbx_cmd;
  223. struct ocrdma_mq mq;
  224. struct mqe_ctx mqe_ctx;
  225. struct be_dev_info nic_info;
  226. struct phy_info phy;
  227. char model_number[32];
  228. u32 hba_port_num;
  229. struct list_head entry;
  230. struct rcu_head rcu;
  231. int id;
  232. u64 *stag_arr;
  233. u8 sl; /* service level */
  234. bool pfc_state;
  235. atomic_t update_sl;
  236. u16 pvid;
  237. u32 asic_id;
  238. ulong last_stats_time;
  239. struct mutex stats_lock; /* provide synch for debugfs operations */
  240. struct stats_mem stats_mem;
  241. struct ocrdma_stats rsrc_stats;
  242. struct ocrdma_stats rx_stats;
  243. struct ocrdma_stats wqe_stats;
  244. struct ocrdma_stats tx_stats;
  245. struct ocrdma_stats db_err_stats;
  246. struct ocrdma_stats tx_qp_err_stats;
  247. struct ocrdma_stats rx_qp_err_stats;
  248. struct ocrdma_stats tx_dbg_stats;
  249. struct ocrdma_stats rx_dbg_stats;
  250. struct ocrdma_stats driver_stats;
  251. struct ocrdma_stats reset_stats;
  252. struct dentry *dir;
  253. atomic_t async_err_stats[OCRDMA_MAX_ASYNC_ERRORS];
  254. atomic_t cqe_err_stats[OCRDMA_MAX_CQE_ERR];
  255. struct ocrdma_pd_resource_mgr *pd_mgr;
  256. };
  257. struct ocrdma_cq {
  258. struct ib_cq ibcq;
  259. struct ocrdma_cqe *va;
  260. u32 phase;
  261. u32 getp; /* pointer to pending wrs to
  262. * return to stack, wrap arounds
  263. * at max_hw_cqe
  264. */
  265. u32 max_hw_cqe;
  266. bool phase_change;
  267. bool deferred_arm, deferred_sol;
  268. bool first_arm;
  269. spinlock_t cq_lock ____cacheline_aligned; /* provide synchronization
  270. * to cq polling
  271. */
  272. /* syncronizes cq completion handler invoked from multiple context */
  273. spinlock_t comp_handler_lock ____cacheline_aligned;
  274. u16 id;
  275. u16 eqn;
  276. struct ocrdma_ucontext *ucontext;
  277. dma_addr_t pa;
  278. u32 len;
  279. u32 cqe_cnt;
  280. /* head of all qp's sq and rq for which cqes need to be flushed
  281. * by the software.
  282. */
  283. struct list_head sq_head, rq_head;
  284. };
  285. struct ocrdma_pd {
  286. struct ib_pd ibpd;
  287. struct ocrdma_ucontext *uctx;
  288. u32 id;
  289. int num_dpp_qp;
  290. u32 dpp_page;
  291. bool dpp_enabled;
  292. };
  293. struct ocrdma_ah {
  294. struct ib_ah ibah;
  295. struct ocrdma_av *av;
  296. u16 sgid_index;
  297. u32 id;
  298. };
  299. struct ocrdma_qp_hwq_info {
  300. u8 *va; /* virtual address */
  301. u32 max_sges;
  302. u32 head, tail;
  303. u32 entry_size;
  304. u32 max_cnt;
  305. u32 max_wqe_idx;
  306. u16 dbid; /* qid, where to ring the doorbell. */
  307. u32 len;
  308. dma_addr_t pa;
  309. };
  310. struct ocrdma_srq {
  311. struct ib_srq ibsrq;
  312. u8 __iomem *db;
  313. struct ocrdma_qp_hwq_info rq;
  314. u64 *rqe_wr_id_tbl;
  315. u32 *idx_bit_fields;
  316. u32 bit_fields_len;
  317. /* provide synchronization to multiple context(s) posting rqe */
  318. spinlock_t q_lock ____cacheline_aligned;
  319. struct ocrdma_pd *pd;
  320. u32 id;
  321. };
  322. struct ocrdma_qp {
  323. struct ib_qp ibqp;
  324. u8 __iomem *sq_db;
  325. struct ocrdma_qp_hwq_info sq;
  326. struct {
  327. uint64_t wrid;
  328. uint16_t dpp_wqe_idx;
  329. uint16_t dpp_wqe;
  330. uint8_t signaled;
  331. uint8_t rsvd[3];
  332. } *wqe_wr_id_tbl;
  333. u32 max_inline_data;
  334. /* provide synchronization to multiple context(s) posting wqe, rqe */
  335. spinlock_t q_lock ____cacheline_aligned;
  336. struct ocrdma_cq *sq_cq;
  337. /* list maintained per CQ to flush SQ errors */
  338. struct list_head sq_entry;
  339. u8 __iomem *rq_db;
  340. struct ocrdma_qp_hwq_info rq;
  341. u64 *rqe_wr_id_tbl;
  342. struct ocrdma_cq *rq_cq;
  343. struct ocrdma_srq *srq;
  344. /* list maintained per CQ to flush RQ errors */
  345. struct list_head rq_entry;
  346. enum ocrdma_qp_state state; /* QP state */
  347. int cap_flags;
  348. u32 max_ord, max_ird;
  349. u32 id;
  350. struct ocrdma_pd *pd;
  351. enum ib_qp_type qp_type;
  352. int sgid_idx;
  353. u32 qkey;
  354. bool dpp_enabled;
  355. u8 *ird_q_va;
  356. bool signaled;
  357. };
  358. struct ocrdma_ucontext {
  359. struct ib_ucontext ibucontext;
  360. struct list_head mm_head;
  361. struct mutex mm_list_lock; /* protects list entries of mm type */
  362. struct ocrdma_pd *cntxt_pd;
  363. int pd_in_use;
  364. struct {
  365. u32 *va;
  366. dma_addr_t pa;
  367. u32 len;
  368. } ah_tbl;
  369. };
  370. struct ocrdma_mm {
  371. struct {
  372. u64 phy_addr;
  373. unsigned long len;
  374. } key;
  375. struct list_head entry;
  376. };
  377. static inline struct ocrdma_dev *get_ocrdma_dev(struct ib_device *ibdev)
  378. {
  379. return container_of(ibdev, struct ocrdma_dev, ibdev);
  380. }
  381. static inline struct ocrdma_ucontext *get_ocrdma_ucontext(struct ib_ucontext
  382. *ibucontext)
  383. {
  384. return container_of(ibucontext, struct ocrdma_ucontext, ibucontext);
  385. }
  386. static inline struct ocrdma_pd *get_ocrdma_pd(struct ib_pd *ibpd)
  387. {
  388. return container_of(ibpd, struct ocrdma_pd, ibpd);
  389. }
  390. static inline struct ocrdma_cq *get_ocrdma_cq(struct ib_cq *ibcq)
  391. {
  392. return container_of(ibcq, struct ocrdma_cq, ibcq);
  393. }
  394. static inline struct ocrdma_qp *get_ocrdma_qp(struct ib_qp *ibqp)
  395. {
  396. return container_of(ibqp, struct ocrdma_qp, ibqp);
  397. }
  398. static inline struct ocrdma_mr *get_ocrdma_mr(struct ib_mr *ibmr)
  399. {
  400. return container_of(ibmr, struct ocrdma_mr, ibmr);
  401. }
  402. static inline struct ocrdma_ah *get_ocrdma_ah(struct ib_ah *ibah)
  403. {
  404. return container_of(ibah, struct ocrdma_ah, ibah);
  405. }
  406. static inline struct ocrdma_srq *get_ocrdma_srq(struct ib_srq *ibsrq)
  407. {
  408. return container_of(ibsrq, struct ocrdma_srq, ibsrq);
  409. }
  410. static inline int is_cqe_valid(struct ocrdma_cq *cq, struct ocrdma_cqe *cqe)
  411. {
  412. int cqe_valid;
  413. cqe_valid = le32_to_cpu(cqe->flags_status_srcqpn) & OCRDMA_CQE_VALID;
  414. return (cqe_valid == cq->phase);
  415. }
  416. static inline int is_cqe_for_sq(struct ocrdma_cqe *cqe)
  417. {
  418. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  419. OCRDMA_CQE_QTYPE) ? 0 : 1;
  420. }
  421. static inline int is_cqe_invalidated(struct ocrdma_cqe *cqe)
  422. {
  423. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  424. OCRDMA_CQE_INVALIDATE) ? 1 : 0;
  425. }
  426. static inline int is_cqe_imm(struct ocrdma_cqe *cqe)
  427. {
  428. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  429. OCRDMA_CQE_IMM) ? 1 : 0;
  430. }
  431. static inline int is_cqe_wr_imm(struct ocrdma_cqe *cqe)
  432. {
  433. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  434. OCRDMA_CQE_WRITE_IMM) ? 1 : 0;
  435. }
  436. static inline int ocrdma_resolve_dmac(struct ocrdma_dev *dev,
  437. struct ib_ah_attr *ah_attr, u8 *mac_addr)
  438. {
  439. struct in6_addr in6;
  440. memcpy(&in6, ah_attr->grh.dgid.raw, sizeof(in6));
  441. if (rdma_is_multicast_addr(&in6))
  442. rdma_get_mcast_mac(&in6, mac_addr);
  443. else if (rdma_link_local_addr(&in6))
  444. rdma_get_ll_mac(&in6, mac_addr);
  445. else
  446. memcpy(mac_addr, ah_attr->dmac, ETH_ALEN);
  447. return 0;
  448. }
  449. static inline char *hca_name(struct ocrdma_dev *dev)
  450. {
  451. switch (dev->nic_info.pdev->device) {
  452. case OC_SKH_DEVICE_PF:
  453. case OC_SKH_DEVICE_VF:
  454. return OC_NAME_SH;
  455. default:
  456. return OC_NAME_UNKNOWN;
  457. }
  458. }
  459. static inline int ocrdma_get_eq_table_index(struct ocrdma_dev *dev,
  460. int eqid)
  461. {
  462. int indx;
  463. for (indx = 0; indx < dev->eq_cnt; indx++) {
  464. if (dev->eq_tbl[indx].q.id == eqid)
  465. return indx;
  466. }
  467. return -EINVAL;
  468. }
  469. static inline u8 ocrdma_get_asic_type(struct ocrdma_dev *dev)
  470. {
  471. if (dev->nic_info.dev_family == 0xF && !dev->asic_id) {
  472. pci_read_config_dword(
  473. dev->nic_info.pdev,
  474. OCRDMA_SLI_ASIC_ID_OFFSET, &dev->asic_id);
  475. }
  476. return (dev->asic_id & OCRDMA_SLI_ASIC_GEN_NUM_MASK) >>
  477. OCRDMA_SLI_ASIC_GEN_NUM_SHIFT;
  478. }
  479. static inline u8 ocrdma_get_pfc_prio(u8 *pfc, u8 prio)
  480. {
  481. return *(pfc + prio);
  482. }
  483. static inline u8 ocrdma_get_app_prio(u8 *app_prio, u8 prio)
  484. {
  485. return *(app_prio + prio);
  486. }
  487. static inline u8 ocrdma_is_enabled_and_synced(u32 state)
  488. { /* May also be used to interpret TC-state, QCN-state
  489. * Appl-state and Logical-link-state in future.
  490. */
  491. return (state & OCRDMA_STATE_FLAG_ENABLED) &&
  492. (state & OCRDMA_STATE_FLAG_SYNC);
  493. }
  494. #endif