ehca_main.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  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 = 0;
  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. 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. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  238. if (!rblock) {
  239. ehca_gen_err("Cannot allocate rblock memory.");
  240. return -ENOMEM;
  241. }
  242. h_ret = hipz_h_query_hca(shca->ipz_hca_handle, rblock);
  243. if (h_ret != H_SUCCESS) {
  244. ehca_gen_err("Cannot query device properties. h_ret=%li",
  245. h_ret);
  246. ret = -EPERM;
  247. goto sense_attributes1;
  248. }
  249. if (ehca_nr_ports == 1)
  250. shca->num_ports = 1;
  251. else
  252. shca->num_ports = (u8)rblock->num_ports;
  253. ehca_gen_dbg(" ... found %x ports", rblock->num_ports);
  254. if (ehca_hw_level == 0) {
  255. u32 hcaaver;
  256. u32 revid;
  257. hcaaver = EHCA_BMASK_GET(EHCA_HCAAVER, rblock->hw_ver);
  258. revid = EHCA_BMASK_GET(EHCA_REVID, rblock->hw_ver);
  259. ehca_gen_dbg(" ... hardware version=%x:%x", hcaaver, revid);
  260. if (hcaaver == 1) {
  261. if (revid <= 3)
  262. shca->hw_level = 0x10 | (revid + 1);
  263. else
  264. shca->hw_level = 0x14;
  265. } else if (hcaaver == 2) {
  266. if (revid == 0)
  267. shca->hw_level = 0x21;
  268. else if (revid == 0x10)
  269. shca->hw_level = 0x22;
  270. else if (revid == 0x20 || revid == 0x21)
  271. shca->hw_level = 0x23;
  272. }
  273. if (!shca->hw_level) {
  274. ehca_gen_warn("unknown hardware version"
  275. " - assuming default level");
  276. shca->hw_level = 0x22;
  277. }
  278. } else
  279. shca->hw_level = ehca_hw_level;
  280. ehca_gen_dbg(" ... hardware level=%x", shca->hw_level);
  281. shca->sport[0].rate = IB_RATE_30_GBPS;
  282. shca->sport[1].rate = IB_RATE_30_GBPS;
  283. shca->hca_cap = rblock->hca_cap_indicators;
  284. ehca_gen_dbg(" ... HCA capabilities:");
  285. for (i = 0; i < ARRAY_SIZE(hca_cap_descr); i++)
  286. if (EHCA_BMASK_GET(hca_cap_descr[i].mask, shca->hca_cap))
  287. ehca_gen_dbg(" %s", hca_cap_descr[i].descr);
  288. shca->hca_cap_mr_pgsize = rblock->memory_page_size_supported;
  289. port = (struct hipz_query_port *)rblock;
  290. h_ret = hipz_h_query_port(shca->ipz_hca_handle, 1, port);
  291. if (h_ret != H_SUCCESS) {
  292. ehca_gen_err("Cannot query port properties. h_ret=%li",
  293. h_ret);
  294. ret = -EPERM;
  295. goto sense_attributes1;
  296. }
  297. shca->max_mtu = port->max_mtu;
  298. sense_attributes1:
  299. ehca_free_fw_ctrlblock(rblock);
  300. return ret;
  301. }
  302. static int init_node_guid(struct ehca_shca *shca)
  303. {
  304. int ret = 0;
  305. struct hipz_query_hca *rblock;
  306. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  307. if (!rblock) {
  308. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  309. return -ENOMEM;
  310. }
  311. if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) {
  312. ehca_err(&shca->ib_device, "Can't query device properties");
  313. ret = -EINVAL;
  314. goto init_node_guid1;
  315. }
  316. memcpy(&shca->ib_device.node_guid, &rblock->node_guid, sizeof(u64));
  317. init_node_guid1:
  318. ehca_free_fw_ctrlblock(rblock);
  319. return ret;
  320. }
  321. int ehca_init_device(struct ehca_shca *shca)
  322. {
  323. int ret;
  324. ret = init_node_guid(shca);
  325. if (ret)
  326. return ret;
  327. strlcpy(shca->ib_device.name, "ehca%d", IB_DEVICE_NAME_MAX);
  328. shca->ib_device.owner = THIS_MODULE;
  329. shca->ib_device.uverbs_abi_ver = 8;
  330. shca->ib_device.uverbs_cmd_mask =
  331. (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
  332. (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
  333. (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
  334. (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
  335. (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
  336. (1ull << IB_USER_VERBS_CMD_REG_MR) |
  337. (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
  338. (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
  339. (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
  340. (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
  341. (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
  342. (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
  343. (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
  344. (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
  345. (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
  346. (1ull << IB_USER_VERBS_CMD_DETACH_MCAST);
  347. shca->ib_device.node_type = RDMA_NODE_IB_CA;
  348. shca->ib_device.phys_port_cnt = shca->num_ports;
  349. shca->ib_device.num_comp_vectors = 1;
  350. shca->ib_device.dma_device = &shca->ofdev->dev;
  351. shca->ib_device.query_device = ehca_query_device;
  352. shca->ib_device.query_port = ehca_query_port;
  353. shca->ib_device.query_gid = ehca_query_gid;
  354. shca->ib_device.query_pkey = ehca_query_pkey;
  355. /* shca->in_device.modify_device = ehca_modify_device */
  356. shca->ib_device.modify_port = ehca_modify_port;
  357. shca->ib_device.alloc_ucontext = ehca_alloc_ucontext;
  358. shca->ib_device.dealloc_ucontext = ehca_dealloc_ucontext;
  359. shca->ib_device.alloc_pd = ehca_alloc_pd;
  360. shca->ib_device.dealloc_pd = ehca_dealloc_pd;
  361. shca->ib_device.create_ah = ehca_create_ah;
  362. /* shca->ib_device.modify_ah = ehca_modify_ah; */
  363. shca->ib_device.query_ah = ehca_query_ah;
  364. shca->ib_device.destroy_ah = ehca_destroy_ah;
  365. shca->ib_device.create_qp = ehca_create_qp;
  366. shca->ib_device.modify_qp = ehca_modify_qp;
  367. shca->ib_device.query_qp = ehca_query_qp;
  368. shca->ib_device.destroy_qp = ehca_destroy_qp;
  369. shca->ib_device.post_send = ehca_post_send;
  370. shca->ib_device.post_recv = ehca_post_recv;
  371. shca->ib_device.create_cq = ehca_create_cq;
  372. shca->ib_device.destroy_cq = ehca_destroy_cq;
  373. shca->ib_device.resize_cq = ehca_resize_cq;
  374. shca->ib_device.poll_cq = ehca_poll_cq;
  375. /* shca->ib_device.peek_cq = ehca_peek_cq; */
  376. shca->ib_device.req_notify_cq = ehca_req_notify_cq;
  377. /* shca->ib_device.req_ncomp_notif = ehca_req_ncomp_notif; */
  378. shca->ib_device.get_dma_mr = ehca_get_dma_mr;
  379. shca->ib_device.reg_phys_mr = ehca_reg_phys_mr;
  380. shca->ib_device.reg_user_mr = ehca_reg_user_mr;
  381. shca->ib_device.query_mr = ehca_query_mr;
  382. shca->ib_device.dereg_mr = ehca_dereg_mr;
  383. shca->ib_device.rereg_phys_mr = ehca_rereg_phys_mr;
  384. shca->ib_device.alloc_mw = ehca_alloc_mw;
  385. shca->ib_device.bind_mw = ehca_bind_mw;
  386. shca->ib_device.dealloc_mw = ehca_dealloc_mw;
  387. shca->ib_device.alloc_fmr = ehca_alloc_fmr;
  388. shca->ib_device.map_phys_fmr = ehca_map_phys_fmr;
  389. shca->ib_device.unmap_fmr = ehca_unmap_fmr;
  390. shca->ib_device.dealloc_fmr = ehca_dealloc_fmr;
  391. shca->ib_device.attach_mcast = ehca_attach_mcast;
  392. shca->ib_device.detach_mcast = ehca_detach_mcast;
  393. /* shca->ib_device.process_mad = ehca_process_mad; */
  394. shca->ib_device.mmap = ehca_mmap;
  395. if (EHCA_BMASK_GET(HCA_CAP_SRQ, shca->hca_cap)) {
  396. shca->ib_device.uverbs_cmd_mask |=
  397. (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
  398. (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
  399. (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
  400. (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
  401. shca->ib_device.create_srq = ehca_create_srq;
  402. shca->ib_device.modify_srq = ehca_modify_srq;
  403. shca->ib_device.query_srq = ehca_query_srq;
  404. shca->ib_device.destroy_srq = ehca_destroy_srq;
  405. shca->ib_device.post_srq_recv = ehca_post_srq_recv;
  406. }
  407. return ret;
  408. }
  409. static int ehca_create_aqp1(struct ehca_shca *shca, u32 port)
  410. {
  411. struct ehca_sport *sport = &shca->sport[port - 1];
  412. struct ib_cq *ibcq;
  413. struct ib_qp *ibqp;
  414. struct ib_qp_init_attr qp_init_attr;
  415. int ret;
  416. if (sport->ibcq_aqp1) {
  417. ehca_err(&shca->ib_device, "AQP1 CQ is already created.");
  418. return -EPERM;
  419. }
  420. ibcq = ib_create_cq(&shca->ib_device, NULL, NULL, (void *)(-1), 10, 0);
  421. if (IS_ERR(ibcq)) {
  422. ehca_err(&shca->ib_device, "Cannot create AQP1 CQ.");
  423. return PTR_ERR(ibcq);
  424. }
  425. sport->ibcq_aqp1 = ibcq;
  426. if (sport->ibqp_aqp1) {
  427. ehca_err(&shca->ib_device, "AQP1 QP is already created.");
  428. ret = -EPERM;
  429. goto create_aqp1;
  430. }
  431. memset(&qp_init_attr, 0, sizeof(struct ib_qp_init_attr));
  432. qp_init_attr.send_cq = ibcq;
  433. qp_init_attr.recv_cq = ibcq;
  434. qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR;
  435. qp_init_attr.cap.max_send_wr = 100;
  436. qp_init_attr.cap.max_recv_wr = 100;
  437. qp_init_attr.cap.max_send_sge = 2;
  438. qp_init_attr.cap.max_recv_sge = 1;
  439. qp_init_attr.qp_type = IB_QPT_GSI;
  440. qp_init_attr.port_num = port;
  441. qp_init_attr.qp_context = NULL;
  442. qp_init_attr.event_handler = NULL;
  443. qp_init_attr.srq = NULL;
  444. ibqp = ib_create_qp(&shca->pd->ib_pd, &qp_init_attr);
  445. if (IS_ERR(ibqp)) {
  446. ehca_err(&shca->ib_device, "Cannot create AQP1 QP.");
  447. ret = PTR_ERR(ibqp);
  448. goto create_aqp1;
  449. }
  450. sport->ibqp_aqp1 = ibqp;
  451. return 0;
  452. create_aqp1:
  453. ib_destroy_cq(sport->ibcq_aqp1);
  454. return ret;
  455. }
  456. static int ehca_destroy_aqp1(struct ehca_sport *sport)
  457. {
  458. int ret;
  459. ret = ib_destroy_qp(sport->ibqp_aqp1);
  460. if (ret) {
  461. ehca_gen_err("Cannot destroy AQP1 QP. ret=%i", ret);
  462. return ret;
  463. }
  464. ret = ib_destroy_cq(sport->ibcq_aqp1);
  465. if (ret)
  466. ehca_gen_err("Cannot destroy AQP1 CQ. ret=%i", ret);
  467. return ret;
  468. }
  469. static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf)
  470. {
  471. return snprintf(buf, PAGE_SIZE, "%d\n",
  472. ehca_debug_level);
  473. }
  474. static ssize_t ehca_store_debug_level(struct device_driver *ddp,
  475. const char *buf, size_t count)
  476. {
  477. int value = (*buf) - '0';
  478. if (value >= 0 && value <= 9)
  479. ehca_debug_level = value;
  480. return 1;
  481. }
  482. DRIVER_ATTR(debug_level, S_IRUSR | S_IWUSR,
  483. ehca_show_debug_level, ehca_store_debug_level);
  484. static struct attribute *ehca_drv_attrs[] = {
  485. &driver_attr_debug_level.attr,
  486. NULL
  487. };
  488. static struct attribute_group ehca_drv_attr_grp = {
  489. .attrs = ehca_drv_attrs
  490. };
  491. #define EHCA_RESOURCE_ATTR(name) \
  492. static ssize_t ehca_show_##name(struct device *dev, \
  493. struct device_attribute *attr, \
  494. char *buf) \
  495. { \
  496. struct ehca_shca *shca; \
  497. struct hipz_query_hca *rblock; \
  498. int data; \
  499. \
  500. shca = dev->driver_data; \
  501. \
  502. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); \
  503. if (!rblock) { \
  504. dev_err(dev, "Can't allocate rblock memory.\n"); \
  505. return 0; \
  506. } \
  507. \
  508. if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) { \
  509. dev_err(dev, "Can't query device properties\n"); \
  510. ehca_free_fw_ctrlblock(rblock); \
  511. return 0; \
  512. } \
  513. \
  514. data = rblock->name; \
  515. ehca_free_fw_ctrlblock(rblock); \
  516. \
  517. if ((strcmp(#name, "num_ports") == 0) && (ehca_nr_ports == 1)) \
  518. return snprintf(buf, 256, "1\n"); \
  519. else \
  520. return snprintf(buf, 256, "%d\n", data); \
  521. \
  522. } \
  523. static DEVICE_ATTR(name, S_IRUGO, ehca_show_##name, NULL);
  524. EHCA_RESOURCE_ATTR(num_ports);
  525. EHCA_RESOURCE_ATTR(hw_ver);
  526. EHCA_RESOURCE_ATTR(max_eq);
  527. EHCA_RESOURCE_ATTR(cur_eq);
  528. EHCA_RESOURCE_ATTR(max_cq);
  529. EHCA_RESOURCE_ATTR(cur_cq);
  530. EHCA_RESOURCE_ATTR(max_qp);
  531. EHCA_RESOURCE_ATTR(cur_qp);
  532. EHCA_RESOURCE_ATTR(max_mr);
  533. EHCA_RESOURCE_ATTR(cur_mr);
  534. EHCA_RESOURCE_ATTR(max_mw);
  535. EHCA_RESOURCE_ATTR(cur_mw);
  536. EHCA_RESOURCE_ATTR(max_pd);
  537. EHCA_RESOURCE_ATTR(max_ah);
  538. static ssize_t ehca_show_adapter_handle(struct device *dev,
  539. struct device_attribute *attr,
  540. char *buf)
  541. {
  542. struct ehca_shca *shca = dev->driver_data;
  543. return sprintf(buf, "%lx\n", shca->ipz_hca_handle.handle);
  544. }
  545. static DEVICE_ATTR(adapter_handle, S_IRUGO, ehca_show_adapter_handle, NULL);
  546. static ssize_t ehca_show_mr_largepage(struct device *dev,
  547. struct device_attribute *attr,
  548. char *buf)
  549. {
  550. return sprintf(buf, "%d\n", ehca_mr_largepage);
  551. }
  552. static DEVICE_ATTR(mr_largepage, S_IRUGO, ehca_show_mr_largepage, NULL);
  553. static struct attribute *ehca_dev_attrs[] = {
  554. &dev_attr_adapter_handle.attr,
  555. &dev_attr_num_ports.attr,
  556. &dev_attr_hw_ver.attr,
  557. &dev_attr_max_eq.attr,
  558. &dev_attr_cur_eq.attr,
  559. &dev_attr_max_cq.attr,
  560. &dev_attr_cur_cq.attr,
  561. &dev_attr_max_qp.attr,
  562. &dev_attr_cur_qp.attr,
  563. &dev_attr_max_mr.attr,
  564. &dev_attr_cur_mr.attr,
  565. &dev_attr_max_mw.attr,
  566. &dev_attr_cur_mw.attr,
  567. &dev_attr_max_pd.attr,
  568. &dev_attr_max_ah.attr,
  569. &dev_attr_mr_largepage.attr,
  570. NULL
  571. };
  572. static struct attribute_group ehca_dev_attr_grp = {
  573. .attrs = ehca_dev_attrs
  574. };
  575. static int __devinit ehca_probe(struct of_device *dev,
  576. const struct of_device_id *id)
  577. {
  578. struct ehca_shca *shca;
  579. const u64 *handle;
  580. struct ib_pd *ibpd;
  581. int ret;
  582. handle = of_get_property(dev->node, "ibm,hca-handle", NULL);
  583. if (!handle) {
  584. ehca_gen_err("Cannot get eHCA handle for adapter: %s.",
  585. dev->node->full_name);
  586. return -ENODEV;
  587. }
  588. if (!(*handle)) {
  589. ehca_gen_err("Wrong eHCA handle for adapter: %s.",
  590. dev->node->full_name);
  591. return -ENODEV;
  592. }
  593. shca = (struct ehca_shca *)ib_alloc_device(sizeof(*shca));
  594. if (!shca) {
  595. ehca_gen_err("Cannot allocate shca memory.");
  596. return -ENOMEM;
  597. }
  598. mutex_init(&shca->modify_mutex);
  599. shca->ofdev = dev;
  600. shca->ipz_hca_handle.handle = *handle;
  601. dev->dev.driver_data = shca;
  602. ret = ehca_sense_attributes(shca);
  603. if (ret < 0) {
  604. ehca_gen_err("Cannot sense eHCA attributes.");
  605. goto probe1;
  606. }
  607. ret = ehca_init_device(shca);
  608. if (ret) {
  609. ehca_gen_err("Cannot init ehca device struct");
  610. goto probe1;
  611. }
  612. /* create event queues */
  613. ret = ehca_create_eq(shca, &shca->eq, EHCA_EQ, 2048);
  614. if (ret) {
  615. ehca_err(&shca->ib_device, "Cannot create EQ.");
  616. goto probe1;
  617. }
  618. ret = ehca_create_eq(shca, &shca->neq, EHCA_NEQ, 513);
  619. if (ret) {
  620. ehca_err(&shca->ib_device, "Cannot create NEQ.");
  621. goto probe3;
  622. }
  623. /* create internal protection domain */
  624. ibpd = ehca_alloc_pd(&shca->ib_device, (void *)(-1), NULL);
  625. if (IS_ERR(ibpd)) {
  626. ehca_err(&shca->ib_device, "Cannot create internal PD.");
  627. ret = PTR_ERR(ibpd);
  628. goto probe4;
  629. }
  630. shca->pd = container_of(ibpd, struct ehca_pd, ib_pd);
  631. shca->pd->ib_pd.device = &shca->ib_device;
  632. /* create internal max MR */
  633. ret = ehca_reg_internal_maxmr(shca, shca->pd, &shca->maxmr);
  634. if (ret) {
  635. ehca_err(&shca->ib_device, "Cannot create internal MR ret=%i",
  636. ret);
  637. goto probe5;
  638. }
  639. ret = ib_register_device(&shca->ib_device);
  640. if (ret) {
  641. ehca_err(&shca->ib_device,
  642. "ib_register_device() failed ret=%i", ret);
  643. goto probe6;
  644. }
  645. /* create AQP1 for port 1 */
  646. if (ehca_open_aqp1 == 1) {
  647. shca->sport[0].port_state = IB_PORT_DOWN;
  648. ret = ehca_create_aqp1(shca, 1);
  649. if (ret) {
  650. ehca_err(&shca->ib_device,
  651. "Cannot create AQP1 for port 1.");
  652. goto probe7;
  653. }
  654. }
  655. /* create AQP1 for port 2 */
  656. if ((ehca_open_aqp1 == 1) && (shca->num_ports == 2)) {
  657. shca->sport[1].port_state = IB_PORT_DOWN;
  658. ret = ehca_create_aqp1(shca, 2);
  659. if (ret) {
  660. ehca_err(&shca->ib_device,
  661. "Cannot create AQP1 for port 2.");
  662. goto probe8;
  663. }
  664. }
  665. ret = sysfs_create_group(&dev->dev.kobj, &ehca_dev_attr_grp);
  666. if (ret) /* only complain; we can live without attributes */
  667. ehca_err(&shca->ib_device,
  668. "Cannot create device attributes ret=%d", ret);
  669. spin_lock(&shca_list_lock);
  670. list_add(&shca->shca_list, &shca_list);
  671. spin_unlock(&shca_list_lock);
  672. return 0;
  673. probe8:
  674. ret = ehca_destroy_aqp1(&shca->sport[0]);
  675. if (ret)
  676. ehca_err(&shca->ib_device,
  677. "Cannot destroy AQP1 for port 1. ret=%i", ret);
  678. probe7:
  679. ib_unregister_device(&shca->ib_device);
  680. probe6:
  681. ret = ehca_dereg_internal_maxmr(shca);
  682. if (ret)
  683. ehca_err(&shca->ib_device,
  684. "Cannot destroy internal MR. ret=%x", ret);
  685. probe5:
  686. ret = ehca_dealloc_pd(&shca->pd->ib_pd);
  687. if (ret)
  688. ehca_err(&shca->ib_device,
  689. "Cannot destroy internal PD. ret=%x", ret);
  690. probe4:
  691. ret = ehca_destroy_eq(shca, &shca->neq);
  692. if (ret)
  693. ehca_err(&shca->ib_device,
  694. "Cannot destroy NEQ. ret=%x", ret);
  695. probe3:
  696. ret = ehca_destroy_eq(shca, &shca->eq);
  697. if (ret)
  698. ehca_err(&shca->ib_device,
  699. "Cannot destroy EQ. ret=%x", ret);
  700. probe1:
  701. ib_dealloc_device(&shca->ib_device);
  702. return -EINVAL;
  703. }
  704. static int __devexit ehca_remove(struct of_device *dev)
  705. {
  706. struct ehca_shca *shca = dev->dev.driver_data;
  707. int ret;
  708. sysfs_remove_group(&dev->dev.kobj, &ehca_dev_attr_grp);
  709. if (ehca_open_aqp1 == 1) {
  710. int i;
  711. for (i = 0; i < shca->num_ports; i++) {
  712. ret = ehca_destroy_aqp1(&shca->sport[i]);
  713. if (ret)
  714. ehca_err(&shca->ib_device,
  715. "Cannot destroy AQP1 for port %x "
  716. "ret=%i", ret, i);
  717. }
  718. }
  719. ib_unregister_device(&shca->ib_device);
  720. ret = ehca_dereg_internal_maxmr(shca);
  721. if (ret)
  722. ehca_err(&shca->ib_device,
  723. "Cannot destroy internal MR. ret=%i", ret);
  724. ret = ehca_dealloc_pd(&shca->pd->ib_pd);
  725. if (ret)
  726. ehca_err(&shca->ib_device,
  727. "Cannot destroy internal PD. ret=%i", ret);
  728. ret = ehca_destroy_eq(shca, &shca->eq);
  729. if (ret)
  730. ehca_err(&shca->ib_device, "Cannot destroy EQ. ret=%i", ret);
  731. ret = ehca_destroy_eq(shca, &shca->neq);
  732. if (ret)
  733. ehca_err(&shca->ib_device, "Canot destroy NEQ. ret=%i", ret);
  734. ib_dealloc_device(&shca->ib_device);
  735. spin_lock(&shca_list_lock);
  736. list_del(&shca->shca_list);
  737. spin_unlock(&shca_list_lock);
  738. return ret;
  739. }
  740. static struct of_device_id ehca_device_table[] =
  741. {
  742. {
  743. .name = "lhca",
  744. .compatible = "IBM,lhca",
  745. },
  746. {},
  747. };
  748. static struct of_platform_driver ehca_driver = {
  749. .name = "ehca",
  750. .match_table = ehca_device_table,
  751. .probe = ehca_probe,
  752. .remove = ehca_remove,
  753. };
  754. void ehca_poll_eqs(unsigned long data)
  755. {
  756. struct ehca_shca *shca;
  757. spin_lock(&shca_list_lock);
  758. list_for_each_entry(shca, &shca_list, shca_list) {
  759. if (shca->eq.is_initialized) {
  760. /* call deadman proc only if eq ptr does not change */
  761. struct ehca_eq *eq = &shca->eq;
  762. int max = 3;
  763. volatile u64 q_ofs, q_ofs2;
  764. u64 flags;
  765. spin_lock_irqsave(&eq->spinlock, flags);
  766. q_ofs = eq->ipz_queue.current_q_offset;
  767. spin_unlock_irqrestore(&eq->spinlock, flags);
  768. do {
  769. spin_lock_irqsave(&eq->spinlock, flags);
  770. q_ofs2 = eq->ipz_queue.current_q_offset;
  771. spin_unlock_irqrestore(&eq->spinlock, flags);
  772. max--;
  773. } while (q_ofs == q_ofs2 && max > 0);
  774. if (q_ofs == q_ofs2)
  775. ehca_process_eq(shca, 0);
  776. }
  777. }
  778. mod_timer(&poll_eqs_timer, jiffies + HZ);
  779. spin_unlock(&shca_list_lock);
  780. }
  781. int __init ehca_module_init(void)
  782. {
  783. int ret;
  784. printk(KERN_INFO "eHCA Infiniband Device Driver "
  785. "(Version " HCAD_VERSION ")\n");
  786. ret = ehca_create_comp_pool();
  787. if (ret) {
  788. ehca_gen_err("Cannot create comp pool.");
  789. return ret;
  790. }
  791. ret = ehca_create_slab_caches();
  792. if (ret) {
  793. ehca_gen_err("Cannot create SLAB caches");
  794. ret = -ENOMEM;
  795. goto module_init1;
  796. }
  797. ret = ibmebus_register_driver(&ehca_driver);
  798. if (ret) {
  799. ehca_gen_err("Cannot register eHCA device driver");
  800. ret = -EINVAL;
  801. goto module_init2;
  802. }
  803. ret = sysfs_create_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp);
  804. if (ret) /* only complain; we can live without attributes */
  805. ehca_gen_err("Cannot create driver attributes ret=%d", ret);
  806. if (ehca_poll_all_eqs != 1) {
  807. ehca_gen_err("WARNING!!!");
  808. ehca_gen_err("It is possible to lose interrupts.");
  809. } else {
  810. init_timer(&poll_eqs_timer);
  811. poll_eqs_timer.function = ehca_poll_eqs;
  812. poll_eqs_timer.expires = jiffies + HZ;
  813. add_timer(&poll_eqs_timer);
  814. }
  815. return 0;
  816. module_init2:
  817. ehca_destroy_slab_caches();
  818. module_init1:
  819. ehca_destroy_comp_pool();
  820. return ret;
  821. };
  822. void __exit ehca_module_exit(void)
  823. {
  824. if (ehca_poll_all_eqs == 1)
  825. del_timer_sync(&poll_eqs_timer);
  826. sysfs_remove_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp);
  827. ibmebus_unregister_driver(&ehca_driver);
  828. ehca_destroy_slab_caches();
  829. ehca_destroy_comp_pool();
  830. idr_destroy(&ehca_cq_idr);
  831. idr_destroy(&ehca_qp_idr);
  832. };
  833. module_init(ehca_module_init);
  834. module_exit(ehca_module_exit);