073-v4.10-0002-net-bgmac-drop-struct-bcma_mdio-we-don-t-need-anymor.patch 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. From aa8863e5d49417094b9457a0d53e8505e95a1863 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
  3. Date: Tue, 31 Jan 2017 19:37:55 +0100
  4. Subject: [PATCH 2/3] net: bgmac: drop struct bcma_mdio we don't need anymore
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Adding struct bcma_mdio was a workaround for bcma code not having access
  9. to the struct bgmac used in the core code. Now we don't duplicate this
  10. struct we can just use it internally in bcma code.
  11. This simplifies code & allows access to all bgmac driver details from
  12. all places in bcma code.
  13. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  14. Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
  15. Signed-off-by: David S. Miller <davem@davemloft.net>
  16. ---
  17. drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c | 98 ++++++++++---------------
  18. drivers/net/ethernet/broadcom/bgmac-bcma.c | 2 +-
  19. drivers/net/ethernet/broadcom/bgmac.h | 2 +-
  20. 3 files changed, 42 insertions(+), 60 deletions(-)
  21. --- a/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
  22. +++ b/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
  23. @@ -12,11 +12,6 @@
  24. #include <linux/brcmphy.h>
  25. #include "bgmac.h"
  26. -struct bcma_mdio {
  27. - struct bcma_device *core;
  28. - u8 phyaddr;
  29. -};
  30. -
  31. static bool bcma_mdio_wait_value(struct bcma_device *core, u16 reg, u32 mask,
  32. u32 value, int timeout)
  33. {
  34. @@ -37,7 +32,7 @@ static bool bcma_mdio_wait_value(struct
  35. * PHY ops
  36. **************************************************/
  37. -static u16 bcma_mdio_phy_read(struct bcma_mdio *bcma_mdio, u8 phyaddr, u8 reg)
  38. +static u16 bcma_mdio_phy_read(struct bgmac *bgmac, u8 phyaddr, u8 reg)
  39. {
  40. struct bcma_device *core;
  41. u16 phy_access_addr;
  42. @@ -56,12 +51,12 @@ static u16 bcma_mdio_phy_read(struct bcm
  43. BUILD_BUG_ON(BGMAC_PC_MCT_SHIFT != BCMA_GMAC_CMN_PC_MCT_SHIFT);
  44. BUILD_BUG_ON(BGMAC_PC_MTE != BCMA_GMAC_CMN_PC_MTE);
  45. - if (bcma_mdio->core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  46. - core = bcma_mdio->core->bus->drv_gmac_cmn.core;
  47. + if (bgmac->bcma.core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  48. + core = bgmac->bcma.core->bus->drv_gmac_cmn.core;
  49. phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS;
  50. phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL;
  51. } else {
  52. - core = bcma_mdio->core;
  53. + core = bgmac->bcma.core;
  54. phy_access_addr = BGMAC_PHY_ACCESS;
  55. phy_ctl_addr = BGMAC_PHY_CNTL;
  56. }
  57. @@ -87,7 +82,7 @@ static u16 bcma_mdio_phy_read(struct bcm
  58. }
  59. /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphywr */
  60. -static int bcma_mdio_phy_write(struct bcma_mdio *bcma_mdio, u8 phyaddr, u8 reg,
  61. +static int bcma_mdio_phy_write(struct bgmac *bgmac, u8 phyaddr, u8 reg,
  62. u16 value)
  63. {
  64. struct bcma_device *core;
  65. @@ -95,12 +90,12 @@ static int bcma_mdio_phy_write(struct bc
  66. u16 phy_ctl_addr;
  67. u32 tmp;
  68. - if (bcma_mdio->core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  69. - core = bcma_mdio->core->bus->drv_gmac_cmn.core;
  70. + if (bgmac->bcma.core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  71. + core = bgmac->bcma.core->bus->drv_gmac_cmn.core;
  72. phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS;
  73. phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL;
  74. } else {
  75. - core = bcma_mdio->core;
  76. + core = bgmac->bcma.core;
  77. phy_access_addr = BGMAC_PHY_ACCESS;
  78. phy_ctl_addr = BGMAC_PHY_CNTL;
  79. }
  80. @@ -110,8 +105,8 @@ static int bcma_mdio_phy_write(struct bc
  81. tmp |= phyaddr;
  82. bcma_write32(core, phy_ctl_addr, tmp);
  83. - bcma_write32(bcma_mdio->core, BGMAC_INT_STATUS, BGMAC_IS_MDIO);
  84. - if (bcma_read32(bcma_mdio->core, BGMAC_INT_STATUS) & BGMAC_IS_MDIO)
  85. + bcma_write32(bgmac->bcma.core, BGMAC_INT_STATUS, BGMAC_IS_MDIO);
  86. + if (bcma_read32(bgmac->bcma.core, BGMAC_INT_STATUS) & BGMAC_IS_MDIO)
  87. dev_warn(&core->dev, "Error setting MDIO int\n");
  88. tmp = BGMAC_PA_START;
  89. @@ -132,39 +127,39 @@ static int bcma_mdio_phy_write(struct bc
  90. }
  91. /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyinit */
  92. -static void bcma_mdio_phy_init(struct bcma_mdio *bcma_mdio)
  93. +static void bcma_mdio_phy_init(struct bgmac *bgmac)
  94. {
  95. - struct bcma_chipinfo *ci = &bcma_mdio->core->bus->chipinfo;
  96. + struct bcma_chipinfo *ci = &bgmac->bcma.core->bus->chipinfo;
  97. u8 i;
  98. if (ci->id == BCMA_CHIP_ID_BCM5356) {
  99. for (i = 0; i < 5; i++) {
  100. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x008b);
  101. - bcma_mdio_phy_write(bcma_mdio, i, 0x15, 0x0100);
  102. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f);
  103. - bcma_mdio_phy_write(bcma_mdio, i, 0x12, 0x2aaa);
  104. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b);
  105. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x008b);
  106. + bcma_mdio_phy_write(bgmac, i, 0x15, 0x0100);
  107. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000f);
  108. + bcma_mdio_phy_write(bgmac, i, 0x12, 0x2aaa);
  109. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b);
  110. }
  111. }
  112. if ((ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg != 10) ||
  113. (ci->id == BCMA_CHIP_ID_BCM4749 && ci->pkg != 10) ||
  114. (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg != 9)) {
  115. - struct bcma_drv_cc *cc = &bcma_mdio->core->bus->drv_cc;
  116. + struct bcma_drv_cc *cc = &bgmac->bcma.core->bus->drv_cc;
  117. bcma_chipco_chipctl_maskset(cc, 2, ~0xc0000000, 0);
  118. bcma_chipco_chipctl_maskset(cc, 4, ~0x80000000, 0);
  119. for (i = 0; i < 5; i++) {
  120. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f);
  121. - bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x5284);
  122. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b);
  123. - bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x0010);
  124. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f);
  125. - bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x5296);
  126. - bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x1073);
  127. - bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x9073);
  128. - bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x52b6);
  129. - bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x9273);
  130. - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b);
  131. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000f);
  132. + bcma_mdio_phy_write(bgmac, i, 0x16, 0x5284);
  133. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b);
  134. + bcma_mdio_phy_write(bgmac, i, 0x17, 0x0010);
  135. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000f);
  136. + bcma_mdio_phy_write(bgmac, i, 0x16, 0x5296);
  137. + bcma_mdio_phy_write(bgmac, i, 0x17, 0x1073);
  138. + bcma_mdio_phy_write(bgmac, i, 0x17, 0x9073);
  139. + bcma_mdio_phy_write(bgmac, i, 0x16, 0x52b6);
  140. + bcma_mdio_phy_write(bgmac, i, 0x17, 0x9273);
  141. + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b);
  142. }
  143. }
  144. }
  145. @@ -172,17 +167,17 @@ static void bcma_mdio_phy_init(struct bc
  146. /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyreset */
  147. static int bcma_mdio_phy_reset(struct mii_bus *bus)
  148. {
  149. - struct bcma_mdio *bcma_mdio = bus->priv;
  150. - u8 phyaddr = bcma_mdio->phyaddr;
  151. + struct bgmac *bgmac = bus->priv;
  152. + u8 phyaddr = bgmac->phyaddr;
  153. - if (bcma_mdio->phyaddr == BGMAC_PHY_NOREGS)
  154. + if (phyaddr == BGMAC_PHY_NOREGS)
  155. return 0;
  156. - bcma_mdio_phy_write(bcma_mdio, phyaddr, MII_BMCR, BMCR_RESET);
  157. + bcma_mdio_phy_write(bgmac, phyaddr, MII_BMCR, BMCR_RESET);
  158. udelay(100);
  159. - if (bcma_mdio_phy_read(bcma_mdio, phyaddr, MII_BMCR) & BMCR_RESET)
  160. - dev_err(&bcma_mdio->core->dev, "PHY reset failed\n");
  161. - bcma_mdio_phy_init(bcma_mdio);
  162. + if (bcma_mdio_phy_read(bgmac, phyaddr, MII_BMCR) & BMCR_RESET)
  163. + dev_err(bgmac->dev, "PHY reset failed\n");
  164. + bcma_mdio_phy_init(bgmac);
  165. return 0;
  166. }
  167. @@ -202,16 +197,12 @@ static int bcma_mdio_mii_write(struct mi
  168. return bcma_mdio_phy_write(bus->priv, mii_id, regnum, value);
  169. }
  170. -struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr)
  171. +struct mii_bus *bcma_mdio_mii_register(struct bgmac *bgmac)
  172. {
  173. - struct bcma_mdio *bcma_mdio;
  174. + struct bcma_device *core = bgmac->bcma.core;
  175. struct mii_bus *mii_bus;
  176. int i, err;
  177. - bcma_mdio = kzalloc(sizeof(*bcma_mdio), GFP_KERNEL);
  178. - if (!bcma_mdio)
  179. - return ERR_PTR(-ENOMEM);
  180. -
  181. mii_bus = mdiobus_alloc();
  182. if (!mii_bus) {
  183. err = -ENOMEM;
  184. @@ -221,12 +212,12 @@ struct mii_bus *bcma_mdio_mii_register(s
  185. mii_bus->name = "bcma_mdio mii bus";
  186. sprintf(mii_bus->id, "%s-%d-%d", "bcma_mdio", core->bus->num,
  187. core->core_unit);
  188. - mii_bus->priv = bcma_mdio;
  189. + mii_bus->priv = bgmac;
  190. mii_bus->read = bcma_mdio_mii_read;
  191. mii_bus->write = bcma_mdio_mii_write;
  192. mii_bus->reset = bcma_mdio_phy_reset;
  193. mii_bus->parent = &core->dev;
  194. - mii_bus->phy_mask = ~(1 << phyaddr);
  195. + mii_bus->phy_mask = ~(1 << bgmac->phyaddr);
  196. mii_bus->irq = kmalloc_array(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
  197. if (!mii_bus->irq) {
  198. @@ -236,9 +227,6 @@ struct mii_bus *bcma_mdio_mii_register(s
  199. for (i = 0; i < PHY_MAX_ADDR; i++)
  200. mii_bus->irq[i] = PHY_POLL;
  201. - bcma_mdio->core = core;
  202. - bcma_mdio->phyaddr = phyaddr;
  203. -
  204. err = mdiobus_register(mii_bus);
  205. if (err) {
  206. dev_err(&core->dev, "Registration of mii bus failed\n");
  207. @@ -252,24 +240,18 @@ err_free_irq:
  208. err_free_bus:
  209. mdiobus_free(mii_bus);
  210. err:
  211. - kfree(bcma_mdio);
  212. return ERR_PTR(err);
  213. }
  214. EXPORT_SYMBOL_GPL(bcma_mdio_mii_register);
  215. void bcma_mdio_mii_unregister(struct mii_bus *mii_bus)
  216. {
  217. - struct bcma_mdio *bcma_mdio;
  218. -
  219. if (!mii_bus)
  220. return;
  221. - bcma_mdio = mii_bus->priv;
  222. -
  223. mdiobus_unregister(mii_bus);
  224. kfree(mii_bus->irq);
  225. mdiobus_free(mii_bus);
  226. - kfree(bcma_mdio);
  227. }
  228. EXPORT_SYMBOL_GPL(bcma_mdio_mii_unregister);
  229. --- a/drivers/net/ethernet/broadcom/bgmac-bcma.c
  230. +++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c
  231. @@ -159,7 +159,7 @@ static int bgmac_probe(struct bcma_devic
  232. if (!bgmac_is_bcm4707_family(core) &&
  233. !(ci->id == BCMA_CHIP_ID_BCM53573 && core->core_unit == 1)) {
  234. - mii_bus = bcma_mdio_mii_register(core, bgmac->phyaddr);
  235. + mii_bus = bcma_mdio_mii_register(bgmac);
  236. if (IS_ERR(mii_bus)) {
  237. err = PTR_ERR(mii_bus);
  238. goto err;
  239. --- a/drivers/net/ethernet/broadcom/bgmac.h
  240. +++ b/drivers/net/ethernet/broadcom/bgmac.h
  241. @@ -519,7 +519,7 @@ struct bgmac *bgmac_alloc(struct device
  242. int bgmac_enet_probe(struct bgmac *bgmac);
  243. void bgmac_enet_remove(struct bgmac *bgmac);
  244. -struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr);
  245. +struct mii_bus *bcma_mdio_mii_register(struct bgmac *bgmac);
  246. void bcma_mdio_mii_unregister(struct mii_bus *mii_bus);
  247. static inline u32 bgmac_read(struct bgmac *bgmac, u16 offset)