mac.c (b662b71ac3cccb50e9a45aae194591fc50e433ce) mac.c (4dbcb9125cc3e10a6d879c10e4f5816d05a87c49)
1// SPDX-License-Identifier: ISC
2/* Copyright (C) 2020 MediaTek Inc. */
3
4#include <linux/etherdevice.h>
5#include <linux/timekeeping.h>
1// SPDX-License-Identifier: ISC
2/* Copyright (C) 2020 MediaTek Inc. */
3
4#include <linux/etherdevice.h>
5#include <linux/timekeeping.h>
6#include "coredump.h"
6#include "mt7915.h"
7#include "../dma.h"
8#include "mac.h"
9#include "mcu.h"
10
11#define to_rssi(field, rcpi) ((FIELD_GET(field, rcpi) - 220) / 2)
12
13static const struct mt7915_dfs_radar_spec etsi_radar_specs = {

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

1615 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work,
1616 MT7915_WATCHDOG_TIME);
1617 if (phy2)
1618 ieee80211_queue_delayed_work(ext_phy->hw,
1619 &phy2->mt76->mac_work,
1620 MT7915_WATCHDOG_TIME);
1621}
1622
7#include "mt7915.h"
8#include "../dma.h"
9#include "mac.h"
10#include "mcu.h"
11
12#define to_rssi(field, rcpi) ((FIELD_GET(field, rcpi) - 220) / 2)
13
14static const struct mt7915_dfs_radar_spec etsi_radar_specs = {

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

1616 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work,
1617 MT7915_WATCHDOG_TIME);
1618 if (phy2)
1619 ieee80211_queue_delayed_work(ext_phy->hw,
1620 &phy2->mt76->mac_work,
1621 MT7915_WATCHDOG_TIME);
1622}
1623
1624/* firmware coredump */
1625void mt7915_mac_dump_work(struct work_struct *work)
1626{
1627 const struct mt7915_mem_region *mem_region;
1628 struct mt7915_crash_data *crash_data;
1629 struct mt7915_dev *dev;
1630 struct mt7915_mem_hdr *hdr;
1631 size_t buf_len;
1632 int i;
1633 u32 num;
1634 u8 *buf;
1635
1636 dev = container_of(work, struct mt7915_dev, dump_work);
1637
1638 mutex_lock(&dev->dump_mutex);
1639
1640 crash_data = mt7915_coredump_new(dev);
1641 if (!crash_data) {
1642 mutex_unlock(&dev->dump_mutex);
1643 goto skip_coredump;
1644 }
1645
1646 mem_region = mt7915_coredump_get_mem_layout(dev, &num);
1647 if (!mem_region || !crash_data->memdump_buf_len) {
1648 mutex_unlock(&dev->dump_mutex);
1649 goto skip_memdump;
1650 }
1651
1652 buf = crash_data->memdump_buf;
1653 buf_len = crash_data->memdump_buf_len;
1654
1655 /* dumping memory content... */
1656 memset(buf, 0, buf_len);
1657 for (i = 0; i < num; i++) {
1658 if (mem_region->len > buf_len) {
1659 dev_warn(dev->mt76.dev, "%s len %lu is too large\n",
1660 mem_region->name,
1661 (unsigned long)mem_region->len);
1662 break;
1663 }
1664
1665 /* reserve space for the header */
1666 hdr = (void *)buf;
1667 buf += sizeof(*hdr);
1668 buf_len -= sizeof(*hdr);
1669
1670 mt7915_memcpy_fromio(dev, buf, mem_region->start,
1671 mem_region->len);
1672
1673 hdr->start = mem_region->start;
1674 hdr->len = mem_region->len;
1675
1676 if (!mem_region->len)
1677 /* note: the header remains, just with zero length */
1678 break;
1679
1680 buf += mem_region->len;
1681 buf_len -= mem_region->len;
1682
1683 mem_region++;
1684 }
1685
1686 mutex_unlock(&dev->dump_mutex);
1687
1688skip_memdump:
1689 mt7915_coredump_submit(dev);
1690skip_coredump:
1691 queue_work(dev->mt76.wq, &dev->reset_work);
1692}
1693
1623void mt7915_reset(struct mt7915_dev *dev)
1624{
1625 if (!dev->recovery.hw_init_done)
1626 return;
1627
1628 if (dev->recovery.hw_full_reset)
1629 return;
1630
1631 /* wm/wa exception: do full recovery */
1632 if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WDT_MASK) {
1633 dev->recovery.restart = true;
1634 dev_info(dev->mt76.dev,
1635 "%s indicated firmware crash, attempting recovery\n",
1636 wiphy_name(dev->mt76.hw->wiphy));
1637
1638 mt7915_irq_disable(dev, MT_INT_MCU_CMD);
1694void mt7915_reset(struct mt7915_dev *dev)
1695{
1696 if (!dev->recovery.hw_init_done)
1697 return;
1698
1699 if (dev->recovery.hw_full_reset)
1700 return;
1701
1702 /* wm/wa exception: do full recovery */
1703 if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WDT_MASK) {
1704 dev->recovery.restart = true;
1705 dev_info(dev->mt76.dev,
1706 "%s indicated firmware crash, attempting recovery\n",
1707 wiphy_name(dev->mt76.hw->wiphy));
1708
1709 mt7915_irq_disable(dev, MT_INT_MCU_CMD);
1639 queue_work(dev->mt76.wq, &dev->reset_work);
1710 queue_work(dev->mt76.wq, &dev->dump_work);
1640 return;
1641 }
1642
1643 queue_work(dev->mt76.wq, &dev->reset_work);
1644 wake_up(&dev->reset_wait);
1645}
1646
1647void mt7915_mac_update_stats(struct mt7915_phy *phy)

--- 710 unchanged lines hidden ---
1711 return;
1712 }
1713
1714 queue_work(dev->mt76.wq, &dev->reset_work);
1715 wake_up(&dev->reset_wait);
1716}
1717
1718void mt7915_mac_update_stats(struct mt7915_phy *phy)

--- 710 unchanged lines hidden ---