Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752647AbdHOLg4 (ORCPT ); Tue, 15 Aug 2017 07:36:56 -0400 Received: from mail-db5eur01on0118.outbound.protection.outlook.com ([104.47.2.118]:42336 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752174AbdHOLgw (ORCPT ); Tue, 15 Aug 2017 07:36:52 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; Subject: Re: [PATCH v2 2/3] usb: chipidea: Hook into mux framework to toggle usb switch To: Stephen Boyd , Peter Chen Cc: linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.infradead.org, Rob Herring , Rob Clark , Andy Gross , Greg Kroah-Hartman , devicetree@vger.kernel.org References: <20170714214005.14967-1-stephen.boyd@linaro.org> <20170714214005.14967-3-stephen.boyd@linaro.org> <7080030c-c9c2-657d-aad4-aef636438cb1@axentia.se> <150215709134.18242.599725161375995991@sboyd-linaro> <150249037091.15411.10074988823155268663@sboyd-linaro> From: Peter Rosin Organization: Axentia Technologies AB Message-ID: <8bbd90f2-a80f-1bf7-e5a8-400cebf6dc89@axentia.se> Date: Tue, 15 Aug 2017 13:36:42 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <150249037091.15411.10074988823155268663@sboyd-linaro> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [81.224.168.30] X-ClientProxiedBy: HE1PR0401CA0051.eurprd04.prod.outlook.com (2603:10a6:3:19::19) To AM5PR0202MB2547.eurprd02.prod.outlook.com (2603:10a6:203:6d::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 00042455-891e-4486-2ed3-08d4e3d1ea6b X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(2017082002075)(300000503095)(300135400095)(201703131423075)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:AM5PR0202MB2547; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2547;3:h/hAnXDdfwATSzMfrE+nMn1pj6ZCYjwcqc+ZrSvdC9Q1i7fxeJ0nuvtYe7LdhZuU8lvk2RR9GuZv6Ng9w7oz3VGQZFsi3WnCFzXRT+goxvf2c4Zv9JguZUWpMCR2yyFnv2Azw8/eL35CZcys+rz57eFnnhJn8fbpzXd3U4veOxK+FEdDCqkT5zA8uHnFgsPg2LBEsHRnC6ZUi3fgJ9NfKahbVFPbIKdJkJqu83TdyKMCEFimOptfXMPAESby11/S;25:PLtvqTBtLVwrLUUk9XkNkvSifaVJPXyjICMeOCBU1N52JYdqFTEx5k2msAeRotFCbhXPiMkwWDk9LKfbbUt/WfRyuyfUWdzHT5/sSa2w86CtHFN7+1q77hTGIAF2F4kC/yOjhlCBAwYQooqazvgk4Or6rTucmeXU4oKLHgTrDRAQ1wmrvrT7gg+BVGMfad6q/si80iF4Sm7h2D+3Ha7aZopkmI7AI5XCIrTwkFDxxIrZR1JaSF6lhVNG5BcE03RUStA+v8iCbnwG2HRiMSu+ao/hZreC7ACDyuadf40vPZoZt1S2vy5eOppC9VTuxw6NrkDh4vx6SF5Flyo3/g1Cpg==;31:kI3OXO+6dnfC0Vh25jI8IVlZalze/IFXFBlU3z1iyFTUR6cGHZvl/G1oIzwQDRxnxfqxqR/2ztNdO6VEdU2G+J+IfXYomIHMlsFcsbXa6rTFmOAyL8AeFYvpdbTfjFSa8D7lOpeuTRB42sMznrGaQr56VRJPj3l7ODaSbwST+08ZGOju1296txL34NmZ46YnrmLyA/r9mKDG8UBzyst+W6XHoMhEyoAy8UIQPvjJ4BU= X-MS-TrafficTypeDiagnostic: AM5PR0202MB2547: X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6041248)(20161123560025)(20161123558100)(20161123562025)(20161123555025)(2016111802025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(6072148)(6043046)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:AM5PR0202MB2547;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:AM5PR0202MB2547; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2547;4:Nxj0bGMSoJdwN6FR2t9dFC5OgqHnmFdR58Utz8tYRBF4MHIt7UOS0aQ85BddLvaX/zqtClklcYDwCBA6aUs4sP3fDLJX57aoGBMPQD/48mZLqKxb0+GTS7xEZdA6h1OWWmIorRqUVsTC7WtPVLnmVVUQjwgbfsgPuGDIxUNuO0qXKhj0cObPtXo9lp4TjkE+HjnZAQFM+THSpg7pjWfkjdjXv1FWWl3XKmIl8fTgkgLCs5RzuNiF+DbFb6Hhit8q X-Forefront-PRVS: 04004D94E2 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(7370300001)(4630300001)(6009001)(6049001)(39830400002)(377424004)(189002)(24454002)(199003)(42186005)(189998001)(36756003)(97736004)(2906002)(478600001)(3260700006)(33646002)(25786009)(117156002)(23676002)(230700001)(53546010)(68736007)(53936002)(3846002)(6116002)(31686004)(105586002)(101416001)(106356001)(6246003)(4326008)(54906002)(74482002)(83506001)(6666003)(64126003)(7416002)(65956001)(66066001)(4001350100001)(31696002)(65806001)(65826007)(50466002)(47776003)(2950100002)(5660300001)(305945005)(81166006)(81156014)(76176999)(7736002)(54356999)(6486002)(93886004)(7350300001)(50986999)(8676002)(8656003)(77096006)(86362001)(229853002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM5PR0202MB2547;H:[192.168.13.3];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTTVQUjAyMDJNQjI1NDc7MjM6UFRPWXVqcGU0bGg3RlBFZDh6Qzdtc0Fp?= =?utf-8?B?QndSYStUY0ZwUldJaVk1RElDeWt0b1JRZGdmd2s4SVh3eTF1cWtLbHRzQTU0?= =?utf-8?B?TUo3M3ZWQTkwSHpkaWhHUkRMb1RuaTBRb0R6dnBkQ2pVNXpYNlVBK3ZpTGg0?= =?utf-8?B?Tzd1QmRXaW8wTWZIeS9ZajNldngyUmJnUFNWL1ZYNkJKMlBMZFU0YVo2SXcy?= =?utf-8?B?RWNpcDhzNENPR2pFWUorTkx4NXJOeVZEYlNackdWTVBTL244YjIwcUpCQ1R4?= =?utf-8?B?NVRQUUdvc0hVdVJYMDJMVjFraE8wWjgzY1lqdmNXaGNJL2pseVZCQ2JkVDR1?= =?utf-8?B?MUNPbUxpR1VxMjlidVNHVmgxL3ZEa0JvdmJWZFMycVZPaHM1c3pRQWdOKzRI?= =?utf-8?B?WDlPK0NkdVArVGtCRDloVWtVd0dwQmM0RkxpMUpObHVHZTJTYjlXYnpDRG8r?= =?utf-8?B?S1JsWXd4Tm9zTDJ2YVBpMnVobFdyZ1BvQ05IeU1wdkpEM3JEdXFXcTBiRXN3?= =?utf-8?B?eWpyR20vQjFLNjhvNW5jVFJVNnAyNFIxRVl5TVp5ZVBuVEw0ckFSYkxuZEVC?= =?utf-8?B?M3o1Uk9rQVZzanBCQjZXVUhZeXk5d2UwaURFZld0UmtaWncvTTFBbzlPS0wv?= =?utf-8?B?SFh0QmdoSW5OaTk1bmNETkhwWXRyWGdkQjVnVG53V3kxVmM4cm5Sak1oQVJ3?= =?utf-8?B?Y1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24:aGMuzGeJtHhuIYGs3PFpBlcFXhua5OCDpefwMjcvkTFKh1/7VbVFSe/pZmxhdBg8NCXz0KqUSR9xre/GfN6gBFN2zvMuANsuF3t8uIOvFDw=;7:GRGmPYEy98KuHJdIx6bLl/2qyyIRqFCaqVfgeZ5kQoBHET9/fgSsSlMoAy65FptB/pOT1FYl5ZIElgcVbo0HBgu8kKuaRs8RD3ZKc0+j0iMLTuLUs6+5zW8LPui428iy2r9gOudK1Ww9bp+xfPaQa5U8WzOc5/3H0FWwSSpfX0d3v5H+XSLQuNfU8r9VReOS9hyVL3jW0wUPwVo9HirtEfO6YwI2vA5PcF8X3E+CGqQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2017 11:36:46.7739 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0202MB2547 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3272 Lines: 66 On 2017-08-12 00:26, Stephen Boyd wrote: > Quoting Peter Rosin (2017-08-08 05:46:30) >> On 2017-08-08 03:51, Stephen Boyd wrote: >> >>> It looked like we paired the start/stop ops with >>> each other so that the mux is properly managed across these ops. >> >> Yes, it *looks* ok... >> >>> My >>> testing hasn't shown a problem, but maybe there's some corner case >>> you're thinking of? I'll double check the code. >> >> ...but since I do not know the usb code, I can't tell. What I worry about >> is the usb core calling udc_id_switch_for_host or udc_id_switch_for_device >> more than once without any call to the other in between. Maybe that is a >> guarantee that the usb core makes? Or maybe it isn't? If e.g. there is a >> third mode (or if one is added in the future), then the calls to >> mux_control_select and mux_control_deselect would not be paired correctly. >> Ok, sure, a third mode probably doesn't exist and will probably not be >> added, but but but... >> >> Also, what happens if udc_id_switch_for_device fails? Is it certain that >> it will be called again before udc_id_switch_for_host is called, or is >> the failure simply logged? If the latter, you might have a call to >> mux_control_deselect without a preceding (and successful) call to >> mux_control_select. That's fatal. > > The only thing that could fail right now is the mux selection, so we > wouldn't get into some sort of situation where that's locked in and > unchangeable. We do rollback the role if it fails to switch, so we also > wouldn't go into a half-way state of being in one role but not actually > switching all the way over to it. What do you roll back to if the initial setting of the role fails? Hopefully that causes a probe failure? Cheers, Peter >> I have similar worries for host_start/host_stop, but for that case >> host_stop is not allowed to fail, and it seems like a safe bet that >> host_stop will only be called if host_start succeeds. So, I'm not as >> worried there. >> >> In other words, the question is if the usb core is designed to allow >> this kind of "raw" resource administration in udc_id_switch_for_host and >> udc_id_switch_for_device, or if you need to keep a local record of the >> state so that you do not do double resource acquisition or attempt to >> free resources you don't have? >> >> I think I would feel better if the muxing for the device mode could >> be done in a start/stop pair of function just like the host mode is >> doing. Again, I don't know the usb code and don't know if such hooks >> exist or not? >> > > The host_start/host_stop functions are assigned to the same struct > ci_role_driver ops that udc_idc_switch_for_{device,host} are for the > gadget role. Really, these things are called from the same place by the > chipidea driver so not much is different between the two files I modify > to make the mux calls. Furthermore, we don't want to do this if we have > HNP or "true" OTG support so I've put it behind the ci_otg_is_fsm_mode() > check to make sure we don't do any muxing stuff based on fsm state > changes. It doesn't really make any sense here anyway because this > device I have doesn't support OTG, just role switching.