From patchwork Sun Jul 28 13:06:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Usyskin X-Patchwork-Id: 13743994 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 B1478EAD0 for ; Sun, 28 Jul 2024 13:15:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722172538; cv=none; b=P0cQ/zSgHT4u/WT7l57eBT8eQL1tC8VTU4HDcbcSUtEB3lYKiaM+ZkVu+KJailcySchBsDqVOVUjcdADvXc0vD1DKMrZIjHFfS4RdYaWK0XuaTQo63IB8tBi3VX1PZdO8UA+/158wsmj/5GIvoIM1zypHvbUIR6OUA+sfdBUbsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722172538; c=relaxed/simple; bh=RXv/8HHQlvGJZSc4bfEumgCJIypGPgEUU9zuekqRKBA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BT28uS7mTzd8ZYVCvYR7yzLG5VV/s4p+6/qPpuoAPetkYKmYhhYqAxAnavZ5Rv4oJdIG6P+yJcn+L82c/u+HBjMzuKncmuRf7AqfeMWp3eV0RRI+2rXx7aLlMFSDroaGIEYFrbVmMV3+LKN6BsG0KYxuymB6ZyC20Bn1RlFckoo= 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=JguiNGLc; arc=none smtp.client-ip=198.175.65.14 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="JguiNGLc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1722172537; x=1753708537; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RXv/8HHQlvGJZSc4bfEumgCJIypGPgEUU9zuekqRKBA=; b=JguiNGLcFjcaZ2NtNuprROagSjrZLZY+nWoD8WKUPyVd5BYZRyE3WsOf +wA6spwC737BgDpl1N/0rWdAKMqAHmfO+6sfvchYh/VRkxYZaeRoZC23z 6Xr6VtE7ZUl6FkN5QPfoV90dNYh3IEAym7AVKcnVCBzYyJBlxPZjtcf5G NOAnyuj90P14+PSkC0UgKrWfg2kLUr5f9HnrmxsLhtXSr8QXHJ0Vp2Jdt RKXV1b9BF11iKiQIMtBgZnrYIAhuP51TCk2CuaCebPbpixh3SAFnlkVNJ aMAVahk3tohgPtrBHSm3LsKKKz+bXJI8uKrRPlQzHQkrn+/ZkdErykUWA Q==; X-CSE-ConnectionGUID: 6Lbcx5YATkiAvPFVR6stcg== X-CSE-MsgGUID: rtnecNVgQbmcYgA8BeGZAA== X-IronPort-AV: E=McAfee;i="6700,10204,11147"; a="23713444" X-IronPort-AV: E=Sophos;i="6.09,243,1716274800"; d="scan'208";a="23713444" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2024 06:15:36 -0700 X-CSE-ConnectionGUID: QOT7DcAjRnizYORmajGlVw== X-CSE-MsgGUID: 9dMvzYyxTfeKqVnVcBzXPA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,243,1716274800"; d="scan'208";a="53389265" Received: from sannilnx-dsk.jer.intel.com ([10.12.231.107]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2024 06:15:31 -0700 From: Alexander Usyskin To: Mark Brown , Lucas De Marchi , Oded Gabbay , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin Cc: Tomas Winkler , Alexander Usyskin , Vitaly Lubart , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-spi@vger.kernel.org, intel-gfx@lists.freedesktop.org Subject: [PATCH v4 06/12] spi: intel-dg: align 64bit read and write Date: Sun, 28 Jul 2024 16:06:32 +0300 Message-Id: <20240728130638.1930463-7-alexander.usyskin@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240728130638.1930463-1-alexander.usyskin@intel.com> References: <20240728130638.1930463-1-alexander.usyskin@intel.com> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 GSC SPI HW errors on quad access overlapping 1K border. Align 64bit read and write to avoid readq/writeq over 1K border. Signed-off-by: Alexander Usyskin --- drivers/spi/spi-intel-dg.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/spi/spi-intel-dg.c b/drivers/spi/spi-intel-dg.c index dfb457c43a5d..c76b0a70f8d8 100644 --- a/drivers/spi/spi-intel-dg.c +++ b/drivers/spi/spi-intel-dg.c @@ -231,6 +231,24 @@ static ssize_t spi_write(struct intel_dg_spi *spi, u8 region, len_s -= to_shift; } + if (!IS_ALIGNED(to, sizeof(u64)) && + ((to ^ (to + len_s)) & GENMASK(31, 10))) { + /* + * Workaround reads/writes across 1k-aligned addresses + * (start u32 before 1k, end u32 after) + * as this fails on hardware. + */ + u32 data; + + memcpy(&data, &buf[0], sizeof(u32)); + spi_write32(spi, to, data); + if (spi_error(spi)) + return -EIO; + buf += sizeof(u32); + to += sizeof(u32); + len_s -= sizeof(u32); + } + len8 = ALIGN_DOWN(len_s, sizeof(u64)); for (i = 0; i < len8; i += sizeof(u64)) { u64 data; @@ -289,6 +307,23 @@ static ssize_t spi_read(struct intel_dg_spi *spi, u8 region, from += from_shift; } + if (!IS_ALIGNED(from, sizeof(u64)) && + ((from ^ (from + len_s)) & GENMASK(31, 10))) { + /* + * Workaround reads/writes across 1k-aligned addresses + * (start u32 before 1k, end u32 after) + * as this fails on hardware. + */ + u32 data = spi_read32(spi, from); + + if (spi_error(spi)) + return -EIO; + memcpy(&buf[0], &data, sizeof(data)); + len_s -= sizeof(u32); + buf += sizeof(u32); + from += sizeof(u32); + } + len8 = ALIGN_DOWN(len_s, sizeof(u64)); for (i = 0; i < len8; i += sizeof(u64)) { u64 data = spi_read64(spi, from + i);