xref: /linux/net/smc/smc_ism.h (revision 24168c5e6dfbdd5b414f048f47f75d64533296ca)
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 
21 struct smcd_dev_list {	/* List of SMCD devices */
22 	struct list_head list;
23 	struct mutex mutex;	/* Protects list of devices */
24 };
25 
26 extern struct smcd_dev_list	smcd_dev_list;	/* list of smcd devices */
27 
28 struct 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 
34 struct smc_ism_seid {
35 	u8 seid_string[24];
36 	u8 serial_number[4];
37 	u8 type[4];
38 };
39 
40 struct smcd_dev;
41 
42 int smc_ism_cantalk(struct smcd_gid *peer_gid, unsigned short vlan_id,
43 		    struct smcd_dev *dev);
44 void smc_ism_set_conn(struct smc_connection *conn);
45 void smc_ism_unset_conn(struct smc_connection *conn);
46 int smc_ism_get_vlan(struct smcd_dev *dev, unsigned short vlan_id);
47 int smc_ism_put_vlan(struct smcd_dev *dev, unsigned short vlan_id);
48 int smc_ism_register_dmb(struct smc_link_group *lgr, int buf_size,
49 			 struct smc_buf_desc *dmb_desc);
50 int smc_ism_unregister_dmb(struct smcd_dev *dev, struct smc_buf_desc *dmb_desc);
51 bool smc_ism_support_dmb_nocopy(struct smcd_dev *smcd);
52 int smc_ism_attach_dmb(struct smcd_dev *dev, u64 token,
53 		       struct smc_buf_desc *dmb_desc);
54 int smc_ism_detach_dmb(struct smcd_dev *dev, u64 token);
55 int smc_ism_signal_shutdown(struct smc_link_group *lgr);
56 void smc_ism_get_system_eid(u8 **eid);
57 u16 smc_ism_get_chid(struct smcd_dev *dev);
58 bool smc_ism_is_v2_capable(void);
59 void smc_ism_set_v2_capable(void);
60 int smc_ism_init(void);
61 void smc_ism_exit(void);
62 int smcd_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb);
63 
64 static inline int smc_ism_write(struct smcd_dev *smcd, u64 dmb_tok,
65 				unsigned int idx, bool sf, unsigned int offset,
66 				void *data, size_t len)
67 {
68 	int rc;
69 
70 	rc = smcd->ops->move_data(smcd, dmb_tok, idx, sf, offset, data, len);
71 	return rc < 0 ? rc : 0;
72 }
73 
74 static inline bool __smc_ism_is_emulated(u16 chid)
75 {
76 	/* CHIDs in range of 0xFF00 to 0xFFFF are reserved
77 	 * for Emulated-ISM device.
78 	 *
79 	 * loopback-ism:	0xFFFF
80 	 * virtio-ism:		0xFF00 ~ 0xFFFE
81 	 */
82 	return ((chid & 0xFF00) == 0xFF00);
83 }
84 
85 static inline bool smc_ism_is_emulated(struct smcd_dev *smcd)
86 {
87 	u16 chid = smcd->ops->get_chid(smcd);
88 
89 	return __smc_ism_is_emulated(chid);
90 }
91 
92 static inline bool smc_ism_is_loopback(struct smcd_dev *smcd)
93 {
94 	return (smcd->ops->get_chid(smcd) == 0xFFFF);
95 }
96 
97 #endif
98