Commit 1ca8089a authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt7615: mcu: do not use function pointers whenever possible

Remove function pointers in mt7615_mcu_set_bss_info and run function
directly. Moreover remove __mt7615_mcu_set_bss_info since it is run just
by mt7615_mcu_set_bss_info and remove duplicated istructions
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent fddc827f
...@@ -676,154 +676,107 @@ int mt7615_mcu_set_dev_info(struct mt7615_dev *dev, ...@@ -676,154 +676,107 @@ int mt7615_mcu_set_dev_info(struct mt7615_dev *dev,
return mt7615_mcu_msg_send(dev, skb, MCU_EXT_CMD_DEV_INFO_UPDATE); return mt7615_mcu_msg_send(dev, skb, MCU_EXT_CMD_DEV_INFO_UPDATE);
} }
static void bss_info_omac_handler (struct mt7615_dev *dev, static void
struct bss_info *bss_info, mt7615_mcu_bss_info_omac_header(struct mt7615_vif *mvif, u8 *data,
struct sk_buff *skb) u32 conn_type)
{ {
struct bss_info_omac tlv = {0}; struct bss_info_omac *hdr = (struct bss_info_omac *)data;
u8 idx;
tlv.tag = cpu_to_le16(BSS_INFO_OMAC);
tlv.len = cpu_to_le16(sizeof(tlv));
tlv.hw_bss_idx = (bss_info->omac_idx > EXT_BSSID_START) ?
HW_BSSID_0 : bss_info->omac_idx;
tlv.omac_idx = bss_info->omac_idx;
tlv.band_idx = bss_info->band_idx;
tlv.conn_type = cpu_to_le32(bss_info->conn_type);
memcpy(skb_put(skb, sizeof(tlv)), &tlv, sizeof(tlv)); idx = mvif->omac_idx > EXT_BSSID_START ? HW_BSSID_0 : mvif->omac_idx;
hdr->tag = cpu_to_le16(BSS_INFO_OMAC);
hdr->len = cpu_to_le16(sizeof(struct bss_info_omac));
hdr->hw_bss_idx = idx;
hdr->omac_idx = mvif->omac_idx;
hdr->band_idx = mvif->band_idx;
hdr->conn_type = cpu_to_le32(conn_type);
} }
static void bss_info_basic_handler (struct mt7615_dev *dev, static void
struct bss_info *bss_info, mt7615_mcu_bss_info_basic_header(struct ieee80211_vif *vif, u8 *data,
struct sk_buff *skb) u32 net_type, u8 tx_wlan_idx,
bool enable)
{ {
struct bss_info_basic tlv = {0}; struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
struct bss_info_basic *hdr = (struct bss_info_basic *)data;
tlv.tag = cpu_to_le16(BSS_INFO_BASIC);
tlv.len = cpu_to_le16(sizeof(tlv)); hdr->tag = cpu_to_le16(BSS_INFO_BASIC);
tlv.network_type = cpu_to_le32(bss_info->network_type); hdr->len = cpu_to_le16(sizeof(struct bss_info_basic));
tlv.active = bss_info->enable; hdr->network_type = cpu_to_le32(net_type);
tlv.bcn_interval = cpu_to_le16(bss_info->bcn_interval); hdr->active = enable;
memcpy(tlv.bssid, bss_info->bssid, ETH_ALEN); hdr->bcn_interval = cpu_to_le16(vif->bss_conf.beacon_int);
tlv.wmm_idx = bss_info->wmm_idx; memcpy(hdr->bssid, vif->bss_conf.bssid, ETH_ALEN);
tlv.dtim_period = bss_info->dtim_period; hdr->wmm_idx = mvif->wmm_idx;
tlv.bmc_tx_wlan_idx = bss_info->bmc_tx_wlan_idx; hdr->dtim_period = vif->bss_conf.dtim_period;
hdr->bmc_tx_wlan_idx = tx_wlan_idx;
memcpy(skb_put(skb, sizeof(tlv)), &tlv, sizeof(tlv));
} }
static void bss_info_ext_bss_handler (struct mt7615_dev *dev, static void
struct bss_info *bss_info, mt7615_mcu_bss_info_ext_header(struct mt7615_vif *mvif, u8 *data)
struct sk_buff *skb)
{ {
/* SIFS 20us + 512 byte beacon tranmitted by 1Mbps (3906us) */ /* SIFS 20us + 512 byte beacon tranmitted by 1Mbps (3906us) */
#define BCN_TX_ESTIMATE_TIME (4096 + 20) #define BCN_TX_ESTIMATE_TIME (4096 + 20)
struct bss_info_ext_bss tlv = {0}; struct bss_info_ext_bss *hdr = (struct bss_info_ext_bss *)data;
int ext_bss_idx; int ext_bss_idx;
ext_bss_idx = bss_info->omac_idx - EXT_BSSID_START; ext_bss_idx = mvif->omac_idx - EXT_BSSID_START;
if (ext_bss_idx < 0) if (ext_bss_idx < 0)
return; return;
tlv.tag = cpu_to_le16(BSS_INFO_EXT_BSS); hdr->tag = cpu_to_le16(BSS_INFO_EXT_BSS);
tlv.len = cpu_to_le16(sizeof(tlv)); hdr->len = cpu_to_le16(sizeof(struct bss_info_ext_bss));
tlv.mbss_tsf_offset = ext_bss_idx * BCN_TX_ESTIMATE_TIME; hdr->mbss_tsf_offset = ext_bss_idx * BCN_TX_ESTIMATE_TIME;
memcpy(skb_put(skb, sizeof(tlv)), &tlv, sizeof(tlv));
} }
static struct bss_info_tag_handler bss_info_tag_handler[] = { int mt7615_mcu_set_bss_info(struct mt7615_dev *dev,
{BSS_INFO_OMAC, sizeof(struct bss_info_omac), bss_info_omac_handler}, struct ieee80211_vif *vif, int en)
{BSS_INFO_BASIC, sizeof(struct bss_info_basic), bss_info_basic_handler},
{BSS_INFO_RF_CH, sizeof(struct bss_info_rf_ch), NULL},
{BSS_INFO_PM, 0, NULL},
{BSS_INFO_UAPSD, 0, NULL},
{BSS_INFO_ROAM_DETECTION, 0, NULL},
{BSS_INFO_LQ_RM, 0, NULL},
{BSS_INFO_EXT_BSS, sizeof(struct bss_info_ext_bss), bss_info_ext_bss_handler},
{BSS_INFO_BMC_INFO, 0, NULL},
{BSS_INFO_SYNC_MODE, 0, NULL},
{BSS_INFO_RA, 0, NULL},
{BSS_INFO_MAX_NUM, 0, NULL},
};
static int __mt7615_mcu_set_bss_info(struct mt7615_dev *dev,
struct bss_info *bss_info)
{ {
struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
struct req_hdr { struct req_hdr {
u8 bss_idx; u8 bss_idx;
u8 rsv0; u8 rsv0;
__le16 tlv_num; __le16 tlv_num;
u8 is_tlv_append; u8 is_tlv_append;
u8 rsv1[3]; u8 rsv1[3];
} __packed req_hdr = {0}; } __packed;
int len = sizeof(struct req_hdr) + sizeof(struct bss_info_basic);
int ret, i, features = BIT(BSS_INFO_BASIC), ntlv = 1;
u32 conn_type = 0, net_type = NETWORK_INFRA;
u8 *buf, *data, tx_wlan_idx = 0;
struct req_hdr *hdr;
struct sk_buff *skb; struct sk_buff *skb;
u16 tlv_num = 0;
u32 size = 0;
int i;
for (i = 0; i < BSS_INFO_MAX_NUM; i++) if (en) {
if ((BIT(bss_info_tag_handler[i].tag) & bss_info->feature) && len += sizeof(struct bss_info_omac);
bss_info_tag_handler[i].handler) { features |= BIT(BSS_INFO_OMAC);
tlv_num++; if (mvif->omac_idx > EXT_BSSID_START) {
size += bss_info_tag_handler[i].len; len += sizeof(struct bss_info_ext_bss);
features |= BIT(BSS_INFO_EXT_BSS);
ntlv++;
}
ntlv++;
} }
skb = mt7615_mcu_msg_alloc(NULL, sizeof(req_hdr) + size);
req_hdr.bss_idx = bss_info->bss_idx;
req_hdr.tlv_num = cpu_to_le16(tlv_num);
req_hdr.is_tlv_append = tlv_num ? 1 : 0;
memcpy(skb_put(skb, sizeof(req_hdr)), &req_hdr, sizeof(req_hdr));
for (i = 0; i < BSS_INFO_MAX_NUM; i++)
if ((BIT(bss_info_tag_handler[i].tag) & bss_info->feature) &&
bss_info_tag_handler[i].handler)
bss_info_tag_handler[i].handler(dev, bss_info, skb);
return mt7615_mcu_msg_send(dev, skb, MCU_EXT_CMD_BSS_INFO_UPDATE);
}
int mt7615_mcu_set_bss_info(struct mt7615_dev *dev,
struct ieee80211_vif *vif, int en)
{
struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
struct bss_info bss_info = {
.bss_idx = mvif->idx,
.omac_idx = mvif->omac_idx,
.band_idx = mvif->band_idx,
.bcn_interval = vif->bss_conf.beacon_int,
.dtim_period = vif->bss_conf.dtim_period,
.enable = en,
.feature = BIT(BSS_INFO_BASIC),
.wmm_idx = mvif->wmm_idx,
};
switch (vif->type) { switch (vif->type) {
case NL80211_IFTYPE_AP: case NL80211_IFTYPE_AP:
bss_info.bmc_tx_wlan_idx = mvif->sta.wcid.idx; tx_wlan_idx = mvif->sta.wcid.idx;
bss_info.network_type = NETWORK_INFRA; conn_type = CONNECTION_INFRA_AP;
bss_info.conn_type = CONNECTION_INFRA_AP;
break; break;
case NL80211_IFTYPE_STATION: { case NL80211_IFTYPE_STATION: {
/* find the unicast entry for sta mode bmc tx */ struct ieee80211_sta *sta;
struct ieee80211_sta *ap_sta;
struct mt7615_sta *msta; struct mt7615_sta *msta;
rcu_read_lock(); rcu_read_lock();
ap_sta = ieee80211_find_sta(vif, vif->bss_conf.bssid); sta = ieee80211_find_sta(vif, vif->bss_conf.bssid);
if (!ap_sta) { if (!sta) {
rcu_read_unlock(); rcu_read_unlock();
return -EINVAL; return -EINVAL;
} }
msta = (struct mt7615_sta *)ap_sta->drv_priv; msta = (struct mt7615_sta *)sta->drv_priv;
bss_info.bmc_tx_wlan_idx = msta->wcid.idx; tx_wlan_idx = msta->wcid.idx;
bss_info.network_type = NETWORK_INFRA; conn_type = CONNECTION_INFRA_STA;
bss_info.conn_type = CONNECTION_INFRA_STA;
rcu_read_unlock(); rcu_read_unlock();
break; break;
...@@ -832,15 +785,52 @@ int mt7615_mcu_set_bss_info(struct mt7615_dev *dev, ...@@ -832,15 +785,52 @@ int mt7615_mcu_set_bss_info(struct mt7615_dev *dev,
WARN_ON(1); WARN_ON(1);
break; break;
} }
memcpy(bss_info.bssid, vif->bss_conf.bssid, ETH_ALEN);
if (en) { buf = kzalloc(len, GFP_KERNEL);
bss_info.feature |= BIT(BSS_INFO_OMAC); if (!buf)
if (mvif->omac_idx > EXT_BSSID_START) return -ENOMEM;
bss_info.feature |= BIT(BSS_INFO_EXT_BSS);
hdr = (struct req_hdr *)buf;
hdr->bss_idx = mvif->idx;
hdr->tlv_num = cpu_to_le16(ntlv);
hdr->is_tlv_append = 1;
data = buf + sizeof(*hdr);
for (i = 0; i < BSS_INFO_MAX_NUM; i++) {
int tag = ffs(features & BIT(i)) - 1;
switch (tag) {
case BSS_INFO_OMAC:
mt7615_mcu_bss_info_omac_header(mvif, data,
conn_type);
data += sizeof(struct bss_info_omac);
break;
case BSS_INFO_BASIC:
mt7615_mcu_bss_info_basic_header(vif, data, net_type,
tx_wlan_idx, en);
data += sizeof(struct bss_info_basic);
break;
case BSS_INFO_EXT_BSS:
mt7615_mcu_bss_info_ext_header(mvif, data);
data += sizeof(struct bss_info_ext_bss);
break;
default:
break;
}
}
skb = mt7615_mcu_msg_alloc(buf, len);
if (!skb) {
ret = -ENOMEM;
goto out;
} }
return __mt7615_mcu_set_bss_info(dev, &bss_info); ret = mt7615_mcu_msg_send(dev, skb, MCU_EXT_CMD_BSS_INFO_UPDATE);
out:
kfree(buf);
return ret;
} }
static int static int
......
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