fsi: aspeed: Fix unaligned raw accesses, OPB0 byte order registers
Subsystems (3)
v2 cover fsi: aspeed: Fix unaligned raw accesses, OPB0 byte order registers
Hello,
v2 pulls in a reworked OPB0 data byte order configuration patch in 1/3, superseeding those posted previously. It also fixes and optimises the unaligned data access width calculation as mentioned in [1] in patch 3/3.
[1] https://patchwork.ozlabs.org/patch/1187178/
The series is based on top of https://patchwork.ozlabs.org/cover/1187185/ with the original byte order configuration patch reverted to accommodate the rework.
Please review.
Andrew
Andrew Jeffery (3):
fsi: aspeed: Fix OPB0 byte order register values
trace: fsi: Print transfer size unsigned
fsi: core: Fix small accesses and unaligned offsets via sysfs
drivers/fsi/fsi-core.c | 31 +++++++++++++++++++++++++++---- drivers/fsi/fsi-master-aspeed.c | 6 +++--- include/trace/events/fsi.h | 6 +++--- 3 files changed, 33 insertions(+), 10 deletions(-)
Signature · 1 line
2.20.1
PATCH v2 1/3 fsi: aspeed: Fix OPB0 byte order register values
The data byte order selection registers in the APB2OPB primarily expose some internal plumbing necessary to get correct write accesses onto the OPB. OPB write cycles require "data mirroring" across the 32-bit data bus to support variable data width slaves that don't implement "byte enables". For slaves that do implement byte enables the master can signal which bytes on the data bus the slave should consider valid.
The data mirroring behaviour is specified by the following table:
+-----------------+----------+-----------------------------------+
| | | 32-bit Data Bus |
+---------+-------+----------+---------+---------+-------+-------+
| | | | | | | |
| ABus | Mn_BE | Request | Dbus | Dbus | Dbus | Dbus |
| (30:31) | (0:3) | Transfer | 0:7 | 8:15 | 16:23 | 24:31 |
| | | Size | byte0 | byte1 | byte2 | byte3 |
+---------+-------+----------+---------+---------+-------+-------+
| 00 | 1111 | fullword | byte0 | byte1 | byte2 | byte3 |
+---------+-------+----------+---------+---------+-------+-------+
| 00 | 1110 | halfword | byte0 | byte1 | byte2 | |
+---------+-------+----------+---------+---------+-------+-------+
| 01 | 0111 | byte | _byte1_ | byte1 | byte2 | byte3 |
+---------+-------+----------+---------+---------+-------+-------+
| 00 | 1100 | halfword | byte0 | byte1 | | |
+---------+-------+----------+---------+---------+-------+-------+
| 01 | 0110 | byte | _byte1_ | byte1 | byte2 | |
+---------+-------+----------+---------+---------+-------+-------+
| 10 | 0011 | halfword | _byte2_ | _byte3_ | byte2 | byte3 |
+---------+-------+----------+---------+---------+-------+-------+
| 00 | 1000 | byte | byte0 | | | |
+---------+-------+----------+---------+---------+-------+-------+
| 01 | 0100 | byte | _byte1_ | byte1 | | |
+---------+-------+----------+---------+---------+-------+-------+
| 10 | 0010 | byte | _byte2_ | | byte2 | |
+---------+-------+----------+---------+---------+-------+-------+
| 11 | 0001 | byte | _byte3_ | _byte3_ | | byte3 |
+---------+-------+----------+---------+---------+-------+-------+Mirrored data values are highlighted by underscores in the Dbus columns. The values in the ABus and Request Transfer Size columns correspond to values in the field names listed in the write data order select register descriptions.
Similar configuration registers are exposed for reads which enables the secondary purpose of configuring hardware endian conversions. It appears the data bus byte order is switched around in hardware so set the registers such that we can access the correct values for all widths. The values were determined by experimentation on hardware against fixed CFAM register values to configure the read data order, then in combination with the table above and the register layout documentation in the AST2600 datasheet performing write/read cycles to configure the write data order registers.
---
Joel: Note that this replaces https://patchwork.ozlabs.org/patch/1187189/
--- drivers/fsi/fsi-master-aspeed.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/fsi/fsi-master-aspeed.c +3 -3
@@ -583,11 +583,11 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev)writel (fsi_base, aspeed->base +OPB_FSI_BASE );/* Set read data order */ -writel (0x0011bb1b , aspeed->base +OPB0_R_ENDIAN ); +writel (0x00030b1b , aspeed->base +OPB0_R_ENDIAN );/* Set write data order */ -writel (0x0011bb1b , aspeed->base +OPB0_W_ENDIAN ); -writel (0xffaa5500 , aspeed->base +0x50 ); +writel (0x0011101b , aspeed->base +OPB0_W_ENDIAN ); +writel (0x0c330f3f , aspeed->base +0x50 );/* * Select OPB0 for all operations.
Signature · 1 line
2.20.1
PATCH v2 2/3 trace: fsi: Print transfer size unsigned
In reply to Andrew JefferyDue to other bugs I observed a spurious -1 transfer size.
--- include/trace/events/fsi.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/trace/events/fsi.h +3 -3
@@ -26,7 +26,7 @@ TRACE_EVENT(fsi_master_read, __entry->addr = addr; __entry->size = size; ), - TP_printk("fsi%d:%02d:%02d %08x[%zd]", + TP_printk("fsi%d:%02d:%02d %08x[%zu]", __entry->master_idx, __entry->link, __entry->id,
@@ -56,7 +56,7 @@ TRACE_EVENT(fsi_master_write, __entry->data =0 ;memcpy (&__entry->data, data, size); ), - TP_printk("fsi%d:%02d:%02d %08x[%zd] <= {%*ph}", + TP_printk("fsi%d:%02d:%02d %08x[%zu] <= {%*ph}", __entry->master_idx, __entry->link, __entry->id,
@@ -93,7 +93,7 @@ TRACE_EVENT(fsi_master_rw_result,if (__entry->write || !__entry->ret)memcpy (&__entry->data, data, size); ), - TP_printk("fsi%d:%02d:%02d %08x[%zd] %s {%*ph} ret %d", + TP_printk("fsi%d:%02d:%02d %08x[%zu] %s {%*ph} ret %d", __entry->master_idx, __entry->link, __entry->id,
Signature · 1 line
2.20.1
PATCH v2 3/3 fsi: core: Fix small accesses and unaligned offsets via sysfs
In reply to Andrew JefferySubtracting the offset delta from four-byte alignment lead to wrapping of the requested length where count is less than off. Generalise the length handling to enable and optimise aligned access sizes for all offset and size combinations. The new formula produces the following results for given offset and count values:
offset count | length
--------------+-------
0 1 | 1
0 2 | 2
0 3 | 2
0 4 | 4
0 5 | 4
1 1 | 1
1 2 | 1
1 3 | 1
1 4 | 1
1 5 | 1
2 1 | 1
2 2 | 2
2 3 | 2
2 4 | 2
2 5 | 2
3 1 | 1
3 2 | 1
3 3 | 1
3 4 | 1
3 5 | 1
We might need something like this for the cfam chardevs as well, for example we don't currently implement any alignment restrictions / handling in the hardware master driver.
--- drivers/fsi/fsi-core.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
drivers/fsi/fsi-core.c +27 -4
@@ -544,6 +544,31 @@ static int fsi_slave_scan(struct fsi_slave *slave)return 0 ; } +static unsigned long aligned_access_size (size_t offset,size_t count) +{ +unsigned long offset_unit, count_unit; + +/* Criteria: +* +* 1. Access size must be less than or equal to the maximum access +* width or the highest power-of-two factor of offset +* 2. Access size must be less than or equal to the amount specified by +* count +* +* The access width is optimal if we can calculate 1 to be strictly +* equal while still satisfying 2. +*/ + +/* Find 1 by the bottom bit of offset (with a 4 byte access cap) */ + offset_unit =BIT (__builtin_ctzl (offset |4 )); + +/* Find 2 by the top bit of count */ + count_unit =BIT (8 *sizeof (unsigned long ) -1 -__builtin_clzl (count)); + +/* Constrain the maximum access width to the minimum of both criteria */ +return BIT (__builtin_ctzl (offset_unit | count_unit)); +} +static ssize_t fsi_slave_sysfs_raw_read (struct file *file,struct kobject *kobj,struct bin_attribute *attr,char *buf,loff_t off,size_t count)
@@ -559,8 +584,7 @@ static ssize_t fsi_slave_sysfs_raw_read(struct file *file,return -EINVAL ;for (total_len =0 ; total_len < count; total_len += read_len) { - read_len =min_t (size_t, count,4 ); - read_len -= off &0x3 ; + read_len =aligned_access_size (off, count - total_len); rc =fsi_slave_read (slave, off, buf + total_len, read_len);if (rc)
@@ -587,8 +611,7 @@ static ssize_t fsi_slave_sysfs_raw_write(struct file *file,return -EINVAL ;for (total_len =0 ; total_len < count; total_len += write_len) { - write_len =min_t (size_t, count,4 ); - write_len -= off &0x3 ; + write_len =aligned_access_size (off, count - total_len); rc =fsi_slave_write (slave, off, buf + total_len, write_len);if (rc)
Signature · 1 line
2.20.1