From patchwork Thu Jul 22 18:38:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1508840 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=secospa.onmicrosoft.com header.i=@secospa.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-secospa-onmicrosoft-com header.b=pApJHCFR; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GW1T14sxSz9sRR for ; Fri, 23 Jul 2021 04:39:33 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BA59482BDF; Thu, 22 Jul 2021 20:39:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=secospa.onmicrosoft.com header.i=@secospa.onmicrosoft.com header.b="pApJHCFR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8F63C82C61; Thu, 22 Jul 2021 20:39:23 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-ve1eur02on0603.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe06::603]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 22EE182BDF for ; Thu, 22 Jul 2021 20:39:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sean.anderson@seco.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VaI1u+Nd+gbuFi6SDBufmUKp8LyP78Qq6M6xeIkN1sj48Bi451kcjZuuYluikuAAc6ZX7yQ0EJ7Vj7sTd9F80spb9WFE7CHwASXRmsAoeiWmZ4OohtooG5PSd6xrZxO8kdLktaNcorhzUgW0mGbjg5n3Aoqp4f/WdGO4QcL4FKuAk1JVzG8hf299TtlM9xfC5rhH4TsWB2g4eWXyz3JY4XxhYWxZ8t9s6kJa/Ec/yXzzLIQ2LcnYuUfd5nIMtlPJXZiINN96k3uRyygYqfxjaYSmyYo2yxAqdyk8IlMqIadPr6BLhgJjU1/tNA1nudWiGvQyGNTwbmzhX3JubYA4/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xh32uOKR8MJmPq/1XwQ7x1cllhARkg9pJo2LC1yryNg=; b=FOlD5FPOvsTMtM2adANJgjMPgJDtD+nxOdxlfA/B63rxI1qmY8+77kXJJ2r3BsiyZK76mw5TtOr2YfLPcx7jDOr2UPrX06GjaQszKscnbX8YIEMh7GlvD8x8SmgND0PvPUqCuPx+PaR98INwqObLqbgGr1nJnb9Isma1uWg2GcAuDlD4S/L3N6zNyHqRcuur9MNKVviN5wXNBr3DX6GmIdZu5zEnDwH/Xj0m3Wya1hcOfL/FXruuVY7cIitMHBheBPHvaIyy/UhDON2HOIGPKyIAOPgHh7sS0WFzomZCTnEnXpwbzsqvvmBwZddRSYyLFs5eII6V9I2r2BWzFWFA9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secospa.onmicrosoft.com; s=selector2-secospa-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xh32uOKR8MJmPq/1XwQ7x1cllhARkg9pJo2LC1yryNg=; b=pApJHCFRNEalLaTTeu3TTJN28vsQK0jvtHyUVK854wlN/pHemqtd0FGXeb/1BsiuWyeQQ8IYmIPkMgVbL6oXYnAwl3huQaa6kA0f1n4oFj3wSm4NgBQrG5h184BYgMNwm4zvbMcuEWTndvh7PqQ3PMJ2rEbqDZfvKJjIFLh/o64= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) by DB7PR03MB4619.eurprd03.prod.outlook.com (2603:10a6:10:14::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.24; Thu, 22 Jul 2021 18:39:17 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::dc6c:815b:2062:d1f1]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::dc6c:815b:2062:d1f1%7]) with mapi id 15.20.4352.025; Thu, 22 Jul 2021 18:39:17 +0000 From: Sean Anderson To: u-boot@lists.denx.de, Lukasz Majewski Cc: Andre Przywara , Marek Szyprowski , Peng Fan , Bryan O'Donoghue , Marek Vasut , Jun Li , Maxime Ripard , Ye Li , Jagan Teki , Sean Anderson Subject: [PATCH v2 1/3] usb: f_mass_storage: Check bh->state in sleep_thread Date: Thu, 22 Jul 2021 14:38:08 -0400 Message-Id: <20210722183811.76441-1-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: MN2PR01CA0047.prod.exchangelabs.com (2603:10b6:208:23f::16) To DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from plantagenet.inhand.com (50.195.82.171) by MN2PR01CA0047.prod.exchangelabs.com (2603:10b6:208:23f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.26 via Frontend Transport; Thu, 22 Jul 2021 18:39:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd22e0be-1a8d-4cd9-dd5a-08d94d4002c5 X-MS-TrafficTypeDiagnostic: DB7PR03MB4619: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:291; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8XyK8et5z1yJgpWhowrwxjd9wZMIdTK5RmUsyVKbfnZQMwh9QL7GYlcDFldH6EJJcU1LK3TQFl71A3RYqkGBrkTha3uvmZRD8aP4eMU1TSIXCkVI4ncq/wPbN6dLnftLJGk6o6bIqazd8PYV+F4ben2PU9Tt/e9QmfLWiZMe0fjgYMIiCMlv7wCmD1XYNkhnY4qyg/8hFjFHcjP78tSYBBFIDFZcZR3gO0XBTJTh9Wm6S+WIHeqg6aKvkHq25KB9WqcClzpdbd5WnaCNrdom2rfroItFkAF0VAGPnTSDFsxBBrHOs8702nSS1ewwrIhTEmRC+2Bpj1ZgaJjNNldAIZiB3Zbb/PTeaOO4J6zujX04bIvjjyjzDKpDUY//q3s3SXc8ImRX9OJJGgINlxPX4MU3n+3Xgb8FOA8Qm7Yw5GJfoc/FCHNQQKLeAy63YdP+kPpbFAnt+MvSPC71iMEDPkzuIgr81c3SuY1a059uo67mS2o7ksqwPQ+M2890YHw6YHsssBGgTsw55e1p4N1BIt6va0fOl9+VuJDMw/UqyywgBLIvGVZuH62ahJ8hLLte416NcV6fmigbCwKIU1hb0vrp59Rd267+6C7v3hEMzmM6IBk59Lfer9surP5neWat4CXoRKMqVcGYLZhknzA+NUstr/PPX5eg63S/7zyq0DlQbs8+OZLleepodr4hVUfq4teXpNtITLJsP3n/MvlozA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4523.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(136003)(346002)(396003)(376002)(39830400003)(366004)(107886003)(2616005)(316002)(6506007)(66476007)(66946007)(86362001)(956004)(66556008)(478600001)(44832011)(83380400001)(186003)(26005)(52116002)(6486002)(38350700002)(8676002)(38100700002)(8936002)(6666004)(4326008)(5660300002)(30864003)(6512007)(7416002)(54906003)(2906002)(36756003)(1076003)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ANAD/mEN/908BNa67g6aAAnNOniR2/T/D4NKE7RcaBu33uVVGefWJWmPgKXfFV2wx1/G9obZPmm9HNVYHpr9srLmeSq5mro6uPaffDHsunEkeLM1+q3YBJferHCucaytQyLzC3Ga+X2AT1w9LaqFjuU2wKW+UlbATjWyPimwhTCOI6BxoG8L9ukK4WvJ+h4BU1jvQ5D5CscO/GOs1tGTnCwGjflSuBNmAoWdfXMvXRw4CeIjeV2OnFt0iymUCuZziUjM4105GpCBd5QnYC9N7Dz7/mhrBslxpCIaR1xRrpM1O8Ry8VcCI2lLiI1oHfug7VElMuCgOCLj9/MUbT5xFfBli7idF6OwvOdiU2FCD6c+Z+diT5108DZIeRs9eMJz6aQ4Irw4cwJrA77ZQcCTx2KyFn9LTeJIhcO4+w4K/RiGt/lsWKGDwOfP+uMJsy9x8hVJLGyx8lyDZ8TJ1nFwyDzFKCyY3o9Cq/8jI/f2DpGidDDhBC1XHSq6nrauvN4rE4ntKuQn2SCPwPfrWkGvIZqP6N1iW14nqDzBG64ajOmsUcfSqWSwtTJ7OkwQ6BmXs4ZC9m5ANwQiQsxj0jZ5U9qRZgQllA2ibVtlrhzjr6LM4P2LUI+Z99/mqGSBtwBvfZ5CKpwOJx+GkJA8sVeN+6B2HWuMn7obQMjOqyjB67Y3lMNTFNzZXeaZmr7oxzvDRsgrSzlnrs2vCKXxiDkx+0jpqduwNtdxsKcwSZkgeRXldFp8kGXz/LbxxM0V5sokxa64QNVEiBya4UBnlXpyLsY3J1fcL9D2Y4nhBC5TdzxMv5dadKT2b/6M75mfpxYDmLL0pVDQOrgKJBJ/1knNR3xZcMMV6415FTMj+3spmU3iE/EL8bO81HIUI8pUJqwhJjY/StDTRk0K1STgOxO+u5C6yYXqCtwC5Cjp5dDoD2hjsqyj2KPE6UcWUQlK0hloWeVEku1guxf6HtZ+NNeRNDVbFxN/XkBGTeLIrdObVnIRDD7sswWM83wP61W/wruuVpfn2Pb4BU7TmPmCxgkk3zCAdA7+K0+phmdOdoLHwp29VhmxXxuugbXFulevG3nDpiAmMuv3kZ94+tnODR9ZDacr4l/38l500MS0ZsTKB+srGAJzD9x9x/APZnWdDq+YWIORQiK387Z8X+5uJ5rBSp3Wx9z26bf0hMHN7AjPJo4t5VjXI+moA3yo+EB0i88yU1QONBOtiELX9SBnywqSLtnsmQBJvMdgv3JF3mYBDAOjhHW+RyLHmDJFusp6ZMyAK5AeJl+8ZLmna9uJ6LG/pYHuCk8xCmjD9tCeA/YnF2mBZk4DDYT8msIo8Ag3AMOD X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd22e0be-1a8d-4cd9-dd5a-08d94d4002c5 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2021 18:39:17.0622 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: w0atc8DoVmHYfwlUTv5k3CnHZ1tbW9P6N6bgTN8z5JEDmJmpUWhPZzLMRBES1RiRav8vV0f7cX0Lv89VAl0YBA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR03MB4619 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Every caller of sleep_thread except one wraps it in a second loop which waits for a buffer head to be filled. Since sleep_thread is already (infinitely) looping, we can move this check down. Some parts of the code have been reorganized to better take advantage of this property and and be structured closer to their Linux counterparts. In addition, sleep_thread now returns -EINTR if we need to wake up, mirroring Linux. This takes advantage of the existing logic regarding sleep_thread, which typically returns immediately on error. With this change, any exception causes the current operation to be backed out of immediately. Lastly, we only clear thread_wakeup_needed in handle_exception, mirroring Linux's signal-handling logic. Any subsequent calls to sleep_thread will still wake up. While these changes are conceptually different, their implementation is interdependent, so they are all performed at once. These changes are primarily inspired by Linux commit 225785aec726 ("USB: f_mass_storage: improve memory barriers and synchronization"). Signed-off-by: Sean Anderson --- Changes in v2: - Fix some checkpatch lint - Make comment for sleep thread match loop condition drivers/usb/gadget/f_mass_storage.c | 228 ++++++++++++---------------- drivers/usb/gadget/storage_common.c | 2 +- 2 files changed, 101 insertions(+), 129 deletions(-) diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 45f0504b6e..6f39c24503 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -652,15 +652,17 @@ static void busy_indicator(void) state = 0; } -static int sleep_thread(struct fsg_common *common) +static int sleep_thread(struct fsg_common *common, struct fsg_buffhd *bh) { - int rc = 0; int i = 0, k = 0; - /* Wait until a signal arrives or we are woken up */ - for (;;) { - if (common->thread_wakeup_needed) - break; + /* + * Wait until a signal arrives, we are woken up, or the buffer is no + * longer busy. + */ + while (!bh || bh->state == BUF_STATE_BUSY) { + if (exception_in_progress(common)) + return -EINTR; if (++i == 20000) { busy_indicator(); @@ -682,8 +684,7 @@ static int sleep_thread(struct fsg_common *common) usb_gadget_handle_interrupts(controller_index); } - common->thread_wakeup_needed = 0; - return rc; + return 0; } /*-------------------------------------------------------------------------*/ @@ -744,11 +745,9 @@ static int do_read(struct fsg_common *common) /* Wait for the next buffer to become available */ bh = common->next_buffhd_to_fill; - while (bh->state != BUF_STATE_EMPTY) { - rc = sleep_thread(common); - if (rc) - return rc; - } + rc = sleep_thread(common, bh); + if (rc) + return rc; /* If we were asked to read past the end of file, * end with an empty buffer. */ @@ -922,67 +921,63 @@ static int do_write(struct fsg_common *common) bh = common->next_buffhd_to_drain; if (bh->state == BUF_STATE_EMPTY && !get_some_more) break; /* We stopped early */ - if (bh->state == BUF_STATE_FULL) { - common->next_buffhd_to_drain = bh->next; - bh->state = BUF_STATE_EMPTY; - /* Did something go wrong with the transfer? */ - if (bh->outreq->status != 0) { - curlun->sense_data = SS_COMMUNICATION_FAILURE; - curlun->info_valid = 1; - break; - } + rc = sleep_thread(common, bh); + if (rc) + return rc; - amount = bh->outreq->actual; + common->next_buffhd_to_drain = bh->next; + bh->state = BUF_STATE_EMPTY; - /* Perform the write */ - rc = ums[common->lun].write_sector(&ums[common->lun], - file_offset / SECTOR_SIZE, - amount / SECTOR_SIZE, - (char __user *)bh->buf); - if (!rc) - return -EIO; - nwritten = rc * SECTOR_SIZE; - - VLDBG(curlun, "file write %u @ %llu -> %d\n", amount, - (unsigned long long) file_offset, - (int) nwritten); - - if (nwritten < 0) { - LDBG(curlun, "error in file write: %d\n", - (int) nwritten); - nwritten = 0; - } else if (nwritten < amount) { - LDBG(curlun, "partial file write: %d/%u\n", - (int) nwritten, amount); - nwritten -= (nwritten & 511); - /* Round down to a block */ - } - file_offset += nwritten; - amount_left_to_write -= nwritten; - common->residue -= nwritten; - - /* If an error occurred, report it and its position */ - if (nwritten < amount) { - printf("nwritten:%zd amount:%u\n", nwritten, - amount); - curlun->sense_data = SS_WRITE_ERROR; - curlun->info_valid = 1; - break; - } + /* Did something go wrong with the transfer? */ + if (bh->outreq->status != 0) { + curlun->sense_data = SS_COMMUNICATION_FAILURE; + curlun->info_valid = 1; + break; + } - /* Did the host decide to stop early? */ - if (bh->outreq->actual != bh->outreq->length) { - common->short_packet_received = 1; - break; - } - continue; + amount = bh->outreq->actual; + + /* Perform the write */ + rc = ums[common->lun].write_sector(&ums[common->lun], + file_offset / SECTOR_SIZE, + amount / SECTOR_SIZE, + (char __user *)bh->buf); + if (!rc) + return -EIO; + nwritten = rc * SECTOR_SIZE; + + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount, + (unsigned long long)file_offset, (int)nwritten); + + if (nwritten < 0) { + LDBG(curlun, "error in file write: %d\n", + (int)nwritten); + nwritten = 0; + } else if (nwritten < amount) { + LDBG(curlun, "partial file write: %d/%u\n", + (int)nwritten, amount); + nwritten -= (nwritten & 511); + /* Round down to a block */ } + file_offset += nwritten; + amount_left_to_write -= nwritten; + common->residue -= nwritten; - /* Wait for something to happen */ - rc = sleep_thread(common); - if (rc) - return rc; + /* If an error occurred, report it and its position */ + if (nwritten < amount) { + printf("nwritten:%zd amount:%u\n", nwritten, + amount); + curlun->sense_data = SS_WRITE_ERROR; + curlun->info_valid = 1; + break; + } + + /* Did the host decide to stop early? */ + if (bh->outreq->actual != bh->outreq->length) { + common->short_packet_received = 1; + break; + } } return -EIO; /* No default reply */ @@ -1430,13 +1425,10 @@ static int pad_with_zeros(struct fsg_dev *fsg) bh->state = BUF_STATE_EMPTY; /* For the first iteration */ fsg->common->usb_amount_left = nkeep + fsg->common->residue; while (fsg->common->usb_amount_left > 0) { - /* Wait for the next buffer to be free */ - while (bh->state != BUF_STATE_EMPTY) { - rc = sleep_thread(fsg->common); - if (rc) - return rc; - } + rc = sleep_thread(fsg->common, bh); + if (rc) + return rc; nsend = min(fsg->common->usb_amount_left, FSG_BUFLEN); memset(bh->buf + nkeep, 0, nsend - nkeep); @@ -1461,23 +1453,7 @@ static int throw_away_data(struct fsg_common *common) bh->state != BUF_STATE_EMPTY || common->usb_amount_left > 0; bh = common->next_buffhd_to_drain) { - /* Throw away the data in a filled buffer */ - if (bh->state == BUF_STATE_FULL) { - bh->state = BUF_STATE_EMPTY; - common->next_buffhd_to_drain = bh->next; - - /* A short packet or an error ends everything */ - if (bh->outreq->actual != bh->outreq->length || - bh->outreq->status != 0) { - raise_exception(common, - FSG_STATE_ABORT_BULK_OUT); - return -EINTR; - } - continue; - } - /* Try to submit another request if we need one */ - bh = common->next_buffhd_to_fill; if (bh->state == BUF_STATE_EMPTY && common->usb_amount_left > 0) { amount = min(common->usb_amount_left, FSG_BUFLEN); @@ -1494,13 +1470,24 @@ static int throw_away_data(struct fsg_common *common) return -EIO; common->next_buffhd_to_fill = bh->next; common->usb_amount_left -= amount; - continue; } - /* Otherwise wait for something to happen */ - rc = sleep_thread(common); + /* Wait for the data to be received */ + rc = sleep_thread(common, bh); if (rc) return rc; + + /* Throw away the data in a filled buffer */ + bh->state = BUF_STATE_EMPTY; + common->next_buffhd_to_drain = bh->next; + + /* A short packet or an error ends everything */ + if (bh->outreq->actual != bh->outreq->length || + bh->outreq->status != 0) { + raise_exception(common, + FSG_STATE_ABORT_BULK_OUT); + return -EINTR; + } } return 0; } @@ -1613,11 +1600,9 @@ static int send_status(struct fsg_common *common) /* Wait for the next buffer to become available */ bh = common->next_buffhd_to_fill; - while (bh->state != BUF_STATE_EMPTY) { - rc = sleep_thread(common); - if (rc) - return rc; - } + rc = sleep_thread(common, bh); + if (rc) + return rc; if (curlun) sd = curlun->sense_data; @@ -1790,11 +1775,9 @@ static int do_scsi_command(struct fsg_common *common) /* Wait for the next buffer to become available for data or status */ bh = common->next_buffhd_to_fill; common->next_buffhd_to_drain = bh; - while (bh->state != BUF_STATE_EMPTY) { - rc = sleep_thread(common); - if (rc) - return rc; - } + rc = sleep_thread(common, bh); + if (rc) + return rc; common->phase_error = 0; common->short_packet_received = 0; @@ -2118,11 +2101,9 @@ static int get_next_command(struct fsg_common *common) /* Wait for the next buffer to become available */ bh = common->next_buffhd_to_fill; - while (bh->state != BUF_STATE_EMPTY) { - rc = sleep_thread(common); - if (rc) - return rc; - } + rc = sleep_thread(common, bh); + if (rc) + return rc; /* Queue a request to read a Bulk-only CBW */ set_bulk_out_req_length(common, bh, USB_BULK_CB_WRAP_LEN); @@ -2137,11 +2118,9 @@ static int get_next_command(struct fsg_common *common) * next_buffhd_to_fill. */ /* Wait for the CBW to arrive */ - while (bh->state != BUF_STATE_FULL) { - rc = sleep_thread(common); - if (rc) - return rc; - } + rc = sleep_thread(common, bh); + if (rc) + return rc; rc = fsg_is_set(common) ? received_cbw(common->fsg, bh) : -EIO; bh->state = BUF_STATE_EMPTY; @@ -2291,6 +2270,7 @@ static void handle_exception(struct fsg_common *common) struct fsg_lun *curlun; unsigned int exception_req_tag; + common->thread_wakeup_needed = 0; /* Cancel all the pending transfers */ if (common->fsg) { for (i = 0; i < FSG_NUM_BUFFERS; ++i) { @@ -2300,18 +2280,9 @@ static void handle_exception(struct fsg_common *common) if (bh->outreq_busy) usb_ep_dequeue(common->fsg->bulk_out, bh->outreq); - } - /* Wait until everything is idle */ - for (;;) { - int num_active = 0; - for (i = 0; i < FSG_NUM_BUFFERS; ++i) { - bh = &common->buffhds[i]; - num_active += bh->inreq_busy + bh->outreq_busy; - } - if (num_active == 0) - break; - if (sleep_thread(common)) + /* Wait until the transfer is idle */ + if (sleep_thread(common, bh)) return; } @@ -2403,15 +2374,16 @@ int fsg_main_thread(void *common_) } if (!common->running) { - ret = sleep_thread(common); - if (ret) + ret = sleep_thread(common, NULL); + if (ret != -EINTR) return ret; - continue; } ret = get_next_command(common); - if (ret) + if (ret == -EINTR) + continue; + else if (ret) return ret; if (!exception_in_progress(common)) diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index 5674e8fe49..723549ef09 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c @@ -318,7 +318,7 @@ static struct fsg_lun *fsg_lun_from_dev(struct device *dev) enum fsg_buffer_state { BUF_STATE_EMPTY = 0, BUF_STATE_FULL, - BUF_STATE_BUSY + BUF_STATE_BUSY, }; struct fsg_buffhd { From patchwork Thu Jul 22 18:38:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1508841 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=secospa.onmicrosoft.com header.i=@secospa.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-secospa-onmicrosoft-com header.b=kbQ/IRgP; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GW1TG5sJtz9sT6 for ; Fri, 23 Jul 2021 04:39:46 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 759A182C5E; Thu, 22 Jul 2021 20:39:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=secospa.onmicrosoft.com header.i=@secospa.onmicrosoft.com header.b="kbQ/IRgP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A289682C68; Thu, 22 Jul 2021 20:39:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-ve1eur02on061e.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe06::61e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 271FF82C49 for ; Thu, 22 Jul 2021 20:39:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sean.anderson@seco.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kk3rC+GuDjycC9KbAXrNL/e+unKvSqPLX3Wn5eW2jq9dAjz8OLbI8CE2KZQdCDH6FAHDE5MJbEBH2xH0Xy86foxvHmsnGSv6TuXUafZLCldaBNqaBpFjgE9iMOmNbmSoulU0xoCPIWhDSscUCLg+MPLWHuvlvNLiydgE1g0pUuEyUh4pTWgTKBjnSEFkbtOcBk0nw57MnWDh0I3v2766zImi8Rg6l9bdFpIYLLiCx6s3XjpfhY5cpMFHUdDkVujk+qT3YHYom2pKiZyrvXxpqja357Xf0EPkmARaPmjFwRK3+OfFvKnghnLb1O0cGx5VzjN5ycYlbOnEqQFpk3P5fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FelDLeSt7q2el1Yi4XkDpJ+qAE3lccAuVnlw4FcpUWg=; b=kBwugEj/vCTgCkGZoWQ8hfYShZVp5hzUcmCW1EkGAYdX/Dfx9LY4sMtX2GbKQglOp9KqpmQjXAhfg3eZZmj77rvBYKB2T496TcrIZaXsGWRb6BkodhkoYwd5XZWCa90xIfSydyg4HITiFb7tGjxCVDSnSDoZX0oI2MgmmkuJuV8xn4PsSGQox8x4x8WwY7FL0ZtHzFdt25gF3xccPOjkWEBrfWKBVkOsOofi/aL6U+zQ6LsOydGPxfQl1eJ0/MRfA1omIlSEiO/R+9/LfKAqhCHSqOW/wtBXLWRKmP5KXE6kyr2dmAzwU8mFC85Vne4PYNUFy8afjx0wXIGYYXQo9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secospa.onmicrosoft.com; s=selector2-secospa-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FelDLeSt7q2el1Yi4XkDpJ+qAE3lccAuVnlw4FcpUWg=; b=kbQ/IRgPCu3Ufs6NZ7AISXejf2NeHc3OlwmryKwDR5D2GKVDhTBfcd7fiD5gT7fhcrS8Qg+91k+ZHSrBv5ePTXPhHE6zfPQcETinrPhh0KArcB34i4ifhCLRrGr84qThHrP0xXAtWn2d2mKYzpdgj25Oz5A9MfLxns0L1P4Qzj8= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) by DB7PR03MB4619.eurprd03.prod.outlook.com (2603:10a6:10:14::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.24; Thu, 22 Jul 2021 18:39:18 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::dc6c:815b:2062:d1f1]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::dc6c:815b:2062:d1f1%7]) with mapi id 15.20.4352.025; Thu, 22 Jul 2021 18:39:19 +0000 From: Sean Anderson To: u-boot@lists.denx.de, Lukasz Majewski Cc: Andre Przywara , Marek Szyprowski , Peng Fan , Bryan O'Donoghue , Marek Vasut , Jun Li , Maxime Ripard , Ye Li , Jagan Teki , Sean Anderson Subject: [PATCH v2 2/3] usb: f_mass_storage: Drop wakeup_needed Date: Thu, 22 Jul 2021 14:38:09 -0400 Message-Id: <20210722183811.76441-2-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210722183811.76441-1-sean.anderson@seco.com> References: <20210722183811.76441-1-sean.anderson@seco.com> X-ClientProxiedBy: MN2PR01CA0047.prod.exchangelabs.com (2603:10b6:208:23f::16) To DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from plantagenet.inhand.com (50.195.82.171) by MN2PR01CA0047.prod.exchangelabs.com (2603:10b6:208:23f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.26 via Frontend Transport; Thu, 22 Jul 2021 18:39:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: edd06efd-c686-47b3-7068-08d94d4003e4 X-MS-TrafficTypeDiagnostic: DB7PR03MB4619: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zvNNHkwtajBxml8fcIJNuzd0eDE0bSgMuhGBOx6TzOQg2ldQuPIBGmJFaa3m08RVY/lKQ8GgjzXKZwatXLkrBval5hfLbZ0B76vrTEfo1wjyPIbP5wN9diFugd76U+z06jqNdApXwP7B/f1oxPyIPD0BThx+2UzUjJCY2qD8QXJFQNYZF4IQPtuvd2qnb/pwXrmctXDVV7mu7uXEN3JsvACA/T0IvpdqhJSNm9spzvCSGjjwRW+ZUYEgT6NNBW6xKKj+cCkhjc/nmTmrfB1q5GLDPzNjFerNReY6T94qSz9DUm2hWmpNHBQ/qcx/Xjik7ccNqzc+PRNwg2yLNhtd+osZ9xB8F6IF7fwi7GPb/TJ+vIHQ70cbPQHpgELBsi2WrCeqHuKqEfYXeQy8FB/j8hUcKVnNo74mnLMsaiLPKv6TG7/YUw+zFzhGiNeHpv+FY+ltK7qYizVfF1VBTc9Pnu0EBdQkaYCok+R8mnT9n4Obey+/THf0GwW54S1/s56P92kzBJZ9IM4vlCiysxM4F/0gsQ36ZJUxOEzrfGVBd61e7w99esY/sKei8AX+A78W6rqHEPsVkPzetlflyzKzsIENVsQD7Ulf6f5cgPvK3YVuX+ES/01iFos1+1y6FQV0BNCsrucH3wq8fGsHE/NC3f/nUfzrVBguhV6xJXBrwYEqqcAy/r49LIcpXLUn+yhb08eGhutp4/H3Jcqe4WFHsQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4523.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(136003)(346002)(396003)(376002)(39830400003)(366004)(107886003)(2616005)(316002)(6506007)(66476007)(66946007)(86362001)(956004)(66556008)(478600001)(44832011)(83380400001)(186003)(26005)(52116002)(6486002)(38350700002)(8676002)(38100700002)(8936002)(6666004)(4326008)(5660300002)(6512007)(7416002)(54906003)(2906002)(36756003)(1076003)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UJIMMB9aLhHuAab2Jt75XoUMa3F0PuTc+AbXEmqn64sniAATSEE/MTzRnk8oM13DLvfOWfsY7EavN6g9ZYUDN6r3WyZwrxobKE5LrAD+bfJEzGVeGQbDDwk8vGrLwSXDtqJTuPWyY8D4OSeZFqbNELPU0PNOhB8uPr7WAkMhW/XpOOV8KwY8sZmz8kDcZ4d6xGO6Ay2Rt3V953sZdkmMP6M4DY5Tv9goO99dToDCs6mVKZ8YUJUBLNU7XG6tCf9NZVG8tZjgJrzOdz7MVtrkeNopjDTBuxjutX7R2hUAcmY0IqGQmN0GlFx728+Ca00IO5IbfHsabTutaQaAaU/fvmg+oJlArSF8kyACoqswwYcPEgMNXGHmFsoJBSX4WFukmue/Q+S0nxmdhMj0ssYzUm5xLRMHH7SKbwuw27razSpfHF8S92PEAduyphP7VtkV+MgFgyS6riN2kIuDPLhG0PyffrKUeuBL9dNfllnLPsD9iQIAcZ+mAyokoMZAR9aAQaJbGBSFtkYRGRcWou5JvQbCDE8twrVJrzt7odWpSSuOgIvyoLUuLwC3+NpG/CzlJpVZ4UA4YuqkM5FfCwnyfmPc5bHwO5T+wwegWCzah95wbQHOQMkF9Hg7srC8kiXwhoevtV8lwNahhwni3AX3NIqnn4t1BOLGdG5KC1jrgNcwvUlqCEdGt+fxmmyoR8ppoCI6QzXJ/s9hUUBFkmwdE18lAsK2Hk7Jj1dLcnaBTh6TDZoQWVzBx5DDOX0WLs7I5KOfrWtNdaKS811ZEiTSIZ3slLPX/wKAggK5b+Pjto3IOBlgllK0WhsmaEJ+On05f0bSC/Pmi1BSLqgvfPm7TNqQ/KHPLUeMFuQZog+NN64z1TL4guwxRlUcM8yZuavM4nuyhQaVCg7c0/7UWKtvjBmSYlNv5uE0g0Lds1bx+knRnBtb3upRafNdksOeDl0N48G+SHbKXg7JInXEqs0vVLsZfpnpM2RgPrLkR8c/wBTY79KA5JnVGv/zTb8iwuwt/mLlkjfJgBfnBr/JVCqSVoTJnZa0bBDTqolgjf3dDZppV8soBUn+tLEvahqSuH4mycDRoUaMMjEyxFih1Ee6mtsKxn0k22lgjtWslsccgxh0QZwoT/Ikf6J+3A0Yzw/fYOzOoReZg0tc+gtjNzeE+c46z74sky2DDpxHzZJWDqK1S3aYCMJG8QU2TfRD6EqqQ2fq7wTqwvY4DnYVxZcBzmjSUqQYNfaFaPHgRwCPN695iG0M0lvpBpan+3h6C0wfwGvZQLXdoqf/fMK3SKVD8ZGRlr48ASEu/vFZ2qT7yRzixrcWpmHywYfToc+2+5kQ X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: edd06efd-c686-47b3-7068-08d94d4003e4 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2021 18:39:18.9213 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gOklgpO+mOjRPpRmbLj7qxT55gkd1BV0j2/xIYGc4tptTGhxYhPG1WOanVAsa7CN/yyvpp/eDlUwYJ1gK779cQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR03MB4619 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Now that we check bh->state in sleep_thread, there is no need to have a separate wakeup_needed flag. Drop it. Signed-off-by: Sean Anderson --- (no changes since v1) drivers/usb/gadget/f_mass_storage.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 6f39c24503..92e4f22797 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -328,7 +328,6 @@ struct fsg_common { unsigned int bad_lun_okay:1; unsigned int running:1; - int thread_wakeup_needed; struct completion thread_notifier; struct task_struct *thread_task; @@ -455,12 +454,6 @@ static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep) /* These routines may be called in process context or in_irq */ -/* Caller must hold fsg->lock */ -static void wakeup_thread(struct fsg_common *common) -{ - common->thread_wakeup_needed = 1; -} - static void raise_exception(struct fsg_common *common, enum fsg_state new_state) { /* Do nothing if a higher-priority exception is already in progress. @@ -469,7 +462,6 @@ static void raise_exception(struct fsg_common *common, enum fsg_state new_state) if (common->state <= new_state) { common->exception_req_tag = common->ep0_req_tag; common->state = new_state; - common->thread_wakeup_needed = 1; } } @@ -508,7 +500,6 @@ static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req) /* Hold the lock while we update the request and buffer states */ bh->inreq_busy = 0; bh->state = BUF_STATE_EMPTY; - wakeup_thread(common); } static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req) @@ -527,7 +518,6 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req) /* Hold the lock while we update the request and buffer states */ bh->outreq_busy = 0; bh->state = BUF_STATE_FULL; - wakeup_thread(common); } /*-------------------------------------------------------------------------*/ @@ -2270,7 +2260,6 @@ static void handle_exception(struct fsg_common *common) struct fsg_lun *curlun; unsigned int exception_req_tag; - common->thread_wakeup_needed = 0; /* Cancel all the pending transfers */ if (common->fsg) { for (i = 0; i < FSG_NUM_BUFFERS; ++i) { From patchwork Thu Jul 22 18:38:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1508842 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=secospa.onmicrosoft.com header.i=@secospa.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-secospa-onmicrosoft-com header.b=VfevKkYb; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GW1TS24Lvz9sT6 for ; Fri, 23 Jul 2021 04:39:56 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8C77982C68; Thu, 22 Jul 2021 20:39:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=secospa.onmicrosoft.com header.i=@secospa.onmicrosoft.com header.b="VfevKkYb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3D4F382C61; Thu, 22 Jul 2021 20:39:32 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20611.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1b::611]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D933882C5E for ; Thu, 22 Jul 2021 20:39:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sean.anderson@seco.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L51bbXXR2a3HlaH9IdQbSoUoxCo2C14pHIL/zq6Pfl1sk+cvniQ2ZWTIsUCpKRQ8S5RMsFHtdF2eU8BuMW94PIblpnK0SkmfTqfd55BY17YTwu4h6xhl74+ws1/kKQ2TiT6IGNyoEZRrpkPlsVsIA/leL8qeCidS41+MB0+h8b8SKfQWF8g4EqEO8vD9Fm69PZSrsHNl6bW5I+UN0LmiaUI1720Z9PShxuG2lNOfvQXrnTCY4TfzXFJoDVPwuy8aQy9D3HMRLKTcDqciQfRjkWxgvfHZA5XoWcbIDKZ5SqP1thpzINmZv9KItfvfYd/z5jCtvBnIyJDytnhjmwN60g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uxnVQJ3gti5+oTpKmjihIyP3mBbMZZrAkVCRlP6UqJE=; b=Dap6eLdyIWgOlYPaVxsM/HnK4PomtVp+pfGQV5W6+HjHfa9UdcsUcr5sq0aGpecOrGHmYKwyH6OGvV4MQnaYNNYTzsoao/rBpG5uwjawLQTwLFckBToxjMr/rqMHgrk2d1zkBK9xcPUIlL0iqMPPlxNHQMGbQFx6kS6OM51vbVUdqLGx5N2ZPo5ir3SWFuNHdW4ECyarR2CaAZ56Y77MtiDFwd1ESxiRGUTuj+5eUSeySkeRfL1Us872Gd+TB7eRULQwZaDhl1s2/4sh6hB7wIrf64sSSojle8chjhYuxlYZHx5U3niS4AdV2HcSbmyh7wbfSYbD12JEVkztxDxE4g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secospa.onmicrosoft.com; s=selector2-secospa-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uxnVQJ3gti5+oTpKmjihIyP3mBbMZZrAkVCRlP6UqJE=; b=VfevKkYbcZL4BHVkC7NlZoRBjEkAlWw1HjZQ3nXZLsQ3dXa2+nTQsgBdpzVnWgWX9S5oMQwFLc0aqteyX3Cz7aJmG0u8oFcGEqOQJnpWtJYw+NEj3gVgZDDfDsr2StUmuikYDBjrJy8P0InwdsBGx5JRUhQVeCHNRUdKIjwUWgQ= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) by DB7PR03MB4619.eurprd03.prod.outlook.com (2603:10a6:10:14::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.24; Thu, 22 Jul 2021 18:39:20 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::dc6c:815b:2062:d1f1]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::dc6c:815b:2062:d1f1%7]) with mapi id 15.20.4352.025; Thu, 22 Jul 2021 18:39:20 +0000 From: Sean Anderson To: u-boot@lists.denx.de, Lukasz Majewski Cc: Andre Przywara , Marek Szyprowski , Peng Fan , Bryan O'Donoghue , Marek Vasut , Jun Li , Maxime Ripard , Ye Li , Jagan Teki , Sean Anderson Subject: [PATCH v2 3/3] usb: f_mass_storage: Stop after the host deconfigures us Date: Thu, 22 Jul 2021 14:38:10 -0400 Message-Id: <20210722183811.76441-3-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210722183811.76441-1-sean.anderson@seco.com> References: <20210722183811.76441-1-sean.anderson@seco.com> X-ClientProxiedBy: MN2PR01CA0047.prod.exchangelabs.com (2603:10b6:208:23f::16) To DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from plantagenet.inhand.com (50.195.82.171) by MN2PR01CA0047.prod.exchangelabs.com (2603:10b6:208:23f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.26 via Frontend Transport; Thu, 22 Jul 2021 18:39:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 324bfecb-018e-4fb6-1d93-08d94d400500 X-MS-TrafficTypeDiagnostic: DB7PR03MB4619: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7FNg4v1/Vp1xD5zAgjE0lvbEWfRLZVanqweWHia5omM1aKqcnyfF4+sZNBzSrOCryKG/WlYaJhaplSqU29Tf1JZHIev/mBpOsIfxyiQ3GmTKUIBFy6LrWzKGADybZazLEBOHHd3BmTl96kSjL0M4EjGMdir80LSGthUiKjUuKAeh/SUCCRkCg1wiv5MgR6Eirrr2wLkN2QEmETtqOcvuEDMtta6VgJ2vmnEeQbDy41AFTryej99SpS2Lnqh27uJH6wACQun3Ihdzpwm/Hk0cMakGRKqHKCy4qOj+16mUZp1+slApueweAshhuzCDgAhJIe4Lqd+GYV4GGSlepyuqQFcJb37hR0frjCGLg0g6SuNKD/E2pxN3AOlTh6ITpohYi2UAMgn6+b9SlhGkrFxhVwiMG7QUwPqb3/ZXNaRySvBhzaqRJMVd9yPr57ALBC7IwoydICo5a4baVOq56muyEraxVoS7MrkmlH8RMGH2r9HOq1ouR/g2zIRr4ih7+Ea0atPbBctITmZdOjRnPWIdRMm9KPlNbhQYKtdn1zZleTk5LGyUqZkHlZinK0Vbe8AOHdSw/i62jY52gJpWZcggn28YavQDFAfTdOFdgSMX6wkAMMEI1l7uK6k0dOi1K1GLfS8Uf5YXFJjS823wiMtwn01W5QUXeOGfVqc2hj3Z9uN55jm5bOlLSCv667P+tSxWD8Jz9XAvOnYYN9cOnhMHFQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4523.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(136003)(346002)(396003)(376002)(39830400003)(366004)(107886003)(2616005)(316002)(6506007)(66476007)(66946007)(86362001)(956004)(66556008)(478600001)(44832011)(83380400001)(186003)(26005)(52116002)(6486002)(38350700002)(8676002)(38100700002)(8936002)(6666004)(4326008)(5660300002)(6512007)(7416002)(54906003)(2906002)(36756003)(1076003)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5krZwaDv46dRsg6I6doWLN1wz4kqDaOed7mh30rwnWRwD8vSH8G22b00zZR0GOCszr66jBDuVZAK+b2XQ7TY7O25J0B48d4SD/k48fqpnjoe1P1Wd7JXG9/gvSOrxBWQcwXE+BO5VhCa03VEc78vql7ZwW2OzzWMHjtyxSdpt5Enq3TJDkdcWXUNwLYIhIbsFKFK1WNa1zyMOY6+4H+tHIMRNCn1nxVbBb0Vm6met8cFEHDERI8AYHSFed6PqrOdahwy0PqqpgFn+RYlz9zAJG2WiUOiA1si2DNOrXAFcStKXdJeNp5QZS4sn4ItAA7HBadYn4RWkm+Er6VHHV7t/YthjivsV+9EwMtDc+urKqSAE/fAIbnmo5QZ25cDWa6+LGBldibQeP+JHASoFT5U5uh14/y6hpJVf5uVnU+uhcFaWXk0sUL0QJ0yBoNWMe+W1FRe/MLtfbvGASiJkk1YIw9gD4uW6f5gRSKQ1jMpcbXt1D+Pek1f+OjzB27TD5b2Y4CWVKfPsRC/Gi8ZJ0UApn0RXFPlXIf/L4XEG76AHrfkCJfh0iI/McS1E/xe+Y7mOasfB3BQpLOifNTPiYEswqgUI2YyZQ3lL97FHkcl//QHsBfQY0JbPY5Ivku1+3zlHEKYkk7KyvJykH4Y52z0ZcUA+GMuS2p5SEdbQPaLxPolwZSuE1vaMJwR2uvWqEAV7mCW+u9nCi8n9Yx1uUDxU1rxzNsgTmnFQLQA3WMSp1uOTZeB/OHqSvAhnhp6rYcbWzrlyKc8FzYcMZJpxatq+jvxDhqk3ueLWD7uU0zs4Ohg/ggruFkypLKjOHu6tWFiafVL9LBbNPSRzJDPA2MiTwLuO8R7MWkC5jm8wK1yD4gAG9YMf0duknkpndz5jDUDSDbsA7eaYoeJ1zoUmy8qeOpsWh3VySA+PDBoNzfmfr4pEuHeO9GNkiCKNrCGRZJdWbZOgjdXIDRJB+gpf2DUqxk+ZdJYRm/SXUx7TmaaVqSOdTUX4rEMMJBRx4IWo8G7T2W8g95uJLVNgPrg/8ppMt6yAQqGG69Q9d58SqFl9oSxPLUsSxrILg3lBiLtyUpTFfK+LMxbZW2N2stKBUZC0SEC0Gl4+bjbqUvIUn+ga9Hug7gKo8L6xzQ3hwfuedZq2bj8/yT8YBMblj9EPFZ4O4eclYJ5KuLr4i353MfUu6RnVaR2//HM5yRY1brhVsRQc5uSMcXBcXeVIAb8jGPT/ZQh/EdwJBcFNn+q2hFKox0orqG6Ql4RLi+ozN0lUk+YX0EyRfEMJMbwUJhxQySHXf/44Lfl23roIxhGWcKGapvL4F/Byj+JDn7McLJLRtjw X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 324bfecb-018e-4fb6-1d93-08d94d400500 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2021 18:39:20.7864 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lNK0DwWWKMvFnsBJdghLVyrEqnx5FFDHKHV2HkArjdUxMkIE1vIPijpGU7YL0MvtOht3NWreZ0LO/P83cBaD9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR03MB4619 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean At the moment there is no way to signal to U-Boot from the host that we are done reading/writing data. This stops the gadget after the host deconfigures us by selecting config 0. In theory, the host could later select this configuration again, but this rarely happens. On Linux this may be accomplished by running udisksctl power-off -b /dev/sdX Signed-off-by: Sean Anderson --- (no changes since v1) cmd/usb_mass_storage.c | 3 +++ drivers/usb/gadget/f_mass_storage.c | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/usb_mass_storage.c b/cmd/usb_mass_storage.c index d4e619b842..bac4ad87b9 100644 --- a/cmd/usb_mass_storage.c +++ b/cmd/usb_mass_storage.c @@ -227,6 +227,9 @@ static int do_usb_mass_storage(struct cmd_tbl *cmdtp, int flag, if (rc == -EPIPE) printf("\rCTRL+C - Operation aborted\n"); + if (rc == -ENOLINK) + printf("\rHost closed connection\n"); + rc = CMD_RET_SUCCESS; goto cleanup_register; } diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 92e4f22797..0e7a90683b 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -2247,7 +2247,10 @@ static void fsg_disable(struct usb_function *f) { struct fsg_dev *fsg = fsg_from_func(f); fsg->common->new_fsg = NULL; - raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); + if (fsg->common->running) + raise_exception(fsg->common, FSG_STATE_EXIT); + else + raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); } /*-------------------------------------------------------------------------*/ @@ -2393,6 +2396,8 @@ int fsg_main_thread(void *common_) common->thread_task = NULL; + if (common->state == FSG_STATE_TERMINATED) + return -ENOLINK; return 0; }