Skip to content

Commit

Permalink
support response with status not at first word (#256)
Browse files Browse the repository at this point in the history
Signed-off-by: Min Ma <min.ma@amd.com>
  • Loading branch information
mamin506 authored Sep 14, 2024
1 parent f158f2e commit 136c6d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 34 deletions.
43 changes: 9 additions & 34 deletions src/driver/amdxdna/aie2_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
#define DECLARE_AIE2_MSG(name, op) \
DECLARE_XDNA_MSG_COMMON(name, op, MAX_AIE2_STATUS_CODE)

static int aie2_send_mgmt_msg_wait(struct amdxdna_dev_hdl *ndev,
struct xdna_mailbox_msg *msg)
#define aie2_send_mgmt_msg_wait(ndev, msg) \
aie2_send_mgmt_msg_wait_offset(ndev, msg, 0)

static int
aie2_send_mgmt_msg_wait_offset(struct amdxdna_dev_hdl *ndev,
struct xdna_mailbox_msg *msg,
u32 offset)
{
struct amdxdna_dev *xdna = ndev->xdna;
struct xdna_notify *hdl = msg->handle;
Expand All @@ -34,7 +39,7 @@ static int aie2_send_mgmt_msg_wait(struct amdxdna_dev_hdl *ndev,
ndev->mgmt_chann = NULL;
}

if (!ret && *hdl->data != AIE2_STATUS_SUCCESS) {
if (!ret && hdl->data[offset] != AIE2_STATUS_SUCCESS) {
XDNA_ERR(xdna, "command opcode 0x%x failed, status 0x%x",
msg->opcode, *hdl->data);
ret = -EINVAL;
Expand Down Expand Up @@ -105,36 +110,6 @@ int aie2_check_protocol_version(struct amdxdna_dev_hdl *ndev)
}

#ifdef AMDXDNA_DEVEL
/* TODO: Delete this. move status to the first word of struct get_telemetry_resp */
static int aie2_send_mgmt_msg_wait_for_telemetry(struct amdxdna_dev_hdl *ndev,
struct xdna_mailbox_msg *msg)
{
struct amdxdna_dev *xdna = ndev->xdna;
struct xdna_notify *hdl = msg->handle;
struct get_telemetry_resp *resp;
int ret;

if (!ndev->mgmt_chann)
return -ENODEV;

drm_WARN_ON(&xdna->ddev, !mutex_is_locked(&xdna->dev_lock));
ret = xdna_send_msg_wait(xdna, ndev->mgmt_chann, msg);
if (ret == -ETIME) {
xdna_mailbox_stop_channel(ndev->mgmt_chann);
xdna_mailbox_destroy_channel(ndev->mgmt_chann);
ndev->mgmt_chann = NULL;
}

resp = (struct get_telemetry_resp *)hdl->data;
if (!ret && resp->status != AIE2_STATUS_SUCCESS) {
XDNA_ERR(xdna, "command opcode 0x%x failed, status 0x%x",
msg->opcode, resp->status);
ret = -EINVAL;
}

return ret;
}

int aie2_get_telemetry(struct amdxdna_dev_hdl *ndev, u32 type, dma_addr_t addr, u32 size)
{
DECLARE_AIE2_MSG(get_telemetry, MSG_OP_GET_TELEMETRY);
Expand All @@ -150,7 +125,7 @@ int aie2_get_telemetry(struct amdxdna_dev_hdl *ndev, u32 type, dma_addr_t addr,
req.buf_size = size;
req.type = type;

ret = aie2_send_mgmt_msg_wait_for_telemetry(ndev, &msg);
ret = aie2_send_mgmt_msg_wait_offset(ndev, &msg, XDNA_STATUS_OFFSET(get_telemetry));
if (ret) {
XDNA_ERR(xdna, "Failed to get telemetry, ret %d", ret);
return ret;
Expand Down
2 changes: 2 additions & 0 deletions src/driver/amdxdna/amdxdna_mailbox_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ struct xdna_notify {
.notify_cb = xdna_msg_cb, \
}

#define XDNA_STATUS_OFFSET(name) (offsetof(struct name##_resp, status) / sizeof(u32))

int xdna_msg_cb(void *handle, const u32 *data, size_t size);
int xdna_send_msg_wait(struct amdxdna_dev *xdna, struct mailbox_channel *chann,
struct xdna_mailbox_msg *msg);
Expand Down

0 comments on commit 136c6d5

Please sign in to comment.