Commit 11ca82d7 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: mt7603: use standard signature for mt7603_mcu_msg_send

Use mt76 common signature for mt7603_mcu_msg_send. Move skb allocation
in mt7603_mcu_msg_send and remove duplicated code. This is a preliminary
patch for mt7615-mt7603 mcu code unification
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 114fe5e3
...@@ -22,9 +22,6 @@ __mt7603_mcu_msg_send(struct mt7603_dev *dev, struct sk_buff *skb, ...@@ -22,9 +22,6 @@ __mt7603_mcu_msg_send(struct mt7603_dev *dev, struct sk_buff *skb,
struct mt7603_mcu_txd *txd; struct mt7603_mcu_txd *txd;
u8 seq; u8 seq;
if (!skb)
return -EINVAL;
seq = ++mdev->mmio.mcu.msg_seq & 0xf; seq = ++mdev->mmio.mcu.msg_seq & 0xf;
if (!seq) if (!seq)
seq = ++mdev->mmio.mcu.msg_seq & 0xf; seq = ++mdev->mmio.mcu.msg_seq & 0xf;
...@@ -57,20 +54,26 @@ __mt7603_mcu_msg_send(struct mt7603_dev *dev, struct sk_buff *skb, ...@@ -57,20 +54,26 @@ __mt7603_mcu_msg_send(struct mt7603_dev *dev, struct sk_buff *skb,
} }
static int static int
mt7603_mcu_msg_send(struct mt7603_dev *dev, struct sk_buff *skb, int cmd) mt7603_mcu_msg_send(struct mt7603_dev *dev, int cmd, const void *data,
int len, bool wait_resp)
{ {
struct mt76_dev *mdev = &dev->mt76; struct mt76_dev *mdev = &dev->mt76;
unsigned long expires = jiffies + 3 * HZ; unsigned long expires = jiffies + 3 * HZ;
struct mt7603_mcu_rxd *rxd; struct mt7603_mcu_rxd *rxd;
struct sk_buff *skb;
int ret, seq; int ret, seq;
skb = mt7603_mcu_msg_alloc(data, len);
if (!skb)
return -ENOMEM;
mutex_lock(&mdev->mmio.mcu.mutex); mutex_lock(&mdev->mmio.mcu.mutex);
ret = __mt7603_mcu_msg_send(dev, skb, cmd, &seq); ret = __mt7603_mcu_msg_send(dev, skb, cmd, &seq);
if (ret) if (ret)
goto out; goto out;
while (1) { while (wait_resp) {
bool check_seq = false; bool check_seq = false;
skb = mt76_mcu_get_response(&dev->mt76, expires); skb = mt76_mcu_get_response(&dev->mt76, expires);
...@@ -111,9 +114,9 @@ mt7603_mcu_init_download(struct mt7603_dev *dev, u32 addr, u32 len) ...@@ -111,9 +114,9 @@ mt7603_mcu_init_download(struct mt7603_dev *dev, u32 addr, u32 len)
.len = cpu_to_le32(len), .len = cpu_to_le32(len),
.mode = cpu_to_le32(BIT(31)), .mode = cpu_to_le32(BIT(31)),
}; };
struct sk_buff *skb = mt7603_mcu_msg_alloc(&req, sizeof(req));
return mt7603_mcu_msg_send(dev, skb, -MCU_CMD_TARGET_ADDRESS_LEN_REQ); return mt7603_mcu_msg_send(dev, -MCU_CMD_TARGET_ADDRESS_LEN_REQ,
&req, sizeof(req), true);
} }
static int static int
...@@ -152,17 +155,16 @@ mt7603_mcu_start_firmware(struct mt7603_dev *dev, u32 addr) ...@@ -152,17 +155,16 @@ mt7603_mcu_start_firmware(struct mt7603_dev *dev, u32 addr)
.override = cpu_to_le32(addr ? 1 : 0), .override = cpu_to_le32(addr ? 1 : 0),
.addr = cpu_to_le32(addr), .addr = cpu_to_le32(addr),
}; };
struct sk_buff *skb = mt7603_mcu_msg_alloc(&req, sizeof(req));
return mt7603_mcu_msg_send(dev, skb, -MCU_CMD_FW_START_REQ); return mt7603_mcu_msg_send(dev, -MCU_CMD_FW_START_REQ,
&req, sizeof(req), true);
} }
static int static int
mt7603_mcu_restart(struct mt7603_dev *dev) mt7603_mcu_restart(struct mt7603_dev *dev)
{ {
struct sk_buff *skb = mt7603_mcu_msg_alloc(NULL, 0); return mt7603_mcu_msg_send(dev, -MCU_CMD_RESTART_DL_REQ,
NULL, 0, true);
return mt7603_mcu_msg_send(dev, skb, -MCU_CMD_RESTART_DL_REQ);
} }
int mt7603_load_firmware(struct mt7603_dev *dev) int mt7603_load_firmware(struct mt7603_dev *dev)
...@@ -343,30 +345,24 @@ int mt7603_mcu_set_eeprom(struct mt7603_dev *dev) ...@@ -343,30 +345,24 @@ int mt7603_mcu_set_eeprom(struct mt7603_dev *dev)
u8 buffer_mode; u8 buffer_mode;
u8 len; u8 len;
u8 pad[2]; u8 pad[2];
} req_hdr = { struct req_data data[255];
} req = {
.buffer_mode = 1, .buffer_mode = 1,
.len = ARRAY_SIZE(req_fields) - 1, .len = ARRAY_SIZE(req_fields) - 1,
}; };
struct sk_buff *skb;
struct req_data *data;
const int size = 0xff * sizeof(struct req_data);
u8 *eep = (u8 *)dev->mt76.eeprom.data; u8 *eep = (u8 *)dev->mt76.eeprom.data;
int i; int i;
BUILD_BUG_ON(ARRAY_SIZE(req_fields) * sizeof(*data) > size); BUILD_BUG_ON(ARRAY_SIZE(req_fields) > ARRAY_SIZE(req.data));
skb = mt7603_mcu_msg_alloc(NULL, size + sizeof(req_hdr));
memcpy(skb_put(skb, sizeof(req_hdr)), &req_hdr, sizeof(req_hdr));
data = (struct req_data *)skb_put(skb, size);
memset(data, 0, size);
for (i = 0; i < ARRAY_SIZE(req_fields); i++) { for (i = 0; i < ARRAY_SIZE(req_fields); i++) {
data[i].addr = cpu_to_le16(req_fields[i]); req.data[i].addr = cpu_to_le16(req_fields[i]);
data[i].val = eep[req_fields[i]]; req.data[i].val = eep[req_fields[i]];
data[i].pad = 0; req.data[i].pad = 0;
} }
return mt7603_mcu_msg_send(dev, skb, MCU_EXT_CMD_EFUSE_BUFFER_MODE); return mt7603_mcu_msg_send(dev, MCU_EXT_CMD_EFUSE_BUFFER_MODE,
&req, sizeof(req), true);
} }
static int mt7603_mcu_set_tx_power(struct mt7603_dev *dev) static int mt7603_mcu_set_tx_power(struct mt7603_dev *dev)
...@@ -401,7 +397,6 @@ static int mt7603_mcu_set_tx_power(struct mt7603_dev *dev) ...@@ -401,7 +397,6 @@ static int mt7603_mcu_set_tx_power(struct mt7603_dev *dev)
}, },
#undef EEP_VAL #undef EEP_VAL
}; };
struct sk_buff *skb;
u8 *eep = (u8 *)dev->mt76.eeprom.data; u8 *eep = (u8 *)dev->mt76.eeprom.data;
memcpy(req.rate_power_delta, eep + MT_EE_TX_POWER_CCK, memcpy(req.rate_power_delta, eep + MT_EE_TX_POWER_CCK,
...@@ -410,8 +405,8 @@ static int mt7603_mcu_set_tx_power(struct mt7603_dev *dev) ...@@ -410,8 +405,8 @@ static int mt7603_mcu_set_tx_power(struct mt7603_dev *dev)
memcpy(req.temp_comp_power, eep + MT_EE_STEP_NUM_NEG_6_7, memcpy(req.temp_comp_power, eep + MT_EE_STEP_NUM_NEG_6_7,
sizeof(req.temp_comp_power)); sizeof(req.temp_comp_power));
skb = mt7603_mcu_msg_alloc(&req, sizeof(req)); return mt7603_mcu_msg_send(dev, MCU_EXT_CMD_SET_TX_POWER_CTRL,
return mt7603_mcu_msg_send(dev, skb, MCU_EXT_CMD_SET_TX_POWER_CTRL); &req, sizeof(req), true);
} }
int mt7603_mcu_set_channel(struct mt7603_dev *dev) int mt7603_mcu_set_channel(struct mt7603_dev *dev)
...@@ -435,10 +430,8 @@ int mt7603_mcu_set_channel(struct mt7603_dev *dev) ...@@ -435,10 +430,8 @@ int mt7603_mcu_set_channel(struct mt7603_dev *dev)
.tx_streams = n_chains, .tx_streams = n_chains,
.rx_streams = n_chains, .rx_streams = n_chains,
}; };
struct sk_buff *skb;
s8 tx_power; s8 tx_power;
int ret; int i, ret;
int i;
if (dev->mt76.chandef.width == NL80211_CHAN_WIDTH_40) { if (dev->mt76.chandef.width == NL80211_CHAN_WIDTH_40) {
req.bw = MT_BW_40; req.bw = MT_BW_40;
...@@ -458,8 +451,8 @@ int mt7603_mcu_set_channel(struct mt7603_dev *dev) ...@@ -458,8 +451,8 @@ int mt7603_mcu_set_channel(struct mt7603_dev *dev)
for (i = 0; i < ARRAY_SIZE(req.txpower); i++) for (i = 0; i < ARRAY_SIZE(req.txpower); i++)
req.txpower[i] = tx_power; req.txpower[i] = tx_power;
skb = mt7603_mcu_msg_alloc(&req, sizeof(req)); ret = mt7603_mcu_msg_send(dev, MCU_EXT_CMD_CHANNEL_SWITCH,
ret = mt7603_mcu_msg_send(dev, skb, MCU_EXT_CMD_CHANNEL_SWITCH); &req, sizeof(req), true);
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