aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/Kconfig11
-rw-r--r--drivers/usb/gadget/dummy_hcd.c745
-rw-r--r--drivers/usb/gadget/ether.c353
-rw-r--r--drivers/usb/gadget/file_storage.c61
-rw-r--r--drivers/usb/gadget/goku_udc.c28
-rw-r--r--drivers/usb/gadget/inode.c12
-rw-r--r--drivers/usb/gadget/ndis.h14
-rw-r--r--drivers/usb/gadget/net2280.c51
-rw-r--r--drivers/usb/gadget/omap_udc.c301
-rw-r--r--drivers/usb/gadget/omap_udc.h4
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c43
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.h10
-rw-r--r--drivers/usb/gadget/rndis.c515
-rw-r--r--drivers/usb/gadget/rndis.h95
-rw-r--r--drivers/usb/gadget/serial.c36
-rw-r--r--drivers/usb/gadget/zero.c6
16 files changed, 1279 insertions, 1006 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 3b24f9f2c234..ff075a53c8d6 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -53,6 +53,9 @@ config USB_GADGET_DEBUG_FILES
53 driver on a new board. Enable these files by choosing "Y" 53 driver on a new board. Enable these files by choosing "Y"
54 here. If in doubt, or to conserve kernel memory, say "N". 54 here. If in doubt, or to conserve kernel memory, say "N".
55 55
56config USB_GADGET_SELECTED
57 boolean
58
56# 59#
57# USB Peripheral Controller Support 60# USB Peripheral Controller Support
58# 61#
@@ -85,6 +88,7 @@ config USB_NET2280
85 tristate 88 tristate
86 depends on USB_GADGET_NET2280 89 depends on USB_GADGET_NET2280
87 default USB_GADGET 90 default USB_GADGET
91 select USB_GADGET_SELECTED
88 92
89config USB_GADGET_PXA2XX 93config USB_GADGET_PXA2XX
90 boolean "PXA 25x or IXP 4xx" 94 boolean "PXA 25x or IXP 4xx"
@@ -105,6 +109,7 @@ config USB_PXA2XX
105 tristate 109 tristate
106 depends on USB_GADGET_PXA2XX 110 depends on USB_GADGET_PXA2XX
107 default USB_GADGET 111 default USB_GADGET
112 select USB_GADGET_SELECTED
108 113
109# if there's only one gadget driver, using only two bulk endpoints, 114# if there's only one gadget driver, using only two bulk endpoints,
110# don't waste memory for the other endpoints 115# don't waste memory for the other endpoints
@@ -134,6 +139,7 @@ config USB_GOKU
134 tristate 139 tristate
135 depends on USB_GADGET_GOKU 140 depends on USB_GADGET_GOKU
136 default USB_GADGET 141 default USB_GADGET
142 select USB_GADGET_SELECTED
137 143
138 144
139config USB_GADGET_LH7A40X 145config USB_GADGET_LH7A40X
@@ -146,6 +152,7 @@ config USB_LH7A40X
146 tristate 152 tristate
147 depends on USB_GADGET_LH7A40X 153 depends on USB_GADGET_LH7A40X
148 default USB_GADGET 154 default USB_GADGET
155 select USB_GADGET_SELECTED
149 156
150 157
151config USB_GADGET_OMAP 158config USB_GADGET_OMAP
@@ -167,6 +174,7 @@ config USB_OMAP
167 tristate 174 tristate
168 depends on USB_GADGET_OMAP 175 depends on USB_GADGET_OMAP
169 default USB_GADGET 176 default USB_GADGET
177 select USB_GADGET_SELECTED
170 178
171config USB_OTG 179config USB_OTG
172 boolean "OTG Support" 180 boolean "OTG Support"
@@ -207,6 +215,7 @@ config USB_DUMMY_HCD
207 tristate 215 tristate
208 depends on USB_GADGET_DUMMY_HCD 216 depends on USB_GADGET_DUMMY_HCD
209 default USB_GADGET 217 default USB_GADGET
218 select USB_GADGET_SELECTED
210 219
211# NOTE: Please keep dummy_hcd LAST so that "real hardware" appears 220# NOTE: Please keep dummy_hcd LAST so that "real hardware" appears
212# first and will be selected by default. 221# first and will be selected by default.
@@ -226,7 +235,7 @@ config USB_GADGET_DUALSPEED
226# 235#
227choice 236choice
228 tristate "USB Gadget Drivers" 237 tristate "USB Gadget Drivers"
229 depends on USB_GADGET 238 depends on USB_GADGET && USB_GADGET_SELECTED
230 default USB_ETH 239 default USB_ETH
231 help 240 help
232 A Linux "Gadget Driver" talks to the USB Peripheral Controller 241 A Linux "Gadget Driver" talks to the USB Peripheral Controller
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index c039d2fbe7ab..4d692670f288 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -65,7 +65,7 @@
65 65
66 66
67#define DRIVER_DESC "USB Host+Gadget Emulator" 67#define DRIVER_DESC "USB Host+Gadget Emulator"
68#define DRIVER_VERSION "17 Dec 2004" 68#define DRIVER_VERSION "02 May 2005"
69 69
70static const char driver_name [] = "dummy_hcd"; 70static const char driver_name [] = "dummy_hcd";
71static const char driver_desc [] = "USB Host+Gadget Emulator"; 71static const char driver_desc [] = "USB Host+Gadget Emulator";
@@ -141,6 +141,8 @@ static const char *const ep_name [] = {
141}; 141};
142#define DUMMY_ENDPOINTS (sizeof(ep_name)/sizeof(char *)) 142#define DUMMY_ENDPOINTS (sizeof(ep_name)/sizeof(char *))
143 143
144/*-------------------------------------------------------------------------*/
145
144#define FIFO_SIZE 64 146#define FIFO_SIZE 64
145 147
146struct urbp { 148struct urbp {
@@ -148,6 +150,13 @@ struct urbp {
148 struct list_head urbp_list; 150 struct list_head urbp_list;
149}; 151};
150 152
153
154enum dummy_rh_state {
155 DUMMY_RH_RESET,
156 DUMMY_RH_SUSPENDED,
157 DUMMY_RH_RUNNING
158};
159
151struct dummy { 160struct dummy {
152 spinlock_t lock; 161 spinlock_t lock;
153 162
@@ -161,12 +170,18 @@ struct dummy {
161 struct dummy_request fifo_req; 170 struct dummy_request fifo_req;
162 u8 fifo_buf [FIFO_SIZE]; 171 u8 fifo_buf [FIFO_SIZE];
163 u16 devstatus; 172 u16 devstatus;
173 unsigned udc_suspended:1;
174 unsigned pullup:1;
175 unsigned active:1;
176 unsigned old_active:1;
164 177
165 /* 178 /*
166 * MASTER/HOST side support 179 * MASTER/HOST side support
167 */ 180 */
181 enum dummy_rh_state rh_state;
168 struct timer_list timer; 182 struct timer_list timer;
169 u32 port_status; 183 u32 port_status;
184 u32 old_status;
170 unsigned resuming:1; 185 unsigned resuming:1;
171 unsigned long re_timeout; 186 unsigned long re_timeout;
172 187
@@ -189,6 +204,11 @@ static inline struct device *dummy_dev (struct dummy *dum)
189 return dummy_to_hcd(dum)->self.controller; 204 return dummy_to_hcd(dum)->self.controller;
190} 205}
191 206
207static inline struct device *udc_dev (struct dummy *dum)
208{
209 return dum->gadget.dev.parent;
210}
211
192static inline struct dummy *ep_to_dummy (struct dummy_ep *ep) 212static inline struct dummy *ep_to_dummy (struct dummy_ep *ep)
193{ 213{
194 return container_of (ep->gadget, struct dummy, gadget); 214 return container_of (ep->gadget, struct dummy, gadget);
@@ -208,16 +228,98 @@ static struct dummy *the_controller;
208 228
209/*-------------------------------------------------------------------------*/ 229/*-------------------------------------------------------------------------*/
210 230
211/* 231/* SLAVE/GADGET SIDE UTILITY ROUTINES */
212 * This "hardware" may look a bit odd in diagnostics since it's got both
213 * host and device sides; and it binds different drivers to each side.
214 */
215static struct platform_device the_pdev;
216 232
217static struct device_driver dummy_driver = { 233/* called with spinlock held */
218 .name = (char *) driver_name, 234static void nuke (struct dummy *dum, struct dummy_ep *ep)
219 .bus = &platform_bus_type, 235{
220}; 236 while (!list_empty (&ep->queue)) {
237 struct dummy_request *req;
238
239 req = list_entry (ep->queue.next, struct dummy_request, queue);
240 list_del_init (&req->queue);
241 req->req.status = -ESHUTDOWN;
242
243 spin_unlock (&dum->lock);
244 req->req.complete (&ep->ep, &req->req);
245 spin_lock (&dum->lock);
246 }
247}
248
249/* caller must hold lock */
250static void
251stop_activity (struct dummy *dum)
252{
253 struct dummy_ep *ep;
254
255 /* prevent any more requests */
256 dum->address = 0;
257
258 /* The timer is left running so that outstanding URBs can fail */
259
260 /* nuke any pending requests first, so driver i/o is quiesced */
261 list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list)
262 nuke (dum, ep);
263
264 /* driver now does any non-usb quiescing necessary */
265}
266
267/* caller must hold lock */
268static void
269set_link_state (struct dummy *dum)
270{
271 dum->active = 0;
272 if ((dum->port_status & USB_PORT_STAT_POWER) == 0)
273 dum->port_status = 0;
274
275 /* UDC suspend must cause a disconnect */
276 else if (!dum->pullup || dum->udc_suspended) {
277 dum->port_status &= ~(USB_PORT_STAT_CONNECTION |
278 USB_PORT_STAT_ENABLE |
279 USB_PORT_STAT_LOW_SPEED |
280 USB_PORT_STAT_HIGH_SPEED |
281 USB_PORT_STAT_SUSPEND);
282 if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0)
283 dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16);
284 } else {
285 dum->port_status |= USB_PORT_STAT_CONNECTION;
286 if ((dum->old_status & USB_PORT_STAT_CONNECTION) == 0)
287 dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16);
288 if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0)
289 dum->port_status &= ~USB_PORT_STAT_SUSPEND;
290 else if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 &&
291 dum->rh_state != DUMMY_RH_SUSPENDED)
292 dum->active = 1;
293 }
294
295 if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0 || dum->active)
296 dum->resuming = 0;
297
298 if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0 ||
299 (dum->port_status & USB_PORT_STAT_RESET) != 0) {
300 if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0 &&
301 (dum->old_status & USB_PORT_STAT_RESET) == 0 &&
302 dum->driver) {
303 stop_activity (dum);
304 spin_unlock (&dum->lock);
305 dum->driver->disconnect (&dum->gadget);
306 spin_lock (&dum->lock);
307 }
308 } else if (dum->active != dum->old_active) {
309 if (dum->old_active && dum->driver->suspend) {
310 spin_unlock (&dum->lock);
311 dum->driver->suspend (&dum->gadget);
312 spin_lock (&dum->lock);
313 } else if (!dum->old_active && dum->driver->resume) {
314 spin_unlock (&dum->lock);
315 dum->driver->resume (&dum->gadget);
316 spin_lock (&dum->lock);
317 }
318 }
319
320 dum->old_status = dum->port_status;
321 dum->old_active = dum->active;
322}
221 323
222/*-------------------------------------------------------------------------*/ 324/*-------------------------------------------------------------------------*/
223 325
@@ -324,7 +426,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
324 _ep->maxpacket = max; 426 _ep->maxpacket = max;
325 ep->desc = desc; 427 ep->desc = desc;
326 428
327 dev_dbg (dummy_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n", 429 dev_dbg (udc_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n",
328 _ep->name, 430 _ep->name,
329 desc->bEndpointAddress & 0x0f, 431 desc->bEndpointAddress & 0x0f,
330 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 432 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
@@ -345,22 +447,6 @@ done:
345 return retval; 447 return retval;
346} 448}
347 449
348/* called with spinlock held */
349static void nuke (struct dummy *dum, struct dummy_ep *ep)
350{
351 while (!list_empty (&ep->queue)) {
352 struct dummy_request *req;
353
354 req = list_entry (ep->queue.next, struct dummy_request, queue);
355 list_del_init (&req->queue);
356 req->req.status = -ESHUTDOWN;
357
358 spin_unlock (&dum->lock);
359 req->req.complete (&ep->ep, &req->req);
360 spin_lock (&dum->lock);
361 }
362}
363
364static int dummy_disable (struct usb_ep *_ep) 450static int dummy_disable (struct usb_ep *_ep)
365{ 451{
366 struct dummy_ep *ep; 452 struct dummy_ep *ep;
@@ -379,7 +465,7 @@ static int dummy_disable (struct usb_ep *_ep)
379 nuke (dum, ep); 465 nuke (dum, ep);
380 spin_unlock_irqrestore (&dum->lock, flags); 466 spin_unlock_irqrestore (&dum->lock, flags);
381 467
382 dev_dbg (dummy_dev(dum), "disabled %s\n", _ep->name); 468 dev_dbg (udc_dev(dum), "disabled %s\n", _ep->name);
383 return retval; 469 return retval;
384} 470}
385 471
@@ -474,7 +560,7 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req, int mem_flags)
474 return -ESHUTDOWN; 560 return -ESHUTDOWN;
475 561
476#if 0 562#if 0
477 dev_dbg (dummy_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n", 563 dev_dbg (udc_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n",
478 ep, _req, _ep->name, _req->length, _req->buf); 564 ep, _req, _ep->name, _req->length, _req->buf);
479#endif 565#endif
480 566
@@ -537,7 +623,7 @@ static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req)
537 spin_unlock_irqrestore (&dum->lock, flags); 623 spin_unlock_irqrestore (&dum->lock, flags);
538 624
539 if (retval == 0) { 625 if (retval == 0) {
540 dev_dbg (dummy_dev(dum), 626 dev_dbg (udc_dev(dum),
541 "dequeued req %p from %s, len %d buf %p\n", 627 "dequeued req %p from %s, len %d buf %p\n",
542 req, _ep->name, _req->length, _req->buf); 628 req, _ep->name, _req->length, _req->buf);
543 _req->complete (_ep, _req); 629 _req->complete (_ep, _req);
@@ -601,13 +687,21 @@ static int dummy_wakeup (struct usb_gadget *_gadget)
601 struct dummy *dum; 687 struct dummy *dum;
602 688
603 dum = gadget_to_dummy (_gadget); 689 dum = gadget_to_dummy (_gadget);
604 if ((dum->devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) == 0 690 if (!(dum->devstatus & ( (1 << USB_DEVICE_B_HNP_ENABLE)
605 || !(dum->port_status & (1 << USB_PORT_FEAT_SUSPEND))) 691 | (1 << USB_DEVICE_REMOTE_WAKEUP))))
606 return -EINVAL; 692 return -EINVAL;
693 if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0)
694 return -ENOLINK;
695 if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 &&
696 dum->rh_state != DUMMY_RH_SUSPENDED)
697 return -EIO;
698
699 /* FIXME: What if the root hub is suspended but the port isn't? */
607 700
608 /* hub notices our request, issues downstream resume, etc */ 701 /* hub notices our request, issues downstream resume, etc */
609 dum->resuming = 1; 702 dum->resuming = 1;
610 dum->port_status |= (1 << USB_PORT_FEAT_C_SUSPEND); 703 dum->re_timeout = jiffies + msecs_to_jiffies(20);
704 mod_timer (&dummy_to_hcd (dum)->rh_timer, dum->re_timeout);
611 return 0; 705 return 0;
612} 706}
613 707
@@ -623,10 +717,26 @@ static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value)
623 return 0; 717 return 0;
624} 718}
625 719
720static int dummy_pullup (struct usb_gadget *_gadget, int value)
721{
722 struct dummy *dum;
723 unsigned long flags;
724
725 dum = gadget_to_dummy (_gadget);
726 spin_lock_irqsave (&dum->lock, flags);
727 dum->pullup = (value != 0);
728 set_link_state (dum);
729 spin_unlock_irqrestore (&dum->lock, flags);
730
731 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
732 return 0;
733}
734
626static const struct usb_gadget_ops dummy_ops = { 735static const struct usb_gadget_ops dummy_ops = {
627 .get_frame = dummy_g_get_frame, 736 .get_frame = dummy_g_get_frame,
628 .wakeup = dummy_wakeup, 737 .wakeup = dummy_wakeup,
629 .set_selfpowered = dummy_set_selfpowered, 738 .set_selfpowered = dummy_set_selfpowered,
739 .pullup = dummy_pullup,
630}; 740};
631 741
632/*-------------------------------------------------------------------------*/ 742/*-------------------------------------------------------------------------*/
@@ -641,7 +751,7 @@ show_function (struct device *dev, struct device_attribute *attr, char *buf)
641 return 0; 751 return 0;
642 return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function); 752 return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function);
643} 753}
644DEVICE_ATTR (function, S_IRUGO, show_function, NULL); 754static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
645 755
646/*-------------------------------------------------------------------------*/ 756/*-------------------------------------------------------------------------*/
647 757
@@ -659,38 +769,6 @@ DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
659 * for each driver that registers: just add to a big root hub. 769 * for each driver that registers: just add to a big root hub.
660 */ 770 */
661 771
662static void
663dummy_udc_release (struct device *dev)
664{
665}
666
667static void
668dummy_pdev_release (struct device *dev)
669{
670}
671
672static int
673dummy_register_udc (struct dummy *dum)
674{
675 int rc;
676
677 strcpy (dum->gadget.dev.bus_id, "udc");
678 dum->gadget.dev.parent = dummy_dev(dum);
679 dum->gadget.dev.release = dummy_udc_release;
680
681 rc = device_register (&dum->gadget.dev);
682 if (rc == 0)
683 device_create_file (&dum->gadget.dev, &dev_attr_function);
684 return rc;
685}
686
687static void
688dummy_unregister_udc (struct dummy *dum)
689{
690 device_remove_file (&dum->gadget.dev, &dev_attr_function);
691 device_unregister (&dum->gadget.dev);
692}
693
694int 772int
695usb_gadget_register_driver (struct usb_gadget_driver *driver) 773usb_gadget_register_driver (struct usb_gadget_driver *driver)
696{ 774{
@@ -709,12 +787,8 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
709 * SLAVE side init ... the layer above hardware, which 787 * SLAVE side init ... the layer above hardware, which
710 * can't enumerate without help from the driver we're binding. 788 * can't enumerate without help from the driver we're binding.
711 */ 789 */
712 dum->gadget.name = gadget_name;
713 dum->gadget.ops = &dummy_ops;
714 dum->gadget.is_dualspeed = 1;
715 790
716 dum->devstatus = 0; 791 dum->devstatus = 0;
717 dum->resuming = 0;
718 792
719 INIT_LIST_HEAD (&dum->gadget.ep_list); 793 INIT_LIST_HEAD (&dum->gadget.ep_list);
720 for (i = 0; i < DUMMY_ENDPOINTS; i++) { 794 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
@@ -740,7 +814,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
740 814
741 dum->driver = driver; 815 dum->driver = driver;
742 dum->gadget.dev.driver = &driver->driver; 816 dum->gadget.dev.driver = &driver->driver;
743 dev_dbg (dummy_dev(dum), "binding gadget driver '%s'\n", 817 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
744 driver->driver.name); 818 driver->driver.name);
745 if ((retval = driver->bind (&dum->gadget)) != 0) { 819 if ((retval = driver->bind (&dum->gadget)) != 0) {
746 dum->driver = NULL; 820 dum->driver = NULL;
@@ -748,42 +822,21 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
748 return retval; 822 return retval;
749 } 823 }
750 824
751 // FIXME: Check these calls for errors and re-order
752 driver->driver.bus = dum->gadget.dev.parent->bus; 825 driver->driver.bus = dum->gadget.dev.parent->bus;
753 driver_register (&driver->driver); 826 driver_register (&driver->driver);
754
755 device_bind_driver (&dum->gadget.dev); 827 device_bind_driver (&dum->gadget.dev);
756 828
757 /* khubd will enumerate this in a while */ 829 /* khubd will enumerate this in a while */
758 dum->port_status |= USB_PORT_STAT_CONNECTION 830 spin_lock_irq (&dum->lock);
759 | (1 << USB_PORT_FEAT_C_CONNECTION); 831 dum->pullup = 1;
832 set_link_state (dum);
833 spin_unlock_irq (&dum->lock);
834
835 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
760 return 0; 836 return 0;
761} 837}
762EXPORT_SYMBOL (usb_gadget_register_driver); 838EXPORT_SYMBOL (usb_gadget_register_driver);
763 839
764/* caller must hold lock */
765static void
766stop_activity (struct dummy *dum, struct usb_gadget_driver *driver)
767{
768 struct dummy_ep *ep;
769
770 /* prevent any more requests */
771 dum->address = 0;
772
773 /* The timer is left running so that outstanding URBs can fail */
774
775 /* nuke any pending requests first, so driver i/o is quiesced */
776 list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list)
777 nuke (dum, ep);
778
779 /* driver now does any non-usb quiescing necessary */
780 if (driver) {
781 spin_unlock (&dum->lock);
782 driver->disconnect (&dum->gadget);
783 spin_lock (&dum->lock);
784 }
785}
786
787int 840int
788usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 841usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
789{ 842{
@@ -795,35 +848,138 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
795 if (!driver || driver != dum->driver) 848 if (!driver || driver != dum->driver)
796 return -EINVAL; 849 return -EINVAL;
797 850
798 dev_dbg (dummy_dev(dum), "unregister gadget driver '%s'\n", 851 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n",
799 driver->driver.name); 852 driver->driver.name);
800 853
801 spin_lock_irqsave (&dum->lock, flags); 854 spin_lock_irqsave (&dum->lock, flags);
802 stop_activity (dum, driver); 855 dum->pullup = 0;
803 dum->port_status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | 856 set_link_state (dum);
804 USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED);
805 dum->port_status |= (1 << USB_PORT_FEAT_C_CONNECTION);
806 spin_unlock_irqrestore (&dum->lock, flags); 857 spin_unlock_irqrestore (&dum->lock, flags);
807 858
808 driver->unbind (&dum->gadget); 859 driver->unbind (&dum->gadget);
809 dum->driver = NULL; 860 dum->driver = NULL;
810 861
811 device_release_driver (&dum->gadget.dev); 862 device_release_driver (&dum->gadget.dev);
812
813 driver_unregister (&driver->driver); 863 driver_unregister (&driver->driver);
814 864
865 spin_lock_irqsave (&dum->lock, flags);
866 dum->pullup = 0;
867 set_link_state (dum);
868 spin_unlock_irqrestore (&dum->lock, flags);
869
870 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
815 return 0; 871 return 0;
816} 872}
817EXPORT_SYMBOL (usb_gadget_unregister_driver); 873EXPORT_SYMBOL (usb_gadget_unregister_driver);
818 874
819#undef is_enabled 875#undef is_enabled
820 876
877/* just declare this in any driver that really need it */
878extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode);
879
821int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode) 880int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode)
822{ 881{
823 return -ENOSYS; 882 return -ENOSYS;
824} 883}
825EXPORT_SYMBOL (net2280_set_fifo_mode); 884EXPORT_SYMBOL (net2280_set_fifo_mode);
826 885
886
887/* The gadget structure is stored inside the hcd structure and will be
888 * released along with it. */
889static void
890dummy_gadget_release (struct device *dev)
891{
892#if 0 /* usb_bus_put isn't EXPORTed! */
893 struct dummy *dum = gadget_dev_to_dummy (dev);
894
895 usb_bus_put (&dummy_to_hcd (dum)->self);
896#endif
897}
898
899static int dummy_udc_probe (struct device *dev)
900{
901 struct dummy *dum = the_controller;
902 int rc;
903
904 dum->gadget.name = gadget_name;
905 dum->gadget.ops = &dummy_ops;
906 dum->gadget.is_dualspeed = 1;
907
908 /* maybe claim OTG support, though we won't complete HNP */
909 dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0);
910
911 strcpy (dum->gadget.dev.bus_id, "gadget");
912 dum->gadget.dev.parent = dev;
913 dum->gadget.dev.release = dummy_gadget_release;
914 rc = device_register (&dum->gadget.dev);
915 if (rc < 0)
916 return rc;
917
918#if 0 /* usb_bus_get isn't EXPORTed! */
919 usb_bus_get (&dummy_to_hcd (dum)->self);
920#endif
921
922 dev_set_drvdata (dev, dum);
923 device_create_file (&dum->gadget.dev, &dev_attr_function);
924 return rc;
925}
926
927static int dummy_udc_remove (struct device *dev)
928{
929 struct dummy *dum = dev_get_drvdata (dev);
930
931 dev_set_drvdata (dev, NULL);
932 device_remove_file (&dum->gadget.dev, &dev_attr_function);
933 device_unregister (&dum->gadget.dev);
934 return 0;
935}
936
937static int dummy_udc_suspend (struct device *dev, pm_message_t state,
938 u32 level)
939{
940 struct dummy *dum = dev_get_drvdata(dev);
941
942 if (level != SUSPEND_DISABLE)
943 return 0;
944
945 dev_dbg (dev, "%s\n", __FUNCTION__);
946 spin_lock_irq (&dum->lock);
947 dum->udc_suspended = 1;
948 set_link_state (dum);
949 spin_unlock_irq (&dum->lock);
950
951 dev->power.power_state = state;
952 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
953 return 0;
954}
955
956static int dummy_udc_resume (struct device *dev, u32 level)
957{
958 struct dummy *dum = dev_get_drvdata(dev);
959
960 if (level != RESUME_ENABLE)
961 return 0;
962
963 dev_dbg (dev, "%s\n", __FUNCTION__);
964 spin_lock_irq (&dum->lock);
965 dum->udc_suspended = 0;
966 set_link_state (dum);
967 spin_unlock_irq (&dum->lock);
968
969 dev->power.power_state = PMSG_ON;
970 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
971 return 0;
972}
973
974static struct device_driver dummy_udc_driver = {
975 .name = (char *) gadget_name,
976 .bus = &platform_bus_type,
977 .probe = dummy_udc_probe,
978 .remove = dummy_udc_remove,
979 .suspend = dummy_udc_suspend,
980 .resume = dummy_udc_resume,
981};
982
827/*-------------------------------------------------------------------------*/ 983/*-------------------------------------------------------------------------*/
828 984
829/* MASTER/HOST SIDE DRIVER 985/* MASTER/HOST SIDE DRIVER
@@ -880,7 +1036,16 @@ static int dummy_urb_enqueue (
880 1036
881static int dummy_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 1037static int dummy_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
882{ 1038{
883 /* giveback happens automatically in timer callback */ 1039 struct dummy *dum;
1040 unsigned long flags;
1041
1042 /* giveback happens automatically in timer callback,
1043 * so make sure the callback happens */
1044 dum = hcd_to_dummy (hcd);
1045 spin_lock_irqsave (&dum->lock, flags);
1046 if (dum->rh_state != DUMMY_RH_RUNNING && !list_empty(&dum->urbp_list))
1047 mod_timer (&dum->timer, jiffies);
1048 spin_unlock_irqrestore (&dum->lock, flags);
884 return 0; 1049 return 0;
885} 1050}
886 1051
@@ -1025,7 +1190,6 @@ static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep)
1025 1190
1026 /* high bandwidth mode */ 1191 /* high bandwidth mode */
1027 tmp = le16_to_cpu(ep->desc->wMaxPacketSize); 1192 tmp = le16_to_cpu(ep->desc->wMaxPacketSize);
1028 tmp = le16_to_cpu (tmp);
1029 tmp = (tmp >> 11) & 0x03; 1193 tmp = (tmp >> 11) & 0x03;
1030 tmp *= 8 /* applies to entire frame */; 1194 tmp *= 8 /* applies to entire frame */;
1031 limit += limit * tmp; 1195 limit += limit * tmp;
@@ -1123,7 +1287,8 @@ restart:
1123 if (urb->status != -EINPROGRESS) { 1287 if (urb->status != -EINPROGRESS) {
1124 /* likely it was just unlinked */ 1288 /* likely it was just unlinked */
1125 goto return_urb; 1289 goto return_urb;
1126 } 1290 } else if (dum->rh_state != DUMMY_RH_RUNNING)
1291 continue;
1127 type = usb_pipetype (urb->pipe); 1292 type = usb_pipetype (urb->pipe);
1128 1293
1129 /* used up this frame's non-periodic bandwidth? 1294 /* used up this frame's non-periodic bandwidth?
@@ -1168,12 +1333,14 @@ restart:
1168 struct usb_ctrlrequest setup; 1333 struct usb_ctrlrequest setup;
1169 int value = 1; 1334 int value = 1;
1170 struct dummy_ep *ep2; 1335 struct dummy_ep *ep2;
1336 unsigned w_index;
1337 unsigned w_value;
1171 1338
1172 setup = *(struct usb_ctrlrequest*) urb->setup_packet; 1339 setup = *(struct usb_ctrlrequest*) urb->setup_packet;
1173 le16_to_cpus (&setup.wIndex); 1340 w_index = le16_to_cpu(setup.wIndex);
1174 le16_to_cpus (&setup.wValue); 1341 w_value = le16_to_cpu(setup.wValue);
1175 le16_to_cpus (&setup.wLength); 1342 if (le16_to_cpu(setup.wLength) !=
1176 if (setup.wLength != urb->transfer_buffer_length) { 1343 urb->transfer_buffer_length) {
1177 maybe_set_status (urb, -EOVERFLOW); 1344 maybe_set_status (urb, -EOVERFLOW);
1178 goto return_urb; 1345 goto return_urb;
1179 } 1346 }
@@ -1182,7 +1349,7 @@ restart:
1182 list_for_each_entry (req, &ep->queue, queue) { 1349 list_for_each_entry (req, &ep->queue, queue) {
1183 list_del_init (&req->queue); 1350 list_del_init (&req->queue);
1184 req->req.status = -EOVERFLOW; 1351 req->req.status = -EOVERFLOW;
1185 dev_dbg (dummy_dev(dum), "stale req = %p\n", 1352 dev_dbg (udc_dev(dum), "stale req = %p\n",
1186 req); 1353 req);
1187 1354
1188 spin_unlock (&dum->lock); 1355 spin_unlock (&dum->lock);
@@ -1203,31 +1370,40 @@ restart:
1203 case USB_REQ_SET_ADDRESS: 1370 case USB_REQ_SET_ADDRESS:
1204 if (setup.bRequestType != Dev_Request) 1371 if (setup.bRequestType != Dev_Request)
1205 break; 1372 break;
1206 dum->address = setup.wValue; 1373 dum->address = w_value;
1207 maybe_set_status (urb, 0); 1374 maybe_set_status (urb, 0);
1208 dev_dbg (dummy_dev(dum), "set_address = %d\n", 1375 dev_dbg (udc_dev(dum), "set_address = %d\n",
1209 setup.wValue); 1376 w_value);
1210 value = 0; 1377 value = 0;
1211 break; 1378 break;
1212 case USB_REQ_SET_FEATURE: 1379 case USB_REQ_SET_FEATURE:
1213 if (setup.bRequestType == Dev_Request) { 1380 if (setup.bRequestType == Dev_Request) {
1214 value = 0; 1381 value = 0;
1215 switch (setup.wValue) { 1382 switch (w_value) {
1216 case USB_DEVICE_REMOTE_WAKEUP: 1383 case USB_DEVICE_REMOTE_WAKEUP:
1217 break; 1384 break;
1385 case USB_DEVICE_B_HNP_ENABLE:
1386 dum->gadget.b_hnp_enable = 1;
1387 break;
1388 case USB_DEVICE_A_HNP_SUPPORT:
1389 dum->gadget.a_hnp_support = 1;
1390 break;
1391 case USB_DEVICE_A_ALT_HNP_SUPPORT:
1392 dum->gadget.a_alt_hnp_support
1393 = 1;
1394 break;
1218 default: 1395 default:
1219 value = -EOPNOTSUPP; 1396 value = -EOPNOTSUPP;
1220 } 1397 }
1221 if (value == 0) { 1398 if (value == 0) {
1222 dum->devstatus |= 1399 dum->devstatus |=
1223 (1 << setup.wValue); 1400 (1 << w_value);
1224 maybe_set_status (urb, 0); 1401 maybe_set_status (urb, 0);
1225 } 1402 }
1226 1403
1227 } else if (setup.bRequestType == Ep_Request) { 1404 } else if (setup.bRequestType == Ep_Request) {
1228 // endpoint halt 1405 // endpoint halt
1229 ep2 = find_endpoint (dum, 1406 ep2 = find_endpoint (dum, w_index);
1230 setup.wIndex);
1231 if (!ep2) { 1407 if (!ep2) {
1232 value = -EOPNOTSUPP; 1408 value = -EOPNOTSUPP;
1233 break; 1409 break;
@@ -1239,7 +1415,7 @@ restart:
1239 break; 1415 break;
1240 case USB_REQ_CLEAR_FEATURE: 1416 case USB_REQ_CLEAR_FEATURE:
1241 if (setup.bRequestType == Dev_Request) { 1417 if (setup.bRequestType == Dev_Request) {
1242 switch (setup.wValue) { 1418 switch (w_value) {
1243 case USB_DEVICE_REMOTE_WAKEUP: 1419 case USB_DEVICE_REMOTE_WAKEUP:
1244 dum->devstatus &= ~(1 << 1420 dum->devstatus &= ~(1 <<
1245 USB_DEVICE_REMOTE_WAKEUP); 1421 USB_DEVICE_REMOTE_WAKEUP);
@@ -1252,8 +1428,7 @@ restart:
1252 } 1428 }
1253 } else if (setup.bRequestType == Ep_Request) { 1429 } else if (setup.bRequestType == Ep_Request) {
1254 // endpoint halt 1430 // endpoint halt
1255 ep2 = find_endpoint (dum, 1431 ep2 = find_endpoint (dum, w_index);
1256 setup.wIndex);
1257 if (!ep2) { 1432 if (!ep2) {
1258 value = -EOPNOTSUPP; 1433 value = -EOPNOTSUPP;
1259 break; 1434 break;
@@ -1279,7 +1454,7 @@ restart:
1279 if (urb->transfer_buffer_length > 0) { 1454 if (urb->transfer_buffer_length > 0) {
1280 if (setup.bRequestType == 1455 if (setup.bRequestType ==
1281 Ep_InRequest) { 1456 Ep_InRequest) {
1282 ep2 = find_endpoint (dum, setup.wIndex); 1457 ep2 = find_endpoint (dum, w_index);
1283 if (!ep2) { 1458 if (!ep2) {
1284 value = -EOPNOTSUPP; 1459 value = -EOPNOTSUPP;
1285 break; 1460 break;
@@ -1321,7 +1496,7 @@ restart:
1321 1496
1322 if (value < 0) { 1497 if (value < 0) {
1323 if (value != -EOPNOTSUPP) 1498 if (value != -EOPNOTSUPP)
1324 dev_dbg (dummy_dev(dum), 1499 dev_dbg (udc_dev(dum),
1325 "setup --> %d\n", 1500 "setup --> %d\n",
1326 value); 1501 value);
1327 maybe_set_status (urb, -EPIPE); 1502 maybe_set_status (urb, -EPIPE);
@@ -1377,12 +1552,12 @@ return_urb:
1377 goto restart; 1552 goto restart;
1378 } 1553 }
1379 1554
1380 /* want a 1 msec delay here */ 1555 if (list_empty (&dum->urbp_list)) {
1381 if (!list_empty (&dum->urbp_list))
1382 mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1));
1383 else {
1384 usb_put_dev (dum->udev); 1556 usb_put_dev (dum->udev);
1385 dum->udev = NULL; 1557 dum->udev = NULL;
1558 } else if (dum->rh_state == DUMMY_RH_RUNNING) {
1559 /* want a 1 msec delay here */
1560 mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1));
1386 } 1561 }
1387 1562
1388 spin_unlock_irqrestore (&dum->lock, flags); 1563 spin_unlock_irqrestore (&dum->lock, flags);
@@ -1391,29 +1566,39 @@ return_urb:
1391/*-------------------------------------------------------------------------*/ 1566/*-------------------------------------------------------------------------*/
1392 1567
1393#define PORT_C_MASK \ 1568#define PORT_C_MASK \
1394 ((1 << USB_PORT_FEAT_C_CONNECTION) \ 1569 ((USB_PORT_STAT_C_CONNECTION \
1395 | (1 << USB_PORT_FEAT_C_ENABLE) \ 1570 | USB_PORT_STAT_C_ENABLE \
1396 | (1 << USB_PORT_FEAT_C_SUSPEND) \ 1571 | USB_PORT_STAT_C_SUSPEND \
1397 | (1 << USB_PORT_FEAT_C_OVER_CURRENT) \ 1572 | USB_PORT_STAT_C_OVERCURRENT \
1398 | (1 << USB_PORT_FEAT_C_RESET)) 1573 | USB_PORT_STAT_C_RESET) << 16)
1399 1574
1400static int dummy_hub_status (struct usb_hcd *hcd, char *buf) 1575static int dummy_hub_status (struct usb_hcd *hcd, char *buf)
1401{ 1576{
1402 struct dummy *dum; 1577 struct dummy *dum;
1403 unsigned long flags; 1578 unsigned long flags;
1404 int retval; 1579 int retval = 0;
1405 1580
1406 dum = hcd_to_dummy (hcd); 1581 dum = hcd_to_dummy (hcd);
1407 1582
1408 spin_lock_irqsave (&dum->lock, flags); 1583 spin_lock_irqsave (&dum->lock, flags);
1409 if (!(dum->port_status & PORT_C_MASK)) 1584 if (hcd->state != HC_STATE_RUNNING)
1410 retval = 0; 1585 goto done;
1411 else { 1586
1587 if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) {
1588 dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16);
1589 dum->port_status &= ~USB_PORT_STAT_SUSPEND;
1590 set_link_state (dum);
1591 }
1592
1593 if ((dum->port_status & PORT_C_MASK) != 0) {
1412 *buf = (1 << 1); 1594 *buf = (1 << 1);
1413 dev_dbg (dummy_dev(dum), "port status 0x%08x has changes\n", 1595 dev_dbg (dummy_dev(dum), "port status 0x%08x has changes\n",
1414 dum->port_status); 1596 dum->port_status);
1415 retval = 1; 1597 retval = 1;
1598 if (dum->rh_state == DUMMY_RH_SUSPENDED)
1599 usb_hcd_resume_root_hub (hcd);
1416 } 1600 }
1601done:
1417 spin_unlock_irqrestore (&dum->lock, flags); 1602 spin_unlock_irqrestore (&dum->lock, flags);
1418 return retval; 1603 return retval;
1419} 1604}
@@ -1424,7 +1609,8 @@ hub_descriptor (struct usb_hub_descriptor *desc)
1424 memset (desc, 0, sizeof *desc); 1609 memset (desc, 0, sizeof *desc);
1425 desc->bDescriptorType = 0x29; 1610 desc->bDescriptorType = 0x29;
1426 desc->bDescLength = 9; 1611 desc->bDescLength = 9;
1427 desc->wHubCharacteristics = __constant_cpu_to_le16 (0x0001); 1612 desc->wHubCharacteristics = (__force __u16)
1613 (__constant_cpu_to_le16 (0x0001));
1428 desc->bNbrPorts = 1; 1614 desc->bNbrPorts = 1;
1429 desc->bitmap [0] = 0xff; 1615 desc->bitmap [0] = 0xff;
1430 desc->bitmap [1] = 0xff; 1616 desc->bitmap [1] = 0xff;
@@ -1442,6 +1628,9 @@ static int dummy_hub_control (
1442 int retval = 0; 1628 int retval = 0;
1443 unsigned long flags; 1629 unsigned long flags;
1444 1630
1631 if (hcd->state != HC_STATE_RUNNING)
1632 return -ETIMEDOUT;
1633
1445 dum = hcd_to_dummy (hcd); 1634 dum = hcd_to_dummy (hcd);
1446 spin_lock_irqsave (&dum->lock, flags); 1635 spin_lock_irqsave (&dum->lock, flags);
1447 switch (typeReq) { 1636 switch (typeReq) {
@@ -1450,27 +1639,27 @@ static int dummy_hub_control (
1450 case ClearPortFeature: 1639 case ClearPortFeature:
1451 switch (wValue) { 1640 switch (wValue) {
1452 case USB_PORT_FEAT_SUSPEND: 1641 case USB_PORT_FEAT_SUSPEND:
1453 if (dum->port_status & (1 << USB_PORT_FEAT_SUSPEND)) { 1642 if (dum->port_status & USB_PORT_STAT_SUSPEND) {
1454 /* 20msec resume signaling */ 1643 /* 20msec resume signaling */
1455 dum->resuming = 1; 1644 dum->resuming = 1;
1456 dum->re_timeout = jiffies + 1645 dum->re_timeout = jiffies +
1457 msecs_to_jiffies(20); 1646 msecs_to_jiffies(20);
1458 } 1647 }
1459 break; 1648 break;
1460 case USB_PORT_FEAT_POWER: 1649 case USB_PORT_FEAT_POWER:
1461 dum->port_status = 0; 1650 if (dum->port_status & USB_PORT_STAT_POWER)
1462 dum->resuming = 0; 1651 dev_dbg (dummy_dev(dum), "power-off\n");
1463 stop_activity(dum, dum->driver); 1652 /* FALLS THROUGH */
1464 break;
1465 default: 1653 default:
1466 dum->port_status &= ~(1 << wValue); 1654 dum->port_status &= ~(1 << wValue);
1655 set_link_state (dum);
1467 } 1656 }
1468 break; 1657 break;
1469 case GetHubDescriptor: 1658 case GetHubDescriptor:
1470 hub_descriptor ((struct usb_hub_descriptor *) buf); 1659 hub_descriptor ((struct usb_hub_descriptor *) buf);
1471 break; 1660 break;
1472 case GetHubStatus: 1661 case GetHubStatus:
1473 *(u32 *) buf = __constant_cpu_to_le32 (0); 1662 *(__le32 *) buf = __constant_cpu_to_le32 (0);
1474 break; 1663 break;
1475 case GetPortStatus: 1664 case GetPortStatus:
1476 if (wIndex != 1) 1665 if (wIndex != 1)
@@ -1479,23 +1668,16 @@ static int dummy_hub_control (
1479 /* whoever resets or resumes must GetPortStatus to 1668 /* whoever resets or resumes must GetPortStatus to
1480 * complete it!! 1669 * complete it!!
1481 */ 1670 */
1482 if (dum->resuming && time_after (jiffies, dum->re_timeout)) { 1671 if (dum->resuming &&
1483 dum->port_status |= (1 << USB_PORT_FEAT_C_SUSPEND); 1672 time_after_eq (jiffies, dum->re_timeout)) {
1484 dum->port_status &= ~(1 << USB_PORT_FEAT_SUSPEND); 1673 dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16);
1485 dum->resuming = 0; 1674 dum->port_status &= ~USB_PORT_STAT_SUSPEND;
1486 dum->re_timeout = 0;
1487 if (dum->driver && dum->driver->resume) {
1488 spin_unlock (&dum->lock);
1489 dum->driver->resume (&dum->gadget);
1490 spin_lock (&dum->lock);
1491 }
1492 } 1675 }
1493 if ((dum->port_status & (1 << USB_PORT_FEAT_RESET)) != 0 1676 if ((dum->port_status & USB_PORT_STAT_RESET) != 0 &&
1494 && time_after (jiffies, dum->re_timeout)) { 1677 time_after_eq (jiffies, dum->re_timeout)) {
1495 dum->port_status |= (1 << USB_PORT_FEAT_C_RESET); 1678 dum->port_status |= (USB_PORT_STAT_C_RESET << 16);
1496 dum->port_status &= ~(1 << USB_PORT_FEAT_RESET); 1679 dum->port_status &= ~USB_PORT_STAT_RESET;
1497 dum->re_timeout = 0; 1680 if (dum->pullup) {
1498 if (dum->driver) {
1499 dum->port_status |= USB_PORT_STAT_ENABLE; 1681 dum->port_status |= USB_PORT_STAT_ENABLE;
1500 /* give it the best speed we agree on */ 1682 /* give it the best speed we agree on */
1501 dum->gadget.speed = dum->driver->speed; 1683 dum->gadget.speed = dum->driver->speed;
@@ -1516,8 +1698,9 @@ static int dummy_hub_control (
1516 } 1698 }
1517 } 1699 }
1518 } 1700 }
1519 ((u16 *) buf)[0] = cpu_to_le16 (dum->port_status); 1701 set_link_state (dum);
1520 ((u16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16); 1702 ((__le16 *) buf)[0] = cpu_to_le16 (dum->port_status);
1703 ((__le16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16);
1521 break; 1704 break;
1522 case SetHubFeature: 1705 case SetHubFeature:
1523 retval = -EPIPE; 1706 retval = -EPIPE;
@@ -1525,36 +1708,37 @@ static int dummy_hub_control (
1525 case SetPortFeature: 1708 case SetPortFeature:
1526 switch (wValue) { 1709 switch (wValue) {
1527 case USB_PORT_FEAT_SUSPEND: 1710 case USB_PORT_FEAT_SUSPEND:
1528 if ((dum->port_status & (1 << USB_PORT_FEAT_SUSPEND)) 1711 if (dum->active) {
1529 == 0) { 1712 dum->port_status |= USB_PORT_STAT_SUSPEND;
1530 dum->port_status |= 1713
1531 (1 << USB_PORT_FEAT_SUSPEND); 1714 /* HNP would happen here; for now we
1532 if (dum->driver && dum->driver->suspend) { 1715 * assume b_bus_req is always true.
1533 spin_unlock (&dum->lock); 1716 */
1534 dum->driver->suspend (&dum->gadget); 1717 set_link_state (dum);
1535 spin_lock (&dum->lock); 1718 if (((1 << USB_DEVICE_B_HNP_ENABLE)
1536 } 1719 & dum->devstatus) != 0)
1720 dev_dbg (dummy_dev(dum),
1721 "no HNP yet!\n");
1537 } 1722 }
1538 break; 1723 break;
1724 case USB_PORT_FEAT_POWER:
1725 dum->port_status |= USB_PORT_STAT_POWER;
1726 set_link_state (dum);
1727 break;
1539 case USB_PORT_FEAT_RESET: 1728 case USB_PORT_FEAT_RESET:
1540 /* if it's already running, disconnect first */ 1729 /* if it's already enabled, disable */
1541 if (dum->port_status & USB_PORT_STAT_ENABLE) { 1730 dum->port_status &= ~(USB_PORT_STAT_ENABLE
1542 dum->port_status &= ~(USB_PORT_STAT_ENABLE 1731 | USB_PORT_STAT_LOW_SPEED
1543 | USB_PORT_STAT_LOW_SPEED 1732 | USB_PORT_STAT_HIGH_SPEED);
1544 | USB_PORT_STAT_HIGH_SPEED); 1733 dum->devstatus = 0;
1545 if (dum->driver) {
1546 dev_dbg (dummy_dev(dum),
1547 "disconnect\n");
1548 stop_activity (dum, dum->driver);
1549 }
1550
1551 /* FIXME test that code path! */
1552 }
1553 /* 50msec reset signaling */ 1734 /* 50msec reset signaling */
1554 dum->re_timeout = jiffies + msecs_to_jiffies(50); 1735 dum->re_timeout = jiffies + msecs_to_jiffies(50);
1555 /* FALLTHROUGH */ 1736 /* FALLS THROUGH */
1556 default: 1737 default:
1557 dum->port_status |= (1 << wValue); 1738 if ((dum->port_status & USB_PORT_STAT_POWER) != 0) {
1739 dum->port_status |= (1 << wValue);
1740 set_link_state (dum);
1741 }
1558 } 1742 }
1559 break; 1743 break;
1560 1744
@@ -1567,9 +1751,35 @@ static int dummy_hub_control (
1567 retval = -EPIPE; 1751 retval = -EPIPE;
1568 } 1752 }
1569 spin_unlock_irqrestore (&dum->lock, flags); 1753 spin_unlock_irqrestore (&dum->lock, flags);
1754
1755 if ((dum->port_status & PORT_C_MASK) != 0)
1756 usb_hcd_poll_rh_status (hcd);
1570 return retval; 1757 return retval;
1571} 1758}
1572 1759
1760static int dummy_hub_suspend (struct usb_hcd *hcd)
1761{
1762 struct dummy *dum = hcd_to_dummy (hcd);
1763
1764 spin_lock_irq (&dum->lock);
1765 dum->rh_state = DUMMY_RH_SUSPENDED;
1766 set_link_state (dum);
1767 spin_unlock_irq (&dum->lock);
1768 return 0;
1769}
1770
1771static int dummy_hub_resume (struct usb_hcd *hcd)
1772{
1773 struct dummy *dum = hcd_to_dummy (hcd);
1774
1775 spin_lock_irq (&dum->lock);
1776 dum->rh_state = DUMMY_RH_RUNNING;
1777 set_link_state (dum);
1778 if (!list_empty(&dum->urbp_list))
1779 mod_timer (&dum->timer, jiffies);
1780 spin_unlock_irq (&dum->lock);
1781 return 0;
1782}
1573 1783
1574/*-------------------------------------------------------------------------*/ 1784/*-------------------------------------------------------------------------*/
1575 1785
@@ -1625,8 +1835,6 @@ static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL);
1625static int dummy_start (struct usb_hcd *hcd) 1835static int dummy_start (struct usb_hcd *hcd)
1626{ 1836{
1627 struct dummy *dum; 1837 struct dummy *dum;
1628 struct usb_device *root;
1629 int retval;
1630 1838
1631 dum = hcd_to_dummy (hcd); 1839 dum = hcd_to_dummy (hcd);
1632 1840
@@ -1639,38 +1847,22 @@ static int dummy_start (struct usb_hcd *hcd)
1639 init_timer (&dum->timer); 1847 init_timer (&dum->timer);
1640 dum->timer.function = dummy_timer; 1848 dum->timer.function = dummy_timer;
1641 dum->timer.data = (unsigned long) dum; 1849 dum->timer.data = (unsigned long) dum;
1850 dum->rh_state = DUMMY_RH_RUNNING;
1642 1851
1643 INIT_LIST_HEAD (&dum->urbp_list); 1852 INIT_LIST_HEAD (&dum->urbp_list);
1644 1853
1645 root = usb_alloc_dev (NULL, &hcd->self, 0);
1646 if (!root)
1647 return -ENOMEM;
1648
1649 /* root hub enters addressed state... */
1650 hcd->state = HC_STATE_RUNNING;
1651 root->speed = USB_SPEED_HIGH;
1652
1653 /* ...then configured, so khubd sees us. */
1654 if ((retval = usb_hcd_register_root_hub (root, hcd)) != 0) {
1655 goto err1;
1656 }
1657
1658 /* only show a low-power port: just 8mA */ 1854 /* only show a low-power port: just 8mA */
1659 hub_set_power_budget (root, 8); 1855 hcd->power_budget = 8;
1856 hcd->state = HC_STATE_RUNNING;
1857 hcd->uses_new_polling = 1;
1660 1858
1661 if ((retval = dummy_register_udc (dum)) != 0) 1859#ifdef CONFIG_USB_OTG
1662 goto err2; 1860 hcd->self.otg_port = 1;
1861#endif
1663 1862
1664 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */ 1863 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */
1665 device_create_file (dummy_dev(dum), &dev_attr_urbs); 1864 device_create_file (dummy_dev(dum), &dev_attr_urbs);
1666 return 0; 1865 return 0;
1667
1668 err2:
1669 usb_disconnect (&hcd->self.root_hub);
1670 err1:
1671 usb_put_dev (root);
1672 hcd->state = HC_STATE_QUIESCING;
1673 return retval;
1674} 1866}
1675 1867
1676static void dummy_stop (struct usb_hcd *hcd) 1868static void dummy_stop (struct usb_hcd *hcd)
@@ -1680,10 +1872,7 @@ static void dummy_stop (struct usb_hcd *hcd)
1680 dum = hcd_to_dummy (hcd); 1872 dum = hcd_to_dummy (hcd);
1681 1873
1682 device_remove_file (dummy_dev(dum), &dev_attr_urbs); 1874 device_remove_file (dummy_dev(dum), &dev_attr_urbs);
1683
1684 usb_gadget_unregister_driver (dum->driver); 1875 usb_gadget_unregister_driver (dum->driver);
1685 dummy_unregister_udc (dum);
1686
1687 dev_info (dummy_dev(dum), "stopped\n"); 1876 dev_info (dummy_dev(dum), "stopped\n");
1688} 1877}
1689 1878
@@ -1711,9 +1900,11 @@ static const struct hc_driver dummy_hcd = {
1711 1900
1712 .hub_status_data = dummy_hub_status, 1901 .hub_status_data = dummy_hub_status,
1713 .hub_control = dummy_hub_control, 1902 .hub_control = dummy_hub_control,
1903 .hub_suspend = dummy_hub_suspend,
1904 .hub_resume = dummy_hub_resume,
1714}; 1905};
1715 1906
1716static int dummy_probe (struct device *dev) 1907static int dummy_hcd_probe (struct device *dev)
1717{ 1908{
1718 struct usb_hcd *hcd; 1909 struct usb_hcd *hcd;
1719 int retval; 1910 int retval;
@@ -1733,7 +1924,7 @@ static int dummy_probe (struct device *dev)
1733 return retval; 1924 return retval;
1734} 1925}
1735 1926
1736static void dummy_remove (struct device *dev) 1927static int dummy_hcd_remove (struct device *dev)
1737{ 1928{
1738 struct usb_hcd *hcd; 1929 struct usb_hcd *hcd;
1739 1930
@@ -1741,53 +1932,127 @@ static void dummy_remove (struct device *dev)
1741 usb_remove_hcd (hcd); 1932 usb_remove_hcd (hcd);
1742 usb_put_hcd (hcd); 1933 usb_put_hcd (hcd);
1743 the_controller = NULL; 1934 the_controller = NULL;
1935 return 0;
1744} 1936}
1745 1937
1746/*-------------------------------------------------------------------------*/ 1938static int dummy_hcd_suspend (struct device *dev, pm_message_t state,
1747 1939 u32 level)
1748static int dummy_pdev_detect (void)
1749{ 1940{
1750 int retval; 1941 struct usb_hcd *hcd;
1751 1942
1752 retval = driver_register (&dummy_driver); 1943 if (level != SUSPEND_DISABLE)
1753 if (retval < 0) 1944 return 0;
1754 return retval; 1945
1946 dev_dbg (dev, "%s\n", __FUNCTION__);
1947 hcd = dev_get_drvdata (dev);
1755 1948
1756 the_pdev.name = "hc"; 1949#ifndef CONFIG_USB_SUSPEND
1757 the_pdev.dev.driver = &dummy_driver; 1950 /* Otherwise this would never happen */
1758 the_pdev.dev.release = dummy_pdev_release; 1951 usb_lock_device (hcd->self.root_hub);
1952 dummy_hub_suspend (hcd);
1953 usb_unlock_device (hcd->self.root_hub);
1954#endif
1759 1955
1760 retval = platform_device_register (&the_pdev); 1956 hcd->state = HC_STATE_SUSPENDED;
1761 if (retval < 0) 1957 return 0;
1762 driver_unregister (&dummy_driver);
1763 return retval;
1764} 1958}
1765 1959
1766static void dummy_pdev_remove (void) 1960static int dummy_hcd_resume (struct device *dev, u32 level)
1767{ 1961{
1768 platform_device_unregister (&the_pdev); 1962 struct usb_hcd *hcd;
1769 driver_unregister (&dummy_driver); 1963
1964 if (level != RESUME_ENABLE)
1965 return 0;
1966
1967 dev_dbg (dev, "%s\n", __FUNCTION__);
1968 hcd = dev_get_drvdata (dev);
1969 hcd->state = HC_STATE_RUNNING;
1970
1971#ifndef CONFIG_USB_SUSPEND
1972 /* Otherwise this would never happen */
1973 usb_lock_device (hcd->self.root_hub);
1974 dummy_hub_resume (hcd);
1975 usb_unlock_device (hcd->self.root_hub);
1976#endif
1977
1978 usb_hcd_poll_rh_status (hcd);
1979 return 0;
1770} 1980}
1771 1981
1982static struct device_driver dummy_hcd_driver = {
1983 .name = (char *) driver_name,
1984 .bus = &platform_bus_type,
1985 .probe = dummy_hcd_probe,
1986 .remove = dummy_hcd_remove,
1987 .suspend = dummy_hcd_suspend,
1988 .resume = dummy_hcd_resume,
1989};
1990
1772/*-------------------------------------------------------------------------*/ 1991/*-------------------------------------------------------------------------*/
1773 1992
1993/* These don't need to do anything because the pdev structures are
1994 * statically allocated. */
1995static void
1996dummy_udc_release (struct device *dev) {}
1997
1998static void
1999dummy_hcd_release (struct device *dev) {}
2000
2001static struct platform_device the_udc_pdev = {
2002 .name = (char *) gadget_name,
2003 .id = -1,
2004 .dev = {
2005 .release = dummy_udc_release,
2006 },
2007};
2008
2009static struct platform_device the_hcd_pdev = {
2010 .name = (char *) driver_name,
2011 .id = -1,
2012 .dev = {
2013 .release = dummy_hcd_release,
2014 },
2015};
2016
1774static int __init init (void) 2017static int __init init (void)
1775{ 2018{
1776 int retval; 2019 int retval;
1777 2020
1778 if (usb_disabled ()) 2021 if (usb_disabled ())
1779 return -ENODEV; 2022 return -ENODEV;
1780 if ((retval = dummy_pdev_detect ()) != 0) 2023
2024 retval = driver_register (&dummy_hcd_driver);
2025 if (retval < 0)
1781 return retval; 2026 return retval;
1782 if ((retval = dummy_probe (&the_pdev.dev)) != 0) 2027
1783 dummy_pdev_remove (); 2028 retval = driver_register (&dummy_udc_driver);
2029 if (retval < 0)
2030 goto err_register_udc_driver;
2031
2032 retval = platform_device_register (&the_hcd_pdev);
2033 if (retval < 0)
2034 goto err_register_hcd;
2035
2036 retval = platform_device_register (&the_udc_pdev);
2037 if (retval < 0)
2038 goto err_register_udc;
2039 return retval;
2040
2041err_register_udc:
2042 platform_device_unregister (&the_hcd_pdev);
2043err_register_hcd:
2044 driver_unregister (&dummy_udc_driver);
2045err_register_udc_driver:
2046 driver_unregister (&dummy_hcd_driver);
1784 return retval; 2047 return retval;
1785} 2048}
1786module_init (init); 2049module_init (init);
1787 2050
1788static void __exit cleanup (void) 2051static void __exit cleanup (void)
1789{ 2052{
1790 dummy_remove (&the_pdev.dev); 2053 platform_device_unregister (&the_udc_pdev);
1791 dummy_pdev_remove (); 2054 platform_device_unregister (&the_hcd_pdev);
2055 driver_unregister (&dummy_udc_driver);
2056 driver_unregister (&dummy_hcd_driver);
1792} 2057}
1793module_exit (cleanup); 2058module_exit (cleanup);
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 3f783cbdc7c3..5bb53ae88969 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -84,18 +84,19 @@
84 */ 84 */
85 85
86#define DRIVER_DESC "Ethernet Gadget" 86#define DRIVER_DESC "Ethernet Gadget"
87#define DRIVER_VERSION "Equinox 2004" 87#define DRIVER_VERSION "May Day 2005"
88 88
89static const char shortname [] = "ether"; 89static const char shortname [] = "ether";
90static const char driver_desc [] = DRIVER_DESC; 90static const char driver_desc [] = DRIVER_DESC;
91 91
92#define RX_EXTRA 20 /* guard against rx overflows */ 92#define RX_EXTRA 20 /* guard against rx overflows */
93 93
94#ifdef CONFIG_USB_ETH_RNDIS
95#include "rndis.h" 94#include "rndis.h"
96#else 95
97#define rndis_init() 0 96#ifndef CONFIG_USB_ETH_RNDIS
98#define rndis_exit() do{}while(0) 97#define rndis_uninit(x) do{}while(0)
98#define rndis_deregister(c) do{}while(0)
99#define rndis_exit() do{}while(0)
99#endif 100#endif
100 101
101/* CDC and RNDIS support the same host-chosen outgoing packet filters. */ 102/* CDC and RNDIS support the same host-chosen outgoing packet filters. */
@@ -140,9 +141,6 @@ struct eth_dev {
140 * It also ASSUMES a self-powered device, without remote wakeup, 141 * It also ASSUMES a self-powered device, without remote wakeup,
141 * although remote wakeup support would make sense. 142 * although remote wakeup support would make sense.
142 */ 143 */
143static const char *EP_IN_NAME;
144static const char *EP_OUT_NAME;
145static const char *EP_STATUS_NAME;
146 144
147/*-------------------------------------------------------------------------*/ 145/*-------------------------------------------------------------------------*/
148 146
@@ -312,6 +310,7 @@ static inline int rndis_active(struct eth_dev *dev)
312#define FS_BPS (19 * 64 * 1 * 1000 * 8) 310#define FS_BPS (19 * 64 * 1 * 1000 * 8)
313 311
314#ifdef CONFIG_USB_GADGET_DUALSPEED 312#ifdef CONFIG_USB_GADGET_DUALSPEED
313#define DEVSPEED USB_SPEED_HIGH
315 314
316static unsigned qmult = 5; 315static unsigned qmult = 5;
317module_param (qmult, uint, S_IRUGO|S_IWUSR); 316module_param (qmult, uint, S_IRUGO|S_IWUSR);
@@ -330,6 +329,8 @@ static inline int BITRATE(struct usb_gadget *g)
330} 329}
331 330
332#else /* full speed (low speed doesn't do bulk) */ 331#else /* full speed (low speed doesn't do bulk) */
332#define DEVSPEED USB_SPEED_FULL
333
333#define qlen(gadget) DEFAULT_QLEN 334#define qlen(gadget) DEFAULT_QLEN
334 335
335static inline int BITRATE(struct usb_gadget *g) 336static inline int BITRATE(struct usb_gadget *g)
@@ -395,7 +396,8 @@ static inline int BITRATE(struct usb_gadget *g)
395#define STRING_SUBSET 8 396#define STRING_SUBSET 8
396#define STRING_RNDIS 9 397#define STRING_RNDIS 9
397 398
398#define USB_BUFSIZ 256 /* holds our biggest descriptor */ 399/* holds our biggest descriptor (or RNDIS response) */
400#define USB_BUFSIZ 256
399 401
400/* 402/*
401 * This device advertises one configuration, eth_config, unless RNDIS 403 * This device advertises one configuration, eth_config, unless RNDIS
@@ -538,7 +540,7 @@ static const struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor = {
538 .bDataInterface = 0x01, 540 .bDataInterface = 0x01,
539}; 541};
540 542
541static struct usb_cdc_acm_descriptor acm_descriptor = { 543static const struct usb_cdc_acm_descriptor acm_descriptor = {
542 .bLength = sizeof acm_descriptor, 544 .bLength = sizeof acm_descriptor,
543 .bDescriptorType = USB_DT_CS_INTERFACE, 545 .bDescriptorType = USB_DT_CS_INTERFACE,
544 .bDescriptorSubType = USB_CDC_ACM_TYPE, 546 .bDescriptorSubType = USB_CDC_ACM_TYPE,
@@ -846,7 +848,7 @@ static const struct usb_descriptor_header *hs_rndis_function [] = {
846#else 848#else
847 849
848/* if there's no high speed support, maxpacket doesn't change. */ 850/* if there's no high speed support, maxpacket doesn't change. */
849#define ep_desc(g,hs,fs) fs 851#define ep_desc(g,hs,fs) (((void)(g)), (fs))
850 852
851static inline void __init hs_subset_descriptors(void) 853static inline void __init hs_subset_descriptors(void)
852{ 854{
@@ -946,10 +948,31 @@ config_buf (enum usb_device_speed speed,
946static void eth_start (struct eth_dev *dev, int gfp_flags); 948static void eth_start (struct eth_dev *dev, int gfp_flags);
947static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags); 949static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags);
948 950
949#ifdef DEV_CONFIG_CDC 951static int
950static inline int ether_alt_ep_setup (struct eth_dev *dev, struct usb_ep *ep) 952set_ether_config (struct eth_dev *dev, int gfp_flags)
951{ 953{
952 const struct usb_endpoint_descriptor *d; 954 int result = 0;
955 struct usb_gadget *gadget = dev->gadget;
956
957 /* status endpoint used for RNDIS and (optionally) CDC */
958 if (!subset_active(dev) && dev->status_ep) {
959 dev->status = ep_desc (gadget, &hs_status_desc,
960 &fs_status_desc);
961 dev->status_ep->driver_data = dev;
962
963 result = usb_ep_enable (dev->status_ep, dev->status);
964 if (result != 0) {
965 DEBUG (dev, "enable %s --> %d\n",
966 dev->status_ep->name, result);
967 goto done;
968 }
969 }
970
971 dev->in = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc);
972 dev->in_ep->driver_data = dev;
973
974 dev->out = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc);
975 dev->out_ep->driver_data = dev;
953 976
954 /* With CDC, the host isn't allowed to use these two data 977 /* With CDC, the host isn't allowed to use these two data
955 * endpoints in the default altsetting for the interface. 978 * endpoints in the default altsetting for the interface.
@@ -959,135 +982,33 @@ static inline int ether_alt_ep_setup (struct eth_dev *dev, struct usb_ep *ep)
959 * a side effect of setting a packet filter. Deactivation is 982 * a side effect of setting a packet filter. Deactivation is
960 * from REMOTE_NDIS_HALT_MSG, reset from REMOTE_NDIS_RESET_MSG. 983 * from REMOTE_NDIS_HALT_MSG, reset from REMOTE_NDIS_RESET_MSG.
961 */ 984 */
962 985 if (!cdc_active(dev)) {
963 /* one endpoint writes data back IN to the host */ 986 result = usb_ep_enable (dev->in_ep, dev->in);
964 if (strcmp (ep->name, EP_IN_NAME) == 0) { 987 if (result != 0) {
965 d = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); 988 DEBUG(dev, "enable %s --> %d\n",
966 ep->driver_data = dev; 989 dev->in_ep->name, result);
967 dev->in = d; 990 goto done;
968
969 /* one endpoint just reads OUT packets */
970 } else if (strcmp (ep->name, EP_OUT_NAME) == 0) {
971 d = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc);
972 ep->driver_data = dev;
973 dev->out = d;
974
975 /* optional status/notification endpoint */
976 } else if (EP_STATUS_NAME &&
977 strcmp (ep->name, EP_STATUS_NAME) == 0) {
978 int result;
979
980 d = ep_desc (dev->gadget, &hs_status_desc, &fs_status_desc);
981 result = usb_ep_enable (ep, d);
982 if (result < 0)
983 return result;
984
985 ep->driver_data = dev;
986 dev->status = d;
987 }
988 return 0;
989}
990#endif
991
992#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS)
993static inline int ether_ep_setup (struct eth_dev *dev, struct usb_ep *ep)
994{
995 int result;
996 const struct usb_endpoint_descriptor *d;
997
998 /* CDC subset is simpler: if the device is there,
999 * it's live with rx and tx endpoints.
1000 *
1001 * Do this as a shortcut for RNDIS too.
1002 */
1003
1004 /* one endpoint writes data back IN to the host */
1005 if (strcmp (ep->name, EP_IN_NAME) == 0) {
1006 d = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc);
1007 result = usb_ep_enable (ep, d);
1008 if (result < 0)
1009 return result;
1010
1011 ep->driver_data = dev;
1012 dev->in = d;
1013
1014 /* one endpoint just reads OUT packets */
1015 } else if (strcmp (ep->name, EP_OUT_NAME) == 0) {
1016 d = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc);
1017 result = usb_ep_enable (ep, d);
1018 if (result < 0)
1019 return result;
1020
1021 ep->driver_data = dev;
1022 dev->out = d;
1023 }
1024
1025 return 0;
1026}
1027#endif
1028
1029static int
1030set_ether_config (struct eth_dev *dev, int gfp_flags)
1031{
1032 int result = 0;
1033 struct usb_ep *ep;
1034 struct usb_gadget *gadget = dev->gadget;
1035
1036 gadget_for_each_ep (ep, gadget) {
1037#ifdef DEV_CONFIG_CDC
1038 if (!dev->rndis && dev->cdc) {
1039 result = ether_alt_ep_setup (dev, ep);
1040 if (result == 0)
1041 continue;
1042 } 991 }
1043#endif
1044
1045#ifdef CONFIG_USB_ETH_RNDIS
1046 if (dev->rndis && strcmp (ep->name, EP_STATUS_NAME) == 0) {
1047 const struct usb_endpoint_descriptor *d;
1048 d = ep_desc (gadget, &hs_status_desc, &fs_status_desc);
1049 result = usb_ep_enable (ep, d);
1050 if (result == 0) {
1051 ep->driver_data = dev;
1052 dev->status = d;
1053 continue;
1054 }
1055 } else
1056#endif
1057 992
1058 { 993 result = usb_ep_enable (dev->out_ep, dev->out);
1059#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 994 if (result != 0) {
1060 result = ether_ep_setup (dev, ep); 995 DEBUG (dev, "enable %s --> %d\n",
1061 if (result == 0) 996 dev->in_ep->name, result);
1062 continue; 997 goto done;
1063#endif
1064 } 998 }
1065
1066 /* stop on error */
1067 ERROR (dev, "can't enable %s, result %d\n", ep->name, result);
1068 break;
1069 } 999 }
1070 if (!result && (!dev->in_ep || !dev->out_ep))
1071 result = -ENODEV;
1072 1000
1001done:
1073 if (result == 0) 1002 if (result == 0)
1074 result = alloc_requests (dev, qlen (gadget), gfp_flags); 1003 result = alloc_requests (dev, qlen (gadget), gfp_flags);
1075 1004
1076 /* on error, disable any endpoints */ 1005 /* on error, disable any endpoints */
1077 if (result < 0) { 1006 if (result < 0) {
1078#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 1007 if (!subset_active(dev))
1079 if (dev->status)
1080 (void) usb_ep_disable (dev->status_ep); 1008 (void) usb_ep_disable (dev->status_ep);
1081#endif
1082 dev->status = NULL; 1009 dev->status = NULL;
1083#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 1010 (void) usb_ep_disable (dev->in_ep);
1084 if (dev->rndis || !dev->cdc) { 1011 (void) usb_ep_disable (dev->out_ep);
1085 if (dev->in)
1086 (void) usb_ep_disable (dev->in_ep);
1087 if (dev->out)
1088 (void) usb_ep_disable (dev->out_ep);
1089 }
1090#endif
1091 dev->in = NULL; 1012 dev->in = NULL;
1092 dev->out = NULL; 1013 dev->out = NULL;
1093 } else 1014 } else
@@ -1095,8 +1016,7 @@ set_ether_config (struct eth_dev *dev, int gfp_flags)
1095 /* activate non-CDC configs right away 1016 /* activate non-CDC configs right away
1096 * this isn't strictly according to the RNDIS spec 1017 * this isn't strictly according to the RNDIS spec
1097 */ 1018 */
1098#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 1019 if (!cdc_active (dev)) {
1099 if (dev->rndis || !dev->cdc) {
1100 netif_carrier_on (dev->net); 1020 netif_carrier_on (dev->net);
1101 if (netif_running (dev->net)) { 1021 if (netif_running (dev->net)) {
1102 spin_unlock (&dev->lock); 1022 spin_unlock (&dev->lock);
@@ -1104,7 +1024,6 @@ set_ether_config (struct eth_dev *dev, int gfp_flags)
1104 spin_lock (&dev->lock); 1024 spin_lock (&dev->lock);
1105 } 1025 }
1106 } 1026 }
1107#endif
1108 1027
1109 if (result == 0) 1028 if (result == 0)
1110 DEBUG (dev, "qlen %d\n", qlen (gadget)); 1029 DEBUG (dev, "qlen %d\n", qlen (gadget));
@@ -1124,6 +1043,7 @@ static void eth_reset_config (struct eth_dev *dev)
1124 1043
1125 netif_stop_queue (dev->net); 1044 netif_stop_queue (dev->net);
1126 netif_carrier_off (dev->net); 1045 netif_carrier_off (dev->net);
1046 rndis_uninit(dev->rndis_config);
1127 1047
1128 /* disable endpoints, forcing (synchronous) completion of 1048 /* disable endpoints, forcing (synchronous) completion of
1129 * pending i/o. then free the requests. 1049 * pending i/o. then free the requests.
@@ -1150,6 +1070,8 @@ static void eth_reset_config (struct eth_dev *dev)
1150 if (dev->status) { 1070 if (dev->status) {
1151 usb_ep_disable (dev->status_ep); 1071 usb_ep_disable (dev->status_ep);
1152 } 1072 }
1073 dev->rndis = 0;
1074 dev->cdc_filter = 0;
1153 dev->config = 0; 1075 dev->config = 0;
1154} 1076}
1155 1077
@@ -1162,9 +1084,6 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
1162 int result = 0; 1084 int result = 0;
1163 struct usb_gadget *gadget = dev->gadget; 1085 struct usb_gadget *gadget = dev->gadget;
1164 1086
1165 if (number == dev->config)
1166 return 0;
1167
1168 if (gadget_is_sa1100 (gadget) 1087 if (gadget_is_sa1100 (gadget)
1169 && dev->config 1088 && dev->config
1170 && atomic_read (&dev->tx_qlen) != 0) { 1089 && atomic_read (&dev->tx_qlen) != 0) {
@@ -1174,12 +1093,8 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
1174 } 1093 }
1175 eth_reset_config (dev); 1094 eth_reset_config (dev);
1176 1095
1177 /* default: pass all packets, no multicast filtering */
1178 dev->cdc_filter = DEFAULT_FILTER;
1179
1180 switch (number) { 1096 switch (number) {
1181 case DEV_CONFIG_VALUE: 1097 case DEV_CONFIG_VALUE:
1182 dev->rndis = 0;
1183 result = set_ether_config (dev, gfp_flags); 1098 result = set_ether_config (dev, gfp_flags);
1184 break; 1099 break;
1185#ifdef CONFIG_USB_ETH_RNDIS 1100#ifdef CONFIG_USB_ETH_RNDIS
@@ -1218,9 +1133,9 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
1218 dev->config = number; 1133 dev->config = number;
1219 INFO (dev, "%s speed config #%d: %d mA, %s, using %s\n", 1134 INFO (dev, "%s speed config #%d: %d mA, %s, using %s\n",
1220 speed, number, power, driver_desc, 1135 speed, number, power, driver_desc,
1221 dev->rndis 1136 rndis_active(dev)
1222 ? "RNDIS" 1137 ? "RNDIS"
1223 : (dev->cdc 1138 : (cdc_active(dev)
1224 ? "CDC Ethernet" 1139 ? "CDC Ethernet"
1225 : "CDC Ethernet Subset")); 1140 : "CDC Ethernet Subset"));
1226 } 1141 }
@@ -1231,6 +1146,13 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
1231 1146
1232#ifdef DEV_CONFIG_CDC 1147#ifdef DEV_CONFIG_CDC
1233 1148
1149/* The interrupt endpoint is used in CDC networking models (Ethernet, ATM)
1150 * only to notify the host about link status changes (which we support) or
1151 * report completion of some encapsulated command (as used in RNDIS). Since
1152 * we want this CDC Ethernet code to be vendor-neutral, we don't use that
1153 * command mechanism; and only one status request is ever queued.
1154 */
1155
1234static void eth_status_complete (struct usb_ep *ep, struct usb_request *req) 1156static void eth_status_complete (struct usb_ep *ep, struct usb_request *req)
1235{ 1157{
1236 struct usb_cdc_notification *event = req->buf; 1158 struct usb_cdc_notification *event = req->buf;
@@ -1259,7 +1181,7 @@ static void eth_status_complete (struct usb_ep *ep, struct usb_request *req)
1259 } else if (value != -ECONNRESET) 1181 } else if (value != -ECONNRESET)
1260 DEBUG (dev, "event %02x --> %d\n", 1182 DEBUG (dev, "event %02x --> %d\n",
1261 event->bNotificationType, value); 1183 event->bNotificationType, value);
1262 event->bmRequestType = 0xff; 1184 req->context = NULL;
1263} 1185}
1264 1186
1265static void issue_start_status (struct eth_dev *dev) 1187static void issue_start_status (struct eth_dev *dev)
@@ -1276,6 +1198,8 @@ static void issue_start_status (struct eth_dev *dev)
1276 * a "cancel the whole queue" primitive since any 1198 * a "cancel the whole queue" primitive since any
1277 * unlink-one primitive has way too many error modes. 1199 * unlink-one primitive has way too many error modes.
1278 * here, we "know" toggle is already clear... 1200 * here, we "know" toggle is already clear...
1201 *
1202 * FIXME iff req->context != null just dequeue it
1279 */ 1203 */
1280 usb_ep_disable (dev->status_ep); 1204 usb_ep_disable (dev->status_ep);
1281 usb_ep_enable (dev->status_ep, dev->status); 1205 usb_ep_enable (dev->status_ep, dev->status);
@@ -1292,6 +1216,8 @@ static void issue_start_status (struct eth_dev *dev)
1292 1216
1293 req->length = sizeof *event; 1217 req->length = sizeof *event;
1294 req->complete = eth_status_complete; 1218 req->complete = eth_status_complete;
1219 req->context = dev;
1220
1295 value = usb_ep_queue (dev->status_ep, req, GFP_ATOMIC); 1221 value = usb_ep_queue (dev->status_ep, req, GFP_ATOMIC);
1296 if (value < 0) 1222 if (value < 0)
1297 DEBUG (dev, "status buf queue --> %d\n", value); 1223 DEBUG (dev, "status buf queue --> %d\n", value);
@@ -1351,9 +1277,9 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1351 struct eth_dev *dev = get_gadget_data (gadget); 1277 struct eth_dev *dev = get_gadget_data (gadget);
1352 struct usb_request *req = dev->req; 1278 struct usb_request *req = dev->req;
1353 int value = -EOPNOTSUPP; 1279 int value = -EOPNOTSUPP;
1354 u16 wIndex = (__force u16) ctrl->wIndex; 1280 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1355 u16 wValue = (__force u16) ctrl->wValue; 1281 u16 wValue = le16_to_cpu(ctrl->wValue);
1356 u16 wLength = (__force u16) ctrl->wLength; 1282 u16 wLength = le16_to_cpu(ctrl->wLength);
1357 1283
1358 /* descriptors just go into the pre-allocated ep0 buffer, 1284 /* descriptors just go into the pre-allocated ep0 buffer,
1359 * while config change events may enable network traffic. 1285 * while config change events may enable network traffic.
@@ -1424,7 +1350,7 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1424 || !dev->config 1350 || !dev->config
1425 || wIndex > 1) 1351 || wIndex > 1)
1426 break; 1352 break;
1427 if (!dev->cdc && wIndex != 0) 1353 if (!cdc_active(dev) && wIndex != 0)
1428 break; 1354 break;
1429 spin_lock (&dev->lock); 1355 spin_lock (&dev->lock);
1430 1356
@@ -1456,9 +1382,11 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1456 1382
1457 /* CDC requires the data transfers not be done from 1383 /* CDC requires the data transfers not be done from
1458 * the default interface setting ... also, setting 1384 * the default interface setting ... also, setting
1459 * the non-default interface clears filters etc. 1385 * the non-default interface resets filters etc.
1460 */ 1386 */
1461 if (wValue == 1) { 1387 if (wValue == 1) {
1388 if (!cdc_active (dev))
1389 break;
1462 usb_ep_enable (dev->in_ep, dev->in); 1390 usb_ep_enable (dev->in_ep, dev->in);
1463 usb_ep_enable (dev->out_ep, dev->out); 1391 usb_ep_enable (dev->out_ep, dev->out);
1464 dev->cdc_filter = DEFAULT_FILTER; 1392 dev->cdc_filter = DEFAULT_FILTER;
@@ -1492,11 +1420,11 @@ done_set_intf:
1492 || !dev->config 1420 || !dev->config
1493 || wIndex > 1) 1421 || wIndex > 1)
1494 break; 1422 break;
1495 if (!(dev->cdc || dev->rndis) && wIndex != 0) 1423 if (!(cdc_active(dev) || rndis_active(dev)) && wIndex != 0)
1496 break; 1424 break;
1497 1425
1498 /* for CDC, iff carrier is on, data interface is active. */ 1426 /* for CDC, iff carrier is on, data interface is active. */
1499 if (dev->rndis || wIndex != 1) 1427 if (rndis_active(dev) || wIndex != 1)
1500 *(u8 *)req->buf = 0; 1428 *(u8 *)req->buf = 0;
1501 else 1429 else
1502 *(u8 *)req->buf = netif_carrier_ok (dev->net) ? 1 : 0; 1430 *(u8 *)req->buf = netif_carrier_ok (dev->net) ? 1 : 0;
@@ -1509,8 +1437,7 @@ done_set_intf:
1509 * wValue = packet filter bitmap 1437 * wValue = packet filter bitmap
1510 */ 1438 */
1511 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) 1439 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1512 || !dev->cdc 1440 || !cdc_active(dev)
1513 || dev->rndis
1514 || wLength != 0 1441 || wLength != 0
1515 || wIndex > 1) 1442 || wIndex > 1)
1516 break; 1443 break;
@@ -1534,7 +1461,7 @@ done_set_intf:
1534 */ 1461 */
1535 case USB_CDC_SEND_ENCAPSULATED_COMMAND: 1462 case USB_CDC_SEND_ENCAPSULATED_COMMAND:
1536 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) 1463 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1537 || !dev->rndis 1464 || !rndis_active(dev)
1538 || wLength > USB_BUFSIZ 1465 || wLength > USB_BUFSIZ
1539 || wValue 1466 || wValue
1540 || rndis_control_intf.bInterfaceNumber 1467 || rndis_control_intf.bInterfaceNumber
@@ -1549,7 +1476,7 @@ done_set_intf:
1549 case USB_CDC_GET_ENCAPSULATED_RESPONSE: 1476 case USB_CDC_GET_ENCAPSULATED_RESPONSE:
1550 if ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE) 1477 if ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1551 == ctrl->bRequestType 1478 == ctrl->bRequestType
1552 && dev->rndis 1479 && rndis_active(dev)
1553 // && wLength >= 0x0400 1480 // && wLength >= 0x0400
1554 && !wValue 1481 && !wValue
1555 && rndis_control_intf.bInterfaceNumber 1482 && rndis_control_intf.bInterfaceNumber
@@ -1688,10 +1615,8 @@ rx_submit (struct eth_dev *dev, struct usb_request *req, int gfp_flags)
1688 */ 1615 */
1689 size = (sizeof (struct ethhdr) + dev->net->mtu + RX_EXTRA); 1616 size = (sizeof (struct ethhdr) + dev->net->mtu + RX_EXTRA);
1690 size += dev->out_ep->maxpacket - 1; 1617 size += dev->out_ep->maxpacket - 1;
1691#ifdef CONFIG_USB_ETH_RNDIS 1618 if (rndis_active(dev))
1692 if (dev->rndis)
1693 size += sizeof (struct rndis_packet_msg_type); 1619 size += sizeof (struct rndis_packet_msg_type);
1694#endif
1695 size -= size % dev->out_ep->maxpacket; 1620 size -= size % dev->out_ep->maxpacket;
1696 1621
1697 if ((skb = alloc_skb (size + NET_IP_ALIGN, gfp_flags)) == 0) { 1622 if ((skb = alloc_skb (size + NET_IP_ALIGN, gfp_flags)) == 0) {
@@ -1735,11 +1660,9 @@ static void rx_complete (struct usb_ep *ep, struct usb_request *req)
1735 /* normal completion */ 1660 /* normal completion */
1736 case 0: 1661 case 0:
1737 skb_put (skb, req->actual); 1662 skb_put (skb, req->actual);
1738#ifdef CONFIG_USB_ETH_RNDIS
1739 /* we know MaxPacketsPerTransfer == 1 here */ 1663 /* we know MaxPacketsPerTransfer == 1 here */
1740 if (dev->rndis) 1664 if (rndis_active(dev))
1741 status = rndis_rm_hdr (skb); 1665 status = rndis_rm_hdr (skb);
1742#endif
1743 if (status < 0 1666 if (status < 0
1744 || ETH_HLEN > skb->len 1667 || ETH_HLEN > skb->len
1745 || skb->len > ETH_FRAME_LEN) { 1668 || skb->len > ETH_FRAME_LEN) {
@@ -1859,8 +1782,6 @@ static void rx_fill (struct eth_dev *dev, int gfp_flags)
1859 struct usb_request *req; 1782 struct usb_request *req;
1860 unsigned long flags; 1783 unsigned long flags;
1861 1784
1862 clear_bit (WORK_RX_MEMORY, &dev->todo);
1863
1864 /* fill unused rxq slots with some skb */ 1785 /* fill unused rxq slots with some skb */
1865 spin_lock_irqsave (&dev->lock, flags); 1786 spin_lock_irqsave (&dev->lock, flags);
1866 while (!list_empty (&dev->rx_reqs)) { 1787 while (!list_empty (&dev->rx_reqs)) {
@@ -1883,11 +1804,9 @@ static void eth_work (void *_dev)
1883{ 1804{
1884 struct eth_dev *dev = _dev; 1805 struct eth_dev *dev = _dev;
1885 1806
1886 if (test_bit (WORK_RX_MEMORY, &dev->todo)) { 1807 if (test_and_clear_bit (WORK_RX_MEMORY, &dev->todo)) {
1887 if (netif_running (dev->net)) 1808 if (netif_running (dev->net))
1888 rx_fill (dev, GFP_KERNEL); 1809 rx_fill (dev, GFP_KERNEL);
1889 else
1890 clear_bit (WORK_RX_MEMORY, &dev->todo);
1891 } 1810 }
1892 1811
1893 if (dev->todo) 1812 if (dev->todo)
@@ -1971,8 +1890,7 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1971 * or the hardware can't use skb buffers. 1890 * or the hardware can't use skb buffers.
1972 * or there's not enough space for any RNDIS headers we need 1891 * or there's not enough space for any RNDIS headers we need
1973 */ 1892 */
1974#ifdef CONFIG_USB_ETH_RNDIS 1893 if (rndis_active(dev)) {
1975 if (dev->rndis) {
1976 struct sk_buff *skb_rndis; 1894 struct sk_buff *skb_rndis;
1977 1895
1978 skb_rndis = skb_realloc_headroom (skb, 1896 skb_rndis = skb_realloc_headroom (skb,
@@ -1985,7 +1903,6 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1985 rndis_add_hdr (skb); 1903 rndis_add_hdr (skb);
1986 length = skb->len; 1904 length = skb->len;
1987 } 1905 }
1988#endif
1989 req->buf = skb->data; 1906 req->buf = skb->data;
1990 req->context = skb; 1907 req->context = skb;
1991 req->complete = tx_complete; 1908 req->complete = tx_complete;
@@ -2018,9 +1935,7 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
2018 } 1935 }
2019 1936
2020 if (retval) { 1937 if (retval) {
2021#ifdef CONFIG_USB_ETH_RNDIS
2022drop: 1938drop:
2023#endif
2024 dev->stats.tx_dropped++; 1939 dev->stats.tx_dropped++;
2025 dev_kfree_skb_any (skb); 1940 dev_kfree_skb_any (skb);
2026 spin_lock_irqsave (&dev->lock, flags); 1941 spin_lock_irqsave (&dev->lock, flags);
@@ -2036,27 +1951,31 @@ drop:
2036 1951
2037#ifdef CONFIG_USB_ETH_RNDIS 1952#ifdef CONFIG_USB_ETH_RNDIS
2038 1953
2039static void rndis_send_media_state (struct eth_dev *dev, int connect) 1954/* The interrupt endpoint is used in RNDIS to notify the host when messages
2040{ 1955 * other than data packets are available ... notably the REMOTE_NDIS_*_CMPLT
2041 if (!dev) 1956 * messages, but also REMOTE_NDIS_INDICATE_STATUS_MSG and potentially even
2042 return; 1957 * REMOTE_NDIS_KEEPALIVE_MSG.
2043 1958 *
2044 if (connect) { 1959 * The RNDIS control queue is processed by GET_ENCAPSULATED_RESPONSE, and
2045 if (rndis_signal_connect (dev->rndis_config)) 1960 * normally just one notification will be queued.
2046 return; 1961 */
2047 } else { 1962
2048 if (rndis_signal_disconnect (dev->rndis_config)) 1963static struct usb_request *eth_req_alloc (struct usb_ep *, unsigned, unsigned);
2049 return; 1964static void eth_req_free (struct usb_ep *ep, struct usb_request *req);
2050 }
2051}
2052 1965
2053static void 1966static void
2054rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *req) 1967rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *req)
2055{ 1968{
1969 struct eth_dev *dev = ep->driver_data;
1970
2056 if (req->status || req->actual != req->length) 1971 if (req->status || req->actual != req->length)
2057 DEBUG ((struct eth_dev *) ep->driver_data, 1972 DEBUG (dev,
2058 "rndis control ack complete --> %d, %d/%d\n", 1973 "rndis control ack complete --> %d, %d/%d\n",
2059 req->status, req->actual, req->length); 1974 req->status, req->actual, req->length);
1975 req->context = NULL;
1976
1977 if (req != dev->stat_req)
1978 eth_req_free(ep, req);
2060} 1979}
2061 1980
2062static int rndis_control_ack (struct net_device *net) 1981static int rndis_control_ack (struct net_device *net)
@@ -2071,11 +1990,19 @@ static int rndis_control_ack (struct net_device *net)
2071 return -ENODEV; 1990 return -ENODEV;
2072 } 1991 }
2073 1992
1993 /* in case queue length > 1 */
1994 if (resp->context) {
1995 resp = eth_req_alloc (dev->status_ep, 8, GFP_ATOMIC);
1996 if (!resp)
1997 return -ENOMEM;
1998 }
1999
2074 /* Send RNDIS RESPONSE_AVAILABLE notification; 2000 /* Send RNDIS RESPONSE_AVAILABLE notification;
2075 * USB_CDC_NOTIFY_RESPONSE_AVAILABLE should work too 2001 * USB_CDC_NOTIFY_RESPONSE_AVAILABLE should work too
2076 */ 2002 */
2077 resp->length = 8; 2003 resp->length = 8;
2078 resp->complete = rndis_control_ack_complete; 2004 resp->complete = rndis_control_ack_complete;
2005 resp->context = dev;
2079 2006
2080 *((__le32 *) resp->buf) = __constant_cpu_to_le32 (1); 2007 *((__le32 *) resp->buf) = __constant_cpu_to_le32 (1);
2081 *((__le32 *) resp->buf + 1) = __constant_cpu_to_le32 (0); 2008 *((__le32 *) resp->buf + 1) = __constant_cpu_to_le32 (0);
@@ -2089,6 +2016,10 @@ static int rndis_control_ack (struct net_device *net)
2089 return 0; 2016 return 0;
2090} 2017}
2091 2018
2019#else
2020
2021#define rndis_control_ack NULL
2022
2092#endif /* RNDIS */ 2023#endif /* RNDIS */
2093 2024
2094static void eth_start (struct eth_dev *dev, int gfp_flags) 2025static void eth_start (struct eth_dev *dev, int gfp_flags)
@@ -2101,14 +2032,12 @@ static void eth_start (struct eth_dev *dev, int gfp_flags)
2101 /* and open the tx floodgates */ 2032 /* and open the tx floodgates */
2102 atomic_set (&dev->tx_qlen, 0); 2033 atomic_set (&dev->tx_qlen, 0);
2103 netif_wake_queue (dev->net); 2034 netif_wake_queue (dev->net);
2104#ifdef CONFIG_USB_ETH_RNDIS 2035 if (rndis_active(dev)) {
2105 if (dev->rndis) {
2106 rndis_set_param_medium (dev->rndis_config, 2036 rndis_set_param_medium (dev->rndis_config,
2107 NDIS_MEDIUM_802_3, 2037 NDIS_MEDIUM_802_3,
2108 BITRATE(dev->gadget)/100); 2038 BITRATE(dev->gadget)/100);
2109 rndis_send_media_state (dev, 1); 2039 (void) rndis_signal_connect (dev->rndis_config);
2110 } 2040 }
2111#endif
2112} 2041}
2113 2042
2114static int eth_open (struct net_device *net) 2043static int eth_open (struct net_device *net)
@@ -2149,28 +2078,27 @@ static int eth_stop (struct net_device *net)
2149 } 2078 }
2150 } 2079 }
2151 2080
2152#ifdef CONFIG_USB_ETH_RNDIS 2081 if (rndis_active(dev)) {
2153 if (dev->rndis) {
2154 rndis_set_param_medium (dev->rndis_config, 2082 rndis_set_param_medium (dev->rndis_config,
2155 NDIS_MEDIUM_802_3, 0); 2083 NDIS_MEDIUM_802_3, 0);
2156 rndis_send_media_state (dev, 0); 2084 (void) rndis_signal_disconnect (dev->rndis_config);
2157 } 2085 }
2158#endif
2159 2086
2160 return 0; 2087 return 0;
2161} 2088}
2162 2089
2163/*-------------------------------------------------------------------------*/ 2090/*-------------------------------------------------------------------------*/
2164 2091
2165static struct usb_request *eth_req_alloc (struct usb_ep *ep, unsigned size) 2092static struct usb_request *
2093eth_req_alloc (struct usb_ep *ep, unsigned size, unsigned gfp_flags)
2166{ 2094{
2167 struct usb_request *req; 2095 struct usb_request *req;
2168 2096
2169 req = usb_ep_alloc_request (ep, GFP_KERNEL); 2097 req = usb_ep_alloc_request (ep, gfp_flags);
2170 if (!req) 2098 if (!req)
2171 return NULL; 2099 return NULL;
2172 2100
2173 req->buf = kmalloc (size, GFP_KERNEL); 2101 req->buf = kmalloc (size, gfp_flags);
2174 if (!req->buf) { 2102 if (!req->buf) {
2175 usb_ep_free_request (ep, req); 2103 usb_ep_free_request (ep, req);
2176 req = NULL; 2104 req = NULL;
@@ -2192,10 +2120,8 @@ eth_unbind (struct usb_gadget *gadget)
2192 struct eth_dev *dev = get_gadget_data (gadget); 2120 struct eth_dev *dev = get_gadget_data (gadget);
2193 2121
2194 DEBUG (dev, "unbind\n"); 2122 DEBUG (dev, "unbind\n");
2195#ifdef CONFIG_USB_ETH_RNDIS
2196 rndis_deregister (dev->rndis_config); 2123 rndis_deregister (dev->rndis_config);
2197 rndis_exit (); 2124 rndis_exit ();
2198#endif
2199 2125
2200 /* we've already been disconnected ... no i/o is active */ 2126 /* we've already been disconnected ... no i/o is active */
2201 if (dev->req) { 2127 if (dev->req) {
@@ -2368,13 +2294,11 @@ autoconf_fail:
2368 gadget->name); 2294 gadget->name);
2369 return -ENODEV; 2295 return -ENODEV;
2370 } 2296 }
2371 EP_IN_NAME = in_ep->name;
2372 in_ep->driver_data = in_ep; /* claim */ 2297 in_ep->driver_data = in_ep; /* claim */
2373 2298
2374 out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc); 2299 out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc);
2375 if (!out_ep) 2300 if (!out_ep)
2376 goto autoconf_fail; 2301 goto autoconf_fail;
2377 EP_OUT_NAME = out_ep->name;
2378 out_ep->driver_data = out_ep; /* claim */ 2302 out_ep->driver_data = out_ep; /* claim */
2379 2303
2380#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 2304#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
@@ -2384,7 +2308,6 @@ autoconf_fail:
2384 if (cdc || rndis) { 2308 if (cdc || rndis) {
2385 status_ep = usb_ep_autoconfig (gadget, &fs_status_desc); 2309 status_ep = usb_ep_autoconfig (gadget, &fs_status_desc);
2386 if (status_ep) { 2310 if (status_ep) {
2387 EP_STATUS_NAME = status_ep->name;
2388 status_ep->driver_data = status_ep; /* claim */ 2311 status_ep->driver_data = status_ep; /* claim */
2389 } else if (rndis) { 2312 } else if (rndis) {
2390 dev_err (&gadget->dev, 2313 dev_err (&gadget->dev,
@@ -2426,7 +2349,7 @@ autoconf_fail:
2426 hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress; 2349 hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
2427 hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress; 2350 hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
2428#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 2351#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
2429 if (EP_STATUS_NAME) 2352 if (status_ep)
2430 hs_status_desc.bEndpointAddress = 2353 hs_status_desc.bEndpointAddress =
2431 fs_status_desc.bEndpointAddress; 2354 fs_status_desc.bEndpointAddress;
2432#endif 2355#endif
@@ -2499,20 +2422,23 @@ autoconf_fail:
2499 SET_ETHTOOL_OPS(net, &ops); 2422 SET_ETHTOOL_OPS(net, &ops);
2500 2423
2501 /* preallocate control message data and buffer */ 2424 /* preallocate control message data and buffer */
2502 dev->req = eth_req_alloc (gadget->ep0, USB_BUFSIZ); 2425 dev->req = eth_req_alloc (gadget->ep0, USB_BUFSIZ, GFP_KERNEL);
2503 if (!dev->req) 2426 if (!dev->req)
2504 goto fail; 2427 goto fail;
2505 dev->req->complete = eth_setup_complete; 2428 dev->req->complete = eth_setup_complete;
2506 2429
2507 /* ... and maybe likewise for status transfer */ 2430 /* ... and maybe likewise for status transfer */
2431#ifdef DEV_CONFIG_CDC
2508 if (dev->status_ep) { 2432 if (dev->status_ep) {
2509 dev->stat_req = eth_req_alloc (dev->status_ep, 2433 dev->stat_req = eth_req_alloc (dev->status_ep,
2510 STATUS_BYTECOUNT); 2434 STATUS_BYTECOUNT, GFP_KERNEL);
2511 if (!dev->stat_req) { 2435 if (!dev->stat_req) {
2512 eth_req_free (gadget->ep0, dev->req); 2436 eth_req_free (gadget->ep0, dev->req);
2513 goto fail; 2437 goto fail;
2514 } 2438 }
2439 dev->stat_req->context = NULL;
2515 } 2440 }
2441#endif
2516 2442
2517 /* finish hookup to lower layer ... */ 2443 /* finish hookup to lower layer ... */
2518 dev->gadget = gadget; 2444 dev->gadget = gadget;
@@ -2526,16 +2452,16 @@ autoconf_fail:
2526 netif_stop_queue (dev->net); 2452 netif_stop_queue (dev->net);
2527 netif_carrier_off (dev->net); 2453 netif_carrier_off (dev->net);
2528 2454
2529 // SET_NETDEV_DEV (dev->net, &gadget->dev); 2455 SET_NETDEV_DEV (dev->net, &gadget->dev);
2530 status = register_netdev (dev->net); 2456 status = register_netdev (dev->net);
2531 if (status < 0) 2457 if (status < 0)
2532 goto fail1; 2458 goto fail1;
2533 2459
2534 INFO (dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); 2460 INFO (dev, "%s, version: " DRIVER_VERSION "\n", driver_desc);
2535 INFO (dev, "using %s, OUT %s IN %s%s%s\n", gadget->name, 2461 INFO (dev, "using %s, OUT %s IN %s%s%s\n", gadget->name,
2536 EP_OUT_NAME, EP_IN_NAME, 2462 out_ep->name, in_ep->name,
2537 EP_STATUS_NAME ? " STATUS " : "", 2463 status_ep ? " STATUS " : "",
2538 EP_STATUS_NAME ? EP_STATUS_NAME : "" 2464 status_ep ? status_ep->name : ""
2539 ); 2465 );
2540 INFO (dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n", 2466 INFO (dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
2541 net->dev_addr [0], net->dev_addr [1], 2467 net->dev_addr [0], net->dev_addr [1],
@@ -2548,7 +2474,6 @@ autoconf_fail:
2548 dev->host_mac [2], dev->host_mac [3], 2474 dev->host_mac [2], dev->host_mac [3],
2549 dev->host_mac [4], dev->host_mac [5]); 2475 dev->host_mac [4], dev->host_mac [5]);
2550 2476
2551#ifdef CONFIG_USB_ETH_RNDIS
2552 if (rndis) { 2477 if (rndis) {
2553 u32 vendorID = 0; 2478 u32 vendorID = 0;
2554 2479
@@ -2565,7 +2490,7 @@ fail0:
2565 /* these set up a lot of the OIDs that RNDIS needs */ 2490 /* these set up a lot of the OIDs that RNDIS needs */
2566 rndis_set_host_mac (dev->rndis_config, dev->host_mac); 2491 rndis_set_host_mac (dev->rndis_config, dev->host_mac);
2567 if (rndis_set_param_dev (dev->rndis_config, dev->net, 2492 if (rndis_set_param_dev (dev->rndis_config, dev->net,
2568 &dev->stats)) 2493 &dev->stats, &dev->cdc_filter))
2569 goto fail0; 2494 goto fail0;
2570 if (rndis_set_param_vendor (dev->rndis_config, vendorID, 2495 if (rndis_set_param_vendor (dev->rndis_config, vendorID,
2571 manufacturer)) 2496 manufacturer))
@@ -2576,7 +2501,6 @@ fail0:
2576 goto fail0; 2501 goto fail0;
2577 INFO (dev, "RNDIS ready\n"); 2502 INFO (dev, "RNDIS ready\n");
2578 } 2503 }
2579#endif
2580 2504
2581 return status; 2505 return status;
2582 2506
@@ -2610,11 +2534,8 @@ eth_resume (struct usb_gadget *gadget)
2610/*-------------------------------------------------------------------------*/ 2534/*-------------------------------------------------------------------------*/
2611 2535
2612static struct usb_gadget_driver eth_driver = { 2536static struct usb_gadget_driver eth_driver = {
2613#ifdef CONFIG_USB_GADGET_DUALSPEED 2537 .speed = DEVSPEED,
2614 .speed = USB_SPEED_HIGH, 2538
2615#else
2616 .speed = USB_SPEED_FULL,
2617#endif
2618 .function = (char *) driver_desc, 2539 .function = (char *) driver_desc,
2619 .bind = eth_bind, 2540 .bind = eth_bind,
2620 .unbind = eth_unbind, 2541 .unbind = eth_unbind,
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a9be85103d23..4f57085619b4 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -81,6 +81,10 @@
81 * removable Default false, boolean for removable media 81 * removable Default false, boolean for removable media
82 * luns=N Default N = number of filenames, number of 82 * luns=N Default N = number of filenames, number of
83 * LUNs to support 83 * LUNs to support
84 * stall Default determined according to the type of
85 * USB device controller (usually true),
86 * boolean to permit the driver to halt
87 * bulk endpoints
84 * transport=XXX Default BBB, transport name (CB, CBI, or BBB) 88 * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
85 * protocol=YYY Default SCSI, protocol name (RBC, 8020 or 89 * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
86 * ATAPI, QIC, UFI, 8070, or SCSI; 90 * ATAPI, QIC, UFI, 8070, or SCSI;
@@ -91,14 +95,10 @@
91 * buflen=N Default N=16384, buffer size used (will be 95 * buflen=N Default N=16384, buffer size used (will be
92 * rounded down to a multiple of 96 * rounded down to a multiple of
93 * PAGE_CACHE_SIZE) 97 * PAGE_CACHE_SIZE)
94 * stall Default determined according to the type of
95 * USB device controller (usually true),
96 * boolean to permit the driver to halt
97 * bulk endpoints
98 * 98 *
99 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", 99 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro",
100 * "removable", and "luns" options are available; default values are used 100 * "removable", "luns", and "stall" options are available; default values
101 * for everything else. 101 * are used for everything else.
102 * 102 *
103 * The pathnames of the backing files and the ro settings are available in 103 * The pathnames of the backing files and the ro settings are available in
104 * the attribute files "file" and "ro" in the lun<n> subdirectory of the 104 * the attribute files "file" and "ro" in the lun<n> subdirectory of the
@@ -342,14 +342,15 @@ static struct {
342 int num_ros; 342 int num_ros;
343 unsigned int nluns; 343 unsigned int nluns;
344 344
345 int removable;
346 int can_stall;
347
345 char *transport_parm; 348 char *transport_parm;
346 char *protocol_parm; 349 char *protocol_parm;
347 int removable;
348 unsigned short vendor; 350 unsigned short vendor;
349 unsigned short product; 351 unsigned short product;
350 unsigned short release; 352 unsigned short release;
351 unsigned int buflen; 353 unsigned int buflen;
352 int can_stall;
353 354
354 int transport_type; 355 int transport_type;
355 char *transport_name; 356 char *transport_name;
@@ -360,11 +361,11 @@ static struct {
360 .transport_parm = "BBB", 361 .transport_parm = "BBB",
361 .protocol_parm = "SCSI", 362 .protocol_parm = "SCSI",
362 .removable = 0, 363 .removable = 0,
364 .can_stall = 1,
363 .vendor = DRIVER_VENDOR_ID, 365 .vendor = DRIVER_VENDOR_ID,
364 .product = DRIVER_PRODUCT_ID, 366 .product = DRIVER_PRODUCT_ID,
365 .release = 0xffff, // Use controller chip type 367 .release = 0xffff, // Use controller chip type
366 .buflen = 16384, 368 .buflen = 16384,
367 .can_stall = 1,
368 }; 369 };
369 370
370 371
@@ -380,6 +381,9 @@ MODULE_PARM_DESC(luns, "number of LUNs");
380module_param_named(removable, mod_data.removable, bool, S_IRUGO); 381module_param_named(removable, mod_data.removable, bool, S_IRUGO);
381MODULE_PARM_DESC(removable, "true to simulate removable media"); 382MODULE_PARM_DESC(removable, "true to simulate removable media");
382 383
384module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
385MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
386
383 387
384/* In the non-TEST version, only the module parameters listed above 388/* In the non-TEST version, only the module parameters listed above
385 * are available. */ 389 * are available. */
@@ -404,9 +408,6 @@ MODULE_PARM_DESC(release, "USB release number");
404module_param_named(buflen, mod_data.buflen, uint, S_IRUGO); 408module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
405MODULE_PARM_DESC(buflen, "I/O buffer size"); 409MODULE_PARM_DESC(buflen, "I/O buffer size");
406 410
407module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
408MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
409
410#endif /* CONFIG_USB_FILE_STORAGE_TEST */ 411#endif /* CONFIG_USB_FILE_STORAGE_TEST */
411 412
412 413
@@ -818,7 +819,7 @@ static void inline put_be32(u8 *buf, u32 val)
818 buf[0] = val >> 24; 819 buf[0] = val >> 24;
819 buf[1] = val >> 16; 820 buf[1] = val >> 16;
820 buf[2] = val >> 8; 821 buf[2] = val >> 8;
821 buf[3] = val; 822 buf[3] = val & 0xff;
822} 823}
823 824
824 825
@@ -1276,8 +1277,8 @@ static int class_setup_req(struct fsg_dev *fsg,
1276{ 1277{
1277 struct usb_request *req = fsg->ep0req; 1278 struct usb_request *req = fsg->ep0req;
1278 int value = -EOPNOTSUPP; 1279 int value = -EOPNOTSUPP;
1279 u16 w_index = ctrl->wIndex; 1280 u16 w_index = le16_to_cpu(ctrl->wIndex);
1280 u16 w_length = ctrl->wLength; 1281 u16 w_length = le16_to_cpu(ctrl->wLength);
1281 1282
1282 if (!fsg->config) 1283 if (!fsg->config)
1283 return value; 1284 return value;
@@ -1312,7 +1313,7 @@ static int class_setup_req(struct fsg_dev *fsg,
1312 } 1313 }
1313 VDBG(fsg, "get max LUN\n"); 1314 VDBG(fsg, "get max LUN\n");
1314 *(u8 *) req->buf = fsg->nluns - 1; 1315 *(u8 *) req->buf = fsg->nluns - 1;
1315 value = min(w_length, (u16) 1); 1316 value = 1;
1316 break; 1317 break;
1317 } 1318 }
1318 } 1319 }
@@ -1344,7 +1345,7 @@ static int class_setup_req(struct fsg_dev *fsg,
1344 "unknown class-specific control req " 1345 "unknown class-specific control req "
1345 "%02x.%02x v%04x i%04x l%u\n", 1346 "%02x.%02x v%04x i%04x l%u\n",
1346 ctrl->bRequestType, ctrl->bRequest, 1347 ctrl->bRequestType, ctrl->bRequest,
1347 ctrl->wValue, w_index, w_length); 1348 le16_to_cpu(ctrl->wValue), w_index, w_length);
1348 return value; 1349 return value;
1349} 1350}
1350 1351
@@ -1358,9 +1359,8 @@ static int standard_setup_req(struct fsg_dev *fsg,
1358{ 1359{
1359 struct usb_request *req = fsg->ep0req; 1360 struct usb_request *req = fsg->ep0req;
1360 int value = -EOPNOTSUPP; 1361 int value = -EOPNOTSUPP;
1361 u16 w_index = ctrl->wIndex; 1362 u16 w_index = le16_to_cpu(ctrl->wIndex);
1362 u16 w_value = ctrl->wValue; 1363 u16 w_value = le16_to_cpu(ctrl->wValue);
1363 u16 w_length = ctrl->wLength;
1364 1364
1365 /* Usually this just stores reply data in the pre-allocated ep0 buffer, 1365 /* Usually this just stores reply data in the pre-allocated ep0 buffer,
1366 * but config change events will also reconfigure hardware. */ 1366 * but config change events will also reconfigure hardware. */
@@ -1374,7 +1374,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1374 1374
1375 case USB_DT_DEVICE: 1375 case USB_DT_DEVICE:
1376 VDBG(fsg, "get device descriptor\n"); 1376 VDBG(fsg, "get device descriptor\n");
1377 value = min(w_length, (u16) sizeof device_desc); 1377 value = sizeof device_desc;
1378 memcpy(req->buf, &device_desc, value); 1378 memcpy(req->buf, &device_desc, value);
1379 break; 1379 break;
1380#ifdef CONFIG_USB_GADGET_DUALSPEED 1380#ifdef CONFIG_USB_GADGET_DUALSPEED
@@ -1382,7 +1382,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1382 VDBG(fsg, "get device qualifier\n"); 1382 VDBG(fsg, "get device qualifier\n");
1383 if (!fsg->gadget->is_dualspeed) 1383 if (!fsg->gadget->is_dualspeed)
1384 break; 1384 break;
1385 value = min(w_length, (u16) sizeof dev_qualifier); 1385 value = sizeof dev_qualifier;
1386 memcpy(req->buf, &dev_qualifier, value); 1386 memcpy(req->buf, &dev_qualifier, value);
1387 break; 1387 break;
1388 1388
@@ -1401,8 +1401,6 @@ static int standard_setup_req(struct fsg_dev *fsg,
1401 req->buf, 1401 req->buf,
1402 w_value >> 8, 1402 w_value >> 8,
1403 w_value & 0xff); 1403 w_value & 0xff);
1404 if (value >= 0)
1405 value = min(w_length, (u16) value);
1406 break; 1404 break;
1407 1405
1408 case USB_DT_STRING: 1406 case USB_DT_STRING:
@@ -1411,8 +1409,6 @@ static int standard_setup_req(struct fsg_dev *fsg,
1411 /* wIndex == language code */ 1409 /* wIndex == language code */
1412 value = usb_gadget_get_string(&stringtab, 1410 value = usb_gadget_get_string(&stringtab,
1413 w_value & 0xff, req->buf); 1411 w_value & 0xff, req->buf);
1414 if (value >= 0)
1415 value = min(w_length, (u16) value);
1416 break; 1412 break;
1417 } 1413 }
1418 break; 1414 break;
@@ -1438,7 +1434,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1438 break; 1434 break;
1439 VDBG(fsg, "get configuration\n"); 1435 VDBG(fsg, "get configuration\n");
1440 *(u8 *) req->buf = fsg->config; 1436 *(u8 *) req->buf = fsg->config;
1441 value = min(w_length, (u16) 1); 1437 value = 1;
1442 break; 1438 break;
1443 1439
1444 case USB_REQ_SET_INTERFACE: 1440 case USB_REQ_SET_INTERFACE:
@@ -1466,14 +1462,14 @@ static int standard_setup_req(struct fsg_dev *fsg,
1466 } 1462 }
1467 VDBG(fsg, "get interface\n"); 1463 VDBG(fsg, "get interface\n");
1468 *(u8 *) req->buf = 0; 1464 *(u8 *) req->buf = 0;
1469 value = min(w_length, (u16) 1); 1465 value = 1;
1470 break; 1466 break;
1471 1467
1472 default: 1468 default:
1473 VDBG(fsg, 1469 VDBG(fsg,
1474 "unknown control req %02x.%02x v%04x i%04x l%u\n", 1470 "unknown control req %02x.%02x v%04x i%04x l%u\n",
1475 ctrl->bRequestType, ctrl->bRequest, 1471 ctrl->bRequestType, ctrl->bRequest,
1476 w_value, w_index, w_length); 1472 w_value, w_index, le16_to_cpu(ctrl->wLength));
1477 } 1473 }
1478 1474
1479 return value; 1475 return value;
@@ -1485,6 +1481,7 @@ static int fsg_setup(struct usb_gadget *gadget,
1485{ 1481{
1486 struct fsg_dev *fsg = get_gadget_data(gadget); 1482 struct fsg_dev *fsg = get_gadget_data(gadget);
1487 int rc; 1483 int rc;
1484 int w_length = le16_to_cpu(ctrl->wLength);
1488 1485
1489 ++fsg->ep0_req_tag; // Record arrival of a new request 1486 ++fsg->ep0_req_tag; // Record arrival of a new request
1490 fsg->ep0req->context = NULL; 1487 fsg->ep0req->context = NULL;
@@ -1498,9 +1495,9 @@ static int fsg_setup(struct usb_gadget *gadget,
1498 1495
1499 /* Respond with data/status or defer until later? */ 1496 /* Respond with data/status or defer until later? */
1500 if (rc >= 0 && rc != DELAYED_STATUS) { 1497 if (rc >= 0 && rc != DELAYED_STATUS) {
1498 rc = min(rc, w_length);
1501 fsg->ep0req->length = rc; 1499 fsg->ep0req->length = rc;
1502 fsg->ep0req->zero = (rc < ctrl->wLength && 1500 fsg->ep0req->zero = rc < w_length;
1503 (rc % gadget->ep0->maxpacket) == 0);
1504 fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ? 1501 fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
1505 "ep0-in" : "ep0-out"); 1502 "ep0-in" : "ep0-out");
1506 rc = ep0_queue(fsg); 1503 rc = ep0_queue(fsg);
@@ -2660,7 +2657,7 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2660 } 2657 }
2661 } 2658 }
2662 2659
2663 /* Check that the LUN values are oonsistent */ 2660 /* Check that the LUN values are consistent */
2664 if (transport_is_bbb()) { 2661 if (transport_is_bbb()) {
2665 if (fsg->lun != lun) 2662 if (fsg->lun != lun)
2666 DBG(fsg, "using LUN %d from CBW, " 2663 DBG(fsg, "using LUN %d from CBW, "
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 005db7cca292..ed773a9111de 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -70,7 +70,7 @@ MODULE_LICENSE("GPL");
70 * seem to behave quite as expected. Used by default. 70 * seem to behave quite as expected. Used by default.
71 * 71 *
72 * OUT dma documents design problems handling the common "short packet" 72 * OUT dma documents design problems handling the common "short packet"
73 * transfer termination policy; it couldn't enabled by default, even 73 * transfer termination policy; it couldn't be enabled by default, even
74 * if the OUT-dma abort problems had a resolution. 74 * if the OUT-dma abort problems had a resolution.
75 */ 75 */
76static unsigned use_dma = 1; 76static unsigned use_dma = 1;
@@ -313,7 +313,7 @@ goku_free_request(struct usb_ep *_ep, struct usb_request *_req)
313#if defined(CONFIG_X86) 313#if defined(CONFIG_X86)
314#define USE_KMALLOC 314#define USE_KMALLOC
315 315
316#elif defined(CONFIG_MIPS) && !defined(CONFIG_NONCOHERENT_IO) 316#elif defined(CONFIG_MIPS) && !defined(CONFIG_DMA_NONCOHERENT)
317#define USE_KMALLOC 317#define USE_KMALLOC
318 318
319#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE) 319#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
@@ -1524,9 +1524,12 @@ static void ep0_setup(struct goku_udc *dev)
1524 /* read SETUP packet and enter DATA stage */ 1524 /* read SETUP packet and enter DATA stage */
1525 ctrl.bRequestType = readl(&regs->bRequestType); 1525 ctrl.bRequestType = readl(&regs->bRequestType);
1526 ctrl.bRequest = readl(&regs->bRequest); 1526 ctrl.bRequest = readl(&regs->bRequest);
1527 ctrl.wValue = (readl(&regs->wValueH) << 8) | readl(&regs->wValueL); 1527 ctrl.wValue = cpu_to_le16((readl(&regs->wValueH) << 8)
1528 ctrl.wIndex = (readl(&regs->wIndexH) << 8) | readl(&regs->wIndexL); 1528 | readl(&regs->wValueL));
1529 ctrl.wLength = (readl(&regs->wLengthH) << 8) | readl(&regs->wLengthL); 1529 ctrl.wIndex = cpu_to_le16((readl(&regs->wIndexH) << 8)
1530 | readl(&regs->wIndexL));
1531 ctrl.wLength = cpu_to_le16((readl(&regs->wLengthH) << 8)
1532 | readl(&regs->wLengthL));
1530 writel(0, &regs->SetupRecv); 1533 writel(0, &regs->SetupRecv);
1531 1534
1532 nuke(&dev->ep[0], 0); 1535 nuke(&dev->ep[0], 0);
@@ -1548,18 +1551,20 @@ static void ep0_setup(struct goku_udc *dev)
1548 case USB_REQ_CLEAR_FEATURE: 1551 case USB_REQ_CLEAR_FEATURE:
1549 switch (ctrl.bRequestType) { 1552 switch (ctrl.bRequestType) {
1550 case USB_RECIP_ENDPOINT: 1553 case USB_RECIP_ENDPOINT:
1551 tmp = ctrl.wIndex & 0x0f; 1554 tmp = le16_to_cpu(ctrl.wIndex) & 0x0f;
1552 /* active endpoint */ 1555 /* active endpoint */
1553 if (tmp > 3 || (!dev->ep[tmp].desc && tmp != 0)) 1556 if (tmp > 3 || (!dev->ep[tmp].desc && tmp != 0))
1554 goto stall; 1557 goto stall;
1555 if (ctrl.wIndex & USB_DIR_IN) { 1558 if (ctrl.wIndex & __constant_cpu_to_le16(
1559 USB_DIR_IN)) {
1556 if (!dev->ep[tmp].is_in) 1560 if (!dev->ep[tmp].is_in)
1557 goto stall; 1561 goto stall;
1558 } else { 1562 } else {
1559 if (dev->ep[tmp].is_in) 1563 if (dev->ep[tmp].is_in)
1560 goto stall; 1564 goto stall;
1561 } 1565 }
1562 if (ctrl.wValue != USB_ENDPOINT_HALT) 1566 if (ctrl.wValue != __constant_cpu_to_le16(
1567 USB_ENDPOINT_HALT))
1563 goto stall; 1568 goto stall;
1564 if (tmp) 1569 if (tmp)
1565 goku_clear_halt(&dev->ep[tmp]); 1570 goku_clear_halt(&dev->ep[tmp]);
@@ -1571,7 +1576,7 @@ succeed:
1571 return; 1576 return;
1572 case USB_RECIP_DEVICE: 1577 case USB_RECIP_DEVICE:
1573 /* device remote wakeup: always clear */ 1578 /* device remote wakeup: always clear */
1574 if (ctrl.wValue != 1) 1579 if (ctrl.wValue != __constant_cpu_to_le16(1))
1575 goto stall; 1580 goto stall;
1576 VDBG(dev, "clear dev remote wakeup\n"); 1581 VDBG(dev, "clear dev remote wakeup\n");
1577 goto succeed; 1582 goto succeed;
@@ -1589,14 +1594,15 @@ succeed:
1589#ifdef USB_TRACE 1594#ifdef USB_TRACE
1590 VDBG(dev, "SETUP %02x.%02x v%04x i%04x l%04x\n", 1595 VDBG(dev, "SETUP %02x.%02x v%04x i%04x l%04x\n",
1591 ctrl.bRequestType, ctrl.bRequest, 1596 ctrl.bRequestType, ctrl.bRequest,
1592 ctrl.wValue, ctrl.wIndex, ctrl.wLength); 1597 le16_to_cpu(ctrl.wValue), le16_to_cpu(ctrl.wIndex),
1598 le16_to_cpu(ctrl.wLength));
1593#endif 1599#endif
1594 1600
1595 /* hw wants to know when we're configured (or not) */ 1601 /* hw wants to know when we're configured (or not) */
1596 dev->req_config = (ctrl.bRequest == USB_REQ_SET_CONFIGURATION 1602 dev->req_config = (ctrl.bRequest == USB_REQ_SET_CONFIGURATION
1597 && ctrl.bRequestType == USB_RECIP_DEVICE); 1603 && ctrl.bRequestType == USB_RECIP_DEVICE);
1598 if (unlikely(dev->req_config)) 1604 if (unlikely(dev->req_config))
1599 dev->configured = (ctrl.wValue != 0); 1605 dev->configured = (ctrl.wValue != __constant_cpu_to_le16(0));
1600 1606
1601 /* delegate everything to the gadget driver. 1607 /* delegate everything to the gadget driver.
1602 * it may respond after this irq handler returns. 1608 * it may respond after this irq handler returns.
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 1e5e6ddef787..020815397a49 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -417,8 +417,8 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
417 goto free1; 417 goto free1;
418 418
419 value = ep_io (data, kbuf, len); 419 value = ep_io (data, kbuf, len);
420 VDEBUG (data->dev, "%s read %d OUT, status %d\n", 420 VDEBUG (data->dev, "%s read %zu OUT, status %d\n",
421 data->name, len, value); 421 data->name, len, (int) value);
422 if (value >= 0 && copy_to_user (buf, kbuf, value)) 422 if (value >= 0 && copy_to_user (buf, kbuf, value))
423 value = -EFAULT; 423 value = -EFAULT;
424 424
@@ -465,8 +465,8 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
465 } 465 }
466 466
467 value = ep_io (data, kbuf, len); 467 value = ep_io (data, kbuf, len);
468 VDEBUG (data->dev, "%s write %d IN, status %d\n", 468 VDEBUG (data->dev, "%s write %zu IN, status %d\n",
469 data->name, len, value); 469 data->name, len, (int) value);
470free1: 470free1:
471 up (&data->lock); 471 up (&data->lock);
472 kfree (kbuf); 472 kfree (kbuf);
@@ -1318,8 +1318,8 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1318 struct usb_request *req = dev->req; 1318 struct usb_request *req = dev->req;
1319 int value = -EOPNOTSUPP; 1319 int value = -EOPNOTSUPP;
1320 struct usb_gadgetfs_event *event; 1320 struct usb_gadgetfs_event *event;
1321 u16 w_value = ctrl->wValue; 1321 u16 w_value = le16_to_cpu(ctrl->wValue);
1322 u16 w_length = ctrl->wLength; 1322 u16 w_length = le16_to_cpu(ctrl->wLength);
1323 1323
1324 spin_lock (&dev->lock); 1324 spin_lock (&dev->lock);
1325 dev->setup_abort = 0; 1325 dev->setup_abort = 0;
diff --git a/drivers/usb/gadget/ndis.h b/drivers/usb/gadget/ndis.h
index c553bbf68cab..09e3ee4eeae1 100644
--- a/drivers/usb/gadget/ndis.h
+++ b/drivers/usb/gadget/ndis.h
@@ -47,17 +47,17 @@ struct NDIS_PM_WAKE_UP_CAPABILITIES {
47#define NDIS_DEVICE_WAKE_ON_MAGIC_PACKET_ENABLE 0x00000004 47#define NDIS_DEVICE_WAKE_ON_MAGIC_PACKET_ENABLE 0x00000004
48 48
49struct NDIS_PNP_CAPABILITIES { 49struct NDIS_PNP_CAPABILITIES {
50 u32 Flags; 50 __le32 Flags;
51 struct NDIS_PM_WAKE_UP_CAPABILITIES WakeUpCapabilities; 51 struct NDIS_PM_WAKE_UP_CAPABILITIES WakeUpCapabilities;
52}; 52};
53 53
54struct NDIS_PM_PACKET_PATTERN { 54struct NDIS_PM_PACKET_PATTERN {
55 u32 Priority; 55 __le32 Priority;
56 u32 Reserved; 56 __le32 Reserved;
57 u32 MaskSize; 57 __le32 MaskSize;
58 u32 PatternOffset; 58 __le32 PatternOffset;
59 u32 PatternSize; 59 __le32 PatternSize;
60 u32 PatternFlags; 60 __le32 PatternFlags;
61}; 61};
62 62
63 63
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index e47e398daeb5..13a3dbc9949b 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -448,7 +448,7 @@ net2280_free_request (struct usb_ep *_ep, struct usb_request *_req)
448#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE) 448#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
449#define USE_KMALLOC 449#define USE_KMALLOC
450 450
451#elif defined(CONFIG_MIPS) && !defined(CONFIG_NONCOHERENT_IO) 451#elif defined(CONFIG_MIPS) && !defined(CONFIG_DMA_NONCOHERENT)
452#define USE_KMALLOC 452#define USE_KMALLOC
453 453
454/* FIXME there are other cases, including an x86-64 one ... */ 454/* FIXME there are other cases, including an x86-64 one ... */
@@ -1113,7 +1113,7 @@ static void restart_dma (struct net2280_ep *ep)
1113 if (ep->in_fifo_validate) 1113 if (ep->in_fifo_validate)
1114 dmactl |= (1 << DMA_FIFO_VALIDATE); 1114 dmactl |= (1 << DMA_FIFO_VALIDATE);
1115 list_for_each_entry (entry, &ep->queue, queue) { 1115 list_for_each_entry (entry, &ep->queue, queue) {
1116 u32 dmacount; 1116 __le32 dmacount;
1117 1117
1118 if (entry == req) 1118 if (entry == req)
1119 continue; 1119 continue;
@@ -1238,7 +1238,7 @@ static int net2280_dequeue (struct usb_ep *_ep, struct usb_request *_req)
1238 &ep->dma->dmadesc); 1238 &ep->dma->dmadesc);
1239 if (req->td->dmacount & dma_done_ie) 1239 if (req->td->dmacount & dma_done_ie)
1240 writel (readl (&ep->dma->dmacount) 1240 writel (readl (&ep->dma->dmacount)
1241 | dma_done_ie, 1241 | le32_to_cpu(dma_done_ie),
1242 &ep->dma->dmacount); 1242 &ep->dma->dmacount);
1243 } else { 1243 } else {
1244 struct net2280_request *prev; 1244 struct net2280_request *prev;
@@ -1779,6 +1779,9 @@ static void set_fifo_mode (struct net2280 *dev, int mode)
1779 list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list); 1779 list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list);
1780} 1780}
1781 1781
1782/* just declare this in any driver that really need it */
1783extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode);
1784
1782/** 1785/**
1783 * net2280_set_fifo_mode - change allocation of fifo buffers 1786 * net2280_set_fifo_mode - change allocation of fifo buffers
1784 * @gadget: access to the net2280 device that will be updated 1787 * @gadget: access to the net2280 device that will be updated
@@ -2382,9 +2385,9 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2382 cpu_to_le32s (&u.raw [0]); 2385 cpu_to_le32s (&u.raw [0]);
2383 cpu_to_le32s (&u.raw [1]); 2386 cpu_to_le32s (&u.raw [1]);
2384 2387
2385 le16_to_cpus (&u.r.wValue); 2388#define w_value le16_to_cpup (&u.r.wValue)
2386 le16_to_cpus (&u.r.wIndex); 2389#define w_index le16_to_cpup (&u.r.wIndex)
2387 le16_to_cpus (&u.r.wLength); 2390#define w_length le16_to_cpup (&u.r.wLength)
2388 2391
2389 /* ack the irq */ 2392 /* ack the irq */
2390 writel (1 << SETUP_PACKET_INTERRUPT, &dev->regs->irqstat0); 2393 writel (1 << SETUP_PACKET_INTERRUPT, &dev->regs->irqstat0);
@@ -2413,25 +2416,25 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2413 switch (u.r.bRequest) { 2416 switch (u.r.bRequest) {
2414 case USB_REQ_GET_STATUS: { 2417 case USB_REQ_GET_STATUS: {
2415 struct net2280_ep *e; 2418 struct net2280_ep *e;
2416 u16 status; 2419 __le32 status;
2417 2420
2418 /* hw handles device and interface status */ 2421 /* hw handles device and interface status */
2419 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) 2422 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT))
2420 goto delegate; 2423 goto delegate;
2421 if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0 2424 if ((e = get_ep_by_addr (dev, w_index)) == 0
2422 || u.r.wLength > 2) 2425 || w_length > 2)
2423 goto do_stall; 2426 goto do_stall;
2424 2427
2425 if (readl (&e->regs->ep_rsp) 2428 if (readl (&e->regs->ep_rsp)
2426 & (1 << SET_ENDPOINT_HALT)) 2429 & (1 << SET_ENDPOINT_HALT))
2427 status = __constant_cpu_to_le16 (1); 2430 status = __constant_cpu_to_le32 (1);
2428 else 2431 else
2429 status = __constant_cpu_to_le16 (0); 2432 status = __constant_cpu_to_le32 (0);
2430 2433
2431 /* don't bother with a request object! */ 2434 /* don't bother with a request object! */
2432 writel (0, &dev->epregs [0].ep_irqenb); 2435 writel (0, &dev->epregs [0].ep_irqenb);
2433 set_fifo_bytecount (ep, u.r.wLength); 2436 set_fifo_bytecount (ep, w_length);
2434 writel (status, &dev->epregs [0].ep_data); 2437 writel ((__force u32)status, &dev->epregs [0].ep_data);
2435 allow_status (ep); 2438 allow_status (ep);
2436 VDEBUG (dev, "%s stat %02x\n", ep->ep.name, status); 2439 VDEBUG (dev, "%s stat %02x\n", ep->ep.name, status);
2437 goto next_endpoints; 2440 goto next_endpoints;
@@ -2443,10 +2446,10 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2443 /* hw handles device features */ 2446 /* hw handles device features */
2444 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 2447 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
2445 goto delegate; 2448 goto delegate;
2446 if (u.r.wValue != USB_ENDPOINT_HALT 2449 if (w_value != USB_ENDPOINT_HALT
2447 || u.r.wLength != 0) 2450 || w_length != 0)
2448 goto do_stall; 2451 goto do_stall;
2449 if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0) 2452 if ((e = get_ep_by_addr (dev, w_index)) == 0)
2450 goto do_stall; 2453 goto do_stall;
2451 clear_halt (e); 2454 clear_halt (e);
2452 allow_status (ep); 2455 allow_status (ep);
@@ -2460,10 +2463,10 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2460 /* hw handles device features */ 2463 /* hw handles device features */
2461 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 2464 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
2462 goto delegate; 2465 goto delegate;
2463 if (u.r.wValue != USB_ENDPOINT_HALT 2466 if (w_value != USB_ENDPOINT_HALT
2464 || u.r.wLength != 0) 2467 || w_length != 0)
2465 goto do_stall; 2468 goto do_stall;
2466 if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0) 2469 if ((e = get_ep_by_addr (dev, w_index)) == 0)
2467 goto do_stall; 2470 goto do_stall;
2468 set_halt (e); 2471 set_halt (e);
2469 allow_status (ep); 2472 allow_status (ep);
@@ -2473,10 +2476,10 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2473 break; 2476 break;
2474 default: 2477 default:
2475delegate: 2478delegate:
2476 VDEBUG (dev, "setup %02x.%02x v%04x i%04x " 2479 VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x"
2477 "ep_cfg %08x\n", 2480 "ep_cfg %08x\n",
2478 u.r.bRequestType, u.r.bRequest, 2481 u.r.bRequestType, u.r.bRequest,
2479 u.r.wValue, u.r.wIndex, 2482 w_value, w_index, w_length,
2480 readl (&ep->regs->ep_cfg)); 2483 readl (&ep->regs->ep_cfg));
2481 spin_unlock (&dev->lock); 2484 spin_unlock (&dev->lock);
2482 tmp = dev->driver->setup (&dev->gadget, &u.r); 2485 tmp = dev->driver->setup (&dev->gadget, &u.r);
@@ -2497,6 +2500,10 @@ do_stall:
2497 */ 2500 */
2498 } 2501 }
2499 2502
2503#undef w_value
2504#undef w_index
2505#undef w_length
2506
2500next_endpoints: 2507next_endpoints:
2501 /* endpoint data irq ? */ 2508 /* endpoint data irq ? */
2502 scratch = stat & 0x7f; 2509 scratch = stat & 0x7f;
@@ -2653,7 +2660,7 @@ static void handle_stat1_irqs (struct net2280 *dev, u32 stat)
2653 restart_dma (ep); 2660 restart_dma (ep);
2654 else if (ep->is_in && use_dma_chaining) { 2661 else if (ep->is_in && use_dma_chaining) {
2655 struct net2280_request *req; 2662 struct net2280_request *req;
2656 u32 dmacount; 2663 __le32 dmacount;
2657 2664
2658 /* the descriptor at the head of the chain 2665 /* the descriptor at the head of the chain
2659 * may still have VALID_BIT clear; that's 2666 * may still have VALID_BIT clear; that's
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 98cbcbc16cc1..a2b812af6e66 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -52,7 +52,6 @@
52#include <asm/mach-types.h> 52#include <asm/mach-types.h>
53 53
54#include <asm/arch/dma.h> 54#include <asm/arch/dma.h>
55#include <asm/arch/mux.h>
56#include <asm/arch/usb.h> 55#include <asm/arch/usb.h>
57 56
58#include "omap_udc.h" 57#include "omap_udc.h"
@@ -167,7 +166,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
167 maxp = le16_to_cpu (desc->wMaxPacketSize); 166 maxp = le16_to_cpu (desc->wMaxPacketSize);
168 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK 167 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
169 && maxp != ep->maxpacket) 168 && maxp != ep->maxpacket)
170 || desc->wMaxPacketSize > ep->maxpacket 169 || le16_to_cpu(desc->wMaxPacketSize) > ep->maxpacket
171 || !desc->wMaxPacketSize) { 170 || !desc->wMaxPacketSize) {
172 DBG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name); 171 DBG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name);
173 return -ERANGE; 172 return -ERANGE;
@@ -214,7 +213,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
214 ep->has_dma = 0; 213 ep->has_dma = 0;
215 ep->lch = -1; 214 ep->lch = -1;
216 use_ep(ep, UDC_EP_SEL); 215 use_ep(ep, UDC_EP_SEL);
217 UDC_CTRL_REG = UDC_RESET_EP; 216 UDC_CTRL_REG = udc->clr_halt;
218 ep->ackwait = 0; 217 ep->ackwait = 0;
219 deselect_ep(); 218 deselect_ep();
220 219
@@ -253,7 +252,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
253 } 252 }
254 253
255 spin_lock_irqsave(&ep->udc->lock, flags); 254 spin_lock_irqsave(&ep->udc->lock, flags);
256 ep->desc = 0; 255 ep->desc = NULL;
257 nuke (ep, -ESHUTDOWN); 256 nuke (ep, -ESHUTDOWN);
258 ep->ep.maxpacket = ep->maxpacket; 257 ep->ep.maxpacket = ep->maxpacket;
259 ep->has_dma = 0; 258 ep->has_dma = 0;
@@ -388,8 +387,8 @@ done(struct omap_ep *ep, struct omap_req *req, int status)
388 387
389/*-------------------------------------------------------------------------*/ 388/*-------------------------------------------------------------------------*/
390 389
391#define FIFO_FULL (UDC_NON_ISO_FIFO_FULL | UDC_ISO_FIFO_FULL) 390#define UDC_FIFO_FULL (UDC_NON_ISO_FIFO_FULL | UDC_ISO_FIFO_FULL)
392#define FIFO_UNWRITABLE (UDC_EP_HALTED | FIFO_FULL) 391#define UDC_FIFO_UNWRITABLE (UDC_EP_HALTED | UDC_FIFO_FULL)
393 392
394#define FIFO_EMPTY (UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY) 393#define FIFO_EMPTY (UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY)
395#define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY) 394#define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY)
@@ -433,7 +432,7 @@ static int write_fifo(struct omap_ep *ep, struct omap_req *req)
433 432
434 /* PIO-IN isn't double buffered except for iso */ 433 /* PIO-IN isn't double buffered except for iso */
435 ep_stat = UDC_STAT_FLG_REG; 434 ep_stat = UDC_STAT_FLG_REG;
436 if (ep_stat & FIFO_UNWRITABLE) 435 if (ep_stat & UDC_FIFO_UNWRITABLE)
437 return 0; 436 return 0;
438 437
439 count = ep->ep.maxpacket; 438 count = ep->ep.maxpacket;
@@ -504,7 +503,7 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
504 if (ep_stat & UDC_EP_HALTED) 503 if (ep_stat & UDC_EP_HALTED)
505 break; 504 break;
506 505
507 if (ep_stat & FIFO_FULL) 506 if (ep_stat & UDC_FIFO_FULL)
508 avail = ep->ep.maxpacket; 507 avail = ep->ep.maxpacket;
509 else { 508 else {
510 avail = UDC_RXFSTAT_REG; 509 avail = UDC_RXFSTAT_REG;
@@ -538,6 +537,32 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
538 537
539/*-------------------------------------------------------------------------*/ 538/*-------------------------------------------------------------------------*/
540 539
540static inline dma_addr_t dma_csac(unsigned lch)
541{
542 dma_addr_t csac;
543
544 /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
545 * read before the DMA controller finished disabling the channel.
546 */
547 csac = omap_readw(OMAP_DMA_CSAC(lch));
548 if (csac == 0)
549 csac = omap_readw(OMAP_DMA_CSAC(lch));
550 return csac;
551}
552
553static inline dma_addr_t dma_cdac(unsigned lch)
554{
555 dma_addr_t cdac;
556
557 /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
558 * read before the DMA controller finished disabling the channel.
559 */
560 cdac = omap_readw(OMAP_DMA_CDAC(lch));
561 if (cdac == 0)
562 cdac = omap_readw(OMAP_DMA_CDAC(lch));
563 return cdac;
564}
565
541static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start) 566static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
542{ 567{
543 dma_addr_t end; 568 dma_addr_t end;
@@ -548,7 +573,7 @@ static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
548 if (cpu_is_omap15xx()) 573 if (cpu_is_omap15xx())
549 return 0; 574 return 0;
550 575
551 end = omap_readw(OMAP_DMA_CSAC(ep->lch)); 576 end = dma_csac(ep->lch);
552 if (end == ep->dma_counter) 577 if (end == ep->dma_counter)
553 return 0; 578 return 0;
554 579
@@ -559,14 +584,14 @@ static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
559} 584}
560 585
561#define DMA_DEST_LAST(x) (cpu_is_omap15xx() \ 586#define DMA_DEST_LAST(x) (cpu_is_omap15xx() \
562 ? OMAP_DMA_CSAC(x) /* really: CPC */ \ 587 ? omap_readw(OMAP_DMA_CSAC(x)) /* really: CPC */ \
563 : OMAP_DMA_CDAC(x)) 588 : dma_cdac(x))
564 589
565static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start) 590static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start)
566{ 591{
567 dma_addr_t end; 592 dma_addr_t end;
568 593
569 end = omap_readw(DMA_DEST_LAST(ep->lch)); 594 end = DMA_DEST_LAST(ep->lch);
570 if (end == ep->dma_counter) 595 if (end == ep->dma_counter)
571 return 0; 596 return 0;
572 597
@@ -593,7 +618,7 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
593 : OMAP_DMA_SYNC_ELEMENT; 618 : OMAP_DMA_SYNC_ELEMENT;
594 619
595 /* measure length in either bytes or packets */ 620 /* measure length in either bytes or packets */
596 if ((cpu_is_omap16xx() && length <= (UDC_TXN_TSC + 1)) 621 if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC)
597 || (cpu_is_omap15xx() && length < ep->maxpacket)) { 622 || (cpu_is_omap15xx() && length < ep->maxpacket)) {
598 txdma_ctrl = UDC_TXN_EOT | length; 623 txdma_ctrl = UDC_TXN_EOT | length;
599 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 624 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
@@ -602,15 +627,15 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
602 length = min(length / ep->maxpacket, 627 length = min(length / ep->maxpacket,
603 (unsigned) UDC_TXN_TSC + 1); 628 (unsigned) UDC_TXN_TSC + 1);
604 txdma_ctrl = length; 629 txdma_ctrl = length;
605 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 630 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
606 ep->ep.maxpacket, length, sync_mode); 631 ep->ep.maxpacket >> 1, length, sync_mode);
607 length *= ep->maxpacket; 632 length *= ep->maxpacket;
608 } 633 }
609 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, 634 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF,
610 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); 635 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual);
611 636
612 omap_start_dma(ep->lch); 637 omap_start_dma(ep->lch);
613 ep->dma_counter = omap_readw(OMAP_DMA_CSAC(ep->lch)); 638 ep->dma_counter = dma_csac(ep->lch);
614 UDC_DMA_IRQ_EN_REG |= UDC_TX_DONE_IE(ep->dma_channel); 639 UDC_DMA_IRQ_EN_REG |= UDC_TX_DONE_IE(ep->dma_channel);
615 UDC_TXDMA_REG(ep->dma_channel) = UDC_TXN_START | txdma_ctrl; 640 UDC_TXDMA_REG(ep->dma_channel) = UDC_TXN_START | txdma_ctrl;
616 req->dma_bytes = length; 641 req->dma_bytes = length;
@@ -650,12 +675,12 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
650 packets = (req->req.length - req->req.actual) / ep->ep.maxpacket; 675 packets = (req->req.length - req->req.actual) / ep->ep.maxpacket;
651 packets = min(packets, (unsigned)UDC_RXN_TC + 1); 676 packets = min(packets, (unsigned)UDC_RXN_TC + 1);
652 req->dma_bytes = packets * ep->ep.maxpacket; 677 req->dma_bytes = packets * ep->ep.maxpacket;
653 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 678 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
654 ep->ep.maxpacket, packets, 679 ep->ep.maxpacket >> 1, packets,
655 OMAP_DMA_SYNC_ELEMENT); 680 OMAP_DMA_SYNC_ELEMENT);
656 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, 681 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF,
657 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); 682 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual);
658 ep->dma_counter = omap_readw(DMA_DEST_LAST(ep->lch)); 683 ep->dma_counter = DMA_DEST_LAST(ep->lch);
659 684
660 UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1); 685 UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1);
661 UDC_DMA_IRQ_EN_REG |= UDC_RX_EOT_IE(ep->dma_channel); 686 UDC_DMA_IRQ_EN_REG |= UDC_RX_EOT_IE(ep->dma_channel);
@@ -763,7 +788,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
763 reg = UDC_TXDMA_CFG_REG; 788 reg = UDC_TXDMA_CFG_REG;
764 else 789 else
765 reg = UDC_RXDMA_CFG_REG; 790 reg = UDC_RXDMA_CFG_REG;
766 reg |= 1 << 12; /* "pulse" activated */ 791 reg |= UDC_DMA_REQ; /* "pulse" activated */
767 792
768 ep->dma_channel = 0; 793 ep->dma_channel = 0;
769 ep->lch = -1; 794 ep->lch = -1;
@@ -787,6 +812,11 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
787 ep->ep.name, dma_error, ep, &ep->lch); 812 ep->ep.name, dma_error, ep, &ep->lch);
788 if (status == 0) { 813 if (status == 0) {
789 UDC_TXDMA_CFG_REG = reg; 814 UDC_TXDMA_CFG_REG = reg;
815 /* EMIFF */
816 omap_set_dma_src_burst_mode(ep->lch,
817 OMAP_DMA_DATA_BURST_4);
818 omap_set_dma_src_data_pack(ep->lch, 1);
819 /* TIPB */
790 omap_set_dma_dest_params(ep->lch, 820 omap_set_dma_dest_params(ep->lch,
791 OMAP_DMA_PORT_TIPB, 821 OMAP_DMA_PORT_TIPB,
792 OMAP_DMA_AMODE_CONSTANT, 822 OMAP_DMA_AMODE_CONSTANT,
@@ -797,10 +827,15 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
797 ep->ep.name, dma_error, ep, &ep->lch); 827 ep->ep.name, dma_error, ep, &ep->lch);
798 if (status == 0) { 828 if (status == 0) {
799 UDC_RXDMA_CFG_REG = reg; 829 UDC_RXDMA_CFG_REG = reg;
830 /* TIPB */
800 omap_set_dma_src_params(ep->lch, 831 omap_set_dma_src_params(ep->lch,
801 OMAP_DMA_PORT_TIPB, 832 OMAP_DMA_PORT_TIPB,
802 OMAP_DMA_AMODE_CONSTANT, 833 OMAP_DMA_AMODE_CONSTANT,
803 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG)); 834 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG));
835 /* EMIFF */
836 omap_set_dma_dest_burst_mode(ep->lch,
837 OMAP_DMA_DATA_BURST_4);
838 omap_set_dma_dest_data_pack(ep->lch, 1);
804 } 839 }
805 } 840 }
806 if (status) 841 if (status)
@@ -856,7 +891,7 @@ static void dma_channel_release(struct omap_ep *ep)
856 if (!list_empty(&ep->queue)) 891 if (!list_empty(&ep->queue))
857 req = container_of(ep->queue.next, struct omap_req, queue); 892 req = container_of(ep->queue.next, struct omap_req, queue);
858 else 893 else
859 req = 0; 894 req = NULL;
860 895
861 active = ((1 << 7) & omap_readl(OMAP_DMA_CCR(ep->lch))) != 0; 896 active = ((1 << 7) & omap_readl(OMAP_DMA_CCR(ep->lch))) != 0;
862 897
@@ -865,9 +900,13 @@ static void dma_channel_release(struct omap_ep *ep)
865 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', 900 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r',
866 ep->dma_channel - 1, req); 901 ep->dma_channel - 1, req);
867 902
903 /* NOTE: re-setting RX_REQ/TX_REQ because of a chip bug (before
904 * OMAP 1710 ES2.0) where reading the DMA_CFG can clear them.
905 */
906
868 /* wait till current packet DMA finishes, and fifo empties */ 907 /* wait till current packet DMA finishes, and fifo empties */
869 if (ep->bEndpointAddress & USB_DIR_IN) { 908 if (ep->bEndpointAddress & USB_DIR_IN) {
870 UDC_TXDMA_CFG_REG &= ~mask; 909 UDC_TXDMA_CFG_REG = (UDC_TXDMA_CFG_REG & ~mask) | UDC_DMA_REQ;
871 910
872 if (req) { 911 if (req) {
873 finish_in_dma(ep, req, -ECONNRESET); 912 finish_in_dma(ep, req, -ECONNRESET);
@@ -880,7 +919,7 @@ static void dma_channel_release(struct omap_ep *ep)
880 while (UDC_TXDMA_CFG_REG & mask) 919 while (UDC_TXDMA_CFG_REG & mask)
881 udelay(10); 920 udelay(10);
882 } else { 921 } else {
883 UDC_RXDMA_CFG_REG &= ~mask; 922 UDC_RXDMA_CFG_REG = (UDC_RXDMA_CFG_REG & ~mask) | UDC_DMA_REQ;
884 923
885 /* dma empties the fifo */ 924 /* dma empties the fifo */
886 while (UDC_RXDMA_CFG_REG & mask) 925 while (UDC_RXDMA_CFG_REG & mask)
@@ -997,18 +1036,19 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
997 UDC_IRQ_EN_REG = irq_en; 1036 UDC_IRQ_EN_REG = irq_en;
998 } 1037 }
999 1038
1000 /* STATUS is reverse direction */ 1039 /* STATUS for zero length DATA stages is
1001 UDC_EP_NUM_REG = is_in 1040 * always an IN ... even for IN transfers,
1002 ? UDC_EP_SEL 1041 * a wierd case which seem to stall OMAP.
1003 : (UDC_EP_SEL|UDC_EP_DIR); 1042 */
1043 UDC_EP_NUM_REG = (UDC_EP_SEL|UDC_EP_DIR);
1004 UDC_CTRL_REG = UDC_CLR_EP; 1044 UDC_CTRL_REG = UDC_CLR_EP;
1005 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1045 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1006 UDC_EP_NUM_REG = udc->ep0_in ? 0 : UDC_EP_DIR; 1046 UDC_EP_NUM_REG = UDC_EP_DIR;
1007 1047
1008 /* cleanup */ 1048 /* cleanup */
1009 udc->ep0_pending = 0; 1049 udc->ep0_pending = 0;
1010 done(ep, req, 0); 1050 done(ep, req, 0);
1011 req = 0; 1051 req = NULL;
1012 1052
1013 /* non-empty DATA stage */ 1053 /* non-empty DATA stage */
1014 } else if (is_in) { 1054 } else if (is_in) {
@@ -1029,7 +1069,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
1029 (is_in ? next_in_dma : next_out_dma)(ep, req); 1069 (is_in ? next_in_dma : next_out_dma)(ep, req);
1030 else if (req) { 1070 else if (req) {
1031 if ((is_in ? write_fifo : read_fifo)(ep, req) == 1) 1071 if ((is_in ? write_fifo : read_fifo)(ep, req) == 1)
1032 req = 0; 1072 req = NULL;
1033 deselect_ep(); 1073 deselect_ep();
1034 if (!is_in) { 1074 if (!is_in) {
1035 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1075 UDC_CTRL_REG = UDC_SET_FIFO_EN;
@@ -1041,7 +1081,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
1041 1081
1042irq_wait: 1082irq_wait:
1043 /* irq handler advances the queue */ 1083 /* irq handler advances the queue */
1044 if (req != 0) 1084 if (req != NULL)
1045 list_add_tail(&req->queue, &ep->queue); 1085 list_add_tail(&req->queue, &ep->queue);
1046 spin_unlock_irqrestore(&udc->lock, flags); 1086 spin_unlock_irqrestore(&udc->lock, flags);
1047 1087
@@ -1140,7 +1180,7 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value)
1140 dma_channel_claim(ep, channel); 1180 dma_channel_claim(ep, channel);
1141 } else { 1181 } else {
1142 use_ep(ep, 0); 1182 use_ep(ep, 0);
1143 UDC_CTRL_REG = UDC_RESET_EP; 1183 UDC_CTRL_REG = ep->udc->clr_halt;
1144 ep->ackwait = 0; 1184 ep->ackwait = 0;
1145 if (!(ep->bEndpointAddress & USB_DIR_IN)) { 1185 if (!(ep->bEndpointAddress & USB_DIR_IN)) {
1146 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1186 UDC_CTRL_REG = UDC_SET_FIFO_EN;
@@ -1238,6 +1278,8 @@ static int can_pullup(struct omap_udc *udc)
1238 1278
1239static void pullup_enable(struct omap_udc *udc) 1279static void pullup_enable(struct omap_udc *udc)
1240{ 1280{
1281 udc->gadget.dev.parent->power.power_state = PMSG_ON;
1282 udc->gadget.dev.power.power_state = PMSG_ON;
1241 UDC_SYSCON1_REG |= UDC_PULLUP_EN; 1283 UDC_SYSCON1_REG |= UDC_PULLUP_EN;
1242#ifndef CONFIG_USB_OTG 1284#ifndef CONFIG_USB_OTG
1243 if (!cpu_is_omap15xx()) 1285 if (!cpu_is_omap15xx())
@@ -1382,7 +1424,7 @@ static void update_otg(struct omap_udc *udc)
1382static void ep0_irq(struct omap_udc *udc, u16 irq_src) 1424static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1383{ 1425{
1384 struct omap_ep *ep0 = &udc->ep[0]; 1426 struct omap_ep *ep0 = &udc->ep[0];
1385 struct omap_req *req = 0; 1427 struct omap_req *req = NULL;
1386 1428
1387 ep0->irqs++; 1429 ep0->irqs++;
1388 1430
@@ -1438,7 +1480,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1438 if (req) 1480 if (req)
1439 done(ep0, req, 0); 1481 done(ep0, req, 0);
1440 } 1482 }
1441 req = 0; 1483 req = NULL;
1442 } else if (stat & UDC_STALL) { 1484 } else if (stat & UDC_STALL) {
1443 UDC_CTRL_REG = UDC_CLR_HALT; 1485 UDC_CTRL_REG = UDC_CLR_HALT;
1444 UDC_EP_NUM_REG = UDC_EP_DIR; 1486 UDC_EP_NUM_REG = UDC_EP_DIR;
@@ -1511,9 +1553,10 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1511 u.word[3] = UDC_DATA_REG; 1553 u.word[3] = UDC_DATA_REG;
1512 UDC_EP_NUM_REG = 0; 1554 UDC_EP_NUM_REG = 0;
1513 } while (UDC_IRQ_SRC_REG & UDC_SETUP); 1555 } while (UDC_IRQ_SRC_REG & UDC_SETUP);
1514 le16_to_cpus (&u.r.wValue); 1556
1515 le16_to_cpus (&u.r.wIndex); 1557#define w_value le16_to_cpup (&u.r.wValue)
1516 le16_to_cpus (&u.r.wLength); 1558#define w_index le16_to_cpup (&u.r.wIndex)
1559#define w_length le16_to_cpup (&u.r.wLength)
1517 1560
1518 /* Delegate almost all control requests to the gadget driver, 1561 /* Delegate almost all control requests to the gadget driver,
1519 * except for a handful of ch9 status/feature requests that 1562 * except for a handful of ch9 status/feature requests that
@@ -1529,11 +1572,11 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1529 /* udc needs to know when ep != 0 is valid */ 1572 /* udc needs to know when ep != 0 is valid */
1530 if (u.r.bRequestType != USB_RECIP_DEVICE) 1573 if (u.r.bRequestType != USB_RECIP_DEVICE)
1531 goto delegate; 1574 goto delegate;
1532 if (u.r.wLength != 0) 1575 if (w_length != 0)
1533 goto do_stall; 1576 goto do_stall;
1534 udc->ep0_set_config = 1; 1577 udc->ep0_set_config = 1;
1535 udc->ep0_reset_config = (u.r.wValue == 0); 1578 udc->ep0_reset_config = (w_value == 0);
1536 VDBG("set config %d\n", u.r.wValue); 1579 VDBG("set config %d\n", w_value);
1537 1580
1538 /* update udc NOW since gadget driver may start 1581 /* update udc NOW since gadget driver may start
1539 * queueing requests immediately; clear config 1582 * queueing requests immediately; clear config
@@ -1549,23 +1592,28 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1549 /* clear endpoint halt */ 1592 /* clear endpoint halt */
1550 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 1593 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
1551 goto delegate; 1594 goto delegate;
1552 if (u.r.wValue != USB_ENDPOINT_HALT 1595 if (w_value != USB_ENDPOINT_HALT
1553 || u.r.wLength != 0) 1596 || w_length != 0)
1554 goto do_stall; 1597 goto do_stall;
1555 ep = &udc->ep[u.r.wIndex & 0xf]; 1598 ep = &udc->ep[w_index & 0xf];
1556 if (ep != ep0) { 1599 if (ep != ep0) {
1557 if (u.r.wIndex & USB_DIR_IN) 1600 if (w_index & USB_DIR_IN)
1558 ep += 16; 1601 ep += 16;
1559 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC 1602 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
1560 || !ep->desc) 1603 || !ep->desc)
1561 goto do_stall; 1604 goto do_stall;
1562 use_ep(ep, 0); 1605 use_ep(ep, 0);
1563 UDC_CTRL_REG = UDC_RESET_EP; 1606 UDC_CTRL_REG = udc->clr_halt;
1564 ep->ackwait = 0; 1607 ep->ackwait = 0;
1565 if (!(ep->bEndpointAddress & USB_DIR_IN)) { 1608 if (!(ep->bEndpointAddress & USB_DIR_IN)) {
1566 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1609 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1567 ep->ackwait = 1 + ep->double_buf; 1610 ep->ackwait = 1 + ep->double_buf;
1568 } 1611 }
1612 /* NOTE: assumes the host behaves sanely,
1613 * only clearing real halts. Else we may
1614 * need to kill pending transfers and then
1615 * restart the queue... very messy for DMA!
1616 */
1569 } 1617 }
1570 VDBG("%s halt cleared by host\n", ep->name); 1618 VDBG("%s halt cleared by host\n", ep->name);
1571 goto ep0out_status_stage; 1619 goto ep0out_status_stage;
@@ -1573,11 +1621,11 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1573 /* set endpoint halt */ 1621 /* set endpoint halt */
1574 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 1622 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
1575 goto delegate; 1623 goto delegate;
1576 if (u.r.wValue != USB_ENDPOINT_HALT 1624 if (w_value != USB_ENDPOINT_HALT
1577 || u.r.wLength != 0) 1625 || w_length != 0)
1578 goto do_stall; 1626 goto do_stall;
1579 ep = &udc->ep[u.r.wIndex & 0xf]; 1627 ep = &udc->ep[w_index & 0xf];
1580 if (u.r.wIndex & USB_DIR_IN) 1628 if (w_index & USB_DIR_IN)
1581 ep += 16; 1629 ep += 16;
1582 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC 1630 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
1583 || ep == ep0 || !ep->desc) 1631 || ep == ep0 || !ep->desc)
@@ -1615,13 +1663,13 @@ ep0out_status_stage:
1615 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1663 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1616 UDC_EP_NUM_REG = UDC_EP_DIR; 1664 UDC_EP_NUM_REG = UDC_EP_DIR;
1617 status = 0; 1665 status = 0;
1618 VDBG("GET_STATUS, interface %d\n", u.r.wIndex); 1666 VDBG("GET_STATUS, interface %d\n", w_index);
1619 /* next, status stage */ 1667 /* next, status stage */
1620 break; 1668 break;
1621 default: 1669 default:
1622delegate: 1670delegate:
1623 /* activate the ep0out fifo right away */ 1671 /* activate the ep0out fifo right away */
1624 if (!udc->ep0_in && u.r.wLength) { 1672 if (!udc->ep0_in && w_length) {
1625 UDC_EP_NUM_REG = 0; 1673 UDC_EP_NUM_REG = 0;
1626 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1674 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1627 } 1675 }
@@ -1632,7 +1680,11 @@ delegate:
1632 */ 1680 */
1633 VDBG("SETUP %02x.%02x v%04x i%04x l%04x\n", 1681 VDBG("SETUP %02x.%02x v%04x i%04x l%04x\n",
1634 u.r.bRequestType, u.r.bRequest, 1682 u.r.bRequestType, u.r.bRequest,
1635 u.r.wValue, u.r.wIndex, u.r.wLength); 1683 w_value, w_index, w_length);
1684
1685#undef w_value
1686#undef w_index
1687#undef w_length
1636 1688
1637 /* The gadget driver may return an error here, 1689 /* The gadget driver may return an error here,
1638 * causing an immediate protocol stall. 1690 * causing an immediate protocol stall.
@@ -2013,7 +2065,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2013 udc->softconnect = 1; 2065 udc->softconnect = 1;
2014 2066
2015 /* hook up the driver */ 2067 /* hook up the driver */
2016 driver->driver.bus = 0; 2068 driver->driver.bus = NULL;
2017 udc->driver = driver; 2069 udc->driver = driver;
2018 udc->gadget.dev.driver = &driver->driver; 2070 udc->gadget.dev.driver = &driver->driver;
2019 spin_unlock_irqrestore(&udc->lock, flags); 2071 spin_unlock_irqrestore(&udc->lock, flags);
@@ -2021,8 +2073,8 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2021 status = driver->bind (&udc->gadget); 2073 status = driver->bind (&udc->gadget);
2022 if (status) { 2074 if (status) {
2023 DBG("bind to %s --> %d\n", driver->driver.name, status); 2075 DBG("bind to %s --> %d\n", driver->driver.name, status);
2024 udc->gadget.dev.driver = 0; 2076 udc->gadget.dev.driver = NULL;
2025 udc->driver = 0; 2077 udc->driver = NULL;
2026 goto done; 2078 goto done;
2027 } 2079 }
2028 DBG("bound to driver %s\n", driver->driver.name); 2080 DBG("bound to driver %s\n", driver->driver.name);
@@ -2035,8 +2087,8 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2035 if (status < 0) { 2087 if (status < 0) {
2036 ERR("can't bind to transceiver\n"); 2088 ERR("can't bind to transceiver\n");
2037 driver->unbind (&udc->gadget); 2089 driver->unbind (&udc->gadget);
2038 udc->gadget.dev.driver = 0; 2090 udc->gadget.dev.driver = NULL;
2039 udc->driver = 0; 2091 udc->driver = NULL;
2040 goto done; 2092 goto done;
2041 } 2093 }
2042 } else { 2094 } else {
@@ -2071,7 +2123,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2071 omap_vbus_session(&udc->gadget, 0); 2123 omap_vbus_session(&udc->gadget, 0);
2072 2124
2073 if (udc->transceiver) 2125 if (udc->transceiver)
2074 (void) otg_set_peripheral(udc->transceiver, 0); 2126 (void) otg_set_peripheral(udc->transceiver, NULL);
2075 else 2127 else
2076 pullup_disable(udc); 2128 pullup_disable(udc);
2077 2129
@@ -2080,9 +2132,8 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2080 spin_unlock_irqrestore(&udc->lock, flags); 2132 spin_unlock_irqrestore(&udc->lock, flags);
2081 2133
2082 driver->unbind(&udc->gadget); 2134 driver->unbind(&udc->gadget);
2083 udc->gadget.dev.driver = 0; 2135 udc->gadget.dev.driver = NULL;
2084 udc->driver = 0; 2136 udc->driver = NULL;
2085
2086 2137
2087 DBG("unregistered driver '%s'\n", driver->driver.name); 2138 DBG("unregistered driver '%s'\n", driver->driver.name);
2088 return status; 2139 return status;
@@ -2178,14 +2229,14 @@ static int proc_otg_show(struct seq_file *s)
2178 2229
2179 tmp = OTG_REV_REG; 2230 tmp = OTG_REV_REG;
2180 trans = USB_TRANSCEIVER_CTRL_REG; 2231 trans = USB_TRANSCEIVER_CTRL_REG;
2181 seq_printf(s, "OTG rev %d.%d, transceiver_ctrl %03x\n", 2232 seq_printf(s, "\nOTG rev %d.%d, transceiver_ctrl %05x\n",
2182 tmp >> 4, tmp & 0xf, trans); 2233 tmp >> 4, tmp & 0xf, trans);
2183 tmp = OTG_SYSCON_1_REG; 2234 tmp = OTG_SYSCON_1_REG;
2184 seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s," 2235 seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s,"
2185 FOURBITS "\n", tmp, 2236 FOURBITS "\n", tmp,
2186 trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R), 2237 trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R),
2187 trx_mode(USB1_TRX_MODE(tmp), trans & CONF_USB1_UNI_R), 2238 trx_mode(USB1_TRX_MODE(tmp), trans & CONF_USB1_UNI_R),
2188 (USB0_TRX_MODE(tmp) == 0) 2239 (USB0_TRX_MODE(tmp) == 0 && !cpu_is_omap1710())
2189 ? "internal" 2240 ? "internal"
2190 : trx_mode(USB0_TRX_MODE(tmp), 1), 2241 : trx_mode(USB0_TRX_MODE(tmp), 1),
2191 (tmp & OTG_IDLE_EN) ? " !otg" : "", 2242 (tmp & OTG_IDLE_EN) ? " !otg" : "",
@@ -2235,6 +2286,7 @@ static int proc_otg_show(struct seq_file *s)
2235 seq_printf(s, "otg_outctrl %04x" "\n", tmp); 2286 seq_printf(s, "otg_outctrl %04x" "\n", tmp);
2236 tmp = OTG_TEST_REG; 2287 tmp = OTG_TEST_REG;
2237 seq_printf(s, "otg_test %04x" "\n", tmp); 2288 seq_printf(s, "otg_test %04x" "\n", tmp);
2289 return 0;
2238} 2290}
2239 2291
2240static int proc_udc_show(struct seq_file *s, void *_) 2292static int proc_udc_show(struct seq_file *s, void *_)
@@ -2378,7 +2430,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
2378 2430
2379static int proc_udc_open(struct inode *inode, struct file *file) 2431static int proc_udc_open(struct inode *inode, struct file *file)
2380{ 2432{
2381 return single_open(file, proc_udc_show, 0); 2433 return single_open(file, proc_udc_show, NULL);
2382} 2434}
2383 2435
2384static struct file_operations proc_ops = { 2436static struct file_operations proc_ops = {
@@ -2399,7 +2451,7 @@ static void create_proc_file(void)
2399 2451
2400static void remove_proc_file(void) 2452static void remove_proc_file(void)
2401{ 2453{
2402 remove_proc_entry(proc_filename, 0); 2454 remove_proc_entry(proc_filename, NULL);
2403} 2455}
2404 2456
2405#else 2457#else
@@ -2414,6 +2466,10 @@ static inline void remove_proc_file(void) {}
2414/* Before this controller can enumerate, we need to pick an endpoint 2466/* Before this controller can enumerate, we need to pick an endpoint
2415 * configuration, or "fifo_mode" That involves allocating 2KB of packet 2467 * configuration, or "fifo_mode" That involves allocating 2KB of packet
2416 * buffer space among the endpoints we'll be operating. 2468 * buffer space among the endpoints we'll be operating.
2469 *
2470 * NOTE: as of OMAP 1710 ES2.0, writing a new endpoint config when
2471 * UDC_SYSCON_1_REG.CFG_LOCK is set can now work. We won't use that
2472 * capability yet though.
2417 */ 2473 */
2418static unsigned __init 2474static unsigned __init
2419omap_ep_setup(char *name, u8 addr, u8 type, 2475omap_ep_setup(char *name, u8 addr, u8 type,
@@ -2505,7 +2561,7 @@ static void omap_udc_release(struct device *dev)
2505{ 2561{
2506 complete(udc->done); 2562 complete(udc->done);
2507 kfree (udc); 2563 kfree (udc);
2508 udc = 0; 2564 udc = NULL;
2509} 2565}
2510 2566
2511static int __init 2567static int __init
@@ -2577,23 +2633,33 @@ omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv)
2577 case 1: 2633 case 1:
2578 OMAP_BULK_EP("ep1in", USB_DIR_IN | 1); 2634 OMAP_BULK_EP("ep1in", USB_DIR_IN | 1);
2579 OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2); 2635 OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2);
2636 OMAP_INT_EP("ep9in", USB_DIR_IN | 9, 16);
2637
2580 OMAP_BULK_EP("ep3in", USB_DIR_IN | 3); 2638 OMAP_BULK_EP("ep3in", USB_DIR_IN | 3);
2581 OMAP_BULK_EP("ep4out", USB_DIR_OUT | 4); 2639 OMAP_BULK_EP("ep4out", USB_DIR_OUT | 4);
2640 OMAP_INT_EP("ep10in", USB_DIR_IN | 10, 16);
2582 2641
2583 OMAP_BULK_EP("ep5in", USB_DIR_IN | 5); 2642 OMAP_BULK_EP("ep5in", USB_DIR_IN | 5);
2584 OMAP_BULK_EP("ep5out", USB_DIR_OUT | 5); 2643 OMAP_BULK_EP("ep5out", USB_DIR_OUT | 5);
2644 OMAP_INT_EP("ep11in", USB_DIR_IN | 11, 16);
2645
2585 OMAP_BULK_EP("ep6in", USB_DIR_IN | 6); 2646 OMAP_BULK_EP("ep6in", USB_DIR_IN | 6);
2586 OMAP_BULK_EP("ep6out", USB_DIR_OUT | 6); 2647 OMAP_BULK_EP("ep6out", USB_DIR_OUT | 6);
2648 OMAP_INT_EP("ep12in", USB_DIR_IN | 12, 16);
2587 2649
2588 OMAP_BULK_EP("ep7in", USB_DIR_IN | 7); 2650 OMAP_BULK_EP("ep7in", USB_DIR_IN | 7);
2589 OMAP_BULK_EP("ep7out", USB_DIR_OUT | 7); 2651 OMAP_BULK_EP("ep7out", USB_DIR_OUT | 7);
2652 OMAP_INT_EP("ep13in", USB_DIR_IN | 13, 16);
2653 OMAP_INT_EP("ep13out", USB_DIR_OUT | 13, 16);
2654
2590 OMAP_BULK_EP("ep8in", USB_DIR_IN | 8); 2655 OMAP_BULK_EP("ep8in", USB_DIR_IN | 8);
2591 OMAP_BULK_EP("ep8out", USB_DIR_OUT | 8); 2656 OMAP_BULK_EP("ep8out", USB_DIR_OUT | 8);
2657 OMAP_INT_EP("ep14in", USB_DIR_IN | 14, 16);
2658 OMAP_INT_EP("ep14out", USB_DIR_OUT | 14, 16);
2659
2660 OMAP_BULK_EP("ep15in", USB_DIR_IN | 15);
2661 OMAP_BULK_EP("ep15out", USB_DIR_OUT | 15);
2592 2662
2593 OMAP_INT_EP("ep9in", USB_DIR_IN | 9, 16);
2594 OMAP_INT_EP("ep10out", USB_DIR_IN | 10, 16);
2595 OMAP_INT_EP("ep11in", USB_DIR_IN | 9, 16);
2596 OMAP_INT_EP("ep12out", USB_DIR_IN | 10, 16);
2597 break; 2663 break;
2598 2664
2599#ifdef USE_ISO 2665#ifdef USE_ISO
@@ -2640,8 +2706,8 @@ static int __init omap_udc_probe(struct device *dev)
2640 struct platform_device *odev = to_platform_device(dev); 2706 struct platform_device *odev = to_platform_device(dev);
2641 int status = -ENODEV; 2707 int status = -ENODEV;
2642 int hmc; 2708 int hmc;
2643 struct otg_transceiver *xceiv = 0; 2709 struct otg_transceiver *xceiv = NULL;
2644 const char *type = 0; 2710 const char *type = NULL;
2645 struct omap_usb_config *config = dev->platform_data; 2711 struct omap_usb_config *config = dev->platform_data;
2646 2712
2647 /* NOTE: "knows" the order of the resources! */ 2713 /* NOTE: "knows" the order of the resources! */
@@ -2676,54 +2742,78 @@ static int __init omap_udc_probe(struct device *dev)
2676 FUNC_MUX_CTRL_0_REG = tmp; 2742 FUNC_MUX_CTRL_0_REG = tmp;
2677 } 2743 }
2678 } else { 2744 } else {
2745 /* The transceiver may package some GPIO logic or handle
2746 * loopback and/or transceiverless setup; if we find one,
2747 * use it. Except for OTG, we don't _need_ to talk to one;
2748 * but not having one probably means no VBUS detection.
2749 */
2750 xceiv = otg_get_transceiver();
2751 if (xceiv)
2752 type = xceiv->label;
2753 else if (config->otg) {
2754 DBG("OTG requires external transceiver!\n");
2755 goto cleanup0;
2756 }
2757
2679 hmc = HMC_1610; 2758 hmc = HMC_1610;
2680 switch (hmc) { 2759 switch (hmc) {
2760 case 0: /* POWERUP DEFAULT == 0 */
2761 case 4:
2762 case 12:
2763 case 20:
2764 if (!cpu_is_omap1710()) {
2765 type = "integrated";
2766 break;
2767 }
2768 /* FALL THROUGH */
2681 case 3: 2769 case 3:
2682 case 11: 2770 case 11:
2683 case 16: 2771 case 16:
2684 case 19: 2772 case 19:
2685 case 25: 2773 case 25:
2686 xceiv = otg_get_transceiver();
2687 if (!xceiv) { 2774 if (!xceiv) {
2688 DBG("external transceiver not registered!\n"); 2775 DBG("external transceiver not registered!\n");
2689 if (config->otg) 2776 type = "unknown";
2690 goto cleanup0; 2777 }
2691 type = "(unknown external)";
2692 } else
2693 type = xceiv->label;
2694 break;
2695 case 0: /* POWERUP DEFAULT == 0 */
2696 case 4:
2697 case 12:
2698 case 20:
2699 type = "INTEGRATED";
2700 break; 2778 break;
2701 case 21: /* internal loopback */ 2779 case 21: /* internal loopback */
2702 type = "(loopback)"; 2780 type = "loopback";
2703 break; 2781 break;
2704 case 14: /* transceiverless */ 2782 case 14: /* transceiverless */
2705 type = "(none)"; 2783 if (cpu_is_omap1710())
2784 goto bad_on_1710;
2785 /* FALL THROUGH */
2786 case 13:
2787 case 15:
2788 type = "no";
2706 break; 2789 break;
2707 2790
2708 default: 2791 default:
2792bad_on_1710:
2709 ERR("unrecognized UDC HMC mode %d\n", hmc); 2793 ERR("unrecognized UDC HMC mode %d\n", hmc);
2710 return -ENODEV; 2794 goto cleanup0;
2711 } 2795 }
2712 } 2796 }
2713 INFO("hmc mode %d, transceiver %s\n", hmc, type); 2797 INFO("hmc mode %d, %s transceiver\n", hmc, type);
2714 2798
2715 /* a "gadget" abstracts/virtualizes the controller */ 2799 /* a "gadget" abstracts/virtualizes the controller */
2716 status = omap_udc_setup(odev, xceiv); 2800 status = omap_udc_setup(odev, xceiv);
2717 if (status) { 2801 if (status) {
2718 goto cleanup0; 2802 goto cleanup0;
2719 } 2803 }
2720 xceiv = 0; 2804 xceiv = NULL;
2721 // "udc" is now valid 2805 // "udc" is now valid
2722 pullup_disable(udc); 2806 pullup_disable(udc);
2723#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) 2807#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
2724 udc->gadget.is_otg = (config->otg != 0); 2808 udc->gadget.is_otg = (config->otg != 0);
2725#endif 2809#endif
2726 2810
2811 /* starting with omap1710 es2.0, clear toggle is a separate bit */
2812 if (UDC_REV_REG >= 0x61)
2813 udc->clr_halt = UDC_RESET_EP | UDC_CLRDATA_TOGGLE;
2814 else
2815 udc->clr_halt = UDC_RESET_EP;
2816
2727 /* USB general purpose IRQ: ep0, state changes, dma, etc */ 2817 /* USB general purpose IRQ: ep0, state changes, dma, etc */
2728 status = request_irq(odev->resource[1].start, omap_udc_irq, 2818 status = request_irq(odev->resource[1].start, omap_udc_irq,
2729 SA_SAMPLE_RANDOM, driver_name, udc); 2819 SA_SAMPLE_RANDOM, driver_name, udc);
@@ -2765,7 +2855,7 @@ cleanup2:
2765 2855
2766cleanup1: 2856cleanup1:
2767 kfree (udc); 2857 kfree (udc);
2768 udc = 0; 2858 udc = NULL;
2769 2859
2770cleanup0: 2860cleanup0:
2771 if (xceiv) 2861 if (xceiv)
@@ -2788,7 +2878,7 @@ static int __exit omap_udc_remove(struct device *dev)
2788 pullup_disable(udc); 2878 pullup_disable(udc);
2789 if (udc->transceiver) { 2879 if (udc->transceiver) {
2790 put_device(udc->transceiver->dev); 2880 put_device(udc->transceiver->dev);
2791 udc->transceiver = 0; 2881 udc->transceiver = NULL;
2792 } 2882 }
2793 UDC_SYSCON1_REG = 0; 2883 UDC_SYSCON1_REG = 0;
2794 2884
@@ -2809,13 +2899,32 @@ static int __exit omap_udc_remove(struct device *dev)
2809 return 0; 2899 return 0;
2810} 2900}
2811 2901
2812static int omap_udc_suspend(struct device *dev, pm_message_t state, u32 level) 2902/* suspend/resume/wakeup from sysfs (echo > power/state) or when the
2903 * system is forced into deep sleep
2904 *
2905 * REVISIT we should probably reject suspend requests when there's a host
2906 * session active, rather than disconnecting, at least on boards that can
2907 * report VBUS irqs (UDC_DEVSTAT_REG.UDC_ATT). And in any case, we need to
2908 * make host resumes and VBUS detection trigger OMAP wakeup events; that
2909 * may involve talking to an external transceiver (e.g. isp1301).
2910 */
2911static int omap_udc_suspend(struct device *dev, pm_message_t message, u32 level)
2813{ 2912{
2814 if (level != 0) 2913 u32 devstat;
2914
2915 if (level != SUSPEND_POWER_DOWN)
2815 return 0; 2916 return 0;
2917 devstat = UDC_DEVSTAT_REG;
2918
2919 /* we're requesting 48 MHz clock if the pullup is enabled
2920 * (== we're attached to the host) and we're not suspended,
2921 * which would prevent entry to deep sleep...
2922 */
2923 if ((devstat & UDC_ATT) != 0 && (devstat & UDC_SUS) == 0) {
2924 WARN("session active; suspend requires disconnect\n");
2925 omap_pullup(&udc->gadget, 0);
2926 }
2816 2927
2817 DBG("suspend, state %d\n", state);
2818 omap_pullup(&udc->gadget, 0);
2819 udc->gadget.dev.power.power_state = PMSG_SUSPEND; 2928 udc->gadget.dev.power.power_state = PMSG_SUSPEND;
2820 udc->gadget.dev.parent->power.power_state = PMSG_SUSPEND; 2929 udc->gadget.dev.parent->power.power_state = PMSG_SUSPEND;
2821 return 0; 2930 return 0;
@@ -2823,7 +2932,7 @@ static int omap_udc_suspend(struct device *dev, pm_message_t state, u32 level)
2823 2932
2824static int omap_udc_resume(struct device *dev, u32 level) 2933static int omap_udc_resume(struct device *dev, u32 level)
2825{ 2934{
2826 if (level != 0) 2935 if (level != RESUME_POWER_ON)
2827 return 0; 2936 return 0;
2828 2937
2829 DBG("resume + wakeup/SRP\n"); 2938 DBG("resume + wakeup/SRP\n");
diff --git a/drivers/usb/gadget/omap_udc.h b/drivers/usb/gadget/omap_udc.h
index c9e68541622c..652ee4627344 100644
--- a/drivers/usb/gadget/omap_udc.h
+++ b/drivers/usb/gadget/omap_udc.h
@@ -20,6 +20,7 @@
20#define UDC_CTRL_REG UDC_REG(0x0C) /* Endpoint control */ 20#define UDC_CTRL_REG UDC_REG(0x0C) /* Endpoint control */
21# define UDC_CLR_HALT (1 << 7) 21# define UDC_CLR_HALT (1 << 7)
22# define UDC_SET_HALT (1 << 6) 22# define UDC_SET_HALT (1 << 6)
23# define UDC_CLRDATA_TOGGLE (1 << 3)
23# define UDC_SET_FIFO_EN (1 << 2) 24# define UDC_SET_FIFO_EN (1 << 2)
24# define UDC_CLR_EP (1 << 1) 25# define UDC_CLR_EP (1 << 1)
25# define UDC_RESET_EP (1 << 0) 26# define UDC_RESET_EP (1 << 0)
@@ -99,6 +100,7 @@
99 100
100/* DMA configuration registers: up to three channels in each direction. */ 101/* DMA configuration registers: up to three channels in each direction. */
101#define UDC_RXDMA_CFG_REG UDC_REG(0x40) /* 3 eps for RX DMA */ 102#define UDC_RXDMA_CFG_REG UDC_REG(0x40) /* 3 eps for RX DMA */
103# define UDC_DMA_REQ (1 << 12)
102#define UDC_TXDMA_CFG_REG UDC_REG(0x44) /* 3 eps for TX DMA */ 104#define UDC_TXDMA_CFG_REG UDC_REG(0x44) /* 3 eps for TX DMA */
103#define UDC_DATA_DMA_REG UDC_REG(0x48) /* rx/tx fifo addr */ 105#define UDC_DATA_DMA_REG UDC_REG(0x48) /* rx/tx fifo addr */
104 106
@@ -162,6 +164,7 @@ struct omap_udc {
162 spinlock_t lock; 164 spinlock_t lock;
163 struct omap_ep ep[32]; 165 struct omap_ep ep[32];
164 u16 devstat; 166 u16 devstat;
167 u16 clr_halt;
165 struct otg_transceiver *transceiver; 168 struct otg_transceiver *transceiver;
166 struct list_head iso; 169 struct list_head iso;
167 unsigned softconnect:1; 170 unsigned softconnect:1;
@@ -171,7 +174,6 @@ struct omap_udc {
171 unsigned ep0_set_config:1; 174 unsigned ep0_set_config:1;
172 unsigned ep0_reset_config:1; 175 unsigned ep0_reset_config:1;
173 unsigned ep0_setup:1; 176 unsigned ep0_setup:1;
174
175 struct completion *done; 177 struct completion *done;
176}; 178};
177 179
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index b8b4524ed746..6a0b957af335 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * linux/drivers/usb/gadget/pxa2xx_udc.c 2 * linux/drivers/usb/gadget/pxa2xx_udc.c
3 * Intel PXA2xx and IXP4xx on-chip full speed USB device controllers 3 * Intel PXA25x and IXP4xx on-chip full speed USB device controllers
4 * 4 *
5 * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker) 5 * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker)
6 * Copyright (C) 2003 Robert Schwebel, Pengutronix 6 * Copyright (C) 2003 Robert Schwebel, Pengutronix
@@ -63,7 +63,7 @@
63 63
64 64
65/* 65/*
66 * This driver handles the USB Device Controller (UDC) in Intel's PXA 2xx 66 * This driver handles the USB Device Controller (UDC) in Intel's PXA 25x
67 * series processors. The UDC for the IXP 4xx series is very similar. 67 * series processors. The UDC for the IXP 4xx series is very similar.
68 * There are fifteen endpoints, in addition to ep0. 68 * There are fifteen endpoints, in addition to ep0.
69 * 69 *
@@ -79,8 +79,8 @@
79 * pxa250 a0/a1 b0/b1/b2 sure act like they're still there. 79 * pxa250 a0/a1 b0/b1/b2 sure act like they're still there.
80 */ 80 */
81 81
82#define DRIVER_VERSION "14-Dec-2003" 82#define DRIVER_VERSION "4-May-2005"
83#define DRIVER_DESC "PXA 2xx USB Device Controller driver" 83#define DRIVER_DESC "PXA 25x USB Device Controller driver"
84 84
85 85
86static const char driver_name [] = "pxa2xx_udc"; 86static const char driver_name [] = "pxa2xx_udc";
@@ -290,6 +290,7 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep,
290static int pxa2xx_ep_disable (struct usb_ep *_ep) 290static int pxa2xx_ep_disable (struct usb_ep *_ep)
291{ 291{
292 struct pxa2xx_ep *ep; 292 struct pxa2xx_ep *ep;
293 unsigned long flags;
293 294
294 ep = container_of (_ep, struct pxa2xx_ep, ep); 295 ep = container_of (_ep, struct pxa2xx_ep, ep);
295 if (!_ep || !ep->desc) { 296 if (!_ep || !ep->desc) {
@@ -297,6 +298,8 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep)
297 _ep ? ep->ep.name : NULL); 298 _ep ? ep->ep.name : NULL);
298 return -EINVAL; 299 return -EINVAL;
299 } 300 }
301 local_irq_save(flags);
302
300 nuke (ep, -ESHUTDOWN); 303 nuke (ep, -ESHUTDOWN);
301 304
302#ifdef USE_DMA 305#ifdef USE_DMA
@@ -313,6 +316,7 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep)
313 ep->desc = NULL; 316 ep->desc = NULL;
314 ep->stopped = 1; 317 ep->stopped = 1;
315 318
319 local_irq_restore(flags);
316 DBG(DBG_VERBOSE, "%s disabled\n", _ep->name); 320 DBG(DBG_VERBOSE, "%s disabled\n", _ep->name);
317 return 0; 321 return 0;
318} 322}
@@ -971,10 +975,10 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
971 kick_dma(ep, req); 975 kick_dma(ep, req);
972#endif 976#endif
973 /* can the FIFO can satisfy the request immediately? */ 977 /* can the FIFO can satisfy the request immediately? */
974 } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0 978 } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0) {
975 && (*ep->reg_udccs & UDCCS_BI_TFS) != 0 979 if ((*ep->reg_udccs & UDCCS_BI_TFS) != 0
976 && write_fifo(ep, req)) { 980 && write_fifo(ep, req))
977 req = NULL; 981 req = NULL;
978 } else if ((*ep->reg_udccs & UDCCS_BO_RFS) != 0 982 } else if ((*ep->reg_udccs & UDCCS_BO_RFS) != 0
979 && read_fifo(ep, req)) { 983 && read_fifo(ep, req)) {
980 req = NULL; 984 req = NULL;
@@ -1290,7 +1294,7 @@ udc_proc_read(char *page, char **start, off_t off, int count,
1290 "%s version: %s\nGadget driver: %s\nHost %s\n\n", 1294 "%s version: %s\nGadget driver: %s\nHost %s\n\n",
1291 driver_name, DRIVER_VERSION SIZE_STR DMASTR, 1295 driver_name, DRIVER_VERSION SIZE_STR DMASTR,
1292 dev->driver ? dev->driver->driver.name : "(none)", 1296 dev->driver ? dev->driver->driver.name : "(none)",
1293 is_usb_connected() ? "full speed" : "disconnected"); 1297 is_vbus_present() ? "full speed" : "disconnected");
1294 size -= t; 1298 size -= t;
1295 next += t; 1299 next += t;
1296 1300
@@ -1339,7 +1343,7 @@ udc_proc_read(char *page, char **start, off_t off, int count,
1339 next += t; 1343 next += t;
1340 } 1344 }
1341 1345
1342 if (!is_usb_connected() || !dev->driver) 1346 if (!is_vbus_present() || !dev->driver)
1343 goto done; 1347 goto done;
1344 1348
1345 t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n", 1349 t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
@@ -1454,7 +1458,7 @@ static void udc_disable(struct pxa2xx_udc *dev)
1454 UFNRH = UFNRH_SIM; 1458 UFNRH = UFNRH_SIM;
1455 1459
1456 /* if hardware supports it, disconnect from usb */ 1460 /* if hardware supports it, disconnect from usb */
1457 make_usb_disappear(); 1461 pullup_off();
1458 1462
1459 udc_clear_mask_UDCCR(UDCCR_UDE); 1463 udc_clear_mask_UDCCR(UDCCR_UDE);
1460 1464
@@ -1567,7 +1571,7 @@ static void udc_enable (struct pxa2xx_udc *dev)
1567 UICR0 &= ~UICR0_IM0; 1571 UICR0 &= ~UICR0_IM0;
1568 1572
1569 /* if hardware supports it, pullup D+ and wait for reset */ 1573 /* if hardware supports it, pullup D+ and wait for reset */
1570 let_usb_appear(); 1574 pullup_on();
1571} 1575}
1572 1576
1573 1577
@@ -2052,10 +2056,10 @@ pxa2xx_udc_irq(int irq, void *_dev, struct pt_regs *r)
2052 if (unlikely(udccr & UDCCR_SUSIR)) { 2056 if (unlikely(udccr & UDCCR_SUSIR)) {
2053 udc_ack_int_UDCCR(UDCCR_SUSIR); 2057 udc_ack_int_UDCCR(UDCCR_SUSIR);
2054 handled = 1; 2058 handled = 1;
2055 DBG(DBG_VERBOSE, "USB suspend%s\n", is_usb_connected() 2059 DBG(DBG_VERBOSE, "USB suspend%s\n", is_vbus_present()
2056 ? "" : "+disconnect"); 2060 ? "" : "+disconnect");
2057 2061
2058 if (!is_usb_connected()) 2062 if (!is_vbus_present())
2059 stop_activity(dev, dev->driver); 2063 stop_activity(dev, dev->driver);
2060 else if (dev->gadget.speed != USB_SPEED_UNKNOWN 2064 else if (dev->gadget.speed != USB_SPEED_UNKNOWN
2061 && dev->driver 2065 && dev->driver
@@ -2073,7 +2077,7 @@ pxa2xx_udc_irq(int irq, void *_dev, struct pt_regs *r)
2073 if (dev->gadget.speed != USB_SPEED_UNKNOWN 2077 if (dev->gadget.speed != USB_SPEED_UNKNOWN
2074 && dev->driver 2078 && dev->driver
2075 && dev->driver->resume 2079 && dev->driver->resume
2076 && is_usb_connected()) 2080 && is_vbus_present())
2077 dev->driver->resume(&dev->gadget); 2081 dev->driver->resume(&dev->gadget);
2078 } 2082 }
2079 2083
@@ -2509,7 +2513,7 @@ static int __init pxa2xx_udc_probe(struct device *_dev)
2509 udc_disable(dev); 2513 udc_disable(dev);
2510 udc_reinit(dev); 2514 udc_reinit(dev);
2511 2515
2512 dev->vbus = is_usb_connected(); 2516 dev->vbus = is_vbus_present();
2513 2517
2514 /* irq setup after old hardware state is cleaned up */ 2518 /* irq setup after old hardware state is cleaned up */
2515 retval = request_irq(IRQ_USB, pxa2xx_udc_irq, 2519 retval = request_irq(IRQ_USB, pxa2xx_udc_irq,
@@ -2555,6 +2559,12 @@ lubbock_fail0:
2555 2559
2556 return 0; 2560 return 0;
2557} 2561}
2562
2563static void pxa2xx_udc_shutdown(struct device *_dev)
2564{
2565 pullup_off();
2566}
2567
2558static int __exit pxa2xx_udc_remove(struct device *_dev) 2568static int __exit pxa2xx_udc_remove(struct device *_dev)
2559{ 2569{
2560 struct pxa2xx_udc *dev = dev_get_drvdata(_dev); 2570 struct pxa2xx_udc *dev = dev_get_drvdata(_dev);
@@ -2624,6 +2634,7 @@ static struct device_driver udc_driver = {
2624 .name = "pxa2xx-udc", 2634 .name = "pxa2xx-udc",
2625 .bus = &platform_bus_type, 2635 .bus = &platform_bus_type,
2626 .probe = pxa2xx_udc_probe, 2636 .probe = pxa2xx_udc_probe,
2637 .shutdown = pxa2xx_udc_shutdown,
2627 .remove = __exit_p(pxa2xx_udc_remove), 2638 .remove = __exit_p(pxa2xx_udc_remove),
2628 .suspend = pxa2xx_udc_suspend, 2639 .suspend = pxa2xx_udc_suspend,
2629 .resume = pxa2xx_udc_resume, 2640 .resume = pxa2xx_udc_resume,
diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h
index 1f3a7d999da7..d0bc396a85d5 100644
--- a/drivers/usb/gadget/pxa2xx_udc.h
+++ b/drivers/usb/gadget/pxa2xx_udc.h
@@ -177,23 +177,23 @@ struct pxa2xx_udc {
177 177
178static struct pxa2xx_udc *the_controller; 178static struct pxa2xx_udc *the_controller;
179 179
180/* one GPIO should be used to detect host disconnect */ 180/* one GPIO should be used to detect VBUS from the host */
181static inline int is_usb_connected(void) 181static inline int is_vbus_present(void)
182{ 182{
183 if (!the_controller->mach->udc_is_connected) 183 if (!the_controller->mach->udc_is_connected)
184 return 1; 184 return 1;
185 return the_controller->mach->udc_is_connected(); 185 return the_controller->mach->udc_is_connected();
186} 186}
187 187
188/* one GPIO should force the host to see this device (or not) */ 188/* one GPIO should control a D+ pullup, so host sees this device (or not) */
189static inline void make_usb_disappear(void) 189static inline void pullup_off(void)
190{ 190{
191 if (!the_controller->mach->udc_command) 191 if (!the_controller->mach->udc_command)
192 return; 192 return;
193 the_controller->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); 193 the_controller->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
194} 194}
195 195
196static inline void let_usb_appear(void) 196static inline void pullup_on(void)
197{ 197{
198 if (!the_controller->mach->udc_command) 198 if (!the_controller->mach->udc_command)
199 return; 199 return;
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 7457268d5f28..06b6eba925b5 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -41,6 +41,7 @@
41 41
42 42
43#undef RNDIS_PM 43#undef RNDIS_PM
44#undef RNDIS_WAKEUP
44#undef VERBOSE 45#undef VERBOSE
45 46
46#include "rndis.h" 47#include "rndis.h"
@@ -60,7 +61,7 @@
60 } while (0) 61 } while (0)
61static int rndis_debug = 0; 62static int rndis_debug = 0;
62 63
63module_param (rndis_debug, bool, 0); 64module_param (rndis_debug, int, 0);
64MODULE_PARM_DESC (rndis_debug, "enable debugging"); 65MODULE_PARM_DESC (rndis_debug, "enable debugging");
65 66
66#else 67#else
@@ -78,22 +79,103 @@ static rndis_params rndis_per_dev_params [RNDIS_MAX_CONFIGS];
78static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1); 79static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1);
79 80
80/* Function Prototypes */ 81/* Function Prototypes */
81static int rndis_init_response (int configNr, rndis_init_msg_type *buf);
82static int rndis_query_response (int configNr, rndis_query_msg_type *buf);
83static int rndis_set_response (int configNr, rndis_set_msg_type *buf);
84static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf);
85static int rndis_keepalive_response (int configNr,
86 rndis_keepalive_msg_type *buf);
87
88static rndis_resp_t *rndis_add_response (int configNr, u32 length); 82static rndis_resp_t *rndis_add_response (int configNr, u32 length);
89 83
90 84
85/* supported OIDs */
86static const u32 oid_supported_list [] =
87{
88 /* the general stuff */
89 OID_GEN_SUPPORTED_LIST,
90 OID_GEN_HARDWARE_STATUS,
91 OID_GEN_MEDIA_SUPPORTED,
92 OID_GEN_MEDIA_IN_USE,
93 OID_GEN_MAXIMUM_FRAME_SIZE,
94 OID_GEN_LINK_SPEED,
95 OID_GEN_TRANSMIT_BLOCK_SIZE,
96 OID_GEN_RECEIVE_BLOCK_SIZE,
97 OID_GEN_VENDOR_ID,
98 OID_GEN_VENDOR_DESCRIPTION,
99 OID_GEN_VENDOR_DRIVER_VERSION,
100 OID_GEN_CURRENT_PACKET_FILTER,
101 OID_GEN_MAXIMUM_TOTAL_SIZE,
102 OID_GEN_MEDIA_CONNECT_STATUS,
103 OID_GEN_PHYSICAL_MEDIUM,
104#if 0
105 OID_GEN_RNDIS_CONFIG_PARAMETER,
106#endif
107
108 /* the statistical stuff */
109 OID_GEN_XMIT_OK,
110 OID_GEN_RCV_OK,
111 OID_GEN_XMIT_ERROR,
112 OID_GEN_RCV_ERROR,
113 OID_GEN_RCV_NO_BUFFER,
114#ifdef RNDIS_OPTIONAL_STATS
115 OID_GEN_DIRECTED_BYTES_XMIT,
116 OID_GEN_DIRECTED_FRAMES_XMIT,
117 OID_GEN_MULTICAST_BYTES_XMIT,
118 OID_GEN_MULTICAST_FRAMES_XMIT,
119 OID_GEN_BROADCAST_BYTES_XMIT,
120 OID_GEN_BROADCAST_FRAMES_XMIT,
121 OID_GEN_DIRECTED_BYTES_RCV,
122 OID_GEN_DIRECTED_FRAMES_RCV,
123 OID_GEN_MULTICAST_BYTES_RCV,
124 OID_GEN_MULTICAST_FRAMES_RCV,
125 OID_GEN_BROADCAST_BYTES_RCV,
126 OID_GEN_BROADCAST_FRAMES_RCV,
127 OID_GEN_RCV_CRC_ERROR,
128 OID_GEN_TRANSMIT_QUEUE_LENGTH,
129#endif /* RNDIS_OPTIONAL_STATS */
130
131 /* mandatory 802.3 */
132 /* the general stuff */
133 OID_802_3_PERMANENT_ADDRESS,
134 OID_802_3_CURRENT_ADDRESS,
135 OID_802_3_MULTICAST_LIST,
136 OID_802_3_MAC_OPTIONS,
137 OID_802_3_MAXIMUM_LIST_SIZE,
138
139 /* the statistical stuff */
140 OID_802_3_RCV_ERROR_ALIGNMENT,
141 OID_802_3_XMIT_ONE_COLLISION,
142 OID_802_3_XMIT_MORE_COLLISIONS,
143#ifdef RNDIS_OPTIONAL_STATS
144 OID_802_3_XMIT_DEFERRED,
145 OID_802_3_XMIT_MAX_COLLISIONS,
146 OID_802_3_RCV_OVERRUN,
147 OID_802_3_XMIT_UNDERRUN,
148 OID_802_3_XMIT_HEARTBEAT_FAILURE,
149 OID_802_3_XMIT_TIMES_CRS_LOST,
150 OID_802_3_XMIT_LATE_COLLISIONS,
151#endif /* RNDIS_OPTIONAL_STATS */
152
153#ifdef RNDIS_PM
154 /* PM and wakeup are mandatory for USB: */
155
156 /* power management */
157 OID_PNP_CAPABILITIES,
158 OID_PNP_QUERY_POWER,
159 OID_PNP_SET_POWER,
160
161#ifdef RNDIS_WAKEUP
162 /* wake up host */
163 OID_PNP_ENABLE_WAKE_UP,
164 OID_PNP_ADD_WAKE_UP_PATTERN,
165 OID_PNP_REMOVE_WAKE_UP_PATTERN,
166#endif /* RNDIS_WAKEUP */
167#endif /* RNDIS_PM */
168};
169
170
91/* NDIS Functions */ 171/* NDIS Functions */
92static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r) 172static int
173gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
174 rndis_resp_t *r)
93{ 175{
94 int retval = -ENOTSUPP; 176 int retval = -ENOTSUPP;
95 u32 length = 0; 177 u32 length = 4; /* usually */
96 __le32 *tmp; 178 __le32 *outbuf;
97 int i, count; 179 int i, count;
98 rndis_query_cmplt_type *resp; 180 rndis_query_cmplt_type *resp;
99 181
@@ -101,7 +183,22 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
101 resp = (rndis_query_cmplt_type *) r->buf; 183 resp = (rndis_query_cmplt_type *) r->buf;
102 184
103 if (!resp) return -ENOMEM; 185 if (!resp) return -ENOMEM;
104 186
187 if (buf_len && rndis_debug > 1) {
188 DEBUG("query OID %08x value, len %d:\n", OID, buf_len);
189 for (i = 0; i < buf_len; i += 16) {
190 DEBUG ("%03d: %08x %08x %08x %08x\n", i,
191 le32_to_cpup((__le32 *)&buf[i]),
192 le32_to_cpup((__le32 *)&buf[i + 4]),
193 le32_to_cpup((__le32 *)&buf[i + 8]),
194 le32_to_cpup((__le32 *)&buf[i + 12]));
195 }
196 }
197
198 /* response goes here, right after the header */
199 outbuf = (__le32 *) &resp[1];
200 resp->InformationBufferOffset = __constant_cpu_to_le32 (16);
201
105 switch (OID) { 202 switch (OID) {
106 203
107 /* general oids (table 4-1) */ 204 /* general oids (table 4-1) */
@@ -111,42 +208,36 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
111 DEBUG ("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__); 208 DEBUG ("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__);
112 length = sizeof (oid_supported_list); 209 length = sizeof (oid_supported_list);
113 count = length / sizeof (u32); 210 count = length / sizeof (u32);
114 tmp = (__le32 *) ((u8 *)resp + 24);
115 for (i = 0; i < count; i++) 211 for (i = 0; i < count; i++)
116 tmp[i] = cpu_to_le32 (oid_supported_list[i]); 212 outbuf[i] = cpu_to_le32 (oid_supported_list[i]);
117 retval = 0; 213 retval = 0;
118 break; 214 break;
119 215
120 /* mandatory */ 216 /* mandatory */
121 case OID_GEN_HARDWARE_STATUS: 217 case OID_GEN_HARDWARE_STATUS:
122 DEBUG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__); 218 DEBUG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__);
123 length = 4;
124 /* Bogus question! 219 /* Bogus question!
125 * Hardware must be ready to receive high level protocols. 220 * Hardware must be ready to receive high level protocols.
126 * BTW: 221 * BTW:
127 * reddite ergo quae sunt Caesaris Caesari 222 * reddite ergo quae sunt Caesaris Caesari
128 * et quae sunt Dei Deo! 223 * et quae sunt Dei Deo!
129 */ 224 */
130 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 225 *outbuf = __constant_cpu_to_le32 (0);
131 retval = 0; 226 retval = 0;
132 break; 227 break;
133 228
134 /* mandatory */ 229 /* mandatory */
135 case OID_GEN_MEDIA_SUPPORTED: 230 case OID_GEN_MEDIA_SUPPORTED:
136 DEBUG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__); 231 DEBUG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__);
137 length = 4; 232 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
138 *((__le32 *) resp + 6) = cpu_to_le32 (
139 rndis_per_dev_params [configNr].medium);
140 retval = 0; 233 retval = 0;
141 break; 234 break;
142 235
143 /* mandatory */ 236 /* mandatory */
144 case OID_GEN_MEDIA_IN_USE: 237 case OID_GEN_MEDIA_IN_USE:
145 DEBUG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__); 238 DEBUG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__);
146 length = 4;
147 /* one medium, one transport... (maybe you do it better) */ 239 /* one medium, one transport... (maybe you do it better) */
148 *((__le32 *) resp + 6) = cpu_to_le32 ( 240 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
149 rndis_per_dev_params [configNr].medium);
150 retval = 0; 241 retval = 0;
151 break; 242 break;
152 243
@@ -154,25 +245,21 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
154 case OID_GEN_MAXIMUM_FRAME_SIZE: 245 case OID_GEN_MAXIMUM_FRAME_SIZE:
155 DEBUG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__); 246 DEBUG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__);
156 if (rndis_per_dev_params [configNr].dev) { 247 if (rndis_per_dev_params [configNr].dev) {
157 length = 4; 248 *outbuf = cpu_to_le32 (
158 *((__le32 *) resp + 6) = cpu_to_le32 (
159 rndis_per_dev_params [configNr].dev->mtu); 249 rndis_per_dev_params [configNr].dev->mtu);
160 retval = 0; 250 retval = 0;
161 } else {
162 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
163 retval = 0;
164 } 251 }
165 break; 252 break;
166 253
167 /* mandatory */ 254 /* mandatory */
168 case OID_GEN_LINK_SPEED: 255 case OID_GEN_LINK_SPEED:
169// DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__); 256 if (rndis_debug > 1)
170 length = 4; 257 DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__);
171 if (rndis_per_dev_params [configNr].media_state 258 if (rndis_per_dev_params [configNr].media_state
172 == NDIS_MEDIA_STATE_DISCONNECTED) 259 == NDIS_MEDIA_STATE_DISCONNECTED)
173 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 260 *outbuf = __constant_cpu_to_le32 (0);
174 else 261 else
175 *((__le32 *) resp + 6) = cpu_to_le32 ( 262 *outbuf = cpu_to_le32 (
176 rndis_per_dev_params [configNr].speed); 263 rndis_per_dev_params [configNr].speed);
177 retval = 0; 264 retval = 0;
178 break; 265 break;
@@ -181,8 +268,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
181 case OID_GEN_TRANSMIT_BLOCK_SIZE: 268 case OID_GEN_TRANSMIT_BLOCK_SIZE:
182 DEBUG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__); 269 DEBUG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__);
183 if (rndis_per_dev_params [configNr].dev) { 270 if (rndis_per_dev_params [configNr].dev) {
184 length = 4; 271 *outbuf = cpu_to_le32 (
185 *((__le32 *) resp + 6) = cpu_to_le32 (
186 rndis_per_dev_params [configNr].dev->mtu); 272 rndis_per_dev_params [configNr].dev->mtu);
187 retval = 0; 273 retval = 0;
188 } 274 }
@@ -192,8 +278,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
192 case OID_GEN_RECEIVE_BLOCK_SIZE: 278 case OID_GEN_RECEIVE_BLOCK_SIZE:
193 DEBUG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__); 279 DEBUG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__);
194 if (rndis_per_dev_params [configNr].dev) { 280 if (rndis_per_dev_params [configNr].dev) {
195 length = 4; 281 *outbuf = cpu_to_le32 (
196 *((__le32 *) resp + 6) = cpu_to_le32 (
197 rndis_per_dev_params [configNr].dev->mtu); 282 rndis_per_dev_params [configNr].dev->mtu);
198 retval = 0; 283 retval = 0;
199 } 284 }
@@ -202,8 +287,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
202 /* mandatory */ 287 /* mandatory */
203 case OID_GEN_VENDOR_ID: 288 case OID_GEN_VENDOR_ID:
204 DEBUG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__); 289 DEBUG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__);
205 length = 4; 290 *outbuf = cpu_to_le32 (
206 *((__le32 *) resp + 6) = cpu_to_le32 (
207 rndis_per_dev_params [configNr].vendorID); 291 rndis_per_dev_params [configNr].vendorID);
208 retval = 0; 292 retval = 0;
209 break; 293 break;
@@ -212,51 +296,44 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
212 case OID_GEN_VENDOR_DESCRIPTION: 296 case OID_GEN_VENDOR_DESCRIPTION:
213 DEBUG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__); 297 DEBUG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__);
214 length = strlen (rndis_per_dev_params [configNr].vendorDescr); 298 length = strlen (rndis_per_dev_params [configNr].vendorDescr);
215 memcpy ((u8 *) resp + 24, 299 memcpy (outbuf,
216 rndis_per_dev_params [configNr].vendorDescr, length); 300 rndis_per_dev_params [configNr].vendorDescr, length);
217 retval = 0; 301 retval = 0;
218 break; 302 break;
219 303
220 case OID_GEN_VENDOR_DRIVER_VERSION: 304 case OID_GEN_VENDOR_DRIVER_VERSION:
221 DEBUG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__); 305 DEBUG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__);
222 length = 4;
223 /* Created as LE */ 306 /* Created as LE */
224 *((__le32 *) resp + 6) = rndis_driver_version; 307 *outbuf = rndis_driver_version;
225 retval = 0; 308 retval = 0;
226 break; 309 break;
227 310
228 /* mandatory */ 311 /* mandatory */
229 case OID_GEN_CURRENT_PACKET_FILTER: 312 case OID_GEN_CURRENT_PACKET_FILTER:
230 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__); 313 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__);
231 length = 4; 314 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter);
232 *((__le32 *) resp + 6) = cpu_to_le32 (
233 rndis_per_dev_params[configNr].filter);
234 retval = 0; 315 retval = 0;
235 break; 316 break;
236 317
237 /* mandatory */ 318 /* mandatory */
238 case OID_GEN_MAXIMUM_TOTAL_SIZE: 319 case OID_GEN_MAXIMUM_TOTAL_SIZE:
239 DEBUG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__); 320 DEBUG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__);
240 length = 4; 321 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
241 *((__le32 *) resp + 6) = __constant_cpu_to_le32(
242 RNDIS_MAX_TOTAL_SIZE);
243 retval = 0; 322 retval = 0;
244 break; 323 break;
245 324
246 /* mandatory */ 325 /* mandatory */
247 case OID_GEN_MEDIA_CONNECT_STATUS: 326 case OID_GEN_MEDIA_CONNECT_STATUS:
248 DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__); 327 if (rndis_debug > 1)
249 length = 4; 328 DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__);
250 *((__le32 *) resp + 6) = cpu_to_le32 ( 329 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
251 rndis_per_dev_params [configNr]
252 .media_state); 330 .media_state);
253 retval = 0; 331 retval = 0;
254 break; 332 break;
255 333
256 case OID_GEN_PHYSICAL_MEDIUM: 334 case OID_GEN_PHYSICAL_MEDIUM:
257 DEBUG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__); 335 DEBUG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__);
258 length = 4; 336 *outbuf = __constant_cpu_to_le32 (0);
259 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
260 retval = 0; 337 retval = 0;
261 break; 338 break;
262 339
@@ -266,8 +343,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
266 */ 343 */
267 case OID_GEN_MAC_OPTIONS: /* from WinME */ 344 case OID_GEN_MAC_OPTIONS: /* from WinME */
268 DEBUG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__); 345 DEBUG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__);
269 length = 4; 346 *outbuf = __constant_cpu_to_le32(
270 *((__le32 *) resp + 6) = __constant_cpu_to_le32(
271 NDIS_MAC_OPTION_RECEIVE_SERIALIZED 347 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
272 | NDIS_MAC_OPTION_FULL_DUPLEX); 348 | NDIS_MAC_OPTION_FULL_DUPLEX);
273 retval = 0; 349 retval = 0;
@@ -277,62 +353,49 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
277 353
278 /* mandatory */ 354 /* mandatory */
279 case OID_GEN_XMIT_OK: 355 case OID_GEN_XMIT_OK:
280 DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__); 356 if (rndis_debug > 1)
357 DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__);
281 if (rndis_per_dev_params [configNr].stats) { 358 if (rndis_per_dev_params [configNr].stats) {
282 length = 4; 359 *outbuf = cpu_to_le32 (
283 *((__le32 *) resp + 6) = cpu_to_le32 (
284 rndis_per_dev_params [configNr].stats->tx_packets - 360 rndis_per_dev_params [configNr].stats->tx_packets -
285 rndis_per_dev_params [configNr].stats->tx_errors - 361 rndis_per_dev_params [configNr].stats->tx_errors -
286 rndis_per_dev_params [configNr].stats->tx_dropped); 362 rndis_per_dev_params [configNr].stats->tx_dropped);
287 retval = 0; 363 retval = 0;
288 } else {
289 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
290 retval = 0;
291 } 364 }
292 break; 365 break;
293 366
294 /* mandatory */ 367 /* mandatory */
295 case OID_GEN_RCV_OK: 368 case OID_GEN_RCV_OK:
296 DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__); 369 if (rndis_debug > 1)
370 DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__);
297 if (rndis_per_dev_params [configNr].stats) { 371 if (rndis_per_dev_params [configNr].stats) {
298 length = 4; 372 *outbuf = cpu_to_le32 (
299 *((__le32 *) resp + 6) = cpu_to_le32 (
300 rndis_per_dev_params [configNr].stats->rx_packets - 373 rndis_per_dev_params [configNr].stats->rx_packets -
301 rndis_per_dev_params [configNr].stats->rx_errors - 374 rndis_per_dev_params [configNr].stats->rx_errors -
302 rndis_per_dev_params [configNr].stats->rx_dropped); 375 rndis_per_dev_params [configNr].stats->rx_dropped);
303 retval = 0; 376 retval = 0;
304 } else {
305 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
306 retval = 0;
307 } 377 }
308 break; 378 break;
309 379
310 /* mandatory */ 380 /* mandatory */
311 case OID_GEN_XMIT_ERROR: 381 case OID_GEN_XMIT_ERROR:
312 DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__); 382 if (rndis_debug > 1)
383 DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__);
313 if (rndis_per_dev_params [configNr].stats) { 384 if (rndis_per_dev_params [configNr].stats) {
314 length = 4; 385 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
315 *((__le32 *) resp + 6) = cpu_to_le32 (
316 rndis_per_dev_params [configNr]
317 .stats->tx_errors); 386 .stats->tx_errors);
318 retval = 0; 387 retval = 0;
319 } else {
320 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
321 retval = 0;
322 } 388 }
323 break; 389 break;
324 390
325 /* mandatory */ 391 /* mandatory */
326 case OID_GEN_RCV_ERROR: 392 case OID_GEN_RCV_ERROR:
327 DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__); 393 if (rndis_debug > 1)
394 DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__);
328 if (rndis_per_dev_params [configNr].stats) { 395 if (rndis_per_dev_params [configNr].stats) {
329 *((__le32 *) resp + 6) = cpu_to_le32 ( 396 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
330 rndis_per_dev_params [configNr]
331 .stats->rx_errors); 397 .stats->rx_errors);
332 retval = 0; 398 retval = 0;
333 } else {
334 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
335 retval = 0;
336 } 399 }
337 break; 400 break;
338 401
@@ -340,13 +403,9 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
340 case OID_GEN_RCV_NO_BUFFER: 403 case OID_GEN_RCV_NO_BUFFER:
341 DEBUG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__); 404 DEBUG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__);
342 if (rndis_per_dev_params [configNr].stats) { 405 if (rndis_per_dev_params [configNr].stats) {
343 *((__le32 *) resp + 6) = cpu_to_le32 ( 406 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
344 rndis_per_dev_params [configNr]
345 .stats->rx_dropped); 407 .stats->rx_dropped);
346 retval = 0; 408 retval = 0;
347 } else {
348 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
349 retval = 0;
350 } 409 }
351 break; 410 break;
352 411
@@ -359,8 +418,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
359 * divided by weight of Alpha Centauri 418 * divided by weight of Alpha Centauri
360 */ 419 */
361 if (rndis_per_dev_params [configNr].stats) { 420 if (rndis_per_dev_params [configNr].stats) {
362 length = 4; 421 *outbuf = cpu_to_le32 (
363 *((__le32 *) resp + 6) = cpu_to_le32 (
364 (rndis_per_dev_params [configNr] 422 (rndis_per_dev_params [configNr]
365 .stats->tx_packets - 423 .stats->tx_packets -
366 rndis_per_dev_params [configNr] 424 rndis_per_dev_params [configNr]
@@ -369,9 +427,6 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
369 .stats->tx_dropped) 427 .stats->tx_dropped)
370 * 123); 428 * 123);
371 retval = 0; 429 retval = 0;
372 } else {
373 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
374 retval = 0;
375 } 430 }
376 break; 431 break;
377 432
@@ -379,8 +434,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
379 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__); 434 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__);
380 /* dito */ 435 /* dito */
381 if (rndis_per_dev_params [configNr].stats) { 436 if (rndis_per_dev_params [configNr].stats) {
382 length = 4; 437 *outbuf = cpu_to_le32 (
383 *((__le32 *) resp + 6) = cpu_to_le32 (
384 (rndis_per_dev_params [configNr] 438 (rndis_per_dev_params [configNr]
385 .stats->tx_packets - 439 .stats->tx_packets -
386 rndis_per_dev_params [configNr] 440 rndis_per_dev_params [configNr]
@@ -389,144 +443,105 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
389 .stats->tx_dropped) 443 .stats->tx_dropped)
390 / 123); 444 / 123);
391 retval = 0; 445 retval = 0;
392 } else {
393 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
394 retval = 0;
395 } 446 }
396 break; 447 break;
397 448
398 case OID_GEN_MULTICAST_BYTES_XMIT: 449 case OID_GEN_MULTICAST_BYTES_XMIT:
399 DEBUG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__); 450 DEBUG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__);
400 if (rndis_per_dev_params [configNr].stats) { 451 if (rndis_per_dev_params [configNr].stats) {
401 *((__le32 *) resp + 6) = cpu_to_le32 ( 452 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
402 rndis_per_dev_params [configNr]
403 .stats->multicast*1234); 453 .stats->multicast*1234);
404 retval = 0; 454 retval = 0;
405 } else {
406 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
407 retval = 0;
408 } 455 }
409 break; 456 break;
410 457
411 case OID_GEN_MULTICAST_FRAMES_XMIT: 458 case OID_GEN_MULTICAST_FRAMES_XMIT:
412 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__); 459 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__);
413 if (rndis_per_dev_params [configNr].stats) { 460 if (rndis_per_dev_params [configNr].stats) {
414 *((__le32 *) resp + 6) = cpu_to_le32 ( 461 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
415 rndis_per_dev_params [configNr]
416 .stats->multicast); 462 .stats->multicast);
417 retval = 0; 463 retval = 0;
418 } else {
419 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
420 retval = 0;
421 } 464 }
422 break; 465 break;
423 466
424 case OID_GEN_BROADCAST_BYTES_XMIT: 467 case OID_GEN_BROADCAST_BYTES_XMIT:
425 DEBUG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__); 468 DEBUG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__);
426 if (rndis_per_dev_params [configNr].stats) { 469 if (rndis_per_dev_params [configNr].stats) {
427 *((__le32 *) resp + 6) = cpu_to_le32 ( 470 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
428 rndis_per_dev_params [configNr]
429 .stats->tx_packets/42*255); 471 .stats->tx_packets/42*255);
430 retval = 0; 472 retval = 0;
431 } else {
432 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
433 retval = 0;
434 } 473 }
435 break; 474 break;
436 475
437 case OID_GEN_BROADCAST_FRAMES_XMIT: 476 case OID_GEN_BROADCAST_FRAMES_XMIT:
438 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__); 477 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__);
439 if (rndis_per_dev_params [configNr].stats) { 478 if (rndis_per_dev_params [configNr].stats) {
440 *((__le32 *) resp + 6) = cpu_to_le32 ( 479 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
441 rndis_per_dev_params [configNr]
442 .stats->tx_packets/42); 480 .stats->tx_packets/42);
443 retval = 0; 481 retval = 0;
444 } else {
445 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
446 retval = 0;
447 } 482 }
448 break; 483 break;
449 484
450 case OID_GEN_DIRECTED_BYTES_RCV: 485 case OID_GEN_DIRECTED_BYTES_RCV:
451 DEBUG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__); 486 DEBUG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__);
452 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 487 *outbuf = __constant_cpu_to_le32 (0);
453 retval = 0; 488 retval = 0;
454 break; 489 break;
455 490
456 case OID_GEN_DIRECTED_FRAMES_RCV: 491 case OID_GEN_DIRECTED_FRAMES_RCV:
457 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__); 492 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__);
458 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 493 *outbuf = __constant_cpu_to_le32 (0);
459 retval = 0; 494 retval = 0;
460 break; 495 break;
461 496
462 case OID_GEN_MULTICAST_BYTES_RCV: 497 case OID_GEN_MULTICAST_BYTES_RCV:
463 DEBUG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__); 498 DEBUG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__);
464 if (rndis_per_dev_params [configNr].stats) { 499 if (rndis_per_dev_params [configNr].stats) {
465 *((__le32 *) resp + 6) = cpu_to_le32 ( 500 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
466 rndis_per_dev_params [configNr]
467 .stats->multicast * 1111); 501 .stats->multicast * 1111);
468 retval = 0; 502 retval = 0;
469 } else {
470 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
471 retval = 0;
472 } 503 }
473 break; 504 break;
474 505
475 case OID_GEN_MULTICAST_FRAMES_RCV: 506 case OID_GEN_MULTICAST_FRAMES_RCV:
476 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__); 507 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__);
477 if (rndis_per_dev_params [configNr].stats) { 508 if (rndis_per_dev_params [configNr].stats) {
478 *((__le32 *) resp + 6) = cpu_to_le32 ( 509 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
479 rndis_per_dev_params [configNr]
480 .stats->multicast); 510 .stats->multicast);
481 retval = 0; 511 retval = 0;
482 } else {
483 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
484 retval = 0;
485 } 512 }
486 break; 513 break;
487 514
488 case OID_GEN_BROADCAST_BYTES_RCV: 515 case OID_GEN_BROADCAST_BYTES_RCV:
489 DEBUG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__); 516 DEBUG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__);
490 if (rndis_per_dev_params [configNr].stats) { 517 if (rndis_per_dev_params [configNr].stats) {
491 *((__le32 *) resp + 6) = cpu_to_le32 ( 518 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
492 rndis_per_dev_params [configNr]
493 .stats->rx_packets/42*255); 519 .stats->rx_packets/42*255);
494 retval = 0; 520 retval = 0;
495 } else {
496 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
497 retval = 0;
498 } 521 }
499 break; 522 break;
500 523
501 case OID_GEN_BROADCAST_FRAMES_RCV: 524 case OID_GEN_BROADCAST_FRAMES_RCV:
502 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__); 525 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__);
503 if (rndis_per_dev_params [configNr].stats) { 526 if (rndis_per_dev_params [configNr].stats) {
504 *((__le32 *) resp + 6) = cpu_to_le32 ( 527 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
505 rndis_per_dev_params [configNr]
506 .stats->rx_packets/42); 528 .stats->rx_packets/42);
507 retval = 0; 529 retval = 0;
508 } else {
509 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
510 retval = 0;
511 } 530 }
512 break; 531 break;
513 532
514 case OID_GEN_RCV_CRC_ERROR: 533 case OID_GEN_RCV_CRC_ERROR:
515 DEBUG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__); 534 DEBUG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__);
516 if (rndis_per_dev_params [configNr].stats) { 535 if (rndis_per_dev_params [configNr].stats) {
517 *((__le32 *) resp + 6) = cpu_to_le32 ( 536 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
518 rndis_per_dev_params [configNr]
519 .stats->rx_crc_errors); 537 .stats->rx_crc_errors);
520 retval = 0; 538 retval = 0;
521 } else {
522 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
523 retval = 0;
524 } 539 }
525 break; 540 break;
526 541
527 case OID_GEN_TRANSMIT_QUEUE_LENGTH: 542 case OID_GEN_TRANSMIT_QUEUE_LENGTH:
528 DEBUG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__); 543 DEBUG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__);
529 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 544 *outbuf = __constant_cpu_to_le32 (0);
530 retval = 0; 545 retval = 0;
531 break; 546 break;
532#endif /* RNDIS_OPTIONAL_STATS */ 547#endif /* RNDIS_OPTIONAL_STATS */
@@ -538,13 +553,10 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
538 DEBUG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__); 553 DEBUG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__);
539 if (rndis_per_dev_params [configNr].dev) { 554 if (rndis_per_dev_params [configNr].dev) {
540 length = ETH_ALEN; 555 length = ETH_ALEN;
541 memcpy ((u8 *) resp + 24, 556 memcpy (outbuf,
542 rndis_per_dev_params [configNr].host_mac, 557 rndis_per_dev_params [configNr].host_mac,
543 length); 558 length);
544 retval = 0; 559 retval = 0;
545 } else {
546 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
547 retval = 0;
548 } 560 }
549 break; 561 break;
550 562
@@ -553,7 +565,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
553 DEBUG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__); 565 DEBUG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__);
554 if (rndis_per_dev_params [configNr].dev) { 566 if (rndis_per_dev_params [configNr].dev) {
555 length = ETH_ALEN; 567 length = ETH_ALEN;
556 memcpy ((u8 *) resp + 24, 568 memcpy (outbuf,
557 rndis_per_dev_params [configNr].host_mac, 569 rndis_per_dev_params [configNr].host_mac,
558 length); 570 length);
559 retval = 0; 571 retval = 0;
@@ -563,18 +575,16 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
563 /* mandatory */ 575 /* mandatory */
564 case OID_802_3_MULTICAST_LIST: 576 case OID_802_3_MULTICAST_LIST:
565 DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__); 577 DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__);
566 length = 4;
567 /* Multicast base address only */ 578 /* Multicast base address only */
568 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0xE0000000); 579 *outbuf = __constant_cpu_to_le32 (0xE0000000);
569 retval = 0; 580 retval = 0;
570 break; 581 break;
571 582
572 /* mandatory */ 583 /* mandatory */
573 case OID_802_3_MAXIMUM_LIST_SIZE: 584 case OID_802_3_MAXIMUM_LIST_SIZE:
574 DEBUG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__); 585 DEBUG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__);
575 length = 4;
576 /* Multicast base address only */ 586 /* Multicast base address only */
577 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (1); 587 *outbuf = __constant_cpu_to_le32 (1);
578 retval = 0; 588 retval = 0;
579 break; 589 break;
580 590
@@ -587,11 +597,8 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
587 /* mandatory */ 597 /* mandatory */
588 case OID_802_3_RCV_ERROR_ALIGNMENT: 598 case OID_802_3_RCV_ERROR_ALIGNMENT:
589 DEBUG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__); 599 DEBUG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__);
590 if (rndis_per_dev_params [configNr].stats) 600 if (rndis_per_dev_params [configNr].stats) {
591 { 601 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
592 length = 4;
593 *((__le32 *) resp + 6) = cpu_to_le32 (
594 rndis_per_dev_params [configNr]
595 .stats->rx_frame_errors); 602 .stats->rx_frame_errors);
596 retval = 0; 603 retval = 0;
597 } 604 }
@@ -600,16 +607,14 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
600 /* mandatory */ 607 /* mandatory */
601 case OID_802_3_XMIT_ONE_COLLISION: 608 case OID_802_3_XMIT_ONE_COLLISION:
602 DEBUG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__); 609 DEBUG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__);
603 length = 4; 610 *outbuf = __constant_cpu_to_le32 (0);
604 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
605 retval = 0; 611 retval = 0;
606 break; 612 break;
607 613
608 /* mandatory */ 614 /* mandatory */
609 case OID_802_3_XMIT_MORE_COLLISIONS: 615 case OID_802_3_XMIT_MORE_COLLISIONS:
610 DEBUG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__); 616 DEBUG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__);
611 length = 4; 617 *outbuf = __constant_cpu_to_le32 (0);
612 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
613 retval = 0; 618 retval = 0;
614 break; 619 break;
615 620
@@ -655,27 +660,18 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
655 case OID_PNP_CAPABILITIES: 660 case OID_PNP_CAPABILITIES:
656 DEBUG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__); 661 DEBUG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__);
657 662
658 /* just PM, and remote wakeup on link status change 663 /* for now, no wakeup capabilities */
659 * (not magic packet or pattern match)
660 */
661 length = sizeof (struct NDIS_PNP_CAPABILITIES); 664 length = sizeof (struct NDIS_PNP_CAPABILITIES);
662 memset (resp, 0, length); 665 memset(outbuf, 0, length);
663 {
664 struct NDIS_PNP_CAPABILITIES *caps = (void *) resp;
665
666 caps->Flags = NDIS_DEVICE_WAKE_UP_ENABLE;
667 caps->WakeUpCapabilities.MinLinkChangeWakeUp
668 = NdisDeviceStateD3;
669
670 /* FIXME then use usb_gadget_wakeup(), and
671 * set USB_CONFIG_ATT_WAKEUP in config desc
672 */
673 }
674 retval = 0; 666 retval = 0;
675 break; 667 break;
676 case OID_PNP_QUERY_POWER: 668 case OID_PNP_QUERY_POWER:
677 DEBUG("%s: OID_PNP_QUERY_POWER\n", __FUNCTION__); 669 DEBUG("%s: OID_PNP_QUERY_POWER D%d\n", __FUNCTION__,
678 /* sure, handle any power state that maps to USB suspend */ 670 le32_to_cpup((__le32 *) buf) - 1);
671 /* only suspend is a real power state, and
672 * it can't be entered by OID_PNP_SET_POWER...
673 */
674 length = 0;
679 retval = 0; 675 retval = 0;
680 break; 676 break;
681#endif 677#endif
@@ -684,11 +680,12 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
684 printk (KERN_WARNING "%s: query unknown OID 0x%08X\n", 680 printk (KERN_WARNING "%s: query unknown OID 0x%08X\n",
685 __FUNCTION__, OID); 681 __FUNCTION__, OID);
686 } 682 }
683 if (retval < 0)
684 length = 0;
687 685
688 resp->InformationBufferOffset = __constant_cpu_to_le32 (16);
689 resp->InformationBufferLength = cpu_to_le32 (length); 686 resp->InformationBufferLength = cpu_to_le32 (length);
690 resp->MessageLength = cpu_to_le32 (24 + length); 687 r->length = length + sizeof *resp;
691 r->length = 24 + length; 688 resp->MessageLength = cpu_to_le32 (r->length);
692 return retval; 689 return retval;
693} 690}
694 691
@@ -705,45 +702,40 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
705 if (!resp) 702 if (!resp)
706 return -ENOMEM; 703 return -ENOMEM;
707 704
708 DEBUG("set OID %08x value, len %d:\n", OID, buf_len); 705 if (buf_len && rndis_debug > 1) {
709 for (i = 0; i < buf_len; i += 16) { 706 DEBUG("set OID %08x value, len %d:\n", OID, buf_len);
710 DEBUG ("%03d: " 707 for (i = 0; i < buf_len; i += 16) {
711 " %02x %02x %02x %02x" 708 DEBUG ("%03d: %08x %08x %08x %08x\n", i,
712 " %02x %02x %02x %02x" 709 le32_to_cpup((__le32 *)&buf[i]),
713 " %02x %02x %02x %02x" 710 le32_to_cpup((__le32 *)&buf[i + 4]),
714 " %02x %02x %02x %02x" 711 le32_to_cpup((__le32 *)&buf[i + 8]),
715 "\n", 712 le32_to_cpup((__le32 *)&buf[i + 12]));
716 i, 713 }
717 buf[i], buf [i+1],
718 buf[i+2], buf[i+3],
719 buf[i+4], buf [i+5],
720 buf[i+6], buf[i+7],
721 buf[i+8], buf [i+9],
722 buf[i+10], buf[i+11],
723 buf[i+12], buf [i+13],
724 buf[i+14], buf[i+15]);
725 } 714 }
726 715
716 params = &rndis_per_dev_params [configNr];
727 switch (OID) { 717 switch (OID) {
728 case OID_GEN_CURRENT_PACKET_FILTER: 718 case OID_GEN_CURRENT_PACKET_FILTER:
729 params = &rndis_per_dev_params [configNr];
730 retval = 0;
731 719
732 /* FIXME use these NDIS_PACKET_TYPE_* bitflags to 720 /* these NDIS_PACKET_TYPE_* bitflags are shared with
733 * set the cdc_filter; it's not RNDIS-specific 721 * cdc_filter; it's not RNDIS-specific
734 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in: 722 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in:
735 * PROMISCUOUS, DIRECTED, 723 * PROMISCUOUS, DIRECTED,
736 * MULTICAST, ALL_MULTICAST, BROADCAST 724 * MULTICAST, ALL_MULTICAST, BROADCAST
737 */ 725 */
738 params->filter = le32_to_cpup((__le32 *)buf); 726 *params->filter = (u16) le32_to_cpup((__le32 *)buf);
739 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", 727 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n",
740 __FUNCTION__, params->filter); 728 __FUNCTION__, *params->filter);
741 729
742 /* this call has a significant side effect: it's 730 /* this call has a significant side effect: it's
743 * what makes the packet flow start and stop, like 731 * what makes the packet flow start and stop, like
744 * activating the CDC Ethernet altsetting. 732 * activating the CDC Ethernet altsetting.
745 */ 733 */
746 if (params->filter) { 734#ifdef RNDIS_PM
735update_linkstate:
736#endif
737 retval = 0;
738 if (*params->filter) {
747 params->state = RNDIS_DATA_INITIALIZED; 739 params->state = RNDIS_DATA_INITIALIZED;
748 netif_carrier_on(params->dev); 740 netif_carrier_on(params->dev);
749 if (netif_running(params->dev)) 741 if (netif_running(params->dev))
@@ -776,21 +768,34 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
776 768
777#ifdef RNDIS_PM 769#ifdef RNDIS_PM
778 case OID_PNP_SET_POWER: 770 case OID_PNP_SET_POWER:
779 DEBUG ("OID_PNP_SET_POWER\n"); 771 /* The only real power state is USB suspend, and RNDIS requests
780 /* sure, handle any power state that maps to USB suspend */ 772 * can't enter it; this one isn't really about power. After
781 retval = 0; 773 * resuming, Windows forces a reset, and then SET_POWER D0.
782 break; 774 * FIXME ... then things go batty; Windows wedges itself.
783 775 */
784 case OID_PNP_ENABLE_WAKE_UP: 776 i = le32_to_cpup((__force __le32 *)buf);
785 /* always-connected ... */ 777 DEBUG("%s: OID_PNP_SET_POWER D%d\n", __FUNCTION__, i - 1);
786 DEBUG ("OID_PNP_ENABLE_WAKE_UP\n"); 778 switch (i) {
787 retval = 0; 779 case NdisDeviceStateD0:
780 *params->filter = params->saved_filter;
781 goto update_linkstate;
782 case NdisDeviceStateD3:
783 case NdisDeviceStateD2:
784 case NdisDeviceStateD1:
785 params->saved_filter = *params->filter;
786 retval = 0;
787 break;
788 }
788 break; 789 break;
789 790
790 // no PM resume patterns supported (specified where?) 791#ifdef RNDIS_WAKEUP
791 // so OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN always fails 792 // no wakeup support advertised, so wakeup OIDs always fail:
793 // - OID_PNP_ENABLE_WAKE_UP
794 // - OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN
792#endif 795#endif
793 796
797#endif /* RNDIS_PM */
798
794 default: 799 default:
795 printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n", 800 printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n",
796 __FUNCTION__, OID, buf_len); 801 __FUNCTION__, OID, buf_len);
@@ -811,13 +816,10 @@ static int rndis_init_response (int configNr, rndis_init_msg_type *buf)
811 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP; 816 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
812 817
813 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type)); 818 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type));
814 819 if (!r)
815 if (!r) return -ENOMEM; 820 return -ENOMEM;
816
817 resp = (rndis_init_cmplt_type *) r->buf; 821 resp = (rndis_init_cmplt_type *) r->buf;
818 822
819 if (!resp) return -ENOMEM;
820
821 resp->MessageType = __constant_cpu_to_le32 ( 823 resp->MessageType = __constant_cpu_to_le32 (
822 REMOTE_NDIS_INITIALIZE_CMPLT); 824 REMOTE_NDIS_INITIALIZE_CMPLT);
823 resp->MessageLength = __constant_cpu_to_le32 (52); 825 resp->MessageLength = __constant_cpu_to_le32 (52);
@@ -857,20 +859,22 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
857 * oid_supported_list is the largest answer 859 * oid_supported_list is the largest answer
858 */ 860 */
859 r = rndis_add_response (configNr, sizeof (oid_supported_list)); 861 r = rndis_add_response (configNr, sizeof (oid_supported_list));
860 862 if (!r)
861 if (!r) return -ENOMEM; 863 return -ENOMEM;
862 resp = (rndis_query_cmplt_type *) r->buf; 864 resp = (rndis_query_cmplt_type *) r->buf;
863 865
864 if (!resp) return -ENOMEM;
865
866 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT); 866 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT);
867 resp->MessageLength = __constant_cpu_to_le32 (24);
868 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 867 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
869 868
870 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID), r)) { 869 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID),
870 le32_to_cpu(buf->InformationBufferOffset)
871 + 8 + (u8 *) buf,
872 le32_to_cpu(buf->InformationBufferLength),
873 r)) {
871 /* OID not supported */ 874 /* OID not supported */
872 resp->Status = __constant_cpu_to_le32 ( 875 resp->Status = __constant_cpu_to_le32 (
873 RNDIS_STATUS_NOT_SUPPORTED); 876 RNDIS_STATUS_NOT_SUPPORTED);
877 resp->MessageLength = __constant_cpu_to_le32 (sizeof *resp);
874 resp->InformationBufferLength = __constant_cpu_to_le32 (0); 878 resp->InformationBufferLength = __constant_cpu_to_le32 (0);
875 resp->InformationBufferOffset = __constant_cpu_to_le32 (0); 879 resp->InformationBufferOffset = __constant_cpu_to_le32 (0);
876 } else 880 } else
@@ -889,10 +893,9 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
889 rndis_resp_t *r; 893 rndis_resp_t *r;
890 894
891 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type)); 895 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type));
892 896 if (!r)
893 if (!r) return -ENOMEM; 897 return -ENOMEM;
894 resp = (rndis_set_cmplt_type *) r->buf; 898 resp = (rndis_set_cmplt_type *) r->buf;
895 if (!resp) return -ENOMEM;
896 899
897 BufLength = le32_to_cpu (buf->InformationBufferLength); 900 BufLength = le32_to_cpu (buf->InformationBufferLength);
898 BufOffset = le32_to_cpu (buf->InformationBufferOffset); 901 BufOffset = le32_to_cpu (buf->InformationBufferOffset);
@@ -930,10 +933,9 @@ static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf)
930 rndis_resp_t *r; 933 rndis_resp_t *r;
931 934
932 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type)); 935 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type));
933 936 if (!r)
934 if (!r) return -ENOMEM; 937 return -ENOMEM;
935 resp = (rndis_reset_cmplt_type *) r->buf; 938 resp = (rndis_reset_cmplt_type *) r->buf;
936 if (!resp) return -ENOMEM;
937 939
938 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT); 940 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT);
939 resp->MessageLength = __constant_cpu_to_le32 (16); 941 resp->MessageLength = __constant_cpu_to_le32 (16);
@@ -957,8 +959,9 @@ static int rndis_keepalive_response (int configNr,
957 /* host "should" check only in RNDIS_DATA_INITIALIZED state */ 959 /* host "should" check only in RNDIS_DATA_INITIALIZED state */
958 960
959 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type)); 961 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type));
962 if (!r)
963 return -ENOMEM;
960 resp = (rndis_keepalive_cmplt_type *) r->buf; 964 resp = (rndis_keepalive_cmplt_type *) r->buf;
961 if (!resp) return -ENOMEM;
962 965
963 resp->MessageType = __constant_cpu_to_le32 ( 966 resp->MessageType = __constant_cpu_to_le32 (
964 REMOTE_NDIS_KEEPALIVE_CMPLT); 967 REMOTE_NDIS_KEEPALIVE_CMPLT);
@@ -987,10 +990,9 @@ static int rndis_indicate_status_msg (int configNr, u32 status)
987 990
988 r = rndis_add_response (configNr, 991 r = rndis_add_response (configNr,
989 sizeof (rndis_indicate_status_msg_type)); 992 sizeof (rndis_indicate_status_msg_type));
990 if (!r) return -ENOMEM; 993 if (!r)
991 994 return -ENOMEM;
992 resp = (rndis_indicate_status_msg_type *) r->buf; 995 resp = (rndis_indicate_status_msg_type *) r->buf;
993 if (!resp) return -ENOMEM;
994 996
995 resp->MessageType = __constant_cpu_to_le32 ( 997 resp->MessageType = __constant_cpu_to_le32 (
996 REMOTE_NDIS_INDICATE_STATUS_MSG); 998 REMOTE_NDIS_INDICATE_STATUS_MSG);
@@ -1021,6 +1023,21 @@ int rndis_signal_disconnect (int configNr)
1021 RNDIS_STATUS_MEDIA_DISCONNECT); 1023 RNDIS_STATUS_MEDIA_DISCONNECT);
1022} 1024}
1023 1025
1026void rndis_uninit (int configNr)
1027{
1028 u8 *buf;
1029 u32 length;
1030
1031 if (configNr >= RNDIS_MAX_CONFIGS)
1032 return;
1033 rndis_per_dev_params [configNr].used = 0;
1034 rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED;
1035
1036 /* drain the response queue */
1037 while ((buf = rndis_get_next_response(configNr, &length)))
1038 rndis_free_response(configNr, buf);
1039}
1040
1024void rndis_set_host_mac (int configNr, const u8 *addr) 1041void rndis_set_host_mac (int configNr, const u8 *addr)
1025{ 1042{
1026 rndis_per_dev_params [configNr].host_mac = addr; 1043 rndis_per_dev_params [configNr].host_mac = addr;
@@ -1046,9 +1063,13 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1046 return -ENOTSUPP; 1063 return -ENOTSUPP;
1047 params = &rndis_per_dev_params [configNr]; 1064 params = &rndis_per_dev_params [configNr];
1048 1065
1066 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
1067 * rx/tx statistics and link status, in addition to KEEPALIVE traffic
1068 * and normal HC level polling to see if there's any IN traffic.
1069 */
1070
1049 /* For USB: responses may take up to 10 seconds */ 1071 /* For USB: responses may take up to 10 seconds */
1050 switch (MsgType) 1072 switch (MsgType) {
1051 {
1052 case REMOTE_NDIS_INITIALIZE_MSG: 1073 case REMOTE_NDIS_INITIALIZE_MSG:
1053 DEBUG("%s: REMOTE_NDIS_INITIALIZE_MSG\n", 1074 DEBUG("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
1054 __FUNCTION__ ); 1075 __FUNCTION__ );
@@ -1082,10 +1103,9 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1082 1103
1083 case REMOTE_NDIS_KEEPALIVE_MSG: 1104 case REMOTE_NDIS_KEEPALIVE_MSG:
1084 /* For USB: host does this every 5 seconds */ 1105 /* For USB: host does this every 5 seconds */
1085#ifdef VERBOSE 1106 if (rndis_debug > 1)
1086 DEBUG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", 1107 DEBUG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
1087 __FUNCTION__ ); 1108 __FUNCTION__ );
1088#endif
1089 return rndis_keepalive_response (configNr, 1109 return rndis_keepalive_response (configNr,
1090 (rndis_keepalive_msg_type *) 1110 (rndis_keepalive_msg_type *)
1091 buf); 1111 buf);
@@ -1152,7 +1172,8 @@ void rndis_deregister (int configNr)
1152} 1172}
1153 1173
1154int rndis_set_param_dev (u8 configNr, struct net_device *dev, 1174int rndis_set_param_dev (u8 configNr, struct net_device *dev,
1155 struct net_device_stats *stats) 1175 struct net_device_stats *stats,
1176 u16 *cdc_filter)
1156{ 1177{
1157 DEBUG("%s:\n", __FUNCTION__ ); 1178 DEBUG("%s:\n", __FUNCTION__ );
1158 if (!dev || !stats) return -1; 1179 if (!dev || !stats) return -1;
@@ -1160,6 +1181,7 @@ int rndis_set_param_dev (u8 configNr, struct net_device *dev,
1160 1181
1161 rndis_per_dev_params [configNr].dev = dev; 1182 rndis_per_dev_params [configNr].dev = dev;
1162 rndis_per_dev_params [configNr].stats = stats; 1183 rndis_per_dev_params [configNr].stats = stats;
1184 rndis_per_dev_params [configNr].filter = cdc_filter;
1163 1185
1164 return 0; 1186 return 0;
1165} 1187}
@@ -1178,7 +1200,7 @@ int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr)
1178 1200
1179int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) 1201int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed)
1180{ 1202{
1181 DEBUG("%s:\n", __FUNCTION__ ); 1203 DEBUG("%s: %u %u\n", __FUNCTION__, medium, speed);
1182 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 1204 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1183 1205
1184 rndis_per_dev_params [configNr].medium = medium; 1206 rndis_per_dev_params [configNr].medium = medium;
@@ -1242,6 +1264,7 @@ static rndis_resp_t *rndis_add_response (int configNr, u32 length)
1242{ 1264{
1243 rndis_resp_t *r; 1265 rndis_resp_t *r;
1244 1266
1267 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
1245 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC); 1268 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC);
1246 if (!r) return NULL; 1269 if (!r) return NULL;
1247 1270
diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h
index 2b5b55df3cfd..95b4c6326100 100644
--- a/drivers/usb/gadget/rndis.h
+++ b/drivers/usb/gadget/rndis.h
@@ -69,90 +69,6 @@
69#define OID_PNP_ENABLE_WAKE_UP 0xFD010106 69#define OID_PNP_ENABLE_WAKE_UP 0xFD010106
70 70
71 71
72/* supported OIDs */
73static const u32 oid_supported_list [] =
74{
75 /* the general stuff */
76 OID_GEN_SUPPORTED_LIST,
77 OID_GEN_HARDWARE_STATUS,
78 OID_GEN_MEDIA_SUPPORTED,
79 OID_GEN_MEDIA_IN_USE,
80 OID_GEN_MAXIMUM_FRAME_SIZE,
81 OID_GEN_LINK_SPEED,
82 OID_GEN_TRANSMIT_BLOCK_SIZE,
83 OID_GEN_RECEIVE_BLOCK_SIZE,
84 OID_GEN_VENDOR_ID,
85 OID_GEN_VENDOR_DESCRIPTION,
86 OID_GEN_VENDOR_DRIVER_VERSION,
87 OID_GEN_CURRENT_PACKET_FILTER,
88 OID_GEN_MAXIMUM_TOTAL_SIZE,
89 OID_GEN_MEDIA_CONNECT_STATUS,
90 OID_GEN_PHYSICAL_MEDIUM,
91#if 0
92 OID_GEN_RNDIS_CONFIG_PARAMETER,
93#endif
94
95 /* the statistical stuff */
96 OID_GEN_XMIT_OK,
97 OID_GEN_RCV_OK,
98 OID_GEN_XMIT_ERROR,
99 OID_GEN_RCV_ERROR,
100 OID_GEN_RCV_NO_BUFFER,
101#ifdef RNDIS_OPTIONAL_STATS
102 OID_GEN_DIRECTED_BYTES_XMIT,
103 OID_GEN_DIRECTED_FRAMES_XMIT,
104 OID_GEN_MULTICAST_BYTES_XMIT,
105 OID_GEN_MULTICAST_FRAMES_XMIT,
106 OID_GEN_BROADCAST_BYTES_XMIT,
107 OID_GEN_BROADCAST_FRAMES_XMIT,
108 OID_GEN_DIRECTED_BYTES_RCV,
109 OID_GEN_DIRECTED_FRAMES_RCV,
110 OID_GEN_MULTICAST_BYTES_RCV,
111 OID_GEN_MULTICAST_FRAMES_RCV,
112 OID_GEN_BROADCAST_BYTES_RCV,
113 OID_GEN_BROADCAST_FRAMES_RCV,
114 OID_GEN_RCV_CRC_ERROR,
115 OID_GEN_TRANSMIT_QUEUE_LENGTH,
116#endif /* RNDIS_OPTIONAL_STATS */
117
118 /* mandatory 802.3 */
119 /* the general stuff */
120 OID_802_3_PERMANENT_ADDRESS,
121 OID_802_3_CURRENT_ADDRESS,
122 OID_802_3_MULTICAST_LIST,
123 OID_802_3_MAC_OPTIONS,
124 OID_802_3_MAXIMUM_LIST_SIZE,
125
126 /* the statistical stuff */
127 OID_802_3_RCV_ERROR_ALIGNMENT,
128 OID_802_3_XMIT_ONE_COLLISION,
129 OID_802_3_XMIT_MORE_COLLISIONS,
130#ifdef RNDIS_OPTIONAL_STATS
131 OID_802_3_XMIT_DEFERRED,
132 OID_802_3_XMIT_MAX_COLLISIONS,
133 OID_802_3_RCV_OVERRUN,
134 OID_802_3_XMIT_UNDERRUN,
135 OID_802_3_XMIT_HEARTBEAT_FAILURE,
136 OID_802_3_XMIT_TIMES_CRS_LOST,
137 OID_802_3_XMIT_LATE_COLLISIONS,
138#endif /* RNDIS_OPTIONAL_STATS */
139
140#ifdef RNDIS_PM
141 /* PM and wakeup are mandatory for USB: */
142
143 /* power management */
144 OID_PNP_CAPABILITIES,
145 OID_PNP_QUERY_POWER,
146 OID_PNP_SET_POWER,
147
148 /* wake up host */
149 OID_PNP_ENABLE_WAKE_UP,
150 OID_PNP_ADD_WAKE_UP_PATTERN,
151 OID_PNP_REMOVE_WAKE_UP_PATTERN,
152#endif
153};
154
155
156typedef struct rndis_init_msg_type 72typedef struct rndis_init_msg_type
157{ 73{
158 __le32 MessageType; 74 __le32 MessageType;
@@ -309,15 +225,18 @@ typedef struct rndis_resp_t
309typedef struct rndis_params 225typedef struct rndis_params
310{ 226{
311 u8 confignr; 227 u8 confignr;
312 int used; 228 u8 used;
229 u16 saved_filter;
313 enum rndis_state state; 230 enum rndis_state state;
314 u32 filter;
315 u32 medium; 231 u32 medium;
316 u32 speed; 232 u32 speed;
317 u32 media_state; 233 u32 media_state;
234
318 const u8 *host_mac; 235 const u8 *host_mac;
236 u16 *filter;
319 struct net_device *dev; 237 struct net_device *dev;
320 struct net_device_stats *stats; 238 struct net_device_stats *stats;
239
321 u32 vendorID; 240 u32 vendorID;
322 const char *vendorDescr; 241 const char *vendorDescr;
323 int (*ack) (struct net_device *); 242 int (*ack) (struct net_device *);
@@ -329,7 +248,8 @@ int rndis_msg_parser (u8 configNr, u8 *buf);
329int rndis_register (int (*rndis_control_ack) (struct net_device *)); 248int rndis_register (int (*rndis_control_ack) (struct net_device *));
330void rndis_deregister (int configNr); 249void rndis_deregister (int configNr);
331int rndis_set_param_dev (u8 configNr, struct net_device *dev, 250int rndis_set_param_dev (u8 configNr, struct net_device *dev,
332 struct net_device_stats *stats); 251 struct net_device_stats *stats,
252 u16 *cdc_filter);
333int rndis_set_param_vendor (u8 configNr, u32 vendorID, 253int rndis_set_param_vendor (u8 configNr, u32 vendorID,
334 const char *vendorDescr); 254 const char *vendorDescr);
335int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed); 255int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed);
@@ -338,6 +258,7 @@ int rndis_rm_hdr (struct sk_buff *skb);
338u8 *rndis_get_next_response (int configNr, u32 *length); 258u8 *rndis_get_next_response (int configNr, u32 *length);
339void rndis_free_response (int configNr, u8 *buf); 259void rndis_free_response (int configNr, u8 *buf);
340 260
261void rndis_uninit (int configNr);
341int rndis_signal_connect (int configNr); 262int rndis_signal_connect (int configNr);
342int rndis_signal_disconnect (int configNr); 263int rndis_signal_disconnect (int configNr);
343int rndis_state (int configNr); 264int rndis_state (int configNr);
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 4d591c764e38..9e4f1c6935a5 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -300,18 +300,18 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
300 u8 type, unsigned int index, int is_otg); 300 u8 type, unsigned int index, int is_otg);
301 301
302static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, 302static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len,
303 int kmalloc_flags); 303 unsigned kmalloc_flags);
304static void gs_free_req(struct usb_ep *ep, struct usb_request *req); 304static void gs_free_req(struct usb_ep *ep, struct usb_request *req);
305 305
306static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, 306static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len,
307 int kmalloc_flags); 307 unsigned kmalloc_flags);
308static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req); 308static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req);
309 309
310static int gs_alloc_ports(struct gs_dev *dev, int kmalloc_flags); 310static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags);
311static void gs_free_ports(struct gs_dev *dev); 311static void gs_free_ports(struct gs_dev *dev);
312 312
313/* circular buffer */ 313/* circular buffer */
314static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags); 314static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags);
315static void gs_buf_free(struct gs_buf *gb); 315static void gs_buf_free(struct gs_buf *gb);
316static void gs_buf_clear(struct gs_buf *gb); 316static void gs_buf_clear(struct gs_buf *gb);
317static unsigned int gs_buf_data_avail(struct gs_buf *gb); 317static unsigned int gs_buf_data_avail(struct gs_buf *gb);
@@ -1607,9 +1607,9 @@ static int gs_setup(struct usb_gadget *gadget,
1607 int ret = -EOPNOTSUPP; 1607 int ret = -EOPNOTSUPP;
1608 struct gs_dev *dev = get_gadget_data(gadget); 1608 struct gs_dev *dev = get_gadget_data(gadget);
1609 struct usb_request *req = dev->dev_ctrl_req; 1609 struct usb_request *req = dev->dev_ctrl_req;
1610 u16 wIndex = ctrl->wIndex; 1610 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1611 u16 wValue = ctrl->wValue; 1611 u16 wValue = le16_to_cpu(ctrl->wValue);
1612 u16 wLength = ctrl->wLength; 1612 u16 wLength = le16_to_cpu(ctrl->wLength);
1613 1613
1614 switch (ctrl->bRequestType & USB_TYPE_MASK) { 1614 switch (ctrl->bRequestType & USB_TYPE_MASK) {
1615 case USB_TYPE_STANDARD: 1615 case USB_TYPE_STANDARD:
@@ -1651,9 +1651,9 @@ static int gs_setup_standard(struct usb_gadget *gadget,
1651 int ret = -EOPNOTSUPP; 1651 int ret = -EOPNOTSUPP;
1652 struct gs_dev *dev = get_gadget_data(gadget); 1652 struct gs_dev *dev = get_gadget_data(gadget);
1653 struct usb_request *req = dev->dev_ctrl_req; 1653 struct usb_request *req = dev->dev_ctrl_req;
1654 u16 wIndex = ctrl->wIndex; 1654 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1655 u16 wValue = ctrl->wValue; 1655 u16 wValue = le16_to_cpu(ctrl->wValue);
1656 u16 wLength = ctrl->wLength; 1656 u16 wLength = le16_to_cpu(ctrl->wLength);
1657 1657
1658 switch (ctrl->bRequest) { 1658 switch (ctrl->bRequest) {
1659 case USB_REQ_GET_DESCRIPTOR: 1659 case USB_REQ_GET_DESCRIPTOR:
@@ -1782,9 +1782,9 @@ static int gs_setup_class(struct usb_gadget *gadget,
1782 struct gs_dev *dev = get_gadget_data(gadget); 1782 struct gs_dev *dev = get_gadget_data(gadget);
1783 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */ 1783 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */
1784 struct usb_request *req = dev->dev_ctrl_req; 1784 struct usb_request *req = dev->dev_ctrl_req;
1785 u16 wIndex = ctrl->wIndex; 1785 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1786 u16 wValue = ctrl->wValue; 1786 u16 wValue = le16_to_cpu(ctrl->wValue);
1787 u16 wLength = ctrl->wLength; 1787 u16 wLength = le16_to_cpu(ctrl->wLength);
1788 1788
1789 switch (ctrl->bRequest) { 1789 switch (ctrl->bRequest) {
1790 case USB_CDC_REQ_SET_LINE_CODING: 1790 case USB_CDC_REQ_SET_LINE_CODING:
@@ -2119,7 +2119,8 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
2119 * Allocate a usb_request and its buffer. Returns a pointer to the 2119 * Allocate a usb_request and its buffer. Returns a pointer to the
2120 * usb_request or NULL if there is an error. 2120 * usb_request or NULL if there is an error.
2121 */ 2121 */
2122static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, int kmalloc_flags) 2122static struct usb_request *
2123gs_alloc_req(struct usb_ep *ep, unsigned int len, unsigned kmalloc_flags)
2123{ 2124{
2124 struct usb_request *req; 2125 struct usb_request *req;
2125 2126
@@ -2159,7 +2160,8 @@ static void gs_free_req(struct usb_ep *ep, struct usb_request *req)
2159 * Allocates a request and its buffer, using the given 2160 * Allocates a request and its buffer, using the given
2160 * endpoint, buffer len, and kmalloc flags. 2161 * endpoint, buffer len, and kmalloc flags.
2161 */ 2162 */
2162static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, int kmalloc_flags) 2163static struct gs_req_entry *
2164gs_alloc_req_entry(struct usb_ep *ep, unsigned len, unsigned kmalloc_flags)
2163{ 2165{
2164 struct gs_req_entry *req; 2166 struct gs_req_entry *req;
2165 2167
@@ -2200,7 +2202,7 @@ static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req)
2200 * 2202 *
2201 * The device lock is normally held when calling this function. 2203 * The device lock is normally held when calling this function.
2202 */ 2204 */
2203static int gs_alloc_ports(struct gs_dev *dev, int kmalloc_flags) 2205static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags)
2204{ 2206{
2205 int i; 2207 int i;
2206 struct gs_port *port; 2208 struct gs_port *port;
@@ -2282,7 +2284,7 @@ static void gs_free_ports(struct gs_dev *dev)
2282 * 2284 *
2283 * Allocate a circular buffer and all associated memory. 2285 * Allocate a circular buffer and all associated memory.
2284 */ 2286 */
2285static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags) 2287static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags)
2286{ 2288{
2287 struct gs_buf *gb; 2289 struct gs_buf *gb;
2288 2290
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 6e49432071a1..a6e035e24479 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -919,9 +919,9 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
919 struct zero_dev *dev = get_gadget_data (gadget); 919 struct zero_dev *dev = get_gadget_data (gadget);
920 struct usb_request *req = dev->req; 920 struct usb_request *req = dev->req;
921 int value = -EOPNOTSUPP; 921 int value = -EOPNOTSUPP;
922 u16 w_index = ctrl->wIndex; 922 u16 w_index = le16_to_cpu(ctrl->wIndex);
923 u16 w_value = ctrl->wValue; 923 u16 w_value = le16_to_cpu(ctrl->wValue);
924 u16 w_length = ctrl->wLength; 924 u16 w_length = le16_to_cpu(ctrl->wLength);
925 925
926 /* usually this stores reply data in the pre-allocated ep0 buffer, 926 /* usually this stores reply data in the pre-allocated ep0 buffer,
927 * but config change events will reconfigure hardware. 927 * but config change events will reconfigure hardware.