Skip to content

Commit 9de4df7

Browse files
Stefan Raspldavem330
authored andcommitted
net/smc: Separate SMC-D and ISM APIs
We separate the code implementing the struct smcd_ops API in the ISM device driver from the functions that may be used by other exploiters of ISM devices. Note: We start out small, and don't offer the whole breadth of the ISM device for public use, as many functions are specific to or likely only ever used in the context of SMC-D. This is the third part of a bigger overhaul of the interfaces between SMC and ISM. Signed-off-by: Stefan Raspl <[email protected]> Signed-off-by: Jan Karcher <[email protected]> Signed-off-by: Wenjia Zhang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8747716 commit 9de4df7

File tree

6 files changed

+86
-36
lines changed

6 files changed

+86
-36
lines changed

drivers/s390/net/ism_drv.c

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,9 @@ static int ism_read_local_gid(struct ism_dev *ism)
273273
return ret;
274274
}
275275

276-
static int ism_query_rgid(struct smcd_dev *smcd, u64 rgid, u32 vid_valid,
276+
static int ism_query_rgid(struct ism_dev *ism, u64 rgid, u32 vid_valid,
277277
u32 vid)
278278
{
279-
struct ism_dev *ism = smcd->priv;
280279
union ism_query_rgid cmd;
281280

282281
memset(&cmd, 0, sizeof(cmd));
@@ -290,6 +289,11 @@ static int ism_query_rgid(struct smcd_dev *smcd, u64 rgid, u32 vid_valid,
290289
return ism_cmd(ism, &cmd);
291290
}
292291

292+
static int smcd_query_rgid(struct smcd_dev *smcd, u64 rgid, u32 vid_valid, u32 vid)
293+
{
294+
return ism_query_rgid(smcd->priv, rgid, vid_valid, vid);
295+
}
296+
293297
static void ism_free_dmb(struct ism_dev *ism, struct ism_dmb *dmb)
294298
{
295299
clear_bit(dmb->sba_idx, ism->sba_bitmap);
@@ -326,9 +330,9 @@ static int ism_alloc_dmb(struct ism_dev *ism, struct ism_dmb *dmb)
326330
return dmb->cpu_addr ? 0 : -ENOMEM;
327331
}
328332

329-
static int ism_register_dmb(struct smcd_dev *smcd, struct ism_dmb *dmb)
333+
int ism_register_dmb(struct ism_dev *ism, struct ism_dmb *dmb,
334+
struct ism_client *client)
330335
{
331-
struct ism_dev *ism = smcd->priv;
332336
union ism_reg_dmb cmd;
333337
int ret;
334338

@@ -353,18 +357,19 @@ static int ism_register_dmb(struct smcd_dev *smcd, struct ism_dmb *dmb)
353357
goto out;
354358
}
355359
dmb->dmb_tok = cmd.response.dmb_tok;
360+
ism->sba_client_arr[dmb->sba_idx - ISM_DMB_BIT_OFFSET] = client->id;
356361
out:
357362
return ret;
358363
}
364+
EXPORT_SYMBOL_GPL(ism_register_dmb);
359365

360366
static int smcd_register_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb)
361367
{
362-
return ism_register_dmb(smcd, (struct ism_dmb *)dmb);
368+
return ism_register_dmb(smcd->priv, (struct ism_dmb *)dmb, NULL);
363369
}
364370

365-
static int ism_unregister_dmb(struct smcd_dev *smcd, struct ism_dmb *dmb)
371+
int ism_unregister_dmb(struct ism_dev *ism, struct ism_dmb *dmb)
366372
{
367-
struct ism_dev *ism = smcd->priv;
368373
union ism_unreg_dmb cmd;
369374
int ret;
370375

@@ -374,6 +379,8 @@ static int ism_unregister_dmb(struct smcd_dev *smcd, struct ism_dmb *dmb)
374379

375380
cmd.request.dmb_tok = dmb->dmb_tok;
376381

382+
ism->sba_client_arr[dmb->sba_idx - ISM_DMB_BIT_OFFSET] = NO_CLIENT;
383+
377384
ret = ism_cmd(ism, &cmd);
378385
if (ret && ret != ISM_ERROR)
379386
goto out;
@@ -382,15 +389,15 @@ static int ism_unregister_dmb(struct smcd_dev *smcd, struct ism_dmb *dmb)
382389
out:
383390
return ret;
384391
}
392+
EXPORT_SYMBOL_GPL(ism_unregister_dmb);
385393

386394
static int smcd_unregister_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb)
387395
{
388-
return ism_unregister_dmb(smcd, (struct ism_dmb *)dmb);
396+
return ism_unregister_dmb(smcd->priv, (struct ism_dmb *)dmb);
389397
}
390398

391-
static int ism_add_vlan_id(struct smcd_dev *smcd, u64 vlan_id)
399+
static int ism_add_vlan_id(struct ism_dev *ism, u64 vlan_id)
392400
{
393-
struct ism_dev *ism = smcd->priv;
394401
union ism_set_vlan_id cmd;
395402

396403
memset(&cmd, 0, sizeof(cmd));
@@ -402,9 +409,13 @@ static int ism_add_vlan_id(struct smcd_dev *smcd, u64 vlan_id)
402409
return ism_cmd(ism, &cmd);
403410
}
404411

405-
static int ism_del_vlan_id(struct smcd_dev *smcd, u64 vlan_id)
412+
static int smcd_add_vlan_id(struct smcd_dev *smcd, u64 vlan_id)
413+
{
414+
return ism_add_vlan_id(smcd->priv, vlan_id);
415+
}
416+
417+
static int ism_del_vlan_id(struct ism_dev *ism, u64 vlan_id)
406418
{
407-
struct ism_dev *ism = smcd->priv;
408419
union ism_set_vlan_id cmd;
409420

410421
memset(&cmd, 0, sizeof(cmd));
@@ -416,6 +427,11 @@ static int ism_del_vlan_id(struct smcd_dev *smcd, u64 vlan_id)
416427
return ism_cmd(ism, &cmd);
417428
}
418429

430+
static int smcd_del_vlan_id(struct smcd_dev *smcd, u64 vlan_id)
431+
{
432+
return ism_del_vlan_id(smcd->priv, vlan_id);
433+
}
434+
419435
static int ism_set_vlan_required(struct smcd_dev *smcd)
420436
{
421437
return ism_cmd_simple(smcd->priv, ISM_SET_VLAN);
@@ -426,8 +442,8 @@ static int ism_reset_vlan_required(struct smcd_dev *smcd)
426442
return ism_cmd_simple(smcd->priv, ISM_RESET_VLAN);
427443
}
428444

429-
static int ism_signal_ieq(struct smcd_dev *smcd, u64 rgid, u32 trigger_irq,
430-
u32 event_code, u64 info)
445+
static int smcd_signal_ieq(struct smcd_dev *smcd, u64 rgid, u32 trigger_irq,
446+
u32 event_code, u64 info)
431447
{
432448
struct ism_dev *ism = smcd->priv;
433449
union ism_sig_ieq cmd;
@@ -450,8 +466,9 @@ static unsigned int max_bytes(unsigned int start, unsigned int len,
450466
return min(boundary - (start & (boundary - 1)), len);
451467
}
452468

453-
static int ism_move(struct smcd_dev *smcd, u64 dmb_tok, unsigned int idx,
454-
bool sf, unsigned int offset, void *data, unsigned int size)
469+
static int smcd_move(struct smcd_dev *smcd, u64 dmb_tok, unsigned int idx,
470+
bool sf, unsigned int offset, void *data,
471+
unsigned int size)
455472
{
456473
struct ism_dev *ism = smcd->priv;
457474
unsigned int bytes;
@@ -495,14 +512,15 @@ static void ism_create_system_eid(void)
495512
memcpy(&SYSTEM_EID.type, tmp, 4);
496513
}
497514

498-
static u8 *ism_get_system_eid(void)
515+
u8 *ism_get_seid(void)
499516
{
500517
return SYSTEM_EID.seid_string;
501518
}
519+
EXPORT_SYMBOL_GPL(ism_get_seid);
502520

503-
static u16 ism_get_chid(struct smcd_dev *smcd)
521+
static u16 smcd_get_chid(struct smcd_dev *smcd)
504522
{
505-
struct ism_dev *ism = (struct ism_dev *)smcd->priv;
523+
struct ism_dev *ism = smcd->priv;
506524

507525
if (!ism || !ism->pdev)
508526
return 0;
@@ -565,18 +583,26 @@ static irqreturn_t ism_handle_irq(int irq, void *data)
565583
return IRQ_HANDLED;
566584
}
567585

586+
static u64 smcd_get_local_gid(struct smcd_dev *smcd)
587+
{
588+
struct ism_dev *ism = smcd->priv;
589+
590+
return ism->local_gid;
591+
}
592+
568593
static const struct smcd_ops ism_ops = {
569-
.query_remote_gid = ism_query_rgid,
594+
.query_remote_gid = smcd_query_rgid,
570595
.register_dmb = smcd_register_dmb,
571596
.unregister_dmb = smcd_unregister_dmb,
572-
.add_vlan_id = ism_add_vlan_id,
573-
.del_vlan_id = ism_del_vlan_id,
597+
.add_vlan_id = smcd_add_vlan_id,
598+
.del_vlan_id = smcd_del_vlan_id,
574599
.set_vlan_required = ism_set_vlan_required,
575600
.reset_vlan_required = ism_reset_vlan_required,
576-
.signal_event = ism_signal_ieq,
577-
.move_data = ism_move,
578-
.get_system_eid = ism_get_system_eid,
579-
.get_chid = ism_get_chid,
601+
.signal_event = smcd_signal_ieq,
602+
.move_data = smcd_move,
603+
.get_system_eid = ism_get_seid,
604+
.get_local_gid = smcd_get_local_gid,
605+
.get_chid = smcd_get_chid,
580606
};
581607

582608
static void ism_dev_add_work_func(struct work_struct *work)
@@ -599,10 +625,15 @@ static int ism_dev_init(struct ism_dev *ism)
599625
if (ret <= 0)
600626
goto out;
601627

628+
ism->sba_client_arr = kzalloc(ISM_NR_DMBS, GFP_KERNEL);
629+
if (!ism->sba_client_arr)
630+
goto free_vectors;
631+
memset(ism->sba_client_arr, NO_CLIENT, ISM_NR_DMBS);
632+
602633
ret = request_irq(pci_irq_vector(pdev, 0), ism_handle_irq, 0,
603634
pci_name(pdev), ism);
604635
if (ret)
605-
goto free_vectors;
636+
goto free_client_arr;
606637

607638
ret = register_sba(ism);
608639
if (ret)
@@ -616,7 +647,7 @@ static int ism_dev_init(struct ism_dev *ism)
616647
if (ret)
617648
goto unreg_ieq;
618649

619-
if (!ism_add_vlan_id(ism->smcd, ISM_RESERVED_VLANID))
650+
if (!ism_add_vlan_id(ism, ISM_RESERVED_VLANID))
620651
/* hardware is V2 capable */
621652
ism_create_system_eid();
622653

@@ -651,6 +682,8 @@ static int ism_dev_init(struct ism_dev *ism)
651682
unregister_sba(ism);
652683
free_irq:
653684
free_irq(pci_irq_vector(pdev, 0), ism);
685+
free_client_arr:
686+
kfree(ism->sba_client_arr);
654687
free_vectors:
655688
pci_free_irq_vectors(pdev);
656689
out:
@@ -746,10 +779,11 @@ static void ism_dev_exit(struct ism_dev *ism)
746779

747780
if (SYSTEM_EID.serial_number[0] != '0' ||
748781
SYSTEM_EID.type[0] != '0')
749-
ism_del_vlan_id(ism->smcd, ISM_RESERVED_VLANID);
782+
ism_del_vlan_id(ism, ISM_RESERVED_VLANID);
750783
unregister_ieq(ism);
751784
unregister_sba(ism);
752785
free_irq(pci_irq_vector(pdev, 0), ism);
786+
kfree(ism->sba_client_arr);
753787
pci_free_irq_vectors(pdev);
754788
list_del_init(&ism->list);
755789
}

include/linux/ism.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,11 @@ static inline void ism_set_priv(struct ism_dev *dev, struct ism_client *client,
8787
dev->priv[client->id] = priv;
8888
}
8989

90+
int ism_register_dmb(struct ism_dev *dev, struct ism_dmb *dmb,
91+
struct ism_client *client);
92+
int ism_unregister_dmb(struct ism_dev *dev, struct ism_dmb *dmb);
93+
int ism_move(struct ism_dev *dev, u64 dmb_tok, unsigned int idx, bool sf,
94+
unsigned int offset, void *data, unsigned int size);
95+
u8 *ism_get_seid(void);
96+
9097
#endif /* _ISM_H */

include/net/smc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ struct smcd_ops {
6666
bool sf, unsigned int offset, void *data,
6767
unsigned int size);
6868
u8* (*get_system_eid)(void);
69+
u64 (*get_local_gid)(struct smcd_dev *dev);
6970
u16 (*get_chid)(struct smcd_dev *dev);
7071
};
7172

7273
struct smcd_dev {
7374
const struct smcd_ops *ops;
7475
struct device dev;
76+
struct ism_dev *ism;
7577
void *priv;
76-
u64 local_gid;
7778
struct list_head list;
7879
spinlock_t lock;
7980
struct smc_connection **conn;

net/smc/smc_clc.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini)
813813
struct smc_clc_v2_extension *v2_ext;
814814
struct smc_clc_msg_smcd *pclc_smcd;
815815
struct smc_clc_msg_trail *trl;
816+
struct smcd_dev *smcd;
816817
int len, i, plen, rc;
817818
int reason_code = 0;
818819
struct kvec vec[8];
@@ -868,7 +869,9 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini)
868869
if (smcd_indicated(ini->smc_type_v1)) {
869870
/* add SMC-D specifics */
870871
if (ini->ism_dev[0]) {
871-
pclc_smcd->ism.gid = htonll(ini->ism_dev[0]->local_gid);
872+
smcd = ini->ism_dev[0];
873+
pclc_smcd->ism.gid =
874+
htonll(smcd->ops->get_local_gid(smcd));
872875
pclc_smcd->ism.chid =
873876
htons(smc_ism_get_chid(ini->ism_dev[0]));
874877
}
@@ -914,8 +917,9 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini)
914917
plen += sizeof(*smcd_v2_ext);
915918
if (ini->ism_offered_cnt) {
916919
for (i = 1; i <= ini->ism_offered_cnt; i++) {
920+
smcd = ini->ism_dev[i];
917921
gidchids[i - 1].gid =
918-
htonll(ini->ism_dev[i]->local_gid);
922+
htonll(smcd->ops->get_local_gid(smcd));
919923
gidchids[i - 1].chid =
920924
htons(smc_ism_get_chid(ini->ism_dev[i]));
921925
}
@@ -1000,7 +1004,8 @@ static int smc_clc_send_confirm_accept(struct smc_sock *smc,
10001004
memcpy(clc->hdr.eyecatcher, SMCD_EYECATCHER,
10011005
sizeof(SMCD_EYECATCHER));
10021006
clc->hdr.typev1 = SMC_TYPE_D;
1003-
clc->d0.gid = conn->lgr->smcd->local_gid;
1007+
clc->d0.gid =
1008+
conn->lgr->smcd->ops->get_local_gid(conn->lgr->smcd);
10041009
clc->d0.token = conn->rmb_desc->token;
10051010
clc->d0.dmbe_size = conn->rmbe_size_short;
10061011
clc->d0.dmbe_idx = 0;

net/smc/smc_core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ static int smc_nl_fill_smcd_lgr(struct smc_link_group *lgr,
500500
struct netlink_callback *cb)
501501
{
502502
char smc_pnet[SMC_MAX_PNETID_LEN + 1];
503+
struct smcd_dev *smcd = lgr->smcd;
503504
struct nlattr *attrs;
504505
void *nlh;
505506

@@ -515,8 +516,9 @@ static int smc_nl_fill_smcd_lgr(struct smc_link_group *lgr,
515516

516517
if (nla_put_u32(skb, SMC_NLA_LGR_D_ID, *((u32 *)&lgr->id)))
517518
goto errattr;
518-
if (nla_put_u64_64bit(skb, SMC_NLA_LGR_D_GID, lgr->smcd->local_gid,
519-
SMC_NLA_LGR_D_PAD))
519+
if (nla_put_u64_64bit(skb, SMC_NLA_LGR_D_GID,
520+
smcd->ops->get_local_gid(smcd),
521+
SMC_NLA_LGR_D_PAD))
520522
goto errattr;
521523
if (nla_put_u64_64bit(skb, SMC_NLA_LGR_D_PEER_GID, lgr->peer_gid,
522524
SMC_NLA_LGR_D_PAD))

net/smc/smc_diag.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,13 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb,
167167
!list_empty(&smc->conn.lgr->list)) {
168168
struct smc_connection *conn = &smc->conn;
169169
struct smcd_diag_dmbinfo dinfo;
170+
struct smcd_dev *smcd = conn->lgr->smcd;
170171

171172
memset(&dinfo, 0, sizeof(dinfo));
172173

173174
dinfo.linkid = *((u32 *)conn->lgr->id);
174175
dinfo.peer_gid = conn->lgr->peer_gid;
175-
dinfo.my_gid = conn->lgr->smcd->local_gid;
176+
dinfo.my_gid = smcd->ops->get_local_gid(smcd);
176177
dinfo.token = conn->rmb_desc->token;
177178
dinfo.peer_token = conn->peer_token;
178179

0 commit comments

Comments
 (0)