073-v5.12-0003-net-broadcom-rename-BCM4908-driver-update-DT-binding.patch 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614
  1. From 9d61d138ab30bbfe4a8609853c81e881c4054a0b Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  3. Date: Thu, 11 Feb 2021 13:12:34 +0100
  4. Subject: [PATCH] net: broadcom: rename BCM4908 driver & update DT binding
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. compatible string was updated to match normal naming convention so
  9. update driver as well
  10. Signed-off-by: Rafał Miłecki <[email protected]>
  11. Reviewed-by: Florian Fainelli <[email protected]>
  12. Signed-off-by: David S. Miller <[email protected]>
  13. ---
  14. MAINTAINERS | 2 +-
  15. drivers/net/ethernet/broadcom/Kconfig | 2 +-
  16. drivers/net/ethernet/broadcom/Makefile | 2 +-
  17. .../{bcm4908enet.c => bcm4908_enet.c} | 215 +++++++++---------
  18. .../{bcm4908enet.h => bcm4908_enet.h} | 4 +-
  19. 5 files changed, 113 insertions(+), 112 deletions(-)
  20. rename drivers/net/ethernet/broadcom/{bcm4908enet.c => bcm4908_enet.c} (68%)
  21. rename drivers/net/ethernet/broadcom/{bcm4908enet.h => bcm4908_enet.h} (98%)
  22. --- a/MAINTAINERS
  23. +++ b/MAINTAINERS
  24. @@ -3213,7 +3213,7 @@ M: [email protected]
  25. L: [email protected]
  26. S: Maintained
  27. F: Documentation/devicetree/bindings/net/brcm,bcm4908-enet.yaml
  28. -F: drivers/net/ethernet/broadcom/bcm4908enet.*
  29. +F: drivers/net/ethernet/broadcom/bcm4908_enet.*
  30. F: drivers/net/ethernet/broadcom/unimac.h
  31. BROADCOM BCM5301X ARM ARCHITECTURE
  32. --- a/drivers/net/ethernet/broadcom/Kconfig
  33. +++ b/drivers/net/ethernet/broadcom/Kconfig
  34. @@ -51,7 +51,7 @@ config B44_PCI
  35. depends on B44_PCI_AUTOSELECT && B44_PCICORE_AUTOSELECT
  36. default y
  37. -config BCM4908ENET
  38. +config BCM4908_ENET
  39. tristate "Broadcom BCM4908 internal mac support"
  40. depends on ARCH_BCM4908 || COMPILE_TEST
  41. default y
  42. --- a/drivers/net/ethernet/broadcom/Makefile
  43. +++ b/drivers/net/ethernet/broadcom/Makefile
  44. @@ -4,7 +4,7 @@
  45. #
  46. obj-$(CONFIG_B44) += b44.o
  47. -obj-$(CONFIG_BCM4908ENET) += bcm4908enet.o
  48. +obj-$(CONFIG_BCM4908_ENET) += bcm4908_enet.o
  49. obj-$(CONFIG_BCM63XX_ENET) += bcm63xx_enet.o
  50. obj-$(CONFIG_BCMGENET) += genet/
  51. obj-$(CONFIG_BNX2) += bnx2.o
  52. --- a/drivers/net/ethernet/broadcom/bcm4908enet.c
  53. +++ /dev/null
  54. @@ -1,676 +0,0 @@
  55. -// SPDX-License-Identifier: GPL-2.0-only
  56. -/*
  57. - * Copyright (C) 2021 Rafał Miłecki <[email protected]>
  58. - */
  59. -
  60. -#include <linux/delay.h>
  61. -#include <linux/etherdevice.h>
  62. -#include <linux/interrupt.h>
  63. -#include <linux/module.h>
  64. -#include <linux/of.h>
  65. -#include <linux/platform_device.h>
  66. -#include <linux/slab.h>
  67. -#include <linux/string.h>
  68. -
  69. -#include "bcm4908enet.h"
  70. -#include "unimac.h"
  71. -
  72. -#define ENET_DMA_CH_RX_CFG ENET_DMA_CH0_CFG
  73. -#define ENET_DMA_CH_TX_CFG ENET_DMA_CH1_CFG
  74. -#define ENET_DMA_CH_RX_STATE_RAM ENET_DMA_CH0_STATE_RAM
  75. -#define ENET_DMA_CH_TX_STATE_RAM ENET_DMA_CH1_STATE_RAM
  76. -
  77. -#define ENET_TX_BDS_NUM 200
  78. -#define ENET_RX_BDS_NUM 200
  79. -#define ENET_RX_BDS_NUM_MAX 8192
  80. -
  81. -#define ENET_DMA_INT_DEFAULTS (ENET_DMA_CH_CFG_INT_DONE | \
  82. - ENET_DMA_CH_CFG_INT_NO_DESC | \
  83. - ENET_DMA_CH_CFG_INT_BUFF_DONE)
  84. -#define ENET_DMA_MAX_BURST_LEN 8 /* in 64 bit words */
  85. -
  86. -#define ENET_MTU_MIN 60
  87. -#define ENET_MTU_MAX 1500 /* Is it possible to support 2044? */
  88. -#define ENET_MTU_MAX_EXTRA_SIZE 32 /* L2 */
  89. -
  90. -struct bcm4908enet_dma_ring_bd {
  91. - __le32 ctl;
  92. - __le32 addr;
  93. -} __packed;
  94. -
  95. -struct bcm4908enet_dma_ring_slot {
  96. - struct sk_buff *skb;
  97. - unsigned int len;
  98. - dma_addr_t dma_addr;
  99. -};
  100. -
  101. -struct bcm4908enet_dma_ring {
  102. - int is_tx;
  103. - int read_idx;
  104. - int write_idx;
  105. - int length;
  106. - u16 cfg_block;
  107. - u16 st_ram_block;
  108. -
  109. - union {
  110. - void *cpu_addr;
  111. - struct bcm4908enet_dma_ring_bd *buf_desc;
  112. - };
  113. - dma_addr_t dma_addr;
  114. -
  115. - struct bcm4908enet_dma_ring_slot *slots;
  116. -};
  117. -
  118. -struct bcm4908enet {
  119. - struct device *dev;
  120. - struct net_device *netdev;
  121. - struct napi_struct napi;
  122. - void __iomem *base;
  123. -
  124. - struct bcm4908enet_dma_ring tx_ring;
  125. - struct bcm4908enet_dma_ring rx_ring;
  126. -};
  127. -
  128. -/***
  129. - * R/W ops
  130. - */
  131. -
  132. -static inline u32 enet_read(struct bcm4908enet *enet, u16 offset)
  133. -{
  134. - return readl(enet->base + offset);
  135. -}
  136. -
  137. -static inline void enet_write(struct bcm4908enet *enet, u16 offset, u32 value)
  138. -{
  139. - writel(value, enet->base + offset);
  140. -}
  141. -
  142. -static inline void enet_maskset(struct bcm4908enet *enet, u16 offset, u32 mask, u32 set)
  143. -{
  144. - u32 val;
  145. -
  146. - WARN_ON(set & ~mask);
  147. -
  148. - val = enet_read(enet, offset);
  149. - val = (val & ~mask) | (set & mask);
  150. - enet_write(enet, offset, val);
  151. -}
  152. -
  153. -static inline void enet_set(struct bcm4908enet *enet, u16 offset, u32 set)
  154. -{
  155. - enet_maskset(enet, offset, set, set);
  156. -}
  157. -
  158. -static inline u32 enet_umac_read(struct bcm4908enet *enet, u16 offset)
  159. -{
  160. - return enet_read(enet, ENET_UNIMAC + offset);
  161. -}
  162. -
  163. -static inline void enet_umac_write(struct bcm4908enet *enet, u16 offset, u32 value)
  164. -{
  165. - enet_write(enet, ENET_UNIMAC + offset, value);
  166. -}
  167. -
  168. -static inline void enet_umac_maskset(struct bcm4908enet *enet, u16 offset, u32 mask, u32 set)
  169. -{
  170. - enet_maskset(enet, ENET_UNIMAC + offset, mask, set);
  171. -}
  172. -
  173. -static inline void enet_umac_set(struct bcm4908enet *enet, u16 offset, u32 set)
  174. -{
  175. - enet_set(enet, ENET_UNIMAC + offset, set);
  176. -}
  177. -
  178. -/***
  179. - * Helpers
  180. - */
  181. -
  182. -static void bcm4908enet_intrs_on(struct bcm4908enet *enet)
  183. -{
  184. - enet_write(enet, ENET_DMA_CH_RX_CFG + ENET_DMA_CH_CFG_INT_MASK, ENET_DMA_INT_DEFAULTS);
  185. -}
  186. -
  187. -static void bcm4908enet_intrs_off(struct bcm4908enet *enet)
  188. -{
  189. - enet_write(enet, ENET_DMA_CH_RX_CFG + ENET_DMA_CH_CFG_INT_MASK, 0);
  190. -}
  191. -
  192. -static void bcm4908enet_intrs_ack(struct bcm4908enet *enet)
  193. -{
  194. - enet_write(enet, ENET_DMA_CH_RX_CFG + ENET_DMA_CH_CFG_INT_STAT, ENET_DMA_INT_DEFAULTS);
  195. -}
  196. -
  197. -/***
  198. - * DMA
  199. - */
  200. -
  201. -static int bcm4908_dma_alloc_buf_descs(struct bcm4908enet *enet, struct bcm4908enet_dma_ring *ring)
  202. -{
  203. - int size = ring->length * sizeof(struct bcm4908enet_dma_ring_bd);
  204. - struct device *dev = enet->dev;
  205. -
  206. - ring->cpu_addr = dma_alloc_coherent(dev, size, &ring->dma_addr, GFP_KERNEL);
  207. - if (!ring->cpu_addr)
  208. - return -ENOMEM;
  209. -
  210. - if (((uintptr_t)ring->cpu_addr) & (0x40 - 1)) {
  211. - dev_err(dev, "Invalid DMA ring alignment\n");
  212. - goto err_free_buf_descs;
  213. - }
  214. -
  215. - ring->slots = kzalloc(ring->length * sizeof(*ring->slots), GFP_KERNEL);
  216. - if (!ring->slots)
  217. - goto err_free_buf_descs;
  218. -
  219. - memset(ring->cpu_addr, 0, size);
  220. -
  221. - ring->read_idx = 0;
  222. - ring->write_idx = 0;
  223. -
  224. - return 0;
  225. -
  226. -err_free_buf_descs:
  227. - dma_free_coherent(dev, size, ring->cpu_addr, ring->dma_addr);
  228. - return -ENOMEM;
  229. -}
  230. -
  231. -static void bcm4908enet_dma_free(struct bcm4908enet *enet)
  232. -{
  233. - struct bcm4908enet_dma_ring *tx_ring = &enet->tx_ring;
  234. - struct bcm4908enet_dma_ring *rx_ring = &enet->rx_ring;
  235. - struct device *dev = enet->dev;
  236. - int size;
  237. -
  238. - size = rx_ring->length * sizeof(struct bcm4908enet_dma_ring_bd);
  239. - if (rx_ring->cpu_addr)
  240. - dma_free_coherent(dev, size, rx_ring->cpu_addr, rx_ring->dma_addr);
  241. - kfree(rx_ring->slots);
  242. -
  243. - size = tx_ring->length * sizeof(struct bcm4908enet_dma_ring_bd);
  244. - if (tx_ring->cpu_addr)
  245. - dma_free_coherent(dev, size, tx_ring->cpu_addr, tx_ring->dma_addr);
  246. - kfree(tx_ring->slots);
  247. -}
  248. -
  249. -static int bcm4908enet_dma_alloc(struct bcm4908enet *enet)
  250. -{
  251. - struct bcm4908enet_dma_ring *tx_ring = &enet->tx_ring;
  252. - struct bcm4908enet_dma_ring *rx_ring = &enet->rx_ring;
  253. - struct device *dev = enet->dev;
  254. - int err;
  255. -
  256. - tx_ring->length = ENET_TX_BDS_NUM;
  257. - tx_ring->is_tx = 1;
  258. - tx_ring->cfg_block = ENET_DMA_CH_TX_CFG;
  259. - tx_ring->st_ram_block = ENET_DMA_CH_TX_STATE_RAM;
  260. - err = bcm4908_dma_alloc_buf_descs(enet, tx_ring);
  261. - if (err) {
  262. - dev_err(dev, "Failed to alloc TX buf descriptors: %d\n", err);
  263. - return err;
  264. - }
  265. -
  266. - rx_ring->length = ENET_RX_BDS_NUM;
  267. - rx_ring->is_tx = 0;
  268. - rx_ring->cfg_block = ENET_DMA_CH_RX_CFG;
  269. - rx_ring->st_ram_block = ENET_DMA_CH_RX_STATE_RAM;
  270. - err = bcm4908_dma_alloc_buf_descs(enet, rx_ring);
  271. - if (err) {
  272. - dev_err(dev, "Failed to alloc RX buf descriptors: %d\n", err);
  273. - bcm4908enet_dma_free(enet);
  274. - return err;
  275. - }
  276. -
  277. - return 0;
  278. -}
  279. -
  280. -static void bcm4908enet_dma_reset(struct bcm4908enet *enet)
  281. -{
  282. - struct bcm4908enet_dma_ring *rings[] = { &enet->rx_ring, &enet->tx_ring };
  283. - int i;
  284. -
  285. - /* Disable the DMA controller and channel */
  286. - for (i = 0; i < ARRAY_SIZE(rings); i++)
  287. - enet_write(enet, rings[i]->cfg_block + ENET_DMA_CH_CFG, 0);
  288. - enet_maskset(enet, ENET_DMA_CONTROLLER_CFG, ENET_DMA_CTRL_CFG_MASTER_EN, 0);
  289. -
  290. - /* Reset channels state */
  291. - for (i = 0; i < ARRAY_SIZE(rings); i++) {
  292. - struct bcm4908enet_dma_ring *ring = rings[i];
  293. -
  294. - enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_BASE_DESC_PTR, 0);
  295. - enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_STATE_DATA, 0);
  296. - enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_DESC_LEN_STATUS, 0);
  297. - enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_DESC_BASE_BUFPTR, 0);
  298. - }
  299. -}
  300. -
  301. -static int bcm4908enet_dma_alloc_rx_buf(struct bcm4908enet *enet, unsigned int idx)
  302. -{
  303. - struct bcm4908enet_dma_ring_bd *buf_desc = &enet->rx_ring.buf_desc[idx];
  304. - struct bcm4908enet_dma_ring_slot *slot = &enet->rx_ring.slots[idx];
  305. - struct device *dev = enet->dev;
  306. - u32 tmp;
  307. - int err;
  308. -
  309. - slot->len = ENET_MTU_MAX + ENET_MTU_MAX_EXTRA_SIZE;
  310. -
  311. - slot->skb = netdev_alloc_skb(enet->netdev, slot->len);
  312. - if (!slot->skb)
  313. - return -ENOMEM;
  314. -
  315. - slot->dma_addr = dma_map_single(dev, slot->skb->data, slot->len, DMA_FROM_DEVICE);
  316. - err = dma_mapping_error(dev, slot->dma_addr);
  317. - if (err) {
  318. - dev_err(dev, "Failed to map DMA buffer: %d\n", err);
  319. - kfree_skb(slot->skb);
  320. - slot->skb = NULL;
  321. - return err;
  322. - }
  323. -
  324. - tmp = slot->len << DMA_CTL_LEN_DESC_BUFLENGTH_SHIFT;
  325. - tmp |= DMA_CTL_STATUS_OWN;
  326. - if (idx == enet->rx_ring.length - 1)
  327. - tmp |= DMA_CTL_STATUS_WRAP;
  328. - buf_desc->ctl = cpu_to_le32(tmp);
  329. - buf_desc->addr = cpu_to_le32(slot->dma_addr);
  330. -
  331. - return 0;
  332. -}
  333. -
  334. -static void bcm4908enet_dma_ring_init(struct bcm4908enet *enet,
  335. - struct bcm4908enet_dma_ring *ring)
  336. -{
  337. - int reset_channel = 0; /* We support only 1 main channel (with TX and RX) */
  338. - int reset_subch = ring->is_tx ? 1 : 0;
  339. -
  340. - /* Reset the DMA channel */
  341. - enet_write(enet, ENET_DMA_CTRL_CHANNEL_RESET, BIT(reset_channel * 2 + reset_subch));
  342. - enet_write(enet, ENET_DMA_CTRL_CHANNEL_RESET, 0);
  343. -
  344. - enet_write(enet, ring->cfg_block + ENET_DMA_CH_CFG, 0);
  345. - enet_write(enet, ring->cfg_block + ENET_DMA_CH_CFG_MAX_BURST, ENET_DMA_MAX_BURST_LEN);
  346. - enet_write(enet, ring->cfg_block + ENET_DMA_CH_CFG_INT_MASK, 0);
  347. -
  348. - enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_BASE_DESC_PTR,
  349. - (uint32_t)ring->dma_addr);
  350. -}
  351. -
  352. -static void bcm4908enet_dma_uninit(struct bcm4908enet *enet)
  353. -{
  354. - struct bcm4908enet_dma_ring *rx_ring = &enet->rx_ring;
  355. - struct bcm4908enet_dma_ring_slot *slot;
  356. - struct device *dev = enet->dev;
  357. - int i;
  358. -
  359. - for (i = rx_ring->length - 1; i >= 0; i--) {
  360. - slot = &rx_ring->slots[i];
  361. - if (!slot->skb)
  362. - continue;
  363. - dma_unmap_single(dev, slot->dma_addr, slot->len, DMA_FROM_DEVICE);
  364. - kfree_skb(slot->skb);
  365. - slot->skb = NULL;
  366. - }
  367. -}
  368. -
  369. -static int bcm4908enet_dma_init(struct bcm4908enet *enet)
  370. -{
  371. - struct bcm4908enet_dma_ring *rx_ring = &enet->rx_ring;
  372. - struct device *dev = enet->dev;
  373. - int err;
  374. - int i;
  375. -
  376. - for (i = 0; i < rx_ring->length; i++) {
  377. - err = bcm4908enet_dma_alloc_rx_buf(enet, i);
  378. - if (err) {
  379. - dev_err(dev, "Failed to alloc RX buffer: %d\n", err);
  380. - bcm4908enet_dma_uninit(enet);
  381. - return err;
  382. - }
  383. - }
  384. -
  385. - bcm4908enet_dma_ring_init(enet, &enet->tx_ring);
  386. - bcm4908enet_dma_ring_init(enet, &enet->rx_ring);
  387. -
  388. - return 0;
  389. -}
  390. -
  391. -static void bcm4908enet_dma_tx_ring_ensable(struct bcm4908enet *enet,
  392. - struct bcm4908enet_dma_ring *ring)
  393. -{
  394. - enet_write(enet, ring->cfg_block + ENET_DMA_CH_CFG, ENET_DMA_CH_CFG_ENABLE);
  395. -}
  396. -
  397. -static void bcm4908enet_dma_tx_ring_disable(struct bcm4908enet *enet,
  398. - struct bcm4908enet_dma_ring *ring)
  399. -{
  400. - enet_write(enet, ring->cfg_block + ENET_DMA_CH_CFG, 0);
  401. -}
  402. -
  403. -static void bcm4908enet_dma_rx_ring_enable(struct bcm4908enet *enet,
  404. - struct bcm4908enet_dma_ring *ring)
  405. -{
  406. - enet_set(enet, ring->cfg_block + ENET_DMA_CH_CFG, ENET_DMA_CH_CFG_ENABLE);
  407. -}
  408. -
  409. -static void bcm4908enet_dma_rx_ring_disable(struct bcm4908enet *enet,
  410. - struct bcm4908enet_dma_ring *ring)
  411. -{
  412. - unsigned long deadline;
  413. - u32 tmp;
  414. -
  415. - enet_maskset(enet, ring->cfg_block + ENET_DMA_CH_CFG, ENET_DMA_CH_CFG_ENABLE, 0);
  416. -
  417. - deadline = jiffies + usecs_to_jiffies(2000);
  418. - do {
  419. - tmp = enet_read(enet, ring->cfg_block + ENET_DMA_CH_CFG);
  420. - if (!(tmp & ENET_DMA_CH_CFG_ENABLE))
  421. - return;
  422. - enet_maskset(enet, ring->cfg_block + ENET_DMA_CH_CFG, ENET_DMA_CH_CFG_ENABLE, 0);
  423. - usleep_range(10, 30);
  424. - } while (!time_after_eq(jiffies, deadline));
  425. -
  426. - dev_warn(enet->dev, "Timeout waiting for DMA TX stop\n");
  427. -}
  428. -
  429. -/***
  430. - * Ethernet driver
  431. - */
  432. -
  433. -static void bcm4908enet_gmac_init(struct bcm4908enet *enet)
  434. -{
  435. - u32 cmd;
  436. -
  437. - cmd = enet_umac_read(enet, UMAC_CMD);
  438. - enet_umac_write(enet, UMAC_CMD, cmd | CMD_SW_RESET);
  439. - enet_umac_write(enet, UMAC_CMD, cmd & ~CMD_SW_RESET);
  440. -
  441. - enet_set(enet, ENET_FLUSH, ENET_FLUSH_RXFIFO_FLUSH | ENET_FLUSH_TXFIFO_FLUSH);
  442. - enet_maskset(enet, ENET_FLUSH, ENET_FLUSH_RXFIFO_FLUSH | ENET_FLUSH_TXFIFO_FLUSH, 0);
  443. -
  444. - enet_set(enet, ENET_MIB_CTRL, ENET_MIB_CTRL_CLR_MIB);
  445. - enet_maskset(enet, ENET_MIB_CTRL, ENET_MIB_CTRL_CLR_MIB, 0);
  446. -
  447. - cmd = enet_umac_read(enet, UMAC_CMD);
  448. - cmd &= ~(CMD_SPEED_MASK << CMD_SPEED_SHIFT);
  449. - cmd &= ~CMD_TX_EN;
  450. - cmd &= ~CMD_RX_EN;
  451. - cmd |= CMD_SPEED_1000 << CMD_SPEED_SHIFT;
  452. - enet_umac_write(enet, UMAC_CMD, cmd);
  453. -
  454. - enet_maskset(enet, ENET_GMAC_STATUS,
  455. - ENET_GMAC_STATUS_ETH_SPEED_MASK |
  456. - ENET_GMAC_STATUS_HD |
  457. - ENET_GMAC_STATUS_AUTO_CFG_EN |
  458. - ENET_GMAC_STATUS_LINK_UP,
  459. - ENET_GMAC_STATUS_ETH_SPEED_1000 |
  460. - ENET_GMAC_STATUS_AUTO_CFG_EN |
  461. - ENET_GMAC_STATUS_LINK_UP);
  462. -}
  463. -
  464. -static irqreturn_t bcm4908enet_irq_handler(int irq, void *dev_id)
  465. -{
  466. - struct bcm4908enet *enet = dev_id;
  467. -
  468. - bcm4908enet_intrs_off(enet);
  469. - bcm4908enet_intrs_ack(enet);
  470. -
  471. - napi_schedule(&enet->napi);
  472. -
  473. - return IRQ_HANDLED;
  474. -}
  475. -
  476. -static int bcm4908enet_open(struct net_device *netdev)
  477. -{
  478. - struct bcm4908enet *enet = netdev_priv(netdev);
  479. - struct device *dev = enet->dev;
  480. - int err;
  481. -
  482. - err = request_irq(netdev->irq, bcm4908enet_irq_handler, 0, "enet", enet);
  483. - if (err) {
  484. - dev_err(dev, "Failed to request IRQ %d: %d\n", netdev->irq, err);
  485. - return err;
  486. - }
  487. -
  488. - bcm4908enet_gmac_init(enet);
  489. - bcm4908enet_dma_reset(enet);
  490. - bcm4908enet_dma_init(enet);
  491. -
  492. - enet_umac_set(enet, UMAC_CMD, CMD_TX_EN | CMD_RX_EN);
  493. -
  494. - enet_set(enet, ENET_DMA_CONTROLLER_CFG, ENET_DMA_CTRL_CFG_MASTER_EN);
  495. - enet_maskset(enet, ENET_DMA_CONTROLLER_CFG, ENET_DMA_CTRL_CFG_FLOWC_CH1_EN, 0);
  496. - bcm4908enet_dma_rx_ring_enable(enet, &enet->rx_ring);
  497. -
  498. - napi_enable(&enet->napi);
  499. - netif_carrier_on(netdev);
  500. - netif_start_queue(netdev);
  501. -
  502. - bcm4908enet_intrs_ack(enet);
  503. - bcm4908enet_intrs_on(enet);
  504. -
  505. - return 0;
  506. -}
  507. -
  508. -static int bcm4908enet_stop(struct net_device *netdev)
  509. -{
  510. - struct bcm4908enet *enet = netdev_priv(netdev);
  511. -
  512. - netif_stop_queue(netdev);
  513. - netif_carrier_off(netdev);
  514. - napi_disable(&enet->napi);
  515. -
  516. - bcm4908enet_dma_rx_ring_disable(enet, &enet->rx_ring);
  517. - bcm4908enet_dma_tx_ring_disable(enet, &enet->tx_ring);
  518. -
  519. - bcm4908enet_dma_uninit(enet);
  520. -
  521. - free_irq(enet->netdev->irq, enet);
  522. -
  523. - return 0;
  524. -}
  525. -
  526. -static int bcm4908enet_start_xmit(struct sk_buff *skb, struct net_device *netdev)
  527. -{
  528. - struct bcm4908enet *enet = netdev_priv(netdev);
  529. - struct bcm4908enet_dma_ring *ring = &enet->tx_ring;
  530. - struct bcm4908enet_dma_ring_slot *slot;
  531. - struct device *dev = enet->dev;
  532. - struct bcm4908enet_dma_ring_bd *buf_desc;
  533. - int free_buf_descs;
  534. - u32 tmp;
  535. -
  536. - /* Free transmitted skbs */
  537. - while (ring->read_idx != ring->write_idx) {
  538. - buf_desc = &ring->buf_desc[ring->read_idx];
  539. - if (buf_desc->ctl & DMA_CTL_STATUS_OWN)
  540. - break;
  541. - slot = &ring->slots[ring->read_idx];
  542. -
  543. - dma_unmap_single(dev, slot->dma_addr, slot->len, DMA_TO_DEVICE);
  544. - dev_kfree_skb(slot->skb);
  545. - if (++ring->read_idx == ring->length)
  546. - ring->read_idx = 0;
  547. - }
  548. -
  549. - /* Don't use the last empty buf descriptor */
  550. - if (ring->read_idx <= ring->write_idx)
  551. - free_buf_descs = ring->read_idx - ring->write_idx + ring->length;
  552. - else
  553. - free_buf_descs = ring->read_idx - ring->write_idx;
  554. - if (free_buf_descs < 2)
  555. - return NETDEV_TX_BUSY;
  556. -
  557. - /* Hardware removes OWN bit after sending data */
  558. - buf_desc = &ring->buf_desc[ring->write_idx];
  559. - if (unlikely(le32_to_cpu(buf_desc->ctl) & DMA_CTL_STATUS_OWN)) {
  560. - netif_stop_queue(netdev);
  561. - return NETDEV_TX_BUSY;
  562. - }
  563. -
  564. - slot = &ring->slots[ring->write_idx];
  565. - slot->skb = skb;
  566. - slot->len = skb->len;
  567. - slot->dma_addr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
  568. - if (unlikely(dma_mapping_error(dev, slot->dma_addr)))
  569. - return NETDEV_TX_BUSY;
  570. -
  571. - tmp = skb->len << DMA_CTL_LEN_DESC_BUFLENGTH_SHIFT;
  572. - tmp |= DMA_CTL_STATUS_OWN;
  573. - tmp |= DMA_CTL_STATUS_SOP;
  574. - tmp |= DMA_CTL_STATUS_EOP;
  575. - tmp |= DMA_CTL_STATUS_APPEND_CRC;
  576. - if (ring->write_idx + 1 == ring->length - 1)
  577. - tmp |= DMA_CTL_STATUS_WRAP;
  578. -
  579. - buf_desc->addr = cpu_to_le32((uint32_t)slot->dma_addr);
  580. - buf_desc->ctl = cpu_to_le32(tmp);
  581. -
  582. - bcm4908enet_dma_tx_ring_ensable(enet, &enet->tx_ring);
  583. -
  584. - if (++ring->write_idx == ring->length - 1)
  585. - ring->write_idx = 0;
  586. - enet->netdev->stats.tx_bytes += skb->len;
  587. - enet->netdev->stats.tx_packets++;
  588. -
  589. - return NETDEV_TX_OK;
  590. -}
  591. -
  592. -static int bcm4908enet_poll(struct napi_struct *napi, int weight)
  593. -{
  594. - struct bcm4908enet *enet = container_of(napi, struct bcm4908enet, napi);
  595. - struct device *dev = enet->dev;
  596. - int handled = 0;
  597. -
  598. - while (handled < weight) {
  599. - struct bcm4908enet_dma_ring_bd *buf_desc;
  600. - struct bcm4908enet_dma_ring_slot slot;
  601. - u32 ctl;
  602. - int len;
  603. - int err;
  604. -
  605. - buf_desc = &enet->rx_ring.buf_desc[enet->rx_ring.read_idx];
  606. - ctl = le32_to_cpu(buf_desc->ctl);
  607. - if (ctl & DMA_CTL_STATUS_OWN)
  608. - break;
  609. -
  610. - slot = enet->rx_ring.slots[enet->rx_ring.read_idx];
  611. -
  612. - /* Provide new buffer before unpinning the old one */
  613. - err = bcm4908enet_dma_alloc_rx_buf(enet, enet->rx_ring.read_idx);
  614. - if (err)
  615. - break;
  616. -
  617. - if (++enet->rx_ring.read_idx == enet->rx_ring.length)
  618. - enet->rx_ring.read_idx = 0;
  619. -
  620. - len = (ctl & DMA_CTL_LEN_DESC_BUFLENGTH) >> DMA_CTL_LEN_DESC_BUFLENGTH_SHIFT;
  621. -
  622. - if (len < ENET_MTU_MIN ||
  623. - (ctl & (DMA_CTL_STATUS_SOP | DMA_CTL_STATUS_EOP)) != (DMA_CTL_STATUS_SOP | DMA_CTL_STATUS_EOP)) {
  624. - enet->netdev->stats.rx_dropped++;
  625. - break;
  626. - }
  627. -
  628. - dma_unmap_single(dev, slot.dma_addr, slot.len, DMA_FROM_DEVICE);
  629. -
  630. - skb_put(slot.skb, len - 4 + 2);
  631. - slot.skb->protocol = eth_type_trans(slot.skb, enet->netdev);
  632. - netif_receive_skb(slot.skb);
  633. -
  634. - enet->netdev->stats.rx_packets++;
  635. - enet->netdev->stats.rx_bytes += len;
  636. - }
  637. -
  638. - if (handled < weight) {
  639. - napi_complete_done(napi, handled);
  640. - bcm4908enet_intrs_on(enet);
  641. - }
  642. -
  643. - return handled;
  644. -}
  645. -
  646. -static const struct net_device_ops bcm96xx_netdev_ops = {
  647. - .ndo_open = bcm4908enet_open,
  648. - .ndo_stop = bcm4908enet_stop,
  649. - .ndo_start_xmit = bcm4908enet_start_xmit,
  650. - .ndo_set_mac_address = eth_mac_addr,
  651. -};
  652. -
  653. -static int bcm4908enet_probe(struct platform_device *pdev)
  654. -{
  655. - struct device *dev = &pdev->dev;
  656. - struct net_device *netdev;
  657. - struct bcm4908enet *enet;
  658. - int err;
  659. -
  660. - netdev = devm_alloc_etherdev(dev, sizeof(*enet));
  661. - if (!netdev)
  662. - return -ENOMEM;
  663. -
  664. - enet = netdev_priv(netdev);
  665. - enet->dev = dev;
  666. - enet->netdev = netdev;
  667. -
  668. - enet->base = devm_platform_ioremap_resource(pdev, 0);
  669. - if (IS_ERR(enet->base)) {
  670. - dev_err(dev, "Failed to map registers: %ld\n", PTR_ERR(enet->base));
  671. - return PTR_ERR(enet->base);
  672. - }
  673. -
  674. - netdev->irq = platform_get_irq_byname(pdev, "rx");
  675. - if (netdev->irq < 0)
  676. - return netdev->irq;
  677. -
  678. - dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
  679. -
  680. - err = bcm4908enet_dma_alloc(enet);
  681. - if (err)
  682. - return err;
  683. -
  684. - SET_NETDEV_DEV(netdev, &pdev->dev);
  685. - eth_hw_addr_random(netdev);
  686. - netdev->netdev_ops = &bcm96xx_netdev_ops;
  687. - netdev->min_mtu = ETH_ZLEN;
  688. - netdev->mtu = ENET_MTU_MAX;
  689. - netdev->max_mtu = ENET_MTU_MAX;
  690. - netif_napi_add(netdev, &enet->napi, bcm4908enet_poll, 64);
  691. -
  692. - err = register_netdev(netdev);
  693. - if (err) {
  694. - bcm4908enet_dma_free(enet);
  695. - return err;
  696. - }
  697. -
  698. - platform_set_drvdata(pdev, enet);
  699. -
  700. - return 0;
  701. -}
  702. -
  703. -static int bcm4908enet_remove(struct platform_device *pdev)
  704. -{
  705. - struct bcm4908enet *enet = platform_get_drvdata(pdev);
  706. -
  707. - unregister_netdev(enet->netdev);
  708. - netif_napi_del(&enet->napi);
  709. - bcm4908enet_dma_free(enet);
  710. -
  711. - return 0;
  712. -}
  713. -
  714. -static const struct of_device_id bcm4908enet_of_match[] = {
  715. - { .compatible = "brcm,bcm4908enet"},
  716. - {},
  717. -};
  718. -
  719. -static struct platform_driver bcm4908enet_driver = {
  720. - .driver = {
  721. - .name = "bcm4908enet",
  722. - .of_match_table = bcm4908enet_of_match,
  723. - },
  724. - .probe = bcm4908enet_probe,
  725. - .remove = bcm4908enet_remove,
  726. -};
  727. -module_platform_driver(bcm4908enet_driver);
  728. -
  729. -MODULE_LICENSE("GPL v2");
  730. -MODULE_DEVICE_TABLE(of, bcm4908enet_of_match);
  731. --- /dev/null
  732. +++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c
  733. @@ -0,0 +1,677 @@
  734. +// SPDX-License-Identifier: GPL-2.0-only
  735. +/*
  736. + * Copyright (C) 2021 Rafał Miłecki <[email protected]>
  737. + */
  738. +
  739. +#include <linux/delay.h>
  740. +#include <linux/etherdevice.h>
  741. +#include <linux/interrupt.h>
  742. +#include <linux/module.h>
  743. +#include <linux/of.h>
  744. +#include <linux/platform_device.h>
  745. +#include <linux/slab.h>
  746. +#include <linux/string.h>
  747. +
  748. +#include "bcm4908_enet.h"
  749. +#include "unimac.h"
  750. +
  751. +#define ENET_DMA_CH_RX_CFG ENET_DMA_CH0_CFG
  752. +#define ENET_DMA_CH_TX_CFG ENET_DMA_CH1_CFG
  753. +#define ENET_DMA_CH_RX_STATE_RAM ENET_DMA_CH0_STATE_RAM
  754. +#define ENET_DMA_CH_TX_STATE_RAM ENET_DMA_CH1_STATE_RAM
  755. +
  756. +#define ENET_TX_BDS_NUM 200
  757. +#define ENET_RX_BDS_NUM 200
  758. +#define ENET_RX_BDS_NUM_MAX 8192
  759. +
  760. +#define ENET_DMA_INT_DEFAULTS (ENET_DMA_CH_CFG_INT_DONE | \
  761. + ENET_DMA_CH_CFG_INT_NO_DESC | \
  762. + ENET_DMA_CH_CFG_INT_BUFF_DONE)
  763. +#define ENET_DMA_MAX_BURST_LEN 8 /* in 64 bit words */
  764. +
  765. +#define ENET_MTU_MIN 60
  766. +#define ENET_MTU_MAX 1500 /* Is it possible to support 2044? */
  767. +#define ENET_MTU_MAX_EXTRA_SIZE 32 /* L2 */
  768. +
  769. +struct bcm4908_enet_dma_ring_bd {
  770. + __le32 ctl;
  771. + __le32 addr;
  772. +} __packed;
  773. +
  774. +struct bcm4908_enet_dma_ring_slot {
  775. + struct sk_buff *skb;
  776. + unsigned int len;
  777. + dma_addr_t dma_addr;
  778. +};
  779. +
  780. +struct bcm4908_enet_dma_ring {
  781. + int is_tx;
  782. + int read_idx;
  783. + int write_idx;
  784. + int length;
  785. + u16 cfg_block;
  786. + u16 st_ram_block;
  787. +
  788. + union {
  789. + void *cpu_addr;
  790. + struct bcm4908_enet_dma_ring_bd *buf_desc;
  791. + };
  792. + dma_addr_t dma_addr;
  793. +
  794. + struct bcm4908_enet_dma_ring_slot *slots;
  795. +};
  796. +
  797. +struct bcm4908_enet {
  798. + struct device *dev;
  799. + struct net_device *netdev;
  800. + struct napi_struct napi;
  801. + void __iomem *base;
  802. +
  803. + struct bcm4908_enet_dma_ring tx_ring;
  804. + struct bcm4908_enet_dma_ring rx_ring;
  805. +};
  806. +
  807. +/***
  808. + * R/W ops
  809. + */
  810. +
  811. +static inline u32 enet_read(struct bcm4908_enet *enet, u16 offset)
  812. +{
  813. + return readl(enet->base + offset);
  814. +}
  815. +
  816. +static inline void enet_write(struct bcm4908_enet *enet, u16 offset, u32 value)
  817. +{
  818. + writel(value, enet->base + offset);
  819. +}
  820. +
  821. +static inline void enet_maskset(struct bcm4908_enet *enet, u16 offset, u32 mask, u32 set)
  822. +{
  823. + u32 val;
  824. +
  825. + WARN_ON(set & ~mask);
  826. +
  827. + val = enet_read(enet, offset);
  828. + val = (val & ~mask) | (set & mask);
  829. + enet_write(enet, offset, val);
  830. +}
  831. +
  832. +static inline void enet_set(struct bcm4908_enet *enet, u16 offset, u32 set)
  833. +{
  834. + enet_maskset(enet, offset, set, set);
  835. +}
  836. +
  837. +static inline u32 enet_umac_read(struct bcm4908_enet *enet, u16 offset)
  838. +{
  839. + return enet_read(enet, ENET_UNIMAC + offset);
  840. +}
  841. +
  842. +static inline void enet_umac_write(struct bcm4908_enet *enet, u16 offset, u32 value)
  843. +{
  844. + enet_write(enet, ENET_UNIMAC + offset, value);
  845. +}
  846. +
  847. +static inline void enet_umac_maskset(struct bcm4908_enet *enet, u16 offset, u32 mask, u32 set)
  848. +{
  849. + enet_maskset(enet, ENET_UNIMAC + offset, mask, set);
  850. +}
  851. +
  852. +static inline void enet_umac_set(struct bcm4908_enet *enet, u16 offset, u32 set)
  853. +{
  854. + enet_set(enet, ENET_UNIMAC + offset, set);
  855. +}
  856. +
  857. +/***
  858. + * Helpers
  859. + */
  860. +
  861. +static void bcm4908_enet_intrs_on(struct bcm4908_enet *enet)
  862. +{
  863. + enet_write(enet, ENET_DMA_CH_RX_CFG + ENET_DMA_CH_CFG_INT_MASK, ENET_DMA_INT_DEFAULTS);
  864. +}
  865. +
  866. +static void bcm4908_enet_intrs_off(struct bcm4908_enet *enet)
  867. +{
  868. + enet_write(enet, ENET_DMA_CH_RX_CFG + ENET_DMA_CH_CFG_INT_MASK, 0);
  869. +}
  870. +
  871. +static void bcm4908_enet_intrs_ack(struct bcm4908_enet *enet)
  872. +{
  873. + enet_write(enet, ENET_DMA_CH_RX_CFG + ENET_DMA_CH_CFG_INT_STAT, ENET_DMA_INT_DEFAULTS);
  874. +}
  875. +
  876. +/***
  877. + * DMA
  878. + */
  879. +
  880. +static int bcm4908_dma_alloc_buf_descs(struct bcm4908_enet *enet,
  881. + struct bcm4908_enet_dma_ring *ring)
  882. +{
  883. + int size = ring->length * sizeof(struct bcm4908_enet_dma_ring_bd);
  884. + struct device *dev = enet->dev;
  885. +
  886. + ring->cpu_addr = dma_alloc_coherent(dev, size, &ring->dma_addr, GFP_KERNEL);
  887. + if (!ring->cpu_addr)
  888. + return -ENOMEM;
  889. +
  890. + if (((uintptr_t)ring->cpu_addr) & (0x40 - 1)) {
  891. + dev_err(dev, "Invalid DMA ring alignment\n");
  892. + goto err_free_buf_descs;
  893. + }
  894. +
  895. + ring->slots = kzalloc(ring->length * sizeof(*ring->slots), GFP_KERNEL);
  896. + if (!ring->slots)
  897. + goto err_free_buf_descs;
  898. +
  899. + memset(ring->cpu_addr, 0, size);
  900. +
  901. + ring->read_idx = 0;
  902. + ring->write_idx = 0;
  903. +
  904. + return 0;
  905. +
  906. +err_free_buf_descs:
  907. + dma_free_coherent(dev, size, ring->cpu_addr, ring->dma_addr);
  908. + return -ENOMEM;
  909. +}
  910. +
  911. +static void bcm4908_enet_dma_free(struct bcm4908_enet *enet)
  912. +{
  913. + struct bcm4908_enet_dma_ring *tx_ring = &enet->tx_ring;
  914. + struct bcm4908_enet_dma_ring *rx_ring = &enet->rx_ring;
  915. + struct device *dev = enet->dev;
  916. + int size;
  917. +
  918. + size = rx_ring->length * sizeof(struct bcm4908_enet_dma_ring_bd);
  919. + if (rx_ring->cpu_addr)
  920. + dma_free_coherent(dev, size, rx_ring->cpu_addr, rx_ring->dma_addr);
  921. + kfree(rx_ring->slots);
  922. +
  923. + size = tx_ring->length * sizeof(struct bcm4908_enet_dma_ring_bd);
  924. + if (tx_ring->cpu_addr)
  925. + dma_free_coherent(dev, size, tx_ring->cpu_addr, tx_ring->dma_addr);
  926. + kfree(tx_ring->slots);
  927. +}
  928. +
  929. +static int bcm4908_enet_dma_alloc(struct bcm4908_enet *enet)
  930. +{
  931. + struct bcm4908_enet_dma_ring *tx_ring = &enet->tx_ring;
  932. + struct bcm4908_enet_dma_ring *rx_ring = &enet->rx_ring;
  933. + struct device *dev = enet->dev;
  934. + int err;
  935. +
  936. + tx_ring->length = ENET_TX_BDS_NUM;
  937. + tx_ring->is_tx = 1;
  938. + tx_ring->cfg_block = ENET_DMA_CH_TX_CFG;
  939. + tx_ring->st_ram_block = ENET_DMA_CH_TX_STATE_RAM;
  940. + err = bcm4908_dma_alloc_buf_descs(enet, tx_ring);
  941. + if (err) {
  942. + dev_err(dev, "Failed to alloc TX buf descriptors: %d\n", err);
  943. + return err;
  944. + }
  945. +
  946. + rx_ring->length = ENET_RX_BDS_NUM;
  947. + rx_ring->is_tx = 0;
  948. + rx_ring->cfg_block = ENET_DMA_CH_RX_CFG;
  949. + rx_ring->st_ram_block = ENET_DMA_CH_RX_STATE_RAM;
  950. + err = bcm4908_dma_alloc_buf_descs(enet, rx_ring);
  951. + if (err) {
  952. + dev_err(dev, "Failed to alloc RX buf descriptors: %d\n", err);
  953. + bcm4908_enet_dma_free(enet);
  954. + return err;
  955. + }
  956. +
  957. + return 0;
  958. +}
  959. +
  960. +static void bcm4908_enet_dma_reset(struct bcm4908_enet *enet)
  961. +{
  962. + struct bcm4908_enet_dma_ring *rings[] = { &enet->rx_ring, &enet->tx_ring };
  963. + int i;
  964. +
  965. + /* Disable the DMA controller and channel */
  966. + for (i = 0; i < ARRAY_SIZE(rings); i++)
  967. + enet_write(enet, rings[i]->cfg_block + ENET_DMA_CH_CFG, 0);
  968. + enet_maskset(enet, ENET_DMA_CONTROLLER_CFG, ENET_DMA_CTRL_CFG_MASTER_EN, 0);
  969. +
  970. + /* Reset channels state */
  971. + for (i = 0; i < ARRAY_SIZE(rings); i++) {
  972. + struct bcm4908_enet_dma_ring *ring = rings[i];
  973. +
  974. + enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_BASE_DESC_PTR, 0);
  975. + enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_STATE_DATA, 0);
  976. + enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_DESC_LEN_STATUS, 0);
  977. + enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_DESC_BASE_BUFPTR, 0);
  978. + }
  979. +}
  980. +
  981. +static int bcm4908_enet_dma_alloc_rx_buf(struct bcm4908_enet *enet, unsigned int idx)
  982. +{
  983. + struct bcm4908_enet_dma_ring_bd *buf_desc = &enet->rx_ring.buf_desc[idx];
  984. + struct bcm4908_enet_dma_ring_slot *slot = &enet->rx_ring.slots[idx];
  985. + struct device *dev = enet->dev;
  986. + u32 tmp;
  987. + int err;
  988. +
  989. + slot->len = ENET_MTU_MAX + ENET_MTU_MAX_EXTRA_SIZE;
  990. +
  991. + slot->skb = netdev_alloc_skb(enet->netdev, slot->len);
  992. + if (!slot->skb)
  993. + return -ENOMEM;
  994. +
  995. + slot->dma_addr = dma_map_single(dev, slot->skb->data, slot->len, DMA_FROM_DEVICE);
  996. + err = dma_mapping_error(dev, slot->dma_addr);
  997. + if (err) {
  998. + dev_err(dev, "Failed to map DMA buffer: %d\n", err);
  999. + kfree_skb(slot->skb);
  1000. + slot->skb = NULL;
  1001. + return err;
  1002. + }
  1003. +
  1004. + tmp = slot->len << DMA_CTL_LEN_DESC_BUFLENGTH_SHIFT;
  1005. + tmp |= DMA_CTL_STATUS_OWN;
  1006. + if (idx == enet->rx_ring.length - 1)
  1007. + tmp |= DMA_CTL_STATUS_WRAP;
  1008. + buf_desc->ctl = cpu_to_le32(tmp);
  1009. + buf_desc->addr = cpu_to_le32(slot->dma_addr);
  1010. +
  1011. + return 0;
  1012. +}
  1013. +
  1014. +static void bcm4908_enet_dma_ring_init(struct bcm4908_enet *enet,
  1015. + struct bcm4908_enet_dma_ring *ring)
  1016. +{
  1017. + int reset_channel = 0; /* We support only 1 main channel (with TX and RX) */
  1018. + int reset_subch = ring->is_tx ? 1 : 0;
  1019. +
  1020. + /* Reset the DMA channel */
  1021. + enet_write(enet, ENET_DMA_CTRL_CHANNEL_RESET, BIT(reset_channel * 2 + reset_subch));
  1022. + enet_write(enet, ENET_DMA_CTRL_CHANNEL_RESET, 0);
  1023. +
  1024. + enet_write(enet, ring->cfg_block + ENET_DMA_CH_CFG, 0);
  1025. + enet_write(enet, ring->cfg_block + ENET_DMA_CH_CFG_MAX_BURST, ENET_DMA_MAX_BURST_LEN);
  1026. + enet_write(enet, ring->cfg_block + ENET_DMA_CH_CFG_INT_MASK, 0);
  1027. +
  1028. + enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_BASE_DESC_PTR,
  1029. + (uint32_t)ring->dma_addr);
  1030. +}
  1031. +
  1032. +static void bcm4908_enet_dma_uninit(struct bcm4908_enet *enet)
  1033. +{
  1034. + struct bcm4908_enet_dma_ring *rx_ring = &enet->rx_ring;
  1035. + struct bcm4908_enet_dma_ring_slot *slot;
  1036. + struct device *dev = enet->dev;
  1037. + int i;
  1038. +
  1039. + for (i = rx_ring->length - 1; i >= 0; i--) {
  1040. + slot = &rx_ring->slots[i];
  1041. + if (!slot->skb)
  1042. + continue;
  1043. + dma_unmap_single(dev, slot->dma_addr, slot->len, DMA_FROM_DEVICE);
  1044. + kfree_skb(slot->skb);
  1045. + slot->skb = NULL;
  1046. + }
  1047. +}
  1048. +
  1049. +static int bcm4908_enet_dma_init(struct bcm4908_enet *enet)
  1050. +{
  1051. + struct bcm4908_enet_dma_ring *rx_ring = &enet->rx_ring;
  1052. + struct device *dev = enet->dev;
  1053. + int err;
  1054. + int i;
  1055. +
  1056. + for (i = 0; i < rx_ring->length; i++) {
  1057. + err = bcm4908_enet_dma_alloc_rx_buf(enet, i);
  1058. + if (err) {
  1059. + dev_err(dev, "Failed to alloc RX buffer: %d\n", err);
  1060. + bcm4908_enet_dma_uninit(enet);
  1061. + return err;
  1062. + }
  1063. + }
  1064. +
  1065. + bcm4908_enet_dma_ring_init(enet, &enet->tx_ring);
  1066. + bcm4908_enet_dma_ring_init(enet, &enet->rx_ring);
  1067. +
  1068. + return 0;
  1069. +}
  1070. +
  1071. +static void bcm4908_enet_dma_tx_ring_ensable(struct bcm4908_enet *enet,
  1072. + struct bcm4908_enet_dma_ring *ring)
  1073. +{
  1074. + enet_write(enet, ring->cfg_block + ENET_DMA_CH_CFG, ENET_DMA_CH_CFG_ENABLE);
  1075. +}
  1076. +
  1077. +static void bcm4908_enet_dma_tx_ring_disable(struct bcm4908_enet *enet,
  1078. + struct bcm4908_enet_dma_ring *ring)
  1079. +{
  1080. + enet_write(enet, ring->cfg_block + ENET_DMA_CH_CFG, 0);
  1081. +}
  1082. +
  1083. +static void bcm4908_enet_dma_rx_ring_enable(struct bcm4908_enet *enet,
  1084. + struct bcm4908_enet_dma_ring *ring)
  1085. +{
  1086. + enet_set(enet, ring->cfg_block + ENET_DMA_CH_CFG, ENET_DMA_CH_CFG_ENABLE);
  1087. +}
  1088. +
  1089. +static void bcm4908_enet_dma_rx_ring_disable(struct bcm4908_enet *enet,
  1090. + struct bcm4908_enet_dma_ring *ring)
  1091. +{
  1092. + unsigned long deadline;
  1093. + u32 tmp;
  1094. +
  1095. + enet_maskset(enet, ring->cfg_block + ENET_DMA_CH_CFG, ENET_DMA_CH_CFG_ENABLE, 0);
  1096. +
  1097. + deadline = jiffies + usecs_to_jiffies(2000);
  1098. + do {
  1099. + tmp = enet_read(enet, ring->cfg_block + ENET_DMA_CH_CFG);
  1100. + if (!(tmp & ENET_DMA_CH_CFG_ENABLE))
  1101. + return;
  1102. + enet_maskset(enet, ring->cfg_block + ENET_DMA_CH_CFG, ENET_DMA_CH_CFG_ENABLE, 0);
  1103. + usleep_range(10, 30);
  1104. + } while (!time_after_eq(jiffies, deadline));
  1105. +
  1106. + dev_warn(enet->dev, "Timeout waiting for DMA TX stop\n");
  1107. +}
  1108. +
  1109. +/***
  1110. + * Ethernet driver
  1111. + */
  1112. +
  1113. +static void bcm4908_enet_gmac_init(struct bcm4908_enet *enet)
  1114. +{
  1115. + u32 cmd;
  1116. +
  1117. + cmd = enet_umac_read(enet, UMAC_CMD);
  1118. + enet_umac_write(enet, UMAC_CMD, cmd | CMD_SW_RESET);
  1119. + enet_umac_write(enet, UMAC_CMD, cmd & ~CMD_SW_RESET);
  1120. +
  1121. + enet_set(enet, ENET_FLUSH, ENET_FLUSH_RXFIFO_FLUSH | ENET_FLUSH_TXFIFO_FLUSH);
  1122. + enet_maskset(enet, ENET_FLUSH, ENET_FLUSH_RXFIFO_FLUSH | ENET_FLUSH_TXFIFO_FLUSH, 0);
  1123. +
  1124. + enet_set(enet, ENET_MIB_CTRL, ENET_MIB_CTRL_CLR_MIB);
  1125. + enet_maskset(enet, ENET_MIB_CTRL, ENET_MIB_CTRL_CLR_MIB, 0);
  1126. +
  1127. + cmd = enet_umac_read(enet, UMAC_CMD);
  1128. + cmd &= ~(CMD_SPEED_MASK << CMD_SPEED_SHIFT);
  1129. + cmd &= ~CMD_TX_EN;
  1130. + cmd &= ~CMD_RX_EN;
  1131. + cmd |= CMD_SPEED_1000 << CMD_SPEED_SHIFT;
  1132. + enet_umac_write(enet, UMAC_CMD, cmd);
  1133. +
  1134. + enet_maskset(enet, ENET_GMAC_STATUS,
  1135. + ENET_GMAC_STATUS_ETH_SPEED_MASK |
  1136. + ENET_GMAC_STATUS_HD |
  1137. + ENET_GMAC_STATUS_AUTO_CFG_EN |
  1138. + ENET_GMAC_STATUS_LINK_UP,
  1139. + ENET_GMAC_STATUS_ETH_SPEED_1000 |
  1140. + ENET_GMAC_STATUS_AUTO_CFG_EN |
  1141. + ENET_GMAC_STATUS_LINK_UP);
  1142. +}
  1143. +
  1144. +static irqreturn_t bcm4908_enet_irq_handler(int irq, void *dev_id)
  1145. +{
  1146. + struct bcm4908_enet *enet = dev_id;
  1147. +
  1148. + bcm4908_enet_intrs_off(enet);
  1149. + bcm4908_enet_intrs_ack(enet);
  1150. +
  1151. + napi_schedule(&enet->napi);
  1152. +
  1153. + return IRQ_HANDLED;
  1154. +}
  1155. +
  1156. +static int bcm4908_enet_open(struct net_device *netdev)
  1157. +{
  1158. + struct bcm4908_enet *enet = netdev_priv(netdev);
  1159. + struct device *dev = enet->dev;
  1160. + int err;
  1161. +
  1162. + err = request_irq(netdev->irq, bcm4908_enet_irq_handler, 0, "enet", enet);
  1163. + if (err) {
  1164. + dev_err(dev, "Failed to request IRQ %d: %d\n", netdev->irq, err);
  1165. + return err;
  1166. + }
  1167. +
  1168. + bcm4908_enet_gmac_init(enet);
  1169. + bcm4908_enet_dma_reset(enet);
  1170. + bcm4908_enet_dma_init(enet);
  1171. +
  1172. + enet_umac_set(enet, UMAC_CMD, CMD_TX_EN | CMD_RX_EN);
  1173. +
  1174. + enet_set(enet, ENET_DMA_CONTROLLER_CFG, ENET_DMA_CTRL_CFG_MASTER_EN);
  1175. + enet_maskset(enet, ENET_DMA_CONTROLLER_CFG, ENET_DMA_CTRL_CFG_FLOWC_CH1_EN, 0);
  1176. + bcm4908_enet_dma_rx_ring_enable(enet, &enet->rx_ring);
  1177. +
  1178. + napi_enable(&enet->napi);
  1179. + netif_carrier_on(netdev);
  1180. + netif_start_queue(netdev);
  1181. +
  1182. + bcm4908_enet_intrs_ack(enet);
  1183. + bcm4908_enet_intrs_on(enet);
  1184. +
  1185. + return 0;
  1186. +}
  1187. +
  1188. +static int bcm4908_enet_stop(struct net_device *netdev)
  1189. +{
  1190. + struct bcm4908_enet *enet = netdev_priv(netdev);
  1191. +
  1192. + netif_stop_queue(netdev);
  1193. + netif_carrier_off(netdev);
  1194. + napi_disable(&enet->napi);
  1195. +
  1196. + bcm4908_enet_dma_rx_ring_disable(enet, &enet->rx_ring);
  1197. + bcm4908_enet_dma_tx_ring_disable(enet, &enet->tx_ring);
  1198. +
  1199. + bcm4908_enet_dma_uninit(enet);
  1200. +
  1201. + free_irq(enet->netdev->irq, enet);
  1202. +
  1203. + return 0;
  1204. +}
  1205. +
  1206. +static int bcm4908_enet_start_xmit(struct sk_buff *skb, struct net_device *netdev)
  1207. +{
  1208. + struct bcm4908_enet *enet = netdev_priv(netdev);
  1209. + struct bcm4908_enet_dma_ring *ring = &enet->tx_ring;
  1210. + struct bcm4908_enet_dma_ring_slot *slot;
  1211. + struct device *dev = enet->dev;
  1212. + struct bcm4908_enet_dma_ring_bd *buf_desc;
  1213. + int free_buf_descs;
  1214. + u32 tmp;
  1215. +
  1216. + /* Free transmitted skbs */
  1217. + while (ring->read_idx != ring->write_idx) {
  1218. + buf_desc = &ring->buf_desc[ring->read_idx];
  1219. + if (buf_desc->ctl & DMA_CTL_STATUS_OWN)
  1220. + break;
  1221. + slot = &ring->slots[ring->read_idx];
  1222. +
  1223. + dma_unmap_single(dev, slot->dma_addr, slot->len, DMA_TO_DEVICE);
  1224. + dev_kfree_skb(slot->skb);
  1225. + if (++ring->read_idx == ring->length)
  1226. + ring->read_idx = 0;
  1227. + }
  1228. +
  1229. + /* Don't use the last empty buf descriptor */
  1230. + if (ring->read_idx <= ring->write_idx)
  1231. + free_buf_descs = ring->read_idx - ring->write_idx + ring->length;
  1232. + else
  1233. + free_buf_descs = ring->read_idx - ring->write_idx;
  1234. + if (free_buf_descs < 2)
  1235. + return NETDEV_TX_BUSY;
  1236. +
  1237. + /* Hardware removes OWN bit after sending data */
  1238. + buf_desc = &ring->buf_desc[ring->write_idx];
  1239. + if (unlikely(le32_to_cpu(buf_desc->ctl) & DMA_CTL_STATUS_OWN)) {
  1240. + netif_stop_queue(netdev);
  1241. + return NETDEV_TX_BUSY;
  1242. + }
  1243. +
  1244. + slot = &ring->slots[ring->write_idx];
  1245. + slot->skb = skb;
  1246. + slot->len = skb->len;
  1247. + slot->dma_addr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
  1248. + if (unlikely(dma_mapping_error(dev, slot->dma_addr)))
  1249. + return NETDEV_TX_BUSY;
  1250. +
  1251. + tmp = skb->len << DMA_CTL_LEN_DESC_BUFLENGTH_SHIFT;
  1252. + tmp |= DMA_CTL_STATUS_OWN;
  1253. + tmp |= DMA_CTL_STATUS_SOP;
  1254. + tmp |= DMA_CTL_STATUS_EOP;
  1255. + tmp |= DMA_CTL_STATUS_APPEND_CRC;
  1256. + if (ring->write_idx + 1 == ring->length - 1)
  1257. + tmp |= DMA_CTL_STATUS_WRAP;
  1258. +
  1259. + buf_desc->addr = cpu_to_le32((uint32_t)slot->dma_addr);
  1260. + buf_desc->ctl = cpu_to_le32(tmp);
  1261. +
  1262. + bcm4908_enet_dma_tx_ring_ensable(enet, &enet->tx_ring);
  1263. +
  1264. + if (++ring->write_idx == ring->length - 1)
  1265. + ring->write_idx = 0;
  1266. + enet->netdev->stats.tx_bytes += skb->len;
  1267. + enet->netdev->stats.tx_packets++;
  1268. +
  1269. + return NETDEV_TX_OK;
  1270. +}
  1271. +
  1272. +static int bcm4908_enet_poll(struct napi_struct *napi, int weight)
  1273. +{
  1274. + struct bcm4908_enet *enet = container_of(napi, struct bcm4908_enet, napi);
  1275. + struct device *dev = enet->dev;
  1276. + int handled = 0;
  1277. +
  1278. + while (handled < weight) {
  1279. + struct bcm4908_enet_dma_ring_bd *buf_desc;
  1280. + struct bcm4908_enet_dma_ring_slot slot;
  1281. + u32 ctl;
  1282. + int len;
  1283. + int err;
  1284. +
  1285. + buf_desc = &enet->rx_ring.buf_desc[enet->rx_ring.read_idx];
  1286. + ctl = le32_to_cpu(buf_desc->ctl);
  1287. + if (ctl & DMA_CTL_STATUS_OWN)
  1288. + break;
  1289. +
  1290. + slot = enet->rx_ring.slots[enet->rx_ring.read_idx];
  1291. +
  1292. + /* Provide new buffer before unpinning the old one */
  1293. + err = bcm4908_enet_dma_alloc_rx_buf(enet, enet->rx_ring.read_idx);
  1294. + if (err)
  1295. + break;
  1296. +
  1297. + if (++enet->rx_ring.read_idx == enet->rx_ring.length)
  1298. + enet->rx_ring.read_idx = 0;
  1299. +
  1300. + len = (ctl & DMA_CTL_LEN_DESC_BUFLENGTH) >> DMA_CTL_LEN_DESC_BUFLENGTH_SHIFT;
  1301. +
  1302. + if (len < ENET_MTU_MIN ||
  1303. + (ctl & (DMA_CTL_STATUS_SOP | DMA_CTL_STATUS_EOP)) != (DMA_CTL_STATUS_SOP | DMA_CTL_STATUS_EOP)) {
  1304. + enet->netdev->stats.rx_dropped++;
  1305. + break;
  1306. + }
  1307. +
  1308. + dma_unmap_single(dev, slot.dma_addr, slot.len, DMA_FROM_DEVICE);
  1309. +
  1310. + skb_put(slot.skb, len - 4 + 2);
  1311. + slot.skb->protocol = eth_type_trans(slot.skb, enet->netdev);
  1312. + netif_receive_skb(slot.skb);
  1313. +
  1314. + enet->netdev->stats.rx_packets++;
  1315. + enet->netdev->stats.rx_bytes += len;
  1316. + }
  1317. +
  1318. + if (handled < weight) {
  1319. + napi_complete_done(napi, handled);
  1320. + bcm4908_enet_intrs_on(enet);
  1321. + }
  1322. +
  1323. + return handled;
  1324. +}
  1325. +
  1326. +static const struct net_device_ops bcm96xx_netdev_ops = {
  1327. + .ndo_open = bcm4908_enet_open,
  1328. + .ndo_stop = bcm4908_enet_stop,
  1329. + .ndo_start_xmit = bcm4908_enet_start_xmit,
  1330. + .ndo_set_mac_address = eth_mac_addr,
  1331. +};
  1332. +
  1333. +static int bcm4908_enet_probe(struct platform_device *pdev)
  1334. +{
  1335. + struct device *dev = &pdev->dev;
  1336. + struct net_device *netdev;
  1337. + struct bcm4908_enet *enet;
  1338. + int err;
  1339. +
  1340. + netdev = devm_alloc_etherdev(dev, sizeof(*enet));
  1341. + if (!netdev)
  1342. + return -ENOMEM;
  1343. +
  1344. + enet = netdev_priv(netdev);
  1345. + enet->dev = dev;
  1346. + enet->netdev = netdev;
  1347. +
  1348. + enet->base = devm_platform_ioremap_resource(pdev, 0);
  1349. + if (IS_ERR(enet->base)) {
  1350. + dev_err(dev, "Failed to map registers: %ld\n", PTR_ERR(enet->base));
  1351. + return PTR_ERR(enet->base);
  1352. + }
  1353. +
  1354. + netdev->irq = platform_get_irq_byname(pdev, "rx");
  1355. + if (netdev->irq < 0)
  1356. + return netdev->irq;
  1357. +
  1358. + dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
  1359. +
  1360. + err = bcm4908_enet_dma_alloc(enet);
  1361. + if (err)
  1362. + return err;
  1363. +
  1364. + SET_NETDEV_DEV(netdev, &pdev->dev);
  1365. + eth_hw_addr_random(netdev);
  1366. + netdev->netdev_ops = &bcm96xx_netdev_ops;
  1367. + netdev->min_mtu = ETH_ZLEN;
  1368. + netdev->mtu = ENET_MTU_MAX;
  1369. + netdev->max_mtu = ENET_MTU_MAX;
  1370. + netif_napi_add(netdev, &enet->napi, bcm4908_enet_poll, 64);
  1371. +
  1372. + err = register_netdev(netdev);
  1373. + if (err) {
  1374. + bcm4908_enet_dma_free(enet);
  1375. + return err;
  1376. + }
  1377. +
  1378. + platform_set_drvdata(pdev, enet);
  1379. +
  1380. + return 0;
  1381. +}
  1382. +
  1383. +static int bcm4908_enet_remove(struct platform_device *pdev)
  1384. +{
  1385. + struct bcm4908_enet *enet = platform_get_drvdata(pdev);
  1386. +
  1387. + unregister_netdev(enet->netdev);
  1388. + netif_napi_del(&enet->napi);
  1389. + bcm4908_enet_dma_free(enet);
  1390. +
  1391. + return 0;
  1392. +}
  1393. +
  1394. +static const struct of_device_id bcm4908_enet_of_match[] = {
  1395. + { .compatible = "brcm,bcm4908-enet"},
  1396. + {},
  1397. +};
  1398. +
  1399. +static struct platform_driver bcm4908_enet_driver = {
  1400. + .driver = {
  1401. + .name = "bcm4908_enet",
  1402. + .of_match_table = bcm4908_enet_of_match,
  1403. + },
  1404. + .probe = bcm4908_enet_probe,
  1405. + .remove = bcm4908_enet_remove,
  1406. +};
  1407. +module_platform_driver(bcm4908_enet_driver);
  1408. +
  1409. +MODULE_LICENSE("GPL v2");
  1410. +MODULE_DEVICE_TABLE(of, bcm4908_enet_of_match);
  1411. --- a/drivers/net/ethernet/broadcom/bcm4908enet.h
  1412. +++ /dev/null
  1413. @@ -1,96 +0,0 @@
  1414. -/* SPDX-License-Identifier: GPL-2.0-only */
  1415. -#ifndef __BCM4908ENET_H
  1416. -#define __BCM4908ENET_H
  1417. -
  1418. -#define ENET_CONTROL 0x000
  1419. -#define ENET_MIB_CTRL 0x004
  1420. -#define ENET_MIB_CTRL_CLR_MIB 0x00000001
  1421. -#define ENET_RX_ERR_MASK 0x008
  1422. -#define ENET_MIB_MAX_PKT_SIZE 0x00C
  1423. -#define ENET_MIB_MAX_PKT_SIZE_VAL 0x00003fff
  1424. -#define ENET_DIAG_OUT 0x01c
  1425. -#define ENET_ENABLE_DROP_PKT 0x020
  1426. -#define ENET_IRQ_ENABLE 0x024
  1427. -#define ENET_IRQ_ENABLE_OVFL 0x00000001
  1428. -#define ENET_GMAC_STATUS 0x028
  1429. -#define ENET_GMAC_STATUS_ETH_SPEED_MASK 0x00000003
  1430. -#define ENET_GMAC_STATUS_ETH_SPEED_10 0x00000000
  1431. -#define ENET_GMAC_STATUS_ETH_SPEED_100 0x00000001
  1432. -#define ENET_GMAC_STATUS_ETH_SPEED_1000 0x00000002
  1433. -#define ENET_GMAC_STATUS_HD 0x00000004
  1434. -#define ENET_GMAC_STATUS_AUTO_CFG_EN 0x00000008
  1435. -#define ENET_GMAC_STATUS_LINK_UP 0x00000010
  1436. -#define ENET_IRQ_STATUS 0x02c
  1437. -#define ENET_IRQ_STATUS_OVFL 0x00000001
  1438. -#define ENET_OVERFLOW_COUNTER 0x030
  1439. -#define ENET_FLUSH 0x034
  1440. -#define ENET_FLUSH_RXFIFO_FLUSH 0x00000001
  1441. -#define ENET_FLUSH_TXFIFO_FLUSH 0x00000002
  1442. -#define ENET_RSV_SELECT 0x038
  1443. -#define ENET_BP_FORCE 0x03c
  1444. -#define ENET_BP_FORCE_FORCE 0x00000001
  1445. -#define ENET_DMA_RX_OK_TO_SEND_COUNT 0x040
  1446. -#define ENET_DMA_RX_OK_TO_SEND_COUNT_VAL 0x0000000f
  1447. -#define ENET_TX_CRC_CTRL 0x044
  1448. -#define ENET_MIB 0x200
  1449. -#define ENET_UNIMAC 0x400
  1450. -#define ENET_DMA 0x800
  1451. -#define ENET_DMA_CONTROLLER_CFG 0x800
  1452. -#define ENET_DMA_CTRL_CFG_MASTER_EN 0x00000001
  1453. -#define ENET_DMA_CTRL_CFG_FLOWC_CH1_EN 0x00000002
  1454. -#define ENET_DMA_CTRL_CFG_FLOWC_CH3_EN 0x00000004
  1455. -#define ENET_DMA_FLOWCTL_CH1_THRESH_LO 0x804
  1456. -#define ENET_DMA_FLOWCTL_CH1_THRESH_HI 0x808
  1457. -#define ENET_DMA_FLOWCTL_CH1_ALLOC 0x80c
  1458. -#define ENET_DMA_FLOWCTL_CH1_ALLOC_FORCE 0x80000000
  1459. -#define ENET_DMA_FLOWCTL_CH3_THRESH_LO 0x810
  1460. -#define ENET_DMA_FLOWCTL_CH3_THRESH_HI 0x814
  1461. -#define ENET_DMA_FLOWCTL_CH3_ALLOC 0x818
  1462. -#define ENET_DMA_FLOWCTL_CH5_THRESH_LO 0x81C
  1463. -#define ENET_DMA_FLOWCTL_CH5_THRESH_HI 0x820
  1464. -#define ENET_DMA_FLOWCTL_CH5_ALLOC 0x824
  1465. -#define ENET_DMA_FLOWCTL_CH7_THRESH_LO 0x828
  1466. -#define ENET_DMA_FLOWCTL_CH7_THRESH_HI 0x82C
  1467. -#define ENET_DMA_FLOWCTL_CH7_ALLOC 0x830
  1468. -#define ENET_DMA_CTRL_CHANNEL_RESET 0x834
  1469. -#define ENET_DMA_CTRL_CHANNEL_DEBUG 0x838
  1470. -#define ENET_DMA_CTRL_GLOBAL_INTERRUPT_STATUS 0x840
  1471. -#define ENET_DMA_CTRL_GLOBAL_INTERRUPT_MASK 0x844
  1472. -#define ENET_DMA_CH0_CFG 0xa00 /* RX */
  1473. -#define ENET_DMA_CH1_CFG 0xa10 /* TX */
  1474. -#define ENET_DMA_CH0_STATE_RAM 0xc00 /* RX */
  1475. -#define ENET_DMA_CH1_STATE_RAM 0xc10 /* TX */
  1476. -
  1477. -#define ENET_DMA_CH_CFG 0x00 /* assorted configuration */
  1478. -#define ENET_DMA_CH_CFG_ENABLE 0x00000001 /* set to enable channel */
  1479. -#define ENET_DMA_CH_CFG_PKT_HALT 0x00000002 /* idle after an EOP flag is detected */
  1480. -#define ENET_DMA_CH_CFG_BURST_HALT 0x00000004 /* idle after finish current memory burst */
  1481. -#define ENET_DMA_CH_CFG_INT_STAT 0x04 /* interrupts control and status */
  1482. -#define ENET_DMA_CH_CFG_INT_MASK 0x08 /* interrupts mask */
  1483. -#define ENET_DMA_CH_CFG_INT_BUFF_DONE 0x00000001 /* buffer done */
  1484. -#define ENET_DMA_CH_CFG_INT_DONE 0x00000002 /* packet xfer complete */
  1485. -#define ENET_DMA_CH_CFG_INT_NO_DESC 0x00000004 /* no valid descriptors */
  1486. -#define ENET_DMA_CH_CFG_INT_RX_ERROR 0x00000008 /* rxdma detect client protocol error */
  1487. -#define ENET_DMA_CH_CFG_MAX_BURST 0x0c /* max burst length permitted */
  1488. -#define ENET_DMA_CH_CFG_MAX_BURST_DESCSIZE_SEL 0x00040000 /* DMA Descriptor Size Selection */
  1489. -#define ENET_DMA_CH_CFG_SIZE 0x10
  1490. -
  1491. -#define ENET_DMA_CH_STATE_RAM_BASE_DESC_PTR 0x00 /* descriptor ring start address */
  1492. -#define ENET_DMA_CH_STATE_RAM_STATE_DATA 0x04 /* state/bytes done/ring offset */
  1493. -#define ENET_DMA_CH_STATE_RAM_DESC_LEN_STATUS 0x08 /* buffer descriptor status and len */
  1494. -#define ENET_DMA_CH_STATE_RAM_DESC_BASE_BUFPTR 0x0c /* buffer descrpitor current processing */
  1495. -#define ENET_DMA_CH_STATE_RAM_SIZE 0x10
  1496. -
  1497. -#define DMA_CTL_STATUS_APPEND_CRC 0x00000100
  1498. -#define DMA_CTL_STATUS_APPEND_BRCM_TAG 0x00000200
  1499. -#define DMA_CTL_STATUS_PRIO 0x00000C00 /* Prio for Tx */
  1500. -#define DMA_CTL_STATUS_WRAP 0x00001000 /* */
  1501. -#define DMA_CTL_STATUS_SOP 0x00002000 /* first buffer in packet */
  1502. -#define DMA_CTL_STATUS_EOP 0x00004000 /* last buffer in packet */
  1503. -#define DMA_CTL_STATUS_OWN 0x00008000 /* cleared by DMA, set by SW */
  1504. -#define DMA_CTL_LEN_DESC_BUFLENGTH 0x0fff0000
  1505. -#define DMA_CTL_LEN_DESC_BUFLENGTH_SHIFT 16
  1506. -#define DMA_CTL_LEN_DESC_MULTICAST 0x40000000
  1507. -#define DMA_CTL_LEN_DESC_USEFPM 0x80000000
  1508. -
  1509. -#endif
  1510. --- /dev/null
  1511. +++ b/drivers/net/ethernet/broadcom/bcm4908_enet.h
  1512. @@ -0,0 +1,96 @@
  1513. +/* SPDX-License-Identifier: GPL-2.0-only */
  1514. +#ifndef __BCM4908_ENET_H
  1515. +#define __BCM4908_ENET_H
  1516. +
  1517. +#define ENET_CONTROL 0x000
  1518. +#define ENET_MIB_CTRL 0x004
  1519. +#define ENET_MIB_CTRL_CLR_MIB 0x00000001
  1520. +#define ENET_RX_ERR_MASK 0x008
  1521. +#define ENET_MIB_MAX_PKT_SIZE 0x00C
  1522. +#define ENET_MIB_MAX_PKT_SIZE_VAL 0x00003fff
  1523. +#define ENET_DIAG_OUT 0x01c
  1524. +#define ENET_ENABLE_DROP_PKT 0x020
  1525. +#define ENET_IRQ_ENABLE 0x024
  1526. +#define ENET_IRQ_ENABLE_OVFL 0x00000001
  1527. +#define ENET_GMAC_STATUS 0x028
  1528. +#define ENET_GMAC_STATUS_ETH_SPEED_MASK 0x00000003
  1529. +#define ENET_GMAC_STATUS_ETH_SPEED_10 0x00000000
  1530. +#define ENET_GMAC_STATUS_ETH_SPEED_100 0x00000001
  1531. +#define ENET_GMAC_STATUS_ETH_SPEED_1000 0x00000002
  1532. +#define ENET_GMAC_STATUS_HD 0x00000004
  1533. +#define ENET_GMAC_STATUS_AUTO_CFG_EN 0x00000008
  1534. +#define ENET_GMAC_STATUS_LINK_UP 0x00000010
  1535. +#define ENET_IRQ_STATUS 0x02c
  1536. +#define ENET_IRQ_STATUS_OVFL 0x00000001
  1537. +#define ENET_OVERFLOW_COUNTER 0x030
  1538. +#define ENET_FLUSH 0x034
  1539. +#define ENET_FLUSH_RXFIFO_FLUSH 0x00000001
  1540. +#define ENET_FLUSH_TXFIFO_FLUSH 0x00000002
  1541. +#define ENET_RSV_SELECT 0x038
  1542. +#define ENET_BP_FORCE 0x03c
  1543. +#define ENET_BP_FORCE_FORCE 0x00000001
  1544. +#define ENET_DMA_RX_OK_TO_SEND_COUNT 0x040
  1545. +#define ENET_DMA_RX_OK_TO_SEND_COUNT_VAL 0x0000000f
  1546. +#define ENET_TX_CRC_CTRL 0x044
  1547. +#define ENET_MIB 0x200
  1548. +#define ENET_UNIMAC 0x400
  1549. +#define ENET_DMA 0x800
  1550. +#define ENET_DMA_CONTROLLER_CFG 0x800
  1551. +#define ENET_DMA_CTRL_CFG_MASTER_EN 0x00000001
  1552. +#define ENET_DMA_CTRL_CFG_FLOWC_CH1_EN 0x00000002
  1553. +#define ENET_DMA_CTRL_CFG_FLOWC_CH3_EN 0x00000004
  1554. +#define ENET_DMA_FLOWCTL_CH1_THRESH_LO 0x804
  1555. +#define ENET_DMA_FLOWCTL_CH1_THRESH_HI 0x808
  1556. +#define ENET_DMA_FLOWCTL_CH1_ALLOC 0x80c
  1557. +#define ENET_DMA_FLOWCTL_CH1_ALLOC_FORCE 0x80000000
  1558. +#define ENET_DMA_FLOWCTL_CH3_THRESH_LO 0x810
  1559. +#define ENET_DMA_FLOWCTL_CH3_THRESH_HI 0x814
  1560. +#define ENET_DMA_FLOWCTL_CH3_ALLOC 0x818
  1561. +#define ENET_DMA_FLOWCTL_CH5_THRESH_LO 0x81C
  1562. +#define ENET_DMA_FLOWCTL_CH5_THRESH_HI 0x820
  1563. +#define ENET_DMA_FLOWCTL_CH5_ALLOC 0x824
  1564. +#define ENET_DMA_FLOWCTL_CH7_THRESH_LO 0x828
  1565. +#define ENET_DMA_FLOWCTL_CH7_THRESH_HI 0x82C
  1566. +#define ENET_DMA_FLOWCTL_CH7_ALLOC 0x830
  1567. +#define ENET_DMA_CTRL_CHANNEL_RESET 0x834
  1568. +#define ENET_DMA_CTRL_CHANNEL_DEBUG 0x838
  1569. +#define ENET_DMA_CTRL_GLOBAL_INTERRUPT_STATUS 0x840
  1570. +#define ENET_DMA_CTRL_GLOBAL_INTERRUPT_MASK 0x844
  1571. +#define ENET_DMA_CH0_CFG 0xa00 /* RX */
  1572. +#define ENET_DMA_CH1_CFG 0xa10 /* TX */
  1573. +#define ENET_DMA_CH0_STATE_RAM 0xc00 /* RX */
  1574. +#define ENET_DMA_CH1_STATE_RAM 0xc10 /* TX */
  1575. +
  1576. +#define ENET_DMA_CH_CFG 0x00 /* assorted configuration */
  1577. +#define ENET_DMA_CH_CFG_ENABLE 0x00000001 /* set to enable channel */
  1578. +#define ENET_DMA_CH_CFG_PKT_HALT 0x00000002 /* idle after an EOP flag is detected */
  1579. +#define ENET_DMA_CH_CFG_BURST_HALT 0x00000004 /* idle after finish current memory burst */
  1580. +#define ENET_DMA_CH_CFG_INT_STAT 0x04 /* interrupts control and status */
  1581. +#define ENET_DMA_CH_CFG_INT_MASK 0x08 /* interrupts mask */
  1582. +#define ENET_DMA_CH_CFG_INT_BUFF_DONE 0x00000001 /* buffer done */
  1583. +#define ENET_DMA_CH_CFG_INT_DONE 0x00000002 /* packet xfer complete */
  1584. +#define ENET_DMA_CH_CFG_INT_NO_DESC 0x00000004 /* no valid descriptors */
  1585. +#define ENET_DMA_CH_CFG_INT_RX_ERROR 0x00000008 /* rxdma detect client protocol error */
  1586. +#define ENET_DMA_CH_CFG_MAX_BURST 0x0c /* max burst length permitted */
  1587. +#define ENET_DMA_CH_CFG_MAX_BURST_DESCSIZE_SEL 0x00040000 /* DMA Descriptor Size Selection */
  1588. +#define ENET_DMA_CH_CFG_SIZE 0x10
  1589. +
  1590. +#define ENET_DMA_CH_STATE_RAM_BASE_DESC_PTR 0x00 /* descriptor ring start address */
  1591. +#define ENET_DMA_CH_STATE_RAM_STATE_DATA 0x04 /* state/bytes done/ring offset */
  1592. +#define ENET_DMA_CH_STATE_RAM_DESC_LEN_STATUS 0x08 /* buffer descriptor status and len */
  1593. +#define ENET_DMA_CH_STATE_RAM_DESC_BASE_BUFPTR 0x0c /* buffer descrpitor current processing */
  1594. +#define ENET_DMA_CH_STATE_RAM_SIZE 0x10
  1595. +
  1596. +#define DMA_CTL_STATUS_APPEND_CRC 0x00000100
  1597. +#define DMA_CTL_STATUS_APPEND_BRCM_TAG 0x00000200
  1598. +#define DMA_CTL_STATUS_PRIO 0x00000C00 /* Prio for Tx */
  1599. +#define DMA_CTL_STATUS_WRAP 0x00001000 /* */
  1600. +#define DMA_CTL_STATUS_SOP 0x00002000 /* first buffer in packet */
  1601. +#define DMA_CTL_STATUS_EOP 0x00004000 /* last buffer in packet */
  1602. +#define DMA_CTL_STATUS_OWN 0x00008000 /* cleared by DMA, set by SW */
  1603. +#define DMA_CTL_LEN_DESC_BUFLENGTH 0x0fff0000
  1604. +#define DMA_CTL_LEN_DESC_BUFLENGTH_SHIFT 16
  1605. +#define DMA_CTL_LEN_DESC_MULTICAST 0x40000000
  1606. +#define DMA_CTL_LEN_DESC_USEFPM 0x80000000
  1607. +
  1608. +#endif