Path: blob/main/sys/contrib/dev/mediatek/mt76/mt7925/pci_mac.c
48526 views
// SPDX-License-Identifier: ISC1/* Copyright (C) 2023 MediaTek Inc. */23#include "mt7925.h"4#include "../dma.h"5#include "mac.h"67int mt7925e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,8enum mt76_txq_id qid, struct mt76_wcid *wcid,9struct ieee80211_sta *sta,10struct mt76_tx_info *tx_info)11{12struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);13struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_info->skb);14struct ieee80211_key_conf *key = info->control.hw_key;15struct mt76_connac_hw_txp *txp;16struct mt76_txwi_cache *t;17int id, pid;18u8 *txwi = (u8 *)txwi_ptr;1920if (unlikely(tx_info->skb->len <= ETH_HLEN))21return -EINVAL;2223if (!wcid)24wcid = &dev->mt76.global_wcid;2526t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);27t->skb = tx_info->skb;2829id = mt76_token_consume(mdev, &t);30if (id < 0)31return id;3233if (sta) {34struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;3536if (time_after(jiffies, msta->deflink.last_txs + HZ / 4)) {37info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;38msta->deflink.last_txs = jiffies;39}40}4142pid = mt76_tx_status_skb_add(mdev, wcid, tx_info->skb);43mt7925_mac_write_txwi(mdev, txwi_ptr, tx_info->skb, wcid, key,44pid, qid, 0);4546txp = (struct mt76_connac_hw_txp *)(txwi + MT_TXD_SIZE);47memset(txp, 0, sizeof(struct mt76_connac_hw_txp));48mt76_connac_write_hw_txp(mdev, tx_info, txp, id);4950tx_info->skb = NULL;5152return 0;53}5455void mt7925_tx_token_put(struct mt792x_dev *dev)56{57struct mt76_txwi_cache *txwi;58int id;5960spin_lock_bh(&dev->mt76.token_lock);61idr_for_each_entry(&dev->mt76.token, txwi, id) {62mt7925_txwi_free(dev, txwi, NULL, NULL, NULL);63dev->mt76.token_count--;64}65spin_unlock_bh(&dev->mt76.token_lock);66idr_destroy(&dev->mt76.token);67}6869int mt7925e_mac_reset(struct mt792x_dev *dev)70{71const struct mt792x_irq_map *irq_map = dev->irq_map;72int i, err;7374mt792xe_mcu_drv_pmctrl(dev);7576mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);7778mt76_wr(dev, dev->irq_map->host_irq_enable, 0);79mt76_wr(dev, MT_PCIE_MAC_INT_ENABLE, 0x0);8081set_bit(MT76_RESET, &dev->mphy.state);82set_bit(MT76_MCU_RESET, &dev->mphy.state);83wake_up(&dev->mt76.mcu.wait);84skb_queue_purge(&dev->mt76.mcu.res_q);8586mt76_txq_schedule_all(&dev->mphy);8788mt76_worker_disable(&dev->mt76.tx_worker);89if (irq_map->rx.data_complete_mask)90napi_disable(&dev->mt76.napi[MT_RXQ_MAIN]);91if (irq_map->rx.wm_complete_mask)92napi_disable(&dev->mt76.napi[MT_RXQ_MCU]);93if (irq_map->rx.wm2_complete_mask)94napi_disable(&dev->mt76.napi[MT_RXQ_MCU_WA]);95if (irq_map->tx.all_complete_mask)96napi_disable(&dev->mt76.tx_napi);9798mt7925_tx_token_put(dev);99idr_init(&dev->mt76.token);100101mt792x_wpdma_reset(dev, true);102103mt76_for_each_q_rx(&dev->mt76, i) {104napi_enable(&dev->mt76.napi[i]);105}106napi_enable(&dev->mt76.tx_napi);107108local_bh_disable();109mt76_for_each_q_rx(&dev->mt76, i) {110napi_schedule(&dev->mt76.napi[i]);111}112napi_schedule(&dev->mt76.tx_napi);113local_bh_enable();114115dev->fw_assert = false;116clear_bit(MT76_MCU_RESET, &dev->mphy.state);117118mt76_wr(dev, dev->irq_map->host_irq_enable,119dev->irq_map->tx.all_complete_mask |120MT_INT_RX_DONE_ALL | MT_INT_MCU_CMD);121mt76_wr(dev, MT_PCIE_MAC_INT_ENABLE, 0xff);122123err = mt792xe_mcu_fw_pmctrl(dev);124if (err)125return err;126127err = __mt792xe_mcu_drv_pmctrl(dev);128if (err)129goto out;130131err = mt7925_run_firmware(dev);132if (err)133goto out;134135err = mt7925_mcu_set_eeprom(dev);136if (err)137goto out;138139err = mt7925_mac_init(dev);140if (err)141goto out;142143err = __mt7925_start(&dev->phy);144out:145clear_bit(MT76_RESET, &dev->mphy.state);146147mt76_worker_enable(&dev->mt76.tx_worker);148149return err;150}151152153