From patchwork Tue Jun 5 06:16:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishanth Menon X-Patchwork-Id: 137690 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp565510lji; Mon, 4 Jun 2018 23:18:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIrVc6qoHdwGMY291oR7NdB2J19mUTse/ZW5cJ5hkzy/mgzjfTcxsMRyCijxfByDJhn+7W6 X-Received: by 2002:a63:6b43:: with SMTP id g64-v6mr19569855pgc.337.1528179503576; Mon, 04 Jun 2018 23:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528179503; cv=none; d=google.com; s=arc-20160816; b=Nm4E5VfU+n5suo51evUeZnNEQRB8h07Q3HuM6Dk13ZAV3tsUAhka+BL3obhbJeshzK DZaJYLSqhQfJwDRWUWx7VLR61fj9cCeZs/pU6fGCxmL78v5sgBi4iXjmewjRqCzJMRDP Xyzcgo4nZXxkoES94O1/AJS8C2FfwkWgUk0flafP2OpyKKHhsTsqdLCtuMxVa5Bn3kLc eFlt10VZdQQezNOppHPhTj54GvtZSUc8CgzD6rKHcQD1Z+3o6t34wRaE8Jt3pAWSvn8W OF8KAM5sLxc/wOiP8dfamAIOQ70Xq0PgEyjwmcGGe24oY5ZzQSBGvcl2ofmsBQgmOQ5b 8l0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=6WszYD0uZeaoPHg8EGkIRrPUJ8MLDymlbhq3u/DUshI=; b=PgWfyt6c8qgUthajyOmqZu9n9STodon4DhXi7X+8vUyk7NTsCucegJZ58u9CoFlssP srWSRoWLPPYnVrUlgb2r/fYFpqkgMet0e0Mb6lBLfej0QbLhg8NXWdaNR66PjxryZ9mR h1sys+C6pWK/xH7hWNm9IjFD8OwR4qe50psF6e+h5mDnrKFS5gObc0i6xiqkiMQ3m/Lj +FEZ76+16+RIM6+KPF0rScuhiiY7WY2VmH5rfrondlJECdrUiuS6G/uEvzM8ZiOnMEmE WQqdwbqsfLCXUBo+C07q79GBj4jkMyXOAeZOOvLPpCcDSkaw995ilsmbtSuyxctLHjf6 jciA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=U1LXF40p; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v32-v6si48058165plb.273.2018.06.04.23.18.23; Mon, 04 Jun 2018 23:18:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=U1LXF40p; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751884AbeFEGSV (ORCPT + 30 others); Tue, 5 Jun 2018 02:18:21 -0400 Received: from lelnx194.ext.ti.com ([198.47.27.80]:37249 "EHLO lelnx194.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751813AbeFEGQr (ORCPT ); Tue, 5 Jun 2018 02:16:47 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id w556GT6w001013; Tue, 5 Jun 2018 01:16:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1528179389; bh=6WszYD0uZeaoPHg8EGkIRrPUJ8MLDymlbhq3u/DUshI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=U1LXF40pUewwug/YUWXALKdd++0dMTGTfWthFobMIHhy6XIo7QwM9m/LGaqpJeFiE 8jek2D2jEklQrdTY27w+BMmhXGXUVJqqMhFP9/xp36GO6scOOblApeVmotN9d9iUKT 8Jm6AcYwk3/JH2lXQHfVs3m21afLpps5eyFLDBS8= Received: from DLEE102.ent.ti.com (dlee102.ent.ti.com [157.170.170.32]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w556GTbt015147; Tue, 5 Jun 2018 01:16:29 -0500 Received: from DLEE114.ent.ti.com (157.170.170.25) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Tue, 5 Jun 2018 01:16:29 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Tue, 5 Jun 2018 01:16:29 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w556GTiN024160; Tue, 5 Jun 2018 01:16:29 -0500 From: Nishanth Menon To: Jassi Brar , Rob Herring CC: , , , Nishanth Menon , Tero Kristo , Suman Anna Subject: [RFC PATCH 2/8] mailbox: ti-msgmgr: Allocate Rx channel resources only on request Date: Tue, 5 Jun 2018 01:16:23 -0500 Message-ID: <20180605061629.4759-3-nm@ti.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180605061629.4759-1-nm@ti.com> References: <20180605061629.4759-1-nm@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In a much bigger system SoCs, the number of Rx channels can be many and mostly unused based on the system of choice, and not all Rx channels need IRQs and allocating all memory at probe will be inefficient. Some SoCs could have total threads in the 100s and usage would be just 1 Rx thread. Thus, request and map the IRQs and allocate memory only when needed. Since these channels are requested by client drivers on need, our utilization will be optimal. Signed-off-by: Nishanth Menon --- drivers/mailbox/ti-msgmgr.c | 91 ++++++++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 30 deletions(-) -- 2.15.1 diff --git a/drivers/mailbox/ti-msgmgr.c b/drivers/mailbox/ti-msgmgr.c index 7cd5f9c9c97f..7221590c409c 100644 --- a/drivers/mailbox/ti-msgmgr.c +++ b/drivers/mailbox/ti-msgmgr.c @@ -310,6 +310,51 @@ static int ti_msgmgr_send_data(struct mbox_chan *chan, void *data) return 0; } +/** + * ti_msgmgr_queue_rx_irq_req() - RX IRQ request + * @dev: device pointer + * @qinst: Queue instance + * @chan: Channel pointer + */ +static int ti_msgmgr_queue_rx_irq_req(struct device *dev, + struct ti_queue_inst *qinst, + struct mbox_chan *chan) +{ + int ret = 0; + char of_rx_irq_name[7]; + struct device_node *np; + + snprintf(of_rx_irq_name, sizeof(of_rx_irq_name), + "rx_%03d", qinst->queue_id); + + /* Get the IRQ if not found */ + if (qinst->irq < 0) { + np = of_node_get(dev->of_node); + if (!np) + return -ENODATA; + qinst->irq = of_irq_get_byname(np, of_rx_irq_name); + of_node_put(np); + + if (qinst->irq < 0) { + dev_err(dev, + "QID %d PID %d:No IRQ[%s]: %d\n", + qinst->queue_id, qinst->proxy_id, + of_rx_irq_name, qinst->irq); + return qinst->irq; + } + } + + /* With the expectation that the IRQ might be shared in SoC */ + ret = request_irq(qinst->irq, ti_msgmgr_queue_rx_interrupt, + IRQF_SHARED, qinst->name, chan); + if (ret) { + dev_err(dev, "Unable to get IRQ %d on %s(res=%d)\n", + qinst->irq, qinst->name, ret); + } + + return ret; +} + /** * ti_msgmgr_queue_startup() - Startup queue * @chan: Channel pointer @@ -318,19 +363,21 @@ static int ti_msgmgr_send_data(struct mbox_chan *chan, void *data) */ static int ti_msgmgr_queue_startup(struct mbox_chan *chan) { - struct ti_queue_inst *qinst = chan->con_priv; struct device *dev = chan->mbox->dev; + struct ti_msgmgr_inst *inst = dev_get_drvdata(dev); + struct ti_queue_inst *qinst = chan->con_priv; + const struct ti_msgmgr_desc *d = inst->desc; int ret; if (!qinst->is_tx) { - /* - * With the expectation that the IRQ might be shared in SoC - */ - ret = request_irq(qinst->irq, ti_msgmgr_queue_rx_interrupt, - IRQF_SHARED, qinst->name, chan); + /* Allocate usage buffer for rx */ + qinst->rx_buff = kzalloc(d->max_message_size, GFP_KERNEL); + if (!qinst->rx_buff) + return -ENOMEM; + /* Request IRQ */ + ret = ti_msgmgr_queue_rx_irq_req(dev, qinst, chan); if (ret) { - dev_err(dev, "Unable to get IRQ %d on %s(res=%d)\n", - qinst->irq, qinst->name, ret); + kfree(qinst->rx_buff); return ret; } } @@ -346,8 +393,10 @@ static void ti_msgmgr_queue_shutdown(struct mbox_chan *chan) { struct ti_queue_inst *qinst = chan->con_priv; - if (!qinst->is_tx) + if (!qinst->is_tx) { free_irq(qinst->irq, chan); + kfree(qinst->rx_buff); + } } /** @@ -425,27 +474,6 @@ static int ti_msgmgr_queue_setup(int idx, struct device *dev, dev_name(dev), qinst->is_tx ? "tx" : "rx", qinst->queue_id, qinst->proxy_id); - if (!qinst->is_tx) { - char of_rx_irq_name[7]; - - snprintf(of_rx_irq_name, sizeof(of_rx_irq_name), - "rx_%03d", qinst->queue_id); - - qinst->irq = of_irq_get_byname(np, of_rx_irq_name); - if (qinst->irq < 0) { - dev_crit(dev, - "[%d]QID %d PID %d:No IRQ[%s]: %d\n", - idx, qinst->queue_id, qinst->proxy_id, - of_rx_irq_name, qinst->irq); - return qinst->irq; - } - /* Allocate usage buffer for rx */ - qinst->rx_buff = devm_kzalloc(dev, - d->max_message_size, GFP_KERNEL); - if (!qinst->rx_buff) - return -ENOMEM; - } - qinst->queue_buff_start = inst->queue_proxy_region + Q_DATA_OFFSET(qinst->proxy_id, qinst->queue_id, d->data_first_reg); qinst->queue_buff_end = inst->queue_proxy_region + @@ -454,6 +482,9 @@ static int ti_msgmgr_queue_setup(int idx, struct device *dev, Q_STATE_OFFSET(qinst->queue_id); qinst->chan = chan; + /* Setup an error value for IRQ - Lazy allocation */ + qinst->irq = -EINVAL; + chan->con_priv = qinst; dev_dbg(dev, "[%d] qidx=%d pidx=%d irq=%d q_s=%p q_e = %p\n",