stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	Mathias Nyman <mathias.nyman@linux.intel.com>,
	stable@kernel.org
Subject: [PATCH 5.4 080/108] usb: hub: Fix link power management max exit latency (MEL) calculations
Date: Mon, 26 Jul 2021 17:39:21 +0200	[thread overview]
Message-ID: <20210726153834.241087667@linuxfoundation.org> (raw)
In-Reply-To: <20210726153831.696295003@linuxfoundation.org>

From: Mathias Nyman <mathias.nyman@linux.intel.com>

commit 1bf2761c837571a66ec290fb66c90413821ffda2 upstream.

Maximum Exit Latency (MEL) value is used by host to know how much in
advance it needs to start waking up a U1/U2 suspended link in order to
service a periodic transfer in time.

Current MEL calculation only includes the time to wake up the path from
U1/U2 to U0. This is called tMEL1 in USB 3.1 section C 1.5.2

Total MEL = tMEL1 + tMEL2 +tMEL3 + tMEL4 which should additinally include:
- tMEL2 which is the time it takes for PING message to reach device
- tMEL3 time for device to process the PING and submit a PING_RESPONSE
- tMEL4 time for PING_RESPONSE to traverse back upstream to host.

Add the missing tMEL2, tMEL3 and tMEL4 to MEL calculation.

Cc: <stable@kernel.org> # v3.5
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20210715150122.1995966-1-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/core/hub.c |   52 ++++++++++++++++++++++++++-----------------------
 1 file changed, 28 insertions(+), 24 deletions(-)

--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -46,6 +46,7 @@
 
 #define USB_TP_TRANSMISSION_DELAY	40	/* ns */
 #define USB_TP_TRANSMISSION_DELAY_MAX	65535	/* ns */
+#define USB_PING_RESPONSE_TIME		400	/* ns */
 
 /* Protect struct usb_device->state and ->children members
  * Note: Both are also protected by ->dev.sem, except that ->state can
@@ -180,8 +181,9 @@ int usb_device_supports_lpm(struct usb_d
 }
 
 /*
- * Set the Maximum Exit Latency (MEL) for the host to initiate a transition from
- * either U1 or U2.
+ * Set the Maximum Exit Latency (MEL) for the host to wakup up the path from
+ * U1/U2, send a PING to the device and receive a PING_RESPONSE.
+ * See USB 3.1 section C.1.5.2
  */
 static void usb_set_lpm_mel(struct usb_device *udev,
 		struct usb3_lpm_parameters *udev_lpm_params,
@@ -191,35 +193,37 @@ static void usb_set_lpm_mel(struct usb_d
 		unsigned int hub_exit_latency)
 {
 	unsigned int total_mel;
-	unsigned int device_mel;
-	unsigned int hub_mel;
 
 	/*
-	 * Calculate the time it takes to transition all links from the roothub
-	 * to the parent hub into U0.  The parent hub must then decode the
-	 * packet (hub header decode latency) to figure out which port it was
-	 * bound for.
-	 *
-	 * The Hub Header decode latency is expressed in 0.1us intervals (0x1
-	 * means 0.1us).  Multiply that by 100 to get nanoseconds.
+	 * tMEL1. time to transition path from host to device into U0.
+	 * MEL for parent already contains the delay up to parent, so only add
+	 * the exit latency for the last link (pick the slower exit latency),
+	 * and the hub header decode latency. See USB 3.1 section C 2.2.1
+	 * Store MEL in nanoseconds
 	 */
 	total_mel = hub_lpm_params->mel +
-		(hub->descriptor->u.ss.bHubHdrDecLat * 100);
+		max(udev_exit_latency, hub_exit_latency) * 1000 +
+		hub->descriptor->u.ss.bHubHdrDecLat * 100;
 
 	/*
-	 * How long will it take to transition the downstream hub's port into
-	 * U0?  The greater of either the hub exit latency or the device exit
-	 * latency.
-	 *
-	 * The BOS U1/U2 exit latencies are expressed in 1us intervals.
-	 * Multiply that by 1000 to get nanoseconds.
+	 * tMEL2. Time to submit PING packet. Sum of tTPTransmissionDelay for
+	 * each link + wHubDelay for each hub. Add only for last link.
+	 * tMEL4, the time for PING_RESPONSE to traverse upstream is similar.
+	 * Multiply by 2 to include it as well.
 	 */
-	device_mel = udev_exit_latency * 1000;
-	hub_mel = hub_exit_latency * 1000;
-	if (device_mel > hub_mel)
-		total_mel += device_mel;
-	else
-		total_mel += hub_mel;
+	total_mel += (__le16_to_cpu(hub->descriptor->u.ss.wHubDelay) +
+		      USB_TP_TRANSMISSION_DELAY) * 2;
+
+	/*
+	 * tMEL3, tPingResponse. Time taken by device to generate PING_RESPONSE
+	 * after receiving PING. Also add 2100ns as stated in USB 3.1 C 1.5.2.4
+	 * to cover the delay if the PING_RESPONSE is queued behind a Max Packet
+	 * Size DP.
+	 * Note these delays should be added only once for the entire path, so
+	 * add them to the MEL of the device connected to the roothub.
+	 */
+	if (!hub->hdev->parent)
+		total_mel += USB_PING_RESPONSE_TIME + 2100;
 
 	udev_lpm_params->mel = total_mel;
 }



  parent reply	other threads:[~2021-07-26 15:59 UTC|newest]

Thread overview: 115+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-26 15:38 [PATCH 5.4 000/108] 5.4.136-rc1 review Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 001/108] igc: Fix use-after-free error during reset Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 002/108] igb: " Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 003/108] igc: change default return of igc_read_phy_reg() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 004/108] ixgbe: Fix an error handling path in ixgbe_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 005/108] igc: Prefer to use the pci_release_mem_regions method Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 006/108] igc: Fix an error handling path in igc_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 007/108] igb: Fix an error handling path in igb_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 008/108] fm10k: Fix an error handling path in fm10k_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 009/108] e1000e: Fix an error handling path in e1000_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 010/108] iavf: Fix an error handling path in iavf_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 011/108] igb: Check if num of q_vectors is smaller than max before array access Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 012/108] igb: Fix position of assignment to *ring Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 013/108] gve: Fix an error handling path in gve_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 014/108] ipv6: fix disable_policy for fwd packets Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 015/108] selftests: icmp_redirect: remove from checking for IPv6 route get Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 016/108] selftests: icmp_redirect: IPv6 PMTU info should be cleared after redirect Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 017/108] pwm: sprd: Ensure configuring period and duty_cycle isnt wrongly skipped Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 018/108] cxgb4: fix IRQ free race during driver unload Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 019/108] nvme-pci: do not call nvme_dev_remove_admin from nvme_remove Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 020/108] perf map: Fix dso->nsinfo refcounting Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 021/108] perf probe: " Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 022/108] perf env: Fix sibling_dies memory leak Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 023/108] perf test session_topology: Delete session->evlist Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 024/108] perf test event_update: Fix memory leak of evlist Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 025/108] perf dso: Fix memory leak in dso__new_map() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 026/108] perf script: Fix memory threads and cpus leaks on exit Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 027/108] perf lzma: Close lzma stream " Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 028/108] perf probe-file: Delete namelist in del_events() on the error path Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 029/108] perf data: Close all files in close_dir() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 030/108] spi: imx: add a check for speed_hz before calculating the clock Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 031/108] spi: stm32: Use dma_request_chan() instead dma_request_slave_channel() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 032/108] spi: stm32: fixes pm_runtime calls in probe/remove Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 033/108] regulator: hi6421: Use correct variable type for regmap api val argument Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 034/108] regulator: hi6421: Fix getting wrong drvdata Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 035/108] spi: mediatek: fix fifo rx mode Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 036/108] ASoC: rt5631: Fix regcache sync errors on resume Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 037/108] liquidio: Fix unintentional sign extension issue on left shift of u16 Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 038/108] s390/bpf: Perform r1 range checking before accessing jit->seen_reg[r1] Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 039/108] bpf, sockmap, tcp: sk_prot needs inuse_idx set for proc stats Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 040/108] bpftool: Check malloc return value in mount_bpffs_for_pin Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 041/108] net: fix uninit-value in caif_seqpkt_sendmsg Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 042/108] efi/tpm: Differentiate missing and invalid final event log table Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 043/108] net: decnet: Fix sleeping inside in af_decnet Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 044/108] KVM: PPC: Book3S: Fix CONFIG_TRANSACTIONAL_MEM=n crash Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 045/108] KVM: PPC: Fix kvm_arch_vcpu_ioctl vcpu_load leak Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 046/108] net: sched: fix memory leak in tcindex_partial_destroy_work Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 047/108] netrom: Decrease sock refcount when sock timers expire Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 048/108] scsi: iscsi: Fix iface sysfs attr detection Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 049/108] scsi: target: Fix protect handling in WRITE SAME(32) Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 050/108] spi: cadence: Correct initialisation of runtime PM again Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 051/108] bnxt_en: Improve bnxt_ulp_stop()/bnxt_ulp_start() call sequence Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 052/108] bnxt_en: Refresh RoCE capabilities in bnxt_ulp_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 053/108] bnxt_en: Add missing check for BNXT_STATE_ABORT_ERR in bnxt_fw_rset_task() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 054/108] bnxt_en: Check abort error state in bnxt_half_open_nic() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 055/108] net: hisilicon: rename CACHE_LINE_MASK to avoid redefinition Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 056/108] net/tcp_fastopen: fix data races around tfo_active_disable_stamp Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 057/108] net: hns3: fix rx VLAN offload state inconsistent issue Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 058/108] net/sched: act_skbmod: Skip non-Ethernet packets Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 059/108] ipv6: fix another slab-out-of-bounds in fib6_nh_flush_exceptions Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 060/108] nvme-pci: dont WARN_ON in nvme_reset_work if ctrl.state is not RESETTING Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 061/108] Revert "USB: quirks: ignore remote wake-up on Fibocom L850-GL LTE modem" Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 062/108] afs: Fix tracepoint string placement with built-in AFS Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 063/108] r8169: Avoid duplicate sysfs entry creation error Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 064/108] nvme: set the PRACT bit when using Write Zeroes with T10 PI Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 065/108] sctp: update active_key for asoc when old key is being replaced Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 066/108] net: sched: cls_api: Fix the the wrong parameter Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 067/108] drm/panel: raspberrypi-touchscreen: Prevent double-free Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 068/108] proc: Avoid mixing integer types in mem_rw() Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 069/108] [PATCH] Revert "MIPS: add PMD table accounting into MIPSpmd_alloc_one" Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 070/108] s390/ftrace: fix ftrace_update_ftrace_func implementation Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 071/108] s390/boot: fix use of expolines in the DMA code Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 072/108] ALSA: usb-audio: Add missing proc text entry for BESPOKEN type Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 073/108] ALSA: usb-audio: Add registration quirk for JBL Quantum headsets Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 074/108] ALSA: sb: Fix potential ABBA deadlock in CSP driver Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 075/108] ALSA: hdmi: Expose all pins on MSI MS-7C94 board Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 076/108] xhci: Fix lost USB 2 remote wake Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 077/108] KVM: PPC: Book3S: Fix H_RTAS rets buffer overflow Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 078/108] KVM: PPC: Book3S HV Nested: Sanitise H_ENTER_NESTED TM state Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 079/108] usb: hub: Disable USB 3 device initiated lpm if exit latency is too high Greg Kroah-Hartman
2021-07-26 15:39 ` Greg Kroah-Hartman [this message]
2021-07-26 15:39 ` [PATCH 5.4 081/108] USB: usb-storage: Add LaCie Rugged USB3-FW to IGNORE_UAS Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 082/108] usb: max-3421: Prevent corruption of freed memory Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 083/108] usb: renesas_usbhs: Fix superfluous irqs happen after usb_pkt_pop() Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 084/108] USB: serial: option: add support for u-blox LARA-R6 family Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 085/108] USB: serial: cp210x: fix comments for GE CS1000 Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 086/108] USB: serial: cp210x: add ID for CEL EM3588 USB ZigBee stick Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 087/108] usb: dwc2: gadget: Fix sending zero length packet in DDMA mode Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 088/108] firmware/efi: Tell memblock about EFI iomem reservations Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 089/108] tracing/histogram: Rename "cpu" to "common_cpu" Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 090/108] tracing: Fix bug in rb_per_cpu_empty() that might cause deadloop Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 091/108] btrfs: check for missing device in btrfs_trim_fs Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 092/108] media: ngene: Fix out-of-bounds bug in ngene_command_config_free_buf() Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 093/108] ixgbe: Fix packet corruption due to missing DMA sync Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 094/108] selftest: use mmap instead of posix_memalign to allocate memory Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 095/108] userfaultfd: do not untag user pointers Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 096/108] hugetlbfs: fix mount mode command line processing Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 097/108] rbd: dont hold lock_rwsem while running_list is being drained Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 098/108] rbd: always kick acquire on "acquired" and "released" notifications Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 099/108] nds32: fix up stack guard gap Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 100/108] drm: Return -ENOTTY for non-drm ioctls Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 101/108] net: dsa: mv88e6xxx: use correct .stats_set_histogram() on Topaz Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 102/108] net: bcmgenet: ensure EXT_ENERGY_DET_MASK is clear Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 103/108] iio: accel: bma180: Use explicit member assignment Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 104/108] iio: accel: bma180: Fix BMA25x bandwidth register values Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 105/108] btrfs: compression: dont try to compress if we dont have enough pages Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 106/108] PCI: Mark AMD Navi14 GPU ATS as broken Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 107/108] perf inject: Close inject.output on exit Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 108/108] xhci: add xhci_get_virt_ep() helper Greg Kroah-Hartman
2021-07-26 21:15 ` [PATCH 5.4 000/108] 5.4.136-rc1 review Florian Fainelli
2021-07-27  0:35 ` Shuah Khan
2021-07-27  8:49 ` Naresh Kamboju
2021-07-27  9:43 ` Jon Hunter
2021-07-27 16:06 ` Sudip Mukherjee
2021-07-27 18:02 ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210726153834.241087667@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=stable@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).