From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3C29421F0F for ; Tue, 11 Aug 2026 09:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786441362; cv=none; b=Jz02vNndXU26fhQXvj/dYTY8t67irki3F5ze587GG5Pk+ZHGheakaE9kkwygc2e35cC+47a90JqDn5pLifr9prgRRV41HcoVfpXVNpqkmOTHrSdcFSm56zoF5hR9Sk1xJtJid7joZHvSfPqbPtkL4fIs22Kj1qpSI9oWwxzxjlc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786441362; c=relaxed/simple; bh=3GtPDBtfDSI5Fg2TNJcbEvcKP7Jiow8UZdpWvMuWxk0=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=Eixl/z5pJKNWojrKIOpwMMjSsP1wELU7viuHcl5eOGPK5pW0lk7mg8606aic/R5jBt0cNIVFIEQSlts43A0MZjSRWr+HYY+dwE3h7j8XIv+voQMUTExIwDQ5b58G09Uj5U7FUm2tJRpw8/AMK4kuazFS7FUVHAyL5FwzPua5B20= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wyliodrin.com; spf=pass smtp.mailfrom=wyliodrin.com; dkim=pass (1024-bit key) header.d=wyliodrin.com header.i=@wyliodrin.com header.b=IUwQbBtv; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wyliodrin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wyliodrin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=wyliodrin.com header.i=@wyliodrin.com header.b="IUwQbBtv" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-47ffaa8ebbdso2269261f8f.0 for ; Tue, 11 Aug 2026 02:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wyliodrin.com; s=google; t=1786441358; x=1787046158; darn=vger.kernel.org; h=cc:to:content-transfer-encoding:content-type:mime-version :message-id:date:subject:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=vDbf3rFmEbyUidca3UBZclD6tLiyKIeDuCnP/rYnFg0=; b=IUwQbBtvtneF7lZvik9PzYS0WQ4NQbagYsGZvhcikWXXwk6pHNlGrAXs6bQ6ClF5V9 bDMMmt5ygAjWoonBBOMQXIxU7RvvSOX01BZTqJoORjB4cVZKs2Jy8cVnNJZCJXf+GvsO MSICWl3AUcLYD5VU7FBtDKa55KO4mnOxDAR+o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786441358; x=1787046158; h=cc:to:content-transfer-encoding:content-type:mime-version :message-id:date:subject:from:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=vDbf3rFmEbyUidca3UBZclD6tLiyKIeDuCnP/rYnFg0=; b=MtTV78EA7fx7hV7d9LxF8SUA3xhxJ98/Rp8dnKaLushxmhKUoA+cjQJYR3924QvQdQ vQ6/AeCimZzfj0ACF/sVScyhEsYpenRVOj6QIoCg51OekPCEDq3gsLVuIdul7tB/ecna DPGn5PnOt6AN91gYkUBMzCAR1ZiBNnvSrPTbL6R27aHWiXbb+hW6bRmN4TMAg1QqfT84 fCOMNgQMgoMQ1XlrsdihlcJak6QiUr5/G/OzQWhk9dqyjY7bBkoCQ86bIPliH16j2Jfm AiRL6J1yQN+dQ8J9ITSpWzuemA0ghvUIUA1mp8yyMkbeL7IyOcuGaUe0c5bMf5JQF5Z3 +xpw== X-Gm-Message-State: AOJu0YzUKS0b9pWk3ukrvr24ni6NMu56Qv45FZSIWthrFNBluurdo5+y HLF7kn/OSahB3fgAKtcp+Pvq+fpPy6KoktgkWjtUonwBe+NMYcfbjVu7NXWn2apiaP0= X-Gm-Gg: AR+sD12DBAJ/Ov6B6PYbG8BfhS2NmJuSfX9tVfbwdU9aa65cRtCDxZ4bqn+KAiGgtQm mI2ZTMwd+NyVtkIEvZZ/XNg/bO2yfNCiM+/PiKyrwvKYeTPPQmeYqPRTYPhGrhru59sgoklN4hh W4iaFUnew26H6vzV1L3EkDvi72RRpt0cJ+rs33Fk+JetuawccCI37dpuqEzyftKhMMPNM2VW+M2 djox9XjyycVWpAmCKG9V4c85Mcq5K8xLeiB52ZBLNy27NZTSK/z1GSLCzcqvmqCq8RbJ6CASQZD Yo7G/qqA//+4X1Nmwxtrfd7GO3LJll4fhXulTZw0Ck1BGJE56DpjPIQVfEbvkCM9Qbc+6wKtOU9 yM7twG+R6u30i+pzn4bSHJVjMxIHMj+GRKZkL34qooxswBU7dZ5CBm+H7xXyv/jmuPuRZDpLnF3 +ppfzQYJD1yeek+LOYoy0NLpIeaNzJhshM1f3fTpERQ41dqZ9KZXQYxpPHOPPsPSWj68w1/m4qu RpFn06zTkoZ6/P3NXcT6XCcyRhvcAiORIc3iA== X-Received: by 2002:a05:6000:1449:b0:47f:fa17:ae0e with SMTP id ffacd0b85a97d-4814ad8a600mr2615990f8f.11.1786441358189; Tue, 11 Aug 2026 02:42:38 -0700 (PDT) Received: from [10.0.36.57] ([217.73.170.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4814a709624sm3388917f8f.22.2026.08.11.02.42.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 02:42:37 -0700 (PDT) From: Alexandru Radovici Subject: [PATCH RFC v2 0/4] rust: usb: abstractions towards the port of usbsevseg.c to Rust Date: Tue, 11 Aug 2026 12:42:27 +0300 Message-Id: <20260811-rust-usb_control_msg-v2-0-ef79c92bd898@wyliodrin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAAAAAAAC/32NQQqDMBBFryKzbkqSRpGuCoUeoNsi0sSpDmhSJ mor4t0bPECX73/++ytEZMII52wFxpkiBZ9AHzJw3dO3KKhJDFrqQpZSCZ7iKKZoaxf8yKGvh9g KxJNBKbUtVQlp+mZ80XfXPuB+u0KVwo7iGHjZr2a1V/+tsxJSFHlurTHG5tpdPktPoWHyRxcGq LZt+wFLAZY3wQAAAA== X-Change-ID: 20260801-rust-usb_control_msg-ee34e002b818 To: Greg Kroah-Hartman , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= , "Rafael J. Wysocki" Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev, Alexandru Radovici X-Mailer: b4 0.14.3 My end goal is to port the usbsevseg.c USB driver to Rust. That driver is small enough to make a useful first target; the remaining piece it needs is sysfs attribute support for USB devices, which I plan to send separately. Porting the driver requires: - retrieving endpoints and sending control messages API (this series) - enabling sysfs attributes API for USB devices (future patch) These patches add the USB and sysfs abstractions needed to port drivers/usb/misc/usbsevseg.c to Rust: retrieving an interface's endpoints, and sending and receiving control messages. Patch 1 adds `AlternateEndpoint`, along with `AlternateSetting` and the accessors needed to reach one. Patch 2 adds the control transfer methods and the `Request` type describing a setup packet. Patch 3 adds the sysfs abstractions. Patch 4 adds the sysfs abstractions to `usb::Driver`. The part I would most like feedback on is the typestate design in patch 1. `HostEndpoint` is generic over a direction and a transfer type, both sealed 1-ZST markers, so a function can require e.g. `&HostEndpoint` and skip checking the descriptor itself. Control endpoints get a `Bidirectional` marker rather than a direction, since bit 7 of bEndpointAddress is ignored for them. I am not sure whether this earns its complexity for the drivers we expect, or whether plain run-time check would be better. Only `as_control()`, `as_in()` and `as_out()` are implemented so far; `as_bulk()`, `as_interrupt()` and `as_isochronous()` are skiped for now as no current user needs them. I am not sure about the soundness of the sysfs absgtractions, especially the lifetime annotations of `DEVICE_GROUPS`. Feedback for this would be greatly appreciated. Signed-off-by: Alexandru Radovici --- Changes in v2: - add sysfs abstractions - add DEVICE_GROUPS abstractions to usb::Driver using sysfs - rename the `control_` methods correctly - use `Duration` instead of `i32` for control functions timeout - fix control function 0 value timeout from "for ever" to `USB_MAX_SYNCHRONOUS_TIMEOUT` - add `#[inline]` to short functions - use `u16::from_le` to read `wMaxPacketSize` - rename `Generic` generic type to `Dir` - impl `max_nak_rate` for `HostEndpoint` - make data `&mut [u8]` for `control_message_receive` - Link to v1: https://lore.kernel.org/r/20260801-rust-usb_control_msg-v1-0-655bb444b52c@wyliodrin.com --- Alexandru Radovici (4): rust: usb: add endpoint abstraction rust: usb: add control message send and receive rust: sysfs: add abstractions for device attributes rust: usb: allow drivers to expose sysfs attributes rust/kernel/device.rs | 2 +- rust/kernel/lib.rs | 2 + rust/kernel/sysfs.rs | 602 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/usb.rs | 227 ++++++++++++++- rust/kernel/usb/control.rs | 367 ++++++++++++++++++++++++ rust/kernel/usb/endpoint.rs | 516 ++++++++++++++++++++++++++++++++++ samples/rust/rust_driver_usb.rs | 14 + 7 files changed, 1725 insertions(+), 5 deletions(-) --- base-commit: 8ba098e6b6ff0db8edf28528d1552be261af30d4 change-id: 20260801-rust-usb_control_msg-ee34e002b818 Best regards, -- Alexandru Radovici