linux/drivers/dibs/dibs_loopback.c
Alexandra Winter 05e68d8ded dibs: Local gid for dibs devices
Define a uuid_t GID attribute to identify a dibs device.

SMC uses 64 Bit and 128 Bit Global Identifiers (GIDs) per device, that
need to be sent via the SMC protocol. Because the smc code uses integers,
network endianness and host endianness need to be considered. Avoid this
in the dibs layer by using uuid_t byte arrays. Future patches could change
SMC to use uuid_t. For now conversion helper functions are introduced.

ISM devices provide 64 Bit GIDs. Map them to dibs uuid_t GIDs like this:
 _________________________________________
| 64 Bit ISM-vPCI GID | 00000000_00000000 |
 -----------------------------------------
If interpreted as UUID [1], this would be interpreted as the UIID variant,
that is reserved for NCS backward compatibility. So it will not collide
with UUIDs that were generated according to the standard.

smc_loopback already uses version 4 UUIDs as 128 Bit GIDs, move that to
dibs loopback. A temporary change to smc_lo_query_rgid() is required,
that will be moved to dibs_loopback with a follow-on patch.

Provide gid of a dibs device as sysfs read-only attribute.

Link: https://datatracker.ietf.org/doc/html/rfc4122 [1]
Signed-off-by: Alexandra Winter <wintera@linux.ibm.com>
Reviewed-by: Julian Ruess <julianr@linux.ibm.com>
Reviewed-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
Link: https://patch.msgid.link/20250918110500.1731261-11-wintera@linux.ibm.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2025-09-23 11:13:22 +02:00

89 lines
1.5 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Functions for dibs loopback/loopback-ism device.
*
* Copyright (c) 2024, Alibaba Inc.
*
* Author: Wen Gu <guwen@linux.alibaba.com>
* Tony Lu <tonylu@linux.alibaba.com>
*
*/
#include <linux/dibs.h>
#include <linux/slab.h>
#include <linux/types.h>
#include "dibs_loopback.h"
static const char dibs_lo_dev_name[] = "lo";
/* global loopback device */
static struct dibs_lo_dev *lo_dev;
static u16 dibs_lo_get_fabric_id(struct dibs_dev *dibs)
{
return DIBS_LOOPBACK_FABRIC;
}
static const struct dibs_dev_ops dibs_lo_ops = {
.get_fabric_id = dibs_lo_get_fabric_id,
};
static int dibs_lo_dev_probe(void)
{
struct dibs_lo_dev *ldev;
struct dibs_dev *dibs;
int ret;
ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
if (!ldev)
return -ENOMEM;
dibs = dibs_dev_alloc();
if (!dibs) {
kfree(ldev);
return -ENOMEM;
}
ldev->dibs = dibs;
dibs->drv_priv = ldev;
uuid_gen(&dibs->gid);
dibs->ops = &dibs_lo_ops;
dibs->dev.parent = NULL;
dev_set_name(&dibs->dev, "%s", dibs_lo_dev_name);
ret = dibs_dev_add(dibs);
if (ret)
goto err_reg;
lo_dev = ldev;
return 0;
err_reg:
/* pairs with dibs_dev_alloc() */
put_device(&dibs->dev);
kfree(ldev);
return ret;
}
static void dibs_lo_dev_remove(void)
{
if (!lo_dev)
return;
dibs_dev_del(lo_dev->dibs);
/* pairs with dibs_dev_alloc() */
put_device(&lo_dev->dibs->dev);
kfree(lo_dev);
lo_dev = NULL;
}
int dibs_loopback_init(void)
{
return dibs_lo_dev_probe();
}
void dibs_loopback_exit(void)
{
dibs_lo_dev_remove();
}