From patchwork Fri Nov 18 08:51:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 13047851 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E58FC433FE for ; Fri, 18 Nov 2022 08:52:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241209AbiKRIwR (ORCPT ); Fri, 18 Nov 2022 03:52:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241591AbiKRIv6 (ORCPT ); Fri, 18 Nov 2022 03:51:58 -0500 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2079.outbound.protection.outlook.com [40.107.247.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54D6EF2B; Fri, 18 Nov 2022 00:51:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gh6CUUnFajxLCAnD3pMIketK52LhKV2reWf73TwUYSJDnK9JjlBjJTPQekCE0ZKA5UKja5iI91jY5KdK/FDCso50iIV4sbFsI4waiPKZd6Uxs9MO2OMERp9ynGealjUCS9yq2Z+F8nYOkN1JqN9Mv0rkxMgO/IE9DN8Lf/1L27CENoHGupVUAqLto5VCc7sO7cOP534LhFdu4CDPYdDaMGJS4kQFMkZZJrHZ7jJrRG00y27/Q+edAWbmz9ZyqPaSj+gtm7omAIFDPUKbevrUdHwIazuYqoMawiD3X/yDBUX613ev86KMJiGl7nPCmYO9p1U5eVT3WP9/4Lo0iXluSQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nkpBjTQLrU/SYz0p299mNmxNibbVm0edBOAvPoLAoQY=; b=KMzA/K3RzZfzFyzFZJ8g1TEUZEKme0ulhcfTWEpylCEUWKZgcQhYslHbfnNgZSdZBXktDffGBYAe3ZAV60GXxyjyXEqlDiyaNYJ3bDy055DXZ7g0LDX8gtpjX7Ql1MVixmiSQhBFEtNKlIuNb3zKJga1aIZPge9DStc3BQHBK5rzbEVm48ZGElqwL5UZ8jSQNSh0VSrUDTDXXqmJGCm/A7evPEVAomDMkMl6CQdoFhtvSx+ltVMA+CkVJZgwUaAR96zEK0hJrhm47by5Kl9SwVrNVTr4xZLnH9ybnfxdB7VmFmQBsLaRYRj+nS1IBwm0f8z2XPJXBTDxyUFVIrw8fg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nkpBjTQLrU/SYz0p299mNmxNibbVm0edBOAvPoLAoQY=; b=D029+58efF/jha3NtjML5FsJy1+JRqpid8MwWf7TL6wvHD8ZDZ+BuGZkSXdud8+gpXZRKr6uweVPZbfVrzoFFXr+YDk8x66BtWDrjX/4kd3seukvBvV3o/wHMyc1ytcOeVa0M838dcdx2585WZruH8zNxqDJf3di34yUPm8UFB8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) by AM9PR04MB7586.eurprd04.prod.outlook.com (2603:10a6:20b:2d5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.9; Fri, 18 Nov 2022 08:51:54 +0000 Received: from AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::5c78:27ea:319f:d11]) by AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::5c78:27ea:319f:d11%3]) with mapi id 15.20.5813.019; Fri, 18 Nov 2022 08:51:54 +0000 From: Ming Qian To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl Cc: shawnguo@kernel.org, robh+dt@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, xiahong.bao@nxp.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] media: amphion: try to wakeup vpu core to avoid failure Date: Fri, 18 Nov 2022 16:51:29 +0800 Message-Id: <20221118085129.15412-1-ming.qian@nxp.com> X-Mailer: git-send-email 2.38.1 X-ClientProxiedBy: SI2PR02CA0054.apcprd02.prod.outlook.com (2603:1096:4:196::13) To AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB6341:EE_|AM9PR04MB7586:EE_ X-MS-Office365-Filtering-Correlation-Id: c0481b34-c878-4e6c-9934-08dac9422421 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 44wicaAc7fLPpMow9WBoP6K8vHLRGSoxdAirBf297t1nmYnl4G1Hv00BH4S2oe0mXgT26dDPjbI1ZEvbGDLd+vgnJsYbOKkrKoMyOHeQY6O7LCaBKuwXuLSF55PM8QBFr45UI0Vi6odsqYZUKO2JQfVAkMfGlLeCQUz+WViLgX7EQtzr/TncXcnrX2HweI6yUanirRf6ydkgJFV6PLH7S10JEnwB++1qb9lt9+U3BSUP3PQ2XMkB892G9EjAuLgm1F6k87z8KWewl20+KfWSblxL3bqpPLyNkJj3UiE/U6/SBmIldAiSrWBfaSDgnshmMcpSm39Mq29nr8UxOghgMk8JJcgh2W00MptZnG9yDR/u19cxngpmU6UIHKFOYmToLX3ymSzNJdXMGnknBJkDNU3d0jqDakSZ1dFX6cZK1oCvFZIm6/wSU7if/QfyWIL8Zp5zws/qeSmfzHoiboINvnOrpMgaNQ/mVFzQ8JKAFXEB+3MPR+vqh9hBELLAeOf1H5AtU9xVWbJh9KxMocshegp4MWA9nH9ZtCmuXMe1am3d/tod9XDNYmFtjFEdg5dfL4wrF2og7yRSwuRsKvzz0JXDXj4ZpXGhWOtToaMRddbSLdzwdo4vAr985yt0NolZy7lC0JAWJORyYqgDhwvo4nv+2eFpj1vxlFk0LNZgnae0YkZRBnQ2SwldkkKW6GPeF9tNI6H1rrX6FyA760vXpw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB6341.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(376002)(396003)(346002)(366004)(136003)(451199015)(38100700002)(38350700002)(36756003)(86362001)(6512007)(66946007)(6666004)(26005)(52116002)(6506007)(316002)(478600001)(6486002)(7416002)(186003)(5660300002)(44832011)(2906002)(83380400001)(41300700001)(66476007)(4326008)(8676002)(66556008)(1076003)(8936002)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AFEtgPCyV1aAHf/Rt417BQuq1SFe4Z7QBazjRScO01spdCLQ0COrVApr79W8AI6MMJErLN9QMzWM43pL7MPr4V/fEGROEwdln4iZB9uZNZJbgyW/g2NsXxhGABRWNFVu+Yf3+mriftGOF78kMOVciLPqtLWBkezwGhSsTR/vVnCfGAKt4yGpbpUcyDYHKvvsU8XNRDg4LYusrAsNR8KZbQYFink9j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Fh3rImZYakQsFSuJIIbON/6ADYqE4l7m+scwy3FQFYtm0ezOy1CnlRKAhhb8o2ccw4K6igL1Ra17O8jrne7/rXSOFbG+O/LZx+dg40ldg0AQ7Sjbo4Fypc1pk2vf+lhLnTzCxG/nMBMOWL1QZs5DGgENLJWYsnOvqabLyeli7KtdoLP6gtpXvtpMGlgIbl0mepFxggb6iOzPgboSoq68nyKmKVdpGaD1QnihqO307PeMPsKyV2cAMy7OSAfPzhLChoeXjSdjwoHxDN9Odi1zQX/WsFzrFwCiSI36p5b1M6SpWm X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0481b34-c878-4e6c-9934-08dac9422421 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2022 08:51:53.9427 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KNce3icmP4UjqPwW8iKv+yZ953RFmnQSmYqhPTwKCspZJV1op1pnPfSx10Lc+gdLlFTuclIntEPm6fQBTMrIZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB7586 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org firmware should be waked up by start or configure command, but there is a very small chance that firmware failed to wakeup. in such case, try to wakeup firmware again by sending a noop command Fixes: 6de8d628df6e ("media: amphion: add v4l2 m2m vpu decoder stateful driver") Signed-off-by: Ming Qian --- drivers/media/platform/amphion/vpu.h | 1 + drivers/media/platform/amphion/vpu_cmds.c | 39 ++++++++++++++++++-- drivers/media/platform/amphion/vpu_malone.c | 1 + drivers/media/platform/amphion/vpu_windsor.c | 1 + 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/amphion/vpu.h b/drivers/media/platform/amphion/vpu.h index 73e34b3ec0e3..3bfe193722af 100644 --- a/drivers/media/platform/amphion/vpu.h +++ b/drivers/media/platform/amphion/vpu.h @@ -13,6 +13,7 @@ #include #include +#define VPU_TIMEOUT_WAKEUP msecs_to_jiffies(200) #define VPU_TIMEOUT msecs_to_jiffies(1000) #define VPU_INST_NULL_ID (-1L) #define VPU_MSG_BUFFER_SIZE (8192) diff --git a/drivers/media/platform/amphion/vpu_cmds.c b/drivers/media/platform/amphion/vpu_cmds.c index f4d7ca78a621..fa581ba6bab2 100644 --- a/drivers/media/platform/amphion/vpu_cmds.c +++ b/drivers/media/platform/amphion/vpu_cmds.c @@ -269,7 +269,7 @@ static bool check_is_responsed(struct vpu_inst *inst, unsigned long key) return flag; } -static int sync_session_response(struct vpu_inst *inst, unsigned long key) +static int sync_session_response(struct vpu_inst *inst, unsigned long key, long timeout, int try) { struct vpu_core *core; @@ -279,10 +279,12 @@ static int sync_session_response(struct vpu_inst *inst, unsigned long key) core = inst->core; call_void_vop(inst, wait_prepare); - wait_event_timeout(core->ack_wq, check_is_responsed(inst, key), VPU_TIMEOUT); + wait_event_timeout(core->ack_wq, check_is_responsed(inst, key), timeout); call_void_vop(inst, wait_finish); if (!check_is_responsed(inst, key)) { + if (try) + return -EINVAL; dev_err(inst->dev, "[%d] sync session timeout\n", inst->id); set_bit(inst->id, &core->hang_mask); mutex_lock(&inst->core->cmd_lock); @@ -294,6 +296,19 @@ static int sync_session_response(struct vpu_inst *inst, unsigned long key) return 0; } +static void vpu_core_keep_active(struct vpu_core *core) +{ + struct vpu_rpc_event pkt; + + memset(&pkt, 0, sizeof(pkt)); + vpu_iface_pack_cmd(core, &pkt, 0, VPU_CMD_ID_NOOP, NULL); + + dev_dbg(core->dev, "try to wake up\n"); + mutex_lock(&core->cmd_lock); + vpu_cmd_send(core, &pkt); + mutex_unlock(&core->cmd_lock); +} + static int vpu_session_send_cmd(struct vpu_inst *inst, u32 id, void *data) { unsigned long key; @@ -304,9 +319,25 @@ static int vpu_session_send_cmd(struct vpu_inst *inst, u32 id, void *data) return -EINVAL; ret = vpu_request_cmd(inst, id, data, &key, &sync); - if (!ret && sync) - ret = sync_session_response(inst, key); + if (ret) + goto exit; + + /* workaround for a firmware issue, + * firmware should be waked up by start or configure command, + * but there is a very small change that firmware failed to wakeup. + * in such case, try to wakeup firmware again by sending a noop command + */ + if (sync && (id == VPU_CMD_ID_CONFIGURE_CODEC || id == VPU_CMD_ID_START)) { + if (sync_session_response(inst, key, VPU_TIMEOUT_WAKEUP, 1)) + vpu_core_keep_active(inst->core); + else + goto exit; + } + + if (sync) + ret = sync_session_response(inst, key, VPU_TIMEOUT, 0); +exit: if (ret) dev_err(inst->dev, "[%d] send cmd(0x%x) fail\n", inst->id, id); diff --git a/drivers/media/platform/amphion/vpu_malone.c b/drivers/media/platform/amphion/vpu_malone.c index 69d9a2269fce..2c9bfc6a5a72 100644 --- a/drivers/media/platform/amphion/vpu_malone.c +++ b/drivers/media/platform/amphion/vpu_malone.c @@ -693,6 +693,7 @@ int vpu_malone_set_decode_params(struct vpu_shared_addr *shared, } static struct vpu_pair malone_cmds[] = { + {VPU_CMD_ID_NOOP, VID_API_CMD_NULL}, {VPU_CMD_ID_START, VID_API_CMD_START}, {VPU_CMD_ID_STOP, VID_API_CMD_STOP}, {VPU_CMD_ID_ABORT, VID_API_CMD_ABORT}, diff --git a/drivers/media/platform/amphion/vpu_windsor.c b/drivers/media/platform/amphion/vpu_windsor.c index a454f142ae17..b245ff6a1102 100644 --- a/drivers/media/platform/amphion/vpu_windsor.c +++ b/drivers/media/platform/amphion/vpu_windsor.c @@ -658,6 +658,7 @@ int vpu_windsor_get_stream_buffer_size(struct vpu_shared_addr *shared) } static struct vpu_pair windsor_cmds[] = { + {VPU_CMD_ID_NOOP, GTB_ENC_CMD_NOOP}, {VPU_CMD_ID_CONFIGURE_CODEC, GTB_ENC_CMD_CONFIGURE_CODEC}, {VPU_CMD_ID_START, GTB_ENC_CMD_STREAM_START}, {VPU_CMD_ID_STOP, GTB_ENC_CMD_STREAM_STOP},