Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759510AbbKTJ37 (ORCPT ); Fri, 20 Nov 2015 04:29:59 -0500 Received: from mail-bl2on0143.outbound.protection.outlook.com ([65.55.169.143]:20517 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1161252AbbKTJ3r (ORCPT ); Fri, 20 Nov 2015 04:29:47 -0500 Authentication-Results: spf=permerror (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; samsung.com; dkim=none (message not signed) header.d=none;samsung.com; dmarc=none action=none header.from=freescale.com; Date: Fri, 20 Nov 2015 17:26:53 +0800 From: Peter Chen To: Marek Szyprowski CC: , , "Ruslan Bilovol" , Bartlomiej Zolnierkiewicz Subject: Re: [PATCH v6 4/4] usb: gadget: udc-core: independent registration of gadgets and gadget drivers Message-ID: <20151120092652.GF30829@shlinux2> References: <1448009652-14716-1-git-send-email-m.szyprowski@samsung.com> <1448009652-14716-5-git-send-email-m.szyprowski@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1448009652-14716-5-git-send-email-m.szyprowski@samsung.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11OLC008;1:P8cG+WGHUl+F0FTmfvPXWCDtuYN+jLR+iTgr05rK6Jbyj7vNiUCaPmPtjGBXqWybEHwl4VAGKOAWLEDqGA6ak+4CHBiRlv+6cmeSJ4psKCDUa6iez427x5F8nBc79p+MZKdjRXL65wYx+CEI+I5LTDSZIYf8iyvGeSMax5s/kWp44ub3FYxTqRnOPwR4ouGF/p36snCvdDVRwCyZrgscm7BjcuANP6J3M0mM9wdE8MNxC5XjCfglxKoFH5NAAytDjt6se3ORaMVDd7uiZlTU7TvfeSBQfWSsneANQddib3zYXIoVaVj2fPxmq2VDKNz9BcjvC4hNnyR4vHDGcx9W203jqidrqto5GsHh/KNfg0a+KfuHRcTPqwXeo500G9DZ8RF7Hd+C9HnNS2+TjYEhKQ== X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(1060300003)(448002)(189002)(199003)(24454002)(50986999)(76176999)(47776003)(77096005)(83506001)(19580405001)(110436001)(2950100001)(81156007)(5007970100001)(69596002)(86362001)(110136002)(97756001)(85326001)(5001960100002)(33656002)(106466001)(4290100001)(87936001)(11100500001)(46406003)(33716001)(54356999)(6806005)(5008740100001)(97736004)(104016004)(92566002)(606003)(23726002)(50466002)(19580395003)(4001350100001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR0301MB1230;H:az84smr01.freescale.net;FPR:;SPF:PermError;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1230;2:qJPY1Q5nFK+2CgVbIG98pQgPZ9ts/WygYbV+kJIyEdFbLg9JzHQ/E9M3uiD9vvH/CRYz+cWQPG2HTAKZ58tcdrEj/uTrM7IvjPBth91LuEWbPTnSf4oVt2pXdysteLSm5zRU3TLGkmHnKLIb7Wx7vWCnWlnK23w1AEMAsw7zWF0=;3:AwoAgSMzQu+qwf+l15b8Mw6gtR+UZNPFEXrphHIcRNzHz4TqV4ssbRZnIy2tZd7fBBl7BZ5G2zEJZL9htF7HYeHGogeMAhntt3ZJABc7OqM7H+CKHzTWyVFVaWhGpR3EjiFLAbWpmNzkiAkMD4xr9FF1TlpJeahkW0tA8fnebTeBYZcf8WMWAv+LkVVMr7liHYunIzDdfOxAZxX/7mnKWv3s9+97zFoRtQH+wW6DxkI=;25:Zy/isB1eXi5t5l6JHMV+EH3psqDJZSidJKQOBZEjA3KqvyXm91UKQ7kL4tiQ12TfbaBum2M/VL2zS2W7tFbrN710qRVQkjPp/54BQi1O5DhU6X6gPC7yR+t0+QLWzAG64Agnn7M94ZfOeDSIigEjbnIGUzjOod+vUxEpfRR9DvgF6+9vDIBT0/VF4mtoq7hLH2tNullJ8ch4pD3b5kLF0aiG70/TeCPoMIcjUCdX7S5igGPdWP4CcSvARjTktMoyQGCt66Pa0d0OjL1AO/YeRg== X-Microsoft-Antispam: UriScan:;BCL:1;PCL:0;RULEID:;SRVR:DM2PR0301MB1230; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1230;20:/0s90oy7pCjkqPlbd1s421x8GXuxbRFNF1LvJvBI1+n8QcmChKjyj2XmyiCz6hJLL8re7vqNr2qo/7L67If/wbZwiJrLoukNZkI0AApn5CdJTnppoPFXvmCGpfOUaQQyg5XWVI51bIHikoNG9O5s6iRzMDvRsZGSuD6GaWy0rUOz5j/YBDJ4c/4SpHveXD4tuANENRzxzPBmpu0FRGdd2t7pZ7KZXL55/KrAwehu4fOL/xyflDLu5sAsjQsj7SdIrnAMa+YTKo4wm9ae4uxzydDpJSkrf6KwOk/Khp3DDguPtqTTmR4t8rNz7VxBcTgro9Qfm9fmF//gSrBTLC8fo+UgWI6SpvRVVmyJwaJY8O4=;4:IVCCaY0FdQys79Xq8xuXCNuNCbHl25et2UllSQJ2HsuplqO4DEBvd5pbVfiiSxthOb5qPT7GUSfD/B7y6JJD/9JcRuF5hz1xkjxudGH8EgG5vU7x84NXn8nP8K4f41LVhdDOwMhNQcsTyXCBgQ19y7145+sNf2Pkc00Xss62KGfHg65/qkCRPloDBlZP4lVIE3rLdelagJPFAcYAprVtb5EyoE+gSCzTZ2Od7X12bsnZRl45QC8zKPSHBZfZ0XTadiP/3zo0n+hU4W69ptz47XX2ilwb+S8flWFoJkFhvW6lvaULM6EYicsJ0R6wimG6BxhGwGT+Iej0fgUIVjIIf6vpksnL8oH3Q+R0t4HfGiVau65fCwmeFzkj2mSwJzhk33eUt6qV4UGQMI15MpPPJA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:1;PCL:0;RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(1201001)(10201501046)(3002001);SRVR:DM2PR0301MB1230;BCL:1;PCL:0;RULEID:;SRVR:DM2PR0301MB1230; X-Forefront-PRVS: 07665BE9D1 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2PR0301MB1230;23:i55lUWifa4gHz57kM38QMBO8PaY0zEsqdRJaHSx?= =?us-ascii?Q?n7KAjlqO8mzedNB5CgNN4WMHo0C00UKJC1aSDrrxejKoxEzqQq6v0bkYf8Jm?= =?us-ascii?Q?jgYef6Duao6Dc0XkRNSiu1C04PDdCSulXwaUYXaliG21t31Z8h3jVUraz72z?= =?us-ascii?Q?7GcZCtnS0XaZVdSKxi+ZMuDqKkdncrN26DDMxsyByrsGirQd2aUF4QdO3nLg?= =?us-ascii?Q?ye1VMH0JSWHyYZ9rYFqWIPm3VeWvJhInv4PcQTDhoyhlEnWv1oqRKy5GCKmM?= =?us-ascii?Q?g/8JMBf5M2bWKhz19nS3u2zlX9YbselYQ8XixKb0RVhM7mmkaLgfUCdYOR00?= =?us-ascii?Q?bdqvn8dLyZfN8iGO9MSogxGsvpTZd5bBjsCj+e6hs2wY27NzCjZi2yb2zdCb?= =?us-ascii?Q?mzawc2WPGNedPICHPWTsTVlaD9WXsSyTr3sx1Sl1uBZ4mImZm0VPIoxm1/k0?= =?us-ascii?Q?oloeI4ulztN+dgLPEj5Bb/MJmdGr4/TgNKGAwU6y5s5xVTurfHfxZIRHdnyt?= =?us-ascii?Q?teH1pKkXTsheVu4/jrtKWdvgAWArRaTHbIb2uulV797V23O5AyEooZe8Dapq?= =?us-ascii?Q?jD+coQvdpS0G5V238JokTXkchEieofbd/nRhZivM1Eh9sKxLFOLF8QUGGngf?= =?us-ascii?Q?0fmm2n1bR6pVjHEfXIHISYPKNTx/m5W6D/pZarhGnE+OV6Z/0bVAneiWUXXr?= =?us-ascii?Q?bW9vkxh0jadsd0I/S2MJf2lBjEAmLFFP93qh8ppnE2yM4dAdwmRlMIEi2Fbe?= =?us-ascii?Q?IwB8zaSAANNx75hCiBDi6WcjRmCs8NdoeISS2/PA6OxtjqIkX1gWUY897qG0?= =?us-ascii?Q?aRxqn4298xznCXWcajYqrr12n4Git/glJfco2N0ltPY3qr5tIg0wPYETJt+8?= =?us-ascii?Q?+uHF37uZCXcOd8a/CCFs8x/U/iId9byN25LcHWlCQQdSKlJhE2yMprfwicid?= =?us-ascii?Q?Wrz4twfboIGOtxt3MuhzysuutXJ1dYktLx3mmxk2sD3XEdsmjLY2ytckBOBE?= =?us-ascii?Q?HgfTDXnYlEanjsF5lrn3eMfdFS/mlrhpDNn8gQu88lS1YAD219ybldVP99qG?= =?us-ascii?Q?kCFwXNsldlHcxU1rPqx8uiq4lhiDZISg/7VUO3kOPoSKAhdQn4A=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1230;5:wRroZEYJWsXeK/WNIpZC7y4/gRHnfD6DQzROZD6C/QADzOlxgSfRIuf7rap+YpLq9klTCcAwCAr2mat3RqSf7FmFVyctxzoFHgr6WdXWGw9E0E+9D2oLWAv9+yerKT0Qn6x+x6QeHBFpvm33NDFLeQ==;24:47I2NVaG6ily9PRXKzRNCYWKxXkc4oXFkS/VAWB6xogr0MtygGMQKl3fLqJkbbmB/VWvgJg7XOh2MH6LN5S/ymi5tJzBvSZLPlSGEw8DYGo=;20:qAc8q6hDdHpRKdLD0ZvgaqHdSHiAe8mV1Ed2AAmF+uuZv5s9lIbfkH17HaeMhulfV6HyJDBXMfK8BZBASzYQ5g== SpamDiagnosticOutput: 1:5 SpamDiagnosticMetadata: 00000000%2D0000%2D0000%2D0000%2D000000000000 SpamDiagnosticMetadata: 1 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2015 09:29:42.6134 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB1230 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5588 Lines: 164 On Fri, Nov 20, 2015 at 09:54:12AM +0100, Marek Szyprowski wrote: > From: Ruslan Bilovol > > Change behavior during registration of gadgets and > gadget drivers in udc-core. Instead of previous > approach when for successful probe of usb gadget driver > at least one usb gadget should be already registered > use another one where gadget drivers and gadgets > can be registered in udc-core independently. > > Independent registration of gadgets and gadget drivers > is useful for built-in into kernel gadget and gadget > driver case - because it's possible that gadget is > really probed only on late_init stage (due to deferred > probe) whereas gadget driver's probe is silently failed > on module_init stage due to no any UDC added. > > Also it is useful for modules case - now there is no > difference what module to insert first: gadget module > or gadget driver one. > > Tested-by: Maxime Ripard > Signed-off-by: Ruslan Bilovol > [simplified code as requested by Alan Stern and Felipe Balbi] > Signed-off-by: Marek Szyprowski > --- > drivers/usb/gadget/udc/udc-core.c | 43 +++++++++++++++++++++++++++++++-------- > include/linux/usb/gadget.h | 2 ++ > 2 files changed, 37 insertions(+), 8 deletions(-) > > diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c > index f76ebc8..461b311 100644 > --- a/drivers/usb/gadget/udc/udc-core.c > +++ b/drivers/usb/gadget/udc/udc-core.c > @@ -51,8 +51,12 @@ struct usb_udc { > > static struct class *udc_class; > static LIST_HEAD(udc_list); > +static LIST_HEAD(gadget_driver_pending_list); > static DEFINE_MUTEX(udc_lock); > > +static int udc_bind_to_driver(struct usb_udc *udc, > + struct usb_gadget_driver *driver); > + > /* ------------------------------------------------------------------------- */ > > #ifdef CONFIG_HAS_DMA > @@ -356,6 +360,7 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, > void (*release)(struct device *dev)) > { > struct usb_udc *udc; > + struct usb_gadget_driver *driver; > int ret = -ENOMEM; > > udc = kzalloc(sizeof(*udc), GFP_KERNEL); > @@ -403,6 +408,18 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, > usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); > udc->vbus = true; > > + /* pick up one of pending gadget drivers */ > + list_for_each_entry(driver, &gadget_driver_pending_list, pending) { > + if (!driver->udc_name || strcmp(driver->udc_name, > + dev_name(&udc->dev)) == 0) { > + ret = udc_bind_to_driver(udc, driver); > + if (ret) > + goto err4; > + list_del(&driver->pending); > + break; > + } > + } > + > mutex_unlock(&udc_lock); > > return 0; > @@ -475,9 +492,16 @@ void usb_del_gadget_udc(struct usb_gadget *gadget) > list_del(&udc->list); > mutex_unlock(&udc_lock); > > - if (udc->driver) > + if (udc->driver) { > + struct usb_gadget_driver *driver = udc->driver; > + > usb_gadget_remove_driver(udc); > > + mutex_lock(&udc_lock); > + list_add(&driver->pending, &gadget_driver_pending_list); > + mutex_unlock(&udc_lock); > + } > + > kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); > flush_work(&gadget->work); > device_unregister(&udc->dev); > @@ -535,11 +559,7 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver) > if (!ret) > break; > } > - if (ret) > - ret = -ENODEV; > - else if (udc->driver) > - ret = -EBUSY; > - else > + if (!ret && !udc->driver) > goto found; > } else { > list_for_each_entry(udc, &udc_list, list) { > @@ -549,9 +569,12 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver) > } > } > > - pr_debug("couldn't find an available UDC\n"); > + list_add_tail(&driver->pending, &gadget_driver_pending_list); > + pr_info("udc-core: couldn't find an available UDC " > + "- added [%s] to list of pending drivers\n", > + driver->function); > mutex_unlock(&udc_lock); > - return ret; > + return 0; > found: > ret = udc_bind_to_driver(udc, driver); > mutex_unlock(&udc_lock); > @@ -577,6 +600,10 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) > break; > } > > + if (ret) { > + list_del(&driver->pending); > + ret = 0; > + } > mutex_unlock(&udc_lock); > return ret; > } > diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h > index e11f5a2..a3436bf 100644 > --- a/include/linux/usb/gadget.h > +++ b/include/linux/usb/gadget.h > @@ -1014,6 +1014,7 @@ static inline int usb_gadget_activate(struct usb_gadget *gadget) > * @driver: Driver model state for this driver. > * @udc_name: A name of UDC this driver should be bound to. If udc_name is NULL, > * this driver will be bound to any available UDC. > + * @pending: UDC core private data used for deferred probe of this driver. > * > * Devices are disabled till a gadget driver successfully bind()s, which > * means the driver will handle setup() requests needed to enumerate (and > @@ -1076,6 +1077,7 @@ struct usb_gadget_driver { > struct device_driver driver; > > char *udc_name; > + struct list_head pending; > }; > > And it seems can't apply for felipe's testing/next which I just rebased on it. -- Best Regards, Peter Chen -- 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/