@@ -10,9 +10,9 @@
#include <asm/armv8/mmu.h>
#include <asm/io.h>
#include <asm/arch-fsl-lsch3/immap_lsch3.h>
+#include <layerscape/fsl_mc.h>
#include "cpu.h"
#include "speed.h"
-#include <fsl_mc.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -12,7 +12,7 @@
#include <asm/io.h>
#include <fdt_support.h>
#include <libfdt.h>
-#include <fsl_mc.h>
+#include <layerscape/fsl_mc.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -5,4 +5,6 @@
#
# Layerscape MC driver
-obj-y += mc.o
+obj-y += mc.o \
+ fsl_mc_io_wrapper.o \
+ fsl_mc_dpmng_cmd_wrappers.o
new file mode 100644
@@ -0,0 +1,29 @@
+/*
+ * Freescale Layerscape MC DPMNG command wrappers
+ *
+ * Copyright (C) 2014 Freescale Semiconductor, Inc.
+ * Author: German Rivera <German.Rivera@freescale.com>
+ * Lijun Pan <Lijun.Pan@freescale.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <linux/types.h>
+#include <linux/string.h>
+#include <layerscape/fsl_mc_dpmng_cmd_wrappers.h>
+#include <layerscape/fsl_mc_io_wrapper.h>
+
+int mc_get_version(struct mc_portal_wrapper *mc_portal,
+ struct mc_version *mc_ver_info)
+{
+ int error;
+ struct mc_command cmd;
+
+ build_cmd_mc_get_version(&cmd);
+ error = mc_portal_wrapper_send_command(mc_portal, &cmd);
+ if (error < 0)
+ return error;
+
+ parse_resp_mc_get_version(&cmd, mc_ver_info);
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,89 @@
+/*
+ * Freescale Layerscape MC I/O wrapper
+ *
+ * Copyright (C) 2014 Freescale Semiconductor, Inc.
+ * Author: German Rivera <German.Rivera@freescale.com>
+ * Lijun Pan <Lijun.Pan@freescale.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <asm/io.h>
+#include <layerscape/fsl_mc_io_wrapper.h>
+#include <layerscape/mc_hardware/fsl_mc_io.h>
+
+/**
+ * mc_portal_wrapper_send_command - Send MC command and wait for response
+ *
+ * @mc_portal: Pointer to MC portal wrapper to be used
+ * @cmd: MC command buffer. On input, it contains the command to send to the MC.
+ * On output, it contains the response from the MC if any.
+ *
+ * Depending on the sharing option specified when creating the MC portal
+ * wrapper, this function will use a spinlock or mutex to ensure exclusive
+ * access to the MC portal from the point when the command is sent until a
+ * response is received from the MC.
+ */
+int mc_portal_wrapper_send_command(struct mc_portal_wrapper *mc_portal,
+ struct mc_command *cmd)
+{
+ enum mc_cmd_status status;
+ int error;
+ int timeout = 2000;
+
+ mc_write_command(mc_portal->mmio_regs, cmd);
+
+ do {
+ udelay(1000); /* throttle polling */
+ if (timeout-- <= 0) {
+ error = -ETIMEDOUT;
+ goto out;
+ }
+ status = mc_read_response(mc_portal->mmio_regs, cmd);
+ } while (status == MC_CMD_STATUS_READY);
+ /* MC_CMD_STATUS_READY means command has been send to MC portal, it is
+ * ready to read the result from the MC portal. */
+
+ switch (status) {
+ case MC_CMD_STATUS_OK:
+ error = 0;
+ break;
+ case MC_CMD_STATUS_AUTH_ERR:
+ error = -EACCES; /* Authentication error */
+ break;
+ case MC_CMD_STATUS_NO_PRIVILEGE:
+ error = -EPERM; /* Permission denied */
+ break;
+ case MC_CMD_STATUS_DMA_ERR:
+ error = -EIO; /* Input/Output error */
+ break;
+ case MC_CMD_STATUS_CONFIG_ERR:
+ error = -EINVAL; /* Device not configured */
+ break;
+ case MC_CMD_STATUS_TIMEOUT:
+ error = -ETIMEDOUT; /* Operation timed out */
+ break;
+ case MC_CMD_STATUS_NO_RESOURCE:
+ error = -ENAVAIL; /* Resource temporarily unavailable */
+ break;
+ case MC_CMD_STATUS_NO_MEMORY:
+ error = -ENOMEM; /* Cannot allocate memory */
+ break;
+ case MC_CMD_STATUS_BUSY:
+ error = -EBUSY; /* Device busy */
+ break;
+ case MC_CMD_STATUS_UNSUPPORTED_OP:
+ error = -EINVAL; /* Operation not supported by device */
+ break;
+ case MC_CMD_STATUS_INVALID_STATE:
+ error = -ENODEV; /* Invalid device state */
+ break;
+ default:
+ error = -EINVAL;
+ }
+
+out:
+ return error;
+}
@@ -5,7 +5,7 @@
*/
#include <errno.h>
#include <asm/io.h>
-#include <fsl_mc.h>
+#include <layerscape/fsl_mc.h>
DECLARE_GLOBAL_DATA_PTR;
static int mc_boot_status;
similarity index 100%
rename from include/fsl_mc.h
rename to include/layerscape/fsl_mc.h
new file mode 100644
@@ -0,0 +1,19 @@
+/*
+ * Freescale Layerscape Management Complex (MC) dpmng command wrappers
+ *
+ * Copyright (C) 2014 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _FSL_MC_DPMNG_CMD_WRAPPERS_H
+#define _FSL_MC_DPMNG_CMD_WRAPPERS_H
+
+#include <layerscape/mc_hardware/fsl_mc_dpmng_commands.h>
+
+struct mc_portal_wrapper;
+
+int mc_get_version(struct mc_portal_wrapper *mc_portal,
+ struct mc_version *mc_ver_info);
+
+#endif /* _FSL_MC_DPMNG_CMD_WRAPPERS_H */
new file mode 100644
@@ -0,0 +1,25 @@
+/*
+ * Freescale Layerscape Management Complex (MC) I/O wrapper
+ *
+ * Copyright (C) 2014 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _FSL_MC_IO_WRAPPER_H
+#define _FSL_MC_IO_WRAPPER_H
+
+#include <asm/io.h>
+
+/*
+ * struct mc_portal_wrapper - MC command portal wrapper object
+ */
+struct mc_portal_wrapper {
+ struct mc_command __iomem *mmio_regs;
+};
+
+int __must_check mc_portal_wrapper_send_command(struct mc_portal_wrapper
+ *mc_portal,
+ struct mc_command *cmd);
+
+#endif /* _FSL_MC_IO_WRAPPER_H */
Management Complex wrapper functions are built upon the Management Complex hardware interface. These wrapper functions are OS dependent, which vary in U-boot and Linux. Current patch supports MC portal flib version 0.4. Signed-off-by: Lijun Pan <Lijun.Pan@freescale.com> --- arch/arm/cpu/armv8/fsl-lsch3/cpu.c | 2 +- board/freescale/ls2085a/ls2085a.c | 2 +- drivers/net/fsl_mc/Makefile | 4 +- drivers/net/fsl_mc/fsl_mc_dpmng_cmd_wrappers.c | 29 +++++++++ drivers/net/fsl_mc/fsl_mc_io_wrapper.c | 89 ++++++++++++++++++++++++++ drivers/net/fsl_mc/mc.c | 2 +- include/{ => layerscape}/fsl_mc.h | 0 include/layerscape/fsl_mc_dpmng_cmd_wrappers.h | 19 ++++++ include/layerscape/fsl_mc_io_wrapper.h | 25 ++++++++ 9 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 drivers/net/fsl_mc/fsl_mc_dpmng_cmd_wrappers.c create mode 100644 drivers/net/fsl_mc/fsl_mc_io_wrapper.c rename include/{ => layerscape}/fsl_mc.h (100%) create mode 100644 include/layerscape/fsl_mc_dpmng_cmd_wrappers.h create mode 100644 include/layerscape/fsl_mc_io_wrapper.h