23 #include <linux/netdevice.h>
25 #include <linux/slab.h>
110 { 4, { 3, 2, 1, 0 }},
111 { 5, { 4, 3, 2, 1, 0 }},
112 { 6, { 5, 4, 3, 2, 1, 0}},
113 { 5, { 6, 3, 2, 1, 0 }},
114 { 6, { 7, 6, 3, 2, 1, 0 }},
115 { 6, { 8, 6, 3, 2, 1, 0 }},
116 { 7, { 9, 8, 6, 3, 2, 1, 0 }},
117 { 8, {10, 9, 8, 6, 3, 2, 1, 0 }},
118 { 9, {11, 10, 9, 8, 6, 3, 2, 1, 0 }}
122 { .center_freq = 2412, .hw_value = 1 },
123 { .center_freq = 2417, .hw_value = 2 },
124 { .center_freq = 2422, .hw_value = 3 },
125 { .center_freq = 2427, .hw_value = 4 },
126 { .center_freq = 2432, .hw_value = 5 },
127 { .center_freq = 2437, .hw_value = 6 },
128 { .center_freq = 2442, .hw_value = 7 },
129 { .center_freq = 2447, .hw_value = 8 },
130 { .center_freq = 2452, .hw_value = 9 },
131 { .center_freq = 2457, .hw_value = 10 },
132 { .center_freq = 2462, .hw_value = 11 },
133 { .center_freq = 2467, .hw_value = 12 },
134 { .center_freq = 2472, .hw_value = 13 },
135 { .center_freq = 2484, .hw_value = 14 },
138 static void housekeeping_init(
struct zd_mac *
mac);
139 static void housekeeping_enable(
struct zd_mac *
mac);
140 static void housekeeping_disable(
struct zd_mac *
mac);
141 static void beacon_init(
struct zd_mac *
mac);
142 static void beacon_enable(
struct zd_mac *
mac);
143 static void beacon_disable(
struct zd_mac *
mac);
144 static void set_rts_cts(
struct zd_mac *
mac,
unsigned int short_preamble);
148 static int zd_reg2alpha2(
u8 regdomain,
char *alpha2)
152 for (i = 0; i <
ARRAY_SIZE(reg_alpha2_map); i++) {
153 reg_map = ®_alpha2_map[
i];
154 if (regdomain == reg_map->
reg) {
155 alpha2[0] = reg_map->
alpha2[0];
156 alpha2[1] = reg_map->
alpha2[1];
168 "%s: signal value from device not in range 0..100, "
169 "but %d.\n", __func__, signal);
173 else if (signal > 100)
183 struct zd_mac *mac = zd_hw_mac(hw);
189 SET_IEEE80211_PERM_ADDR(hw, addr);
197 struct zd_mac *mac = zd_hw_mac(hw);
200 u8 default_regdomain;
214 spin_lock_irq(&mac->
lock);
216 spin_unlock_irq(&mac->
lock);
224 r = zd_reg2alpha2(mac->
regdomain, alpha2);
243 static int set_rx_filter(
struct zd_mac *mac)
251 spin_unlock_irqrestore(&mac->
lock, flags);
256 static int set_mac_and_bssid(
struct zd_mac *mac)
271 return set_rx_filter(mac);
276 static int set_mc_hash(
struct zd_mac *mac)
285 struct zd_mac *mac = zd_hw_mac(hw);
303 r = set_rx_filter(mac);
306 r = set_mc_hash(mac);
319 "%s: failed to set radio on\n", __func__);
329 housekeeping_enable(mac);
345 struct zd_mac *mac = zd_hw_mac(hw);
359 housekeeping_disable(mac);
375 unsigned int short_preamble;
381 spin_lock_irq(&mac->
lock);
384 beacon_interval = mac->
beacon.interval;
385 beacon_period = mac->
beacon.period;
387 spin_unlock_irq(&mac->
lock);
389 r = set_mac_and_bssid(mac);
402 set_rts_cts(mac, short_preamble);
407 "zd_chip_set_multicast_hash failed, %d\n", r);
415 beacon = ieee80211_beacon_get(mac->
hw, mac->
vif);
417 zd_mac_config_beacon(mac->
hw, beacon,
false);
421 beacon_period, mac->
type);
423 spin_lock_irq(&mac->
lock);
425 spin_unlock_irq(&mac->
lock);
450 int success = 1,
retry = 1;
454 ieee80211_tx_info_clear_status(info);
469 first_idx = info->
status.rates[0].idx;
471 retries = &zd_retry_rates[first_idx];
475 info->
status.rates[0].count = 1;
479 info->
status.rates[
i].count = 1;
482 info->
status.rates[
i].idx = retries->
rate[retry - 1];
483 info->
status.rates[
i].count = 1;
486 info->
status.rates[
i].idx = -1;
488 info->
status.ack_signal = zd_check_signal(hw, ackssi);
503 struct zd_mac *mac = zd_hw_mac(hw);
506 struct tx_status *tx_status = (
struct tx_status *)urb->transfer_buffer;
508 int success = !tx_status->
failure;
509 int retry = tx_status->
retry + success;
516 skb_queue_walk(q, skb) {
519 int first_idx, final_idx;
529 skb_queue_is_first(q, skb)) {
542 info = IEEE80211_SKB_CB(skb);
543 first_idx = info->
status.rates[0].idx;
545 retries = &zd_retry_rates[first_idx];
546 if (retry <= 0 || retry > retries->
count)
549 final_idx = retries->
rate[retry - 1];
550 final_rate = zd_rates[final_idx].
hw_value;
552 if (final_rate != tx_status->
rate) {
561 for (i=1; i<=position; i++) {
562 skb = __skb_dequeue(q);
563 zd_mac_tx_status(hw, skb,
565 i == position ? tx_status :
NULL);
570 spin_unlock_irqrestore(&q->
lock, flags);
587 struct zd_mac *mac = zd_hw_mac(hw);
589 ieee80211_tx_info_clear_status(info);
611 static int zd_calc_tx_length_us(
u8 *
service,
u8 zd_rate,
u16 tx_length)
616 static const u8 rate_divisor[] = {
641 bits = (2*
bits) + 10;
647 if (0 < t && t <= 3) {
693 if (!mac->
beacon.cur_beacon)
696 if (mac->
beacon.cur_beacon->len != beacon->
len)
702 static void zd_mac_free_cur_beacon_locked(
struct zd_mac *mac)
710 static void zd_mac_free_cur_beacon(
struct zd_mac *mac)
713 zd_mac_free_cur_beacon_locked(mac);
720 struct zd_mac *mac = zd_hw_mac(hw);
721 int r,
ret, num_cmds, req_pos = 0;
724 u32 full_len = beacon->
len + 4;
725 unsigned long end_jiffies, message_jiffies;
731 if (zd_mac_match_cur_beacon(mac, beacon)) {
737 num_cmds = 1 + zd_chip_is_zd1211b(&mac->
chip) + full_len;
750 if (in_intr && tmp & 0x2) {
764 "CR_BCN_FIFO_SEMAPHORE not ready\n");
767 "Giving up beacon config.\n");
776 ioreqs[req_pos].
value = full_len - 1;
778 if (zd_chip_is_zd1211b(&mac->
chip)) {
780 ioreqs[req_pos].
value = full_len - 1;
784 for (j = 0 ; j < beacon->
len; j++) {
786 ioreqs[req_pos].
value = *((
u8 *)(beacon->
data + j));
790 for (j = 0; j < 4; j++) {
792 ioreqs[req_pos].
value = 0x0;
796 BUG_ON(req_pos != num_cmds);
819 "CR_BCN_FIFO_SEMAPHORE!\n");
820 if (r < 0 || ret < 0) {
826 zd_mac_free_cur_beacon_locked(mac);
832 zd_mac_free_cur_beacon_locked(mac);
833 mac->
beacon.cur_beacon = beacon;
840 r = zd_iowrite32_locked(&mac->
chip, 0x00000400 | (full_len << 19),
851 zd_mac_free_cur_beacon_locked(mac);
859 "resetting device...");
865 static int fill_ctrlset(
struct zd_mac *mac,
871 unsigned int packet_length;
887 txrate = ieee80211_get_tx_rate(mac->
hw, info);
895 cs_set_control(mac, cs, hdr, info);
897 packet_length = frag_len +
sizeof(
struct zd_ctrlset) + 10;
944 struct zd_mac *mac = zd_hw_mac(hw);
948 r = fill_ctrlset(mac, skb);
980 struct zd_mac *mac = zd_hw_mac(hw);
992 skb_queue_walk(q, skb) {
997 if (mac->
ack_pending && skb_queue_is_first(q, skb))
1009 for (i=1; i<position; i++) {
1010 skb = __skb_dequeue(q);
1011 zd_mac_tx_status(hw, skb,
1022 skb = __skb_dequeue(q);
1028 spin_unlock_irqrestore(&q->
lock, flags);
1034 struct zd_mac *mac = zd_hw_mac(hw);
1048 memset(&stats, 0,
sizeof(stats));
1061 (buffer + (length -
sizeof(
struct rx_status)));
1079 for (i = 0; i < mac->
band.n_bitrates; i++)
1080 if (rate == mac->
band.bitrates[i].hw_value)
1097 need_padding = ieee80211_is_data_qos(fc) ^ ieee80211_has_a4(fc);
1099 skb = dev_alloc_skb(length + (need_padding ? 2 : 0));
1104 skb_reserve(skb, 2);
1110 memcpy(IEEE80211_SKB_RXCB(skb), &stats,
sizeof(stats));
1115 static int zd_op_add_interface(
struct ieee80211_hw *hw,
1118 struct zd_mac *mac = zd_hw_mac(hw);
1124 switch (vif->
type) {
1138 return set_mac_and_bssid(mac);
1141 static void zd_op_remove_interface(
struct ieee80211_hw *hw,
1144 struct zd_mac *mac = zd_hw_mac(hw);
1150 zd_mac_free_cur_beacon(mac);
1155 struct zd_mac *mac = zd_hw_mac(hw);
1158 spin_lock_irq(&mac->
lock);
1160 spin_unlock_irq(&mac->
lock);
1165 static void zd_beacon_done(
struct zd_mac *mac)
1181 zd_op_tx(mac->
hw,
NULL, skb);
1187 beacon = ieee80211_beacon_get(mac->
hw, mac->
vif);
1189 zd_mac_config_beacon(mac->
hw, beacon,
true);
1191 spin_lock_irq(&mac->
lock);
1193 spin_unlock_irq(&mac->
lock);
1199 unsigned long flags;
1204 spin_unlock_irqrestore(&mac->
lock, flags);
1208 zd_beacon_done(mac);
1220 struct zd_mac *mac = zd_hw_mac(hw);
1234 #define SUPPORTED_FIF_FLAGS \
1235 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | FIF_CONTROL | \
1236 FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)
1237 static void zd_op_configure_filter(
struct ieee80211_hw *hw,
1238 unsigned int changed_flags,
1239 unsigned int *new_flags,
1244 .high = multicast >> 32,
1246 struct zd_mac *mac = zd_hw_mac(hw);
1247 unsigned long flags;
1262 zd_mc_add_all(&hash);
1268 spin_unlock_irqrestore(&mac->
lock, flags);
1273 r = set_rx_filter(mac);
1295 static void zd_op_bss_info_changed(
struct ieee80211_hw *hw,
1300 struct zd_mac *mac = zd_hw_mac(hw);
1310 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
1314 zd_mac_config_beacon(hw, beacon,
false);
1328 spin_lock_irq(&mac->
lock);
1332 spin_unlock_irq(&mac->
lock);
1338 associated = is_valid_ether_addr(bss_conf->
bssid);
1340 spin_lock_irq(&mac->
lock);
1342 spin_unlock_irq(&mac->
lock);
1347 spin_lock_irq(&mac->
lock);
1349 spin_unlock_irq(&mac->
lock);
1357 struct zd_mac *mac = zd_hw_mac(hw);
1365 .add_interface = zd_op_add_interface,
1366 .remove_interface = zd_op_remove_interface,
1367 .config = zd_op_config,
1368 .prepare_multicast = zd_op_prepare_multicast,
1369 .configure_filter = zd_op_configure_filter,
1370 .bss_info_changed = zd_op_bss_info_changed,
1371 .get_tsf = zd_op_get_tsf,
1381 dev_dbg_f(&intf->dev,
"out of memory\n");
1385 mac = zd_hw_mac(hw);
1387 memset(mac, 0,
sizeof(*mac));
1407 hw->
wiphy->interface_modes =
1427 housekeeping_init(mac);
1431 SET_IEEE80211_DEV(hw, &intf->dev);
1435 #define BEACON_WATCHDOG_DELAY round_jiffies_relative(HZ)
1437 static void beacon_watchdog_handler(
struct work_struct *work)
1450 spin_lock_irq(&mac->
lock);
1451 interval = mac->
beacon.interval;
1452 period = mac->
beacon.period;
1453 timeout = mac->
beacon.last_update +
1455 spin_unlock_irq(&mac->
lock);
1460 "(interval: %d, dtim: %d)\n",
1465 beacon = ieee80211_beacon_get(mac->
hw, mac->
vif);
1467 zd_mac_free_cur_beacon(mac);
1469 zd_mac_config_beacon(mac->
hw, beacon,
false);
1476 spin_lock_irq(&mac->
lock);
1478 spin_unlock_irq(&mac->
lock);
1486 static void beacon_init(
struct zd_mac *mac)
1491 static void beacon_enable(
struct zd_mac *mac)
1500 static void beacon_disable(
struct zd_mac *mac)
1505 zd_mac_free_cur_beacon(mac);
1508 #define LINK_LED_WORK_DELAY HZ
1510 static void link_led_handler(
struct work_struct *work)
1521 spin_lock_irq(&mac->
lock);
1523 spin_unlock_irq(&mac->
lock);
1535 static void housekeeping_init(
struct zd_mac *mac)
1540 static void housekeeping_enable(
struct zd_mac *mac)
1547 static void housekeeping_disable(
struct zd_mac *mac)