mcu.c (5472240245793c13e9986c61dd34c697296deed4) mcu.c (680a2ead741ad9b479a53adf154ed5eee74d2b9a)
1// SPDX-License-Identifier: ISC
2/* Copyright (C) 2020 MediaTek Inc. */
3
4#include <linux/firmware.h>
5#include <linux/fs.h>
6#include "mt7921.h"
7#include "mt7921_trace.h"
8#include "mcu.h"

--- 149 unchanged lines hidden (view full) ---

158 memcpy(buf, res->data, 16);
159
160 return 0;
161}
162
163int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd,
164 struct sk_buff *skb, int seq)
165{
1// SPDX-License-Identifier: ISC
2/* Copyright (C) 2020 MediaTek Inc. */
3
4#include <linux/firmware.h>
5#include <linux/fs.h>
6#include "mt7921.h"
7#include "mt7921_trace.h"
8#include "mcu.h"

--- 149 unchanged lines hidden (view full) ---

158 memcpy(buf, res->data, 16);
159
160 return 0;
161}
162
163int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd,
164 struct sk_buff *skb, int seq)
165{
166 int mcu_cmd = FIELD_GET(__MCU_CMD_FIELD_ID, cmd);
166 struct mt7921_mcu_rxd *rxd;
167 struct mt7921_mcu_rxd *rxd;
167 int mcu_cmd = cmd & MCU_CMD_MASK;
168 int ret = 0;
169
170 if (!skb) {
171 dev_err(mdev->dev, "Message %08x (seq %d) timeout\n",
172 cmd, seq);
173 mt7921_reset(mdev);
174
175 return -ETIMEDOUT;

--- 20 unchanged lines hidden (view full) ---

196 struct mt7921_mcu_uni_event *event;
197
198 skb_pull(skb, sizeof(*rxd));
199 event = (struct mt7921_mcu_uni_event *)skb->data;
200 ret = le32_to_cpu(event->status);
201 /* skip invalid event */
202 if (mcu_cmd != event->cid)
203 ret = -EAGAIN;
168 int ret = 0;
169
170 if (!skb) {
171 dev_err(mdev->dev, "Message %08x (seq %d) timeout\n",
172 cmd, seq);
173 mt7921_reset(mdev);
174
175 return -ETIMEDOUT;

--- 20 unchanged lines hidden (view full) ---

196 struct mt7921_mcu_uni_event *event;
197
198 skb_pull(skb, sizeof(*rxd));
199 event = (struct mt7921_mcu_uni_event *)skb->data;
200 ret = le32_to_cpu(event->status);
201 /* skip invalid event */
202 if (mcu_cmd != event->cid)
203 ret = -EAGAIN;
204 } else if (cmd == MCU_CMD_REG_READ) {
204 } else if (cmd == MCU_CE_QUERY(REG_READ)) {
205 struct mt7921_mcu_reg_event *event;
206
207 skb_pull(skb, sizeof(*rxd));
208 event = (struct mt7921_mcu_reg_event *)skb->data;
209 ret = (int)le32_to_cpu(event->val);
210 } else {
211 skb_pull(skb, sizeof(struct mt7921_mcu_rxd));
212 }

--- 56 unchanged lines hidden (view full) ---

269 mcu_txd->pq_id = cpu_to_le16(MCU_PQ_ID(MT_TX_PORT_IDX_MCU,
270 MT_TX_MCU_PORT_RX_Q0));
271 mcu_txd->pkt_type = MCU_PKT_ID;
272 mcu_txd->seq = seq;
273 mcu_txd->cid = mcu_cmd;
274 mcu_txd->s2d_index = MCU_S2D_H2N;
275 mcu_txd->ext_cid = FIELD_GET(__MCU_CMD_FIELD_EXT_ID, cmd);
276
205 struct mt7921_mcu_reg_event *event;
206
207 skb_pull(skb, sizeof(*rxd));
208 event = (struct mt7921_mcu_reg_event *)skb->data;
209 ret = (int)le32_to_cpu(event->val);
210 } else {
211 skb_pull(skb, sizeof(struct mt7921_mcu_rxd));
212 }

--- 56 unchanged lines hidden (view full) ---

269 mcu_txd->pq_id = cpu_to_le16(MCU_PQ_ID(MT_TX_PORT_IDX_MCU,
270 MT_TX_MCU_PORT_RX_Q0));
271 mcu_txd->pkt_type = MCU_PKT_ID;
272 mcu_txd->seq = seq;
273 mcu_txd->cid = mcu_cmd;
274 mcu_txd->s2d_index = MCU_S2D_H2N;
275 mcu_txd->ext_cid = FIELD_GET(__MCU_CMD_FIELD_EXT_ID, cmd);
276
277 if (mcu_txd->ext_cid || (cmd & MCU_CE_PREFIX)) {
277 if (mcu_txd->ext_cid || (cmd & __MCU_CMD_FIELD_CE)) {
278 if (cmd & __MCU_CMD_FIELD_QUERY)
279 mcu_txd->set_query = MCU_Q_QUERY;
280 else
281 mcu_txd->set_query = MCU_Q_SET;
282 mcu_txd->ext_cid_ack = !!mcu_txd->ext_cid;
283 } else {
284 mcu_txd->set_query = MCU_Q_NA;
285 }

--- 603 unchanged lines hidden (view full) ---

889{
890 struct {
891 u8 ctrl_val;
892 u8 pad[3];
893 } data = {
894 .ctrl_val = ctrl
895 };
896
278 if (cmd & __MCU_CMD_FIELD_QUERY)
279 mcu_txd->set_query = MCU_Q_QUERY;
280 else
281 mcu_txd->set_query = MCU_Q_SET;
282 mcu_txd->ext_cid_ack = !!mcu_txd->ext_cid;
283 } else {
284 mcu_txd->set_query = MCU_Q_NA;
285 }

--- 603 unchanged lines hidden (view full) ---

889{
890 struct {
891 u8 ctrl_val;
892 u8 pad[3];
893 } data = {
894 .ctrl_val = ctrl
895 };
896
897 return mt76_mcu_send_msg(&dev->mt76, MCU_CMD_FWLOG_2_HOST, &data,
898 sizeof(data), false);
897 return mt76_mcu_send_msg(&dev->mt76, MCU_CE_CMD(FWLOG_2_HOST),
898 &data, sizeof(data), false);
899}
900
901int mt7921_run_firmware(struct mt7921_dev *dev)
902{
903 int err;
904
905 err = mt7921_load_firmware(dev);
906 if (err)

--- 108 unchanged lines hidden (view full) ---

1015 e = &(req_mu.edca[to_aci[ac]]);
1016
1017 e->cw_min = q->ecw_min_max & 0xf;
1018 e->cw_max = (q->ecw_min_max & 0xf0) >> 4;
1019 e->aifsn = q->aifsn;
1020 e->timer = q->mu_edca_timer;
1021 }
1022
899}
900
901int mt7921_run_firmware(struct mt7921_dev *dev)
902{
903 int err;
904
905 err = mt7921_load_firmware(dev);
906 if (err)

--- 108 unchanged lines hidden (view full) ---

1015 e = &(req_mu.edca[to_aci[ac]]);
1016
1017 e->cw_min = q->ecw_min_max & 0xf;
1018 e->cw_max = (q->ecw_min_max & 0xf0) >> 4;
1019 e->aifsn = q->aifsn;
1020 e->timer = q->mu_edca_timer;
1021 }
1022
1023 return mt76_mcu_send_msg(&dev->mt76, MCU_CMD_SET_MU_EDCA_PARMS, &req_mu,
1024 sizeof(req_mu), false);
1023 return mt76_mcu_send_msg(&dev->mt76, MCU_CE_CMD(SET_MU_EDCA_PARMS),
1024 &req_mu, sizeof(req_mu), false);
1025}
1026
1027int mt7921_mcu_set_chan_info(struct mt7921_phy *phy, int cmd)
1028{
1029 struct mt7921_dev *dev = phy->dev;
1030 struct cfg80211_chan_def *chandef = &phy->mt76->chandef;
1031 int freq1 = chandef->center_freq1;
1032 struct {

--- 187 unchanged lines hidden (view full) ---

1220 } req_hdr = {
1221 .bss_idx = mvif->mt76.idx,
1222 };
1223 int err;
1224
1225 if (vif->type != NL80211_IFTYPE_STATION)
1226 return 0;
1227
1025}
1026
1027int mt7921_mcu_set_chan_info(struct mt7921_phy *phy, int cmd)
1028{
1029 struct mt7921_dev *dev = phy->dev;
1030 struct cfg80211_chan_def *chandef = &phy->mt76->chandef;
1031 int freq1 = chandef->center_freq1;
1032 struct {

--- 187 unchanged lines hidden (view full) ---

1220 } req_hdr = {
1221 .bss_idx = mvif->mt76.idx,
1222 };
1223 int err;
1224
1225 if (vif->type != NL80211_IFTYPE_STATION)
1226 return 0;
1227
1228 err = mt76_mcu_send_msg(&dev->mt76, MCU_CMD_SET_BSS_ABORT, &req_hdr,
1229 sizeof(req_hdr), false);
1228 err = mt76_mcu_send_msg(&dev->mt76, MCU_CE_CMD(SET_BSS_ABORT),
1229 &req_hdr, sizeof(req_hdr), false);
1230 if (err < 0 || !enable)
1231 return err;
1232
1230 if (err < 0 || !enable)
1231 return err;
1232
1233 return mt76_mcu_send_msg(&dev->mt76, MCU_CMD_SET_BSS_CONNECTED, &req,
1234 sizeof(req), false);
1233 return mt76_mcu_send_msg(&dev->mt76, MCU_CE_CMD(SET_BSS_CONNECTED),
1234 &req, sizeof(req), false);
1235}
1236
1237int mt7921_mcu_sta_update(struct mt7921_dev *dev, struct ieee80211_sta *sta,
1238 struct ieee80211_vif *vif, bool enable,
1239 enum mt76_sta_info_state state)
1240{
1241 struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
1242 int rssi = -ewma_rssi_read(&mvif->rssi);

--- 93 unchanged lines hidden (view full) ---

1336{
1337 struct mt7921_txpwr_event *event;
1338 struct mt7921_txpwr_req req = {
1339 .dbdc_idx = 0,
1340 };
1341 struct sk_buff *skb;
1342 int ret;
1343
1235}
1236
1237int mt7921_mcu_sta_update(struct mt7921_dev *dev, struct ieee80211_sta *sta,
1238 struct ieee80211_vif *vif, bool enable,
1239 enum mt76_sta_info_state state)
1240{
1241 struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
1242 int rssi = -ewma_rssi_read(&mvif->rssi);

--- 93 unchanged lines hidden (view full) ---

1336{
1337 struct mt7921_txpwr_event *event;
1338 struct mt7921_txpwr_req req = {
1339 .dbdc_idx = 0,
1340 };
1341 struct sk_buff *skb;
1342 int ret;
1343
1344 ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_CMD_GET_TXPWR,
1344 ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_CE_CMD(GET_TXPWR),
1345 &req, sizeof(req), true, &skb);
1346 if (ret)
1347 return ret;
1348
1349 event = (struct mt7921_txpwr_event *)skb->data;
1350 WARN_ON(skb->len != le16_to_cpu(event->len));
1351 memcpy(txpwr, &event->txpwr, sizeof(event->txpwr));
1352
1353 dev_kfree_skb(skb);
1354
1355 return 0;
1356}
1345 &req, sizeof(req), true, &skb);
1346 if (ret)
1347 return ret;
1348
1349 event = (struct mt7921_txpwr_event *)skb->data;
1350 WARN_ON(skb->len != le16_to_cpu(event->len));
1351 memcpy(txpwr, &event->txpwr, sizeof(event->txpwr));
1352
1353 dev_kfree_skb(skb);
1354
1355 return 0;
1356}