ehca_main.c 27 KB

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