3 * Common code for mac80211 Prism54 drivers
5 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
6 * Copyright (c) 2007, Christian Lamparter <chunkeey@web.de>
8 * Based on the islsm (softmac prism54) driver, which is:
9 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/init.h>
17 #include <linux/firmware.h>
18 #include <linux/etherdevice.h>
20 #include <net/mac80211.h>
23 #include "p54common.h"
25 MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
26 MODULE_DESCRIPTION("Softmac Prism54 common code");
27 MODULE_LICENSE("GPL");
28 MODULE_ALIAS("prism54common");
30 static struct ieee80211_rate p54_rates
[] = {
31 { .bitrate
= 10, .hw_value
= 0, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
32 { .bitrate
= 20, .hw_value
= 1, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
33 { .bitrate
= 55, .hw_value
= 2, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
34 { .bitrate
= 110, .hw_value
= 3, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
35 { .bitrate
= 60, .hw_value
= 4, },
36 { .bitrate
= 90, .hw_value
= 5, },
37 { .bitrate
= 120, .hw_value
= 6, },
38 { .bitrate
= 180, .hw_value
= 7, },
39 { .bitrate
= 240, .hw_value
= 8, },
40 { .bitrate
= 360, .hw_value
= 9, },
41 { .bitrate
= 480, .hw_value
= 10, },
42 { .bitrate
= 540, .hw_value
= 11, },
45 static struct ieee80211_channel p54_channels
[] = {
46 { .center_freq
= 2412, .hw_value
= 1, },
47 { .center_freq
= 2417, .hw_value
= 2, },
48 { .center_freq
= 2422, .hw_value
= 3, },
49 { .center_freq
= 2427, .hw_value
= 4, },
50 { .center_freq
= 2432, .hw_value
= 5, },
51 { .center_freq
= 2437, .hw_value
= 6, },
52 { .center_freq
= 2442, .hw_value
= 7, },
53 { .center_freq
= 2447, .hw_value
= 8, },
54 { .center_freq
= 2452, .hw_value
= 9, },
55 { .center_freq
= 2457, .hw_value
= 10, },
56 { .center_freq
= 2462, .hw_value
= 11, },
57 { .center_freq
= 2467, .hw_value
= 12, },
58 { .center_freq
= 2472, .hw_value
= 13, },
59 { .center_freq
= 2484, .hw_value
= 14, },
62 static struct ieee80211_supported_band band_2GHz
= {
63 .channels
= p54_channels
,
64 .n_channels
= ARRAY_SIZE(p54_channels
),
65 .bitrates
= p54_rates
,
66 .n_bitrates
= ARRAY_SIZE(p54_rates
),
70 void p54_parse_firmware(struct ieee80211_hw
*dev
, const struct firmware
*fw
)
72 struct p54_common
*priv
= dev
->priv
;
73 struct bootrec_exp_if
*exp_if
;
74 struct bootrec
*bootrec
;
75 u32
*data
= (u32
*)fw
->data
;
76 u32
*end_data
= (u32
*)fw
->data
+ (fw
->size
>> 2);
77 u8
*fw_version
= NULL
;
84 while (data
< end_data
&& *data
)
87 while (data
< end_data
&& !*data
)
90 bootrec
= (struct bootrec
*) data
;
92 while (bootrec
->data
<= end_data
&&
93 (bootrec
->data
+ (len
= le32_to_cpu(bootrec
->len
))) <= end_data
) {
94 u32 code
= le32_to_cpu(bootrec
->code
);
96 case BR_CODE_COMPONENT_ID
:
97 switch (be32_to_cpu(*(__be32
*)bootrec
->data
)) {
99 printk(KERN_INFO
"p54: FreeMAC firmware\n");
102 printk(KERN_INFO
"p54: LM20 firmware\n");
105 printk(KERN_INFO
"p54: LM86 firmware\n");
108 printk(KERN_INFO
"p54: LM87 firmware - not supported yet!\n");
111 printk(KERN_INFO
"p54: unknown firmware\n");
115 case BR_CODE_COMPONENT_VERSION
:
116 /* 24 bytes should be enough for all firmwares */
117 if (strnlen((unsigned char*)bootrec
->data
, 24) < 24)
118 fw_version
= (unsigned char*)bootrec
->data
;
121 priv
->rx_start
= le32_to_cpu(((__le32
*)bootrec
->data
)[1]);
122 /* FIXME add sanity checking */
123 priv
->rx_end
= le32_to_cpu(((__le32
*)bootrec
->data
)[2]) - 0x3500;
125 case BR_CODE_EXPOSED_IF
:
126 exp_if
= (struct bootrec_exp_if
*) bootrec
->data
;
127 for (i
= 0; i
< (len
* sizeof(*exp_if
) / 4); i
++)
128 if (exp_if
[i
].if_id
== cpu_to_le16(0x1a))
129 priv
->fw_var
= le16_to_cpu(exp_if
[i
].variant
);
131 case BR_CODE_DEPENDENT_IF
:
133 case BR_CODE_END_OF_BRA
:
134 case LEGACY_BR_CODE_END_OF_BRA
:
140 bootrec
= (struct bootrec
*)&bootrec
->data
[len
];
144 printk(KERN_INFO
"p54: FW rev %s - Softmac protocol %x.%x\n",
145 fw_version
, priv
->fw_var
>> 8, priv
->fw_var
& 0xff);
147 if (priv
->fw_var
>= 0x300) {
148 /* Firmware supports QoS, use it! */
149 priv
->tx_stats
[4].limit
= 3;
150 priv
->tx_stats
[5].limit
= 4;
151 priv
->tx_stats
[6].limit
= 3;
152 priv
->tx_stats
[7].limit
= 1;
156 EXPORT_SYMBOL_GPL(p54_parse_firmware
);
158 static int p54_convert_rev0(struct ieee80211_hw
*dev
,
159 struct pda_pa_curve_data
*curve_data
)
161 struct p54_common
*priv
= dev
->priv
;
162 struct p54_pa_curve_data_sample
*dst
;
163 struct pda_pa_curve_data_sample_rev0
*src
;
164 size_t cd_len
= sizeof(*curve_data
) +
165 (curve_data
->points_per_channel
*sizeof(*dst
) + 2) *
166 curve_data
->channels
;
168 void *source
, *target
;
170 priv
->curve_data
= kmalloc(cd_len
, GFP_KERNEL
);
171 if (!priv
->curve_data
)
174 memcpy(priv
->curve_data
, curve_data
, sizeof(*curve_data
));
175 source
= curve_data
->data
;
176 target
= priv
->curve_data
->data
;
177 for (i
= 0; i
< curve_data
->channels
; i
++) {
178 __le16
*freq
= source
;
179 source
+= sizeof(__le16
);
180 *((__le16
*)target
) = *freq
;
181 target
+= sizeof(__le16
);
182 for (j
= 0; j
< curve_data
->points_per_channel
; j
++) {
186 dst
->rf_power
= src
->rf_power
;
187 dst
->pa_detector
= src
->pa_detector
;
188 dst
->data_64qam
= src
->pcv
;
189 /* "invent" the points for the other modulations */
190 #define SUB(x,y) (u8)((x) - (y)) > (x) ? 0 : (x) - (y)
191 dst
->data_16qam
= SUB(src
->pcv
, 12);
192 dst
->data_qpsk
= SUB(dst
->data_16qam
, 12);
193 dst
->data_bpsk
= SUB(dst
->data_qpsk
, 12);
194 dst
->data_barker
= SUB(dst
->data_bpsk
, 14);
196 target
+= sizeof(*dst
);
197 source
+= sizeof(*src
);
204 static int p54_convert_rev1(struct ieee80211_hw
*dev
,
205 struct pda_pa_curve_data
*curve_data
)
207 struct p54_common
*priv
= dev
->priv
;
208 struct p54_pa_curve_data_sample
*dst
;
209 struct pda_pa_curve_data_sample_rev1
*src
;
210 size_t cd_len
= sizeof(*curve_data
) +
211 (curve_data
->points_per_channel
*sizeof(*dst
) + 2) *
212 curve_data
->channels
;
214 void *source
, *target
;
216 priv
->curve_data
= kmalloc(cd_len
, GFP_KERNEL
);
217 if (!priv
->curve_data
)
220 memcpy(priv
->curve_data
, curve_data
, sizeof(*curve_data
));
221 source
= curve_data
->data
;
222 target
= priv
->curve_data
->data
;
223 for (i
= 0; i
< curve_data
->channels
; i
++) {
224 __le16
*freq
= source
;
225 source
+= sizeof(__le16
);
226 *((__le16
*)target
) = *freq
;
227 target
+= sizeof(__le16
);
228 for (j
= 0; j
< curve_data
->points_per_channel
; j
++) {
229 memcpy(target
, source
, sizeof(*src
));
231 target
+= sizeof(*dst
);
232 source
+= sizeof(*src
);
240 int p54_parse_eeprom(struct ieee80211_hw
*dev
, void *eeprom
, int len
)
242 struct p54_common
*priv
= dev
->priv
;
243 struct eeprom_pda_wrap
*wrap
= NULL
;
244 struct pda_entry
*entry
;
245 unsigned int data_len
, entry_len
;
248 u8
*end
= (u8
*)eeprom
+ len
;
250 wrap
= (struct eeprom_pda_wrap
*) eeprom
;
251 entry
= (void *)wrap
->data
+ le16_to_cpu(wrap
->len
);
253 /* verify that at least the entry length/code fits */
254 while ((u8
*)entry
<= end
- sizeof(*entry
)) {
255 entry_len
= le16_to_cpu(entry
->len
);
256 data_len
= ((entry_len
- 1) << 1);
258 /* abort if entry exceeds whole structure */
259 if ((u8
*)entry
+ sizeof(*entry
) + data_len
> end
)
262 switch (le16_to_cpu(entry
->code
)) {
263 case PDR_MAC_ADDRESS
:
264 SET_IEEE80211_PERM_ADDR(dev
, entry
->data
);
266 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS
:
272 if (2 + entry
->data
[1]*sizeof(*priv
->output_limit
) > data_len
) {
277 priv
->output_limit
= kmalloc(entry
->data
[1] *
278 sizeof(*priv
->output_limit
), GFP_KERNEL
);
280 if (!priv
->output_limit
) {
285 memcpy(priv
->output_limit
, &entry
->data
[2],
286 entry
->data
[1]*sizeof(*priv
->output_limit
));
287 priv
->output_limit_len
= entry
->data
[1];
289 case PDR_PRISM_PA_CAL_CURVE_DATA
: {
290 struct pda_pa_curve_data
*curve_data
=
291 (struct pda_pa_curve_data
*)entry
->data
;
292 if (data_len
< sizeof(*curve_data
)) {
297 switch (curve_data
->cal_method_rev
) {
299 err
= p54_convert_rev0(dev
, curve_data
);
302 err
= p54_convert_rev1(dev
, curve_data
);
305 printk(KERN_ERR
"p54: unknown curve data "
307 curve_data
->cal_method_rev
);
315 case PDR_PRISM_ZIF_TX_IQ_CALIBRATION
:
316 priv
->iq_autocal
= kmalloc(data_len
, GFP_KERNEL
);
317 if (!priv
->iq_autocal
) {
322 memcpy(priv
->iq_autocal
, entry
->data
, data_len
);
323 priv
->iq_autocal_len
= data_len
/ sizeof(struct pda_iq_autocal_entry
);
325 case PDR_INTERFACE_LIST
:
327 while ((u8
*)tmp
< entry
->data
+ data_len
) {
328 struct bootrec_exp_if
*exp_if
= tmp
;
329 if (le16_to_cpu(exp_if
->if_id
) == 0xF)
330 priv
->rxhw
= exp_if
->variant
& cpu_to_le16(0x07);
331 tmp
+= sizeof(struct bootrec_exp_if
);
334 case PDR_HARDWARE_PLATFORM_COMPONENT_ID
:
335 priv
->version
= *(u8
*)(entry
->data
+ 1);
338 /* make it overrun */
342 printk(KERN_INFO
"p54: unknown eeprom code : 0x%x\n",
343 le16_to_cpu(entry
->code
));
347 entry
= (void *)entry
+ (entry_len
+ 1)*2;
350 if (!priv
->iq_autocal
|| !priv
->output_limit
|| !priv
->curve_data
) {
351 printk(KERN_ERR
"p54: not all required entries found in eeprom!\n");
359 if (priv
->iq_autocal
) {
360 kfree(priv
->iq_autocal
);
361 priv
->iq_autocal
= NULL
;
364 if (priv
->output_limit
) {
365 kfree(priv
->output_limit
);
366 priv
->output_limit
= NULL
;
369 if (priv
->curve_data
) {
370 kfree(priv
->curve_data
);
371 priv
->curve_data
= NULL
;
374 printk(KERN_ERR
"p54: eeprom parse failed!\n");
377 EXPORT_SYMBOL_GPL(p54_parse_eeprom
);
379 void p54_fill_eeprom_readback(struct p54_control_hdr
*hdr
)
381 struct p54_eeprom_lm86
*eeprom_hdr
;
383 hdr
->magic1
= cpu_to_le16(0x8000);
384 hdr
->len
= cpu_to_le16(sizeof(*eeprom_hdr
) + 0x2000);
385 hdr
->type
= cpu_to_le16(P54_CONTROL_TYPE_EEPROM_READBACK
);
386 hdr
->retry1
= hdr
->retry2
= 0;
387 eeprom_hdr
= (struct p54_eeprom_lm86
*) hdr
->data
;
388 eeprom_hdr
->offset
= 0x0;
389 eeprom_hdr
->len
= cpu_to_le16(0x2000);
391 EXPORT_SYMBOL_GPL(p54_fill_eeprom_readback
);
393 static void p54_rx_data(struct ieee80211_hw
*dev
, struct sk_buff
*skb
)
395 struct p54_rx_hdr
*hdr
= (struct p54_rx_hdr
*) skb
->data
;
396 struct ieee80211_rx_status rx_status
= {0};
397 u16 freq
= le16_to_cpu(hdr
->freq
);
399 rx_status
.signal
= hdr
->rssi
;
401 rx_status
.qual
= (100 * hdr
->rssi
) / 127;
402 rx_status
.rate_idx
= hdr
->rate
& 0xf;
403 rx_status
.freq
= freq
;
404 rx_status
.band
= IEEE80211_BAND_2GHZ
;
405 rx_status
.antenna
= hdr
->antenna
;
406 rx_status
.mactime
= le64_to_cpu(hdr
->timestamp
);
407 rx_status
.flag
|= RX_FLAG_TSFT
;
409 skb_pull(skb
, sizeof(*hdr
));
410 skb_trim(skb
, le16_to_cpu(hdr
->len
));
412 ieee80211_rx_irqsafe(dev
, skb
, &rx_status
);
415 static void inline p54_wake_free_queues(struct ieee80211_hw
*dev
)
417 struct p54_common
*priv
= dev
->priv
;
420 for (i
= 0; i
< dev
->queues
; i
++)
421 if (priv
->tx_stats
[i
+ 4].len
< priv
->tx_stats
[i
+ 4].limit
)
422 ieee80211_wake_queue(dev
, i
);
425 static void p54_rx_frame_sent(struct ieee80211_hw
*dev
, struct sk_buff
*skb
)
427 struct p54_common
*priv
= dev
->priv
;
428 struct p54_control_hdr
*hdr
= (struct p54_control_hdr
*) skb
->data
;
429 struct p54_frame_sent_hdr
*payload
= (struct p54_frame_sent_hdr
*) hdr
->data
;
430 struct sk_buff
*entry
= (struct sk_buff
*) priv
->tx_queue
.next
;
431 u32 addr
= le32_to_cpu(hdr
->req_id
) - 0x70;
432 struct memrecord
*range
= NULL
;
434 u32 last_addr
= priv
->rx_start
;
437 spin_lock_irqsave(&priv
->tx_queue
.lock
, flags
);
438 while (entry
!= (struct sk_buff
*)&priv
->tx_queue
) {
439 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(entry
);
440 range
= (void *)info
->driver_data
;
441 if (range
->start_addr
== addr
) {
442 struct p54_control_hdr
*entry_hdr
;
443 struct p54_tx_control_allocdata
*entry_data
;
446 if (entry
->next
!= (struct sk_buff
*)&priv
->tx_queue
) {
447 struct ieee80211_tx_info
*ni
;
448 struct memrecord
*mr
;
450 ni
= IEEE80211_SKB_CB(entry
->next
);
451 mr
= (struct memrecord
*)ni
->driver_data
;
452 freed
= mr
->start_addr
- last_addr
;
454 freed
= priv
->rx_end
- last_addr
;
456 last_addr
= range
->end_addr
;
457 __skb_unlink(entry
, &priv
->tx_queue
);
458 spin_unlock_irqrestore(&priv
->tx_queue
.lock
, flags
);
460 memset(&info
->status
, 0, sizeof(info
->status
));
461 entry_hdr
= (struct p54_control_hdr
*) entry
->data
;
462 entry_data
= (struct p54_tx_control_allocdata
*) entry_hdr
->data
;
463 if ((entry_hdr
->magic1
& cpu_to_le16(0x4000)) != 0)
464 pad
= entry_data
->align
[0];
466 priv
->tx_stats
[entry_data
->hw_queue
].len
--;
467 if (!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
)) {
468 if (!(payload
->status
& 0x01))
469 info
->flags
|= IEEE80211_TX_STAT_ACK
;
471 info
->status
.excessive_retries
= 1;
473 info
->status
.retry_count
= payload
->retries
- 1;
474 info
->status
.ack_signal
= le16_to_cpu(payload
->ack_rssi
);
475 skb_pull(entry
, sizeof(*hdr
) + pad
+ sizeof(*entry_data
));
476 ieee80211_tx_status_irqsafe(dev
, entry
);
479 last_addr
= range
->end_addr
;
482 spin_unlock_irqrestore(&priv
->tx_queue
.lock
, flags
);
485 if (freed
>= IEEE80211_MAX_RTS_THRESHOLD
+ 0x170 +
486 sizeof(struct p54_control_hdr
))
487 p54_wake_free_queues(dev
);
490 static void p54_rx_control(struct ieee80211_hw
*dev
, struct sk_buff
*skb
)
492 struct p54_control_hdr
*hdr
= (struct p54_control_hdr
*) skb
->data
;
494 switch (le16_to_cpu(hdr
->type
)) {
495 case P54_CONTROL_TYPE_TXDONE
:
496 p54_rx_frame_sent(dev
, skb
);
498 case P54_CONTROL_TYPE_BBP
:
501 printk(KERN_DEBUG
"%s: not handling 0x%02x type control frame\n",
502 wiphy_name(dev
->wiphy
), le16_to_cpu(hdr
->type
));
507 /* returns zero if skb can be reused */
508 int p54_rx(struct ieee80211_hw
*dev
, struct sk_buff
*skb
)
510 u8 type
= le16_to_cpu(*((__le16
*)skb
->data
)) >> 8;
514 p54_rx_data(dev
, skb
);
517 /* TODO: do something better... but then again, I've never seen this happen */
518 printk(KERN_ERR
"%s: Received fault. Probably need to restart hardware now..\n",
519 wiphy_name(dev
->wiphy
));
522 p54_rx_control(dev
, skb
);
525 printk(KERN_ERR
"%s: unknown frame RXed (0x%02x)\n",
526 wiphy_name(dev
->wiphy
), type
);
531 EXPORT_SYMBOL_GPL(p54_rx
);
534 * So, the firmware is somewhat stupid and doesn't know what places in its
535 * memory incoming data should go to. By poking around in the firmware, we
536 * can find some unused memory to upload our packets to. However, data that we
537 * want the card to TX needs to stay intact until the card has told us that
538 * it is done with it. This function finds empty places we can upload to and
539 * marks allocated areas as reserved if necessary. p54_rx_frame_sent frees
542 static void p54_assign_address(struct ieee80211_hw
*dev
, struct sk_buff
*skb
,
543 struct p54_control_hdr
*data
, u32 len
)
545 struct p54_common
*priv
= dev
->priv
;
546 struct sk_buff
*entry
= priv
->tx_queue
.next
;
547 struct sk_buff
*target_skb
= NULL
;
548 u32 last_addr
= priv
->rx_start
;
549 u32 largest_hole
= 0;
550 u32 target_addr
= priv
->rx_start
;
553 len
= (len
+ 0x170 + 3) & ~0x3; /* 0x70 headroom, 0x100 tailroom */
555 spin_lock_irqsave(&priv
->tx_queue
.lock
, flags
);
556 left
= skb_queue_len(&priv
->tx_queue
);
559 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(entry
);
560 struct memrecord
*range
= (void *)info
->driver_data
;
561 hole_size
= range
->start_addr
- last_addr
;
562 if (!target_skb
&& hole_size
>= len
) {
563 target_skb
= entry
->prev
;
565 target_addr
= last_addr
;
567 largest_hole
= max(largest_hole
, hole_size
);
568 last_addr
= range
->end_addr
;
571 if (!target_skb
&& priv
->rx_end
- last_addr
>= len
) {
572 target_skb
= priv
->tx_queue
.prev
;
573 largest_hole
= max(largest_hole
, priv
->rx_end
- last_addr
- len
);
574 if (!skb_queue_empty(&priv
->tx_queue
)) {
575 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(target_skb
);
576 struct memrecord
*range
= (void *)info
->driver_data
;
577 target_addr
= range
->end_addr
;
580 largest_hole
= max(largest_hole
, priv
->rx_end
- last_addr
);
583 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
584 struct memrecord
*range
= (void *)info
->driver_data
;
585 range
->start_addr
= target_addr
;
586 range
->end_addr
= target_addr
+ len
;
587 __skb_queue_after(&priv
->tx_queue
, target_skb
, skb
);
588 if (largest_hole
< IEEE80211_MAX_RTS_THRESHOLD
+ 0x170 +
589 sizeof(struct p54_control_hdr
))
590 ieee80211_stop_queues(dev
);
592 spin_unlock_irqrestore(&priv
->tx_queue
.lock
, flags
);
594 data
->req_id
= cpu_to_le32(target_addr
+ 0x70);
597 static int p54_tx(struct ieee80211_hw
*dev
, struct sk_buff
*skb
)
599 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
600 struct ieee80211_tx_queue_stats
*current_queue
;
601 struct p54_common
*priv
= dev
->priv
;
602 struct p54_control_hdr
*hdr
;
603 struct ieee80211_hdr
*ieee80211hdr
= (struct ieee80211_hdr
*)skb
->data
;
604 struct p54_tx_control_allocdata
*txhdr
;
609 current_queue
= &priv
->tx_stats
[skb_get_queue_mapping(skb
) + 4];
610 if (unlikely(current_queue
->len
> current_queue
->limit
))
611 return NETDEV_TX_BUSY
;
612 current_queue
->len
++;
613 current_queue
->count
++;
614 if (current_queue
->len
== current_queue
->limit
)
615 ieee80211_stop_queue(dev
, skb_get_queue_mapping(skb
));
617 padding
= (unsigned long)(skb
->data
- (sizeof(*hdr
) + sizeof(*txhdr
))) & 3;
620 txhdr
= (struct p54_tx_control_allocdata
*)
621 skb_push(skb
, sizeof(*txhdr
) + padding
);
622 hdr
= (struct p54_control_hdr
*) skb_push(skb
, sizeof(*hdr
));
625 hdr
->magic1
= cpu_to_le16(0x4010);
627 hdr
->magic1
= cpu_to_le16(0x0010);
628 hdr
->len
= cpu_to_le16(len
);
629 hdr
->type
= (info
->flags
& IEEE80211_TX_CTL_NO_ACK
) ? 0 : cpu_to_le16(1);
630 hdr
->retry1
= hdr
->retry2
= info
->control
.retry_limit
;
632 /* TODO: add support for alternate retry TX rates */
633 rate
= ieee80211_get_tx_rate(dev
, info
)->hw_value
;
634 if (info
->flags
& IEEE80211_TX_CTL_SHORT_PREAMBLE
) {
638 if (info
->flags
& IEEE80211_TX_CTL_USE_RTS_CTS
) {
640 cts_rate
|= ieee80211_get_rts_cts_rate(dev
, info
)->hw_value
;
641 } else if (info
->flags
& IEEE80211_TX_CTL_USE_CTS_PROTECT
) {
643 cts_rate
|= ieee80211_get_rts_cts_rate(dev
, info
)->hw_value
;
645 memset(txhdr
->rateset
, rate
, 8);
648 txhdr
->hw_queue
= skb_get_queue_mapping(skb
) + 4;
649 txhdr
->tx_antenna
= (info
->antenna_sel_tx
== 0) ?
650 2 : info
->antenna_sel_tx
- 1;
651 txhdr
->output_power
= 0x7f; // HW Maximum
652 txhdr
->cts_rate
= (info
->flags
& IEEE80211_TX_CTL_NO_ACK
) ?
655 txhdr
->align
[0] = padding
;
657 /* FIXME: The sequence that follows is needed for this driver to
658 * work with mac80211 since "mac80211: fix TX sequence numbers".
659 * As with the temporary code in rt2x00, changes will be needed
660 * to get proper sequence numbers on beacons. In addition, this
661 * patch places the sequence number in the hardware state, which
662 * limits us to a single virtual state.
664 if (info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
665 if (info
->flags
& IEEE80211_TX_CTL_FIRST_FRAGMENT
)
667 ieee80211hdr
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
668 ieee80211hdr
->seq_ctrl
|= cpu_to_le16(priv
->seqno
);
670 /* modifies skb->cb and with it info, so must be last! */
671 p54_assign_address(dev
, skb
, hdr
, skb
->len
);
673 priv
->tx(dev
, hdr
, skb
->len
, 0);
677 static int p54_set_filter(struct ieee80211_hw
*dev
, u16 filter_type
,
678 const u8
*dst
, const u8
*src
, u8 antenna
,
679 u32 magic3
, u32 magic8
, u32 magic9
)
681 struct p54_common
*priv
= dev
->priv
;
682 struct p54_control_hdr
*hdr
;
683 struct p54_tx_control_filter
*filter
;
685 hdr
= kzalloc(sizeof(*hdr
) + sizeof(*filter
) +
686 priv
->tx_hdr_len
, GFP_ATOMIC
);
690 hdr
= (void *)hdr
+ priv
->tx_hdr_len
;
692 filter
= (struct p54_tx_control_filter
*) hdr
->data
;
693 hdr
->magic1
= cpu_to_le16(0x8001);
694 hdr
->len
= cpu_to_le16(sizeof(*filter
));
695 p54_assign_address(dev
, NULL
, hdr
, sizeof(*hdr
) + sizeof(*filter
));
696 hdr
->type
= cpu_to_le16(P54_CONTROL_TYPE_FILTER_SET
);
698 filter
->filter_type
= cpu_to_le16(filter_type
);
699 memcpy(filter
->dst
, dst
, ETH_ALEN
);
701 memset(filter
->src
, ~0, ETH_ALEN
);
703 memcpy(filter
->src
, src
, ETH_ALEN
);
704 filter
->antenna
= antenna
;
705 filter
->magic3
= cpu_to_le32(magic3
);
706 filter
->rx_addr
= cpu_to_le32(priv
->rx_end
);
707 filter
->max_rx
= cpu_to_le16(0x0620); /* FIXME: for usb ver 1.. maybe */
708 filter
->rxhw
= priv
->rxhw
;
709 filter
->magic8
= cpu_to_le16(magic8
);
710 filter
->magic9
= cpu_to_le16(magic9
);
712 priv
->tx(dev
, hdr
, sizeof(*hdr
) + sizeof(*filter
), 1);
716 static int p54_set_freq(struct ieee80211_hw
*dev
, __le16 freq
)
718 struct p54_common
*priv
= dev
->priv
;
719 struct p54_control_hdr
*hdr
;
720 struct p54_tx_control_channel
*chan
;
724 hdr
= kzalloc(sizeof(*hdr
) + sizeof(*chan
) +
725 priv
->tx_hdr_len
, GFP_KERNEL
);
729 hdr
= (void *)hdr
+ priv
->tx_hdr_len
;
731 chan
= (struct p54_tx_control_channel
*) hdr
->data
;
733 hdr
->magic1
= cpu_to_le16(0x8001);
734 hdr
->len
= cpu_to_le16(sizeof(*chan
));
735 hdr
->type
= cpu_to_le16(P54_CONTROL_TYPE_CHANNEL_CHANGE
);
736 p54_assign_address(dev
, NULL
, hdr
, sizeof(*hdr
) + sizeof(*chan
));
738 chan
->flags
= cpu_to_le16(0x1);
739 chan
->dwell
= cpu_to_le16(0x0);
741 for (i
= 0; i
< priv
->iq_autocal_len
; i
++) {
742 if (priv
->iq_autocal
[i
].freq
!= freq
)
745 memcpy(&chan
->iq_autocal
, &priv
->iq_autocal
[i
],
746 sizeof(*priv
->iq_autocal
));
749 if (i
== priv
->iq_autocal_len
)
752 for (i
= 0; i
< priv
->output_limit_len
; i
++) {
753 if (priv
->output_limit
[i
].freq
!= freq
)
756 chan
->val_barker
= 0x38;
757 chan
->val_bpsk
= chan
->dup_bpsk
=
758 priv
->output_limit
[i
].val_bpsk
;
759 chan
->val_qpsk
= chan
->dup_qpsk
=
760 priv
->output_limit
[i
].val_qpsk
;
761 chan
->val_16qam
= chan
->dup_16qam
=
762 priv
->output_limit
[i
].val_16qam
;
763 chan
->val_64qam
= chan
->dup_64qam
=
764 priv
->output_limit
[i
].val_64qam
;
767 if (i
== priv
->output_limit_len
)
770 entry
= priv
->curve_data
->data
;
771 for (i
= 0; i
< priv
->curve_data
->channels
; i
++) {
772 if (*((__le16
*)entry
) != freq
) {
773 entry
+= sizeof(__le16
);
774 entry
+= sizeof(struct p54_pa_curve_data_sample
) *
775 priv
->curve_data
->points_per_channel
;
779 entry
+= sizeof(__le16
);
780 chan
->pa_points_per_curve
=
781 min(priv
->curve_data
->points_per_channel
, (u8
) 8);
783 memcpy(chan
->curve_data
, entry
, sizeof(*chan
->curve_data
) *
784 chan
->pa_points_per_curve
);
788 chan
->rssical_mul
= cpu_to_le16(130);
789 chan
->rssical_add
= cpu_to_le16(0xfe70); /* -400 */
791 priv
->tx(dev
, hdr
, sizeof(*hdr
) + sizeof(*chan
), 1);
795 printk(KERN_ERR
"%s: frequency change failed\n", wiphy_name(dev
->wiphy
));
800 static int p54_set_leds(struct ieee80211_hw
*dev
, int mode
, int link
, int act
)
802 struct p54_common
*priv
= dev
->priv
;
803 struct p54_control_hdr
*hdr
;
804 struct p54_tx_control_led
*led
;
806 hdr
= kzalloc(sizeof(*hdr
) + sizeof(*led
) +
807 priv
->tx_hdr_len
, GFP_KERNEL
);
811 hdr
= (void *)hdr
+ priv
->tx_hdr_len
;
812 hdr
->magic1
= cpu_to_le16(0x8001);
813 hdr
->len
= cpu_to_le16(sizeof(*led
));
814 hdr
->type
= cpu_to_le16(P54_CONTROL_TYPE_LED
);
815 p54_assign_address(dev
, NULL
, hdr
, sizeof(*hdr
) + sizeof(*led
));
817 led
= (struct p54_tx_control_led
*) hdr
->data
;
818 led
->mode
= cpu_to_le16(mode
);
819 led
->led_permanent
= cpu_to_le16(link
);
820 led
->led_temporary
= cpu_to_le16(act
);
821 led
->duration
= cpu_to_le16(1000);
823 priv
->tx(dev
, hdr
, sizeof(*hdr
) + sizeof(*led
), 1);
828 #define P54_SET_QUEUE(queue, ai_fs, cw_min, cw_max, _txop) \
830 queue.aifs = cpu_to_le16(ai_fs); \
831 queue.cwmin = cpu_to_le16(cw_min); \
832 queue.cwmax = cpu_to_le16(cw_max); \
833 queue.txop = cpu_to_le16(_txop); \
836 static void p54_init_vdcf(struct ieee80211_hw
*dev
)
838 struct p54_common
*priv
= dev
->priv
;
839 struct p54_control_hdr
*hdr
;
840 struct p54_tx_control_vdcf
*vdcf
;
842 /* all USB V1 adapters need a extra headroom */
843 hdr
= (void *)priv
->cached_vdcf
+ priv
->tx_hdr_len
;
844 hdr
->magic1
= cpu_to_le16(0x8001);
845 hdr
->len
= cpu_to_le16(sizeof(*vdcf
));
846 hdr
->type
= cpu_to_le16(P54_CONTROL_TYPE_DCFINIT
);
847 hdr
->req_id
= cpu_to_le32(priv
->rx_start
);
849 vdcf
= (struct p54_tx_control_vdcf
*) hdr
->data
;
851 P54_SET_QUEUE(vdcf
->queue
[0], 0x0002, 0x0003, 0x0007, 47);
852 P54_SET_QUEUE(vdcf
->queue
[1], 0x0002, 0x0007, 0x000f, 94);
853 P54_SET_QUEUE(vdcf
->queue
[2], 0x0003, 0x000f, 0x03ff, 0);
854 P54_SET_QUEUE(vdcf
->queue
[3], 0x0007, 0x000f, 0x03ff, 0);
857 static void p54_set_vdcf(struct ieee80211_hw
*dev
)
859 struct p54_common
*priv
= dev
->priv
;
860 struct p54_control_hdr
*hdr
;
861 struct p54_tx_control_vdcf
*vdcf
;
863 hdr
= (void *)priv
->cached_vdcf
+ priv
->tx_hdr_len
;
865 p54_assign_address(dev
, NULL
, hdr
, sizeof(*hdr
) + sizeof(*vdcf
));
867 vdcf
= (struct p54_tx_control_vdcf
*) hdr
->data
;
869 if (dev
->conf
.flags
& IEEE80211_CONF_SHORT_SLOT_TIME
) {
879 /* (see prism54/isl_oid.h for further details) */
880 vdcf
->frameburst
= cpu_to_le16(0);
882 priv
->tx(dev
, hdr
, sizeof(*hdr
) + sizeof(*vdcf
), 0);
885 static int p54_start(struct ieee80211_hw
*dev
)
887 struct p54_common
*priv
= dev
->priv
;
890 if (!priv
->cached_vdcf
) {
891 priv
->cached_vdcf
= kzalloc(sizeof(struct p54_tx_control_vdcf
)+
892 priv
->tx_hdr_len
+ sizeof(struct p54_control_hdr
),
895 if (!priv
->cached_vdcf
)
899 err
= priv
->open(dev
);
901 priv
->mode
= IEEE80211_IF_TYPE_MNTR
;
908 static void p54_stop(struct ieee80211_hw
*dev
)
910 struct p54_common
*priv
= dev
->priv
;
912 while ((skb
= skb_dequeue(&priv
->tx_queue
)))
915 priv
->mode
= IEEE80211_IF_TYPE_INVALID
;
918 static int p54_add_interface(struct ieee80211_hw
*dev
,
919 struct ieee80211_if_init_conf
*conf
)
921 struct p54_common
*priv
= dev
->priv
;
923 if (priv
->mode
!= IEEE80211_IF_TYPE_MNTR
)
926 switch (conf
->type
) {
927 case IEEE80211_IF_TYPE_STA
:
928 priv
->mode
= conf
->type
;
934 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
936 p54_set_filter(dev
, 0, priv
->mac_addr
, NULL
, 0, 1, 0, 0xF642);
937 p54_set_filter(dev
, 0, priv
->mac_addr
, NULL
, 1, 0, 0, 0xF642);
939 switch (conf
->type
) {
940 case IEEE80211_IF_TYPE_STA
:
941 p54_set_filter(dev
, 1, priv
->mac_addr
, NULL
, 0, 0x15F, 0x1F4, 0);
944 BUG(); /* impossible */
948 p54_set_leds(dev
, 1, 0, 0);
953 static void p54_remove_interface(struct ieee80211_hw
*dev
,
954 struct ieee80211_if_init_conf
*conf
)
956 struct p54_common
*priv
= dev
->priv
;
957 priv
->mode
= IEEE80211_IF_TYPE_MNTR
;
958 memset(priv
->mac_addr
, 0, ETH_ALEN
);
959 p54_set_filter(dev
, 0, priv
->mac_addr
, NULL
, 2, 0, 0, 0);
962 static int p54_config(struct ieee80211_hw
*dev
, struct ieee80211_conf
*conf
)
965 struct p54_common
*priv
= dev
->priv
;
967 mutex_lock(&priv
->conf_mutex
);
968 ret
= p54_set_freq(dev
, cpu_to_le16(conf
->channel
->center_freq
));
970 mutex_unlock(&priv
->conf_mutex
);
974 static int p54_config_interface(struct ieee80211_hw
*dev
,
975 struct ieee80211_vif
*vif
,
976 struct ieee80211_if_conf
*conf
)
978 struct p54_common
*priv
= dev
->priv
;
980 mutex_lock(&priv
->conf_mutex
);
981 p54_set_filter(dev
, 0, priv
->mac_addr
, conf
->bssid
, 0, 1, 0, 0xF642);
982 p54_set_filter(dev
, 0, priv
->mac_addr
, conf
->bssid
, 2, 0, 0, 0);
983 p54_set_leds(dev
, 1, !is_multicast_ether_addr(conf
->bssid
), 0);
984 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
985 mutex_unlock(&priv
->conf_mutex
);
989 static void p54_configure_filter(struct ieee80211_hw
*dev
,
990 unsigned int changed_flags
,
991 unsigned int *total_flags
,
992 int mc_count
, struct dev_mc_list
*mclist
)
994 struct p54_common
*priv
= dev
->priv
;
996 *total_flags
&= FIF_BCN_PRBRESP_PROMISC
;
998 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
999 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
)
1000 p54_set_filter(dev
, 0, priv
->mac_addr
,
1003 p54_set_filter(dev
, 0, priv
->mac_addr
,
1004 priv
->bssid
, 2, 0, 0, 0);
1008 static int p54_conf_tx(struct ieee80211_hw
*dev
, u16 queue
,
1009 const struct ieee80211_tx_queue_params
*params
)
1011 struct p54_common
*priv
= dev
->priv
;
1012 struct p54_tx_control_vdcf
*vdcf
;
1014 vdcf
= (struct p54_tx_control_vdcf
*)(((struct p54_control_hdr
*)
1015 ((void *)priv
->cached_vdcf
+ priv
->tx_hdr_len
))->data
);
1017 if ((params
) && !(queue
> 4)) {
1018 P54_SET_QUEUE(vdcf
->queue
[queue
], params
->aifs
,
1019 params
->cw_min
, params
->cw_max
, params
->txop
);
1028 static int p54_get_stats(struct ieee80211_hw
*dev
,
1029 struct ieee80211_low_level_stats
*stats
)
1035 static int p54_get_tx_stats(struct ieee80211_hw
*dev
,
1036 struct ieee80211_tx_queue_stats
*stats
)
1038 struct p54_common
*priv
= dev
->priv
;
1040 memcpy(stats
, &priv
->tx_stats
[4], sizeof(stats
[0]) * dev
->queues
);
1045 static const struct ieee80211_ops p54_ops
= {
1049 .add_interface
= p54_add_interface
,
1050 .remove_interface
= p54_remove_interface
,
1051 .config
= p54_config
,
1052 .config_interface
= p54_config_interface
,
1053 .configure_filter
= p54_configure_filter
,
1054 .conf_tx
= p54_conf_tx
,
1055 .get_stats
= p54_get_stats
,
1056 .get_tx_stats
= p54_get_tx_stats
1059 struct ieee80211_hw
*p54_init_common(size_t priv_data_len
)
1061 struct ieee80211_hw
*dev
;
1062 struct p54_common
*priv
;
1064 dev
= ieee80211_alloc_hw(priv_data_len
, &p54_ops
);
1069 priv
->mode
= IEEE80211_IF_TYPE_INVALID
;
1070 skb_queue_head_init(&priv
->tx_queue
);
1071 dev
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &band_2GHz
;
1072 dev
->flags
= IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING
| /* not sure */
1073 IEEE80211_HW_RX_INCLUDES_FCS
|
1074 IEEE80211_HW_SIGNAL_UNSPEC
;
1076 dev
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
1078 dev
->channel_change_time
= 1000; /* TODO: find actual value */
1079 dev
->max_signal
= 127;
1081 priv
->tx_stats
[0].limit
= 1;
1082 priv
->tx_stats
[1].limit
= 1;
1083 priv
->tx_stats
[2].limit
= 1;
1084 priv
->tx_stats
[3].limit
= 1;
1085 priv
->tx_stats
[4].limit
= 5;
1088 dev
->extra_tx_headroom
= sizeof(struct p54_control_hdr
) + 4 +
1089 sizeof(struct p54_tx_control_allocdata
);
1091 mutex_init(&priv
->conf_mutex
);
1095 EXPORT_SYMBOL_GPL(p54_init_common
);
1097 void p54_free_common(struct ieee80211_hw
*dev
)
1099 struct p54_common
*priv
= dev
->priv
;
1100 kfree(priv
->iq_autocal
);
1101 kfree(priv
->output_limit
);
1102 kfree(priv
->curve_data
);
1103 kfree(priv
->cached_vdcf
);
1105 EXPORT_SYMBOL_GPL(p54_free_common
);
1107 static int __init
p54_init(void)
1112 static void __exit
p54_exit(void)
1116 module_init(p54_init
);
1117 module_exit(p54_exit
);