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 9 #ifndef SMCD_ISM_H 10 #define SMCD_ISM_H 11 12 #include <linux/uio.h> 13 #include <linux/types.h> 14 #include <linux/mutex.h> 15 16 #include "smc.h" 17 18 #define SMC_VIRTUAL_ISM_CHID_MASK 0xFF00 19 20 struct smcd_dev_list { /* List of SMCD devices */ 21 struct list_head list; 22 struct mutex mutex; /* Protects list of devices */ 23 }; 24 25 extern struct smcd_dev_list smcd_dev_list; /* list of smcd devices */ 26 27 struct smc_ism_vlanid { /* VLAN id set on ISM device */ 28 struct list_head list; 29 unsigned short vlanid; /* Vlan id */ 30 refcount_t refcnt; /* Reference count */ 31 }; 32 33 struct smcd_dev; 34 35 int smc_ism_cantalk(struct smcd_gid *peer_gid, unsigned short vlan_id, 36 struct smcd_dev *dev); 37 void smc_ism_set_conn(struct smc_connection *conn); 38 void smc_ism_unset_conn(struct smc_connection *conn); 39 int smc_ism_get_vlan(struct smcd_dev *dev, unsigned short vlan_id); 40 int smc_ism_put_vlan(struct smcd_dev *dev, unsigned short vlan_id); 41 int smc_ism_register_dmb(struct smc_link_group *lgr, int buf_size, 42 struct smc_buf_desc *dmb_desc); 43 int smc_ism_unregister_dmb(struct smcd_dev *dev, struct smc_buf_desc *dmb_desc); 44 bool smc_ism_support_dmb_nocopy(struct smcd_dev *smcd); 45 int smc_ism_attach_dmb(struct smcd_dev *dev, u64 token, 46 struct smc_buf_desc *dmb_desc); 47 int smc_ism_detach_dmb(struct smcd_dev *dev, u64 token); 48 int smc_ism_signal_shutdown(struct smc_link_group *lgr); 49 void smc_ism_get_system_eid(u8 **eid); 50 u16 smc_ism_get_chid(struct smcd_dev *dev); 51 bool smc_ism_is_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 56 static inline int smc_ism_write(struct smcd_dev *smcd, u64 dmb_tok, 57 unsigned int idx, bool sf, unsigned int offset, 58 void *data, size_t len) 59 { 60 int rc; 61 62 rc = smcd->ops->move_data(smcd, dmb_tok, idx, sf, offset, data, len); 63 return rc < 0 ? rc : 0; 64 } 65 66 static inline bool __smc_ism_is_virtual(u16 chid) 67 { 68 /* CHIDs in range of 0xFF00 to 0xFFFF are reserved 69 * for virtual ISM device. 70 * 71 * loopback-ism: 0xFFFF 72 * virtio-ism: 0xFF00 ~ 0xFFFE 73 */ 74 return ((chid & 0xFF00) == 0xFF00); 75 } 76 77 static inline bool smc_ism_is_virtual(struct smcd_dev *smcd) 78 { 79 u16 chid = smcd->ops->get_chid(smcd); 80 81 return __smc_ism_is_virtual(chid); 82 } 83 84 #endif 85