ehca_main.c 26 KB

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