From patchwork Fri Feb 11 15:18:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuzmichev X-Patchwork-Id: 82772 X-Patchwork-Delegate: linux@bohmer.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 8C675B7162 for ; Sat, 12 Feb 2011 02:25:31 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CE02A28110; Fri, 11 Feb 2011 16:25:06 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YZVVzr5+ADDk; Fri, 11 Feb 2011 16:25:06 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 59BF1280CA; Fri, 11 Feb 2011 16:24:44 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9FA65280BE for ; Fri, 11 Feb 2011 16:24:32 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dvCl8zODh64J for ; Fri, 11 Feb 2011 16:24:32 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-bw0-f44.google.com (mail-bw0-f44.google.com [209.85.214.44]) by theia.denx.de (Postfix) with ESMTPS id 23D8C280C7 for ; Fri, 11 Feb 2011 16:24:29 +0100 (CET) Received: by mail-bw0-f44.google.com with SMTP id 12so3551273bwz.3 for ; Fri, 11 Feb 2011 07:24:29 -0800 (PST) Received: by 10.204.68.9 with SMTP id t9mr11921127bki.173.1297437868874; Fri, 11 Feb 2011 07:24:28 -0800 (PST) Received: from localhost.localdomain (mail.dev.rtsoft.ru [213.79.90.226]) by mx.google.com with ESMTPS id z18sm544843bkf.8.2011.02.11.07.24.28 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 11 Feb 2011 07:24:28 -0800 (PST) From: Vitaly Kuzmichev To: u-boot@lists.denx.de Date: Fri, 11 Feb 2011 18:18:35 +0300 Message-Id: <1297437515-4069-6-git-send-email-vkuzmichev@mvista.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1297437515-4069-1-git-send-email-vkuzmichev@mvista.com> References: <1297437515-4069-1-git-send-email-vkuzmichev@mvista.com> Subject: [U-Boot] [PATCH 5/5] USB-RNDIS: Send RNDIS state on disconnecting X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Add waiting for receiving Ethernet gadget state on the Windows host side before dropping pullup, but keep it for debug. Signed-off-by: Vitaly Kuzmichev --- drivers/usb/gadget/ether.c | 23 +++++++++++++++++++++++ drivers/usb/gadget/rndis.c | 5 +++++ drivers/usb/gadget/rndis.h | 8 ++++++++ 3 files changed, 36 insertions(+), 0 deletions(-) diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index f909267..9fb0e80 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -1921,10 +1921,22 @@ static void eth_start(struct eth_dev *dev, gfp_t gfp_flags) static int eth_stop(struct eth_dev *dev) { +#ifdef RNDIS_COMPLETE_SIGNAL_DISCONNECT + unsigned long ts; + unsigned long timeout = CONFIG_SYS_HZ; /* 1 sec to stop RNDIS */ +#endif + if (rndis_active(dev)) { rndis_set_param_medium(dev->rndis_config, NDIS_MEDIUM_802_3, 0); rndis_signal_disconnect(dev->rndis_config); +#ifdef RNDIS_COMPLETE_SIGNAL_DISCONNECT + /* Wait until host receives OID_GEN_MEDIA_CONNECT_STATUS */ + ts = get_timer(0); + while (get_timer(ts) < timeout) + usb_gadget_handle_interrupts(); +#endif + rndis_uninit(dev->rndis_config); dev->rndis = 0; } @@ -2486,6 +2498,17 @@ void usb_eth_halt(struct eth_device *netdev) if (!dev->gadget) return; + /* + * Some USB controllers may need additional deinitialization here + * before dropping pull-up (also due to hardware issues). + * For example: unhandled interrupt with status stage started may + * bring the controller to fully broken state (until board reset). + * There are some variants to debug and fix such cases: + * 1) In the case of RNDIS connection eth_stop can perform additional + * interrupt handling. See RNDIS_COMPLETE_SIGNAL_DISCONNECT definition. + * 2) 'pullup' callback in your UDC driver can be improved to perform + * this deinitialization. + */ eth_stop(dev); usb_gadget_disconnect(dev->gadget); diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index 3e3f740..886c093 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c @@ -995,7 +995,12 @@ int rndis_signal_disconnect(int configNr) rndis_per_dev_params[configNr].media_state = NDIS_MEDIA_STATE_DISCONNECTED; +#ifdef RNDIS_COMPLETE_SIGNAL_DISCONNECT + return rndis_indicate_status_msg(configNr, + RNDIS_STATUS_MEDIA_DISCONNECT); +#else return 0; +#endif } void rndis_uninit(int configNr) diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h index 73a1204..d9e3a75 100644 --- a/drivers/usb/gadget/rndis.h +++ b/drivers/usb/gadget/rndis.h @@ -17,6 +17,14 @@ #include "ndis.h" +/* + * By default rndis_signal_disconnect does not send status message about + * RNDIS disconnection to USB host (indicated as cable disconnected). + * Define RNDIS_COMPLETE_SIGNAL_DISCONNECT to send it. + * However, this will cause 1 sec delay on Ethernet device halt. + * Usually you do not need to define it. Mostly usable for debugging. + */ + #define RNDIS_MAXIMUM_FRAME_SIZE 1518 #define RNDIS_MAX_TOTAL_SIZE 1558