075-0003-net-ethernet-bgmac-move-BCMA-MDIO-Phy-code-into-a-se.patch 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. From 55954f3bfdacc5908515b0c306cea23e77fab740 Mon Sep 17 00:00:00 2001
  2. From: Jon Mason <jon.mason@broadcom.com>
  3. Date: Thu, 7 Jul 2016 19:08:55 -0400
  4. Subject: [PATCH 3/5] net: ethernet: bgmac: move BCMA MDIO Phy code into a
  5. separate file
  6. Move the BCMA MDIO phy into a separate file, as it is very tightly
  7. coupled with the BCMA bus. This will help with the upcoming BCMA
  8. removal from the bgmac driver. Optimally, this should be moved into
  9. phy drivers, but it is too tightly coupled with the bgmac driver to
  10. effectively move it without more changes to the driver.
  11. Note: the phy_reset was intentionally removed, as the mdio phy subsystem
  12. automatically resets the phy if a reset function pointer is present. In
  13. addition to the moving of the driver, this reset function is added.
  14. Signed-off-by: Jon Mason <jon.mason@broadcom.com>
  15. Acked-by: Arnd Bergmann <arnd@arndb.de>
  16. Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
  17. Tested-by: Florian Fainelli <f.fainelli@gmail.com>
  18. Signed-off-by: David S. Miller <davem@davemloft.net>
  19. ---
  20. drivers/net/ethernet/broadcom/Makefile | 2 +-
  21. drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c | 264 ++++++++++++++++++++++++
  22. drivers/net/ethernet/broadcom/bgmac.c | 246 +++-------------------
  23. drivers/net/ethernet/broadcom/bgmac.h | 3 +
  24. 4 files changed, 298 insertions(+), 217 deletions(-)
  25. create mode 100644 drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
  26. --- a/drivers/net/ethernet/broadcom/Makefile
  27. +++ b/drivers/net/ethernet/broadcom/Makefile
  28. @@ -10,6 +10,6 @@ obj-$(CONFIG_CNIC) += cnic.o
  29. obj-$(CONFIG_BNX2X) += bnx2x/
  30. obj-$(CONFIG_SB1250_MAC) += sb1250-mac.o
  31. obj-$(CONFIG_TIGON3) += tg3.o
  32. -obj-$(CONFIG_BGMAC) += bgmac.o
  33. +obj-$(CONFIG_BGMAC) += bgmac.o bgmac-bcma-mdio.o
  34. obj-$(CONFIG_SYSTEMPORT) += bcmsysport.o
  35. obj-$(CONFIG_BNXT) += bnxt/
  36. --- /dev/null
  37. +++ b/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
  38. @@ -0,0 +1,275 @@
  39. +/*
  40. + * Driver for (BCM4706)? GBit MAC core on BCMA bus.
  41. + *
  42. + * Copyright (C) 2012 Rafał Miłecki <zajec5@gmail.com>
  43. + *
  44. + * Licensed under the GNU/GPL. See COPYING for details.
  45. + */
  46. +
  47. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  48. +
  49. +#include <linux/bcma/bcma.h>
  50. +#include <linux/brcmphy.h>
  51. +#include "bgmac.h"
  52. +
  53. +struct bcma_mdio {
  54. + struct bcma_device *core;
  55. + u8 phyaddr;
  56. +};
  57. +
  58. +static bool bcma_mdio_wait_value(struct bcma_device *core, u16 reg, u32 mask,
  59. + u32 value, int timeout)
  60. +{
  61. + u32 val;
  62. + int i;
  63. +
  64. + for (i = 0; i < timeout / 10; i++) {
  65. + val = bcma_read32(core, reg);
  66. + if ((val & mask) == value)
  67. + return true;
  68. + udelay(10);
  69. + }
  70. + dev_err(&core->dev, "Timeout waiting for reg 0x%X\n", reg);
  71. + return false;
  72. +}
  73. +
  74. +/**************************************************
  75. + * PHY ops
  76. + **************************************************/
  77. +
  78. +static u16 bcma_mdio_phy_read(struct bcma_mdio *bcma_mdio, u8 phyaddr, u8 reg)
  79. +{
  80. + struct bcma_device *core;
  81. + u16 phy_access_addr;
  82. + u16 phy_ctl_addr;
  83. + u32 tmp;
  84. +
  85. + BUILD_BUG_ON(BGMAC_PA_DATA_MASK != BCMA_GMAC_CMN_PA_DATA_MASK);
  86. + BUILD_BUG_ON(BGMAC_PA_ADDR_MASK != BCMA_GMAC_CMN_PA_ADDR_MASK);
  87. + BUILD_BUG_ON(BGMAC_PA_ADDR_SHIFT != BCMA_GMAC_CMN_PA_ADDR_SHIFT);
  88. + BUILD_BUG_ON(BGMAC_PA_REG_MASK != BCMA_GMAC_CMN_PA_REG_MASK);
  89. + BUILD_BUG_ON(BGMAC_PA_REG_SHIFT != BCMA_GMAC_CMN_PA_REG_SHIFT);
  90. + BUILD_BUG_ON(BGMAC_PA_WRITE != BCMA_GMAC_CMN_PA_WRITE);
  91. + BUILD_BUG_ON(BGMAC_PA_START != BCMA_GMAC_CMN_PA_START);
  92. + BUILD_BUG_ON(BGMAC_PC_EPA_MASK != BCMA_GMAC_CMN_PC_EPA_MASK);
  93. + BUILD_BUG_ON(BGMAC_PC_MCT_MASK != BCMA_GMAC_CMN_PC_MCT_MASK);
  94. + BUILD_BUG_ON(BGMAC_PC_MCT_SHIFT != BCMA_GMAC_CMN_PC_MCT_SHIFT);
  95. + BUILD_BUG_ON(BGMAC_PC_MTE != BCMA_GMAC_CMN_PC_MTE);
  96. +
  97. + if (bcma_mdio->core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  98. + core = bcma_mdio->core->bus->drv_gmac_cmn.core;
  99. + phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS;
  100. + phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL;
  101. + } else {
  102. + core = bcma_mdio->core;
  103. + phy_access_addr = BGMAC_PHY_ACCESS;
  104. + phy_ctl_addr = BGMAC_PHY_CNTL;
  105. + }
  106. +
  107. + tmp = bcma_read32(core, phy_ctl_addr);
  108. + tmp &= ~BGMAC_PC_EPA_MASK;
  109. + tmp |= phyaddr;
  110. + bcma_write32(core, phy_ctl_addr, tmp);
  111. +
  112. + tmp = BGMAC_PA_START;
  113. + tmp |= phyaddr << BGMAC_PA_ADDR_SHIFT;
  114. + tmp |= reg << BGMAC_PA_REG_SHIFT;
  115. + bcma_write32(core, phy_access_addr, tmp);
  116. +
  117. + if (!bcma_mdio_wait_value(core, phy_access_addr, BGMAC_PA_START, 0,
  118. + 1000)) {
  119. + dev_err(&core->dev, "Reading PHY %d register 0x%X failed\n",
  120. + phyaddr, reg);
  121. + return 0xffff;
  122. + }
  123. +
  124. + return bcma_read32(core, phy_access_addr) & BGMAC_PA_DATA_MASK;
  125. +}
  126. +
  127. +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphywr */
  128. +static int bcma_mdio_phy_write(struct bcma_mdio *bcma_mdio, u8 phyaddr, u8 reg,
  129. + u16 value)
  130. +{
  131. + struct bcma_device *core;
  132. + u16 phy_access_addr;
  133. + u16 phy_ctl_addr;
  134. + u32 tmp;
  135. +
  136. + if (bcma_mdio->core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  137. + core = bcma_mdio->core->bus->drv_gmac_cmn.core;
  138. + phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS;
  139. + phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL;
  140. + } else {
  141. + core = bcma_mdio->core;
  142. + phy_access_addr = BGMAC_PHY_ACCESS;
  143. + phy_ctl_addr = BGMAC_PHY_CNTL;
  144. + }
  145. +
  146. + tmp = bcma_read32(core, phy_ctl_addr);
  147. + tmp &= ~BGMAC_PC_EPA_MASK;
  148. + tmp |= phyaddr;
  149. + bcma_write32(core, phy_ctl_addr, tmp);
  150. +
  151. + bcma_write32(bcma_mdio->core, BGMAC_INT_STATUS, BGMAC_IS_MDIO);
  152. + if (bcma_read32(bcma_mdio->core, BGMAC_INT_STATUS) & BGMAC_IS_MDIO)
  153. + dev_warn(&core->dev, "Error setting MDIO int\n");
  154. +
  155. + tmp = BGMAC_PA_START;
  156. + tmp |= BGMAC_PA_WRITE;
  157. + tmp |= phyaddr << BGMAC_PA_ADDR_SHIFT;
  158. + tmp |= reg << BGMAC_PA_REG_SHIFT;
  159. + tmp |= value;
  160. + bcma_write32(core, phy_access_addr, tmp);
  161. +
  162. + if (!bcma_mdio_wait_value(core, phy_access_addr, BGMAC_PA_START, 0,
  163. + 1000)) {
  164. + dev_err(&core->dev, "Writing to PHY %d register 0x%X failed\n",
  165. + phyaddr, reg);
  166. + return -ETIMEDOUT;
  167. + }
  168. +
  169. + return 0;
  170. +}
  171. +
  172. +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyinit */
  173. +static void bcma_mdio_phy_init(struct bcma_mdio *bcma_mdio)
  174. +{
  175. + struct bcma_chipinfo *ci = &bcma_mdio->core->bus->chipinfo;
  176. + u8 i;
  177. +
  178. + if (ci->id == BCMA_CHIP_ID_BCM5356) {
  179. + for (i = 0; i < 5; i++) {
  180. + bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x008b);
  181. + bcma_mdio_phy_write(bcma_mdio, i, 0x15, 0x0100);
  182. + bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f);
  183. + bcma_mdio_phy_write(bcma_mdio, i, 0x12, 0x2aaa);
  184. + bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b);
  185. + }
  186. + }
  187. + if ((ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg != 10) ||
  188. + (ci->id == BCMA_CHIP_ID_BCM4749 && ci->pkg != 10) ||
  189. + (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg != 9)) {
  190. + struct bcma_drv_cc *cc = &bcma_mdio->core->bus->drv_cc;
  191. +
  192. + bcma_chipco_chipctl_maskset(cc, 2, ~0xc0000000, 0);
  193. + bcma_chipco_chipctl_maskset(cc, 4, ~0x80000000, 0);
  194. + for (i = 0; i < 5; i++) {
  195. + bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f);
  196. + bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x5284);
  197. + bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b);
  198. + bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x0010);
  199. + bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f);
  200. + bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x5296);
  201. + bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x1073);
  202. + bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x9073);
  203. + bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x52b6);
  204. + bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x9273);
  205. + bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b);
  206. + }
  207. + }
  208. +}
  209. +
  210. +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyreset */
  211. +static int bcma_mdio_phy_reset(struct mii_bus *bus)
  212. +{
  213. + struct bcma_mdio *bcma_mdio = bus->priv;
  214. + u8 phyaddr = bcma_mdio->phyaddr;
  215. +
  216. + if (bcma_mdio->phyaddr == BGMAC_PHY_NOREGS)
  217. + return 0;
  218. +
  219. + bcma_mdio_phy_write(bcma_mdio, phyaddr, MII_BMCR, BMCR_RESET);
  220. + udelay(100);
  221. + if (bcma_mdio_phy_read(bcma_mdio, phyaddr, MII_BMCR) & BMCR_RESET)
  222. + dev_err(&bcma_mdio->core->dev, "PHY reset failed\n");
  223. + bcma_mdio_phy_init(bcma_mdio);
  224. +
  225. + return 0;
  226. +}
  227. +
  228. +/**************************************************
  229. + * MII
  230. + **************************************************/
  231. +
  232. +static int bcma_mdio_mii_read(struct mii_bus *bus, int mii_id, int regnum)
  233. +{
  234. + return bcma_mdio_phy_read(bus->priv, mii_id, regnum);
  235. +}
  236. +
  237. +static int bcma_mdio_mii_write(struct mii_bus *bus, int mii_id, int regnum,
  238. + u16 value)
  239. +{
  240. + return bcma_mdio_phy_write(bus->priv, mii_id, regnum, value);
  241. +}
  242. +
  243. +struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr)
  244. +{
  245. + struct bcma_mdio *bcma_mdio;
  246. + struct mii_bus *mii_bus;
  247. + int i, err;
  248. +
  249. + bcma_mdio = kzalloc(sizeof(*bcma_mdio), GFP_KERNEL);
  250. + if (!bcma_mdio)
  251. + return ERR_PTR(-ENOMEM);
  252. +
  253. + mii_bus = mdiobus_alloc();
  254. + if (!mii_bus) {
  255. + err = -ENOMEM;
  256. + goto err;
  257. + }
  258. +
  259. + mii_bus->name = "bcma_mdio mii bus";
  260. + sprintf(mii_bus->id, "%s-%d-%d", "bcma_mdio", core->bus->num,
  261. + core->core_unit);
  262. + mii_bus->priv = bcma_mdio;
  263. + mii_bus->read = bcma_mdio_mii_read;
  264. + mii_bus->write = bcma_mdio_mii_write;
  265. + mii_bus->reset = bcma_mdio_phy_reset;
  266. + mii_bus->parent = &core->dev;
  267. + mii_bus->phy_mask = ~(1 << phyaddr);
  268. +
  269. + mii_bus->irq = kmalloc_array(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
  270. + if (!mii_bus->irq) {
  271. + err = -ENOMEM;
  272. + goto err_free_bus;
  273. + }
  274. + for (i = 0; i < PHY_MAX_ADDR; i++)
  275. + mii_bus->irq[i] = PHY_POLL;
  276. +
  277. + bcma_mdio->core = core;
  278. + bcma_mdio->phyaddr = phyaddr;
  279. +
  280. + err = mdiobus_register(mii_bus);
  281. + if (err) {
  282. + dev_err(&core->dev, "Registration of mii bus failed\n");
  283. + goto err_free_irq;
  284. + }
  285. +
  286. + return mii_bus;
  287. +
  288. +err_free_irq:
  289. + kfree(mii_bus->irq);
  290. +err_free_bus:
  291. + mdiobus_free(mii_bus);
  292. +err:
  293. + kfree(bcma_mdio);
  294. + return ERR_PTR(err);
  295. +}
  296. +
  297. +void bcma_mdio_mii_unregister(struct mii_bus *mii_bus)
  298. +{
  299. + struct bcma_mdio *bcma_mdio;
  300. +
  301. + if (!mii_bus)
  302. + return;
  303. +
  304. + bcma_mdio = mii_bus->priv;
  305. +
  306. + mdiobus_unregister(mii_bus);
  307. + kfree(mii_bus->irq);
  308. + mdiobus_free(mii_bus);
  309. + kfree(bcma_mdio);
  310. +}
  311. +
  312. +MODULE_AUTHOR("Rafał Miłecki");
  313. +MODULE_LICENSE("GPL");
  314. --- a/drivers/net/ethernet/broadcom/bgmac.c
  315. +++ b/drivers/net/ethernet/broadcom/bgmac.c
  316. @@ -759,150 +759,6 @@ error:
  317. return err;
  318. }
  319. -/**************************************************
  320. - * PHY ops
  321. - **************************************************/
  322. -
  323. -static u16 bgmac_phy_read(struct bgmac *bgmac, u8 phyaddr, u8 reg)
  324. -{
  325. - struct bcma_device *core;
  326. - u16 phy_access_addr;
  327. - u16 phy_ctl_addr;
  328. - u32 tmp;
  329. -
  330. - BUILD_BUG_ON(BGMAC_PA_DATA_MASK != BCMA_GMAC_CMN_PA_DATA_MASK);
  331. - BUILD_BUG_ON(BGMAC_PA_ADDR_MASK != BCMA_GMAC_CMN_PA_ADDR_MASK);
  332. - BUILD_BUG_ON(BGMAC_PA_ADDR_SHIFT != BCMA_GMAC_CMN_PA_ADDR_SHIFT);
  333. - BUILD_BUG_ON(BGMAC_PA_REG_MASK != BCMA_GMAC_CMN_PA_REG_MASK);
  334. - BUILD_BUG_ON(BGMAC_PA_REG_SHIFT != BCMA_GMAC_CMN_PA_REG_SHIFT);
  335. - BUILD_BUG_ON(BGMAC_PA_WRITE != BCMA_GMAC_CMN_PA_WRITE);
  336. - BUILD_BUG_ON(BGMAC_PA_START != BCMA_GMAC_CMN_PA_START);
  337. - BUILD_BUG_ON(BGMAC_PC_EPA_MASK != BCMA_GMAC_CMN_PC_EPA_MASK);
  338. - BUILD_BUG_ON(BGMAC_PC_MCT_MASK != BCMA_GMAC_CMN_PC_MCT_MASK);
  339. - BUILD_BUG_ON(BGMAC_PC_MCT_SHIFT != BCMA_GMAC_CMN_PC_MCT_SHIFT);
  340. - BUILD_BUG_ON(BGMAC_PC_MTE != BCMA_GMAC_CMN_PC_MTE);
  341. -
  342. - if (bgmac->core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  343. - core = bgmac->core->bus->drv_gmac_cmn.core;
  344. - phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS;
  345. - phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL;
  346. - } else {
  347. - core = bgmac->core;
  348. - phy_access_addr = BGMAC_PHY_ACCESS;
  349. - phy_ctl_addr = BGMAC_PHY_CNTL;
  350. - }
  351. -
  352. - tmp = bcma_read32(core, phy_ctl_addr);
  353. - tmp &= ~BGMAC_PC_EPA_MASK;
  354. - tmp |= phyaddr;
  355. - bcma_write32(core, phy_ctl_addr, tmp);
  356. -
  357. - tmp = BGMAC_PA_START;
  358. - tmp |= phyaddr << BGMAC_PA_ADDR_SHIFT;
  359. - tmp |= reg << BGMAC_PA_REG_SHIFT;
  360. - bcma_write32(core, phy_access_addr, tmp);
  361. -
  362. - if (!bgmac_wait_value(core, phy_access_addr, BGMAC_PA_START, 0, 1000)) {
  363. - dev_err(bgmac->dev, "Reading PHY %d register 0x%X failed\n",
  364. - phyaddr, reg);
  365. - return 0xffff;
  366. - }
  367. -
  368. - return bcma_read32(core, phy_access_addr) & BGMAC_PA_DATA_MASK;
  369. -}
  370. -
  371. -/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphywr */
  372. -static int bgmac_phy_write(struct bgmac *bgmac, u8 phyaddr, u8 reg, u16 value)
  373. -{
  374. - struct bcma_device *core;
  375. - u16 phy_access_addr;
  376. - u16 phy_ctl_addr;
  377. - u32 tmp;
  378. -
  379. - if (bgmac->core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  380. - core = bgmac->core->bus->drv_gmac_cmn.core;
  381. - phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS;
  382. - phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL;
  383. - } else {
  384. - core = bgmac->core;
  385. - phy_access_addr = BGMAC_PHY_ACCESS;
  386. - phy_ctl_addr = BGMAC_PHY_CNTL;
  387. - }
  388. -
  389. - tmp = bcma_read32(core, phy_ctl_addr);
  390. - tmp &= ~BGMAC_PC_EPA_MASK;
  391. - tmp |= phyaddr;
  392. - bcma_write32(core, phy_ctl_addr, tmp);
  393. -
  394. - bgmac_write(bgmac, BGMAC_INT_STATUS, BGMAC_IS_MDIO);
  395. - if (bgmac_read(bgmac, BGMAC_INT_STATUS) & BGMAC_IS_MDIO)
  396. - dev_warn(bgmac->dev, "Error setting MDIO int\n");
  397. -
  398. - tmp = BGMAC_PA_START;
  399. - tmp |= BGMAC_PA_WRITE;
  400. - tmp |= phyaddr << BGMAC_PA_ADDR_SHIFT;
  401. - tmp |= reg << BGMAC_PA_REG_SHIFT;
  402. - tmp |= value;
  403. - bcma_write32(core, phy_access_addr, tmp);
  404. -
  405. - if (!bgmac_wait_value(core, phy_access_addr, BGMAC_PA_START, 0, 1000)) {
  406. - dev_err(bgmac->dev, "Writing to PHY %d register 0x%X failed\n",
  407. - phyaddr, reg);
  408. - return -ETIMEDOUT;
  409. - }
  410. -
  411. - return 0;
  412. -}
  413. -
  414. -/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyinit */
  415. -static void bgmac_phy_init(struct bgmac *bgmac)
  416. -{
  417. - struct bcma_chipinfo *ci = &bgmac->core->bus->chipinfo;
  418. - struct bcma_drv_cc *cc = &bgmac->core->bus->drv_cc;
  419. - u8 i;
  420. -
  421. - if (ci->id == BCMA_CHIP_ID_BCM5356) {
  422. - for (i = 0; i < 5; i++) {
  423. - bgmac_phy_write(bgmac, i, 0x1f, 0x008b);
  424. - bgmac_phy_write(bgmac, i, 0x15, 0x0100);
  425. - bgmac_phy_write(bgmac, i, 0x1f, 0x000f);
  426. - bgmac_phy_write(bgmac, i, 0x12, 0x2aaa);
  427. - bgmac_phy_write(bgmac, i, 0x1f, 0x000b);
  428. - }
  429. - }
  430. - if ((ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg != 10) ||
  431. - (ci->id == BCMA_CHIP_ID_BCM4749 && ci->pkg != 10) ||
  432. - (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg != 9)) {
  433. - bcma_chipco_chipctl_maskset(cc, 2, ~0xc0000000, 0);
  434. - bcma_chipco_chipctl_maskset(cc, 4, ~0x80000000, 0);
  435. - for (i = 0; i < 5; i++) {
  436. - bgmac_phy_write(bgmac, i, 0x1f, 0x000f);
  437. - bgmac_phy_write(bgmac, i, 0x16, 0x5284);
  438. - bgmac_phy_write(bgmac, i, 0x1f, 0x000b);
  439. - bgmac_phy_write(bgmac, i, 0x17, 0x0010);
  440. - bgmac_phy_write(bgmac, i, 0x1f, 0x000f);
  441. - bgmac_phy_write(bgmac, i, 0x16, 0x5296);
  442. - bgmac_phy_write(bgmac, i, 0x17, 0x1073);
  443. - bgmac_phy_write(bgmac, i, 0x17, 0x9073);
  444. - bgmac_phy_write(bgmac, i, 0x16, 0x52b6);
  445. - bgmac_phy_write(bgmac, i, 0x17, 0x9273);
  446. - bgmac_phy_write(bgmac, i, 0x1f, 0x000b);
  447. - }
  448. - }
  449. -}
  450. -
  451. -/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyreset */
  452. -static void bgmac_phy_reset(struct bgmac *bgmac)
  453. -{
  454. - if (bgmac->phyaddr == BGMAC_PHY_NOREGS)
  455. - return;
  456. -
  457. - bgmac_phy_write(bgmac, bgmac->phyaddr, MII_BMCR, BMCR_RESET);
  458. - udelay(100);
  459. - if (bgmac_phy_read(bgmac, bgmac->phyaddr, MII_BMCR) & BMCR_RESET)
  460. - dev_err(bgmac->dev, "PHY reset failed\n");
  461. - bgmac_phy_init(bgmac);
  462. -}
  463. /**************************************************
  464. * Chip ops
  465. @@ -1159,7 +1015,8 @@ static void bgmac_chip_reset(struct bgma
  466. else
  467. bgmac_set(bgmac, BGMAC_PHY_CNTL, BGMAC_PC_MTE);
  468. bgmac_miiconfig(bgmac);
  469. - bgmac_phy_init(bgmac);
  470. + if (bgmac->mii_bus)
  471. + bgmac->mii_bus->reset(bgmac->mii_bus);
  472. netdev_reset_queue(bgmac->net_dev);
  473. }
  474. @@ -1553,17 +1410,6 @@ static const struct ethtool_ops bgmac_et
  475. * MII
  476. **************************************************/
  477. -static int bgmac_mii_read(struct mii_bus *bus, int mii_id, int regnum)
  478. -{
  479. - return bgmac_phy_read(bus->priv, mii_id, regnum);
  480. -}
  481. -
  482. -static int bgmac_mii_write(struct mii_bus *bus, int mii_id, int regnum,
  483. - u16 value)
  484. -{
  485. - return bgmac_phy_write(bus->priv, mii_id, regnum, value);
  486. -}
  487. -
  488. static void bgmac_adjust_link(struct net_device *net_dev)
  489. {
  490. struct bgmac *bgmac = netdev_priv(net_dev);
  491. @@ -1588,7 +1434,7 @@ static void bgmac_adjust_link(struct net
  492. }
  493. }
  494. -static int bgmac_fixed_phy_register(struct bgmac *bgmac)
  495. +static int bgmac_phy_connect_direct(struct bgmac *bgmac)
  496. {
  497. struct fixed_phy_status fphy_status = {
  498. .link = 1,
  499. @@ -1614,81 +1460,24 @@ static int bgmac_fixed_phy_register(stru
  500. return err;
  501. }
  502. -static int bgmac_mii_register(struct bgmac *bgmac)
  503. +static int bgmac_phy_connect(struct bgmac *bgmac)
  504. {
  505. - struct mii_bus *mii_bus;
  506. struct phy_device *phy_dev;
  507. char bus_id[MII_BUS_ID_SIZE + 3];
  508. - int i, err = 0;
  509. -
  510. - if (bgmac_is_bcm4707_family(bgmac))
  511. - return bgmac_fixed_phy_register(bgmac);
  512. -
  513. - mii_bus = mdiobus_alloc();
  514. - if (!mii_bus)
  515. - return -ENOMEM;
  516. -
  517. - mii_bus->name = "bgmac mii bus";
  518. - sprintf(mii_bus->id, "%s-%d-%d", "bgmac", bgmac->core->bus->num,
  519. - bgmac->core->core_unit);
  520. - mii_bus->priv = bgmac;
  521. - mii_bus->read = bgmac_mii_read;
  522. - mii_bus->write = bgmac_mii_write;
  523. - mii_bus->parent = &bgmac->core->dev;
  524. - mii_bus->phy_mask = ~(1 << bgmac->phyaddr);
  525. -
  526. - mii_bus->irq = kmalloc_array(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
  527. - if (!mii_bus->irq) {
  528. - err = -ENOMEM;
  529. - goto err_free_bus;
  530. - }
  531. - for (i = 0; i < PHY_MAX_ADDR; i++)
  532. - mii_bus->irq[i] = PHY_POLL;
  533. -
  534. - err = mdiobus_register(mii_bus);
  535. - if (err) {
  536. - dev_err(bgmac->dev, "Registration of mii bus failed\n");
  537. - goto err_free_irq;
  538. - }
  539. -
  540. - bgmac->mii_bus = mii_bus;
  541. /* Connect to the PHY */
  542. - snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, mii_bus->id,
  543. + snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, bgmac->mii_bus->id,
  544. bgmac->phyaddr);
  545. phy_dev = phy_connect(bgmac->net_dev, bus_id, &bgmac_adjust_link,
  546. PHY_INTERFACE_MODE_MII);
  547. if (IS_ERR(phy_dev)) {
  548. dev_err(bgmac->dev, "PHY connecton failed\n");
  549. - err = PTR_ERR(phy_dev);
  550. - goto err_unregister_bus;
  551. + return PTR_ERR(phy_dev);
  552. }
  553. - return err;
  554. -
  555. -err_unregister_bus:
  556. - mdiobus_unregister(mii_bus);
  557. -err_free_irq:
  558. - kfree(mii_bus->irq);
  559. -err_free_bus:
  560. - mdiobus_free(mii_bus);
  561. - return err;
  562. -}
  563. -
  564. -static void bgmac_mii_unregister(struct bgmac *bgmac)
  565. -{
  566. - struct mii_bus *mii_bus = bgmac->mii_bus;
  567. -
  568. - mdiobus_unregister(mii_bus);
  569. - kfree(mii_bus->irq);
  570. - mdiobus_free(mii_bus);
  571. + return 0;
  572. }
  573. -/**************************************************
  574. - * BCMA bus ops
  575. - **************************************************/
  576. -
  577. -/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipattach */
  578. static int bgmac_probe(struct bcma_device *core)
  579. {
  580. struct net_device *net_dev;
  581. @@ -1809,9 +1598,6 @@ static int bgmac_probe(struct bcma_devic
  582. if (bcm47xx_nvram_getenv("et0_no_txint", NULL, 0) == 0)
  583. bgmac->int_mask &= ~BGMAC_IS_TX_MASK;
  584. - /* TODO: reset the external phy. Specs are needed */
  585. - bgmac_phy_reset(bgmac);
  586. -
  587. bgmac->has_robosw = !!(core->bus->sprom.boardflags_lo &
  588. BGMAC_BFL_ENETROBO);
  589. if (bgmac->has_robosw)
  590. @@ -1822,10 +1608,25 @@ static int bgmac_probe(struct bcma_devic
  591. netif_napi_add(net_dev, &bgmac->napi, bgmac_poll, BGMAC_WEIGHT);
  592. - err = bgmac_mii_register(bgmac);
  593. + if (!bgmac_is_bcm4707_family(bgmac)) {
  594. + struct mii_bus *mii_bus;
  595. +
  596. + mii_bus = bcma_mdio_mii_register(core, bgmac->phyaddr);
  597. + if (!IS_ERR(mii_bus)) {
  598. + err = PTR_ERR(mii_bus);
  599. + goto err_dma_free;
  600. + }
  601. +
  602. + bgmac->mii_bus = mii_bus;
  603. + }
  604. +
  605. + if (!bgmac->mii_bus)
  606. + err = bgmac_phy_connect_direct(bgmac);
  607. + else
  608. + err = bgmac_phy_connect(bgmac);
  609. if (err) {
  610. dev_err(bgmac->dev, "Cannot connect to phy\n");
  611. - goto err_dma_free;
  612. + goto err_mii_unregister;
  613. }
  614. net_dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
  615. @@ -1835,18 +1636,19 @@ static int bgmac_probe(struct bcma_devic
  616. err = register_netdev(bgmac->net_dev);
  617. if (err) {
  618. dev_err(bgmac->dev, "Cannot register net device\n");
  619. - goto err_mii_unregister;
  620. + goto err_phy_disconnect;
  621. }
  622. netif_carrier_off(net_dev);
  623. return 0;
  624. +err_phy_disconnect:
  625. + phy_disconnect(net_dev->phydev);
  626. err_mii_unregister:
  627. - bgmac_mii_unregister(bgmac);
  628. + bcma_mdio_mii_unregister(bgmac->mii_bus);
  629. err_dma_free:
  630. bgmac_dma_free(bgmac);
  631. -
  632. err_netdev_free:
  633. bcma_set_drvdata(core, NULL);
  634. free_netdev(net_dev);
  635. @@ -1859,7 +1661,8 @@ static void bgmac_remove(struct bcma_dev
  636. struct bgmac *bgmac = bcma_get_drvdata(core);
  637. unregister_netdev(bgmac->net_dev);
  638. - bgmac_mii_unregister(bgmac);
  639. + phy_disconnect(bgmac->net_dev->phydev);
  640. + bcma_mdio_mii_unregister(bgmac->mii_bus);
  641. netif_napi_del(&bgmac->napi);
  642. bgmac_dma_free(bgmac);
  643. bcma_set_drvdata(core, NULL);
  644. --- a/drivers/net/ethernet/broadcom/bgmac.h
  645. +++ b/drivers/net/ethernet/broadcom/bgmac.h
  646. @@ -456,6 +456,9 @@ struct bgmac {
  647. bool loopback;
  648. };
  649. +struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr);
  650. +void bcma_mdio_mii_unregister(struct mii_bus *mii_bus);
  651. +
  652. static inline u32 bgmac_read(struct bgmac *bgmac, u16 offset)
  653. {
  654. return bcma_read32(bgmac->core, offset);