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 #include <linux/dibs.h>
16
17 #include "smc.h"
18
19 #define SMC_EMULATED_ISM_CHID_MASK 0xFF00
20 #define SMC_ISM_IDENT_MASK 0x00FFFF
21
22 struct smcd_dev_list { /* List of SMCD devices */
23 struct list_head list;
24 struct mutex mutex; /* Protects list of devices */
25 };
26
27 extern struct smcd_dev_list smcd_dev_list; /* list of smcd devices */
28
29 struct smc_ism_vlanid { /* VLAN id set on ISM device */
30 struct list_head list;
31 unsigned short vlanid; /* Vlan id */
32 refcount_t refcnt; /* Reference count */
33 };
34
35 struct smc_ism_seid {
36 u8 seid_string[24];
37 u8 serial_number[4];
38 u8 type[4];
39 };
40
41 struct smcd_dev;
42
43 int smc_ism_cantalk(struct smcd_gid *peer_gid, unsigned short vlan_id,
44 struct smcd_dev *dev);
45 void smc_ism_set_conn(struct smc_connection *conn);
46 void smc_ism_unset_conn(struct smc_connection *conn);
47 int smc_ism_get_vlan(struct smcd_dev *dev, unsigned short vlan_id);
48 int smc_ism_put_vlan(struct smcd_dev *dev, unsigned short vlan_id);
49 int smc_ism_register_dmb(struct smc_link_group *lgr, int buf_size,
50 struct smc_buf_desc *dmb_desc);
51 void smc_ism_unregister_dmb(struct smcd_dev *dev,
52 struct smc_buf_desc *dmb_desc);
53 bool smc_ism_support_dmb_nocopy(struct smcd_dev *smcd);
54 int smc_ism_attach_dmb(struct smcd_dev *dev, u64 token,
55 struct smc_buf_desc *dmb_desc);
56 int smc_ism_detach_dmb(struct smcd_dev *dev, u64 token);
57 int smc_ism_signal_shutdown(struct smc_link_group *lgr);
58 void smc_ism_get_system_eid(u8 **eid);
59 u16 smc_ism_get_chid(struct smcd_dev *dev);
60 bool smc_ism_is_v2_capable(void);
61 void smc_ism_set_v2_capable(void);
62 int smc_ism_init(void);
63 void smc_ism_exit(void);
64 int smcd_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb);
65
smc_ism_write(struct smcd_dev * smcd,u64 dmb_tok,unsigned int idx,bool sf,unsigned int offset,void * data,size_t len)66 static inline int smc_ism_write(struct smcd_dev *smcd, u64 dmb_tok,
67 unsigned int idx, bool sf, unsigned int offset,
68 void *data, size_t len)
69 {
70 int rc;
71
72 rc = smcd->dibs->ops->move_data(smcd->dibs, dmb_tok, idx, sf, offset,
73 data, len);
74
75 return rc < 0 ? rc : 0;
76 }
77
__smc_ism_is_emulated(u16 chid)78 static inline bool __smc_ism_is_emulated(u16 chid)
79 {
80 /* CHIDs in range of 0xFF00 to 0xFFFF are reserved
81 * for Emulated-ISM device.
82 *
83 * loopback-ism: 0xFFFF
84 * virtio-ism: 0xFF00 ~ 0xFFFE
85 */
86 return ((chid & 0xFF00) == 0xFF00);
87 }
88
smc_ism_is_emulated(struct smcd_dev * smcd)89 static inline bool smc_ism_is_emulated(struct smcd_dev *smcd)
90 {
91 u16 chid = smcd->dibs->ops->get_fabric_id(smcd->dibs);
92
93 return __smc_ism_is_emulated(chid);
94 }
95
smc_ism_is_loopback(struct dibs_dev * dibs)96 static inline bool smc_ism_is_loopback(struct dibs_dev *dibs)
97 {
98 return (dibs->ops->get_fabric_id(dibs) == DIBS_LOOPBACK_FABRIC);
99 }
100
copy_to_smcdgid(struct smcd_gid * sgid,uuid_t * dibs_gid)101 static inline void copy_to_smcdgid(struct smcd_gid *sgid, uuid_t *dibs_gid)
102 {
103 __be64 temp;
104
105 memcpy(&temp, dibs_gid, sizeof(sgid->gid));
106 sgid->gid = ntohll(temp);
107 memcpy(&temp, (uint8_t *)dibs_gid + sizeof(sgid->gid),
108 sizeof(sgid->gid_ext));
109 sgid->gid_ext = ntohll(temp);
110 }
111
copy_to_dibsgid(uuid_t * dibs_gid,struct smcd_gid * sgid)112 static inline void copy_to_dibsgid(uuid_t *dibs_gid, struct smcd_gid *sgid)
113 {
114 __be64 temp;
115
116 temp = htonll(sgid->gid);
117 memcpy(dibs_gid, &temp, sizeof(sgid->gid));
118 temp = htonll(sgid->gid_ext);
119 memcpy((uint8_t *)dibs_gid + sizeof(sgid->gid), &temp,
120 sizeof(sgid->gid_ext));
121 }
122
123 #endif
124