From patchwork Thu Feb 9 15:49:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastien Nocera X-Patchwork-Id: 55026 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp420883wrn; Thu, 9 Feb 2023 08:05:49 -0800 (PST) X-Google-Smtp-Source: AK7set+73rFsC1wdRnPL2WO6Zjpuw3CqNVkEZ8rTNSJEY8bTHaCAvc9I0NZSfcyZ0I9J5aRU4EfN X-Received: by 2002:a05:6a20:1a82:b0:bf:8a97:6e48 with SMTP id ci2-20020a056a201a8200b000bf8a976e48mr9603734pzb.37.1675958748743; Thu, 09 Feb 2023 08:05:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675958748; cv=none; d=google.com; s=arc-20160816; b=KmJIfZnbnHRcu4iqRCM8PSfyWlcCDmXED2FY4Hd/xfkPKarIX/vBW9BtLrHokkifRC DZg1qq5g6Vx48yMO8+xllVFW2M2J92lgEaluckjfMVUT41eeOcWl+lBglRcVqZd5cs9r ONS7wTdjEnj+1dzA9RP/eFqGQUadwksjsXhaqBKb4xbG7/f22CCQ8XEVsaObMZ1oSzPm eKoA6TSyFNlCTWuwXwlDerBNeFK6999QzzneyxJEAA/y+r7bzIVvBczAES2xiuplmnhz GJd2tk5JD93LJngYNze0vmo/MqP0jAOhOyzsaj3M7t7+d3eGRuRr7c8BJELUFanJmHNg 0L2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=+DJUQQ8sA6GgsxDsJ2jBw/02M69PE0TjngcVjM23tbQ=; b=DQ17Q9i1DDu4l5VnN0uPxT0ZMoIZBtHRb9SxwFt6gnbuSX6qyrk0PwGmRbYQajROBf NzL+2ZxCqfzdAwI3Us9Y1+aIvUYfCGJxysFtohCNlW7Liiwa50uzC3D5tD1GnlmFXIok NuwSTaxK91vdJzH1wMJW7EKD3m0ZpFs/023W/xJZdddznDVXyL8HLsts6rCHkQQVKfvk y5KV9lxEyt9pyTV/bbj8UTy/1wC1LxZ56j7kCY2tu9Tm++rXFvkK5JdMYnk1+n5KXfMV hYk+iG+fYbE4beyMj6LOOoyAa31FAVK+/8n3sOPM9xejIFZ/KvTwFGeqh85TjXh/lInb p+2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l186-20020a6388c3000000b004fb11689cfbsi2170379pgd.546.2023.02.09.08.05.36; Thu, 09 Feb 2023 08:05:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231538AbjBIPtt (ORCPT + 99 others); Thu, 9 Feb 2023 10:49:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231327AbjBIPtk (ORCPT ); Thu, 9 Feb 2023 10:49:40 -0500 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C9F42887C; Thu, 9 Feb 2023 07:49:26 -0800 (PST) Received: (Authenticated sender: hadess@hadess.net) by mail.gandi.net (Postfix) with ESMTPSA id 86D76240005; Thu, 9 Feb 2023 15:49:21 +0000 (UTC) From: Bastien Nocera To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , "Peter F . Patel-Schneider" , =?utf-8?q?Filipe_La?= =?utf-8?q?=C3=ADns?= , Nestor Lopez Casado Subject: [PATCH v3 1/2] HID: logitech-hidpp: Retry commands when device is busy Date: Thu, 9 Feb 2023 16:49:15 +0100 Message-Id: <20230209154916.462158-1-hadess@hadess.net> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757370121082464511?= X-GMAIL-MSGID: =?utf-8?q?1757370121082464511?= Handle the busy error coming from the device or receiver. The documentation says a busy error can be returned when: " Device (or receiver) cannot answer immediately to this request for any reason i.e: - already processing a request from the same or another SW - pipe full " Signed-off-by: Bastien Nocera --- Use a bounded for loop instead of a goto, to avoid infinite loops. drivers/hid/hid-logitech-hidpp.c | 54 ++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 1952d8d3b6b2..ff427d7a0fa0 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -283,6 +283,7 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp, struct hidpp_report *response) { int ret; + int max_retries = 3; mutex_lock(&hidpp->send_mutex); @@ -295,34 +296,39 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp, */ *response = *message; - ret = __hidpp_send_report(hidpp->hid_dev, message); + for (; max_retries != 0; max_retries--) { + ret = __hidpp_send_report(hidpp->hid_dev, message); - if (ret) { - dbg_hid("__hidpp_send_report returned err: %d\n", ret); - memset(response, 0, sizeof(struct hidpp_report)); - goto exit; - } + if (ret) { + dbg_hid("__hidpp_send_report returned err: %d\n", ret); + memset(response, 0, sizeof(struct hidpp_report)); + goto exit; + } - if (!wait_event_timeout(hidpp->wait, hidpp->answer_available, - 5*HZ)) { - dbg_hid("%s:timeout waiting for response\n", __func__); - memset(response, 0, sizeof(struct hidpp_report)); - ret = -ETIMEDOUT; - } + if (!wait_event_timeout(hidpp->wait, hidpp->answer_available, + 5*HZ)) { + dbg_hid("%s:timeout waiting for response\n", __func__); + memset(response, 0, sizeof(struct hidpp_report)); + ret = -ETIMEDOUT; + } - if (response->report_id == REPORT_ID_HIDPP_SHORT && - response->rap.sub_id == HIDPP_ERROR) { - ret = response->rap.params[1]; - dbg_hid("%s:got hidpp error %02X\n", __func__, ret); - goto exit; - } + if (response->report_id == REPORT_ID_HIDPP_SHORT && + response->rap.sub_id == HIDPP_ERROR) { + ret = response->rap.params[1]; + dbg_hid("%s:got hidpp error %02X\n", __func__, ret); + goto exit; + } - if ((response->report_id == REPORT_ID_HIDPP_LONG || - response->report_id == REPORT_ID_HIDPP_VERY_LONG) && - response->fap.feature_index == HIDPP20_ERROR) { - ret = response->fap.params[1]; - dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret); - goto exit; + if ((response->report_id == REPORT_ID_HIDPP_LONG || + response->report_id == REPORT_ID_HIDPP_VERY_LONG) && + response->fap.feature_index == HIDPP20_ERROR) { + ret = response->fap.params[1]; + if (ret != HIDPP20_ERROR_BUSY) { + dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret); + goto exit; + } + dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__, ret); + } } exit: