Lines Matching +full:fsl +full:- +full:mc

1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
5 * I/O services to send MC commands to the MC hardware
14 #include <linux/io-64-nonatomic-hi-lo.h>
15 #include <linux/fsl/mc.h>
17 #include "fsl-mc-private.h"
20 * Timeout in milliseconds to wait for the completion of an MC command
26 * iterations while waiting for MC command completion
33 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header; in mc_cmd_hdr_read_status()
35 return (enum mc_cmd_status)hdr->status; in mc_cmd_hdr_read_status()
40 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header; in mc_cmd_hdr_read_cmdid()
41 u16 cmd_id = le16_to_cpu(hdr->cmd_id); in mc_cmd_hdr_read_cmdid()
50 [MC_CMD_STATUS_AUTH_ERR] = -EACCES, in mc_status_to_error()
51 [MC_CMD_STATUS_NO_PRIVILEGE] = -EPERM, in mc_status_to_error()
52 [MC_CMD_STATUS_DMA_ERR] = -EIO, in mc_status_to_error()
53 [MC_CMD_STATUS_CONFIG_ERR] = -ENXIO, in mc_status_to_error()
54 [MC_CMD_STATUS_TIMEOUT] = -ETIMEDOUT, in mc_status_to_error()
55 [MC_CMD_STATUS_NO_RESOURCE] = -ENAVAIL, in mc_status_to_error()
56 [MC_CMD_STATUS_NO_MEMORY] = -ENOMEM, in mc_status_to_error()
57 [MC_CMD_STATUS_BUSY] = -EBUSY, in mc_status_to_error()
58 [MC_CMD_STATUS_UNSUPPORTED_OP] = -ENOTSUPP, in mc_status_to_error()
59 [MC_CMD_STATUS_INVALID_STATE] = -ENODEV, in mc_status_to_error()
63 return -EINVAL; in mc_status_to_error()
86 return "Unknown MC error"; in mc_status_to_string()
92 * mc_write_command - writes a command to a Management Complex (MC) portal
94 * @portal: pointer to an MC portal
105 * Data is already in the expected LE byte-order. Do an in mc_write_command()
106 * extra LE -> CPU conversion so that the CPU -> LE done in in mc_write_command()
109 writeq_relaxed(le64_to_cpu(cmd->params[i]), &portal->params[i]); in mc_write_command()
112 writeq(le64_to_cpu(cmd->header), &portal->header); in mc_write_command()
116 * mc_read_response - reads the response for the last MC command from a
117 * Management Complex (MC) portal
119 * @portal: pointer to an MC portal
131 /* Copy command response header from MC portal: */ in mc_read_response()
132 resp->header = cpu_to_le64(readq_relaxed(&portal->header)); in mc_read_response()
137 /* Copy command response data from MC portal: */ in mc_read_response()
140 * Data is expected to be in LE byte-order. Do an in mc_read_response()
141 * extra CPU -> LE to revert the LE -> CPU done in in mc_read_response()
144 resp->params[i] = in mc_read_response()
145 cpu_to_le64(readq_relaxed(&portal->params[i])); in mc_read_response()
151 * mc_polling_wait_preemptible() - Waits for the completion of an MC
155 * @mc_io: MC I/O object to be used
156 * @cmd: command buffer to receive MC response
157 * @mc_status: MC command completion status
168 * Wait for response from the MC hardware: in mc_polling_wait_preemptible()
171 status = mc_read_response(mc_io->portal_virt_addr, cmd); in mc_polling_wait_preemptible()
176 * TODO: When MC command completion interrupts are supported in mc_polling_wait_preemptible()
183 dev_dbg(mc_io->dev, in mc_polling_wait_preemptible()
184 "MC command timed out (portal: %pa, dprc handle: %#x, command: %#x)\n", in mc_polling_wait_preemptible()
185 &mc_io->portal_phys_addr, in mc_polling_wait_preemptible()
189 return -ETIMEDOUT; in mc_polling_wait_preemptible()
198 * mc_polling_wait_atomic() - Waits for the completion of an MC command
201 * @mc_io: MC I/O object to be used
202 * @cmd: command buffer to receive MC response
203 * @mc_status: MC command completion status
216 status = mc_read_response(mc_io->portal_virt_addr, cmd); in mc_polling_wait_atomic()
221 timeout_usecs -= MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS; in mc_polling_wait_atomic()
223 dev_dbg(mc_io->dev, in mc_polling_wait_atomic()
224 "MC command timed out (portal: %pa, dprc handle: %#x, command: %#x)\n", in mc_polling_wait_atomic()
225 &mc_io->portal_phys_addr, in mc_polling_wait_atomic()
229 return -ETIMEDOUT; in mc_polling_wait_atomic()
238 * mc_send_command() - Sends a command to the MC device using the given
239 * MC I/O object
240 * @mc_io: MC I/O object to be used
251 if (in_irq() && !(mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)) in mc_send_command()
252 return -EINVAL; in mc_send_command()
254 if (mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL) in mc_send_command()
255 raw_spin_lock_irqsave(&mc_io->spinlock, irq_flags); in mc_send_command()
257 mutex_lock(&mc_io->mutex); in mc_send_command()
260 * Send command to the MC hardware: in mc_send_command()
262 mc_write_command(mc_io->portal_virt_addr, cmd); in mc_send_command()
265 * Wait for response from the MC hardware: in mc_send_command()
267 if (!(mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)) in mc_send_command()
276 dev_dbg(mc_io->dev, in mc_send_command()
277 "MC command failed: portal: %pa, dprc handle: %#x, command: %#x, status: %s (%#x)\n", in mc_send_command()
278 &mc_io->portal_phys_addr, in mc_send_command()
290 if (mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL) in mc_send_command()
291 raw_spin_unlock_irqrestore(&mc_io->spinlock, irq_flags); in mc_send_command()
293 mutex_unlock(&mc_io->mutex); in mc_send_command()