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