diff --git a/sys/dev/dpaa2/dpaa2_rc.c b/sys/dev/dpaa2/dpaa2_rc.c --- a/sys/dev/dpaa2/dpaa2_rc.c +++ b/sys/dev/dpaa2/dpaa2_rc.c @@ -706,11 +706,12 @@ if (portal == NULL || cmd == NULL || token == NULL) return (DPAA2_CMD_STAT_ERR); + hdr = (struct dpaa2_cmd_header *) &cmd->header; + hdr->token = 0; cmd->params[0] = cont_id; error = dpaa2_rc_exec_cmd(portal, cmd, CMDID_RC_OPEN); if (!error) { - hdr = (struct dpaa2_cmd_header *) &cmd->header; *token = hdr->token; } @@ -1083,10 +1084,11 @@ if (portal == NULL || cmd == NULL || token == NULL) return (DPAA2_CMD_STAT_ERR); + hdr = (struct dpaa2_cmd_header *) &cmd->header; + hdr->token = 0; cmd->params[0] = dpni_id; error = dpaa2_rc_exec_cmd(portal, cmd, CMDID_NI_OPEN); if (!error) { - hdr = (struct dpaa2_cmd_header *) &cmd->header; *token = hdr->token; } @@ -1957,10 +1959,11 @@ if (portal == NULL || cmd == NULL || token == NULL) return (DPAA2_CMD_STAT_ERR); + hdr = (struct dpaa2_cmd_header *) &cmd->header; + hdr->token = 0; cmd->params[0] = dpio_id; error = dpaa2_rc_exec_cmd(portal, cmd, CMDID_IO_OPEN); if (!error) { - hdr = (struct dpaa2_cmd_header *) &cmd->header; *token = hdr->token; } @@ -2171,10 +2174,11 @@ if (portal == NULL || cmd == NULL || token == NULL) return (DPAA2_CMD_STAT_ERR); + hdr = (struct dpaa2_cmd_header *) &cmd->header; + hdr->token = 0; cmd->params[0] = dpbp_id; error = dpaa2_rc_exec_cmd(portal, cmd, CMDID_BP_OPEN); if (!error) { - hdr = (struct dpaa2_cmd_header *) &cmd->header; *token = hdr->token; } @@ -2261,10 +2265,11 @@ if (portal == NULL || cmd == NULL || token == NULL) return (DPAA2_CMD_STAT_ERR); + hdr = (struct dpaa2_cmd_header *) &cmd->header; + hdr->token = 0; cmd->params[0] = dpmac_id; error = dpaa2_rc_exec_cmd(portal, cmd, CMDID_MAC_OPEN); if (!error) { - hdr = (struct dpaa2_cmd_header *) &cmd->header; *token = hdr->token; } @@ -2537,10 +2542,11 @@ if (portal == NULL || cmd == NULL || token == NULL) return (DPAA2_CMD_STAT_ERR); + hdr = (struct dpaa2_cmd_header *) &cmd->header; + hdr->token = 0; cmd->params[0] = dpcon_id; error = dpaa2_rc_exec_cmd(portal, cmd, CMDID_CON_OPEN); if (!error) { - hdr = (struct dpaa2_cmd_header *) &cmd->header; *token = hdr->token; } @@ -2705,10 +2711,11 @@ if (portal == NULL || cmd == NULL || token == NULL) return (DPAA2_CMD_STAT_ERR); + hdr = (struct dpaa2_cmd_header *) &cmd->header; + hdr->token = 0; cmd->params[0] = dpmcp_id; error = dpaa2_rc_exec_cmd(portal, cmd, CMDID_MCP_OPEN); if (!error) { - hdr = (struct dpaa2_cmd_header *) &cmd->header; *token = hdr->token; } @@ -3244,13 +3251,13 @@ /* Send a command to MC and wait for the result. */ dpaa2_rc_send_cmd(mcp, cmd); error = dpaa2_rc_wait_for_cmd(mcp, cmd); - if (error) { + if (error != DPAA2_CMD_STAT_OK) { DPAA2_MCP_UNLOCK(mcp); - return (DPAA2_CMD_STAT_ERR); + return (error); } if (hdr->status != DPAA2_CMD_STAT_OK) { DPAA2_MCP_UNLOCK(mcp); - return (int)(hdr->status); + return (hdr->status); } DPAA2_MCP_UNLOCK(mcp); @@ -3264,6 +3271,7 @@ static int dpaa2_rc_send_cmd(struct dpaa2_mcp *mcp, struct dpaa2_cmd *cmd) { + /* Write command parameters. */ for (uint32_t i = 1; i <= DPAA2_CMD_PARAMS_N; i++) bus_write_8(mcp->map, sizeof(uint64_t) * i, cmd->params[i-1]); @@ -3284,15 +3292,19 @@ static int dpaa2_rc_wait_for_cmd(struct dpaa2_mcp *mcp, struct dpaa2_cmd *cmd) { - struct dpaa2_cmd_header *hdr; + struct dpaa2_cmd_header *hdr, *chdr; uint64_t val; uint32_t i; + chdr = (struct dpaa2_cmd_header *)&cmd->header; + /* Wait for a command execution result from the MC hardware. */ for (i = 1; i <= CMD_SPIN_ATTEMPTS; i++) { val = bus_read_8(mcp->map, 0); hdr = (struct dpaa2_cmd_header *) &val; - if (hdr->status != DPAA2_CMD_STAT_READY) { + if ((hdr->token == chdr->token || chdr->token == 0) && + hdr->cmdid == chdr->cmdid && + hdr->status != DPAA2_CMD_STAT_READY) { break; } DELAY(CMD_SPIN_TIMEOUT);