Commit | Line | Data |
---|---|---|
4bd14dd5 JB |
1 | /****************************************************************************** |
2 | * | |
3 | * This file is provided under a dual BSD/GPLv2 license. When using or | |
4 | * redistributing this file, you may do so under either license. | |
5 | * | |
6 | * GPL LICENSE SUMMARY | |
7 | * | |
51368bf7 | 8 | * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved. |
6eb031d2 | 9 | * Copyright(c) 2015 Intel Deutschland GmbH |
4bd14dd5 JB |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of version 2 of the GNU General Public License as | |
13 | * published by the Free Software Foundation. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, but | |
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | * General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | |
23 | * USA | |
24 | * | |
25 | * The full GNU General Public License is included in this distribution | |
410dc5aa | 26 | * in the file called COPYING. |
4bd14dd5 JB |
27 | * |
28 | * Contact Information: | |
d01c5366 | 29 | * Intel Linux Wireless <linuxwifi@intel.com> |
4bd14dd5 JB |
30 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
31 | * | |
32 | * BSD LICENSE | |
33 | * | |
51368bf7 | 34 | * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved. |
4bd14dd5 JB |
35 | * All rights reserved. |
36 | * | |
37 | * Redistribution and use in source and binary forms, with or without | |
38 | * modification, are permitted provided that the following conditions | |
39 | * are met: | |
40 | * | |
41 | * * Redistributions of source code must retain the above copyright | |
42 | * notice, this list of conditions and the following disclaimer. | |
43 | * * Redistributions in binary form must reproduce the above copyright | |
44 | * notice, this list of conditions and the following disclaimer in | |
45 | * the documentation and/or other materials provided with the | |
46 | * distribution. | |
47 | * * Neither the name Intel Corporation nor the names of its | |
48 | * contributors may be used to endorse or promote products derived | |
49 | * from this software without specific prior written permission. | |
50 | * | |
51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
55 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
56 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
57 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
58 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
59 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
60 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
61 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
62 | * | |
63 | *****************************************************************************/ | |
64 | #include <linux/sched.h> | |
ac91f910 | 65 | #include <linux/export.h> |
4bd14dd5 | 66 | |
48e29340 | 67 | #include "iwl-drv.h" |
4bd14dd5 JB |
68 | #include "iwl-notif-wait.h" |
69 | ||
70 | ||
71 | void iwl_notification_wait_init(struct iwl_notif_wait_data *notif_wait) | |
72 | { | |
73 | spin_lock_init(¬if_wait->notif_wait_lock); | |
74 | INIT_LIST_HEAD(¬if_wait->notif_waits); | |
75 | init_waitqueue_head(¬if_wait->notif_waitq); | |
76 | } | |
48e29340 | 77 | IWL_EXPORT_SYMBOL(iwl_notification_wait_init); |
4bd14dd5 JB |
78 | |
79 | void iwl_notification_wait_notify(struct iwl_notif_wait_data *notif_wait, | |
80 | struct iwl_rx_packet *pkt) | |
81 | { | |
db662d47 JB |
82 | bool triggered = false; |
83 | ||
4bd14dd5 JB |
84 | if (!list_empty(¬if_wait->notif_waits)) { |
85 | struct iwl_notification_wait *w; | |
86 | ||
87 | spin_lock(¬if_wait->notif_wait_lock); | |
88 | list_for_each_entry(w, ¬if_wait->notif_waits, list) { | |
db662d47 JB |
89 | int i; |
90 | bool found = false; | |
91 | ||
92 | /* | |
93 | * If it already finished (triggered) or has been | |
94 | * aborted then don't evaluate it again to avoid races, | |
95 | * Otherwise the function could be called again even | |
96 | * though it returned true before | |
97 | */ | |
98 | if (w->triggered || w->aborted) | |
99 | continue; | |
100 | ||
101 | for (i = 0; i < w->n_cmds; i++) { | |
5b88792c SS |
102 | u16 rec_id = WIDE_ID(pkt->hdr.group_id, |
103 | pkt->hdr.cmd); | |
104 | ||
105 | if (w->cmds[i] == rec_id || | |
106 | (!iwl_cmd_groupid(w->cmds[i]) && | |
107 | DEF_ID(w->cmds[i]) == rec_id)) { | |
db662d47 JB |
108 | found = true; |
109 | break; | |
110 | } | |
111 | } | |
112 | if (!found) | |
4bd14dd5 | 113 | continue; |
db662d47 JB |
114 | |
115 | if (!w->fn || w->fn(notif_wait, pkt, w->fn_data)) { | |
116 | w->triggered = true; | |
117 | triggered = true; | |
118 | } | |
4bd14dd5 JB |
119 | } |
120 | spin_unlock(¬if_wait->notif_wait_lock); | |
121 | ||
4bd14dd5 | 122 | } |
db662d47 JB |
123 | |
124 | if (triggered) | |
125 | wake_up_all(¬if_wait->notif_waitq); | |
4bd14dd5 | 126 | } |
48e29340 | 127 | IWL_EXPORT_SYMBOL(iwl_notification_wait_notify); |
4bd14dd5 JB |
128 | |
129 | void iwl_abort_notification_waits(struct iwl_notif_wait_data *notif_wait) | |
130 | { | |
4bd14dd5 JB |
131 | struct iwl_notification_wait *wait_entry; |
132 | ||
3595c003 | 133 | spin_lock(¬if_wait->notif_wait_lock); |
4bd14dd5 JB |
134 | list_for_each_entry(wait_entry, ¬if_wait->notif_waits, list) |
135 | wait_entry->aborted = true; | |
3595c003 | 136 | spin_unlock(¬if_wait->notif_wait_lock); |
4bd14dd5 JB |
137 | |
138 | wake_up_all(¬if_wait->notif_waitq); | |
139 | } | |
48e29340 | 140 | IWL_EXPORT_SYMBOL(iwl_abort_notification_waits); |
4bd14dd5 JB |
141 | |
142 | void | |
143 | iwl_init_notification_wait(struct iwl_notif_wait_data *notif_wait, | |
144 | struct iwl_notification_wait *wait_entry, | |
6eb031d2 | 145 | const u16 *cmds, int n_cmds, |
db662d47 | 146 | bool (*fn)(struct iwl_notif_wait_data *notif_wait, |
4bd14dd5 JB |
147 | struct iwl_rx_packet *pkt, void *data), |
148 | void *fn_data) | |
149 | { | |
db662d47 JB |
150 | if (WARN_ON(n_cmds > MAX_NOTIF_CMDS)) |
151 | n_cmds = MAX_NOTIF_CMDS; | |
152 | ||
4bd14dd5 JB |
153 | wait_entry->fn = fn; |
154 | wait_entry->fn_data = fn_data; | |
db662d47 | 155 | wait_entry->n_cmds = n_cmds; |
6eb031d2 | 156 | memcpy(wait_entry->cmds, cmds, n_cmds * sizeof(u16)); |
4bd14dd5 JB |
157 | wait_entry->triggered = false; |
158 | wait_entry->aborted = false; | |
159 | ||
160 | spin_lock_bh(¬if_wait->notif_wait_lock); | |
161 | list_add(&wait_entry->list, ¬if_wait->notif_waits); | |
162 | spin_unlock_bh(¬if_wait->notif_wait_lock); | |
163 | } | |
48e29340 | 164 | IWL_EXPORT_SYMBOL(iwl_init_notification_wait); |
4bd14dd5 JB |
165 | |
166 | int iwl_wait_notification(struct iwl_notif_wait_data *notif_wait, | |
167 | struct iwl_notification_wait *wait_entry, | |
168 | unsigned long timeout) | |
169 | { | |
170 | int ret; | |
171 | ||
172 | ret = wait_event_timeout(notif_wait->notif_waitq, | |
173 | wait_entry->triggered || wait_entry->aborted, | |
174 | timeout); | |
175 | ||
176 | spin_lock_bh(¬if_wait->notif_wait_lock); | |
177 | list_del(&wait_entry->list); | |
178 | spin_unlock_bh(¬if_wait->notif_wait_lock); | |
179 | ||
180 | if (wait_entry->aborted) | |
181 | return -EIO; | |
182 | ||
183 | /* return value is always >= 0 */ | |
184 | if (ret <= 0) | |
185 | return -ETIMEDOUT; | |
186 | return 0; | |
187 | } | |
48e29340 | 188 | IWL_EXPORT_SYMBOL(iwl_wait_notification); |
4bd14dd5 JB |
189 | |
190 | void iwl_remove_notification(struct iwl_notif_wait_data *notif_wait, | |
191 | struct iwl_notification_wait *wait_entry) | |
192 | { | |
193 | spin_lock_bh(¬if_wait->notif_wait_lock); | |
194 | list_del(&wait_entry->list); | |
195 | spin_unlock_bh(¬if_wait->notif_wait_lock); | |
196 | } | |
48e29340 | 197 | IWL_EXPORT_SYMBOL(iwl_remove_notification); |