ehca_classes.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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 <rdma/ib_verbs.h>
  54. #include <rdma/ib_user_verbs.h>
  55. #ifdef CONFIG_PPC64
  56. #include "ehca_classes_pSeries.h"
  57. #endif
  58. #include "ipz_pt_fn.h"
  59. #include "ehca_qes.h"
  60. #include "ehca_irq.h"
  61. #define EHCA_EQE_CACHE_SIZE 20
  62. struct ehca_eqe_cache_entry {
  63. struct ehca_eqe *eqe;
  64. struct ehca_cq *cq;
  65. };
  66. struct ehca_eq {
  67. u32 length;
  68. struct ipz_queue ipz_queue;
  69. struct ipz_eq_handle ipz_eq_handle;
  70. struct work_struct work;
  71. struct h_galpas galpas;
  72. int is_initialized;
  73. struct ehca_pfeq pf;
  74. spinlock_t spinlock;
  75. struct tasklet_struct interrupt_task;
  76. u32 ist;
  77. spinlock_t irq_spinlock;
  78. struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE];
  79. };
  80. struct ehca_sma_attr {
  81. u16 lid, lmc, sm_sl, sm_lid;
  82. u16 pkey_tbl_len, pkeys[16];
  83. };
  84. struct ehca_sport {
  85. struct ib_cq *ibcq_aqp1;
  86. struct ib_qp *ibqp_aqp1;
  87. enum ib_rate rate;
  88. enum ib_port_state port_state;
  89. struct ehca_sma_attr saved_attr;
  90. };
  91. #define HCA_CAP_MR_PGSIZE_4K 1
  92. #define HCA_CAP_MR_PGSIZE_64K 2
  93. #define HCA_CAP_MR_PGSIZE_1M 4
  94. #define HCA_CAP_MR_PGSIZE_16M 8
  95. struct ehca_shca {
  96. struct ib_device ib_device;
  97. struct ibmebus_dev *ibmebus_dev;
  98. u8 num_ports;
  99. int hw_level;
  100. struct list_head shca_list;
  101. struct ipz_adapter_handle ipz_hca_handle;
  102. struct ehca_sport sport[2];
  103. struct ehca_eq eq;
  104. struct ehca_eq neq;
  105. struct ehca_mr *maxmr;
  106. struct ehca_pd *pd;
  107. struct h_galpas galpas;
  108. struct mutex modify_mutex;
  109. u64 hca_cap;
  110. /* MR pgsize: bit 0-3 means 4K, 64K, 1M, 16M respectively */
  111. u32 hca_cap_mr_pgsize;
  112. int max_mtu;
  113. };
  114. struct ehca_pd {
  115. struct ib_pd ib_pd;
  116. struct ipz_pd fw_pd;
  117. u32 ownpid;
  118. /* small queue mgmt */
  119. struct mutex lock;
  120. struct list_head free[2];
  121. struct list_head full[2];
  122. };
  123. enum ehca_ext_qp_type {
  124. EQPT_NORMAL = 0,
  125. EQPT_LLQP = 1,
  126. EQPT_SRQBASE = 2,
  127. EQPT_SRQ = 3,
  128. };
  129. struct ehca_qp {
  130. union {
  131. struct ib_qp ib_qp;
  132. struct ib_srq ib_srq;
  133. };
  134. u32 qp_type;
  135. enum ehca_ext_qp_type ext_type;
  136. struct ipz_queue ipz_squeue;
  137. struct ipz_queue ipz_rqueue;
  138. struct h_galpas galpas;
  139. u32 qkey;
  140. u32 real_qp_num;
  141. u32 token;
  142. spinlock_t spinlock_s;
  143. spinlock_t spinlock_r;
  144. u32 sq_max_inline_data_size;
  145. struct ipz_qp_handle ipz_qp_handle;
  146. struct ehca_pfqp pf;
  147. struct ib_qp_init_attr init_attr;
  148. struct ehca_cq *send_cq;
  149. struct ehca_cq *recv_cq;
  150. unsigned int sqerr_purgeflag;
  151. struct hlist_node list_entries;
  152. /* mmap counter for resources mapped into user space */
  153. u32 mm_count_squeue;
  154. u32 mm_count_rqueue;
  155. u32 mm_count_galpa;
  156. };
  157. #define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)
  158. #define HAS_SQ(qp) (qp->ext_type != EQPT_SRQ)
  159. #define HAS_RQ(qp) (qp->ext_type != EQPT_SRQBASE)
  160. /* must be power of 2 */
  161. #define QP_HASHTAB_LEN 8
  162. struct ehca_cq {
  163. struct ib_cq ib_cq;
  164. struct ipz_queue ipz_queue;
  165. struct h_galpas galpas;
  166. spinlock_t spinlock;
  167. u32 cq_number;
  168. u32 token;
  169. u32 nr_of_entries;
  170. struct ipz_cq_handle ipz_cq_handle;
  171. struct ehca_pfcq pf;
  172. spinlock_t cb_lock;
  173. struct hlist_head qp_hashtab[QP_HASHTAB_LEN];
  174. struct list_head entry;
  175. u32 nr_callbacks; /* #events assigned to cpu by scaling code */
  176. atomic_t nr_events; /* #events seen */
  177. wait_queue_head_t wait_completion;
  178. spinlock_t task_lock;
  179. u32 ownpid;
  180. /* mmap counter for resources mapped into user space */
  181. u32 mm_count_queue;
  182. u32 mm_count_galpa;
  183. };
  184. enum ehca_mr_flag {
  185. EHCA_MR_FLAG_FMR = 0x80000000, /* FMR, created with ehca_alloc_fmr */
  186. EHCA_MR_FLAG_MAXMR = 0x40000000, /* max-MR */
  187. };
  188. struct ehca_mr {
  189. union {
  190. struct ib_mr ib_mr; /* must always be first in ehca_mr */
  191. struct ib_fmr ib_fmr; /* must always be first in ehca_mr */
  192. } ib;
  193. struct ib_umem *umem;
  194. spinlock_t mrlock;
  195. enum ehca_mr_flag flags;
  196. u32 num_kpages; /* number of kernel pages */
  197. u32 num_hwpages; /* number of hw pages to form MR */
  198. u64 hwpage_size; /* hw page size used for this MR */
  199. int acl; /* ACL (stored here for usage in reregister) */
  200. u64 *start; /* virtual start address (stored here for */
  201. /* usage in reregister) */
  202. u64 size; /* size (stored here for usage in reregister) */
  203. u32 fmr_page_size; /* page size for FMR */
  204. u32 fmr_max_pages; /* max pages for FMR */
  205. u32 fmr_max_maps; /* max outstanding maps for FMR */
  206. u32 fmr_map_cnt; /* map counter for FMR */
  207. /* fw specific data */
  208. struct ipz_mrmw_handle ipz_mr_handle; /* MR handle for h-calls */
  209. struct h_galpas galpas;
  210. };
  211. struct ehca_mw {
  212. struct ib_mw ib_mw; /* gen2 mw, must always be first in ehca_mw */
  213. spinlock_t mwlock;
  214. u8 never_bound; /* indication MW was never bound */
  215. struct ipz_mrmw_handle ipz_mw_handle; /* MW handle for h-calls */
  216. struct h_galpas galpas;
  217. };
  218. enum ehca_mr_pgi_type {
  219. EHCA_MR_PGI_PHYS = 1, /* type of ehca_reg_phys_mr,
  220. * ehca_rereg_phys_mr,
  221. * ehca_reg_internal_maxmr */
  222. EHCA_MR_PGI_USER = 2, /* type of ehca_reg_user_mr */
  223. EHCA_MR_PGI_FMR = 3 /* type of ehca_map_phys_fmr */
  224. };
  225. struct ehca_mr_pginfo {
  226. enum ehca_mr_pgi_type type;
  227. u64 num_kpages;
  228. u64 kpage_cnt;
  229. u64 hwpage_size; /* hw page size used for this MR */
  230. u64 num_hwpages; /* number of hw pages */
  231. u64 hwpage_cnt; /* counter for hw pages */
  232. u64 next_hwpage; /* next hw page in buffer/chunk/listelem */
  233. union {
  234. struct { /* type EHCA_MR_PGI_PHYS section */
  235. int num_phys_buf;
  236. struct ib_phys_buf *phys_buf_array;
  237. u64 next_buf;
  238. } phy;
  239. struct { /* type EHCA_MR_PGI_USER section */
  240. struct ib_umem *region;
  241. struct ib_umem_chunk *next_chunk;
  242. u64 next_nmap;
  243. } usr;
  244. struct { /* type EHCA_MR_PGI_FMR section */
  245. u64 fmr_pgsize;
  246. u64 *page_list;
  247. u64 next_listelem;
  248. } fmr;
  249. } u;
  250. };
  251. /* output parameters for MR/FMR hipz calls */
  252. struct ehca_mr_hipzout_parms {
  253. struct ipz_mrmw_handle handle;
  254. u32 lkey;
  255. u32 rkey;
  256. u64 len;
  257. u64 vaddr;
  258. u32 acl;
  259. };
  260. /* output parameters for MW hipz calls */
  261. struct ehca_mw_hipzout_parms {
  262. struct ipz_mrmw_handle handle;
  263. u32 rkey;
  264. };
  265. struct ehca_av {
  266. struct ib_ah ib_ah;
  267. struct ehca_ud_av av;
  268. };
  269. struct ehca_ucontext {
  270. struct ib_ucontext ib_ucontext;
  271. };
  272. int ehca_init_pd_cache(void);
  273. void ehca_cleanup_pd_cache(void);
  274. int ehca_init_cq_cache(void);
  275. void ehca_cleanup_cq_cache(void);
  276. int ehca_init_qp_cache(void);
  277. void ehca_cleanup_qp_cache(void);
  278. int ehca_init_av_cache(void);
  279. void ehca_cleanup_av_cache(void);
  280. int ehca_init_mrmw_cache(void);
  281. void ehca_cleanup_mrmw_cache(void);
  282. int ehca_init_small_qp_cache(void);
  283. void ehca_cleanup_small_qp_cache(void);
  284. extern rwlock_t ehca_qp_idr_lock;
  285. extern rwlock_t ehca_cq_idr_lock;
  286. extern struct idr ehca_qp_idr;
  287. extern struct idr ehca_cq_idr;
  288. extern int ehca_static_rate;
  289. extern int ehca_port_act_time;
  290. extern int ehca_use_hp_mr;
  291. extern int ehca_scaling_code;
  292. extern int ehca_mr_largepage;
  293. struct ipzu_queue_resp {
  294. u32 qe_size; /* queue entry size */
  295. u32 act_nr_of_sg;
  296. u32 queue_length; /* queue length allocated in bytes */
  297. u32 pagesize;
  298. u32 toggle_state;
  299. u32 offset; /* save offset within a page for small_qp */
  300. };
  301. struct ehca_create_cq_resp {
  302. u32 cq_number;
  303. u32 token;
  304. struct ipzu_queue_resp ipz_queue;
  305. };
  306. struct ehca_create_qp_resp {
  307. u32 qp_num;
  308. u32 token;
  309. u32 qp_type;
  310. u32 ext_type;
  311. u32 qkey;
  312. /* qp_num assigned by ehca: sqp0/1 may have got different numbers */
  313. u32 real_qp_num;
  314. u32 dummy; /* padding for 8 byte alignment */
  315. struct ipzu_queue_resp ipz_squeue;
  316. struct ipzu_queue_resp ipz_rqueue;
  317. };
  318. struct ehca_alloc_cq_parms {
  319. u32 nr_cqe;
  320. u32 act_nr_of_entries;
  321. u32 act_pages;
  322. struct ipz_eq_handle eq_handle;
  323. };
  324. enum ehca_service_type {
  325. ST_RC = 0,
  326. ST_UC = 1,
  327. ST_RD = 2,
  328. ST_UD = 3,
  329. };
  330. enum ehca_ll_comp_flags {
  331. LLQP_SEND_COMP = 0x20,
  332. LLQP_RECV_COMP = 0x40,
  333. LLQP_COMP_MASK = 0x60,
  334. };
  335. struct ehca_alloc_queue_parms {
  336. /* input parameters */
  337. int max_wr;
  338. int max_sge;
  339. int page_size;
  340. int is_small;
  341. /* output parameters */
  342. u16 act_nr_wqes;
  343. u8 act_nr_sges;
  344. u32 queue_size; /* bytes for small queues, pages otherwise */
  345. };
  346. struct ehca_alloc_qp_parms {
  347. struct ehca_alloc_queue_parms squeue;
  348. struct ehca_alloc_queue_parms rqueue;
  349. /* input parameters */
  350. enum ehca_service_type servicetype;
  351. int qp_storage;
  352. int sigtype;
  353. enum ehca_ext_qp_type ext_type;
  354. enum ehca_ll_comp_flags ll_comp_flags;
  355. int ud_av_l_key_ctl;
  356. u32 token;
  357. struct ipz_eq_handle eq_handle;
  358. struct ipz_pd pd;
  359. struct ipz_cq_handle send_cq_handle, recv_cq_handle;
  360. u32 srq_qpn, srq_token, srq_limit;
  361. /* output parameters */
  362. u32 real_qp_num;
  363. struct ipz_qp_handle qp_handle;
  364. struct h_galpas galpas;
  365. };
  366. int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp);
  367. int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num);
  368. struct ehca_qp *ehca_cq_get_qp(struct ehca_cq *cq, int qp_num);
  369. #endif