drivers/net/wireless/mediatek/mt76/mt7925/testmode.c

Source file repositories/reference/linux-study-clean/drivers/net/wireless/mediatek/mt76/mt7925/testmode.c

File Facts

System
Linux kernel
Corpus path
drivers/net/wireless/mediatek/mt76/mt7925/testmode.c
Extension
.c
Size
4780 bytes
Lines
207
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct mt7925_tm_cmd {
	u8 padding[4];
	struct uni_cmd_testmode_ctrl c;
} __packed;

struct mt7925_tm_evt {
	u32 param0;
	u32 param1;
} __packed;

static const struct nla_policy mt7925_tm_policy[NUM_MT7925_TM_ATTRS] = {
	[MT7925_TM_ATTR_SET] = NLA_POLICY_EXACT_LEN(sizeof(struct mt7925_tm_cmd)),
	[MT7925_TM_ATTR_QUERY] = NLA_POLICY_EXACT_LEN(sizeof(struct mt7925_tm_cmd)),
};

static int
mt7925_tm_set(struct mt792x_dev *dev, struct mt7925_tm_cmd *req)
{
	struct mt7925_rftest_cmd cmd;
	struct mt7925_rftest_cmd *pcmd = &cmd;
	bool testmode = false, normal = false;
	struct mt76_connac_pm *pm = &dev->pm;
	struct mt76_phy *phy = &dev->mphy;
	int ret = -ENOTCONN;

	memset(pcmd, 0, sizeof(*pcmd));
	memcpy(pcmd, req, sizeof(struct mt7925_tm_cmd));

	mutex_lock(&dev->mt76.mutex);

	if (pcmd->ctrl.action == CMD_TEST_CTRL_ACT_SWITCH_MODE) {
		if (pcmd->ctrl.data.op_mode == CMD_TEST_CTRL_ACT_SWITCH_MODE_NORMAL)
			normal = true;
		else
			testmode = true;
	}

	if (testmode) {
		/* Make sure testmode running on full power mode */
		pm->enable = false;
		cancel_delayed_work_sync(&pm->ps_work);
		cancel_work_sync(&pm->wake_work);
		__mt792x_mcu_drv_pmctrl(dev);

		phy->test.state = MT76_TM_STATE_ON;
	}

	if (!mt76_testmode_enabled(phy))
		goto out;

	ret = mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(TESTMODE_CTRL), &cmd,
				sizeof(cmd), false);

	if (ret)
		goto out;

	if (normal) {
		/* Switch back to the normal world */
		phy->test.state = MT76_TM_STATE_OFF;
		pm->enable = true;
	}
out:
	mutex_unlock(&dev->mt76.mutex);

	return ret;
}

static int
mt7925_tm_query(struct mt792x_dev *dev, struct mt7925_tm_cmd *req,
		char *evt_resp)
{
	struct mt7925_rftest_cmd cmd;
	char *pcmd = (char *)&cmd;
	struct sk_buff *skb = NULL;
	int ret = 1;

	memset(pcmd, 0, sizeof(*pcmd));
	memcpy(pcmd + 4, (char *)&req->c, sizeof(struct uni_cmd_testmode_ctrl));

	if (*((uint16_t *)req->padding) == MCU_UNI_CMD_TESTMODE_CTRL)
		ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_UNI_QUERY(TESTMODE_CTRL),
						&cmd, sizeof(cmd), true, &skb);
	else if (*((uint16_t *)req->padding) == MCU_UNI_CMD_TESTMODE_RX_STAT)
		ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_UNI_QUERY(TESTMODE_RX_STAT),
						&cmd, sizeof(cmd), true, &skb);

	if (ret)
		goto out;

	if (skb->len < MT7925_EVT_RSP_LEN + 8) {

Annotation

Implementation Notes