From: "Li, Ming" <ming4.li@intel.com>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: <Jonathan.Cameron@huawei.com>, <dave.jiang@intel.com>,
<alison.schofield@intel.com>, <ira.weiny@intel.com>,
<vishal.l.verma@intel.com>, <fan.ni@samsung.com>,
<a.manzanares@samsung.com>, <linux-cxl@vger.kernel.org>,
<dan.j.williams@intel.com>
Subject: Re: [PATCH 2/7] cxl/mbox: Add background cmd handling machinery
Date: Sun, 23 Apr 2023 15:54:07 +0800 [thread overview]
Message-ID: <d9ba88f8-9cc1-44f8-6e92-cb46683de938@intel.com> (raw)
In-Reply-To: <20230421092321.12741-3-dave@stgolabs.net>
On 4/21/2023 5:23 PM, Davidlohr Bueso wrote:
> This adds support for handling background operations, as defined in
> the CXL 3.0 spec. Commands that can take too long (over ~2 seconds)
> can run in the background asynchronously (to the hardware).
>
> The driver will deal with such commands synchronously, blocking all
> other incoming commands for a specified period of time, allowing
> time-slicing the command such that the caller can send incremental
> requests to avoid monopolizing the driver/device. This approach
> makes the code simpler, where any out of sync (timeout) between the
> driver and hardware is just disregarded as an invalid state until
> the next successful submission.
>
> On devices where mbox interrupts are supported, this will still use
> a poller that will wakeup in the specified wait intervals. The irq
> handler will simply awake a blocked cmd, which is also safe vs a
> task that is either waking (timing out) or already awoken. Similarly
> any irq setup error during the probing falls back to polling, thus
> avoids unnecessarily erroring out.
>
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
> ---
......
> +static bool cxl_mbox_background_complete(struct cxl_dev_state *cxlds)
> +{
> + u64 reg;
> +
> + reg = readq(cxlds->regs.mbox + CXLDEV_MBOX_BG_CMD_STATUS_OFFSET);
> + return FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_PCT_MASK, reg) == 100;
> +}
should using a MACRO to define '100' be better?
> +
> +static irqreturn_t cxl_pci_mbox_irq(int irq, void *id)
> +{
> + struct cxl_dev_state *cxlds = id;
> +
> + /* spurious or raced with hw? */
> + if (!cxl_mbox_background_complete(cxlds)) {
> + struct pci_dev *pdev = to_pci_dev(cxlds->dev);
> +
> + dev_warn(&pdev->dev,
> + "Mailbox background operation IRQ but incomplete\n");
> + goto done;
> + }
> +
> + /* short-circuit the wait in __cxl_pci_mbox_send_cmd() */
> + wake_up(&mbox_wait);
> +done:
> + return IRQ_HANDLED;
> +}
> +
> /**
> * __cxl_pci_mbox_send_cmd() - Execute a mailbox command
> * @cxlds: The device state to communicate with.
> @@ -178,7 +206,59 @@ 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);
>
> - if (mbox_cmd->return_code != CXL_MBOX_CMD_RC_SUCCESS) {
> + /*
> + * 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) {
> + u64 bg_status_reg;
> + int i;
> +
> + dev_dbg(dev, "Mailbox background operation (0x%04x) started\n",
> + mbox_cmd->opcode);
> +
> + for (i = 0; i < mbox_cmd->poll_count; i++) {
> + int ret = wait_event_interruptible_timeout(
> + mbox_wait, cxl_mbox_background_complete(cxlds),
> + msecs_to_jiffies(mbox_cmd->poll_interval));
> + if (ret > 0)
> + break;
> +
> + /* interrupted by a signal */
> + if (ret < 0)
> + return ret;
> + }
> +
> + 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 &&
> + mbox_cmd->return_code != CXL_MBOX_CMD_RC_BACKGROUND) {
> dev_dbg(dev, "Mailbox operation had an error: %s\n",
> cxl_mbox_cmd_rc2str(mbox_cmd));
> return 0; /* completed but caller must check return_code */
why does here only handle failure cases for non-background command? Maybe I missed something, I think that we need to do same thing here for background command.
Thanks
Ming
> @@ -224,6 +304,7 @@ static int cxl_pci_setup_mailbox(struct cxl_dev_state *cxlds)
> const int cap = readl(cxlds->regs.mbox + CXLDEV_MBOX_CAPS_OFFSET);
> unsigned long timeout;
> u64 md_status;
> + int rc, irq;
>
> timeout = jiffies + mbox_ready_timeout * HZ;
> do {
> @@ -272,6 +353,27 @@ static int cxl_pci_setup_mailbox(struct cxl_dev_state *cxlds)
> dev_dbg(cxlds->dev, "Mailbox payload sized %zu",
> cxlds->payload_size);
>
> + if (cap & CXLDEV_MBOX_CAP_BG_CMD_IRQ) {
> + struct pci_dev *pdev = to_pci_dev(cxlds->dev);
> +
> + irq = pci_irq_vector(pdev,
> + FIELD_GET(CXLDEV_MBOX_CAP_IRQ_MSGNUM_MASK, cap));
> + if (irq < 0)
> + goto mbox_poll;
> +
> + rc = devm_request_irq(cxlds->dev, irq, cxl_pci_mbox_irq,
> + IRQF_SHARED, "mailbox", cxlds);
> + if (rc)
> + goto mbox_poll;
> +
> + 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;
> }
>
next prev parent reply other threads:[~2023-04-23 7:54 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-21 9:23 [PATCH v4 0/7] cxl: Background cmds and device sanitation Davidlohr Bueso
2023-04-21 9:23 ` [PATCH 1/7] cxl/pci: Allocate irq vectors earlier in pci probe Davidlohr Bueso
2023-04-28 16:09 ` Dave Jiang
2023-05-11 13:55 ` Jonathan Cameron
2023-04-21 9:23 ` [PATCH 2/7] cxl/mbox: Add background cmd handling machinery Davidlohr Bueso
2023-04-23 7:54 ` Li, Ming [this message]
2023-04-23 20:51 ` Davidlohr Bueso
2023-04-28 16:21 ` Dave Jiang
2023-04-28 17:18 ` Davidlohr Bueso
2023-04-28 21:04 ` Dave Jiang
2023-04-28 22:03 ` Davidlohr Bueso
2023-05-01 15:56 ` Davidlohr Bueso
2023-05-11 14:23 ` Jonathan Cameron
2023-05-11 16:04 ` Davidlohr Bueso
2023-05-12 17:05 ` Jonathan Cameron
2023-04-21 9:23 ` [PATCH 3/7] cxl/mbox: Add sanitation " Davidlohr Bueso
2023-04-28 16:43 ` Dave Jiang
2023-04-28 16:46 ` Davidlohr Bueso
2023-04-28 17:37 ` Dave Jiang
2023-05-11 14:45 ` Jonathan Cameron
2023-05-11 16:48 ` Davidlohr Bueso
2023-05-12 17:02 ` Jonathan Cameron
2023-04-21 9:23 ` [PATCH 4/7] cxl/mem: Wire up Sanitation support Davidlohr Bueso
2023-04-21 20:04 ` kernel test robot
2023-04-21 20:24 ` kernel test robot
2023-05-11 15:07 ` Jonathan Cameron
2023-05-11 17:23 ` Davidlohr Bueso
2023-05-12 17:00 ` Jonathan Cameron
2023-04-21 9:23 ` [PATCH 5/7] cxl/test: Add Sanitize opcode support Davidlohr Bueso
2023-05-11 15:09 ` Jonathan Cameron
2023-05-11 15:13 ` Davidlohr Bueso
2023-04-21 9:23 ` [PATCH 6/7] cxl/mem: Support Secure Erase Davidlohr Bueso
2023-05-11 15:10 ` Jonathan Cameron
2023-04-21 9:23 ` [PATCH 7/7] cxl/test: Add Secure Erase opcode support Davidlohr Bueso
2023-05-11 15:10 ` Jonathan Cameron
2023-04-23 2:05 ` [PATCH v4 0/7] cxl: Background cmds and device sanitation Davidlohr Bueso
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=d9ba88f8-9cc1-44f8-6e92-cb46683de938@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=ira.weiny@intel.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