2 * Copyright (C) 2001-2004 by David Brownell
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* this file is part of ehci-hcd.c */
20 static void qh_link_async (struct ehci_hcd
*ehci
, struct ehci_qh
*qh
);
21 static struct ehci_qh
*qh_make (struct ehci_hcd
*ehci
, struct urb
*urb
, gfp_t flags
);
22 static inline void ehci_qtd_init (struct ehci_hcd
*ehci
, struct ehci_qtd
*qtd
, dma_addr_t dma
);
23 static inline void ehci_qtd_free (struct ehci_hcd
*ehci
, struct ehci_qtd
*qtd
);
25 /*-------------------------------------------------------------------------*/
28 * EHCI Root Hub ... the nonsharable stuff
30 * Registers don't need cpu_to_le32, that happens transparently
33 /*-------------------------------------------------------------------------*/
35 #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
39 static int ehci_hub_control(
48 /* After a power loss, ports that were owned by the companion must be
49 * reset so that the companion can still own them.
51 static void ehci_handover_companion_ports(struct ehci_hcd
*ehci
)
57 struct usb_hcd
*hcd
= ehci_to_hcd(ehci
);
59 if (!ehci
->owned_ports
)
62 /* Give the connections some time to appear */
65 port
= HCS_N_PORTS(ehci
->hcs_params
);
67 if (test_bit(port
, &ehci
->owned_ports
)) {
68 reg
= &ehci
->regs
->port_status
[port
];
69 status
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
71 /* Port already owned by companion? */
72 if (status
& PORT_OWNER
)
73 clear_bit(port
, &ehci
->owned_ports
);
74 else if (test_bit(port
, &ehci
->companion_ports
))
75 ehci_writel(ehci
, status
& ~PORT_PE
, reg
);
77 ehci_hub_control(hcd
, SetPortFeature
,
78 USB_PORT_FEAT_RESET
, port
+ 1,
83 if (!ehci
->owned_ports
)
85 msleep(90); /* Wait for resets to complete */
87 port
= HCS_N_PORTS(ehci
->hcs_params
);
89 if (test_bit(port
, &ehci
->owned_ports
)) {
90 ehci_hub_control(hcd
, GetPortStatus
,
92 (char *) &buf
, sizeof(buf
));
94 /* The companion should now own the port,
95 * but if something went wrong the port must not
98 reg
= &ehci
->regs
->port_status
[port
];
99 status
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
100 if (status
& PORT_OWNER
)
101 ehci_writel(ehci
, status
| PORT_CSC
, reg
);
103 ehci_dbg(ehci
, "failed handover port %d: %x\n",
105 ehci_writel(ehci
, status
& ~PORT_PE
, reg
);
110 ehci
->owned_ports
= 0;
113 static int ehci_bus_suspend (struct usb_hcd
*hcd
)
115 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
119 ehci_dbg(ehci
, "suspend root hub\n");
121 if (time_before (jiffies
, ehci
->next_statechange
))
123 del_timer_sync(&ehci
->watchdog
);
124 del_timer_sync(&ehci
->iaa_watchdog
);
126 spin_lock_irq (&ehci
->lock
);
128 /* Once the controller is stopped, port resumes that are already
129 * in progress won't complete. Hence if remote wakeup is enabled
130 * for the root hub and any ports are in the middle of a resume or
131 * remote wakeup, we must fail the suspend.
133 if (hcd
->self
.root_hub
->do_remote_wakeup
) {
134 port
= HCS_N_PORTS(ehci
->hcs_params
);
136 if (ehci
->reset_done
[port
] != 0) {
137 spin_unlock_irq(&ehci
->lock
);
138 ehci_dbg(ehci
, "suspend failed because "
139 "port %d is resuming\n",
146 /* stop schedules, clean any completed work */
147 if (HC_IS_RUNNING(hcd
->state
)) {
149 hcd
->state
= HC_STATE_QUIESCING
;
151 ehci
->command
= ehci_readl(ehci
, &ehci
->regs
->command
);
154 /* Unlike other USB host controller types, EHCI doesn't have
155 * any notion of "global" or bus-wide suspend. The driver has
156 * to manually suspend all the active unsuspended ports, and
157 * then manually resume them in the bus_resume() routine.
159 ehci
->bus_suspended
= 0;
160 ehci
->owned_ports
= 0;
161 port
= HCS_N_PORTS(ehci
->hcs_params
);
163 u32 __iomem
*reg
= &ehci
->regs
->port_status
[port
];
164 u32 t1
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
167 /* keep track of which ports we suspend */
169 set_bit(port
, &ehci
->owned_ports
);
170 else if ((t1
& PORT_PE
) && !(t1
& PORT_SUSPEND
)) {
172 set_bit(port
, &ehci
->bus_suspended
);
175 /* enable remote wakeup on all ports */
176 if (hcd
->self
.root_hub
->do_remote_wakeup
)
177 t2
|= PORT_WAKE_BITS
;
179 t2
&= ~PORT_WAKE_BITS
;
182 ehci_vdbg (ehci
, "port %d, %08x -> %08x\n",
184 ehci_writel(ehci
, t2
, reg
);
188 /* Apparently some devices need a >= 1-uframe delay here */
189 if (ehci
->bus_suspended
)
192 /* turn off now-idle HC */
194 hcd
->state
= HC_STATE_SUSPENDED
;
197 end_unlink_async(ehci
);
199 /* allow remote wakeup */
201 if (!hcd
->self
.root_hub
->do_remote_wakeup
)
203 ehci_writel(ehci
, mask
, &ehci
->regs
->intr_enable
);
204 ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
206 ehci
->next_statechange
= jiffies
+ msecs_to_jiffies(10);
207 spin_unlock_irq (&ehci
->lock
);
209 /* ehci_work() may have re-enabled the watchdog timer, which we do not
210 * want, and so we must delete any pending watchdog timer events.
212 del_timer_sync(&ehci
->watchdog
);
217 /* caller has locked the root hub, and should reset/reinit on error */
218 static int ehci_bus_resume (struct usb_hcd
*hcd
)
220 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
224 u8 resume_needed
= 0;
226 if (time_before (jiffies
, ehci
->next_statechange
))
228 spin_lock_irq (&ehci
->lock
);
229 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
)) {
230 spin_unlock_irq(&ehci
->lock
);
234 /* Ideally and we've got a real resume here, and no port's power
235 * was lost. (For PCI, that means Vaux was maintained.) But we
236 * could instead be restoring a swsusp snapshot -- so that BIOS was
237 * the last user of the controller, not reset/pm hardware keeping
238 * state we gave to it.
240 power_okay
= ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
241 ehci_dbg(ehci
, "resume root hub%s\n",
242 power_okay
? "" : " after power loss");
244 /* at least some APM implementations will try to deliver
245 * IRQs right away, so delay them until we're ready.
247 ehci_writel(ehci
, 0, &ehci
->regs
->intr_enable
);
249 /* re-init operational registers */
250 ehci_writel(ehci
, 0, &ehci
->regs
->segment
);
251 ehci_writel(ehci
, ehci
->periodic_dma
, &ehci
->regs
->frame_list
);
252 ehci_writel(ehci
, (u32
) ehci
->async
->qh_dma
, &ehci
->regs
->async_next
);
254 /* restore CMD_RUN, framelist size, and irq threshold */
255 ehci_writel(ehci
, ehci
->command
, &ehci
->regs
->command
);
257 /* Some controller/firmware combinations need a delay during which
258 * they set up the port statuses. See Bugzilla #8190. */
259 spin_unlock_irq(&ehci
->lock
);
261 spin_lock_irq(&ehci
->lock
);
263 /* manually resume the ports we suspended during bus_suspend() */
264 i
= HCS_N_PORTS (ehci
->hcs_params
);
266 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
267 temp
&= ~(PORT_RWC_BITS
| PORT_WAKE_BITS
);
268 if (test_bit(i
, &ehci
->bus_suspended
) &&
269 (temp
& PORT_SUSPEND
)) {
273 ehci_writel(ehci
, temp
, &ehci
->regs
->port_status
[i
]);
276 /* msleep for 20ms only if code is trying to resume port */
278 spin_unlock_irq(&ehci
->lock
);
280 spin_lock_irq(&ehci
->lock
);
283 i
= HCS_N_PORTS (ehci
->hcs_params
);
285 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
286 if (test_bit(i
, &ehci
->bus_suspended
) &&
287 (temp
& PORT_SUSPEND
)) {
288 temp
&= ~(PORT_RWC_BITS
| PORT_RESUME
);
289 ehci_writel(ehci
, temp
, &ehci
->regs
->port_status
[i
]);
290 ehci_vdbg (ehci
, "resumed port %d\n", i
+ 1);
293 (void) ehci_readl(ehci
, &ehci
->regs
->command
);
295 /* maybe re-activate the schedule(s) */
297 if (ehci
->async
->qh_next
.qh
)
299 if (ehci
->periodic_sched
)
302 ehci
->command
|= temp
;
303 ehci_writel(ehci
, ehci
->command
, &ehci
->regs
->command
);
306 ehci
->next_statechange
= jiffies
+ msecs_to_jiffies(5);
307 hcd
->state
= HC_STATE_RUNNING
;
309 /* Now we can safely re-enable irqs */
310 ehci_writel(ehci
, INTR_MASK
, &ehci
->regs
->intr_enable
);
312 spin_unlock_irq (&ehci
->lock
);
313 ehci_handover_companion_ports(ehci
);
319 #define ehci_bus_suspend NULL
320 #define ehci_bus_resume NULL
322 #endif /* CONFIG_PM */
324 /*-------------------------------------------------------------------------*/
326 /* Display the ports dedicated to the companion controller */
327 static ssize_t
show_companion(struct device
*dev
,
328 struct device_attribute
*attr
,
331 struct ehci_hcd
*ehci
;
332 int nports
, index
, n
;
333 int count
= PAGE_SIZE
;
336 ehci
= hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev
)));
337 nports
= HCS_N_PORTS(ehci
->hcs_params
);
339 for (index
= 0; index
< nports
; ++index
) {
340 if (test_bit(index
, &ehci
->companion_ports
)) {
341 n
= scnprintf(ptr
, count
, "%d\n", index
+ 1);
350 * Sets the owner of a port
352 static void set_owner(struct ehci_hcd
*ehci
, int portnum
, int new_owner
)
354 u32 __iomem
*status_reg
;
358 status_reg
= &ehci
->regs
->port_status
[portnum
];
361 * The controller won't set the OWNER bit if the port is
362 * enabled, so this loop will sometimes require at least two
363 * iterations: one to disable the port and one to set OWNER.
365 for (try = 4; try > 0; --try) {
366 spin_lock_irq(&ehci
->lock
);
367 port_status
= ehci_readl(ehci
, status_reg
);
368 if ((port_status
& PORT_OWNER
) == new_owner
369 || (port_status
& (PORT_OWNER
| PORT_CONNECT
))
373 port_status
^= PORT_OWNER
;
374 port_status
&= ~(PORT_PE
| PORT_RWC_BITS
);
375 ehci_writel(ehci
, port_status
, status_reg
);
377 spin_unlock_irq(&ehci
->lock
);
384 * Dedicate or undedicate a port to the companion controller.
385 * Syntax is "[-]portnum", where a leading '-' sign means
386 * return control of the port to the EHCI controller.
388 static ssize_t
store_companion(struct device
*dev
,
389 struct device_attribute
*attr
,
390 const char *buf
, size_t count
)
392 struct ehci_hcd
*ehci
;
393 int portnum
, new_owner
;
395 ehci
= hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev
)));
396 new_owner
= PORT_OWNER
; /* Owned by companion */
397 if (sscanf(buf
, "%d", &portnum
) != 1)
401 new_owner
= 0; /* Owned by EHCI */
403 if (portnum
<= 0 || portnum
> HCS_N_PORTS(ehci
->hcs_params
))
407 set_bit(portnum
, &ehci
->companion_ports
);
409 clear_bit(portnum
, &ehci
->companion_ports
);
410 set_owner(ehci
, portnum
, new_owner
);
413 static DEVICE_ATTR(companion
, 0644, show_companion
, store_companion
);
415 static inline void create_companion_file(struct ehci_hcd
*ehci
)
419 /* with integrated TT there is no companion! */
420 if (!ehci_is_TDI(ehci
))
421 i
= device_create_file(ehci_to_hcd(ehci
)->self
.controller
,
422 &dev_attr_companion
);
425 static inline void remove_companion_file(struct ehci_hcd
*ehci
)
427 /* with integrated TT there is no companion! */
428 if (!ehci_is_TDI(ehci
))
429 device_remove_file(ehci_to_hcd(ehci
)->self
.controller
,
430 &dev_attr_companion
);
434 /*-------------------------------------------------------------------------*/
436 static int check_reset_complete (
437 struct ehci_hcd
*ehci
,
439 u32 __iomem
*status_reg
,
442 if (!(port_status
& PORT_CONNECT
))
445 /* if reset finished and it's still not enabled -- handoff */
446 if (!(port_status
& PORT_PE
)) {
448 /* with integrated TT, there's nobody to hand it to! */
449 if (ehci_is_TDI(ehci
)) {
451 "Failed to enable port %d on root hub TT\n",
456 ehci_dbg (ehci
, "port %d full speed --> companion\n",
459 // what happens if HCS_N_CC(params) == 0 ?
460 port_status
|= PORT_OWNER
;
461 port_status
&= ~PORT_RWC_BITS
;
462 ehci_writel(ehci
, port_status
, status_reg
);
465 ehci_dbg (ehci
, "port %d high speed\n", index
+ 1);
470 /*-------------------------------------------------------------------------*/
473 /* build "status change" packet (one or two bytes) from HC registers */
476 ehci_hub_status_data (struct usb_hcd
*hcd
, char *buf
)
478 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
479 u32 temp
, status
= 0;
481 int ports
, i
, retval
= 1;
484 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
485 if (!HC_IS_RUNNING(hcd
->state
))
488 /* init status to no-changes */
490 ports
= HCS_N_PORTS (ehci
->hcs_params
);
496 /* Some boards (mostly VIA?) report bogus overcurrent indications,
497 * causing massive log spam unless we completely ignore them. It
498 * may be relevant that VIA VT8235 controlers, where PORT_POWER is
499 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
500 * PORT_POWER; that's surprising, but maybe within-spec.
503 mask
= PORT_CSC
| PORT_PEC
| PORT_OCC
;
505 mask
= PORT_CSC
| PORT_PEC
;
506 // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
508 /* no hub change reports (bit 0) for now (power, ...) */
510 /* port N changes (bit N)? */
511 spin_lock_irqsave (&ehci
->lock
, flags
);
512 for (i
= 0; i
< ports
; i
++) {
513 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
516 * Return status information even for ports with OWNER set.
517 * Otherwise khubd wouldn't see the disconnect event when a
518 * high-speed device is switched over to the companion
519 * controller by the user.
522 if ((temp
& mask
) != 0 || test_bit(i
, &ehci
->port_c_suspend
)
523 || (ehci
->reset_done
[i
] && time_after_eq(
524 jiffies
, ehci
->reset_done
[i
]))) {
526 buf
[0] |= 1 << (i
+ 1);
528 buf
[1] |= 1 << (i
- 7);
532 /* FIXME autosuspend idle root hubs */
533 spin_unlock_irqrestore (&ehci
->lock
, flags
);
534 return status
? retval
: 0;
537 /*-------------------------------------------------------------------------*/
540 ehci_hub_descriptor (
541 struct ehci_hcd
*ehci
,
542 struct usb_hub_descriptor
*desc
544 int ports
= HCS_N_PORTS (ehci
->hcs_params
);
547 desc
->bDescriptorType
= 0x29;
548 desc
->bPwrOn2PwrGood
= 10; /* ehci 1.0, 2.3.9 says 20ms max */
549 desc
->bHubContrCurrent
= 0;
551 desc
->bNbrPorts
= ports
;
552 temp
= 1 + (ports
/ 8);
553 desc
->bDescLength
= 7 + 2 * temp
;
555 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
556 memset (&desc
->bitmap
[0], 0, temp
);
557 memset (&desc
->bitmap
[temp
], 0xff, temp
);
559 temp
= 0x0008; /* per-port overcurrent reporting */
560 if (HCS_PPC (ehci
->hcs_params
))
561 temp
|= 0x0001; /* per-port power control */
563 temp
|= 0x0002; /* no power switching */
565 // re-enable when we support USB_PORT_FEAT_INDICATOR below.
566 if (HCS_INDICATOR (ehci
->hcs_params
))
567 temp
|= 0x0080; /* per-port indicators (LEDs) */
569 desc
->wHubCharacteristics
= cpu_to_le16(temp
);
572 /*-------------------------------------------------------------------------*/
574 static int ehci_hub_control (
582 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
583 int ports
= HCS_N_PORTS (ehci
->hcs_params
);
584 u32 __iomem
*status_reg
= &ehci
->regs
->port_status
[
585 (wIndex
& 0xff) - 1];
593 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
594 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
595 * (track current state ourselves) ... blink for diagnostics,
596 * power, "this is the one", etc. EHCI spec supports this.
599 spin_lock_irqsave (&ehci
->lock
, flags
);
601 case ClearHubFeature
:
603 case C_HUB_LOCAL_POWER
:
604 case C_HUB_OVER_CURRENT
:
605 /* no hub-wide feature/status flags */
611 case ClearPortFeature
:
612 if (!wIndex
|| wIndex
> ports
)
615 temp
= ehci_readl(ehci
, status_reg
);
618 * Even if OWNER is set, so the port is owned by the
619 * companion controller, khubd needs to be able to clear
620 * the port-change status bits (especially
621 * USB_PORT_FEAT_C_CONNECTION).
625 case USB_PORT_FEAT_ENABLE
:
626 ehci_writel(ehci
, temp
& ~PORT_PE
, status_reg
);
628 case USB_PORT_FEAT_C_ENABLE
:
629 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_PEC
,
632 case USB_PORT_FEAT_SUSPEND
:
633 if (temp
& PORT_RESET
)
635 if (ehci
->no_selective_suspend
)
637 if (temp
& PORT_SUSPEND
) {
638 if ((temp
& PORT_PE
) == 0)
640 /* resume signaling for 20 msec */
641 temp
&= ~(PORT_RWC_BITS
| PORT_WAKE_BITS
);
642 ehci_writel(ehci
, temp
| PORT_RESUME
,
644 ehci
->reset_done
[wIndex
] = jiffies
645 + msecs_to_jiffies (20);
648 case USB_PORT_FEAT_C_SUSPEND
:
649 clear_bit(wIndex
, &ehci
->port_c_suspend
);
651 case USB_PORT_FEAT_POWER
:
652 if (HCS_PPC (ehci
->hcs_params
))
654 temp
& ~(PORT_RWC_BITS
| PORT_POWER
),
657 case USB_PORT_FEAT_C_CONNECTION
:
658 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_CSC
,
661 case USB_PORT_FEAT_C_OVER_CURRENT
:
662 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_OCC
,
665 case USB_PORT_FEAT_C_RESET
:
666 /* GetPortStatus clears reset */
671 ehci_readl(ehci
, &ehci
->regs
->command
); /* unblock posted write */
673 case GetHubDescriptor
:
674 ehci_hub_descriptor (ehci
, (struct usb_hub_descriptor
*)
678 /* no hub-wide feature/status flags */
680 //cpu_to_le32s ((u32 *) buf);
683 if (!wIndex
|| wIndex
> ports
)
687 temp
= ehci_readl(ehci
, status_reg
);
691 status
|= 1 << USB_PORT_FEAT_C_CONNECTION
;
693 status
|= 1 << USB_PORT_FEAT_C_ENABLE
;
695 if ((temp
& PORT_OCC
) && !ignore_oc
){
696 status
|= 1 << USB_PORT_FEAT_C_OVER_CURRENT
;
699 * Hubs should disable port power on over-current.
700 * However, not all EHCI implementations do this
701 * automatically, even if they _do_ support per-port
702 * power switching; they're allowed to just limit the
703 * current. khubd will turn the power back on.
705 if (HCS_PPC (ehci
->hcs_params
)){
707 temp
& ~(PORT_RWC_BITS
| PORT_POWER
),
712 /* whoever resumes must GetPortStatus to complete it!! */
713 if (temp
& PORT_RESUME
) {
715 /* Remote Wakeup received? */
716 if (!ehci
->reset_done
[wIndex
]) {
717 /* resume signaling for 20 msec */
718 ehci
->reset_done
[wIndex
] = jiffies
719 + msecs_to_jiffies(20);
720 /* check the port again */
721 mod_timer(&ehci_to_hcd(ehci
)->rh_timer
,
722 ehci
->reset_done
[wIndex
]);
725 /* resume completed? */
726 else if (time_after_eq(jiffies
,
727 ehci
->reset_done
[wIndex
])) {
728 clear_bit(wIndex
, &ehci
->suspended_ports
);
729 set_bit(wIndex
, &ehci
->port_c_suspend
);
730 ehci
->reset_done
[wIndex
] = 0;
732 /* stop resume signaling */
733 temp
= ehci_readl(ehci
, status_reg
);
735 temp
& ~(PORT_RWC_BITS
| PORT_RESUME
),
737 retval
= handshake(ehci
, status_reg
,
738 PORT_RESUME
, 0, 2000 /* 2msec */);
741 "port %d resume error %d\n",
745 temp
&= ~(PORT_SUSPEND
|PORT_RESUME
|(3<<10));
749 /* whoever resets must GetPortStatus to complete it!! */
750 if ((temp
& PORT_RESET
)
751 && time_after_eq(jiffies
,
752 ehci
->reset_done
[wIndex
])) {
753 status
|= 1 << USB_PORT_FEAT_C_RESET
;
754 ehci
->reset_done
[wIndex
] = 0;
756 /* force reset to complete */
757 ehci_writel(ehci
, temp
& ~(PORT_RWC_BITS
| PORT_RESET
),
759 /* REVISIT: some hardware needs 550+ usec to clear
760 * this bit; seems too long to spin routinely...
762 retval
= handshake(ehci
, status_reg
,
763 PORT_RESET
, 0, 1000);
765 ehci_err (ehci
, "port %d reset error %d\n",
770 /* see what we found out */
771 temp
= check_reset_complete (ehci
, wIndex
, status_reg
,
772 ehci_readl(ehci
, status_reg
));
775 if (!(temp
& (PORT_RESUME
|PORT_RESET
)))
776 ehci
->reset_done
[wIndex
] = 0;
778 /* transfer dedicated ports to the companion hc */
779 if ((temp
& PORT_CONNECT
) &&
780 test_bit(wIndex
, &ehci
->companion_ports
)) {
781 temp
&= ~PORT_RWC_BITS
;
783 ehci_writel(ehci
, temp
, status_reg
);
784 ehci_dbg(ehci
, "port %d --> companion\n", wIndex
+ 1);
785 temp
= ehci_readl(ehci
, status_reg
);
789 * Even if OWNER is set, there's no harm letting khubd
790 * see the wPortStatus values (they should all be 0 except
791 * for PORT_POWER anyway).
794 if (temp
& PORT_CONNECT
) {
795 status
|= 1 << USB_PORT_FEAT_CONNECTION
;
796 // status may be from integrated TT
797 status
|= ehci_port_speed(ehci
, temp
);
800 status
|= 1 << USB_PORT_FEAT_ENABLE
;
802 /* maybe the port was unsuspended without our knowledge */
803 if (temp
& (PORT_SUSPEND
|PORT_RESUME
)) {
804 status
|= 1 << USB_PORT_FEAT_SUSPEND
;
805 } else if (test_bit(wIndex
, &ehci
->suspended_ports
)) {
806 clear_bit(wIndex
, &ehci
->suspended_ports
);
807 ehci
->reset_done
[wIndex
] = 0;
809 set_bit(wIndex
, &ehci
->port_c_suspend
);
813 status
|= 1 << USB_PORT_FEAT_OVER_CURRENT
;
814 if (temp
& PORT_RESET
)
815 status
|= 1 << USB_PORT_FEAT_RESET
;
816 if (temp
& PORT_POWER
)
817 status
|= 1 << USB_PORT_FEAT_POWER
;
818 if (test_bit(wIndex
, &ehci
->port_c_suspend
))
819 status
|= 1 << USB_PORT_FEAT_C_SUSPEND
;
821 #ifndef VERBOSE_DEBUG
822 if (status
& ~0xffff) /* only if wPortChange is interesting */
824 dbg_port (ehci
, "GetStatus", wIndex
+ 1, temp
);
825 put_unaligned(cpu_to_le32 (status
), (__le32
*) buf
);
829 case C_HUB_LOCAL_POWER
:
830 case C_HUB_OVER_CURRENT
:
831 /* no hub-wide feature/status flags */
838 selector
= wIndex
>> 8;
840 if (!wIndex
|| wIndex
> ports
)
843 temp
= ehci_readl(ehci
, status_reg
);
844 if (temp
& PORT_OWNER
)
847 temp
&= ~PORT_RWC_BITS
;
849 case USB_PORT_FEAT_SUSPEND
:
850 if (ehci
->no_selective_suspend
)
852 if ((temp
& PORT_PE
) == 0
853 || (temp
& PORT_RESET
) != 0)
855 ehci_writel(ehci
, temp
| PORT_SUSPEND
, status_reg
);
856 set_bit(wIndex
, &ehci
->suspended_ports
);
858 case USB_PORT_FEAT_POWER
:
859 if (HCS_PPC (ehci
->hcs_params
))
860 ehci_writel(ehci
, temp
| PORT_POWER
,
863 case USB_PORT_FEAT_RESET
:
864 if (temp
& PORT_RESUME
)
866 /* line status bits may report this as low speed,
867 * which can be fine if this root hub has a
868 * transaction translator built in.
870 if ((temp
& (PORT_PE
|PORT_CONNECT
)) == PORT_CONNECT
871 && !ehci_is_TDI(ehci
)
872 && PORT_USB11 (temp
)) {
874 "port %d low speed --> companion\n",
878 ehci_vdbg (ehci
, "port %d reset\n", wIndex
+ 1);
883 * caller must wait, then call GetPortStatus
884 * usb 2.0 spec says 50 ms resets on root
886 ehci
->reset_done
[wIndex
] = jiffies
887 + msecs_to_jiffies (50);
889 ehci_writel(ehci
, temp
, status_reg
);
892 /* For downstream facing ports (these): one hub port is put
893 * into test mode according to USB2 11.24.2.13, then the hub
894 * must be reset (which for root hub now means rmmod+modprobe,
895 * or else system reboot). See EHCI 2.3.9 and 4.14 for info
896 * about the EHCI-specific stuff.
898 case USB_PORT_FEAT_TEST
:
899 if (!selector
|| selector
> 5)
903 temp
|= selector
<< 16;
904 ehci_writel(ehci
, temp
, status_reg
);
910 ehci_readl(ehci
, &ehci
->regs
->command
); /* unblock posted writes */
913 /* EHCI fastpath acceleration */
914 /* Use parameters instead of buffer to avoid core modifications */
915 case EHCI_SET_BYPASS_CB
:
916 ehci
->ehci_bypass_callback
= (void (*)(int, struct ehci_qh
*, spinlock_t
*lock
))(wValue
| (wIndex
<< 16));
917 ehci_info(ehci
, "EHCI Fastpath: Got the bypass callback command in EHCI %p\n", ehci
->ehci_bypass_callback
);
919 case EHCI_SET_BYPASS_DEV
:
920 hcc_params
= ehci_readl(ehci
, &ehci
->caps
->hcc_params
);
921 if (HCC_64BIT_ADDR (hcc_params
)) {
922 ehci_info(ehci
, "EHCI Fastpath: EHCI 64bit addressing mode not supported\n");
925 ehci
->bypass_device
= (struct usb_device
*)(wValue
| (wIndex
<< 16));
926 ehci_info(ehci
, "EHCI Fastpath: Got the bypass device command in EHCI %p\n", ehci
->bypass_device
);
928 case EHCI_SET_EP_BYPASS
:
930 struct urb dummy_urb
;
931 /* In/out bit mask is 0x10 */
933 int pipeindex
= wIndex
;
934 struct usb_device
*udev
= ehci
->bypass_device
;
937 bool pipeout
= ((pipe
&0x10) == 0);
939 struct usb_host_endpoint
*ep
;
941 ehci_info(ehci
, "EHCI Fastpath: Got the RH bypass command in EHCI for EP #%d %04x\n", pipeindex
, pipe
);
944 ep
= pipeout
? udev
->ep_out
[pipe
] : udev
->ep_in
[pipe
];
945 usb_pipe
= pipeout
? usb_sndbulkpipe(udev
, pipe
) : usb_rcvbulkpipe(udev
, pipe
);
947 usb_fill_bulk_urb(&dummy_urb
, ehci
->bypass_device
, usb_pipe
, NULL
, 0, NULL
, NULL
);
949 qh
= qh_make(ehci
, &dummy_urb
, GFP_ATOMIC
);
951 if (ehci
->fastpath_pool
!= NULL
) {
954 ehci_info(ehci
, "EHCI Fastpath: release native dummy qtd and alloc new one\n");
955 ehci_qtd_free (ehci
, qh
->dummy
);
957 qh
->dummy
= dma_pool_alloc (ehci
->fastpath_pool
, GFP_ATOMIC
, &dma
);
958 if (qh
->dummy
!= NULL
)
959 ehci_qtd_init (ehci
, qh
->dummy
, dma
);
961 printk("re-alloc dummy qtd from fastpath_pool error !!\n");
965 qh
->first_qtd
= qh
->dummy
;
967 ehci_info(ehci
, "EHCI Fastpath: EP %p QH %p dummy %p\n", ep
, qh
, qh
->dummy
);
970 qh_link_async (ehci
, qh
);
973 qh
->qh_state
= QH_STATE_DETACHED
;
975 /* Save the pipe pointer */
976 ehci
->ehci_pipes
[pipeindex
] = qh
;
981 case EHCI_DUMP_STATE
:
983 int sts
= ehci_readl(ehci
, &ehci
->regs
->status
);
985 printk("EHCI IRQ status %08x\n", sts
);
986 printk("EHCI INT status %08x\n", ehci
->regs
->intr_enable
);
990 case EHCI_SET_BYPASS_POOL
:
991 ehci
->fastpath_pool
= (struct dma_pool
*)(wValue
| (wIndex
<< 16));
992 ehci_info(ehci
, "EHCI Fastpath: Got the bypass fastpath pool command in EHCI %p\n", ehci
->fastpath_pool
);
995 case EHCI_CLR_EP_BYPASS
:
999 /* reset callback func and bapass dev */
1000 ehci
->ehci_bypass_callback
= NULL
;
1001 ehci
->bypass_device
= NULL
;
1003 /* freeing qh and qtd info */
1004 for (idx
= 0; idx
< 3; idx
++) {
1005 printk("%d freeing \n", idx
);
1006 if (ehci
->ehci_pipes
[idx
] != NULL
) {
1007 struct ehci_qh
*rm_qh
= ehci
->ehci_pipes
[idx
];
1008 struct ehci_qtd
*rm_qtd
= ehci
->ehci_pipes
[idx
]->dummy
;
1010 dma_pool_free(ehci
->fastpath_pool
, rm_qtd
, rm_qtd
->qtd_dma
);
1011 dma_pool_free(ehci
->qh_pool
, rm_qh
, rm_qh
->qh_dma
);
1012 ehci
->ehci_pipes
[idx
] = NULL
;
1019 /* "stall" on error */
1022 spin_unlock_irqrestore (&ehci
->lock
, flags
);
1026 static void ehci_relinquish_port(struct usb_hcd
*hcd
, int portnum
)
1028 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
1030 if (ehci_is_TDI(ehci
))
1032 set_owner(ehci
, --portnum
, PORT_OWNER
);
1035 static int ehci_port_handed_over(struct usb_hcd
*hcd
, int portnum
)
1037 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
1040 if (ehci_is_TDI(ehci
))
1042 reg
= &ehci
->regs
->port_status
[portnum
- 1];
1043 return ehci_readl(ehci
, reg
) & PORT_OWNER
;