Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4722106imw; Tue, 19 Jul 2022 11:57:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vkZj941L8tPEvTxCbrY7emMXYdBLVHAz/RPu/LNlYNdMH3l4BQHWK5TJO0KfXWJi4dhTzH X-Received: by 2002:a63:210:0:b0:419:c604:2c2b with SMTP id 16-20020a630210000000b00419c6042c2bmr23720741pgc.190.1658257030422; Tue, 19 Jul 2022 11:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658257030; cv=none; d=google.com; s=arc-20160816; b=xfY0EMCvhs6KhK/8joMq9ojcme7ckSt87ycVmWJO/I6VKp4a50b1cfIUM/7wsy5mfu v5ksmex31W4BbIAXSlH8kQqVQF0jIIZ4wSUPGZ+R7XNLjtb3xYZpLBMEw4huhbb8YyEw wn+y6N5NN8rJqwuql2f6VbjVJO6e+KN9BQYzRdrHANDwLFfvaN5jL78a4P7pRSpzpsyg hkYetvej4/g6+SY6ovtEdtGWLpGGAaAPQlZaxhEXnQj0efqJm/VIQycjcthDUy+d/jax 3SPI1j59yvc6VTiM6RCjh8vlqPCuuFqzzijF+70LJQUdvMEGtm5LKomOSFYn7z1ndi+a dMOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tjQd+IiiTzNLW2LdbGs9lPQ9GQarVE74SKVcOuBSN/0=; b=ammQfmpac3Fhhos3MDLSXuPz/fJNC4iF/r7wTvqOcHgmCk8ukGueDACwS1fVFWHUjM l/6cAzwuCbiVw9GOSW6Xim9MGJ58rr4Yr6T1kJzv4yI+RNwqzj5snt3e8/9YmunvOWbF Vjs99oG7yJV4F654l0xYjneZ8LafvEJUmpgX8UCepXNLS426aolKI6g+cQ+dwcdsbqoS Mwm+KAqeFqQ/qA21uuqpr5FIMLcSO8RHTxwpzR6WdlMITCeKCjhi73DcB41UEvriXmc4 GtuuaWP3zvxFe4grDgLye0jHFR9sUjLAWjPQaoie5UZ/EefIQ2hc+ohrLV+W9mxI+L6u IxSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EO6nnGG7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x21-20020a63b215000000b00411bc000639si19147210pge.93.2022.07.19.11.56.54; Tue, 19 Jul 2022 11:57:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EO6nnGG7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238495AbiGSSKd (ORCPT + 99 others); Tue, 19 Jul 2022 14:10:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239887AbiGSSK2 (ORCPT ); Tue, 19 Jul 2022 14:10:28 -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 9C4FE49B65 for ; Tue, 19 Jul 2022 11:10:27 -0700 (PDT) Received: by mail-il1-x12b.google.com with SMTP id s13so803781ilp.13 for ; Tue, 19 Jul 2022 11:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tjQd+IiiTzNLW2LdbGs9lPQ9GQarVE74SKVcOuBSN/0=; b=EO6nnGG7AnCHdAhOKx3ZvF6ZgT16cSGoVTK2lq/NLCf6BjUKWa6H0KbE7hvaWjALeV BiVR2FK3/AkDHidYSZtYsMUdlIM3Y0qUgE2oXOAKslRGn92MOh9uiT3nWSIJU/a9rxwd CaclPQ0DQE4Wujh6tRa8pCCIlMwe9+49hUD55grWtDedItC0M3UIbYb/zSoWreUtRDaV iMDptTymrRSzvdlbOc8HLpuoiSN0s24TtuNyHPSYJY49QLZ/LUHUmW71AyJya3Z+xz6J utAwm1Bm9SimKKZVZH3BOAbDqpbG+lDAyvnNHAAbSxNfdh7CiCvuvcJAyvBgnUCBC0jH Mi9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tjQd+IiiTzNLW2LdbGs9lPQ9GQarVE74SKVcOuBSN/0=; b=B/inRJWNa2m6ekf14y6134+y4Atb2rW6I0bor8qnKaSGHpPAxLSshSw0FmNaWDNHao yYnmmBim2qYnVKwP8pXSbM6IMIgpT/QfTGcFRz+n/WMo2lSihMPGW+md5+YC/TPIpOhk Px3vtwgdom6xeg94MkV3/+WNHMKHTC8vrMHcA+6XkAuN2kbWTSAihHp6HRdfWJ9QpySh AemWoyACXAKD6kUGrNaylf+Q25UpmN0cTaP693r7Jw1f2htT5c43sFD6Ni14WV9pTw2P unJBimebVJOofmVsybetngcN2juWIhgALINqKABsy0qzjnkpy/HtRALx+sgnAzh1ADcI Glgw== X-Gm-Message-State: AJIora/57loT0YXlsd4p6X+EeEc0nIr26RXlijllg+6iDYfTJT22rN2U j4LwQK/sBFe4HTITCceny8Bsrw== X-Received: by 2002:a92:c549:0:b0:2dc:949f:5514 with SMTP id a9-20020a92c549000000b002dc949f5514mr16200897ilj.301.1658254226976; Tue, 19 Jul 2022 11:10:26 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id f6-20020a056e020b4600b002dae42fa5f2sm6089552ilu.56.2022.07.19.11.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 11:10: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 v2 2/5] net: ipa: rearrange transaction initialization Date: Tue, 19 Jul 2022 13:10:17 -0500 Message-Id: <20220719181020.372697-3-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220719181020.372697-1-elder@linaro.org> References: <20220719181020.372697-1-elder@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The transaction map is really associated with the transaction pool; move its definition earlier in the gsi_trans_info structure. Rearrange initialization in gsi_channel_trans_init() so it sets the tre_avail value first, then initializes the transaction pool, and finally allocating the transaction map. Update comments. Signed-off-by: Alex Elder --- v2: Fixed the misspelling of "outstanding" in two spots. drivers/net/ipa/gsi.h | 3 +- drivers/net/ipa/gsi_trans.c | 60 +++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/drivers/net/ipa/gsi.h b/drivers/net/ipa/gsi.h index 1c8941911069d..c197df64e69a2 100644 --- a/drivers/net/ipa/gsi.h +++ b/drivers/net/ipa/gsi.h @@ -82,9 +82,10 @@ struct gsi_trans_pool { struct gsi_trans_info { atomic_t tre_avail; /* TREs available for allocation */ struct gsi_trans_pool pool; /* transaction pool */ + struct gsi_trans **map; /* TRE -> transaction map */ + struct gsi_trans_pool sg_pool; /* scatterlist pool */ struct gsi_trans_pool cmd_pool; /* command payload DMA pool */ - struct gsi_trans **map; /* TRE -> transaction map */ spinlock_t spinlock; /* protects updates to the lists */ struct list_head alloc; /* allocated, not committed */ diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index 45572ebb76e95..3f52932e9e413 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -709,6 +709,7 @@ void gsi_trans_read_byte_done(struct gsi *gsi, u32 channel_id) int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) { struct gsi_channel *channel = &gsi->channel[channel_id]; + u32 tre_count = channel->tre_count; struct gsi_trans_info *trans_info; u32 tre_max; int ret; @@ -716,30 +717,40 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) /* Ensure the size of a channel element is what's expected */ BUILD_BUG_ON(sizeof(struct gsi_tre) != GSI_RING_ELEMENT_SIZE); - /* The map array is used to determine what transaction is associated - * with a TRE that the hardware reports has completed. We need one - * map entry per TRE. - */ trans_info = &channel->trans_info; - trans_info->map = kcalloc(channel->tre_count, sizeof(*trans_info->map), - GFP_KERNEL); - if (!trans_info->map) - return -ENOMEM; - /* We can't use more TREs than there are available in the ring. + /* The tre_avail field is what ultimately limits the number of + * outstanding transactions and their resources. A transaction + * allocation succeeds only if the TREs available are sufficient + * for what the transaction might need. + */ + tre_max = gsi_channel_tre_max(channel->gsi, channel_id); + atomic_set(&trans_info->tre_avail, tre_max); + + /* We can't use more TREs than the number available in the ring. * This limits the number of transactions that can be outstanding. * Worst case is one TRE per transaction (but we actually limit - * it to something a little less than that). We allocate resources - * for transactions (including transaction structures) based on - * this maximum number. + * it to something a little less than that). By allocating a + * power-of-two number of transactions we can use an index + * modulo that number to determine the next one that's free. + * Transactions are allocated one at a time. */ - tre_max = gsi_channel_tre_max(channel->gsi, channel_id); - - /* Transactions are allocated one at a time. */ ret = gsi_trans_pool_init(&trans_info->pool, sizeof(struct gsi_trans), tre_max, 1); if (ret) - goto err_kfree; + return -ENOMEM; + + /* A completion event contains a pointer to the TRE that caused + * the event (which will be the last one used by the transaction). + * Each entry in this map records the transaction associated + * with a corresponding completed TRE. + */ + trans_info->map = kcalloc(tre_count, sizeof(*trans_info->map), + GFP_KERNEL); + if (!trans_info->map) { + ret = -ENOMEM; + goto err_trans_free; + } /* A transaction uses a scatterlist array to represent the data * transfers implemented by the transaction. Each scatterlist @@ -751,16 +762,7 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) sizeof(struct scatterlist), tre_max, channel->trans_tre_max); if (ret) - goto err_trans_pool_exit; - - /* Finally, the tre_avail field is what ultimately limits the number - * of outstanding transactions and their resources. A transaction - * allocation succeeds only if the TREs available are sufficient for - * what the transaction might need. Transaction resource pools are - * sized based on the maximum number of outstanding TREs, so there - * will always be resources available if there are TREs available. - */ - atomic_set(&trans_info->tre_avail, tre_max); + goto err_map_free; spin_lock_init(&trans_info->spinlock); INIT_LIST_HEAD(&trans_info->alloc); @@ -771,10 +773,10 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) return 0; -err_trans_pool_exit: - gsi_trans_pool_exit(&trans_info->pool); -err_kfree: +err_map_free: kfree(trans_info->map); +err_trans_free: + gsi_trans_pool_exit(&trans_info->pool); dev_err(gsi->dev, "error %d initializing channel %u transactions\n", ret, channel_id); -- 2.34.1