forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/infiniband/hw/hns/hns_roce_cmd.c
....@@ -36,9 +36,9 @@
3636 #include "hns_roce_device.h"
3737 #include "hns_roce_cmd.h"
3838
39
-#define CMD_POLL_TOKEN 0xffff
40
-#define CMD_MAX_NUM 32
41
-#define CMD_TOKEN_MASK 0x1f
39
+#define CMD_POLL_TOKEN 0xffff
40
+#define CMD_MAX_NUM 32
41
+#define CMD_TOKEN_MASK 0x1f
4242
4343 static int hns_roce_cmd_mbox_post_hw(struct hns_roce_dev *hr_dev, u64 in_param,
4444 u64 out_param, u32 in_modifier,
....@@ -93,8 +93,8 @@
9393 void hns_roce_cmd_event(struct hns_roce_dev *hr_dev, u16 token, u8 status,
9494 u64 out_param)
9595 {
96
- struct hns_roce_cmd_context
97
- *context = &hr_dev->cmd.context[token & hr_dev->cmd.token_mask];
96
+ struct hns_roce_cmd_context *context =
97
+ &hr_dev->cmd.context[token % hr_dev->cmd.max_cmds];
9898
9999 if (token != context->token)
100100 return;
....@@ -103,7 +103,6 @@
103103 context->out_param = out_param;
104104 complete(&context->done);
105105 }
106
-EXPORT_SYMBOL_GPL(hns_roce_cmd_event);
107106
108107 /* this should be called with "use_events" */
109108 static int __hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, u64 in_param,
....@@ -162,11 +161,11 @@
162161 u64 out_param, unsigned long in_modifier,
163162 u8 op_modifier, u16 op, unsigned long timeout)
164163 {
165
- int ret = 0;
164
+ int ret;
166165
167166 down(&hr_dev->cmd.event_sem);
168
- ret = __hns_roce_cmd_mbox_wait(hr_dev, in_param, out_param,
169
- in_modifier, op_modifier, op, timeout);
167
+ ret = __hns_roce_cmd_mbox_wait(hr_dev, in_param, out_param, in_modifier,
168
+ op_modifier, op, timeout);
170169 up(&hr_dev->cmd.event_sem);
171170
172171 return ret;
....@@ -176,19 +175,34 @@
176175 unsigned long in_modifier, u8 op_modifier, u16 op,
177176 unsigned long timeout)
178177 {
179
- if (hr_dev->is_reset)
180
- return 0;
178
+ int ret;
179
+
180
+ if (hr_dev->hw->rst_prc_mbox) {
181
+ ret = hr_dev->hw->rst_prc_mbox(hr_dev);
182
+ if (ret == CMD_RST_PRC_SUCCESS)
183
+ return 0;
184
+ else if (ret == CMD_RST_PRC_EBUSY)
185
+ return -EBUSY;
186
+ }
181187
182188 if (hr_dev->cmd.use_events)
183
- return hns_roce_cmd_mbox_wait(hr_dev, in_param, out_param,
184
- in_modifier, op_modifier, op,
185
- timeout);
189
+ ret = hns_roce_cmd_mbox_wait(hr_dev, in_param, out_param,
190
+ in_modifier, op_modifier, op,
191
+ timeout);
186192 else
187
- return hns_roce_cmd_mbox_poll(hr_dev, in_param, out_param,
188
- in_modifier, op_modifier, op,
189
- timeout);
193
+ ret = hns_roce_cmd_mbox_poll(hr_dev, in_param, out_param,
194
+ in_modifier, op_modifier, op,
195
+ timeout);
196
+
197
+ if (ret == CMD_RST_PRC_EBUSY)
198
+ return -EBUSY;
199
+
200
+ if (ret && (hr_dev->hw->rst_prc_mbox &&
201
+ hr_dev->hw->rst_prc_mbox(hr_dev) == CMD_RST_PRC_SUCCESS))
202
+ return 0;
203
+
204
+ return ret;
190205 }
191
-EXPORT_SYMBOL_GPL(hns_roce_cmd_mbox);
192206
193207 int hns_roce_cmd_init(struct hns_roce_dev *hr_dev)
194208 {
....@@ -197,7 +211,6 @@
197211 mutex_init(&hr_dev->cmd.hcr_mutex);
198212 sema_init(&hr_dev->cmd.poll_sem, 1);
199213 hr_dev->cmd.use_events = 0;
200
- hr_dev->cmd.toggle = 1;
201214 hr_dev->cmd.max_cmds = CMD_MAX_NUM;
202215 hr_dev->cmd.pool = dma_pool_create("hns_roce_cmd", dev,
203216 HNS_ROCE_MAILBOX_SIZE,
....@@ -218,9 +231,8 @@
218231 struct hns_roce_cmdq *hr_cmd = &hr_dev->cmd;
219232 int i;
220233
221
- hr_cmd->context = kmalloc_array(hr_cmd->max_cmds,
222
- sizeof(*hr_cmd->context),
223
- GFP_KERNEL);
234
+ hr_cmd->context =
235
+ kcalloc(hr_cmd->max_cmds, sizeof(*hr_cmd->context), GFP_KERNEL);
224236 if (!hr_cmd->context)
225237 return -ENOMEM;
226238
....@@ -238,27 +250,19 @@
238250 hr_cmd->token_mask = CMD_TOKEN_MASK;
239251 hr_cmd->use_events = 1;
240252
241
- down(&hr_cmd->poll_sem);
242
-
243253 return 0;
244254 }
245255
246256 void hns_roce_cmd_use_polling(struct hns_roce_dev *hr_dev)
247257 {
248258 struct hns_roce_cmdq *hr_cmd = &hr_dev->cmd;
249
- int i;
250
-
251
- hr_cmd->use_events = 0;
252
-
253
- for (i = 0; i < hr_cmd->max_cmds; ++i)
254
- down(&hr_cmd->event_sem);
255259
256260 kfree(hr_cmd->context);
257
- up(&hr_cmd->poll_sem);
261
+ hr_cmd->use_events = 0;
258262 }
259263
260
-struct hns_roce_cmd_mailbox
261
- *hns_roce_alloc_cmd_mailbox(struct hns_roce_dev *hr_dev)
264
+struct hns_roce_cmd_mailbox *
265
+hns_roce_alloc_cmd_mailbox(struct hns_roce_dev *hr_dev)
262266 {
263267 struct hns_roce_cmd_mailbox *mailbox;
264268
....@@ -266,8 +270,8 @@
266270 if (!mailbox)
267271 return ERR_PTR(-ENOMEM);
268272
269
- mailbox->buf = dma_pool_alloc(hr_dev->cmd.pool, GFP_KERNEL,
270
- &mailbox->dma);
273
+ mailbox->buf =
274
+ dma_pool_alloc(hr_dev->cmd.pool, GFP_KERNEL, &mailbox->dma);
271275 if (!mailbox->buf) {
272276 kfree(mailbox);
273277 return ERR_PTR(-ENOMEM);
....@@ -275,7 +279,6 @@
275279
276280 return mailbox;
277281 }
278
-EXPORT_SYMBOL_GPL(hns_roce_alloc_cmd_mailbox);
279282
280283 void hns_roce_free_cmd_mailbox(struct hns_roce_dev *hr_dev,
281284 struct hns_roce_cmd_mailbox *mailbox)
....@@ -286,4 +289,3 @@
286289 dma_pool_free(hr_dev->cmd.pool, mailbox->buf, mailbox->dma);
287290 kfree(mailbox);
288291 }
289
-EXPORT_SYMBOL_GPL(hns_roce_free_cmd_mailbox);