ehca_main.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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_0022");
  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 = 1;
  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. void ehca_create_driver_sysfs(struct ibmebus_driver *drv)
  393. {
  394. driver_create_file(&drv->driver, &driver_attr_debug_level);
  395. }
  396. void ehca_remove_driver_sysfs(struct ibmebus_driver *drv)
  397. {
  398. driver_remove_file(&drv->driver, &driver_attr_debug_level);
  399. }
  400. #define EHCA_RESOURCE_ATTR(name) \
  401. static ssize_t ehca_show_##name(struct device *dev, \
  402. struct device_attribute *attr, \
  403. char *buf) \
  404. { \
  405. struct ehca_shca *shca; \
  406. struct hipz_query_hca *rblock; \
  407. int data; \
  408. \
  409. shca = dev->driver_data; \
  410. \
  411. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); \
  412. if (!rblock) { \
  413. dev_err(dev, "Can't allocate rblock memory."); \
  414. return 0; \
  415. } \
  416. \
  417. if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) { \
  418. dev_err(dev, "Can't query device properties"); \
  419. ehca_free_fw_ctrlblock(rblock); \
  420. return 0; \
  421. } \
  422. \
  423. data = rblock->name; \
  424. ehca_free_fw_ctrlblock(rblock); \
  425. \
  426. if ((strcmp(#name, "num_ports") == 0) && (ehca_nr_ports == 1)) \
  427. return snprintf(buf, 256, "1\n"); \
  428. else \
  429. return snprintf(buf, 256, "%d\n", data); \
  430. \
  431. } \
  432. static DEVICE_ATTR(name, S_IRUGO, ehca_show_##name, NULL);
  433. EHCA_RESOURCE_ATTR(num_ports);
  434. EHCA_RESOURCE_ATTR(hw_ver);
  435. EHCA_RESOURCE_ATTR(max_eq);
  436. EHCA_RESOURCE_ATTR(cur_eq);
  437. EHCA_RESOURCE_ATTR(max_cq);
  438. EHCA_RESOURCE_ATTR(cur_cq);
  439. EHCA_RESOURCE_ATTR(max_qp);
  440. EHCA_RESOURCE_ATTR(cur_qp);
  441. EHCA_RESOURCE_ATTR(max_mr);
  442. EHCA_RESOURCE_ATTR(cur_mr);
  443. EHCA_RESOURCE_ATTR(max_mw);
  444. EHCA_RESOURCE_ATTR(cur_mw);
  445. EHCA_RESOURCE_ATTR(max_pd);
  446. EHCA_RESOURCE_ATTR(max_ah);
  447. static ssize_t ehca_show_adapter_handle(struct device *dev,
  448. struct device_attribute *attr,
  449. char *buf)
  450. {
  451. struct ehca_shca *shca = dev->driver_data;
  452. return sprintf(buf, "%lx\n", shca->ipz_hca_handle.handle);
  453. }
  454. static DEVICE_ATTR(adapter_handle, S_IRUGO, ehca_show_adapter_handle, NULL);
  455. void ehca_create_device_sysfs(struct ibmebus_dev *dev)
  456. {
  457. device_create_file(&dev->ofdev.dev, &dev_attr_adapter_handle);
  458. device_create_file(&dev->ofdev.dev, &dev_attr_num_ports);
  459. device_create_file(&dev->ofdev.dev, &dev_attr_hw_ver);
  460. device_create_file(&dev->ofdev.dev, &dev_attr_max_eq);
  461. device_create_file(&dev->ofdev.dev, &dev_attr_cur_eq);
  462. device_create_file(&dev->ofdev.dev, &dev_attr_max_cq);
  463. device_create_file(&dev->ofdev.dev, &dev_attr_cur_cq);
  464. device_create_file(&dev->ofdev.dev, &dev_attr_max_qp);
  465. device_create_file(&dev->ofdev.dev, &dev_attr_cur_qp);
  466. device_create_file(&dev->ofdev.dev, &dev_attr_max_mr);
  467. device_create_file(&dev->ofdev.dev, &dev_attr_cur_mr);
  468. device_create_file(&dev->ofdev.dev, &dev_attr_max_mw);
  469. device_create_file(&dev->ofdev.dev, &dev_attr_cur_mw);
  470. device_create_file(&dev->ofdev.dev, &dev_attr_max_pd);
  471. device_create_file(&dev->ofdev.dev, &dev_attr_max_ah);
  472. }
  473. void ehca_remove_device_sysfs(struct ibmebus_dev *dev)
  474. {
  475. device_remove_file(&dev->ofdev.dev, &dev_attr_adapter_handle);
  476. device_remove_file(&dev->ofdev.dev, &dev_attr_num_ports);
  477. device_remove_file(&dev->ofdev.dev, &dev_attr_hw_ver);
  478. device_remove_file(&dev->ofdev.dev, &dev_attr_max_eq);
  479. device_remove_file(&dev->ofdev.dev, &dev_attr_cur_eq);
  480. device_remove_file(&dev->ofdev.dev, &dev_attr_max_cq);
  481. device_remove_file(&dev->ofdev.dev, &dev_attr_cur_cq);
  482. device_remove_file(&dev->ofdev.dev, &dev_attr_max_qp);
  483. device_remove_file(&dev->ofdev.dev, &dev_attr_cur_qp);
  484. device_remove_file(&dev->ofdev.dev, &dev_attr_max_mr);
  485. device_remove_file(&dev->ofdev.dev, &dev_attr_cur_mr);
  486. device_remove_file(&dev->ofdev.dev, &dev_attr_max_mw);
  487. device_remove_file(&dev->ofdev.dev, &dev_attr_cur_mw);
  488. device_remove_file(&dev->ofdev.dev, &dev_attr_max_pd);
  489. device_remove_file(&dev->ofdev.dev, &dev_attr_max_ah);
  490. }
  491. static int __devinit ehca_probe(struct ibmebus_dev *dev,
  492. const struct of_device_id *id)
  493. {
  494. struct ehca_shca *shca;
  495. const u64 *handle;
  496. struct ib_pd *ibpd;
  497. int ret;
  498. handle = of_get_property(dev->ofdev.node, "ibm,hca-handle", NULL);
  499. if (!handle) {
  500. ehca_gen_err("Cannot get eHCA handle for adapter: %s.",
  501. dev->ofdev.node->full_name);
  502. return -ENODEV;
  503. }
  504. if (!(*handle)) {
  505. ehca_gen_err("Wrong eHCA handle for adapter: %s.",
  506. dev->ofdev.node->full_name);
  507. return -ENODEV;
  508. }
  509. shca = (struct ehca_shca *)ib_alloc_device(sizeof(*shca));
  510. if (!shca) {
  511. ehca_gen_err("Cannot allocate shca memory.");
  512. return -ENOMEM;
  513. }
  514. mutex_init(&shca->modify_mutex);
  515. shca->ibmebus_dev = dev;
  516. shca->ipz_hca_handle.handle = *handle;
  517. dev->ofdev.dev.driver_data = shca;
  518. ret = ehca_sense_attributes(shca);
  519. if (ret < 0) {
  520. ehca_gen_err("Cannot sense eHCA attributes.");
  521. goto probe1;
  522. }
  523. ret = ehca_init_device(shca);
  524. if (ret) {
  525. ehca_gen_err("Cannot init ehca device struct");
  526. goto probe1;
  527. }
  528. /* create event queues */
  529. ret = ehca_create_eq(shca, &shca->eq, EHCA_EQ, 2048);
  530. if (ret) {
  531. ehca_err(&shca->ib_device, "Cannot create EQ.");
  532. goto probe1;
  533. }
  534. ret = ehca_create_eq(shca, &shca->neq, EHCA_NEQ, 513);
  535. if (ret) {
  536. ehca_err(&shca->ib_device, "Cannot create NEQ.");
  537. goto probe3;
  538. }
  539. /* create internal protection domain */
  540. ibpd = ehca_alloc_pd(&shca->ib_device, (void*)(-1), NULL);
  541. if (IS_ERR(ibpd)) {
  542. ehca_err(&shca->ib_device, "Cannot create internal PD.");
  543. ret = PTR_ERR(ibpd);
  544. goto probe4;
  545. }
  546. shca->pd = container_of(ibpd, struct ehca_pd, ib_pd);
  547. shca->pd->ib_pd.device = &shca->ib_device;
  548. /* create internal max MR */
  549. ret = ehca_reg_internal_maxmr(shca, shca->pd, &shca->maxmr);
  550. if (ret) {
  551. ehca_err(&shca->ib_device, "Cannot create internal MR ret=%x",
  552. ret);
  553. goto probe5;
  554. }
  555. ret = ib_register_device(&shca->ib_device);
  556. if (ret) {
  557. ehca_err(&shca->ib_device,
  558. "ib_register_device() failed ret=%x", ret);
  559. goto probe6;
  560. }
  561. /* create AQP1 for port 1 */
  562. if (ehca_open_aqp1 == 1) {
  563. shca->sport[0].port_state = IB_PORT_DOWN;
  564. ret = ehca_create_aqp1(shca, 1);
  565. if (ret) {
  566. ehca_err(&shca->ib_device,
  567. "Cannot create AQP1 for port 1.");
  568. goto probe7;
  569. }
  570. }
  571. /* create AQP1 for port 2 */
  572. if ((ehca_open_aqp1 == 1) && (shca->num_ports == 2)) {
  573. shca->sport[1].port_state = IB_PORT_DOWN;
  574. ret = ehca_create_aqp1(shca, 2);
  575. if (ret) {
  576. ehca_err(&shca->ib_device,
  577. "Cannot create AQP1 for port 2.");
  578. goto probe8;
  579. }
  580. }
  581. ehca_create_device_sysfs(dev);
  582. spin_lock(&shca_list_lock);
  583. list_add(&shca->shca_list, &shca_list);
  584. spin_unlock(&shca_list_lock);
  585. return 0;
  586. probe8:
  587. ret = ehca_destroy_aqp1(&shca->sport[0]);
  588. if (ret)
  589. ehca_err(&shca->ib_device,
  590. "Cannot destroy AQP1 for port 1. ret=%x", ret);
  591. probe7:
  592. ib_unregister_device(&shca->ib_device);
  593. probe6:
  594. ret = ehca_dereg_internal_maxmr(shca);
  595. if (ret)
  596. ehca_err(&shca->ib_device,
  597. "Cannot destroy internal MR. ret=%x", ret);
  598. probe5:
  599. ret = ehca_dealloc_pd(&shca->pd->ib_pd);
  600. if (ret)
  601. ehca_err(&shca->ib_device,
  602. "Cannot destroy internal PD. ret=%x", ret);
  603. probe4:
  604. ret = ehca_destroy_eq(shca, &shca->neq);
  605. if (ret)
  606. ehca_err(&shca->ib_device,
  607. "Cannot destroy NEQ. ret=%x", ret);
  608. probe3:
  609. ret = ehca_destroy_eq(shca, &shca->eq);
  610. if (ret)
  611. ehca_err(&shca->ib_device,
  612. "Cannot destroy EQ. ret=%x", ret);
  613. probe1:
  614. ib_dealloc_device(&shca->ib_device);
  615. return -EINVAL;
  616. }
  617. static int __devexit ehca_remove(struct ibmebus_dev *dev)
  618. {
  619. struct ehca_shca *shca = dev->ofdev.dev.driver_data;
  620. int ret;
  621. ehca_remove_device_sysfs(dev);
  622. if (ehca_open_aqp1 == 1) {
  623. int i;
  624. for (i = 0; i < shca->num_ports; i++) {
  625. ret = ehca_destroy_aqp1(&shca->sport[i]);
  626. if (ret)
  627. ehca_err(&shca->ib_device,
  628. "Cannot destroy AQP1 for port %x "
  629. "ret=%x", ret, i);
  630. }
  631. }
  632. ib_unregister_device(&shca->ib_device);
  633. ret = ehca_dereg_internal_maxmr(shca);
  634. if (ret)
  635. ehca_err(&shca->ib_device,
  636. "Cannot destroy internal MR. ret=%x", ret);
  637. ret = ehca_dealloc_pd(&shca->pd->ib_pd);
  638. if (ret)
  639. ehca_err(&shca->ib_device,
  640. "Cannot destroy internal PD. ret=%x", ret);
  641. ret = ehca_destroy_eq(shca, &shca->eq);
  642. if (ret)
  643. ehca_err(&shca->ib_device, "Cannot destroy EQ. ret=%x", ret);
  644. ret = ehca_destroy_eq(shca, &shca->neq);
  645. if (ret)
  646. ehca_err(&shca->ib_device, "Canot destroy NEQ. ret=%x", ret);
  647. ib_dealloc_device(&shca->ib_device);
  648. spin_lock(&shca_list_lock);
  649. list_del(&shca->shca_list);
  650. spin_unlock(&shca_list_lock);
  651. return ret;
  652. }
  653. static struct of_device_id ehca_device_table[] =
  654. {
  655. {
  656. .name = "lhca",
  657. .compatible = "IBM,lhca",
  658. },
  659. {},
  660. };
  661. static struct ibmebus_driver ehca_driver = {
  662. .name = "ehca",
  663. .id_table = ehca_device_table,
  664. .probe = ehca_probe,
  665. .remove = ehca_remove,
  666. };
  667. void ehca_poll_eqs(unsigned long data)
  668. {
  669. struct ehca_shca *shca;
  670. spin_lock(&shca_list_lock);
  671. list_for_each_entry(shca, &shca_list, shca_list) {
  672. if (shca->eq.is_initialized) {
  673. /* call deadman proc only if eq ptr does not change */
  674. struct ehca_eq *eq = &shca->eq;
  675. int max = 3;
  676. volatile u64 q_ofs, q_ofs2;
  677. u64 flags;
  678. spin_lock_irqsave(&eq->spinlock, flags);
  679. q_ofs = eq->ipz_queue.current_q_offset;
  680. spin_unlock_irqrestore(&eq->spinlock, flags);
  681. do {
  682. spin_lock_irqsave(&eq->spinlock, flags);
  683. q_ofs2 = eq->ipz_queue.current_q_offset;
  684. spin_unlock_irqrestore(&eq->spinlock, flags);
  685. max--;
  686. } while (q_ofs == q_ofs2 && max > 0);
  687. if (q_ofs == q_ofs2)
  688. ehca_process_eq(shca, 0);
  689. }
  690. }
  691. mod_timer(&poll_eqs_timer, jiffies + HZ);
  692. spin_unlock(&shca_list_lock);
  693. }
  694. int __init ehca_module_init(void)
  695. {
  696. int ret;
  697. printk(KERN_INFO "eHCA Infiniband Device Driver "
  698. "(Rel.: SVNEHCA_0022)\n");
  699. idr_init(&ehca_qp_idr);
  700. idr_init(&ehca_cq_idr);
  701. spin_lock_init(&ehca_qp_idr_lock);
  702. spin_lock_init(&ehca_cq_idr_lock);
  703. spin_lock_init(&hcall_lock);
  704. INIT_LIST_HEAD(&shca_list);
  705. spin_lock_init(&shca_list_lock);
  706. if ((ret = ehca_create_comp_pool())) {
  707. ehca_gen_err("Cannot create comp pool.");
  708. return ret;
  709. }
  710. if ((ret = ehca_create_slab_caches())) {
  711. ehca_gen_err("Cannot create SLAB caches");
  712. ret = -ENOMEM;
  713. goto module_init1;
  714. }
  715. if ((ret = ibmebus_register_driver(&ehca_driver))) {
  716. ehca_gen_err("Cannot register eHCA device driver");
  717. ret = -EINVAL;
  718. goto module_init2;
  719. }
  720. ehca_create_driver_sysfs(&ehca_driver);
  721. if (ehca_poll_all_eqs != 1) {
  722. ehca_gen_err("WARNING!!!");
  723. ehca_gen_err("It is possible to lose interrupts.");
  724. } else {
  725. init_timer(&poll_eqs_timer);
  726. poll_eqs_timer.function = ehca_poll_eqs;
  727. poll_eqs_timer.expires = jiffies + HZ;
  728. add_timer(&poll_eqs_timer);
  729. }
  730. return 0;
  731. module_init2:
  732. ehca_destroy_slab_caches();
  733. module_init1:
  734. ehca_destroy_comp_pool();
  735. return ret;
  736. };
  737. void __exit ehca_module_exit(void)
  738. {
  739. if (ehca_poll_all_eqs == 1)
  740. del_timer_sync(&poll_eqs_timer);
  741. ehca_remove_driver_sysfs(&ehca_driver);
  742. ibmebus_unregister_driver(&ehca_driver);
  743. ehca_destroy_slab_caches();
  744. ehca_destroy_comp_pool();
  745. idr_destroy(&ehca_cq_idr);
  746. idr_destroy(&ehca_qp_idr);
  747. };
  748. module_init(ehca_module_init);
  749. module_exit(ehca_module_exit);