From patchwork Wed Nov 2 22:11:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 14507 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp173166wru; Wed, 2 Nov 2022 15:19:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM46Zo0sMxSe8wBZmDD9XhISbNgYXgLNbwI8d2YEcN18cMsPRQoMVWuyCUY3tNRvgSmIPWjw X-Received: by 2002:a17:907:3d88:b0:7ae:943:1cc2 with SMTP id he8-20020a1709073d8800b007ae09431cc2mr4188406ejc.675.1667427549663; Wed, 02 Nov 2022 15:19:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667427549; cv=none; d=google.com; s=arc-20160816; b=oUxB3D0gNoq4vEa+s+UXs8FsUIPnMX0RtlICPogPH8sAl8btPpO5k5S535Vvw6gXY0 aIxT0i8Uxw3FAaa2dR2QoYw1XWa8WHrRoPcFcjtAAnrZZIqIjti6IU9B1HtV2AqDsrVZ 9tSG6TkPqJPku1FAxVWjdT4AGgRz/IS6plEUnq0blnFh8WBxXtCflLLfVjgmU2DxyUSj eR4jfdhuzMd4wB8ZED/lOD084oAhv1ul4+zTCCc26bGQ6UHJZwgOIA7vqAqgYiWXwaV1 wMg7TcqE5FdVfABrlj9i4GmwhgGQeI6Pn0uznTeyhbUlLw0Wkov8qG7PMEuElkCIZyk7 7huA== 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=awvIszSlBYbQTFNtVRRr363ktjZrC0gWJbbrDOYC/aw=; b=Uv/OKb2ihavxVAwNQQt9ZvHUgpfmRsoG9t4PQnJ1adKTPvUI5napRe9jxH9zRoQ2kV C0Rpj1CzuyJw7OhmjU6Z1yapTTCufpO3wCk6E0LH7wcVL4Gzca3y0m6y4KEv8ROQNE3G EqmpdJIF+SaOIwy/1HkYAfAXW0wBxhmfWVRXZUNdT6aC/tr+muna4GnmmSdoGUy3JUCA I6zMK4K/WYPQkjKbRqVVeQOZrdFK7KKABGyzNurz9qMSmccXQ/gaIf8Zf5b4h+rVm3Ig gk9c/YTJiTqlp1t+cdBivJI7oXJwtQBXSRsf1fL8Xv9Psze/2oX7A8X+QFacakUH1No0 jD3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lebLyog2; 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 ji17-20020a170907981100b0078b41dcf4b8si19236011ejc.479.2022.11.02.15.18.28; Wed, 02 Nov 2022 15:19:09 -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=lebLyog2; 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 S231542AbiKBWM1 (ORCPT + 99 others); Wed, 2 Nov 2022 18:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231504AbiKBWLz (ORCPT ); Wed, 2 Nov 2022 18:11:55 -0400 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF69DB4AA for ; Wed, 2 Nov 2022 15:11:51 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id e19so176815ili.4 for ; Wed, 02 Nov 2022 15:11:51 -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=awvIszSlBYbQTFNtVRRr363ktjZrC0gWJbbrDOYC/aw=; b=lebLyog2wztMpEEot55TP04NnKX9SjVNcWNDniFxJiAhXNDUBG7PZtVGfrjk778O8X xJOVjjZ72UBD6RXLHTBI2wD/A4CDaEH/TaGFrmBvlaNVB99bUcU/5kmDICdH3kI9P3jj C81M2wiDcc4ScK75rxHEGG7nk+Aw44LWcjC7PmdL1Wi4e5Px8siVV1FxytzI4/Ac+d5L psS0FXtpoSSYingR6m+H5itkBrsTHOVjXYYyLpnAc2b+4E2am8mcfkCkiiYcwnYC2HSd P5edIo/IpJpOPq7nhlXIjBIFr5HkF2gDPEdizYYQSg3HkEPlzbXeVKJZHdZuLw7U0KPS OOZA== 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=awvIszSlBYbQTFNtVRRr363ktjZrC0gWJbbrDOYC/aw=; b=UCEq2xEEXNWT6LVG4tUOoL/lCtrryFP5DShnIuKyQhz7DZL9zXjaV2/S/qQUjmxt8K NbQ5DzcCVjWvu1SUIBWvLdMeRVSrdeY9ofXlIz8UqF8WJCkh0uYAbGHYWwcGBkt3s1TW yfQUKOX/cl45PTpGXcUHV3bcOj8kVOSUzZetSScb3bR0lNmOnqZbUvzDt0Czu8EbNs8z 9VDdv3TsWAdBB1AV5QbD4UOSmsuQVYwul7jSHA3xN+wDRQ28I+G0EobWPJcXYyJi5RIh 0HsU59BQrVe0s1VfDRdaTaqhvm9NOtF55xHcBCoH8Go08uIBTiAFOI4SiUIjijyd2E4x CQ1g== X-Gm-Message-State: ACrzQf2FIiT622jSizripQangXfJMYo0LS5zRl3HLCcFwhY6jEQKQ4kR Uuv51rew6bEPcbdAG/lGoW2kTg== X-Received: by 2002:a05:6e02:d04:b0:300:8716:e7b1 with SMTP id g4-20020a056e020d0400b003008716e7b1mr16448650ilj.231.1667427110619; Wed, 02 Nov 2022 15:11:50 -0700 (PDT) Received: from presto.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id f8-20020a02a108000000b0037465a1dd3fsm5073974jag.156.2022.11.02.15.11.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 15:11:50 -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 v2 6/9] net: ipa: use a bitmap for available endpoints Date: Wed, 2 Nov 2022 17:11:36 -0500 Message-Id: <20221102221139.1091510-7-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221102221139.1091510-1-elder@linaro.org> References: <20221102221139.1091510-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 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?1748424509981729887?= X-GMAIL-MSGID: =?utf-8?q?1748424509981729887?= Similar to the previous patch, replace the 32-bit unsigned used to track endpoints supported by hardware with a Linux bitmap, to allow an arbitrary number of endpoints to be represented. Move ipa_endpoint_deconfig() above ipa_endpoint_config() and use it in the error path of the latter function. Signed-off-by: Alex Elder --- v2: - Use ipa_endpoint_deconfig() in ipa_endpoint_config() cleanup drivers/net/ipa/ipa.h | 8 ++++-- drivers/net/ipa/ipa_endpoint.c | 49 ++++++++++++++++++++++----------- drivers/net/ipa/ipa_interrupt.c | 8 ++++-- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/drivers/net/ipa/ipa.h b/drivers/net/ipa/ipa.h index 261c7263f9e31..c603575e2a58b 100644 --- a/drivers/net/ipa/ipa.h +++ b/drivers/net/ipa/ipa.h @@ -61,9 +61,10 @@ struct ipa_interrupt; * @zero_addr: DMA address of preallocated zero-filled memory * @zero_virt: Virtual address of preallocated zero-filled memory * @zero_size: Size (bytes) of preallocated zero-filled memory - * @endpoint_count: Number of endpoints represented by bit masks below + * @endpoint_count: Number of defined bits in most bitmaps below + * @available_count: Number of defined bits in the available bitmap * @defined: Bitmap of endpoints defined in config data - * @available: Bit mask indicating endpoints hardware supports + * @available: Bitmap of endpoints supported by hardware * @filter_map: Bit mask indicating endpoints that support filtering * @set_up: Bit mask indicating endpoints set up * @enabled: Bit mask indicating endpoints enabled @@ -119,8 +120,9 @@ struct ipa { /* Bitmaps indicating endpoint state */ u32 endpoint_count; + u32 available_count; unsigned long *defined; /* Defined in configuration data */ - u32 available; /* Supported by hardware */ + unsigned long *available; /* Supported by hardware */ u32 filter_map; u32 set_up; u32 enabled; diff --git a/drivers/net/ipa/ipa_endpoint.c b/drivers/net/ipa/ipa_endpoint.c index abc939c272b5a..a7932e8d0b2bf 100644 --- a/drivers/net/ipa/ipa_endpoint.c +++ b/drivers/net/ipa/ipa_endpoint.c @@ -351,19 +351,17 @@ ipa_endpoint_program_delay(struct ipa_endpoint *endpoint, bool enable) static bool ipa_endpoint_aggr_active(struct ipa_endpoint *endpoint) { u32 endpoint_id = endpoint->endpoint_id; - u32 mask = BIT(endpoint_id % 32); struct ipa *ipa = endpoint->ipa; u32 unit = endpoint_id / 32; const struct ipa_reg *reg; u32 val; - /* This works until we actually have more than 32 endpoints */ - WARN_ON(!(mask & ipa->available)); + WARN_ON(!test_bit(endpoint_id, ipa->available)); reg = ipa_reg(ipa, STATE_AGGR_ACTIVE); val = ioread32(ipa->reg_virt + ipa_reg_n_offset(reg, unit)); - return !!(val & mask); + return !!(val & BIT(endpoint_id % 32)); } static void ipa_endpoint_force_close(struct ipa_endpoint *endpoint) @@ -374,8 +372,7 @@ static void ipa_endpoint_force_close(struct ipa_endpoint *endpoint) u32 unit = endpoint_id / 32; const struct ipa_reg *reg; - /* This works until we actually have more than 32 endpoints */ - WARN_ON(!(mask & ipa->available)); + WARN_ON(!test_bit(endpoint_id, ipa->available)); reg = ipa_reg(ipa, AGGR_FORCE_CLOSE); iowrite32(mask, ipa->reg_virt + ipa_reg_n_offset(reg, unit)); @@ -1841,6 +1838,13 @@ void ipa_endpoint_teardown(struct ipa *ipa) ipa->set_up = 0; } +void ipa_endpoint_deconfig(struct ipa *ipa) +{ + ipa->available_count = 0; + bitmap_free(ipa->available); + ipa->available = NULL; +} + int ipa_endpoint_config(struct ipa *ipa) { struct device *dev = &ipa->pdev->dev; @@ -1863,7 +1867,13 @@ int ipa_endpoint_config(struct ipa *ipa) * assume the configuration is valid. */ if (ipa->version < IPA_VERSION_3_5) { - ipa->available = ~0; + ipa->available = bitmap_zalloc(IPA_ENDPOINT_MAX, GFP_KERNEL); + if (!ipa->available) + return -ENOMEM; + ipa->available_count = IPA_ENDPOINT_MAX; + + bitmap_set(ipa->available, 0, IPA_ENDPOINT_MAX); + return 0; } @@ -1885,8 +1895,15 @@ int ipa_endpoint_config(struct ipa *ipa) return -EINVAL; } + /* Allocate and initialize the available endpoint bitmap */ + ipa->available = bitmap_zalloc(limit, GFP_KERNEL); + if (!ipa->available) + return -ENOMEM; + ipa->available_count = limit; + /* Mark all supported RX and TX endpoints as available */ - ipa->available = GENMASK(limit - 1, rx_base) | GENMASK(tx_count - 1, 0); + bitmap_set(ipa->available, 0, tx_count); + bitmap_set(ipa->available, rx_base, rx_count); for_each_set_bit(endpoint_id, ipa->defined, ipa->endpoint_count) { struct ipa_endpoint *endpoint; @@ -1894,13 +1911,13 @@ int ipa_endpoint_config(struct ipa *ipa) if (endpoint_id >= limit) { dev_err(dev, "invalid endpoint id, %u > %u\n", endpoint_id, limit - 1); - return -EINVAL; + goto err_free_bitmap; } - if (!(BIT(endpoint_id) & ipa->available)) { + if (!test_bit(endpoint_id, ipa->available)) { dev_err(dev, "unavailable endpoint id %u\n", endpoint_id); - return -EINVAL; + goto err_free_bitmap; } /* Make sure it's pointing in the right direction */ @@ -1913,15 +1930,15 @@ int ipa_endpoint_config(struct ipa *ipa) } dev_err(dev, "endpoint id %u wrong direction\n", endpoint_id); - return -EINVAL; + goto err_free_bitmap; } return 0; -} -void ipa_endpoint_deconfig(struct ipa *ipa) -{ - ipa->available = 0; /* Nothing more to do */ +err_free_bitmap: + ipa_endpoint_deconfig(ipa); + + return -EINVAL; } static void ipa_endpoint_init_one(struct ipa *ipa, enum ipa_endpoint_name name, diff --git a/drivers/net/ipa/ipa_interrupt.c b/drivers/net/ipa/ipa_interrupt.c index a62bc667bda0e..a49f66efacb87 100644 --- a/drivers/net/ipa/ipa_interrupt.c +++ b/drivers/net/ipa/ipa_interrupt.c @@ -132,14 +132,13 @@ static void ipa_interrupt_suspend_control(struct ipa_interrupt *interrupt, u32 endpoint_id, bool enable) { struct ipa *ipa = interrupt->ipa; - u32 mask = BIT(endpoint_id % 32); u32 unit = endpoint_id / 32; const struct ipa_reg *reg; u32 offset; + u32 mask; u32 val; - /* This works until we actually have more than 32 endpoints */ - WARN_ON(!(mask & ipa->available)); + WARN_ON(!test_bit(endpoint_id, ipa->available)); /* IPA version 3.0 does not support TX_SUSPEND interrupt control */ if (ipa->version == IPA_VERSION_3_0) @@ -148,10 +147,13 @@ static void ipa_interrupt_suspend_control(struct ipa_interrupt *interrupt, reg = ipa_reg(ipa, IRQ_SUSPEND_EN); offset = ipa_reg_n_offset(reg, unit); val = ioread32(ipa->reg_virt + offset); + + mask = BIT(endpoint_id); if (enable) val |= mask; else val &= ~mask; + iowrite32(val, ipa->reg_virt + offset); }