From patchwork Thu Sep 17 17:39:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 313136 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp647197ilg; Thu, 17 Sep 2020 10:58:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcuUfnRKn3+q862JL3ZrEc2WWSQHsHXmwZSJkQ1nHTfrzTyHE3snOhEdL5PFplRQY7FPLD X-Received: by 2002:a17:906:275b:: with SMTP id a27mr33386552ejd.190.1600365523060; Thu, 17 Sep 2020 10:58:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600365523; cv=none; d=google.com; s=arc-20160816; b=v66WKYYLa50BqfIIrRYDD4zCE9qhT5hwQ/N1JvwjmJT/JRTsRds2BLGYYJz2Qrc4SX KAyUdqKel4UfcKKgCrz87BayFLcF0KTfo6lxFyQ3+ii38lfT9WvepdaqdLMhaK9huhDW 6Ue8uduI+0wSjoqt9eODfJ72zNOYaZiO1KalQarKfldaPkgThTrI4bZWffzV+leGtVqX TwDMDGynRpTrGD4bANLNzxVxai4FmyxYIM732J0TP4XAYtM6AqJYmK4K0ssIEaxkv37b TuCP6XG1e0ao6g6ZsWrBRucqUXKxHAkey4l8BAuxcOmAyWF9E1Us7MmskaUHyuRagagQ jZaw== 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=rTpW3FNcBGaT4VwfmVMgzfLSYM7ObfFzlWr4lD0H81Y=; b=D4guV0BPePYLN4Fbs0uIZK4sZ8yE2e3ititTJYwoQBFI2uMNaC6M7TBiPeVHTTMb8+ HkimJfYub4jmev9/rU/Gs2wcNfCW+Vm6P3jHnSlAp5y3uhJ6ifHafC+pSNtdbGQydFbD eV6V8BSNTSpP6jHFefvP5qcEuilC9PHC+oVqKEVMkgjNpKIL4Ftpx5R+a1gwtD0iK8l1 6/sPa7H+3Gc1mMlhF8kIPHIZ9ky7PTK6h/RwuqWarMOR0eCZKMu+LvB3saAHlxsRjC2+ +DDSR89Pe95StGtYEWutO7CLudWBS0vTt6JarG2Q59nzWvhxcSxdBBfexOpVL3sBC4e8 JcTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QlhMnJ4R; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-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 da18si276826edb.466.2020.09.17.10.58.42; Thu, 17 Sep 2020 10:58:43 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-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=QlhMnJ4R; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-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 S1726634AbgIQR6j (ORCPT + 8 others); Thu, 17 Sep 2020 13:58:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726557AbgIQRjl (ORCPT ); Thu, 17 Sep 2020 13:39:41 -0400 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6DC1C0612F2 for ; Thu, 17 Sep 2020 10:39:35 -0700 (PDT) Received: by mail-io1-xd43.google.com with SMTP id b6so3128438iof.6 for ; Thu, 17 Sep 2020 10:39:35 -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=rTpW3FNcBGaT4VwfmVMgzfLSYM7ObfFzlWr4lD0H81Y=; b=QlhMnJ4RWiyKxprNM4XBp9qS7dGEy7oolZwAPHOSewO4Rq9qLs8XsRARWl1gqte78Y LzV0pDl/qub20uTH0brcbvS2e36lStDuYI5IvZmc5uIKMMOLCX1UXhNh/HrWvQAv7Xgc rY+X4dB493DYPdFpY0u6WMPeogFqMUDbVOxuKXs6jEosh7MH+qTVwoeBV3AIOhxisJyX OvwBko98YQRgrAK0OZWhSO0jE8yaZ4QsiH0UR/1qtuBIngVQixXhIiOM+8wgacPOLtt5 hgavctH+HrKhakOrcfbaIW7pn8BaXHyujRsUJvxX99hFHCI5WBfXleQE052CYmc4bz9F 2XTg== 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=rTpW3FNcBGaT4VwfmVMgzfLSYM7ObfFzlWr4lD0H81Y=; b=nTqxzKWxaBaIKLD2tiKscNWGSWUmafTVqm3EpGjKumyqL79pIJeGsL1oBxvREVzLAv MQt/dHD/DHF/E0/RR/kq/dkMyJQAbToIL5Pbl3P/UuCoH8/i7teDghK+v4QrHiN9UgAt ka1dIcswfzVEI3BQo8vhpP8TAcRM+SPUeXvw8GrGZlTgrZlKalTNW0F6in5/P6/EPaIg YOzyfujWbsSr7GnpbXcxqjrjemm3ltW5n+bbb30QGKoIHiGCYwlI96QJipX3DJzALWY5 U/o/pHVLJZCIi0u+r3V2SF7inAhHl39NRpjUvxRLFzhhokC1cO2JwSkgqkvOoywUA5aM T/FA== X-Gm-Message-State: AOAM532PVXAK0/IkvF+0qYmSYpPkb3aJHs7ikf1fLiJBv4meZw+cj3Iz gUX19i5UX3CWei2N5JG5eti/BQ== X-Received: by 2002:a6b:b846:: with SMTP id i67mr24671016iof.103.1600364375115; Thu, 17 Sep 2020 10:39:35 -0700 (PDT) Received: from beast.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id l6sm192725ilt.34.2020.09.17.10.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 10:39:34 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: evgreen@chromium.org, subashab@codeaurora.org, cpratapa@codeaurora.org, bjorn.andersson@linaro.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 4/7] net: ipa: use device_init_wakeup() Date: Thu, 17 Sep 2020 12:39:23 -0500 Message-Id: <20200917173926.24266-5-elder@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200917173926.24266-1-elder@linaro.org> References: <20200917173926.24266-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The call to wakeup_source_register() in ipa_probe() does not do what it was intended to do. Call device_init_wakeup() in ipa_setup() instead, to set the IPA device as wakeup-capable and to initially enable wakeup capability. When we receive a SUSPEND interrupt, call pm_wakeup_dev_event() with a zero processing time, to simply call for a resume without any other processing. The ipa_resume() call will take care of waking things up again, and will handle receiving the packet. Note that this gets rid of a clock reference counting bug that occurred when handling an IPA SUSPEND interrupt. Specifically, ipa_suspend_handler() took an IPA clock reference *in addition* to the one taken by ipa_resume(). There is no need to back-port this fix however, because it only affects code that was not previously working (this patch is part of fixing that). Signed-off-by: Alex Elder Reviewed-by: Bjorn Andersson --- v3: Added Bjorn's reviewed-by tag. drivers/net/ipa/ipa.h | 2 -- drivers/net/ipa/ipa_main.c | 42 ++++++++++++++++---------------------- 2 files changed, 18 insertions(+), 26 deletions(-) -- 2.20.1 diff --git a/drivers/net/ipa/ipa.h b/drivers/net/ipa/ipa.h index e02fe979b645b..c688155ccf375 100644 --- a/drivers/net/ipa/ipa.h +++ b/drivers/net/ipa/ipa.h @@ -114,8 +114,6 @@ struct ipa { void *zero_virt; size_t zero_size; - struct wakeup_source *wakeup_source; - /* Bit masks indicating endpoint state */ u32 available; /* supported by hardware */ u32 filter_map; diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c index 4d5394bcfe47e..4e2508bb1bf80 100644 --- a/drivers/net/ipa/ipa_main.c +++ b/drivers/net/ipa/ipa_main.c @@ -75,17 +75,19 @@ * @ipa: IPA pointer * @irq_id: IPA interrupt type (unused) * - * When in suspended state, the IPA can trigger a resume by sending a SUSPEND - * IPA interrupt. + * If an RX endpoint is in suspend state, and the IPA has a packet + * destined for that endpoint, the IPA generates a SUSPEND interrupt + * to inform the AP that it should resume the endpoint. If we get + * one of these interrupts we just resume everything. */ static void ipa_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id) { - /* Take a a single clock reference to prevent suspend. All - * endpoints will be resumed as a result. This reference will - * be dropped when we get a power management suspend request. + /* Just report the event, and let system resume handle the rest. + * More than one endpoint could signal this; if so, ignore + * all but the first. */ if (!test_and_set_bit(IPA_FLAG_CLOCK_HELD, ipa->flags)) - ipa_clock_get(ipa); + pm_wakeup_dev_event(&ipa->pdev->dev, 0, true); /* Acknowledge/clear the suspend interrupt on all endpoints */ ipa_interrupt_suspend_clear_all(ipa->interrupt); @@ -106,6 +108,7 @@ int ipa_setup(struct ipa *ipa) { struct ipa_endpoint *exception_endpoint; struct ipa_endpoint *command_endpoint; + struct device *dev = &ipa->pdev->dev; int ret; /* Setup for IPA v3.5.1 has some slight differences */ @@ -123,6 +126,10 @@ int ipa_setup(struct ipa *ipa) ipa_uc_setup(ipa); + ret = device_init_wakeup(dev, true); + if (ret) + goto err_uc_teardown; + ipa_endpoint_setup(ipa); /* We need to use the AP command TX endpoint to perform other @@ -158,7 +165,7 @@ int ipa_setup(struct ipa *ipa) ipa->setup_complete = true; - dev_info(&ipa->pdev->dev, "IPA driver setup completed successfully\n"); + dev_info(dev, "IPA driver setup completed successfully\n"); return 0; @@ -173,6 +180,8 @@ int ipa_setup(struct ipa *ipa) ipa_endpoint_disable_one(command_endpoint); err_endpoint_teardown: ipa_endpoint_teardown(ipa); + (void)device_init_wakeup(dev, false); +err_uc_teardown: ipa_uc_teardown(ipa); ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_TX_SUSPEND); ipa_interrupt_teardown(ipa->interrupt); @@ -200,6 +209,7 @@ static void ipa_teardown(struct ipa *ipa) command_endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX]; ipa_endpoint_disable_one(command_endpoint); ipa_endpoint_teardown(ipa); + (void)device_init_wakeup(&ipa->pdev->dev, false); ipa_uc_teardown(ipa); ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_TX_SUSPEND); ipa_interrupt_teardown(ipa->interrupt); @@ -709,7 +719,6 @@ static void ipa_validate_build(void) */ static int ipa_probe(struct platform_device *pdev) { - struct wakeup_source *wakeup_source; struct device *dev = &pdev->dev; const struct ipa_data *data; struct ipa_clock *clock; @@ -758,19 +767,11 @@ static int ipa_probe(struct platform_device *pdev) goto err_clock_exit; } - /* Create a wakeup source. */ - wakeup_source = wakeup_source_register(dev, "ipa"); - if (!wakeup_source) { - /* The most likely reason for failure is memory exhaustion */ - ret = -ENOMEM; - goto err_clock_exit; - } - /* Allocate and initialize the IPA structure */ ipa = kzalloc(sizeof(*ipa), GFP_KERNEL); if (!ipa) { ret = -ENOMEM; - goto err_wakeup_source_unregister; + goto err_clock_exit; } ipa->pdev = pdev; @@ -778,7 +779,6 @@ static int ipa_probe(struct platform_device *pdev) ipa->modem_rproc = rproc; ipa->clock = clock; __clear_bit(IPA_FLAG_CLOCK_HELD, ipa->flags); - ipa->wakeup_source = wakeup_source; ipa->version = data->version; ret = ipa_reg_init(ipa); @@ -857,8 +857,6 @@ static int ipa_probe(struct platform_device *pdev) ipa_reg_exit(ipa); err_kfree_ipa: kfree(ipa); -err_wakeup_source_unregister: - wakeup_source_unregister(wakeup_source); err_clock_exit: ipa_clock_exit(clock); err_rproc_put: @@ -872,11 +870,8 @@ static int ipa_remove(struct platform_device *pdev) struct ipa *ipa = dev_get_drvdata(&pdev->dev); struct rproc *rproc = ipa->modem_rproc; struct ipa_clock *clock = ipa->clock; - struct wakeup_source *wakeup_source; int ret; - wakeup_source = ipa->wakeup_source; - if (ipa->setup_complete) { ret = ipa_modem_stop(ipa); if (ret) @@ -893,7 +888,6 @@ static int ipa_remove(struct platform_device *pdev) ipa_mem_exit(ipa); ipa_reg_exit(ipa); kfree(ipa); - wakeup_source_unregister(wakeup_source); ipa_clock_exit(clock); rproc_put(rproc);