mac80211: b43: backport b43 patches from wireless testing
[openwrt/staging/mkresin.git] / package / kernel / mac80211 / patches / 830-b43-workaround-pcie-bcm4716.patch
1 From 4f214b1ead0af7439921637645cb63f378516175 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 21 Jan 2012 18:48:38 +0100
4 Subject: [PATCH 33/34] b43: add workaround for b43 on pcie bus of bcm4716.
5
6 bcm4716 (which includes 4717 & 4718), plus 4706 on PCIe can reorder
7 transactions. As a fix, a read after write is performed on certain
8 places in the code. Older chips and the newer 5357 family don't require
9 this fix.
10 This code is based on the brcmsmac driver.
11
12 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
13 ---
14 drivers/net/wireless/b43/b43.h | 26 ++++++++++++++++++++++++++
15 drivers/net/wireless/b43/bus.h | 10 ++++++++++
16 drivers/net/wireless/b43/phy_common.c | 6 ++++++
17 drivers/net/wireless/b43/phy_n.c | 10 +++++-----
18 4 files changed, 47 insertions(+), 5 deletions(-)
19
20 --- a/drivers/net/wireless/b43/b43.h
21 +++ b/drivers/net/wireless/b43/b43.h
22 @@ -1054,6 +1054,31 @@ static inline bool b43_using_pio_transfe
23 return dev->__using_pio_transfers;
24 }
25
26 +/*
27 + * bcm4716 (which includes 4717 & 4718), plus 4706 on PCIe can reorder
28 + * transactions. As a fix, a read after write is performed on certain places
29 + * in the code. Older chips and the newer 5357 family don't require this fix.
30 + */
31 +#ifdef CONFIG_BCM47XX_BCMA
32 +#include <asm/mach-bcm47xx/bcm47xx.h>
33 +static inline void b43_wflush16(struct b43_wldev *dev, u16 offset, u16 value)
34 +{
35 + if (b43_bus_host_is_pci(dev->dev) &&
36 + bcm47xx_bus_type == BCM47XX_BUS_TYPE_BCMA &&
37 + bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4716) {
38 + b43_write16(dev, offset, value);
39 + b43_read16(dev, offset);
40 + } else {
41 + b43_write16(dev, offset, value);
42 + }
43 +}
44 +#else
45 +static inline void b43_wflush16(struct b43_wldev *dev, u16 offset, u16 value)
46 +{
47 + b43_write16(dev, offset, value);
48 +}
49 +#endif
50 +
51 /* Message printing */
52 __printf(2, 3) void b43info(struct b43_wl *wl, const char *fmt, ...);
53 __printf(2, 3) void b43err(struct b43_wl *wl, const char *fmt, ...);
54 --- a/drivers/net/wireless/b43/bus.h
55 +++ b/drivers/net/wireless/b43/bus.h
56 @@ -70,6 +70,18 @@ static inline bool b43_bus_host_is_sdio(
57 return false;
58 #endif
59 }
60 +static inline bool b43_bus_host_is_pci(struct b43_bus_dev *dev)
61 +{
62 +#ifdef CPTCFG_B43_BCMA
63 + if (dev->bus_type == B43_BUS_BCMA)
64 + return (dev->bdev->bus->hosttype == BCMA_HOSTTYPE_PCI);
65 +#endif
66 +#ifdef CPTCFG_B43_SSB
67 + if (dev->bus_type == B43_BUS_SSB)
68 + return (dev->sdev->bus->bustype == SSB_BUSTYPE_PCI);
69 +#endif
70 + return false;
71 +}
72
73 struct b43_bus_dev *b43_bus_dev_bcma_init(struct bcma_device *core);
74 struct b43_bus_dev *b43_bus_dev_ssb_init(struct ssb_device *sdev);
75 --- a/drivers/net/wireless/b43/main.c
76 +++ b/drivers/net/wireless/b43/main.c
77 @@ -4422,7 +4422,7 @@ static int b43_phy_versioning(struct b43
78 u16 radio24[3];
79
80 for (tmp = 0; tmp < 3; tmp++) {
81 - b43_write16(dev, B43_MMIO_RADIO24_CONTROL, tmp);
82 + b43_wflush16(dev, B43_MMIO_RADIO24_CONTROL, tmp);
83 radio24[tmp] = b43_read16(dev, B43_MMIO_RADIO24_DATA);
84 }
85
86 @@ -4441,10 +4441,10 @@ static int b43_phy_versioning(struct b43
87 else
88 tmp = 0x5205017F;
89 } else {
90 - b43_write16(dev, B43_MMIO_RADIO_CONTROL,
91 + b43_wflush16(dev, B43_MMIO_RADIO_CONTROL,
92 B43_RADIOCTL_ID);
93 tmp = b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
94 - b43_write16(dev, B43_MMIO_RADIO_CONTROL,
95 + b43_wflush16(dev, B43_MMIO_RADIO_CONTROL,
96 B43_RADIOCTL_ID);
97 tmp |= (u32)b43_read16(dev, B43_MMIO_RADIO_DATA_HIGH)
98 << 16;
99 --- a/drivers/net/wireless/b43/phy_common.c
100 +++ b/drivers/net/wireless/b43/phy_common.c
101 @@ -275,6 +275,12 @@ void b43_phy_write(struct b43_wldev *dev
102 {
103 assert_mac_suspended(dev);
104 dev->phy.ops->phy_write(dev, reg, value);
105 +#ifdef CONFIG_BCM47XX
106 + if (b43_bus_host_is_pci(dev->dev) && reg == 0x72) {
107 + b43_read16(dev, B43_MMIO_PHY_VER);
108 + return;
109 + }
110 +#endif
111 if (++dev->phy.writes_counter == B43_MAX_WRITES_IN_ROW) {
112 b43_read16(dev, B43_MMIO_PHY_VER);
113 dev->phy.writes_counter = 0;
114 --- a/drivers/net/wireless/b43/phy_ht.c
115 +++ b/drivers/net/wireless/b43/phy_ht.c
116 @@ -1073,20 +1073,20 @@ static unsigned int b43_phy_ht_op_get_de
117
118 static u16 b43_phy_ht_op_read(struct b43_wldev *dev, u16 reg)
119 {
120 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
121 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
122 return b43_read16(dev, B43_MMIO_PHY_DATA);
123 }
124
125 static void b43_phy_ht_op_write(struct b43_wldev *dev, u16 reg, u16 value)
126 {
127 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
128 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
129 b43_write16(dev, B43_MMIO_PHY_DATA, value);
130 }
131
132 static void b43_phy_ht_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
133 u16 set)
134 {
135 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
136 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
137 b43_write16(dev, B43_MMIO_PHY_DATA,
138 (b43_read16(dev, B43_MMIO_PHY_DATA) & mask) | set);
139 }
140 @@ -1096,14 +1096,14 @@ static u16 b43_phy_ht_op_radio_read(stru
141 /* HT-PHY needs 0x200 for read access */
142 reg |= 0x200;
143
144 - b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
145 + b43_wflush16(dev, B43_MMIO_RADIO24_CONTROL, reg);
146 return b43_read16(dev, B43_MMIO_RADIO24_DATA);
147 }
148
149 static void b43_phy_ht_op_radio_write(struct b43_wldev *dev, u16 reg,
150 u16 value)
151 {
152 - b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
153 + b43_wflush16(dev, B43_MMIO_RADIO24_CONTROL, reg);
154 b43_write16(dev, B43_MMIO_RADIO24_DATA, value);
155 }
156
157 --- a/drivers/net/wireless/b43/phy_lcn.c
158 +++ b/drivers/net/wireless/b43/phy_lcn.c
159 @@ -845,20 +845,20 @@ static void b43_phy_lcn_op_adjust_txpowe
160
161 static u16 b43_phy_lcn_op_read(struct b43_wldev *dev, u16 reg)
162 {
163 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
164 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
165 return b43_read16(dev, B43_MMIO_PHY_DATA);
166 }
167
168 static void b43_phy_lcn_op_write(struct b43_wldev *dev, u16 reg, u16 value)
169 {
170 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
171 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
172 b43_write16(dev, B43_MMIO_PHY_DATA, value);
173 }
174
175 static void b43_phy_lcn_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
176 u16 set)
177 {
178 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
179 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
180 b43_write16(dev, B43_MMIO_PHY_DATA,
181 (b43_read16(dev, B43_MMIO_PHY_DATA) & mask) | set);
182 }
183 @@ -868,14 +868,14 @@ static u16 b43_phy_lcn_op_radio_read(str
184 /* LCN-PHY needs 0x200 for read access */
185 reg |= 0x200;
186
187 - b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
188 + b43_wflush16(dev, B43_MMIO_RADIO24_CONTROL, reg);
189 return b43_read16(dev, B43_MMIO_RADIO24_DATA);
190 }
191
192 static void b43_phy_lcn_op_radio_write(struct b43_wldev *dev, u16 reg,
193 u16 value)
194 {
195 - b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
196 + b43_wflush16(dev, B43_MMIO_RADIO24_CONTROL, reg);
197 b43_write16(dev, B43_MMIO_RADIO24_DATA, value);
198 }
199
200 --- a/drivers/net/wireless/b43/phy_n.c
201 +++ b/drivers/net/wireless/b43/phy_n.c
202 @@ -6251,14 +6251,14 @@ static inline void check_phyreg(struct b
203 static u16 b43_nphy_op_read(struct b43_wldev *dev, u16 reg)
204 {
205 check_phyreg(dev, reg);
206 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
207 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
208 return b43_read16(dev, B43_MMIO_PHY_DATA);
209 }
210
211 static void b43_nphy_op_write(struct b43_wldev *dev, u16 reg, u16 value)
212 {
213 check_phyreg(dev, reg);
214 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
215 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
216 b43_write16(dev, B43_MMIO_PHY_DATA, value);
217 }
218
219 @@ -6266,7 +6266,7 @@ static void b43_nphy_op_maskset(struct b
220 u16 set)
221 {
222 check_phyreg(dev, reg);
223 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
224 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
225 b43_maskset16(dev, B43_MMIO_PHY_DATA, mask, set);
226 }
227
228 @@ -6280,7 +6280,7 @@ static u16 b43_nphy_op_radio_read(struct
229 else
230 reg |= 0x100;
231
232 - b43_write16(dev, B43_MMIO_RADIO_CONTROL, reg);
233 + b43_wflush16(dev, B43_MMIO_RADIO_CONTROL, reg);
234 return b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
235 }
236
237 @@ -6289,7 +6289,7 @@ static void b43_nphy_op_radio_write(stru
238 /* Register 1 is a 32-bit register. */
239 B43_WARN_ON(dev->phy.rev < 7 && reg == 1);
240
241 - b43_write16(dev, B43_MMIO_RADIO_CONTROL, reg);
242 + b43_wflush16(dev, B43_MMIO_RADIO_CONTROL, reg);
243 b43_write16(dev, B43_MMIO_RADIO_DATA_LOW, value);
244 }
245