Commit a389d016 authored by Lang Cheng's avatar Lang Cheng Committed by Jason Gunthorpe

RDMA/hns: Enable all CMDQ context

Fix error of cmd's context number calculation algorithm to enable all of
32 cmd entries and support 32 concurrent accesses.

Link: https://lore.kernel.org/r/1617262341-37571-2-git-send-email-liweihang@huawei.comSigned-off-by: default avatarLang Cheng <chenglang@huawei.com>
Signed-off-by: default avatarWeihang Li <liweihang@huawei.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent ea492251
...@@ -38,22 +38,14 @@ ...@@ -38,22 +38,14 @@
#define CMD_POLL_TOKEN 0xffff #define CMD_POLL_TOKEN 0xffff
#define CMD_MAX_NUM 32 #define CMD_MAX_NUM 32
#define CMD_TOKEN_MASK 0x1f
static int hns_roce_cmd_mbox_post_hw(struct hns_roce_dev *hr_dev, u64 in_param, static int hns_roce_cmd_mbox_post_hw(struct hns_roce_dev *hr_dev, u64 in_param,
u64 out_param, u32 in_modifier, u64 out_param, u32 in_modifier,
u8 op_modifier, u16 op, u16 token, u8 op_modifier, u16 op, u16 token,
int event) int event)
{ {
struct hns_roce_cmdq *cmd = &hr_dev->cmd; return hr_dev->hw->post_mbox(hr_dev, in_param, out_param, in_modifier,
int ret; op_modifier, op, token, event);
mutex_lock(&cmd->hcr_mutex);
ret = hr_dev->hw->post_mbox(hr_dev, in_param, out_param, in_modifier,
op_modifier, op, token, event);
mutex_unlock(&cmd->hcr_mutex);
return ret;
} }
/* this should be called with "poll_sem" */ /* this should be called with "poll_sem" */
...@@ -96,15 +88,18 @@ void hns_roce_cmd_event(struct hns_roce_dev *hr_dev, u16 token, u8 status, ...@@ -96,15 +88,18 @@ void hns_roce_cmd_event(struct hns_roce_dev *hr_dev, u16 token, u8 status,
struct hns_roce_cmd_context *context = struct hns_roce_cmd_context *context =
&hr_dev->cmd.context[token % hr_dev->cmd.max_cmds]; &hr_dev->cmd.context[token % hr_dev->cmd.max_cmds];
if (token != context->token) if (unlikely(token != context->token)) {
dev_err_ratelimited(hr_dev->dev,
"[cmd] invalid ae token %x,context token is %x!\n",
token, context->token);
return; return;
}
context->result = (status == HNS_ROCE_CMD_SUCCESS) ? 0 : (-EIO); context->result = (status == HNS_ROCE_CMD_SUCCESS) ? 0 : (-EIO);
context->out_param = out_param; context->out_param = out_param;
complete(&context->done); complete(&context->done);
} }
/* this should be called with "use_events" */
static int __hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, u64 in_param, static int __hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, u64 in_param,
u64 out_param, unsigned long in_modifier, u64 out_param, unsigned long in_modifier,
u8 op_modifier, u16 op, u8 op_modifier, u16 op,
...@@ -116,13 +111,18 @@ static int __hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, u64 in_param, ...@@ -116,13 +111,18 @@ static int __hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, u64 in_param,
int ret; int ret;
spin_lock(&cmd->context_lock); spin_lock(&cmd->context_lock);
WARN_ON(cmd->free_head < 0);
context = &cmd->context[cmd->free_head]; do {
context->token += cmd->token_mask + 1; context = &cmd->context[cmd->free_head];
cmd->free_head = context->next; cmd->free_head = context->next;
} while (context->busy);
context->busy = 1;
context->token += cmd->max_cmds;
spin_unlock(&cmd->context_lock); spin_unlock(&cmd->context_lock);
init_completion(&context->done); reinit_completion(&context->done);
ret = hns_roce_cmd_mbox_post_hw(hr_dev, in_param, out_param, ret = hns_roce_cmd_mbox_post_hw(hr_dev, in_param, out_param,
in_modifier, op_modifier, op, in_modifier, op_modifier, op,
...@@ -130,30 +130,19 @@ static int __hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, u64 in_param, ...@@ -130,30 +130,19 @@ static int __hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, u64 in_param,
if (ret) if (ret)
goto out; goto out;
/*
* It is timeout when wait_for_completion_timeout return 0
* The return value is the time limit set in advance
* how many seconds showing
*/
if (!wait_for_completion_timeout(&context->done, if (!wait_for_completion_timeout(&context->done,
msecs_to_jiffies(timeout))) { msecs_to_jiffies(timeout))) {
dev_err(dev, "[cmd]wait_for_completion_timeout timeout\n"); dev_err(dev, "[cmd] token %x timeout, drop.\n", context->token);
ret = -EBUSY; ret = -EBUSY;
goto out; goto out;
} }
ret = context->result; ret = context->result;
if (ret) { if (ret)
dev_err(dev, "[cmd]event mod cmd process error!err=%d\n", ret); dev_err(dev, "[cmd] token %x error %d\n", context->token, ret);
goto out;
}
out: out:
spin_lock(&cmd->context_lock); context->busy = 0;
context->next = cmd->free_head;
cmd->free_head = context - cmd->context;
spin_unlock(&cmd->context_lock);
return ret; return ret;
} }
...@@ -195,7 +184,6 @@ int hns_roce_cmd_init(struct hns_roce_dev *hr_dev) ...@@ -195,7 +184,6 @@ int hns_roce_cmd_init(struct hns_roce_dev *hr_dev)
{ {
struct device *dev = hr_dev->dev; struct device *dev = hr_dev->dev;
mutex_init(&hr_dev->cmd.hcr_mutex);
sema_init(&hr_dev->cmd.poll_sem, 1); sema_init(&hr_dev->cmd.poll_sem, 1);
hr_dev->cmd.use_events = 0; hr_dev->cmd.use_events = 0;
hr_dev->cmd.max_cmds = CMD_MAX_NUM; hr_dev->cmd.max_cmds = CMD_MAX_NUM;
...@@ -226,16 +214,16 @@ int hns_roce_cmd_use_events(struct hns_roce_dev *hr_dev) ...@@ -226,16 +214,16 @@ int hns_roce_cmd_use_events(struct hns_roce_dev *hr_dev)
for (i = 0; i < hr_cmd->max_cmds; ++i) { for (i = 0; i < hr_cmd->max_cmds; ++i) {
hr_cmd->context[i].token = i; hr_cmd->context[i].token = i;
hr_cmd->context[i].next = i + 1; hr_cmd->context[i].next = i + 1;
init_completion(&hr_cmd->context[i].done);
} }
hr_cmd->context[hr_cmd->max_cmds - 1].next = 0;
hr_cmd->context[hr_cmd->max_cmds - 1].next = -1;
hr_cmd->free_head = 0; hr_cmd->free_head = 0;
sema_init(&hr_cmd->event_sem, hr_cmd->max_cmds); sema_init(&hr_cmd->event_sem, hr_cmd->max_cmds);
spin_lock_init(&hr_cmd->context_lock); spin_lock_init(&hr_cmd->context_lock);
hr_cmd->token_mask = CMD_TOKEN_MASK;
hr_cmd->use_events = 1; hr_cmd->use_events = 1;
down(&hr_cmd->poll_sem);
return 0; return 0;
} }
...@@ -246,6 +234,8 @@ void hns_roce_cmd_use_polling(struct hns_roce_dev *hr_dev) ...@@ -246,6 +234,8 @@ void hns_roce_cmd_use_polling(struct hns_roce_dev *hr_dev)
kfree(hr_cmd->context); kfree(hr_cmd->context);
hr_cmd->use_events = 0; hr_cmd->use_events = 0;
up(&hr_cmd->poll_sem);
} }
struct hns_roce_cmd_mailbox * struct hns_roce_cmd_mailbox *
......
...@@ -550,6 +550,7 @@ struct hns_roce_cmd_context { ...@@ -550,6 +550,7 @@ struct hns_roce_cmd_context {
int next; int next;
u64 out_param; u64 out_param;
u16 token; u16 token;
u16 busy;
}; };
struct hns_roce_cmdq { struct hns_roce_cmdq {
...@@ -565,11 +566,6 @@ struct hns_roce_cmdq { ...@@ -565,11 +566,6 @@ struct hns_roce_cmdq {
spinlock_t context_lock; spinlock_t context_lock;
int free_head; int free_head;
struct hns_roce_cmd_context *context; struct hns_roce_cmd_context *context;
/*
* Result of get integer part
* which max_comds compute according a power of 2
*/
u16 token_mask;
/* /*
* Process whether use event mode, init default non-zero * Process whether use event mode, init default non-zero
* After the event queue of cmd event ready, * After the event queue of cmd event ready,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment