Commit a74d6336 authored by Stanislaw Gruszka's avatar Stanislaw Gruszka Committed by Felix Fietkau

mt76: remove mcu_msg_alloc

We almost always use patter like this:

       skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg));
       return mt76_mcu_send_msg(dev, skb, CMD_FUN_SET_OP, wait_resp);

This is not needed, we can allocate skb in mcu_send_msg routine.
Signed-off-by: default avatarStanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent ad3f993a
...@@ -135,9 +135,8 @@ struct mt76_queue { ...@@ -135,9 +135,8 @@ struct mt76_queue {
}; };
struct mt76_mcu_ops { struct mt76_mcu_ops {
struct sk_buff *(*mcu_msg_alloc)(const void *data, int len); int (*mcu_send_msg)(struct mt76_dev *dev, int cmd, const void *data,
int (*mcu_send_msg)(struct mt76_dev *dev, struct sk_buff *skb, int len, bool wait_resp);
int cmd, bool wait_resp);
int (*mcu_wr_rp)(struct mt76_dev *dev, u32 base, int (*mcu_wr_rp)(struct mt76_dev *dev, u32 base,
const struct mt76_reg_pair *rp, int len); const struct mt76_reg_pair *rp, int len);
int (*mcu_rd_rp)(struct mt76_dev *dev, u32 base, int (*mcu_rd_rp)(struct mt76_dev *dev, u32 base,
...@@ -503,7 +502,6 @@ struct mt76_rx_status { ...@@ -503,7 +502,6 @@ struct mt76_rx_status {
#define mt76_wr_rp(dev, ...) (dev)->mt76.bus->wr_rp(&((dev)->mt76), __VA_ARGS__) #define mt76_wr_rp(dev, ...) (dev)->mt76.bus->wr_rp(&((dev)->mt76), __VA_ARGS__)
#define mt76_rd_rp(dev, ...) (dev)->mt76.bus->rd_rp(&((dev)->mt76), __VA_ARGS__) #define mt76_rd_rp(dev, ...) (dev)->mt76.bus->rd_rp(&((dev)->mt76), __VA_ARGS__)
#define mt76_mcu_msg_alloc(dev, ...) (dev)->mt76.mcu_ops->mcu_msg_alloc(__VA_ARGS__)
#define mt76_mcu_send_msg(dev, ...) (dev)->mt76.mcu_ops->mcu_send_msg(&((dev)->mt76), __VA_ARGS__) #define mt76_mcu_send_msg(dev, ...) (dev)->mt76.mcu_ops->mcu_send_msg(&((dev)->mt76), __VA_ARGS__)
#define mt76_set(dev, offset, val) mt76_rmw(dev, offset, 0, val) #define mt76_set(dev, offset, val) mt76_rmw(dev, offset, 0, val)
......
...@@ -127,7 +127,6 @@ static int mt76x0e_load_firmware(struct mt76x02_dev *dev) ...@@ -127,7 +127,6 @@ static int mt76x0e_load_firmware(struct mt76x02_dev *dev)
int mt76x0e_mcu_init(struct mt76x02_dev *dev) int mt76x0e_mcu_init(struct mt76x02_dev *dev)
{ {
static const struct mt76_mcu_ops mt76x0e_mcu_ops = { static const struct mt76_mcu_ops mt76x0e_mcu_ops = {
.mcu_msg_alloc = mt76x02_mcu_msg_alloc,
.mcu_send_msg = mt76x02_mcu_msg_send, .mcu_send_msg = mt76x02_mcu_msg_send,
}; };
int err; int err;
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "mt76x02_mcu.h" #include "mt76x02_mcu.h"
struct sk_buff *mt76x02_mcu_msg_alloc(const void *data, int len) static struct sk_buff *mt76x02_mcu_msg_alloc(const void *data, int len)
{ {
struct sk_buff *skb; struct sk_buff *skb;
...@@ -32,7 +32,6 @@ struct sk_buff *mt76x02_mcu_msg_alloc(const void *data, int len) ...@@ -32,7 +32,6 @@ struct sk_buff *mt76x02_mcu_msg_alloc(const void *data, int len)
return skb; return skb;
} }
EXPORT_SYMBOL_GPL(mt76x02_mcu_msg_alloc);
static struct sk_buff * static struct sk_buff *
mt76x02_mcu_get_response(struct mt76x02_dev *dev, unsigned long expires) mt76x02_mcu_get_response(struct mt76x02_dev *dev, unsigned long expires)
...@@ -80,16 +79,18 @@ mt76x02_tx_queue_mcu(struct mt76x02_dev *dev, enum mt76_txq_id qid, ...@@ -80,16 +79,18 @@ mt76x02_tx_queue_mcu(struct mt76x02_dev *dev, enum mt76_txq_id qid,
return 0; return 0;
} }
int mt76x02_mcu_msg_send(struct mt76_dev *mdev, struct sk_buff *skb, int mt76x02_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data,
int cmd, bool wait_resp) int len, bool wait_resp)
{ {
struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76); struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76);
unsigned long expires = jiffies + HZ; unsigned long expires = jiffies + HZ;
struct sk_buff *skb;
int ret; int ret;
u8 seq; u8 seq;
skb = mt76x02_mcu_msg_alloc(data, len);
if (!skb) if (!skb)
return -EINVAL; return -ENOMEM;
mutex_lock(&mdev->mmio.mcu.mutex); mutex_lock(&mdev->mmio.mcu.mutex);
...@@ -135,7 +136,6 @@ int mt76x02_mcu_function_select(struct mt76x02_dev *dev, ...@@ -135,7 +136,6 @@ int mt76x02_mcu_function_select(struct mt76x02_dev *dev,
enum mcu_function func, enum mcu_function func,
u32 val, bool wait_resp) u32 val, bool wait_resp)
{ {
struct sk_buff *skb;
struct { struct {
__le32 id; __le32 id;
__le32 value; __le32 value;
...@@ -144,15 +144,14 @@ int mt76x02_mcu_function_select(struct mt76x02_dev *dev, ...@@ -144,15 +144,14 @@ int mt76x02_mcu_function_select(struct mt76x02_dev *dev,
.value = cpu_to_le32(val), .value = cpu_to_le32(val),
}; };
skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg)); return mt76_mcu_send_msg(dev, CMD_FUN_SET_OP, &msg, sizeof(msg),
return mt76_mcu_send_msg(dev, skb, CMD_FUN_SET_OP, wait_resp); wait_resp);
} }
EXPORT_SYMBOL_GPL(mt76x02_mcu_function_select); EXPORT_SYMBOL_GPL(mt76x02_mcu_function_select);
int mt76x02_mcu_set_radio_state(struct mt76x02_dev *dev, bool on, int mt76x02_mcu_set_radio_state(struct mt76x02_dev *dev, bool on,
bool wait_resp) bool wait_resp)
{ {
struct sk_buff *skb;
struct { struct {
__le32 mode; __le32 mode;
__le32 level; __le32 level;
...@@ -161,15 +160,14 @@ int mt76x02_mcu_set_radio_state(struct mt76x02_dev *dev, bool on, ...@@ -161,15 +160,14 @@ int mt76x02_mcu_set_radio_state(struct mt76x02_dev *dev, bool on,
.level = cpu_to_le32(0), .level = cpu_to_le32(0),
}; };
skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg)); return mt76_mcu_send_msg(dev, CMD_POWER_SAVING_OP, &msg, sizeof(msg),
return mt76_mcu_send_msg(dev, skb, CMD_POWER_SAVING_OP, wait_resp); wait_resp);
} }
EXPORT_SYMBOL_GPL(mt76x02_mcu_set_radio_state); EXPORT_SYMBOL_GPL(mt76x02_mcu_set_radio_state);
int mt76x02_mcu_calibrate(struct mt76x02_dev *dev, int type, int mt76x02_mcu_calibrate(struct mt76x02_dev *dev, int type,
u32 param, bool wait) u32 param, bool wait)
{ {
struct sk_buff *skb;
struct { struct {
__le32 id; __le32 id;
__le32 value; __le32 value;
...@@ -182,8 +180,8 @@ int mt76x02_mcu_calibrate(struct mt76x02_dev *dev, int type, ...@@ -182,8 +180,8 @@ int mt76x02_mcu_calibrate(struct mt76x02_dev *dev, int type,
if (wait) if (wait)
mt76_rmw(dev, MT_MCU_COM_REG0, BIT(31), 0); mt76_rmw(dev, MT_MCU_COM_REG0, BIT(31), 0);
skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg)); ret = mt76_mcu_send_msg(dev, CMD_CALIBRATION_OP, &msg, sizeof(msg),
ret = mt76_mcu_send_msg(dev, skb, CMD_CALIBRATION_OP, true); true);
if (ret) if (ret)
return ret; return ret;
......
...@@ -99,9 +99,8 @@ struct mt76x02_patch_header { ...@@ -99,9 +99,8 @@ struct mt76x02_patch_header {
int mt76x02_mcu_cleanup(struct mt76x02_dev *dev); int mt76x02_mcu_cleanup(struct mt76x02_dev *dev);
int mt76x02_mcu_calibrate(struct mt76x02_dev *dev, int type, int mt76x02_mcu_calibrate(struct mt76x02_dev *dev, int type,
u32 param, bool wait); u32 param, bool wait);
struct sk_buff *mt76x02_mcu_msg_alloc(const void *data, int len); int mt76x02_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data,
int mt76x02_mcu_msg_send(struct mt76_dev *mdev, struct sk_buff *skb, int len, bool wait_resp);
int cmd, bool wait_resp);
int mt76x02_mcu_function_select(struct mt76x02_dev *dev, int mt76x02_mcu_function_select(struct mt76x02_dev *dev,
enum mcu_function func, enum mcu_function func,
u32 val, bool wait_resp); u32 val, bool wait_resp);
......
...@@ -129,9 +129,6 @@ __mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb, ...@@ -129,9 +129,6 @@ __mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb,
u8 seq = 0; u8 seq = 0;
u32 info; u32 info;
if (!skb)
return -EINVAL;
if (test_bit(MT76_REMOVED, &dev->state)) if (test_bit(MT76_REMOVED, &dev->state))
return 0; return 0;
...@@ -162,12 +159,17 @@ __mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb, ...@@ -162,12 +159,17 @@ __mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb,
} }
static int static int
mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb, mt76x02u_mcu_send_msg(struct mt76_dev *dev, int cmd, const void *data,
int cmd, bool wait_resp) int len, bool wait_resp)
{ {
struct mt76_usb *usb = &dev->usb; struct mt76_usb *usb = &dev->usb;
struct sk_buff *skb;
int err; int err;
skb = mt76x02u_mcu_msg_alloc(data, len);
if (!skb)
return -ENOMEM;
mutex_lock(&usb->mcu.mutex); mutex_lock(&usb->mcu.mutex);
err = __mt76x02u_mcu_send_msg(dev, skb, cmd, wait_resp); err = __mt76x02u_mcu_send_msg(dev, skb, cmd, wait_resp);
mutex_unlock(&usb->mcu.mutex); mutex_unlock(&usb->mcu.mutex);
...@@ -186,6 +188,7 @@ mt76x02u_mcu_wr_rp(struct mt76_dev *dev, u32 base, ...@@ -186,6 +188,7 @@ mt76x02u_mcu_wr_rp(struct mt76_dev *dev, u32 base,
{ {
const int CMD_RANDOM_WRITE = 12; const int CMD_RANDOM_WRITE = 12;
const int max_vals_per_cmd = MT_INBAND_PACKET_MAX_LEN / 8; const int max_vals_per_cmd = MT_INBAND_PACKET_MAX_LEN / 8;
struct mt76_usb *usb = &dev->usb;
struct sk_buff *skb; struct sk_buff *skb;
int cnt, i, ret; int cnt, i, ret;
...@@ -204,7 +207,9 @@ mt76x02u_mcu_wr_rp(struct mt76_dev *dev, u32 base, ...@@ -204,7 +207,9 @@ mt76x02u_mcu_wr_rp(struct mt76_dev *dev, u32 base,
skb_put_le32(skb, data[i].value); skb_put_le32(skb, data[i].value);
} }
ret = mt76x02u_mcu_send_msg(dev, skb, CMD_RANDOM_WRITE, cnt == n); mutex_lock(&usb->mcu.mutex);
ret = __mt76x02u_mcu_send_msg(dev, skb, CMD_RANDOM_WRITE, cnt == n);
mutex_unlock(&usb->mcu.mutex);
if (ret) if (ret)
return ret; return ret;
...@@ -345,7 +350,6 @@ EXPORT_SYMBOL_GPL(mt76x02u_mcu_fw_send_data); ...@@ -345,7 +350,6 @@ EXPORT_SYMBOL_GPL(mt76x02u_mcu_fw_send_data);
void mt76x02u_init_mcu(struct mt76_dev *dev) void mt76x02u_init_mcu(struct mt76_dev *dev)
{ {
static const struct mt76_mcu_ops mt76x02u_mcu_ops = { static const struct mt76_mcu_ops mt76x02u_mcu_ops = {
.mcu_msg_alloc = mt76x02u_mcu_msg_alloc,
.mcu_send_msg = mt76x02u_mcu_send_msg, .mcu_send_msg = mt76x02u_mcu_send_msg,
.mcu_wr_rp = mt76x02u_mcu_wr_rp, .mcu_wr_rp = mt76x02u_mcu_wr_rp,
.mcu_rd_rp = mt76x02u_mcu_rd_rp, .mcu_rd_rp = mt76x02u_mcu_rd_rp,
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
int mt76x2_mcu_set_channel(struct mt76x02_dev *dev, u8 channel, u8 bw, int mt76x2_mcu_set_channel(struct mt76x02_dev *dev, u8 channel, u8 bw,
u8 bw_index, bool scan) u8 bw_index, bool scan)
{ {
struct sk_buff *skb;
struct { struct {
u8 idx; u8 idx;
u8 scan; u8 scan;
...@@ -45,21 +44,19 @@ int mt76x2_mcu_set_channel(struct mt76x02_dev *dev, u8 channel, u8 bw, ...@@ -45,21 +44,19 @@ int mt76x2_mcu_set_channel(struct mt76x02_dev *dev, u8 channel, u8 bw,
}; };
/* first set the channel without the extension channel info */ /* first set the channel without the extension channel info */
skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg)); mt76_mcu_send_msg(dev, CMD_SWITCH_CHANNEL_OP, &msg, sizeof(msg), true);
mt76_mcu_send_msg(dev, skb, CMD_SWITCH_CHANNEL_OP, true);
usleep_range(5000, 10000); usleep_range(5000, 10000);
msg.ext_chan = 0xe0 + bw_index; msg.ext_chan = 0xe0 + bw_index;
skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg)); return mt76_mcu_send_msg(dev, CMD_SWITCH_CHANNEL_OP, &msg, sizeof(msg),
return mt76_mcu_send_msg(dev, skb, CMD_SWITCH_CHANNEL_OP, true); true);
} }
EXPORT_SYMBOL_GPL(mt76x2_mcu_set_channel); EXPORT_SYMBOL_GPL(mt76x2_mcu_set_channel);
int mt76x2_mcu_load_cr(struct mt76x02_dev *dev, u8 type, u8 temp_level, int mt76x2_mcu_load_cr(struct mt76x02_dev *dev, u8 type, u8 temp_level,
u8 channel) u8 channel)
{ {
struct sk_buff *skb;
struct { struct {
u8 cr_mode; u8 cr_mode;
u8 temp; u8 temp;
...@@ -80,15 +77,13 @@ int mt76x2_mcu_load_cr(struct mt76x02_dev *dev, u8 type, u8 temp_level, ...@@ -80,15 +77,13 @@ int mt76x2_mcu_load_cr(struct mt76x02_dev *dev, u8 type, u8 temp_level,
msg.cfg = cpu_to_le32(val); msg.cfg = cpu_to_le32(val);
/* first set the channel without the extension channel info */ /* first set the channel without the extension channel info */
skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg)); return mt76_mcu_send_msg(dev, CMD_LOAD_CR, &msg, sizeof(msg), true);
return mt76_mcu_send_msg(dev, skb, CMD_LOAD_CR, true);
} }
EXPORT_SYMBOL_GPL(mt76x2_mcu_load_cr); EXPORT_SYMBOL_GPL(mt76x2_mcu_load_cr);
int mt76x2_mcu_init_gain(struct mt76x02_dev *dev, u8 channel, u32 gain, int mt76x2_mcu_init_gain(struct mt76x02_dev *dev, u8 channel, u32 gain,
bool force) bool force)
{ {
struct sk_buff *skb;
struct { struct {
__le32 channel; __le32 channel;
__le32 gain_val; __le32 gain_val;
...@@ -100,15 +95,14 @@ int mt76x2_mcu_init_gain(struct mt76x02_dev *dev, u8 channel, u32 gain, ...@@ -100,15 +95,14 @@ int mt76x2_mcu_init_gain(struct mt76x02_dev *dev, u8 channel, u32 gain,
if (force) if (force)
msg.channel |= cpu_to_le32(BIT(31)); msg.channel |= cpu_to_le32(BIT(31));
skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg)); return mt76_mcu_send_msg(dev, CMD_INIT_GAIN_OP, &msg, sizeof(msg),
return mt76_mcu_send_msg(dev, skb, CMD_INIT_GAIN_OP, true); true);
} }
EXPORT_SYMBOL_GPL(mt76x2_mcu_init_gain); EXPORT_SYMBOL_GPL(mt76x2_mcu_init_gain);
int mt76x2_mcu_tssi_comp(struct mt76x02_dev *dev, int mt76x2_mcu_tssi_comp(struct mt76x02_dev *dev,
struct mt76x2_tssi_comp *tssi_data) struct mt76x2_tssi_comp *tssi_data)
{ {
struct sk_buff *skb;
struct { struct {
__le32 id; __le32 id;
struct mt76x2_tssi_comp data; struct mt76x2_tssi_comp data;
...@@ -117,7 +111,7 @@ int mt76x2_mcu_tssi_comp(struct mt76x02_dev *dev, ...@@ -117,7 +111,7 @@ int mt76x2_mcu_tssi_comp(struct mt76x02_dev *dev,
.data = *tssi_data, .data = *tssi_data,
}; };
skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg)); return mt76_mcu_send_msg(dev, CMD_CALIBRATION_OP, &msg, sizeof(msg),
return mt76_mcu_send_msg(dev, skb, CMD_CALIBRATION_OP, true); true);
} }
EXPORT_SYMBOL_GPL(mt76x2_mcu_tssi_comp); EXPORT_SYMBOL_GPL(mt76x2_mcu_tssi_comp);
...@@ -168,7 +168,6 @@ mt76pci_load_firmware(struct mt76x02_dev *dev) ...@@ -168,7 +168,6 @@ mt76pci_load_firmware(struct mt76x02_dev *dev)
int mt76x2_mcu_init(struct mt76x02_dev *dev) int mt76x2_mcu_init(struct mt76x02_dev *dev)
{ {
static const struct mt76_mcu_ops mt76x2_mcu_ops = { static const struct mt76_mcu_ops mt76x2_mcu_ops = {
.mcu_msg_alloc = mt76x02_mcu_msg_alloc,
.mcu_send_msg = mt76x02_mcu_msg_send, .mcu_send_msg = mt76x02_mcu_msg_send,
}; };
int ret; int 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