190520afbSLorenzo Bianconi // SPDX-License-Identifier: ISC
290520afbSLorenzo Bianconi /* Copyright (C) 2020 MediaTek Inc.
390520afbSLorenzo Bianconi *
490520afbSLorenzo Bianconi * Author: Lorenzo Bianconi <lorenzo@kernel.org>
590520afbSLorenzo Bianconi * Sean Wang <sean.wang@mediatek.com>
690520afbSLorenzo Bianconi */
790520afbSLorenzo Bianconi
890520afbSLorenzo Bianconi #include <linux/kernel.h>
990520afbSLorenzo Bianconi #include <linux/module.h>
1090520afbSLorenzo Bianconi #include <linux/usb.h>
1190520afbSLorenzo Bianconi
1290520afbSLorenzo Bianconi #include "mt7615.h"
1390520afbSLorenzo Bianconi #include "mac.h"
1490520afbSLorenzo Bianconi #include "mcu.h"
1590520afbSLorenzo Bianconi #include "regs.h"
1690520afbSLorenzo Bianconi
1790520afbSLorenzo Bianconi const u32 mt7663_usb_sdio_reg_map[] = {
1890520afbSLorenzo Bianconi [MT_TOP_CFG_BASE] = 0x80020000,
1990520afbSLorenzo Bianconi [MT_HW_BASE] = 0x80000000,
2090520afbSLorenzo Bianconi [MT_DMA_SHDL_BASE] = 0x5000a000,
2190520afbSLorenzo Bianconi [MT_HIF_BASE] = 0x50000000,
2290520afbSLorenzo Bianconi [MT_CSR_BASE] = 0x40000000,
2390520afbSLorenzo Bianconi [MT_EFUSE_ADDR_BASE] = 0x78011000,
2490520afbSLorenzo Bianconi [MT_TOP_MISC_BASE] = 0x81020000,
2590520afbSLorenzo Bianconi [MT_PLE_BASE] = 0x82060000,
2690520afbSLorenzo Bianconi [MT_PSE_BASE] = 0x82068000,
27a66cbdd6SSean Wang [MT_PP_BASE] = 0x8206c000,
2890520afbSLorenzo Bianconi [MT_WTBL_BASE_ADDR] = 0x820e0000,
2990520afbSLorenzo Bianconi [MT_CFG_BASE] = 0x820f0000,
3090520afbSLorenzo Bianconi [MT_AGG_BASE] = 0x820f2000,
3190520afbSLorenzo Bianconi [MT_ARB_BASE] = 0x820f3000,
3290520afbSLorenzo Bianconi [MT_TMAC_BASE] = 0x820f4000,
3390520afbSLorenzo Bianconi [MT_RMAC_BASE] = 0x820f5000,
3490520afbSLorenzo Bianconi [MT_DMA_BASE] = 0x820f7000,
3590520afbSLorenzo Bianconi [MT_PF_BASE] = 0x820f8000,
3690520afbSLorenzo Bianconi [MT_WTBL_BASE_ON] = 0x820f9000,
3790520afbSLorenzo Bianconi [MT_WTBL_BASE_OFF] = 0x820f9800,
3890520afbSLorenzo Bianconi [MT_LPON_BASE] = 0x820fb000,
3990520afbSLorenzo Bianconi [MT_MIB_BASE] = 0x820fd000,
4090520afbSLorenzo Bianconi };
4190520afbSLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7663_usb_sdio_reg_map);
4290520afbSLorenzo Bianconi
4390520afbSLorenzo Bianconi static void
mt7663_usb_sdio_write_txwi(struct mt7615_dev * dev,struct mt76_wcid * wcid,enum mt76_txq_id qid,struct ieee80211_sta * sta,struct ieee80211_key_conf * key,int pid,struct sk_buff * skb)4490520afbSLorenzo Bianconi mt7663_usb_sdio_write_txwi(struct mt7615_dev *dev, struct mt76_wcid *wcid,
4590520afbSLorenzo Bianconi enum mt76_txq_id qid, struct ieee80211_sta *sta,
46191587cdSLorenzo Bianconi struct ieee80211_key_conf *key, int pid,
47191587cdSLorenzo Bianconi struct sk_buff *skb)
4890520afbSLorenzo Bianconi {
49191587cdSLorenzo Bianconi __le32 *txwi = (__le32 *)(skb->data - MT_USB_TXD_SIZE);
5090520afbSLorenzo Bianconi
5190520afbSLorenzo Bianconi memset(txwi, 0, MT_USB_TXD_SIZE);
52*1d5af0acSFelix Fietkau mt7615_mac_write_txwi(dev, txwi, skb, wcid, sta, pid, key, qid, false);
5390520afbSLorenzo Bianconi skb_push(skb, MT_USB_TXD_SIZE);
5490520afbSLorenzo Bianconi }
5590520afbSLorenzo Bianconi
mt7663_usb_sdio_set_rates(struct mt7615_dev * dev,struct mt7615_wtbl_rate_desc * wrd)56d927ebb9SLorenzo Bianconi static int mt7663_usb_sdio_set_rates(struct mt7615_dev *dev,
57d927ebb9SLorenzo Bianconi struct mt7615_wtbl_rate_desc *wrd)
5890520afbSLorenzo Bianconi {
59d927ebb9SLorenzo Bianconi struct mt7615_rate_desc *rate = &wrd->rate;
60d927ebb9SLorenzo Bianconi struct mt7615_sta *sta = wrd->sta;
6190520afbSLorenzo Bianconi u32 w5, w27, addr, val;
624a52d6abSColin Ian King u16 idx;
6390520afbSLorenzo Bianconi
6490520afbSLorenzo Bianconi lockdep_assert_held(&dev->mt76.mutex);
6590520afbSLorenzo Bianconi
6690520afbSLorenzo Bianconi if (!sta)
6790520afbSLorenzo Bianconi return -EINVAL;
6890520afbSLorenzo Bianconi
6990520afbSLorenzo Bianconi if (!mt76_poll(dev, MT_WTBL_UPDATE, MT_WTBL_UPDATE_BUSY, 0, 5000))
7090520afbSLorenzo Bianconi return -ETIMEDOUT;
7190520afbSLorenzo Bianconi
7290520afbSLorenzo Bianconi addr = mt7615_mac_wtbl_addr(dev, sta->wcid.idx);
7390520afbSLorenzo Bianconi
7490520afbSLorenzo Bianconi w27 = mt76_rr(dev, addr + 27 * 4);
7590520afbSLorenzo Bianconi w27 &= ~MT_WTBL_W27_CC_BW_SEL;
7690520afbSLorenzo Bianconi w27 |= FIELD_PREP(MT_WTBL_W27_CC_BW_SEL, rate->bw);
7790520afbSLorenzo Bianconi
7890520afbSLorenzo Bianconi w5 = mt76_rr(dev, addr + 5 * 4);
7990520afbSLorenzo Bianconi w5 &= ~(MT_WTBL_W5_BW_CAP | MT_WTBL_W5_CHANGE_BW_RATE |
8090520afbSLorenzo Bianconi MT_WTBL_W5_MPDU_OK_COUNT |
8190520afbSLorenzo Bianconi MT_WTBL_W5_MPDU_FAIL_COUNT |
8290520afbSLorenzo Bianconi MT_WTBL_W5_RATE_IDX);
8390520afbSLorenzo Bianconi w5 |= FIELD_PREP(MT_WTBL_W5_BW_CAP, rate->bw) |
8490520afbSLorenzo Bianconi FIELD_PREP(MT_WTBL_W5_CHANGE_BW_RATE,
8590520afbSLorenzo Bianconi rate->bw_idx ? rate->bw_idx - 1 : 7);
8690520afbSLorenzo Bianconi
8790520afbSLorenzo Bianconi mt76_wr(dev, MT_WTBL_RIUCR0, w5);
8890520afbSLorenzo Bianconi
8990520afbSLorenzo Bianconi mt76_wr(dev, MT_WTBL_RIUCR1,
9090520afbSLorenzo Bianconi FIELD_PREP(MT_WTBL_RIUCR1_RATE0, rate->probe_val) |
9190520afbSLorenzo Bianconi FIELD_PREP(MT_WTBL_RIUCR1_RATE1, rate->val[0]) |
9290520afbSLorenzo Bianconi FIELD_PREP(MT_WTBL_RIUCR1_RATE2_LO, rate->val[1]));
9390520afbSLorenzo Bianconi
9490520afbSLorenzo Bianconi mt76_wr(dev, MT_WTBL_RIUCR2,
9590520afbSLorenzo Bianconi FIELD_PREP(MT_WTBL_RIUCR2_RATE2_HI, rate->val[1] >> 8) |
9690520afbSLorenzo Bianconi FIELD_PREP(MT_WTBL_RIUCR2_RATE3, rate->val[1]) |
9790520afbSLorenzo Bianconi FIELD_PREP(MT_WTBL_RIUCR2_RATE4, rate->val[2]) |
9890520afbSLorenzo Bianconi FIELD_PREP(MT_WTBL_RIUCR2_RATE5_LO, rate->val[2]));
9990520afbSLorenzo Bianconi
10090520afbSLorenzo Bianconi mt76_wr(dev, MT_WTBL_RIUCR3,
10190520afbSLorenzo Bianconi FIELD_PREP(MT_WTBL_RIUCR3_RATE5_HI, rate->val[2] >> 4) |
10290520afbSLorenzo Bianconi FIELD_PREP(MT_WTBL_RIUCR3_RATE6, rate->val[3]) |
10390520afbSLorenzo Bianconi FIELD_PREP(MT_WTBL_RIUCR3_RATE7, rate->val[3]));
10490520afbSLorenzo Bianconi
10590520afbSLorenzo Bianconi mt76_wr(dev, MT_WTBL_UPDATE,
10690520afbSLorenzo Bianconi FIELD_PREP(MT_WTBL_UPDATE_WLAN_IDX, sta->wcid.idx) |
10790520afbSLorenzo Bianconi MT_WTBL_UPDATE_RATE_UPDATE |
10890520afbSLorenzo Bianconi MT_WTBL_UPDATE_TX_COUNT_CLEAR);
10990520afbSLorenzo Bianconi
11090520afbSLorenzo Bianconi mt76_wr(dev, addr + 27 * 4, w27);
11190520afbSLorenzo Bianconi
11290520afbSLorenzo Bianconi sta->rate_probe = sta->rateset[rate->rateset].probe_rate.idx != -1;
11390520afbSLorenzo Bianconi
1144a52d6abSColin Ian King idx = sta->vif->mt76.omac_idx;
115a4a5a430SRyder Lee idx = idx > HW_BSSID_MAX ? HW_BSSID_0 : idx;
116a4a5a430SRyder Lee addr = idx > 1 ? MT_LPON_TCR2(idx): MT_LPON_TCR0(idx);
117a4a5a430SRyder Lee
118accbcea4SRyder Lee mt76_rmw(dev, addr, MT_LPON_TCR_MODE, MT_LPON_TCR_READ); /* TSF read */
11990520afbSLorenzo Bianconi val = mt76_rr(dev, MT_LPON_UTTR0);
12090520afbSLorenzo Bianconi sta->rate_set_tsf = (val & ~BIT(0)) | rate->rateset;
12190520afbSLorenzo Bianconi
12290520afbSLorenzo Bianconi if (!(sta->wcid.tx_info & MT_WCID_TX_INFO_SET))
12390520afbSLorenzo Bianconi mt76_poll(dev, MT_WTBL_UPDATE, MT_WTBL_UPDATE_BUSY, 0, 5000);
12490520afbSLorenzo Bianconi
12590520afbSLorenzo Bianconi sta->rate_count = 2 * MT7615_RATE_RETRY * sta->n_rates;
12690520afbSLorenzo Bianconi sta->wcid.tx_info |= MT_WCID_TX_INFO_SET;
12790520afbSLorenzo Bianconi
12890520afbSLorenzo Bianconi return 0;
12990520afbSLorenzo Bianconi }
13090520afbSLorenzo Bianconi
mt7663_usb_sdio_rate_work(struct work_struct * work)131d927ebb9SLorenzo Bianconi static void mt7663_usb_sdio_rate_work(struct work_struct *work)
13290520afbSLorenzo Bianconi {
133d927ebb9SLorenzo Bianconi struct mt7615_wtbl_rate_desc *wrd, *wrd_next;
134d927ebb9SLorenzo Bianconi struct list_head wrd_list;
13590520afbSLorenzo Bianconi struct mt7615_dev *dev;
13690520afbSLorenzo Bianconi
13790520afbSLorenzo Bianconi dev = (struct mt7615_dev *)container_of(work, struct mt7615_dev,
138d927ebb9SLorenzo Bianconi rate_work);
13990520afbSLorenzo Bianconi
140d927ebb9SLorenzo Bianconi INIT_LIST_HEAD(&wrd_list);
14190520afbSLorenzo Bianconi spin_lock_bh(&dev->mt76.lock);
142d927ebb9SLorenzo Bianconi list_splice_init(&dev->wrd_head, &wrd_list);
14390520afbSLorenzo Bianconi spin_unlock_bh(&dev->mt76.lock);
14490520afbSLorenzo Bianconi
145d927ebb9SLorenzo Bianconi list_for_each_entry_safe(wrd, wrd_next, &wrd_list, node) {
146d927ebb9SLorenzo Bianconi list_del(&wrd->node);
14790520afbSLorenzo Bianconi
14890520afbSLorenzo Bianconi mt7615_mutex_acquire(dev);
149d927ebb9SLorenzo Bianconi mt7663_usb_sdio_set_rates(dev, wrd);
15090520afbSLorenzo Bianconi mt7615_mutex_release(dev);
15190520afbSLorenzo Bianconi
152d927ebb9SLorenzo Bianconi kfree(wrd);
15390520afbSLorenzo Bianconi }
15490520afbSLorenzo Bianconi }
15590520afbSLorenzo Bianconi
mt7663_usb_sdio_tx_status_data(struct mt76_dev * mdev,u8 * update)15690520afbSLorenzo Bianconi bool mt7663_usb_sdio_tx_status_data(struct mt76_dev *mdev, u8 *update)
15790520afbSLorenzo Bianconi {
15890520afbSLorenzo Bianconi struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
15990520afbSLorenzo Bianconi
16090520afbSLorenzo Bianconi mt7615_mutex_acquire(dev);
16190520afbSLorenzo Bianconi mt7615_mac_sta_poll(dev);
16290520afbSLorenzo Bianconi mt7615_mutex_release(dev);
16390520afbSLorenzo Bianconi
1644fb0a7d2Sjing yangyang return false;
16590520afbSLorenzo Bianconi }
16690520afbSLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7663_usb_sdio_tx_status_data);
16790520afbSLorenzo Bianconi
mt7663_usb_sdio_tx_complete_skb(struct mt76_dev * mdev,struct mt76_queue_entry * e)16890520afbSLorenzo Bianconi void mt7663_usb_sdio_tx_complete_skb(struct mt76_dev *mdev,
16990520afbSLorenzo Bianconi struct mt76_queue_entry *e)
17090520afbSLorenzo Bianconi {
17190520afbSLorenzo Bianconi unsigned int headroom = MT_USB_TXD_SIZE;
17290520afbSLorenzo Bianconi
17390520afbSLorenzo Bianconi if (mt76_is_usb(mdev))
17490520afbSLorenzo Bianconi headroom += MT_USB_HDR_SIZE;
17590520afbSLorenzo Bianconi skb_pull(e->skb, headroom);
17690520afbSLorenzo Bianconi
177e1378e52SFelix Fietkau mt76_tx_complete_skb(mdev, e->wcid, e->skb);
17890520afbSLorenzo Bianconi }
17990520afbSLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7663_usb_sdio_tx_complete_skb);
18090520afbSLorenzo Bianconi
mt7663_usb_sdio_tx_prepare_skb(struct mt76_dev * mdev,void * txwi_ptr,enum mt76_txq_id qid,struct mt76_wcid * wcid,struct ieee80211_sta * sta,struct mt76_tx_info * tx_info)18190520afbSLorenzo Bianconi int mt7663_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
18290520afbSLorenzo Bianconi enum mt76_txq_id qid, struct mt76_wcid *wcid,
18390520afbSLorenzo Bianconi struct ieee80211_sta *sta,
18490520afbSLorenzo Bianconi struct mt76_tx_info *tx_info)
18590520afbSLorenzo Bianconi {
18690520afbSLorenzo Bianconi struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
18790520afbSLorenzo Bianconi struct sk_buff *skb = tx_info->skb;
18890520afbSLorenzo Bianconi struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
189191587cdSLorenzo Bianconi struct ieee80211_key_conf *key = info->control.hw_key;
1908d3cdc1bSLorenzo Bianconi struct mt7615_sta *msta;
1912a9e9857SLorenzo Bianconi int pad, err, pktid;
19290520afbSLorenzo Bianconi
1938d3cdc1bSLorenzo Bianconi msta = wcid ? container_of(wcid, struct mt7615_sta, wcid) : NULL;
1942a9e9857SLorenzo Bianconi if (!wcid)
1952a9e9857SLorenzo Bianconi wcid = &dev->mt76.global_wcid;
1962a9e9857SLorenzo Bianconi
19790520afbSLorenzo Bianconi if ((info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) &&
1988d3cdc1bSLorenzo Bianconi msta && !msta->rate_probe) {
19990520afbSLorenzo Bianconi /* request to configure sampling rate */
20090520afbSLorenzo Bianconi spin_lock_bh(&dev->mt76.lock);
20190520afbSLorenzo Bianconi mt7615_mac_set_rates(&dev->phy, msta, &info->control.rates[0],
20290520afbSLorenzo Bianconi msta->rates);
20390520afbSLorenzo Bianconi spin_unlock_bh(&dev->mt76.lock);
20490520afbSLorenzo Bianconi }
20590520afbSLorenzo Bianconi
2062a9e9857SLorenzo Bianconi pktid = mt76_tx_status_skb_add(&dev->mt76, wcid, skb);
207191587cdSLorenzo Bianconi mt7663_usb_sdio_write_txwi(dev, wcid, qid, sta, key, pktid, skb);
2088da40d69SLorenzo Bianconi if (mt76_is_usb(mdev)) {
2098da40d69SLorenzo Bianconi u32 len = skb->len;
2108da40d69SLorenzo Bianconi
2118da40d69SLorenzo Bianconi put_unaligned_le32(len, skb_push(skb, sizeof(len)));
212e98e6df6SLorenzo Bianconi pad = round_up(skb->len, 4) + 4 - skb->len;
213e98e6df6SLorenzo Bianconi } else {
214e98e6df6SLorenzo Bianconi pad = round_up(skb->len, 4) - skb->len;
2158da40d69SLorenzo Bianconi }
21690520afbSLorenzo Bianconi
2172a9e9857SLorenzo Bianconi err = mt76_skb_adjust_pad(skb, pad);
2182a9e9857SLorenzo Bianconi if (err)
2192a9e9857SLorenzo Bianconi /* Release pktid in case of error. */
2202a9e9857SLorenzo Bianconi idr_remove(&wcid->pktid, pktid);
2212a9e9857SLorenzo Bianconi
2222a9e9857SLorenzo Bianconi return err;
22390520afbSLorenzo Bianconi }
22490520afbSLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7663_usb_sdio_tx_prepare_skb);
22590520afbSLorenzo Bianconi
mt7663u_dma_sched_init(struct mt7615_dev * dev)22690520afbSLorenzo Bianconi static int mt7663u_dma_sched_init(struct mt7615_dev *dev)
22790520afbSLorenzo Bianconi {
22890520afbSLorenzo Bianconi int i;
22990520afbSLorenzo Bianconi
23090520afbSLorenzo Bianconi mt76_rmw(dev, MT_DMA_SHDL(MT_DMASHDL_PKT_MAX_SIZE),
23190520afbSLorenzo Bianconi MT_DMASHDL_PKT_MAX_SIZE_PLE | MT_DMASHDL_PKT_MAX_SIZE_PSE,
23290520afbSLorenzo Bianconi FIELD_PREP(MT_DMASHDL_PKT_MAX_SIZE_PLE, 1) |
23390520afbSLorenzo Bianconi FIELD_PREP(MT_DMASHDL_PKT_MAX_SIZE_PSE, 8));
23490520afbSLorenzo Bianconi
23590520afbSLorenzo Bianconi /* disable refill group 5 - group 15 and raise group 2
23690520afbSLorenzo Bianconi * and 3 as high priority.
23790520afbSLorenzo Bianconi */
23890520afbSLorenzo Bianconi mt76_wr(dev, MT_DMA_SHDL(MT_DMASHDL_REFILL), 0xffe00006);
23990520afbSLorenzo Bianconi mt76_clear(dev, MT_DMA_SHDL(MT_DMASHDL_PAGE), BIT(16));
24090520afbSLorenzo Bianconi
24190520afbSLorenzo Bianconi for (i = 0; i < 5; i++)
24290520afbSLorenzo Bianconi mt76_wr(dev, MT_DMA_SHDL(MT_DMASHDL_GROUP_QUOTA(i)),
24390520afbSLorenzo Bianconi FIELD_PREP(MT_DMASHDL_GROUP_QUOTA_MIN, 0x3) |
24490520afbSLorenzo Bianconi FIELD_PREP(MT_DMASHDL_GROUP_QUOTA_MAX, 0x1ff));
24590520afbSLorenzo Bianconi
24690520afbSLorenzo Bianconi mt76_wr(dev, MT_DMA_SHDL(MT_DMASHDL_Q_MAP(0)), 0x42104210);
24790520afbSLorenzo Bianconi mt76_wr(dev, MT_DMA_SHDL(MT_DMASHDL_Q_MAP(1)), 0x42104210);
24890520afbSLorenzo Bianconi
24990520afbSLorenzo Bianconi mt76_wr(dev, MT_DMA_SHDL(MT_DMASHDL_Q_MAP(2)), 0x4444);
25090520afbSLorenzo Bianconi
25190520afbSLorenzo Bianconi /* group pririority from high to low:
25290520afbSLorenzo Bianconi * 15 (cmd groups) > 4 > 3 > 2 > 1 > 0.
25390520afbSLorenzo Bianconi */
25490520afbSLorenzo Bianconi mt76_wr(dev, MT_DMA_SHDL(MT_DMASHDL_SCHED_SET0), 0x6501234f);
25590520afbSLorenzo Bianconi mt76_wr(dev, MT_DMA_SHDL(MT_DMASHDL_SCHED_SET1), 0xedcba987);
25690520afbSLorenzo Bianconi mt76_wr(dev, MT_DMA_SHDL(MT_DMASHDL_OPTIONAL), 0x7004801c);
25790520afbSLorenzo Bianconi
25890520afbSLorenzo Bianconi mt76_wr(dev, MT_UDMA_WLCFG_1,
25990520afbSLorenzo Bianconi FIELD_PREP(MT_WL_TX_TMOUT_LMT, 80000) |
26090520afbSLorenzo Bianconi FIELD_PREP(MT_WL_RX_AGG_PKT_LMT, 1));
26190520afbSLorenzo Bianconi
26290520afbSLorenzo Bianconi /* setup UDMA Rx Flush */
26390520afbSLorenzo Bianconi mt76_clear(dev, MT_UDMA_WLCFG_0, MT_WL_RX_FLUSH);
26490520afbSLorenzo Bianconi /* hif reset */
26590520afbSLorenzo Bianconi mt76_set(dev, MT_HIF_RST, MT_HIF_LOGIC_RST_N);
26690520afbSLorenzo Bianconi
26790520afbSLorenzo Bianconi mt76_set(dev, MT_UDMA_WLCFG_0,
26890520afbSLorenzo Bianconi MT_WL_RX_AGG_EN | MT_WL_RX_EN | MT_WL_TX_EN |
26990520afbSLorenzo Bianconi MT_WL_RX_MPSZ_PAD0 | MT_TICK_1US_EN |
27090520afbSLorenzo Bianconi MT_WL_TX_TMOUT_FUNC_EN);
27190520afbSLorenzo Bianconi mt76_rmw(dev, MT_UDMA_WLCFG_0, MT_WL_RX_AGG_LMT | MT_WL_RX_AGG_TO,
27290520afbSLorenzo Bianconi FIELD_PREP(MT_WL_RX_AGG_LMT, 32) |
27390520afbSLorenzo Bianconi FIELD_PREP(MT_WL_RX_AGG_TO, 100));
27490520afbSLorenzo Bianconi
27590520afbSLorenzo Bianconi return 0;
27690520afbSLorenzo Bianconi }
27790520afbSLorenzo Bianconi
mt7663_usb_sdio_init_hardware(struct mt7615_dev * dev)27890520afbSLorenzo Bianconi static int mt7663_usb_sdio_init_hardware(struct mt7615_dev *dev)
27990520afbSLorenzo Bianconi {
28090520afbSLorenzo Bianconi int ret, idx;
28190520afbSLorenzo Bianconi
28290520afbSLorenzo Bianconi ret = mt7615_eeprom_init(dev, MT_EFUSE_BASE);
28390520afbSLorenzo Bianconi if (ret < 0)
28490520afbSLorenzo Bianconi return ret;
28590520afbSLorenzo Bianconi
28690520afbSLorenzo Bianconi if (mt76_is_usb(&dev->mt76)) {
28790520afbSLorenzo Bianconi ret = mt7663u_dma_sched_init(dev);
28890520afbSLorenzo Bianconi if (ret)
28990520afbSLorenzo Bianconi return ret;
29090520afbSLorenzo Bianconi }
29190520afbSLorenzo Bianconi
29290520afbSLorenzo Bianconi set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
29390520afbSLorenzo Bianconi
29490520afbSLorenzo Bianconi /* Beacon and mgmt frames should occupy wcid 0 */
29590520afbSLorenzo Bianconi idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7615_WTBL_STA - 1);
29690520afbSLorenzo Bianconi if (idx)
29790520afbSLorenzo Bianconi return -ENOSPC;
29890520afbSLorenzo Bianconi
29990520afbSLorenzo Bianconi dev->mt76.global_wcid.idx = idx;
30090520afbSLorenzo Bianconi dev->mt76.global_wcid.hw_key_idx = -1;
30190520afbSLorenzo Bianconi rcu_assign_pointer(dev->mt76.wcid[idx], &dev->mt76.global_wcid);
30290520afbSLorenzo Bianconi
30390520afbSLorenzo Bianconi return 0;
30490520afbSLorenzo Bianconi }
30590520afbSLorenzo Bianconi
mt7663_usb_sdio_register_device(struct mt7615_dev * dev)30690520afbSLorenzo Bianconi int mt7663_usb_sdio_register_device(struct mt7615_dev *dev)
30790520afbSLorenzo Bianconi {
30890520afbSLorenzo Bianconi struct ieee80211_hw *hw = mt76_hw(dev);
30990520afbSLorenzo Bianconi int err;
31090520afbSLorenzo Bianconi
311d927ebb9SLorenzo Bianconi INIT_WORK(&dev->rate_work, mt7663_usb_sdio_rate_work);
312d927ebb9SLorenzo Bianconi INIT_LIST_HEAD(&dev->wrd_head);
31390520afbSLorenzo Bianconi mt7615_init_device(dev);
31490520afbSLorenzo Bianconi
31590520afbSLorenzo Bianconi err = mt7663_usb_sdio_init_hardware(dev);
31690520afbSLorenzo Bianconi if (err)
31790520afbSLorenzo Bianconi return err;
31890520afbSLorenzo Bianconi
319b9b852b9SLorenzo Bianconi hw->extra_tx_headroom += MT_USB_TXD_SIZE;
320b9b852b9SLorenzo Bianconi if (mt76_is_usb(&dev->mt76)) {
321b9b852b9SLorenzo Bianconi hw->extra_tx_headroom += MT_USB_HDR_SIZE;
32290520afbSLorenzo Bianconi /* check hw sg support in order to enable AMSDU */
323b9b852b9SLorenzo Bianconi if (dev->mt76.usb.sg_en)
324d39b52e3SSean Wang hw->max_tx_fragments = MT_HW_TXP_MAX_BUF_NUM;
325d39b52e3SSean Wang else
326d39b52e3SSean Wang hw->max_tx_fragments = 1;
327b9b852b9SLorenzo Bianconi }
32890520afbSLorenzo Bianconi
32954b8fdebSLorenzo Bianconi err = mt76_register_device(&dev->mt76, true, mt76_rates,
33054b8fdebSLorenzo Bianconi ARRAY_SIZE(mt76_rates));
33190520afbSLorenzo Bianconi if (err < 0)
33290520afbSLorenzo Bianconi return err;
33390520afbSLorenzo Bianconi
33490520afbSLorenzo Bianconi if (!dev->mt76.usb.sg_en) {
33590520afbSLorenzo Bianconi struct ieee80211_sta_vht_cap *vht_cap;
33690520afbSLorenzo Bianconi
33790520afbSLorenzo Bianconi /* decrease max A-MSDU size if SG is not supported */
33890520afbSLorenzo Bianconi vht_cap = &dev->mphy.sband_5g.sband.vht_cap;
33990520afbSLorenzo Bianconi vht_cap->cap &= ~IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
34090520afbSLorenzo Bianconi }
34190520afbSLorenzo Bianconi
34290520afbSLorenzo Bianconi ieee80211_queue_work(hw, &dev->mcu_work);
34390520afbSLorenzo Bianconi mt7615_init_txpower(dev, &dev->mphy.sband_2g.sband);
34490520afbSLorenzo Bianconi mt7615_init_txpower(dev, &dev->mphy.sband_5g.sband);
34590520afbSLorenzo Bianconi
34690520afbSLorenzo Bianconi return mt7615_init_debugfs(dev);
34790520afbSLorenzo Bianconi }
34890520afbSLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7663_usb_sdio_register_device);
34990520afbSLorenzo Bianconi
35090520afbSLorenzo Bianconi MODULE_AUTHOR("Lorenzo Bianconi <lorenzo@kernel.org>");
35190520afbSLorenzo Bianconi MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>");
35290520afbSLorenzo Bianconi MODULE_LICENSE("Dual BSD/GPL");
353