From patchwork Wed Sep 20 19:26:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393318 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98517C04FEE for ; Wed, 20 Sep 2023 19:28:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230032AbjITT2b (ORCPT ); Wed, 20 Sep 2023 15:28:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjITT2a (ORCPT ); Wed, 20 Sep 2023 15:28:30 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA3CFE6; Wed, 20 Sep 2023 12:28:22 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50300141a64so447877e87.0; Wed, 20 Sep 2023 12:28:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238101; x=1695842901; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=slA2GCsU+M93cytZBZ/cPNG/4Z+l1JlZLJUZAsah/2M=; b=XLsawXZMEqnncaPl7LJzYzIBdWiaF1/WpNYwNa8fjHKuNn7ofvDXg2dpxqJeXqChz4 Yu3RKtliN+O4iYvPoKh0VESxNnUVJZk0I+YBdw1+tk/udaI/Q8EMZGwOii87B80FyoM/ f44/dxX6ClOYZ38d0aG5RyeVFdvw2KD0KHchQWwKAngeaQmujx9KaDyzxw+6jCHooNo0 Gsvyiytad4kdzY+lsgVqAweB/bnhjUlujAEvHUAesIqP3BQeD182UbYHZQ2BzosVu0Cu xIKVJCMP28G4aKWH65WnKFax37e+zEyh58/Y87+Usz1Tl4FewNNSHaC8GhXasuZFOCQu ZxUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238101; x=1695842901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=slA2GCsU+M93cytZBZ/cPNG/4Z+l1JlZLJUZAsah/2M=; b=moU4GMz38a+Se5Tzj6MqGglT9L9ht6Xw1vi6IxUyQhFhtDexQx+xCIpzS2Sgt75CPK dcA4FkuqhMIJSTdLNBUzAq5NUB71SPSSWvwwXSWL8pPFFWuPjdwfI46bqth0Q9Mw5OQW TrJzM8nt+pB9gMLb1YupvfSIm8DeRLC0B+v9urimCmAxRN5aJrwNp/MBSshZLRNB4XlY GoInPPQSBVoYqLZpHBFaH9NgBsYs210jF1xWJUeMlZPqZ2hW/qsbCXrHEiLlNzbH9c4j 2Qs0qvt4Q303AHDErCEfLPKcNZ7gXhmZz6vQwQCkuUg8gS+td52Lv+MRBaSKYVykEb35 WYjw== X-Gm-Message-State: AOJu0YzlQsYI7F7X/tSK+5cQP1y2tFj4JdqAGXxm7DPgDA5D82OUbAuG C61ZZ/uuZe967YSRI4PNztk= X-Google-Smtp-Source: AGHT+IF+ObWvzYHZ8zlMxC7DoVW4y5G1q84HHE1PKwiFaw5asqnXFJ+fr0nnN/Rho8M8vEajlLTXNg== X-Received: by 2002:a19:6905:0:b0:502:adbb:f9db with SMTP id e5-20020a196905000000b00502adbbf9dbmr2142896lfc.65.1695238100510; Wed, 20 Sep 2023 12:28:20 -0700 (PDT) Received: from localhost ([85.26.234.143]) by smtp.gmail.com with ESMTPSA id v22-20020ac25596000000b005041a71237asm339716lfg.111.2023.09.20.12.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:28:19 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 01/18] EDAC/synopsys: Convert sysfs nodes to debugfs ones Date: Wed, 20 Sep 2023 22:26:46 +0300 Message-ID: <20230920192806.29960-2-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org The DW uMCTL2 DDRC EDAC driver supports creating two sysfs nodes: "inject_data_error" and "inject_data_poison". First of them is responsible for setting the error-injecting physical address up. The second one is supposed to be used to enable the hardware capability of the correctable and uncorrectable errors injection. The semantics of these nodes is pure debug. They are even created only if the EDAC_DEBUG kernel config is enabled. Thus there is no point in having these nodes exported in the sysfs especially seeing they aren't listed in the sysfs ABI. Just move them to the device private directory in DebugFS. While at it move the address map initialization procedure call to the DebugFS nodes creating function (it's useless with no DebugFS nodes being available anyway) and create an empty snps_create_debugfs_nodes() method in case if the EDAC_DEBUG config is disabled. Thus the DW uMCTL2 DDRC EDAC probe procedure will get to be a bit simpler and redundant work won't be performed. Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 221 +++++++++++++++++++---------------- 1 file changed, 122 insertions(+), 99 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index 327023e35d42..10716f365c6f 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -641,6 +642,16 @@ static int snps_setup_irq(struct mem_ctl_info *mci, struct platform_device *pdev #ifdef CONFIG_EDAC_DEBUG +#define SNPS_DEBUGFS_FOPS(__name, __read, __write) \ + static const struct file_operations __name = { \ + .owner = THIS_MODULE, \ + .open = simple_open, \ + .read = __read, \ + .write = __write, \ + } + +#define SNPS_DBGFS_BUF_LEN 128 + /** * snps_data_poison_setup - Update poison registers. * @priv: DDR memory controller private instance data. @@ -701,90 +712,6 @@ static void snps_data_poison_setup(struct snps_edac_priv *priv) writel(regval, priv->baseaddr + ECC_POISON1_OFST); } -static ssize_t inject_data_error_show(struct device *dev, - struct device_attribute *mattr, - char *data) -{ - struct mem_ctl_info *mci = to_mci(dev); - struct snps_edac_priv *priv = mci->pvt_info; - - return sprintf(data, "Poison0 Addr: 0x%08x\n\rPoison1 Addr: 0x%08x\n\r" - "Error injection Address: 0x%lx\n\r", - readl(priv->baseaddr + ECC_POISON0_OFST), - readl(priv->baseaddr + ECC_POISON1_OFST), - priv->poison_addr); -} - -static ssize_t inject_data_error_store(struct device *dev, - struct device_attribute *mattr, - const char *data, size_t count) -{ - struct mem_ctl_info *mci = to_mci(dev); - struct snps_edac_priv *priv = mci->pvt_info; - - if (kstrtoul(data, 0, &priv->poison_addr)) - return -EINVAL; - - snps_data_poison_setup(priv); - - return count; -} - -static ssize_t inject_data_poison_show(struct device *dev, - struct device_attribute *mattr, - char *data) -{ - struct mem_ctl_info *mci = to_mci(dev); - struct snps_edac_priv *priv = mci->pvt_info; - const char *errstr; - u32 regval; - - regval = readl(priv->baseaddr + ECC_CFG1_OFST); - errstr = FIELD_GET(ECC_CEPOISON_MASK, regval) == ECC_CEPOISON_MASK ? - "Correctable Error" : "UnCorrectable Error"; - - return sprintf(data, "Data Poisoning: %s\n\r", errstr); -} - -static ssize_t inject_data_poison_store(struct device *dev, - struct device_attribute *mattr, - const char *data, size_t count) -{ - struct mem_ctl_info *mci = to_mci(dev); - struct snps_edac_priv *priv = mci->pvt_info; - - writel(0, priv->baseaddr + DDR_SWCTL); - if (strncmp(data, "CE", 2) == 0) - writel(ECC_CEPOISON_MASK, priv->baseaddr + ECC_CFG1_OFST); - else - writel(ECC_UEPOISON_MASK, priv->baseaddr + ECC_CFG1_OFST); - writel(1, priv->baseaddr + DDR_SWCTL); - - return count; -} - -static DEVICE_ATTR_RW(inject_data_error); -static DEVICE_ATTR_RW(inject_data_poison); - -static int snps_create_sysfs_attributes(struct mem_ctl_info *mci) -{ - int rc; - - rc = device_create_file(&mci->dev, &dev_attr_inject_data_error); - if (rc < 0) - return rc; - rc = device_create_file(&mci->dev, &dev_attr_inject_data_poison); - if (rc < 0) - return rc; - return 0; -} - -static void snps_remove_sysfs_attributes(struct mem_ctl_info *mci) -{ - device_remove_file(&mci->dev, &dev_attr_inject_data_error); - device_remove_file(&mci->dev, &dev_attr_inject_data_poison); -} - static void snps_setup_row_address_map(struct snps_edac_priv *priv, u32 *addrmap) { u32 addrmap_row_b2_10; @@ -1005,7 +932,115 @@ static void snps_setup_address_map(struct snps_edac_priv *priv) snps_setup_rank_address_map(priv, addrmap); } -#endif /* CONFIG_EDAC_DEBUG */ + +static ssize_t snps_inject_data_error_read(struct file *filep, char __user *ubuf, + size_t size, loff_t *offp) +{ + struct mem_ctl_info *mci = filep->private_data; + struct snps_edac_priv *priv = mci->pvt_info; + char buf[SNPS_DBGFS_BUF_LEN]; + int pos; + + pos = scnprintf(buf, sizeof(buf), "Poison0 Addr: 0x%08x\n\r", + readl(priv->baseaddr + ECC_POISON0_OFST)); + pos += scnprintf(buf + pos, sizeof(buf) - pos, "Poison1 Addr: 0x%08x\n\r", + readl(priv->baseaddr + ECC_POISON1_OFST)); + pos += scnprintf(buf + pos, sizeof(buf) - pos, "Error injection Address: 0x%lx\n\r", + priv->poison_addr); + + return simple_read_from_buffer(ubuf, size, offp, buf, pos); +} + +static ssize_t snps_inject_data_error_write(struct file *filep, const char __user *ubuf, + size_t size, loff_t *offp) +{ + struct mem_ctl_info *mci = filep->private_data; + struct snps_edac_priv *priv = mci->pvt_info; + int rc; + + rc = kstrtoul_from_user(ubuf, size, 0, &priv->poison_addr); + if (rc) + return rc; + + snps_data_poison_setup(priv); + + return size; +} + +SNPS_DEBUGFS_FOPS(snps_inject_data_error, snps_inject_data_error_read, + snps_inject_data_error_write); + +static ssize_t snps_inject_data_poison_read(struct file *filep, char __user *ubuf, + size_t size, loff_t *offp) +{ + struct mem_ctl_info *mci = filep->private_data; + struct snps_edac_priv *priv = mci->pvt_info; + char buf[SNPS_DBGFS_BUF_LEN]; + const char *errstr; + u32 regval; + int pos; + + regval = readl(priv->baseaddr + ECC_CFG1_OFST); + errstr = FIELD_GET(ECC_CEPOISON_MASK, regval) == ECC_CEPOISON_MASK ? + "Correctable Error" : "UnCorrectable Error"; + + pos = scnprintf(buf, sizeof(buf), "Data Poisoning: %s\n\r", errstr); + + return simple_read_from_buffer(ubuf, size, offp, buf, pos); +} + +static ssize_t snps_inject_data_poison_write(struct file *filep, const char __user *ubuf, + size_t size, loff_t *offp) +{ + struct mem_ctl_info *mci = filep->private_data; + struct snps_edac_priv *priv = mci->pvt_info; + char buf[SNPS_DBGFS_BUF_LEN]; + int rc; + + rc = simple_write_to_buffer(buf, sizeof(buf), offp, ubuf, size); + if (rc < 0) + return rc; + + writel(0, priv->baseaddr + DDR_SWCTL); + if (strncmp(buf, "CE", 2) == 0) + writel(ECC_CEPOISON_MASK, priv->baseaddr + ECC_CFG1_OFST); + else + writel(ECC_UEPOISON_MASK, priv->baseaddr + ECC_CFG1_OFST); + writel(1, priv->baseaddr + DDR_SWCTL); + + return size; +} + +SNPS_DEBUGFS_FOPS(snps_inject_data_poison, snps_inject_data_poison_read, + snps_inject_data_poison_write); + +/** + * snps_create_debugfs_nodes - Create DebugFS nodes. + * @mci: EDAC memory controller instance. + * + * Create DW uMCTL2 EDAC driver DebugFS nodes in the device private + * DebugFS directory. + * + * Return: none. + */ +static void snps_create_debugfs_nodes(struct mem_ctl_info *mci) +{ + struct snps_edac_priv *priv = mci->pvt_info; + + snps_setup_address_map(priv); + + edac_debugfs_create_file("inject_data_error", 0600, mci->debugfs, mci, + &snps_inject_data_error); + + edac_debugfs_create_file("inject_data_poison", 0600, mci->debugfs, mci, + &snps_inject_data_poison); +} + +#else /* !CONFIG_EDAC_DEBUG */ + +static inline void snps_create_debugfs_nodes(struct mem_ctl_info *mci) {} + +#endif /* !CONFIG_EDAC_DEBUG */ /** * snps_mc_probe - Check controller and bind driver. @@ -1071,17 +1106,9 @@ static int snps_mc_probe(struct platform_device *pdev) goto free_edac_mc; } -#ifdef CONFIG_EDAC_DEBUG - rc = snps_create_sysfs_attributes(mci); - if (rc) { - edac_printk(KERN_ERR, EDAC_MC, "Failed to create sysfs entries\n"); - goto free_edac_mc; - } + snps_create_debugfs_nodes(mci); - snps_setup_address_map(priv); -#endif - - return rc; + return 0; free_edac_mc: edac_mc_free(mci); @@ -1102,10 +1129,6 @@ static int snps_mc_remove(struct platform_device *pdev) snps_disable_irq(priv); -#ifdef CONFIG_EDAC_DEBUG - snps_remove_sysfs_attributes(mci); -#endif - edac_mc_del_mc(&pdev->dev); edac_mc_free(mci); From patchwork Wed Sep 20 19:26:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F320C04FEE for ; Wed, 20 Sep 2023 19:28:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230083AbjITT2k (ORCPT ); Wed, 20 Sep 2023 15:28:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230086AbjITT2d (ORCPT ); Wed, 20 Sep 2023 15:28:33 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C1F5CF; Wed, 20 Sep 2023 12:28:25 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-5041d6d8b10so388987e87.2; Wed, 20 Sep 2023 12:28:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238103; x=1695842903; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lSZwUqk2LhSLToURZdxj4BC7qr/BbA6pyW8daToL0QU=; b=GOGFa5ZnwkOyvD39t7dB/bRq9FH81IB5xGCcpy2qCyGmjF1ZGJ/kqJeMUCXPgqg9hB uhjgGHAlfQW2mO6E03NCubxWAhGFvOnuoozdEreTErIEXUZEasazSd54ECyuB6mlCJS7 Q8iUhktLkOy5RNY4K26Ed6S3rWbOKU4r0LT/9j1C4KLU/gnwJi2EzEp5mCopfVhHsRgq zg23FUo8xdtL0LgWoFIyDFypEwwxaAqe09ONTJM6YLmzTk2McnB1uOh3Jvg4p8F/c+2a YkvLEqh/9zCzpLvBqoLgJaDDR+i06Bi3FRjYEKsMePj7n/qA+F+Iw5KYBLCScjJp/tTU 4brQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238103; x=1695842903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lSZwUqk2LhSLToURZdxj4BC7qr/BbA6pyW8daToL0QU=; b=uxfS3YSwyoCsI8+h9kLVqRgwCnLwBMrVfUYaqk60TPWCKW59sYiwRPvdO3w5+OGmR3 uXSWDvk4efaKXuLKqnBNBRjV4wzaf3azYl4xyjnfgiNi3OMYXgFRP0oQ+LFKIo3WJ15V dJz+apn1Ft0+IRLzDG7hGfj1KBtP92jUzwNYoMnI5losoQ2GIMCrXAVuZnJrATnkcYsj Kf13TwhkP26o7IjOz9iVDEAQ1p0vmsfBleAl4PN9MsIEaj4qlZgrygEwEcyhxUa9tt0Q 0UlCzlXLCSYsH5PEs+MNNrwQHIbPWzfngG9hCar9rwwQkmGV75QLO3WtjIwMtkJYVOpa Q2+g== X-Gm-Message-State: AOJu0YxaYBmmJBaUjYFXaKG4v22Sze7WwBREWMrQAg5hqKxwBfVat7mk C6FZg6vNUOhhJZILbyWiTQE= X-Google-Smtp-Source: AGHT+IHu9ipPueyvMIh6eHJbINo45HFjPnT1i9SCVvpQktfQ6hYhHXC08wGvzUA0gWFFZYqbkjqqLQ== X-Received: by 2002:a19:ca03:0:b0:500:b42f:1830 with SMTP id a3-20020a19ca03000000b00500b42f1830mr2620543lfg.63.1695238103285; Wed, 20 Sep 2023 12:28:23 -0700 (PDT) Received: from localhost ([178.176.81.142]) by smtp.gmail.com with ESMTPSA id i25-20020a056512007900b0050332394bcasm802769lfo.150.2023.09.20.12.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:28:22 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 02/18] EDAC/mc: Extend memtypes with LPDDR(mDDR) and LPDDR2 Date: Wed, 20 Sep 2023 22:26:47 +0300 Message-ID: <20230920192806.29960-3-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org These are normal memory types [1] which can be met on the real hardware. DW uMCTL2 DDRC IP-core can be configured to have them supported [2,3]. Extend the EDAC memory types enumeration with the corresponding IDs then. [1] https://en.wikipedia.org/wiki/LPDDR [2] DesignWare® Cores Enhanced Universal DDR Memory Controller (uMCTL2) Databook, Version 3.91a, October 2020, p.501 [3] DesignWare® Cores Enhanced Universal DDR Memory Controller (uMCTL2) Databook, Version 3.91a, October 2020, p.1717 Signed-off-by: Serge Semin --- drivers/edac/edac_mc.c | 2 ++ include/linux/edac.h | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 634c41ea7804..e353e98e01e2 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -151,10 +151,12 @@ const char * const edac_mem_types[] = { [MEM_RDR] = "Registered-SDR", [MEM_DDR] = "Unbuffered-DDR", [MEM_RDDR] = "Registered-DDR", + [MEM_LPDDR] = "Low-Power-(m)DDR-RAM", [MEM_RMBS] = "RMBS", [MEM_DDR2] = "Unbuffered-DDR2", [MEM_FB_DDR2] = "FullyBuffered-DDR2", [MEM_RDDR2] = "Registered-DDR2", + [MEM_LPDDR2] = "Low-Power-DDR2-RAM", [MEM_XDR] = "XDR", [MEM_DDR3] = "Unbuffered-DDR3", [MEM_RDDR3] = "Registered-DDR3", diff --git a/include/linux/edac.h b/include/linux/edac.h index fa4bda2a70f6..89167a4459d5 100644 --- a/include/linux/edac.h +++ b/include/linux/edac.h @@ -157,6 +157,7 @@ static inline char *mc_event_error_type(const unsigned int err_type) * This is a variant of the DDR memories. * A registered memory has a buffer inside it, hiding * part of the memory details to the memory controller. + * @MEM_LPDDR: Low-Power DDR memory (mDDR). * @MEM_RMBS: Rambus DRAM, used on a few Pentium III/IV controllers. * @MEM_DDR2: DDR2 RAM, as described at JEDEC JESD79-2F. * Those memories are labeled as "PC2-" instead of "PC" to @@ -167,6 +168,7 @@ static inline char *mc_event_error_type(const unsigned int err_type) * a chip select signal. * @MEM_RDDR2: Registered DDR2 RAM * This is a variant of the DDR2 memories. + * @MEM_LPDDR2: Low-Power DDR2 memory. * @MEM_XDR: Rambus XDR * It is an evolution of the original RAMBUS memories, * created to compete with DDR2. Weren't used on any @@ -199,10 +201,12 @@ enum mem_type { MEM_RDR, MEM_DDR, MEM_RDDR, + MEM_LPDDR, MEM_RMBS, MEM_DDR2, MEM_FB_DDR2, MEM_RDDR2, + MEM_LPDDR2, MEM_XDR, MEM_DDR3, MEM_RDDR3, @@ -230,10 +234,12 @@ enum mem_type { #define MEM_FLAG_RDR BIT(MEM_RDR) #define MEM_FLAG_DDR BIT(MEM_DDR) #define MEM_FLAG_RDDR BIT(MEM_RDDR) +#define MEM_FLAG_LPDDR BIT(MEM_LPDDR) #define MEM_FLAG_RMBS BIT(MEM_RMBS) #define MEM_FLAG_DDR2 BIT(MEM_DDR2) #define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2) #define MEM_FLAG_RDDR2 BIT(MEM_RDDR2) +#define MEM_FLAG_LPDDR2 BIT(MEM_LPDDR2) #define MEM_FLAG_XDR BIT(MEM_XDR) #define MEM_FLAG_DDR3 BIT(MEM_DDR3) #define MEM_FLAG_RDDR3 BIT(MEM_RDDR3) From patchwork Wed Sep 20 19:26:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393320 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D522C04FF3 for ; Wed, 20 Sep 2023 19:28:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230075AbjITT2m (ORCPT ); Wed, 20 Sep 2023 15:28:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbjITT2j (ORCPT ); Wed, 20 Sep 2023 15:28:39 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A61DDD; Wed, 20 Sep 2023 12:28:28 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2bfc1d8f2d2so1527691fa.0; Wed, 20 Sep 2023 12:28:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238106; x=1695842906; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yRpb2GxtnVP5nWSE0kBTW6FlNIFe1bv1+IIvLCRkryM=; b=J89/KX1rrGeSm7nZZXyjFhCIYQi2CTeY96kmWBC0FVvy4u9hIPHDsK/p1DyRWpyBMJ fxxCPDURZmZSsIuPhPBkqjoOtHLTPuy+okI5DJOi4ZiqJi6d32s/+wrzbsIsxH72ZRss 1O+vT04WvaiY2x5pD9E3oR526f21VcA4qgz6CFXknitRWPxBIaEK0spJyhleXN+qyaJg pVdYOs3g3KcnabVkv2OrDKltjDkMVB2S7J0cCk+OhuM9Eu1D3bnowI2PjF4m+tag7PYN ubm+Q5cBm8qAYQ8CCbn7VfXwtspHxa1DK+0NfCKviFy1ayGi3S/HMFlIrDJlJNY/Te9g kcAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238106; x=1695842906; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yRpb2GxtnVP5nWSE0kBTW6FlNIFe1bv1+IIvLCRkryM=; b=wyXMbnoVznsu/dxDgZRiSXisqDcJ7Lrc++9owLbxuxzP3IXlLKo8TRR4Nxm+36Ry4V 9tajnphzFNzQ/DjtHlYxsqBhnBuZF2sXs7xgrCQ9FkpMYzfOs40HOPus8YE+6hKd5ftS lKqY/fRAR4gw/Uem4tS7s0GI044ONokYFjO4UOFa+ZmczHgONDAuNy+PZumIEIanW7rs QBZEqwi2s00ATOGOOaN/CZPckz0qi433jsBtZ80v0mWZi5xyxqNZ9Z8i8tMeRwP+pNcM qoNQFQ1Aqb79xGbigp6ivRZsB6HT8Hw7V5qOoJ751F0WU4clW3fABAod8lNXuPECpKii gDBg== X-Gm-Message-State: AOJu0YyZXRbvbleQFPDDk8QRTRdmSOrXCdqHWgbuXOkC4C7lV4WPHkYf Xi9rVv/21VcTPXaU3tuE0OU= X-Google-Smtp-Source: AGHT+IGyHrILRPaV9pJ2zQgJeEVuZslG3NO98MRbEvq/YyXB/RrkwS0N6dvP/s2RWOZgLB2ubbRn0Q== X-Received: by 2002:a2e:a60b:0:b0:2bf:f90e:2794 with SMTP id v11-20020a2ea60b000000b002bff90e2794mr2545427ljp.23.1695238106225; Wed, 20 Sep 2023 12:28:26 -0700 (PDT) Received: from localhost ([178.176.85.138]) by smtp.gmail.com with ESMTPSA id d19-20020a2eb053000000b002b9ec22d9fasm1105300ljl.29.2023.09.20.12.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:28:25 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 03/18] EDAC/synopsys: Extend memtypes supported by controller Date: Wed, 20 Sep 2023 22:26:48 +0300 Message-ID: <20230920192806.29960-4-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org In accordance with [1] the DW uMCTL2 DDR controllers can support the next DDR protocols: LPDDR, (LP)DDR(2|3|4). Even if the controller is configured to support several of these memory chip types only one of these modes could be enabled at runtime [2]. Taking all of that into account update the snps_get_mtype() procedure so the DW uMCTL2 DDRC driver would be able to detect all the claimed to be supported memory types in accordance with the table defined in [2]. Note alas it's not possible do determine which MEMC DDR configs were enabled at the IP-core synthesize. Therefore there is no other choice but to initialize the EDAC MC mem-types capability field with all the types claimed to be supported by the IP-core. [1] DesignWare® Cores Enhanced Universal DDR Memory Controller (uMCTL2) Databook, Version 3.91a, October 2020, p.501 [2] DesignWare® Cores Enhanced Universal DDR Memory Controller (uMCTL2) Databook, Version 3.91a, October 2020, p.501 Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 41 ++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index 10716f365c6f..e08e9f3c81cb 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -102,11 +102,14 @@ #define DDR_MSTR_BUSWIDTH_16 2 #define DDR_MSTR_BUSWIDTH_32 1 #define DDR_MSTR_BUSWIDTH_64 0 +#define DDR_MSTR_MEM_MASK GENMASK(5, 0) #define DDR_MSTR_MEM_LPDDR4 BIT(5) #define DDR_MSTR_MEM_DDR4 BIT(4) #define DDR_MSTR_MEM_LPDDR3 BIT(3) -#define DDR_MSTR_MEM_DDR2 BIT(2) +#define DDR_MSTR_MEM_LPDDR2 BIT(2) +#define DDR_MSTR_MEM_LPDDR BIT(1) #define DDR_MSTR_MEM_DDR3 BIT(0) +#define DDR_MSTR_MEM_DDR2 0 /* ECC CFG0 register definitions */ #define ECC_CFG0_MODE_MASK GENMASK(2, 0) @@ -535,21 +538,29 @@ static u32 snps_get_memsize(void) */ static enum mem_type snps_get_mtype(const void __iomem *base) { - enum mem_type mt; - u32 memtype; + u32 regval; - memtype = readl(base + DDR_MSTR_OFST); + regval = readl(base + DDR_MSTR_OFST); + regval = FIELD_GET(DDR_MSTR_MEM_MASK, regval); - if ((memtype & DDR_MSTR_MEM_DDR3) || (memtype & DDR_MSTR_MEM_LPDDR3)) - mt = MEM_DDR3; - else if (memtype & DDR_MSTR_MEM_DDR2) - mt = MEM_RDDR2; - else if ((memtype & DDR_MSTR_MEM_LPDDR4) || (memtype & DDR_MSTR_MEM_DDR4)) - mt = MEM_DDR4; - else - mt = MEM_EMPTY; + switch (regval) { + case DDR_MSTR_MEM_DDR2: + return MEM_DDR2; + case DDR_MSTR_MEM_DDR3: + return MEM_DDR3; + case DDR_MSTR_MEM_LPDDR: + return MEM_LPDDR; + case DDR_MSTR_MEM_LPDDR2: + return MEM_LPDDR2; + case DDR_MSTR_MEM_LPDDR3: + return MEM_LPDDR3; + case DDR_MSTR_MEM_DDR4: + return MEM_DDR4; + case DDR_MSTR_MEM_LPDDR4: + return MEM_LPDDR4; + } - return mt; + return MEM_RESERVED; } /** @@ -597,7 +608,9 @@ static void snps_mc_init(struct mem_ctl_info *mci, struct platform_device *pdev) platform_set_drvdata(pdev, mci); /* Initialize controller capabilities and configuration */ - mci->mtype_cap = MEM_FLAG_DDR3 | MEM_FLAG_DDR2; + mci->mtype_cap = MEM_FLAG_LPDDR | MEM_FLAG_DDR2 | MEM_FLAG_LPDDR2 | + MEM_FLAG_DDR3 | MEM_FLAG_LPDDR3 | + MEM_FLAG_DDR4 | MEM_FLAG_LPDDR4; mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED; mci->scrub_cap = SCRUB_FLAG_HW_SRC; mci->scrub_mode = SCRUB_NONE; From patchwork Wed Sep 20 19:26:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E90FC04FEE for ; Wed, 20 Sep 2023 19:28:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230062AbjITT2o (ORCPT ); Wed, 20 Sep 2023 15:28:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbjITT2m (ORCPT ); Wed, 20 Sep 2023 15:28:42 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42CBF114; Wed, 20 Sep 2023 12:28:31 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2b703a0453fso2524441fa.3; Wed, 20 Sep 2023 12:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238109; x=1695842909; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0p8U90biBaY98m+/7YTgOwqeSiRSThvzebPVxAHZ0NU=; b=YU5zbwGKx/ICAPjZvijMNjTAiNNyrDSv8Z701ckije+DwAzWZbArwY0k/qtxfAI22k e+CJ8BBNqFJNjx9KwV4s8Vw+lH7ccWiwuRIsB2gD3YZnWW4YwwygwuhMkILVU8JaHTMz aH5Z0boQNbSXtnlS1gU8Knvi6TphsV8vKO89od6kjMT7bTldTbRpwFaglys5it5Uef2K SpzJvYpSl3UUsb6nq9svjRzqvyJKjLKDSflp3xoUZ0iQwtZ5xVr6z7LQUHb6PHqopyKv 05TKkt+ElArn+CqxT4IiCoE2Vo42CgpO2iTNf+0DTUI4fX/SwDtW95roZQFqO7r8uv47 PrZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238109; x=1695842909; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0p8U90biBaY98m+/7YTgOwqeSiRSThvzebPVxAHZ0NU=; b=WmHUpH2yFZjPHE4BNisYO/yQPuP/s5M73HULW21qmg584wD2cfy5Chfugn7S3ReoJ1 iDi1yphBInTQO3n2byr59nl6pWAAbvecxe//PPf/XGVwFjO6lvu08DrisFSdQ18lXh3L i5hCA2vWFLJjRyJBOJs0vHuKL1pnYk9rkRu/TGpQRsrWGQ2ai21pZM30PBlSNIvUxhJj R6HjUd9yEBUgeB6H+LplFt1YUN71io1bVGgucL9h/F80rvgOzkCUdZicdHURRehR5kfe fDEEcKCCD9BSwcjiCGwOgL1onq3audR51L1kH1GBcqOmrYmFP+npDyUDGaICbf+IwenR OZVg== X-Gm-Message-State: AOJu0YyyORO3KutCPK7cIAHsych4cag2/n/JcGJx8RQB9WzZYgKwymkq hIY9ORzEQO9Aa+XpGZjqF5Y= X-Google-Smtp-Source: AGHT+IGIdInnubjIeWh18A6utltiooTc5XhoZwMANbo8N+mo1k1GV2zYTk6K/MsLe6Nk9T2xrOWP9w== X-Received: by 2002:a05:6512:3da7:b0:503:38ef:eb54 with SMTP id k39-20020a0565123da700b0050338efeb54mr4177670lfv.37.1695238109286; Wed, 20 Sep 2023 12:28:29 -0700 (PDT) Received: from localhost ([83.149.21.189]) by smtp.gmail.com with ESMTPSA id q26-20020a05651232ba00b0050307bf2bcdsm1933853lfe.247.2023.09.20.12.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:28:28 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 04/18] EDAC/synopsys: Detach private data from mci instance Date: Wed, 20 Sep 2023 22:26:49 +0300 Message-ID: <20230920192806.29960-5-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org A comprehensive DW uMCTL2 DDRC parameters detection procedure and some resources requests (clocks and resets) are about to be added to the driver. Since these parameters will be utilized in the various parts of the driver and in particular used for the Memory Controller data instance pre-initialization, they need to be: first retrieved before the MCI is allocated; second preserved in the driver private data. Therefore the best approach would be to add the parameters structure right into the driver private data and just allocate the data separately from the mem_ctl_info instance. For that: add a new static method snps_data_create(), which aside with the snps_edac_priv structure allocation will also perform the private data basic initialization like CSRs region mapping, device data getting, platform data pointer copying and spin-lock initialization; convert the snps_mc_init() method to snps_mc_create(), which from now will be used to allocate and initialize the mem_ctl_info structure instance. Note in order to have an access to the snps_edac_priv structure instance as before this change, the mem_ctl_info.pvt_info field will be initialized with the pointer to that structure instance. Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 137 +++++++++++++++++++++++------------ 1 file changed, 90 insertions(+), 47 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index e08e9f3c81cb..e177a36646c0 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -242,6 +242,7 @@ struct snps_ecc_status { /** * struct snps_edac_priv - DDR memory controller private data. + * @pdev: Platform device. * @baseaddr: Base address of the DDR controller. * @reglock: Concurrent CSRs access lock. * @message: Buffer for framing the event specific info. @@ -255,6 +256,7 @@ struct snps_ecc_status { * @rank_shift: Bit shifts for rank bit. */ struct snps_edac_priv { + struct platform_device *pdev; void __iomem *baseaddr; spinlock_t reglock; char message[SNPS_EDAC_MSG_SIZE]; @@ -463,6 +465,34 @@ static irqreturn_t snps_irq_handler(int irq, void *dev_id) return IRQ_HANDLED; } +/** + * snps_create_data - Create private data. + * @pdev: platform device. + * + * Return: Private data instance or negative errno. + */ +static struct snps_edac_priv *snps_create_data(struct platform_device *pdev) +{ + struct snps_edac_priv *priv; + + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return ERR_PTR(-ENOMEM); + + priv->baseaddr = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(priv->baseaddr)) + return ERR_CAST(priv->baseaddr); + + priv->p_data = of_device_get_match_data(&pdev->dev); + if (!priv->p_data) + return ERR_PTR(-ENODEV); + + priv->pdev = pdev; + spin_lock_init(&priv->reglock); + + return priv; +} + /** * snps_get_dtype - Return the controller memory width. * @base: DDR memory controller base address. @@ -594,18 +624,36 @@ static void snps_init_csrows(struct mem_ctl_info *mci) } /** - * snps_mc_init - Initialize one driver instance. - * @mci: EDAC memory controller instance. - * @pdev: platform device. + * snps_mc_create - Create and initialize MC instance. + * @priv: DDR memory controller private data. + * + * Allocate the EDAC memory controller descriptor and initialize it + * using the private data info. * - * Perform initialization of the EDAC memory controller instance and - * related driver-private data associated with the memory controller the - * instance is bound to. + * Return: MC data instance or negative errno. */ -static void snps_mc_init(struct mem_ctl_info *mci, struct platform_device *pdev) +static struct mem_ctl_info *snps_mc_create(struct snps_edac_priv *priv) { - mci->pdev = &pdev->dev; - platform_set_drvdata(pdev, mci); + struct edac_mc_layer layers[2]; + struct mem_ctl_info *mci; + + layers[0].type = EDAC_MC_LAYER_CHIP_SELECT; + layers[0].size = SNPS_EDAC_NR_CSROWS; + layers[0].is_virt_csrow = true; + layers[1].type = EDAC_MC_LAYER_CHANNEL; + layers[1].size = SNPS_EDAC_NR_CHANS; + layers[1].is_virt_csrow = false; + + mci = edac_mc_alloc(EDAC_AUTO_MC_NUM, ARRAY_SIZE(layers), layers, 0); + if (!mci) { + edac_printk(KERN_ERR, EDAC_MC, + "Failed memory allocation for mc instance\n"); + return ERR_PTR(-ENOMEM); + } + + mci->pvt_info = priv; + mci->pdev = &priv->pdev->dev; + platform_set_drvdata(priv->pdev, mci); /* Initialize controller capabilities and configuration */ mci->mtype_cap = MEM_FLAG_LPDDR | MEM_FLAG_DDR2 | MEM_FLAG_LPDDR2 | @@ -625,24 +673,43 @@ static void snps_mc_init(struct mem_ctl_info *mci, struct platform_device *pdev) mci->ctl_page_to_phys = NULL; snps_init_csrows(mci); + + return mci; } +/** + * snps_mc_free - Free MC instance. + * @mci: EDAC memory controller instance. + * + * Just revert what was done in the framework of the snps_mc_create(). + * + * Return: MC data instance or negative errno. + */ +static void snps_mc_free(struct mem_ctl_info *mci) +{ + struct snps_edac_priv *priv = mci->pvt_info; + + platform_set_drvdata(priv->pdev, NULL); + edac_mc_free(mci); +} -static int snps_setup_irq(struct mem_ctl_info *mci, struct platform_device *pdev) + + +static int snps_setup_irq(struct mem_ctl_info *mci) { struct snps_edac_priv *priv = mci->pvt_info; int ret, irq; - irq = platform_get_irq(pdev, 0); + irq = platform_get_irq(priv->pdev, 0); if (irq < 0) { edac_printk(KERN_ERR, EDAC_MC, "No IRQ %d in DT\n", irq); return irq; } - ret = devm_request_irq(&pdev->dev, irq, snps_irq_handler, - 0, dev_name(&pdev->dev), mci); + ret = devm_request_irq(&priv->pdev->dev, irq, snps_irq_handler, + 0, dev_name(&priv->pdev->dev), mci); if (ret < 0) { edac_printk(KERN_ERR, EDAC_MC, "Failed to request IRQ\n"); return ret; @@ -1066,49 +1133,24 @@ static inline void snps_create_debugfs_nodes(struct mem_ctl_info *mci) {} */ static int snps_mc_probe(struct platform_device *pdev) { - const struct snps_platform_data *p_data; - struct edac_mc_layer layers[2]; struct snps_edac_priv *priv; struct mem_ctl_info *mci; - void __iomem *baseaddr; int rc; - baseaddr = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(baseaddr)) - return PTR_ERR(baseaddr); - - p_data = of_device_get_match_data(&pdev->dev); - if (!p_data) - return -ENODEV; + priv = snps_create_data(pdev); + if (IS_ERR(priv)) + return PTR_ERR(priv); if (!snps_get_ecc_state(baseaddr)) { edac_printk(KERN_INFO, EDAC_MC, "ECC not enabled\n"); return -ENXIO; } - layers[0].type = EDAC_MC_LAYER_CHIP_SELECT; - layers[0].size = SNPS_EDAC_NR_CSROWS; - layers[0].is_virt_csrow = true; - layers[1].type = EDAC_MC_LAYER_CHANNEL; - layers[1].size = SNPS_EDAC_NR_CHANS; - layers[1].is_virt_csrow = false; - - mci = edac_mc_alloc(EDAC_AUTO_MC_NUM, ARRAY_SIZE(layers), layers, - sizeof(struct snps_edac_priv)); - if (!mci) { - edac_printk(KERN_ERR, EDAC_MC, - "Failed memory allocation for mc instance\n"); - return -ENOMEM; - } - - priv = mci->pvt_info; - priv->baseaddr = baseaddr; - priv->p_data = p_data; - spin_lock_init(&priv->reglock); + mci = snps_mc_create(priv); + if (IS_ERR(mci)) + return PTR_ERR(mci); - snps_mc_init(mci, pdev); - - rc = snps_setup_irq(mci, pdev); + rc = snps_setup_irq(mci); if (rc) goto free_edac_mc; @@ -1124,7 +1166,7 @@ static int snps_mc_probe(struct platform_device *pdev) return 0; free_edac_mc: - edac_mc_free(mci); + snps_mc_free(mci); return rc; } @@ -1143,7 +1185,8 @@ static int snps_mc_remove(struct platform_device *pdev) snps_disable_irq(priv); edac_mc_del_mc(&pdev->dev); - edac_mc_free(mci); + + snps_mc_free(mci); return 0; } From patchwork Wed Sep 20 19:26:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393322 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E39FBC04FEE for ; Wed, 20 Sep 2023 19:28:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230158AbjITT2z (ORCPT ); Wed, 20 Sep 2023 15:28:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230161AbjITT2v (ORCPT ); Wed, 20 Sep 2023 15:28:51 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3BB6182; Wed, 20 Sep 2023 12:28:35 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2c00c0f11b2so2598101fa.1; Wed, 20 Sep 2023 12:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238113; x=1695842913; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FcE22L1gZlo+3hTGWgJEFMaEq2Hv0fi5fdl2Fwo2OJ8=; b=X1ZyVkZyMtshuDAhuknVrGLMXBwDrm2c5bj3aimVSzDvfNgOLxsROxYtujbShr1DYp 6TuPO462BggEfiP5QPS++Un0MU8Gun1TGVOH/oX8cMoNvPWRdpFe2kKeYWB5IfvLf6gi FRKU5T8gUmHU81MLpOnrU4C9oTyvRSjX0F7wYK9il7d1UmNr7A6sWNlhMNdEbjq6tTZK F5EdN/aDLKoGNjlMNnXcHosLgM4qLS7Ms31N+Y7itJ+8xuAwceEIlFTFIsf+z0APNp9s QiAbzVbixxgxWxX63h5uW+pJ0h1Hq4cdifeRzUqOIfB7Qngkw4Ffj5WNfwUotuzNmaWU Ahjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238113; x=1695842913; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FcE22L1gZlo+3hTGWgJEFMaEq2Hv0fi5fdl2Fwo2OJ8=; b=Fr6d+oiQ0G3jtvfMtmXjAUWDDVNU+pO5rGgSy5GAuA7cW61Hsmo5mQMBCym20xSz2l KpPt9IAgrBI5RzajEkJTQENKO9N/tyS/ukNYaAr1HZjHcwUUiowRctYacQ+iBrU+Xf4L B2KWzs78w6Jt7GFXvzRbDqZThYabF9DH//wUjrD014J0DnGmg67Rtt4ylAub9Ywp6Lk0 FgCkYvBuKG7d6meYIQc9mKXxTO3kHoqPlrjRyql6Zbz534tcn6Jl6B0jZWX6fAlZPp1R EWCXnKhocwjcf6hPJEou49rypUF1wZ7Q/013n5OVwcccZRwp9NHjlKjXseApSkdNcTz1 l9gQ== X-Gm-Message-State: AOJu0Yx0C5E1D31zZNDe5BeXa1cwdc3EJutQwZdz7pTAcxMIBC1MPivj Ax4RN0GyAppfNJKk7d+Wjlw= X-Google-Smtp-Source: AGHT+IGiKZmJrEyWUj9IUt/0uAtjUF2FJ30VYmmzKUPIOz+867IhCz6JlP56yZK2hIC7esXYv4AdjQ== X-Received: by 2002:a2e:90d5:0:b0:2bf:ff17:811b with SMTP id o21-20020a2e90d5000000b002bfff17811bmr2917213ljg.3.1695238113260; Wed, 20 Sep 2023 12:28:33 -0700 (PDT) Received: from localhost ([178.176.83.40]) by smtp.gmail.com with ESMTPSA id x18-20020a2e9c92000000b002b6cb25e3f1sm3065569lji.108.2023.09.20.12.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:28:32 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 05/18] EDAC/synopsys: Add DDRC basic parameters infrastructure Date: Wed, 20 Sep 2023 22:26:50 +0300 Message-ID: <20230920192806.29960-6-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Currently the driver supports a single DW uMCTL2 DDRC IP-core: 64-bit DQ bus, ECC SEC/DED with always on Scrub (HW-src scrub). This makes the driver application being very limited. In addition to that lacking of any controller capabilities/parameters infrastructure makes it harder to add optional features support. Let's overcome all of that by adding a simple DW uMCTL2 DDRC IP-core parameters infrastructure. It's made of the snps_ddrc_info structure and a new method snps_get_ddrc_info() introduced to fill the structure fields in. The structure contains the IP-core parameters needed to create a more comprehensive driver and will be used in the driver to activate/de-activate various features: - ECC Mode: SEC/DED or Advanced X4/X8 ECC features. (Currently SEC/DED is only supported.) - SDRAM mode: (LP)DDR[2-4] memory interfaces. (Required for the HIF/SDRAM address translation.) - Memory Device config: Memory chips detected on the platform. (Applicable for DDR4 setups only.) - DQ-bus width: Maximal DQ-bus width utilized by the device. (Required for the Application/HIF address translation.) - DQ-bus mode: Actual DQ-bus width used to access the memory devices. (Required for the HIF/SDRAM address translation and ECC grain calc.) - HIF/SDRAM burst length. (Required for the Scrubber bandwidth calculation.) - HIF/SDRAM frequency ratio. (Required for the SDRAM bandwidth calculation.) - SDRAM ranks number. (Required for the Application/HIF address translation.) The list can be easily updated should any additional features support is required to be added in future, but at this stage the driver is fixed in a few places to have the new infrastructure utilized: SDRAM column address mapper, MCI csrows initialization. Note getting all of these parameters in a single method is very suitable from two perspectives. First it localizes the IP-core parameters detection thus improving the code readability and maintainability. Second it's very suitable for the platform-specific quirks implementation. Since some of the IP-core parameters can't be auto-detected at run-time, they will be able to be fixed right in the parameters getter by means of the platform quirks. Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 268 +++++++++++++++++++++++++++-------- 1 file changed, 211 insertions(+), 57 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index e177a36646c0..b830e4b4292d 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -87,6 +88,11 @@ /* DDR Software Control Register */ #define DDR_SWCTL 0x320 +/* ECC Poison Pattern Registers */ +#define ECC_POISONPAT0_OFST 0x37C +#define ECC_POISONPAT1_OFST 0x380 +#define ECC_POISONPAT2_OFST 0x384 + /* ZynqMP DDR QOS Registers */ #define ZYNQMP_DDR_QOS_IRQ_STAT_OFST 0x20200 #define ZYNQMP_DDR_QOS_IRQ_EN_OFST 0x20208 @@ -98,10 +104,10 @@ #define DDR_MSTR_DEV_X8 1 #define DDR_MSTR_DEV_X16 2 #define DDR_MSTR_DEV_X32 3 +#define DDR_MSTR_ACT_RANKS_MASK GENMASK(27, 24) +#define DDR_MSTR_FREQ_RATIO11 BIT(22) +#define DDR_MSTR_BURST_RDWR GENMASK(19, 16) #define DDR_MSTR_BUSWIDTH_MASK GENMASK(13, 12) -#define DDR_MSTR_BUSWIDTH_16 2 -#define DDR_MSTR_BUSWIDTH_32 1 -#define DDR_MSTR_BUSWIDTH_64 0 #define DDR_MSTR_MEM_MASK GENMASK(5, 0) #define DDR_MSTR_MEM_LPDDR4 BIT(5) #define DDR_MSTR_MEM_DDR4 BIT(4) @@ -113,7 +119,6 @@ /* ECC CFG0 register definitions */ #define ECC_CFG0_MODE_MASK GENMASK(2, 0) -#define ECC_CFG0_MODE_SECDED 0x4 /* ECC status register definitions */ #define ECC_STAT_UE_MASK GENMASK(23, 16) @@ -208,6 +213,91 @@ #define ZYNQMP_DDR_QOS_CE_MASK BIT(1) #define ZYNQMP_DDR_QOS_IRQ_MASK (ZYNQMP_DDR_QOS_UE_MASK | ZYNQMP_DDR_QOS_CE_MASK) +/** + * enum snps_dq_width - SDRAM DQ bus width (ECC capable). + * SNPS_DQ_32: 32-bit memory data width. + * SNPS_DQ_64: 64-bit memory data width. + */ +enum snps_dq_width { + SNPS_DQ_32 = 2, + SNPS_DQ_64 = 3, +}; + +/** + * enum snps_dq_mode - SDRAM DQ bus mode. + * @SNPS_DQ_FULL: Full DQ bus width. + * @SNPS_DQ_HALF: Half DQ bus width. + * @SNPS_DQ_QRTR: Quarter DQ bus width. + */ +enum snps_dq_mode { + SNPS_DQ_FULL = 0, + SNPS_DQ_HALF = 1, + SNPS_DQ_QRTR = 2, +}; + +/** + * enum snps_burst_length - HIF/SDRAM burst transactions length. + * @SNPS_DDR_BL2: Burst length 2xSDRAM-words. + * @SNPS_DDR_BL4: Burst length 4xSDRAM-words. + * @SNPS_DDR_BL8: Burst length 8xSDRAM-words. + * @SNPS_DDR_BL16: Burst length 16xSDRAM-words. + */ +enum snps_burst_length { + SNPS_DDR_BL2 = 2, + SNPS_DDR_BL4 = 4, + SNPS_DDR_BL8 = 8, + SNPS_DDR_BL16 = 16, +}; + +/** + * enum snps_freq_ratio - HIF:SDRAM frequency ratio mode. + * @SNPS_FREQ_RATIO11: 1:1 frequency mode. + * @SNPS_FREQ_RATIO12: 1:2 frequency mode. + */ +enum snps_freq_ratio { + SNPS_FREQ_RATIO11 = 1, + SNPS_FREQ_RATIO12 = 2, +}; + +/** + * enum snps_ecc_mode - ECC mode. + * @SNPS_ECC_DISABLED: ECC is disabled/unavailable. + * @SNPS_ECC_SECDED: SEC/DED over 1 beat ECC (SideBand/Inline). + * @SNPS_ECC_ADVX4X8: Advanced ECC X4/X8 (SideBand). + */ +enum snps_ecc_mode { + SNPS_ECC_DISABLED = 0, + SNPS_ECC_SECDED = 4, + SNPS_ECC_ADVX4X8 = 5, +}; + +/** + * struct snps_ddrc_info - DDR controller platform parameters. + * @caps: DDR controller capabilities. + * @sdram_mode: Current SDRAM mode selected. + * @dev_cfg: Current memory device config (if applicable). + * @dq_width: Memory data bus width (width of the DQ signals + * connected to SDRAM chips). + * @dq_mode: Proportion of the DQ bus utilized to access SDRAM. + * @sdram_burst_len: SDRAM burst transaction length. + * @hif_burst_len: HIF burst transaction length (Host Interface). + * @freq_ratio: HIF/SDRAM frequency ratio mode. + * @ecc_mode: ECC mode enabled for the DDR controller (SEC/DED, etc). + * @ranks: Number of ranks enabled to access DIMM (1, 2 or 4). + */ +struct snps_ddrc_info { + unsigned int caps; + enum mem_type sdram_mode; + enum dev_type dev_cfg; + enum snps_dq_width dq_width; + enum snps_dq_mode dq_mode; + enum snps_burst_length sdram_burst_len; + enum snps_burst_length hif_burst_len; + enum snps_freq_ratio freq_ratio; + enum snps_ecc_mode ecc_mode; + unsigned int ranks; +}; + /** * struct snps_ecc_error_info - ECC error log information. * @row: Row number. @@ -242,6 +332,7 @@ struct snps_ecc_status { /** * struct snps_edac_priv - DDR memory controller private data. + * @info: DDR controller config info. * @pdev: Platform device. * @baseaddr: Base address of the DDR controller. * @reglock: Concurrent CSRs access lock. @@ -256,6 +347,7 @@ struct snps_ecc_status { * @rank_shift: Bit shifts for rank bit. */ struct snps_edac_priv { + struct snps_ddrc_info info; struct platform_device *pdev; void __iomem *baseaddr; spinlock_t reglock; @@ -495,23 +587,19 @@ static struct snps_edac_priv *snps_create_data(struct platform_device *pdev) /** * snps_get_dtype - Return the controller memory width. - * @base: DDR memory controller base address. + * @mstr: Master CSR value. * * Get the EDAC device type width appropriate for the current controller * configuration. * * Return: a device type width enumeration. */ -static enum dev_type snps_get_dtype(const void __iomem *base) +static inline enum dev_type snps_get_dtype(u32 mstr) { - u32 regval; - - regval = readl(base + DDR_MSTR_OFST); - if (!(regval & DDR_MSTR_MEM_DDR4)) + if (!(mstr & DDR_MSTR_MEM_DDR4)) return DEV_UNKNOWN; - regval = FIELD_GET(DDR_MSTR_DEV_CFG_MASK, regval); - switch (regval) { + switch (FIELD_GET(DDR_MSTR_DEV_CFG_MASK, mstr)) { case DDR_MSTR_DEV_X4: return DEV_X4; case DDR_MSTR_DEV_X8: @@ -525,24 +613,6 @@ static enum dev_type snps_get_dtype(const void __iomem *base) return DEV_UNKNOWN; } -/** - * snps_get_ecc_state - Return the controller ECC enable/disable status. - * @base: DDR memory controller base address. - * - * Get the ECC enable/disable status for the controller. - * - * Return: a ECC status boolean i.e true/false - enabled/disabled. - */ -static bool snps_get_ecc_state(void __iomem *base) -{ - u32 regval; - - regval = readl(base + ECC_CFG0_OFST); - regval = FIELD_GET(ECC_CFG0_MODE_MASK, regval); - - return (regval == ECC_CFG0_MODE_SECDED); -} - /** * snps_get_memsize - Read the size of the attached memory device. * @@ -559,21 +629,16 @@ static u32 snps_get_memsize(void) /** * snps_get_mtype - Returns controller memory type. - * @base: Synopsys ECC status structure. + * @mstr: Master CSR value. * * Get the EDAC memory type appropriate for the current controller * configuration. * * Return: a memory type enumeration. */ -static enum mem_type snps_get_mtype(const void __iomem *base) +static inline enum mem_type snps_get_mtype(u32 mstr) { - u32 regval; - - regval = readl(base + DDR_MSTR_OFST); - regval = FIELD_GET(DDR_MSTR_MEM_MASK, regval); - - switch (regval) { + switch (FIELD_GET(DDR_MSTR_MEM_MASK, mstr)) { case DDR_MSTR_MEM_DDR2: return MEM_DDR2; case DDR_MSTR_MEM_DDR3: @@ -593,6 +658,69 @@ static enum mem_type snps_get_mtype(const void __iomem *base) return MEM_RESERVED; } +/** + * snps_get_ddrc_info - Get the DDR controller config data. + * @priv: DDR memory controller private data. + * + * Return: negative errno if no ECC detected, otherwise - zero. + */ +static int snps_get_ddrc_info(struct snps_edac_priv *priv) +{ + int (*init_plat)(struct snps_edac_priv *priv); + u32 regval; + + /* Before getting the DDRC parameters make sure ECC is enabled */ + regval = readl(priv->baseaddr + ECC_CFG0_OFST); + + priv->info.ecc_mode = FIELD_GET(ECC_CFG0_MODE_MASK, regval); + if (priv->info.ecc_mode != SNPS_ECC_SECDED) { + edac_printk(KERN_INFO, EDAC_MC, "SEC/DED ECC not enabled\n"); + return -ENXIO; + } + + /* Auto-detect the basic HIF/SDRAM bus parameters */ + regval = readl(priv->baseaddr + DDR_MSTR_OFST); + + priv->info.sdram_mode = snps_get_mtype(regval); + priv->info.dev_cfg = snps_get_dtype(regval); + + priv->info.dq_mode = FIELD_GET(DDR_MSTR_BUSWIDTH_MASK, regval); + + /* + * Assume HIF burst length matches the SDRAM burst length since it's + * not auto-detectable + */ + priv->info.sdram_burst_len = FIELD_GET(DDR_MSTR_BURST_RDWR, regval) << 1; + priv->info.hif_burst_len = priv->info.sdram_burst_len; + + /* Retrieve the current HIF/SDRAM frequency ratio: 1:1 vs 1:2 */ + priv->info.freq_ratio = !(regval & DDR_MSTR_FREQ_RATIO11) + 1; + + /* Activated ranks field: set bit corresponds to populated rank */ + priv->info.ranks = FIELD_GET(DDR_MSTR_ACT_RANKS_MASK, regval); + priv->info.ranks = hweight_long(priv->info.ranks); + + /* Auto-detect the DQ bus width by using the ECC-poison pattern CSR */ + writel(0, priv->baseaddr + DDR_SWCTL); + + /* + * If poison pattern [32:64] is changeable then DQ is 64-bit wide. + * Note the feature has been available since IP-core v2.51a. + */ + regval = readl(priv->baseaddr + ECC_POISONPAT1_OFST); + writel(~regval, priv->baseaddr + ECC_POISONPAT1_OFST); + if (regval != readl(priv->baseaddr + ECC_POISONPAT1_OFST)) { + priv->info.dq_width = SNPS_DQ_64; + writel(regval, priv->baseaddr + ECC_POISONPAT1_OFST); + } else { + priv->info.dq_width = SNPS_DQ_32; + } + + writel(1, priv->baseaddr + DDR_SWCTL); + + return 0; +} + /** * snps_init_csrows - Initialize the csrow data. * @mci: EDAC memory controller instance. @@ -615,10 +743,10 @@ static void snps_init_csrows(struct mem_ctl_info *mci) for (j = 0; j < csi->nr_channels; j++) { dimm = csi->channels[j]->dimm; dimm->edac_mode = EDAC_SECDED; - dimm->mtype = snps_get_mtype(priv->baseaddr); + dimm->mtype = priv->info.sdram_mode; dimm->nr_pages = (size >> PAGE_SHIFT) / csi->nr_channels; dimm->grain = SNPS_EDAC_ERR_GRAIN; - dimm->dtype = snps_get_dtype(priv->baseaddr); + dimm->dtype = priv->info.dev_cfg; } } } @@ -732,6 +860,33 @@ static int snps_setup_irq(struct mem_ctl_info *mci) #define SNPS_DBGFS_BUF_LEN 128 +static int snps_ddrc_info_show(struct seq_file *s, void *data) +{ + struct mem_ctl_info *mci = s->private; + struct snps_edac_priv *priv = mci->pvt_info; + + seq_printf(s, "SDRAM: %s\n", edac_mem_types[priv->info.sdram_mode]); + + seq_printf(s, "DQ bus: %u/%s\n", (BITS_PER_BYTE << priv->info.dq_width), + priv->info.dq_mode == SNPS_DQ_FULL ? "Full" : + priv->info.dq_mode == SNPS_DQ_HALF ? "Half" : + priv->info.dq_mode == SNPS_DQ_QRTR ? "Quarter" : + "Unknown"); + seq_printf(s, "Burst: SDRAM %u HIF %u\n", priv->info.sdram_burst_len, + priv->info.hif_burst_len); + + seq_printf(s, "Ranks: %u\n", priv->info.ranks); + + seq_printf(s, "ECC: %s\n", + priv->info.ecc_mode == SNPS_ECC_SECDED ? "SEC/DED" : + priv->info.ecc_mode == SNPS_ECC_ADVX4X8 ? "Advanced X4/X8" : + "Unknown"); + + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(snps_ddrc_info); + /** * snps_data_poison_setup - Update poison registers. * @priv: DDR memory controller private instance data. @@ -853,12 +1008,8 @@ static void snps_setup_row_address_map(struct snps_edac_priv *priv, u32 *addrmap static void snps_setup_column_address_map(struct snps_edac_priv *priv, u32 *addrmap) { - u32 width, memtype; int index; - memtype = readl(priv->baseaddr + DDR_MSTR_OFST); - width = FIELD_GET(DDR_MSTR_BUSWIDTH_MASK, memtype); - priv->col_shift[0] = 0; priv->col_shift[1] = 1; priv->col_shift[2] = (addrmap[2] & COL_MAX_VAL_MASK) + COL_B2_BASE; @@ -882,8 +1033,8 @@ static void snps_setup_column_address_map(struct snps_edac_priv *priv, u32 *addr priv->col_shift[9] = (((addrmap[3] >> 24) & COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : (((addrmap[3] >> 24) & COL_MAX_VAL_MASK) + COL_B9_BASE); - if (width == DDR_MSTR_BUSWIDTH_64) { - if (memtype & DDR_MSTR_MEM_LPDDR3) { + if (priv->info.dq_mode == SNPS_DQ_FULL) { + if (priv->info.sdram_mode == MEM_LPDDR3) { priv->col_shift[10] = ((addrmap[4] & COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : ((addrmap[4] & COL_MAX_VAL_MASK) + @@ -902,8 +1053,8 @@ static void snps_setup_column_address_map(struct snps_edac_priv *priv, u32 *addr (((addrmap[4] >> 8) & COL_MAX_VAL_MASK) + COL_B11_BASE); } - } else if (width == DDR_MSTR_BUSWIDTH_32) { - if (memtype & DDR_MSTR_MEM_LPDDR3) { + } else if (priv->info.dq_mode == SNPS_DQ_HALF) { + if (priv->info.sdram_mode == MEM_LPDDR3) { priv->col_shift[10] = (((addrmap[3] >> 24) & COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : (((addrmap[3] >> 24) & COL_MAX_VAL_MASK) + @@ -923,7 +1074,7 @@ static void snps_setup_column_address_map(struct snps_edac_priv *priv, u32 *addr COL_B10_BASE); } } else { - if (memtype & DDR_MSTR_MEM_LPDDR3) { + if (priv->info.sdram_mode == MEM_LPDDR3) { priv->col_shift[10] = (((addrmap[3] >> 16) & COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : (((addrmap[3] >> 16) & COL_MAX_VAL_MASK) + @@ -944,10 +1095,11 @@ static void snps_setup_column_address_map(struct snps_edac_priv *priv, u32 *addr } } - if (width) { - for (index = 9; index > width; index--) { - priv->col_shift[index] = priv->col_shift[index - width]; - priv->col_shift[index - width] = 0; + if (priv->info.dq_mode) { + for (index = 9; index > priv->info.dq_mode; index--) { + priv->col_shift[index] = + priv->col_shift[index - priv->info.dq_mode]; + priv->col_shift[index - priv->info.dq_mode] = 0; } } @@ -1109,6 +1261,9 @@ static void snps_create_debugfs_nodes(struct mem_ctl_info *mci) snps_setup_address_map(priv); + edac_debugfs_create_file("ddrc_info", 0400, mci->debugfs, mci, + &snps_ddrc_info_fops); + edac_debugfs_create_file("inject_data_error", 0600, mci->debugfs, mci, &snps_inject_data_error); @@ -1141,10 +1296,9 @@ static int snps_mc_probe(struct platform_device *pdev) if (IS_ERR(priv)) return PTR_ERR(priv); - if (!snps_get_ecc_state(baseaddr)) { - edac_printk(KERN_INFO, EDAC_MC, "ECC not enabled\n"); - return -ENXIO; - } + rc = snps_get_ddrc_info(priv); + if (rc) + return rc; mci = snps_mc_create(priv); if (IS_ERR(mci)) From patchwork Wed Sep 20 19:26:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393323 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BFFFC04FF5 for ; Wed, 20 Sep 2023 19:28:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230036AbjITT25 (ORCPT ); Wed, 20 Sep 2023 15:28:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230086AbjITT2w (ORCPT ); Wed, 20 Sep 2023 15:28:52 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12F72DC; Wed, 20 Sep 2023 12:28:38 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-503012f4e71so1568236e87.0; Wed, 20 Sep 2023 12:28:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238116; x=1695842916; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AdGvtIhnrYM49qOF0XUq1B70UdgD51RskmRPZFchMpY=; b=FBt9uxSi91J33FLj5glMQTZgds5i3ryEoDg4Xl57+ubzdKGL7/3C3+P19ty+qzCHrY XAS7Yln49MYlKGaoGxKmc+fjJbUkhbq818tm9Sskh62tPtv4bxIwO7QE7STeGpW82kNG 1f9oWOeU4DWqQidERbrkYhKQ+EjLhCBgPjTRgc9jvHsZgmFZcGbtNIahAX4wSL6EMWNg hgE4dG3RijF8wcJhKr6XzRQ2HCvlI5x1okZnq8g7BXRQClAGhzH7s3P8b98E5+ja3n/b GlYUP9OUJqn0G15oUHTxRVhPgO7mq2Fovv5CRRy6k2BEcjGnPnnAY0CN8KL4NZjDGkH9 uRag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238116; x=1695842916; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AdGvtIhnrYM49qOF0XUq1B70UdgD51RskmRPZFchMpY=; b=szeJF7nu3CrGcmjKF3nrTzWw/rkiQG156MkM46i2y1vWbb2ObFccJRSre17oBMCEjw 2NJxIKWVBWaADv7pEZD9ImS0hrdEutq1x5yCjgSEh8w15IfTWj4m1io5lTk6OMyI6ixp JrcHwCb95mikApFTZZoCC/7BFE02fTGHsrWzUTrSay/dxp5/Bu0a8QPvZL5Vh21ESLuM Ug6AG8iqPrxRL5Nskvd1GbPuHF85LFMr51KKZxo21TCRpCj9Gr1L5FGYhN2fo3+ArSBg glrccTpHCbN/jgKmwu/SFMSCSvY1tEZdG9xcrVQKFW0+c7v1aFjcNsYXAPDBR5+HfucQ CjiA== X-Gm-Message-State: AOJu0Yw5A/VhRdRGJsERO6VYGlK94d9Q6qNzDwtp5fKiDqlcUYMuuufI hAAC/UPO4wx3afH/2E2dVko= X-Google-Smtp-Source: AGHT+IGvY2WjckLrqKF2TZ5J4zmwaRfWiTj3OXCSDcx1z66FZOZ2M7wBbipUU8euAtyWN4c2zI6iZQ== X-Received: by 2002:a05:6512:3d29:b0:502:d973:3206 with SMTP id d41-20020a0565123d2900b00502d9733206mr3053467lfv.6.1695238116092; Wed, 20 Sep 2023 12:28:36 -0700 (PDT) Received: from localhost ([85.140.0.70]) by smtp.gmail.com with ESMTPSA id p21-20020a19f015000000b00500a14a6659sm2769277lfc.51.2023.09.20.12.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:28:35 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 06/18] EDAC/synopsys: Convert plat-data to plat-init function Date: Wed, 20 Sep 2023 22:26:51 +0300 Message-ID: <20230920192806.29960-7-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Since DW uMCTL2 device info and capabilities infrastructure is now available there is no point in supporting an additional abstraction like platform quirks. Instead convert the already defined ZynqMP quirk to the ZynqMP-specific capability and add the platform-specific initialization function support. This function will be called after the device parameters are detected and thus fixing some of them if required. Note the new approach will provide a very flexible interface of the platform-specific setups. The platform-specific init() callback can be used not only for the capabilities flags modification, but for example for the resources requests or custom CSRs alterations. Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 68 +++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index b830e4b4292d..b77bc84c0bb0 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -34,8 +34,8 @@ #define SNPS_EDAC_MOD_STRING "snps_edac" #define SNPS_EDAC_MOD_VER "1" -/* DDR ECC Quirks */ -#define SNPS_ZYNQMP_IRQ_REGS BIT(0) +/* DDR capabilities */ +#define SNPS_CAP_ZYNQMP BIT(31) /* Synopsys uMCTL2 DDR controller registers that are relevant to ECC */ @@ -338,7 +338,6 @@ struct snps_ecc_status { * @reglock: Concurrent CSRs access lock. * @message: Buffer for framing the event specific info. * @stat: ECC status information. - * @p_data: Platform data. * @poison_addr: Data poison address. * @row_shift: Bit shifts for row bit. * @col_shift: Bit shifts for column bit. @@ -353,7 +352,6 @@ struct snps_edac_priv { spinlock_t reglock; char message[SNPS_EDAC_MSG_SIZE]; struct snps_ecc_status stat; - const struct snps_platform_data *p_data; #ifdef CONFIG_EDAC_DEBUG ulong poison_addr; u32 row_shift[18]; @@ -364,14 +362,6 @@ struct snps_edac_priv { #endif }; -/** - * struct snps_platform_data - Synopsys uMCTL2 DDRC platform data. - * @quirks: IP-core specific quirks. - */ -struct snps_platform_data { - u32 quirks; -}; - /** * snps_get_error_info - Get the current ECC error info. * @priv: DDR memory controller private instance data. @@ -485,7 +475,7 @@ static void snps_enable_irq(struct snps_edac_priv *priv) unsigned long flags; /* Enable UE/CE Interrupts */ - if (priv->p_data->quirks & SNPS_ZYNQMP_IRQ_REGS) { + if (priv->info.caps & SNPS_CAP_ZYNQMP) { writel(ZYNQMP_DDR_QOS_UE_MASK | ZYNQMP_DDR_QOS_CE_MASK, priv->baseaddr + ZYNQMP_DDR_QOS_IRQ_EN_OFST); @@ -509,7 +499,7 @@ static void snps_disable_irq(struct snps_edac_priv *priv) unsigned long flags; /* Disable UE/CE Interrupts */ - if (priv->p_data->quirks & SNPS_ZYNQMP_IRQ_REGS) { + if (priv->info.caps & SNPS_CAP_ZYNQMP) { writel(ZYNQMP_DDR_QOS_UE_MASK | ZYNQMP_DDR_QOS_CE_MASK, priv->baseaddr + ZYNQMP_DDR_QOS_IRQ_DB_OFST); @@ -538,7 +528,7 @@ static irqreturn_t snps_irq_handler(int irq, void *dev_id) priv = mci->pvt_info; - if (priv->p_data->quirks & SNPS_ZYNQMP_IRQ_REGS) { + if (priv->info.caps & SNPS_CAP_ZYNQMP) { regval = readl(priv->baseaddr + ZYNQMP_DDR_QOS_IRQ_STAT_OFST); regval &= (ZYNQMP_DDR_QOS_CE_MASK | ZYNQMP_DDR_QOS_UE_MASK); if (!(regval & ZYNQMP_DDR_QOS_IRQ_MASK)) @@ -551,7 +541,7 @@ static irqreturn_t snps_irq_handler(int irq, void *dev_id) snps_handle_error(mci, &priv->stat); - if (priv->p_data->quirks & SNPS_ZYNQMP_IRQ_REGS) + if (priv->info.caps & SNPS_CAP_ZYNQMP) writel(regval, priv->baseaddr + ZYNQMP_DDR_QOS_IRQ_STAT_OFST); return IRQ_HANDLED; @@ -575,16 +565,26 @@ static struct snps_edac_priv *snps_create_data(struct platform_device *pdev) if (IS_ERR(priv->baseaddr)) return ERR_CAST(priv->baseaddr); - priv->p_data = of_device_get_match_data(&pdev->dev); - if (!priv->p_data) - return ERR_PTR(-ENODEV); - priv->pdev = pdev; spin_lock_init(&priv->reglock); return priv; } +/* + * zynqmp_init_plat - ZynqMP-specific platform initialization. + * @priv: DDR memory controller private data. + * + * Return: always zero. + */ +static int zynqmp_init_plat(struct snps_edac_priv *priv) +{ + priv->info.caps |= SNPS_CAP_ZYNQMP; + priv->info.dq_width = SNPS_DQ_64; + + return 0; +} + /** * snps_get_dtype - Return the controller memory width. * @mstr: Master CSR value. @@ -718,7 +718,10 @@ static int snps_get_ddrc_info(struct snps_edac_priv *priv) writel(1, priv->baseaddr + DDR_SWCTL); - return 0; + /* Apply platform setups after all the configs auto-detection */ + init_plat = device_get_match_data(&priv->pdev->dev); + + return init_plat ? init_plat(priv) : 0; } /** @@ -822,8 +825,6 @@ static void snps_mc_free(struct mem_ctl_info *mci) edac_mc_free(mci); } - - static int snps_setup_irq(struct mem_ctl_info *mci) { struct snps_edac_priv *priv = mci->pvt_info; @@ -882,6 +883,15 @@ static int snps_ddrc_info_show(struct seq_file *s, void *data) priv->info.ecc_mode == SNPS_ECC_ADVX4X8 ? "Advanced X4/X8" : "Unknown"); + seq_puts(s, "Caps:"); + if (priv->info.caps) { + if (priv->info.caps & SNPS_CAP_ZYNQMP) + seq_puts(s, " +ZynqMP"); + } else { + seq_puts(s, " -"); + } + seq_putc(s, '\n'); + return 0; } @@ -1345,17 +1355,9 @@ static int snps_mc_remove(struct platform_device *pdev) return 0; } -static const struct snps_platform_data zynqmp_edac_def = { - .quirks = SNPS_ZYNQMP_IRQ_REGS, -}; - -static const struct snps_platform_data snps_edac_def = { - .quirks = 0, -}; - static const struct of_device_id snps_edac_match[] = { - { .compatible = "xlnx,zynqmp-ddrc-2.40a", .data = &zynqmp_edac_def }, - { .compatible = "snps,ddrc-3.80a", .data = &snps_edac_def }, + { .compatible = "xlnx,zynqmp-ddrc-2.40a", .data = zynqmp_init_plat }, + { .compatible = "snps,ddrc-3.80a" }, { } }; MODULE_DEVICE_TABLE(of, snps_edac_match); From patchwork Wed Sep 20 19:26:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393324 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93EAAC04FEE for ; Wed, 20 Sep 2023 19:29:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230096AbjITT3I (ORCPT ); Wed, 20 Sep 2023 15:29:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230090AbjITT2y (ORCPT ); Wed, 20 Sep 2023 15:28:54 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BD9E1A5; Wed, 20 Sep 2023 12:28:45 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-500cfb168c6so371944e87.2; Wed, 20 Sep 2023 12:28:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238123; x=1695842923; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9BUlFc32U67LJr2U7BzHv473MxaTEfZQ+YLInYVLVj8=; b=G4j6I0PEtmkd/FLWjBLSJKg6Uuxtf/S9Losx6B2SdamqsmGTzr1tHFoDUxfyUY3cJm me3PddC58J1/UI8FxHS6DPa0wnTSveOjva4W9VW8mbGkR+4ysct1U+Ze1k0IZiImWlyU dh5kWVx4cPqZZ+dv1AW11+wpw279/INJc0kDxKPhLE2CjnfmljWglf6MNwBirgxg96fU BaJtfaBQ7ECFRWUwTrvgYejOk6QPWgUpcsvwG8xSCx6JKrdOi0kLbMMUYaapny1G/R7A oX1WtiqNvyxCB5wdcm69KztPCK4adr4qaGuHqp4sNgM0ems85pBslctZXLh+1dHQ0qhF qwCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238123; x=1695842923; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9BUlFc32U67LJr2U7BzHv473MxaTEfZQ+YLInYVLVj8=; b=a2pzXqTAVm5psBTrPVjuoVjH/Tg8R5kUDMdRUAMnlhUnMq0EjJML8l8Jp7eNlnDoMV bRw7LLHAuFxkqgrQqRUMkHqHgZG0bV+ODHYLwJJ/a8GpXH6hle6MjaprLDAi3sc8Tv/C yxKng5kjkHTgB7984FpZLaY9mOiZQlLOgmwovpCumNyXO7poSDAz/9mt5PzSFpdmymMX awdpMemLpGmdPWOMdQ5+0w2jPmXrM4jnSsGt3vx0tErqTAotEBDKe8IJTYUtIsnlqfkQ 9uZxRJjo2O80KDSX1bDV5RERVoYgfLMwypkcAaGGngf4CI5XjIO9LPbsS6H7mUZSLLfF wclw== X-Gm-Message-State: AOJu0YzfpBduH5HTxh8DSJ+/v7+kreOD31tDpHhbmx6vgPQRlB5D+Kc9 Q5DD/ISsONDH7/2HbuGeYR8xtcnC0Xg= X-Google-Smtp-Source: AGHT+IFYNvADX+pg8J040J7aG80SLXnN5ERc9qA5f7ctLC5xfL2gP5i7P26Ct9T5OB35Yi6y+G1VvQ== X-Received: by 2002:a19:384b:0:b0:4fd:c715:5667 with SMTP id d11-20020a19384b000000b004fdc7155667mr2480908lfj.20.1695238123500; Wed, 20 Sep 2023 12:28:43 -0700 (PDT) Received: from localhost ([178.176.82.53]) by smtp.gmail.com with ESMTPSA id d5-20020ac241c5000000b004fe28e3841bsm2793757lfi.267.2023.09.20.12.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:28:42 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 07/18] EDAC/synopsys: Parse ADDRMAP[7-8] CSRs for (LP)DDR4 only Date: Wed, 20 Sep 2023 22:26:52 +0300 Message-ID: <20230920192806.29960-8-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org These CSRs contain the SDRAM Bank Groups and row[16]/row[17] bits mapping, which are applicable for the DDR4 and LPDDR4 memory chips only. For the rest of the memories the ADDRMAP[7-8] registers are unused by the controller and are zeros by default. The zero values will be perceived by the HIF/SDRAM mapping detection procedure as normal bit positions, which is wrong. So in order to prevent that parse these registers only if they are applicable for the detected DDR protocol. Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index b77bc84c0bb0..5a06038aedcb 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -1008,12 +1008,15 @@ static void snps_setup_row_address_map(struct snps_edac_priv *priv, u32 *addrmap priv->row_shift[15] = (((addrmap[6] >> 24) & ROW_MAX_VAL_MASK) == ROW_MAX_VAL_MASK) ? 0 : (((addrmap[6] >> 24) & ROW_MAX_VAL_MASK) + ROW_B15_BASE); - priv->row_shift[16] = ((addrmap[7] & ROW_MAX_VAL_MASK) == - ROW_MAX_VAL_MASK) ? 0 : ((addrmap[7] & - ROW_MAX_VAL_MASK) + ROW_B16_BASE); - priv->row_shift[17] = (((addrmap[7] >> 8) & ROW_MAX_VAL_MASK) == - ROW_MAX_VAL_MASK) ? 0 : (((addrmap[7] >> 8) & - ROW_MAX_VAL_MASK) + ROW_B17_BASE); + + if (priv->info.sdram_mode == MEM_DDR4 || priv->info.sdram_mode == MEM_LPDDR4) { + priv->row_shift[16] = ((addrmap[7] & ROW_MAX_VAL_MASK) == + ROW_MAX_VAL_MASK) ? 0 : ((addrmap[7] & + ROW_MAX_VAL_MASK) + ROW_B16_BASE); + priv->row_shift[17] = (((addrmap[7] >> 8) & ROW_MAX_VAL_MASK) == + ROW_MAX_VAL_MASK) ? 0 : (((addrmap[7] >> 8) & + ROW_MAX_VAL_MASK) + ROW_B17_BASE); + } } static void snps_setup_column_address_map(struct snps_edac_priv *priv, u32 *addrmap) @@ -1129,6 +1132,10 @@ static void snps_setup_bank_address_map(struct snps_edac_priv *priv, u32 *addrma static void snps_setup_bg_address_map(struct snps_edac_priv *priv, u32 *addrmap) { + /* Bank group signals are available on the DDR4 memory only */ + if (priv->info.sdram_mode != MEM_DDR4) + return; + priv->bankgrp_shift[0] = (addrmap[8] & BANKGRP_MAX_VAL_MASK) + BANKGRP_B0_BASE; priv->bankgrp_shift[1] = (((addrmap[8] >> 8) & BANKGRP_MAX_VAL_MASK) == From patchwork Wed Sep 20 19:26:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393325 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 104BDC04FF1 for ; Wed, 20 Sep 2023 19:29:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230086AbjITT3O (ORCPT ); Wed, 20 Sep 2023 15:29:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbjITT27 (ORCPT ); Wed, 20 Sep 2023 15:28:59 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09217D9; Wed, 20 Sep 2023 12:28:48 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2c012232792so2901491fa.0; Wed, 20 Sep 2023 12:28:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238127; x=1695842927; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TA5e5G5EPvnnL49j/b8nNcZDnZYJMuuDQgONa21D59s=; b=HVTKD1PAZTSKPtyVTWjufOWJMa9K4lX7qwOMsIF7NIOSM8Detpe1AejJOFkMO2PWJ5 fDIk4DQWjDKhP/JOrJrLjo/7ZQP7Mc9OICb1YVPdlBwXrB4WJ5EOmChD6TYL1nUxK2aT XtaLOPl6CT+P2FfG2vUAV9Uk6YyxRQvhHXxAiB999nvXMu0/+Q/YdiJ1jAb2vXFJPE4A Zob0Y+YndTxFSqzrVRDqFLHHg8OrGsrXAbvABAPaF8zt9/TenjN9WeFPj4DFLmwuCcRF hq66PcrB+aK0lEAYRkb9t6cqAoI0v4qKHjVtXQVeTtNROR0kA78eMAv/5r448V/VzzEu lv1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238127; x=1695842927; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TA5e5G5EPvnnL49j/b8nNcZDnZYJMuuDQgONa21D59s=; b=xHMW3lJcnzHhdkWYpyNdnip3H+FAvfOS/F4hTOcWYHFNER9E7m9MZx2KpX9eHwnjK6 cIc2wy4kP7K23XEZb3LUB9roZrWW0whGyYB+YRV9J9mw8Pqjq5l/KiokYkoTIgZ+xhu3 PkhzrSFgI1Jo9Um5snlHgzjFMW8WCK+f709ZmIVXjUPl3DqMX0mrzcIiHhMwiOC4Ydil hzr3j+3iUP3AM83H6KFWoXYReRnK2tGPghQswU0lWDzGnhIn+cd1794OVFVBYu26jf8U 70yG9xVTV9yuZwhafFGHw4Vmy61SeoFVHtcjIfHpX26O9+rLyP5y4LXf7hBkpxTgzUXY gSeg== X-Gm-Message-State: AOJu0Yx24Rc17SJFk11WQ9gArhgM/wBaDBm3yhhPnBDSFNH4B44rparI BoIUbh19KrIO/Z1J7E6fTss= X-Google-Smtp-Source: AGHT+IFZDSF5zoq/W8jvFfDRKCF1KokOy7dJYucnqgvUrulEP8IaDlgpjwEqAHOhtU+vPGMtXh3DmA== X-Received: by 2002:a05:6512:104f:b0:503:364e:96ce with SMTP id c15-20020a056512104f00b00503364e96cemr3532656lfb.29.1695238126987; Wed, 20 Sep 2023 12:28:46 -0700 (PDT) Received: from localhost ([178.176.85.138]) by smtp.gmail.com with ESMTPSA id j26-20020a19f51a000000b004ff973cb14esm739436lfb.108.2023.09.20.12.28.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:28:45 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 08/18] EDAC/synopsys: Parse ADDRMAP[0] CSR for multi-ranks case only Date: Wed, 20 Sep 2023 22:26:53 +0300 Message-ID: <20230920192806.29960-9-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org The ADDRMAP[0] CSR contains the SDRAM Rank bits mapping (and memory channel mapping but it's irrelevant in this case). Obviously they are applicable for the multi-ranked memory only. If either the attached memory isn't multi-ranked or the controller simply doesn't support the multi-rank memory, parsing the ADDRMAP[0] CSR will be not just pointless, but in the later case erroneous since the CSR fields will contain zeros which will be perceived by the mapping detection procedure as a valid value. So the mapping will get to be invalid. Thus make sure the ADDRMAP[0] register is parsed only if a multi-ranked memory setup has been detected. Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index 5a06038aedcb..e6288e135480 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -1146,9 +1146,12 @@ static void snps_setup_bg_address_map(struct snps_edac_priv *priv, u32 *addrmap) static void snps_setup_rank_address_map(struct snps_edac_priv *priv, u32 *addrmap) { - priv->rank_shift[0] = ((addrmap[0] & RANK_MAX_VAL_MASK) == - RANK_MAX_VAL_MASK) ? 0 : ((addrmap[0] & - RANK_MAX_VAL_MASK) + RANK_B0_BASE); + /* Ranks mapping is unavailable for the single-ranked memory */ + if (priv->info.ranks > 1) { + priv->rank_shift[0] = ((addrmap[0] & RANK_MAX_VAL_MASK) == + RANK_MAX_VAL_MASK) ? 0 : ((addrmap[0] & + RANK_MAX_VAL_MASK) + RANK_B0_BASE); + } } /** From patchwork Wed Sep 20 19:26:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393336 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EE61C04FF3 for ; Wed, 20 Sep 2023 19:29:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230223AbjITT3U (ORCPT ); Wed, 20 Sep 2023 15:29:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbjITT3G (ORCPT ); Wed, 20 Sep 2023 15:29:06 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4EC5D3; Wed, 20 Sep 2023 12:28:52 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2bcb50e194dso2352431fa.3; Wed, 20 Sep 2023 12:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238130; x=1695842930; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QqkMxqOHncqsMYhQRlBDL7MG22B9ye3F7LSOor6Fxdc=; b=a++IAGYwtjcU3SLjl1zGCBp9P+8PgKA35kvSW1Wn9LUe6HB2d8Mpsdg5/pkHCLU2Sn wF5k5bjzBx4hn0pJ38Kg7mLaRZXpI06/fPaFKE9LM2agjjudqUNG5dBk1BkWBFyHxC/9 w+NzRHXiTK4F1ZOTTgADtw6Ilr9jaDdM8/HIrQkGIYQfHiOurz43vHFxP1E6WlGZq86B wQLqZJ0SM535FxlNDQgsusYhMTGLT3SlXtIvY1eeOTPOIOt6zAESGRLunQkNggV+DT6y DHoXXbKOqhSDIIFghyL2CiDgKcPrx8edHCEovnQrx7wCE66GGH6cgy2SgotVQLyVRpzx qHoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238130; x=1695842930; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QqkMxqOHncqsMYhQRlBDL7MG22B9ye3F7LSOor6Fxdc=; b=iMGI9tOzHR4gidoF3IY9qQXzUMQOkGaXcs8lu5NYF6X9wmCSUqk83i1uzbseL702za FyhfDN9+4IFRsyt0YCdTAVoMhXxI/FSyprwe+0BL1QhAQTE1adfnowMJV8kIIJGOkQco YX50KyNeNCxjEfm803JULXDcxB+lmp0YkVMKonD6VWKbKYZifa6AHwoV6rLPV9fKmGKz w252dJd4htXzMJUNsBriaPXGCTQJ5qZxpMbYfW4hj/Aea8G46N70KNLyWGjvFLsYMDQ4 S+Zpz/I0Q4p4V5VnF2K18mI8d8lvejpVjVEidXxaou+TcgvAwHonFCAuvl90qQGYrXYS 6JBg== X-Gm-Message-State: AOJu0YyHM15TBPGwrceizy/7eg48R/UTVwl6H4bUUOg+F0jaX6l1xYO0 TqUYVfYjSqLaGSYCQ4Yj4ZA= X-Google-Smtp-Source: AGHT+IHwKIWEU16ms/otWDq2b8ELHaN+mH3xTI3PC2c/Z46prfo2moy4ZDTclGHfvjbZhTpn7gKqlQ== X-Received: by 2002:a05:6512:2813:b0:503:3803:9e99 with SMTP id cf19-20020a056512281300b0050338039e99mr4239358lfb.15.1695238129974; Wed, 20 Sep 2023 12:28:49 -0700 (PDT) Received: from localhost ([178.176.86.191]) by smtp.gmail.com with ESMTPSA id r6-20020a19ac46000000b00502e01d1383sm2805899lfc.27.2023.09.20.12.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:28:49 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 09/18] EDAC/synopsys: Set actual DIMM ECC errors grain Date: Wed, 20 Sep 2023 22:26:54 +0300 Message-ID: <20230920192806.29960-10-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org It was wrong to set the DIMM errors grain parameter to just 1 byte because DW uMCTL2 DDRC calculates ECC for each SDRAM word and passes it as an additional byte of data to the memory chips. SDRAM word is the actual DQ-bus width determined by the DQ-width set during the IP-core synthesize and the DQ-bus mode (part of the DQ-bus actually used to get data from the memory chips) selected during the DDR controller initial setup procedure. Thus set the MCI DIMMs grain based on these parameters determined during the DW uMCTL2 DDRC config getting procedure. Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index e6288e135480..e10778cead63 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -26,9 +26,6 @@ /* Number of channels per memory controller */ #define SNPS_EDAC_NR_CHANS 1 -/* Granularity of reported error in bytes */ -#define SNPS_EDAC_ERR_GRAIN 1 - #define SNPS_EDAC_MSG_SIZE 256 #define SNPS_EDAC_MOD_STRING "snps_edac" @@ -736,9 +733,12 @@ static void snps_init_csrows(struct mem_ctl_info *mci) struct snps_edac_priv *priv = mci->pvt_info; struct csrow_info *csi; struct dimm_info *dimm; - u32 size, row; + u32 size, row, width; int j; + /* Actual SDRAM-word width for which ECC is calculated */ + width = 1U << (priv->info.dq_width - priv->info.dq_mode); + for (row = 0; row < mci->nr_csrows; row++) { csi = mci->csrows[row]; size = snps_get_memsize(); @@ -748,7 +748,7 @@ static void snps_init_csrows(struct mem_ctl_info *mci) dimm->edac_mode = EDAC_SECDED; dimm->mtype = priv->info.sdram_mode; dimm->nr_pages = (size >> PAGE_SHIFT) / csi->nr_channels; - dimm->grain = SNPS_EDAC_ERR_GRAIN; + dimm->grain = width; dimm->dtype = priv->info.dev_cfg; } } From patchwork Wed Sep 20 19:26:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08644C04FF1 for ; Wed, 20 Sep 2023 19:29:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230203AbjITT30 (ORCPT ); Wed, 20 Sep 2023 15:29:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230101AbjITT3N (ORCPT ); Wed, 20 Sep 2023 15:29:13 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F1A218D; Wed, 20 Sep 2023 12:28:56 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-501eec0a373so408053e87.3; Wed, 20 Sep 2023 12:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238134; x=1695842934; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dSPG6G1jeOItVuaHV8to9W/3RsF6DlFlBIE3fQ0A7VI=; b=H4PdOimijOaI+icFx7NG9ZN9vofW2NsMBKtBngapQkEwvJnFqvgCI2heBWXmap7p6b uw4wZHZ4YHpHGXUAAt9t9qm9WZI44nwh7qraIuT0ddtpfNTshjFAOq3Z9MxNhQAJTfjo 2XbGHsnnC2T18fnJLZriIiqvmt2icrDN1kwT2Svk0U2q/sAkn5LTg45V4CKU3ozm6c5F 8+w1DfOOC1HGpuDDnGbRu6X7BF3fOJ+xAzPLMSVl6R+QlCFHY4LqyB9nbdOKAHEz8YzU 3mdmiaaiU5gAjgFbYN991lcb4AvOedZheXFC7cRiQQUDxAKjV+k7BHlWLcQj5/2VyNEp e10A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238134; x=1695842934; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dSPG6G1jeOItVuaHV8to9W/3RsF6DlFlBIE3fQ0A7VI=; b=h8Y3n4WRGwj/u1EHSaSVV9S1D1180nSPq7d3aM53vI8k1oWY+z7x5Ypgpo1XJIDV37 NmmiJ3NxpELyySK0I9TRzAjdhOO2yYZwGkytgMjw6jTFEv9147QJhjcgH3lHnN2s/vAx jxfVIUZQ4j791XakBw/Hxs9d7tYQVl+yjB3RdHILWxbh36z2kkr0nVMlUWIcdrmXTB8W NSmZbiDuhBvqpUubV3m8vjrBxZRgICfLo0nTPz7q7GREJMGAbwkSwxH5NSiIYkWxTQh7 nTmARxTSASDmyHM7sPITYn5gac9RICHyGPtOo9COK6ELqLwQegXoKy5EVrtcwKzxtK8B 5rFg== X-Gm-Message-State: AOJu0YxnlKVnDHzJvN5WBVfkOrWO9Eibnq4HOaK3D0O/Ejx20si1zepu Buin81DdV9VnI93EZHhN+f4= X-Google-Smtp-Source: AGHT+IE4CKi5qzbdonKtH3syFc1QDsHYzWBoZm/gWrZLX2VxjB4N/bBbjITdQQHzwGC8uuJ42MoYbQ== X-Received: by 2002:a19:e04c:0:b0:4fd:fabf:b6ee with SMTP id g12-20020a19e04c000000b004fdfabfb6eemr2561415lfj.9.1695238133794; Wed, 20 Sep 2023 12:28:53 -0700 (PDT) Received: from localhost ([85.140.6.11]) by smtp.gmail.com with ESMTPSA id eo25-20020a056512481900b00500b3157ec8sm2790111lfb.163.2023.09.20.12.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:28:53 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 10/18] EDAC/synopsys: Get corrected bit position Date: Wed, 20 Sep 2023 22:26:55 +0300 Message-ID: <20230920192806.29960-11-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Since the DQ-bus width is now available in the driver it can be utilized to calculate the exact bit-position corrected by the ECC engine for any Synopsys memory controller setup. A corrected error syndrome is exposed by the ECCSTAT.corrected_bit_num field. A particular erroneous bit position is described in the lookup table [1] which also contains a dependency between the field value and the DQ-bus widths. The syndrome values table basically represents a standard lookup table for the Hamming (64,8)/(32,7)/(16,6) codes (the error-correcting bits placed at the power-of-two positions) except that the zero value means error in the ecc[0] bit. So using the offsets from that table introduce a new inline method snps_get_bitpos() which would provide the actual CE bit-position. The method will be called if a corrected error is detected. [1] DesignWare® Cores Enhanced Universal DDR Memory Controller (uMCTL2) Databook, Version 3.91a, October 2020, p.426-427 Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index e10778cead63..e08cb30b7a7d 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -301,6 +302,7 @@ struct snps_ddrc_info { * @col: Column number. * @bank: Bank number. * @bankgrp: Bank group number. + * @syndrome: Error syndrome. * @bitpos: Bit position. * @data: Data causing the error. */ @@ -309,6 +311,7 @@ struct snps_ecc_error_info { u32 col; u32 bank; u32 bankgrp; + u32 syndrome; u32 bitpos; u32 data; }; @@ -359,6 +362,27 @@ struct snps_edac_priv { #endif }; +/** + * snps_get_bitpos - Get DQ-bus corrected bit position. + * @syndrome: Error syndrome. + * @dq_width: Controller DQ-bus width. + * + * Return: actual corrected DQ-bus bit position starting from 0. + */ +static inline u32 snps_get_bitpos(u32 syndrome, enum snps_dq_width dq_width) +{ + /* ecc[0] bit */ + if (syndrome == 0) + return BITS_PER_BYTE << dq_width; + + /* ecc[1:x] bit */ + if (is_power_of_2(syndrome)) + return (BITS_PER_BYTE << dq_width) + ilog2(syndrome) + 1; + + /* data[0:y] bit */ + return syndrome - ilog2(syndrome) - 2; +} + /** * snps_get_error_info - Get the current ECC error info. * @priv: DDR memory controller private instance data. @@ -379,7 +403,7 @@ static int snps_get_error_info(struct snps_edac_priv *priv) if (!regval) return 1; - p->ceinfo.bitpos = FIELD_GET(ECC_STAT_BITNUM_MASK, regval); + p->ceinfo.syndrome = FIELD_GET(ECC_STAT_BITNUM_MASK, regval); regval = readl(base + ECC_ERRCNT_OFST); p->ce_cnt = FIELD_GET(ECC_ERRCNT_CECNT_MASK, regval); @@ -387,6 +411,8 @@ static int snps_get_error_info(struct snps_edac_priv *priv) if (!p->ce_cnt) goto ue_err; + p->ceinfo.bitpos = snps_get_bitpos(p->ceinfo.syndrome, priv->info.dq_width); + regval = readl(base + ECC_CEADDR0_OFST); p->ceinfo.row = FIELD_GET(ECC_CEADDR0_ROW_MASK, regval); From patchwork Wed Sep 20 19:26:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393338 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC00DC04FF1 for ; Wed, 20 Sep 2023 19:29:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230176AbjITT33 (ORCPT ); Wed, 20 Sep 2023 15:29:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230189AbjITT3R (ORCPT ); Wed, 20 Sep 2023 15:29:17 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 394301B7; Wed, 20 Sep 2023 12:28:58 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-502934c88b7so389497e87.2; Wed, 20 Sep 2023 12:28:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238136; x=1695842936; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1JamuYRg/bmHGo8DyK8kNadLYs1ZIGP2QJGW5LQhCWc=; b=Hh8BWqYObv5wesG9jZxqawXtYHAPXVP6jDHygiaBZngJGbOkBN3dmkWymAS6BASBw+ cofSyZF6L339PeSjPOkcWYZEh3KPP2lebcOm4+0HSSnGHq5w4tkFfSxyz12ToBfKoLta w77xItzL7Dl1up9Nl2AO58k5tBrmQD97OWD1plKRBgIIayUDWywWpdpVGvE4ZmEGRWXF QKOwY6upbapkoYj4gVTXP6E+R+VlrAZXC/1EHeNyZzHdwdG7aN5e3XFLRZiuc/qxpJ05 pWyVoKjiwVfBpvQygh9A7pqx7I8kLtrqchosPo8khf8lbx5orh7zFM8o7NFl1SZHciEb 8R6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238136; x=1695842936; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1JamuYRg/bmHGo8DyK8kNadLYs1ZIGP2QJGW5LQhCWc=; b=Tan7Spayj1nDiQ3mGXkHORv+0xidiBomhi231nR10aDM93bFw7KQOjNYBEaIgxzDIW BbLHtjSThwJI2vmohnaVM3Zt2gTV0Qa+C7+OIA8HwT+eaG/f4m5VZLyqUf11pJItdZhm cLA3igbyQvhkthcF31QDAaUrBfqWNt+ZkmD9kjGU08N6DwCmoPmWlabYGGGPDRc9tumr f+Ei0cd21gTwJdzlPyS9ntoguqTuPHVjgg5zskSviWzzofMAw93dcehoxHg2LPmRbvEL ncwtcaYazf1qzwGw+zQ9+0iKxnsoCDYweQwsHO76ftuIPBlG41fC8YSkCGPCFFd94K7j 7R6Q== X-Gm-Message-State: AOJu0YxbHvrXwy2Ad0ZDiefWmHywqGZx+GsCcSStqtDQsf2eA7WPLEJF YNm225ScovO+fFgwX7mkQJQ= X-Google-Smtp-Source: AGHT+IHed65zcIiGfMl4641Tw0aSRdFZiaSvi+nuE8E8l6I8lUHfaSfYYBmvSyduJ4FWc0Z/ibqVGA== X-Received: by 2002:a05:6512:32b8:b0:502:adbc:9b75 with SMTP id q24-20020a05651232b800b00502adbc9b75mr2680835lfe.51.1695238136237; Wed, 20 Sep 2023 12:28:56 -0700 (PDT) Received: from localhost ([85.140.6.205]) by smtp.gmail.com with ESMTPSA id y20-20020ac255b4000000b005009d5aaaedsm2822225lfg.172.2023.09.20.12.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:28:55 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 11/18] EDAC/synopsys: Pass syndrome to EDAC error handler Date: Wed, 20 Sep 2023 22:26:56 +0300 Message-ID: <20230920192806.29960-12-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org EDAC MC error handler permits specifying a corrected error syndrome which then will be printed as a part of the generic error message. Since it's available in the error info structure pass it to the edac_mc_handle_error() function. Signed-off-by: Serge Semin --- Changelog v4: - Get syndrome from the ECCSTAT.ecc_corrected_bit_num field rather than from ECCCSYN2. The later CSR in fact contains ECC. --- drivers/edac/synopsys_edac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index e08cb30b7a7d..fbf1f8af9788 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -474,7 +474,7 @@ static void snps_handle_error(struct mem_ctl_info *mci, struct snps_ecc_status * pinf->bitpos, pinf->data); edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, - p->ce_cnt, 0, 0, 0, 0, 0, -1, + p->ce_cnt, 0, 0, pinf->syndrome, 0, 0, -1, priv->message, ""); } From patchwork Wed Sep 20 19:26:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 129DCC04FEE for ; Wed, 20 Sep 2023 19:29:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230263AbjITT3i (ORCPT ); Wed, 20 Sep 2023 15:29:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230007AbjITT3V (ORCPT ); Wed, 20 Sep 2023 15:29:21 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE6B6CCC; Wed, 20 Sep 2023 12:29:00 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-503065c4b25so364579e87.1; Wed, 20 Sep 2023 12:29:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238139; x=1695842939; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uqBb3j7kZv1svEf6sHTFvZChySF0UAHxjiT2Ls2Akek=; b=fJzisKqvYBK3m7qetj0q8ol2HcrJzV7Qmu0HYMbkAepxA5isVM2QCz4vOIbvVmiXy5 9PKaMNhN1PSyFxCIhRxb+KyDldXoFpL6G1fXD4DifNRFgdKJQCBUH3u86ctK0zudKPf9 at5rcBASP+iGWZvK0POAHpEpKNpHNaxzmnAuR7FB97isZgkTp720hX/ngoM7y/1WOuiA la/JWB4mP4J6TfBOp1Eg8qK2K3HxesE25/Cm3AgpImIafh/X5yt3GPdfjyNDMIg8QjJi Bxy6jN2qcdYNOeq8PJYh8P0bXh6Mulds/n3BKWHy+zXR/to5XxsWxFxmZe0RSu3nFEqN /TCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238139; x=1695842939; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uqBb3j7kZv1svEf6sHTFvZChySF0UAHxjiT2Ls2Akek=; b=KW+5NbUfv18tfTD10BLyh1wICZPsAzveDDXsxnmp/j/sqs7lvoYIuVrt2+tqn/xdB2 9RXPAE2i6ICG0sFtzx4M1SOiFXGp9dg/YEM8Wq5brtaaXF7+Nh9rj4mlby+o207iYLJC 5ianqITm1sZ1BVDFJqKOJRIU2fN4nxQkVOCvN0k5PkTdSYZwTItIW8ObtmG4aQyvloh8 2dE2EqKkqdE5FLuz/7V+s8BN1csEOUXXvGLOZx6bM53Tbs1r9nuw7SPiOl7V04MoOmtg +tUUaVqyLzaLz53MGORgPI7x3TXQ3AfmttWBVtcW/m4Wc5I2W1SwDot94NakubCWeNc9 AXlg== X-Gm-Message-State: AOJu0YzTp83yDY36oeR9UbBQQZJEvxWp1yPQx0p066BrIQe2Y/LNX9kM 189CN2j228wnzLN2ApJDtcc= X-Google-Smtp-Source: AGHT+IGR+wqT1IZCsN8BwpelDunWHlppDt+ckZw/f6gkalBZjyHHw9oeTt8SYJvf8EPjwOvyp2pgkQ== X-Received: by 2002:ac2:4bd1:0:b0:503:3805:e902 with SMTP id o17-20020ac24bd1000000b005033805e902mr3479722lfq.30.1695238138594; Wed, 20 Sep 2023 12:28:58 -0700 (PDT) Received: from localhost ([85.26.234.143]) by smtp.gmail.com with ESMTPSA id d9-20020ac244c9000000b005007da9f823sm524439lfm.168.2023.09.20.12.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:28:58 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 12/18] EDAC/synopsys: Read full data+ecc pattern on errors Date: Wed, 20 Sep 2023 22:26:57 +0300 Message-ID: <20230920192806.29960-13-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org DW uMCTL2 DDRC calculates ECC for the Full DQ-bus word. If non-Full bus width mode is activated the leftover DQ-bits will be padded with zeros, but the ECC code is calculated for the whole width anyway [1]. For some reason the DW uMCTL2 DDRC driver currently doesn't read the whole SDRAM word in if ECC errors happens even though the 64-bits DQ-bus has been supported for a long time. Moreover a Full ECC value is also available in the ECC(C|U)SYN2 register. In a less than 64-bits DQ-bus setups the higher ECC bits are just unused. So update the errors handler to reading the entire data+ecc pattern: extend the data field of the ECC error info structure since it may contain 64-bit data; add a new ECC field there since it's a part of the erroneous data pattern; read the upper 32-bits part of the data pattern only if an ECC error happens and the DDR controller has been configured with the 64-bits DQ bus; read the full ECC value from the ECC(C|U)SYN2 register. The data+ecc couple will be printed as a part of the custom error message passed then to the edac_mc_handle_error() method. Note since the full data+ecc info is now always logged into the EDAC core there is no longer need in the debug print of the Syndrome Registers content. Drop it then. [1] DesignWare® Cores Enhanced Universal DDR Memory Controller (uMCTL2) Databook, Version 3.91a, October 2020, p.424-425 Signed-off-by: Serge Semin --- Changelog v4: - Retrieve ECC too. --- drivers/edac/synopsys_edac.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index fbf1f8af9788..7376a0fc6394 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -305,6 +305,7 @@ struct snps_ddrc_info { * @syndrome: Error syndrome. * @bitpos: Bit position. * @data: Data causing the error. + * @ecc: Data ECC. */ struct snps_ecc_error_info { u32 row; @@ -313,7 +314,8 @@ struct snps_ecc_error_info { u32 bankgrp; u32 syndrome; u32 bitpos; - u32 data; + u64 data; + u32 ecc; }; /** @@ -422,10 +424,10 @@ static int snps_get_error_info(struct snps_edac_priv *priv) p->ceinfo.col = FIELD_GET(ECC_CEADDR1_COL_MASK, regval); p->ceinfo.data = readl(base + ECC_CSYND0_OFST); + if (priv->info.dq_width == SNPS_DQ_64) + p->ceinfo.data |= (u64)readl(base + ECC_CSYND1_OFST) << 32; - edac_dbg(2, "ECCCSYN0: 0x%08X ECCCSYN1: 0x%08X ECCCSYN2: 0x%08X\n", - readl(base + ECC_CSYND0_OFST), readl(base + ECC_CSYND1_OFST), - readl(base + ECC_CSYND2_OFST)); + p->ceinfo.ecc = readl(base + ECC_CSYND2_OFST); ue_err: if (!p->ue_cnt) @@ -440,6 +442,11 @@ static int snps_get_error_info(struct snps_edac_priv *priv) p->ueinfo.col = FIELD_GET(ECC_CEADDR1_COL_MASK, regval); p->ueinfo.data = readl(base + ECC_UESYND0_OFST); + if (priv->info.dq_width == SNPS_DQ_64) + p->ueinfo.data |= (u64)readl(base + ECC_UESYND1_OFST) << 32; + + p->ueinfo.ecc = readl(base + ECC_UESYND2_OFST); + out: spin_lock_irqsave(&priv->reglock, flags); @@ -469,9 +476,9 @@ static void snps_handle_error(struct mem_ctl_info *mci, struct snps_ecc_status * pinf = &p->ceinfo; snprintf(priv->message, SNPS_EDAC_MSG_SIZE, - "Row %d Col %d Bank %d Bank Group %d Bit %d Data 0x%08x", + "Row %d Col %d Bank %d Bank Group %d Bit %d Data 0x%08llx:0x%02x", pinf->row, pinf->col, pinf->bank, pinf->bankgrp, - pinf->bitpos, pinf->data); + pinf->bitpos, pinf->data, pinf->ecc); edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, p->ce_cnt, 0, 0, pinf->syndrome, 0, 0, -1, @@ -482,8 +489,9 @@ static void snps_handle_error(struct mem_ctl_info *mci, struct snps_ecc_status * pinf = &p->ueinfo; snprintf(priv->message, SNPS_EDAC_MSG_SIZE, - "Row %d Col %d Bank %d Bank Group %d", - pinf->row, pinf->col, pinf->bank, pinf->bankgrp); + "Row %d Col %d Bank %d Bank Group %d Data 0x%08llx:0x%02x", + pinf->row, pinf->col, pinf->bank, pinf->bankgrp, + pinf->data, pinf->ecc); edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, p->ue_cnt, 0, 0, 0, 0, 0, -1, From patchwork Wed Sep 20 19:26:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393340 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1B52C04FEE for ; Wed, 20 Sep 2023 19:29:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbjITT3q (ORCPT ); Wed, 20 Sep 2023 15:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbjITT30 (ORCPT ); Wed, 20 Sep 2023 15:29:26 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7524A1A4; Wed, 20 Sep 2023 12:29:03 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2c007d6159aso2387061fa.3; Wed, 20 Sep 2023 12:29:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238141; x=1695842941; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PyWc+rqkVGRwEwvNukmSeBhnWN0IDxv9BejmAkmAVHI=; b=NSY71lbc6z0w8Du1Rgi2hiG3+N11VLPiYHAiAz5YJlRGUaXAm/Q3ADL3HK7X1xEtYA PFJXsIBHzJfDYmOYaty831K/aIsIJsSzdIugyACS2QwYgrP9e+/uKoCZZgLYpJEsyStA IWnT/bypVbCBfVM6GYcgMNsZuxsaXWaI4NEhCXU8V5a7Hc8XZQQuSl/hWPud6dTYLd3X MFfr4RlU0tnFscmuOSDDqWOfeALLqYQ7GcO9683HEV5Khz574O9ApsXJCkQUaIGR9s0M P7Gy7LBaY+0HPbzvBj5UCCaE2cIeJHoO4f7Fz3yy9Ubi+kSXFS7ffY9E3TxOgOp7Qp8P 0OwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238141; x=1695842941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PyWc+rqkVGRwEwvNukmSeBhnWN0IDxv9BejmAkmAVHI=; b=gwDK5z9mnaEWhmyOh0m4g7AC+4PUuiKddgwCA9xDv90Lejj5l7hl8q2iAmV87RQn1Q IjGdchv5B+26YRDALvZSYLjbKV01+AkoE0TtFeRyi/o3Mv5YChT1q8ui2Lwi1msHJ4g6 +yeRXxP0lxlBdKhmcudekyvhyZs8HlbmejiarGpFd92Z74R115lH9BWY6D8awIjF2jil KBrpbT3/sn0sLFfWpkuEchpDlpRUGgck0R3ONfoq0uJmfn3EcIq0fmdRlvdr4njnU4bK ygzd8CKn6EZHWOCebiBFwnlmEAfZB8HB7SoVrxdc86SXVMbBmwxr/HHW5zpTeNrvnyrZ J54g== X-Gm-Message-State: AOJu0YwmrkJEsNsxg45M3fEW5v1nsdS0G4MZw0icGEjiIJ6qSD9WMLXW 0Aa8MC2PP2ORIuqDnxwgYp8= X-Google-Smtp-Source: AGHT+IEpTykgcLIH+idrJB48K2nb7IZC4Rc3s6pqC54gb+zNS9FJz8ftJFzd+shjXK6WP/7b6om5tg== X-Received: by 2002:a2e:7410:0:b0:2bf:b133:dd65 with SMTP id p16-20020a2e7410000000b002bfb133dd65mr3011859ljc.38.1695238141089; Wed, 20 Sep 2023 12:29:01 -0700 (PDT) Received: from localhost ([85.140.0.70]) by smtp.gmail.com with ESMTPSA id c3-20020a2e9483000000b002bcdbfe36a1sm3211616ljh.84.2023.09.20.12.29.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:29:00 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 13/18] EDAC/synopsys: Introduce System/SDRAM address translation interface Date: Wed, 20 Sep 2023 22:26:58 +0300 Message-ID: <20230920192806.29960-14-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Currently the address translation is performed only in the framework of the ECC poison procedures. The available infrastructure is utilized for the device and driver debugging. Meanwhile it would be very useful to know not only the SDRAM address of the runtime ECC errors, but the originating system address accepted on the AXI/AHB ports of the DW uMCTL2 DDR controller. In order to be able to do so the currently available infrastructure needs to be properly updated. First of all move it away from under the EDAC_DEBUG config, since it will be always utilized by the driver. Secondly for the sake of the code simplification split up the translation procedure into the next three stages: 1. System<->Application address translation (just type cast for now). 2. Application<->HIF address translation (DQ-bus width based address shift). 3. HIF<->SDRAM address translation (ADDRMAPx-based mapping). The suggested implementation supports the 1->3 translation only in the same way as it was before this modification (the backward address translation will be added later). Semantically it's the same except the next four aspects: ff-value is used as a marker of the unmapped HIF/SDRAM bits instead of zero-value which in some cases is a valid mapping bit id; DQ-width is used to perform the Application<->HIF address translation instead of the fixed 64-bit DQ-bus width assumption; the HIF/SDRAM address translation procedure searches through the whole dimensions width instead of stopping at the first unmapped bit since in general some of the row/column/bank/etc bits (especially the column bits, like b10) can be left unmapped; the number of supported ranks is extended to four - maximum possible value. Note while at it the code is simplified a bit: encapsulate the mapping table into a dedicated structure (snps_hif_sdram_map); use the FIELD_GET() helper to get ADDRMAP CSR fields; define more descriptive max-value macros. Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 750 +++++++++++++++++++++-------------- 1 file changed, 453 insertions(+), 297 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index 7376a0fc6394..204d7f1fc7e2 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -153,17 +153,28 @@ #define ECC_CEPOISON_MASK GENMASK(1, 0) #define ECC_UEPOISON_MASK BIT(0) -/* DDRC Device config shifts/masks */ -#define DDR_MAX_ROW_SHIFT 18 -#define DDR_MAX_COL_SHIFT 14 -#define DDR_MAX_BANK_SHIFT 3 -#define DDR_MAX_BANKGRP_SHIFT 2 - -#define ROW_MAX_VAL_MASK 0xF -#define COL_MAX_VAL_MASK 0xF -#define BANK_MAX_VAL_MASK 0x1F -#define BANKGRP_MAX_VAL_MASK 0x1F -#define RANK_MAX_VAL_MASK 0x1F +/* DDRC address mapping parameters */ +#define DDR_ADDRMAP_NREGS 12 + +#define DDR_MAX_ROW_WIDTH 18 +#define DDR_MAX_COL_WIDTH 14 +#define DDR_MAX_BANK_WIDTH 3 +#define DDR_MAX_BANKGRP_WIDTH 2 +#define DDR_MAX_RANK_WIDTH 2 + +#define DDR_ADDRMAP_B0_M15 GENMASK(3, 0) +#define DDR_ADDRMAP_B8_M15 GENMASK(11, 8) +#define DDR_ADDRMAP_B16_M15 GENMASK(19, 16) +#define DDR_ADDRMAP_B24_M15 GENMASK(27, 24) + +#define DDR_ADDRMAP_B0_M31 GENMASK(4, 0) +#define DDR_ADDRMAP_B8_M31 GENMASK(12, 8) +#define DDR_ADDRMAP_B16_M31 GENMASK(20, 16) +#define DDR_ADDRMAP_B24_M31 GENMASK(28, 24) + +#define DDR_ADDRMAP_UNUSED ((u8)-1) +#define DDR_ADDRMAP_MAX_15 DDR_ADDRMAP_B0_M15 +#define DDR_ADDRMAP_MAX_31 DDR_ADDRMAP_B0_M31 #define ROW_B0_BASE 6 #define ROW_B1_BASE 7 @@ -205,6 +216,7 @@ #define BANKGRP_B1_BASE 3 #define RANK_B0_BASE 6 +#define RANK_B1_BASE 7 /* ZynqMP DDR QOS Interrupt register definitions */ #define ZYNQMP_DDR_QOS_UE_MASK BIT(2) @@ -296,6 +308,41 @@ struct snps_ddrc_info { unsigned int ranks; }; +/** + * struct snps_hif_sdram_map - HIF/SDRAM mapping table. + * @row: HIF bit offsets used as row address bits. + * @col: HIF bit offsets used as column address bits. + * @bank: HIF bit offsets used as bank address bits. + * @bankgrp: HIF bit offsets used as bank group address bits. + * @rank: HIF bit offsets used as rank address bits. + * + * For example, row[0] = 6 means row bit #0 is encoded by the HIF + * address bit #6 and vice-versa. + */ +struct snps_hif_sdram_map { + u8 row[DDR_MAX_ROW_WIDTH]; + u8 col[DDR_MAX_COL_WIDTH]; + u8 bank[DDR_MAX_BANK_WIDTH]; + u8 bankgrp[DDR_MAX_BANKGRP_WIDTH]; + u8 rank[DDR_MAX_RANK_WIDTH]; +}; + +/** + * struct snps_sdram_addr - SDRAM address. + * @row: Row number. + * @col: Column number. + * @bank: Bank number. + * @bankgrp: Bank group number. + * @rank: Rank number. + */ +struct snps_sdram_addr { + u16 row; + u16 col; + u8 bank; + u8 bankgrp; + u8 rank; +}; + /** * struct snps_ecc_error_info - ECC error log information. * @row: Row number. @@ -335,20 +382,17 @@ struct snps_ecc_status { /** * struct snps_edac_priv - DDR memory controller private data. * @info: DDR controller config info. + * @hif_sdram_map: HIF/SDRAM mapping table. * @pdev: Platform device. * @baseaddr: Base address of the DDR controller. * @reglock: Concurrent CSRs access lock. * @message: Buffer for framing the event specific info. * @stat: ECC status information. * @poison_addr: Data poison address. - * @row_shift: Bit shifts for row bit. - * @col_shift: Bit shifts for column bit. - * @bank_shift: Bit shifts for bank bit. - * @bankgrp_shift: Bit shifts for bank group bit. - * @rank_shift: Bit shifts for rank bit. */ struct snps_edac_priv { struct snps_ddrc_info info; + struct snps_hif_sdram_map hif_sdram_map; struct platform_device *pdev; void __iomem *baseaddr; spinlock_t reglock; @@ -356,14 +400,97 @@ struct snps_edac_priv { struct snps_ecc_status stat; #ifdef CONFIG_EDAC_DEBUG ulong poison_addr; - u32 row_shift[18]; - u32 col_shift[14]; - u32 bank_shift[3]; - u32 bankgrp_shift[2]; - u32 rank_shift[1]; #endif }; +/** + * snps_map_app_to_hif - Map Application address to HIF address. + * @priv: DDR memory controller private instance data. + * @app: Application address (source). + * @hif: HIF address (destination). + * + * HIF address is used to perform the DQ bus width aligned burst transactions. + * So in order to perform the Application-to-HIF address translation we just + * need to discard the SDRAM-word bits of the Application address. + */ +static void snps_map_app_to_hif(struct snps_edac_priv *priv, + u64 app, u64 *hif) +{ + *hif = app >> priv->info.dq_width; +} + +/** + * snps_map_hif_to_sdram - Map HIF address to SDRAM address. + * @priv: DDR memory controller private instance data. + * @hif: HIF address (source). + * @sdram: SDRAM address (destination). + * + * HIF-SDRAM address mapping is configured with the ADDRMAPx registers, Based + * on the CSRs value the HIF address bits are mapped to the corresponding bits + * in the SDRAM rank/bank/column/row. If an SDRAM address bit is unused (there + * is no any HIF address bit corresponding to it) it will be set to zero. Using + * this fact we can freely set the output SDRAM address with zeros and walk + * over the set HIF address bits only. Similarly the unmapped HIF address bits + * are just ignored. + */ +static void snps_map_hif_to_sdram(struct snps_edac_priv *priv, + u64 hif, struct snps_sdram_addr *sdram) +{ + struct snps_hif_sdram_map *map = &priv->hif_sdram_map; + int i; + + sdram->row = 0; + for (i = 0; i < DDR_MAX_ROW_WIDTH; i++) { + if (map->row[i] != DDR_ADDRMAP_UNUSED && hif & BIT(map->row[i])) + sdram->row |= BIT(i); + } + + sdram->col = 0; + for (i = 0; i < DDR_MAX_COL_WIDTH; i++) { + if (map->col[i] != DDR_ADDRMAP_UNUSED && hif & BIT(map->col[i])) + sdram->col |= BIT(i); + } + + sdram->bank = 0; + for (i = 0; i < DDR_MAX_BANK_WIDTH; i++) { + if (map->bank[i] != DDR_ADDRMAP_UNUSED && hif & BIT(map->bank[i])) + sdram->bank |= BIT(i); + } + + sdram->bankgrp = 0; + for (i = 0; i < DDR_MAX_BANKGRP_WIDTH; i++) { + if (map->bankgrp[i] != DDR_ADDRMAP_UNUSED && hif & BIT(map->bankgrp[i])) + sdram->bankgrp |= BIT(i); + } + + sdram->rank = 0; + for (i = 0; i < DDR_MAX_RANK_WIDTH; i++) { + if (map->rank[i] != DDR_ADDRMAP_UNUSED && hif & BIT(map->rank[i])) + sdram->rank |= BIT(i); + } +} + +/** + * snps_map_sys_to_sdram - Map System address to SDRAM address. + * @priv: DDR memory controller private instance data. + * @sys: System address (source). + * @sdram: SDRAM address (destination). + * + * Perform a full mapping of the system address (detected on the controller + * ports) to the SDRAM address tuple row/column/bank/etc. + */ +static void snps_map_sys_to_sdram(struct snps_edac_priv *priv, + dma_addr_t sys, struct snps_sdram_addr *sdram) +{ + u64 app, hif; + + app = sys; + + snps_map_app_to_hif(priv, app, &hif); + + snps_map_hif_to_sdram(priv, hif, sdram); +} + /** * snps_get_bitpos - Get DQ-bus corrected bit position. * @syndrome: Error syndrome. @@ -755,6 +882,301 @@ static int snps_get_ddrc_info(struct snps_edac_priv *priv) return init_plat ? init_plat(priv) : 0; } +/** + * snps_get_hif_row_map - Get HIF/SDRAM-row address map. + * @priv: DDR memory controller private instance data. + * @addrmap: Array with ADDRMAP registers value. + * + * SDRAM-row address is defined by the fields in the ADDRMAP[5-7,9-11] + * registers. Those fields value indicate the HIF address bits used to encode + * the DDR row address. + */ +static void snps_get_hif_row_map(struct snps_edac_priv *priv, u32 *addrmap) +{ + struct snps_hif_sdram_map *map = &priv->hif_sdram_map; + u8 map_row_b2_10; + int i; + + for (i = 0; i < DDR_MAX_ROW_WIDTH; i++) + map->row[i] = DDR_ADDRMAP_UNUSED; + + map->row[0] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[5]) + ROW_B0_BASE; + map->row[1] = FIELD_GET(DDR_ADDRMAP_B8_M15, addrmap[5]) + ROW_B1_BASE; + + map_row_b2_10 = FIELD_GET(DDR_ADDRMAP_B16_M15, addrmap[5]); + if (map_row_b2_10 != DDR_ADDRMAP_MAX_15) { + for (i = 2; i < 11; i++) + map->row[i] = map_row_b2_10 + i + ROW_B0_BASE; + } else { + map->row[2] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[9]) + ROW_B2_BASE; + map->row[3] = FIELD_GET(DDR_ADDRMAP_B8_M15, addrmap[9]) + ROW_B3_BASE; + map->row[4] = FIELD_GET(DDR_ADDRMAP_B16_M15, addrmap[9]) + ROW_B4_BASE; + map->row[5] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[9]) + ROW_B5_BASE; + map->row[6] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[10]) + ROW_B6_BASE; + map->row[7] = FIELD_GET(DDR_ADDRMAP_B8_M15, addrmap[10]) + ROW_B7_BASE; + map->row[8] = FIELD_GET(DDR_ADDRMAP_B16_M15, addrmap[10]) + ROW_B8_BASE; + map->row[9] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[10]) + ROW_B9_BASE; + map->row[10] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[11]) + ROW_B10_BASE; + } + + map->row[11] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[5]); + map->row[11] = map->row[11] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->row[11] + ROW_B11_BASE; + + map->row[12] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[6]); + map->row[12] = map->row[12] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->row[12] + ROW_B12_BASE; + + map->row[13] = FIELD_GET(DDR_ADDRMAP_B8_M15, addrmap[6]); + map->row[13] = map->row[13] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->row[13] + ROW_B13_BASE; + + map->row[14] = FIELD_GET(DDR_ADDRMAP_B16_M15, addrmap[6]); + map->row[14] = map->row[14] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->row[14] + ROW_B14_BASE; + + map->row[15] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[6]); + map->row[15] = map->row[15] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->row[15] + ROW_B15_BASE; + + if (priv->info.sdram_mode == MEM_DDR4 || priv->info.sdram_mode == MEM_LPDDR4) { + map->row[16] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[7]); + map->row[16] = map->row[16] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->row[16] + ROW_B16_BASE; + + map->row[17] = FIELD_GET(DDR_ADDRMAP_B8_M15, addrmap[7]); + map->row[17] = map->row[17] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->row[17] + ROW_B17_BASE; + } +} + +/** + * snps_get_hif_col_map - Get HIF/SDRAM-column address map. + * @priv: DDR memory controller private instance data. + * @addrmap: Array with ADDRMAP registers value. + * + * SDRAM-column address is defined by the fields in the ADDRMAP[2-4] + * registers. Those fields value indicate the HIF address bits used to encode + * the DDR row address. + */ +static void snps_get_hif_col_map(struct snps_edac_priv *priv, u32 *addrmap) +{ + struct snps_hif_sdram_map *map = &priv->hif_sdram_map; + int i; + + for (i = 0; i < DDR_MAX_COL_WIDTH; i++) + map->col[i] = DDR_ADDRMAP_UNUSED; + + map->col[0] = 0; + map->col[1] = 1; + map->col[2] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[2]) + COL_B2_BASE; + map->col[3] = FIELD_GET(DDR_ADDRMAP_B8_M15, addrmap[2]) + COL_B3_BASE; + + map->col[4] = FIELD_GET(DDR_ADDRMAP_B16_M15, addrmap[2]); + map->col[4] = map->col[4] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[4] + COL_B4_BASE; + + map->col[5] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[2]); + map->col[5] = map->col[5] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[5] + COL_B5_BASE; + + map->col[6] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[3]); + map->col[6] = map->col[6] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[6] + COL_B6_BASE; + + map->col[7] = FIELD_GET(DDR_ADDRMAP_B8_M15, addrmap[3]); + map->col[7] = map->col[7] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[7] + COL_B7_BASE; + + map->col[8] = FIELD_GET(DDR_ADDRMAP_B16_M15, addrmap[3]); + map->col[8] = map->col[8] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[8] + COL_B8_BASE; + + map->col[9] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[3]); + map->col[9] = map->col[9] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[9] + COL_B9_BASE; + + if (priv->info.dq_mode) { + for (i = 9; i > priv->info.dq_mode; i--) { + map->col[i] = map->col[i - priv->info.dq_mode]; + map->col[i - priv->info.dq_mode] = DDR_ADDRMAP_UNUSED; + } + } + + /* + * Per JEDEC DDR2/3/4/mDDR specification, column address bit 10 is + * reserved for indicating auto-precharge, and hence no source + * address bit can be mapped to col[10]. + * Per JEDEC specification, column address bit 12 is reserved + * for the Burst-chop status, so no source address bit mapping + * for col[12] either. + */ + if (priv->info.dq_mode == SNPS_DQ_FULL) { + if (priv->info.sdram_mode == MEM_LPDDR3) { + map->col[10] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[4]); + map->col[10] = map->col[10] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[10] + COL_B10_BASE; + + map->col[11] = FIELD_GET(DDR_ADDRMAP_B8_M15, addrmap[4]); + map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[11] + COL_B11_BASE; + } else { + map->col[11] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[4]); + map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[11] + COL_B10_BASE; + + map->col[13] = FIELD_GET(DDR_ADDRMAP_B8_M15, addrmap[4]); + map->col[13] = map->col[13] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[13] + COL_B11_BASE; + } + } else if (priv->info.dq_mode == SNPS_DQ_HALF) { + if (priv->info.sdram_mode == MEM_LPDDR3) { + map->col[10] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[3]); + map->col[10] = map->col[10] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[10] + COL_B9_BASE; + + map->col[11] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[4]); + map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[11] + COL_B10_BASE; + } else { + map->col[11] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[3]); + map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[11] + COL_B9_BASE; + + map->col[13] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[4]); + map->col[13] = map->col[13] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[13] + COL_B10_BASE; + } + } else { + if (priv->info.sdram_mode == MEM_LPDDR3) { + map->col[10] = FIELD_GET(DDR_ADDRMAP_B16_M15, addrmap[3]); + map->col[10] = map->col[10] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[10] + COL_B8_BASE; + + map->col[11] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[3]); + map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[11] + COL_B9_BASE; + } else { + map->col[11] = FIELD_GET(DDR_ADDRMAP_B16_M15, addrmap[3]); + map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[11] + COL_B8_BASE; + + map->col[11] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[3]); + map->col[13] = map->col[13] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[13] + COL_B9_BASE; + } + } +} + +/** + * snps_get_hif_bank_map - Get HIF/SDRAM-bank address map. + * @priv: DDR memory controller private instance data. + * @addrmap: Array with ADDRMAP registers value. + * + * SDRAM-bank address is defined by the fields in the ADDRMAP[1] + * register. Those fields value indicate the HIF address bits used to encode + * the DDR bank address. + */ +static void snps_get_hif_bank_map(struct snps_edac_priv *priv, u32 *addrmap) +{ + struct snps_hif_sdram_map *map = &priv->hif_sdram_map; + int i; + + for (i = 0; i < DDR_MAX_BANK_WIDTH; i++) + map->bank[i] = DDR_ADDRMAP_UNUSED; + + map->bank[0] = FIELD_GET(DDR_ADDRMAP_B0_M31, addrmap[1]) + BANK_B0_BASE; + map->bank[1] = FIELD_GET(DDR_ADDRMAP_B8_M31, addrmap[1]) + BANK_B1_BASE; + + map->bank[2] = FIELD_GET(DDR_ADDRMAP_B16_M31, addrmap[1]); + map->bank[2] = map->bank[2] == DDR_ADDRMAP_MAX_31 ? + DDR_ADDRMAP_UNUSED : map->bank[2] + BANK_B2_BASE; +} + +/** + * snps_get_hif_bankgrp_map - Get HIF/SDRAM-bank group address map. + * @priv: DDR memory controller private instance data. + * @addrmap: Array with ADDRMAP registers value. + * + * SDRAM-bank group address is defined by the fields in the ADDRMAP[8] + * register. Those fields value indicate the HIF address bits used to encode + * the DDR bank group address. + */ +static void snps_get_hif_bankgrp_map(struct snps_edac_priv *priv, u32 *addrmap) +{ + struct snps_hif_sdram_map *map = &priv->hif_sdram_map; + int i; + + for (i = 0; i < DDR_MAX_BANKGRP_WIDTH; i++) + map->bankgrp[i] = DDR_ADDRMAP_UNUSED; + + /* Bank group signals are available on the DDR4 memory only */ + if (priv->info.sdram_mode != MEM_DDR4) + return; + + map->bankgrp[0] = FIELD_GET(DDR_ADDRMAP_B0_M31, addrmap[8]) + BANKGRP_B0_BASE; + + map->bankgrp[1] = FIELD_GET(DDR_ADDRMAP_B8_M31, addrmap[8]); + map->bankgrp[1] = map->bankgrp[1] == DDR_ADDRMAP_MAX_31 ? + DDR_ADDRMAP_UNUSED : map->bankgrp[1] + BANKGRP_B1_BASE; +} + +/** + * snps_get_hif_rank_map - Get HIF/SDRAM-rank address map. + * @priv: DDR memory controller private instance data. + * @addrmap: Array with ADDRMAP registers value. + * + * SDRAM-rank address is defined by the fields in the ADDRMAP[0] + * register. Those fields value indicate the HIF address bits used to encode + * the DDR rank address. + */ +static void snps_get_hif_rank_map(struct snps_edac_priv *priv, u32 *addrmap) +{ + struct snps_hif_sdram_map *map = &priv->hif_sdram_map; + int i; + + for (i = 0; i < DDR_MAX_RANK_WIDTH; i++) + map->rank[i] = DDR_ADDRMAP_UNUSED; + + if (priv->info.ranks > 1) { + map->rank[0] = FIELD_GET(DDR_ADDRMAP_B0_M31, addrmap[0]); + map->rank[0] = map->rank[0] == DDR_ADDRMAP_MAX_31 ? + DDR_ADDRMAP_UNUSED : map->rank[0] + RANK_B0_BASE; + } + + if (priv->info.ranks > 2) { + map->rank[1] = FIELD_GET(DDR_ADDRMAP_B8_M31, addrmap[0]); + map->rank[1] = map->rank[1] == DDR_ADDRMAP_MAX_31 ? + DDR_ADDRMAP_UNUSED : map->rank[1] + RANK_B1_BASE; + } +} + +/** + * snps_get_addr_map - Get HIF/SDRAM/etc address map from CSRs. + * @priv: DDR memory controller private instance data. + * + * Parse the controller registers content creating the addresses mapping tables. + * They will be used for the erroneous and poison addresses encode/decode. + */ +static void snps_get_addr_map(struct snps_edac_priv *priv) +{ + u32 regval[DDR_ADDRMAP_NREGS]; + int i; + + for (i = 0; i < DDR_ADDRMAP_NREGS; i++) + regval[i] = readl(priv->baseaddr + DDR_ADDRMAP0_OFST + i * 4); + + snps_get_hif_row_map(priv, regval); + + snps_get_hif_col_map(priv, regval); + + snps_get_hif_bank_map(priv, regval); + + snps_get_hif_bankgrp_map(priv, regval); + + snps_get_hif_rank_map(priv, regval); +} + /** * snps_init_csrows - Initialize the csrow data. * @mci: EDAC memory controller instance. @@ -940,285 +1362,21 @@ DEFINE_SHOW_ATTRIBUTE(snps_ddrc_info); */ static void snps_data_poison_setup(struct snps_edac_priv *priv) { - int col = 0, row = 0, bank = 0, bankgrp = 0, rank = 0, regval; - int index; - ulong hif_addr = 0; - - hif_addr = priv->poison_addr >> 3; - - for (index = 0; index < DDR_MAX_ROW_SHIFT; index++) { - if (priv->row_shift[index]) - row |= (((hif_addr >> priv->row_shift[index]) & - BIT(0)) << index); - else - break; - } - - for (index = 0; index < DDR_MAX_COL_SHIFT; index++) { - if (priv->col_shift[index] || index < 3) - col |= (((hif_addr >> priv->col_shift[index]) & - BIT(0)) << index); - else - break; - } - - for (index = 0; index < DDR_MAX_BANK_SHIFT; index++) { - if (priv->bank_shift[index]) - bank |= (((hif_addr >> priv->bank_shift[index]) & - BIT(0)) << index); - else - break; - } - - for (index = 0; index < DDR_MAX_BANKGRP_SHIFT; index++) { - if (priv->bankgrp_shift[index]) - bankgrp |= (((hif_addr >> priv->bankgrp_shift[index]) - & BIT(0)) << index); - else - break; - } + struct snps_sdram_addr sdram; + u32 regval; - if (priv->rank_shift[0]) - rank = (hif_addr >> priv->rank_shift[0]) & BIT(0); + snps_map_sys_to_sdram(priv, priv->poison_addr, &sdram); - regval = FIELD_PREP(ECC_POISON0_RANK_MASK, rank) | - FIELD_PREP(ECC_POISON0_COL_MASK, col); + regval = FIELD_PREP(ECC_POISON0_RANK_MASK, sdram.rank) | + FIELD_PREP(ECC_POISON0_COL_MASK, sdram.col); writel(regval, priv->baseaddr + ECC_POISON0_OFST); - regval = FIELD_PREP(ECC_POISON1_BANKGRP_MASK, bankgrp) | - FIELD_PREP(ECC_POISON1_BANK_MASK, bank) | - FIELD_PREP(ECC_POISON1_ROW_MASK, row); + regval = FIELD_PREP(ECC_POISON1_BANKGRP_MASK, sdram.bankgrp) | + FIELD_PREP(ECC_POISON1_BANK_MASK, sdram.bank) | + FIELD_PREP(ECC_POISON1_ROW_MASK, sdram.row); writel(regval, priv->baseaddr + ECC_POISON1_OFST); } -static void snps_setup_row_address_map(struct snps_edac_priv *priv, u32 *addrmap) -{ - u32 addrmap_row_b2_10; - int index; - - priv->row_shift[0] = (addrmap[5] & ROW_MAX_VAL_MASK) + ROW_B0_BASE; - priv->row_shift[1] = ((addrmap[5] >> 8) & - ROW_MAX_VAL_MASK) + ROW_B1_BASE; - - addrmap_row_b2_10 = (addrmap[5] >> 16) & ROW_MAX_VAL_MASK; - if (addrmap_row_b2_10 != ROW_MAX_VAL_MASK) { - for (index = 2; index < 11; index++) - priv->row_shift[index] = addrmap_row_b2_10 + - index + ROW_B0_BASE; - - } else { - priv->row_shift[2] = (addrmap[9] & - ROW_MAX_VAL_MASK) + ROW_B2_BASE; - priv->row_shift[3] = ((addrmap[9] >> 8) & - ROW_MAX_VAL_MASK) + ROW_B3_BASE; - priv->row_shift[4] = ((addrmap[9] >> 16) & - ROW_MAX_VAL_MASK) + ROW_B4_BASE; - priv->row_shift[5] = ((addrmap[9] >> 24) & - ROW_MAX_VAL_MASK) + ROW_B5_BASE; - priv->row_shift[6] = (addrmap[10] & - ROW_MAX_VAL_MASK) + ROW_B6_BASE; - priv->row_shift[7] = ((addrmap[10] >> 8) & - ROW_MAX_VAL_MASK) + ROW_B7_BASE; - priv->row_shift[8] = ((addrmap[10] >> 16) & - ROW_MAX_VAL_MASK) + ROW_B8_BASE; - priv->row_shift[9] = ((addrmap[10] >> 24) & - ROW_MAX_VAL_MASK) + ROW_B9_BASE; - priv->row_shift[10] = (addrmap[11] & - ROW_MAX_VAL_MASK) + ROW_B10_BASE; - } - - priv->row_shift[11] = (((addrmap[5] >> 24) & ROW_MAX_VAL_MASK) == - ROW_MAX_VAL_MASK) ? 0 : (((addrmap[5] >> 24) & - ROW_MAX_VAL_MASK) + ROW_B11_BASE); - priv->row_shift[12] = ((addrmap[6] & ROW_MAX_VAL_MASK) == - ROW_MAX_VAL_MASK) ? 0 : ((addrmap[6] & - ROW_MAX_VAL_MASK) + ROW_B12_BASE); - priv->row_shift[13] = (((addrmap[6] >> 8) & ROW_MAX_VAL_MASK) == - ROW_MAX_VAL_MASK) ? 0 : (((addrmap[6] >> 8) & - ROW_MAX_VAL_MASK) + ROW_B13_BASE); - priv->row_shift[14] = (((addrmap[6] >> 16) & ROW_MAX_VAL_MASK) == - ROW_MAX_VAL_MASK) ? 0 : (((addrmap[6] >> 16) & - ROW_MAX_VAL_MASK) + ROW_B14_BASE); - priv->row_shift[15] = (((addrmap[6] >> 24) & ROW_MAX_VAL_MASK) == - ROW_MAX_VAL_MASK) ? 0 : (((addrmap[6] >> 24) & - ROW_MAX_VAL_MASK) + ROW_B15_BASE); - - if (priv->info.sdram_mode == MEM_DDR4 || priv->info.sdram_mode == MEM_LPDDR4) { - priv->row_shift[16] = ((addrmap[7] & ROW_MAX_VAL_MASK) == - ROW_MAX_VAL_MASK) ? 0 : ((addrmap[7] & - ROW_MAX_VAL_MASK) + ROW_B16_BASE); - priv->row_shift[17] = (((addrmap[7] >> 8) & ROW_MAX_VAL_MASK) == - ROW_MAX_VAL_MASK) ? 0 : (((addrmap[7] >> 8) & - ROW_MAX_VAL_MASK) + ROW_B17_BASE); - } -} - -static void snps_setup_column_address_map(struct snps_edac_priv *priv, u32 *addrmap) -{ - int index; - - priv->col_shift[0] = 0; - priv->col_shift[1] = 1; - priv->col_shift[2] = (addrmap[2] & COL_MAX_VAL_MASK) + COL_B2_BASE; - priv->col_shift[3] = ((addrmap[2] >> 8) & - COL_MAX_VAL_MASK) + COL_B3_BASE; - priv->col_shift[4] = (((addrmap[2] >> 16) & COL_MAX_VAL_MASK) == - COL_MAX_VAL_MASK) ? 0 : (((addrmap[2] >> 16) & - COL_MAX_VAL_MASK) + COL_B4_BASE); - priv->col_shift[5] = (((addrmap[2] >> 24) & COL_MAX_VAL_MASK) == - COL_MAX_VAL_MASK) ? 0 : (((addrmap[2] >> 24) & - COL_MAX_VAL_MASK) + COL_B5_BASE); - priv->col_shift[6] = ((addrmap[3] & COL_MAX_VAL_MASK) == - COL_MAX_VAL_MASK) ? 0 : ((addrmap[3] & - COL_MAX_VAL_MASK) + COL_B6_BASE); - priv->col_shift[7] = (((addrmap[3] >> 8) & COL_MAX_VAL_MASK) == - COL_MAX_VAL_MASK) ? 0 : (((addrmap[3] >> 8) & - COL_MAX_VAL_MASK) + COL_B7_BASE); - priv->col_shift[8] = (((addrmap[3] >> 16) & COL_MAX_VAL_MASK) == - COL_MAX_VAL_MASK) ? 0 : (((addrmap[3] >> 16) & - COL_MAX_VAL_MASK) + COL_B8_BASE); - priv->col_shift[9] = (((addrmap[3] >> 24) & COL_MAX_VAL_MASK) == - COL_MAX_VAL_MASK) ? 0 : (((addrmap[3] >> 24) & - COL_MAX_VAL_MASK) + COL_B9_BASE); - if (priv->info.dq_mode == SNPS_DQ_FULL) { - if (priv->info.sdram_mode == MEM_LPDDR3) { - priv->col_shift[10] = ((addrmap[4] & - COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : - ((addrmap[4] & COL_MAX_VAL_MASK) + - COL_B10_BASE); - priv->col_shift[11] = (((addrmap[4] >> 8) & - COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : - (((addrmap[4] >> 8) & COL_MAX_VAL_MASK) + - COL_B11_BASE); - } else { - priv->col_shift[11] = ((addrmap[4] & - COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : - ((addrmap[4] & COL_MAX_VAL_MASK) + - COL_B10_BASE); - priv->col_shift[13] = (((addrmap[4] >> 8) & - COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : - (((addrmap[4] >> 8) & COL_MAX_VAL_MASK) + - COL_B11_BASE); - } - } else if (priv->info.dq_mode == SNPS_DQ_HALF) { - if (priv->info.sdram_mode == MEM_LPDDR3) { - priv->col_shift[10] = (((addrmap[3] >> 24) & - COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : - (((addrmap[3] >> 24) & COL_MAX_VAL_MASK) + - COL_B9_BASE); - priv->col_shift[11] = ((addrmap[4] & - COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : - ((addrmap[4] & COL_MAX_VAL_MASK) + - COL_B10_BASE); - } else { - priv->col_shift[11] = (((addrmap[3] >> 24) & - COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : - (((addrmap[3] >> 24) & COL_MAX_VAL_MASK) + - COL_B9_BASE); - priv->col_shift[13] = ((addrmap[4] & - COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : - ((addrmap[4] & COL_MAX_VAL_MASK) + - COL_B10_BASE); - } - } else { - if (priv->info.sdram_mode == MEM_LPDDR3) { - priv->col_shift[10] = (((addrmap[3] >> 16) & - COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : - (((addrmap[3] >> 16) & COL_MAX_VAL_MASK) + - COL_B8_BASE); - priv->col_shift[11] = (((addrmap[3] >> 24) & - COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : - (((addrmap[3] >> 24) & COL_MAX_VAL_MASK) + - COL_B9_BASE); - } else { - priv->col_shift[11] = (((addrmap[3] >> 16) & - COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : - (((addrmap[3] >> 16) & COL_MAX_VAL_MASK) + - COL_B8_BASE); - priv->col_shift[13] = (((addrmap[3] >> 24) & - COL_MAX_VAL_MASK) == COL_MAX_VAL_MASK) ? 0 : - (((addrmap[3] >> 24) & COL_MAX_VAL_MASK) + - COL_B9_BASE); - } - } - - if (priv->info.dq_mode) { - for (index = 9; index > priv->info.dq_mode; index--) { - priv->col_shift[index] = - priv->col_shift[index - priv->info.dq_mode]; - priv->col_shift[index - priv->info.dq_mode] = 0; - } - } - -} - -static void snps_setup_bank_address_map(struct snps_edac_priv *priv, u32 *addrmap) -{ - priv->bank_shift[0] = (addrmap[1] & BANK_MAX_VAL_MASK) + BANK_B0_BASE; - priv->bank_shift[1] = ((addrmap[1] >> 8) & - BANK_MAX_VAL_MASK) + BANK_B1_BASE; - priv->bank_shift[2] = (((addrmap[1] >> 16) & - BANK_MAX_VAL_MASK) == BANK_MAX_VAL_MASK) ? 0 : - (((addrmap[1] >> 16) & BANK_MAX_VAL_MASK) + - BANK_B2_BASE); - -} - -static void snps_setup_bg_address_map(struct snps_edac_priv *priv, u32 *addrmap) -{ - /* Bank group signals are available on the DDR4 memory only */ - if (priv->info.sdram_mode != MEM_DDR4) - return; - - priv->bankgrp_shift[0] = (addrmap[8] & - BANKGRP_MAX_VAL_MASK) + BANKGRP_B0_BASE; - priv->bankgrp_shift[1] = (((addrmap[8] >> 8) & BANKGRP_MAX_VAL_MASK) == - BANKGRP_MAX_VAL_MASK) ? 0 : (((addrmap[8] >> 8) - & BANKGRP_MAX_VAL_MASK) + BANKGRP_B1_BASE); - -} - -static void snps_setup_rank_address_map(struct snps_edac_priv *priv, u32 *addrmap) -{ - /* Ranks mapping is unavailable for the single-ranked memory */ - if (priv->info.ranks > 1) { - priv->rank_shift[0] = ((addrmap[0] & RANK_MAX_VAL_MASK) == - RANK_MAX_VAL_MASK) ? 0 : ((addrmap[0] & - RANK_MAX_VAL_MASK) + RANK_B0_BASE); - } -} - -/** - * snps_setup_address_map - Set Address Map by querying ADDRMAP registers. - * @priv: DDR memory controller private instance data. - * - * Set Address Map by querying ADDRMAP registers. - * - * Return: none. - */ -static void snps_setup_address_map(struct snps_edac_priv *priv) -{ - u32 addrmap[12]; - int index; - - for (index = 0; index < 12; index++) { - u32 addrmap_offset; - - addrmap_offset = DDR_ADDRMAP0_OFST + (index * 4); - addrmap[index] = readl(priv->baseaddr + addrmap_offset); - } - - snps_setup_row_address_map(priv, addrmap); - - snps_setup_column_address_map(priv, addrmap); - - snps_setup_bank_address_map(priv, addrmap); - - snps_setup_bg_address_map(priv, addrmap); - - snps_setup_rank_address_map(priv, addrmap); -} - static ssize_t snps_inject_data_error_read(struct file *filep, char __user *ubuf, size_t size, loff_t *offp) { @@ -1311,10 +1469,6 @@ SNPS_DEBUGFS_FOPS(snps_inject_data_poison, snps_inject_data_poison_read, */ static void snps_create_debugfs_nodes(struct mem_ctl_info *mci) { - struct snps_edac_priv *priv = mci->pvt_info; - - snps_setup_address_map(priv); - edac_debugfs_create_file("ddrc_info", 0400, mci->debugfs, mci, &snps_ddrc_info_fops); @@ -1354,6 +1508,8 @@ static int snps_mc_probe(struct platform_device *pdev) if (rc) return rc; + snps_get_addr_map(priv); + mci = snps_mc_create(priv); if (IS_ERR(mci)) return PTR_ERR(mci); From patchwork Wed Sep 20 19:26:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2123C04FF5 for ; Wed, 20 Sep 2023 19:29:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230100AbjITT3r (ORCPT ); Wed, 20 Sep 2023 15:29:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230136AbjITT3Z (ORCPT ); Wed, 20 Sep 2023 15:29:25 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E534DE5; Wed, 20 Sep 2023 12:29:05 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-501bd6f7d11so387209e87.1; Wed, 20 Sep 2023 12:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238144; x=1695842944; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c4SLo29ZsWRxmXYEq5pouZGHA4AJYrYqVFNN0wYQp34=; b=dM/61Eo0GXvnTyd1VzZ8dOz+7u2YIHREyMkebKzI03yrsaXZBBQYxwA3w9r/+q4k6Y GepmN2adF9r/y9FUejuobvwMQCX1UHbG854FZZfYS7sSLB2/Saf6+q4W9msYR9db/Atw HCFUVELMLqilQQs55dhR1evTUxQ51DXqzAmOBs91LTf/ceEtdeJ1iJQGSJeg9e6Ba7zJ qMD0HAEXyFkXrttJPXrG3yNGbHyWhwg/A9tUKICFFD5i5e/YOjjvQIhZvvbUEfc1E0bp OpODI+y8xZOVAE40gki4kpZpCJeR/OOP4n1t1hFEW12TrMGgSqQZrR4ZkGNRn3NuIguW zCgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238144; x=1695842944; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c4SLo29ZsWRxmXYEq5pouZGHA4AJYrYqVFNN0wYQp34=; b=rcRrMrgw8+D1GvwGWajBs1BAZ2fSPaGSMcfeeXQCqQXCja92KjxEIzCuaxZEVwC23P b7uZKpU3Xyb97qwUfY33FvnWCNr0eIoF4zkAMyrULei/ZsO+q7i54U3u/iwnvgz/jHyL tYksl17A2Tws4XAS01imv8c487aseNCguDSzr/k9qc3TIt0IxnuoM9mLwUD9pSZAB+/+ KdIYYvorW6EGOmjkXFb21ru+Pser0pwaU6tKgsrCt/XTcFc6F4xF8YrEL+V9vZ2H29b1 N1h0I7guOsAbLml4wjcXuMKfouzqkHxGQAH/PUB5GyywyrVOFSKYh03ZUFCJ9pd88HkP 96DA== X-Gm-Message-State: AOJu0YyJH9SLvaMsLCdRy4qWk8uh9KEFbNpqainFJ0b5r29JiXAK1b9c 4za5VuQCz4eJg8OBUeBPMC0= X-Google-Smtp-Source: AGHT+IE61sBSRYaEasfvKoNub8Bh9Qbify371yZ1L9/rJ06IVapYKu9pHIJzUaCgHNrlId97sqmRMA== X-Received: by 2002:ac2:5b1d:0:b0:500:9214:b308 with SMTP id v29-20020ac25b1d000000b005009214b308mr3264451lfn.65.1695238143992; Wed, 20 Sep 2023 12:29:03 -0700 (PDT) Received: from localhost ([85.26.234.143]) by smtp.gmail.com with ESMTPSA id v10-20020ac2560a000000b00501ce5c2e4asm542921lfd.262.2023.09.20.12.29.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:29:03 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 14/18] EDAC/synopsys: Simplify HIF/SDRAM column mapping get procedure Date: Wed, 20 Sep 2023 22:26:59 +0300 Message-ID: <20230920192806.29960-15-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org What is currently implemented in the driver by means of the multiple if-else-if-else statements in fact is described in the hardware reference manual [1]. It says: 1. All of the column bits shift up 1 bit when only half of the data bus is in use. (In this case, for instance, you need to look at ADDRMAP3.addrmap_col_b6 instead to determine the value of column address bit 7.) 2. All of the column bits shift up 2 bits when only a quarter of the data bus is in use. (In this case, for instance, you need to look at ADDRMAP2.addrmap_col_b5 instead to determine the value of column address bit 7.) 3. In addition to the above, the column bit 10 is reserved for the auto-precharge command in DDR2/3/4/mDDR. So the column bits must be further shifted up 1 bit when one of these DDR protocols is enabled. So taking into account all of the notes above and what the column bit 12 is always reserved, the SDRAM column bits mapping procedure can be significantly simplified: initially read the mapping as if for the LPDDR2/3/4 memory with Full DQ-bus utilized; then shift the column bits up in accordance with the detected DQ-bus width mode. That's it. Simple, canonical and scalable. [1] DesignWare® Cores Enhanced Universal DDR Memory Controller (uMCTL2) Databook, Version 3.91a, October 2020, p.154 Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 83 ++++++++++++------------------------ 1 file changed, 27 insertions(+), 56 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index 204d7f1fc7e2..a359018c261c 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -996,8 +996,22 @@ static void snps_get_hif_col_map(struct snps_edac_priv *priv, u32 *addrmap) map->col[9] = map->col[9] == DDR_ADDRMAP_MAX_15 ? DDR_ADDRMAP_UNUSED : map->col[9] + COL_B9_BASE; + map->col[10] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[4]); + map->col[10] = map->col[10] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[10] + COL_B10_BASE; + + map->col[11] = FIELD_GET(DDR_ADDRMAP_B8_M15, addrmap[4]); + map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? + DDR_ADDRMAP_UNUSED : map->col[11] + COL_B11_BASE; + + /* + * In case of the non-Full DQ bus mode the lowest columns are + * unmapped and used by the controller to read the full DQ word + * in multiple cycles (col[0] for the Half bus mode, col[0:1] for + * the Quarter bus mode). + */ if (priv->info.dq_mode) { - for (i = 9; i > priv->info.dq_mode; i--) { + for (i = 11 + priv->info.dq_mode; i >= priv->info.dq_mode; i--) { map->col[i] = map->col[i - priv->info.dq_mode]; map->col[i - priv->info.dq_mode] = DDR_ADDRMAP_UNUSED; } @@ -1007,65 +1021,22 @@ static void snps_get_hif_col_map(struct snps_edac_priv *priv, u32 *addrmap) * Per JEDEC DDR2/3/4/mDDR specification, column address bit 10 is * reserved for indicating auto-precharge, and hence no source * address bit can be mapped to col[10]. + */ + if (priv->info.sdram_mode == MEM_LPDDR || priv->info.sdram_mode == MEM_DDR2 || + priv->info.sdram_mode == MEM_DDR3 || priv->info.sdram_mode == MEM_DDR4) { + for (i = 12 + priv->info.dq_mode; i > 10; i--) { + map->col[i] = map->col[i - 1]; + map->col[i - 1] = DDR_ADDRMAP_UNUSED; + } + } + + /* * Per JEDEC specification, column address bit 12 is reserved * for the Burst-chop status, so no source address bit mapping * for col[12] either. */ - if (priv->info.dq_mode == SNPS_DQ_FULL) { - if (priv->info.sdram_mode == MEM_LPDDR3) { - map->col[10] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[4]); - map->col[10] = map->col[10] == DDR_ADDRMAP_MAX_15 ? - DDR_ADDRMAP_UNUSED : map->col[10] + COL_B10_BASE; - - map->col[11] = FIELD_GET(DDR_ADDRMAP_B8_M15, addrmap[4]); - map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? - DDR_ADDRMAP_UNUSED : map->col[11] + COL_B11_BASE; - } else { - map->col[11] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[4]); - map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? - DDR_ADDRMAP_UNUSED : map->col[11] + COL_B10_BASE; - - map->col[13] = FIELD_GET(DDR_ADDRMAP_B8_M15, addrmap[4]); - map->col[13] = map->col[13] == DDR_ADDRMAP_MAX_15 ? - DDR_ADDRMAP_UNUSED : map->col[13] + COL_B11_BASE; - } - } else if (priv->info.dq_mode == SNPS_DQ_HALF) { - if (priv->info.sdram_mode == MEM_LPDDR3) { - map->col[10] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[3]); - map->col[10] = map->col[10] == DDR_ADDRMAP_MAX_15 ? - DDR_ADDRMAP_UNUSED : map->col[10] + COL_B9_BASE; - - map->col[11] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[4]); - map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? - DDR_ADDRMAP_UNUSED : map->col[11] + COL_B10_BASE; - } else { - map->col[11] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[3]); - map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? - DDR_ADDRMAP_UNUSED : map->col[11] + COL_B9_BASE; - - map->col[13] = FIELD_GET(DDR_ADDRMAP_B0_M15, addrmap[4]); - map->col[13] = map->col[13] == DDR_ADDRMAP_MAX_15 ? - DDR_ADDRMAP_UNUSED : map->col[13] + COL_B10_BASE; - } - } else { - if (priv->info.sdram_mode == MEM_LPDDR3) { - map->col[10] = FIELD_GET(DDR_ADDRMAP_B16_M15, addrmap[3]); - map->col[10] = map->col[10] == DDR_ADDRMAP_MAX_15 ? - DDR_ADDRMAP_UNUSED : map->col[10] + COL_B8_BASE; - - map->col[11] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[3]); - map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? - DDR_ADDRMAP_UNUSED : map->col[11] + COL_B9_BASE; - } else { - map->col[11] = FIELD_GET(DDR_ADDRMAP_B16_M15, addrmap[3]); - map->col[11] = map->col[11] == DDR_ADDRMAP_MAX_15 ? - DDR_ADDRMAP_UNUSED : map->col[11] + COL_B8_BASE; - - map->col[11] = FIELD_GET(DDR_ADDRMAP_B24_M15, addrmap[3]); - map->col[13] = map->col[13] == DDR_ADDRMAP_MAX_15 ? - DDR_ADDRMAP_UNUSED : map->col[13] + COL_B9_BASE; - } - } + map->col[13] = map->col[12]; + map->col[12] = DDR_ADDRMAP_UNUSED; } /** From patchwork Wed Sep 20 19:27:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393350 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AF82C04FF3 for ; Wed, 20 Sep 2023 19:36:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229475AbjITTg3 (ORCPT ); Wed, 20 Sep 2023 15:36:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbjITT3d (ORCPT ); Wed, 20 Sep 2023 15:29:33 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 924F1CD9; Wed, 20 Sep 2023 12:29:13 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-50317080342so408894e87.2; Wed, 20 Sep 2023 12:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695238151; x=1695842951; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ruI/DsrXUPHPt+yo4IDD0wOJzQ+cTuT8XaOYtD4sKFA=; b=XeAT/oXQ8jOHcpye/2I707yLdkIKkUrLGctawH4fa4AWrg2al0EoIkp6ONqyZL/SKi VBuJpc2D2q+36v7LBWbBAdwfVFwV47n7zssJjKZfSSBFz1ZS3a8toboU2zaYPg8VYFGF kOdso5k+RbLGtGIYcnKpQpRHqARltWzugjBf/jYwf/LR/BNiR8rn0QyGw4ftO1dIhaIr TnvRJar7wcHbpEhXNhgpnzKwGgLV+ikQ6pRq5HaWS5JY5XFLrYis3C3/TNUMpOQuGt0c +/rYfrhKweET9CnYGiwthl2Tn/IdHOgelQCDiT7yCUPmfu2awPP+Y+yameWH3U3715UF 2wiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695238151; x=1695842951; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ruI/DsrXUPHPt+yo4IDD0wOJzQ+cTuT8XaOYtD4sKFA=; b=vs5en5tmw9MeZTYcSCj+pzTVi85lcE96SMV4OIEGG1fUkQRCAgZ+C5aLcsn2N8A0Qj GBlmHsFEg/x7hsvf2NtvVgNCsL1xg+c2cr9Rjnn9HF40b4TrBKOJVv9QxbjhOr1CrO3b +Hm86wgcoNh7EmsLLvK/aLzjQ42Tj26+B1qsEEO2N1UX7TUSyMfWikvbC2piZPFqFUGy k5q3ZnPYQXuV/b08tqlfkN2cGslKI6pejwhRylSSRqkhMOTf/5P3PJd3FCU2E8Xqm0t+ Fm1ffgcQiGeYSou347GVgroFa6lm3L+e/2Klse4HfdJGtxbU0mxVBs+5ReqbzHltsfgy yr3A== X-Gm-Message-State: AOJu0YwGdoAq4wgKY5xZ4s+VikvYuS8gK2Ziy74rrDs9g7ke8Womh83T XFYhAxJmTvyuIuNS+ABzz7g= X-Google-Smtp-Source: AGHT+IGNZjm+wfCwzWQAszOVACunejknYU5hlY3VaoId/Y1DBikEzHrl+fcXMYzw4TlI07AA56CvxQ== X-Received: by 2002:a05:6512:3f1:b0:500:91ac:c0b5 with SMTP id n17-20020a05651203f100b0050091acc0b5mr2883240lfq.30.1695238151186; Wed, 20 Sep 2023 12:29:11 -0700 (PDT) Received: from localhost ([178.176.86.251]) by smtp.gmail.com with ESMTPSA id z23-20020ac25df7000000b004fdde1db756sm2808772lfq.26.2023.09.20.12.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:29:10 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 15/18] EDAC/synopsys: Add HIF/SDRAM mapping debugfs node Date: Wed, 20 Sep 2023 22:27:00 +0300 Message-ID: <20230920192806.29960-16-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Since the available address mapping is about to be utilized for the erroneous SDRAM address decode, before adding such functionality it will be useful to have a way to get an info regarding the most complicated part of the address translation - HIF/SDRAM mapping table just in case something gets wrong in the implemented translation procedures. So add the DebugFS node which on read returns the HIF/SDRAM mapping table in the hexdump-like manner: first line contains the HIF address bit position units, first column contains the HIF address bit position tens, the line and column intersections have the SDRAM dimension (row/column/bank/etc) and a bit position used to encode the corresponding HIF address bit. Note DW uMCTL2 DDRC IP-core doesn't have a parameter to set the HIF address width. So the maximum value (60 bits) of the UMCTL2_A_ADDRW synthesize parameter [1] is utilized as the maximum HIF address width. That parameter defines the controller ports address bus width and in case if the DQ bus width equals to eight bytes defines the HIF address width too. So its upper constraints is fully applicable in this case. [1] DesignWare® Cores Enhanced Universal DDR Memory Controller (uMCTL2) Databook, Version 3.91a, October 2020, p.515 Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 82 ++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index a359018c261c..6b8949c66eef 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -156,6 +156,7 @@ /* DDRC address mapping parameters */ #define DDR_ADDRMAP_NREGS 12 +#define DDR_MAX_HIF_WIDTH 60 #define DDR_MAX_ROW_WIDTH 18 #define DDR_MAX_COL_WIDTH 14 #define DDR_MAX_BANK_WIDTH 3 @@ -1324,6 +1325,84 @@ static int snps_ddrc_info_show(struct seq_file *s, void *data) DEFINE_SHOW_ATTRIBUTE(snps_ddrc_info); +static u8 snps_find_sdram_dim(struct snps_edac_priv *priv, u8 hif, char *dim) +{ + struct snps_hif_sdram_map *map = &priv->hif_sdram_map; + int i; + + for (i = 0; i < DDR_MAX_ROW_WIDTH; i++) { + if (map->row[i] == hif) { + *dim = 'r'; + return i; + } + } + + for (i = 0; i < DDR_MAX_COL_WIDTH; i++) { + if (map->col[i] == hif) { + *dim = 'c'; + return i; + } + } + + for (i = 0; i < DDR_MAX_BANK_WIDTH; i++) { + if (map->bank[i] == hif) { + *dim = 'b'; + return i; + } + } + + for (i = 0; i < DDR_MAX_BANKGRP_WIDTH; i++) { + if (map->bankgrp[i] == hif) { + *dim = 'g'; + return i; + } + } + + for (i = 0; i < DDR_MAX_RANK_WIDTH; i++) { + if (map->rank[i] == hif) { + *dim = 'a'; + return i; + } + } + + return DDR_ADDRMAP_UNUSED; +} + +static int snps_hif_sdram_map_show(struct seq_file *s, void *data) +{ + struct mem_ctl_info *mci = s->private; + struct snps_edac_priv *priv = mci->pvt_info; + char dim, buf[SNPS_DBGFS_BUF_LEN]; + const int line_len = 10; + u8 bit; + int i; + + seq_printf(s, "%3s", ""); + for (i = 0; i < line_len; i++) + seq_printf(s, " %02d ", i); + + for (i = 0; i < DDR_MAX_HIF_WIDTH; i++) { + if (i % line_len == 0) + seq_printf(s, "\n%02d ", i); + + bit = snps_find_sdram_dim(priv, i, &dim); + + if (bit != DDR_ADDRMAP_UNUSED) + scnprintf(buf, SNPS_DBGFS_BUF_LEN, "%c%hhu", dim, bit); + else + scnprintf(buf, SNPS_DBGFS_BUF_LEN, "--"); + + seq_printf(s, "%3s ", buf); + } + seq_putc(s, '\n'); + + seq_puts(s, "r - row, c - column, b - bank, g - bank group, a - rank\n"); + + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(snps_hif_sdram_map); + /** * snps_data_poison_setup - Update poison registers. * @priv: DDR memory controller private instance data. @@ -1443,6 +1522,9 @@ static void snps_create_debugfs_nodes(struct mem_ctl_info *mci) edac_debugfs_create_file("ddrc_info", 0400, mci->debugfs, mci, &snps_ddrc_info_fops); + edac_debugfs_create_file("hif_sdram_map", 0400, mci->debugfs, mci, + &snps_hif_sdram_map_fops); + edac_debugfs_create_file("inject_data_error", 0600, mci->debugfs, mci, &snps_inject_data_error); From patchwork Wed Sep 20 19:46:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393352 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16824C04FEE for ; Wed, 20 Sep 2023 19:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229508AbjITTrW (ORCPT ); Wed, 20 Sep 2023 15:47:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjITTrW (ORCPT ); Wed, 20 Sep 2023 15:47:22 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FFC5B9; Wed, 20 Sep 2023 12:47:15 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-502153ae36cso382930e87.3; Wed, 20 Sep 2023 12:47:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695239233; x=1695844033; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LsdrfYeqptfMWbElOCcxrDUsL4RROO8o0AF8EPJzHss=; b=c/gRjfOw9dmTnxtzo7sBfACCqEXDPfz98CVaBXUfyrxX4u+W+QnBKBs0V1XtMj57RY c47vQ/5foZQZSFJiVzGUUyFMGFGQA4+pHHn4R1O5qkOwd5JtLvE7E2hca7JpsRpJg88U VPcK+bu5QjN5F0T97OHCP8T41jam/4cIGkusnD/fCw/sO/YHjpos6/FpcgydiVzmVPbg Fhe6O4IkRUy5b2u2OMJ4PSj3kr6ZIOrErYV3HvTnykKNvMrl/NADrFsK3ivZIjW+58pH ad7BWLwJwp72O2PX0hhaZTLMkE6srNdJ8O9Hp91XW40WcIGKoZXzZvp7PnNf2uowhCIL rXVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695239233; x=1695844033; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LsdrfYeqptfMWbElOCcxrDUsL4RROO8o0AF8EPJzHss=; b=iQrWqaz+Vzt1BS4foztSAHkW8235wFkKTlnT8PCzk27H0qXRWyI86f5YyZcwy5fcb3 Ri0vlAgwck0VAkI6OH3CeulqrmIwQ8bFNsXQNqJ0wL5zOTlNbbBQvwZ6x2F0IYQFQ96r nYEPh+oV+96dN1sTcTR+1+ZlZaEwrVs13bXIhf04CSCEtCu1qJLGadNO0FdpZqwpYw+5 nIvLgYq+EuImFYW+3dJ79c6HWwMSjD8u8GgUrV2OEXG66GTLfOEDsjfM56nX00whvo7H 6B6Oc321e8sVyhqke813zmhfxfTBHQC3Y68XfpBE6yH+DKylzrcFIg406L0ImnBCmUwo gqBg== X-Gm-Message-State: AOJu0YwO3aP12wNyQPNmi5x/JlOKyOPp6ADsbDsc4lLzwOthSQC3HPFv aKRtBW1s3NYq+ONcxCMnVms= X-Google-Smtp-Source: AGHT+IF2EECUChEDs96AZIqyG2t+5+DnqORvDjSbDx+3X391xaVVAM70vp3LMepGVoihIJSTPWJe+g== X-Received: by 2002:a2e:96c4:0:b0:2bd:1804:29fa with SMTP id d4-20020a2e96c4000000b002bd180429famr3383605ljj.39.1695239233454; Wed, 20 Sep 2023 12:47:13 -0700 (PDT) Received: from localhost ([178.176.81.142]) by smtp.gmail.com with ESMTPSA id v5-20020a2e7a05000000b002bcda31af28sm3240999ljc.42.2023.09.20.12.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:47:12 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 16/18] EDAC/synopsys: Add erroneous page-frame/offset reporting Date: Wed, 20 Sep 2023 22:46:53 +0300 Message-ID: <20230920194656.30879-1-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org A full System/SDRAM address translation interface is now available. Use it to determine the system address causing the ECC faults: add the System-> Application->HIF->SDRAM address translation procedures based on the DW uMCTL2 DDRC DQ-bus config and HIF/SDRAM mapping table retrieved on the device probe stage; for the sake of simplification convert the snps_ecc_error_info structure to containing the snps_sdram_addr structure instance, since the erroneous SDRAM address will now participate in the address translation chain; issue the SDRAM->System address translation before passing the later to the edac_mc_handle_error() method. Note the ECC address rank needs to be retrieved now too in order to determine a correct system address. But the rank won't be passed to the MCI core for now since the MCI device is registered with a single ranked layer 0. Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 143 +++++++++++++++++++++++++++++------ 1 file changed, 118 insertions(+), 25 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index 6b8949c66eef..5384e93ec58c 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -346,20 +347,14 @@ struct snps_sdram_addr { /** * struct snps_ecc_error_info - ECC error log information. - * @row: Row number. - * @col: Column number. - * @bank: Bank number. - * @bankgrp: Bank group number. + * @sdram: SDRAM address. * @syndrome: Error syndrome. * @bitpos: Bit position. * @data: Data causing the error. * @ecc: Data ECC. */ struct snps_ecc_error_info { - u32 row; - u32 col; - u32 bank; - u32 bankgrp; + struct snps_sdram_addr sdram; u32 syndrome; u32 bitpos; u64 data; @@ -420,6 +415,21 @@ static void snps_map_app_to_hif(struct snps_edac_priv *priv, *hif = app >> priv->info.dq_width; } +/** + * snps_map_hif_to_app - Map HIF address to Application address. + * @priv: DDR memory controller private instance data. + * @hif: HIF address (source). + * @app: Application address (destination). + * + * Backward HIF-to-App translation is just the opposite DQ-width-based + * shift operation. + */ +static void snps_map_hif_to_app(struct snps_edac_priv *priv, + u64 hif, u64 *app) +{ + *app = hif << priv->info.dq_width; +} + /** * snps_map_hif_to_sdram - Map HIF address to SDRAM address. * @priv: DDR memory controller private instance data. @@ -471,6 +481,58 @@ static void snps_map_hif_to_sdram(struct snps_edac_priv *priv, } } +/** + * snps_map_sdram_to_hif - Map SDRAM address to HIF address. + * @priv: DDR memory controller private instance data. + * @sdram: SDRAM address (source). + * @hif: HIF address (destination). + * + * SDRAM-HIF address mapping is similar to the HIF-SDRAM mapping procedure, but + * we'll traverse each SDRAM rank/bank/column/row bit. + * + * Note the unmapped bits of the SDRAM address components will be just + * ignored. So make sure the source address is valid. + */ +static void snps_map_sdram_to_hif(struct snps_edac_priv *priv, + struct snps_sdram_addr *sdram, u64 *hif) +{ + struct snps_hif_sdram_map *map = &priv->hif_sdram_map; + unsigned long addr; + int i; + + *hif = 0; + + addr = sdram->row; + for_each_set_bit(i, &addr, DDR_MAX_ROW_WIDTH) { + if (map->row[i] != DDR_ADDRMAP_UNUSED) + *hif |= BIT_ULL(map->row[i]); + } + + addr = sdram->col; + for_each_set_bit(i, &addr, DDR_MAX_COL_WIDTH) { + if (map->col[i] != DDR_ADDRMAP_UNUSED) + *hif |= BIT_ULL(map->col[i]); + } + + addr = sdram->bank; + for_each_set_bit(i, &addr, DDR_MAX_BANK_WIDTH) { + if (map->bank[i] != DDR_ADDRMAP_UNUSED) + *hif |= BIT_ULL(map->bank[i]); + } + + addr = sdram->bankgrp; + for_each_set_bit(i, &addr, DDR_MAX_BANKGRP_WIDTH) { + if (map->bankgrp[i] != DDR_ADDRMAP_UNUSED) + *hif |= BIT_ULL(map->bankgrp[i]); + } + + addr = sdram->rank; + for_each_set_bit(i, &addr, DDR_MAX_RANK_WIDTH) { + if (map->rank[i] != DDR_ADDRMAP_UNUSED) + *hif |= BIT_ULL(map->rank[i]); + } +} + /** * snps_map_sys_to_sdram - Map System address to SDRAM address. * @priv: DDR memory controller private instance data. @@ -492,6 +554,27 @@ static void snps_map_sys_to_sdram(struct snps_edac_priv *priv, snps_map_hif_to_sdram(priv, hif, sdram); } +/** + * snps_map_sdram_to_sys - Map SDRAM address to SDRAM address. + * @priv: DDR memory controller private instance data. + * @sys: System address (source). + * @sdram: SDRAM address (destination). + * + * Perform a full mapping of the SDRAM address (row/column/bank/etc) to + * the system address specific to the controller system bus ports. + */ +static void snps_map_sdram_to_sys(struct snps_edac_priv *priv, + struct snps_sdram_addr *sdram, dma_addr_t *sys) +{ + u64 app, hif; + + snps_map_sdram_to_hif(priv, sdram, &hif); + + snps_map_hif_to_app(priv, hif, &app); + + *sys = app; +} + /** * snps_get_bitpos - Get DQ-bus corrected bit position. * @syndrome: Error syndrome. @@ -544,12 +627,13 @@ static int snps_get_error_info(struct snps_edac_priv *priv) p->ceinfo.bitpos = snps_get_bitpos(p->ceinfo.syndrome, priv->info.dq_width); regval = readl(base + ECC_CEADDR0_OFST); - p->ceinfo.row = FIELD_GET(ECC_CEADDR0_ROW_MASK, regval); + p->ceinfo.sdram.rank = FIELD_GET(ECC_CEADDR0_RANK_MASK, regval); + p->ceinfo.sdram.row = FIELD_GET(ECC_CEADDR0_ROW_MASK, regval); regval = readl(base + ECC_CEADDR1_OFST); - p->ceinfo.bank = FIELD_GET(ECC_CEADDR1_BANK_MASK, regval); - p->ceinfo.bankgrp = FIELD_GET(ECC_CEADDR1_BANKGRP_MASK, regval); - p->ceinfo.col = FIELD_GET(ECC_CEADDR1_COL_MASK, regval); + p->ceinfo.sdram.bankgrp = FIELD_GET(ECC_CEADDR1_BANKGRP_MASK, regval); + p->ceinfo.sdram.bank = FIELD_GET(ECC_CEADDR1_BANK_MASK, regval); + p->ceinfo.sdram.col = FIELD_GET(ECC_CEADDR1_COL_MASK, regval); p->ceinfo.data = readl(base + ECC_CSYND0_OFST); if (priv->info.dq_width == SNPS_DQ_64) @@ -562,12 +646,13 @@ static int snps_get_error_info(struct snps_edac_priv *priv) goto out; regval = readl(base + ECC_UEADDR0_OFST); - p->ueinfo.row = FIELD_GET(ECC_CEADDR0_ROW_MASK, regval); + p->ueinfo.sdram.rank = FIELD_GET(ECC_CEADDR0_RANK_MASK, regval); + p->ueinfo.sdram.row = FIELD_GET(ECC_CEADDR0_ROW_MASK, regval); regval = readl(base + ECC_UEADDR1_OFST); - p->ueinfo.bankgrp = FIELD_GET(ECC_CEADDR1_BANKGRP_MASK, regval); - p->ueinfo.bank = FIELD_GET(ECC_CEADDR1_BANK_MASK, regval); - p->ueinfo.col = FIELD_GET(ECC_CEADDR1_COL_MASK, regval); + p->ueinfo.sdram.bankgrp = FIELD_GET(ECC_CEADDR1_BANKGRP_MASK, regval); + p->ueinfo.sdram.bank = FIELD_GET(ECC_CEADDR1_BANK_MASK, regval); + p->ueinfo.sdram.col = FIELD_GET(ECC_CEADDR1_COL_MASK, regval); p->ueinfo.data = readl(base + ECC_UESYND0_OFST); if (priv->info.dq_width == SNPS_DQ_64) @@ -599,31 +684,39 @@ static void snps_handle_error(struct mem_ctl_info *mci, struct snps_ecc_status * { struct snps_edac_priv *priv = mci->pvt_info; struct snps_ecc_error_info *pinf; + dma_addr_t sys; if (p->ce_cnt) { pinf = &p->ceinfo; + snps_map_sdram_to_sys(priv, &pinf->sdram, &sys); + snprintf(priv->message, SNPS_EDAC_MSG_SIZE, - "Row %d Col %d Bank %d Bank Group %d Bit %d Data 0x%08llx:0x%02x", - pinf->row, pinf->col, pinf->bank, pinf->bankgrp, + "Row %hu Col %hu Bank %hhu Bank Group %hhu Rank %hhu Bit %d Data 0x%08llx:0x%02x", + pinf->sdram.row, pinf->sdram.col, pinf->sdram.bank, + pinf->sdram.bankgrp, pinf->sdram.rank, pinf->bitpos, pinf->data, pinf->ecc); - edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, - p->ce_cnt, 0, 0, pinf->syndrome, 0, 0, -1, + edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, p->ce_cnt, + PHYS_PFN(sys), offset_in_page(sys), + pinf->syndrome, 0, 0, -1, priv->message, ""); } if (p->ue_cnt) { pinf = &p->ueinfo; + snps_map_sdram_to_sys(priv, &pinf->sdram, &sys); + snprintf(priv->message, SNPS_EDAC_MSG_SIZE, - "Row %d Col %d Bank %d Bank Group %d Data 0x%08llx:0x%02x", - pinf->row, pinf->col, pinf->bank, pinf->bankgrp, + "Row %hu Col %hu Bank %hhu Bank Group %hhu Rank %hhu Data 0x%08llx:0x%02x", + pinf->sdram.row, pinf->sdram.col, pinf->sdram.bank, + pinf->sdram.bankgrp, pinf->sdram.rank, pinf->data, pinf->ecc); - edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, - p->ue_cnt, 0, 0, 0, 0, 0, -1, - priv->message, ""); + edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, p->ue_cnt, + PHYS_PFN(sys), offset_in_page(sys), + 0, 0, 0, -1, priv->message, ""); } memset(p, 0, sizeof(*p)); From patchwork Wed Sep 20 19:50:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 268A6C04FEE for ; Wed, 20 Sep 2023 19:50:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229503AbjITTum (ORCPT ); Wed, 20 Sep 2023 15:50:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjITTum (ORCPT ); Wed, 20 Sep 2023 15:50:42 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FDBE9E; Wed, 20 Sep 2023 12:50:35 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-5033918c09eso385947e87.2; Wed, 20 Sep 2023 12:50:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695239434; x=1695844234; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YWC//1VDwpZ/BXBcYZgbJZ5FW8tYbZIyE13JuB9Qg8Y=; b=WQDOOwZzpxRoJ3c/RXfjjZlkJlIwZOno+CMl8wDD+WhQVaXguWew2XHdQZe721f1nK SF31UmiStBeWxXCrdmUA/8cc4eHkqW4p+tpvok8nyzN1v5Odt4GisnTK0qNid25j2ztv 1YSyqSokrgwA/gxHkGDdQwGau9eWtiQJZDsdSI9+9uvYfOGrPu7h7dZNYwbU5/QTlmdj aQm453jXRu26bfHg7LMV93ZyYOYT6f2yipPlsS73/IYqajtp2oBDkBWuJd6mZaP2/PjO 9HG5izX3YFYJHvdpf5ARyXvxQ/kplUH3Hv68PEgvk321JfjTJMccSrEwAfNvvyWxpebB 2fbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695239434; x=1695844234; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YWC//1VDwpZ/BXBcYZgbJZ5FW8tYbZIyE13JuB9Qg8Y=; b=C9nmGobUeb0usn074ZdjhwN2KP5e/kBpv/VjZMBtGPkHYwtfW6cf6ApK4nyGXhdW4a +cxTGGvO6jb/HEVz0qAY5TKdckwRBncE35VzLGOI0EpgoF+Job/F2uPsNpmKdwEUaNww PSJ6bHV90EcwHSPCMMB1cPEony9l4BjzWlVrhS517e4vI84Nf2rkTC9NJZ73Zgqgql3e 3de1nnU0QfWdxGd5FpV7k8xvTu9sRPZATEiRz4GlLklNCB+FRw4WSVnlvA9c5ASyG0d5 0lxPA8888qQtjj0SK8hOSHIuo8muYevCOGMgkGflEtfyoLVq8cmzIwpd1naLj0vI7y+5 FXEg== X-Gm-Message-State: AOJu0Yz40s+x+RC6CW5WfCg4GIlSxiI19onOkPldM+Zxg98+WuMICc5y nwF5UjaDmRKN0PQA1C+Wze4mYuwQD7s= X-Google-Smtp-Source: AGHT+IHl9bQqdS2KJb5XtEqsELvseVSuXh9tdWPDur97OTi1SeKgJauyCJnpn1BUq+4/XVCrCREzNw== X-Received: by 2002:a19:5057:0:b0:503:2561:c8b with SMTP id z23-20020a195057000000b0050325610c8bmr2989096lfj.33.1695239433506; Wed, 20 Sep 2023 12:50:33 -0700 (PDT) Received: from localhost ([178.176.81.142]) by smtp.gmail.com with ESMTPSA id w26-20020ac2443a000000b004fe47879d93sm2798613lfl.106.2023.09.20.12.50.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:50:33 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 17/18] EDAC/synopsys: Add system address regions support Date: Wed, 20 Sep 2023 22:50:27 +0300 Message-ID: <20230920195030.31437-1-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Aside with the Application, HIF and SDRAM address spaces DW uMCTL2 DDR controller supports one more level of the address abstraction. It's the System Address Regions (SARs). By default SARs are disabled by means of the IP-core synthesize parameter UMCTL2_A_NSAR being set to zero. In that case the System and Application address spaces match. But if that parameter is set to a non-zero value (but less than or equal to 4), then it's possible to define up to 4 disjoint memory regions mapping to the SDRAM as consecutive addresses. So if the SARs are available on the particular DW uMCTL2 DDR controller, they need to be taken into account in order to get a correct Physical/DMA address by the SDRAM address and vice-versa. The SAR/Application address mapping support is implemented in the similar way as it has been done for the HIF/SDRAM address translation: read the mapping from the SARBASEn and SARSIZEn CSRs and save it in the System/Application address mapping table as the regions base address, size and offset; use the SARs mapping table to translate the system addresses to the application addresses and vice-versa in the framework of the sys-to-SDRAM and SDRAM-to-sys address translation chain. The described functionality is utilized in the code requiring the address translation: ECC errors detection and ECC data poisoning. Note aside with the number of SARs there is the aUMCTL2_SARMINSIZE IP-core parameter which indicates the SARs minimal block size. Alas it isn't auto-detectable, but it's critical to have a correct mapping table. So the suggested functionality expects it being specified for each particular controller otherwise the system address regions support will be forcibly disabled in the driver. Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 191 ++++++++++++++++++++++++++++++++++- 1 file changed, 188 insertions(+), 3 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index 5384e93ec58c..d67a19fedb3c 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -92,6 +93,10 @@ #define ECC_POISONPAT1_OFST 0x380 #define ECC_POISONPAT2_OFST 0x384 +/* DDR SAR Registers */ +#define DDR_SARBASE0_OFST 0xF04 +#define DDR_SARSIZE0_OFST 0xF08 + /* ZynqMP DDR QOS Registers */ #define ZYNQMP_DDR_QOS_IRQ_STAT_OFST 0x20200 #define ZYNQMP_DDR_QOS_IRQ_EN_OFST 0x20208 @@ -220,6 +225,10 @@ #define RANK_B0_BASE 6 #define RANK_B1_BASE 7 +/* DDRC System Address parameters */ +#define DDR_MAX_NSAR 4 +#define DDR_MIN_SARSIZE SZ_256M + /* ZynqMP DDR QOS Interrupt register definitions */ #define ZYNQMP_DDR_QOS_UE_MASK BIT(2) #define ZYNQMP_DDR_QOS_CE_MASK BIT(1) @@ -310,6 +319,24 @@ struct snps_ddrc_info { unsigned int ranks; }; +/** + * struct snps_sys_app_map - System/Application mapping table. + * @nsar: Number of SARs enabled on the controller (max 4). + * @minsize: Minimal block size (from 256MB to 32GB). + * @sar.base: SAR base address aligned to minsize. + * @sar.size: SAR size aligned to minsize. + * @sar.ofst: SAR address offset. + */ +struct snps_sys_app_map { + u8 nsar; + u64 minsize; + struct { + u64 base; + u64 size; + u64 ofst; + } sar[DDR_MAX_NSAR]; +}; + /** * struct snps_hif_sdram_map - HIF/SDRAM mapping table. * @row: HIF bit offsets used as row address bits. @@ -378,6 +405,7 @@ struct snps_ecc_status { /** * struct snps_edac_priv - DDR memory controller private data. * @info: DDR controller config info. + * @sys_app_map: Sys/App mapping table. * @hif_sdram_map: HIF/SDRAM mapping table. * @pdev: Platform device. * @baseaddr: Base address of the DDR controller. @@ -388,6 +416,7 @@ struct snps_ecc_status { */ struct snps_edac_priv { struct snps_ddrc_info info; + struct snps_sys_app_map sys_app_map; struct snps_hif_sdram_map hif_sdram_map; struct platform_device *pdev; void __iomem *baseaddr; @@ -399,6 +428,77 @@ struct snps_edac_priv { #endif }; +/** + * snps_map_sys_to_app - Map System address to Application address. + * @priv: DDR memory controller private instance data. + * @sys: System address (source). + * @app: Application address (destination). + * + * System address space is used to define disjoint memory regions + * mapped then to the contiguous application memory space: + * + * System Address Space (SAR) <-> Application Address Space + * +------+ +------+ + * | SAR0 |----------------------->| Reg0 | + * +------+ -offset +------+ + * | ... | +----------->| Reg1 | + * +------+ | +------+ + * | SAR1 |-----------+ | ... | + * +------+ + * | ... | + * + * The translation is done by applying the corresponding SAR offset + * to the inbound system address. Note according to the hardware reference + * manual the same mapping is applied to the addresses up to the next + * SAR base address irrespective to the region size. + */ +static void snps_map_sys_to_app(struct snps_edac_priv *priv, + dma_addr_t sys, u64 *app) +{ + struct snps_sys_app_map *map = &priv->sys_app_map; + u64 ofst; + int i; + + ofst = 0; + for (i = 0; i < map->nsar; i++) { + if (sys < map->sar[i].base) + break; + + ofst = map->sar[i].ofst; + } + + *app = sys - ofst; +} + +/** + * snps_map_sys_to_app - Map Application address to System address. + * @priv: DDR memory controller private instance data. + * @app: Application address (source). + * @sys: System address (destination). + * + * Backward App-to-sys translation is easier because the application address + * space is contiguous. So we just need to add the offset corresponding + * to the region the passed address belongs to. Note the later offset is applied + * to all the addresses above the last available region. + */ +static void snps_map_app_to_sys(struct snps_edac_priv *priv, + u64 app, dma_addr_t *sys) +{ + struct snps_sys_app_map *map = &priv->sys_app_map; + u64 ofst, size; + int i; + + ofst = 0; + for (i = 0, size = 0; i < map->nsar; i++) { + ofst = map->sar[i].ofst; + size += map->sar[i].size; + if (app < size) + break; + } + + *sys = app + ofst; +} + /** * snps_map_app_to_hif - Map Application address to HIF address. * @priv: DDR memory controller private instance data. @@ -547,7 +647,7 @@ static void snps_map_sys_to_sdram(struct snps_edac_priv *priv, { u64 app, hif; - app = sys; + snps_map_sys_to_app(priv, sys, &app); snps_map_app_to_hif(priv, app, &hif); @@ -572,7 +672,7 @@ static void snps_map_sdram_to_sys(struct snps_edac_priv *priv, snps_map_hif_to_app(priv, hif, &app); - *sys = app; + snps_map_app_to_sys(priv, app, sys); } /** @@ -976,6 +1076,52 @@ static int snps_get_ddrc_info(struct snps_edac_priv *priv) return init_plat ? init_plat(priv) : 0; } +/** + * snps_get_sys_app_map - Get System/Application address map. + * @priv: DDR memory controller private instance data. + * @sarregs: Array with SAR registers value. + * + * System address regions are defined by the SARBASEn and SARSIZEn registers. + * Controller reference manual requires the base addresses and sizes creating + * a set of ascending non-overlapped regions in order to have a linear + * application address space. Doing otherwise causes unpredictable results. + */ +static void snps_get_sys_app_map(struct snps_edac_priv *priv, u32 *sarregs) +{ + struct snps_sys_app_map *map = &priv->sys_app_map; + int i, ofst; + + /* + * SARs are supposed to be initialized in the ascending non-overlapped + * order: base[i - 1] < base[i] < etc. If that rule is broken for a SAR + * it's considered as no more SARs have been enabled, so the detection + * procedure will halt. Having the very first SAR with zero base + * address only makes sense if there is a consequent SAR. + */ + for (i = 0, ofst = 0; i < DDR_MAX_NSAR; i++) { + map->sar[i].base = sarregs[2 * i] * map->minsize; + if (map->sar[i].base) + map->nsar = i + 1; + else if (i && map->sar[i].base <= map->sar[i - 1].base) + break; + + map->sar[i].size = (sarregs[2 * i + 1] + 1) * map->minsize; + map->sar[i].ofst = map->sar[i].base - ofst; + ofst += map->sar[i].size; + } + + /* + * SAR block size isn't auto-detectable. If one isn't specified for the + * platform there is a good chance to have invalid mapping of the + * detected SARs. So proceed with 1:1 mapping then. + */ + if (!map->minsize && map->nsar) { + edac_printk(KERN_WARNING, EDAC_MC, + "No block size specified. Discard SARs mapping\n"); + map->nsar = 0; + } +} + /** * snps_get_hif_row_map - Get HIF/SDRAM-row address map. * @priv: DDR memory controller private instance data. @@ -1225,9 +1371,14 @@ static void snps_get_hif_rank_map(struct snps_edac_priv *priv, u32 *addrmap) */ static void snps_get_addr_map(struct snps_edac_priv *priv) { - u32 regval[DDR_ADDRMAP_NREGS]; + u32 regval[max(DDR_ADDRMAP_NREGS, 2 * DDR_MAX_NSAR)]; int i; + for (i = 0; i < 2 * DDR_MAX_NSAR; i++) + regval[i] = readl(priv->baseaddr + DDR_SARBASE0_OFST + i * 4); + + snps_get_sys_app_map(priv, regval); + for (i = 0; i < DDR_ADDRMAP_NREGS; i++) regval[i] = readl(priv->baseaddr + DDR_ADDRMAP0_OFST + i * 4); @@ -1418,6 +1569,37 @@ static int snps_ddrc_info_show(struct seq_file *s, void *data) DEFINE_SHOW_ATTRIBUTE(snps_ddrc_info); +static int snps_sys_app_map_show(struct seq_file *s, void *data) +{ + struct mem_ctl_info *mci = s->private; + struct snps_edac_priv *priv = mci->pvt_info; + struct snps_sys_app_map *map = &priv->sys_app_map; + u64 size; + int i; + + if (!map->nsar) { + seq_puts(s, "No SARs detected\n"); + return 0; + } + + seq_printf(s, "%9s %-37s %-18s %-37s\n", + "", "System address", "Offset", "App address"); + + for (i = 0, size = 0; i < map->nsar; i++) { + seq_printf(s, "Region %d: ", i); + seq_printf(s, "0x%016llx-0x%016llx ", map->sar[i].base, + map->sar[i].base + map->sar[i].size - 1); + seq_printf(s, "0x%016llx ", map->sar[i].ofst); + seq_printf(s, "0x%016llx-0x%016llx\n", size, + size + map->sar[i].size - 1); + size += map->sar[i].size; + } + + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(snps_sys_app_map); + static u8 snps_find_sdram_dim(struct snps_edac_priv *priv, u8 hif, char *dim) { struct snps_hif_sdram_map *map = &priv->hif_sdram_map; @@ -1615,6 +1797,9 @@ static void snps_create_debugfs_nodes(struct mem_ctl_info *mci) edac_debugfs_create_file("ddrc_info", 0400, mci->debugfs, mci, &snps_ddrc_info_fops); + edac_debugfs_create_file("sys_app_map", 0400, mci->debugfs, mci, + &snps_sys_app_map_fops); + edac_debugfs_create_file("hif_sdram_map", 0400, mci->debugfs, mci, &snps_hif_sdram_map_fops); From patchwork Wed Sep 20 19:50:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13393364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22427C04FF7 for ; Wed, 20 Sep 2023 19:50:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230137AbjITTu6 (ORCPT ); Wed, 20 Sep 2023 15:50:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230134AbjITTu5 (ORCPT ); Wed, 20 Sep 2023 15:50:57 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87FA6D7; Wed, 20 Sep 2023 12:50:50 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-500cfb168c6so406284e87.2; Wed, 20 Sep 2023 12:50:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695239449; x=1695844249; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lLdARslqZ1UHIFAXq/hck+mV3lZPnBFJ5rf0uyQGrzY=; b=LsLESdnayLmaQuCa+IKo4tBAiZSu8sIVLWoCU1JERe1njC5O8CxUNY91VRtvsCdJfL 60/alef8p5FlBweD/1X/cF/Y6hWZsa8r6DqQcTdpiSMEtGpOwSaH9EjykSXbxldMDL+W DQpFkyI2cYj16yOd5zAEWK2sFtRyyHG7N6s5L8knzMCQZOq84ic7frVFNUrFVsDKF2+r f3QUeFjiXM8qeVw1LAwXTMpZUGvBreQXPVgqNrIvs3hsw52BHVUPxZGijr2BDWnGfrV4 W9TQ9UriXA384I2IX5ENV4SViAkqCvMdO8/8TmhXxsDzsCm6VYYyQBI606wrK4oDvbgH LzZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695239449; x=1695844249; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lLdARslqZ1UHIFAXq/hck+mV3lZPnBFJ5rf0uyQGrzY=; b=SiG7hfhVgNU4GbqPYN6n2gfRqxtfqqdm7c6FPviziuuntValjZbcomE7U7bYxUxFx+ nLkDlCjXH3KKXjJ1/m3fnYbrpXKLsWb+nrJ0wzWI27c3tE5o3CT25hyGZdG+gonB4FaR LUAQ3Xe+AOocGgKQCCVfDDEfKVDJa43lxYXChvwLEsO/8MYq1U3FMTDt15yDTDbZ0TTA iXX1C/bZGsavvxeZIohkKycUQxR7vXspVeZN8KQolti9uFwnp0IjhjfFvPCfR7IPQG3K tGQuzfdyEil8nDCuOh7QexOCE6Cjiij6nQFxCDW7uVsz/b1EltH5mvCBywKwxXOx/iYb 05pg== X-Gm-Message-State: AOJu0Yz49tUQbxxOnKKKhR2NWkNe8tHY1PoIE98gahZQGx9xqLovPd4d 5o4v0nBri35TEWlBDjdZtxU= X-Google-Smtp-Source: AGHT+IGD+1vuPJHvvxlM6XsMPzpeFlN+p62CF5i4Vq+sUzIz0nwdXcTwcBohCcB4cG1BpSAoCNN2PQ== X-Received: by 2002:a05:6512:b10:b0:500:9a29:bcb8 with SMTP id w16-20020a0565120b1000b005009a29bcb8mr4023028lfu.4.1695239448598; Wed, 20 Sep 2023 12:50:48 -0700 (PDT) Received: from localhost ([85.140.0.132]) by smtp.gmail.com with ESMTPSA id t26-20020ac2549a000000b004fe09e6d1e7sm2791953lfk.110.2023.09.20.12.50.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:50:48 -0700 (PDT) From: Serge Semin To: Michal Simek , Alexander Stein , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter Cc: Serge Semin , Punnaiah Choudary Kalluri , Dinh Nguyen , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 18/18] EDAC/synopsys: Add mapping-based memory size calculation Date: Wed, 20 Sep 2023 22:50:42 +0300 Message-ID: <20230920195045.31466-1-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920192806.29960-1-fancer.lancer@gmail.com> References: <20230920192806.29960-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Currently the size of the memory attached to the controller is retrieved by means of the si_meminfo() method. It isn't quite correct because the system may have more than one memory controller. There is a better and more portable approach available to find out the attached memory size. Since the full HIF/SDRAM mapping table is available already in the device probe procedure and the DQ-bus width is detected at that stage too, that info can be used to calculate the total memory size accessible over the corresponding DW uMCTL2 DDR controller. It can be done since the controller databook demands that none two SDRAM bits are mapped to the same HIF bit [1] and that the unused SDRAM address bits mapping must be disabled [2]. Note the size calculation procedure takes the ranks mapping into account. That part will be removed after the multi-ranked MC registration is added. [1] DesignWare® Cores Enhanced Universal DDR Memory Controller (uMCTL2) Databook, Version 3.91a, October 2020, p.108 [2] DesignWare® Cores Enhanced Universal DDR Memory Controller (uMCTL2) Databook, Version 3.91a, October 2020, p.109 Signed-off-by: Serge Semin --- drivers/edac/synopsys_edac.c | 66 ++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c index d67a19fedb3c..9a621b7a256d 100644 --- a/drivers/edac/synopsys_edac.c +++ b/drivers/edac/synopsys_edac.c @@ -965,20 +965,6 @@ static inline enum dev_type snps_get_dtype(u32 mstr) return DEV_UNKNOWN; } -/** - * snps_get_memsize - Read the size of the attached memory device. - * - * Return: the memory size in bytes. - */ -static u32 snps_get_memsize(void) -{ - struct sysinfo inf; - - si_meminfo(&inf); - - return inf.totalram * inf.mem_unit; -} - /** * snps_get_mtype - Returns controller memory type. * @mstr: Master CSR value. @@ -1393,6 +1379,51 @@ static void snps_get_addr_map(struct snps_edac_priv *priv) snps_get_hif_rank_map(priv, regval); } +/** + * snps_get_sdram_size - Calculate SDRAM size. + * @priv: DDR memory controller private data. + * + * The total size of the attached memory is calculated based on the HIF/SDRAM + * mapping table. It can be done since the hardware reference manual demands + * that none two SDRAM bits should be mapped to the same HIF bit and that the + * unused SDRAM address bits mapping must be disabled. + * + * Return: the memory size in bytes. + */ +static u64 snps_get_sdram_size(struct snps_edac_priv *priv) +{ + struct snps_hif_sdram_map *map = &priv->hif_sdram_map; + u64 size = 0; + int i; + + for (i = 0; i < DDR_MAX_ROW_WIDTH; i++) { + if (map->row[i] != DDR_ADDRMAP_UNUSED) + size++; + } + + for (i = 0; i < DDR_MAX_COL_WIDTH; i++) { + if (map->col[i] != DDR_ADDRMAP_UNUSED) + size++; + } + + for (i = 0; i < DDR_MAX_BANK_WIDTH; i++) { + if (map->bank[i] != DDR_ADDRMAP_UNUSED) + size++; + } + + for (i = 0; i < DDR_MAX_BANKGRP_WIDTH; i++) { + if (map->bankgrp[i] != DDR_ADDRMAP_UNUSED) + size++; + } + + for (i = 0; i < DDR_MAX_RANK_WIDTH; i++) { + if (map->rank[i] != DDR_ADDRMAP_UNUSED) + size++; + } + + return 1ULL << (size + priv->info.dq_width); +} + /** * snps_init_csrows - Initialize the csrow data. * @mci: EDAC memory controller instance. @@ -1405,7 +1436,8 @@ static void snps_init_csrows(struct mem_ctl_info *mci) struct snps_edac_priv *priv = mci->pvt_info; struct csrow_info *csi; struct dimm_info *dimm; - u32 size, row, width; + u32 row, width; + u64 size; int j; /* Actual SDRAM-word width for which ECC is calculated */ @@ -1413,13 +1445,13 @@ static void snps_init_csrows(struct mem_ctl_info *mci) for (row = 0; row < mci->nr_csrows; row++) { csi = mci->csrows[row]; - size = snps_get_memsize(); + size = snps_get_sdram_size(priv); for (j = 0; j < csi->nr_channels; j++) { dimm = csi->channels[j]->dimm; dimm->edac_mode = EDAC_SECDED; dimm->mtype = priv->info.sdram_mode; - dimm->nr_pages = (size >> PAGE_SHIFT) / csi->nr_channels; + dimm->nr_pages = PHYS_PFN(size) / csi->nr_channels; dimm->grain = width; dimm->dtype = priv->info.dev_cfg; }