ehca_classes.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. /*
  2. * IBM eServer eHCA Infiniband device driver for Linux on POWER
  3. *
  4. * Struct definition for eHCA internal structures
  5. *
  6. * Authors: Heiko J Schick <schickhj@de.ibm.com>
  7. * Christoph Raisch <raisch@de.ibm.com>
  8. * Joachim Fenkes <fenkes@de.ibm.com>
  9. *
  10. * Copyright (c) 2005 IBM Corporation
  11. *
  12. * All rights reserved.
  13. *
  14. * This source code is distributed under a dual license of GPL v2.0 and OpenIB
  15. * BSD.
  16. *
  17. * OpenIB BSD License
  18. *
  19. * Redistribution and use in source and binary forms, with or without
  20. * modification, are permitted provided that the following conditions are met:
  21. *
  22. * Redistributions of source code must retain the above copyright notice, this
  23. * list of conditions and the following disclaimer.
  24. *
  25. * Redistributions in binary form must reproduce the above copyright notice,
  26. * this list of conditions and the following disclaimer in the documentation
  27. * and/or other materials
  28. * provided with the distribution.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  31. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  34. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  35. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  36. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  37. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  38. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  39. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGE.
  41. */
  42. #ifndef __EHCA_CLASSES_H__
  43. #define __EHCA_CLASSES_H__
  44. struct ehca_module;
  45. struct ehca_qp;
  46. struct ehca_cq;
  47. struct ehca_eq;
  48. struct ehca_mr;
  49. struct ehca_mw;
  50. struct ehca_pd;
  51. struct ehca_av;
  52. #include <linux/wait.h>
  53. #include <linux/mutex.h>
  54. #include <rdma/ib_verbs.h>
  55. #include <rdma/ib_user_verbs.h>
  56. #ifdef CONFIG_PPC64
  57. #include "ehca_classes_pSeries.h"
  58. #endif
  59. #include "ipz_pt_fn.h"
  60. #include "ehca_qes.h"
  61. #include "ehca_irq.h"
  62. #define EHCA_EQE_CACHE_SIZE 20
  63. struct ehca_eqe_cache_entry {
  64. struct ehca_eqe *eqe;
  65. struct ehca_cq *cq;
  66. };
  67. struct ehca_eq {
  68. u32 length;
  69. struct ipz_queue ipz_queue;
  70. struct ipz_eq_handle ipz_eq_handle;
  71. struct work_struct work;
  72. struct h_galpas galpas;
  73. int is_initialized;
  74. struct ehca_pfeq pf;
  75. spinlock_t spinlock;
  76. struct tasklet_struct interrupt_task;
  77. u32 ist;
  78. spinlock_t irq_spinlock;
  79. struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE];
  80. };
  81. struct ehca_sma_attr {
  82. u16 lid, lmc, sm_sl, sm_lid;
  83. u16 pkey_tbl_len, pkeys[16];
  84. };
  85. struct ehca_sport {
  86. struct ib_cq *ibcq_aqp1;
  87. struct ib_qp *ibqp_sqp[2];
  88. /* lock to serialze modify_qp() calls for sqp in normal
  89. * and irq path (when event PORT_ACTIVE is received first time)
  90. */
  91. spinlock_t mod_sqp_lock;
  92. enum ib_port_state port_state;
  93. struct ehca_sma_attr saved_attr;
  94. u32 pma_qp_nr;
  95. };
  96. #define HCA_CAP_MR_PGSIZE_4K 0x80000000
  97. #define HCA_CAP_MR_PGSIZE_64K 0x40000000
  98. #define HCA_CAP_MR_PGSIZE_1M 0x20000000
  99. #define HCA_CAP_MR_PGSIZE_16M 0x10000000
  100. struct ehca_shca {
  101. struct ib_device ib_device;
  102. struct of_device *ofdev;
  103. u8 num_ports;
  104. int hw_level;
  105. struct list_head shca_list;
  106. struct ipz_adapter_handle ipz_hca_handle;
  107. struct ehca_sport sport[2];
  108. struct ehca_eq eq;
  109. struct ehca_eq neq;
  110. struct ehca_mr *maxmr;
  111. struct ehca_pd *pd;
  112. struct h_galpas galpas;
  113. struct mutex modify_mutex;
  114. u64 hca_cap;
  115. /* MR pgsize: bit 0-3 means 4K, 64K, 1M, 16M respectively */
  116. u32 hca_cap_mr_pgsize;
  117. int max_mtu;
  118. };
  119. struct ehca_pd {
  120. struct ib_pd ib_pd;
  121. struct ipz_pd fw_pd;
  122. u32 ownpid;
  123. /* small queue mgmt */
  124. struct mutex lock;
  125. struct list_head free[2];
  126. struct list_head full[2];
  127. };
  128. enum ehca_ext_qp_type {
  129. EQPT_NORMAL = 0,
  130. EQPT_LLQP = 1,
  131. EQPT_SRQBASE = 2,
  132. EQPT_SRQ = 3,
  133. };
  134. /* struct to cache modify_qp()'s parms for GSI/SMI qp */
  135. struct ehca_mod_qp_parm {
  136. int mask;
  137. struct ib_qp_attr attr;
  138. };
  139. #define EHCA_MOD_QP_PARM_MAX 4
  140. struct ehca_qp {
  141. union {
  142. struct ib_qp ib_qp;
  143. struct ib_srq ib_srq;
  144. };
  145. u32 qp_type;
  146. enum ehca_ext_qp_type ext_type;
  147. struct ipz_queue ipz_squeue;
  148. struct ipz_queue ipz_rqueue;
  149. struct h_galpas galpas;
  150. u32 qkey;
  151. u32 real_qp_num;
  152. u32 token;
  153. spinlock_t spinlock_s;
  154. spinlock_t spinlock_r;
  155. u32 sq_max_inline_data_size;
  156. struct ipz_qp_handle ipz_qp_handle;
  157. struct ehca_pfqp pf;
  158. struct ib_qp_init_attr init_attr;
  159. struct ehca_cq *send_cq;
  160. struct ehca_cq *recv_cq;
  161. unsigned int sqerr_purgeflag;
  162. struct hlist_node list_entries;
  163. /* array to cache modify_qp()'s parms for GSI/SMI qp */
  164. struct ehca_mod_qp_parm *mod_qp_parm;
  165. int mod_qp_parm_idx;
  166. /* mmap counter for resources mapped into user space */
  167. u32 mm_count_squeue;
  168. u32 mm_count_rqueue;
  169. u32 mm_count_galpa;
  170. /* unsolicited ack circumvention */
  171. int unsol_ack_circ;
  172. int mtu_shift;
  173. u32 message_count;
  174. u32 packet_count;
  175. };
  176. #define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)
  177. #define HAS_SQ(qp) (qp->ext_type != EQPT_SRQ)
  178. #define HAS_RQ(qp) (qp->ext_type != EQPT_SRQBASE)
  179. /* must be power of 2 */
  180. #define QP_HASHTAB_LEN 8
  181. struct ehca_cq {
  182. struct ib_cq ib_cq;
  183. struct ipz_queue ipz_queue;
  184. struct h_galpas galpas;
  185. spinlock_t spinlock;
  186. u32 cq_number;
  187. u32 token;
  188. u32 nr_of_entries;
  189. struct ipz_cq_handle ipz_cq_handle;
  190. struct ehca_pfcq pf;
  191. spinlock_t cb_lock;
  192. struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
  193. struct list_head entry;
  194. u32 nr_callbacks; /* #events assigned to cpu by scaling code */
  195. atomic_t nr_events; /* #events seen */
  196. wait_queue_head_t wait_completion;
  197. spinlock_t task_lock;
  198. u32 ownpid;
  199. /* mmap counter for resources mapped into user space */
  200. u32 mm_count_queue;
  201. u32 mm_count_galpa;
  202. };
  203. enum ehca_mr_flag {
  204. EHCA_MR_FLAG_FMR = 0x80000000, /* FMR, created with ehca_alloc_fmr */
  205. EHCA_MR_FLAG_MAXMR = 0x40000000, /* max-MR */
  206. };
  207. struct ehca_mr {
  208. union {
  209. struct ib_mr ib_mr; /* must always be first in ehca_mr */
  210. struct ib_fmr ib_fmr; /* must always be first in ehca_mr */
  211. } ib;
  212. struct ib_umem *umem;
  213. spinlock_t mrlock;
  214. enum ehca_mr_flag flags;
  215. u32 num_kpages; /* number of kernel pages */
  216. u32 num_hwpages; /* number of hw pages to form MR */
  217. u64 hwpage_size; /* hw page size used for this MR */
  218. int acl; /* ACL (stored here for usage in reregister) */
  219. u64 *start; /* virtual start address (stored here for */
  220. /* usage in reregister) */
  221. u64 size; /* size (stored here for usage in reregister) */
  222. u32 fmr_page_size; /* page size for FMR */
  223. u32 fmr_max_pages; /* max pages for FMR */
  224. u32 fmr_max_maps; /* max outstanding maps for FMR */
  225. u32 fmr_map_cnt; /* map counter for FMR */
  226. /* fw specific data */
  227. struct ipz_mrmw_handle ipz_mr_handle; /* MR handle for h-calls */
  228. struct h_galpas galpas;
  229. };
  230. struct ehca_mw {
  231. struct ib_mw ib_mw; /* gen2 mw, must always be first in ehca_mw */
  232. spinlock_t mwlock;
  233. u8 never_bound; /* indication MW was never bound */
  234. struct ipz_mrmw_handle ipz_mw_handle; /* MW handle for h-calls */
  235. struct h_galpas galpas;
  236. };
  237. enum ehca_mr_pgi_type {
  238. EHCA_MR_PGI_PHYS = 1, /* type of ehca_reg_phys_mr,
  239. * ehca_rereg_phys_mr,
  240. * ehca_reg_internal_maxmr */
  241. EHCA_MR_PGI_USER = 2, /* type of ehca_reg_user_mr */
  242. EHCA_MR_PGI_FMR = 3 /* type of ehca_map_phys_fmr */
  243. };
  244. struct ehca_mr_pginfo {
  245. enum ehca_mr_pgi_type type;
  246. u64 num_kpages;
  247. u64 kpage_cnt;
  248. u64 hwpage_size; /* hw page size used for this MR */
  249. u64 num_hwpages; /* number of hw pages */
  250. u64 hwpage_cnt; /* counter for hw pages */
  251. u64 next_hwpage; /* next hw page in buffer/chunk/listelem */
  252. union {
  253. struct { /* type EHCA_MR_PGI_PHYS section */
  254. int num_phys_buf;
  255. struct ib_phys_buf *phys_buf_array;
  256. u64 next_buf;
  257. } phy;
  258. struct { /* type EHCA_MR_PGI_USER section */
  259. struct ib_umem *region;
  260. struct ib_umem_chunk *next_chunk;
  261. u64 next_nmap;
  262. } usr;
  263. struct { /* type EHCA_MR_PGI_FMR section */
  264. u64 fmr_pgsize;
  265. u64 *page_list;
  266. u64 next_listelem;
  267. } fmr;
  268. } u;
  269. };
  270. /* output parameters for MR/FMR hipz calls */
  271. struct ehca_mr_hipzout_parms {
  272. struct ipz_mrmw_handle handle;
  273. u32 lkey;
  274. u32 rkey;
  275. u64 len;
  276. u64 vaddr;
  277. u32 acl;
  278. };
  279. /* output parameters for MW hipz calls */
  280. struct ehca_mw_hipzout_parms {
  281. struct ipz_mrmw_handle handle;
  282. u32 rkey;
  283. };
  284. struct ehca_av {
  285. struct ib_ah ib_ah;
  286. struct ehca_ud_av av;
  287. };
  288. struct ehca_ucontext {
  289. struct ib_ucontext ib_ucontext;
  290. };
  291. int ehca_init_pd_cache(void);
  292. void ehca_cleanup_pd_cache(void);
  293. int ehca_init_cq_cache(void);
  294. void ehca_cleanup_cq_cache(void);
  295. int ehca_init_qp_cache(void);
  296. void ehca_cleanup_qp_cache(void);
  297. int ehca_init_av_cache(void);
  298. void ehca_cleanup_av_cache(void);
  299. int ehca_init_mrmw_cache(void);
  300. void ehca_cleanup_mrmw_cache(void);
  301. int ehca_init_small_qp_cache(void);
  302. void ehca_cleanup_small_qp_cache(void);
  303. extern rwlock_t ehca_qp_idr_lock;
  304. extern rwlock_t ehca_cq_idr_lock;
  305. extern struct idr ehca_qp_idr;
  306. extern struct idr ehca_cq_idr;
  307. extern int ehca_static_rate;
  308. extern int ehca_port_act_time;
  309. extern int ehca_use_hp_mr;
  310. extern int ehca_scaling_code;
  311. extern int ehca_lock_hcalls;
  312. extern int ehca_nr_ports;
  313. struct ipzu_queue_resp {
  314. u32 qe_size; /* queue entry size */
  315. u32 act_nr_of_sg;
  316. u32 queue_length; /* queue length allocated in bytes */
  317. u32 pagesize;
  318. u32 toggle_state;
  319. u32 offset; /* save offset within a page for small_qp */
  320. };
  321. struct ehca_create_cq_resp {
  322. u32 cq_number;
  323. u32 token;
  324. struct ipzu_queue_resp ipz_queue;
  325. u32 fw_handle_ofs;
  326. u32 dummy;
  327. };
  328. struct ehca_create_qp_resp {
  329. u32 qp_num;
  330. u32 token;
  331. u32 qp_type;
  332. u32 ext_type;
  333. u32 qkey;
  334. /* qp_num assigned by ehca: sqp0/1 may have got different numbers */
  335. u32 real_qp_num;
  336. u32 fw_handle_ofs;
  337. u32 dummy;
  338. struct ipzu_queue_resp ipz_squeue;
  339. struct ipzu_queue_resp ipz_rqueue;
  340. };
  341. struct ehca_alloc_cq_parms {
  342. u32 nr_cqe;
  343. u32 act_nr_of_entries;
  344. u32 act_pages;
  345. struct ipz_eq_handle eq_handle;
  346. };
  347. enum ehca_service_type {
  348. ST_RC = 0,
  349. ST_UC = 1,
  350. ST_RD = 2,
  351. ST_UD = 3,
  352. };
  353. enum ehca_ll_comp_flags {
  354. LLQP_SEND_COMP = 0x20,
  355. LLQP_RECV_COMP = 0x40,
  356. LLQP_COMP_MASK = 0x60,
  357. };
  358. struct ehca_alloc_queue_parms {
  359. /* input parameters */
  360. int max_wr;
  361. int max_sge;
  362. int page_size;
  363. int is_small;
  364. /* output parameters */
  365. u16 act_nr_wqes;
  366. u8 act_nr_sges;
  367. u32 queue_size; /* bytes for small queues, pages otherwise */
  368. };
  369. struct ehca_alloc_qp_parms {
  370. struct ehca_alloc_queue_parms squeue;
  371. struct ehca_alloc_queue_parms rqueue;
  372. /* input parameters */
  373. enum ehca_service_type servicetype;
  374. int qp_storage;
  375. int sigtype;
  376. enum ehca_ext_qp_type ext_type;
  377. enum ehca_ll_comp_flags ll_comp_flags;
  378. int ud_av_l_key_ctl;
  379. u32 token;
  380. struct ipz_eq_handle eq_handle;
  381. struct ipz_pd pd;
  382. struct ipz_cq_handle send_cq_handle, recv_cq_handle;
  383. u32 srq_qpn, srq_token, srq_limit;
  384. /* output parameters */
  385. u32 real_qp_num;
  386. struct ipz_qp_handle qp_handle;
  387. struct h_galpas galpas;
  388. };
  389. int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp);
  390. int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num);
  391. struct ehca_qp *ehca_cq_get_qp(struct ehca_cq *cq, int qp_num);
  392. #endif