aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-01-02 13:31:04 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-02 13:31:04 -0500
commit80618fa83a34a26199fa99cfd06476a81ddf57df (patch)
tree30a486902351f57c8f072dee268d2abeb3ddfe7e /drivers/usb
parent92cde4d5396c3b6cbf3192286b687f97a889dffe (diff)
parentb21a207141d83a06abc5f492b80204602e02ca44 (diff)
Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/dvrabel/uwb
* 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/dvrabel/uwb: (31 commits) uwb: remove beacon cache entry after calling uwb_notify() uwb: remove unused include/linux/uwb/debug.h uwb: use print_hex_dump() uwb: use dev_dbg() for debug messages uwb: fix memory leak in uwb_rc_notif() wusb: fix oops when terminating a non-existant reservation uwb: fix oops when terminating an already terminated reservation uwb: improved MAS allocator and reservation conflict handling wusb: add debug files for ASL, PZL and DI to the whci-hcd driver uwb: fix oops in debug PAL's reservation callback uwb: clean up whci_wait_for() timeout error message wusb: whci-hcd shouldn't do ASL/PZL updates while channel is inactive uwb: remove unused beacon group join/leave events wlp: start/stop radio on network interface up/down uwb: add basic radio manager uwb: add pal parameter to new reservation callback uwb: fix races between events and neh timers uwb: don't unbind the radio controller driver when resetting uwb: per-radio controller event thread and beacon cache uwb: add commands to add/remove IEs to the debug interface ...
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/host/hwa-hc.c159
-rw-r--r--drivers/usb/host/whci/Kbuild1
-rw-r--r--drivers/usb/host/whci/asl.c46
-rw-r--r--drivers/usb/host/whci/debug.c189
-rw-r--r--drivers/usb/host/whci/hcd.c6
-rw-r--r--drivers/usb/host/whci/hw.c8
-rw-r--r--drivers/usb/host/whci/int.c1
-rw-r--r--drivers/usb/host/whci/pzl.c49
-rw-r--r--drivers/usb/host/whci/qset.c40
-rw-r--r--drivers/usb/host/whci/whcd.h11
-rw-r--r--drivers/usb/host/whci/whci-hc.h2
-rw-r--r--drivers/usb/host/whci/wusb.c43
-rw-r--r--drivers/usb/wusbcore/cbaf.c1
-rw-r--r--drivers/usb/wusbcore/crypto.c79
-rw-r--r--drivers/usb/wusbcore/dev-sysfs.c4
-rw-r--r--drivers/usb/wusbcore/devconnect.c233
-rw-r--r--drivers/usb/wusbcore/mmc.c118
-rw-r--r--drivers/usb/wusbcore/pal.c16
-rw-r--r--drivers/usb/wusbcore/reservation.c21
-rw-r--r--drivers/usb/wusbcore/rh.c104
-rw-r--r--drivers/usb/wusbcore/security.c78
-rw-r--r--drivers/usb/wusbcore/wa-nep.c16
-rw-r--r--drivers/usb/wusbcore/wa-rpipe.c68
-rw-r--r--drivers/usb/wusbcore/wa-xfer.c180
-rw-r--r--drivers/usb/wusbcore/wusbhc.h36
25 files changed, 563 insertions, 946 deletions
diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
index 64be4d88df11..8582236e4cad 100644
--- a/drivers/usb/host/hwa-hc.c
+++ b/drivers/usb/host/hwa-hc.c
@@ -54,7 +54,6 @@
54 * DWA). 54 * DWA).
55 */ 55 */
56#include <linux/kernel.h> 56#include <linux/kernel.h>
57#include <linux/version.h>
58#include <linux/init.h> 57#include <linux/init.h>
59#include <linux/module.h> 58#include <linux/module.h>
60#include <linux/workqueue.h> 59#include <linux/workqueue.h>
@@ -63,16 +62,12 @@
63#include "../wusbcore/wa-hc.h" 62#include "../wusbcore/wa-hc.h"
64#include "../wusbcore/wusbhc.h" 63#include "../wusbcore/wusbhc.h"
65 64
66#define D_LOCAL 0
67#include <linux/uwb/debug.h>
68
69struct hwahc { 65struct hwahc {
70 struct wusbhc wusbhc; /* has to be 1st */ 66 struct wusbhc wusbhc; /* has to be 1st */
71 struct wahc wa; 67 struct wahc wa;
72 u8 buffer[16]; /* for misc usb transactions */
73}; 68};
74 69
75/** 70/*
76 * FIXME should be wusbhc 71 * FIXME should be wusbhc
77 * 72 *
78 * NOTE: we need to cache the Cluster ID because later...there is no 73 * NOTE: we need to cache the Cluster ID because later...there is no
@@ -126,7 +121,6 @@ static int hwahc_op_reset(struct usb_hcd *usb_hcd)
126 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); 121 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
127 struct device *dev = &hwahc->wa.usb_iface->dev; 122 struct device *dev = &hwahc->wa.usb_iface->dev;
128 123
129 d_fnstart(4, dev, "(hwahc %p)\n", hwahc);
130 mutex_lock(&wusbhc->mutex); 124 mutex_lock(&wusbhc->mutex);
131 wa_nep_disarm(&hwahc->wa); 125 wa_nep_disarm(&hwahc->wa);
132 result = __wa_set_feature(&hwahc->wa, WA_RESET); 126 result = __wa_set_feature(&hwahc->wa, WA_RESET);
@@ -134,7 +128,6 @@ static int hwahc_op_reset(struct usb_hcd *usb_hcd)
134 dev_err(dev, "error commanding HC to reset: %d\n", result); 128 dev_err(dev, "error commanding HC to reset: %d\n", result);
135 goto error_unlock; 129 goto error_unlock;
136 } 130 }
137 d_printf(3, dev, "reset: waiting for device to change state\n");
138 result = __wa_wait_status(&hwahc->wa, WA_STATUS_RESETTING, 0); 131 result = __wa_wait_status(&hwahc->wa, WA_STATUS_RESETTING, 0);
139 if (result < 0) { 132 if (result < 0) {
140 dev_err(dev, "error waiting for HC to reset: %d\n", result); 133 dev_err(dev, "error waiting for HC to reset: %d\n", result);
@@ -142,7 +135,6 @@ static int hwahc_op_reset(struct usb_hcd *usb_hcd)
142 } 135 }
143error_unlock: 136error_unlock:
144 mutex_unlock(&wusbhc->mutex); 137 mutex_unlock(&wusbhc->mutex);
145 d_fnend(4, dev, "(hwahc %p) = %d\n", hwahc, result);
146 return result; 138 return result;
147} 139}
148 140
@@ -155,15 +147,9 @@ static int hwahc_op_start(struct usb_hcd *usb_hcd)
155 int result; 147 int result;
156 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); 148 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
157 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); 149 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
158 struct device *dev = &hwahc->wa.usb_iface->dev;
159 150
160 /* Set up a Host Info WUSB Information Element */
161 d_fnstart(4, dev, "(hwahc %p)\n", hwahc);
162 result = -ENOSPC; 151 result = -ENOSPC;
163 mutex_lock(&wusbhc->mutex); 152 mutex_lock(&wusbhc->mutex);
164 /* Start the numbering from the top so that the bottom
165 * range of the unauth addr space is used for devices,
166 * the top for HCs; use 0xfe - RC# */
167 addr = wusb_cluster_id_get(); 153 addr = wusb_cluster_id_get();
168 if (addr == 0) 154 if (addr == 0)
169 goto error_cluster_id_get; 155 goto error_cluster_id_get;
@@ -171,22 +157,14 @@ static int hwahc_op_start(struct usb_hcd *usb_hcd)
171 if (result < 0) 157 if (result < 0)
172 goto error_set_cluster_id; 158 goto error_set_cluster_id;
173 159
174 result = wa_nep_arm(&hwahc->wa, GFP_KERNEL);
175 if (result < 0) {
176 dev_err(dev, "cannot listen to notifications: %d\n", result);
177 goto error_stop;
178 }
179 usb_hcd->uses_new_polling = 1; 160 usb_hcd->uses_new_polling = 1;
180 usb_hcd->poll_rh = 1; 161 usb_hcd->poll_rh = 1;
181 usb_hcd->state = HC_STATE_RUNNING; 162 usb_hcd->state = HC_STATE_RUNNING;
182 result = 0; 163 result = 0;
183out: 164out:
184 mutex_unlock(&wusbhc->mutex); 165 mutex_unlock(&wusbhc->mutex);
185 d_fnend(4, dev, "(hwahc %p) = %d\n", hwahc, result);
186 return result; 166 return result;
187 167
188error_stop:
189 __wa_stop(&hwahc->wa);
190error_set_cluster_id: 168error_set_cluster_id:
191 wusb_cluster_id_put(wusbhc->cluster_id); 169 wusb_cluster_id_put(wusbhc->cluster_id);
192error_cluster_id_get: 170error_cluster_id_get:
@@ -194,39 +172,6 @@ error_cluster_id_get:
194 172
195} 173}
196 174
197/*
198 * FIXME: break this function up
199 */
200static int __hwahc_op_wusbhc_start(struct wusbhc *wusbhc)
201{
202 int result;
203 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
204 struct device *dev = &hwahc->wa.usb_iface->dev;
205
206 /* Set up a Host Info WUSB Information Element */
207 d_fnstart(4, dev, "(hwahc %p)\n", hwahc);
208 result = -ENOSPC;
209
210 result = __wa_set_feature(&hwahc->wa, WA_ENABLE);
211 if (result < 0) {
212 dev_err(dev, "error commanding HC to start: %d\n", result);
213 goto error_stop;
214 }
215 result = __wa_wait_status(&hwahc->wa, WA_ENABLE, WA_ENABLE);
216 if (result < 0) {
217 dev_err(dev, "error waiting for HC to start: %d\n", result);
218 goto error_stop;
219 }
220 result = 0;
221out:
222 d_fnend(4, dev, "(hwahc %p) = %d\n", hwahc, result);
223 return result;
224
225error_stop:
226 result = __wa_clear_feature(&hwahc->wa, WA_ENABLE);
227 goto out;
228}
229
230static int hwahc_op_suspend(struct usb_hcd *usb_hcd, pm_message_t msg) 175static int hwahc_op_suspend(struct usb_hcd *usb_hcd, pm_message_t msg)
231{ 176{
232 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); 177 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
@@ -246,18 +191,6 @@ static int hwahc_op_resume(struct usb_hcd *usb_hcd)
246 return -ENOSYS; 191 return -ENOSYS;
247} 192}
248 193
249static void __hwahc_op_wusbhc_stop(struct wusbhc *wusbhc)
250{
251 int result;
252 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
253 struct device *dev = &hwahc->wa.usb_iface->dev;
254
255 d_fnstart(4, dev, "(hwahc %p)\n", hwahc);
256 /* Nothing for now */
257 d_fnend(4, dev, "(hwahc %p) = %d\n", hwahc, result);
258 return;
259}
260
261/* 194/*
262 * No need to abort pipes, as when this is called, all the children 195 * No need to abort pipes, as when this is called, all the children
263 * has been disconnected and that has done it [through 196 * has been disconnected and that has done it [through
@@ -266,21 +199,11 @@ static void __hwahc_op_wusbhc_stop(struct wusbhc *wusbhc)
266 */ 199 */
267static void hwahc_op_stop(struct usb_hcd *usb_hcd) 200static void hwahc_op_stop(struct usb_hcd *usb_hcd)
268{ 201{
269 int result;
270 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); 202 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
271 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
272 struct wahc *wa = &hwahc->wa;
273 struct device *dev = &wa->usb_iface->dev;
274 203
275 d_fnstart(4, dev, "(hwahc %p)\n", hwahc);
276 mutex_lock(&wusbhc->mutex); 204 mutex_lock(&wusbhc->mutex);
277 wusbhc_stop(wusbhc);
278 wa_nep_disarm(&hwahc->wa);
279 result = __wa_stop(&hwahc->wa);
280 wusb_cluster_id_put(wusbhc->cluster_id); 205 wusb_cluster_id_put(wusbhc->cluster_id);
281 mutex_unlock(&wusbhc->mutex); 206 mutex_unlock(&wusbhc->mutex);
282 d_fnend(4, dev, "(hwahc %p) = %d\n", hwahc, result);
283 return;
284} 207}
285 208
286static int hwahc_op_get_frame_number(struct usb_hcd *usb_hcd) 209static int hwahc_op_get_frame_number(struct usb_hcd *usb_hcd)
@@ -325,6 +248,54 @@ static void hwahc_op_endpoint_disable(struct usb_hcd *usb_hcd,
325 rpipe_ep_disable(&hwahc->wa, ep); 248 rpipe_ep_disable(&hwahc->wa, ep);
326} 249}
327 250
251static int __hwahc_op_wusbhc_start(struct wusbhc *wusbhc)
252{
253 int result;
254 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
255 struct device *dev = &hwahc->wa.usb_iface->dev;
256
257 result = __wa_set_feature(&hwahc->wa, WA_ENABLE);
258 if (result < 0) {
259 dev_err(dev, "error commanding HC to start: %d\n", result);
260 goto error_stop;
261 }
262 result = __wa_wait_status(&hwahc->wa, WA_ENABLE, WA_ENABLE);
263 if (result < 0) {
264 dev_err(dev, "error waiting for HC to start: %d\n", result);
265 goto error_stop;
266 }
267 result = wa_nep_arm(&hwahc->wa, GFP_KERNEL);
268 if (result < 0) {
269 dev_err(dev, "cannot listen to notifications: %d\n", result);
270 goto error_stop;
271 }
272 return result;
273
274error_stop:
275 __wa_clear_feature(&hwahc->wa, WA_ENABLE);
276 return result;
277}
278
279static void __hwahc_op_wusbhc_stop(struct wusbhc *wusbhc, int delay)
280{
281 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
282 struct wahc *wa = &hwahc->wa;
283 u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber;
284 int ret;
285
286 ret = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
287 WUSB_REQ_CHAN_STOP,
288 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
289 delay * 1000,
290 iface_no,
291 NULL, 0, 1000 /* FIXME: arbitrary */);
292 if (ret == 0)
293 msleep(delay);
294
295 wa_nep_disarm(&hwahc->wa);
296 __wa_stop(&hwahc->wa);
297}
298
328/* 299/*
329 * Set the UWB MAS allocation for the WUSB cluster 300 * Set the UWB MAS allocation for the WUSB cluster
330 * 301 *
@@ -581,11 +552,11 @@ static int wa_fill_descr(struct wahc *wa)
581 itr_size = le16_to_cpu(usb_dev->actconfig->desc.wTotalLength); 552 itr_size = le16_to_cpu(usb_dev->actconfig->desc.wTotalLength);
582 while (itr_size >= sizeof(*hdr)) { 553 while (itr_size >= sizeof(*hdr)) {
583 hdr = (struct usb_descriptor_header *) itr; 554 hdr = (struct usb_descriptor_header *) itr;
584 d_printf(3, dev, "Extra device descriptor: " 555 dev_dbg(dev, "Extra device descriptor: "
585 "type %02x/%u bytes @ %zu (%zu left)\n", 556 "type %02x/%u bytes @ %zu (%zu left)\n",
586 hdr->bDescriptorType, hdr->bLength, 557 hdr->bDescriptorType, hdr->bLength,
587 (itr - usb_dev->rawdescriptors[actconfig_idx]), 558 (itr - usb_dev->rawdescriptors[actconfig_idx]),
588 itr_size); 559 itr_size);
589 if (hdr->bDescriptorType == USB_DT_WIRE_ADAPTER) 560 if (hdr->bDescriptorType == USB_DT_WIRE_ADAPTER)
590 goto found; 561 goto found;
591 itr += hdr->bLength; 562 itr += hdr->bLength;
@@ -794,7 +765,6 @@ static void hwahc_destroy(struct hwahc *hwahc)
794{ 765{
795 struct wusbhc *wusbhc = &hwahc->wusbhc; 766 struct wusbhc *wusbhc = &hwahc->wusbhc;
796 767
797 d_fnstart(1, NULL, "(hwahc %p)\n", hwahc);
798 mutex_lock(&wusbhc->mutex); 768 mutex_lock(&wusbhc->mutex);
799 __wa_destroy(&hwahc->wa); 769 __wa_destroy(&hwahc->wa);
800 wusbhc_destroy(&hwahc->wusbhc); 770 wusbhc_destroy(&hwahc->wusbhc);
@@ -804,7 +774,6 @@ static void hwahc_destroy(struct hwahc *hwahc)
804 usb_put_intf(hwahc->wa.usb_iface); 774 usb_put_intf(hwahc->wa.usb_iface);
805 usb_put_dev(hwahc->wa.usb_dev); 775 usb_put_dev(hwahc->wa.usb_dev);
806 mutex_unlock(&wusbhc->mutex); 776 mutex_unlock(&wusbhc->mutex);
807 d_fnend(1, NULL, "(hwahc %p) = void\n", hwahc);
808} 777}
809 778
810static void hwahc_init(struct hwahc *hwahc) 779static void hwahc_init(struct hwahc *hwahc)
@@ -821,7 +790,6 @@ static int hwahc_probe(struct usb_interface *usb_iface,
821 struct hwahc *hwahc; 790 struct hwahc *hwahc;
822 struct device *dev = &usb_iface->dev; 791 struct device *dev = &usb_iface->dev;
823 792
824 d_fnstart(4, dev, "(%p, %p)\n", usb_iface, id);
825 result = -ENOMEM; 793 result = -ENOMEM;
826 usb_hcd = usb_create_hcd(&hwahc_hc_driver, &usb_iface->dev, "wusb-hwa"); 794 usb_hcd = usb_create_hcd(&hwahc_hc_driver, &usb_iface->dev, "wusb-hwa");
827 if (usb_hcd == NULL) { 795 if (usb_hcd == NULL) {
@@ -848,7 +816,6 @@ static int hwahc_probe(struct usb_interface *usb_iface,
848 dev_err(dev, "Cannot setup phase B of WUSBHC: %d\n", result); 816 dev_err(dev, "Cannot setup phase B of WUSBHC: %d\n", result);
849 goto error_wusbhc_b_create; 817 goto error_wusbhc_b_create;
850 } 818 }
851 d_fnend(4, dev, "(%p, %p) = 0\n", usb_iface, id);
852 return 0; 819 return 0;
853 820
854error_wusbhc_b_create: 821error_wusbhc_b_create:
@@ -858,7 +825,6 @@ error_add_hcd:
858error_hwahc_create: 825error_hwahc_create:
859 usb_put_hcd(usb_hcd); 826 usb_put_hcd(usb_hcd);
860error_alloc: 827error_alloc:
861 d_fnend(4, dev, "(%p, %p) = %d\n", usb_iface, id, result);
862 return result; 828 return result;
863} 829}
864 830
@@ -872,16 +838,12 @@ static void hwahc_disconnect(struct usb_interface *usb_iface)
872 wusbhc = usb_hcd_to_wusbhc(usb_hcd); 838 wusbhc = usb_hcd_to_wusbhc(usb_hcd);
873 hwahc = container_of(wusbhc, struct hwahc, wusbhc); 839 hwahc = container_of(wusbhc, struct hwahc, wusbhc);
874 840
875 d_fnstart(1, NULL, "(hwahc %p [usb_iface %p])\n", hwahc, usb_iface);
876 wusbhc_b_destroy(&hwahc->wusbhc); 841 wusbhc_b_destroy(&hwahc->wusbhc);
877 usb_remove_hcd(usb_hcd); 842 usb_remove_hcd(usb_hcd);
878 hwahc_destroy(hwahc); 843 hwahc_destroy(hwahc);
879 usb_put_hcd(usb_hcd); 844 usb_put_hcd(usb_hcd);
880 d_fnend(1, NULL, "(hwahc %p [usb_iface %p]) = void\n", hwahc,
881 usb_iface);
882} 845}
883 846
884/** USB device ID's that we handle */
885static struct usb_device_id hwahc_id_table[] = { 847static struct usb_device_id hwahc_id_table[] = {
886 /* FIXME: use class labels for this */ 848 /* FIXME: use class labels for this */
887 { USB_INTERFACE_INFO(0xe0, 0x02, 0x01), }, 849 { USB_INTERFACE_INFO(0xe0, 0x02, 0x01), },
@@ -898,18 +860,7 @@ static struct usb_driver hwahc_driver = {
898 860
899static int __init hwahc_driver_init(void) 861static int __init hwahc_driver_init(void)
900{ 862{
901 int result; 863 return usb_register(&hwahc_driver);
902 result = usb_register(&hwahc_driver);
903 if (result < 0) {
904 printk(KERN_ERR "WA-CDS: Cannot register USB driver: %d\n",
905 result);
906 goto error_usb_register;
907 }
908 return 0;
909
910error_usb_register:
911 return result;
912
913} 864}
914module_init(hwahc_driver_init); 865module_init(hwahc_driver_init);
915 866
diff --git a/drivers/usb/host/whci/Kbuild b/drivers/usb/host/whci/Kbuild
index 26a3871ea0f9..11e5040b8337 100644
--- a/drivers/usb/host/whci/Kbuild
+++ b/drivers/usb/host/whci/Kbuild
@@ -2,6 +2,7 @@ obj-$(CONFIG_USB_WHCI_HCD) += whci-hcd.o
2 2
3whci-hcd-y := \ 3whci-hcd-y := \
4 asl.o \ 4 asl.o \
5 debug.o \
5 hcd.o \ 6 hcd.o \
6 hw.o \ 7 hw.o \
7 init.o \ 8 init.o \
diff --git a/drivers/usb/host/whci/asl.c b/drivers/usb/host/whci/asl.c
index 4d7078e50572..577c0d29849d 100644
--- a/drivers/usb/host/whci/asl.c
+++ b/drivers/usb/host/whci/asl.c
@@ -19,32 +19,11 @@
19#include <linux/dma-mapping.h> 19#include <linux/dma-mapping.h>
20#include <linux/uwb/umc.h> 20#include <linux/uwb/umc.h>
21#include <linux/usb.h> 21#include <linux/usb.h>
22#define D_LOCAL 0
23#include <linux/uwb/debug.h>
24 22
25#include "../../wusbcore/wusbhc.h" 23#include "../../wusbcore/wusbhc.h"
26 24
27#include "whcd.h" 25#include "whcd.h"
28 26
29#if D_LOCAL >= 4
30static void dump_asl(struct whc *whc, const char *tag)
31{
32 struct device *dev = &whc->umc->dev;
33 struct whc_qset *qset;
34
35 d_printf(4, dev, "ASL %s\n", tag);
36
37 list_for_each_entry(qset, &whc->async_list, list_node) {
38 dump_qset(qset, dev);
39 }
40}
41#else
42static inline void dump_asl(struct whc *whc, const char *tag)
43{
44}
45#endif
46
47
48static void qset_get_next_prev(struct whc *whc, struct whc_qset *qset, 27static void qset_get_next_prev(struct whc *whc, struct whc_qset *qset,
49 struct whc_qset **next, struct whc_qset **prev) 28 struct whc_qset **next, struct whc_qset **prev)
50{ 29{
@@ -179,11 +158,26 @@ void asl_stop(struct whc *whc)
179 1000, "stop ASL"); 158 1000, "stop ASL");
180} 159}
181 160
161/**
162 * asl_update - request an ASL update and wait for the hardware to be synced
163 * @whc: the WHCI HC
164 * @wusbcmd: WUSBCMD value to start the update.
165 *
166 * If the WUSB HC is inactive (i.e., the ASL is stopped) then the
167 * update must be skipped as the hardware may not respond to update
168 * requests.
169 */
182void asl_update(struct whc *whc, uint32_t wusbcmd) 170void asl_update(struct whc *whc, uint32_t wusbcmd)
183{ 171{
184 whc_write_wusbcmd(whc, wusbcmd, wusbcmd); 172 struct wusbhc *wusbhc = &whc->wusbhc;
185 wait_event(whc->async_list_wq, 173
186 (le_readl(whc->base + WUSBCMD) & WUSBCMD_ASYNC_UPDATED) == 0); 174 mutex_lock(&wusbhc->mutex);
175 if (wusbhc->active) {
176 whc_write_wusbcmd(whc, wusbcmd, wusbcmd);
177 wait_event(whc->async_list_wq,
178 (le_readl(whc->base + WUSBCMD) & WUSBCMD_ASYNC_UPDATED) == 0);
179 }
180 mutex_unlock(&wusbhc->mutex);
187} 181}
188 182
189/** 183/**
@@ -202,8 +196,6 @@ void scan_async_work(struct work_struct *work)
202 196
203 spin_lock_irq(&whc->lock); 197 spin_lock_irq(&whc->lock);
204 198
205 dump_asl(whc, "before processing");
206
207 /* 199 /*
208 * Transerve the software list backwards so new qsets can be 200 * Transerve the software list backwards so new qsets can be
209 * safely inserted into the ASL without making it non-circular. 201 * safely inserted into the ASL without making it non-circular.
@@ -217,8 +209,6 @@ void scan_async_work(struct work_struct *work)
217 update |= process_qset(whc, qset); 209 update |= process_qset(whc, qset);
218 } 210 }
219 211
220 dump_asl(whc, "after processing");
221
222 spin_unlock_irq(&whc->lock); 212 spin_unlock_irq(&whc->lock);
223 213
224 if (update) { 214 if (update) {
diff --git a/drivers/usb/host/whci/debug.c b/drivers/usb/host/whci/debug.c
new file mode 100644
index 000000000000..cf2d45946c57
--- /dev/null
+++ b/drivers/usb/host/whci/debug.c
@@ -0,0 +1,189 @@
1/*
2 * Wireless Host Controller (WHC) debug.
3 *
4 * Copyright (C) 2008 Cambridge Silicon Radio Ltd.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include <linux/kernel.h>
19#include <linux/debugfs.h>
20#include <linux/seq_file.h>
21
22#include "../../wusbcore/wusbhc.h"
23
24#include "whcd.h"
25
26struct whc_dbg {
27 struct dentry *di_f;
28 struct dentry *asl_f;
29 struct dentry *pzl_f;
30};
31
32void qset_print(struct seq_file *s, struct whc_qset *qset)
33{
34 struct whc_std *std;
35 struct urb *urb = NULL;
36 int i;
37
38 seq_printf(s, "qset %08x\n", (u32)qset->qset_dma);
39 seq_printf(s, " -> %08x\n", (u32)qset->qh.link);
40 seq_printf(s, " info: %08x %08x %08x\n",
41 qset->qh.info1, qset->qh.info2, qset->qh.info3);
42 seq_printf(s, " sts: %04x errs: %d\n", qset->qh.status, qset->qh.err_count);
43 seq_printf(s, " TD: sts: %08x opts: %08x\n",
44 qset->qh.overlay.qtd.status, qset->qh.overlay.qtd.options);
45
46 for (i = 0; i < WHCI_QSET_TD_MAX; i++) {
47 seq_printf(s, " %c%c TD[%d]: sts: %08x opts: %08x ptr: %08x\n",
48 i == qset->td_start ? 'S' : ' ',
49 i == qset->td_end ? 'E' : ' ',
50 i, qset->qtd[i].status, qset->qtd[i].options,
51 (u32)qset->qtd[i].page_list_ptr);
52 }
53 seq_printf(s, " ntds: %d\n", qset->ntds);
54 list_for_each_entry(std, &qset->stds, list_node) {
55 if (urb != std->urb) {
56 urb = std->urb;
57 seq_printf(s, " urb %p transferred: %d bytes\n", urb,
58 urb->actual_length);
59 }
60 if (std->qtd)
61 seq_printf(s, " sTD[%td]: %zu bytes @ %08x\n",
62 std->qtd - &qset->qtd[0],
63 std->len, std->num_pointers ?
64 (u32)(std->pl_virt[0].buf_ptr) : (u32)std->dma_addr);
65 else
66 seq_printf(s, " sTD[-]: %zd bytes @ %08x\n",
67 std->len, std->num_pointers ?
68 (u32)(std->pl_virt[0].buf_ptr) : (u32)std->dma_addr);
69 }
70}
71
72static int di_print(struct seq_file *s, void *p)
73{
74 struct whc *whc = s->private;
75 char buf[72];
76 int d;
77
78 for (d = 0; d < whc->n_devices; d++) {
79 struct di_buf_entry *di = &whc->di_buf[d];
80
81 bitmap_scnprintf(buf, sizeof(buf),
82 (unsigned long *)di->availability_info, UWB_NUM_MAS);
83
84 seq_printf(s, "DI[%d]\n", d);
85 seq_printf(s, " availability: %s\n", buf);
86 seq_printf(s, " %c%c key idx: %d dev addr: %d\n",
87 (di->addr_sec_info & WHC_DI_SECURE) ? 'S' : ' ',
88 (di->addr_sec_info & WHC_DI_DISABLE) ? 'D' : ' ',
89 (di->addr_sec_info & WHC_DI_KEY_IDX_MASK) >> 8,
90 (di->addr_sec_info & WHC_DI_DEV_ADDR_MASK));
91 }
92 return 0;
93}
94
95static int asl_print(struct seq_file *s, void *p)
96{
97 struct whc *whc = s->private;
98 struct whc_qset *qset;
99
100 list_for_each_entry(qset, &whc->async_list, list_node) {
101 qset_print(s, qset);
102 }
103
104 return 0;
105}
106
107static int pzl_print(struct seq_file *s, void *p)
108{
109 struct whc *whc = s->private;
110 struct whc_qset *qset;
111 int period;
112
113 for (period = 0; period < 5; period++) {
114 seq_printf(s, "Period %d\n", period);
115 list_for_each_entry(qset, &whc->periodic_list[period], list_node) {
116 qset_print(s, qset);
117 }
118 }
119 return 0;
120}
121
122static int di_open(struct inode *inode, struct file *file)
123{
124 return single_open(file, di_print, inode->i_private);
125}
126
127static int asl_open(struct inode *inode, struct file *file)
128{
129 return single_open(file, asl_print, inode->i_private);
130}
131
132static int pzl_open(struct inode *inode, struct file *file)
133{
134 return single_open(file, pzl_print, inode->i_private);
135}
136
137static struct file_operations di_fops = {
138 .open = di_open,
139 .read = seq_read,
140 .llseek = seq_lseek,
141 .release = single_release,
142 .owner = THIS_MODULE,
143};
144
145static struct file_operations asl_fops = {
146 .open = asl_open,
147 .read = seq_read,
148 .llseek = seq_lseek,
149 .release = single_release,
150 .owner = THIS_MODULE,
151};
152
153static struct file_operations pzl_fops = {
154 .open = pzl_open,
155 .read = seq_read,
156 .llseek = seq_lseek,
157 .release = single_release,
158 .owner = THIS_MODULE,
159};
160
161void whc_dbg_init(struct whc *whc)
162{
163 if (whc->wusbhc.pal.debugfs_dir == NULL)
164 return;
165
166 whc->dbg = kzalloc(sizeof(struct whc_dbg), GFP_KERNEL);
167 if (whc->dbg == NULL)
168 return;
169
170 whc->dbg->di_f = debugfs_create_file("di", 0444,
171 whc->wusbhc.pal.debugfs_dir, whc,
172 &di_fops);
173 whc->dbg->asl_f = debugfs_create_file("asl", 0444,
174 whc->wusbhc.pal.debugfs_dir, whc,
175 &asl_fops);
176 whc->dbg->pzl_f = debugfs_create_file("pzl", 0444,
177 whc->wusbhc.pal.debugfs_dir, whc,
178 &pzl_fops);
179}
180
181void whc_dbg_clean_up(struct whc *whc)
182{
183 if (whc->dbg) {
184 debugfs_remove(whc->dbg->pzl_f);
185 debugfs_remove(whc->dbg->asl_f);
186 debugfs_remove(whc->dbg->di_f);
187 kfree(whc->dbg);
188 }
189}
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c
index ef3ad4dca945..1569afd6245b 100644
--- a/drivers/usb/host/whci/hcd.c
+++ b/drivers/usb/host/whci/hcd.c
@@ -15,7 +15,6 @@
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18#include <linux/version.h>
19#include <linux/kernel.h> 18#include <linux/kernel.h>
20#include <linux/init.h> 19#include <linux/init.h>
21#include <linux/uwb/umc.h> 20#include <linux/uwb/umc.h>
@@ -92,8 +91,6 @@ static void whc_stop(struct usb_hcd *usb_hcd)
92 91
93 mutex_lock(&wusbhc->mutex); 92 mutex_lock(&wusbhc->mutex);
94 93
95 wusbhc_stop(wusbhc);
96
97 /* stop HC */ 94 /* stop HC */
98 le_writel(0, whc->base + WUSBINTR); 95 le_writel(0, whc->base + WUSBINTR);
99 whc_write_wusbcmd(whc, WUSBCMD_RUN, 0); 96 whc_write_wusbcmd(whc, WUSBCMD_RUN, 0);
@@ -276,6 +273,8 @@ static int whc_probe(struct umc_dev *umc)
276 goto error_wusbhc_b_create; 273 goto error_wusbhc_b_create;
277 } 274 }
278 275
276 whc_dbg_init(whc);
277
279 return 0; 278 return 0;
280 279
281error_wusbhc_b_create: 280error_wusbhc_b_create:
@@ -299,6 +298,7 @@ static void whc_remove(struct umc_dev *umc)
299 struct whc *whc = wusbhc_to_whc(wusbhc); 298 struct whc *whc = wusbhc_to_whc(wusbhc);
300 299
301 if (usb_hcd) { 300 if (usb_hcd) {
301 whc_dbg_clean_up(whc);
302 wusbhc_b_destroy(wusbhc); 302 wusbhc_b_destroy(wusbhc);
303 usb_remove_hcd(usb_hcd); 303 usb_remove_hcd(usb_hcd);
304 wusbhc_destroy(wusbhc); 304 wusbhc_destroy(wusbhc);
diff --git a/drivers/usb/host/whci/hw.c b/drivers/usb/host/whci/hw.c
index ac86e59c1225..d498e7203217 100644
--- a/drivers/usb/host/whci/hw.c
+++ b/drivers/usb/host/whci/hw.c
@@ -50,6 +50,7 @@ int whc_do_gencmd(struct whc *whc, u32 cmd, u32 params, void *addr, size_t len)
50 unsigned long flags; 50 unsigned long flags;
51 dma_addr_t dma_addr; 51 dma_addr_t dma_addr;
52 int t; 52 int t;
53 int ret = 0;
53 54
54 mutex_lock(&whc->mutex); 55 mutex_lock(&whc->mutex);
55 56
@@ -61,7 +62,8 @@ int whc_do_gencmd(struct whc *whc, u32 cmd, u32 params, void *addr, size_t len)
61 dev_err(&whc->umc->dev, "generic command timeout (%04x/%04x)\n", 62 dev_err(&whc->umc->dev, "generic command timeout (%04x/%04x)\n",
62 le_readl(whc->base + WUSBGENCMDSTS), 63 le_readl(whc->base + WUSBGENCMDSTS),
63 le_readl(whc->base + WUSBGENCMDPARAMS)); 64 le_readl(whc->base + WUSBGENCMDPARAMS));
64 return -ETIMEDOUT; 65 ret = -ETIMEDOUT;
66 goto out;
65 } 67 }
66 68
67 if (addr) { 69 if (addr) {
@@ -80,8 +82,8 @@ int whc_do_gencmd(struct whc *whc, u32 cmd, u32 params, void *addr, size_t len)
80 whc->base + WUSBGENCMDSTS); 82 whc->base + WUSBGENCMDSTS);
81 83
82 spin_unlock_irqrestore(&whc->lock, flags); 84 spin_unlock_irqrestore(&whc->lock, flags);
83 85out:
84 mutex_unlock(&whc->mutex); 86 mutex_unlock(&whc->mutex);
85 87
86 return 0; 88 return ret;
87} 89}
diff --git a/drivers/usb/host/whci/int.c b/drivers/usb/host/whci/int.c
index fce01174aa9b..6aae70028101 100644
--- a/drivers/usb/host/whci/int.c
+++ b/drivers/usb/host/whci/int.c
@@ -15,7 +15,6 @@
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18#include <linux/version.h>
19#include <linux/kernel.h> 18#include <linux/kernel.h>
20#include <linux/init.h> 19#include <linux/init.h>
21#include <linux/uwb/umc.h> 20#include <linux/uwb/umc.h>
diff --git a/drivers/usb/host/whci/pzl.c b/drivers/usb/host/whci/pzl.c
index 8d62df0c330b..2ae5abf69a6a 100644
--- a/drivers/usb/host/whci/pzl.c
+++ b/drivers/usb/host/whci/pzl.c
@@ -19,35 +19,11 @@
19#include <linux/dma-mapping.h> 19#include <linux/dma-mapping.h>
20#include <linux/uwb/umc.h> 20#include <linux/uwb/umc.h>
21#include <linux/usb.h> 21#include <linux/usb.h>
22#define D_LOCAL 0
23#include <linux/uwb/debug.h>
24 22
25#include "../../wusbcore/wusbhc.h" 23#include "../../wusbcore/wusbhc.h"
26 24
27#include "whcd.h" 25#include "whcd.h"
28 26
29#if D_LOCAL >= 4
30static void dump_pzl(struct whc *whc, const char *tag)
31{
32 struct device *dev = &whc->umc->dev;
33 struct whc_qset *qset;
34 int period = 0;
35
36 d_printf(4, dev, "PZL %s\n", tag);
37
38 for (period = 0; period < 5; period++) {
39 d_printf(4, dev, "Period %d\n", period);
40 list_for_each_entry(qset, &whc->periodic_list[period], list_node) {
41 dump_qset(qset, dev);
42 }
43 }
44}
45#else
46static inline void dump_pzl(struct whc *whc, const char *tag)
47{
48}
49#endif
50
51static void update_pzl_pointers(struct whc *whc, int period, u64 addr) 27static void update_pzl_pointers(struct whc *whc, int period, u64 addr)
52{ 28{
53 switch (period) { 29 switch (period) {
@@ -195,11 +171,26 @@ void pzl_stop(struct whc *whc)
195 1000, "stop PZL"); 171 1000, "stop PZL");
196} 172}
197 173
174/**
175 * pzl_update - request a PZL update and wait for the hardware to be synced
176 * @whc: the WHCI HC
177 * @wusbcmd: WUSBCMD value to start the update.
178 *
179 * If the WUSB HC is inactive (i.e., the PZL is stopped) then the
180 * update must be skipped as the hardware may not respond to update
181 * requests.
182 */
198void pzl_update(struct whc *whc, uint32_t wusbcmd) 183void pzl_update(struct whc *whc, uint32_t wusbcmd)
199{ 184{
200 whc_write_wusbcmd(whc, wusbcmd, wusbcmd); 185 struct wusbhc *wusbhc = &whc->wusbhc;
201 wait_event(whc->periodic_list_wq, 186
202 (le_readl(whc->base + WUSBCMD) & WUSBCMD_PERIODIC_UPDATED) == 0); 187 mutex_lock(&wusbhc->mutex);
188 if (wusbhc->active) {
189 whc_write_wusbcmd(whc, wusbcmd, wusbcmd);
190 wait_event(whc->periodic_list_wq,
191 (le_readl(whc->base + WUSBCMD) & WUSBCMD_PERIODIC_UPDATED) == 0);
192 }
193 mutex_unlock(&wusbhc->mutex);
203} 194}
204 195
205static void update_pzl_hw_view(struct whc *whc) 196static void update_pzl_hw_view(struct whc *whc)
@@ -235,8 +226,6 @@ void scan_periodic_work(struct work_struct *work)
235 226
236 spin_lock_irq(&whc->lock); 227 spin_lock_irq(&whc->lock);
237 228
238 dump_pzl(whc, "before processing");
239
240 for (period = 4; period >= 0; period--) { 229 for (period = 4; period >= 0; period--) {
241 list_for_each_entry_safe(qset, t, &whc->periodic_list[period], list_node) { 230 list_for_each_entry_safe(qset, t, &whc->periodic_list[period], list_node) {
242 if (!qset->in_hw_list) 231 if (!qset->in_hw_list)
@@ -248,8 +237,6 @@ void scan_periodic_work(struct work_struct *work)
248 if (update & (WHC_UPDATE_ADDED | WHC_UPDATE_REMOVED)) 237 if (update & (WHC_UPDATE_ADDED | WHC_UPDATE_REMOVED))
249 update_pzl_hw_view(whc); 238 update_pzl_hw_view(whc);
250 239
251 dump_pzl(whc, "after processing");
252
253 spin_unlock_irq(&whc->lock); 240 spin_unlock_irq(&whc->lock);
254 241
255 if (update) { 242 if (update) {
diff --git a/drivers/usb/host/whci/qset.c b/drivers/usb/host/whci/qset.c
index 0420037d2e18..7be74314ee12 100644
--- a/drivers/usb/host/whci/qset.c
+++ b/drivers/usb/host/whci/qset.c
@@ -24,46 +24,6 @@
24 24
25#include "whcd.h" 25#include "whcd.h"
26 26
27void dump_qset(struct whc_qset *qset, struct device *dev)
28{
29 struct whc_std *std;
30 struct urb *urb = NULL;
31 int i;
32
33 dev_dbg(dev, "qset %08x\n", (u32)qset->qset_dma);
34 dev_dbg(dev, " -> %08x\n", (u32)qset->qh.link);
35 dev_dbg(dev, " info: %08x %08x %08x\n",
36 qset->qh.info1, qset->qh.info2, qset->qh.info3);
37 dev_dbg(dev, " sts: %04x errs: %d\n", qset->qh.status, qset->qh.err_count);
38 dev_dbg(dev, " TD: sts: %08x opts: %08x\n",
39 qset->qh.overlay.qtd.status, qset->qh.overlay.qtd.options);
40
41 for (i = 0; i < WHCI_QSET_TD_MAX; i++) {
42 dev_dbg(dev, " %c%c TD[%d]: sts: %08x opts: %08x ptr: %08x\n",
43 i == qset->td_start ? 'S' : ' ',
44 i == qset->td_end ? 'E' : ' ',
45 i, qset->qtd[i].status, qset->qtd[i].options,
46 (u32)qset->qtd[i].page_list_ptr);
47 }
48 dev_dbg(dev, " ntds: %d\n", qset->ntds);
49 list_for_each_entry(std, &qset->stds, list_node) {
50 if (urb != std->urb) {
51 urb = std->urb;
52 dev_dbg(dev, " urb %p transferred: %d bytes\n", urb,
53 urb->actual_length);
54 }
55 if (std->qtd)
56 dev_dbg(dev, " sTD[%td]: %zu bytes @ %08x\n",
57 std->qtd - &qset->qtd[0],
58 std->len, std->num_pointers ?
59 (u32)(std->pl_virt[0].buf_ptr) : (u32)std->dma_addr);
60 else
61 dev_dbg(dev, " sTD[-]: %zd bytes @ %08x\n",
62 std->len, std->num_pointers ?
63 (u32)(std->pl_virt[0].buf_ptr) : (u32)std->dma_addr);
64 }
65}
66
67struct whc_qset *qset_alloc(struct whc *whc, gfp_t mem_flags) 27struct whc_qset *qset_alloc(struct whc *whc, gfp_t mem_flags)
68{ 28{
69 struct whc_qset *qset; 29 struct whc_qset *qset;
diff --git a/drivers/usb/host/whci/whcd.h b/drivers/usb/host/whci/whcd.h
index 1d2a53bd39fd..0f3540f04f53 100644
--- a/drivers/usb/host/whci/whcd.h
+++ b/drivers/usb/host/whci/whcd.h
@@ -21,6 +21,7 @@
21#define __WHCD_H 21#define __WHCD_H
22 22
23#include <linux/uwb/whci.h> 23#include <linux/uwb/whci.h>
24#include <linux/uwb/umc.h>
24#include <linux/workqueue.h> 25#include <linux/workqueue.h>
25 26
26#include "whci-hc.h" 27#include "whci-hc.h"
@@ -28,6 +29,7 @@
28/* Generic command timeout. */ 29/* Generic command timeout. */
29#define WHC_GENCMD_TIMEOUT_MS 100 30#define WHC_GENCMD_TIMEOUT_MS 100
30 31
32struct whc_dbg;
31 33
32struct whc { 34struct whc {
33 struct wusbhc wusbhc; 35 struct wusbhc wusbhc;
@@ -69,6 +71,8 @@ struct whc {
69 struct list_head periodic_removed_list; 71 struct list_head periodic_removed_list;
70 wait_queue_head_t periodic_list_wq; 72 wait_queue_head_t periodic_list_wq;
71 struct work_struct periodic_work; 73 struct work_struct periodic_work;
74
75 struct whc_dbg *dbg;
72}; 76};
73 77
74#define wusbhc_to_whc(w) (container_of((w), struct whc, wusbhc)) 78#define wusbhc_to_whc(w) (container_of((w), struct whc, wusbhc))
@@ -136,7 +140,7 @@ int whc_do_gencmd(struct whc *whc, u32 cmd, u32 params, void *addr, size_t len);
136 140
137/* wusb.c */ 141/* wusb.c */
138int whc_wusbhc_start(struct wusbhc *wusbhc); 142int whc_wusbhc_start(struct wusbhc *wusbhc);
139void whc_wusbhc_stop(struct wusbhc *wusbhc); 143void whc_wusbhc_stop(struct wusbhc *wusbhc, int delay);
140int whc_mmcie_add(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt, 144int whc_mmcie_add(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt,
141 u8 handle, struct wuie_hdr *wuie); 145 u8 handle, struct wuie_hdr *wuie);
142int whc_mmcie_rm(struct wusbhc *wusbhc, u8 handle); 146int whc_mmcie_rm(struct wusbhc *wusbhc, u8 handle);
@@ -190,8 +194,11 @@ void process_inactive_qtd(struct whc *whc, struct whc_qset *qset,
190 struct whc_qtd *qtd); 194 struct whc_qtd *qtd);
191enum whc_update qset_add_qtds(struct whc *whc, struct whc_qset *qset); 195enum whc_update qset_add_qtds(struct whc *whc, struct whc_qset *qset);
192void qset_remove_complete(struct whc *whc, struct whc_qset *qset); 196void qset_remove_complete(struct whc *whc, struct whc_qset *qset);
193void dump_qset(struct whc_qset *qset, struct device *dev);
194void pzl_update(struct whc *whc, uint32_t wusbcmd); 197void pzl_update(struct whc *whc, uint32_t wusbcmd);
195void asl_update(struct whc *whc, uint32_t wusbcmd); 198void asl_update(struct whc *whc, uint32_t wusbcmd);
196 199
200/* debug.c */
201void whc_dbg_init(struct whc *whc);
202void whc_dbg_clean_up(struct whc *whc);
203
197#endif /* #ifndef __WHCD_H */ 204#endif /* #ifndef __WHCD_H */
diff --git a/drivers/usb/host/whci/whci-hc.h b/drivers/usb/host/whci/whci-hc.h
index bff1eb7a35cf..51df7e313b38 100644
--- a/drivers/usb/host/whci/whci-hc.h
+++ b/drivers/usb/host/whci/whci-hc.h
@@ -410,6 +410,8 @@ struct dn_buf_entry {
410# define WUSBDNTSCTRL_SLOTS(s) ((s) << 0) 410# define WUSBDNTSCTRL_SLOTS(s) ((s) << 0)
411 411
412#define WUSBTIME 0x68 412#define WUSBTIME 0x68
413# define WUSBTIME_CHANNEL_TIME_MASK 0x00ffffff
414
413#define WUSBBPST 0x6c 415#define WUSBBPST 0x6c
414#define WUSBDIBUPDATED 0x70 416#define WUSBDIBUPDATED 0x70
415 417
diff --git a/drivers/usb/host/whci/wusb.c b/drivers/usb/host/whci/wusb.c
index 66e4ddcd961d..f24efdebad17 100644
--- a/drivers/usb/host/whci/wusb.c
+++ b/drivers/usb/host/whci/wusb.c
@@ -15,47 +15,19 @@
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18#include <linux/version.h>
19#include <linux/kernel.h> 18#include <linux/kernel.h>
20#include <linux/init.h> 19#include <linux/init.h>
21#include <linux/uwb/umc.h> 20#include <linux/uwb/umc.h>
22#define D_LOCAL 1
23#include <linux/uwb/debug.h>
24 21
25#include "../../wusbcore/wusbhc.h" 22#include "../../wusbcore/wusbhc.h"
26 23
27#include "whcd.h" 24#include "whcd.h"
28 25
29#if D_LOCAL >= 1
30static void dump_di(struct whc *whc, int idx)
31{
32 struct di_buf_entry *di = &whc->di_buf[idx];
33 struct device *dev = &whc->umc->dev;
34 char buf[128];
35
36 bitmap_scnprintf(buf, sizeof(buf), (unsigned long *)di->availability_info, UWB_NUM_MAS);
37
38 d_printf(1, dev, "DI[%d]\n", idx);
39 d_printf(1, dev, " availability: %s\n", buf);
40 d_printf(1, dev, " %c%c key idx: %d dev addr: %d\n",
41 (di->addr_sec_info & WHC_DI_SECURE) ? 'S' : ' ',
42 (di->addr_sec_info & WHC_DI_DISABLE) ? 'D' : ' ',
43 (di->addr_sec_info & WHC_DI_KEY_IDX_MASK) >> 8,
44 (di->addr_sec_info & WHC_DI_DEV_ADDR_MASK));
45}
46#else
47static inline void dump_di(struct whc *whc, int idx)
48{
49}
50#endif
51
52static int whc_update_di(struct whc *whc, int idx) 26static int whc_update_di(struct whc *whc, int idx)
53{ 27{
54 int offset = idx / 32; 28 int offset = idx / 32;
55 u32 bit = 1 << (idx % 32); 29 u32 bit = 1 << (idx % 32);
56 30
57 dump_di(whc, idx);
58
59 le_writel(bit, whc->base + WUSBDIBUPDATED + offset); 31 le_writel(bit, whc->base + WUSBDIBUPDATED + offset);
60 32
61 return whci_wait_for(&whc->umc->dev, 33 return whci_wait_for(&whc->umc->dev,
@@ -64,8 +36,9 @@ static int whc_update_di(struct whc *whc, int idx)
64} 36}
65 37
66/* 38/*
67 * WHCI starts and stops MMCs based on there being a valid GTK so 39 * WHCI starts MMCs based on there being a valid GTK so these need
68 * these need only start/stop the asynchronous and periodic schedules. 40 * only start/stop the asynchronous and periodic schedules and send a
41 * channel stop command.
69 */ 42 */
70 43
71int whc_wusbhc_start(struct wusbhc *wusbhc) 44int whc_wusbhc_start(struct wusbhc *wusbhc)
@@ -78,12 +51,20 @@ int whc_wusbhc_start(struct wusbhc *wusbhc)
78 return 0; 51 return 0;
79} 52}
80 53
81void whc_wusbhc_stop(struct wusbhc *wusbhc) 54void whc_wusbhc_stop(struct wusbhc *wusbhc, int delay)
82{ 55{
83 struct whc *whc = wusbhc_to_whc(wusbhc); 56 struct whc *whc = wusbhc_to_whc(wusbhc);
57 u32 stop_time, now_time;
58 int ret;
84 59
85 pzl_stop(whc); 60 pzl_stop(whc);
86 asl_stop(whc); 61 asl_stop(whc);
62
63 now_time = le_readl(whc->base + WUSBTIME) & WUSBTIME_CHANNEL_TIME_MASK;
64 stop_time = (now_time + ((delay * 8) << 7)) & 0x00ffffff;
65 ret = whc_do_gencmd(whc, WUSBGENCMDSTS_CHAN_STOP, stop_time, NULL, 0);
66 if (ret == 0)
67 msleep(delay);
87} 68}
88 69
89int whc_mmcie_add(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt, 70int whc_mmcie_add(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt,
diff --git a/drivers/usb/wusbcore/cbaf.c b/drivers/usb/wusbcore/cbaf.c
index ab4788d1785a..1335cbe1191d 100644
--- a/drivers/usb/wusbcore/cbaf.c
+++ b/drivers/usb/wusbcore/cbaf.c
@@ -88,7 +88,6 @@
88 */ 88 */
89#include <linux/module.h> 89#include <linux/module.h>
90#include <linux/ctype.h> 90#include <linux/ctype.h>
91#include <linux/version.h>
92#include <linux/usb.h> 91#include <linux/usb.h>
93#include <linux/interrupt.h> 92#include <linux/interrupt.h>
94#include <linux/delay.h> 93#include <linux/delay.h>
diff --git a/drivers/usb/wusbcore/crypto.c b/drivers/usb/wusbcore/crypto.c
index c36c4389baae..9ec7fd5da489 100644
--- a/drivers/usb/wusbcore/crypto.c
+++ b/drivers/usb/wusbcore/crypto.c
@@ -51,9 +51,17 @@
51#include <linux/uwb.h> 51#include <linux/uwb.h>
52#include <linux/usb/wusb.h> 52#include <linux/usb/wusb.h>
53#include <linux/scatterlist.h> 53#include <linux/scatterlist.h>
54#define D_LOCAL 0
55#include <linux/uwb/debug.h>
56 54
55static int debug_crypto_verify = 0;
56
57module_param(debug_crypto_verify, int, 0);
58MODULE_PARM_DESC(debug_crypto_verify, "verify the key generation algorithms");
59
60static void wusb_key_dump(const void *buf, size_t len)
61{
62 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_OFFSET, 16, 1,
63 buf, len, 0);
64}
57 65
58/* 66/*
59 * Block of data, as understood by AES-CCM 67 * Block of data, as understood by AES-CCM
@@ -203,9 +211,6 @@ static int wusb_ccm_mac(struct crypto_blkcipher *tfm_cbc,
203 const u8 bzero[16] = { 0 }; 211 const u8 bzero[16] = { 0 };
204 size_t zero_padding; 212 size_t zero_padding;
205 213
206 d_fnstart(3, NULL, "(tfm_cbc %p, tfm_aes %p, mic %p, "
207 "n %p, a %p, b %p, blen %zu)\n",
208 tfm_cbc, tfm_aes, mic, n, a, b, blen);
209 /* 214 /*
210 * These checks should be compile time optimized out 215 * These checks should be compile time optimized out
211 * ensure @a fills b1's mac_header and following fields 216 * ensure @a fills b1's mac_header and following fields
@@ -247,16 +252,6 @@ static int wusb_ccm_mac(struct crypto_blkcipher *tfm_cbc,
247 b1.la = cpu_to_be16(blen + 14); 252 b1.la = cpu_to_be16(blen + 14);
248 memcpy(&b1.mac_header, a, sizeof(*a)); 253 memcpy(&b1.mac_header, a, sizeof(*a));
249 254
250 d_printf(4, NULL, "I: B0 (%zu bytes)\n", sizeof(b0));
251 d_dump(4, NULL, &b0, sizeof(b0));
252 d_printf(4, NULL, "I: B1 (%zu bytes)\n", sizeof(b1));
253 d_dump(4, NULL, &b1, sizeof(b1));
254 d_printf(4, NULL, "I: B (%zu bytes)\n", blen);
255 d_dump(4, NULL, b, blen);
256 d_printf(4, NULL, "I: B 0-padding (%zu bytes)\n", zero_padding);
257 d_printf(4, NULL, "D: IV before crypto (%zu)\n", ivsize);
258 d_dump(4, NULL, iv, ivsize);
259
260 sg_init_table(sg, ARRAY_SIZE(sg)); 255 sg_init_table(sg, ARRAY_SIZE(sg));
261 sg_set_buf(&sg[0], &b0, sizeof(b0)); 256 sg_set_buf(&sg[0], &b0, sizeof(b0));
262 sg_set_buf(&sg[1], &b1, sizeof(b1)); 257 sg_set_buf(&sg[1], &b1, sizeof(b1));
@@ -273,8 +268,6 @@ static int wusb_ccm_mac(struct crypto_blkcipher *tfm_cbc,
273 result); 268 result);
274 goto error_cbc_crypt; 269 goto error_cbc_crypt;
275 } 270 }
276 d_printf(4, NULL, "D: MIC tag\n");
277 d_dump(4, NULL, iv, ivsize);
278 271
279 /* Now we crypt the MIC Tag (*iv) with Ax -- values per WUSB1.0[6.5] 272 /* Now we crypt the MIC Tag (*iv) with Ax -- values per WUSB1.0[6.5]
280 * The procedure is to AES crypt the A0 block and XOR the MIC 273 * The procedure is to AES crypt the A0 block and XOR the MIC
@@ -289,17 +282,10 @@ static int wusb_ccm_mac(struct crypto_blkcipher *tfm_cbc,
289 ax.counter = 0; 282 ax.counter = 0;
290 crypto_cipher_encrypt_one(tfm_aes, (void *)&ax, (void *)&ax); 283 crypto_cipher_encrypt_one(tfm_aes, (void *)&ax, (void *)&ax);
291 bytewise_xor(mic, &ax, iv, 8); 284 bytewise_xor(mic, &ax, iv, 8);
292 d_printf(4, NULL, "D: CTR[MIC]\n");
293 d_dump(4, NULL, &ax, 8);
294 d_printf(4, NULL, "D: CCM-MIC tag\n");
295 d_dump(4, NULL, mic, 8);
296 result = 8; 285 result = 8;
297error_cbc_crypt: 286error_cbc_crypt:
298 kfree(dst_buf); 287 kfree(dst_buf);
299error_dst_buf: 288error_dst_buf:
300 d_fnend(3, NULL, "(tfm_cbc %p, tfm_aes %p, mic %p, "
301 "n %p, a %p, b %p, blen %zu)\n",
302 tfm_cbc, tfm_aes, mic, n, a, b, blen);
303 return result; 289 return result;
304} 290}
305 291
@@ -321,10 +307,6 @@ ssize_t wusb_prf(void *out, size_t out_size,
321 u64 sfn = 0; 307 u64 sfn = 0;
322 __le64 sfn_le; 308 __le64 sfn_le;
323 309
324 d_fnstart(3, NULL, "(out %p, out_size %zu, key %p, _n %p, "
325 "a %p, b %p, blen %zu, len %zu)\n", out, out_size,
326 key, _n, a, b, blen, len);
327
328 tfm_cbc = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC); 310 tfm_cbc = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
329 if (IS_ERR(tfm_cbc)) { 311 if (IS_ERR(tfm_cbc)) {
330 result = PTR_ERR(tfm_cbc); 312 result = PTR_ERR(tfm_cbc);
@@ -366,9 +348,6 @@ error_alloc_aes:
366error_setkey_cbc: 348error_setkey_cbc:
367 crypto_free_blkcipher(tfm_cbc); 349 crypto_free_blkcipher(tfm_cbc);
368error_alloc_cbc: 350error_alloc_cbc:
369 d_fnend(3, NULL, "(out %p, out_size %zu, key %p, _n %p, "
370 "a %p, b %p, blen %zu, len %zu) = %d\n", out, out_size,
371 key, _n, a, b, blen, len, (int)bytes);
372 return result; 351 return result;
373} 352}
374 353
@@ -422,14 +401,14 @@ static int wusb_oob_mic_verify(void)
422 "mismatch between MIC result and WUSB1.0[A2]\n"); 401 "mismatch between MIC result and WUSB1.0[A2]\n");
423 hs_size = sizeof(stv_hsmic_hs) - sizeof(stv_hsmic_hs.MIC); 402 hs_size = sizeof(stv_hsmic_hs) - sizeof(stv_hsmic_hs.MIC);
424 printk(KERN_ERR "E: Handshake2 in: (%zu bytes)\n", hs_size); 403 printk(KERN_ERR "E: Handshake2 in: (%zu bytes)\n", hs_size);
425 dump_bytes(NULL, &stv_hsmic_hs, hs_size); 404 wusb_key_dump(&stv_hsmic_hs, hs_size);
426 printk(KERN_ERR "E: CCM Nonce in: (%zu bytes)\n", 405 printk(KERN_ERR "E: CCM Nonce in: (%zu bytes)\n",
427 sizeof(stv_hsmic_n)); 406 sizeof(stv_hsmic_n));
428 dump_bytes(NULL, &stv_hsmic_n, sizeof(stv_hsmic_n)); 407 wusb_key_dump(&stv_hsmic_n, sizeof(stv_hsmic_n));
429 printk(KERN_ERR "E: MIC out:\n"); 408 printk(KERN_ERR "E: MIC out:\n");
430 dump_bytes(NULL, mic, sizeof(mic)); 409 wusb_key_dump(mic, sizeof(mic));
431 printk(KERN_ERR "E: MIC out (from WUSB1.0[A.2]):\n"); 410 printk(KERN_ERR "E: MIC out (from WUSB1.0[A.2]):\n");
432 dump_bytes(NULL, stv_hsmic_hs.MIC, sizeof(stv_hsmic_hs.MIC)); 411 wusb_key_dump(stv_hsmic_hs.MIC, sizeof(stv_hsmic_hs.MIC));
433 result = -EINVAL; 412 result = -EINVAL;
434 } else 413 } else
435 result = 0; 414 result = 0;
@@ -497,19 +476,16 @@ static int wusb_key_derive_verify(void)
497 printk(KERN_ERR "E: WUSB key derivation test: " 476 printk(KERN_ERR "E: WUSB key derivation test: "
498 "mismatch between key derivation result " 477 "mismatch between key derivation result "
499 "and WUSB1.0[A1] Errata 2006/12\n"); 478 "and WUSB1.0[A1] Errata 2006/12\n");
500 printk(KERN_ERR "E: keydvt in: key (%zu bytes)\n", 479 printk(KERN_ERR "E: keydvt in: key\n");
501 sizeof(stv_key_a1)); 480 wusb_key_dump(stv_key_a1, sizeof(stv_key_a1));
502 dump_bytes(NULL, stv_key_a1, sizeof(stv_key_a1)); 481 printk(KERN_ERR "E: keydvt in: nonce\n");
503 printk(KERN_ERR "E: keydvt in: nonce (%zu bytes)\n", 482 wusb_key_dump( &stv_keydvt_n_a1, sizeof(stv_keydvt_n_a1));
504 sizeof(stv_keydvt_n_a1)); 483 printk(KERN_ERR "E: keydvt in: hnonce & dnonce\n");
505 dump_bytes(NULL, &stv_keydvt_n_a1, sizeof(stv_keydvt_n_a1)); 484 wusb_key_dump(&stv_keydvt_in_a1, sizeof(stv_keydvt_in_a1));
506 printk(KERN_ERR "E: keydvt in: hnonce & dnonce (%zu bytes)\n",
507 sizeof(stv_keydvt_in_a1));
508 dump_bytes(NULL, &stv_keydvt_in_a1, sizeof(stv_keydvt_in_a1));
509 printk(KERN_ERR "E: keydvt out: KCK\n"); 485 printk(KERN_ERR "E: keydvt out: KCK\n");
510 dump_bytes(NULL, &keydvt_out.kck, sizeof(keydvt_out.kck)); 486 wusb_key_dump(&keydvt_out.kck, sizeof(keydvt_out.kck));
511 printk(KERN_ERR "E: keydvt out: PTK\n"); 487 printk(KERN_ERR "E: keydvt out: PTK\n");
512 dump_bytes(NULL, &keydvt_out.ptk, sizeof(keydvt_out.ptk)); 488 wusb_key_dump(&keydvt_out.ptk, sizeof(keydvt_out.ptk));
513 result = -EINVAL; 489 result = -EINVAL;
514 } else 490 } else
515 result = 0; 491 result = 0;
@@ -526,10 +502,13 @@ int wusb_crypto_init(void)
526{ 502{
527 int result; 503 int result;
528 504
529 result = wusb_key_derive_verify(); 505 if (debug_crypto_verify) {
530 if (result < 0) 506 result = wusb_key_derive_verify();
531 return result; 507 if (result < 0)
532 return wusb_oob_mic_verify(); 508 return result;
509 return wusb_oob_mic_verify();
510 }
511 return 0;
533} 512}
534 513
535void wusb_crypto_exit(void) 514void wusb_crypto_exit(void)
diff --git a/drivers/usb/wusbcore/dev-sysfs.c b/drivers/usb/wusbcore/dev-sysfs.c
index 7897a19652e5..101834576236 100644
--- a/drivers/usb/wusbcore/dev-sysfs.c
+++ b/drivers/usb/wusbcore/dev-sysfs.c
@@ -28,10 +28,6 @@
28#include <linux/workqueue.h> 28#include <linux/workqueue.h>
29#include "wusbhc.h" 29#include "wusbhc.h"
30 30
31#undef D_LOCAL
32#define D_LOCAL 4
33#include <linux/uwb/debug.h>
34
35static ssize_t wusb_disconnect_store(struct device *dev, 31static ssize_t wusb_disconnect_store(struct device *dev,
36 struct device_attribute *attr, 32 struct device_attribute *attr,
37 const char *buf, size_t size) 33 const char *buf, size_t size)
diff --git a/drivers/usb/wusbcore/devconnect.c b/drivers/usb/wusbcore/devconnect.c
index f45d777bef34..e2e7e4bc8463 100644
--- a/drivers/usb/wusbcore/devconnect.c
+++ b/drivers/usb/wusbcore/devconnect.c
@@ -57,9 +57,6 @@
57 * Called by notif.c:wusb_handle_dn_connect() 57 * Called by notif.c:wusb_handle_dn_connect()
58 * when a DN_Connect is received. 58 * when a DN_Connect is received.
59 * 59 *
60 * wusbhc_devconnect_auth() Called by rh.c:wusbhc_rh_port_reset() when
61 * doing the device connect sequence.
62 *
63 * wusb_devconnect_acked() Ack done, release resources. 60 * wusb_devconnect_acked() Ack done, release resources.
64 * 61 *
65 * wusb_handle_dn_alive() Called by notif.c:wusb_handle_dn() 62 * wusb_handle_dn_alive() Called by notif.c:wusb_handle_dn()
@@ -69,9 +66,6 @@
69 * process a disconenct request from a 66 * process a disconenct request from a
70 * device. 67 * device.
71 * 68 *
72 * wusb_dev_reset() Called by rh.c:wusbhc_rh_port_reset() when
73 * resetting a device.
74 *
75 * __wusb_dev_disable() Called by rh.c:wusbhc_rh_clear_port_feat() when 69 * __wusb_dev_disable() Called by rh.c:wusbhc_rh_clear_port_feat() when
76 * disabling a port. 70 * disabling a port.
77 * 71 *
@@ -97,10 +91,6 @@
97#include <linux/workqueue.h> 91#include <linux/workqueue.h>
98#include "wusbhc.h" 92#include "wusbhc.h"
99 93
100#undef D_LOCAL
101#define D_LOCAL 1
102#include <linux/uwb/debug.h>
103
104static void wusbhc_devconnect_acked_work(struct work_struct *work); 94static void wusbhc_devconnect_acked_work(struct work_struct *work);
105 95
106static void wusb_dev_free(struct wusb_dev *wusb_dev) 96static void wusb_dev_free(struct wusb_dev *wusb_dev)
@@ -240,6 +230,7 @@ static struct wusb_dev *wusbhc_cack_add(struct wusbhc *wusbhc,
240 list_add_tail(&wusb_dev->cack_node, &wusbhc->cack_list); 230 list_add_tail(&wusb_dev->cack_node, &wusbhc->cack_list);
241 wusbhc->cack_count++; 231 wusbhc->cack_count++;
242 wusbhc_fill_cack_ie(wusbhc); 232 wusbhc_fill_cack_ie(wusbhc);
233
243 return wusb_dev; 234 return wusb_dev;
244} 235}
245 236
@@ -250,12 +241,9 @@ static struct wusb_dev *wusbhc_cack_add(struct wusbhc *wusbhc,
250 */ 241 */
251static void wusbhc_cack_rm(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev) 242static void wusbhc_cack_rm(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
252{ 243{
253 struct device *dev = wusbhc->dev;
254 d_fnstart(3, dev, "(wusbhc %p wusb_dev %p)\n", wusbhc, wusb_dev);
255 list_del_init(&wusb_dev->cack_node); 244 list_del_init(&wusb_dev->cack_node);
256 wusbhc->cack_count--; 245 wusbhc->cack_count--;
257 wusbhc_fill_cack_ie(wusbhc); 246 wusbhc_fill_cack_ie(wusbhc);
258 d_fnend(3, dev, "(wusbhc %p wusb_dev %p) = void\n", wusbhc, wusb_dev);
259} 247}
260 248
261/* 249/*
@@ -263,14 +251,11 @@ static void wusbhc_cack_rm(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
263static 251static
264void wusbhc_devconnect_acked(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev) 252void wusbhc_devconnect_acked(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
265{ 253{
266 struct device *dev = wusbhc->dev;
267 d_fnstart(3, dev, "(wusbhc %p wusb_dev %p)\n", wusbhc, wusb_dev);
268 wusbhc_cack_rm(wusbhc, wusb_dev); 254 wusbhc_cack_rm(wusbhc, wusb_dev);
269 if (wusbhc->cack_count) 255 if (wusbhc->cack_count)
270 wusbhc_mmcie_set(wusbhc, 0, 0, &wusbhc->cack_ie.hdr); 256 wusbhc_mmcie_set(wusbhc, 0, 0, &wusbhc->cack_ie.hdr);
271 else 257 else
272 wusbhc_mmcie_rm(wusbhc, &wusbhc->cack_ie.hdr); 258 wusbhc_mmcie_rm(wusbhc, &wusbhc->cack_ie.hdr);
273 d_fnend(3, dev, "(wusbhc %p wusb_dev %p) = void\n", wusbhc, wusb_dev);
274} 259}
275 260
276static void wusbhc_devconnect_acked_work(struct work_struct *work) 261static 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,
320 struct wusb_port *port; 305 struct wusb_port *port;
321 unsigned idx, devnum; 306 unsigned idx, devnum;
322 307
323 d_fnstart(3, dev, "(%p, %p, %s)\n", wusbhc, dnc, pr_cdid);
324 mutex_lock(&wusbhc->mutex); 308 mutex_lock(&wusbhc->mutex);
325 309
326 /* Check we are not handling it already */ 310 /* Check we are not handling it already */
@@ -366,16 +350,13 @@ void wusbhc_devconnect_ack(struct wusbhc *wusbhc, struct wusb_dn_connect *dnc,
366 port->wusb_dev = wusb_dev; 350 port->wusb_dev = wusb_dev;
367 port->status |= USB_PORT_STAT_CONNECTION; 351 port->status |= USB_PORT_STAT_CONNECTION;
368 port->change |= USB_PORT_STAT_C_CONNECTION; 352 port->change |= USB_PORT_STAT_C_CONNECTION;
369 port->reset_count = 0;
370 /* Now the port status changed to connected; khubd will 353 /* Now the port status changed to connected; khubd will
371 * pick the change up and try to reset the port to bring it to 354 * pick the change up and try to reset the port to bring it to
372 * the enabled state--so this process returns up to the stack 355 * the enabled state--so this process returns up to the stack
373 * and it calls back into wusbhc_rh_port_reset() who will call 356 * and it calls back into wusbhc_rh_port_reset().
374 * devconnect_auth().
375 */ 357 */
376error_unlock: 358error_unlock:
377 mutex_unlock(&wusbhc->mutex); 359 mutex_unlock(&wusbhc->mutex);
378 d_fnend(3, dev, "(%p, %p, %s) = void\n", wusbhc, dnc, pr_cdid);
379 return; 360 return;
380 361
381} 362}
@@ -398,10 +379,8 @@ error_unlock:
398static void __wusbhc_dev_disconnect(struct wusbhc *wusbhc, 379static void __wusbhc_dev_disconnect(struct wusbhc *wusbhc,
399 struct wusb_port *port) 380 struct wusb_port *port)
400{ 381{
401 struct device *dev = wusbhc->dev;
402 struct wusb_dev *wusb_dev = port->wusb_dev; 382 struct wusb_dev *wusb_dev = port->wusb_dev;
403 383
404 d_fnstart(3, dev, "(wusbhc %p, port %p)\n", wusbhc, port);
405 port->status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE 384 port->status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE
406 | USB_PORT_STAT_SUSPEND | USB_PORT_STAT_RESET 385 | USB_PORT_STAT_SUSPEND | USB_PORT_STAT_RESET
407 | USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED); 386 | USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED);
@@ -413,15 +392,11 @@ static void __wusbhc_dev_disconnect(struct wusbhc *wusbhc,
413 wusb_dev_put(wusb_dev); 392 wusb_dev_put(wusb_dev);
414 } 393 }
415 port->wusb_dev = NULL; 394 port->wusb_dev = NULL;
416 /* don't reset the reset_count to zero or wusbhc_rh_port_reset will get
417 * confused! We only reset to zero when we connect a new device.
418 */
419 395
420 /* After a device disconnects, change the GTK (see [WUSB] 396 /* After a device disconnects, change the GTK (see [WUSB]
421 * section 6.2.11.2). */ 397 * section 6.2.11.2). */
422 wusbhc_gtk_rekey(wusbhc); 398 wusbhc_gtk_rekey(wusbhc);
423 399
424 d_fnend(3, dev, "(wusbhc %p, port %p) = void\n", wusbhc, port);
425 /* The Wireless USB part has forgotten about the device already; now 400 /* The Wireless USB part has forgotten about the device already; now
426 * khubd's timer will pick up the disconnection and remove the USB 401 * khubd's timer will pick up the disconnection and remove the USB
427 * device from the system 402 * device from the system
@@ -429,39 +404,6 @@ static void __wusbhc_dev_disconnect(struct wusbhc *wusbhc,
429} 404}
430 405
431/* 406/*
432 * Authenticate a device into the WUSB Cluster
433 *
434 * Called from the Root Hub code (rh.c:wusbhc_rh_port_reset()) when
435 * asking for a reset on a port that is not enabled (ie: first connect
436 * on the port).
437 *
438 * Performs the 4way handshake to allow the device to comunicate w/ the
439 * WUSB Cluster securely; once done, issue a request to the device for
440 * it to change to address 0.
441 *
442 * This mimics the reset step of Wired USB that once resetting a
443 * device, leaves the port in enabled state and the dev with the
444 * default address (0).
445 *
446 * WUSB1.0[7.1.2]
447 *
448 * @port_idx: port where the change happened--This is the index into
449 * the wusbhc port array, not the USB port number.
450 */
451int wusbhc_devconnect_auth(struct wusbhc *wusbhc, u8 port_idx)
452{
453 struct device *dev = wusbhc->dev;
454 struct wusb_port *port = wusb_port_by_idx(wusbhc, port_idx);
455
456 d_fnstart(3, dev, "(%p, %u)\n", wusbhc, port_idx);
457 port->status &= ~USB_PORT_STAT_RESET;
458 port->status |= USB_PORT_STAT_ENABLE;
459 port->change |= USB_PORT_STAT_C_RESET | USB_PORT_STAT_C_ENABLE;
460 d_fnend(3, dev, "(%p, %u) = 0\n", wusbhc, port_idx);
461 return 0;
462}
463
464/*
465 * Refresh the list of keep alives to emit in the MMC 407 * Refresh the list of keep alives to emit in the MMC
466 * 408 *
467 * Some devices don't respond to keep alives unless they've been 409 * Some devices don't respond to keep alives unless they've been
@@ -528,21 +470,15 @@ static void __wusbhc_keep_alive(struct wusbhc *wusbhc)
528 */ 470 */
529static void wusbhc_keep_alive_run(struct work_struct *ws) 471static void wusbhc_keep_alive_run(struct work_struct *ws)
530{ 472{
531 struct delayed_work *dw = 473 struct delayed_work *dw = container_of(ws, struct delayed_work, work);
532 container_of(ws, struct delayed_work, work); 474 struct wusbhc *wusbhc = container_of(dw, struct wusbhc, keep_alive_timer);
533 struct wusbhc *wusbhc = 475
534 container_of(dw, struct wusbhc, keep_alive_timer); 476 mutex_lock(&wusbhc->mutex);
535 477 __wusbhc_keep_alive(wusbhc);
536 d_fnstart(5, wusbhc->dev, "(wusbhc %p)\n", wusbhc); 478 mutex_unlock(&wusbhc->mutex);
537 if (wusbhc->active) { 479
538 mutex_lock(&wusbhc->mutex); 480 queue_delayed_work(wusbd, &wusbhc->keep_alive_timer,
539 __wusbhc_keep_alive(wusbhc); 481 msecs_to_jiffies(wusbhc->trust_timeout / 2));
540 mutex_unlock(&wusbhc->mutex);
541 queue_delayed_work(wusbd, &wusbhc->keep_alive_timer,
542 (wusbhc->trust_timeout * CONFIG_HZ)/1000/2);
543 }
544 d_fnend(5, wusbhc->dev, "(wusbhc %p) = void\n", wusbhc);
545 return;
546} 482}
547 483
548/* 484/*
@@ -585,10 +521,6 @@ static struct wusb_dev *wusbhc_find_dev_by_addr(struct wusbhc *wusbhc, u8 addr)
585 */ 521 */
586static void wusbhc_handle_dn_alive(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev) 522static void wusbhc_handle_dn_alive(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
587{ 523{
588 struct device *dev = wusbhc->dev;
589
590 d_printf(2, dev, "DN ALIVE: device 0x%02x pong\n", wusb_dev->addr);
591
592 mutex_lock(&wusbhc->mutex); 524 mutex_lock(&wusbhc->mutex);
593 wusb_dev->entry_ts = jiffies; 525 wusb_dev->entry_ts = jiffies;
594 __wusbhc_keep_alive(wusbhc); 526 __wusbhc_keep_alive(wusbhc);
@@ -621,11 +553,10 @@ static void wusbhc_handle_dn_connect(struct wusbhc *wusbhc,
621 "no-beacon" 553 "no-beacon"
622 }; 554 };
623 555
624 d_fnstart(3, dev, "(%p, %p, %zu)\n", wusbhc, dn_hdr, size);
625 if (size < sizeof(*dnc)) { 556 if (size < sizeof(*dnc)) {
626 dev_err(dev, "DN CONNECT: short notification (%zu < %zu)\n", 557 dev_err(dev, "DN CONNECT: short notification (%zu < %zu)\n",
627 size, sizeof(*dnc)); 558 size, sizeof(*dnc));
628 goto out; 559 return;
629 } 560 }
630 561
631 dnc = container_of(dn_hdr, struct wusb_dn_connect, hdr); 562 dnc = container_of(dn_hdr, struct wusb_dn_connect, hdr);
@@ -637,10 +568,6 @@ static void wusbhc_handle_dn_connect(struct wusbhc *wusbhc,
637 wusb_dn_connect_new_connection(dnc) ? "connect" : "reconnect"); 568 wusb_dn_connect_new_connection(dnc) ? "connect" : "reconnect");
638 /* ACK the connect */ 569 /* ACK the connect */
639 wusbhc_devconnect_ack(wusbhc, dnc, pr_cdid); 570 wusbhc_devconnect_ack(wusbhc, dnc, pr_cdid);
640out:
641 d_fnend(3, dev, "(%p, %p, %zu) = void\n",
642 wusbhc, dn_hdr, size);
643 return;
644} 571}
645 572
646/* 573/*
@@ -662,60 +589,6 @@ static void wusbhc_handle_dn_disconnect(struct wusbhc *wusbhc, struct wusb_dev *
662} 589}
663 590
664/* 591/*
665 * Reset a WUSB device on a HWA
666 *
667 * @wusbhc
668 * @port_idx Index of the port where the device is
669 *
670 * In Wireless USB, a reset is more or less equivalent to a full
671 * disconnect; so we just do a full disconnect and send the device a
672 * Device Reset IE (WUSB1.0[7.5.11]) giving it a few millisecs (6 MMCs).
673 *
674 * @wusbhc should be refcounted and unlocked
675 */
676int wusbhc_dev_reset(struct wusbhc *wusbhc, u8 port_idx)
677{
678 int result;
679 struct device *dev = wusbhc->dev;
680 struct wusb_dev *wusb_dev;
681 struct wuie_reset *ie;
682
683 d_fnstart(3, dev, "(%p, %u)\n", wusbhc, port_idx);
684 mutex_lock(&wusbhc->mutex);
685 result = 0;
686 wusb_dev = wusb_port_by_idx(wusbhc, port_idx)->wusb_dev;
687 if (wusb_dev == NULL) {
688 /* reset no device? ignore */
689 dev_dbg(dev, "RESET: no device at port %u, ignoring\n",
690 port_idx);
691 goto error_unlock;
692 }
693 result = -ENOMEM;
694 ie = kzalloc(sizeof(*ie), GFP_KERNEL);
695 if (ie == NULL)
696 goto error_unlock;
697 ie->hdr.bLength = sizeof(ie->hdr) + sizeof(ie->CDID);
698 ie->hdr.bIEIdentifier = WUIE_ID_RESET_DEVICE;
699 ie->CDID = wusb_dev->cdid;
700 result = wusbhc_mmcie_set(wusbhc, 0xff, 6, &ie->hdr);
701 if (result < 0) {
702 dev_err(dev, "RESET: cant's set MMC: %d\n", result);
703 goto error_kfree;
704 }
705 __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, port_idx));
706
707 /* 120ms, hopefully 6 MMCs (FIXME) */
708 msleep(120);
709 wusbhc_mmcie_rm(wusbhc, &ie->hdr);
710error_kfree:
711 kfree(ie);
712error_unlock:
713 mutex_unlock(&wusbhc->mutex);
714 d_fnend(3, dev, "(%p, %u) = %d\n", wusbhc, port_idx, result);
715 return result;
716}
717
718/*
719 * Handle a Device Notification coming a host 592 * Handle a Device Notification coming a host
720 * 593 *
721 * The Device Notification comes from a host (HWA, DWA or WHCI) 594 * The Device Notification comes from a host (HWA, DWA or WHCI)
@@ -735,19 +608,17 @@ void wusbhc_handle_dn(struct wusbhc *wusbhc, u8 srcaddr,
735 struct device *dev = wusbhc->dev; 608 struct device *dev = wusbhc->dev;
736 struct wusb_dev *wusb_dev; 609 struct wusb_dev *wusb_dev;
737 610
738 d_fnstart(3, dev, "(%p, %p)\n", wusbhc, dn_hdr);
739
740 if (size < sizeof(struct wusb_dn_hdr)) { 611 if (size < sizeof(struct wusb_dn_hdr)) {
741 dev_err(dev, "DN data shorter than DN header (%d < %d)\n", 612 dev_err(dev, "DN data shorter than DN header (%d < %d)\n",
742 (int)size, (int)sizeof(struct wusb_dn_hdr)); 613 (int)size, (int)sizeof(struct wusb_dn_hdr));
743 goto out; 614 return;
744 } 615 }
745 616
746 wusb_dev = wusbhc_find_dev_by_addr(wusbhc, srcaddr); 617 wusb_dev = wusbhc_find_dev_by_addr(wusbhc, srcaddr);
747 if (wusb_dev == NULL && dn_hdr->bType != WUSB_DN_CONNECT) { 618 if (wusb_dev == NULL && dn_hdr->bType != WUSB_DN_CONNECT) {
748 dev_dbg(dev, "ignoring DN %d from unconnected device %02x\n", 619 dev_dbg(dev, "ignoring DN %d from unconnected device %02x\n",
749 dn_hdr->bType, srcaddr); 620 dn_hdr->bType, srcaddr);
750 goto out; 621 return;
751 } 622 }
752 623
753 switch (dn_hdr->bType) { 624 switch (dn_hdr->bType) {
@@ -772,9 +643,6 @@ void wusbhc_handle_dn(struct wusbhc *wusbhc, u8 srcaddr,
772 dev_warn(dev, "unknown DN %u (%d octets) from %u\n", 643 dev_warn(dev, "unknown DN %u (%d octets) from %u\n",
773 dn_hdr->bType, (int)size, srcaddr); 644 dn_hdr->bType, (int)size, srcaddr);
774 } 645 }
775out:
776 d_fnend(3, dev, "(%p, %p) = void\n", wusbhc, dn_hdr);
777 return;
778} 646}
779EXPORT_SYMBOL_GPL(wusbhc_handle_dn); 647EXPORT_SYMBOL_GPL(wusbhc_handle_dn);
780 648
@@ -804,59 +672,30 @@ void __wusbhc_dev_disable(struct wusbhc *wusbhc, u8 port_idx)
804 struct wusb_dev *wusb_dev; 672 struct wusb_dev *wusb_dev;
805 struct wuie_disconnect *ie; 673 struct wuie_disconnect *ie;
806 674
807 d_fnstart(3, dev, "(%p, %u)\n", wusbhc, port_idx);
808 result = 0;
809 wusb_dev = wusb_port_by_idx(wusbhc, port_idx)->wusb_dev; 675 wusb_dev = wusb_port_by_idx(wusbhc, port_idx)->wusb_dev;
810 if (wusb_dev == NULL) { 676 if (wusb_dev == NULL) {
811 /* reset no device? ignore */ 677 /* reset no device? ignore */
812 dev_dbg(dev, "DISCONNECT: no device at port %u, ignoring\n", 678 dev_dbg(dev, "DISCONNECT: no device at port %u, ignoring\n",
813 port_idx); 679 port_idx);
814 goto error; 680 return;
815 } 681 }
816 __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, port_idx)); 682 __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, port_idx));
817 683
818 result = -ENOMEM;
819 ie = kzalloc(sizeof(*ie), GFP_KERNEL); 684 ie = kzalloc(sizeof(*ie), GFP_KERNEL);
820 if (ie == NULL) 685 if (ie == NULL)
821 goto error; 686 return;
822 ie->hdr.bLength = sizeof(*ie); 687 ie->hdr.bLength = sizeof(*ie);
823 ie->hdr.bIEIdentifier = WUIE_ID_DEVICE_DISCONNECT; 688 ie->hdr.bIEIdentifier = WUIE_ID_DEVICE_DISCONNECT;
824 ie->bDeviceAddress = wusb_dev->addr; 689 ie->bDeviceAddress = wusb_dev->addr;
825 result = wusbhc_mmcie_set(wusbhc, 0, 0, &ie->hdr); 690 result = wusbhc_mmcie_set(wusbhc, 0, 0, &ie->hdr);
826 if (result < 0) { 691 if (result < 0)
827 dev_err(dev, "DISCONNECT: can't set MMC: %d\n", result); 692 dev_err(dev, "DISCONNECT: can't set MMC: %d\n", result);
828 goto error_kfree; 693 else {
694 /* At least 6 MMCs, assuming at least 1 MMC per zone. */
695 msleep(7*4);
696 wusbhc_mmcie_rm(wusbhc, &ie->hdr);
829 } 697 }
830
831 /* 120ms, hopefully 6 MMCs */
832 msleep(100);
833 wusbhc_mmcie_rm(wusbhc, &ie->hdr);
834error_kfree:
835 kfree(ie); 698 kfree(ie);
836error:
837 d_fnend(3, dev, "(%p, %u) = %d\n", wusbhc, port_idx, result);
838 return;
839}
840
841static void wusb_cap_descr_printf(const unsigned level, struct device *dev,
842 const struct usb_wireless_cap_descriptor *wcd)
843{
844 d_printf(level, dev,
845 "WUSB Capability Descriptor\n"
846 " bDevCapabilityType 0x%02x\n"
847 " bmAttributes 0x%02x\n"
848 " wPhyRates 0x%04x\n"
849 " bmTFITXPowerInfo 0x%02x\n"
850 " bmFFITXPowerInfo 0x%02x\n"
851 " bmBandGroup 0x%04x\n"
852 " bReserved 0x%02x\n",
853 wcd->bDevCapabilityType,
854 wcd->bmAttributes,
855 le16_to_cpu(wcd->wPHYRates),
856 wcd->bmTFITXPowerInfo,
857 wcd->bmFFITXPowerInfo,
858 wcd->bmBandGroup,
859 wcd->bReserved);
860} 699}
861 700
862/* 701/*
@@ -899,8 +738,6 @@ static int wusb_dev_bos_grok(struct usb_device *usb_dev,
899 } 738 }
900 cap_size = cap_hdr->bLength; 739 cap_size = cap_hdr->bLength;
901 cap_type = cap_hdr->bDevCapabilityType; 740 cap_type = cap_hdr->bDevCapabilityType;
902 d_printf(4, dev, "BOS Capability: 0x%02x (%zu bytes)\n",
903 cap_type, cap_size);
904 if (cap_size == 0) 741 if (cap_size == 0)
905 break; 742 break;
906 if (cap_size > top - itr) { 743 if (cap_size > top - itr) {
@@ -912,7 +749,6 @@ static int wusb_dev_bos_grok(struct usb_device *usb_dev,
912 result = -EBADF; 749 result = -EBADF;
913 goto error_bad_cap; 750 goto error_bad_cap;
914 } 751 }
915 d_dump(3, dev, itr, cap_size);
916 switch (cap_type) { 752 switch (cap_type) {
917 case USB_CAP_TYPE_WIRELESS_USB: 753 case USB_CAP_TYPE_WIRELESS_USB:
918 if (cap_size != sizeof(*wusb_dev->wusb_cap_descr)) 754 if (cap_size != sizeof(*wusb_dev->wusb_cap_descr))
@@ -920,10 +756,8 @@ static int wusb_dev_bos_grok(struct usb_device *usb_dev,
920 "descriptor is %zu bytes vs %zu " 756 "descriptor is %zu bytes vs %zu "
921 "needed\n", cap_size, 757 "needed\n", cap_size,
922 sizeof(*wusb_dev->wusb_cap_descr)); 758 sizeof(*wusb_dev->wusb_cap_descr));
923 else { 759 else
924 wusb_dev->wusb_cap_descr = itr; 760 wusb_dev->wusb_cap_descr = itr;
925 wusb_cap_descr_printf(3, dev, itr);
926 }
927 break; 761 break;
928 default: 762 default:
929 dev_err(dev, "BUG? Unknown BOS capability 0x%02x " 763 dev_err(dev, "BUG? Unknown BOS capability 0x%02x "
@@ -988,9 +822,7 @@ static int wusb_dev_bos_add(struct usb_device *usb_dev,
988 "%zu bytes): %zd\n", desc_size, result); 822 "%zu bytes): %zd\n", desc_size, result);
989 goto error_get_descriptor; 823 goto error_get_descriptor;
990 } 824 }
991 d_printf(2, dev, "Got BOS descriptor %zd bytes, %u capabilities\n", 825
992 result, bos->bNumDeviceCaps);
993 d_dump(2, dev, bos, result);
994 result = wusb_dev_bos_grok(usb_dev, wusb_dev, bos, result); 826 result = wusb_dev_bos_grok(usb_dev, wusb_dev, bos, result);
995 if (result < 0) 827 if (result < 0)
996 goto error_bad_bos; 828 goto error_bad_bos;
@@ -1056,8 +888,6 @@ static void wusb_dev_add_ncb(struct usb_device *usb_dev)
1056 if (usb_dev->wusb == 0 || usb_dev->devnum == 1) 888 if (usb_dev->wusb == 0 || usb_dev->devnum == 1)
1057 return; /* skip non wusb and wusb RHs */ 889 return; /* skip non wusb and wusb RHs */
1058 890
1059 d_fnstart(3, dev, "(usb_dev %p)\n", usb_dev);
1060
1061 wusbhc = wusbhc_get_by_usb_dev(usb_dev); 891 wusbhc = wusbhc_get_by_usb_dev(usb_dev);
1062 if (wusbhc == NULL) 892 if (wusbhc == NULL)
1063 goto error_nodev; 893 goto error_nodev;
@@ -1087,7 +917,6 @@ out:
1087 wusb_dev_put(wusb_dev); 917 wusb_dev_put(wusb_dev);
1088 wusbhc_put(wusbhc); 918 wusbhc_put(wusbhc);
1089error_nodev: 919error_nodev:
1090 d_fnend(3, dev, "(usb_dev %p) = void\n", usb_dev);
1091 return; 920 return;
1092 921
1093 wusb_dev_sysfs_rm(wusb_dev); 922 wusb_dev_sysfs_rm(wusb_dev);
@@ -1174,11 +1003,10 @@ EXPORT_SYMBOL_GPL(__wusb_dev_get_by_usb_dev);
1174 1003
1175void wusb_dev_destroy(struct kref *_wusb_dev) 1004void wusb_dev_destroy(struct kref *_wusb_dev)
1176{ 1005{
1177 struct wusb_dev *wusb_dev 1006 struct wusb_dev *wusb_dev = container_of(_wusb_dev, struct wusb_dev, refcnt);
1178 = container_of(_wusb_dev, struct wusb_dev, refcnt); 1007
1179 list_del_init(&wusb_dev->cack_node); 1008 list_del_init(&wusb_dev->cack_node);
1180 wusb_dev_free(wusb_dev); 1009 wusb_dev_free(wusb_dev);
1181 d_fnend(1, NULL, "%s (wusb_dev %p) = void\n", __func__, wusb_dev);
1182} 1010}
1183EXPORT_SYMBOL_GPL(wusb_dev_destroy); 1011EXPORT_SYMBOL_GPL(wusb_dev_destroy);
1184 1012
@@ -1190,8 +1018,6 @@ EXPORT_SYMBOL_GPL(wusb_dev_destroy);
1190 */ 1018 */
1191int wusbhc_devconnect_create(struct wusbhc *wusbhc) 1019int wusbhc_devconnect_create(struct wusbhc *wusbhc)
1192{ 1020{
1193 d_fnstart(3, wusbhc->dev, "(wusbhc %p)\n", wusbhc);
1194
1195 wusbhc->keep_alive_ie.hdr.bIEIdentifier = WUIE_ID_KEEP_ALIVE; 1021 wusbhc->keep_alive_ie.hdr.bIEIdentifier = WUIE_ID_KEEP_ALIVE;
1196 wusbhc->keep_alive_ie.hdr.bLength = sizeof(wusbhc->keep_alive_ie.hdr); 1022 wusbhc->keep_alive_ie.hdr.bLength = sizeof(wusbhc->keep_alive_ie.hdr);
1197 INIT_DELAYED_WORK(&wusbhc->keep_alive_timer, wusbhc_keep_alive_run); 1023 INIT_DELAYED_WORK(&wusbhc->keep_alive_timer, wusbhc_keep_alive_run);
@@ -1200,7 +1026,6 @@ int wusbhc_devconnect_create(struct wusbhc *wusbhc)
1200 wusbhc->cack_ie.hdr.bLength = sizeof(wusbhc->cack_ie.hdr); 1026 wusbhc->cack_ie.hdr.bLength = sizeof(wusbhc->cack_ie.hdr);
1201 INIT_LIST_HEAD(&wusbhc->cack_list); 1027 INIT_LIST_HEAD(&wusbhc->cack_list);
1202 1028
1203 d_fnend(3, wusbhc->dev, "(wusbhc %p) = void\n", wusbhc);
1204 return 0; 1029 return 0;
1205} 1030}
1206 1031
@@ -1209,8 +1034,7 @@ int wusbhc_devconnect_create(struct wusbhc *wusbhc)
1209 */ 1034 */
1210void wusbhc_devconnect_destroy(struct wusbhc *wusbhc) 1035void wusbhc_devconnect_destroy(struct wusbhc *wusbhc)
1211{ 1036{
1212 d_fnstart(3, wusbhc->dev, "(wusbhc %p)\n", wusbhc); 1037 /* no op */
1213 d_fnend(3, wusbhc->dev, "(wusbhc %p) = void\n", wusbhc);
1214} 1038}
1215 1039
1216/* 1040/*
@@ -1222,8 +1046,7 @@ void wusbhc_devconnect_destroy(struct wusbhc *wusbhc)
1222 * FIXME: This also enables the keep alives but this is not necessary 1046 * FIXME: This also enables the keep alives but this is not necessary
1223 * until there are connected and authenticated devices. 1047 * until there are connected and authenticated devices.
1224 */ 1048 */
1225int wusbhc_devconnect_start(struct wusbhc *wusbhc, 1049int wusbhc_devconnect_start(struct wusbhc *wusbhc)
1226 const struct wusb_ckhdid *chid)
1227{ 1050{
1228 struct device *dev = wusbhc->dev; 1051 struct device *dev = wusbhc->dev;
1229 struct wuie_host_info *hi; 1052 struct wuie_host_info *hi;
@@ -1236,7 +1059,7 @@ int wusbhc_devconnect_start(struct wusbhc *wusbhc,
1236 hi->hdr.bLength = sizeof(*hi); 1059 hi->hdr.bLength = sizeof(*hi);
1237 hi->hdr.bIEIdentifier = WUIE_ID_HOST_INFO; 1060 hi->hdr.bIEIdentifier = WUIE_ID_HOST_INFO;
1238 hi->attributes = cpu_to_le16((wusbhc->rsv->stream << 3) | WUIE_HI_CAP_ALL); 1061 hi->attributes = cpu_to_le16((wusbhc->rsv->stream << 3) | WUIE_HI_CAP_ALL);
1239 hi->CHID = *chid; 1062 hi->CHID = wusbhc->chid;
1240 result = wusbhc_mmcie_set(wusbhc, 0, 0, &hi->hdr); 1063 result = wusbhc_mmcie_set(wusbhc, 0, 0, &hi->hdr);
1241 if (result < 0) { 1064 if (result < 0) {
1242 dev_err(dev, "Cannot add Host Info MMCIE: %d\n", result); 1065 dev_err(dev, "Cannot add Host Info MMCIE: %d\n", result);
diff --git a/drivers/usb/wusbcore/mmc.c b/drivers/usb/wusbcore/mmc.c
index cfa77a01cebd..3b52161e6e9c 100644
--- a/drivers/usb/wusbcore/mmc.c
+++ b/drivers/usb/wusbcore/mmc.c
@@ -159,15 +159,35 @@ found:
159} 159}
160EXPORT_SYMBOL_GPL(wusbhc_mmcie_rm); 160EXPORT_SYMBOL_GPL(wusbhc_mmcie_rm);
161 161
162static int wusbhc_mmc_start(struct wusbhc *wusbhc)
163{
164 int ret;
165
166 mutex_lock(&wusbhc->mutex);
167 ret = wusbhc->start(wusbhc);
168 if (ret >= 0)
169 wusbhc->active = 1;
170 mutex_unlock(&wusbhc->mutex);
171
172 return ret;
173}
174
175static void wusbhc_mmc_stop(struct wusbhc *wusbhc)
176{
177 mutex_lock(&wusbhc->mutex);
178 wusbhc->active = 0;
179 wusbhc->stop(wusbhc, WUSB_CHANNEL_STOP_DELAY_MS);
180 mutex_unlock(&wusbhc->mutex);
181}
182
162/* 183/*
163 * wusbhc_start - start transmitting MMCs and accepting connections 184 * wusbhc_start - start transmitting MMCs and accepting connections
164 * @wusbhc: the HC to start 185 * @wusbhc: the HC to start
165 * @chid: the CHID to use for this host
166 * 186 *
167 * Establishes a cluster reservation, enables device connections, and 187 * Establishes a cluster reservation, enables device connections, and
168 * starts MMCs with appropriate DNTS parameters. 188 * starts MMCs with appropriate DNTS parameters.
169 */ 189 */
170int wusbhc_start(struct wusbhc *wusbhc, const struct wusb_ckhdid *chid) 190int wusbhc_start(struct wusbhc *wusbhc)
171{ 191{
172 int result; 192 int result;
173 struct device *dev = wusbhc->dev; 193 struct device *dev = wusbhc->dev;
@@ -181,7 +201,7 @@ int wusbhc_start(struct wusbhc *wusbhc, const struct wusb_ckhdid *chid)
181 goto error_rsv_establish; 201 goto error_rsv_establish;
182 } 202 }
183 203
184 result = wusbhc_devconnect_start(wusbhc, chid); 204 result = wusbhc_devconnect_start(wusbhc);
185 if (result < 0) { 205 if (result < 0) {
186 dev_err(dev, "error enabling device connections: %d\n", result); 206 dev_err(dev, "error enabling device connections: %d\n", result);
187 goto error_devconnect_start; 207 goto error_devconnect_start;
@@ -199,12 +219,12 @@ int wusbhc_start(struct wusbhc *wusbhc, const struct wusb_ckhdid *chid)
199 dev_err(dev, "Cannot set DNTS parameters: %d\n", result); 219 dev_err(dev, "Cannot set DNTS parameters: %d\n", result);
200 goto error_set_num_dnts; 220 goto error_set_num_dnts;
201 } 221 }
202 result = wusbhc->start(wusbhc); 222 result = wusbhc_mmc_start(wusbhc);
203 if (result < 0) { 223 if (result < 0) {
204 dev_err(dev, "error starting wusbch: %d\n", result); 224 dev_err(dev, "error starting wusbch: %d\n", result);
205 goto error_wusbhc_start; 225 goto error_wusbhc_start;
206 } 226 }
207 wusbhc->active = 1; 227
208 return 0; 228 return 0;
209 229
210error_wusbhc_start: 230error_wusbhc_start:
@@ -219,76 +239,17 @@ error_rsv_establish:
219} 239}
220 240
221/* 241/*
222 * Disconnect all from the WUSB Channel
223 *
224 * Send a Host Disconnect IE in the MMC, wait, don't send it any more
225 */
226static int __wusbhc_host_disconnect_ie(struct wusbhc *wusbhc)
227{
228 int result = -ENOMEM;
229 struct wuie_host_disconnect *host_disconnect_ie;
230 might_sleep();
231 host_disconnect_ie = kmalloc(sizeof(*host_disconnect_ie), GFP_KERNEL);
232 if (host_disconnect_ie == NULL)
233 goto error_alloc;
234 host_disconnect_ie->hdr.bLength = sizeof(*host_disconnect_ie);
235 host_disconnect_ie->hdr.bIEIdentifier = WUIE_ID_HOST_DISCONNECT;
236 result = wusbhc_mmcie_set(wusbhc, 0, 0, &host_disconnect_ie->hdr);
237 if (result < 0)
238 goto error_mmcie_set;
239
240 /* WUSB1.0[8.5.3.1 & 7.5.2] */
241 msleep(100);
242 wusbhc_mmcie_rm(wusbhc, &host_disconnect_ie->hdr);
243error_mmcie_set:
244 kfree(host_disconnect_ie);
245error_alloc:
246 return result;
247}
248
249/*
250 * wusbhc_stop - stop transmitting MMCs 242 * wusbhc_stop - stop transmitting MMCs
251 * @wusbhc: the HC to stop 243 * @wusbhc: the HC to stop
252 * 244 *
253 * Send a Host Disconnect IE, wait, remove all the MMCs (stop sending MMCs). 245 * Stops the WUSB channel and removes the cluster reservation.
254 *
255 * If we can't allocate a Host Stop IE, screw it, we don't notify the
256 * devices we are disconnecting...
257 */ 246 */
258void wusbhc_stop(struct wusbhc *wusbhc) 247void wusbhc_stop(struct wusbhc *wusbhc)
259{ 248{
260 if (wusbhc->active) { 249 wusbhc_mmc_stop(wusbhc);
261 wusbhc->active = 0; 250 wusbhc_sec_stop(wusbhc);
262 wusbhc->stop(wusbhc); 251 wusbhc_devconnect_stop(wusbhc);
263 wusbhc_sec_stop(wusbhc); 252 wusbhc_rsv_terminate(wusbhc);
264 __wusbhc_host_disconnect_ie(wusbhc);
265 wusbhc_devconnect_stop(wusbhc);
266 wusbhc_rsv_terminate(wusbhc);
267 }
268}
269EXPORT_SYMBOL_GPL(wusbhc_stop);
270
271/*
272 * Change the CHID in a WUSB Channel
273 *
274 * If it is just a new CHID, send a Host Disconnect IE and then change
275 * the CHID IE.
276 */
277static int __wusbhc_chid_change(struct wusbhc *wusbhc,
278 const struct wusb_ckhdid *chid)
279{
280 int result = -ENOSYS;
281 struct device *dev = wusbhc->dev;
282 dev_err(dev, "%s() not implemented yet\n", __func__);
283 return result;
284
285 BUG_ON(wusbhc->wuie_host_info == NULL);
286 __wusbhc_host_disconnect_ie(wusbhc);
287 wusbhc->wuie_host_info->CHID = *chid;
288 result = wusbhc_mmcie_set(wusbhc, 0, 0, &wusbhc->wuie_host_info->hdr);
289 if (result < 0)
290 dev_err(dev, "Can't update Host Info WUSB IE: %d\n", result);
291 return result;
292} 253}
293 254
294/* 255/*
@@ -306,16 +267,19 @@ int wusbhc_chid_set(struct wusbhc *wusbhc, const struct wusb_ckhdid *chid)
306 chid = NULL; 267 chid = NULL;
307 268
308 mutex_lock(&wusbhc->mutex); 269 mutex_lock(&wusbhc->mutex);
309 if (wusbhc->active) { 270 if (chid) {
310 if (chid) 271 if (wusbhc->active) {
311 result = __wusbhc_chid_change(wusbhc, chid); 272 mutex_unlock(&wusbhc->mutex);
312 else 273 return -EBUSY;
313 wusbhc_stop(wusbhc); 274 }
314 } else { 275 wusbhc->chid = *chid;
315 if (chid)
316 wusbhc_start(wusbhc, chid);
317 } 276 }
318 mutex_unlock(&wusbhc->mutex); 277 mutex_unlock(&wusbhc->mutex);
278
279 if (chid)
280 result = uwb_radio_start(&wusbhc->pal);
281 else
282 uwb_radio_stop(&wusbhc->pal);
319 return result; 283 return result;
320} 284}
321EXPORT_SYMBOL_GPL(wusbhc_chid_set); 285EXPORT_SYMBOL_GPL(wusbhc_chid_set);
diff --git a/drivers/usb/wusbcore/pal.c b/drivers/usb/wusbcore/pal.c
index 7cc51e9905cf..d0b172c5ecc7 100644
--- a/drivers/usb/wusbcore/pal.c
+++ b/drivers/usb/wusbcore/pal.c
@@ -18,6 +18,16 @@
18 */ 18 */
19#include "wusbhc.h" 19#include "wusbhc.h"
20 20
21static void wusbhc_channel_changed(struct uwb_pal *pal, int channel)
22{
23 struct wusbhc *wusbhc = container_of(pal, struct wusbhc, pal);
24
25 if (channel < 0)
26 wusbhc_stop(wusbhc);
27 else
28 wusbhc_start(wusbhc);
29}
30
21/** 31/**
22 * wusbhc_pal_register - register the WUSB HC as a UWB PAL 32 * wusbhc_pal_register - register the WUSB HC as a UWB PAL
23 * @wusbhc: the WUSB HC 33 * @wusbhc: the WUSB HC
@@ -28,8 +38,10 @@ int wusbhc_pal_register(struct wusbhc *wusbhc)
28 38
29 wusbhc->pal.name = "wusbhc"; 39 wusbhc->pal.name = "wusbhc";
30 wusbhc->pal.device = wusbhc->usb_hcd.self.controller; 40 wusbhc->pal.device = wusbhc->usb_hcd.self.controller;
41 wusbhc->pal.rc = wusbhc->uwb_rc;
42 wusbhc->pal.channel_changed = wusbhc_channel_changed;
31 43
32 return uwb_pal_register(wusbhc->uwb_rc, &wusbhc->pal); 44 return uwb_pal_register(&wusbhc->pal);
33} 45}
34 46
35/** 47/**
@@ -38,5 +50,5 @@ int wusbhc_pal_register(struct wusbhc *wusbhc)
38 */ 50 */
39void wusbhc_pal_unregister(struct wusbhc *wusbhc) 51void wusbhc_pal_unregister(struct wusbhc *wusbhc)
40{ 52{
41 uwb_pal_unregister(wusbhc->uwb_rc, &wusbhc->pal); 53 uwb_pal_unregister(&wusbhc->pal);
42} 54}
diff --git a/drivers/usb/wusbcore/reservation.c b/drivers/usb/wusbcore/reservation.c
index fc63e77ded2d..4ed97360c046 100644
--- a/drivers/usb/wusbcore/reservation.c
+++ b/drivers/usb/wusbcore/reservation.c
@@ -48,18 +48,19 @@ static void wusbhc_rsv_complete_cb(struct uwb_rsv *rsv)
48{ 48{
49 struct wusbhc *wusbhc = rsv->pal_priv; 49 struct wusbhc *wusbhc = rsv->pal_priv;
50 struct device *dev = wusbhc->dev; 50 struct device *dev = wusbhc->dev;
51 struct uwb_mas_bm mas;
51 char buf[72]; 52 char buf[72];
52 53
53 switch (rsv->state) { 54 switch (rsv->state) {
54 case UWB_RSV_STATE_O_ESTABLISHED: 55 case UWB_RSV_STATE_O_ESTABLISHED:
55 bitmap_scnprintf(buf, sizeof(buf), rsv->mas.bm, UWB_NUM_MAS); 56 uwb_rsv_get_usable_mas(rsv, &mas);
57 bitmap_scnprintf(buf, sizeof(buf), mas.bm, UWB_NUM_MAS);
56 dev_dbg(dev, "established reservation: %s\n", buf); 58 dev_dbg(dev, "established reservation: %s\n", buf);
57 wusbhc_bwa_set(wusbhc, rsv->stream, &rsv->mas); 59 wusbhc_bwa_set(wusbhc, rsv->stream, &mas);
58 break; 60 break;
59 case UWB_RSV_STATE_NONE: 61 case UWB_RSV_STATE_NONE:
60 dev_dbg(dev, "removed reservation\n"); 62 dev_dbg(dev, "removed reservation\n");
61 wusbhc_bwa_set(wusbhc, 0, NULL); 63 wusbhc_bwa_set(wusbhc, 0, NULL);
62 wusbhc->rsv = NULL;
63 break; 64 break;
64 default: 65 default:
65 dev_dbg(dev, "unexpected reservation state: %d\n", rsv->state); 66 dev_dbg(dev, "unexpected reservation state: %d\n", rsv->state);
@@ -86,13 +87,12 @@ int wusbhc_rsv_establish(struct wusbhc *wusbhc)
86 bcid.data[0] = wusbhc->cluster_id; 87 bcid.data[0] = wusbhc->cluster_id;
87 bcid.data[1] = 0; 88 bcid.data[1] = 0;
88 89
89 rsv->owner = &rc->uwb_dev;
90 rsv->target.type = UWB_RSV_TARGET_DEVADDR; 90 rsv->target.type = UWB_RSV_TARGET_DEVADDR;
91 rsv->target.devaddr = bcid; 91 rsv->target.devaddr = bcid;
92 rsv->type = UWB_DRP_TYPE_PRIVATE; 92 rsv->type = UWB_DRP_TYPE_PRIVATE;
93 rsv->max_mas = 256; 93 rsv->max_mas = 256; /* try to get as much as possible */
94 rsv->min_mas = 16; /* one MAS per zone? */ 94 rsv->min_mas = 15; /* one MAS per zone */
95 rsv->sparsity = 16; /* at least one MAS in each zone? */ 95 rsv->max_interval = 1; /* max latency is one zone */
96 rsv->is_multicast = true; 96 rsv->is_multicast = true;
97 97
98 ret = uwb_rsv_establish(rsv); 98 ret = uwb_rsv_establish(rsv);
@@ -105,11 +105,14 @@ int wusbhc_rsv_establish(struct wusbhc *wusbhc)
105 105
106 106
107/** 107/**
108 * wusbhc_rsv_terminate - terminate any cluster reservation 108 * wusbhc_rsv_terminate - terminate the cluster reservation
109 * @wusbhc: the WUSB host whose reservation is to be terminated 109 * @wusbhc: the WUSB host whose reservation is to be terminated
110 */ 110 */
111void wusbhc_rsv_terminate(struct wusbhc *wusbhc) 111void wusbhc_rsv_terminate(struct wusbhc *wusbhc)
112{ 112{
113 if (wusbhc->rsv) 113 if (wusbhc->rsv) {
114 uwb_rsv_terminate(wusbhc->rsv); 114 uwb_rsv_terminate(wusbhc->rsv);
115 uwb_rsv_destroy(wusbhc->rsv);
116 wusbhc->rsv = NULL;
117 }
115} 118}
diff --git a/drivers/usb/wusbcore/rh.c b/drivers/usb/wusbcore/rh.c
index 267a64325106..95c6fa3bf6b2 100644
--- a/drivers/usb/wusbcore/rh.c
+++ b/drivers/usb/wusbcore/rh.c
@@ -71,19 +71,20 @@
71 */ 71 */
72#include "wusbhc.h" 72#include "wusbhc.h"
73 73
74#define D_LOCAL 0
75#include <linux/uwb/debug.h>
76
77/* 74/*
78 * Reset a fake port 75 * Reset a fake port
79 * 76 *
80 * This can be called to reset a port from any other state or to reset 77 * Using a Reset Device IE is too heavyweight as it causes the device
81 * it when connecting. In Wireless USB they are different; when doing 78 * to enter the UnConnected state and leave the cluster, this can mean
82 * a new connect that involves going over the authentication. When 79 * that when the device reconnects it is connected to a different fake
83 * just reseting, its a different story. 80 * port.
81 *
82 * Instead, reset authenticated devices with a SetAddress(0), followed
83 * by a SetAddresss(AuthAddr).
84 * 84 *
85 * The Linux USB stack resets a port twice before it considers it 85 * For unauthenticated devices just pretend to reset but do nothing.
86 * enabled, so we have to detect and ignore that. 86 * If the device initialization continues to fail it will eventually
87 * time out after TrustTimeout and enter the UnConnected state.
87 * 88 *
88 * @wusbhc is assumed referenced and @wusbhc->mutex unlocked. 89 * @wusbhc is assumed referenced and @wusbhc->mutex unlocked.
89 * 90 *
@@ -97,20 +98,20 @@ static int wusbhc_rh_port_reset(struct wusbhc *wusbhc, u8 port_idx)
97{ 98{
98 int result = 0; 99 int result = 0;
99 struct wusb_port *port = wusb_port_by_idx(wusbhc, port_idx); 100 struct wusb_port *port = wusb_port_by_idx(wusbhc, port_idx);
101 struct wusb_dev *wusb_dev = port->wusb_dev;
100 102
101 d_fnstart(3, wusbhc->dev, "(wusbhc %p port_idx %u)\n", 103 port->status |= USB_PORT_STAT_RESET;
102 wusbhc, port_idx); 104 port->change |= USB_PORT_STAT_C_RESET;
103 if (port->reset_count == 0) { 105
104 wusbhc_devconnect_auth(wusbhc, port_idx); 106 if (wusb_dev->addr & WUSB_DEV_ADDR_UNAUTH)
105 port->reset_count++; 107 result = 0;
106 } else if (port->reset_count == 1)
107 /* see header */
108 d_printf(2, wusbhc->dev, "Ignoring second reset on port_idx "
109 "%u\n", port_idx);
110 else 108 else
111 result = wusbhc_dev_reset(wusbhc, port_idx); 109 result = wusb_dev_update_address(wusbhc, wusb_dev);
112 d_fnend(3, wusbhc->dev, "(wusbhc %p port_idx %u) = %d\n", 110
113 wusbhc, port_idx, result); 111 port->status &= ~USB_PORT_STAT_RESET;
112 port->status |= USB_PORT_STAT_ENABLE;
113 port->change |= USB_PORT_STAT_C_RESET | USB_PORT_STAT_C_ENABLE;
114
114 return result; 115 return result;
115} 116}
116 117
@@ -138,7 +139,6 @@ int wusbhc_rh_status_data(struct usb_hcd *usb_hcd, char *_buf)
138 size_t cnt, size; 139 size_t cnt, size;
139 unsigned long *buf = (unsigned long *) _buf; 140 unsigned long *buf = (unsigned long *) _buf;
140 141
141 d_fnstart(1, wusbhc->dev, "(wusbhc %p)\n", wusbhc);
142 /* WE DON'T LOCK, see comment */ 142 /* WE DON'T LOCK, see comment */
143 size = wusbhc->ports_max + 1 /* hub bit */; 143 size = wusbhc->ports_max + 1 /* hub bit */;
144 size = (size + 8 - 1) / 8; /* round to bytes */ 144 size = (size + 8 - 1) / 8; /* round to bytes */
@@ -147,8 +147,6 @@ int wusbhc_rh_status_data(struct usb_hcd *usb_hcd, char *_buf)
147 set_bit(cnt + 1, buf); 147 set_bit(cnt + 1, buf);
148 else 148 else
149 clear_bit(cnt + 1, buf); 149 clear_bit(cnt + 1, buf);
150 d_fnend(1, wusbhc->dev, "(wusbhc %p) %u, buffer:\n", wusbhc, (int)size);
151 d_dump(1, wusbhc->dev, _buf, size);
152 return size; 150 return size;
153} 151}
154EXPORT_SYMBOL_GPL(wusbhc_rh_status_data); 152EXPORT_SYMBOL_GPL(wusbhc_rh_status_data);
@@ -197,9 +195,7 @@ static int wusbhc_rh_get_hub_descr(struct wusbhc *wusbhc, u16 wValue,
197static int wusbhc_rh_clear_hub_feat(struct wusbhc *wusbhc, u16 feature) 195static int wusbhc_rh_clear_hub_feat(struct wusbhc *wusbhc, u16 feature)
198{ 196{
199 int result; 197 int result;
200 struct device *dev = wusbhc->dev;
201 198
202 d_fnstart(4, dev, "(%p, feature 0x%04u)\n", wusbhc, feature);
203 switch (feature) { 199 switch (feature) {
204 case C_HUB_LOCAL_POWER: 200 case C_HUB_LOCAL_POWER:
205 /* FIXME: maybe plug bit 0 to the power input status, 201 /* FIXME: maybe plug bit 0 to the power input status,
@@ -211,7 +207,6 @@ static int wusbhc_rh_clear_hub_feat(struct wusbhc *wusbhc, u16 feature)
211 default: 207 default:
212 result = -EPIPE; 208 result = -EPIPE;
213 } 209 }
214 d_fnend(4, dev, "(%p, feature 0x%04u), %d\n", wusbhc, feature, result);
215 return result; 210 return result;
216} 211}
217 212
@@ -238,14 +233,10 @@ static int wusbhc_rh_get_hub_status(struct wusbhc *wusbhc, u32 *buf,
238static int wusbhc_rh_set_port_feat(struct wusbhc *wusbhc, u16 feature, 233static int wusbhc_rh_set_port_feat(struct wusbhc *wusbhc, u16 feature,
239 u8 selector, u8 port_idx) 234 u8 selector, u8 port_idx)
240{ 235{
241 int result = -EINVAL;
242 struct device *dev = wusbhc->dev; 236 struct device *dev = wusbhc->dev;
243 237
244 d_fnstart(4, dev, "(feat 0x%04u, selector 0x%u, port_idx %d)\n",
245 feature, selector, port_idx);
246
247 if (port_idx > wusbhc->ports_max) 238 if (port_idx > wusbhc->ports_max)
248 goto error; 239 return -EINVAL;
249 240
250 switch (feature) { 241 switch (feature) {
251 /* According to USB2.0[11.24.2.13]p2, these features 242 /* According to USB2.0[11.24.2.13]p2, these features
@@ -255,35 +246,27 @@ static int wusbhc_rh_set_port_feat(struct wusbhc *wusbhc, u16 feature,
255 case USB_PORT_FEAT_C_SUSPEND: 246 case USB_PORT_FEAT_C_SUSPEND:
256 case USB_PORT_FEAT_C_CONNECTION: 247 case USB_PORT_FEAT_C_CONNECTION:
257 case USB_PORT_FEAT_C_RESET: 248 case USB_PORT_FEAT_C_RESET:
258 result = 0; 249 return 0;
259 break;
260
261 case USB_PORT_FEAT_POWER: 250 case USB_PORT_FEAT_POWER:
262 /* No such thing, but we fake it works */ 251 /* No such thing, but we fake it works */
263 mutex_lock(&wusbhc->mutex); 252 mutex_lock(&wusbhc->mutex);
264 wusb_port_by_idx(wusbhc, port_idx)->status |= USB_PORT_STAT_POWER; 253 wusb_port_by_idx(wusbhc, port_idx)->status |= USB_PORT_STAT_POWER;
265 mutex_unlock(&wusbhc->mutex); 254 mutex_unlock(&wusbhc->mutex);
266 result = 0; 255 return 0;
267 break;
268 case USB_PORT_FEAT_RESET: 256 case USB_PORT_FEAT_RESET:
269 result = wusbhc_rh_port_reset(wusbhc, port_idx); 257 return wusbhc_rh_port_reset(wusbhc, port_idx);
270 break;
271 case USB_PORT_FEAT_ENABLE: 258 case USB_PORT_FEAT_ENABLE:
272 case USB_PORT_FEAT_SUSPEND: 259 case USB_PORT_FEAT_SUSPEND:
273 dev_err(dev, "(port_idx %d) set feat %d/%d UNIMPLEMENTED\n", 260 dev_err(dev, "(port_idx %d) set feat %d/%d UNIMPLEMENTED\n",
274 port_idx, feature, selector); 261 port_idx, feature, selector);
275 result = -ENOSYS; 262 return -ENOSYS;
276 break;
277 default: 263 default:
278 dev_err(dev, "(port_idx %d) set feat %d/%d UNKNOWN\n", 264 dev_err(dev, "(port_idx %d) set feat %d/%d UNKNOWN\n",
279 port_idx, feature, selector); 265 port_idx, feature, selector);
280 result = -EPIPE; 266 return -EPIPE;
281 break;
282 } 267 }
283error: 268
284 d_fnend(4, dev, "(feat 0x%04u, selector 0x%u, port_idx %d) = %d\n", 269 return 0;
285 feature, selector, port_idx, result);
286 return result;
287} 270}
288 271
289/* 272/*
@@ -294,17 +277,13 @@ error:
294static int wusbhc_rh_clear_port_feat(struct wusbhc *wusbhc, u16 feature, 277static int wusbhc_rh_clear_port_feat(struct wusbhc *wusbhc, u16 feature,
295 u8 selector, u8 port_idx) 278 u8 selector, u8 port_idx)
296{ 279{
297 int result = -EINVAL; 280 int result = 0;
298 struct device *dev = wusbhc->dev; 281 struct device *dev = wusbhc->dev;
299 282
300 d_fnstart(4, dev, "(wusbhc %p feat 0x%04x selector %d port_idx %d)\n",
301 wusbhc, feature, selector, port_idx);
302
303 if (port_idx > wusbhc->ports_max) 283 if (port_idx > wusbhc->ports_max)
304 goto error; 284 return -EINVAL;
305 285
306 mutex_lock(&wusbhc->mutex); 286 mutex_lock(&wusbhc->mutex);
307 result = 0;
308 switch (feature) { 287 switch (feature) {
309 case USB_PORT_FEAT_POWER: /* fake port always on */ 288 case USB_PORT_FEAT_POWER: /* fake port always on */
310 /* According to USB2.0[11.24.2.7.1.4], no need to implement? */ 289 /* According to USB2.0[11.24.2.7.1.4], no need to implement? */
@@ -324,10 +303,8 @@ static int wusbhc_rh_clear_port_feat(struct wusbhc *wusbhc, u16 feature,
324 break; 303 break;
325 case USB_PORT_FEAT_SUSPEND: 304 case USB_PORT_FEAT_SUSPEND:
326 case USB_PORT_FEAT_C_SUSPEND: 305 case USB_PORT_FEAT_C_SUSPEND:
327 case 0xffff: /* ??? FIXME */
328 dev_err(dev, "(port_idx %d) Clear feat %d/%d UNIMPLEMENTED\n", 306 dev_err(dev, "(port_idx %d) Clear feat %d/%d UNIMPLEMENTED\n",
329 port_idx, feature, selector); 307 port_idx, feature, selector);
330 /* dump_stack(); */
331 result = -ENOSYS; 308 result = -ENOSYS;
332 break; 309 break;
333 default: 310 default:
@@ -337,9 +314,7 @@ static int wusbhc_rh_clear_port_feat(struct wusbhc *wusbhc, u16 feature,
337 break; 314 break;
338 } 315 }
339 mutex_unlock(&wusbhc->mutex); 316 mutex_unlock(&wusbhc->mutex);
340error: 317
341 d_fnend(4, dev, "(wusbhc %p feat 0x%04x selector %d port_idx %d) = "
342 "%d\n", wusbhc, feature, selector, port_idx, result);
343 return result; 318 return result;
344} 319}
345 320
@@ -351,22 +326,17 @@ error:
351static int wusbhc_rh_get_port_status(struct wusbhc *wusbhc, u16 port_idx, 326static int wusbhc_rh_get_port_status(struct wusbhc *wusbhc, u16 port_idx,
352 u32 *_buf, u16 wLength) 327 u32 *_buf, u16 wLength)
353{ 328{
354 int result = -EINVAL;
355 u16 *buf = (u16 *) _buf; 329 u16 *buf = (u16 *) _buf;
356 330
357 d_fnstart(1, wusbhc->dev, "(wusbhc %p port_idx %u wLength %u)\n",
358 wusbhc, port_idx, wLength);
359 if (port_idx > wusbhc->ports_max) 331 if (port_idx > wusbhc->ports_max)
360 goto error; 332 return -EINVAL;
333
361 mutex_lock(&wusbhc->mutex); 334 mutex_lock(&wusbhc->mutex);
362 buf[0] = cpu_to_le16(wusb_port_by_idx(wusbhc, port_idx)->status); 335 buf[0] = cpu_to_le16(wusb_port_by_idx(wusbhc, port_idx)->status);
363 buf[1] = cpu_to_le16(wusb_port_by_idx(wusbhc, port_idx)->change); 336 buf[1] = cpu_to_le16(wusb_port_by_idx(wusbhc, port_idx)->change);
364 result = 0;
365 mutex_unlock(&wusbhc->mutex); 337 mutex_unlock(&wusbhc->mutex);
366error: 338
367 d_fnend(1, wusbhc->dev, "(wusbhc %p) = %d, buffer:\n", wusbhc, result); 339 return 0;
368 d_dump(1, wusbhc->dev, _buf, wLength);
369 return result;
370} 340}
371 341
372/* 342/*
diff --git a/drivers/usb/wusbcore/security.c b/drivers/usb/wusbcore/security.c
index a101cad6a8d4..f4aa28eca70d 100644
--- a/drivers/usb/wusbcore/security.c
+++ b/drivers/usb/wusbcore/security.c
@@ -27,19 +27,6 @@
27#include <linux/random.h> 27#include <linux/random.h>
28#include "wusbhc.h" 28#include "wusbhc.h"
29 29
30/*
31 * DEBUG & SECURITY WARNING!!!!
32 *
33 * If you enable this past 1, the debug code will weaken the
34 * cryptographic safety of the system (on purpose, for debugging).
35 *
36 * Weaken means:
37 * we print secret keys and intermediate values all the way,
38 */
39#undef D_LOCAL
40#define D_LOCAL 2
41#include <linux/uwb/debug.h>
42
43static void wusbhc_set_gtk_callback(struct urb *urb); 30static void wusbhc_set_gtk_callback(struct urb *urb);
44static void wusbhc_gtk_rekey_done_work(struct work_struct *work); 31static void wusbhc_gtk_rekey_done_work(struct work_struct *work);
45 32
@@ -219,7 +206,6 @@ int wusb_dev_sec_add(struct wusbhc *wusbhc,
219 const void *itr, *top; 206 const void *itr, *top;
220 char buf[64]; 207 char buf[64];
221 208
222 d_fnstart(3, dev, "(usb_dev %p, wusb_dev %p)\n", usb_dev, wusb_dev);
223 result = usb_get_descriptor(usb_dev, USB_DT_SECURITY, 209 result = usb_get_descriptor(usb_dev, USB_DT_SECURITY,
224 0, &secd, sizeof(secd)); 210 0, &secd, sizeof(secd));
225 if (result < sizeof(secd)) { 211 if (result < sizeof(secd)) {
@@ -228,8 +214,6 @@ int wusb_dev_sec_add(struct wusbhc *wusbhc,
228 goto error_secd; 214 goto error_secd;
229 } 215 }
230 secd_size = le16_to_cpu(secd.wTotalLength); 216 secd_size = le16_to_cpu(secd.wTotalLength);
231 d_printf(5, dev, "got %d bytes of sec descriptor, total is %d\n",
232 result, secd_size);
233 secd_buf = kmalloc(secd_size, GFP_KERNEL); 217 secd_buf = kmalloc(secd_size, GFP_KERNEL);
234 if (secd_buf == NULL) { 218 if (secd_buf == NULL) {
235 dev_err(dev, "Can't allocate space for security descriptors\n"); 219 dev_err(dev, "Can't allocate space for security descriptors\n");
@@ -242,7 +226,6 @@ int wusb_dev_sec_add(struct wusbhc *wusbhc,
242 "not enough data: %d\n", result); 226 "not enough data: %d\n", result);
243 goto error_secd_all; 227 goto error_secd_all;
244 } 228 }
245 d_printf(5, dev, "got %d bytes of sec descriptors\n", result);
246 bytes = 0; 229 bytes = 0;
247 itr = secd_buf + sizeof(secd); 230 itr = secd_buf + sizeof(secd);
248 top = secd_buf + result; 231 top = secd_buf + result;
@@ -279,14 +262,12 @@ int wusb_dev_sec_add(struct wusbhc *wusbhc,
279 goto error_no_ccm1; 262 goto error_no_ccm1;
280 } 263 }
281 wusb_dev->ccm1_etd = *ccm1_etd; 264 wusb_dev->ccm1_etd = *ccm1_etd;
282 dev_info(dev, "supported encryption: %s; using %s (0x%02x/%02x)\n", 265 dev_dbg(dev, "supported encryption: %s; using %s (0x%02x/%02x)\n",
283 buf, wusb_et_name(ccm1_etd->bEncryptionType), 266 buf, wusb_et_name(ccm1_etd->bEncryptionType),
284 ccm1_etd->bEncryptionValue, ccm1_etd->bAuthKeyIndex); 267 ccm1_etd->bEncryptionValue, ccm1_etd->bAuthKeyIndex);
285 result = 0; 268 result = 0;
286 kfree(secd_buf); 269 kfree(secd_buf);
287out: 270out:
288 d_fnend(3, dev, "(usb_dev %p, wusb_dev %p) = %d\n",
289 usb_dev, wusb_dev, result);
290 return result; 271 return result;
291 272
292 273
@@ -303,32 +284,6 @@ void wusb_dev_sec_rm(struct wusb_dev *wusb_dev)
303 /* Nothing so far */ 284 /* Nothing so far */
304} 285}
305 286
306static void hs_printk(unsigned level, struct device *dev,
307 struct usb_handshake *hs)
308{
309 d_printf(level, dev,
310 " bMessageNumber: %u\n"
311 " bStatus: %u\n"
312 " tTKID: %02x %02x %02x\n"
313 " CDID: %02x %02x %02x %02x %02x %02x %02x %02x\n"
314 " %02x %02x %02x %02x %02x %02x %02x %02x\n"
315 " nonce: %02x %02x %02x %02x %02x %02x %02x %02x\n"
316 " %02x %02x %02x %02x %02x %02x %02x %02x\n"
317 " MIC: %02x %02x %02x %02x %02x %02x %02x %02x\n",
318 hs->bMessageNumber, hs->bStatus,
319 hs->tTKID[2], hs->tTKID[1], hs->tTKID[0],
320 hs->CDID[0], hs->CDID[1], hs->CDID[2], hs->CDID[3],
321 hs->CDID[4], hs->CDID[5], hs->CDID[6], hs->CDID[7],
322 hs->CDID[8], hs->CDID[9], hs->CDID[10], hs->CDID[11],
323 hs->CDID[12], hs->CDID[13], hs->CDID[14], hs->CDID[15],
324 hs->nonce[0], hs->nonce[1], hs->nonce[2], hs->nonce[3],
325 hs->nonce[4], hs->nonce[5], hs->nonce[6], hs->nonce[7],
326 hs->nonce[8], hs->nonce[9], hs->nonce[10], hs->nonce[11],
327 hs->nonce[12], hs->nonce[13], hs->nonce[14], hs->nonce[15],
328 hs->MIC[0], hs->MIC[1], hs->MIC[2], hs->MIC[3],
329 hs->MIC[4], hs->MIC[5], hs->MIC[6], hs->MIC[7]);
330}
331
332/** 287/**
333 * Update the address of an unauthenticated WUSB device 288 * Update the address of an unauthenticated WUSB device
334 * 289 *
@@ -338,8 +293,7 @@ static void hs_printk(unsigned level, struct device *dev,
338 * Before the device's address (as known by it) was usb_dev->devnum | 293 * Before the device's address (as known by it) was usb_dev->devnum |
339 * 0x80 (unauthenticated address). With this we update it to usb_dev->devnum. 294 * 0x80 (unauthenticated address). With this we update it to usb_dev->devnum.
340 */ 295 */
341static int wusb_dev_update_address(struct wusbhc *wusbhc, 296int wusb_dev_update_address(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
342 struct wusb_dev *wusb_dev)
343{ 297{
344 int result = -ENOMEM; 298 int result = -ENOMEM;
345 struct usb_device *usb_dev = wusb_dev->usb_dev; 299 struct usb_device *usb_dev = wusb_dev->usb_dev;
@@ -422,9 +376,6 @@ int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev,
422 get_random_bytes(&hs[0].nonce, sizeof(hs[0].nonce)); 376 get_random_bytes(&hs[0].nonce, sizeof(hs[0].nonce));
423 memset(hs[0].MIC, 0, sizeof(hs[0].MIC)); /* Per WUSB1.0[T7-22] */ 377 memset(hs[0].MIC, 0, sizeof(hs[0].MIC)); /* Per WUSB1.0[T7-22] */
424 378
425 d_printf(1, dev, "I: sending hs1:\n");
426 hs_printk(2, dev, &hs[0]);
427
428 result = usb_control_msg( 379 result = usb_control_msg(
429 usb_dev, usb_sndctrlpipe(usb_dev, 0), 380 usb_dev, usb_sndctrlpipe(usb_dev, 0),
430 USB_REQ_SET_HANDSHAKE, 381 USB_REQ_SET_HANDSHAKE,
@@ -445,8 +396,6 @@ int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev,
445 dev_err(dev, "Handshake2: request failed: %d\n", result); 396 dev_err(dev, "Handshake2: request failed: %d\n", result);
446 goto error_hs2; 397 goto error_hs2;
447 } 398 }
448 d_printf(1, dev, "got HS2:\n");
449 hs_printk(2, dev, &hs[1]);
450 399
451 result = -EINVAL; 400 result = -EINVAL;
452 if (hs[1].bMessageNumber != 2) { 401 if (hs[1].bMessageNumber != 2) {
@@ -487,10 +436,6 @@ int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev,
487 result); 436 result);
488 goto error_hs2; 437 goto error_hs2;
489 } 438 }
490 d_printf(2, dev, "KCK:\n");
491 d_dump(2, dev, keydvt_out.kck, sizeof(keydvt_out.kck));
492 d_printf(2, dev, "PTK:\n");
493 d_dump(2, dev, keydvt_out.ptk, sizeof(keydvt_out.ptk));
494 439
495 /* Compute MIC and verify it */ 440 /* Compute MIC and verify it */
496 result = wusb_oob_mic(mic, keydvt_out.kck, &ccm_n, &hs[1]); 441 result = wusb_oob_mic(mic, keydvt_out.kck, &ccm_n, &hs[1]);
@@ -500,8 +445,6 @@ int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev,
500 goto error_hs2; 445 goto error_hs2;
501 } 446 }
502 447
503 d_printf(2, dev, "MIC:\n");
504 d_dump(2, dev, mic, sizeof(mic));
505 if (memcmp(hs[1].MIC, mic, sizeof(hs[1].MIC))) { 448 if (memcmp(hs[1].MIC, mic, sizeof(hs[1].MIC))) {
506 dev_err(dev, "Handshake2 failed: MIC mismatch\n"); 449 dev_err(dev, "Handshake2 failed: MIC mismatch\n");
507 goto error_hs2; 450 goto error_hs2;
@@ -521,9 +464,6 @@ int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev,
521 goto error_hs2; 464 goto error_hs2;
522 } 465 }
523 466
524 d_printf(1, dev, "I: sending hs3:\n");
525 hs_printk(2, dev, &hs[2]);
526
527 result = usb_control_msg( 467 result = usb_control_msg(
528 usb_dev, usb_sndctrlpipe(usb_dev, 0), 468 usb_dev, usb_sndctrlpipe(usb_dev, 0),
529 USB_REQ_SET_HANDSHAKE, 469 USB_REQ_SET_HANDSHAKE,
@@ -534,14 +474,11 @@ int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev,
534 goto error_hs3; 474 goto error_hs3;
535 } 475 }
536 476
537 d_printf(1, dev, "I: turning on encryption on host for device\n");
538 d_dump(2, dev, keydvt_out.ptk, sizeof(keydvt_out.ptk));
539 result = wusbhc->set_ptk(wusbhc, wusb_dev->port_idx, tkid, 477 result = wusbhc->set_ptk(wusbhc, wusb_dev->port_idx, tkid,
540 keydvt_out.ptk, sizeof(keydvt_out.ptk)); 478 keydvt_out.ptk, sizeof(keydvt_out.ptk));
541 if (result < 0) 479 if (result < 0)
542 goto error_wusbhc_set_ptk; 480 goto error_wusbhc_set_ptk;
543 481
544 d_printf(1, dev, "I: setting a GTK\n");
545 result = wusb_dev_set_gtk(wusbhc, wusb_dev); 482 result = wusb_dev_set_gtk(wusbhc, wusb_dev);
546 if (result < 0) { 483 if (result < 0) {
547 dev_err(dev, "Set GTK for device: request failed: %d\n", 484 dev_err(dev, "Set GTK for device: request failed: %d\n",
@@ -551,13 +488,12 @@ int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev,
551 488
552 /* Update the device's address from unauth to auth */ 489 /* Update the device's address from unauth to auth */
553 if (usb_dev->authenticated == 0) { 490 if (usb_dev->authenticated == 0) {
554 d_printf(1, dev, "I: updating addres to auth from non-auth\n");
555 result = wusb_dev_update_address(wusbhc, wusb_dev); 491 result = wusb_dev_update_address(wusbhc, wusb_dev);
556 if (result < 0) 492 if (result < 0)
557 goto error_dev_update_address; 493 goto error_dev_update_address;
558 } 494 }
559 result = 0; 495 result = 0;
560 d_printf(1, dev, "I: 4way handshke done, device authenticated\n"); 496 dev_info(dev, "device authenticated\n");
561 497
562error_dev_update_address: 498error_dev_update_address:
563error_wusbhc_set_gtk: 499error_wusbhc_set_gtk:
@@ -570,10 +506,8 @@ error_hs1:
570 memset(&keydvt_in, 0, sizeof(keydvt_in)); 506 memset(&keydvt_in, 0, sizeof(keydvt_in));
571 memset(&ccm_n, 0, sizeof(ccm_n)); 507 memset(&ccm_n, 0, sizeof(ccm_n));
572 memset(mic, 0, sizeof(mic)); 508 memset(mic, 0, sizeof(mic));
573 if (result < 0) { 509 if (result < 0)
574 /* error path */
575 wusb_dev_set_encryption(usb_dev, 0); 510 wusb_dev_set_encryption(usb_dev, 0);
576 }
577error_dev_set_encryption: 511error_dev_set_encryption:
578 kfree(hs); 512 kfree(hs);
579error_kzalloc: 513error_kzalloc:
diff --git a/drivers/usb/wusbcore/wa-nep.c b/drivers/usb/wusbcore/wa-nep.c
index 3f542990c73f..17d2626038be 100644
--- a/drivers/usb/wusbcore/wa-nep.c
+++ b/drivers/usb/wusbcore/wa-nep.c
@@ -51,7 +51,7 @@
51 */ 51 */
52#include <linux/workqueue.h> 52#include <linux/workqueue.h>
53#include <linux/ctype.h> 53#include <linux/ctype.h>
54#include <linux/uwb/debug.h> 54
55#include "wa-hc.h" 55#include "wa-hc.h"
56#include "wusbhc.h" 56#include "wusbhc.h"
57 57
@@ -139,13 +139,10 @@ static void wa_notif_dispatch(struct work_struct *ws)
139 /* FIXME: unimplemented WA NOTIFs */ 139 /* FIXME: unimplemented WA NOTIFs */
140 /* fallthru */ 140 /* fallthru */
141 default: 141 default:
142 if (printk_ratelimit()) { 142 dev_err(dev, "HWA: unknown notification 0x%x, "
143 dev_err(dev, "HWA: unknown notification 0x%x, " 143 "%zu bytes; discarding\n",
144 "%zu bytes; discarding\n", 144 notif_hdr->bNotifyType,
145 notif_hdr->bNotifyType, 145 (size_t)notif_hdr->bLength);
146 (size_t)notif_hdr->bLength);
147 dump_bytes(dev, notif_hdr, 16);
148 }
149 break; 146 break;
150 } 147 }
151 } 148 }
@@ -160,12 +157,9 @@ out:
160 * discard the data, as this should not happen. 157 * discard the data, as this should not happen.
161 */ 158 */
162exhausted_buffer: 159exhausted_buffer:
163 if (!printk_ratelimit())
164 goto out;
165 dev_warn(dev, "HWA: device sent short notification, " 160 dev_warn(dev, "HWA: device sent short notification, "
166 "%d bytes missing; discarding %d bytes.\n", 161 "%d bytes missing; discarding %d bytes.\n",
167 missing, (int)size); 162 missing, (int)size);
168 dump_bytes(dev, itr, size);
169 goto out; 163 goto out;
170} 164}
171 165
diff --git a/drivers/usb/wusbcore/wa-rpipe.c b/drivers/usb/wusbcore/wa-rpipe.c
index f18e4aae66e9..7369655f69cd 100644
--- a/drivers/usb/wusbcore/wa-rpipe.c
+++ b/drivers/usb/wusbcore/wa-rpipe.c
@@ -60,13 +60,10 @@
60#include <linux/init.h> 60#include <linux/init.h>
61#include <asm/atomic.h> 61#include <asm/atomic.h>
62#include <linux/bitmap.h> 62#include <linux/bitmap.h>
63
63#include "wusbhc.h" 64#include "wusbhc.h"
64#include "wa-hc.h" 65#include "wa-hc.h"
65 66
66#define D_LOCAL 0
67#include <linux/uwb/debug.h>
68
69
70static int __rpipe_get_descr(struct wahc *wa, 67static int __rpipe_get_descr(struct wahc *wa,
71 struct usb_rpipe_descriptor *descr, u16 index) 68 struct usb_rpipe_descriptor *descr, u16 index)
72{ 69{
@@ -76,7 +73,6 @@ static int __rpipe_get_descr(struct wahc *wa,
76 /* Get the RPIPE descriptor -- we cannot use the usb_get_descriptor() 73 /* Get the RPIPE descriptor -- we cannot use the usb_get_descriptor()
77 * function because the arguments are different. 74 * function because the arguments are different.
78 */ 75 */
79 d_printf(1, dev, "rpipe %u: get descr\n", index);
80 result = usb_control_msg( 76 result = usb_control_msg(
81 wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0), 77 wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0),
82 USB_REQ_GET_DESCRIPTOR, 78 USB_REQ_GET_DESCRIPTOR,
@@ -115,7 +111,6 @@ static int __rpipe_set_descr(struct wahc *wa,
115 /* we cannot use the usb_get_descriptor() function because the 111 /* we cannot use the usb_get_descriptor() function because the
116 * arguments are different. 112 * arguments are different.
117 */ 113 */
118 d_printf(1, dev, "rpipe %u: set descr\n", index);
119 result = usb_control_msg( 114 result = usb_control_msg(
120 wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), 115 wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
121 USB_REQ_SET_DESCRIPTOR, 116 USB_REQ_SET_DESCRIPTOR,
@@ -174,13 +169,12 @@ void rpipe_destroy(struct kref *_rpipe)
174{ 169{
175 struct wa_rpipe *rpipe = container_of(_rpipe, struct wa_rpipe, refcnt); 170 struct wa_rpipe *rpipe = container_of(_rpipe, struct wa_rpipe, refcnt);
176 u8 index = le16_to_cpu(rpipe->descr.wRPipeIndex); 171 u8 index = le16_to_cpu(rpipe->descr.wRPipeIndex);
177 d_fnstart(1, NULL, "(rpipe %p %u)\n", rpipe, index); 172
178 if (rpipe->ep) 173 if (rpipe->ep)
179 rpipe->ep->hcpriv = NULL; 174 rpipe->ep->hcpriv = NULL;
180 rpipe_put_idx(rpipe->wa, index); 175 rpipe_put_idx(rpipe->wa, index);
181 wa_put(rpipe->wa); 176 wa_put(rpipe->wa);
182 kfree(rpipe); 177 kfree(rpipe);
183 d_fnend(1, NULL, "(rpipe %p %u)\n", rpipe, index);
184} 178}
185EXPORT_SYMBOL_GPL(rpipe_destroy); 179EXPORT_SYMBOL_GPL(rpipe_destroy);
186 180
@@ -202,7 +196,6 @@ static int rpipe_get_idle(struct wa_rpipe **prpipe, struct wahc *wa, u8 crs,
202 struct wa_rpipe *rpipe; 196 struct wa_rpipe *rpipe;
203 struct device *dev = &wa->usb_iface->dev; 197 struct device *dev = &wa->usb_iface->dev;
204 198
205 d_fnstart(3, dev, "(wa %p crs 0x%02x)\n", wa, crs);
206 rpipe = kzalloc(sizeof(*rpipe), gfp); 199 rpipe = kzalloc(sizeof(*rpipe), gfp);
207 if (rpipe == NULL) 200 if (rpipe == NULL)
208 return -ENOMEM; 201 return -ENOMEM;
@@ -223,14 +216,12 @@ static int rpipe_get_idle(struct wa_rpipe **prpipe, struct wahc *wa, u8 crs,
223 } 216 }
224 *prpipe = NULL; 217 *prpipe = NULL;
225 kfree(rpipe); 218 kfree(rpipe);
226 d_fnend(3, dev, "(wa %p crs 0x%02x) = -ENXIO\n", wa, crs);
227 return -ENXIO; 219 return -ENXIO;
228 220
229found: 221found:
230 set_bit(rpipe_idx, wa->rpipe_bm); 222 set_bit(rpipe_idx, wa->rpipe_bm);
231 rpipe->wa = wa_get(wa); 223 rpipe->wa = wa_get(wa);
232 *prpipe = rpipe; 224 *prpipe = rpipe;
233 d_fnstart(3, dev, "(wa %p crs 0x%02x) = 0\n", wa, crs);
234 return 0; 225 return 0;
235} 226}
236 227
@@ -239,7 +230,6 @@ static int __rpipe_reset(struct wahc *wa, unsigned index)
239 int result; 230 int result;
240 struct device *dev = &wa->usb_iface->dev; 231 struct device *dev = &wa->usb_iface->dev;
241 232
242 d_printf(1, dev, "rpipe %u: reset\n", index);
243 result = usb_control_msg( 233 result = usb_control_msg(
244 wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), 234 wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
245 USB_REQ_RPIPE_RESET, 235 USB_REQ_RPIPE_RESET,
@@ -276,7 +266,6 @@ static struct usb_wireless_ep_comp_descriptor *rpipe_epc_find(
276 struct usb_descriptor_header *hdr; 266 struct usb_descriptor_header *hdr;
277 struct usb_wireless_ep_comp_descriptor *epcd; 267 struct usb_wireless_ep_comp_descriptor *epcd;
278 268
279 d_fnstart(3, dev, "(ep %p)\n", ep);
280 if (ep->desc.bEndpointAddress == 0) { 269 if (ep->desc.bEndpointAddress == 0) {
281 epcd = &epc0; 270 epcd = &epc0;
282 goto out; 271 goto out;
@@ -310,7 +299,6 @@ static struct usb_wireless_ep_comp_descriptor *rpipe_epc_find(
310 itr_size -= hdr->bDescriptorType; 299 itr_size -= hdr->bDescriptorType;
311 } 300 }
312out: 301out:
313 d_fnend(3, dev, "(ep %p) = %p\n", ep, epcd);
314 return epcd; 302 return epcd;
315} 303}
316 304
@@ -329,8 +317,6 @@ static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa,
329 struct usb_wireless_ep_comp_descriptor *epcd; 317 struct usb_wireless_ep_comp_descriptor *epcd;
330 u8 unauth; 318 u8 unauth;
331 319
332 d_fnstart(3, dev, "(rpipe %p wa %p ep %p, urb %p)\n",
333 rpipe, wa, ep, urb);
334 epcd = rpipe_epc_find(dev, ep); 320 epcd = rpipe_epc_find(dev, ep);
335 if (epcd == NULL) { 321 if (epcd == NULL) {
336 dev_err(dev, "ep 0x%02x: can't find companion descriptor\n", 322 dev_err(dev, "ep 0x%02x: can't find companion descriptor\n",
@@ -350,10 +336,12 @@ static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa,
350 /* FIXME: use maximum speed as supported or recommended by device */ 336 /* FIXME: use maximum speed as supported or recommended by device */
351 rpipe->descr.bSpeed = usb_pipeendpoint(urb->pipe) == 0 ? 337 rpipe->descr.bSpeed = usb_pipeendpoint(urb->pipe) == 0 ?
352 UWB_PHY_RATE_53 : UWB_PHY_RATE_200; 338 UWB_PHY_RATE_53 : UWB_PHY_RATE_200;
353 d_printf(2, dev, "addr %u (0x%02x) rpipe #%u ep# %u speed %d\n", 339
354 urb->dev->devnum, urb->dev->devnum | unauth, 340 dev_dbg(dev, "addr %u (0x%02x) rpipe #%u ep# %u speed %d\n",
355 le16_to_cpu(rpipe->descr.wRPipeIndex), 341 urb->dev->devnum, urb->dev->devnum | unauth,
356 usb_pipeendpoint(urb->pipe), rpipe->descr.bSpeed); 342 le16_to_cpu(rpipe->descr.wRPipeIndex),
343 usb_pipeendpoint(urb->pipe), rpipe->descr.bSpeed);
344
357 /* see security.c:wusb_update_address() */ 345 /* see security.c:wusb_update_address() */
358 if (unlikely(urb->dev->devnum == 0x80)) 346 if (unlikely(urb->dev->devnum == 0x80))
359 rpipe->descr.bDeviceAddress = 0; 347 rpipe->descr.bDeviceAddress = 0;
@@ -384,8 +372,6 @@ static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa,
384 } 372 }
385 result = 0; 373 result = 0;
386error: 374error:
387 d_fnend(3, dev, "(rpipe %p wa %p ep %p urb %p) = %d\n",
388 rpipe, wa, ep, urb, result);
389 return result; 375 return result;
390} 376}
391 377
@@ -405,8 +391,6 @@ static int rpipe_check_aim(const struct wa_rpipe *rpipe, const struct wahc *wa,
405 u8 unauth = (usb_dev->wusb && !usb_dev->authenticated) ? 0x80 : 0; 391 u8 unauth = (usb_dev->wusb && !usb_dev->authenticated) ? 0x80 : 0;
406 u8 portnum = wusb_port_no_to_idx(urb->dev->portnum); 392 u8 portnum = wusb_port_no_to_idx(urb->dev->portnum);
407 393
408 d_fnstart(3, dev, "(rpipe %p wa %p ep %p, urb %p)\n",
409 rpipe, wa, ep, urb);
410#define AIM_CHECK(rdf, val, text) \ 394#define AIM_CHECK(rdf, val, text) \
411 do { \ 395 do { \
412 if (rpipe->descr.rdf != (val)) { \ 396 if (rpipe->descr.rdf != (val)) { \
@@ -451,8 +435,6 @@ int rpipe_get_by_ep(struct wahc *wa, struct usb_host_endpoint *ep,
451 struct wa_rpipe *rpipe; 435 struct wa_rpipe *rpipe;
452 u8 eptype; 436 u8 eptype;
453 437
454 d_fnstart(3, dev, "(wa %p ep %p urb %p gfp 0x%08x)\n", wa, ep, urb,
455 gfp);
456 mutex_lock(&wa->rpipe_mutex); 438 mutex_lock(&wa->rpipe_mutex);
457 rpipe = ep->hcpriv; 439 rpipe = ep->hcpriv;
458 if (rpipe != NULL) { 440 if (rpipe != NULL) {
@@ -462,9 +444,9 @@ int rpipe_get_by_ep(struct wahc *wa, struct usb_host_endpoint *ep,
462 goto error; 444 goto error;
463 } 445 }
464 __rpipe_get(rpipe); 446 __rpipe_get(rpipe);
465 d_printf(2, dev, "ep 0x%02x: reusing rpipe %u\n", 447 dev_dbg(dev, "ep 0x%02x: reusing rpipe %u\n",
466 ep->desc.bEndpointAddress, 448 ep->desc.bEndpointAddress,
467 le16_to_cpu(rpipe->descr.wRPipeIndex)); 449 le16_to_cpu(rpipe->descr.wRPipeIndex));
468 } else { 450 } else {
469 /* hmm, assign idle rpipe, aim it */ 451 /* hmm, assign idle rpipe, aim it */
470 result = -ENOBUFS; 452 result = -ENOBUFS;
@@ -480,14 +462,12 @@ int rpipe_get_by_ep(struct wahc *wa, struct usb_host_endpoint *ep,
480 ep->hcpriv = rpipe; 462 ep->hcpriv = rpipe;
481 rpipe->ep = ep; 463 rpipe->ep = ep;
482 __rpipe_get(rpipe); /* for caching into ep->hcpriv */ 464 __rpipe_get(rpipe); /* for caching into ep->hcpriv */
483 d_printf(2, dev, "ep 0x%02x: using rpipe %u\n", 465 dev_dbg(dev, "ep 0x%02x: using rpipe %u\n",
484 ep->desc.bEndpointAddress, 466 ep->desc.bEndpointAddress,
485 le16_to_cpu(rpipe->descr.wRPipeIndex)); 467 le16_to_cpu(rpipe->descr.wRPipeIndex));
486 } 468 }
487 d_dump(4, dev, &rpipe->descr, sizeof(rpipe->descr));
488error: 469error:
489 mutex_unlock(&wa->rpipe_mutex); 470 mutex_unlock(&wa->rpipe_mutex);
490 d_fnend(3, dev, "(wa %p ep %p urb %p gfp 0x%08x)\n", wa, ep, urb, gfp);
491 return result; 471 return result;
492} 472}
493 473
@@ -507,7 +487,7 @@ int wa_rpipes_create(struct wahc *wa)
507void wa_rpipes_destroy(struct wahc *wa) 487void wa_rpipes_destroy(struct wahc *wa)
508{ 488{
509 struct device *dev = &wa->usb_iface->dev; 489 struct device *dev = &wa->usb_iface->dev;
510 d_fnstart(3, dev, "(wa %p)\n", wa); 490
511 if (!bitmap_empty(wa->rpipe_bm, wa->rpipes)) { 491 if (!bitmap_empty(wa->rpipe_bm, wa->rpipes)) {
512 char buf[256]; 492 char buf[256];
513 WARN_ON(1); 493 WARN_ON(1);
@@ -515,7 +495,6 @@ void wa_rpipes_destroy(struct wahc *wa)
515 dev_err(dev, "BUG: pipes not released on exit: %s\n", buf); 495 dev_err(dev, "BUG: pipes not released on exit: %s\n", buf);
516 } 496 }
517 kfree(wa->rpipe_bm); 497 kfree(wa->rpipe_bm);
518 d_fnend(3, dev, "(wa %p)\n", wa);
519} 498}
520 499
521/* 500/*
@@ -530,33 +509,20 @@ void wa_rpipes_destroy(struct wahc *wa)
530 */ 509 */
531void rpipe_ep_disable(struct wahc *wa, struct usb_host_endpoint *ep) 510void rpipe_ep_disable(struct wahc *wa, struct usb_host_endpoint *ep)
532{ 511{
533 struct device *dev = &wa->usb_iface->dev;
534 struct wa_rpipe *rpipe; 512 struct wa_rpipe *rpipe;
535 d_fnstart(2, dev, "(wa %p ep %p)\n", wa, ep); 513
536 mutex_lock(&wa->rpipe_mutex); 514 mutex_lock(&wa->rpipe_mutex);
537 rpipe = ep->hcpriv; 515 rpipe = ep->hcpriv;
538 if (rpipe != NULL) { 516 if (rpipe != NULL) {
539 unsigned rc = atomic_read(&rpipe->refcnt.refcount);
540 int result;
541 u16 index = le16_to_cpu(rpipe->descr.wRPipeIndex); 517 u16 index = le16_to_cpu(rpipe->descr.wRPipeIndex);
542 518
543 if (rc != 1) 519 usb_control_msg(
544 d_printf(1, dev, "(wa %p ep %p) rpipe %p refcnt %u\n",
545 wa, ep, rpipe, rc);
546
547 d_printf(1, dev, "rpipe %u: abort\n", index);
548 result = usb_control_msg(
549 wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0), 520 wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0),
550 USB_REQ_RPIPE_ABORT, 521 USB_REQ_RPIPE_ABORT,
551 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, 522 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE,
552 0, index, NULL, 0, 1000 /* FIXME: arbitrary */); 523 0, index, NULL, 0, 1000 /* FIXME: arbitrary */);
553 if (result < 0 && result != -ENODEV /* dev is gone */)
554 d_printf(1, dev, "(wa %p rpipe %u): abort failed: %d\n",
555 wa, index, result);
556 rpipe_put(rpipe); 524 rpipe_put(rpipe);
557 } 525 }
558 mutex_unlock(&wa->rpipe_mutex); 526 mutex_unlock(&wa->rpipe_mutex);
559 d_fnend(2, dev, "(wa %p ep %p)\n", wa, ep);
560 return;
561} 527}
562EXPORT_SYMBOL_GPL(rpipe_ep_disable); 528EXPORT_SYMBOL_GPL(rpipe_ep_disable);
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index c038635d1c64..238a96aee3a1 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -82,13 +82,10 @@
82#include <linux/init.h> 82#include <linux/init.h>
83#include <linux/spinlock.h> 83#include <linux/spinlock.h>
84#include <linux/hash.h> 84#include <linux/hash.h>
85
85#include "wa-hc.h" 86#include "wa-hc.h"
86#include "wusbhc.h" 87#include "wusbhc.h"
87 88
88#undef D_LOCAL
89#define D_LOCAL 0 /* 0 disabled, > 0 different levels... */
90#include <linux/uwb/debug.h>
91
92enum { 89enum {
93 WA_SEGS_MAX = 255, 90 WA_SEGS_MAX = 255,
94}; 91};
@@ -180,7 +177,6 @@ static void wa_xfer_destroy(struct kref *_xfer)
180 } 177 }
181 } 178 }
182 kfree(xfer); 179 kfree(xfer);
183 d_printf(2, NULL, "xfer %p destroyed\n", xfer);
184} 180}
185 181
186static void wa_xfer_get(struct wa_xfer *xfer) 182static void wa_xfer_get(struct wa_xfer *xfer)
@@ -190,10 +186,7 @@ static void wa_xfer_get(struct wa_xfer *xfer)
190 186
191static void wa_xfer_put(struct wa_xfer *xfer) 187static void wa_xfer_put(struct wa_xfer *xfer)
192{ 188{
193 d_fnstart(3, NULL, "(xfer %p) -- ref count bef put %d\n",
194 xfer, atomic_read(&xfer->refcnt.refcount));
195 kref_put(&xfer->refcnt, wa_xfer_destroy); 189 kref_put(&xfer->refcnt, wa_xfer_destroy);
196 d_fnend(3, NULL, "(xfer %p) = void\n", xfer);
197} 190}
198 191
199/* 192/*
@@ -209,7 +202,7 @@ static void wa_xfer_put(struct wa_xfer *xfer)
209static void wa_xfer_giveback(struct wa_xfer *xfer) 202static void wa_xfer_giveback(struct wa_xfer *xfer)
210{ 203{
211 unsigned long flags; 204 unsigned long flags;
212 d_fnstart(3, NULL, "(xfer %p)\n", xfer); 205
213 spin_lock_irqsave(&xfer->wa->xfer_list_lock, flags); 206 spin_lock_irqsave(&xfer->wa->xfer_list_lock, flags);
214 list_del_init(&xfer->list_node); 207 list_del_init(&xfer->list_node);
215 spin_unlock_irqrestore(&xfer->wa->xfer_list_lock, flags); 208 spin_unlock_irqrestore(&xfer->wa->xfer_list_lock, flags);
@@ -217,7 +210,6 @@ static void wa_xfer_giveback(struct wa_xfer *xfer)
217 wusbhc_giveback_urb(xfer->wa->wusb, xfer->urb, xfer->result); 210 wusbhc_giveback_urb(xfer->wa->wusb, xfer->urb, xfer->result);
218 wa_put(xfer->wa); 211 wa_put(xfer->wa);
219 wa_xfer_put(xfer); 212 wa_xfer_put(xfer);
220 d_fnend(3, NULL, "(xfer %p) = void\n", xfer);
221} 213}
222 214
223/* 215/*
@@ -227,13 +219,10 @@ static void wa_xfer_giveback(struct wa_xfer *xfer)
227 */ 219 */
228static void wa_xfer_completion(struct wa_xfer *xfer) 220static void wa_xfer_completion(struct wa_xfer *xfer)
229{ 221{
230 d_fnstart(3, NULL, "(xfer %p)\n", xfer);
231 if (xfer->wusb_dev) 222 if (xfer->wusb_dev)
232 wusb_dev_put(xfer->wusb_dev); 223 wusb_dev_put(xfer->wusb_dev);
233 rpipe_put(xfer->ep->hcpriv); 224 rpipe_put(xfer->ep->hcpriv);
234 wa_xfer_giveback(xfer); 225 wa_xfer_giveback(xfer);
235 d_fnend(3, NULL, "(xfer %p) = void\n", xfer);
236 return;
237} 226}
238 227
239/* 228/*
@@ -243,12 +232,12 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
243 */ 232 */
244static unsigned __wa_xfer_is_done(struct wa_xfer *xfer) 233static unsigned __wa_xfer_is_done(struct wa_xfer *xfer)
245{ 234{
235 struct device *dev = &xfer->wa->usb_iface->dev;
246 unsigned result, cnt; 236 unsigned result, cnt;
247 struct wa_seg *seg; 237 struct wa_seg *seg;
248 struct urb *urb = xfer->urb; 238 struct urb *urb = xfer->urb;
249 unsigned found_short = 0; 239 unsigned found_short = 0;
250 240
251 d_fnstart(3, NULL, "(xfer %p)\n", xfer);
252 result = xfer->segs_done == xfer->segs_submitted; 241 result = xfer->segs_done == xfer->segs_submitted;
253 if (result == 0) 242 if (result == 0)
254 goto out; 243 goto out;
@@ -258,10 +247,8 @@ static unsigned __wa_xfer_is_done(struct wa_xfer *xfer)
258 switch (seg->status) { 247 switch (seg->status) {
259 case WA_SEG_DONE: 248 case WA_SEG_DONE:
260 if (found_short && seg->result > 0) { 249 if (found_short && seg->result > 0) {
261 if (printk_ratelimit()) 250 dev_dbg(dev, "xfer %p#%u: bad short segments (%zu)\n",
262 printk(KERN_ERR "xfer %p#%u: bad short " 251 xfer, cnt, seg->result);
263 "segments (%zu)\n", xfer, cnt,
264 seg->result);
265 urb->status = -EINVAL; 252 urb->status = -EINVAL;
266 goto out; 253 goto out;
267 } 254 }
@@ -269,36 +256,30 @@ static unsigned __wa_xfer_is_done(struct wa_xfer *xfer)
269 if (seg->result < xfer->seg_size 256 if (seg->result < xfer->seg_size
270 && cnt != xfer->segs-1) 257 && cnt != xfer->segs-1)
271 found_short = 1; 258 found_short = 1;
272 d_printf(2, NULL, "xfer %p#%u: DONE short %d " 259 dev_dbg(dev, "xfer %p#%u: DONE short %d "
273 "result %zu urb->actual_length %d\n", 260 "result %zu urb->actual_length %d\n",
274 xfer, seg->index, found_short, seg->result, 261 xfer, seg->index, found_short, seg->result,
275 urb->actual_length); 262 urb->actual_length);
276 break; 263 break;
277 case WA_SEG_ERROR: 264 case WA_SEG_ERROR:
278 xfer->result = seg->result; 265 xfer->result = seg->result;
279 d_printf(2, NULL, "xfer %p#%u: ERROR result %zu\n", 266 dev_dbg(dev, "xfer %p#%u: ERROR result %zu\n",
280 xfer, seg->index, seg->result); 267 xfer, seg->index, seg->result);
281 goto out; 268 goto out;
282 case WA_SEG_ABORTED: 269 case WA_SEG_ABORTED:
283 WARN_ON(urb->status != -ECONNRESET 270 dev_dbg(dev, "xfer %p#%u ABORTED: result %d\n",
284 && urb->status != -ENOENT); 271 xfer, seg->index, urb->status);
285 d_printf(2, NULL, "xfer %p#%u ABORTED: result %d\n",
286 xfer, seg->index, urb->status);
287 xfer->result = urb->status; 272 xfer->result = urb->status;
288 goto out; 273 goto out;
289 default: 274 default:
290 /* if (printk_ratelimit()) */ 275 dev_warn(dev, "xfer %p#%u: is_done bad state %d\n",
291 printk(KERN_ERR "xfer %p#%u: " 276 xfer, cnt, seg->status);
292 "is_done bad state %d\n",
293 xfer, cnt, seg->status);
294 xfer->result = -EINVAL; 277 xfer->result = -EINVAL;
295 WARN_ON(1);
296 goto out; 278 goto out;
297 } 279 }
298 } 280 }
299 xfer->result = 0; 281 xfer->result = 0;
300out: 282out:
301 d_fnend(3, NULL, "(xfer %p) = void\n", xfer);
302 return result; 283 return result;
303} 284}
304 285
@@ -424,8 +405,6 @@ static ssize_t __wa_xfer_setup_sizes(struct wa_xfer *xfer,
424 struct urb *urb = xfer->urb; 405 struct urb *urb = xfer->urb;
425 struct wa_rpipe *rpipe = xfer->ep->hcpriv; 406 struct wa_rpipe *rpipe = xfer->ep->hcpriv;
426 407
427 d_fnstart(3, dev, "(xfer %p [rpipe %p] urb %p)\n",
428 xfer, rpipe, urb);
429 switch (rpipe->descr.bmAttribute & 0x3) { 408 switch (rpipe->descr.bmAttribute & 0x3) {
430 case USB_ENDPOINT_XFER_CONTROL: 409 case USB_ENDPOINT_XFER_CONTROL:
431 *pxfer_type = WA_XFER_TYPE_CTL; 410 *pxfer_type = WA_XFER_TYPE_CTL;
@@ -472,12 +451,10 @@ static ssize_t __wa_xfer_setup_sizes(struct wa_xfer *xfer,
472 if (xfer->segs == 0 && *pxfer_type == WA_XFER_TYPE_CTL) 451 if (xfer->segs == 0 && *pxfer_type == WA_XFER_TYPE_CTL)
473 xfer->segs = 1; 452 xfer->segs = 1;
474error: 453error:
475 d_fnend(3, dev, "(xfer %p [rpipe %p] urb %p) = %d\n",
476 xfer, rpipe, urb, (int)result);
477 return result; 454 return result;
478} 455}
479 456
480/** Fill in the common request header and xfer-type specific data. */ 457/* Fill in the common request header and xfer-type specific data. */
481static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer, 458static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer,
482 struct wa_xfer_hdr *xfer_hdr0, 459 struct wa_xfer_hdr *xfer_hdr0,
483 enum wa_xfer_type xfer_type, 460 enum wa_xfer_type xfer_type,
@@ -534,14 +511,13 @@ static void wa_seg_dto_cb(struct urb *urb)
534 unsigned rpipe_ready = 0; 511 unsigned rpipe_ready = 0;
535 u8 done = 0; 512 u8 done = 0;
536 513
537 d_fnstart(3, NULL, "(urb %p [%d])\n", urb, urb->status);
538 switch (urb->status) { 514 switch (urb->status) {
539 case 0: 515 case 0:
540 spin_lock_irqsave(&xfer->lock, flags); 516 spin_lock_irqsave(&xfer->lock, flags);
541 wa = xfer->wa; 517 wa = xfer->wa;
542 dev = &wa->usb_iface->dev; 518 dev = &wa->usb_iface->dev;
543 d_printf(2, dev, "xfer %p#%u: data out done (%d bytes)\n", 519 dev_dbg(dev, "xfer %p#%u: data out done (%d bytes)\n",
544 xfer, seg->index, urb->actual_length); 520 xfer, seg->index, urb->actual_length);
545 if (seg->status < WA_SEG_PENDING) 521 if (seg->status < WA_SEG_PENDING)
546 seg->status = WA_SEG_PENDING; 522 seg->status = WA_SEG_PENDING;
547 seg->result = urb->actual_length; 523 seg->result = urb->actual_length;
@@ -555,9 +531,8 @@ static void wa_seg_dto_cb(struct urb *urb)
555 wa = xfer->wa; 531 wa = xfer->wa;
556 dev = &wa->usb_iface->dev; 532 dev = &wa->usb_iface->dev;
557 rpipe = xfer->ep->hcpriv; 533 rpipe = xfer->ep->hcpriv;
558 if (printk_ratelimit()) 534 dev_dbg(dev, "xfer %p#%u: data out error %d\n",
559 dev_err(dev, "xfer %p#%u: data out error %d\n", 535 xfer, seg->index, urb->status);
560 xfer, seg->index, urb->status);
561 if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, 536 if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS,
562 EDC_ERROR_TIMEFRAME)){ 537 EDC_ERROR_TIMEFRAME)){
563 dev_err(dev, "DTO: URB max acceptable errors " 538 dev_err(dev, "DTO: URB max acceptable errors "
@@ -578,7 +553,6 @@ static void wa_seg_dto_cb(struct urb *urb)
578 if (rpipe_ready) 553 if (rpipe_ready)
579 wa_xfer_delayed_run(rpipe); 554 wa_xfer_delayed_run(rpipe);
580 } 555 }
581 d_fnend(3, NULL, "(urb %p [%d]) = void\n", urb, urb->status);
582} 556}
583 557
584/* 558/*
@@ -610,14 +584,12 @@ static void wa_seg_cb(struct urb *urb)
610 unsigned rpipe_ready; 584 unsigned rpipe_ready;
611 u8 done = 0; 585 u8 done = 0;
612 586
613 d_fnstart(3, NULL, "(urb %p [%d])\n", urb, urb->status);
614 switch (urb->status) { 587 switch (urb->status) {
615 case 0: 588 case 0:
616 spin_lock_irqsave(&xfer->lock, flags); 589 spin_lock_irqsave(&xfer->lock, flags);
617 wa = xfer->wa; 590 wa = xfer->wa;
618 dev = &wa->usb_iface->dev; 591 dev = &wa->usb_iface->dev;
619 d_printf(2, dev, "xfer %p#%u: request done\n", 592 dev_dbg(dev, "xfer %p#%u: request done\n", xfer, seg->index);
620 xfer, seg->index);
621 if (xfer->is_inbound && seg->status < WA_SEG_PENDING) 593 if (xfer->is_inbound && seg->status < WA_SEG_PENDING)
622 seg->status = WA_SEG_PENDING; 594 seg->status = WA_SEG_PENDING;
623 spin_unlock_irqrestore(&xfer->lock, flags); 595 spin_unlock_irqrestore(&xfer->lock, flags);
@@ -652,7 +624,6 @@ static void wa_seg_cb(struct urb *urb)
652 if (rpipe_ready) 624 if (rpipe_ready)
653 wa_xfer_delayed_run(rpipe); 625 wa_xfer_delayed_run(rpipe);
654 } 626 }
655 d_fnend(3, NULL, "(urb %p [%d]) = void\n", urb, urb->status);
656} 627}
657 628
658/* 629/*
@@ -750,9 +721,6 @@ static int __wa_xfer_setup(struct wa_xfer *xfer, struct urb *urb)
750 size_t xfer_hdr_size, cnt, transfer_size; 721 size_t xfer_hdr_size, cnt, transfer_size;
751 struct wa_xfer_hdr *xfer_hdr0, *xfer_hdr; 722 struct wa_xfer_hdr *xfer_hdr0, *xfer_hdr;
752 723
753 d_fnstart(3, dev, "(xfer %p [rpipe %p] urb %p)\n",
754 xfer, xfer->ep->hcpriv, urb);
755
756 result = __wa_xfer_setup_sizes(xfer, &xfer_type); 724 result = __wa_xfer_setup_sizes(xfer, &xfer_type);
757 if (result < 0) 725 if (result < 0)
758 goto error_setup_sizes; 726 goto error_setup_sizes;
@@ -788,8 +756,6 @@ static int __wa_xfer_setup(struct wa_xfer *xfer, struct urb *urb)
788 result = 0; 756 result = 0;
789error_setup_segs: 757error_setup_segs:
790error_setup_sizes: 758error_setup_sizes:
791 d_fnend(3, dev, "(xfer %p [rpipe %p] urb %p) = %d\n",
792 xfer, xfer->ep->hcpriv, urb, result);
793 return result; 759 return result;
794} 760}
795 761
@@ -843,9 +809,6 @@ static void wa_xfer_delayed_run(struct wa_rpipe *rpipe)
843 struct wa_xfer *xfer; 809 struct wa_xfer *xfer;
844 unsigned long flags; 810 unsigned long flags;
845 811
846 d_fnstart(1, dev, "(rpipe #%d) %d segments available\n",
847 le16_to_cpu(rpipe->descr.wRPipeIndex),
848 atomic_read(&rpipe->segs_available));
849 spin_lock_irqsave(&rpipe->seg_lock, flags); 812 spin_lock_irqsave(&rpipe->seg_lock, flags);
850 while (atomic_read(&rpipe->segs_available) > 0 813 while (atomic_read(&rpipe->segs_available) > 0
851 && !list_empty(&rpipe->seg_list)) { 814 && !list_empty(&rpipe->seg_list)) {
@@ -854,10 +817,8 @@ static void wa_xfer_delayed_run(struct wa_rpipe *rpipe)
854 list_del(&seg->list_node); 817 list_del(&seg->list_node);
855 xfer = seg->xfer; 818 xfer = seg->xfer;
856 result = __wa_seg_submit(rpipe, xfer, seg); 819 result = __wa_seg_submit(rpipe, xfer, seg);
857 d_printf(1, dev, "xfer %p#%u submitted from delayed " 820 dev_dbg(dev, "xfer %p#%u submitted from delayed [%d segments available] %d\n",
858 "[%d segments available] %d\n", 821 xfer, seg->index, atomic_read(&rpipe->segs_available), result);
859 xfer, seg->index,
860 atomic_read(&rpipe->segs_available), result);
861 if (unlikely(result < 0)) { 822 if (unlikely(result < 0)) {
862 spin_unlock_irqrestore(&rpipe->seg_lock, flags); 823 spin_unlock_irqrestore(&rpipe->seg_lock, flags);
863 spin_lock_irqsave(&xfer->lock, flags); 824 spin_lock_irqsave(&xfer->lock, flags);
@@ -868,10 +829,6 @@ static void wa_xfer_delayed_run(struct wa_rpipe *rpipe)
868 } 829 }
869 } 830 }
870 spin_unlock_irqrestore(&rpipe->seg_lock, flags); 831 spin_unlock_irqrestore(&rpipe->seg_lock, flags);
871 d_fnend(1, dev, "(rpipe #%d) = void, %d segments available\n",
872 le16_to_cpu(rpipe->descr.wRPipeIndex),
873 atomic_read(&rpipe->segs_available));
874
875} 832}
876 833
877/* 834/*
@@ -894,9 +851,6 @@ static int __wa_xfer_submit(struct wa_xfer *xfer)
894 u8 available; 851 u8 available;
895 u8 empty; 852 u8 empty;
896 853
897 d_fnstart(3, dev, "(xfer %p [rpipe %p])\n",
898 xfer, xfer->ep->hcpriv);
899
900 spin_lock_irqsave(&wa->xfer_list_lock, flags); 854 spin_lock_irqsave(&wa->xfer_list_lock, flags);
901 list_add_tail(&xfer->list_node, &wa->xfer_list); 855 list_add_tail(&xfer->list_node, &wa->xfer_list);
902 spin_unlock_irqrestore(&wa->xfer_list_lock, flags); 856 spin_unlock_irqrestore(&wa->xfer_list_lock, flags);
@@ -908,30 +862,24 @@ static int __wa_xfer_submit(struct wa_xfer *xfer)
908 available = atomic_read(&rpipe->segs_available); 862 available = atomic_read(&rpipe->segs_available);
909 empty = list_empty(&rpipe->seg_list); 863 empty = list_empty(&rpipe->seg_list);
910 seg = xfer->seg[cnt]; 864 seg = xfer->seg[cnt];
911 d_printf(2, dev, "xfer %p#%u: available %u empty %u (%s)\n", 865 dev_dbg(dev, "xfer %p#%u: available %u empty %u (%s)\n",
912 xfer, cnt, available, empty, 866 xfer, cnt, available, empty,
913 available == 0 || !empty ? "delayed" : "submitted"); 867 available == 0 || !empty ? "delayed" : "submitted");
914 if (available == 0 || !empty) { 868 if (available == 0 || !empty) {
915 d_printf(1, dev, "xfer %p#%u: delayed\n", xfer, cnt); 869 dev_dbg(dev, "xfer %p#%u: delayed\n", xfer, cnt);
916 seg->status = WA_SEG_DELAYED; 870 seg->status = WA_SEG_DELAYED;
917 list_add_tail(&seg->list_node, &rpipe->seg_list); 871 list_add_tail(&seg->list_node, &rpipe->seg_list);
918 } else { 872 } else {
919 result = __wa_seg_submit(rpipe, xfer, seg); 873 result = __wa_seg_submit(rpipe, xfer, seg);
920 if (result < 0) 874 if (result < 0) {
875 __wa_xfer_abort(xfer);
921 goto error_seg_submit; 876 goto error_seg_submit;
877 }
922 } 878 }
923 xfer->segs_submitted++; 879 xfer->segs_submitted++;
924 } 880 }
925 spin_unlock_irqrestore(&rpipe->seg_lock, flags);
926 d_fnend(3, dev, "(xfer %p [rpipe %p]) = void\n", xfer,
927 xfer->ep->hcpriv);
928 return result;
929
930error_seg_submit: 881error_seg_submit:
931 __wa_xfer_abort(xfer);
932 spin_unlock_irqrestore(&rpipe->seg_lock, flags); 882 spin_unlock_irqrestore(&rpipe->seg_lock, flags);
933 d_fnend(3, dev, "(xfer %p [rpipe %p]) = void\n", xfer,
934 xfer->ep->hcpriv);
935 return result; 883 return result;
936} 884}
937 885
@@ -964,11 +912,9 @@ static void wa_urb_enqueue_b(struct wa_xfer *xfer)
964 struct urb *urb = xfer->urb; 912 struct urb *urb = xfer->urb;
965 struct wahc *wa = xfer->wa; 913 struct wahc *wa = xfer->wa;
966 struct wusbhc *wusbhc = wa->wusb; 914 struct wusbhc *wusbhc = wa->wusb;
967 struct device *dev = &wa->usb_iface->dev;
968 struct wusb_dev *wusb_dev; 915 struct wusb_dev *wusb_dev;
969 unsigned done; 916 unsigned done;
970 917
971 d_fnstart(3, dev, "(wa %p urb %p)\n", wa, urb);
972 result = rpipe_get_by_ep(wa, xfer->ep, urb, xfer->gfp); 918 result = rpipe_get_by_ep(wa, xfer->ep, urb, xfer->gfp);
973 if (result < 0) 919 if (result < 0)
974 goto error_rpipe_get; 920 goto error_rpipe_get;
@@ -997,7 +943,6 @@ static void wa_urb_enqueue_b(struct wa_xfer *xfer)
997 if (result < 0) 943 if (result < 0)
998 goto error_xfer_submit; 944 goto error_xfer_submit;
999 spin_unlock_irqrestore(&xfer->lock, flags); 945 spin_unlock_irqrestore(&xfer->lock, flags);
1000 d_fnend(3, dev, "(wa %p urb %p) = void\n", wa, urb);
1001 return; 946 return;
1002 947
1003 /* this is basically wa_xfer_completion() broken up wa_xfer_giveback() 948 /* this is basically wa_xfer_completion() broken up wa_xfer_giveback()
@@ -1015,7 +960,6 @@ error_dev_gone:
1015error_rpipe_get: 960error_rpipe_get:
1016 xfer->result = result; 961 xfer->result = result;
1017 wa_xfer_giveback(xfer); 962 wa_xfer_giveback(xfer);
1018 d_fnend(3, dev, "(wa %p urb %p) = (void) %d\n", wa, urb, result);
1019 return; 963 return;
1020 964
1021error_xfer_submit: 965error_xfer_submit:
@@ -1024,8 +968,6 @@ error_xfer_submit:
1024 spin_unlock_irqrestore(&xfer->lock, flags); 968 spin_unlock_irqrestore(&xfer->lock, flags);
1025 if (done) 969 if (done)
1026 wa_xfer_completion(xfer); 970 wa_xfer_completion(xfer);
1027 d_fnend(3, dev, "(wa %p urb %p) = (void) %d\n", wa, urb, result);
1028 return;
1029} 971}
1030 972
1031/* 973/*
@@ -1041,11 +983,9 @@ error_xfer_submit:
1041void wa_urb_enqueue_run(struct work_struct *ws) 983void wa_urb_enqueue_run(struct work_struct *ws)
1042{ 984{
1043 struct wahc *wa = container_of(ws, struct wahc, xfer_work); 985 struct wahc *wa = container_of(ws, struct wahc, xfer_work);
1044 struct device *dev = &wa->usb_iface->dev;
1045 struct wa_xfer *xfer, *next; 986 struct wa_xfer *xfer, *next;
1046 struct urb *urb; 987 struct urb *urb;
1047 988
1048 d_fnstart(3, dev, "(wa %p)\n", wa);
1049 spin_lock_irq(&wa->xfer_list_lock); 989 spin_lock_irq(&wa->xfer_list_lock);
1050 list_for_each_entry_safe(xfer, next, &wa->xfer_delayed_list, 990 list_for_each_entry_safe(xfer, next, &wa->xfer_delayed_list,
1051 list_node) { 991 list_node) {
@@ -1059,7 +999,6 @@ void wa_urb_enqueue_run(struct work_struct *ws)
1059 spin_lock_irq(&wa->xfer_list_lock); 999 spin_lock_irq(&wa->xfer_list_lock);
1060 } 1000 }
1061 spin_unlock_irq(&wa->xfer_list_lock); 1001 spin_unlock_irq(&wa->xfer_list_lock);
1062 d_fnend(3, dev, "(wa %p) = void\n", wa);
1063} 1002}
1064EXPORT_SYMBOL_GPL(wa_urb_enqueue_run); 1003EXPORT_SYMBOL_GPL(wa_urb_enqueue_run);
1065 1004
@@ -1084,9 +1023,6 @@ int wa_urb_enqueue(struct wahc *wa, struct usb_host_endpoint *ep,
1084 unsigned long my_flags; 1023 unsigned long my_flags;
1085 unsigned cant_sleep = irqs_disabled() | in_atomic(); 1024 unsigned cant_sleep = irqs_disabled() | in_atomic();
1086 1025
1087 d_fnstart(3, dev, "(wa %p ep %p urb %p [%d] gfp 0x%x)\n",
1088 wa, ep, urb, urb->transfer_buffer_length, gfp);
1089
1090 if (urb->transfer_buffer == NULL 1026 if (urb->transfer_buffer == NULL
1091 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) 1027 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
1092 && urb->transfer_buffer_length != 0) { 1028 && urb->transfer_buffer_length != 0) {
@@ -1108,11 +1044,13 @@ int wa_urb_enqueue(struct wahc *wa, struct usb_host_endpoint *ep,
1108 xfer->gfp = gfp; 1044 xfer->gfp = gfp;
1109 xfer->ep = ep; 1045 xfer->ep = ep;
1110 urb->hcpriv = xfer; 1046 urb->hcpriv = xfer;
1111 d_printf(2, dev, "xfer %p urb %p pipe 0x%02x [%d bytes] %s %s %s\n", 1047
1112 xfer, urb, urb->pipe, urb->transfer_buffer_length, 1048 dev_dbg(dev, "xfer %p urb %p pipe 0x%02x [%d bytes] %s %s %s\n",
1113 urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP ? "dma" : "nodma", 1049 xfer, urb, urb->pipe, urb->transfer_buffer_length,
1114 urb->pipe & USB_DIR_IN ? "inbound" : "outbound", 1050 urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP ? "dma" : "nodma",
1115 cant_sleep ? "deferred" : "inline"); 1051 urb->pipe & USB_DIR_IN ? "inbound" : "outbound",
1052 cant_sleep ? "deferred" : "inline");
1053
1116 if (cant_sleep) { 1054 if (cant_sleep) {
1117 usb_get_urb(urb); 1055 usb_get_urb(urb);
1118 spin_lock_irqsave(&wa->xfer_list_lock, my_flags); 1056 spin_lock_irqsave(&wa->xfer_list_lock, my_flags);
@@ -1122,15 +1060,11 @@ int wa_urb_enqueue(struct wahc *wa, struct usb_host_endpoint *ep,
1122 } else { 1060 } else {
1123 wa_urb_enqueue_b(xfer); 1061 wa_urb_enqueue_b(xfer);
1124 } 1062 }
1125 d_fnend(3, dev, "(wa %p ep %p urb %p [%d] gfp 0x%x) = 0\n",
1126 wa, ep, urb, urb->transfer_buffer_length, gfp);
1127 return 0; 1063 return 0;
1128 1064
1129error_dequeued: 1065error_dequeued:
1130 kfree(xfer); 1066 kfree(xfer);
1131error_kmalloc: 1067error_kmalloc:
1132 d_fnend(3, dev, "(wa %p ep %p urb %p [%d] gfp 0x%x) = %d\n",
1133 wa, ep, urb, urb->transfer_buffer_length, gfp, result);
1134 return result; 1068 return result;
1135} 1069}
1136EXPORT_SYMBOL_GPL(wa_urb_enqueue); 1070EXPORT_SYMBOL_GPL(wa_urb_enqueue);
@@ -1155,7 +1089,6 @@ EXPORT_SYMBOL_GPL(wa_urb_enqueue);
1155 */ 1089 */
1156int wa_urb_dequeue(struct wahc *wa, struct urb *urb) 1090int wa_urb_dequeue(struct wahc *wa, struct urb *urb)
1157{ 1091{
1158 struct device *dev = &wa->usb_iface->dev;
1159 unsigned long flags, flags2; 1092 unsigned long flags, flags2;
1160 struct wa_xfer *xfer; 1093 struct wa_xfer *xfer;
1161 struct wa_seg *seg; 1094 struct wa_seg *seg;
@@ -1163,9 +1096,6 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb)
1163 unsigned cnt; 1096 unsigned cnt;
1164 unsigned rpipe_ready = 0; 1097 unsigned rpipe_ready = 0;
1165 1098
1166 d_fnstart(3, dev, "(wa %p, urb %p)\n", wa, urb);
1167
1168 d_printf(1, dev, "xfer %p urb %p: aborting\n", urb->hcpriv, urb);
1169 xfer = urb->hcpriv; 1099 xfer = urb->hcpriv;
1170 if (xfer == NULL) { 1100 if (xfer == NULL) {
1171 /* NOthing setup yet enqueue will see urb->status != 1101 /* NOthing setup yet enqueue will see urb->status !=
@@ -1234,13 +1164,11 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb)
1234 wa_xfer_completion(xfer); 1164 wa_xfer_completion(xfer);
1235 if (rpipe_ready) 1165 if (rpipe_ready)
1236 wa_xfer_delayed_run(rpipe); 1166 wa_xfer_delayed_run(rpipe);
1237 d_fnend(3, dev, "(wa %p, urb %p) = 0\n", wa, urb);
1238 return 0; 1167 return 0;
1239 1168
1240out_unlock: 1169out_unlock:
1241 spin_unlock_irqrestore(&xfer->lock, flags); 1170 spin_unlock_irqrestore(&xfer->lock, flags);
1242out: 1171out:
1243 d_fnend(3, dev, "(wa %p, urb %p) = 0\n", wa, urb);
1244 return 0; 1172 return 0;
1245 1173
1246dequeue_delayed: 1174dequeue_delayed:
@@ -1250,7 +1178,6 @@ dequeue_delayed:
1250 spin_unlock_irqrestore(&xfer->lock, flags); 1178 spin_unlock_irqrestore(&xfer->lock, flags);
1251 wa_xfer_giveback(xfer); 1179 wa_xfer_giveback(xfer);
1252 usb_put_urb(urb); /* we got a ref in enqueue() */ 1180 usb_put_urb(urb); /* we got a ref in enqueue() */
1253 d_fnend(3, dev, "(wa %p, urb %p) = 0\n", wa, urb);
1254 return 0; 1181 return 0;
1255} 1182}
1256EXPORT_SYMBOL_GPL(wa_urb_dequeue); 1183EXPORT_SYMBOL_GPL(wa_urb_dequeue);
@@ -1326,7 +1253,6 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer)
1326 u8 usb_status; 1253 u8 usb_status;
1327 unsigned rpipe_ready = 0; 1254 unsigned rpipe_ready = 0;
1328 1255
1329 d_fnstart(3, dev, "(wa %p xfer %p)\n", wa, xfer);
1330 spin_lock_irqsave(&xfer->lock, flags); 1256 spin_lock_irqsave(&xfer->lock, flags);
1331 seg_idx = xfer_result->bTransferSegment & 0x7f; 1257 seg_idx = xfer_result->bTransferSegment & 0x7f;
1332 if (unlikely(seg_idx >= xfer->segs)) 1258 if (unlikely(seg_idx >= xfer->segs))
@@ -1334,8 +1260,8 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer)
1334 seg = xfer->seg[seg_idx]; 1260 seg = xfer->seg[seg_idx];
1335 rpipe = xfer->ep->hcpriv; 1261 rpipe = xfer->ep->hcpriv;
1336 usb_status = xfer_result->bTransferStatus; 1262 usb_status = xfer_result->bTransferStatus;
1337 d_printf(2, dev, "xfer %p#%u: bTransferStatus 0x%02x (seg %u)\n", 1263 dev_dbg(dev, "xfer %p#%u: bTransferStatus 0x%02x (seg %u)\n",
1338 xfer, seg_idx, usb_status, seg->status); 1264 xfer, seg_idx, usb_status, seg->status);
1339 if (seg->status == WA_SEG_ABORTED 1265 if (seg->status == WA_SEG_ABORTED
1340 || seg->status == WA_SEG_ERROR) /* already handled */ 1266 || seg->status == WA_SEG_ERROR) /* already handled */
1341 goto segment_aborted; 1267 goto segment_aborted;
@@ -1391,10 +1317,8 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer)
1391 wa_xfer_completion(xfer); 1317 wa_xfer_completion(xfer);
1392 if (rpipe_ready) 1318 if (rpipe_ready)
1393 wa_xfer_delayed_run(rpipe); 1319 wa_xfer_delayed_run(rpipe);
1394 d_fnend(3, dev, "(wa %p xfer %p) = void\n", wa, xfer);
1395 return; 1320 return;
1396 1321
1397
1398error_submit_buf_in: 1322error_submit_buf_in:
1399 if (edc_inc(&wa->dti_edc, EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME)) { 1323 if (edc_inc(&wa->dti_edc, EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME)) {
1400 dev_err(dev, "DTI: URB max acceptable errors " 1324 dev_err(dev, "DTI: URB max acceptable errors "
@@ -1416,11 +1340,8 @@ error_complete:
1416 wa_xfer_completion(xfer); 1340 wa_xfer_completion(xfer);
1417 if (rpipe_ready) 1341 if (rpipe_ready)
1418 wa_xfer_delayed_run(rpipe); 1342 wa_xfer_delayed_run(rpipe);
1419 d_fnend(3, dev, "(wa %p xfer %p) = void [segment/DTI-submit error]\n",
1420 wa, xfer);
1421 return; 1343 return;
1422 1344
1423
1424error_bad_seg: 1345error_bad_seg:
1425 spin_unlock_irqrestore(&xfer->lock, flags); 1346 spin_unlock_irqrestore(&xfer->lock, flags);
1426 wa_urb_dequeue(wa, xfer->urb); 1347 wa_urb_dequeue(wa, xfer->urb);
@@ -1431,17 +1352,11 @@ error_bad_seg:
1431 "exceeded, resetting device\n"); 1352 "exceeded, resetting device\n");
1432 wa_reset_all(wa); 1353 wa_reset_all(wa);
1433 } 1354 }
1434 d_fnend(3, dev, "(wa %p xfer %p) = void [bad seg]\n", wa, xfer);
1435 return; 1355 return;
1436 1356
1437
1438segment_aborted: 1357segment_aborted:
1439 /* nothing to do, as the aborter did the completion */ 1358 /* nothing to do, as the aborter did the completion */
1440 spin_unlock_irqrestore(&xfer->lock, flags); 1359 spin_unlock_irqrestore(&xfer->lock, flags);
1441 d_fnend(3, dev, "(wa %p xfer %p) = void [segment aborted]\n",
1442 wa, xfer);
1443 return;
1444
1445} 1360}
1446 1361
1447/* 1362/*
@@ -1465,15 +1380,14 @@ static void wa_buf_in_cb(struct urb *urb)
1465 unsigned long flags; 1380 unsigned long flags;
1466 u8 done = 0; 1381 u8 done = 0;
1467 1382
1468 d_fnstart(3, NULL, "(urb %p [%d])\n", urb, urb->status);
1469 switch (urb->status) { 1383 switch (urb->status) {
1470 case 0: 1384 case 0:
1471 spin_lock_irqsave(&xfer->lock, flags); 1385 spin_lock_irqsave(&xfer->lock, flags);
1472 wa = xfer->wa; 1386 wa = xfer->wa;
1473 dev = &wa->usb_iface->dev; 1387 dev = &wa->usb_iface->dev;
1474 rpipe = xfer->ep->hcpriv; 1388 rpipe = xfer->ep->hcpriv;
1475 d_printf(2, dev, "xfer %p#%u: data in done (%zu bytes)\n", 1389 dev_dbg(dev, "xfer %p#%u: data in done (%zu bytes)\n",
1476 xfer, seg->index, (size_t)urb->actual_length); 1390 xfer, seg->index, (size_t)urb->actual_length);
1477 seg->status = WA_SEG_DONE; 1391 seg->status = WA_SEG_DONE;
1478 seg->result = urb->actual_length; 1392 seg->result = urb->actual_length;
1479 xfer->segs_done++; 1393 xfer->segs_done++;
@@ -1514,7 +1428,6 @@ static void wa_buf_in_cb(struct urb *urb)
1514 if (rpipe_ready) 1428 if (rpipe_ready)
1515 wa_xfer_delayed_run(rpipe); 1429 wa_xfer_delayed_run(rpipe);
1516 } 1430 }
1517 d_fnend(3, NULL, "(urb %p [%d]) = void\n", urb, urb->status);
1518} 1431}
1519 1432
1520/* 1433/*
@@ -1553,14 +1466,12 @@ static void wa_xfer_result_cb(struct urb *urb)
1553 struct wa_xfer *xfer; 1466 struct wa_xfer *xfer;
1554 u8 usb_status; 1467 u8 usb_status;
1555 1468
1556 d_fnstart(3, dev, "(%p)\n", wa);
1557 BUG_ON(wa->dti_urb != urb); 1469 BUG_ON(wa->dti_urb != urb);
1558 switch (wa->dti_urb->status) { 1470 switch (wa->dti_urb->status) {
1559 case 0: 1471 case 0:
1560 /* We have a xfer result buffer; check it */ 1472 /* We have a xfer result buffer; check it */
1561 d_printf(2, dev, "DTI: xfer result %d bytes at %p\n", 1473 dev_dbg(dev, "DTI: xfer result %d bytes at %p\n",
1562 urb->actual_length, urb->transfer_buffer); 1474 urb->actual_length, urb->transfer_buffer);
1563 d_dump(3, dev, urb->transfer_buffer, urb->actual_length);
1564 if (wa->dti_urb->actual_length != sizeof(*xfer_result)) { 1475 if (wa->dti_urb->actual_length != sizeof(*xfer_result)) {
1565 dev_err(dev, "DTI Error: xfer result--bad size " 1476 dev_err(dev, "DTI Error: xfer result--bad size "
1566 "xfer result (%d bytes vs %zu needed)\n", 1477 "xfer result (%d bytes vs %zu needed)\n",
@@ -1622,7 +1533,6 @@ static void wa_xfer_result_cb(struct urb *urb)
1622 wa_reset_all(wa); 1533 wa_reset_all(wa);
1623 } 1534 }
1624out: 1535out:
1625 d_fnend(3, dev, "(%p) = void\n", wa);
1626 return; 1536 return;
1627} 1537}
1628 1538
@@ -1653,7 +1563,6 @@ void wa_handle_notif_xfer(struct wahc *wa, struct wa_notif_hdr *notif_hdr)
1653 struct wa_notif_xfer *notif_xfer; 1563 struct wa_notif_xfer *notif_xfer;
1654 const struct usb_endpoint_descriptor *dti_epd = wa->dti_epd; 1564 const struct usb_endpoint_descriptor *dti_epd = wa->dti_epd;
1655 1565
1656 d_fnstart(4, dev, "(%p, %p)\n", wa, notif_hdr);
1657 notif_xfer = container_of(notif_hdr, struct wa_notif_xfer, hdr); 1566 notif_xfer = container_of(notif_hdr, struct wa_notif_xfer, hdr);
1658 BUG_ON(notif_hdr->bNotifyType != WA_NOTIF_TRANSFER); 1567 BUG_ON(notif_hdr->bNotifyType != WA_NOTIF_TRANSFER);
1659 1568
@@ -1693,7 +1602,6 @@ void wa_handle_notif_xfer(struct wahc *wa, struct wa_notif_hdr *notif_hdr)
1693 goto error_dti_urb_submit; 1602 goto error_dti_urb_submit;
1694 } 1603 }
1695out: 1604out:
1696 d_fnend(4, dev, "(%p, %p) = void\n", wa, notif_hdr);
1697 return; 1605 return;
1698 1606
1699error_dti_urb_submit: 1607error_dti_urb_submit:
@@ -1704,6 +1612,4 @@ error_buf_in_urb_alloc:
1704error_dti_urb_alloc: 1612error_dti_urb_alloc:
1705error: 1613error:
1706 wa_reset_all(wa); 1614 wa_reset_all(wa);
1707 d_fnend(4, dev, "(%p, %p) = void\n", wa, notif_hdr);
1708 return;
1709} 1615}
diff --git a/drivers/usb/wusbcore/wusbhc.h b/drivers/usb/wusbcore/wusbhc.h
index d0c132434f1b..797c2453a35b 100644
--- a/drivers/usb/wusbcore/wusbhc.h
+++ b/drivers/usb/wusbcore/wusbhc.h
@@ -64,6 +64,13 @@
64#include <linux/uwb.h> 64#include <linux/uwb.h>
65#include <linux/usb/wusb.h> 65#include <linux/usb/wusb.h>
66 66
67/*
68 * Time from a WUSB channel stop request to the last transmitted MMC.
69 *
70 * This needs to be > 4.096 ms in case no MMCs can be transmitted in
71 * zone 0.
72 */
73#define WUSB_CHANNEL_STOP_DELAY_MS 8
67 74
68/** 75/**
69 * Wireless USB device 76 * Wireless USB device
@@ -147,7 +154,6 @@ struct wusb_port {
147 u16 status; 154 u16 status;
148 u16 change; 155 u16 change;
149 struct wusb_dev *wusb_dev; /* connected device's info */ 156 struct wusb_dev *wusb_dev; /* connected device's info */
150 unsigned reset_count;
151 u32 ptk_tkid; 157 u32 ptk_tkid;
152}; 158};
153 159
@@ -198,21 +204,18 @@ struct wusb_port {
198 * @mmcies_max Max number of Information Elements this HC can send 204 * @mmcies_max Max number of Information Elements this HC can send
199 * in its MMC. Read-only. 205 * in its MMC. Read-only.
200 * 206 *
207 * @start Start the WUSB channel.
208 *
209 * @stop Stop the WUSB channel after the specified number of
210 * milliseconds. Channel Stop IEs should be transmitted
211 * as required by [WUSB] 4.16.2.1.
212 *
201 * @mmcie_add HC specific operation (WHCI or HWA) for adding an 213 * @mmcie_add HC specific operation (WHCI or HWA) for adding an
202 * MMCIE. 214 * MMCIE.
203 * 215 *
204 * @mmcie_rm HC specific operation (WHCI or HWA) for removing an 216 * @mmcie_rm HC specific operation (WHCI or HWA) for removing an
205 * MMCIE. 217 * MMCIE.
206 * 218 *
207 * @enc_types Array which describes the encryptions methods
208 * supported by the host as described in WUSB1.0 --
209 * one entry per supported method. As of WUSB1.0 there
210 * is only four methods, we make space for eight just in
211 * case they decide to add some more (and pray they do
212 * it in sequential order). if 'enc_types[enc_method]
213 * != 0', then it is supported by the host. enc_method
214 * is USB_ENC_TYPE*.
215 *
216 * @set_ptk: Set the PTK and enable encryption for a device. Or, if 219 * @set_ptk: Set the PTK and enable encryption for a device. Or, if
217 * the supplied key is NULL, disable encryption for that 220 * the supplied key is NULL, disable encryption for that
218 * device. 221 * device.
@@ -249,7 +252,8 @@ struct wusbhc {
249 struct uwb_pal pal; 252 struct uwb_pal pal;
250 253
251 unsigned trust_timeout; /* in jiffies */ 254 unsigned trust_timeout; /* in jiffies */
252 struct wuie_host_info *wuie_host_info; /* Includes CHID */ 255 struct wusb_ckhdid chid;
256 struct wuie_host_info *wuie_host_info;
253 257
254 struct mutex mutex; /* locks everything else */ 258 struct mutex mutex; /* locks everything else */
255 u16 cluster_id; /* Wireless USB Cluster ID */ 259 u16 cluster_id; /* Wireless USB Cluster ID */
@@ -269,7 +273,7 @@ struct wusbhc {
269 u8 mmcies_max; 273 u8 mmcies_max;
270 /* FIXME: make wusbhc_ops? */ 274 /* FIXME: make wusbhc_ops? */
271 int (*start)(struct wusbhc *wusbhc); 275 int (*start)(struct wusbhc *wusbhc);
272 void (*stop)(struct wusbhc *wusbhc); 276 void (*stop)(struct wusbhc *wusbhc, int delay);
273 int (*mmcie_add)(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt, 277 int (*mmcie_add)(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt,
274 u8 handle, struct wuie_hdr *wuie); 278 u8 handle, struct wuie_hdr *wuie);
275 int (*mmcie_rm)(struct wusbhc *wusbhc, u8 handle); 279 int (*mmcie_rm)(struct wusbhc *wusbhc, u8 handle);
@@ -373,20 +377,17 @@ static inline void wusbhc_put(struct wusbhc *wusbhc)
373 usb_put_hcd(&wusbhc->usb_hcd); 377 usb_put_hcd(&wusbhc->usb_hcd);
374} 378}
375 379
376int wusbhc_start(struct wusbhc *wusbhc, const struct wusb_ckhdid *chid); 380int wusbhc_start(struct wusbhc *wusbhc);
377void wusbhc_stop(struct wusbhc *wusbhc); 381void wusbhc_stop(struct wusbhc *wusbhc);
378extern int wusbhc_chid_set(struct wusbhc *, const struct wusb_ckhdid *); 382extern int wusbhc_chid_set(struct wusbhc *, const struct wusb_ckhdid *);
379 383
380/* Device connect handling */ 384/* Device connect handling */
381extern int wusbhc_devconnect_create(struct wusbhc *); 385extern int wusbhc_devconnect_create(struct wusbhc *);
382extern void wusbhc_devconnect_destroy(struct wusbhc *); 386extern void wusbhc_devconnect_destroy(struct wusbhc *);
383extern int wusbhc_devconnect_start(struct wusbhc *wusbhc, 387extern int wusbhc_devconnect_start(struct wusbhc *wusbhc);
384 const struct wusb_ckhdid *chid);
385extern void wusbhc_devconnect_stop(struct wusbhc *wusbhc); 388extern void wusbhc_devconnect_stop(struct wusbhc *wusbhc);
386extern int wusbhc_devconnect_auth(struct wusbhc *, u8);
387extern void wusbhc_handle_dn(struct wusbhc *, u8 srcaddr, 389extern void wusbhc_handle_dn(struct wusbhc *, u8 srcaddr,
388 struct wusb_dn_hdr *dn_hdr, size_t size); 390 struct wusb_dn_hdr *dn_hdr, size_t size);
389extern int wusbhc_dev_reset(struct wusbhc *wusbhc, u8 port);
390extern void __wusbhc_dev_disable(struct wusbhc *wusbhc, u8 port); 391extern void __wusbhc_dev_disable(struct wusbhc *wusbhc, u8 port);
391extern int wusb_usb_ncb(struct notifier_block *nb, unsigned long val, 392extern int wusb_usb_ncb(struct notifier_block *nb, unsigned long val,
392 void *priv); 393 void *priv);
@@ -432,6 +433,7 @@ extern void wusb_dev_sec_rm(struct wusb_dev *) ;
432extern int wusb_dev_4way_handshake(struct wusbhc *, struct wusb_dev *, 433extern int wusb_dev_4way_handshake(struct wusbhc *, struct wusb_dev *,
433 struct wusb_ckhdid *ck); 434 struct wusb_ckhdid *ck);
434void wusbhc_gtk_rekey(struct wusbhc *wusbhc); 435void wusbhc_gtk_rekey(struct wusbhc *wusbhc);
436int wusb_dev_update_address(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev);
435 437
436 438
437/* WUSB Cluster ID handling */ 439/* WUSB Cluster ID handling */