3 * Driver glue, HWA-specific functions, bridges to WAHC and WUSBHC
5 * Copyright (C) 2005-2006 Intel Corporation
6 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * The HWA driver is a simple layer that forwards requests to the WAHC
24 * (Wire Adater Host Controller) or WUSBHC (Wireless USB Host
27 * Host Wire Adapter is the 'WUSB 1.0 standard' name for Wireless-USB
28 * Host Controller that is connected to your system via USB (a USB
29 * dongle that implements a USB host...). There is also a Device Wired
30 * Adaptor, DWA (Wireless USB hub) that uses the same mechanism for
31 * transferring data (it is after all a USB host connected via
32 * Wireless USB), we have a common layer called Wire Adapter Host
33 * Controller that does all the hard work. The WUSBHC (Wireless USB
34 * Host Controller) is the part common to WUSB Host Controllers, the
35 * HWA and the PCI-based one, that is implemented following the WHCI
36 * spec. All these layers are implemented in ../wusbcore.
38 * The main functions are hwahc_op_urb_{en,de}queue(), that pass the
39 * job of converting a URB to a Wire Adapter
43 * hwahc_driver_*() Driver initialization, registration and
46 * hwahc_probe() New device came up, create an instance for
47 * it [from device enumeration].
49 * hwahc_disconnect() Remove device instance [from device
52 * [__]hwahc_op_*() Host-Wire-Adaptor specific functions for
53 * starting/stopping/etc (some might be made also
56 #include <linux/kernel.h>
57 #include <linux/init.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"
66 #include <linux/uwb/debug.h>
69 struct wusbhc wusbhc
; /* has to be 1st */
71 u8 buffer
[16]; /* for misc usb transactions */
75 * FIXME should be wusbhc
77 * NOTE: we need to cache the Cluster ID because later...there is no
80 static int __hwahc_set_cluster_id(struct hwahc
*hwahc
, u8 cluster_id
)
83 struct wusbhc
*wusbhc
= &hwahc
->wusbhc
;
84 struct wahc
*wa
= &hwahc
->wa
;
85 struct device
*dev
= &wa
->usb_iface
->dev
;
87 result
= usb_control_msg(wa
->usb_dev
, usb_sndctrlpipe(wa
->usb_dev
, 0),
88 WUSB_REQ_SET_CLUSTER_ID
,
89 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
91 wa
->usb_iface
->cur_altsetting
->desc
.bInterfaceNumber
,
92 NULL
, 0, 1000 /* FIXME: arbitrary */);
94 dev_err(dev
, "Cannot set WUSB Cluster ID to 0x%02x: %d\n",
97 wusbhc
->cluster_id
= cluster_id
;
98 dev_info(dev
, "Wireless USB Cluster ID set to 0x%02x\n", cluster_id
);
102 static int __hwahc_op_set_num_dnts(struct wusbhc
*wusbhc
, u8 interval
, u8 slots
)
104 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
105 struct wahc
*wa
= &hwahc
->wa
;
107 return usb_control_msg(wa
->usb_dev
, usb_sndctrlpipe(wa
->usb_dev
, 0),
108 WUSB_REQ_SET_NUM_DNTS
,
109 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
110 interval
<< 8 | slots
,
111 wa
->usb_iface
->cur_altsetting
->desc
.bInterfaceNumber
,
112 NULL
, 0, 1000 /* FIXME: arbitrary */);
116 * Reset a WUSB host controller and wait for it to complete doing it.
118 * @usb_hcd: Pointer to WUSB Host Controller instance.
121 static int hwahc_op_reset(struct usb_hcd
*usb_hcd
)
124 struct wusbhc
*wusbhc
= usb_hcd_to_wusbhc(usb_hcd
);
125 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
126 struct device
*dev
= &hwahc
->wa
.usb_iface
->dev
;
128 d_fnstart(4, dev
, "(hwahc %p)\n", hwahc
);
129 mutex_lock(&wusbhc
->mutex
);
130 wa_nep_disarm(&hwahc
->wa
);
131 result
= __wa_set_feature(&hwahc
->wa
, WA_RESET
);
133 dev_err(dev
, "error commanding HC to reset: %d\n", result
);
136 d_printf(3, dev
, "reset: waiting for device to change state\n");
137 result
= __wa_wait_status(&hwahc
->wa
, WA_STATUS_RESETTING
, 0);
139 dev_err(dev
, "error waiting for HC to reset: %d\n", result
);
143 mutex_unlock(&wusbhc
->mutex
);
144 d_fnend(4, dev
, "(hwahc %p) = %d\n", hwahc
, result
);
149 * FIXME: break this function up
151 static int hwahc_op_start(struct usb_hcd
*usb_hcd
)
155 struct wusbhc
*wusbhc
= usb_hcd_to_wusbhc(usb_hcd
);
156 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
157 struct device
*dev
= &hwahc
->wa
.usb_iface
->dev
;
159 /* Set up a Host Info WUSB Information Element */
160 d_fnstart(4, dev
, "(hwahc %p)\n", hwahc
);
162 mutex_lock(&wusbhc
->mutex
);
163 /* Start the numbering from the top so that the bottom
164 * range of the unauth addr space is used for devices,
165 * the top for HCs; use 0xfe - RC# */
166 addr
= wusb_cluster_id_get();
168 goto error_cluster_id_get
;
169 result
= __hwahc_set_cluster_id(hwahc
, addr
);
171 goto error_set_cluster_id
;
173 usb_hcd
->uses_new_polling
= 1;
174 usb_hcd
->poll_rh
= 1;
175 usb_hcd
->state
= HC_STATE_RUNNING
;
178 mutex_unlock(&wusbhc
->mutex
);
179 d_fnend(4, dev
, "(hwahc %p) = %d\n", hwahc
, result
);
182 error_set_cluster_id
:
183 wusb_cluster_id_put(wusbhc
->cluster_id
);
184 error_cluster_id_get
:
189 static int hwahc_op_suspend(struct usb_hcd
*usb_hcd
, pm_message_t msg
)
191 struct wusbhc
*wusbhc
= usb_hcd_to_wusbhc(usb_hcd
);
192 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
193 dev_err(wusbhc
->dev
, "%s (%p [%p], 0x%lx) UNIMPLEMENTED\n", __func__
,
194 usb_hcd
, hwahc
, *(unsigned long *) &msg
);
198 static int hwahc_op_resume(struct usb_hcd
*usb_hcd
)
200 struct wusbhc
*wusbhc
= usb_hcd_to_wusbhc(usb_hcd
);
201 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
203 dev_err(wusbhc
->dev
, "%s (%p [%p]) UNIMPLEMENTED\n", __func__
,
209 * No need to abort pipes, as when this is called, all the children
210 * has been disconnected and that has done it [through
211 * usb_disable_interface() -> usb_disable_endpoint() ->
212 * hwahc_op_ep_disable() - >rpipe_ep_disable()].
214 static void hwahc_op_stop(struct usb_hcd
*usb_hcd
)
217 struct wusbhc
*wusbhc
= usb_hcd_to_wusbhc(usb_hcd
);
218 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
219 struct wahc
*wa
= &hwahc
->wa
;
220 struct device
*dev
= &wa
->usb_iface
->dev
;
222 d_fnstart(4, dev
, "(hwahc %p)\n", hwahc
);
223 mutex_lock(&wusbhc
->mutex
);
225 wusb_cluster_id_put(wusbhc
->cluster_id
);
226 mutex_unlock(&wusbhc
->mutex
);
227 d_fnend(4, dev
, "(hwahc %p) = %d\n", hwahc
, result
);
231 static int hwahc_op_get_frame_number(struct usb_hcd
*usb_hcd
)
233 struct wusbhc
*wusbhc
= usb_hcd_to_wusbhc(usb_hcd
);
234 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
236 dev_err(wusbhc
->dev
, "%s (%p [%p]) UNIMPLEMENTED\n", __func__
,
241 static int hwahc_op_urb_enqueue(struct usb_hcd
*usb_hcd
, struct urb
*urb
,
244 struct wusbhc
*wusbhc
= usb_hcd_to_wusbhc(usb_hcd
);
245 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
247 return wa_urb_enqueue(&hwahc
->wa
, urb
->ep
, urb
, gfp
);
250 static int hwahc_op_urb_dequeue(struct usb_hcd
*usb_hcd
, struct urb
*urb
,
253 struct wusbhc
*wusbhc
= usb_hcd_to_wusbhc(usb_hcd
);
254 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
256 return wa_urb_dequeue(&hwahc
->wa
, urb
);
260 * Release resources allocated for an endpoint
262 * If there is an associated rpipe to this endpoint, go ahead and put it.
264 static void hwahc_op_endpoint_disable(struct usb_hcd
*usb_hcd
,
265 struct usb_host_endpoint
*ep
)
267 struct wusbhc
*wusbhc
= usb_hcd_to_wusbhc(usb_hcd
);
268 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
270 rpipe_ep_disable(&hwahc
->wa
, ep
);
273 static int __hwahc_op_wusbhc_start(struct wusbhc
*wusbhc
)
276 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
277 struct device
*dev
= &hwahc
->wa
.usb_iface
->dev
;
279 result
= __wa_set_feature(&hwahc
->wa
, WA_ENABLE
);
281 dev_err(dev
, "error commanding HC to start: %d\n", result
);
284 result
= __wa_wait_status(&hwahc
->wa
, WA_ENABLE
, WA_ENABLE
);
286 dev_err(dev
, "error waiting for HC to start: %d\n", result
);
289 result
= wa_nep_arm(&hwahc
->wa
, GFP_KERNEL
);
291 dev_err(dev
, "cannot listen to notifications: %d\n", result
);
297 __wa_clear_feature(&hwahc
->wa
, WA_ENABLE
);
301 static void __hwahc_op_wusbhc_stop(struct wusbhc
*wusbhc
, int delay
)
303 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
304 struct wahc
*wa
= &hwahc
->wa
;
305 u8 iface_no
= wa
->usb_iface
->cur_altsetting
->desc
.bInterfaceNumber
;
308 ret
= usb_control_msg(wa
->usb_dev
, usb_sndctrlpipe(wa
->usb_dev
, 0),
310 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
313 NULL
, 0, 1000 /* FIXME: arbitrary */);
317 wa_nep_disarm(&hwahc
->wa
);
318 __wa_stop(&hwahc
->wa
);
322 * Set the UWB MAS allocation for the WUSB cluster
324 * @stream_index: stream to use (-1 for cancelling the allocation)
325 * @mas: mas bitmap to use
327 static int __hwahc_op_bwa_set(struct wusbhc
*wusbhc
, s8 stream_index
,
328 const struct uwb_mas_bm
*mas
)
331 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
332 struct wahc
*wa
= &hwahc
->wa
;
333 struct device
*dev
= &wa
->usb_iface
->dev
;
334 u8 mas_le
[UWB_NUM_MAS
/8];
336 /* Set the stream index */
337 result
= usb_control_msg(wa
->usb_dev
, usb_sndctrlpipe(wa
->usb_dev
, 0),
338 WUSB_REQ_SET_STREAM_IDX
,
339 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
341 wa
->usb_iface
->cur_altsetting
->desc
.bInterfaceNumber
,
342 NULL
, 0, 1000 /* FIXME: arbitrary */);
344 dev_err(dev
, "Cannot set WUSB stream index: %d\n", result
);
347 uwb_mas_bm_copy_le(mas_le
, mas
);
348 /* Set the MAS allocation */
349 result
= usb_control_msg(wa
->usb_dev
, usb_sndctrlpipe(wa
->usb_dev
, 0),
350 WUSB_REQ_SET_WUSB_MAS
,
351 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
352 0, wa
->usb_iface
->cur_altsetting
->desc
.bInterfaceNumber
,
353 mas_le
, 32, 1000 /* FIXME: arbitrary */);
355 dev_err(dev
, "Cannot set WUSB MAS allocation: %d\n", result
);
361 * Add an IE to the host's MMC
363 * @interval: See WUSB1.0[8.5.3.1]
364 * @repeat_cnt: See WUSB1.0[8.5.3.1]
365 * @handle: See WUSB1.0[8.5.3.1]
366 * @wuie: Pointer to the header of the WUSB IE data to add.
367 * MUST BE allocated in a kmalloc buffer (no stack or
370 * NOTE: the format of the WUSB IEs for MMCs are different to the
371 * normal MBOA MAC IEs (IE Id + Length in MBOA MAC vs. Length +
372 * Id in WUSB IEs). Standards...you gotta love'em.
374 static int __hwahc_op_mmcie_add(struct wusbhc
*wusbhc
, u8 interval
,
375 u8 repeat_cnt
, u8 handle
,
376 struct wuie_hdr
*wuie
)
378 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
379 struct wahc
*wa
= &hwahc
->wa
;
380 u8 iface_no
= wa
->usb_iface
->cur_altsetting
->desc
.bInterfaceNumber
;
382 return usb_control_msg(wa
->usb_dev
, usb_sndctrlpipe(wa
->usb_dev
, 0),
384 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
385 interval
<< 8 | repeat_cnt
,
386 handle
<< 8 | iface_no
,
387 wuie
, wuie
->bLength
, 1000 /* FIXME: arbitrary */);
391 * Remove an IE to the host's MMC
393 * @handle: See WUSB1.0[8.5.3.1]
395 static int __hwahc_op_mmcie_rm(struct wusbhc
*wusbhc
, u8 handle
)
397 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
398 struct wahc
*wa
= &hwahc
->wa
;
399 u8 iface_no
= wa
->usb_iface
->cur_altsetting
->desc
.bInterfaceNumber
;
400 return usb_control_msg(wa
->usb_dev
, usb_sndctrlpipe(wa
->usb_dev
, 0),
401 WUSB_REQ_REMOVE_MMC_IE
,
402 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
403 0, handle
<< 8 | iface_no
,
404 NULL
, 0, 1000 /* FIXME: arbitrary */);
408 * Update device information for a given fake port
410 * @port_idx: Fake port to which device is connected (wusbhc index, not
413 static int __hwahc_op_dev_info_set(struct wusbhc
*wusbhc
,
414 struct wusb_dev
*wusb_dev
)
416 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
417 struct wahc
*wa
= &hwahc
->wa
;
418 u8 iface_no
= wa
->usb_iface
->cur_altsetting
->desc
.bInterfaceNumber
;
419 struct hwa_dev_info
*dev_info
;
422 /* fill out the Device Info buffer and send it */
423 dev_info
= kzalloc(sizeof(struct hwa_dev_info
), GFP_KERNEL
);
426 uwb_mas_bm_copy_le(dev_info
->bmDeviceAvailability
,
427 &wusb_dev
->availability
);
428 dev_info
->bDeviceAddress
= wusb_dev
->addr
;
431 * If the descriptors haven't been read yet, use a default PHY
432 * rate of 53.3 Mbit/s only. The correct value will be used
433 * when this will be called again as part of the
434 * authentication process (which occurs after the descriptors
437 if (wusb_dev
->wusb_cap_descr
)
438 dev_info
->wPHYRates
= wusb_dev
->wusb_cap_descr
->wPHYRates
;
440 dev_info
->wPHYRates
= cpu_to_le16(USB_WIRELESS_PHY_53
);
442 ret
= usb_control_msg(wa
->usb_dev
, usb_sndctrlpipe(wa
->usb_dev
, 0),
443 WUSB_REQ_SET_DEV_INFO
,
444 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
445 0, wusb_dev
->port_idx
<< 8 | iface_no
,
446 dev_info
, sizeof(struct hwa_dev_info
),
447 1000 /* FIXME: arbitrary */);
453 * Set host's idea of which encryption (and key) method to use when
454 * talking to ad evice on a given port.
456 * If key is NULL, it means disable encryption for that "virtual port"
457 * (used when we disconnect).
459 static int __hwahc_dev_set_key(struct wusbhc
*wusbhc
, u8 port_idx
, u32 tkid
,
460 const void *key
, size_t key_size
,
463 int result
= -ENOMEM
;
464 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
465 struct wahc
*wa
= &hwahc
->wa
;
466 u8 iface_no
= wa
->usb_iface
->cur_altsetting
->desc
.bInterfaceNumber
;
467 struct usb_key_descriptor
*keyd
;
470 keyd_len
= sizeof(*keyd
) + key_size
;
471 keyd
= kzalloc(keyd_len
, GFP_KERNEL
);
475 keyd
->bLength
= keyd_len
;
476 keyd
->bDescriptorType
= USB_DT_KEY
;
477 keyd
->tTKID
[0] = (tkid
>> 0) & 0xff;
478 keyd
->tTKID
[1] = (tkid
>> 8) & 0xff;
479 keyd
->tTKID
[2] = (tkid
>> 16) & 0xff;
480 memcpy(keyd
->bKeyData
, key
, key_size
);
482 result
= usb_control_msg(wa
->usb_dev
, usb_sndctrlpipe(wa
->usb_dev
, 0),
483 USB_REQ_SET_DESCRIPTOR
,
484 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
485 USB_DT_KEY
<< 8 | key_idx
,
486 port_idx
<< 8 | iface_no
,
487 keyd
, keyd_len
, 1000 /* FIXME: arbitrary */);
489 memset(keyd
, 0, sizeof(*keyd
)); /* clear keys etc. */
495 * Set host's idea of which encryption (and key) method to use when
496 * talking to ad evice on a given port.
498 * If key is NULL, it means disable encryption for that "virtual port"
499 * (used when we disconnect).
501 static int __hwahc_op_set_ptk(struct wusbhc
*wusbhc
, u8 port_idx
, u32 tkid
,
502 const void *key
, size_t key_size
)
504 int result
= -ENOMEM
;
505 struct hwahc
*hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
506 struct wahc
*wa
= &hwahc
->wa
;
507 u8 iface_no
= wa
->usb_iface
->cur_altsetting
->desc
.bInterfaceNumber
;
510 /* Tell the host which key to use to talk to the device */
512 u8 key_idx
= wusb_key_index(0, WUSB_KEY_INDEX_TYPE_PTK
,
513 WUSB_KEY_INDEX_ORIGINATOR_HOST
);
515 result
= __hwahc_dev_set_key(wusbhc
, port_idx
, tkid
,
516 key
, key_size
, key_idx
);
519 encryption_value
= wusbhc
->ccm1_etd
->bEncryptionValue
;
521 /* FIXME: this should come from wusbhc->etd[UNSECURE].value */
522 encryption_value
= 0;
525 /* Set the encryption type for commmunicating with the device */
526 result
= usb_control_msg(wa
->usb_dev
, usb_sndctrlpipe(wa
->usb_dev
, 0),
527 USB_REQ_SET_ENCRYPTION
,
528 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
529 encryption_value
, port_idx
<< 8 | iface_no
,
530 NULL
, 0, 1000 /* FIXME: arbitrary */);
532 dev_err(wusbhc
->dev
, "Can't set host's WUSB encryption for "
533 "port index %u to %s (value %d): %d\n", port_idx
,
534 wusb_et_name(wusbhc
->ccm1_etd
->bEncryptionType
),
535 wusbhc
->ccm1_etd
->bEncryptionValue
, result
);
543 static int __hwahc_op_set_gtk(struct wusbhc
*wusbhc
, u32 tkid
,
544 const void *key
, size_t key_size
)
546 u8 key_idx
= wusb_key_index(0, WUSB_KEY_INDEX_TYPE_GTK
,
547 WUSB_KEY_INDEX_ORIGINATOR_HOST
);
549 return __hwahc_dev_set_key(wusbhc
, 0, tkid
, key
, key_size
, key_idx
);
553 * Get the Wire Adapter class-specific descriptor
555 * NOTE: this descriptor comes with the big bundled configuration
556 * descriptor that includes the interfaces' and endpoints', so
557 * we just look for it in the cached copy kept by the USB stack.
559 * NOTE2: We convert LE fields to CPU order.
561 static int wa_fill_descr(struct wahc
*wa
)
564 struct device
*dev
= &wa
->usb_iface
->dev
;
566 struct usb_device
*usb_dev
= wa
->usb_dev
;
567 struct usb_descriptor_header
*hdr
;
568 struct usb_wa_descriptor
*wa_descr
;
569 size_t itr_size
, actconfig_idx
;
571 actconfig_idx
= (usb_dev
->actconfig
- usb_dev
->config
) /
572 sizeof(usb_dev
->config
[0]);
573 itr
= usb_dev
->rawdescriptors
[actconfig_idx
];
574 itr_size
= le16_to_cpu(usb_dev
->actconfig
->desc
.wTotalLength
);
575 while (itr_size
>= sizeof(*hdr
)) {
576 hdr
= (struct usb_descriptor_header
*) itr
;
577 d_printf(3, dev
, "Extra device descriptor: "
578 "type %02x/%u bytes @ %zu (%zu left)\n",
579 hdr
->bDescriptorType
, hdr
->bLength
,
580 (itr
- usb_dev
->rawdescriptors
[actconfig_idx
]),
582 if (hdr
->bDescriptorType
== USB_DT_WIRE_ADAPTER
)
585 itr_size
-= hdr
->bLength
;
587 dev_err(dev
, "cannot find Wire Adapter Class descriptor\n");
592 if (hdr
->bLength
> itr_size
) { /* is it available? */
593 dev_err(dev
, "incomplete Wire Adapter Class descriptor "
594 "(%zu bytes left, %u needed)\n",
595 itr_size
, hdr
->bLength
);
598 if (hdr
->bLength
< sizeof(*wa
->wa_descr
)) {
599 dev_err(dev
, "short Wire Adapter Class descriptor\n");
602 wa
->wa_descr
= wa_descr
= (struct usb_wa_descriptor
*) hdr
;
603 /* Make LE fields CPU order */
604 wa_descr
->bcdWAVersion
= le16_to_cpu(wa_descr
->bcdWAVersion
);
605 wa_descr
->wNumRPipes
= le16_to_cpu(wa_descr
->wNumRPipes
);
606 wa_descr
->wRPipeMaxBlock
= le16_to_cpu(wa_descr
->wRPipeMaxBlock
);
607 if (wa_descr
->bcdWAVersion
> 0x0100)
608 dev_warn(dev
, "Wire Adapter v%d.%d newer than groked v1.0\n",
609 wa_descr
->bcdWAVersion
& 0xff00 >> 8,
610 wa_descr
->bcdWAVersion
& 0x00ff);
616 static struct hc_driver hwahc_hc_driver
= {
617 .description
= "hwa-hcd",
618 .product_desc
= "Wireless USB HWA host controller",
619 .hcd_priv_size
= sizeof(struct hwahc
) - sizeof(struct usb_hcd
),
620 .irq
= NULL
, /* FIXME */
621 .flags
= HCD_USB2
, /* FIXME */
622 .reset
= hwahc_op_reset
,
623 .start
= hwahc_op_start
,
624 .pci_suspend
= hwahc_op_suspend
,
625 .pci_resume
= hwahc_op_resume
,
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
,
632 .hub_status_data
= wusbhc_rh_status_data
,
633 .hub_control
= wusbhc_rh_control
,
634 .bus_suspend
= wusbhc_rh_suspend
,
635 .bus_resume
= wusbhc_rh_resume
,
636 .start_port_reset
= wusbhc_rh_start_port_reset
,
639 static int hwahc_security_create(struct hwahc
*hwahc
)
642 struct wusbhc
*wusbhc
= &hwahc
->wusbhc
;
643 struct usb_device
*usb_dev
= hwahc
->wa
.usb_dev
;
644 struct device
*dev
= &usb_dev
->dev
;
645 struct usb_security_descriptor
*secd
;
646 struct usb_encryption_descriptor
*etd
;
648 size_t itr_size
, needed
, bytes
;
652 /* Find the host's security descriptors in the config descr bundle */
653 index
= (usb_dev
->actconfig
- usb_dev
->config
) /
654 sizeof(usb_dev
->config
[0]);
655 itr
= usb_dev
->rawdescriptors
[index
];
656 itr_size
= le16_to_cpu(usb_dev
->actconfig
->desc
.wTotalLength
);
657 top
= itr
+ itr_size
;
658 result
= __usb_get_extra_descriptor(usb_dev
->rawdescriptors
[index
],
659 le16_to_cpu(usb_dev
->actconfig
->desc
.wTotalLength
),
660 USB_DT_SECURITY
, (void **) &secd
);
662 dev_warn(dev
, "BUG? WUSB host has no security descriptors\n");
665 needed
= sizeof(*secd
);
666 if (top
- (void *)secd
< needed
) {
667 dev_err(dev
, "BUG? Not enough data to process security "
668 "descriptor header (%zu bytes left vs %zu needed)\n",
669 top
- (void *) secd
, needed
);
672 needed
= le16_to_cpu(secd
->wTotalLength
);
673 if (top
- (void *)secd
< needed
) {
674 dev_err(dev
, "BUG? Not enough data to process security "
675 "descriptors (%zu bytes left vs %zu needed)\n",
676 top
- (void *) secd
, needed
);
679 /* Walk over the sec descriptors and store CCM1's on wusbhc */
680 itr
= (void *) secd
+ sizeof(*secd
);
681 top
= (void *) secd
+ le16_to_cpu(secd
->wTotalLength
);
686 if (top
- itr
< sizeof(*etd
)) {
687 dev_err(dev
, "BUG: bad host security descriptor; "
688 "not enough data (%zu vs %zu left)\n",
689 top
- itr
, sizeof(*etd
));
692 if (etd
->bLength
< sizeof(*etd
)) {
693 dev_err(dev
, "BUG: bad host encryption descriptor; "
694 "descriptor is too short "
695 "(%zu vs %zu needed)\n",
696 (size_t)etd
->bLength
, sizeof(*etd
));
700 bytes
+= snprintf(buf
+ bytes
, sizeof(buf
) - bytes
,
702 wusb_et_name(etd
->bEncryptionType
),
703 etd
->bEncryptionValue
);
704 wusbhc
->ccm1_etd
= etd
;
706 dev_info(dev
, "supported encryption types: %s\n", buf
);
707 if (wusbhc
->ccm1_etd
== NULL
) {
708 dev_err(dev
, "E: host doesn't support CCM-1 crypto\n");
711 /* Pretty print what we support */
715 static void hwahc_security_release(struct hwahc
*hwahc
)
717 /* nothing to do here so far... */
720 static int hwahc_create(struct hwahc
*hwahc
, struct usb_interface
*iface
)
723 struct device
*dev
= &iface
->dev
;
724 struct wusbhc
*wusbhc
= &hwahc
->wusbhc
;
725 struct wahc
*wa
= &hwahc
->wa
;
726 struct usb_device
*usb_dev
= interface_to_usbdev(iface
);
728 wa
->usb_dev
= usb_get_dev(usb_dev
); /* bind the USB device */
729 wa
->usb_iface
= usb_get_intf(iface
);
731 wusbhc
->uwb_rc
= uwb_rc_get_by_grandpa(iface
->dev
.parent
);
732 if (wusbhc
->uwb_rc
== NULL
) {
734 dev_err(dev
, "Cannot get associated UWB Host Controller\n");
737 result
= wa_fill_descr(wa
); /* Get the device descriptor */
739 goto error_fill_descriptor
;
740 if (wa
->wa_descr
->bNumPorts
> USB_MAXCHILDREN
) {
741 dev_err(dev
, "FIXME: USB_MAXCHILDREN too low for WUSB "
742 "adapter (%u ports)\n", wa
->wa_descr
->bNumPorts
);
743 wusbhc
->ports_max
= USB_MAXCHILDREN
;
745 wusbhc
->ports_max
= wa
->wa_descr
->bNumPorts
;
747 wusbhc
->mmcies_max
= wa
->wa_descr
->bNumMMCIEs
;
748 wusbhc
->start
= __hwahc_op_wusbhc_start
;
749 wusbhc
->stop
= __hwahc_op_wusbhc_stop
;
750 wusbhc
->mmcie_add
= __hwahc_op_mmcie_add
;
751 wusbhc
->mmcie_rm
= __hwahc_op_mmcie_rm
;
752 wusbhc
->dev_info_set
= __hwahc_op_dev_info_set
;
753 wusbhc
->bwa_set
= __hwahc_op_bwa_set
;
754 wusbhc
->set_num_dnts
= __hwahc_op_set_num_dnts
;
755 wusbhc
->set_ptk
= __hwahc_op_set_ptk
;
756 wusbhc
->set_gtk
= __hwahc_op_set_gtk
;
757 result
= hwahc_security_create(hwahc
);
759 dev_err(dev
, "Can't initialize security: %d\n", result
);
760 goto error_security_create
;
762 wa
->wusb
= wusbhc
; /* FIXME: ugly, need to fix */
763 result
= wusbhc_create(&hwahc
->wusbhc
);
765 dev_err(dev
, "Can't create WUSB HC structures: %d\n", result
);
766 goto error_wusbhc_create
;
768 result
= wa_create(&hwahc
->wa
, iface
);
770 goto error_wa_create
;
774 wusbhc_destroy(&hwahc
->wusbhc
);
776 /* WA Descr fill allocs no resources */
777 error_security_create
:
778 error_fill_descriptor
:
779 uwb_rc_put(wusbhc
->uwb_rc
);
782 usb_put_dev(usb_dev
);
786 static void hwahc_destroy(struct hwahc
*hwahc
)
788 struct wusbhc
*wusbhc
= &hwahc
->wusbhc
;
790 d_fnstart(1, NULL
, "(hwahc %p)\n", hwahc
);
791 mutex_lock(&wusbhc
->mutex
);
792 __wa_destroy(&hwahc
->wa
);
793 wusbhc_destroy(&hwahc
->wusbhc
);
794 hwahc_security_release(hwahc
);
795 hwahc
->wusbhc
.dev
= NULL
;
796 uwb_rc_put(wusbhc
->uwb_rc
);
797 usb_put_intf(hwahc
->wa
.usb_iface
);
798 usb_put_dev(hwahc
->wa
.usb_dev
);
799 mutex_unlock(&wusbhc
->mutex
);
800 d_fnend(1, NULL
, "(hwahc %p) = void\n", hwahc
);
803 static void hwahc_init(struct hwahc
*hwahc
)
808 static int hwahc_probe(struct usb_interface
*usb_iface
,
809 const struct usb_device_id
*id
)
812 struct usb_hcd
*usb_hcd
;
813 struct wusbhc
*wusbhc
;
815 struct device
*dev
= &usb_iface
->dev
;
817 d_fnstart(4, dev
, "(%p, %p)\n", usb_iface
, id
);
819 usb_hcd
= usb_create_hcd(&hwahc_hc_driver
, &usb_iface
->dev
, "wusb-hwa");
820 if (usb_hcd
== NULL
) {
821 dev_err(dev
, "unable to allocate instance\n");
824 usb_hcd
->wireless
= 1;
825 usb_hcd
->flags
|= HCD_FLAG_SAW_IRQ
;
826 wusbhc
= usb_hcd_to_wusbhc(usb_hcd
);
827 hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
829 result
= hwahc_create(hwahc
, usb_iface
);
831 dev_err(dev
, "Cannot initialize internals: %d\n", result
);
832 goto error_hwahc_create
;
834 result
= usb_add_hcd(usb_hcd
, 0, 0);
836 dev_err(dev
, "Cannot add HCD: %d\n", result
);
839 result
= wusbhc_b_create(&hwahc
->wusbhc
);
841 dev_err(dev
, "Cannot setup phase B of WUSBHC: %d\n", result
);
842 goto error_wusbhc_b_create
;
844 d_fnend(4, dev
, "(%p, %p) = 0\n", usb_iface
, id
);
847 error_wusbhc_b_create
:
848 usb_remove_hcd(usb_hcd
);
850 hwahc_destroy(hwahc
);
852 usb_put_hcd(usb_hcd
);
854 d_fnend(4, dev
, "(%p, %p) = %d\n", usb_iface
, id
, result
);
858 static void hwahc_disconnect(struct usb_interface
*usb_iface
)
860 struct usb_hcd
*usb_hcd
;
861 struct wusbhc
*wusbhc
;
864 usb_hcd
= usb_get_intfdata(usb_iface
);
865 wusbhc
= usb_hcd_to_wusbhc(usb_hcd
);
866 hwahc
= container_of(wusbhc
, struct hwahc
, wusbhc
);
868 d_fnstart(1, NULL
, "(hwahc %p [usb_iface %p])\n", hwahc
, usb_iface
);
869 wusbhc_b_destroy(&hwahc
->wusbhc
);
870 usb_remove_hcd(usb_hcd
);
871 hwahc_destroy(hwahc
);
872 usb_put_hcd(usb_hcd
);
873 d_fnend(1, NULL
, "(hwahc %p [usb_iface %p]) = void\n", hwahc
,
877 /** USB device ID's that we handle */
878 static struct usb_device_id hwahc_id_table
[] = {
879 /* FIXME: use class labels for this */
880 { USB_INTERFACE_INFO(0xe0, 0x02, 0x01), },
883 MODULE_DEVICE_TABLE(usb
, hwahc_id_table
);
885 static struct usb_driver hwahc_driver
= {
887 .probe
= hwahc_probe
,
888 .disconnect
= hwahc_disconnect
,
889 .id_table
= hwahc_id_table
,
892 static int __init
hwahc_driver_init(void)
895 result
= usb_register(&hwahc_driver
);
897 printk(KERN_ERR
"WA-CDS: Cannot register USB driver: %d\n",
899 goto error_usb_register
;
907 module_init(hwahc_driver_init
);
909 static void __exit
hwahc_driver_exit(void)
911 usb_deregister(&hwahc_driver
);
913 module_exit(hwahc_driver_exit
);
916 MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>");
917 MODULE_DESCRIPTION("Host Wired Adapter USB Host Control Driver");
918 MODULE_LICENSE("GPL");