hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/infiniband/sw/rxe/rxe_task.c
....@@ -1,41 +1,14 @@
1
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
12 /*
23 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
34 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
4
- *
5
- * This software is available to you under a choice of one of two
6
- * licenses. You may choose to be licensed under the terms of the GNU
7
- * General Public License (GPL) Version 2, available from the file
8
- * COPYING in the main directory of this source tree, or the
9
- * OpenIB.org BSD license below:
10
- *
11
- * Redistribution and use in source and binary forms, with or
12
- * without modification, are permitted provided that the following
13
- * conditions are met:
14
- *
15
- * - Redistributions of source code must retain the above
16
- * copyright notice, this list of conditions and the following
17
- * disclaimer.
18
- *
19
- * - Redistributions in binary form must reproduce the above
20
- * copyright notice, this list of conditions and the following
21
- * disclaimer in the documentation and/or other materials
22
- * provided with the distribution.
23
- *
24
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
- * SOFTWARE.
325 */
336
347 #include <linux/kernel.h>
358 #include <linux/interrupt.h>
369 #include <linux/hardirq.h>
3710
38
-#include "rxe_task.h"
11
+#include "rxe.h"
3912
4013 int __rxe_do_task(struct rxe_task *task)
4114
....@@ -55,12 +28,13 @@
5528 * a second caller finds the task already running
5629 * but looks just after the last call to func
5730 */
58
-void rxe_do_task(unsigned long data)
31
+void rxe_do_task(struct tasklet_struct *t)
5932 {
6033 int cont;
6134 int ret;
6235 unsigned long flags;
63
- struct rxe_task *task = (struct rxe_task *)data;
36
+ struct rxe_task *task = from_tasklet(task, t, tasklet);
37
+ unsigned int iterations = RXE_MAX_ITERATIONS;
6438
6539 spin_lock_irqsave(&task->state_lock, flags);
6640 switch (task->state) {
....@@ -71,7 +45,7 @@
7145
7246 case TASK_STATE_BUSY:
7347 task->state = TASK_STATE_ARMED;
74
- /* fall through */
48
+ fallthrough;
7549 case TASK_STATE_ARMED:
7650 spin_unlock_irqrestore(&task->state_lock, flags);
7751 return;
....@@ -89,13 +63,20 @@
8963 spin_lock_irqsave(&task->state_lock, flags);
9064 switch (task->state) {
9165 case TASK_STATE_BUSY:
92
- if (ret)
66
+ if (ret) {
9367 task->state = TASK_STATE_START;
94
- else
68
+ } else if (iterations--) {
9569 cont = 1;
70
+ } else {
71
+ /* reschedule the tasklet and exit
72
+ * the loop to give up the cpu
73
+ */
74
+ tasklet_schedule(&task->tasklet);
75
+ task->state = TASK_STATE_START;
76
+ }
9677 break;
9778
98
- /* soneone tried to run the task since the last time we called
79
+ /* someone tried to run the task since the last time we called
9980 * func, so we will call one more time regardless of the
10081 * return value
10182 */
....@@ -114,16 +95,13 @@
11495 task->ret = ret;
11596 }
11697
117
-int rxe_init_task(void *obj, struct rxe_task *task,
118
- void *arg, int (*func)(void *), char *name)
98
+int rxe_init_task(struct rxe_task *task, void *arg, int (*func)(void *))
11999 {
120
- task->obj = obj;
121100 task->arg = arg;
122101 task->func = func;
123
- snprintf(task->name, sizeof(task->name), "%s", name);
124102 task->destroyed = false;
125103
126
- tasklet_init(&task->tasklet, rxe_do_task, (unsigned long)task);
104
+ tasklet_setup(&task->tasklet, rxe_do_task);
127105
128106 task->state = TASK_STATE_START;
129107 spin_lock_init(&task->state_lock);
....@@ -159,7 +137,7 @@
159137 if (sched)
160138 tasklet_schedule(&task->tasklet);
161139 else
162
- rxe_do_task((unsigned long)task);
140
+ rxe_do_task(&task->tasklet);
163141 }
164142
165143 void rxe_disable_task(struct rxe_task *task)