From patchwork Wed Dec 9 15:03:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 11961723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9AC4C4361B for ; Wed, 9 Dec 2020 14:56:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE35723719 for ; Wed, 9 Dec 2020 14:56:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733221AbgLIO4l (ORCPT ); Wed, 9 Dec 2020 09:56:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732558AbgLIO4l (ORCPT ); Wed, 9 Dec 2020 09:56:41 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03739C0613CF for ; Wed, 9 Dec 2020 06:56:01 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id i9so2065995wrc.4 for ; Wed, 09 Dec 2020 06:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=DvbvG6mQGm3snXcxs0szgugtcoGkSBwdHyd4ZKjZrVE=; b=oB8cX+Z4rNWyS4GCSBB/ODF7O05C4eQUADsbe2lrGqcdXoTFeqmv0cr+zaiHT8Ozpd ja3YSzbYRXWWLfMIvVIlnQKC5cGHMtSaqzUHqmSQLwnlAPnYZLvYSfP5nfSCItu/uMe5 QicDJlzLCj10J5iZFEuiJ4jMSNuqkAt+kQ6+5d7JXhfk1zsdyp+9rkZ1llgrGZfms/qw 2zDxF1GU049XQUfxzKX8URR6CqvdIjhUr+92PJPPxMs44PlQeYxNy5QKN9uFahftV8E5 WWA+tz2y+TiiIqg5QqlrR0iWuX3sBh78XmSRKuz+LWOvcNLeZQCVdBhE4PrWlps0rsXQ XBnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=DvbvG6mQGm3snXcxs0szgugtcoGkSBwdHyd4ZKjZrVE=; b=didVpMnIjewQZbU8qeWXrl+T28m94o30twf/bOGH4OYc5i+9heZWvHeZczw0I9AqRl 0vb/NKj3U36CgrTNmD5kMM+mIOFr5tV6EZTwGBWJaGaOmWMpGUGbVP9m4AHiBexrgvMf q/UECOfpRVORsHbQUEV8V7ik7HAjzGk8Y6QPPP+Dg1FRZWkSI+/ePTTkhUaoiEDYYMtd 4gYz/PxbBPbjRn57xnStxR4oiwDXxMhzFzjxC/9Lxg0kFS0jQ79ostaVKSbfluarnYYI aCiLKC07B6BJqgM3MxG2R35FoQWS0SswUb79poryWcuaBiDUSzud+Jtbk40k4L+fKw6E +CKg== X-Gm-Message-State: AOAM530C0F8pA/qSUOc2cBH57USbXBtZUiRm5z7AQ46Q/ZzPSGAsMoX0 ex48h1lLxFpPXLOGBedwDsTQSoBcmymhEpbV X-Google-Smtp-Source: ABdhPJyXtOpUmw7LcWmrd+o1rvAd+cU6WaHd2Ay85/a7Q5EWljbi+Y/+LpQK+VhbCaTiH62+JIMX2w== X-Received: by 2002:adf:ed12:: with SMTP id a18mr3132543wro.5.1607525759683; Wed, 09 Dec 2020 06:55:59 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:490:8730:c728:53f6:5e7e:2f63]) by smtp.gmail.com with ESMTPSA id i11sm3782219wrm.1.2020.12.09.06.55.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Dec 2020 06:55:59 -0800 (PST) From: Loic Poulain To: kuba@kernel.org Cc: manivannan.sadhasivam@linaro.org, linux-arm-msm@vger.kernel.org, netdev@vger.kernel.org, davem@davemloft.net, Hemant Kumar Subject: [PATCH 1/3] bus: mhi: core: Add helper API to return number of free TREs Date: Wed, 9 Dec 2020 16:03:01 +0100 Message-Id: <1607526183-25652-1-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Hemant Kumar Introduce mhi_get_free_desc_count() API to return number of TREs available to queue buffer. MHI clients can use this API to know before hand if ring is full without calling queue API. Signed-off-by: Hemant Kumar Reviewed-by: Jeffrey Hugo Reviewed-by: Manivannan Sadhasivam --- drivers/bus/mhi/core/main.c | 12 ++++++++++++ include/linux/mhi.h | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c index 54d9c80..a24ba4f 100644 --- a/drivers/bus/mhi/core/main.c +++ b/drivers/bus/mhi/core/main.c @@ -303,6 +303,18 @@ int mhi_destroy_device(struct device *dev, void *data) return 0; } +int mhi_get_free_desc_count(struct mhi_device *mhi_dev, + enum dma_data_direction dir) +{ + struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl; + struct mhi_chan *mhi_chan = (dir == DMA_TO_DEVICE) ? + mhi_dev->ul_chan : mhi_dev->dl_chan; + struct mhi_ring *tre_ring = &mhi_chan->tre_ring; + + return get_nr_avail_ring_elements(mhi_cntrl, tre_ring); +} +EXPORT_SYMBOL_GPL(mhi_get_free_desc_count); + void mhi_notify(struct mhi_device *mhi_dev, enum mhi_callback cb_reason) { struct mhi_driver *mhi_drv; diff --git a/include/linux/mhi.h b/include/linux/mhi.h index 09f786e..25c69a0 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -616,6 +616,15 @@ void mhi_set_mhi_state(struct mhi_controller *mhi_cntrl, void mhi_notify(struct mhi_device *mhi_dev, enum mhi_callback cb_reason); /** + * mhi_get_free_desc_count - Get transfer ring length + * Get # of TD available to queue buffers + * @mhi_dev: Device associated with the channels + * @dir: Direction of the channel + */ +int mhi_get_free_desc_count(struct mhi_device *mhi_dev, + enum dma_data_direction dir); + +/** * mhi_prepare_for_power_up - Do pre-initialization before power up. * This is optional, call this before power up if * the controller does not want bus framework to From patchwork Wed Dec 9 15:03:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 11961725 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAB36C4167B for ; Wed, 9 Dec 2020 14:57:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6658823719 for ; Wed, 9 Dec 2020 14:57:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733312AbgLIO47 (ORCPT ); Wed, 9 Dec 2020 09:56:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733310AbgLIO4n (ORCPT ); Wed, 9 Dec 2020 09:56:43 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57694C061794 for ; Wed, 9 Dec 2020 06:56:03 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id a3so1960436wmb.5 for ; Wed, 09 Dec 2020 06:56:03 -0800 (PST) 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; bh=ecliB25BkDl7EtZQbZOa7FY8xOJRTZHDugkajt346ps=; b=cM7DPz1e0wcHHZ9QaAHOeggqlWF/cZuUV42BMeczFGC5+e84TsMwJcw4tXIl9ns1kj L3aAJtygMKOM2wVxvo93uEq6Fq9MeJNcdCARhMQp07zoZWEUzyWQmFRYvwxCzYwdoIa5 hF99N00s0iugtQkoBh2oOzmi8Cxat6/gWampLmDqBbroEZ3xhfh821B8RrNdVKAXhQeN H4J3B9Fx3xM2Z6i33jMTg1ASNtqDImExfHmlvwmkA5Bl6stHTYPqbNbh6/Ljl7bc6eGw 0P4FMYYhaWdbfQXnOPACLDi/hZ6f1HwIqVjQnQDcLPniqeguWX/PXe+bpR18XIwprUGj q5wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ecliB25BkDl7EtZQbZOa7FY8xOJRTZHDugkajt346ps=; b=EcmUWbzuht9ajSacFRHT5TM5Td92oA5CuCTa6+cQXz3+Ah1pgbaTflxG39/NKKPbf4 mAdA42SEWptd7BrzyWgnUDWz9JfuCqxnAK459nZKGAoCWTDqibhWWLFRaPjkRRILUCWa BfuwsvLwBk0U/HBJGY0KAfe6Fd6U6oCa0BDLr++KnsUSBRx/F1kKP3nJNt/sxNauvHhM iFZnFgdPpWbBXfLffTmiD3DmNmzXKCA7TUmijkEwwdKzEq+UIeWkaUesz/rYh3EV4dud GS0kEl45wAp29LyeFn5BgKy9gacOTcb7l00JGeH+Dc8MhUO+453h5zWm+zd5Gu0I0rsT i+SA== X-Gm-Message-State: AOAM5305+ikTPXdXNZPgjYBXAU506JAmxZkctcL9VjFXn5+owbLvMZBL u6lMNquBE99nCg5FTwYbjVUFag== X-Google-Smtp-Source: ABdhPJwbVyhyvERj8OwNjWetMWm4OEdK1qiCddorl/OduN1GwtyyVG7K2q3FLuwAnoRMsCCBqd5ajw== X-Received: by 2002:a05:600c:410d:: with SMTP id j13mr3196810wmi.95.1607525761755; Wed, 09 Dec 2020 06:56:01 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:490:8730:c728:53f6:5e7e:2f63]) by smtp.gmail.com with ESMTPSA id i11sm3782219wrm.1.2020.12.09.06.56.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Dec 2020 06:56:01 -0800 (PST) From: Loic Poulain To: kuba@kernel.org Cc: manivannan.sadhasivam@linaro.org, linux-arm-msm@vger.kernel.org, netdev@vger.kernel.org, davem@davemloft.net, Loic Poulain Subject: [PATCH 2/3] net: mhi: Get RX queue size from MHI core Date: Wed, 9 Dec 2020 16:03:02 +0100 Message-Id: <1607526183-25652-2-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1607526183-25652-1-git-send-email-loic.poulain@linaro.org> References: <1607526183-25652-1-git-send-email-loic.poulain@linaro.org> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The RX queue size can be determined at runtime by retrieveing the number of available transfer descriptors Signed-off-by: Loic Poulain --- drivers/net/mhi_net.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/mhi_net.c b/drivers/net/mhi_net.c index 8e72d94..0333e07 100644 --- a/drivers/net/mhi_net.c +++ b/drivers/net/mhi_net.c @@ -256,9 +256,6 @@ static int mhi_net_probe(struct mhi_device *mhi_dev, mhi_netdev->mdev = mhi_dev; SET_NETDEV_DEV(ndev, &mhi_dev->dev); - /* All MHI net channels have 128 ring elements (at least for now) */ - mhi_netdev->rx_queue_sz = 128; - INIT_DELAYED_WORK(&mhi_netdev->rx_refill, mhi_net_rx_refill_work); u64_stats_init(&mhi_netdev->stats.rx_syncp); u64_stats_init(&mhi_netdev->stats.tx_syncp); @@ -268,6 +265,9 @@ static int mhi_net_probe(struct mhi_device *mhi_dev, if (err) goto out_err; + /* Number of transfer descriptors determines size of the queue */ + mhi_netdev->rx_queue_sz = mhi_get_free_desc_count(mhi_dev, DMA_FROM_DEVICE); + err = register_netdev(ndev); if (err) goto out_err; From patchwork Wed Dec 9 15:03:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 11961727 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00D7FC433FE for ; Wed, 9 Dec 2020 14:57:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C064323A33 for ; Wed, 9 Dec 2020 14:57:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387411AbgLIO5W (ORCPT ); Wed, 9 Dec 2020 09:57:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732445AbgLIO5V (ORCPT ); Wed, 9 Dec 2020 09:57:21 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0231C0617A6 for ; Wed, 9 Dec 2020 06:56:04 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id y23so1973441wmi.1 for ; Wed, 09 Dec 2020 06:56:04 -0800 (PST) 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; bh=BGfO0Eswp9lnQgcF2ohJFOorqCfHltMpUAVxKVdPxlo=; b=im9mHqn8LdwMxu6IhAbVxZnVNQ+4/qD1xBFo0uH8GNlSEQhzz8/sr9yYNG/Eb5lpbK wtvOVV5KnB3H+X70nu7LEY7+VJ2T9A/Ysmd+HoUlIvRO2pMKCsynqSjjiy7P+M33MhaS QP66LBsuAWbkuRO33O0sl+12fTzxPvoMgtMFIBqxlv0+OUHsvrHEaNwgeZheq0WLCGuZ 5hAQO12tYu8H32zQ0ys1atozuIztG7feqejrNncZa72cAZb+M1Zxunv7FXVfZ6NRBd0S 3xjvf9jyjKrz74badLuubGWcuqRPyEqTsCJr7yMRXe9NcbpYqL2iQT0DO5wTqZuABDNM YgZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BGfO0Eswp9lnQgcF2ohJFOorqCfHltMpUAVxKVdPxlo=; b=ehfhmMx0g7ff0Pzu+BHh59bXVZ7PXbGdscy1MRRxOy0LdIMYxVyFlpfRQK8/xmK7m7 TEeh8mHVheD7VWWswnFCuftP2FvHEl49DbSdtZL0oOZXzMlkmPoQh/WDhVeUdi3X9hu+ 5in5C4VQTiLDopmCV5doytX0/rOF/BXjeah/QnCFUk8O4i8aEqfvoDrtQpxPA02Cfvjl 1hXjrH5eLNhTV/g3XK98G7/HYEzQjfWlWj0puS48sS+LuA2U2lAaAIJ585y7dMtbfzMq cYYqPx/LmnR+ghD/rotSc9KVnt5e3C5YZAxKxnWLJKQqmPRRb/2+N5cFV1BbjvLz7Zn0 LKSg== X-Gm-Message-State: AOAM530oXL1O4B141URcs3xB+eNJ6UnEC/uSKO/qax0LLa9PULv67zRr cvp9NrKfApOXO4S4HsjpSSwJjg== X-Google-Smtp-Source: ABdhPJyPltzQtqNtstQ8+RvYR+AVwDF3My4GECRIoAhYYMNCmIAbhke7jNJnFYU8qIYzRut6/4QlIw== X-Received: by 2002:a1c:7318:: with SMTP id d24mr3263440wmb.39.1607525763428; Wed, 09 Dec 2020 06:56:03 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:490:8730:c728:53f6:5e7e:2f63]) by smtp.gmail.com with ESMTPSA id i11sm3782219wrm.1.2020.12.09.06.56.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Dec 2020 06:56:03 -0800 (PST) From: Loic Poulain To: kuba@kernel.org Cc: manivannan.sadhasivam@linaro.org, linux-arm-msm@vger.kernel.org, netdev@vger.kernel.org, davem@davemloft.net, Loic Poulain Subject: [PATCH 3/3] net: mhi: Add dedicated alloc thread Date: Wed, 9 Dec 2020 16:03:03 +0100 Message-Id: <1607526183-25652-3-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1607526183-25652-1-git-send-email-loic.poulain@linaro.org> References: <1607526183-25652-1-git-send-email-loic.poulain@linaro.org> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The buffer allocation for RX path is currently done by a work executed in the system workqueue. The work to do is quite simple and consists mostly in allocating and queueing as much as possible buffers to the MHI RX channel. It appears that using a dedicated kthread would be more appropriate to prevent 1. RX allocation latency introduced by the system queue 2. Unbounded work execution, the work only returning when queue is full, it can possibly monopolise the workqueue thread on slower systems. This patch replaces the system work with a simple kthread that loops on buffer allocation and sleeps when queue is full. Moreover it gets rid of the local rx_queued variable (to track buffer count), and instead, relies on the new mhi_get_free_desc_count helper. After pratical testing on a x86_64 machine, this change improves - Peek throughput (slightly, by few mbps) - Throughput stability when concurrent loads are running (stress) - CPU usage, less CPU cycles dedicated to the task Below is the powertop output for RX allocation task before and after this change, when performing UDP download at 6Gbps. Mostly to highlight the improvement in term of CPU usage. older (system workqueue): Usage Events/s Category Description 63,2 ms/s 134,0 kWork mhi_net_rx_refill_work 62,8 ms/s 134,3 kWork mhi_net_rx_refill_work 60,8 ms/s 141,4 kWork mhi_net_rx_refill_work newer (dedicated kthread): Usage Events/s Category Description 20,7 ms/s 155,6 Process [PID 3360] [mhi-net-rx] 22,2 ms/s 169,6 Process [PID 3360] [mhi-net-rx] 22,3 ms/s 150,2 Process [PID 3360] [mhi-net-rx] Signed-off-by: Loic Poulain --- drivers/net/mhi_net.c | 98 ++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/drivers/net/mhi_net.c b/drivers/net/mhi_net.c index 0333e07..eef40f5 100644 --- a/drivers/net/mhi_net.c +++ b/drivers/net/mhi_net.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -25,7 +26,6 @@ struct mhi_net_stats { u64_stats_t tx_bytes; u64_stats_t tx_errors; u64_stats_t tx_dropped; - atomic_t rx_queued; struct u64_stats_sync tx_syncp; struct u64_stats_sync rx_syncp; }; @@ -33,17 +33,59 @@ struct mhi_net_stats { struct mhi_net_dev { struct mhi_device *mdev; struct net_device *ndev; - struct delayed_work rx_refill; + struct task_struct *refill_task; + wait_queue_head_t refill_wq; struct mhi_net_stats stats; u32 rx_queue_sz; }; +static int mhi_net_refill_thread(void *data) +{ + struct mhi_net_dev *mhi_netdev = data; + struct net_device *ndev = mhi_netdev->ndev; + struct mhi_device *mdev = mhi_netdev->mdev; + int size = READ_ONCE(ndev->mtu); + struct sk_buff *skb; + int err; + + while (1) { + err = wait_event_interruptible(mhi_netdev->refill_wq, + !mhi_queue_is_full(mdev, DMA_FROM_DEVICE) + || kthread_should_stop()); + if (err || kthread_should_stop()) + break; + + skb = netdev_alloc_skb(ndev, size); + if (unlikely(!skb)) { + /* No memory, retry later */ + schedule_timeout_interruptible(msecs_to_jiffies(250)); + continue; + } + + err = mhi_queue_skb(mdev, DMA_FROM_DEVICE, skb, size, MHI_EOT); + if (unlikely(err)) { + net_err_ratelimited("%s: Failed to queue RX buf (%d)\n", + ndev->name, err); + kfree_skb(skb); + break; + } + + /* Do not hog the CPU */ + cond_resched(); + } + + return 0; +} + static int mhi_ndo_open(struct net_device *ndev) { struct mhi_net_dev *mhi_netdev = netdev_priv(ndev); - /* Feed the rx buffer pool */ - schedule_delayed_work(&mhi_netdev->rx_refill, 0); + mhi_netdev->refill_task = kthread_run(mhi_net_refill_thread, mhi_netdev, + "mhi-net-rx"); + if (IS_ERR(mhi_netdev->refill_task)) { + return PTR_ERR(mhi_netdev->refill_task); + } /* Carrier is established via out-of-band channel (e.g. qmi) */ netif_carrier_on(ndev); @@ -57,9 +99,9 @@ static int mhi_ndo_stop(struct net_device *ndev) { struct mhi_net_dev *mhi_netdev = netdev_priv(ndev); + kthread_stop(mhi_netdev->refill_task); netif_stop_queue(ndev); netif_carrier_off(ndev); - cancel_delayed_work_sync(&mhi_netdev->rx_refill); return 0; } @@ -138,9 +180,6 @@ static void mhi_net_dl_callback(struct mhi_device *mhi_dev, { struct mhi_net_dev *mhi_netdev = dev_get_drvdata(&mhi_dev->dev); struct sk_buff *skb = mhi_res->buf_addr; - int remaining; - - remaining = atomic_dec_return(&mhi_netdev->stats.rx_queued); if (unlikely(mhi_res->transaction_status)) { dev_kfree_skb_any(skb); @@ -163,9 +202,8 @@ static void mhi_net_dl_callback(struct mhi_device *mhi_dev, netif_rx(skb); } - /* Refill if RX buffers queue becomes low */ - if (remaining <= mhi_netdev->rx_queue_sz / 2) - schedule_delayed_work(&mhi_netdev->rx_refill, 0); + if (mhi_get_free_desc_count(mhi_dev, DMA_FROM_DEVICE) >= mhi_netdev->rx_queue_sz / 3) + wake_up_interruptible(&mhi_netdev->refill_wq); } static void mhi_net_ul_callback(struct mhi_device *mhi_dev, @@ -200,42 +238,6 @@ static void mhi_net_ul_callback(struct mhi_device *mhi_dev, netif_wake_queue(ndev); } -static void mhi_net_rx_refill_work(struct work_struct *work) -{ - struct mhi_net_dev *mhi_netdev = container_of(work, struct mhi_net_dev, - rx_refill.work); - struct net_device *ndev = mhi_netdev->ndev; - struct mhi_device *mdev = mhi_netdev->mdev; - int size = READ_ONCE(ndev->mtu); - struct sk_buff *skb; - int err; - - while (atomic_read(&mhi_netdev->stats.rx_queued) < mhi_netdev->rx_queue_sz) { - skb = netdev_alloc_skb(ndev, size); - if (unlikely(!skb)) - break; - - err = mhi_queue_skb(mdev, DMA_FROM_DEVICE, skb, size, MHI_EOT); - if (unlikely(err)) { - net_err_ratelimited("%s: Failed to queue RX buf (%d)\n", - ndev->name, err); - kfree_skb(skb); - break; - } - - atomic_inc(&mhi_netdev->stats.rx_queued); - - /* Do not hog the CPU if rx buffers are consumed faster than - * queued (unlikely). - */ - cond_resched(); - } - - /* If we're still starved of rx buffers, reschedule later */ - if (unlikely(!atomic_read(&mhi_netdev->stats.rx_queued))) - schedule_delayed_work(&mhi_netdev->rx_refill, HZ / 2); -} - static int mhi_net_probe(struct mhi_device *mhi_dev, const struct mhi_device_id *id) { @@ -256,7 +258,7 @@ static int mhi_net_probe(struct mhi_device *mhi_dev, mhi_netdev->mdev = mhi_dev; SET_NETDEV_DEV(ndev, &mhi_dev->dev); - INIT_DELAYED_WORK(&mhi_netdev->rx_refill, mhi_net_rx_refill_work); + init_waitqueue_head(&mhi_netdev->refill_wq); u64_stats_init(&mhi_netdev->stats.rx_syncp); u64_stats_init(&mhi_netdev->stats.tx_syncp);