d733e58537b3ca6c1ff28430ca0f51e1d1cd1328
[openwrt/staging/rmilecki.git] / target / linux / ramips / patches-5.10 / 0114-staging-mt7621-pci-avoid-to-poweroff-the-phy-for-slo.patch
1 From d81fe3c13aa6f4ab1ec318212d2007175e6d05aa Mon Sep 17 00:00:00 2001
2 From: Sergio Paracuellos <sergio.paracuellos@gmail.com>
3 Date: Fri, 20 Mar 2020 16:38:37 +0100
4 Subject: [PATCH] staging: mt7621-pci: avoid to poweroff the phy for slot one
5
6 Phy for slot 0 and 1 is shared and handled properly in slot 0.
7 If there is only one port in use,(slot 0) we shall not call the
8 'phy_power_off' function with an invalid slot because kernel
9 will crash with an unaligned access fault like the following:
10
11 mt7621-pci 1e140000.pcie: Error applying setting, reverse things back
12 mt7621-pci-phy 1e149000.pcie-phy: PHY for 0xbe149000 (dual port = 1)
13 mt7621-pci-phy 1e14a000.pcie-phy: PHY for 0xbe14a000 (dual port = 0)
14 mt7621-pci-phy 1e149000.pcie-phy: Xtal is 40MHz
15 mt7621-pci-phy 1e14a000.pcie-phy: Xtal is 40MHz
16 mt7621-pci 1e140000.pcie: pcie1 no card, disable it (RST & CLK)
17 Unhandled kernel unaligned access[#1]:
18 CPU: 3 PID: 111 Comm: kworker/3:2 Not tainted 5.6.0-rc3-00347-g825c6f470c62-dirty #9
19 Workqueue: events deferred_probe_work_func
20 $ 0 : 00000000 00000001 5f60d043 8fe1ba80
21 $ 4 : 0000010d 01eb9000 00000000 00000000
22 $ 8 : 294b4c00 80940000 00000008 000000ce
23 $12 : 2e303030 00000000 00000000 65696370
24 $16 : ffffffed 0000010d 8e373cd0 8214c1e0
25 $20 : 00000000 82144c80 82144680 8214c250
26 $24 : 00000018 803ef8f4
27 $28 : 8e372000 8e373c60 8214c080 803940e8
28 Hi : 00000125
29 Lo : 122f2000
30 epc : 807b3328 mutex_lock+0x8/0x44
31 ra : 803940e8 phy_power_off+0x28/0xb0
32 Status: 1100fc03 KERNEL EXL IE
33 Cause : 00800010 (ExcCode 04)
34 BadVA : 0000010d
35 PrId : 0001992f (MIPS 1004Kc)
36 Modules linked in:
37 Process kworker/3:2 (pid: 111, threadinfo=(ptrval), task=(ptrval), tls=00000000)
38 Stack : 8e373cd0 803fe4f4 8e372000 8e373c90 8214c080 804fde1c 8e373c98 808d62f4
39 8e373c78 00000000 8214c254 804fe648 1e160000 804f27b8 00000001 808d62f4
40 00000000 00000001 8214c228 808d62f4 80930000 809a0000 8fd47e10 808d63d4
41 808d62d4 8fd47e10 808d0000 808d0000 8e373cd0 8e373cd0 809e2a74 809db510
42 809db510 00000006 00000001 00000000 00000000 00000000 01000000 1e1440ff
43 ...
44 Call Trace:
45 [<807b3328>] mutex_lock+0x8/0x44
46 [<803940e8>] phy_power_off+0x28/0xb0
47 [<804fe648>] mt7621_pci_probe+0xc20/0xd18
48 [<80402ab8>] platform_drv_probe+0x40/0x94
49 [<80400a74>] really_probe+0x104/0x364
50 [<803feb74>] bus_for_each_drv+0x84/0xdc
51 [<80400924>] __device_attach+0xdc/0x120
52 [<803ffb5c>] bus_probe_device+0xa0/0xbc
53 [<80400124>] deferred_probe_work_func+0x7c/0xbc
54 [<800420e8>] process_one_work+0x230/0x450
55 [<80042638>] worker_thread+0x330/0x5fc
56 [<80048eb0>] kthread+0x12c/0x134
57 [<80007438>] ret_from_kernel_thread+0x14/0x1c
58 Code: 24050002 27bdfff8 8f830000 <c0850000> 14a00005 00000000 00600825 e0810000 1020fffa
59
60 Fixes: bf516f413f4e ("staging: mt7621-pci: use only two phys from device tree")
61 Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
62 Link: https://lore.kernel.org/r/20200320153837.20415-1-sergio.paracuellos@gmail.com
63 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
64 ---
65 drivers/staging/mt7621-pci/pci-mt7621.c | 3 ++-
66 1 file changed, 2 insertions(+), 1 deletion(-)
67
68 --- a/drivers/staging/mt7621-pci/pci-mt7621.c
69 +++ b/drivers/staging/mt7621-pci/pci-mt7621.c
70 @@ -517,7 +517,8 @@ static void mt7621_pcie_init_ports(struc
71 if (!mt7621_pcie_port_is_linkup(port)) {
72 dev_err(dev, "pcie%d no card, disable it (RST & CLK)\n",
73 slot);
74 - phy_power_off(port->phy);
75 + if (slot != 1)
76 + phy_power_off(port->phy);
77 mt7621_control_assert(port);
78 mt7621_pcie_port_clk_disable(port);
79 port->enabled = false;