Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support response with status not at first word #256

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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