From patchwork Sat Nov 5 21:11:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 621878 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 0F2A3C4332F for ; Sat, 5 Nov 2022 21:12:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229991AbiKEVMg (ORCPT ); Sat, 5 Nov 2022 17:12:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbiKEVMf (ORCPT ); Sat, 5 Nov 2022 17:12:35 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0AB611810; Sat, 5 Nov 2022 14:12:34 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id ud5so21380187ejc.4; Sat, 05 Nov 2022 14:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZSJlpADL6FxqQLVTkCQJu3ikcoUIWPyVlc8ef31tV88=; b=KkxYKwLguylCO+MOb3Wo7CY9rR2ZX6ti/BveSUiotix/fU5ITz9DR6TU/JEBJnD8dO Emvu1hSojxp2l3AlfTrBbDxTL/kkDr3jYrO6bCLL7ud00sIAYRPnmvphyYnLUeU6p0uA 9gbBBObTNmua0uFrEeyFdPucSAf1xblJvPAy8/3vEgCfg9nonqgIET0X3SxF/xkOJzrC y2x5h+/k+6Yuq7lo/wuM2RBvIyYB6H7zRr9Xtni523bgRVNQoBLAHgfgH1CukRONGWMt YzDH4jshP0fDR3RyRYeQUIfLQn8uYJJ9LxivcyhrSszpvjdXVc+JQZKU00VX7brfOuF1 comw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZSJlpADL6FxqQLVTkCQJu3ikcoUIWPyVlc8ef31tV88=; b=2SBpT9XP5iHsE0c55dj4YP6+/pHMMI3uuMEC0odQ5zfogQwNLYZyaSrUsszL1iiET+ 73or/IDl6fegqySBjR7NV6ZLzfia858LdDOWwavstzN0GpA+bwYTqrwERrzklLANrNRR nGDnCaR3ZPGsFtoZHFNfhVn/bl1iIBU47XtGAHey64hRUwLSV49puYggiOjPB7mnGftV woiOnXRbPQ71ItWTmTolirABsR5cKyMxwZcDjiImndMva3Q/jqJ/DFj1VaM7P2gGhPwg 5y0N6w8oClCIPzb2dVwqi3/sP6VuWgtyuqzhsy1wiIKVxSUq7gAnzdwlm6wiThPuZhIW jDGg== X-Gm-Message-State: ACrzQf1QH79n6IUv16bY2Miaqr/HItWKay/vqp2/hF4oChgmYzGgWfJX CwfrNn2liiygS1WMA3qHxgo= X-Google-Smtp-Source: AMsMyM5nuu0DYzHoEpqFUn/wyXveSAK3LL1IxYlC5a6zOxMHAIx7TCnalFV2T0emNlo/rhxIvzzKsw== X-Received: by 2002:a17:907:72c3:b0:792:56d7:285a with SMTP id du3-20020a17090772c300b0079256d7285amr39988211ejc.597.1667682753198; Sat, 05 Nov 2022 14:12:33 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:12:32 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman , Guillaume Champagne Subject: [PATCH v4 01/13] HID: ft260: ft260_xfer_status routine cleanup Date: Sat, 5 Nov 2022 23:11:39 +0200 Message-Id: <20221105211151.7094-2-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org After clarifying with FTDI's support, it turned out that the error condition (bit 1) in byte 1 of the i2c status HID report is a status bit reflecting all error conditions. When bits 2, 3, or 4 are raised to 1, bit 1 is set to 1 also. Since the ft260_xfer_status routine tests the error condition bit and exits in the case of an error, the program flow never reaches the conditional expressions for 2, 3, and 4 bits when any of them indicates an error state. Though these expressions are never evaluated to true, they are checked several times per IO, increasing the ft260_xfer_status polling cycle duration. The patch removes the conditional expressions for 2, 3, and 4 bits in byte 1 of the i2c status HID report. Signed-off-by: Michael Zaidman Tested-by: Guillaume Champagne --- drivers/hid/hid-ft260.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index 79505c64dbfe..a35201d68b15 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -313,27 +313,17 @@ static int ft260_xfer_status(struct ft260_device *dev) if (report.bus_status & FT260_I2C_STATUS_CTRL_BUSY) return -EAGAIN; - if (report.bus_status & FT260_I2C_STATUS_BUS_BUSY) - return -EBUSY; - - if (report.bus_status & FT260_I2C_STATUS_ERROR) + /* + * The error condition (bit 1) is a status bit reflecting any + * error conditions. When any of the bits 2, 3, or 4 are raised + * to 1, bit 1 is also set to 1. + */ + if (report.bus_status & FT260_I2C_STATUS_ERROR) { + hid_err(hdev, "i2c bus error: %#02x\n", report.bus_status); return -EIO; + } - ret = -EIO; - - if (report.bus_status & FT260_I2C_STATUS_ADDR_NO_ACK) - ft260_dbg("unacknowledged address\n"); - - if (report.bus_status & FT260_I2C_STATUS_DATA_NO_ACK) - ft260_dbg("unacknowledged data\n"); - - if (report.bus_status & FT260_I2C_STATUS_ARBITR_LOST) - ft260_dbg("arbitration loss\n"); - - if (report.bus_status & FT260_I2C_STATUS_CTRL_IDLE) - ret = 0; - - return ret; + return 0; } static int ft260_hid_output_report(struct hid_device *hdev, u8 *data, @@ -376,7 +366,7 @@ static int ft260_hid_output_report_check_status(struct ft260_device *dev, break; } while (--try); - if (ret == 0 || ret == -EBUSY) + if (ret == 0) return 0; ft260_i2c_reset(hdev); From patchwork Sat Nov 5 21:11:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 622776 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 08BEBC43217 for ; Sat, 5 Nov 2022 21:12:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230100AbiKEVMq (ORCPT ); Sat, 5 Nov 2022 17:12:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230086AbiKEVMp (ORCPT ); Sat, 5 Nov 2022 17:12:45 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0708911A01; Sat, 5 Nov 2022 14:12:42 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id b2so21344808eja.6; Sat, 05 Nov 2022 14:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RqowWq5NnPX1JsllkPtBTllVoOrDwgpWdvHnLuJ47J8=; b=cfv3VMxE7Hw8TlRhts/LzufO93wAhFaFLwnTRHqavjCnWw43SKsvAGmn/c6P6HmfvA 73LquxHA1POMbMIIJcU2NobiP++uWArpDZEwRhWMFAuDE6NcuMYy1fhDWwwnLXOyw7OT 0P/wSFSQu5zPyhe+skjoBi5aGmfS3Mjrb7fyk+he6Y5nJWAz4Ggb2NybSGRkLZ4AkVs7 5RIC9SdWbkAdDPMk8UAiZuFBhFbg0mDtQvzJq/eNFS01GAcnEiU+pCD9Gb++pm5NUNui 23FOUc5aVO4lSmh2rCRtn1hyomZ99hMkIFBPvhDUXLnfl73VMT3Q3b0ujlb9Z5qXs1G4 zEpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RqowWq5NnPX1JsllkPtBTllVoOrDwgpWdvHnLuJ47J8=; b=nMxvZ97L66dTi5/z5upjqabKC4d2QEFO6Tnw1ndL/joMySQsUCXJqyCUQTKaUuX64g Kqtj8d58b2X68nBEuBwjkWmLx+94QJFPg1UayIgBV+DtcZizwG+wbU9v960PneZEg1o7 m6iLlnwtCrr/WK260iggL/G9JETLAy1/6piZ1NY3BEchcZ1o3Jf1OdVBKRu1+6UnQH2c jJNmgSST+tdylaY4hKbN/+DZ9Br1o+MnDYZnerYref+3GgaXuYl7Xu3RgxmqoZEea6sf DwOIQPbEZ/Ocm3iiWr62zFVmuRB3iASqV1FENoF3Rorn5v/4UaCp0IViW+3bhOsYza4Z X16A== X-Gm-Message-State: ACrzQf1y3WPBigEfRvuBPYtj79yK7V0GNKpUeFiDHYvbZMRHEESzSqUl vARQXadQMedT2FJKSXmzvGk= X-Google-Smtp-Source: AMsMyM651U+c+oA+m4aRUhUW5VD3BBNoHPpaRaEo4Xei07IywvkNaD8n1N0UQPdkmmJz+BL9Abg9Nw== X-Received: by 2002:a17:907:2714:b0:7ad:e2b5:e068 with SMTP id w20-20020a170907271400b007ade2b5e068mr29059316ejk.715.1667682760573; Sat, 05 Nov 2022 14:12:40 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:12:40 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman , Guillaume Champagne Subject: [PATCH v4 02/13] HID: ft260: improve i2c write performance Date: Sat, 5 Nov 2022 23:11:40 +0200 Message-Id: <20221105211151.7094-3-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The patch improves the I2C write performance by 20 - 30 percent by revising the sleep time in the ft260_hid_output_report_check_status() in the following ways: 1. Reduce the wait time and start to poll earlier. Sending a large amount of data at a low I2C clock rate saturates the internal FT260 buffer and causes hiccups in status readiness, as shown below in the log fragment. Aligning the status check wait time to the worst case significantly reduces the write performance. [Oct22 10:28] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0 [ +0.005296] ft260_xfer_status: bus_status 0x20, clock 100 [ +0.013460] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0 [ +0.003244] ft260_hid_output_report_check_status: wait 1920 usec, len 38 [ +0.000190] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.015324] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0 [ +0.003491] ft260_hid_output_report_check_status: wait 1920 usec, len 38 [ +0.000202] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.016047] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0 [ +0.002768] ft260_hid_output_report_check_status: wait 1920 usec, len 38 [ +0.000150] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.011389] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0 [ +0.003467] ft260_hid_output_report_check_status: wait 1920 usec, len 38 [ +0.000191] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000172] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000131] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000241] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000233] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000190] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000196] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.011314] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0 [ +0.003334] ft260_hid_output_report_check_status: wait 1920 usec, len 38 [ +0.000227] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000204] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000198] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000147] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.011060] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0 Before: $ sudo ./i2cperf -f 2 -o 2 -s 32 -r 0-0xff 13 0x51 -S Fill block with increment via i2ctransfer by chunks ------------------------------------------------------------------- data rate(bps) efficiency(%) data size(B) total IOs IO size(B) ------------------------------------------------------------------- 40510 80 256 8 32 After: $ sudo ./i2cperf -f 2 -o 2 -s 32 -r 0-0xff 13 0x51 -S Fill block with increment via i2ctransfer by chunks ------------------------------------------------------------------- data rate(bps) efficiency(%) data size(B) total IOs IO size(B) ------------------------------------------------------------------- 52584 80 256 8 32 2. Do not sleep if the estimated I2C transfer time is below 2 ms since the first xfer status query frequently takes around 1.5 ms, and the following status queries take about 200us on average. So we usually return from the routine after the first 1 - 3 status checks. [Oct22 11:14] ft260_i2c_write: rep 0xd4 addr 0x51 off 0 len 18 d[0] 0x0 [ +0.004270] ft260_xfer_status: bus_status 0x20, clock 100 [ +0.013889] ft260_i2c_write: rep 0xd4 addr 0x51 off 0 len 18 d[0] 0x0 [ +0.000856] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000138] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.013352] ft260_i2c_write: rep 0xd4 addr 0x51 off 0 len 18 d[0] 0x0 [ +0.001501] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000177] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.014477] ft260_i2c_write: rep 0xd4 addr 0x51 off 0 len 18 d[0] 0x0 [ +0.001377] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000233] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000191] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.013197] ft260_i2c_write: rep 0xd4 addr 0x51 off 0 len 18 d[0] 0x0 Before: $ sudo ./i2cperf -f 2 -o 2 -s 16 -r 0-0xff 13 0x51 -S Fill block with increment via i2ctransfer by chunks ------------------------------------------------------------------- data rate(bps) efficiency(%) data size(B) total IOs IO size(B) ------------------------------------------------------------------- 28826 73 256 16 16 After: $ sudo ./i2cperf -f 2 -o 2 -s 16 -r 0-0xff 13 0x51 -S Fill block with increment via i2ctransfer by chunks ------------------------------------------------------------------- data rate(bps) efficiency(%) data size(B) total IOs IO size(B) ------------------------------------------------------------------- 45138 73 256 16 16 Signed-off-by: Michael Zaidman Tested-by: Guillaume Champagne --- drivers/hid/hid-ft260.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index a35201d68b15..44106cadd746 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -345,7 +345,7 @@ static int ft260_hid_output_report(struct hid_device *hdev, u8 *data, static int ft260_hid_output_report_check_status(struct ft260_device *dev, u8 *data, int len) { - int ret, usec, try = 3; + int ret, usec, try = 100; struct hid_device *hdev = dev->hdev; ret = ft260_hid_output_report(hdev, data, len); @@ -356,10 +356,14 @@ static int ft260_hid_output_report_check_status(struct ft260_device *dev, return ret; } - /* transfer time = 1 / clock(KHz) * 10 bits * bytes */ - usec = 10000 / dev->clock * len; - usleep_range(usec, usec + 100); - ft260_dbg("wait %d usec, len %d\n", usec, len); + /* transfer time = 1 / clock(KHz) * 9 bits * bytes */ + usec = len * 9000 / dev->clock; + if (usec > 2000) { + usec -= 1500; + usleep_range(usec, usec + 100); + ft260_dbg("wait %d usec, len %d\n", usec, len); + } + do { ret = ft260_xfer_status(dev); if (ret != -EAGAIN) From patchwork Sat Nov 5 21:11:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 621877 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 F3CF9C43217 for ; Sat, 5 Nov 2022 21:12:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbiKEVMv (ORCPT ); Sat, 5 Nov 2022 17:12:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbiKEVMr (ORCPT ); Sat, 5 Nov 2022 17:12:47 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A28FD1182B; Sat, 5 Nov 2022 14:12:46 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id f5so21376283ejc.5; Sat, 05 Nov 2022 14:12:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DNp683CGj+Z6itDhM79bg7tLFjPTOBd5dr9kEuZxIG0=; b=jSP8rX2OYgpY9svnfLdJCrhFOnfGvCRR6duCKcGyP5C0T9CFx9uvRPVZ3A2a/jik5N fp0swRahG6SKBzgtMxK4dTeesmtMJQMoU/AFDnIPrzx1dfB3GpLHm0+LEevVo+DRZycB tfdB/SVdMeTkG9of9n5R5tvboHHBIJTKkawsx6XWDX2/rfR4iXSp0HbIVxkRNSeTFkDB 48ReGcuMLeGcj/VpXsv8LuAbZwUVld78oifd4hklX5Awnr90PcTuh/YGpR2bdunOF7kk koYOpBcZzTYLCUYavzrOBRnvdF5TusbYu9ki35oUvWF07MMmKjoMpnrR9qXUCeSjpSai tHyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DNp683CGj+Z6itDhM79bg7tLFjPTOBd5dr9kEuZxIG0=; b=V+FvgjHyPan5Dp7fV8LKQjJt7omwDRK2bBGunt0+nEbgIQGkFROF1fml067bVbHJcZ RKQMdTfzfrW/YKkScRjcugnlOwyHOs+MEB1M2uhurIoP5NT+X2xewE4c/66KXJEm+40D 8MWkhYXrKENbr4U434w9wIVd1pqQBOpWC4rFJMKKuY7ZMgubowoSBimJWhKWqHNo07Rs Zt3tn4qWejpERv1DViWsNeJC6/EyhtLVcAK/DpH9d4rYlU1d/Eb1SYbyxNBrjnIQvvl8 6JMZAKH8rJ9HOvOJ2YrjCblDw2QFe+Efzy5r5IAUngXugEmrNxO12FPz8xY270KG9qtb LUkg== X-Gm-Message-State: ACrzQf3pFJ0B61fIMDiOD9GfD+WUWTMwNDpAQPVcsmTzXIN/Vaz4VC9o i8GVj/NUyrX8J90RnrGs4v2ntFD74zcysA== X-Google-Smtp-Source: AMsMyM4ZObKe5UfkKgA01Cb8flMs1nqmBkv0JkxuSuXiiMbSAH22+UfTvJUdoQsnn13I5zwNnDccTA== X-Received: by 2002:a17:907:75cc:b0:7ad:b9b7:582b with SMTP id jl12-20020a17090775cc00b007adb9b7582bmr37747860ejc.150.1667682765013; Sat, 05 Nov 2022 14:12:45 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:12:44 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman , Guillaume Champagne Subject: [PATCH v4 03/13] HID: ft260: support i2c writes larger than HID report size Date: Sat, 5 Nov 2022 23:11:41 +0200 Message-Id: <20221105211151.7094-4-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org To support longer than one HID report size write, the driver splits a single i2c message data payload into multiple i2c messages of HID report size. However, it does not replicate the offset bytes within the EEPROM chip in every consequent HID report because it is not and should not be aware of the EEPROM type. It breaks the i2c write message integrity and causes the EEPROM device not to acknowledge the second HID report keeping the i2c bus busy until the ft260 controller reports failure. This patch preserves the i2c write message integrity by manipulating the i2c flag bits across multiple HID reports to be seen by the EEPROM device as a single i2c write transfer. Before: $ sudo ./i2cperf -f 2 -o 2 -s 64 -r 0-0xff 13 0x51 -S Error: Sending messages failed: Input/output error [ +3.667741] ft260_i2c_write: rep 0xde addr 0x51 off 0 len 60 d[0] 0x0 [ +0.007330] ft260_hid_output_report_check_status: wait 6400 usec, len 64 [ +0.000203] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.000001] ft260_i2c_write: rep 0xd1 addr 0x51 off 60 len 6 d[0] 0x0 [ +0.002337] ft260_hid_output_report_check_status: wait 1000 usec, len 10 [ +0.000157] ft260_xfer_status: bus_status 0x2e, clock 100 [ +0.000241] ft260_i2c_reset: done [ +0.000003] ft260_i2c_write: failed to start transfer, ret -5 After: $ sudo ./i2cperf -f 2 -o 2 -s 128 -r 0-0xff 13 0x51 -S Fill block with increment via i2ctransfer by chunks ------------------------------------------------------------------- data rate(bps) efficiency(%) data size(B) total IOs IO size(B) ------------------------------------------------------------------- 71260 86 256 2 128 Signed-off-by: Michael Zaidman Tested-by: Guillaume Champagne --- drivers/hid/hid-ft260.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index 44106cadd746..cec83f69ebdc 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -378,41 +378,46 @@ static int ft260_hid_output_report_check_status(struct ft260_device *dev, } static int ft260_i2c_write(struct ft260_device *dev, u8 addr, u8 *data, - int data_len, u8 flag) + int len, u8 flag) { - int len, ret, idx = 0; + int ret, wr_len, idx = 0; struct hid_device *hdev = dev->hdev; struct ft260_i2c_write_request_report *rep = (struct ft260_i2c_write_request_report *)dev->write_buf; + rep->flag = FT260_FLAG_START; + do { - if (data_len <= FT260_WR_DATA_MAX) - len = data_len; - else - len = FT260_WR_DATA_MAX; + if (len <= FT260_WR_DATA_MAX) { + wr_len = len; + if (flag == FT260_FLAG_START_STOP) + rep->flag |= FT260_FLAG_STOP; + } else { + wr_len = FT260_WR_DATA_MAX; + } - rep->report = FT260_I2C_DATA_REPORT_ID(len); + rep->report = FT260_I2C_DATA_REPORT_ID(wr_len); rep->address = addr; - rep->length = len; - rep->flag = flag; + rep->length = wr_len; - memcpy(rep->data, &data[idx], len); + memcpy(rep->data, &data[idx], wr_len); - ft260_dbg("rep %#02x addr %#02x off %d len %d d[0] %#02x\n", - rep->report, addr, idx, len, data[0]); + ft260_dbg("rep %#02x addr %#02x off %d len %d wlen %d flag %#x d[0] %#02x\n", + rep->report, addr, idx, len, wr_len, + rep->flag, data[0]); ret = ft260_hid_output_report_check_status(dev, (u8 *)rep, - len + 4); + wr_len + 4); if (ret < 0) { - hid_err(hdev, "%s: failed to start transfer, ret %d\n", - __func__, ret); + hid_err(hdev, "%s: failed with %d\n", __func__, ret); return ret; } - data_len -= len; - idx += len; + len -= wr_len; + idx += wr_len; + rep->flag = 0; - } while (data_len > 0); + } while (len > 0); return 0; } From patchwork Sat Nov 5 21:11:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 622775 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 13042C433FE for ; Sat, 5 Nov 2022 21:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229971AbiKEVNJ (ORCPT ); Sat, 5 Nov 2022 17:13:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230131AbiKEVMx (ORCPT ); Sat, 5 Nov 2022 17:12:53 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E81E1183C; Sat, 5 Nov 2022 14:12:51 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id d26so21297671eje.10; Sat, 05 Nov 2022 14:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ALhJBetIf5X/SyaoXHlGdZsad0OG/1yQx1wQzt9ePhk=; b=JVD+DIUGz7tcYWKpKFUiLGHd5GsgisugyiOu3/TQj1m/kih6cjyY4I0AFK75u5QDaY mKMAKa3VVEsRUfLaZVFTPw5vQWDO0TgeJsitgfg+7OAYO2Sj09b9SXHs50VfVg8RhGVG HKOhfdnqqaobWogzBQJ99RhU+nbvyiGgUP/yU8e+5drKbyqCCVgGrDApxvKlA2XHBntk lgczeCa7myP3Iy4H+Z7RBtF6Kdq1YYTCygJow+QgwTsBjGJOrk1qscSjX6Vue6TQZ3kf nIDzayF6yra+TnewrrwaO06KVROTk2ryXa/I5bhp2tVheLHW7xFHXe4WoRahgVp+2dlB P2jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ALhJBetIf5X/SyaoXHlGdZsad0OG/1yQx1wQzt9ePhk=; b=wKKlTDYtN0sjyqhmN1aPzOsbp34ellDQJw2aJ7tml/uqC1GzmNsLPtJnsqa9o/oh8U K5sd3sQpzFN6ssnMCRXjC7QChNrzdmhPHBPdOWVVR2OQ7cEeB4VHbKBON4kRDHMGM9n2 TXBLaiwzFsSNgqCo7GxzLaKukf4DK71VCkIoHR1XlhOHvfc25DZv7fs2nqAnGI/GqGhJ ejliuqSt/YiYwfePoNTZ61kG6hB5AZB7IlA3MJX7f85QsTFgcdskx+ZymdGN1BPtEIjF Nst9M6LvPE8Jxqw9rrzm5G+BNi0JTtgPNy9mlAwEDOTT/LuW6iTMSJrnq6/zD1piF4q4 yNOg== X-Gm-Message-State: ACrzQf1Ks20zsTzXXuE7GAh93SRy7loF1mIX6JMgHKLZYwdGrI1b6LON alc/FQD0GqTl9AgIxuI9bQA= X-Google-Smtp-Source: AMsMyM4U3Oh2dbtyCVr8QUm0v7UkS75SXqRhWWHc+KQIG8z3FPgVlI/GVoayUxuttyDq+oZB2VEQUg== X-Received: by 2002:a17:907:728c:b0:78e:2856:7fed with SMTP id dt12-20020a170907728c00b0078e28567fedmr41268521ejc.2.1667682769440; Sat, 05 Nov 2022 14:12:49 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:12:49 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman , Guillaume Champagne Subject: [PATCH v4 04/13] HID: ft260: support i2c reads greater than HID report size Date: Sat, 5 Nov 2022 23:11:42 +0200 Message-Id: <20221105211151.7094-5-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org A random i2c read operation in EEPROM devices is implemented as a dummy write operation, followed by a current address read operation. The dummy write operation is used to load the target byte or word address (a.k.a offset) into the offset counter, from which the subsequent read operation then reads. To support longer than one HID report size random read, the ft260 driver issues multiple pairs of i2c write offset + read data transactions of HID report size so that the EEPROM device sees many i2c random read requests from different offsets. Two issues with the current implementation: - This approach suffers from extra overhead caused by writing offset requests. - Necessity to handle offset per HID report in big-endian representation as EEPROM devices expect. The current implementation does not do it and correctly handles the reads up to 60 bytes only. This patch addresses both issues by implementing more efficient approach. It issues a single i2c read request of up to the EEPROM page size and then waits for the data to arrive in multiple HID reports. For example, to read the 256 bytes from a 24LC512 chip, which has 128 bytes page size, the old method performs six ft260_i2c_write_read transactions while the new - two only. Before: $ sudo ./i2cperf -d 2 -o 2 -s 128 -r 0-0xff 13 0x51 -S Read block via i2ctransfer by chunks ------------------------------------------------------------------- data rate(bps) efficiency(%) data size(B) total IOs IO size(B) ------------------------------------------------------------------- 40803 85 256 2 128 Kernel log of a single 128 bytes read request: [ +2.376308] ft260_i2c_write_read: read_off 0x0 left_len 128 len 60 [ +0.000002] ft260_i2c_write: rep 0xd0 addr 0x51 off 0 len 2 wlen 2 flag 0x2 d[0] 0x0 [ +0.000707] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000173] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.000001] ft260_i2c_read: rep 0xc2 addr 0x51 len 60 [ +0.008660] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.000156] ft260_xfer_status: bus_status 0x20, clock 100 [ +0.000001] ft260_i2c_write_read: read_off 0x3c left_len 68 len 60 [ +0.000001] ft260_i2c_write: rep 0xd0 addr 0x51 off 0 len 2 wlen 2 flag 0x2 d[0] 0x3c [ +0.001034] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000191] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.000001] ft260_i2c_read: rep 0xc2 addr 0x51 len 60 [ +0.008614] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.000203] ft260_xfer_status: bus_status 0x20, clock 100 [ +0.000001] ft260_i2c_write_read: read_off 0x78 left_len 8 len 8 [ +0.000001] ft260_i2c_write: rep 0xd0 addr 0x51 off 0 len 2 wlen 2 flag 0x2 d[0] 0x78 [ +0.000987] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000192] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.000001] ft260_i2c_read: rep 0xc2 addr 0x51 len 8 [ +0.002614] ft260_raw_event: i2c resp: rep 0xd1 len 8 [ +0.000200] ft260_xfer_status: bus_status 0x20, clock 100 After: $ sudo ./i2cperf -d 2 -o 2 -s 128 -r 0-0xff 13 0x51 -S Read block via i2ctransfer by chunks ------------------------------------------------------------------- data rate(bps) efficiency(%) data size(B) total IOs IO size(B) ------------------------------------------------------------------- 43990 85 256 2 128 Kernel log of a single 128 bytes read request: [ +1.464346] ft260_i2c_write_read: off 0x0 rlen 128 wlen 2 [ +0.000002] ft260_i2c_write: rep 0xd0 addr 0x51 off 0 len 2 wlen 2 flag 0x2 d[0] 0x0 [ +0.001653] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000188] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.000002] ft260_i2c_read: rep 0xc2 addr 0x51 len 128 rlen 60 flag 0x3 [ +0.008609] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.000157] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.000002] ft260_i2c_read: rep 0xc2 addr 0x51 len 68 rlen 60 flag 0x0 [ +0.008840] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.000203] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.000002] ft260_i2c_read: rep 0xc2 addr 0x51 len 8 rlen 8 flag 0x4 [ +0.002794] ft260_raw_event: i2c resp: rep 0xd1 len 8 [ +0.000201] ft260_xfer_status: bus_status 0x20, clock 100 Signed-off-by: Michael Zaidman Tested-by: Guillaume Champagne --- drivers/hid/hid-ft260.c | 127 +++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 61 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index cec83f69ebdc..a354089bb747 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -456,49 +456,62 @@ static int ft260_smbus_write(struct ft260_device *dev, u8 addr, u8 cmd, static int ft260_i2c_read(struct ft260_device *dev, u8 addr, u8 *data, u16 len, u8 flag) { + u16 rd_len; + int timeout, ret; struct ft260_i2c_read_request_report rep; struct hid_device *hdev = dev->hdev; - int timeout; - int ret; - if (len > FT260_RD_DATA_MAX) { - hid_err(hdev, "%s: unsupported rd len: %d\n", __func__, len); - return -EINVAL; - } + if ((flag & FT260_FLAG_START_REPEATED) == FT260_FLAG_START_REPEATED) + flag = FT260_FLAG_START_REPEATED; + else + flag = FT260_FLAG_START; + do { + if (len <= FT260_RD_DATA_MAX) { + rd_len = len; + flag |= FT260_FLAG_STOP; + } else { + rd_len = FT260_RD_DATA_MAX; + } - dev->read_idx = 0; - dev->read_buf = data; - dev->read_len = len; + dev->read_idx = 0; + dev->read_buf = data; + dev->read_len = rd_len; - rep.report = FT260_I2C_READ_REQ; - rep.length = cpu_to_le16(len); - rep.address = addr; - rep.flag = flag; + rep.report = FT260_I2C_READ_REQ; + rep.length = cpu_to_le16(rd_len); + rep.address = addr; + rep.flag = flag; - ft260_dbg("rep %#02x addr %#02x len %d\n", rep.report, rep.address, - rep.length); + ft260_dbg("rep %#02x addr %#02x len %d rlen %d flag %#x\n", + rep.report, rep.address, len, rd_len, flag); - reinit_completion(&dev->wait); + reinit_completion(&dev->wait); - ret = ft260_hid_output_report(hdev, (u8 *)&rep, sizeof(rep)); - if (ret < 0) { - hid_err(hdev, "%s: failed to start transaction, ret %d\n", - __func__, ret); - return ret; - } + ret = ft260_hid_output_report(hdev, (u8 *)&rep, sizeof(rep)); + if (ret < 0) { + hid_err(hdev, "%s: failed with %d\n", __func__, ret); + return ret; + } - timeout = msecs_to_jiffies(5000); - if (!wait_for_completion_timeout(&dev->wait, timeout)) { - ft260_i2c_reset(hdev); - return -ETIMEDOUT; - } + timeout = msecs_to_jiffies(5000); + if (!wait_for_completion_timeout(&dev->wait, timeout)) { + ft260_i2c_reset(hdev); + return -ETIMEDOUT; + } - ret = ft260_xfer_status(dev); - if (ret == 0) - return 0; + ret = ft260_xfer_status(dev); + if (ret < 0) { + ft260_i2c_reset(hdev); + return -EIO; + } - ft260_i2c_reset(hdev); - return -EIO; + len -= rd_len; + data += rd_len; + flag = 0; + + } while (len > 0); + + return 0; } /* @@ -509,45 +522,37 @@ static int ft260_i2c_read(struct ft260_device *dev, u8 addr, u8 *data, */ static int ft260_i2c_write_read(struct ft260_device *dev, struct i2c_msg *msgs) { - int len, ret; - u16 left_len = msgs[1].len; - u8 *read_buf = msgs[1].buf; + int ret; + int wr_len = msgs[0].len; + int rd_len = msgs[1].len; + struct hid_device *hdev = dev->hdev; u8 addr = msgs[0].addr; u16 read_off = 0; - struct hid_device *hdev = dev->hdev; - if (msgs[0].len > 2) { - hid_err(hdev, "%s: unsupported wr len: %d\n", __func__, - msgs[0].len); + if (wr_len > 2) { + hid_err(hdev, "%s: invalid wr_len: %d\n", __func__, wr_len); return -EOPNOTSUPP; } - memcpy(&read_off, msgs[0].buf, msgs[0].len); - - do { - if (left_len <= FT260_RD_DATA_MAX) - len = left_len; + if (ft260_debug) { + if (wr_len == 2) + read_off = be16_to_cpu(*(u16 *)msgs[0].buf); else - len = FT260_RD_DATA_MAX; + read_off = *msgs[0].buf; - ft260_dbg("read_off %#x left_len %d len %d\n", read_off, - left_len, len); - - ret = ft260_i2c_write(dev, addr, (u8 *)&read_off, msgs[0].len, - FT260_FLAG_START); - if (ret < 0) - return ret; - - ret = ft260_i2c_read(dev, addr, read_buf, len, - FT260_FLAG_START_STOP); - if (ret < 0) - return ret; + pr_info("%s: off %#x rlen %d wlen %d\n", __func__, + read_off, rd_len, wr_len); + } - left_len -= len; - read_buf += len; - read_off += len; + ret = ft260_i2c_write(dev, addr, msgs[0].buf, wr_len, + FT260_FLAG_START); + if (ret < 0) + return ret; - } while (left_len > 0); + ret = ft260_i2c_read(dev, addr, msgs[1].buf, rd_len, + FT260_FLAG_START_STOP_REPEATED); + if (ret < 0) + return ret; return 0; } From patchwork Sat Nov 5 21:11:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 621876 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 B8819C43219 for ; Sat, 5 Nov 2022 21:13:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbiKEVNN (ORCPT ); Sat, 5 Nov 2022 17:13:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230018AbiKEVNE (ORCPT ); Sat, 5 Nov 2022 17:13:04 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C52911C13; Sat, 5 Nov 2022 14:12:55 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id v27so12272374eda.1; Sat, 05 Nov 2022 14:12:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YSSvluQm3NGC5J6X42oGu/YUSo51/OoBhNLx5zGbzEw=; b=bBbmixxXZOY2xxelIgiyCOhcCDIZ52+f+3hq86RrpIDyUQnjg+eM+KJnq2/o9pCGZL VbU38fSx7CUQus6utx273xANyUL68yHm7zkRFQYBs9xQKOJWhESCIGlqCu/c1jesV1Ti 2B5wBiCMJDxlZyRpkZ7RSX2+9/4UDq3GxvyK/rMC64Us86MrLKcUATGkxdDy9L2E0boZ vDLMSq2e9pCU6FrLylW3Y//4sfBmop/6DzNNIXFfqkHELrACSDXmk/W3d6DeYeD81FCV t+DysS04PJplx12tKBGVgDUDU8/ykwYV1B0kDa5QYbFgBOjV+9tZz3i+T543KUT7PLJq /sLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YSSvluQm3NGC5J6X42oGu/YUSo51/OoBhNLx5zGbzEw=; b=8KtVdhlrUuY6+dz0hjvJuG6aI9zugvi2KtJHYzZveRyWVLl1a0DMnHYezwlrTrz0UQ +wXHxM2Y2XuAyRzLPUD99DF2Zjk/CYYblSSNS9/t0dKqdbBhq5Tz3vinyosrLgwxcNV5 3+n+z/38GugtSx90PuSkK0jxMfI3b3KfU2g0Bu4s4gwL1BOCjkpp9eM+1dpJItHqtCff Tkn93CycycsiVScwxXbrzfhsnXSeBEBHO7KjsDduX0Bv4BRTUHwYe67o2d2z/uFubzoZ iGyIBPVc624uD2ZFXk6d5T08dCEJFVxPb3lxbByNZ/N2y/iylo4V85Rx/ICkw5LujJKo PkOQ== X-Gm-Message-State: ACrzQf23UZiM9Y8ecZN5nXBkMyvdaA9Y68ZPwQsaVRHpXco9RN6nWEYo xZfdruJ4J4tkwnQxjfbMKjs= X-Google-Smtp-Source: AMsMyM5vVypAaj3/q1whPPfHQnfPsa5f8ysab+6nwFUKbs9QM+VPJPNtgQrUr+DqzWM4PRlZLV/ewA== X-Received: by 2002:a05:6402:5250:b0:461:e870:850f with SMTP id t16-20020a056402525000b00461e870850fmr41969402edd.404.1667682774203; Sat, 05 Nov 2022 14:12:54 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:12:53 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman Subject: [PATCH v4 05/13] HID: ft260: improve i2c large reads performance Date: Sat, 5 Nov 2022 23:11:43 +0200 Message-Id: <20221105211151.7094-6-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The patch increases the read buffer size to 180 bytes. It reduces the number of ft260_i2c_read() calls by three, improving the big reads performance. $ sudo i2ctransfer -y -f 13 w2@0x51 0x0 0x0 r180 Before: [ +4.071878] ft260_i2c_write_read: off 0x0 rlen 180 wlen 2 [ +0.000005] ft260_i2c_write: rep 0xd0 addr 0x51 off 0 len 2 wlen 2 flag 0x2 d[0] 0x0 [ +0.001097] ft260_xfer_status: bus_status 0x41, clock 100 [ +0.000175] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.000004] ft260_i2c_read: rep 0xc2 addr 0x51 len 180 rlen 60 flag 0x3 [ +0.008579] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.000208] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.000001] ft260_i2c_read: rep 0xc2 addr 0x51 len 120 rlen 60 flag 0x0 [ +0.008794] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.000181] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.000002] ft260_i2c_read: rep 0xc2 addr 0x51 len 60 rlen 60 flag 0x4 [ +0.008817] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.000223] ft260_xfer_status: bus_status 0x20, clock 100 After: [ +11.611642] ft260_i2c_write_read: off 0x0 rlen 180 wlen 2 [ +0.000005] ft260_i2c_write: rep 0xd0 addr 0x51 off 0 len 2 wlen 2 flag 0x2 d[0] 0x0 [ +0.008001] ft260_xfer_status: bus_status 0x20, clock 100 [ +0.000001] ft260_i2c_read: rep 0xc2 addr 0x51 len 180 rlen 180 flag 0x7 [ +0.008994] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.007987] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.007992] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.000206] ft260_xfer_status: bus_status 0x20, clock 100 Suggested-by: Enrik Berkhan Signed-off-by: Michael Zaidman --- drivers/hid/hid-ft260.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index a354089bb747..91f9087e49dc 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -30,12 +30,19 @@ MODULE_PARM_DESC(debug, "Toggle FT260 debugging messages"); #define FT260_REPORT_MAX_LENGTH (64) #define FT260_I2C_DATA_REPORT_ID(len) (FT260_I2C_REPORT_MIN + (len - 1) / 4) + /* - * The input report format assigns 62 bytes for the data payload, but ft260 - * returns 60 and 2 in two separate transactions. To minimize transfer time - * in reading chunks mode, set the maximum read payload length to 60 bytes. - */ -#define FT260_RD_DATA_MAX (60) + * The ft260 input report format defines 62 bytes for the data payload, but + * when requested 62 bytes, the controller returns 60 and 2 in separate input + * reports. To achieve better performance with the multi-report read data + * transfers, we set the maximum read payload length to a multiple of 60. + * With a 100 kHz I2C clock, one 240 bytes read takes about 1/27 second, + * which is excessive; On the other hand, some higher layer drivers like at24 + * or optoe limit the i2c reads to 128 bytes. To not block other drivers out + * of I2C for potentially troublesome amounts of time, we select the maximum + * read payload length to be 180 bytes. +*/ +#define FT260_RD_DATA_MAX (180) #define FT260_WR_DATA_MAX (60) /* From patchwork Sat Nov 5 21:11:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 622774 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 B2A81C433FE for ; Sat, 5 Nov 2022 21:13:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230156AbiKEVNY (ORCPT ); Sat, 5 Nov 2022 17:13:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230159AbiKEVNI (ORCPT ); Sat, 5 Nov 2022 17:13:08 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 118E9120A3; Sat, 5 Nov 2022 14:13:01 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id l11so12254147edb.4; Sat, 05 Nov 2022 14:13:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l/pgm5Us2Yq+S8ZFCwq+NZ3vvwHGv8IPDUFxkuklnRI=; b=TYmJn6OByOPMmMzF8mJvwXco5uoZteGK2huxTy/qItH3gMDh+Bt+wzerZrsE5a4GyH 7jYDD2uLvB+Dou2btBswSM8FC1vVvf+14mfI91mxclDvtkVD3qWAfWQhdK0VjJtOxQSV lsO0zOCjnKaFzXKMBD1xq9LUYNJP1P57/qhcuRInsTkGbAh1IjPnP2uDd2cCo8N+aJ6A ouYDoBmJAeY+IDpHMe0RKW+CeExbKABeRaPj9EJeG+9fcBDwKuen6fXlnMKyolChOBZf 1lFT9z1BjAtclzjAR/1TbasLbsw3knrbdJAnjtYCOCozYd9GoSF1J5XM8n44nislwXUo /grQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l/pgm5Us2Yq+S8ZFCwq+NZ3vvwHGv8IPDUFxkuklnRI=; b=vO586JEFt6x/SGXiFuMT9uGDtUENiNVHFhR9gYCEDpOOb6fEZKUQ6C3F/NfARrU6UF czGWLzKCfWfn+qbLsWOWTXSCoSmQN7r/KRrCMrFbVbl8Xtt865U87Z2QnXde+nHhd+fk vdcNDLWAivuZRdN2YylbVw7cjmZmKLQyEWp5UyqGWmLL5Vdu4dRimPM8E49bhV1zADUq DxYYf1a1SZgMwu5J2QHT3wAC44y13V7TYQFp1qj4wAiz6ne5l0gfMwicxZ1FM2eu4Gou GjG0BnfKVMlRUuwy49ymCXsyNfpaFxth5g71NuEOPIGk1BkRMlYVwvtCAkoACeYeVIV4 kG0A== X-Gm-Message-State: ACrzQf0Ss9lFMtA1txYHm0YSBedn4TId+OrI7VdC9JE2L2qvTaL9I0y9 Jtn8TwTVep4EUvIMhlYQiUk= X-Google-Smtp-Source: AMsMyM5bGF6StyBpp8NpPd9/247LoutMgEcG5G5CZZUhSO4Y2W/hGMa7A01GnaI440gq5xwDPC8UzQ== X-Received: by 2002:a05:6402:1f84:b0:455:27b8:27aa with SMTP id c4-20020a0564021f8400b0045527b827aamr41594489edc.243.1667682779543; Sat, 05 Nov 2022 14:12:59 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:12:59 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman Subject: [PATCH v4 06/13] HID: ft260: do not populate /dev/hidraw device Date: Sat, 5 Nov 2022 23:11:44 +0200 Message-Id: <20221105211151.7094-7-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Do not populate the /dev/hidraw on ft260 interfaces when the hid-ft260 driver is loaded. $ sudo insmod hid-ft260.ko $ ls /dev/hidraw* /dev/hidraw0 $ sudo rmmod hid-ft260.ko $ ls /dev/hidraw* /dev/hidraw0 /dev/hidraw1 /dev/hidraw2 Reported-by: Enrik Berkhan Signed-off-by: Michael Zaidman --- drivers/hid/hid-ft260.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index 91f9087e49dc..8d6d2a19b9ed 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -939,7 +939,7 @@ static int ft260_probe(struct hid_device *hdev, const struct hid_device_id *id) return ret; } - ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); + ret = hid_hw_start(hdev, 0); if (ret) { hid_err(hdev, "failed to start HID HW\n"); return ret; @@ -966,6 +966,10 @@ static int ft260_probe(struct hid_device *hdev, const struct hid_device_id *id) if (ret <= 0) goto err_hid_close; + hid_info(hdev, "USB HID v%x.%02x Device [%s] on %s\n", + hdev->version >> 8, hdev->version & 0xff, hdev->name, + hdev->phys); + hid_set_drvdata(hdev, dev); dev->hdev = hdev; dev->adap.owner = THIS_MODULE; @@ -974,8 +978,7 @@ static int ft260_probe(struct hid_device *hdev, const struct hid_device_id *id) dev->adap.quirks = &ft260_i2c_quirks; dev->adap.dev.parent = &hdev->dev; snprintf(dev->adap.name, sizeof(dev->adap.name), - "FT260 usb-i2c bridge on hidraw%d", - ((struct hidraw *)hdev->hidraw)->minor); + "FT260 usb-i2c bridge"); mutex_init(&dev->lock); init_completion(&dev->wait); From patchwork Sat Nov 5 21:11:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 621875 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 7BBC7C433FE for ; Sat, 5 Nov 2022 21:13:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230133AbiKEVN0 (ORCPT ); Sat, 5 Nov 2022 17:13:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230135AbiKEVNK (ORCPT ); Sat, 5 Nov 2022 17:13:10 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3521811828; Sat, 5 Nov 2022 14:13:06 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id q9so21477070ejd.0; Sat, 05 Nov 2022 14:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=47oIaMFA8Eg3AOKmQgHp46WYx0yoJU5i2kodk4hvPko=; b=N91QVKYwk9ywA88EX/NPEo03LgbDWYnJqPpnaX1AiBEMXleyJK57FALGJ4JbvOdeI8 E0aR/ws0ryw9vU6yLUyqds00LvzZ5o1Zp/UcW51XN3PlKysQzh6IBDVMEV/hXppxOcfc AGp46ZXc9v90GcGm7FSKKr7N3/tmsqBI7YYRhx9umsace9YQDiSGoTLY8To7tHb30mCK bZrZamedDqEKFrj5kkqubBwbbZO7f40xjgILSi8isbDLnn3dQtl5Elv8hwBnb77mT59D ++bTDsVHTTfpYS9Puj2kkwivHZ60CTuAqn1ZITEKqNIgOHqy9HeRl3oHmtdGYiicrkZ6 Jtuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=47oIaMFA8Eg3AOKmQgHp46WYx0yoJU5i2kodk4hvPko=; b=w8Qe06/llEeeeXDH86Wx2SgF1+eUhaf5+XD0kY+QrKLS/HAbNNflbiKhQCAFRx0pNC TzQ+HE1spdQpUv0eXXsOmzeCmlshbAreulSAyFtNJ0RVJHMPHzSv4Y4C+Gi48QJhE5jA 6pMmVgtr3Lv6VNitu6z1EEXqBGg2WIQs2PDhb46nklMIX6sPnCA3d+cFaA0KsjQNQ2ON HZO7C88tgdaWEL1jj948pcdzYwBZEOepiwjY7fIGiYmGc8A3O5HVYqbgzURRu/8u2rbq s4hzcqX6pW77Tp90zdZrTDJea84OeKXhHFBSY+YSgvEgKAjeMmEBD3sj39u0LhEatLc7 hCjw== X-Gm-Message-State: ACrzQf1+NM4B3eOY34cikNgLPxlLL8epy3B/MsA37Fiai/xwlNVncWDr r/RNrmABn+3KlRP+u+BiqT4= X-Google-Smtp-Source: AMsMyM6Dwi+QxepqGR1MGBPEqdKbN8UKAmHc82B6JwRP4EZOx3pE3FyZ1GuAzQ4q/F7CMMyRNAFBgg== X-Received: by 2002:a17:906:fe46:b0:73d:939a:ec99 with SMTP id wz6-20020a170906fe4600b0073d939aec99mr41008444ejb.169.1667682784743; Sat, 05 Nov 2022 14:13:04 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.13.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:13:04 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman Subject: [PATCH v4 07/13] HID: ft260: skip unexpected HID input reports Date: Sat, 5 Nov 2022 23:11:45 +0200 Message-Id: <20221105211151.7094-8-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The FT260 is not supposed to generate unexpected HID reports. However, in theory, the unsolicited HID Input reports can be issued by a specially crafted malicious USB device masquerading as FT260 when the attacker has physical access to the USB port. In this case, the read_buf pointer points to the final data portion of the previous I2C Read transfer, and the memcpy invoked in the ft260_raw_event() will try copying the content of the unexpected report into the wrong location. This commit sets the Read buffer pointer to NULL on the I2C Read transaction completion and checks it in the ft260_raw_event() to detect and skip the unsolicited Input report. Reported-by: Enrik Berkhan Signed-off-by: Michael Zaidman --- drivers/hid/hid-ft260.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index 8d6d2a19b9ed..8b6ebc5228eb 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -464,7 +464,7 @@ static int ft260_i2c_read(struct ft260_device *dev, u8 addr, u8 *data, u16 len, u8 flag) { u16 rd_len; - int timeout, ret; + int timeout, ret = 0; struct ft260_i2c_read_request_report rep; struct hid_device *hdev = dev->hdev; @@ -480,10 +480,6 @@ static int ft260_i2c_read(struct ft260_device *dev, u8 addr, u8 *data, rd_len = FT260_RD_DATA_MAX; } - dev->read_idx = 0; - dev->read_buf = data; - dev->read_len = rd_len; - rep.report = FT260_I2C_READ_REQ; rep.length = cpu_to_le16(rd_len); rep.address = addr; @@ -494,22 +490,30 @@ static int ft260_i2c_read(struct ft260_device *dev, u8 addr, u8 *data, reinit_completion(&dev->wait); + dev->read_idx = 0; + dev->read_buf = data; + dev->read_len = rd_len; + ret = ft260_hid_output_report(hdev, (u8 *)&rep, sizeof(rep)); if (ret < 0) { hid_err(hdev, "%s: failed with %d\n", __func__, ret); - return ret; + goto ft260_i2c_read_exit; } timeout = msecs_to_jiffies(5000); if (!wait_for_completion_timeout(&dev->wait, timeout)) { + ret = -ETIMEDOUT; ft260_i2c_reset(hdev); - return -ETIMEDOUT; + goto ft260_i2c_read_exit; } + dev->read_buf = NULL; + ret = ft260_xfer_status(dev); if (ret < 0) { + ret = -EIO; ft260_i2c_reset(hdev); - return -EIO; + goto ft260_i2c_read_exit; } len -= rd_len; @@ -518,7 +522,9 @@ static int ft260_i2c_read(struct ft260_device *dev, u8 addr, u8 *data, } while (len > 0); - return 0; +ft260_i2c_read_exit: + dev->read_buf = NULL; + return ret; } /* @@ -1036,6 +1042,13 @@ static int ft260_raw_event(struct hid_device *hdev, struct hid_report *report, ft260_dbg("i2c resp: rep %#02x len %d\n", xfer->report, xfer->length); + if ((dev->read_buf == NULL) || + (xfer->length > dev->read_len - dev->read_idx)) { + hid_err(hdev, "unexpected report %#02x, length %d\n", + xfer->report, xfer->length); + return -1; + } + memcpy(&dev->read_buf[dev->read_idx], &xfer->data, xfer->length); dev->read_idx += xfer->length; @@ -1044,10 +1057,9 @@ static int ft260_raw_event(struct hid_device *hdev, struct hid_report *report, complete(&dev->wait); } else { - hid_err(hdev, "unknown report: %#02x\n", xfer->report); - return 0; + hid_err(hdev, "unhandled report %#02x\n", xfer->report); } - return 1; + return 0; } static struct hid_driver ft260_driver = { From patchwork Sat Nov 5 21:11:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 622773 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 3C9FAC4332F for ; Sat, 5 Nov 2022 21:13:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230146AbiKEVNg (ORCPT ); Sat, 5 Nov 2022 17:13:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbiKEVNM (ORCPT ); Sat, 5 Nov 2022 17:13:12 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7B1B11A3F; Sat, 5 Nov 2022 14:13:11 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id bj12so21258761ejb.13; Sat, 05 Nov 2022 14:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qGr1gPz8zB0Ciz7kPlieGQfpDM11emH9iwgNzYsPKO4=; b=iA4Y+SAEjENlYkR+CrOnrV/GxoJtAbGsibNObkGE9ELJjJ1f0x1RdIFCc9dNKGn6Zr NRmwf2S3dUuKslalJ2L8Ro/sjvq51zBkG4PguLlRDYGp0zt+NjjyOTr4q2N+kUNixcPD Bp/3OReFhNHs2T1Fe5kNE+J19XMl6h3L7rXCGztUvtvLg9mnmJuZ5gANBHl9NgbHgRTn jbYa5tyw9+qN7BpRidEllnZ/iCSNVh21IVkDIsnSJu0fBQ0642k2W+Hi26WY9PHAoXoO uDpihBN1b/T30jUI2hG2IDK6gj+oVdEGLV6q4Ep2T/EAT28mh69n9QvQSYdv1CRiuLU+ 0h3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qGr1gPz8zB0Ciz7kPlieGQfpDM11emH9iwgNzYsPKO4=; b=tM7+w3xRBLMJvHwxTms11CAtSjWTAVdbYSv4UOgyxG4aL/rs+KoG8my6mZ0oemnO0G JaO5dlsYt53AGzIQr94BY9vPy21lC9YipQB6+ncs/hypYj2AQRt7wrKRWFCtq42YpUn+ zTJNNQFXGJb1UXGW1FUIFPbhEz41y84UUmkGPKrB22goyNoEQN45RlCT1w5Kn22m14Yh Tm17EyHIiMNZjvOB8Io70paUuzOLpTjFlyjcSQEvV+ITEJ04nft5jKCHYXThwvJI2ucX D+/AKsKcLNTTdw8hMBI2ZlMHH3O754SbQfS4cyyMBKM/ItftUSbvdprPoAipef6k7HMj X2vw== X-Gm-Message-State: ACrzQf23OlD2NjIMqE0i0WSxZYzGrId+TLuyzo0Nk4C+AgCEprgWGSn1 7b/ZL6FJbVoSYqVeS8h386c= X-Google-Smtp-Source: AMsMyM6J8t83NCWCEpyie8exJ5sS+zx6COXQb+ipEo3y1OP+GwnlYwBDwwvlZFtqE74GIWEkt8gu+Q== X-Received: by 2002:a17:907:c03:b0:781:fd5a:c093 with SMTP id ga3-20020a1709070c0300b00781fd5ac093mr40841917ejc.89.1667682790314; Sat, 05 Nov 2022 14:13:10 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.13.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:13:09 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman , Vince Asbridge , Stephen Shirron Subject: [PATCH v4 08/13] HID: ft260: remove SMBus Quick command support Date: Sat, 5 Nov 2022 23:11:46 +0200 Message-Id: <20221105211151.7094-9-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The i2cdetect uses the SMBus Quick command by default to scan devices on the I2C bus. The FT260 implements an I2C bus controller. The SMBus is derived from I2C, but there are several differences between the specifications of the two buses in the areas of timing, protocols, operation modes, and electrical characteristics. One of the differences is that the I2C devices allow the slave not to ACK its slave address, but SMBus requires it to always ACK it as a mechanism to detect a detachable device’s presence on the bus. Since FT260 is the I2C bus controller, it does not acknowledge the SMBus Quick write command, which sends a single bit to the device at the place of the RD/WR bit. The ft260 driver attempted to mimic the SMBus Quick Write functionality by writing a single byte as the SMBus Byte Write command does. Usually, one byte in the SMBus Quick Write will be fine. However, it may cause problems with devices with a control register at offset 0, like i2c muxes, for example, when scanned with the i2cdetect utility. The i2cdetect with the "-r" option uses the SMBus Read Byte command, which is a reasonable workaround. To prevent the I2C bus from locking at write-only devices (most notably clock chips at address 0x69), use the "-r" option in conjunction with scanning range parameters. This patch removes the SMBus Quick command support. $ sudo i2cdetect -y 13 Warning: Can't use SMBus Quick Write command, will skip some addresses 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: 10: 20: 30: -- -- -- -- -- -- -- -- 40: 50: 50 51 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: 70: $ sudo i2cdetect -y -r 13 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: 50 51 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- Reported-by: Vince Asbridge Reported-by: Stephen Shirron Reported-by: Enrik Berkhan Signed-off-by: Michael Zaidman --- drivers/hid/hid-ft260.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index 8b6ebc5228eb..d186aa5a8e73 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -630,14 +630,6 @@ static int ft260_smbus_xfer(struct i2c_adapter *adapter, u16 addr, u16 flags, } switch (size) { - case I2C_SMBUS_QUICK: - if (read_write == I2C_SMBUS_READ) - ret = ft260_i2c_read(dev, addr, &data->byte, 0, - FT260_FLAG_START_STOP); - else - ret = ft260_smbus_write(dev, addr, cmd, NULL, 0, - FT260_FLAG_START_STOP); - break; case I2C_SMBUS_BYTE: if (read_write == I2C_SMBUS_READ) ret = ft260_i2c_read(dev, addr, &data->byte, 1, @@ -720,7 +712,7 @@ static int ft260_smbus_xfer(struct i2c_adapter *adapter, u16 addr, u16 flags, static u32 ft260_functionality(struct i2c_adapter *adap) { - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_QUICK | + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_I2C_BLOCK; } From patchwork Sat Nov 5 21:11:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 621874 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 0B052C433FE for ; Sat, 5 Nov 2022 21:13:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230174AbiKEVNx (ORCPT ); Sat, 5 Nov 2022 17:13:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230216AbiKEVNa (ORCPT ); Sat, 5 Nov 2022 17:13:30 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 357FD11819; Sat, 5 Nov 2022 14:13:27 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id x2so12257127edd.2; Sat, 05 Nov 2022 14:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yAkHqN6oZd2dovWsENCSlIqD0VO6aehIZ8ArRH69xz8=; b=Gei7ZmZQounWS45EMBl0U2TG+aaR3pZeEr3PVRDoLl4ydUUt1MatfvkhH0gb9Ue/54 3AdR6o9UWbK7wj6WNV7BHSkQJgXlLOD+7i2DFxzGrdWnOO9xxuPl/5KG0UFA/XgGcrNA jh0KZE6E6r3ETIrYuEnNxZJ3Meiyq1Mpk5GClPYLnSuMb0P3igfEvrtiVh45hiJzcF3u 6I7hM09k2PyGGUsqLSgz8YrsFTCyR3tg5BzweF6jCMQ7wmMO/oN5/Ok2WN5J8OWdI/HM uluPSm0q6o4RxQD9RrNCyJuOwBt/tKWU2yMz9F2r2itquLa0BcZ0RBnxfOS0US695M2p iZQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yAkHqN6oZd2dovWsENCSlIqD0VO6aehIZ8ArRH69xz8=; b=c4RDweOERWG+S9HgIMntcVHRn1lfuy30h/sNooiHT/274v129RYtS97+Vc5Fy1fjnE IMQbIzXuxnZrsfBjhphdbeF1u33a4Hl5edUP5xLJLRNQb07n/sMEvaNfmdEtpD36LduU NAdx0FUV+eJc531iSsWIVimTX+jClVReSFCIae7kYIQch+kbKMYdxsOd2rKcgKSKa3+b wUyS1TEV6ia3acSdU0nL9wpvaxJgyRiFGTqujbjVoOTHKO/7NTHEQRQgeYhvGTJ8KpOm IlFSzseDI3p+rBwRQMEqTU3a/Q3zamOUSzdfn7cwFMvuGnRtRzJWgjP8q4o3jAvPxLts ne+A== X-Gm-Message-State: ACrzQf0KosjLJufScUYzHEfAfoBNlEMGa8B90gq5b+RvK9pgS9M8ZyQn 1Tr42nzsewpCe7MGpVZjg7o= X-Google-Smtp-Source: AMsMyM4+odZ/gnJSto9z8Z7b4jWvwgO6SBfEpRXYz9Lf5w2TPNgbScf49zBVc3U8fZAWL2khy3Y0GA== X-Received: by 2002:a05:6402:5202:b0:461:b7e3:e6b7 with SMTP id s2-20020a056402520200b00461b7e3e6b7mr41915334edd.282.1667682805713; Sat, 05 Nov 2022 14:13:25 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:13:25 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman Subject: [PATCH v4 09/13] HID: ft260: missed NACK from big i2c read Date: Sat, 5 Nov 2022 23:11:47 +0200 Message-Id: <20221105211151.7094-10-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The FT260 controller does not return NACK when performing a big read (of multiple hid reports size) from a non-existing device or from the device responding with NACK when it is not ready to serve the request. However, it responds correctly with NACK to a read of up to a single hid report size. To overcome this issue, we split the muli-report read request into a read of a single HID report of 60 bytes size and a multi-report read. Big read of 256 bytes with first read of 60 bytes: $ sudo ./i2cperf -d 2 -o 2 -s 256 -r 0-0xff 1 0x50 -S [ +5.633280] ft260_i2c_write_read: off 0x0 rlen 255 wlen 2 [ +0.000006] ft260_i2c_write: rep 0xd0 addr 0x50 off 0 len 2 wlen 2 flag 0x2 d[0] 0x0 [ +0.013205] ft260_xfer_status: bus_status 0x20, clock 100 [ +0.000007] ft260_i2c_read: rep 0xc2 addr 0x50 len 255 rlen 60 flag 0x3 [ +0.010932] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.004733] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.000006] ft260_i2c_read: rep 0xc2 addr 0x50 len 195 rlen 128 flag 0x0 [ +0.012572] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.005789] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.003189] ft260_raw_event: i2c resp: rep 0xd1 len 8 [ +0.004092] ft260_xfer_status: bus_status 0x40, clock 100 [ +0.000010] ft260_i2c_read: rep 0xc2 addr 0x50 len 67 rlen 67 flag 0x4 [ +0.011688] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.004700] ft260_raw_event: i2c resp: rep 0xd1 len 7 [ +0.004858] ft260_xfer_status: bus_status 0x20, clock 100 Read from non-existing device at address 8. The first 60 read responded with NACK. $ sudo ./i2cperf -d 2 -o 2 -s 256 -r 0-0xff 1 0x8 -S [Oct19 15:37] ft260_i2c_write_read: off 0x0 rlen 255 wlen 2 [ +0.000007] ft260_i2c_write: rep 0xd0 addr 0x8 off 0 len 2 wlen 2 flag 0x2 d[0] 0x0 [ +0.022820] ft260_xfer_status: bus_status 0x20, clock 100 [ +0.000007] ft260_i2c_read: rep 0xc2 addr 0x8 len 255 rlen 60 flag 0x3 [ +0.010658] ft260_raw_event: i2c resp: rep 0xde len 60 [ +0.005965] ft260_xfer_status: bus_status 0x46, clock 100 <-- NACK [ +0.000009] ft260 0003:0403:6030.0004: i2c bus error: 0x46 [ +0.007784] ft260_i2c_reset: done Co-developed-by: Enrik Berkhan Signed-off-by: Enrik Berkhan Signed-off-by: Michael Zaidman --- drivers/hid/hid-ft260.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index d186aa5a8e73..40fae81386e3 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -464,6 +464,7 @@ static int ft260_i2c_read(struct ft260_device *dev, u8 addr, u8 *data, u16 len, u8 flag) { u16 rd_len; + u16 rd_data_max = 60; int timeout, ret = 0; struct ft260_i2c_read_request_report rep; struct hid_device *hdev = dev->hdev; @@ -473,12 +474,13 @@ static int ft260_i2c_read(struct ft260_device *dev, u8 addr, u8 *data, else flag = FT260_FLAG_START; do { - if (len <= FT260_RD_DATA_MAX) { + if (len <= rd_data_max) { rd_len = len; flag |= FT260_FLAG_STOP; } else { - rd_len = FT260_RD_DATA_MAX; + rd_len = rd_data_max; } + rd_data_max = FT260_RD_DATA_MAX; rep.report = FT260_I2C_READ_REQ; rep.length = cpu_to_le16(rd_len); From patchwork Sat Nov 5 21:11:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 622772 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 684A1C4332F for ; Sat, 5 Nov 2022 21:14:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230182AbiKEVNz (ORCPT ); Sat, 5 Nov 2022 17:13:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbiKEVNe (ORCPT ); Sat, 5 Nov 2022 17:13:34 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3ED911C0F; Sat, 5 Nov 2022 14:13:32 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id 21so12287306edv.3; Sat, 05 Nov 2022 14:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kVosFDdegYc2T7RE574s5zEjHMpyk85WYcARAoep7g4=; b=fyltJM5WyL6AFgNX1gBp4zc5q82ihqO5x6jGOFnI/L4ppp7hYWd9nh7m7pw/I4pp35 ZHCNiYPst96enZydrjbTnz+BnGxcvfLgcpaxm22CS5owmr5pJ4vJAHmhElojcGcuoiH6 K2XWs6NVIT09t+Bdz6eTsAE2z7NpgSVor7mlRjSBgIXh5me2IaXn38z8koQBbwaGwYi+ WbpODgb9awKgtrh5Qhh02HGbJBqc12pwKm1sPgS47kUlCGF6P9egpn2YZXlPVC++E9+9 Wi3HfbXKq+D/J7jsuSaCaKBLt9FmoOwmKuk+0Wi5CZR7f/mWeVdC2RXziVnZNesUsGkK LWkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kVosFDdegYc2T7RE574s5zEjHMpyk85WYcARAoep7g4=; b=TOmF9jBKoejjpO+YOtbzeYt75NVGgyV78JosAYCaSbN3JnihVKSHvhNFDzaIPIP5Ly R0HRLIWeATs7HvuoWu4A9+IJNlo0Qfz3gBHs7FRX2Stg5EUX2/Fe6OcqYFZ//IDrfYVd 2YGCIU2ro/mJTRnjSBA9IUMeEotWoedai5jE5lvW9qYH03Mytm5prBCI3bV6eCQUD5G7 aahnZcIsinBCle1vHwexcPkvfOA4xG1kUr5fM1/Ulyme48Hy5vsdm1bljy+4ALpTRTtE iARo1y0/FcaA+mDK36FuQ53QN6qwUT/Wz35l0K1Rc3A1tfT5agt0v9otQyL2Q+8xGGZb b9mQ== X-Gm-Message-State: ACrzQf3TXq5xPSaygYJo03jvauuNEvK/gtelFUuj4zTbGLdcp1jh/PQB yGVf5oa0SKkOnNX0+4Wc7bA= X-Google-Smtp-Source: AMsMyM53U8/5uP+6tI+gEGH84aRwbgmg1oyyqGL5fTi+NQsQK39mPVA0sqIPRkai+xWmEoHZJBDaug== X-Received: by 2002:aa7:ce92:0:b0:461:78c7:dfe2 with SMTP id y18-20020aa7ce92000000b0046178c7dfe2mr43144584edv.342.1667682811259; Sat, 05 Nov 2022 14:13:31 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:13:30 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman Subject: [PATCH v4 10/13] HID: ft260: wake up device from power saving mode Date: Sat, 5 Nov 2022 23:11:48 +0200 Message-Id: <20221105211151.7094-11-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The FT260 can enter a power saving mode after being idle for longer than 5 seconds. When being woken up from power saving mode by an I2C write request, a possible NACK is not correctly reported by the controller. As a workaround, the driver will issue an I2C status report two times in ft260_xfer_status() after the chip has been idle for more than 5s. Co-developed-by: Enrik Berkhan Signed-off-by: Enrik Berkhan Signed-off-by: Michael Zaidman --- drivers/hid/hid-ft260.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index 40fae81386e3..ac133980dfe9 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -31,6 +31,8 @@ MODULE_PARM_DESC(debug, "Toggle FT260 debugging messages"); #define FT260_REPORT_MAX_LENGTH (64) #define FT260_I2C_DATA_REPORT_ID(len) (FT260_I2C_REPORT_MIN + (len - 1) / 4) +#define FT260_WAKEUP_NEEDED_AFTER_MS (4800) /* 5s minus 200ms margin */ + /* * The ft260 input report format defines 62 bytes for the data payload, but * when requested 62 bytes, the controller returns 60 and 2 in separate input @@ -237,6 +239,7 @@ struct ft260_device { struct completion wait; struct mutex lock; u8 write_buf[FT260_REPORT_MAX_LENGTH]; + unsigned long need_wakeup_at; u8 *read_buf; u16 read_idx; u16 read_len; @@ -306,6 +309,20 @@ static int ft260_xfer_status(struct ft260_device *dev) struct ft260_get_i2c_status_report report; int ret; + if (time_is_before_jiffies(dev->need_wakeup_at)) { + ret = ft260_hid_feature_report_get(hdev, FT260_I2C_STATUS, + (u8 *)&report, sizeof(report)); + if (unlikely(ret < 0)) { + hid_err(hdev, "failed to retrieve status: %d, no wakeup\n", + ret); + } else { + dev->need_wakeup_at = jiffies + + msecs_to_jiffies(FT260_WAKEUP_NEEDED_AFTER_MS); + ft260_dbg("bus_status %#02x, wakeup\n", + report.bus_status); + } + } + ret = ft260_hid_feature_report_get(hdev, FT260_I2C_STATUS, (u8 *)&report, sizeof(report)); if (unlikely(ret < 0)) { From patchwork Sat Nov 5 21:11:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 621872 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 01B0EC4167B for ; Sat, 5 Nov 2022 21:14:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230115AbiKEVOS (ORCPT ); Sat, 5 Nov 2022 17:14:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230208AbiKEVNs (ORCPT ); Sat, 5 Nov 2022 17:13:48 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04D1B1408C; Sat, 5 Nov 2022 14:13:43 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id b2so21347788eja.6; Sat, 05 Nov 2022 14:13:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LiMUaNhBUJOR9OA8ZtBEVhMz3WyIU1kHl60F6lstO3A=; b=H8kCc5kNdiDaLwfV1szOsGC3FQvFMahJRrhpAgTYfawIDxtKT+Xp8X8ToVoz3iouul q8Ojdb5ihW44WlIpYghJ8qKS2JT56hkBcBrKUHRUj/+jdqxzPp19jj9uJ0IGMjCVYRdV syjVZD2dH4UlAHF0SwuBJ4mzggx8/W5ab5Ht+PXqyy6SRiT1kpEWRe9nTwSanzOTgxhK 5tGmUSApfw2l8WIm0VoJoxib7NY7/R+mIzIka3YXX7xF/eUCsLywnyego0qC5OEftt1l vfLVfjjFrJlITzfVIMitnJm5/SJeiorgI2Ih0OuunsYZAlgV5+Ed0XauXRQeK3l+tm6r RErQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LiMUaNhBUJOR9OA8ZtBEVhMz3WyIU1kHl60F6lstO3A=; b=8C4igtjOtQXqWz1A+l3YWyXphrai7GYTwzq1MhiquFFRsEnxuTS7gS2eEpvwNa+8xV Rpt9QYmCXGMkFLHSjAHeHkYTYYTBtveYIq7/01PvX7PmvG58vh1i+eH9fNjwqPXRe6Po fye05EXJYz2RakHd78aq3/5Enx3nGUWSrtUqUQszp6IfuC8HhZQi4darPoYbFSxMS/qp 8M7xGf+XFlmSjMPLbhNfkUZAoQckEOHBFh9tvaDUQmyMOA3oCVPKYTWmOxGW8OSNV7SY pRTFQpT6jrPfJB4CT1xhGoKcHYiIh0cfbypeCFFWTCXLRMDE8bw2gIoePjNqHCCesiHL TWGw== X-Gm-Message-State: ACrzQf2Xgn3mygNQir76pyWgXnrXAZyqTm1Uy4ZcYhxA/E1hwfhuOmH+ iw743D3KMIAsXOwVY/4TKoM= X-Google-Smtp-Source: AMsMyM69yMUlPdhKEZ6i72kZbwHaYLHE1s+ekv6urYeBcIDN6iBabY25Cammr8rJFVnO69ZY4zbZ4w== X-Received: by 2002:a17:906:8a6c:b0:7a8:2f09:d88d with SMTP id hy12-20020a1709068a6c00b007a82f09d88dmr40191568ejc.49.1667682821568; Sat, 05 Nov 2022 14:13:41 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:13:41 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman Subject: [PATCH v4 11/13] HID: ft260: fix a NULL pointer dereference in ft260_i2c_write Date: Sat, 5 Nov 2022 23:11:49 +0200 Message-Id: <20221105211151.7094-12-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The zero-length passed into the ft260_i2c_write() triggered the NULL pointer dereference in the debug message on data[0] access. Since the controller does not support a write of zero length, let's not allow it. Before: $ sudo i2ctransfer -y 13 w0@0x51 Killed After: $ sudo i2ctransfer -y 13 w0@0x51 Error: Sending messages failed: Invalid argument Reported-by: Enrik Berkhan Signed-off-by: Michael Zaidman --- drivers/hid/hid-ft260.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index ac133980dfe9..b4f180c8750a 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -409,6 +409,9 @@ static int ft260_i2c_write(struct ft260_device *dev, u8 addr, u8 *data, struct ft260_i2c_write_request_report *rep = (struct ft260_i2c_write_request_report *)dev->write_buf; + if (len < 1) + return -EINVAL; + rep->flag = FT260_FLAG_START; do { From patchwork Sat Nov 5 21:11:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 621873 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 07453C43219 for ; Sat, 5 Nov 2022 21:14:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230245AbiKEVOL (ORCPT ); Sat, 5 Nov 2022 17:14:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230167AbiKEVNv (ORCPT ); Sat, 5 Nov 2022 17:13:51 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F7521013; Sat, 5 Nov 2022 14:13:48 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id ud5so21384023ejc.4; Sat, 05 Nov 2022 14:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RAH3kEkujeyAnJuII7Acg6ukzobTIRImw/F1DL0pg+A=; b=peYNN+X0rLVhiD6h2RacNrBcfFZKmdOwvM+SlIAqr/aJQdetlAygIYyIcAAto6KIgt uBgx+WYcUXmv/6V7Iy2kxQ+FOqsYz8++lO2F6MxoCGvP6WtDanbzHasfdlRSFh1yE0LS TVbU2LzzAPL482t2VU6G+OGDWlljex5SlIs6uryv9eM6LKO3/W4eDmIIKy4OX7WAab4n e6fgYI4EOzRLKkOqbWbTAoYTqeRxVsZ16Ldvq6+zYJWL4mpHK/6SJAuSUWNKe+6CFPeP beNHqZfTjWSCHdRsW84WWJUnflCM1RkDORUDk2eh/A4pDB9jMvOKxfTd8IHYw7HUIK5z Kwxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RAH3kEkujeyAnJuII7Acg6ukzobTIRImw/F1DL0pg+A=; b=noVnv8iuMtN+smopby7vlTJfwztn1PBhqITNkkkXXogKFtmoj1mADEtett3IrN8Z0z ORFDgTNEs20NWHtJ0szUH2cm60qqxXpXN3fjyJTFv5KnldTn96zzmVffWE+QWyZRRvlB TeeuT18/DqfKQ8Z1OnVZXcrMYz6sF2m0v3sNW3VzQ9Otg3VfeKh2c1M4L5iUnE3F+5y8 yGSWTpjvwRRiLnQql6NUhqLjLnfhRrw4GsmDl/A1rE/W56i9mlKimhrtm0JLtRaL5QVc NaxRnrpBAh53yjnTUr/ZcLycgFG0VIcmgHXB507mxlTSxLbBUIqdMs1UmophQb3FmTMW iMhg== X-Gm-Message-State: ACrzQf3+s7fBcVE9tpSvDSgPHwzwFth9g+BRvOFxrR4xYgDjEKRY8NKi sc/q53bpKYL6Lu7q9pCb0x8= X-Google-Smtp-Source: AMsMyM4eqQ9WUMAOtK9vxdkojfHWbOPxZie4/zY7pbmZJIdNYBbXdCi/s6z1gOYhfuQ0O4sfR3tNRg== X-Received: by 2002:a17:907:86a1:b0:7ac:c5c3:9c80 with SMTP id qa33-20020a17090786a100b007acc5c39c80mr41727981ejc.37.1667682826856; Sat, 05 Nov 2022 14:13:46 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:13:46 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman , Germain Hebert Subject: [PATCH v4 12/13] HID: ft260: missed NACK from busy device Date: Sat, 5 Nov 2022 23:11:50 +0200 Message-Id: <20221105211151.7094-13-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org When writing into a slow device like an EEPROM chip, the controller may exit the busy state before the device releases the bus. In this case, the ft260_xfer_status returns success before the data transfer completion. The patch fixes it by returning from the ft260_xfer_status() with the "-EAGAIN" on both controller and bus busy status when appropriate. It does not apply to the i2c combined transactions when after the write IO, the controller keeps the bus busy until the read IO and then between reading IOs to ensure an atomic operation. Co-developed-by: Germain Hebert Signed-off-by: Germain Hebert Signed-off-by: Michael Zaidman --- drivers/hid/hid-ft260.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index b4f180c8750a..d5b092b85d7f 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -303,7 +303,7 @@ static int ft260_i2c_reset(struct hid_device *hdev) return ret; } -static int ft260_xfer_status(struct ft260_device *dev) +static int ft260_xfer_status(struct ft260_device *dev, u8 bus_busy) { struct hid_device *hdev = dev->hdev; struct ft260_get_i2c_status_report report; @@ -334,7 +334,7 @@ static int ft260_xfer_status(struct ft260_device *dev) ft260_dbg("bus_status %#02x, clock %u\n", report.bus_status, dev->clock); - if (report.bus_status & FT260_I2C_STATUS_CTRL_BUSY) + if (report.bus_status & (FT260_I2C_STATUS_CTRL_BUSY | bus_busy)) return -EAGAIN; /* @@ -369,8 +369,11 @@ static int ft260_hid_output_report(struct hid_device *hdev, u8 *data, static int ft260_hid_output_report_check_status(struct ft260_device *dev, u8 *data, int len) { + u8 bus_busy; int ret, usec, try = 100; struct hid_device *hdev = dev->hdev; + struct ft260_i2c_write_request_report *rep = + (struct ft260_i2c_write_request_report *)data; ret = ft260_hid_output_report(hdev, data, len); if (ret < 0) { @@ -388,8 +391,18 @@ static int ft260_hid_output_report_check_status(struct ft260_device *dev, ft260_dbg("wait %d usec, len %d\n", usec, len); } + /* + * Do not check the busy bit for combined transactions + * since the controller keeps the bus busy between writing + * and reading IOs to ensure an atomic operation. + */ + if (rep->flag == FT260_FLAG_START) + bus_busy = 0; + else + bus_busy = FT260_I2C_STATUS_BUS_BUSY; + do { - ret = ft260_xfer_status(dev); + ret = ft260_xfer_status(dev, bus_busy); if (ret != -EAGAIN) break; } while (--try); @@ -488,6 +501,7 @@ static int ft260_i2c_read(struct ft260_device *dev, u8 addr, u8 *data, int timeout, ret = 0; struct ft260_i2c_read_request_report rep; struct hid_device *hdev = dev->hdev; + u8 bus_busy = 0; if ((flag & FT260_FLAG_START_REPEATED) == FT260_FLAG_START_REPEATED) flag = FT260_FLAG_START_REPEATED; @@ -531,7 +545,10 @@ static int ft260_i2c_read(struct ft260_device *dev, u8 addr, u8 *data, dev->read_buf = NULL; - ret = ft260_xfer_status(dev); + if (flag & FT260_FLAG_STOP) + bus_busy = FT260_I2C_STATUS_BUS_BUSY; + + ret = ft260_xfer_status(dev, bus_busy); if (ret < 0) { ret = -EIO; ft260_i2c_reset(hdev); @@ -1003,7 +1020,7 @@ static int ft260_probe(struct hid_device *hdev, const struct hid_device_id *id) mutex_init(&dev->lock); init_completion(&dev->wait); - ret = ft260_xfer_status(dev); + ret = ft260_xfer_status(dev, FT260_I2C_STATUS_BUS_BUSY); if (ret) ft260_i2c_reset(hdev); From patchwork Sat Nov 5 21:11:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zaidman X-Patchwork-Id: 622771 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 7353DC4167B for ; Sat, 5 Nov 2022 21:14:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230162AbiKEVOP (ORCPT ); Sat, 5 Nov 2022 17:14:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230193AbiKEVN4 (ORCPT ); Sat, 5 Nov 2022 17:13:56 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1292A11812; Sat, 5 Nov 2022 14:13:55 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id v17so12242450edc.8; Sat, 05 Nov 2022 14:13:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JQsmdApmFfLSOhvFZKZk9s/wKfo/oplrqMZ6WuKFAxM=; b=qHV+i9ppycFF19PrlgqXEzYpHXjowxqFainZsFDues9Piz5mGJ5/JluCulEB4UnPLf a5hpPxochXoCZhpyJ3Y+Jp6QxJ30nxAa8Ff4HuE9yG0TxxtTXOYpd0toNTfxY/ZTzICM CX8YkCpwUUmETtgkqAKYvQzaGlAOA2Spp42GyvQPE+wPBUIqOTdu3ZGrHaBB7W6jXOVD 7WOGs1BNuYSGAQ7gmz8nKomHFPHbQwf6iLXpxl0QbBzuAhx87PL4PdRzz/2eMty2s3fx P6pdCgvx58owxpVebpLboJ8UhFsrR5aNPKPVkFcCCvOGXwzwG7KFpsP14N2lJEulxn2g dOpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JQsmdApmFfLSOhvFZKZk9s/wKfo/oplrqMZ6WuKFAxM=; b=bi4xlFDbWzUwKlZBI3PIqeij6hZlPzw9xz3elkwjqtwT18DqKNRl05CvRY50/y++RN OyxIAxKlc//fXX7DglDI3YbJHNal6OVsm2ZdK1v2W0Y+ou85b+sB7I0oAo2CBX55kD99 ZLOS0PiQXuixwSEwAfVGk6UsPm/eHPEisB12VGNbYwcQBce6GkpEfMZlabAPiaGgu5P6 SgXSbBpjE0vaTmyxFCznxhKhQpNwZDnHebQPpkduDqsHpR6HmP7Bi7oKsIo6zcygZbqo G3xFijH0Da8mTSXLLOkE1jSdubaqXi1eL19NEts4HqVB4SSLfMW9HszjC3a6lT0CqDXP 3v2g== X-Gm-Message-State: ACrzQf3EPdJdiv4JvV7t4PmfdAic7rjvfz1uYkWgcc9Yam0WtnmpJkVq 9cJdCtgzIj2jJaltRAn3CKc= X-Google-Smtp-Source: AMsMyM4eXv50yEdjZrMsJ80HF6rYXQVEiu55y1+8Uv9nafkP3gIdol/r7Rc7zflN7yEE71WP5T6KlQ== X-Received: by 2002:a05:6402:174f:b0:463:12ed:3f8f with SMTP id v15-20020a056402174f00b0046312ed3f8fmr40338429edx.67.1667682833558; Sat, 05 Nov 2022 14:13:53 -0700 (PDT) Received: from michael-VirtualBox.. (89-138-220-136.bb.netvision.net.il. [89.138.220.136]) by smtp.googlemail.com with ESMTPSA id ta19-20020a1709078c1300b0073d796a1043sm1323502ejc.123.2022.11.05.14.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 14:13:53 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, Enrik.Berkhan@inka.de, Michael Zaidman , kernel test robot Subject: [PATCH v4 13/13] HID: ft260: fix 'cast to restricted' kernel CI bot warnings Date: Sat, 5 Nov 2022 23:11:51 +0200 Message-Id: <20221105211151.7094-14-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com> References: <20221105211151.7094-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Fix 'cast to restricted' sparse warnings reported by kernel test robot in https://lore.kernel.org/all/202211021607.ssjymlKi-lkp@intel.com/ Reported-by: kernel test robot Signed-off-by: Michael Zaidman --- drivers/hid/hid-ft260.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index d5b092b85d7f..333341e80b0e 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -588,7 +588,7 @@ static int ft260_i2c_write_read(struct ft260_device *dev, struct i2c_msg *msgs) if (ft260_debug) { if (wr_len == 2) - read_off = be16_to_cpu(*(u16 *)msgs[0].buf); + read_off = be16_to_cpu(*(__be16 *)msgs[0].buf); else read_off = *msgs[0].buf; @@ -830,7 +830,7 @@ static int ft260_byte_show(struct hid_device *hdev, int id, u8 *cfg, int len, } static int ft260_word_show(struct hid_device *hdev, int id, u8 *cfg, int len, - u16 *field, u8 *buf) + __le16 *field, u8 *buf) { int ret; @@ -859,9 +859,9 @@ static int ft260_word_show(struct hid_device *hdev, int id, u8 *cfg, int len, #define FT260_I2CST_ATTR_SHOW(name) \ FT260_ATTR_SHOW(name, ft260_get_i2c_status_report, \ - FT260_I2C_STATUS, u16, ft260_word_show) + FT260_I2C_STATUS, __le16, ft260_word_show) -#define FT260_ATTR_STORE(name, reptype, id, req, type, func) \ +#define FT260_ATTR_STORE(name, reptype, id, req, type, ctype, func) \ static ssize_t name##_store(struct device *kdev, \ struct device_attribute *attr, \ const char *buf, size_t count) \ @@ -871,7 +871,7 @@ static int ft260_word_show(struct hid_device *hdev, int id, u8 *cfg, int len, type name; \ int ret; \ \ - if (!func(buf, 10, &name)) { \ + if (!func(buf, 10, (ctype *)&name)) { \ rep.name = name; \ rep.report = id; \ rep.request = req; \ @@ -887,11 +887,11 @@ static int ft260_word_show(struct hid_device *hdev, int id, u8 *cfg, int len, #define FT260_BYTE_ATTR_STORE(name, reptype, req) \ FT260_ATTR_STORE(name, reptype, FT260_SYSTEM_SETTINGS, req, \ - u8, kstrtou8) + u8, u8, kstrtou8) #define FT260_WORD_ATTR_STORE(name, reptype, req) \ FT260_ATTR_STORE(name, reptype, FT260_SYSTEM_SETTINGS, req, \ - u16, kstrtou16) + __le16, u16, kstrtou16) FT260_SSTAT_ATTR_SHOW(chip_mode); static DEVICE_ATTR_RO(chip_mode);