From patchwork Wed Aug 31 22:40:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 601871 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 63E3BECAAD4 for ; Wed, 31 Aug 2022 22:40:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232549AbiHaWk0 (ORCPT ); Wed, 31 Aug 2022 18:40:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232186AbiHaWkZ (ORCPT ); Wed, 31 Aug 2022 18:40:25 -0400 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79E217B7AA for ; Wed, 31 Aug 2022 15:40:23 -0700 (PDT) Received: by mail-io1-xd2a.google.com with SMTP id z72so13166394iof.12 for ; Wed, 31 Aug 2022 15:40:23 -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; bh=hjkW+5FH7s1T93UZlntThyQm/ZXADqLvUTT7CWgmonE=; b=Nnwv169lcchIRi5N50vLHCVg0GD83gYuwrhUTbKeysdRSeVhUfGyShjZkynN+H9fkz Llyy/qD77FnfR+XAHjvR1oWIxt9XRP1OxinTBBrs0rTXoxs9R2LF7GenOozgEgtruMcz Ku/swqIu8gVSnXHYcwMIKYQggwfbRaUEjGeHwiLbeW7Gg3yM/YE2I+kyNmPXDO0tWcQh txaonBYPfNiaNveIL24qrg8QKDDVT1bctVPwy1PVgdJqXFLLjKwfHU98p+t2EQHHC90P v0Uy7L/4laStfaoAg5HcA00OT3mPvGAsk7izfExnF28oQ/VpQOBpdkcqfhcZ2dygSndb Clkg== 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; bh=hjkW+5FH7s1T93UZlntThyQm/ZXADqLvUTT7CWgmonE=; b=QS5hEKvpvC/QrjH58I6ujtMgcxXCdWH1VC+KGnjFS3IR3Mx/llgqOAj6XvWbtLFnZi PDDSXdChGbGnevzNS+U+kODCZvcN3zQ9xT50NalUWHJNU9+JE+e4LoRWWadbSsUo8ryL 1TyilABUSo2QPkiusMCu7PVQl8wpFQoB1+9yMch0cYQTF6Zt9eE44ryHqC1jzv3oL7lQ Fhd5TNRaPHX8xk6YbIj9S5sUXYIhxT0CvA9+jgGG7rUDR1Z/B10EjGZPyzUGVmF5l+65 LkfnvjLtzpGSEJfkh8XC/vNlOVNy6qDEGFGEgNU2YmW+qDGoVmS0Pwwcd4rdeyE//KPS 4ncA== X-Gm-Message-State: ACgBeo3OCLi67d6QLK7esNuXK61wNRhhc8X5U1V7lLY4KPCwnwvs+oNo w23wy77p2htsM9lgUGONrW28nA== X-Google-Smtp-Source: AA6agR45AL7Z4KePSZ1jjAe8UmsoVzWr6mvZ/vFqsqKv1g3vR9ZLPuFuj/WzxpSanqjvbTKtI3fPww== X-Received: by 2002:a05:6638:3892:b0:342:8aa5:a050 with SMTP id b18-20020a056638389200b003428aa5a050mr16835283jav.145.1661985622865; Wed, 31 Aug 2022 15:40:22 -0700 (PDT) Received: from localhost.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id n30-20020a02a19e000000b0034c0db05629sm1392005jah.161.2022.08.31.15.40.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 15:40:22 -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, bjorn.andersson@linaro.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 1/6] net: ipa: use an array for transactions Date: Wed, 31 Aug 2022 17:40:12 -0500 Message-Id: <20220831224017.377745-2-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220831224017.377745-1-elder@linaro.org> References: <20220831224017.377745-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Transactions are always allocated one at a time. The maximum number of them we could ever need occurs if each TRE is assigned to a transaction. So a channel requires no more transactions than the number of TREs in its transfer ring. That number is known to be a power-of-2 less than 65536. The transaction pool abstraction is used for other things, but for transactions we can use a simple array of transaction structures, and use a free index to indicate which entry in the array is the next one free for allocation. By having the number of elements in the array be a power-of-2, we can use an ever-incrementing 16-bit free index, and use it modulo the array size. Distinguish a "trans_id" (whose value can exceed the number of entries in the transaction array) from a "trans_index" (which is less than the number of entries). Signed-off-by: Alex Elder --- drivers/net/ipa/gsi.h | 4 +++- drivers/net/ipa/gsi_trans.c | 39 +++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/drivers/net/ipa/gsi.h b/drivers/net/ipa/gsi.h index 23de5f67374cf..4a88aec7e7d92 100644 --- a/drivers/net/ipa/gsi.h +++ b/drivers/net/ipa/gsi.h @@ -82,7 +82,9 @@ struct gsi_trans_pool { struct gsi_trans_info { atomic_t tre_avail; /* TREs available for allocation */ - struct gsi_trans_pool pool; /* transaction pool */ + + u16 free_id; /* first free trans in array */ + struct gsi_trans *trans; /* transaction array */ struct gsi_trans **map; /* TRE -> transaction map */ struct gsi_trans_pool sg_pool; /* scatterlist pool */ diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index 18e7e8c405bea..9775e50d0423f 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -343,20 +343,22 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id, struct gsi_channel *channel = &gsi->channel[channel_id]; struct gsi_trans_info *trans_info; struct gsi_trans *trans; + u16 trans_index; if (WARN_ON(tre_count > channel->trans_tre_max)) return NULL; trans_info = &channel->trans_info; - /* We reserve the TREs now, but consume them at commit time. - * If there aren't enough available, we're done. - */ + /* If we can't reserve the TREs for the transaction, we're done */ if (!gsi_trans_tre_reserve(trans_info, tre_count)) return NULL; - /* Allocate and initialize non-zero fields in the transaction */ - trans = gsi_trans_pool_alloc(&trans_info->pool, 1); + trans_index = trans_info->free_id % channel->tre_count; + trans = &trans_info->trans[trans_index]; + memset(trans, 0, sizeof(*trans)); + + /* Initialize non-zero fields in the transaction */ trans->gsi = gsi; trans->channel_id = channel_id; trans->rsvd_count = tre_count; @@ -367,15 +369,17 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id, sg_init_marker(trans->sgl, tre_count); trans->direction = direction; - - spin_lock_bh(&trans_info->spinlock); - - list_add_tail(&trans->links, &trans_info->alloc); - - spin_unlock_bh(&trans_info->spinlock); - refcount_set(&trans->refcount, 1); + /* This free transaction will now be allocated */ + trans_info->free_id++; + + spin_lock_bh(&trans_info->spinlock); + + list_add_tail(&trans->links, &trans_info->alloc); + + spin_unlock_bh(&trans_info->spinlock); + return trans; } @@ -736,10 +740,11 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) * modulo that number to determine the next one that's free. * Transactions are allocated one at a time. */ - ret = gsi_trans_pool_init(&trans_info->pool, sizeof(struct gsi_trans), - tre_max, 1); - if (ret) + trans_info->trans = kcalloc(tre_count, sizeof(*trans_info->trans), + GFP_KERNEL); + if (!trans_info->trans) return -ENOMEM; + trans_info->free_id = 0; /* modulo channel->tre_count */ /* A completion event contains a pointer to the TRE that caused * the event (which will be the last one used by the transaction). @@ -777,7 +782,7 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) err_map_free: kfree(trans_info->map); err_trans_free: - gsi_trans_pool_exit(&trans_info->pool); + kfree(trans_info->trans); dev_err(gsi->dev, "error %d initializing channel %u transactions\n", ret, channel_id); @@ -791,6 +796,6 @@ void gsi_channel_trans_exit(struct gsi_channel *channel) struct gsi_trans_info *trans_info = &channel->trans_info; gsi_trans_pool_exit(&trans_info->sg_pool); - gsi_trans_pool_exit(&trans_info->pool); + kfree(trans_info->trans); kfree(trans_info->map); } From patchwork Wed Aug 31 22:40:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 601870 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 CFF23C64991 for ; Wed, 31 Aug 2022 22:40:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232586AbiHaWk2 (ORCPT ); Wed, 31 Aug 2022 18:40:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232561AbiHaWk0 (ORCPT ); Wed, 31 Aug 2022 18:40:26 -0400 Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FA1885FE0 for ; Wed, 31 Aug 2022 15:40:24 -0700 (PDT) Received: by mail-il1-x12b.google.com with SMTP id s11so6856362ilt.7 for ; Wed, 31 Aug 2022 15:40:24 -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; bh=xr5LlJafNYPtsRXFWcggz2TXxTu5qcopLJfaNmU/uX0=; b=s5uW3vqCPy4yTk5IW2Fzx7gJsfZQyEFZxK0exzAZA4rr/GN7/oM04jx09bxOWq6rPM MmnLYMmvUcMVxBMU4w4hHGXFHZkFj0eICzQfoMFgBuWFYhwoQFu1xqX8eA8fh07lsoy9 YVI75RZE0OOsMYAhuW9efX3MOcQH7wjVMAJfoLYCYVTJnhgMMwKRRYold39anoFMeihO FBw9BCWi9+IpwONUswMcjcb6FLe1WSyBvBntdMQZtRiJ5Ac2/eH9VGJlyMRT0c1zrjie 4i0atnTa0l0g9AnrgiF1HsEwB30RHyqIte9kpk8TmKj3VF6nt9IHwfcPk4fYEeXOa4n1 GrQw== 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; bh=xr5LlJafNYPtsRXFWcggz2TXxTu5qcopLJfaNmU/uX0=; b=Y8qrW0DwvIZnaOK5otkSXZ18ezP/+KBGHV6rUXfYcDdKBicjZjc6Dk/eOy2d0in/MJ x6Z+dzTTBpS2xQ/BVkmX31KEBkCAs3y4ZKWwZ2MNN65RvjhN47LwleqCSLWZ+Wwmw2an R+gUl7nSXAlBavaac8jfyPijlJ/LShBws0FKfA6B7+zJMSOOFDQlrT+p02sUKBQ1gmvU NxIwx6mu39bXggC4sTbKoxc1GFisSBBsGc/ljm9fxBnyV5SzlMY6I0sWQLWgNNG/3ozG LtflHr8QkXxBSEYNtP2YI7x+oYDESf8Tz1Fg15WNIR09GN6vbvbuDDKYPtG8M1aP0JVW T9Pg== X-Gm-Message-State: ACgBeo13+xMZy82bA03ElUdpoIpm+ucXfo/rHjyv+eQCLK4/WZ45jffQ 0iMThY+/FdUA6n8Cdy6gFdttKQ== X-Google-Smtp-Source: AA6agR4S8XU3EC4IdjW8yeW28mePPsI4gLVqcu8XuWnsJieRoTmxZqgsDBjJUkYZXh7gCZ9WWEAmjw== X-Received: by 2002:a92:c265:0:b0:2ea:8f5b:f759 with SMTP id h5-20020a92c265000000b002ea8f5bf759mr13095686ild.73.1661985623886; Wed, 31 Aug 2022 15:40:23 -0700 (PDT) Received: from localhost.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id n30-20020a02a19e000000b0034c0db05629sm1392005jah.161.2022.08.31.15.40.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 15:40:23 -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, bjorn.andersson@linaro.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/6] net: ipa: track allocated transactions with an ID Date: Wed, 31 Aug 2022 17:40:13 -0500 Message-Id: <20220831224017.377745-3-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220831224017.377745-1-elder@linaro.org> References: <20220831224017.377745-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Transactions for a channel are now managed in an array, with a free transaction ID indicating which is the next one free. Add another transaction ID field to track the first element in the array that has been allocated. Advance it when a transaction is committed (because that is when that transaction leaves allocated state). Temporarily add warnings that verify that the first allocated transaction tracked by the ID matches the first element on the allocated list, both when allocating and committing a transaction. Signed-off-by: Alex Elder --- NOTE: I find these temporary WARN_ON() calls helpful in proving the new index refers to the same transaction as the first element of an "old" list. I'll gladly remove these if requested. (This comment applies throughout this series.) drivers/net/ipa/gsi.h | 1 + drivers/net/ipa/gsi_trans.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/net/ipa/gsi.h b/drivers/net/ipa/gsi.h index 4a88aec7e7d92..6bbbda6f27eae 100644 --- a/drivers/net/ipa/gsi.h +++ b/drivers/net/ipa/gsi.h @@ -84,6 +84,7 @@ struct gsi_trans_info { atomic_t tre_avail; /* TREs available for allocation */ u16 free_id; /* first free trans in array */ + u16 allocated_id; /* first allocated transaction */ struct gsi_trans *trans; /* transaction array */ struct gsi_trans **map; /* TRE -> transaction map */ diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index 9775e50d0423f..d84400e13487f 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -246,12 +246,26 @@ static void gsi_trans_move_committed(struct gsi_trans *trans) { struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info = &channel->trans_info; + u16 trans_index; spin_lock_bh(&trans_info->spinlock); list_move_tail(&trans->links, &trans_info->committed); + trans = list_first_entry_or_null(&trans_info->alloc, + struct gsi_trans, links); + spin_unlock_bh(&trans_info->spinlock); + + /* This allocated transaction is now committed */ + trans_info->allocated_id++; + + if (trans) { + trans_index = trans_info->allocated_id % channel->tre_count; + WARN_ON(trans != &trans_info->trans[trans_index]); + } else { + WARN_ON(trans_info->allocated_id != trans_info->free_id); + } } /* Move transactions from the committed list to the pending list */ @@ -378,8 +392,14 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id, list_add_tail(&trans->links, &trans_info->alloc); + trans = list_first_entry(&trans_info->alloc, struct gsi_trans, links); + spin_unlock_bh(&trans_info->spinlock); + WARN_ON(trans_info->allocated_id == trans_info->free_id); + trans_index = trans_info->allocated_id % channel->tre_count; + WARN_ON(trans != &trans_info->trans[trans_index]); + return trans; } @@ -408,7 +428,10 @@ void gsi_trans_free(struct gsi_trans *trans) if (!last) return; - if (trans->used_count) + /* Unused transactions are allocated but never committed */ + if (!trans->used_count) + trans_info->allocated_id++; + else ipa_gsi_trans_release(trans); /* Releasing the reserved TREs implicitly frees the sgl[] and @@ -744,7 +767,8 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) GFP_KERNEL); if (!trans_info->trans) return -ENOMEM; - trans_info->free_id = 0; /* modulo channel->tre_count */ + trans_info->free_id = 0; /* all modulo channel->tre_count */ + trans_info->allocated_id = 0; /* A completion event contains a pointer to the TRE that caused * the event (which will be the last one used by the transaction). From patchwork Wed Aug 31 22:40:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 601478 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 AE1F1ECAAD5 for ; Wed, 31 Aug 2022 22:40:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232591AbiHaWk2 (ORCPT ); Wed, 31 Aug 2022 18:40:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232560AbiHaWk0 (ORCPT ); Wed, 31 Aug 2022 18:40:26 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 833F489CD7 for ; Wed, 31 Aug 2022 15:40:25 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id b17so1010940ilh.0 for ; Wed, 31 Aug 2022 15:40:25 -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; bh=FNHBw9fAedMEvmueNQFIEpZu4DZG/pmo27+myDmJUYQ=; b=T4votMRvaQ5gheXuQ8nqesjK6N7/oipC1fShu8/sYxhIl1eT5ugqduWyPd6Xo+1/m1 VuA+nHG6q86XBBw7yqRuZEmaynql9i2p8pH6a1wYyx9QGh0Svd5TB2xhmxBU812C8+zV ads0kaQW4PeB+o81cfvyjI8czR28khqo+ApnPCQR5kUCBathcxecfY7ABOaTIl4MHyAo qKSMdpe7K3dsxrusIH7NKSvPlBJdRGzhQrUccS7GkfaHg0GWyT9OYmG60RO687k0jBal Exo24UwsDrQKyOgdf8OphQmvr9O9W4eAQW2C9hJ10xhN3qiVrHWv0jjqhm96JPXc+pao pcIQ== 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; bh=FNHBw9fAedMEvmueNQFIEpZu4DZG/pmo27+myDmJUYQ=; b=aexqsZkTxjPCEKUvHnLMJ7F002JA/zJYxq2MWPglK0pXGigN/DJr1kVZRxndSDh7rA VVaMJsyv2vJNCZu/UdD+X7F7dER44BAw5BZTxNC8Jfgj2gMbR25DSQPuXKGLs3TV+EZj RTdw/njo8CruuXOVsz953ddHBJDHZwt2Xh0zCACtyE8weIuNWqJ+G835WbMu21N1GQTq HCqBLOcFP4dlN8lRqeb8/ArmKNwQjuis5YRf3nrpVGPPylY41ir8ViC00yEtBdbJ04MX DqjT5gAhkHQpIL+GXA8PEtS3t9ODwOFKwdlK7QZZ0yenUVCo2h0tCfuiacS9sio4i7yk 2m3w== X-Gm-Message-State: ACgBeo0ZCpaInid7J0t1fkoBJ/LjoH4yg/tySLmWKkyS1tK11cqKIpEQ 4uXY+X7mBqoM27fYyAi0wkgj/g== X-Google-Smtp-Source: AA6agR43T90S0/2mpnSBwJQNSAN7MM04L/zu9Nh52MTHPfKq+mm6Fc/rmuVLv10fg+Ehm7vPtiDGqA== X-Received: by 2002:a05:6e02:1524:b0:2ec:71c6:7b85 with SMTP id i4-20020a056e02152400b002ec71c67b85mr1042342ilu.237.1661985624914; Wed, 31 Aug 2022 15:40:24 -0700 (PDT) Received: from localhost.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id n30-20020a02a19e000000b0034c0db05629sm1392005jah.161.2022.08.31.15.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 15:40:24 -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, bjorn.andersson@linaro.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 3/6] net: ipa: track committed transactions with an ID Date: Wed, 31 Aug 2022 17:40:14 -0500 Message-Id: <20220831224017.377745-4-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220831224017.377745-1-elder@linaro.org> References: <20220831224017.377745-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add a transaction ID field to track the first element in a channel's transaction array that has been committed, but not yet passed to the hardware. Advance the ID when the hardware is notified via doorbell that TREs from a transaction are ready for consumption. Temporarily add warnings that verify that the first committed transaction tracked by the ID matches the first element on the committed list, both when committing and pending (at doorbell). Remove the temporary warnings added by the previous commit. Signed-off-by: Alex Elder --- drivers/net/ipa/gsi.h | 1 + drivers/net/ipa/gsi_trans.c | 45 +++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/drivers/net/ipa/gsi.h b/drivers/net/ipa/gsi.h index 6bbbda6f27eae..cc46a9119fc5b 100644 --- a/drivers/net/ipa/gsi.h +++ b/drivers/net/ipa/gsi.h @@ -85,6 +85,7 @@ struct gsi_trans_info { u16 free_id; /* first free trans in array */ u16 allocated_id; /* first allocated transaction */ + u16 committed_id; /* first committed transaction */ struct gsi_trans *trans; /* transaction array */ struct gsi_trans **map; /* TRE -> transaction map */ diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index d84400e13487f..72da795908fee 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -252,20 +252,17 @@ static void gsi_trans_move_committed(struct gsi_trans *trans) list_move_tail(&trans->links, &trans_info->committed); - trans = list_first_entry_or_null(&trans_info->alloc, - struct gsi_trans, links); + trans = list_first_entry(&trans_info->committed, + struct gsi_trans, links); spin_unlock_bh(&trans_info->spinlock); /* This allocated transaction is now committed */ trans_info->allocated_id++; - if (trans) { - trans_index = trans_info->allocated_id % channel->tre_count; - WARN_ON(trans != &trans_info->trans[trans_index]); - } else { - WARN_ON(trans_info->allocated_id != trans_info->free_id); - } + WARN_ON(trans_info->committed_id == trans_info->allocated_id); + trans_index = trans_info->committed_id % channel->tre_count; + WARN_ON(trans != &trans_info->trans[trans_index]); } /* Move transactions from the committed list to the pending list */ @@ -273,7 +270,9 @@ static void gsi_trans_move_pending(struct gsi_trans *trans) { struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info = &channel->trans_info; + u16 trans_index = trans - &trans_info->trans[0]; struct list_head list; + u16 delta; spin_lock_bh(&trans_info->spinlock); @@ -281,7 +280,22 @@ static void gsi_trans_move_pending(struct gsi_trans *trans) list_cut_position(&list, &trans_info->committed, &trans->links); list_splice_tail(&list, &trans_info->pending); + trans = list_first_entry_or_null(&trans_info->committed, + struct gsi_trans, links); + spin_unlock_bh(&trans_info->spinlock); + + /* These committed transactions are now pending */ + delta = trans_index - trans_info->committed_id + 1; + trans_info->committed_id += delta % channel->tre_count; + + if (trans) { + trans_index = trans_info->committed_id % channel->tre_count; + WARN_ON(trans != &trans_info->trans[trans_index]); + } else { + WARN_ON(trans_info->committed_id != + trans_info->allocated_id); + } } /* Move a transaction and all of its predecessors from the pending list @@ -392,14 +406,8 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id, list_add_tail(&trans->links, &trans_info->alloc); - trans = list_first_entry(&trans_info->alloc, struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); - WARN_ON(trans_info->allocated_id == trans_info->free_id); - trans_index = trans_info->allocated_id % channel->tre_count; - WARN_ON(trans != &trans_info->trans[trans_index]); - return trans; } @@ -428,11 +436,13 @@ void gsi_trans_free(struct gsi_trans *trans) if (!last) return; - /* Unused transactions are allocated but never committed */ - if (!trans->used_count) + /* Unused transactions are allocated but never committed or pending */ + if (!trans->used_count) { trans_info->allocated_id++; - else + trans_info->committed_id++; + } else { ipa_gsi_trans_release(trans); + } /* Releasing the reserved TREs implicitly frees the sgl[] and * (if present) info[] arrays, plus the transaction itself. @@ -769,6 +779,7 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) return -ENOMEM; trans_info->free_id = 0; /* all modulo channel->tre_count */ trans_info->allocated_id = 0; + trans_info->committed_id = 0; /* A completion event contains a pointer to the TRE that caused * the event (which will be the last one used by the transaction). From patchwork Wed Aug 31 22:40:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 601869 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 C0F2DECAAD5 for ; Wed, 31 Aug 2022 22:40:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232526AbiHaWkc (ORCPT ); Wed, 31 Aug 2022 18:40:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232590AbiHaWk2 (ORCPT ); Wed, 31 Aug 2022 18:40:28 -0400 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C97477B1FD for ; Wed, 31 Aug 2022 15:40:26 -0700 (PDT) Received: by mail-il1-x129.google.com with SMTP id h14so6761539ilh.10 for ; Wed, 31 Aug 2022 15:40:26 -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; bh=fKArLUzw6N+hE15V3rYIaHqoaxWoXFuO2t1gN8Zf76U=; b=fuP6aMIo/eSsHxECmDrj8dMXLYW1bCtFFRZmMCDqJlDZZuK/ouJoz/Kx4By5cYz7ta 8W0UwX9UJxa3AtwjFAbHBiE8MisBCZ4lbhBJsjpqONb1+LZJYwvn+rzxSu09JpYZTztK B1teChK0WYsFNWmDYNnesQwbwaSGfFLXeiNjvGKZXiU55tyZ+p9GBw1bliUZkEfCd6F5 6PX45drEUFYci05j13wXWjAUCuxbL+UUHUBy6d7axzVV9BoMgbGINqzPBSFS2Qb9N4zP rcCE57D5usnJb3zvv83R5f5zFnZnFkOWsAmmei1OsKZ0i6iv7WUPNJ+X/hVLqmG4KppL nK3w== 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; bh=fKArLUzw6N+hE15V3rYIaHqoaxWoXFuO2t1gN8Zf76U=; b=kVmZN+oo17othprlXReIGN7WmS9ZM4dtjGKOHZkd6sW+0eakkN6Q8gdZxtaENtY/dc UilJ8Ptdc+OsQQsP9KkIf3YEVntX5/cf88gggweStnTP64dplz6XpvYqnifvSy6xnSyI qBAKyQyKbwbIxKYwznSMj9uZE9jn7KhXShjG/seRf+xpKdB94k1OjfMpqHuU4bPLRScc vcxLl9W4e1kniVdVBv/nQyjp7YRWJBH45ME3MuLI0JUxM2mpNNcXyD2yq+/lp1FAcHVM EwgzOcXgnKk8iC8Zvy9agEnLIh1HWf3Qz9sETWZfKuy2fcrW6oC7Bz1D/iRr2IBek9A1 QA0Q== X-Gm-Message-State: ACgBeo1Tk2sNu3tzY+K/awHPG3+qeISjPk1XpK++ZCxo3j1ZaJQsu5U8 YY/3m6YwV2P/PnPy2joNmjj3fg== X-Google-Smtp-Source: AA6agR6hTYnDxOtkcXvoqmtwe1dB5WhE5hOJx5s9+QGIdkCVOefooukqHqvJlK2PDdPev3LmrCw38w== X-Received: by 2002:a92:2a0a:0:b0:2d9:2571:f57e with SMTP id r10-20020a922a0a000000b002d92571f57emr15255617ile.154.1661985625908; Wed, 31 Aug 2022 15:40:25 -0700 (PDT) Received: from localhost.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id n30-20020a02a19e000000b0034c0db05629sm1392005jah.161.2022.08.31.15.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 15:40:25 -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, bjorn.andersson@linaro.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 4/6] net: ipa: track pending transactions with an ID Date: Wed, 31 Aug 2022 17:40:15 -0500 Message-Id: <20220831224017.377745-5-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220831224017.377745-1-elder@linaro.org> References: <20220831224017.377745-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add a transaction ID field to track the first element in the transaction array that is pending (sent to hardware) but not yet complete. Advance the ID when a completion event for a channel indicates that transactions have completed. Temporarily add warnings that verify that the first pending transaction tracked by the ID matches the first element on the pending list, both when pending and completing, as well as when resetting the channel. Remove the temporary warnings added by the previous commit. Signed-off-by: Alex Elder --- drivers/net/ipa/gsi.h | 1 + drivers/net/ipa/gsi_trans.c | 46 ++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/drivers/net/ipa/gsi.h b/drivers/net/ipa/gsi.h index cc46a9119fc5b..f23e7e562585e 100644 --- a/drivers/net/ipa/gsi.h +++ b/drivers/net/ipa/gsi.h @@ -86,6 +86,7 @@ struct gsi_trans_info { u16 free_id; /* first free trans in array */ u16 allocated_id; /* first allocated transaction */ u16 committed_id; /* first committed transaction */ + u16 pending_id; /* first pending transaction */ struct gsi_trans *trans; /* transaction array */ struct gsi_trans **map; /* TRE -> transaction map */ diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index 72da795908fee..5e3b4f673d9fb 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -246,23 +246,15 @@ static void gsi_trans_move_committed(struct gsi_trans *trans) { struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info = &channel->trans_info; - u16 trans_index; spin_lock_bh(&trans_info->spinlock); list_move_tail(&trans->links, &trans_info->committed); - trans = list_first_entry(&trans_info->committed, - struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); /* This allocated transaction is now committed */ trans_info->allocated_id++; - - WARN_ON(trans_info->committed_id == trans_info->allocated_id); - trans_index = trans_info->committed_id % channel->tre_count; - WARN_ON(trans != &trans_info->trans[trans_index]); } /* Move transactions from the committed list to the pending list */ @@ -280,8 +272,8 @@ static void gsi_trans_move_pending(struct gsi_trans *trans) list_cut_position(&list, &trans_info->committed, &trans->links); list_splice_tail(&list, &trans_info->pending); - trans = list_first_entry_or_null(&trans_info->committed, - struct gsi_trans, links); + trans = list_first_entry(&trans_info->pending, + struct gsi_trans, links); spin_unlock_bh(&trans_info->spinlock); @@ -289,13 +281,9 @@ static void gsi_trans_move_pending(struct gsi_trans *trans) delta = trans_index - trans_info->committed_id + 1; trans_info->committed_id += delta % channel->tre_count; - if (trans) { - trans_index = trans_info->committed_id % channel->tre_count; - WARN_ON(trans != &trans_info->trans[trans_index]); - } else { - WARN_ON(trans_info->committed_id != - trans_info->allocated_id); - } + WARN_ON(trans_info->pending_id == trans_info->committed_id); + trans_index = trans_info->pending_id % channel->tre_count; + WARN_ON(trans != &trans_info->trans[trans_index]); } /* Move a transaction and all of its predecessors from the pending list @@ -305,7 +293,9 @@ void gsi_trans_move_complete(struct gsi_trans *trans) { struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info = &channel->trans_info; + u16 trans_index = trans - trans_info->trans; struct list_head list; + u16 delta; spin_lock_bh(&trans_info->spinlock); @@ -313,7 +303,23 @@ void gsi_trans_move_complete(struct gsi_trans *trans) list_cut_position(&list, &trans_info->pending, &trans->links); list_splice_tail(&list, &trans_info->complete); + trans = list_first_entry_or_null(&trans_info->pending, + struct gsi_trans, links); + spin_unlock_bh(&trans_info->spinlock); + + /* These pending transactions are now completed */ + delta = trans_index - trans_info->pending_id + 1; + delta %= channel->tre_count; + trans_info->pending_id += delta; + + if (trans) { + trans_index = trans_info->pending_id % channel->tre_count; + WARN_ON(trans != &trans_info->trans[trans_index]); + } else { + WARN_ON(trans_info->pending_id != + trans_info->committed_id); + } } /* Move a transaction from the completed list to the polled list */ @@ -436,10 +442,13 @@ void gsi_trans_free(struct gsi_trans *trans) if (!last) return; - /* Unused transactions are allocated but never committed or pending */ + /* Unused transactions are allocated but never committed, pending, + * or completed. + */ if (!trans->used_count) { trans_info->allocated_id++; trans_info->committed_id++; + trans_info->pending_id++; } else { ipa_gsi_trans_release(trans); } @@ -780,6 +789,7 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) trans_info->free_id = 0; /* all modulo channel->tre_count */ trans_info->allocated_id = 0; trans_info->committed_id = 0; + trans_info->pending_id = 0; /* A completion event contains a pointer to the TRE that caused * the event (which will be the last one used by the transaction). From patchwork Wed Aug 31 22:40:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 601477 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 99BC8ECAAD1 for ; Wed, 31 Aug 2022 22:40:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232604AbiHaWka (ORCPT ); Wed, 31 Aug 2022 18:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232593AbiHaWk3 (ORCPT ); Wed, 31 Aug 2022 18:40:29 -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 B4E2485FE0 for ; Wed, 31 Aug 2022 15:40:27 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id y17so3110684ilb.4 for ; Wed, 31 Aug 2022 15:40:27 -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; bh=Yc6ZsFPyEM3kFhmeyp2pTQv8n95urKP/xL3I5LxZcU8=; b=xtGGtkYdxXLUjN/j9lTbb1UmdHhBXQtjzhw3Zu73Z7MRb+Q92408zHAPe/wq8VP7F2 rcwFiITymzXNJ1OsJ/Mcy6tThqkCIdUP4k7erRx87ugJurqYnjF8s1+fb8ZZmuyAcKey hwz3dZQXxuuBoBGVz9Twq1C4EnoNE3YmF0tfoP2hXLjiFmQq9H7Zx/ySqnOQ26RfLLdu fUhKuSlNxxGl4CokHFxaJvI0Ox2i7GOikGCI31A6kZ3SQAh7BhTAqdOxAAGKiPH/cqRB ThhAyOMm8593l9SnquJbe5o6k8d5fqHiBWCvdlV7z5LRN94Er5KdB2DJAhGfFe12k1Et YMFg== 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; bh=Yc6ZsFPyEM3kFhmeyp2pTQv8n95urKP/xL3I5LxZcU8=; b=z3+4SPmzPqt5+MI7RnX27gwYgqtgS6NeLJ6Y27MxpK01OM/VxbmovR7BG8Zrm/dvCF upOaELHdUHQXjLJMF57ix2+MlG8EKcaXvUdBwAssUWuh05FibNW5CUHSlp7Ifo26Q+QB 3uXlP9SqbKpzbPN0rwVaevMAtrjGFaXQdocByMYCe0Cg4YcjyIbIq0nvyxAV5bPfnDIB 9lR7EtOpCsqfshAtKhTZBAGktHyQO7UFkw96uyqVpS6QCzXKX9PYCDDgt5DrdNs2WjVj AMXpWfP5Y8Kkf1lvS1tla3prLhk/ok30zDfO0cWir6RZFDi5rtT66HeJ7+ueCPTMUOsi fl7A== X-Gm-Message-State: ACgBeo0QstG4susDgqQH5tft+Nmuy8h30OKQwKCISt7u4ygkfnYPqEgL 2kVxH3TRmn84qLjqhlpU2dsTgA== X-Google-Smtp-Source: AA6agR7QXd4eyLjTxWT56dB7rYwndgVzG6luLUZfhqUiViyUKk1JhyL5zWuxt9oqVWPlCmiNKQ36Xg== X-Received: by 2002:a05:6e02:1ca9:b0:2e5:fa2a:6345 with SMTP id x9-20020a056e021ca900b002e5fa2a6345mr15057998ill.5.1661985627071; Wed, 31 Aug 2022 15:40:27 -0700 (PDT) Received: from localhost.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id n30-20020a02a19e000000b0034c0db05629sm1392005jah.161.2022.08.31.15.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 15:40:26 -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, bjorn.andersson@linaro.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 5/6] net: ipa: track completed transactions with an ID Date: Wed, 31 Aug 2022 17:40:16 -0500 Message-Id: <20220831224017.377745-6-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220831224017.377745-1-elder@linaro.org> References: <20220831224017.377745-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add a transaction ID field to track the first element in the transaction array that has completed but has not yet been polled. Advance the ID when we are processing a transaction in the NAPI polling loop (where completed transactions become polled). Temporarily add warnings that verify that the first completed transaction tracked by the ID matches the first element on the completed list, both when pending and completing. Remove the temporary warnings added by the previous commit. Signed-off-by: Alex Elder --- drivers/net/ipa/gsi.h | 1 + drivers/net/ipa/gsi_trans.c | 40 +++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/drivers/net/ipa/gsi.h b/drivers/net/ipa/gsi.h index f23e7e562585e..987f9f5f35d36 100644 --- a/drivers/net/ipa/gsi.h +++ b/drivers/net/ipa/gsi.h @@ -87,6 +87,7 @@ struct gsi_trans_info { u16 allocated_id; /* first allocated transaction */ u16 committed_id; /* first committed transaction */ u16 pending_id; /* first pending transaction */ + u16 completed_id; /* first completed transaction */ struct gsi_trans *trans; /* transaction array */ struct gsi_trans **map; /* TRE -> transaction map */ diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index 5e3b4f673d9fb..40852b1dd5b98 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -272,18 +272,11 @@ static void gsi_trans_move_pending(struct gsi_trans *trans) list_cut_position(&list, &trans_info->committed, &trans->links); list_splice_tail(&list, &trans_info->pending); - trans = list_first_entry(&trans_info->pending, - struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); /* These committed transactions are now pending */ delta = trans_index - trans_info->committed_id + 1; trans_info->committed_id += delta % channel->tre_count; - - WARN_ON(trans_info->pending_id == trans_info->committed_id); - trans_index = trans_info->pending_id % channel->tre_count; - WARN_ON(trans != &trans_info->trans[trans_index]); } /* Move a transaction and all of its predecessors from the pending list @@ -303,8 +296,8 @@ void gsi_trans_move_complete(struct gsi_trans *trans) list_cut_position(&list, &trans_info->pending, &trans->links); list_splice_tail(&list, &trans_info->complete); - trans = list_first_entry_or_null(&trans_info->pending, - struct gsi_trans, links); + trans = list_first_entry(&trans_info->complete, + struct gsi_trans, links); spin_unlock_bh(&trans_info->spinlock); @@ -313,13 +306,9 @@ void gsi_trans_move_complete(struct gsi_trans *trans) delta %= channel->tre_count; trans_info->pending_id += delta; - if (trans) { - trans_index = trans_info->pending_id % channel->tre_count; - WARN_ON(trans != &trans_info->trans[trans_index]); - } else { - WARN_ON(trans_info->pending_id != - trans_info->committed_id); - } + WARN_ON(trans_info->completed_id == trans_info->pending_id); + trans_index = trans_info->completed_id % channel->tre_count; + WARN_ON(trans != &trans_info->trans[trans_index]); } /* Move a transaction from the completed list to the polled list */ @@ -327,12 +316,27 @@ void gsi_trans_move_polled(struct gsi_trans *trans) { struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info = &channel->trans_info; + u16 trans_index; spin_lock_bh(&trans_info->spinlock); list_move_tail(&trans->links, &trans_info->polled); + trans = list_first_entry_or_null(&trans_info->complete, + struct gsi_trans, links); + spin_unlock_bh(&trans_info->spinlock); + + /* This completed transaction is now polled */ + trans_info->completed_id++; + + if (trans) { + trans_index = trans_info->completed_id % channel->tre_count; + WARN_ON(trans != &trans_info->trans[trans_index]); + } else { + WARN_ON(trans_info->completed_id != + trans_info->pending_id); + } } /* Reserve some number of TREs on a channel. Returns true if successful */ @@ -443,12 +447,13 @@ void gsi_trans_free(struct gsi_trans *trans) return; /* Unused transactions are allocated but never committed, pending, - * or completed. + * completed, or polled. */ if (!trans->used_count) { trans_info->allocated_id++; trans_info->committed_id++; trans_info->pending_id++; + trans_info->completed_id++; } else { ipa_gsi_trans_release(trans); } @@ -790,6 +795,7 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) trans_info->allocated_id = 0; trans_info->committed_id = 0; trans_info->pending_id = 0; + trans_info->completed_id = 0; /* A completion event contains a pointer to the TRE that caused * the event (which will be the last one used by the transaction). From patchwork Wed Aug 31 22:40:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 601476 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 211CDECAAD4 for ; Wed, 31 Aug 2022 22:40:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232607AbiHaWkn (ORCPT ); Wed, 31 Aug 2022 18:40:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232602AbiHaWka (ORCPT ); Wed, 31 Aug 2022 18:40:30 -0400 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4E258E0E5 for ; Wed, 31 Aug 2022 15:40:28 -0700 (PDT) Received: by mail-il1-x129.google.com with SMTP id s11so6856435ilt.7 for ; Wed, 31 Aug 2022 15:40:28 -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; bh=iA+ZsMRaFINLBa2q6rRWWDvmtN6jkG3m27+u4i2eWYk=; b=H+H0lsqEzdDcbzgUWISig1YUnIg/aehePSBnNojWIJj5QTRJWpJDhTDUIdVUWGmvrR frN9CtxPw+IA143oPez6mRWiKyGjGVU8bBjA3Wn59GA8d4910uqHdvCkbBQnEbv+xZZM i1k0g0/aGgThMCXoGwoX4NZk+tcIv6H3oZb4vEQDwwM8Qnk5RW4vNcNLUyhgp6exbeoU CYCd74UaJDUEw46FOi8MDuoBE6J+Edd3nx+kWSckyZhYh4HVYyQr6P5Ga6T1LDyCTHmD 1N50leIh8WybO3pC/EV1I+fwMyiKKLaOCP2og3t7ZdxRC32HCtZKfbOw1lVzzfp2IPPN TpcQ== 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; bh=iA+ZsMRaFINLBa2q6rRWWDvmtN6jkG3m27+u4i2eWYk=; b=TJntShDyXGMmmspVNw5N38IQXkwJlj1uDzoyyiysSf+OGDpbrGbP7L48jv0sjikvKG N5HVlT+AvEiQqKcqvxk6JfmaHC766Onv6TfqfiJW5Rm7S0tpf+gQNOxaNt8g+ZqjkpJq 6sLVvpKke5SVfUT00caNdmx/09hYU6KCKraK7ArFQNcOB6YnI7o+ti4QoSrlTrTgf3v0 0YT/nsr3CSgI64cVkCDeNnzOuKeOjlQwga+xbHYP09RjVN4Sg6ZZ55kl6UUC2RNlXtb0 vyiRVhz/atLKzMHKja6XD5j5m2OU8FTp8p/A9dgtqGfwbBhByxCylGdmv//Vtjsg3M4D 3EaA== X-Gm-Message-State: ACgBeo0YsDQ52Jo2CGCnfCqiTw4HsBZY5Eh0IQLLKsJBleZDKIH0Qdvo Y4QU2o3/7JF4wuD/xNDQN3xNAA== X-Google-Smtp-Source: AA6agR5x6getp83xkq0Tm4yf3gx4pL6enoWi1EqhzDjZt9MysZ1jzL7YI7dQgbx0LXwOTlUroLP0Ug== X-Received: by 2002:a92:8e09:0:b0:2eb:15a:c449 with SMTP id c9-20020a928e09000000b002eb015ac449mr8091188ild.162.1661985628119; Wed, 31 Aug 2022 15:40:28 -0700 (PDT) Received: from localhost.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id n30-20020a02a19e000000b0034c0db05629sm1392005jah.161.2022.08.31.15.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 15:40:27 -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, bjorn.andersson@linaro.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 6/6] net: ipa: track polled transactions with an ID Date: Wed, 31 Aug 2022 17:40:17 -0500 Message-Id: <20220831224017.377745-7-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220831224017.377745-1-elder@linaro.org> References: <20220831224017.377745-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add a transaction ID to track the first element in the transaction array that has been polled. Advance the ID when we are releasing a transaction. Temporarily add warnings that verify that the first polled transaction tracked by the ID matches the first element on the polled list, both when polling and freeing. Remove the temporary warnings added by the previous commit. Signed-off-by: Alex Elder --- drivers/net/ipa/gsi.h | 1 + drivers/net/ipa/gsi_trans.c | 39 ++++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/drivers/net/ipa/gsi.h b/drivers/net/ipa/gsi.h index 987f9f5f35d36..13468704c4000 100644 --- a/drivers/net/ipa/gsi.h +++ b/drivers/net/ipa/gsi.h @@ -88,6 +88,7 @@ struct gsi_trans_info { u16 committed_id; /* first committed transaction */ u16 pending_id; /* first pending transaction */ u16 completed_id; /* first completed transaction */ + u16 polled_id; /* first polled transaction */ struct gsi_trans *trans; /* transaction array */ struct gsi_trans **map; /* TRE -> transaction map */ diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index 40852b1dd5b98..4eef1480c2005 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -296,19 +296,12 @@ void gsi_trans_move_complete(struct gsi_trans *trans) list_cut_position(&list, &trans_info->pending, &trans->links); list_splice_tail(&list, &trans_info->complete); - trans = list_first_entry(&trans_info->complete, - struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); /* These pending transactions are now completed */ delta = trans_index - trans_info->pending_id + 1; delta %= channel->tre_count; trans_info->pending_id += delta; - - WARN_ON(trans_info->completed_id == trans_info->pending_id); - trans_index = trans_info->completed_id % channel->tre_count; - WARN_ON(trans != &trans_info->trans[trans_index]); } /* Move a transaction from the completed list to the polled list */ @@ -322,21 +315,17 @@ void gsi_trans_move_polled(struct gsi_trans *trans) list_move_tail(&trans->links, &trans_info->polled); - trans = list_first_entry_or_null(&trans_info->complete, - struct gsi_trans, links); + trans = list_first_entry(&trans_info->polled, + struct gsi_trans, links); spin_unlock_bh(&trans_info->spinlock); /* This completed transaction is now polled */ trans_info->completed_id++; - if (trans) { - trans_index = trans_info->completed_id % channel->tre_count; - WARN_ON(trans != &trans_info->trans[trans_index]); - } else { - WARN_ON(trans_info->completed_id != - trans_info->pending_id); - } + WARN_ON(trans_info->polled_id == trans_info->completed_id); + trans_index = trans_info->polled_id % channel->tre_count; + WARN_ON(trans != &trans_info->trans[trans_index]); } /* Reserve some number of TREs on a channel. Returns true if successful */ @@ -424,8 +413,11 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id, /* Free a previously-allocated transaction */ void gsi_trans_free(struct gsi_trans *trans) { + struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; refcount_t *refcount = &trans->refcount; struct gsi_trans_info *trans_info; + struct gsi_trans *polled; + u16 trans_index; bool last; /* We must hold the lock to release the last reference */ @@ -441,6 +433,9 @@ void gsi_trans_free(struct gsi_trans *trans) if (last) list_del(&trans->links); + polled = list_first_entry_or_null(&trans_info->polled, + struct gsi_trans, links); + spin_unlock_bh(&trans_info->spinlock); if (!last) @@ -458,6 +453,17 @@ void gsi_trans_free(struct gsi_trans *trans) ipa_gsi_trans_release(trans); } + /* This transaction is now free */ + trans_info->polled_id++; + + if (polled) { + trans_index = trans_info->polled_id % channel->tre_count; + WARN_ON(polled != &trans_info->trans[trans_index]); + } else { + WARN_ON(trans_info->polled_id != + trans_info->completed_id); + } + /* Releasing the reserved TREs implicitly frees the sgl[] and * (if present) info[] arrays, plus the transaction itself. */ @@ -796,6 +802,7 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) trans_info->committed_id = 0; trans_info->pending_id = 0; trans_info->completed_id = 0; + trans_info->polled_id = 0; /* A completion event contains a pointer to the TRE that caused * the event (which will be the last one used by the transaction).