Commit 845c334a authored by Julian Ruess's avatar Julian Ruess Committed by Paolo Abeni
Browse files

dibs: Move struct device to dibs_dev



Move struct device from ism_dev and smc_lo_dev to dibs_dev, and define a
corresponding release function. Free ism_dev in ism_remove() and smc_lo_dev
in smc_lo_dev_remove().

Replace smcd->ops->get_dev(smcd) by using dibs->dev directly.

An alternative design would be to embed dibs_dev as a field in ism_dev and
do the same for other dibs device driver specific structs. However that
would have the disadvantage that each dibs device driver needs to allocate
dibs_dev and each dibs device driver needs a different device release
function. The advantage would be that ism_dev and other device driver
specific structs would be covered by device reference counts.

Signed-off-by: default avatarJulian Ruess <julianr@linux.ibm.com>
Co-developed-by: default avatarAlexandra Winter <wintera@linux.ibm.com>
Signed-off-by: default avatarAlexandra Winter <wintera@linux.ibm.com>
Reviewed-by: default avatarMahanta Jambigi <mjambigi@linux.ibm.com>
Link: https://patch.msgid.link/20250918110500.1731261-9-wintera@linux.ibm.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 69baaac9
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@

#include "dibs_loopback.h"

static const char dibs_lo_dev_name[] = "lo";
/* global loopback device */
static struct dibs_lo_dev *lo_dev;

@@ -27,11 +28,6 @@ static const struct dibs_dev_ops dibs_lo_ops = {
	.get_fabric_id = dibs_lo_get_fabric_id,
};

static void dibs_lo_dev_exit(struct dibs_lo_dev *ldev)
{
	dibs_dev_del(ldev->dibs);
}

static int dibs_lo_dev_probe(void)
{
	struct dibs_lo_dev *ldev;
@@ -52,6 +48,9 @@ static int dibs_lo_dev_probe(void)
	dibs->drv_priv = ldev;
	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;
@@ -60,7 +59,7 @@ static int dibs_lo_dev_probe(void)

err_reg:
	/* pairs with dibs_dev_alloc() */
	kfree(dibs);
	put_device(&dibs->dev);
	kfree(ldev);

	return ret;
@@ -71,9 +70,9 @@ static void dibs_lo_dev_remove(void)
	if (!lo_dev)
		return;

	dibs_lo_dev_exit(lo_dev);
	dibs_dev_del(lo_dev->dibs);
	/* pairs with dibs_dev_alloc() */
	kfree(lo_dev->dibs);
	put_device(&lo_dev->dibs->dev);
	kfree(lo_dev);
	lo_dev = NULL;
}
+20 −1
Original line number Diff line number Diff line
@@ -88,11 +88,24 @@ int dibs_unregister_client(struct dibs_client *client)
}
EXPORT_SYMBOL_GPL(dibs_unregister_client);

static void dibs_dev_release(struct device *dev)
{
	struct dibs_dev *dibs;

	dibs = container_of(dev, struct dibs_dev, dev);

	kfree(dibs);
}

struct dibs_dev *dibs_dev_alloc(void)
{
	struct dibs_dev *dibs;

	dibs = kzalloc(sizeof(*dibs), GFP_KERNEL);
	if (!dibs)
		return dibs;
	dibs->dev.release = dibs_dev_release;
	device_initialize(&dibs->dev);

	return dibs;
}
@@ -100,7 +113,11 @@ EXPORT_SYMBOL_GPL(dibs_dev_alloc);

int dibs_dev_add(struct dibs_dev *dibs)
{
	int i;
	int i, ret;

	ret = device_add(&dibs->dev);
	if (ret)
		return ret;

	mutex_lock(&dibs_dev_list.mutex);
	mutex_lock(&clients_lock);
@@ -129,6 +146,8 @@ void dibs_dev_del(struct dibs_dev *dibs)
	mutex_unlock(&clients_lock);
	list_del_init(&dibs->list);
	mutex_unlock(&dibs_dev_list.mutex);

	device_del(&dibs->dev);
}
EXPORT_SYMBOL_GPL(dibs_dev_del);

+8 −32
Original line number Diff line number Diff line
@@ -602,15 +602,6 @@ static int ism_dev_init(struct ism_dev *ism)
	return ret;
}

static void ism_dev_release(struct device *dev)
{
	struct ism_dev *ism;

	ism = container_of(dev, struct ism_dev, dev);

	kfree(ism);
}

static void ism_dev_exit(struct ism_dev *ism)
{
	struct pci_dev *pdev = ism->pdev;
@@ -649,17 +640,10 @@ static int ism_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	spin_lock_init(&ism->cmd_lock);
	dev_set_drvdata(&pdev->dev, ism);
	ism->pdev = pdev;
	ism->dev.parent = &pdev->dev;
	ism->dev.release = ism_dev_release;
	device_initialize(&ism->dev);
	dev_set_name(&ism->dev, "%s", dev_name(&pdev->dev));
	ret = device_add(&ism->dev);
	if (ret)
		goto err_dev;

	ret = pci_enable_device_mem(pdev);
	if (ret)
		goto err;
		goto err_dev;

	ret = pci_request_mem_regions(pdev, DRV_NAME);
	if (ret)
@@ -687,6 +671,9 @@ static int ism_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	if (ret)
		goto err_dibs;

	dibs->dev.parent = &pdev->dev;
	dev_set_name(&dibs->dev, "%s", dev_name(&pdev->dev));

	ret = dibs_dev_add(dibs);
	if (ret)
		goto err_ism;
@@ -697,16 +684,14 @@ static int ism_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	ism_dev_exit(ism);
err_dibs:
	/* pairs with dibs_dev_alloc() */
	kfree(dibs);
	put_device(&dibs->dev);
err_resource:
	pci_release_mem_regions(pdev);
err_disable:
	pci_disable_device(pdev);
err:
	device_del(&ism->dev);
err_dev:
	dev_set_drvdata(&pdev->dev, NULL);
	put_device(&ism->dev);
	kfree(ism);

	return ret;
}
@@ -719,13 +704,12 @@ static void ism_remove(struct pci_dev *pdev)
	dibs_dev_del(dibs);
	ism_dev_exit(ism);
	/* pairs with dibs_dev_alloc() */
	kfree(dibs);
	put_device(&dibs->dev);

	pci_release_mem_regions(pdev);
	pci_disable_device(pdev);
	device_del(&ism->dev);
	dev_set_drvdata(&pdev->dev, NULL);
	put_device(&ism->dev);
	kfree(ism);
}

static struct pci_driver ism_driver = {
@@ -866,13 +850,6 @@ static void smcd_get_local_gid(struct smcd_dev *smcd,
	smcd_gid->gid_ext = 0;
}

static inline struct device *smcd_get_dev(struct smcd_dev *dev)
{
	struct ism_dev *ism = dev->priv;

	return &ism->dev;
}

static const struct smcd_ops ism_smcd_ops = {
	.query_remote_gid = smcd_query_rgid,
	.register_dmb = smcd_register_dmb,
@@ -885,7 +862,6 @@ static const struct smcd_ops ism_smcd_ops = {
	.move_data = smcd_move,
	.supports_v2 = smcd_supports_v2,
	.get_local_gid = smcd_get_local_gid,
	.get_dev = smcd_get_dev,
};

const struct smcd_ops *ism_get_smcd_ops(void)
+1 −0
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ struct dibs_dev_ops {

struct dibs_dev {
	struct list_head list;
	struct device dev;
	/* To be filled by device driver, before calling dibs_dev_add(): */
	const struct dibs_dev_ops *ops;
	/* priv pointer for device driver */
+0 −1
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ struct ism_dev {
	struct ism_eq *ieq;
	dma_addr_t ieq_dma_addr;

	struct device dev;
	u64 local_gid;
	int ieq_idx;

Loading