Skip to content

Commit 0479134

Browse files
Wen GuPaolo Abeni
authored andcommitted
net/smc: register loopback-ism into SMC-D device list
After the loopback-ism device is ready, add it to the SMC-D device list as an ISMv2 device, and always keep it at the beginning to ensure it is preferred for providing a shortcut for data transfer within the same kernel. Signed-off-by: Wen Gu <guwen@linux.alibaba.com> Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com> Reviewed-and-tested-by: Jan Karcher <jaka@linux.ibm.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent c8df2d4 commit 0479134

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

net/smc/smc_ism.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ bool smc_ism_is_v2_capable(void)
9191
return smc_ism_v2_capable;
9292
}
9393

94+
void smc_ism_set_v2_capable(void)
95+
{
96+
smc_ism_v2_capable = true;
97+
}
98+
9499
/* Set a connection using this DMBE. */
95100
void smc_ism_set_conn(struct smc_connection *conn)
96101
{
@@ -439,7 +444,7 @@ static struct smcd_dev *smcd_alloc_dev(struct device *parent, const char *name,
439444
static void smcd_register_dev(struct ism_dev *ism)
440445
{
441446
const struct smcd_ops *ops = ism_get_smcd_ops();
442-
struct smcd_dev *smcd;
447+
struct smcd_dev *smcd, *fentry;
443448

444449
if (!ops)
445450
return;
@@ -454,16 +459,23 @@ static void smcd_register_dev(struct ism_dev *ism)
454459
if (smc_pnetid_by_dev_port(&ism->pdev->dev, 0, smcd->pnetid))
455460
smc_pnetid_by_table_smcd(smcd);
456461

462+
if (smcd->ops->supports_v2())
463+
smc_ism_set_v2_capable();
457464
mutex_lock(&smcd_dev_list.mutex);
458-
if (list_empty(&smcd_dev_list.list)) {
459-
if (smcd->ops->supports_v2())
460-
smc_ism_v2_capable = true;
461-
}
462-
/* sort list: devices without pnetid before devices with pnetid */
463-
if (smcd->pnetid[0])
465+
/* sort list:
466+
* - devices without pnetid before devices with pnetid;
467+
* - loopback-ism always at the very beginning;
468+
*/
469+
if (!smcd->pnetid[0]) {
470+
fentry = list_first_entry_or_null(&smcd_dev_list.list,
471+
struct smcd_dev, list);
472+
if (fentry && smc_ism_is_loopback(fentry))
473+
list_add(&smcd->list, &fentry->list);
474+
else
475+
list_add(&smcd->list, &smcd_dev_list.list);
476+
} else {
464477
list_add_tail(&smcd->list, &smcd_dev_list.list);
465-
else
466-
list_add(&smcd->list, &smcd_dev_list.list);
478+
}
467479
mutex_unlock(&smcd_dev_list.mutex);
468480

469481
pr_warn_ratelimited("smc: adding smcd device %s with pnetid %.16s%s\n",

net/smc/smc_ism.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ int smc_ism_signal_shutdown(struct smc_link_group *lgr);
5252
void smc_ism_get_system_eid(u8 **eid);
5353
u16 smc_ism_get_chid(struct smcd_dev *dev);
5454
bool smc_ism_is_v2_capable(void);
55+
void smc_ism_set_v2_capable(void);
5556
int smc_ism_init(void);
5657
void smc_ism_exit(void);
5758
int smcd_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb);

net/smc/smc_loopback.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,20 +246,26 @@ static int smcd_lo_register_dev(struct smc_lo_dev *ldev)
246246
return -ENOMEM;
247247
ldev->smcd = smcd;
248248
smcd->priv = ldev;
249-
250-
/* TODO:
251-
* register loopback-ism to smcd_dev list.
252-
*/
249+
smc_ism_set_v2_capable();
250+
mutex_lock(&smcd_dev_list.mutex);
251+
list_add(&smcd->list, &smcd_dev_list.list);
252+
mutex_unlock(&smcd_dev_list.mutex);
253+
pr_warn_ratelimited("smc: adding smcd device %s\n",
254+
dev_name(&ldev->dev));
253255
return 0;
254256
}
255257

256258
static void smcd_lo_unregister_dev(struct smc_lo_dev *ldev)
257259
{
258260
struct smcd_dev *smcd = ldev->smcd;
259261

260-
/* TODO:
261-
* unregister loopback-ism from smcd_dev list.
262-
*/
262+
pr_warn_ratelimited("smc: removing smcd device %s\n",
263+
dev_name(&ldev->dev));
264+
smcd->going_away = 1;
265+
smc_smcd_terminate_all(smcd);
266+
mutex_lock(&smcd_dev_list.mutex);
267+
list_del_init(&smcd->list);
268+
mutex_unlock(&smcd_dev_list.mutex);
263269
kfree(smcd->conn);
264270
kfree(smcd);
265271
}

0 commit comments

Comments
 (0)