1
0

930-ar8216-make-reg-access-atomic.patch 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From b3797d1a92afe97c173b00fdb7824cedba24eef0 Mon Sep 17 00:00:00 2001
  2. From: Chuanhong Guo <gch981213@gmail.com>
  3. Date: Sun, 20 Sep 2020 01:00:45 +0800
  4. Subject: [PATCH] ath79: ar8216: make switch register access atomic
  5. due to some unknown reason these register accesses sometimes fail
  6. on the integrated switch without this patch.
  7. THIS ONLY WORKS ON ATH79 AND MAY BREAK THE DRIVER ON OTHER PLATFORMS!
  8. The mdio bus on ath79 works in polling mode and doesn't rely on
  9. any interrupt. This patch breaks the driver on any mdio master
  10. with interrupts used.
  11. ---
  12. --- a/drivers/net/phy/ar8216.c
  13. +++ b/drivers/net/phy/ar8216.c
  14. @@ -252,6 +252,7 @@ ar8xxx_mii_write32(struct ar8xxx_priv *p
  15. u32
  16. ar8xxx_read(struct ar8xxx_priv *priv, int reg)
  17. {
  18. + unsigned long flags;
  19. struct mii_bus *bus = priv->mii_bus;
  20. u16 r1, r2, page;
  21. u32 val;
  22. @@ -259,11 +260,13 @@ ar8xxx_read(struct ar8xxx_priv *priv, in
  23. split_addr((u32) reg, &r1, &r2, &page);
  24. mutex_lock(&bus->mdio_lock);
  25. + local_irq_save(flags);
  26. bus->write(bus, 0x18, 0, page);
  27. wait_for_page_switch();
  28. val = ar8xxx_mii_read32(priv, 0x10 | r2, r1);
  29. + local_irq_restore(flags);
  30. mutex_unlock(&bus->mdio_lock);
  31. return val;
  32. @@ -272,17 +275,20 @@ ar8xxx_read(struct ar8xxx_priv *priv, in
  33. void
  34. ar8xxx_write(struct ar8xxx_priv *priv, int reg, u32 val)
  35. {
  36. + unsigned long flags;
  37. struct mii_bus *bus = priv->mii_bus;
  38. u16 r1, r2, page;
  39. split_addr((u32) reg, &r1, &r2, &page);
  40. mutex_lock(&bus->mdio_lock);
  41. + local_irq_save(flags);
  42. bus->write(bus, 0x18, 0, page);
  43. wait_for_page_switch();
  44. ar8xxx_mii_write32(priv, 0x10 | r2, r1, val);
  45. + local_irq_restore(flags);
  46. mutex_unlock(&bus->mdio_lock);
  47. }