17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 static int ath9k_htc_btcoex_enable;
37 #define CHAN2G(_freq, _idx) { \
38 .center_freq = (_freq), \
43 #define CHAN5G(_freq, _idx) { \
44 .band = IEEE80211_BAND_5GHZ, \
45 .center_freq = (_freq), \
99 #define SHPCHECK(__hw_rate, __flags) \
100 ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate | 0x04) : 0)
102 #define RATE(_bitrate, _hw_rate, _flags) { \
103 .bitrate = (_bitrate), \
105 .hw_value = (_hw_rate), \
106 .hw_value_short = (SHPCHECK(_hw_rate, _flags)) \
124 #ifdef CONFIG_MAC80211_LEDS
126 { .
throughput = 0 * 1024, .blink_time = 334 },
127 { .throughput = 1 * 1024, .blink_time = 260 },
128 { .throughput = 5 * 1024, .blink_time = 220 },
129 { .throughput = 10 * 1024, .blink_time = 190 },
130 { .throughput = 20 * 1024, .blink_time = 170 },
131 { .throughput = 50 * 1024, .blink_time = 150 },
132 { .throughput = 70 * 1024, .blink_time = 130 },
133 { .throughput = 100 * 1024, .blink_time = 110 },
134 { .throughput = 200 * 1024, .blink_time = 80 },
135 { .throughput = 300 * 1024, .blink_time = 50 },
151 dev_err(priv->
dev,
"ath9k_htc: Target is unresponsive\n");
172 ath9k_deinit_leds(priv);
176 ath9k_deinit_priv(priv);
179 static inline int ath9k_htc_connect_svc(
struct ath9k_htc_priv *priv,
194 req.ep_callbacks.tx =
tx;
265 priv->
htc->credits = 45;
267 priv->
htc->credits = 33;
273 dev_info(priv->
dev,
"ath9k_htc: HTC initialized with %d credits\n",
279 dev_err(priv->
dev,
"ath9k_htc: Unable to initialize HTC services\n");
283 static int ath9k_reg_notifier(
struct wiphy *
wiphy,
290 ath9k_hw_regulatory(priv->
ah));
293 static unsigned int ath9k_regread(
void *hw_priv,
u32 reg_offset)
303 (
u8 *) &val,
sizeof(val),
306 ath_dbg(common, WMI,
"REGISTER READ FAILED: (0x%04x, %d)\n",
314 static void ath9k_multi_regread(
void *hw_priv,
u32 *
addr,
318 struct ath_common *common = ath9k_hw_common(ah);
329 (
u8 *)tmpaddr ,
sizeof(
u32) * count,
330 (
u8 *)tmpval,
sizeof(
u32) * count,
334 "Multiple REGISTER READ FAILED (count: %d)\n", count);
337 for (i = 0; i <
count; i++) {
342 static void ath9k_regwrite_single(
void *hw_priv,
u32 val,
u32 reg_offset)
345 struct ath_common *common = ath9k_hw_common(ah);
355 (
u8 *) &val,
sizeof(val),
358 ath_dbg(common, WMI,
"REGISTER WRITE FAILED:(0x%04x, %d)\n",
363 static void ath9k_regwrite_buffer(
void *hw_priv,
u32 val,
u32 reg_offset)
366 struct ath_common *common = ath9k_hw_common(ah);
374 priv->
wmi->multi_write[priv->
wmi->multi_write_idx].reg =
376 priv->
wmi->multi_write[priv->
wmi->multi_write_idx].val =
379 priv->
wmi->multi_write_idx++;
384 (
u8 *) &priv->
wmi->multi_write,
386 (
u8 *) &rsp_status,
sizeof(rsp_status),
390 "REGISTER WRITE FAILED, multi len: %d\n",
391 priv->
wmi->multi_write_idx);
393 priv->
wmi->multi_write_idx = 0;
399 static void ath9k_regwrite(
void *hw_priv,
u32 val,
u32 reg_offset)
402 struct ath_common *common = ath9k_hw_common(ah);
406 ath9k_regwrite_buffer(hw_priv, val, reg_offset);
408 ath9k_regwrite_single(hw_priv, val, reg_offset);
411 static void ath9k_enable_regwrite_buffer(
void *hw_priv)
414 struct ath_common *common = ath9k_hw_common(ah);
420 static void ath9k_regwrite_flush(
void *hw_priv)
423 struct ath_common *common = ath9k_hw_common(ah);
432 if (priv->
wmi->multi_write_idx) {
434 (
u8 *) &priv->
wmi->multi_write,
436 (
u8 *) &rsp_status,
sizeof(rsp_status),
440 "REGISTER WRITE FAILED, multi len: %d\n",
441 priv->
wmi->multi_write_idx);
443 priv->
wmi->multi_write_idx = 0;
449 static u32 ath9k_reg_rmw(
void *hw_priv,
u32 reg_offset,
u32 set,
u32 clr)
453 val = ath9k_regread(hw_priv, reg_offset);
456 ath9k_regwrite(hw_priv, val, reg_offset);
460 static void ath_usb_read_cachesize(
struct ath_common *common,
int *csz)
484 static const struct ath_bus_ops ath9k_usb_bus_ops = {
486 .read_cachesize = ath_usb_read_cachesize,
487 .eeprom_read = ath_usb_eeprom_read,
494 u8 tx_streams, rx_streams;
518 tx_streams, rx_streams);
520 if (tx_streams != rx_streams) {
522 ht_info->
mcs.tx_params |= ((tx_streams - 1) <<
526 for (i = 0; i < rx_streams; i++)
527 ht_info->
mcs.rx_mask[i] = 0xff;
542 ath_err(common,
"Unable to setup BEACON xmit queue\n");
547 if (priv->
cabq == -1) {
548 ath_err(common,
"Unable to setup CAB xmit queue\n");
553 ath_err(common,
"Unable to setup xmit queue for BE traffic\n");
558 ath_err(common,
"Unable to setup xmit queue for BK traffic\n");
562 ath_err(common,
"Unable to setup xmit queue for VI traffic\n");
566 ath_err(common,
"Unable to setup xmit queue for VO traffic\n");
576 static void ath9k_init_channels_rates(
struct ath9k_htc_priv *priv)
595 ath9k_legacy_rates + 4;
616 int i, ret = 0, csz = 0;
627 ah->
reg_ops.read = ath9k_regread;
628 ah->
reg_ops.multi_read = ath9k_multi_regread;
629 ah->
reg_ops.write = ath9k_regwrite;
630 ah->
reg_ops.enable_write_buffer = ath9k_enable_regwrite_buffer;
631 ah->
reg_ops.write_flush = ath9k_regwrite_flush;
632 ah->
reg_ops.rmw = ath9k_reg_rmw;
635 common = ath9k_hw_common(ah);
637 common->
bus_ops = &ath9k_usb_bus_ops;
639 common->
hw = priv->
hw;
649 (
unsigned long)priv);
651 (
unsigned long)priv);
656 (
unsigned long)priv);
662 ath_read_cachesize(common, &csz);
668 "Unable to initialize hardware; initialization status: %d\n",
673 ret = ath9k_init_queues(priv);
681 ath9k_init_channels_rates(priv);
682 ath9k_init_misc(priv);
683 ath9k_htc_init_btcoex(priv, product);
712 hw->
wiphy->interface_modes =
751 SET_IEEE80211_PERM_ADDR(hw, common->
macaddr);
754 static int ath9k_init_firmware_version(
struct ath9k_htc_priv *priv)
773 dev_info(priv->
dev,
"ath9k_htc: FW Version: %d.%d\n",
783 dev_err(priv->
dev,
"ath9k_htc: Please upgrade to FW version %d.%d\n",
792 u16 devid,
char *product,
u32 drv_info)
802 error = ath9k_init_priv(priv, devid, product, drv_info);
807 common = ath9k_hw_common(ah);
810 error = ath9k_init_firmware_version(priv);
832 #ifdef CONFIG_MAC80211_LEDS
834 priv->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(priv->
hw,
853 ath_err(common,
"Unable to create debugfs files\n");
858 "WMI:%d, BCN:%d, CAB:%d, UAPSD:%d, MGMT:%d, BE:%d, BK:%d, VI:%d, VO:%d\n",
872 ath9k_init_leds(priv);
888 ath9k_deinit_priv(priv);
894 u16 devid,
char *product,
u32 drv_info)
906 priv->
htc = htc_handle;
909 SET_IEEE80211_DEV(hw, priv->
dev);
911 ret = ath9k_htc_wait_for_target(priv);
921 ret = ath9k_init_htc_services(priv, devid, drv_info);
954 void ath9k_htc_suspend(
struct htc_target *htc_handle)
959 int ath9k_htc_resume(
struct htc_target *htc_handle)
964 ret = ath9k_htc_wait_for_target(priv);
968 ret = ath9k_init_htc_services(priv, priv->
ah->hw_version.devid,
969 priv->
ah->hw_version.usbdev);
974 static int __init ath9k_htc_init(
void)
977 pr_err(
"No USB devices found, driver not installed\n");
985 static void __exit ath9k_htc_exit(
void)