Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5459136pxu; Tue, 22 Dec 2020 18:42:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJztUVlWCwLWcQ4SukPuVImfkmjw1qWalnvG/UIu8r+1h8yg8BZvNN99JXDay5cKgFYUwR3Z X-Received: by 2002:a17:906:2984:: with SMTP id x4mr22457199eje.239.1608691377498; Tue, 22 Dec 2020 18:42:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608691377; cv=none; d=google.com; s=arc-20160816; b=k2LMfoSKcM2TSZFwmVfep2SpLnsGuT6AftiMc3GU6WCmTYOeEEqQumL8C7LMnUD0q7 A4N1VfIzXI5CqhwE/OOLk2npDUev13dSrTagxLkiu+lYBTleDHox9jrtcJmOMVJCu5+/ zcAZ0obLz26GSqMnmd1s4RClkld+rhWUql39F7jlASZVxXUZ/rF3y44AUNb61xD+zqs9 iw+uOQsBL3FMItmZqHyspabSyN0KGsPN9u1XrLvcWisV0N87At90Jsx2JPUndrpuY7mC 7CK7xsYF26ogPP25mL6VXEdNFgIv/kq2B4R3lzrHcXK2ge97KjJAXFWiEi1oO/ql/GfG JjeA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/bFZN2bCxxz87clTIdNFR3IDLCMaEpDhMIuI/50R+JM=; b=tVy6mGhbej6mWdQKEImFLvGN2+2xKLvjzvkUKE+B4NHNIbd4PqRZRKgkVK9bKKyv61 yQUWL5lvFtx1qOZVgnh1/owutFUzLi+0zRi/b+Tb4x49WElYSus+JJwAyb7VM8yRJRo6 7bWx10fQt3XGPMaJ4Mng9C7i03oSbOqjoq3Waj7Z8G9f/Q4L4I6y8JkHbD210vjvcvE5 InQox4dxU1Yc7n2E4HC2ZL3ug5bVE9BuL2lN6dp6c0eMMpu2GCyRK+MX6kCApq6OIMwn glUAWKqcu9ha+BAkrc5BtA0EX6p206OpZns+8v2bt95ccOJXKgGVRhwhecaCgS+g44RN 6JsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=clJITbCB; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ne6si13021509ejb.6.2020.12.22.18.42.35; Tue, 22 Dec 2020 18:42:57 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=clJITbCB; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730047AbgLWClu (ORCPT + 99 others); Tue, 22 Dec 2020 21:41:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:52452 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729958AbgLWCXU (ORCPT ); Tue, 22 Dec 2020 21:23:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 06412229C5; Wed, 23 Dec 2020 02:22:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608690180; bh=Wa3DOgXCw4joMzbcnvPmB1yM8gF9Zj4VxFT+kaS3pMA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=clJITbCB2p0eBQGJdxNb9wrjGU9RhpPNk6NEYfbOWEdi/iUSTXwuIzj82RBozH0bR 99vtLArHuGSEu+AxL4K8k18f4iY2MbCETANlnolmD5XhyWmH8UdKf0DFEqCBk9/6gk 7EBdwjeNVr0sdNMIlqoLEd0t0etdjvjtdXqbOq6tPlQSnbGYuN/in96JS6CW1zF5qs Rx9Pg/GTbsfI6N13SymCJnWO9UY+7HvvZIWf6yM2+2a+w0Gib7wB3EsQvx1QDlo/iv qDQ1/Nl/5jmh8xwutRaROJoH+42p77a9ue9+r4QN6QvDAFBdTsoonthN6pGDaezXfx bZOuMAUatJa3A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: akshatzen , Jack Wang , Viswas G , Ruksar Devadi , Radha Ramachandran , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 05/66] scsi: pm80xx: Avoid busywait in FW ready check Date: Tue, 22 Dec 2020 21:21:51 -0500 Message-Id: <20201223022253.2793452-5-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201223022253.2793452-1-sashal@kernel.org> References: <20201223022253.2793452-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: akshatzen [ Upstream commit 48cd6b38eb4f2874f091c4776ea1c26e7e4f967e ] In function check_fw_ready() we busy wait using udelay. The CPU is not released and we see need_resched failures. Busy waiting is not necessary since we are in process context and we can sleep instead. Replace udelay with msleep of 20 ms intervals while waiting for firmware to become ready. It has been verified that check_fw_ready is not being used in interrupt context anywhere, hence it is safe to make this change. Link: https://lore.kernel.org/r/20201102165528.26510-4-Viswas.G@microchip.com.com Acked-by: Jack Wang Signed-off-by: akshatzen Signed-off-by: Viswas G Signed-off-by: Ruksar Devadi Signed-off-by: Radha Ramachandran Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/pm8001/pm80xx_hwi.c | 21 +++++++++++---------- drivers/scsi/pm8001/pm80xx_hwi.h | 6 ++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/pm8001/pm80xx_hwi.c b/drivers/scsi/pm8001/pm80xx_hwi.c index df5f0bc295875..50e0890ddc678 100644 --- a/drivers/scsi/pm8001/pm80xx_hwi.c +++ b/drivers/scsi/pm8001/pm80xx_hwi.c @@ -692,6 +692,7 @@ static int mpi_init_check(struct pm8001_hba_info *pm8001_ha) /** * check_fw_ready - The LLDD check if the FW is ready, if not, return error. + * This function sleeps hence it must not be used in atomic context. * @pm8001_ha: our hba card information */ static int check_fw_ready(struct pm8001_hba_info *pm8001_ha) @@ -702,16 +703,16 @@ static int check_fw_ready(struct pm8001_hba_info *pm8001_ha) int ret = 0; /* reset / PCIe ready */ - max_wait_time = max_wait_count = 100 * 1000; /* 100 milli sec */ + max_wait_time = max_wait_count = 5; /* 100 milli sec */ do { - udelay(1); + msleep(FW_READY_INTERVAL); value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1); } while ((value == 0xFFFFFFFF) && (--max_wait_count)); /* check ila status */ - max_wait_time = max_wait_count = 1000 * 1000; /* 1000 milli sec */ + max_wait_time = max_wait_count = 50; /* 1000 milli sec */ do { - udelay(1); + msleep(FW_READY_INTERVAL); value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1); } while (((value & SCRATCH_PAD_ILA_READY) != SCRATCH_PAD_ILA_READY) && (--max_wait_count)); @@ -724,9 +725,9 @@ static int check_fw_ready(struct pm8001_hba_info *pm8001_ha) } /* check RAAE status */ - max_wait_time = max_wait_count = 1800 * 1000; /* 1800 milli sec */ + max_wait_time = max_wait_count = 90; /* 1800 milli sec */ do { - udelay(1); + msleep(FW_READY_INTERVAL); value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1); } while (((value & SCRATCH_PAD_RAAE_READY) != SCRATCH_PAD_RAAE_READY) && (--max_wait_count)); @@ -739,9 +740,9 @@ static int check_fw_ready(struct pm8001_hba_info *pm8001_ha) } /* check iop0 status */ - max_wait_time = max_wait_count = 600 * 1000; /* 600 milli sec */ + max_wait_time = max_wait_count = 30; /* 600 milli sec */ do { - udelay(1); + msleep(FW_READY_INTERVAL); value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1); } while (((value & SCRATCH_PAD_IOP0_READY) != SCRATCH_PAD_IOP0_READY) && (--max_wait_count)); @@ -757,9 +758,9 @@ static int check_fw_ready(struct pm8001_hba_info *pm8001_ha) if ((pm8001_ha->chip_id != chip_8008) && (pm8001_ha->chip_id != chip_8009)) { /* 200 milli sec */ - max_wait_time = max_wait_count = 200 * 1000; + max_wait_time = max_wait_count = 10; do { - udelay(1); + msleep(FW_READY_INTERVAL); value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1); } while (((value & SCRATCH_PAD_IOP1_READY) != SCRATCH_PAD_IOP1_READY) && (--max_wait_count)); diff --git a/drivers/scsi/pm8001/pm80xx_hwi.h b/drivers/scsi/pm8001/pm80xx_hwi.h index 411b414a9a0ef..85cdd6d9348a6 100644 --- a/drivers/scsi/pm8001/pm80xx_hwi.h +++ b/drivers/scsi/pm8001/pm80xx_hwi.h @@ -1534,3 +1534,9 @@ typedef struct SASProtocolTimerConfig SASProtocolTimerConfig_t; #define MEMBASE_II_SHIFT_REGISTER 0x1010 #endif + +/** + * As we know sleep (1~20) ms may result in sleep longer than ~20 ms, hence we + * choose 20 ms interval. + */ +#define FW_READY_INTERVAL 20 -- 2.27.0