2 * Wireless USB Host Controller
3 * Common infrastructure for WHCI and HWA WUSB-HC drivers
6 * Copyright (C) 2005-2006 Intel Corporation
7 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License version
11 * 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * This driver implements parts common to all Wireless USB Host
25 * Controllers (struct wusbhc, embedding a struct usb_hcd) and is used
28 * - hwahc: HWA, USB-dongle that implements a Wireless USB host
29 * controller, (Wireless USB 1.0 Host-Wire-Adapter specification).
31 * - whci: WHCI, a PCI card with a wireless host controller
32 * (Wireless Host Controller Interface 1.0 specification).
34 * Check out the Design-overview.txt file in the source documentation
35 * for other details on the implementation.
39 * rh Root Hub emulation (part of the HCD glue)
41 * devconnect Handle all the issues related to device connection,
42 * authentication, disconnection, timeout, reseting,
45 * mmc MMC IE broadcasting handling
47 * A host controller driver just initializes its stuff and as part of
48 * that, creates a 'struct wusbhc' instance that handles all the
49 * common WUSB mechanisms. Links in the function ops that are specific
50 * to it and then registers the host controller. Ready to run.
56 #include <linux/usb.h>
57 #include <linux/list.h>
58 #include <linux/mutex.h>
59 #include <linux/kref.h>
60 #include <linux/workqueue.h>
61 #include <linux/usb/hcd.h>
62 #include <linux/uwb.h>
63 #include <linux/usb/wusb.h>
66 * Time from a WUSB channel stop request to the last transmitted MMC.
68 * This needs to be > 4.096 ms in case no MMCs can be transmitted in
71 #define WUSB_CHANNEL_STOP_DELAY_MS 8
75 struct wusbhc
*wusbhc
;
76 struct list_head cack_node
; /* Connect-Ack list */
80 struct usb_encryption_descriptor ccm1_etd
;
81 struct wusb_ckhdid cdid
;
82 unsigned long entry_ts
;
83 struct usb_bos_descriptor
*bos
;
84 struct usb_wireless_cap_descriptor
*wusb_cap_descr
;
85 struct uwb_mas_bm availability
;
86 struct work_struct devconnect_acked_work
;
87 struct urb
*set_gtk_urb
;
88 struct usb_ctrlrequest
*set_gtk_req
;
89 struct usb_device
*usb_dev
;
92 #define WUSB_DEV_ADDR_UNAUTH 0x80
94 static inline void wusb_dev_init(struct wusb_dev
*wusb_dev
)
96 kref_init(&wusb_dev
->refcnt
);
97 /* no need to init the cack_node */
100 extern void wusb_dev_destroy(struct kref
*_wusb_dev
);
102 static inline struct wusb_dev
*wusb_dev_get(struct wusb_dev
*wusb_dev
)
104 kref_get(&wusb_dev
->refcnt
);
108 static inline void wusb_dev_put(struct wusb_dev
*wusb_dev
)
110 kref_put(&wusb_dev
->refcnt
, wusb_dev_destroy
);
114 * Wireless USB Host Controlller root hub "fake" ports
115 * (state and device information)
117 * Wireless USB is wireless, so there are no ports; but we
118 * fake'em. Each RC can connect a max of devices at the same time
119 * (given in the Wireless Adapter descriptor, bNumPorts or WHCI's
120 * caps), referred to in wusbhc->ports_max.
122 * See rh.c for more information.
124 * The @status and @change use the same bits as in USB2.0[11.24.2.7],
125 * so we don't have to do much when getting the port's status.
127 * WUSB1.0[7.1], USB2.0[11.24.2.7.1,fig 11-10],
128 * include/linux/usb_ch9.h (#define USB_PORT_STAT_*)
133 struct wusb_dev
*wusb_dev
; /* connected device's info */
138 * WUSB Host Controller specifics
140 * All fields that are common to all Wireless USB controller types
141 * (HWA and WHCI) are grouped here. Host Controller
142 * functions/operations that only deal with general Wireless USB HC
143 * issues use this data type to refer to the host.
145 * @usb_hcd Instantiation of a USB host controller
146 * (initialized by upper layer [HWA=HC or WHCI].
148 * @dev Device that implements this; initialized by the
149 * upper layer (HWA-HC, WHCI...); this device should
152 * @trust_timeout After this time without hearing for device
153 * activity, we consider the device gone and we have to
156 * Can be accessed w/o locking--however, read to a
157 * local variable then use.
159 * @chid WUSB Cluster Host ID: this is supposed to be a
160 * unique value that doesn't change across reboots (so
161 * that your devices do not require re-association).
163 * Read/Write protected by @mutex
165 * @dev_info This array has ports_max elements. It is used to
166 * give the HC information about the WUSB devices (see
167 * 'struct wusb_dev_info').
169 * For HWA we need to allocate it in heap; for WHCI it
170 * needs to be permanently mapped, so we keep it for
171 * both and make it easy. Call wusbhc->dev_info_set()
172 * to update an entry.
174 * @ports_max Number of simultaneous device connections (fake
175 * ports) this HC will take. Read-only.
177 * @port Array of port status for each fake root port. Guaranteed to
178 * always be the same length during device existence
179 * [this allows for some unlocked but referenced reading].
181 * @mmcies_max Max number of Information Elements this HC can send
182 * in its MMC. Read-only.
184 * @start Start the WUSB channel.
186 * @stop Stop the WUSB channel after the specified number of
187 * milliseconds. Channel Stop IEs should be transmitted
188 * as required by [WUSB] 4.16.2.1.
190 * @mmcie_add HC specific operation (WHCI or HWA) for adding an
193 * @mmcie_rm HC specific operation (WHCI or HWA) for removing an
196 * @set_ptk: Set the PTK and enable encryption for a device. Or, if
197 * the supplied key is NULL, disable encryption for that
200 * @set_gtk: Set the GTK to be used for all future broadcast packets
201 * (i.e., MMCs). With some hardware, setting the GTK may start
206 * - If wusb_dev->usb_dev is not NULL, then usb_dev is valid
207 * (wusb_dev has a refcount on it). Likewise, if usb_dev->wusb_dev
208 * is not NULL, usb_dev->wusb_dev is valid (usb_dev keeps a
211 * Most of the times when you need to use it, it will be non-NULL,
212 * so there is no real need to check for it (wusb_dev will
213 * dissapear before usb_dev).
215 * - The following fields need to be filled out before calling
216 * wusbhc_create(): ports_max, mmcies_max, mmcie_{add,rm}.
218 * - there is no wusbhc_init() method, we do everything in
221 * - Creation is done in two phases, wusbhc_create() and
222 * wusbhc_create_b(); b are the parts that need to be called after
223 * calling usb_hcd_add(&wusbhc->usb_hcd).
226 struct usb_hcd usb_hcd
; /* HAS TO BE 1st */
228 struct uwb_rc
*uwb_rc
;
231 unsigned trust_timeout
; /* in jiffies */
232 struct wusb_ckhdid chid
;
234 struct wuie_host_info
*wuie_host_info
;
236 struct mutex mutex
; /* locks everything else */
237 u16 cluster_id
; /* Wireless USB Cluster ID */
238 struct wusb_port
*port
; /* Fake port status handling */
239 struct wusb_dev_info
*dev_info
; /* for Set Device Info mgmt */
241 unsigned active
:1; /* currently xmit'ing MMCs */
242 struct wuie_keep_alive keep_alive_ie
; /* protected by mutex */
243 struct delayed_work keep_alive_timer
;
244 struct list_head cack_list
; /* Connect acknowledging */
245 size_t cack_count
; /* protected by 'mutex' */
246 struct wuie_connect_ack cack_ie
;
247 struct uwb_rsv
*rsv
; /* cluster bandwidth reservation */
249 struct mutex mmcie_mutex
; /* MMC WUIE handling */
250 struct wuie_hdr
**mmcie
; /* WUIE array */
252 int (*start
)(struct wusbhc
*wusbhc
);
253 void (*stop
)(struct wusbhc
*wusbhc
, int delay
);
254 int (*mmcie_add
)(struct wusbhc
*wusbhc
, u8 interval
, u8 repeat_cnt
,
255 u8 handle
, struct wuie_hdr
*wuie
);
256 int (*mmcie_rm
)(struct wusbhc
*wusbhc
, u8 handle
);
257 int (*dev_info_set
)(struct wusbhc
*, struct wusb_dev
*wusb_dev
);
258 int (*bwa_set
)(struct wusbhc
*wusbhc
, s8 stream_index
,
259 const struct uwb_mas_bm
*);
260 int (*set_ptk
)(struct wusbhc
*wusbhc
, u8 port_idx
,
261 u32 tkid
, const void *key
, size_t key_size
);
262 int (*set_gtk
)(struct wusbhc
*wusbhc
,
263 u32 tkid
, const void *key
, size_t key_size
);
264 int (*set_num_dnts
)(struct wusbhc
*wusbhc
, u8 interval
, u8 slots
);
267 struct usb_key_descriptor descr
;
268 u8 data
[16]; /* GTK key data */
269 } __attribute__((packed
)) gtk
;
272 struct work_struct gtk_rekey_done_work
;
273 int pending_set_gtks
;
275 struct usb_encryption_descriptor
*ccm1_etd
;
278 #define usb_hcd_to_wusbhc(u) container_of((u), struct wusbhc, usb_hcd)
281 extern int wusbhc_create(struct wusbhc
*);
282 extern int wusbhc_b_create(struct wusbhc
*);
283 extern void wusbhc_b_destroy(struct wusbhc
*);
284 extern void wusbhc_destroy(struct wusbhc
*);
285 extern int wusb_dev_sysfs_add(struct wusbhc
*, struct usb_device
*,
287 extern void wusb_dev_sysfs_rm(struct wusb_dev
*);
288 extern int wusbhc_sec_create(struct wusbhc
*);
289 extern int wusbhc_sec_start(struct wusbhc
*);
290 extern void wusbhc_sec_stop(struct wusbhc
*);
291 extern void wusbhc_sec_destroy(struct wusbhc
*);
292 extern void wusbhc_giveback_urb(struct wusbhc
*wusbhc
, struct urb
*urb
,
294 void wusbhc_reset_all(struct wusbhc
*wusbhc
);
296 int wusbhc_pal_register(struct wusbhc
*wusbhc
);
297 void wusbhc_pal_unregister(struct wusbhc
*wusbhc
);
300 * Return @usb_dev's @usb_hcd (properly referenced) or NULL if gone
302 * @usb_dev: USB device, UNLOCKED and referenced (or otherwise, safe ptr)
304 * This is a safe assumption as @usb_dev->bus is referenced all the
305 * time during the @usb_dev life cycle.
307 static inline struct usb_hcd
*usb_hcd_get_by_usb_dev(struct usb_device
*usb_dev
)
309 struct usb_hcd
*usb_hcd
;
310 usb_hcd
= container_of(usb_dev
->bus
, struct usb_hcd
, self
);
311 return usb_get_hcd(usb_hcd
);
315 * Increment the reference count on a wusbhc.
317 * @wusbhc's life cycle is identical to that of the underlying usb_hcd.
319 static inline struct wusbhc
*wusbhc_get(struct wusbhc
*wusbhc
)
321 return usb_get_hcd(&wusbhc
->usb_hcd
) ? wusbhc
: NULL
;
324 static inline struct wusbhc
*wusbhc_get_by_usb_dev(struct usb_device
*usb_dev
)
326 struct wusbhc
*wusbhc
= NULL
;
327 struct usb_hcd
*usb_hcd
;
328 if (usb_dev
->devnum
> 1 && !usb_dev
->wusb
) {
330 dev_err(&usb_dev
->dev
, "devnum %d wusb %d\n", usb_dev
->devnum
,
332 BUG_ON(usb_dev
->devnum
> 1 && !usb_dev
->wusb
);
334 usb_hcd
= usb_hcd_get_by_usb_dev(usb_dev
);
337 BUG_ON(usb_hcd
->wireless
== 0);
338 return wusbhc
= usb_hcd_to_wusbhc(usb_hcd
);
342 static inline void wusbhc_put(struct wusbhc
*wusbhc
)
344 usb_put_hcd(&wusbhc
->usb_hcd
);
347 int wusbhc_start(struct wusbhc
*wusbhc
);
348 void wusbhc_stop(struct wusbhc
*wusbhc
);
349 extern int wusbhc_chid_set(struct wusbhc
*, const struct wusb_ckhdid
*);
351 /* Device connect handling */
352 extern int wusbhc_devconnect_create(struct wusbhc
*);
353 extern void wusbhc_devconnect_destroy(struct wusbhc
*);
354 extern int wusbhc_devconnect_start(struct wusbhc
*wusbhc
);
355 extern void wusbhc_devconnect_stop(struct wusbhc
*wusbhc
);
356 extern void wusbhc_handle_dn(struct wusbhc
*, u8 srcaddr
,
357 struct wusb_dn_hdr
*dn_hdr
, size_t size
);
358 extern void __wusbhc_dev_disable(struct wusbhc
*wusbhc
, u8 port
);
359 extern int wusb_usb_ncb(struct notifier_block
*nb
, unsigned long val
,
361 extern int wusb_set_dev_addr(struct wusbhc
*wusbhc
, struct wusb_dev
*wusb_dev
,
364 /* Wireless USB fake Root Hub methods */
365 extern int wusbhc_rh_create(struct wusbhc
*);
366 extern void wusbhc_rh_destroy(struct wusbhc
*);
368 extern int wusbhc_rh_status_data(struct usb_hcd
*, char *);
369 extern int wusbhc_rh_control(struct usb_hcd
*, u16
, u16
, u16
, char *, u16
);
370 extern int wusbhc_rh_suspend(struct usb_hcd
*);
371 extern int wusbhc_rh_resume(struct usb_hcd
*);
372 extern int wusbhc_rh_start_port_reset(struct usb_hcd
*, unsigned);
375 extern int wusbhc_mmcie_create(struct wusbhc
*);
376 extern void wusbhc_mmcie_destroy(struct wusbhc
*);
377 extern int wusbhc_mmcie_set(struct wusbhc
*, u8 interval
, u8 repeat_cnt
,
379 extern void wusbhc_mmcie_rm(struct wusbhc
*, struct wuie_hdr
*);
381 /* Bandwidth reservation */
382 int wusbhc_rsv_establish(struct wusbhc
*wusbhc
);
383 void wusbhc_rsv_terminate(struct wusbhc
*wusbhc
);
387 * I wanted a wedding in a church...
389 * but lately I've been thinking about
390 * the Botanical Gardens.
392 * We could do it by the tulips.
397 extern int wusb_dev_sec_add(struct wusbhc
*, struct usb_device
*,
399 extern void wusb_dev_sec_rm(struct wusb_dev
*) ;
400 extern int wusb_dev_4way_handshake(struct wusbhc
*, struct wusb_dev
*,
401 struct wusb_ckhdid
*ck
);
402 void wusbhc_gtk_rekey(struct wusbhc
*wusbhc
);
403 int wusb_dev_update_address(struct wusbhc
*wusbhc
, struct wusb_dev
*wusb_dev
);
406 /* WUSB Cluster ID handling */
407 extern u8
wusb_cluster_id_get(void);
408 extern void wusb_cluster_id_put(u8
);
411 * wusb_port_by_idx - return the port associated to a zero-based port index
413 * NOTE: valid without locking as long as wusbhc is referenced (as the
414 * number of ports doesn't change). The data pointed to has to
415 * be verified though :)
417 static inline struct wusb_port
*wusb_port_by_idx(struct wusbhc
*wusbhc
,
420 return &wusbhc
->port
[port_idx
];
424 * wusb_port_no_to_idx - Convert port number (per usb_dev->portnum) to
427 * USB stack USB ports are 1 based!!
429 * NOTE: only valid for WUSB devices!!!
431 static inline u8
wusb_port_no_to_idx(u8 port_no
)
436 extern struct wusb_dev
*__wusb_dev_get_by_usb_dev(struct wusbhc
*,
437 struct usb_device
*);
440 struct wusb_dev
*wusb_dev_get_by_usb_dev(struct usb_device
*usb_dev
)
442 struct wusbhc
*wusbhc
;
443 struct wusb_dev
*wusb_dev
;
444 wusbhc
= wusbhc_get_by_usb_dev(usb_dev
);
447 mutex_lock(&wusbhc
->mutex
);
448 wusb_dev
= __wusb_dev_get_by_usb_dev(wusbhc
, usb_dev
);
449 mutex_unlock(&wusbhc
->mutex
);
456 extern struct workqueue_struct
*wusbd
;
457 #endif /* #ifndef __WUSBHC_H__ */