From: Vitaly Kuzmichev <vkuzmichev@mvista.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] usb_ether: register usb ethernet gadget at each eth init
Date: Tue, 30 Nov 2010 18:13:54 +0300 [thread overview]
Message-ID: <4CF514B2.6010906@mvista.com> (raw)
In-Reply-To: <AANLkTinGx5fw5q6dzkLUXHjPt0GtHTVw_P52DU2ZZM5s@mail.gmail.com>
Hi Lei,
Lei Wen wrote:
> Hi Vitaly,
> [...]
>> And additional calling of usb_gadget_unregister_driver will at most
>> return an error.
>>
>
> For current ether.c state, there is no usb_gadget_unregister_driver in
> it. Even it has, we still need
> usb_gadget_register_driver call in each eth_init().
Yes, if we do 'unregister' we should do 'register' somewhere before. If
we do 'register' we should do 'unregister' somewhere after.
This is the symmetry such like in dynamic data allocation (like
malloc/free), and we should comply it.
The reason why there is no 'usb_gadget_unregister_driver' in the Ether
driver yet is that there is no symmetrical function for
'usb_eth_initialize' because there is no way to remove a network device
from the U-Boot environment.
> [...]
>>> I think the gadget driver should adopt like this to allow two gadget coexist.
>>> And from gadget driver's review, the switch from one gadget to another
>>> is easy, just
>>> register it to another should be enough. Does it really need to return EBUSY?
>>
>> If the UDC (not a gadget) driver does not support more than 1 gadget
>> driver in the same time it must return an error (EBUSY is fine for now)
>> when another gadget tries to register itself.
> Right, if at the same time certainly need to return error.
So your code that expects successful register will make Ether gadget
broken...
> [...]
>> I really do not understand what a problem with using 2 gadgets in the
>> same time without your patch if the UDC driver supports this.
>> Especially I do not understand...
>>
> Sorry, maybe I make a confused saying here. I don't mean to support two gadget
> at the "same time", but to let one gadget could work after another
> gadget is finished.
> Like after tftp, I could use fastboot, or after return from fastboot,
> I could still use the tftp.
...But if you add usb_gadget_unregister_driver in eth_halt (and
additional checking that dev->gadget is not equal to NULL) all existing
UDC drivers (mine and Remy's at91_udc) will be working fine. And your
fastboot will be working too.
> [...]
>> ...how can the gadget (or UDC?) driver be confused here?
> [...]
>>
> The confused thing is for the ether.c would register its gadget at the
> usb_eth_initialize() call,
> which is a very begining of the uboot. If we use some other gadget,
> like fastboot, it would take
> place of gadget registered in the gadget driver.
You probably meant "in the UDC driver"?
Note that USB gadget stack consists of 2 sorts of drivers: gadget and
controller (UDC, USB device controller). The gadget driver provides
hardware independent protocol for talking with host machine. The
controller driver interacts with hardware - USB device chip. The UDC
driver allocates 'struct gadget' (passed in 'usb_gadget_driver.bind'
callback) for each gadget driver which tries to register itself.
However, all existing UDC drivers (both in Linux and U-Boot) are not
able to handle more than 1 gadget driver in the same time. And now I
guess that this impossible. So they all return EBUSY if another gadget
tries to register itself.
This means that if you want 2 gadgets you need to register each one
right before transferring data and unregister right after the data was
transferred. By doing gadget unregister you will free allocated
resources (such as USB endpoints and USB requests) in UDC and Ether
drivers properly. Otherwise you will have memory leaks.
____
Best regards,
Vitaly.
next prev parent reply other threads:[~2010-11-30 15:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-26 3:21 [U-Boot] [PATCH] usb_ether: register usb ethernet gadget at each eth init Lei Wen
2010-11-26 18:23 ` Vitaly Kuzmichev
2010-11-27 14:21 ` Lei Wen
2010-11-29 13:56 ` Vitaly Kuzmichev
2010-11-29 14:06 ` Vitaly Kuzmichev
2010-11-30 2:04 ` Lei Wen
2010-11-30 15:13 ` Vitaly Kuzmichev [this message]
2010-11-30 15:55 ` Lei Wen
2010-11-30 16:41 ` Vitaly Kuzmichev
2010-12-01 15:32 ` Lei Wen
2010-12-01 15:43 ` Lei Wen
2010-12-02 16:34 ` Vitaly Kuzmichev
2010-12-03 2:35 ` Lei Wen
2010-12-09 18:53 ` Remy Bohmer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CF514B2.6010906@mvista.com \
--to=vkuzmichev@mvista.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox