From patchwork Sat Aug 17 08:33:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjian Song X-Patchwork-Id: 13767062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC24BC52D7F for ; Sat, 17 Aug 2024 08:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=jMjBW1Ztf1ecRopCiAC763qdj7xKc6fo+L3DENhzyFs=; b=oUWsWpKJA58wXbIlBRe/oUvaeU 8IZs3iM8P6HOjld8jiMmD8Wcc4ZWn3Iw8NNKgrcqRfjgb2Ed8knMqI7oribYAixxQrjtyq8I1rA/Y FFE5pd+3q6tgS4aQ1nJd3ncoiVcwqjGLgNRA3lz5Y6SJ8lFXVL2NwSMy2FLg9Umwq1rTWRiO9kpcm bXSvtRmssqGKF1/dkzMPGliPOdAwEckHRR4wLdF5nigZsczpnUdU3j+941bd1pBIe0KoHkBJy+u4C buGr2xPpZj7sjdUe3RPWgzyBU+00l7cKrIrMpliT8SVrGDfMawoPelCQi7lyPEir0gahqXrzRBXil Fd0uJFqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfEtU-0000000EvEG-1ITT; Sat, 17 Aug 2024 08:34:40 +0000 Received: from mail-psaapc01on2071e.outbound.protection.outlook.com ([2a01:111:f400:feae::71e] helo=APC01-PSA-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfEtQ-0000000EvDe-27ig; Sat, 17 Aug 2024 08:34:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=seLH7fciqOrjTXNX9x+Z1jKxz2Ydf0FxgNkeq+IMTtleNX8mnMw+yjdPZzYA4dFzWJfp9TkEPoo86xv1NGvR4v8u4+PAJxjFuJ4TBZ3Nfc3nimCsViIAlGa/d6WoVdY6OqbxZjmQ6A2WGEsIJeRHyOmWGdCzrVbzoftHpuAvZpbkySHcDg/fqSksUbyFf56gI/GJECbMSYFYpOaXcbEM+SlJiZwhTCTAfBIdwfWll2HllCOQH7oyUv/sCVWMP4rv0T3Tv0HdKV0VtTRw8aLu0nh8/bJUkERnranq+mKVKIzgnLyaabwZloL9udlBMbroeAGvO4qaWSebNs0wMZda/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jMjBW1Ztf1ecRopCiAC763qdj7xKc6fo+L3DENhzyFs=; b=lDDyZknAYx7D/QBYMkNIkoNnCzqJFsYelgGgwafUI6jsHxUO5yVesVfVA9F1NgBR+Mv2ZS6ZAW+8WYJqhlmq+IcczPY7QFaudhANGYGeT3ud1DkfG4KkxQkz1vkH1m4bDjckaONuk5rymwAZ4ZZXcn+Xn+t84zGcNh3XZGhdnb3Q0zjt3W/PVE1iRCj8mNHjGsZJlelvK3IW23MWZLjzvt2NXEAldsfH2y5uPqnoIBfbGr3uf2k+200Jasi/hGKTVyjm33fERr/O3D/T4ijbsw/yS83mhbxUOofDcLQzbPOsSbHlnPnpNt1DDS+MMKyULZmi7ZYh4wEafT/6nj1gXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fibocom.com; dmarc=pass action=none header.from=fibocom.com; dkim=pass header.d=fibocom.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fibocomcorp.onmicrosoft.com; s=selector1-fibocomcorp-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jMjBW1Ztf1ecRopCiAC763qdj7xKc6fo+L3DENhzyFs=; b=oNaWcQ2vQwpXHvyUgm5XhLnwQWkz5+O7Q5VRWJuyY3IbTQASRR4cxVuDFZOpG+AcxKiTGhloUvNwSILl/Vq1BOCzt/jkKsxZJg5y+5vOj74oXcni+Lu52tndUEHlFJLkutwyFFK6LRwvExdqh77o/KB4sWVfE45Fzu5iH7HmPqk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=fibocom.com; Received: from TY0PR02MB5766.apcprd02.prod.outlook.com (2603:1096:400:1b5::6) by TY0PR02MB6152.apcprd02.prod.outlook.com (2603:1096:400:27a::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.19; Sat, 17 Aug 2024 08:34:20 +0000 Received: from TY0PR02MB5766.apcprd02.prod.outlook.com ([fe80::f53d:47b:3b04:9a8b]) by TY0PR02MB5766.apcprd02.prod.outlook.com ([fe80::f53d:47b:3b04:9a8b%5]) with mapi id 15.20.7875.019; Sat, 17 Aug 2024 08:34:19 +0000 From: Jinjian Song To: chandrashekar.devegowda@intel.com, chiranjeevi.rapolu@linux.intel.com, haijun.liu@mediatek.com, m.chetan.kumar@linux.intel.com, ricardo.martinez@linux.intel.com, loic.poulain@linaro.org, ryazanov.s.a@gmail.com, johannes@sipsolutions.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, angelogioacchino.delregno@collabora.com, linux-arm-kernel@lists.infradead.org, matthias.bgg@gmail.com, corbet@lwn.net, linux-mediatek@lists.infradead.org, helgaas@kernel.org, danielwinkler@google.com, korneld@google.com, Jinjian Song Subject: [net-next v3] net: wwan: t7xx: PCIe reset rescan Date: Sat, 17 Aug 2024 16:33:55 +0800 Message-Id: <20240817083355.29811-1-jinjian.song@fibocom.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SG2PR06CA0213.apcprd06.prod.outlook.com (2603:1096:4:68::21) To TY0PR02MB5766.apcprd02.prod.outlook.com (2603:1096:400:1b5::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TY0PR02MB5766:EE_|TY0PR02MB6152:EE_ X-MS-Office365-Filtering-Correlation-Id: 168615ee-a66f-42cf-034a-08dcbe97634e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|366016|7416014|376014|921020|38350700014; X-Microsoft-Antispam-Message-Info: OlZVkRwHBPsAseL7AWtCoVKpz2Lf1hQBGMfVtLXrLWFWaxKcu5RwDYUrvnes5s6zlaFaAXBXm3wciDHeaJPnNmgMBkhS4o/6mL9yjU2fT/No57KxSJDdOCb6S7TzxTmO5ad89A3pNfU3+kpxv3Xy2EArrQhH97N6i1hjQM70T6jVc1EkoxMsWrHj4oMRlfALq3x4lqDOumM76NFuR9uMY681kimYUTnwtedFGgLBdMLuZdbPFGOcu7ytci1lblwyDPQsMLbyEylTLdAcC0zkUZWNlgq7h3Qodo8LdGO6kB1fn7tkJejeukzosG1dDKx+1KQcAakG9cAX7+czoRwpCBgC5vbYG32BnUs9a0jprXDqghA1JDRC3YyhhXW8Aq2ZmPAvlGR3D2s7F4bGPUJBLKUUq1ebFf5ZONBQr8zZos2aX/v/ODngUHVhndlGR6MmEzWRlsfpyt9GlazQ72C/KqvAzUGQT5NteMcf50fL7mkxehxcOEz1inEtFO8OCIUaT+Ol5apjbbplgYWxmZa5uC2L3ak0axIlfqhp8MoBxhzZdJXVk0CMSQulETooXuut0V+9lJWmh2YQ9hWz1niZqHFPpfjTm9Jnw7gFhieNb5b1pWTMR5iuFilm5HpOu8oRK3tBXeYn43Go1eS6LiF8OPXNtBU5uzu0IvLcgURtHKmOj7F10xfGU3qousVgfMV2R830POttzcpIb8Ie/1/1nWkNu8aGh3q33QKV7Kb4aSp8DJyhowiHIRgy7xBdxqDiF3rCm+VHDS5xnwJ9aIv40v5Ii4PIeaIjKHorpjCxmxCORSU8ijYdJx3pCFwzCQDvvkUDxLz1IMwvIwzoEf9r38iJa6OiWHH+jsJdUw6j6L2T5hiqrXW6/w8ZUW8ugut01OWp3AUS+1VzizQFE4ttToerEHxqgENcCQm+c3okwI6wpgMaWIrT4u/j4PaRmlPIDCwVLmKgNhdxNojMhmmWxlaFRqqJjuOe4Q7h8Ua17Q9e/1GquDfZoRqQsA36AEd36/CKh77EnzoYGsKvmCdXvMPF2EquTKbCs8awr0F8tZ5Yn3rtQAGBOyDurl9D+t21U2cjBF8zigLWlGViaZggh+2in3gm0AclhDHBqWDeZfCofr9ygT1SJc9zE71BTuHk8ITTzGGS3wIaRNTU4sZX8HL1KBFlRdgZgL8SHujoWAbmNAOjLVuMD80Llele0viETSeBYh0TjDmNfNDqqIdbtgRu3WlnSFdtNJqWkvUdTZjPKKs4+ayZxjJTMU9T5oqPuEToVbrqOVAMwmhjpTs0B8ZylTidGCDf8dv1oodpsDe9PB/T03XEj6H9qUiIhy+e6ZPZ75Ctr3jvytIT6FgM66c9CicWOrFQLpdMI7uVmeoT9EA5aChRvSzGllLNTBpn X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TY0PR02MB5766.apcprd02.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(52116014)(366016)(7416014)(376014)(921020)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eznmQwobLaKgJVPkX+UXbaQ7dZX6zY6Mhiz/Z2ycQ0pGZyiH/60aCs8wO2CJex8Lcf8pm2EIaFGQIt9ZA9dkYvcPKOgvU9t4hNMqEOYkTRUhPXGuIRCLG9DdHJN6l/45XhoDi3k2jUkwHZfgdnwG4J/FjB9OLBrsLkTpd4sc+zprORJ9b6FTFVkH+vG4hXOIQ1A5+pjBEIgZINN29e8klNFnOimo5Dej36GzuKhluLcuQ+Ps3aWfkhYdG5TxkT1sGBOXeaVy8Zg9OfJuuRaFozLzHvhlnr41YuAqcpiCK2aJNZMNtO+ExiV1dDyiuQAy3ZTo53fCCoNpxTUktJFLn2dCs/rC6o+obESU7wpXB+s0K+SpyMJan6f/Xx6P3kBE+m9liyC40hbZvANWWoyMcIYj6qoyu6v8oQUIa48jKe+A8rQaSE+l5A6zfzgHOZKmPG7BQYTjFHhWHJ5R0cjCZjALefaKttpagN0ukT0u4vDMxjrrh8oqmimOTos7/w84xxCaFudw6C7p/YdKfkydZEeviT8Hk2Umf40DNK+n29mEJnHkCTwOag7hjcfQhBdFTwtjny3xahp/rVnn86vcAfK+VEwoyqOZwYYHlnwp+6/E+wFgt++H0bV5g8xrbGJ1MgT7EOlZVikw7Hw2F1/9gWEH+Th1HTF6MD40MBhOb5hXJweU6dNN0OZEZZ1LDiwjl7Mp60bTdWgiPxC23ItzPpbBvRz3Yv3LJH9yb4L9TcyiYqS3Us6unCOmDLXPFJeCwu0M+U7ExgSphNw5bjvd5Vs8RXP6/jrTyjg7BoMVzzwQXOvP29hq7CcCu3G04r3WB1Go6JyQ7BS7/YhAi0ztn5JASs+HVj2XtYfCXlflHP/VdItRWMw8OcVkCeSSV1X0EkR6EEIeOPjmKMtuRGVX+kV5Jca9QtwJh6bkKDsXd8G4BQPOdlcYxu3STtbtZY9TRRmIO2HWQD5/KTMg64xpLJUJdgMqh8mHI7jNYe3CrZdFT8envZDPPTUJxYkJYUyZHDbVkmQXviYJUxiVj2DdYFnTdDqpqw82jWspOV+w+5saZjGu2Erfn3LYzuMUx8BTzK2ieorqBS/qUnB7KI8ukIZ/Nyoi0CduENeGNxB0k+XX6c3/EYYNdmQ0Zfl4yoibAyfoAAZOBP97hrB/4aAb3GkAjAXKhiwMO66FZ7xPM47PxqNedoORyPkcR/BWtUGGtQ6ZLFYdoBAzwmZAMPQ+4DtokcYWkMMrO1N0NV1cJ9DWEz5+Tqk5yjJBjrt8jDxQcIYF1iR8dD028XA5ZYoRbOxfGBu4DPtH+iQongjeTrMg7KwuKtcuwT3ucVUMFjh6HUyF4ztFivmLmBLDsvBkjUSQb1oHHow6qwQKWx1548x06hgtg9fl91B61Yo+Twg43NrFb4R9gBKEa4+/9SdmjuVb9XrnsZRcqKv9tN3Wyp94Hc3CLLH5mTHE3trMSey58nqi17TnOf9uhXW85N9s00JdDkqH7jpuASZIJzvp5LS5VNwIG/72kxx0tvjMBtj50P29zN2zUhYxaKKSmuIT/enU8C6SJ+fQKKS76TisUnTPC1lCyt+zGK9/f2kqGRwo8wx3ntBviapniHjFinYXDQ== X-OriginatorOrg: fibocom.com X-MS-Exchange-CrossTenant-Network-Message-Id: 168615ee-a66f-42cf-034a-08dcbe97634e X-MS-Exchange-CrossTenant-AuthSource: TY0PR02MB5766.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2024 08:34:19.7287 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 889bfe61-8c21-436b-bc07-3908050c8236 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CvdBtrEUOgfkd7TSoKbaMQSuL7EbfJi0prxmz0OXhPHyH9IuJ1GhugLeooaf78RX/TsOuM+jjfZQEzWHhyMo/9x7ZVspzM2mvqOLQBobQTI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY0PR02MB6152 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240817_013437_019537_4F11C09B X-CRM114-Status: GOOD ( 18.47 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org WWAN device is programmed to boot in normal mode or fastboot mode, when triggering a device reset through ACPI call or fastboot switch command. Maintain state machine synchronization and reprobe logic after a device reset. The PCIe device reset triggered by several ways. E.g.: - fastboot: echo "fastboot_switching" > /sys/bus/pci/devices/${bdf}/t7xx_mode. - reset: echo "reset" > /sys/bus/pci/devices/${bdf}/t7xx_mode. - IRQ: PCIe device request driver to reset itself by an interrupt request. Use pci_reset_function() as a generic way to reset device, save and restore the PCIe configuration before and after reset device to ensure the reprobe process. Suggestion from Bjorn: Link: https://lore.kernel.org/all/20230127133034.GA1364550@bhelgaas/ Signed-off-by: Jinjian Song --- V3: * supplementary commit information * fix the error codestyle in t7xx_mode_store() * use CONFIG_DEBUG_ATOMIC_SLEEP to test the reset feature V2: * initialize the variable 'ret' in t7xx_reset_device() function --- drivers/net/wwan/t7xx/t7xx_modem_ops.c | 47 ++++++++++++++++--- drivers/net/wwan/t7xx/t7xx_modem_ops.h | 9 +++- drivers/net/wwan/t7xx/t7xx_pci.c | 53 ++++++++++++++++++---- drivers/net/wwan/t7xx/t7xx_pci.h | 3 ++ drivers/net/wwan/t7xx/t7xx_port_proxy.c | 1 - drivers/net/wwan/t7xx/t7xx_port_trace.c | 1 + drivers/net/wwan/t7xx/t7xx_state_monitor.c | 34 +++++--------- 7 files changed, 105 insertions(+), 43 deletions(-) diff --git a/drivers/net/wwan/t7xx/t7xx_modem_ops.c b/drivers/net/wwan/t7xx/t7xx_modem_ops.c index 8d864d4ed77f..79f17100f70b 100644 --- a/drivers/net/wwan/t7xx/t7xx_modem_ops.c +++ b/drivers/net/wwan/t7xx/t7xx_modem_ops.c @@ -53,6 +53,7 @@ #define RGU_RESET_DELAY_MS 10 #define PORT_RESET_DELAY_MS 2000 +#define FASTBOOT_RESET_DELAY_MS 2000 #define EX_HS_TIMEOUT_MS 5000 #define EX_HS_POLL_DELAY_MS 10 @@ -167,19 +168,52 @@ static int t7xx_acpi_reset(struct t7xx_pci_dev *t7xx_dev, char *fn_name) } kfree(buffer.pointer); +#else + struct device *dev = &t7xx_dev->pdev->dev; + int ret; + ret = pci_reset_function(t7xx_dev->pdev); + if (ret) { + dev_err(dev, "Failed to reset device, error:%d\n", ret); + return ret; + } #endif return 0; } -int t7xx_acpi_fldr_func(struct t7xx_pci_dev *t7xx_dev) +static void t7xx_host_event_notify(struct t7xx_pci_dev *t7xx_dev, unsigned int event_id) { - return t7xx_acpi_reset(t7xx_dev, "_RST"); + u32 value; + + value = ioread32(IREG_BASE(t7xx_dev) + T7XX_PCIE_MISC_DEV_STATUS); + value &= ~HOST_EVENT_MASK; + value |= FIELD_PREP(HOST_EVENT_MASK, event_id); + iowrite32(value, IREG_BASE(t7xx_dev) + T7XX_PCIE_MISC_DEV_STATUS); } -int t7xx_acpi_pldr_func(struct t7xx_pci_dev *t7xx_dev) +int t7xx_reset_device(struct t7xx_pci_dev *t7xx_dev, enum reset_type type) { - return t7xx_acpi_reset(t7xx_dev, "MRST._RST"); + int ret = 0; + + pci_save_state(t7xx_dev->pdev); + t7xx_pci_reprobe_early(t7xx_dev); + t7xx_mode_update(t7xx_dev, T7XX_RESET); + + if (type == FLDR) { + ret = t7xx_acpi_reset(t7xx_dev, "_RST"); + } else if (type == PLDR) { + ret = t7xx_acpi_reset(t7xx_dev, "MRST._RST"); + } else if (type == FASTBOOT) { + t7xx_host_event_notify(t7xx_dev, FASTBOOT_DL_NOTIFY); + t7xx_mhccif_h2d_swint_trigger(t7xx_dev, H2D_CH_DEVICE_RESET); + msleep(FASTBOOT_RESET_DELAY_MS); + } + + pci_restore_state(t7xx_dev->pdev); + if (ret) + return ret; + + return t7xx_pci_reprobe(t7xx_dev, true); } static void t7xx_reset_device_via_pmic(struct t7xx_pci_dev *t7xx_dev) @@ -188,16 +222,15 @@ static void t7xx_reset_device_via_pmic(struct t7xx_pci_dev *t7xx_dev) val = ioread32(IREG_BASE(t7xx_dev) + T7XX_PCIE_MISC_DEV_STATUS); if (val & MISC_RESET_TYPE_PLDR) - t7xx_acpi_reset(t7xx_dev, "MRST._RST"); + t7xx_reset_device(t7xx_dev, PLDR); else if (val & MISC_RESET_TYPE_FLDR) - t7xx_acpi_fldr_func(t7xx_dev); + t7xx_reset_device(t7xx_dev, FLDR); } static irqreturn_t t7xx_rgu_isr_thread(int irq, void *data) { struct t7xx_pci_dev *t7xx_dev = data; - t7xx_mode_update(t7xx_dev, T7XX_RESET); msleep(RGU_RESET_DELAY_MS); t7xx_reset_device_via_pmic(t7xx_dev); return IRQ_HANDLED; diff --git a/drivers/net/wwan/t7xx/t7xx_modem_ops.h b/drivers/net/wwan/t7xx/t7xx_modem_ops.h index b39e945a92e0..39ed0000fbba 100644 --- a/drivers/net/wwan/t7xx/t7xx_modem_ops.h +++ b/drivers/net/wwan/t7xx/t7xx_modem_ops.h @@ -78,14 +78,19 @@ struct t7xx_modem { spinlock_t exp_lock; /* Protects exception events */ }; +enum reset_type { + FLDR, + PLDR, + FASTBOOT, +}; + void t7xx_md_exception_handshake(struct t7xx_modem *md); void t7xx_md_event_notify(struct t7xx_modem *md, enum md_event_id evt_id); int t7xx_md_reset(struct t7xx_pci_dev *t7xx_dev); int t7xx_md_init(struct t7xx_pci_dev *t7xx_dev); void t7xx_md_exit(struct t7xx_pci_dev *t7xx_dev); void t7xx_clear_rgu_irq(struct t7xx_pci_dev *t7xx_dev); -int t7xx_acpi_fldr_func(struct t7xx_pci_dev *t7xx_dev); -int t7xx_acpi_pldr_func(struct t7xx_pci_dev *t7xx_dev); +int t7xx_reset_device(struct t7xx_pci_dev *t7xx_dev, enum reset_type type); int t7xx_pci_mhccif_isr(struct t7xx_pci_dev *t7xx_dev); #endif /* __T7XX_MODEM_OPS_H__ */ diff --git a/drivers/net/wwan/t7xx/t7xx_pci.c b/drivers/net/wwan/t7xx/t7xx_pci.c index 10a8c1080b10..e556e5bd49ab 100644 --- a/drivers/net/wwan/t7xx/t7xx_pci.c +++ b/drivers/net/wwan/t7xx/t7xx_pci.c @@ -69,6 +69,7 @@ static ssize_t t7xx_mode_store(struct device *dev, { struct t7xx_pci_dev *t7xx_dev; struct pci_dev *pdev; + enum t7xx_mode mode; int index = 0; pdev = to_pci_dev(dev); @@ -76,12 +77,22 @@ static ssize_t t7xx_mode_store(struct device *dev, if (!t7xx_dev) return -ENODEV; + mode = READ_ONCE(t7xx_dev->mode); + index = sysfs_match_string(t7xx_mode_names, buf); + if (index == mode) + return -EBUSY; + if (index == T7XX_FASTBOOT_SWITCHING) { + if (mode == T7XX_FASTBOOT_DOWNLOAD) + return count; + WRITE_ONCE(t7xx_dev->mode, T7XX_FASTBOOT_SWITCHING); + pm_runtime_resume(dev); + t7xx_reset_device(t7xx_dev, FASTBOOT); } else if (index == T7XX_RESET) { - WRITE_ONCE(t7xx_dev->mode, T7XX_RESET); - t7xx_acpi_pldr_func(t7xx_dev); + pm_runtime_resume(dev); + t7xx_reset_device(t7xx_dev, PLDR); } return count; @@ -446,7 +457,7 @@ static int t7xx_pcie_reinit(struct t7xx_pci_dev *t7xx_dev, bool is_d3) if (is_d3) { t7xx_mhccif_init(t7xx_dev); - return t7xx_pci_pm_reinit(t7xx_dev); + t7xx_pci_pm_reinit(t7xx_dev); } return 0; @@ -481,6 +492,33 @@ static int t7xx_send_fsm_command(struct t7xx_pci_dev *t7xx_dev, u32 event) return ret; } +int t7xx_pci_reprobe_early(struct t7xx_pci_dev *t7xx_dev) +{ + enum t7xx_mode mode = READ_ONCE(t7xx_dev->mode); + int ret; + + if (mode == T7XX_FASTBOOT_DOWNLOAD) + pm_runtime_put_noidle(&t7xx_dev->pdev->dev); + + ret = t7xx_send_fsm_command(t7xx_dev, FSM_CMD_STOP); + if (ret) + return ret; + + return 0; +} + +int t7xx_pci_reprobe(struct t7xx_pci_dev *t7xx_dev, bool boot) +{ + int ret; + + ret = t7xx_pcie_reinit(t7xx_dev, boot); + if (ret) + return ret; + + t7xx_clear_rgu_irq(t7xx_dev); + return t7xx_send_fsm_command(t7xx_dev, FSM_CMD_START); +} + static int __t7xx_pci_pm_resume(struct pci_dev *pdev, bool state_check) { struct t7xx_pci_dev *t7xx_dev; @@ -507,16 +545,11 @@ static int __t7xx_pci_pm_resume(struct pci_dev *pdev, bool state_check) if (prev_state == PM_RESUME_REG_STATE_L3 || (prev_state == PM_RESUME_REG_STATE_INIT && atr_reg_val == ATR_SRC_ADDR_INVALID)) { - ret = t7xx_send_fsm_command(t7xx_dev, FSM_CMD_STOP); - if (ret) - return ret; - - ret = t7xx_pcie_reinit(t7xx_dev, true); + ret = t7xx_pci_reprobe_early(t7xx_dev); if (ret) return ret; - t7xx_clear_rgu_irq(t7xx_dev); - return t7xx_send_fsm_command(t7xx_dev, FSM_CMD_START); + return t7xx_pci_reprobe(t7xx_dev, true); } if (prev_state == PM_RESUME_REG_STATE_EXP || diff --git a/drivers/net/wwan/t7xx/t7xx_pci.h b/drivers/net/wwan/t7xx/t7xx_pci.h index 49a11586d8d8..cd8ea17c2644 100644 --- a/drivers/net/wwan/t7xx/t7xx_pci.h +++ b/drivers/net/wwan/t7xx/t7xx_pci.h @@ -133,4 +133,7 @@ int t7xx_pci_pm_entity_unregister(struct t7xx_pci_dev *t7xx_dev, struct md_pm_en void t7xx_pci_pm_init_late(struct t7xx_pci_dev *t7xx_dev); void t7xx_pci_pm_exp_detected(struct t7xx_pci_dev *t7xx_dev); void t7xx_mode_update(struct t7xx_pci_dev *t7xx_dev, enum t7xx_mode mode); +int t7xx_pci_reprobe(struct t7xx_pci_dev *t7xx_dev, bool boot); +int t7xx_pci_reprobe_early(struct t7xx_pci_dev *t7xx_dev); + #endif /* __T7XX_PCI_H__ */ diff --git a/drivers/net/wwan/t7xx/t7xx_port_proxy.c b/drivers/net/wwan/t7xx/t7xx_port_proxy.c index 7d6388bf1d7c..35743e7de0c3 100644 --- a/drivers/net/wwan/t7xx/t7xx_port_proxy.c +++ b/drivers/net/wwan/t7xx/t7xx_port_proxy.c @@ -553,7 +553,6 @@ static int t7xx_proxy_alloc(struct t7xx_modem *md) md->port_prox = port_prox; port_prox->dev = dev; - t7xx_port_proxy_set_cfg(md, PORT_CFG_ID_EARLY); return 0; } diff --git a/drivers/net/wwan/t7xx/t7xx_port_trace.c b/drivers/net/wwan/t7xx/t7xx_port_trace.c index 6a3f36385865..4ed8b4e29bf1 100644 --- a/drivers/net/wwan/t7xx/t7xx_port_trace.c +++ b/drivers/net/wwan/t7xx/t7xx_port_trace.c @@ -59,6 +59,7 @@ static void t7xx_trace_port_uninit(struct t7xx_port *port) relay_close(relaych); debugfs_remove_recursive(debugfs_dir); + port->log.relaych = NULL; } static int t7xx_trace_port_recv_skb(struct t7xx_port *port, struct sk_buff *skb) diff --git a/drivers/net/wwan/t7xx/t7xx_state_monitor.c b/drivers/net/wwan/t7xx/t7xx_state_monitor.c index 9889ca4621cf..3931c7a13f5a 100644 --- a/drivers/net/wwan/t7xx/t7xx_state_monitor.c +++ b/drivers/net/wwan/t7xx/t7xx_state_monitor.c @@ -213,16 +213,6 @@ static void fsm_routine_exception(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_comm fsm_finish_command(ctl, cmd, 0); } -static void t7xx_host_event_notify(struct t7xx_modem *md, unsigned int event_id) -{ - u32 value; - - value = ioread32(IREG_BASE(md->t7xx_dev) + T7XX_PCIE_MISC_DEV_STATUS); - value &= ~HOST_EVENT_MASK; - value |= FIELD_PREP(HOST_EVENT_MASK, event_id); - iowrite32(value, IREG_BASE(md->t7xx_dev) + T7XX_PCIE_MISC_DEV_STATUS); -} - static void t7xx_lk_stage_event_handling(struct t7xx_fsm_ctl *ctl, unsigned int status) { struct t7xx_modem *md = ctl->md; @@ -264,8 +254,14 @@ static void t7xx_lk_stage_event_handling(struct t7xx_fsm_ctl *ctl, unsigned int static int fsm_stopped_handler(struct t7xx_fsm_ctl *ctl) { + enum t7xx_mode mode; + ctl->curr_state = FSM_STATE_STOPPED; + mode = READ_ONCE(ctl->md->t7xx_dev->mode); + if (mode == T7XX_FASTBOOT_DOWNLOAD || mode == T7XX_FASTBOOT_DUMP) + return 0; + t7xx_fsm_broadcast_state(ctl, MD_STATE_STOPPED); return t7xx_md_reset(ctl->md->t7xx_dev); } @@ -284,8 +280,6 @@ static void fsm_routine_stopping(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_comma { struct cldma_ctrl *md_ctrl = ctl->md->md_ctrl[CLDMA_ID_MD]; struct t7xx_pci_dev *t7xx_dev = ctl->md->t7xx_dev; - enum t7xx_mode mode = READ_ONCE(t7xx_dev->mode); - int err; if (ctl->curr_state == FSM_STATE_STOPPED || ctl->curr_state == FSM_STATE_STOPPING) { fsm_finish_command(ctl, cmd, -EINVAL); @@ -296,21 +290,10 @@ static void fsm_routine_stopping(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_comma t7xx_fsm_broadcast_state(ctl, MD_STATE_WAITING_TO_STOP); t7xx_cldma_stop(md_ctrl); - if (mode == T7XX_FASTBOOT_SWITCHING) - t7xx_host_event_notify(ctl->md, FASTBOOT_DL_NOTIFY); - t7xx_mhccif_h2d_swint_trigger(t7xx_dev, H2D_CH_DRM_DISABLE_AP); /* Wait for the DRM disable to take effect */ msleep(FSM_DRM_DISABLE_DELAY_MS); - if (mode == T7XX_FASTBOOT_SWITCHING) { - t7xx_mhccif_h2d_swint_trigger(t7xx_dev, H2D_CH_DEVICE_RESET); - } else { - err = t7xx_acpi_fldr_func(t7xx_dev); - if (err) - t7xx_mhccif_h2d_swint_trigger(t7xx_dev, H2D_CH_DEVICE_RESET); - } - fsm_finish_command(ctl, cmd, fsm_stopped_handler(ctl)); } @@ -414,7 +397,9 @@ static void fsm_routine_start(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command case T7XX_DEV_STAGE_LK: dev_dbg(dev, "LK_STAGE Entered\n"); + t7xx_port_proxy_set_cfg(md, PORT_CFG_ID_EARLY); t7xx_lk_stage_event_handling(ctl, status); + break; case T7XX_DEV_STAGE_LINUX: @@ -436,6 +421,9 @@ static void fsm_routine_start(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command } finish_command: + if (ret) + t7xx_mode_update(md->t7xx_dev, T7XX_UNKNOWN); + fsm_finish_command(ctl, cmd, ret); }