.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. |
---|
3 | 4 | * 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. |
---|
32 | 5 | */ |
---|
33 | 6 | |
---|
34 | 7 | #include <linux/kernel.h> |
---|
35 | 8 | #include <linux/interrupt.h> |
---|
36 | 9 | #include <linux/hardirq.h> |
---|
37 | 10 | |
---|
38 | | -#include "rxe_task.h" |
---|
| 11 | +#include "rxe.h" |
---|
39 | 12 | |
---|
40 | 13 | int __rxe_do_task(struct rxe_task *task) |
---|
41 | 14 | |
---|
.. | .. |
---|
55 | 28 | * a second caller finds the task already running |
---|
56 | 29 | * but looks just after the last call to func |
---|
57 | 30 | */ |
---|
58 | | -void rxe_do_task(unsigned long data) |
---|
| 31 | +void rxe_do_task(struct tasklet_struct *t) |
---|
59 | 32 | { |
---|
60 | 33 | int cont; |
---|
61 | 34 | int ret; |
---|
62 | 35 | 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; |
---|
64 | 38 | |
---|
65 | 39 | spin_lock_irqsave(&task->state_lock, flags); |
---|
66 | 40 | switch (task->state) { |
---|
.. | .. |
---|
71 | 45 | |
---|
72 | 46 | case TASK_STATE_BUSY: |
---|
73 | 47 | task->state = TASK_STATE_ARMED; |
---|
74 | | - /* fall through */ |
---|
| 48 | + fallthrough; |
---|
75 | 49 | case TASK_STATE_ARMED: |
---|
76 | 50 | spin_unlock_irqrestore(&task->state_lock, flags); |
---|
77 | 51 | return; |
---|
.. | .. |
---|
89 | 63 | spin_lock_irqsave(&task->state_lock, flags); |
---|
90 | 64 | switch (task->state) { |
---|
91 | 65 | case TASK_STATE_BUSY: |
---|
92 | | - if (ret) |
---|
| 66 | + if (ret) { |
---|
93 | 67 | task->state = TASK_STATE_START; |
---|
94 | | - else |
---|
| 68 | + } else if (iterations--) { |
---|
95 | 69 | 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 | + } |
---|
96 | 77 | break; |
---|
97 | 78 | |
---|
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 |
---|
99 | 80 | * func, so we will call one more time regardless of the |
---|
100 | 81 | * return value |
---|
101 | 82 | */ |
---|
.. | .. |
---|
114 | 95 | task->ret = ret; |
---|
115 | 96 | } |
---|
116 | 97 | |
---|
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 *)) |
---|
119 | 99 | { |
---|
120 | | - task->obj = obj; |
---|
121 | 100 | task->arg = arg; |
---|
122 | 101 | task->func = func; |
---|
123 | | - snprintf(task->name, sizeof(task->name), "%s", name); |
---|
124 | 102 | task->destroyed = false; |
---|
125 | 103 | |
---|
126 | | - tasklet_init(&task->tasklet, rxe_do_task, (unsigned long)task); |
---|
| 104 | + tasklet_setup(&task->tasklet, rxe_do_task); |
---|
127 | 105 | |
---|
128 | 106 | task->state = TASK_STATE_START; |
---|
129 | 107 | spin_lock_init(&task->state_lock); |
---|
.. | .. |
---|
159 | 137 | if (sched) |
---|
160 | 138 | tasklet_schedule(&task->tasklet); |
---|
161 | 139 | else |
---|
162 | | - rxe_do_task((unsigned long)task); |
---|
| 140 | + rxe_do_task(&task->tasklet); |
---|
163 | 141 | } |
---|
164 | 142 | |
---|
165 | 143 | void rxe_disable_task(struct rxe_task *task) |
---|