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

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

64 } else {
65 skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd));
66 }
67
68 return ret;
69}
70EXPORT_SYMBOL_GPL(mt7921_mcu_parse_response);
71
1// SPDX-License-Identifier: ISC
2/* Copyright (C) 2020 MediaTek Inc. */
3
4#include <linux/fs.h>
5#include <linux/firmware.h>
6#include "mt7921.h"
7#include "mt7921_trace.h"
8#include "mcu.h"

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

64 } else {
65 skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd));
66 }
67
68 return ret;
69}
70EXPORT_SYMBOL_GPL(mt7921_mcu_parse_response);
71
72static int mt7921_mcu_read_eeprom(struct mt7921_dev *dev, u32 offset, u8 *val)
72static int mt7921_mcu_read_eeprom(struct mt792x_dev *dev, u32 offset, u8 *val)
73{
74 struct mt7921_mcu_eeprom_info *res, req = {
75 .addr = cpu_to_le32(round_down(offset,
76 MT7921_EEPROM_BLOCK_SIZE)),
77 };
78 struct sk_buff *skb;
79 int ret;
80

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

129 }
130
131 mt76_connac_mcu_set_suspend_iter(priv, mac, vif);
132}
133
134#endif /* CONFIG_PM */
135
136static void
73{
74 struct mt7921_mcu_eeprom_info *res, req = {
75 .addr = cpu_to_le32(round_down(offset,
76 MT7921_EEPROM_BLOCK_SIZE)),
77 };
78 struct sk_buff *skb;
79 int ret;
80

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

129 }
130
131 mt76_connac_mcu_set_suspend_iter(priv, mac, vif);
132}
133
134#endif /* CONFIG_PM */
135
136static void
137mt7921_mcu_uni_roc_event(struct mt7921_dev *dev, struct sk_buff *skb)
137mt7921_mcu_uni_roc_event(struct mt792x_dev *dev, struct sk_buff *skb)
138{
139 struct mt7921_roc_grant_tlv *grant;
140 struct mt76_connac2_mcu_rxd *rxd;
141 int duration;
142
143 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
144 grant = (struct mt7921_roc_grant_tlv *)(rxd->tlv + 4);
145

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

152 dev->phy.roc_grant = true;
153 wake_up(&dev->phy.roc_wait);
154 duration = le32_to_cpu(grant->max_interval);
155 mod_timer(&dev->phy.roc_timer,
156 jiffies + msecs_to_jiffies(duration));
157}
158
159static void
138{
139 struct mt7921_roc_grant_tlv *grant;
140 struct mt76_connac2_mcu_rxd *rxd;
141 int duration;
142
143 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
144 grant = (struct mt7921_roc_grant_tlv *)(rxd->tlv + 4);
145

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

152 dev->phy.roc_grant = true;
153 wake_up(&dev->phy.roc_wait);
154 duration = le32_to_cpu(grant->max_interval);
155 mod_timer(&dev->phy.roc_timer,
156 jiffies + msecs_to_jiffies(duration));
157}
158
159static void
160mt7921_mcu_scan_event(struct mt7921_dev *dev, struct sk_buff *skb)
160mt7921_mcu_scan_event(struct mt792x_dev *dev, struct sk_buff *skb)
161{
162 struct mt76_phy *mphy = &dev->mt76.phy;
163 struct mt792x_phy *phy = (struct mt792x_phy *)mphy->priv;
164
165 spin_lock_bh(&dev->mt76.lock);
166 __skb_queue_tail(&phy->scan_event_list, skb);
167 spin_unlock_bh(&dev->mt76.lock);
168

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

183 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER) ||
184 vif->type != NL80211_IFTYPE_STATION)
185 return;
186
187 ieee80211_connection_loss(vif);
188}
189
190static void
161{
162 struct mt76_phy *mphy = &dev->mt76.phy;
163 struct mt792x_phy *phy = (struct mt792x_phy *)mphy->priv;
164
165 spin_lock_bh(&dev->mt76.lock);
166 __skb_queue_tail(&phy->scan_event_list, skb);
167 spin_unlock_bh(&dev->mt76.lock);
168

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

183 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER) ||
184 vif->type != NL80211_IFTYPE_STATION)
185 return;
186
187 ieee80211_connection_loss(vif);
188}
189
190static void
191mt7921_mcu_connection_loss_event(struct mt7921_dev *dev, struct sk_buff *skb)
191mt7921_mcu_connection_loss_event(struct mt792x_dev *dev, struct sk_buff *skb)
192{
193 struct mt76_connac_beacon_loss_event *event;
194 struct mt76_phy *mphy = &dev->mt76.phy;
195
196 skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd));
197 event = (struct mt76_connac_beacon_loss_event *)skb->data;
198
199 ieee80211_iterate_active_interfaces_atomic(mphy->hw,
200 IEEE80211_IFACE_ITER_RESUME_ALL,
201 mt7921_mcu_connection_loss_iter, event);
202}
203
204static void
192{
193 struct mt76_connac_beacon_loss_event *event;
194 struct mt76_phy *mphy = &dev->mt76.phy;
195
196 skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd));
197 event = (struct mt76_connac_beacon_loss_event *)skb->data;
198
199 ieee80211_iterate_active_interfaces_atomic(mphy->hw,
200 IEEE80211_IFACE_ITER_RESUME_ALL,
201 mt7921_mcu_connection_loss_iter, event);
202}
203
204static void
205mt7921_mcu_debug_msg_event(struct mt7921_dev *dev, struct sk_buff *skb)
205mt7921_mcu_debug_msg_event(struct mt792x_dev *dev, struct sk_buff *skb)
206{
207 struct mt7921_debug_msg {
208 __le16 id;
209 u8 type;
210 u8 flag;
211 __le32 value;
212 __le16 len;
213 u8 content[512];

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

224 if (!msg->content[i])
225 msg->content[i] = ' ';
226 }
227 wiphy_info(mt76_hw(dev)->wiphy, "%.*s", len, msg->content);
228 }
229}
230
231static void
206{
207 struct mt7921_debug_msg {
208 __le16 id;
209 u8 type;
210 u8 flag;
211 __le32 value;
212 __le16 len;
213 u8 content[512];

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

224 if (!msg->content[i])
225 msg->content[i] = ' ';
226 }
227 wiphy_info(mt76_hw(dev)->wiphy, "%.*s", len, msg->content);
228 }
229}
230
231static void
232mt7921_mcu_low_power_event(struct mt7921_dev *dev, struct sk_buff *skb)
232mt7921_mcu_low_power_event(struct mt792x_dev *dev, struct sk_buff *skb)
233{
234 struct mt7921_mcu_lp_event {
235 u8 state;
236 u8 reserved[3];
237 } __packed * event;
238
239 skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd));
240 event = (struct mt7921_mcu_lp_event *)skb->data;
241
242 trace_lp_event(dev, event->state);
243}
244
245static void
233{
234 struct mt7921_mcu_lp_event {
235 u8 state;
236 u8 reserved[3];
237 } __packed * event;
238
239 skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd));
240 event = (struct mt7921_mcu_lp_event *)skb->data;
241
242 trace_lp_event(dev, event->state);
243}
244
245static void
246mt7921_mcu_tx_done_event(struct mt7921_dev *dev, struct sk_buff *skb)
246mt7921_mcu_tx_done_event(struct mt792x_dev *dev, struct sk_buff *skb)
247{
248 struct mt7921_mcu_tx_done_event *event;
249
250 skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd));
251 event = (struct mt7921_mcu_tx_done_event *)skb->data;
252
253 mt7921_mac_add_txs(dev, event->txs);
254}
255
256static void
247{
248 struct mt7921_mcu_tx_done_event *event;
249
250 skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd));
251 event = (struct mt7921_mcu_tx_done_event *)skb->data;
252
253 mt7921_mac_add_txs(dev, event->txs);
254}
255
256static void
257mt7921_mcu_rx_unsolicited_event(struct mt7921_dev *dev, struct sk_buff *skb)
257mt7921_mcu_rx_unsolicited_event(struct mt792x_dev *dev, struct sk_buff *skb)
258{
259 struct mt76_connac2_mcu_rxd *rxd;
260
261 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
262 switch (rxd->eid) {
263 case MCU_EVENT_BSS_BEACON_LOSS:
264 mt7921_mcu_connection_loss_event(dev, skb);
265 break;

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

283 break;
284 default:
285 break;
286 }
287 dev_kfree_skb(skb);
288}
289
290static void
258{
259 struct mt76_connac2_mcu_rxd *rxd;
260
261 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
262 switch (rxd->eid) {
263 case MCU_EVENT_BSS_BEACON_LOSS:
264 mt7921_mcu_connection_loss_event(dev, skb);
265 break;

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

283 break;
284 default:
285 break;
286 }
287 dev_kfree_skb(skb);
288}
289
290static void
291mt7921_mcu_uni_rx_unsolicited_event(struct mt7921_dev *dev,
291mt7921_mcu_uni_rx_unsolicited_event(struct mt792x_dev *dev,
292 struct sk_buff *skb)
293{
294 struct mt76_connac2_mcu_rxd *rxd;
295
296 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
297
298 switch (rxd->eid) {
299 case MCU_UNI_EVENT_ROC:
300 mt7921_mcu_uni_roc_event(dev, skb);
301 break;
302 default:
303 break;
304 }
305 dev_kfree_skb(skb);
306}
307
292 struct sk_buff *skb)
293{
294 struct mt76_connac2_mcu_rxd *rxd;
295
296 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
297
298 switch (rxd->eid) {
299 case MCU_UNI_EVENT_ROC:
300 mt7921_mcu_uni_roc_event(dev, skb);
301 break;
302 default:
303 break;
304 }
305 dev_kfree_skb(skb);
306}
307
308void mt7921_mcu_rx_event(struct mt7921_dev *dev, struct sk_buff *skb)
308void mt7921_mcu_rx_event(struct mt792x_dev *dev, struct sk_buff *skb)
309{
310 struct mt76_connac2_mcu_rxd *rxd;
311
312 if (skb_linearize(skb))
313 return;
314
315 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
316

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

334 rxd->eid == MCU_EVENT_LP_INFO ||
335 !rxd->seq)
336 mt7921_mcu_rx_unsolicited_event(dev, skb);
337 else
338 mt76_mcu_rx_event(&dev->mt76, skb);
339}
340
341/** starec & wtbl **/
309{
310 struct mt76_connac2_mcu_rxd *rxd;
311
312 if (skb_linearize(skb))
313 return;
314
315 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
316

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

334 rxd->eid == MCU_EVENT_LP_INFO ||
335 !rxd->seq)
336 mt7921_mcu_rx_unsolicited_event(dev, skb);
337 else
338 mt76_mcu_rx_event(&dev->mt76, skb);
339}
340
341/** starec & wtbl **/
342int mt7921_mcu_uni_tx_ba(struct mt7921_dev *dev,
342int mt7921_mcu_uni_tx_ba(struct mt792x_dev *dev,
343 struct ieee80211_ampdu_params *params,
344 bool enable)
345{
346 struct mt792x_sta *msta = (struct mt792x_sta *)params->sta->drv_priv;
347
348 if (enable && !params->amsdu)
349 msta->wcid.amsdu = false;
350
351 return mt76_connac_mcu_sta_ba(&dev->mt76, &msta->vif->mt76, params,
352 MCU_UNI_CMD(STA_REC_UPDATE),
353 enable, true);
354}
355
343 struct ieee80211_ampdu_params *params,
344 bool enable)
345{
346 struct mt792x_sta *msta = (struct mt792x_sta *)params->sta->drv_priv;
347
348 if (enable && !params->amsdu)
349 msta->wcid.amsdu = false;
350
351 return mt76_connac_mcu_sta_ba(&dev->mt76, &msta->vif->mt76, params,
352 MCU_UNI_CMD(STA_REC_UPDATE),
353 enable, true);
354}
355
356int mt7921_mcu_uni_rx_ba(struct mt7921_dev *dev,
356int mt7921_mcu_uni_rx_ba(struct mt792x_dev *dev,
357 struct ieee80211_ampdu_params *params,
358 bool enable)
359{
360 struct mt792x_sta *msta = (struct mt792x_sta *)params->sta->drv_priv;
361
362 return mt76_connac_mcu_sta_ba(&dev->mt76, &msta->vif->mt76, params,
363 MCU_UNI_CMD(STA_REC_UPDATE),
364 enable, false);
365}
366
357 struct ieee80211_ampdu_params *params,
358 bool enable)
359{
360 struct mt792x_sta *msta = (struct mt792x_sta *)params->sta->drv_priv;
361
362 return mt76_connac_mcu_sta_ba(&dev->mt76, &msta->vif->mt76, params,
363 MCU_UNI_CMD(STA_REC_UPDATE),
364 enable, false);
365}
366
367static char *mt7921_patch_name(struct mt7921_dev *dev)
367static char *mt7921_patch_name(struct mt792x_dev *dev)
368{
369 char *ret;
370
371 if (is_mt7922(&dev->mt76))
372 ret = MT7922_ROM_PATCH;
373 else
374 ret = MT7921_ROM_PATCH;
375
376 return ret;
377}
378
368{
369 char *ret;
370
371 if (is_mt7922(&dev->mt76))
372 ret = MT7922_ROM_PATCH;
373 else
374 ret = MT7921_ROM_PATCH;
375
376 return ret;
377}
378
379static char *mt7921_ram_name(struct mt7921_dev *dev)
379static char *mt7921_ram_name(struct mt792x_dev *dev)
380{
381 char *ret;
382
383 if (is_mt7922(&dev->mt76))
384 ret = MT7922_FIRMWARE_WM;
385 else
386 ret = MT7921_FIRMWARE_WM;
387
388 return ret;
389}
390
380{
381 char *ret;
382
383 if (is_mt7922(&dev->mt76))
384 ret = MT7922_FIRMWARE_WM;
385 else
386 ret = MT7921_FIRMWARE_WM;
387
388 return ret;
389}
390
391static int mt7921_load_clc(struct mt7921_dev *dev, const char *fw_name)
391static int mt7921_load_clc(struct mt792x_dev *dev, const char *fw_name)
392{
393 const struct mt76_connac2_fw_trailer *hdr;
394 const struct mt76_connac2_fw_region *region;
395 const struct mt7921_clc *clc;
396 struct mt76_dev *mdev = &dev->mt76;
397 struct mt792x_phy *phy = &dev->phy;
398 const struct firmware *fw;
399 int ret, i, len, offset = 0;

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

467 }
468 ret = mt7921_mcu_set_clc(dev, "00", ENVIRON_INDOOR);
469out:
470 release_firmware(fw);
471
472 return ret;
473}
474
392{
393 const struct mt76_connac2_fw_trailer *hdr;
394 const struct mt76_connac2_fw_region *region;
395 const struct mt7921_clc *clc;
396 struct mt76_dev *mdev = &dev->mt76;
397 struct mt792x_phy *phy = &dev->phy;
398 const struct firmware *fw;
399 int ret, i, len, offset = 0;

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

467 }
468 ret = mt7921_mcu_set_clc(dev, "00", ENVIRON_INDOOR);
469out:
470 release_firmware(fw);
471
472 return ret;
473}
474
475static int mt7921_load_firmware(struct mt7921_dev *dev)
475static int mt7921_load_firmware(struct mt792x_dev *dev)
476{
477 int ret;
478
479 ret = mt76_connac2_load_patch(&dev->mt76, mt7921_patch_name(dev));
480 if (ret)
481 return ret;
482
483 if (mt76_is_sdio(&dev->mt76)) {

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

502 dev->mt76.hw->wiphy->wowlan = &mt76_connac_wowlan_support;
503#endif /* CONFIG_PM */
504
505 dev_dbg(dev->mt76.dev, "Firmware init done\n");
506
507 return 0;
508}
509
476{
477 int ret;
478
479 ret = mt76_connac2_load_patch(&dev->mt76, mt7921_patch_name(dev));
480 if (ret)
481 return ret;
482
483 if (mt76_is_sdio(&dev->mt76)) {

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

502 dev->mt76.hw->wiphy->wowlan = &mt76_connac_wowlan_support;
503#endif /* CONFIG_PM */
504
505 dev_dbg(dev->mt76.dev, "Firmware init done\n");
506
507 return 0;
508}
509
510int mt7921_mcu_fw_log_2_host(struct mt7921_dev *dev, u8 ctrl)
510int mt7921_mcu_fw_log_2_host(struct mt792x_dev *dev, u8 ctrl)
511{
512 struct {
513 u8 ctrl_val;
514 u8 pad[3];
515 } data = {
516 .ctrl_val = ctrl
517 };
518
519 return mt76_mcu_send_msg(&dev->mt76, MCU_CE_CMD(FWLOG_2_HOST),
520 &data, sizeof(data), false);
521}
522
511{
512 struct {
513 u8 ctrl_val;
514 u8 pad[3];
515 } data = {
516 .ctrl_val = ctrl
517 };
518
519 return mt76_mcu_send_msg(&dev->mt76, MCU_CE_CMD(FWLOG_2_HOST),
520 &data, sizeof(data), false);
521}
522
523int mt7921_run_firmware(struct mt7921_dev *dev)
523int mt7921_run_firmware(struct mt792x_dev *dev)
524{
525 int err;
526
527 err = mt7921_load_firmware(dev);
528 if (err)
529 return err;
530
531 err = mt76_connac_mcu_get_nic_capability(&dev->mphy);

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

536 err = mt7921_load_clc(dev, mt7921_ram_name(dev));
537 if (err)
538 return err;
539
540 return mt7921_mcu_fw_log_2_host(dev, 1);
541}
542EXPORT_SYMBOL_GPL(mt7921_run_firmware);
543
524{
525 int err;
526
527 err = mt7921_load_firmware(dev);
528 if (err)
529 return err;
530
531 err = mt76_connac_mcu_get_nic_capability(&dev->mphy);

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

536 err = mt7921_load_clc(dev, mt7921_ram_name(dev));
537 if (err)
538 return err;
539
540 return mt7921_mcu_fw_log_2_host(dev, 1);
541}
542EXPORT_SYMBOL_GPL(mt7921_run_firmware);
543
544int mt7921_mcu_set_tx(struct mt7921_dev *dev, struct ieee80211_vif *vif)
544int mt7921_mcu_set_tx(struct mt792x_dev *dev, struct ieee80211_vif *vif)
545{
546 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
547 struct edca {
548 __le16 cw_min;
549 __le16 cw_max;
550 __le16 txop;
551 __le16 aifs;
552 u8 guardtime;

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

635 &req_mu, sizeof(req_mu), false);
636}
637
638int mt7921_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_vif *vif,
639 struct ieee80211_channel *chan, int duration,
640 enum mt7921_roc_req type, u8 token_id)
641{
642 int center_ch = ieee80211_frequency_to_channel(chan->center_freq);
545{
546 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
547 struct edca {
548 __le16 cw_min;
549 __le16 cw_max;
550 __le16 txop;
551 __le16 aifs;
552 u8 guardtime;

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

635 &req_mu, sizeof(req_mu), false);
636}
637
638int mt7921_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_vif *vif,
639 struct ieee80211_channel *chan, int duration,
640 enum mt7921_roc_req type, u8 token_id)
641{
642 int center_ch = ieee80211_frequency_to_channel(chan->center_freq);
643 struct mt7921_dev *dev = phy->dev;
643 struct mt792x_dev *dev = phy->dev;
644 struct {
645 struct {
646 u8 rsv[4];
647 } __packed hdr;
648 struct roc_acquire_tlv {
649 __le16 tag;
650 __le16 len;
651 u8 bss_idx;

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

700
701 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(ROC),
702 &req, sizeof(req), false);
703}
704
705int mt7921_mcu_abort_roc(struct mt792x_phy *phy, struct mt792x_vif *vif,
706 u8 token_id)
707{
644 struct {
645 struct {
646 u8 rsv[4];
647 } __packed hdr;
648 struct roc_acquire_tlv {
649 __le16 tag;
650 __le16 len;
651 u8 bss_idx;

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

700
701 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(ROC),
702 &req, sizeof(req), false);
703}
704
705int mt7921_mcu_abort_roc(struct mt792x_phy *phy, struct mt792x_vif *vif,
706 u8 token_id)
707{
708 struct mt7921_dev *dev = phy->dev;
708 struct mt792x_dev *dev = phy->dev;
709 struct {
710 struct {
711 u8 rsv[4];
712 } __packed hdr;
713 struct roc_abort_tlv {
714 __le16 tag;
715 __le16 len;
716 u8 bss_idx;

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

729 };
730
731 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(ROC),
732 &req, sizeof(req), false);
733}
734
735int mt7921_mcu_set_chan_info(struct mt792x_phy *phy, int cmd)
736{
709 struct {
710 struct {
711 u8 rsv[4];
712 } __packed hdr;
713 struct roc_abort_tlv {
714 __le16 tag;
715 __le16 len;
716 u8 bss_idx;

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

729 };
730
731 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(ROC),
732 &req, sizeof(req), false);
733}
734
735int mt7921_mcu_set_chan_info(struct mt792x_phy *phy, int cmd)
736{
737 struct mt7921_dev *dev = phy->dev;
737 struct mt792x_dev *dev = phy->dev;
738 struct cfg80211_chan_def *chandef = &phy->mt76->chandef;
739 int freq1 = chandef->center_freq1;
740 struct {
741 u8 control_ch;
742 u8 center_ch;
743 u8 bw;
744 u8 tx_streams_num;
745 u8 rx_streams; /* mask or num */

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

786 int freq2 = chandef->center_freq2;
787
788 req.center_ch2 = ieee80211_frequency_to_channel(freq2);
789 }
790
791 return mt76_mcu_send_msg(&dev->mt76, cmd, &req, sizeof(req), true);
792}
793
738 struct cfg80211_chan_def *chandef = &phy->mt76->chandef;
739 int freq1 = chandef->center_freq1;
740 struct {
741 u8 control_ch;
742 u8 center_ch;
743 u8 bw;
744 u8 tx_streams_num;
745 u8 rx_streams; /* mask or num */

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

786 int freq2 = chandef->center_freq2;
787
788 req.center_ch2 = ieee80211_frequency_to_channel(freq2);
789 }
790
791 return mt76_mcu_send_msg(&dev->mt76, cmd, &req, sizeof(req), true);
792}
793
794int mt7921_mcu_set_eeprom(struct mt7921_dev *dev)
794int mt7921_mcu_set_eeprom(struct mt792x_dev *dev)
795{
796 struct req_hdr {
797 u8 buffer_mode;
798 u8 format;
799 __le16 len;
800 } __packed req = {
801 .buffer_mode = EE_MODE_EFUSE,
802 .format = EE_FORMAT_WHOLE,
803 };
804
805 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EFUSE_BUFFER_MODE),
806 &req, sizeof(req), true);
807}
808EXPORT_SYMBOL_GPL(mt7921_mcu_set_eeprom);
809
795{
796 struct req_hdr {
797 u8 buffer_mode;
798 u8 format;
799 __le16 len;
800 } __packed req = {
801 .buffer_mode = EE_MODE_EFUSE,
802 .format = EE_FORMAT_WHOLE,
803 };
804
805 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EFUSE_BUFFER_MODE),
806 &req, sizeof(req), true);
807}
808EXPORT_SYMBOL_GPL(mt7921_mcu_set_eeprom);
809
810int mt7921_mcu_uni_bss_ps(struct mt7921_dev *dev, struct ieee80211_vif *vif)
810int mt7921_mcu_uni_bss_ps(struct mt792x_dev *dev, struct ieee80211_vif *vif)
811{
812 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
813 struct {
814 struct {
815 u8 bss_idx;
816 u8 pad[3];
817 } __packed hdr;
818 struct ps_tlv {

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

840 if (vif->type != NL80211_IFTYPE_STATION)
841 return -EOPNOTSUPP;
842
843 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE),
844 &ps_req, sizeof(ps_req), true);
845}
846
847static int
811{
812 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
813 struct {
814 struct {
815 u8 bss_idx;
816 u8 pad[3];
817 } __packed hdr;
818 struct ps_tlv {

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

840 if (vif->type != NL80211_IFTYPE_STATION)
841 return -EOPNOTSUPP;
842
843 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE),
844 &ps_req, sizeof(ps_req), true);
845}
846
847static int
848mt7921_mcu_uni_bss_bcnft(struct mt7921_dev *dev, struct ieee80211_vif *vif,
848mt7921_mcu_uni_bss_bcnft(struct mt792x_dev *dev, struct ieee80211_vif *vif,
849 bool enable)
850{
851 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
852 struct {
853 struct {
854 u8 bss_idx;
855 u8 pad[3];
856 } __packed hdr;

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

876 if (vif->type != NL80211_IFTYPE_STATION)
877 return 0;
878
879 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE),
880 &bcnft_req, sizeof(bcnft_req), true);
881}
882
883int
849 bool enable)
850{
851 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
852 struct {
853 struct {
854 u8 bss_idx;
855 u8 pad[3];
856 } __packed hdr;

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

876 if (vif->type != NL80211_IFTYPE_STATION)
877 return 0;
878
879 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE),
880 &bcnft_req, sizeof(bcnft_req), true);
881}
882
883int
884mt7921_mcu_set_bss_pm(struct mt7921_dev *dev, struct ieee80211_vif *vif,
884mt7921_mcu_set_bss_pm(struct mt792x_dev *dev, struct ieee80211_vif *vif,
885 bool enable)
886{
887 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
888 struct {
889 u8 bss_idx;
890 u8 dtim_period;
891 __le16 aid;
892 __le16 bcn_interval;

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

913 &req_hdr, sizeof(req_hdr), false);
914 if (err < 0 || !enable)
915 return err;
916
917 return mt76_mcu_send_msg(&dev->mt76, MCU_CE_CMD(SET_BSS_CONNECTED),
918 &req, sizeof(req), false);
919}
920
885 bool enable)
886{
887 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
888 struct {
889 u8 bss_idx;
890 u8 dtim_period;
891 __le16 aid;
892 __le16 bcn_interval;

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

913 &req_hdr, sizeof(req_hdr), false);
914 if (err < 0 || !enable)
915 return err;
916
917 return mt76_mcu_send_msg(&dev->mt76, MCU_CE_CMD(SET_BSS_CONNECTED),
918 &req, sizeof(req), false);
919}
920
921int mt7921_mcu_sta_update(struct mt7921_dev *dev, struct ieee80211_sta *sta,
921int mt7921_mcu_sta_update(struct mt792x_dev *dev, struct ieee80211_sta *sta,
922 struct ieee80211_vif *vif, bool enable,
923 enum mt76_sta_info_state state)
924{
925 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
926 int rssi = -ewma_rssi_read(&mvif->rssi);
927 struct mt76_sta_cmd_info info = {
928 .sta = sta,
929 .vif = vif,

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

937
938 msta = sta ? (struct mt792x_sta *)sta->drv_priv : NULL;
939 info.wcid = msta ? &msta->wcid : &mvif->sta.wcid;
940 info.newly = msta ? state != MT76_STA_INFO_STATE_ASSOC : true;
941
942 return mt76_connac_mcu_sta_cmd(&dev->mphy, &info);
943}
944
922 struct ieee80211_vif *vif, bool enable,
923 enum mt76_sta_info_state state)
924{
925 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
926 int rssi = -ewma_rssi_read(&mvif->rssi);
927 struct mt76_sta_cmd_info info = {
928 .sta = sta,
929 .vif = vif,

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

937
938 msta = sta ? (struct mt792x_sta *)sta->drv_priv : NULL;
939 info.wcid = msta ? &msta->wcid : &mvif->sta.wcid;
940 info.newly = msta ? state != MT76_STA_INFO_STATE_ASSOC : true;
941
942 return mt76_connac_mcu_sta_cmd(&dev->mphy, &info);
943}
944
945int mt7921_mcu_drv_pmctrl(struct mt7921_dev *dev)
945int mt7921_mcu_drv_pmctrl(struct mt792x_dev *dev)
946{
947 struct mt76_phy *mphy = &dev->mt76.phy;
948 struct mt76_connac_pm *pm = &dev->pm;
949 int err = 0;
950
951 mutex_lock(&pm->mutex);
952
953 if (!test_bit(MT76_STATE_PM, &mphy->state))

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

959
960 if (err)
961 mt7921_reset(&dev->mt76);
962
963 return err;
964}
965EXPORT_SYMBOL_GPL(mt7921_mcu_drv_pmctrl);
966
946{
947 struct mt76_phy *mphy = &dev->mt76.phy;
948 struct mt76_connac_pm *pm = &dev->pm;
949 int err = 0;
950
951 mutex_lock(&pm->mutex);
952
953 if (!test_bit(MT76_STATE_PM, &mphy->state))

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

959
960 if (err)
961 mt7921_reset(&dev->mt76);
962
963 return err;
964}
965EXPORT_SYMBOL_GPL(mt7921_mcu_drv_pmctrl);
966
967int mt7921_mcu_fw_pmctrl(struct mt7921_dev *dev)
967int mt7921_mcu_fw_pmctrl(struct mt792x_dev *dev)
968{
969 struct mt76_phy *mphy = &dev->mt76.phy;
970 struct mt76_connac_pm *pm = &dev->pm;
971 int err = 0;
972
973 mutex_lock(&pm->mutex);
974
975 if (mt76_connac_skip_fw_pmctrl(mphy, pm))

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

981
982 if (err)
983 mt7921_reset(&dev->mt76);
984
985 return err;
986}
987EXPORT_SYMBOL_GPL(mt7921_mcu_fw_pmctrl);
988
968{
969 struct mt76_phy *mphy = &dev->mt76.phy;
970 struct mt76_connac_pm *pm = &dev->pm;
971 int err = 0;
972
973 mutex_lock(&pm->mutex);
974
975 if (mt76_connac_skip_fw_pmctrl(mphy, pm))

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

981
982 if (err)
983 mt7921_reset(&dev->mt76);
984
985 return err;
986}
987EXPORT_SYMBOL_GPL(mt7921_mcu_fw_pmctrl);
988
989int mt7921_mcu_set_beacon_filter(struct mt7921_dev *dev,
989int mt7921_mcu_set_beacon_filter(struct mt792x_dev *dev,
990 struct ieee80211_vif *vif,
991 bool enable)
992{
993#define MT7921_FIF_BIT_CLR BIT(1)
994#define MT7921_FIF_BIT_SET BIT(0)
995 int err;
996
997 if (enable) {

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

1016 MT7921_FIF_BIT_CLR,
1017 MT_WF_RFCR_DROP_OTHER_BEACON);
1018 if (err)
1019 return err;
1020
1021 return 0;
1022}
1023
990 struct ieee80211_vif *vif,
991 bool enable)
992{
993#define MT7921_FIF_BIT_CLR BIT(1)
994#define MT7921_FIF_BIT_SET BIT(0)
995 int err;
996
997 if (enable) {

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

1016 MT7921_FIF_BIT_CLR,
1017 MT_WF_RFCR_DROP_OTHER_BEACON);
1018 if (err)
1019 return err;
1020
1021 return 0;
1022}
1023
1024int mt7921_get_txpwr_info(struct mt7921_dev *dev, struct mt7921_txpwr *txpwr)
1024int mt7921_get_txpwr_info(struct mt792x_dev *dev, struct mt7921_txpwr *txpwr)
1025{
1026 struct mt7921_txpwr_event *event;
1027 struct mt7921_txpwr_req req = {
1028 .dbdc_idx = 0,
1029 };
1030 struct sk_buff *skb;
1031 int ret;
1032

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

1039 WARN_ON(skb->len != le16_to_cpu(event->len));
1040 memcpy(txpwr, &event->txpwr, sizeof(event->txpwr));
1041
1042 dev_kfree_skb(skb);
1043
1044 return 0;
1045}
1046
1025{
1026 struct mt7921_txpwr_event *event;
1027 struct mt7921_txpwr_req req = {
1028 .dbdc_idx = 0,
1029 };
1030 struct sk_buff *skb;
1031 int ret;
1032

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

1039 WARN_ON(skb->len != le16_to_cpu(event->len));
1040 memcpy(txpwr, &event->txpwr, sizeof(event->txpwr));
1041
1042 dev_kfree_skb(skb);
1043
1044 return 0;
1045}
1046
1047int mt7921_mcu_set_sniffer(struct mt7921_dev *dev, struct ieee80211_vif *vif,
1047int mt7921_mcu_set_sniffer(struct mt792x_dev *dev, struct ieee80211_vif *vif,
1048 bool enable)
1049{
1050 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
1051 struct {
1052 struct {
1053 u8 band_idx;
1054 u8 pad[3];
1055 } __packed hdr;

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

1138 else if (req.tlv.control_ch > req.tlv.center_ch)
1139 req.tlv.sco = 3; /* SCB */
1140
1141 return mt76_mcu_send_msg(vif->phy->mt76->dev, MCU_UNI_CMD(SNIFFER),
1142 &req, sizeof(req), true);
1143}
1144
1145int
1048 bool enable)
1049{
1050 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
1051 struct {
1052 struct {
1053 u8 band_idx;
1054 u8 pad[3];
1055 } __packed hdr;

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

1138 else if (req.tlv.control_ch > req.tlv.center_ch)
1139 req.tlv.sco = 3; /* SCB */
1140
1141 return mt76_mcu_send_msg(vif->phy->mt76->dev, MCU_UNI_CMD(SNIFFER),
1142 &req, sizeof(req), true);
1143}
1144
1145int
1146mt7921_mcu_uni_add_beacon_offload(struct mt7921_dev *dev,
1146mt7921_mcu_uni_add_beacon_offload(struct mt792x_dev *dev,
1147 struct ieee80211_hw *hw,
1148 struct ieee80211_vif *vif,
1149 bool enable)
1150{
1151 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1152 struct mt76_wcid *wcid = &dev->mt76.global_wcid;
1153 struct ieee80211_mutable_offsets offs;
1154 struct {

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

1216 }
1217 dev_kfree_skb(skb);
1218
1219 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE),
1220 &req, sizeof(req), true);
1221}
1222
1223static
1147 struct ieee80211_hw *hw,
1148 struct ieee80211_vif *vif,
1149 bool enable)
1150{
1151 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1152 struct mt76_wcid *wcid = &dev->mt76.global_wcid;
1153 struct ieee80211_mutable_offsets offs;
1154 struct {

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

1216 }
1217 dev_kfree_skb(skb);
1218
1219 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE),
1220 &req, sizeof(req), true);
1221}
1222
1223static
1224int __mt7921_mcu_set_clc(struct mt7921_dev *dev, u8 *alpha2,
1224int __mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2,
1225 enum environment_cap env_cap,
1226 struct mt7921_clc *clc,
1227 u8 idx)
1228{
1229 struct sk_buff *skb;
1230 struct {
1231 u8 ver;
1232 u8 pad0;

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

1278 }
1279
1280 if (!valid_cnt)
1281 return -ENOENT;
1282
1283 return 0;
1284}
1285
1225 enum environment_cap env_cap,
1226 struct mt7921_clc *clc,
1227 u8 idx)
1228{
1229 struct sk_buff *skb;
1230 struct {
1231 u8 ver;
1232 u8 pad0;

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

1278 }
1279
1280 if (!valid_cnt)
1281 return -ENOENT;
1282
1283 return 0;
1284}
1285
1286int mt7921_mcu_set_clc(struct mt7921_dev *dev, u8 *alpha2,
1286int mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2,
1287 enum environment_cap env_cap)
1288{
1289 struct mt792x_phy *phy = (struct mt792x_phy *)&dev->phy;
1290 int i, ret;
1291
1292 /* submit all clc config */
1293 for (i = 0; i < ARRAY_SIZE(phy->clc); i++) {
1294 ret = __mt7921_mcu_set_clc(dev, alpha2, env_cap,

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

1302 if (ret < 0)
1303 return ret;
1304 }
1305 return 0;
1306}
1307
1308int mt7921_mcu_get_temperature(struct mt792x_phy *phy)
1309{
1287 enum environment_cap env_cap)
1288{
1289 struct mt792x_phy *phy = (struct mt792x_phy *)&dev->phy;
1290 int i, ret;
1291
1292 /* submit all clc config */
1293 for (i = 0; i < ARRAY_SIZE(phy->clc); i++) {
1294 ret = __mt7921_mcu_set_clc(dev, alpha2, env_cap,

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

1302 if (ret < 0)
1303 return ret;
1304 }
1305 return 0;
1306}
1307
1308int mt7921_mcu_get_temperature(struct mt792x_phy *phy)
1309{
1310 struct mt7921_dev *dev = phy->dev;
1310 struct mt792x_dev *dev = phy->dev;
1311 struct {
1312 u8 ctrl_id;
1313 u8 action;
1314 u8 band_idx;
1315 u8 rsv[5];
1316 } req = {
1317 .ctrl_id = THERMAL_SENSOR_TEMP_QUERY,
1318 .band_idx = phy->mt76->band_idx,
1319 };
1320
1321 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_CTRL), &req,
1322 sizeof(req), true);
1323}
1324
1311 struct {
1312 u8 ctrl_id;
1313 u8 action;
1314 u8 band_idx;
1315 u8 rsv[5];
1316 } req = {
1317 .ctrl_id = THERMAL_SENSOR_TEMP_QUERY,
1318 .band_idx = phy->mt76->band_idx,
1319 };
1320
1321 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_CTRL), &req,
1322 sizeof(req), true);
1323}
1324
1325int mt7921_mcu_set_rxfilter(struct mt7921_dev *dev, u32 fif,
1325int mt7921_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif,
1326 u8 bit_op, u32 bit_map)
1327{
1328 struct {
1329 u8 rsv[4];
1330 u8 mode;
1331 u8 rsv2[3];
1332 __le32 fif;
1333 __le32 bit_map; /* bit_* for bitmap update */

--- 12 unchanged lines hidden ---
1326 u8 bit_op, u32 bit_map)
1327{
1328 struct {
1329 u8 rsv[4];
1330 u8 mode;
1331 u8 rsv2[3];
1332 __le32 fif;
1333 __le32 bit_map; /* bit_* for bitmap update */

--- 12 unchanged lines hidden ---