From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752564AbbKQGjy (ORCPT ); Tue, 17 Nov 2015 01:39:54 -0500 Received: from mga03.intel.com ([134.134.136.65]:47411 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751918AbbKQGjv (ORCPT ); Tue, 17 Nov 2015 01:39:51 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,306,1444719600"; d="scan'208";a="601616829" From: Lu Baolu To: Mathias Nyman , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v4 08/12] usb: xhci: dbc: handle endpoint stall Date: Tue, 17 Nov 2015 14:38:54 +0800 Message-Id: <1447742338-8381-9-git-send-email-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1447742338-8381-1-git-send-email-baolu.lu@linux.intel.com> References: <1447742338-8381-1-git-send-email-baolu.lu@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case of endpoint stall, software is able to detect the situation by reading DCCTRL.HIT or DCCTRL.HOT bits. DbC follows the normal USB framework to handle endpoint stall. When software detects endpoint stall situation, it should wait until endpoint is recovered before read or write oprations. Signed-off-by: Lu Baolu --- drivers/usb/early/xhci-dbc.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c index 8a5a51f..aaf655f 100644 --- a/drivers/usb/early/xhci-dbc.c +++ b/drivers/usb/early/xhci-dbc.c @@ -1176,6 +1176,37 @@ static int xdbc_wait_until_dbc_configured(void) return -ETIMEDOUT; } +static int xdbc_wait_until_epstall_cleared(bool read) +{ + int timeout = 0; + + if (read) { + do { + if (!(readl(&xdbcp->xdbc_reg->control) & CTRL_HIT)) { + xdbcp->in_ep_state = EP_RUNNING; + + return 0; + } + + xdbcp->in_ep_state = EP_HALTED; + xdbc_udelay(10); + } while (timeout++ < XDBC_LOOPS); + } else { + do { + if (!(readl(&xdbcp->xdbc_reg->control) & CTRL_HOT)) { + xdbcp->out_ep_state = EP_RUNNING; + + return 0; + } + + xdbcp->out_ep_state = EP_HALTED; + xdbc_udelay(10); + } while (timeout++ < XDBC_LOOPS); + } + + return -ETIMEDOUT; +} + static int xdbc_bulk_transfer(void *data, int size, int loops, bool read) { u64 addr; @@ -1195,6 +1226,11 @@ static int xdbc_bulk_transfer(void *data, int size, int loops, bool read) return -EPERM; } + if (xdbc_wait_until_epstall_cleared(read)) { + xdbc_trace("%s: endpoint not ready\n", __func__); + return -EPERM; + } + ring = (read ? &xdbcp->in_ring : &xdbcp->out_ring); trb = ring->enqueue; cycle = ring->cycle_state; -- 2.1.4