Add sysfs interface to switchtec-dma
Subsystems (2)
Logan Gunthorpe
maintainerv4 cover Add sysfs interface to switchtec-dma
This is mostly a resend of my series last week. I'm really hoping to get this in this cycle as this is the work I actually need to get done and the bug fixes are something of a side project.
This patch set adds a handful of sysfs attributes to the switchtec-dma driver. This is the 4th version which I'm hoping to get it in now that my bug fixes and cleanup branch from Sashiko feedback was merged.
The first two patches clean up and generalize the technique that ioat used to add sysfs attributes to a dma channel. The other two patches add a couple different sets of sysfs attributes that are useful in configuring and monitoring the hardware.
This patch set is based on v7.4-rc2.
Logan
[v3] https://lore.kernel.org/all/[email protected]/
--
Changes since v3:
- Added Dave Jiang's Reviewed-by tag
- Rebased on v7.4-rc2
Changes since v2:
- Renamed the new channel lookup helpers to use the dmaengine_ prefix:
dma_chan_from_dev_lock() and dma_chan_from_dev_unlock() are now dmaengine_chan_from_dev_lock() and dmaengine_chan_from_dev_unlock(), and the dma_chan_from_dev CLASS is now dmaengine_chan_from_dev. (Per Frank Li)
- Rebased on v7.4-rc1
Changes since v1:
- Replaced the per-channel embedded-kobject approach entirely with a new dma_device.chan_groups mechanism that attaches driver sysfs attributes directly to the channel's existing struct device instead of a second, separately-managed kobject. (Per Sashiko)
- Fixed the busy-channel check in perf_cfg_store(): it now returns -EBUSY instead of falsely reporting success, and the racy lockless chan->client_count check has been replaced with a hw_cfg_locked flag that's set/cleared under hw_ctrl_lock from alloc/free_chan_resources(), closing a TOCTOU window against concurrent channel allocation. (Per Sashiko)
- Took the hw_ctrl_lock around the perf_cfg read-modify-write so concurrent sysfs writes to different config attributes can't interleave and lose an update. (Per Sashiko)
- Converted latency_selector_show() from strcat() to sysfs_emit()/sysfs_emit_at(). (Per Sashiko)
- The PCI1008 device ID patch has been removed from this series, expanded and sent separately.
Logan Gunthorpe (4):
dmaengine: add per-channel sysfs attribute groups via chan_groups
dmaengine: ioatdma: convert per-channel sysfs to chan_groups
dmaengine: switchtec-dma: add config sysfs attributes
dmaengine: switchtec-dma: add pmon sysfs attributes
drivers/dma/dmaengine.c | 27 +++ drivers/dma/dmaengine.h | 19 ++ drivers/dma/ioat/dma.h | 6 +- drivers/dma/ioat/init.c | 5 +- drivers/dma/ioat/sysfs.c | 166 ++++++------- drivers/dma/switchtec_dma.c | 452 ++++++++++++++++++++++++++++++++++++ include/linux/dmaengine.h | 4 + 7 files changed, 569 insertions(+), 110 deletions(-)
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
Signature · 1 line
2.47.3
Logan Gunthorpe
maintainerPATCH v4 1/4 dmaengine: add per-channel sysfs attribute groups via chan_groups
Each channel already gets its own struct device (dma_chan_dev), registered with device_register()/device_unregister() and torn down correctly by chan_dev_release(). Let drivers add their own sysfs attributes to that device directly, via a new dma_device.chan_groups field.
This avoids drivers needing a second, separately-managed kobject to expose driver-specific attributes. That's a use-after-free issue:kobject_put() can invoke the ktype's release() and free the structure embedding dma_chan while the core (or the driver) still expects to reference it afterward, so avoiding it requires careful ordering and bookkeeping that's easy to get wrong. The channel's struct device already has the correct lifetime, and sysfs_create_group() supports the same named-subdirectory layout (attribute_group.name) that a bare kobject would provide.
To let show()/store() callbacks safely recover the struct dma_chan from the struct device they're attached to without exposing dma_list_mutex itself to drivers, add a small dmaengine_chan_from_dev_lock() / dmaengine_chan_from_dev_unlock() pair that take / release the lock, and wrap them in a dmaengine_chan_from_dev CLASS so callers can write:
CLASS(dmaengine_chan_from_dev, c)(dev); if (!c) return -ENODEV;
--- drivers/dma/dmaengine.c | 27 +++++++++++++++++++++++++++ drivers/dma/dmaengine.h | 19 +++++++++++++++++++ include/linux/dmaengine.h | 4 ++++ 3 files changed, 50 insertions(+)
drivers/dma/dmaengine.c +27 -0
@@ -161,6 +161,32 @@ static struct dma_chan *dev_to_dma_chan(struct device *dev)return chan_dev->chan; } +/** +* dmaengine_chan_from_dev_lock - take dma_list_mutex and convert a channel's +* struct device to its dma_chan +* @dev: the channel's struct device, embedded in struct dma_chan_dev +* +* Returns NULL if the channel has already been unregistered. Pairs with +* dmaengine_chan_from_dev_unlock(); see the dmaengine_chan_from_dev CLASS in +* drivers/dma/dmaengine.h. +*/ +struct dma_chan *dmaengine_chan_from_dev_lock (struct device *dev) +{ +mutex_lock (&dma_list_mutex); +return dev_to_dma_chan (dev); +} +EXPORT_SYMBOL_GPL (dmaengine_chan_from_dev_lock); + +/** +* dmaengine_chan_from_dev_unlock - release the channel lookup lock +* @chan: unused; matches the value produced by dmaengine_chan_from_dev_lock() +*/ +void dmaengine_chan_from_dev_unlock (struct dma_chan *chan) +{ +mutex_unlock (&dma_list_mutex); +} +EXPORT_SYMBOL_GPL (dmaengine_chan_from_dev_unlock); +static ssize_t memcpy_count_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -1117,6 +1143,7 @@ static int __dma_async_device_channel_register(struct dma_device *device,dmaengine_chan_dev (chan)->class = &dma_devclass;dmaengine_chan_dev (chan)->parent = device->dev; +dmaengine_chan_dev (chan)->groups = device->chan_groups; chan->chan_dev->chan = chan; chan->chan_dev->dev_id = device->dev_id;spin_lock_init (&chan->lock);
drivers/dma/dmaengine.h +19 -0
@@ -214,6 +214,25 @@ int dma_async_device_channel_register(struct dma_device *device,void dma_async_device_channel_unregister (struct dma_device *device,struct dma_chan *chan); +/* +* dmaengine_chan_from_dev_lock() / dmaengine_chan_from_dev_unlock() bracket +* a critical section across which a channel's struct device can be safely +* converted back to its struct dma_chan: dmaengine_chan_from_dev_lock() +* returns NULL if the channel has already been unregistered, and the lock +* it takes must be held for as long as the returned channel (or anything +* derived from it) is accessed. +* +* Use these through the dmaengine_chan_from_dev CLASS below rather than calling +* them directly. +*/ +struct dma_chan *dmaengine_chan_from_dev_lock (struct device *dev); +void dmaengine_chan_from_dev_unlock (struct dma_chan *chan); + +DEFINE_CLASS(dmaengine_chan_from_dev, struct dma_chan *, +dmaengine_chan_from_dev_unlock (_T), +dmaengine_chan_from_dev_lock (dev), + struct device *dev) +#ifdef CONFIG_DEBUG_FS #include <linux/debugfs.h>
include/linux/dmaengine.h +4 -0
@@ -839,6 +839,9 @@ struct dma_filter {* @dev: struct device reference for dma mapping api * @owner: owner module (automatically set based on the provided dev) * @chan_ida: unique channel ID +* @chan_groups: optional NULL-terminated array of sysfs attribute groups +* added to each channel's struct device, for driver-specific per-channel +* attributes * @src_addr_widths: bit mask of src addr widths the device supports * Width is specified in bytes, e.g. for a device supporting * a width of 4 the mask should have BIT(4) set.
@@ -923,6 +926,7 @@ struct dma_device {struct device *dev;struct module *owner;struct ida chan_ida; +const struct attribute_group **chan_groups;u32 src_addr_widths;u32 dst_addr_widths;
Signature · 1 line
2.47.3
Re: [PATCH v4 1/4] dmaengine: add per-channel sysfs attribute groups via chan_groups
Quoted 71 lines · Logan Gunthorpe
Each channel already gets its own struct device (
dma_chan_dev), registered with device_register()/device_unregister() and torn down correctly bychan_dev_release(). Let drivers add their own sysfs attributes to that device directly, via a new dma_device.chan_groups field.This avoids drivers needing a second, separately-managed kobject to expose driver-specific attributes. That's a use-after-free issue:
kobject_put()can invoke the ktype'srelease()and free the structure embeddingdma_chanwhile the core (or the driver) still expects to reference it afterward, so avoiding it requires careful ordering and bookkeeping that's easy to get wrong. The channel's struct device already has the correct lifetime, andsysfs_create_group()supports the same named-subdirectory layout (attribute_group.name) that a bare kobject would provide.To let show()/store() callbacks safely recover the struct
dma_chanfrom the struct device they're attached to without exposingdma_list_mutexitself to drivers, add a smalldmaengine_chan_from_dev_lock()/dmaengine_chan_from_dev_unlock()pair that take / release the lock, and wrap them in admaengine_chan_from_devCLASS so callers can write:CLASS(dmaengine_chan_from_dev, c)(dev); if (!c) return -ENODEV;Signed-off-by Logan Gunthorpe <[email protected]>--- drivers/dma/dmaengine.c | 27 +++++++++++++++++++++++++++ drivers/dma/dmaengine.h | 19 +++++++++++++++++++ include/linux/dmaengine.h | 4 ++++ 3 files changed, 50 insertions(+)drivers/dma/dmaengine.c +26
-0@@ -161,6 +161,32 @@ static struct dma_chan *dev_to_dma_chan(struct device *dev)return chan_dev->chan; } +/** +* dmaengine_chan_from_dev_lock - take dma_list_mutex and convert a channel's +* struct device to its dma_chan +* @dev: the channel's struct device, embedded in struct dma_chan_dev +* +* Returns NULL if the channel has already been unregistered. Pairs with +* dmaengine_chan_from_dev_unlock(); see the dmaengine_chan_from_dev CLASS in +* drivers/dma/dmaengine.h. +*/ +struct dma_chan *dmaengine_chan_from_dev_lock (struct device *dev) +{ +mutex_lock (&dma_list_mutex); +return dev_to_dma_chan (dev); +} +EXPORT_SYMBOL_GPL (dmaengine_chan_from_dev_lock); + +/** +* dmaengine_chan_from_dev_unlock - release the channel lookup lock +* @chan: unused; matches the value produced by dmaengine_chan_from_dev_lock() +*/ +void dmaengine_chan_from_dev_unlock (struct dma_chan *chan) +{ +mutex_unlock (&dma_list_mutex); +} +EXPORT_SYMBOL_GPL (dmaengine_chan_from_dev_unlock); +static ssize_t memcpy_count_show (struct device *dev,struct device_attribute *attr,char *buf) {
drivers/dma/dmaengine.c static int __dma_async_device_channel_register(struct dma_device *device, · line 1146
Quoted 4 lines
drivers/dma/dmaengine.c +1
-0@@ -1117,6 +1143,7 @@ static int __dma_async_device_channel_register(struct dma_device *device,dmaengine_chan_dev (chan)->class = &dma_devclass;dmaengine_chan_dev (chan)->parent = device->dev; +dmaengine_chan_dev (chan)->groups = device->chan_groups;
if echo channel have same groups, why need copy it to dma_chan?
Quoted 8 lines
drivers/dma/dmaengine.c +0
-0chan->chan_dev->chan = chan; chan->chan_dev->dev_id = device->dev_id;spin_lock_init (&chan->lock);drivers/dma/dmaengine.h +0
-0
drivers/dma/dmaengine.h int dma_async_device_channel_register(struct dma_device *device, · line 221
Quoted 8 lines
drivers/dma/dmaengine.h +5
-0@@ -214,6 +214,25 @@ int dma_async_device_channel_register(struct dma_device *device,void dma_async_device_channel_unregister (struct dma_device *device,struct dma_chan *chan); +/* +* dmaengine_chan_from_dev_lock() / dmaengine_chan_from_dev_unlock() bracket +* a critical section across which a channel's struct device can be safely +* converted back to its struct dma_chan: dmaengine_chan_from_dev_lock() +* returns NULL if the channel has already been unregistered, and the lock
where return NULL when already been unregistered
static struct dma_chan *dev_to_dma_chan(struct device *dev)
{
struct dma_chan_dev *chan_dev;
chan_dev = container_of(dev, typeof(*chan_dev), device);
return chan_dev->chan;
}Frank
Quoted 42 lines
drivers/dma/dmaengine.h +14
-0+* it takes must be held for as long as the returned channel (or anything +* derived from it) is accessed. +* +* Use these through the dmaengine_chan_from_dev CLASS below rather than calling +* them directly. +*/ +struct dma_chan *dmaengine_chan_from_dev_lock (struct device *dev); +void dmaengine_chan_from_dev_unlock (struct dma_chan *chan); + +DEFINE_CLASS(dmaengine_chan_from_dev, struct dma_chan *, +dmaengine_chan_from_dev_unlock (_T), +dmaengine_chan_from_dev_lock (dev), + struct device *dev) +#ifdef CONFIG_DEBUG_FS #include <linux/debugfs.h> include/linux/dmaengine.h +4
-1@@ -839,6 +839,9 @@ struct dma_filter {* @dev: struct device reference for dma mapping api * @owner: owner module (automatically set based on the provided dev) * @chan_ida: unique channel ID +* @chan_groups: optional NULL-terminated array of sysfs attribute groups +* added to each channel's struct device, for driver-specific per-channel +* attributes * @src_addr_widths: bit mask of src addr widths the device supports * Width is specified in bytes, e.g. for a device supporting * a width of 4 the mask should have BIT(4) set. @@ -923,6 +926,7 @@ struct dma_device {struct device *dev;struct module *owner;struct ida chan_ida; +const struct attribute_group **chan_groups;u32 src_addr_widths;u32 dst_addr_widths; --2.47.3
Logan Gunthorpe
maintainerRe: [PATCH v4 1/4] dmaengine: add per-channel sysfs attribute groups via chan_groups
Quoted 11 lines · Frank Li
drivers/dma/dmaengine.c static int __dma_async_device_channel_register(struct dma_device *device, · line 1146
Quoted 8 lines · Logan Gunthorpe
static
ssize_tmemcpy_count_show(struct device *dev,drivers/dma/dmaengine.c +1
-0struct device_attribute *attr, char *buf) {@@ -1117,6 +1143,7 @@ static int __dma_async_device_channel_register(struct dma_device *device,dmaengine_chan_dev (chan)->class = &dma_devclass;dmaengine_chan_dev (chan)->parent = device->dev; +dmaengine_chan_dev (chan)->groups = device->chan_groups;if echo channel have same groups, why need copy it to
dma_chan?
The groups pointer belong to each channel, so each dma_chan must set its groups to the chan_groups pointer stored in the device. The only way to add these groups is to set dma_chan->groups to something and the pointer stored chan_groups is exactly what it is there for. I can't see any other way to accomplish this. It makes no sense for each channel to have different groups.
Quoted 8 lines
drivers/dma/dmaengine.h int dma_async_device_channel_register(struct dma_device *device, · line 221
Quoted 5 lines
drivers/dma/dmaengine.h +5
-0+/* +* dmaengine_chan_from_dev_lock() / dmaengine_chan_from_dev_unlock() bracket +* a critical section across which a channel's struct device can be safely +* converted back to its struct dma_chan: dmaengine_chan_from_dev_lock() +* returns NULL if the channel has already been unregistered, and the lock where return NULL when already been unregistered
Quoted 7 lines
static struct
dma_chan*dev_to_dma_chan(struct device *dev){ struct dma_chan_dev *chan_dev; chan_dev = container_of(dev, typeof(*chan_dev), device); return chan_dev->chan; }
__dma_async_device_channel_unregister() will set chan_dev->chan to NULL while holding the dma_list_mutex lock.
Thanks for reviewing this,
Logan
Re: [PATCH v4 1/4] dmaengine: add per-channel sysfs attribute groups via chan_groups
In reply to Logan GunthorpeQuoted 22 lines · Logan Gunthorpe
Each channel already gets its own struct device (
dma_chan_dev), registered with device_register()/device_unregister() and torn down correctly bychan_dev_release(). Let drivers add their own sysfs attributes to that device directly, via a new dma_device.chan_groups field.This avoids drivers needing a second, separately-managed kobject to expose driver-specific attributes. That's a use-after-free issue:
kobject_put()can invoke the ktype'srelease()and free the structure embeddingdma_chanwhile the core (or the driver) still expects to reference it afterward, so avoiding it requires careful ordering and bookkeeping that's easy to get wrong. The channel's struct device already has the correct lifetime, andsysfs_create_group()supports the same named-subdirectory layout (attribute_group.name) that a bare kobject would provide.To let show()/store() callbacks safely recover the struct
dma_chanfrom the struct device they're attached to without exposingdma_list_mutexitself to drivers, add a smalldmaengine_chan_from_dev_lock()/dmaengine_chan_from_dev_unlock()pair that take / release the lock, and wrap them in admaengine_chan_from_devCLASS so callers can write:
Quoted 6 lines
CLASS(dmaengine_chan_from_dev, c)(dev); if (!c) return -ENODEV;Signed-off-by Logan Gunthorpe <[email protected]>---
Quoted 105 lines
drivers/dma/dmaengine.c | 27 +++++++++++++++++++++++++++ drivers/dma/dmaengine.h | 19 +++++++++++++++++++ include/linux/dmaengine.h | 4 ++++ 3 files changed, 50 insertions(+)drivers/dma/dmaengine.c +27
-0@@ -161,6 +161,32 @@ static struct dma_chan *dev_to_dma_chan(struct device *dev)return chan_dev->chan; } +/** +* dmaengine_chan_from_dev_lock - take dma_list_mutex and convert a channel's +* struct device to its dma_chan +* @dev: the channel's struct device, embedded in struct dma_chan_dev +* +* Returns NULL if the channel has already been unregistered. Pairs with +* dmaengine_chan_from_dev_unlock(); see the dmaengine_chan_from_dev CLASS in +* drivers/dma/dmaengine.h. +*/ +struct dma_chan *dmaengine_chan_from_dev_lock (struct device *dev) +{ +mutex_lock (&dma_list_mutex); +return dev_to_dma_chan (dev); +} +EXPORT_SYMBOL_GPL (dmaengine_chan_from_dev_lock); + +/** +* dmaengine_chan_from_dev_unlock - release the channel lookup lock +* @chan: unused; matches the value produced by dmaengine_chan_from_dev_lock() +*/ +void dmaengine_chan_from_dev_unlock (struct dma_chan *chan) +{ +mutex_unlock (&dma_list_mutex); +} +EXPORT_SYMBOL_GPL (dmaengine_chan_from_dev_unlock); +static ssize_t memcpy_count_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -1117,6 +1143,7 @@ static int __dma_async_device_channel_register(struct dma_device *device,dmaengine_chan_dev (chan)->class = &dma_devclass;dmaengine_chan_dev (chan)->parent = device->dev; +dmaengine_chan_dev (chan)->groups = device->chan_groups; chan->chan_dev->chan = chan; chan->chan_dev->dev_id = device->dev_id;spin_lock_init (&chan->lock);drivers/dma/dmaengine.h +19
-0@@ -214,6 +214,25 @@ int dma_async_device_channel_register(struct dma_device *device,void dma_async_device_channel_unregister (struct dma_device *device,struct dma_chan *chan); +/* +* dmaengine_chan_from_dev_lock() / dmaengine_chan_from_dev_unlock() bracket +* a critical section across which a channel's struct device can be safely +* converted back to its struct dma_chan: dmaengine_chan_from_dev_lock() +* returns NULL if the channel has already been unregistered, and the lock +* it takes must be held for as long as the returned channel (or anything +* derived from it) is accessed. +* +* Use these through the dmaengine_chan_from_dev CLASS below rather than calling +* them directly. +*/ +struct dma_chan *dmaengine_chan_from_dev_lock (struct device *dev); +void dmaengine_chan_from_dev_unlock (struct dma_chan *chan); + +DEFINE_CLASS(dmaengine_chan_from_dev, struct dma_chan *, +dmaengine_chan_from_dev_unlock (_T), +dmaengine_chan_from_dev_lock (dev), + struct device *dev) +#ifdef CONFIG_DEBUG_FS #include <linux/debugfs.h> include/linux/dmaengine.h +4
-1@@ -839,6 +839,9 @@ struct dma_filter {* @dev: struct device reference for dma mapping api * @owner: owner module (automatically set based on the provided dev) * @chan_ida: unique channel ID +* @chan_groups: optional NULL-terminated array of sysfs attribute groups +* added to each channel's struct device, for driver-specific per-channel +* attributes * @src_addr_widths: bit mask of src addr widths the device supports * Width is specified in bytes, e.g. for a device supporting * a width of 4 the mask should have BIT(4) set. @@ -923,6 +926,7 @@ struct dma_device {struct device *dev;struct module *owner;struct ida chan_ida; +const struct attribute_group **chan_groups;u32 src_addr_widths;u32 dst_addr_widths; --2.47.3
Logan Gunthorpe
maintainerPATCH v4 2/4 dmaengine: ioatdma: convert per-channel sysfs to chan_groups
In reply to Logan GunthorpeUse the new dma_device.chan_groups mechanism to add ioat's "quickdata" per-channel attributes directly to the channel's existing struct device, instead of a second, separately managed kobject (ioat_ktype/ioat_kobject_add()/ioat_kobject_del()).
Each show()/store() now recovers the struct dma_chan via dev_to_dma_chan() under dma_list_mutex, the same safe pattern already used by the core attributes, returning -ENODEV once the channel has been unregistered rather than reading it after the fact.
--- drivers/dma/ioat/dma.h | 6 +- drivers/dma/ioat/init.c | 5 +- drivers/dma/ioat/sysfs.c | 166 +++++++++++++++------------------------ 3 files changed, 67 insertions(+), 110 deletions(-)
drivers/dma/ioat/dma.h +1 -5
@@ -103,7 +103,6 @@ struct ioatdma_chan {#define IOAT_CHAN_DOWN 0#define IOAT_COMPLETION_ACK 1#define IOAT_RESET_PENDING 2 -#define IOAT_KOBJ_INIT_FAIL 3#define IOAT_RUN 5#define IOAT_CHAN_ACTIVE 6struct timer_list timer;
@@ -112,7 +111,6 @@ struct ioatdma_chan {dma_addr_t completion_dma;u64 *completion;struct tasklet_struct cleanup_task; -struct kobject kobj;/* ioat v2 / v3 channel attributes * @xfercap_log; log2 of channel max transfer length (for fast division)
@@ -190,7 +188,7 @@ struct ioat_ring_ent { };extern int ioat_pending_level; -extern const struct kobj_type ioat_ktype; +extern const struct attribute_group *ioat_groups[];extern struct kmem_cache *ioat_cache;extern struct kmem_cache *ioat_sed_cache;
@@ -393,8 +391,6 @@ void ioat_issue_pending(struct dma_chan *chan);/* IOAT Init functions */ bool is_bwd_ioat (struct pci_dev *pdev);struct dca_provider *ioat_dca_init (struct pci_dev *pdev,void __iomem *iobase); -void ioat_kobject_add (struct ioatdma_device *ioat_dma,const struct kobj_type *type); -void ioat_kobject_del (struct ioatdma_device *ioat_dma);int ioat_dma_setup_interrupts (struct ioatdma_device *ioat_dma);void ioat_stop (struct ioatdma_chan *ioat_chan);#endif /* IOATDMA_H */
drivers/dma/ioat/init.c +1 -4
@@ -541,8 +541,6 @@ static void ioat_dma_remove(struct ioatdma_device *ioat_dma)ioat_disable_interrupts (ioat_dma); -ioat_kobject_del (ioat_dma); -dma_async_device_unregister (dma); }
@@ -1185,12 +1183,11 @@ static int ioat3_dma_probe(struct ioatdma_device *ioat_dma, int dca) goto err_disable_interrupts; } + dma->chan_groups = ioat_groups; err =dma_async_device_register (&ioat_dma->dma_dev);if (err) goto err_disable_interrupts; -ioat_kobject_add (ioat_dma, &ioat_ktype); -if (dca) ioat_dma->dca =ioat_dca_init (pdev, ioat_dma->reg_base);
drivers/dma/ioat/sysfs.c +65 -101
219 lines not on this page · raw message
Signature · 1 line
2.47.3
Re: [PATCH v4 2/4] dmaengine: ioatdma: convert per-channel sysfs to chan_groups
Quoted 5 lines · Logan Gunthorpe
Use the new dma_device.chan_groups mechanism to add ioat's "quickdata" per-channel attributes directly to the channel's existing struct device, instead of a second, separately managed kobject (ioat_ktype/ioat_kobject_add()/ioat_kobject_del()).
Quoted 8 lines
Each show()/store() now recovers the struct
dma_chanviadev_to_dma_chan()underdma_list_mutex, the same safe pattern already used by the core attributes, returning-ENODEVonce the channel has been unregistered rather than reading it after the fact.Reviewed-by Dave Jiang <[email protected]>Signed-off-by Logan Gunthorpe <[email protected]>---
Quoted 298 lines
drivers/dma/ioat/dma.h | 6 +- drivers/dma/ioat/init.c | 5 +- drivers/dma/ioat/sysfs.c | 166 +++++++++++++++------------------------ 3 files changed, 67 insertions(+), 110 deletions(-)drivers/dma/ioat/dma.h +1
-5@@ -103,7 +103,6 @@ struct ioatdma_chan {#define IOAT_CHAN_DOWN 0#define IOAT_COMPLETION_ACK 1#define IOAT_RESET_PENDING 2 -#define IOAT_KOBJ_INIT_FAIL 3#define IOAT_RUN 5#define IOAT_CHAN_ACTIVE 6struct timer_list timer;@@ -112,7 +111,6 @@ struct ioatdma_chan {dma_addr_t completion_dma;u64 *completion;struct tasklet_struct cleanup_task; -struct kobject kobj;/* ioat v2 / v3 channel attributes * @xfercap_log; log2 of channel max transfer length (for fast division) @@ -190,7 +188,7 @@ struct ioat_ring_ent { };extern int ioat_pending_level; -extern const struct kobj_type ioat_ktype; +extern const struct attribute_group *ioat_groups[];extern struct kmem_cache *ioat_cache;extern struct kmem_cache *ioat_sed_cache;@@ -393,8 +391,6 @@ void ioat_issue_pending(struct dma_chan *chan);/* IOAT Init functions */ bool is_bwd_ioat (struct pci_dev *pdev);struct dca_provider *ioat_dca_init (struct pci_dev *pdev,void __iomem *iobase); -void ioat_kobject_add (struct ioatdma_device *ioat_dma,const struct kobj_type *type); -void ioat_kobject_del (struct ioatdma_device *ioat_dma);int ioat_dma_setup_interrupts (struct ioatdma_device *ioat_dma);void ioat_stop (struct ioatdma_chan *ioat_chan);#endif /* IOATDMA_H */ drivers/dma/ioat/init.c +1
-4@@ -541,8 +541,6 @@ static void ioat_dma_remove(struct ioatdma_device *ioat_dma)ioat_disable_interrupts (ioat_dma); -ioat_kobject_del (ioat_dma); -dma_async_device_unregister (dma); }@@ -1185,12 +1183,11 @@ static int ioat3_dma_probe(struct ioatdma_device *ioat_dma, int dca) goto err_disable_interrupts; } + dma->chan_groups = ioat_groups; err =dma_async_device_register (&ioat_dma->dma_dev);if (err) goto err_disable_interrupts; -ioat_kobject_add (ioat_dma, &ioat_ktype); -if (dca) ioat_dma->dca =ioat_dca_init (pdev, ioat_dma->reg_base);drivers/dma/ioat/sysfs.c +65
-102@@ -14,134 +14,95 @@#include "../dmaengine.h" -struct ioat_sysfs_entry { -struct attribute attr; -ssize_t (*show)(struct dma_chan *,char *); -ssize_t (*store)(struct dma_chan *,const char *,size_t ); -}; - -static ssize_t cap_show (struct dma_chan *c,char *page) +static ssize_t cap_show (struct device *dev,struct device_attribute *attr, +char *page) { -struct dma_device *dma = c->device; +struct dma_device *dma; +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + dma = c->device;return sysfs_emit (page,"copy%s%s%s%s%s\n" ,dma_has_cap (DMA_PQ , dma->cap_mask) ?" pq" :"" ,dma_has_cap (DMA_PQ_VAL , dma->cap_mask) ?" pq_val" :"" ,dma_has_cap (DMA_XOR , dma->cap_mask) ?" xor" :"" ,dma_has_cap (DMA_XOR_VAL , dma->cap_mask) ?" xor_val" :"" ,dma_has_cap (DMA_INTERRUPT , dma->cap_mask) ?" intr" :"" ); - } -static const struct ioat_sysfs_entry ioat_cap_attr =__ATTR_RO (cap); +static DEVICE_ATTR_RO (cap); -static ssize_t version_show (struct dma_chan *c,char *page) +static ssize_t version_show (struct device *dev,struct device_attribute *attr, +char *page) { -struct dma_device *dma = c->device; -struct ioatdma_device *ioat_dma =to_ioatdma_device (dma); +struct ioatdma_device *ioat_dma; +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + ioat_dma =to_ioatdma_device (c->device);return sysfs_emit (page,"%d.%d\n" , ioat_dma->version >>4 , ioat_dma->version &0xf ); } -static const struct ioat_sysfs_entry ioat_version_attr =__ATTR_RO (version); +static DEVICE_ATTR_RO (version); -static ssize_t -ioat_attr_show (struct kobject *kobj,struct attribute *attr,char *page) +static ssize_t ring_size_show (struct device *dev,struct device_attribute *attr, +char *page) { -const struct ioat_sysfs_entry *entry; -struct ioatdma_chan *ioat_chan; +CLASS (dmaengine_chan_from_dev, c)(dev); - entry = container_of_const(attr, struct ioat_sysfs_entry, attr); - ioat_chan = container_of(kobj, struct ioatdma_chan, kobj); +if (!c) +return -ENODEV ; -if (!entry->show) -return -EIO ; -return entry->show (&ioat_chan->dma_chan, page); -} - -static ssize_t -ioat_attr_store (struct kobject *kobj,struct attribute *attr, -const char *page,size_t count) -{ -const struct ioat_sysfs_entry *entry; -struct ioatdma_chan *ioat_chan; - - entry = container_of_const(attr, struct ioat_sysfs_entry, attr); - ioat_chan = container_of(kobj, struct ioatdma_chan, kobj); - -if (!entry->store) -return -EIO ; -return entry->store (&ioat_chan->dma_chan, page, count); -} - -static const struct sysfs_ops ioat_sysfs_ops = { - .show = ioat_attr_show, - .store = ioat_attr_store, -}; - -void ioat_kobject_add (struct ioatdma_device *ioat_dma,const struct kobj_type *type) -{ -struct dma_device *dma = &ioat_dma->dma_dev; -struct dma_chan *c; - -list_for_each_entry (c, &dma->channels, device_node) { -struct ioatdma_chan *ioat_chan =to_ioat_chan (c); -struct kobject *parent = &c->dev->device.kobj; -int err; - - err =kobject_init_and_add (&ioat_chan->kobj, type, - parent,"quickdata" ); -if (err) { -dev_warn (to_dev (ioat_chan), -"sysfs init error (%d), continuing...\n" , err); -kobject_put (&ioat_chan->kobj); -set_bit (IOAT_KOBJ_INIT_FAIL , &ioat_chan->state); - } - } -} - -void ioat_kobject_del (struct ioatdma_device *ioat_dma) -{ -struct dma_device *dma = &ioat_dma->dma_dev; -struct dma_chan *c; - -list_for_each_entry (c, &dma->channels, device_node) { -struct ioatdma_chan *ioat_chan =to_ioat_chan (c); - -if (!test_bit (IOAT_KOBJ_INIT_FAIL , &ioat_chan->state)) { -kobject_del (&ioat_chan->kobj); -kobject_put (&ioat_chan->kobj); - } - } -} - -static ssize_t ring_size_show (struct dma_chan *c,char *page) -{struct ioatdma_chan *ioat_chan =to_ioat_chan (c);return sysfs_emit (page,"%d\n" , (1 << ioat_chan->alloc_order) & ~1 ); } -static const struct ioat_sysfs_entry ring_size_attr =__ATTR_RO (ring_size); +static DEVICE_ATTR_RO (ring_size); -static ssize_t ring_active_show (struct dma_chan *c,char *page) +static ssize_t ring_active_show (struct device *dev, +struct device_attribute *attr,char *page) { +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; +struct ioatdma_chan *ioat_chan =to_ioat_chan (c);/* ...taken outside the lock, no need to be precise */ return sysfs_emit (page,"%d\n" ,ioat_ring_active (ioat_chan)); } -static const struct ioat_sysfs_entry ring_active_attr =__ATTR_RO (ring_active); +static DEVICE_ATTR_RO (ring_active); -static ssize_t intr_coalesce_show (struct dma_chan *c,char *page) +static ssize_t intr_coalesce_show (struct device *dev, +struct device_attribute *attr,char *page) { +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; +struct ioatdma_chan *ioat_chan =to_ioat_chan (c);return sysfs_emit (page,"%d\n" , ioat_chan->intr_coalesce); } -static ssize_t intr_coalesce_store (struct dma_chan *c,const char *page, -size_t count) +static ssize_t intr_coalesce_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) {int intr_coalesce =0 ; + +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; +struct ioatdma_chan *ioat_chan =to_ioat_chan (c);if (sscanf (page,"%du" , &intr_coalesce) !=-1 ) {@@ -153,20 +114,23 @@ size_t count)return count; } +static DEVICE_ATTR_RW (intr_coalesce); -static const struct ioat_sysfs_entry intr_coalesce_attr =__ATTR_RW (intr_coalesce); - -static const struct attribute *const ioat_attrs[] = { - &ring_size_attr.attr, - &ring_active_attr.attr, - &ioat_cap_attr.attr, - &ioat_version_attr.attr, - &intr_coalesce_attr.attr, +static struct attribute *ioat_attrs[] = { + &dev_attr_ring_size.attr, + &dev_attr_ring_active.attr, + &dev_attr_cap.attr, + &dev_attr_version.attr, + &dev_attr_intr_coalesce.attr,NULL , }; -ATTRIBUTE_GROUPS (ioat); -const struct kobj_type ioat_ktype = { - .sysfs_ops = &ioat_sysfs_ops, - .default_groups = ioat_groups, +static const struct attribute_group ioat_attr_group = { + .name ="quickdata" , + .attrs = ioat_attrs, +}; + +const struct attribute_group *ioat_groups[] = { + &ioat_attr_group, +NULL , }; --2.47.3
Logan Gunthorpe
maintainerPATCH v4 3/4 dmaengine: switchtec-dma: add config sysfs attributes
In reply to Logan GunthorpeAdd sysfs configuration options for switchtec-dma channels, using dma_device.chan_groups the same way the ioatdma conversion does:
attach a "switchtec-config" attribute group directly to the channel's existing struct device, with each show()/store() recovering the struct dma_chan via the dmaengine_chan_from_dev CLASS.
The read-modify-write of the shared perf_cfg register is protected by hw_ctrl_lock, and writes are rejected with -EBUSY while the channel is allocated to a client (hw_cfg_locked), instead of a TOCTOU-prone chan->client_count check.
--- drivers/dma/switchtec_dma.c | 179 ++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+)
drivers/dma/switchtec_dma.c +179 -0
@@ -132,6 +132,11 @@ struct switchtec_dma_chan {/* Serialize hardware control register access */ spinlock_t hw_ctrl_lock; +/* +* Set while the channel is allocated to a client; blocks sysfs +* hw config changes +*/ +bool hw_cfg_locked;struct tasklet_struct desc_task;
@@ -1029,6 +1034,10 @@ static int switchtec_dma_alloc_chan_resources(struct dma_chan *chan)dev_dbg (dmaengine_chan_dev (chan),"MRRS: 0x%x\n" ,FIELD_GET (PERF_MRRS_MASK , perf_cfg)); +spin_lock (&swdma_chan->hw_ctrl_lock); + swdma_chan->hw_cfg_locked = true; +spin_unlock (&swdma_chan->hw_ctrl_lock); +return SWITCHTEC_DMA_SQ_SIZE ; err_ring_inactive:
@@ -1046,11 +1055,180 @@ static int switchtec_dma_alloc_chan_resources(struct dma_chan *chan)return rc; } +static __always_inline ssize_t perf_cfg_show(struct device *dev, char *page, +unsigned int mask) +{ +struct switchtec_dma_chan *swdma_chan; +struct chan_fw_regs __iomem *chan_fw; +u32 perf_cfg; +int value; + +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + swdma_chan = container_of(c, struct switchtec_dma_chan, dma_chan); + chan_fw = swdma_chan->mmio_chan_fw; + +rcu_read_lock (); +if (!rcu_dereference (swdma_chan->swdma_dev->pdev)) { +rcu_read_unlock (); +return -ENODEV ; + } + + perf_cfg =readl (&chan_fw->perf_cfg); + value =field_get (mask, perf_cfg); + +rcu_read_unlock (); +return sysfs_emit (page,"0x%x\n" , value); +} + +static __always_inline ssize_t perf_cfg_store(struct device *dev, +const char *page,size_t count, +unsigned int mask) +{ +struct switchtec_dma_chan *swdma_chan; +struct chan_fw_regs __iomem *chan_fw; +ssize_t ret = count; +u32 perf_cfg; +int value; + +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + swdma_chan = container_of(c, struct switchtec_dma_chan, dma_chan); + chan_fw = swdma_chan->mmio_chan_fw; + +if (kstrtoint (page,0 , &value) <0 ) +return -EINVAL ; + +if (value <0 || value >field_max (mask)) +return -EINVAL ; + +rcu_read_lock (); +if (!rcu_dereference (swdma_chan->swdma_dev->pdev)) { + ret = -ENODEV ; + goto err_unlock; + } + +spin_lock (&swdma_chan->hw_ctrl_lock); +if (swdma_chan->hw_cfg_locked) { +spin_unlock (&swdma_chan->hw_ctrl_lock); + ret = -EBUSY ; + goto err_unlock; + } + + perf_cfg =readl (&chan_fw->perf_cfg); + perf_cfg = (perf_cfg & ~mask) |field_prep (mask, value); +writel (perf_cfg, &chan_fw->perf_cfg); +spin_unlock (&swdma_chan->hw_ctrl_lock); + +err_unlock: +rcu_read_unlock (); +return ret; +} + +static ssize_t burst_scale_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return perf_cfg_show (dev, page,PERF_BURST_SCALE_MASK ); +} + +static ssize_t burst_scale_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) +{ +return perf_cfg_store (dev, page, count,PERF_BURST_SCALE_MASK ); +} +static DEVICE_ATTR_RW (burst_scale); + +static ssize_t mrrs_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return perf_cfg_show (dev, page,PERF_MRRS_MASK ); +} + +static ssize_t mrrs_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) +{ +return perf_cfg_store (dev, page, count,PERF_MRRS_MASK ); +} +static DEVICE_ATTR_RW (mrrs); + +static ssize_t interval_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return perf_cfg_show (dev, page,PERF_INTERVAL_MASK ); +} + +static ssize_t interval_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) +{ +return perf_cfg_store (dev, page, count,PERF_INTERVAL_MASK ); +} +static DEVICE_ATTR_RW (interval); + +static ssize_t burst_size_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return perf_cfg_show (dev, page,PERF_BURST_SIZE_MASK ); +} + +static ssize_t burst_size_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) +{ +return perf_cfg_store (dev, page, count,PERF_BURST_SIZE_MASK ); +} +static DEVICE_ATTR_RW (burst_size); + +static ssize_t arb_weight_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return perf_cfg_show (dev, page,PERF_ARB_WEIGHT_MASK ); +} + +static ssize_t arb_weight_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) +{ +return perf_cfg_store (dev, page, count,PERF_ARB_WEIGHT_MASK ); +} +static DEVICE_ATTR_RW (arb_weight); + +static struct attribute *switchtec_config_attrs[] = { + &dev_attr_burst_scale.attr, + &dev_attr_mrrs.attr, + &dev_attr_interval.attr, + &dev_attr_burst_size.attr, + &dev_attr_arb_weight.attr, +NULL , +}; + +static const struct attribute_group switchtec_config_group = { + .name ="switchtec-config" , + .attrs = switchtec_config_attrs, +}; + +static const struct attribute_group *switchtec_groups[] = { + &switchtec_config_group, +NULL , +}; +static void switchtec_dma_free_chan_resources (struct dma_chan *chan) {struct switchtec_dma_chan *swdma_chan = container_of(chan, struct switchtec_dma_chan, dma_chan); +spin_lock (&swdma_chan->hw_ctrl_lock); + swdma_chan->hw_cfg_locked = false; +spin_unlock (&swdma_chan->hw_ctrl_lock); +spin_lock_bh (&swdma_chan->submit_lock); swdma_chan->ring_active = false;spin_unlock_bh (&swdma_chan->submit_lock);
@@ -1313,6 +1491,7 @@ static int switchtec_dma_create(struct pci_dev *pdev) dma->device_terminate_all = switchtec_dma_terminate_all; dma->device_synchronize = switchtec_dma_synchronize; dma->device_release = switchtec_dma_release; + dma->chan_groups = switchtec_groups; rc =dma_async_device_register (dma);if (rc) {
Signature · 1 line
2.47.3
Re: [PATCH v4 3/4] dmaengine: switchtec-dma: add config sysfs attributes
Quoted 6 lines · Logan Gunthorpe
Add sysfs configuration options for switchtec-dma channels, using dma_device.chan_groups the same way the ioatdma conversion does:
attach a "switchtec-config" attribute group directly to the channel's existing struct device, with each show()/store() recovering the structdma_chanvia thedmaengine_chan_from_devCLASS.
Quoted 7 lines
The read-modify-write of the shared
perf_cfgregister is protected byhw_ctrl_lock, and writes are rejected with-EBUSYwhile the channel is allocated to a client (hw_cfg_locked), instead of a TOCTOU-pronechan->client_countcheck.Signed-off-by Logan Gunthorpe <[email protected]>---
Quoted 222 lines
drivers/dma/switchtec_dma.c | 179 ++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+)drivers/dma/switchtec_dma.c +179
-1@@ -132,6 +132,11 @@ struct switchtec_dma_chan {/* Serialize hardware control register access */ spinlock_t hw_ctrl_lock; +/* +* Set while the channel is allocated to a client; blocks sysfs +* hw config changes +*/ +bool hw_cfg_locked;struct tasklet_struct desc_task;@@ -1029,6 +1034,10 @@ static int switchtec_dma_alloc_chan_resources(struct dma_chan *chan)dev_dbg (dmaengine_chan_dev (chan),"MRRS: 0x%x\n" ,FIELD_GET (PERF_MRRS_MASK , perf_cfg)); +spin_lock (&swdma_chan->hw_ctrl_lock); + swdma_chan->hw_cfg_locked = true; +spin_unlock (&swdma_chan->hw_ctrl_lock); +return SWITCHTEC_DMA_SQ_SIZE ; err_ring_inactive:@@ -1046,11 +1055,180 @@ static int switchtec_dma_alloc_chan_resources(struct dma_chan *chan)return rc; } +static __always_inline ssize_t perf_cfg_show(struct device *dev, char *page, +unsigned int mask) +{ +struct switchtec_dma_chan *swdma_chan; +struct chan_fw_regs __iomem *chan_fw; +u32 perf_cfg; +int value; + +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + swdma_chan = container_of(c, struct switchtec_dma_chan, dma_chan); + chan_fw = swdma_chan->mmio_chan_fw; + +rcu_read_lock (); +if (!rcu_dereference (swdma_chan->swdma_dev->pdev)) { +rcu_read_unlock (); +return -ENODEV ; + } + + perf_cfg =readl (&chan_fw->perf_cfg); + value =field_get (mask, perf_cfg); + +rcu_read_unlock (); +return sysfs_emit (page,"0x%x\n" , value); +} + +static __always_inline ssize_t perf_cfg_store(struct device *dev, +const char *page,size_t count, +unsigned int mask) +{ +struct switchtec_dma_chan *swdma_chan; +struct chan_fw_regs __iomem *chan_fw; +ssize_t ret = count; +u32 perf_cfg; +int value; + +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + swdma_chan = container_of(c, struct switchtec_dma_chan, dma_chan); + chan_fw = swdma_chan->mmio_chan_fw; + +if (kstrtoint (page,0 , &value) <0 ) +return -EINVAL ; + +if (value <0 || value >field_max (mask)) +return -EINVAL ; + +rcu_read_lock (); +if (!rcu_dereference (swdma_chan->swdma_dev->pdev)) { + ret = -ENODEV ; + goto err_unlock; + } + +spin_lock (&swdma_chan->hw_ctrl_lock); +if (swdma_chan->hw_cfg_locked) { +spin_unlock (&swdma_chan->hw_ctrl_lock); + ret = -EBUSY ; + goto err_unlock; + } + + perf_cfg =readl (&chan_fw->perf_cfg); + perf_cfg = (perf_cfg & ~mask) |field_prep (mask, value); +writel (perf_cfg, &chan_fw->perf_cfg); +spin_unlock (&swdma_chan->hw_ctrl_lock); + +err_unlock: +rcu_read_unlock (); +return ret; +} + +static ssize_t burst_scale_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return perf_cfg_show (dev, page,PERF_BURST_SCALE_MASK ); +} + +static ssize_t burst_scale_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) +{ +return perf_cfg_store (dev, page, count,PERF_BURST_SCALE_MASK ); +} +static DEVICE_ATTR_RW (burst_scale); + +static ssize_t mrrs_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return perf_cfg_show (dev, page,PERF_MRRS_MASK ); +} + +static ssize_t mrrs_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) +{ +return perf_cfg_store (dev, page, count,PERF_MRRS_MASK ); +} +static DEVICE_ATTR_RW (mrrs); + +static ssize_t interval_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return perf_cfg_show (dev, page,PERF_INTERVAL_MASK ); +} + +static ssize_t interval_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) +{ +return perf_cfg_store (dev, page, count,PERF_INTERVAL_MASK ); +} +static DEVICE_ATTR_RW (interval); + +static ssize_t burst_size_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return perf_cfg_show (dev, page,PERF_BURST_SIZE_MASK ); +} + +static ssize_t burst_size_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) +{ +return perf_cfg_store (dev, page, count,PERF_BURST_SIZE_MASK ); +} +static DEVICE_ATTR_RW (burst_size); + +static ssize_t arb_weight_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return perf_cfg_show (dev, page,PERF_ARB_WEIGHT_MASK ); +} + +static ssize_t arb_weight_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) +{ +return perf_cfg_store (dev, page, count,PERF_ARB_WEIGHT_MASK ); +} +static DEVICE_ATTR_RW (arb_weight); + +static struct attribute *switchtec_config_attrs[] = { + &dev_attr_burst_scale.attr, + &dev_attr_mrrs.attr, + &dev_attr_interval.attr, + &dev_attr_burst_size.attr, + &dev_attr_arb_weight.attr, +NULL , +}; + +static const struct attribute_group switchtec_config_group = { + .name ="switchtec-config" , + .attrs = switchtec_config_attrs, +}; + +static const struct attribute_group *switchtec_groups[] = { + &switchtec_config_group, +NULL , +}; +static void switchtec_dma_free_chan_resources (struct dma_chan *chan) {struct switchtec_dma_chan *swdma_chan = container_of(chan, struct switchtec_dma_chan, dma_chan); +spin_lock (&swdma_chan->hw_ctrl_lock); + swdma_chan->hw_cfg_locked = false; +spin_unlock (&swdma_chan->hw_ctrl_lock); +spin_lock_bh (&swdma_chan->submit_lock); swdma_chan->ring_active = false;spin_unlock_bh (&swdma_chan->submit_lock);@@ -1313,6 +1491,7 @@ static int switchtec_dma_create(struct pci_dev *pdev) dma->device_terminate_all = switchtec_dma_terminate_all; dma->device_synchronize = switchtec_dma_synchronize; dma->device_release = switchtec_dma_release; + dma->chan_groups = switchtec_groups; rc =dma_async_device_register (dma);if (rc) { --2.47.3
Logan Gunthorpe
maintainerPATCH v4 4/4 dmaengine: switchtec-dma: add pmon sysfs attributes
In reply to Logan GunthorpeSwitchtec hardware exposes some performance monitor registers which can be used to monitor various statistics of the hardware.
Expose these as a "switchtec-pmon" sysfs attribute group, alongside the "switchtec-config" group added previously.
The various registers are read through a small shared pmon_show() helper parameterized by a reader function pointer, rather than a macro, to avoid generating the whole read + rcu_read_lock/unlock + sysfs_emit sequence per attribute.
--- drivers/dma/switchtec_dma.c | 273 ++++++++++++++++++++++++++++++++++++ 1 file changed, 273 insertions(+)
drivers/dma/switchtec_dma.c +273 -0
@@ -12,6 +12,7 @@#include <linux/pci.h> #include <linux/delay.h> #include <linux/iopoll.h> +#include <linux/io-64-nonatomic-lo-hi.h> #include "dmaengine.h"
@@ -91,6 +92,12 @@ struct chan_hw_regs {#define SE_BUF_LEN_MASK GENMASK_U32(20, 12)#define SE_THRESH_MASK GENMASK_U32(31, 23) +#define SWITCHTEC_LAT_SE_FETCH BIT(0) +#define SWITCHTEC_LAT_VDM BIT(1) +#define SWITCHTEC_LAT_RD_IMM BIT(2) +#define SWITCHTEC_LAT_FW_NP BIT(3) +#define SWITCHTEC_LAT_SE_PROCESS BIT(4) +#define SWITCHTEC_CHAN_ENABLE BIT(1)struct chan_fw_regs {
@@ -1215,8 +1222,274 @@ static const struct attribute_group switchtec_config_group = { .attrs = switchtec_config_attrs, }; +static ssize_t pmon_show (struct device *dev,char *page, +u64 (*reader)(struct chan_fw_regs __iomem *chan_fw)) +{ +struct switchtec_dma_chan *swdma_chan; +u64 val; + +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + swdma_chan = container_of(c, struct switchtec_dma_chan, dma_chan); + +rcu_read_lock (); +if (!rcu_dereference (swdma_chan->swdma_dev->pdev)) { +rcu_read_unlock (); +return -ENODEV ; + } + + val =reader (swdma_chan->mmio_chan_fw); +rcu_read_unlock (); + +return sysfs_emit (page,"0x%llx\n" , val); +} + +static u64 read_se_count (struct chan_fw_regs __iomem *chan_fw) +{ +return lo_hi_readq (&chan_fw->perf_fetched_se_cnt_lo); +} + +static ssize_t se_count_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_se_count); +} +static DEVICE_ATTR_RO (se_count); + +static u64 read_byte_count (struct chan_fw_regs __iomem *chan_fw) +{ +return lo_hi_readq (&chan_fw->perf_byte_cnt_lo); +} + +static ssize_t byte_count_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_byte_count); +} +static DEVICE_ATTR_RO (byte_count); + +static u64 read_se_pending (struct chan_fw_regs __iomem *chan_fw) +{ +return readw (&chan_fw->perf_se_pending); +} + +static ssize_t se_pending_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_se_pending); +} +static DEVICE_ATTR_RO (se_pending); + +static u64 read_se_buf_empty (struct chan_fw_regs __iomem *chan_fw) +{ +return readw (&chan_fw->perf_se_buf_empty); +} + +static ssize_t se_buf_empty_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_se_buf_empty); +} +static DEVICE_ATTR_RO (se_buf_empty); + +static u64 read_chan_idle (struct chan_fw_regs __iomem *chan_fw) +{ +return readl (&chan_fw->perf_chan_idle); +} + +static ssize_t chan_idle_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_chan_idle); +} +static DEVICE_ATTR_RO (chan_idle); + +static u64 read_latency_max (struct chan_fw_regs __iomem *chan_fw) +{ +return readl (&chan_fw->perf_lat_max); +} + +static ssize_t latency_max_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_latency_max); +} +static DEVICE_ATTR_RO (latency_max); + +static u64 read_latency_min (struct chan_fw_regs __iomem *chan_fw) +{ +return readl (&chan_fw->perf_lat_min); +} + +static ssize_t latency_min_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_latency_min); +} +static DEVICE_ATTR_RO (latency_min); + +static u64 read_latency_last (struct chan_fw_regs __iomem *chan_fw) +{ +return readl (&chan_fw->perf_lat_last); +} + +static ssize_t latency_last_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_latency_last); +} +static DEVICE_ATTR_RO (latency_last); + +static ssize_t latency_selector_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +struct switchtec_dma_chan *swdma_chan; +struct chan_fw_regs __iomem *chan_fw; +u32 lat =0 ; +int len; + +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + swdma_chan = container_of(c, struct switchtec_dma_chan, dma_chan); + chan_fw = swdma_chan->mmio_chan_fw; + +rcu_read_lock (); +if (!rcu_dereference (swdma_chan->swdma_dev->pdev)) { +rcu_read_unlock (); +return -ENODEV ; + } + + lat =readl (&chan_fw->perf_latency_selector); +rcu_read_unlock (); + + len =sysfs_emit (page, +"To select a latency type, write the type number\n" ); + len +=sysfs_emit_at (page, len,"(1 ~ 5) to latency_selector\n\n" ); + + len +=sysfs_emit_at (page, len,"Latency Types:\n" ); + len +=sysfs_emit_at (page, len,"(1) SE Fetch latency" ); +if (lat &SWITCHTEC_LAT_SE_FETCH ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + + len +=sysfs_emit_at (page, len,"(2) VDM latency" ); +if (lat &SWITCHTEC_LAT_VDM ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + + len +=sysfs_emit_at (page, len,"(3) Read Immediate latency" ); +if (lat &SWITCHTEC_LAT_RD_IMM ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + + len +=sysfs_emit_at (page, len,"(4) SE Processing latency" ); +if (lat &SWITCHTEC_LAT_SE_PROCESS ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + + len +=sysfs_emit_at (page, len,"(5) FW NP TLP latency" ); +if (lat &SWITCHTEC_LAT_FW_NP ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + +return len; +} + +static ssize_t latency_selector_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) +{ +struct switchtec_dma_chan *swdma_chan; +struct chan_fw_regs __iomem *chan_fw; +ssize_t ret = count; +int lat_type; + +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + swdma_chan = container_of(c, struct switchtec_dma_chan, dma_chan); + chan_fw = swdma_chan->mmio_chan_fw; + +if (kstrtoint (page,0 , &lat_type) <0 ) +return -EINVAL ; + +switch (lat_type) { +case 1 : + lat_type =SWITCHTEC_LAT_SE_FETCH ; +break ; +case 2 : + lat_type =SWITCHTEC_LAT_VDM ; +break ; +case 3 : + lat_type =SWITCHTEC_LAT_RD_IMM ; +break ; +case 4 : + lat_type =SWITCHTEC_LAT_SE_PROCESS ; +break ; +case 5 : + lat_type =SWITCHTEC_LAT_FW_NP ; +break ; +default : +return -EINVAL ; + } + +rcu_read_lock (); +if (!rcu_dereference (swdma_chan->swdma_dev->pdev)) { + ret = -ENODEV ; + goto err_unlock; + } + +spin_lock (&swdma_chan->hw_ctrl_lock); +if (swdma_chan->hw_cfg_locked) { +spin_unlock (&swdma_chan->hw_ctrl_lock); + ret = -EBUSY ; + goto err_unlock; + } + +writel (lat_type, &chan_fw->perf_latency_selector); +spin_unlock (&swdma_chan->hw_ctrl_lock); + +err_unlock: +rcu_read_unlock (); + +return ret; +} +static DEVICE_ATTR_RW (latency_selector); + +static struct attribute *switchtec_pmon_attrs[] = { + &dev_attr_se_count.attr, + &dev_attr_byte_count.attr, + &dev_attr_se_pending.attr, + &dev_attr_se_buf_empty.attr, + &dev_attr_chan_idle.attr, + &dev_attr_latency_max.attr, + &dev_attr_latency_min.attr, + &dev_attr_latency_last.attr, + &dev_attr_latency_selector.attr, +NULL , +}; + +static const struct attribute_group switchtec_pmon_group = { + .name ="switchtec-pmon" , + .attrs = switchtec_pmon_attrs, +}; +static const struct attribute_group *switchtec_groups[] = { &switchtec_config_group, + &switchtec_pmon_group,NULL , };
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v4 4/4] dmaengine: switchtec-dma: add pmon sysfs attributes
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] dmaengine: switchtec-dma: multi-line menu output in latency_selector_show() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] dmaengine: switchtec-dma: multi-line menu output in latency_selector_show()
--
commit a610541f39faa290edb39d9134f3a2df55bdae1a
Author: Logan Gunthorpe <[email protected]>
dmaengine: switchtec-dma: add pmon sysfs attributes
This commit adds a "switchtec-pmon" sysfs attribute group to expose Switchtec DMA performance monitoring registers per channel.
Quoted 4 lines
drivers/dma/switchtec_dma.c +0
-0
[ ... ]
Quoted 4 lines
drivers/dma/switchtec_dma.c +0
-0@@ -1215,8 +1222,274 @@ static const struct attribute_group switchtec_config_group = { .attrs = switchtec_config_attrs, };
[ ... ]
Quoted 52 lines
drivers/dma/switchtec_dma.c +52
-0+static ssize_t latency_selector_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +struct switchtec_dma_chan *swdma_chan; +struct chan_fw_regs __iomem *chan_fw; +u32 lat =0 ; +int len; + +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + swdma_chan = container_of(c, struct switchtec_dma_chan, dma_chan); + chan_fw = swdma_chan->mmio_chan_fw; + +rcu_read_lock (); +if (!rcu_dereference (swdma_chan->swdma_dev->pdev)) { +rcu_read_unlock (); +return -ENODEV ; + } + + lat =readl (&chan_fw->perf_latency_selector); +rcu_read_unlock (); + + len =sysfs_emit (page, +"To select a latency type, write the type number\n" ); + len +=sysfs_emit_at (page, len,"(1 ~ 5) to latency_selector\n\n" ); + + len +=sysfs_emit_at (page, len,"Latency Types:\n" ); + len +=sysfs_emit_at (page, len,"(1) SE Fetch latency" ); +if (lat &SWITCHTEC_LAT_SE_FETCH ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + + len +=sysfs_emit_at (page, len,"(2) VDM latency" ); +if (lat &SWITCHTEC_LAT_VDM ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + + len +=sysfs_emit_at (page, len,"(3) Read Immediate latency" ); +if (lat &SWITCHTEC_LAT_RD_IMM ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + + len +=sysfs_emit_at (page, len,"(4) SE Processing latency" ); +if (lat &SWITCHTEC_LAT_SE_PROCESS ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else
drivers/dma/switchtec_dma.c static const struct attribute_group switchtec_config_group = { · line 1407
Quoted 10 lines
drivers/dma/switchtec_dma.c +10
-0+ len +=sysfs_emit_at (page, len,"\n" ); + + len +=sysfs_emit_at (page, len,"(5) FW NP TLP latency" ); +if (lat &SWITCHTEC_LAT_FW_NP ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + +return len; +}
[Severity: Low]
Does latency_selector_show() violate the sysfs one-value-per-file rule?
Reading latency_selector emits multi-line usage instructions and a numbered menu marked with "(*)", while latency_selector_store() expects a single integer from 1 to 5 via kstrtoint(), so the output cannot be parsed as a single value or written back to the attribute. Could latency_selector expose a single value (or a single-line space-separated list of tokens with brackets around the active selection, documented under Documentation/ABI/), or move human-oriented menus to debugfs?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Logan Gunthorpe
maintainerRe: [PATCH v4 4/4] dmaengine: switchtec-dma: add pmon sysfs attributes
Quoted 2 lines · On 2026-11-10 11:47, [email protected] wrote:
[Severity: Low]
Doeslatency_selector_show()violate the sysfs one-value-per-file rule?
Strictly speaking yes, but we think the text printed is self-documentation that's worth having here. If others feel strongly against this we can revisit it.
Logan
Re: [PATCH v4 4/4] dmaengine: switchtec-dma: add pmon sysfs attributes
In reply to Logan GunthorpeQuoted 6 lines · Logan Gunthorpe
Switchtec hardware exposes some performance monitor registers which can be used to monitor various statistics of the hardware.
Expose these as a "switchtec-pmon" sysfs attribute group, alongside the "switchtec-config" group added previously.
Quoted 7 lines
The various registers are read through a small shared
pmon_show()helper parameterized by a reader function pointer, rather than a macro, to avoid generating the whole read + rcu_read_lock/unlock +sysfs_emitsequence per attribute.Signed-off-by Logan Gunthorpe <[email protected]>---
Quoted 306 lines
drivers/dma/switchtec_dma.c | 273 ++++++++++++++++++++++++++++++++++++ 1 file changed, 273 insertions(+)drivers/dma/switchtec_dma.c +273
-1@@ -12,6 +12,7 @@#include <linux/pci.h> #include <linux/delay.h> #include <linux/iopoll.h> +#include <linux/io-64-nonatomic-lo-hi.h> #include "dmaengine.h" @@ -91,6 +92,12 @@ struct chan_hw_regs {#define SE_BUF_LEN_MASK GENMASK_U32(20, 12)#define SE_THRESH_MASK GENMASK_U32(31, 23) +#define SWITCHTEC_LAT_SE_FETCH BIT(0) +#define SWITCHTEC_LAT_VDM BIT(1) +#define SWITCHTEC_LAT_RD_IMM BIT(2) +#define SWITCHTEC_LAT_FW_NP BIT(3) +#define SWITCHTEC_LAT_SE_PROCESS BIT(4) +#define SWITCHTEC_CHAN_ENABLE BIT(1)struct chan_fw_regs {@@ -1215,8 +1222,274 @@ static const struct attribute_group switchtec_config_group = { .attrs = switchtec_config_attrs, }; +static ssize_t pmon_show (struct device *dev,char *page, +u64 (*reader)(struct chan_fw_regs __iomem *chan_fw)) +{ +struct switchtec_dma_chan *swdma_chan; +u64 val; + +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + swdma_chan = container_of(c, struct switchtec_dma_chan, dma_chan); + +rcu_read_lock (); +if (!rcu_dereference (swdma_chan->swdma_dev->pdev)) { +rcu_read_unlock (); +return -ENODEV ; + } + + val =reader (swdma_chan->mmio_chan_fw); +rcu_read_unlock (); + +return sysfs_emit (page,"0x%llx\n" , val); +} + +static u64 read_se_count (struct chan_fw_regs __iomem *chan_fw) +{ +return lo_hi_readq (&chan_fw->perf_fetched_se_cnt_lo); +} + +static ssize_t se_count_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_se_count); +} +static DEVICE_ATTR_RO (se_count); + +static u64 read_byte_count (struct chan_fw_regs __iomem *chan_fw) +{ +return lo_hi_readq (&chan_fw->perf_byte_cnt_lo); +} + +static ssize_t byte_count_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_byte_count); +} +static DEVICE_ATTR_RO (byte_count); + +static u64 read_se_pending (struct chan_fw_regs __iomem *chan_fw) +{ +return readw (&chan_fw->perf_se_pending); +} + +static ssize_t se_pending_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_se_pending); +} +static DEVICE_ATTR_RO (se_pending); + +static u64 read_se_buf_empty (struct chan_fw_regs __iomem *chan_fw) +{ +return readw (&chan_fw->perf_se_buf_empty); +} + +static ssize_t se_buf_empty_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_se_buf_empty); +} +static DEVICE_ATTR_RO (se_buf_empty); + +static u64 read_chan_idle (struct chan_fw_regs __iomem *chan_fw) +{ +return readl (&chan_fw->perf_chan_idle); +} + +static ssize_t chan_idle_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_chan_idle); +} +static DEVICE_ATTR_RO (chan_idle); + +static u64 read_latency_max (struct chan_fw_regs __iomem *chan_fw) +{ +return readl (&chan_fw->perf_lat_max); +} + +static ssize_t latency_max_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_latency_max); +} +static DEVICE_ATTR_RO (latency_max); + +static u64 read_latency_min (struct chan_fw_regs __iomem *chan_fw) +{ +return readl (&chan_fw->perf_lat_min); +} + +static ssize_t latency_min_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_latency_min); +} +static DEVICE_ATTR_RO (latency_min); + +static u64 read_latency_last (struct chan_fw_regs __iomem *chan_fw) +{ +return readl (&chan_fw->perf_lat_last); +} + +static ssize_t latency_last_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +return pmon_show (dev, page, read_latency_last); +} +static DEVICE_ATTR_RO (latency_last); + +static ssize_t latency_selector_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +struct switchtec_dma_chan *swdma_chan; +struct chan_fw_regs __iomem *chan_fw; +u32 lat =0 ; +int len; + +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + swdma_chan = container_of(c, struct switchtec_dma_chan, dma_chan); + chan_fw = swdma_chan->mmio_chan_fw; + +rcu_read_lock (); +if (!rcu_dereference (swdma_chan->swdma_dev->pdev)) { +rcu_read_unlock (); +return -ENODEV ; + } + + lat =readl (&chan_fw->perf_latency_selector); +rcu_read_unlock (); + + len =sysfs_emit (page, +"To select a latency type, write the type number\n" ); + len +=sysfs_emit_at (page, len,"(1 ~ 5) to latency_selector\n\n" ); + + len +=sysfs_emit_at (page, len,"Latency Types:\n" ); + len +=sysfs_emit_at (page, len,"(1) SE Fetch latency" ); +if (lat &SWITCHTEC_LAT_SE_FETCH ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + + len +=sysfs_emit_at (page, len,"(2) VDM latency" ); +if (lat &SWITCHTEC_LAT_VDM ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + + len +=sysfs_emit_at (page, len,"(3) Read Immediate latency" ); +if (lat &SWITCHTEC_LAT_RD_IMM ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + + len +=sysfs_emit_at (page, len,"(4) SE Processing latency" ); +if (lat &SWITCHTEC_LAT_SE_PROCESS ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + + len +=sysfs_emit_at (page, len,"(5) FW NP TLP latency" ); +if (lat &SWITCHTEC_LAT_FW_NP ) + len +=sysfs_emit_at (page, len," (*)\n" ); +else + len +=sysfs_emit_at (page, len,"\n" ); + +return len; +} + +static ssize_t latency_selector_store (struct device *dev, +struct device_attribute *attr, +const char *page,size_t count) +{ +struct switchtec_dma_chan *swdma_chan; +struct chan_fw_regs __iomem *chan_fw; +ssize_t ret = count; +int lat_type; + +CLASS (dmaengine_chan_from_dev, c)(dev); + +if (!c) +return -ENODEV ; + + swdma_chan = container_of(c, struct switchtec_dma_chan, dma_chan); + chan_fw = swdma_chan->mmio_chan_fw; + +if (kstrtoint (page,0 , &lat_type) <0 ) +return -EINVAL ; + +switch (lat_type) { +case 1 : + lat_type =SWITCHTEC_LAT_SE_FETCH ; +break ; +case 2 : + lat_type =SWITCHTEC_LAT_VDM ; +break ; +case 3 : + lat_type =SWITCHTEC_LAT_RD_IMM ; +break ; +case 4 : + lat_type =SWITCHTEC_LAT_SE_PROCESS ; +break ; +case 5 : + lat_type =SWITCHTEC_LAT_FW_NP ; +break ; +default : +return -EINVAL ; + } + +rcu_read_lock (); +if (!rcu_dereference (swdma_chan->swdma_dev->pdev)) { + ret = -ENODEV ; + goto err_unlock; + } + +spin_lock (&swdma_chan->hw_ctrl_lock); +if (swdma_chan->hw_cfg_locked) { +spin_unlock (&swdma_chan->hw_ctrl_lock); + ret = -EBUSY ; + goto err_unlock; + } + +writel (lat_type, &chan_fw->perf_latency_selector); +spin_unlock (&swdma_chan->hw_ctrl_lock); + +err_unlock: +rcu_read_unlock (); + +return ret; +} +static DEVICE_ATTR_RW (latency_selector); + +static struct attribute *switchtec_pmon_attrs[] = { + &dev_attr_se_count.attr, + &dev_attr_byte_count.attr, + &dev_attr_se_pending.attr, + &dev_attr_se_buf_empty.attr, + &dev_attr_chan_idle.attr, + &dev_attr_latency_max.attr, + &dev_attr_latency_min.attr, + &dev_attr_latency_last.attr, + &dev_attr_latency_selector.attr, +NULL , +}; + +static const struct attribute_group switchtec_pmon_group = { + .name ="switchtec-pmon" , + .attrs = switchtec_pmon_attrs, +}; +static const struct attribute_group *switchtec_groups[] = { &switchtec_config_group, + &switchtec_pmon_group,NULL , }; --2.47.3