wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices
Subsystems (2)
Shayne Chen
reviewercover wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices
Add MediaTek new mac80211 driver mt7996 for Wi-Fi 7 (802.11be) devices. The driver first supports Filogic 680 PCI device, which is a Wi-Fi 7 chipset supporting concurrent tri-band operation at 6 GHz, 5 GHz, and 2.4 GHz with 4x4 antennas on each band.
Currently, mt7996 only supports tri-band HE or older mode. EHT mode and more variants of Filogic 680 support will be introduced in further patches.
----------------[commit message cut here]----------------
This series is based on the following series with fixes folded:
- https://patchwork.kernel.org/project/linux-wireless/cover/[email protected]/
For easier review, the big patch has been splitted into multiple patches per functionality. These patches will be folded into a single patch in the final version.
Shayne Chen (9):
wifi: mt76: mt7996: add PCI support
wifi: mt76: mt7996: add DMA support
wifi: mt76: mt7996: add MCU support
wifi: mt76: mt7996: add EEPROM support
wifi: mt76: mt7996: add MAC support
wifi: mt76: mt7996: add ieee80211_ops
wifi: mt76: mt7996: add debugfs support
wifi: mt76: mt7996: add module support
wifi: mt76: add mt7996 module support
drivers/net/wireless/mediatek/mt76/Kconfig | 1 + drivers/net/wireless/mediatek/mt76/Makefile | 1 + .../net/wireless/mediatek/mt76/mt7996/Kconfig | 12 + .../wireless/mediatek/mt76/mt7996/Makefile | 6 + .../wireless/mediatek/mt76/mt7996/debugfs.c | 851 ++++ .../net/wireless/mediatek/mt76/mt7996/dma.c | 360 ++ .../wireless/mediatek/mt76/mt7996/eeprom.c | 229 ++ .../wireless/mediatek/mt76/mt7996/eeprom.h | 75 + .../net/wireless/mediatek/mt76/mt7996/init.c | 816 ++++ .../net/wireless/mediatek/mt76/mt7996/mac.c | 2468 ++++++++++++ .../net/wireless/mediatek/mt76/mt7996/mac.h | 398 ++ .../net/wireless/mediatek/mt76/mt7996/main.c | 1325 +++++++ .../net/wireless/mediatek/mt76/mt7996/mcu.c | 3429 +++++++++++++++++ .../net/wireless/mediatek/mt76/mt7996/mcu.h | 662 ++++ .../net/wireless/mediatek/mt76/mt7996/mmio.c | 385 ++ .../wireless/mediatek/mt76/mt7996/mt7996.h | 516 +++ .../net/wireless/mediatek/mt76/mt7996/pci.c | 222 ++ .../net/wireless/mediatek/mt76/mt7996/regs.h | 533 +++ 18 files changed, 12289 insertions(+) create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/Kconfig create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/Makefile create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/dma.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/eeprom.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/eeprom.h create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/init.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/mac.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/mac.h create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/main.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/mcu.h create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/mmio.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/pci.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/regs.h
Signature · 1 line
2.25.1
Shayne Chen
reviewerPATCH 1/9 wifi: mt76: mt7996: add PCI support
(Split the big patch into smaller intermediate patches by functionality for easier review. Refer to the cover letter for more info.)
--- .../net/wireless/mediatek/mt76/mt7996/mmio.c | 385 +++++++++++++ .../wireless/mediatek/mt76/mt7996/mt7996.h | 516 +++++++++++++++++ .../net/wireless/mediatek/mt76/mt7996/pci.c | 222 ++++++++ .../net/wireless/mediatek/mt76/mt7996/regs.h | 533 ++++++++++++++++++ 4 files changed, 1656 insertions(+) create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/mmio.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/pci.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/regs.h
drivers/net/wireless/mediatek/mt76/mt7996/mmio.c new file +385 -0
@@ -0,0 +1,385 @@ +// SPDX-License-Identifier: ISC +/* +* Copyright (C) 2022 MediaTek Inc. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/pci.h> + +#include "mt7996.h" +#include "mac.h" +#include "../trace.h" + +static const struct __base mt7996_reg_base[] = { + [WF_AGG_BASE ] = { {0x820e2000 ,0x820f2000 ,0x830e2000 } }, + [WF_MIB_BASE ] = { {0x820ed000 ,0x820fd000 ,0x830ed000 } }, + [WF_TMAC_BASE ] = { {0x820e4000 ,0x820f4000 ,0x830e4000 } }, + [WF_RMAC_BASE ] = { {0x820e5000 ,0x820f5000 ,0x830e5000 } }, + [WF_ARB_BASE ] = { {0x820e3000 ,0x820f3000 ,0x830e3000 } }, + [WF_LPON_BASE ] = { {0x820eb000 ,0x820fb000 ,0x830eb000 } }, + [WF_ETBF_BASE ] = { {0x820ea000 ,0x820fa000 ,0x830ea000 } }, + [WF_DMA_BASE ] = { {0x820e7000 ,0x820f7000 ,0x830e7000 } }, +}; + +static const struct __map mt7996_reg_map[] = { + {0x54000000 ,0x02000 ,0x1000 },/* WFDMA_0 (PCIE0 MCU DMA0) */ + {0x55000000 ,0x03000 ,0x1000 },/* WFDMA_1 (PCIE0 MCU DMA1) */ + {0x56000000 ,0x04000 ,0x1000 },/* WFDMA reserved */ + {0x57000000 ,0x05000 ,0x1000 },/* WFDMA MCU wrap CR */ + {0x58000000 ,0x06000 ,0x1000 },/* WFDMA PCIE1 MCU DMA0 (MEM_DMA) */ + {0x59000000 ,0x07000 ,0x1000 },/* WFDMA PCIE1 MCU DMA1 */ + {0x820c0000 ,0x08000 ,0x4000 },/* WF_UMAC_TOP (PLE) */ + {0x820c8000 ,0x0c000 ,0x2000 },/* WF_UMAC_TOP (PSE) */ + {0x820cc000 ,0x0e000 ,0x1000 },/* WF_UMAC_TOP (PP) */ + {0x74030000 ,0x10000 ,0x1000 },/* PCIe MAC */ + {0x820e0000 ,0x20000 ,0x0400 },/* WF_LMAC_TOP BN0 (WF_CFG) */ + {0x820e1000 ,0x20400 ,0x0200 },/* WF_LMAC_TOP BN0 (WF_TRB) */ + {0x820e2000 ,0x20800 ,0x0400 },/* WF_LMAC_TOP BN0 (WF_AGG) */ + {0x820e3000 ,0x20c00 ,0x0400 },/* WF_LMAC_TOP BN0 (WF_ARB) */ + {0x820e4000 ,0x21000 ,0x0400 },/* WF_LMAC_TOP BN0 (WF_TMAC) */ + {0x820e5000 ,0x21400 ,0x0800 },/* WF_LMAC_TOP BN0 (WF_RMAC) */ + {0x820ce000 ,0x21c00 ,0x0200 },/* WF_LMAC_TOP (WF_SEC) */ + {0x820e7000 ,0x21e00 ,0x0200 },/* WF_LMAC_TOP BN0 (WF_DMA) */ + {0x820cf000 ,0x22000 ,0x1000 },/* WF_LMAC_TOP (WF_PF) */ + {0x820e9000 ,0x23400 ,0x0200 },/* WF_LMAC_TOP BN0 (WF_WTBLOFF) */ + {0x820ea000 ,0x24000 ,0x0200 },/* WF_LMAC_TOP BN0 (WF_ETBF) */ + {0x820eb000 ,0x24200 ,0x0400 },/* WF_LMAC_TOP BN0 (WF_LPON) */ + {0x820ec000 ,0x24600 ,0x0200 },/* WF_LMAC_TOP BN0 (WF_INT) */ + {0x820ed000 ,0x24800 ,0x0800 },/* WF_LMAC_TOP BN0 (WF_MIB) */ + {0x820ca000 ,0x26000 ,0x2000 },/* WF_LMAC_TOP BN0 (WF_MUCOP) */ + {0x820d0000 ,0x30000 ,0x10000 },/* WF_LMAC_TOP (WF_WTBLON) */ + {0x40000000 ,0x70000 ,0x10000 },/* WF_UMAC_SYSRAM */ + {0x00400000 ,0x80000 ,0x10000 },/* WF_MCU_SYSRAM */ + {0x00410000 ,0x90000 ,0x10000 },/* WF_MCU_SYSRAM (configure register) */ + {0x820f0000 ,0xa0000 ,0x0400 },/* WF_LMAC_TOP BN1 (WF_CFG) */ + {0x820f1000 ,0xa0600 ,0x0200 },/* WF_LMAC_TOP BN1 (WF_TRB) */ + {0x820f2000 ,0xa0800 ,0x0400 },/* WF_LMAC_TOP BN1 (WF_AGG) */ + {0x820f3000 ,0xa0c00 ,0x0400 },/* WF_LMAC_TOP BN1 (WF_ARB) */ + {0x820f4000 ,0xa1000 ,0x0400 },/* WF_LMAC_TOP BN1 (WF_TMAC) */ + {0x820f5000 ,0xa1400 ,0x0800 },/* WF_LMAC_TOP BN1 (WF_RMAC) */ + {0x820f7000 ,0xa1e00 ,0x0200 },/* WF_LMAC_TOP BN1 (WF_DMA) */ + {0x820f9000 ,0xa3400 ,0x0200 },/* WF_LMAC_TOP BN1 (WF_WTBLOFF) */ + {0x820fa000 ,0xa4000 ,0x0200 },/* WF_LMAC_TOP BN1 (WF_ETBF) */ + {0x820fb000 ,0xa4200 ,0x0400 },/* WF_LMAC_TOP BN1 (WF_LPON) */ + {0x820fc000 ,0xa4600 ,0x0200 },/* WF_LMAC_TOP BN1 (WF_INT) */ + {0x820fd000 ,0xa4800 ,0x0800 },/* WF_LMAC_TOP BN1 (WF_MIB) */ + {0x820cc000 ,0xa5000 ,0x2000 },/* WF_LMAC_TOP BN1 (WF_MUCOP) */ + {0x820c4000 ,0xa8000 ,0x4000 },/* WF_LMAC_TOP BN1 (WF_MUCOP) */ + {0x820b0000 ,0xae000 ,0x1000 },/* [APB2] WFSYS_ON */ + {0x80020000 ,0xb0000 ,0x10000 },/* WF_TOP_MISC_OFF */ + {0x81020000 ,0xc0000 ,0x10000 },/* WF_TOP_MISC_ON */ + {0x7c020000 ,0xd0000 ,0x10000 },/* CONN_INFRA, wfdma */ + {0x7c060000 ,0xe0000 ,0x10000 },/* CONN_INFRA, conn_host_csr_top */ + {0x7c000000 ,0xf0000 ,0x10000 },/* CONN_INFRA */ + {0x0 ,0x0 ,0x0 },/* imply end of search */ +}; + +static u32 mt7996_reg_map_l1 (struct mt7996_dev *dev,u32 addr) +{ +u32 offset =FIELD_GET (MT_HIF_REMAP_L1_OFFSET , addr); +u32 base =FIELD_GET (MT_HIF_REMAP_L1_BASE , addr); + + dev->reg_l1_backup = dev->bus_ops->rr (&dev->mt76,MT_HIF_REMAP_L1 ); + dev->bus_ops->rmw (&dev->mt76,MT_HIF_REMAP_L1 , +MT_HIF_REMAP_L1_MASK , +FIELD_PREP (MT_HIF_REMAP_L1_MASK , base)); +/* use read to push write */ + dev->bus_ops->rr (&dev->mt76,MT_HIF_REMAP_L1 ); + +return MT_HIF_REMAP_BASE_L1 + offset; +} + +static u32 mt7996_reg_map_l2 (struct mt7996_dev *dev,u32 addr) +{ +u32 offset =FIELD_GET (MT_HIF_REMAP_L2_OFFSET , addr); +u32 base =FIELD_GET (MT_HIF_REMAP_L2_BASE , addr); + + dev->reg_l2_backup = dev->bus_ops->rr (&dev->mt76,MT_HIF_REMAP_L2 ); + dev->bus_ops->rmw (&dev->mt76,MT_HIF_REMAP_L2 , +MT_HIF_REMAP_L2_MASK , +FIELD_PREP (MT_HIF_REMAP_L2_MASK , base)); +/* use read to push write */ + dev->bus_ops->rr (&dev->mt76,MT_HIF_REMAP_L2 ); + +return MT_HIF_REMAP_BASE_L2 + offset; +} + +static void mt7996_reg_remap_restore (struct mt7996_dev *dev) +{ +/* remap to ori status */ +if (unlikely (dev->reg_l1_backup)) { + dev->bus_ops->wr (&dev->mt76,MT_HIF_REMAP_L1 , dev->reg_l1_backup); + dev->reg_l1_backup =0 ; + } + +if (dev->reg_l2_backup) { + dev->bus_ops->wr (&dev->mt76,MT_HIF_REMAP_L2 , dev->reg_l2_backup); + dev->reg_l2_backup =0 ; + } +} + +static u32 __mt7996_reg_addr (struct mt7996_dev *dev,u32 addr) +{ +int i; + +mt7996_reg_remap_restore (dev); + +if (addr <0x100000 ) +return addr; + +for (i =0 ; i < dev->reg.map_size; i++) { +u32 ofs; + +if (addr < dev->reg.map[i].phys) +continue ; + + ofs = addr - dev->reg.map[i].phys; +if (ofs > dev->reg.map[i].size) +continue ; + +return dev->reg.map[i].mapped + ofs; + } + +if ((addr >=MT_INFRA_BASE && addr <MT_WFSYS0_PHY_START ) || + (addr >=MT_WFSYS0_PHY_START && addr <MT_WFSYS1_PHY_START ) || + (addr >=MT_WFSYS1_PHY_START && addr <=MT_WFSYS1_PHY_END )) +return mt7996_reg_map_l1 (dev, addr); + +if (dev_is_pci (dev->mt76.dev) && + ((addr >=MT_CBTOP1_PHY_START && addr <=MT_CBTOP1_PHY_END ) || + (addr >=MT_CBTOP2_PHY_START && addr <=MT_CBTOP2_PHY_END ))) +return mt7996_reg_map_l1 (dev, addr); + +/* CONN_INFRA: covert to phyiscal addr and use layer 1 remap */ +if (addr >=MT_INFRA_MCU_START && addr <=MT_INFRA_MCU_END ) { + addr = addr -MT_INFRA_MCU_START +MT_INFRA_BASE ; +return mt7996_reg_map_l1 (dev, addr); + } + +return mt7996_reg_map_l2 (dev, addr); +} + +static u32 mt7996_rr (struct mt76_dev *mdev,u32 offset) +{ + struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76); + +return dev->bus_ops->rr (mdev,__mt7996_reg_addr (dev, offset)); +} + +static void mt7996_wr (struct mt76_dev *mdev,u32 offset,u32 val) +{ + struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76); + + dev->bus_ops->wr (mdev,__mt7996_reg_addr (dev, offset), val); +} + +static u32 mt7996_rmw (struct mt76_dev *mdev,u32 offset,u32 mask,u32 val) +{ + struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76); + +return dev->bus_ops->rmw (mdev,__mt7996_reg_addr (dev, offset), mask, val); +} + +static int mt7996_mmio_init (struct mt76_dev *mdev, +void __iomem *mem_base, +u32 device_id) +{ +struct mt76_bus_ops *bus_ops; +struct mt7996_dev *dev; + + dev = container_of(mdev, struct mt7996_dev, mt76); +mt76_mmio_init (&dev->mt76, mem_base); + +switch (device_id) { +case 0x7990 : + dev->reg.base = mt7996_reg_base; + dev->reg.map = mt7996_reg_map; + dev->reg.map_size =ARRAY_SIZE (mt7996_reg_map); +break ; +default : +return -EINVAL ; + } + + dev->bus_ops = dev->mt76.bus; + bus_ops =devm_kmemdup (dev->mt76.dev, dev->bus_ops,sizeof (*bus_ops), +GFP_KERNEL ); +if (!bus_ops) +return -ENOMEM ; + + bus_ops->rr = mt7996_rr; + bus_ops->wr = mt7996_wr; + bus_ops->rmw = mt7996_rmw; + dev->mt76.bus = bus_ops; + + mdev->rev = (device_id <<16 ) | (mt76_rr (dev,MT_HW_REV ) &0xff ); + +dev_dbg (mdev->dev,"ASIC revision: %04x\n" , mdev->rev); + +return 0 ; +} + +void mt7996_dual_hif_set_irq_mask (struct mt7996_dev *dev,bool write_reg, +u32 clear,u32 set) +{ +struct mt76_dev *mdev = &dev->mt76; +unsigned long flags; + +spin_lock_irqsave (&mdev->mmio.irq_lock, flags); + + mdev->mmio.irqmask &= ~clear; + mdev->mmio.irqmask |= set; + +if (write_reg) { +mt76_wr (dev,MT_INT_MASK_CSR , mdev->mmio.irqmask); +mt76_wr (dev,MT_INT1_MASK_CSR , mdev->mmio.irqmask); + } + +spin_unlock_irqrestore (&mdev->mmio.irq_lock, flags); +} + +static void mt7996_rx_poll_complete (struct mt76_dev *mdev, +enum mt76_rxq_id q) +{ + struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76); + +mt7996_irq_enable (dev,MT_INT_RX (q)); +} + +/* TODO: support 2/4/6/8 MSI-X vectors */ +static void mt7996_irq_tasklet (struct tasklet_struct *t) +{ +struct mt7996_dev *dev =from_tasklet (dev, t, irq_tasklet); +u32 i, intr, mask, intr1; + +mt76_wr (dev,MT_INT_MASK_CSR ,0 ); +if (dev->hif2) +mt76_wr (dev,MT_INT1_MASK_CSR ,0 ); + + intr =mt76_rr (dev,MT_INT_SOURCE_CSR ); + intr &= dev->mt76.mmio.irqmask; +mt76_wr (dev,MT_INT_SOURCE_CSR , intr); + +if (dev->hif2) { + intr1 =mt76_rr (dev,MT_INT1_SOURCE_CSR ); + intr1 &= dev->mt76.mmio.irqmask; +mt76_wr (dev,MT_INT1_SOURCE_CSR , intr1); + + intr |= intr1; + } + +trace_dev_irq (&dev->mt76, intr, dev->mt76.mmio.irqmask); + + mask = intr &MT_INT_RX_DONE_ALL ; +if (intr &MT_INT_TX_DONE_MCU ) + mask |=MT_INT_TX_DONE_MCU ; +mt7996_irq_disable (dev, mask); + +if (intr &MT_INT_TX_DONE_MCU ) +napi_schedule (&dev->mt76.tx_napi); + +for (i =0 ; i < __MT_RXQ_MAX; i++) { +if ((intr &MT_INT_RX (i))) +napi_schedule (&dev->mt76.napi[i]); + } + +if (intr &MT_INT_MCU_CMD ) { +u32 val =mt76_rr (dev,MT_MCU_CMD ); + +mt76_wr (dev,MT_MCU_CMD , val); +if (val &MT_MCU_CMD_ERROR_MASK ) { + dev->reset_state = val; +ieee80211_queue_work (mt76_hw (dev), &dev->reset_work); +wake_up (&dev->reset_wait); + } + } +} + +irqreturn_t mt7996_irq_handler (int irq,void *dev_instance) +{ +struct mt7996_dev *dev = dev_instance; + +mt76_wr (dev,MT_INT_MASK_CSR ,0 ); +if (dev->hif2) +mt76_wr (dev,MT_INT1_MASK_CSR ,0 ); + +if (!test_bit (MT76_STATE_INITIALIZED , &dev->mphy.state)) +return IRQ_NONE ; + +tasklet_schedule (&dev->irq_tasklet); + +return IRQ_HANDLED ; +} + +struct mt7996_dev *mt7996_mmio_probe (struct device *pdev, +void __iomem *mem_base,u32 device_id) +{ +static const struct mt76_driver_ops drv_ops = { +/* txwi_size = txd size + txp size */ + .txwi_size =MT_TXD_SIZE +sizeof (struct mt7996_txp ), + .drv_flags =MT_DRV_TXWI_NO_FREE | +MT_DRV_HW_MGMT_TXQ , + .survey_flags =SURVEY_INFO_TIME_TX | +SURVEY_INFO_TIME_RX | +SURVEY_INFO_TIME_BSS_RX , + .token_size =MT7996_TOKEN_SIZE , + .tx_prepare_skb = mt7996_tx_prepare_skb, + .tx_complete_skb = mt7996_tx_complete_skb, + .rx_skb = mt7996_queue_rx_skb, + .rx_check = mt7996_rx_check, + .rx_poll_complete = mt7996_rx_poll_complete, + .sta_ps = mt7996_sta_ps, + .sta_add = mt7996_mac_sta_add, + .sta_remove = mt7996_mac_sta_remove, + .update_survey = mt7996_update_channel, + }; +struct mt7996_dev *dev; +struct mt76_dev *mdev; +int ret; + + mdev =mt76_alloc_device (pdev,sizeof (*dev), &mt7996_ops, &drv_ops); +if (!mdev) +return ERR_PTR (-ENOMEM ); + + dev = container_of(mdev, struct mt7996_dev, mt76); + + ret =mt7996_mmio_init (mdev, mem_base, device_id); +if (ret) + goto error; + +tasklet_setup (&dev->irq_tasklet, mt7996_irq_tasklet); + +mt76_wr (dev,MT_INT_MASK_CSR ,0 ); + +return dev; + +error: +mt76_free_device (&dev->mt76); + +return ERR_PTR (ret); +} + +static int __init mt7996_init (void ) +{ +int ret; + + ret =pci_register_driver (&mt7996_hif_driver); +if (ret) +return ret; + + ret =pci_register_driver (&mt7996_pci_driver); +if (ret) +pci_unregister_driver (&mt7996_hif_driver); + +return ret; +} + +static void __exit mt7996_exit(void) +{ +pci_unregister_driver (&mt7996_pci_driver); +pci_unregister_driver (&mt7996_hif_driver); +} + +module_init (mt7996_init); +module_exit (mt7996_exit); +MODULE_LICENSE ("Dual BSD/GPL" );
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h new file +516 -0
516 lines not on this page · raw message
drivers/net/wireless/mediatek/mt76/mt7996/pci.c new file +222 -0
222 lines not on this page · raw message
drivers/net/wireless/mediatek/mt76/mt7996/regs.h new file +533 -0
533 lines not on this page · raw message
Signature · 1 line
2.25.1
Shayne Chen
reviewerPATCH 2/9 wifi: mt76: mt7996: add DMA support
In reply to Shayne Chen(Split the big patch into smaller intermediate patches by functionality for easier review. Refer to the cover letter for more info.)
--- .../net/wireless/mediatek/mt76/mt7996/dma.c | 360 ++++++++++++++++++ 1 file changed, 360 insertions(+) create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/dma.c
drivers/net/wireless/mediatek/mt76/mt7996/dma.c new file +360 -0
@@ -0,0 +1,360 @@ +// SPDX-License-Identifier: ISC +/* +* Copyright (C) 2022 MediaTek Inc. +*/ + +#include "mt7996.h" +#include "../dma.h" +#include "mac.h" + +static int mt7996_poll_tx (struct napi_struct *napi,int budget) +{ +struct mt7996_dev *dev; + + dev = container_of(napi, struct mt7996_dev, mt76.tx_napi); + +mt76_connac_tx_cleanup (&dev->mt76); +if (napi_complete_done (napi,0 )) +mt7996_irq_enable (dev,MT_INT_TX_DONE_MCU ); + +return 0 ; +} + +static void mt7996_dma_config (struct mt7996_dev *dev) +{ +#define Q_CONFIG (q, wfdma, int, id) do { \ + if (wfdma) \ + dev->q_wfdma_mask |= (1 << (q)); \ + dev->q_int_mask[(q)] = int; \ + dev->q_id[(q)] = id; \ +} while (0) + +#define MCUQ_CONFIG (q, wfdma, int, id) Q_CONFIG(q, (wfdma), (int), (id)) +#define RXQ_CONFIG (q, wfdma, int, id) Q_CONFIG(__RXQ(q), (wfdma), (int), (id)) +#define TXQ_CONFIG (q, wfdma, int, id) Q_CONFIG(__TXQ(q), (wfdma), (int), (id)) + +/* rx queue */ +RXQ_CONFIG (MT_RXQ_MCU ,WFDMA0 ,MT_INT_RX_DONE_WM ,MT7996_RXQ_MCU_WM ); +RXQ_CONFIG (MT_RXQ_MCU_WA ,WFDMA0 ,MT_INT_RX_DONE_WA ,MT7996_RXQ_MCU_WA ); + +/* band0/band1 */ +RXQ_CONFIG (MT_RXQ_MAIN ,WFDMA0 ,MT_INT_RX_DONE_BAND0 ,MT7996_RXQ_BAND0 ); +RXQ_CONFIG (MT_RXQ_MAIN_WA ,WFDMA0 ,MT_INT_RX_DONE_WA_MAIN ,MT7996_RXQ_MCU_WA_MAIN ); + +/* band2 */ +RXQ_CONFIG (MT_RXQ_BAND2 ,WFDMA0 ,MT_INT_RX_DONE_BAND2 ,MT7996_RXQ_BAND2 ); +RXQ_CONFIG (MT_RXQ_BAND2_WA ,WFDMA0 ,MT_INT_RX_DONE_WA_TRI ,MT7996_RXQ_MCU_WA_TRI ); + +/* data tx queue */ +TXQ_CONFIG (0 ,WFDMA0 ,MT_INT_TX_DONE_BAND0 ,MT7996_TXQ_BAND0 ); +TXQ_CONFIG (1 ,WFDMA0 ,MT_INT_TX_DONE_BAND1 ,MT7996_TXQ_BAND1 ); +TXQ_CONFIG (2 ,WFDMA0 ,MT_INT_TX_DONE_BAND2 ,MT7996_TXQ_BAND2 ); + +/* mcu tx queue */ +MCUQ_CONFIG (MT_MCUQ_WM ,WFDMA0 ,MT_INT_TX_DONE_MCU_WM ,MT7996_TXQ_MCU_WM ); +MCUQ_CONFIG (MT_MCUQ_WA ,WFDMA0 ,MT_INT_TX_DONE_MCU_WA ,MT7996_TXQ_MCU_WA ); +MCUQ_CONFIG (MT_MCUQ_FWDL ,WFDMA0 ,MT_INT_TX_DONE_FWDL ,MT7996_TXQ_FWDL ); +} + +static void __mt7996_dma_prefetch (struct mt7996_dev *dev,u32 ofs) +{ +#define PREFETCH (_base, _depth) ((_base) << 16 | (_depth)) +/* prefetch SRAM wrapping boundary for tx/rx ring. */ +mt76_wr (dev,MT_MCUQ_EXT_CTRL (MT_MCUQ_FWDL ) + ofs,PREFETCH (0x0 ,0x2 )); +mt76_wr (dev,MT_MCUQ_EXT_CTRL (MT_MCUQ_WM ) + ofs,PREFETCH (0x20 ,0x2 )); +mt76_wr (dev,MT_TXQ_EXT_CTRL (0 ) + ofs,PREFETCH (0x40 ,0x4 )); +mt76_wr (dev,MT_TXQ_EXT_CTRL (1 ) + ofs,PREFETCH (0x80 ,0x4 )); +mt76_wr (dev,MT_MCUQ_EXT_CTRL (MT_MCUQ_WA ) + ofs,PREFETCH (0xc0 ,0x2 )); +mt76_wr (dev,MT_TXQ_EXT_CTRL (2 ) + ofs,PREFETCH (0xe0 ,0x4 )); +mt76_wr (dev,MT_RXQ_BAND1_CTRL (MT_RXQ_MCU ) + ofs,PREFETCH (0x120 ,0x2 )); +mt76_wr (dev,MT_RXQ_BAND1_CTRL (MT_RXQ_MCU_WA ) + ofs,PREFETCH (0x140 ,0x2 )); +mt76_wr (dev,MT_RXQ_BAND1_CTRL (MT_RXQ_MAIN_WA ) + ofs,PREFETCH (0x160 ,0x2 )); +mt76_wr (dev,MT_RXQ_BAND1_CTRL (MT_RXQ_BAND2_WA ) + ofs,PREFETCH (0x180 ,0x2 )); +mt76_wr (dev,MT_RXQ_BAND1_CTRL (MT_RXQ_MAIN ) + ofs,PREFETCH (0x1a0 ,0x10 )); +mt76_wr (dev,MT_RXQ_BAND1_CTRL (MT_RXQ_BAND2 ) + ofs,PREFETCH (0x2a0 ,0x10 )); + +mt76_set (dev,WF_WFDMA0_GLO_CFG_EXT1 + ofs,WF_WFDMA0_GLO_CFG_EXT1_CALC_MODE ); +} + +void mt7996_dma_prefetch (struct mt7996_dev *dev) +{ +__mt7996_dma_prefetch (dev,0 ); +if (dev->hif2) +__mt7996_dma_prefetch (dev,MT_WFDMA0_PCIE1 (0 ) -MT_WFDMA0 (0 )); +} + +static void mt7996_dma_disable (struct mt7996_dev *dev,bool reset) +{ +u32 hif1_ofs =0 ; + +if (dev->hif2) + hif1_ofs =MT_WFDMA0_PCIE1 (0 ) -MT_WFDMA0 (0 ); + +if (reset) { +mt76_clear (dev,MT_WFDMA0_RST , +MT_WFDMA0_RST_DMASHDL_ALL_RST | +MT_WFDMA0_RST_LOGIC_RST ); + +mt76_set (dev,MT_WFDMA0_RST , +MT_WFDMA0_RST_DMASHDL_ALL_RST | +MT_WFDMA0_RST_LOGIC_RST ); + +if (dev->hif2) { +mt76_clear (dev,MT_WFDMA0_RST + hif1_ofs, +MT_WFDMA0_RST_DMASHDL_ALL_RST | +MT_WFDMA0_RST_LOGIC_RST ); + +mt76_set (dev,MT_WFDMA0_RST + hif1_ofs, +MT_WFDMA0_RST_DMASHDL_ALL_RST | +MT_WFDMA0_RST_LOGIC_RST ); + } + } + +/* disable */ +mt76_clear (dev,MT_WFDMA0_GLO_CFG , +MT_WFDMA0_GLO_CFG_TX_DMA_EN | +MT_WFDMA0_GLO_CFG_RX_DMA_EN | +MT_WFDMA0_GLO_CFG_OMIT_TX_INFO | +MT_WFDMA0_GLO_CFG_OMIT_RX_INFO | +MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2 ); + +if (dev->hif2) { +mt76_clear (dev,MT_WFDMA0_GLO_CFG + hif1_ofs, +MT_WFDMA0_GLO_CFG_TX_DMA_EN | +MT_WFDMA0_GLO_CFG_RX_DMA_EN | +MT_WFDMA0_GLO_CFG_OMIT_TX_INFO | +MT_WFDMA0_GLO_CFG_OMIT_RX_INFO | +MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2 ); + } +} + +static int mt7996_dma_enable (struct mt7996_dev *dev) +{ +u32 hif1_ofs =0 ; +u32 irq_mask; + +if (dev->hif2) + hif1_ofs =MT_WFDMA0_PCIE1 (0 ) -MT_WFDMA0 (0 ); + +/* reset dma idx */ +mt76_wr (dev,MT_WFDMA0_RST_DTX_PTR , ~0 ); +if (dev->hif2) +mt76_wr (dev,MT_WFDMA0_RST_DTX_PTR + hif1_ofs, ~0 ); + +/* configure delay interrupt off */ +mt76_wr (dev,MT_WFDMA0_PRI_DLY_INT_CFG0 ,0 ); +mt76_wr (dev,MT_WFDMA0_PRI_DLY_INT_CFG1 ,0 ); +mt76_wr (dev,MT_WFDMA0_PRI_DLY_INT_CFG2 ,0 ); + +if (dev->hif2) { +mt76_wr (dev,MT_WFDMA0_PRI_DLY_INT_CFG0 + hif1_ofs,0 ); +mt76_wr (dev,MT_WFDMA0_PRI_DLY_INT_CFG1 + hif1_ofs,0 ); +mt76_wr (dev,MT_WFDMA0_PRI_DLY_INT_CFG2 + hif1_ofs,0 ); + } + +/* configure perfetch settings */ +mt7996_dma_prefetch (dev); + +/* hif wait WFDMA idle */ +mt76_set (dev,MT_WFDMA0_BUSY_ENA , +MT_WFDMA0_BUSY_ENA_TX_FIFO0 | +MT_WFDMA0_BUSY_ENA_TX_FIFO1 | +MT_WFDMA0_BUSY_ENA_RX_FIFO ); + +if (dev->hif2) +mt76_set (dev,MT_WFDMA0_BUSY_ENA + hif1_ofs, +MT_WFDMA0_PCIE1_BUSY_ENA_TX_FIFO0 | +MT_WFDMA0_PCIE1_BUSY_ENA_TX_FIFO1 | +MT_WFDMA0_PCIE1_BUSY_ENA_RX_FIFO ); + +mt76_poll (dev,MT_WFDMA_EXT_CSR_HIF_MISC , +MT_WFDMA_EXT_CSR_HIF_MISC_BUSY ,0 ,1000 ); + +/* set WFDMA Tx/Rx */ +mt76_set (dev,MT_WFDMA0_GLO_CFG , +MT_WFDMA0_GLO_CFG_TX_DMA_EN | +MT_WFDMA0_GLO_CFG_RX_DMA_EN | +MT_WFDMA0_GLO_CFG_OMIT_TX_INFO | +MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2 ); + +/* GLO_CFG_EXT0 */ +mt76_set (dev,WF_WFDMA0_GLO_CFG_EXT0 , +WF_WFDMA0_GLO_CFG_EXT0_RX_WB_RXD | +WF_WFDMA0_GLO_CFG_EXT0_WED_MERGE_MODE ); + +/* GLO_CFG_EXT1 */ +mt76_set (dev,WF_WFDMA0_GLO_CFG_EXT1 , +WF_WFDMA0_GLO_CFG_EXT1_TX_FCTRL_MODE ); + +if (dev->hif2) { +mt76_set (dev,MT_WFDMA0_GLO_CFG + hif1_ofs, +MT_WFDMA0_GLO_CFG_TX_DMA_EN | +MT_WFDMA0_GLO_CFG_RX_DMA_EN | +MT_WFDMA0_GLO_CFG_OMIT_TX_INFO | +MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2 ); + +/* GLO_CFG_EXT0 */ +mt76_set (dev,WF_WFDMA0_GLO_CFG_EXT0 + hif1_ofs, +WF_WFDMA0_GLO_CFG_EXT0_RX_WB_RXD | +WF_WFDMA0_GLO_CFG_EXT0_WED_MERGE_MODE ); + +/* GLO_CFG_EXT1 */ +mt76_set (dev,WF_WFDMA0_GLO_CFG_EXT1 + hif1_ofs, +WF_WFDMA0_GLO_CFG_EXT1_TX_FCTRL_MODE ); + +mt76_set (dev,MT_WFDMA_HOST_CONFIG , +MT_WFDMA_HOST_CONFIG_PDMA_BAND ); + } + +if (dev->hif2) { +/* fix hardware limitation, pcie1's rx ring3 is not available +* so, redirect pcie0 rx ring3 interrupt to pcie1 +*/ +mt76_set (dev,MT_WFDMA0_RX_INT_PCIE_SEL , +MT_WFDMA0_RX_INT_SEL_RING3 ); + +/* TODO: redirect rx ring6 interrupt to pcie0 for wed function */ + } + +/* enable interrupts for TX/RX rings */ + irq_mask =MT_INT_RX_DONE_MCU | +MT_INT_TX_DONE_MCU | +MT_INT_MCU_CMD ; + +if (!dev->mphy.band_idx) + irq_mask |=MT_INT_BAND0_RX_DONE ; + +if (dev->dbdc_support) + irq_mask |=MT_INT_BAND1_RX_DONE ; + +if (dev->tbtc_support) + irq_mask |=MT_INT_BAND2_RX_DONE ; + +mt7996_irq_enable (dev, irq_mask); + +return 0 ; +} + +int mt7996_dma_init (struct mt7996_dev *dev) +{ +u32 hif1_ofs =0 ; +int ret; + +mt7996_dma_config (dev); + +mt76_dma_attach (&dev->mt76); + +if (dev->hif2) + hif1_ofs =MT_WFDMA0_PCIE1 (0 ) -MT_WFDMA0 (0 ); + +mt7996_dma_disable (dev, true); + +/* init tx queue */ + ret =mt76_connac_init_tx_queues (dev->phy.mt76, +MT_TXQ_ID (dev->mphy.band_idx), +MT7996_TX_RING_SIZE , +MT_TXQ_RING_BASE (0 ),0 ); +if (ret) +return ret; + +/* command to WM */ + ret =mt76_init_mcu_queue (&dev->mt76,MT_MCUQ_WM , +MT_MCUQ_ID (MT_MCUQ_WM ), +MT7996_TX_MCU_RING_SIZE , +MT_MCUQ_RING_BASE (MT_MCUQ_WM )); +if (ret) +return ret; + +/* command to WA */ + ret =mt76_init_mcu_queue (&dev->mt76,MT_MCUQ_WA , +MT_MCUQ_ID (MT_MCUQ_WA ), +MT7996_TX_MCU_RING_SIZE , +MT_MCUQ_RING_BASE (MT_MCUQ_WA )); +if (ret) +return ret; + +/* firmware download */ + ret =mt76_init_mcu_queue (&dev->mt76,MT_MCUQ_FWDL , +MT_MCUQ_ID (MT_MCUQ_FWDL ), +MT7996_TX_FWDL_RING_SIZE , +MT_MCUQ_RING_BASE (MT_MCUQ_FWDL )); +if (ret) +return ret; + +/* event from WM */ + ret =mt76_queue_alloc (dev, &dev->mt76.q_rx[MT_RXQ_MCU ], +MT_RXQ_ID (MT_RXQ_MCU ), +MT7996_RX_MCU_RING_SIZE , +MT_RX_BUF_SIZE , +MT_RXQ_RING_BASE (MT_RXQ_MCU )); +if (ret) +return ret; + +/* event from WA */ + ret =mt76_queue_alloc (dev, &dev->mt76.q_rx[MT_RXQ_MCU_WA ], +MT_RXQ_ID (MT_RXQ_MCU_WA ), +MT7996_RX_MCU_RING_SIZE , +MT_RX_BUF_SIZE , +MT_RXQ_RING_BASE (MT_RXQ_MCU_WA )); +if (ret) +return ret; + +/* rx data queue for band0 and band1 */ + ret =mt76_queue_alloc (dev, &dev->mt76.q_rx[MT_RXQ_MAIN ], +MT_RXQ_ID (MT_RXQ_MAIN ), +MT7996_RX_RING_SIZE , +MT_RX_BUF_SIZE , +MT_RXQ_RING_BASE (MT_RXQ_MAIN )); +if (ret) +return ret; + +/* tx free notify event from WA for band0 */ + ret =mt76_queue_alloc (dev, &dev->mt76.q_rx[MT_RXQ_MAIN_WA ], +MT_RXQ_ID (MT_RXQ_MAIN_WA ), +MT7996_RX_MCU_RING_SIZE , +MT_RX_BUF_SIZE , +MT_RXQ_RING_BASE (MT_RXQ_MAIN_WA )); +if (ret) +return ret; + +if (dev->tbtc_support || dev->mphy.band_idx ==MT_BAND2 ) { +/* rx data queue for band2 */ + ret =mt76_queue_alloc (dev, &dev->mt76.q_rx[MT_RXQ_BAND2 ], +MT_RXQ_ID (MT_RXQ_BAND2 ), +MT7996_RX_RING_SIZE , +MT_RX_BUF_SIZE , +MT_RXQ_RING_BASE (MT_RXQ_BAND2 ) + hif1_ofs); +if (ret) +return ret; + +/* tx free notify event from WA for band2 +* use pcie0's rx ring3, but, redirect pcie0 rx ring3 interrupt to pcie1 +*/ + ret =mt76_queue_alloc (dev, &dev->mt76.q_rx[MT_RXQ_BAND2_WA ], +MT_RXQ_ID (MT_RXQ_BAND2_WA ), +MT7996_RX_MCU_RING_SIZE , +MT_RX_BUF_SIZE , +MT_RXQ_RING_BASE (MT_RXQ_BAND2_WA )); +if (ret) +return ret; + } + + ret =mt76_init_queues (dev, mt76_dma_rx_poll); +if (ret <0 ) +return ret; + +netif_napi_add_tx (&dev->mt76.tx_napi_dev, &dev->mt76.tx_napi, + mt7996_poll_tx); +napi_enable (&dev->mt76.tx_napi); + +mt7996_dma_enable (dev); + +return 0 ; +} + +void mt7996_dma_cleanup (struct mt7996_dev *dev) +{ +mt7996_dma_disable (dev, true); + +mt76_dma_cleanup (&dev->mt76); +}
Signature · 1 line
2.25.1
Shayne Chen
reviewerPATCH 3/9 wifi: mt76: mt7996: add MCU support
In reply to Shayne Chen(Split the big patch into smaller intermediate patches by functionality for easier review. Refer to the cover letter for more info.)
--- .../net/wireless/mediatek/mt76/mt7996/mcu.c | 3429 +++++++++++++++++ .../net/wireless/mediatek/mt76/mt7996/mcu.h | 662 ++++ 2 files changed, 4091 insertions(+) create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c new file +3429 -0
@@ -0,0 +1,3429 @@ +// SPDX-License-Identifier: ISC +/* +* Copyright (C) 2022 MediaTek Inc. +*/ + +#include <linux/firmware.h> +#include <linux/fs.h> +#include "mt7996.h" +#include "mcu.h" +#include "mac.h" +#include "eeprom.h" + +struct mt7996_patch_hdr { +char build_date[16 ]; +char platform[4 ]; +__be32 hw_sw_ver; +__be32 patch_ver; +__be16 checksum; +u16 reserved; +struct { +__be32 patch_ver; +__be32 subsys; +__be32 feature; +__be32 n_region; +__be32 crc; +u32 reserved[11 ]; + } desc; +} __packed; + +struct mt7996_patch_sec { +__be32 type; +__be32 offs; +__be32 size; +union { +__be32 spec[13 ]; +struct { +__be32 addr; +__be32 len; +__be32 sec_key_idx; +__be32 align_len; +u32 reserved[9 ]; + } info; + }; +} __packed; + +struct mt7996_fw_trailer { +u8 chip_id; +u8 eco_code; +u8 n_region; +u8 format_ver; +u8 format_flag; +u8 reserved[2 ]; +char fw_ver[10 ]; +char build_date[15 ]; +u32 crc; +} __packed; + +struct mt7996_fw_region { +__le32 decomp_crc; +__le32 decomp_len; +__le32 decomp_blk_sz; +u8 reserved[4 ]; +__le32 addr; +__le32 len; +u8 feature_set; +u8 reserved1[15 ]; +} __packed; + +#define MCU_PATCH_ADDRESS 0x200000 + +#define HE_PHY (p, c) u8_get_bits(c, IEEE80211_HE_PHY_##p) +#define HE_MAC (m, c) u8_get_bits(c, IEEE80211_HE_MAC_##m) + +static u8 +mt7996_mcu_get_sta_nss (u16 mcs_map) +{ +u8 nss; + +for (nss =8 ; nss >0 ; nss--) { +u8 nss_mcs = (mcs_map >> (2 * (nss -1 ))) &3 ; + +if (nss_mcs !=IEEE80211_VHT_MCS_NOT_SUPPORTED ) +break ; + } + +return nss -1 ; +} + +static void +mt7996_mcu_set_sta_he_mcs (struct ieee80211_sta *sta,__le16 *he_mcs, +u16 mcs_map) +{ +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; +enum nl80211_band band = msta->vif->phy->mt76->chandef.chan->band; +const u16 *mask = msta->vif->bitrate_mask.control[band].he_mcs; +int nss, max_nss = sta->deflink.rx_nss >3 ?4 : sta->deflink.rx_nss; + +for (nss =0 ; nss < max_nss; nss++) { +int mcs; + +switch ((mcs_map >> (2 * nss)) &0x3 ) { +case IEEE80211_HE_MCS_SUPPORT_0_11 : + mcs =GENMASK (11 ,0 ); +break ; +case IEEE80211_HE_MCS_SUPPORT_0_9 : + mcs =GENMASK (9 ,0 ); +break ; +case IEEE80211_HE_MCS_SUPPORT_0_7 : + mcs =GENMASK (7 ,0 ); +break ; +default : + mcs =0 ; + } + + mcs = mcs ?fls (mcs & mask[nss]) -1 :-1 ; + +switch (mcs) { + case 0 ... 7: + mcs =IEEE80211_HE_MCS_SUPPORT_0_7 ; +break ; + case 8 ... 9: + mcs =IEEE80211_HE_MCS_SUPPORT_0_9 ; +break ; + case 10 ... 11: + mcs =IEEE80211_HE_MCS_SUPPORT_0_11 ; +break ; +default : + mcs =IEEE80211_HE_MCS_NOT_SUPPORTED ; +break ; + } + mcs_map &= ~(0x3 << (nss *2 )); + mcs_map |= mcs << (nss *2 ); + } + + *he_mcs =cpu_to_le16 (mcs_map); +} + +static void +mt7996_mcu_set_sta_vht_mcs (struct ieee80211_sta *sta,__le16 *vht_mcs, +const u16 *mask) +{ +u16 mcs, mcs_map =le16_to_cpu (sta->deflink.vht_cap.vht_mcs.rx_mcs_map); +int nss, max_nss = sta->deflink.rx_nss >3 ?4 : sta->deflink.rx_nss; + +for (nss =0 ; nss < max_nss; nss++, mcs_map >>=2 ) { +switch (mcs_map &0x3 ) { +case IEEE80211_VHT_MCS_SUPPORT_0_9 : + mcs =GENMASK (9 ,0 ); +break ; +case IEEE80211_VHT_MCS_SUPPORT_0_8 : + mcs =GENMASK (8 ,0 ); +break ; +case IEEE80211_VHT_MCS_SUPPORT_0_7 : + mcs =GENMASK (7 ,0 ); +break ; +default : + mcs =0 ; + } + + vht_mcs[nss] =cpu_to_le16 (mcs & mask[nss]); + } +} + +static void +mt7996_mcu_set_sta_ht_mcs (struct ieee80211_sta *sta,u8 *ht_mcs, +const u8 *mask) +{ +int nss, max_nss = sta->deflink.rx_nss >3 ?4 : sta->deflink.rx_nss; + +for (nss =0 ; nss < max_nss; nss++) + ht_mcs[nss] = sta->deflink.ht_cap.mcs.rx_mask[nss] & mask[nss]; +} + +static int +mt7996_mcu_parse_response (struct mt76_dev *mdev,int cmd, +struct sk_buff *skb,int seq) +{ +struct mt7996_mcu_rxd *rxd; +struct mt7996_mcu_uni_event *event; +int mcu_cmd =FIELD_GET (__MCU_CMD_FIELD_ID, cmd); +int ret =0 ; + +if (!skb) { +dev_err (mdev->dev,"Message %08x (seq %d) timeout\n" , + cmd, seq); +return -ETIMEDOUT ; + } + + rxd = (struct mt7996_mcu_rxd *)skb->data; +if (seq != rxd->seq) +return -EAGAIN ; + +if (cmd ==MCU_CMD (PATCH_SEM_CONTROL )) { +skb_pull (skb,sizeof (*rxd) -4 ); + ret = *skb->data; + }else if ((rxd->option &MCU_UNI_CMD_EVENT ) && + rxd->eid ==MCU_UNI_EVENT_RESULT ) { +skb_pull (skb,sizeof (*rxd)); + event = (struct mt7996_mcu_uni_event *)skb->data; + ret =le32_to_cpu (event->status); +/* skip invalid event */ +if (mcu_cmd != event->cid) + ret = -EAGAIN ; + }else { +skb_pull (skb,sizeof (struct mt7996_mcu_rxd )); + } + +return ret; +} + +static int +mt7996_mcu_send_message (struct mt76_dev *mdev,struct sk_buff *skb, +int cmd,int *wait_seq) +{ + struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76); +int txd_len, mcu_cmd =FIELD_GET (__MCU_CMD_FIELD_ID, cmd); +struct mt76_connac2_mcu_uni_txd *uni_txd; +struct mt76_connac2_mcu_txd *mcu_txd; +enum mt76_mcuq_id qid; +__le32 *txd; +u32 val; +u8 seq; + + mdev->mcu.timeout =20 *HZ ; + + seq = ++dev->mt76.mcu.msg_seq &0xf ; +if (!seq) + seq = ++dev->mt76.mcu.msg_seq &0xf ; + +if (cmd ==MCU_CMD (FW_SCATTER )) { + qid =MT_MCUQ_FWDL ; + goto exit; + } + + txd_len = cmd & __MCU_CMD_FIELD_UNI ?sizeof (*uni_txd) :sizeof (*mcu_txd); + txd = (__le32 *)skb_push (skb, txd_len); +if (test_bit (MT76_STATE_MCU_RUNNING , &dev->mphy.state)) + qid =MT_MCUQ_WA ; +else + qid =MT_MCUQ_WM ; + + val =FIELD_PREP (MT_TXD0_TX_BYTES , skb->len) | +FIELD_PREP (MT_TXD0_PKT_FMT ,MT_TX_TYPE_CMD ) | +FIELD_PREP (MT_TXD0_Q_IDX ,MT_TX_MCU_PORT_RX_Q0 ); + txd[0 ] =cpu_to_le32 (val); + + val =FIELD_PREP (MT_TXD1_HDR_FORMAT ,MT_HDR_FORMAT_CMD ); + txd[1 ] =cpu_to_le32 (val); + +if (cmd & __MCU_CMD_FIELD_UNI) { + uni_txd = (struct mt76_connac2_mcu_uni_txd *)txd; + uni_txd->len =cpu_to_le16 (skb->len -sizeof (uni_txd->txd)); + uni_txd->cid =cpu_to_le16 (mcu_cmd); + uni_txd->s2d_index =MCU_S2D_H2CN ; + uni_txd->pkt_type =MCU_PKT_ID ; + uni_txd->seq = seq; + +if (cmd & __MCU_CMD_FIELD_QUERY) + uni_txd->option =MCU_CMD_UNI_QUERY_ACK ; +else + uni_txd->option =MCU_CMD_UNI_EXT_ACK ; + +if ((cmd & __MCU_CMD_FIELD_WA) && (cmd & __MCU_CMD_FIELD_WM)) + uni_txd->s2d_index =MCU_S2D_H2CN ; +else if (cmd & __MCU_CMD_FIELD_WA) + uni_txd->s2d_index =MCU_S2D_H2C ; +else if (cmd & __MCU_CMD_FIELD_WM) + uni_txd->s2d_index =MCU_S2D_H2N ; + + goto exit; + } + + mcu_txd = (struct mt76_connac2_mcu_txd *)txd; + mcu_txd->len =cpu_to_le16 (skb->len -sizeof (mcu_txd->txd)); + mcu_txd->pq_id =cpu_to_le16 (MCU_PQ_ID (MT_TX_PORT_IDX_MCU , +MT_TX_MCU_PORT_RX_Q0 )); + mcu_txd->pkt_type =MCU_PKT_ID ; + mcu_txd->seq = seq; + + mcu_txd->cid =FIELD_GET (__MCU_CMD_FIELD_ID, cmd); + mcu_txd->set_query =MCU_Q_NA ; + mcu_txd->ext_cid =FIELD_GET (__MCU_CMD_FIELD_EXT_ID, cmd); +if (mcu_txd->ext_cid) { + mcu_txd->ext_cid_ack =1 ; + +if (cmd & __MCU_CMD_FIELD_QUERY) + mcu_txd->set_query =MCU_Q_QUERY ; +else + mcu_txd->set_query =MCU_Q_SET ; + } + +if (cmd & __MCU_CMD_FIELD_WA) + mcu_txd->s2d_index =MCU_S2D_H2C ; +else + mcu_txd->s2d_index =MCU_S2D_H2N ; + +exit: +if (wait_seq) + *wait_seq = seq; + +return mt76_tx_queue_skb_raw (dev, mdev->q_mcu[qid], skb,0 ); +} + +int mt7996_mcu_wa_cmd (struct mt7996_dev *dev,int cmd,u32 a1,u32 a2,u32 a3) +{ +struct { +__le32 args[3 ]; + } req = { + .args = { +cpu_to_le32 (a1), +cpu_to_le32 (a2), +cpu_to_le32 (a3), + }, + }; + +return mt76_mcu_send_msg (&dev->mt76, cmd, &req,sizeof (req), false); +} + +static void +mt7996_mcu_csa_finish (void *priv,u8 *mac,struct ieee80211_vif *vif) +{ +if (vif->bss_conf.csa_active) +ieee80211_csa_finish (vif); +} + +static void +mt7996_mcu_rx_radar_detected (struct mt7996_dev *dev,struct sk_buff *skb) +{ +struct mt76_phy *mphy = &dev->mt76.phy; +struct mt7996_mcu_rdd_report *r; + + r = (struct mt7996_mcu_rdd_report *)skb->data; + + mphy = dev->mt76.phys[r->band_idx]; +if (!mphy) +return ; + +if (r->band_idx ==MT_RX_SEL2 ) +cfg80211_background_radar_event (mphy->hw->wiphy, + &dev->rdd2_chandef, +GFP_ATOMIC ); +else +ieee80211_radar_detected (mphy->hw); + dev->hw_pattern++; +} + +static void +mt7996_mcu_rx_log_message (struct mt7996_dev *dev,struct sk_buff *skb) +{ +#define UNI_EVENT_FW_LOG_FORMAT 0 +struct mt7996_mcu_rxd *rxd = (struct mt7996_mcu_rxd *)skb->data; +const char *data = (char *)&rxd[1 ] +4 , *type; +struct tlv *tlv = (struct tlv *)data; +int len; + +if (!(rxd->option &MCU_UNI_CMD_EVENT )) { + len = skb->len -sizeof (*rxd); + data = (char *)&rxd[1 ]; + goto out; + } + +if (le16_to_cpu (tlv->tag) !=UNI_EVENT_FW_LOG_FORMAT ) +return ; + + data +=sizeof (*tlv) +4 ; + len =le16_to_cpu (tlv->len) -sizeof (*tlv) -4 ; + +out: +switch (rxd->s2d_index) { +case 0 : +if (mt7996_debugfs_rx_log (dev, data, len)) +return ; + + type ="WM" ; +break ; +case 2 : + type ="WA" ; +break ; +default : + type ="unknown" ; +break ; + } + +wiphy_info (mt76_hw (dev)->wiphy,"%s: %.*s" , type, len, data); +} + +static void +mt7996_mcu_cca_finish (void *priv,u8 *mac,struct ieee80211_vif *vif) +{ +if (!vif->bss_conf.color_change_active) +return ; + +ieee80211_color_change_finish (vif); +} + +static void +mt7996_mcu_ie_countdown (struct mt7996_dev *dev,struct sk_buff *skb) +{ +#define UNI_EVENT_IE_COUNTDOWN_CSA 0 +#define UNI_EVENT_IE_COUNTDOWN_BCC 1 +struct header { +u8 band; +u8 rsv[3 ]; + }; +struct mt76_phy *mphy = &dev->mt76.phy; +struct mt7996_mcu_rxd *rxd = (struct mt7996_mcu_rxd *)skb->data; +const char *data = (char *)&rxd[1 ], *tail; +struct header *hdr = (struct header *)data; +struct tlv *tlv = (struct tlv *)(data +4 ); + +if (hdr->band && dev->mt76.phys[hdr->band]) + mphy = dev->mt76.phys[hdr->band]; + + tail = skb->data +le16_to_cpu (rxd->len); +while (data +sizeof (struct tlv ) < tail &&le16_to_cpu (tlv->len)) { +switch (le16_to_cpu (tlv->tag)) { +case UNI_EVENT_IE_COUNTDOWN_CSA : +ieee80211_iterate_active_interfaces_atomic (mphy->hw, +IEEE80211_IFACE_ITER_RESUME_ALL , + mt7996_mcu_csa_finish, mphy->hw); +break ; +case UNI_EVENT_IE_COUNTDOWN_BCC : +ieee80211_iterate_active_interfaces_atomic (mphy->hw, +IEEE80211_IFACE_ITER_RESUME_ALL , + mt7996_mcu_cca_finish, mphy->hw); +break ; + } + + data +=le16_to_cpu (tlv->len); + tlv = (struct tlv *)data; + } +} + +static void +mt7996_mcu_rx_ext_event (struct mt7996_dev *dev,struct sk_buff *skb) +{ +struct mt7996_mcu_rxd *rxd = (struct mt7996_mcu_rxd *)skb->data; + +switch (rxd->ext_eid) { +case MCU_EXT_EVENT_FW_LOG_2_HOST : +mt7996_mcu_rx_log_message (dev, skb); +break ; +default : +break ; + } +} + +static void +mt7996_mcu_rx_unsolicited_event (struct mt7996_dev *dev,struct sk_buff *skb) +{ +struct mt7996_mcu_rxd *rxd = (struct mt7996_mcu_rxd *)skb->data; + +switch (rxd->eid) { +case MCU_EVENT_EXT : +mt7996_mcu_rx_ext_event (dev, skb); +break ; +default : +break ; + } +dev_kfree_skb (skb); +} + +static void +mt7996_mcu_uni_rx_unsolicited_event (struct mt7996_dev *dev,struct sk_buff *skb) +{ +struct mt7996_mcu_rxd *rxd = (struct mt7996_mcu_rxd *)skb->data; + +switch (rxd->eid) { +case MCU_UNI_EVENT_FW_LOG_2_HOST : +mt7996_mcu_rx_log_message (dev, skb); +break ; +case MCU_UNI_EVENT_IE_COUNTDOWN : +mt7996_mcu_ie_countdown (dev, skb); +break ; +case MCU_UNI_EVENT_RDD_REPORT : +mt7996_mcu_rx_radar_detected (dev, skb); +break ; +default : +break ; + } +dev_kfree_skb (skb); +} + +void mt7996_mcu_rx_event (struct mt7996_dev *dev,struct sk_buff *skb) +{ +struct mt7996_mcu_rxd *rxd = (struct mt7996_mcu_rxd *)skb->data; + +if (rxd->option &MCU_UNI_CMD_UNSOLICITED_EVENT ) { +mt7996_mcu_uni_rx_unsolicited_event (dev, skb); +return ; + } + +/* WA still uses legacy event*/ +if (rxd->ext_eid ==MCU_EXT_EVENT_FW_LOG_2_HOST || + !rxd->seq) +mt7996_mcu_rx_unsolicited_event (dev, skb); +else +mt76_mcu_rx_event (&dev->mt76, skb); +} + +static struct tlv * +mt7996_mcu_add_uni_tlv (struct sk_buff *skb,u16 tag,u16 len) +{ +struct tlv *ptlv, tlv = { + .tag =cpu_to_le16 (tag), + .len =cpu_to_le16 (len), + }; + + ptlv =skb_put (skb, len); +memcpy (ptlv, &tlv,sizeof (tlv)); + +return ptlv; +} + +static void +mt7996_mcu_bss_rfch_tlv (struct sk_buff *skb,struct ieee80211_vif *vif, +struct mt7996_phy *phy) +{ +static const u8 rlm_ch_band[] = { + [NL80211_BAND_2GHZ ] =1 , + [NL80211_BAND_5GHZ ] =2 , + [NL80211_BAND_6GHZ ] =3 , + }; +struct cfg80211_chan_def *chandef = &phy->mt76->chandef; +struct bss_rlm_tlv *ch; +struct tlv *tlv; +int freq1 = chandef->center_freq1; + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_BSS_INFO_RLM ,sizeof (*ch)); + + ch = (struct bss_rlm_tlv *)tlv; + ch->control_channel = chandef->chan->hw_value; + ch->center_chan =ieee80211_frequency_to_channel (freq1); + ch->bw =mt76_connac_chan_bw (chandef); + ch->tx_streams =hweight8 (phy->mt76->antenna_mask); + ch->rx_streams =hweight8 (phy->mt76->antenna_mask); + ch->band = rlm_ch_band[chandef->chan->band]; + +if (chandef->width ==NL80211_CHAN_WIDTH_80P80 ) { +int freq2 = chandef->center_freq2; + + ch->center_chan2 =ieee80211_frequency_to_channel (freq2); + } +} + +static void +mt7996_mcu_bss_ra_tlv (struct sk_buff *skb,struct ieee80211_vif *vif, +struct mt7996_phy *phy) +{ +struct bss_ra_tlv *ra; +struct tlv *tlv; + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_BSS_INFO_RA ,sizeof (*ra)); + + ra = (struct bss_ra_tlv *)tlv; + ra->short_preamble = true; +} + +static void +mt7996_mcu_bss_he_tlv (struct sk_buff *skb,struct ieee80211_vif *vif, +struct mt7996_phy *phy) +{ +#define DEFAULT_HE_PE_DURATION 4 +#define DEFAULT_HE_DURATION_RTS_THRES 1023 +const struct ieee80211_sta_he_cap *cap; +struct bss_info_uni_he *he; +struct tlv *tlv; + + cap =mt76_connac_get_he_phy_cap (phy->mt76, vif); + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_BSS_INFO_HE_BASIC ,sizeof (*he)); + + he = (struct bss_info_uni_he *)tlv; + he->he_pe_duration = vif->bss_conf.htc_trig_based_pkt_ext; +if (!he->he_pe_duration) + he->he_pe_duration =DEFAULT_HE_PE_DURATION ; + + he->he_rts_thres =cpu_to_le16 (vif->bss_conf.frame_time_rts_th); +if (!he->he_rts_thres) + he->he_rts_thres =cpu_to_le16 (DEFAULT_HE_DURATION_RTS_THRES ); + + he->max_nss_mcs[CMD_HE_MCS_BW80 ] = cap->he_mcs_nss_supp.tx_mcs_80; + he->max_nss_mcs[CMD_HE_MCS_BW160 ] = cap->he_mcs_nss_supp.tx_mcs_160; + he->max_nss_mcs[CMD_HE_MCS_BW8080 ] = cap->he_mcs_nss_supp.tx_mcs_80p80; +} + +static void +mt7996_mcu_bss_bmc_tlv (struct sk_buff *skb,struct mt7996_phy *phy) +{ +struct bss_rate_tlv *bmc; +struct cfg80211_chan_def *chandef = &phy->mt76->chandef; +enum nl80211_band band = chandef->chan->band; +struct tlv *tlv; + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_BSS_INFO_RATE ,sizeof (*bmc)); + + bmc = (struct bss_rate_tlv *)tlv; +if (band ==NL80211_BAND_2GHZ ) { + bmc->short_preamble = true; + }else { + bmc->bc_trans =cpu_to_le16 (0x8080 ); + bmc->mc_trans =cpu_to_le16 (0x8080 ); + bmc->bc_fixed_rate =1 ; + bmc->mc_fixed_rate =1 ; + bmc->short_preamble =1 ; + } +} + +static void +mt7996_mcu_bss_txcmd_tlv (struct sk_buff *skb,bool en) +{ +struct bss_txcmd_tlv *txcmd; +struct tlv *tlv; + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_BSS_INFO_TXCMD ,sizeof (*txcmd)); + + txcmd = (struct bss_txcmd_tlv *)tlv; + txcmd->txcmd_mode = en; +} + +static void +mt7996_mcu_bss_mld_tlv (struct sk_buff *skb,struct ieee80211_vif *vif) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct bss_mld_tlv *mld; +struct tlv *tlv; + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_BSS_INFO_MLD ,sizeof (*mld)); + + mld = (struct bss_mld_tlv *)tlv; + mld->group_mld_id =0xff ; + mld->own_mld_id = mvif->mt76.idx; + mld->remap_idx =0xff ; +} + +static void +mt7996_mcu_bss_sec_tlv (struct sk_buff *skb,struct ieee80211_vif *vif) +{ +struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; +struct bss_sec_tlv *sec; +struct tlv *tlv; + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_BSS_INFO_SEC ,sizeof (*sec)); + + sec = (struct bss_sec_tlv *)tlv; + sec->cipher = mvif->cipher; +} + +static int +mt7996_mcu_muar_config (struct mt7996_phy *phy,struct ieee80211_vif *vif, +bool bssid,bool enable) +{ +#define UNI_MUAR_ENTRY 2 +struct mt7996_dev *dev = phy->dev; +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +u32 idx = mvif->mt76.omac_idx -REPEATER_BSSID_START ; +const u8 *addr = vif->addr; + +struct { +struct { +u8 band; +u8 __rsv[3 ]; + } hdr; + +__le16 tag; +__le16 len; + +bool smesh; +u8 bssid; +u8 index; +u8 entry_add; +u8 addr[ETH_ALEN ]; +u8 __rsv[2 ]; + } __packed req = { + .hdr.band = phy->mt76->band_idx, + .tag =cpu_to_le16 (UNI_MUAR_ENTRY ), + .len =cpu_to_le16 (sizeof (req) -sizeof (req.hdr)), + .smesh = false, + .index = idx *2 + bssid, + .entry_add = true, + }; + +if (bssid) + addr = vif->bss_conf.bssid; + +if (enable) +memcpy (req.addr, addr,ETH_ALEN ); + +return mt76_mcu_send_msg (&dev->mt76,MCU_WM_UNI_CMD (REPT_MUAR ), &req, +sizeof (req), true); +} + +static int +mt7996_mcu_bss_basic_tlv (struct sk_buff *skb, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct mt76_phy *phy,u16 wlan_idx, +bool enable) +{ +struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; +struct cfg80211_chan_def *chandef = &phy->chandef; +struct mt76_connac_bss_basic_tlv *bss; +u32 type =CONNECTION_INFRA_AP ; +struct tlv *tlv; +int idx; + +switch (vif->type) { +case NL80211_IFTYPE_MESH_POINT : +case NL80211_IFTYPE_AP : +case NL80211_IFTYPE_MONITOR : +break ; +case NL80211_IFTYPE_STATION : +if (enable) { +rcu_read_lock (); +if (!sta) + sta =ieee80211_find_sta (vif, + vif->bss_conf.bssid); +/* TODO: enable BSS_INFO_UAPSD & BSS_INFO_PM */ +if (sta) { +struct mt76_wcid *wcid; + + wcid = (struct mt76_wcid *)sta->drv_priv; + wlan_idx = wcid->idx; + } +rcu_read_unlock (); + } + type =CONNECTION_INFRA_STA ; +break ; +case NL80211_IFTYPE_ADHOC : + type =CONNECTION_IBSS_ADHOC ; +break ; +default : +WARN_ON (1 ); +break ; + } + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_BSS_INFO_BASIC ,sizeof (*bss)); + + bss = (struct mt76_connac_bss_basic_tlv *)tlv; + bss->bcn_interval =cpu_to_le16 (vif->bss_conf.beacon_int); + bss->dtim_period = vif->bss_conf.dtim_period; + bss->bmc_tx_wlan_idx =cpu_to_le16 (wlan_idx); + bss->sta_idx =cpu_to_le16 (wlan_idx); + bss->conn_type =cpu_to_le32 (type); + bss->omac_idx = mvif->omac_idx; + bss->band_idx = mvif->band_idx; + bss->wmm_idx = mvif->wmm_idx; + bss->conn_state = !enable; + bss->active = enable; + + idx = mvif->omac_idx >EXT_BSSID_START ?HW_BSSID_0 : mvif->omac_idx; + bss->hw_bss_idx = idx; + +if (vif->type ==NL80211_IFTYPE_MONITOR ) { +memcpy (bss->bssid, phy->macaddr,ETH_ALEN ); +return 0 ; + } + +memcpy (bss->bssid, vif->bss_conf.bssid,ETH_ALEN ); + bss->bcn_interval =cpu_to_le16 (vif->bss_conf.beacon_int); + bss->dtim_period = vif->bss_conf.dtim_period; + bss->phymode =mt76_connac_get_phy_mode (phy, vif, + chandef->chan->band,NULL ); + +if (chandef->chan->band ==NL80211_BAND_6GHZ ) + bss->phymode_ext |=PHY_MODE_AX_6G ; + +return 0 ; +} + +static struct sk_buff * +__mt7996_mcu_alloc_bss_req (struct mt76_dev *dev,struct mt76_vif *mvif,int len) +{ +struct bss_req_hdr hdr = { + .bss_idx = mvif->idx, + }; +struct sk_buff *skb; + + skb =mt76_mcu_msg_alloc (dev,NULL , len); +if (!skb) +return ERR_PTR (-ENOMEM ); + +skb_put_data (skb, &hdr,sizeof (hdr)); + +return skb; +} + +int mt7996_mcu_add_bss_info (struct mt7996_phy *phy, +struct ieee80211_vif *vif,int enable) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_dev *dev = phy->dev; +struct sk_buff *skb; + +if (mvif->mt76.omac_idx >=REPEATER_BSSID_START ) { +mt7996_mcu_muar_config (phy, vif, false, enable); +mt7996_mcu_muar_config (phy, vif, true, enable); + } + + skb =__mt7996_mcu_alloc_bss_req (&dev->mt76, &mvif->mt76, +MT7996_BSS_UPDATE_MAX_SIZE ); +if (IS_ERR (skb)) +return PTR_ERR (skb); + +/* bss_basic must be first */ +mt7996_mcu_bss_basic_tlv (skb, vif,NULL , phy->mt76, + mvif->sta.wcid.idx, enable); +mt7996_mcu_bss_sec_tlv (skb, vif); + +if (vif->type ==NL80211_IFTYPE_MONITOR ) + goto out; + +if (enable) { +mt7996_mcu_bss_rfch_tlv (skb, vif, phy); +mt7996_mcu_bss_bmc_tlv (skb, phy); +mt7996_mcu_bss_ra_tlv (skb, vif, phy); +mt7996_mcu_bss_txcmd_tlv (skb, true); + +if (vif->bss_conf.he_support) +mt7996_mcu_bss_he_tlv (skb, vif, phy); + +/* this tag is necessary no matter if the vif is MLD */ +mt7996_mcu_bss_mld_tlv (skb, vif); + } +out: +return mt76_mcu_skb_send_msg (&dev->mt76, skb, +MCU_WMWA_UNI_CMD (BSS_INFO_UPDATE ), true); +} + +static int +mt7996_mcu_sta_ba (struct mt76_dev *dev,struct mt76_vif *mvif, +struct ieee80211_ampdu_params *params, +bool enable,bool tx) +{ +struct mt76_wcid *wcid = (struct mt76_wcid *)params->sta->drv_priv; +struct sta_rec_ba_uni *ba; +struct sk_buff *skb; +struct tlv *tlv; + + skb =__mt76_connac_mcu_alloc_sta_req (dev, mvif, wcid, +MT7996_STA_UPDATE_MAX_SIZE ); +if (IS_ERR (skb)) +return PTR_ERR (skb); + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_BA ,sizeof (*ba)); + + ba = (struct sta_rec_ba_uni *)tlv; + ba->ba_type = tx ?MT_BA_TYPE_ORIGINATOR :MT_BA_TYPE_RECIPIENT ; + ba->winsize =cpu_to_le16 (params->buf_size); + ba->ssn =cpu_to_le16 (params->ssn); + ba->ba_en = enable << params->tid; + ba->amsdu = params->amsdu; + ba->tid = params->tid; + +return mt76_mcu_skb_send_msg (dev, skb, +MCU_WMWA_UNI_CMD (STA_REC_UPDATE ), true); +} + +/** starec & wtbl **/ +int mt7996_mcu_add_tx_ba (struct mt7996_dev *dev, +struct ieee80211_ampdu_params *params, +bool enable) +{ +struct mt7996_sta *msta = (struct mt7996_sta *)params->sta->drv_priv; +struct mt7996_vif *mvif = msta->vif; + +if (enable && !params->amsdu) + msta->wcid.amsdu = false; + +return mt7996_mcu_sta_ba (&dev->mt76, &mvif->mt76, params, + enable, true); +} + +int mt7996_mcu_add_rx_ba (struct mt7996_dev *dev, +struct ieee80211_ampdu_params *params, +bool enable) +{ +struct mt7996_sta *msta = (struct mt7996_sta *)params->sta->drv_priv; +struct mt7996_vif *mvif = msta->vif; + +return mt7996_mcu_sta_ba (&dev->mt76, &mvif->mt76, params, + enable, false); +} + +static void +mt7996_mcu_sta_he_tlv (struct sk_buff *skb,struct ieee80211_sta *sta) +{ +struct ieee80211_he_cap_elem *elem = &sta->deflink.he_cap.he_cap_elem; +struct ieee80211_he_mcs_nss_supp mcs_map; +struct sta_rec_he_v2 *he; +struct tlv *tlv; +int i =0 ; + +if (!sta->deflink.he_cap.has_he) +return ; + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_HE_V2 ,sizeof (*he)); + + he = (struct sta_rec_he_v2 *)tlv; +for (i =0 ; i <11 ; i++) { +if (i <6 ) + he->he_mac_cap[i] =cpu_to_le16 (elem->mac_cap_info[i]); + he->he_phy_cap[i] =cpu_to_le16 (elem->phy_cap_info[i]); + } + + mcs_map = sta->deflink.he_cap.he_mcs_nss_supp; +switch (sta->deflink.bandwidth) { +case IEEE80211_STA_RX_BW_160 : +if (elem->phy_cap_info[0 ] & +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G ) +mt7996_mcu_set_sta_he_mcs (sta, + &he->max_nss_mcs[CMD_HE_MCS_BW8080 ], +le16_to_cpu (mcs_map.rx_mcs_80p80)); + +mt7996_mcu_set_sta_he_mcs (sta, + &he->max_nss_mcs[CMD_HE_MCS_BW160 ], +le16_to_cpu (mcs_map.rx_mcs_160)); + fallthrough; +default : +mt7996_mcu_set_sta_he_mcs (sta, + &he->max_nss_mcs[CMD_HE_MCS_BW80 ], +le16_to_cpu (mcs_map.rx_mcs_80)); +break ; + } + + he->pkt_ext =2 ; +} + +static void +mt7996_mcu_sta_he_6g_tlv (struct sk_buff *skb,struct ieee80211_sta *sta) +{ +struct sta_rec_he_6g_capa *he_6g; +struct tlv *tlv; + +if (!sta->deflink.he_6ghz_capa.capa) +return ; + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_HE_6G ,sizeof (*he_6g)); + + he_6g = (struct sta_rec_he_6g_capa *)tlv; + he_6g->capa =cpu_to_le16 (sta->deflink.he_6ghz_capa.capa); +} + +static void +mt7996_mcu_sta_ht_tlv (struct sk_buff *skb,struct ieee80211_sta *sta) +{ +struct sta_rec_ht *ht; +struct tlv *tlv; + +if (!sta->deflink.ht_cap.ht_supported) +return ; + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_HT ,sizeof (*ht)); + + ht = (struct sta_rec_ht *)tlv; + ht->ht_cap =cpu_to_le16 (sta->deflink.ht_cap.cap); +} + +static void +mt7996_mcu_sta_vht_tlv (struct sk_buff *skb,struct ieee80211_sta *sta) +{ +struct sta_rec_vht *vht; +struct tlv *tlv; + +/* For 6G band, this tlv is necessary to let hw work normally */ +if (!sta->deflink.he_6ghz_capa.capa && !sta->deflink.vht_cap.vht_supported) +return ; + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_VHT ,sizeof (*vht)); + + vht = (struct sta_rec_vht *)tlv; + vht->vht_cap =cpu_to_le32 (sta->deflink.vht_cap.cap); + vht->vht_rx_mcs_map = sta->deflink.vht_cap.vht_mcs.rx_mcs_map; + vht->vht_tx_mcs_map = sta->deflink.vht_cap.vht_mcs.tx_mcs_map; +} + +static void +mt7996_mcu_sta_amsdu_tlv (struct mt7996_dev *dev,struct sk_buff *skb, +struct ieee80211_vif *vif,struct ieee80211_sta *sta) +{ +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; +struct sta_rec_amsdu *amsdu; +struct tlv *tlv; + +if (vif->type !=NL80211_IFTYPE_STATION && + vif->type !=NL80211_IFTYPE_AP ) +return ; + +if (!sta->deflink.agg.max_amsdu_len) +return ; + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_HW_AMSDU ,sizeof (*amsdu)); + amsdu = (struct sta_rec_amsdu *)tlv; + amsdu->max_amsdu_num =8 ; + amsdu->amsdu_en = true; + msta->wcid.amsdu = true; + +switch (sta->deflink.agg.max_amsdu_len) { +case IEEE80211_MAX_MPDU_LEN_VHT_11454 : + amsdu->max_mpdu_size = +IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 ; +return ; +case IEEE80211_MAX_MPDU_LEN_HT_7935 : +case IEEE80211_MAX_MPDU_LEN_VHT_7991 : + amsdu->max_mpdu_size =IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 ; +return ; +default : + amsdu->max_mpdu_size =IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 ; +return ; + } +} + +static inline bool +mt7996_is_ebf_supported (struct mt7996_phy *phy,struct ieee80211_vif *vif, +struct ieee80211_sta *sta,bool bfee) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +int tx_ant =hweight8 (phy->mt76->antenna_mask) -1 ; + +if (vif->type !=NL80211_IFTYPE_STATION && + vif->type !=NL80211_IFTYPE_AP ) +return false; + +if (!bfee && tx_ant <2 ) +return false; + +if (sta->deflink.he_cap.has_he) { +struct ieee80211_he_cap_elem *pe = &sta->deflink.he_cap.he_cap_elem; + +if (bfee) +return mvif->cap.he_su_ebfee && +HE_PHY (CAP3_SU_BEAMFORMER , pe->phy_cap_info[3 ]); +else +return mvif->cap.he_su_ebfer && +HE_PHY (CAP4_SU_BEAMFORMEE , pe->phy_cap_info[4 ]); + } + +if (sta->deflink.vht_cap.vht_supported) { +u32 cap = sta->deflink.vht_cap.cap; + +if (bfee) +return mvif->cap.vht_su_ebfee && + (cap &IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE ); +else +return mvif->cap.vht_su_ebfer && + (cap &IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE ); + } + +return false; +} + +static void +mt7996_mcu_sta_sounding_rate (struct sta_rec_bf *bf) +{ + bf->sounding_phy =MT_PHY_TYPE_OFDM ; + bf->ndp_rate =0 ;/* mcs0 */ + bf->ndpa_rate =MT7996_CFEND_RATE_DEFAULT ;/* ofdm 24m */ + bf->rept_poll_rate =MT7996_CFEND_RATE_DEFAULT ;/* ofdm 24m */ +} + +static void +mt7996_mcu_sta_bfer_ht (struct ieee80211_sta *sta,struct mt7996_phy *phy, +struct sta_rec_bf *bf) +{ +struct ieee80211_mcs_info *mcs = &sta->deflink.ht_cap.mcs; +u8 n =0 ; + + bf->tx_mode =MT_PHY_TYPE_HT ; + +if ((mcs->tx_params &IEEE80211_HT_MCS_TX_RX_DIFF ) && + (mcs->tx_params &IEEE80211_HT_MCS_TX_DEFINED )) + n =FIELD_GET (IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK , + mcs->tx_params); +else if (mcs->rx_mask[3 ]) + n =3 ; +else if (mcs->rx_mask[2 ]) + n =2 ; +else if (mcs->rx_mask[1 ]) + n =1 ; + + bf->nrow =hweight8 (phy->mt76->antenna_mask) -1 ; + bf->ncol =min_t (u8, bf->nrow, n); + bf->ibf_ncol = n; +} + +static void +mt7996_mcu_sta_bfer_vht (struct ieee80211_sta *sta,struct mt7996_phy *phy, +struct sta_rec_bf *bf,bool explicit) +{ +struct ieee80211_sta_vht_cap *pc = &sta->deflink.vht_cap; +struct ieee80211_sta_vht_cap *vc = &phy->mt76->sband_5g.sband.vht_cap; +u16 mcs_map =le16_to_cpu (pc->vht_mcs.rx_mcs_map); +u8 nss_mcs =mt7996_mcu_get_sta_nss (mcs_map); +u8 tx_ant =hweight8 (phy->mt76->antenna_mask) -1 ; + + bf->tx_mode =MT_PHY_TYPE_VHT ; + +if (explicit) { +u8 sts, snd_dim; + +mt7996_mcu_sta_sounding_rate (bf); + + sts =FIELD_GET (IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK , + pc->cap); + snd_dim =FIELD_GET (IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK , + vc->cap); + bf->nrow =min_t (u8,min_t (u8, snd_dim, sts), tx_ant); + bf->ncol =min_t (u8, nss_mcs, bf->nrow); + bf->ibf_ncol = bf->ncol; + +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_160 ) + bf->nrow =1 ; + }else { + bf->nrow = tx_ant; + bf->ncol =min_t (u8, nss_mcs, bf->nrow); + bf->ibf_ncol = nss_mcs; + +if (sta->deflink.bandwidth ==IEEE80211_STA_RX_BW_160 ) + bf->ibf_nrow =1 ; + } +} + +static void +mt7996_mcu_sta_bfer_he (struct ieee80211_sta *sta,struct ieee80211_vif *vif, +struct mt7996_phy *phy,struct sta_rec_bf *bf) +{ +struct ieee80211_sta_he_cap *pc = &sta->deflink.he_cap; +struct ieee80211_he_cap_elem *pe = &pc->he_cap_elem; +const struct ieee80211_sta_he_cap *vc = +mt76_connac_get_he_phy_cap (phy->mt76, vif); +const struct ieee80211_he_cap_elem *ve = &vc->he_cap_elem; +u16 mcs_map =le16_to_cpu (pc->he_mcs_nss_supp.rx_mcs_80); +u8 nss_mcs =mt7996_mcu_get_sta_nss (mcs_map); +u8 snd_dim, sts; + + bf->tx_mode =MT_PHY_TYPE_HE_SU ; + +mt7996_mcu_sta_sounding_rate (bf); + + bf->trigger_su =HE_PHY (CAP6_TRIG_SU_BEAMFORMING_FB , + pe->phy_cap_info[6 ]); + bf->trigger_mu =HE_PHY (CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB , + pe->phy_cap_info[6 ]); + snd_dim =HE_PHY (CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK , + ve->phy_cap_info[5 ]); + sts =HE_PHY (CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_MASK , + pe->phy_cap_info[4 ]); + bf->nrow =min_t (u8, snd_dim, sts); + bf->ncol =min_t (u8, nss_mcs, bf->nrow); + bf->ibf_ncol = bf->ncol; + +if (sta->deflink.bandwidth !=IEEE80211_STA_RX_BW_160 ) +return ; + +/* go over for 160MHz and 80p80 */ +if (pe->phy_cap_info[0 ] & +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G ) { + mcs_map =le16_to_cpu (pc->he_mcs_nss_supp.rx_mcs_160); + nss_mcs =mt7996_mcu_get_sta_nss (mcs_map); + + bf->ncol_gt_bw80 = nss_mcs; + } + +if (pe->phy_cap_info[0 ] & +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G ) { + mcs_map =le16_to_cpu (pc->he_mcs_nss_supp.rx_mcs_80p80); + nss_mcs =mt7996_mcu_get_sta_nss (mcs_map); + +if (bf->ncol_gt_bw80) + bf->ncol_gt_bw80 =min_t (u8, bf->ncol_gt_bw80, nss_mcs); +else + bf->ncol_gt_bw80 = nss_mcs; + } + + snd_dim =HE_PHY (CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK , + ve->phy_cap_info[5 ]); + sts =HE_PHY (CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_MASK , + pe->phy_cap_info[4 ]); + + bf->nrow_gt_bw80 =min_t (int, snd_dim, sts); +} + +static void +mt7996_mcu_sta_bfer_tlv (struct mt7996_dev *dev,struct sk_buff *skb, +struct ieee80211_vif *vif,struct ieee80211_sta *sta) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_phy *phy = mvif->phy; +int tx_ant =hweight8 (phy->mt76->antenna_mask) -1 ; +struct sta_rec_bf *bf; +struct tlv *tlv; +const u8 matrix[4 ][4 ] = { + {0 ,0 ,0 ,0 }, + {1 ,1 ,0 ,0 },/* 2x1, 2x2, 2x3, 2x4 */ + {2 ,4 ,4 ,0 },/* 3x1, 3x2, 3x3, 3x4 */ + {3 ,5 ,6 ,0 }/* 4x1, 4x2, 4x3, 4x4 */ + }; +bool ebf; + +if (!(sta->deflink.ht_cap.ht_supported || sta->deflink.he_cap.has_he)) +return ; + + ebf =mt7996_is_ebf_supported (phy, vif, sta, false); +if (!ebf && !dev->ibf) +return ; + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_BF ,sizeof (*bf)); + bf = (struct sta_rec_bf *)tlv; + +/* he: eBF only, in accordance with spec +* vht: support eBF and iBF +* ht: iBF only, since mac80211 lacks of eBF support +*/ +if (sta->deflink.he_cap.has_he && ebf) +mt7996_mcu_sta_bfer_he (sta, vif, phy, bf); +else if (sta->deflink.vht_cap.vht_supported) +mt7996_mcu_sta_bfer_vht (sta, phy, bf, ebf); +else if (sta->deflink.ht_cap.ht_supported) +mt7996_mcu_sta_bfer_ht (sta, phy, bf); +else +return ; + + bf->bf_cap = ebf ? ebf : dev->ibf <<1 ; + bf->bw = sta->deflink.bandwidth; + bf->ibf_dbw = sta->deflink.bandwidth; + bf->ibf_nrow = tx_ant; + +if (!ebf && sta->deflink.bandwidth <=IEEE80211_STA_RX_BW_40 && !bf->ncol) + bf->ibf_timeout =0x48 ; +else + bf->ibf_timeout =0x18 ; + +if (ebf && bf->nrow != tx_ant) + bf->mem_20m = matrix[tx_ant][bf->ncol]; +else + bf->mem_20m = matrix[bf->nrow][bf->ncol]; + +switch (sta->deflink.bandwidth) { +case IEEE80211_STA_RX_BW_160 : +case IEEE80211_STA_RX_BW_80 : + bf->mem_total = bf->mem_20m *2 ; +break ; +case IEEE80211_STA_RX_BW_40 : + bf->mem_total = bf->mem_20m; +break ; +case IEEE80211_STA_RX_BW_20 : +default : +break ; + } +} + +static void +mt7996_mcu_sta_bfee_tlv (struct mt7996_dev *dev,struct sk_buff *skb, +struct ieee80211_vif *vif,struct ieee80211_sta *sta) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_phy *phy = mvif->phy; +int tx_ant =hweight8 (phy->mt76->antenna_mask) -1 ; +struct sta_rec_bfee *bfee; +struct tlv *tlv; +u8 nrow =0 ; + +if (!(sta->deflink.vht_cap.vht_supported || sta->deflink.he_cap.has_he)) +return ; + +if (!mt7996_is_ebf_supported (phy, vif, sta, true)) +return ; + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_BFEE ,sizeof (*bfee)); + bfee = (struct sta_rec_bfee *)tlv; + +if (sta->deflink.he_cap.has_he) { +struct ieee80211_he_cap_elem *pe = &sta->deflink.he_cap.he_cap_elem; + + nrow =HE_PHY (CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK , + pe->phy_cap_info[5 ]); + }else if (sta->deflink.vht_cap.vht_supported) { +struct ieee80211_sta_vht_cap *pc = &sta->deflink.vht_cap; + + nrow =FIELD_GET (IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK , + pc->cap); + } + +/* reply with identity matrix to avoid 2x2 BF negative gain */ + bfee->fb_identity_matrix = (nrow ==1 && tx_ant ==2 ); +} + +static void +mt7996_mcu_sta_phy_tlv (struct mt7996_dev *dev,struct sk_buff *skb, +struct ieee80211_vif *vif,struct ieee80211_sta *sta) +{ +struct sta_rec_phy *phy; +struct tlv *tlv; +u8 af =0 , mm =0 ; + +if (!sta->deflink.ht_cap.ht_supported && !sta->deflink.he_6ghz_capa.capa) +return ; + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_PHY ,sizeof (*phy)); + + phy = (struct sta_rec_phy *)tlv; +if (sta->deflink.ht_cap.ht_supported) { + af = sta->deflink.ht_cap.ampdu_factor; + mm = sta->deflink.ht_cap.ampdu_density; + } + +if (sta->deflink.vht_cap.vht_supported) { +u8 vht_af =FIELD_GET (IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK , + sta->deflink.vht_cap.cap); + + af =max_t (u8, af, vht_af); + } + +if (sta->deflink.he_6ghz_capa.capa) { + af =le16_get_bits (sta->deflink.he_6ghz_capa.capa, +IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP ); + mm =le16_get_bits (sta->deflink.he_6ghz_capa.capa, +IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START ); + } + + phy->ampdu =FIELD_PREP (IEEE80211_HT_AMPDU_PARM_FACTOR , af) | +FIELD_PREP (IEEE80211_HT_AMPDU_PARM_DENSITY , mm); + phy->max_ampdu_len = af; +} + +static void +mt7996_mcu_sta_hdrt_tlv (struct mt7996_dev *dev,struct sk_buff *skb) +{ +struct sta_rec_hdrt *hdrt; +struct tlv *tlv; + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_HDRT ,sizeof (*hdrt)); + + hdrt = (struct sta_rec_hdrt *)tlv; + hdrt->hdrt_mode =1 ; +} + +static void +mt7996_mcu_sta_hdr_trans_tlv (struct mt7996_dev *dev,struct sk_buff *skb, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta) +{ +struct sta_rec_hdr_trans *hdr_trans; +struct mt76_wcid *wcid; +struct tlv *tlv; + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_HDR_TRANS ,sizeof (*hdr_trans)); + hdr_trans = (struct sta_rec_hdr_trans *)tlv; + hdr_trans->dis_rx_hdr_tran = true; + +if (vif->type ==NL80211_IFTYPE_STATION ) + hdr_trans->to_ds = true; +else + hdr_trans->from_ds = true; + + wcid = (struct mt76_wcid *)sta->drv_priv; +if (!wcid) +return ; + + hdr_trans->dis_rx_hdr_tran = !test_bit (MT_WCID_FLAG_HDR_TRANS , &wcid->flags); +if (test_bit (MT_WCID_FLAG_4ADDR , &wcid->flags)) { + hdr_trans->to_ds = true; + hdr_trans->from_ds = true; + } +} + +static enum mcu_mmps_mode +mt7996_mcu_get_mmps_mode (enum ieee80211_smps_mode smps) +{ +switch (smps) { +case IEEE80211_SMPS_OFF : +return MCU_MMPS_DISABLE ; +case IEEE80211_SMPS_STATIC : +return MCU_MMPS_STATIC ; +case IEEE80211_SMPS_DYNAMIC : +return MCU_MMPS_DYNAMIC ; +default : +return MCU_MMPS_DISABLE ; + } +} + +int mt7996_mcu_set_fixed_rate_ctrl (struct mt7996_dev *dev, +void *data,u16 version) +{ +struct ra_fixed_rate *req; +struct uni_header hdr; +struct sk_buff *skb; +struct tlv *tlv; +int len; + + len =sizeof (hdr) +sizeof (*req); + + skb =mt76_mcu_msg_alloc (&dev->mt76,NULL , len); +if (!skb) +return -ENOMEM ; + +skb_put_data (skb, &hdr,sizeof (hdr)); + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_RA_FIXED_RATE ,sizeof (*req)); + req = (struct ra_fixed_rate *)tlv; + req->version =cpu_to_le16 (version); +memcpy (&req->rate, data,sizeof (req->rate)); + +return mt76_mcu_skb_send_msg (&dev->mt76, skb, +MCU_WM_UNI_CMD (RA ), true); +} + +static void +mt7996_mcu_sta_rate_ctrl_tlv (struct sk_buff *skb,struct mt7996_dev *dev, +struct ieee80211_vif *vif,struct ieee80211_sta *sta) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt76_phy *mphy = mvif->phy->mt76; +struct cfg80211_chan_def *chandef = &mphy->chandef; +struct cfg80211_bitrate_mask *mask = &mvif->bitrate_mask; +enum nl80211_band band = chandef->chan->band; +struct sta_rec_ra *ra; +struct tlv *tlv; +u32 supp_rate = sta->deflink.supp_rates[band]; +u32 cap = sta->wme ?STA_CAP_WMM :0 ; + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_RA ,sizeof (*ra)); + ra = (struct sta_rec_ra *)tlv; + + ra->valid = true; + ra->auto_rate = true; + ra->phy_mode =mt76_connac_get_phy_mode (mphy, vif, band, sta); + ra->channel = chandef->chan->hw_value; + ra->bw = sta->deflink.bandwidth; + ra->phy.bw = sta->deflink.bandwidth; + ra->mmps_mode =mt7996_mcu_get_mmps_mode (sta->deflink.smps_mode); + +if (supp_rate) { + supp_rate &= mask->control[band].legacy; + ra->rate_len =hweight32 (supp_rate); + +if (band ==NL80211_BAND_2GHZ ) { + ra->supp_mode =MODE_CCK ; + ra->supp_cck_rate = supp_rate &GENMASK (3 ,0 ); + +if (ra->rate_len >4 ) { + ra->supp_mode |=MODE_OFDM ; + ra->supp_ofdm_rate = supp_rate >>4 ; + } + }else { + ra->supp_mode =MODE_OFDM ; + ra->supp_ofdm_rate = supp_rate; + } + } + +if (sta->deflink.ht_cap.ht_supported) { + ra->supp_mode |=MODE_HT ; + ra->af = sta->deflink.ht_cap.ampdu_factor; + ra->ht_gf = !!(sta->deflink.ht_cap.cap &IEEE80211_HT_CAP_GRN_FLD ); + + cap |=STA_CAP_HT ; +if (sta->deflink.ht_cap.cap &IEEE80211_HT_CAP_SGI_20 ) + cap |=STA_CAP_SGI_20 ; +if (sta->deflink.ht_cap.cap &IEEE80211_HT_CAP_SGI_40 ) + cap |=STA_CAP_SGI_40 ; +if (sta->deflink.ht_cap.cap &IEEE80211_HT_CAP_TX_STBC ) + cap |=STA_CAP_TX_STBC ; +if (sta->deflink.ht_cap.cap &IEEE80211_HT_CAP_RX_STBC ) + cap |=STA_CAP_RX_STBC ; +if (mvif->cap.ht_ldpc && + (sta->deflink.ht_cap.cap &IEEE80211_HT_CAP_LDPC_CODING )) + cap |=STA_CAP_LDPC ; + +mt7996_mcu_set_sta_ht_mcs (sta, ra->ht_mcs, + mask->control[band].ht_mcs); + ra->supp_ht_mcs = *(__le32 *)ra->ht_mcs; + } + +if (sta->deflink.vht_cap.vht_supported) { +u8 af; + + ra->supp_mode |=MODE_VHT ; + af =FIELD_GET (IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK , + sta->deflink.vht_cap.cap); + ra->af =max_t (u8, ra->af, af); + + cap |=STA_CAP_VHT ; +if (sta->deflink.vht_cap.cap &IEEE80211_VHT_CAP_SHORT_GI_80 ) + cap |=STA_CAP_VHT_SGI_80 ; +if (sta->deflink.vht_cap.cap &IEEE80211_VHT_CAP_SHORT_GI_160 ) + cap |=STA_CAP_VHT_SGI_160 ; +if (sta->deflink.vht_cap.cap &IEEE80211_VHT_CAP_TXSTBC ) + cap |=STA_CAP_VHT_TX_STBC ; +if (sta->deflink.vht_cap.cap &IEEE80211_VHT_CAP_RXSTBC_1 ) + cap |=STA_CAP_VHT_RX_STBC ; +if (mvif->cap.vht_ldpc && + (sta->deflink.vht_cap.cap &IEEE80211_VHT_CAP_RXLDPC )) + cap |=STA_CAP_VHT_LDPC ; + +mt7996_mcu_set_sta_vht_mcs (sta, ra->supp_vht_mcs, + mask->control[band].vht_mcs); + } + +if (sta->deflink.he_cap.has_he) { + ra->supp_mode |=MODE_HE ; + cap |=STA_CAP_HE ; + +if (sta->deflink.he_6ghz_capa.capa) + ra->af =le16_get_bits (sta->deflink.he_6ghz_capa.capa, +IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP ); + } + ra->sta_cap =cpu_to_le32 (cap); +} + +int mt7996_mcu_add_rate_ctrl (struct mt7996_dev *dev,struct ieee80211_vif *vif, +struct ieee80211_sta *sta,bool changed) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; +struct sk_buff *skb; + + skb =__mt76_connac_mcu_alloc_sta_req (&dev->mt76, &mvif->mt76, + &msta->wcid, +MT7996_STA_UPDATE_MAX_SIZE ); +if (IS_ERR (skb)) +return PTR_ERR (skb); + +/* firmware rc algorithm refers to sta_rec_he for HE control. +* once dev->rc_work changes the settings driver should also +* update sta_rec_he here. +*/ +if (changed) +mt7996_mcu_sta_he_tlv (skb, sta); + +/* sta_rec_ra accommodates BW, NSS and only MCS range format +* i.e 0-{7,8,9} for VHT. +*/ +mt7996_mcu_sta_rate_ctrl_tlv (skb, dev, vif, sta); + +return mt76_mcu_skb_send_msg (&dev->mt76, skb, +MCU_WMWA_UNI_CMD (STA_REC_UPDATE ), true); +} + +static int +mt7996_mcu_add_group (struct mt7996_dev *dev,struct ieee80211_vif *vif, +struct ieee80211_sta *sta) +{ +#define MT_STA_BSS_GROUP 1 +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_sta *msta; +struct { +u8 __rsv1[4 ]; + +__le16 tag; +__le16 len; +__le16 wlan_idx; +u8 __rsv2[2 ]; +__le32 action; +__le32 val; +u8 __rsv3[8 ]; + } __packed req = { + .tag =cpu_to_le16 (UNI_VOW_DRR_CTRL ), + .len =cpu_to_le16 (sizeof (req) -4 ), + .action =cpu_to_le32 (MT_STA_BSS_GROUP ), + .val =cpu_to_le32 (mvif->mt76.idx %16 ), + }; + + msta = sta ? (struct mt7996_sta *)sta->drv_priv : &mvif->sta; + req.wlan_idx =cpu_to_le16 (msta->wcid.idx); + +return mt76_mcu_send_msg (&dev->mt76,MCU_WM_UNI_CMD (VOW ), &req, +sizeof (req), true); +} + +int mt7996_mcu_add_sta (struct mt7996_dev *dev,struct ieee80211_vif *vif, +struct ieee80211_sta *sta,bool enable) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_sta *msta; +struct sk_buff *skb; +int ret; + + msta = sta ? (struct mt7996_sta *)sta->drv_priv : &mvif->sta; + + skb =__mt76_connac_mcu_alloc_sta_req (&dev->mt76, &mvif->mt76, + &msta->wcid, +MT7996_STA_UPDATE_MAX_SIZE ); +if (IS_ERR (skb)) +return PTR_ERR (skb); + +/* starec basic */ +mt76_connac_mcu_sta_basic_tlv (skb, vif, sta, enable, + !rcu_access_pointer (dev->mt76.wcid[msta->wcid.idx])); +if (!enable) + goto out; + +/* tag order is in accordance with firmware dependency. */ +if (sta) { +/* starec phy */ +mt7996_mcu_sta_phy_tlv (dev, skb, vif, sta); +/* starec hdrt mode */ +mt7996_mcu_sta_hdrt_tlv (dev, skb); +/* starec bfer */ +mt7996_mcu_sta_bfer_tlv (dev, skb, vif, sta); +/* starec ht */ +mt7996_mcu_sta_ht_tlv (skb, sta); +/* starec vht */ +mt7996_mcu_sta_vht_tlv (skb, sta); +/* starec uapsd */ +mt76_connac_mcu_sta_uapsd (skb, vif, sta); +/* starec amsdu */ +mt7996_mcu_sta_amsdu_tlv (dev, skb, vif, sta); +/* starec he */ +mt7996_mcu_sta_he_tlv (skb, sta); +/* starec he 6g*/ +mt7996_mcu_sta_he_6g_tlv (skb, sta); +/* TODO: starec muru */ +/* starec bfee */ +mt7996_mcu_sta_bfee_tlv (dev, skb, vif, sta); +/* starec hdr trans */ +mt7996_mcu_sta_hdr_trans_tlv (dev, skb, vif, sta); + } + + ret =mt7996_mcu_add_group (dev, vif, sta); +if (ret) { +dev_kfree_skb (skb); +return ret; + } +out: +return mt76_mcu_skb_send_msg (&dev->mt76, skb, +MCU_WMWA_UNI_CMD (STA_REC_UPDATE ), true); +} + +static int +mt7996_mcu_sta_key_tlv (struct mt76_wcid *wcid, +struct mt76_connac_sta_key_conf *sta_key_conf, +struct sk_buff *skb, +struct ieee80211_key_conf *key, +enum set_key_cmd cmd) +{ +struct sta_rec_sec_uni *sec; +struct tlv *tlv; + + tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_KEY_V2 ,sizeof (*sec)); + sec = (struct sta_rec_sec_uni *)tlv; + sec->add = cmd; + +if (cmd ==SET_KEY ) { +struct sec_key_uni *sec_key; +u8 cipher; + + cipher =mt76_connac_mcu_get_cipher (key->cipher); +if (cipher ==MCU_CIPHER_NONE ) +return -EOPNOTSUPP ; + + sec_key = &sec->key[0 ]; + sec_key->cipher_len =sizeof (*sec_key); + +if (cipher ==MCU_CIPHER_BIP_CMAC_128 ) { + sec_key->wlan_idx =cpu_to_le16 (wcid->idx); + sec_key->cipher_id =MCU_CIPHER_AES_CCMP ; + sec_key->key_id = sta_key_conf->keyidx; + sec_key->key_len =16 ; +memcpy (sec_key->key, sta_key_conf->key,16 ); + + sec_key = &sec->key[1 ]; + sec_key->wlan_idx =cpu_to_le16 (wcid->idx); + sec_key->cipher_id =MCU_CIPHER_BIP_CMAC_128 ; + sec_key->cipher_len =sizeof (*sec_key); + sec_key->key_len =16 ; +memcpy (sec_key->key, key->key,16 ); + sec->n_cipher =2 ; + }else { + sec_key->wlan_idx =cpu_to_le16 (wcid->idx); + sec_key->cipher_id = cipher; + sec_key->key_id = key->keyidx; + sec_key->key_len = key->keylen; +memcpy (sec_key->key, key->key, key->keylen); + +if (cipher ==MCU_CIPHER_TKIP ) { +/* Rx/Tx MIC keys are swapped */ +memcpy (sec_key->key +16 , key->key +24 ,8 ); +memcpy (sec_key->key +24 , key->key +16 ,8 ); + } + +/* store key_conf for BIP batch update */ +if (cipher ==MCU_CIPHER_AES_CCMP ) { +memcpy (sta_key_conf->key, key->key, key->keylen); + sta_key_conf->keyidx = key->keyidx; + } + + sec->n_cipher =1 ; + } + }else { + sec->n_cipher =0 ; + } + +return 0 ; +} + +int mt7996_mcu_add_key (struct mt76_dev *dev,struct ieee80211_vif *vif, +struct mt76_connac_sta_key_conf *sta_key_conf, +struct ieee80211_key_conf *key,int mcu_cmd, +struct mt76_wcid *wcid,enum set_key_cmd cmd) +{ +struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv; +struct sk_buff *skb; +int ret; + + skb =__mt76_connac_mcu_alloc_sta_req (dev, mvif, wcid, +MT7996_STA_UPDATE_MAX_SIZE ); +if (IS_ERR (skb)) +return PTR_ERR (skb); + + ret =mt7996_mcu_sta_key_tlv (wcid, sta_key_conf, skb, key, cmd); +if (ret) +return ret; + +return mt76_mcu_skb_send_msg (dev, skb, mcu_cmd, true); +} + +int mt7996_mcu_add_dev_info (struct mt7996_phy *phy, +struct ieee80211_vif *vif,bool enable) +{ +struct mt7996_dev *dev = phy->dev; +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct { +struct req_hdr { +u8 omac_idx; +u8 band_idx; +u8 __rsv[2 ]; + } __packed hdr; +struct req_tlv { +__le16 tag; +__le16 len; +u8 active; +u8 __rsv; +u8 omac_addr[ETH_ALEN ]; + } __packed tlv; + } data = { + .hdr = { + .omac_idx = mvif->mt76.omac_idx, + .band_idx = mvif->mt76.band_idx, + }, + .tlv = { + .tag =cpu_to_le16 (DEV_INFO_ACTIVE ), + .len =cpu_to_le16 (sizeof (struct req_tlv )), + .active = enable, + }, + }; + +if (mvif->mt76.omac_idx >=REPEATER_BSSID_START ) +return mt7996_mcu_muar_config (phy, vif, false, enable); + +memcpy (data.tlv.omac_addr, vif->addr,ETH_ALEN ); +return mt76_mcu_send_msg (&dev->mt76,MCU_WMWA_UNI_CMD (DEV_INFO_UPDATE ), + &data,sizeof (data), true); +} + +static void +mt7996_mcu_beacon_cntdwn (struct ieee80211_vif *vif,struct sk_buff *rskb, +struct sk_buff *skb, +struct ieee80211_mutable_offsets *offs) +{ +struct bss_bcn_cntdwn_tlv *info; +struct tlv *tlv; +u16 tag; + +if (!offs->cntdwn_counter_offs[0 ]) +return ; + + tag = vif->bss_conf.csa_active ?UNI_BSS_INFO_BCN_CSA :UNI_BSS_INFO_BCN_BCC ; + + tlv =mt7996_mcu_add_uni_tlv (rskb, tag,sizeof (*info)); + + info = (struct bss_bcn_cntdwn_tlv *)tlv; + info->cnt = skb->data[offs->cntdwn_counter_offs[0 ]]; +} + +static void +mt7996_mcu_beacon_cont (struct mt7996_dev *dev,struct ieee80211_vif *vif, +struct sk_buff *rskb,struct sk_buff *skb, +struct bss_bcn_content_tlv *bcn, +struct ieee80211_mutable_offsets *offs) +{ +struct mt76_wcid *wcid = &dev->mt76.global_wcid; +u8 *buf; + + bcn->pkt_len =cpu_to_le16 (MT_TXD_SIZE + skb->len); + bcn->tim_ie_pos =cpu_to_le16 (offs->tim_offset); + +if (offs->cntdwn_counter_offs[0 ]) { +u16 offset = offs->cntdwn_counter_offs[0 ]; + +if (vif->bss_conf.csa_active) + bcn->csa_ie_pos =cpu_to_le16 (offset -4 ); +if (vif->bss_conf.color_change_active) + bcn->bcc_ie_pos =cpu_to_le16 (offset -3 ); + } + + buf = (u8 *)bcn +sizeof (*bcn) -MAX_BEACON_SIZE ; +mt7996_mac_write_txwi (dev, (__le32 *)buf, skb, wcid,0 ,NULL , +BSS_CHANGED_BEACON ); +memcpy (buf +MT_TXD_SIZE , skb->data, skb->len); +} + +static void +mt7996_mcu_beacon_check_caps (struct mt7996_phy *phy,struct ieee80211_vif *vif, +struct sk_buff *skb) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_vif_cap *vc = &mvif->cap; +const struct ieee80211_he_cap_elem *he; +const struct ieee80211_vht_cap *vht; +const struct ieee80211_ht_cap *ht; +struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; +const u8 *ie; +u32 len, bc; + +/* Check missing configuration options to allow AP mode in mac80211 +* to remain in sync with hostapd settings, and get a subset of +* beacon and hardware capabilities. +*/ +if (WARN_ON_ONCE (skb->len <= (mgmt->u.beacon.variable - skb->data))) +return ; + +memset (vc,0 ,sizeof (*vc)); + + len = skb->len - (mgmt->u.beacon.variable - skb->data); + + ie =cfg80211_find_ie (WLAN_EID_HT_CAPABILITY , mgmt->u.beacon.variable, + len); +if (ie && ie[1 ] >=sizeof (*ht)) { + ht = (void *)(ie +2 ); + vc->ht_ldpc |= !!(le16_to_cpu (ht->cap_info) & +IEEE80211_HT_CAP_LDPC_CODING ); + } + + ie =cfg80211_find_ie (WLAN_EID_VHT_CAPABILITY , mgmt->u.beacon.variable, + len); +if (ie && ie[1 ] >=sizeof (*vht)) { +u32 pc = phy->mt76->sband_5g.sband.vht_cap.cap; + + vht = (void *)(ie +2 ); + bc =le32_to_cpu (vht->vht_cap_info); + + vc->vht_ldpc |= !!(bc &IEEE80211_VHT_CAP_RXLDPC ); + vc->vht_su_ebfer = + (bc &IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE ) && + (pc &IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE ); + vc->vht_su_ebfee = + (bc &IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE ) && + (pc &IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE ); + vc->vht_mu_ebfer = + (bc &IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE ) && + (pc &IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE ); + vc->vht_mu_ebfee = + (bc &IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE ) && + (pc &IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE ); + } + + ie =cfg80211_find_ext_ie (WLAN_EID_EXT_HE_CAPABILITY , + mgmt->u.beacon.variable, len); +if (ie && ie[1 ] >=sizeof (*he) +1 ) { +const struct ieee80211_sta_he_cap *pc = +mt76_connac_get_he_phy_cap (phy->mt76, vif); +const struct ieee80211_he_cap_elem *pe = &pc->he_cap_elem; + + he = (void *)(ie +3 ); + + vc->he_ldpc = +HE_PHY (CAP1_LDPC_CODING_IN_PAYLOAD , pe->phy_cap_info[1 ]); + vc->he_su_ebfer = +HE_PHY (CAP3_SU_BEAMFORMER , he->phy_cap_info[3 ]) && +HE_PHY (CAP3_SU_BEAMFORMER , pe->phy_cap_info[3 ]); + vc->he_su_ebfee = +HE_PHY (CAP4_SU_BEAMFORMEE , he->phy_cap_info[4 ]) && +HE_PHY (CAP4_SU_BEAMFORMEE , pe->phy_cap_info[4 ]); + vc->he_mu_ebfer = +HE_PHY (CAP4_MU_BEAMFORMER , he->phy_cap_info[4 ]) && +HE_PHY (CAP4_MU_BEAMFORMER , pe->phy_cap_info[4 ]); + } +} + +int mt7996_mcu_add_beacon (struct ieee80211_hw *hw, +struct ieee80211_vif *vif,int en) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct ieee80211_mutable_offsets offs; +struct ieee80211_tx_info *info; +struct sk_buff *skb, *rskb; +struct tlv *tlv; +struct bss_bcn_content_tlv *bcn; + + rskb =__mt7996_mcu_alloc_bss_req (&dev->mt76, &mvif->mt76, +MT7996_BEACON_UPDATE_SIZE ); +if (IS_ERR (rskb)) +return PTR_ERR (rskb); + + tlv =mt7996_mcu_add_uni_tlv (rskb, +UNI_BSS_INFO_BCN_CONTENT ,sizeof (*bcn)); + bcn = (struct bss_bcn_content_tlv *)tlv; + bcn->enable = en; + +if (!en) + goto out; + + skb =ieee80211_beacon_get_template (hw, vif, &offs,0 ); +if (!skb) +return -EINVAL ; + +if (skb->len >MAX_BEACON_SIZE -MT_TXD_SIZE ) { +dev_err (dev->mt76.dev,"Bcn size limit exceed\n" ); +dev_kfree_skb (skb); +return -EINVAL ; + } + + info =IEEE80211_SKB_CB (skb); + info->hw_queue |=FIELD_PREP (MT_TX_HW_QUEUE_PHY , phy->mt76->band_idx); + +mt7996_mcu_beacon_check_caps (phy, vif, skb); + +mt7996_mcu_beacon_cont (dev, vif, rskb, skb, bcn, &offs); +/* TODO: subtag - 11v MBSSID */ +mt7996_mcu_beacon_cntdwn (vif, rskb, skb, &offs); +dev_kfree_skb (skb); +out: +return mt76_mcu_skb_send_msg (&phy->dev->mt76, rskb, +MCU_WMWA_UNI_CMD (BSS_INFO_UPDATE ), true); +} + +int mt7996_mcu_beacon_inband_discov (struct mt7996_dev *dev, +struct ieee80211_vif *vif,u32 changed) +{ +#define OFFLOAD_TX_MODE_SU BIT(0) +#define OFFLOAD_TX_MODE_MU BIT(1) +struct ieee80211_hw *hw =mt76_hw (dev); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct cfg80211_chan_def *chandef = &mvif->phy->mt76->chandef; +enum nl80211_band band = chandef->chan->band; +struct mt76_wcid *wcid = &dev->mt76.global_wcid; +struct bss_inband_discovery_tlv *discov; +struct ieee80211_tx_info *info; +struct sk_buff *rskb, *skb =NULL ; +struct tlv *tlv; +u8 *buf, interval; + + rskb =__mt7996_mcu_alloc_bss_req (&dev->mt76, &mvif->mt76, +MT7996_INBAND_FRAME_SIZE ); +if (IS_ERR (rskb)) +return PTR_ERR (rskb); + +if (changed &BSS_CHANGED_FILS_DISCOVERY && + vif->bss_conf.fils_discovery.max_interval) { + interval = vif->bss_conf.fils_discovery.max_interval; + skb =ieee80211_get_fils_discovery_tmpl (hw, vif); + }else if (changed &BSS_CHANGED_UNSOL_BCAST_PROBE_RESP && + vif->bss_conf.unsol_bcast_probe_resp_interval) { + interval = vif->bss_conf.unsol_bcast_probe_resp_interval; + skb =ieee80211_get_unsol_bcast_probe_resp_tmpl (hw, vif); + } + +if (!skb) +return -EINVAL ; + +if (skb->len >MAX_INBAND_FRAME_SIZE -MT_TXD_SIZE ) { +dev_err (dev->mt76.dev,"inband discovery size limit exceed\n" ); +dev_kfree_skb (skb); +return -EINVAL ; + } + + info =IEEE80211_SKB_CB (skb); + info->control.vif = vif; + info->band = band; + info->hw_queue |=FIELD_PREP (MT_TX_HW_QUEUE_PHY , phy->mt76->band_idx); + + tlv =mt7996_mcu_add_uni_tlv (rskb,UNI_BSS_INFO_OFFLOAD ,sizeof (*discov)); + + discov = (struct bss_inband_discovery_tlv *)tlv; + discov->tx_mode =OFFLOAD_TX_MODE_SU ; +/* 0: UNSOL PROBE RESP, 1: FILS DISCOV */ + discov->tx_type = !!(changed &BSS_CHANGED_FILS_DISCOVERY ); + discov->tx_interval = interval; + discov->prob_rsp_len =cpu_to_le16 (MT_TXD_SIZE + skb->len); + discov->enable = true; + discov->wcid =cpu_to_le16 (MT7996_WTBL_RESERVED ); + + buf = (u8 *)tlv +sizeof (*discov) -MAX_INBAND_FRAME_SIZE ; + +mt7996_mac_write_txwi (dev, (__le32 *)buf, skb, wcid,0 ,NULL , + changed); + +memcpy (buf +MT_TXD_SIZE , skb->data, skb->len); + +dev_kfree_skb (skb); + +return mt76_mcu_skb_send_msg (&dev->mt76, rskb, +MCU_WMWA_UNI_CMD (BSS_INFO_UPDATE ), true); +} + +static int mt7996_driver_own (struct mt7996_dev *dev,u8 band) +{ +mt76_wr (dev,MT_TOP_LPCR_HOST_BAND (band),MT_TOP_LPCR_HOST_DRV_OWN ); +if (!mt76_poll_msec (dev,MT_TOP_LPCR_HOST_BAND (band), +MT_TOP_LPCR_HOST_FW_OWN_STAT ,0 ,500 )) { +dev_err (dev->mt76.dev,"Timeout for driver own\n" ); +return -EIO ; + } + +/* clear irq when the driver own success */ +mt76_wr (dev,MT_TOP_LPCR_HOST_BAND_IRQ_STAT (band), +MT_TOP_LPCR_HOST_BAND_STAT ); + +return 0 ; +} + +static u32 mt7996_patch_sec_mode (u32 key_info) +{ +u32 sec =u32_get_bits (key_info,MT7996_PATCH_SEC ), key =0 ; + +if (key_info ==GENMASK (31 ,0 ) || sec ==MT7996_SEC_MODE_PLAIN ) +return 0 ; + +if (sec ==MT7996_SEC_MODE_AES ) + key =u32_get_bits (key_info,MT7996_PATCH_AES_KEY ); +else + key =u32_get_bits (key_info,MT7996_PATCH_SCRAMBLE_KEY ); + +return MT7996_SEC_ENCRYPT |MT7996_SEC_IV | +u32_encode_bits (key,MT7996_SEC_KEY_IDX ); +} + +static int mt7996_load_patch (struct mt7996_dev *dev) +{ +const struct mt7996_patch_hdr *hdr; +const struct firmware *fw =NULL ; +int i, ret, sem; + + sem =mt76_connac_mcu_patch_sem_ctrl (&dev->mt76,1 ); +switch (sem) { +case PATCH_IS_DL : +return 0 ; +case PATCH_NOT_DL_SEM_SUCCESS : +break ; +default : +dev_err (dev->mt76.dev,"Failed to get patch semaphore\n" ); +return -EAGAIN ; + } + + ret =request_firmware (&fw,MT7996_ROM_PATCH , dev->mt76.dev); +if (ret) + goto out; + +if (!fw || !fw->data || fw->size <sizeof (*hdr)) { +dev_err (dev->mt76.dev,"Invalid firmware\n" ); + ret = -EINVAL ; + goto out; + } + + hdr = (const struct mt7996_patch_hdr *)(fw->data); + +dev_info (dev->mt76.dev,"HW/SW Version: 0x%x, Build Time: %.16s\n" , +be32_to_cpu (hdr->hw_sw_ver), hdr->build_date); + +for (i =0 ; i <be32_to_cpu (hdr->desc.n_region); i++) { +struct mt7996_patch_sec *sec; +const u8 *dl; +u32 len, addr, sec_key_idx, mode =DL_MODE_NEED_RSP ; + + sec = (struct mt7996_patch_sec *)(fw->data +sizeof (*hdr) + + i *sizeof (*sec)); +if ((be32_to_cpu (sec->type) &PATCH_SEC_TYPE_MASK ) != +PATCH_SEC_TYPE_INFO ) { + ret = -EINVAL ; + goto out; + } + + addr =be32_to_cpu (sec->info.addr); + len =be32_to_cpu (sec->info.len); + sec_key_idx =be32_to_cpu (sec->info.sec_key_idx); + dl = fw->data +be32_to_cpu (sec->offs); + + mode |=mt7996_patch_sec_mode (sec_key_idx); + + ret =mt76_connac_mcu_init_download (&dev->mt76, addr, len, + mode); +if (ret) { +dev_err (dev->mt76.dev,"Download request failed\n" ); + goto out; + } + + ret =__mt76_mcu_send_firmware (&dev->mt76,MCU_CMD (FW_SCATTER ), + dl, len,4096 ); +if (ret) { +dev_err (dev->mt76.dev,"Failed to send patch\n" ); + goto out; + } + } + + ret =mt76_connac_mcu_start_patch (&dev->mt76); +if (ret) +dev_err (dev->mt76.dev,"Failed to start patch\n" ); + +out: + sem =mt76_connac_mcu_patch_sem_ctrl (&dev->mt76,0 ); +switch (sem) { +case PATCH_REL_SEM_SUCCESS : +break ; +default : + ret = -EAGAIN ; +dev_err (dev->mt76.dev,"Failed to release patch semaphore\n" ); +break ; + } +release_firmware (fw); + +return ret; +} + +static int +mt7996_mcu_send_ram_firmware (struct mt7996_dev *dev, +const struct mt7996_fw_trailer *hdr, +const u8 *data,bool is_wa) +{ +int i, offset =0 ; +u32 override =0 , option =0 ; + +for (i =0 ; i < hdr->n_region; i++) { +const struct mt7996_fw_region *region; +int err; +u32 len, addr, mode; + + region = (const struct mt7996_fw_region *)((const u8 *)hdr - + (hdr->n_region - i) *sizeof (*region)); + mode =mt76_connac_mcu_gen_dl_mode (&dev->mt76, + region->feature_set, is_wa); + len =le32_to_cpu (region->len); + addr =le32_to_cpu (region->addr); + +if (region->feature_set &FW_FEATURE_OVERRIDE_ADDR ) + override = addr; + + err =mt76_connac_mcu_init_download (&dev->mt76, addr, len, + mode); +if (err) { +dev_err (dev->mt76.dev,"Download request failed\n" ); +return err; + } + + err =__mt76_mcu_send_firmware (&dev->mt76,MCU_CMD (FW_SCATTER ), + data + offset, len,4096 ); +if (err) { +dev_err (dev->mt76.dev,"Failed to send firmware.\n" ); +return err; + } + + offset += len; + } + +if (override) + option |=FW_START_OVERRIDE ; + +if (is_wa) + option |=FW_START_WORKING_PDA_CR4 ; + +return mt76_connac_mcu_start_firmware (&dev->mt76, override, option); +} + +static int mt7996_load_ram (struct mt7996_dev *dev) +{ +const struct mt7996_fw_trailer *hdr; +const struct firmware *fw; +int ret; + + ret =request_firmware (&fw,MT7996_FIRMWARE_WM , dev->mt76.dev); +if (ret) +return ret; + +if (!fw || !fw->data || fw->size <sizeof (*hdr)) { +dev_err (dev->mt76.dev,"Invalid firmware\n" ); + ret = -EINVAL ; + goto out; + } + + hdr = (const struct mt7996_fw_trailer *)(fw->data + fw->size -sizeof (*hdr)); + +dev_info (dev->mt76.dev,"WM Firmware Version: %.10s, Build Time: %.15s\n" , + hdr->fw_ver, hdr->build_date); + + ret =mt7996_mcu_send_ram_firmware (dev, hdr, fw->data, false); +if (ret) { +dev_err (dev->mt76.dev,"Failed to start WM firmware\n" ); + goto out; + } + +release_firmware (fw); + + ret =request_firmware (&fw,MT7996_FIRMWARE_WA , dev->mt76.dev); +if (ret) +return ret; + +if (!fw || !fw->data || fw->size <sizeof (*hdr)) { +dev_err (dev->mt76.dev,"Invalid firmware\n" ); + ret = -EINVAL ; + goto out; + } + + hdr = (const struct mt7996_fw_trailer *)(fw->data + fw->size -sizeof (*hdr)); + +dev_info (dev->mt76.dev,"WA Firmware Version: %.10s, Build Time: %.15s\n" , + hdr->fw_ver, hdr->build_date); + + ret =mt7996_mcu_send_ram_firmware (dev, hdr, fw->data, true); +if (ret) { +dev_err (dev->mt76.dev,"Failed to start WA firmware\n" ); + goto out; + } + +snprintf (dev->mt76.hw->wiphy->fw_version, +sizeof (dev->mt76.hw->wiphy->fw_version), +"%.10s-%.15s" , hdr->fw_ver, hdr->build_date); + +out: +release_firmware (fw); + +return ret; +} + +static int +mt7996_firmware_state (struct mt7996_dev *dev,bool wa) +{ +u32 state =FIELD_PREP (MT_TOP_MISC_FW_STATE , + wa ?FW_STATE_RDY :FW_STATE_FW_DOWNLOAD ); + +if (!mt76_poll_msec (dev,MT_TOP_MISC ,MT_TOP_MISC_FW_STATE , + state,1000 )) { +dev_err (dev->mt76.dev,"Timeout for initializing firmware\n" ); +return -EIO ; + } +return 0 ; +} + +static int mt7996_load_firmware (struct mt7996_dev *dev) +{ +int ret; + +/* make sure fw is download state */ +if (mt7996_firmware_state (dev, false)) { +/* restart firmware once */ +__mt76_mcu_restart (&dev->mt76); + ret =mt7996_firmware_state (dev, false); +if (ret) { +dev_err (dev->mt76.dev, +"Firmware is not ready for download\n" ); +return ret; + } + } + + ret =mt7996_load_patch (dev); +if (ret) +return ret; + + ret =mt7996_load_ram (dev); +if (ret) +return ret; + + ret =mt7996_firmware_state (dev, true); +if (ret) +return ret; + +mt76_queue_tx_cleanup (dev, dev->mt76.q_mcu[MT_MCUQ_FWDL ], false); + +dev_dbg (dev->mt76.dev,"Firmware init done\n" ); + +return 0 ; +} + +int mt7996_mcu_fw_log_2_host (struct mt7996_dev *dev,u8 type,u8 ctrl) +{ +struct { +u8 _rsv[4 ]; + +__le16 tag; +__le16 len; +u8 ctrl; +u8 interval; +u8 _rsv2[2 ]; + } __packed data = { + .tag =cpu_to_le16 (UNI_WSYS_CONFIG_FW_LOG_CTRL ), + .len =cpu_to_le16 (sizeof (data) -4 ), + .ctrl = ctrl, + }; + +if (type ==MCU_FW_LOG_WA ) +return mt76_mcu_send_msg (&dev->mt76,MCU_WA_UNI_CMD (WSYS_CONFIG ), + &data,sizeof (data), true); + +return mt76_mcu_send_msg (&dev->mt76,MCU_WM_UNI_CMD (WSYS_CONFIG ), &data, +sizeof (data), true); +} + +int mt7996_mcu_fw_dbg_ctrl (struct mt7996_dev *dev,u32 module,u8 level) +{ +struct { +u8 _rsv[4 ]; + +__le16 tag; +__le16 len; +__le32 module_idx; +u8 level; +u8 _rsv2[3 ]; + } data = { + .tag =cpu_to_le16 (UNI_WSYS_CONFIG_FW_DBG_CTRL ), + .len =cpu_to_le16 (sizeof (data) -4 ), + .module_idx =cpu_to_le32 (module), + .level = level, + }; + +return mt76_mcu_send_msg (&dev->mt76,MCU_WM_UNI_CMD (WSYS_CONFIG ), &data, +sizeof (data), false); +} + +static int mt7996_mcu_set_mwds (struct mt7996_dev *dev,bool enabled) +{ +struct { +u8 enable; +u8 _rsv[3 ]; + } __packed req = { + .enable = enabled + }; + +return mt76_mcu_send_msg (&dev->mt76,MCU_WA_EXT_CMD (MWDS_SUPPORT ), &req, +sizeof (req), false); +} + +static void mt7996_add_rx_airtime_tlv (struct sk_buff *skb,u8 band_idx) +{ +struct vow_rx_airtime *req; +struct tlv *tlv; + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_VOW_RX_AT_AIRTIME_CLR_EN ,sizeof (*req)); + req = (struct vow_rx_airtime *)tlv; + req->enable = true; + req->band = band_idx; + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_VOW_RX_AT_AIRTIME_EN ,sizeof (*req)); + req = (struct vow_rx_airtime *)tlv; + req->enable = true; + req->band = band_idx; +} + +static int +mt7996_mcu_init_rx_airtime (struct mt7996_dev *dev) +{ +struct uni_header hdr = {}; +struct sk_buff *skb; +int len, num; + + num =2 +2 * (dev->dbdc_support + dev->tbtc_support); + len =sizeof (hdr) + num *sizeof (struct vow_rx_airtime ); + skb =mt76_mcu_msg_alloc (&dev->mt76,NULL , len); +if (!skb) +return -ENOMEM ; + +skb_put_data (skb, &hdr,sizeof (hdr)); + +mt7996_add_rx_airtime_tlv (skb, dev->mt76.phy.band_idx); + +if (dev->dbdc_support) +mt7996_add_rx_airtime_tlv (skb,MT_BAND1 ); + +if (dev->tbtc_support) +mt7996_add_rx_airtime_tlv (skb,MT_BAND2 ); + +return mt76_mcu_skb_send_msg (&dev->mt76, skb, +MCU_WM_UNI_CMD (VOW ), true); +} + +static int +mt7996_mcu_restart (struct mt76_dev *dev) +{ +struct { +u8 __rsv1[4 ]; + +__le16 tag; +__le16 len; +u8 power_mode; +u8 __rsv2[3 ]; + } __packed req = { + .tag =cpu_to_le16 (UNI_POWER_OFF ), + .len =cpu_to_le16 (sizeof (req) -4 ), + .power_mode =1 , + }; + +return mt76_mcu_send_msg (dev,MCU_WM_UNI_CMD (POWER_CREL ), &req, +sizeof (req), false); +} + +int mt7996_mcu_init (struct mt7996_dev *dev) +{ +static const struct mt76_mcu_ops mt7996_mcu_ops = { + .headroom =sizeof (struct mt76_connac2_mcu_txd ),/* reuse */ + .mcu_skb_send_msg = mt7996_mcu_send_message, + .mcu_parse_response = mt7996_mcu_parse_response, + .mcu_restart = mt7996_mcu_restart, + }; +int ret; + + dev->mt76.mcu_ops = &mt7996_mcu_ops; + +/* force firmware operation mode into normal state, +* which should be set before firmware download stage. +*/ +mt76_wr (dev,MT_SWDEF_MODE ,MT_SWDEF_NORMAL_MODE ); + + ret =mt7996_driver_own (dev,0 ); +if (ret) +return ret; +/* set driver own for band1 when two hif exist */ +if (dev->hif2) { + ret =mt7996_driver_own (dev,1 ); +if (ret) +return ret; + } + + ret =mt7996_load_firmware (dev); +if (ret) +return ret; + +set_bit (MT76_STATE_MCU_RUNNING , &dev->mphy.state); + ret =mt7996_mcu_fw_log_2_host (dev,MCU_FW_LOG_WM ,0 ); +if (ret) +return ret; + + ret =mt7996_mcu_fw_log_2_host (dev,MCU_FW_LOG_WA ,0 ); +if (ret) +return ret; + + ret =mt7996_mcu_set_mwds (dev,1 ); +if (ret) +return ret; + + ret =mt7996_mcu_init_rx_airtime (dev); +if (ret) +return ret; + +return mt7996_mcu_wa_cmd (dev,MCU_WA_PARAM_CMD (SET ), +MCU_WA_PARAM_RED ,0 ,0 ); +} + +void mt7996_mcu_exit (struct mt7996_dev *dev) +{ +__mt76_mcu_restart (&dev->mt76); +if (mt7996_firmware_state (dev, false)) { +dev_err (dev->mt76.dev,"Failed to exit mcu\n" ); +return ; + } + +mt76_wr (dev,MT_TOP_LPCR_HOST_BAND (0 ),MT_TOP_LPCR_HOST_FW_OWN ); +if (dev->hif2) +mt76_wr (dev,MT_TOP_LPCR_HOST_BAND (1 ), +MT_TOP_LPCR_HOST_FW_OWN ); +skb_queue_purge (&dev->mt76.mcu.res_q); +} + +int mt7996_mcu_set_hdr_trans (struct mt7996_dev *dev,bool hdr_trans) +{ +struct { +u8 __rsv[4 ]; + } __packed hdr; +struct hdr_trans_blacklist *req_blacklist; +struct hdr_trans_en *req_en; +struct sk_buff *skb; +struct tlv *tlv; +int len =MT7996_HDR_TRANS_MAX_SIZE +sizeof (hdr); + + skb =mt76_mcu_msg_alloc (&dev->mt76,NULL , len); +if (!skb) +return -ENOMEM ; + +skb_put_data (skb, &hdr,sizeof (hdr)); + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_HDR_TRANS_EN ,sizeof (*req_en)); + req_en = (struct hdr_trans_en *)tlv; + req_en->enable = hdr_trans; + + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_HDR_TRANS_VLAN , +sizeof (struct hdr_trans_vlan )); + +if (hdr_trans) { + tlv =mt7996_mcu_add_uni_tlv (skb,UNI_HDR_TRANS_BLACKLIST , +sizeof (*req_blacklist)); + req_blacklist = (struct hdr_trans_blacklist *)tlv; + req_blacklist->enable =1 ; + req_blacklist->type =cpu_to_le16 (ETH_P_PAE ); + } + +return mt76_mcu_skb_send_msg (&dev->mt76, skb, +MCU_WM_UNI_CMD (RX_HDR_TRANS ), true); +} + +int mt7996_mcu_set_tx (struct mt7996_dev *dev,struct ieee80211_vif *vif) +{ +#define MCU_EDCA_AC_PARAM 0 +#define WMM_AIFS_SET BIT(0) +#define WMM_CW_MIN_SET BIT(1) +#define WMM_CW_MAX_SET BIT(2) +#define WMM_TXOP_SET BIT(3) +#define WMM_PARAM_SET (WMM_AIFS_SET | WMM_CW_MIN_SET | \ + WMM_CW_MAX_SET | WMM_TXOP_SET) +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct { +u8 bss_idx; +u8 __rsv[3 ]; + } __packed hdr = { + .bss_idx = mvif->mt76.idx, + }; +struct sk_buff *skb; +int len =sizeof (hdr) +IEEE80211_NUM_ACS *sizeof (struct edca ); +int ac; + + skb =mt76_mcu_msg_alloc (&dev->mt76,NULL , len); +if (!skb) +return -ENOMEM ; + +skb_put_data (skb, &hdr,sizeof (hdr)); + +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +struct ieee80211_tx_queue_params *q = &mvif->queue_params[ac]; +struct edca *e; +struct tlv *tlv; + + tlv =mt7996_mcu_add_uni_tlv (skb,MCU_EDCA_AC_PARAM ,sizeof (*e)); + + e = (struct edca *)tlv; + e->set =WMM_PARAM_SET ; + e->queue = ac + mvif->mt76.wmm_idx *MT7996_MAX_WMM_SETS ; + e->aifs = q->aifs; + e->txop =cpu_to_le16 (q->txop); + +if (q->cw_min) + e->cw_min =fls (q->cw_min); +else + e->cw_min =5 ; + +if (q->cw_max) + e->cw_max =fls (q->cw_max); +else + e->cw_max =10 ; + } + +return mt76_mcu_skb_send_msg (&dev->mt76, skb, +MCU_WM_UNI_CMD (EDCA_UPDATE ), true); +} + +int mt7996_mcu_set_fcc5_lpn (struct mt7996_dev *dev,int val) +{ +struct { +u8 _rsv[4 ]; + +__le16 tag; +__le16 len; + +__le32 ctrl; +__le16 min_lpn; +u8 rsv[2 ]; + } __packed req = { + .tag =cpu_to_le16 (UNI_RDD_CTRL_SET_TH ), + .len =cpu_to_le16 (sizeof (req) -4 ), + + .ctrl =cpu_to_le32 (0x1 ), + .min_lpn =cpu_to_le16 (val), + }; + +return mt76_mcu_send_msg (&dev->mt76,MCU_WM_UNI_CMD (RDD_CTRL ), + &req,sizeof (req), true); +} + +int mt7996_mcu_set_pulse_th (struct mt7996_dev *dev, +const struct mt7996_dfs_pulse *pulse) +{ +struct { +u8 _rsv[4 ]; + +__le16 tag; +__le16 len; + +__le32 ctrl; + +__le32 max_width;/* us */ +__le32 max_pwr;/* dbm */ +__le32 min_pwr;/* dbm */ +__le32 min_stgr_pri;/* us */ +__le32 max_stgr_pri;/* us */ +__le32 min_cr_pri;/* us */ +__le32 max_cr_pri;/* us */ + } __packed req = { + .tag =cpu_to_le16 (UNI_RDD_CTRL_SET_TH ), + .len =cpu_to_le16 (sizeof (req) -4 ), + + .ctrl =cpu_to_le32 (0x3 ), + +#define __req_field(field) .field = cpu_to_le32(pulse->field) +__req_field (max_width), +__req_field (max_pwr), +__req_field (min_pwr), +__req_field (min_stgr_pri), +__req_field (max_stgr_pri), +__req_field (min_cr_pri), +__req_field (max_cr_pri), +#undef __req_field + }; + +return mt76_mcu_send_msg (&dev->mt76,MCU_WM_UNI_CMD (RDD_CTRL ), + &req,sizeof (req), true); +} + +int mt7996_mcu_set_radar_th (struct mt7996_dev *dev,int index, +const struct mt7996_dfs_pattern *pattern) +{ +struct { +u8 _rsv[4 ]; + +__le16 tag; +__le16 len; + +__le32 ctrl; +__le16 radar_type; + +u8 enb; +u8 stgr; +u8 min_crpn; +u8 max_crpn; +u8 min_crpr; +u8 min_pw; +__le32 min_pri; +__le32 max_pri; +u8 max_pw; +u8 min_crbn; +u8 max_crbn; +u8 min_stgpn; +u8 max_stgpn; +u8 min_stgpr; +u8 rsv[2 ]; +__le32 min_stgpr_diff; + } __packed req = { + .tag =cpu_to_le16 (UNI_RDD_CTRL_SET_TH ), + .len =cpu_to_le16 (sizeof (req) -4 ), + + .ctrl =cpu_to_le32 (0x2 ), + .radar_type =cpu_to_le16 (index), + +#define __req_field_u8(field) .field = pattern->field +#define __req_field_u32(field) .field = cpu_to_le32(pattern->field) +__req_field_u8 (enb), +__req_field_u8 (stgr), +__req_field_u8 (min_crpn), +__req_field_u8 (max_crpn), +__req_field_u8 (min_crpr), +__req_field_u8 (min_pw), +__req_field_u32 (min_pri), +__req_field_u32 (max_pri), +__req_field_u8 (max_pw), +__req_field_u8 (min_crbn), +__req_field_u8 (max_crbn), +__req_field_u8 (min_stgpn), +__req_field_u8 (max_stgpn), +__req_field_u8 (min_stgpr), +__req_field_u32 (min_stgpr_diff), +#undef __req_field_u8 +#undef __req_field_u32 + }; + +return mt76_mcu_send_msg (&dev->mt76,MCU_WM_UNI_CMD (RDD_CTRL ), + &req,sizeof (req), true); +} + +static int +mt7996_mcu_background_chain_ctrl (struct mt7996_phy *phy, +struct cfg80211_chan_def *chandef, +int cmd) +{ +struct mt7996_dev *dev = phy->dev; +struct mt76_phy *mphy = phy->mt76; +struct ieee80211_channel *chan = mphy->chandef.chan; +int freq = mphy->chandef.center_freq1; +struct mt7996_mcu_background_chain_ctrl req = { + .tag =cpu_to_le16 (0 ), + .len =cpu_to_le16 (sizeof (req) -4 ), + .monitor_scan_type =2 ,/* simple rx */ + }; + +if (!chandef && cmd !=CH_SWITCH_BACKGROUND_SCAN_STOP ) +return -EINVAL ; + +if (!cfg80211_chandef_valid (&mphy->chandef)) +return -EINVAL ; + +switch (cmd) { +case CH_SWITCH_BACKGROUND_SCAN_START : { + req.chan = chan->hw_value; + req.central_chan =ieee80211_frequency_to_channel (freq); + req.bw =mt76_connac_chan_bw (&mphy->chandef); + req.monitor_chan = chandef->chan->hw_value; + req.monitor_central_chan = +ieee80211_frequency_to_channel (chandef->center_freq1); + req.monitor_bw =mt76_connac_chan_bw (chandef); + req.band_idx = phy->mt76->band_idx; + req.scan_mode =1 ; +break ; + } +case CH_SWITCH_BACKGROUND_SCAN_RUNNING : + req.monitor_chan = chandef->chan->hw_value; + req.monitor_central_chan = +ieee80211_frequency_to_channel (chandef->center_freq1); + req.band_idx = phy->mt76->band_idx; + req.scan_mode =2 ; +break ; +case CH_SWITCH_BACKGROUND_SCAN_STOP : + req.chan = chan->hw_value; + req.central_chan =ieee80211_frequency_to_channel (freq); + req.bw =mt76_connac_chan_bw (&mphy->chandef); + req.tx_stream =hweight8 (mphy->antenna_mask); + req.rx_stream = mphy->antenna_mask; +break ; +default : +return -EINVAL ; + } + req.band = chandef ? chandef->chan->band ==NL80211_BAND_5GHZ :1 ; + +return mt76_mcu_send_msg (&dev->mt76,MCU_WM_UNI_CMD (OFFCH_SCAN_CTRL ), + &req,sizeof (req), false); +} + +int mt7996_mcu_rdd_background_enable (struct mt7996_phy *phy, +struct cfg80211_chan_def *chandef) +{ +struct mt7996_dev *dev = phy->dev; +int err, region; + +if (!chandef) {/* disable offchain */ + err =mt7996_mcu_rdd_cmd (dev,RDD_STOP ,MT_RX_SEL2 , +0 ,0 ); +if (err) +return err; + +return mt7996_mcu_background_chain_ctrl (phy,NULL , +CH_SWITCH_BACKGROUND_SCAN_STOP ); + } + + err =mt7996_mcu_background_chain_ctrl (phy, chandef, +CH_SWITCH_BACKGROUND_SCAN_START ); +if (err) +return err; + +switch (dev->mt76.region) { +case NL80211_DFS_ETSI : + region =0 ; +break ; +case NL80211_DFS_JP : + region =2 ; +break ; +case NL80211_DFS_FCC : +default : + region =1 ; +break ; + } + +return mt7996_mcu_rdd_cmd (dev,RDD_START ,MT_RX_SEL2 , +0 , region); +} + +int mt7996_mcu_set_chan_info (struct mt7996_phy *phy,u16 tag) +{ +static const u8 ch_band[] = { + [NL80211_BAND_2GHZ ] =0 , + [NL80211_BAND_5GHZ ] =1 , + [NL80211_BAND_6GHZ ] =2 , + }; +struct mt7996_dev *dev = phy->dev; +struct cfg80211_chan_def *chandef = &phy->mt76->chandef; +int freq1 = chandef->center_freq1; +u8 band_idx = phy->mt76->band_idx; +struct { +/* fixed field */ +u8 __rsv[4 ]; + +__le16 tag; +__le16 len; +u8 control_ch; +u8 center_ch; +u8 bw; +u8 tx_path_num; +u8 rx_path;/* mask or num */ +u8 switch_reason; +u8 band_idx; +u8 center_ch2;/* for 80+80 only */ +__le16 cac_case; +u8 channel_band; +u8 rsv0; +__le32 outband_freq; +u8 txpower_drop; +u8 ap_bw; +u8 ap_center_ch; +u8 rsv1[53 ]; + } __packed req = { + .tag =cpu_to_le16 (tag), + .len =cpu_to_le16 (sizeof (req) -4 ), + .control_ch = chandef->chan->hw_value, + .center_ch =ieee80211_frequency_to_channel (freq1), + .bw =mt76_connac_chan_bw (chandef), + .tx_path_num =hweight16 (phy->mt76->chainmask), + .rx_path = phy->mt76->chainmask >> dev->chainshift[band_idx], + .band_idx = band_idx, + .channel_band = ch_band[chandef->chan->band], + }; + +if (tag ==UNI_CHANNEL_RX_PATH || + dev->mt76.hw->conf.flags &IEEE80211_CONF_MONITOR ) + req.switch_reason =CH_SWITCH_NORMAL ; +else if (phy->mt76->hw->conf.flags &IEEE80211_CONF_OFFCHANNEL ) + req.switch_reason =CH_SWITCH_SCAN_BYPASS_DPD ; +else if (!cfg80211_reg_can_beacon (phy->mt76->hw->wiphy, chandef, +NL80211_IFTYPE_AP )) + req.switch_reason =CH_SWITCH_DFS ; +else + req.switch_reason =CH_SWITCH_NORMAL ; + +if (tag ==UNI_CHANNEL_SWITCH ) + req.rx_path =hweight8 (req.rx_path); + +if (chandef->width ==NL80211_CHAN_WIDTH_80P80 ) { +int freq2 = chandef->center_freq2; + + req.center_ch2 =ieee80211_frequency_to_channel (freq2); + } + +return mt76_mcu_send_msg (&dev->mt76,MCU_WMWA_UNI_CMD (CHANNEL_SWITCH ), + &req,sizeof (req), true); +} + +static int mt7996_mcu_set_eeprom_flash (struct mt7996_dev *dev) +{ +#define MAX_PAGE_IDX_MASK GENMASK(7, 5) +#define PAGE_IDX_MASK GENMASK(4, 2) +#define PER_PAGE_SIZE 0x400 +struct mt7996_mcu_eeprom req = { + .tag =cpu_to_le16 (UNI_EFUSE_BUFFER_MODE ), + .buffer_mode =EE_MODE_BUFFER + }; +u16 eeprom_size =MT7996_EEPROM_SIZE ; +u8 total =DIV_ROUND_UP (eeprom_size,PER_PAGE_SIZE ); +u8 *eep = (u8 *)dev->mt76.eeprom.data; +int eep_len, i; + +for (i =0 ; i < total; i++, eep += eep_len) { +struct sk_buff *skb; +int ret, msg_len; + +if (i == total -1 && !!(eeprom_size %PER_PAGE_SIZE )) + eep_len = eeprom_size %PER_PAGE_SIZE ; +else + eep_len =PER_PAGE_SIZE ; + + msg_len =sizeof (req) + eep_len; + skb =mt76_mcu_msg_alloc (&dev->mt76,NULL , msg_len); +if (!skb) +return -ENOMEM ; + + req.len =cpu_to_le16 (msg_len -4 ); + req.format =FIELD_PREP (MAX_PAGE_IDX_MASK , total -1 ) | +FIELD_PREP (PAGE_IDX_MASK , i) |EE_FORMAT_WHOLE ; + req.buf_len =cpu_to_le16 (eep_len); + +skb_put_data (skb, &req,sizeof (req)); +skb_put_data (skb, eep, eep_len); + + ret =mt76_mcu_skb_send_msg (&dev->mt76, skb, +MCU_WM_UNI_CMD (EFUSE_CTRL ), true); +if (ret) +return ret; + } + +return 0 ; +} + +int mt7996_mcu_set_eeprom (struct mt7996_dev *dev) +{ +struct mt7996_mcu_eeprom req = { + .tag =cpu_to_le16 (UNI_EFUSE_BUFFER_MODE ), + .len =cpu_to_le16 (sizeof (req) -4 ), + .buffer_mode =EE_MODE_EFUSE , + .format =EE_FORMAT_WHOLE + }; + +if (dev->flash_mode) +return mt7996_mcu_set_eeprom_flash (dev); + +return mt76_mcu_send_msg (&dev->mt76,MCU_WM_UNI_CMD (EFUSE_CTRL ), + &req,sizeof (req), true); +} + +int mt7996_mcu_get_eeprom (struct mt7996_dev *dev,u32 offset) +{ +struct { +u8 _rsv[4 ]; + +__le16 tag; +__le16 len; +__le32 addr; +__le32 valid; +u8 data[16 ]; + } __packed req = { + .tag =cpu_to_le16 (UNI_EFUSE_ACCESS ), + .len =cpu_to_le16 (sizeof (req) -4 ), + .addr =cpu_to_le32 (round_down (offset, +MT7996_EEPROM_BLOCK_SIZE )), + }; +struct sk_buff *skb; +bool valid; +int ret; + + ret =mt76_mcu_send_and_get_msg (&dev->mt76,MCU_WM_UNI_CMD_QUERY (EFUSE_CTRL ), &req, +sizeof (req), true, &skb); +if (ret) +return ret; + + valid =le32_to_cpu (*(__le32 *)(skb->data +16 )); +if (valid) { +u32 addr =le32_to_cpu (*(__le32 *)(skb->data +12 )); +u8 *buf = (u8 *)dev->mt76.eeprom.data + addr; + +skb_pull (skb,64 ); +memcpy (buf, skb->data,MT7996_EEPROM_BLOCK_SIZE ); + } + +dev_kfree_skb (skb); + +return 0 ; +} + +int mt7996_mcu_get_eeprom_free_block (struct mt7996_dev *dev,u8 *block_num) +{ +struct { +u8 _rsv[4 ]; + +__le16 tag; +__le16 len; +u8 num; +u8 version; +u8 die_idx; +u8 _rsv2; + } __packed req = { + .tag =cpu_to_le16 (UNI_EFUSE_FREE_BLOCK ), + .len =cpu_to_le16 (sizeof (req) -4 ), + .version =2 , + }; +struct sk_buff *skb; +int ret; + + ret =mt76_mcu_send_and_get_msg (&dev->mt76,MCU_WM_UNI_CMD_QUERY (EFUSE_CTRL ), &req, +sizeof (req), true, &skb); +if (ret) +return ret; + + *block_num = *(u8 *)(skb->data +8 ); +dev_kfree_skb (skb); + +return 0 ; +} + +int mt7996_mcu_get_chan_mib_info (struct mt7996_phy *phy,bool chan_switch) +{ +struct { +struct { +u8 band; +u8 __rsv[3 ]; + } hdr; +struct { +__le16 tag; +__le16 len; +__le32 offs; + } data[4 ]; + } __packed req = { + .hdr.band = phy->mt76->band_idx, + }; +/* strict order */ +static const u32 offs[] = { +UNI_MIB_TX_TIME , +UNI_MIB_RX_TIME , +UNI_MIB_OBSS_AIRTIME , +UNI_MIB_NON_WIFI_TIME , + }; +struct mt76_channel_state *state = phy->mt76->chan_state; +struct mt76_channel_state *state_ts = &phy->state_ts; +struct mt7996_dev *dev = phy->dev; +struct mt7996_mcu_mib *res; +struct sk_buff *skb; +int i, ret; + +for (i =0 ; i <4 ; i++) { + req.data[i].tag =cpu_to_le16 (UNI_CMD_MIB_DATA ); + req.data[i].len =cpu_to_le16 (sizeof (req.data[i]));
Lines of this file are not shown. View the raw message.
drivers/net/wireless/mediatek/mt76/mt7996/mcu.h new file +662 -0
662 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.25.1
Part of the diff is not shown here. View the raw message.
Shayne Chen
reviewerPATCH 4/9 wifi: mt76: mt7996: add EEPROM support
In reply to Shayne Chen(Split the big patch into smaller intermediate patches by functionality for easier review. Refer to the cover letter for more info.)
--- .../wireless/mediatek/mt76/mt7996/eeprom.c | 229 ++++++++++++++++++ .../wireless/mediatek/mt76/mt7996/eeprom.h | 75 ++++++ 2 files changed, 304 insertions(+) create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/eeprom.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/eeprom.h
drivers/net/wireless/mediatek/mt76/mt7996/eeprom.c new file +229 -0
@@ -0,0 +1,229 @@ +// SPDX-License-Identifier: ISC +/* +* Copyright (C) 2022 MediaTek Inc. +*/ + +#include <linux/firmware.h> +#include "mt7996.h" +#include "eeprom.h" + +static int mt7996_check_eeprom (struct mt7996_dev *dev) +{ +u8 *eeprom = dev->mt76.eeprom.data; +u16 val =get_unaligned_le16 (eeprom); + +switch (val) { +case 0x7990 : +return 0 ; +default : +return -EINVAL ; + } +} + +static char *mt7996_eeprom_name (struct mt7996_dev *dev) +{ +/* reserve for future variants */ +return MT7996_EEPROM_DEFAULT ; +} + +static int +mt7996_eeprom_load_default (struct mt7996_dev *dev) +{ +u8 *eeprom = dev->mt76.eeprom.data; +const struct firmware *fw =NULL ; +int ret; + + ret =request_firmware (&fw,mt7996_eeprom_name (dev), dev->mt76.dev); +if (ret) +return ret; + +if (!fw || !fw->data) { +dev_err (dev->mt76.dev,"Invalid default bin\n" ); + ret = -EINVAL ; + goto out; + } + +memcpy (eeprom, fw->data,MT7996_EEPROM_SIZE ); + dev->flash_mode = true; + +out: +release_firmware (fw); + +return ret; +} + +static int mt7996_eeprom_load (struct mt7996_dev *dev) +{ +int ret; + + ret =mt76_eeprom_init (&dev->mt76,MT7996_EEPROM_SIZE ); +if (ret <0 ) +return ret; + +if (ret) { + dev->flash_mode = true; + }else { +u8 free_block_num; +u32 block_num, i; + +/* TODO: check free block event */ +mt7996_mcu_get_eeprom_free_block (dev, &free_block_num); +/* efuse info not enough */ +if (free_block_num >=59 ) +return -EINVAL ; + +/* read eeprom data from efuse */ + block_num =DIV_ROUND_UP (MT7996_EEPROM_SIZE ,MT7996_EEPROM_BLOCK_SIZE ); +for (i =0 ; i < block_num; i++) +mt7996_mcu_get_eeprom (dev, i *MT7996_EEPROM_BLOCK_SIZE ); + } + +return mt7996_check_eeprom (dev); +} + +static int mt7996_eeprom_parse_band_config (struct mt7996_phy *phy) +{ +u8 *eeprom = phy->dev->mt76.eeprom.data; +u32 val = eeprom[MT_EE_WIFI_CONF ]; +int ret =0 ; + +switch (phy->mt76->band_idx) { +case MT_BAND1 : + val =FIELD_GET (MT_EE_WIFI_CONF1_BAND_SEL , val); +break ; +case MT_BAND2 : + val = eeprom[MT_EE_WIFI_CONF +1 ]; + val =FIELD_GET (MT_EE_WIFI_CONF2_BAND_SEL , val); +break ; +default : + val =FIELD_GET (MT_EE_WIFI_CONF0_BAND_SEL , val); +break ; + } + +switch (val) { +case MT_EE_BAND_SEL_2GHZ : + phy->mt76->cap.has_2ghz = true; +break ; +case MT_EE_BAND_SEL_5GHZ : + phy->mt76->cap.has_5ghz = true; +break ; +case MT_EE_BAND_SEL_6GHZ : + phy->mt76->cap.has_6ghz = true; +break ; +case MT_EE_BAND_SEL_5GHZ_6GHZ : + phy->mt76->cap.has_5ghz = true; + phy->mt76->cap.has_6ghz = true; +break ; +default : + ret = -EINVAL ; +break ; + } + +return ret; +} + +int mt7996_eeprom_parse_hw_cap (struct mt7996_dev *dev,struct mt7996_phy *phy) +{ +u8 path, nss, band_idx = phy->mt76->band_idx; +u8 *eeprom = dev->mt76.eeprom.data; +struct mt76_phy *mphy = phy->mt76; + +switch (band_idx) { +case MT_BAND1 : + path =FIELD_GET (MT_EE_WIFI_CONF2_TX_PATH_BAND1 , + eeprom[MT_EE_WIFI_CONF +2 ]); + nss =FIELD_GET (MT_EE_WIFI_CONF5_STREAM_NUM_BAND1 , + eeprom[MT_EE_WIFI_CONF +5 ]); +break ; +case MT_BAND2 : + path =FIELD_GET (MT_EE_WIFI_CONF2_TX_PATH_BAND2 , + eeprom[MT_EE_WIFI_CONF +2 ]); + nss =FIELD_GET (MT_EE_WIFI_CONF5_STREAM_NUM_BAND2 , + eeprom[MT_EE_WIFI_CONF +5 ]); +break ; +default : + path =FIELD_GET (MT_EE_WIFI_CONF1_TX_PATH_BAND0 , + eeprom[MT_EE_WIFI_CONF +1 ]); + nss =FIELD_GET (MT_EE_WIFI_CONF4_STREAM_NUM_BAND0 , + eeprom[MT_EE_WIFI_CONF +4 ]); +break ; + } + +if (!path || path >4 ) + path =4 ; + + nss =min_t (u8,min_t (u8,4 , nss), path); + + mphy->antenna_mask =BIT (nss) -1 ; + mphy->chainmask = (BIT (path) -1 ) << dev->chainshift[band_idx]; + dev->chainmask |= mphy->chainmask; +if (band_idx <MT_BAND2 ) + dev->chainshift[band_idx +1 ] = dev->chainshift[band_idx] + +hweight16 (mphy->chainmask); + +return mt7996_eeprom_parse_band_config (phy); +} + +int mt7996_eeprom_init (struct mt7996_dev *dev) +{ +int ret; + + ret =mt7996_eeprom_load (dev); +if (ret <0 ) { +if (ret != -EINVAL ) +return ret; + +dev_warn (dev->mt76.dev,"eeprom load fail, use default bin\n" ); + ret =mt7996_eeprom_load_default (dev); +if (ret) +return ret; + } + + ret =mt7996_eeprom_parse_hw_cap (dev, &dev->phy); +if (ret <0 ) +return ret; + +memcpy (dev->mphy.macaddr, dev->mt76.eeprom.data +MT_EE_MAC_ADDR ,ETH_ALEN ); +mt76_eeprom_override (&dev->mphy); + +return 0 ; +} + +int mt7996_eeprom_get_target_power (struct mt7996_dev *dev, +struct ieee80211_channel *chan) +{ +u8 *eeprom = dev->mt76.eeprom.data; +int target_power; + +if (chan->band ==NL80211_BAND_5GHZ ) + target_power = eeprom[MT_EE_TX0_POWER_5G + +mt7996_get_channel_group_5g (chan->hw_value)]; +else if (chan->band ==NL80211_BAND_6GHZ ) + target_power = eeprom[MT_EE_TX0_POWER_6G + +mt7996_get_channel_group_6g (chan->hw_value)]; +else + target_power = eeprom[MT_EE_TX0_POWER_2G ]; + +return target_power; +} + +s8 mt7996_eeprom_get_power_delta (struct mt7996_dev *dev,int band) +{ +u8 *eeprom = dev->mt76.eeprom.data; +u32 val; +s8 delta; + +if (band ==NL80211_BAND_5GHZ ) + val = eeprom[MT_EE_RATE_DELTA_5G ]; +else if (band ==NL80211_BAND_6GHZ ) + val = eeprom[MT_EE_RATE_DELTA_6G ]; +else + val = eeprom[MT_EE_RATE_DELTA_2G ]; + +if (!(val &MT_EE_RATE_DELTA_EN )) +return 0 ; + + delta =FIELD_GET (MT_EE_RATE_DELTA_MASK , val); + +return val &MT_EE_RATE_DELTA_SIGN ? delta : -delta; +}
drivers/net/wireless/mediatek/mt76/mt7996/eeprom.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.25.1
Shayne Chen
reviewerPATCH 5/9 wifi: mt76: mt7996: add MAC support
In reply to Shayne Chen(Split the big patch into smaller intermediate patches by functionality for easier review. Refer to the cover letter for more info.)
--- .../net/wireless/mediatek/mt76/mt7996/init.c | 816 ++++++ .../net/wireless/mediatek/mt76/mt7996/mac.c | 2468 +++++++++++++++++ .../net/wireless/mediatek/mt76/mt7996/mac.h | 398 +++ 3 files changed, 3682 insertions(+) create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/init.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/mac.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/mac.h
drivers/net/wireless/mediatek/mt76/mt7996/init.c new file +816 -0
@@ -0,0 +1,816 @@ +// SPDX-License-Identifier: ISC +/* +* Copyright (C) 2022 MediaTek Inc. +*/ + +#include <linux/etherdevice.h> +#include <linux/thermal.h> +#include "mt7996.h" +#include "mac.h" +#include "mcu.h" +#include "eeprom.h" + +static const struct ieee80211_iface_limit if_limits[] = { + { + .max =1 , + .types =BIT (NL80211_IFTYPE_ADHOC ) + }, { + .max =16 , + .types =BIT (NL80211_IFTYPE_AP ) +#ifdef CONFIG_MAC80211_MESH + |BIT (NL80211_IFTYPE_MESH_POINT ) +#endif + }, { + .max =MT7996_MAX_INTERFACES , + .types =BIT (NL80211_IFTYPE_STATION ) + } +}; + +static const struct ieee80211_iface_combination if_comb[] = { + { + .limits = if_limits, + .n_limits =ARRAY_SIZE (if_limits), + .max_interfaces =MT7996_MAX_INTERFACES , + .num_different_channels =1 , + .beacon_int_infra_match = true, + .radar_detect_widths =BIT (NL80211_CHAN_WIDTH_20_NOHT ) | +BIT (NL80211_CHAN_WIDTH_20 ) | +BIT (NL80211_CHAN_WIDTH_40 ) | +BIT (NL80211_CHAN_WIDTH_80 ) | +BIT (NL80211_CHAN_WIDTH_160 ) | +BIT (NL80211_CHAN_WIDTH_80P80 ), + } +}; + +static void mt7996_led_set_config (struct led_classdev *led_cdev, +u8 delay_on,u8 delay_off) +{ +struct mt7996_dev *dev; +struct mt76_dev *mt76; +u32 val; + + mt76 = container_of(led_cdev, struct mt76_dev, led_cdev); + dev = container_of(mt76, struct mt7996_dev, mt76); + +/* select TX blink mode, 2: only data frames */ +mt76_rmw_field (dev,MT_TMAC_TCR0 (0 ),MT_TMAC_TCR0_TX_BLINK ,2 ); + +/* enable LED */ +mt76_wr (dev,MT_LED_EN (0 ),1 ); + +/* set LED Tx blink on/off time */ + val =FIELD_PREP (MT_LED_TX_BLINK_ON_MASK , delay_on) | +FIELD_PREP (MT_LED_TX_BLINK_OFF_MASK , delay_off); +mt76_wr (dev,MT_LED_TX_BLINK (0 ), val); + +/* control LED */ + val =MT_LED_CTRL_BLINK_MODE |MT_LED_CTRL_KICK ; +if (dev->mt76.led_al) + val |=MT_LED_CTRL_POLARITY ; + +mt76_wr (dev,MT_LED_CTRL (0 ), val); +mt76_clear (dev,MT_LED_CTRL (0 ),MT_LED_CTRL_KICK ); +} + +static int mt7996_led_set_blink (struct led_classdev *led_cdev, +unsigned long *delay_on, +unsigned long *delay_off) +{ +u16 delta_on =0 , delta_off =0 ; + +#define HW_TICK 10 +#define TO_HW_TICK (_t) (((_t) > HW_TICK) ? ((_t) / HW_TICK) : HW_TICK) + +if (*delay_on) + delta_on =TO_HW_TICK (*delay_on); +if (*delay_off) + delta_off =TO_HW_TICK (*delay_off); + +mt7996_led_set_config (led_cdev, delta_on, delta_off); + +return 0 ; +} + +static void mt7996_led_set_brightness (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +if (!brightness) +mt7996_led_set_config (led_cdev,0 ,0xff ); +else +mt7996_led_set_config (led_cdev,0xff ,0 ); +} + +static void +mt7996_init_txpower (struct mt7996_dev *dev, +struct ieee80211_supported_band *sband) +{ +int i, nss =hweight8 (dev->mphy.antenna_mask); +int nss_delta =mt76_tx_power_nss_delta (nss); +int pwr_delta =mt7996_eeprom_get_power_delta (dev, sband->band); +struct mt76_power_limits limits; + +for (i =0 ; i < sband->n_channels; i++) { +struct ieee80211_channel *chan = &sband->channels[i]; +int target_power =mt7996_eeprom_get_target_power (dev, chan); + + target_power += pwr_delta; + target_power =mt76_get_rate_power_limits (&dev->mphy, chan, + &limits, + target_power); + target_power += nss_delta; + target_power =DIV_ROUND_UP (target_power,2 ); + chan->max_power =min_t (int, chan->max_reg_power, + target_power); + chan->orig_mpwr = target_power; + } +} + +static void +mt7996_regd_notifier (struct wiphy *wiphy, +struct regulatory_request *request) +{ +struct ieee80211_hw *hw =wiphy_to_ieee80211_hw (wiphy); +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); + +memcpy (dev->mt76.alpha2, request->alpha2,sizeof (dev->mt76.alpha2)); + dev->mt76.region = request->dfs_region; + +if (dev->mt76.region ==NL80211_DFS_UNSET ) +mt7996_mcu_rdd_background_enable (phy,NULL ); + +mt7996_init_txpower (dev, &phy->mt76->sband_2g.sband); +mt7996_init_txpower (dev, &phy->mt76->sband_5g.sband); +mt7996_init_txpower (dev, &phy->mt76->sband_6g.sband); + + phy->mt76->dfs_state =MT_DFS_STATE_UNKNOWN ; +mt7996_dfs_init_radar_detector (phy); +} + +static void +mt7996_init_wiphy (struct ieee80211_hw *hw) +{ +struct mt7996_phy *phy =mt7996_hw_phy (hw); +struct mt76_dev *mdev = &phy->dev->mt76; +struct wiphy *wiphy = hw->wiphy; + + hw->queues =4 ; + hw->max_rx_aggregation_subframes =IEEE80211_MAX_AMPDU_BUF_HE ; + hw->max_tx_aggregation_subframes =IEEE80211_MAX_AMPDU_BUF_HE ; + hw->netdev_features =NETIF_F_RXCSUM ; + + hw->radiotap_timestamp.units_pos = +IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US ; + + phy->slottime =9 ; + + hw->sta_data_size =sizeof (struct mt7996_sta ); + hw->vif_data_size =sizeof (struct mt7996_vif ); + + wiphy->iface_combinations = if_comb; + wiphy->n_iface_combinations =ARRAY_SIZE (if_comb); + wiphy->reg_notifier = mt7996_regd_notifier; + wiphy->flags |=WIPHY_FLAG_HAS_CHANNEL_SWITCH ; + +wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_BSS_COLOR ); +wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_VHT_IBSS ); +wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_BEACON_RATE_LEGACY ); +wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_BEACON_RATE_HT ); +wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_BEACON_RATE_VHT ); +wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_BEACON_RATE_HE ); +wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP ); +wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_FILS_DISCOVERY ); + +if (!mdev->dev->of_node || + !of_property_read_bool (mdev->dev->of_node, +"mediatek,disable-radar-background" )) +wiphy_ext_feature_set (wiphy, +NL80211_EXT_FEATURE_RADAR_BACKGROUND ); + +ieee80211_hw_set (hw,HAS_RATE_CONTROL ); +ieee80211_hw_set (hw,SUPPORTS_TX_ENCAP_OFFLOAD ); +ieee80211_hw_set (hw,SUPPORTS_RX_DECAP_OFFLOAD ); +ieee80211_hw_set (hw,WANT_MONITOR_VIF ); + + hw->max_tx_fragments =4 ; + +if (phy->mt76->cap.has_2ghz) + phy->mt76->sband_2g.sband.ht_cap.cap |= +IEEE80211_HT_CAP_LDPC_CODING | +IEEE80211_HT_CAP_MAX_AMSDU ; + +if (phy->mt76->cap.has_5ghz) { + phy->mt76->sband_5g.sband.ht_cap.cap |= +IEEE80211_HT_CAP_LDPC_CODING | +IEEE80211_HT_CAP_MAX_AMSDU ; + + phy->mt76->sband_5g.sband.vht_cap.cap |= +IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | +IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK | +IEEE80211_VHT_CAP_SHORT_GI_160 | +IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ; + } + +mt76_set_stream_caps (phy->mt76, true); +mt7996_set_stream_vht_txbf_caps (phy); +mt7996_set_stream_he_caps (phy); + + wiphy->available_antennas_rx = phy->mt76->antenna_mask; + wiphy->available_antennas_tx = phy->mt76->antenna_mask; +} + +static void +mt7996_mac_init_band (struct mt7996_dev *dev,u8 band) +{ +u32 mask, set; + +/* clear estimated value of EIFS for Rx duration & OBSS time */ +mt76_wr (dev,MT_WF_RMAC_RSVD0 (band),MT_WF_RMAC_RSVD0_EIFS_CLR ); + +/* clear backoff time for Rx duration */ +mt76_clear (dev,MT_WF_RMAC_MIB_AIRTIME1 (band), +MT_WF_RMAC_MIB_NONQOSD_BACKOFF ); +mt76_clear (dev,MT_WF_RMAC_MIB_AIRTIME3 (band), +MT_WF_RMAC_MIB_QOS01_BACKOFF ); +mt76_clear (dev,MT_WF_RMAC_MIB_AIRTIME4 (band), +MT_WF_RMAC_MIB_QOS23_BACKOFF ); + +/* clear backoff time and set software compensation for OBSS time */ + mask =MT_WF_RMAC_MIB_OBSS_BACKOFF |MT_WF_RMAC_MIB_ED_OFFSET ; + set =FIELD_PREP (MT_WF_RMAC_MIB_OBSS_BACKOFF ,0 ) | +FIELD_PREP (MT_WF_RMAC_MIB_ED_OFFSET ,4 ); +mt76_rmw (dev,MT_WF_RMAC_MIB_AIRTIME0 (band), mask, set); +} + +static void mt7996_mac_init (struct mt7996_dev *dev) +{ +#define HIF_TXD_V2_1 4 +int i; + +mt76_clear (dev,MT_MDP_DCR2 ,MT_MDP_DCR2_RX_TRANS_SHORT ); + +for (i =0 ; i <MT7996_WTBL_SIZE ; i++) +mt7996_mac_wtbl_update (dev, i, +MT_WTBL_UPDATE_ADM_COUNT_CLEAR ); + +if (IS_ENABLED (CONFIG_MT76_LEDS )) { + i = dev->mt76.led_pin ?MT_LED_GPIO_MUX3 :MT_LED_GPIO_MUX2 ; +mt76_rmw_field (dev, i,MT_LED_GPIO_SEL_MASK ,4 ); + } + +/* txs report queue */ +mt76_rmw_field (dev,MT_DMA_TCRF1 (0 ),MT_DMA_TCRF1_QIDX ,0 ); +mt76_rmw_field (dev,MT_DMA_TCRF1 (1 ),MT_DMA_TCRF1_QIDX ,6 ); +mt76_rmw_field (dev,MT_DMA_TCRF1 (2 ),MT_DMA_TCRF1_QIDX ,0 ); + +/* rro module init */ +mt7996_mcu_set_rro (dev,UNI_RRO_SET_PLATFORM_TYPE ,2 ); +mt7996_mcu_set_rro (dev,UNI_RRO_SET_BYPASS_MODE ,3 ); +mt7996_mcu_set_rro (dev,UNI_RRO_SET_TXFREE_PATH ,1 ); + +mt7996_mcu_wa_cmd (dev,MCU_WA_PARAM_CMD (SET ), +MCU_WA_PARAM_HW_PATH_HIF_VER , +HIF_TXD_V2_1 ,0 ); + +for (i =MT_BAND0 ; i <=MT_BAND2 ; i++) +mt7996_mac_init_band (dev, i); +} + +static int mt7996_txbf_init (struct mt7996_dev *dev) +{ +int ret; + +if (dev->dbdc_support) { + ret =mt7996_mcu_set_txbf (dev,BF_MOD_EN_CTRL ); +if (ret) +return ret; + } + +/* trigger sounding packets */ + ret =mt7996_mcu_set_txbf (dev,BF_SOUNDING_ON ); +if (ret) +return ret; + +/* enable eBF */ +return mt7996_mcu_set_txbf (dev,BF_HW_EN_UPDATE ); +} + +static int mt7996_register_phy (struct mt7996_dev *dev,struct mt7996_phy *phy, +enum mt76_band_id band) +{ +struct mt76_phy *mphy; +u32 mac_ofs, hif1_ofs =0 ; +int ret; + +if (band !=MT_BAND1 && band !=MT_BAND2 ) +return 0 ; + +if ((band ==MT_BAND1 && !dev->dbdc_support) || + (band ==MT_BAND2 && !dev->tbtc_support)) +return 0 ; + +if (phy) +return 0 ; + +if (band ==MT_BAND2 && dev->hif2) + hif1_ofs =MT_WFDMA0_PCIE1 (0 ) -MT_WFDMA0 (0 ); + + mphy =mt76_alloc_phy (&dev->mt76,sizeof (*phy), &mt7996_ops, band); +if (!mphy) +return -ENOMEM ; + + phy = mphy->priv; + phy->dev = dev; + phy->mt76 = mphy; + mphy->dev->phys[band] = mphy; + +INIT_DELAYED_WORK (&mphy->mac_work, mt7996_mac_work); + + ret =mt7996_eeprom_parse_hw_cap (dev, phy); +if (ret) + goto error; + + mac_ofs = band ==MT_BAND2 ?MT_EE_MAC_ADDR3 :MT_EE_MAC_ADDR2 ; +memcpy (mphy->macaddr, dev->mt76.eeprom.data + mac_ofs,ETH_ALEN ); +/* Make the extra PHY MAC address local without overlapping with +* the usual MAC address allocation scheme on multiple virtual interfaces +*/ +if (!is_valid_ether_addr (mphy->macaddr)) { +memcpy (mphy->macaddr, dev->mt76.eeprom.data +MT_EE_MAC_ADDR , +ETH_ALEN ); + mphy->macaddr[0 ] |=2 ; + mphy->macaddr[0 ] ^=BIT (7 ); +if (band ==MT_BAND2 ) + mphy->macaddr[0 ] ^=BIT (6 ); + } +mt76_eeprom_override (mphy); + +/* init wiphy according to mphy and phy */ +mt7996_init_wiphy (mphy->hw); + ret =mt76_connac_init_tx_queues (phy->mt76, +MT_TXQ_ID (band), +MT7996_TX_RING_SIZE , +MT_TXQ_RING_BASE (band) + hif1_ofs,0 ); +if (ret) + goto error; + + ret =mt76_register_phy (mphy, true, mt76_rates, +ARRAY_SIZE (mt76_rates)); +if (ret) + goto error; + + ret =mt7996_init_debugfs (phy); +if (ret) + goto error; + +return 0 ; + +error: + mphy->dev->phys[band] =NULL ; +ieee80211_free_hw (mphy->hw); +return ret; +} + +static void +mt7996_unregister_phy (struct mt7996_phy *phy,enum mt76_band_id band) +{ +struct mt76_phy *mphy; + +if (!phy) +return ; + + mphy = phy->dev->mt76.phys[band]; +mt76_unregister_phy (mphy); +ieee80211_free_hw (mphy->hw); + phy->dev->mt76.phys[band] =NULL ; +} + +static void mt7996_init_work (struct work_struct *work) +{ + struct mt7996_dev *dev = container_of(work, struct mt7996_dev, + init_work); + +mt7996_mcu_set_eeprom (dev); +mt7996_mac_init (dev); +mt7996_init_txpower (dev, &dev->mphy.sband_2g.sband); +mt7996_init_txpower (dev, &dev->mphy.sband_5g.sband); +mt7996_init_txpower (dev, &dev->mphy.sband_6g.sband); +mt7996_txbf_init (dev); +} + +void mt7996_wfsys_reset (struct mt7996_dev *dev) +{ +mt76_set (dev,MT_WF_SUBSYS_RST ,0x1 ); +msleep (20 ); + +mt76_clear (dev,MT_WF_SUBSYS_RST ,0x1 ); +msleep (20 ); +} + +static int mt7996_init_hardware (struct mt7996_dev *dev) +{ +int ret, idx; + +mt76_wr (dev,MT_INT_SOURCE_CSR , ~0 ); + +INIT_WORK (&dev->init_work, mt7996_init_work); + + dev->dbdc_support = true; + dev->tbtc_support = true; + + ret =mt7996_dma_init (dev); +if (ret) +return ret; + +set_bit (MT76_STATE_INITIALIZED , &dev->mphy.state); + + ret =mt7996_mcu_init (dev); +if (ret) +return ret; + + ret =mt7996_eeprom_init (dev); +if (ret <0 ) +return ret; + +/* Beacon and mgmt frames should occupy wcid 0 */ + idx =mt76_wcid_alloc (dev->mt76.wcid_mask,MT7996_WTBL_STA ); +if (idx) +return -ENOSPC ; + + dev->mt76.global_wcid.idx = idx; + dev->mt76.global_wcid.hw_key_idx =-1 ; + dev->mt76.global_wcid.tx_info |=MT_WCID_TX_INFO_SET ; +rcu_assign_pointer (dev->mt76.wcid[idx], &dev->mt76.global_wcid); + +return 0 ; +} + +void mt7996_set_stream_vht_txbf_caps (struct mt7996_phy *phy) +{ +int sts; +u32 *cap; + +if (!phy->mt76->cap.has_5ghz) +return ; + + sts =hweight16 (phy->mt76->chainmask); + cap = &phy->mt76->sband_5g.sband.vht_cap.cap; + + *cap |=IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | +IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE | + (3 <<IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT ); + + *cap &= ~(IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK | +IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | +IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE ); + +if (sts <2 ) +return ; + + *cap |=IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | +IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE | +FIELD_PREP (IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK , sts -1 ); +} + +static void +mt7996_set_stream_he_txbf_caps (struct mt7996_phy *phy, +struct ieee80211_sta_he_cap *he_cap,int vif) +{ +struct ieee80211_he_cap_elem *elem = &he_cap->he_cap_elem; +int sts =hweight16 (phy->mt76->chainmask); +u8 c; + +#ifdef CONFIG_MAC80211_MESH +if (vif ==NL80211_IFTYPE_MESH_POINT ) +return ; +#endif + + elem->phy_cap_info[3 ] &= ~IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER ; + elem->phy_cap_info[4 ] &= ~IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER ; + + c =IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK | +IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK ; + elem->phy_cap_info[5 ] &= ~c; + + c =IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMING_FB | +IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB ; + elem->phy_cap_info[6 ] &= ~c; + + elem->phy_cap_info[7 ] &= ~IEEE80211_HE_PHY_CAP7_MAX_NC_MASK ; + + c = IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | +IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | +IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO ; + elem->phy_cap_info[2 ] |= c; + + c =IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE | +IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4 | +IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_4 ; + elem->phy_cap_info[4 ] |= c; + +/* do not support NG16 due to spec D4.0 changes subcarrier idx */ + c =IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU | +IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU ; + +if (vif ==NL80211_IFTYPE_STATION ) + c |=IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO ; + + elem->phy_cap_info[6 ] |= c; + +if (sts <2 ) +return ; + +/* the maximum cap is 4 x 3, (Nr, Nc) = (3, 2) */ + elem->phy_cap_info[7 ] |=min_t (int, sts -1 ,2 ) <<3 ; + +if (vif !=NL80211_IFTYPE_AP ) +return ; + + elem->phy_cap_info[3 ] |=IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER ; + elem->phy_cap_info[4 ] |=IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER ; + + c =FIELD_PREP (IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK , + sts -1 ) | +FIELD_PREP (IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK , + sts -1 ); + elem->phy_cap_info[5 ] |= c; + + c =IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMING_FB | +IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB ; + elem->phy_cap_info[6 ] |= c; + + c =IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ | +IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ ; + elem->phy_cap_info[7 ] |= c; +} + +static void +mt7996_gen_ppe_thresh (u8 *he_ppet,int nss) +{ +u8 i, ppet_bits, ppet_size, ru_bit_mask =0x7 ;/* HE80 */ +static const u8 ppet16_ppet8_ru3_ru0[] = {0x1c ,0xc7 ,0x71 }; + + he_ppet[0 ] =FIELD_PREP (IEEE80211_PPE_THRES_NSS_MASK , nss -1 ) | +FIELD_PREP (IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK , + ru_bit_mask); + + ppet_bits =IEEE80211_PPE_THRES_INFO_PPET_SIZE * + nss *hweight8 (ru_bit_mask) *2 ; + ppet_size =DIV_ROUND_UP (ppet_bits,8 ); + +for (i =0 ; i < ppet_size -1 ; i++) + he_ppet[i +1 ] = ppet16_ppet8_ru3_ru0[i %3 ]; + + he_ppet[i +1 ] = ppet16_ppet8_ru3_ru0[i %3 ] & + (0xff >> (8 - (ppet_bits -1 ) %8 )); +} + +static int +mt7996_init_he_caps (struct mt7996_phy *phy,enum nl80211_band band, +struct ieee80211_sband_iftype_data *data) +{ +int i, idx =0 , nss =hweight8 (phy->mt76->antenna_mask); +u16 mcs_map =0 ; + +for (i =0 ; i <8 ; i++) { +if (i < nss) + mcs_map |= (IEEE80211_HE_MCS_SUPPORT_0_11 << (i *2 )); +else + mcs_map |= (IEEE80211_HE_MCS_NOT_SUPPORTED << (i *2 )); + } + +for (i =0 ; i <NUM_NL80211_IFTYPES ; i++) { +struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap; +struct ieee80211_he_cap_elem *he_cap_elem = + &he_cap->he_cap_elem; +struct ieee80211_he_mcs_nss_supp *he_mcs = + &he_cap->he_mcs_nss_supp; + +switch (i) { +case NL80211_IFTYPE_STATION : +case NL80211_IFTYPE_AP : +#ifdef CONFIG_MAC80211_MESH +case NL80211_IFTYPE_MESH_POINT : +#endif +break ; +default : +continue ; + } + + data[idx].types_mask =BIT (i); + he_cap->has_he = true; + + he_cap_elem->mac_cap_info[0 ] = +IEEE80211_HE_MAC_CAP0_HTC_HE ; + he_cap_elem->mac_cap_info[3 ] = +IEEE80211_HE_MAC_CAP3_OMI_CONTROL | +IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3 ; + he_cap_elem->mac_cap_info[4 ] = +IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU ; + +if (band ==NL80211_BAND_2GHZ ) + he_cap_elem->phy_cap_info[0 ] = +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G ; +else + he_cap_elem->phy_cap_info[0 ] = +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G ; + + he_cap_elem->phy_cap_info[1 ] = +IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD ; + he_cap_elem->phy_cap_info[2 ] = +IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | +IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ ; + +switch (i) { +case NL80211_IFTYPE_AP : + he_cap_elem->mac_cap_info[0 ] |= +IEEE80211_HE_MAC_CAP0_TWT_RES ; + he_cap_elem->mac_cap_info[2 ] |= +IEEE80211_HE_MAC_CAP2_BSR ; + he_cap_elem->mac_cap_info[4 ] |= +IEEE80211_HE_MAC_CAP4_BQR ; + he_cap_elem->mac_cap_info[5 ] |= +IEEE80211_HE_MAC_CAP5_OM_CTRL_UL_MU_DATA_DIS_RX ; + he_cap_elem->phy_cap_info[3 ] |= +IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK | +IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK ; + he_cap_elem->phy_cap_info[6 ] |= +IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE | +IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT ; + he_cap_elem->phy_cap_info[9 ] |= +IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU | +IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU ; +break ; +case NL80211_IFTYPE_STATION : + he_cap_elem->mac_cap_info[1 ] |= +IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US ; + +if (band ==NL80211_BAND_2GHZ ) + he_cap_elem->phy_cap_info[0 ] |= +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G ; +else + he_cap_elem->phy_cap_info[0 ] |= +IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G ; + + he_cap_elem->phy_cap_info[1 ] |= +IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | +IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US ; + he_cap_elem->phy_cap_info[3 ] |= +IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK | +IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK ; + he_cap_elem->phy_cap_info[6 ] |= +IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB | +IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE | +IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT ; + he_cap_elem->phy_cap_info[7 ] |= +IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP | +IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI ; + he_cap_elem->phy_cap_info[8 ] |= +IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G | +IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU | +IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU | +IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_484 ; + he_cap_elem->phy_cap_info[9 ] |= +IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM | +IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK | +IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU | +IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU | +IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB | +IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB ; +break ; + } + + he_mcs->rx_mcs_80 =cpu_to_le16 (mcs_map); + he_mcs->tx_mcs_80 =cpu_to_le16 (mcs_map); + he_mcs->rx_mcs_160 =cpu_to_le16 (mcs_map); + he_mcs->tx_mcs_160 =cpu_to_le16 (mcs_map); + he_mcs->rx_mcs_80p80 =cpu_to_le16 (mcs_map); + he_mcs->tx_mcs_80p80 =cpu_to_le16 (mcs_map); + +mt7996_set_stream_he_txbf_caps (phy, he_cap, i); + +memset (he_cap->ppe_thres,0 ,sizeof (he_cap->ppe_thres)); +if (he_cap_elem->phy_cap_info[6 ] & +IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT ) { +mt7996_gen_ppe_thresh (he_cap->ppe_thres, nss); + }else { + he_cap_elem->phy_cap_info[9 ] |= +IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US ; + } + +if (band ==NL80211_BAND_6GHZ ) { +u16 cap =IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS | +IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS ; + + cap |=u16_encode_bits (IEEE80211_HT_MPDU_DENSITY_2 , +IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START ) | +u16_encode_bits (IEEE80211_VHT_MAX_AMPDU_1024K , +IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP ) | +u16_encode_bits (IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 , +IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN ); + + data[idx].he_6ghz_capa.capa =cpu_to_le16 (cap); + } + + idx++; + } + +return idx; +} + +void mt7996_set_stream_he_caps (struct mt7996_phy *phy) +{ +struct ieee80211_sband_iftype_data *data; +struct ieee80211_supported_band *band; +int n; + +if (phy->mt76->cap.has_2ghz) { + data = phy->iftype[NL80211_BAND_2GHZ ]; + n =mt7996_init_he_caps (phy,NL80211_BAND_2GHZ , data); + + band = &phy->mt76->sband_2g.sband; + band->iftype_data = data; + band->n_iftype_data = n; + } + +if (phy->mt76->cap.has_5ghz) { + data = phy->iftype[NL80211_BAND_5GHZ ]; + n =mt7996_init_he_caps (phy,NL80211_BAND_5GHZ , data); + + band = &phy->mt76->sband_5g.sband; + band->iftype_data = data; + band->n_iftype_data = n; + } + +if (phy->mt76->cap.has_6ghz) { + data = phy->iftype[NL80211_BAND_6GHZ ]; + n =mt7996_init_he_caps (phy,NL80211_BAND_6GHZ , data); + + band = &phy->mt76->sband_6g.sband; + band->iftype_data = data; + band->n_iftype_data = n; + } +} + +int mt7996_register_device (struct mt7996_dev *dev) +{ +struct ieee80211_hw *hw =mt76_hw (dev); +int ret; + + dev->phy.dev = dev; + dev->phy.mt76 = &dev->mt76.phy; + dev->mt76.phy.priv = &dev->phy; +INIT_WORK (&dev->rc_work, mt7996_mac_sta_rc_work); +INIT_DELAYED_WORK (&dev->mphy.mac_work, mt7996_mac_work); +INIT_LIST_HEAD (&dev->sta_rc_list); +INIT_LIST_HEAD (&dev->sta_poll_list); +INIT_LIST_HEAD (&dev->twt_list); +spin_lock_init (&dev->sta_poll_lock); + +init_waitqueue_head (&dev->reset_wait); +INIT_WORK (&dev->reset_work, mt7996_mac_reset_work); + + ret =mt7996_init_hardware (dev); +if (ret) +return ret; + +mt7996_init_wiphy (hw); + +/* init led callbacks */ +if (IS_ENABLED (CONFIG_MT76_LEDS )) { + dev->mt76.led_cdev.brightness_set = mt7996_led_set_brightness; + dev->mt76.led_cdev.blink_set = mt7996_led_set_blink; + } + + ret =mt76_register_device (&dev->mt76, true, mt76_rates, +ARRAY_SIZE (mt76_rates)); +if (ret) +return ret; + +ieee80211_queue_work (mt76_hw (dev), &dev->init_work); + + ret =mt7996_register_phy (dev,mt7996_phy2 (dev),MT_BAND1 ); +if (ret) +return ret; + + ret =mt7996_register_phy (dev,mt7996_phy3 (dev),MT_BAND2 ); +if (ret) +return ret; + +return mt7996_init_debugfs (&dev->phy); +} + +void mt7996_unregister_device (struct mt7996_dev *dev) +{ +mt7996_unregister_phy (mt7996_phy3 (dev),MT_BAND2 ); +mt7996_unregister_phy (mt7996_phy2 (dev),MT_BAND1 ); +mt76_unregister_device (&dev->mt76); +mt7996_mcu_exit (dev); +mt7996_tx_token_put (dev); +mt7996_dma_cleanup (dev); +tasklet_disable (&dev->irq_tasklet); + +mt76_free_device (&dev->mt76); +}
drivers/net/wireless/mediatek/mt76/mt7996/mac.c new file +2468 -0
2,184 lines not on this page · raw message
drivers/net/wireless/mediatek/mt76/mt7996/mac.h new file +398 -0
398 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.25.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH 5/9] wifi: mt76: mt7996: add MAC support
Quoted 4 lines · Shayne Chen
(Split the big patch into smaller intermediate patches by functionality for easier review. Refer to the cover letter for more info.)
Signed-off-by Shayne Chen <[email protected]>
[...]
Quoted 12 lines
drivers/net/wireless/mediatek/mt76/mt7996/mac.c new file +12
-0+static void mt7996_mac_sta_poll (struct mt7996_dev *dev) +{ +static const u8 ac_to_tid[] = { + [IEEE80211_AC_BE ] =0 , + [IEEE80211_AC_BK ] =1 , + [IEEE80211_AC_VI ] =4 , + [IEEE80211_AC_VO ] =6 + }; +struct ieee80211_sta *sta; +struct mt7996_sta *msta; +struct rate_info *rate; +u32 tx_time[IEEE80211_NUM_ACS ], rx_time[IEEE80211_NUM_ACS ];
drivers/net/wireless/mediatek/mt76/mt7996/mac.c line 123
Quoted 10 lines
drivers/net/wireless/mediatek/mt76/mt7996/mac.c new file +10
-0+LIST_HEAD (sta_poll_list); +int i; + +spin_lock_bh (&dev->sta_poll_lock); +list_splice_init (&dev->sta_poll_list, &sta_poll_list); +spin_unlock_bh (&dev->sta_poll_lock); + +rcu_read_lock (); + +while (true) {
In upstream we have a preference that there's some kind of limit for loops, to avoid neverending loops.
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Felix Fietkau
maintainerRe: [PATCH 5/9] wifi: mt76: mt7996: add MAC support
Quoted 26 lines · Kalle Valo
Quoted 4 lines · Shayne Chen
(Split the big patch into smaller intermediate patches by functionality for easier review. Refer to the cover letter for more info.)
Signed-off-by Shayne Chen <[email protected]>[...]
Quoted 17 lines
drivers/net/wireless/mediatek/mt76/mt7996/mac.c new file +17
-0+static void mt7996_mac_sta_poll (struct mt7996_dev *dev) +{ +static const u8 ac_to_tid[] = { + [IEEE80211_AC_BE ] =0 , + [IEEE80211_AC_BK ] =1 , + [IEEE80211_AC_VI ] =4 , + [IEEE80211_AC_VO ] =6 + }; +struct ieee80211_sta *sta; +struct mt7996_sta *msta; +struct rate_info *rate; +u32 tx_time[IEEE80211_NUM_ACS ], rx_time[IEEE80211_NUM_ACS ]; +LIST_HEAD (sta_poll_list); +int i; + +spin_lock_bh (&dev->sta_poll_lock); +list_splice_init (&dev->sta_poll_list, &sta_poll_list);
Quoted 8 lines
drivers/net/wireless/mediatek/mt76/mt7996/mac.c line 123
Quoted 5 lines
drivers/net/wireless/mediatek/mt76/mt7996/mac.c new file +5
-0+spin_unlock_bh (&dev->sta_poll_lock); + +rcu_read_lock (); + +while (true) {In upstream we have a preference that there's some kind of limit for loops, to avoid neverending loops.
This loop pulls entries from the on-stack sta_poll_list and bails out when the list is empty, so it's impossible for it to be neverending.
- Felix
Shayne Chen
reviewerPATCH 6/9 wifi: mt76: mt7996: add ieee80211_ops
In reply to Shayne Chen(Split the big patch into smaller intermediate patches by functionality for easier review. Refer to the cover letter for more info.)
--- .../net/wireless/mediatek/mt76/mt7996/main.c | 1325 +++++++++++++++++ 1 file changed, 1325 insertions(+) create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/main.c
drivers/net/wireless/mediatek/mt76/mt7996/main.c new file +1325 -0
@@ -0,0 +1,1325 @@ +// SPDX-License-Identifier: ISC +/* +* Copyright (C) 2022 MediaTek Inc. +*/ + +#include "mt7996.h" +#include "mcu.h" + +static bool mt7996_dev_running (struct mt7996_dev *dev) +{ +struct mt7996_phy *phy; + +if (test_bit (MT76_STATE_RUNNING , &dev->mphy.state)) +return true; + + phy =mt7996_phy2 (dev); +if (phy &&test_bit (MT76_STATE_RUNNING , &phy->mt76->state)) +return true; + + phy =mt7996_phy3 (dev); + +return phy &&test_bit (MT76_STATE_RUNNING , &phy->mt76->state); +} + +static int mt7996_start (struct ieee80211_hw *hw) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +bool running; +int ret; + +flush_work (&dev->init_work); + +mutex_lock (&dev->mt76.mutex); + + running =mt7996_dev_running (dev); +if (!running) { + ret =mt7996_mcu_set_hdr_trans (dev, true); +if (ret) + goto out; + } + +mt7996_mac_enable_nf (dev, phy->mt76->band_idx); + + ret =mt7996_mcu_set_rts_thresh (phy,0x92b ); +if (ret) + goto out; + + ret =mt7996_mcu_set_chan_info (phy,UNI_CHANNEL_RX_PATH ); +if (ret) + goto out; + +set_bit (MT76_STATE_RUNNING , &phy->mt76->state); + +ieee80211_iterate_interfaces (dev->mt76.hw, +IEEE80211_IFACE_ITER_RESUME_ALL , + mt7996_mcu_set_pm, dev->mt76.hw); + +ieee80211_queue_delayed_work (hw, &phy->mt76->mac_work, +MT7996_WATCHDOG_TIME ); + +if (!running) +mt7996_mac_reset_counters (phy); + +out: +mutex_unlock (&dev->mt76.mutex); + +return ret; +} + +static void mt7996_stop (struct ieee80211_hw *hw) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); + +cancel_delayed_work_sync (&phy->mt76->mac_work); + +mutex_lock (&dev->mt76.mutex); + +clear_bit (MT76_STATE_RUNNING , &phy->mt76->state); + +ieee80211_iterate_interfaces (dev->mt76.hw, +IEEE80211_IFACE_ITER_RESUME_ALL , + mt7996_mcu_set_pm, dev->mt76.hw); + +mutex_unlock (&dev->mt76.mutex); +} + +static inline int get_free_idx (u32 mask,u8 start,u8 end) +{ +return ffs (~mask &GENMASK (end, start)); +} + +static int get_omac_idx (enum nl80211_iftype type,u64 mask) +{ +int i; + +switch (type) { +case NL80211_IFTYPE_MESH_POINT : +case NL80211_IFTYPE_ADHOC : +case NL80211_IFTYPE_STATION : +/* prefer hw bssid slot 1-3 */ + i =get_free_idx (mask,HW_BSSID_1 ,HW_BSSID_3 ); +if (i) +return i -1 ; + +if (type !=NL80211_IFTYPE_STATION ) +break ; + + i =get_free_idx (mask,EXT_BSSID_1 ,EXT_BSSID_MAX ); +if (i) +return i -1 ; + +if (~mask &BIT (HW_BSSID_0 )) +return HW_BSSID_0 ; + +break ; +case NL80211_IFTYPE_MONITOR : +case NL80211_IFTYPE_AP : +/* ap uses hw bssid 0 and ext bssid */ +if (~mask &BIT (HW_BSSID_0 )) +return HW_BSSID_0 ; + + i =get_free_idx (mask,EXT_BSSID_1 ,EXT_BSSID_MAX ); +if (i) +return i -1 ; + +break ; +default : +WARN_ON (1 ); +break ; + } + +return -1 ; +} + +static void mt7996_init_bitrate_mask (struct ieee80211_vif *vif) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +int i; + +for (i =0 ; i <ARRAY_SIZE (mvif->bitrate_mask.control); i++) { + mvif->bitrate_mask.control[i].gi =NL80211_TXRATE_DEFAULT_GI ; + mvif->bitrate_mask.control[i].he_gi =0xff ; + mvif->bitrate_mask.control[i].he_ltf =0xff ; + mvif->bitrate_mask.control[i].legacy =GENMASK (31 ,0 ); +memset (mvif->bitrate_mask.control[i].ht_mcs,0xff , +sizeof (mvif->bitrate_mask.control[i].ht_mcs)); +memset (mvif->bitrate_mask.control[i].vht_mcs,0xff , +sizeof (mvif->bitrate_mask.control[i].vht_mcs)); +memset (mvif->bitrate_mask.control[i].he_mcs,0xff , +sizeof (mvif->bitrate_mask.control[i].he_mcs)); + } +} + +static int mt7996_add_interface (struct ieee80211_hw *hw, +struct ieee80211_vif *vif) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +struct mt76_txq *mtxq; +u8 band_idx = phy->mt76->band_idx; +int idx, ret =0 ; + +mutex_lock (&dev->mt76.mutex); + +if (vif->type ==NL80211_IFTYPE_MONITOR && +is_zero_ether_addr (vif->addr)) + phy->monitor_vif = vif; + + mvif->mt76.idx =__ffs64 (~dev->mt76.vif_mask); +if (mvif->mt76.idx >= (MT7996_MAX_INTERFACES << dev->dbdc_support)) { + ret = -ENOSPC ; + goto out; + } + + idx =get_omac_idx (vif->type, phy->omac_mask); +if (idx <0 ) { + ret = -ENOSPC ; + goto out; + } + mvif->mt76.omac_idx = idx; + mvif->phy = phy; + mvif->mt76.band_idx = band_idx; + mvif->mt76.wmm_idx = band_idx; + + ret =mt7996_mcu_add_dev_info (phy, vif, true); +if (ret) + goto out; + + ret =mt7996_mcu_set_radio_en (phy, true); +if (ret) + goto out; + + dev->mt76.vif_mask |=BIT_ULL (mvif->mt76.idx); + phy->omac_mask |=BIT_ULL (mvif->mt76.omac_idx); + + idx =MT7996_WTBL_RESERVED - mvif->mt76.idx; + +INIT_LIST_HEAD (&mvif->sta.rc_list); +INIT_LIST_HEAD (&mvif->sta.poll_list); + mvif->sta.wcid.idx = idx; + mvif->sta.wcid.phy_idx = band_idx; + mvif->sta.wcid.hw_key_idx =-1 ; + mvif->sta.wcid.tx_info |=MT_WCID_TX_INFO_SET ; +mt76_packet_id_init (&mvif->sta.wcid); + +mt7996_mac_wtbl_update (dev, idx, +MT_WTBL_UPDATE_ADM_COUNT_CLEAR ); + +if (vif->txq) { + mtxq = (struct mt76_txq *)vif->txq->drv_priv; + mtxq->wcid = idx; + } + +if (vif->type !=NL80211_IFTYPE_AP && + (!mvif->mt76.omac_idx || mvif->mt76.omac_idx >3 )) + vif->offload_flags =0 ; + vif->offload_flags |=IEEE80211_OFFLOAD_ENCAP_4ADDR ; + +mt7996_init_bitrate_mask (vif); +memset (&mvif->cap,-1 ,sizeof (mvif->cap)); + +mt7996_mcu_add_bss_info (phy, vif, true); +mt7996_mcu_add_sta (dev, vif,NULL , true); +rcu_assign_pointer (dev->mt76.wcid[idx], &mvif->sta.wcid); + +out: +mutex_unlock (&dev->mt76.mutex); + +return ret; +} + +static void mt7996_remove_interface (struct ieee80211_hw *hw, +struct ieee80211_vif *vif) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_sta *msta = &mvif->sta; +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +int idx = msta->wcid.idx; + +mt7996_mcu_add_bss_info (phy, vif, false); +mt7996_mcu_add_sta (dev, vif,NULL , false); + +if (vif == phy->monitor_vif) + phy->monitor_vif =NULL ; + +mt7996_mcu_add_dev_info (phy, vif, false); +mt7996_mcu_set_radio_en (phy, false); + +rcu_assign_pointer (dev->mt76.wcid[idx],NULL ); + +mutex_lock (&dev->mt76.mutex); + dev->mt76.vif_mask &= ~BIT_ULL (mvif->mt76.idx); + phy->omac_mask &= ~BIT_ULL (mvif->mt76.omac_idx); +mutex_unlock (&dev->mt76.mutex); + +spin_lock_bh (&dev->sta_poll_lock); +if (!list_empty (&msta->poll_list)) +list_del_init (&msta->poll_list); +spin_unlock_bh (&dev->sta_poll_lock); + +mt76_packet_id_flush (&dev->mt76, &msta->wcid); +} + +int mt7996_set_channel (struct mt7996_phy *phy) +{ +struct mt7996_dev *dev = phy->dev; +int ret; + +cancel_delayed_work_sync (&phy->mt76->mac_work); + +mutex_lock (&dev->mt76.mutex); +set_bit (MT76_RESET , &phy->mt76->state); + +mt76_set_channel (phy->mt76); + + ret =mt7996_mcu_set_chan_info (phy,UNI_CHANNEL_SWITCH ); +if (ret) + goto out; + +mt7996_mac_set_timing (phy); + ret =mt7996_dfs_init_radar_detector (phy); +mt7996_mac_cca_stats_reset (phy); + +mt7996_mac_reset_counters (phy); + phy->noise =0 ; + +out: +clear_bit (MT76_RESET , &phy->mt76->state); +mutex_unlock (&dev->mt76.mutex); + +mt76_txq_schedule_all (phy->mt76); + +ieee80211_queue_delayed_work (phy->mt76->hw, + &phy->mt76->mac_work, +MT7996_WATCHDOG_TIME ); + +return ret; +} + +static int mt7996_set_key (struct ieee80211_hw *hw,enum set_key_cmd cmd, +struct ieee80211_vif *vif,struct ieee80211_sta *sta, +struct ieee80211_key_conf *key) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_sta *msta = sta ? (struct mt7996_sta *)sta->drv_priv : + &mvif->sta; +struct mt76_wcid *wcid = &msta->wcid; +u8 *wcid_keyidx = &wcid->hw_key_idx; +int idx = key->keyidx; +int err =0 ; + +/* The hardware does not support per-STA RX GTK, fallback +* to software mode for these. +*/ +if ((vif->type ==NL80211_IFTYPE_ADHOC || + vif->type ==NL80211_IFTYPE_MESH_POINT ) && + (key->cipher ==WLAN_CIPHER_SUITE_TKIP || + key->cipher ==WLAN_CIPHER_SUITE_CCMP ) && + !(key->flags &IEEE80211_KEY_FLAG_PAIRWISE )) +return -EOPNOTSUPP ; + +/* fall back to sw encryption for unsupported ciphers */ +switch (key->cipher) { +case WLAN_CIPHER_SUITE_AES_CMAC : + wcid_keyidx = &wcid->hw_key_idx2; + key->flags |=IEEE80211_KEY_FLAG_GENERATE_MMIE ; +break ; +case WLAN_CIPHER_SUITE_TKIP : +case WLAN_CIPHER_SUITE_CCMP : +case WLAN_CIPHER_SUITE_CCMP_256 : +case WLAN_CIPHER_SUITE_GCMP : +case WLAN_CIPHER_SUITE_GCMP_256 : +case WLAN_CIPHER_SUITE_SMS4 : +break ; +case WLAN_CIPHER_SUITE_WEP40 : +case WLAN_CIPHER_SUITE_WEP104 : +default : +return -EOPNOTSUPP ; + } + +mutex_lock (&dev->mt76.mutex); + +if (cmd ==SET_KEY && !sta && !mvif->mt76.cipher) { + mvif->mt76.cipher =mt76_connac_mcu_get_cipher (key->cipher); +mt7996_mcu_add_bss_info (phy, vif, true); + } + +if (cmd ==SET_KEY ) + *wcid_keyidx = idx; +else if (idx == *wcid_keyidx) + *wcid_keyidx =-1 ; +else + goto out; + +mt76_wcid_key_setup (&dev->mt76, wcid, + cmd ==SET_KEY ? key :NULL ); + + err =mt7996_mcu_add_key (&dev->mt76, vif, &msta->bip, + key,MCU_WMWA_UNI_CMD (STA_REC_UPDATE ), + &msta->wcid, cmd); +out: +mutex_unlock (&dev->mt76.mutex); + +return err; +} + +static int mt7996_config (struct ieee80211_hw *hw,u32 changed) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +int ret; + +if (changed &IEEE80211_CONF_CHANGE_CHANNEL ) { +ieee80211_stop_queues (hw); + ret =mt7996_set_channel (phy); +if (ret) +return ret; +ieee80211_wake_queues (hw); + } + +mutex_lock (&dev->mt76.mutex); + +if (changed &IEEE80211_CONF_CHANGE_MONITOR ) { +bool enabled = !!(hw->conf.flags &IEEE80211_CONF_MONITOR ); + +if (!enabled) + phy->rxfilter |=MT_WF_RFCR_DROP_OTHER_UC ; +else + phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_UC ; + +mt76_rmw_field (dev,MT_DMA_DCR0 (phy->mt76->band_idx), +MT_DMA_DCR0_RXD_G5_EN , enabled); +mt76_wr (dev,MT_WF_RFCR (phy->mt76->band_idx), phy->rxfilter); + } + +mutex_unlock (&dev->mt76.mutex); + +return 0 ; +} + +static int +mt7996_conf_tx (struct ieee80211_hw *hw,struct ieee80211_vif *vif, +unsigned int link_id,u16 queue, +const struct ieee80211_tx_queue_params *params) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; + +/* no need to update right away, we'll get BSS_CHANGED_QOS */ + queue =mt76_connac_lmac_mapping (queue); + mvif->queue_params[queue] = *params; + +return 0 ; +} + +static void mt7996_configure_filter (struct ieee80211_hw *hw, +unsigned int changed_flags, +unsigned int *total_flags, +u64 multicast) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +u32 ctl_flags =MT_WF_RFCR1_DROP_ACK | +MT_WF_RFCR1_DROP_BF_POLL | +MT_WF_RFCR1_DROP_BA | +MT_WF_RFCR1_DROP_CFEND | +MT_WF_RFCR1_DROP_CFACK ; +u32 flags =0 ; + +#define MT76_FILTER (_flag, _hw) do { \ + flags |= *total_flags & FIF_##_flag; \ + phy->rxfilter &= ~(_hw); \ + phy->rxfilter |= !(flags & FIF_##_flag) * (_hw); \ + } while (0) + +mutex_lock (&dev->mt76.mutex); + + phy->rxfilter &= ~(MT_WF_RFCR_DROP_OTHER_BSS | +MT_WF_RFCR_DROP_OTHER_BEACON | +MT_WF_RFCR_DROP_FRAME_REPORT | +MT_WF_RFCR_DROP_PROBEREQ | +MT_WF_RFCR_DROP_MCAST_FILTERED | +MT_WF_RFCR_DROP_MCAST | +MT_WF_RFCR_DROP_BCAST | +MT_WF_RFCR_DROP_DUPLICATE | +MT_WF_RFCR_DROP_A2_BSSID | +MT_WF_RFCR_DROP_UNWANTED_CTL | +MT_WF_RFCR_DROP_STBC_MULTI ); + +MT76_FILTER (OTHER_BSS ,MT_WF_RFCR_DROP_OTHER_TIM | +MT_WF_RFCR_DROP_A3_MAC | +MT_WF_RFCR_DROP_A3_BSSID ); + +MT76_FILTER (FCSFAIL ,MT_WF_RFCR_DROP_FCSFAIL ); + +MT76_FILTER (CONTROL ,MT_WF_RFCR_DROP_CTS | +MT_WF_RFCR_DROP_RTS | +MT_WF_RFCR_DROP_CTL_RSV | +MT_WF_RFCR_DROP_NDPA ); + + *total_flags = flags; +mt76_wr (dev,MT_WF_RFCR (phy->mt76->band_idx), phy->rxfilter); + +if (*total_flags &FIF_CONTROL ) +mt76_clear (dev,MT_WF_RFCR1 (phy->mt76->band_idx), ctl_flags); +else +mt76_set (dev,MT_WF_RFCR1 (phy->mt76->band_idx), ctl_flags); + +mutex_unlock (&dev->mt76.mutex); +} + +static void +mt7996_update_bss_color (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct cfg80211_he_bss_color *bss_color) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); + +switch (vif->type) { +case NL80211_IFTYPE_AP : { +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; + +if (mvif->mt76.omac_idx >HW_BSSID_MAX ) +return ; + fallthrough; + } +case NL80211_IFTYPE_STATION : +mt7996_mcu_update_bss_color (dev, vif, bss_color); +break ; +default : +break ; + } +} + +static void mt7996_bss_info_changed (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_bss_conf *info, +u64 changed) +{ +struct mt7996_phy *phy =mt7996_hw_phy (hw); +struct mt7996_dev *dev =mt7996_hw_dev (hw); + +mutex_lock (&dev->mt76.mutex); + +/* station mode uses BSSID to map the wlan entry to a peer, +* and then peer references bss_info_rfch to set bandwidth cap. +*/ +if (changed &BSS_CHANGED_BSSID && + vif->type ==NL80211_IFTYPE_STATION ) { +bool join = !is_zero_ether_addr (info->bssid); + +mt7996_mcu_add_bss_info (phy, vif, join); +mt7996_mcu_add_sta (dev, vif,NULL , join); + } + +if (changed &BSS_CHANGED_ASSOC ) { +mt7996_mcu_add_bss_info (phy, vif, vif->cfg.assoc); +mt7996_mcu_add_obss_spr (dev, vif, info->he_obss_pd.enable); + } + +if (changed &BSS_CHANGED_ERP_SLOT ) { +int slottime = info->use_short_slot ?9 :20 ; + +if (slottime != phy->slottime) { + phy->slottime = slottime; +mt7996_mac_set_timing (phy); + } + } + +if (changed &BSS_CHANGED_BEACON_ENABLED && info->enable_beacon) { +mt7996_mcu_add_bss_info (phy, vif, true); +mt7996_mcu_add_sta (dev, vif,NULL , true); + } + +/* ensure that enable txcmd_mode after bss_info */ +if (changed & (BSS_CHANGED_QOS |BSS_CHANGED_BEACON_ENABLED )) +mt7996_mcu_set_tx (dev, vif); + +if (changed &BSS_CHANGED_HE_OBSS_PD ) +mt7996_mcu_add_obss_spr (dev, vif, info->he_obss_pd.enable); + +if (changed &BSS_CHANGED_HE_BSS_COLOR ) +mt7996_update_bss_color (hw, vif, &info->he_bss_color); + +if (changed & (BSS_CHANGED_BEACON | +BSS_CHANGED_BEACON_ENABLED )) +mt7996_mcu_add_beacon (hw, vif, info->enable_beacon); + +if (changed &BSS_CHANGED_UNSOL_BCAST_PROBE_RESP || + changed &BSS_CHANGED_FILS_DISCOVERY ) +mt7996_mcu_beacon_inband_discov (dev, vif, changed); + +mutex_unlock (&dev->mt76.mutex); +} + +static void +mt7996_channel_switch_beacon (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct cfg80211_chan_def *chandef) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); + +mutex_lock (&dev->mt76.mutex); +mt7996_mcu_add_beacon (hw, vif, true); +mutex_unlock (&dev->mt76.mutex); +} + +int mt7996_mac_sta_add (struct mt76_dev *mdev,struct ieee80211_vif *vif, +struct ieee80211_sta *sta) +{ + struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76); +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +u8 band_idx = mvif->phy->mt76->band_idx; +int ret, idx; + + idx =mt76_wcid_alloc (dev->mt76.wcid_mask,MT7996_WTBL_STA ); +if (idx <0 ) +return -ENOSPC ; + +INIT_LIST_HEAD (&msta->rc_list); +INIT_LIST_HEAD (&msta->poll_list); + msta->vif = mvif; + msta->wcid.sta =1 ; + msta->wcid.idx = idx; + msta->wcid.phy_idx = band_idx; + msta->wcid.tx_info |=MT_WCID_TX_INFO_SET ; + msta->jiffies = jiffies; + +mt7996_mac_wtbl_update (dev, idx, +MT_WTBL_UPDATE_ADM_COUNT_CLEAR ); + + ret =mt7996_mcu_add_sta (dev, vif, sta, true); +if (ret) +return ret; + +return mt7996_mcu_add_rate_ctrl (dev, vif, sta, false); +} + +void mt7996_mac_sta_remove (struct mt76_dev *mdev,struct ieee80211_vif *vif, +struct ieee80211_sta *sta) +{ + struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76); +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; +int i; + +mt7996_mcu_add_sta (dev, vif, sta, false); + +mt7996_mac_wtbl_update (dev, msta->wcid.idx, +MT_WTBL_UPDATE_ADM_COUNT_CLEAR ); + +for (i =0 ; i <ARRAY_SIZE (msta->twt.flow); i++) +mt7996_mac_twt_teardown_flow (dev, msta, i); + +spin_lock_bh (&dev->sta_poll_lock); +if (!list_empty (&msta->poll_list)) +list_del_init (&msta->poll_list); +if (!list_empty (&msta->rc_list)) +list_del_init (&msta->rc_list); +spin_unlock_bh (&dev->sta_poll_lock); +} + +static void mt7996_tx (struct ieee80211_hw *hw, +struct ieee80211_tx_control *control, +struct sk_buff *skb) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt76_phy *mphy = hw->priv; +struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb); +struct ieee80211_vif *vif = info->control.vif; +struct mt76_wcid *wcid = &dev->mt76.global_wcid; + +if (control->sta) { +struct mt7996_sta *sta; + + sta = (struct mt7996_sta *)control->sta->drv_priv; + wcid = &sta->wcid; + } + +if (vif && !control->sta) { +struct mt7996_vif *mvif; + + mvif = (struct mt7996_vif *)vif->drv_priv; + wcid = &mvif->sta.wcid; + } + +mt76_tx (mphy, control->sta, wcid, skb); +} + +static int mt7996_set_rts_threshold (struct ieee80211_hw *hw,u32 val) +{ +struct mt7996_phy *phy =mt7996_hw_phy (hw); +int ret; + +mutex_lock (&phy->dev->mt76.mutex); + ret =mt7996_mcu_set_rts_thresh (phy, val); +mutex_unlock (&phy->dev->mt76.mutex); + +return ret; +} + +static int +mt7996_ampdu_action (struct ieee80211_hw *hw,struct ieee80211_vif *vif, +struct ieee80211_ampdu_params *params) +{ +enum ieee80211_ampdu_mlme_action action = params->action; +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct ieee80211_sta *sta = params->sta; +struct ieee80211_txq *txq = sta->txq[params->tid]; +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; +u16 tid = params->tid; +u16 ssn = params->ssn; +struct mt76_txq *mtxq; +int ret =0 ; + +if (!txq) +return -EINVAL ; + + mtxq = (struct mt76_txq *)txq->drv_priv; + +mutex_lock (&dev->mt76.mutex); +switch (action) { +case IEEE80211_AMPDU_RX_START : +mt76_rx_aggr_start (&dev->mt76, &msta->wcid, tid, ssn, + params->buf_size); + ret =mt7996_mcu_add_rx_ba (dev, params, true); +break ; +case IEEE80211_AMPDU_RX_STOP : +mt76_rx_aggr_stop (&dev->mt76, &msta->wcid, tid); + ret =mt7996_mcu_add_rx_ba (dev, params, false); +break ; +case IEEE80211_AMPDU_TX_OPERATIONAL : + mtxq->aggr = true; + mtxq->send_bar = false; + ret =mt7996_mcu_add_tx_ba (dev, params, true); +break ; +case IEEE80211_AMPDU_TX_STOP_FLUSH : +case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT : + mtxq->aggr = false; +clear_bit (tid, &msta->ampdu_state); + ret =mt7996_mcu_add_tx_ba (dev, params, false); +break ; +case IEEE80211_AMPDU_TX_START : +set_bit (tid, &msta->ampdu_state); + ret =IEEE80211_AMPDU_TX_START_IMMEDIATE ; +break ; +case IEEE80211_AMPDU_TX_STOP_CONT : + mtxq->aggr = false; +clear_bit (tid, &msta->ampdu_state); + ret =mt7996_mcu_add_tx_ba (dev, params, false); +ieee80211_stop_tx_ba_cb_irqsafe (vif, sta->addr, tid); +break ; + } +mutex_unlock (&dev->mt76.mutex); + +return ret; +} + +static int +mt7996_sta_add (struct ieee80211_hw *hw,struct ieee80211_vif *vif, +struct ieee80211_sta *sta) +{ +return mt76_sta_state (hw, vif, sta,IEEE80211_STA_NOTEXIST , +IEEE80211_STA_NONE ); +} + +static int +mt7996_sta_remove (struct ieee80211_hw *hw,struct ieee80211_vif *vif, +struct ieee80211_sta *sta) +{ +return mt76_sta_state (hw, vif, sta,IEEE80211_STA_NONE , +IEEE80211_STA_NOTEXIST ); +} + +static int +mt7996_get_stats (struct ieee80211_hw *hw, +struct ieee80211_low_level_stats *stats) +{ +struct mt7996_phy *phy =mt7996_hw_phy (hw); +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mib_stats *mib = &phy->mib; + +mutex_lock (&dev->mt76.mutex); + + stats->dot11RTSSuccessCount = mib->rts_cnt; + stats->dot11RTSFailureCount = mib->rts_retries_cnt; + stats->dot11FCSErrorCount = mib->fcs_err_cnt; + stats->dot11ACKFailureCount = mib->ack_fail_cnt; + +mutex_unlock (&dev->mt76.mutex); + +return 0 ; +} + +u64 __mt7996_get_tsf (struct ieee80211_hw *hw,struct mt7996_vif *mvif) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +union { +u64 t64; +u32 t32[2 ]; + } tsf; +u16 n; + +lockdep_assert_held (&dev->mt76.mutex); + + n = mvif->mt76.omac_idx >HW_BSSID_MAX ?HW_BSSID_0 + : mvif->mt76.omac_idx; +/* TSF software read */ +mt76_rmw (dev,MT_LPON_TCR (phy->mt76->band_idx, n),MT_LPON_TCR_SW_MODE , +MT_LPON_TCR_SW_READ ); + tsf.t32[0 ] =mt76_rr (dev,MT_LPON_UTTR0 (phy->mt76->band_idx)); + tsf.t32[1 ] =mt76_rr (dev,MT_LPON_UTTR1 (phy->mt76->band_idx)); + +return tsf.t64; +} + +static u64 +mt7996_get_tsf (struct ieee80211_hw *hw,struct ieee80211_vif *vif) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_dev *dev =mt7996_hw_dev (hw); +u64 ret; + +mutex_lock (&dev->mt76.mutex); + ret =__mt7996_get_tsf (hw, mvif); +mutex_unlock (&dev->mt76.mutex); + +return ret; +} + +static void +mt7996_set_tsf (struct ieee80211_hw *hw,struct ieee80211_vif *vif, +u64 timestamp) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +union { +u64 t64; +u32 t32[2 ]; + } tsf = { .t64 = timestamp, }; +u16 n; + +mutex_lock (&dev->mt76.mutex); + + n = mvif->mt76.omac_idx >HW_BSSID_MAX ?HW_BSSID_0 + : mvif->mt76.omac_idx; +mt76_wr (dev,MT_LPON_UTTR0 (phy->mt76->band_idx), tsf.t32[0 ]); +mt76_wr (dev,MT_LPON_UTTR1 (phy->mt76->band_idx), tsf.t32[1 ]); +/* TSF software overwrite */ +mt76_rmw (dev,MT_LPON_TCR (phy->mt76->band_idx, n),MT_LPON_TCR_SW_MODE , +MT_LPON_TCR_SW_WRITE ); + +mutex_unlock (&dev->mt76.mutex); +} + +static void +mt7996_offset_tsf (struct ieee80211_hw *hw,struct ieee80211_vif *vif, +s64 timestamp) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +union { +u64 t64; +u32 t32[2 ]; + } tsf = { .t64 = timestamp, }; +u16 n; + +mutex_lock (&dev->mt76.mutex); + + n = mvif->mt76.omac_idx >HW_BSSID_MAX ?HW_BSSID_0 + : mvif->mt76.omac_idx; +mt76_wr (dev,MT_LPON_UTTR0 (phy->mt76->band_idx), tsf.t32[0 ]); +mt76_wr (dev,MT_LPON_UTTR1 (phy->mt76->band_idx), tsf.t32[1 ]); +/* TSF software adjust*/ +mt76_rmw (dev,MT_LPON_TCR (phy->mt76->band_idx, n),MT_LPON_TCR_SW_MODE , +MT_LPON_TCR_SW_ADJUST ); + +mutex_unlock (&dev->mt76.mutex); +} + +static void +mt7996_set_coverage_class (struct ieee80211_hw *hw,s16 coverage_class) +{ +struct mt7996_phy *phy =mt7996_hw_phy (hw); +struct mt7996_dev *dev = phy->dev; + +mutex_lock (&dev->mt76.mutex); + phy->coverage_class =max_t (s16, coverage_class,0 ); +mt7996_mac_set_timing (phy); +mutex_unlock (&dev->mt76.mutex); +} + +static int +mt7996_set_antenna (struct ieee80211_hw *hw,u32 tx_ant,u32 rx_ant) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +int max_nss =hweight8 (hw->wiphy->available_antennas_tx); +u8 band_idx = phy->mt76->band_idx, shift = dev->chainshift[band_idx]; + +if (!tx_ant || tx_ant != rx_ant ||ffs (tx_ant) > max_nss) +return -EINVAL ; + +if ((BIT (hweight8 (tx_ant)) -1 ) != tx_ant) + tx_ant =BIT (ffs (tx_ant) -1 ) -1 ; + +mutex_lock (&dev->mt76.mutex); + + phy->mt76->antenna_mask = tx_ant; + +/* restore to the origin chainmask which might have auxiliary path */ +if (hweight8 (tx_ant) == max_nss) + phy->mt76->chainmask = (dev->chainmask >> shift) << shift; +else + phy->mt76->chainmask = tx_ant << shift; + +mt76_set_stream_caps (phy->mt76, true); +mt7996_set_stream_vht_txbf_caps (phy); +mt7996_set_stream_he_caps (phy); + +mutex_unlock (&dev->mt76.mutex); + +return 0 ; +} + +static void mt7996_sta_statistics (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct station_info *sinfo) +{ +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; +struct rate_info *txrate = &msta->wcid.rate; + +if (!txrate->legacy && !txrate->flags) +return ; + +if (txrate->legacy) { + sinfo->txrate.legacy = txrate->legacy; + }else { + sinfo->txrate.mcs = txrate->mcs; + sinfo->txrate.nss = txrate->nss; + sinfo->txrate.bw = txrate->bw; + sinfo->txrate.he_gi = txrate->he_gi; + sinfo->txrate.he_dcm = txrate->he_dcm; + sinfo->txrate.he_ru_alloc = txrate->he_ru_alloc; + } + sinfo->txrate.flags = txrate->flags; + sinfo->filled |=BIT_ULL (NL80211_STA_INFO_TX_BITRATE ); +} + +static void mt7996_sta_rc_work (void *data,struct ieee80211_sta *sta) +{ +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; +struct mt7996_dev *dev = msta->vif->phy->dev; +u32 *changed = data; + +spin_lock_bh (&dev->sta_poll_lock); + msta->changed |= *changed; +if (list_empty (&msta->rc_list)) +list_add_tail (&msta->rc_list, &dev->sta_rc_list); +spin_unlock_bh (&dev->sta_poll_lock); +} + +static void mt7996_sta_rc_update (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +u32 changed) +{ +struct mt7996_phy *phy =mt7996_hw_phy (hw); +struct mt7996_dev *dev = phy->dev; + +mt7996_sta_rc_work (&changed, sta); +ieee80211_queue_work (hw, &dev->rc_work); +} + +static int +mt7996_set_bitrate_mask (struct ieee80211_hw *hw,struct ieee80211_vif *vif, +const struct cfg80211_bitrate_mask *mask) +{ +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt7996_phy *phy =mt7996_hw_phy (hw); +struct mt7996_dev *dev = phy->dev; +u32 changed =IEEE80211_RC_SUPP_RATES_CHANGED ; + + mvif->bitrate_mask = *mask; + +/* if multiple rates across different preambles are given we can +* reconfigure this info with all peers using sta_rec command with +* the below exception cases. +* - single rate : if a rate is passed along with different preambles, +* we select the highest one as fixed rate. i.e VHT MCS for VHT peers. +* - multiple rates: if it's not in range format i.e 0-{7,8,9} for VHT +* then multiple MCS setting (MCS 4,5,6) is not supported. +*/ +ieee80211_iterate_stations_atomic (hw, mt7996_sta_rc_work, &changed); +ieee80211_queue_work (hw, &dev->rc_work); + +return 0 ; +} + +static void mt7996_sta_set_4addr (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +bool enabled) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + +if (enabled) +set_bit (MT_WCID_FLAG_4ADDR , &msta->wcid.flags); +else +clear_bit (MT_WCID_FLAG_4ADDR , &msta->wcid.flags); + +mt7996_mcu_wtbl_update_hdr_trans (dev, vif, sta); +} + +static void mt7996_sta_set_decap_offload (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +bool enabled) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + +if (enabled) +set_bit (MT_WCID_FLAG_HDR_TRANS , &msta->wcid.flags); +else +clear_bit (MT_WCID_FLAG_HDR_TRANS , &msta->wcid.flags); + +mt7996_mcu_wtbl_update_hdr_trans (dev, vif, sta); +} + +static const char mt7996_gstrings_stats[][ETH_GSTRING_LEN ] = { +"tx_ampdu_cnt" , +"tx_stop_q_empty_cnt" , +"tx_mpdu_attempts" , +"tx_mpdu_success" , +"tx_rwp_fail_cnt" , +"tx_rwp_need_cnt" , +"tx_pkt_ebf_cnt" , +"tx_pkt_ibf_cnt" , +"tx_ampdu_len:0-1" , +"tx_ampdu_len:2-10" , +"tx_ampdu_len:11-19" , +"tx_ampdu_len:20-28" , +"tx_ampdu_len:29-37" , +"tx_ampdu_len:38-46" , +"tx_ampdu_len:47-55" , +"tx_ampdu_len:56-79" , +"tx_ampdu_len:80-103" , +"tx_ampdu_len:104-127" , +"tx_ampdu_len:128-151" , +"tx_ampdu_len:152-175" , +"tx_ampdu_len:176-199" , +"tx_ampdu_len:200-223" , +"tx_ampdu_len:224-247" , +"ba_miss_count" , +"tx_beamformer_ppdu_iBF" , +"tx_beamformer_ppdu_eBF" , +"tx_beamformer_rx_feedback_all" , +"tx_beamformer_rx_feedback_he" , +"tx_beamformer_rx_feedback_vht" , +"tx_beamformer_rx_feedback_ht" , +"tx_beamformer_rx_feedback_bw" ,/* zero based idx: 20, 40, 80, 160 */ +"tx_beamformer_rx_feedback_nc" , +"tx_beamformer_rx_feedback_nr" , +"tx_beamformee_ok_feedback_pkts" , +"tx_beamformee_feedback_trig" , +"tx_mu_beamforming" , +"tx_mu_mpdu" , +"tx_mu_successful_mpdu" , +"tx_su_successful_mpdu" , +"tx_msdu_pack_1" , +"tx_msdu_pack_2" , +"tx_msdu_pack_3" , +"tx_msdu_pack_4" , +"tx_msdu_pack_5" , +"tx_msdu_pack_6" , +"tx_msdu_pack_7" , +"tx_msdu_pack_8" , + +/* rx counters */ +"rx_fifo_full_cnt" , +"rx_mpdu_cnt" , +"channel_idle_cnt" , +"rx_vector_mismatch_cnt" , +"rx_delimiter_fail_cnt" , +"rx_len_mismatch_cnt" , +"rx_ampdu_cnt" , +"rx_ampdu_bytes_cnt" , +"rx_ampdu_valid_subframe_cnt" , +"rx_ampdu_valid_subframe_b_cnt" , +"rx_pfdrop_cnt" , +"rx_vec_queue_overflow_drop_cnt" , +"rx_ba_cnt" , + +/* per vif counters */ +"v_tx_mode_cck" , +"v_tx_mode_ofdm" , +"v_tx_mode_ht" , +"v_tx_mode_ht_gf" , +"v_tx_mode_vht" , +"v_tx_mode_he_su" , +"v_tx_mode_he_ext_su" , +"v_tx_mode_he_tb" , +"v_tx_mode_he_mu" , +"v_tx_bw_20" , +"v_tx_bw_40" , +"v_tx_bw_80" , +"v_tx_bw_160" , +"v_tx_mcs_0" , +"v_tx_mcs_1" , +"v_tx_mcs_2" , +"v_tx_mcs_3" , +"v_tx_mcs_4" , +"v_tx_mcs_5" , +"v_tx_mcs_6" , +"v_tx_mcs_7" , +"v_tx_mcs_8" , +"v_tx_mcs_9" , +"v_tx_mcs_10" , +"v_tx_mcs_11" , +}; + +#define MT7996_SSTATS_LEN ARRAY_SIZE(mt7996_gstrings_stats) + +/* Ethtool related API */ +static +void mt7996_get_et_strings (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +u32 sset,u8 *data) +{ +if (sset ==ETH_SS_STATS ) +memcpy (data, *mt7996_gstrings_stats, +sizeof (mt7996_gstrings_stats)); +} + +static +int mt7996_get_et_sset_count (struct ieee80211_hw *hw, +struct ieee80211_vif *vif,int sset) +{ +if (sset ==ETH_SS_STATS ) +return MT7996_SSTATS_LEN ; + +return 0 ; +} + +static void mt7996_ethtool_worker (void *wi_data,struct ieee80211_sta *sta) +{ +struct mt76_ethtool_worker_info *wi = wi_data; +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; + +if (msta->vif->mt76.idx != wi->idx) +return ; + +mt76_ethtool_worker (wi, &msta->stats); +} + +static +void mt7996_get_et_stats (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ethtool_stats *stats,u64 *data) +{ +struct mt7996_dev *dev =mt7996_hw_dev (hw); +struct mt7996_phy *phy =mt7996_hw_phy (hw); +struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; +struct mt76_ethtool_worker_info wi = { + .data = data, + .idx = mvif->mt76.idx, + }; +struct mib_stats *mib = &phy->mib; +/* See mt7996_ampdu_stat_read_phy, etc */ +int i, ei =0 ; + +mutex_lock (&dev->mt76.mutex); + +mt7996_mac_update_stats (phy); + + data[ei++] = mib->tx_ampdu_cnt; + data[ei++] = mib->tx_stop_q_empty_cnt; + data[ei++] = mib->tx_mpdu_attempts_cnt; + data[ei++] = mib->tx_mpdu_success_cnt; + data[ei++] = mib->tx_rwp_fail_cnt; + data[ei++] = mib->tx_rwp_need_cnt; + data[ei++] = mib->tx_bf_ebf_ppdu_cnt; + data[ei++] = mib->tx_bf_ibf_ppdu_cnt; + +/* Tx ampdu stat */ +for (i =0 ; i <15 /*ARRAY_SIZE(bound)*/ ; i++) + data[ei++] = phy->mt76->aggr_stats[i]; + data[ei++] = phy->mib.ba_miss_cnt; + +/* Tx Beamformer monitor */ + data[ei++] = mib->tx_bf_ibf_ppdu_cnt; + data[ei++] = mib->tx_bf_ebf_ppdu_cnt; + +/* Tx Beamformer Rx feedback monitor */ + data[ei++] = mib->tx_bf_rx_fb_all_cnt; + data[ei++] = mib->tx_bf_rx_fb_he_cnt; + data[ei++] = mib->tx_bf_rx_fb_vht_cnt; + data[ei++] = mib->tx_bf_rx_fb_ht_cnt; + + data[ei++] = mib->tx_bf_rx_fb_bw; + data[ei++] = mib->tx_bf_rx_fb_nc_cnt; + data[ei++] = mib->tx_bf_rx_fb_nr_cnt; + +/* Tx Beamformee Rx NDPA & Tx feedback report */ + data[ei++] = mib->tx_bf_fb_cpl_cnt; + data[ei++] = mib->tx_bf_fb_trig_cnt; + +/* Tx SU & MU counters */ + data[ei++] = mib->tx_mu_bf_cnt; + data[ei++] = mib->tx_mu_mpdu_cnt; + data[ei++] = mib->tx_mu_acked_mpdu_cnt; + data[ei++] = mib->tx_su_acked_mpdu_cnt; + +/* Tx amsdu info (pack-count histogram) */ +for (i =0 ; i <ARRAY_SIZE (mib->tx_amsdu); i++) + data[ei++] = mib->tx_amsdu[i]; + +/* rx counters */ + data[ei++] = mib->rx_fifo_full_cnt; + data[ei++] = mib->rx_mpdu_cnt; + data[ei++] = mib->channel_idle_cnt; + data[ei++] = mib->rx_vector_mismatch_cnt; + data[ei++] = mib->rx_delimiter_fail_cnt; + data[ei++] = mib->rx_len_mismatch_cnt; + data[ei++] = mib->rx_ampdu_cnt; + data[ei++] = mib->rx_ampdu_bytes_cnt; + data[ei++] = mib->rx_ampdu_valid_subframe_cnt; + data[ei++] = mib->rx_ampdu_valid_subframe_bytes_cnt; + data[ei++] = mib->rx_pfdrop_cnt; + data[ei++] = mib->rx_vec_queue_overflow_drop_cnt; + data[ei++] = mib->rx_ba_cnt; + +/* Add values for all stations owned by this vif */ + wi.initial_stat_idx = ei; +ieee80211_iterate_stations_atomic (hw, mt7996_ethtool_worker, &wi); + +mutex_unlock (&dev->mt76.mutex); + +if (wi.sta_count ==0 ) +return ; + + ei += wi.worker_stat_count; +if (ei !=MT7996_SSTATS_LEN ) +dev_err (dev->mt76.dev,"ei: %d MT7996_SSTATS_LEN: %d" , + ei, (int )MT7996_SSTATS_LEN ); +} + +static void +mt7996_twt_teardown_request (struct ieee80211_hw *hw, +struct ieee80211_sta *sta, +u8 flowid) +{ +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; +struct mt7996_dev *dev =mt7996_hw_dev (hw); + +mutex_lock (&dev->mt76.mutex); +mt7996_mac_twt_teardown_flow (dev, msta, flowid); +mutex_unlock (&dev->mt76.mutex); +} + +static int +mt7996_set_radar_background (struct ieee80211_hw *hw, +struct cfg80211_chan_def *chandef) +{ +struct mt7996_phy *phy =mt7996_hw_phy (hw); +struct mt7996_dev *dev = phy->dev; +int ret = -EINVAL ; +bool running; + +mutex_lock (&dev->mt76.mutex); + +if (dev->mt76.region ==NL80211_DFS_UNSET ) + goto out; + +if (dev->rdd2_phy && dev->rdd2_phy != phy) { +/* rdd2 is already locked */ + ret = -EBUSY ; + goto out; + } + +/* rdd2 already configured on a radar channel */ + running = dev->rdd2_phy && +cfg80211_chandef_valid (&dev->rdd2_chandef) && + !!(dev->rdd2_chandef.chan->flags &IEEE80211_CHAN_RADAR ); + +if (!chandef || running || + !(chandef->chan->flags &IEEE80211_CHAN_RADAR )) { + ret =mt7996_mcu_rdd_background_enable (phy,NULL ); +if (ret) + goto out; + +if (!running) + goto update_phy; + } + + ret =mt7996_mcu_rdd_background_enable (phy, chandef); +if (ret) + goto out; + +update_phy: + dev->rdd2_phy = chandef ? phy :NULL ; +if (chandef) + dev->rdd2_chandef = *chandef; +out: +mutex_unlock (&dev->mt76.mutex); + +return ret; +} + +const struct ieee80211_ops mt7996_ops = { + .tx = mt7996_tx, + .start = mt7996_start, + .stop = mt7996_stop, + .add_interface = mt7996_add_interface, + .remove_interface = mt7996_remove_interface, + .config = mt7996_config, + .conf_tx = mt7996_conf_tx, + .configure_filter = mt7996_configure_filter, + .bss_info_changed = mt7996_bss_info_changed, + .sta_add = mt7996_sta_add, + .sta_remove = mt7996_sta_remove, + .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove, + .sta_rc_update = mt7996_sta_rc_update, + .set_key = mt7996_set_key, + .ampdu_action = mt7996_ampdu_action, + .set_rts_threshold = mt7996_set_rts_threshold, + .wake_tx_queue = mt76_wake_tx_queue, + .sw_scan_start = mt76_sw_scan, + .sw_scan_complete = mt76_sw_scan_complete, + .release_buffered_frames = mt76_release_buffered_frames, + .get_txpower = mt76_get_txpower, + .channel_switch_beacon = mt7996_channel_switch_beacon, + .get_stats = mt7996_get_stats, + .get_et_sset_count = mt7996_get_et_sset_count, + .get_et_stats = mt7996_get_et_stats, + .get_et_strings = mt7996_get_et_strings, + .get_tsf = mt7996_get_tsf, + .set_tsf = mt7996_set_tsf, + .offset_tsf = mt7996_offset_tsf, + .get_survey = mt76_get_survey, + .get_antenna = mt76_get_antenna, + .set_antenna = mt7996_set_antenna, + .set_bitrate_mask = mt7996_set_bitrate_mask, + .set_coverage_class = mt7996_set_coverage_class, + .sta_statistics = mt7996_sta_statistics, + .sta_set_4addr = mt7996_sta_set_4addr, + .sta_set_decap_offload = mt7996_sta_set_decap_offload, + .add_twt_setup = mt7996_mac_add_twt_setup, + .twt_teardown_request = mt7996_twt_teardown_request, +#ifdef CONFIG_MAC80211_DEBUGFS + .sta_add_debugfs = mt7996_sta_add_debugfs, +#endif + .set_radar_background = mt7996_set_radar_background, +};
Signature · 1 line
2.25.1
Shayne Chen
reviewerPATCH 7/9 wifi: mt76: mt7996: add debugfs support
In reply to Shayne Chen(Split the big patch into smaller intermediate patches by functionality for easier review. Refer to the cover letter for more info.)
--- .../wireless/mediatek/mt76/mt7996/debugfs.c | 851 ++++++++++++++++++ 1 file changed, 851 insertions(+) create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c
drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c new file +851 -0
@@ -0,0 +1,851 @@ +// SPDX-License-Identifier: ISC +/* +* Copyright (C) 2022 MediaTek Inc. +*/ + +#include <linux/relay.h> +#include "mt7996.h" +#include "eeprom.h" +#include "mcu.h" +#include "mac.h" + +#define FW_BIN_LOG_MAGIC 0x44d9c99a + +/** global debugfs **/ + +struct hw_queue_map { +const char *name; +u8 index; +u8 pid; +u8 qid; +}; + +static int +mt7996_implicit_txbf_set (void *data,u64 val) +{ +struct mt7996_dev *dev = data; + +/* The existing connected stations shall reconnect to apply +* new implicit txbf configuration. +*/ + dev->ibf = !!val; + +return mt7996_mcu_set_txbf (dev,BF_HW_EN_UPDATE ); +} + +static int +mt7996_implicit_txbf_get (void *data,u64 *val) +{ +struct mt7996_dev *dev = data; + + *val = dev->ibf; + +return 0 ; +} + +DEFINE_DEBUGFS_ATTRIBUTE (fops_implicit_txbf, mt7996_implicit_txbf_get, + mt7996_implicit_txbf_set,"%lld\n" ); + +/* test knob of system error recovery */ +static ssize_t +mt7996_fw_ser_set (struct file *file,const char __user *user_buf, +size_t count,loff_t *ppos) +{ +struct mt7996_phy *phy = file->private_data; +struct mt7996_dev *dev = phy->dev; +u8 band_idx = phy->mt76->band_idx; +char buf[16 ]; +int ret =0 ; +u16 val; + +if (count >=sizeof (buf)) +return -EINVAL ; + +if (copy_from_user (buf, user_buf, count)) +return -EFAULT ; + +if (count && buf[count -1 ] =='\n' ) + buf[count -1 ] ='\0' ; +else + buf[count] ='\0' ; + +if (kstrtou16 (buf,0 , &val)) +return -EINVAL ; + +switch (val) { +case SER_SET_RECOVER_L1 : +case SER_SET_RECOVER_L2 : +case SER_SET_RECOVER_L3_RX_ABORT : +case SER_SET_RECOVER_L3_TX_ABORT : +case SER_SET_RECOVER_L3_TX_DISABLE : +case SER_SET_RECOVER_L3_BF : + ret =mt7996_mcu_set_ser (dev,SER_ENABLE ,BIT (val), band_idx); +if (ret) +return ret; + + ret =mt7996_mcu_set_ser (dev,SER_RECOVER , val, band_idx); +break ; +default : +break ; + } + +return ret ? ret : count; +} + +static const struct file_operations mt7996_fw_ser_ops = { + .write = mt7996_fw_ser_set, +/* TODO: ser read */ + .open = simple_open, + .llseek = default_llseek, +}; + +static int +mt7996_radar_trigger (void *data,u64 val) +{ +struct mt7996_dev *dev = data; + +if (val >MT_RX_SEL2 ) +return -EINVAL ; + +return mt7996_mcu_rdd_cmd (dev,RDD_RADAR_EMULATE , + val,0 ,0 ); +} + +DEFINE_DEBUGFS_ATTRIBUTE (fops_radar_trigger,NULL , + mt7996_radar_trigger,"%lld\n" ); + +static int +mt7996_rdd_monitor (struct seq_file *s,void *data) +{ +struct mt7996_dev *dev =dev_get_drvdata (s->private); +struct cfg80211_chan_def *chandef = &dev->rdd2_chandef; +const char *bw; +int ret =0 ; + +mutex_lock (&dev->mt76.mutex); + +if (!cfg80211_chandef_valid (chandef)) { + ret = -EINVAL ; + goto out; + } + +if (!dev->rdd2_phy) { +seq_puts (s,"not running\n" ); + goto out; + } + +switch (chandef->width) { +case NL80211_CHAN_WIDTH_40 : + bw ="40" ; +break ; +case NL80211_CHAN_WIDTH_80 : + bw ="80" ; +break ; +case NL80211_CHAN_WIDTH_160 : + bw ="160" ; +break ; +case NL80211_CHAN_WIDTH_80P80 : + bw ="80P80" ; +break ; +default : + bw ="20" ; +break ; + } + +seq_printf (s,"channel %d (%d MHz) width %s MHz center1: %d MHz\n" , + chandef->chan->hw_value, chandef->chan->center_freq, + bw, chandef->center_freq1); +out: +mutex_unlock (&dev->mt76.mutex); + +return ret; +} + +static int +mt7996_fw_debug_wm_set (void *data,u64 val) +{ +struct mt7996_dev *dev = data; +enum { +DEBUG_TXCMD =62 , +DEBUG_CMD_RPT_TX , +DEBUG_CMD_RPT_TRIG , +DEBUG_SPL , +DEBUG_RPT_RX , +DEBUG_RPT_RA =68 , + } debug; +bool tx, rx, en; +int ret; + + dev->fw_debug_wm = val ?MCU_FW_LOG_TO_HOST :0 ; + +if (dev->fw_debug_bin) + val =MCU_FW_LOG_RELAY ; +else + val = dev->fw_debug_wm; + + tx = dev->fw_debug_wm || (dev->fw_debug_bin &BIT (1 )); + rx = dev->fw_debug_wm || (dev->fw_debug_bin &BIT (2 )); + en = dev->fw_debug_wm || (dev->fw_debug_bin &BIT (0 )); + + ret =mt7996_mcu_fw_log_2_host (dev,MCU_FW_LOG_WM , val); +if (ret) +return ret; + +for (debug =DEBUG_TXCMD ; debug <=DEBUG_RPT_RA ; debug++) { +if (debug ==67 ) +continue ; + +if (debug ==DEBUG_RPT_RX ) + val = en && rx; +else + val = en && tx; + + ret =mt7996_mcu_fw_dbg_ctrl (dev, debug, val); +if (ret) +return ret; + } + +return 0 ; +} + +static int +mt7996_fw_debug_wm_get (void *data,u64 *val) +{ +struct mt7996_dev *dev = data; + + *val = dev->fw_debug_wm; + +return 0 ; +} + +DEFINE_DEBUGFS_ATTRIBUTE (fops_fw_debug_wm, mt7996_fw_debug_wm_get, + mt7996_fw_debug_wm_set,"%lld\n" ); + +static int +mt7996_fw_debug_wa_set (void *data,u64 val) +{ +struct mt7996_dev *dev = data; +int ret; + + dev->fw_debug_wa = val ?MCU_FW_LOG_TO_HOST :0 ; + + ret =mt7996_mcu_fw_log_2_host (dev,MCU_FW_LOG_WA , dev->fw_debug_wa); +if (ret) +return ret; + +return mt7996_mcu_wa_cmd (dev,MCU_WA_PARAM_CMD (SET ),MCU_WA_PARAM_PDMA_RX , + !!dev->fw_debug_wa,0 ); +} + +static int +mt7996_fw_debug_wa_get (void *data,u64 *val) +{ +struct mt7996_dev *dev = data; + + *val = dev->fw_debug_wa; + +return 0 ; +} + +DEFINE_DEBUGFS_ATTRIBUTE (fops_fw_debug_wa, mt7996_fw_debug_wa_get, + mt7996_fw_debug_wa_set,"%lld\n" ); + +static struct dentry * +create_buf_file_cb (const char *filename,struct dentry *parent,umode_t mode, +struct rchan_buf *buf,int *is_global) +{ +struct dentry *f; + + f =debugfs_create_file ("fwlog_data" , mode, parent, buf, + &relay_file_operations); +if (IS_ERR (f)) +return NULL ; + + *is_global =1 ; + +return f; +} + +static int +remove_buf_file_cb (struct dentry *f) +{ +debugfs_remove (f); + +return 0 ; +} + +static int +mt7996_fw_debug_bin_set (void *data,u64 val) +{ +static struct rchan_callbacks relay_cb = { + .create_buf_file = create_buf_file_cb, + .remove_buf_file = remove_buf_file_cb, + }; +struct mt7996_dev *dev = data; + +if (!dev->relay_fwlog) + dev->relay_fwlog =relay_open ("fwlog_data" , dev->debugfs_dir, +1500 ,512 , &relay_cb,NULL ); +if (!dev->relay_fwlog) +return -ENOMEM ; + + dev->fw_debug_bin = val; + +relay_reset (dev->relay_fwlog); + +return mt7996_fw_debug_wm_set (dev, dev->fw_debug_wm); +} + +static int +mt7996_fw_debug_bin_get (void *data,u64 *val) +{ +struct mt7996_dev *dev = data; + + *val = dev->fw_debug_bin; + +return 0 ; +} + +DEFINE_DEBUGFS_ATTRIBUTE (fops_fw_debug_bin, mt7996_fw_debug_bin_get, + mt7996_fw_debug_bin_set,"%lld\n" ); + +static int +mt7996_fw_util_wa_show (struct seq_file *file,void *data) +{ +struct mt7996_dev *dev = file->private; + +if (dev->fw_debug_wa) +return mt7996_mcu_wa_cmd (dev,MCU_WA_PARAM_CMD (QUERY ), +MCU_WA_PARAM_CPU_UTIL ,0 ,0 ); + +return 0 ; +} + +DEFINE_SHOW_ATTRIBUTE (mt7996_fw_util_wa); + +static void +mt7996_ampdu_stat_read_phy (struct mt7996_phy *phy,struct seq_file *file) +{ +struct mt7996_dev *dev = phy->dev; +int bound[15 ], range[8 ], i; +u8 band_idx = phy->mt76->band_idx; + +/* Tx ampdu stat */ +for (i =0 ; i <ARRAY_SIZE (range); i++) + range[i] =mt76_rr (dev,MT_MIB_ARNG (band_idx, i)); + +for (i =0 ; i <ARRAY_SIZE (bound); i++) + bound[i] =MT_MIB_ARNCR_RANGE (range[i /2 ], i %2 ) +1 ; + +seq_printf (file,"\nPhy %s, Phy band %d\n" , +wiphy_name (phy->mt76->hw->wiphy), band_idx); + +seq_printf (file,"Length: %8d | " , bound[0 ]); +for (i =0 ; i <ARRAY_SIZE (bound) -1 ; i++) +seq_printf (file,"%3d -%3d | " , + bound[i] +1 , bound[i +1 ]); + +seq_puts (file,"\nCount: " ); +for (i =0 ; i <ARRAY_SIZE (bound); i++) +seq_printf (file,"%8d | " , phy->mt76->aggr_stats[i]); +seq_puts (file,"\n" ); + +seq_printf (file,"BA miss count: %d\n" , phy->mib.ba_miss_cnt); +} + +static void +mt7996_txbf_stat_read_phy (struct mt7996_phy *phy,struct seq_file *s) +{ +static const char *const bw[] = { +"BW20" ,"BW40" ,"BW80" ,"BW160" + }; +struct mib_stats *mib = &phy->mib; + +/* Tx Beamformer monitor */ +seq_puts (s,"\nTx Beamformer applied PPDU counts: " ); + +seq_printf (s,"iBF: %d, eBF: %d\n" , + mib->tx_bf_ibf_ppdu_cnt, + mib->tx_bf_ebf_ppdu_cnt); + +/* Tx Beamformer Rx feedback monitor */ +seq_puts (s,"Tx Beamformer Rx feedback statistics: " ); + +seq_printf (s,"All: %d, HE: %d, VHT: %d, HT: %d, " , + mib->tx_bf_rx_fb_all_cnt, + mib->tx_bf_rx_fb_he_cnt, + mib->tx_bf_rx_fb_vht_cnt, + mib->tx_bf_rx_fb_ht_cnt); + +seq_printf (s,"%s, NC: %d, NR: %d\n" , + bw[mib->tx_bf_rx_fb_bw], + mib->tx_bf_rx_fb_nc_cnt, + mib->tx_bf_rx_fb_nr_cnt); + +/* Tx Beamformee Rx NDPA & Tx feedback report */ +seq_printf (s,"Tx Beamformee successful feedback frames: %d\n" , + mib->tx_bf_fb_cpl_cnt); +seq_printf (s,"Tx Beamformee feedback triggered counts: %d\n" , + mib->tx_bf_fb_trig_cnt); + +/* Tx SU & MU counters */ +seq_printf (s,"Tx multi-user Beamforming counts: %d\n" , + mib->tx_mu_bf_cnt); +seq_printf (s,"Tx multi-user MPDU counts: %d\n" , mib->tx_mu_mpdu_cnt); +seq_printf (s,"Tx multi-user successful MPDU counts: %d\n" , + mib->tx_mu_acked_mpdu_cnt); +seq_printf (s,"Tx single-user successful MPDU counts: %d\n" , + mib->tx_su_acked_mpdu_cnt); + +seq_puts (s,"\n" ); +} + +static int +mt7996_tx_stats_show (struct seq_file *file,void *data) +{ +struct mt7996_phy *phy = file->private; +struct mt7996_dev *dev = phy->dev; +struct mib_stats *mib = &phy->mib; +int i; +u32 attempts, success, per; + +mutex_lock (&dev->mt76.mutex); + +mt7996_mac_update_stats (phy); +mt7996_ampdu_stat_read_phy (phy, file); + + attempts = mib->tx_mpdu_attempts_cnt; + success = mib->tx_mpdu_success_cnt; + per = attempts ?100 - success *100 / attempts :100 ; +seq_printf (file,"Tx attempts: %8u (MPDUs)\n" , attempts); +seq_printf (file,"Tx success: %8u (MPDUs)\n" , success); +seq_printf (file,"Tx PER: %u%%\n" , per); + +mt7996_txbf_stat_read_phy (phy, file); + +/* Tx amsdu info */ +seq_puts (file,"Tx MSDU statistics:\n" ); +for (i =0 ; i <ARRAY_SIZE (mib->tx_amsdu); i++) { +seq_printf (file,"AMSDU pack count of %d MSDU in TXD: %8d " , + i +1 , mib->tx_amsdu[i]); +if (mib->tx_amsdu_cnt) +seq_printf (file,"(%3d%%)\n" , + mib->tx_amsdu[i] *100 / mib->tx_amsdu_cnt); +else +seq_puts (file,"\n" ); + } + +mutex_unlock (&dev->mt76.mutex); + +return 0 ; +} + +DEFINE_SHOW_ATTRIBUTE (mt7996_tx_stats); + +static void +mt7996_hw_queue_read (struct seq_file *s,u32 size, +const struct hw_queue_map *map) +{ +struct mt7996_phy *phy = s->private; +struct mt7996_dev *dev = phy->dev; +u32 i, val; + + val =mt76_rr (dev,MT_FL_Q_EMPTY ); +for (i =0 ; i < size; i++) { +u32 ctrl, head, tail, queued; + +if (val &BIT (map[i].index)) +continue ; + + ctrl =BIT (31 ) | (map[i].pid <<10 ) | (map[i].qid <<24 ); +mt76_wr (dev,MT_FL_Q0_CTRL , ctrl); + + head =mt76_get_field (dev,MT_FL_Q2_CTRL , +GENMASK (11 ,0 )); + tail =mt76_get_field (dev,MT_FL_Q2_CTRL , +GENMASK (27 ,16 )); + queued =mt76_get_field (dev,MT_FL_Q3_CTRL , +GENMASK (11 ,0 )); + +seq_printf (s,"\t%s: " , map[i].name); +seq_printf (s,"queued:0x%03x head:0x%03x tail:0x%03x\n" , + queued, head, tail); + } +} + +static void +mt7996_sta_hw_queue_read (void *data,struct ieee80211_sta *sta) +{ +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; +struct mt7996_dev *dev = msta->vif->phy->dev; +struct seq_file *s = data; +u8 ac; + +for (ac =0 ; ac <4 ; ac++) { +u32 qlen, ctrl, val; +u32 idx = msta->wcid.idx >>5 ; +u8 offs = msta->wcid.idx &GENMASK (4 ,0 ); + + ctrl =BIT (31 ) |BIT (11 ) | (ac <<24 ); + val =mt76_rr (dev,MT_PLE_AC_QEMPTY (ac, idx)); + +if (val &BIT (offs)) +continue ; + +mt76_wr (dev,MT_FL_Q0_CTRL , ctrl | msta->wcid.idx); + qlen =mt76_get_field (dev,MT_FL_Q3_CTRL , +GENMASK (11 ,0 )); +seq_printf (s,"\tSTA %pM wcid %d: AC%d%d queued:%d\n" , + sta->addr, msta->wcid.idx, + msta->vif->mt76.wmm_idx, ac, qlen); + } +} + +static int +mt7996_hw_queues_show (struct seq_file *file,void *data) +{ +struct mt7996_phy *phy = file->private; +struct mt7996_dev *dev = phy->dev; +static const struct hw_queue_map ple_queue_map[] = { + {"CPU_Q0" ,0 ,1 ,MT_CTX0 }, + {"CPU_Q1" ,1 ,1 ,MT_CTX0 +1 }, + {"CPU_Q2" ,2 ,1 ,MT_CTX0 +2 }, + {"CPU_Q3" ,3 ,1 ,MT_CTX0 +3 }, + {"ALTX_Q0" ,8 ,2 ,MT_LMAC_ALTX0 }, + {"BMC_Q0" ,9 ,2 ,MT_LMAC_BMC0 }, + {"BCN_Q0" ,10 ,2 ,MT_LMAC_BCN0 }, + {"PSMP_Q0" ,11 ,2 ,MT_LMAC_PSMP0 }, + {"ALTX_Q1" ,12 ,2 ,MT_LMAC_ALTX0 +4 }, + {"BMC_Q1" ,13 ,2 ,MT_LMAC_BMC0 +4 }, + {"BCN_Q1" ,14 ,2 ,MT_LMAC_BCN0 +4 }, + {"PSMP_Q1" ,15 ,2 ,MT_LMAC_PSMP0 +4 }, + }; +static const struct hw_queue_map pse_queue_map[] = { + {"CPU Q0" ,0 ,1 ,MT_CTX0 }, + {"CPU Q1" ,1 ,1 ,MT_CTX0 +1 }, + {"CPU Q2" ,2 ,1 ,MT_CTX0 +2 }, + {"CPU Q3" ,3 ,1 ,MT_CTX0 +3 }, + {"HIF_Q0" ,8 ,0 ,MT_HIF0 }, + {"HIF_Q1" ,9 ,0 ,MT_HIF0 +1 }, + {"HIF_Q2" ,10 ,0 ,MT_HIF0 +2 }, + {"HIF_Q3" ,11 ,0 ,MT_HIF0 +3 }, + {"HIF_Q4" ,12 ,0 ,MT_HIF0 +4 }, + {"HIF_Q5" ,13 ,0 ,MT_HIF0 +5 }, + {"LMAC_Q" ,16 ,2 ,0 }, + {"MDP_TXQ" ,17 ,2 ,1 }, + {"MDP_RXQ" ,18 ,2 ,2 }, + {"SEC_TXQ" ,19 ,2 ,3 }, + {"SEC_RXQ" ,20 ,2 ,4 }, + }; +u32 val, head, tail; + +/* ple queue */ + val =mt76_rr (dev,MT_PLE_FREEPG_CNT ); + head =mt76_get_field (dev,MT_PLE_FREEPG_HEAD_TAIL ,GENMASK (11 ,0 )); + tail =mt76_get_field (dev,MT_PLE_FREEPG_HEAD_TAIL ,GENMASK (27 ,16 )); +seq_puts (file,"PLE page info:\n" ); +seq_printf (file, +"\tTotal free page: 0x%08x head: 0x%03x tail: 0x%03x\n" , + val, head, tail); + + val =mt76_rr (dev,MT_PLE_PG_HIF_GROUP ); + head =mt76_get_field (dev,MT_PLE_HIF_PG_INFO ,GENMASK (11 ,0 )); + tail =mt76_get_field (dev,MT_PLE_HIF_PG_INFO ,GENMASK (27 ,16 )); +seq_printf (file,"\tHIF free page: 0x%03x res: 0x%03x used: 0x%03x\n" , + val, head, tail); + +seq_puts (file,"PLE non-empty queue info:\n" ); +mt7996_hw_queue_read (file,ARRAY_SIZE (ple_queue_map), + &ple_queue_map[0 ]); + +/* iterate per-sta ple queue */ +ieee80211_iterate_stations_atomic (phy->mt76->hw, + mt7996_sta_hw_queue_read, file); +/* pse queue */ +seq_puts (file,"PSE non-empty queue info:\n" ); +mt7996_hw_queue_read (file,ARRAY_SIZE (pse_queue_map), + &pse_queue_map[0 ]); + +return 0 ; +} + +DEFINE_SHOW_ATTRIBUTE (mt7996_hw_queues); + +static int +mt7996_xmit_queues_show (struct seq_file *file,void *data) +{ +struct mt7996_phy *phy = file->private; +struct mt7996_dev *dev = phy->dev; +struct { +struct mt76_queue *q; +char *queue; + } queue_map[] = { + { phy->mt76->q_tx[MT_TXQ_BE ]," MAIN" }, + { dev->mt76.q_mcu[MT_MCUQ_WM ]," MCUWM" }, + { dev->mt76.q_mcu[MT_MCUQ_WA ]," MCUWA" }, + { dev->mt76.q_mcu[MT_MCUQ_FWDL ],"MCUFWDL" }, + }; +int i; + +seq_puts (file," queue | hw-queued | head | tail |\n" ); +for (i =0 ; i <ARRAY_SIZE (queue_map); i++) { +struct mt76_queue *q = queue_map[i].q; + +if (!q) +continue ; + +seq_printf (file," %s | %9d | %9d | %9d |\n" , + queue_map[i].queue, q->queued, q->head, + q->tail); + } + +return 0 ; +} + +DEFINE_SHOW_ATTRIBUTE (mt7996_xmit_queues); + +static int +mt7996_twt_stats (struct seq_file *s,void *data) +{ +struct mt7996_dev *dev =dev_get_drvdata (s->private); +struct mt7996_twt_flow *iter; + +rcu_read_lock (); + +seq_puts (s," wcid | id | flags | exp | mantissa" ); +seq_puts (s," | duration | tsf |\n" ); +list_for_each_entry_rcu (iter, &dev->twt_list, list) +seq_printf (s, +"%9d | %8d | %5c%c%c%c | %8d | %8d | %8d | %14lld |\n" , + iter->wcid, iter->id, + iter->sched ?'s' :'u' , + iter->protection ?'p' :'-' , + iter->trigger ?'t' :'-' , + iter->flowtype ?'-' :'a' , + iter->exp, iter->mantissa, + iter->duration, iter->tsf); + +rcu_read_unlock (); + +return 0 ; +} + +/* The index of RF registers use the generic regidx, combined with two parts: +* WF selection [31:24] and offset [23:0]. +*/ +static int +mt7996_rf_regval_get (void *data,u64 *val) +{ +struct mt7996_dev *dev = data; +u32 regval; +int ret; + + ret =mt7996_mcu_rf_regval (dev, dev->mt76.debugfs_reg, ®val, false); +if (ret) +return ret; + + *val =le32_to_cpu (regval); + +return 0 ; +} + +static int +mt7996_rf_regval_set (void *data,u64 val) +{ +struct mt7996_dev *dev = data; + +return mt7996_mcu_rf_regval (dev, dev->mt76.debugfs_reg, (u32 *)&val, true); +} + +DEFINE_DEBUGFS_ATTRIBUTE (fops_rf_regval, mt7996_rf_regval_get, + mt7996_rf_regval_set,"0x%08llx\n" ); + +int mt7996_init_debugfs (struct mt7996_phy *phy) +{ +struct mt7996_dev *dev = phy->dev; +struct dentry *dir; + + dir =mt76_register_debugfs_fops (phy->mt76,NULL ); +if (!dir) +return -ENOMEM ; +debugfs_create_file ("hw-queues" ,0400 , dir, phy, + &mt7996_hw_queues_fops); +debugfs_create_file ("xmit-queues" ,0400 , dir, phy, + &mt7996_xmit_queues_fops); +debugfs_create_file ("tx_stats" ,0400 , dir, phy, &mt7996_tx_stats_fops); +debugfs_create_file ("fw_debug_wm" ,0600 , dir, dev, &fops_fw_debug_wm); +debugfs_create_file ("fw_debug_wa" ,0600 , dir, dev, &fops_fw_debug_wa); +debugfs_create_file ("fw_debug_bin" ,0600 , dir, dev, &fops_fw_debug_bin); +/* TODO: wm fw cpu utilization */ +debugfs_create_file ("fw_util_wa" ,0400 , dir, dev, + &mt7996_fw_util_wa_fops); +debugfs_create_file ("implicit_txbf" ,0600 , dir, dev, + &fops_implicit_txbf); +debugfs_create_devm_seqfile (dev->mt76.dev,"twt_stats" , dir, + mt7996_twt_stats); +debugfs_create_file ("fw_ser" ,0600 , dir, phy, &mt7996_fw_ser_ops); +debugfs_create_file ("rf_regval" ,0600 , dir, dev, &fops_rf_regval); + +if (phy->mt76->cap.has_5ghz) { +debugfs_create_u32 ("dfs_hw_pattern" ,0400 , dir, + &dev->hw_pattern); +debugfs_create_file ("radar_trigger" ,0200 , dir, dev, + &fops_radar_trigger); +debugfs_create_devm_seqfile (dev->mt76.dev,"rdd_monitor" , dir, + mt7996_rdd_monitor); + } + +if (phy == &dev->phy) + dev->debugfs_dir = dir; + +return 0 ; +} + +static void +mt7996_debugfs_write_fwlog (struct mt7996_dev *dev,const void *hdr,int hdrlen, +const void *data,int len) +{ +static DEFINE_SPINLOCK (lock); +unsigned long flags; +void *dest; + +spin_lock_irqsave (&lock, flags); + dest =relay_reserve (dev->relay_fwlog, hdrlen + len +4 ); +if (dest) { + *(u32 *)dest = hdrlen + len; + dest +=4 ; + +if (hdrlen) { +memcpy (dest, hdr, hdrlen); + dest += hdrlen; + } + +memcpy (dest, data, len); +relay_flush (dev->relay_fwlog); + } +spin_unlock_irqrestore (&lock, flags); +} + +void mt7996_debugfs_rx_fw_monitor (struct mt7996_dev *dev,const void *data,int len) +{ +struct { +__le32 magic; +u8 version; +u8 _rsv; +__le16 serial_id; +__le32 timestamp; +__le16 msg_type; +__le16 len; + } hdr = { + .version =0x1 , + .magic =cpu_to_le32 (FW_BIN_LOG_MAGIC ), + .msg_type =cpu_to_le16 (PKT_TYPE_RX_FW_MONITOR ), + }; + +if (!dev->relay_fwlog) +return ; + + hdr.serial_id =cpu_to_le16 (dev->fw_debug_seq++); + hdr.timestamp =cpu_to_le32 (mt76_rr (dev,MT_LPON_FRCR (0 ))); + hdr.len = *(__le16 *)data; +mt7996_debugfs_write_fwlog (dev, &hdr,sizeof (hdr), data, len); +} + +bool mt7996_debugfs_rx_log (struct mt7996_dev *dev,const void *data,int len) +{ +if (get_unaligned_le32 (data) !=FW_BIN_LOG_MAGIC ) +return false; + +if (dev->relay_fwlog) +mt7996_debugfs_write_fwlog (dev,NULL ,0 , data, len); + +return true; +} + +#ifdef CONFIG_MAC80211_DEBUGFS +/** per-station debugfs **/ + +static ssize_t mt7996_sta_fixed_rate_set (struct file *file, +const char __user *user_buf, +size_t count,loff_t *ppos) +{ +#define SHORT_PREAMBLE 0 +#define LONG_PREAMBLE 1 +struct ieee80211_sta *sta = file->private_data; +struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; +struct mt7996_dev *dev = msta->vif->phy->dev; +struct ra_rate phy = {}; +char buf[100 ]; +int ret; +u16 gi, ltf; + +if (count >=sizeof (buf)) +return -EINVAL ; + +if (copy_from_user (buf, user_buf, count)) +return -EFAULT ; + +if (count && buf[count -1 ] =='\n' ) + buf[count -1 ] ='\0' ; +else + buf[count] ='\0' ; + +/* mode - cck: 0, ofdm: 1, ht: 2, gf: 3, vht: 4, he_su: 8, he_er: 9 +* bw - bw20: 0, bw40: 1, bw80: 2, bw160: 3 +* nss - vht: 1~4, he: 1~4, others: ignore +* mcs - cck: 0~4, ofdm: 0~7, ht: 0~32, vht: 0~9, he_su: 0~11, he_er: 0~2 +* gi - (ht/vht) lgi: 0, sgi: 1; (he) 0.8us: 0, 1.6us: 1, 3.2us: 2 +* preamble - short: 1, long: 0 +* ldpc - off: 0, on: 1 +* stbc - off: 0, on: 1 +* ltf - 1xltf: 0, 2xltf: 1, 4xltf: 2 +*/ +if (sscanf (buf,"%hhu %hhu %hhu %hhu %hu %hhu %hhu %hhu %hhu %hu" , + &phy.mode, &phy.bw, &phy.mcs, &phy.nss, &gi, + &phy.preamble, &phy.stbc, &phy.ldpc, &phy.spe, <f) !=10 ) { +dev_warn (dev->mt76.dev, +"format: Mode BW MCS NSS GI Preamble STBC LDPC SPE ltf\n" ); + goto out; + } + + phy.wlan_idx =cpu_to_le16 (msta->wcid.idx); + phy.gi =cpu_to_le16 (gi); + phy.ltf =cpu_to_le16 (ltf); + phy.ldpc = phy.ldpc ?7 :0 ; + phy.preamble = phy.preamble ?SHORT_PREAMBLE :LONG_PREAMBLE ; + + ret =mt7996_mcu_set_fixed_rate_ctrl (dev, &phy,0 ); +if (ret) +return -EFAULT ; + +out: +return count; +} + +static const struct file_operations fops_fixed_rate = { + .write = mt7996_sta_fixed_rate_set, + .open = simple_open, + .owner =THIS_MODULE , + .llseek = default_llseek, +}; + +static int +mt7996_queues_show (struct seq_file *s,void *data) +{ +struct ieee80211_sta *sta = s->private; + +mt7996_sta_hw_queue_read (s, sta); + +return 0 ; +} + +DEFINE_SHOW_ATTRIBUTE (mt7996_queues); + +void mt7996_sta_add_debugfs (struct ieee80211_hw *hw,struct ieee80211_vif *vif, +struct ieee80211_sta *sta,struct dentry *dir) +{ +debugfs_create_file ("fixed_rate" ,0600 , dir, sta, &fops_fixed_rate); +debugfs_create_file ("hw-queues" ,0400 , dir, sta, &mt7996_queues_fops); +} + +#endif
Signature · 1 line
2.25.1
Shayne Chen
reviewerPATCH 8/9 wifi: mt76: mt7996: add module support
In reply to Shayne Chen(Split the big patch into smaller intermediate patches by functionality for easier review. Refer to the cover letter for more info.)
--- drivers/net/wireless/mediatek/mt76/mt7996/Kconfig | 12 ++++++++++++ drivers/net/wireless/mediatek/mt76/mt7996/Makefile | 6 ++++++ 2 files changed, 18 insertions(+) create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/Kconfig create mode 100644 drivers/net/wireless/mediatek/mt76/mt7996/Makefile
drivers/net/wireless/mediatek/mt76/mt7996/Kconfig new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: ISC +config MT7996E + tristate "MediaTek MT7996 (PCIe) support" + select MT76_CONNAC_LIB + depends on MAC80211 + depends on PCI + help + This adds support for MT7996-based wireless PCIe devices, + which support concurrent tri-band operation at 6GHz, 5GHz, + and 2.4GHz IEEE 802.11be 4x4:4SS 4096-QAM, 320MHz channels. + + To compile this driver as a module, choose M here.
drivers/net/wireless/mediatek/mt76/mt7996/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: ISC + +obj-$(CONFIG_MT7996E) += mt7996e.o + +mt7996e-y := pci.o init.o dma.o eeprom.o main.o mcu.o mac.o \ + debugfs.o mmio.o
Signature · 1 line
2.25.1
Shayne Chen
reviewerPATCH 9/9 wifi: mt76: add mt7996 module support
In reply to Shayne Chen(Split the big patch into smaller intermediate patches by functionality for easier review. Refer to the cover letter for more info.)
--- drivers/net/wireless/mediatek/mt76/Kconfig | 1 + drivers/net/wireless/mediatek/mt76/Makefile | 1 + 2 files changed, 2 insertions(+)
drivers/net/wireless/mediatek/mt76/Kconfig +1 -0
@@ -34,3 +34,4 @@ source "drivers/net/wireless/mediatek/mt76/mt7603/Kconfig" source "drivers/net/wireless/mediatek/mt76/mt7615/Kconfig" source "drivers/net/wireless/mediatek/mt76/mt7915/Kconfig" source "drivers/net/wireless/mediatek/mt76/mt7921/Kconfig" +source "drivers/net/wireless/mediatek/mt76/mt7996/Kconfig"
drivers/net/wireless/mediatek/mt76/Makefile +1 -0
@@ -35,3 +35,4 @@ obj-$(CONFIG_MT7603E) += mt7603/ obj-$(CONFIG_MT7615_COMMON) += mt7615/ obj-$(CONFIG_MT7915E) += mt7915/ obj-$(CONFIG_MT7921_COMMON) += mt7921/ +obj-$(CONFIG_MT7996E) += mt7996/
Signature · 1 line
2.25.1
Quoted 26 lines · Shayne Chen
Add MediaTek new mac80211 driver mt7996 for Wi-Fi 7 (802.11be) devices. The driver first supports Filogic 680 PCI device, which is a Wi-Fi 7 chipset supporting concurrent tri-band operation at 6 GHz, 5 GHz, and 2.4 GHz with 4x4 antennas on each band.
Currently, mt7996 only supports tri-band HE or older mode. EHT mode and more variants of Filogic 680 support will be introduced in further patches.
Reviewed-by Ryder Lee <[email protected]>Co-developed-by Peter Chiu <[email protected]>Signed-off-by Peter Chiu <[email protected]>Co-developed-by Bo Jiao <[email protected]>Signed-off-by Bo Jiao <[email protected]>Co-developed-by Howard Hsu <[email protected]>Signed-off-by Howard Hsu <[email protected]>Co-developed-by MeiChia Chiu <[email protected]>Signed-off-by MeiChia Chiu <[email protected]>Co-developed-by StanleyYP Wang <[email protected]>Signed-off-by StanleyYP Wang <[email protected]>Co-developed-by Money Wang <[email protected]>Signed-off-by Money Wang <[email protected]>Co-developed-by Evelyn Tsai <[email protected]>Signed-off-by Evelyn Tsai <[email protected]>Signed-off-by Shayne Chen <[email protected]>
Quoted 8 lines
----------------[commit message cut here]----------------
This series is based on the following series with fixes folded:
- https://patchwork.kernel.org/project/linux-wireless/cover/[email protected]/For easier review, the big patch has been splitted into multiple patches per functionality. These patches will be folded into a single patch in the final version.
I wish you had split the patches per file like I asked, it makes reviewing a new driver so much easier. Reviewing is hard, please always take us reviewers into consideration when submitting patches.
No need to resend because of this, but I am grumpy.
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Shayne Chen (陳軒丞)
reviewerQuoted 45 lines · Kalle Valo
Quoted 37 lines · Shayne Chen
Add MediaTek new mac80211 driver mt7996 for Wi-Fi 7 (802.11be) devices.
The driver first supports Filogic 680 PCI device, which is a Wi-Fi 7
chipset supporting concurrent tri-band operation at 6 GHz, 5 GHz, and
2.4 GHz with 4x4 antennas on each band.Currently, mt7996 only supports tri-band HE or older mode. EHT mode and more variants of Filogic 680 support will be introduced
in further patches.Reviewed-by Ryder Lee <[email protected]>Co-developed-by Peter Chiu <[email protected]>Signed-off-by Peter Chiu <[email protected]>Co-developed-by Bo Jiao <[email protected]>Signed-off-by Bo Jiao <[email protected]>Co-developed-by Howard Hsu <[email protected]>Signed-off-by Howard Hsu <[email protected]>Co-developed-by MeiChia Chiu <[email protected]>Signed-off-by MeiChia Chiu <[email protected]>Co-developed-by StanleyYP Wang <[email protected]>Signed-off-by StanleyYP Wang <[email protected]>Co-developed-by Money Wang <[email protected]>Signed-off-by Money Wang <[email protected]>Co-developed-by Evelyn Tsai <[email protected]>Signed-off-by Evelyn Tsai <[email protected]>Signed-off-by Shayne Chen <[email protected]>----------------[commit message cut here]----------------
This series is based on the following series with fixes folded:
-
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-wireless/cover/[email protected]/__;!!CTRNKA9wMg0ARbw!3dab74MyEsbcnl1X5kv2N1RQlZiDfg9P-YL_3d_opTcmOs5bGdWoc91z1QGJgr8wg6g$Quoted 5 lines
For easier review, the big patch has been splitted into multiple patches
per functionality. These patches will be folded into a single patch in
the final version.
Quoted 7 lines
I wish you had split the patches per file like I asked, it makes reviewing a new driver so much easier. Reviewing is hard, please always
take us reviewers into consideration when submitting patches.No need to resend because of this, but I am grumpy.
Hi Kalle,
I am sorry for any inconvenience caused.
Will keep this in mind when upstreaming a new driver next time.
Thanks,
Shayne