Add sysfs interface to switchtec-dma
Subsystems (2)
Logan Gunthorpe
maintainerv5 cover Add sysfs interface to switchtec-dma
This is just a resend with Frank's Reviewd-by tags collected on all the patches. I'm hoping this can be picked up for v7.5.
This patch set is based (cleanly) on v7.4-rc4.
Logan
[v4] https://lore.kernel.org/all/[email protected]
--
Changes since v4:
- Added Frank Li's Reviewed-by tags (covers all patches)
- Rebased on v7.4-rc4
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: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f --
2.47.3
Logan Gunthorpe
maintainerPATCH v5 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
Logan Gunthorpe
maintainerPATCH v5 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
Logan Gunthorpe
maintainerPATCH v5 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
Logan Gunthorpe
maintainerPATCH v5 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 v5 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 88f647b9334dbbed040eb8ea50d2882f9874a0c9
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 monitor registers per channel.
Quoted 4 lines
drivers/dma/switchtec_dma.c +0
-0
[ ... ]
Quoted 3 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 3 lines
drivers/dma/switchtec_dma.c +3
-0+static ssize_t latency_selector_show (struct device *dev, +struct device_attribute *attr,char *page) +{
[ ... ]
Quoted 42 lines
drivers/dma/switchtec_dma.c +42
-0+ 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) +{
[ ... ]
drivers/dma/switchtec_dma.c
Quoted 2 lines
drivers/dma/switchtec_dma.c +2
-0+if (kstrtoint (page,0 , &lat_type) <0 ) +return -EINVAL ;
[Severity: Low]
Does latency_selector_show() violate the sysfs one-value-per-file rule in Documentation/filesystems/sysfs.rst?
Reading latency_selector emits multi-line usage instructions and a numbered menu marking the active bit with "(*)", whereas latency_selector_store() parses a single integer from 1 to 5 via kstrtoint(), so the attribute's output cannot be parsed as a single value or written back to the file. 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 the human-formatted menu to debugfs?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v5 4/4] dmaengine: switchtec-dma: add pmon sysfs attributes
Quoted 77 lines · On Tue, Nov 24, 2026 at 03:59:03PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] dmaengine: switchtec-dma: multi-line menu output inlatency_selector_show()
--commit
88f647b9334dbbed040eb8ea50d2882f9874a0c9
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 monitor registers per channel.
Quoted 4 lines
drivers/dma/switchtec_dma.c +0
-0[ ... ]
Quoted 3 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 3 lines
drivers/dma/switchtec_dma.c +3
-0+static ssize_t latency_selector_show (struct device *dev, +struct device_attribute *attr,char *page) +{[ ... ]
Quoted 42 lines
drivers/dma/switchtec_dma.c +42
-0+ 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) +{[ ... ]
drivers/dma/switchtec_dma.c
Quoted 2 lines
drivers/dma/switchtec_dma.c +2
-0+if (kstrtoint (page,0 , &lat_type) <0 ) +return -EINVAL ;[Severity: Low]
Doeslatency_selector_show()violate the sysfs one-value-per-file rule inDocumentation/filesystems/sysfs.rst?
Quoted 8 lines
Reading
latency_selectoremits multi-line usage instructions and a numbered menu marking the active bit with "(*)", whereaslatency_selector_store()parses a single integer from 1 to 5 viakstrtoint(), so the attribute's output cannot be parsed as a single value or written back to the file. Couldlatency_selectorexpose a single value (or a single-line space-separated list of tokens with brackets around the active selection, documented underDocumentation/ABI/), or move the human-formatted menu to debugfs?
Yes, this is one problem, which need be addressed. the sysfs one-value-per-file rule
Frank
Quoted 3 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Logan Gunthorpe
maintainerRe: [PATCH v5 4/4] dmaengine: switchtec-dma: add pmon sysfs attributes
Quoted 87 lines · Frank Li
Quoted 77 lines · On Tue, Nov 24, 2026 at 03:59:03PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] dmaengine: switchtec-dma: multi-line menu output inlatency_selector_show()
--commit
88f647b9334dbbed040eb8ea50d2882f9874a0c9
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 monitor registers per channel.
Quoted 4 lines
drivers/dma/switchtec_dma.c +0
-0[ ... ]
Quoted 3 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 3 lines
drivers/dma/switchtec_dma.c +3
-0+static ssize_t latency_selector_show (struct device *dev, +struct device_attribute *attr,char *page) +{[ ... ]
Quoted 42 lines
drivers/dma/switchtec_dma.c +42
-0+ 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) +{[ ... ]
drivers/dma/switchtec_dma.c
Quoted 2 lines
drivers/dma/switchtec_dma.c +2
-0+if (kstrtoint (page,0 , &lat_type) <0 ) +return -EINVAL ;[Severity: Low]
Doeslatency_selector_show()violate the sysfs one-value-per-file rule inDocumentation/filesystems/sysfs.rst?Quoted 8 lines
Reading
latency_selectoremits multi-line usage instructions and a numbered menu marking the active bit with "(*)", whereaslatency_selector_store()parses a single integer from 1 to 5 viakstrtoint(), so the attribute's output cannot be parsed as a single value or written back to the file. Couldlatency_selectorexpose a single value (or a single-line space-separated list of tokens with brackets around the active selection, documented underDocumentation/ABI/), or move the human-formatted menu to debugfs?
Quoted 2 lines
Yes, this is one problem, which need be addressed. the sysfs one-value-per-file rule
I responded to this in v4[1].
We were really hoping to skirt that rule seeing we view the self documenting feature of the field worth having. If you really want to push this issue please let us know so we can create a new version promptly. I'd really like to get this merged this cycle.
Thanks,
Logan
Re: [PATCH v5 4/4] dmaengine: switchtec-dma: add pmon sysfs attributes
Quoted 90 lines · Logan Gunthorpe
Quoted 87 lines · Frank Li
Quoted 85 lines · On Tue, Nov 24, 2026 at 03:59:03PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] dmaengine: switchtec-dma: multi-line menu output inlatency_selector_show()
--commit
88f647b9334dbbed040eb8ea50d2882f9874a0c9
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 monitor registers per channel.
Quoted 4 lines
drivers/dma/switchtec_dma.c +0
-0[ ... ]
Quoted 3 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 3 lines
drivers/dma/switchtec_dma.c +3
-0+static ssize_t latency_selector_show (struct device *dev, +struct device_attribute *attr,char *page) +{[ ... ]
Quoted 42 lines
drivers/dma/switchtec_dma.c +42
-0+ 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) +{[ ... ]
drivers/dma/switchtec_dma.c
Quoted 2 lines
drivers/dma/switchtec_dma.c +2
-0+if (kstrtoint (page,0 , &lat_type) <0 ) +return -EINVAL ;[Severity: Low]
Doeslatency_selector_show()violate the sysfs one-value-per-file rule inDocumentation/filesystems/sysfs.rst?Reading
latency_selectoremits multi-line usage instructions and a numbered menu marking the active bit with "(*)", whereaslatency_selector_store()parses a single integer from 1 to 5 viakstrtoint(), so the attribute's output cannot be parsed as a single value or written back to the file. Couldlatency_selectorexpose a single value (or a single-line space-separated list of tokens with brackets around the active selection, documented underDocumentation/ABI/), or move the human-formatted menu to debugfs?
Quoted 8 lines
Quoted 2 lines
Yes, this is one problem, which need be addressed. the sysfs one-value-per-file rule
I responded to this in v4[1].
We were really hoping to skirt that rule seeing we view the self documenting feature of the field worth having. If you really want to push this issue please let us know so we can create a new version promptly. I'd really like to get this merged this cycle.
I don't think it is critical now and marked at patchwork to wait for vinod to pick.
sys interface is ABI. It may become difficult to change it in future. I suggest consider it to debugfs or follow sysfs rule during wait for vinod.
Frank
Quoted 8 lines
Thanks,
Logan