Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wusbhc.h
Go to the documentation of this file.
1 /*
2  * Wireless USB Host Controller
3  * Common infrastructure for WHCI and HWA WUSB-HC drivers
4  *
5  *
6  * Copyright (C) 2005-2006 Intel Corporation
7  * Inaky Perez-Gonzalez <[email protected]>
8  *
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.
12  *
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.
17  *
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
21  * 02110-1301, USA.
22  *
23  *
24  * This driver implements parts common to all Wireless USB Host
25  * Controllers (struct wusbhc, embedding a struct usb_hcd) and is used
26  * by:
27  *
28  * - hwahc: HWA, USB-dongle that implements a Wireless USB host
29  * controller, (Wireless USB 1.0 Host-Wire-Adapter specification).
30  *
31  * - whci: WHCI, a PCI card with a wireless host controller
32  * (Wireless Host Controller Interface 1.0 specification).
33  *
34  * Check out the Design-overview.txt file in the source documentation
35  * for other details on the implementation.
36  *
37  * Main blocks:
38  *
39  * rh Root Hub emulation (part of the HCD glue)
40  *
41  * devconnect Handle all the issues related to device connection,
42  * authentication, disconnection, timeout, reseting,
43  * keepalives, etc.
44  *
45  * mmc MMC IE broadcasting handling
46  *
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.
51  */
52 
53 #ifndef __WUSBHC_H__
54 #define __WUSBHC_H__
55 
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>
64 
65 /*
66  * Time from a WUSB channel stop request to the last transmitted MMC.
67  *
68  * This needs to be > 4.096 ms in case no MMCs can be transmitted in
69  * zone 0.
70  */
71 #define WUSB_CHANNEL_STOP_DELAY_MS 8
72 
94 struct wusb_dev {
95  struct kref refcnt;
96  struct wusbhc *wusbhc;
97  struct list_head cack_node; /* Connect-Ack list */
103  unsigned long entry_ts;
108  struct urb *set_gtk_urb;
110  struct usb_device *usb_dev;
111 };
112 
113 #define WUSB_DEV_ADDR_UNAUTH 0x80
114 
115 static inline void wusb_dev_init(struct wusb_dev *wusb_dev)
116 {
117  kref_init(&wusb_dev->refcnt);
118  /* no need to init the cack_node */
119 }
120 
121 extern void wusb_dev_destroy(struct kref *_wusb_dev);
122 
123 static inline struct wusb_dev *wusb_dev_get(struct wusb_dev *wusb_dev)
124 {
125  kref_get(&wusb_dev->refcnt);
126  return wusb_dev;
127 }
128 
129 static inline void wusb_dev_put(struct wusb_dev *wusb_dev)
130 {
131  kref_put(&wusb_dev->refcnt, wusb_dev_destroy);
132 }
133 
151 struct wusb_port {
154  struct wusb_dev *wusb_dev; /* connected device's info */
156 };
157 
246 struct wusbhc {
247  struct usb_hcd usb_hcd; /* HAS TO BE 1st */
248  struct device *dev;
249  struct uwb_rc *uwb_rc;
250  struct uwb_pal pal;
251 
252  unsigned trust_timeout; /* in jiffies */
256 
257  struct mutex mutex; /* locks everything else */
258  u16 cluster_id; /* Wireless USB Cluster ID */
259  struct wusb_port *port; /* Fake port status handling */
260  struct wusb_dev_info *dev_info; /* for Set Device Info mgmt */
262  unsigned active:1; /* currently xmit'ing MMCs */
263  struct wuie_keep_alive keep_alive_ie; /* protected by mutex */
265  struct list_head cack_list; /* Connect acknowledging */
266  size_t cack_count; /* protected by 'mutex' */
268  struct uwb_rsv *rsv; /* cluster bandwidth reservation */
269 
270  struct mutex mmcie_mutex; /* MMC WUIE handling */
271  struct wuie_hdr **mmcie; /* WUIE array */
273  /* FIXME: make wusbhc_ops? */
274  int (*start)(struct wusbhc *wusbhc);
275  void (*stop)(struct wusbhc *wusbhc, int delay);
276  int (*mmcie_add)(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt,
277  u8 handle, struct wuie_hdr *wuie);
279  int (*dev_info_set)(struct wusbhc *, struct wusb_dev *wusb_dev);
280  int (*bwa_set)(struct wusbhc *wusbhc, s8 stream_index,
281  const struct uwb_mas_bm *);
282  int (*set_ptk)(struct wusbhc *wusbhc, u8 port_idx,
283  u32 tkid, const void *key, size_t key_size);
284  int (*set_gtk)(struct wusbhc *wusbhc,
285  u32 tkid, const void *key, size_t key_size);
287 
288  struct {
290  u8 data[16]; /* GTK key data */
291  } __attribute__((packed)) gtk;
296 
298 };
299 
300 #define usb_hcd_to_wusbhc(u) container_of((u), struct wusbhc, usb_hcd)
301 
302 
303 extern int wusbhc_create(struct wusbhc *);
304 extern int wusbhc_b_create(struct wusbhc *);
305 extern void wusbhc_b_destroy(struct wusbhc *);
306 extern void wusbhc_destroy(struct wusbhc *);
307 extern int wusb_dev_sysfs_add(struct wusbhc *, struct usb_device *,
308  struct wusb_dev *);
309 extern void wusb_dev_sysfs_rm(struct wusb_dev *);
310 extern int wusbhc_sec_create(struct wusbhc *);
311 extern int wusbhc_sec_start(struct wusbhc *);
312 extern void wusbhc_sec_stop(struct wusbhc *);
313 extern void wusbhc_sec_destroy(struct wusbhc *);
314 extern void wusbhc_giveback_urb(struct wusbhc *wusbhc, struct urb *urb,
315  int status);
316 void wusbhc_reset_all(struct wusbhc *wusbhc);
317 
318 int wusbhc_pal_register(struct wusbhc *wusbhc);
319 void wusbhc_pal_unregister(struct wusbhc *wusbhc);
320 
321 /*
322  * Return @usb_dev's @usb_hcd (properly referenced) or NULL if gone
323  *
324  * @usb_dev: USB device, UNLOCKED and referenced (or otherwise, safe ptr)
325  *
326  * This is a safe assumption as @usb_dev->bus is referenced all the
327  * time during the @usb_dev life cycle.
328  */
329 static inline struct usb_hcd *usb_hcd_get_by_usb_dev(struct usb_device *usb_dev)
330 {
331  struct usb_hcd *usb_hcd;
332  usb_hcd = container_of(usb_dev->bus, struct usb_hcd, self);
333  return usb_get_hcd(usb_hcd);
334 }
335 
336 /*
337  * Increment the reference count on a wusbhc.
338  *
339  * @wusbhc's life cycle is identical to that of the underlying usb_hcd.
340  */
341 static inline struct wusbhc *wusbhc_get(struct wusbhc *wusbhc)
342 {
343  return usb_get_hcd(&wusbhc->usb_hcd) ? wusbhc : NULL;
344 }
345 
346 /*
347  * Return the wusbhc associated to a @usb_dev
348  *
349  * @usb_dev: USB device, UNLOCKED and referenced (or otherwise, safe ptr)
350  *
351  * @returns: wusbhc for @usb_dev; NULL if the @usb_dev is being torn down.
352  * WARNING: referenced at the usb_hcd level, unlocked
353  *
354  * FIXME: move offline
355  */
356 static inline struct wusbhc *wusbhc_get_by_usb_dev(struct usb_device *usb_dev)
357 {
358  struct wusbhc *wusbhc = NULL;
359  struct usb_hcd *usb_hcd;
360  if (usb_dev->devnum > 1 && !usb_dev->wusb) {
361  /* but root hubs */
362  dev_err(&usb_dev->dev, "devnum %d wusb %d\n", usb_dev->devnum,
363  usb_dev->wusb);
364  BUG_ON(usb_dev->devnum > 1 && !usb_dev->wusb);
365  }
366  usb_hcd = usb_hcd_get_by_usb_dev(usb_dev);
367  if (usb_hcd == NULL)
368  return NULL;
369  BUG_ON(usb_hcd->wireless == 0);
370  return wusbhc = usb_hcd_to_wusbhc(usb_hcd);
371 }
372 
373 
374 static inline void wusbhc_put(struct wusbhc *wusbhc)
375 {
376  usb_put_hcd(&wusbhc->usb_hcd);
377 }
378 
379 int wusbhc_start(struct wusbhc *wusbhc);
380 void wusbhc_stop(struct wusbhc *wusbhc);
381 extern int wusbhc_chid_set(struct wusbhc *, const struct wusb_ckhdid *);
382 
383 /* Device connect handling */
384 extern int wusbhc_devconnect_create(struct wusbhc *);
385 extern void wusbhc_devconnect_destroy(struct wusbhc *);
386 extern int wusbhc_devconnect_start(struct wusbhc *wusbhc);
387 extern void wusbhc_devconnect_stop(struct wusbhc *wusbhc);
388 extern void wusbhc_handle_dn(struct wusbhc *, u8 srcaddr,
389  struct wusb_dn_hdr *dn_hdr, size_t size);
390 extern void __wusbhc_dev_disable(struct wusbhc *wusbhc, u8 port);
391 extern int wusb_usb_ncb(struct notifier_block *nb, unsigned long val,
392  void *priv);
393 extern int wusb_set_dev_addr(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev,
394  u8 addr);
395 
396 /* Wireless USB fake Root Hub methods */
397 extern int wusbhc_rh_create(struct wusbhc *);
398 extern void wusbhc_rh_destroy(struct wusbhc *);
399 
400 extern int wusbhc_rh_status_data(struct usb_hcd *, char *);
401 extern int wusbhc_rh_control(struct usb_hcd *, u16, u16, u16, char *, u16);
402 extern int wusbhc_rh_suspend(struct usb_hcd *);
403 extern int wusbhc_rh_resume(struct usb_hcd *);
404 extern int wusbhc_rh_start_port_reset(struct usb_hcd *, unsigned);
405 
406 /* MMC handling */
407 extern int wusbhc_mmcie_create(struct wusbhc *);
408 extern void wusbhc_mmcie_destroy(struct wusbhc *);
409 extern int wusbhc_mmcie_set(struct wusbhc *, u8 interval, u8 repeat_cnt,
410  struct wuie_hdr *);
411 extern void wusbhc_mmcie_rm(struct wusbhc *, struct wuie_hdr *);
412 
413 /* Bandwidth reservation */
414 int wusbhc_rsv_establish(struct wusbhc *wusbhc);
415 void wusbhc_rsv_terminate(struct wusbhc *wusbhc);
416 
417 /*
418  * I've always said
419  * I wanted a wedding in a church...
420  *
421  * but lately I've been thinking about
422  * the Botanical Gardens.
423  *
424  * We could do it by the tulips.
425  * It'll be beautiful
426  *
427  * --Security!
428  */
429 extern int wusb_dev_sec_add(struct wusbhc *, struct usb_device *,
430  struct wusb_dev *);
431 extern void wusb_dev_sec_rm(struct wusb_dev *) ;
432 extern int wusb_dev_4way_handshake(struct wusbhc *, struct wusb_dev *,
433  struct wusb_ckhdid *ck);
434 void wusbhc_gtk_rekey(struct wusbhc *wusbhc);
435 int wusb_dev_update_address(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev);
436 
437 
438 /* WUSB Cluster ID handling */
439 extern u8 wusb_cluster_id_get(void);
440 extern void wusb_cluster_id_put(u8);
441 
442 /*
443  * wusb_port_by_idx - return the port associated to a zero-based port index
444  *
445  * NOTE: valid without locking as long as wusbhc is referenced (as the
446  * number of ports doesn't change). The data pointed to has to
447  * be verified though :)
448  */
449 static inline struct wusb_port *wusb_port_by_idx(struct wusbhc *wusbhc,
450  u8 port_idx)
451 {
452  return &wusbhc->port[port_idx];
453 }
454 
455 /*
456  * wusb_port_no_to_idx - Convert port number (per usb_dev->portnum) to
457  * a port_idx.
458  *
459  * USB stack USB ports are 1 based!!
460  *
461  * NOTE: only valid for WUSB devices!!!
462  */
463 static inline u8 wusb_port_no_to_idx(u8 port_no)
464 {
465  return port_no - 1;
466 }
467 
468 extern struct wusb_dev *__wusb_dev_get_by_usb_dev(struct wusbhc *,
469  struct usb_device *);
470 
471 /*
472  * Return a referenced wusb_dev given a @usb_dev
473  *
474  * Returns NULL if the usb_dev is being torn down.
475  *
476  * FIXME: move offline
477  */
478 static inline
479 struct wusb_dev *wusb_dev_get_by_usb_dev(struct usb_device *usb_dev)
480 {
481  struct wusbhc *wusbhc;
482  struct wusb_dev *wusb_dev;
483  wusbhc = wusbhc_get_by_usb_dev(usb_dev);
484  if (wusbhc == NULL)
485  return NULL;
486  mutex_lock(&wusbhc->mutex);
487  wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, usb_dev);
488  mutex_unlock(&wusbhc->mutex);
489  wusbhc_put(wusbhc);
490  return wusb_dev;
491 }
492 
493 /* Misc */
494 
495 extern struct workqueue_struct *wusbd;
496 #endif /* #ifndef __WUSBHC_H__ */