smc_ism.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Shared Memory Communications Direct over ISM devices (SMC-D)
  3. *
  4. * SMC-D ISM device structure definitions.
  5. *
  6. * Copyright IBM Corp. 2018
  7. */
  8. #ifndef SMCD_ISM_H
  9. #define SMCD_ISM_H
  10. #include <linux/uio.h>
  11. #include <linux/types.h>
  12. #include <linux/mutex.h>
  13. #include <linux/dibs.h>
  14. #include "smc.h"
  15. #define SMC_EMULATED_ISM_CHID_MASK 0xFF00
  16. #define SMC_ISM_IDENT_MASK 0x00FFFF
  17. struct smcd_dev_list { /* List of SMCD devices */
  18. struct list_head list;
  19. struct mutex mutex; /* Protects list of devices */
  20. };
  21. extern struct smcd_dev_list smcd_dev_list; /* list of smcd devices */
  22. struct smc_ism_vlanid { /* VLAN id set on ISM device */
  23. struct list_head list;
  24. unsigned short vlanid; /* Vlan id */
  25. refcount_t refcnt; /* Reference count */
  26. };
  27. struct smc_ism_seid {
  28. u8 seid_string[24];
  29. u8 serial_number[4];
  30. u8 type[4];
  31. };
  32. struct smcd_dev;
  33. int smc_ism_cantalk(struct smcd_gid *peer_gid, unsigned short vlan_id,
  34. struct smcd_dev *dev);
  35. void smc_ism_set_conn(struct smc_connection *conn);
  36. void smc_ism_unset_conn(struct smc_connection *conn);
  37. int smc_ism_get_vlan(struct smcd_dev *dev, unsigned short vlan_id);
  38. int smc_ism_put_vlan(struct smcd_dev *dev, unsigned short vlan_id);
  39. int smc_ism_register_dmb(struct smc_link_group *lgr, int buf_size,
  40. struct smc_buf_desc *dmb_desc);
  41. void smc_ism_unregister_dmb(struct smcd_dev *dev,
  42. struct smc_buf_desc *dmb_desc);
  43. bool smc_ism_support_dmb_nocopy(struct smcd_dev *smcd);
  44. int smc_ism_attach_dmb(struct smcd_dev *dev, u64 token,
  45. struct smc_buf_desc *dmb_desc);
  46. int smc_ism_detach_dmb(struct smcd_dev *dev, u64 token);
  47. int smc_ism_signal_shutdown(struct smc_link_group *lgr);
  48. void smc_ism_get_system_eid(u8 **eid);
  49. u16 smc_ism_get_chid(struct smcd_dev *dev);
  50. bool smc_ism_is_v2_capable(void);
  51. void smc_ism_set_v2_capable(void);
  52. int smc_ism_init(void);
  53. void smc_ism_exit(void);
  54. int smcd_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb);
  55. static inline int smc_ism_write(struct smcd_dev *smcd, u64 dmb_tok,
  56. unsigned int idx, bool sf, unsigned int offset,
  57. void *data, size_t len)
  58. {
  59. int rc;
  60. rc = smcd->dibs->ops->move_data(smcd->dibs, dmb_tok, idx, sf, offset,
  61. data, len);
  62. return rc < 0 ? rc : 0;
  63. }
  64. static inline bool __smc_ism_is_emulated(u16 chid)
  65. {
  66. /* CHIDs in range of 0xFF00 to 0xFFFF are reserved
  67. * for Emulated-ISM device.
  68. *
  69. * loopback-ism: 0xFFFF
  70. * virtio-ism: 0xFF00 ~ 0xFFFE
  71. */
  72. return ((chid & 0xFF00) == 0xFF00);
  73. }
  74. static inline bool smc_ism_is_emulated(struct smcd_dev *smcd)
  75. {
  76. u16 chid = smcd->dibs->ops->get_fabric_id(smcd->dibs);
  77. return __smc_ism_is_emulated(chid);
  78. }
  79. static inline bool smc_ism_is_loopback(struct dibs_dev *dibs)
  80. {
  81. return (dibs->ops->get_fabric_id(dibs) == DIBS_LOOPBACK_FABRIC);
  82. }
  83. static inline void copy_to_smcdgid(struct smcd_gid *sgid, uuid_t *dibs_gid)
  84. {
  85. __be64 temp;
  86. memcpy(&temp, dibs_gid, sizeof(sgid->gid));
  87. sgid->gid = ntohll(temp);
  88. memcpy(&temp, (uint8_t *)dibs_gid + sizeof(sgid->gid),
  89. sizeof(sgid->gid_ext));
  90. sgid->gid_ext = ntohll(temp);
  91. }
  92. static inline void copy_to_dibsgid(uuid_t *dibs_gid, struct smcd_gid *sgid)
  93. {
  94. __be64 temp;
  95. temp = htonll(sgid->gid);
  96. memcpy(dibs_gid, &temp, sizeof(sgid->gid));
  97. temp = htonll(sgid->gid_ext);
  98. memcpy((uint8_t *)dibs_gid + sizeof(sgid->gid), &temp,
  99. sizeof(sgid->gid_ext));
  100. }
  101. #endif