From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:51:14
Hello Jakub, hello David,
this is a pull request of 19 patches for net-next/master.
The first 16 patches are by me and target the tcan4x5x SPI glue driver for the
m_can CAN driver. First there are a several cleanup commits, then the SPI
regmap part is converted to 8 bits per word, to make it possible to use that
driver on SPI controllers that only support the 8 bit per word mode (such as
the SPI cores on the raspberry pi).
Oliver Hartkopp contributes a patch for the CAN_RAW protocol. The getsockopt()
for CAN_RAW_FILTER is changed to return -ERANGE if the filterset does not fit
into the provided user space buffer.
The last two patches are by Joakim Zhang and add wakeup support to the flexcan
driver for the i.MX8QM SoC. The dt-bindings docs are extended to describe the
added property.
regards,
Marc
---
The following changes since commit ede71cae72855f8d6f6268510895210adc317666:
net-next: docs: Fix typos in snmp_counter.rst (2021-01-05 17:07:38 -0800)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git tags/linux-can-next-for-5.12-20210106
for you to fetch changes up to 812f0116c66a3ebaf0b6062226aa85574dd79f67:
can: flexcan: add CAN wakeup function for i.MX8QM (2021-01-06 15:20:13 +0100)
----------------------------------------------------------------
linux-can-next-for-5.12-20210106
----------------------------------------------------------------
Joakim Zhang (2):
dt-bindings: can: fsl,flexcan: add fsl,scu-index property to indicate a resource
can: flexcan: add CAN wakeup function for i.MX8QM
Marc Kleine-Budde (16):
can: tcan4x5x: replace DEVICE_NAME by KBUILD_MODNAME
can: tcan4x5x: beautify indention of tcan4x5x_of_match and tcan4x5x_id_table
can: tcan4x5x: rename tcan4x5x.c -> tcan4x5x-core.c
can: tcan4x5x: move regmap code into seperate file
can: tcan4x5x: mark struct regmap_bus tcan4x5x_bus as constant
can: tcan4x5x: tcan4x5x_bus: remove not needed read_flag_mask
can: tcan4x5x: remove regmap async support
can: tcan4x5x: rename regmap_spi_gather_write() -> tcan4x5x_regmap_gather_write()
can: tcan4x5x: tcan4x5x_regmap_write(): remove not needed casts and replace 4 by sizeof
can: tcan4x5x: tcan4x5x_regmap_init(): use spi as context pointer
can: tcan4x5x: fix max register value
can: tcan4x5x: tcan4x5x_regmap: set reg_stride to 4
can: tcan4x5x: add max_raw_{read,write} of 256
can: tcan4x5x: add {wr,rd}_table
can: tcan4x5x: rework SPI access
can: tcan4x5x: add support for half-duplex controllers
Oliver Hartkopp (1):
can: raw: return -ERANGE when filterset does not fit into user space buffer
.../devicetree/bindings/net/can/fsl,flexcan.yaml | 11 ++
drivers/net/can/flexcan.c | 123 ++++++++++++++++---
drivers/net/can/m_can/Makefile | 4 +
.../net/can/m_can/{tcan4x5x.c => tcan4x5x-core.c} | 126 +++----------------
drivers/net/can/m_can/tcan4x5x-regmap.c | 135 +++++++++++++++++++++
drivers/net/can/m_can/tcan4x5x.h | 57 +++++++++
net/can/raw.c | 16 ++-
7 files changed, 340 insertions(+), 132 deletions(-)
rename drivers/net/can/m_can/{tcan4x5x.c => tcan4x5x-core.c} (80%)
create mode 100644 drivers/net/can/m_can/tcan4x5x-regmap.c
create mode 100644 drivers/net/can/m_can/tcan4x5x.h
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:50:47
This patch beautifies the indention of the tcan4x5x_of_match and
tcan4x5x_id_table.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-3-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:50:47
This patch fixes the max register value for the regmap.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-12-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x-regmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:50:48
This patch replaces the context pointer of the regmap callback functions by a
pointer to the spi_device. This saves one level of indirection in the
callbacks.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-11-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x-regmap.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:50:48
This is a preparation patch to move the regmap related code into a seperate
file. This patch removes the tcan4x5x.c to tcan4x5x-core.c.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-4-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/Makefile | 3 +++
drivers/net/can/m_can/{tcan4x5x.c => tcan4x5x-core.c} | 0
2 files changed, 3 insertions(+)
rename drivers/net/can/m_can/{tcan4x5x.c => tcan4x5x-core.c} (100%)
diff --git a/drivers/net/can/m_can/tcan4x5x.c b/drivers/net/can/m_can/tcan4x5x-core.csimilarity index 100%rename from drivers/net/can/m_can/tcan4x5x.crename to drivers/net/can/m_can/tcan4x5x-core.c
--
2.29.2
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:51:14
With C99 initializers, all non mentioned members are initialzied to 0, so
remove not needed initialization of read_flag_mask.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-7-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x-regmap.c | 1 -
1 file changed, 1 deletion(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:51:17
This patch reworks the SPI access and fixes several probems:
- tcan4x5x_regmap_gather_write(), tcan4x5x_regmap_read():
Do not place variable "addr" on stack and use it as buffer for SPI
transfer. Buffers for SPI transfers must be allocated from DMA save
memory.
- tcan4x5x_regmap_gather_write(), tcan4x5x_regmap_read():
Halfe number of SPI transfers by using a single buffer + memcpy().
This improves the performance, especially on SPI controllers, which
use interrupt based transfers.
- Use "8" bits per word, not "32". This makes it possible to use this
driver on SoCs like the Raspberry Pi, which SPI host controller
drivers only support 8 bits per word.
Note: this breaks half duplex only controllers. Support for them will be
re-added in the next patch.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-16-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x-core.c | 2 +-
drivers/net/can/m_can/tcan4x5x-regmap.c | 87 +++++++++++++++++--------
drivers/net/can/m_can/tcan4x5x.h | 23 +++++++
3 files changed, 84 insertions(+), 28 deletions(-)
@@ -380,7 +380,7 @@ static int tcan4x5x_can_probe(struct spi_device *spi)spi_set_drvdata(spi,priv);/* Configure the SPI bus */-spi->bits_per_word=32;+spi->bits_per_word=8;ret=spi_setup(spi);if(ret)gotoout_m_can_class_free_dev;
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:51:22
This patch renames the regmap_spi_gather_write() function to
tcan4x5x_regmap_gather_write(). Now it has a "tcan4x5x_" prefix as all other
functions in this driver.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-9-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x-regmap.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:51:30
From: Joakim Zhang <redacted>
The System Controller Firmware (SCFW) is a low-level system function
which runs on a dedicated Cortex-M core to provide power, clock, and
resource management. It exists on some i.MX8 processors. e.g. i.MX8QM
(QM, QP), and i.MX8QX (QXP, DX). SCU driver manages the IPC interface
between host CPU and the SCU firmware running on M4.
For i.MX8QM, stop mode request is controlled by System Controller Unit(SCU)
firmware, this patch introduces FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW quirk
for this function.
Signed-off-by: Joakim Zhang <redacted>
Link: https://lore.kernel.org/r/20201106105627.31061-6-qiangqing.zhang@nxp.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/flexcan.c | 123 ++++++++++++++++++++++++++++++++------
1 file changed, 106 insertions(+), 17 deletions(-)
@@ -9,6 +9,7 @@//// Based on code originally by Andrey Volkov <avolkov@varma-el.com>+#include<dt-bindings/firmware/imx/rsrc.h>#include<linux/bitfield.h>#include<linux/can.h>#include<linux/can/dev.h>
@@ -242,6 +244,8 @@#define FLEXCAN_QUIRK_SUPPORT_FD BIT(9)/* support memory detection and correction */#define FLEXCAN_QUIRK_SUPPORT_ECC BIT(10)+/* Setup stop mode with SCU firmware to support wakeup */+#define FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW BIT(11)/* Structure of the message buffer */structflexcan_mb{
@@ -347,6 +351,7 @@ struct flexcan_priv {u8mb_count;u8mb_size;u8clk_src;/* clock source of CAN Protocol Engine */+u8scu_idx;u64rx_mask;u64tx_mask;
@@ -358,6 +363,9 @@ struct flexcan_priv {structregulator*reg_xceiver;structflexcan_stop_modestm;+/* IPC handle when setup stop mode by System Controller firmware(scfw) */+structimx_sc_ipc*sc_ipc_handle;+/* Read and Write APIs */u32(*read)(void__iomem*addr);void(*write)(u32val,void__iomem*addr);
@@ -1924,6 +1958,58 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)returnret;}+staticintflexcan_setup_stop_mode_scfw(structplatform_device*pdev)+{+structnet_device*dev=platform_get_drvdata(pdev);+structflexcan_priv*priv;+u8scu_idx;+intret;++ret=of_property_read_u8(pdev->dev.of_node,"fsl,scu-index",&scu_idx);+if(ret<0){+dev_dbg(&pdev->dev,"failed to get scu index\n");+returnret;+}++priv=netdev_priv(dev);+priv->scu_idx=scu_idx;++/* this function could be defered probe, return -EPROBE_DEFER */+returnimx_scu_get_handle(&priv->sc_ipc_handle);+}++/* flexcan_setup_stop_mode - Setup stop mode for wakeup+*+*Return:=0setupstopmodesuccessfullyordoesn'tsupportthisfeature+*<0failtosetupstopmode(couldbedeferedprobe)+*/+staticintflexcan_setup_stop_mode(structplatform_device*pdev)+{+structnet_device*dev=platform_get_drvdata(pdev);+structflexcan_priv*priv;+intret;++priv=netdev_priv(dev);++if(priv->devtype_data->quirks&FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW)+ret=flexcan_setup_stop_mode_scfw(pdev);+elseif(priv->devtype_data->quirks&FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR)+ret=flexcan_setup_stop_mode_gpr(pdev);+else+/* return 0 directly if doesn't support stop mode feature */+return0;++if(ret)+returnret;++device_set_wakeup_capable(&pdev->dev,true);++if(of_property_read_bool(pdev->dev.of_node,"wakeup-source"))+device_set_wakeup_enable(&pdev->dev,true);++return0;+}+staticconststructof_device_idflexcan_of_match[]={{.compatible="fsl,imx8qm-flexcan",.data=&fsl_imx8qm_devtype_data,},{.compatible="fsl,imx8mp-flexcan",.data=&fsl_imx8mp_devtype_data,},
@@ -2054,17 +2140,20 @@ static int flexcan_probe(struct platform_device *pdev)gotofailed_register;}+err=flexcan_setup_stop_mode(pdev);+if(err<0){+if(err!=-EPROBE_DEFER)+dev_err(&pdev->dev,"setup stop mode failed\n");+gotofailed_setup_stop_mode;+}+of_can_transceiver(dev);devm_can_led_init(dev);-if(priv->devtype_data->quirks&FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR){-err=flexcan_setup_stop_mode(pdev);-if(err)-dev_dbg(&pdev->dev,"failed to setup stop-mode\n");-}-return0;+failed_setup_stop_mode:+unregister_flexcandev(dev);failed_register:pm_runtime_put_noidle(&pdev->dev);pm_runtime_disable(&pdev->dev);
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:51:33
This patch marks the struct regmap_bus tcan4x5x_bus as constant.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-6-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x-regmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:51:33
The tcan4x5x chip support bulk read/write, but as the length field is only 8
bits wide, the maximum is 256. A length of 0 is treated as 256.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-14-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x-regmap.c | 2 ++
1 file changed, 2 insertions(+)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:51:35
From: Oliver Hartkopp <socketcan@hartkopp.net>
Multiple filters (struct can_filter) can be set with the setsockopt()
function, which was originally intended as a write-only operation.
As getsockopt() also provides a CAN_RAW_FILTER option to read back the
given filters, the caller has to provide an appropriate user space buffer.
In the case this buffer is too small the getsockopt() silently truncates
the filter information and gives no information about the needed space.
This is safe but not convenient for the programmer.
In net/core/sock.c the SO_PEERGROUPS sockopt had a similar requirement
and solved it by returning -ERANGE in the case that the provided data
does not fit into the given user space buffer and fills the required size
into optlen, so that the caller can retry with a matching buffer length.
This patch adopts this approach for CAN_RAW_FILTER getsockopt().
Reported-by: Phillip Schichtel <redacted>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Tested-By: Phillip Schichtel <redacted>
Link: https://lore.kernel.org/r/20201216174928.21663-1-socketcan@hartkopp.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
net/can/raw.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
@@ -665,10 +665,18 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,if(ro->count>0){intfsize=ro->count*sizeof(structcan_filter);-if(len>fsize)-len=fsize;-if(copy_to_user(optval,ro->filter,len))-err=-EFAULT;+/* user space buffer to small for filter list? */+if(len<fsize){+/* return -ERANGE and needed space in optlen */+err=-ERANGE;+if(put_user(fsize,optlen))+err=-EFAULT;+}else{+if(len>fsize)+len=fsize;+if(copy_to_user(optval,ro->filter,len))+err=-EFAULT;+}}else{len=0;}
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:52:04
From: Joakim Zhang <redacted>
For SoCs with SCU support, need setup stop mode via SCU firmware, so this
property can help indicate a resource in SCU firmware.
Signed-off-by: Joakim Zhang <redacted>
Link: https://lore.kernel.org/r/20201106105627.31061-3-qiangqing.zhang@nxp.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
.../devicetree/bindings/net/can/fsl,flexcan.yaml | 11 +++++++++++
1 file changed, 11 insertions(+)
@@ -110,6 +110,16 @@ properties:description:Enable CAN remote wakeup.+fsl,scu-index:+description:|+The scu index of CAN instance.+For SoCs with SCU support, need setup stop mode via SCU firmware, so this+property can help indicate a resource. It supports up to 3 CAN instances+now.+$ref:/schemas/types.yaml#/definitions/uint8+minimum:0+maximum:2+required:-compatible-reg
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:52:04
This patch replaces the DEVICE_NAME macro by KBUILD_MODNAME and removed the
superfluous DEVICE_NAME.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-2-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:52:04
This patch adds back support for half-duplex controllers, which was removed in
the last patch.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-17-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x-regmap.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:52:04
This patch sets the regmap stide to 4, as the chip only supports access on 32
bit alligned access.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-13-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x-regmap.c | 1 +
1 file changed, 1 insertion(+)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:52:04
This patch simplifies the tcan4x5x_regmap_write(0 function by removing not
needed casts and replaces hardcoded "4" by appropriate sizeof()s.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-10-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x-regmap.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:52:34
The memory space of the chip is not fully populated, so add a regmap range
table to document this.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-15-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x-regmap.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-01-07 09:52:34
The driver doesn't use regmap async support, so remove the stubs.
Reviewed-by: Dan Murphy <redacted>
Tested-by: Sean Nyekjaer <redacted>
Link: https://lore.kernel.org/r/20201215231746.1132907-8-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/tcan4x5x-regmap.c | 15 ---------------
1 file changed, 15 deletions(-)
From: Jakub Kicinski <kuba@kernel.org> Date: 2021-01-07 19:08:07
On Thu, 7 Jan 2021 10:48:41 +0100 Marc Kleine-Budde wrote:
Hello Jakub, hello David,
this is a pull request of 19 patches for net-next/master.
The first 16 patches are by me and target the tcan4x5x SPI glue driver for the
m_can CAN driver. First there are a several cleanup commits, then the SPI
regmap part is converted to 8 bits per word, to make it possible to use that
driver on SPI controllers that only support the 8 bit per word mode (such as
the SPI cores on the raspberry pi).
Oliver Hartkopp contributes a patch for the CAN_RAW protocol. The getsockopt()
for CAN_RAW_FILTER is changed to return -ERANGE if the filterset does not fit
into the provided user space buffer.
The last two patches are by Joakim Zhang and add wakeup support to the flexcan
driver for the i.MX8QM SoC. The dt-bindings docs are extended to describe the
added property.
Due to the packing of the struct tcan4x5x_buf_cmd it should have a length of 4
bytes. Without __packed, will the "u8 data" come directly after the cmd?
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
__packed as it's the byte stream send to the chip via SPI.
____cacheline_aligned, as it might be subject to DMA mapping in the SPI host
driver. An alternative would be to allocate these with separate kmalloc().
regards,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Due to the packing of the struct tcan4x5x_buf_cmd it should have a length of 4
bytes. Without __packed, will the "u8 data" come directly after the cmd?
Yup, u8 with no alignment attribute will follow the previous
field with no holes.
Due to the packing of the struct tcan4x5x_buf_cmd it should have a length of 4
bytes. Without __packed, will the "u8 data" come directly after the cmd?
Yup, u8 with no alignment attribute will follow the previous
field with no holes.
__packed has a documentation benefit though. It documents that the author
considers the current layout to be the only correct one. (and thus extra
care should be taken when modifying it).
Due to the packing of the struct tcan4x5x_buf_cmd it should have a length of 4
bytes. Without __packed, will the "u8 data" come directly after the cmd?
Yup, u8 with no alignment attribute will follow the previous
field with no holes.
__packed has a documentation benefit though. It documents that the author
considers the current layout to be the only correct one. (and thus extra
care should be taken when modifying it).
____cacheline_aligned adds a big architecture dependent padding at the
end of this struct, so the size of this structure is architecture
dependent. Besides using packed forced the compiler to use byte by byte
loads on architectures without unaligned access, so __packed is not
free.
This has to be packed, as I assume the compiler would add some space after the
"u8 cmd" to align the __be16 naturally.
Why not generate a series of 32bit words to be sent over the SPI bus.
Slightly less faffing in the code.
Then have a #define (or inline function) to merge the cmd+addr+len
into a single 32bit word.
Also if the length is in 32bit units, then the data[] field
ought to be u32[].
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Due to the packing of the struct tcan4x5x_buf_cmd it should have a length of 4
bytes. Without __packed, will the "u8 data" come directly after the cmd?
Yup, u8 with no alignment attribute will follow the previous
field with no holes.
__packed has a documentation benefit though. It documents that the author
considers the current layout to be the only correct one. (and thus extra
care should be taken when modifying it).
____cacheline_aligned adds a big architecture dependent padding at the
end of this struct, so the size of this structure is architecture
dependent. Besides using packed forced the compiler to use byte by byte
loads on architectures without unaligned access, so __packed is not
free.
https://godbolt.org/z/j68x8n
seems to indicate that explicit alignment "overrules" packed's implicit
alignment of 1 as
there isn't any byte-by-byte access generated for a struct
that is both packed and cacheline aligned. packed only structs are accessed
byte-by-byte however.
Did I get something wrong in my testcase?
I compiled with ARM gcc 8.2 -mno-unaligned-access -fno-strict-aliasing -O2
Cheers,
Ahmad
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Due to the packing of the struct tcan4x5x_buf_cmd it should have a length of 4
bytes. Without __packed, will the "u8 data" come directly after the cmd?
Yup, u8 with no alignment attribute will follow the previous
field with no holes.
__packed has a documentation benefit though. It documents that the author
considers the current layout to be the only correct one. (and thus extra
care should be taken when modifying it).
____cacheline_aligned adds a big architecture dependent padding at the
end of this struct, so the size of this structure is architecture
dependent. Besides using packed forced the compiler to use byte by byte
loads on architectures without unaligned access, so __packed is not
free.
https://godbolt.org/z/j68x8n
seems to indicate that explicit alignment "overrules" packed's implicit
alignment of 1 as
there isn't any byte-by-byte access generated for a struct
that is both packed and cacheline aligned. packed only structs are accessed
byte-by-byte however.
Did I get something wrong in my testcase?
I compiled with ARM gcc 8.2 -mno-unaligned-access -fno-strict-aliasing -O2
I see, that's why I said combining ____cacheline_aligned with __packed
looks very confusing. Good to know which one takes precedence.
That doesn't change my recommendation to remove __packed, though, let's
not leave readers of this code scratching their heads.
Due to the packing of the struct tcan4x5x_buf_cmd it should have a length of 4
bytes. Without __packed, will the "u8 data" come directly after the cmd?
Yup, u8 with no alignment attribute will follow the previous
field with no holes.
Ack, without __packed, there's no diff in the objdump on arm.
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
This has to be packed, as I assume the compiler would add some space after the
"u8 cmd" to align the __be16 naturally.
Why not generate a series of 32bit words to be sent over the SPI bus.
Slightly less faffing in the code.
Then have a #define (or inline function) to merge the cmd+addr+len
into a single 32bit word.
The driver uses regmap. With proper configuration regmap already formats the
"cmd" and the "addr" in correct byte order into the first 3 bytes of the "reg_buf".
As regmap doesn't support generating a length parameter, I use the above struct
tcan4x5x_buf_cmd to set the length.
Also if the length is in 32bit units, then the data[] field
ought to be u32[].
In the regmap callback the data is passed with a void pointer and a length (in
bytes), so copying this to a "u8 data[]" felt more natural to me.
regards,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |