781-v6.6-01-net-dsa-qca8k-fix-regmap-bulk-read-write-methods-on-.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. From 5652d1741574eb89cc02576e50ee3e348bd6dd77 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Marek=20Beh=C3=BAn?= <[email protected]>
  3. Date: Wed, 4 Oct 2023 11:19:03 +0200
  4. Subject: [PATCH 1/2] net: dsa: qca8k: fix regmap bulk read/write methods on
  5. big endian systems
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. Commit c766e077d927 ("net: dsa: qca8k: convert to regmap read/write
  10. API") introduced bulk read/write methods to qca8k's regmap.
  11. The regmap bulk read/write methods get the register address in a buffer
  12. passed as a void pointer parameter (the same buffer contains also the
  13. read/written values). The register address occupies only as many bytes
  14. as it requires at the beginning of this buffer. For example if the
  15. .reg_bits member in regmap_config is 16 (as is the case for this
  16. driver), the register address occupies only the first 2 bytes in this
  17. buffer, so it can be cast to u16.
  18. But the original commit implementing these bulk read/write methods cast
  19. the buffer to u32:
  20. u32 reg = *(u32 *)reg_buf & U16_MAX;
  21. taking the first 4 bytes. This works on little endian systems where the
  22. first 2 bytes of the buffer correspond to the low 16-bits, but it
  23. obviously cannot work on big endian systems.
  24. Fix this by casting the beginning of the buffer to u16 as
  25. u32 reg = *(u16 *)reg_buf;
  26. Fixes: c766e077d927 ("net: dsa: qca8k: convert to regmap read/write API")
  27. Signed-off-by: Marek Behún <[email protected]>
  28. Tested-by: Christian Marangi <[email protected]>
  29. Reviewed-by: Christian Marangi <[email protected]>
  30. Signed-off-by: David S. Miller <[email protected]>
  31. ---
  32. drivers/net/dsa/qca/qca8k-8xxx.c | 4 ++--
  33. 1 file changed, 2 insertions(+), 2 deletions(-)
  34. --- a/drivers/net/dsa/qca/qca8k-8xxx.c
  35. +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
  36. @@ -504,8 +504,8 @@ qca8k_bulk_read(void *ctx, const void *r
  37. void *val_buf, size_t val_len)
  38. {
  39. int i, count = val_len / sizeof(u32), ret;
  40. - u32 reg = *(u32 *)reg_buf & U16_MAX;
  41. struct qca8k_priv *priv = ctx;
  42. + u32 reg = *(u16 *)reg_buf;
  43. if (priv->mgmt_master &&
  44. !qca8k_read_eth(priv, reg, val_buf, val_len))
  45. @@ -526,8 +526,8 @@ qca8k_bulk_gather_write(void *ctx, const
  46. const void *val_buf, size_t val_len)
  47. {
  48. int i, count = val_len / sizeof(u32), ret;
  49. - u32 reg = *(u32 *)reg_buf & U16_MAX;
  50. struct qca8k_priv *priv = ctx;
  51. + u32 reg = *(u16 *)reg_buf;
  52. u32 *val = (u32 *)val_buf;
  53. if (priv->mgmt_master &&