1 // SPDX-License-Identifier: ISC
8 mt7603_rx_loopback_skb(struct mt7603_dev
*dev
, struct sk_buff
*skb
)
10 static const u8 tid_to_ac
[8] = {
20 __le32
*txd
= (__le32
*)skb
->data
;
21 struct ieee80211_hdr
*hdr
;
22 struct ieee80211_sta
*sta
;
23 struct mt7603_sta
*msta
;
24 struct mt76_wcid
*wcid
;
30 if (skb
->len
< MT_TXD_SIZE
+ sizeof(struct ieee80211_hdr
))
33 val
= le32_to_cpu(txd
[1]);
34 idx
= FIELD_GET(MT_TXD1_WLAN_IDX
, val
);
35 skb
->priority
= FIELD_GET(MT_TXD1_TID
, val
);
37 if (idx
>= MT7603_WTBL_STA
- 1)
40 wcid
= rcu_dereference(dev
->mt76
.wcid
[idx
]);
44 priv
= msta
= container_of(wcid
, struct mt7603_sta
, wcid
);
45 val
= le32_to_cpu(txd
[0]);
46 val
&= ~(MT_TXD0_P_IDX
| MT_TXD0_Q_IDX
);
47 val
|= FIELD_PREP(MT_TXD0_Q_IDX
, MT_TX_HW_QUEUE_MGMT
);
48 txd
[0] = cpu_to_le32(val
);
50 sta
= container_of(priv
, struct ieee80211_sta
, drv_priv
);
51 hdr
= (struct ieee80211_hdr
*)&skb
->data
[MT_TXD_SIZE
];
52 if (ieee80211_is_data_qos(hdr
->frame_control
))
53 tid
= *ieee80211_get_qos_ctl(hdr
) &
54 IEEE80211_QOS_CTL_TAG1D_MASK
;
55 skb_set_queue_mapping(skb
, tid_to_ac
[tid
]);
56 ieee80211_sta_set_buffered(sta
, tid
, true);
58 spin_lock_bh(&dev
->ps_lock
);
59 __skb_queue_tail(&msta
->psq
, skb
);
60 if (skb_queue_len(&msta
->psq
) >= 64) {
61 skb
= __skb_dequeue(&msta
->psq
);
64 spin_unlock_bh(&dev
->ps_lock
);
71 void mt7603_queue_rx_skb(struct mt76_dev
*mdev
, enum mt76_rxq_id q
,
74 struct mt7603_dev
*dev
= container_of(mdev
, struct mt7603_dev
, mt76
);
75 __le32
*rxd
= (__le32
*)skb
->data
;
76 __le32
*end
= (__le32
*)&skb
->data
[skb
->len
];
77 enum rx_pkt_type type
;
79 type
= FIELD_GET(MT_RXD0_PKT_TYPE
, le32_to_cpu(rxd
[0]));
81 if (q
== MT_RXQ_MCU
) {
82 if (type
== PKT_TYPE_RX_EVENT
)
83 mt76_mcu_rx_event(&dev
->mt76
, skb
);
85 mt7603_rx_loopback_skb(dev
, skb
);
91 for (rxd
++; rxd
+ 5 <= end
; rxd
+= 5)
92 mt7603_mac_add_txs(dev
, rxd
);
95 case PKT_TYPE_RX_EVENT
:
96 mt76_mcu_rx_event(&dev
->mt76
, skb
);
99 if (mt7603_mac_fill_rx(dev
, skb
) == 0) {
100 mt76_rx(&dev
->mt76
, q
, skb
);
111 mt7603_init_rx_queue(struct mt7603_dev
*dev
, struct mt76_queue
*q
,
112 int idx
, int n_desc
, int bufsize
)
116 err
= mt76_queue_alloc(dev
, q
, idx
, n_desc
, bufsize
,
121 mt7603_irq_enable(dev
, MT_INT_RX_DONE(idx
));
126 static int mt7603_poll_tx(struct napi_struct
*napi
, int budget
)
128 struct mt7603_dev
*dev
;
131 dev
= container_of(napi
, struct mt7603_dev
, mt76
.tx_napi
);
132 dev
->tx_dma_check
= 0;
134 mt76_queue_tx_cleanup(dev
, dev
->mt76
.q_mcu
[MT_MCUQ_WM
], false);
135 for (i
= MT_TXQ_PSD
; i
>= 0; i
--)
136 mt76_queue_tx_cleanup(dev
, dev
->mphy
.q_tx
[i
], false);
138 if (napi_complete_done(napi
, 0))
139 mt7603_irq_enable(dev
, MT_INT_TX_DONE_ALL
);
141 mt76_queue_tx_cleanup(dev
, dev
->mt76
.q_mcu
[MT_MCUQ_WM
], false);
142 for (i
= MT_TXQ_PSD
; i
>= 0; i
--)
143 mt76_queue_tx_cleanup(dev
, dev
->mphy
.q_tx
[i
], false);
145 mt7603_mac_sta_poll(dev
);
147 mt76_worker_schedule(&dev
->mt76
.tx_worker
);
152 int mt7603_dma_init(struct mt7603_dev
*dev
)
154 static const u8 wmm_queue_map
[] = {
155 [IEEE80211_AC_BK
] = 0,
156 [IEEE80211_AC_BE
] = 1,
157 [IEEE80211_AC_VI
] = 2,
158 [IEEE80211_AC_VO
] = 3,
163 mt76_dma_attach(&dev
->mt76
);
165 mt76_clear(dev
, MT_WPDMA_GLO_CFG
,
166 MT_WPDMA_GLO_CFG_TX_DMA_EN
|
167 MT_WPDMA_GLO_CFG_RX_DMA_EN
|
168 MT_WPDMA_GLO_CFG_DMA_BURST_SIZE
|
169 MT_WPDMA_GLO_CFG_TX_WRITEBACK_DONE
);
171 mt76_wr(dev
, MT_WPDMA_RST_IDX
, ~0);
172 mt7603_pse_client_reset(dev
);
174 for (i
= 0; i
< ARRAY_SIZE(wmm_queue_map
); i
++) {
175 ret
= mt76_init_tx_queue(&dev
->mphy
, i
, wmm_queue_map
[i
],
176 MT7603_TX_RING_SIZE
, MT_TX_RING_BASE
);
181 ret
= mt76_init_tx_queue(&dev
->mphy
, MT_TXQ_PSD
, MT_TX_HW_QUEUE_MGMT
,
182 MT7603_PSD_RING_SIZE
, MT_TX_RING_BASE
);
186 ret
= mt76_init_mcu_queue(&dev
->mt76
, MT_MCUQ_WM
, MT_TX_HW_QUEUE_MCU
,
187 MT_MCU_RING_SIZE
, MT_TX_RING_BASE
);
191 ret
= mt76_init_tx_queue(&dev
->mphy
, MT_TXQ_BEACON
, MT_TX_HW_QUEUE_BCN
,
192 MT_MCU_RING_SIZE
, MT_TX_RING_BASE
);
196 ret
= mt76_init_tx_queue(&dev
->mphy
, MT_TXQ_CAB
, MT_TX_HW_QUEUE_BMC
,
197 MT_MCU_RING_SIZE
, MT_TX_RING_BASE
);
201 mt7603_irq_enable(dev
,
202 MT_INT_TX_DONE(IEEE80211_AC_VO
) |
203 MT_INT_TX_DONE(IEEE80211_AC_VI
) |
204 MT_INT_TX_DONE(IEEE80211_AC_BE
) |
205 MT_INT_TX_DONE(IEEE80211_AC_BK
) |
206 MT_INT_TX_DONE(MT_TX_HW_QUEUE_MGMT
) |
207 MT_INT_TX_DONE(MT_TX_HW_QUEUE_MCU
) |
208 MT_INT_TX_DONE(MT_TX_HW_QUEUE_BCN
) |
209 MT_INT_TX_DONE(MT_TX_HW_QUEUE_BMC
));
211 ret
= mt7603_init_rx_queue(dev
, &dev
->mt76
.q_rx
[MT_RXQ_MCU
], 1,
212 MT7603_MCU_RX_RING_SIZE
, MT_RX_BUF_SIZE
);
216 ret
= mt7603_init_rx_queue(dev
, &dev
->mt76
.q_rx
[MT_RXQ_MAIN
], 0,
217 MT7603_RX_RING_SIZE
, MT_RX_BUF_SIZE
);
221 mt76_wr(dev
, MT_DELAY_INT_CFG
, 0);
222 ret
= mt76_init_queues(dev
);
226 netif_tx_napi_add(&dev
->mt76
.napi_dev
, &dev
->mt76
.tx_napi
,
227 mt7603_poll_tx
, NAPI_POLL_WEIGHT
);
228 napi_enable(&dev
->mt76
.tx_napi
);
233 void mt7603_dma_cleanup(struct mt7603_dev
*dev
)
235 mt76_clear(dev
, MT_WPDMA_GLO_CFG
,
236 MT_WPDMA_GLO_CFG_TX_DMA_EN
|
237 MT_WPDMA_GLO_CFG_RX_DMA_EN
|
238 MT_WPDMA_GLO_CFG_TX_WRITEBACK_DONE
);
240 mt76_dma_cleanup(&dev
->mt76
);