ath9k: improve ANI debugfs file
[openwrt.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 @@ -1061,6 +1061,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 @@ -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);
59  }
60 +static inline bool b43_bus_host_is_pci(struct b43_bus_dev *dev)
61 +{
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);
67 +#endif
68 +       return false;
69 +}
70  
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 @@ -4437,7 +4437,7 @@ static int b43_phy_versioning(struct b43
76                 u16 radio24[3];
77  
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);
82                 }
83  
84 @@ -4456,10 +4456,10 @@ static int b43_phy_versioning(struct b43
85                         else
86                                 tmp = 0x5205017F;
87                 } else {
88 -                       b43_write16(dev, B43_MMIO_RADIO_CONTROL,
89 +                       b43_wflush16(dev, B43_MMIO_RADIO_CONTROL,
90                                     B43_RADIOCTL_ID);
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,
94                                     B43_RADIOCTL_ID);
95                         tmp |= (u32)b43_read16(dev, B43_MMIO_RADIO_DATA_HIGH)
96                                 << 16;
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
100  {
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);
106 +               return;
107 +       }
108 +#endif
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
115  
116  static u16 b43_phy_ht_op_read(struct b43_wldev *dev, u16 reg)
117  {
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);
121  }
122  
123  static void b43_phy_ht_op_write(struct b43_wldev *dev, u16 reg, u16 value)
124  {
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);
128  }
129  
130  static void b43_phy_ht_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
131                                  u16 set)
132  {
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);
137  }
138 @@ -1096,14 +1096,14 @@ static u16 b43_phy_ht_op_radio_read(stru
139         /* HT-PHY needs 0x200 for read access */
140         reg |= 0x200;
141  
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);
145  }
146  
147  static void b43_phy_ht_op_radio_write(struct b43_wldev *dev, u16 reg,
148                                       u16 value)
149  {
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);
153  }
154  
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
158  
159  static u16 b43_phy_lcn_op_read(struct b43_wldev *dev, u16 reg)
160  {
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);
164  }
165  
166  static void b43_phy_lcn_op_write(struct b43_wldev *dev, u16 reg, u16 value)
167  {
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);
171  }
172  
173  static void b43_phy_lcn_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
174                                    u16 set)
175  {
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);
180  }
181 @@ -868,14 +868,14 @@ static u16 b43_phy_lcn_op_radio_read(str
182         /* LCN-PHY needs 0x200 for read access */
183         reg |= 0x200;
184  
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);
188  }
189  
190  static void b43_phy_lcn_op_radio_write(struct b43_wldev *dev, u16 reg,
191                                        u16 value)
192  {
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);
196  }
197  
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)
202  {
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);
207  }
208  
209  static void b43_nphy_op_write(struct b43_wldev *dev, u16 reg, u16 value)
210  {
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);
215  }
216  
217 @@ -5433,7 +5433,7 @@ static void b43_nphy_op_maskset(struct b
218                                  u16 set)
219  {
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);
224  }
225  
226 @@ -5444,7 +5444,7 @@ static u16 b43_nphy_op_radio_read(struct
227         /* N-PHY needs 0x100 for read access */
228         reg |= 0x100;
229  
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);
233  }
234  
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);
238  
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);
242  }
243