smc_ism.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Shared Memory Communications Direct over ISM devices (SMC-D)
  3. *
  4. * Functions for ISM device.
  5. *
  6. * Copyright IBM Corp. 2018
  7. */
  8. #include <linux/if_vlan.h>
  9. #include <linux/spinlock.h>
  10. #include <linux/mutex.h>
  11. #include <linux/slab.h>
  12. #include <asm/page.h>
  13. #include "smc.h"
  14. #include "smc_core.h"
  15. #include "smc_ism.h"
  16. #include "smc_pnet.h"
  17. #include "smc_netlink.h"
  18. #include "linux/dibs.h"
  19. struct smcd_dev_list smcd_dev_list = {
  20. .list = LIST_HEAD_INIT(smcd_dev_list.list),
  21. .mutex = __MUTEX_INITIALIZER(smcd_dev_list.mutex)
  22. };
  23. static bool smc_ism_v2_capable;
  24. static u8 smc_ism_v2_system_eid[SMC_MAX_EID_LEN];
  25. static void smcd_register_dev(struct dibs_dev *dibs);
  26. static void smcd_unregister_dev(struct dibs_dev *dibs);
  27. static void smcd_handle_event(struct dibs_dev *dibs,
  28. const struct dibs_event *event);
  29. static void smcd_handle_irq(struct dibs_dev *dibs, unsigned int dmbno,
  30. u16 dmbemask);
  31. static struct dibs_client_ops smc_client_ops = {
  32. .add_dev = smcd_register_dev,
  33. .del_dev = smcd_unregister_dev,
  34. .handle_event = smcd_handle_event,
  35. .handle_irq = smcd_handle_irq,
  36. };
  37. static struct dibs_client smc_dibs_client = {
  38. .name = "SMC-D",
  39. .ops = &smc_client_ops,
  40. };
  41. static void smc_ism_create_system_eid(void)
  42. {
  43. struct smc_ism_seid *seid =
  44. (struct smc_ism_seid *)smc_ism_v2_system_eid;
  45. #if IS_ENABLED(CONFIG_S390)
  46. struct cpuid id;
  47. u16 ident_tail;
  48. char tmp[5];
  49. memcpy(seid->seid_string, "IBM-SYSZ-ISMSEID00000000", 24);
  50. get_cpu_id(&id);
  51. ident_tail = (u16)(id.ident & SMC_ISM_IDENT_MASK);
  52. snprintf(tmp, 5, "%04X", ident_tail);
  53. memcpy(seid->serial_number, tmp, 4);
  54. snprintf(tmp, 5, "%04X", id.machine);
  55. memcpy(seid->type, tmp, 4);
  56. #else
  57. memset(seid, 0, SMC_MAX_EID_LEN);
  58. #endif
  59. }
  60. /* Test if an ISM communication is possible - same CPC */
  61. int smc_ism_cantalk(struct smcd_gid *peer_gid, unsigned short vlan_id,
  62. struct smcd_dev *smcd)
  63. {
  64. struct dibs_dev *dibs = smcd->dibs;
  65. uuid_t ism_rgid;
  66. copy_to_dibsgid(&ism_rgid, peer_gid);
  67. return dibs->ops->query_remote_gid(dibs, &ism_rgid, vlan_id ? 1 : 0,
  68. vlan_id);
  69. }
  70. void smc_ism_get_system_eid(u8 **eid)
  71. {
  72. if (!smc_ism_v2_capable)
  73. *eid = NULL;
  74. else
  75. *eid = smc_ism_v2_system_eid;
  76. }
  77. u16 smc_ism_get_chid(struct smcd_dev *smcd)
  78. {
  79. return smcd->dibs->ops->get_fabric_id(smcd->dibs);
  80. }
  81. /* HW supports ISM V2 and thus System EID is defined */
  82. bool smc_ism_is_v2_capable(void)
  83. {
  84. return smc_ism_v2_capable;
  85. }
  86. void smc_ism_set_v2_capable(void)
  87. {
  88. smc_ism_v2_capable = true;
  89. }
  90. /* Set a connection using this DMBE. */
  91. void smc_ism_set_conn(struct smc_connection *conn)
  92. {
  93. unsigned long flags;
  94. spin_lock_irqsave(&conn->lgr->smcd->lock, flags);
  95. conn->lgr->smcd->conn[conn->rmb_desc->sba_idx] = conn;
  96. spin_unlock_irqrestore(&conn->lgr->smcd->lock, flags);
  97. }
  98. /* Unset a connection using this DMBE. */
  99. void smc_ism_unset_conn(struct smc_connection *conn)
  100. {
  101. unsigned long flags;
  102. if (!conn->rmb_desc)
  103. return;
  104. spin_lock_irqsave(&conn->lgr->smcd->lock, flags);
  105. conn->lgr->smcd->conn[conn->rmb_desc->sba_idx] = NULL;
  106. spin_unlock_irqrestore(&conn->lgr->smcd->lock, flags);
  107. }
  108. /* Register a VLAN identifier with the ISM device. Use a reference count
  109. * and add a VLAN identifier only when the first DMB using this VLAN is
  110. * registered.
  111. */
  112. int smc_ism_get_vlan(struct smcd_dev *smcd, unsigned short vlanid)
  113. {
  114. struct smc_ism_vlanid *new_vlan, *vlan;
  115. unsigned long flags;
  116. int rc = 0;
  117. if (!vlanid) /* No valid vlan id */
  118. return -EINVAL;
  119. if (!smcd->dibs->ops->add_vlan_id)
  120. return -EOPNOTSUPP;
  121. /* create new vlan entry, in case we need it */
  122. new_vlan = kzalloc_obj(*new_vlan);
  123. if (!new_vlan)
  124. return -ENOMEM;
  125. new_vlan->vlanid = vlanid;
  126. refcount_set(&new_vlan->refcnt, 1);
  127. /* if there is an existing entry, increase count and return */
  128. spin_lock_irqsave(&smcd->lock, flags);
  129. list_for_each_entry(vlan, &smcd->vlan, list) {
  130. if (vlan->vlanid == vlanid) {
  131. refcount_inc(&vlan->refcnt);
  132. kfree(new_vlan);
  133. goto out;
  134. }
  135. }
  136. /* no existing entry found.
  137. * add new entry to device; might fail, e.g., if HW limit reached
  138. */
  139. if (smcd->dibs->ops->add_vlan_id(smcd->dibs, vlanid)) {
  140. kfree(new_vlan);
  141. rc = -EIO;
  142. goto out;
  143. }
  144. list_add_tail(&new_vlan->list, &smcd->vlan);
  145. out:
  146. spin_unlock_irqrestore(&smcd->lock, flags);
  147. return rc;
  148. }
  149. /* Unregister a VLAN identifier with the ISM device. Use a reference count
  150. * and remove a VLAN identifier only when the last DMB using this VLAN is
  151. * unregistered.
  152. */
  153. int smc_ism_put_vlan(struct smcd_dev *smcd, unsigned short vlanid)
  154. {
  155. struct smc_ism_vlanid *vlan;
  156. unsigned long flags;
  157. bool found = false;
  158. int rc = 0;
  159. if (!vlanid) /* No valid vlan id */
  160. return -EINVAL;
  161. if (!smcd->dibs->ops->del_vlan_id)
  162. return -EOPNOTSUPP;
  163. spin_lock_irqsave(&smcd->lock, flags);
  164. list_for_each_entry(vlan, &smcd->vlan, list) {
  165. if (vlan->vlanid == vlanid) {
  166. if (!refcount_dec_and_test(&vlan->refcnt))
  167. goto out;
  168. found = true;
  169. break;
  170. }
  171. }
  172. if (!found) {
  173. rc = -ENOENT;
  174. goto out; /* VLAN id not in table */
  175. }
  176. /* Found and the last reference just gone */
  177. if (smcd->dibs->ops->del_vlan_id(smcd->dibs, vlanid))
  178. rc = -EIO;
  179. list_del(&vlan->list);
  180. kfree(vlan);
  181. out:
  182. spin_unlock_irqrestore(&smcd->lock, flags);
  183. return rc;
  184. }
  185. void smc_ism_unregister_dmb(struct smcd_dev *smcd,
  186. struct smc_buf_desc *dmb_desc)
  187. {
  188. struct dibs_dmb dmb;
  189. if (!dmb_desc->dma_addr)
  190. return;
  191. memset(&dmb, 0, sizeof(dmb));
  192. dmb.dmb_tok = dmb_desc->token;
  193. dmb.idx = dmb_desc->sba_idx;
  194. dmb.cpu_addr = dmb_desc->cpu_addr;
  195. dmb.dma_addr = dmb_desc->dma_addr;
  196. dmb.dmb_len = dmb_desc->len;
  197. smcd->dibs->ops->unregister_dmb(smcd->dibs, &dmb);
  198. return;
  199. }
  200. int smc_ism_register_dmb(struct smc_link_group *lgr, int dmb_len,
  201. struct smc_buf_desc *dmb_desc)
  202. {
  203. struct dibs_dev *dibs;
  204. struct dibs_dmb dmb;
  205. int rc;
  206. memset(&dmb, 0, sizeof(dmb));
  207. dmb.dmb_len = dmb_len;
  208. dmb.idx = dmb_desc->sba_idx;
  209. dmb.vlan_id = lgr->vlan_id;
  210. copy_to_dibsgid(&dmb.rgid, &lgr->peer_gid);
  211. dibs = lgr->smcd->dibs;
  212. rc = dibs->ops->register_dmb(dibs, &dmb, &smc_dibs_client);
  213. if (!rc) {
  214. dmb_desc->sba_idx = dmb.idx;
  215. dmb_desc->token = dmb.dmb_tok;
  216. dmb_desc->cpu_addr = dmb.cpu_addr;
  217. dmb_desc->dma_addr = dmb.dma_addr;
  218. dmb_desc->len = dmb.dmb_len;
  219. }
  220. return rc;
  221. }
  222. bool smc_ism_support_dmb_nocopy(struct smcd_dev *smcd)
  223. {
  224. /* for now only loopback-ism supports
  225. * merging sndbuf with peer DMB to avoid
  226. * data copies between them.
  227. */
  228. return (smcd->dibs->ops->support_mmapped_rdmb &&
  229. smcd->dibs->ops->support_mmapped_rdmb(smcd->dibs));
  230. }
  231. int smc_ism_attach_dmb(struct smcd_dev *dev, u64 token,
  232. struct smc_buf_desc *dmb_desc)
  233. {
  234. struct dibs_dmb dmb;
  235. int rc = 0;
  236. if (!dev->dibs->ops->attach_dmb)
  237. return -EINVAL;
  238. memset(&dmb, 0, sizeof(dmb));
  239. dmb.dmb_tok = token;
  240. rc = dev->dibs->ops->attach_dmb(dev->dibs, &dmb);
  241. if (!rc) {
  242. dmb_desc->sba_idx = dmb.idx;
  243. dmb_desc->token = dmb.dmb_tok;
  244. dmb_desc->cpu_addr = dmb.cpu_addr;
  245. dmb_desc->dma_addr = dmb.dma_addr;
  246. dmb_desc->len = dmb.dmb_len;
  247. dmb_desc->is_attached = true;
  248. }
  249. return rc;
  250. }
  251. int smc_ism_detach_dmb(struct smcd_dev *dev, u64 token)
  252. {
  253. if (!dev->dibs->ops->detach_dmb)
  254. return -EINVAL;
  255. return dev->dibs->ops->detach_dmb(dev->dibs, token);
  256. }
  257. static int smc_nl_handle_smcd_dev(struct smcd_dev *smcd,
  258. struct sk_buff *skb,
  259. struct netlink_callback *cb)
  260. {
  261. char smc_pnet[SMC_MAX_PNETID_LEN + 1];
  262. struct smc_pci_dev smc_pci_dev;
  263. struct nlattr *port_attrs;
  264. struct dibs_dev *dibs;
  265. struct nlattr *attrs;
  266. int use_cnt = 0;
  267. void *nlh;
  268. dibs = smcd->dibs;
  269. nlh = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
  270. &smc_gen_nl_family, NLM_F_MULTI,
  271. SMC_NETLINK_GET_DEV_SMCD);
  272. if (!nlh)
  273. goto errmsg;
  274. attrs = nla_nest_start(skb, SMC_GEN_DEV_SMCD);
  275. if (!attrs)
  276. goto errout;
  277. use_cnt = atomic_read(&smcd->lgr_cnt);
  278. if (nla_put_u32(skb, SMC_NLA_DEV_USE_CNT, use_cnt))
  279. goto errattr;
  280. if (nla_put_u8(skb, SMC_NLA_DEV_IS_CRIT, use_cnt > 0))
  281. goto errattr;
  282. memset(&smc_pci_dev, 0, sizeof(smc_pci_dev));
  283. smc_set_pci_values(to_pci_dev(dibs->dev.parent), &smc_pci_dev);
  284. if (nla_put_u32(skb, SMC_NLA_DEV_PCI_FID, smc_pci_dev.pci_fid))
  285. goto errattr;
  286. if (nla_put_u16(skb, SMC_NLA_DEV_PCI_CHID, smc_pci_dev.pci_pchid))
  287. goto errattr;
  288. if (nla_put_u16(skb, SMC_NLA_DEV_PCI_VENDOR, smc_pci_dev.pci_vendor))
  289. goto errattr;
  290. if (nla_put_u16(skb, SMC_NLA_DEV_PCI_DEVICE, smc_pci_dev.pci_device))
  291. goto errattr;
  292. if (nla_put_string(skb, SMC_NLA_DEV_PCI_ID, smc_pci_dev.pci_id))
  293. goto errattr;
  294. port_attrs = nla_nest_start(skb, SMC_NLA_DEV_PORT);
  295. if (!port_attrs)
  296. goto errattr;
  297. if (nla_put_u8(skb, SMC_NLA_DEV_PORT_PNET_USR, smcd->pnetid_by_user))
  298. goto errportattr;
  299. memcpy(smc_pnet, smcd->pnetid, SMC_MAX_PNETID_LEN);
  300. smc_pnet[SMC_MAX_PNETID_LEN] = 0;
  301. if (nla_put_string(skb, SMC_NLA_DEV_PORT_PNETID, smc_pnet))
  302. goto errportattr;
  303. nla_nest_end(skb, port_attrs);
  304. nla_nest_end(skb, attrs);
  305. genlmsg_end(skb, nlh);
  306. return 0;
  307. errportattr:
  308. nla_nest_cancel(skb, port_attrs);
  309. errattr:
  310. nla_nest_cancel(skb, attrs);
  311. errout:
  312. nlmsg_cancel(skb, nlh);
  313. errmsg:
  314. return -EMSGSIZE;
  315. }
  316. static void smc_nl_prep_smcd_dev(struct smcd_dev_list *dev_list,
  317. struct sk_buff *skb,
  318. struct netlink_callback *cb)
  319. {
  320. struct smc_nl_dmp_ctx *cb_ctx = smc_nl_dmp_ctx(cb);
  321. int snum = cb_ctx->pos[0];
  322. struct smcd_dev *smcd;
  323. int num = 0;
  324. mutex_lock(&dev_list->mutex);
  325. list_for_each_entry(smcd, &dev_list->list, list) {
  326. if (num < snum)
  327. goto next;
  328. if (smc_ism_is_loopback(smcd->dibs))
  329. goto next;
  330. if (smc_nl_handle_smcd_dev(smcd, skb, cb))
  331. goto errout;
  332. next:
  333. num++;
  334. }
  335. errout:
  336. mutex_unlock(&dev_list->mutex);
  337. cb_ctx->pos[0] = num;
  338. }
  339. int smcd_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb)
  340. {
  341. smc_nl_prep_smcd_dev(&smcd_dev_list, skb, cb);
  342. return skb->len;
  343. }
  344. struct smc_ism_event_work {
  345. struct work_struct work;
  346. struct smcd_dev *smcd;
  347. struct dibs_event event;
  348. };
  349. #define ISM_EVENT_REQUEST 0x0001
  350. #define ISM_EVENT_RESPONSE 0x0002
  351. #define ISM_EVENT_REQUEST_IR 0x00000001
  352. #define ISM_EVENT_CODE_SHUTDOWN 0x80
  353. #define ISM_EVENT_CODE_TESTLINK 0x83
  354. union smcd_sw_event_info {
  355. u64 info;
  356. struct {
  357. u8 uid[SMC_LGR_ID_SIZE];
  358. unsigned short vlan_id;
  359. u16 code;
  360. };
  361. };
  362. static void smcd_handle_sw_event(struct smc_ism_event_work *wrk)
  363. {
  364. struct dibs_dev *dibs = wrk->smcd->dibs;
  365. union smcd_sw_event_info ev_info;
  366. struct smcd_gid peer_gid;
  367. uuid_t ism_rgid;
  368. copy_to_smcdgid(&peer_gid, &wrk->event.gid);
  369. ev_info.info = wrk->event.data;
  370. switch (wrk->event.subtype) {
  371. case ISM_EVENT_CODE_SHUTDOWN: /* Peer shut down DMBs */
  372. smc_smcd_terminate(wrk->smcd, &peer_gid, ev_info.vlan_id);
  373. break;
  374. case ISM_EVENT_CODE_TESTLINK: /* Activity timer */
  375. if (ev_info.code == ISM_EVENT_REQUEST &&
  376. dibs->ops->signal_event) {
  377. ev_info.code = ISM_EVENT_RESPONSE;
  378. copy_to_dibsgid(&ism_rgid, &peer_gid);
  379. dibs->ops->signal_event(dibs, &ism_rgid,
  380. ISM_EVENT_REQUEST_IR,
  381. ISM_EVENT_CODE_TESTLINK,
  382. ev_info.info);
  383. }
  384. break;
  385. }
  386. }
  387. /* worker for SMC-D events */
  388. static void smc_ism_event_work(struct work_struct *work)
  389. {
  390. struct smc_ism_event_work *wrk =
  391. container_of(work, struct smc_ism_event_work, work);
  392. struct smcd_gid smcd_gid;
  393. copy_to_smcdgid(&smcd_gid, &wrk->event.gid);
  394. switch (wrk->event.type) {
  395. case DIBS_DEV_EVENT: /* GID event, token is peer GID */
  396. smc_smcd_terminate(wrk->smcd, &smcd_gid, VLAN_VID_MASK);
  397. break;
  398. case DIBS_BUF_EVENT:
  399. break;
  400. case DIBS_SW_EVENT: /* Software defined event */
  401. smcd_handle_sw_event(wrk);
  402. break;
  403. }
  404. kfree(wrk);
  405. }
  406. static struct smcd_dev *smcd_alloc_dev(const char *name, int max_dmbs)
  407. {
  408. struct smcd_dev *smcd;
  409. smcd = kzalloc_obj(*smcd);
  410. if (!smcd)
  411. return NULL;
  412. smcd->conn = kzalloc_objs(struct smc_connection *, max_dmbs);
  413. if (!smcd->conn)
  414. goto free_smcd;
  415. smcd->event_wq = alloc_ordered_workqueue("ism_evt_wq-%s)",
  416. WQ_MEM_RECLAIM, name);
  417. if (!smcd->event_wq)
  418. goto free_conn;
  419. spin_lock_init(&smcd->lock);
  420. spin_lock_init(&smcd->lgr_lock);
  421. INIT_LIST_HEAD(&smcd->vlan);
  422. INIT_LIST_HEAD(&smcd->lgr_list);
  423. init_waitqueue_head(&smcd->lgrs_deleted);
  424. return smcd;
  425. free_conn:
  426. kfree(smcd->conn);
  427. free_smcd:
  428. kfree(smcd);
  429. return NULL;
  430. }
  431. static void smcd_register_dev(struct dibs_dev *dibs)
  432. {
  433. struct smcd_dev *smcd, *fentry;
  434. int max_dmbs;
  435. max_dmbs = dibs->ops->max_dmbs();
  436. smcd = smcd_alloc_dev(dev_name(&dibs->dev), max_dmbs);
  437. if (!smcd)
  438. return;
  439. smcd->dibs = dibs;
  440. dibs_set_priv(dibs, &smc_dibs_client, smcd);
  441. if (smc_pnetid_by_dev_port(dibs->dev.parent, 0, smcd->pnetid))
  442. smc_pnetid_by_table_smcd(smcd);
  443. if (smc_ism_is_loopback(dibs) ||
  444. (dibs->ops->add_vlan_id &&
  445. !dibs->ops->add_vlan_id(dibs, ISM_RESERVED_VLANID))) {
  446. smc_ism_set_v2_capable();
  447. }
  448. mutex_lock(&smcd_dev_list.mutex);
  449. /* sort list:
  450. * - devices without pnetid before devices with pnetid;
  451. * - loopback-ism always at the very beginning;
  452. */
  453. if (!smcd->pnetid[0]) {
  454. fentry = list_first_entry_or_null(&smcd_dev_list.list,
  455. struct smcd_dev, list);
  456. if (fentry && smc_ism_is_loopback(fentry->dibs))
  457. list_add(&smcd->list, &fentry->list);
  458. else
  459. list_add(&smcd->list, &smcd_dev_list.list);
  460. } else {
  461. list_add_tail(&smcd->list, &smcd_dev_list.list);
  462. }
  463. mutex_unlock(&smcd_dev_list.mutex);
  464. if (smc_pnet_is_pnetid_set(smcd->pnetid))
  465. pr_warn_ratelimited("smc: adding smcd device %s with pnetid %.16s%s\n",
  466. dev_name(&dibs->dev), smcd->pnetid,
  467. smcd->pnetid_by_user ?
  468. " (user defined)" :
  469. "");
  470. else
  471. pr_warn_ratelimited("smc: adding smcd device %s without pnetid\n",
  472. dev_name(&dibs->dev));
  473. return;
  474. }
  475. static void smcd_unregister_dev(struct dibs_dev *dibs)
  476. {
  477. struct smcd_dev *smcd = dibs_get_priv(dibs, &smc_dibs_client);
  478. pr_warn_ratelimited("smc: removing smcd device %s\n",
  479. dev_name(&dibs->dev));
  480. smcd->going_away = 1;
  481. smc_smcd_terminate_all(smcd);
  482. mutex_lock(&smcd_dev_list.mutex);
  483. list_del_init(&smcd->list);
  484. mutex_unlock(&smcd_dev_list.mutex);
  485. destroy_workqueue(smcd->event_wq);
  486. kfree(smcd->conn);
  487. kfree(smcd);
  488. }
  489. /* SMCD Device event handler. Called from ISM device interrupt handler.
  490. * Parameters are ism device pointer,
  491. * - event->type (0 --> DMB, 1 --> GID),
  492. * - event->code (event code),
  493. * - event->tok (either DMB token when event type 0, or GID when event type 1)
  494. * - event->time (time of day)
  495. * - event->info (debug info).
  496. *
  497. * Context:
  498. * - Function called in IRQ context from ISM device driver event handler.
  499. */
  500. static void smcd_handle_event(struct dibs_dev *dibs,
  501. const struct dibs_event *event)
  502. {
  503. struct smcd_dev *smcd = dibs_get_priv(dibs, &smc_dibs_client);
  504. struct smc_ism_event_work *wrk;
  505. if (smcd->going_away)
  506. return;
  507. /* copy event to event work queue, and let it be handled there */
  508. wrk = kmalloc_obj(*wrk, GFP_ATOMIC);
  509. if (!wrk)
  510. return;
  511. INIT_WORK(&wrk->work, smc_ism_event_work);
  512. wrk->smcd = smcd;
  513. wrk->event = *event;
  514. queue_work(smcd->event_wq, &wrk->work);
  515. }
  516. /* SMCD Device interrupt handler. Called from ISM device interrupt handler.
  517. * Parameters are the ism device pointer, DMB number, and the DMBE bitmask.
  518. * Find the connection and schedule the tasklet for this connection.
  519. *
  520. * Context:
  521. * - Function called in IRQ context from ISM device driver IRQ handler.
  522. */
  523. static void smcd_handle_irq(struct dibs_dev *dibs, unsigned int dmbno,
  524. u16 dmbemask)
  525. {
  526. struct smcd_dev *smcd = dibs_get_priv(dibs, &smc_dibs_client);
  527. struct smc_connection *conn = NULL;
  528. unsigned long flags;
  529. spin_lock_irqsave(&smcd->lock, flags);
  530. conn = smcd->conn[dmbno];
  531. if (conn && !conn->killed)
  532. tasklet_schedule(&conn->rx_tsklet);
  533. spin_unlock_irqrestore(&smcd->lock, flags);
  534. }
  535. int smc_ism_signal_shutdown(struct smc_link_group *lgr)
  536. {
  537. int rc = 0;
  538. union smcd_sw_event_info ev_info;
  539. uuid_t ism_rgid;
  540. if (lgr->peer_shutdown)
  541. return 0;
  542. if (!lgr->smcd->dibs->ops->signal_event)
  543. return 0;
  544. memcpy(ev_info.uid, lgr->id, SMC_LGR_ID_SIZE);
  545. ev_info.vlan_id = lgr->vlan_id;
  546. ev_info.code = ISM_EVENT_REQUEST;
  547. copy_to_dibsgid(&ism_rgid, &lgr->peer_gid);
  548. rc = lgr->smcd->dibs->ops->signal_event(lgr->smcd->dibs, &ism_rgid,
  549. ISM_EVENT_REQUEST_IR,
  550. ISM_EVENT_CODE_SHUTDOWN,
  551. ev_info.info);
  552. return rc;
  553. }
  554. int smc_ism_init(void)
  555. {
  556. int rc = 0;
  557. smc_ism_v2_capable = false;
  558. smc_ism_create_system_eid();
  559. rc = dibs_register_client(&smc_dibs_client);
  560. return rc;
  561. }
  562. void smc_ism_exit(void)
  563. {
  564. dibs_unregister_client(&smc_dibs_client);
  565. }