All of lore.kernel.org
 help / color / mirror / Atom feed
From: viktor.barna@celeno.com
To: linux-wireless@vger.kernel.org
Cc: Kalle Valo <kvalo@codeaurora.org>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Aviad Brikman <aviad.brikman@celeno.com>,
	Eliav Farber <eliav.farber@gmail.com>,
	Maksym Kokhan <maksym.kokhan@celeno.com>,
	Oleksandr Savchenko <oleksandr.savchenko@celeno.com>,
	Shay Bar <shay.bar@celeno.com>,
	Viktor Barna <viktor.barna@celeno.com>
Subject: [RFC v2 60/96] cl8k: add recovery.c
Date: Tue, 24 May 2022 14:34:26 +0300	[thread overview]
Message-ID: <20220524113502.1094459-61-viktor.barna@celeno.com> (raw)
In-Reply-To: <20220524113502.1094459-1-viktor.barna@celeno.com>

From: Viktor Barna <viktor.barna@celeno.com>

(Part of the split. Please, take a look at the cover letter for more
details).

Signed-off-by: Viktor Barna <viktor.barna@celeno.com>
---
 drivers/net/wireless/celeno/cl8k/recovery.c | 280 ++++++++++++++++++++
 1 file changed, 280 insertions(+)
 create mode 100644 drivers/net/wireless/celeno/cl8k/recovery.c

diff --git a/drivers/net/wireless/celeno/cl8k/recovery.c b/drivers/net/wireless/celeno/cl8k/recovery.c
new file mode 100644
index 000000000000..dc0c33be9200
--- /dev/null
+++ b/drivers/net/wireless/celeno/cl8k/recovery.c
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/* Copyright(c) 2019-2022, Celeno Communications Ltd. */
+
+#include "hw.h"
+#include "main.h"
+#include "phy.h"
+#include "vif.h"
+#include "dfs.h"
+#include "maintenance.h"
+#include "vns.h"
+#include "config.h"
+#include "ela.h"
+#include "radio.h"
+#include "recovery.h"
+
+struct cl_recovery_work {
+	struct work_struct ws;
+	struct cl_hw *cl_hw;
+	int reason;
+};
+
+#define RECOVERY_POLL_TIMEOUT 6
+
+static void cl_recovery_poll_completion(struct cl_hw *cl_hw)
+{
+	u8 cntr = 0;
+
+	while (test_bit(CL_DEV_SW_RESTART, &cl_hw->drv_flags)) {
+		msleep(1000);
+
+		if (++cntr == RECOVERY_POLL_TIMEOUT) {
+			cl_dbg_verbose(cl_hw, "\n");
+			cl_dbg_err(cl_hw, "Driver handgup was detected!...");
+			break;
+		}
+	}
+}
+
+static void cl_recovery_start_hw(struct cl_hw *cl_hw)
+{
+	clear_bit(CL_DEV_STOP_HW, &cl_hw->drv_flags);
+
+	/* Restart MAC firmware... */
+	if (cl_main_on(cl_hw)) {
+		cl_dbg_err(cl_hw, "Couldn't turn platform on .. aborting\n");
+		return;
+	}
+
+	if (cl_msg_tx_reset(cl_hw)) {
+		cl_dbg_err(cl_hw, "Failed to send firmware reset .. aborting\n");
+		return;
+	}
+
+	set_bit(CL_DEV_SW_RESTART, &cl_hw->drv_flags);
+	clear_bit(CL_DEV_HW_RESTART, &cl_hw->drv_flags);
+
+	/* Hand over to mac80211 from here */
+	ieee80211_restart_hw(cl_hw->hw);
+	/* Start firmware */
+	if (cl_msg_tx_start(cl_hw)) {
+		cl_dbg_err(cl_hw, "Failed to send firmware start .. aborting\n");
+		return;
+	}
+
+	cl_recovery_poll_completion(cl_hw);
+}
+
+static void cl_recovery_stop_hw(struct cl_hw *cl_hw)
+{
+	/* Start recovery process */
+	ieee80211_stop_queues(cl_hw->hw);
+	cl_hw->recovery_db.in_recovery = true;
+
+	clear_bit(CL_DEV_STARTED, &cl_hw->drv_flags);
+	set_bit(CL_DEV_HW_RESTART, &cl_hw->drv_flags);
+	set_bit(CL_DEV_STOP_HW, &cl_hw->drv_flags);
+	/* Disable interrupts */
+	cl_irq_disable(cl_hw, cl_hw->ipc_e2a_irq.all);
+	cl_maintenance_stop(cl_hw);
+
+	mutex_lock(&cl_hw->dbginfo.mutex);
+
+	cl_main_off(cl_hw);
+
+	cl_hw->fw_active = false;
+	cl_hw->fw_send_start = false;
+
+	mutex_unlock(&cl_hw->dbginfo.mutex);
+
+	/* Reset it so MM_SET_FILTER_REQ will be called during the recovery */
+	cl_hw->rx_filter = 0;
+
+	/*
+	 * Reset channel/frequency parameters so that cl_msg_tx_set_channel()
+	 * will not be skipped in cl_ops_config()
+	 */
+	cl_hw->channel = 0;
+	cl_hw->primary_freq = 0;
+	cl_hw->center_freq = 0;
+}
+
+static void cl_recovery_process(struct cl_hw *cl_hw)
+{
+	int ret;
+	struct cl_chip *chip = cl_hw->chip;
+
+	mutex_lock(&chip->recovery_mutex);
+
+	cl_dbg_verbose(cl_hw, "Start\n");
+
+	cl_recovery_stop_hw(cl_hw);
+
+	if (chip->conf->ci_phy_dev != PHY_DEV_DUMMY) {
+		cl_phy_reset(cl_hw);
+
+		ret = cl_phy_load_recovery(cl_hw);
+		if (ret) {
+			cl_dbg_err(cl_hw, "cl_phy_load_recovery failed %d\n", ret);
+			goto out;
+		}
+	}
+
+	cl_recovery_start_hw(cl_hw);
+
+out:
+	mutex_unlock(&chip->recovery_mutex);
+}
+
+static void cl_recovery_handler(struct cl_hw *cl_hw, int reason)
+{
+	unsigned long recovery_diff = jiffies_to_msecs(jiffies - cl_hw->recovery_db.last_restart);
+
+	cl_hw->recovery_db.restart_cnt++;
+
+	if (recovery_diff > cl_hw->conf->ce_fw_watchdog_limit_time) {
+		cl_hw->recovery_db.restart_cnt = 1;
+	} else if (cl_hw->recovery_db.restart_cnt > cl_hw->conf->ce_fw_watchdog_limit_count) {
+		cl_dbg_verbose(cl_hw, "Too many failures... aborting\n");
+		cl_hw->conf->ce_fw_watchdog_mode = FW_WD_DISABLE;
+		return;
+	}
+
+	cl_hw->recovery_db.last_restart = jiffies;
+
+	/* Count recovery attempts for statistics */
+	cl_hw->fw_recovery_cntr++;
+	cl_dbg_trace(cl_hw, "Recovering from firmware failure, attempt #%i\n",
+		     cl_hw->fw_recovery_cntr);
+
+	cl_recovery_process(cl_hw);
+}
+
+static void cl_recovery_work_do(struct work_struct *ws)
+{
+	/* Worker for restarting hw. */
+	struct cl_recovery_work *recovery_work = container_of(ws, struct cl_recovery_work, ws);
+
+	recovery_work->cl_hw->assert_info.restart_sched = false;
+	cl_recovery_handler(recovery_work->cl_hw, recovery_work->reason);
+	kfree(recovery_work);
+}
+
+static void cl_recovery_work_sched(struct cl_hw *cl_hw, int reason)
+{
+	/*
+	 * Schedule work to restart device and firmware
+	 * This is scheduled when driver detects hw assert storm.
+	 */
+	struct cl_recovery_work *recovery_work;
+
+	if (!cl_hw->ipc_env || cl_hw->is_stop_context) {
+		cl_dbg_warn(cl_hw, "Skip recovery - Running down!\n");
+		return;
+	}
+
+	/* If restart is already scheduled - exit */
+	if (cl_hw->assert_info.restart_sched)
+		return;
+
+	cl_hw->assert_info.restart_sched = true;
+
+	/* Recovery_work will be freed by cl_recovery_work_do */
+	recovery_work = kzalloc(sizeof(*recovery_work), GFP_ATOMIC);
+
+	if (!recovery_work)
+		return;
+
+	INIT_WORK(&recovery_work->ws, cl_recovery_work_do);
+	recovery_work->cl_hw = cl_hw;
+	recovery_work->reason = reason;
+
+	queue_work(cl_hw->drv_workqueue, &recovery_work->ws);
+}
+
+bool cl_recovery_in_progress(struct cl_hw *cl_hw)
+{
+	return cl_hw->recovery_db.in_recovery;
+}
+
+void cl_recovery_reconfig_complete(struct cl_hw *cl_hw)
+{
+	clear_bit(CL_DEV_SW_RESTART, &cl_hw->drv_flags);
+
+	if (cl_ela_is_on(cl_hw->chip)) {
+		cl_ela_lcu_reset(cl_hw->chip);
+		cl_ela_lcu_apply_config(cl_hw->chip);
+	}
+
+#ifdef CONFIG_CL8K_DYN_MCAST_RATE
+	cl_dyn_mcast_rate_recovery(cl_hw);
+
+#endif /* CONFIG_CL8K_DYN_MCAST_RATE */
+#ifdef CONFIG_CL8K_DYN_BCAST_RATE
+	cl_dyn_bcast_rate_recovery(cl_hw);
+
+#endif /* CONFIG_CL8K_DYN_BCAST_RATE */
+	/* DFS recovery */
+	cl_dfs_recovery(cl_hw);
+
+	/* VNS recovery */
+	cl_vns_recovery(cl_hw);
+
+	/* Restore EDCA configuration */
+	cl_edca_recovery(cl_hw);
+
+	/* Temperature  recovery */
+	cl_temperature_recovery(cl_hw);
+
+	/* Sounding recovery */
+	cl_sounding_recovery(cl_hw);
+
+	/*
+	 * Update Tx params for all connected stations to sync firmware after the
+	 * recovery process. Should be called after cl_mu_ofdma_grp_recovery to let
+	 * MU-OFDMA rates in FW be updated successfully
+	 */
+	cl_wrs_api_recovery(cl_hw);
+
+	/* Enable maintenance timers back */
+	cl_maintenance_start(cl_hw);
+	if (cl_radio_is_on(cl_hw)) {
+		/*
+		 * Rearm last_tbtt_ind so that error message will
+		 * not be printed in cl_irq_status_tbtt()
+		 */
+		cl_hw->last_tbtt_irq = jiffies;
+
+		cl_msg_tx_set_idle(cl_hw, MAC_ACTIVE, true);
+	}
+
+	cl_hw->recovery_db.in_recovery = false;
+
+	pr_debug("cl_recovery: complete\n");
+
+	cl_rx_post_recovery(cl_hw);
+}
+
+void cl_recovery_start(struct cl_hw *cl_hw, int reason)
+{
+	/* Prevent new messages to be sent until firmware has recovered */
+	set_bit(CL_DEV_FW_ERROR, &cl_hw->drv_flags);
+
+	switch (cl_hw->conf->ce_fw_watchdog_mode) {
+	case FW_WD_DISABLE:
+		cl_dbg_info(cl_hw, "Skip recovery - Watchdog is off!\n");
+		break;
+
+	case FW_WD_INTERNAL_RECOVERY:
+		cl_recovery_work_sched(cl_hw, reason);
+		break;
+
+	case FW_WD_DRV_RELOAD:
+		/* TODO: Implement netlink hint to the userspace */
+		cl_dbg_info(cl_hw, "RELOAD handler is absent, doing nothing");
+		break;
+
+	default:
+		break;
+	}
+}
-- 
2.36.1


  parent reply	other threads:[~2022-05-24 11:39 UTC|newest]

Thread overview: 125+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-24 11:33 [RFC v2 00/96] wireless: cl8k driver for Celeno IEEE 802.11ax devices viktor.barna
2022-05-24 11:33 ` [RFC v2 01/96] celeno: add Kconfig viktor.barna
2022-05-24 11:33 ` [RFC v2 02/96] celeno: add Makefile viktor.barna
2022-05-24 11:33 ` [RFC v2 03/96] cl8k: add Kconfig viktor.barna
2022-05-26 18:18   ` Johannes Berg
2022-05-27  6:09     ` Kalle Valo
2022-07-11 23:04       ` Viktor Barna
2022-07-13  7:32   ` Kalle Valo
2022-05-24 11:33 ` [RFC v2 04/96] cl8k: add Makefile viktor.barna
2022-05-26 18:24   ` Johannes Berg
2022-07-13  7:39   ` Kalle Valo
2022-05-24 11:33 ` [RFC v2 05/96] cl8k: add ampdu.c viktor.barna
2022-05-26 18:19   ` Johannes Berg
2022-05-26 18:22   ` Johannes Berg
2022-05-24 11:33 ` [RFC v2 06/96] cl8k: add ampdu.h viktor.barna
2022-05-24 11:33 ` [RFC v2 07/96] cl8k: add bf.c viktor.barna
2022-05-24 17:24   ` Jeff Johnson
2022-05-24 11:33 ` [RFC v2 08/96] cl8k: add bf.h viktor.barna
2022-05-24 11:33 ` [RFC v2 09/96] cl8k: add calib.c viktor.barna
2022-05-24 11:33 ` [RFC v2 10/96] cl8k: add calib.h viktor.barna
2022-05-24 11:33 ` [RFC v2 11/96] cl8k: add channel.c viktor.barna
2022-05-24 11:33 ` [RFC v2 12/96] cl8k: add channel.h viktor.barna
2022-05-24 11:33 ` [RFC v2 13/96] cl8k: add chip.c viktor.barna
2022-05-24 11:33 ` [RFC v2 14/96] cl8k: add chip.h viktor.barna
2022-05-24 11:33 ` [RFC v2 15/96] cl8k: add config.c viktor.barna
2022-05-24 11:33 ` [RFC v2 16/96] cl8k: add config.h viktor.barna
2022-05-25 18:31   ` Jeff Johnson
2022-05-24 11:33 ` [RFC v2 17/96] cl8k: add debug.c viktor.barna
2022-05-24 11:33 ` [RFC v2 18/96] cl8k: add debug.h viktor.barna
2022-05-24 11:33 ` [RFC v2 19/96] cl8k: add def.h viktor.barna
2022-05-25 18:39   ` Jeff Johnson
2022-05-24 11:33 ` [RFC v2 20/96] cl8k: add dfs.c viktor.barna
2022-05-24 11:33 ` [RFC v2 21/96] cl8k: add dfs.h viktor.barna
2022-05-24 11:33 ` [RFC v2 22/96] cl8k: add dsp.c viktor.barna
2022-05-24 11:33 ` [RFC v2 23/96] cl8k: add dsp.h viktor.barna
2022-05-24 11:33 ` [RFC v2 24/96] cl8k: add e2p.c viktor.barna
2022-05-24 11:33 ` [RFC v2 25/96] cl8k: add e2p.h viktor.barna
2022-05-24 11:33 ` [RFC v2 26/96] cl8k: add eeprom.h viktor.barna
2022-05-24 11:33 ` [RFC v2 27/96] cl8k: add ela.c viktor.barna
2022-05-24 11:33 ` [RFC v2 28/96] cl8k: add ela.h viktor.barna
2022-05-24 11:33 ` [RFC v2 29/96] cl8k: add enhanced_tim.c viktor.barna
2022-05-24 11:33 ` [RFC v2 30/96] cl8k: add enhanced_tim.h viktor.barna
2022-05-24 11:33 ` [RFC v2 31/96] cl8k: add fw.c viktor.barna
2022-05-24 11:33 ` [RFC v2 32/96] cl8k: add fw.h viktor.barna
2022-05-25 18:58   ` Jeff Johnson
2022-05-24 11:33 ` [RFC v2 33/96] cl8k: add hw.c viktor.barna
2022-05-24 11:34 ` [RFC v2 34/96] cl8k: add hw.h viktor.barna
2022-05-24 11:34 ` [RFC v2 35/96] cl8k: add ipc_shared.h viktor.barna
2022-05-24 11:34 ` [RFC v2 36/96] cl8k: add key.c viktor.barna
2022-05-26 19:38   ` Johannes Berg
2022-07-11 23:10     ` Viktor Barna
2022-05-24 11:34 ` [RFC v2 37/96] cl8k: add key.h viktor.barna
2022-05-24 11:34 ` [RFC v2 38/96] cl8k: add mac80211.c viktor.barna
2022-05-26 19:49   ` Johannes Berg
2022-07-11 23:13     ` Viktor Barna
2022-05-24 11:34 ` [RFC v2 39/96] cl8k: add mac80211.h viktor.barna
2022-05-26 19:52   ` Johannes Berg
2022-05-24 11:34 ` [RFC v2 40/96] cl8k: add mac_addr.c viktor.barna
2022-05-26 22:31   ` Jeff Johnson
2022-05-24 11:34 ` [RFC v2 41/96] cl8k: add mac_addr.h viktor.barna
2022-05-24 11:34 ` [RFC v2 42/96] cl8k: add main.c viktor.barna
2022-05-26 23:01   ` Jeff Johnson
2022-05-24 11:34 ` [RFC v2 43/96] cl8k: add main.h viktor.barna
2022-05-24 11:34 ` [RFC v2 44/96] cl8k: add maintenance.c viktor.barna
2022-05-24 11:34 ` [RFC v2 45/96] cl8k: add maintenance.h viktor.barna
2022-05-24 11:34 ` [RFC v2 46/96] cl8k: add motion_sense.c viktor.barna
2022-05-24 11:34 ` [RFC v2 47/96] cl8k: add motion_sense.h viktor.barna
2022-05-24 11:34 ` [RFC v2 48/96] cl8k: add pci.c viktor.barna
2022-05-24 11:34 ` [RFC v2 49/96] cl8k: add pci.h viktor.barna
2022-05-24 11:34 ` [RFC v2 50/96] cl8k: add phy.c viktor.barna
2022-06-01  0:27   ` Jeff Johnson
2022-07-11 23:16     ` Viktor Barna
2022-05-24 11:34 ` [RFC v2 51/96] cl8k: add phy.h viktor.barna
2022-05-24 11:34 ` [RFC v2 52/96] cl8k: add platform.c viktor.barna
2022-05-24 11:34 ` [RFC v2 53/96] cl8k: add platform.h viktor.barna
2022-05-24 11:34 ` [RFC v2 54/96] cl8k: add power.c viktor.barna
2022-05-24 11:34 ` [RFC v2 55/96] cl8k: add power.h viktor.barna
2022-05-24 11:34 ` [RFC v2 56/96] cl8k: add radio.c viktor.barna
2022-05-24 11:34 ` [RFC v2 57/96] cl8k: add radio.h viktor.barna
2022-05-24 11:34 ` [RFC v2 58/96] cl8k: add rates.c viktor.barna
2022-05-24 11:34 ` [RFC v2 59/96] cl8k: add rates.h viktor.barna
2022-05-26 19:54   ` Johannes Berg
2022-07-11 23:17     ` Viktor Barna
2022-07-12  7:17       ` Johannes Berg
2022-05-24 11:34 ` viktor.barna [this message]
2022-05-24 11:34 ` [RFC v2 61/96] cl8k: add recovery.h viktor.barna
2022-05-24 11:34 ` [RFC v2 62/96] cl8k: add regdom.c viktor.barna
2022-05-24 11:34 ` [RFC v2 63/96] cl8k: add regdom.h viktor.barna
2022-05-24 11:34 ` [RFC v2 64/96] cl8k: add reg/reg_access.h viktor.barna
2022-05-24 11:34 ` [RFC v2 65/96] cl8k: add reg/reg_defs.h viktor.barna
2022-05-24 11:34 ` [RFC v2 66/96] cl8k: add rfic.c viktor.barna
2022-05-24 11:34 ` [RFC v2 67/96] cl8k: add rfic.h viktor.barna
2022-06-02 20:40   ` Jeff Johnson
2022-07-11 23:18     ` Viktor Barna
2022-05-24 11:34 ` [RFC v2 68/96] cl8k: add rx.c viktor.barna
2022-05-24 11:34 ` [RFC v2 69/96] cl8k: add rx.h viktor.barna
2022-05-24 11:34 ` [RFC v2 70/96] cl8k: add scan.c viktor.barna
2022-05-24 11:34 ` [RFC v2 71/96] cl8k: add scan.h viktor.barna
2022-05-24 11:34 ` [RFC v2 72/96] cl8k: add sounding.c viktor.barna
2022-05-24 11:34 ` [RFC v2 73/96] cl8k: add sounding.h viktor.barna
2022-05-24 11:34 ` [RFC v2 74/96] cl8k: add sta.c viktor.barna
2022-05-24 11:34 ` [RFC v2 75/96] cl8k: add sta.h viktor.barna
2022-05-24 11:34 ` [RFC v2 76/96] cl8k: add stats.c viktor.barna
2022-06-02 20:59   ` Jeff Johnson
2022-07-11 23:20     ` Viktor Barna
2022-05-24 11:34 ` [RFC v2 77/96] cl8k: add stats.h viktor.barna
2022-05-24 11:34 ` [RFC v2 78/96] cl8k: add tcv.c viktor.barna
2022-05-24 11:34 ` [RFC v2 79/96] cl8k: add tcv.h viktor.barna
2022-05-24 11:34 ` [RFC v2 80/96] cl8k: add temperature.c viktor.barna
2022-05-24 11:34 ` [RFC v2 81/96] cl8k: add temperature.h viktor.barna
2022-05-24 11:34 ` [RFC v2 82/96] cl8k: add traffic.c viktor.barna
2022-05-24 11:34 ` [RFC v2 83/96] cl8k: add traffic.h viktor.barna
2022-05-24 11:34 ` [RFC v2 84/96] cl8k: add tx.c viktor.barna
2022-05-24 11:34 ` [RFC v2 85/96] cl8k: add tx.h viktor.barna
2022-05-24 11:34 ` [RFC v2 86/96] cl8k: add utils.c viktor.barna
2022-05-24 11:34 ` [RFC v2 87/96] cl8k: add utils.h viktor.barna
2022-05-24 11:34 ` [RFC v2 88/96] cl8k: add version.c viktor.barna
2022-05-24 11:34 ` [RFC v2 89/96] cl8k: add version.h viktor.barna
2022-05-24 11:34 ` [RFC v2 90/96] cl8k: add vif.c viktor.barna
2022-05-24 11:34 ` [RFC v2 91/96] cl8k: add vif.h viktor.barna
2022-05-24 11:34 ` [RFC v2 92/96] cl8k: add vns.c viktor.barna
2022-05-24 11:34 ` [RFC v2 93/96] cl8k: add vns.h viktor.barna
2022-05-24 11:35 ` [RFC v2 94/96] cl8k: add wrs.c viktor.barna
2022-05-24 11:35 ` [RFC v2 95/96] cl8k: add wrs.h viktor.barna
2022-05-24 11:35 ` [RFC v2 96/96] wireless: add Celeno vendor viktor.barna

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220524113502.1094459-61-viktor.barna@celeno.com \
    --to=viktor.barna@celeno.com \
    --cc=aviad.brikman@celeno.com \
    --cc=davem@davemloft.net \
    --cc=eliav.farber@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=maksym.kokhan@celeno.com \
    --cc=oleksandr.savchenko@celeno.com \
    --cc=shay.bar@celeno.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.