From patchwork Thu Jun 17 15:58:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viktor Barna X-Patchwork-Id: 462769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A37EC48BE5 for ; Thu, 17 Jun 2021 16:04:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 402CB61351 for ; Thu, 17 Jun 2021 16:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229673AbhFQQGN (ORCPT ); Thu, 17 Jun 2021 12:06:13 -0400 Received: from mail-vi1eur05on2081.outbound.protection.outlook.com ([40.107.21.81]:58626 "EHLO EUR05-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233642AbhFQQF6 (ORCPT ); Thu, 17 Jun 2021 12:05:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g4kY3X90oCTYrehGnLP3poI1oaiPNAbCiZtszK2yyzFIqF9EAI+LU2sV7yhcMy+g8u4Wv0fm6+oSdrkmIQcNGXYxWsvCxQeaofPKuYz2NiEwFPSSBVhj3uySnuW8grC6Jd3Zco4SpbgyxLB5FsJOR0Bs7TnLXuB/XGRJUQoZBwsZEAvMH+yJZutUo1gagY9QvEHIhHqIndDmEWUrC2KmyvXChkpB2OCA9/YCqUPGdESo32cbgT5OlCfea8aW15liAGcc/o2x5mgNj4NUW1VAVsk7yA37TT18CU3dRhO5fYz5OccMJuxnRkR8liADGlocqc22XW7DQiPls6fGG2xbdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JjFgC45B9R8TkOP7PpbZinh56CrNG68HSy4ON8jZySE=; b=Zv2oZ9B3rIsxnN29mRGepr1fBeZcITrlI82m1fCNfIkRSBncrubpoxQsHKg0O/m8PAXPhSrkb1hi31kj5BRktAGlYxwtaxqfZeEK+6P4EBdVx7rSMY+07mC2mtF52GJZPDSFzmZhsx9k9mjhnFuefcQdP7034Gz15EP0oGT0KuB8HpruIdnjKCM+bzj44rdFx/Rg1yDeRaPnZ1+us6OUWC9iq2o2+3A/HmbDlYItGpPhaPhb/8xXPzJ2qffjQ7fgo833HIsJqUqCDsjG3Ja8hW3NhK/o3j3kwG5UHMdAX3e6Jf8TaFlQhAJuViZ3Pxf2YH70QLTI/Nk/RgoVbt+IMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=celeno.com; dmarc=pass action=none header.from=celeno.com; dkim=pass header.d=celeno.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=celeno.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JjFgC45B9R8TkOP7PpbZinh56CrNG68HSy4ON8jZySE=; b=NQJHMfrD0svJAf0jWbKX7Z8VwFdpowT55s6pinVCK91dNxqyBJIaUkJWwbj3kyeM5hA8VaIxhGhqhy/NCGHyBMZOQwMTScEJcL3WVxUo/0IL4NFBYcHfSJ3d+YRDCQnJ/W5c8vvxuOKVfIdCufXoduIx37eONPX4sQFUb0Yqc2M= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=celeno.com; Received: from AM9P192MB1412.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:38b::16) by AM0P192MB0499.EURP192.PROD.OUTLOOK.COM (2603:10a6:208:4e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.15; Thu, 17 Jun 2021 16:03:44 +0000 Received: from AM9P192MB1412.EURP192.PROD.OUTLOOK.COM ([fe80::1847:5583:4db7:102f]) by AM9P192MB1412.EURP192.PROD.OUTLOOK.COM ([fe80::1847:5583:4db7:102f%4]) with mapi id 15.20.4242.021; Thu, 17 Jun 2021 16:03:44 +0000 From: viktor.barna@celeno.com To: linux-wireless@vger.kernel.org Cc: Kalle Valo , "David S . Miller" , Jakub Kicinski , Aviad Brikman , Eliav Farber , Oleksandr Savchenko , Shay Bar , Viktor Barna Subject: [RFC v1 048/256] cl8k: add coredump.c Date: Thu, 17 Jun 2021 15:58:55 +0000 Message-Id: <20210617160223.160998-49-viktor.barna@celeno.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210617160223.160998-1-viktor.barna@celeno.com> References: <20210617160223.160998-1-viktor.barna@celeno.com> X-Originating-IP: [62.216.42.54] X-ClientProxiedBy: PR3PR09CA0018.eurprd09.prod.outlook.com (2603:10a6:102:b7::23) To AM9P192MB1412.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:38b::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (62.216.42.54) by PR3PR09CA0018.eurprd09.prod.outlook.com (2603:10a6:102:b7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.18 via Frontend Transport; Thu, 17 Jun 2021 16:03:25 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2f70d0a6-4c6c-45a3-3b39-08d931a970e5 X-MS-TrafficTypeDiagnostic: AM0P192MB0499: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uDsU2DsoUPgnTTfWPhRegFX26+XTZUzcR9iicxapvBCcba1crylMQf9RAi0WcKaaKo9LyCpYw8PM/XACnBnf0t6iS/zbNie0Of9BN5PmyXU+0ErmoXWVB9AZBpCkEwapw0ReWlqU4UTe0SwtUa7TtRPWP/xi14qEFWl8m3JzM87X4EVEVJ9r1IFSVG7q8Nstvy+XlmXyUtqHRkoNQpGcPgV9pXwip1GXtztUmWs5/OKJgvbnIVp0grfC0eKRJTb7EAuhfBTNcBflqqnJ4SydudGUuJdu1S9mkOrdZZ9RC+S5FMN6V70bacipBvo7zvsRrn3R0+sOKOwh+QmIphwO5s3rAsR2fp3aXbd6iuUE6mxiQRe6uyuEQGivU7ddTByFjJuHe041DfrXfbqjIbUEBqCKgp4QAX6b5x0ZVCzwBtXWxAGxi6F7XohTDzmvhUyWzF9tTTTsU5Q/4NZpeK6IjNfvS9a7hieYGCmld11VFUqm6zqUILHNS3FqRU50brGP5Wa1wC1j8eLAgWkBIFROyRPl97yRLbS2gSpjvUQyTVUyu+ihFSP629chJe8f9/I1OQTG6jg8tfljzYon/X9f4QzhXZjvjHhg67RVONHi7xvyqUUU+OU3ORm2JtpyPvAxX+buusGgtUcSsp8KiC+KeUQ3b/ENCcy1C0r1lW/gcmAezpS9gRVhkSUka3yzwFskW6Ore7rkbqd1JKPbBQ2Xpw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9P192MB1412.EURP192.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(136003)(39840400004)(396003)(376002)(366004)(346002)(86362001)(107886003)(66556008)(52116002)(83380400001)(55236004)(36756003)(4326008)(186003)(16526019)(956004)(316002)(6486002)(8676002)(54906003)(38100700002)(38350700002)(66476007)(6506007)(2906002)(26005)(9686003)(6512007)(66946007)(2616005)(5660300002)(478600001)(1076003)(6666004)(8936002)(6916009)(69590400013)(32563001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1Tij3CB7quMuvUFGvWAJ+aSdPMqk6isZFGHGWcOhq/VVeH5M2XE5pEiMyX+Ks9cXxTBfNd8C1IbDEHuvL4AJl7ixBI4RzsHD6iYS/35rBANW4O9Iv1rxHlr2FpyM47BDmH46R3QNjNZa2jYrbyjAE6s94ivuly8uh3K4NWkeTdIGnJjuYFFzBroTbZ06IXfR/k1Exm2+U6vqzVLUvGLmUl2MLwbMBnhL2GyFgqkZwnJNZD7N3qisnTcjK0fUA3cKmITqrNIAmTHQztUrlsPUtioHIrdcSZtjA68hVIpYuLuVkGpgIYTrb21Kxwuiv4t9+Al5ZqiXbqrA9ngqBjuMF5tAVk2xRpFTcypah+Auwh9zhxq4VmFxDNAwC2svtmL+zYHeQ6MU2GJKpsulnA8l+Z4QfKxv9rzkIFBX4Li1d+x34VFlFti/HWhpGl3mOkRxGOs6oou92OW8GITiavOoFdSKvXlWrYBgKINKwLCe0SGfslYyZP1VHkl4n5X57BCpthbXNBz0JDN3vzaI4o+LT+eJrnZLzScZrzOD1BwvtBrdFTjcWXHsgooBFhsUjQHKSCaqQOVk6Jrl3KSfrT/JyDG0kK8ujn0o+dIW64w/Y6+sbprXagaiz8fdYq9Gu1hIe0XM+dSkiv2IEuKY4tKJgiDDY8eAU8/6HdYlzPZKUdKtqaLVJueUzvDnXO7r43whFaN2y8hW+FnwrCIYitrEoFzs7N5f7XEH9++cvbiF9oWtw3qljRRoGH/rjF5/K0Vhfg4Tn2AZ4+TrhY3e+vSJp0ecitILGR8S/eDxlUmJf79n7RajakZ6Zif/szpMsbkhAySJiLlxpoSxUHS88vBQw9E2KoHg76ukxhR3JwCX8KmYGyBrtZ+AoIfYls2PAY+KRu/uCYLVkZcWi/nZ4ZFJmDGhvL2AZ0W0Kh429BlAKBhPon7HayF5OUOa+jqNGYFcXU8Od1K21pX0+OYJj3Ij7o611IV2laOgTN/n1oAVYDIcaxMuEOMN3QRbIc+cpQC+gcRAHDv6ErVoC2vjdFqhWotqjaKxKMlPrpspW/cKJk2FIQLWT/TJtLdLeF7KQJX+PX4p8MuSeWzla8AUxjhNzlwsoGGjPj6nNQ/kOcSaNQDaEQvIDvvArDgi7OFe8tgzDeD0ZOx/v6PyhjyOtCm7TzMbG3DFufwz+ZOFrROD659Jjs5GzpIDCeIcHJzJcxewNASHpr5lOhac/wWtvZ1DlyUO7L6N59M4MfR90cvqmMaJiRhl9X9B/GN4r1XsKnDgs4ulvnJPOuFfSZJMeRAp2WP0gUX5z57a2erF6BqQ5vGoYIb34Vz5pfVXpTtUoKXa X-OriginatorOrg: celeno.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f70d0a6-4c6c-45a3-3b39-08d931a970e5 X-MS-Exchange-CrossTenant-AuthSource: AM9P192MB1412.EURP192.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2021 16:03:26.4384 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f313103b-4c9f-4fd3-b5cf-b97f91c4afa8 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: J7sO13E117j22785IvH+3S/A+82cUGQcfHg23hwC0a4jLSqVi8c6XrnawgGqYnbRxgMFeV/ZDqsR/VKt3DiTmg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0P192MB0499 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Viktor Barna (Part of the split. Please, take a look at the cover letter for more details). Signed-off-by: Viktor Barna --- drivers/net/wireless/celeno/cl8k/coredump.c | 190 ++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/coredump.c -- 2.30.0 diff --git a/drivers/net/wireless/celeno/cl8k/coredump.c b/drivers/net/wireless/celeno/cl8k/coredump.c new file mode 100644 index 000000000000..bf0313715f6f --- /dev/null +++ b/drivers/net/wireless/celeno/cl8k/coredump.c @@ -0,0 +1,190 @@ +// SPDX-License-Identifier: MIT +/* Copyright(c) 2019-2021, Celeno Communications Ltd. */ + +#include "coredump.h" +#include "recovery.h" +#include "mib.h" +#include "ela.h" +#ifdef CONFIG_CL_PCIE +#include "bus/pci/ipc.h" +#endif +#include "chip.h" +#include "config.h" + +#include "fw/fw_dbg.h" + +#include + +static int cl_coredump_generate(struct cl_hw *cl_hw) +{ + struct cl_coredump *dump; + + dump = cl_fw_dbg_prepare_coredump(cl_hw); + if (!dump) + return -ENODATA; + + dev_coredumpv(cl_hw->chip->dev, dump, le32_to_cpu(dump->len), + GFP_KERNEL); + + return 0; +} + +static void cl_coredump_done(struct cl_hw *cl_hw) +{ + /* + * Print MIB counters only if watchdog is disabled, + * otherwise the dump of prints effects the recovery + */ + if (cl_hw->conf->ce_fw_watchdog_mode == FW_WD_DISABLE) + cl_mib_cntrs_dump(cl_hw); + + if (!test_bit(CL_DEV_STARTED, &cl_hw->drv_flags)) + return; + + /* + * Assuming firmware cannot request next dump before we release the host buffer + * so no need to sync the following against error_ind() + */ + cl_hw->debugfs.trace_prst = false; +#ifdef CONFIG_CL_PCIE + cl_ipc_dbginfobuf_push(cl_hw->ipc_env, cl_hw->dbginfo.dma_addr); +#endif + if (cl_hw->dbginfo.buf->u.dump.general_data.error_type == DBG_ERROR_FATAL || + cl_hw->assert_info.restart_needed) { + cl_dbg_err(cl_hw, "Starting recovery due to unrecoverable assert\n"); + cl_recovery_start(cl_hw, RECOVERY_UNRECOVERABLE_ASSERT); + } +} + +static void cl_coredump_work(struct work_struct *ws) +{ + struct cl_debugfs *debugfs = container_of(ws, struct cl_debugfs, coredump_work); + struct cl_hw *cl_hw = container_of(debugfs, struct cl_hw, debugfs); + unsigned long flags; + + debugfs->coredump_call_tstamp = jiffies; + + cl_coredump_generate(cl_hw); + if (cl_ela_is_on(cl_hw->chip)) { + cl_ela_lcu_reset(cl_hw->chip); + cl_ela_lcu_apply_config(cl_hw->chip); + } + + spin_lock_irqsave(&debugfs->coredump_lock, flags); + if (!debugfs->unregistering) + cl_coredump_done(cl_hw); + debugfs->coredump_scheduled = false; + spin_unlock_irqrestore(&debugfs->coredump_lock, flags); +} + +int cl_coredump_trigger(struct cl_hw *cl_hw) +{ + struct cl_debugfs *debugfs = &cl_hw->debugfs; + unsigned long flags; + unsigned long curr_time = jiffies; + unsigned int diff_time = jiffies_to_msecs(curr_time - debugfs->coredump_call_tstamp); + + if (diff_time < cl_hw->conf->ci_coredump_diff_time_ms) { +#ifdef CONFIG_CL_PCIE + cl_ipc_dbginfobuf_push(cl_hw->ipc_env, cl_hw->dbginfo.dma_addr); +#endif + cl_dbg_verbose(cl_hw, + "Skip coredump - time from previous call=%u m-sec\n", + diff_time); + return -1; + } + + spin_lock_irqsave(&debugfs->coredump_lock, flags); + if (debugfs->coredump_scheduled) { + spin_unlock_irqrestore(&debugfs->coredump_lock, flags); + cl_dbg_verbose(cl_hw, ": Already scheduled\n"); + return -EBUSY; + } + + if (debugfs->unregistering) { + spin_unlock_irqrestore(&debugfs->coredump_lock, flags); + cl_dbg_verbose(cl_hw, ": unregistering\n"); + return -ENOENT; + } + + debugfs->coredump_scheduled = true; + debugfs->trace_prst = true; + ktime_get_real_ts64(&cl_hw->dbginfo.trigger_tstamp); + + schedule_work(&debugfs->coredump_work); + spin_unlock_irqrestore(&debugfs->coredump_lock, flags); + + return 0; +} + +bool cl_coredump_recovery(struct cl_hw *cl_hw, int reason) +{ + struct cl_debugfs *debugfs = &cl_hw->debugfs; + unsigned long flags; + bool need_restart = false; + + spin_lock_irqsave(&debugfs->coredump_lock, flags); + + if (!debugfs->coredump_scheduled) { + cl_dbg_trace(cl_hw, + "Starting recovery due to reason:%d\n", + reason); + cl_recovery_start(cl_hw, reason); + } else { + need_restart = true; + } + + spin_unlock_irqrestore(&debugfs->coredump_lock, flags); + + return need_restart; +} + +bool cl_coredump_is_scheduled(struct cl_hw *cl_hw) +{ + struct cl_debugfs *debugfs = &cl_hw->debugfs; + + return debugfs->coredump_scheduled; +} + +void cl_coredump_reset_trace(struct cl_hw *cl_hw) +{ + struct cl_debugfs *debugfs = &cl_hw->debugfs; + + debugfs->trace_prst = false; +} + +void cl_coredump_init(struct cl_hw *cl_hw, struct dentry *dir_drv) +{ + struct cl_debugfs *debugfs = &cl_hw->debugfs; + + debugfs->dir = dir_drv; + debugfs->unregistering = false; + debugfs->trace_prst = false; + debugfs->coredump_scheduled = false; + + INIT_WORK(&debugfs->coredump_work, cl_coredump_work); + + spin_lock_init(&debugfs->coredump_lock); + + /* + * Initialize coredump_call_tstamp to current time minus + * (ci_coredump_diff_time_ms + 1), so that if assert happens immediately + * coredump will be called. + */ + debugfs->coredump_call_tstamp = jiffies - + msecs_to_jiffies(cl_hw->conf->ci_coredump_diff_time_ms + 1); +} + +void cl_coredump_close(struct cl_hw *cl_hw) +{ + struct cl_debugfs *debugfs = &cl_hw->debugfs; + + flush_work(&debugfs->coredump_work); + + if (!debugfs->dir) + return; + + debugfs->unregistering = true; + debugfs_remove_recursive(debugfs->dir); + debugfs->dir = NULL; +}