ehca_main.c 24 KB

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