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#include <linux/kernel.h>
58#include <linux/slab.h>
59#include <linux/module.h>
60#include <linux/workqueue.h>
61#include <linux/wait.h>
62#include <linux/completion.h>
63#include "../wusbcore/wa-hc.h"
64#include "../wusbcore/wusbhc.h"
65
66struct hwahc {
67 struct wusbhc wusbhc;
68 struct wahc wa;
69};
70
71
72
73
74
75
76
77static int __hwahc_set_cluster_id(struct hwahc *hwahc, u8 cluster_id)
78{
79 int result;
80 struct wusbhc *wusbhc = &hwahc->wusbhc;
81 struct wahc *wa = &hwahc->wa;
82 struct device *dev = &wa->usb_iface->dev;
83
84 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
85 WUSB_REQ_SET_CLUSTER_ID,
86 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
87 cluster_id,
88 wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
89 NULL, 0, USB_CTRL_SET_TIMEOUT);
90 if (result < 0)
91 dev_err(dev, "Cannot set WUSB Cluster ID to 0x%02x: %d\n",
92 cluster_id, result);
93 else
94 wusbhc->cluster_id = cluster_id;
95 dev_info(dev, "Wireless USB Cluster ID set to 0x%02x\n", cluster_id);
96 return result;
97}
98
99static int __hwahc_op_set_num_dnts(struct wusbhc *wusbhc, u8 interval, u8 slots)
100{
101 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
102 struct wahc *wa = &hwahc->wa;
103
104 return usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
105 WUSB_REQ_SET_NUM_DNTS,
106 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
107 interval << 8 | slots,
108 wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
109 NULL, 0, USB_CTRL_SET_TIMEOUT);
110}
111
112
113
114
115
116
117
118static int hwahc_op_reset(struct usb_hcd *usb_hcd)
119{
120 int result;
121 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
122 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
123 struct device *dev = &hwahc->wa.usb_iface->dev;
124
125 mutex_lock(&wusbhc->mutex);
126 wa_nep_disarm(&hwahc->wa);
127 result = __wa_set_feature(&hwahc->wa, WA_RESET);
128 if (result < 0) {
129 dev_err(dev, "error commanding HC to reset: %d\n", result);
130 goto error_unlock;
131 }
132 result = __wa_wait_status(&hwahc->wa, WA_STATUS_RESETTING, 0);
133 if (result < 0) {
134 dev_err(dev, "error waiting for HC to reset: %d\n", result);
135 goto error_unlock;
136 }
137error_unlock:
138 mutex_unlock(&wusbhc->mutex);
139 return result;
140}
141
142
143
144
145static int hwahc_op_start(struct usb_hcd *usb_hcd)
146{
147 u8 addr;
148 int result;
149 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
150 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
151
152 result = -ENOSPC;
153 mutex_lock(&wusbhc->mutex);
154 addr = wusb_cluster_id_get();
155 if (addr == 0)
156 goto error_cluster_id_get;
157 result = __hwahc_set_cluster_id(hwahc, addr);
158 if (result < 0)
159 goto error_set_cluster_id;
160
161 usb_hcd->uses_new_polling = 1;
162 set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags);
163 usb_hcd->state = HC_STATE_RUNNING;
164
165
166
167
168
169 pm_runtime_get_noresume(&usb_hcd->self.root_hub->dev);
170
171 result = 0;
172out:
173 mutex_unlock(&wusbhc->mutex);
174 return result;
175
176error_set_cluster_id:
177 wusb_cluster_id_put(wusbhc->cluster_id);
178error_cluster_id_get:
179 goto out;
180
181}
182
183
184
185
186
187
188
189static void hwahc_op_stop(struct usb_hcd *usb_hcd)
190{
191 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
192
193 mutex_lock(&wusbhc->mutex);
194 wusb_cluster_id_put(wusbhc->cluster_id);
195 mutex_unlock(&wusbhc->mutex);
196}
197
198static int hwahc_op_get_frame_number(struct usb_hcd *usb_hcd)
199{
200 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
201 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
202 struct wahc *wa = &hwahc->wa;
203
204
205
206
207
208
209 return usb_get_current_frame_number(wa->usb_dev);
210}
211
212static int hwahc_op_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb,
213 gfp_t gfp)
214{
215 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
216 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
217
218 return wa_urb_enqueue(&hwahc->wa, urb->ep, urb, gfp);
219}
220
221static int hwahc_op_urb_dequeue(struct usb_hcd *usb_hcd, struct urb *urb,
222 int status)
223{
224 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
225 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
226
227 return wa_urb_dequeue(&hwahc->wa, urb, status);
228}
229
230
231
232
233
234
235static void hwahc_op_endpoint_disable(struct usb_hcd *usb_hcd,
236 struct usb_host_endpoint *ep)
237{
238 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
239 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
240
241 rpipe_ep_disable(&hwahc->wa, ep);
242}
243
244static int __hwahc_op_wusbhc_start(struct wusbhc *wusbhc)
245{
246 int result;
247 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
248 struct device *dev = &hwahc->wa.usb_iface->dev;
249
250 result = __wa_set_feature(&hwahc->wa, WA_ENABLE);
251 if (result < 0) {
252 dev_err(dev, "error commanding HC to start: %d\n", result);
253 goto error_stop;
254 }
255 result = __wa_wait_status(&hwahc->wa, WA_ENABLE, WA_ENABLE);
256 if (result < 0) {
257 dev_err(dev, "error waiting for HC to start: %d\n", result);
258 goto error_stop;
259 }
260 result = wa_nep_arm(&hwahc->wa, GFP_KERNEL);
261 if (result < 0) {
262 dev_err(dev, "cannot listen to notifications: %d\n", result);
263 goto error_stop;
264 }
265
266
267
268
269 if (hwahc->wa.quirks &
270 WUSB_QUIRK_ALEREON_HWA_DISABLE_XFER_NOTIFICATIONS) {
271 struct usb_host_interface *cur_altsetting =
272 hwahc->wa.usb_iface->cur_altsetting;
273
274 result = usb_control_msg(hwahc->wa.usb_dev,
275 usb_sndctrlpipe(hwahc->wa.usb_dev, 0),
276 WA_REQ_ALEREON_DISABLE_XFER_NOTIFICATIONS,
277 USB_DIR_OUT | USB_TYPE_VENDOR |
278 USB_RECIP_INTERFACE,
279 WA_REQ_ALEREON_FEATURE_SET,
280 cur_altsetting->desc.bInterfaceNumber,
281 NULL, 0,
282 USB_CTRL_SET_TIMEOUT);
283
284
285
286
287
288 if (result == 0)
289 result = wa_dti_start(&hwahc->wa);
290 else
291 result = 0;
292
293 if (result < 0) {
294 dev_err(dev, "cannot start DTI: %d\n", result);
295 goto error_dti_start;
296 }
297 }
298
299 return result;
300
301error_dti_start:
302 wa_nep_disarm(&hwahc->wa);
303error_stop:
304 __wa_clear_feature(&hwahc->wa, WA_ENABLE);
305 return result;
306}
307
308static void __hwahc_op_wusbhc_stop(struct wusbhc *wusbhc, int delay)
309{
310 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
311 struct wahc *wa = &hwahc->wa;
312 u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber;
313 int ret;
314
315 ret = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
316 WUSB_REQ_CHAN_STOP,
317 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
318 delay * 1000,
319 iface_no,
320 NULL, 0, USB_CTRL_SET_TIMEOUT);
321 if (ret == 0)
322 msleep(delay);
323
324 wa_nep_disarm(&hwahc->wa);
325 __wa_stop(&hwahc->wa);
326}
327
328
329
330
331
332
333
334static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
335 const struct uwb_mas_bm *mas)
336{
337 int result;
338 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
339 struct wahc *wa = &hwahc->wa;
340 struct device *dev = &wa->usb_iface->dev;
341 u8 mas_le[UWB_NUM_MAS/8];
342
343
344 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
345 WUSB_REQ_SET_STREAM_IDX,
346 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
347 stream_index,
348 wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
349 NULL, 0, USB_CTRL_SET_TIMEOUT);
350 if (result < 0) {
351 dev_err(dev, "Cannot set WUSB stream index: %d\n", result);
352 goto out;
353 }
354 uwb_mas_bm_copy_le(mas_le, mas);
355
356 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
357 WUSB_REQ_SET_WUSB_MAS,
358 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
359 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
360 mas_le, 32, USB_CTRL_SET_TIMEOUT);
361 if (result < 0)
362 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
363out:
364 return result;
365}
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381static int __hwahc_op_mmcie_add(struct wusbhc *wusbhc, u8 interval,
382 u8 repeat_cnt, u8 handle,
383 struct wuie_hdr *wuie)
384{
385 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
386 struct wahc *wa = &hwahc->wa;
387 u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber;
388
389 return usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
390 WUSB_REQ_ADD_MMC_IE,
391 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
392 interval << 8 | repeat_cnt,
393 handle << 8 | iface_no,
394 wuie, wuie->bLength, USB_CTRL_SET_TIMEOUT);
395}
396
397
398
399
400
401
402static int __hwahc_op_mmcie_rm(struct wusbhc *wusbhc, u8 handle)
403{
404 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
405 struct wahc *wa = &hwahc->wa;
406 u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber;
407 return usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
408 WUSB_REQ_REMOVE_MMC_IE,
409 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
410 0, handle << 8 | iface_no,
411 NULL, 0, USB_CTRL_SET_TIMEOUT);
412}
413
414
415
416
417
418
419
420static int __hwahc_op_dev_info_set(struct wusbhc *wusbhc,
421 struct wusb_dev *wusb_dev)
422{
423 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
424 struct wahc *wa = &hwahc->wa;
425 u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber;
426 struct hwa_dev_info *dev_info;
427 int ret;
428
429
430 dev_info = kzalloc(sizeof(struct hwa_dev_info), GFP_KERNEL);
431 if (!dev_info)
432 return -ENOMEM;
433 uwb_mas_bm_copy_le(dev_info->bmDeviceAvailability,
434 &wusb_dev->availability);
435 dev_info->bDeviceAddress = wusb_dev->addr;
436
437
438
439
440
441
442
443
444 if (wusb_dev->wusb_cap_descr)
445 dev_info->wPHYRates = wusb_dev->wusb_cap_descr->wPHYRates;
446 else
447 dev_info->wPHYRates = cpu_to_le16(USB_WIRELESS_PHY_53);
448
449 ret = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
450 WUSB_REQ_SET_DEV_INFO,
451 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
452 0, wusb_dev->port_idx << 8 | iface_no,
453 dev_info, sizeof(struct hwa_dev_info),
454 USB_CTRL_SET_TIMEOUT);
455 kfree(dev_info);
456 return ret;
457}
458
459
460
461
462
463
464
465
466static int __hwahc_dev_set_key(struct wusbhc *wusbhc, u8 port_idx, u32 tkid,
467 const void *key, size_t key_size,
468 u8 key_idx)
469{
470 int result = -ENOMEM;
471 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
472 struct wahc *wa = &hwahc->wa;
473 u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber;
474 struct usb_key_descriptor *keyd;
475 size_t keyd_len;
476
477 keyd_len = sizeof(*keyd) + key_size;
478 keyd = kzalloc(keyd_len, GFP_KERNEL);
479 if (keyd == NULL)
480 return -ENOMEM;
481
482 keyd->bLength = keyd_len;
483 keyd->bDescriptorType = USB_DT_KEY;
484 keyd->tTKID[0] = (tkid >> 0) & 0xff;
485 keyd->tTKID[1] = (tkid >> 8) & 0xff;
486 keyd->tTKID[2] = (tkid >> 16) & 0xff;
487 memcpy(keyd->bKeyData, key, key_size);
488
489 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
490 USB_REQ_SET_DESCRIPTOR,
491 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
492 USB_DT_KEY << 8 | key_idx,
493 port_idx << 8 | iface_no,
494 keyd, keyd_len, USB_CTRL_SET_TIMEOUT);
495
496 kzfree(keyd);
497 return result;
498}
499
500
501
502
503
504
505
506
507static int __hwahc_op_set_ptk(struct wusbhc *wusbhc, u8 port_idx, u32 tkid,
508 const void *key, size_t key_size)
509{
510 int result = -ENOMEM;
511 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
512 struct wahc *wa = &hwahc->wa;
513 u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber;
514 u8 encryption_value;
515
516
517 if (key) {
518 u8 key_idx = wusb_key_index(0, WUSB_KEY_INDEX_TYPE_PTK,
519 WUSB_KEY_INDEX_ORIGINATOR_HOST);
520
521 result = __hwahc_dev_set_key(wusbhc, port_idx, tkid,
522 key, key_size, key_idx);
523 if (result < 0)
524 goto error_set_key;
525 encryption_value = wusbhc->ccm1_etd->bEncryptionValue;
526 } else {
527
528 encryption_value = 0;
529 }
530
531
532 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
533 USB_REQ_SET_ENCRYPTION,
534 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
535 encryption_value, port_idx << 8 | iface_no,
536 NULL, 0, USB_CTRL_SET_TIMEOUT);
537 if (result < 0)
538 dev_err(wusbhc->dev, "Can't set host's WUSB encryption for "
539 "port index %u to %s (value %d): %d\n", port_idx,
540 wusb_et_name(wusbhc->ccm1_etd->bEncryptionType),
541 wusbhc->ccm1_etd->bEncryptionValue, result);
542error_set_key:
543 return result;
544}
545
546
547
548
549static int __hwahc_op_set_gtk(struct wusbhc *wusbhc, u32 tkid,
550 const void *key, size_t key_size)
551{
552 u8 key_idx = wusb_key_index(0, WUSB_KEY_INDEX_TYPE_GTK,
553 WUSB_KEY_INDEX_ORIGINATOR_HOST);
554
555 return __hwahc_dev_set_key(wusbhc, 0, tkid, key, key_size, key_idx);
556}
557
558
559
560
561
562
563
564
565
566
567static int wa_fill_descr(struct wahc *wa)
568{
569 int result;
570 struct device *dev = &wa->usb_iface->dev;
571 char *itr;
572 struct usb_device *usb_dev = wa->usb_dev;
573 struct usb_descriptor_header *hdr;
574 struct usb_wa_descriptor *wa_descr;
575 size_t itr_size, actconfig_idx;
576
577 actconfig_idx = (usb_dev->actconfig - usb_dev->config) /
578 sizeof(usb_dev->config[0]);
579 itr = usb_dev->rawdescriptors[actconfig_idx];
580 itr_size = le16_to_cpu(usb_dev->actconfig->desc.wTotalLength);
581 while (itr_size >= sizeof(*hdr)) {
582 hdr = (struct usb_descriptor_header *) itr;
583 dev_dbg(dev, "Extra device descriptor: "
584 "type %02x/%u bytes @ %zu (%zu left)\n",
585 hdr->bDescriptorType, hdr->bLength,
586 (itr - usb_dev->rawdescriptors[actconfig_idx]),
587 itr_size);
588 if (hdr->bDescriptorType == USB_DT_WIRE_ADAPTER)
589 goto found;
590 itr += hdr->bLength;
591 itr_size -= hdr->bLength;
592 }
593 dev_err(dev, "cannot find Wire Adapter Class descriptor\n");
594 return -ENODEV;
595
596found:
597 result = -EINVAL;
598 if (hdr->bLength > itr_size) {
599 dev_err(dev, "incomplete Wire Adapter Class descriptor "
600 "(%zu bytes left, %u needed)\n",
601 itr_size, hdr->bLength);
602 goto error;
603 }
604 if (hdr->bLength < sizeof(*wa->wa_descr)) {
605 dev_err(dev, "short Wire Adapter Class descriptor\n");
606 goto error;
607 }
608 wa->wa_descr = wa_descr = (struct usb_wa_descriptor *) hdr;
609 if (le16_to_cpu(wa_descr->bcdWAVersion) > 0x0100)
610 dev_warn(dev, "Wire Adapter v%d.%d newer than groked v1.0\n",
611 (le16_to_cpu(wa_descr->bcdWAVersion) & 0xff00) >> 8,
612 le16_to_cpu(wa_descr->bcdWAVersion) & 0x00ff);
613 result = 0;
614error:
615 return result;
616}
617
618static const struct hc_driver hwahc_hc_driver = {
619 .description = "hwa-hcd",
620 .product_desc = "Wireless USB HWA host controller",
621 .hcd_priv_size = sizeof(struct hwahc) - sizeof(struct usb_hcd),
622 .irq = NULL,
623 .flags = HCD_USB25,
624 .reset = hwahc_op_reset,
625 .start = hwahc_op_start,
626 .stop = hwahc_op_stop,
627 .get_frame_number = hwahc_op_get_frame_number,
628 .urb_enqueue = hwahc_op_urb_enqueue,
629 .urb_dequeue = hwahc_op_urb_dequeue,
630 .endpoint_disable = hwahc_op_endpoint_disable,
631
632 .hub_status_data = wusbhc_rh_status_data,
633 .hub_control = wusbhc_rh_control,
634 .start_port_reset = wusbhc_rh_start_port_reset,
635};
636
637static int hwahc_security_create(struct hwahc *hwahc)
638{
639 int result;
640 struct wusbhc *wusbhc = &hwahc->wusbhc;
641 struct usb_device *usb_dev = hwahc->wa.usb_dev;
642 struct device *dev = &usb_dev->dev;
643 struct usb_security_descriptor *secd;
644 struct usb_encryption_descriptor *etd;
645 void *itr, *top;
646 size_t itr_size, needed, bytes;
647 u8 index;
648 char buf[64];
649
650
651 index = (usb_dev->actconfig - usb_dev->config) /
652 sizeof(usb_dev->config[0]);
653 itr = usb_dev->rawdescriptors[index];
654 itr_size = le16_to_cpu(usb_dev->actconfig->desc.wTotalLength);
655 top = itr + itr_size;
656 result = __usb_get_extra_descriptor(usb_dev->rawdescriptors[index],
657 le16_to_cpu(usb_dev->actconfig->desc.wTotalLength),
658 USB_DT_SECURITY, (void **) &secd, sizeof(*secd));
659 if (result == -1) {
660 dev_warn(dev, "BUG? WUSB host has no security descriptors\n");
661 return 0;
662 }
663 needed = sizeof(*secd);
664 if (top - (void *)secd < needed) {
665 dev_err(dev, "BUG? Not enough data to process security "
666 "descriptor header (%zu bytes left vs %zu needed)\n",
667 top - (void *) secd, needed);
668 return 0;
669 }
670 needed = le16_to_cpu(secd->wTotalLength);
671 if (top - (void *)secd < needed) {
672 dev_err(dev, "BUG? Not enough data to process security "
673 "descriptors (%zu bytes left vs %zu needed)\n",
674 top - (void *) secd, needed);
675 return 0;
676 }
677
678 itr = (void *) secd + sizeof(*secd);
679 top = (void *) secd + le16_to_cpu(secd->wTotalLength);
680 index = 0;
681 bytes = 0;
682 while (itr < top) {
683 etd = itr;
684 if (top - itr < sizeof(*etd)) {
685 dev_err(dev, "BUG: bad host security descriptor; "
686 "not enough data (%zu vs %zu left)\n",
687 top - itr, sizeof(*etd));
688 break;
689 }
690 if (etd->bLength < sizeof(*etd)) {
691 dev_err(dev, "BUG: bad host encryption descriptor; "
692 "descriptor is too short "
693 "(%zu vs %zu needed)\n",
694 (size_t)etd->bLength, sizeof(*etd));
695 break;
696 }
697 itr += etd->bLength;
698 bytes += snprintf(buf + bytes, sizeof(buf) - bytes,
699 "%s (0x%02x) ",
700 wusb_et_name(etd->bEncryptionType),
701 etd->bEncryptionValue);
702 wusbhc->ccm1_etd = etd;
703 }
704 dev_info(dev, "supported encryption types: %s\n", buf);
705 if (wusbhc->ccm1_etd == NULL) {
706 dev_err(dev, "E: host doesn't support CCM-1 crypto\n");
707 return 0;
708 }
709
710 return 0;
711}
712
713static void hwahc_security_release(struct hwahc *hwahc)
714{
715
716}
717
718static int hwahc_create(struct hwahc *hwahc, struct usb_interface *iface,
719 kernel_ulong_t quirks)
720{
721 int result;
722 struct device *dev = &iface->dev;
723 struct wusbhc *wusbhc = &hwahc->wusbhc;
724 struct wahc *wa = &hwahc->wa;
725 struct usb_device *usb_dev = interface_to_usbdev(iface);
726
727 wa->usb_dev = usb_get_dev(usb_dev);
728 wa->usb_iface = usb_get_intf(iface);
729 wusbhc->dev = dev;
730
731
732 wusbhc->uwb_rc = NULL;
733 result = wa_fill_descr(wa);
734 if (result < 0)
735 goto error_fill_descriptor;
736 if (wa->wa_descr->bNumPorts > USB_MAXCHILDREN) {
737 dev_err(dev, "FIXME: USB_MAXCHILDREN too low for WUSB "
738 "adapter (%u ports)\n", wa->wa_descr->bNumPorts);
739 wusbhc->ports_max = USB_MAXCHILDREN;
740 } else {
741 wusbhc->ports_max = wa->wa_descr->bNumPorts;
742 }
743 wusbhc->mmcies_max = wa->wa_descr->bNumMMCIEs;
744 wusbhc->start = __hwahc_op_wusbhc_start;
745 wusbhc->stop = __hwahc_op_wusbhc_stop;
746 wusbhc->mmcie_add = __hwahc_op_mmcie_add;
747 wusbhc->mmcie_rm = __hwahc_op_mmcie_rm;
748 wusbhc->dev_info_set = __hwahc_op_dev_info_set;
749 wusbhc->bwa_set = __hwahc_op_bwa_set;
750 wusbhc->set_num_dnts = __hwahc_op_set_num_dnts;
751 wusbhc->set_ptk = __hwahc_op_set_ptk;
752 wusbhc->set_gtk = __hwahc_op_set_gtk;
753 result = hwahc_security_create(hwahc);
754 if (result < 0) {
755 dev_err(dev, "Can't initialize security: %d\n", result);
756 goto error_security_create;
757 }
758 wa->wusb = wusbhc;
759 result = wusbhc_create(&hwahc->wusbhc);
760 if (result < 0) {
761 dev_err(dev, "Can't create WUSB HC structures: %d\n", result);
762 goto error_wusbhc_create;
763 }
764 result = wa_create(&hwahc->wa, iface, quirks);
765 if (result < 0)
766 goto error_wa_create;
767 return 0;
768
769error_wa_create:
770 wusbhc_destroy(&hwahc->wusbhc);
771error_wusbhc_create:
772
773error_security_create:
774error_fill_descriptor:
775 usb_put_intf(iface);
776 usb_put_dev(usb_dev);
777 return result;
778}
779
780static void hwahc_destroy(struct hwahc *hwahc)
781{
782 struct wusbhc *wusbhc = &hwahc->wusbhc;
783
784 mutex_lock(&wusbhc->mutex);
785 __wa_destroy(&hwahc->wa);
786 wusbhc_destroy(&hwahc->wusbhc);
787 hwahc_security_release(hwahc);
788 hwahc->wusbhc.dev = NULL;
789 uwb_rc_put(wusbhc->uwb_rc);
790 usb_put_intf(hwahc->wa.usb_iface);
791 usb_put_dev(hwahc->wa.usb_dev);
792 mutex_unlock(&wusbhc->mutex);
793}
794
795static void hwahc_init(struct hwahc *hwahc)
796{
797 wa_init(&hwahc->wa);
798}
799
800static int hwahc_probe(struct usb_interface *usb_iface,
801 const struct usb_device_id *id)
802{
803 int result;
804 struct usb_hcd *usb_hcd;
805 struct wusbhc *wusbhc;
806 struct hwahc *hwahc;
807 struct device *dev = &usb_iface->dev;
808
809 result = -ENOMEM;
810 usb_hcd = usb_create_hcd(&hwahc_hc_driver, &usb_iface->dev, "wusb-hwa");
811 if (usb_hcd == NULL) {
812 dev_err(dev, "unable to allocate instance\n");
813 goto error_alloc;
814 }
815 usb_hcd->wireless = 1;
816 usb_hcd->self.sg_tablesize = ~0;
817 wusbhc = usb_hcd_to_wusbhc(usb_hcd);
818 hwahc = container_of(wusbhc, struct hwahc, wusbhc);
819 hwahc_init(hwahc);
820 result = hwahc_create(hwahc, usb_iface, id->driver_info);
821 if (result < 0) {
822 dev_err(dev, "Cannot initialize internals: %d\n", result);
823 goto error_hwahc_create;
824 }
825 result = usb_add_hcd(usb_hcd, 0, 0);
826 if (result < 0) {
827 dev_err(dev, "Cannot add HCD: %d\n", result);
828 goto error_add_hcd;
829 }
830 device_wakeup_enable(usb_hcd->self.controller);
831 result = wusbhc_b_create(&hwahc->wusbhc);
832 if (result < 0) {
833 dev_err(dev, "Cannot setup phase B of WUSBHC: %d\n", result);
834 goto error_wusbhc_b_create;
835 }
836 return 0;
837
838error_wusbhc_b_create:
839 usb_remove_hcd(usb_hcd);
840error_add_hcd:
841 hwahc_destroy(hwahc);
842error_hwahc_create:
843 usb_put_hcd(usb_hcd);
844error_alloc:
845 return result;
846}
847
848static void hwahc_disconnect(struct usb_interface *usb_iface)
849{
850 struct usb_hcd *usb_hcd;
851 struct wusbhc *wusbhc;
852 struct hwahc *hwahc;
853
854 usb_hcd = usb_get_intfdata(usb_iface);
855 wusbhc = usb_hcd_to_wusbhc(usb_hcd);
856 hwahc = container_of(wusbhc, struct hwahc, wusbhc);
857
858 wusbhc_b_destroy(&hwahc->wusbhc);
859 usb_remove_hcd(usb_hcd);
860 hwahc_destroy(hwahc);
861 usb_put_hcd(usb_hcd);
862}
863
864static const struct usb_device_id hwahc_id_table[] = {
865
866 { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5310, 0xe0, 0x02, 0x01),
867 .driver_info = WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC |
868 WUSB_QUIRK_ALEREON_HWA_DISABLE_XFER_NOTIFICATIONS },
869
870 { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5611, 0xe0, 0x02, 0x01),
871 .driver_info = WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC |
872 WUSB_QUIRK_ALEREON_HWA_DISABLE_XFER_NOTIFICATIONS },
873
874 { USB_INTERFACE_INFO(0xe0, 0x02, 0x01), },
875 {},
876};
877MODULE_DEVICE_TABLE(usb, hwahc_id_table);
878
879static struct usb_driver hwahc_driver = {
880 .name = "hwa-hc",
881 .probe = hwahc_probe,
882 .disconnect = hwahc_disconnect,
883 .id_table = hwahc_id_table,
884};
885
886module_usb_driver(hwahc_driver);
887
888MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>");
889MODULE_DESCRIPTION("Host Wired Adapter USB Host Control Driver");
890MODULE_LICENSE("GPL");
891