Commit d089692b authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau
Browse files

mt76: move token utilities in mt76 common module



Move token management in mt76 common module since it is shared between
mt7615, mt7915 and mt7921 drivers

Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent b17aff33
Loading
Loading
Loading
Loading
+45 −5
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@
#define MT_MAX_NON_AQL_PKT	16
#define MT_TXQ_FREE_THR		32

#define MT76_TOKEN_FREE_THR	64

struct mt76_dev;
struct mt76_phy;
struct mt76_wcid;
@@ -332,6 +334,7 @@ struct mt76_driver_ops {
	u32 drv_flags;
	u32 survey_flags;
	u16 txwi_size;
	u16 token_size;
	u8 mcs_rates;

	void (*update_survey)(struct mt76_dev *dev);
@@ -1215,4 +1218,41 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
			      struct mt76_power_limits *dest,
			      s8 target_power);

struct mt76_txwi_cache *
mt76_token_release(struct mt76_dev *dev, int token, bool *wake);
int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi);
void mt76_token_init(struct mt76_dev *dev);
void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked);

static inline void mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked)
{
	spin_lock_bh(&dev->token_lock);
	__mt76_set_tx_blocked(dev, blocked);
	spin_unlock_bh(&dev->token_lock);
}

static inline int
mt76_token_get(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi)
{
	int token;

	spin_lock_bh(&dev->token_lock);
	token = idr_alloc(&dev->token, *ptxwi, 0, dev->drv->token_size,
			  GFP_ATOMIC);
	spin_unlock_bh(&dev->token_lock);

	return token;
}

static inline struct mt76_txwi_cache *
mt76_token_put(struct mt76_dev *dev, int token)
{
	struct mt76_txwi_cache *txwi;

	spin_lock_bh(&dev->token_lock);
	txwi = idr_remove(&dev->token, token);
	spin_unlock_bh(&dev->token_lock);

	return txwi;
}
#endif
+1 −5
Original line number Diff line number Diff line
@@ -1465,11 +1465,7 @@ mt7615_mac_tx_free_token(struct mt7615_dev *dev, u16 token)
	u8 wcid;

	trace_mac_tx_free(dev, token);

	spin_lock_bh(&mdev->token_lock);
	txwi = idr_remove(&mdev->token, token);
	spin_unlock_bh(&mdev->token_lock);

	txwi = mt76_token_put(mdev, token);
	if (!txwi)
		return;

+1 −0
Original line number Diff line number Diff line
@@ -190,6 +190,7 @@ int mt7615_mmio_probe(struct device *pdev, void __iomem *mem_base,
		.survey_flags = SURVEY_INFO_TIME_TX |
				SURVEY_INFO_TIME_RX |
				SURVEY_INFO_TIME_BSS_RX,
		.token_size = MT7615_TOKEN_SIZE,
		.tx_prepare_skb = mt7615_tx_prepare_skb,
		.tx_complete_skb = mt7615_tx_complete_skb,
		.rx_skb = mt7615_queue_rx_skb,
+1 −2
Original line number Diff line number Diff line
@@ -40,8 +40,7 @@ static int mt7615_init_hardware(struct mt7615_dev *dev)
	mt76_wr(dev, MT_INT_SOURCE_CSR, ~0);

	INIT_WORK(&dev->mcu_work, mt7615_pci_init_work);
	spin_lock_init(&dev->mt76.token_lock);
	idr_init(&dev->mt76.token);
	mt76_token_init(&dev->mt76);

	ret = mt7615_eeprom_init(dev, addr);
	if (ret < 0)
+2 −6
Original line number Diff line number Diff line
@@ -37,9 +37,7 @@ void mt7615_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e)
			token = le16_to_cpu(txp->hw.msdu_id[0]) &
				~MT_MSDU_ID_VALID;

		spin_lock_bh(&mdev->token_lock);
		t = idr_remove(&mdev->token, token);
		spin_unlock_bh(&mdev->token_lock);
		t = mt76_token_put(mdev, token);
		e->skb = t ? t->skb : NULL;
	}

@@ -161,9 +159,7 @@ int mt7615_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
	t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);
	t->skb = tx_info->skb;

	spin_lock_bh(&mdev->token_lock);
	id = idr_alloc(&mdev->token, t, 0, MT7615_TOKEN_SIZE, GFP_ATOMIC);
	spin_unlock_bh(&mdev->token_lock);
	id = mt76_token_get(mdev, &t);
	if (id < 0)
		return id;

Loading