ehca_main.c 23 KB

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