Skip to content

Commit 700af3a

Browse files
davejiangvinodkoul
authored andcommitted
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 <[email protected]> Signed-off-by: Dave Jiang <[email protected]> Link: https://lore.kernel.org/r/162637460065.744545.584492831446090984.stgit@djiang5-desk3.ch.intel.com Signed-off-by: Vinod Koul <[email protected]>
1 parent da5a11d commit 700af3a

File tree

6 files changed

+251
-185
lines changed

6 files changed

+251
-185
lines changed

drivers/dma/idxd/cdev.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct idxd_user_context {
4141

4242
static void idxd_cdev_dev_release(struct device *dev)
4343
{
44-
struct idxd_cdev *idxd_cdev = container_of(dev, struct idxd_cdev, dev);
44+
struct idxd_cdev *idxd_cdev = dev_to_cdev(dev);
4545
struct idxd_cdev_context *cdev_ctx;
4646
struct idxd_wq *wq = idxd_cdev->wq;
4747

@@ -256,9 +256,10 @@ int idxd_wq_add_cdev(struct idxd_wq *wq)
256256
if (!idxd_cdev)
257257
return -ENOMEM;
258258

259+
idxd_cdev->idxd_dev.type = IDXD_DEV_CDEV;
259260
idxd_cdev->wq = wq;
260261
cdev = &idxd_cdev->cdev;
261-
dev = &idxd_cdev->dev;
262+
dev = cdev_dev(idxd_cdev);
262263
cdev_ctx = &ictx[wq->idxd->data->type];
263264
minor = ida_simple_get(&cdev_ctx->minor_ida, 0, MINORMASK, GFP_KERNEL);
264265
if (minor < 0) {
@@ -268,7 +269,7 @@ int idxd_wq_add_cdev(struct idxd_wq *wq)
268269
idxd_cdev->minor = minor;
269270

270271
device_initialize(dev);
271-
dev->parent = &wq->conf_dev;
272+
dev->parent = wq_confdev(wq);
272273
dev->bus = &dsa_bus_type;
273274
dev->type = &idxd_cdev_device_type;
274275
dev->devt = MKDEV(MAJOR(cdev_ctx->devt), minor);
@@ -299,8 +300,8 @@ void idxd_wq_del_cdev(struct idxd_wq *wq)
299300

300301
idxd_cdev = wq->idxd_cdev;
301302
wq->idxd_cdev = NULL;
302-
cdev_device_del(&idxd_cdev->cdev, &idxd_cdev->dev);
303-
put_device(&idxd_cdev->dev);
303+
cdev_device_del(&idxd_cdev->cdev, cdev_dev(idxd_cdev));
304+
put_device(cdev_dev(idxd_cdev));
304305
}
305306

306307
int idxd_cdev_register(void)

drivers/dma/idxd/dma.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ int idxd_register_dma_channel(struct idxd_wq *wq)
245245

246246
wq->idxd_chan = idxd_chan;
247247
idxd_chan->wq = wq;
248-
get_device(&wq->conf_dev);
248+
get_device(wq_confdev(wq));
249249

250250
return 0;
251251
}
@@ -260,5 +260,5 @@ void idxd_unregister_dma_channel(struct idxd_wq *wq)
260260
list_del(&chan->device_node);
261261
kfree(wq->idxd_chan);
262262
wq->idxd_chan = NULL;
263-
put_device(&wq->conf_dev);
263+
put_device(wq_confdev(wq));
264264
}

drivers/dma/idxd/idxd.h

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,24 @@
1717

1818
extern struct kmem_cache *idxd_desc_pool;
1919

20-
struct idxd_device;
2120
struct idxd_wq;
21+
struct idxd_dev;
22+
23+
enum idxd_dev_type {
24+
IDXD_DEV_NONE = -1,
25+
IDXD_DEV_DSA = 0,
26+
IDXD_DEV_IAX,
27+
IDXD_DEV_WQ,
28+
IDXD_DEV_GROUP,
29+
IDXD_DEV_ENGINE,
30+
IDXD_DEV_CDEV,
31+
IDXD_DEV_MAX_TYPE,
32+
};
33+
34+
struct idxd_dev {
35+
struct device conf_dev;
36+
enum idxd_dev_type type;
37+
};
2238

2339
#define IDXD_REG_TIMEOUT 50
2440
#define IDXD_DRAIN_TIMEOUT 5000
@@ -52,7 +68,7 @@ struct idxd_irq_entry {
5268
};
5369

5470
struct idxd_group {
55-
struct device conf_dev;
71+
struct idxd_dev idxd_dev;
5672
struct idxd_device *idxd;
5773
struct grpcfg grpcfg;
5874
int id;
@@ -111,7 +127,7 @@ enum idxd_wq_type {
111127
struct idxd_cdev {
112128
struct idxd_wq *wq;
113129
struct cdev cdev;
114-
struct device dev;
130+
struct idxd_dev idxd_dev;
115131
int minor;
116132
};
117133

@@ -139,7 +155,7 @@ struct idxd_wq {
139155
void __iomem *portal;
140156
struct percpu_ref wq_active;
141157
struct completion wq_dead;
142-
struct device conf_dev;
158+
struct idxd_dev idxd_dev;
143159
struct idxd_cdev *idxd_cdev;
144160
struct wait_queue_head err_queue;
145161
struct idxd_device *idxd;
@@ -174,7 +190,7 @@ struct idxd_wq {
174190
};
175191

176192
struct idxd_engine {
177-
struct device conf_dev;
193+
struct idxd_dev idxd_dev;
178194
int id;
179195
struct idxd_group *group;
180196
struct idxd_device *idxd;
@@ -218,7 +234,7 @@ struct idxd_driver_data {
218234
};
219235

220236
struct idxd_device {
221-
struct device conf_dev;
237+
struct idxd_dev idxd_dev;
222238
struct idxd_driver_data *data;
223239
struct list_head list;
224240
struct idxd_hw hw;
@@ -301,8 +317,58 @@ enum idxd_completion_status {
301317
IDXD_COMP_DESC_ABORT = 0xff,
302318
};
303319

304-
#define confdev_to_idxd(dev) container_of(dev, struct idxd_device, conf_dev)
305-
#define confdev_to_wq(dev) container_of(dev, struct idxd_wq, conf_dev)
320+
#define idxd_confdev(idxd) &idxd->idxd_dev.conf_dev
321+
#define wq_confdev(wq) &wq->idxd_dev.conf_dev
322+
#define engine_confdev(engine) &engine->idxd_dev.conf_dev
323+
#define group_confdev(group) &group->idxd_dev.conf_dev
324+
#define cdev_dev(cdev) &cdev->idxd_dev.conf_dev
325+
326+
#define confdev_to_idxd_dev(dev) container_of(dev, struct idxd_dev, conf_dev)
327+
328+
static inline struct idxd_device *confdev_to_idxd(struct device *dev)
329+
{
330+
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
331+
332+
return container_of(idxd_dev, struct idxd_device, idxd_dev);
333+
}
334+
335+
static inline struct idxd_wq *confdev_to_wq(struct device *dev)
336+
{
337+
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
338+
339+
return container_of(idxd_dev, struct idxd_wq, idxd_dev);
340+
}
341+
342+
static inline struct idxd_engine *confdev_to_engine(struct device *dev)
343+
{
344+
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
345+
346+
return container_of(idxd_dev, struct idxd_engine, idxd_dev);
347+
}
348+
349+
static inline struct idxd_group *confdev_to_group(struct device *dev)
350+
{
351+
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
352+
353+
return container_of(idxd_dev, struct idxd_group, idxd_dev);
354+
}
355+
356+
static inline struct idxd_cdev *dev_to_cdev(struct device *dev)
357+
{
358+
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
359+
360+
return container_of(idxd_dev, struct idxd_cdev, idxd_dev);
361+
}
362+
363+
static inline void idxd_dev_set_type(struct idxd_dev *idev, int type)
364+
{
365+
if (type >= IDXD_DEV_MAX_TYPE) {
366+
idev->type = IDXD_DEV_NONE;
367+
return;
368+
}
369+
370+
idev->type = type;
371+
}
306372

307373
extern struct bus_type dsa_bus_type;
308374
extern struct bus_type iax_bus_type;

0 commit comments

Comments
 (0)