* [PATCH] usb: gadget: f_mass_storage: Stop ums on START-STOP UNIT SCSI command
@ 2023-11-07 0:09 Marek Vasut
2023-11-07 9:02 ` Mattijs Korpershoek
2023-11-13 9:08 ` Mattijs Korpershoek
0 siblings, 2 replies; 3+ messages in thread
From: Marek Vasut @ 2023-11-07 0:09 UTC (permalink / raw)
To: u-boot; +Cc: Marek Vasut, Lukasz Majewski, Mattijs Korpershoek
Exit the UMS handler loop in case START-STOP UNIT SCSI command is
received. This is sent e.g. by the util-linux eject(1) command and
indicates to the device that it is supposed to spin down the media
and enter low power state.
This effectively adds support for exitting the 'ums' command from
host using 'eject /dev/sdN' that is on par with 'dfu-util -e' .
Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: Lukasz Majewski <lukma@denx.de>
Cc: Mattijs Korpershoek <mkorpershoek@baylibre.com>
---
drivers/usb/gadget/f_mass_storage.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 1d17331cb03..c725aed3f62 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -327,6 +327,7 @@ struct fsg_common {
unsigned int short_packet_received:1;
unsigned int bad_lun_okay:1;
unsigned int running:1;
+ unsigned int eject:1;
int thread_wakeup_needed;
struct completion thread_notifier;
@@ -669,6 +670,10 @@ static int sleep_thread(struct fsg_common *common)
}
if (k == 10) {
+ /* Handle START-STOP UNIT */
+ if (common->eject)
+ return -EPIPE;
+
/* Handle CTRL+C */
if (ctrlc())
return -EPIPE;
@@ -1325,6 +1330,8 @@ static int do_start_stop(struct fsg_common *common)
return -EINVAL;
}
+ common->eject = 1;
+
return 0;
}
--
2.42.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] usb: gadget: f_mass_storage: Stop ums on START-STOP UNIT SCSI command
2023-11-07 0:09 [PATCH] usb: gadget: f_mass_storage: Stop ums on START-STOP UNIT SCSI command Marek Vasut
@ 2023-11-07 9:02 ` Mattijs Korpershoek
2023-11-13 9:08 ` Mattijs Korpershoek
1 sibling, 0 replies; 3+ messages in thread
From: Mattijs Korpershoek @ 2023-11-07 9:02 UTC (permalink / raw)
To: Marek Vasut, u-boot; +Cc: Marek Vasut, Lukasz Majewski
Hi Marek,
Thank you for your patch.
On mar., nov. 07, 2023 at 01:09, Marek Vasut <marex@denx.de> wrote:
> Exit the UMS handler loop in case START-STOP UNIT SCSI command is
> received. This is sent e.g. by the util-linux eject(1) command and
> indicates to the device that it is supposed to spin down the media
> and enter low power state.
>
> This effectively adds support for exitting the 'ums' command from
> host using 'eject /dev/sdN' that is on par with 'dfu-util -e' .
>
> Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
> ---
> Cc: Lukasz Majewski <lukma@denx.de>
> Cc: Mattijs Korpershoek <mkorpershoek@baylibre.com>
> ---
> drivers/usb/gadget/f_mass_storage.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
> index 1d17331cb03..c725aed3f62 100644
> --- a/drivers/usb/gadget/f_mass_storage.c
> +++ b/drivers/usb/gadget/f_mass_storage.c
> @@ -327,6 +327,7 @@ struct fsg_common {
> unsigned int short_packet_received:1;
> unsigned int bad_lun_okay:1;
> unsigned int running:1;
> + unsigned int eject:1;
>
> int thread_wakeup_needed;
> struct completion thread_notifier;
> @@ -669,6 +670,10 @@ static int sleep_thread(struct fsg_common *common)
> }
>
> if (k == 10) {
> + /* Handle START-STOP UNIT */
> + if (common->eject)
> + return -EPIPE;
> +
> /* Handle CTRL+C */
> if (ctrlc())
> return -EPIPE;
> @@ -1325,6 +1330,8 @@ static int do_start_stop(struct fsg_common *common)
> return -EINVAL;
> }
>
> + common->eject = 1;
> +
> return 0;
> }
>
> --
> 2.42.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] usb: gadget: f_mass_storage: Stop ums on START-STOP UNIT SCSI command
2023-11-07 0:09 [PATCH] usb: gadget: f_mass_storage: Stop ums on START-STOP UNIT SCSI command Marek Vasut
2023-11-07 9:02 ` Mattijs Korpershoek
@ 2023-11-13 9:08 ` Mattijs Korpershoek
1 sibling, 0 replies; 3+ messages in thread
From: Mattijs Korpershoek @ 2023-11-13 9:08 UTC (permalink / raw)
To: u-boot, Marek Vasut; +Cc: Lukasz Majewski
Hi,
On Tue, 07 Nov 2023 01:09:59 +0100, Marek Vasut wrote:
> Exit the UMS handler loop in case START-STOP UNIT SCSI command is
> received. This is sent e.g. by the util-linux eject(1) command and
> indicates to the device that it is supposed to spin down the media
> and enter low power state.
>
> This effectively adds support for exitting the 'ums' command from
> host using 'eject /dev/sdN' that is on par with 'dfu-util -e' .
>
> [...]
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu-next)
[1/1] usb: gadget: f_mass_storage: Stop ums on START-STOP UNIT SCSI command
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/957e96e9fcccf26a2fe4101adbd6681578346460
--
Mattijs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-13 9:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-07 0:09 [PATCH] usb: gadget: f_mass_storage: Stop ums on START-STOP UNIT SCSI command Marek Vasut
2023-11-07 9:02 ` Mattijs Korpershoek
2023-11-13 9:08 ` Mattijs Korpershoek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox