Skip to content

Commit f3950a4

Browse files
LorenzoBianconinbd168
authored andcommitted
mt76: set txwi_size according to the driver value
Dynamically allocate txwi since new chipsets will use longer txwi descriptors Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Felix Fietkau <[email protected]>
1 parent ce0fd82 commit f3950a4

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

drivers/net/wireless/mediatek/mt76/dma.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,14 @@ mt76_dma_tx_queue_skb(struct mt76_dev *dev, enum mt76_txq_id qid,
296296
struct mt76_txwi_cache *t;
297297
struct sk_buff *iter;
298298
dma_addr_t addr;
299+
u8 *txwi;
299300

300301
t = mt76_get_txwi(dev);
301302
if (!t) {
302303
ieee80211_free_txskb(dev->hw, skb);
303304
return -ENOMEM;
304305
}
306+
txwi = mt76_get_txwi_ptr(dev, t);
305307

306308
skb->prev = skb->next = NULL;
307309
if (dev->drv->tx_aligned4_skbs)
@@ -331,11 +333,11 @@ mt76_dma_tx_queue_skb(struct mt76_dev *dev, enum mt76_txq_id qid,
331333
}
332334
tx_info.nbuf = n;
333335

334-
dma_sync_single_for_cpu(dev->dev, t->dma_addr, sizeof(t->txwi),
336+
dma_sync_single_for_cpu(dev->dev, t->dma_addr, dev->drv->txwi_size,
335337
DMA_TO_DEVICE);
336-
ret = dev->drv->tx_prepare_skb(dev, &t->txwi, skb, qid, wcid, sta,
338+
ret = dev->drv->tx_prepare_skb(dev, txwi, skb, qid, wcid, sta,
337339
&tx_info);
338-
dma_sync_single_for_device(dev->dev, t->dma_addr, sizeof(t->txwi),
340+
dma_sync_single_for_device(dev->dev, t->dma_addr, dev->drv->txwi_size,
339341
DMA_TO_DEVICE);
340342
if (ret < 0)
341343
goto unmap;

drivers/net/wireless/mediatek/mt76/mt76.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,10 @@ struct mt76_txq {
229229
};
230230

231231
struct mt76_txwi_cache {
232-
u32 txwi[8];
233-
dma_addr_t dma_addr;
234232
struct list_head list;
233+
dma_addr_t dma_addr;
235234
};
236235

237-
238236
struct mt76_rx_tid {
239237
struct rcu_head rcu_head;
240238

@@ -617,6 +615,12 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str,
617615
int mt76_eeprom_init(struct mt76_dev *dev, int len);
618616
void mt76_eeprom_override(struct mt76_dev *dev);
619617

618+
static inline u8 *
619+
mt76_get_txwi_ptr(struct mt76_dev *dev, struct mt76_txwi_cache *t)
620+
{
621+
return (u8 *)t - dev->drv->txwi_size;
622+
}
623+
620624
/* increment with wrap-around */
621625
static inline int mt76_incr(int val, int size)
622626
{

drivers/net/wireless/mediatek/mt76/mt76x02_mac.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ void mt76x02_tx_complete_skb(struct mt76_dev *mdev, enum mt76_txq_id qid,
770770
{
771771
struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76);
772772
struct mt76x02_txwi *txwi;
773+
u8 *txwi_ptr;
773774

774775
if (!e->txwi) {
775776
dev_kfree_skb_any(e->skb);
@@ -778,7 +779,8 @@ void mt76x02_tx_complete_skb(struct mt76_dev *mdev, enum mt76_txq_id qid,
778779

779780
mt76x02_mac_poll_tx_status(dev, false);
780781

781-
txwi = (struct mt76x02_txwi *) &e->txwi->txwi;
782+
txwi_ptr = mt76_get_txwi_ptr(mdev, e->txwi);
783+
txwi = (struct mt76x02_txwi *)txwi_ptr;
782784
trace_mac_txdone_add(dev, txwi->wcid, txwi->pktid);
783785

784786
mt76_tx_complete_skb(mdev, e->skb);

drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ int mt76x02_dma_init(struct mt76x02_dev *dev)
175175
struct mt76_queue *q;
176176
void *status_fifo;
177177

178-
BUILD_BUG_ON(sizeof(t->txwi) < sizeof(struct mt76x02_txwi));
179178
BUILD_BUG_ON(sizeof(struct mt76x02_rxwi) > MT_RX_HEADROOM);
180179

181180
fifo_size = roundup_pow_of_two(32 * sizeof(struct mt76x02_tx_status));

drivers/net/wireless/mediatek/mt76/tx.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ mt76_alloc_txwi(struct mt76_dev *dev)
2121
{
2222
struct mt76_txwi_cache *t;
2323
dma_addr_t addr;
24+
u8 *txwi;
2425
int size;
2526

26-
size = (sizeof(*t) + L1_CACHE_BYTES - 1) & ~(L1_CACHE_BYTES - 1);
27-
t = devm_kzalloc(dev->dev, size, GFP_ATOMIC);
28-
if (!t)
27+
size = L1_CACHE_ALIGN(dev->drv->txwi_size + sizeof(*t));
28+
txwi = devm_kzalloc(dev->dev, size, GFP_ATOMIC);
29+
if (!txwi)
2930
return NULL;
3031

31-
addr = dma_map_single(dev->dev, &t->txwi, sizeof(t->txwi),
32+
addr = dma_map_single(dev->dev, txwi, dev->drv->txwi_size,
3233
DMA_TO_DEVICE);
34+
t = (struct mt76_txwi_cache *)(txwi + dev->drv->txwi_size);
3335
t->dma_addr = addr;
3436

3537
return t;
@@ -78,7 +80,7 @@ void mt76_tx_free(struct mt76_dev *dev)
7880
struct mt76_txwi_cache *t;
7981

8082
while ((t = __mt76_get_txwi(dev)) != NULL)
81-
dma_unmap_single(dev->dev, t->dma_addr, sizeof(t->txwi),
83+
dma_unmap_single(dev->dev, t->dma_addr, dev->drv->txwi_size,
8284
DMA_TO_DEVICE);
8385
}
8486

0 commit comments

Comments
 (0)