mac80211: rt2x00: add support for the RT3662/RT3883 SoCs
[openwrt/svn-archive/archive.git] / package / kernel / mac80211 / patches / 600-0003-rt2x00-rt2800-serialize-shared-memory-access.patch
1 From 250a1b520cd7fdc0df4fc3fedea9066913f49ecf Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Sat, 17 Aug 2013 19:31:42 +0200
4 Subject: [PATCH] rt2x00: rt2800: serialize shared memory access
5
6 The shared memory of the rt2800 devices is accessible
7 through the register offset range between 0x4000 and
8 0x8000. The size of this range is 16KB only and on
9 devices which have more than 16KB of shared memory either
10 the low or the high part of the memory is accessible at a
11 time.
12
13 Serialize all accesses to the shared memory by a mutex,
14 in order to avoid concurrent use of that.
15
16 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
17 ---
18 Changes since v1: ---
19 ---
20 drivers/net/wireless/rt2x00/rt2800lib.c | 55 +++++++++++++++++++++++++++++-
21 drivers/net/wireless/rt2x00/rt2800lib.h | 32 +++++++++++++++++
22 drivers/net/wireless/rt2x00/rt2800mmio.c | 26 ++++++++++++++
23 drivers/net/wireless/rt2x00/rt2800mmio.h | 4 +++
24 drivers/net/wireless/rt2x00/rt2800pci.c | 14 ++++++++
25 drivers/net/wireless/rt2x00/rt2800soc.c | 3 ++
26 drivers/net/wireless/rt2x00/rt2800usb.c | 31 +++++++++++++++++
27 7 files changed, 164 insertions(+), 1 deletion(-)
28
29 --- a/drivers/net/wireless/rt2x00/rt2800lib.c
30 +++ b/drivers/net/wireless/rt2x00/rt2800lib.c
31 @@ -451,11 +451,13 @@ void rt2800_mcu_request(struct rt2x00_de
32 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
33 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
34 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
35 + rt2800_shared_mem_lock(rt2x00dev);
36 rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
37
38 reg = 0;
39 rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
40 rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
41 + rt2800_shared_mem_unlock(rt2x00dev);
42 }
43
44 mutex_unlock(&rt2x00dev->csr_mutex);
45 @@ -674,7 +676,9 @@ int rt2800_load_firmware(struct rt2x00_d
46 * Wait for device to stabilize.
47 */
48 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
49 + rt2800_shared_mem_lock(rt2x00dev);
50 rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
51 + rt2800_shared_mem_unlock(rt2x00dev);
52 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
53 break;
54 msleep(1);
55 @@ -694,10 +698,16 @@ int rt2800_load_firmware(struct rt2x00_d
56 /*
57 * Initialize firmware.
58 */
59 + rt2800_shared_mem_lock(rt2x00dev);
60 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
61 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
62 + rt2800_shared_mem_unlock(rt2x00dev);
63 +
64 if (rt2x00_is_usb(rt2x00dev)) {
65 + rt2800_shared_mem_lock(rt2x00dev);
66 rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0);
67 + rt2800_shared_mem_unlock(rt2x00dev);
68 +
69 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
70 }
71 msleep(1);
72 @@ -1001,8 +1011,10 @@ void rt2800_write_beacon(struct queue_en
73
74 beacon_base = rt2800_hw_beacon_base(rt2x00dev, entry->entry_idx);
75
76 + rt2800_shared_mem_lock(rt2x00dev);
77 rt2800_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data,
78 entry->skb->len + padding_len);
79 + rt2800_shared_mem_unlock(rt2x00dev);
80
81 /*
82 * Enable beaconing again.
83 @@ -1027,6 +1039,8 @@ static inline void rt2800_clear_beacon_r
84
85 beacon_base = rt2800_hw_beacon_base(rt2x00dev, index);
86
87 + rt2800_shared_mem_lock(rt2x00dev);
88 +
89 /*
90 * For the Beacon base registers we only need to clear
91 * the whole TXWI which (when set to 0) will invalidate
92 @@ -1034,6 +1048,8 @@ static inline void rt2800_clear_beacon_r
93 */
94 for (i = 0; i < txwi_desc_size; i += sizeof(__le32))
95 rt2800_register_write(rt2x00dev, beacon_base + i, 0);
96 +
97 + rt2800_shared_mem_unlock(rt2x00dev);
98 }
99
100 void rt2800_clear_beacon(struct queue_entry *entry)
101 @@ -1217,7 +1233,9 @@ static void rt2800_delete_wcid_attr(stru
102 {
103 u32 offset;
104 offset = MAC_WCID_ATTR_ENTRY(wcid);
105 + rt2800_shared_mem_lock(rt2x00dev);
106 rt2800_register_write(rt2x00dev, offset, 0);
107 + rt2800_shared_mem_unlock(rt2x00dev);
108 }
109
110 static void rt2800_config_wcid_attr_bssidx(struct rt2x00_dev *rt2x00dev,
111 @@ -1230,11 +1248,13 @@ static void rt2800_config_wcid_attr_bssi
112 * The BSS Idx numbers is split in a main value of 3 bits,
113 * and a extended field for adding one additional bit to the value.
114 */
115 + rt2800_shared_mem_lock(rt2x00dev);
116 rt2800_register_read(rt2x00dev, offset, &reg);
117 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX, (bssidx & 0x7));
118 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX_EXT,
119 (bssidx & 0x8) >> 3);
120 rt2800_register_write(rt2x00dev, offset, reg);
121 + rt2800_shared_mem_unlock(rt2x00dev);
122 }
123
124 static void rt2800_config_wcid_attr_cipher(struct rt2x00_dev *rt2x00dev,
125 @@ -1247,6 +1267,7 @@ static void rt2800_config_wcid_attr_ciph
126
127 offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
128
129 + rt2800_shared_mem_lock(rt2x00dev);
130 if (crypto->cmd == SET_KEY) {
131 rt2800_register_read(rt2x00dev, offset, &reg);
132 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB,
133 @@ -1271,6 +1292,7 @@ static void rt2800_config_wcid_attr_ciph
134 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, 0);
135 rt2800_register_write(rt2x00dev, offset, reg);
136 }
137 + rt2800_shared_mem_unlock(rt2x00dev);
138
139 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
140
141 @@ -1280,8 +1302,11 @@ static void rt2800_config_wcid_attr_ciph
142 (crypto->cipher == CIPHER_AES))
143 iveiv_entry.iv[3] |= 0x20;
144 iveiv_entry.iv[3] |= key->keyidx << 6;
145 +
146 + rt2800_shared_mem_lock(rt2x00dev);
147 rt2800_register_multiwrite(rt2x00dev, offset,
148 &iveiv_entry, sizeof(iveiv_entry));
149 + rt2800_shared_mem_unlock(rt2x00dev);
150 }
151
152 int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
153 @@ -1304,8 +1329,11 @@ int rt2800_config_shared_key(struct rt2x
154 sizeof(key_entry.rx_mic));
155
156 offset = SHARED_KEY_ENTRY(key->hw_key_idx);
157 +
158 + rt2800_shared_mem_lock(rt2x00dev);
159 rt2800_register_multiwrite(rt2x00dev, offset,
160 &key_entry, sizeof(key_entry));
161 + rt2800_shared_mem_unlock(rt2x00dev);
162 }
163
164 /*
165 @@ -1320,10 +1348,12 @@ int rt2800_config_shared_key(struct rt2x
166
167 offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
168
169 + rt2800_shared_mem_lock(rt2x00dev);
170 rt2800_register_read(rt2x00dev, offset, &reg);
171 rt2x00_set_field32(&reg, field,
172 (crypto->cmd == SET_KEY) * crypto->cipher);
173 rt2800_register_write(rt2x00dev, offset, reg);
174 + rt2800_shared_mem_unlock(rt2x00dev);
175
176 /*
177 * Update WCID information
178 @@ -1393,8 +1423,11 @@ int rt2800_config_pairwise_key(struct rt
179 sizeof(key_entry.rx_mic));
180
181 offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
182 +
183 + rt2800_shared_mem_lock(rt2x00dev);
184 rt2800_register_multiwrite(rt2x00dev, offset,
185 &key_entry, sizeof(key_entry));
186 + rt2800_shared_mem_unlock(rt2x00dev);
187 }
188
189 /*
190 @@ -4876,14 +4909,19 @@ static int rt2800_init_registers(struct
191 /*
192 * ASIC will keep garbage value after boot, clear encryption keys.
193 */
194 + rt2800_shared_mem_lock(rt2x00dev);
195 for (i = 0; i < 4; i++)
196 rt2800_register_write(rt2x00dev,
197 SHARED_KEY_MODE_ENTRY(i), 0);
198 + rt2800_shared_mem_unlock(rt2x00dev);
199
200 for (i = 0; i < 256; i++) {
201 rt2800_config_wcid(rt2x00dev, NULL, i);
202 rt2800_delete_wcid_attr(rt2x00dev, i);
203 +
204 + rt2800_shared_mem_lock(rt2x00dev);
205 rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
206 + rt2800_shared_mem_unlock(rt2x00dev);
207 }
208
209 /*
210 @@ -5009,8 +5047,10 @@ static int rt2800_wait_bbp_ready(struct
211 * BBP was enabled after firmware was loaded,
212 * but we need to reactivate it now.
213 */
214 + rt2800_shared_mem_lock(rt2x00dev);
215 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
216 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
217 + rt2800_shared_mem_unlock(rt2x00dev);
218 msleep(1);
219
220 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
221 @@ -6706,11 +6746,19 @@ int rt2800_enable_radio(struct rt2x00_de
222 /*
223 * Send signal during boot time to initialize firmware.
224 */
225 + rt2800_shared_mem_lock(rt2x00dev);
226 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
227 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
228 - if (rt2x00_is_usb(rt2x00dev))
229 + rt2800_shared_mem_unlock(rt2x00dev);
230 +
231 + if (rt2x00_is_usb(rt2x00dev)) {
232 + rt2800_shared_mem_lock(rt2x00dev);
233 rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0);
234 + rt2800_shared_mem_unlock(rt2x00dev);
235 + }
236 +
237 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
238 +
239 msleep(1);
240
241 /*
242 @@ -7716,6 +7764,8 @@ int rt2800_probe_hw(struct rt2x00_dev *r
243 int retval;
244 u32 reg;
245
246 + rt2800_shared_mem_init_lock(rt2x00dev);
247 +
248 retval = rt2800_probe_rt(rt2x00dev);
249 if (retval)
250 return retval;
251 @@ -7795,8 +7845,11 @@ void rt2800_get_tkip_seq(struct ieee8021
252 u32 offset;
253
254 offset = MAC_IVEIV_ENTRY(hw_key_idx);
255 +
256 + rt2800_shared_mem_lock(rt2x00dev);
257 rt2800_register_multiread(rt2x00dev, offset,
258 &iveiv_entry, sizeof(iveiv_entry));
259 + rt2800_shared_mem_unlock(rt2x00dev);
260
261 memcpy(iv16, &iveiv_entry.iv[0], sizeof(*iv16));
262 memcpy(iv32, &iveiv_entry.iv[4], sizeof(*iv32));
263 --- a/drivers/net/wireless/rt2x00/rt2800lib.h
264 +++ b/drivers/net/wireless/rt2x00/rt2800lib.h
265 @@ -35,6 +35,11 @@ struct rt2800_drv_data {
266 unsigned int tbtt_tick;
267
268 unsigned long rt2800_flags;
269 +
270 + union {
271 + spinlock_t spin;
272 + struct mutex mutex;
273 + } shmem_lock;
274 };
275
276 struct rt2800_ops {
277 @@ -65,6 +70,10 @@ struct rt2800_ops {
278 const u8 *data, const size_t len);
279 int (*drv_init_registers)(struct rt2x00_dev *rt2x00dev);
280 __le32 *(*drv_get_txwi)(struct queue_entry *entry);
281 +
282 + void (*shmem_init_lock)(struct rt2x00_dev *rt2x00dev);
283 + void (*shmem_lock)(struct rt2x00_dev *rt2x00dev);
284 + void (*shmem_unlock)(struct rt2x00_dev *rt2x00dev);
285 };
286
287 static inline bool rt2800_has_high_shared_mem(struct rt2x00_dev *rt2x00dev)
288 @@ -74,6 +83,29 @@ static inline bool rt2800_has_high_share
289 return test_bit(RT2800_HAS_HIGH_SHARED_MEM, &drv_data->rt2800_flags);
290 }
291
292 +static inline void rt2800_shared_mem_init_lock(struct rt2x00_dev *rt2x00dev)
293 +{
294 + const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
295 +
296 + rt2800ops->shmem_init_lock(rt2x00dev);
297 +}
298 +
299 +static inline void rt2800_shared_mem_lock(struct rt2x00_dev *rt2x00dev)
300 +{
301 + const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
302 +
303 + if (rt2800_has_high_shared_mem(rt2x00dev))
304 + rt2800ops->shmem_lock(rt2x00dev);
305 +}
306 +
307 +static inline void rt2800_shared_mem_unlock(struct rt2x00_dev *rt2x00dev)
308 +{
309 + const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
310 +
311 + if (rt2800_has_high_shared_mem(rt2x00dev))
312 + rt2800ops->shmem_unlock(rt2x00dev);
313 +}
314 +
315 static inline void rt2800_register_read(struct rt2x00_dev *rt2x00dev,
316 const unsigned int offset,
317 u32 *value)
318 --- a/drivers/net/wireless/rt2x00/rt2800mmio.c
319 +++ b/drivers/net/wireless/rt2x00/rt2800mmio.c
320 @@ -820,8 +820,10 @@ int rt2800mmio_init_registers(struct rt2
321 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DRX_IDX0, 1);
322 rt2x00mmio_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
323
324 + rt2800_shared_mem_lock(rt2x00dev);
325 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f);
326 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00);
327 + rt2800_shared_mem_unlock(rt2x00dev);
328
329 if (rt2x00_is_pcie(rt2x00dev) &&
330 (rt2x00_rt(rt2x00dev, RT3090) ||
331 @@ -865,6 +867,30 @@ int rt2800mmio_enable_radio(struct rt2x0
332 }
333 EXPORT_SYMBOL_GPL(rt2800mmio_enable_radio);
334
335 +void rt2800mmio_shmem_init_lock(struct rt2x00_dev *rt2x00dev)
336 +{
337 + struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
338 +
339 + spin_lock_init(&drv_data->shmem_lock.spin);
340 +}
341 +EXPORT_SYMBOL_GPL(rt2800mmio_shmem_init_lock);
342 +
343 +void rt2800mmio_shmem_lock(struct rt2x00_dev *rt2x00dev)
344 +{
345 + struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
346 +
347 + spin_lock_bh(&drv_data->shmem_lock.spin);
348 +}
349 +EXPORT_SYMBOL_GPL(rt2800mmio_shmem_lock);
350 +
351 +void rt2800mmio_shmem_unlock(struct rt2x00_dev *rt2x00dev)
352 +{
353 + struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
354 +
355 + spin_unlock_bh(&drv_data->shmem_lock.spin);
356 +}
357 +EXPORT_SYMBOL_GPL(rt2800mmio_shmem_unlock);
358 +
359 MODULE_AUTHOR(DRV_PROJECT);
360 MODULE_VERSION(DRV_VERSION);
361 MODULE_DESCRIPTION("rt2800 MMIO library");
362 --- a/drivers/net/wireless/rt2x00/rt2800mmio.h
363 +++ b/drivers/net/wireless/rt2x00/rt2800mmio.h
364 @@ -160,4 +160,8 @@ int rt2800mmio_init_registers(struct rt2
365 /* Device state switch handlers. */
366 int rt2800mmio_enable_radio(struct rt2x00_dev *rt2x00dev);
367
368 +void rt2800mmio_shmem_init_lock(struct rt2x00_dev *rt2x00dev);
369 +void rt2800mmio_shmem_lock(struct rt2x00_dev *rt2x00dev);
370 +void rt2800mmio_shmem_unlock(struct rt2x00_dev *rt2x00dev);
371 +
372 #endif /* RT2800MMIO_H */
373 --- a/drivers/net/wireless/rt2x00/rt2800pci.c
374 +++ b/drivers/net/wireless/rt2x00/rt2800pci.c
375 @@ -69,7 +69,9 @@ static void rt2800pci_mcu_status(struct
376 return;
377
378 for (i = 0; i < 200; i++) {
379 + rt2800_shared_mem_lock(rt2x00dev);
380 rt2x00mmio_register_read(rt2x00dev, H2M_MAILBOX_CID, &reg);
381 + rt2800_shared_mem_unlock(rt2x00dev);
382
383 if ((rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD0) == token) ||
384 (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD1) == token) ||
385 @@ -83,8 +85,10 @@ static void rt2800pci_mcu_status(struct
386 if (i == 200)
387 rt2x00_err(rt2x00dev, "MCU request failed, no response from hardware\n");
388
389 + rt2800_shared_mem_lock(rt2x00dev);
390 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
391 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
392 + rt2800_shared_mem_unlock(rt2x00dev);
393 }
394
395 static void rt2800pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
396 @@ -184,6 +188,8 @@ static int rt2800pci_write_firmware(stru
397 */
398 reg = 0;
399 rt2x00_set_field32(&reg, PBF_SYS_CTRL_HOST_RAM_WRITE, 1);
400 +
401 + rt2800_shared_mem_lock(rt2x00dev);
402 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, reg);
403
404 /*
405 @@ -197,6 +203,7 @@ static int rt2800pci_write_firmware(stru
406
407 rt2x00mmio_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
408 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
409 + rt2800_shared_mem_unlock(rt2x00dev);
410
411 return 0;
412 }
413 @@ -213,8 +220,10 @@ static int rt2800pci_enable_radio(struct
414 return retval;
415
416 /* After resume MCU_BOOT_SIGNAL will trash these. */
417 + rt2800_shared_mem_lock(rt2x00dev);
418 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
419 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
420 + rt2800_shared_mem_unlock(rt2x00dev);
421
422 rt2800_mcu_request(rt2x00dev, MCU_SLEEP, TOKEN_RADIO_OFF, 0xff, 0x02);
423 rt2800pci_mcu_status(rt2x00dev, TOKEN_RADIO_OFF);
424 @@ -233,10 +242,12 @@ static int rt2800pci_set_state(struct rt
425 0, 0x02);
426 rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKEUP);
427 } else if (state == STATE_SLEEP) {
428 + rt2800_shared_mem_lock(rt2x00dev);
429 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS,
430 0xffffffff);
431 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID,
432 0xffffffff);
433 + rt2800_shared_mem_unlock(rt2x00dev);
434 rt2800_mcu_request(rt2x00dev, MCU_SLEEP, TOKEN_SLEEP,
435 0xff, 0x01);
436 }
437 @@ -337,6 +348,9 @@ static const struct rt2800_ops rt2800pci
438 .drv_write_firmware = rt2800pci_write_firmware,
439 .drv_init_registers = rt2800mmio_init_registers,
440 .drv_get_txwi = rt2800mmio_get_txwi,
441 + .shmem_init_lock = rt2800mmio_shmem_init_lock,
442 + .shmem_lock = rt2800mmio_shmem_lock,
443 + .shmem_unlock = rt2800mmio_shmem_unlock,
444 };
445
446 static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = {
447 --- a/drivers/net/wireless/rt2x00/rt2800soc.c
448 +++ b/drivers/net/wireless/rt2x00/rt2800soc.c
449 @@ -176,6 +176,9 @@ static const struct rt2800_ops rt2800soc
450 .drv_write_firmware = rt2800soc_write_firmware,
451 .drv_init_registers = rt2800mmio_init_registers,
452 .drv_get_txwi = rt2800mmio_get_txwi,
453 + .shmem_init_lock = rt2800mmio_shmem_init_lock,
454 + .shmem_lock = rt2800mmio_shmem_lock,
455 + .shmem_unlock = rt2800mmio_shmem_unlock,
456 };
457
458 static const struct rt2x00lib_ops rt2800soc_rt2x00_ops = {
459 --- a/drivers/net/wireless/rt2x00/rt2800usb.c
460 +++ b/drivers/net/wireless/rt2x00/rt2800usb.c
461 @@ -51,6 +51,27 @@ static bool rt2800usb_hwcrypt_disabled(s
462 return modparam_nohwcrypt;
463 }
464
465 +static void rt2800usb_shmem_init_lock(struct rt2x00_dev *rt2x00dev)
466 +{
467 + struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
468 +
469 + mutex_init(&drv_data->shmem_lock.mutex);
470 +}
471 +
472 +static void rt2800usb_shmem_lock(struct rt2x00_dev *rt2x00dev)
473 +{
474 + struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
475 +
476 + mutex_lock(&drv_data->shmem_lock.mutex);
477 +}
478 +
479 +static void rt2800usb_shmem_unlock(struct rt2x00_dev *rt2x00dev)
480 +{
481 + struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
482 +
483 + mutex_unlock(&drv_data->shmem_lock.mutex);
484 +}
485 +
486 /*
487 * Queue handlers.
488 */
489 @@ -260,8 +281,10 @@ static int rt2800usb_write_firmware(stru
490 rt2x00usb_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
491 data + offset, length);
492
493 + rt2800_shared_mem_lock(rt2x00dev);
494 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
495 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
496 + rt2800_shared_mem_unlock(rt2x00dev);
497
498 /*
499 * Send firmware request to device to load firmware,
500 @@ -276,7 +299,10 @@ static int rt2800usb_write_firmware(stru
501 }
502
503 msleep(10);
504 +
505 + rt2800_shared_mem_lock(rt2x00dev);
506 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
507 + rt2800_shared_mem_unlock(rt2x00dev);
508
509 return 0;
510 }
511 @@ -294,8 +320,10 @@ static int rt2800usb_init_registers(stru
512 if (rt2800_wait_csr_ready(rt2x00dev))
513 return -EBUSY;
514
515 + rt2800_shared_mem_lock(rt2x00dev);
516 rt2x00usb_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
517 rt2x00usb_register_write(rt2x00dev, PBF_SYS_CTRL, reg & ~0x00002000);
518 + rt2800_shared_mem_unlock(rt2x00dev);
519
520 reg = 0;
521 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
522 @@ -810,6 +838,9 @@ static const struct rt2800_ops rt2800usb
523 .drv_write_firmware = rt2800usb_write_firmware,
524 .drv_init_registers = rt2800usb_init_registers,
525 .drv_get_txwi = rt2800usb_get_txwi,
526 + .shmem_init_lock = rt2800usb_shmem_init_lock,
527 + .shmem_lock = rt2800usb_shmem_lock,
528 + .shmem_unlock = rt2800usb_shmem_unlock,
529 };
530
531 static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {