From nobody Sun Nov 24 05:39:47 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3AD01CFEAE for ; Tue, 19 Nov 2024 14:13:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732025594; cv=none; b=NSuIbbcvcCXZtK8vHkaQFL6TxikE/6ZUJtC8axeB7PoBSVkb687qiFZdsSw4yadkp6+zrcsPhFZ3DfhXMjXE1ycNzgIcVW+61NXAkYI4PvMgilGUe1jn8HOqdHE/j3269IqCQBiVkT5MBgzY+QY1vNWuM8t/vNQb9rG5BmZw22U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732025594; c=relaxed/simple; bh=YddhOr+x1FFsjDxuWJVLYltOhqNL9BDhv+loxqb6xZc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=soqyobT6TKw8jRkDxVySsmDZAGlFF3Lm2VNNsMYNskPyOusx+7hKHwB5W7apsEJk3v8S44QkQk1d7mfVM8QptI6NPdR6UPjoXN5q1+aMLvOcR30bLO4x0UMSfD84+XjSUZDqloE122N+FKhiE+BKfPgzh41lzcRzo8XvHou80uU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Y/FqzSMw; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Y/FqzSMw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732025593; x=1763561593; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YddhOr+x1FFsjDxuWJVLYltOhqNL9BDhv+loxqb6xZc=; b=Y/FqzSMwynBsnJY9rTeP48KHueBYgo2cZkbgOf1DZJKi/znkBjptK9GX GsZi8Pni+7A0I+SKIQi4OP3GGuveEvhYpT64hfo2ETiQjffDKyCcX95+A J1zFMRTaIAONnqP9gkJ1ss1UKdVlzT1CEhMugznMKc4QitZoq33E0sfbQ +pNeYD66E/MOh3ZT/2wVrcwXQ0SQ9RpBtOj1nERxVqZ/1Ja11M2jYSKYH spJCib2dz3Co+kpDfmtPdoZ7Bv0QUBvp9OHI6yilL+3wLy112J95B/VWz OfPImbX1dzuTAXtzqq61R9/d8ipYgtsa3eZOz4sPcAzSNvaJdvT+Dbc/V A==; X-CSE-ConnectionGUID: jAILY+tkTeeDuSP4KZR7tg== X-CSE-MsgGUID: 614wXZEhSbqWCyaBWPm+lQ== X-IronPort-AV: E=McAfee;i="6700,10204,11261"; a="54526785" X-IronPort-AV: E=Sophos;i="6.12,166,1728975600"; d="scan'208";a="54526785" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2024 06:13:13 -0800 X-CSE-ConnectionGUID: RUO/cq5pQnOAjP4/YbdIXw== X-CSE-MsgGUID: QJLySFFrQIi9Xp4IFW825w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,166,1728975600"; d="scan'208";a="94398663" Received: from sannilnx-dsk.jer.intel.com ([10.12.231.107]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2024 06:13:08 -0800 From: Alexander Usyskin To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Lucas De Marchi , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Rodrigo Vivi , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jani Nikula , Joonas Lahtinen , Tvrtko Ursulin Cc: Oren Weil , linux-mtd@lists.infradead.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, Alexander Usyskin Subject: [PATCH v3 06/10] mtd: intel-dg: wake card on operations Date: Tue, 19 Nov 2024 16:01:08 +0200 Message-ID: <20241119140112.790720-7-alexander.usyskin@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241119140112.790720-1-alexander.usyskin@intel.com> References: <20241119140112.790720-1-alexander.usyskin@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Enable runtime PM in mtd driver to notify graphics driver that whole card should be kept awake while nvm operations are performed through this driver. CC: Lucas De Marchi Acked-by: Miquel Raynal Signed-off-by: Alexander Usyskin --- drivers/mtd/devices/mtd-intel-dg.c | 70 +++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/drivers/mtd/devices/mtd-intel-dg.c b/drivers/mtd/devices/mtd-i= ntel-dg.c index 230bf444b7fe..9dd23b11ee95 100644 --- a/drivers/mtd/devices/mtd-intel-dg.c +++ b/drivers/mtd/devices/mtd-intel-dg.c @@ -15,11 +15,14 @@ #include #include #include +#include #include #include #include #include =20 +#define INTEL_DG_NVM_RPM_TIMEOUT 500 + struct intel_dg_nvm { struct kref refcnt; struct mtd_info mtd; @@ -460,6 +463,7 @@ static int intel_dg_mtd_erase(struct mtd_info *mtd, str= uct erase_info *info) loff_t from; size_t len; size_t total_len; + int ret =3D 0; =20 if (WARN_ON(!nvm)) return -EINVAL; @@ -474,20 +478,28 @@ static int intel_dg_mtd_erase(struct mtd_info *mtd, s= truct erase_info *info) total_len =3D info->len; addr =3D info->addr; =20 + ret =3D pm_runtime_resume_and_get(mtd->dev.parent); + if (ret < 0) { + dev_err(&mtd->dev, "rpm: get failed %d\n", ret); + return ret; + } + guard(mutex)(&nvm->lock); =20 while (total_len > 0) { if (!IS_ALIGNED(addr, SZ_4K) || !IS_ALIGNED(total_len, SZ_4K)) { dev_err(&mtd->dev, "unaligned erase %llx %zx\n", addr, total_len); info->fail_addr =3D addr; - return -ERANGE; + ret =3D -ERANGE; + goto out; } =20 idx =3D idg_nvm_get_region(nvm, addr); if (idx >=3D nvm->nregions) { dev_err(&mtd->dev, "out of range"); info->fail_addr =3D MTD_FAIL_ADDR_UNKNOWN; - return -ERANGE; + ret =3D -ERANGE; + goto out; } =20 from =3D addr - nvm->regions[idx].offset; @@ -503,14 +515,18 @@ static int intel_dg_mtd_erase(struct mtd_info *mtd, s= truct erase_info *info) if (bytes < 0) { dev_dbg(&mtd->dev, "erase failed with %zd\n", bytes); info->fail_addr +=3D nvm->regions[idx].offset; - return bytes; + ret =3D bytes; + goto out; } =20 addr +=3D len; total_len -=3D len; } =20 - return 0; +out: + pm_runtime_mark_last_busy(mtd->dev.parent); + pm_runtime_put_autosuspend(mtd->dev.parent); + return ret; } =20 static int intel_dg_mtd_read(struct mtd_info *mtd, loff_t from, size_t len, @@ -539,17 +555,25 @@ static int intel_dg_mtd_read(struct mtd_info *mtd, lo= ff_t from, size_t len, if (len > nvm->regions[idx].size - from) len =3D nvm->regions[idx].size - from; =20 + ret =3D pm_runtime_resume_and_get(mtd->dev.parent); + if (ret < 0) { + dev_err(&mtd->dev, "rpm: get failed %zd\n", ret); + return ret; + } + guard(mutex)(&nvm->lock); =20 ret =3D idg_read(nvm, region, from, len, buf); if (ret < 0) { dev_dbg(&mtd->dev, "read failed with %zd\n", ret); - return ret; + } else { + *retlen =3D ret; + ret =3D 0; } =20 - *retlen =3D ret; - - return 0; + pm_runtime_mark_last_busy(mtd->dev.parent); + pm_runtime_put_autosuspend(mtd->dev.parent); + return ret; } =20 static int intel_dg_mtd_write(struct mtd_info *mtd, loff_t to, size_t len, @@ -578,17 +602,25 @@ static int intel_dg_mtd_write(struct mtd_info *mtd, l= off_t to, size_t len, if (len > nvm->regions[idx].size - to) len =3D nvm->regions[idx].size - to; =20 + ret =3D pm_runtime_resume_and_get(mtd->dev.parent); + if (ret < 0) { + dev_err(&mtd->dev, "rpm: get failed %zd\n", ret); + return ret; + } + guard(mutex)(&nvm->lock); =20 ret =3D idg_write(nvm, region, to, len, buf); if (ret < 0) { dev_dbg(&mtd->dev, "write failed with %zd\n", ret); - return ret; + } else { + *retlen =3D ret; + ret =3D 0; } =20 - *retlen =3D ret; - - return 0; + pm_runtime_mark_last_busy(mtd->dev.parent); + pm_runtime_put_autosuspend(mtd->dev.parent); + return ret; } =20 static void intel_dg_nvm_release(struct kref *kref) @@ -720,6 +752,17 @@ static int intel_dg_mtd_probe(struct auxiliary_device = *aux_dev, n++; } =20 + devm_pm_runtime_enable(device); + + pm_runtime_set_autosuspend_delay(device, INTEL_DG_NVM_RPM_TIMEOUT); + pm_runtime_use_autosuspend(device); + + ret =3D pm_runtime_resume_and_get(device); + if (ret < 0) { + dev_err(device, "rpm: get failed %d\n", ret); + goto err_norpm; + } + nvm->base =3D devm_ioremap_resource(device, &invm->bar); if (IS_ERR(nvm->base)) { dev_err(device, "mmio not mapped\n"); @@ -742,9 +785,12 @@ static int intel_dg_mtd_probe(struct auxiliary_device = *aux_dev, =20 dev_set_drvdata(&aux_dev->dev, nvm); =20 + pm_runtime_put(device); return 0; =20 err: + pm_runtime_put(device); +err_norpm: kref_put(&nvm->refcnt, intel_dg_nvm_release); return ret; } --=20 2.43.0