From: "Li, Ming" <ming4.li@intel.com>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: <dave.jiang@intel.com>, <alison.schofield@intel.com>,
<vishal.l.verma@intel.com>, <Jonathan.Cameron@huawei.com>,
<fan.ni@samsung.com>, <a.manzanares@samsung.com>,
<linux-cxl@vger.kernel.org>, <dan.j.williams@intel.com>
Subject: Re: [PATCH v2] cxl/mbox: Add background cmd handling machinery
Date: Tue, 16 May 2023 15:58:58 +0800 [thread overview]
Message-ID: <09aaafe8-76c2-85a0-ab5b-fd337c625530@intel.com> (raw)
In-Reply-To: <gtvozgdx2ak7tekc3heczk5g7gj3cwuoptez6tjmkecader4lo@7t2em7rclcxn>
On 5/3/2023 10:57 PM, Davidlohr Bueso wrote:
> /**
> * __cxl_pci_mbox_send_cmd() - Execute a mailbox command
> * @cxlds: The device state to communicate with.
> @@ -177,6 +205,57 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_dev_state *cxlds,
> mbox_cmd->return_code =
> FIELD_GET(CXLDEV_MBOX_STATUS_RET_CODE_MASK, status_reg);
>
> + /*
> + * Handle the background command in a synchronous manner.
> + *
> + * All other mailbox commands will serialize/queue on the mbox_mutex,
> + * which we currently hold. Furthermore this also guarantees that
> + * cxl_mbox_background_complete() checks are safe amongst each other,
> + * in that no new bg operation can occur in between.
> + *
> + * Background operations are timesliced in accordance with the nature
> + * of the command. In the event of timeout, the mailbox state is
> + * indeterminate until the next successful command submission and the
> + * driver can get back in sync with the hardware state.
> + */
> + if (mbox_cmd->return_code == CXL_MBOX_CMD_RC_BACKGROUND) {
> + long ret;
> + u64 bg_status_reg;
> + int i, timeout = mbox_cmd->poll_interval;
> +
> + dev_dbg(dev, "Mailbox background operation (0x%04x) started\n",
> + mbox_cmd->opcode);
> +
> + for (i = 0; i < mbox_cmd->poll_count; i++) {
> + ret = rcuwait_wait_event_timeout(&cxlds->mbox_wait,
> + cxl_mbox_background_complete(cxlds),
> + TASK_INTERRUPTIBLE,
> + msecs_to_jiffies(timeout));
> + if (ret > 0)
> + break;
> + if (ret < 0) /* interrupted by a signal */
> + return ret;
What do you think if adding a dev_dbg() here for outputting current percentage complete for debugging? is it helpful?
Thanks
Ming
> + }
> +
> + if (!cxl_mbox_background_complete(cxlds)) {
> + u64 md_status =
> + readq(cxlds->regs.memdev + CXLMDEV_STATUS_OFFSET);
> +
> + cxl_cmd_err(cxlds->dev, mbox_cmd, md_status,
> + "background timeout");
> + return -ETIMEDOUT;
> + }
> +
> + bg_status_reg = readq(cxlds->regs.mbox +
> + CXLDEV_MBOX_BG_CMD_STATUS_OFFSET);
> + mbox_cmd->return_code =
> + FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_RC_MASK,
> + bg_status_reg);
> + dev_dbg(dev,
> + "Mailbox background operation (0x%04x) completed\n",
> + mbox_cmd->opcode);
> + }
> +
> if (mbox_cmd->return_code != CXL_MBOX_CMD_RC_SUCCESS) {
> dev_dbg(dev, "Mailbox operation had an error: %s\n",
> cxl_mbox_cmd_rc2str(mbox_cmd));
> @@ -271,6 +350,29 @@ static int cxl_pci_setup_mailbox(struct cxl_dev_state *cxlds)
> dev_dbg(cxlds->dev, "Mailbox payload sized %zu",
> cxlds->payload_size);
>
> + rcuwait_init(&cxlds->mbox_wait);
> + if (cap & CXLDEV_MBOX_CAP_BG_CMD_IRQ) {
> + int irq, msgnum;
> + struct pci_dev *pdev = to_pci_dev(cxlds->dev);
> +
> + msgnum = FIELD_GET(CXLDEV_MBOX_CAP_IRQ_MSGNUM_MASK, cap);
> + irq = pci_irq_vector(pdev, msgnum);
> + if (irq < 0)
> + goto mbox_poll;
> +
> + if (devm_request_irq(cxlds->dev, irq, cxl_pci_mbox_irq,
> + IRQF_SHARED, NULL, cxlds))
> + goto mbox_poll;
> +
> + /* only enable background cmd mbox irq support */
> + writel(CXLDEV_MBOX_CTRL_BG_CMD_IRQ,
> + cxlds->regs.mbox + CXLDEV_MBOX_CTRL_OFFSET);
> +
> + return 0;
> + }
> +
> +mbox_poll:
> + dev_dbg(cxlds->dev, "Mailbox interrupts are unsupported");
> return 0;
> }
>
> --
> 2.40.1
next prev parent reply other threads:[~2023-05-16 7:59 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-02 17:18 [PATCH 0/3] cxl: Handle background commands Davidlohr Bueso
2023-05-02 17:18 ` [PATCH 1/3] rcuwait: Support timeouts Davidlohr Bueso
2023-05-19 21:38 ` Dan Williams
2023-05-19 22:55 ` Davidlohr Bueso
2023-05-20 11:03 ` Peter Zijlstra
2023-05-02 17:18 ` [PATCH 2/3] cxl/pci: Allocate irq vectors earlier in pci probe Davidlohr Bueso
2023-05-15 10:08 ` Jonathan Cameron
2023-05-02 17:18 ` [PATCH 3/3] cxl/mbox: Add background cmd handling machinery Davidlohr Bueso
2023-05-02 17:55 ` Davidlohr Bueso
2023-05-03 14:57 ` [PATCH v2] " Davidlohr Bueso
2023-05-15 10:30 ` Jonathan Cameron
2023-05-15 15:40 ` Davidlohr Bueso
2023-05-15 16:19 ` Jonathan Cameron
2023-05-16 7:58 ` Li, Ming [this message]
2023-05-16 17:02 ` Davidlohr Bueso
2023-05-19 23:13 ` Dan Williams
2023-05-22 16:58 ` Davidlohr Bueso
2023-05-22 18:19 ` Dan Williams
2023-05-22 18:57 ` Davidlohr Bueso
2023-05-22 20:16 ` Dan Williams
2023-05-22 20:28 ` Davidlohr Bueso
2023-05-22 21:21 ` Dan Williams
2023-05-22 21:26 ` Davidlohr Bueso
2023-05-22 22:48 ` Dan Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=09aaafe8-76c2-85a0-ab5b-fd337c625530@intel.com \
--to=ming4.li@intel.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=a.manzanares@samsung.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=fan.ni@samsung.com \
--cc=linux-cxl@vger.kernel.org \
--cc=vishal.l.verma@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox