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#include <linux/usb/wusb.h>
40#include "wusbhc.h"
41
42
43int wusbhc_mmcie_create(struct wusbhc *wusbhc)
44{
45 u8 mmcies = wusbhc->mmcies_max;
46 wusbhc->mmcie = kcalloc(mmcies, sizeof(wusbhc->mmcie[0]), GFP_KERNEL);
47 if (wusbhc->mmcie == NULL)
48 return -ENOMEM;
49 mutex_init(&wusbhc->mmcie_mutex);
50 return 0;
51}
52
53
54void wusbhc_mmcie_destroy(struct wusbhc *wusbhc)
55{
56 kfree(wusbhc->mmcie);
57}
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92int wusbhc_mmcie_set(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt,
93 struct wuie_hdr *wuie)
94{
95 int result = -ENOBUFS;
96 unsigned handle, itr;
97
98
99 mutex_lock(&wusbhc->mmcie_mutex);
100 switch (wuie->bIEIdentifier) {
101 case WUIE_ID_HOST_INFO:
102
103 handle = wusbhc->mmcies_max - 1;
104 break;
105 case WUIE_ID_ISOCH_DISCARD:
106 dev_err(wusbhc->dev, "Special ordering case for WUIE ID 0x%x "
107 "unimplemented\n", wuie->bIEIdentifier);
108 result = -ENOSYS;
109 goto error_unlock;
110 default:
111
112 handle = ~0;
113 for (itr = 0; itr < wusbhc->mmcies_max - 1; itr++) {
114 if (wusbhc->mmcie[itr] == wuie) {
115 handle = itr;
116 break;
117 }
118 if (wusbhc->mmcie[itr] == NULL)
119 handle = itr;
120 }
121 if (handle == ~0)
122 goto error_unlock;
123 }
124 result = (wusbhc->mmcie_add)(wusbhc, interval, repeat_cnt, handle,
125 wuie);
126 if (result >= 0)
127 wusbhc->mmcie[handle] = wuie;
128error_unlock:
129 mutex_unlock(&wusbhc->mmcie_mutex);
130 return result;
131}
132EXPORT_SYMBOL_GPL(wusbhc_mmcie_set);
133
134
135
136
137
138
139void wusbhc_mmcie_rm(struct wusbhc *wusbhc, struct wuie_hdr *wuie)
140{
141 int result;
142 unsigned handle, itr;
143
144 mutex_lock(&wusbhc->mmcie_mutex);
145 for (itr = 0; itr < wusbhc->mmcies_max; itr++) {
146 if (wusbhc->mmcie[itr] == wuie) {
147 handle = itr;
148 goto found;
149 }
150 }
151 mutex_unlock(&wusbhc->mmcie_mutex);
152 return;
153
154found:
155 result = (wusbhc->mmcie_rm)(wusbhc, handle);
156 if (result == 0)
157 wusbhc->mmcie[itr] = NULL;
158 mutex_unlock(&wusbhc->mmcie_mutex);
159}
160EXPORT_SYMBOL_GPL(wusbhc_mmcie_rm);
161
162static int wusbhc_mmc_start(struct wusbhc *wusbhc)
163{
164 int ret;
165
166 mutex_lock(&wusbhc->mutex);
167 ret = wusbhc->start(wusbhc);
168 if (ret >= 0)
169 wusbhc->active = 1;
170 mutex_unlock(&wusbhc->mutex);
171
172 return ret;
173}
174
175static void wusbhc_mmc_stop(struct wusbhc *wusbhc)
176{
177 mutex_lock(&wusbhc->mutex);
178 wusbhc->active = 0;
179 wusbhc->stop(wusbhc, WUSB_CHANNEL_STOP_DELAY_MS);
180 mutex_unlock(&wusbhc->mutex);
181}
182
183
184
185
186
187
188
189
190int wusbhc_start(struct wusbhc *wusbhc)
191{
192 int result;
193 struct device *dev = wusbhc->dev;
194
195 WARN_ON(wusbhc->wuie_host_info != NULL);
196
197 result = wusbhc_rsv_establish(wusbhc);
198 if (result < 0) {
199 dev_err(dev, "cannot establish cluster reservation: %d\n",
200 result);
201 goto error_rsv_establish;
202 }
203
204 result = wusbhc_devconnect_start(wusbhc);
205 if (result < 0) {
206 dev_err(dev, "error enabling device connections: %d\n", result);
207 goto error_devconnect_start;
208 }
209
210 result = wusbhc_sec_start(wusbhc);
211 if (result < 0) {
212 dev_err(dev, "error starting security in the HC: %d\n", result);
213 goto error_sec_start;
214 }
215
216
217 result = wusbhc->set_num_dnts(wusbhc, 0, 15);
218 if (result < 0) {
219 dev_err(dev, "Cannot set DNTS parameters: %d\n", result);
220 goto error_set_num_dnts;
221 }
222 result = wusbhc_mmc_start(wusbhc);
223 if (result < 0) {
224 dev_err(dev, "error starting wusbch: %d\n", result);
225 goto error_wusbhc_start;
226 }
227
228 return 0;
229
230error_wusbhc_start:
231 wusbhc_sec_stop(wusbhc);
232error_set_num_dnts:
233error_sec_start:
234 wusbhc_devconnect_stop(wusbhc);
235error_devconnect_start:
236 wusbhc_rsv_terminate(wusbhc);
237error_rsv_establish:
238 return result;
239}
240
241
242
243
244
245
246
247void wusbhc_stop(struct wusbhc *wusbhc)
248{
249 wusbhc_mmc_stop(wusbhc);
250 wusbhc_sec_stop(wusbhc);
251 wusbhc_devconnect_stop(wusbhc);
252 wusbhc_rsv_terminate(wusbhc);
253}
254
255
256
257
258
259
260
261
262int wusbhc_chid_set(struct wusbhc *wusbhc, const struct wusb_ckhdid *chid)
263{
264 int result = 0;
265
266 if (memcmp(chid, &wusb_ckhdid_zero, sizeof(chid)) == 0)
267 chid = NULL;
268
269 mutex_lock(&wusbhc->mutex);
270 if (chid) {
271 if (wusbhc->active) {
272 mutex_unlock(&wusbhc->mutex);
273 return -EBUSY;
274 }
275 wusbhc->chid = *chid;
276 }
277 mutex_unlock(&wusbhc->mutex);
278
279 if (chid)
280 result = uwb_radio_start(&wusbhc->pal);
281 else
282 uwb_radio_stop(&wusbhc->pal);
283 return result;
284}
285EXPORT_SYMBOL_GPL(wusbhc_chid_set);
286