mcu.c (182071cdd594bc79f42899c85afa995c370ef82d) mcu.c (fc6ee71a2a8f2d183724e3f97762e93c5102425c)
1// SPDX-License-Identifier: ISC
2/* Copyright (C) 2020 MediaTek Inc. */
3
4#include <linux/fs.h>
5#include "mt7915.h"
6#include "mcu.h"
7#include "mac.h"
8#include "eeprom.h"

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

145 for (nss = 0; nss < max_nss; nss++)
146 ht_mcs[nss] = sta->deflink.ht_cap.mcs.rx_mask[nss] & mask[nss];
147}
148
149static int
150mt7915_mcu_parse_response(struct mt76_dev *mdev, int cmd,
151 struct sk_buff *skb, int seq)
152{
1// SPDX-License-Identifier: ISC
2/* Copyright (C) 2020 MediaTek Inc. */
3
4#include <linux/fs.h>
5#include "mt7915.h"
6#include "mcu.h"
7#include "mac.h"
8#include "eeprom.h"

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

145 for (nss = 0; nss < max_nss; nss++)
146 ht_mcs[nss] = sta->deflink.ht_cap.mcs.rx_mask[nss] & mask[nss];
147}
148
149static int
150mt7915_mcu_parse_response(struct mt76_dev *mdev, int cmd,
151 struct sk_buff *skb, int seq)
152{
153 struct mt7915_mcu_rxd *rxd;
153 struct mt76_connac2_mcu_rxd *rxd;
154 int ret = 0;
155
156 if (!skb) {
157 dev_err(mdev->dev, "Message %08x (seq %d) timeout\n",
158 cmd, seq);
159 return -ETIMEDOUT;
160 }
161
154 int ret = 0;
155
156 if (!skb) {
157 dev_err(mdev->dev, "Message %08x (seq %d) timeout\n",
158 cmd, seq);
159 return -ETIMEDOUT;
160 }
161
162 rxd = (struct mt7915_mcu_rxd *)skb->data;
162 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
163 if (seq != rxd->seq)
164 return -EAGAIN;
165
166 if (cmd == MCU_CMD(PATCH_SEM_CONTROL)) {
167 skb_pull(skb, sizeof(*rxd) - 4);
168 ret = *skb->data;
169 } else if (cmd == MCU_EXT_CMD(THERMAL_CTRL)) {
170 skb_pull(skb, sizeof(*rxd) + 4);
171 ret = le32_to_cpu(*(__le32 *)skb->data);
172 } else {
163 if (seq != rxd->seq)
164 return -EAGAIN;
165
166 if (cmd == MCU_CMD(PATCH_SEM_CONTROL)) {
167 skb_pull(skb, sizeof(*rxd) - 4);
168 ret = *skb->data;
169 } else if (cmd == MCU_EXT_CMD(THERMAL_CTRL)) {
170 skb_pull(skb, sizeof(*rxd) + 4);
171 ret = le32_to_cpu(*(__le32 *)skb->data);
172 } else {
173 skb_pull(skb, sizeof(struct mt7915_mcu_rxd));
173 skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd));
174 }
175
176 return ret;
177}
178
179static int
180mt7915_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb,
181 int cmd, int *wait_seq)
182{
183 struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
174 }
175
176 return ret;
177}
178
179static int
180mt7915_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb,
181 int cmd, int *wait_seq)
182{
183 struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
184 struct mt7915_mcu_txd *mcu_txd;
184 struct mt76_connac2_mcu_txd *mcu_txd;
185 enum mt76_mcuq_id qid;
186 __le32 *txd;
187 u32 val;
188 u8 seq;
189
190 /* TODO: make dynamic based on msg type */
191 mdev->mcu.timeout = 20 * HZ;
192
193 seq = ++dev->mt76.mcu.msg_seq & 0xf;
194 if (!seq)
195 seq = ++dev->mt76.mcu.msg_seq & 0xf;
196
197 if (cmd == MCU_CMD(FW_SCATTER)) {
198 qid = MT_MCUQ_FWDL;
199 goto exit;
200 }
201
185 enum mt76_mcuq_id qid;
186 __le32 *txd;
187 u32 val;
188 u8 seq;
189
190 /* TODO: make dynamic based on msg type */
191 mdev->mcu.timeout = 20 * HZ;
192
193 seq = ++dev->mt76.mcu.msg_seq & 0xf;
194 if (!seq)
195 seq = ++dev->mt76.mcu.msg_seq & 0xf;
196
197 if (cmd == MCU_CMD(FW_SCATTER)) {
198 qid = MT_MCUQ_FWDL;
199 goto exit;
200 }
201
202 mcu_txd = (struct mt7915_mcu_txd *)skb_push(skb, sizeof(*mcu_txd));
202 mcu_txd = (struct mt76_connac2_mcu_txd *)skb_push(skb, sizeof(*mcu_txd));
203 if (test_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state))
204 qid = MT_MCUQ_WA;
205 else
206 qid = MT_MCUQ_WM;
207
208 txd = mcu_txd->txd;
209
210 val = FIELD_PREP(MT_TXD0_TX_BYTES, skb->len) |

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

321 else
322 ieee80211_radar_detected(mphy->hw);
323 dev->hw_pattern++;
324}
325
326static void
327mt7915_mcu_rx_log_message(struct mt7915_dev *dev, struct sk_buff *skb)
328{
203 if (test_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state))
204 qid = MT_MCUQ_WA;
205 else
206 qid = MT_MCUQ_WM;
207
208 txd = mcu_txd->txd;
209
210 val = FIELD_PREP(MT_TXD0_TX_BYTES, skb->len) |

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

321 else
322 ieee80211_radar_detected(mphy->hw);
323 dev->hw_pattern++;
324}
325
326static void
327mt7915_mcu_rx_log_message(struct mt7915_dev *dev, struct sk_buff *skb)
328{
329 struct mt7915_mcu_rxd *rxd = (struct mt7915_mcu_rxd *)skb->data;
330 const char *data = (char *)&rxd[1];
331 const char *type;
329 struct mt76_connac2_mcu_rxd *rxd;
332 int len = skb->len - sizeof(*rxd);
330 int len = skb->len - sizeof(*rxd);
331 const char *data, *type;
333
332
333 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
334 data = (char *)&rxd[1];
335
334 switch (rxd->s2d_index) {
335 case 0:
336 if (mt7915_debugfs_rx_log(dev, data, len))
337 return;
338
339 type = "WM";
340 break;
341 case 2:

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

372 ieee80211_iterate_active_interfaces_atomic(mphy->hw,
373 IEEE80211_IFACE_ITER_RESUME_ALL,
374 mt7915_mcu_cca_finish, mphy->hw);
375}
376
377static void
378mt7915_mcu_rx_ext_event(struct mt7915_dev *dev, struct sk_buff *skb)
379{
336 switch (rxd->s2d_index) {
337 case 0:
338 if (mt7915_debugfs_rx_log(dev, data, len))
339 return;
340
341 type = "WM";
342 break;
343 case 2:

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

374 ieee80211_iterate_active_interfaces_atomic(mphy->hw,
375 IEEE80211_IFACE_ITER_RESUME_ALL,
376 mt7915_mcu_cca_finish, mphy->hw);
377}
378
379static void
380mt7915_mcu_rx_ext_event(struct mt7915_dev *dev, struct sk_buff *skb)
381{
380 struct mt7915_mcu_rxd *rxd = (struct mt7915_mcu_rxd *)skb->data;
382 struct mt76_connac2_mcu_rxd *rxd;
381
383
384 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
382 switch (rxd->ext_eid) {
383 case MCU_EXT_EVENT_THERMAL_PROTECT:
384 mt7915_mcu_rx_thermal_notify(dev, skb);
385 break;
386 case MCU_EXT_EVENT_RDD_REPORT:
387 mt7915_mcu_rx_radar_detected(dev, skb);
388 break;
389 case MCU_EXT_EVENT_CSA_NOTIFY:

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

398 default:
399 break;
400 }
401}
402
403static void
404mt7915_mcu_rx_unsolicited_event(struct mt7915_dev *dev, struct sk_buff *skb)
405{
385 switch (rxd->ext_eid) {
386 case MCU_EXT_EVENT_THERMAL_PROTECT:
387 mt7915_mcu_rx_thermal_notify(dev, skb);
388 break;
389 case MCU_EXT_EVENT_RDD_REPORT:
390 mt7915_mcu_rx_radar_detected(dev, skb);
391 break;
392 case MCU_EXT_EVENT_CSA_NOTIFY:

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

401 default:
402 break;
403 }
404}
405
406static void
407mt7915_mcu_rx_unsolicited_event(struct mt7915_dev *dev, struct sk_buff *skb)
408{
406 struct mt7915_mcu_rxd *rxd = (struct mt7915_mcu_rxd *)skb->data;
409 struct mt76_connac2_mcu_rxd *rxd;
407
410
411 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
408 switch (rxd->eid) {
409 case MCU_EVENT_EXT:
410 mt7915_mcu_rx_ext_event(dev, skb);
411 break;
412 default:
413 break;
414 }
415 dev_kfree_skb(skb);
416}
417
418void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb)
419{
412 switch (rxd->eid) {
413 case MCU_EVENT_EXT:
414 mt7915_mcu_rx_ext_event(dev, skb);
415 break;
416 default:
417 break;
418 }
419 dev_kfree_skb(skb);
420}
421
422void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb)
423{
420 struct mt7915_mcu_rxd *rxd = (struct mt7915_mcu_rxd *)skb->data;
424 struct mt76_connac2_mcu_rxd *rxd;
421
425
426 rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
422 if (rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT ||
423 rxd->ext_eid == MCU_EXT_EVENT_FW_LOG_2_HOST ||
424 rxd->ext_eid == MCU_EXT_EVENT_ASSERT_DUMP ||
425 rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC ||
426 rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY ||
427 !rxd->seq)
428 mt7915_mcu_rx_unsolicited_event(dev, skb);
429 else

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

2270
2271 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(RX_AIRTIME_CTRL), &req,
2272 sizeof(req), true);
2273}
2274
2275int mt7915_mcu_init(struct mt7915_dev *dev)
2276{
2277 static const struct mt76_mcu_ops mt7915_mcu_ops = {
427 if (rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT ||
428 rxd->ext_eid == MCU_EXT_EVENT_FW_LOG_2_HOST ||
429 rxd->ext_eid == MCU_EXT_EVENT_ASSERT_DUMP ||
430 rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC ||
431 rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY ||
432 !rxd->seq)
433 mt7915_mcu_rx_unsolicited_event(dev, skb);
434 else

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

2275
2276 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(RX_AIRTIME_CTRL), &req,
2277 sizeof(req), true);
2278}
2279
2280int mt7915_mcu_init(struct mt7915_dev *dev)
2281{
2282 static const struct mt76_mcu_ops mt7915_mcu_ops = {
2278 .headroom = sizeof(struct mt7915_mcu_txd),
2283 .headroom = sizeof(struct mt76_connac2_mcu_txd),
2279 .mcu_skb_send_msg = mt7915_mcu_send_message,
2280 .mcu_parse_response = mt7915_mcu_parse_response,
2281 .mcu_restart = mt76_connac_mcu_restart,
2282 };
2283 int ret;
2284
2285 dev->mt76.mcu_ops = &mt7915_mcu_ops;
2286

--- 1222 unchanged lines hidden ---
2284 .mcu_skb_send_msg = mt7915_mcu_send_message,
2285 .mcu_parse_response = mt7915_mcu_parse_response,
2286 .mcu_restart = mt76_connac_mcu_restart,
2287 };
2288 int ret;
2289
2290 dev->mt76.mcu_ops = &mt7915_mcu_ops;
2291

--- 1222 unchanged lines hidden ---