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.
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
10 This code is based on the brcmsmac driver.
12 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
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(-)
20 --- a/drivers/net/wireless/b43/b43.h
21 +++ b/drivers/net/wireless/b43/b43.h
22 @@ -1058,6 +1058,31 @@ static inline bool b43_using_pio_transfe
23 return dev->__using_pio_transfers;
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.
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)
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);
41 + b43_write16(dev, offset, value);
45 +static inline void b43_wflush16(struct b43_wldev *dev, u16 offset, u16 value)
47 + b43_write16(dev, offset, value);
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 @@ -60,6 +60,16 @@ static inline bool b43_bus_host_is_sdio(
57 return (dev->bus_type == B43_BUS_SSB &&
58 dev->sdev->bus->bustype == SSB_BUSTYPE_SDIO);
60 +static inline bool b43_bus_host_is_pci(struct b43_bus_dev *dev)
62 + if (dev->bus_type == B43_BUS_SSB)
63 + return (dev->sdev->bus->bustype == SSB_BUSTYPE_PCI);
64 +#ifdef CPTCFG_B43_BCMA
65 + if (dev->bus_type == B43_BUS_BCMA)
66 + return (dev->bdev->bus->hosttype == BCMA_HOSTTYPE_PCI);
71 struct b43_bus_dev *b43_bus_dev_bcma_init(struct bcma_device *core);
72 struct b43_bus_dev *b43_bus_dev_ssb_init(struct ssb_device *sdev);
73 --- a/drivers/net/wireless/b43/main.c
74 +++ b/drivers/net/wireless/b43/main.c
75 @@ -4419,7 +4419,7 @@ static int b43_phy_versioning(struct b43
78 for (tmp = 0; tmp < 3; tmp++) {
79 - b43_write16(dev, B43_MMIO_RADIO24_CONTROL, tmp);
80 + b43_wflush16(dev, B43_MMIO_RADIO24_CONTROL, tmp);
81 radio24[tmp] = b43_read16(dev, B43_MMIO_RADIO24_DATA);
84 @@ -4438,10 +4438,10 @@ static int b43_phy_versioning(struct b43
88 - b43_write16(dev, B43_MMIO_RADIO_CONTROL,
89 + b43_wflush16(dev, B43_MMIO_RADIO_CONTROL,
91 tmp = b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
92 - b43_write16(dev, B43_MMIO_RADIO_CONTROL,
93 + b43_wflush16(dev, B43_MMIO_RADIO_CONTROL,
95 tmp |= (u32)b43_read16(dev, B43_MMIO_RADIO_DATA_HIGH)
97 --- a/drivers/net/wireless/b43/phy_common.c
98 +++ b/drivers/net/wireless/b43/phy_common.c
99 @@ -266,6 +266,12 @@ void b43_phy_write(struct b43_wldev *dev
101 assert_mac_suspended(dev);
102 dev->phy.ops->phy_write(dev, reg, value);
103 +#ifdef CONFIG_BCM47XX
104 + if (b43_bus_host_is_pci(dev->dev) && reg == 0x72) {
105 + b43_read16(dev, B43_MMIO_PHY_VER);
109 if (++dev->phy.writes_counter == B43_MAX_WRITES_IN_ROW) {
110 b43_read16(dev, B43_MMIO_PHY_VER);
111 dev->phy.writes_counter = 0;
112 --- a/drivers/net/wireless/b43/phy_ht.c
113 +++ b/drivers/net/wireless/b43/phy_ht.c
114 @@ -1073,20 +1073,20 @@ static unsigned int b43_phy_ht_op_get_de
116 static u16 b43_phy_ht_op_read(struct b43_wldev *dev, u16 reg)
118 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
119 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
120 return b43_read16(dev, B43_MMIO_PHY_DATA);
123 static void b43_phy_ht_op_write(struct b43_wldev *dev, u16 reg, u16 value)
125 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
126 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
127 b43_write16(dev, B43_MMIO_PHY_DATA, value);
130 static void b43_phy_ht_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
133 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
134 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
135 b43_write16(dev, B43_MMIO_PHY_DATA,
136 (b43_read16(dev, B43_MMIO_PHY_DATA) & mask) | set);
138 @@ -1096,14 +1096,14 @@ static u16 b43_phy_ht_op_radio_read(stru
139 /* HT-PHY needs 0x200 for read access */
142 - b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
143 + b43_wflush16(dev, B43_MMIO_RADIO24_CONTROL, reg);
144 return b43_read16(dev, B43_MMIO_RADIO24_DATA);
147 static void b43_phy_ht_op_radio_write(struct b43_wldev *dev, u16 reg,
150 - b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
151 + b43_wflush16(dev, B43_MMIO_RADIO24_CONTROL, reg);
152 b43_write16(dev, B43_MMIO_RADIO24_DATA, value);
155 --- a/drivers/net/wireless/b43/phy_lcn.c
156 +++ b/drivers/net/wireless/b43/phy_lcn.c
157 @@ -845,20 +845,20 @@ static void b43_phy_lcn_op_adjust_txpowe
159 static u16 b43_phy_lcn_op_read(struct b43_wldev *dev, u16 reg)
161 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
162 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
163 return b43_read16(dev, B43_MMIO_PHY_DATA);
166 static void b43_phy_lcn_op_write(struct b43_wldev *dev, u16 reg, u16 value)
168 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
169 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
170 b43_write16(dev, B43_MMIO_PHY_DATA, value);
173 static void b43_phy_lcn_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
176 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
177 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
178 b43_write16(dev, B43_MMIO_PHY_DATA,
179 (b43_read16(dev, B43_MMIO_PHY_DATA) & mask) | set);
181 @@ -868,14 +868,14 @@ static u16 b43_phy_lcn_op_radio_read(str
182 /* LCN-PHY needs 0x200 for read access */
185 - b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
186 + b43_wflush16(dev, B43_MMIO_RADIO24_CONTROL, reg);
187 return b43_read16(dev, B43_MMIO_RADIO24_DATA);
190 static void b43_phy_lcn_op_radio_write(struct b43_wldev *dev, u16 reg,
193 - b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
194 + b43_wflush16(dev, B43_MMIO_RADIO24_CONTROL, reg);
195 b43_write16(dev, B43_MMIO_RADIO24_DATA, value);
198 --- a/drivers/net/wireless/b43/phy_n.c
199 +++ b/drivers/net/wireless/b43/phy_n.c
200 @@ -5418,14 +5418,14 @@ static inline void check_phyreg(struct b
201 static u16 b43_nphy_op_read(struct b43_wldev *dev, u16 reg)
203 check_phyreg(dev, reg);
204 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
205 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
206 return b43_read16(dev, B43_MMIO_PHY_DATA);
209 static void b43_nphy_op_write(struct b43_wldev *dev, u16 reg, u16 value)
211 check_phyreg(dev, reg);
212 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
213 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
214 b43_write16(dev, B43_MMIO_PHY_DATA, value);
217 @@ -5433,7 +5433,7 @@ static void b43_nphy_op_maskset(struct b
220 check_phyreg(dev, reg);
221 - b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
222 + b43_wflush16(dev, B43_MMIO_PHY_CONTROL, reg);
223 b43_maskset16(dev, B43_MMIO_PHY_DATA, mask, set);
226 @@ -5444,7 +5444,7 @@ static u16 b43_nphy_op_radio_read(struct
227 /* N-PHY needs 0x100 for read access */
230 - b43_write16(dev, B43_MMIO_RADIO_CONTROL, reg);
231 + b43_wflush16(dev, B43_MMIO_RADIO_CONTROL, reg);
232 return b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
235 @@ -5453,7 +5453,7 @@ static void b43_nphy_op_radio_write(stru
236 /* Register 1 is a 32-bit register. */
237 B43_WARN_ON(reg == 1);
239 - b43_write16(dev, B43_MMIO_RADIO_CONTROL, reg);
240 + b43_wflush16(dev, B43_MMIO_RADIO_CONTROL, reg);
241 b43_write16(dev, B43_MMIO_RADIO_DATA_LOW, value);