@@ -105,3 +105,26 @@ int mt76_mcu_skb_send_and_get_msg(struct mt76_dev *dev, struct sk_buff *skb,
return ret;
}
EXPORT_SYMBOL_GPL(mt76_mcu_skb_send_and_get_msg);
+
+int mt76_mcu_send_firmware(struct mt76_dev *dev, int cmd, const void *data,
+ int len)
+{
+ int err, cur_len;
+
+ while (len > 0) {
+ cur_len = min_t(int, 4096 - dev->mcu_ops->headroom, len);
+
+ err = mt76_mcu_send_msg(dev, cmd, data, cur_len, false);
+ if (err)
+ return err;
+
+ data += cur_len;
+ len -= cur_len;
+
+ if (dev->queue_ops->tx_cleanup)
+ dev->queue_ops->tx_cleanup(dev, MT_TXQ_FWDL, false);
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(mt76_mcu_send_firmware);
@@ -1076,6 +1076,8 @@ int mt76_mcu_send_and_get_msg(struct mt76_dev *dev, int cmd, const void *data,
int len, bool wait_resp, struct sk_buff **ret);
int mt76_mcu_skb_send_and_get_msg(struct mt76_dev *dev, struct sk_buff *skb,
int cmd, bool wait_resp, struct sk_buff **ret);
+int mt76_mcu_send_firmware(struct mt76_dev *dev, int cmd, const void *data,
+ int len);
static inline int
mt76_mcu_send_msg(struct mt76_dev *dev, int cmd, const void *data, int len,
bool wait_resp)
@@ -93,27 +93,6 @@ mt7603_mcu_init_download(struct mt7603_dev *dev, u32 addr, u32 len)
&req, sizeof(req), true);
}
-static int
-mt7603_mcu_send_firmware(struct mt7603_dev *dev, const void *data, int len)
-{
- int cur_len, ret = 0;
-
- while (len > 0) {
- cur_len = min_t(int, 4096 - sizeof(struct mt7603_mcu_txd),
- len);
-
- ret = mt76_mcu_send_msg(&dev->mt76, -MCU_CMD_FW_SCATTER, data,
- cur_len, false);
- if (ret)
- break;
-
- data += cur_len;
- len -= cur_len;
- }
-
- return ret;
-}
-
static int
mt7603_mcu_start_firmware(struct mt7603_dev *dev, u32 addr)
{
@@ -200,7 +179,8 @@ static int mt7603_load_firmware(struct mt7603_dev *dev)
goto out;
}
- ret = mt7603_mcu_send_firmware(dev, fw->data, dl_len);
+ ret = mt76_mcu_send_firmware(&dev->mt76, -MCU_CMD_FW_SCATTER,
+ fw->data, dl_len);
if (ret) {
dev_err(dev->mt76.dev, "Failed to send firmware to device\n");
goto out;
@@ -1872,29 +1872,6 @@ static const struct mt7615_mcu_ops uni_update_ops = {
.set_fw_ctrl = mt7615_mcu_fw_pmctrl,
};
-static int mt7615_mcu_send_firmware(struct mt7615_dev *dev, const void *data,
- int len)
-{
- int ret = 0, cur_len;
-
- while (len > 0) {
- cur_len = min_t(int, 4096 - dev->mt76.mcu_ops->headroom, len);
-
- ret = mt76_mcu_send_msg(&dev->mt76, MCU_CMD_FW_SCATTER, data,
- cur_len, false);
- if (ret)
- break;
-
- data += cur_len;
- len -= cur_len;
-
- if (mt76_is_mmio(&dev->mt76))
- mt76_queue_tx_cleanup(dev, MT_TXQ_FWDL, false);
- }
-
- return ret;
-}
-
static int mt7615_mcu_start_firmware(struct mt7615_dev *dev, u32 addr,
u32 option)
{
@@ -1981,7 +1958,8 @@ static int mt7615_load_patch(struct mt7615_dev *dev, u32 addr, const char *name)
goto out;
}
- ret = mt7615_mcu_send_firmware(dev, fw->data + sizeof(*hdr), len);
+ ret = mt76_mcu_send_firmware(&dev->mt76, MCU_CMD_FW_SCATTER,
+ fw->data + sizeof(*hdr), len);
if (ret) {
dev_err(dev->mt76.dev, "Failed to send firmware to device\n");
goto out;
@@ -2041,7 +2019,8 @@ mt7615_mcu_send_ram_firmware(struct mt7615_dev *dev,
return err;
}
- err = mt7615_mcu_send_firmware(dev, data + offset, len);
+ err = mt76_mcu_send_firmware(&dev->mt76, MCU_CMD_FW_SCATTER,
+ data + offset, len);
if (err) {
dev_err(dev->mt76.dev, "Failed to send firmware to device\n");
return err;
@@ -2282,7 +2261,8 @@ static int mt7663_load_n9(struct mt7615_dev *dev, const char *name)
goto out;
}
- ret = mt7615_mcu_send_firmware(dev, fw->data + offset, len);
+ ret = mt76_mcu_send_firmware(&dev->mt76, MCU_CMD_FW_SCATTER,
+ fw->data + offset, len);
if (ret) {
dev_err(dev->mt76.dev, "Failed to send firmware\n");
goto out;
@@ -2486,28 +2486,6 @@ int mt7915_mcu_add_beacon(struct ieee80211_hw *hw,
MCU_EXT_CMD_BSS_INFO_UPDATE, true);
}
-static int mt7915_mcu_send_firmware(struct mt7915_dev *dev, const void *data,
- int len)
-{
- int ret = 0, cur_len;
-
- while (len > 0) {
- cur_len = min_t(int, 4096 - sizeof(struct mt7915_mcu_txd),
- len);
-
- ret = mt76_mcu_send_msg(&dev->mt76, -MCU_CMD_FW_SCATTER, data,
- cur_len, false);
- if (ret)
- break;
-
- data += cur_len;
- len -= cur_len;
- mt76_queue_tx_cleanup(dev, MT_TXQ_FWDL, false);
- }
-
- return ret;
-}
-
static int mt7915_mcu_start_firmware(struct mt7915_dev *dev, u32 addr,
u32 option)
{
@@ -2653,7 +2631,8 @@ static int mt7915_load_patch(struct mt7915_dev *dev)
goto out;
}
- ret = mt7915_mcu_send_firmware(dev, dl, len);
+ ret = mt76_mcu_send_firmware(&dev->mt76, -MCU_CMD_FW_SCATTER,
+ dl, len);
if (ret) {
dev_err(dev->mt76.dev, "Failed to send patch\n");
goto out;
@@ -2721,7 +2700,8 @@ mt7915_mcu_send_ram_firmware(struct mt7915_dev *dev,
return err;
}
- err = mt7915_mcu_send_firmware(dev, data + offset, len);
+ err = mt76_mcu_send_firmware(&dev->mt76, -MCU_CMD_FW_SCATTER,
+ data + offset, len);
if (err) {
dev_err(dev->mt76.dev, "Failed to send firmware.\n");
return err;
Move mt76_mcu_send_firmware routine in common code since it is actually shared between mt7615, mt7663, mt7603 and mt7915 devices Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> --- drivers/net/wireless/mediatek/mt76/mcu.c | 23 +++++++++++++ drivers/net/wireless/mediatek/mt76/mt76.h | 2 ++ .../net/wireless/mediatek/mt76/mt7603/mcu.c | 24 ++------------ .../net/wireless/mediatek/mt76/mt7615/mcu.c | 32 ++++--------------- .../net/wireless/mediatek/mt76/mt7915/mcu.c | 28 +++------------- 5 files changed, 37 insertions(+), 72 deletions(-)