Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3029790ybt; Mon, 29 Jun 2020 13:20:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO5sNsVR5fpZzwpNa8hBzIR6TGOFnC4mQrvC0BuQjpKoUZlr7NuOENxF7CkMUXLy6N+0jF X-Received: by 2002:a50:9b5d:: with SMTP id a29mr17109714edj.68.1593462051662; Mon, 29 Jun 2020 13:20:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593462051; cv=none; d=google.com; s=arc-20160816; b=bfr+xf/vokDMwkbTyJdy7R5Y8P7keSOjnfOKCkwQ9B3YxnlcX3zzyEiOtso9Wyr/d4 SakXQEpU+Y6nligKhvTNLarWKcmsX6rVQ88ser86nnliT8WB7JxLEoquTO/RJ3iFbUhF SVmOzcr/hRZwS0VXPgGg9ftig+93vM/s//mPaQqjv00/d5IQsb9MTRSedP38JWuj0aJZ ISPlqdEI2kJ7Y7OaQfw0pQtaUIIQcQg6ilvP07+wTCg6ICjSsCL5rnq08C/mMLbCxuqQ tJt0d517PoObHaMYnSqZatEr7sexsZ9x89O1EX0X0DDJu0RkqVNivoVeov8aL1TgPXYM HoYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=8KS8I9Q3x2kXGfX+XyyK1sOmdPbnTRSOpvvTvwkAeTs=; b=iJU/nXeVSZlMIwKiecMka5XK2egKzNnHDfEvzlqrvpCMJueV4x1zq6RI+g+oW3o7cE qKhh44Ve/Pk0rX8EY1/fohOAne4MbI1ydzLd22w46U5DoHhngqvwj1LMuhL+g08bCExc zTZ9N4E02TplhCAHeW5ejgoIuKc7mxQksNNe+x6odhavjtYgCELG/8aueXNzGOCpapig AxxWbc0dCwOyyQVCi+8NQ4RO+58hcVgZtDmBbdC+f/qBw2KFBUuiH7JIup/c8voaTKLR K1cXALk6Ji9TZKS1Pfs/nXKbf6xZXWd9l9fxxcnd4JJJqVI66td1fAP0A/E6w51wm1sh dXhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kKlzs4sb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b12si201551eds.283.2020.06.29.13.20.28; Mon, 29 Jun 2020 13:20:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kKlzs4sb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729774AbgF2USw (ORCPT + 99 others); Mon, 29 Jun 2020 16:18:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388538AbgF2USj (ORCPT ); Mon, 29 Jun 2020 16:18:39 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8720EC061755; Mon, 29 Jun 2020 13:18:38 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id b25so16139293ljp.6; Mon, 29 Jun 2020 13:18:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=8KS8I9Q3x2kXGfX+XyyK1sOmdPbnTRSOpvvTvwkAeTs=; b=kKlzs4sb6gvS9zYIlKdtNO9qZQptM0LCZ/5tTmz0g8zeAuvX6L7DG9YSQv5O6J8o0t +CfV51o+Z9H4vt+N0eAH1ce3eZwBa+rTl+XL8Hf1acezphKbNdejOR7/uTqpvIv9SfQA 2KWUGHa9aRo43YP5EqG7Hx9mGJwieKRlykPLqMKejsyZIky6Rpy0C0LZHNa3HINiVxpa MEuoN5HtplNVLYZFprLtWZFMPJ3H2GbFy+unFlOKGfRMW6Tbn6F2doUdsuu+6jTP+uWQ nvvaoXQQPTxy7YodFAQgWWGj5w3UiZCX3Y67jQeJz9wcdsDAK+XaohzCuEGB9fN7piJ+ ahYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=8KS8I9Q3x2kXGfX+XyyK1sOmdPbnTRSOpvvTvwkAeTs=; b=KsE/W+rfDYRWXsZsV0vEPeO4m2I8BnQfISLxWwOGtmoFlB9ZXp3T7ukjSXuPLDlj7/ Lf4xy7+4cL01mKYGweluUT0/2ONBfOzLFso/UimyzlhQCa1Z/jjKXTtEKxrrYW9V9f/K 1JJYYrPeAGlqEyVGgHYMFuHWRXfgIJUeqz+tVMOQrhpWgdjrfEjXZwSswOWuQrJ7uedy lfl4PBR7oCb90Q4khyrBbGkvpMaT8fWyUfoP68v02RraaIfdpNOtc5DbiReY8mw3+fao 8ncno4+QxpzC6L6c9eBVxjtykwjCKunDZ2AMqFoD/z6twJA89jhbTuLkt+iGT4iVVS6a oEIg== X-Gm-Message-State: AOAM531wiCNvQQWz9dUIZ6HnAPli7IyRKMfwpbbDRPVNhcEX/U3YUmyN P5Dk4rTmfYYNPpvTM4KSaqk= X-Received: by 2002:a2e:b88e:: with SMTP id r14mr8307120ljp.197.1593461917004; Mon, 29 Jun 2020 13:18:37 -0700 (PDT) Received: from localhost ([80.64.86.170]) by smtp.gmail.com with ESMTPSA id x64sm154660lff.14.2020.06.29.13.18.36 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jun 2020 13:18:36 -0700 (PDT) From: Ruslan Bilovol To: balbi@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] usb: gadget: epautoconf: claim smallest endpoints first Date: Mon, 29 Jun 2020 23:18:45 +0300 Message-Id: <20200629201845.28138-1-ruslan.bilovol@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org UDC hardware may have endpoints with different maxpacket size. Current endpoint matching code takes first matching endpoint from the list. It's always possible that gadget allocates endpoints for small transfers (maxpacket size) first, then larger ones. That works fine if all matching UDC endpoints have same maxpacket size or are big enough to serve that allocation. However, some UDCs have first endpoints in the list with bigger maxpacket size, whereas last endpoints are much smaller. In this case endpoint allocation will fail for the gadget (which allocates smaller endpoints first) on final endpoint allocations. To make endpoint allocation fair, pick up smallest matching endpoints first, leaving bigger ones for heavier applications. Signed-off-by: Ruslan Bilovol --- v2: rebased onto latest balbi/next branch drivers/usb/gadget/epautoconf.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index 1eb4fa2e623f..6c453b5d87bb 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c @@ -66,7 +66,7 @@ struct usb_ep *usb_ep_autoconfig_ss( struct usb_ss_ep_comp_descriptor *ep_comp ) { - struct usb_ep *ep; + struct usb_ep *ep, *ep_min = NULL; if (gadget->ops->match_ep) { ep = gadget->ops->match_ep(gadget, desc, ep_comp); @@ -74,14 +74,27 @@ struct usb_ep *usb_ep_autoconfig_ss( goto found_ep; } - /* Second, look at endpoints until an unclaimed one looks usable */ + /* + * Second, look at endpoints until an unclaimed one looks usable. + * Try to find one with smallest maxpacket limit, leaving larger + * endpoints for heavier applications + */ list_for_each_entry (ep, &gadget->ep_list, ep_list) { - if (usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp)) - goto found_ep; + if (usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp)) { + if (desc->wMaxPacketSize == 0) + goto found_ep; + else if (!ep_min) + ep_min = ep; + else if (ep->maxpacket_limit < ep_min->maxpacket_limit) + ep_min = ep; + } } /* Fail */ - return NULL; + if (!ep_min) + return NULL; + + ep = ep_min; found_ep: /* -- 2.17.1