Hi, Tom,
On 4/28/23 13:55, Tom Zanussi wrote:
> From: Dave Jiang <dave.jiang@intel.com>
>
> With the possibility of multiple wq drivers that can be bound to the wq,
> the user config tool accel-config needs a way to know which wq driver to
> bind to the wq. Introduce per wq driver_name sysfs attribute where the user
> can indicate the driver to be bound to the wq. This allows accel-config to
> just bind to the driver using wq->driver_name.
>
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
> ---
...
> diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h
> index 7ced8d283d98..505118fc19de 100644
> --- a/drivers/dma/idxd/idxd.h
> +++ b/drivers/dma/idxd/idxd.h
> @@ -214,6 +214,8 @@ struct idxd_wq {
> char name[WQ_NAME_SIZE + 1];
> u64 max_xfer_bytes;
> u32 max_batch_size;
> +
> + char driver_name[WQ_NAME_SIZE + 1];
It's confused to use "WQ_NAME_SIZE" for driver name size.
Maybe it's better to have a new definition "DRIVER_NAME_SIZE"?
BTW, WQ_NAME_SIZE is 1024 which is unnecessary big for storing
driver_name[] in the structure. It would be better to have a smaller
size (e.g. 128) in DRIVER_NAME_SIZE.
Thanks.
-Fenghua
Hi Fenghua,
On Fri, 2023-04-28 at 17:14 -0700, Fenghua Yu wrote:
> Hi, Tom,
>
> On 4/28/23 13:55, Tom Zanussi wrote:
> > From: Dave Jiang <dave.jiang@intel.com>
> >
> > With the possibility of multiple wq drivers that can be bound to
> > the wq,
> > the user config tool accel-config needs a way to know which wq
> > driver to
> > bind to the wq. Introduce per wq driver_name sysfs attribute where
> > the user
> > can indicate the driver to be bound to the wq. This allows accel-
> > config to
> > just bind to the driver using wq->driver_name.
> >
> > Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> > Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
> > ---
>
> ...
>
> > diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h
> > index 7ced8d283d98..505118fc19de 100644
> > --- a/drivers/dma/idxd/idxd.h
> > +++ b/drivers/dma/idxd/idxd.h
> > @@ -214,6 +214,8 @@ struct idxd_wq {
> > char name[WQ_NAME_SIZE + 1];
> > u64 max_xfer_bytes;
> > u32 max_batch_size;
> > +
> > + char driver_name[WQ_NAME_SIZE + 1];
>
> It's confused to use "WQ_NAME_SIZE" for driver name size.
> Maybe it's better to have a new definition "DRIVER_NAME_SIZE"?
> BTW, WQ_NAME_SIZE is 1024 which is unnecessary big for storing
> driver_name[] in the structure. It would be better to have a smaller
> size (e.g. 128) in DRIVER_NAME_SIZE.
Yes, that makes sense - I'll add an IAA_DRIVER_NAME_SIZE of 128 and use
that instead.
Thanks,
Tom
>
> Thanks.
>
> -Fenghua
@@ -244,6 +244,12 @@ Description: Shows the operation capability bits displayed in bitmap format
correlates to the operations allowed. It's visible only
on platforms that support the capability.
+What: /sys/bus/dsa/devices/wq<m>.<n>/driver_name
+Date: Mar 27, 2023
+KernelVersion: 6.4.0
+Contact: dmaengine@vger.kernel.org
+Description: Name of driver to be bounded to the wq.
+
What: /sys/bus/dsa/devices/engine<m>.<n>/group_id
Date: Oct 25, 2019
KernelVersion: 5.6.0
@@ -304,6 +304,7 @@ void idxd_wq_del_cdev(struct idxd_wq *wq)
static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)
{
+ struct device *dev = &idxd_dev->conf_dev;
struct idxd_wq *wq = idxd_dev_to_wq(idxd_dev);
struct idxd_device *idxd = wq->idxd;
int rc;
@@ -330,6 +331,13 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)
}
mutex_lock(&wq->wq_lock);
+
+ if (!idxd_wq_driver_name_match(wq, dev)) {
+ idxd->cmd_status = IDXD_SCMD_WQ_NO_DRV_NAME;
+ rc = -ENODEV;
+ goto err;
+ }
+
wq->type = IDXD_WQT_USER;
rc = drv_enable_wq(wq);
if (rc < 0)
@@ -305,6 +305,12 @@ static int idxd_dmaengine_drv_probe(struct idxd_dev *idxd_dev)
return -ENXIO;
mutex_lock(&wq->wq_lock);
+ if (!idxd_wq_driver_name_match(wq, dev)) {
+ idxd->cmd_status = IDXD_SCMD_WQ_NO_DRV_NAME;
+ rc = -ENODEV;
+ goto err;
+ }
+
wq->type = IDXD_WQT_KERNEL;
rc = drv_enable_wq(wq);
@@ -214,6 +214,8 @@ struct idxd_wq {
char name[WQ_NAME_SIZE + 1];
u64 max_xfer_bytes;
u32 max_batch_size;
+
+ char driver_name[WQ_NAME_SIZE + 1];
};
struct idxd_engine {
@@ -580,6 +582,11 @@ static inline void idxd_wqcfg_set_max_batch_shift(int idxd_type, union wqcfg *wq
wqcfg->max_batch_shift = max_batch_shift;
}
+static inline int idxd_wq_driver_name_match(struct idxd_wq *wq, struct device *dev)
+{
+ return (strncmp(wq->driver_name, dev->driver->name, strlen(dev->driver->name)) == 0);
+}
+
int __must_check __idxd_driver_register(struct idxd_device_driver *idxd_drv,
struct module *module, const char *mod_name);
#define idxd_driver_register(driver) \
@@ -1224,6 +1224,33 @@ static ssize_t wq_op_config_store(struct device *dev, struct device_attribute *a
static struct device_attribute dev_attr_wq_op_config =
__ATTR(op_config, 0644, wq_op_config_show, wq_op_config_store);
+static ssize_t wq_driver_name_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ struct idxd_wq *wq = confdev_to_wq(dev);
+
+ return sysfs_emit(buf, "%s\n", wq->driver_name);
+}
+
+static ssize_t wq_driver_name_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct idxd_wq *wq = confdev_to_wq(dev);
+
+ if (wq->state != IDXD_WQ_DISABLED)
+ return -EPERM;
+
+ if (strlen(buf) > WQ_NAME_SIZE || strlen(buf) == 0)
+ return -EINVAL;
+
+ memset(wq->driver_name, 0, WQ_NAME_SIZE + 1);
+ strncpy(wq->driver_name, buf, WQ_NAME_SIZE);
+ strreplace(wq->name, '\n', '\0');
+ return count;
+}
+
+static struct device_attribute dev_attr_wq_driver_name =
+ __ATTR(driver_name, 0644, wq_driver_name_show, wq_driver_name_store);
+
static struct attribute *idxd_wq_attributes[] = {
&dev_attr_wq_clients.attr,
&dev_attr_wq_state.attr,
@@ -1242,6 +1269,7 @@ static struct attribute *idxd_wq_attributes[] = {
&dev_attr_wq_occupancy.attr,
&dev_attr_wq_enqcmds_retries.attr,
&dev_attr_wq_op_config.attr,
+ &dev_attr_wq_driver_name.attr,
NULL,
};
@@ -30,6 +30,7 @@ enum idxd_scmd_stat {
IDXD_SCMD_WQ_NO_PRIV = 0x800f0000,
IDXD_SCMD_WQ_IRQ_ERR = 0x80100000,
IDXD_SCMD_WQ_USER_NO_IOMMU = 0x80110000,
+ IDXD_SCMD_WQ_NO_DRV_NAME = 0x80200000,
};
#define IDXD_SCMD_SOFTERR_MASK 0x80000000