From patchwork Tue Oct 27 16:11:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 319159 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp1708755ilc; Tue, 27 Oct 2020 09:12:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYQ2P+MIZxdpJYzwsGblw7wJqCAlOaJ5q590l5mJrJ3z08eA3v86DqzQU4BwooJdNB6Hsv X-Received: by 2002:adf:818b:: with SMTP id 11mr3659699wra.74.1603815176739; Tue, 27 Oct 2020 09:12:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603815176; cv=none; d=google.com; s=arc-20160816; b=L5v1PrXlq4kA2RpfNayvt+x7k19AG2xI6K3BMc8vWQgaNaKs3LsrVep6GIUf+0zM78 rf+E6nnvUrB5HxplHUWbg9Qy32DDmrhDHuEly5u6sImrqLe0jjfRbodkzrYeT65POPdR ttCmuonIF+cGFom6N99uuHNSEGgNwfQdu4mM+zY4n8uAfZEom5l1iwEBD47RA4B3vDbI yz+R1EUB3sTx3hROSPtZ0u56Jg9wy3Oy4uLiiv6cHOVtLygVXeF3GFCwXuMIUBhwyFhZ GQkDpaB2CgpodcC49DdwGQroZQ1ciCBBHz8zVyzTCv0G8AuYyDyI6s8zDYu3n//SKd9Q iJvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vdv8LjT2CgfUj8c+ccLLrRWl2zDtGgEY+2d5t9DuZoQ=; b=BAciyIf/t1I6EMmN/Qy/fuT75vsuGAo6h8ZSa7CVXrbwUYyf6hzV7QdwV4CTGn/PIK P12hEx6OyNT0UWJOjIba4dPOyGp4qSP2M8QzIlfeE8VhH7Xy6XY+PTclhS8H30o++PPB COkJWSIv5S3SA+j+uKmP0eWj5RyimioNiYwUuUOj3DYsbQNt3kiCZqI8xGd5WZPl54LT +LkadoCRzsS0FK8EB0zIcf3qHxDkkBLEz6VNstoKghF8Uqoth2ILoHjejMe/WMEOj8hj tQl0mn7nR2ZBzk0CpgF5SKbsSF2n5qvtXutz/Iywbg3+JFpPntvaWMV+lvWK2n50QyZ1 bgSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ezLz5t4W; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt15si1425884ejb.170.2020.10.27.09.12.56; Tue, 27 Oct 2020 09:12:56 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ezLz5t4W; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1807673AbgJ0QMz (ORCPT + 8 others); Tue, 27 Oct 2020 12:12:55 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:37918 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1807544AbgJ0QLf (ORCPT ); Tue, 27 Oct 2020 12:11:35 -0400 Received: by mail-io1-f67.google.com with SMTP id y20so2127523iod.5 for ; Tue, 27 Oct 2020 09:11:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vdv8LjT2CgfUj8c+ccLLrRWl2zDtGgEY+2d5t9DuZoQ=; b=ezLz5t4Watnu8iYcnTyQEwoLmhxFfGy4kPGwfZ86E19HsahqY6zaqLXAlmA4z4mVFa MMUz7enZq7mit3DZosxtSNBAntOA6JLb15t04kakk32aYvD0kbkP6t9HPbWpFPYYlpW8 IEp6YbPP8KHlGkh4AlcP11eeWzuAEUTBaZMl1Q4tVPt/bQJL+PYTSrmBPPdrHFqcI/rW BcPd5i9q5KadZobPhBgbPLcfgBms3A+FPf/8VkvE3FpM5v9KwB1n08+t37x5MI/F2o5P u5Ruo8Bh/C2+1OVSyhEe/G8lx8GTCuN747+OfdQwJD8wTge11T7yMRQIw92+hFgU5Qaz yopw== 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=vdv8LjT2CgfUj8c+ccLLrRWl2zDtGgEY+2d5t9DuZoQ=; b=sW8pdKF1kbF3jnDiicNszrGgqund6FH146T7Vd+6oUDpZ2xIrC9V6jZ9Be9GSG/N8U gM+PDwwxVzU2TLzJX85JkRCSCbLlMlm9tQ8BzRnw6L8WmH8k3UMZDvpH1X+fUIBtRCdf KnE3Slu/oAvvs1bVJ7mYHJAC7BKm1/yrKEb5zkC65LetfjuDfB1oVEBGFxij/FIEyCUm sX78r7PIVx5c1kniOkZC8GlnVii3zg09regczoTEkp4okQZH7AmkSn7E3ksaHCwoRWcC cNTBIIpM+zIGGilHP+SNVJQ8nxi0W9Ff6sWk75xfNTVwBbbif/l80pqG7rdQteLVxjqW 0dhw== X-Gm-Message-State: AOAM5324a+aJs5waHCyOQgQP9HozMGiOHmcdUImsojyTFIbvqxfACZmD mHQbhts/dMfAIZlDpWtX6/b1ZQ== X-Received: by 2002:a02:cd2c:: with SMTP id h12mr3176363jaq.138.1603815094306; Tue, 27 Oct 2020 09:11:34 -0700 (PDT) Received: from beast.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id w15sm1082264iom.6.2020.10.27.09.11.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 09:11:33 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: evgreen@chromium.org, subashab@codeaurora.org, cpratapa@codeaurora.org, bjorn.andersson@linaro.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net 5/5] net: ipa: avoid going past end of resource group array Date: Tue, 27 Oct 2020 11:11:20 -0500 Message-Id: <20201027161120.5575-6-elder@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201027161120.5575-1-elder@linaro.org> References: <20201027161120.5575-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The minimum and maximum limits for resources assigned to a given resource group are programmed in pairs, with the limits for two groups set in a single register. If the number of supported resource groups is odd, only half of the register that defines these limits is valid for the last group; that group has no second group in the pair. Currently we ignore this constraint, and it turns out to be harmless, but it is not guaranteed to be. This patch addresses that, and adds support for programming the 5th resource group's limits. Rework how the resource group limit registers are programmed by having a single function program all group pairs rather than having one function program each pair. Add the programming of the 4-5 resource group pair limits to this function. If a resource group is not supported, pass a null pointer to ipa_resource_config_common() for that group and have that function write zeroes in that case. Fixes: cdf2e9419dd91 ("soc: qcom: ipa: main code") Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_main.c | 89 +++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 36 deletions(-) -- 2.20.1 diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c index 74b1e15ebd6b2..09c8a16d216df 100644 --- a/drivers/net/ipa/ipa_main.c +++ b/drivers/net/ipa/ipa_main.c @@ -370,8 +370,11 @@ static bool ipa_resource_limits_valid(struct ipa *ipa, u32 i; u32 j; + /* We program at most 6 source or destination resource group limits */ + BUILD_BUG_ON(IPA_RESOURCE_GROUP_SRC_MAX > 6); + group_count = ipa_resource_group_src_count(ipa->version); - if (!group_count) + if (!group_count || group_count >= IPA_RESOURCE_GROUP_SRC_MAX) return false; /* Return an error if a non-zero resource limit is specified @@ -387,7 +390,7 @@ static bool ipa_resource_limits_valid(struct ipa *ipa, } group_count = ipa_resource_group_dst_count(ipa->version); - if (!group_count) + if (!group_count || group_count >= IPA_RESOURCE_GROUP_DST_MAX) return false; for (i = 0; i < data->resource_dst_count; i++) { @@ -421,46 +424,64 @@ ipa_resource_config_common(struct ipa *ipa, u32 offset, val = u32_encode_bits(xlimits->min, X_MIN_LIM_FMASK); val |= u32_encode_bits(xlimits->max, X_MAX_LIM_FMASK); - val |= u32_encode_bits(ylimits->min, Y_MIN_LIM_FMASK); - val |= u32_encode_bits(ylimits->max, Y_MAX_LIM_FMASK); + if (ylimits) { + val |= u32_encode_bits(ylimits->min, Y_MIN_LIM_FMASK); + val |= u32_encode_bits(ylimits->max, Y_MAX_LIM_FMASK); + } iowrite32(val, ipa->reg_virt + offset); } -static void ipa_resource_config_src_01(struct ipa *ipa, - const struct ipa_resource_src *resource) +static void ipa_resource_config_src(struct ipa *ipa, + const struct ipa_resource_src *resource) { - u32 offset = IPA_REG_SRC_RSRC_GRP_01_RSRC_TYPE_N_OFFSET(resource->type); + u32 group_count = ipa_resource_group_src_count(ipa->version); + const struct ipa_resource_limits *ylimits; + u32 offset; - ipa_resource_config_common(ipa, offset, - &resource->limits[0], &resource->limits[1]); -} + offset = IPA_REG_SRC_RSRC_GRP_01_RSRC_TYPE_N_OFFSET(resource->type); + ylimits = group_count == 1 ? NULL : &resource->limits[1]; + ipa_resource_config_common(ipa, offset, &resource->limits[0], ylimits); -static void ipa_resource_config_src_23(struct ipa *ipa, - const struct ipa_resource_src *resource) -{ - u32 offset = IPA_REG_SRC_RSRC_GRP_23_RSRC_TYPE_N_OFFSET(resource->type); + if (group_count < 2) + return; - ipa_resource_config_common(ipa, offset, - &resource->limits[2], &resource->limits[3]); -} + offset = IPA_REG_SRC_RSRC_GRP_23_RSRC_TYPE_N_OFFSET(resource->type); + ylimits = group_count == 3 ? NULL : &resource->limits[3]; + ipa_resource_config_common(ipa, offset, &resource->limits[2], ylimits); -static void ipa_resource_config_dst_01(struct ipa *ipa, - const struct ipa_resource_dst *resource) -{ - u32 offset = IPA_REG_DST_RSRC_GRP_01_RSRC_TYPE_N_OFFSET(resource->type); + if (group_count < 4) + return; - ipa_resource_config_common(ipa, offset, - &resource->limits[0], &resource->limits[1]); + offset = IPA_REG_SRC_RSRC_GRP_45_RSRC_TYPE_N_OFFSET(resource->type); + ylimits = group_count == 5 ? NULL : &resource->limits[5]; + ipa_resource_config_common(ipa, offset, &resource->limits[4], ylimits); } -static void ipa_resource_config_dst_23(struct ipa *ipa, - const struct ipa_resource_dst *resource) +static void ipa_resource_config_dst(struct ipa *ipa, + const struct ipa_resource_dst *resource) { - u32 offset = IPA_REG_DST_RSRC_GRP_23_RSRC_TYPE_N_OFFSET(resource->type); + u32 group_count = ipa_resource_group_dst_count(ipa->version); + const struct ipa_resource_limits *ylimits; + u32 offset; + + offset = IPA_REG_DST_RSRC_GRP_01_RSRC_TYPE_N_OFFSET(resource->type); + ylimits = group_count == 1 ? NULL : &resource->limits[1]; + ipa_resource_config_common(ipa, offset, &resource->limits[0], ylimits); + + if (group_count < 2) + return; + + offset = IPA_REG_DST_RSRC_GRP_23_RSRC_TYPE_N_OFFSET(resource->type); + ylimits = group_count == 3 ? NULL : &resource->limits[3]; + ipa_resource_config_common(ipa, offset, &resource->limits[2], ylimits); + + if (group_count < 4) + return; - ipa_resource_config_common(ipa, offset, - &resource->limits[2], &resource->limits[3]); + offset = IPA_REG_DST_RSRC_GRP_45_RSRC_TYPE_N_OFFSET(resource->type); + ylimits = group_count == 5 ? NULL : &resource->limits[5]; + ipa_resource_config_common(ipa, offset, &resource->limits[4], ylimits); } static int @@ -471,15 +492,11 @@ ipa_resource_config(struct ipa *ipa, const struct ipa_resource_data *data) if (!ipa_resource_limits_valid(ipa, data)) return -EINVAL; - for (i = 0; i < data->resource_src_count; i++) { - ipa_resource_config_src_01(ipa, &data->resource_src[i]); - ipa_resource_config_src_23(ipa, &data->resource_src[i]); - } + for (i = 0; i < data->resource_src_count; i++) + ipa_resource_config_src(ipa, data->resource_src); - for (i = 0; i < data->resource_dst_count; i++) { - ipa_resource_config_dst_01(ipa, &data->resource_dst[i]); - ipa_resource_config_dst_23(ipa, &data->resource_dst[i]); - } + for (i = 0; i < data->resource_dst_count; i++) + ipa_resource_config_dst(ipa, data->resource_dst); return 0; }