3b4199a70c4d07809adeca7a6a25e40b74453228
[openwrt/staging/chunkeey.git] / target / linux / brcm47xx / patches-4.19 / 031-v5.0-MIPS-BCM47XX-Setup-struct-device-for-the-SoC.patch
1 From 321c46b91550adc03054125fa7a1639390608e1a Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Thu, 3 Jan 2019 08:34:17 +0100
4 Subject: [PATCH] MIPS: BCM47XX: Setup struct device for the SoC
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 So far we never had any device registered for the SoC. This resulted in
10 some small issues that we kept ignoring like:
11 1) Not working GPIOLIB_IRQCHIP (gpiochip_irqchip_add_key() failing)
12 2) Lack of proper tree in the /sys/devices/
13 3) mips_dma_alloc_coherent() silently handling empty coherent_dma_mask
14
15 Kernel 4.19 came with a lot of DMA changes and caused a regression on
16 bcm47xx. Starting with the commit f8c55dc6e828 ("MIPS: use generic dma
17 noncoherent ops for simple noncoherent platforms") DMA coherent
18 allocations just fail. Example:
19 [ 1.114914] bgmac_bcma bcma0:2: Allocation of TX ring 0x200 failed
20 [ 1.121215] bgmac_bcma bcma0:2: Unable to alloc memory for DMA
21 [ 1.127626] bgmac_bcma: probe of bcma0:2 failed with error -12
22 [ 1.133838] bgmac_bcma: Broadcom 47xx GBit MAC driver loaded
23
24 The bgmac driver also triggers a WARNING:
25 [ 0.959486] ------------[ cut here ]------------
26 [ 0.964387] WARNING: CPU: 0 PID: 1 at ./include/linux/dma-mapping.h:516 bgmac_enet_probe+0x1b4/0x5c4
27 [ 0.973751] Modules linked in:
28 [ 0.976913] CPU: 0 PID: 1 Comm: swapper Not tainted 4.19.9 #0
29 [ 0.982750] Stack : 804a0000 804597c4 00000000 00000000 80458fd8 8381bc2c 838282d4 80481a47
30 [ 0.991367] 8042e3ec 00000001 804d38f0 00000204 83980000 00000065 8381bbe0 6f55b24f
31 [ 0.999975] 00000000 00000000 80520000 00002018 00000000 00000075 00000007 00000000
32 [ 1.008583] 00000000 80480000 000ee811 00000000 00000000 00000000 80432c00 80248db8
33 [ 1.017196] 00000009 00000204 83980000 803ad7b0 00000000 801feeec 00000000 804d0000
34 [ 1.025804] ...
35 [ 1.028325] Call Trace:
36 [ 1.030875] [<8000aef8>] show_stack+0x58/0x100
37 [ 1.035513] [<8001f8b4>] __warn+0xe4/0x118
38 [ 1.039708] [<8001f9a4>] warn_slowpath_null+0x48/0x64
39 [ 1.044935] [<80248db8>] bgmac_enet_probe+0x1b4/0x5c4
40 [ 1.050101] [<802498e0>] bgmac_probe+0x558/0x590
41 [ 1.054906] [<80252fd0>] bcma_device_probe+0x38/0x70
42 [ 1.060017] [<8020e1e8>] really_probe+0x170/0x2e8
43 [ 1.064891] [<8020e714>] __driver_attach+0xa4/0xec
44 [ 1.069784] [<8020c1e0>] bus_for_each_dev+0x58/0xb0
45 [ 1.074833] [<8020d590>] bus_add_driver+0xf8/0x218
46 [ 1.079731] [<8020ef24>] driver_register+0xcc/0x11c
47 [ 1.084804] [<804b54cc>] bgmac_init+0x1c/0x44
48 [ 1.089258] [<8000121c>] do_one_initcall+0x7c/0x1a0
49 [ 1.094343] [<804a1d34>] kernel_init_freeable+0x150/0x218
50 [ 1.099886] [<803a082c>] kernel_init+0x10/0x104
51 [ 1.104583] [<80005878>] ret_from_kernel_thread+0x14/0x1c
52 [ 1.110107] ---[ end trace f441c0d873d1fb5b ]---
53
54 This patch setups a "struct device" (and passes it to the bcma) which
55 allows fixing all the mentioned problems. It'll also require a tiny bcma
56 patch which will follow through the wireless tree & its maintainer.
57
58 Fixes: f8c55dc6e828 ("MIPS: use generic dma noncoherent ops for simple noncoherent platforms")
59 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
60 Signed-off-by: Paul Burton <paul.burton@mips.com>
61 Acked-by: Hauke Mehrtens <hauke@hauke-m.de>
62 Cc: Christoph Hellwig <hch@lst.de>
63 Cc: Linus Walleij <linus.walleij@linaro.org>
64 Cc: linux-wireless@vger.kernel.org
65 Cc: Ralf Baechle <ralf@linux-mips.org>
66 Cc: James Hogan <jhogan@kernel.org>
67 Cc: linux-mips@linux-mips.org
68 Cc: linux-kernel@vger.kernel.org
69 Cc: stable@vger.kernel.org # v4.19+
70 ---
71 arch/mips/bcm47xx/setup.c | 31 +++++++++++++++++++++++++++++++
72 include/linux/bcma/bcma_soc.h | 1 +
73 2 files changed, 32 insertions(+)
74
75 --- a/arch/mips/bcm47xx/setup.c
76 +++ b/arch/mips/bcm47xx/setup.c
77 @@ -173,6 +173,31 @@ void __init plat_mem_setup(void)
78 pm_power_off = bcm47xx_machine_halt;
79 }
80
81 +#ifdef CONFIG_BCM47XX_BCMA
82 +static struct device * __init bcm47xx_setup_device(void)
83 +{
84 + struct device *dev;
85 + int err;
86 +
87 + dev = kzalloc(sizeof(*dev), GFP_KERNEL);
88 + if (!dev)
89 + return NULL;
90 +
91 + err = dev_set_name(dev, "bcm47xx_soc");
92 + if (err) {
93 + pr_err("Failed to set SoC device name: %d\n", err);
94 + kfree(dev);
95 + return NULL;
96 + }
97 +
98 + err = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
99 + if (err)
100 + pr_err("Failed to set SoC DMA mask: %d\n", err);
101 +
102 + return dev;
103 +}
104 +#endif
105 +
106 /*
107 * This finishes bus initialization doing things that were not possible without
108 * kmalloc. Make sure to call it late enough (after mm_init).
109 @@ -183,6 +208,10 @@ void __init bcm47xx_bus_setup(void)
110 if (bcm47xx_bus_type == BCM47XX_BUS_TYPE_BCMA) {
111 int err;
112
113 + bcm47xx_bus.bcma.dev = bcm47xx_setup_device();
114 + if (!bcm47xx_bus.bcma.dev)
115 + panic("Failed to setup SoC device\n");
116 +
117 err = bcma_host_soc_init(&bcm47xx_bus.bcma);
118 if (err)
119 panic("Failed to initialize BCMA bus (err %d)", err);
120 @@ -235,6 +264,8 @@ static int __init bcm47xx_register_bus_c
121 #endif
122 #ifdef CONFIG_BCM47XX_BCMA
123 case BCM47XX_BUS_TYPE_BCMA:
124 + if (device_register(bcm47xx_bus.bcma.dev))
125 + pr_err("Failed to register SoC device\n");
126 bcma_bus_register(&bcm47xx_bus.bcma.bus);
127 break;
128 #endif