1
0

071-v4.8-0005-net-ethernet-bgmac-Add-platform-device-support.patch 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  1. From f6a95a24957aec5bb488c3f978c4ed508177998f Mon Sep 17 00:00:00 2001
  2. From: Jon Mason <jon.mason@broadcom.com>
  3. Date: Thu, 7 Jul 2016 19:08:57 -0400
  4. Subject: [PATCH 5/5] net: ethernet: bgmac: Add platform device support
  5. The bcma portion of the driver has been split off into a bcma specific
  6. driver. This has been mirrored for the platform driver. The last
  7. references to the bcma core struct have been changed into a generic
  8. function call. These function calls are wrappers to either the original
  9. bcma code or new platform functions that access the same areas via MMIO.
  10. This necessitated adding function pointers for both platform and bcma to
  11. hide which backend is being used from the generic bgmac code.
  12. Signed-off-by: Jon Mason <jon.mason@broadcom.com>
  13. Acked-by: Arnd Bergmann <arnd@arndb.de>
  14. Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
  15. Tested-by: Florian Fainelli <f.fainelli@gmail.com>
  16. Signed-off-by: David S. Miller <davem@davemloft.net>
  17. ---
  18. drivers/net/ethernet/broadcom/Kconfig | 23 +-
  19. drivers/net/ethernet/broadcom/Makefile | 4 +-
  20. drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c | 2 +
  21. drivers/net/ethernet/broadcom/bgmac-bcma.c | 315 +++++++++++++++++++++++
  22. drivers/net/ethernet/broadcom/bgmac-platform.c | 189 ++++++++++++++
  23. drivers/net/ethernet/broadcom/bgmac.c | 329 ++++--------------------
  24. drivers/net/ethernet/broadcom/bgmac.h | 73 +++++-
  25. 7 files changed, 650 insertions(+), 285 deletions(-)
  26. create mode 100644 drivers/net/ethernet/broadcom/bgmac-bcma.c
  27. create mode 100644 drivers/net/ethernet/broadcom/bgmac-platform.c
  28. --- a/drivers/net/ethernet/broadcom/Kconfig
  29. +++ b/drivers/net/ethernet/broadcom/Kconfig
  30. @@ -150,10 +150,18 @@ config BNX2X_VXLAN
  31. Virtual eXtensible Local Area Network (VXLAN) in the driver.
  32. config BGMAC
  33. - tristate "BCMA bus GBit core support"
  34. + tristate
  35. + help
  36. + This enables the integrated ethernet controller support for many
  37. + Broadcom (mostly iProc) SoCs. An appropriate bus interface driver
  38. + needs to be enabled to select this.
  39. +
  40. +config BGMAC_BCMA
  41. + tristate "Broadcom iProc GBit BCMA support"
  42. depends on BCMA && BCMA_HOST_SOC
  43. depends on HAS_DMA
  44. depends on BCM47XX || ARCH_BCM_5301X || COMPILE_TEST
  45. + select BGMAC
  46. select PHYLIB
  47. select FIXED_PHY
  48. ---help---
  49. @@ -162,6 +170,19 @@ config BGMAC
  50. In case of using this driver on BCM4706 it's also requires to enable
  51. BCMA_DRIVER_GMAC_CMN to make it work.
  52. +config BGMAC_PLATFORM
  53. + tristate "Broadcom iProc GBit platform support"
  54. + depends on HAS_DMA
  55. + depends on ARCH_BCM_IPROC || COMPILE_TEST
  56. + depends on OF
  57. + select BGMAC
  58. + select PHYLIB
  59. + select FIXED_PHY
  60. + default ARCH_BCM_IPROC
  61. + ---help---
  62. + Say Y here if you want to use the Broadcom iProc Gigabit Ethernet
  63. + controller through the generic platform interface
  64. +
  65. config SYSTEMPORT
  66. tristate "Broadcom SYSTEMPORT internal MAC support"
  67. depends on OF
  68. --- a/drivers/net/ethernet/broadcom/Makefile
  69. +++ b/drivers/net/ethernet/broadcom/Makefile
  70. @@ -10,6 +10,8 @@ obj-$(CONFIG_CNIC) += cnic.o
  71. obj-$(CONFIG_BNX2X) += bnx2x/
  72. obj-$(CONFIG_SB1250_MAC) += sb1250-mac.o
  73. obj-$(CONFIG_TIGON3) += tg3.o
  74. -obj-$(CONFIG_BGMAC) += bgmac.o bgmac-bcma-mdio.o
  75. +obj-$(CONFIG_BGMAC) += bgmac.o
  76. +obj-$(CONFIG_BGMAC_BCMA) += bgmac-bcma.o bgmac-bcma-mdio.o
  77. +obj-$(CONFIG_BGMAC_PLATFORM) += bgmac-platform.o
  78. obj-$(CONFIG_SYSTEMPORT) += bcmsysport.o
  79. obj-$(CONFIG_BNXT) += bnxt/
  80. --- a/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
  81. +++ b/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
  82. @@ -255,6 +255,7 @@ err:
  83. kfree(bcma_mdio);
  84. return ERR_PTR(err);
  85. }
  86. +EXPORT_SYMBOL_GPL(bcma_mdio_mii_register);
  87. void bcma_mdio_mii_unregister(struct mii_bus *mii_bus)
  88. {
  89. @@ -270,6 +271,7 @@ void bcma_mdio_mii_unregister(struct mii
  90. mdiobus_free(mii_bus);
  91. kfree(bcma_mdio);
  92. }
  93. +EXPORT_SYMBOL_GPL(bcma_mdio_mii_unregister);
  94. MODULE_AUTHOR("Rafał Miłecki");
  95. MODULE_LICENSE("GPL");
  96. --- /dev/null
  97. +++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c
  98. @@ -0,0 +1,315 @@
  99. +/*
  100. + * Driver for (BCM4706)? GBit MAC core on BCMA bus.
  101. + *
  102. + * Copyright (C) 2012 Rafał Miłecki <zajec5@gmail.com>
  103. + *
  104. + * Licensed under the GNU/GPL. See COPYING for details.
  105. + */
  106. +
  107. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  108. +
  109. +#include <linux/bcma/bcma.h>
  110. +#include <linux/brcmphy.h>
  111. +#include <linux/etherdevice.h>
  112. +#include "bgmac.h"
  113. +
  114. +static inline bool bgmac_is_bcm4707_family(struct bcma_device *core)
  115. +{
  116. + switch (core->bus->chipinfo.id) {
  117. + case BCMA_CHIP_ID_BCM4707:
  118. + case BCMA_CHIP_ID_BCM47094:
  119. + case BCMA_CHIP_ID_BCM53018:
  120. + return true;
  121. + default:
  122. + return false;
  123. + }
  124. +}
  125. +
  126. +/**************************************************
  127. + * BCMA bus ops
  128. + **************************************************/
  129. +
  130. +static u32 bcma_bgmac_read(struct bgmac *bgmac, u16 offset)
  131. +{
  132. + return bcma_read32(bgmac->bcma.core, offset);
  133. +}
  134. +
  135. +static void bcma_bgmac_write(struct bgmac *bgmac, u16 offset, u32 value)
  136. +{
  137. + bcma_write32(bgmac->bcma.core, offset, value);
  138. +}
  139. +
  140. +static u32 bcma_bgmac_idm_read(struct bgmac *bgmac, u16 offset)
  141. +{
  142. + return bcma_aread32(bgmac->bcma.core, offset);
  143. +}
  144. +
  145. +static void bcma_bgmac_idm_write(struct bgmac *bgmac, u16 offset, u32 value)
  146. +{
  147. + return bcma_awrite32(bgmac->bcma.core, offset, value);
  148. +}
  149. +
  150. +static bool bcma_bgmac_clk_enabled(struct bgmac *bgmac)
  151. +{
  152. + return bcma_core_is_enabled(bgmac->bcma.core);
  153. +}
  154. +
  155. +static void bcma_bgmac_clk_enable(struct bgmac *bgmac, u32 flags)
  156. +{
  157. + bcma_core_enable(bgmac->bcma.core, flags);
  158. +}
  159. +
  160. +static void bcma_bgmac_cco_ctl_maskset(struct bgmac *bgmac, u32 offset,
  161. + u32 mask, u32 set)
  162. +{
  163. + struct bcma_drv_cc *cc = &bgmac->bcma.core->bus->drv_cc;
  164. +
  165. + bcma_chipco_chipctl_maskset(cc, offset, mask, set);
  166. +}
  167. +
  168. +static u32 bcma_bgmac_get_bus_clock(struct bgmac *bgmac)
  169. +{
  170. + struct bcma_drv_cc *cc = &bgmac->bcma.core->bus->drv_cc;
  171. +
  172. + return bcma_pmu_get_bus_clock(cc);
  173. +}
  174. +
  175. +static void bcma_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset, u32 mask,
  176. + u32 set)
  177. +{
  178. + bcma_maskset32(bgmac->bcma.cmn, offset, mask, set);
  179. +}
  180. +
  181. +static const struct bcma_device_id bgmac_bcma_tbl[] = {
  182. + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT,
  183. + BCMA_ANY_REV, BCMA_ANY_CLASS),
  184. + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_MAC_GBIT, BCMA_ANY_REV,
  185. + BCMA_ANY_CLASS),
  186. + {},
  187. +};
  188. +MODULE_DEVICE_TABLE(bcma, bgmac_bcma_tbl);
  189. +
  190. +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipattach */
  191. +static int bgmac_probe(struct bcma_device *core)
  192. +{
  193. + struct ssb_sprom *sprom = &core->bus->sprom;
  194. + struct mii_bus *mii_bus;
  195. + struct bgmac *bgmac;
  196. + u8 *mac;
  197. + int err;
  198. +
  199. + bgmac = kzalloc(sizeof(*bgmac), GFP_KERNEL);
  200. + if (!bgmac)
  201. + return -ENOMEM;
  202. +
  203. + bgmac->bcma.core = core;
  204. + bgmac->dev = &core->dev;
  205. + bgmac->dma_dev = core->dma_dev;
  206. + bgmac->irq = core->irq;
  207. +
  208. + bcma_set_drvdata(core, bgmac);
  209. +
  210. + switch (core->core_unit) {
  211. + case 0:
  212. + mac = sprom->et0mac;
  213. + break;
  214. + case 1:
  215. + mac = sprom->et1mac;
  216. + break;
  217. + case 2:
  218. + mac = sprom->et2mac;
  219. + break;
  220. + default:
  221. + dev_err(bgmac->dev, "Unsupported core_unit %d\n",
  222. + core->core_unit);
  223. + err = -ENOTSUPP;
  224. + goto err;
  225. + }
  226. +
  227. + ether_addr_copy(bgmac->mac_addr, mac);
  228. +
  229. + /* On BCM4706 we need common core to access PHY */
  230. + if (core->id.id == BCMA_CORE_4706_MAC_GBIT &&
  231. + !core->bus->drv_gmac_cmn.core) {
  232. + dev_err(bgmac->dev, "GMAC CMN core not found (required for BCM4706)\n");
  233. + err = -ENODEV;
  234. + goto err;
  235. + }
  236. + bgmac->bcma.cmn = core->bus->drv_gmac_cmn.core;
  237. +
  238. + switch (core->core_unit) {
  239. + case 0:
  240. + bgmac->phyaddr = sprom->et0phyaddr;
  241. + break;
  242. + case 1:
  243. + bgmac->phyaddr = sprom->et1phyaddr;
  244. + break;
  245. + case 2:
  246. + bgmac->phyaddr = sprom->et2phyaddr;
  247. + break;
  248. + }
  249. + bgmac->phyaddr &= BGMAC_PHY_MASK;
  250. + if (bgmac->phyaddr == BGMAC_PHY_MASK) {
  251. + dev_err(bgmac->dev, "No PHY found\n");
  252. + err = -ENODEV;
  253. + goto err;
  254. + }
  255. + dev_info(bgmac->dev, "Found PHY addr: %d%s\n", bgmac->phyaddr,
  256. + bgmac->phyaddr == BGMAC_PHY_NOREGS ? " (NOREGS)" : "");
  257. +
  258. + if (!bgmac_is_bcm4707_family(core)) {
  259. + mii_bus = bcma_mdio_mii_register(core, bgmac->phyaddr);
  260. + if (!IS_ERR(mii_bus)) {
  261. + err = PTR_ERR(mii_bus);
  262. + goto err;
  263. + }
  264. +
  265. + bgmac->mii_bus = mii_bus;
  266. + }
  267. +
  268. + if (core->bus->hosttype == BCMA_HOSTTYPE_PCI) {
  269. + dev_err(bgmac->dev, "PCI setup not implemented\n");
  270. + err = -ENOTSUPP;
  271. + goto err1;
  272. + }
  273. +
  274. + bgmac->has_robosw = !!(core->bus->sprom.boardflags_lo &
  275. + BGMAC_BFL_ENETROBO);
  276. + if (bgmac->has_robosw)
  277. + dev_warn(bgmac->dev, "Support for Roboswitch not implemented\n");
  278. +
  279. + if (core->bus->sprom.boardflags_lo & BGMAC_BFL_ENETADM)
  280. + dev_warn(bgmac->dev, "Support for ADMtek ethernet switch not implemented\n");
  281. +
  282. + /* Feature Flags */
  283. + switch (core->bus->chipinfo.id) {
  284. + case BCMA_CHIP_ID_BCM5357:
  285. + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
  286. + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  287. + bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1;
  288. + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY;
  289. + if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM47186) {
  290. + bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
  291. + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII;
  292. + }
  293. + if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM5358)
  294. + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_EPHYRMII;
  295. + break;
  296. + case BCMA_CHIP_ID_BCM53572:
  297. + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
  298. + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  299. + bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1;
  300. + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY;
  301. + if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM47188) {
  302. + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII;
  303. + bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
  304. + }
  305. + break;
  306. + case BCMA_CHIP_ID_BCM4749:
  307. + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
  308. + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  309. + bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1;
  310. + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY;
  311. + if (core->bus->chipinfo.pkg == 10) {
  312. + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII;
  313. + bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
  314. + }
  315. + break;
  316. + case BCMA_CHIP_ID_BCM4716:
  317. + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  318. + /* fallthrough */
  319. + case BCMA_CHIP_ID_BCM47162:
  320. + bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL2;
  321. + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
  322. + break;
  323. + /* bcm4707_family */
  324. + case BCMA_CHIP_ID_BCM4707:
  325. + case BCMA_CHIP_ID_BCM47094:
  326. + case BCMA_CHIP_ID_BCM53018:
  327. + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  328. + bgmac->feature_flags |= BGMAC_FEAT_NO_RESET;
  329. + bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500;
  330. + break;
  331. + default:
  332. + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  333. + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
  334. + }
  335. +
  336. + if (!bgmac_is_bcm4707_family(core) && core->id.rev > 2)
  337. + bgmac->feature_flags |= BGMAC_FEAT_MISC_PLL_REQ;
  338. +
  339. + if (core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  340. + bgmac->feature_flags |= BGMAC_FEAT_CMN_PHY_CTL;
  341. + bgmac->feature_flags |= BGMAC_FEAT_NO_CLR_MIB;
  342. + }
  343. +
  344. + if (core->id.rev >= 4) {
  345. + bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4;
  346. + bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP;
  347. + bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP;
  348. + }
  349. +
  350. + bgmac->read = bcma_bgmac_read;
  351. + bgmac->write = bcma_bgmac_write;
  352. + bgmac->idm_read = bcma_bgmac_idm_read;
  353. + bgmac->idm_write = bcma_bgmac_idm_write;
  354. + bgmac->clk_enabled = bcma_bgmac_clk_enabled;
  355. + bgmac->clk_enable = bcma_bgmac_clk_enable;
  356. + bgmac->cco_ctl_maskset = bcma_bgmac_cco_ctl_maskset;
  357. + bgmac->get_bus_clock = bcma_bgmac_get_bus_clock;
  358. + bgmac->cmn_maskset32 = bcma_bgmac_cmn_maskset32;
  359. +
  360. + err = bgmac_enet_probe(bgmac);
  361. + if (err)
  362. + goto err1;
  363. +
  364. + return 0;
  365. +
  366. +err1:
  367. + bcma_mdio_mii_unregister(bgmac->mii_bus);
  368. +err:
  369. + kfree(bgmac);
  370. + bcma_set_drvdata(core, NULL);
  371. +
  372. + return err;
  373. +}
  374. +
  375. +static void bgmac_remove(struct bcma_device *core)
  376. +{
  377. + struct bgmac *bgmac = bcma_get_drvdata(core);
  378. +
  379. + bcma_mdio_mii_unregister(bgmac->mii_bus);
  380. + bgmac_enet_remove(bgmac);
  381. + bcma_set_drvdata(core, NULL);
  382. + kfree(bgmac);
  383. +}
  384. +
  385. +static struct bcma_driver bgmac_bcma_driver = {
  386. + .name = KBUILD_MODNAME,
  387. + .id_table = bgmac_bcma_tbl,
  388. + .probe = bgmac_probe,
  389. + .remove = bgmac_remove,
  390. +};
  391. +
  392. +static int __init bgmac_init(void)
  393. +{
  394. + int err;
  395. +
  396. + err = bcma_driver_register(&bgmac_bcma_driver);
  397. + if (err)
  398. + return err;
  399. + pr_info("Broadcom 47xx GBit MAC driver loaded\n");
  400. +
  401. + return 0;
  402. +}
  403. +
  404. +static void __exit bgmac_exit(void)
  405. +{
  406. + bcma_driver_unregister(&bgmac_bcma_driver);
  407. +}
  408. +
  409. +module_init(bgmac_init)
  410. +module_exit(bgmac_exit)
  411. +
  412. +MODULE_AUTHOR("Rafał Miłecki");
  413. +MODULE_LICENSE("GPL");
  414. --- /dev/null
  415. +++ b/drivers/net/ethernet/broadcom/bgmac-platform.c
  416. @@ -0,0 +1,189 @@
  417. +/*
  418. + * Copyright (C) 2016 Broadcom
  419. + *
  420. + * This program is free software; you can redistribute it and/or
  421. + * modify it under the terms of the GNU General Public License as
  422. + * published by the Free Software Foundation version 2.
  423. + *
  424. + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  425. + * kind, whether express or implied; without even the implied warranty
  426. + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  427. + * GNU General Public License for more details.
  428. + */
  429. +
  430. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  431. +
  432. +#include <linux/bcma/bcma.h>
  433. +#include <linux/etherdevice.h>
  434. +#include <linux/of_address.h>
  435. +#include <linux/of_net.h>
  436. +#include "bgmac.h"
  437. +
  438. +static u32 platform_bgmac_read(struct bgmac *bgmac, u16 offset)
  439. +{
  440. + return readl(bgmac->plat.base + offset);
  441. +}
  442. +
  443. +static void platform_bgmac_write(struct bgmac *bgmac, u16 offset, u32 value)
  444. +{
  445. + writel(value, bgmac->plat.base + offset);
  446. +}
  447. +
  448. +static u32 platform_bgmac_idm_read(struct bgmac *bgmac, u16 offset)
  449. +{
  450. + return readl(bgmac->plat.idm_base + offset);
  451. +}
  452. +
  453. +static void platform_bgmac_idm_write(struct bgmac *bgmac, u16 offset, u32 value)
  454. +{
  455. + return writel(value, bgmac->plat.idm_base + offset);
  456. +}
  457. +
  458. +static bool platform_bgmac_clk_enabled(struct bgmac *bgmac)
  459. +{
  460. + if ((bgmac_idm_read(bgmac, BCMA_IOCTL) &
  461. + (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC)) != BCMA_IOCTL_CLK)
  462. + return false;
  463. + if (bgmac_idm_read(bgmac, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET)
  464. + return false;
  465. + return true;
  466. +}
  467. +
  468. +static void platform_bgmac_clk_enable(struct bgmac *bgmac, u32 flags)
  469. +{
  470. + bgmac_idm_write(bgmac, BCMA_IOCTL,
  471. + (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC | flags));
  472. + bgmac_idm_read(bgmac, BCMA_IOCTL);
  473. +
  474. + bgmac_idm_write(bgmac, BCMA_RESET_CTL, 0);
  475. + bgmac_idm_read(bgmac, BCMA_RESET_CTL);
  476. + udelay(1);
  477. +
  478. + bgmac_idm_write(bgmac, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags));
  479. + bgmac_idm_read(bgmac, BCMA_IOCTL);
  480. + udelay(1);
  481. +}
  482. +
  483. +static void platform_bgmac_cco_ctl_maskset(struct bgmac *bgmac, u32 offset,
  484. + u32 mask, u32 set)
  485. +{
  486. + /* This shouldn't be encountered */
  487. + WARN_ON(1);
  488. +}
  489. +
  490. +static u32 platform_bgmac_get_bus_clock(struct bgmac *bgmac)
  491. +{
  492. + /* This shouldn't be encountered */
  493. + WARN_ON(1);
  494. +
  495. + return 0;
  496. +}
  497. +
  498. +static void platform_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset,
  499. + u32 mask, u32 set)
  500. +{
  501. + /* This shouldn't be encountered */
  502. + WARN_ON(1);
  503. +}
  504. +
  505. +static int bgmac_probe(struct platform_device *pdev)
  506. +{
  507. + struct device_node *np = pdev->dev.of_node;
  508. + struct bgmac *bgmac;
  509. + struct resource *regs;
  510. + const u8 *mac_addr;
  511. +
  512. + bgmac = devm_kzalloc(&pdev->dev, sizeof(*bgmac), GFP_KERNEL);
  513. + if (!bgmac)
  514. + return -ENOMEM;
  515. +
  516. + platform_set_drvdata(pdev, bgmac);
  517. +
  518. + /* Set the features of the 4707 family */
  519. + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  520. + bgmac->feature_flags |= BGMAC_FEAT_NO_RESET;
  521. + bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500;
  522. + bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4;
  523. + bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP;
  524. + bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP;
  525. +
  526. + bgmac->dev = &pdev->dev;
  527. + bgmac->dma_dev = &pdev->dev;
  528. +
  529. + mac_addr = of_get_mac_address(np);
  530. + if (mac_addr)
  531. + ether_addr_copy(bgmac->mac_addr, mac_addr);
  532. + else
  533. + dev_warn(&pdev->dev, "MAC address not present in device tree\n");
  534. +
  535. + bgmac->irq = platform_get_irq(pdev, 0);
  536. + if (bgmac->irq < 0) {
  537. + dev_err(&pdev->dev, "Unable to obtain IRQ\n");
  538. + return bgmac->irq;
  539. + }
  540. +
  541. + regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "amac_base");
  542. + if (!regs) {
  543. + dev_err(&pdev->dev, "Unable to obtain base resource\n");
  544. + return -EINVAL;
  545. + }
  546. +
  547. + bgmac->plat.base = devm_ioremap_resource(&pdev->dev, regs);
  548. + if (IS_ERR(bgmac->plat.base)) {
  549. + dev_err(&pdev->dev, "Unable to map base resource\n");
  550. + return PTR_ERR(bgmac->plat.base);
  551. + }
  552. +
  553. + regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "idm_base");
  554. + if (!regs) {
  555. + dev_err(&pdev->dev, "Unable to obtain idm resource\n");
  556. + return -EINVAL;
  557. + }
  558. +
  559. + bgmac->plat.idm_base = devm_ioremap_resource(&pdev->dev, regs);
  560. + if (!bgmac->plat.idm_base) {
  561. + dev_err(&pdev->dev, "Unable to map idm resource\n");
  562. + return PTR_ERR(bgmac->plat.idm_base);
  563. + }
  564. +
  565. + bgmac->read = platform_bgmac_read;
  566. + bgmac->write = platform_bgmac_write;
  567. + bgmac->idm_read = platform_bgmac_idm_read;
  568. + bgmac->idm_write = platform_bgmac_idm_write;
  569. + bgmac->clk_enabled = platform_bgmac_clk_enabled;
  570. + bgmac->clk_enable = platform_bgmac_clk_enable;
  571. + bgmac->cco_ctl_maskset = platform_bgmac_cco_ctl_maskset;
  572. + bgmac->get_bus_clock = platform_bgmac_get_bus_clock;
  573. + bgmac->cmn_maskset32 = platform_bgmac_cmn_maskset32;
  574. +
  575. + return bgmac_enet_probe(bgmac);
  576. +}
  577. +
  578. +static int bgmac_remove(struct platform_device *pdev)
  579. +{
  580. + struct bgmac *bgmac = platform_get_drvdata(pdev);
  581. +
  582. + bgmac_enet_remove(bgmac);
  583. +
  584. + return 0;
  585. +}
  586. +
  587. +static const struct of_device_id bgmac_of_enet_match[] = {
  588. + {.compatible = "brcm,amac",},
  589. + {.compatible = "brcm,nsp-amac",},
  590. + {},
  591. +};
  592. +
  593. +MODULE_DEVICE_TABLE(of, bgmac_of_enet_match);
  594. +
  595. +static struct platform_driver bgmac_enet_driver = {
  596. + .driver = {
  597. + .name = "bgmac-enet",
  598. + .of_match_table = bgmac_of_enet_match,
  599. + },
  600. + .probe = bgmac_probe,
  601. + .remove = bgmac_remove,
  602. +};
  603. +
  604. +module_platform_driver(bgmac_enet_driver);
  605. +MODULE_LICENSE("GPL");
  606. --- a/drivers/net/ethernet/broadcom/bgmac.c
  607. +++ b/drivers/net/ethernet/broadcom/bgmac.c
  608. @@ -6,51 +6,27 @@
  609. * Licensed under the GNU/GPL. See COPYING for details.
  610. */
  611. -#include "bgmac.h"
  612. -#include <linux/kernel.h>
  613. -#include <linux/module.h>
  614. -#include <linux/delay.h>
  615. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  616. +
  617. +#include <linux/bcma/bcma.h>
  618. #include <linux/etherdevice.h>
  619. -#include <linux/mii.h>
  620. -#include <linux/phy.h>
  621. -#include <linux/phy_fixed.h>
  622. -#include <linux/interrupt.h>
  623. -#include <linux/dma-mapping.h>
  624. #include <linux/bcm47xx_nvram.h>
  625. +#include "bgmac.h"
  626. -static const struct bcma_device_id bgmac_bcma_tbl[] = {
  627. - BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT, BCMA_ANY_REV, BCMA_ANY_CLASS),
  628. - BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_MAC_GBIT, BCMA_ANY_REV, BCMA_ANY_CLASS),
  629. - {},
  630. -};
  631. -MODULE_DEVICE_TABLE(bcma, bgmac_bcma_tbl);
  632. -
  633. -static inline bool bgmac_is_bcm4707_family(struct bgmac *bgmac)
  634. -{
  635. - switch (bgmac->core->bus->chipinfo.id) {
  636. - case BCMA_CHIP_ID_BCM4707:
  637. - case BCMA_CHIP_ID_BCM47094:
  638. - case BCMA_CHIP_ID_BCM53018:
  639. - return true;
  640. - default:
  641. - return false;
  642. - }
  643. -}
  644. -
  645. -static bool bgmac_wait_value(struct bcma_device *core, u16 reg, u32 mask,
  646. +static bool bgmac_wait_value(struct bgmac *bgmac, u16 reg, u32 mask,
  647. u32 value, int timeout)
  648. {
  649. u32 val;
  650. int i;
  651. for (i = 0; i < timeout / 10; i++) {
  652. - val = bcma_read32(core, reg);
  653. + val = bgmac_read(bgmac, reg);
  654. if ((val & mask) == value)
  655. return true;
  656. udelay(10);
  657. }
  658. - dev_err(&core->dev, "Timeout waiting for reg 0x%X\n", reg);
  659. + dev_err(bgmac->dev, "Timeout waiting for reg 0x%X\n", reg);
  660. return false;
  661. }
  662. @@ -89,7 +65,7 @@ static void bgmac_dma_tx_reset(struct bg
  663. /* Remove SUSPEND bit */
  664. bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_TX_CTL, 0);
  665. - if (!bgmac_wait_value(bgmac->core,
  666. + if (!bgmac_wait_value(bgmac,
  667. ring->mmio_base + BGMAC_DMA_TX_STATUS,
  668. BGMAC_DMA_TX_STAT, BGMAC_DMA_TX_STAT_DISABLED,
  669. 10000)) {
  670. @@ -317,7 +293,7 @@ static void bgmac_dma_rx_reset(struct bg
  671. return;
  672. bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_RX_CTL, 0);
  673. - if (!bgmac_wait_value(bgmac->core,
  674. + if (!bgmac_wait_value(bgmac,
  675. ring->mmio_base + BGMAC_DMA_RX_STATUS,
  676. BGMAC_DMA_RX_STAT, BGMAC_DMA_RX_STAT_DISABLED,
  677. 10000))
  678. @@ -643,7 +619,7 @@ static int bgmac_dma_alloc(struct bgmac
  679. BUILD_BUG_ON(BGMAC_MAX_TX_RINGS > ARRAY_SIZE(ring_base));
  680. BUILD_BUG_ON(BGMAC_MAX_RX_RINGS > ARRAY_SIZE(ring_base));
  681. - if (!(bcma_aread32(bgmac->core, BCMA_IOST) & BCMA_IOST_DMA64)) {
  682. + if (!(bgmac_idm_read(bgmac, BCMA_IOST) & BCMA_IOST_DMA64)) {
  683. dev_err(bgmac->dev, "Core does not report 64-bit DMA\n");
  684. return -ENOTSUPP;
  685. }
  686. @@ -875,12 +851,10 @@ static void bgmac_mac_speed(struct bgmac
  687. static void bgmac_miiconfig(struct bgmac *bgmac)
  688. {
  689. - struct bcma_device *core = bgmac->core;
  690. -
  691. if (bgmac->feature_flags & BGMAC_FEAT_FORCE_SPEED_2500) {
  692. - bcma_awrite32(core, BCMA_IOCTL,
  693. - bcma_aread32(core, BCMA_IOCTL) | 0x40 |
  694. - BGMAC_BCMA_IOCTL_SW_CLKEN);
  695. + bgmac_idm_write(bgmac, BCMA_IOCTL,
  696. + bgmac_idm_read(bgmac, BCMA_IOCTL) | 0x40 |
  697. + BGMAC_BCMA_IOCTL_SW_CLKEN);
  698. bgmac->mac_speed = SPEED_2500;
  699. bgmac->mac_duplex = DUPLEX_FULL;
  700. bgmac_mac_speed(bgmac);
  701. @@ -900,12 +874,11 @@ static void bgmac_miiconfig(struct bgmac
  702. /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipreset */
  703. static void bgmac_chip_reset(struct bgmac *bgmac)
  704. {
  705. - struct bcma_device *core = bgmac->core;
  706. u32 cmdcfg_sr;
  707. u32 iost;
  708. int i;
  709. - if (bcma_core_is_enabled(core)) {
  710. + if (bgmac_clk_enabled(bgmac)) {
  711. if (!bgmac->stats_grabbed) {
  712. /* bgmac_chip_stats_update(bgmac); */
  713. bgmac->stats_grabbed = true;
  714. @@ -923,7 +896,7 @@ static void bgmac_chip_reset(struct bgma
  715. /* TODO: Clear software multicast filter list */
  716. }
  717. - iost = bcma_aread32(core, BCMA_IOST);
  718. + iost = bgmac_idm_read(bgmac, BCMA_IOST);
  719. if (bgmac->feature_flags & BGMAC_FEAT_IOST_ATTACHED)
  720. iost &= ~BGMAC_BCMA_IOST_ATTACHED;
  721. @@ -935,21 +908,20 @@ static void bgmac_chip_reset(struct bgma
  722. if (!bgmac->has_robosw)
  723. flags |= BGMAC_BCMA_IOCTL_SW_RESET;
  724. }
  725. - bcma_core_enable(core, flags);
  726. + bgmac_clk_enable(bgmac, flags);
  727. }
  728. /* Request Misc PLL for corerev > 2 */
  729. if (bgmac->feature_flags & BGMAC_FEAT_MISC_PLL_REQ) {
  730. bgmac_set(bgmac, BCMA_CLKCTLST,
  731. BGMAC_BCMA_CLKCTLST_MISC_PLL_REQ);
  732. - bgmac_wait_value(bgmac->core, BCMA_CLKCTLST,
  733. + bgmac_wait_value(bgmac, BCMA_CLKCTLST,
  734. BGMAC_BCMA_CLKCTLST_MISC_PLL_ST,
  735. BGMAC_BCMA_CLKCTLST_MISC_PLL_ST,
  736. 1000);
  737. }
  738. if (bgmac->feature_flags & BGMAC_FEAT_SW_TYPE_PHY) {
  739. - struct bcma_drv_cc *cc = &bgmac->core->bus->drv_cc;
  740. u8 et_swtype = 0;
  741. u8 sw_type = BGMAC_CHIPCTL_1_SW_TYPE_EPHY |
  742. BGMAC_CHIPCTL_1_IF_TYPE_MII;
  743. @@ -968,16 +940,15 @@ static void bgmac_chip_reset(struct bgma
  744. sw_type = BGMAC_CHIPCTL_1_IF_TYPE_RGMII |
  745. BGMAC_CHIPCTL_1_SW_TYPE_RGMII;
  746. }
  747. - bcma_chipco_chipctl_maskset(cc, 1,
  748. - ~(BGMAC_CHIPCTL_1_IF_TYPE_MASK |
  749. - BGMAC_CHIPCTL_1_SW_TYPE_MASK),
  750. - sw_type);
  751. + bgmac_cco_ctl_maskset(bgmac, 1, ~(BGMAC_CHIPCTL_1_IF_TYPE_MASK |
  752. + BGMAC_CHIPCTL_1_SW_TYPE_MASK),
  753. + sw_type);
  754. }
  755. if (iost & BGMAC_BCMA_IOST_ATTACHED && !bgmac->has_robosw)
  756. - bcma_awrite32(core, BCMA_IOCTL,
  757. - bcma_aread32(core, BCMA_IOCTL) &
  758. - ~BGMAC_BCMA_IOCTL_SW_RESET);
  759. + bgmac_idm_write(bgmac, BCMA_IOCTL,
  760. + bgmac_idm_read(bgmac, BCMA_IOCTL) &
  761. + ~BGMAC_BCMA_IOCTL_SW_RESET);
  762. /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/gmac_reset
  763. * Specs don't say about using BGMAC_CMDCFG_SR, but in this routine
  764. @@ -1013,8 +984,8 @@ static void bgmac_chip_reset(struct bgma
  765. bgmac_clear_mib(bgmac);
  766. if (bgmac->feature_flags & BGMAC_FEAT_CMN_PHY_CTL)
  767. - bcma_maskset32(bgmac->cmn, BCMA_GMAC_CMN_PHY_CTL, ~0,
  768. - BCMA_GMAC_CMN_PC_MTE);
  769. + bgmac_cmn_maskset32(bgmac, BCMA_GMAC_CMN_PHY_CTL, ~0,
  770. + BCMA_GMAC_CMN_PC_MTE);
  771. else
  772. bgmac_set(bgmac, BGMAC_PHY_CNTL, BGMAC_PC_MTE);
  773. bgmac_miiconfig(bgmac);
  774. @@ -1059,8 +1030,8 @@ static void bgmac_enable(struct bgmac *b
  775. if (bgmac->feature_flags & BGMAC_FEAT_CLKCTLST || mode != 0)
  776. bgmac_set(bgmac, BCMA_CLKCTLST, BCMA_CLKCTLST_FORCEHT);
  777. if (bgmac->feature_flags & BGMAC_FEAT_CLKCTLST && mode == 2)
  778. - bcma_chipco_chipctl_maskset(&bgmac->core->bus->drv_cc, 1, ~0,
  779. - BGMAC_CHIPCTL_1_RXC_DLL_BYPASS);
  780. + bgmac_cco_ctl_maskset(bgmac, 1, ~0,
  781. + BGMAC_CHIPCTL_1_RXC_DLL_BYPASS);
  782. if (bgmac->feature_flags & (BGMAC_FEAT_FLW_CTRL1 |
  783. BGMAC_FEAT_FLW_CTRL2)) {
  784. @@ -1082,8 +1053,7 @@ static void bgmac_enable(struct bgmac *b
  785. rxq_ctl = bgmac_read(bgmac, BGMAC_RXQ_CTL);
  786. rxq_ctl &= ~BGMAC_RXQ_CTL_MDP_MASK;
  787. - bp_clk = bcma_pmu_get_bus_clock(&bgmac->core->bus->drv_cc) /
  788. - 1000000;
  789. + bp_clk = bgmac_get_bus_clock(bgmac) / 1000000;
  790. mdp = (bp_clk * 128 / 1000) - 3;
  791. rxq_ctl |= (mdp << BGMAC_RXQ_CTL_MDP_SHIFT);
  792. bgmac_write(bgmac, BGMAC_RXQ_CTL, rxq_ctl);
  793. @@ -1178,7 +1148,7 @@ static int bgmac_open(struct net_device
  794. /* Specs say about reclaiming rings here, but we do that in DMA init */
  795. bgmac_chip_init(bgmac);
  796. - err = request_irq(bgmac->core->irq, bgmac_interrupt, IRQF_SHARED,
  797. + err = request_irq(bgmac->irq, bgmac_interrupt, IRQF_SHARED,
  798. KBUILD_MODNAME, net_dev);
  799. if (err < 0) {
  800. dev_err(bgmac->dev, "IRQ request error: %d!\n", err);
  801. @@ -1204,7 +1174,7 @@ static int bgmac_stop(struct net_device
  802. napi_disable(&bgmac->napi);
  803. bgmac_chip_intrs_off(bgmac);
  804. - free_irq(bgmac->core->irq, net_dev);
  805. + free_irq(bgmac->irq, net_dev);
  806. bgmac_chip_reset(bgmac);
  807. bgmac_dma_cleanup(bgmac);
  808. @@ -1399,7 +1369,7 @@ static void bgmac_get_drvinfo(struct net
  809. struct ethtool_drvinfo *info)
  810. {
  811. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  812. - strlcpy(info->bus_info, "BCMA", sizeof(info->bus_info));
  813. + strlcpy(info->bus_info, "AXI", sizeof(info->bus_info));
  814. }
  815. static const struct ethtool_ops bgmac_ethtool_ops = {
  816. @@ -1483,116 +1453,41 @@ static int bgmac_phy_connect(struct bgma
  817. return 0;
  818. }
  819. -static int bgmac_probe(struct bcma_device *core)
  820. +int bgmac_enet_probe(struct bgmac *info)
  821. {
  822. struct net_device *net_dev;
  823. struct bgmac *bgmac;
  824. - struct ssb_sprom *sprom = &core->bus->sprom;
  825. - u8 *mac;
  826. int err;
  827. - switch (core->core_unit) {
  828. - case 0:
  829. - mac = sprom->et0mac;
  830. - break;
  831. - case 1:
  832. - mac = sprom->et1mac;
  833. - break;
  834. - case 2:
  835. - mac = sprom->et2mac;
  836. - break;
  837. - default:
  838. - dev_err(&core->dev, "Unsupported core_unit %d\n",
  839. - core->core_unit);
  840. - return -ENOTSUPP;
  841. - }
  842. -
  843. - if (!is_valid_ether_addr(mac)) {
  844. - dev_err(&core->dev, "Invalid MAC addr: %pM\n", mac);
  845. - eth_random_addr(mac);
  846. - dev_warn(&core->dev, "Using random MAC: %pM\n", mac);
  847. - }
  848. -
  849. - /* This (reset &) enable is not preset in specs or reference driver but
  850. - * Broadcom does it in arch PCI code when enabling fake PCI device.
  851. - */
  852. - bcma_core_enable(core, 0);
  853. -
  854. /* Allocation and references */
  855. net_dev = alloc_etherdev(sizeof(*bgmac));
  856. if (!net_dev)
  857. return -ENOMEM;
  858. +
  859. net_dev->netdev_ops = &bgmac_netdev_ops;
  860. - net_dev->irq = core->irq;
  861. net_dev->ethtool_ops = &bgmac_ethtool_ops;
  862. bgmac = netdev_priv(net_dev);
  863. - bgmac->dev = &core->dev;
  864. - bgmac->dma_dev = core->dma_dev;
  865. + memcpy(bgmac, info, sizeof(*bgmac));
  866. bgmac->net_dev = net_dev;
  867. - bgmac->core = core;
  868. - bcma_set_drvdata(core, bgmac);
  869. - SET_NETDEV_DEV(net_dev, &core->dev);
  870. -
  871. - /* Defaults */
  872. - memcpy(bgmac->net_dev->dev_addr, mac, ETH_ALEN);
  873. -
  874. - /* On BCM4706 we need common core to access PHY */
  875. - if (core->id.id == BCMA_CORE_4706_MAC_GBIT &&
  876. - !core->bus->drv_gmac_cmn.core) {
  877. - dev_err(bgmac->dev, "GMAC CMN core not found (required for BCM4706)\n");
  878. - err = -ENODEV;
  879. - goto err_netdev_free;
  880. - }
  881. - bgmac->cmn = core->bus->drv_gmac_cmn.core;
  882. + net_dev->irq = bgmac->irq;
  883. + SET_NETDEV_DEV(net_dev, bgmac->dev);
  884. - switch (core->core_unit) {
  885. - case 0:
  886. - bgmac->phyaddr = sprom->et0phyaddr;
  887. - break;
  888. - case 1:
  889. - bgmac->phyaddr = sprom->et1phyaddr;
  890. - break;
  891. - case 2:
  892. - bgmac->phyaddr = sprom->et2phyaddr;
  893. - break;
  894. + if (!is_valid_ether_addr(bgmac->mac_addr)) {
  895. + dev_err(bgmac->dev, "Invalid MAC addr: %pM\n",
  896. + bgmac->mac_addr);
  897. + eth_random_addr(bgmac->mac_addr);
  898. + dev_warn(bgmac->dev, "Using random MAC: %pM\n",
  899. + bgmac->mac_addr);
  900. }
  901. - bgmac->phyaddr &= BGMAC_PHY_MASK;
  902. - if (bgmac->phyaddr == BGMAC_PHY_MASK) {
  903. - dev_err(bgmac->dev, "No PHY found\n");
  904. - err = -ENODEV;
  905. - goto err_netdev_free;
  906. - }
  907. - dev_info(bgmac->dev, "Found PHY addr: %d%s\n", bgmac->phyaddr,
  908. - bgmac->phyaddr == BGMAC_PHY_NOREGS ? " (NOREGS)" : "");
  909. + ether_addr_copy(net_dev->dev_addr, bgmac->mac_addr);
  910. - if (core->bus->hosttype == BCMA_HOSTTYPE_PCI) {
  911. - dev_err(bgmac->dev, "PCI setup not implemented\n");
  912. - err = -ENOTSUPP;
  913. - goto err_netdev_free;
  914. - }
  915. + /* This (reset &) enable is not preset in specs or reference driver but
  916. + * Broadcom does it in arch PCI code when enabling fake PCI device.
  917. + */
  918. + bgmac_clk_enable(bgmac, 0);
  919. bgmac_chip_reset(bgmac);
  920. - /* For Northstar, we have to take all GMAC core out of reset */
  921. - if (bgmac_is_bcm4707_family(bgmac)) {
  922. - struct bcma_device *ns_core;
  923. - int ns_gmac;
  924. -
  925. - /* Northstar has 4 GMAC cores */
  926. - for (ns_gmac = 0; ns_gmac < 4; ns_gmac++) {
  927. - /* As Northstar requirement, we have to reset all GMACs
  928. - * before accessing one. bgmac_chip_reset() call
  929. - * bcma_core_enable() for this core. Then the other
  930. - * three GMACs didn't reset. We do it here.
  931. - */
  932. - ns_core = bcma_find_core_unit(core->bus,
  933. - BCMA_CORE_MAC_GBIT,
  934. - ns_gmac);
  935. - if (ns_core && !bcma_core_is_enabled(ns_core))
  936. - bcma_core_enable(ns_core, 0);
  937. - }
  938. - }
  939. -
  940. err = bgmac_dma_alloc(bgmac);
  941. if (err) {
  942. dev_err(bgmac->dev, "Unable to alloc memory for DMA\n");
  943. @@ -1603,103 +1498,15 @@ static int bgmac_probe(struct bcma_devic
  944. if (bcm47xx_nvram_getenv("et0_no_txint", NULL, 0) == 0)
  945. bgmac->int_mask &= ~BGMAC_IS_TX_MASK;
  946. - bgmac->has_robosw = !!(core->bus->sprom.boardflags_lo &
  947. - BGMAC_BFL_ENETROBO);
  948. - if (bgmac->has_robosw)
  949. - dev_warn(bgmac->dev, "Support for Roboswitch not implemented\n");
  950. -
  951. - if (core->bus->sprom.boardflags_lo & BGMAC_BFL_ENETADM)
  952. - dev_warn(bgmac->dev, "Support for ADMtek ethernet switch not implemented\n");
  953. -
  954. - /* Feature Flags */
  955. - switch (core->bus->chipinfo.id) {
  956. - case BCMA_CHIP_ID_BCM5357:
  957. - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
  958. - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  959. - bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1;
  960. - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY;
  961. - if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM47186) {
  962. - bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
  963. - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII;
  964. - }
  965. - if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM5358)
  966. - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_EPHYRMII;
  967. - break;
  968. - case BCMA_CHIP_ID_BCM53572:
  969. - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
  970. - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  971. - bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1;
  972. - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY;
  973. - if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM47188) {
  974. - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII;
  975. - bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
  976. - }
  977. - break;
  978. - case BCMA_CHIP_ID_BCM4749:
  979. - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
  980. - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  981. - bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1;
  982. - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY;
  983. - if (core->bus->chipinfo.pkg == 10) {
  984. - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII;
  985. - bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
  986. - }
  987. - break;
  988. - case BCMA_CHIP_ID_BCM4716:
  989. - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  990. - /* fallthrough */
  991. - case BCMA_CHIP_ID_BCM47162:
  992. - bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL2;
  993. - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
  994. - break;
  995. - /* bcm4707_family */
  996. - case BCMA_CHIP_ID_BCM4707:
  997. - case BCMA_CHIP_ID_BCM47094:
  998. - case BCMA_CHIP_ID_BCM53018:
  999. - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  1000. - bgmac->feature_flags |= BGMAC_FEAT_NO_RESET;
  1001. - bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500;
  1002. - break;
  1003. - default:
  1004. - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
  1005. - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
  1006. - }
  1007. -
  1008. - if (!bgmac_is_bcm4707_family(bgmac) && core->id.rev > 2)
  1009. - bgmac->feature_flags |= BGMAC_FEAT_MISC_PLL_REQ;
  1010. -
  1011. - if (core->id.id == BCMA_CORE_4706_MAC_GBIT) {
  1012. - bgmac->feature_flags |= BGMAC_FEAT_CMN_PHY_CTL;
  1013. - bgmac->feature_flags |= BGMAC_FEAT_NO_CLR_MIB;
  1014. - }
  1015. -
  1016. - if (core->id.rev >= 4) {
  1017. - bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4;
  1018. - bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP;
  1019. - bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP;
  1020. - }
  1021. -
  1022. netif_napi_add(net_dev, &bgmac->napi, bgmac_poll, BGMAC_WEIGHT);
  1023. - if (!bgmac_is_bcm4707_family(bgmac)) {
  1024. - struct mii_bus *mii_bus;
  1025. -
  1026. - mii_bus = bcma_mdio_mii_register(core, bgmac->phyaddr);
  1027. - if (!IS_ERR(mii_bus)) {
  1028. - err = PTR_ERR(mii_bus);
  1029. - goto err_dma_free;
  1030. - }
  1031. -
  1032. - bgmac->mii_bus = mii_bus;
  1033. - }
  1034. -
  1035. if (!bgmac->mii_bus)
  1036. err = bgmac_phy_connect_direct(bgmac);
  1037. else
  1038. err = bgmac_phy_connect(bgmac);
  1039. if (err) {
  1040. dev_err(bgmac->dev, "Cannot connect to phy\n");
  1041. - goto err_mii_unregister;
  1042. + goto err_dma_free;
  1043. }
  1044. net_dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
  1045. @@ -1718,56 +1525,24 @@ static int bgmac_probe(struct bcma_devic
  1046. err_phy_disconnect:
  1047. phy_disconnect(net_dev->phydev);
  1048. -err_mii_unregister:
  1049. - bcma_mdio_mii_unregister(bgmac->mii_bus);
  1050. err_dma_free:
  1051. bgmac_dma_free(bgmac);
  1052. err_netdev_free:
  1053. - bcma_set_drvdata(core, NULL);
  1054. free_netdev(net_dev);
  1055. return err;
  1056. }
  1057. +EXPORT_SYMBOL_GPL(bgmac_enet_probe);
  1058. -static void bgmac_remove(struct bcma_device *core)
  1059. +void bgmac_enet_remove(struct bgmac *bgmac)
  1060. {
  1061. - struct bgmac *bgmac = bcma_get_drvdata(core);
  1062. -
  1063. unregister_netdev(bgmac->net_dev);
  1064. phy_disconnect(bgmac->net_dev->phydev);
  1065. - bcma_mdio_mii_unregister(bgmac->mii_bus);
  1066. netif_napi_del(&bgmac->napi);
  1067. bgmac_dma_free(bgmac);
  1068. - bcma_set_drvdata(core, NULL);
  1069. free_netdev(bgmac->net_dev);
  1070. }
  1071. -
  1072. -static struct bcma_driver bgmac_bcma_driver = {
  1073. - .name = KBUILD_MODNAME,
  1074. - .id_table = bgmac_bcma_tbl,
  1075. - .probe = bgmac_probe,
  1076. - .remove = bgmac_remove,
  1077. -};
  1078. -
  1079. -static int __init bgmac_init(void)
  1080. -{
  1081. - int err;
  1082. -
  1083. - err = bcma_driver_register(&bgmac_bcma_driver);
  1084. - if (err)
  1085. - return err;
  1086. - pr_info("Broadcom 47xx GBit MAC driver loaded\n");
  1087. -
  1088. - return 0;
  1089. -}
  1090. -
  1091. -static void __exit bgmac_exit(void)
  1092. -{
  1093. - bcma_driver_unregister(&bgmac_bcma_driver);
  1094. -}
  1095. -
  1096. -module_init(bgmac_init)
  1097. -module_exit(bgmac_exit)
  1098. +EXPORT_SYMBOL_GPL(bgmac_enet_remove);
  1099. MODULE_AUTHOR("Rafał Miłecki");
  1100. MODULE_LICENSE("GPL");
  1101. --- a/drivers/net/ethernet/broadcom/bgmac.h
  1102. +++ b/drivers/net/ethernet/broadcom/bgmac.h
  1103. @@ -1,8 +1,6 @@
  1104. #ifndef _BGMAC_H
  1105. #define _BGMAC_H
  1106. -#include <linux/bcma/bcma.h>
  1107. -#include <linux/brcmphy.h>
  1108. #include <linux/netdevice.h>
  1109. #define BGMAC_DEV_CTL 0x000
  1110. @@ -442,11 +440,21 @@ struct bgmac_rx_header {
  1111. };
  1112. struct bgmac {
  1113. - struct bcma_device *core;
  1114. - struct bcma_device *cmn; /* Reference to CMN core for BCM4706 */
  1115. + union {
  1116. + struct {
  1117. + void *base;
  1118. + void *idm_base;
  1119. + } plat;
  1120. + struct {
  1121. + struct bcma_device *core;
  1122. + /* Reference to CMN core for BCM4706 */
  1123. + struct bcma_device *cmn;
  1124. + } bcma;
  1125. + };
  1126. struct device *dev;
  1127. struct device *dma_dev;
  1128. + unsigned char mac_addr[ETH_ALEN];
  1129. u32 feature_flags;
  1130. struct net_device *net_dev;
  1131. @@ -463,6 +471,7 @@ struct bgmac {
  1132. u32 mib_rx_regs[BGMAC_NUM_MIB_RX_REGS];
  1133. /* Int */
  1134. + int irq;
  1135. u32 int_mask;
  1136. /* Current MAC state */
  1137. @@ -473,19 +482,71 @@ struct bgmac {
  1138. bool has_robosw;
  1139. bool loopback;
  1140. +
  1141. + u32 (*read)(struct bgmac *bgmac, u16 offset);
  1142. + void (*write)(struct bgmac *bgmac, u16 offset, u32 value);
  1143. + u32 (*idm_read)(struct bgmac *bgmac, u16 offset);
  1144. + void (*idm_write)(struct bgmac *bgmac, u16 offset, u32 value);
  1145. + bool (*clk_enabled)(struct bgmac *bgmac);
  1146. + void (*clk_enable)(struct bgmac *bgmac, u32 flags);
  1147. + void (*cco_ctl_maskset)(struct bgmac *bgmac, u32 offset, u32 mask,
  1148. + u32 set);
  1149. + u32 (*get_bus_clock)(struct bgmac *bgmac);
  1150. + void (*cmn_maskset32)(struct bgmac *bgmac, u16 offset, u32 mask,
  1151. + u32 set);
  1152. };
  1153. +int bgmac_enet_probe(struct bgmac *info);
  1154. +void bgmac_enet_remove(struct bgmac *bgmac);
  1155. +
  1156. struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr);
  1157. void bcma_mdio_mii_unregister(struct mii_bus *mii_bus);
  1158. static inline u32 bgmac_read(struct bgmac *bgmac, u16 offset)
  1159. {
  1160. - return bcma_read32(bgmac->core, offset);
  1161. + return bgmac->read(bgmac, offset);
  1162. }
  1163. static inline void bgmac_write(struct bgmac *bgmac, u16 offset, u32 value)
  1164. {
  1165. - bcma_write32(bgmac->core, offset, value);
  1166. + bgmac->write(bgmac, offset, value);
  1167. +}
  1168. +
  1169. +static inline u32 bgmac_idm_read(struct bgmac *bgmac, u16 offset)
  1170. +{
  1171. + return bgmac->idm_read(bgmac, offset);
  1172. +}
  1173. +
  1174. +static inline void bgmac_idm_write(struct bgmac *bgmac, u16 offset, u32 value)
  1175. +{
  1176. + bgmac->idm_write(bgmac, offset, value);
  1177. +}
  1178. +
  1179. +static inline bool bgmac_clk_enabled(struct bgmac *bgmac)
  1180. +{
  1181. + return bgmac->clk_enabled(bgmac);
  1182. +}
  1183. +
  1184. +static inline void bgmac_clk_enable(struct bgmac *bgmac, u32 flags)
  1185. +{
  1186. + bgmac->clk_enable(bgmac, flags);
  1187. +}
  1188. +
  1189. +static inline void bgmac_cco_ctl_maskset(struct bgmac *bgmac, u32 offset,
  1190. + u32 mask, u32 set)
  1191. +{
  1192. + bgmac->cco_ctl_maskset(bgmac, offset, mask, set);
  1193. +}
  1194. +
  1195. +static inline u32 bgmac_get_bus_clock(struct bgmac *bgmac)
  1196. +{
  1197. + return bgmac->get_bus_clock(bgmac);
  1198. +}
  1199. +
  1200. +static inline void bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset,
  1201. + u32 mask, u32 set)
  1202. +{
  1203. + bgmac->cmn_maskset32(bgmac, offset, mask, set);
  1204. }
  1205. static inline void bgmac_maskset(struct bgmac *bgmac, u16 offset, u32 mask,