Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp191679rdb; Thu, 19 Oct 2023 01:09:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdRx6IfmAwabYvUFiVPejVYLAHpmv8H3nmRs/MQ1SrEuB/blfpdl9KcDJndGlXuW1d7Gr0 X-Received: by 2002:a17:90b:268c:b0:27d:7ebe:2e8 with SMTP id pl12-20020a17090b268c00b0027d7ebe02e8mr1465062pjb.9.1697702978115; Thu, 19 Oct 2023 01:09:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697702978; cv=none; d=google.com; s=arc-20160816; b=FhrVDLu9G7jHKMFx7OwxGV8UvEw6mKChOimKotGMK0eLHB7znG2EhkyBSg9znmJ329 g2FBy0Q047XfC4H24Zz10xqfCutLtHVjmGUGeVDTDBFXq4wh0oWpFB86uY05g0D5sDiB LPJxlUY3UusMg970uROAUQa3BpUcXrkx4smRHwpbD0WgAKP7Mxlrqw2l8DOKC1cP7kVG Xv7yZkiEzed8vY87bAa4Dp9MsAYCjksKFJYlRaUCSs1SLT9sEGB3zVTgpjBdIp2/AYKO j6S8JrabS6oBORZfUohRu4Qmy4VVovC/hu0XjxPTo3Ty5lWdDDzjep0C7CGdgzsogv1x OShA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=g17DNvDuwsvkatPfQSbF1sKHfBdyAlQw+IX3K/EwR5U=; fh=fmwyZ/UGY9CEzZmnR5aMlOkX2uEg+eeTmSL28uucaXM=; b=MBiVAjsd9MSuTK357YXnNxP2qWG7Zjkrqjd5FUa9qLNLWPC2bzG8X6udk0AGnXEzOY wsTW+aQKgrVCHugTNewNreg2bKRG2M39/6TGPBDXZj1f+sZene8L63K6Rk27ybtGFOfp 6UZ4vapObGw2eKox2G/6WSSyOWrGEBJfNAolUfzB0v/rdSH8sP0DMGZXfsK3TGdBOoxD dRqyOsROockIdb+4zpPrRs7FzE/VCZC1g1psuM79lUiZQ4Dm20Gui+tN0ZEVGGz+qp1o SnZl7RSVt1Cpgt9XJ0sjOeYW7rU+VkBv1qAbGRMIwAuQoESnhaXF4sYKM+9Tlj10Ac/5 66rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PK/5iYDh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id bf7-20020a656d07000000b005ab1fd6fbc1si4132804pgb.847.2023.10.19.01.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 01:09:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PK/5iYDh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4233E8135BF2; Thu, 19 Oct 2023 01:09:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232926AbjJSIJZ (ORCPT + 99 others); Thu, 19 Oct 2023 04:09:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232976AbjJSIJY (ORCPT ); Thu, 19 Oct 2023 04:09:24 -0400 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5A6812E for ; Thu, 19 Oct 2023 01:09:22 -0700 (PDT) Received: by mail-qt1-x832.google.com with SMTP id d75a77b69052e-41995d42c3bso46188671cf.1 for ; Thu, 19 Oct 2023 01:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697702962; x=1698307762; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=g17DNvDuwsvkatPfQSbF1sKHfBdyAlQw+IX3K/EwR5U=; b=PK/5iYDhgaAWconkr7GJg/THsBsGSORleaGjiqPczpqNfdxAQrchBLsjXo27kINYCQ NUFWvt1Ft2TFPENu5OPDbaU+CyE1e6NkrPYXxPk8uWANeeKWMFvMZ981RYF4ACEflVo8 M29sQF/8M4TixCudldiS5o1E3sD2ae/yG6OqMT9olwtIjSnTriBXfRsIgQbuY/UDCyEJ ZM5e/mkn+6sZxjhohXeqFwaQxZfki+a+TcFRbkDF8rSY+5XMB54tZbXRFCzhJGssgcWJ Gy+lABOl13ak5JGw6R6ykKhLz7rMSGUAurKXWiRQQHwiKAKka5m+rbdIKd8m1bogEqZ7 tuOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697702962; x=1698307762; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=g17DNvDuwsvkatPfQSbF1sKHfBdyAlQw+IX3K/EwR5U=; b=ZP1F//0Q7ZZ8zLn82uIoqE+wEtXYOWlbtsC3oRED7tkYmdBbHS4veSpVVsxt8fsxWb expXAI1nPheKBh09XQgmRSNNLKf8LSDokc/5mj5vYgL4SJjwTSGabPBxni5In/6eZEUl oTodTId68OrIP5hlOLCoUVjaqideuqWnsHLQycR+o2lZ/gwyeizImJUuvVmfTtYhokdf Muul1mtujuLTKltMWpcclsVb/8S+uuv2InwC2Awug51d3o6T9RKGmcyAuCPscIfCdbu8 YZwd0qxCokWP+4QUBAD+s9Sdtj+l9+f38cLoxAEPtB9CbpupYFfYO02p0xmwT5fsdTmH RtNQ== X-Gm-Message-State: AOJu0YwJksqBYKiTBGzHt/0dZ7VY5+MMOv62kFdJArGVfD3Yv6FljRJT 9kI3paFE0nfHgUIcoJhAb9tr X-Received: by 2002:a05:622a:83:b0:41b:8416:ea2a with SMTP id o3-20020a05622a008300b0041b8416ea2amr1895589qtw.40.1697702961759; Thu, 19 Oct 2023 01:09:21 -0700 (PDT) Received: from localhost.localdomain ([117.202.186.25]) by smtp.gmail.com with ESMTPSA id bq15-20020a05622a1c0f00b0041520676966sm573553qtb.47.2023.10.19.01.09.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 01:09:21 -0700 (PDT) From: Manivannan Sadhasivam To: mhi@lists.linux.dev Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH] bus: mhi: ep: Add support for interrupt moderation timer Date: Thu, 19 Oct 2023 13:39:11 +0530 Message-Id: <20231019080911.57938-1-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 01:09:35 -0700 (PDT) MHI spec defines the interrupt moderation timer feature using which the host can limit the number of interrupts being raised for an event ring by the device. This feature allows the host to process multiple event ring elements by a single IRQ from the device, thereby eliminating the need to process IRQ for each element. The INTMODT field in the event context array provides the value to be used for delaying the IRQ generation from device. This value, along with the Block Event Interrupt (BEI) flag of the TRE defines how IRQ is generated to the host. Support for interrupt moderation timer is implemented using delayed workqueue in kernel. And a separate delayed work item is used for each event ring. Signed-off-by: Manivannan Sadhasivam --- drivers/bus/mhi/ep/internal.h | 3 +++ drivers/bus/mhi/ep/main.c | 22 +++++++++++++++++++--- drivers/bus/mhi/ep/ring.c | 19 ++++++++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/drivers/bus/mhi/ep/internal.h b/drivers/bus/mhi/ep/internal.h index a2125fa5fe2f..8c5cf2b67951 100644 --- a/drivers/bus/mhi/ep/internal.h +++ b/drivers/bus/mhi/ep/internal.h @@ -126,6 +126,7 @@ struct mhi_ep_ring { union mhi_ep_ring_ctx *ring_ctx; struct mhi_ring_element *ring_cache; enum mhi_ep_ring_type type; + struct delayed_work intmodt_work; u64 rbase; size_t rd_offset; size_t wr_offset; @@ -135,7 +136,9 @@ struct mhi_ep_ring { u32 ch_id; u32 er_index; u32 irq_vector; + u32 intmodt; bool started; + bool irq_pending; }; struct mhi_ep_cmd { diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c index 834e7afadd64..78559a995b25 100644 --- a/drivers/bus/mhi/ep/main.c +++ b/drivers/bus/mhi/ep/main.c @@ -54,11 +54,27 @@ static int mhi_ep_send_event(struct mhi_ep_cntrl *mhi_cntrl, u32 ring_idx, mutex_unlock(&mhi_cntrl->event_lock); /* - * Raise IRQ to host only if the BEI flag is not set in TRE. Host might - * set this flag for interrupt moderation as per MHI protocol. + * As per the MHI specification, section 4.3, Interrupt moderation: + * + * 1. If BEI flag is not set, cancel any pending intmodt work if started + * for the event ring and raise IRQ immediately. + * + * 2. If both BEI and intmodt are set, and if no IRQ is pending for the + * same event ring, start the IRQ delayed work as per the value of + * intmodt. If previous IRQ is pending, then do nothing as the pending + * IRQ is enough for the host to process the current event ring element. + * + * 3. If BEI is set and intmodt is not set, no need to raise IRQ. */ - if (!bei) + if (!bei) { + if (READ_ONCE(ring->irq_pending)) + cancel_delayed_work(&ring->intmod_work); + mhi_cntrl->raise_irq(mhi_cntrl, ring->irq_vector); + } else if (ring->intmodt && !READ_ONCE(ring->irq_pending)) { + WRITE_ONCE(ring->irq_pending, true); + schedule_delayed_work(&ring->intmod_work, msecs_to_jiffies(ring->intmodt)); + } return 0; diff --git a/drivers/bus/mhi/ep/ring.c b/drivers/bus/mhi/ep/ring.c index 115518ec76a4..a1071c13761b 100644 --- a/drivers/bus/mhi/ep/ring.c +++ b/drivers/bus/mhi/ep/ring.c @@ -157,6 +157,15 @@ void mhi_ep_ring_init(struct mhi_ep_ring *ring, enum mhi_ep_ring_type type, u32 } } +static void mhi_ep_raise_irq(struct work_struct *work) +{ + struct mhi_ep_ring *ring = container_of(work, struct mhi_ep_ring, intmodt_work.work); + struct mhi_ep_cntrl *mhi_cntrl = ring->mhi_cntrl; + + mhi_cntrl->raise_irq(mhi_cntrl, ring->irq_vector); + WRITE_ONCE(ring->irq_pending, false); +} + int mhi_ep_ring_start(struct mhi_ep_cntrl *mhi_cntrl, struct mhi_ep_ring *ring, union mhi_ep_ring_ctx *ctx) { @@ -173,8 +182,13 @@ int mhi_ep_ring_start(struct mhi_ep_cntrl *mhi_cntrl, struct mhi_ep_ring *ring, if (ring->type == RING_TYPE_CH) ring->er_index = le32_to_cpu(ring->ring_ctx->ch.erindex); - if (ring->type == RING_TYPE_ER) + if (ring->type == RING_TYPE_ER) { ring->irq_vector = le32_to_cpu(ring->ring_ctx->ev.msivec); + ring->intmodt = FIELD_GET(EV_CTX_INTMODT_MASK, + le32_to_cpu(ring->ring_ctx->ev.intmod)); + + INIT_DELAYED_WORK(&ring->intmodt_work, mhi_ep_raise_irq); + } /* During ring init, both rp and wp are equal */ memcpy_fromio(&val, (void __iomem *) &ring->ring_ctx->generic.rp, sizeof(u64)); @@ -201,6 +215,9 @@ int mhi_ep_ring_start(struct mhi_ep_cntrl *mhi_cntrl, struct mhi_ep_ring *ring, void mhi_ep_ring_reset(struct mhi_ep_cntrl *mhi_cntrl, struct mhi_ep_ring *ring) { + if (ring->type == RING_TYPE_ER) + cancel_delayed_work_sync(&ring->intmodt_work); + ring->started = false; kfree(ring->ring_cache); ring->ring_cache = NULL; -- 2.25.1