Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2530088imu; Sun, 23 Dec 2018 01:44:40 -0800 (PST) X-Google-Smtp-Source: ALg8bN6uEexrRmLUYA/u+zLR/+S+SAwSr68A5p2FDHeuHMhzITeSFFwnNZix4LTWG7GTjDYe7dwy X-Received: by 2002:a5d:8949:: with SMTP id b9mr2185650iot.136.1545558280760; Sun, 23 Dec 2018 01:44:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545558280; cv=none; d=google.com; s=arc-20160816; b=sjKosU3C/eTGKdCp4C2fnF3Yjo2q21I7d8SE31DOAn4tFx61LWNR4ka3EPgOmI9NIG HkAe/kv4VOBJF8l5L9CldYqW84JiGj86MFWxPYBSxDGJkSHmQ3+lc8YdsKDWHctAOZeK JhPfhTN7qsgXbIw2b+OIbGjlzdxiCPUNqPk8JA2R3WnrTE7AH+cN8O39NxiCkXbM86hr WMUfmeOytiXSLfM2a3JJ1dohpnKMRRXvmQhUBP+LKj4QSYM6hUReB3REtbZS29nGHVpD ISs9WY0ASheJiz/e4jVx8zCiQOS5c2UV0mEFXUCOKpVR32tq5pXds9lR9FNheaf+Fmux tMrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=aZt2eyagM4lqMLEpi1b+c4/zgJkxTUDtvq67TbKB9vA=; b=q5tpSW+A6jYl0vce/i7Z5Ko14Nqn2lvXCrJYvJx0QoBLeE6wz8xWCMBs3m0g7JgqGU YYxpbujecR8vrBSHzQPkk9HwLmiDGGif7EfgQ2fwrRJwFc7soNEJJOk9EfbX/x9QgZwV jKe0NqqDKubMj3OfNI7cz04G385rl2ph8liwPUYfYmSYn6LHqDnq4J6eK9x4kP35l/aH 12TFjtEVPeQ4v+2gv3XEuZEJqxofyKjIL4pB+D2UfUdMdwt1j+9D2haYIZFPYuBCOCgO /7a2zbUQrxFZVbH6ZcBGNal39SduE8/+u+68gsX8S8GquW7FMvDH3U/l0RkrVsrq6ldN tTzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I+OLUMN6; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l63si8003771itl.65.2018.12.23.01.44.27; Sun, 23 Dec 2018 01:44:40 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=I+OLUMN6; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732729AbeLVCAC (ORCPT + 99 others); Fri, 21 Dec 2018 21:00:02 -0500 Received: from mail-io1-f65.google.com ([209.85.166.65]:36571 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725830AbeLVCAB (ORCPT ); Fri, 21 Dec 2018 21:00:01 -0500 Received: by mail-io1-f65.google.com with SMTP id m19so5186459ioh.3; Fri, 21 Dec 2018 18:00:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aZt2eyagM4lqMLEpi1b+c4/zgJkxTUDtvq67TbKB9vA=; b=I+OLUMN6z+8+P1cLDLfncLEfJnqV1hNMlZ8a2oowX/1qYJojSOnTzPYZ+7UwF0vSSv T+fk+p74TATcqe+5c9Y/uhDwYx976YelKyrSAkWN1mjemyT8PI1/2yLee6dNy1lD/68S c9s0UAM6zZE3eRIPQw7xomcre0XjabKJSDkpeodpHb9vBiqgXarGuV4pdAiVwg0RyBVt G6ODCqspTlp+3pL9qq1bgVXeYGBTPHHVZ4KeX675eTVksRs9s3vh5iHefjMdhvA2E8RZ 5F92g1LkckujYzjoWYk3qtBnZIPLqaqb4gv1gi7epySfgUsss++4Z9HKd8tPqCzoZHYn 31lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aZt2eyagM4lqMLEpi1b+c4/zgJkxTUDtvq67TbKB9vA=; b=pGSsMYpLZCZSfubc3ZTQsYHTImYI7ep3+AP4hltnW5QImjA29BuXqxE9eYr951GhJb skKTkRWy9noqxWR3BYKuRE8bVEMBNjhlMk0HYiSFxPgP+dDsmHcqZ713byBWsc6XZEf7 /RUzxnYMvy3nmQ9YqtVEnNS2k47k9NQn3Y5cbfDU0khViWm4N5/kaHGdBHsPmM690zja KmwN+est6TZyZYxNFRdjzb6ftJDb5Cg3MPERMH+7JNdIIzoqum7Fu+ozgUGFznaxntLV oHz1zpkOL2zAm4dWGmlRxxEnIdh3Nl/TYDowrbxp72GJT71VvF/6g+YSyi4J+bjXfeRx aP8A== X-Gm-Message-State: AJcUukfZz0xKpZAhit9gKzrpaHdpnYXbor2Z3eUzNMyiqUnv7Rq6mhAj Z1N5arQGtYfUAYu1pZAuGhrn9RixDoY4uuK0stQ= X-Received: by 2002:a6b:a0d:: with SMTP id z13mr3203284ioi.57.1545444000039; Fri, 21 Dec 2018 18:00:00 -0800 (PST) MIME-Version: 1.0 References: <1545327149-22331-1-git-send-email-wendy.liang@xilinx.com> <1545327149-22331-2-git-send-email-wendy.liang@xilinx.com> In-Reply-To: <1545327149-22331-2-git-send-email-wendy.liang@xilinx.com> From: Jassi Brar Date: Fri, 21 Dec 2018 19:59:48 -0600 Message-ID: Subject: Re: [PATH v7 1/2] mailbox: ZynqMP IPI mailbox controller To: Wendy Liang Cc: Michal Simek , Rob Herring , Mark Rutland , Linux Kernel Mailing List , linux-arm-kernel@lists.infradead.org, Devicetree List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 20, 2018 at 11:32 AM Wendy Liang wrote: > diff --git a/drivers/mailbox/zynqmp-ipi-mailbox.c b/drivers/mailbox/zynqmp-ipi-mailbox.c > new file mode 100644 > index 0000000..bbddfd5 > --- /dev/null > +++ b/drivers/mailbox/zynqmp-ipi-mailbox.c > @@ -0,0 +1,764 @@ ...... > + > +/* IPI SMC Macros */ > +#define IPI_SMC_OPEN_IRQ_MASK 0x00000001UL /* IRQ enable bit in IPI > + * open SMC call > + */ > +#define IPI_SMC_NOTIFY_BLOCK_MASK 0x00000001UL /* Flag to indicate if > + * IPI notification needs > + * to be blocking. > + */ > +#define IPI_SMC_ENQUIRY_DIRQ_MASK 0x00000001UL /* Flag to indicate if > + * notification interrupt > + * to be disabled. > + */ > +#define IPI_SMC_ACK_EIRQ_MASK 0x00000001UL /* Flag to indicate if > + * notification interrupt > + * to be enabled. > + */ > + The first two are unused. > +struct zynqmp_ipi_pdata { > + struct device *dev; > + int irq; > + unsigned int method; > 'method' doesn't track the HVC option in the driver. Please have a look. ...... > + > +static void zynqmp_ipi_fw_call(struct zynqmp_ipi_mbox *ipi_mbox, > + unsigned long a0, unsigned long a3, > + unsigned long a4, unsigned long a5, > + unsigned long a6, unsigned long a7, > + struct arm_smccc_res *res) > [a4,a7] are always 0, so maybe just drop them? > +static bool zynqmp_ipi_last_tx_done(struct mbox_chan *chan) > +{ > + struct device *dev = chan->mbox->dev; > + struct zynqmp_ipi_mbox *ipi_mbox = dev_get_drvdata(dev); > + struct zynqmp_ipi_mchan *mchan = chan->con_priv; > + int ret; > + u64 arg0; > + struct arm_smccc_res res; > + struct zynqmp_ipi_message *msg; > + > + if (WARN_ON(!ipi_mbox)) { > + dev_err(dev, "no platform drv data??\n"); > + return false; > + } > + > + if (mchan->chan_type == IPI_MB_CHNL_TX) { > + /* We only need to check if the message been taken > + * by the remote in the TX channel > + */ > + arg0 = SMC_IPI_MAILBOX_STATUS_ENQUIRY; > + zynqmp_ipi_fw_call(ipi_mbox, arg0, 0, 0, 0, 0, 0, &res); > + /* Check the SMC call status, a0 of the result */ > + ret = (int)(res.a0 & 0xFFFFFFFF); > + if (ret < 0 || ret & IPI_MB_STATUS_SEND_PENDING) > + return false; > + OK, but ... > + msg = mchan->rx_buf; > + msg->len = mchan->resp_buf_size; > + memcpy_fromio(msg->data, mchan->resp_buf, msg->len); > + mbox_chan_received_data(chan, (void *)msg); > .... wouldn't this be done from zynqmp_ipi_interrupt()? > +static int zynqmp_ipi_send_data(struct mbox_chan *chan, void *data) > +{ ......... > + /* Enquire if the mailbox is free to send message */ > + arg0 = SMC_IPI_MAILBOX_STATUS_ENQUIRY; > + timeout = 10; > + if (msg && msg->len) { > + timeout = 10; > + do { > + zynqmp_ipi_fw_call(ipi_mbox, arg0, > + 0, 0, 0, 0, 0, &res); > + ret = res.a0 & 0xFFFFFFFF; > + if (ret >= 0 && > + !(ret & IPI_MB_STATUS_SEND_PENDING)) > + break; > + usleep_range(1, 2); > + timeout--; > + } while (timeout); > + if (!timeout) { > + dev_warn(dev, "chan %d sending msg timeout.\n", > + ipi_mbox->remote_id); > + return -ETIME; > + } > + memcpy_toio(mchan->req_buf, msg->data, msg->len); > + } > This check should be done in last_tx_done, and not here. send_data is never called unless last_tx_done returns true. > + /* Kick IPI mailbox to send message */ > + arg0 = SMC_IPI_MAILBOX_NOTIFY; > + zynqmp_ipi_fw_call(ipi_mbox, arg0, 0, 0, 0, 0, 0, &res); > + } else { > + /* Send response message */ > + if (msg && msg->len > mchan->resp_buf_size) { > + dev_err(dev, "channel %d message length %u > max %lu\n", > + mchan->chan_type, (unsigned int)msg->len, > + mchan->resp_buf_size); > + return -EINVAL; > + } > + if (msg && msg->len) > + memcpy_toio(mchan->resp_buf, msg->data, msg->len); > > + arg0 = SMC_IPI_MAILBOX_NOTIFY; > + arg0 = SMC_IPI_MAILBOX_ACK; > This is obviously wrong. .... > + mbox->chans = chans; > + chans[IPI_MB_CHNL_TX].con_priv = &ipi_mbox->mchans[IPI_MB_CHNL_TX]; > + chans[IPI_MB_CHNL_RX].con_priv = &ipi_mbox->mchans[IPI_MB_CHNL_RX]; > + ipi_mbox->mchans[IPI_MB_CHNL_TX].chan_type = IPI_MB_CHNL_TX; > + ipi_mbox->mchans[IPI_MB_CHNL_RX].chan_type = IPI_MB_CHNL_RX; > + ret = mbox_controller_register(mbox); > while at it, you may want to start using devm_mbox_controller_register() recently added by Thierry. > + if (ret) > + dev_err(mdev, > + "Failed to register mbox_controller(%d)\n", ret); > + else > + dev_info(mdev, "Probed ZynqMP IPI Mailbox driver.\n"); > You may want to also print something instance specific here. > +static int zynqmp_ipi_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct device_node *nc, *np = pdev->dev.of_node; > + struct zynqmp_ipi_pdata *pdata; > + struct zynqmp_ipi_mbox *mbox; > + int i, ret = -EINVAL; > + > + i = 0; > + for_each_available_child_of_node(np, nc) > + i++; > of_get_child_count() ? Thnx