ehca_main.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  1. /*
  2. * IBM eServer eHCA Infiniband device driver for Linux on POWER
  3. *
  4. * module start stop, hca detection
  5. *
  6. * Authors: Heiko J Schick <schickhj@de.ibm.com>
  7. * Hoang-Nam Nguyen <hnguyen@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. #ifdef CONFIG_PPC_64K_PAGES
  43. #include <linux/slab.h>
  44. #endif
  45. #include "ehca_classes.h"
  46. #include "ehca_iverbs.h"
  47. #include "ehca_mrmw.h"
  48. #include "ehca_tools.h"
  49. #include "hcp_if.h"
  50. #define HCAD_VERSION "0024"
  51. MODULE_LICENSE("Dual BSD/GPL");
  52. MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
  53. MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver");
  54. MODULE_VERSION(HCAD_VERSION);
  55. int ehca_open_aqp1 = 0;
  56. int ehca_debug_level = 0;
  57. int ehca_hw_level = 0;
  58. int ehca_nr_ports = 2;
  59. int ehca_use_hp_mr = 0;
  60. int ehca_port_act_time = 30;
  61. int ehca_poll_all_eqs = 1;
  62. int ehca_static_rate = -1;
  63. int ehca_scaling_code = 0;
  64. int ehca_mr_largepage = 1;
  65. module_param_named(open_aqp1, ehca_open_aqp1, int, S_IRUGO);
  66. module_param_named(debug_level, ehca_debug_level, int, S_IRUGO);
  67. module_param_named(hw_level, ehca_hw_level, int, S_IRUGO);
  68. module_param_named(nr_ports, ehca_nr_ports, int, S_IRUGO);
  69. module_param_named(use_hp_mr, ehca_use_hp_mr, int, S_IRUGO);
  70. module_param_named(port_act_time, ehca_port_act_time, int, S_IRUGO);
  71. module_param_named(poll_all_eqs, ehca_poll_all_eqs, int, S_IRUGO);
  72. module_param_named(static_rate, ehca_static_rate, int, S_IRUGO);
  73. module_param_named(scaling_code, ehca_scaling_code, int, S_IRUGO);
  74. module_param_named(mr_largepage, ehca_mr_largepage, int, S_IRUGO);
  75. MODULE_PARM_DESC(open_aqp1,
  76. "AQP1 on startup (0: no (default), 1: yes)");
  77. MODULE_PARM_DESC(debug_level,
  78. "debug level"
  79. " (0: no debug traces (default), 1: with debug traces)");
  80. MODULE_PARM_DESC(hw_level,
  81. "hardware level"
  82. " (0: autosensing (default), 1: v. 0.20, 2: v. 0.21)");
  83. MODULE_PARM_DESC(nr_ports,
  84. "number of connected ports (default: 2)");
  85. MODULE_PARM_DESC(use_hp_mr,
  86. "high performance MRs (0: no (default), 1: yes)");
  87. MODULE_PARM_DESC(port_act_time,
  88. "time to wait for port activation (default: 30 sec)");
  89. MODULE_PARM_DESC(poll_all_eqs,
  90. "polls all event queues periodically"
  91. " (0: no, 1: yes (default))");
  92. MODULE_PARM_DESC(static_rate,
  93. "set permanent static rate (default: disabled)");
  94. MODULE_PARM_DESC(scaling_code,
  95. "set scaling code (0: disabled/default, 1: enabled)");
  96. MODULE_PARM_DESC(mr_largepage,
  97. "use large page for MR (0: use PAGE_SIZE (default), "
  98. "1: use large page depending on MR size");
  99. DEFINE_RWLOCK(ehca_qp_idr_lock);
  100. DEFINE_RWLOCK(ehca_cq_idr_lock);
  101. DEFINE_IDR(ehca_qp_idr);
  102. DEFINE_IDR(ehca_cq_idr);
  103. static LIST_HEAD(shca_list); /* list of all registered ehcas */
  104. static DEFINE_SPINLOCK(shca_list_lock);
  105. static struct timer_list poll_eqs_timer;
  106. #ifdef CONFIG_PPC_64K_PAGES
  107. static struct kmem_cache *ctblk_cache;
  108. void *ehca_alloc_fw_ctrlblock(gfp_t flags)
  109. {
  110. void *ret = kmem_cache_zalloc(ctblk_cache, flags);
  111. if (!ret)
  112. ehca_gen_err("Out of memory for ctblk");
  113. return ret;
  114. }
  115. void ehca_free_fw_ctrlblock(void *ptr)
  116. {
  117. if (ptr)
  118. kmem_cache_free(ctblk_cache, ptr);
  119. }
  120. #endif
  121. int ehca2ib_return_code(u64 ehca_rc)
  122. {
  123. switch (ehca_rc) {
  124. case H_SUCCESS:
  125. return 0;
  126. case H_RESOURCE: /* Resource in use */
  127. case H_BUSY:
  128. return -EBUSY;
  129. case H_NOT_ENOUGH_RESOURCES: /* insufficient resources */
  130. case H_CONSTRAINED: /* resource constraint */
  131. case H_NO_MEM:
  132. return -ENOMEM;
  133. default:
  134. return -EINVAL;
  135. }
  136. }
  137. static int ehca_create_slab_caches(void)
  138. {
  139. int ret;
  140. ret = ehca_init_pd_cache();
  141. if (ret) {
  142. ehca_gen_err("Cannot create PD SLAB cache.");
  143. return ret;
  144. }
  145. ret = ehca_init_cq_cache();
  146. if (ret) {
  147. ehca_gen_err("Cannot create CQ SLAB cache.");
  148. goto create_slab_caches2;
  149. }
  150. ret = ehca_init_qp_cache();
  151. if (ret) {
  152. ehca_gen_err("Cannot create QP SLAB cache.");
  153. goto create_slab_caches3;
  154. }
  155. ret = ehca_init_av_cache();
  156. if (ret) {
  157. ehca_gen_err("Cannot create AV SLAB cache.");
  158. goto create_slab_caches4;
  159. }
  160. ret = ehca_init_mrmw_cache();
  161. if (ret) {
  162. ehca_gen_err("Cannot create MR&MW SLAB cache.");
  163. goto create_slab_caches5;
  164. }
  165. ret = ehca_init_small_qp_cache();
  166. if (ret) {
  167. ehca_gen_err("Cannot create small queue SLAB cache.");
  168. goto create_slab_caches6;
  169. }
  170. #ifdef CONFIG_PPC_64K_PAGES
  171. ctblk_cache = kmem_cache_create("ehca_cache_ctblk",
  172. EHCA_PAGESIZE, H_CB_ALIGNMENT,
  173. SLAB_HWCACHE_ALIGN,
  174. NULL);
  175. if (!ctblk_cache) {
  176. ehca_gen_err("Cannot create ctblk SLAB cache.");
  177. ehca_cleanup_small_qp_cache();
  178. goto create_slab_caches6;
  179. }
  180. #endif
  181. return 0;
  182. create_slab_caches6:
  183. ehca_cleanup_mrmw_cache();
  184. create_slab_caches5:
  185. ehca_cleanup_av_cache();
  186. create_slab_caches4:
  187. ehca_cleanup_qp_cache();
  188. create_slab_caches3:
  189. ehca_cleanup_cq_cache();
  190. create_slab_caches2:
  191. ehca_cleanup_pd_cache();
  192. return ret;
  193. }
  194. static void ehca_destroy_slab_caches(void)
  195. {
  196. ehca_cleanup_small_qp_cache();
  197. ehca_cleanup_mrmw_cache();
  198. ehca_cleanup_av_cache();
  199. ehca_cleanup_qp_cache();
  200. ehca_cleanup_cq_cache();
  201. ehca_cleanup_pd_cache();
  202. #ifdef CONFIG_PPC_64K_PAGES
  203. if (ctblk_cache)
  204. kmem_cache_destroy(ctblk_cache);
  205. #endif
  206. }
  207. #define EHCA_HCAAVER EHCA_BMASK_IBM(32, 39)
  208. #define EHCA_REVID EHCA_BMASK_IBM(40, 63)
  209. static struct cap_descr {
  210. u64 mask;
  211. char *descr;
  212. } hca_cap_descr[] = {
  213. { HCA_CAP_AH_PORT_NR_CHECK, "HCA_CAP_AH_PORT_NR_CHECK" },
  214. { HCA_CAP_ATOMIC, "HCA_CAP_ATOMIC" },
  215. { HCA_CAP_AUTO_PATH_MIG, "HCA_CAP_AUTO_PATH_MIG" },
  216. { HCA_CAP_BAD_P_KEY_CTR, "HCA_CAP_BAD_P_KEY_CTR" },
  217. { HCA_CAP_SQD_RTS_PORT_CHANGE, "HCA_CAP_SQD_RTS_PORT_CHANGE" },
  218. { HCA_CAP_CUR_QP_STATE_MOD, "HCA_CAP_CUR_QP_STATE_MOD" },
  219. { HCA_CAP_INIT_TYPE, "HCA_CAP_INIT_TYPE" },
  220. { HCA_CAP_PORT_ACTIVE_EVENT, "HCA_CAP_PORT_ACTIVE_EVENT" },
  221. { HCA_CAP_Q_KEY_VIOL_CTR, "HCA_CAP_Q_KEY_VIOL_CTR" },
  222. { HCA_CAP_WQE_RESIZE, "HCA_CAP_WQE_RESIZE" },
  223. { HCA_CAP_RAW_PACKET_MCAST, "HCA_CAP_RAW_PACKET_MCAST" },
  224. { HCA_CAP_SHUTDOWN_PORT, "HCA_CAP_SHUTDOWN_PORT" },
  225. { HCA_CAP_RC_LL_QP, "HCA_CAP_RC_LL_QP" },
  226. { HCA_CAP_SRQ, "HCA_CAP_SRQ" },
  227. { HCA_CAP_UD_LL_QP, "HCA_CAP_UD_LL_QP" },
  228. { HCA_CAP_RESIZE_MR, "HCA_CAP_RESIZE_MR" },
  229. { HCA_CAP_MINI_QP, "HCA_CAP_MINI_QP" },
  230. };
  231. static int ehca_sense_attributes(struct ehca_shca *shca)
  232. {
  233. int i, ret = 0;
  234. u64 h_ret;
  235. struct hipz_query_hca *rblock;
  236. struct hipz_query_port *port;
  237. static const u32 pgsize_map[] = {
  238. HCA_CAP_MR_PGSIZE_4K, 0x1000,
  239. HCA_CAP_MR_PGSIZE_64K, 0x10000,
  240. HCA_CAP_MR_PGSIZE_1M, 0x100000,
  241. HCA_CAP_MR_PGSIZE_16M, 0x1000000,
  242. };
  243. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  244. if (!rblock) {
  245. ehca_gen_err("Cannot allocate rblock memory.");
  246. return -ENOMEM;
  247. }
  248. h_ret = hipz_h_query_hca(shca->ipz_hca_handle, rblock);
  249. if (h_ret != H_SUCCESS) {
  250. ehca_gen_err("Cannot query device properties. h_ret=%li",
  251. h_ret);
  252. ret = -EPERM;
  253. goto sense_attributes1;
  254. }
  255. if (ehca_nr_ports == 1)
  256. shca->num_ports = 1;
  257. else
  258. shca->num_ports = (u8)rblock->num_ports;
  259. ehca_gen_dbg(" ... found %x ports", rblock->num_ports);
  260. if (ehca_hw_level == 0) {
  261. u32 hcaaver;
  262. u32 revid;
  263. hcaaver = EHCA_BMASK_GET(EHCA_HCAAVER, rblock->hw_ver);
  264. revid = EHCA_BMASK_GET(EHCA_REVID, rblock->hw_ver);
  265. ehca_gen_dbg(" ... hardware version=%x:%x", hcaaver, revid);
  266. if (hcaaver == 1) {
  267. if (revid <= 3)
  268. shca->hw_level = 0x10 | (revid + 1);
  269. else
  270. shca->hw_level = 0x14;
  271. } else if (hcaaver == 2) {
  272. if (revid == 0)
  273. shca->hw_level = 0x21;
  274. else if (revid == 0x10)
  275. shca->hw_level = 0x22;
  276. else if (revid == 0x20 || revid == 0x21)
  277. shca->hw_level = 0x23;
  278. }
  279. if (!shca->hw_level) {
  280. ehca_gen_warn("unknown hardware version"
  281. " - assuming default level");
  282. shca->hw_level = 0x22;
  283. }
  284. } else
  285. shca->hw_level = ehca_hw_level;
  286. ehca_gen_dbg(" ... hardware level=%x", shca->hw_level);
  287. shca->sport[0].rate = IB_RATE_30_GBPS;
  288. shca->sport[1].rate = IB_RATE_30_GBPS;
  289. shca->hca_cap = rblock->hca_cap_indicators;
  290. ehca_gen_dbg(" ... HCA capabilities:");
  291. for (i = 0; i < ARRAY_SIZE(hca_cap_descr); i++)
  292. if (EHCA_BMASK_GET(hca_cap_descr[i].mask, shca->hca_cap))
  293. ehca_gen_dbg(" %s", hca_cap_descr[i].descr);
  294. /* translate supported MR page sizes; always support 4K */
  295. shca->hca_cap_mr_pgsize = EHCA_PAGESIZE;
  296. if (ehca_mr_largepage) { /* support extra sizes only if enabled */
  297. for (i = 0; i < ARRAY_SIZE(pgsize_map); i += 2)
  298. if (rblock->memory_page_size_supported & pgsize_map[i])
  299. shca->hca_cap_mr_pgsize |= pgsize_map[i + 1];
  300. }
  301. /* query max MTU from first port -- it's the same for all ports */
  302. port = (struct hipz_query_port *)rblock;
  303. h_ret = hipz_h_query_port(shca->ipz_hca_handle, 1, port);
  304. if (h_ret != H_SUCCESS) {
  305. ehca_gen_err("Cannot query port properties. h_ret=%li",
  306. h_ret);
  307. ret = -EPERM;
  308. goto sense_attributes1;
  309. }
  310. shca->max_mtu = port->max_mtu;
  311. sense_attributes1:
  312. ehca_free_fw_ctrlblock(rblock);
  313. return ret;
  314. }
  315. static int init_node_guid(struct ehca_shca *shca)
  316. {
  317. int ret = 0;
  318. struct hipz_query_hca *rblock;
  319. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  320. if (!rblock) {
  321. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  322. return -ENOMEM;
  323. }
  324. if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) {
  325. ehca_err(&shca->ib_device, "Can't query device properties");
  326. ret = -EINVAL;
  327. goto init_node_guid1;
  328. }
  329. memcpy(&shca->ib_device.node_guid, &rblock->node_guid, sizeof(u64));
  330. init_node_guid1:
  331. ehca_free_fw_ctrlblock(rblock);
  332. return ret;
  333. }
  334. int ehca_init_device(struct ehca_shca *shca)
  335. {
  336. int ret;
  337. ret = init_node_guid(shca);
  338. if (ret)
  339. return ret;
  340. strlcpy(shca->ib_device.name, "ehca%d", IB_DEVICE_NAME_MAX);
  341. shca->ib_device.owner = THIS_MODULE;
  342. shca->ib_device.uverbs_abi_ver = 8;
  343. shca->ib_device.uverbs_cmd_mask =
  344. (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
  345. (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
  346. (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
  347. (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
  348. (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
  349. (1ull << IB_USER_VERBS_CMD_REG_MR) |
  350. (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
  351. (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
  352. (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
  353. (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
  354. (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
  355. (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
  356. (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
  357. (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
  358. (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
  359. (1ull << IB_USER_VERBS_CMD_DETACH_MCAST);
  360. shca->ib_device.node_type = RDMA_NODE_IB_CA;
  361. shca->ib_device.phys_port_cnt = shca->num_ports;
  362. shca->ib_device.num_comp_vectors = 1;
  363. shca->ib_device.dma_device = &shca->ofdev->dev;
  364. shca->ib_device.query_device = ehca_query_device;
  365. shca->ib_device.query_port = ehca_query_port;
  366. shca->ib_device.query_gid = ehca_query_gid;
  367. shca->ib_device.query_pkey = ehca_query_pkey;
  368. /* shca->in_device.modify_device = ehca_modify_device */
  369. shca->ib_device.modify_port = ehca_modify_port;
  370. shca->ib_device.alloc_ucontext = ehca_alloc_ucontext;
  371. shca->ib_device.dealloc_ucontext = ehca_dealloc_ucontext;
  372. shca->ib_device.alloc_pd = ehca_alloc_pd;
  373. shca->ib_device.dealloc_pd = ehca_dealloc_pd;
  374. shca->ib_device.create_ah = ehca_create_ah;
  375. /* shca->ib_device.modify_ah = ehca_modify_ah; */
  376. shca->ib_device.query_ah = ehca_query_ah;
  377. shca->ib_device.destroy_ah = ehca_destroy_ah;
  378. shca->ib_device.create_qp = ehca_create_qp;
  379. shca->ib_device.modify_qp = ehca_modify_qp;
  380. shca->ib_device.query_qp = ehca_query_qp;
  381. shca->ib_device.destroy_qp = ehca_destroy_qp;
  382. shca->ib_device.post_send = ehca_post_send;
  383. shca->ib_device.post_recv = ehca_post_recv;
  384. shca->ib_device.create_cq = ehca_create_cq;
  385. shca->ib_device.destroy_cq = ehca_destroy_cq;
  386. shca->ib_device.resize_cq = ehca_resize_cq;
  387. shca->ib_device.poll_cq = ehca_poll_cq;
  388. /* shca->ib_device.peek_cq = ehca_peek_cq; */
  389. shca->ib_device.req_notify_cq = ehca_req_notify_cq;
  390. /* shca->ib_device.req_ncomp_notif = ehca_req_ncomp_notif; */
  391. shca->ib_device.get_dma_mr = ehca_get_dma_mr;
  392. shca->ib_device.reg_phys_mr = ehca_reg_phys_mr;
  393. shca->ib_device.reg_user_mr = ehca_reg_user_mr;
  394. shca->ib_device.query_mr = ehca_query_mr;
  395. shca->ib_device.dereg_mr = ehca_dereg_mr;
  396. shca->ib_device.rereg_phys_mr = ehca_rereg_phys_mr;
  397. shca->ib_device.alloc_mw = ehca_alloc_mw;
  398. shca->ib_device.bind_mw = ehca_bind_mw;
  399. shca->ib_device.dealloc_mw = ehca_dealloc_mw;
  400. shca->ib_device.alloc_fmr = ehca_alloc_fmr;
  401. shca->ib_device.map_phys_fmr = ehca_map_phys_fmr;
  402. shca->ib_device.unmap_fmr = ehca_unmap_fmr;
  403. shca->ib_device.dealloc_fmr = ehca_dealloc_fmr;
  404. shca->ib_device.attach_mcast = ehca_attach_mcast;
  405. shca->ib_device.detach_mcast = ehca_detach_mcast;
  406. /* shca->ib_device.process_mad = ehca_process_mad; */
  407. shca->ib_device.mmap = ehca_mmap;
  408. if (EHCA_BMASK_GET(HCA_CAP_SRQ, shca->hca_cap)) {
  409. shca->ib_device.uverbs_cmd_mask |=
  410. (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
  411. (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
  412. (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
  413. (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
  414. shca->ib_device.create_srq = ehca_create_srq;
  415. shca->ib_device.modify_srq = ehca_modify_srq;
  416. shca->ib_device.query_srq = ehca_query_srq;
  417. shca->ib_device.destroy_srq = ehca_destroy_srq;
  418. shca->ib_device.post_srq_recv = ehca_post_srq_recv;
  419. }
  420. return ret;
  421. }
  422. static int ehca_create_aqp1(struct ehca_shca *shca, u32 port)
  423. {
  424. struct ehca_sport *sport = &shca->sport[port - 1];
  425. struct ib_cq *ibcq;
  426. struct ib_qp *ibqp;
  427. struct ib_qp_init_attr qp_init_attr;
  428. int ret;
  429. if (sport->ibcq_aqp1) {
  430. ehca_err(&shca->ib_device, "AQP1 CQ is already created.");
  431. return -EPERM;
  432. }
  433. ibcq = ib_create_cq(&shca->ib_device, NULL, NULL, (void *)(-1), 10, 0);
  434. if (IS_ERR(ibcq)) {
  435. ehca_err(&shca->ib_device, "Cannot create AQP1 CQ.");
  436. return PTR_ERR(ibcq);
  437. }
  438. sport->ibcq_aqp1 = ibcq;
  439. if (sport->ibqp_aqp1) {
  440. ehca_err(&shca->ib_device, "AQP1 QP is already created.");
  441. ret = -EPERM;
  442. goto create_aqp1;
  443. }
  444. memset(&qp_init_attr, 0, sizeof(struct ib_qp_init_attr));
  445. qp_init_attr.send_cq = ibcq;
  446. qp_init_attr.recv_cq = ibcq;
  447. qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR;
  448. qp_init_attr.cap.max_send_wr = 100;
  449. qp_init_attr.cap.max_recv_wr = 100;
  450. qp_init_attr.cap.max_send_sge = 2;
  451. qp_init_attr.cap.max_recv_sge = 1;
  452. qp_init_attr.qp_type = IB_QPT_GSI;
  453. qp_init_attr.port_num = port;
  454. qp_init_attr.qp_context = NULL;
  455. qp_init_attr.event_handler = NULL;
  456. qp_init_attr.srq = NULL;
  457. ibqp = ib_create_qp(&shca->pd->ib_pd, &qp_init_attr);
  458. if (IS_ERR(ibqp)) {
  459. ehca_err(&shca->ib_device, "Cannot create AQP1 QP.");
  460. ret = PTR_ERR(ibqp);
  461. goto create_aqp1;
  462. }
  463. sport->ibqp_aqp1 = ibqp;
  464. return 0;
  465. create_aqp1:
  466. ib_destroy_cq(sport->ibcq_aqp1);
  467. return ret;
  468. }
  469. static int ehca_destroy_aqp1(struct ehca_sport *sport)
  470. {
  471. int ret;
  472. ret = ib_destroy_qp(sport->ibqp_aqp1);
  473. if (ret) {
  474. ehca_gen_err("Cannot destroy AQP1 QP. ret=%i", ret);
  475. return ret;
  476. }
  477. ret = ib_destroy_cq(sport->ibcq_aqp1);
  478. if (ret)
  479. ehca_gen_err("Cannot destroy AQP1 CQ. ret=%i", ret);
  480. return ret;
  481. }
  482. static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf)
  483. {
  484. return snprintf(buf, PAGE_SIZE, "%d\n",
  485. ehca_debug_level);
  486. }
  487. static ssize_t ehca_store_debug_level(struct device_driver *ddp,
  488. const char *buf, size_t count)
  489. {
  490. int value = (*buf) - '0';
  491. if (value >= 0 && value <= 9)
  492. ehca_debug_level = value;
  493. return 1;
  494. }
  495. DRIVER_ATTR(debug_level, S_IRUSR | S_IWUSR,
  496. ehca_show_debug_level, ehca_store_debug_level);
  497. static struct attribute *ehca_drv_attrs[] = {
  498. &driver_attr_debug_level.attr,
  499. NULL
  500. };
  501. static struct attribute_group ehca_drv_attr_grp = {
  502. .attrs = ehca_drv_attrs
  503. };
  504. #define EHCA_RESOURCE_ATTR(name) \
  505. static ssize_t ehca_show_##name(struct device *dev, \
  506. struct device_attribute *attr, \
  507. char *buf) \
  508. { \
  509. struct ehca_shca *shca; \
  510. struct hipz_query_hca *rblock; \
  511. int data; \
  512. \
  513. shca = dev->driver_data; \
  514. \
  515. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); \
  516. if (!rblock) { \
  517. dev_err(dev, "Can't allocate rblock memory.\n"); \
  518. return 0; \
  519. } \
  520. \
  521. if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) { \
  522. dev_err(dev, "Can't query device properties\n"); \
  523. ehca_free_fw_ctrlblock(rblock); \
  524. return 0; \
  525. } \
  526. \
  527. data = rblock->name; \
  528. ehca_free_fw_ctrlblock(rblock); \
  529. \
  530. if ((strcmp(#name, "num_ports") == 0) && (ehca_nr_ports == 1)) \
  531. return snprintf(buf, 256, "1\n"); \
  532. else \
  533. return snprintf(buf, 256, "%d\n", data); \
  534. \
  535. } \
  536. static DEVICE_ATTR(name, S_IRUGO, ehca_show_##name, NULL);
  537. EHCA_RESOURCE_ATTR(num_ports);
  538. EHCA_RESOURCE_ATTR(hw_ver);
  539. EHCA_RESOURCE_ATTR(max_eq);
  540. EHCA_RESOURCE_ATTR(cur_eq);
  541. EHCA_RESOURCE_ATTR(max_cq);
  542. EHCA_RESOURCE_ATTR(cur_cq);
  543. EHCA_RESOURCE_ATTR(max_qp);
  544. EHCA_RESOURCE_ATTR(cur_qp);
  545. EHCA_RESOURCE_ATTR(max_mr);
  546. EHCA_RESOURCE_ATTR(cur_mr);
  547. EHCA_RESOURCE_ATTR(max_mw);
  548. EHCA_RESOURCE_ATTR(cur_mw);
  549. EHCA_RESOURCE_ATTR(max_pd);
  550. EHCA_RESOURCE_ATTR(max_ah);
  551. static ssize_t ehca_show_adapter_handle(struct device *dev,
  552. struct device_attribute *attr,
  553. char *buf)
  554. {
  555. struct ehca_shca *shca = dev->driver_data;
  556. return sprintf(buf, "%lx\n", shca->ipz_hca_handle.handle);
  557. }
  558. static DEVICE_ATTR(adapter_handle, S_IRUGO, ehca_show_adapter_handle, NULL);
  559. static ssize_t ehca_show_mr_largepage(struct device *dev,
  560. struct device_attribute *attr,
  561. char *buf)
  562. {
  563. return sprintf(buf, "%d\n", ehca_mr_largepage);
  564. }
  565. static DEVICE_ATTR(mr_largepage, S_IRUGO, ehca_show_mr_largepage, NULL);
  566. static struct attribute *ehca_dev_attrs[] = {
  567. &dev_attr_adapter_handle.attr,
  568. &dev_attr_num_ports.attr,
  569. &dev_attr_hw_ver.attr,
  570. &dev_attr_max_eq.attr,
  571. &dev_attr_cur_eq.attr,
  572. &dev_attr_max_cq.attr,
  573. &dev_attr_cur_cq.attr,
  574. &dev_attr_max_qp.attr,
  575. &dev_attr_cur_qp.attr,
  576. &dev_attr_max_mr.attr,
  577. &dev_attr_cur_mr.attr,
  578. &dev_attr_max_mw.attr,
  579. &dev_attr_cur_mw.attr,
  580. &dev_attr_max_pd.attr,
  581. &dev_attr_max_ah.attr,
  582. &dev_attr_mr_largepage.attr,
  583. NULL
  584. };
  585. static struct attribute_group ehca_dev_attr_grp = {
  586. .attrs = ehca_dev_attrs
  587. };
  588. static int __devinit ehca_probe(struct of_device *dev,
  589. const struct of_device_id *id)
  590. {
  591. struct ehca_shca *shca;
  592. const u64 *handle;
  593. struct ib_pd *ibpd;
  594. int ret;
  595. handle = of_get_property(dev->node, "ibm,hca-handle", NULL);
  596. if (!handle) {
  597. ehca_gen_err("Cannot get eHCA handle for adapter: %s.",
  598. dev->node->full_name);
  599. return -ENODEV;
  600. }
  601. if (!(*handle)) {
  602. ehca_gen_err("Wrong eHCA handle for adapter: %s.",
  603. dev->node->full_name);
  604. return -ENODEV;
  605. }
  606. shca = (struct ehca_shca *)ib_alloc_device(sizeof(*shca));
  607. if (!shca) {
  608. ehca_gen_err("Cannot allocate shca memory.");
  609. return -ENOMEM;
  610. }
  611. mutex_init(&shca->modify_mutex);
  612. shca->ofdev = dev;
  613. shca->ipz_hca_handle.handle = *handle;
  614. dev->dev.driver_data = shca;
  615. ret = ehca_sense_attributes(shca);
  616. if (ret < 0) {
  617. ehca_gen_err("Cannot sense eHCA attributes.");
  618. goto probe1;
  619. }
  620. ret = ehca_init_device(shca);
  621. if (ret) {
  622. ehca_gen_err("Cannot init ehca device struct");
  623. goto probe1;
  624. }
  625. /* create event queues */
  626. ret = ehca_create_eq(shca, &shca->eq, EHCA_EQ, 2048);
  627. if (ret) {
  628. ehca_err(&shca->ib_device, "Cannot create EQ.");
  629. goto probe1;
  630. }
  631. ret = ehca_create_eq(shca, &shca->neq, EHCA_NEQ, 513);
  632. if (ret) {
  633. ehca_err(&shca->ib_device, "Cannot create NEQ.");
  634. goto probe3;
  635. }
  636. /* create internal protection domain */
  637. ibpd = ehca_alloc_pd(&shca->ib_device, (void *)(-1), NULL);
  638. if (IS_ERR(ibpd)) {
  639. ehca_err(&shca->ib_device, "Cannot create internal PD.");
  640. ret = PTR_ERR(ibpd);
  641. goto probe4;
  642. }
  643. shca->pd = container_of(ibpd, struct ehca_pd, ib_pd);
  644. shca->pd->ib_pd.device = &shca->ib_device;
  645. /* create internal max MR */
  646. ret = ehca_reg_internal_maxmr(shca, shca->pd, &shca->maxmr);
  647. if (ret) {
  648. ehca_err(&shca->ib_device, "Cannot create internal MR ret=%i",
  649. ret);
  650. goto probe5;
  651. }
  652. ret = ib_register_device(&shca->ib_device);
  653. if (ret) {
  654. ehca_err(&shca->ib_device,
  655. "ib_register_device() failed ret=%i", ret);
  656. goto probe6;
  657. }
  658. /* create AQP1 for port 1 */
  659. if (ehca_open_aqp1 == 1) {
  660. shca->sport[0].port_state = IB_PORT_DOWN;
  661. ret = ehca_create_aqp1(shca, 1);
  662. if (ret) {
  663. ehca_err(&shca->ib_device,
  664. "Cannot create AQP1 for port 1.");
  665. goto probe7;
  666. }
  667. }
  668. /* create AQP1 for port 2 */
  669. if ((ehca_open_aqp1 == 1) && (shca->num_ports == 2)) {
  670. shca->sport[1].port_state = IB_PORT_DOWN;
  671. ret = ehca_create_aqp1(shca, 2);
  672. if (ret) {
  673. ehca_err(&shca->ib_device,
  674. "Cannot create AQP1 for port 2.");
  675. goto probe8;
  676. }
  677. }
  678. ret = sysfs_create_group(&dev->dev.kobj, &ehca_dev_attr_grp);
  679. if (ret) /* only complain; we can live without attributes */
  680. ehca_err(&shca->ib_device,
  681. "Cannot create device attributes ret=%d", ret);
  682. spin_lock(&shca_list_lock);
  683. list_add(&shca->shca_list, &shca_list);
  684. spin_unlock(&shca_list_lock);
  685. return 0;
  686. probe8:
  687. ret = ehca_destroy_aqp1(&shca->sport[0]);
  688. if (ret)
  689. ehca_err(&shca->ib_device,
  690. "Cannot destroy AQP1 for port 1. ret=%i", ret);
  691. probe7:
  692. ib_unregister_device(&shca->ib_device);
  693. probe6:
  694. ret = ehca_dereg_internal_maxmr(shca);
  695. if (ret)
  696. ehca_err(&shca->ib_device,
  697. "Cannot destroy internal MR. ret=%x", ret);
  698. probe5:
  699. ret = ehca_dealloc_pd(&shca->pd->ib_pd);
  700. if (ret)
  701. ehca_err(&shca->ib_device,
  702. "Cannot destroy internal PD. ret=%x", ret);
  703. probe4:
  704. ret = ehca_destroy_eq(shca, &shca->neq);
  705. if (ret)
  706. ehca_err(&shca->ib_device,
  707. "Cannot destroy NEQ. ret=%x", ret);
  708. probe3:
  709. ret = ehca_destroy_eq(shca, &shca->eq);
  710. if (ret)
  711. ehca_err(&shca->ib_device,
  712. "Cannot destroy EQ. ret=%x", ret);
  713. probe1:
  714. ib_dealloc_device(&shca->ib_device);
  715. return -EINVAL;
  716. }
  717. static int __devexit ehca_remove(struct of_device *dev)
  718. {
  719. struct ehca_shca *shca = dev->dev.driver_data;
  720. int ret;
  721. sysfs_remove_group(&dev->dev.kobj, &ehca_dev_attr_grp);
  722. if (ehca_open_aqp1 == 1) {
  723. int i;
  724. for (i = 0; i < shca->num_ports; i++) {
  725. ret = ehca_destroy_aqp1(&shca->sport[i]);
  726. if (ret)
  727. ehca_err(&shca->ib_device,
  728. "Cannot destroy AQP1 for port %x "
  729. "ret=%i", ret, i);
  730. }
  731. }
  732. ib_unregister_device(&shca->ib_device);
  733. ret = ehca_dereg_internal_maxmr(shca);
  734. if (ret)
  735. ehca_err(&shca->ib_device,
  736. "Cannot destroy internal MR. ret=%i", ret);
  737. ret = ehca_dealloc_pd(&shca->pd->ib_pd);
  738. if (ret)
  739. ehca_err(&shca->ib_device,
  740. "Cannot destroy internal PD. ret=%i", ret);
  741. ret = ehca_destroy_eq(shca, &shca->eq);
  742. if (ret)
  743. ehca_err(&shca->ib_device, "Cannot destroy EQ. ret=%i", ret);
  744. ret = ehca_destroy_eq(shca, &shca->neq);
  745. if (ret)
  746. ehca_err(&shca->ib_device, "Canot destroy NEQ. ret=%i", ret);
  747. ib_dealloc_device(&shca->ib_device);
  748. spin_lock(&shca_list_lock);
  749. list_del(&shca->shca_list);
  750. spin_unlock(&shca_list_lock);
  751. return ret;
  752. }
  753. static struct of_device_id ehca_device_table[] =
  754. {
  755. {
  756. .name = "lhca",
  757. .compatible = "IBM,lhca",
  758. },
  759. {},
  760. };
  761. static struct of_platform_driver ehca_driver = {
  762. .name = "ehca",
  763. .match_table = ehca_device_table,
  764. .probe = ehca_probe,
  765. .remove = ehca_remove,
  766. };
  767. void ehca_poll_eqs(unsigned long data)
  768. {
  769. struct ehca_shca *shca;
  770. spin_lock(&shca_list_lock);
  771. list_for_each_entry(shca, &shca_list, shca_list) {
  772. if (shca->eq.is_initialized) {
  773. /* call deadman proc only if eq ptr does not change */
  774. struct ehca_eq *eq = &shca->eq;
  775. int max = 3;
  776. volatile u64 q_ofs, q_ofs2;
  777. u64 flags;
  778. spin_lock_irqsave(&eq->spinlock, flags);
  779. q_ofs = eq->ipz_queue.current_q_offset;
  780. spin_unlock_irqrestore(&eq->spinlock, flags);
  781. do {
  782. spin_lock_irqsave(&eq->spinlock, flags);
  783. q_ofs2 = eq->ipz_queue.current_q_offset;
  784. spin_unlock_irqrestore(&eq->spinlock, flags);
  785. max--;
  786. } while (q_ofs == q_ofs2 && max > 0);
  787. if (q_ofs == q_ofs2)
  788. ehca_process_eq(shca, 0);
  789. }
  790. }
  791. mod_timer(&poll_eqs_timer, jiffies + HZ);
  792. spin_unlock(&shca_list_lock);
  793. }
  794. int __init ehca_module_init(void)
  795. {
  796. int ret;
  797. printk(KERN_INFO "eHCA Infiniband Device Driver "
  798. "(Version " HCAD_VERSION ")\n");
  799. ret = ehca_create_comp_pool();
  800. if (ret) {
  801. ehca_gen_err("Cannot create comp pool.");
  802. return ret;
  803. }
  804. ret = ehca_create_slab_caches();
  805. if (ret) {
  806. ehca_gen_err("Cannot create SLAB caches");
  807. ret = -ENOMEM;
  808. goto module_init1;
  809. }
  810. ret = ibmebus_register_driver(&ehca_driver);
  811. if (ret) {
  812. ehca_gen_err("Cannot register eHCA device driver");
  813. ret = -EINVAL;
  814. goto module_init2;
  815. }
  816. ret = sysfs_create_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp);
  817. if (ret) /* only complain; we can live without attributes */
  818. ehca_gen_err("Cannot create driver attributes ret=%d", ret);
  819. if (ehca_poll_all_eqs != 1) {
  820. ehca_gen_err("WARNING!!!");
  821. ehca_gen_err("It is possible to lose interrupts.");
  822. } else {
  823. init_timer(&poll_eqs_timer);
  824. poll_eqs_timer.function = ehca_poll_eqs;
  825. poll_eqs_timer.expires = jiffies + HZ;
  826. add_timer(&poll_eqs_timer);
  827. }
  828. return 0;
  829. module_init2:
  830. ehca_destroy_slab_caches();
  831. module_init1:
  832. ehca_destroy_comp_pool();
  833. return ret;
  834. };
  835. void __exit ehca_module_exit(void)
  836. {
  837. if (ehca_poll_all_eqs == 1)
  838. del_timer_sync(&poll_eqs_timer);
  839. sysfs_remove_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp);
  840. ibmebus_unregister_driver(&ehca_driver);
  841. ehca_destroy_slab_caches();
  842. ehca_destroy_comp_pool();
  843. idr_destroy(&ehca_cq_idr);
  844. idr_destroy(&ehca_qp_idr);
  845. };
  846. module_init(ehca_module_init);
  847. module_exit(ehca_module_exit);