1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60#include <linux/sched.h>
61#include <linux/export.h>
62
63#include "iwl-drv.h"
64#include "notif-wait.h"
65
66
67void iwl_notification_wait_init(struct iwl_notif_wait_data *notif_wait)
68{
69 spin_lock_init(¬if_wait->notif_wait_lock);
70 INIT_LIST_HEAD(¬if_wait->notif_waits);
71 init_waitqueue_head(¬if_wait->notif_waitq);
72}
73IWL_EXPORT_SYMBOL(iwl_notification_wait_init);
74
75bool iwl_notification_wait(struct iwl_notif_wait_data *notif_wait,
76 struct iwl_rx_packet *pkt)
77{
78 bool triggered = false;
79
80 if (!list_empty(¬if_wait->notif_waits)) {
81 struct iwl_notification_wait *w;
82
83 spin_lock(¬if_wait->notif_wait_lock);
84 list_for_each_entry(w, ¬if_wait->notif_waits, list) {
85 int i;
86 bool found = false;
87
88
89
90
91
92
93
94 if (w->triggered || w->aborted)
95 continue;
96
97 for (i = 0; i < w->n_cmds; i++) {
98 u16 rec_id = WIDE_ID(pkt->hdr.group_id,
99 pkt->hdr.cmd);
100
101 if (w->cmds[i] == rec_id ||
102 (!iwl_cmd_groupid(w->cmds[i]) &&
103 DEF_ID(w->cmds[i]) == rec_id)) {
104 found = true;
105 break;
106 }
107 }
108 if (!found)
109 continue;
110
111 if (!w->fn || w->fn(notif_wait, pkt, w->fn_data)) {
112 w->triggered = true;
113 triggered = true;
114 }
115 }
116 spin_unlock(¬if_wait->notif_wait_lock);
117 }
118
119 return triggered;
120}
121IWL_EXPORT_SYMBOL(iwl_notification_wait);
122
123void iwl_abort_notification_waits(struct iwl_notif_wait_data *notif_wait)
124{
125 struct iwl_notification_wait *wait_entry;
126
127 spin_lock(¬if_wait->notif_wait_lock);
128 list_for_each_entry(wait_entry, ¬if_wait->notif_waits, list)
129 wait_entry->aborted = true;
130 spin_unlock(¬if_wait->notif_wait_lock);
131
132 wake_up_all(¬if_wait->notif_waitq);
133}
134IWL_EXPORT_SYMBOL(iwl_abort_notification_waits);
135
136void
137iwl_init_notification_wait(struct iwl_notif_wait_data *notif_wait,
138 struct iwl_notification_wait *wait_entry,
139 const u16 *cmds, int n_cmds,
140 bool (*fn)(struct iwl_notif_wait_data *notif_wait,
141 struct iwl_rx_packet *pkt, void *data),
142 void *fn_data)
143{
144 if (WARN_ON(n_cmds > MAX_NOTIF_CMDS))
145 n_cmds = MAX_NOTIF_CMDS;
146
147 wait_entry->fn = fn;
148 wait_entry->fn_data = fn_data;
149 wait_entry->n_cmds = n_cmds;
150 memcpy(wait_entry->cmds, cmds, n_cmds * sizeof(u16));
151 wait_entry->triggered = false;
152 wait_entry->aborted = false;
153
154 spin_lock_bh(¬if_wait->notif_wait_lock);
155 list_add(&wait_entry->list, ¬if_wait->notif_waits);
156 spin_unlock_bh(¬if_wait->notif_wait_lock);
157}
158IWL_EXPORT_SYMBOL(iwl_init_notification_wait);
159
160void iwl_remove_notification(struct iwl_notif_wait_data *notif_wait,
161 struct iwl_notification_wait *wait_entry)
162{
163 spin_lock_bh(¬if_wait->notif_wait_lock);
164 list_del(&wait_entry->list);
165 spin_unlock_bh(¬if_wait->notif_wait_lock);
166}
167IWL_EXPORT_SYMBOL(iwl_remove_notification);
168
169int iwl_wait_notification(struct iwl_notif_wait_data *notif_wait,
170 struct iwl_notification_wait *wait_entry,
171 unsigned long timeout)
172{
173 int ret;
174
175 ret = wait_event_timeout(notif_wait->notif_waitq,
176 wait_entry->triggered || wait_entry->aborted,
177 timeout);
178
179 iwl_remove_notification(notif_wait, wait_entry);
180
181 if (wait_entry->aborted)
182 return -EIO;
183
184
185 if (ret <= 0)
186 return -ETIMEDOUT;
187 return 0;
188}
189IWL_EXPORT_SYMBOL(iwl_wait_notification);
190