From patchwork Mon Feb 21 05:52:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Hung X-Patchwork-Id: 1595337 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=GRTC1xDA; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K2BL462gxz9sFn for ; Mon, 21 Feb 2022 16:53:16 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1nM1dB-0000EB-R5; Mon, 21 Feb 2022 05:53:05 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nM1d8-0000DP-PJ for kernel-team@lists.ubuntu.com; Mon, 21 Feb 2022 05:53:02 +0000 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 946443F1B6 for ; Mon, 21 Feb 2022 05:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645422782; bh=GHZEiq90wdnkI8nK4T5wKiTVVLl2+ijIci3BNUido6Q=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GRTC1xDAivKi9bRYJP5eigMddB0lPQvP7kU/xeAZzLS1v/c5fVi3eGNDmrRh0xvYf fpNbRz6x7G8sZyJvqXIQF08L+lUEuxoSMMvDdPUGzGw5O1zd3tIxUrlENa31RfGcN2 k9z1Fhx54q99FlFk6GCSYjgAS04M9uZmhAfdtQR3PLrcCqTsujOFujiWRKDoW6uEco fzLAyOUepRlJRPEhRqG4zAXHZzw7lA73inCGylnuK+RehsASIcUov9mekl7DjBo32y QBiPBK5zAnThB/qb2Py4fwupKGyAOeKam1ig+vKut2v+wdFLOFHYwaGYyhaRI3WdZV /x1C2MIdCWYKQ== Received: by mail-pj1-f69.google.com with SMTP id y15-20020a17090a390f00b001b9fde42fd4so13646287pjb.0 for ; Sun, 20 Feb 2022 21:53:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GHZEiq90wdnkI8nK4T5wKiTVVLl2+ijIci3BNUido6Q=; b=XAToKFXu08xgTxVWbDP3LGt92qjH1f4k8jIY+y5/t9FRe1TfDlWnOpKbnioCyfbtRj Ag4X/3uoT3YjQLAc99KYTivgIggeRskOlqSUwZXdXSc+D9bb/0djGcKuBs03x0rzjBuT QkTeggKE4lzxoIM313/fjvMoBVKbOD8W8ftiuXelal+i9Wem2hhk9VnrRUi1ivEajBON /mjhVWc5FvjF7rGMFCtH/xKY1U38XaeA25Z8SBcZucSWED8ZXvwatp6e6z6TJtMxcF2/ RZnhJaWLX4rX5YZlKGcVLJ5p5FOBmx6vxLj5soa2SVFze3e3+aBdPFq0I/LYHMtvORZ+ fykQ== X-Gm-Message-State: AOAM533VYVomxFQtRxJ5S/ifKyqSripMYrgYf3XkJm3UlMVOjU5QNfZD r90vtZs2A4pFdYMgbNA9MJRCAcQK+Xv8PtjzPmyk54km7ITVlaQt++PKlz7PCTFqky6ONgMUdNV MvxiGoMuiEdGREaf7ktAZo36n1BdvYLcEjZrUDR2vVQ== X-Received: by 2002:a17:902:8d8b:b0:14f:795a:977a with SMTP id v11-20020a1709028d8b00b0014f795a977amr12898558plo.104.1645422780739; Sun, 20 Feb 2022 21:53:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJya3rfTUTOTLRG51OJp9QhVPSzfBopTOibXLIrnHfLuK55j9ws4q8PQFddBxA8R6MkQtBq7Fw== X-Received: by 2002:a17:902:8d8b:b0:14f:795a:977a with SMTP id v11-20020a1709028d8b00b0014f795a977amr12898532plo.104.1645422780361; Sun, 20 Feb 2022 21:53:00 -0800 (PST) Received: from canonical.com (node-1w7jr9yebujeq5th4a1ypmfmg.ipv6.telus.net. [2001:56a:78ed:fb00::998]) by smtp.gmail.com with ESMTPSA id p10sm11717059pfo.209.2022.02.20.21.52.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Feb 2022 21:52:59 -0800 (PST) From: Alex Hung To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/7][SRU][OEM-5.14] HID: amd_sfh: Add command response to check command status Date: Sun, 20 Feb 2022 22:52:51 -0700 Message-Id: <20220221055257.1168996-2-alex.hung@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220221055257.1168996-1-alex.hung@canonical.com> References: <20220221055257.1168996-1-alex.hung@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Basavaraj Natikar BugLink: https://bugs.launchpad.net/bugs/1961121 Sometimes sensor enable/disable may take time, without checking the actual status bits from MP2 FW can lead the amd-sfh to misbehave. Hence add a status check of enable/disable command by waiting on the command response before sending the next command to FW. Reviewed-by: Shyam Sundar S K Signed-off-by: Basavaraj Natikar Signed-off-by: Jiri Kosina (cherry picked from commit 173709f50e98df4c49c2776834605a2f7ed3e681) Signed-off-by: Alex Hung --- drivers/hid/amd-sfh-hid/amd_sfh_client.c | 40 ++++++++++++++++++++++++-------- drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 16 +++++++++++++ drivers/hid/amd-sfh-hid/amd_sfh_pcie.h | 18 ++++++++++++++ 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_client.c b/drivers/hid/amd-sfh-hid/amd_sfh_client.c index 4710b9a..b7b66a1 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_client.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_client.c @@ -123,14 +123,24 @@ static void amd_sfh_work_buffer(struct work_struct *work) int i; for (i = 0; i < cli_data->num_hid_devices; i++) { - report_size = get_input_report(i, cli_data->sensor_idx[i], cli_data->report_id[i], - in_data); - hid_input_report(cli_data->hid_sensor_hubs[i], HID_INPUT_REPORT, - in_data->input_report[i], report_size, 0); + if (cli_data->sensor_sts[i] == SENSOR_ENABLED) { + report_size = get_input_report + (i, cli_data->sensor_idx[i], cli_data->report_id[i], in_data); + hid_input_report(cli_data->hid_sensor_hubs[i], HID_INPUT_REPORT, + in_data->input_report[i], report_size, 0); + } } schedule_delayed_work(&cli_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP)); } +u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts) +{ + if (mp2->mp2_ops->response) + sensor_sts = mp2->mp2_ops->response(mp2, sid, sensor_sts); + + return sensor_sts; +} + int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) { struct amd_input_data *in_data = &privdata->in_data; @@ -139,8 +149,8 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) struct device *dev; u32 feature_report_size; u32 input_report_size; + int rc, i, status; u8 cl_idx; - int rc, i; dev = &privdata->pdev->dev; @@ -155,7 +165,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) in_data->sensor_virt_addr[i] = dma_alloc_coherent(dev, sizeof(int) * 8, &cl_data->sensor_dma_addr[i], GFP_KERNEL); - cl_data->sensor_sts[i] = 0; + cl_data->sensor_sts[i] = SENSOR_DISABLED; cl_data->sensor_requested_cnt[i] = 0; cl_data->cur_hid_dev = i; cl_idx = cl_data->sensor_idx[i]; @@ -201,7 +211,10 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) if (rc) return rc; privdata->mp2_ops->start(privdata, info); - cl_data->sensor_sts[i] = 1; + status = amd_sfh_wait_for_response + (privdata, cl_data->sensor_idx[i], SENSOR_ENABLED); + if (status == SENSOR_ENABLED) + cl_data->sensor_sts[i] = SENSOR_ENABLED; } schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP)); return 0; @@ -224,10 +237,17 @@ int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata) { struct amdtp_cl_data *cl_data = privdata->cl_data; struct amd_input_data *in_data = cl_data->in_data; - int i; + int i, status; - for (i = 0; i < cl_data->num_hid_devices; i++) - privdata->mp2_ops->stop(privdata, i); + for (i = 0; i < cl_data->num_hid_devices; i++) { + if (cl_data->sensor_sts[i] == SENSOR_ENABLED) { + privdata->mp2_ops->stop(privdata, cl_data->sensor_idx[i]); + status = amd_sfh_wait_for_response + (privdata, cl_data->sensor_idx[i], SENSOR_DISABLED); + if (status != SENSOR_ENABLED) + cl_data->sensor_sts[i] = SENSOR_DISABLED; + } + } cancel_delayed_work_sync(&cl_data->work); cancel_delayed_work_sync(&cl_data->work_buffer); diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c index 1b4a192..ef2df3b 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,20 @@ static int sensor_mask_override = -1; module_param_named(sensor_mask, sensor_mask_override, int, 0444); MODULE_PARM_DESC(sensor_mask, "override the detected sensors mask"); +static int amd_sfh_wait_response_v2(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts) +{ + union cmd_response cmd_resp; + + /* Get response with status within a max of 800 ms timeout */ + if (!readl_poll_timeout(mp2->mmio + AMD_P2C_MSG(0), cmd_resp.resp, + (cmd_resp.response_v2.response == sensor_sts && + cmd_resp.response_v2.status == 0 && (sid == 0xff || + cmd_resp.response_v2.sensor_id == sid)), 500, 800000)) + return cmd_resp.response_v2.response; + + return SENSOR_DISABLED; +} + static void amd_start_sensor_v2(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info) { union sfh_cmd_base cmd_base; @@ -183,6 +198,7 @@ static const struct amd_mp2_ops amd_sfh_ops_v2 = { .start = amd_start_sensor_v2, .stop = amd_stop_sensor_v2, .stop_all = amd_stop_all_sensor_v2, + .response = amd_sfh_wait_response_v2, }; static const struct amd_mp2_ops amd_sfh_ops = { diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h index 2d5c57e..21ef55d 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h @@ -24,12 +24,16 @@ #define AMD_C2P_MSG2 0x10508 #define AMD_C2P_MSG(regno) (0x10500 + ((regno) * 4)) +#define AMD_P2C_MSG(regno) (0x10680 + ((regno) * 4)) /* MP2 P2C Message Registers */ #define AMD_P2C_MSG3 0x1068C /* Supported Sensors info */ #define V2_STATUS 0x2 +#define SENSOR_ENABLED 4 +#define SENSOR_DISABLED 5 + #define HPD_IDX 16 /* SFH Command register */ @@ -51,6 +55,19 @@ union sfh_cmd_base { } cmd_v2; }; +union cmd_response { + u32 resp; + struct { + u32 status : 2; + u32 out_in_c2p : 1; + u32 rsvd1 : 1; + u32 response : 4; + u32 sub_cmd : 8; + u32 sensor_id : 6; + u32 rsvd2 : 10; + } response_v2; +}; + union sfh_cmd_param { u32 ul; struct { @@ -117,5 +134,6 @@ struct amd_mp2_ops { void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info); void (*stop)(struct amd_mp2_dev *privdata, u16 sensor_idx); void (*stop_all)(struct amd_mp2_dev *privdata); + int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts); }; #endif