smc_ism.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "smc.h"
  14. #define SMC_EMULATED_ISM_CHID_MASK 0xFF00
  15. #define SMC_ISM_IDENT_MASK 0x00FFFF
  16. struct smcd_dev_list { /* List of SMCD devices */
  17. struct list_head list;
  18. struct mutex mutex; /* Protects list of devices */
  19. };
  20. extern struct smcd_dev_list smcd_dev_list; /* list of smcd devices */
  21. struct smc_ism_vlanid { /* VLAN id set on ISM device */
  22. struct list_head list;
  23. unsigned short vlanid; /* Vlan id */
  24. refcount_t refcnt; /* Reference count */
  25. };
  26. struct smc_ism_seid {
  27. u8 seid_string[24];
  28. u8 serial_number[4];
  29. u8 type[4];
  30. };
  31. struct smcd_dev;
  32. int smc_ism_cantalk(struct smcd_gid *peer_gid, unsigned short vlan_id,
  33. struct smcd_dev *dev);
  34. void smc_ism_set_conn(struct smc_connection *conn);
  35. void smc_ism_unset_conn(struct smc_connection *conn);
  36. int smc_ism_get_vlan(struct smcd_dev *dev, unsigned short vlan_id);
  37. int smc_ism_put_vlan(struct smcd_dev *dev, unsigned short vlan_id);
  38. int smc_ism_register_dmb(struct smc_link_group *lgr, int buf_size,
  39. struct smc_buf_desc *dmb_desc);
  40. int smc_ism_unregister_dmb(struct smcd_dev *dev, struct smc_buf_desc *dmb_desc);
  41. bool smc_ism_support_dmb_nocopy(struct smcd_dev *smcd);
  42. int smc_ism_attach_dmb(struct smcd_dev *dev, u64 token,
  43. struct smc_buf_desc *dmb_desc);
  44. int smc_ism_detach_dmb(struct smcd_dev *dev, u64 token);
  45. int smc_ism_signal_shutdown(struct smc_link_group *lgr);
  46. void smc_ism_get_system_eid(u8 **eid);
  47. u16 smc_ism_get_chid(struct smcd_dev *dev);
  48. bool smc_ism_is_v2_capable(void);
  49. void smc_ism_set_v2_capable(void);
  50. int smc_ism_init(void);
  51. void smc_ism_exit(void);
  52. int smcd_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb);
  53. static inline int smc_ism_write(struct smcd_dev *smcd, u64 dmb_tok,
  54. unsigned int idx, bool sf, unsigned int offset,
  55. void *data, size_t len)
  56. {
  57. int rc;
  58. rc = smcd->ops->move_data(smcd, dmb_tok, idx, sf, offset, data, len);
  59. return rc < 0 ? rc : 0;
  60. }
  61. static inline bool __smc_ism_is_emulated(u16 chid)
  62. {
  63. /* CHIDs in range of 0xFF00 to 0xFFFF are reserved
  64. * for Emulated-ISM device.
  65. *
  66. * loopback-ism: 0xFFFF
  67. * virtio-ism: 0xFF00 ~ 0xFFFE
  68. */
  69. return ((chid & 0xFF00) == 0xFF00);
  70. }
  71. static inline bool smc_ism_is_emulated(struct smcd_dev *smcd)
  72. {
  73. u16 chid = smcd->ops->get_chid(smcd);
  74. return __smc_ism_is_emulated(chid);
  75. }
  76. static inline bool smc_ism_is_loopback(struct smcd_dev *smcd)
  77. {
  78. return (smcd->ops->get_chid(smcd) == 0xFFFF);
  79. }
  80. #endif