aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorChristian Lamparter <chunkeey@web.de>2009-06-23 11:37:40 -0400
committerJohn W. Linville <linville@tuxdriver.com>2009-07-10 15:01:58 -0400
commit76074e1670b197385ce93242e3ba3ccc7a6be377 (patch)
tree94475ea485b0e72166d8392d8bec9c9e06daba51 /drivers
parent289b098c2754d04f768b34ac5a9d08b59c38b725 (diff)
p54: Move firmware code
Copy the firmware i/o code from p54common.c into a new file fwio.c Signed-off-by: Christian Lamparter <chunkeey@web.de> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/p54/fwio.c697
1 files changed, 697 insertions, 0 deletions
diff --git a/drivers/net/wireless/p54/fwio.c b/drivers/net/wireless/p54/fwio.c
new file mode 100644
index 000000000000..178efbce4611
--- /dev/null
+++ b/drivers/net/wireless/p54/fwio.c
@@ -0,0 +1,697 @@
1/*
2 * Firmware I/O code for mac80211 Prism54 drivers
3 *
4 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
5 * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 *
8 * Based on:
9 * - the islsm (softmac prism54) driver, which is:
10 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
11 * - stlc45xx driver
12 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/init.h>
20#include <linux/firmware.h>
21#include <linux/etherdevice.h>
22
23#include <net/mac80211.h>
24
25#include "p54.h"
26#include "eeprom.h"
27#include "lmac.h"
28
29int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
30{
31 struct p54_common *priv = dev->priv;
32 struct exp_if *exp_if;
33 struct bootrec *bootrec;
34 u32 *data = (u32 *)fw->data;
35 u32 *end_data = (u32 *)fw->data + (fw->size >> 2);
36 u8 *fw_version = NULL;
37 size_t len;
38 int i;
39 int maxlen;
40
41 if (priv->rx_start)
42 return 0;
43
44 while (data < end_data && *data)
45 data++;
46
47 while (data < end_data && !*data)
48 data++;
49
50 bootrec = (struct bootrec *) data;
51
52 while (bootrec->data <= end_data && (bootrec->data +
53 (len = le32_to_cpu(bootrec->len))) <= end_data) {
54 u32 code = le32_to_cpu(bootrec->code);
55 switch (code) {
56 case BR_CODE_COMPONENT_ID:
57 priv->fw_interface = be32_to_cpup((__be32 *)
58 bootrec->data);
59 switch (priv->fw_interface) {
60 case FW_LM86:
61 case FW_LM20:
62 case FW_LM87: {
63 char *iftype = (char *)bootrec->data;
64 printk(KERN_INFO "%s: p54 detected a LM%c%c "
65 "firmware\n",
66 wiphy_name(priv->hw->wiphy),
67 iftype[2], iftype[3]);
68 break;
69 }
70 case FW_FMAC:
71 default:
72 printk(KERN_ERR "%s: unsupported firmware\n",
73 wiphy_name(priv->hw->wiphy));
74 return -ENODEV;
75 }
76 break;
77 case BR_CODE_COMPONENT_VERSION:
78 /* 24 bytes should be enough for all firmwares */
79 if (strnlen((unsigned char *) bootrec->data, 24) < 24)
80 fw_version = (unsigned char *) bootrec->data;
81 break;
82 case BR_CODE_DESCR: {
83 struct bootrec_desc *desc =
84 (struct bootrec_desc *)bootrec->data;
85 priv->rx_start = le32_to_cpu(desc->rx_start);
86 /* FIXME add sanity checking */
87 priv->rx_end = le32_to_cpu(desc->rx_end) - 0x3500;
88 priv->headroom = desc->headroom;
89 priv->tailroom = desc->tailroom;
90 priv->privacy_caps = desc->privacy_caps;
91 priv->rx_keycache_size = desc->rx_keycache_size;
92 if (le32_to_cpu(bootrec->len) == 11)
93 priv->rx_mtu = le16_to_cpu(desc->rx_mtu);
94 else
95 priv->rx_mtu = (size_t)
96 0x620 - priv->tx_hdr_len;
97 maxlen = priv->tx_hdr_len + /* USB devices */
98 sizeof(struct p54_rx_data) +
99 4 + /* rx alignment */
100 IEEE80211_MAX_FRAG_THRESHOLD;
101 if (priv->rx_mtu > maxlen && PAGE_SIZE == 4096) {
102 printk(KERN_INFO "p54: rx_mtu reduced from %d "
103 "to %d\n", priv->rx_mtu, maxlen);
104 priv->rx_mtu = maxlen;
105 }
106 break;
107 }
108 case BR_CODE_EXPOSED_IF:
109 exp_if = (struct exp_if *) bootrec->data;
110 for (i = 0; i < (len * sizeof(*exp_if) / 4); i++)
111 if (exp_if[i].if_id == cpu_to_le16(IF_ID_LMAC))
112 priv->fw_var = le16_to_cpu(exp_if[i].variant);
113 break;
114 case BR_CODE_DEPENDENT_IF:
115 break;
116 case BR_CODE_END_OF_BRA:
117 case LEGACY_BR_CODE_END_OF_BRA:
118 end_data = NULL;
119 break;
120 default:
121 break;
122 }
123 bootrec = (struct bootrec *)&bootrec->data[len];
124 }
125
126 if (fw_version)
127 printk(KERN_INFO "%s: FW rev %s - Softmac protocol %x.%x\n",
128 wiphy_name(priv->hw->wiphy), fw_version,
129 priv->fw_var >> 8, priv->fw_var & 0xff);
130
131 if (priv->fw_var < 0x500)
132 printk(KERN_INFO "%s: you are using an obsolete firmware. "
133 "visit http://wireless.kernel.org/en/users/Drivers/p54 "
134 "and grab one for \"kernel >= 2.6.28\"!\n",
135 wiphy_name(priv->hw->wiphy));
136
137 if (priv->fw_var >= 0x300) {
138 /* Firmware supports QoS, use it! */
139
140 if (priv->fw_var >= 0x500) {
141 priv->tx_stats[P54_QUEUE_AC_VO].limit = 16;
142 priv->tx_stats[P54_QUEUE_AC_VI].limit = 16;
143 priv->tx_stats[P54_QUEUE_AC_BE].limit = 16;
144 priv->tx_stats[P54_QUEUE_AC_BK].limit = 16;
145 } else {
146 priv->tx_stats[P54_QUEUE_AC_VO].limit = 3;
147 priv->tx_stats[P54_QUEUE_AC_VI].limit = 4;
148 priv->tx_stats[P54_QUEUE_AC_BE].limit = 3;
149 priv->tx_stats[P54_QUEUE_AC_BK].limit = 2;
150 }
151 priv->hw->queues = P54_QUEUE_AC_NUM;
152 }
153
154 printk(KERN_INFO "%s: cryptographic accelerator "
155 "WEP:%s, TKIP:%s, CCMP:%s\n", wiphy_name(priv->hw->wiphy),
156 (priv->privacy_caps & BR_DESC_PRIV_CAP_WEP) ? "YES" :
157 "no", (priv->privacy_caps & (BR_DESC_PRIV_CAP_TKIP |
158 BR_DESC_PRIV_CAP_MICHAEL)) ? "YES" : "no",
159 (priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP) ?
160 "YES" : "no");
161
162 if (priv->rx_keycache_size) {
163 /*
164 * NOTE:
165 *
166 * The firmware provides at most 255 (0 - 254) slots
167 * for keys which are then used to offload decryption.
168 * As a result the 255 entry (aka 0xff) can be used
169 * safely by the driver to mark keys that didn't fit
170 * into the full cache. This trick saves us from
171 * keeping a extra list for uploaded keys.
172 */
173
174 priv->used_rxkeys = kzalloc(BITS_TO_LONGS(
175 priv->rx_keycache_size), GFP_KERNEL);
176
177 if (!priv->used_rxkeys)
178 return -ENOMEM;
179 }
180
181 return 0;
182}
183EXPORT_SYMBOL_GPL(p54_parse_firmware);
184
185static struct sk_buff *p54_alloc_skb(struct p54_common *priv, u16 hdr_flags,
186 u16 payload_len, u16 type, gfp_t memflags)
187{
188 struct p54_hdr *hdr;
189 struct sk_buff *skb;
190 size_t frame_len = sizeof(*hdr) + payload_len;
191
192 if (frame_len > P54_MAX_CTRL_FRAME_LEN)
193 return NULL;
194
195 if (unlikely(skb_queue_len(&priv->tx_pending) > 64))
196 return NULL;
197
198 skb = __dev_alloc_skb(priv->tx_hdr_len + frame_len, memflags);
199 if (!skb)
200 return NULL;
201 skb_reserve(skb, priv->tx_hdr_len);
202
203 hdr = (struct p54_hdr *) skb_put(skb, sizeof(*hdr));
204 hdr->flags = cpu_to_le16(hdr_flags);
205 hdr->len = cpu_to_le16(payload_len);
206 hdr->type = cpu_to_le16(type);
207 hdr->tries = hdr->rts_tries = 0;
208 return skb;
209}
210
211int p54_download_eeprom(struct p54_common *priv, void *buf,
212 u16 offset, u16 len)
213{
214 struct p54_eeprom_lm86 *eeprom_hdr;
215 struct sk_buff *skb;
216 size_t eeprom_hdr_size;
217 int ret = 0;
218
219 if (priv->fw_var >= 0x509)
220 eeprom_hdr_size = sizeof(*eeprom_hdr);
221 else
222 eeprom_hdr_size = 0x4;
223
224 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL, eeprom_hdr_size +
225 len, P54_CONTROL_TYPE_EEPROM_READBACK,
226 GFP_KERNEL);
227 if (unlikely(!skb))
228 return -ENOMEM;
229
230 mutex_lock(&priv->eeprom_mutex);
231 priv->eeprom = buf;
232 eeprom_hdr = (struct p54_eeprom_lm86 *) skb_put(skb,
233 eeprom_hdr_size + len);
234
235 if (priv->fw_var < 0x509) {
236 eeprom_hdr->v1.offset = cpu_to_le16(offset);
237 eeprom_hdr->v1.len = cpu_to_le16(len);
238 } else {
239 eeprom_hdr->v2.offset = cpu_to_le32(offset);
240 eeprom_hdr->v2.len = cpu_to_le16(len);
241 eeprom_hdr->v2.magic2 = 0xf;
242 memcpy(eeprom_hdr->v2.magic, (const char *)"LOCK", 4);
243 }
244
245 p54_tx(priv, skb);
246
247 if (!wait_for_completion_interruptible_timeout(
248 &priv->eeprom_comp, HZ)) {
249 printk(KERN_ERR "%s: device does not respond!\n",
250 wiphy_name(priv->hw->wiphy));
251 ret = -EBUSY;
252 }
253 priv->eeprom = NULL;
254 mutex_unlock(&priv->eeprom_mutex);
255 return ret;
256}
257
258int p54_update_beacon_tim(struct p54_common *priv, u16 aid, bool set)
259{
260 struct sk_buff *skb;
261 struct p54_tim *tim;
262
263 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*tim),
264 P54_CONTROL_TYPE_TIM, GFP_ATOMIC);
265 if (unlikely(!skb))
266 return -ENOMEM;
267
268 tim = (struct p54_tim *) skb_put(skb, sizeof(*tim));
269 tim->count = 1;
270 tim->entry[0] = cpu_to_le16(set ? (aid | 0x8000) : aid);
271 p54_tx(priv, skb);
272 return 0;
273}
274
275int p54_sta_unlock(struct p54_common *priv, u8 *addr)
276{
277 struct sk_buff *skb;
278 struct p54_sta_unlock *sta;
279
280 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*sta),
281 P54_CONTROL_TYPE_PSM_STA_UNLOCK, GFP_ATOMIC);
282 if (unlikely(!skb))
283 return -ENOMEM;
284
285 sta = (struct p54_sta_unlock *)skb_put(skb, sizeof(*sta));
286 memcpy(sta->addr, addr, ETH_ALEN);
287 p54_tx(priv, skb);
288 return 0;
289}
290
291int p54_tx_cancel(struct p54_common *priv, __le32 req_id)
292{
293 struct sk_buff *skb;
294 struct p54_txcancel *cancel;
295
296 if (unlikely(req_id < priv->rx_start || req_id > priv->rx_end))
297 return -EINVAL;
298
299 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*cancel),
300 P54_CONTROL_TYPE_TXCANCEL, GFP_ATOMIC);
301 if (unlikely(!skb))
302 return -ENOMEM;
303
304 cancel = (struct p54_txcancel *)skb_put(skb, sizeof(*cancel));
305 cancel->req_id = req_id;
306 p54_tx(priv, skb);
307 return 0;
308}
309
310int p54_setup_mac(struct p54_common *priv)
311{
312 struct sk_buff *skb;
313 struct p54_setup_mac *setup;
314 u16 mode;
315
316 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup),
317 P54_CONTROL_TYPE_SETUP, GFP_ATOMIC);
318 if (!skb)
319 return -ENOMEM;
320
321 setup = (struct p54_setup_mac *) skb_put(skb, sizeof(*setup));
322 if (priv->hw->conf.radio_enabled) {
323 switch (priv->mode) {
324 case NL80211_IFTYPE_STATION:
325 mode = P54_FILTER_TYPE_STATION;
326 break;
327 case NL80211_IFTYPE_AP:
328 mode = P54_FILTER_TYPE_AP;
329 break;
330 case NL80211_IFTYPE_ADHOC:
331 case NL80211_IFTYPE_MESH_POINT:
332 mode = P54_FILTER_TYPE_IBSS;
333 break;
334 case NL80211_IFTYPE_MONITOR:
335 mode = P54_FILTER_TYPE_PROMISCUOUS;
336 break;
337 default:
338 mode = P54_FILTER_TYPE_HIBERNATE;
339 break;
340 }
341
342 /*
343 * "TRANSPARENT and PROMISCUOUS are mutually exclusive"
344 * STSW45X0C LMAC API - page 12
345 */
346 if (((priv->filter_flags & FIF_PROMISC_IN_BSS) ||
347 (priv->filter_flags & FIF_OTHER_BSS)) &&
348 (mode != P54_FILTER_TYPE_PROMISCUOUS))
349 mode |= P54_FILTER_TYPE_TRANSPARENT;
350 } else
351 mode = P54_FILTER_TYPE_HIBERNATE;
352
353 setup->mac_mode = cpu_to_le16(mode);
354 memcpy(setup->mac_addr, priv->mac_addr, ETH_ALEN);
355 memcpy(setup->bssid, priv->bssid, ETH_ALEN);
356 setup->rx_antenna = 2 & priv->rx_diversity_mask; /* automatic */
357 setup->rx_align = 0;
358 if (priv->fw_var < 0x500) {
359 setup->v1.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
360 memset(setup->v1.rts_rates, 0, 8);
361 setup->v1.rx_addr = cpu_to_le32(priv->rx_end);
362 setup->v1.max_rx = cpu_to_le16(priv->rx_mtu);
363 setup->v1.rxhw = cpu_to_le16(priv->rxhw);
364 setup->v1.wakeup_timer = cpu_to_le16(priv->wakeup_timer);
365 setup->v1.unalloc0 = cpu_to_le16(0);
366 } else {
367 setup->v2.rx_addr = cpu_to_le32(priv->rx_end);
368 setup->v2.max_rx = cpu_to_le16(priv->rx_mtu);
369 setup->v2.rxhw = cpu_to_le16(priv->rxhw);
370 setup->v2.timer = cpu_to_le16(priv->wakeup_timer);
371 setup->v2.truncate = cpu_to_le16(48896);
372 setup->v2.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
373 setup->v2.sbss_offset = 0;
374 setup->v2.mcast_window = 0;
375 setup->v2.rx_rssi_threshold = 0;
376 setup->v2.rx_ed_threshold = 0;
377 setup->v2.ref_clock = cpu_to_le32(644245094);
378 setup->v2.lpf_bandwidth = cpu_to_le16(65535);
379 setup->v2.osc_start_delay = cpu_to_le16(65535);
380 }
381 p54_tx(priv, skb);
382 return 0;
383}
384
385int p54_scan(struct p54_common *priv, u16 mode, u16 dwell)
386{
387 struct sk_buff *skb;
388 struct p54_hdr *hdr;
389 struct p54_scan_head *head;
390 struct p54_iq_autocal_entry *iq_autocal;
391 union p54_scan_body_union *body;
392 struct p54_scan_tail_rate *rate;
393 struct pda_rssi_cal_entry *rssi;
394 unsigned int i;
395 void *entry;
396 int band = priv->hw->conf.channel->band;
397 __le16 freq = cpu_to_le16(priv->hw->conf.channel->center_freq);
398
399 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*head) +
400 2 + sizeof(*iq_autocal) + sizeof(*body) +
401 sizeof(*rate) + 2 * sizeof(*rssi),
402 P54_CONTROL_TYPE_SCAN, GFP_ATOMIC);
403 if (!skb)
404 return -ENOMEM;
405
406 head = (struct p54_scan_head *) skb_put(skb, sizeof(*head));
407 memset(head->scan_params, 0, sizeof(head->scan_params));
408 head->mode = cpu_to_le16(mode);
409 head->dwell = cpu_to_le16(dwell);
410 head->freq = freq;
411
412 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
413 __le16 *pa_power_points = (__le16 *) skb_put(skb, 2);
414 *pa_power_points = cpu_to_le16(0x0c);
415 }
416
417 iq_autocal = (void *) skb_put(skb, sizeof(*iq_autocal));
418 for (i = 0; i < priv->iq_autocal_len; i++) {
419 if (priv->iq_autocal[i].freq != freq)
420 continue;
421
422 memcpy(iq_autocal, &priv->iq_autocal[i].params,
423 sizeof(struct p54_iq_autocal_entry));
424 break;
425 }
426 if (i == priv->iq_autocal_len)
427 goto err;
428
429 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW)
430 body = (void *) skb_put(skb, sizeof(body->longbow));
431 else
432 body = (void *) skb_put(skb, sizeof(body->normal));
433
434 for (i = 0; i < priv->output_limit->entries; i++) {
435 __le16 *entry_freq = (void *) (priv->output_limit->data +
436 priv->output_limit->entry_size * i);
437
438 if (*entry_freq != freq)
439 continue;
440
441 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
442 memcpy(&body->longbow.power_limits,
443 (void *) entry_freq + sizeof(__le16),
444 priv->output_limit->entry_size);
445 } else {
446 struct pda_channel_output_limit *limits =
447 (void *) entry_freq;
448
449 body->normal.val_barker = 0x38;
450 body->normal.val_bpsk = body->normal.dup_bpsk =
451 limits->val_bpsk;
452 body->normal.val_qpsk = body->normal.dup_qpsk =
453 limits->val_qpsk;
454 body->normal.val_16qam = body->normal.dup_16qam =
455 limits->val_16qam;
456 body->normal.val_64qam = body->normal.dup_64qam =
457 limits->val_64qam;
458 }
459 break;
460 }
461 if (i == priv->output_limit->entries)
462 goto err;
463
464 entry = (void *)(priv->curve_data->data + priv->curve_data->offset);
465 for (i = 0; i < priv->curve_data->entries; i++) {
466 if (*((__le16 *)entry) != freq) {
467 entry += priv->curve_data->entry_size;
468 continue;
469 }
470
471 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
472 memcpy(&body->longbow.curve_data,
473 (void *) entry + sizeof(__le16),
474 priv->curve_data->entry_size);
475 } else {
476 struct p54_scan_body *chan = &body->normal;
477 struct pda_pa_curve_data *curve_data =
478 (void *) priv->curve_data->data;
479
480 entry += sizeof(__le16);
481 chan->pa_points_per_curve = 8;
482 memset(chan->curve_data, 0, sizeof(*chan->curve_data));
483 memcpy(chan->curve_data, entry,
484 sizeof(struct p54_pa_curve_data_sample) *
485 min((u8)8, curve_data->points_per_channel));
486 }
487 break;
488 }
489 if (i == priv->curve_data->entries)
490 goto err;
491
492 if ((priv->fw_var >= 0x500) && (priv->fw_var < 0x509)) {
493 rate = (void *) skb_put(skb, sizeof(*rate));
494 rate->basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
495 for (i = 0; i < sizeof(rate->rts_rates); i++)
496 rate->rts_rates[i] = i;
497 }
498
499 rssi = (struct pda_rssi_cal_entry *) skb_put(skb, sizeof(*rssi));
500 rssi->mul = cpu_to_le16(priv->rssical_db[band].mul);
501 rssi->add = cpu_to_le16(priv->rssical_db[band].add);
502 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
503 /* Longbow frontend needs ever more */
504 rssi = (void *) skb_put(skb, sizeof(*rssi));
505 rssi->mul = cpu_to_le16(priv->rssical_db[band].longbow_unkn);
506 rssi->add = cpu_to_le16(priv->rssical_db[band].longbow_unk2);
507 }
508
509 if (priv->fw_var >= 0x509) {
510 rate = (void *) skb_put(skb, sizeof(*rate));
511 rate->basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
512 for (i = 0; i < sizeof(rate->rts_rates); i++)
513 rate->rts_rates[i] = i;
514 }
515
516 hdr = (struct p54_hdr *) skb->data;
517 hdr->len = cpu_to_le16(skb->len - sizeof(*hdr));
518
519 p54_tx(priv, skb);
520 return 0;
521
522err:
523 printk(KERN_ERR "%s: frequency change to channel %d failed.\n",
524 wiphy_name(priv->hw->wiphy), ieee80211_frequency_to_channel(
525 priv->hw->conf.channel->center_freq));
526
527 dev_kfree_skb_any(skb);
528 return -EINVAL;
529}
530
531int p54_set_leds(struct p54_common *priv)
532{
533 struct sk_buff *skb;
534 struct p54_led *led;
535
536 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*led),
537 P54_CONTROL_TYPE_LED, GFP_ATOMIC);
538 if (unlikely(!skb))
539 return -ENOMEM;
540
541 led = (struct p54_led *) skb_put(skb, sizeof(*led));
542 led->flags = cpu_to_le16(0x0003);
543 led->mask[0] = led->mask[1] = cpu_to_le16(priv->softled_state);
544 led->delay[0] = cpu_to_le16(1);
545 led->delay[1] = cpu_to_le16(0);
546 p54_tx(priv, skb);
547 return 0;
548}
549
550int p54_set_edcf(struct p54_common *priv)
551{
552 struct sk_buff *skb;
553 struct p54_edcf *edcf;
554
555 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*edcf),
556 P54_CONTROL_TYPE_DCFINIT, GFP_ATOMIC);
557 if (unlikely(!skb))
558 return -ENOMEM;
559
560 edcf = (struct p54_edcf *)skb_put(skb, sizeof(*edcf));
561 if (priv->use_short_slot) {
562 edcf->slottime = 9;
563 edcf->sifs = 0x10;
564 edcf->eofpad = 0x00;
565 } else {
566 edcf->slottime = 20;
567 edcf->sifs = 0x0a;
568 edcf->eofpad = 0x06;
569 }
570 /* (see prism54/isl_oid.h for further details) */
571 edcf->frameburst = cpu_to_le16(0);
572 edcf->round_trip_delay = cpu_to_le16(0);
573 edcf->flags = 0;
574 memset(edcf->mapping, 0, sizeof(edcf->mapping));
575 memcpy(edcf->queue, priv->qos_params, sizeof(edcf->queue));
576 p54_tx(priv, skb);
577 return 0;
578}
579
580int p54_set_ps(struct p54_common *priv)
581{
582 struct sk_buff *skb;
583 struct p54_psm *psm;
584 unsigned int i;
585 u16 mode;
586
587 if (priv->hw->conf.flags & IEEE80211_CONF_PS)
588 mode = P54_PSM | P54_PSM_BEACON_TIMEOUT | P54_PSM_DTIM |
589 P54_PSM_CHECKSUM | P54_PSM_MCBC;
590 else
591 mode = P54_PSM_CAM;
592
593 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*psm),
594 P54_CONTROL_TYPE_PSM, GFP_ATOMIC);
595 if (!skb)
596 return -ENOMEM;
597
598 psm = (struct p54_psm *)skb_put(skb, sizeof(*psm));
599 psm->mode = cpu_to_le16(mode);
600 psm->aid = cpu_to_le16(priv->aid);
601 for (i = 0; i < ARRAY_SIZE(psm->intervals); i++) {
602 psm->intervals[i].interval =
603 cpu_to_le16(priv->hw->conf.listen_interval);
604 psm->intervals[i].periods = cpu_to_le16(1);
605 }
606
607 psm->beacon_rssi_skip_max = 200;
608 psm->rssi_delta_threshold = 0;
609 psm->nr = 10;
610 psm->exclude[0] = 0;
611
612 p54_tx(priv, skb);
613 return 0;
614}
615
616int p54_init_xbow_synth(struct p54_common *priv)
617{
618 struct sk_buff *skb;
619 struct p54_xbow_synth *xbow;
620
621 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*xbow),
622 P54_CONTROL_TYPE_XBOW_SYNTH_CFG, GFP_KERNEL);
623 if (unlikely(!skb))
624 return -ENOMEM;
625
626 xbow = (struct p54_xbow_synth *)skb_put(skb, sizeof(*xbow));
627 xbow->magic1 = cpu_to_le16(0x1);
628 xbow->magic2 = cpu_to_le16(0x2);
629 xbow->freq = cpu_to_le16(5390);
630 memset(xbow->padding, 0, sizeof(xbow->padding));
631 p54_tx(priv, skb);
632 return 0;
633}
634
635int p54_upload_key(struct p54_common *priv, u8 algo, int slot, u8 idx, u8 len,
636 u8 *addr, u8* key)
637{
638 struct sk_buff *skb;
639 struct p54_keycache *rxkey;
640
641 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*rxkey),
642 P54_CONTROL_TYPE_RX_KEYCACHE, GFP_KERNEL);
643 if (unlikely(!skb))
644 return -ENOMEM;
645
646 rxkey = (struct p54_keycache *)skb_put(skb, sizeof(*rxkey));
647 rxkey->entry = slot;
648 rxkey->key_id = idx;
649 rxkey->key_type = algo;
650 if (addr)
651 memcpy(rxkey->mac, addr, ETH_ALEN);
652 else
653 memset(rxkey->mac, ~0, ETH_ALEN);
654
655 switch (algo) {
656 case P54_CRYPTO_WEP:
657 case P54_CRYPTO_AESCCMP:
658 rxkey->key_len = min_t(u8, 16, len);
659 memcpy(rxkey->key, key, rxkey->key_len);
660 break;
661
662 case P54_CRYPTO_TKIPMICHAEL:
663 rxkey->key_len = 24;
664 memcpy(rxkey->key, key, 16);
665 memcpy(&(rxkey->key[16]), &(key
666 [NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY]), 8);
667 break;
668
669 case P54_CRYPTO_NONE:
670 rxkey->key_len = 0;
671 memset(rxkey->key, 0, sizeof(rxkey->key));
672 break;
673
674 default:
675 printk(KERN_ERR "%s: invalid cryptographic algorithm: %d\n",
676 wiphy_name(priv->hw->wiphy), algo);
677 dev_kfree_skb(skb);
678 return -EINVAL;
679 }
680
681 p54_tx(priv, skb);
682 return 0;
683}
684
685int p54_fetch_statistics(struct p54_common *priv)
686{
687 struct sk_buff *skb;
688
689 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL,
690 sizeof(struct p54_statistics),
691 P54_CONTROL_TYPE_STAT_READBACK, GFP_KERNEL);
692 if (!skb)
693 return -ENOMEM;
694
695 p54_tx(priv, skb);
696 return 0;
697}