ehca_main.c 25 KB

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