Commit 700af3a0 authored by Dave Jiang's avatar Dave Jiang Committed by Vinod Koul

dmaengine: idxd: add 'struct idxd_dev' as wrapper for conf_dev

Add a 'struct idxd_dev' that wraps the 'struct device' for idxd conf_dev
that registers with the dsa bus. This is introduced in order to deal with
multiple different types of 'devices' that are registered on the dsa_bus
when the compat driver needs to route them to the correct driver to attach.
The bind() call now can determine the type of device and then do the
appropriate driver matching.

Reviewed-by Dan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/162637460065.744545.584492831446090984.stgit@djiang5-desk3.ch.intel.comSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent da5a11d7
...@@ -41,7 +41,7 @@ struct idxd_user_context { ...@@ -41,7 +41,7 @@ struct idxd_user_context {
static void idxd_cdev_dev_release(struct device *dev) static void idxd_cdev_dev_release(struct device *dev)
{ {
struct idxd_cdev *idxd_cdev = container_of(dev, struct idxd_cdev, dev); struct idxd_cdev *idxd_cdev = dev_to_cdev(dev);
struct idxd_cdev_context *cdev_ctx; struct idxd_cdev_context *cdev_ctx;
struct idxd_wq *wq = idxd_cdev->wq; struct idxd_wq *wq = idxd_cdev->wq;
...@@ -256,9 +256,10 @@ int idxd_wq_add_cdev(struct idxd_wq *wq) ...@@ -256,9 +256,10 @@ int idxd_wq_add_cdev(struct idxd_wq *wq)
if (!idxd_cdev) if (!idxd_cdev)
return -ENOMEM; return -ENOMEM;
idxd_cdev->idxd_dev.type = IDXD_DEV_CDEV;
idxd_cdev->wq = wq; idxd_cdev->wq = wq;
cdev = &idxd_cdev->cdev; cdev = &idxd_cdev->cdev;
dev = &idxd_cdev->dev; dev = cdev_dev(idxd_cdev);
cdev_ctx = &ictx[wq->idxd->data->type]; cdev_ctx = &ictx[wq->idxd->data->type];
minor = ida_simple_get(&cdev_ctx->minor_ida, 0, MINORMASK, GFP_KERNEL); minor = ida_simple_get(&cdev_ctx->minor_ida, 0, MINORMASK, GFP_KERNEL);
if (minor < 0) { if (minor < 0) {
...@@ -268,7 +269,7 @@ int idxd_wq_add_cdev(struct idxd_wq *wq) ...@@ -268,7 +269,7 @@ int idxd_wq_add_cdev(struct idxd_wq *wq)
idxd_cdev->minor = minor; idxd_cdev->minor = minor;
device_initialize(dev); device_initialize(dev);
dev->parent = &wq->conf_dev; dev->parent = wq_confdev(wq);
dev->bus = &dsa_bus_type; dev->bus = &dsa_bus_type;
dev->type = &idxd_cdev_device_type; dev->type = &idxd_cdev_device_type;
dev->devt = MKDEV(MAJOR(cdev_ctx->devt), minor); dev->devt = MKDEV(MAJOR(cdev_ctx->devt), minor);
...@@ -299,8 +300,8 @@ void idxd_wq_del_cdev(struct idxd_wq *wq) ...@@ -299,8 +300,8 @@ void idxd_wq_del_cdev(struct idxd_wq *wq)
idxd_cdev = wq->idxd_cdev; idxd_cdev = wq->idxd_cdev;
wq->idxd_cdev = NULL; wq->idxd_cdev = NULL;
cdev_device_del(&idxd_cdev->cdev, &idxd_cdev->dev); cdev_device_del(&idxd_cdev->cdev, cdev_dev(idxd_cdev));
put_device(&idxd_cdev->dev); put_device(cdev_dev(idxd_cdev));
} }
int idxd_cdev_register(void) int idxd_cdev_register(void)
......
...@@ -245,7 +245,7 @@ int idxd_register_dma_channel(struct idxd_wq *wq) ...@@ -245,7 +245,7 @@ int idxd_register_dma_channel(struct idxd_wq *wq)
wq->idxd_chan = idxd_chan; wq->idxd_chan = idxd_chan;
idxd_chan->wq = wq; idxd_chan->wq = wq;
get_device(&wq->conf_dev); get_device(wq_confdev(wq));
return 0; return 0;
} }
...@@ -260,5 +260,5 @@ void idxd_unregister_dma_channel(struct idxd_wq *wq) ...@@ -260,5 +260,5 @@ void idxd_unregister_dma_channel(struct idxd_wq *wq)
list_del(&chan->device_node); list_del(&chan->device_node);
kfree(wq->idxd_chan); kfree(wq->idxd_chan);
wq->idxd_chan = NULL; wq->idxd_chan = NULL;
put_device(&wq->conf_dev); put_device(wq_confdev(wq));
} }
...@@ -17,8 +17,24 @@ ...@@ -17,8 +17,24 @@
extern struct kmem_cache *idxd_desc_pool; extern struct kmem_cache *idxd_desc_pool;
struct idxd_device;
struct idxd_wq; struct idxd_wq;
struct idxd_dev;
enum idxd_dev_type {
IDXD_DEV_NONE = -1,
IDXD_DEV_DSA = 0,
IDXD_DEV_IAX,
IDXD_DEV_WQ,
IDXD_DEV_GROUP,
IDXD_DEV_ENGINE,
IDXD_DEV_CDEV,
IDXD_DEV_MAX_TYPE,
};
struct idxd_dev {
struct device conf_dev;
enum idxd_dev_type type;
};
#define IDXD_REG_TIMEOUT 50 #define IDXD_REG_TIMEOUT 50
#define IDXD_DRAIN_TIMEOUT 5000 #define IDXD_DRAIN_TIMEOUT 5000
...@@ -52,7 +68,7 @@ struct idxd_irq_entry { ...@@ -52,7 +68,7 @@ struct idxd_irq_entry {
}; };
struct idxd_group { struct idxd_group {
struct device conf_dev; struct idxd_dev idxd_dev;
struct idxd_device *idxd; struct idxd_device *idxd;
struct grpcfg grpcfg; struct grpcfg grpcfg;
int id; int id;
...@@ -111,7 +127,7 @@ enum idxd_wq_type { ...@@ -111,7 +127,7 @@ enum idxd_wq_type {
struct idxd_cdev { struct idxd_cdev {
struct idxd_wq *wq; struct idxd_wq *wq;
struct cdev cdev; struct cdev cdev;
struct device dev; struct idxd_dev idxd_dev;
int minor; int minor;
}; };
...@@ -139,7 +155,7 @@ struct idxd_wq { ...@@ -139,7 +155,7 @@ struct idxd_wq {
void __iomem *portal; void __iomem *portal;
struct percpu_ref wq_active; struct percpu_ref wq_active;
struct completion wq_dead; struct completion wq_dead;
struct device conf_dev; struct idxd_dev idxd_dev;
struct idxd_cdev *idxd_cdev; struct idxd_cdev *idxd_cdev;
struct wait_queue_head err_queue; struct wait_queue_head err_queue;
struct idxd_device *idxd; struct idxd_device *idxd;
...@@ -174,7 +190,7 @@ struct idxd_wq { ...@@ -174,7 +190,7 @@ struct idxd_wq {
}; };
struct idxd_engine { struct idxd_engine {
struct device conf_dev; struct idxd_dev idxd_dev;
int id; int id;
struct idxd_group *group; struct idxd_group *group;
struct idxd_device *idxd; struct idxd_device *idxd;
...@@ -218,7 +234,7 @@ struct idxd_driver_data { ...@@ -218,7 +234,7 @@ struct idxd_driver_data {
}; };
struct idxd_device { struct idxd_device {
struct device conf_dev; struct idxd_dev idxd_dev;
struct idxd_driver_data *data; struct idxd_driver_data *data;
struct list_head list; struct list_head list;
struct idxd_hw hw; struct idxd_hw hw;
...@@ -301,8 +317,58 @@ enum idxd_completion_status { ...@@ -301,8 +317,58 @@ enum idxd_completion_status {
IDXD_COMP_DESC_ABORT = 0xff, IDXD_COMP_DESC_ABORT = 0xff,
}; };
#define confdev_to_idxd(dev) container_of(dev, struct idxd_device, conf_dev) #define idxd_confdev(idxd) &idxd->idxd_dev.conf_dev
#define confdev_to_wq(dev) container_of(dev, struct idxd_wq, conf_dev) #define wq_confdev(wq) &wq->idxd_dev.conf_dev
#define engine_confdev(engine) &engine->idxd_dev.conf_dev
#define group_confdev(group) &group->idxd_dev.conf_dev
#define cdev_dev(cdev) &cdev->idxd_dev.conf_dev
#define confdev_to_idxd_dev(dev) container_of(dev, struct idxd_dev, conf_dev)
static inline struct idxd_device *confdev_to_idxd(struct device *dev)
{
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
return container_of(idxd_dev, struct idxd_device, idxd_dev);
}
static inline struct idxd_wq *confdev_to_wq(struct device *dev)
{
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
return container_of(idxd_dev, struct idxd_wq, idxd_dev);
}
static inline struct idxd_engine *confdev_to_engine(struct device *dev)
{
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
return container_of(idxd_dev, struct idxd_engine, idxd_dev);
}
static inline struct idxd_group *confdev_to_group(struct device *dev)
{
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
return container_of(idxd_dev, struct idxd_group, idxd_dev);
}
static inline struct idxd_cdev *dev_to_cdev(struct device *dev)
{
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
return container_of(idxd_dev, struct idxd_cdev, idxd_dev);
}
static inline void idxd_dev_set_type(struct idxd_dev *idev, int type)
{
if (type >= IDXD_DEV_MAX_TYPE) {
idev->type = IDXD_DEV_NONE;
return;
}
idev->type = type;
}
extern struct bus_type dsa_bus_type; extern struct bus_type dsa_bus_type;
extern struct bus_type iax_bus_type; extern struct bus_type iax_bus_type;
......
...@@ -200,6 +200,7 @@ static int idxd_setup_wqs(struct idxd_device *idxd) ...@@ -200,6 +200,7 @@ static int idxd_setup_wqs(struct idxd_device *idxd)
{ {
struct device *dev = &idxd->pdev->dev; struct device *dev = &idxd->pdev->dev;
struct idxd_wq *wq; struct idxd_wq *wq;
struct device *conf_dev;
int i, rc; int i, rc;
idxd->wqs = kcalloc_node(idxd->max_wqs, sizeof(struct idxd_wq *), idxd->wqs = kcalloc_node(idxd->max_wqs, sizeof(struct idxd_wq *),
...@@ -214,15 +215,17 @@ static int idxd_setup_wqs(struct idxd_device *idxd) ...@@ -214,15 +215,17 @@ static int idxd_setup_wqs(struct idxd_device *idxd)
goto err; goto err;
} }
idxd_dev_set_type(&wq->idxd_dev, IDXD_DEV_WQ);
conf_dev = wq_confdev(wq);
wq->id = i; wq->id = i;
wq->idxd = idxd; wq->idxd = idxd;
device_initialize(&wq->conf_dev); device_initialize(wq_confdev(wq));
wq->conf_dev.parent = &idxd->conf_dev; conf_dev->parent = idxd_confdev(idxd);
wq->conf_dev.bus = &dsa_bus_type; conf_dev->bus = &dsa_bus_type;
wq->conf_dev.type = &idxd_wq_device_type; conf_dev->type = &idxd_wq_device_type;
rc = dev_set_name(&wq->conf_dev, "wq%d.%d", idxd->id, wq->id); rc = dev_set_name(conf_dev, "wq%d.%d", idxd->id, wq->id);
if (rc < 0) { if (rc < 0) {
put_device(&wq->conf_dev); put_device(conf_dev);
goto err; goto err;
} }
...@@ -233,7 +236,7 @@ static int idxd_setup_wqs(struct idxd_device *idxd) ...@@ -233,7 +236,7 @@ static int idxd_setup_wqs(struct idxd_device *idxd)
wq->max_batch_size = idxd->max_batch_size; wq->max_batch_size = idxd->max_batch_size;
wq->wqcfg = kzalloc_node(idxd->wqcfg_size, GFP_KERNEL, dev_to_node(dev)); wq->wqcfg = kzalloc_node(idxd->wqcfg_size, GFP_KERNEL, dev_to_node(dev));
if (!wq->wqcfg) { if (!wq->wqcfg) {
put_device(&wq->conf_dev); put_device(conf_dev);
rc = -ENOMEM; rc = -ENOMEM;
goto err; goto err;
} }
...@@ -243,8 +246,11 @@ static int idxd_setup_wqs(struct idxd_device *idxd) ...@@ -243,8 +246,11 @@ static int idxd_setup_wqs(struct idxd_device *idxd)
return 0; return 0;
err: err:
while (--i >= 0) while (--i >= 0) {
put_device(&idxd->wqs[i]->conf_dev); wq = idxd->wqs[i];
conf_dev = wq_confdev(wq);
put_device(conf_dev);
}
return rc; return rc;
} }
...@@ -252,6 +258,7 @@ static int idxd_setup_engines(struct idxd_device *idxd) ...@@ -252,6 +258,7 @@ static int idxd_setup_engines(struct idxd_device *idxd)
{ {
struct idxd_engine *engine; struct idxd_engine *engine;
struct device *dev = &idxd->pdev->dev; struct device *dev = &idxd->pdev->dev;
struct device *conf_dev;
int i, rc; int i, rc;
idxd->engines = kcalloc_node(idxd->max_engines, sizeof(struct idxd_engine *), idxd->engines = kcalloc_node(idxd->max_engines, sizeof(struct idxd_engine *),
...@@ -266,15 +273,17 @@ static int idxd_setup_engines(struct idxd_device *idxd) ...@@ -266,15 +273,17 @@ static int idxd_setup_engines(struct idxd_device *idxd)
goto err; goto err;
} }
idxd_dev_set_type(&engine->idxd_dev, IDXD_DEV_ENGINE);
conf_dev = engine_confdev(engine);
engine->id = i; engine->id = i;
engine->idxd = idxd; engine->idxd = idxd;
device_initialize(&engine->conf_dev); device_initialize(conf_dev);
engine->conf_dev.parent = &idxd->conf_dev; conf_dev->parent = idxd_confdev(idxd);
engine->conf_dev.bus = &dsa_bus_type; conf_dev->bus = &dsa_bus_type;
engine->conf_dev.type = &idxd_engine_device_type; conf_dev->type = &idxd_engine_device_type;
rc = dev_set_name(&engine->conf_dev, "engine%d.%d", idxd->id, engine->id); rc = dev_set_name(conf_dev, "engine%d.%d", idxd->id, engine->id);
if (rc < 0) { if (rc < 0) {
put_device(&engine->conf_dev); put_device(conf_dev);
goto err; goto err;
} }
...@@ -284,14 +293,18 @@ static int idxd_setup_engines(struct idxd_device *idxd) ...@@ -284,14 +293,18 @@ static int idxd_setup_engines(struct idxd_device *idxd)
return 0; return 0;
err: err:
while (--i >= 0) while (--i >= 0) {
put_device(&idxd->engines[i]->conf_dev); engine = idxd->engines[i];
conf_dev = engine_confdev(engine);
put_device(conf_dev);
}
return rc; return rc;
} }
static int idxd_setup_groups(struct idxd_device *idxd) static int idxd_setup_groups(struct idxd_device *idxd)
{ {
struct device *dev = &idxd->pdev->dev; struct device *dev = &idxd->pdev->dev;
struct device *conf_dev;
struct idxd_group *group; struct idxd_group *group;
int i, rc; int i, rc;
...@@ -307,15 +320,17 @@ static int idxd_setup_groups(struct idxd_device *idxd) ...@@ -307,15 +320,17 @@ static int idxd_setup_groups(struct idxd_device *idxd)
goto err; goto err;
} }
idxd_dev_set_type(&group->idxd_dev, IDXD_DEV_GROUP);
conf_dev = group_confdev(group);
group->id = i; group->id = i;
group->idxd = idxd; group->idxd = idxd;
device_initialize(&group->conf_dev); device_initialize(conf_dev);
group->conf_dev.parent = &idxd->conf_dev; conf_dev->parent = idxd_confdev(idxd);
group->conf_dev.bus = &dsa_bus_type; conf_dev->bus = &dsa_bus_type;
group->conf_dev.type = &idxd_group_device_type; conf_dev->type = &idxd_group_device_type;
rc = dev_set_name(&group->conf_dev, "group%d.%d", idxd->id, group->id); rc = dev_set_name(conf_dev, "group%d.%d", idxd->id, group->id);
if (rc < 0) { if (rc < 0) {
put_device(&group->conf_dev); put_device(conf_dev);
goto err; goto err;
} }
...@@ -327,8 +342,10 @@ static int idxd_setup_groups(struct idxd_device *idxd) ...@@ -327,8 +342,10 @@ static int idxd_setup_groups(struct idxd_device *idxd)
return 0; return 0;
err: err:
while (--i >= 0) while (--i >= 0) {
put_device(&idxd->groups[i]->conf_dev); group = idxd->groups[i];
put_device(group_confdev(group));
}
return rc; return rc;
} }
...@@ -337,11 +354,11 @@ static void idxd_cleanup_internals(struct idxd_device *idxd) ...@@ -337,11 +354,11 @@ static void idxd_cleanup_internals(struct idxd_device *idxd)
int i; int i;
for (i = 0; i < idxd->max_groups; i++) for (i = 0; i < idxd->max_groups; i++)
put_device(&idxd->groups[i]->conf_dev); put_device(group_confdev(idxd->groups[i]));
for (i = 0; i < idxd->max_engines; i++) for (i = 0; i < idxd->max_engines; i++)
put_device(&idxd->engines[i]->conf_dev); put_device(engine_confdev(idxd->engines[i]));
for (i = 0; i < idxd->max_wqs; i++) for (i = 0; i < idxd->max_wqs; i++)
put_device(&idxd->wqs[i]->conf_dev); put_device(wq_confdev(idxd->wqs[i]));
destroy_workqueue(idxd->wq); destroy_workqueue(idxd->wq);
} }
...@@ -381,13 +398,13 @@ static int idxd_setup_internals(struct idxd_device *idxd) ...@@ -381,13 +398,13 @@ static int idxd_setup_internals(struct idxd_device *idxd)
err_wkq_create: err_wkq_create:
for (i = 0; i < idxd->max_groups; i++) for (i = 0; i < idxd->max_groups; i++)
put_device(&idxd->groups[i]->conf_dev); put_device(group_confdev(idxd->groups[i]));
err_group: err_group:
for (i = 0; i < idxd->max_engines; i++) for (i = 0; i < idxd->max_engines; i++)
put_device(&idxd->engines[i]->conf_dev); put_device(engine_confdev(idxd->engines[i]));
err_engine: err_engine:
for (i = 0; i < idxd->max_wqs; i++) for (i = 0; i < idxd->max_wqs; i++)
put_device(&idxd->wqs[i]->conf_dev); put_device(wq_confdev(idxd->wqs[i]));
err_wqs: err_wqs:
kfree(idxd->int_handles); kfree(idxd->int_handles);
return rc; return rc;
...@@ -469,6 +486,7 @@ static void idxd_read_caps(struct idxd_device *idxd) ...@@ -469,6 +486,7 @@ static void idxd_read_caps(struct idxd_device *idxd)
static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_data *data) static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_data *data)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device *conf_dev;
struct idxd_device *idxd; struct idxd_device *idxd;
int rc; int rc;
...@@ -476,19 +494,21 @@ static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_d ...@@ -476,19 +494,21 @@ static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_d
if (!idxd) if (!idxd)
return NULL; return NULL;
conf_dev = idxd_confdev(idxd);
idxd->pdev = pdev; idxd->pdev = pdev;
idxd->data = data; idxd->data = data;
idxd_dev_set_type(&idxd->idxd_dev, idxd->data->type);
idxd->id = ida_alloc(&idxd_ida, GFP_KERNEL); idxd->id = ida_alloc(&idxd_ida, GFP_KERNEL);
if (idxd->id < 0) if (idxd->id < 0)
return NULL; return NULL;
device_initialize(&idxd->conf_dev); device_initialize(conf_dev);
idxd->conf_dev.parent = dev; conf_dev->parent = dev;
idxd->conf_dev.bus = &dsa_bus_type; conf_dev->bus = &dsa_bus_type;
idxd->conf_dev.type = idxd->data->dev_type; conf_dev->type = idxd->data->dev_type;
rc = dev_set_name(&idxd->conf_dev, "%s%d", idxd->data->name_prefix, idxd->id); rc = dev_set_name(conf_dev, "%s%d", idxd->data->name_prefix, idxd->id);
if (rc < 0) { if (rc < 0) {
put_device(&idxd->conf_dev); put_device(conf_dev);
return NULL; return NULL;
} }
...@@ -674,7 +694,7 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -674,7 +694,7 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
err: err:
pci_iounmap(pdev, idxd->reg_base); pci_iounmap(pdev, idxd->reg_base);
err_iomap: err_iomap:
put_device(&idxd->conf_dev); put_device(idxd_confdev(idxd));
err_idxd_alloc: err_idxd_alloc:
pci_disable_device(pdev); pci_disable_device(pdev);
return rc; return rc;
...@@ -787,7 +807,7 @@ static void idxd_remove(struct pci_dev *pdev) ...@@ -787,7 +807,7 @@ static void idxd_remove(struct pci_dev *pdev)
pci_disable_device(pdev); pci_disable_device(pdev);
destroy_workqueue(idxd->wq); destroy_workqueue(idxd->wq);
perfmon_pmu_remove(idxd); perfmon_pmu_remove(idxd);
device_unregister(&idxd->conf_dev); device_unregister(idxd_confdev(idxd));
} }
static struct pci_driver idxd_pci_driver = { static struct pci_driver idxd_pci_driver = {
......
...@@ -51,7 +51,7 @@ static void idxd_device_reinit(struct work_struct *work) ...@@ -51,7 +51,7 @@ static void idxd_device_reinit(struct work_struct *work)
rc = idxd_wq_enable(wq); rc = idxd_wq_enable(wq);
if (rc < 0) { if (rc < 0) {
dev_warn(dev, "Unable to re-enable wq %s\n", dev_warn(dev, "Unable to re-enable wq %s\n",
dev_name(&wq->conf_dev)); dev_name(wq_confdev(wq)));
} }
} }
} }
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment