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