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