17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/slab.h>
22 #include <linux/module.h>
45 static int ath9k_btcoex_enable;
49 static int ath9k_enable_diversity;
56 #define CHAN2G(_freq, _idx) { \
57 .band = IEEE80211_BAND_2GHZ, \
58 .center_freq = (_freq), \
63 #define CHAN5G(_freq, _idx) { \
64 .band = IEEE80211_BAND_5GHZ, \
65 .center_freq = (_freq), \
127 #define SHPCHECK(__hw_rate, __flags) \
128 ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate | 0x04 ) : 0)
130 #define RATE(_bitrate, _hw_rate, _flags) { \
131 .bitrate = (_bitrate), \
133 .hw_value = (_hw_rate), \
134 .hw_value_short = (SHPCHECK(_hw_rate, _flags)) \
152 #ifdef CONFIG_MAC80211_LEDS
154 { .
throughput = 0 * 1024, .blink_time = 334 },
155 { .throughput = 1 * 1024, .blink_time = 260 },
156 { .throughput = 5 * 1024, .blink_time = 220 },
157 { .throughput = 10 * 1024, .blink_time = 190 },
158 { .throughput = 20 * 1024, .blink_time = 170 },
159 { .throughput = 50 * 1024, .blink_time = 150 },
160 { .throughput = 70 * 1024, .blink_time = 130 },
161 { .throughput = 100 * 1024, .blink_time = 110 },
162 { .throughput = 200 * 1024, .blink_time = 80 },
163 { .throughput = 300 * 1024, .blink_time = 50 },
167 static void ath9k_deinit_softc(
struct ath_softc *
sc);
175 static void ath9k_iowrite32(
void *hw_priv,
u32 val,
u32 reg_offset)
190 static unsigned int ath9k_ioread32(
void *hw_priv,
u32 reg_offset)
193 struct ath_common *common = ath9k_hw_common(ah);
207 static unsigned int __ath9k_reg_rmw(
struct ath_softc *sc,
u32 reg_offset,
220 static unsigned int ath9k_reg_rmw(
void *hw_priv,
u32 reg_offset,
u32 set,
u32 clr)
223 struct ath_common *common = ath9k_hw_common(ah);
230 val = __ath9k_reg_rmw(sc, reg_offset,
set, clr);
233 val = __ath9k_reg_rmw(sc, reg_offset,
set, clr);
242 static void setup_ht_cap(
struct ath_softc *sc,
246 struct ath_common *common = ath9k_hw_common(ah);
247 u8 tx_streams, rx_streams;
275 if (max_streams >= 2)
286 tx_streams, rx_streams);
288 if (tx_streams != rx_streams) {
290 ht_info->
mcs.tx_params |= ((tx_streams - 1) <<
294 for (i = 0; i < rx_streams; i++)
295 ht_info->
mcs.rx_mask[i] = 0xff;
300 static int ath9k_reg_notifier(
struct wiphy *
wiphy,
316 sc->
curtxpow = ath9k_hw_regulatory(ah)->power_limit;
330 int nbuf,
int ndesc,
bool is_tx)
335 int i, bsize,
error, desc_len;
340 INIT_LIST_HEAD(head);
343 desc_len = sc->
sc_ah->caps.tx_desc_len;
348 if ((desc_len % 4) != 0) {
349 ath_err(common,
"ath_desc not DWORD aligned\n");
350 BUG_ON((desc_len % 4) != 0);
367 while (ndesc_skipped) {
368 dma_len = ndesc_skipped * desc_len;
383 ath_dbg(common,
CONFIG,
"%s DMA map: %p (%u) -> %llx (%u)\n",
388 bsize =
sizeof(
struct ath_buf) * nbuf;
396 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len *
ndesc)) {
398 bf->bf_daddr =
DS2PHYS(dd, ds);
400 if (!(sc->
sc_ah->caps.hw_caps &
412 ds += (desc_len *
ndesc);
414 bf->bf_daddr =
DS2PHYS(dd, ds);
424 memset(dd, 0,
sizeof(*dd));
428 static int ath9k_init_queues(
struct ath_softc *sc)
440 sc->
tx.txq_map[
i]->mac80211_qnum =
i;
446 static int ath9k_init_channels_rates(
struct ath_softc *sc)
455 channels =
kmemdup(ath9k_2ghz_chantable,
470 channels =
kmemdup(ath9k_5ghz_chantable,
483 ath9k_legacy_rates + 4;
490 static void ath9k_init_misc(
struct ath_softc *sc)
524 ah->
reg_ops.read = ath9k_ioread32;
525 ah->
reg_ops.write = ath9k_iowrite32;
526 ah->
reg_ops.rmw = ath9k_reg_rmw;
534 sc->
sc_ah->led_pin = -1;
544 common = ath9k_hw_common(ah);
566 #ifdef CONFIG_ATH9K_DEBUGFS
568 INIT_LIST_HEAD(&sc->nodes);
570 #ifdef CONFIG_ATH9K_MAC_DEBUG
587 ath_read_cachesize(common, &csz);
598 ret = ath9k_init_queues(sc);
602 ret = ath9k_init_btcoex(sc);
606 ret = ath9k_init_channels_rates(sc);
612 ath_fill_led_pin(sc);
614 if (common->
bus_ops->aspm_init)
615 common->
bus_ops->aspm_init(common);
633 static void ath9k_init_band_txpower(
struct ath_softc *sc,
int band)
640 sband = &sc->
sbands[band];
649 static void ath9k_init_txpower_limits(
struct ath_softc *sc)
678 #ifdef CONFIG_MAC80211_MESH
688 .max_interfaces = 2048,
689 .num_different_channels = 1,
695 struct ath_common *common = ath9k_hw_common(ah);
711 hw->
wiphy->interface_modes =
720 hw->
wiphy->iface_combinations = &if_comb;
721 hw->
wiphy->n_iface_combinations = 1;
730 #ifdef CONFIG_PM_SLEEP
733 device_can_wakeup(sc->
dev)) {
738 hw->
wiphy->wowlan.pattern_min_len = 1;
756 hw->
wiphy->available_antennas_rx =
BIT(ah->
caps.max_rxchains) - 1;
757 hw->
wiphy->available_antennas_tx =
BIT(ah->
caps.max_txchains) - 1;
761 hw->
wiphy->available_antennas_rx =
BIT(0) |
BIT(1);
766 #ifdef CONFIG_ATH9K_RATE_CONTROL
779 SET_IEEE80211_PERM_ADDR(hw, common->
macaddr);
792 error = ath9k_init_softc(devid, sc, bus_ops);
797 common = ath9k_hw_common(ah);
818 ath9k_init_txpower_limits(sc);
820 #ifdef CONFIG_MAC80211_LEDS
822 sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->
hw,
834 ath_err(common,
"Unable to create debugfs files\n");
859 ath9k_deinit_softc(sc);
868 static void ath9k_deinit_softc(
struct ath_softc *sc)
878 ath9k_deinit_btcoex(sc);
906 ath9k_deinit_softc(sc);
916 INIT_LIST_HEAD(head);
918 memset(dd, 0,
sizeof(*dd));
925 static int __init ath9k_init(
void)
932 pr_err(
"Unable to register rate control algorithm: %d\n",
939 pr_err(
"No PCI devices found, driver not installed\n");
941 goto err_rate_unregister;
962 static void __exit ath9k_exit(
void)