From patchwork Tue Oct 25 19:51:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 10959 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1189001wru; Tue, 25 Oct 2022 12:57:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7eVfk7Ec1wYo/UtcTz45fyACwcBtQydzVcb8I3gqMd2dUfu//e0OYtyfjBcl8i9SfILrYl X-Received: by 2002:a17:907:2cce:b0:77a:6958:5aaa with SMTP id hg14-20020a1709072cce00b0077a69585aaamr32503205ejc.245.1666727854036; Tue, 25 Oct 2022 12:57:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666727854; cv=none; d=google.com; s=arc-20160816; b=oLn+qh/6DNhuAkeYQwtCPxVM+/Ei9hHmITq4gVnDucYLfHCo+Wx65SHthQUlOfkmbF wZaQMz8YV/KM3im9jmHcF9+Jfusd8pEtI0gVQ8YpFziUqZd2pSkUALaYlk2mpPTY/k1t IegpLP1kL9cv2MJyblSqKzXqVevzt8+aPjz2U0k2ukKB+FVqilSzF/NRwlA00UR2Vc3S xy4bAQuZWzn9gJaEyyfFshU77A53tsYMprnYaksZY/I8u6KGK3fZcSW+JkXJpu1wqiv9 J+7NQ28I5emmO8znO6ig9SFA6CkK3Sc418NrZL7wd7M6ANe0k+YrrvBvjSiq5CXvq4LE LC9A== 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=edo2LzRaJRftF/iqZOQNJxw3dQUUkViR6y/aHrA9w2E=; b=zfyfPKuBS6cCpjvaN/jSTcRMzrZJyTx1CQWd2CyXECIcN8eOPddUK0EuWwPcPQXqNU jdtO+m4cTd4hqVb7m2FCFKPVDQOL7EETWwvpUrJd14B1MwAADef+MwNdEHj+XcHQZ/6D n1Qo0uGklDOCJvG3m3ssFdylyvB/nvWMIIItRrTb7sZNx3LDLCE7AJKRNQE3v3N6R68P TqzdSwAClYaK/3JdNlGsVSRYmzczkXDWf09+vAVQMWOUtX+cabfo453kY+gz+tUyaovl +jQyYLYBZrT0us/gcth9Z3R8UUht1iqat05MMrFhwaTRjpylhj53uR/8/flzBH1MOupe l7xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T6Ycp3vI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dx1-20020a170906a84100b00780e022dfb8si2930891ejb.494.2022.10.25.12.57.10; Tue, 25 Oct 2022 12:57:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T6Ycp3vI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S232563AbiJYTwF (ORCPT + 99 others); Tue, 25 Oct 2022 15:52:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232447AbiJYTv6 (ORCPT ); Tue, 25 Oct 2022 15:51:58 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A208106E0E for ; Tue, 25 Oct 2022 12:51:54 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id h203so11439476iof.1 for ; Tue, 25 Oct 2022 12:51:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=edo2LzRaJRftF/iqZOQNJxw3dQUUkViR6y/aHrA9w2E=; b=T6Ycp3vIxUxmes1zXRChfYjP10CvMxnbVcBj1faRsM3tX7dTXttF7H4vVLpGnuqGRi m6X1geF/Jpn95cBDu+WpP/TbghIiZ7NuF5qKs7Ngo/5r4JXsanWFGfURZFhubnks/MaB 9jxiMh/3oEyS0YY5xcLnAHIsaarLphlMBNegeVNdZh3rw8VRAJW5o0d7td8o7cGxEJXh RNf9xZAVllRoQnboHC5PcXU8I8oLo0ZOGXH4Dmybirs03GBZ8xoFqc1YvEvVX17t9jzY XkuVRqblDOYAaPbrZFxm1wR1vOVEsCLRlwQIc7sVNiYL7yLqMJo9naR1q3yllM+KNiS9 GXrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=edo2LzRaJRftF/iqZOQNJxw3dQUUkViR6y/aHrA9w2E=; b=DvBrwW+xmayzrrlwBmOFkyuQz5U4e2iz7nfYqLaCdjZhmctrpv59ueRpcj6F5jjEL7 VtM2pBamKsA9TCQsH08tdPLDqm1MdjHuTZqPTLhRZCCNMZlNp2u2wzNDLvYllmf9Q6pz Jqa4bP07lV8+u/o5lnI2vlgZasu27K7u/3RuGTfG+RUMnq/Ge8KQ/A+NTyWufWQUGx3c EMtu4w7YF1oeymvaEOfZscetLlROcaypNNqH1JvkUL8gO/mx2CYs6OWtbStOrdNzGYwj FQC84PnFBpRlitYgfninSkoCjkdEmC+oUXfFLLG/pFORbkmBttUp2C0o+Nshf0AM/lGs 3GYA== X-Gm-Message-State: ACrzQf0jf7YC/GekKZFtivmgdA8guepHIz2shR5OLp9RXKE1FXxIUUqA WCecBfEtJEagm/6Bawe4N8sLkQ== X-Received: by 2002:a05:6602:491:b0:672:18ce:8189 with SMTP id y17-20020a056602049100b0067218ce8189mr24199288iov.170.1666727514041; Tue, 25 Oct 2022 12:51:54 -0700 (PDT) Received: from localhost.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id y10-20020a056638014a00b00349d2d52f6asm1211719jao.37.2022.10.25.12.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 12:51:52 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: mka@chromium.org, evgreen@chromium.org, andersson@kernel.org, quic_cpratapa@quicinc.com, quic_avuyyuru@quicinc.com, quic_jponduru@quicinc.com, quic_subashab@quicinc.com, elder@kernel.org, netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/4] net: ipa: determine route table size from memory region Date: Tue, 25 Oct 2022 14:51:41 -0500 Message-Id: <20221025195143.255934-3-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221025195143.255934-1-elder@linaro.org> References: <20221025195143.255934-1-elder@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747690826032135159?= X-GMAIL-MSGID: =?utf-8?q?1747690826032135159?= Currently we assume that any routing table contains a fixed number of entries. The number of entries in a routing table can actually vary, depending only on the size of the IPA-local memory region used to hold the table. Stop assuming that a routing table has exactly 15 entries. Instead, determine the number of entries in a routing table by dividing its memory region size by the size of an entry. The number of entries is computed early, when ipa_table_mem_valid() is called by ipa_table_init(). Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_cmd.c | 17 ++++++++--------- drivers/net/ipa/ipa_table.c | 14 +++++--------- drivers/net/ipa/ipa_table.h | 3 --- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/drivers/net/ipa/ipa_cmd.c b/drivers/net/ipa/ipa_cmd.c index de2cd86aa9e28..08e3f395a9453 100644 --- a/drivers/net/ipa/ipa_cmd.c +++ b/drivers/net/ipa/ipa_cmd.c @@ -145,18 +145,15 @@ union ipa_cmd_payload { static void ipa_cmd_validate_build(void) { - /* The sizes of a filter and route tables need to fit into fields - * in the ipa_cmd_hw_ip_fltrt_init structure. Although hashed tables + /* The size of a filter table needs to fit into fields in the + * ipa_cmd_hw_ip_fltrt_init structure. Although hashed tables * might not be used, non-hashed and hashed tables have the same * maximum size. IPv4 and IPv6 filter tables have the same number - * of entries, as and IPv4 and IPv6 route tables have the same number * of entries. */ -#define TABLE_SIZE (TABLE_COUNT_MAX * sizeof(__le64)) -#define TABLE_COUNT_MAX max_t(u32, IPA_ROUTE_COUNT_MAX, IPA_FILTER_COUNT_MAX) +#define TABLE_SIZE (IPA_FILTER_COUNT_MAX * sizeof(__le64)) BUILD_BUG_ON(TABLE_SIZE > field_max(IP_FLTRT_FLAGS_HASH_SIZE_FMASK)); BUILD_BUG_ON(TABLE_SIZE > field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK)); -#undef TABLE_COUNT_MAX #undef TABLE_SIZE /* Hashed and non-hashed fields are assumed to be the same size */ @@ -178,12 +175,14 @@ bool ipa_cmd_table_init_valid(struct ipa *ipa, const struct ipa_mem *mem, u32 size_max = field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK); const char *table = route ? "route" : "filter"; struct device *dev = &ipa->pdev->dev; + u32 size; + + size = route ? ipa->route_count * sizeof(__le64) : mem->size; /* Size must fit in the immediate command field that holds it */ - if (mem->size > size_max) { + if (size > size_max) { dev_err(dev, "%s table region size too large\n", table); - dev_err(dev, " (0x%04x > 0x%04x)\n", - mem->size, size_max); + dev_err(dev, " (0x%04x > 0x%04x)\n", size, size_max); return false; } diff --git a/drivers/net/ipa/ipa_table.c b/drivers/net/ipa/ipa_table.c index 0815c8967e914..23d3f081ac8e1 100644 --- a/drivers/net/ipa/ipa_table.c +++ b/drivers/net/ipa/ipa_table.c @@ -130,12 +130,8 @@ static void ipa_table_validate_build(void) */ BUILD_BUG_ON(IPA_ZERO_RULE_SIZE != sizeof(__le64)); - /* Impose a practical limit on the number of routes */ - BUILD_BUG_ON(IPA_ROUTE_COUNT_MAX > 32); /* The modem must be allotted at least one route table entry */ BUILD_BUG_ON(!IPA_ROUTE_MODEM_COUNT); - /* AP must too, but we can't use more than what is available */ - BUILD_BUG_ON(IPA_ROUTE_MODEM_COUNT >= IPA_ROUTE_COUNT_MAX); } static const struct ipa_mem * @@ -593,18 +589,18 @@ bool ipa_table_mem_valid(struct ipa *ipa, bool modem_route_count) if (mem_ipv4->size != mem_ipv6->size) return false; - /* Record the number of routing table entries */ + /* Compute the number of entries, and for routing tables, record it */ + count = mem_ipv4->size / sizeof(__le64); + if (count < 2) + return false; if (!filter) - ipa->route_count = IPA_ROUTE_COUNT_MAX; + ipa->route_count = count; /* Table offset and size must fit in TABLE_INIT command fields */ if (!ipa_cmd_table_init_valid(ipa, mem_ipv4, !filter)) return false; /* Make sure the regions are big enough */ - count = mem_ipv4->size / sizeof(__le64); - if (count < 2) - return false; if (filter) { /* Filter tables must able to hold the endpoint bitmap plus * an entry for each endpoint that supports filtering diff --git a/drivers/net/ipa/ipa_table.h b/drivers/net/ipa/ipa_table.h index 65d96debd3917..31363292dc1db 100644 --- a/drivers/net/ipa/ipa_table.h +++ b/drivers/net/ipa/ipa_table.h @@ -16,9 +16,6 @@ struct ipa; /* The number of route table entries allotted to the modem */ #define IPA_ROUTE_MODEM_COUNT 8 -/* The maximum number of route table entries (IPv4, IPv6; hashed or not) */ -#define IPA_ROUTE_COUNT_MAX 15 - /** * ipa_filter_map_valid() - Validate a filter table endpoint bitmap * @ipa: IPA pointer