mediatek: update the ethernet compat string
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.4 / 0083-net-next-mediatek-fix-missing-free-of-scratch-memory.patch
1 From b48745c534ced06005d2ba57198b54a6a160b39d Mon Sep 17 00:00:00 2001
2 From: John Crispin <john@phrozen.org>
3 Date: Sat, 23 Apr 2016 09:18:28 +0200
4 Subject: [PATCH 083/102] net-next: mediatek: fix missing free of scratch
5 memory
6
7 Scratch memory gets allocated in mtk_init_fq_dma() but the corresponding
8 code to free it is missing inside mtk_dma_free() causing a memory leak.
9 With this patch applied, we can run ifconfig/up/down several thousand
10 times without any problems.
11
12 Signed-off-by: John Crispin <john@phrozen.org>
13 ---
14 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 18 +++++++++++++-----
15 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 ++
16 2 files changed, 15 insertions(+), 5 deletions(-)
17
18 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
20 @@ -484,14 +484,14 @@ static inline void mtk_rx_get_desc(struc
21 /* the qdma core needs scratch memory to be setup */
22 static int mtk_init_fq_dma(struct mtk_eth *eth)
23 {
24 - dma_addr_t phy_ring_head, phy_ring_tail;
25 + dma_addr_t phy_ring_tail;
26 int cnt = MTK_DMA_SIZE;
27 dma_addr_t dma_addr;
28 int i;
29
30 eth->scratch_ring = dma_alloc_coherent(eth->dev,
31 cnt * sizeof(struct mtk_tx_dma),
32 - &phy_ring_head,
33 + &eth->phy_scratch_ring,
34 GFP_ATOMIC | __GFP_ZERO);
35 if (unlikely(!eth->scratch_ring))
36 return -ENOMEM;
37 @@ -508,19 +508,19 @@ static int mtk_init_fq_dma(struct mtk_et
38 return -ENOMEM;
39
40 memset(eth->scratch_ring, 0x0, sizeof(struct mtk_tx_dma) * cnt);
41 - phy_ring_tail = phy_ring_head +
42 + phy_ring_tail = eth->phy_scratch_ring +
43 (sizeof(struct mtk_tx_dma) * (cnt - 1));
44
45 for (i = 0; i < cnt; i++) {
46 eth->scratch_ring[i].txd1 =
47 (dma_addr + (i * MTK_QDMA_PAGE_SIZE));
48 if (i < cnt - 1)
49 - eth->scratch_ring[i].txd2 = (phy_ring_head +
50 + eth->scratch_ring[i].txd2 = (eth->phy_scratch_ring +
51 ((i + 1) * sizeof(struct mtk_tx_dma)));
52 eth->scratch_ring[i].txd3 = TX_DMA_SDL(MTK_QDMA_PAGE_SIZE);
53 }
54
55 - mtk_w32(eth, phy_ring_head, MTK_QDMA_FQ_HEAD);
56 + mtk_w32(eth, eth->phy_scratch_ring, MTK_QDMA_FQ_HEAD);
57 mtk_w32(eth, phy_ring_tail, MTK_QDMA_FQ_TAIL);
58 mtk_w32(eth, (cnt << 16) | cnt, MTK_QDMA_FQ_CNT);
59 mtk_w32(eth, MTK_QDMA_PAGE_SIZE << 16, MTK_QDMA_FQ_BLEN);
60 @@ -1220,6 +1220,14 @@ static void mtk_dma_free(struct mtk_eth
61 for (i = 0; i < MTK_MAC_COUNT; i++)
62 if (eth->netdev[i])
63 netdev_reset_queue(eth->netdev[i]);
64 + if (eth->scratch_ring) {
65 + dma_free_coherent(eth->dev,
66 + MTK_DMA_SIZE * sizeof(struct mtk_tx_dma),
67 + eth->scratch_ring,
68 + eth->phy_scratch_ring);
69 + eth->scratch_ring = NULL;
70 + eth->phy_scratch_ring = 0;
71 + }
72 mtk_tx_clean(eth);
73 mtk_rx_clean(eth);
74 kfree(eth->scratch_head);
75 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
76 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
77 @@ -357,6 +357,7 @@ struct mtk_rx_ring {
78 * @rx_ring: Pointer to the memore holding info about the RX ring
79 * @rx_napi: The NAPI struct
80 * @scratch_ring: Newer SoCs need memory for a second HW managed TX ring
81 + * @phy_scratch_ring: physical address of scratch_ring
82 * @scratch_head: The scratch memory that scratch_ring points to.
83 * @clk_ethif: The ethif clock
84 * @clk_esw: The switch clock
85 @@ -384,6 +385,7 @@ struct mtk_eth {
86 struct mtk_rx_ring rx_ring;
87 struct napi_struct rx_napi;
88 struct mtk_tx_dma *scratch_ring;
89 + dma_addr_t phy_scratch_ring;
90 void *scratch_head;
91 struct clk *clk_ethif;
92 struct clk *clk_esw;