From nobody Tue Apr 7 00:42:40 2026 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 CDD30C65C0D for ; Wed, 31 Aug 2022 22:40:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232186AbiHaWka (ORCPT ); Wed, 31 Aug 2022 18:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232526AbiHaWkZ (ORCPT ); Wed, 31 Aug 2022 18:40:25 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 796BB7B1FD for ; Wed, 31 Aug 2022 15:40:23 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id p187so13177770iod.8 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=GCMcDgo0IEDHNDPEXPDBSAbpnX5mS8KcoSBhiV4eQqsBQ4xJNJAyfmtRaw94xh38Lq GGxtmwt3zzC055cVwnWxbQR5Y3qsk6Mbbc/1MfN1OFoekhWbRQ0I2qb/5uYekv8yKMNv 1naBNwK9l8w7SWuBMFGR/6vIRn+GG8sNJkuOD8nxBeQ3d4Tww7cEhfwqHpChQ08gM06m vvypszwSrgqVkcYJr+yRxiLqHY6j3NY2icE4PGm21MHKqsOCGy+MyaljUuIuePVOJfb5 otDR59uJthsMUmHEhbtpXQ19FeJinuShxdTSOAWX1i7nK1qtLKZyusGRmh8lXQEvPxot zCaA== X-Gm-Message-State: ACgBeo0mfkfX+NCEmaDS4Da6wML/uAMt5M/O1484L4pw4ArmvmXNcdJv r4r02vyfRVHHf7KuvYJCVKT3xQ== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 { =20 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 */ =20 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 =3D &gsi->channel[channel_id]; struct gsi_trans_info *trans_info; struct gsi_trans *trans; + u16 trans_index; =20 if (WARN_ON(tre_count > channel->trans_tre_max)) return NULL; =20 trans_info =3D &channel->trans_info; =20 - /* 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; =20 - /* Allocate and initialize non-zero fields in the transaction */ - trans =3D gsi_trans_pool_alloc(&trans_info->pool, 1); + trans_index =3D trans_info->free_id % channel->tre_count; + trans =3D &trans_info->trans[trans_index]; + memset(trans, 0, sizeof(*trans)); + + /* Initialize non-zero fields in the transaction */ trans->gsi =3D gsi; trans->channel_id =3D channel_id; trans->rsvd_count =3D 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); =20 trans->direction =3D 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); =20 + /* 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; } =20 @@ -736,10 +740,11 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 chann= el_id) * modulo that number to determine the next one that's free. * Transactions are allocated one at a time. */ - ret =3D gsi_trans_pool_init(&trans_info->pool, sizeof(struct gsi_trans), - tre_max, 1); - if (ret) + trans_info->trans =3D kcalloc(tre_count, sizeof(*trans_info->trans), + GFP_KERNEL); + if (!trans_info->trans) return -ENOMEM; + trans_info->free_id =3D 0; /* modulo channel->tre_count */ =20 /* 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); =20 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 =3D &channel->trans_info; =20 gsi_trans_pool_exit(&trans_info->sg_pool); - gsi_trans_pool_exit(&trans_info->pool); + kfree(trans_info->trans); kfree(trans_info->map); } --=20 2.34.1 From nobody Tue Apr 7 00:42:40 2026 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 5BD3DECAAD1 for ; Wed, 31 Aug 2022 22:40:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232628AbiHaWkf (ORCPT ); Wed, 31 Aug 2022 18:40:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232562AbiHaWk0 (ORCPT ); Wed, 31 Aug 2022 18:40:26 -0400 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9020286702 for ; Wed, 31 Aug 2022 15:40:24 -0700 (PDT) Received: by mail-il1-x135.google.com with SMTP id l6so6934755ilk.13 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=wRokdeKjvNjbVGyHoCLR6E3h3PqKQVDnLnARZ/fjEV4C5ODsHjlB5QjuuAhA+6xVFg HVUzWreJgqg8jpcXEI5iYJOnOi6OJcvbWKhhyVgo5nD5Vags65lIWynds9TF2S0d70bq LvwnP/6gO1eMLRsmO9KhLfRDkdEHuK4iamLtFXv5WtbTIHlamNZHoMz0G332RBHlfaoO ehVdLJAic+2+DWqxaCwMzlDOP6BFp8f/UjAmeak3co6WotvDlK/AisUCWfttNfc0ffXO ha2lgCd50RfCEwX5o+MytyNuTDVTkjw/b9l2xxzFbGEaKa9CHyPRHs/fWVR5GbPn+i3V rDbw== X-Gm-Message-State: ACgBeo0tyxdxtRbE2b2oaUcJo+Aj0zhF0XI88tAfhffSqXP4quX/t6rB ihyQsgU4NM4RWr3jWRsghP5bxg== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 */ =20 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 */ =20 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 =3D &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info =3D &channel->trans_info; + u16 trans_index; =20 spin_lock_bh(&trans_info->spinlock); =20 list_move_tail(&trans->links, &trans_info->committed); =20 + trans =3D 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 =3D trans_info->allocated_id % channel->tre_count; + WARN_ON(trans !=3D &trans_info->trans[trans_index]); + } else { + WARN_ON(trans_info->allocated_id !=3D trans_info->free_id); + } } =20 /* 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, =20 list_add_tail(&trans->links, &trans_info->alloc); =20 + trans =3D list_first_entry(&trans_info->alloc, struct gsi_trans, links); + spin_unlock_bh(&trans_info->spinlock); =20 + WARN_ON(trans_info->allocated_id =3D=3D trans_info->free_id); + trans_index =3D trans_info->allocated_id % channel->tre_count; + WARN_ON(trans !=3D &trans_info->trans[trans_index]); + return trans; } =20 @@ -408,7 +428,10 @@ void gsi_trans_free(struct gsi_trans *trans) if (!last) return; =20 - 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); =20 /* 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 =3D 0; /* modulo channel->tre_count */ + trans_info->free_id =3D 0; /* all modulo channel->tre_count */ + trans_info->allocated_id =3D 0; =20 /* A completion event contains a pointer to the TRE that caused * the event (which will be the last one used by the transaction). --=20 2.34.1 From nobody Tue Apr 7 00:42:40 2026 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 A666AECAAD1 for ; Wed, 31 Aug 2022 22:40:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232536AbiHaWkq (ORCPT ); Wed, 31 Aug 2022 18:40:46 -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 S232572AbiHaWk1 (ORCPT ); Wed, 31 Aug 2022 18:40:27 -0400 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 850F48A1E3 for ; Wed, 31 Aug 2022 15:40:25 -0700 (PDT) Received: by mail-il1-x136.google.com with SMTP id h14so6761523ilh.10 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=FuawCObxkiBHMWVGe/V9A1Z8Y3sxljjotLjww+5x88jRdkh4BHJ3er7b7I1nATJEBi rMPNHk6+D8DbNKeF0fSnbpkXikJ/KKF50tM3WFPnuszD+8w7JmLD/8gO8i+MYarW5rLU fDiftp6roDvs3CmgjiHNASEN6PZfDEz/9ZYTL6r7pJv4Jvqv+Mlf3VK1l4bYcvRC/JB/ bwDQfA4yFyVLpbu6zMq9hnm1EA3+cWsjsyuhlxbzVkam4qqrCIgveDJsuQ6429ErlQkK toiR9n5UHjyVzMtHukdSX7Vp6Z3EVHNratcgPozdVhm8zUav0Io3yMTYSmiAKAH8I6O8 Xktw== X-Gm-Message-State: ACgBeo1EwzVrtt6ymIqTLc6u/HTwkNYauM8Oh/rXwzzzTFimDT7BSvUo BJfxHIdnbaYcXKSLUUVjUJzZOQ== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 { =20 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 */ =20 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) =20 list_move_tail(&trans->links, &trans_info->committed); =20 - trans =3D list_first_entry_or_null(&trans_info->alloc, - struct gsi_trans, links); + trans =3D list_first_entry(&trans_info->committed, + struct gsi_trans, links); =20 spin_unlock_bh(&trans_info->spinlock); =20 /* This allocated transaction is now committed */ trans_info->allocated_id++; =20 - if (trans) { - trans_index =3D trans_info->allocated_id % channel->tre_count; - WARN_ON(trans !=3D &trans_info->trans[trans_index]); - } else { - WARN_ON(trans_info->allocated_id !=3D trans_info->free_id); - } + WARN_ON(trans_info->committed_id =3D=3D trans_info->allocated_id); + trans_index =3D trans_info->committed_id % channel->tre_count; + WARN_ON(trans !=3D &trans_info->trans[trans_index]); } =20 /* Move transactions from the committed list to the pending list */ @@ -273,7 +270,9 @@ static void gsi_trans_move_pending(struct gsi_trans *tr= ans) { struct gsi_channel *channel =3D &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info =3D &channel->trans_info; + u16 trans_index =3D trans - &trans_info->trans[0]; struct list_head list; + u16 delta; =20 spin_lock_bh(&trans_info->spinlock); =20 @@ -281,7 +280,22 @@ static void gsi_trans_move_pending(struct gsi_trans *t= rans) list_cut_position(&list, &trans_info->committed, &trans->links); list_splice_tail(&list, &trans_info->pending); =20 + trans =3D 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 =3D trans_index - trans_info->committed_id + 1; + trans_info->committed_id +=3D delta % channel->tre_count; + + if (trans) { + trans_index =3D trans_info->committed_id % channel->tre_count; + WARN_ON(trans !=3D &trans_info->trans[trans_index]); + } else { + WARN_ON(trans_info->committed_id !=3D + trans_info->allocated_id); + } } =20 /* 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, =20 list_add_tail(&trans->links, &trans_info->alloc); =20 - trans =3D list_first_entry(&trans_info->alloc, struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); =20 - WARN_ON(trans_info->allocated_id =3D=3D trans_info->free_id); - trans_index =3D trans_info->allocated_id % channel->tre_count; - WARN_ON(trans !=3D &trans_info->trans[trans_index]); - return trans; } =20 @@ -428,11 +436,13 @@ void gsi_trans_free(struct gsi_trans *trans) if (!last) return; =20 - /* 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); + } =20 /* 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 =3D 0; /* all modulo channel->tre_count */ trans_info->allocated_id =3D 0; + trans_info->committed_id =3D 0; =20 /* A completion event contains a pointer to the TRE that caused * the event (which will be the last one used by the transaction). --=20 2.34.1 From nobody Tue Apr 7 00:42:40 2026 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 7E711ECAAD4 for ; Wed, 31 Aug 2022 22:40:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232635AbiHaWkk (ORCPT ); Wed, 31 Aug 2022 18:40:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232588AbiHaWk2 (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 C983F7B7AA for ; Wed, 31 Aug 2022 15:40:26 -0700 (PDT) Received: by mail-il1-x129.google.com with SMTP id v15so5673595iln.6 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=AzdpKSbctAjv9GFTufP+AQoRF7/AiMpaDsPFVvy3PH5qshZfr+k5d9pZU4CYK3P9D7 OC2lwvK2SR2cfrtFy1VH6VmX8Lil51Q8oTKya0k9DVOpC8Fr1yqMwf3wxZ90ylSZjHh5 Iuo5F91Ugp7USg1J/fwI63sQr1Fr/TmS+OWkrOo6hj8mk4XOsVJ697Q3wK05XtyMKw9C lfpRKQ+hyYpIS90S/cQoggLUMEGBABl0re2L7W5uPD/YtWNUvS6BMMK5m6/GwGY98NIY ClaiujNL6N8GK/LcdOTjwLq9ve/LR8sDsFChZhNibnGcuIrOVgU2KHXlRz1GvsyDBIMv icvQ== X-Gm-Message-State: ACgBeo3ykmQdJ1fbY8yTkANipBwzO00Uy5jQtYU0dsWpt3s+KIQumDDs 66IK164/8WfNmL5uNv26EEAN3w== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 */ =20 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 =3D &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info =3D &channel->trans_info; - u16 trans_index; =20 spin_lock_bh(&trans_info->spinlock); =20 list_move_tail(&trans->links, &trans_info->committed); =20 - trans =3D list_first_entry(&trans_info->committed, - struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); =20 /* This allocated transaction is now committed */ trans_info->allocated_id++; - - WARN_ON(trans_info->committed_id =3D=3D trans_info->allocated_id); - trans_index =3D trans_info->committed_id % channel->tre_count; - WARN_ON(trans !=3D &trans_info->trans[trans_index]); } =20 /* Move transactions from the committed list to the pending list */ @@ -280,8 +272,8 @@ static void gsi_trans_move_pending(struct gsi_trans *tr= ans) list_cut_position(&list, &trans_info->committed, &trans->links); list_splice_tail(&list, &trans_info->pending); =20 - trans =3D list_first_entry_or_null(&trans_info->committed, - struct gsi_trans, links); + trans =3D list_first_entry(&trans_info->pending, + struct gsi_trans, links); =20 spin_unlock_bh(&trans_info->spinlock); =20 @@ -289,13 +281,9 @@ static void gsi_trans_move_pending(struct gsi_trans *t= rans) delta =3D trans_index - trans_info->committed_id + 1; trans_info->committed_id +=3D delta % channel->tre_count; =20 - if (trans) { - trans_index =3D trans_info->committed_id % channel->tre_count; - WARN_ON(trans !=3D &trans_info->trans[trans_index]); - } else { - WARN_ON(trans_info->committed_id !=3D - trans_info->allocated_id); - } + WARN_ON(trans_info->pending_id =3D=3D trans_info->committed_id); + trans_index =3D trans_info->pending_id % channel->tre_count; + WARN_ON(trans !=3D &trans_info->trans[trans_index]); } =20 /* 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 =3D &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info =3D &channel->trans_info; + u16 trans_index =3D trans - trans_info->trans; struct list_head list; + u16 delta; =20 spin_lock_bh(&trans_info->spinlock); =20 @@ -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); =20 + trans =3D 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 =3D trans_index - trans_info->pending_id + 1; + delta %=3D channel->tre_count; + trans_info->pending_id +=3D delta; + + if (trans) { + trans_index =3D trans_info->pending_id % channel->tre_count; + WARN_ON(trans !=3D &trans_info->trans[trans_index]); + } else { + WARN_ON(trans_info->pending_id !=3D + trans_info->committed_id); + } } =20 /* 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; =20 - /* 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 =3D 0; /* all modulo channel->tre_count */ trans_info->allocated_id =3D 0; trans_info->committed_id =3D 0; + trans_info->pending_id =3D 0; =20 /* A completion event contains a pointer to the TRE that caused * the event (which will be the last one used by the transaction). --=20 2.34.1 From nobody Tue Apr 7 00:42:40 2026 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 5DDA2ECAAD1 for ; Wed, 31 Aug 2022 22:40:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232670AbiHaWkv (ORCPT ); Wed, 31 Aug 2022 18:40:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232594AbiHaWk3 (ORCPT ); Wed, 31 Aug 2022 18:40:29 -0400 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B857D86702 for ; Wed, 31 Aug 2022 15:40:27 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id t11so5561192ilf.3 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=STMGMbUhTDlwhTJ8kMRb2O82Lu9TdxKy1QAlb+qtU7Vz5gyXRlzy/XgaE7V6M9cWuW 5HDVXnLzD13K3rQhGp3/F77b2RlCGegP1FNnWOKvyVHinpHDaML7QcySQszS97kna0Ml Mtv9RwdOaea14yB9Io/Bul5EKOjU11+mHYvJJum/91/3m0CCt1h18KJAtMb7b65NDWH7 JDr6QqNUvdulsITCMfsn1IppwRlILOyRpJEp8U8ZI6KL8Es6nY2lnLpQSwba7VEhKuMW QqZ3YfvdhAQo7NVUMGeOLiKHIHFbuJUS4twSmbjR06jIOYxOxOpA5XHsj6dRHZYcnSxl RuRA== X-Gm-Message-State: ACgBeo1AQdVF98Lhu3ertQnL43PbbJfmnUU8AKXhxrz1CxhS4LZr1FhW i0QEmdtWe65FD+71fMKNeWVGzA== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 */ =20 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); =20 - trans =3D list_first_entry(&trans_info->pending, - struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); =20 /* These committed transactions are now pending */ delta =3D trans_index - trans_info->committed_id + 1; trans_info->committed_id +=3D delta % channel->tre_count; - - WARN_ON(trans_info->pending_id =3D=3D trans_info->committed_id); - trans_index =3D trans_info->pending_id % channel->tre_count; - WARN_ON(trans !=3D &trans_info->trans[trans_index]); } =20 /* 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); =20 - trans =3D list_first_entry_or_null(&trans_info->pending, - struct gsi_trans, links); + trans =3D list_first_entry(&trans_info->complete, + struct gsi_trans, links); =20 spin_unlock_bh(&trans_info->spinlock); =20 @@ -313,13 +306,9 @@ void gsi_trans_move_complete(struct gsi_trans *trans) delta %=3D channel->tre_count; trans_info->pending_id +=3D delta; =20 - if (trans) { - trans_index =3D trans_info->pending_id % channel->tre_count; - WARN_ON(trans !=3D &trans_info->trans[trans_index]); - } else { - WARN_ON(trans_info->pending_id !=3D - trans_info->committed_id); - } + WARN_ON(trans_info->completed_id =3D=3D trans_info->pending_id); + trans_index =3D trans_info->completed_id % channel->tre_count; + WARN_ON(trans !=3D &trans_info->trans[trans_index]); } =20 /* 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 =3D &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info =3D &channel->trans_info; + u16 trans_index; =20 spin_lock_bh(&trans_info->spinlock); =20 list_move_tail(&trans->links, &trans_info->polled); =20 + trans =3D 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 =3D trans_info->completed_id % channel->tre_count; + WARN_ON(trans !=3D &trans_info->trans[trans_index]); + } else { + WARN_ON(trans_info->completed_id !=3D + trans_info->pending_id); + } } =20 /* 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; =20 /* 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 =3D 0; trans_info->committed_id =3D 0; trans_info->pending_id =3D 0; + trans_info->completed_id =3D 0; =20 /* A completion event contains a pointer to the TRE that caused * the event (which will be the last one used by the transaction). --=20 2.34.1 From nobody Tue Apr 7 00:42:40 2026 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 73164ECAAD4 for ; Wed, 31 Aug 2022 22:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232680AbiHaWkw (ORCPT ); Wed, 31 Aug 2022 18:40:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232608AbiHaWkb (ORCPT ); Wed, 31 Aug 2022 18:40:31 -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 5314490C62 for ; Wed, 31 Aug 2022 15:40:29 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id e7so7013016ilc.5 for ; Wed, 31 Aug 2022 15:40:29 -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=uve1MFjRRL+0Hm9hYJgFKSSAL6jkxWsBkDAOqhZsBE4j8sJpu4RwkowgqoU852haQC Jjn18dyEZylyJkdU+wQpsfr2dmwYfl0d/3ORdLpPbl19BDH4msIhUzQClYfSooIJeIiw fRsEgXYdmgRM+Ed926PQV4/Z2EaET4JRAzpm/s3Jbhw+BqN+/3Ri4+uU0j3e3dAs3TsP UG4EBOlVhJA5RCdyzUwLWJ5pS3FG96OB+SXEWidtBRkBODmXeiRbiE4Y+F/PPV3Pqw5a PXDcsxPG0lu1SBOXWjOaAlbLP/9i0oOr3ktWKot4Z3GXEa5kURwSqshhMVG/4iW7V0Mc Y2ow== X-Gm-Message-State: ACgBeo3P5nDVHCXFW6NO6XpHERwH9cBZKIkPWtZxaoqqQxGDZl4KX7t3 0IhCabalLfbMHu5jHlPx1mDXrA== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 */ =20 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); =20 - trans =3D list_first_entry(&trans_info->complete, - struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); =20 /* These pending transactions are now completed */ delta =3D trans_index - trans_info->pending_id + 1; delta %=3D channel->tre_count; trans_info->pending_id +=3D delta; - - WARN_ON(trans_info->completed_id =3D=3D trans_info->pending_id); - trans_index =3D trans_info->completed_id % channel->tre_count; - WARN_ON(trans !=3D &trans_info->trans[trans_index]); } =20 /* Move a transaction from the completed list to the polled list */ @@ -322,21 +315,17 @@ void gsi_trans_move_polled(struct gsi_trans *trans) =20 list_move_tail(&trans->links, &trans_info->polled); =20 - trans =3D list_first_entry_or_null(&trans_info->complete, - struct gsi_trans, links); + trans =3D list_first_entry(&trans_info->polled, + struct gsi_trans, links); =20 spin_unlock_bh(&trans_info->spinlock); =20 /* This completed transaction is now polled */ trans_info->completed_id++; =20 - if (trans) { - trans_index =3D trans_info->completed_id % channel->tre_count; - WARN_ON(trans !=3D &trans_info->trans[trans_index]); - } else { - WARN_ON(trans_info->completed_id !=3D - trans_info->pending_id); - } + WARN_ON(trans_info->polled_id =3D=3D trans_info->completed_id); + trans_index =3D trans_info->polled_id % channel->tre_count; + WARN_ON(trans !=3D &trans_info->trans[trans_index]); } =20 /* 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 =3D &trans->gsi->channel[trans->channel_id]; refcount_t *refcount =3D &trans->refcount; struct gsi_trans_info *trans_info; + struct gsi_trans *polled; + u16 trans_index; bool last; =20 /* 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); =20 + polled =3D list_first_entry_or_null(&trans_info->polled, + struct gsi_trans, links); + spin_unlock_bh(&trans_info->spinlock); =20 if (!last) @@ -458,6 +453,17 @@ void gsi_trans_free(struct gsi_trans *trans) ipa_gsi_trans_release(trans); } =20 + /* This transaction is now free */ + trans_info->polled_id++; + + if (polled) { + trans_index =3D trans_info->polled_id % channel->tre_count; + WARN_ON(polled !=3D &trans_info->trans[trans_index]); + } else { + WARN_ON(trans_info->polled_id !=3D + 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 =3D 0; trans_info->pending_id =3D 0; trans_info->completed_id =3D 0; + trans_info->polled_id =3D 0; =20 /* A completion event contains a pointer to the TRE that caused * the event (which will be the last one used by the transaction). --=20 2.34.1