From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
alan@lxorguk.ukuu.org.uk,
Sarah Sharp <sarah.a.sharp@linux.intel.com>,
Chintan Mehta <chintan.mehta@sibridgetech.com>,
Shimmer Huang <shimmering.h@gmail.com>,
Bhavik Kothari <bhavik.kothari@sibridgetech.com>
Subject: [ 49/80] xHCI: Fix TD Size calculation on 1.0 hosts.
Date: Wed, 9 Jan 2013 12:35:41 -0800 [thread overview]
Message-ID: <20130109201506.719366083@linuxfoundation.org> (raw)
In-Reply-To: <20130109201500.410171651@linuxfoundation.org>
3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sarah Sharp <sarah.a.sharp@linux.intel.com>
commit 4525c0a10dff7ad3669763c28016c7daffc3900e upstream.
The xHCI 1.0 specification made a change to the TD Size field in TRBs.
The value is now the number of packets that remain to be sent in the TD,
not including this TRB. The TD Size value for the last TRB in a TD must
always be zero.
The xHCI function xhci_v1_0_td_remainder() attempts to calculate this,
but it gets it wrong. First, it erroneously reuses the old
xhci_td_remainder function, which will right shift the value by 10. The
xHCI 1.0 spec as of June 2011 says nothing about right shifting by 10.
Second, it does not set the TD size for the last TRB in a TD to zero.
Third, it uses roundup instead of DIV_ROUND_UP. The total packet count
is supposed to be the total number of bytes in this TD, divided by the
max packet size, rounded up. DIV_ROUND_UP is the right function to use
in that case.
With the old code, a TD on an endpoint with max packet size 1024 would
be set up like so:
TRB 1, TRB length = 600 bytes, TD size = 0
TRB 1, TRB length = 200 bytes, TD size = 0
TRB 1, TRB length = 100 bytes, TD size = 0
With the new code, the TD would be set up like this:
TRB 1, TRB length = 600 bytes, TD size = 1
TRB 1, TRB length = 200 bytes, TD size = 1
TRB 1, TRB length = 100 bytes, TD size = 0
This commit should be backported to kernels as old as 3.0, that contain
the commit 4da6e6f247a2601ab9f1e63424e4d944ed4124f3 "xhci 1.0: Update TD
size field format."
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Reported-by: Chintan Mehta <chintan.mehta@sibridgetech.com>
Reported-by: Shimmer Huang <shimmering.h@gmail.com>
Tested-by: Bhavik Kothari <bhavik.kothari@sibridgetech.com>
Tested-by: Shimmer Huang <shimmering.h@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/usb/host/xhci-ring.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3069,11 +3069,11 @@ static u32 xhci_td_remainder(unsigned in
}
/*
- * For xHCI 1.0 host controllers, TD size is the number of packets remaining in
- * the TD (*not* including this TRB).
+ * For xHCI 1.0 host controllers, TD size is the number of max packet sized
+ * packets remaining in the TD (*not* including this TRB).
*
* Total TD packet count = total_packet_count =
- * roundup(TD size in bytes / wMaxPacketSize)
+ * DIV_ROUND_UP(TD size in bytes / wMaxPacketSize)
*
* Packets transferred up to and including this TRB = packets_transferred =
* rounddown(total bytes transferred including this TRB / wMaxPacketSize)
@@ -3081,15 +3081,16 @@ static u32 xhci_td_remainder(unsigned in
* TD size = total_packet_count - packets_transferred
*
* It must fit in bits 21:17, so it can't be bigger than 31.
+ * The last TRB in a TD must have the TD size set to zero.
*/
-
static u32 xhci_v1_0_td_remainder(int running_total, int trb_buff_len,
- unsigned int total_packet_count, struct urb *urb)
+ unsigned int total_packet_count, struct urb *urb,
+ unsigned int num_trbs_left)
{
int packets_transferred;
/* One TRB with a zero-length data packet. */
- if (running_total == 0 && trb_buff_len == 0)
+ if (num_trbs_left == 0 || (running_total == 0 && trb_buff_len == 0))
return 0;
/* All the TRB queueing functions don't count the current TRB in
@@ -3098,7 +3099,9 @@ static u32 xhci_v1_0_td_remainder(int ru
packets_transferred = (running_total + trb_buff_len) /
usb_endpoint_maxp(&urb->ep->desc);
- return xhci_td_remainder(total_packet_count - packets_transferred);
+ if ((total_packet_count - packets_transferred) > 31)
+ return 31 << 17;
+ return (total_packet_count - packets_transferred) << 17;
}
static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
@@ -3125,7 +3128,7 @@ static int queue_bulk_sg_tx(struct xhci_
num_trbs = count_sg_trbs_needed(xhci, urb);
num_sgs = urb->num_mapped_sgs;
- total_packet_count = roundup(urb->transfer_buffer_length,
+ total_packet_count = DIV_ROUND_UP(urb->transfer_buffer_length,
usb_endpoint_maxp(&urb->ep->desc));
trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id],
@@ -3208,7 +3211,8 @@ static int queue_bulk_sg_tx(struct xhci_
running_total);
} else {
remainder = xhci_v1_0_td_remainder(running_total,
- trb_buff_len, total_packet_count, urb);
+ trb_buff_len, total_packet_count, urb,
+ num_trbs - 1);
}
length_field = TRB_LEN(trb_buff_len) |
remainder |
@@ -3316,7 +3320,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *
start_cycle = ep_ring->cycle_state;
running_total = 0;
- total_packet_count = roundup(urb->transfer_buffer_length,
+ total_packet_count = DIV_ROUND_UP(urb->transfer_buffer_length,
usb_endpoint_maxp(&urb->ep->desc));
/* How much data is in the first TRB? */
addr = (u64) urb->transfer_dma;
@@ -3362,7 +3366,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *
running_total);
} else {
remainder = xhci_v1_0_td_remainder(running_total,
- trb_buff_len, total_packet_count, urb);
+ trb_buff_len, total_packet_count, urb,
+ num_trbs - 1);
}
length_field = TRB_LEN(trb_buff_len) |
remainder |
@@ -3625,7 +3630,7 @@ static int xhci_queue_isoc_tx(struct xhc
addr = start_addr + urb->iso_frame_desc[i].offset;
td_len = urb->iso_frame_desc[i].length;
td_remain_len = td_len;
- total_packet_count = roundup(td_len,
+ total_packet_count = DIV_ROUND_UP(td_len,
usb_endpoint_maxp(&urb->ep->desc));
/* A zero-length transfer still involves at least one packet. */
if (total_packet_count == 0)
@@ -3704,7 +3709,8 @@ static int xhci_queue_isoc_tx(struct xhc
} else {
remainder = xhci_v1_0_td_remainder(
running_total, trb_buff_len,
- total_packet_count, urb);
+ total_packet_count, urb,
+ (trbs_per_td - j - 1));
}
length_field = TRB_LEN(trb_buff_len) |
remainder |
next prev parent reply other threads:[~2013-01-09 20:35 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-09 20:34 [ 00/80] 3.4.25-stable review Greg Kroah-Hartman
2013-01-09 20:34 ` [ 01/80] bonding: Bonding driver does not consider the gso_max_size/gso_max_segs setting of slave devices Greg Kroah-Hartman
2013-01-09 20:34 ` [ 02/80] bonding: fix race condition in bonding_store_slaves_active Greg Kroah-Hartman
2013-01-09 20:34 ` [ 03/80] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails Greg Kroah-Hartman
2013-01-09 20:34 ` [ 04/80] sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall Greg Kroah-Hartman
2013-01-09 20:34 ` [ 05/80] ne2000: add the right platform device Greg Kroah-Hartman
2013-01-09 20:34 ` [ 06/80] irda: sir_dev: Fix copy/paste typo Greg Kroah-Hartman
2013-01-09 20:34 ` [ 07/80] ipv4: ip_check_defrag must not modify skb before unsharing Greg Kroah-Hartman
2013-01-09 20:35 ` [ 08/80] usb/ipheth: Add iPhone 5 support Greg Kroah-Hartman
2013-01-09 20:35 ` [ 09/80] inet_diag: fix oops for IPv4 AF_INET6 TCP SYN-RECV state Greg Kroah-Hartman
2013-01-09 20:35 ` [ 10/80] inet_diag: validate byte code to prevent oops in inet_diag_bc_run() Greg Kroah-Hartman
2013-01-09 20:35 ` [ 11/80] inet_diag: avoid unsafe and nonsensical prefix matches " Greg Kroah-Hartman
2013-01-09 20:35 ` [ 12/80] inet_diag: validate port comparison byte code to prevent unsafe reads Greg Kroah-Hartman
2013-01-09 20:35 ` [ 13/80] b43legacy: Fix firmware loading when driver is built into the kernel Greg Kroah-Hartman
2013-01-09 20:35 ` [ 14/80] b43: fix tx path skb leaks Greg Kroah-Hartman
2013-01-09 20:35 ` [ 15/80] pnpacpi: fix incorrect TEST_ALPHA() test Greg Kroah-Hartman
2013-01-09 20:35 ` [ 16/80] SGI-XP: handle non-fatal traps Greg Kroah-Hartman
2013-01-09 20:35 ` [ 17/80] exec: do not leave bprm->interp on stack Greg Kroah-Hartman
2013-01-09 20:35 ` [ 18/80] x86, 8042: Enable A20 using KBC to fix S3 resume on some MSI laptops Greg Kroah-Hartman
2013-01-09 20:35 ` [ 19/80] virtio: force vring descriptors to be allocated from lowmem Greg Kroah-Hartman
2013-01-09 20:35 ` [ 20/80] mm: fix calculation of dirtyable memory Greg Kroah-Hartman
2013-01-09 20:35 ` [ 21/80] mm: Fix PageHead when !CONFIG_PAGEFLAGS_EXTENDED Greg Kroah-Hartman
2013-01-09 20:35 ` [ 22/80] tmpfs mempolicy: fix /proc/mounts corrupting memory Greg Kroah-Hartman
2013-01-09 20:35 ` [ 23/80] ALSA: usb-audio: Avoid autopm calls after disconnection Greg Kroah-Hartman
2013-01-09 20:35 ` [ 24/80] ALSA: usb-audio: Fix missing autopm for MIDI input Greg Kroah-Hartman
2013-01-09 20:35 ` [ 25/80] ALSA: hda - Fix the wrong pincaps set in ALC861VD dallas/hp fixup Greg Kroah-Hartman
2013-01-09 20:35 ` [ 26/80] ALSA: hda - Fix pin configuration of HP Pavilion dv7 Greg Kroah-Hartman
2013-01-09 20:35 ` [ 27/80] rtlwifi: fix incorrect use of usb_alloc_coherent with usb_control_msg Greg Kroah-Hartman
2013-01-09 20:35 ` [ 28/80] p54usb: add USB ID for T-Com Sinus 154 data II Greg Kroah-Hartman
2013-01-09 20:35 ` [ 29/80] p54usb: add USBIDs for two more p54usb devices Greg Kroah-Hartman
2013-01-09 20:35 ` [ 30/80] usb: gadget: midi: free hs descriptors Greg Kroah-Hartman
2013-01-09 20:35 ` [ 31/80] usb: gadget: phonet: free requests in pn_bind()s error path Greg Kroah-Hartman
2013-01-09 20:35 ` [ 32/80] usb: gadget: uvc: fix error path in uvc_function_bind() Greg Kroah-Hartman
2013-01-09 20:35 ` [ 33/80] usb: gadget: network: fix bind() error path Greg Kroah-Hartman
2013-01-09 20:35 ` [ 34/80] ACPI: do acpisleep dmi check when CONFIG_ACPI_SLEEP is set Greg Kroah-Hartman
2013-01-09 20:35 ` [ 35/80] ACPI / scan: Do not use dummy HID for system bus ACPI nodes Greg Kroah-Hartman
2013-01-09 20:35 ` [ 36/80] NFS: Add sequence_priviliged_ops for nfs4_proc_sequence() Greg Kroah-Hartman
2013-01-09 20:35 ` [ 37/80] NFS: avoid NULL dereference in nfs_destroy_server Greg Kroah-Hartman
2013-01-09 20:35 ` [ 38/80] NFS: Fix calls to drop_nlink() Greg Kroah-Hartman
2013-01-09 20:35 ` [ 39/80] nfs: fix wrong object type in lockowner_slab Greg Kroah-Hartman
2013-01-09 20:35 ` [ 40/80] nfsd: fix v4 reply caching Greg Kroah-Hartman
2013-01-09 20:35 ` [ 41/80] nfsd4: fix oops on unusual readlike compound Greg Kroah-Hartman
2013-01-09 20:35 ` [ 42/80] nfsd: avoid permission checks on EXCLUSIVE_CREATE replay Greg Kroah-Hartman
2013-01-09 20:35 ` [ 43/80] nfs: fix null checking in nfs_get_option_str() Greg Kroah-Hartman
2013-01-09 20:35 ` [ 44/80] Input: walkera0701 - fix crash on startup Greg Kroah-Hartman
2013-01-09 20:35 ` [ 45/80] Input: sentelic - only report position of first finger as ST coordinates Greg Kroah-Hartman
2013-01-09 20:35 ` [ 46/80] genirq: Always force thread affinity Greg Kroah-Hartman
2013-01-09 20:35 ` [ 47/80] usb: musb: cppi_dma: export cppi_interrupt() Greg Kroah-Hartman
2013-01-09 20:35 ` [ 48/80] xhci: Fix conditional check in bandwidth calculation Greg Kroah-Hartman
2013-01-09 20:35 ` Greg Kroah-Hartman [this message]
2013-01-09 20:35 ` [ 50/80] xhci: fix null-pointer dereference when destroying half-built segment rings Greg Kroah-Hartman
2013-01-09 20:35 ` [ 51/80] usb: host: xhci: Stricter conditional for Z1 system models for Compliance Mode Patch Greg Kroah-Hartman
2013-01-09 20:35 ` [ 52/80] xhci: Add Lynx Point LP to list of Intel switchable hosts Greg Kroah-Hartman
2013-01-09 20:35 ` [ 53/80] cgroup: remove incorrect dget/dput() pair in cgroup_create_dir() Greg Kroah-Hartman
2013-01-09 20:35 ` [ 54/80] freezer: add missing mbs to freezer_count() and freezer_should_skip() Greg Kroah-Hartman
2013-01-09 20:35 ` [ 55/80] x86, amd: Disable way access filter on Piledriver CPUs Greg Kroah-Hartman
2013-01-09 20:35 ` [ 56/80] sparc: huge_ptep_set_* functions need to call set_huge_pte_at() Greg Kroah-Hartman
2013-01-09 20:35 ` [ 57/80] batman-adv: fix random jitter calculation Greg Kroah-Hartman
2013-01-09 20:35 ` [ 58/80] inet: Fix kmemleak in tcp_v4/6_syn_recv_sock and dccp_v4/6_request_recv_sock Greg Kroah-Hartman
2013-01-09 20:35 ` [ 59/80] net: sched: integer overflow fix Greg Kroah-Hartman
2013-01-09 20:35 ` [ 60/80] tcp: fix MSG_SENDPAGE_NOTLAST logic Greg Kroah-Hartman
2013-01-09 20:35 ` [ 61/80] tcp: implement RFC 5961 3.2 Greg Kroah-Hartman
2013-01-09 20:35 ` [ 62/80] tcp: implement RFC 5961 4.2 Greg Kroah-Hartman
2013-01-09 20:35 ` [ 63/80] tcp: refine SYN handling in tcp_validate_incoming Greg Kroah-Hartman
2013-01-09 20:35 ` [ 64/80] tcp: tcp_replace_ts_recent() should not be called from tcp_validate_incoming() Greg Kroah-Hartman
2013-01-09 20:35 ` [ 65/80] tcp: RFC 5961 5.2 Blind Data Injection Attack Mitigation Greg Kroah-Hartman
2013-01-09 20:35 ` [ 66/80] ARM: mm: use pteval_t to represent page protection values Greg Kroah-Hartman
2013-01-09 20:35 ` [ 67/80] ARM: missing ->mmap_sem around find_vma() in swp_emulate.c Greg Kroah-Hartman
2013-01-09 20:36 ` [ 68/80] ARM: 7607/1: realview: fix private peripheral memory base for EB rev. B boards Greg Kroah-Hartman
2013-01-09 20:36 ` [ 69/80] solos-pci: fix double-free of TX skb in DMA mode Greg Kroah-Hartman
2013-01-09 20:36 ` [ 70/80] PCI: Reduce Ricoh 0xe822 SD card reader base clock frequency to 50MHz Greg Kroah-Hartman
2013-01-09 20:36 ` [ 71/80] Bluetooth: ath3k: Add support for VAIO VPCEH [0489:e027] Greg Kroah-Hartman
2013-01-09 20:36 ` [ 72/80] Bluetooth: Add missing lock nesting notation Greg Kroah-Hartman
2013-01-09 20:36 ` [ 73/80] Bluetooth: cancel power_on work when unregistering the device Greg Kroah-Hartman
2013-01-09 20:36 ` [ 74/80] lib: atomic64: Initialize locks statically to fix early users Greg Kroah-Hartman
2013-01-09 20:36 ` [ 75/80] CRIS: fix I/O macros Greg Kroah-Hartman
2013-01-09 20:36 ` [ 76/80] drivers/rtc/rtc-vt8500.c: correct handling of CR_24H bitfield Greg Kroah-Hartman
2013-01-09 20:36 ` [ 77/80] drivers/rtc/rtc-vt8500.c: fix handling of data passed in struct rtc_time Greg Kroah-Hartman
2013-01-09 20:36 ` [ 78/80] mm: limit mmu_gather batching to fix soft lockups on !CONFIG_PREEMPT Greg Kroah-Hartman
2013-01-09 20:36 ` [ 79/80] HID: Add Apple wireless keyboard 2011 ANSI to special driver list Greg Kroah-Hartman
2013-01-09 20:36 ` [ 80/80] can: Do not call dev_put if restart timer is running upon close Greg Kroah-Hartman
2013-01-10 18:03 ` [ 00/80] 3.4.25-stable review Shuah Khan
2013-01-11 14:46 ` Satoru Takeuchi
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=20130109201506.719366083@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=bhavik.kothari@sibridgetech.com \
--cc=chintan.mehta@sibridgetech.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sarah.a.sharp@linux.intel.com \
--cc=shimmering.h@gmail.com \
--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).