From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DFC0C2BCA1 for ; Fri, 7 Jun 2019 14:04:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E09AB2133D for ; Fri, 7 Jun 2019 14:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729315AbfFGOEJ (ORCPT ); Fri, 7 Jun 2019 10:04:09 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:34740 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1728203AbfFGOEJ (ORCPT ); Fri, 7 Jun 2019 10:04:09 -0400 Received: (qmail 1674 invoked by uid 2102); 7 Jun 2019 10:04:08 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 7 Jun 2019 10:04:08 -0400 Date: Fri, 7 Jun 2019 10:04:08 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Andrey Konovalov cc: Felipe Balbi , USB list , Alexander Potapenko , Dmitry Vyukov Subject: Re: Pass transfer_buffer to gadget drivers In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On Fri, 7 Jun 2019, Andrey Konovalov wrote: > On Fri, Jun 7, 2019 at 2:43 PM Felipe Balbi > wrote: > > > > > > Hi, > > > > Andrey Konovalov writes: > > >> >> Andrey Konovalov writes: > > >> >> > I've noticed that when the host performs a control request, > > >> >> > urb->transfer_buffer/transfer_buffer_length are not passed to the > > >> >> > gadget drivers via the setup() call, the only thing that is passed is > > >> >> > the usb_ctrlrequest struct. Is there a way to get the transfer_buffer > > >> >> > from within a gadget driver? If not, what approach would the best to > > >> >> > implement this? > > >> >> > > >> >> I think you need to further explain what you mean here. > > >> >> > > >> >> What do you mean by gadget driver in this case? > > >> >> > > >> >> If you mean the drivers under drivers/usb/gadget/{function,legacy} > > >> >> directories then there's no way that they can have access to anything > > >> >> from the host. > > >> >> > > >> >> Remember that gadget and host are two completely distinct units. The > > >> >> only thing they share is a USB cable. When it comes to Control > > >> >> Transfers, if a data stage is necessary, that must be encoded in the > > >> >> wLength field of the control structure. > > >> >> > > >> >> Also, host side does *not* pass its usb_ctrlrequest struct to the > > >> >> gadget, it passes a series of 8 bytes which are oblivious to where in > > >> >> memory they were from the host point of view. > > >> >> > > >> >> If if you have the same machine acting as both host and device, each > > >> >> side has no knowledge of that fact. > > >> > > > >> > Hi Felipe, > > >> > > > >> > What I meant is that any module (gadget driver) that implements > > >> > usb_gadget_driver struct callbacks and registers it, will only get > > >> > usb_ctrlrequest through the setup() callback, but not the > > >> > transfer_buffer/length. > > >> > > >> A control request is *always* 8 bytes. That's mandated by the USB > > >> specification. > > >> > > >> > And therefore it can't access the data that is > > >> > attached to a control request. > > >> > > >> There is no data attached to a control request. A Control Transfer is > > >> composed of 2 or 3 stages: > > >> > > >> - SETUP stage > > >> an 8 byte transfer descriptor type thing > > >> > > >> - (optional) Data stage > > >> if wLength of control request contains a value > 0, then this > > >> stage fires up to transfer the amount of data communicated in > > >> wLength (during previous stage). > > >> > > >> - Status Stage > > >> A zero length transfer to communicate successful end of transfer > > >> (in case it completes fine) or an error (in case of STALL > > >> condition). > > > > > > Hm, then why does the usb_control_msg() function accepts a data and > > > size arguments? Which are described in the comment as "pointer to the > > > data to send" and "length in bytes of the data to send" accordingly? > > > Or is this the buffer for the response? > > > > That's for the data stage :-) > > Sure =) > > > > > usb_control_msg() is an upper lever API to encode and entire Control > > Transfer (all stages of it). > > > > What is the problem you see, then? > > The problem is that I want to receive that data (from the data stage) > from within my gadget driver module. But it's not passed to the > setup() callback. And the question is: how do I do that then? I just caught up on this thread... The answer is simple: The gadget driver's setup() callback routine submits a request for endpoint 0. The Data Stage data is sent or received (depending on the direction encoded in the Setup information) by this request. Alan Stern