Skip to content

Commit ceb675a

Browse files
committed
Merge usb-linus branch into usb-next
This pulls in a bunch of fixes that are in Linus's tree because we need them here for testing and development. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2 parents 9662ced + 200e0d9 commit ceb675a

File tree

23 files changed

+310
-392
lines changed

23 files changed

+310
-392
lines changed

drivers/usb/core/hcd.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <asm/unaligned.h>
4040
#include <linux/platform_device.h>
4141
#include <linux/workqueue.h>
42+
#include <linux/pm_runtime.h>
4243

4344
#include <linux/usb.h>
4445
#include <linux/usb/hcd.h>
@@ -1029,6 +1030,49 @@ static int register_root_hub(struct usb_hcd *hcd)
10291030
return retval;
10301031
}
10311032

1033+
/*
1034+
* usb_hcd_start_port_resume - a root-hub port is sending a resume signal
1035+
* @bus: the bus which the root hub belongs to
1036+
* @portnum: the port which is being resumed
1037+
*
1038+
* HCDs should call this function when they know that a resume signal is
1039+
* being sent to a root-hub port. The root hub will be prevented from
1040+
* going into autosuspend until usb_hcd_end_port_resume() is called.
1041+
*
1042+
* The bus's private lock must be held by the caller.
1043+
*/
1044+
void usb_hcd_start_port_resume(struct usb_bus *bus, int portnum)
1045+
{
1046+
unsigned bit = 1 << portnum;
1047+
1048+
if (!(bus->resuming_ports & bit)) {
1049+
bus->resuming_ports |= bit;
1050+
pm_runtime_get_noresume(&bus->root_hub->dev);
1051+
}
1052+
}
1053+
EXPORT_SYMBOL_GPL(usb_hcd_start_port_resume);
1054+
1055+
/*
1056+
* usb_hcd_end_port_resume - a root-hub port has stopped sending a resume signal
1057+
* @bus: the bus which the root hub belongs to
1058+
* @portnum: the port which is being resumed
1059+
*
1060+
* HCDs should call this function when they know that a resume signal has
1061+
* stopped being sent to a root-hub port. The root hub will be allowed to
1062+
* autosuspend again.
1063+
*
1064+
* The bus's private lock must be held by the caller.
1065+
*/
1066+
void usb_hcd_end_port_resume(struct usb_bus *bus, int portnum)
1067+
{
1068+
unsigned bit = 1 << portnum;
1069+
1070+
if (bus->resuming_ports & bit) {
1071+
bus->resuming_ports &= ~bit;
1072+
pm_runtime_put_noidle(&bus->root_hub->dev);
1073+
}
1074+
}
1075+
EXPORT_SYMBOL_GPL(usb_hcd_end_port_resume);
10321076

10331077
/*-------------------------------------------------------------------------*/
10341078

drivers/usb/core/hub.c

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,6 +2822,23 @@ void usb_enable_ltm(struct usb_device *udev)
28222822
EXPORT_SYMBOL_GPL(usb_enable_ltm);
28232823

28242824
#ifdef CONFIG_USB_SUSPEND
2825+
/*
2826+
* usb_disable_function_remotewakeup - disable usb3.0
2827+
* device's function remote wakeup
2828+
* @udev: target device
2829+
*
2830+
* Assume there's only one function on the USB 3.0
2831+
* device and disable remote wake for the first
2832+
* interface. FIXME if the interface association
2833+
* descriptor shows there's more than one function.
2834+
*/
2835+
static int usb_disable_function_remotewakeup(struct usb_device *udev)
2836+
{
2837+
return usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
2838+
USB_REQ_CLEAR_FEATURE, USB_RECIP_INTERFACE,
2839+
USB_INTRF_FUNC_SUSPEND, 0, NULL, 0,
2840+
USB_CTRL_SET_TIMEOUT);
2841+
}
28252842

28262843
/*
28272844
* usb_port_suspend - suspend a usb device's upstream port
@@ -2939,12 +2956,19 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
29392956
dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n",
29402957
port1, status);
29412958
/* paranoia: "should not happen" */
2942-
if (udev->do_remote_wakeup)
2943-
(void) usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
2944-
USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE,
2945-
USB_DEVICE_REMOTE_WAKEUP, 0,
2946-
NULL, 0,
2947-
USB_CTRL_SET_TIMEOUT);
2959+
if (udev->do_remote_wakeup) {
2960+
if (!hub_is_superspeed(hub->hdev)) {
2961+
(void) usb_control_msg(udev,
2962+
usb_sndctrlpipe(udev, 0),
2963+
USB_REQ_CLEAR_FEATURE,
2964+
USB_RECIP_DEVICE,
2965+
USB_DEVICE_REMOTE_WAKEUP, 0,
2966+
NULL, 0,
2967+
USB_CTRL_SET_TIMEOUT);
2968+
} else
2969+
(void) usb_disable_function_remotewakeup(udev);
2970+
2971+
}
29482972

29492973
/* Try to enable USB2 hardware LPM again */
29502974
if (udev->usb2_hw_lpm_capable == 1)
@@ -3051,20 +3075,30 @@ static int finish_port_resume(struct usb_device *udev)
30513075
* udev->reset_resume
30523076
*/
30533077
} else if (udev->actconfig && !udev->reset_resume) {
3054-
le16_to_cpus(&devstatus);
3055-
if (devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) {
3056-
status = usb_control_msg(udev,
3057-
usb_sndctrlpipe(udev, 0),
3058-
USB_REQ_CLEAR_FEATURE,
3078+
if (!hub_is_superspeed(udev->parent)) {
3079+
le16_to_cpus(&devstatus);
3080+
if (devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP))
3081+
status = usb_control_msg(udev,
3082+
usb_sndctrlpipe(udev, 0),
3083+
USB_REQ_CLEAR_FEATURE,
30593084
USB_RECIP_DEVICE,
3060-
USB_DEVICE_REMOTE_WAKEUP, 0,
3061-
NULL, 0,
3062-
USB_CTRL_SET_TIMEOUT);
3063-
if (status)
3064-
dev_dbg(&udev->dev,
3065-
"disable remote wakeup, status %d\n",
3066-
status);
3085+
USB_DEVICE_REMOTE_WAKEUP, 0,
3086+
NULL, 0,
3087+
USB_CTRL_SET_TIMEOUT);
3088+
} else {
3089+
status = usb_get_status(udev, USB_RECIP_INTERFACE, 0,
3090+
&devstatus);
3091+
le16_to_cpus(&devstatus);
3092+
if (!status && devstatus & (USB_INTRF_STAT_FUNC_RW_CAP
3093+
| USB_INTRF_STAT_FUNC_RW))
3094+
status =
3095+
usb_disable_function_remotewakeup(udev);
30673096
}
3097+
3098+
if (status)
3099+
dev_dbg(&udev->dev,
3100+
"disable remote wakeup, status %d\n",
3101+
status);
30683102
status = 0;
30693103
}
30703104
return status;

drivers/usb/host/ehci-hcd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
797797
ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
798798
set_bit(i, &ehci->resuming_ports);
799799
ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
800+
usb_hcd_start_port_resume(&hcd->self, i);
800801
mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
801802
}
802803
}

drivers/usb/host/ehci-hub.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,11 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
649649
status = STS_PCD;
650650
}
651651
}
652-
/* FIXME autosuspend idle root hubs */
652+
653+
/* If a resume is in progress, make sure it can finish */
654+
if (ehci->resuming_ports)
655+
mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(25));
656+
653657
spin_unlock_irqrestore (&ehci->lock, flags);
654658
return status ? retval : 0;
655659
}
@@ -851,6 +855,7 @@ static int ehci_hub_control (
851855
/* resume signaling for 20 msec */
852856
ehci->reset_done[wIndex] = jiffies
853857
+ msecs_to_jiffies(20);
858+
usb_hcd_start_port_resume(&hcd->self, wIndex);
854859
/* check the port again */
855860
mod_timer(&ehci_to_hcd(ehci)->rh_timer,
856861
ehci->reset_done[wIndex]);
@@ -862,6 +867,7 @@ static int ehci_hub_control (
862867
clear_bit(wIndex, &ehci->suspended_ports);
863868
set_bit(wIndex, &ehci->port_c_suspend);
864869
ehci->reset_done[wIndex] = 0;
870+
usb_hcd_end_port_resume(&hcd->self, wIndex);
865871

866872
/* stop resume signaling */
867873
temp = ehci_readl(ehci, status_reg);
@@ -950,6 +956,7 @@ static int ehci_hub_control (
950956
ehci->reset_done[wIndex] = 0;
951957
if (temp & PORT_PE)
952958
set_bit(wIndex, &ehci->port_c_suspend);
959+
usb_hcd_end_port_resume(&hcd->self, wIndex);
953960
}
954961

955962
if (temp & PORT_OC)

drivers/usb/host/ehci-q.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,17 +1197,26 @@ static void start_iaa_cycle(struct ehci_hcd *ehci, bool nested)
11971197
if (ehci->async_iaa || ehci->async_unlinking)
11981198
return;
11991199

1200-
/* Do all the waiting QHs at once */
1201-
ehci->async_iaa = ehci->async_unlink;
1202-
ehci->async_unlink = NULL;
1203-
12041200
/* If the controller isn't running, we don't have to wait for it */
12051201
if (unlikely(ehci->rh_state < EHCI_RH_RUNNING)) {
1202+
1203+
/* Do all the waiting QHs */
1204+
ehci->async_iaa = ehci->async_unlink;
1205+
ehci->async_unlink = NULL;
1206+
12061207
if (!nested) /* Avoid recursion */
12071208
end_unlink_async(ehci);
12081209

12091210
/* Otherwise start a new IAA cycle */
12101211
} else if (likely(ehci->rh_state == EHCI_RH_RUNNING)) {
1212+
struct ehci_qh *qh;
1213+
1214+
/* Do only the first waiting QH (nVidia bug?) */
1215+
qh = ehci->async_unlink;
1216+
ehci->async_iaa = qh;
1217+
ehci->async_unlink = qh->unlink_next;
1218+
qh->unlink_next = NULL;
1219+
12111220
/* Make sure the unlinks are all visible to the hardware */
12121221
wmb();
12131222

@@ -1255,34 +1264,35 @@ static void end_unlink_async(struct ehci_hcd *ehci)
12551264
}
12561265
}
12571266

1267+
static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh);
1268+
12581269
static void unlink_empty_async(struct ehci_hcd *ehci)
12591270
{
1260-
struct ehci_qh *qh, *next;
1261-
bool stopped = (ehci->rh_state < EHCI_RH_RUNNING);
1271+
struct ehci_qh *qh;
1272+
struct ehci_qh *qh_to_unlink = NULL;
12621273
bool check_unlinks_later = false;
1274+
int count = 0;
12631275

1264-
/* Unlink all the async QHs that have been empty for a timer cycle */
1265-
next = ehci->async->qh_next.qh;
1266-
while (next) {
1267-
qh = next;
1268-
next = qh->qh_next.qh;
1269-
1276+
/* Find the last async QH which has been empty for a timer cycle */
1277+
for (qh = ehci->async->qh_next.qh; qh; qh = qh->qh_next.qh) {
12701278
if (list_empty(&qh->qtd_list) &&
12711279
qh->qh_state == QH_STATE_LINKED) {
1272-
if (!stopped && qh->unlink_cycle ==
1273-
ehci->async_unlink_cycle)
1280+
++count;
1281+
if (qh->unlink_cycle == ehci->async_unlink_cycle)
12741282
check_unlinks_later = true;
12751283
else
1276-
single_unlink_async(ehci, qh);
1284+
qh_to_unlink = qh;
12771285
}
12781286
}
12791287

1280-
/* Start a new IAA cycle if any QHs are waiting for it */
1281-
if (ehci->async_unlink)
1282-
start_iaa_cycle(ehci, false);
1288+
/* If nothing else is being unlinked, unlink the last empty QH */
1289+
if (!ehci->async_iaa && !ehci->async_unlink && qh_to_unlink) {
1290+
start_unlink_async(ehci, qh_to_unlink);
1291+
--count;
1292+
}
12831293

1284-
/* QHs that haven't been empty for long enough will be handled later */
1285-
if (check_unlinks_later) {
1294+
/* Other QHs will be handled later */
1295+
if (count > 0) {
12861296
ehci_enable_event(ehci, EHCI_HRTIMER_ASYNC_UNLINKS, true);
12871297
++ehci->async_unlink_cycle;
12881298
}

drivers/usb/host/ehci-sched.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static inline unsigned char tt_start_uframe(struct ehci_hcd *ehci, __hc32 mask)
213213
}
214214

215215
static const unsigned char
216-
max_tt_usecs[] = { 125, 125, 125, 125, 125, 125, 30, 0 };
216+
max_tt_usecs[] = { 125, 125, 125, 125, 125, 125, 125, 25 };
217217

218218
/* carryover low/fullspeed bandwidth that crosses uframe boundries */
219219
static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8])
@@ -2212,11 +2212,11 @@ static void scan_isoc(struct ehci_hcd *ehci)
22122212
}
22132213
ehci->now_frame = now_frame;
22142214

2215+
frame = ehci->last_iso_frame;
22152216
for (;;) {
22162217
union ehci_shadow q, *q_p;
22172218
__hc32 type, *hw_p;
22182219

2219-
frame = ehci->last_iso_frame;
22202220
restart:
22212221
/* scan each element in frame's queue for completions */
22222222
q_p = &ehci->pshadow [frame];
@@ -2321,6 +2321,9 @@ static void scan_isoc(struct ehci_hcd *ehci)
23212321
/* Stop when we have reached the current frame */
23222322
if (frame == now_frame)
23232323
break;
2324-
ehci->last_iso_frame = (frame + 1) & fmask;
2324+
2325+
/* The last frame may still have active siTDs */
2326+
ehci->last_iso_frame = frame;
2327+
frame = (frame + 1) & fmask;
23252328
}
23262329
}

drivers/usb/host/ehci-timer.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,15 @@ static void ehci_poll_ASS(struct ehci_hcd *ehci)
113113

114114
if (want != actual) {
115115

116-
/* Poll again later, but give up after about 20 ms */
117-
if (ehci->ASS_poll_count++ < 20) {
118-
ehci_enable_event(ehci, EHCI_HRTIMER_POLL_ASS, true);
119-
return;
120-
}
121-
ehci_dbg(ehci, "Waited too long for the async schedule status (%x/%x), giving up\n",
122-
want, actual);
116+
/* Poll again later */
117+
ehci_enable_event(ehci, EHCI_HRTIMER_POLL_ASS, true);
118+
++ehci->ASS_poll_count;
119+
return;
123120
}
121+
122+
if (ehci->ASS_poll_count > 20)
123+
ehci_dbg(ehci, "ASS poll count reached %d\n",
124+
ehci->ASS_poll_count);
124125
ehci->ASS_poll_count = 0;
125126

126127
/* The status is up-to-date; restart or stop the schedule as needed */
@@ -159,14 +160,14 @@ static void ehci_poll_PSS(struct ehci_hcd *ehci)
159160

160161
if (want != actual) {
161162

162-
/* Poll again later, but give up after about 20 ms */
163-
if (ehci->PSS_poll_count++ < 20) {
164-
ehci_enable_event(ehci, EHCI_HRTIMER_POLL_PSS, true);
165-
return;
166-
}
167-
ehci_dbg(ehci, "Waited too long for the periodic schedule status (%x/%x), giving up\n",
168-
want, actual);
163+
/* Poll again later */
164+
ehci_enable_event(ehci, EHCI_HRTIMER_POLL_PSS, true);
165+
return;
169166
}
167+
168+
if (ehci->PSS_poll_count > 20)
169+
ehci_dbg(ehci, "PSS poll count reached %d\n",
170+
ehci->PSS_poll_count);
170171
ehci->PSS_poll_count = 0;
171172

172173
/* The status is up-to-date; restart or stop the schedule as needed */

drivers/usb/host/pci-quirks.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ void usb_enable_xhci_ports(struct pci_dev *xhci_pdev)
780780
"defaulting to EHCI.\n");
781781
dev_warn(&xhci_pdev->dev,
782782
"USB 3.0 devices will work at USB 2.0 speeds.\n");
783+
usb_disable_xhci_ports(xhci_pdev);
783784
return;
784785
}
785786

drivers/usb/host/uhci-hub.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ static void uhci_finish_suspend(struct uhci_hcd *uhci, int port,
116116
}
117117
}
118118
clear_bit(port, &uhci->resuming_ports);
119+
usb_hcd_end_port_resume(&uhci_to_hcd(uhci)->self, port);
119120
}
120121

121122
/* Wait for the UHCI controller in HP's iLO2 server management chip.
@@ -167,6 +168,8 @@ static void uhci_check_ports(struct uhci_hcd *uhci)
167168
set_bit(port, &uhci->resuming_ports);
168169
uhci->ports_timeout = jiffies +
169170
msecs_to_jiffies(25);
171+
usb_hcd_start_port_resume(
172+
&uhci_to_hcd(uhci)->self, port);
170173

171174
/* Make sure we see the port again
172175
* after the resuming period is over. */

0 commit comments

Comments
 (0)