Commit e6d2070d authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: connac: introduce MCU_EXT macros

Introduce MCU_EXT_CMD and MCU_EXT_QUERY macros in mt76_connac module.
This is a preliminary patch to reuse mt76_connac module in mt7915
driver.
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent e0bf699a
...@@ -73,7 +73,7 @@ static int mt7615_start(struct ieee80211_hw *hw) ...@@ -73,7 +73,7 @@ static int mt7615_start(struct ieee80211_hw *hw)
goto out; goto out;
} }
ret = mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD_SET_RX_PATH); ret = mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
if (ret) if (ret)
goto out; goto out;
...@@ -326,7 +326,7 @@ int mt7615_set_channel(struct mt7615_phy *phy) ...@@ -326,7 +326,7 @@ int mt7615_set_channel(struct mt7615_phy *phy)
goto out; goto out;
} }
ret = mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD_CHANNEL_SWITCH); ret = mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD(CHANNEL_SWITCH));
if (ret) if (ret)
goto out; goto out;
......
...@@ -91,7 +91,7 @@ mt7615_tm_set_tx_power(struct mt7615_phy *phy) ...@@ -91,7 +91,7 @@ mt7615_tm_set_tx_power(struct mt7615_phy *phy)
} }
return mt76_mcu_skb_send_msg(&dev->mt76, skb, return mt76_mcu_skb_send_msg(&dev->mt76, skb,
MCU_EXT_CMD_SET_TX_POWER_CTRL, false); MCU_EXT_CMD(SET_TX_POWER_CTRL), false);
} }
static void static void
...@@ -228,7 +228,7 @@ mt7615_tm_set_tx_frames(struct mt7615_phy *phy, bool en) ...@@ -228,7 +228,7 @@ mt7615_tm_set_tx_frames(struct mt7615_phy *phy, bool en)
struct ieee80211_tx_info *info; struct ieee80211_tx_info *info;
struct sk_buff *skb = phy->mt76->test.tx_skb; struct sk_buff *skb = phy->mt76->test.tx_skb;
mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD_SET_RX_PATH); mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
mt7615_tm_set_tx_antenna(phy, en); mt7615_tm_set_tx_antenna(phy, en);
mt7615_tm_set_rx_enable(dev, !en); mt7615_tm_set_rx_enable(dev, !en);
if (!en || !skb) if (!en || !skb)
......
...@@ -176,7 +176,7 @@ int mt76_connac_mcu_set_mac_enable(struct mt76_dev *dev, int band, bool enable, ...@@ -176,7 +176,7 @@ int mt76_connac_mcu_set_mac_enable(struct mt76_dev *dev, int band, bool enable,
.band = band, .band = band,
}; };
return mt76_mcu_send_msg(dev, MCU_EXT_CMD_MAC_INIT_CTRL, &req_mac, return mt76_mcu_send_msg(dev, MCU_EXT_CMD(MAC_INIT_CTRL), &req_mac,
sizeof(req_mac), true); sizeof(req_mac), true);
} }
EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_mac_enable); EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_mac_enable);
...@@ -218,7 +218,7 @@ int mt76_connac_mcu_set_rts_thresh(struct mt76_dev *dev, u32 val, u8 band) ...@@ -218,7 +218,7 @@ int mt76_connac_mcu_set_rts_thresh(struct mt76_dev *dev, u32 val, u8 band)
.pkt_thresh = cpu_to_le32(0x2), .pkt_thresh = cpu_to_le32(0x2),
}; };
return mt76_mcu_send_msg(dev, MCU_EXT_CMD_PROTECT_CTRL, &req, return mt76_mcu_send_msg(dev, MCU_EXT_CMD(PROTECT_CTRL), &req,
sizeof(req), true); sizeof(req), true);
} }
EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_rts_thresh); EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_rts_thresh);
......
...@@ -500,11 +500,19 @@ enum { ...@@ -500,11 +500,19 @@ enum {
#define MCU_FW_PREFIX BIT(31) #define MCU_FW_PREFIX BIT(31)
#define MCU_UNI_PREFIX BIT(30) #define MCU_UNI_PREFIX BIT(30)
#define MCU_CE_PREFIX BIT(29) #define MCU_CE_PREFIX BIT(29)
#define MCU_QUERY_PREFIX BIT(28)
#define MCU_CMD_MASK ~(MCU_FW_PREFIX | MCU_UNI_PREFIX | \ #define MCU_CMD_MASK ~(MCU_FW_PREFIX | MCU_UNI_PREFIX | \
MCU_CE_PREFIX | MCU_QUERY_PREFIX) MCU_CE_PREFIX)
#define MCU_QUERY_MASK BIT(16) #define __MCU_CMD_FIELD_ID GENMASK(7, 0)
#define __MCU_CMD_FIELD_EXT_ID GENMASK(15, 8)
#define __MCU_CMD_FIELD_QUERY BIT(16)
#define MCU_CMD(_t) FIELD_PREP(__MCU_CMD_FIELD_ID, \
MCU_CMD_##_t)
#define MCU_EXT_CMD(_t) (MCU_CMD(EXT_CID) | \
FIELD_PREP(__MCU_CMD_FIELD_EXT_ID, \
MCU_EXT_CMD_##_t))
#define MCU_EXT_QUERY(_t) (MCU_EXT_CMD(_t) | __MCU_CMD_FIELD_QUERY)
enum { enum {
MCU_EXT_CMD_EFUSE_ACCESS = 0x01, MCU_EXT_CMD_EFUSE_ACCESS = 0x01,
...@@ -576,7 +584,7 @@ enum { ...@@ -576,7 +584,7 @@ enum {
MCU_CMD_GET_NIC_CAPAB = MCU_CE_PREFIX | 0x8a, MCU_CMD_GET_NIC_CAPAB = MCU_CE_PREFIX | 0x8a,
MCU_CMD_SET_MU_EDCA_PARMS = MCU_CE_PREFIX | 0xb0, MCU_CMD_SET_MU_EDCA_PARMS = MCU_CE_PREFIX | 0xb0,
MCU_CMD_REG_WRITE = MCU_CE_PREFIX | 0xc0, MCU_CMD_REG_WRITE = MCU_CE_PREFIX | 0xc0,
MCU_CMD_REG_READ = MCU_CE_PREFIX | MCU_QUERY_MASK | 0xc0, MCU_CMD_REG_READ = MCU_CE_PREFIX | __MCU_CMD_FIELD_QUERY | 0xc0,
MCU_CMD_CHIP_CONFIG = MCU_CE_PREFIX | 0xca, MCU_CMD_CHIP_CONFIG = MCU_CE_PREFIX | 0xca,
MCU_CMD_FWLOG_2_HOST = MCU_CE_PREFIX | 0xc5, MCU_CMD_FWLOG_2_HOST = MCU_CE_PREFIX | 0xc5,
MCU_CMD_GET_WTBL = MCU_CE_PREFIX | 0xcd, MCU_CMD_GET_WTBL = MCU_CE_PREFIX | 0xcd,
......
...@@ -233,7 +233,7 @@ int __mt7921_start(struct mt7921_phy *phy) ...@@ -233,7 +233,7 @@ int __mt7921_start(struct mt7921_phy *phy)
if (err) if (err)
return err; return err;
err = mt7921_mcu_set_chan_info(phy, MCU_EXT_CMD_SET_RX_PATH); err = mt7921_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
if (err) if (err)
return err; return err;
...@@ -375,7 +375,7 @@ static int mt7921_set_channel(struct mt7921_phy *phy) ...@@ -375,7 +375,7 @@ static int mt7921_set_channel(struct mt7921_phy *phy)
mt76_set_channel(phy->mt76); mt76_set_channel(phy->mt76);
ret = mt7921_mcu_set_chan_info(phy, MCU_EXT_CMD_CHANNEL_SWITCH); ret = mt7921_mcu_set_chan_info(phy, MCU_EXT_CMD(CHANNEL_SWITCH));
if (ret) if (ret)
goto out; goto out;
......
...@@ -179,24 +179,20 @@ int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd, ...@@ -179,24 +179,20 @@ int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd,
if (seq != rxd->seq) if (seq != rxd->seq)
return -EAGAIN; return -EAGAIN;
switch (cmd) { if (cmd == MCU_CMD_PATCH_SEM_CONTROL) {
case MCU_CMD_PATCH_SEM_CONTROL:
skb_pull(skb, sizeof(*rxd) - 4); skb_pull(skb, sizeof(*rxd) - 4);
ret = *skb->data; ret = *skb->data;
break; } else if (cmd == MCU_EXT_CMD(GET_TEMP)) {
case MCU_EXT_CMD_GET_TEMP:
skb_pull(skb, sizeof(*rxd) + 4); skb_pull(skb, sizeof(*rxd) + 4);
ret = le32_to_cpu(*(__le32 *)skb->data); ret = le32_to_cpu(*(__le32 *)skb->data);
break; } else if (cmd == MCU_EXT_CMD(EFUSE_ACCESS)) {
case MCU_EXT_CMD_EFUSE_ACCESS:
ret = mt7921_mcu_parse_eeprom(mdev, skb); ret = mt7921_mcu_parse_eeprom(mdev, skb);
break; } else if (cmd == MCU_UNI_CMD_DEV_INFO_UPDATE ||
case MCU_UNI_CMD_DEV_INFO_UPDATE: cmd == MCU_UNI_CMD_BSS_INFO_UPDATE ||
case MCU_UNI_CMD_BSS_INFO_UPDATE: cmd == MCU_UNI_CMD_STA_REC_UPDATE ||
case MCU_UNI_CMD_STA_REC_UPDATE: cmd == MCU_UNI_CMD_HIF_CTRL ||
case MCU_UNI_CMD_HIF_CTRL: cmd == MCU_UNI_CMD_OFFLOAD ||
case MCU_UNI_CMD_OFFLOAD: cmd == MCU_UNI_CMD_SUSPEND) {
case MCU_UNI_CMD_SUSPEND: {
struct mt7921_mcu_uni_event *event; struct mt7921_mcu_uni_event *event;
skb_pull(skb, sizeof(*rxd)); skb_pull(skb, sizeof(*rxd));
...@@ -205,19 +201,14 @@ int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd, ...@@ -205,19 +201,14 @@ int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd,
/* skip invalid event */ /* skip invalid event */
if (mcu_cmd != event->cid) if (mcu_cmd != event->cid)
ret = -EAGAIN; ret = -EAGAIN;
break; } else if (cmd == MCU_CMD_REG_READ) {
}
case MCU_CMD_REG_READ: {
struct mt7921_mcu_reg_event *event; struct mt7921_mcu_reg_event *event;
skb_pull(skb, sizeof(*rxd)); skb_pull(skb, sizeof(*rxd));
event = (struct mt7921_mcu_reg_event *)skb->data; event = (struct mt7921_mcu_reg_event *)skb->data;
ret = (int)le32_to_cpu(event->val); ret = (int)le32_to_cpu(event->val);
break; } else {
}
default:
skb_pull(skb, sizeof(struct mt7921_mcu_rxd)); skb_pull(skb, sizeof(struct mt7921_mcu_rxd));
break;
} }
return ret; return ret;
...@@ -228,7 +219,7 @@ int mt7921_mcu_fill_message(struct mt76_dev *mdev, struct sk_buff *skb, ...@@ -228,7 +219,7 @@ int mt7921_mcu_fill_message(struct mt76_dev *mdev, struct sk_buff *skb,
int cmd, int *wait_seq) int cmd, int *wait_seq)
{ {
struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76); struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76);
int txd_len, mcu_cmd = cmd & MCU_CMD_MASK; int txd_len, mcu_cmd = FIELD_GET(__MCU_CMD_FIELD_ID, cmd);
struct mt7921_uni_txd *uni_txd; struct mt7921_uni_txd *uni_txd;
struct mt7921_mcu_txd *mcu_txd; struct mt7921_mcu_txd *mcu_txd;
__le32 *txd; __le32 *txd;
...@@ -283,34 +274,20 @@ int mt7921_mcu_fill_message(struct mt76_dev *mdev, struct sk_buff *skb, ...@@ -283,34 +274,20 @@ int mt7921_mcu_fill_message(struct mt76_dev *mdev, struct sk_buff *skb,
MT_TX_MCU_PORT_RX_Q0)); MT_TX_MCU_PORT_RX_Q0));
mcu_txd->pkt_type = MCU_PKT_ID; mcu_txd->pkt_type = MCU_PKT_ID;
mcu_txd->seq = seq; mcu_txd->seq = seq;
mcu_txd->cid = mcu_cmd;
mcu_txd->s2d_index = MCU_S2D_H2N;
mcu_txd->ext_cid = FIELD_GET(__MCU_CMD_FIELD_EXT_ID, cmd);
switch (cmd & ~MCU_CMD_MASK) { if (mcu_txd->ext_cid || (cmd & MCU_CE_PREFIX)) {
case MCU_FW_PREFIX: if (cmd & __MCU_CMD_FIELD_QUERY)
mcu_txd->set_query = MCU_Q_NA;
mcu_txd->cid = mcu_cmd;
break;
case MCU_CE_PREFIX:
if (cmd & MCU_QUERY_MASK)
mcu_txd->set_query = MCU_Q_QUERY;
else
mcu_txd->set_query = MCU_Q_SET;
mcu_txd->cid = mcu_cmd;
break;
default:
mcu_txd->cid = MCU_CMD_EXT_CID;
if (cmd & MCU_QUERY_PREFIX || cmd == MCU_EXT_CMD_EFUSE_ACCESS)
mcu_txd->set_query = MCU_Q_QUERY; mcu_txd->set_query = MCU_Q_QUERY;
else else
mcu_txd->set_query = MCU_Q_SET; mcu_txd->set_query = MCU_Q_SET;
mcu_txd->ext_cid = mcu_cmd; mcu_txd->ext_cid_ack = !!mcu_txd->ext_cid;
mcu_txd->ext_cid_ack = 1; } else {
break; mcu_txd->set_query = MCU_Q_NA;
} }
mcu_txd->s2d_index = MCU_S2D_H2N;
WARN_ON(cmd == MCU_EXT_CMD_EFUSE_ACCESS &&
mcu_txd->set_query != MCU_Q_QUERY);
exit: exit:
if (wait_seq) if (wait_seq)
*wait_seq = seq; *wait_seq = seq;
...@@ -1022,8 +999,8 @@ int mt7921_mcu_set_tx(struct mt7921_dev *dev, struct ieee80211_vif *vif) ...@@ -1022,8 +999,8 @@ int mt7921_mcu_set_tx(struct mt7921_dev *dev, struct ieee80211_vif *vif)
e->cw_max = cpu_to_le16(10); e->cw_max = cpu_to_le16(10);
} }
ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_EDCA_UPDATE, &req, ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EDCA_UPDATE),
sizeof(req), true); &req, sizeof(req), true);
if (ret) if (ret)
return ret; return ret;
...@@ -1095,7 +1072,7 @@ int mt7921_mcu_set_chan_info(struct mt7921_phy *phy, int cmd) ...@@ -1095,7 +1072,7 @@ int mt7921_mcu_set_chan_info(struct mt7921_phy *phy, int cmd)
else else
req.switch_reason = CH_SWITCH_NORMAL; req.switch_reason = CH_SWITCH_NORMAL;
if (cmd == MCU_EXT_CMD_CHANNEL_SWITCH) if (cmd == MCU_EXT_CMD(CHANNEL_SWITCH))
req.rx_streams = hweight8(req.rx_streams); req.rx_streams = hweight8(req.rx_streams);
if (chandef->width == NL80211_CHAN_WIDTH_80P80) { if (chandef->width == NL80211_CHAN_WIDTH_80P80) {
...@@ -1118,7 +1095,7 @@ int mt7921_mcu_set_eeprom(struct mt7921_dev *dev) ...@@ -1118,7 +1095,7 @@ int mt7921_mcu_set_eeprom(struct mt7921_dev *dev)
.format = EE_FORMAT_WHOLE, .format = EE_FORMAT_WHOLE,
}; };
return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_EFUSE_BUFFER_MODE, return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EFUSE_BUFFER_MODE),
&req, sizeof(req), true); &req, sizeof(req), true);
} }
EXPORT_SYMBOL_GPL(mt7921_mcu_set_eeprom); EXPORT_SYMBOL_GPL(mt7921_mcu_set_eeprom);
...@@ -1133,8 +1110,9 @@ int mt7921_mcu_get_eeprom(struct mt7921_dev *dev, u32 offset) ...@@ -1133,8 +1110,9 @@ int mt7921_mcu_get_eeprom(struct mt7921_dev *dev, u32 offset)
int ret; int ret;
u8 *buf; u8 *buf;
ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_CMD_EFUSE_ACCESS, &req, ret = mt76_mcu_send_and_get_msg(&dev->mt76,
sizeof(req), true, &skb); MCU_EXT_QUERY(EFUSE_ACCESS),
&req, sizeof(req), true, &skb);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment