From: "J. German Rivera" <German.Rivera@freescale.com>
To: <gregkh@linuxfoundation.org>, <arnd@arndb.de>,
<devel@driverdev.osuosl.org>, <linux-kernel@vger.kernel.org>
Cc: <stuart.yoder@freescale.com>, <itai.katz@freescale.com>,
<lijun.pan@freescale.com>, <leoli@freescale.com>,
<scottwood@freescale.com>, <agraf@suse.de>,
<bhamciu1@freescale.com>, <R89243@freescale.com>,
<bhupesh.sharma@freescale.com>, <nir.erez@freescale.com>,
<richard.schmitt@freescale.com>, <dan.carpenter@oracle.com>,
"J. German Rivera" <German.Rivera@freescale.com>
Subject: [PATCH 3/4] staging: fsl-mc:Added support for atomic portals
Date: Wed, 14 Oct 2015 15:11:44 -0500 [thread overview]
Message-ID: <1444853505-1369-4-git-send-email-German.Rivera@freescale.com> (raw)
In-Reply-To: <1444853505-1369-1-git-send-email-German.Rivera@freescale.com>
Refactored mc_send_command() to support two flavors of polling:
- preemptible (for non-atomic portals), which was already supported.
It calls usleep_range() between polling iterations.
- non-preemptible (for atomic portals), which is needed when
mc_send_command() is called with interrupts disabled.
It calls udelay() between polling iterations.
Signed-off-by: J. German Rivera <German.Rivera@freescale.com>
---
drivers/staging/fsl-mc/bus/mc-sys.c | 53 +++++++++++++++++++++++++++++++--
drivers/staging/fsl-mc/include/mc-sys.h | 5 ++++
2 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c b/drivers/staging/fsl-mc/bus/mc-sys.c
index c4f5bdd..6eeb9fa 100644
--- a/drivers/staging/fsl-mc/bus/mc-sys.c
+++ b/drivers/staging/fsl-mc/bus/mc-sys.c
@@ -339,20 +339,63 @@ static int mc_polling_wait_preemptible(struct fsl_mc_io *mc_io,
}
/**
+ * Waits for the completion of an MC command doing atomic polling.
+ * udelay() is called between polling iterations.
+ *
+ * @mc_io: MC I/O object to be used
+ * @cmd: command buffer to receive MC response
+ * @mc_status: MC command completion status
+ */
+static int mc_polling_wait_atomic(struct fsl_mc_io *mc_io,
+ struct mc_command *cmd,
+ enum mc_cmd_status *mc_status)
+{
+ enum mc_cmd_status status;
+ unsigned long timeout_usecs = MC_CMD_COMPLETION_TIMEOUT_MS * 1000;
+
+ BUILD_BUG_ON((MC_CMD_COMPLETION_TIMEOUT_MS * 1000) %
+ MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS != 0);
+
+ for (;;) {
+ status = mc_read_response(mc_io->portal_virt_addr, cmd);
+ if (status != MC_CMD_STATUS_READY)
+ break;
+
+ udelay(MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS);
+ timeout_usecs -= MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS;
+ if (timeout_usecs == 0) {
+ pr_debug("MC command timed out (portal: %#llx, obj handle: %#x, command: %#x)\n",
+ mc_io->portal_phys_addr,
+ (unsigned int)
+ MC_CMD_HDR_READ_TOKEN(cmd->header),
+ (unsigned int)
+ MC_CMD_HDR_READ_CMDID(cmd->header));
+
+ return -ETIMEDOUT;
+ }
+ }
+
+ *mc_status = status;
+ return 0;
+}
+
+/**
* Sends a command to the MC device using the given MC I/O object
*
* @mc_io: MC I/O object to be used
* @cmd: command to be sent
*
* Returns '0' on Success; Error code otherwise.
- *
- * NOTE: This function cannot be invoked from from atomic contexts.
*/
int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
{
int error;
enum mc_cmd_status status;
+ if (WARN_ON(in_irq() &&
+ !(mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)))
+ return -EINVAL;
+
/*
* Send command to the MC hardware:
*/
@@ -361,7 +404,11 @@ int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
/*
* Wait for response from the MC hardware:
*/
- error = mc_polling_wait_preemptible(mc_io, cmd, &status);
+ if (!(mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL))
+ error = mc_polling_wait_preemptible(mc_io, cmd, &status);
+ else
+ error = mc_polling_wait_atomic(mc_io, cmd, &status);
+
if (error < 0)
return error;
diff --git a/drivers/staging/fsl-mc/include/mc-sys.h b/drivers/staging/fsl-mc/include/mc-sys.h
index 7d44d8c..15e19af 100644
--- a/drivers/staging/fsl-mc/include/mc-sys.h
+++ b/drivers/staging/fsl-mc/include/mc-sys.h
@@ -40,6 +40,11 @@
#include <linux/io.h>
#include <linux/dma-mapping.h>
+/**
+ * Bit masks for a MC I/O object (struct fsl_mc_io) flags
+ */
+#define FSL_MC_IO_ATOMIC_CONTEXT_PORTAL 0x0001
+
struct fsl_mc_resource;
struct mc_command;
--
2.3.3
next prev parent reply other threads:[~2015-10-14 20:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-14 20:11 [PATCH 0/4] staging: fsl-mc: MC command serialization J. German Rivera
2015-10-14 20:11 ` [PATCH 1/4] staging: fsl-mc: changed timeout units for MC cmd completion J. German Rivera
2015-10-14 20:11 ` [PATCH 2/4] staging: fsl-mc: refactored mc_send_command() J. German Rivera
2015-10-14 20:11 ` J. German Rivera [this message]
2015-10-14 20:11 ` [PATCH 4/4] staging: fsl-mc: Added serialization to mc_send_command() J. German Rivera
2015-10-17 6:15 ` [PATCH 0/4] staging: fsl-mc: MC command serialization Greg KH
2015-10-17 16:36 ` Jose Rivera
2015-10-17 16:49 ` Greg KH
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=1444853505-1369-4-git-send-email-German.Rivera@freescale.com \
--to=german.rivera@freescale.com \
--cc=R89243@freescale.com \
--cc=agraf@suse.de \
--cc=arnd@arndb.de \
--cc=bhamciu1@freescale.com \
--cc=bhupesh.sharma@freescale.com \
--cc=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=itai.katz@freescale.com \
--cc=leoli@freescale.com \
--cc=lijun.pan@freescale.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nir.erez@freescale.com \
--cc=richard.schmitt@freescale.com \
--cc=scottwood@freescale.com \
--cc=stuart.yoder@freescale.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
all inboxes | Powered by JetHome®