Commit 16d98b54 authored by Sean Wang's avatar Sean Wang Committed by Felix Fietkau
Browse files

mt76: mt7921: rely on mcu_get_nic_capability



Rely on mcu_get_nic_capability to obtain Tx quota information
for the SDIO device, get PHY capability, MAC address and then we can
totally drop mt7921/eeprom.c and any unnecessary code.

Noting that mt76_connac_mcu_get_nic_capability should be run before set
flag MT76_STATE_MCU_RUNNING being set to setup the proper parameters
like Tx quota control before the device is started to running.

Tested-by: default avatarDeren Wu <deren.wu@mediatek.com>
Acked-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarSean Wang <sean.wang@mediatek.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 8c94f0e6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ static int mt7663s_mcu_init_sched(struct mt7615_dev *dev)
						   MT_HIF1_MIN_QUOTA);
	sdio->sched.ple_data_quota = mt76_get_field(dev, MT_PLE_PG_HIF0_GROUP,
						    MT_HIF0_MIN_QUOTA);
	sdio->sched.pse_page_size = MT_PSE_PAGE_SZ;
	txdwcnt = mt76_get_field(dev, MT_PP_TXDWCNT,
				 MT_PP_TXDWCNT_TX1_ADD_DW_CNT);
	sdio->sched.deficit = txdwcnt << 2;
+1 −1
Original line number Diff line number Diff line
@@ -5,6 +5,6 @@ obj-$(CONFIG_MT7921E) += mt7921e.o

CFLAGS_trace.o := -I$(src)

mt7921-common-y := mac.o mcu.o eeprom.o main.o init.o debugfs.o trace.o
mt7921-common-y := mac.o mcu.o main.o init.o debugfs.o trace.o
mt7921-common-$(CONFIG_NL80211_TESTMODE) += testmode.o
mt7921e-y := pci.o pci_mac.o pci_mcu.o dma.o
+0 −101
Original line number Diff line number Diff line
// SPDX-License-Identifier: ISC
/* Copyright (C) 2020 MediaTek Inc. */

#include "mt7921.h"
#include "eeprom.h"

static u32 mt7921_eeprom_read(struct mt7921_dev *dev, u32 offset)
{
	u8 *data = dev->mt76.eeprom.data;

	if (data[offset] == 0xff)
		mt7921_mcu_get_eeprom(dev, offset);

	return data[offset];
}

static int mt7921_eeprom_load(struct mt7921_dev *dev)
{
	int ret;

	ret = mt76_eeprom_init(&dev->mt76, MT7921_EEPROM_SIZE);
	if (ret < 0)
		return ret;

	memset(dev->mt76.eeprom.data, -1, MT7921_EEPROM_SIZE);

	return 0;
}

static int mt7921_check_eeprom(struct mt7921_dev *dev)
{
	u8 *eeprom = dev->mt76.eeprom.data;
	u16 val;

	mt7921_eeprom_read(dev, MT_EE_CHIP_ID);
	val = get_unaligned_le16(eeprom);

	switch (val) {
	case 0x7922:
	case 0x7961:
		return 0;
	default:
		return -EINVAL;
	}
}

void mt7921_eeprom_parse_band_config(struct mt7921_phy *phy)
{
	struct mt7921_dev *dev = phy->dev;
	u32 val;

	val = mt7921_eeprom_read(dev, MT_EE_WIFI_CONF);
	val = FIELD_GET(MT_EE_WIFI_CONF_BAND_SEL, val);

	switch (val) {
	case MT_EE_5GHZ:
		phy->mt76->cap.has_5ghz = true;
		break;
	case MT_EE_2GHZ:
		phy->mt76->cap.has_2ghz = true;
		break;
	default:
		phy->mt76->cap.has_2ghz = true;
		phy->mt76->cap.has_5ghz = true;
		break;
	}
}

static void mt7921_eeprom_parse_hw_cap(struct mt7921_dev *dev)
{
	u8 tx_mask;

	mt7921_eeprom_parse_band_config(&dev->phy);

	/* TODO: read NSS with MCU_CMD_NIC_CAPV2 */
	tx_mask = 2;
	dev->chainmask = BIT(tx_mask) - 1;
	dev->mphy.antenna_mask = dev->chainmask;
	dev->mphy.chainmask = dev->mphy.antenna_mask;
}

int mt7921_eeprom_init(struct mt7921_dev *dev)
{
	int ret;

	ret = mt7921_eeprom_load(dev);
	if (ret < 0)
		return ret;

	ret = mt7921_check_eeprom(dev);
	if (ret)
		return ret;

	mt7921_eeprom_parse_hw_cap(dev);
	memcpy(dev->mphy.macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR,
	       ETH_ALEN);

	mt76_eeprom_override(&dev->mphy);

	return 0;
}
+1 −9
Original line number Diff line number Diff line
@@ -149,7 +149,6 @@ EXPORT_SYMBOL_GPL(mt7921_mac_init);

static int __mt7921_init_hardware(struct mt7921_dev *dev)
{
	struct mt76_dev *mdev = &dev->mt76;
	int ret;

	/* force firmware operation mode into normal state,
@@ -160,9 +159,7 @@ static int __mt7921_init_hardware(struct mt7921_dev *dev)
	if (ret)
		goto out;

	ret = mt7921_eeprom_init(dev);
	if (ret)
		goto out;
	mt76_eeprom_override(&dev->mphy);

	ret = mt7921_mcu_set_eeprom(dev);
	if (ret)
@@ -170,11 +167,6 @@ static int __mt7921_init_hardware(struct mt7921_dev *dev)

	ret = mt7921_mac_init(dev);
out:
	if (ret && mdev->eeprom.data) {
		devm_kfree(mdev->dev, mdev->eeprom.data);
		mdev->eeprom.data = NULL;
	}

	return ret;
}

+5 −3
Original line number Diff line number Diff line
@@ -906,10 +906,12 @@ int mt7921_run_firmware(struct mt7921_dev *dev)
	if (err)
		return err;

	set_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state);
	mt7921_mcu_fw_log_2_host(dev, 1);
	err = mt76_connac_mcu_get_nic_capability(&dev->mphy);
	if (err)
		return err;

	return mt76_connac_mcu_get_nic_capability(&dev->mphy);
	set_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state);
	return mt7921_mcu_fw_log_2_host(dev, 1);
}
EXPORT_SYMBOL_GPL(mt7921_run_firmware);

Loading