Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: host: fotg210: fix the endpoint's transactional opportunities calculation

Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we should make use of the
usb_endpoint_* helpers instead and remove the unnecessary
max_packet()/hb_mult() macro.

Signed-off-by: Kelly Devilliv <kelly.devilliv@gmail.com>
Link: https://lore.kernel.org/r/20210627125747.127646-3-kelly.devilliv@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kelly Devilliv and committed by
Greg Kroah-Hartman
c2e89876 c4c1faf8

+17 -19
+17 -19
drivers/usb/host/fotg210-hcd.c
··· 2512 2512 return count; 2513 2513 } 2514 2514 2515 - /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */ 2516 - #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03)) 2517 - /* ... and packet size, for any kind of endpoint descriptor */ 2518 - #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff) 2519 - 2520 2515 /* reverse of qh_urb_transaction: free a list of TDs. 2521 2516 * used for cleanup after errors, before HC sees an URB's TDs. 2522 2517 */ ··· 2597 2602 token |= (1 /* "in" */ << 8); 2598 2603 /* else it's already initted to "out" pid (0 << 8) */ 2599 2604 2600 - maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input)); 2605 + maxpacket = usb_maxpacket(urb->dev, urb->pipe, !is_input); 2601 2606 2602 2607 /* 2603 2608 * buffer gets wrapped in one or more qtds; ··· 2711 2716 gfp_t flags) 2712 2717 { 2713 2718 struct fotg210_qh *qh = fotg210_qh_alloc(fotg210, flags); 2719 + struct usb_host_endpoint *ep; 2714 2720 u32 info1 = 0, info2 = 0; 2715 2721 int is_input, type; 2716 2722 int maxp = 0; 2723 + int mult; 2717 2724 struct usb_tt *tt = urb->dev->tt; 2718 2725 struct fotg210_qh_hw *hw; 2719 2726 ··· 2730 2733 2731 2734 is_input = usb_pipein(urb->pipe); 2732 2735 type = usb_pipetype(urb->pipe); 2733 - maxp = usb_maxpacket(urb->dev, urb->pipe, !is_input); 2736 + ep = usb_pipe_endpoint(urb->dev, urb->pipe); 2737 + maxp = usb_endpoint_maxp(&ep->desc); 2738 + mult = usb_endpoint_maxp_mult(&ep->desc); 2734 2739 2735 2740 /* 1024 byte maxpacket is a hardware ceiling. High bandwidth 2736 2741 * acts like up to 3KB, but is built from smaller packets. 2737 2742 */ 2738 - if (max_packet(maxp) > 1024) { 2739 - fotg210_dbg(fotg210, "bogus qh maxpacket %d\n", 2740 - max_packet(maxp)); 2743 + if (maxp > 1024) { 2744 + fotg210_dbg(fotg210, "bogus qh maxpacket %d\n", maxp); 2741 2745 goto done; 2742 2746 } 2743 2747 ··· 2752 2754 */ 2753 2755 if (type == PIPE_INTERRUPT) { 2754 2756 qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, 2755 - is_input, 0, 2756 - hb_mult(maxp) * max_packet(maxp))); 2757 + is_input, 0, mult * maxp)); 2757 2758 qh->start = NO_FRAME; 2758 2759 2759 2760 if (urb->dev->speed == USB_SPEED_HIGH) { ··· 2789 2792 think_time = tt ? tt->think_time : 0; 2790 2793 qh->tt_usecs = NS_TO_US(think_time + 2791 2794 usb_calc_bus_time(urb->dev->speed, 2792 - is_input, 0, max_packet(maxp))); 2795 + is_input, 0, maxp)); 2793 2796 qh->period = urb->interval; 2794 2797 if (qh->period > fotg210->periodic_size) { 2795 2798 qh->period = fotg210->periodic_size; ··· 2852 2855 * to help them do so. So now people expect to use 2853 2856 * such nonconformant devices with Linux too; sigh. 2854 2857 */ 2855 - info1 |= max_packet(maxp) << 16; 2858 + info1 |= maxp << 16; 2856 2859 info2 |= (FOTG210_TUNE_MULT_HS << 30); 2857 2860 } else { /* PIPE_INTERRUPT */ 2858 - info1 |= max_packet(maxp) << 16; 2859 - info2 |= hb_mult(maxp) << 30; 2861 + info1 |= maxp << 16; 2862 + info2 |= mult << 30; 2860 2863 } 2861 2864 break; 2862 2865 default: ··· 3926 3929 int is_input; 3927 3930 long bandwidth; 3928 3931 unsigned multi; 3932 + struct usb_host_endpoint *ep; 3929 3933 3930 3934 /* 3931 3935 * this might be a "high bandwidth" highspeed endpoint, ··· 3934 3936 */ 3935 3937 epnum = usb_pipeendpoint(pipe); 3936 3938 is_input = usb_pipein(pipe) ? USB_DIR_IN : 0; 3937 - maxp = usb_maxpacket(dev, pipe, !is_input); 3939 + ep = usb_pipe_endpoint(dev, pipe); 3940 + maxp = usb_endpoint_maxp(&ep->desc); 3938 3941 if (is_input) 3939 3942 buf1 = (1 << 11); 3940 3943 else 3941 3944 buf1 = 0; 3942 3945 3943 - maxp = max_packet(maxp); 3944 - multi = hb_mult(maxp); 3946 + multi = usb_endpoint_maxp_mult(&ep->desc); 3945 3947 buf1 |= maxp; 3946 3948 maxp *= multi; 3947 3949