net: e1000: Fix build warnings for 32-bit
[oweals/u-boot.git] / drivers / net / fsl-mc / mc.c
index 2b38b50a9d5b52d6cb6a8bb71088ccb0192c1e17..ea987d79ddaaa777320de7539ef68a471e0e7984 100644 (file)
@@ -3,8 +3,11 @@
  *
  * SPDX-License-Identifier:    GPL-2.0+
  */
+#include <common.h>
 #include <errno.h>
 #include <asm/io.h>
+#include <libfdt.h>
+#include <fdt_support.h>
 #include <fsl-mc/fsl_mc.h>
 #include <fsl-mc/fsl_mc_sys.h>
 #include <fsl-mc/fsl_mc_private.h>
@@ -185,6 +188,36 @@ static int calculate_mc_private_ram_params(u64 mc_private_ram_start_addr,
        return 0;
 }
 
+static int mc_fixup_dpc(u64 dpc_addr)
+{
+       void *blob = (void *)dpc_addr;
+       int nodeoffset;
+
+       /* delete any existing ICID pools */
+       nodeoffset = fdt_path_offset(blob, "/resources/icid_pools");
+       if (fdt_del_node(blob, nodeoffset) < 0)
+               printf("\nfsl-mc: WARNING: could not delete ICID pool\n");
+
+       /* add a new pool */
+       nodeoffset = fdt_path_offset(blob, "/resources");
+       if (nodeoffset < 0) {
+               printf("\nfsl-mc: ERROR: DPC is missing /resources\n");
+               return -EINVAL;
+       }
+       nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools");
+       nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0");
+       do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
+                            "base_icid", FSL_DPAA2_STREAM_ID_START, 1);
+       do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
+                            "num",
+                            FSL_DPAA2_STREAM_ID_END -
+                            FSL_DPAA2_STREAM_ID_START + 1, 1);
+
+       flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob));
+
+       return 0;
+}
+
 static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size)
 {
        u64 mc_dpc_offset;
@@ -239,6 +272,9 @@ static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size)
                      (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset);
 #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
 
+       if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset))
+               return -EINVAL;
+
        dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset));
        return 0;
 }
@@ -474,7 +510,7 @@ int mc_init(void)
        out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr);
        out_le32(&mc_ccsr_regs->reg_mcfbahr,
                 (u32)(mc_ram_aligned_base_addr >> 32));
-       out_le32(&mc_ccsr_regs->reg_mcfapr, MCFAPR_BYPASS_ICID_MASK);
+       out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ);
 
        /*
         * Tell the MC that we want delayed DPL deployment.
@@ -511,16 +547,21 @@ int mc_init(void)
        debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n",
              portal_id, dflt_mc_io->mmio_regs);
 
-       error = mc_get_version(dflt_mc_io, &mc_ver_info);
+       error = mc_get_version(dflt_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info);
        if (error != 0) {
                printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
                       error);
                goto out;
        }
 
-       if (MC_VER_MAJOR != mc_ver_info.major)
+       if (MC_VER_MAJOR != mc_ver_info.major) {
                printf("fsl-mc: ERROR: Firmware major version mismatch (found: %d, expected: %d)\n",
                       mc_ver_info.major, MC_VER_MAJOR);
+               printf("fsl-mc: Update the Management Complex firmware\n");
+
+               error = -ENODEV;
+               goto out;
+       }
 
        if (MC_VER_MINOR != mc_ver_info.minor)
                printf("fsl-mc: WARNING: Firmware minor version mismatch (found: %d, expected: %d)\n",
@@ -541,7 +582,7 @@ int mc_init(void)
 
 out:
        if (error != 0)
-               mc_boot_status = -error;
+               mc_boot_status = error;
        else
                mc_boot_status = 0;
 
@@ -593,31 +634,35 @@ int dpio_init(struct dprc_obj_desc obj_desc)
 
        dflt_dpio->dpio_id = obj_desc.id;
 
-       err = dpio_open(dflt_mc_io, obj_desc.id, &dflt_dpio_handle);
+       err = dpio_open(dflt_mc_io, MC_CMD_NO_FLAGS, obj_desc.id,
+                       &dflt_dpio_handle);
        if (err) {
                printf("dpio_open() failed\n");
                goto err_open;
        }
 
-       err = dpio_get_attributes(dflt_mc_io, dflt_dpio_handle, &attr);
+       err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
+                                 dflt_dpio_handle, &attr);
        if (err) {
                printf("dpio_get_attributes() failed %d\n", err);
                goto err_get_attr;
        }
 
-       err = dpio_enable(dflt_mc_io, dflt_dpio_handle);
+       err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio_handle);
        if (err) {
                printf("dpio_enable() failed %d\n", err);
                goto err_get_enable;
        }
-       debug("ce_paddr=0x%llx, ci_paddr=0x%llx, portalid=%d, prios=%d\n",
-             attr.qbman_portal_ce_paddr,
-             attr.qbman_portal_ci_paddr,
+       debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
+             attr.qbman_portal_ce_offset,
+             attr.qbman_portal_ci_offset,
              attr.qbman_portal_id,
              attr.num_priorities);
 
-       p_des.cena_bar = (void *)attr.qbman_portal_ce_paddr;
-       p_des.cinh_bar = (void *)attr.qbman_portal_ci_paddr;
+       p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
+                                       + attr.qbman_portal_ce_offset);
+       p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
+                                       + attr.qbman_portal_ci_offset);
 
        dflt_dpio->sw_portal = qbman_swp_init(&p_des);
        if (dflt_dpio->sw_portal == NULL) {
@@ -628,9 +673,9 @@ int dpio_init(struct dprc_obj_desc obj_desc)
 
 err_get_swp_init:
 err_get_enable:
-       dpio_disable(dflt_mc_io, dflt_dpio_handle);
+       dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio_handle);
 err_get_attr:
-       dpio_close(dflt_mc_io, dflt_dpio_handle);
+       dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio_handle);
 err_open:
        free(dflt_dpio);
        return err;
@@ -667,8 +712,9 @@ int dprc_init_container_obj(struct dprc_obj_desc obj_desc, uint16_t dprc_handle)
        } else if (!strcmp(obj_desc.type, "dpni")) {
                strcpy(dpni_endpoint.type, obj_desc.type);
                dpni_endpoint.id = obj_desc.id;
-               error = dprc_get_connection(dflt_mc_io, dprc_handle,
-                                    &dpni_endpoint, &dpmac_endpoint, &state);
+               error = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
+                                           dprc_handle, &dpni_endpoint,
+                                           &dpmac_endpoint, &state);
                if (!strcmp(dpmac_endpoint.type, "dpmac"))
                        error = ldpaa_eth_init(obj_desc);
                if (error < 0)
@@ -685,7 +731,7 @@ int dprc_scan_container_obj(uint16_t dprc_handle, char *obj_type, int i)
 
        memset((void *)&obj_desc, 0x00, sizeof(struct dprc_obj_desc));
 
-       error = dprc_get_obj(dflt_mc_io, dprc_handle,
+       error = dprc_get_obj(dflt_mc_io, MC_CMD_NO_FLAGS, dprc_handle,
                             i, &obj_desc);
        if (error < 0) {
                printf("dprc_get_obj(i=%d) failed: %d\n",
@@ -718,7 +764,8 @@ int fsl_mc_ldpaa_init(bd_t *bis)
        if (error < 0)
                goto error;
 
-       error = dprc_get_container_id(dflt_mc_io, &container_id);
+       error = dprc_get_container_id(dflt_mc_io, MC_CMD_NO_FLAGS,
+                                     &container_id);
        if (error < 0) {
                printf("dprc_get_container_id() failed: %d\n", error);
                goto error;
@@ -726,7 +773,8 @@ int fsl_mc_ldpaa_init(bd_t *bis)
 
        debug("fsl-mc: Container id=0x%x\n", container_id);
 
-       error = dprc_open(dflt_mc_io, container_id, &dflt_dprc_handle);
+       error = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, container_id,
+                         &dflt_dprc_handle);
        if (error < 0) {
                printf("dprc_open() failed: %d\n", error);
                goto error;
@@ -734,7 +782,7 @@ int fsl_mc_ldpaa_init(bd_t *bis)
        dprc_opened = true;
 
        error = dprc_get_obj_count(dflt_mc_io,
-                                  dflt_dprc_handle,
+                                  MC_CMD_NO_FLAGS, dflt_dprc_handle,
                                   &num_child_objects);
        if (error < 0) {
                printf("dprc_get_obj_count() failed: %d\n", error);
@@ -761,7 +809,7 @@ int fsl_mc_ldpaa_init(bd_t *bis)
        }
 error:
        if (dprc_opened)
-               dprc_close(dflt_mc_io, dflt_dprc_handle);
+               dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
 
        return error;
 }
@@ -771,17 +819,20 @@ void fsl_mc_ldpaa_exit(bd_t *bis)
        int err;
 
        if (get_mc_boot_status() == 0) {
-               err = dpio_disable(dflt_mc_io, dflt_dpio_handle);
+               err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS,
+                                  dflt_dpio_handle);
                if (err < 0) {
                        printf("dpio_disable() failed: %d\n", err);
                        return;
                }
-               err = dpio_reset(dflt_mc_io, dflt_dpio_handle);
+               err = dpio_reset(dflt_mc_io, MC_CMD_NO_FLAGS,
+                                dflt_dpio_handle);
                if (err < 0) {
                        printf("dpio_reset() failed: %d\n", err);
                        return;
                }
-               err = dpio_close(dflt_mc_io, dflt_dpio_handle);
+               err = dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS,
+                                dflt_dpio_handle);
                if (err < 0) {
                        printf("dpio_close() failed: %d\n", err);
                        return;