diff --git a/sys/dev/dpaa2/dpaa2_io.c b/sys/dev/dpaa2/dpaa2_io.c index e2b7992bfdb6ba..7bf41beb98eba1 100644 --- a/sys/dev/dpaa2/dpaa2_io.c +++ b/sys/dev/dpaa2/dpaa2_io.c @@ -127,35 +127,48 @@ dpaa2_io_probe(device_t dev) static int dpaa2_io_detach(device_t dev) { + device_t pdev = device_get_parent(dev); device_t child = dev; struct dpaa2_io_softc *sc = device_get_softc(dev); + struct dpaa2_devinfo *rcinfo = device_get_ivars(pdev); struct dpaa2_devinfo *dinfo = device_get_ivars(dev); + struct dpaa2_cmd cmd; + uint16_t rc_token; + uint16_t io_token __unused; int error; - /* Tear down interrupt handler and release IRQ resources. */ dpaa2_io_release_irqs(dev); - - /* Free software portal helper object. */ dpaa2_swp_free_portal(sc->swp); + error = dpaa2_mcp_init_command(&cmd, DPAA2_CMD_DEF); + if (error) { + device_printf(dev, "%s: failed to initialize dpaa2_cmd: " + "error=%d\n", __func__, error); + goto unmap_res; + } - /* Disable DPIO object. */ - error = DPAA2_CMD_IO_DISABLE(dev, child, dpaa2_mcp_tk(sc->cmd, - sc->io_token)); - if (error && bootverbose) + /* Disable DPIO object */ + + error = DPAA2_CMD_RC_OPEN(dev, child, &cmd, rcinfo->id, &rc_token); + if (error) { + device_printf(dev, "%s: failed to open DPRC: error=%d\n", + __func__, error); + goto unmap_res; + } + error = DPAA2_CMD_IO_OPEN(dev, child, &cmd, dinfo->id, &io_token); + if (error) { + device_printf(dev, "%s: failed to open DPIO: id=%d, error=%d\n", + __func__, dinfo->id, error); + goto unmap_res; + } + error = DPAA2_CMD_IO_DISABLE(dev, child, &cmd); + if (error && bootverbose) { device_printf(dev, "%s: failed to disable DPIO: id=%d, " "error=%d\n", __func__, dinfo->id, error); + } + DPAA2_CMD_IO_CLOSE(dev, child, &cmd); + DPAA2_CMD_RC_CLOSE(dev, child, dpaa2_mcp_tk(&cmd, rc_token)); - /* Close control sessions with the DPAA2 objects. */ - DPAA2_CMD_IO_CLOSE(dev, child, dpaa2_mcp_tk(sc->cmd, sc->io_token)); - DPAA2_CMD_RC_CLOSE(dev, child, dpaa2_mcp_tk(sc->cmd, sc->rc_token)); - - /* Free pre-allocated MC command. */ - dpaa2_mcp_free_command(sc->cmd); - sc->cmd = NULL; - sc->io_token = 0; - sc->rc_token = 0; - - /* Unmap memory resources of the portal. */ +unmap_res: for (int i = 0; i < MEM_RES_NUM; i++) { if (sc->res[MEM_RID(i)] == NULL) continue; @@ -166,8 +179,6 @@ dpaa2_io_detach(device_t dev) "resource: rid=%d, error=%d\n", __func__, MEM_RID(i), error); } - - /* Release allocated resources. */ bus_release_resources(dev, dpaa2_io_spec, sc->res); return (0); @@ -183,6 +194,7 @@ dpaa2_io_attach(device_t dev) struct dpaa2_devinfo *rcinfo = device_get_ivars(pdev); struct dpaa2_devinfo *dinfo = device_get_ivars(dev); struct dpaa2_devinfo *mcp_dinfo; + struct dpaa2_cmd cmd; struct resource_map_request req; struct { vm_memattr_t memattr; @@ -192,15 +204,15 @@ dpaa2_io_attach(device_t dev) { VM_MEMATTR_DEVICE, "cache-inhibited part" }, { VM_MEMATTR_DEVICE, "control registers" } }; + uint16_t rc_token; + uint16_t io_token __unused; int error; sc->dev = dev; sc->swp = NULL; - sc->cmd = NULL; sc->intr = NULL; sc->irq_resource = NULL; - /* Allocate resources. */ error = bus_alloc_resources(sc->dev, dpaa2_io_spec, sc->res); if (error) { device_printf(dev, "%s: failed to allocate resources: " @@ -208,16 +220,14 @@ dpaa2_io_attach(device_t dev) return (ENXIO); } - /* Set allocated MC portal up. */ + /* Setup allocated MC portal */ mcp_dev = (device_t) rman_get_start(sc->res[MCP_RID(0)]); mcp_dinfo = device_get_ivars(mcp_dev); dinfo->portal = mcp_dinfo->portal; - /* Map memory resources of the portal. */ for (int i = 0; i < MEM_RES_NUM; i++) { if (sc->res[MEM_RID(i)] == NULL) continue; - resource_init_map_request(&req); req.memattr = map_args[i].memattr; error = bus_map_resource(sc->dev, SYS_RES_MEMORY, @@ -229,46 +239,47 @@ dpaa2_io_attach(device_t dev) } } - /* Allocate a command to send to the MC hardware. */ - error = dpaa2_mcp_init_command(&sc->cmd, DPAA2_CMD_DEF); + error = dpaa2_mcp_init_command(&cmd, DPAA2_CMD_DEF); if (error) { - device_printf(dev, "%s: failed to allocate dpaa2_cmd: " + device_printf(dev, "%s: failed to initialize dpaa2_cmd: " "error=%d\n", __func__, error); goto err_exit; } - /* Prepare DPIO object. */ - error = DPAA2_CMD_RC_OPEN(dev, child, sc->cmd, rcinfo->id, - &sc->rc_token); + /* Enable DPIO object */ + + error = DPAA2_CMD_RC_OPEN(dev, child, &cmd, rcinfo->id, &rc_token); if (error) { device_printf(dev, "%s: failed to open DPRC: error=%d\n", __func__, error); goto err_exit; } - error = DPAA2_CMD_IO_OPEN(dev, child, sc->cmd, dinfo->id, &sc->io_token); + error = DPAA2_CMD_IO_OPEN(dev, child, &cmd, dinfo->id, &io_token); if (error) { device_printf(dev, "%s: failed to open DPIO: id=%d, error=%d\n", __func__, dinfo->id, error); goto err_exit; } - error = DPAA2_CMD_IO_RESET(dev, child, sc->cmd); + error = DPAA2_CMD_IO_RESET(dev, child, &cmd); if (error) { device_printf(dev, "%s: failed to reset DPIO: id=%d, error=%d\n", __func__, dinfo->id, error); goto err_exit; } - error = DPAA2_CMD_IO_GET_ATTRIBUTES(dev, child, sc->cmd, &sc->attr); + error = DPAA2_CMD_IO_GET_ATTRIBUTES(dev, child, &cmd, &sc->attr); if (error) { device_printf(dev, "%s: failed to get DPIO attributes: id=%d, " "error=%d\n", __func__, dinfo->id, error); goto err_exit; } - error = DPAA2_CMD_IO_ENABLE(dev, child, sc->cmd); + error = DPAA2_CMD_IO_ENABLE(dev, child, &cmd); if (error) { device_printf(dev, "%s: failed to enable DPIO: id=%d, " "error=%d\n", __func__, dinfo->id, error); goto err_exit; } + DPAA2_CMD_IO_CLOSE(dev, child, &cmd); + DPAA2_CMD_RC_CLOSE(dev, child, dpaa2_mcp_tk(&cmd, rc_token)); /* Prepare descriptor of the QBMan software portal. */ sc->swp_desc.dpio_dev = dev; @@ -291,7 +302,6 @@ dpaa2_io_attach(device_t dev) sc->swp_desc.swp_cycles_ratio = 256000 / (sc->swp_desc.swp_clk / 1000000); - /* Initialize QBMan software portal. */ error = dpaa2_swp_init_portal(&sc->swp, &sc->swp_desc, DPAA2_SWP_DEF); if (error) { device_printf(dev, "%s: failed to initialize dpaa2_swp: " @@ -306,8 +316,6 @@ dpaa2_io_attach(device_t dev) goto err_exit; } -#if 0 - /* TODO: Enable debug output via sysctl (to reduce output). */ if (bootverbose) device_printf(dev, "dpio_id=%d, swp_id=%d, chan_mode=%s, " "notif_priors=%d, swp_version=0x%x\n", @@ -315,7 +323,7 @@ dpaa2_io_attach(device_t dev) sc->attr.chan_mode == DPAA2_IO_LOCAL_CHANNEL ? "local_channel" : "no_channel", sc->attr.priors_num, sc->attr.swp_version); -#endif + return (0); err_exit: diff --git a/sys/dev/dpaa2/dpaa2_io.h b/sys/dev/dpaa2/dpaa2_io.h index d02dab8144df86..13def050fffb7f 100644 --- a/sys/dev/dpaa2/dpaa2_io.h +++ b/sys/dev/dpaa2/dpaa2_io.h @@ -92,11 +92,6 @@ struct dpaa2_io_softc { struct dpaa2_swp *swp; struct dpaa2_io_attr attr; - /* Help to send commands to MC. */ - struct dpaa2_cmd *cmd; - uint16_t rc_token; - uint16_t io_token; - struct resource *res[DPAA2_IO_MAX_RESOURCES]; struct resource_map map[DPAA2_IO_MAX_RESOURCES]; diff --git a/sys/dev/dpaa2/dpaa2_mcp.c b/sys/dev/dpaa2/dpaa2_mcp.c index f41d9a7d21b026..e6d22f149d163e 100644 --- a/sys/dev/dpaa2/dpaa2_mcp.c +++ b/sys/dev/dpaa2/dpaa2_mcp.c @@ -109,21 +109,14 @@ dpaa2_mcp_free_portal(struct dpaa2_mcp *mcp) } int -dpaa2_mcp_init_command(struct dpaa2_cmd **cmd, uint16_t flags) +dpaa2_mcp_init_command(struct dpaa2_cmd *cmd) { - const int mflags = flags & DPAA2_CMD_NOWAIT_ALLOC - ? (M_NOWAIT | M_ZERO) : (M_WAITOK | M_ZERO); - struct dpaa2_cmd *c; struct dpaa2_cmd_header *hdr; if (!cmd) return (DPAA2_CMD_STAT_EINVAL); - c = malloc(sizeof(struct dpaa2_cmd), M_DPAA2_MCP, mflags); - if (!c) - return (DPAA2_CMD_STAT_NO_MEMORY); - - hdr = (struct dpaa2_cmd_header *) &c->header; + hdr = (struct dpaa2_cmd_header *) cmd->header; hdr->srcid = 0; hdr->status = DPAA2_CMD_STAT_OK; hdr->token = 0; @@ -134,20 +127,13 @@ dpaa2_mcp_init_command(struct dpaa2_cmd **cmd, uint16_t flags) hdr->flags_hw |= DPAA2_HW_FLAG_HIGH_PRIO; if (flags & DPAA2_CMD_INTR_DIS) hdr->flags_sw |= DPAA2_SW_FLAG_INTR_DIS; + for (uint32_t i = 0; i < DPAA2_CMD_PARAMS_N; i++) - c->params[i] = 0; - *cmd = c; + cmd->params[i] = 0; return (0); } -void -dpaa2_mcp_free_command(struct dpaa2_cmd *cmd) -{ - if (cmd != NULL) - free(cmd, M_DPAA2_MCP); -} - struct dpaa2_cmd * dpaa2_mcp_tk(struct dpaa2_cmd *cmd, uint16_t token) { diff --git a/sys/dev/dpaa2/dpaa2_mcp.h b/sys/dev/dpaa2/dpaa2_mcp.h index 55052ca7afb21e..4aaa0658220c50 100644 --- a/sys/dev/dpaa2/dpaa2_mcp.h +++ b/sys/dev/dpaa2/dpaa2_mcp.h @@ -437,9 +437,8 @@ struct dpaa2_mcp_softc { int dpaa2_mcp_init_portal(struct dpaa2_mcp **mcp, struct resource *res, struct resource_map *map, uint16_t flags); -int dpaa2_mcp_init_command(struct dpaa2_cmd **cmd, uint16_t flags); +int dpaa2_mcp_init_command(struct dpaa2_cmd *cmd); void dpaa2_mcp_free_portal(struct dpaa2_mcp *mcp); -void dpaa2_mcp_free_command(struct dpaa2_cmd *cmd); /* to quickly update command token */ struct dpaa2_cmd *dpaa2_mcp_tk(struct dpaa2_cmd *cmd, uint16_t token);