Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp178958pxb; Thu, 12 Aug 2021 13:44:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8LenLY/+hPUpXuxbIYHxRzzzhZAU6Kr9pFgNWbyKZiS1ELUedSwfTs13EAkyl3Zy6T3si X-Received: by 2002:a17:907:20e7:: with SMTP id rh7mr5541716ejb.390.1628801061074; Thu, 12 Aug 2021 13:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628801061; cv=none; d=google.com; s=arc-20160816; b=A20cgmWQUkXE7Z2r3uMk2seIdPUP/cCsiwNkiCDrq4kJO++3vt5sBc+TxrYBw+D0ik v1CtVrKh3inR6HWh9NB+ZVYOnYuFZpFiZ5puMJRYAG9M2ZjsRrCQeEDaYRkbNIsyqnjI vtFgTE2I1eRmpArxgteUBEvm4IGzyWkr4dAR7N5BerGcVNPPa3n3DS/AQPCOWAyw4f9O +DIO9KfZYeBz5OYjPORC7gWztxngaOUG+NmmFzhln+pHuKRFBqKE5mKeONIi8Oq76iN4 eATNGVYBjAmHsB1/xXIdnKSJSN+RABMth4Uf6TzXZ99iepfNR2di+4ASVvY0AQ+7hTz7 MSrA== 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=64xPgsftRVJbwugHrzB1UvjPqduhCUZZEB/J6cFDx2k=; b=h+4zpGg057RtNKwmc5umDiG8N7MpuTQihq8yv+WN6aPdEy3ktwrm9T8cE57W4bha57 Xpds4w0XVfvpej3vSDoHEc5fyBQi9Wu5VMGj7/Yb8q9bTwxHkKknoXuNCR7nRDUC/PHw 4xS3ak8F5fP7H78FGTL+7aXLNYKWwC291k32np5e+AHdc5oRCA7RWgXOONqyZfKnxZCZ wmOMZyAPcBtfmLYMM8pJzmj9+cKnQvH+oD0hW9beEoXAKAy+Rx50WNo35BraZvdRzeBy w82e86ttpGLts8ls0GUmxJh9hD4TirHRwEMnkzYtETl9QgxNgUGoLyIoltk7S+pvC5tD YDrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eXzgkABu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a1si3614162edr.277.2021.08.12.13.43.35; Thu, 12 Aug 2021 13:44:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eXzgkABu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S237079AbhHLTv1 (ORCPT + 99 others); Thu, 12 Aug 2021 15:51:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236018AbhHLTvI (ORCPT ); Thu, 12 Aug 2021 15:51:08 -0400 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DB5EC0617AD for ; Thu, 12 Aug 2021 12:50:42 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id h1so9944528iol.9 for ; Thu, 12 Aug 2021 12:50:42 -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=64xPgsftRVJbwugHrzB1UvjPqduhCUZZEB/J6cFDx2k=; b=eXzgkABuTmzTk1yRQI2m382W8/rUC3gAINQz39akmYF6UzQyXUOLKk2Ss59hTyEcz0 eO1FGq5+C0LWlgOkXsiyXNfXu2f8Bb9pyUjPEWW/zoQ4MrGR6eDo/hNz254HNh46M6DW 1wM61mU+CDkotkqhXFPYyipwaZ9WrkjQ36pz3JdTHjrwo4LD6QfdMgs3I+TEGi6oHd9h CIEUFguydH1jEMEvVnzd6qbTE23m1X5sg17hYY9Gs4flbBAbNC8jjWxjsTZuewicL7z3 pjj5FPfrPMthcNdpHBcsAjyZq5Q5+WkgaWW8xJ/IMIYhzymPjdCc63XXs3UnWb2crd0E /f2g== 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:mime-version:content-transfer-encoding; bh=64xPgsftRVJbwugHrzB1UvjPqduhCUZZEB/J6cFDx2k=; b=BePKzRlFsEzvyDnp4hZ4PXr+7uJmxBF/Nn2O26dYsW4eiS+YZ6dvxAsahWoA1zmsKo wj0W6A8jvkMt1dScsZmcXifmxNewNI+doUHBxq/I1928YHLlgoooK59FBWSUOKnzB1/K 9ceyMe/cP1Z6K/wauMrsL68RcKcK8eY8xeBcQR1lf+MsO+/4XH3kCguoeDvD++rQ4RHe pwrb1ZJNOHYyiYG9FSaQt/8rBC8Zopqv5k7FJ9Afhyc5fHHgFTGvcP4Ff3oYIzF/2i0F 1jwRIXC3iC9Nhk31wB1oNkiE/2F+2BRsyeKt8VRo9sQx1zibvYkDXI8t3ac4iODGC+p/ mjlQ== X-Gm-Message-State: AOAM533qwC/h43mLdsV+XlJYyCGZMDtKQl1ZnOjhIcofYaBsNv7EbcCK jx9YR7356Qg4PEtSFqcRM5h9CA== X-Received: by 2002:a5e:d91a:: with SMTP id n26mr4169992iop.96.1628797841987; Thu, 12 Aug 2021 12:50:41 -0700 (PDT) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id s16sm2058821iln.5.2021.08.12.12.50.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Aug 2021 12:50:41 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, subashab@codeaurora.org, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 4/6] net: ipa: ensure hardware has power in ipa_start_xmit() Date: Thu, 12 Aug 2021 14:50:33 -0500 Message-Id: <20210812195035.2816276-5-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210812195035.2816276-1-elder@linaro.org> References: <20210812195035.2816276-1-elder@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We need to ensure the hardware is powered when we transmit a packet. But if it's not, we can't block to wait for it. So asynchronously request power in ipa_start_xmit(), and only proceed if the return value indicates the power state is active. If the hardware is not active, a runtime resume request will have been initiated. In that case, stop the network stack from further transmit attempts until the resume completes. Return NETDEV_TX_BUSY, to retry sending the packet once the queue is restarted. If the power request returns an error (other than -EINPROGRESS, which just means a resume requested elsewhere isn't complete), just drop the packet. Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_modem.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/net/ipa/ipa_modem.c b/drivers/net/ipa/ipa_modem.c index 0a3b034614b61..aa1b483d9f7db 100644 --- a/drivers/net/ipa/ipa_modem.c +++ b/drivers/net/ipa/ipa_modem.c @@ -106,6 +106,7 @@ static int ipa_start_xmit(struct sk_buff *skb, struct net_device *netdev) struct ipa_endpoint *endpoint; struct ipa *ipa = priv->ipa; u32 skb_len = skb->len; + struct device *dev; int ret; if (!skb_len) @@ -115,7 +116,31 @@ static int ipa_start_xmit(struct sk_buff *skb, struct net_device *netdev) if (endpoint->data->qmap && skb->protocol != htons(ETH_P_MAP)) goto err_drop_skb; + /* The hardware must be powered for us to transmit */ + dev = &ipa->pdev->dev; + ret = pm_runtime_get(dev); + if (ret < 1) { + /* If a resume won't happen, just drop the packet */ + if (ret < 0 && ret != -EINPROGRESS) { + pm_runtime_put_noidle(dev); + goto err_drop_skb; + } + + /* No power (yet). Stop the network stack from transmitting + * until we're resumed; ipa_modem_resume() arranges for the + * TX queue to be started again. + */ + netif_stop_queue(netdev); + + (void)pm_runtime_put(dev); + + return NETDEV_TX_BUSY; + } + ret = ipa_endpoint_skb_tx(endpoint, skb); + + (void)pm_runtime_put(dev); + if (ret) { if (ret != -E2BIG) return NETDEV_TX_BUSY; @@ -201,7 +226,10 @@ void ipa_modem_suspend(struct net_device *netdev) * * Re-enable transmit on the modem network device. This is called * in (power management) work queue context, scheduled when resuming - * the modem. + * the modem. We can't enable the queue directly in ipa_modem_resume() + * because transmits restart the instant the queue is awakened; but the + * device power state won't be ACTIVE until *after* ipa_modem_resume() + * returns. */ static void ipa_modem_wake_queue_work(struct work_struct *work) { -- 2.27.0