1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 /* Shared Memory Communications Direct over IS 2 /* Shared Memory Communications Direct over ISM devices (SMC-D) 3 * 3 * 4 * Functions for ISM device. 4 * Functions for ISM device. 5 * 5 * 6 * Copyright IBM Corp. 2018 6 * Copyright IBM Corp. 2018 7 */ 7 */ 8 8 9 #include <linux/if_vlan.h> 9 #include <linux/if_vlan.h> 10 #include <linux/spinlock.h> 10 #include <linux/spinlock.h> 11 #include <linux/mutex.h> 11 #include <linux/mutex.h> 12 #include <linux/slab.h> 12 #include <linux/slab.h> 13 #include <asm/page.h> 13 #include <asm/page.h> 14 14 15 #include "smc.h" 15 #include "smc.h" 16 #include "smc_core.h" 16 #include "smc_core.h" 17 #include "smc_ism.h" 17 #include "smc_ism.h" 18 #include "smc_pnet.h" 18 #include "smc_pnet.h" 19 #include "smc_netlink.h" 19 #include "smc_netlink.h" 20 #include "linux/ism.h" 20 #include "linux/ism.h" 21 21 22 struct smcd_dev_list smcd_dev_list = { 22 struct smcd_dev_list smcd_dev_list = { 23 .list = LIST_HEAD_INIT(smcd_dev_list.l 23 .list = LIST_HEAD_INIT(smcd_dev_list.list), 24 .mutex = __MUTEX_INITIALIZER(smcd_dev_ 24 .mutex = __MUTEX_INITIALIZER(smcd_dev_list.mutex) 25 }; 25 }; 26 26 27 static bool smc_ism_v2_capable; 27 static bool smc_ism_v2_capable; 28 static u8 smc_ism_v2_system_eid[SMC_MAX_EID_LE 28 static u8 smc_ism_v2_system_eid[SMC_MAX_EID_LEN]; 29 29 30 #if IS_ENABLED(CONFIG_ISM) 30 #if IS_ENABLED(CONFIG_ISM) 31 static void smcd_register_dev(struct ism_dev * 31 static void smcd_register_dev(struct ism_dev *ism); 32 static void smcd_unregister_dev(struct ism_dev 32 static void smcd_unregister_dev(struct ism_dev *ism); 33 static void smcd_handle_event(struct ism_dev * 33 static void smcd_handle_event(struct ism_dev *ism, struct ism_event *event); 34 static void smcd_handle_irq(struct ism_dev *is 34 static void smcd_handle_irq(struct ism_dev *ism, unsigned int dmbno, 35 u16 dmbemask); 35 u16 dmbemask); 36 36 37 static struct ism_client smc_ism_client = { 37 static struct ism_client smc_ism_client = { 38 .name = "SMC-D", 38 .name = "SMC-D", 39 .add = smcd_register_dev, 39 .add = smcd_register_dev, 40 .remove = smcd_unregister_dev, 40 .remove = smcd_unregister_dev, 41 .handle_event = smcd_handle_event, 41 .handle_event = smcd_handle_event, 42 .handle_irq = smcd_handle_irq, 42 .handle_irq = smcd_handle_irq, 43 }; 43 }; 44 #endif 44 #endif 45 45 46 static void smc_ism_create_system_eid(void) 46 static void smc_ism_create_system_eid(void) 47 { 47 { 48 struct smc_ism_seid *seid = 48 struct smc_ism_seid *seid = 49 (struct smc_ism_seid *)smc_ism 49 (struct smc_ism_seid *)smc_ism_v2_system_eid; 50 #if IS_ENABLED(CONFIG_S390) 50 #if IS_ENABLED(CONFIG_S390) 51 struct cpuid id; 51 struct cpuid id; 52 u16 ident_tail; 52 u16 ident_tail; 53 char tmp[5]; 53 char tmp[5]; 54 54 55 memcpy(seid->seid_string, "IBM-SYSZ-IS 55 memcpy(seid->seid_string, "IBM-SYSZ-ISMSEID00000000", 24); 56 get_cpu_id(&id); 56 get_cpu_id(&id); 57 ident_tail = (u16)(id.ident & SMC_ISM_ 57 ident_tail = (u16)(id.ident & SMC_ISM_IDENT_MASK); 58 snprintf(tmp, 5, "%04X", ident_tail); 58 snprintf(tmp, 5, "%04X", ident_tail); 59 memcpy(seid->serial_number, tmp, 4); 59 memcpy(seid->serial_number, tmp, 4); 60 snprintf(tmp, 5, "%04X", id.machine); 60 snprintf(tmp, 5, "%04X", id.machine); 61 memcpy(seid->type, tmp, 4); 61 memcpy(seid->type, tmp, 4); 62 #else 62 #else 63 memset(seid, 0, SMC_MAX_EID_LEN); 63 memset(seid, 0, SMC_MAX_EID_LEN); 64 #endif 64 #endif 65 } 65 } 66 66 67 /* Test if an ISM communication is possible - 67 /* Test if an ISM communication is possible - same CPC */ 68 int smc_ism_cantalk(struct smcd_gid *peer_gid, 68 int smc_ism_cantalk(struct smcd_gid *peer_gid, unsigned short vlan_id, 69 struct smcd_dev *smcd) 69 struct smcd_dev *smcd) 70 { 70 { 71 return smcd->ops->query_remote_gid(smc 71 return smcd->ops->query_remote_gid(smcd, peer_gid, vlan_id ? 1 : 0, 72 vla 72 vlan_id); 73 } 73 } 74 74 75 void smc_ism_get_system_eid(u8 **eid) 75 void smc_ism_get_system_eid(u8 **eid) 76 { 76 { 77 if (!smc_ism_v2_capable) 77 if (!smc_ism_v2_capable) 78 *eid = NULL; 78 *eid = NULL; 79 else 79 else 80 *eid = smc_ism_v2_system_eid; 80 *eid = smc_ism_v2_system_eid; 81 } 81 } 82 82 83 u16 smc_ism_get_chid(struct smcd_dev *smcd) 83 u16 smc_ism_get_chid(struct smcd_dev *smcd) 84 { 84 { 85 return smcd->ops->get_chid(smcd); 85 return smcd->ops->get_chid(smcd); 86 } 86 } 87 87 88 /* HW supports ISM V2 and thus System EID is d 88 /* HW supports ISM V2 and thus System EID is defined */ 89 bool smc_ism_is_v2_capable(void) 89 bool smc_ism_is_v2_capable(void) 90 { 90 { 91 return smc_ism_v2_capable; 91 return smc_ism_v2_capable; 92 } 92 } 93 93 94 void smc_ism_set_v2_capable(void) << 95 { << 96 smc_ism_v2_capable = true; << 97 } << 98 << 99 /* Set a connection using this DMBE. */ 94 /* Set a connection using this DMBE. */ 100 void smc_ism_set_conn(struct smc_connection *c 95 void smc_ism_set_conn(struct smc_connection *conn) 101 { 96 { 102 unsigned long flags; 97 unsigned long flags; 103 98 104 spin_lock_irqsave(&conn->lgr->smcd->lo 99 spin_lock_irqsave(&conn->lgr->smcd->lock, flags); 105 conn->lgr->smcd->conn[conn->rmb_desc-> 100 conn->lgr->smcd->conn[conn->rmb_desc->sba_idx] = conn; 106 spin_unlock_irqrestore(&conn->lgr->smc 101 spin_unlock_irqrestore(&conn->lgr->smcd->lock, flags); 107 } 102 } 108 103 109 /* Unset a connection using this DMBE. */ 104 /* Unset a connection using this DMBE. */ 110 void smc_ism_unset_conn(struct smc_connection 105 void smc_ism_unset_conn(struct smc_connection *conn) 111 { 106 { 112 unsigned long flags; 107 unsigned long flags; 113 108 114 if (!conn->rmb_desc) 109 if (!conn->rmb_desc) 115 return; 110 return; 116 111 117 spin_lock_irqsave(&conn->lgr->smcd->lo 112 spin_lock_irqsave(&conn->lgr->smcd->lock, flags); 118 conn->lgr->smcd->conn[conn->rmb_desc-> 113 conn->lgr->smcd->conn[conn->rmb_desc->sba_idx] = NULL; 119 spin_unlock_irqrestore(&conn->lgr->smc 114 spin_unlock_irqrestore(&conn->lgr->smcd->lock, flags); 120 } 115 } 121 116 122 /* Register a VLAN identifier with the ISM dev 117 /* Register a VLAN identifier with the ISM device. Use a reference count 123 * and add a VLAN identifier only when the fir 118 * and add a VLAN identifier only when the first DMB using this VLAN is 124 * registered. 119 * registered. 125 */ 120 */ 126 int smc_ism_get_vlan(struct smcd_dev *smcd, un 121 int smc_ism_get_vlan(struct smcd_dev *smcd, unsigned short vlanid) 127 { 122 { 128 struct smc_ism_vlanid *new_vlan, *vlan 123 struct smc_ism_vlanid *new_vlan, *vlan; 129 unsigned long flags; 124 unsigned long flags; 130 int rc = 0; 125 int rc = 0; 131 126 132 if (!vlanid) /* No 127 if (!vlanid) /* No valid vlan id */ 133 return -EINVAL; 128 return -EINVAL; 134 if (!smcd->ops->add_vlan_id) << 135 return -EOPNOTSUPP; << 136 129 137 /* create new vlan entry, in case we n 130 /* create new vlan entry, in case we need it */ 138 new_vlan = kzalloc(sizeof(*new_vlan), 131 new_vlan = kzalloc(sizeof(*new_vlan), GFP_KERNEL); 139 if (!new_vlan) 132 if (!new_vlan) 140 return -ENOMEM; 133 return -ENOMEM; 141 new_vlan->vlanid = vlanid; 134 new_vlan->vlanid = vlanid; 142 refcount_set(&new_vlan->refcnt, 1); 135 refcount_set(&new_vlan->refcnt, 1); 143 136 144 /* if there is an existing entry, incr 137 /* if there is an existing entry, increase count and return */ 145 spin_lock_irqsave(&smcd->lock, flags); 138 spin_lock_irqsave(&smcd->lock, flags); 146 list_for_each_entry(vlan, &smcd->vlan, 139 list_for_each_entry(vlan, &smcd->vlan, list) { 147 if (vlan->vlanid == vlanid) { 140 if (vlan->vlanid == vlanid) { 148 refcount_inc(&vlan->re 141 refcount_inc(&vlan->refcnt); 149 kfree(new_vlan); 142 kfree(new_vlan); 150 goto out; 143 goto out; 151 } 144 } 152 } 145 } 153 146 154 /* no existing entry found. 147 /* no existing entry found. 155 * add new entry to device; might fail 148 * add new entry to device; might fail, e.g., if HW limit reached 156 */ 149 */ 157 if (smcd->ops->add_vlan_id(smcd, vlani 150 if (smcd->ops->add_vlan_id(smcd, vlanid)) { 158 kfree(new_vlan); 151 kfree(new_vlan); 159 rc = -EIO; 152 rc = -EIO; 160 goto out; 153 goto out; 161 } 154 } 162 list_add_tail(&new_vlan->list, &smcd-> 155 list_add_tail(&new_vlan->list, &smcd->vlan); 163 out: 156 out: 164 spin_unlock_irqrestore(&smcd->lock, fl 157 spin_unlock_irqrestore(&smcd->lock, flags); 165 return rc; 158 return rc; 166 } 159 } 167 160 168 /* Unregister a VLAN identifier with the ISM d 161 /* Unregister a VLAN identifier with the ISM device. Use a reference count 169 * and remove a VLAN identifier only when the 162 * and remove a VLAN identifier only when the last DMB using this VLAN is 170 * unregistered. 163 * unregistered. 171 */ 164 */ 172 int smc_ism_put_vlan(struct smcd_dev *smcd, un 165 int smc_ism_put_vlan(struct smcd_dev *smcd, unsigned short vlanid) 173 { 166 { 174 struct smc_ism_vlanid *vlan; 167 struct smc_ism_vlanid *vlan; 175 unsigned long flags; 168 unsigned long flags; 176 bool found = false; 169 bool found = false; 177 int rc = 0; 170 int rc = 0; 178 171 179 if (!vlanid) /* No 172 if (!vlanid) /* No valid vlan id */ 180 return -EINVAL; 173 return -EINVAL; 181 if (!smcd->ops->del_vlan_id) << 182 return -EOPNOTSUPP; << 183 174 184 spin_lock_irqsave(&smcd->lock, flags); 175 spin_lock_irqsave(&smcd->lock, flags); 185 list_for_each_entry(vlan, &smcd->vlan, 176 list_for_each_entry(vlan, &smcd->vlan, list) { 186 if (vlan->vlanid == vlanid) { 177 if (vlan->vlanid == vlanid) { 187 if (!refcount_dec_and_ 178 if (!refcount_dec_and_test(&vlan->refcnt)) 188 goto out; 179 goto out; 189 found = true; 180 found = true; 190 break; 181 break; 191 } 182 } 192 } 183 } 193 if (!found) { 184 if (!found) { 194 rc = -ENOENT; 185 rc = -ENOENT; 195 goto out; /* VLA 186 goto out; /* VLAN id not in table */ 196 } 187 } 197 188 198 /* Found and the last reference just g 189 /* Found and the last reference just gone */ 199 if (smcd->ops->del_vlan_id(smcd, vlani 190 if (smcd->ops->del_vlan_id(smcd, vlanid)) 200 rc = -EIO; 191 rc = -EIO; 201 list_del(&vlan->list); 192 list_del(&vlan->list); 202 kfree(vlan); 193 kfree(vlan); 203 out: 194 out: 204 spin_unlock_irqrestore(&smcd->lock, fl 195 spin_unlock_irqrestore(&smcd->lock, flags); 205 return rc; 196 return rc; 206 } 197 } 207 198 208 int smc_ism_unregister_dmb(struct smcd_dev *sm 199 int smc_ism_unregister_dmb(struct smcd_dev *smcd, struct smc_buf_desc *dmb_desc) 209 { 200 { 210 struct smcd_dmb dmb; 201 struct smcd_dmb dmb; 211 int rc = 0; 202 int rc = 0; 212 203 213 if (!dmb_desc->dma_addr) 204 if (!dmb_desc->dma_addr) 214 return rc; 205 return rc; 215 206 216 memset(&dmb, 0, sizeof(dmb)); 207 memset(&dmb, 0, sizeof(dmb)); 217 dmb.dmb_tok = dmb_desc->token; 208 dmb.dmb_tok = dmb_desc->token; 218 dmb.sba_idx = dmb_desc->sba_idx; 209 dmb.sba_idx = dmb_desc->sba_idx; 219 dmb.cpu_addr = dmb_desc->cpu_addr; 210 dmb.cpu_addr = dmb_desc->cpu_addr; 220 dmb.dma_addr = dmb_desc->dma_addr; 211 dmb.dma_addr = dmb_desc->dma_addr; 221 dmb.dmb_len = dmb_desc->len; 212 dmb.dmb_len = dmb_desc->len; 222 rc = smcd->ops->unregister_dmb(smcd, & 213 rc = smcd->ops->unregister_dmb(smcd, &dmb); 223 if (!rc || rc == ISM_ERROR) { 214 if (!rc || rc == ISM_ERROR) { 224 dmb_desc->cpu_addr = NULL; 215 dmb_desc->cpu_addr = NULL; 225 dmb_desc->dma_addr = 0; 216 dmb_desc->dma_addr = 0; 226 } 217 } 227 218 228 return rc; 219 return rc; 229 } 220 } 230 221 231 int smc_ism_register_dmb(struct smc_link_group 222 int smc_ism_register_dmb(struct smc_link_group *lgr, int dmb_len, 232 struct smc_buf_desc * 223 struct smc_buf_desc *dmb_desc) 233 { 224 { >> 225 #if IS_ENABLED(CONFIG_ISM) 234 struct smcd_dmb dmb; 226 struct smcd_dmb dmb; 235 int rc; 227 int rc; 236 228 237 memset(&dmb, 0, sizeof(dmb)); 229 memset(&dmb, 0, sizeof(dmb)); 238 dmb.dmb_len = dmb_len; 230 dmb.dmb_len = dmb_len; 239 dmb.sba_idx = dmb_desc->sba_idx; 231 dmb.sba_idx = dmb_desc->sba_idx; 240 dmb.vlan_id = lgr->vlan_id; 232 dmb.vlan_id = lgr->vlan_id; 241 dmb.rgid = lgr->peer_gid.gid; 233 dmb.rgid = lgr->peer_gid.gid; 242 rc = lgr->smcd->ops->register_dmb(lgr- !! 234 rc = lgr->smcd->ops->register_dmb(lgr->smcd, &dmb, &smc_ism_client); 243 if (!rc) { 235 if (!rc) { 244 dmb_desc->sba_idx = dmb.sba_id 236 dmb_desc->sba_idx = dmb.sba_idx; 245 dmb_desc->token = dmb.dmb_tok; 237 dmb_desc->token = dmb.dmb_tok; 246 dmb_desc->cpu_addr = dmb.cpu_a 238 dmb_desc->cpu_addr = dmb.cpu_addr; 247 dmb_desc->dma_addr = dmb.dma_a 239 dmb_desc->dma_addr = dmb.dma_addr; 248 dmb_desc->len = dmb.dmb_len; 240 dmb_desc->len = dmb.dmb_len; 249 } 241 } 250 return rc; 242 return rc; 251 } !! 243 #else 252 !! 244 return 0; 253 bool smc_ism_support_dmb_nocopy(struct smcd_de !! 245 #endif 254 { << 255 /* for now only loopback-ism supports << 256 * merging sndbuf with peer DMB to avo << 257 * data copies between them. << 258 */ << 259 return (smcd->ops->support_dmb_nocopy << 260 smcd->ops->support_dmb_nocopy( << 261 } << 262 << 263 int smc_ism_attach_dmb(struct smcd_dev *dev, u << 264 struct smc_buf_desc *dm << 265 { << 266 struct smcd_dmb dmb; << 267 int rc = 0; << 268 << 269 if (!dev->ops->attach_dmb) << 270 return -EINVAL; << 271 << 272 memset(&dmb, 0, sizeof(dmb)); << 273 dmb.dmb_tok = token; << 274 rc = dev->ops->attach_dmb(dev, &dmb); << 275 if (!rc) { << 276 dmb_desc->sba_idx = dmb.sba_id << 277 dmb_desc->token = dmb.dmb_tok; << 278 dmb_desc->cpu_addr = dmb.cpu_a << 279 dmb_desc->dma_addr = dmb.dma_a << 280 dmb_desc->len = dmb.dmb_len; << 281 } << 282 return rc; << 283 } << 284 << 285 int smc_ism_detach_dmb(struct smcd_dev *dev, u << 286 { << 287 if (!dev->ops->detach_dmb) << 288 return -EINVAL; << 289 << 290 return dev->ops->detach_dmb(dev, token << 291 } 246 } 292 247 293 static int smc_nl_handle_smcd_dev(struct smcd_ 248 static int smc_nl_handle_smcd_dev(struct smcd_dev *smcd, 294 struct sk_bu 249 struct sk_buff *skb, 295 struct netli 250 struct netlink_callback *cb) 296 { 251 { 297 char smc_pnet[SMC_MAX_PNETID_LEN + 1]; 252 char smc_pnet[SMC_MAX_PNETID_LEN + 1]; 298 struct smc_pci_dev smc_pci_dev; 253 struct smc_pci_dev smc_pci_dev; 299 struct nlattr *port_attrs; 254 struct nlattr *port_attrs; 300 struct nlattr *attrs; 255 struct nlattr *attrs; 301 struct ism_dev *ism; 256 struct ism_dev *ism; 302 int use_cnt = 0; 257 int use_cnt = 0; 303 void *nlh; 258 void *nlh; 304 259 305 ism = smcd->priv; 260 ism = smcd->priv; 306 nlh = genlmsg_put(skb, NETLINK_CB(cb-> 261 nlh = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, 307 &smc_gen_nl_family, 262 &smc_gen_nl_family, NLM_F_MULTI, 308 SMC_NETLINK_GET_DEV_ 263 SMC_NETLINK_GET_DEV_SMCD); 309 if (!nlh) 264 if (!nlh) 310 goto errmsg; 265 goto errmsg; 311 attrs = nla_nest_start(skb, SMC_GEN_DE 266 attrs = nla_nest_start(skb, SMC_GEN_DEV_SMCD); 312 if (!attrs) 267 if (!attrs) 313 goto errout; 268 goto errout; 314 use_cnt = atomic_read(&smcd->lgr_cnt); 269 use_cnt = atomic_read(&smcd->lgr_cnt); 315 if (nla_put_u32(skb, SMC_NLA_DEV_USE_C 270 if (nla_put_u32(skb, SMC_NLA_DEV_USE_CNT, use_cnt)) 316 goto errattr; 271 goto errattr; 317 if (nla_put_u8(skb, SMC_NLA_DEV_IS_CRI 272 if (nla_put_u8(skb, SMC_NLA_DEV_IS_CRIT, use_cnt > 0)) 318 goto errattr; 273 goto errattr; 319 memset(&smc_pci_dev, 0, sizeof(smc_pci 274 memset(&smc_pci_dev, 0, sizeof(smc_pci_dev)); 320 smc_set_pci_values(to_pci_dev(ism->dev 275 smc_set_pci_values(to_pci_dev(ism->dev.parent), &smc_pci_dev); 321 if (nla_put_u32(skb, SMC_NLA_DEV_PCI_F 276 if (nla_put_u32(skb, SMC_NLA_DEV_PCI_FID, smc_pci_dev.pci_fid)) 322 goto errattr; 277 goto errattr; 323 if (nla_put_u16(skb, SMC_NLA_DEV_PCI_C 278 if (nla_put_u16(skb, SMC_NLA_DEV_PCI_CHID, smc_pci_dev.pci_pchid)) 324 goto errattr; 279 goto errattr; 325 if (nla_put_u16(skb, SMC_NLA_DEV_PCI_V 280 if (nla_put_u16(skb, SMC_NLA_DEV_PCI_VENDOR, smc_pci_dev.pci_vendor)) 326 goto errattr; 281 goto errattr; 327 if (nla_put_u16(skb, SMC_NLA_DEV_PCI_D 282 if (nla_put_u16(skb, SMC_NLA_DEV_PCI_DEVICE, smc_pci_dev.pci_device)) 328 goto errattr; 283 goto errattr; 329 if (nla_put_string(skb, SMC_NLA_DEV_PC 284 if (nla_put_string(skb, SMC_NLA_DEV_PCI_ID, smc_pci_dev.pci_id)) 330 goto errattr; 285 goto errattr; 331 286 332 port_attrs = nla_nest_start(skb, SMC_N 287 port_attrs = nla_nest_start(skb, SMC_NLA_DEV_PORT); 333 if (!port_attrs) 288 if (!port_attrs) 334 goto errattr; 289 goto errattr; 335 if (nla_put_u8(skb, SMC_NLA_DEV_PORT_P 290 if (nla_put_u8(skb, SMC_NLA_DEV_PORT_PNET_USR, smcd->pnetid_by_user)) 336 goto errportattr; 291 goto errportattr; 337 memcpy(smc_pnet, smcd->pnetid, SMC_MAX 292 memcpy(smc_pnet, smcd->pnetid, SMC_MAX_PNETID_LEN); 338 smc_pnet[SMC_MAX_PNETID_LEN] = 0; 293 smc_pnet[SMC_MAX_PNETID_LEN] = 0; 339 if (nla_put_string(skb, SMC_NLA_DEV_PO 294 if (nla_put_string(skb, SMC_NLA_DEV_PORT_PNETID, smc_pnet)) 340 goto errportattr; 295 goto errportattr; 341 296 342 nla_nest_end(skb, port_attrs); 297 nla_nest_end(skb, port_attrs); 343 nla_nest_end(skb, attrs); 298 nla_nest_end(skb, attrs); 344 genlmsg_end(skb, nlh); 299 genlmsg_end(skb, nlh); 345 return 0; 300 return 0; 346 301 347 errportattr: 302 errportattr: 348 nla_nest_cancel(skb, port_attrs); 303 nla_nest_cancel(skb, port_attrs); 349 errattr: 304 errattr: 350 nla_nest_cancel(skb, attrs); 305 nla_nest_cancel(skb, attrs); 351 errout: 306 errout: 352 nlmsg_cancel(skb, nlh); 307 nlmsg_cancel(skb, nlh); 353 errmsg: 308 errmsg: 354 return -EMSGSIZE; 309 return -EMSGSIZE; 355 } 310 } 356 311 357 static void smc_nl_prep_smcd_dev(struct smcd_d 312 static void smc_nl_prep_smcd_dev(struct smcd_dev_list *dev_list, 358 struct sk_buf 313 struct sk_buff *skb, 359 struct netlin 314 struct netlink_callback *cb) 360 { 315 { 361 struct smc_nl_dmp_ctx *cb_ctx = smc_nl 316 struct smc_nl_dmp_ctx *cb_ctx = smc_nl_dmp_ctx(cb); 362 int snum = cb_ctx->pos[0]; 317 int snum = cb_ctx->pos[0]; 363 struct smcd_dev *smcd; 318 struct smcd_dev *smcd; 364 int num = 0; 319 int num = 0; 365 320 366 mutex_lock(&dev_list->mutex); 321 mutex_lock(&dev_list->mutex); 367 list_for_each_entry(smcd, &dev_list->l 322 list_for_each_entry(smcd, &dev_list->list, list) { 368 if (num < snum) 323 if (num < snum) 369 goto next; 324 goto next; 370 if (smc_ism_is_loopback(smcd)) << 371 goto next; << 372 if (smc_nl_handle_smcd_dev(smc 325 if (smc_nl_handle_smcd_dev(smcd, skb, cb)) 373 goto errout; 326 goto errout; 374 next: 327 next: 375 num++; 328 num++; 376 } 329 } 377 errout: 330 errout: 378 mutex_unlock(&dev_list->mutex); 331 mutex_unlock(&dev_list->mutex); 379 cb_ctx->pos[0] = num; 332 cb_ctx->pos[0] = num; 380 } 333 } 381 334 382 int smcd_nl_get_device(struct sk_buff *skb, st 335 int smcd_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb) 383 { 336 { 384 smc_nl_prep_smcd_dev(&smcd_dev_list, s 337 smc_nl_prep_smcd_dev(&smcd_dev_list, skb, cb); 385 return skb->len; 338 return skb->len; 386 } 339 } 387 340 388 #if IS_ENABLED(CONFIG_ISM) 341 #if IS_ENABLED(CONFIG_ISM) 389 struct smc_ism_event_work { 342 struct smc_ism_event_work { 390 struct work_struct work; 343 struct work_struct work; 391 struct smcd_dev *smcd; 344 struct smcd_dev *smcd; 392 struct ism_event event; 345 struct ism_event event; 393 }; 346 }; 394 347 395 #define ISM_EVENT_REQUEST 0x0001 348 #define ISM_EVENT_REQUEST 0x0001 396 #define ISM_EVENT_RESPONSE 0x0002 349 #define ISM_EVENT_RESPONSE 0x0002 397 #define ISM_EVENT_REQUEST_IR 0x0000 350 #define ISM_EVENT_REQUEST_IR 0x00000001 398 #define ISM_EVENT_CODE_SHUTDOWN 0x80 351 #define ISM_EVENT_CODE_SHUTDOWN 0x80 399 #define ISM_EVENT_CODE_TESTLINK 0x83 352 #define ISM_EVENT_CODE_TESTLINK 0x83 400 353 401 union smcd_sw_event_info { 354 union smcd_sw_event_info { 402 u64 info; 355 u64 info; 403 struct { 356 struct { 404 u8 uid[SMC_LGR_ID 357 u8 uid[SMC_LGR_ID_SIZE]; 405 unsigned short vlan_id; 358 unsigned short vlan_id; 406 u16 code; 359 u16 code; 407 }; 360 }; 408 }; 361 }; 409 362 410 static void smcd_handle_sw_event(struct smc_is 363 static void smcd_handle_sw_event(struct smc_ism_event_work *wrk) 411 { 364 { 412 struct smcd_gid peer_gid = { .gid = wr 365 struct smcd_gid peer_gid = { .gid = wrk->event.tok, 413 .gid_ext 366 .gid_ext = 0 }; 414 union smcd_sw_event_info ev_info; 367 union smcd_sw_event_info ev_info; 415 368 416 ev_info.info = wrk->event.info; 369 ev_info.info = wrk->event.info; 417 switch (wrk->event.code) { 370 switch (wrk->event.code) { 418 case ISM_EVENT_CODE_SHUTDOWN: /* Pee 371 case ISM_EVENT_CODE_SHUTDOWN: /* Peer shut down DMBs */ 419 smc_smcd_terminate(wrk->smcd, 372 smc_smcd_terminate(wrk->smcd, &peer_gid, ev_info.vlan_id); 420 break; 373 break; 421 case ISM_EVENT_CODE_TESTLINK: /* Act 374 case ISM_EVENT_CODE_TESTLINK: /* Activity timer */ 422 if (ev_info.code == ISM_EVENT_ !! 375 if (ev_info.code == ISM_EVENT_REQUEST) { 423 wrk->smcd->ops->signal_eve << 424 ev_info.code = ISM_EVE 376 ev_info.code = ISM_EVENT_RESPONSE; 425 wrk->smcd->ops->signal 377 wrk->smcd->ops->signal_event(wrk->smcd, 426 378 &peer_gid, 427 379 ISM_EVENT_REQUEST_IR, 428 380 ISM_EVENT_CODE_TESTLINK, 429 381 ev_info.info); 430 } 382 } 431 break; 383 break; 432 } 384 } 433 } 385 } 434 386 435 /* worker for SMC-D events */ 387 /* worker for SMC-D events */ 436 static void smc_ism_event_work(struct work_str 388 static void smc_ism_event_work(struct work_struct *work) 437 { 389 { 438 struct smc_ism_event_work *wrk = 390 struct smc_ism_event_work *wrk = 439 container_of(work, struct smc_ 391 container_of(work, struct smc_ism_event_work, work); 440 struct smcd_gid smcd_gid = { .gid = wr 392 struct smcd_gid smcd_gid = { .gid = wrk->event.tok, 441 .gid_ext 393 .gid_ext = 0 }; 442 394 443 switch (wrk->event.type) { 395 switch (wrk->event.type) { 444 case ISM_EVENT_GID: /* GID event, 396 case ISM_EVENT_GID: /* GID event, token is peer GID */ 445 smc_smcd_terminate(wrk->smcd, 397 smc_smcd_terminate(wrk->smcd, &smcd_gid, VLAN_VID_MASK); 446 break; 398 break; 447 case ISM_EVENT_DMB: 399 case ISM_EVENT_DMB: 448 break; 400 break; 449 case ISM_EVENT_SWR: /* Software de 401 case ISM_EVENT_SWR: /* Software defined event */ 450 smcd_handle_sw_event(wrk); 402 smcd_handle_sw_event(wrk); 451 break; 403 break; 452 } 404 } 453 kfree(wrk); 405 kfree(wrk); 454 } 406 } 455 407 456 static struct smcd_dev *smcd_alloc_dev(struct 408 static struct smcd_dev *smcd_alloc_dev(struct device *parent, const char *name, 457 const s 409 const struct smcd_ops *ops, int max_dmbs) 458 { 410 { 459 struct smcd_dev *smcd; 411 struct smcd_dev *smcd; 460 412 461 smcd = devm_kzalloc(parent, sizeof(*sm 413 smcd = devm_kzalloc(parent, sizeof(*smcd), GFP_KERNEL); 462 if (!smcd) 414 if (!smcd) 463 return NULL; 415 return NULL; 464 smcd->conn = devm_kcalloc(parent, max_ 416 smcd->conn = devm_kcalloc(parent, max_dmbs, 465 sizeof(struc 417 sizeof(struct smc_connection *), GFP_KERNEL); 466 if (!smcd->conn) 418 if (!smcd->conn) 467 return NULL; 419 return NULL; 468 420 469 smcd->event_wq = alloc_ordered_workque 421 smcd->event_wq = alloc_ordered_workqueue("ism_evt_wq-%s)", 470 422 WQ_MEM_RECLAIM, name); 471 if (!smcd->event_wq) 423 if (!smcd->event_wq) 472 return NULL; 424 return NULL; 473 425 474 smcd->ops = ops; 426 smcd->ops = ops; 475 427 476 spin_lock_init(&smcd->lock); 428 spin_lock_init(&smcd->lock); 477 spin_lock_init(&smcd->lgr_lock); 429 spin_lock_init(&smcd->lgr_lock); 478 INIT_LIST_HEAD(&smcd->vlan); 430 INIT_LIST_HEAD(&smcd->vlan); 479 INIT_LIST_HEAD(&smcd->lgr_list); 431 INIT_LIST_HEAD(&smcd->lgr_list); 480 init_waitqueue_head(&smcd->lgrs_delete 432 init_waitqueue_head(&smcd->lgrs_deleted); 481 return smcd; 433 return smcd; 482 } 434 } 483 435 484 static void smcd_register_dev(struct ism_dev * 436 static void smcd_register_dev(struct ism_dev *ism) 485 { 437 { 486 const struct smcd_ops *ops = ism_get_s 438 const struct smcd_ops *ops = ism_get_smcd_ops(); 487 struct smcd_dev *smcd, *fentry; !! 439 struct smcd_dev *smcd; 488 440 489 if (!ops) 441 if (!ops) 490 return; 442 return; 491 443 492 smcd = smcd_alloc_dev(&ism->pdev->dev, 444 smcd = smcd_alloc_dev(&ism->pdev->dev, dev_name(&ism->pdev->dev), ops, 493 ISM_NR_DMBS); 445 ISM_NR_DMBS); 494 if (!smcd) 446 if (!smcd) 495 return; 447 return; 496 smcd->priv = ism; 448 smcd->priv = ism; 497 smcd->client = &smc_ism_client; << 498 ism_set_priv(ism, &smc_ism_client, smc 449 ism_set_priv(ism, &smc_ism_client, smcd); 499 if (smc_pnetid_by_dev_port(&ism->pdev- 450 if (smc_pnetid_by_dev_port(&ism->pdev->dev, 0, smcd->pnetid)) 500 smc_pnetid_by_table_smcd(smcd) 451 smc_pnetid_by_table_smcd(smcd); 501 452 502 if (smcd->ops->supports_v2()) << 503 smc_ism_set_v2_capable(); << 504 mutex_lock(&smcd_dev_list.mutex); 453 mutex_lock(&smcd_dev_list.mutex); 505 /* sort list: !! 454 if (list_empty(&smcd_dev_list.list)) { 506 * - devices without pnetid before dev !! 455 if (smcd->ops->supports_v2()) 507 * - loopback-ism always at the very b !! 456 smc_ism_v2_capable = true; 508 */ << 509 if (!smcd->pnetid[0]) { << 510 fentry = list_first_entry_or_n << 511 << 512 if (fentry && smc_ism_is_loopb << 513 list_add(&smcd->list, << 514 else << 515 list_add(&smcd->list, << 516 } else { << 517 list_add_tail(&smcd->list, &sm << 518 } 457 } >> 458 /* sort list: devices without pnetid before devices with pnetid */ >> 459 if (smcd->pnetid[0]) >> 460 list_add_tail(&smcd->list, &smcd_dev_list.list); >> 461 else >> 462 list_add(&smcd->list, &smcd_dev_list.list); 519 mutex_unlock(&smcd_dev_list.mutex); 463 mutex_unlock(&smcd_dev_list.mutex); 520 464 521 pr_warn_ratelimited("smc: adding smcd 465 pr_warn_ratelimited("smc: adding smcd device %s with pnetid %.16s%s\n", 522 dev_name(&ism->dev 466 dev_name(&ism->dev), smcd->pnetid, 523 smcd->pnetid_by_us 467 smcd->pnetid_by_user ? " (user defined)" : ""); 524 468 525 return; 469 return; 526 } 470 } 527 471 528 static void smcd_unregister_dev(struct ism_dev 472 static void smcd_unregister_dev(struct ism_dev *ism) 529 { 473 { 530 struct smcd_dev *smcd = ism_get_priv(i 474 struct smcd_dev *smcd = ism_get_priv(ism, &smc_ism_client); 531 475 532 pr_warn_ratelimited("smc: removing smc 476 pr_warn_ratelimited("smc: removing smcd device %s\n", 533 dev_name(&ism->dev 477 dev_name(&ism->dev)); 534 smcd->going_away = 1; 478 smcd->going_away = 1; 535 smc_smcd_terminate_all(smcd); 479 smc_smcd_terminate_all(smcd); 536 mutex_lock(&smcd_dev_list.mutex); 480 mutex_lock(&smcd_dev_list.mutex); 537 list_del_init(&smcd->list); 481 list_del_init(&smcd->list); 538 mutex_unlock(&smcd_dev_list.mutex); 482 mutex_unlock(&smcd_dev_list.mutex); 539 destroy_workqueue(smcd->event_wq); 483 destroy_workqueue(smcd->event_wq); 540 } 484 } 541 485 542 /* SMCD Device event handler. Called from ISM 486 /* SMCD Device event handler. Called from ISM device interrupt handler. 543 * Parameters are ism device pointer, 487 * Parameters are ism device pointer, 544 * - event->type (0 --> DMB, 1 --> GID), 488 * - event->type (0 --> DMB, 1 --> GID), 545 * - event->code (event code), 489 * - event->code (event code), 546 * - event->tok (either DMB token when event t 490 * - event->tok (either DMB token when event type 0, or GID when event type 1) 547 * - event->time (time of day) 491 * - event->time (time of day) 548 * - event->info (debug info). 492 * - event->info (debug info). 549 * 493 * 550 * Context: 494 * Context: 551 * - Function called in IRQ context from ISM d 495 * - Function called in IRQ context from ISM device driver event handler. 552 */ 496 */ 553 static void smcd_handle_event(struct ism_dev * 497 static void smcd_handle_event(struct ism_dev *ism, struct ism_event *event) 554 { 498 { 555 struct smcd_dev *smcd = ism_get_priv(i 499 struct smcd_dev *smcd = ism_get_priv(ism, &smc_ism_client); 556 struct smc_ism_event_work *wrk; 500 struct smc_ism_event_work *wrk; 557 501 558 if (smcd->going_away) 502 if (smcd->going_away) 559 return; 503 return; 560 /* copy event to event work queue, and 504 /* copy event to event work queue, and let it be handled there */ 561 wrk = kmalloc(sizeof(*wrk), GFP_ATOMIC 505 wrk = kmalloc(sizeof(*wrk), GFP_ATOMIC); 562 if (!wrk) 506 if (!wrk) 563 return; 507 return; 564 INIT_WORK(&wrk->work, smc_ism_event_wo 508 INIT_WORK(&wrk->work, smc_ism_event_work); 565 wrk->smcd = smcd; 509 wrk->smcd = smcd; 566 wrk->event = *event; 510 wrk->event = *event; 567 queue_work(smcd->event_wq, &wrk->work) 511 queue_work(smcd->event_wq, &wrk->work); 568 } 512 } 569 513 570 /* SMCD Device interrupt handler. Called from 514 /* SMCD Device interrupt handler. Called from ISM device interrupt handler. 571 * Parameters are the ism device pointer, DMB 515 * Parameters are the ism device pointer, DMB number, and the DMBE bitmask. 572 * Find the connection and schedule the taskle 516 * Find the connection and schedule the tasklet for this connection. 573 * 517 * 574 * Context: 518 * Context: 575 * - Function called in IRQ context from ISM d 519 * - Function called in IRQ context from ISM device driver IRQ handler. 576 */ 520 */ 577 static void smcd_handle_irq(struct ism_dev *is 521 static void smcd_handle_irq(struct ism_dev *ism, unsigned int dmbno, 578 u16 dmbemask) 522 u16 dmbemask) 579 { 523 { 580 struct smcd_dev *smcd = ism_get_priv(i 524 struct smcd_dev *smcd = ism_get_priv(ism, &smc_ism_client); 581 struct smc_connection *conn = NULL; 525 struct smc_connection *conn = NULL; 582 unsigned long flags; 526 unsigned long flags; 583 527 584 spin_lock_irqsave(&smcd->lock, flags); 528 spin_lock_irqsave(&smcd->lock, flags); 585 conn = smcd->conn[dmbno]; 529 conn = smcd->conn[dmbno]; 586 if (conn && !conn->killed) 530 if (conn && !conn->killed) 587 tasklet_schedule(&conn->rx_tsk 531 tasklet_schedule(&conn->rx_tsklet); 588 spin_unlock_irqrestore(&smcd->lock, fl 532 spin_unlock_irqrestore(&smcd->lock, flags); 589 } 533 } 590 #endif 534 #endif 591 535 592 int smc_ism_signal_shutdown(struct smc_link_gr 536 int smc_ism_signal_shutdown(struct smc_link_group *lgr) 593 { 537 { 594 int rc = 0; 538 int rc = 0; 595 #if IS_ENABLED(CONFIG_ISM) 539 #if IS_ENABLED(CONFIG_ISM) 596 union smcd_sw_event_info ev_info; 540 union smcd_sw_event_info ev_info; 597 541 598 if (lgr->peer_shutdown) 542 if (lgr->peer_shutdown) 599 return 0; << 600 if (!lgr->smcd->ops->signal_event) << 601 return 0; 543 return 0; 602 544 603 memcpy(ev_info.uid, lgr->id, SMC_LGR_I 545 memcpy(ev_info.uid, lgr->id, SMC_LGR_ID_SIZE); 604 ev_info.vlan_id = lgr->vlan_id; 546 ev_info.vlan_id = lgr->vlan_id; 605 ev_info.code = ISM_EVENT_REQUEST; 547 ev_info.code = ISM_EVENT_REQUEST; 606 rc = lgr->smcd->ops->signal_event(lgr- 548 rc = lgr->smcd->ops->signal_event(lgr->smcd, &lgr->peer_gid, 607 ISM_ 549 ISM_EVENT_REQUEST_IR, 608 ISM_ 550 ISM_EVENT_CODE_SHUTDOWN, 609 ev_i 551 ev_info.info); 610 #endif 552 #endif 611 return rc; 553 return rc; 612 } 554 } 613 555 614 int smc_ism_init(void) 556 int smc_ism_init(void) 615 { 557 { 616 int rc = 0; 558 int rc = 0; 617 559 618 smc_ism_v2_capable = false; 560 smc_ism_v2_capable = false; 619 smc_ism_create_system_eid(); 561 smc_ism_create_system_eid(); 620 562 621 #if IS_ENABLED(CONFIG_ISM) 563 #if IS_ENABLED(CONFIG_ISM) 622 rc = ism_register_client(&smc_ism_clie 564 rc = ism_register_client(&smc_ism_client); 623 #endif 565 #endif 624 return rc; 566 return rc; 625 } 567 } 626 568 627 void smc_ism_exit(void) 569 void smc_ism_exit(void) 628 { 570 { 629 #if IS_ENABLED(CONFIG_ISM) 571 #if IS_ENABLED(CONFIG_ISM) 630 ism_unregister_client(&smc_ism_client) 572 ism_unregister_client(&smc_ism_client); 631 #endif 573 #endif 632 } 574 } 633 575
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.