From patchwork Mon Apr 16 12:29:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 10342869 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8775260365 for ; Mon, 16 Apr 2018 12:30:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78EB12870E for ; Mon, 16 Apr 2018 12:30:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76CF0286C5; Mon, 16 Apr 2018 12:30:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E9B32872C for ; Mon, 16 Apr 2018 12:30:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754606AbeDPMai (ORCPT ); Mon, 16 Apr 2018 08:30:38 -0400 Received: from mga11.intel.com ([192.55.52.93]:38850 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754577AbeDPMah (ORCPT ); Mon, 16 Apr 2018 08:30:37 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Apr 2018 05:30:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,459,1517904000"; d="scan'208";a="46532982" Received: from pipin.fi.intel.com (HELO localhost) ([10.237.68.37]) by fmsmga004.fm.intel.com with ESMTP; 16 Apr 2018 05:30:36 -0700 From: Felipe Balbi To: Mathias Nyman Cc: Linux USB , Felipe Balbi Subject: [PATCH 05/20] usb: host: xhci: introduce xhci_num_tds_for_urb() helper Date: Mon, 16 Apr 2018 15:29:15 +0300 Message-Id: <20180416122930.15697-5-felipe.balbi@linux.intel.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180416122930.15697-1-felipe.balbi@linux.intel.com> References: <20180416122930.15697-1-felipe.balbi@linux.intel.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This helper computes the number of TDs for a given urb. Cleanup only, no functional changes. Note that while at that we've replaced an alignment check with the IS_ALIGNED() macro which makes the code slightly clearer about its intention. Signed-off-by: Felipe Balbi --- drivers/usb/host/xhci.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index dba4c61f5cf6..f2733f717568 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1281,6 +1281,21 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id, return ret; } +static int xhci_num_tds_for_urb(struct urb *urb) +{ + if (usb_endpoint_xfer_isoc(&urb->ep->desc)) + return urb->number_of_packets; + + if (usb_endpoint_is_bulk_out(&urb->ep->desc) && + urb->transfer_buffer_length > 0 && + urb->transfer_flags & URB_ZERO_PACKET && + IS_ALIGNED(urb->transfer_buffer_length, + usb_endpoint_maxp(&urb->ep->desc))) + return 2; + + return 1; +} + /* * non-error returns are a promise to giveback() the urb later * we drop ownership so next owner (or urb unlink) can get it @@ -1327,16 +1342,7 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag } } - if (usb_endpoint_xfer_isoc(&urb->ep->desc)) - num_tds = urb->number_of_packets; - else if (usb_endpoint_is_bulk_out(&urb->ep->desc) && - urb->transfer_buffer_length > 0 && - urb->transfer_flags & URB_ZERO_PACKET && - !(urb->transfer_buffer_length % usb_endpoint_maxp(&urb->ep->desc))) - num_tds = 2; - else - num_tds = 1; - + num_tds = xhci_num_tds_for_urb(urb); urb_priv = kzalloc(sizeof(struct urb_priv) + num_tds * sizeof(struct xhci_td), mem_flags); if (!urb_priv)