From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 32711C61D97 for ; Fri, 24 Nov 2023 13:40:18 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 9D7A1DFA; Fri, 24 Nov 2023 14:40:06 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9D7A1DFA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1700833216; bh=rCFXfoehlNk3vMTlGhCyClVOAyRIFRNIYv27MUstVbM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=N/Z4jp2PZbvG0OI+qQwTi2Dj+If8uIgm0NqEhoCVQ0SG8HoNh8VV/ZombqlDD01YB eys+S3ovkodhYGFm6m48P9ZM6Ug7RArTEYAlSxgub4GX8gwjMivyKhWolsTMa6dbwk TVvUNAe8ZvuIvSIybioylTyhmP+8/PI5BmkSevDo= Received: by alsa1.perex.cz (Postfix, from userid 50401) id C5070F80578; Fri, 24 Nov 2023 14:39:43 +0100 (CET) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 6E4ADF80570; Fri, 24 Nov 2023 14:39:43 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7CB0BF802E8; Fri, 24 Nov 2023 14:39:38 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 6BE1DF80166 for ; Fri, 24 Nov 2023 14:39:28 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6BE1DF80166 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8714C1FDB0; Fri, 24 Nov 2023 13:39:27 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 5C3C913A98; Fri, 24 Nov 2023 13:39:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id +nc1FY+nYGXkNgAAD6G6ig (envelope-from ); Fri, 24 Nov 2023 13:39:27 +0000 Date: Fri, 24 Nov 2023 14:39:26 +0100 Message-ID: <871qcfqnht.wl-tiwai@suse.de> From: Takashi Iwai To: "Geoffrey D. Bennett" Cc: Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-sound@vger.kernel.org Subject: Re: [PATCH RFC v2] ALSA: scarlett2: Add ioctls for user-space access In-Reply-To: References: <76c1526d-78be-92d2-cf2b-148278394575@perex.cz> <123242ed-c343-dab8-fed1-9f5d2da44d7a@perex.cz> <87edhtn0r2.wl-tiwai@suse.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spamd-Bar: ++++++++++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out2.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of tiwai@suse.de) smtp.mailfrom=tiwai@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [14.29 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(3.00)[1.000]; MIME_GOOD(-0.10)[text/plain]; R_SPF_SOFTFAIL(4.60)[~all]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; NEURAL_SPAM_LONG(3.50)[1.000]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[10.34%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Rspamd-Queue-Id: 8714C1FDB0 Message-ID-Hash: 7TRQB24YFJKMF5WSKKYMDA4T43OIOWG5 X-Message-ID-Hash: 7TRQB24YFJKMF5WSKKYMDA4T43OIOWG5 X-MailFrom: tiwai@suse.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Sun, 19 Nov 2023 18:35:27 +0100, Geoffrey D. Bennett wrote: > > Hi Jaroslav, Takashi, > > I took your feedback onboard about not providing generic access to the > scarlett2_usb() function from user-space. > > After a few iterations, I've come up with this hwdep interface to > support reset-to-factory-defaults, reset-to-factory-firmware, and > firmware-update in a safe way: > > -----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<----- > > /* Get protocol version */ > #define SCARLETT2_IOCTL_PVERSION _IOR('S', 0x60, int) > > /* Reboot */ > #define SCARLETT2_IOCTL_REBOOT _IO('S', 0x61) > > /* Select flash segment */ > #define SCARLETT2_SEGMENT_ID_SETTINGS 0 > #define SCARLETT2_SEGMENT_ID_FIRMWARE 1 > #define SCARLETT2_SEGMENT_ID_COUNT 2 > > #define SCARLETT2_IOCTL_SELECT_FLASH_SEGMENT _IOW('S', 0x62, int) > > /* Erase selected flash segment */ > #define SCARLETT2_IOCTL_ERASE_FLASH_SEGMENT _IO('S', 0x63) > > /* Get selected flash segment erase progress > * 1 through to num_blocks, or 255 for complete > */ > struct scarlett2_flash_segment_erase_progress { > unsigned char progress; > unsigned char num_blocks; > }; > #define SCARLETT2_IOCTL_GET_ERASE_PROGRESS \ > _IOR('S', 0x64, struct scarlett2_flash_segment_erase_progress) > > -----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<----- > > Does that look reasonable to you? > > Broadly, it's used like this: > > Reset to factory default configuration: > > - ioctl select_flash_segment SCARLETT2_SEGMENT_ID_SETTINGS > - ioctl erase_flash_segment > - ioctl get_erase_progress (optional) So the erase operation is asynchronous? This sounds a bit dangerous. Will the driver block further conflicting operations until the erase finishes? > Erase firmware (reverts to factory firmware which is stored in a > different flash segment, inaccessible from these ioctls): > > - ioctl select_flash_segment SCARLETT2_SEGMENT_ID_FIRMWARE > - ioctl erase_flash_segment > - ioctl get_erase_progress (optional) > > Upload new firmware: > > - write() <- a bunch of these, only permitted after the previous erase > step was completed The write op must accept partial writes, and it becomes cumbersome. Can it be a one-shot ioctl, too? > On completion: > > - ioctl reboot > > To confirm that this interface is sufficient, I have implemented it in > the scarlett2 driver and written a user-space utility which can > perform all the above operations. > > I will clean up the implementation a bit and then submit for review; > just wanted to share the interface first in case you have any comments > at this point. IMO, from the user POV, it's easier to have per-purpose ioctls, instead of combining multiple ioctl sequences. Of course, it won't scale too much, but for the limited number of operations, it's clearer. That is, we can provide just a few ioctls for reset-to-factory, reset-to-something-else, and update. But, if you need asynchronous operations inevitably by some reason, it's a different story, though. thanks, Takashi