Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754639AbbGaOGP (ORCPT ); Fri, 31 Jul 2015 10:06:15 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:48327 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752630AbbGaOGL (ORCPT ); Fri, 31 Jul 2015 10:06:11 -0400 X-AuditID: cbfee61b-f79706d000001b96-fd-55bb80d1a7f6 From: Robert Baldyga To: balbi@ti.com Cc: gregkh@linuxfoundation.org, Peter.Chen@freescale.com, johnyoun@synopsys.com, dahlmann.thomas@arcor.de, nicolas.ferre@atmel.com, cernekee@gmail.com, leoli@freescale.com, daniel@zonque.org, haojian.zhuang@gmail.com, robert.jarzmik@free.fr, michal.simek@xilinx.com, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-omap@vger.kernel.org, linux-geode@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, andrzej.p@samsung.com, m.szyprowski@samsung.com, stern@rowland.harvard.edu, petr.cvek@tul.cz, Robert Baldyga Subject: [PATCH v5 40/46] usb: gadget: epautoconf: rework ep_matches() function Date: Fri, 31 Jul 2015 16:00:52 +0200 Message-id: <1438351258-31578-41-git-send-email-r.baldyga@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1438351258-31578-1-git-send-email-r.baldyga@samsung.com> References: <1438351258-31578-1-git-send-email-r.baldyga@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprLIsWRmVeSWpSXmKPExsVy+t9jAd2LDbtDDea3GljMetnOYnHwfr3F 3gV3GS067x9mtmj6+4rFYs+ZX+wWzYvXs1lcWGdusfv0JUaLXw+ELDY9vsZq0X/uNIvF5V1z 2CxmL+lnsVi0rJXZ4vf3f6wWa4/cZbd49zLC4tvlZnaLY7P/MlnM75jKavHg8E52i1lvhC0m /L7A5iDhMfnJRiaPBb+2snjc23eYxaN/3WdWj3+H+5k8ds66y+6xf+4ado/NS+o9zs9YyOgx ++4PRo++LasYPbbs/8zocfzGdiaPmSt72Tw+b5Lz2Pv5N0uAYBSXTUpqTmZZapG+XQJXRv/5 buaCTzIVd3rOMTYwThTrYuTkkBAwkeg428UIYYtJXLi3nq2LkYtDSGApo8TctxMZIZyfjBIP bz5kA6liE9CR2PJ9AliHiICAxPoXl9hBipgFfrBInJ3XzQ6SEBbwl9hz9g9YEYuAqkTX1Zss XYwcHLwCbhL/mh0gtslJnDw2mRXE5gQKf11/FqxVSMBV4sixU8wTGHkXMDKsYpRILUguKE5K zzXKSy3XK07MLS7NS9dLzs/dxAiOtGfSOxgP73I/xCjAwajEwyuweFeoEGtiWXFl7iFGCQ5m JRHe+2q7Q4V4UxIrq1KL8uOLSnNSiw8xSnOwKInz6ptsChUSSE8sSc1OTS1ILYLJMnFwSjUw 2lYfypuhV1f1s2iV+dk93cU8xXnP6mfzsK0rmO54cyeL623H6dfCV6rk1yu+P/mh7unttx/N mBWLHn447b9P45iTTamC78si5i3GT04I3z119s0GxvATuuduzFSas9N8nfTLcC1rt1IfvdJn U6f1XY/mEugqmHvv5OVpizeLm5asun6ot/9NixJLcUaioRZzUXEiAKFDGj+wAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3810 Lines: 138 Rework ep_matches() function to make it shorter and more readable. Signed-off-by: Robert Baldyga --- drivers/usb/gadget/epautoconf.c | 87 +++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 52 deletions(-) diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index 7bb28f1..4fa6f5d 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c @@ -30,16 +30,29 @@ ep_matches ( struct usb_ss_ep_comp_descriptor *ep_comp ) { - u8 type; - u16 max; - - int num_req_streams = 0; + u8 type; + u16 max; + int num_req_streams = 0; /* endpoint already claimed? */ if (ep->claimed) return 0; type = usb_endpoint_type(desc); + max = 0x7ff & usb_endpoint_maxp(desc); + + if (usb_endpoint_dir_in(desc) && !ep->caps.dir_in) + return 0; + else if (!ep->caps.dir_out) + return 0; + + if (max > ep->maxpacket_limit) + return 0; + + /* "high bandwidth" works only at high speed */ + if (!gadget_is_dualspeed(gadget) && usb_endpoint_maxp(desc) & (3<<11)) + return 0; + switch (type) { case USB_ENDPOINT_XFER_CONTROL: /* only support ep0 for portable CONTROL traffic */ @@ -47,66 +60,36 @@ ep_matches ( case USB_ENDPOINT_XFER_ISOC: if (!ep->caps.type_iso) return 0; + /* ISO: limit 1023 bytes full speed, + * 1024 high/super speed + */ + if (!gadget_is_dualspeed(gadget) && max > 1023) + return 0; break; case USB_ENDPOINT_XFER_BULK: if (!ep->caps.type_bulk) return 0; + if (ep_comp && gadget_is_superspeed(gadget)) { + /* Get the number of required streams from the + * EP companion descriptor and see if the EP + * matches it + */ + num_req_streams = ep_comp->bmAttributes & 0x1f; + if (num_req_streams > ep->max_streams) + return 0; + } break; case USB_ENDPOINT_XFER_INT: - /* bulk endpoints handle interrupt transfers, + /* Bulk endpoints handle interrupt transfers, * except the toggle-quirky iso-synch kind */ if (!ep->caps.type_int && !ep->caps.type_bulk) return 0; - break; - } - - if (usb_endpoint_dir_in(desc)) { - if (!ep->caps.dir_in) - return 0; - } else { - if (!ep->caps.dir_out) - return 0; - } - - /* - * Get the number of required streams from the EP companion - * descriptor and see if the EP matches it - */ - if (usb_endpoint_xfer_bulk(desc)) { - if (ep_comp && gadget->max_speed >= USB_SPEED_SUPER) { - num_req_streams = ep_comp->bmAttributes & 0x1f; - if (num_req_streams > ep->max_streams) - return 0; - } - - } - - /* endpoint maxpacket size is an input parameter, except for bulk - * where it's an output parameter representing the full speed limit. - * the usb spec fixes high speed bulk maxpacket at 512 bytes. - */ - max = 0x7ff & usb_endpoint_maxp(desc); - switch (type) { - case USB_ENDPOINT_XFER_INT: - /* INT: limit 64 bytes full speed, 1024 high/super speed */ + /* INT: limit 64 bytes full speed, + * 1024 high/super speed + */ if (!gadget_is_dualspeed(gadget) && max > 64) return 0; - /* FALLTHROUGH */ - - case USB_ENDPOINT_XFER_ISOC: - /* ISO: limit 1023 bytes full speed, 1024 high/super speed */ - if (ep->maxpacket_limit < max) - return 0; - if (!gadget_is_dualspeed(gadget) && max > 1023) - return 0; - - /* BOTH: "high bandwidth" works only at high speed */ - if ((desc->wMaxPacketSize & cpu_to_le16(3<<11))) { - if (!gadget_is_dualspeed(gadget)) - return 0; - /* configure your hardware with enough buffering!! */ - } break; } -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/