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