From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; dkim=none X-Greylist: delayed 477 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 24 Nov 2023 05:47:26 PST Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEFC91BE for ; Fri, 24 Nov 2023 05:47:26 -0800 (PST) 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 Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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-Spam-Score: 14.29 X-Rspamd-Queue-Id: 8714C1FDB0 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