Re: [net-next 15/19] can: tcan4x5x: rework SPI access
From: Marc Kleine-Budde <mkl@pengutronix.de>
Date: 2021-01-12 15:37:44
Also in:
linux-can
Attachments
- signature.asc [application/pgp-signature] 488 bytes
From: Marc Kleine-Budde <mkl@pengutronix.de>
Date: 2021-01-12 15:37:44
Also in:
linux-can
On 1/8/21 10:53 PM, David Laight wrote:
quoted
On 1/7/21 8:06 PM, Jakub Kicinski wrote:quoted
On Thu, 7 Jan 2021 11:00:35 -0800 Jakub Kicinski wrote:quoted
On Thu, 7 Jan 2021 10:48:56 +0100 Marc Kleine-Budde wrote:quoted
+struct __packed tcan4x5x_map_buf { + struct tcan4x5x_buf_cmd cmd; + u8 data[256 * sizeof(u32)]; +} ____cacheline_aligned;Interesting attribute combo, I must say.Looking at the rest of the patch I don't really see a reason for __packed. Perhaps it can be dropped?It's the stream of bytes send via SPI to the chip. Here are both structs for reference:quoted
+struct __packed tcan4x5x_buf_cmd { + u8 cmd; + __be16 addr; + u8 len; +};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 |