Skip to content

Commit 8c81ba2

Browse files
Stefan Raspldavem330
authored andcommitted
net/smc: De-tangle ism and smc device initialization
The struct device for ISM devices was part of struct smcd_dev. Move to struct ism_dev, provide a new API call in struct smcd_ops, and convert existing SMCD code accordingly. Furthermore, remove struct smcd_dev from struct ism_dev. This is the final 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 820f210 commit 8c81ba2

File tree

7 files changed

+52
-82
lines changed

7 files changed

+52
-82
lines changed

drivers/s390/net/ism_drv.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,12 @@ static int ism_probe(struct pci_dev *pdev, const struct pci_device_id *id)
646646
spin_lock_init(&ism->lock);
647647
dev_set_drvdata(&pdev->dev, ism);
648648
ism->pdev = pdev;
649+
ism->dev.parent = &pdev->dev;
650+
device_initialize(&ism->dev);
651+
dev_set_name(&ism->dev, dev_name(&pdev->dev));
652+
ret = device_add(&ism->dev);
653+
if (ret)
654+
goto err_dev;
649655

650656
ret = pci_enable_device_mem(pdev);
651657
if (ret)
@@ -663,30 +669,23 @@ static int ism_probe(struct pci_dev *pdev, const struct pci_device_id *id)
663669
dma_set_max_seg_size(&pdev->dev, SZ_1M);
664670
pci_set_master(pdev);
665671

666-
ism->smcd = smcd_alloc_dev(&pdev->dev, dev_name(&pdev->dev), &ism_ops,
667-
ISM_NR_DMBS);
668-
if (!ism->smcd) {
669-
ret = -ENOMEM;
670-
goto err_resource;
671-
}
672-
673-
ism->smcd->priv = ism;
674672
ret = ism_dev_init(ism);
675673
if (ret)
676-
goto err_free;
674+
goto err_resource;
677675

678676
return 0;
679677

680-
err_free:
681-
smcd_free_dev(ism->smcd);
682678
err_resource:
683679
pci_clear_master(pdev);
684680
pci_release_mem_regions(pdev);
685681
err_disable:
686682
pci_disable_device(pdev);
687683
err:
688-
kfree(ism);
684+
device_del(&ism->dev);
685+
err_dev:
689686
dev_set_drvdata(&pdev->dev, NULL);
687+
kfree(ism);
688+
690689
return ret;
691690
}
692691

@@ -740,7 +739,6 @@ static void ism_remove(struct pci_dev *pdev)
740739
ism_dev_exit(ism);
741740
mutex_unlock(&ism_dev_list.mutex);
742741

743-
smcd_free_dev(ism->smcd);
744742
pci_clear_master(pdev);
745743
pci_release_mem_regions(pdev);
746744
pci_disable_device(pdev);
@@ -874,6 +872,7 @@ static const struct smcd_ops ism_ops = {
874872
.get_system_eid = ism_get_seid,
875873
.get_local_gid = smcd_get_local_gid,
876874
.get_chid = smcd_get_chid,
875+
.get_dev = smcd_get_dev,
877876
};
878877

879878
const struct smcd_ops *ism_get_smcd_ops(void)

include/linux/ism.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ struct ism_dev {
3030
spinlock_t lock; /* protects the ism device */
3131
struct list_head list;
3232
struct pci_dev *pdev;
33-
struct smcd_dev *smcd;
3433

3534
struct ism_sba *sba;
3635
dma_addr_t sba_dma_addr;

include/net/smc.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ struct smcd_ops {
7070
u8* (*get_system_eid)(void);
7171
u64 (*get_local_gid)(struct smcd_dev *dev);
7272
u16 (*get_chid)(struct smcd_dev *dev);
73+
struct device* (*get_dev)(struct smcd_dev *dev);
7374
};
7475

7576
struct smcd_dev {
7677
const struct smcd_ops *ops;
77-
struct device dev;
7878
void *priv;
7979
struct list_head list;
8080
spinlock_t lock;
@@ -90,8 +90,4 @@ struct smcd_dev {
9090
u8 going_away : 1;
9191
};
9292

93-
struct smcd_dev *smcd_alloc_dev(struct device *parent, const char *name,
94-
const struct smcd_ops *ops, int max_dmbs);
95-
void smcd_free_dev(struct smcd_dev *smcd);
96-
9793
#endif /* _SMC_H */

net/smc/af_smc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3499,6 +3499,7 @@ static void __exit smc_exit(void)
34993499
sock_unregister(PF_SMC);
35003500
smc_core_exit();
35013501
smc_ib_unregister_client();
3502+
smc_ism_exit();
35023503
destroy_workqueue(smc_close_wq);
35033504
destroy_workqueue(smc_tcp_ls_wq);
35043505
destroy_workqueue(smc_hs_wq);

net/smc/smc_core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
822822
{
823823
struct smc_link_group *lgr;
824824
struct list_head *lgr_list;
825+
struct smcd_dev *smcd;
825826
struct smc_link *lnk;
826827
spinlock_t *lgr_lock;
827828
u8 link_idx;
@@ -868,7 +869,8 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
868869
lgr->conns_all = RB_ROOT;
869870
if (ini->is_smcd) {
870871
/* SMC-D specific settings */
871-
get_device(&ini->ism_dev[ini->ism_selected]->dev);
872+
smcd = ini->ism_dev[ini->ism_selected];
873+
get_device(smcd->ops->get_dev(smcd));
872874
lgr->peer_gid = ini->ism_peer_gid[ini->ism_selected];
873875
lgr->smcd = ini->ism_dev[ini->ism_selected];
874876
lgr_list = &ini->ism_dev[ini->ism_selected]->lgr_list;
@@ -1387,7 +1389,7 @@ static void smc_lgr_free(struct smc_link_group *lgr)
13871389
destroy_workqueue(lgr->tx_wq);
13881390
if (lgr->is_smcd) {
13891391
smc_ism_put_vlan(lgr->smcd, lgr->vlan_id);
1390-
put_device(&lgr->smcd->dev);
1392+
put_device(lgr->smcd->ops->get_dev(lgr->smcd));
13911393
}
13921394
smc_lgr_put(lgr); /* theoretically last lgr_put */
13931395
}

net/smc/smc_ism.c

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,11 @@ static int smc_nl_handle_smcd_dev(struct smcd_dev *smcd,
231231
struct smc_pci_dev smc_pci_dev;
232232
struct nlattr *port_attrs;
233233
struct nlattr *attrs;
234+
struct ism_dev *ism;
234235
int use_cnt = 0;
235236
void *nlh;
236237

238+
ism = smcd->priv;
237239
nlh = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
238240
&smc_gen_nl_family, NLM_F_MULTI,
239241
SMC_NETLINK_GET_DEV_SMCD);
@@ -248,7 +250,7 @@ static int smc_nl_handle_smcd_dev(struct smcd_dev *smcd,
248250
if (nla_put_u8(skb, SMC_NLA_DEV_IS_CRIT, use_cnt > 0))
249251
goto errattr;
250252
memset(&smc_pci_dev, 0, sizeof(smc_pci_dev));
251-
smc_set_pci_values(to_pci_dev(smcd->dev.parent), &smc_pci_dev);
253+
smc_set_pci_values(to_pci_dev(ism->dev.parent), &smc_pci_dev);
252254
if (nla_put_u32(skb, SMC_NLA_DEV_PCI_FID, smc_pci_dev.pci_fid))
253255
goto errattr;
254256
if (nla_put_u16(skb, SMC_NLA_DEV_PCI_CHID, smc_pci_dev.pci_pchid))
@@ -377,41 +379,24 @@ static void smc_ism_event_work(struct work_struct *work)
377379
kfree(wrk);
378380
}
379381

380-
static void smcd_release(struct device *dev)
381-
{
382-
struct smcd_dev *smcd = container_of(dev, struct smcd_dev, dev);
383-
384-
kfree(smcd->conn);
385-
kfree(smcd);
386-
}
387-
388-
struct smcd_dev *smcd_alloc_dev(struct device *parent, const char *name,
389-
const struct smcd_ops *ops, int max_dmbs)
382+
static struct smcd_dev *smcd_alloc_dev(struct device *parent, const char *name,
383+
const struct smcd_ops *ops, int max_dmbs)
390384
{
391385
struct smcd_dev *smcd;
392386

393-
smcd = kzalloc(sizeof(*smcd), GFP_KERNEL);
387+
smcd = devm_kzalloc(parent, sizeof(*smcd), GFP_KERNEL);
394388
if (!smcd)
395389
return NULL;
396-
smcd->conn = kcalloc(max_dmbs, sizeof(struct smc_connection *),
397-
GFP_KERNEL);
398-
if (!smcd->conn) {
399-
kfree(smcd);
390+
smcd->conn = devm_kcalloc(parent, max_dmbs,
391+
sizeof(struct smc_connection *), GFP_KERNEL);
392+
if (!smcd->conn)
400393
return NULL;
401-
}
402394

403395
smcd->event_wq = alloc_ordered_workqueue("ism_evt_wq-%s)",
404396
WQ_MEM_RECLAIM, name);
405-
if (!smcd->event_wq) {
406-
kfree(smcd->conn);
407-
kfree(smcd);
397+
if (!smcd->event_wq)
408398
return NULL;
409-
}
410399

411-
smcd->dev.parent = parent;
412-
smcd->dev.release = smcd_release;
413-
device_initialize(&smcd->dev);
414-
dev_set_name(&smcd->dev, name);
415400
smcd->ops = ops;
416401

417402
spin_lock_init(&smcd->lock);
@@ -421,13 +406,6 @@ struct smcd_dev *smcd_alloc_dev(struct device *parent, const char *name,
421406
init_waitqueue_head(&smcd->lgrs_deleted);
422407
return smcd;
423408
}
424-
EXPORT_SYMBOL_GPL(smcd_alloc_dev);
425-
426-
void smcd_free_dev(struct smcd_dev *smcd)
427-
{
428-
put_device(&smcd->dev);
429-
}
430-
EXPORT_SYMBOL_GPL(smcd_free_dev);
431409

432410
static void smcd_register_dev(struct ism_dev *ism)
433411
{
@@ -465,16 +443,9 @@ static void smcd_register_dev(struct ism_dev *ism)
465443
mutex_unlock(&smcd_dev_list.mutex);
466444

467445
pr_warn_ratelimited("smc: adding smcd device %s with pnetid %.16s%s\n",
468-
dev_name(&smcd->dev), smcd->pnetid,
446+
dev_name(&ism->dev), smcd->pnetid,
469447
smcd->pnetid_by_user ? " (user defined)" : "");
470448

471-
if (device_add(&smcd->dev)) {
472-
mutex_lock(&smcd_dev_list.mutex);
473-
list_del(&smcd->list);
474-
mutex_unlock(&smcd_dev_list.mutex);
475-
smcd_free_dev(smcd);
476-
}
477-
478449
return;
479450
}
480451

@@ -483,15 +454,13 @@ static void smcd_unregister_dev(struct ism_dev *ism)
483454
struct smcd_dev *smcd = ism_get_priv(ism, &smc_ism_client);
484455

485456
pr_warn_ratelimited("smc: removing smcd device %s\n",
486-
dev_name(&smcd->dev));
457+
dev_name(&ism->dev));
487458
smcd->going_away = 1;
488459
smc_smcd_terminate_all(smcd);
489460
mutex_lock(&smcd_dev_list.mutex);
490461
list_del_init(&smcd->list);
491462
mutex_unlock(&smcd_dev_list.mutex);
492463
destroy_workqueue(smcd->event_wq);
493-
494-
device_del(&smcd->dev);
495464
}
496465

497466
/* SMCD Device event handler. Called from ISM device interrupt handler.

net/smc/smc_pnet.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static int smc_pnet_remove_by_pnetid(struct net *net, char *pnet_name)
103103
struct smc_pnetentry *pnetelem, *tmp_pe;
104104
struct smc_pnettable *pnettable;
105105
struct smc_ib_device *ibdev;
106-
struct smcd_dev *smcd_dev;
106+
struct smcd_dev *smcd;
107107
struct smc_net *sn;
108108
int rc = -ENOENT;
109109
int ibport;
@@ -162,16 +162,17 @@ static int smc_pnet_remove_by_pnetid(struct net *net, char *pnet_name)
162162
mutex_unlock(&smc_ib_devices.mutex);
163163
/* remove smcd devices */
164164
mutex_lock(&smcd_dev_list.mutex);
165-
list_for_each_entry(smcd_dev, &smcd_dev_list.list, list) {
166-
if (smcd_dev->pnetid_by_user &&
165+
list_for_each_entry(smcd, &smcd_dev_list.list, list) {
166+
if (smcd->pnetid_by_user &&
167167
(!pnet_name ||
168-
smc_pnet_match(pnet_name, smcd_dev->pnetid))) {
168+
smc_pnet_match(pnet_name, smcd->pnetid))) {
169169
pr_warn_ratelimited("smc: smcd device %s "
170170
"erased user defined pnetid "
171-
"%.16s\n", dev_name(&smcd_dev->dev),
172-
smcd_dev->pnetid);
173-
memset(smcd_dev->pnetid, 0, SMC_MAX_PNETID_LEN);
174-
smcd_dev->pnetid_by_user = false;
171+
"%.16s\n",
172+
dev_name(smcd->ops->get_dev(smcd)),
173+
smcd->pnetid);
174+
memset(smcd->pnetid, 0, SMC_MAX_PNETID_LEN);
175+
smcd->pnetid_by_user = false;
175176
rc = 0;
176177
}
177178
}
@@ -331,8 +332,8 @@ static struct smcd_dev *smc_pnet_find_smcd(char *smcd_name)
331332

332333
mutex_lock(&smcd_dev_list.mutex);
333334
list_for_each_entry(smcd_dev, &smcd_dev_list.list, list) {
334-
if (!strncmp(dev_name(&smcd_dev->dev), smcd_name,
335-
IB_DEVICE_NAME_MAX - 1))
335+
if (!strncmp(dev_name(smcd_dev->ops->get_dev(smcd_dev)),
336+
smcd_name, IB_DEVICE_NAME_MAX - 1))
336337
goto out;
337338
}
338339
smcd_dev = NULL;
@@ -411,7 +412,8 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
411412
struct smc_ib_device *ib_dev;
412413
bool smcddev_applied = true;
413414
bool ibdev_applied = true;
414-
struct smcd_dev *smcd_dev;
415+
struct smcd_dev *smcd;
416+
struct device *dev;
415417
bool new_ibdev;
416418

417419
/* try to apply the pnetid to active devices */
@@ -425,14 +427,16 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
425427
ib_port,
426428
ib_dev->pnetid[ib_port - 1]);
427429
}
428-
smcd_dev = smc_pnet_find_smcd(ib_name);
429-
if (smcd_dev) {
430-
smcddev_applied = smc_pnet_apply_smcd(smcd_dev, pnet_name);
431-
if (smcddev_applied)
430+
smcd = smc_pnet_find_smcd(ib_name);
431+
if (smcd) {
432+
smcddev_applied = smc_pnet_apply_smcd(smcd, pnet_name);
433+
if (smcddev_applied) {
434+
dev = smcd->ops->get_dev(smcd);
432435
pr_warn_ratelimited("smc: smcd device %s "
433436
"applied user defined pnetid "
434-
"%.16s\n", dev_name(&smcd_dev->dev),
435-
smcd_dev->pnetid);
437+
"%.16s\n", dev_name(dev),
438+
smcd->pnetid);
439+
}
436440
}
437441
/* Apply fails when a device has a hardware-defined pnetid set, do not
438442
* add a pnet table entry in that case.
@@ -1181,7 +1185,7 @@ int smc_pnetid_by_table_ib(struct smc_ib_device *smcibdev, u8 ib_port)
11811185
*/
11821186
int smc_pnetid_by_table_smcd(struct smcd_dev *smcddev)
11831187
{
1184-
const char *ib_name = dev_name(&smcddev->dev);
1188+
const char *ib_name = dev_name(smcddev->ops->get_dev(smcddev));
11851189
struct smc_pnettable *pnettable;
11861190
struct smc_pnetentry *tmp_pe;
11871191
struct smc_net *sn;

0 commit comments

Comments
 (0)