public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
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 19:41:46 +0300	[thread overview]
Message-ID: <4CF5294A.8000705@mvista.com> (raw)
In-Reply-To: <AANLkTin9mRc000Dka66zXCnTLE661JSztddf3-HAv_mk@mail.gmail.com>

Hi Lei,

Lei Wen wrote:
> [...]
>>> 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.
>>
> What we need to do is not trying to remove the network device, but to register
> another gadget when we want to switch from tftp to fastboot, and make UDC take
> a different protocol to communicate with host.

I have not asked you to remove network device, I have talked about the
reason for the following:
> For current ether.c state, there is no usb_gadget_unregister_driver in
> it.

> [...]
>>> Right, if at the same time certainly need to return error.
>>
>> So your code that expects successful register will make Ether gadget
>> broken...
> 
> Don't understand here, why the Ether gadget would be broken?

Because UDC driver does not allow to register more than 1 gadget driver
in the same time. It just returns EBUSY. Even if the first gadget driver
is idle (when Ether gadget driver is registered but tftp command is not
issued). This is done to protect against memory leaks.
Just checkout  cdc-at91  branch in  u-boot-usb.git  for example of UDC
driver (drivers/usb/gadget/at91_udc.c). Or look at any UDC driver in
linux kernel.


> [...]
>> 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.
> 
> Sure, so we comes into a conclusion that add register call in the
> eth_init and unregister call
> in eth_halt? In unregister call, the UDC driver should free the ep as you said.

Yes, it will free by 'eth_unbind' called from
'usb_gadget_unregister_driver'.

Note that 'usb_gadget_register_driver' should be removed from
'usb_eth_initialize' and dev->gadget checking should be added in eth_halt.

> 
> Best regards,
> Lei

Best regards,
Vitaly.

  reply	other threads:[~2010-11-30 16:41 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
2010-11-30 15:55           ` Lei Wen
2010-11-30 16:41             ` Vitaly Kuzmichev [this message]
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=4CF5294A.8000705@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