]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/usb/wusbcore/devconnect.c
Merge branch 'topic/usbaudio' into for-linus
[mv-sheeva.git] / drivers / usb / wusbcore / devconnect.c
index f45d777bef349039593324f896e928c458a6abdf..e2e7e4bc84635319f763201366c4fb37fc6ef741 100644 (file)
@@ -57,9 +57,6 @@
  *                              Called by notif.c:wusb_handle_dn_connect()
  *                              when a DN_Connect is received.
  *
- *   wusbhc_devconnect_auth()   Called by rh.c:wusbhc_rh_port_reset() when
- *                              doing the device connect sequence.
- *
  *     wusb_devconnect_acked()  Ack done, release resources.
  *
  *   wusb_handle_dn_alive()     Called by notif.c:wusb_handle_dn()
@@ -69,9 +66,6 @@
  *                              process a disconenct request from a
  *                              device.
  *
- *   wusb_dev_reset()           Called by rh.c:wusbhc_rh_port_reset() when
- *                              resetting a device.
- *
  *   __wusb_dev_disable()       Called by rh.c:wusbhc_rh_clear_port_feat() when
  *                              disabling a port.
  *
 #include <linux/workqueue.h>
 #include "wusbhc.h"
 
-#undef D_LOCAL
-#define D_LOCAL 1
-#include <linux/uwb/debug.h>
-
 static void wusbhc_devconnect_acked_work(struct work_struct *work);
 
 static void wusb_dev_free(struct wusb_dev *wusb_dev)
@@ -240,6 +230,7 @@ static struct wusb_dev *wusbhc_cack_add(struct wusbhc *wusbhc,
        list_add_tail(&wusb_dev->cack_node, &wusbhc->cack_list);
        wusbhc->cack_count++;
        wusbhc_fill_cack_ie(wusbhc);
+
        return wusb_dev;
 }
 
@@ -250,12 +241,9 @@ static struct wusb_dev *wusbhc_cack_add(struct wusbhc *wusbhc,
  */
 static void wusbhc_cack_rm(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
 {
-       struct device *dev = wusbhc->dev;
-       d_fnstart(3, dev, "(wusbhc %p wusb_dev %p)\n", wusbhc, wusb_dev);
        list_del_init(&wusb_dev->cack_node);
        wusbhc->cack_count--;
        wusbhc_fill_cack_ie(wusbhc);
-       d_fnend(3, dev, "(wusbhc %p wusb_dev %p) = void\n", wusbhc, wusb_dev);
 }
 
 /*
@@ -263,14 +251,11 @@ static void wusbhc_cack_rm(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
 static
 void wusbhc_devconnect_acked(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
 {
-       struct device *dev = wusbhc->dev;
-       d_fnstart(3, dev, "(wusbhc %p wusb_dev %p)\n", wusbhc, wusb_dev);
        wusbhc_cack_rm(wusbhc, wusb_dev);
        if (wusbhc->cack_count)
                wusbhc_mmcie_set(wusbhc, 0, 0, &wusbhc->cack_ie.hdr);
        else
                wusbhc_mmcie_rm(wusbhc, &wusbhc->cack_ie.hdr);
-       d_fnend(3, dev, "(wusbhc %p wusb_dev %p) = void\n", wusbhc, wusb_dev);
 }
 
 static void wusbhc_devconnect_acked_work(struct work_struct *work)
@@ -320,7 +305,6 @@ void wusbhc_devconnect_ack(struct wusbhc *wusbhc, struct wusb_dn_connect *dnc,
        struct wusb_port *port;
        unsigned idx, devnum;
 
-       d_fnstart(3, dev, "(%p, %p, %s)\n", wusbhc, dnc, pr_cdid);
        mutex_lock(&wusbhc->mutex);
 
        /* Check we are not handling it already */
@@ -366,16 +350,13 @@ void wusbhc_devconnect_ack(struct wusbhc *wusbhc, struct wusb_dn_connect *dnc,
        port->wusb_dev = wusb_dev;
        port->status |= USB_PORT_STAT_CONNECTION;
        port->change |= USB_PORT_STAT_C_CONNECTION;
-       port->reset_count = 0;
        /* Now the port status changed to connected; khubd will
         * pick the change up and try to reset the port to bring it to
         * the enabled state--so this process returns up to the stack
-        * and it calls back into wusbhc_rh_port_reset() who will call
-        * devconnect_auth().
+        * and it calls back into wusbhc_rh_port_reset().
         */
 error_unlock:
        mutex_unlock(&wusbhc->mutex);
-       d_fnend(3, dev, "(%p, %p, %s) = void\n", wusbhc, dnc, pr_cdid);
        return;
 
 }
@@ -398,10 +379,8 @@ error_unlock:
 static void __wusbhc_dev_disconnect(struct wusbhc *wusbhc,
                                    struct wusb_port *port)
 {
-       struct device *dev = wusbhc->dev;
        struct wusb_dev *wusb_dev = port->wusb_dev;
 
-       d_fnstart(3, dev, "(wusbhc %p, port %p)\n", wusbhc, port);
        port->status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE
                          | USB_PORT_STAT_SUSPEND | USB_PORT_STAT_RESET
                          | USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED);
@@ -413,54 +392,17 @@ static void __wusbhc_dev_disconnect(struct wusbhc *wusbhc,
                wusb_dev_put(wusb_dev);
        }
        port->wusb_dev = NULL;
-       /* don't reset the reset_count to zero or wusbhc_rh_port_reset will get
-        * confused! We only reset to zero when we connect a new device.
-        */
 
        /* After a device disconnects, change the GTK (see [WUSB]
         * section 6.2.11.2). */
        wusbhc_gtk_rekey(wusbhc);
 
-       d_fnend(3, dev, "(wusbhc %p, port %p) = void\n", wusbhc, port);
        /* The Wireless USB part has forgotten about the device already; now
         * khubd's timer will pick up the disconnection and remove the USB
         * device from the system
         */
 }
 
-/*
- * Authenticate a device into the WUSB Cluster
- *
- * Called from the Root Hub code (rh.c:wusbhc_rh_port_reset()) when
- * asking for a reset on a port that is not enabled (ie: first connect
- * on the port).
- *
- * Performs the 4way handshake to allow the device to comunicate w/ the
- * WUSB Cluster securely; once done, issue a request to the device for
- * it to change to address 0.
- *
- * This mimics the reset step of Wired USB that once resetting a
- * device, leaves the port in enabled state and the dev with the
- * default address (0).
- *
- * WUSB1.0[7.1.2]
- *
- * @port_idx: port where the change happened--This is the index into
- *            the wusbhc port array, not the USB port number.
- */
-int wusbhc_devconnect_auth(struct wusbhc *wusbhc, u8 port_idx)
-{
-       struct device *dev = wusbhc->dev;
-       struct wusb_port *port = wusb_port_by_idx(wusbhc, port_idx);
-
-       d_fnstart(3, dev, "(%p, %u)\n", wusbhc, port_idx);
-       port->status &= ~USB_PORT_STAT_RESET;
-       port->status |= USB_PORT_STAT_ENABLE;
-       port->change |= USB_PORT_STAT_C_RESET | USB_PORT_STAT_C_ENABLE;
-       d_fnend(3, dev, "(%p, %u) = 0\n", wusbhc, port_idx);
-       return 0;
-}
-
 /*
  * Refresh the list of keep alives to emit in the MMC
  *
@@ -528,21 +470,15 @@ static void __wusbhc_keep_alive(struct wusbhc *wusbhc)
  */
 static void wusbhc_keep_alive_run(struct work_struct *ws)
 {
-       struct delayed_work *dw =
-               container_of(ws, struct delayed_work, work);
-       struct wusbhc *wusbhc =
-               container_of(dw, struct wusbhc, keep_alive_timer);
-
-       d_fnstart(5, wusbhc->dev, "(wusbhc %p)\n", wusbhc);
-       if (wusbhc->active) {
-               mutex_lock(&wusbhc->mutex);
-               __wusbhc_keep_alive(wusbhc);
-               mutex_unlock(&wusbhc->mutex);
-               queue_delayed_work(wusbd, &wusbhc->keep_alive_timer,
-                                  (wusbhc->trust_timeout * CONFIG_HZ)/1000/2);
-       }
-       d_fnend(5, wusbhc->dev, "(wusbhc %p) = void\n", wusbhc);
-       return;
+       struct delayed_work *dw = container_of(ws, struct delayed_work, work);
+       struct wusbhc *wusbhc = container_of(dw, struct wusbhc, keep_alive_timer);
+
+       mutex_lock(&wusbhc->mutex);
+       __wusbhc_keep_alive(wusbhc);
+       mutex_unlock(&wusbhc->mutex);
+
+       queue_delayed_work(wusbd, &wusbhc->keep_alive_timer,
+                          msecs_to_jiffies(wusbhc->trust_timeout / 2));
 }
 
 /*
@@ -585,10 +521,6 @@ static struct wusb_dev *wusbhc_find_dev_by_addr(struct wusbhc *wusbhc, u8 addr)
  */
 static void wusbhc_handle_dn_alive(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
 {
-       struct device *dev = wusbhc->dev;
-
-       d_printf(2, dev, "DN ALIVE: device 0x%02x pong\n", wusb_dev->addr);
-
        mutex_lock(&wusbhc->mutex);
        wusb_dev->entry_ts = jiffies;
        __wusbhc_keep_alive(wusbhc);
@@ -621,11 +553,10 @@ static void wusbhc_handle_dn_connect(struct wusbhc *wusbhc,
                "no-beacon"
        };
 
-       d_fnstart(3, dev, "(%p, %p, %zu)\n", wusbhc, dn_hdr, size);
        if (size < sizeof(*dnc)) {
                dev_err(dev, "DN CONNECT: short notification (%zu < %zu)\n",
                        size, sizeof(*dnc));
-               goto out;
+               return;
        }
 
        dnc = container_of(dn_hdr, struct wusb_dn_connect, hdr);
@@ -637,10 +568,6 @@ static void wusbhc_handle_dn_connect(struct wusbhc *wusbhc,
                 wusb_dn_connect_new_connection(dnc) ? "connect" : "reconnect");
        /* ACK the connect */
        wusbhc_devconnect_ack(wusbhc, dnc, pr_cdid);
-out:
-       d_fnend(3, dev, "(%p, %p, %zu) = void\n",
-               wusbhc, dn_hdr, size);
-       return;
 }
 
 /*
@@ -661,60 +588,6 @@ static void wusbhc_handle_dn_disconnect(struct wusbhc *wusbhc, struct wusb_dev *
        mutex_unlock(&wusbhc->mutex);
 }
 
-/*
- * Reset a WUSB device on a HWA
- *
- * @wusbhc
- * @port_idx   Index of the port where the device is
- *
- * In Wireless USB, a reset is more or less equivalent to a full
- * disconnect; so we just do a full disconnect and send the device a
- * Device Reset IE (WUSB1.0[7.5.11]) giving it a few millisecs (6 MMCs).
- *
- * @wusbhc should be refcounted and unlocked
- */
-int wusbhc_dev_reset(struct wusbhc *wusbhc, u8 port_idx)
-{
-       int result;
-       struct device *dev = wusbhc->dev;
-       struct wusb_dev *wusb_dev;
-       struct wuie_reset *ie;
-
-       d_fnstart(3, dev, "(%p, %u)\n", wusbhc, port_idx);
-       mutex_lock(&wusbhc->mutex);
-       result = 0;
-       wusb_dev = wusb_port_by_idx(wusbhc, port_idx)->wusb_dev;
-       if (wusb_dev == NULL) {
-               /* reset no device? ignore */
-               dev_dbg(dev, "RESET: no device at port %u, ignoring\n",
-                       port_idx);
-               goto error_unlock;
-       }
-       result = -ENOMEM;
-       ie = kzalloc(sizeof(*ie), GFP_KERNEL);
-       if (ie == NULL)
-               goto error_unlock;
-       ie->hdr.bLength = sizeof(ie->hdr) + sizeof(ie->CDID);
-       ie->hdr.bIEIdentifier = WUIE_ID_RESET_DEVICE;
-       ie->CDID = wusb_dev->cdid;
-       result = wusbhc_mmcie_set(wusbhc, 0xff, 6, &ie->hdr);
-       if (result < 0) {
-               dev_err(dev, "RESET: cant's set MMC: %d\n", result);
-               goto error_kfree;
-       }
-       __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, port_idx));
-
-       /* 120ms, hopefully 6 MMCs (FIXME) */
-       msleep(120);
-       wusbhc_mmcie_rm(wusbhc, &ie->hdr);
-error_kfree:
-       kfree(ie);
-error_unlock:
-       mutex_unlock(&wusbhc->mutex);
-       d_fnend(3, dev, "(%p, %u) = %d\n", wusbhc, port_idx, result);
-       return result;
-}
-
 /*
  * Handle a Device Notification coming a host
  *
@@ -735,19 +608,17 @@ void wusbhc_handle_dn(struct wusbhc *wusbhc, u8 srcaddr,
        struct device *dev = wusbhc->dev;
        struct wusb_dev *wusb_dev;
 
-       d_fnstart(3, dev, "(%p, %p)\n", wusbhc, dn_hdr);
-
        if (size < sizeof(struct wusb_dn_hdr)) {
                dev_err(dev, "DN data shorter than DN header (%d < %d)\n",
                        (int)size, (int)sizeof(struct wusb_dn_hdr));
-               goto out;
+               return;
        }
 
        wusb_dev = wusbhc_find_dev_by_addr(wusbhc, srcaddr);
        if (wusb_dev == NULL && dn_hdr->bType != WUSB_DN_CONNECT) {
                dev_dbg(dev, "ignoring DN %d from unconnected device %02x\n",
                        dn_hdr->bType, srcaddr);
-               goto out;
+               return;
        }
 
        switch (dn_hdr->bType) {
@@ -772,9 +643,6 @@ void wusbhc_handle_dn(struct wusbhc *wusbhc, u8 srcaddr,
                dev_warn(dev, "unknown DN %u (%d octets) from %u\n",
                         dn_hdr->bType, (int)size, srcaddr);
        }
-out:
-       d_fnend(3, dev, "(%p, %p) = void\n", wusbhc, dn_hdr);
-       return;
 }
 EXPORT_SYMBOL_GPL(wusbhc_handle_dn);
 
@@ -804,59 +672,30 @@ void __wusbhc_dev_disable(struct wusbhc *wusbhc, u8 port_idx)
        struct wusb_dev *wusb_dev;
        struct wuie_disconnect *ie;
 
-       d_fnstart(3, dev, "(%p, %u)\n", wusbhc, port_idx);
-       result = 0;
        wusb_dev = wusb_port_by_idx(wusbhc, port_idx)->wusb_dev;
        if (wusb_dev == NULL) {
                /* reset no device? ignore */
                dev_dbg(dev, "DISCONNECT: no device at port %u, ignoring\n",
                        port_idx);
-               goto error;
+               return;
        }
        __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, port_idx));
 
-       result = -ENOMEM;
        ie = kzalloc(sizeof(*ie), GFP_KERNEL);
        if (ie == NULL)
-               goto error;
+               return;
        ie->hdr.bLength = sizeof(*ie);
        ie->hdr.bIEIdentifier = WUIE_ID_DEVICE_DISCONNECT;
        ie->bDeviceAddress = wusb_dev->addr;
        result = wusbhc_mmcie_set(wusbhc, 0, 0, &ie->hdr);
-       if (result < 0) {
+       if (result < 0)
                dev_err(dev, "DISCONNECT: can't set MMC: %d\n", result);
-               goto error_kfree;
+       else {
+               /* At least 6 MMCs, assuming at least 1 MMC per zone. */
+               msleep(7*4);
+               wusbhc_mmcie_rm(wusbhc, &ie->hdr);
        }
-
-       /* 120ms, hopefully 6 MMCs */
-       msleep(100);
-       wusbhc_mmcie_rm(wusbhc, &ie->hdr);
-error_kfree:
        kfree(ie);
-error:
-       d_fnend(3, dev, "(%p, %u) = %d\n", wusbhc, port_idx, result);
-       return;
-}
-
-static void wusb_cap_descr_printf(const unsigned level, struct device *dev,
-                                 const struct usb_wireless_cap_descriptor *wcd)
-{
-       d_printf(level, dev,
-                "WUSB Capability Descriptor\n"
-                "  bDevCapabilityType          0x%02x\n"
-                "  bmAttributes                0x%02x\n"
-                "  wPhyRates                   0x%04x\n"
-                "  bmTFITXPowerInfo            0x%02x\n"
-                "  bmFFITXPowerInfo            0x%02x\n"
-                "  bmBandGroup                 0x%04x\n"
-                "  bReserved                   0x%02x\n",
-                wcd->bDevCapabilityType,
-                wcd->bmAttributes,
-                le16_to_cpu(wcd->wPHYRates),
-                wcd->bmTFITXPowerInfo,
-                wcd->bmFFITXPowerInfo,
-                wcd->bmBandGroup,
-                wcd->bReserved);
 }
 
 /*
@@ -899,8 +738,6 @@ static int wusb_dev_bos_grok(struct usb_device *usb_dev,
                }
                cap_size = cap_hdr->bLength;
                cap_type = cap_hdr->bDevCapabilityType;
-               d_printf(4, dev, "BOS Capability: 0x%02x (%zu bytes)\n",
-                        cap_type, cap_size);
                if (cap_size == 0)
                        break;
                if (cap_size > top - itr) {
@@ -912,7 +749,6 @@ static int wusb_dev_bos_grok(struct usb_device *usb_dev,
                        result = -EBADF;
                        goto error_bad_cap;
                }
-               d_dump(3, dev, itr, cap_size);
                switch (cap_type) {
                case USB_CAP_TYPE_WIRELESS_USB:
                        if (cap_size != sizeof(*wusb_dev->wusb_cap_descr))
@@ -920,10 +756,8 @@ static int wusb_dev_bos_grok(struct usb_device *usb_dev,
                                        "descriptor is %zu bytes vs %zu "
                                        "needed\n", cap_size,
                                        sizeof(*wusb_dev->wusb_cap_descr));
-                       else {
+                       else
                                wusb_dev->wusb_cap_descr = itr;
-                               wusb_cap_descr_printf(3, dev, itr);
-                       }
                        break;
                default:
                        dev_err(dev, "BUG? Unknown BOS capability 0x%02x "
@@ -988,9 +822,7 @@ static int wusb_dev_bos_add(struct usb_device *usb_dev,
                        "%zu bytes): %zd\n", desc_size, result);
                goto error_get_descriptor;
        }
-       d_printf(2, dev, "Got BOS descriptor %zd bytes, %u capabilities\n",
-                result, bos->bNumDeviceCaps);
-       d_dump(2, dev, bos, result);
+
        result = wusb_dev_bos_grok(usb_dev, wusb_dev, bos, result);
        if (result < 0)
                goto error_bad_bos;
@@ -1056,8 +888,6 @@ static void wusb_dev_add_ncb(struct usb_device *usb_dev)
        if (usb_dev->wusb == 0 || usb_dev->devnum == 1)
                return;         /* skip non wusb and wusb RHs */
 
-       d_fnstart(3, dev, "(usb_dev %p)\n", usb_dev);
-
        wusbhc = wusbhc_get_by_usb_dev(usb_dev);
        if (wusbhc == NULL)
                goto error_nodev;
@@ -1087,7 +917,6 @@ out:
        wusb_dev_put(wusb_dev);
        wusbhc_put(wusbhc);
 error_nodev:
-       d_fnend(3, dev, "(usb_dev %p) = void\n", usb_dev);
        return;
 
        wusb_dev_sysfs_rm(wusb_dev);
@@ -1174,11 +1003,10 @@ EXPORT_SYMBOL_GPL(__wusb_dev_get_by_usb_dev);
 
 void wusb_dev_destroy(struct kref *_wusb_dev)
 {
-       struct wusb_dev *wusb_dev
-               = container_of(_wusb_dev, struct wusb_dev, refcnt);
+       struct wusb_dev *wusb_dev = container_of(_wusb_dev, struct wusb_dev, refcnt);
+
        list_del_init(&wusb_dev->cack_node);
        wusb_dev_free(wusb_dev);
-       d_fnend(1, NULL, "%s (wusb_dev %p) = void\n", __func__, wusb_dev);
 }
 EXPORT_SYMBOL_GPL(wusb_dev_destroy);
 
@@ -1190,8 +1018,6 @@ EXPORT_SYMBOL_GPL(wusb_dev_destroy);
  */
 int wusbhc_devconnect_create(struct wusbhc *wusbhc)
 {
-       d_fnstart(3, wusbhc->dev, "(wusbhc %p)\n", wusbhc);
-
        wusbhc->keep_alive_ie.hdr.bIEIdentifier = WUIE_ID_KEEP_ALIVE;
        wusbhc->keep_alive_ie.hdr.bLength = sizeof(wusbhc->keep_alive_ie.hdr);
        INIT_DELAYED_WORK(&wusbhc->keep_alive_timer, wusbhc_keep_alive_run);
@@ -1200,7 +1026,6 @@ int wusbhc_devconnect_create(struct wusbhc *wusbhc)
        wusbhc->cack_ie.hdr.bLength = sizeof(wusbhc->cack_ie.hdr);
        INIT_LIST_HEAD(&wusbhc->cack_list);
 
-       d_fnend(3, wusbhc->dev, "(wusbhc %p) = void\n", wusbhc);
        return 0;
 }
 
@@ -1209,8 +1034,7 @@ int wusbhc_devconnect_create(struct wusbhc *wusbhc)
  */
 void wusbhc_devconnect_destroy(struct wusbhc *wusbhc)
 {
-       d_fnstart(3, wusbhc->dev, "(wusbhc %p)\n", wusbhc);
-       d_fnend(3, wusbhc->dev, "(wusbhc %p) = void\n", wusbhc);
+       /* no op */
 }
 
 /*
@@ -1222,8 +1046,7 @@ void wusbhc_devconnect_destroy(struct wusbhc *wusbhc)
  * FIXME: This also enables the keep alives but this is not necessary
  * until there are connected and authenticated devices.
  */
-int wusbhc_devconnect_start(struct wusbhc *wusbhc,
-                           const struct wusb_ckhdid *chid)
+int wusbhc_devconnect_start(struct wusbhc *wusbhc)
 {
        struct device *dev = wusbhc->dev;
        struct wuie_host_info *hi;
@@ -1236,7 +1059,7 @@ int wusbhc_devconnect_start(struct wusbhc *wusbhc,
        hi->hdr.bLength       = sizeof(*hi);
        hi->hdr.bIEIdentifier = WUIE_ID_HOST_INFO;
        hi->attributes        = cpu_to_le16((wusbhc->rsv->stream << 3) | WUIE_HI_CAP_ALL);
-       hi->CHID              = *chid;
+       hi->CHID              = wusbhc->chid;
        result = wusbhc_mmcie_set(wusbhc, 0, 0, &hi->hdr);
        if (result < 0) {
                dev_err(dev, "Cannot add Host Info MMCIE: %d\n", result);