ehca_main.c 25 KB

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