ehca_main.c 23 KB

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