Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2496274pxj; Mon, 10 May 2021 04:31:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZmBdTXzOvFxbG1bH/vEvB9xwCfEMAZWRRzJ3mTKYEm3FfsqxdbVPx/qpeC5A4Nx7/n3dC X-Received: by 2002:a50:ce5c:: with SMTP id k28mr28304813edj.84.1620646269135; Mon, 10 May 2021 04:31:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620646269; cv=none; d=google.com; s=arc-20160816; b=nhh/1mIKKeYA6e6G9Opfde0jZc2F2+71U+bD2yNogwWasjZv9h6qsoXoicShIax+e4 opWy7loL00bT59llAGlPF6PEFsD5QJeH1sRVFxpepBKtH0ZVze3AeMjhXx1nbn8oc4Y+ 944zyRRuDSwOXxb0bHh6rL9gfOfZDJK0XH/iPuIVEf1lr0mAvjfMqCnADVfKRU1dgzqE lPr0Bp9bdC+hnsVPMqeUJjYa9IJ0LOauyj8b7uAKSR/kqVWFhorHabLfmpPpNiai7aso tS2gE0FFnUkSlWGu2dqEcOprx1tzGy49hlUu3FxH8rf57gzTr7+0VTF7Blz9Ypv66I7k 2g6Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=g+/4rEFgGKKYQt5GluRJDuTHm5IjTUvwWw1wLqBPfFE=; b=wDhXL7rwdSRRyKM/fbP70J3NnKRIoB3Qgr0zW4sW2gBPQVUHuhq6NXcdGE2/XVNeJF cuI4zx++/aMfcgVwHMBqD7Lv1LE4xu+wKzMs/K+9QCJGOhKrRf45LNdbtYKrehigOqTI sT4KGq/8pyUw4boTPqJeuP5dXVkTDEoUVyp8Dwc2rMxKqxYDJ5WGCXyDVvzqg2NaJK6N REVPYBMxmsyflSBbmsFn3Y5QbGbH8kVWBpLxkyTj4ifhpAtyEk2cYdRgMYnsSZErQFhp Boe3zfbGLJPeyEllWAYnWGMGvoZoYFyeLmJnra795BKoR+nkbVsGPTGUeXZvsLm3XT6r qDXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HIDaTZab; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u20si7512350edv.439.2021.05.10.04.30.45; Mon, 10 May 2021 04:31:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HIDaTZab; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239977AbhEJL2I (ORCPT + 99 others); Mon, 10 May 2021 07:28:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:52714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234624AbhEJK4n (ORCPT ); Mon, 10 May 2021 06:56:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6AA9C6193A; Mon, 10 May 2021 10:47:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643654; bh=TgVC4UPVRHZNBIu5csNjWVaW5ddsvCz1lELdgxWi99I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HIDaTZab3czQnHJX6xmIq/Nd8muNi3dHW4V64dEqxDYy7Vjm5BQDwsN5n28vXRkKb dWzx88pw7Q6BtxX7oEdGrwYv8orFZZystNH+VqDgK4TwYHnX3DOCd6rnzHENxOpSSh 5eQ0HVgAeqLZuE5FMpkNxe6g5bxY0zK+Mv5KjEWs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Srinivas Pandruvada , Hans de Goede , Sasha Levin Subject: [PATCH 5.11 104/342] platform/x86: ISST: Account for increased timeout in some cases Date: Mon, 10 May 2021 12:18:14 +0200 Message-Id: <20210510102013.537269794@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102010.096403571@linuxfoundation.org> References: <20210510102010.096403571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Srinivas Pandruvada [ Upstream commit 5c782817a981981917ec3c647cf521022ee07143 ] In some cases when firmware is busy or updating, some mailbox commands still timeout on some newer CPUs. To fix this issue, change how we process timeout. With this change, replaced timeout from using simple count with real timeout in micro-seconds using ktime. When the command response takes more than average processing time, yield to other tasks. The worst case timeout is extended upto 1 milli-second. Signed-off-by: Srinivas Pandruvada Link: https://lore.kernel.org/r/20210330220840.3113959-1-srinivas.pandruvada@linux.intel.com Signed-off-by: Hans de Goede Signed-off-by: Sasha Levin --- .../intel_speed_select_if/isst_if_mbox_pci.c | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/platform/x86/intel_speed_select_if/isst_if_mbox_pci.c b/drivers/platform/x86/intel_speed_select_if/isst_if_mbox_pci.c index a2a2d923e60c..df1fc6c719f3 100644 --- a/drivers/platform/x86/intel_speed_select_if/isst_if_mbox_pci.c +++ b/drivers/platform/x86/intel_speed_select_if/isst_if_mbox_pci.c @@ -21,12 +21,16 @@ #define PUNIT_MAILBOX_BUSY_BIT 31 /* - * The average time to complete some commands is about 40us. The current - * count is enough to satisfy 40us. But when the firmware is very busy, this - * causes timeout occasionally. So increase to deal with some worst case - * scenarios. Most of the command still complete in few us. + * The average time to complete mailbox commands is less than 40us. Most of + * the commands complete in few micro seconds. But the same firmware handles + * requests from all power management features. + * We can create a scenario where we flood the firmware with requests then + * the mailbox response can be delayed for 100s of micro seconds. So define + * two timeouts. One for average case and one for long. + * If the firmware is taking more than average, just call cond_resched(). */ -#define OS_MAILBOX_RETRY_COUNT 100 +#define OS_MAILBOX_TIMEOUT_AVG_US 40 +#define OS_MAILBOX_TIMEOUT_MAX_US 1000 struct isst_if_device { struct mutex mutex; @@ -35,11 +39,13 @@ struct isst_if_device { static int isst_if_mbox_cmd(struct pci_dev *pdev, struct isst_if_mbox_cmd *mbox_cmd) { - u32 retries, data; + s64 tm_delta = 0; + ktime_t tm; + u32 data; int ret; /* Poll for rb bit == 0 */ - retries = OS_MAILBOX_RETRY_COUNT; + tm = ktime_get(); do { ret = pci_read_config_dword(pdev, PUNIT_MAILBOX_INTERFACE, &data); @@ -48,11 +54,14 @@ static int isst_if_mbox_cmd(struct pci_dev *pdev, if (data & BIT_ULL(PUNIT_MAILBOX_BUSY_BIT)) { ret = -EBUSY; + tm_delta = ktime_us_delta(ktime_get(), tm); + if (tm_delta > OS_MAILBOX_TIMEOUT_AVG_US) + cond_resched(); continue; } ret = 0; break; - } while (--retries); + } while (tm_delta < OS_MAILBOX_TIMEOUT_MAX_US); if (ret) return ret; @@ -74,7 +83,8 @@ static int isst_if_mbox_cmd(struct pci_dev *pdev, return ret; /* Poll for rb bit == 0 */ - retries = OS_MAILBOX_RETRY_COUNT; + tm_delta = 0; + tm = ktime_get(); do { ret = pci_read_config_dword(pdev, PUNIT_MAILBOX_INTERFACE, &data); @@ -83,6 +93,9 @@ static int isst_if_mbox_cmd(struct pci_dev *pdev, if (data & BIT_ULL(PUNIT_MAILBOX_BUSY_BIT)) { ret = -EBUSY; + tm_delta = ktime_us_delta(ktime_get(), tm); + if (tm_delta > OS_MAILBOX_TIMEOUT_AVG_US) + cond_resched(); continue; } @@ -96,7 +109,7 @@ static int isst_if_mbox_cmd(struct pci_dev *pdev, mbox_cmd->resp_data = data; ret = 0; break; - } while (--retries); + } while (tm_delta < OS_MAILBOX_TIMEOUT_MAX_US); return ret; } -- 2.30.2