41 #include <linux/slab.h>
42 #include <linux/module.h>
44 #include <linux/random.h>
51 static bool modparam_nohwcrypt;
59 #define RATE(_bitrate, _hw_rate, _txpidx, _flags) { \
60 .bitrate = (_bitrate), \
62 .hw_value = (_hw_rate) | (_txpidx) << 4, \
81 #define carl9170_g_ratetable (__carl9170_ratetable + 0)
82 #define carl9170_g_ratetable_size 12
83 #define carl9170_a_ratetable (__carl9170_ratetable + 4)
84 #define carl9170_a_ratetable_size 8
90 #define CHAN(_freq, _idx) { \
91 .center_freq = (_freq), \
152 #define CARL9170_HT_CAP \
154 .ht_supported = true, \
155 .cap = IEEE80211_HT_CAP_MAX_AMSDU | \
156 IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \
157 IEEE80211_HT_CAP_SGI_40 | \
158 IEEE80211_HT_CAP_DSSSCCK40 | \
159 IEEE80211_HT_CAP_SM_PS, \
160 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, \
161 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
163 .rx_mask = { 0xff, 0xff, 0, 0, 0x1, 0, 0, 0, 0, 0, }, \
164 .rx_highest = cpu_to_le16(300), \
165 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
170 .channels = carl9170_2ghz_chantable,
171 .n_channels =
ARRAY_SIZE(carl9170_2ghz_chantable),
178 .channels = carl9170_5ghz_chantable,
179 .n_channels =
ARRAY_SIZE(carl9170_5ghz_chantable),
185 static void carl9170_ampdu_gc(
struct ar9170 *
ar)
195 list_del_rcu(&tid_info->
list);
207 while (!list_empty(&tid_gc)) {
212 while ((skb = __skb_dequeue(&tid_info->
queue)))
220 static void carl9170_flush(
struct ar9170 *ar,
bool drop_queued)
230 for (i = 0; i < ar->
hw->queues; i++) {
236 info = IEEE80211_SKB_CB(skb);
250 static void carl9170_flush_ba(
struct ar9170 *ar)
256 __skb_queue_head_init(&
free);
264 spin_lock(&tid_info->
lock);
265 while ((skb = __skb_dequeue(&tid_info->
queue)))
266 __skb_queue_tail(&
free, skb);
267 spin_unlock(&tid_info->
lock);
273 while ((skb = __skb_dequeue(&
free)))
277 static void carl9170_zap_queues(
struct ar9170 *ar)
282 carl9170_ampdu_gc(ar);
284 carl9170_flush_ba(ar);
285 carl9170_flush(ar,
true);
287 for (i = 0; i < ar->
hw->queues; i++) {
289 while (!skb_queue_empty(&ar->
tx_status[i])) {
308 for (i = 0; i < ar->
hw->queues; i++)
330 #define CARL9170_FILL_QUEUE(queue, ai_fs, cwmin, cwmax, _txop) \
332 queue.aifs = ai_fs; \
333 queue.cw_min = cwmin; \
334 queue.cw_max = cwmax; \
335 queue.txop = _txop; \
345 carl9170_zap_queues(ar);
364 for (i = 0; i < ar->
hw->queues; i++) {
383 if (ar->
fw.rx_filter) {
407 if (i < AR9170_CAM_MAX_USER) {
427 static void carl9170_cancel_worker(
struct ar9170 *ar)
431 #ifdef CONFIG_CARL9170_LEDS
458 carl9170_zap_queues(ar);
461 carl9170_cancel_worker(ar);
472 carl9170_cancel_worker(ar);
479 dev_err(&ar->
udev->dev,
"Failed to restart device (%d).\n", err);
481 dev_info(&ar->
udev->dev,
"device restarted successfully.\n");
484 carl9170_zap_queues(ar);
513 dev_dbg(&ar->
udev->dev,
"ignoring restart (%d)\n", r);
519 dev_err(&ar->
udev->dev,
"restart device (%d)\n", r);
540 static void carl9170_ping_work(
struct work_struct *work)
555 static int carl9170_init_interface(
struct ar9170 *ar,
568 if (modparam_nohwcrypt ||
579 static int carl9170_op_add_interface(
struct ieee80211_hw *hw,
585 int vif_id = -1, err = 0;
594 vif_id = vif_priv->
id;
605 main_vif = carl9170_get_main_vif(ar);
608 switch (main_vif->type) {
648 vif_priv->
id = vif_id;
655 if (carl9170_get_main_vif(ar) == vif) {
659 err = carl9170_init_interface(ar, vif);
670 if (ar->
fw.tx_seq_table) {
678 if (err && (vif_id >= 0)) {
683 list_del_rcu(&vif_priv->
list);
696 static void carl9170_op_remove_interface(
struct ieee80211_hw *hw,
712 main_vif = carl9170_get_main_vif(ar);
719 list_del_rcu(&vif_priv->
list);
722 if (vif == main_vif) {
726 WARN_ON(carl9170_init_interface(ar,
727 carl9170_get_main_vif(ar)));
738 carl9170_flush_cab(ar,
id);
764 static int carl9170_ps_update(
struct ar9170 *ar)
769 if (!ar->
ps.off_override)
772 if (ps != ar->
ps.state) {
777 if (ar->
ps.state && !ps) {
792 static void carl9170_ps_work(
struct work_struct *work)
802 static int carl9170_update_survey(
struct ar9170 *ar,
bool flush,
bool noise)
812 if (ar->
fw.hw_counters) {
824 static void carl9170_stat_work(
struct work_struct *work)
830 err = carl9170_update_survey(ar,
false,
true);
852 err = carl9170_ps_update(ar);
868 err = carl9170_update_survey(ar,
true,
false);
877 err = carl9170_update_survey(ar,
false,
true);
908 mchash = 1ULL << (0xff >> 2);
911 mchash |= 1ULL << (ha->
addr[5] >> 2);
917 unsigned int changed_flags,
918 unsigned int *new_flags,
921 struct ar9170 *ar = hw->priv;
953 if (!ar->
fw.ba_filter)
970 WARN_ON(carl9170_rx_filter(ar, rx_filter));
977 static void carl9170_op_bss_info_changed(
struct ieee80211_hw *hw,
989 vif_priv = (
void *) vif->drv_priv;
990 main_vif = carl9170_get_main_vif(ar);
1016 if (changed & (BSS_CHANGED_BEACON_ENABLED | BSS_CHANGED_BEACON |
1019 if (main_vif != vif) {
1047 if (main_vif != vif)
1124 if (!is_main_vif(ar, vif)) {
1169 for (i = 0; i < 64; i++)
1247 static int carl9170_op_sta_add(
struct ieee80211_hw *hw,
1256 if (sta->
ht_cap.ht_supported) {
1257 if (sta->
ht_cap.ampdu_density > 6) {
1276 static int carl9170_op_sta_remove(
struct ieee80211_hw *hw,
1283 bool cleanup =
false;
1287 sta_info->
ht_sta =
false;
1308 carl9170_ampdu_gc(ar);
1314 static int carl9170_op_conf_tx(
struct ieee80211_hw *hw,
1323 memcpy(&ar->
edcf[ar9170_qmap[queue]], param,
sizeof(*param));
1333 static void carl9170_ampdu_work(
struct work_struct *work)
1342 carl9170_ampdu_gc(ar);
1346 static int carl9170_op_ampdu_action(
struct ieee80211_hw *hw,
1377 tid_info->
hsn = tid_info->
bsn = tid_info->
snx = (*ssn);
1379 tid_info->
tid = tid;
1382 INIT_LIST_HEAD(&tid_info->
list);
1383 INIT_LIST_HEAD(&tid_info->
tmp_list);
1384 skb_queue_head_init(&tid_info->
queue);
1418 sta_info->
stats[tid].clear =
true;
1419 sta_info->
stats[tid].req =
false;
1444 #ifdef CONFIG_CARL9170_WPC
1445 static int carl9170_register_wps_button(
struct ar9170 *ar)
1447 struct input_dev *
input;
1453 input = input_allocate_device();
1457 snprintf(ar->wps.name,
sizeof(ar->wps.name),
"%s WPS Button",
1458 wiphy_name(ar->
hw->wiphy));
1460 snprintf(ar->wps.phys,
sizeof(ar->wps.phys),
1461 "ieee80211/%s/input0", wiphy_name(ar->
hw->wiphy));
1463 input->name = ar->wps.name;
1464 input->phys = ar->wps.phys;
1466 input->dev.parent = &ar->
hw->wiphy->dev;
1470 err = input_register_device(input);
1472 input_free_device(input);
1476 ar->wps.pbc =
input;
1481 #ifdef CONFIG_CARL9170_HWRNG
1482 static int carl9170_rng_get(
struct ar9170 *ar)
1485 #define RW (CARL9170_MAX_CMD_PAYLOAD_LEN / sizeof(u32))
1486 #define RB (CARL9170_MAX_CMD_PAYLOAD_LEN)
1488 static const __le32 rng_load[
RW] = {
1493 unsigned int i, off = 0, transfer,
count;
1504 RB, (
u8 *) rng_load,
1509 transfer =
min_t(
unsigned int, count,
RW);
1510 for (i = 0; i < transfer; i++)
1511 ar->rng.cache[off + i] = buf[i];
1517 ar->rng.cache_idx = 0;
1524 static int carl9170_rng_read(
struct hwrng *rng,
u32 *
data)
1530 if (ar->rng.cache_idx >=
ARRAY_SIZE(ar->rng.cache)) {
1531 ret = carl9170_rng_get(ar);
1538 *data = ar->rng.cache[ar->rng.cache_idx++];
1544 static void carl9170_unregister_hwrng(
struct ar9170 *ar)
1546 if (ar->rng.initialized) {
1548 ar->rng.initialized =
false;
1552 static int carl9170_register_hwrng(
struct ar9170 *ar)
1557 "%s_%s", KBUILD_MODNAME, wiphy_name(ar->
hw->wiphy));
1558 ar->rng.rng.name = ar->rng.name;
1559 ar->rng.rng.data_read = carl9170_rng_read;
1560 ar->rng.rng.priv = (
unsigned long)ar;
1562 if (
WARN_ON(ar->rng.initialized))
1567 dev_err(&ar->
udev->dev,
"Failed to register the random "
1568 "number generator (%d)\n", err);
1572 ar->rng.initialized =
true;
1574 err = carl9170_rng_get(ar);
1576 carl9170_unregister_hwrng(ar);
1598 err = carl9170_update_survey(ar,
false,
true);
1605 band = ar->
hw->wiphy->bands[
b];
1611 if (band->
channels[i].hw_value == idx) {
1628 if (ar->
fw.hw_counters) {
1637 static void carl9170_op_flush(
struct ieee80211_hw *hw,
bool drop)
1644 carl9170_flush_cab(ar, vid);
1646 carl9170_flush(ar, drop);
1653 struct ar9170 *ar = hw->priv;
1655 memset(stats, 0,
sizeof(*stats));
1661 static void carl9170_op_sta_notify(
struct ieee80211_hw *hw,
1681 static bool carl9170_tx_frames_pending(
struct ieee80211_hw *hw)
1689 .start = carl9170_op_start,
1690 .stop = carl9170_op_stop,
1692 .flush = carl9170_op_flush,
1693 .add_interface = carl9170_op_add_interface,
1694 .remove_interface = carl9170_op_remove_interface,
1695 .config = carl9170_op_config,
1696 .prepare_multicast = carl9170_op_prepare_multicast,
1697 .configure_filter = carl9170_op_configure_filter,
1698 .conf_tx = carl9170_op_conf_tx,
1699 .bss_info_changed = carl9170_op_bss_info_changed,
1700 .get_tsf = carl9170_op_get_tsf,
1701 .set_key = carl9170_op_set_key,
1702 .sta_add = carl9170_op_sta_add,
1703 .sta_remove = carl9170_op_sta_remove,
1704 .sta_notify = carl9170_op_sta_notify,
1705 .get_survey = carl9170_op_get_survey,
1706 .get_stats = carl9170_op_get_stats,
1707 .ampdu_action = carl9170_op_ampdu_action,
1708 .tx_frames_pending = carl9170_tx_frames_pending,
1758 for (i = 0; i < ar->
hw->queues; i++) {
1780 hw->
wiphy->interface_modes = 0;
1819 static int carl9170_read_eeprom(
struct ar9170 *ar)
1822 #define RB (sizeof(u32) * RW)
1835 for (i = 0; i <
sizeof(ar->
eeprom) / RB; i++) {
1836 for (
j = 0;
j <
RW;
j++)
1841 RB, (
u8 *) &offsets,
1842 RB, eeprom + RB * i);
1852 static int carl9170_parse_eeprom(
struct ar9170 *ar)
1855 unsigned int rx_streams, tx_streams,
tx_params = 0;
1865 if (rx_streams != tx_streams) {
1868 WARN_ON(!(tx_streams >= 1 && tx_streams <=
1871 tx_params = (tx_streams - 1) <<
1880 &carl9170_band_2GHz;
1886 &carl9170_band_5GHz;
1907 ar->
hw->channel_change_time = 135 * 1000;
1909 ar->
hw->channel_change_time = 80 * 1000;
1914 SET_IEEE80211_PERM_ADDR(ar->
hw, ar->
eeprom.mac_address);
1919 static int carl9170_reg_notifier(
struct wiphy *
wiphy,
1943 err = carl9170_read_eeprom(ar);
1947 err = carl9170_parse_eeprom(ar);
1952 carl9170_reg_notifier);
1957 carl9170_band_2GHz.
ht_cap.ht_supported =
false;
1958 carl9170_band_5GHz.
ht_cap.ht_supported =
false;
1961 for (i = 0; i < ar->
fw.vif_num; i++) {
1976 #ifdef CONFIG_CARL9170_DEBUGFS
1984 #ifdef CONFIG_CARL9170_LEDS
1985 err = carl9170_led_register(ar);
1990 #ifdef CONFIG_CARL9170_WPC
1991 err = carl9170_register_wps_button(ar);
1996 #ifdef CONFIG_CARL9170_HWRNG
1997 err = carl9170_register_hwrng(ar);
2002 dev_info(&ar->
udev->dev,
"Atheros AR9170 is registered as '%s'\n",
2003 wiphy_name(ar->
hw->wiphy));
2019 #ifdef CONFIG_CARL9170_LEDS
2020 carl9170_led_unregister(ar);
2023 #ifdef CONFIG_CARL9170_DEBUGFS
2027 #ifdef CONFIG_CARL9170_WPC
2029 input_unregister_device(ar->wps.pbc);
2034 #ifdef CONFIG_CARL9170_HWRNG
2035 carl9170_unregister_hwrng(ar);
2038 carl9170_cancel_worker(ar);