27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/slab.h>
47 return vif->
addr[5] & (rt2x00dev->
ops->max_ap_intf - 1);
131 static void rt2x00lib_intf_scheduled_iter(
void *
data,
u8 *
mac,
160 rt2x00lib_intf_scheduled_iter,
172 if (rt2x00dev->
ops->lib->set_device_state(rt2x00dev,
STATE_AWAKE))
173 ERROR(rt2x00dev,
"Device failed to wakeup.\n");
180 static void rt2x00lib_bc_buffer_iter(
void *data,
u8 *mac,
202 static void rt2x00lib_beaconupdate_iter(
void *data,
u8 *mac,
218 WARN_ON(rt2x00_is_usb(rt2x00dev));
229 rt2x00lib_bc_buffer_iter,
241 rt2x00lib_beaconupdate_iter,
253 rt2x00lib_beaconupdate_iter,
276 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
280 u8 rate_idx, rate_flags, retry_rates;
281 u8 skbdesc_flags = skbdesc->
flags;
292 skb_pull(entry->skb, rt2x00dev->
ops->extra_tx_headroom);
335 rt2x00dev->
link.qual.tx_success += success;
336 rt2x00dev->
link.qual.tx_failed += !success;
341 (txdesc->
retry + 1) : 1;
347 tx_info->
status.ack_signal = 0;
356 tx_info->
status.rates[
i].idx = rate_idx -
i;
357 tx_info->
status.rates[
i].flags = rate_flags;
359 if (rate_idx - i == 0) {
364 tx_info->
status.rates[
i].count = retry_rates -
i;
368 tx_info->
status.rates[
i].count = 1;
370 if (i < (IEEE80211_TX_MAX_RATES - 1))
371 tx_info->
status.rates[
i].idx = -1;
392 tx_info->
status.ampdu_len = 1;
393 tx_info->
status.ampdu_ack_len = success ? 1 : 0;
417 ieee80211_tx_status_ni(rt2x00dev->
hw, entry->skb);
427 rt2x00dev->
ops->lib->clear_entry(entry);
438 spin_lock_bh(&entry->queue->tx_lock);
439 if (!rt2x00queue_threshold(entry->queue))
441 spin_unlock_bh(&entry->queue->tx_lock);
457 static u8 *rt2x00lib_find_ie(
u8 *data,
unsigned int len,
u8 ie)
462 pos = (
u8 *)mgmt->
u.beacon.variable;
465 if (pos + 2 + pos[1] > end)
477 static void rt2x00lib_sleep(
struct work_struct *work)
494 static void rt2x00lib_rxdone_check_ps(
struct rt2x00_dev *rt2x00dev,
526 if (tim[1] <
sizeof(*tim_ie))
535 cam = ieee80211_check_tim(tim_ie, tim_len, rt2x00dev->
aid);
538 cam |= (tim_ie->bitmap_ctrl & 0x01);
544 static int rt2x00lib_rxdone_read_signal(
struct rt2x00_dev *rt2x00dev,
550 int signal = rxdesc->
signal;
565 rate = rt2x00_get_rate(sband->
bitrates[i].hw_value);
567 (rate->
plcp == signal)) ||
571 (rate->
mcs == signal))) {
578 if (signal >= 0 && signal <= 76)
585 WARNING(rt2x00dev,
"Frame received with unrecognized signal, "
586 "mode=0x%.4x, signal=0x%.4x, type=%d.\n",
593 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
623 memset(&rxdesc, 0,
sizeof(rxdesc));
624 rt2x00dev->
ops->lib->fill_rxdone(entry, &rxdesc);
631 rxdesc.
size > entry->queue->data_size)) {
632 ERROR(rt2x00dev,
"Wrong frame size %d max %d.\n",
633 rxdesc.
size, entry->queue->data_size);
634 dev_kfree_skb(entry->skb);
654 else if (header_length &&
655 (rxdesc.
size > header_length) &&
665 rate_idx = rt2x00lib_rxdone_read_signal(rt2x00dev, &rxdesc);
674 rt2x00lib_rxdone_check_ps(rt2x00dev, entry->skb, &rxdesc);
687 rx_status = IEEE80211_SKB_RXCB(entry->skb);
694 rx_status->
antenna = rt2x00dev->
link.ant.active.rx;
696 ieee80211_rx_ni(rt2x00dev->
hw, entry->skb);
709 rt2x00dev->
ops->lib->clear_entry(entry);
828 static int rt2x00lib_probe_hw_modes(
struct rt2x00_dev *rt2x00dev,
834 unsigned int num_rates;
847 rates = kcalloc(num_rates,
sizeof(*rates),
GFP_KERNEL);
849 goto exit_free_channels;
854 for (i = 0; i < num_rates; i++)
855 rt2x00lib_rate(&rates[i], i, rt2x00_get_rate(i));
861 rt2x00lib_channel(&channels[i],
879 &spec->
ht,
sizeof(spec->
ht));
897 &spec->
ht,
sizeof(spec->
ht));
904 ERROR(rt2x00dev,
"Allocation ieee80211 modes failed.\n");
908 static void rt2x00lib_remove_hw(
struct rt2x00_dev *rt2x00dev)
923 static int rt2x00lib_probe_hw(
struct rt2x00_dev *rt2x00dev)
934 status = rt2x00lib_probe_hw_modes(rt2x00dev, spec);
941 rt2x00dev->
hw->queues = rt2x00dev->
ops->tx_queues;
946 rt2x00dev->
hw->extra_tx_headroom =
948 rt2x00dev->
ops->extra_tx_headroom);
961 rt2x00dev->
hw->sta_data_size =
sizeof(
struct rt2x00_sta);
976 rt2x00dev->
ops->tx->entry_num *
979 status =
kfifo_alloc(&rt2x00dev->txstatus_fifo, kfifo_size,
990 #define RT2X00_TASKLET_INIT(taskletname) \
991 if (rt2x00dev->ops->lib->taskletname) { \
992 tasklet_init(&rt2x00dev->taskletname, \
993 rt2x00dev->ops->lib->taskletname, \
994 (unsigned long)rt2x00dev); \
1003 #undef RT2X00_TASKLET_INIT
1020 static void rt2x00lib_uninitialize(
struct rt2x00_dev *rt2x00dev)
1028 rt2x00rfkill_unregister(rt2x00dev);
1033 rt2x00dev->
ops->lib->uninitialize(rt2x00dev);
1041 static int rt2x00lib_initialize(
struct rt2x00_dev *rt2x00dev)
1058 status = rt2x00dev->
ops->lib->initialize(rt2x00dev);
1087 retval = rt2x00lib_initialize(rt2x00dev);
1121 static inline void rt2x00lib_set_if_combinations(
struct rt2x00_dev *rt2x00dev)
1130 if_limit->
max = rt2x00dev->
ops->max_ap_intf;
1137 if_combination->
limits = if_limit;
1146 rt2x00dev->
hw->wiphy->n_iface_combinations = 1;
1159 rt2x00lib_set_if_combinations(rt2x00dev);
1164 if (rt2x00dev->
ops->drv_data_size > 0) {
1165 rt2x00dev->
drv_data = kzalloc(rt2x00dev->
ops->drv_data_size,
1190 if (rt2x00dev->
ops->bcn->entry_num > 0)
1191 rt2x00dev->
hw->wiphy->interface_modes |=
1216 retval = rt2x00dev->
ops->lib->probe_hw(rt2x00dev);
1218 ERROR(rt2x00dev,
"Failed to allocate device.\n");
1232 retval = rt2x00lib_probe_hw(rt2x00dev);
1234 ERROR(rt2x00dev,
"Failed to initialize hw.\n");
1244 rt2x00rfkill_register(rt2x00dev);
1270 if (rt2x00_is_usb(rt2x00dev)) {
1295 rt2x00lib_uninitialize(rt2x00dev);
1306 rt2x00lib_remove_hw(rt2x00dev);
1332 NOTICE(rt2x00dev,
"Going to sleep.\n");
1343 rt2x00lib_uninitialize(rt2x00dev);
1362 if (rt2x00dev->
ops->lib->set_device_state(rt2x00dev,
STATE_SLEEP))
1363 WARNING(rt2x00dev,
"Device failed to enter sleep state, "
1364 "continue suspending.\n");
1370 int rt2x00lib_resume(
struct rt2x00_dev *rt2x00dev)
1372 NOTICE(rt2x00dev,
"Waking up.\n");