ehca_main.c 25 KB

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