drivers/net/wireless/mediatek/mt76/mt7921/testmode.c
Source file repositories/reference/linux-study-clean/drivers/net/wireless/mediatek/mt76/mt7921/testmode.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/wireless/mediatek/mt76/mt7921/testmode.c- Extension
.c- Size
- 4382 bytes
- Lines
- 197
- 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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
mt7921.hmcu.h
Detected Declarations
struct mt7921_tm_cmdstruct mt7921_tm_evtenum mt7921_testmode_attrfunction mt7921_tm_setfunction mt7921_tm_queryfunction mt7921_testmode_cmdfunction mt7921_testmode_dump
Annotated Snippet
struct mt7921_tm_cmd {
u8 action;
u32 param0;
u32 param1;
};
struct mt7921_tm_evt {
u32 param0;
u32 param1;
};
static const struct nla_policy mt7921_tm_policy[NUM_MT7921_TM_ATTRS] = {
[MT7921_TM_ATTR_SET] = NLA_POLICY_EXACT_LEN(sizeof(struct mt7921_tm_cmd)),
[MT7921_TM_ATTR_QUERY] = NLA_POLICY_EXACT_LEN(sizeof(struct mt7921_tm_cmd)),
};
static int
mt7921_tm_set(struct mt792x_dev *dev, struct mt7921_tm_cmd *req)
{
struct mt7921_rftest_cmd cmd = {
.action = req->action,
.param0 = cpu_to_le32(req->param0),
.param1 = cpu_to_le32(req->param1),
};
bool testmode = false, normal = false;
struct mt76_connac_pm *pm = &dev->pm;
struct mt76_phy *phy = &dev->mphy;
int ret = -ENOTCONN;
mutex_lock(&dev->mt76.mutex);
if (req->action == TM_SWITCH_MODE) {
if (req->param0 == MT7921_TM_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_CE_CMD(TEST_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
mt7921_tm_query(struct mt792x_dev *dev, struct mt7921_tm_cmd *req,
struct mt7921_tm_evt *evt_resp)
{
struct mt7921_rftest_cmd cmd = {
.action = req->action,
.param0 = cpu_to_le32(req->param0),
.param1 = cpu_to_le32(req->param1),
};
struct mt7921_rftest_evt *evt;
struct sk_buff *skb;
int ret;
ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_CE_CMD(TEST_CTRL),
&cmd, sizeof(cmd), true, &skb);
if (ret)
goto out;
evt = (struct mt7921_rftest_evt *)skb->data;
evt_resp->param0 = le32_to_cpu(evt->param0);
evt_resp->param1 = le32_to_cpu(evt->param1);
out:
dev_kfree_skb(skb);
Annotation
- Immediate include surface: `mt7921.h`, `mcu.h`.
- Detected declarations: `struct mt7921_tm_cmd`, `struct mt7921_tm_evt`, `enum mt7921_testmode_attr`, `function mt7921_tm_set`, `function mt7921_tm_query`, `function mt7921_testmode_cmd`, `function mt7921_testmode_dump`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.