mac80211: add a number of pending fixes
[openwrt.git] / package / kernel / mac80211 / patches / 603-rt2x00-introduce-rt2x00eeprom.patch
1 --- a/.local-symbols
2 +++ b/.local-symbols
3 @@ -329,6 +329,7 @@ RT2X00_LIB_FIRMWARE=
4  RT2X00_LIB_CRYPTO=
5  RT2X00_LIB_LEDS=
6  RT2X00_LIB_DEBUGFS=
7 +RT2X00_LIB_EEPROM=
8  RT2X00_DEBUG=
9  WLAN_VENDOR_REALTEK=
10  RTL8180=
11 --- a/drivers/net/wireless/ralink/rt2x00/Kconfig
12 +++ b/drivers/net/wireless/ralink/rt2x00/Kconfig
13 @@ -69,6 +69,7 @@ config RT2800PCI
14         select RT2X00_LIB_MMIO
15         select RT2X00_LIB_PCI
16         select RT2X00_LIB_FIRMWARE
17 +       select RT2X00_LIB_EEPROM
18         select RT2X00_LIB_CRYPTO
19         depends on CRC_CCITT
20         depends on EEPROM_93CX6
21 @@ -215,6 +216,7 @@ config RT2800SOC
22         select RT2X00_LIB_MMIO
23         select RT2X00_LIB_CRYPTO
24         select RT2X00_LIB_FIRMWARE
25 +       select RT2X00_LIB_EEPROM
26         select RT2800_LIB
27         select RT2800_LIB_MMIO
28         ---help---
29 @@ -265,6 +267,9 @@ config RT2X00_LIB_FIRMWARE
30  config RT2X00_LIB_CRYPTO
31         bool
32  
33 +config RT2X00_LIB_EEPROM
34 +       boolean
35 +
36  config RT2X00_LIB_LEDS
37         bool
38         default y if (RT2X00_LIB=y && LEDS_CLASS=y) || (RT2X00_LIB=m && LEDS_CLASS!=n)
39 --- a/drivers/net/wireless/ralink/rt2x00/Makefile
40 +++ b/drivers/net/wireless/ralink/rt2x00/Makefile
41 @@ -7,6 +7,7 @@ rt2x00lib-$(CPTCFG_RT2X00_LIB_DEBUGFS)  +
42  rt2x00lib-$(CPTCFG_RT2X00_LIB_CRYPTO)  += rt2x00crypto.o
43  rt2x00lib-$(CPTCFG_RT2X00_LIB_FIRMWARE)        += rt2x00firmware.o
44  rt2x00lib-$(CPTCFG_RT2X00_LIB_LEDS)    += rt2x00leds.o
45 +rt2x00lib-$(CPTCFG_RT2X00_LIB_EEPROM)  += rt2x00eeprom.o
46  
47  obj-$(CPTCFG_RT2X00_LIB)               += rt2x00lib.o
48  obj-$(CPTCFG_RT2X00_LIB_MMIO)          += rt2x00mmio.o
49 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
50 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
51 @@ -46,6 +46,8 @@ struct rt2800_drv_data {
52         } shmem_lock;
53  };
54  
55 +#include "rt2800.h"
56 +
57  struct rt2800_ops {
58         void (*register_read)(struct rt2x00_dev *rt2x00dev,
59                               const unsigned int offset, u32 *value);
60 @@ -179,6 +181,15 @@ static inline int rt2800_read_eeprom(str
61  {
62         const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
63  
64 +       if (rt2x00dev->eeprom_file) {
65 +               memcpy(rt2x00dev->eeprom, rt2x00dev->eeprom_file->data,
66 +                      EEPROM_SIZE);
67 +               return 0;
68 +       }
69 +
70 +       if (!rt2800ops->read_eeprom)
71 +               return -EINVAL;
72 +
73         return rt2800ops->read_eeprom(rt2x00dev);
74  }
75  
76 --- a/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
77 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
78 @@ -102,19 +102,6 @@ static int rt2800soc_set_device_state(st
79         return retval;
80  }
81  
82 -static int rt2800soc_read_eeprom(struct rt2x00_dev *rt2x00dev)
83 -{
84 -       void __iomem *base_addr = ioremap(0x1F040000, EEPROM_SIZE);
85 -
86 -       if (!base_addr)
87 -               return -ENOMEM;
88 -
89 -       memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE);
90 -
91 -       iounmap(base_addr);
92 -       return 0;
93 -}
94 -
95  /* Firmware functions */
96  static char *rt2800soc_get_firmware_name(struct rt2x00_dev *rt2x00dev)
97  {
98 @@ -178,7 +165,6 @@ static const struct rt2800_ops rt2800soc
99         .register_multiread     = rt2x00mmio_register_multiread,
100         .register_multiwrite    = rt2x00mmio_register_multiwrite,
101         .regbusy_read           = rt2x00mmio_regbusy_read,
102 -       .read_eeprom            = rt2800soc_read_eeprom,
103         .hwcrypt_disabled       = rt2800soc_hwcrypt_disabled,
104         .drv_write_firmware     = rt2800soc_write_firmware,
105         .drv_init_registers     = rt2800mmio_init_registers,
106 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
107 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
108 @@ -697,6 +697,7 @@ enum rt2x00_capability_flags {
109         REQUIRE_HT_TX_DESC,
110         REQUIRE_PS_AUTOWAKE,
111         REQUIRE_DELAYED_RFKILL,
112 +       REQUIRE_EEPROM_FILE,
113  
114         /*
115          * Capabilities
116 @@ -968,6 +969,11 @@ struct rt2x00_dev {
117         const struct firmware *fw;
118  
119         /*
120 +        * EEPROM image.
121 +        */
122 +       const struct firmware *eeprom_file;
123 +
124 +       /*
125          * FIFO for storing tx status reports between isr and tasklet.
126          */
127         DECLARE_KFIFO_PTR(txstatus_fifo, u32);
128 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
129 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
130 @@ -1335,6 +1335,10 @@ int rt2x00lib_probe_dev(struct rt2x00_de
131         INIT_DELAYED_WORK(&rt2x00dev->autowakeup_work, rt2x00lib_autowakeup);
132         INIT_WORK(&rt2x00dev->sleep_work, rt2x00lib_sleep);
133  
134 +       retval = rt2x00lib_load_eeprom_file(rt2x00dev);
135 +       if (retval)
136 +               goto exit;
137 +
138         /*
139          * Let the driver probe the device to detect the capabilities.
140          */
141 @@ -1475,6 +1479,11 @@ void rt2x00lib_remove_dev(struct rt2x00_
142          * Free the driver data.
143          */
144         kfree(rt2x00dev->drv_data);
145 +
146 +       /*
147 +        * Free EEPROM image.
148 +        */
149 +       rt2x00lib_free_eeprom_file(rt2x00dev);
150  }
151  EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev);
152  
153 --- /dev/null
154 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
155 @@ -0,0 +1,111 @@
156 +/*
157 +       Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
158 +       Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
159 +       <http://rt2x00.serialmonkey.com>
160 +
161 +       This program is free software; you can redistribute it and/or modify
162 +       it under the terms of the GNU General Public License as published by
163 +       the Free Software Foundation; either version 2 of the License, or
164 +       (at your option) any later version.
165 +
166 +       This program is distributed in the hope that it will be useful,
167 +       but WITHOUT ANY WARRANTY; without even the implied warranty of
168 +       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
169 +       GNU General Public License for more details.
170 +
171 +       You should have received a copy of the GNU General Public License
172 +       along with this program; if not, write to the
173 +       Free Software Foundation, Inc.,
174 +       59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
175 + */
176 +
177 +/*
178 +       Module: rt2x00lib
179 +       Abstract: rt2x00 eeprom file loading routines.
180 + */
181 +
182 +#include <linux/kernel.h>
183 +#include <linux/module.h>
184 +
185 +#include "rt2x00.h"
186 +#include "rt2x00lib.h"
187 +
188 +static const char *
189 +rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
190 +{
191 +       struct rt2x00_platform_data *pdata = rt2x00dev->dev->platform_data;
192 +
193 +       if (pdata && pdata->eeprom_file_name)
194 +               return pdata->eeprom_file_name;
195 +
196 +       return NULL
197 +}
198 +
199 +static int rt2x00lib_request_eeprom_file(struct rt2x00_dev *rt2x00dev)
200 +{
201 +       const struct firmware *ee;
202 +       const char *ee_name;
203 +       int retval;
204 +
205 +       ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
206 +       if (!ee_name) {
207 +               rt2x00_err(rt2x00dev,
208 +                          "Invalid EEPROM filename.\n"
209 +                          "Please file bug report to %s.\n", DRV_PROJECT);
210 +               return -EINVAL;
211 +       }
212 +
213 +       rt2x00_info(rt2x00dev, "Loading EEPROM data from '%s'.\n", ee_name);
214 +
215 +       retval = request_firmware(&ee, ee_name, rt2x00dev->dev);
216 +       if (retval) {
217 +               rt2x00_err(rt2x00dev, "Failed to request EEPROM.\n");
218 +               return retval;
219 +       }
220 +
221 +       if (!ee || !ee->size || !ee->data) {
222 +               rt2x00_err(rt2x00dev, "Failed to read EEPROM file.\n");
223 +               retval = -ENOENT;
224 +               goto err_exit;
225 +       }
226 +
227 +       if (ee->size != rt2x00dev->ops->eeprom_size) {
228 +               rt2x00_err(rt2x00dev,
229 +                          "EEPROM file size is invalid, it should be %d bytes\n",
230 +                          rt2x00dev->ops->eeprom_size);
231 +               retval = -EINVAL;
232 +               goto err_release_ee;
233 +       }
234 +
235 +       rt2x00dev->eeprom_file = ee;
236 +       return 0;
237 +
238 +err_release_ee:
239 +       release_firmware(ee);
240 +err_exit:
241 +       return retval;
242 +}
243 +
244 +int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev)
245 +{
246 +       int retval;
247 +
248 +       if (!rt2x00lib_get_eeprom_file_name(rt2x00dev))
249 +               return 0;
250 +
251 +       set_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags);
252 +
253 +       if (!rt2x00dev->eeprom_file) {
254 +               retval = rt2x00lib_request_eeprom_file(rt2x00dev);
255 +               if (retval)
256 +                       return retval;
257 +       }
258 +
259 +       return 0;
260 +}
261 +
262 +void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev)
263 +{
264 +       release_firmware(rt2x00dev->eeprom_file);
265 +       rt2x00dev->eeprom_file = NULL;
266 +}
267 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00lib.h
268 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00lib.h
269 @@ -320,6 +320,22 @@ static inline void rt2x00lib_free_firmwa
270  #endif /* CPTCFG_RT2X00_LIB_FIRMWARE */
271  
272  /*
273 + * EEPROM file handlers.
274 + */
275 +#ifdef CPTCFG_RT2X00_LIB_EEPROM
276 +int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev);
277 +void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev);
278 +#else
279 +static inline int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev)
280 +{
281 +       return 0;
282 +}
283 +static inline void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev)
284 +{
285 +}
286 +#endif /* CPTCFG_RT2X00_LIB_EEPROM */
287 +
288 +/*
289   * Debugfs handlers.
290   */
291  #ifdef CPTCFG_RT2X00_LIB_DEBUGFS
292 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
293 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
294 @@ -92,6 +92,7 @@ int rt2x00soc_probe(struct platform_devi
295         rt2x00dev->hw = hw;
296         rt2x00dev->irq = platform_get_irq(pdev, 0);
297         rt2x00dev->name = pdev->dev.driver->name;
298 +       set_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags);
299  
300         rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
301