hns_roce_device.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /*
  2. * Copyright (c) 2016 Hisilicon Limited.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef _HNS_ROCE_DEVICE_H
  33. #define _HNS_ROCE_DEVICE_H
  34. #include <rdma/ib_verbs.h>
  35. #define DRV_NAME "hns_roce"
  36. #define HNS_ROCE_HW_VER1 ('h' << 24 | 'i' << 16 | '0' << 8 | '6')
  37. #define MAC_ADDR_OCTET_NUM 6
  38. #define HNS_ROCE_MAX_MSG_LEN 0x80000000
  39. #define HNS_ROCE_ALOGN_UP(a, b) ((((a) + (b) - 1) / (b)) * (b))
  40. #define HNS_ROCE_IB_MIN_SQ_STRIDE 6
  41. #define HNS_ROCE_BA_SIZE (32 * 4096)
  42. /* Hardware specification only for v1 engine */
  43. #define HNS_ROCE_MIN_CQE_NUM 0x40
  44. #define HNS_ROCE_MIN_WQE_NUM 0x20
  45. /* Hardware specification only for v1 engine */
  46. #define HNS_ROCE_MAX_INNER_MTPT_NUM 0x7
  47. #define HNS_ROCE_MAX_MTPT_PBL_NUM 0x100000
  48. #define HNS_ROCE_EACH_FREE_CQ_WAIT_MSECS 20
  49. #define HNS_ROCE_MAX_FREE_CQ_WAIT_CNT \
  50. (5000 / HNS_ROCE_EACH_FREE_CQ_WAIT_MSECS)
  51. #define HNS_ROCE_CQE_WCMD_EMPTY_BIT 0x2
  52. #define HNS_ROCE_MIN_CQE_CNT 16
  53. #define HNS_ROCE_MAX_IRQ_NUM 34
  54. #define HNS_ROCE_COMP_VEC_NUM 32
  55. #define HNS_ROCE_AEQE_VEC_NUM 1
  56. #define HNS_ROCE_AEQE_OF_VEC_NUM 1
  57. /* 4G/4K = 1M */
  58. #define HNS_ROCE_SL_SHIFT 28
  59. #define HNS_ROCE_TCLASS_SHIFT 20
  60. #define HNS_ROCE_FLOW_LABLE_MASK 0xfffff
  61. #define HNS_ROCE_MAX_PORTS 6
  62. #define HNS_ROCE_MAX_GID_NUM 16
  63. #define HNS_ROCE_GID_SIZE 16
  64. #define BITMAP_NO_RR 0
  65. #define BITMAP_RR 1
  66. #define MR_TYPE_MR 0x00
  67. #define MR_TYPE_DMA 0x03
  68. #define PKEY_ID 0xffff
  69. #define GUID_LEN 8
  70. #define NODE_DESC_SIZE 64
  71. #define DB_REG_OFFSET 0x1000
  72. #define SERV_TYPE_RC 0
  73. #define SERV_TYPE_RD 1
  74. #define SERV_TYPE_UC 2
  75. #define SERV_TYPE_UD 3
  76. #define PAGES_SHIFT_8 8
  77. #define PAGES_SHIFT_16 16
  78. #define PAGES_SHIFT_24 24
  79. #define PAGES_SHIFT_32 32
  80. enum hns_roce_qp_state {
  81. HNS_ROCE_QP_STATE_RST,
  82. HNS_ROCE_QP_STATE_INIT,
  83. HNS_ROCE_QP_STATE_RTR,
  84. HNS_ROCE_QP_STATE_RTS,
  85. HNS_ROCE_QP_STATE_SQD,
  86. HNS_ROCE_QP_STATE_ERR,
  87. HNS_ROCE_QP_NUM_STATE,
  88. };
  89. enum hns_roce_event {
  90. HNS_ROCE_EVENT_TYPE_PATH_MIG = 0x01,
  91. HNS_ROCE_EVENT_TYPE_PATH_MIG_FAILED = 0x02,
  92. HNS_ROCE_EVENT_TYPE_COMM_EST = 0x03,
  93. HNS_ROCE_EVENT_TYPE_SQ_DRAINED = 0x04,
  94. HNS_ROCE_EVENT_TYPE_WQ_CATAS_ERROR = 0x05,
  95. HNS_ROCE_EVENT_TYPE_INV_REQ_LOCAL_WQ_ERROR = 0x06,
  96. HNS_ROCE_EVENT_TYPE_LOCAL_WQ_ACCESS_ERROR = 0x07,
  97. HNS_ROCE_EVENT_TYPE_SRQ_LIMIT_REACH = 0x08,
  98. HNS_ROCE_EVENT_TYPE_SRQ_LAST_WQE_REACH = 0x09,
  99. HNS_ROCE_EVENT_TYPE_SRQ_CATAS_ERROR = 0x0a,
  100. HNS_ROCE_EVENT_TYPE_CQ_ACCESS_ERROR = 0x0b,
  101. HNS_ROCE_EVENT_TYPE_CQ_OVERFLOW = 0x0c,
  102. HNS_ROCE_EVENT_TYPE_CQ_ID_INVALID = 0x0d,
  103. HNS_ROCE_EVENT_TYPE_PORT_CHANGE = 0x0f,
  104. /* 0x10 and 0x11 is unused in currently application case */
  105. HNS_ROCE_EVENT_TYPE_DB_OVERFLOW = 0x12,
  106. HNS_ROCE_EVENT_TYPE_MB = 0x13,
  107. HNS_ROCE_EVENT_TYPE_CEQ_OVERFLOW = 0x14,
  108. };
  109. /* Local Work Queue Catastrophic Error,SUBTYPE 0x5 */
  110. enum {
  111. HNS_ROCE_LWQCE_QPC_ERROR = 1,
  112. HNS_ROCE_LWQCE_MTU_ERROR = 2,
  113. HNS_ROCE_LWQCE_WQE_BA_ADDR_ERROR = 3,
  114. HNS_ROCE_LWQCE_WQE_ADDR_ERROR = 4,
  115. HNS_ROCE_LWQCE_SQ_WQE_SHIFT_ERROR = 5,
  116. HNS_ROCE_LWQCE_SL_ERROR = 6,
  117. HNS_ROCE_LWQCE_PORT_ERROR = 7,
  118. };
  119. /* Local Access Violation Work Queue Error,SUBTYPE 0x7 */
  120. enum {
  121. HNS_ROCE_LAVWQE_R_KEY_VIOLATION = 1,
  122. HNS_ROCE_LAVWQE_LENGTH_ERROR = 2,
  123. HNS_ROCE_LAVWQE_VA_ERROR = 3,
  124. HNS_ROCE_LAVWQE_PD_ERROR = 4,
  125. HNS_ROCE_LAVWQE_RW_ACC_ERROR = 5,
  126. HNS_ROCE_LAVWQE_KEY_STATE_ERROR = 6,
  127. HNS_ROCE_LAVWQE_MR_OPERATION_ERROR = 7,
  128. };
  129. /* DOORBELL overflow subtype */
  130. enum {
  131. HNS_ROCE_DB_SUBTYPE_SDB_OVF = 1,
  132. HNS_ROCE_DB_SUBTYPE_SDB_ALM_OVF = 2,
  133. HNS_ROCE_DB_SUBTYPE_ODB_OVF = 3,
  134. HNS_ROCE_DB_SUBTYPE_ODB_ALM_OVF = 4,
  135. HNS_ROCE_DB_SUBTYPE_SDB_ALM_EMP = 5,
  136. HNS_ROCE_DB_SUBTYPE_ODB_ALM_EMP = 6,
  137. };
  138. enum {
  139. /* RQ&SRQ related operations */
  140. HNS_ROCE_OPCODE_SEND_DATA_RECEIVE = 0x06,
  141. HNS_ROCE_OPCODE_RDMA_WITH_IMM_RECEIVE = 0x07,
  142. };
  143. #define HNS_ROCE_CMD_SUCCESS 1
  144. #define HNS_ROCE_PORT_DOWN 0
  145. #define HNS_ROCE_PORT_UP 1
  146. #define HNS_ROCE_MTT_ENTRY_PER_SEG 8
  147. #define PAGE_ADDR_SHIFT 12
  148. struct hns_roce_uar {
  149. u64 pfn;
  150. unsigned long index;
  151. };
  152. struct hns_roce_ucontext {
  153. struct ib_ucontext ibucontext;
  154. struct hns_roce_uar uar;
  155. };
  156. struct hns_roce_pd {
  157. struct ib_pd ibpd;
  158. unsigned long pdn;
  159. };
  160. struct hns_roce_bitmap {
  161. /* Bitmap Traversal last a bit which is 1 */
  162. unsigned long last;
  163. unsigned long top;
  164. unsigned long max;
  165. unsigned long reserved_top;
  166. unsigned long mask;
  167. spinlock_t lock;
  168. unsigned long *table;
  169. };
  170. /* Order bitmap length -- bit num compute formula: 1 << (max_order - order) */
  171. /* Order = 0: bitmap is biggest, order = max bitmap is least (only a bit) */
  172. /* Every bit repesent to a partner free/used status in bitmap */
  173. /*
  174. * Initial, bits of other bitmap are all 0 except that a bit of max_order is 1
  175. * Bit = 1 represent to idle and available; bit = 0: not available
  176. */
  177. struct hns_roce_buddy {
  178. /* Members point to every order level bitmap */
  179. unsigned long **bits;
  180. /* Represent to avail bits of the order level bitmap */
  181. u32 *num_free;
  182. int max_order;
  183. spinlock_t lock;
  184. };
  185. /* For Hardware Entry Memory */
  186. struct hns_roce_hem_table {
  187. /* HEM type: 0 = qpc, 1 = mtt, 2 = cqc, 3 = srq, 4 = other */
  188. u32 type;
  189. /* HEM array elment num */
  190. unsigned long num_hem;
  191. /* HEM entry record obj total num */
  192. unsigned long num_obj;
  193. /*Single obj size */
  194. unsigned long obj_size;
  195. int lowmem;
  196. struct mutex mutex;
  197. struct hns_roce_hem **hem;
  198. };
  199. struct hns_roce_mtt {
  200. unsigned long first_seg;
  201. int order;
  202. int page_shift;
  203. };
  204. /* Only support 4K page size for mr register */
  205. #define MR_SIZE_4K 0
  206. struct hns_roce_mr {
  207. struct ib_mr ibmr;
  208. struct ib_umem *umem;
  209. u64 iova; /* MR's virtual orignal addr */
  210. u64 size; /* Address range of MR */
  211. u32 key; /* Key of MR */
  212. u32 pd; /* PD num of MR */
  213. u32 access;/* Access permission of MR */
  214. int enabled; /* MR's active status */
  215. int type; /* MR's register type */
  216. u64 *pbl_buf;/* MR's PBL space */
  217. dma_addr_t pbl_dma_addr; /* MR's PBL space PA */
  218. };
  219. struct hns_roce_mr_table {
  220. struct hns_roce_bitmap mtpt_bitmap;
  221. struct hns_roce_buddy mtt_buddy;
  222. struct hns_roce_hem_table mtt_table;
  223. struct hns_roce_hem_table mtpt_table;
  224. };
  225. struct hns_roce_wq {
  226. u64 *wrid; /* Work request ID */
  227. spinlock_t lock;
  228. int wqe_cnt; /* WQE num */
  229. u32 max_post;
  230. int max_gs;
  231. int offset;
  232. int wqe_shift;/* WQE size */
  233. u32 head;
  234. u32 tail;
  235. void __iomem *db_reg_l;
  236. };
  237. struct hns_roce_buf_list {
  238. void *buf;
  239. dma_addr_t map;
  240. };
  241. struct hns_roce_buf {
  242. struct hns_roce_buf_list direct;
  243. struct hns_roce_buf_list *page_list;
  244. int nbufs;
  245. u32 npages;
  246. int page_shift;
  247. };
  248. struct hns_roce_cq_buf {
  249. struct hns_roce_buf hr_buf;
  250. struct hns_roce_mtt hr_mtt;
  251. };
  252. struct hns_roce_cq {
  253. struct ib_cq ib_cq;
  254. struct hns_roce_cq_buf hr_buf;
  255. spinlock_t lock;
  256. struct ib_umem *umem;
  257. void (*comp)(struct hns_roce_cq *);
  258. void (*event)(struct hns_roce_cq *, enum hns_roce_event);
  259. struct hns_roce_uar *uar;
  260. u32 cq_depth;
  261. u32 cons_index;
  262. void __iomem *cq_db_l;
  263. u16 *tptr_addr;
  264. unsigned long cqn;
  265. u32 vector;
  266. atomic_t refcount;
  267. struct completion free;
  268. };
  269. struct hns_roce_srq {
  270. struct ib_srq ibsrq;
  271. int srqn;
  272. };
  273. struct hns_roce_uar_table {
  274. struct hns_roce_bitmap bitmap;
  275. };
  276. struct hns_roce_qp_table {
  277. struct hns_roce_bitmap bitmap;
  278. spinlock_t lock;
  279. struct hns_roce_hem_table qp_table;
  280. struct hns_roce_hem_table irrl_table;
  281. };
  282. struct hns_roce_cq_table {
  283. struct hns_roce_bitmap bitmap;
  284. spinlock_t lock;
  285. struct radix_tree_root tree;
  286. struct hns_roce_hem_table table;
  287. };
  288. struct hns_roce_raq_table {
  289. struct hns_roce_buf_list *e_raq_buf;
  290. };
  291. struct hns_roce_av {
  292. __le32 port_pd;
  293. u8 gid_index;
  294. u8 stat_rate;
  295. u8 hop_limit;
  296. __le32 sl_tclass_flowlabel;
  297. u8 dgid[HNS_ROCE_GID_SIZE];
  298. u8 mac[6];
  299. __le16 vlan;
  300. };
  301. struct hns_roce_ah {
  302. struct ib_ah ibah;
  303. struct hns_roce_av av;
  304. };
  305. struct hns_roce_cmd_context {
  306. struct completion done;
  307. int result;
  308. int next;
  309. u64 out_param;
  310. u16 token;
  311. };
  312. struct hns_roce_cmdq {
  313. struct dma_pool *pool;
  314. u8 __iomem *hcr;
  315. struct mutex hcr_mutex;
  316. struct semaphore poll_sem;
  317. /*
  318. * Event mode: cmd register mutex protection,
  319. * ensure to not exceed max_cmds and user use limit region
  320. */
  321. struct semaphore event_sem;
  322. int max_cmds;
  323. spinlock_t context_lock;
  324. int free_head;
  325. struct hns_roce_cmd_context *context;
  326. /*
  327. * Result of get integer part
  328. * which max_comds compute according a power of 2
  329. */
  330. u16 token_mask;
  331. /*
  332. * Process whether use event mode, init default non-zero
  333. * After the event queue of cmd event ready,
  334. * can switch into event mode
  335. * close device, switch into poll mode(non event mode)
  336. */
  337. u8 use_events;
  338. u8 toggle;
  339. };
  340. struct hns_roce_cmd_mailbox {
  341. void *buf;
  342. dma_addr_t dma;
  343. };
  344. struct hns_roce_dev;
  345. struct hns_roce_qp {
  346. struct ib_qp ibqp;
  347. struct hns_roce_buf hr_buf;
  348. struct hns_roce_wq rq;
  349. __le64 doorbell_qpn;
  350. __le32 sq_signal_bits;
  351. u32 sq_next_wqe;
  352. int sq_max_wqes_per_wr;
  353. int sq_spare_wqes;
  354. struct hns_roce_wq sq;
  355. struct ib_umem *umem;
  356. struct hns_roce_mtt mtt;
  357. u32 buff_size;
  358. struct mutex mutex;
  359. u8 port;
  360. u8 phy_port;
  361. u8 sl;
  362. u8 resp_depth;
  363. u8 state;
  364. u32 access_flags;
  365. u32 pkey_index;
  366. void (*event)(struct hns_roce_qp *,
  367. enum hns_roce_event);
  368. unsigned long qpn;
  369. atomic_t refcount;
  370. struct completion free;
  371. };
  372. struct hns_roce_sqp {
  373. struct hns_roce_qp hr_qp;
  374. };
  375. struct hns_roce_ib_iboe {
  376. spinlock_t lock;
  377. struct net_device *netdevs[HNS_ROCE_MAX_PORTS];
  378. struct notifier_block nb;
  379. struct notifier_block nb_inet;
  380. u8 phy_port[HNS_ROCE_MAX_PORTS];
  381. };
  382. struct hns_roce_eq {
  383. struct hns_roce_dev *hr_dev;
  384. void __iomem *doorbell;
  385. int type_flag;/* Aeq:1 ceq:0 */
  386. int eqn;
  387. u32 entries;
  388. int log_entries;
  389. int eqe_size;
  390. int irq;
  391. int log_page_size;
  392. int cons_index;
  393. struct hns_roce_buf_list *buf_list;
  394. };
  395. struct hns_roce_eq_table {
  396. struct hns_roce_eq *eq;
  397. void __iomem **eqc_base;
  398. };
  399. struct hns_roce_caps {
  400. u8 num_ports;
  401. int gid_table_len[HNS_ROCE_MAX_PORTS];
  402. int pkey_table_len[HNS_ROCE_MAX_PORTS];
  403. int local_ca_ack_delay;
  404. int num_uars;
  405. u32 phy_num_uars;
  406. u32 max_sq_sg; /* 2 */
  407. u32 max_sq_inline; /* 32 */
  408. u32 max_rq_sg; /* 2 */
  409. int num_qps; /* 256k */
  410. u32 max_wqes; /* 16k */
  411. u32 max_sq_desc_sz; /* 64 */
  412. u32 max_rq_desc_sz; /* 64 */
  413. int max_qp_init_rdma;
  414. int max_qp_dest_rdma;
  415. int num_cqs;
  416. int max_cqes;
  417. int reserved_cqs;
  418. int num_aeq_vectors; /* 1 */
  419. int num_comp_vectors; /* 32 ceq */
  420. int num_other_vectors;
  421. int num_mtpts;
  422. u32 num_mtt_segs;
  423. int reserved_mrws;
  424. int reserved_uars;
  425. int num_pds;
  426. int reserved_pds;
  427. u32 mtt_entry_sz;
  428. u32 cq_entry_sz;
  429. u32 page_size_cap;
  430. u32 reserved_lkey;
  431. int mtpt_entry_sz;
  432. int qpc_entry_sz;
  433. int irrl_entry_sz;
  434. int cqc_entry_sz;
  435. int aeqe_depth;
  436. int ceqe_depth[HNS_ROCE_COMP_VEC_NUM];
  437. enum ib_mtu max_mtu;
  438. };
  439. struct hns_roce_hw {
  440. int (*reset)(struct hns_roce_dev *hr_dev, bool enable);
  441. void (*hw_profile)(struct hns_roce_dev *hr_dev);
  442. int (*hw_init)(struct hns_roce_dev *hr_dev);
  443. void (*hw_exit)(struct hns_roce_dev *hr_dev);
  444. void (*set_gid)(struct hns_roce_dev *hr_dev, u8 port, int gid_index,
  445. union ib_gid *gid);
  446. void (*set_mac)(struct hns_roce_dev *hr_dev, u8 phy_port, u8 *addr);
  447. void (*set_mtu)(struct hns_roce_dev *hr_dev, u8 phy_port,
  448. enum ib_mtu mtu);
  449. int (*write_mtpt)(void *mb_buf, struct hns_roce_mr *mr,
  450. unsigned long mtpt_idx);
  451. void (*write_cqc)(struct hns_roce_dev *hr_dev,
  452. struct hns_roce_cq *hr_cq, void *mb_buf, u64 *mtts,
  453. dma_addr_t dma_handle, int nent, u32 vector);
  454. int (*clear_hem)(struct hns_roce_dev *hr_dev,
  455. struct hns_roce_hem_table *table, int obj);
  456. int (*query_qp)(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr,
  457. int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr);
  458. int (*modify_qp)(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
  459. int attr_mask, enum ib_qp_state cur_state,
  460. enum ib_qp_state new_state);
  461. int (*destroy_qp)(struct ib_qp *ibqp);
  462. int (*post_send)(struct ib_qp *ibqp, struct ib_send_wr *wr,
  463. struct ib_send_wr **bad_wr);
  464. int (*post_recv)(struct ib_qp *qp, struct ib_recv_wr *recv_wr,
  465. struct ib_recv_wr **bad_recv_wr);
  466. int (*req_notify_cq)(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
  467. int (*poll_cq)(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
  468. int (*dereg_mr)(struct hns_roce_dev *hr_dev, struct hns_roce_mr *mr);
  469. int (*destroy_cq)(struct ib_cq *ibcq);
  470. void *priv;
  471. };
  472. struct hns_roce_dev {
  473. struct ib_device ib_dev;
  474. struct platform_device *pdev;
  475. struct hns_roce_uar priv_uar;
  476. const char *irq_names[HNS_ROCE_MAX_IRQ_NUM];
  477. spinlock_t sm_lock;
  478. spinlock_t bt_cmd_lock;
  479. struct hns_roce_ib_iboe iboe;
  480. int irq[HNS_ROCE_MAX_IRQ_NUM];
  481. u8 __iomem *reg_base;
  482. struct hns_roce_caps caps;
  483. struct radix_tree_root qp_table_tree;
  484. unsigned char dev_addr[HNS_ROCE_MAX_PORTS][MAC_ADDR_OCTET_NUM];
  485. u64 sys_image_guid;
  486. u32 vendor_id;
  487. u32 vendor_part_id;
  488. u32 hw_rev;
  489. void __iomem *priv_addr;
  490. struct hns_roce_cmdq cmd;
  491. struct hns_roce_bitmap pd_bitmap;
  492. struct hns_roce_uar_table uar_table;
  493. struct hns_roce_mr_table mr_table;
  494. struct hns_roce_cq_table cq_table;
  495. struct hns_roce_qp_table qp_table;
  496. struct hns_roce_eq_table eq_table;
  497. int cmd_mod;
  498. int loop_idc;
  499. dma_addr_t tptr_dma_addr; /*only for hw v1*/
  500. u32 tptr_size; /*only for hw v1*/
  501. struct hns_roce_hw *hw;
  502. };
  503. static inline struct hns_roce_dev *to_hr_dev(struct ib_device *ib_dev)
  504. {
  505. return container_of(ib_dev, struct hns_roce_dev, ib_dev);
  506. }
  507. static inline struct hns_roce_ucontext
  508. *to_hr_ucontext(struct ib_ucontext *ibucontext)
  509. {
  510. return container_of(ibucontext, struct hns_roce_ucontext, ibucontext);
  511. }
  512. static inline struct hns_roce_pd *to_hr_pd(struct ib_pd *ibpd)
  513. {
  514. return container_of(ibpd, struct hns_roce_pd, ibpd);
  515. }
  516. static inline struct hns_roce_ah *to_hr_ah(struct ib_ah *ibah)
  517. {
  518. return container_of(ibah, struct hns_roce_ah, ibah);
  519. }
  520. static inline struct hns_roce_mr *to_hr_mr(struct ib_mr *ibmr)
  521. {
  522. return container_of(ibmr, struct hns_roce_mr, ibmr);
  523. }
  524. static inline struct hns_roce_qp *to_hr_qp(struct ib_qp *ibqp)
  525. {
  526. return container_of(ibqp, struct hns_roce_qp, ibqp);
  527. }
  528. static inline struct hns_roce_cq *to_hr_cq(struct ib_cq *ib_cq)
  529. {
  530. return container_of(ib_cq, struct hns_roce_cq, ib_cq);
  531. }
  532. static inline struct hns_roce_srq *to_hr_srq(struct ib_srq *ibsrq)
  533. {
  534. return container_of(ibsrq, struct hns_roce_srq, ibsrq);
  535. }
  536. static inline struct hns_roce_sqp *hr_to_hr_sqp(struct hns_roce_qp *hr_qp)
  537. {
  538. return container_of(hr_qp, struct hns_roce_sqp, hr_qp);
  539. }
  540. static inline void hns_roce_write64_k(__be32 val[2], void __iomem *dest)
  541. {
  542. __raw_writeq(*(u64 *) val, dest);
  543. }
  544. static inline struct hns_roce_qp
  545. *__hns_roce_qp_lookup(struct hns_roce_dev *hr_dev, u32 qpn)
  546. {
  547. return radix_tree_lookup(&hr_dev->qp_table_tree,
  548. qpn & (hr_dev->caps.num_qps - 1));
  549. }
  550. static inline void *hns_roce_buf_offset(struct hns_roce_buf *buf, int offset)
  551. {
  552. u32 bits_per_long_val = BITS_PER_LONG;
  553. if (bits_per_long_val == 64 || buf->nbufs == 1)
  554. return (char *)(buf->direct.buf) + offset;
  555. else
  556. return (char *)(buf->page_list[offset >> PAGE_SHIFT].buf) +
  557. (offset & (PAGE_SIZE - 1));
  558. }
  559. int hns_roce_init_uar_table(struct hns_roce_dev *dev);
  560. int hns_roce_uar_alloc(struct hns_roce_dev *dev, struct hns_roce_uar *uar);
  561. void hns_roce_uar_free(struct hns_roce_dev *dev, struct hns_roce_uar *uar);
  562. void hns_roce_cleanup_uar_table(struct hns_roce_dev *dev);
  563. int hns_roce_cmd_init(struct hns_roce_dev *hr_dev);
  564. void hns_roce_cmd_cleanup(struct hns_roce_dev *hr_dev);
  565. void hns_roce_cmd_event(struct hns_roce_dev *hr_dev, u16 token, u8 status,
  566. u64 out_param);
  567. int hns_roce_cmd_use_events(struct hns_roce_dev *hr_dev);
  568. void hns_roce_cmd_use_polling(struct hns_roce_dev *hr_dev);
  569. int hns_roce_mtt_init(struct hns_roce_dev *hr_dev, int npages, int page_shift,
  570. struct hns_roce_mtt *mtt);
  571. void hns_roce_mtt_cleanup(struct hns_roce_dev *hr_dev,
  572. struct hns_roce_mtt *mtt);
  573. int hns_roce_buf_write_mtt(struct hns_roce_dev *hr_dev,
  574. struct hns_roce_mtt *mtt, struct hns_roce_buf *buf);
  575. int hns_roce_init_pd_table(struct hns_roce_dev *hr_dev);
  576. int hns_roce_init_mr_table(struct hns_roce_dev *hr_dev);
  577. int hns_roce_init_eq_table(struct hns_roce_dev *hr_dev);
  578. int hns_roce_init_cq_table(struct hns_roce_dev *hr_dev);
  579. int hns_roce_init_qp_table(struct hns_roce_dev *hr_dev);
  580. void hns_roce_cleanup_pd_table(struct hns_roce_dev *hr_dev);
  581. void hns_roce_cleanup_mr_table(struct hns_roce_dev *hr_dev);
  582. void hns_roce_cleanup_eq_table(struct hns_roce_dev *hr_dev);
  583. void hns_roce_cleanup_cq_table(struct hns_roce_dev *hr_dev);
  584. void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev);
  585. int hns_roce_bitmap_alloc(struct hns_roce_bitmap *bitmap, unsigned long *obj);
  586. void hns_roce_bitmap_free(struct hns_roce_bitmap *bitmap, unsigned long obj,
  587. int rr);
  588. int hns_roce_bitmap_init(struct hns_roce_bitmap *bitmap, u32 num, u32 mask,
  589. u32 reserved_bot, u32 resetrved_top);
  590. void hns_roce_bitmap_cleanup(struct hns_roce_bitmap *bitmap);
  591. void hns_roce_cleanup_bitmap(struct hns_roce_dev *hr_dev);
  592. int hns_roce_bitmap_alloc_range(struct hns_roce_bitmap *bitmap, int cnt,
  593. int align, unsigned long *obj);
  594. void hns_roce_bitmap_free_range(struct hns_roce_bitmap *bitmap,
  595. unsigned long obj, int cnt,
  596. int rr);
  597. struct ib_ah *hns_roce_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr,
  598. struct ib_udata *udata);
  599. int hns_roce_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
  600. int hns_roce_destroy_ah(struct ib_ah *ah);
  601. struct ib_pd *hns_roce_alloc_pd(struct ib_device *ib_dev,
  602. struct ib_ucontext *context,
  603. struct ib_udata *udata);
  604. int hns_roce_dealloc_pd(struct ib_pd *pd);
  605. struct ib_mr *hns_roce_get_dma_mr(struct ib_pd *pd, int acc);
  606. struct ib_mr *hns_roce_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
  607. u64 virt_addr, int access_flags,
  608. struct ib_udata *udata);
  609. int hns_roce_dereg_mr(struct ib_mr *ibmr);
  610. int hns_roce_hw2sw_mpt(struct hns_roce_dev *hr_dev,
  611. struct hns_roce_cmd_mailbox *mailbox,
  612. unsigned long mpt_index);
  613. unsigned long key_to_hw_index(u32 key);
  614. void hns_roce_buf_free(struct hns_roce_dev *hr_dev, u32 size,
  615. struct hns_roce_buf *buf);
  616. int hns_roce_buf_alloc(struct hns_roce_dev *hr_dev, u32 size, u32 max_direct,
  617. struct hns_roce_buf *buf);
  618. int hns_roce_ib_umem_write_mtt(struct hns_roce_dev *hr_dev,
  619. struct hns_roce_mtt *mtt, struct ib_umem *umem);
  620. struct ib_qp *hns_roce_create_qp(struct ib_pd *ib_pd,
  621. struct ib_qp_init_attr *init_attr,
  622. struct ib_udata *udata);
  623. int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  624. int attr_mask, struct ib_udata *udata);
  625. void *get_recv_wqe(struct hns_roce_qp *hr_qp, int n);
  626. void *get_send_wqe(struct hns_roce_qp *hr_qp, int n);
  627. bool hns_roce_wq_overflow(struct hns_roce_wq *hr_wq, int nreq,
  628. struct ib_cq *ib_cq);
  629. enum hns_roce_qp_state to_hns_roce_state(enum ib_qp_state state);
  630. void hns_roce_lock_cqs(struct hns_roce_cq *send_cq,
  631. struct hns_roce_cq *recv_cq);
  632. void hns_roce_unlock_cqs(struct hns_roce_cq *send_cq,
  633. struct hns_roce_cq *recv_cq);
  634. void hns_roce_qp_remove(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp);
  635. void hns_roce_qp_free(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp);
  636. void hns_roce_release_range_qp(struct hns_roce_dev *hr_dev, int base_qpn,
  637. int cnt);
  638. __be32 send_ieth(struct ib_send_wr *wr);
  639. int to_hr_qp_type(int qp_type);
  640. struct ib_cq *hns_roce_ib_create_cq(struct ib_device *ib_dev,
  641. const struct ib_cq_init_attr *attr,
  642. struct ib_ucontext *context,
  643. struct ib_udata *udata);
  644. int hns_roce_ib_destroy_cq(struct ib_cq *ib_cq);
  645. void hns_roce_free_cq(struct hns_roce_dev *hr_dev, struct hns_roce_cq *hr_cq);
  646. void hns_roce_cq_completion(struct hns_roce_dev *hr_dev, u32 cqn);
  647. void hns_roce_cq_event(struct hns_roce_dev *hr_dev, u32 cqn, int event_type);
  648. void hns_roce_qp_event(struct hns_roce_dev *hr_dev, u32 qpn, int event_type);
  649. int hns_get_gid_index(struct hns_roce_dev *hr_dev, u8 port, int gid_index);
  650. extern struct hns_roce_hw hns_roce_hw_v1;
  651. #endif /* _HNS_ROCE_DEVICE_H */