Skip to content

Commit 54b406e

Browse files
abhijitG-xlnxgregkh
authored andcommitted
cdx: Remove cdx controller list from cdx bus system
Remove xarray list of cdx controller. Instead, use platform bus to locate the cdx controller using compat string used by cdx controller platform driver. Also, use ida to allocate a unique id for the controller. Signed-off-by: Abhijit Gangurde <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c40e665 commit 54b406e

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

drivers/cdx/cdx.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#include <linux/of_device.h>
6161
#include <linux/slab.h>
6262
#include <linux/mm.h>
63-
#include <linux/xarray.h>
63+
#include <linux/idr.h>
6464
#include <linux/cdx/cdx_bus.h>
6565
#include <linux/iommu.h>
6666
#include <linux/dma-map-ops.h>
@@ -70,8 +70,10 @@
7070
#define CDX_DEFAULT_DMA_MASK (~0ULL)
7171
#define MAX_CDX_CONTROLLERS 16
7272

73-
/* CDX controllers registered with the CDX bus */
74-
static DEFINE_XARRAY_ALLOC(cdx_controllers);
73+
/* IDA for CDX controllers registered with the CDX bus */
74+
static DEFINE_IDA(cdx_controller_ida);
75+
76+
static char *compat_node_name = "xlnx,versal-net-cdx";
7577

7678
/**
7779
* cdx_dev_reset - Reset a CDX device
@@ -384,7 +386,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
384386
const char *buf, size_t count)
385387
{
386388
struct cdx_controller *cdx;
387-
unsigned long index;
389+
struct platform_device *pd;
390+
struct device_node *np;
388391
bool val;
389392

390393
if (kstrtobool(buf, &val) < 0)
@@ -397,12 +400,19 @@ static ssize_t rescan_store(const struct bus_type *bus,
397400
cdx_unregister_devices(&cdx_bus_type);
398401

399402
/* Rescan all the devices */
400-
xa_for_each(&cdx_controllers, index, cdx) {
401-
int ret;
403+
for_each_compatible_node(np, NULL, compat_node_name) {
404+
if (!np)
405+
return -EINVAL;
402406

403-
ret = cdx->ops->scan(cdx);
404-
if (ret)
405-
dev_err(cdx->dev, "cdx bus scanning failed\n");
407+
pd = of_find_device_by_node(np);
408+
if (!pd)
409+
return -EINVAL;
410+
411+
cdx = platform_get_drvdata(pd);
412+
if (cdx && cdx->controller_registered && cdx->ops->scan)
413+
cdx->ops->scan(cdx);
414+
415+
put_device(&pd->dev);
406416
}
407417

408418
return count;
@@ -520,17 +530,20 @@ int cdx_register_controller(struct cdx_controller *cdx)
520530
{
521531
int ret;
522532

523-
ret = xa_alloc(&cdx_controllers, &cdx->id, cdx,
524-
XA_LIMIT(0, MAX_CDX_CONTROLLERS - 1), GFP_KERNEL);
525-
if (ret) {
533+
ret = ida_alloc_range(&cdx_controller_ida, 0, MAX_CDX_CONTROLLERS - 1, GFP_KERNEL);
534+
if (ret < 0) {
526535
dev_err(cdx->dev,
527536
"No free index available. Maximum controllers already registered\n");
528537
cdx->id = (u8)MAX_CDX_CONTROLLERS;
529538
return ret;
530539
}
531540

541+
cdx->id = ret;
542+
532543
/* Scan all the devices */
533-
cdx->ops->scan(cdx);
544+
if (cdx->ops->scan)
545+
cdx->ops->scan(cdx);
546+
cdx->controller_registered = true;
534547

535548
return 0;
536549
}
@@ -541,8 +554,9 @@ void cdx_unregister_controller(struct cdx_controller *cdx)
541554
if (cdx->id >= MAX_CDX_CONTROLLERS)
542555
return;
543556

557+
cdx->controller_registered = false;
544558
device_for_each_child(cdx->dev, NULL, cdx_unregister_device);
545-
xa_erase(&cdx_controllers, cdx->id);
559+
ida_free(&cdx_controller_ida, cdx->id);
546560
}
547561
EXPORT_SYMBOL_GPL(cdx_unregister_controller);
548562

include/linux/cdx/cdx_bus.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ struct cdx_ops {
6363
* @dev: Linux device associated with the CDX controller.
6464
* @priv: private data
6565
* @id: Controller ID
66+
* @controller_registered: controller registered with bus
6667
* @ops: CDX controller ops
6768
*/
6869
struct cdx_controller {
6970
struct device *dev;
7071
void *priv;
7172
u32 id;
73+
bool controller_registered;
7274
struct cdx_ops *ops;
7375
};
7476

0 commit comments

Comments
 (0)