developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1 | From dfbef22fdf1a3e29f9d3c00a50083a02c69e8ad1 Mon Sep 17 00:00:00 2001 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 2 | From: Sujuan Chen <sujuan.chen@mediatek.com> |
| 3 | Date: Tue, 5 Jul 2022 19:42:55 +0800 |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 4 | Subject: [PATCH 3003/3007] mt76 add wed rx support |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 5 | |
| 6 | Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com> |
| 7 | --- |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 8 | dma.c | 250 ++++++++++++++++++++++++++++++++++++++-------- |
| 9 | dma.h | 10 ++ |
| 10 | mac80211.c | 8 +- |
developer | 20126ad | 2022-09-12 14:42:56 +0800 | [diff] [blame] | 11 | mt76.h | 24 ++++- |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 12 | mt7603/dma.c | 2 +- |
| 13 | mt7603/mt7603.h | 2 +- |
| 14 | mt7615/mac.c | 2 +- |
| 15 | mt7615/mt7615.h | 2 +- |
| 16 | mt76_connac_mcu.c | 9 ++ |
| 17 | mt76x02.h | 2 +- |
| 18 | mt76x02_txrx.c | 2 +- |
| 19 | mt7915/dma.c | 25 +++-- |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 20 | mt7915/mac.c | 101 ++++++++++++++++++- |
developer | 20126ad | 2022-09-12 14:42:56 +0800 | [diff] [blame] | 21 | mt7915/mcu.c | 3 + |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 22 | mt7915/mmio.c | 26 ++++- |
developer | 20126ad | 2022-09-12 14:42:56 +0800 | [diff] [blame] | 23 | mt7915/mt7915.h | 7 +- |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 24 | mt7915/regs.h | 14 ++- |
| 25 | mt7921/mac.c | 2 +- |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 26 | mt7921/mt7921.h | 2 +- |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 27 | tx.c | 34 +++++++ |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 28 | 20 files changed, 456 insertions(+), 71 deletions(-) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 29 | |
| 30 | diff --git a/dma.c b/dma.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 31 | index 8ea09e6e..3317d2b9 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 32 | --- a/dma.c |
| 33 | +++ b/dma.c |
| 34 | @@ -98,6 +98,63 @@ mt76_put_txwi(struct mt76_dev *dev, struct mt76_txwi_cache *t) |
| 35 | } |
| 36 | EXPORT_SYMBOL_GPL(mt76_put_txwi); |
| 37 | |
| 38 | +static struct mt76_txwi_cache * |
| 39 | +mt76_alloc_rxwi(struct mt76_dev *dev) |
| 40 | +{ |
| 41 | + struct mt76_txwi_cache *r; |
| 42 | + int size; |
| 43 | + |
| 44 | + size = L1_CACHE_ALIGN(sizeof(*r)); |
| 45 | + r = kzalloc(size, GFP_ATOMIC); |
| 46 | + if (!r) |
| 47 | + return NULL; |
| 48 | + |
| 49 | + r->buf = NULL; |
| 50 | + |
| 51 | + return r; |
| 52 | +} |
| 53 | + |
| 54 | +static struct mt76_txwi_cache * |
| 55 | +__mt76_get_rxwi(struct mt76_dev *dev) |
| 56 | +{ |
| 57 | + struct mt76_txwi_cache *r = NULL; |
| 58 | + |
| 59 | + spin_lock(&dev->wed_lock); |
| 60 | + if (!list_empty(&dev->rxwi_cache)) { |
| 61 | + r = list_first_entry(&dev->rxwi_cache, struct mt76_txwi_cache, |
| 62 | + list); |
| 63 | + if(r) |
| 64 | + list_del(&r->list); |
| 65 | + } |
| 66 | + spin_unlock(&dev->wed_lock); |
| 67 | + |
| 68 | + return r; |
| 69 | +} |
| 70 | + |
| 71 | +struct mt76_txwi_cache * |
| 72 | +mt76_get_rxwi(struct mt76_dev *dev) |
| 73 | +{ |
| 74 | + struct mt76_txwi_cache *r = __mt76_get_rxwi(dev); |
| 75 | + |
| 76 | + if (r) |
| 77 | + return r; |
| 78 | + |
| 79 | + return mt76_alloc_rxwi(dev); |
| 80 | +} |
| 81 | +EXPORT_SYMBOL_GPL(mt76_get_rxwi); |
| 82 | + |
| 83 | +void |
| 84 | +mt76_put_rxwi(struct mt76_dev *dev, struct mt76_txwi_cache *r) |
| 85 | +{ |
| 86 | + if (!r) |
| 87 | + return; |
| 88 | + |
| 89 | + spin_lock(&dev->wed_lock); |
| 90 | + list_add(&r->list, &dev->rxwi_cache); |
| 91 | + spin_unlock(&dev->wed_lock); |
| 92 | +} |
| 93 | +EXPORT_SYMBOL_GPL(mt76_put_rxwi); |
| 94 | + |
| 95 | static void |
| 96 | mt76_free_pending_txwi(struct mt76_dev *dev) |
| 97 | { |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 98 | @@ -112,6 +169,21 @@ mt76_free_pending_txwi(struct mt76_dev *dev) |
| 99 | local_bh_enable(); |
| 100 | } |
| 101 | |
| 102 | +static void |
| 103 | +mt76_free_pending_rxwi(struct mt76_dev *dev) |
| 104 | +{ |
| 105 | + struct mt76_txwi_cache *r; |
| 106 | + |
| 107 | + local_bh_disable(); |
| 108 | + while ((r = __mt76_get_rxwi(dev)) != NULL) { |
| 109 | + if (r->buf) |
| 110 | + skb_free_frag(r->buf); |
| 111 | + |
| 112 | + kfree(r); |
| 113 | + } |
| 114 | + local_bh_enable(); |
| 115 | +} |
| 116 | + |
| 117 | static void |
| 118 | mt76_dma_sync_idx(struct mt76_dev *dev, struct mt76_queue *q) |
| 119 | { |
| 120 | @@ -141,12 +213,15 @@ mt76_dma_queue_reset(struct mt76_dev *dev, struct mt76_queue *q) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 121 | static int |
| 122 | mt76_dma_add_buf(struct mt76_dev *dev, struct mt76_queue *q, |
| 123 | struct mt76_queue_buf *buf, int nbufs, u32 info, |
| 124 | - struct sk_buff *skb, void *txwi) |
| 125 | + struct sk_buff *skb, void *txwi, void *rxwi) |
| 126 | { |
| 127 | + struct mtk_wed_device *wed = &dev->mmio.wed; |
| 128 | + |
| 129 | struct mt76_queue_entry *entry; |
| 130 | struct mt76_desc *desc; |
| 131 | u32 ctrl; |
| 132 | int i, idx = -1; |
| 133 | + int type; |
| 134 | |
| 135 | if (txwi) { |
| 136 | q->entry[q->head].txwi = DMA_DUMMY_DATA; |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 137 | @@ -162,28 +237,42 @@ mt76_dma_add_buf(struct mt76_dev *dev, struct mt76_queue *q, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 138 | desc = &q->desc[idx]; |
| 139 | entry = &q->entry[idx]; |
| 140 | |
| 141 | - if (buf[0].skip_unmap) |
| 142 | - entry->skip_buf0 = true; |
| 143 | - entry->skip_buf1 = i == nbufs - 1; |
| 144 | - |
| 145 | - entry->dma_addr[0] = buf[0].addr; |
| 146 | - entry->dma_len[0] = buf[0].len; |
| 147 | - |
| 148 | - ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len); |
| 149 | - if (i < nbufs - 1) { |
| 150 | - entry->dma_addr[1] = buf[1].addr; |
| 151 | - entry->dma_len[1] = buf[1].len; |
| 152 | - buf1 = buf[1].addr; |
| 153 | - ctrl |= FIELD_PREP(MT_DMA_CTL_SD_LEN1, buf[1].len); |
| 154 | - if (buf[1].skip_unmap) |
| 155 | - entry->skip_buf1 = true; |
| 156 | + type = FIELD_GET(MT_QFLAG_WED_TYPE, q->flags); |
| 157 | + if (mtk_wed_device_active(wed) && type == MT76_WED_Q_RX) { |
| 158 | + struct mt76_txwi_cache *r = rxwi; |
| 159 | + int rx_token; |
| 160 | + |
| 161 | + if (!r) |
| 162 | + return -ENOMEM; |
| 163 | + |
| 164 | + rx_token = mt76_rx_token_consume(dev, (void *)skb, r, buf[0].addr); |
| 165 | + |
| 166 | + buf1 |= FIELD_PREP(MT_DMA_CTL_TOKEN, rx_token); |
| 167 | + ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, MTK_WED_RX_PKT_SIZE); |
| 168 | + ctrl |= MT_DMA_CTL_TO_HOST; |
| 169 | + } else { |
| 170 | + if (buf[0].skip_unmap) |
| 171 | + entry->skip_buf0 = true; |
| 172 | + entry->skip_buf1 = i == nbufs - 1; |
| 173 | + |
| 174 | + entry->dma_addr[0] = buf[0].addr; |
| 175 | + entry->dma_len[0] = buf[0].len; |
| 176 | + |
| 177 | + ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len); |
| 178 | + if (i < nbufs - 1) { |
| 179 | + entry->dma_addr[1] = buf[1].addr; |
| 180 | + entry->dma_len[1] = buf[1].len; |
| 181 | + buf1 = buf[1].addr; |
| 182 | + ctrl |= FIELD_PREP(MT_DMA_CTL_SD_LEN1, buf[1].len); |
| 183 | + if (buf[1].skip_unmap) |
| 184 | + entry->skip_buf1 = true; |
| 185 | + } |
| 186 | + if (i == nbufs - 1) |
| 187 | + ctrl |= MT_DMA_CTL_LAST_SEC0; |
| 188 | + else if (i == nbufs - 2) |
| 189 | + ctrl |= MT_DMA_CTL_LAST_SEC1; |
| 190 | } |
| 191 | |
| 192 | - if (i == nbufs - 1) |
| 193 | - ctrl |= MT_DMA_CTL_LAST_SEC0; |
| 194 | - else if (i == nbufs - 2) |
| 195 | - ctrl |= MT_DMA_CTL_LAST_SEC1; |
| 196 | - |
| 197 | WRITE_ONCE(desc->buf0, cpu_to_le32(buf0)); |
| 198 | WRITE_ONCE(desc->buf1, cpu_to_le32(buf1)); |
| 199 | WRITE_ONCE(desc->info, cpu_to_le32(info)); |
developer | a15518e | 2022-07-25 19:03:42 +0800 | [diff] [blame] | 200 | @@ -272,33 +361,65 @@ mt76_dma_tx_cleanup(struct mt76_dev *dev, struct mt76_queue *q, bool flush) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 201 | |
| 202 | static void * |
| 203 | mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx, |
| 204 | - int *len, u32 *info, bool *more) |
| 205 | + int *len, u32 *info, bool *more, bool *drop) |
| 206 | { |
| 207 | struct mt76_queue_entry *e = &q->entry[idx]; |
| 208 | struct mt76_desc *desc = &q->desc[idx]; |
| 209 | dma_addr_t buf_addr; |
developer | a15518e | 2022-07-25 19:03:42 +0800 | [diff] [blame] | 210 | - void *buf = e->buf; |
| 211 | + void *buf = e->buf, *copy = NULL; |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 212 | int buf_len = SKB_WITH_OVERHEAD(q->buf_size); |
| 213 | + struct mtk_wed_device *wed = &dev->mmio.wed; |
| 214 | + int type; |
| 215 | |
| 216 | - buf_addr = e->dma_addr[0]; |
| 217 | if (len) { |
| 218 | u32 ctl = le32_to_cpu(READ_ONCE(desc->ctrl)); |
| 219 | *len = FIELD_GET(MT_DMA_CTL_SD_LEN0, ctl); |
| 220 | *more = !(ctl & MT_DMA_CTL_LAST_SEC0); |
| 221 | } |
| 222 | |
| 223 | - if (info) |
| 224 | - *info = le32_to_cpu(desc->info); |
| 225 | + type = FIELD_GET(MT_QFLAG_WED_TYPE, q->flags); |
| 226 | + if (mtk_wed_device_active(wed) && type == MT76_WED_Q_RX) { |
| 227 | + u32 token; |
| 228 | + struct mt76_txwi_cache *r; |
| 229 | + |
| 230 | + token = FIELD_GET(MT_DMA_CTL_TOKEN, desc->buf1); |
| 231 | + |
| 232 | + r = mt76_rx_token_release(dev, token); |
| 233 | + if (!r) |
| 234 | + return NULL; |
| 235 | + |
| 236 | + buf = page_frag_alloc(&q->rx_page, q->buf_size, GFP_ATOMIC); |
| 237 | + if (!buf) |
| 238 | + return NULL; |
| 239 | + |
developer | a15518e | 2022-07-25 19:03:42 +0800 | [diff] [blame] | 240 | + copy = r->buf; |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 241 | + buf_addr = r->dma_addr; |
| 242 | + buf_len = MTK_WED_RX_PKT_SIZE; |
| 243 | + r->dma_addr = 0; |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 244 | + |
| 245 | + mt76_put_rxwi(dev, r); |
| 246 | + |
| 247 | + if (desc->ctrl & (MT_DMA_CTL_TO_HOST_A | MT_DMA_CTL_DROP)) |
| 248 | + *drop = true; |
| 249 | + } else { |
| 250 | + buf_addr = e->dma_addr[0]; |
| 251 | + e->buf = NULL; |
| 252 | + } |
| 253 | |
| 254 | dma_unmap_single(dev->dma_dev, buf_addr, buf_len, DMA_FROM_DEVICE); |
| 255 | - e->buf = NULL; |
| 256 | + |
developer | a15518e | 2022-07-25 19:03:42 +0800 | [diff] [blame] | 257 | + if (copy) |
| 258 | + memcpy(buf, copy, MTK_WED_RX_PKT_SIZE); |
| 259 | + |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 260 | + if (info) |
| 261 | + *info = le32_to_cpu(desc->info); |
| 262 | |
| 263 | return buf; |
| 264 | } |
| 265 | |
| 266 | static void * |
| 267 | mt76_dma_dequeue(struct mt76_dev *dev, struct mt76_queue *q, bool flush, |
| 268 | - int *len, u32 *info, bool *more) |
| 269 | + int *len, u32 *info, bool *more, bool *drop) |
| 270 | { |
| 271 | int idx = q->tail; |
| 272 | |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 273 | @@ -314,7 +435,7 @@ mt76_dma_dequeue(struct mt76_dev *dev, struct mt76_queue *q, bool flush, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 274 | q->tail = (q->tail + 1) % q->ndesc; |
| 275 | q->queued--; |
| 276 | |
| 277 | - return mt76_dma_get_buf(dev, q, idx, len, info, more); |
| 278 | + return mt76_dma_get_buf(dev, q, idx, len, info, more, drop); |
| 279 | } |
| 280 | |
| 281 | static int |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 282 | @@ -336,7 +457,7 @@ mt76_dma_tx_queue_skb_raw(struct mt76_dev *dev, struct mt76_queue *q, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 283 | buf.len = skb->len; |
| 284 | |
| 285 | spin_lock_bh(&q->lock); |
| 286 | - mt76_dma_add_buf(dev, q, &buf, 1, tx_info, skb, NULL); |
| 287 | + mt76_dma_add_buf(dev, q, &buf, 1, tx_info, skb, NULL, NULL); |
| 288 | mt76_dma_kick_queue(dev, q); |
| 289 | spin_unlock_bh(&q->lock); |
| 290 | |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 291 | @@ -413,7 +534,7 @@ mt76_dma_tx_queue_skb(struct mt76_dev *dev, struct mt76_queue *q, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 292 | goto unmap; |
| 293 | |
| 294 | return mt76_dma_add_buf(dev, q, tx_info.buf, tx_info.nbuf, |
| 295 | - tx_info.info, tx_info.skb, t); |
| 296 | + tx_info.info, tx_info.skb, t, NULL); |
| 297 | |
| 298 | unmap: |
| 299 | for (n--; n > 0; n--) |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 300 | @@ -448,6 +569,8 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 301 | int frames = 0; |
| 302 | int len = SKB_WITH_OVERHEAD(q->buf_size); |
| 303 | int offset = q->buf_offset; |
| 304 | + struct mtk_wed_device *wed = &dev->mmio.wed; |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 305 | + struct page_frag_cache *rx_page; |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 306 | |
| 307 | if (!q->ndesc) |
| 308 | return 0; |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 309 | @@ -456,10 +579,29 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 310 | |
| 311 | while (q->queued < q->ndesc - 1) { |
| 312 | struct mt76_queue_buf qbuf; |
| 313 | + int type = FIELD_GET(MT_QFLAG_WED_TYPE, q->flags); |
| 314 | + bool skip_alloc = false; |
| 315 | + struct mt76_txwi_cache *r = NULL; |
| 316 | + |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 317 | + rx_page = &q->rx_page; |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 318 | + if (mtk_wed_device_active(wed) && type == MT76_WED_Q_RX) { |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 319 | + rx_page = &wed->rx_page; |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 320 | + r = mt76_get_rxwi(dev); |
| 321 | + if (!r) |
| 322 | + return -ENOMEM; |
| 323 | + |
| 324 | + if (r->buf) { |
| 325 | + skip_alloc = true; |
| 326 | + len = MTK_WED_RX_PKT_SIZE; |
| 327 | + buf = r->buf; |
| 328 | + } |
| 329 | + } |
| 330 | |
| 331 | - buf = page_frag_alloc(&q->rx_page, q->buf_size, GFP_ATOMIC); |
| 332 | - if (!buf) |
| 333 | - break; |
| 334 | + if (!skip_alloc) { |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 335 | + buf = page_frag_alloc(rx_page, q->buf_size, GFP_ATOMIC); |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 336 | + if (!buf) |
| 337 | + break; |
| 338 | + } |
| 339 | |
| 340 | addr = dma_map_single(dev->dma_dev, buf, len, DMA_FROM_DEVICE); |
| 341 | if (unlikely(dma_mapping_error(dev->dma_dev, addr))) { |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 342 | @@ -470,7 +612,7 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 343 | qbuf.addr = addr + offset; |
| 344 | qbuf.len = len - offset; |
| 345 | qbuf.skip_unmap = false; |
| 346 | - mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, NULL); |
| 347 | + mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, NULL, r); |
| 348 | frames++; |
| 349 | } |
| 350 | |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 351 | @@ -516,6 +658,11 @@ mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 352 | if (!ret) |
| 353 | q->wed_regs = wed->txfree_ring.reg_base; |
| 354 | break; |
| 355 | + case MT76_WED_Q_RX: |
| 356 | + ret = mtk_wed_device_rx_ring_setup(wed, ring, q->regs); |
| 357 | + if (!ret) |
| 358 | + q->wed_regs = wed->rx_ring[ring].reg_base; |
| 359 | + break; |
| 360 | default: |
| 361 | ret = -EINVAL; |
| 362 | } |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 363 | @@ -531,7 +678,8 @@ mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 364 | int idx, int n_desc, int bufsize, |
| 365 | u32 ring_base) |
| 366 | { |
| 367 | - int ret, size; |
| 368 | + int ret, size, type; |
| 369 | + struct mtk_wed_device *wed = &dev->mmio.wed; |
| 370 | |
| 371 | spin_lock_init(&q->lock); |
| 372 | spin_lock_init(&q->cleanup_lock); |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 373 | @@ -541,6 +689,11 @@ mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 374 | q->buf_size = bufsize; |
| 375 | q->hw_idx = idx; |
| 376 | |
| 377 | + type = FIELD_GET(MT_QFLAG_WED_TYPE, q->flags); |
| 378 | + if (mtk_wed_device_active(wed) && type == MT76_WED_Q_RX) |
| 379 | + q->buf_size = SKB_DATA_ALIGN(NET_SKB_PAD + MTK_WED_RX_PKT_SIZE) + |
| 380 | + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 381 | + |
| 382 | size = q->ndesc * sizeof(struct mt76_desc); |
| 383 | q->desc = dmam_alloc_coherent(dev->dma_dev, size, &q->desc_dma, GFP_KERNEL); |
| 384 | if (!q->desc) |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 385 | @@ -573,7 +726,7 @@ mt76_dma_rx_cleanup(struct mt76_dev *dev, struct mt76_queue *q) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 386 | |
| 387 | spin_lock_bh(&q->lock); |
| 388 | do { |
| 389 | - buf = mt76_dma_dequeue(dev, q, true, NULL, NULL, &more); |
| 390 | + buf = mt76_dma_dequeue(dev, q, true, NULL, NULL, &more, NULL); |
| 391 | if (!buf) |
| 392 | break; |
| 393 | |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 394 | @@ -614,7 +767,7 @@ mt76_dma_rx_reset(struct mt76_dev *dev, enum mt76_rxq_id qid) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 395 | |
| 396 | static void |
| 397 | mt76_add_fragment(struct mt76_dev *dev, struct mt76_queue *q, void *data, |
| 398 | - int len, bool more) |
| 399 | + int len, bool more, u32 info) |
| 400 | { |
| 401 | struct sk_buff *skb = q->rx_head; |
| 402 | struct skb_shared_info *shinfo = skb_shinfo(skb); |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 403 | @@ -634,7 +787,7 @@ mt76_add_fragment(struct mt76_dev *dev, struct mt76_queue *q, void *data, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 404 | |
| 405 | q->rx_head = NULL; |
| 406 | if (nr_frags < ARRAY_SIZE(shinfo->frags)) |
| 407 | - dev->drv->rx_skb(dev, q - dev->q_rx, skb); |
| 408 | + dev->drv->rx_skb(dev, q - dev->q_rx, skb, info); |
| 409 | else |
| 410 | dev_kfree_skb(skb); |
| 411 | } |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 412 | @@ -655,6 +808,7 @@ mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | while (done < budget) { |
| 416 | + bool drop = false; |
| 417 | u32 info; |
| 418 | |
| 419 | if (check_ddone) { |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 420 | @@ -665,10 +819,13 @@ mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 421 | break; |
| 422 | } |
| 423 | |
| 424 | - data = mt76_dma_dequeue(dev, q, false, &len, &info, &more); |
| 425 | + data = mt76_dma_dequeue(dev, q, false, &len, &info, &more, &drop); |
| 426 | if (!data) |
| 427 | break; |
| 428 | |
| 429 | + if (drop) |
| 430 | + goto free_frag; |
| 431 | + |
| 432 | if (q->rx_head) |
| 433 | data_len = q->buf_size; |
| 434 | else |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 435 | @@ -681,7 +838,7 @@ mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | if (q->rx_head) { |
| 439 | - mt76_add_fragment(dev, q, data, len, more); |
| 440 | + mt76_add_fragment(dev, q, data, len, more, info); |
| 441 | continue; |
| 442 | } |
| 443 | |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 444 | @@ -708,7 +865,7 @@ mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 445 | continue; |
| 446 | } |
| 447 | |
| 448 | - dev->drv->rx_skb(dev, q - dev->q_rx, skb); |
| 449 | + dev->drv->rx_skb(dev, q - dev->q_rx, skb, info); |
| 450 | continue; |
| 451 | |
| 452 | free_frag: |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 453 | @@ -785,7 +942,7 @@ EXPORT_SYMBOL_GPL(mt76_dma_attach); |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 454 | |
| 455 | void mt76_dma_cleanup(struct mt76_dev *dev) |
| 456 | { |
| 457 | - int i; |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 458 | + int i, type; |
developer | d497569 | 2022-07-15 18:30:03 +0800 | [diff] [blame] | 459 | |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 460 | mt76_worker_disable(&dev->tx_worker); |
| 461 | netif_napi_del(&dev->tx_napi); |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 462 | @@ -806,12 +963,17 @@ void mt76_dma_cleanup(struct mt76_dev *dev) |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 463 | |
| 464 | mt76_for_each_q_rx(dev, i) { |
| 465 | netif_napi_del(&dev->napi[i]); |
| 466 | - mt76_dma_rx_cleanup(dev, &dev->q_rx[i]); |
| 467 | + type = FIELD_GET(MT_QFLAG_WED_TYPE, dev->q_rx[i].flags); |
| 468 | + if (type != MT76_WED_Q_RX) |
| 469 | + mt76_dma_rx_cleanup(dev, &dev->q_rx[i]); |
| 470 | } |
| 471 | |
| 472 | mt76_free_pending_txwi(dev); |
| 473 | + mt76_free_pending_rxwi(dev); |
| 474 | |
| 475 | if (mtk_wed_device_active(&dev->mmio.wed)) |
| 476 | mtk_wed_device_detach(&dev->mmio.wed); |
| 477 | + |
| 478 | + mt76_free_pending_rxwi(dev); |
| 479 | } |
| 480 | EXPORT_SYMBOL_GPL(mt76_dma_cleanup); |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 481 | diff --git a/dma.h b/dma.h |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 482 | index fdf786f9..90370d12 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 483 | --- a/dma.h |
| 484 | +++ b/dma.h |
| 485 | @@ -16,6 +16,16 @@ |
| 486 | #define MT_DMA_CTL_LAST_SEC0 BIT(30) |
| 487 | #define MT_DMA_CTL_DMA_DONE BIT(31) |
| 488 | |
| 489 | +#define MT_DMA_CTL_TO_HOST BIT(8) |
| 490 | +#define MT_DMA_CTL_TO_HOST_A BIT(12) |
| 491 | +#define MT_DMA_CTL_DROP BIT(14) |
| 492 | + |
| 493 | +#define MT_DMA_CTL_TOKEN GENMASK(31, 16) |
| 494 | + |
| 495 | +#define MT_DMA_PPE_CPU_REASON GENMASK(15, 11) |
| 496 | +#define MT_DMA_PPE_ENTRY GENMASK(30, 16) |
| 497 | +#define MT_DMA_INFO_PPE_VLD BIT(31) |
| 498 | + |
| 499 | #define MT_DMA_HDR_LEN 4 |
| 500 | #define MT_RX_INFO_LEN 4 |
| 501 | #define MT_FCE_INFO_LEN 4 |
| 502 | diff --git a/mac80211.c b/mac80211.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 503 | index c477d625..4a8d8d8d 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 504 | --- a/mac80211.c |
| 505 | +++ b/mac80211.c |
developer | 20126ad | 2022-09-12 14:42:56 +0800 | [diff] [blame] | 506 | @@ -599,11 +599,14 @@ mt76_alloc_device(struct device *pdev, unsigned int size, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 507 | BIT(NL80211_IFTYPE_ADHOC); |
| 508 | |
| 509 | spin_lock_init(&dev->token_lock); |
| 510 | + spin_lock_init(&dev->rx_token_lock); |
| 511 | idr_init(&dev->token); |
| 512 | + idr_init(&dev->rx_token); |
| 513 | |
| 514 | INIT_LIST_HEAD(&dev->wcid_list); |
| 515 | |
| 516 | INIT_LIST_HEAD(&dev->txwi_cache); |
| 517 | + INIT_LIST_HEAD(&dev->rxwi_cache); |
| 518 | dev->token_size = dev->drv->token_size; |
| 519 | |
| 520 | for (i = 0; i < ARRAY_SIZE(dev->q_rx); i++) |
developer | 20126ad | 2022-09-12 14:42:56 +0800 | [diff] [blame] | 521 | @@ -1301,7 +1304,10 @@ void mt76_rx_poll_complete(struct mt76_dev *dev, enum mt76_rxq_id q, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 522 | |
| 523 | while ((skb = __skb_dequeue(&dev->rx_skb[q])) != NULL) { |
| 524 | mt76_check_sta(dev, skb); |
| 525 | - mt76_rx_aggr_reorder(skb, &frames); |
| 526 | + if (mtk_wed_device_active(&dev->mmio.wed)) |
| 527 | + __skb_queue_tail(&frames, skb); |
| 528 | + else |
| 529 | + mt76_rx_aggr_reorder(skb, &frames); |
| 530 | } |
| 531 | |
| 532 | mt76_rx_complete(dev, &frames, napi); |
| 533 | diff --git a/mt76.h b/mt76.h |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 534 | index ec9bd59d..f19433d4 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 535 | --- a/mt76.h |
| 536 | +++ b/mt76.h |
| 537 | @@ -20,6 +20,8 @@ |
| 538 | |
| 539 | #define MT_MCU_RING_SIZE 32 |
| 540 | #define MT_RX_BUF_SIZE 2048 |
| 541 | +#define MTK_WED_RX_PKT_SIZE 1700 |
| 542 | + |
| 543 | #define MT_SKB_HEAD_LEN 256 |
| 544 | |
| 545 | #define MT_MAX_NON_AQL_PKT 16 |
| 546 | @@ -35,6 +37,7 @@ |
| 547 | FIELD_PREP(MT_QFLAG_WED_TYPE, _type) | \ |
| 548 | FIELD_PREP(MT_QFLAG_WED_RING, _n)) |
| 549 | #define MT_WED_Q_TX(_n) __MT_WED_Q(MT76_WED_Q_TX, _n) |
| 550 | +#define MT_WED_Q_RX(_n) __MT_WED_Q(MT76_WED_Q_RX, _n) |
| 551 | #define MT_WED_Q_TXFREE __MT_WED_Q(MT76_WED_Q_TXFREE, 0) |
| 552 | |
| 553 | struct mt76_dev; |
| 554 | @@ -56,6 +59,7 @@ enum mt76_bus_type { |
| 555 | enum mt76_wed_type { |
| 556 | MT76_WED_Q_TX, |
| 557 | MT76_WED_Q_TXFREE, |
| 558 | + MT76_WED_Q_RX, |
| 559 | }; |
| 560 | |
| 561 | struct mt76_bus_ops { |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 562 | @@ -339,7 +343,10 @@ struct mt76_txwi_cache { |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 563 | struct list_head list; |
| 564 | dma_addr_t dma_addr; |
| 565 | |
| 566 | - struct sk_buff *skb; |
| 567 | + union { |
| 568 | + void *buf; |
| 569 | + struct sk_buff *skb; |
| 570 | + }; |
| 571 | }; |
| 572 | |
| 573 | struct mt76_rx_tid { |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 574 | @@ -438,7 +445,7 @@ struct mt76_driver_ops { |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 575 | bool (*rx_check)(struct mt76_dev *dev, void *data, int len); |
| 576 | |
| 577 | void (*rx_skb)(struct mt76_dev *dev, enum mt76_rxq_id q, |
| 578 | - struct sk_buff *skb); |
| 579 | + struct sk_buff *skb, u32 info); |
| 580 | |
| 581 | void (*rx_poll_complete)(struct mt76_dev *dev, enum mt76_rxq_id q); |
| 582 | |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 583 | @@ -783,6 +790,7 @@ struct mt76_dev { |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 584 | struct ieee80211_hw *hw; |
| 585 | |
| 586 | spinlock_t lock; |
| 587 | + spinlock_t wed_lock; |
| 588 | spinlock_t cc_lock; |
| 589 | |
| 590 | u32 cur_cc_bss_rx; |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 591 | @@ -808,6 +816,7 @@ struct mt76_dev { |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 592 | struct sk_buff_head rx_skb[__MT_RXQ_MAX]; |
| 593 | |
| 594 | struct list_head txwi_cache; |
| 595 | + struct list_head rxwi_cache; |
| 596 | struct mt76_queue *q_mcu[__MT_MCUQ_MAX]; |
| 597 | struct mt76_queue q_rx[__MT_RXQ_MAX]; |
| 598 | const struct mt76_queue_ops *queue_ops; |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 599 | @@ -821,6 +830,9 @@ struct mt76_dev { |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 600 | u16 wed_token_count; |
| 601 | u16 token_count; |
| 602 | u16 token_size; |
| 603 | + u16 rx_token_size; |
| 604 | + spinlock_t rx_token_lock; |
| 605 | + struct idr rx_token; |
| 606 | |
| 607 | wait_queue_head_t tx_wait; |
| 608 | /* spinclock used to protect wcid pktid linked list */ |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 609 | @@ -1365,6 +1377,8 @@ mt76_tx_status_get_hw(struct mt76_dev *dev, struct sk_buff *skb) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | void mt76_put_txwi(struct mt76_dev *dev, struct mt76_txwi_cache *t); |
| 613 | +void mt76_put_rxwi(struct mt76_dev *dev, struct mt76_txwi_cache *t); |
| 614 | +struct mt76_txwi_cache *mt76_get_rxwi(struct mt76_dev *dev); |
| 615 | void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames, |
| 616 | struct napi_struct *napi); |
| 617 | void mt76_rx_poll_complete(struct mt76_dev *dev, enum mt76_rxq_id q, |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 618 | @@ -1509,6 +1523,12 @@ struct mt76_txwi_cache * |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 619 | mt76_token_release(struct mt76_dev *dev, int token, bool *wake); |
| 620 | int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi); |
| 621 | void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked); |
| 622 | +int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr, |
| 623 | + struct mt76_txwi_cache *r, dma_addr_t phys); |
| 624 | +void skb_trace(const struct sk_buff *skb, bool full_pkt); |
| 625 | + |
| 626 | +struct mt76_txwi_cache * |
| 627 | +mt76_rx_token_release(struct mt76_dev *dev, int token); |
| 628 | |
| 629 | static inline void mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked) |
| 630 | { |
| 631 | diff --git a/mt7603/dma.c b/mt7603/dma.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 632 | index 590cff9d..2ff71c53 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 633 | --- a/mt7603/dma.c |
| 634 | +++ b/mt7603/dma.c |
| 635 | @@ -69,7 +69,7 @@ free: |
| 636 | } |
| 637 | |
| 638 | void mt7603_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
| 639 | - struct sk_buff *skb) |
| 640 | + struct sk_buff *skb, u32 info) |
| 641 | { |
| 642 | struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76); |
| 643 | __le32 *rxd = (__le32 *)skb->data; |
| 644 | diff --git a/mt7603/mt7603.h b/mt7603/mt7603.h |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 645 | index 0fd46d90..f2ce22ae 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 646 | --- a/mt7603/mt7603.h |
| 647 | +++ b/mt7603/mt7603.h |
| 648 | @@ -244,7 +244,7 @@ int mt7603_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 649 | void mt7603_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e); |
| 650 | |
| 651 | void mt7603_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
| 652 | - struct sk_buff *skb); |
| 653 | + struct sk_buff *skb, u32 info); |
| 654 | void mt7603_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q); |
| 655 | void mt7603_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps); |
| 656 | int mt7603_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, |
| 657 | diff --git a/mt7615/mac.c b/mt7615/mac.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 658 | index d6aae60c..4774eaab 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 659 | --- a/mt7615/mac.c |
| 660 | +++ b/mt7615/mac.c |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 661 | @@ -1651,7 +1651,7 @@ bool mt7615_rx_check(struct mt76_dev *mdev, void *data, int len) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 662 | EXPORT_SYMBOL_GPL(mt7615_rx_check); |
| 663 | |
| 664 | void mt7615_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
| 665 | - struct sk_buff *skb) |
| 666 | + struct sk_buff *skb, u32 info) |
| 667 | { |
| 668 | struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76); |
| 669 | __le32 *rxd = (__le32 *)skb->data; |
| 670 | diff --git a/mt7615/mt7615.h b/mt7615/mt7615.h |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 671 | index 060d52c8..232b0f29 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 672 | --- a/mt7615/mt7615.h |
| 673 | +++ b/mt7615/mt7615.h |
| 674 | @@ -511,7 +511,7 @@ void mt7615_tx_worker(struct mt76_worker *w); |
| 675 | void mt7615_tx_token_put(struct mt7615_dev *dev); |
| 676 | bool mt7615_rx_check(struct mt76_dev *mdev, void *data, int len); |
| 677 | void mt7615_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
| 678 | - struct sk_buff *skb); |
| 679 | + struct sk_buff *skb, u32 info); |
| 680 | void mt7615_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps); |
| 681 | int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, |
| 682 | struct ieee80211_sta *sta); |
| 683 | diff --git a/mt76_connac_mcu.c b/mt76_connac_mcu.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 684 | index 36a2914e..290e9711 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 685 | --- a/mt76_connac_mcu.c |
| 686 | +++ b/mt76_connac_mcu.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 687 | @@ -1192,6 +1192,7 @@ int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif *mvif, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 688 | int cmd, bool enable, bool tx) |
| 689 | { |
| 690 | struct mt76_wcid *wcid = (struct mt76_wcid *)params->sta->drv_priv; |
| 691 | + struct mtk_wed_device *wed = &dev->mmio.wed; |
| 692 | struct wtbl_req_hdr *wtbl_hdr; |
| 693 | struct tlv *sta_wtbl; |
| 694 | struct sk_buff *skb; |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 695 | @@ -1212,6 +1213,8 @@ int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif *mvif, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 696 | mt76_connac_mcu_wtbl_ba_tlv(dev, skb, params, enable, tx, sta_wtbl, |
| 697 | wtbl_hdr); |
| 698 | |
| 699 | + if (mtk_wed_device_active(wed) && wed->ver > MTK_WED_V1) |
| 700 | + mtk_wed_device_update_msg(wed, WED_WO_STA_REC, skb->data, skb->len); |
| 701 | ret = mt76_mcu_skb_send_msg(dev, skb, cmd, true); |
| 702 | if (ret) |
| 703 | return ret; |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 704 | @@ -1222,6 +1225,8 @@ int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif *mvif, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 705 | |
| 706 | mt76_connac_mcu_sta_ba_tlv(skb, params, enable, tx); |
| 707 | |
| 708 | + if (mtk_wed_device_active(wed) && wed->ver > MTK_WED_V1) |
| 709 | + mtk_wed_device_update_msg(wed, WED_WO_STA_REC, skb->data, skb->len); |
| 710 | return mt76_mcu_skb_send_msg(dev, skb, cmd, true); |
| 711 | } |
| 712 | EXPORT_SYMBOL_GPL(mt76_connac_mcu_sta_ba); |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 713 | @@ -2636,6 +2641,7 @@ int mt76_connac_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 714 | struct mt76_wcid *wcid, enum set_key_cmd cmd) |
| 715 | { |
| 716 | struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; |
| 717 | + struct mtk_wed_device *wed = &dev->mmio.wed; |
| 718 | struct sk_buff *skb; |
| 719 | int ret; |
| 720 | |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 721 | @@ -2647,6 +2653,9 @@ int mt76_connac_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 722 | if (ret) |
| 723 | return ret; |
| 724 | |
| 725 | + if (mtk_wed_device_active(wed) && wed->ver > MTK_WED_V1) |
| 726 | + mtk_wed_device_update_msg(wed, WED_WO_STA_REC, skb->data, skb->len); |
| 727 | + |
| 728 | return mt76_mcu_skb_send_msg(dev, skb, mcu_cmd, true); |
| 729 | } |
| 730 | EXPORT_SYMBOL_GPL(mt76_connac_mcu_add_key); |
| 731 | diff --git a/mt76x02.h b/mt76x02.h |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 732 | index f76fd22e..0b872af1 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 733 | --- a/mt76x02.h |
| 734 | +++ b/mt76x02.h |
| 735 | @@ -173,7 +173,7 @@ int mt76x02_set_rts_threshold(struct ieee80211_hw *hw, u32 val); |
| 736 | void mt76x02_remove_hdr_pad(struct sk_buff *skb, int len); |
| 737 | bool mt76x02_tx_status_data(struct mt76_dev *mdev, u8 *update); |
| 738 | void mt76x02_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
| 739 | - struct sk_buff *skb); |
| 740 | + struct sk_buff *skb, u32 info); |
| 741 | void mt76x02_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q); |
| 742 | irqreturn_t mt76x02_irq_handler(int irq, void *dev_instance); |
| 743 | void mt76x02_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, |
| 744 | diff --git a/mt76x02_txrx.c b/mt76x02_txrx.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 745 | index 96fdf423..bf24d3e0 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 746 | --- a/mt76x02_txrx.c |
| 747 | +++ b/mt76x02_txrx.c |
| 748 | @@ -33,7 +33,7 @@ void mt76x02_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, |
| 749 | EXPORT_SYMBOL_GPL(mt76x02_tx); |
| 750 | |
| 751 | void mt76x02_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
| 752 | - struct sk_buff *skb) |
| 753 | + struct sk_buff *skb, u32 info) |
| 754 | { |
| 755 | struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76); |
| 756 | void *rxwi = skb->data; |
| 757 | diff --git a/mt7915/dma.c b/mt7915/dma.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 758 | index ac30698f..197a0169 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 759 | --- a/mt7915/dma.c |
| 760 | +++ b/mt7915/dma.c |
developer | 36936c3 | 2022-09-30 12:55:06 +0800 | [diff] [blame^] | 761 | @@ -337,7 +337,8 @@ static int mt7915_dma_enable(struct mt7915_dev *dev) |
| 762 | wed_irq_mask |= MT_INT_TX_DONE_BAND0 | MT_INT_TX_DONE_BAND1; |
| 763 | if (!is_mt7986(&dev->mt76)) |
| 764 | mt76_wr(dev, MT_INT_WED_MASK_CSR, wed_irq_mask); |
| 765 | - mt76_wr(dev, MT_INT_MASK_CSR, wed_irq_mask); |
| 766 | + else |
| 767 | + mt76_wr(dev, MT_INT_MASK_CSR, wed_irq_mask); |
| 768 | mtk_wed_device_start(&dev->mt76.mmio.wed, wed_irq_mask); |
| 769 | } |
| 770 | |
| 771 | @@ -349,6 +350,7 @@ static int mt7915_dma_enable(struct mt7915_dev *dev) |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 772 | int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2) |
| 773 | { |
| 774 | struct mt76_dev *mdev = &dev->mt76; |
| 775 | + struct mtk_wed_device *wed = &mdev->mmio.wed; |
| 776 | u32 wa_rx_base, wa_rx_idx; |
| 777 | u32 hif1_ofs = 0; |
| 778 | int ret; |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 779 | @@ -365,10 +366,12 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2) |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 780 | if (mtk_wed_device_active(&dev->mt76.mmio.wed) && !is_mt7986(mdev)) { |
| 781 | mt76_set(dev, MT_WFDMA_HOST_CONFIG, MT_WFDMA_HOST_CONFIG_WED); |
| 782 | if(is_mt7915(mdev)) { |
| 783 | - mt76_wr(dev, MT_WFDMA_WED_RING_CONTROL, |
| 784 | - FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_TX0, 18) | |
| 785 | - FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_TX1, 19) | |
| 786 | - FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_RX1, 1)); |
| 787 | + mt76_wr(dev, MT_WFDMA_WED_RING_CONTROL, |
| 788 | + FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_TX0, 18) | |
| 789 | + FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_TX1, 19) | |
| 790 | + FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_RX1, 1)); |
| 791 | + mt76_rmw(dev, MT_WFDMA0_EXT0_CFG, MT_WFDMA0_EXT0_RXWB_KEEP, |
| 792 | + MT_WFDMA0_EXT0_RXWB_KEEP); |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 793 | } else { |
| 794 | mt76_wr(dev, MT_WFDMA_WED_RING_CONTROL, |
| 795 | FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_TX0, 18) | |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 796 | @@ -428,7 +431,7 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2) |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 797 | return ret; |
| 798 | |
| 799 | /* event from WA */ |
| 800 | - if (mtk_wed_device_active(&dev->mt76.mmio.wed) && is_mt7915(mdev)) { |
| 801 | + if (mtk_wed_device_active(wed) && is_mt7915(mdev)) { |
| 802 | wa_rx_base = MT_WED_RX_RING_BASE; |
| 803 | wa_rx_idx = MT7915_RXQ_MCU_WA; |
| 804 | dev->mt76.q_rx[MT_RXQ_MCU_WA].flags = MT_WED_Q_TXFREE; |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 805 | @@ -444,6 +447,11 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 806 | |
| 807 | /* rx data queue for band0 */ |
| 808 | if (!dev->phy.band_idx) { |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 809 | + if (mtk_wed_device_active(wed) && wed->ver > MTK_WED_V1) { |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 810 | + dev->mt76.q_rx[MT_RXQ_MAIN].flags = MT_WED_Q_RX(MT7915_RXQ_BAND0); |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 811 | + dev->mt76.rx_token_size += MT7915_RX_RING_SIZE; |
| 812 | + } |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 813 | + |
| 814 | ret = mt76_queue_alloc(dev, &dev->mt76.q_rx[MT_RXQ_MAIN], |
| 815 | MT_RXQ_ID(MT_RXQ_MAIN), |
| 816 | MT7915_RX_RING_SIZE, |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 817 | @@ -458,7 +466,7 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2) |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 818 | wa_rx_base = MT_RXQ_RING_BASE(MT_RXQ_MAIN_WA); |
| 819 | wa_rx_idx = MT_RXQ_ID(MT_RXQ_MAIN_WA); |
| 820 | |
| 821 | - if (mtk_wed_device_active(&dev->mt76.mmio.wed)) { |
| 822 | + if (mtk_wed_device_active(wed)) { |
| 823 | dev->mt76.q_rx[MT_RXQ_MAIN_WA].flags = MT_WED_Q_TXFREE; |
| 824 | if (is_mt7916(mdev)) { |
| 825 | wa_rx_base = MT_WED_RX_RING_BASE; |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 826 | @@ -474,6 +482,11 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2) |
| 827 | } |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 828 | |
| 829 | if (dev->dbdc_support || dev->phy.band_idx) { |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 830 | + if (mtk_wed_device_active(wed) && wed->ver > MTK_WED_V1) { |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 831 | + dev->mt76.q_rx[MT_RXQ_BAND1].flags = MT_WED_Q_RX(MT7915_RXQ_BAND1); |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 832 | + dev->mt76.rx_token_size += MT7915_RX_RING_SIZE; |
| 833 | + } |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 834 | + |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 835 | /* rx data queue for band1 */ |
| 836 | ret = mt76_queue_alloc(dev, &dev->mt76.q_rx[MT_RXQ_BAND1], |
| 837 | MT_RXQ_ID(MT_RXQ_BAND1), |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 838 | diff --git a/mt7915/mac.c b/mt7915/mac.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 839 | index b1788fb8..4e0c3ec4 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 840 | --- a/mt7915/mac.c |
| 841 | +++ b/mt7915/mac.c |
| 842 | @@ -217,7 +217,7 @@ static void mt7915_mac_sta_poll(struct mt7915_dev *dev) |
| 843 | } |
| 844 | |
| 845 | static int |
| 846 | -mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb) |
| 847 | +mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb, enum mt76_rxq_id q, u32 info) |
| 848 | { |
| 849 | struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; |
| 850 | struct mt76_phy *mphy = &dev->mt76.phy; |
| 851 | @@ -494,6 +494,27 @@ mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb) |
| 852 | #endif |
| 853 | } else { |
| 854 | status->flag |= RX_FLAG_8023; |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 855 | + if (msta && msta->vif) { |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 856 | + struct mtk_wed_device *wed; |
| 857 | + int type; |
| 858 | + |
| 859 | + wed = &dev->mt76.mmio.wed; |
| 860 | + type = FIELD_GET(MT_QFLAG_WED_TYPE, dev->mt76.q_rx[q].flags); |
| 861 | + if ((mtk_wed_device_active(wed) && type == MT76_WED_Q_RX) && |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 862 | + (info & MT_DMA_INFO_PPE_VLD)) { |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 863 | + struct ieee80211_vif *vif; |
| 864 | + u32 hash, reason; |
| 865 | + |
| 866 | + vif = container_of((void *)msta->vif, struct ieee80211_vif, |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 867 | + drv_priv); |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 868 | + |
| 869 | + skb->dev = ieee80211_vif_to_netdev(vif); |
| 870 | + reason = FIELD_GET(MT_DMA_PPE_CPU_REASON, info); |
| 871 | + hash = FIELD_GET(MT_DMA_PPE_ENTRY, info); |
| 872 | + |
| 873 | + mtk_wed_device_ppe_check(wed, skb, reason, hash); |
| 874 | + } |
| 875 | + } |
| 876 | } |
| 877 | |
| 878 | if (rxv && mode >= MT_PHY_TYPE_HE_SU && !(status->flag & RX_FLAG_8023)) |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 879 | @@ -831,6 +852,80 @@ u32 mt7915_wed_init_buf(void *ptr, dma_addr_t phys, int token_id) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 880 | return MT_TXD_TXP_BUF_SIZE; |
| 881 | } |
| 882 | |
| 883 | +u32 |
| 884 | +mt7915_wed_init_rx_buf(struct mtk_wed_device *wed, int pkt_num) |
| 885 | +{ |
| 886 | + struct mtk_rxbm_desc *desc = wed->rx_buf_ring.desc; |
| 887 | + struct mt7915_dev *dev; |
| 888 | + dma_addr_t buf_phys; |
| 889 | + void *buf; |
| 890 | + int i, token, buf_size; |
| 891 | + |
| 892 | + buf_size = SKB_DATA_ALIGN(NET_SKB_PAD + wed->wlan.rx_pkt_size) + |
| 893 | + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 894 | + |
| 895 | + dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| 896 | + for (i = 0; i < pkt_num; i++) { |
| 897 | + struct mt76_txwi_cache *r = mt76_get_rxwi(&dev->mt76); |
| 898 | + |
| 899 | + buf = page_frag_alloc(&wed->rx_page, buf_size, GFP_ATOMIC); |
| 900 | + if (!buf) |
| 901 | + return -ENOMEM; |
| 902 | + |
| 903 | + buf_phys = dma_map_single(dev->mt76.dma_dev, buf, wed->wlan.rx_pkt_size, |
| 904 | + DMA_TO_DEVICE); |
| 905 | + |
| 906 | + if (unlikely(dma_mapping_error(dev->mt76.dev, buf_phys))) { |
| 907 | + skb_free_frag(buf); |
| 908 | + break; |
| 909 | + } |
| 910 | + |
| 911 | + desc->buf0 = buf_phys; |
| 912 | + |
| 913 | + token = mt76_rx_token_consume(&dev->mt76, buf, r, buf_phys); |
| 914 | + |
| 915 | + desc->token |= FIELD_PREP(MT_DMA_CTL_TOKEN, token); |
| 916 | + desc++; |
| 917 | + } |
| 918 | + |
| 919 | + return 0; |
| 920 | +} |
| 921 | + |
| 922 | +void mt7915_wed_release_rx_buf(struct mtk_wed_device *wed) |
| 923 | +{ |
| 924 | + struct mt76_txwi_cache *rxwi; |
| 925 | + struct mt7915_dev *dev; |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 926 | + struct page *page; |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 927 | + int token; |
| 928 | + |
| 929 | + dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| 930 | + |
| 931 | + for(token = 0; token < dev->mt76.rx_token_size; token++) { |
| 932 | + rxwi = mt76_rx_token_release(&dev->mt76, token); |
| 933 | + if(!rxwi) |
| 934 | + continue; |
| 935 | + |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 936 | + if(!rxwi->buf) |
| 937 | + continue; |
| 938 | + |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 939 | + dma_unmap_single(dev->mt76.dma_dev, rxwi->dma_addr, |
| 940 | + wed->wlan.rx_pkt_size, DMA_FROM_DEVICE); |
| 941 | + skb_free_frag(rxwi->buf); |
| 942 | + rxwi->buf = NULL; |
| 943 | + |
| 944 | + mt76_put_rxwi(&dev->mt76, rxwi); |
| 945 | + } |
developer | 29f66b3 | 2022-07-12 15:23:20 +0800 | [diff] [blame] | 946 | + |
| 947 | + if (wed->rx_page.va) |
| 948 | + return; |
| 949 | + |
| 950 | + page = virt_to_page(wed->rx_page.va); |
| 951 | + __page_frag_cache_drain(page, wed->rx_page.pagecnt_bias); |
| 952 | + memset(&wed->rx_page, 0, sizeof(wed->rx_page)); |
| 953 | + |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 954 | + return; |
| 955 | +} |
| 956 | + |
| 957 | static void |
| 958 | mt7915_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi) |
| 959 | { |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 960 | @@ -1110,7 +1205,7 @@ bool mt7915_rx_check(struct mt76_dev *mdev, void *data, int len) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | void mt7915_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
| 964 | - struct sk_buff *skb) |
| 965 | + struct sk_buff *skb, u32 info) |
| 966 | { |
| 967 | struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76); |
| 968 | __le32 *rxd = (__le32 *)skb->data; |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 969 | @@ -1144,7 +1239,7 @@ void mt7915_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 970 | dev_kfree_skb(skb); |
| 971 | break; |
| 972 | case PKT_TYPE_NORMAL: |
| 973 | - if (!mt7915_mac_fill_rx(dev, skb)) { |
| 974 | + if (!mt7915_mac_fill_rx(dev, skb, q, info)) { |
| 975 | mt76_rx(&dev->mt76, q, skb); |
| 976 | return; |
| 977 | } |
| 978 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 979 | index 21167f00..aa8bcf70 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 980 | --- a/mt7915/mcu.c |
| 981 | +++ b/mt7915/mcu.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 982 | @@ -1724,6 +1724,7 @@ int mt7915_mcu_add_sta(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 983 | struct ieee80211_sta *sta, bool enable) |
| 984 | { |
| 985 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 986 | + struct mtk_wed_device *wed = &dev->mt76.mmio.wed; |
| 987 | struct mt7915_sta *msta; |
| 988 | struct sk_buff *skb; |
| 989 | int ret; |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 990 | @@ -1776,6 +1777,8 @@ int mt7915_mcu_add_sta(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 991 | return ret; |
| 992 | } |
| 993 | out: |
| 994 | + if (mtk_wed_device_active(wed) && wed->ver > MTK_WED_V1) |
| 995 | + mtk_wed_device_update_msg(wed, WED_WO_STA_REC, skb->data, skb->len); |
| 996 | return mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 997 | MCU_EXT_CMD(STA_REC_UPDATE), true); |
| 998 | } |
| 999 | diff --git a/mt7915/mmio.c b/mt7915/mmio.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1000 | index 6df039a7..6e07311d 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1001 | --- a/mt7915/mmio.c |
| 1002 | +++ b/mt7915/mmio.c |
| 1003 | @@ -28,6 +28,9 @@ static const u32 mt7915_reg[] = { |
| 1004 | [FW_EXCEPTION_ADDR] = 0x219848, |
| 1005 | [SWDEF_BASE_ADDR] = 0x41f200, |
| 1006 | [EXCEPTION_BASE_ADDR] = 0x219848, |
| 1007 | + [WED_TX_RING] = 0xd7300, |
| 1008 | + [WED_RX_RING] = 0xd7410, |
| 1009 | + [WED_RX_DATA_RING] = 0xd4500, |
| 1010 | }; |
| 1011 | |
| 1012 | static const u32 mt7916_reg[] = { |
| 1013 | @@ -45,6 +48,9 @@ static const u32 mt7916_reg[] = { |
| 1014 | [FW_EXCEPTION_ADDR] = 0x022050bc, |
| 1015 | [SWDEF_BASE_ADDR] = 0x411400, |
| 1016 | [EXCEPTION_BASE_ADDR] = 0x022050BC, |
| 1017 | + [WED_TX_RING] = 0xd7300, |
| 1018 | + [WED_RX_RING] = 0xd7410, |
| 1019 | + [WED_RX_DATA_RING] = 0xd4540, |
| 1020 | }; |
| 1021 | |
| 1022 | static const u32 mt7986_reg[] = { |
| 1023 | @@ -62,6 +68,9 @@ static const u32 mt7986_reg[] = { |
| 1024 | [FW_EXCEPTION_ADDR] = 0x02204ffc, |
| 1025 | [SWDEF_BASE_ADDR] = 0x411400, |
| 1026 | [EXCEPTION_BASE_ADDR] = 0x02204FFC, |
| 1027 | + [WED_TX_RING] = 0x24420, |
| 1028 | + [WED_RX_RING] = 0x24520, |
| 1029 | + [WED_RX_DATA_RING] = 0x24540, |
| 1030 | }; |
| 1031 | |
| 1032 | static const u32 mt7915_offs[] = { |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1033 | @@ -712,6 +721,7 @@ mt7915_pci_wed_init(struct mt7915_dev *dev, struct device *pdev, int *irq) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1034 | wed->wlan.bus_type = MTK_BUS_TYPE_PCIE; |
| 1035 | wed->wlan.wpdma_int = base + MT_INT_WED_SOURCE_CSR; |
| 1036 | wed->wlan.wpdma_mask = base + MT_INT_WED_MASK_CSR; |
| 1037 | + wed->wlan.wpdma_phys = base + MT_WFDMA_EXT_CSR_BASE; |
| 1038 | } else { |
| 1039 | struct platform_device *plat_dev; |
| 1040 | struct resource *res; |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1041 | @@ -724,12 +734,19 @@ mt7915_pci_wed_init(struct mt7915_dev *dev, struct device *pdev, int *irq) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1042 | wed->wlan.wpdma_int = base + MT_INT_SOURCE_CSR; |
| 1043 | wed->wlan.wpdma_mask = base + MT_INT_MASK_CSR; |
| 1044 | } |
| 1045 | + wed->wlan.rx_pkt = MT7915_WED_RX_TOKEN_SIZE; |
| 1046 | + wed->wlan.phy_base = base; |
| 1047 | wed->wlan.wpdma_tx = base + MT_TXQ_WED_RING_BASE; |
| 1048 | wed->wlan.wpdma_txfree = base + MT_RXQ_WED_RING_BASE; |
| 1049 | + wed->wlan.wpdma_rx_glo = base + MT_WPDMA_GLO_CFG; |
| 1050 | + wed->wlan.wpdma_rx = base + MT_RXQ_WED_DATA_RING_BASE; |
| 1051 | |
| 1052 | wed->wlan.tx_tbit[0] = MT_WED_TX_DONE_BAND0; |
| 1053 | wed->wlan.tx_tbit[1] = MT_WED_TX_DONE_BAND1; |
| 1054 | wed->wlan.txfree_tbit = MT_WED_TX_FREE_DONE; |
| 1055 | + wed->wlan.rx_tbit[0] = MT_WED_RX_DONE_BAND0; |
| 1056 | + wed->wlan.rx_tbit[1] = MT_WED_RX_DONE_BAND1; |
| 1057 | + |
| 1058 | wed->wlan.nbuf = 7168; |
| 1059 | wed->wlan.token_start = MT7915_TOKEN_SIZE - wed->wlan.nbuf; |
| 1060 | wed->wlan.init_buf = mt7915_wed_init_buf; |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1061 | @@ -739,12 +756,15 @@ mt7915_pci_wed_init(struct mt7915_dev *dev, struct device *pdev, int *irq) |
| 1062 | if (!is_mt7915(mdev)) |
| 1063 | wed->wlan.wcid_512 = true; |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1064 | |
| 1065 | + wed->wlan.rx_nbuf = 65536; |
| 1066 | + wed->wlan.rx_pkt_size = MTK_WED_RX_PKT_SIZE; |
| 1067 | + wed->wlan.init_rx_buf = mt7915_wed_init_rx_buf; |
| 1068 | + wed->wlan.release_rx_buf = mt7915_wed_release_rx_buf; |
| 1069 | + |
developer | c89c547 | 2022-08-02 13:00:04 +0800 | [diff] [blame] | 1070 | + dev->mt76.rx_token_size = wed->wlan.rx_pkt; |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1071 | if (mtk_wed_device_attach(wed) != 0) |
| 1072 | return 0; |
| 1073 | |
| 1074 | - if (wed->ver == MTK_WED_V1) |
| 1075 | - wed->wlan.wpdma_phys = base + MT_WFDMA_EXT_CSR_BASE; |
| 1076 | - |
| 1077 | *irq = wed->irq; |
| 1078 | dev->mt76.dma_dev = wed->dev; |
| 1079 | mdev->token_size = wed->wlan.token_start; |
| 1080 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1081 | index 486c203c..2da2ff8b 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1082 | --- a/mt7915/mt7915.h |
| 1083 | +++ b/mt7915/mt7915.h |
developer | 20126ad | 2022-09-12 14:42:56 +0800 | [diff] [blame] | 1084 | @@ -81,6 +81,7 @@ |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1085 | #define MT7915_MAX_STA_TWT_AGRT 8 |
| 1086 | #define MT7915_MIN_TWT_DUR 64 |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 1087 | #define MT7915_MAX_QUEUE (MT_RXQ_BAND2 + __MT_MCUQ_MAX + 2) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1088 | +#define MT7915_WED_RX_TOKEN_SIZE 12288 |
| 1089 | |
| 1090 | struct mt7915_vif; |
| 1091 | struct mt7915_sta; |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1092 | @@ -545,7 +546,9 @@ void mt7915_wfsys_reset(struct mt7915_dev *dev); |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1093 | irqreturn_t mt7915_irq_handler(int irq, void *dev_instance); |
| 1094 | u64 __mt7915_get_tsf(struct ieee80211_hw *hw, struct mt7915_vif *mvif); |
| 1095 | u32 mt7915_wed_init_buf(void *ptr, dma_addr_t phys, int token_id); |
| 1096 | - |
| 1097 | +u32 mt7915_wed_init_rx_buf(struct mtk_wed_device *wed, |
| 1098 | + int pkt_num); |
| 1099 | +void mt7915_wed_release_rx_buf(struct mtk_wed_device *wed); |
| 1100 | int mt7915_register_device(struct mt7915_dev *dev); |
| 1101 | void mt7915_unregister_device(struct mt7915_dev *dev); |
| 1102 | int mt7915_eeprom_init(struct mt7915_dev *dev); |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1103 | @@ -698,7 +701,7 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1104 | struct mt76_tx_info *tx_info); |
| 1105 | void mt7915_tx_token_put(struct mt7915_dev *dev); |
| 1106 | void mt7915_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
| 1107 | - struct sk_buff *skb); |
| 1108 | + struct sk_buff *skb, u32 info); |
| 1109 | bool mt7915_rx_check(struct mt76_dev *mdev, void *data, int len); |
developer | 20126ad | 2022-09-12 14:42:56 +0800 | [diff] [blame] | 1110 | bool mt7915_wed_wds_check(struct mt76_dev *mdev, struct ieee80211_sta *sta); |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1111 | void mt7915_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps); |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1112 | diff --git a/mt7915/regs.h b/mt7915/regs.h |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1113 | index 51eb553c..dcb40181 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1114 | --- a/mt7915/regs.h |
| 1115 | +++ b/mt7915/regs.h |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 1116 | @@ -27,6 +27,9 @@ enum reg_rev { |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1117 | FW_EXCEPTION_ADDR, |
| 1118 | SWDEF_BASE_ADDR, |
| 1119 | EXCEPTION_BASE_ADDR, |
| 1120 | + WED_TX_RING, |
| 1121 | + WED_RX_RING, |
| 1122 | + WED_RX_DATA_RING, |
| 1123 | __MT_REG_MAX, |
| 1124 | }; |
| 1125 | |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1126 | @@ -568,9 +571,13 @@ enum offs_rev { |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1127 | #define MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2 BIT(21) |
| 1128 | |
| 1129 | #define MT_WFDMA0_RST_DTX_PTR MT_WFDMA0(0x20c) |
| 1130 | +#define MT_WFDMA0_EXT0_CFG MT_WFDMA0(0x2b0) |
| 1131 | +#define MT_WFDMA0_EXT0_RXWB_KEEP BIT(10) |
| 1132 | + |
| 1133 | #define MT_WFDMA0_PRI_DLY_INT_CFG0 MT_WFDMA0(0x2f0) |
| 1134 | #define MT_WFDMA0_PRI_DLY_INT_CFG1 MT_WFDMA0(0x2f4) |
| 1135 | #define MT_WFDMA0_PRI_DLY_INT_CFG2 MT_WFDMA0(0x2f8) |
| 1136 | +#define MT_WPDMA_GLO_CFG MT_WFDMA0(0x208) |
| 1137 | |
| 1138 | #define MT_WFDMA0_MCU_HOST_INT_ENA MT_WFDMA0(0x1f4) |
| 1139 | #define MT_WFDMA0_MT_WA_WDT_INT BIT(31) |
developer | 36936c3 | 2022-09-30 12:55:06 +0800 | [diff] [blame^] | 1140 | @@ -668,12 +675,18 @@ enum offs_rev { |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1141 | #define MT_TXQ_EXT_CTRL(q) (MT_Q_BASE(__TXQ(q)) + 0x600 + \ |
| 1142 | MT_TXQ_ID(q)* 0x4) |
| 1143 | |
| 1144 | -#define MT_TXQ_WED_RING_BASE (!is_mt7986(mdev)? 0xd7300 : 0x24420) |
| 1145 | -#define MT_RXQ_WED_RING_BASE (!is_mt7986(mdev)? 0xd7410 : 0x24520) |
| 1146 | +#define MT_TXQ_WED_RING_BASE __REG(WED_TX_RING) |
| 1147 | +#define MT_RXQ_WED_RING_BASE __REG(WED_RX_RING) |
| 1148 | +#define MT_RXQ_WED_DATA_RING_BASE __REG(WED_RX_DATA_RING) |
| 1149 | |
| 1150 | #define MT_WED_TX_DONE_BAND0 (is_mt7915(mdev)? 4 : 30) |
| 1151 | #define MT_WED_TX_DONE_BAND1 (is_mt7915(mdev)? 5 : 31) |
developer | 36936c3 | 2022-09-30 12:55:06 +0800 | [diff] [blame^] | 1152 | -#define MT_WED_TX_FREE_DONE (is_mt7915(mdev)? 1 : 2) |
| 1153 | +#define MT_WED_TX_FREE_DONE (is_mt7986(mdev) ? 2 : 1) |
| 1154 | +#define MT_WED_RX_DONE_BAND0 (is_mt7915(mdev) ? 16 : \ |
| 1155 | + (is_mt7986(mdev) ? 22 : 18)) |
| 1156 | +#define MT_WED_RX_DONE_BAND1 (is_mt7915(mdev) ? 17 : \ |
| 1157 | + (is_mt7986(mdev) ? 23 : 19)) |
| 1158 | + |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1159 | |
| 1160 | #define MT_INT_SOURCE_CSR __REG(INT_SOURCE_CSR) |
| 1161 | #define MT_INT_MASK_CSR __REG(INT_MASK_CSR) |
| 1162 | diff --git a/mt7921/mac.c b/mt7921/mac.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1163 | index 9c82ec24..6b631a64 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1164 | --- a/mt7921/mac.c |
| 1165 | +++ b/mt7921/mac.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1166 | @@ -680,7 +680,7 @@ bool mt7921_rx_check(struct mt76_dev *mdev, void *data, int len) |
| 1167 | EXPORT_SYMBOL_GPL(mt7921_rx_check); |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1168 | |
| 1169 | void mt7921_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
| 1170 | - struct sk_buff *skb) |
| 1171 | + struct sk_buff *skb, u32 info) |
| 1172 | { |
| 1173 | struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76); |
| 1174 | __le32 *rxd = (__le32 *)skb->data; |
| 1175 | diff --git a/mt7921/mt7921.h b/mt7921/mt7921.h |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1176 | index eaba114a..54a30ca1 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1177 | --- a/mt7921/mt7921.h |
| 1178 | +++ b/mt7921/mt7921.h |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1179 | @@ -408,7 +408,7 @@ void mt7921_tx_worker(struct mt76_worker *w); |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1180 | void mt7921_tx_token_put(struct mt7921_dev *dev); |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1181 | bool mt7921_rx_check(struct mt76_dev *mdev, void *data, int len); |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1182 | void mt7921_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
| 1183 | - struct sk_buff *skb); |
| 1184 | + struct sk_buff *skb, u32 info); |
| 1185 | void mt7921_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps); |
| 1186 | void mt7921_stats_work(struct work_struct *work); |
| 1187 | void mt7921_set_stream_he_caps(struct mt7921_phy *phy); |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1188 | diff --git a/tx.c b/tx.c |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1189 | index 8b33186b..b812d067 100644 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1190 | --- a/tx.c |
| 1191 | +++ b/tx.c |
developer | 4df64ba | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 1192 | @@ -778,3 +778,37 @@ mt76_token_release(struct mt76_dev *dev, int token, bool *wake) |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1193 | return txwi; |
| 1194 | } |
| 1195 | EXPORT_SYMBOL_GPL(mt76_token_release); |
| 1196 | + |
| 1197 | +int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr, |
| 1198 | + struct mt76_txwi_cache *r, dma_addr_t phys) |
| 1199 | +{ |
| 1200 | + int token; |
| 1201 | + |
| 1202 | + spin_lock_bh(&dev->rx_token_lock); |
| 1203 | + |
| 1204 | + token = idr_alloc(&dev->rx_token, r, 0, dev->rx_token_size, GFP_ATOMIC); |
| 1205 | + |
| 1206 | + spin_unlock_bh(&dev->rx_token_lock); |
| 1207 | + |
| 1208 | + r->buf = ptr; |
| 1209 | + r->dma_addr = phys; |
| 1210 | + |
| 1211 | + return token; |
| 1212 | +} |
| 1213 | +EXPORT_SYMBOL_GPL(mt76_rx_token_consume); |
| 1214 | + |
| 1215 | +struct mt76_txwi_cache * |
| 1216 | +mt76_rx_token_release(struct mt76_dev *dev, int token) |
| 1217 | +{ |
| 1218 | + |
| 1219 | + struct mt76_txwi_cache *rxwi; |
| 1220 | + |
| 1221 | + spin_lock_bh(&dev->rx_token_lock); |
| 1222 | + |
| 1223 | + rxwi = idr_remove(&dev->rx_token, token); |
| 1224 | + |
| 1225 | + spin_unlock_bh(&dev->rx_token_lock); |
| 1226 | + |
| 1227 | + return rxwi; |
| 1228 | +} |
| 1229 | +EXPORT_SYMBOL_GPL(mt76_rx_token_release); |
| 1230 | -- |
developer | 33907d4 | 2022-09-19 14:33:58 +0800 | [diff] [blame] | 1231 | 2.25.1 |
developer | 3262bf8 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1232 | |