1 /* SPDX-License-Identifier: ISC */
3 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
9 #include <linux/kernel.h>
11 #include <linux/spinlock.h>
12 #include <linux/skbuff.h>
13 #include <linux/leds.h>
14 #include <linux/usb.h>
15 #include <linux/average.h>
16 #include <net/mac80211.h>
20 #define MT_MCU_RING_SIZE 32
21 #define MT_RX_BUF_SIZE 2048
22 #define MT_SKB_HEAD_LEN 128
24 #define MT_MAX_NON_AQL_PKT 16
25 #define MT_TXQ_FREE_THR 32
31 struct mt76_reg_pair {
43 u32 (*rr)(struct mt76_dev *dev, u32 offset);
44 void (*wr)(struct mt76_dev *dev, u32 offset, u32 val);
45 u32 (*rmw)(struct mt76_dev *dev, u32 offset, u32 mask, u32 val);
46 void (*write_copy)(struct mt76_dev *dev, u32 offset, const void *data,
48 void (*read_copy)(struct mt76_dev *dev, u32 offset, void *data,
50 int (*wr_rp)(struct mt76_dev *dev, u32 base,
51 const struct mt76_reg_pair *rp, int len);
52 int (*rd_rp)(struct mt76_dev *dev, u32 base,
53 struct mt76_reg_pair *rp, int len);
54 enum mt76_bus_type type;
57 #define mt76_is_usb(dev) ((dev)->bus->type == MT76_BUS_USB)
58 #define mt76_is_mmio(dev) ((dev)->bus->type == MT76_BUS_MMIO)
59 #define mt76_is_sdio(dev) ((dev)->bus->type == MT76_BUS_SDIO)
62 MT_TXQ_VO = IEEE80211_AC_VO,
63 MT_TXQ_VI = IEEE80211_AC_VI,
64 MT_TXQ_BE = IEEE80211_AC_BE,
65 MT_TXQ_BK = IEEE80211_AC_BK,
88 struct mt76_queue_buf {
95 struct mt76_queue_buf buf[32];
101 struct mt76_queue_entry {
107 struct mt76_txwi_cache *txwi;
119 struct mt76_queue_regs {
124 } __packed __aligned(4);
127 struct mt76_queue_regs __iomem *regs;
130 spinlock_t cleanup_lock;
131 struct mt76_queue_entry *entry;
132 struct mt76_desc *desc;
148 struct sk_buff *rx_head;
149 struct page_frag_cache rx_page;
152 struct mt76_mcu_ops {
156 int (*mcu_send_msg)(struct mt76_dev *dev, int cmd, const void *data,
157 int len, bool wait_resp);
158 int (*mcu_skb_send_msg)(struct mt76_dev *dev, struct sk_buff *skb,
160 int (*mcu_parse_response)(struct mt76_dev *dev, int cmd,
161 struct sk_buff *skb, int seq);
162 u32 (*mcu_rr)(struct mt76_dev *dev, u32 offset);
163 void (*mcu_wr)(struct mt76_dev *dev, u32 offset, u32 val);
164 int (*mcu_wr_rp)(struct mt76_dev *dev, u32 base,
165 const struct mt76_reg_pair *rp, int len);
166 int (*mcu_rd_rp)(struct mt76_dev *dev, u32 base,
167 struct mt76_reg_pair *rp, int len);
168 int (*mcu_restart)(struct mt76_dev *dev);
171 struct mt76_queue_ops {
172 int (*init)(struct mt76_dev *dev);
174 int (*alloc)(struct mt76_dev *dev, struct mt76_queue *q,
175 int idx, int n_desc, int bufsize,
178 int (*tx_queue_skb)(struct mt76_dev *dev, struct mt76_queue *q,
179 struct sk_buff *skb, struct mt76_wcid *wcid,
180 struct ieee80211_sta *sta);
182 int (*tx_queue_skb_raw)(struct mt76_dev *dev, struct mt76_queue *q,
183 struct sk_buff *skb, u32 tx_info);
185 void *(*dequeue)(struct mt76_dev *dev, struct mt76_queue *q, bool flush,
186 int *len, u32 *info, bool *more);
188 void (*rx_reset)(struct mt76_dev *dev, enum mt76_rxq_id qid);
190 void (*tx_cleanup)(struct mt76_dev *dev, struct mt76_queue *q,
193 void (*kick)(struct mt76_dev *dev, struct mt76_queue *q);
196 enum mt76_wcid_flags {
197 MT_WCID_FLAG_CHECK_PS,
202 #define MT76_N_WCIDS 288
204 /* stored in ieee80211_tx_info::hw_queue */
205 #define MT_TX_HW_QUEUE_EXT_PHY BIT(3)
207 DECLARE_EWMA(signal, 10, 8);
209 #define MT_WCID_TX_INFO_RATE GENMASK(15, 0)
210 #define MT_WCID_TX_INFO_NSS GENMASK(17, 16)
211 #define MT_WCID_TX_INFO_TXPWR_ADJ GENMASK(25, 18)
212 #define MT_WCID_TX_INFO_SET BIT(31)
215 struct mt76_rx_tid __rcu *aggr[IEEE80211_NUM_TIDS];
217 atomic_t non_aql_packets;
220 struct ewma_signal rssi;
231 u8 rx_key_pn[IEEE80211_NUM_TIDS][6];
241 struct mt76_wcid *wcid;
248 struct mt76_txwi_cache {
249 struct list_head list;
256 struct rcu_head rcu_head;
258 struct mt76_dev *dev;
261 struct delayed_work reorder_work;
269 u8 started:1, stopped:1, timer_pending:1;
271 struct sk_buff *reorder_buf[];
274 #define MT_TX_CB_DMA_DONE BIT(0)
275 #define MT_TX_CB_TXS_DONE BIT(1)
276 #define MT_TX_CB_TXS_FAILED BIT(2)
278 #define MT_PACKET_ID_MASK GENMASK(6, 0)
279 #define MT_PACKET_ID_NO_ACK 0
280 #define MT_PACKET_ID_NO_SKB 1
281 #define MT_PACKET_ID_FIRST 2
282 #define MT_PACKET_ID_HAS_RATE BIT(7)
284 #define MT_TX_STATUS_SKB_TIMEOUT HZ
287 unsigned long jiffies;
294 MT76_STATE_INITIALIZED,
296 MT76_STATE_MCU_RUNNING,
299 MT76_HW_SCHED_SCANNING,
305 MT76_STATE_POWER_OFF,
316 #define MT_DRV_TXWI_NO_FREE BIT(0)
317 #define MT_DRV_TX_ALIGNED4_SKBS BIT(1)
318 #define MT_DRV_SW_RX_AIRTIME BIT(2)
319 #define MT_DRV_RX_DMA_HDR BIT(3)
320 #define MT_DRV_HW_MGMT_TXQ BIT(4)
321 #define MT_DRV_AMSDU_OFFLOAD BIT(5)
323 struct mt76_driver_ops {
328 void (*update_survey)(struct mt76_dev *dev);
330 int (*tx_prepare_skb)(struct mt76_dev *dev, void *txwi_ptr,
331 enum mt76_txq_id qid, struct mt76_wcid *wcid,
332 struct ieee80211_sta *sta,
333 struct mt76_tx_info *tx_info);
335 void (*tx_complete_skb)(struct mt76_dev *dev,
336 struct mt76_queue_entry *e);
338 bool (*tx_status_data)(struct mt76_dev *dev, u8 *update);
340 void (*rx_skb)(struct mt76_dev *dev, enum mt76_rxq_id q,
341 struct sk_buff *skb);
343 void (*rx_poll_complete)(struct mt76_dev *dev, enum mt76_rxq_id q);
345 void (*sta_ps)(struct mt76_dev *dev, struct ieee80211_sta *sta,
348 int (*sta_add)(struct mt76_dev *dev, struct ieee80211_vif *vif,
349 struct ieee80211_sta *sta);
351 void (*sta_assoc)(struct mt76_dev *dev, struct ieee80211_vif *vif,
352 struct ieee80211_sta *sta);
354 void (*sta_remove)(struct mt76_dev *dev, struct ieee80211_vif *vif,
355 struct ieee80211_sta *sta);
358 struct mt76_channel_state {
369 struct ieee80211_supported_band sband;
370 struct mt76_channel_state *chan;
373 struct mt76_rate_power {
387 #define MT_VEND_TYPE_EEPROM BIT(31)
388 #define MT_VEND_TYPE_CFG BIT(30)
389 #define MT_VEND_TYPE_MASK (MT_VEND_TYPE_EEPROM | MT_VEND_TYPE_CFG)
391 #define MT_VEND_ADDR(type, n) (MT_VEND_TYPE_##type | (n))
393 MT_VEND_DEV_MODE = 0x1,
395 MT_VEND_POWER_ON = 0x4,
396 MT_VEND_MULTI_WRITE = 0x6,
397 MT_VEND_MULTI_READ = 0x7,
398 MT_VEND_READ_EEPROM = 0x9,
399 MT_VEND_WRITE_FCE = 0x42,
400 MT_VEND_WRITE_CFG = 0x46,
401 MT_VEND_READ_CFG = 0x47,
402 MT_VEND_READ_EXT = 0x63,
403 MT_VEND_WRITE_EXT = 0x66,
404 MT_VEND_FEATURE_SET = 0x91,
414 MT_EP_OUT_INBAND_CMD,
428 struct sk_buff_head res_q;
429 wait_queue_head_t wait;
432 #define MT_TX_SG_MAX_SIZE 8
433 #define MT_RX_SG_MAX_SIZE 4
434 #define MT_NUM_TX_ENTRIES 256
435 #define MT_NUM_RX_ENTRIES 128
436 #define MCU_RESP_URB_SIZE 1024
438 struct mutex usb_ctrl_mtx;
442 struct mt76_worker status_worker;
443 struct mt76_worker rx_worker;
445 struct work_struct stat_work;
447 u8 out_ep[__MT_EP_OUT_MAX];
448 u8 in_ep[__MT_EP_IN_MAX];
454 struct mt76_reg_pair *rp;
461 #define MT76S_XMIT_BUF_SZ (16 * PAGE_SIZE)
463 struct mt76_worker txrx_worker;
464 struct mt76_worker status_worker;
465 struct mt76_worker net_worker;
467 struct work_struct stat_work;
469 u8 *xmit_buf[IEEE80211_NUM_ACS + 2];
471 struct sdio_func *func;
488 struct mt76_rx_status {
490 struct mt76_wcid *wcid;
494 unsigned long reorder_time;
508 u8 encoding:2, bw:3, he_ru:3;
509 u8 he_gi:2, he_dcm:1;
515 s8 chain_signal[IEEE80211_MAX_CHAINS];
518 struct mt76_testmode_ops {
519 int (*set_state)(struct mt76_phy *phy, enum mt76_testmode_state state);
520 int (*set_params)(struct mt76_phy *phy, struct nlattr **tb,
521 enum mt76_testmode_state new_state);
522 int (*dump_stats)(struct mt76_phy *phy, struct sk_buff *msg);
525 struct mt76_testmode_data {
526 enum mt76_testmode_state state;
528 u32 param_set[DIV_ROUND_UP(NUM_MT76_TM_ATTRS, 32)];
529 struct sk_buff *tx_skb;
559 u64 packets[__MT_RXQ_MAX];
560 u64 fcs_error[__MT_RXQ_MAX];
573 struct ieee80211_hw *hw;
574 struct mt76_dev *dev;
579 struct mt76_queue *q_tx[__MT_TXQ_MAX];
581 struct cfg80211_chan_def chandef;
582 struct ieee80211_channel *main_chan;
584 struct mt76_channel_state *chan_state;
587 struct mt76_hw_cap cap;
588 struct mt76_sband sband_2g;
589 struct mt76_sband sband_5g;
591 u8 macaddr[ETH_ALEN];
597 #ifdef CONFIG_NL80211_TESTMODE
598 struct mt76_testmode_data test;
601 struct delayed_work mac_work;
606 struct mt76_phy phy; /* must be first */
608 struct mt76_phy *phy2;
610 struct ieee80211_hw *hw;
617 struct mt76_rx_status rx_ampdu_status;
623 const struct mt76_bus_ops *bus;
624 const struct mt76_driver_ops *drv;
625 const struct mt76_mcu_ops *mcu_ops;
630 struct net_device napi_dev;
632 struct napi_struct napi[__MT_RXQ_MAX];
633 struct sk_buff_head rx_skb[__MT_RXQ_MAX];
635 struct list_head txwi_cache;
636 struct mt76_queue *q_mcu[__MT_MCUQ_MAX];
637 struct mt76_queue q_rx[__MT_RXQ_MAX];
638 const struct mt76_queue_ops *queue_ops;
641 struct mt76_worker tx_worker;
642 struct napi_struct tx_napi;
644 wait_queue_head_t tx_wait;
645 struct sk_buff_head status_list;
647 u32 wcid_mask[DIV_ROUND_UP(MT76_N_WCIDS, 32)];
648 u32 wcid_phy_mask[DIV_ROUND_UP(MT76_N_WCIDS, 32)];
652 struct mt76_wcid global_wcid;
653 struct mt76_wcid __rcu *wcid[MT76_N_WCIDS];
659 struct tasklet_struct pre_tbtt_tasklet;
663 struct debugfs_blob_wrapper eeprom;
664 struct debugfs_blob_wrapper otp;
666 struct mt76_rate_power rate_power;
669 enum nl80211_dfs_regions region;
673 struct led_classdev led_cdev;
682 #ifdef CONFIG_NL80211_TESTMODE
683 const struct mt76_testmode_ops *test_ops;
689 struct workqueue_struct *wq;
692 struct mt76_mmio mmio;
694 struct mt76_sdio sdio;
704 MT_PHY_TYPE_HE_SU = 8,
705 MT_PHY_TYPE_HE_EXT_SU,
710 #define __mt76_rr(dev, ...) (dev)->bus->rr((dev), __VA_ARGS__)
711 #define __mt76_wr(dev, ...) (dev)->bus->wr((dev), __VA_ARGS__)
712 #define __mt76_rmw(dev, ...) (dev)->bus->rmw((dev), __VA_ARGS__)
713 #define __mt76_wr_copy(dev, ...) (dev)->bus->write_copy((dev), __VA_ARGS__)
714 #define __mt76_rr_copy(dev, ...) (dev)->bus->read_copy((dev), __VA_ARGS__)
716 #define __mt76_set(dev, offset, val) __mt76_rmw(dev, offset, 0, val)
717 #define __mt76_clear(dev, offset, val) __mt76_rmw(dev, offset, val, 0)
719 #define mt76_rr(dev, ...) (dev)->mt76.bus->rr(&((dev)->mt76), __VA_ARGS__)
720 #define mt76_wr(dev, ...) (dev)->mt76.bus->wr(&((dev)->mt76), __VA_ARGS__)
721 #define mt76_rmw(dev, ...) (dev)->mt76.bus->rmw(&((dev)->mt76), __VA_ARGS__)
722 #define mt76_wr_copy(dev, ...) (dev)->mt76.bus->write_copy(&((dev)->mt76), __VA_ARGS__)
723 #define mt76_rr_copy(dev, ...) (dev)->mt76.bus->read_copy(&((dev)->mt76), __VA_ARGS__)
724 #define mt76_wr_rp(dev, ...) (dev)->mt76.bus->wr_rp(&((dev)->mt76), __VA_ARGS__)
725 #define mt76_rd_rp(dev, ...) (dev)->mt76.bus->rd_rp(&((dev)->mt76), __VA_ARGS__)
728 #define mt76_mcu_restart(dev, ...) (dev)->mt76.mcu_ops->mcu_restart(&((dev)->mt76))
729 #define __mt76_mcu_restart(dev, ...) (dev)->mcu_ops->mcu_restart((dev))
731 #define mt76_set(dev, offset, val) mt76_rmw(dev, offset, 0, val)
732 #define mt76_clear(dev, offset, val) mt76_rmw(dev, offset, val, 0)
734 #define mt76_get_field(_dev, _reg, _field) \
735 FIELD_GET(_field, mt76_rr(dev, _reg))
737 #define mt76_rmw_field(_dev, _reg, _field, _val) \
738 mt76_rmw(_dev, _reg, _field, FIELD_PREP(_field, _val))
740 #define __mt76_rmw_field(_dev, _reg, _field, _val) \
741 __mt76_rmw(_dev, _reg, _field, FIELD_PREP(_field, _val))
743 #define mt76_hw(dev) (dev)->mphy.hw
745 static inline struct ieee80211_hw *
746 mt76_wcid_hw(struct mt76_dev *dev, u16 wcid)
748 if (wcid <= MT76_N_WCIDS &&
749 mt76_wcid_mask_test(dev->wcid_phy_mask, wcid))
750 return dev->phy2->hw;
755 bool __mt76_poll(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
758 #define mt76_poll(dev, ...) __mt76_poll(&((dev)->mt76), __VA_ARGS__)
760 bool __mt76_poll_msec(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
763 #define mt76_poll_msec(dev, ...) __mt76_poll_msec(&((dev)->mt76), __VA_ARGS__)
765 void mt76_mmio_init(struct mt76_dev *dev, void __iomem *regs);
766 void mt76_pci_disable_aspm(struct pci_dev *pdev);
768 static inline u16 mt76_chip(struct mt76_dev *dev)
770 return dev->rev >> 16;
773 static inline u16 mt76_rev(struct mt76_dev *dev)
775 return dev->rev & 0xffff;
778 #define mt76xx_chip(dev) mt76_chip(&((dev)->mt76))
779 #define mt76xx_rev(dev) mt76_rev(&((dev)->mt76))
781 #define mt76_init_queues(dev) (dev)->mt76.queue_ops->init(&((dev)->mt76))
782 #define mt76_queue_alloc(dev, ...) (dev)->mt76.queue_ops->alloc(&((dev)->mt76), __VA_ARGS__)
783 #define mt76_tx_queue_skb_raw(dev, ...) (dev)->mt76.queue_ops->tx_queue_skb_raw(&((dev)->mt76), __VA_ARGS__)
784 #define mt76_tx_queue_skb(dev, ...) (dev)->mt76.queue_ops->tx_queue_skb(&((dev)->mt76), __VA_ARGS__)
785 #define mt76_queue_rx_reset(dev, ...) (dev)->mt76.queue_ops->rx_reset(&((dev)->mt76), __VA_ARGS__)
786 #define mt76_queue_tx_cleanup(dev, ...) (dev)->mt76.queue_ops->tx_cleanup(&((dev)->mt76), __VA_ARGS__)
787 #define mt76_queue_kick(dev, ...) (dev)->mt76.queue_ops->kick(&((dev)->mt76), __VA_ARGS__)
789 #define mt76_for_each_q_rx(dev, i) \
790 for (i = 0; i < ARRAY_SIZE((dev)->q_rx) && \
791 (dev)->q_rx[i].ndesc; i++)
793 struct mt76_dev *mt76_alloc_device(struct device *pdev, unsigned int size,
794 const struct ieee80211_ops *ops,
795 const struct mt76_driver_ops *drv_ops);
796 int mt76_register_device(struct mt76_dev *dev, bool vht,
797 struct ieee80211_rate *rates, int n_rates);
798 void mt76_unregister_device(struct mt76_dev *dev);
799 void mt76_free_device(struct mt76_dev *dev);
800 void mt76_unregister_phy(struct mt76_phy *phy);
802 struct mt76_phy *mt76_alloc_phy(struct mt76_dev *dev, unsigned int size,
803 const struct ieee80211_ops *ops);
804 int mt76_register_phy(struct mt76_phy *phy, bool vht,
805 struct ieee80211_rate *rates, int n_rates);
807 struct dentry *mt76_register_debugfs(struct mt76_dev *dev);
808 int mt76_queues_read(struct seq_file *s, void *data);
809 void mt76_seq_puts_array(struct seq_file *file, const char *str,
812 int mt76_eeprom_init(struct mt76_dev *dev, int len);
813 void mt76_eeprom_override(struct mt76_phy *phy);
816 mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc,
818 static inline int mt76_init_tx_queue(struct mt76_phy *phy, int qid, int idx,
819 int n_desc, int ring_base)
821 struct mt76_queue *q;
823 q = mt76_init_queue(phy->dev, qid, idx, n_desc, ring_base);
833 static inline int mt76_init_mcu_queue(struct mt76_dev *dev, int qid, int idx,
834 int n_desc, int ring_base)
836 struct mt76_queue *q;
838 q = mt76_init_queue(dev, qid, idx, n_desc, ring_base);
842 q->qid = __MT_TXQ_MAX + qid;
848 static inline struct mt76_phy *
849 mt76_dev_phy(struct mt76_dev *dev, bool phy_ext)
851 if (phy_ext && dev->phy2)
856 static inline struct ieee80211_hw *
857 mt76_phy_hw(struct mt76_dev *dev, bool phy_ext)
859 return mt76_dev_phy(dev, phy_ext)->hw;
863 mt76_get_txwi_ptr(struct mt76_dev *dev, struct mt76_txwi_cache *t)
865 return (u8 *)t - dev->drv->txwi_size;
868 /* increment with wrap-around */
869 static inline int mt76_incr(int val, int size)
871 return (val + 1) & (size - 1);
874 /* decrement with wrap-around */
875 static inline int mt76_decr(int val, int size)
877 return (val - 1) & (size - 1);
880 u8 mt76_ac_to_hwq(u8 ac);
882 static inline struct ieee80211_txq *
883 mtxq_to_txq(struct mt76_txq *mtxq)
887 return container_of(ptr, struct ieee80211_txq, drv_priv);
890 static inline struct ieee80211_sta *
891 wcid_to_sta(struct mt76_wcid *wcid)
895 if (!wcid || !wcid->sta)
898 return container_of(ptr, struct ieee80211_sta, drv_priv);
901 static inline struct mt76_tx_cb *mt76_tx_skb_cb(struct sk_buff *skb)
903 BUILD_BUG_ON(sizeof(struct mt76_tx_cb) >
904 sizeof(IEEE80211_SKB_CB(skb)->status.status_driver_data));
905 return ((void *)IEEE80211_SKB_CB(skb)->status.status_driver_data);
908 static inline void *mt76_skb_get_hdr(struct sk_buff *skb)
910 struct mt76_rx_status mstat;
911 u8 *data = skb->data;
913 /* Alignment concerns */
914 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) % 4);
915 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) % 4);
917 mstat = *((struct mt76_rx_status *)skb->cb);
919 if (mstat.flag & RX_FLAG_RADIOTAP_HE)
920 data += sizeof(struct ieee80211_radiotap_he);
921 if (mstat.flag & RX_FLAG_RADIOTAP_HE_MU)
922 data += sizeof(struct ieee80211_radiotap_he_mu);
927 static inline void mt76_insert_hdr_pad(struct sk_buff *skb)
929 int len = ieee80211_get_hdrlen_from_skb(skb);
935 memmove(skb->data, skb->data + 2, len);
938 skb->data[len + 1] = 0;
941 static inline bool mt76_is_skb_pktid(u8 pktid)
943 if (pktid & MT_PACKET_ID_HAS_RATE)
946 return pktid >= MT_PACKET_ID_FIRST;
949 static inline u8 mt76_tx_power_nss_delta(u8 nss)
951 static const u8 nss_delta[4] = { 0, 6, 9, 12 };
953 return nss_delta[nss - 1];
956 static inline bool mt76_testmode_enabled(struct mt76_phy *phy)
958 #ifdef CONFIG_NL80211_TESTMODE
959 return phy->test.state != MT76_TM_STATE_OFF;
965 static inline bool mt76_is_testmode_skb(struct mt76_dev *dev,
967 struct ieee80211_hw **hw)
969 #ifdef CONFIG_NL80211_TESTMODE
970 if (skb == dev->phy.test.tx_skb)
972 else if (dev->phy2 && skb == dev->phy2->test.tx_skb)
982 void mt76_rx(struct mt76_dev *dev, enum mt76_rxq_id q, struct sk_buff *skb);
983 void mt76_tx(struct mt76_phy *dev, struct ieee80211_sta *sta,
984 struct mt76_wcid *wcid, struct sk_buff *skb);
985 void mt76_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq);
986 void mt76_stop_tx_queues(struct mt76_phy *phy, struct ieee80211_sta *sta,
988 void mt76_tx_check_agg_ssn(struct ieee80211_sta *sta, struct sk_buff *skb);
989 void mt76_txq_schedule(struct mt76_phy *phy, enum mt76_txq_id qid);
990 void mt76_txq_schedule_all(struct mt76_phy *phy);
991 void mt76_tx_worker(struct mt76_worker *w);
992 void mt76_release_buffered_frames(struct ieee80211_hw *hw,
993 struct ieee80211_sta *sta,
994 u16 tids, int nframes,
995 enum ieee80211_frame_release_type reason,
997 bool mt76_has_tx_pending(struct mt76_phy *phy);
998 void mt76_set_channel(struct mt76_phy *phy);
999 void mt76_update_survey(struct mt76_dev *dev);
1000 void mt76_update_survey_active_time(struct mt76_phy *phy, ktime_t time);
1001 int mt76_get_survey(struct ieee80211_hw *hw, int idx,
1002 struct survey_info *survey);
1003 void mt76_set_stream_caps(struct mt76_phy *phy, bool vht);
1005 int mt76_rx_aggr_start(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tid,
1007 void mt76_rx_aggr_stop(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tid);
1009 void mt76_wcid_key_setup(struct mt76_dev *dev, struct mt76_wcid *wcid,
1010 struct ieee80211_key_conf *key);
1012 void mt76_tx_status_lock(struct mt76_dev *dev, struct sk_buff_head *list)
1013 __acquires(&dev->status_list.lock);
1014 void mt76_tx_status_unlock(struct mt76_dev *dev, struct sk_buff_head *list)
1015 __releases(&dev->status_list.lock);
1017 int mt76_tx_status_skb_add(struct mt76_dev *dev, struct mt76_wcid *wcid,
1018 struct sk_buff *skb);
1019 struct sk_buff *mt76_tx_status_skb_get(struct mt76_dev *dev,
1020 struct mt76_wcid *wcid, int pktid,
1021 struct sk_buff_head *list);
1022 void mt76_tx_status_skb_done(struct mt76_dev *dev, struct sk_buff *skb,
1023 struct sk_buff_head *list);
1024 void mt76_tx_complete_skb(struct mt76_dev *dev, u16 wcid, struct sk_buff *skb);
1025 void mt76_tx_status_check(struct mt76_dev *dev, struct mt76_wcid *wcid,
1027 int mt76_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1028 struct ieee80211_sta *sta,
1029 enum ieee80211_sta_state old_state,
1030 enum ieee80211_sta_state new_state);
1031 void __mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
1032 struct ieee80211_sta *sta);
1033 void mt76_sta_pre_rcu_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1034 struct ieee80211_sta *sta);
1036 int mt76_get_min_avg_rssi(struct mt76_dev *dev, bool ext_phy);
1038 int mt76_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1041 void mt76_csa_check(struct mt76_dev *dev);
1042 void mt76_csa_finish(struct mt76_dev *dev);
1044 int mt76_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant);
1045 int mt76_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set);
1046 void mt76_insert_ccmp_hdr(struct sk_buff *skb, u8 key_id);
1047 int mt76_get_rate(struct mt76_dev *dev,
1048 struct ieee80211_supported_band *sband,
1050 void mt76_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1052 void mt76_sw_scan_complete(struct ieee80211_hw *hw,
1053 struct ieee80211_vif *vif);
1054 int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1055 void *data, int len);
1056 int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb,
1057 struct netlink_callback *cb, void *data, int len);
1058 int mt76_testmode_set_state(struct mt76_phy *phy, enum mt76_testmode_state state);
1060 static inline void mt76_testmode_reset(struct mt76_phy *phy, bool disable)
1062 #ifdef CONFIG_NL80211_TESTMODE
1063 enum mt76_testmode_state state = MT76_TM_STATE_IDLE;
1065 if (disable || phy->test.state == MT76_TM_STATE_OFF)
1066 state = MT76_TM_STATE_OFF;
1068 mt76_testmode_set_state(phy, state);
1074 static inline struct ieee80211_hw *
1075 mt76_tx_status_get_hw(struct mt76_dev *dev, struct sk_buff *skb)
1077 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1078 struct ieee80211_hw *hw = dev->phy.hw;
1080 if ((info->hw_queue & MT_TX_HW_QUEUE_EXT_PHY) && dev->phy2)
1083 info->hw_queue &= ~MT_TX_HW_QUEUE_EXT_PHY;
1088 void mt76_put_txwi(struct mt76_dev *dev, struct mt76_txwi_cache *t);
1089 void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
1090 struct napi_struct *napi);
1091 void mt76_rx_poll_complete(struct mt76_dev *dev, enum mt76_rxq_id q,
1092 struct napi_struct *napi);
1093 void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames);
1094 void mt76_testmode_tx_pending(struct mt76_phy *phy);
1095 void mt76_queue_tx_complete(struct mt76_dev *dev, struct mt76_queue *q,
1096 struct mt76_queue_entry *e);
1099 static inline bool mt76u_urb_error(struct urb *urb)
1101 return urb->status &&
1102 urb->status != -ECONNRESET &&
1103 urb->status != -ESHUTDOWN &&
1104 urb->status != -ENOENT;
1107 /* Map hardware queues to usb endpoints */
1108 static inline u8 q2ep(u8 qid)
1110 /* TODO: take management packets to queue 5 */
1115 mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int *actual_len,
1116 int timeout, int ep)
1118 struct usb_interface *uintf = to_usb_interface(dev->dev);
1119 struct usb_device *udev = interface_to_usbdev(uintf);
1120 struct mt76_usb *usb = &dev->usb;
1124 pipe = usb_rcvbulkpipe(udev, usb->in_ep[ep]);
1126 pipe = usb_sndbulkpipe(udev, usb->out_ep[ep]);
1128 return usb_bulk_msg(udev, pipe, data, len, actual_len, timeout);
1131 int mt76_skb_adjust_pad(struct sk_buff *skb, int pad);
1132 int mt76u_vendor_request(struct mt76_dev *dev, u8 req,
1133 u8 req_type, u16 val, u16 offset,
1134 void *buf, size_t len);
1135 void mt76u_single_wr(struct mt76_dev *dev, const u8 req,
1136 const u16 offset, const u32 val);
1137 int mt76u_init(struct mt76_dev *dev, struct usb_interface *intf,
1139 int mt76u_alloc_mcu_queue(struct mt76_dev *dev);
1140 int mt76u_alloc_queues(struct mt76_dev *dev);
1141 void mt76u_stop_tx(struct mt76_dev *dev);
1142 void mt76u_stop_rx(struct mt76_dev *dev);
1143 int mt76u_resume_rx(struct mt76_dev *dev);
1144 void mt76u_queues_deinit(struct mt76_dev *dev);
1146 int mt76s_init(struct mt76_dev *dev, struct sdio_func *func,
1147 const struct mt76_bus_ops *bus_ops);
1148 int mt76s_alloc_queues(struct mt76_dev *dev);
1149 void mt76s_deinit(struct mt76_dev *dev);
1152 mt76_mcu_msg_alloc(struct mt76_dev *dev, const void *data,
1154 void mt76_mcu_rx_event(struct mt76_dev *dev, struct sk_buff *skb);
1155 struct sk_buff *mt76_mcu_get_response(struct mt76_dev *dev,
1156 unsigned long expires);
1157 int mt76_mcu_send_and_get_msg(struct mt76_dev *dev, int cmd, const void *data,
1158 int len, bool wait_resp, struct sk_buff **ret);
1159 int mt76_mcu_skb_send_and_get_msg(struct mt76_dev *dev, struct sk_buff *skb,
1160 int cmd, bool wait_resp, struct sk_buff **ret);
1161 int mt76_mcu_send_firmware(struct mt76_dev *dev, int cmd, const void *data,
1164 mt76_mcu_send_msg(struct mt76_dev *dev, int cmd, const void *data, int len,
1167 return mt76_mcu_send_and_get_msg(dev, cmd, data, len, wait_resp, NULL);
1171 mt76_mcu_skb_send_msg(struct mt76_dev *dev, struct sk_buff *skb, int cmd,
1174 return mt76_mcu_skb_send_and_get_msg(dev, skb, cmd, wait_resp, NULL);
1177 void mt76_set_irq_mask(struct mt76_dev *dev, u32 addr, u32 clear, u32 set);