From patchwork Mon Mar 8 09:03:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12121813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6F68C433E6 for ; Mon, 8 Mar 2021 09:04:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D412651E3 for ; Mon, 8 Mar 2021 09:04:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230002AbhCHJDt (ORCPT ); Mon, 8 Mar 2021 04:03:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230033AbhCHJDi (ORCPT ); Mon, 8 Mar 2021 04:03:38 -0500 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 8783AC06174A; Mon, 8 Mar 2021 01:03:38 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id e7so19885739lft.2; Mon, 08 Mar 2021 01:03:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4NRGthBs+/q6+vesB70sO/ZVgC35VhS+qss/CaaE9UA=; b=hkPT+yy42ZOCPfhktzDUpM2IGYj7wGh/2f4CCg6AEIPGqZwCQg1TRWFEWFwjJcC0m3 5srsz48WKVBlGs6zh3Oo9iBtN6fjmi/8KL8yRh7+0/yRgZm76/nG0DpSN3lX63NtcSa6 CklF0TyYLpXSzIMkpIr84Xtvi9D0HcZ115Yy/IIr1CV8t94NKz3ebE+z5FrxEAdzz+5e k8YShFkerVs8rLlM0fj0xYzgnVAforElJ0KpjEcxld9K0CRxLFGT83J3QohmibZMp/X/ w6wP8uIkhrRvGUpBffrDxA+y2ssw4Erjwt38TZEdnOo3z1IHyFLJCQ/hC+RYgg8RJol2 q4WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4NRGthBs+/q6+vesB70sO/ZVgC35VhS+qss/CaaE9UA=; b=d6gJG6F4BZtztw0qOdDcN2QYPxIPEsdybmcSVdeCK+UArt/hpbP44LL+uhJsq2a004 xZYuDnMNQerdhkW5ie8ULKZXapUtD2DTyANSM3+Z43e3l5gHmMjO4es0+51pMOK2mP6x x4m8OzA4nkZ1vbZRsQuq4h0hsZLB5cvWuMdCjBJlv27I/fopPs4C8eplm32tlTVXaOUC cS5yn/2OnQcY00bzhgwwiAKbGm488gJbbVEY7W8jKnQLSxRXU/zFhrME3zht+wwcxevd aIOpfN9dP/lMaqPRSOGhnJFbPGbAPjlB8dgD5VEge2LQSftScX1YY5Bt0gyW0kRZeWWZ FU0w== X-Gm-Message-State: AOAM531flX0mWNIPswaEjZTLrJ1T1Ncx6Xpi0GNRLwi2gkcooTQgc4Y3 iTCUCKB97FidGMWm+168qIE= X-Google-Smtp-Source: ABdhPJxawVsYQ9hY0VZC/ES9+JkCRXPfPnkqDEheTdpmlN7cJ+cczwO5v9XXATvai3xOKDK0Cfnnew== X-Received: by 2002:a19:ab0a:: with SMTP id u10mr14637656lfe.540.1615194217138; Mon, 08 Mar 2021 01:03:37 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id t13sm1410346ljk.47.2021.03.08.01.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 01:03:36 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, Florian Fainelli , Vivek Unune , bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?b?UmFm?= =?utf-8?b?YcWCIE1pxYJlY2tp?= Subject: [PATCH mips/linux.git 1/5] firmware: bcm47xx_nvram: rename finding function and its variables Date: Mon, 8 Mar 2021 10:03:16 +0100 Message-Id: <20210308090320.9765-2-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210308090320.9765-1-zajec5@gmail.com> References: <20210308090320.9765-1-zajec5@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Rafał Miłecki 1. Use "bcm47xx_" function name prefix for consistency 2. It takes flash start as argument so s/iobase/flash_start/ 3. "off" was used for finding flash end so just call it "flash_size" Signed-off-by: Rafał Miłecki --- drivers/firmware/broadcom/bcm47xx_nvram.c | 24 ++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/firmware/broadcom/bcm47xx_nvram.c b/drivers/firmware/broadcom/bcm47xx_nvram.c index 835ece9c00f1..b04007adc79f 100644 --- a/drivers/firmware/broadcom/bcm47xx_nvram.c +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c @@ -48,11 +48,13 @@ static u32 find_nvram_size(void __iomem *end) return 0; } -/* Probe for NVRAM header */ -static int nvram_find_and_copy(void __iomem *iobase, u32 lim) +/** + * bcm47xx_nvram_find_and_copy - find NVRAM on flash mapping & copy it + */ +static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_size) { struct nvram_header __iomem *header; - u32 off; + size_t flash_size; u32 size; if (nvram_len) { @@ -61,25 +63,25 @@ static int nvram_find_and_copy(void __iomem *iobase, u32 lim) } /* TODO: when nvram is on nand flash check for bad blocks first. */ - off = FLASH_MIN; - while (off <= lim) { + flash_size = FLASH_MIN; + while (flash_size <= res_size) { /* Windowed flash access */ - size = find_nvram_size(iobase + off); + size = find_nvram_size(flash_start + flash_size); if (size) { - header = (struct nvram_header *)(iobase + off - size); + header = (struct nvram_header *)(flash_start + flash_size - size); goto found; } - off <<= 1; + flash_size <<= 1; } /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */ - header = (struct nvram_header *)(iobase + 4096); + header = (struct nvram_header *)(flash_start + 4096); if (header->magic == NVRAM_MAGIC) { size = NVRAM_SPACE; goto found; } - header = (struct nvram_header *)(iobase + 1024); + header = (struct nvram_header *)(flash_start + 1024); if (header->magic == NVRAM_MAGIC) { size = NVRAM_SPACE; goto found; @@ -124,7 +126,7 @@ int bcm47xx_nvram_init_from_mem(u32 base, u32 lim) if (!iobase) return -ENOMEM; - err = nvram_find_and_copy(iobase, lim); + err = bcm47xx_nvram_find_and_copy(iobase, lim); iounmap(iobase); From patchwork Mon Mar 8 09:03:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12121815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B78AC4332B for ; Mon, 8 Mar 2021 09:04:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 562CC651C5 for ; Mon, 8 Mar 2021 09:04:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230075AbhCHJDu (ORCPT ); Mon, 8 Mar 2021 04:03:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbhCHJDl (ORCPT ); Mon, 8 Mar 2021 04:03:41 -0500 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A74BCC06174A; Mon, 8 Mar 2021 01:03:40 -0800 (PST) Received: by mail-lj1-x235.google.com with SMTP id r25so15063325ljk.11; Mon, 08 Mar 2021 01:03:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h1CjJ6ig+osO4HlHfodxEJpSRAPR8gnCp6G0zXv92EQ=; b=Aq5Vac6XFUbDeHf/eDsLNcU2rtbhFI0kgrnfm74+LT45UmDR+IbEWs9dzm5nYlWdGv UlYn+IqZps28P81MpxOUTNuI2IfKBYJfQ/DuHceQnWLay7fhO8OBZbkfWKstvu7DG9SX KvmK3IAFK0wUx4L5ffF6EfOesrgp037+mEiDqSFQdmQAsstEk1dJHCKyMHsQj1TZzhRG +yDTy6ihf+l4ky+kcpNAcyvazrK7wsCrlLSkikT/5IbM7FzT6UbyWSXA6QbyKluzI/uL aiInrl6Wu8/BWSzlNs+tkZINXInL5xKSzfabkmSivXEhS1YeknL4Y10Bc5o+ExICSLp3 EytQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h1CjJ6ig+osO4HlHfodxEJpSRAPR8gnCp6G0zXv92EQ=; b=G4jEKqsCUG3EgOBGrMsrnSellKO011zXceritD6UzOl8mcU37YoQDhHn/oKe6bik4P B9iwfNGHvy2mx5IIvxa5j5Y2dPZVyoc/9ypa2MYlwM1085UBLd2wiMypypsfH5jMmNrd PcVxQrtr5Bf+rWIEc6tJ7lagxWZOZ/cGn5ErxfF36LoXYSg+tjw3uSGKZfCl1NMSq2sL E7Mf1MVh36Yln1rQ8XuuypZnWnVrnojS/tqBdL6/VhX4/QuqjNVg2YLCVVsyK49efuR1 C/poGEvXP8TI4P9FFO2bwJ0Up3D1IbORlUq0ujvdllRNeXfaBYUokfj8UX6z/QXfIG5k YdFw== X-Gm-Message-State: AOAM530QhX0KJO459pWXzJCiVT3iYMgujN8tRZnTZ6SBAUHQrjp4Anpk 7a1QfUTh9JvMLFEQY0eAubs= X-Google-Smtp-Source: ABdhPJxxFvkWKBZcUaNh47icOgTHGTyNzsE8gIyB1DbBexlYZDYK+UeSxJB0HiNHuBgl1IOx1cTTEg== X-Received: by 2002:a2e:810a:: with SMTP id d10mr12910149ljg.304.1615194219267; Mon, 08 Mar 2021 01:03:39 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id t13sm1410346ljk.47.2021.03.08.01.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 01:03:38 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, Florian Fainelli , Vivek Unune , bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?b?UmFm?= =?utf-8?b?YcWCIE1pxYJlY2tp?= Subject: [PATCH mips/linux.git 2/5] firmware: bcm47xx_nvram: add helper checking for NVRAM Date: Mon, 8 Mar 2021 10:03:17 +0100 Message-Id: <20210308090320.9765-3-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210308090320.9765-1-zajec5@gmail.com> References: <20210308090320.9765-1-zajec5@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Rafał Miłecki This avoids duplicating code doing casting and checking for NVRAM magic. Signed-off-by: Rafał Miłecki --- drivers/firmware/broadcom/bcm47xx_nvram.c | 30 ++++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/firmware/broadcom/bcm47xx_nvram.c b/drivers/firmware/broadcom/bcm47xx_nvram.c index b04007adc79f..99f3ec180be6 100644 --- a/drivers/firmware/broadcom/bcm47xx_nvram.c +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c @@ -34,14 +34,20 @@ static char nvram_buf[NVRAM_SPACE]; static size_t nvram_len; static const u32 nvram_sizes[] = {0x6000, 0x8000, 0xF000, 0x10000}; +/** + * bcm47xx_nvram_is_valid - check for a valid NVRAM at specified memory + */ +static bool bcm47xx_nvram_is_valid(void __iomem *nvram) +{ + return ((struct nvram_header *)nvram)->magic == NVRAM_MAGIC; +} + static u32 find_nvram_size(void __iomem *end) { - struct nvram_header __iomem *header; int i; for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) { - header = (struct nvram_header *)(end - nvram_sizes[i]); - if (header->magic == NVRAM_MAGIC) + if (bcm47xx_nvram_is_valid(end - nvram_sizes[i])) return nvram_sizes[i]; } @@ -55,6 +61,7 @@ static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_siz { struct nvram_header __iomem *header; size_t flash_size; + size_t offset; u32 size; if (nvram_len) { @@ -68,31 +75,30 @@ static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_siz /* Windowed flash access */ size = find_nvram_size(flash_start + flash_size); if (size) { - header = (struct nvram_header *)(flash_start + flash_size - size); + offset = flash_size - size; goto found; } flash_size <<= 1; } /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */ - header = (struct nvram_header *)(flash_start + 4096); - if (header->magic == NVRAM_MAGIC) { - size = NVRAM_SPACE; + + offset = 4096; + if (bcm47xx_nvram_is_valid(flash_start + offset)) goto found; - } - header = (struct nvram_header *)(flash_start + 1024); - if (header->magic == NVRAM_MAGIC) { - size = NVRAM_SPACE; + offset = 1024; + if (bcm47xx_nvram_is_valid(flash_start + offset)) goto found; - } pr_err("no nvram found\n"); return -ENXIO; found: + header = (struct nvram_header *)(flash_start + offset); __ioread32_copy(nvram_buf, header, sizeof(*header) / 4); nvram_len = ((struct nvram_header *)(nvram_buf))->len; + size = res_size - offset; if (nvram_len > size) { pr_err("The nvram size according to the header seems to be bigger than the partition on flash\n"); nvram_len = size; From patchwork Mon Mar 8 09:03:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12121817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2FEAC433E9 for ; Mon, 8 Mar 2021 09:04:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2697651EB for ; Mon, 8 Mar 2021 09:04:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbhCHJDv (ORCPT ); Mon, 8 Mar 2021 04:03:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230039AbhCHJDn (ORCPT ); Mon, 8 Mar 2021 04:03:43 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E68E5C06174A; Mon, 8 Mar 2021 01:03:42 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id p21so19770580lfu.11; Mon, 08 Mar 2021 01:03:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QHdcGt7AxJv5t+i0WxNNyS82pcyfDeM2mDcTkiKFnc0=; b=MmolS1fvCwl8ZXC6sR8UJiH5ac1tC4I7+oEHFjRqga9PHL9OqdytRUVpEq1M92OgVL CV4z2CYnbAS0hRLNPJX7CzxaST/RiPaEvw8dVBy8xvau7HSQHyTxOTcms66C6yhMyvPw wzlKIZkTIXjuXVsM2+d7ZrNP6PAd36TILZ5JBjkLy4GERCdwMa3hiU+A1FXIEZ3HyNki h1+R3vTy3IZlPe3J38FWzinrci+vWXmBS3ngzxCrF6pKJxxRAEQWm+5ZuOqo19IsD/TS LXC0dSaL2/P3UX2mdkXt5xOA5Wl430shguLK5UqyPPBk21FdEoWF9WvskpdFj6wbSAJm /iZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QHdcGt7AxJv5t+i0WxNNyS82pcyfDeM2mDcTkiKFnc0=; b=RjVo0jMPVqLy4gdZpqJMl9BqCw4ixkKcpr+2zltazpQ32+Kww7oypoWz4OPyJ5IlGY TJyLXOglFSyYJ2Vca2NWHHYoDOL8D1H/y54FBhmZgE8DsZc1I4TnPbI8QedsvzchCm2t Jkz3pv61sEAKgGCP6slryVaVbFBDcbI/IL3OhwwJX3Z86fBDDs0exsO9w9P9DUWWl83c +Nhi93YWW1Xc5ME9Nl3M2rfsPryH/IHP23d8AyHN84Ad/LazGrVimFsaVdruVQaMtOda 7julvgLmfyR+Zx0O0zEXvhSeFqU4dnz0pRRspv6ALN9C9RJwcQbWUaNSPUzHqsPtnj6e OrIA== X-Gm-Message-State: AOAM532SIXhbLJ6SsjLSctUx91phEr8mY6BFzcUiYjTSiYOKou+pHSg9 bv/onDGTWTVYHk82zpw4iso= X-Google-Smtp-Source: ABdhPJxuVlWfg/qDGMbGPzKfkNXvjObQ6FjU0FoeUnYoDugW+L1Vmbs+inKq0wO4U5cPyQtRZF2HBg== X-Received: by 2002:ac2:455b:: with SMTP id j27mr13730978lfm.72.1615194221481; Mon, 08 Mar 2021 01:03:41 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id t13sm1410346ljk.47.2021.03.08.01.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 01:03:41 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, Florian Fainelli , Vivek Unune , bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?b?UmFm?= =?utf-8?b?YcWCIE1pxYJlY2tp?= Subject: [PATCH mips/linux.git 3/5] firmware: bcm47xx_nvram: extract code copying NVRAM Date: Mon, 8 Mar 2021 10:03:18 +0100 Message-Id: <20210308090320.9765-4-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210308090320.9765-1-zajec5@gmail.com> References: <20210308090320.9765-1-zajec5@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Rafał Miłecki This simplifies function finding NVRAM. It doesn't directly deal with NVRAM structure anymore and is a bit smaller. Signed-off-by: Rafał Miłecki --- drivers/firmware/broadcom/bcm47xx_nvram.c | 43 +++++++++++++---------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/drivers/firmware/broadcom/bcm47xx_nvram.c b/drivers/firmware/broadcom/bcm47xx_nvram.c index 99f3ec180be6..09f51b95849e 100644 --- a/drivers/firmware/broadcom/bcm47xx_nvram.c +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c @@ -54,12 +54,35 @@ static u32 find_nvram_size(void __iomem *end) return 0; } +/** + * bcm47xx_nvram_copy - copy NVRAM to internal buffer + */ +static void bcm47xx_nvram_copy(void __iomem *nvram_start, size_t res_size) +{ + struct nvram_header __iomem *header = nvram_start; + size_t copy_size; + + copy_size = header->len; + if (copy_size > res_size) { + pr_err("The nvram size according to the header seems to be bigger than the partition on flash\n"); + copy_size = res_size; + } + if (copy_size >= NVRAM_SPACE) { + pr_err("nvram on flash (%zu bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n", + copy_size, NVRAM_SPACE - 1); + copy_size = NVRAM_SPACE - 1; + } + + __ioread32_copy(nvram_buf, nvram_start, DIV_ROUND_UP(copy_size, 4)); + nvram_buf[NVRAM_SPACE - 1] = '\0'; + nvram_len = copy_size; +} + /** * bcm47xx_nvram_find_and_copy - find NVRAM on flash mapping & copy it */ static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_size) { - struct nvram_header __iomem *header; size_t flash_size; size_t offset; u32 size; @@ -95,23 +118,7 @@ static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_siz return -ENXIO; found: - header = (struct nvram_header *)(flash_start + offset); - __ioread32_copy(nvram_buf, header, sizeof(*header) / 4); - nvram_len = ((struct nvram_header *)(nvram_buf))->len; - size = res_size - offset; - if (nvram_len > size) { - pr_err("The nvram size according to the header seems to be bigger than the partition on flash\n"); - nvram_len = size; - } - if (nvram_len >= NVRAM_SPACE) { - pr_err("nvram on flash (%zu bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n", - nvram_len, NVRAM_SPACE - 1); - nvram_len = NVRAM_SPACE - 1; - } - /* proceed reading data after header */ - __ioread32_copy(nvram_buf + sizeof(*header), header + 1, - DIV_ROUND_UP(nvram_len, 4)); - nvram_buf[NVRAM_SPACE - 1] = '\0'; + bcm47xx_nvram_copy(flash_start + offset, res_size - offset); return 0; } From patchwork Mon Mar 8 09:03:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12121819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1DBEC433DB for ; Mon, 8 Mar 2021 09:04:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8801A65202 for ; Mon, 8 Mar 2021 09:04:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230113AbhCHJDv (ORCPT ); Mon, 8 Mar 2021 04:03:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbhCHJDp (ORCPT ); Mon, 8 Mar 2021 04:03:45 -0500 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EAE1C06174A; Mon, 8 Mar 2021 01:03:44 -0800 (PST) Received: by mail-lj1-x235.google.com with SMTP id t9so15087754ljt.8; Mon, 08 Mar 2021 01:03:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BB78i/TOrdtbQgIIMS5144s3mE6rskxVn8XRXaD3Po0=; b=unSEgdNsO1ZS1AOfxEfdlbhZxdoZDrxS7aH36MTZ/KfZkdnmNg1MnzbIJD5E2BVSC1 vy5Fh1ZXZGaD2wpSM616BISiaz8KLnWJHHGwC603poxTZeDve4lv9ZnUWvGEK6hoy/we rcsInr8pjkBbZtCBiXOxS4xEGk/ZMwhb/EWQZbjohF/sBUhxzTSPR9JutKdCRTG5ZCIz d4/aYGDZ6U5wwqeAaW545aQW5Y1jSflWKlVGCuOj7YPSiiwCvNXMmjMXp9gQ+EhDvaXf l89UMnAy6M7QOxsSpiZWLyvpZ36WDNGh+g5QA9Y+K3Xr5uR2zpqGz37SZhQy6ZAXbCJ7 LSfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BB78i/TOrdtbQgIIMS5144s3mE6rskxVn8XRXaD3Po0=; b=nQ5TNgtIrvImyU1mJNQ9NgfoHGuNBcl6uygOVgbg9LXo+rEB25ziaOjVDMxy51ET97 a4KpAXnKVUkHZ9l6rWGjdJC5DfR5etgs2g56roMWz7R4cQHgBMxGK5RWWVi36HKenqmk 92jQ+6ucGjKsj1o0CVXekmXEeNznAyfxs6KifpijYQzuYXwI0gDvJJg5nVrRfrSw7hfT GMGmyAgjqyCd3sFZnOFOPVwhSFS9yYjZWG6f85GYv2i4WkgZDwLXc7acEk4TntfwgYcN f64uHVdSXNG9/iTKecdtBvKPghsojX+cJg8y+utOfbGIrhIPQWIfUFqZD/AVQCR+JMfR Q2aA== X-Gm-Message-State: AOAM532TV+uiB+6UrOVgB1IS5W+i/xcIlzhMHuARjJSdBy8xb9iNXpdi Wb+Hyjp+fmEclnnBRxhCBlc= X-Google-Smtp-Source: ABdhPJyK7mQGyO2W7OgUqJ1I3bccbBt71tnUSxhtbuAwNi3kvGd13XX/UjUyaP8e1zUbhRjn1huGnw== X-Received: by 2002:a2e:b814:: with SMTP id u20mr13062565ljo.370.1615194223105; Mon, 08 Mar 2021 01:03:43 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id t13sm1410346ljk.47.2021.03.08.01.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 01:03:42 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, Florian Fainelli , Vivek Unune , bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?b?UmFm?= =?utf-8?b?YcWCIE1pxYJlY2tp?= Subject: [PATCH mips/linux.git 4/5] firmware: bcm47xx_nvram: look for NVRAM with for instead of while Date: Mon, 8 Mar 2021 10:03:19 +0100 Message-Id: <20210308090320.9765-5-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210308090320.9765-1-zajec5@gmail.com> References: <20210308090320.9765-1-zajec5@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Rafał Miłecki This loop requires variable initialization, stop condition and post iteration increment. It's pretty much a for loop definition. Signed-off-by: Rafał Miłecki --- drivers/firmware/broadcom/bcm47xx_nvram.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/firmware/broadcom/bcm47xx_nvram.c b/drivers/firmware/broadcom/bcm47xx_nvram.c index 09f51b95849e..1d2271b1e07a 100644 --- a/drivers/firmware/broadcom/bcm47xx_nvram.c +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c @@ -93,15 +93,13 @@ static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_siz } /* TODO: when nvram is on nand flash check for bad blocks first. */ - flash_size = FLASH_MIN; - while (flash_size <= res_size) { + for (flash_size = FLASH_MIN; flash_size <= res_size; flash_size <<= 1) { /* Windowed flash access */ size = find_nvram_size(flash_start + flash_size); if (size) { offset = flash_size - size; goto found; } - flash_size <<= 1; } /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */ From patchwork Mon Mar 8 09:03:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12121821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB34FC433E0 for ; Mon, 8 Mar 2021 09:04:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69C35651A5 for ; Mon, 8 Mar 2021 09:04:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229711AbhCHJEV (ORCPT ); Mon, 8 Mar 2021 04:04:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229737AbhCHJDs (ORCPT ); Mon, 8 Mar 2021 04:03:48 -0500 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 58B51C06174A; Mon, 8 Mar 2021 01:03:48 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id v9so19872294lfa.1; Mon, 08 Mar 2021 01:03:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f0MkKY1UF1QqFhYKVPwOq+Ju9G4IUVvg4Cjsdu6w/3g=; b=EhqwmCj+hu7PZmHAM0dMG8J+JeLWiEWiHnApd2/aEUepqpPkN+ocEQ0tGtL7TtqAKk 4R/zDo7QvDGVtI7/KQCQyQSav0wAR0znPEi12SJ42mLthNUwHuNyP+e2uAEp+i80uNFL rfkQMzBVt36d2q5fQE8y39we7tZjRwFG0iCOowXcMnLmX12463GUEy2Msun90lSGFWAj ufkEQOKX2Y+lNocNAs7E1fxAzZs3UWoBo4P13A6dmlIb1l+/u3upWpixYshykkxIyvNR 0jdLr3UwHTM+j0uEupoo0RB/6Evjtxvp7GYw1rOgdgFdqM42U3QWc2z+MvboDEjgk3Sr adoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f0MkKY1UF1QqFhYKVPwOq+Ju9G4IUVvg4Cjsdu6w/3g=; b=azXb5SqkI+l5K07xImwB7xxNUWY5my50jXPIKHMKjvTJg7gwOfjk63h6qcfKIwtWYE TO2Ea+99t6JlhQoTeMsDYj/A4uZjj955PtkQorWxjq0brTH+oxxW/lG+s3kVX6k067Z5 gqavVZ5PdXS+Z/7na01/7+rSny3kgCIGHGIq6iF9wzijWw+jpLHvAxyFsUEIxstSZLmm KtfANL7CPrIK6orxCKKeGfTBuvqkkbsWYjv69lnXOiF3KvYC4uwc7rmkUHXRscl8RZ+B e1XYYn6YzxLAHFL4A4liw2xI3C1zSl05IRMmQ83EAVPULVqjhSCGwEThf5BCzo6+xgUe aRdw== X-Gm-Message-State: AOAM5311gPAu1c5LWxa70UY0c9/BIw0tPokJi/1nf138rnCve0doBY6n QJLdhYDvFWOzUzMfHakL/y8= X-Google-Smtp-Source: ABdhPJwWEq2R/+0DcHcTYmLrCNuBZIc3WgrmH7DSX2vHIJ4hzT2ZRTwShzvw+/dXCIBJs69Rs9pwiQ== X-Received: by 2002:a19:2242:: with SMTP id i63mr13237087lfi.643.1615194226928; Mon, 08 Mar 2021 01:03:46 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id t13sm1410346ljk.47.2021.03.08.01.03.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 01:03:46 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, Florian Fainelli , Vivek Unune , bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?b?UmFm?= =?utf-8?b?YcWCIE1pxYJlY2tp?= Subject: [PATCH mips/linux.git 5/5] firmware: bcm47xx_nvram: inline code checking NVRAM size Date: Mon, 8 Mar 2021 10:03:20 +0100 Message-Id: <20210308090320.9765-6-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210308090320.9765-1-zajec5@gmail.com> References: <20210308090320.9765-1-zajec5@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Rafał Miłecki Separated function was not improving code quality much (or at all). Moreover it expected possible flash end address as argument and it was returning NVRAM size. The new code always operates on offsets which means less logic and less calculations. Signed-off-by: Rafał Miłecki --- drivers/firmware/broadcom/bcm47xx_nvram.c | 25 +++++++---------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/drivers/firmware/broadcom/bcm47xx_nvram.c b/drivers/firmware/broadcom/bcm47xx_nvram.c index 1d2271b1e07a..bd235833b687 100644 --- a/drivers/firmware/broadcom/bcm47xx_nvram.c +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c @@ -42,18 +42,6 @@ static bool bcm47xx_nvram_is_valid(void __iomem *nvram) return ((struct nvram_header *)nvram)->magic == NVRAM_MAGIC; } -static u32 find_nvram_size(void __iomem *end) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) { - if (bcm47xx_nvram_is_valid(end - nvram_sizes[i])) - return nvram_sizes[i]; - } - - return 0; -} - /** * bcm47xx_nvram_copy - copy NVRAM to internal buffer */ @@ -85,7 +73,7 @@ static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_siz { size_t flash_size; size_t offset; - u32 size; + int i; if (nvram_len) { pr_warn("nvram already initialized\n"); @@ -93,12 +81,13 @@ static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_siz } /* TODO: when nvram is on nand flash check for bad blocks first. */ + + /* Try every possible flash size and check for NVRAM at its end */ for (flash_size = FLASH_MIN; flash_size <= res_size; flash_size <<= 1) { - /* Windowed flash access */ - size = find_nvram_size(flash_start + flash_size); - if (size) { - offset = flash_size - size; - goto found; + for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) { + offset = flash_size - nvram_sizes[i]; + if (bcm47xx_nvram_is_valid(flash_start + offset)) + goto found; } }