-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kernel: Add a basic USB Attached SCSI (UAS) driver #25067
base: master
Are you sure you want to change the base?
Conversation
45b6666
to
d6236f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last commit idk, rest is fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that's a lot of FIXMEs
// Note: The maximum packet size for the endpoints is 512 bytes on USB2 and 1024 bytes on USB3 | ||
// As the SenseIU is of flexible size we need to forcefully allocate some data here | ||
// The actual max size of the sense data is controlled by the MAXIMUM SENSE DATA LENGTH field in the | ||
// Control extension mode page of the device | ||
// The maximum size of the sense data is 252 bytes | ||
// Meaning the maximum size of the IU is 252+16=268 bytes | ||
// Just to be safe we allocate 512 bytes here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This should probably be formatted into a normal sentence, like what we usually do for comments.
Same for all other comments in this commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the new text better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess it's ok.
3e94004
to
e1d0d3d
Compare
@@ -97,4 +97,37 @@ ErrorOr<size_t> Device::control_transfer(u8 request_type, u8 request, u16 value, | |||
return TRY(m_default_pipe->submit_control_transfer(request_type, request, value, index, length, data)); | |||
} | |||
|
|||
ErrorOr<void> Device::activate_configuration(USBConfiguration const& configuration) | |||
{ | |||
if (m_was_configured.was_set() && m_current_configuration != configuration.configuration_id()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't think this check is necessary. Only one driver can be attached to a USB device. So unless a driver attempts to change configurations more than once, this will never happen.
And if we think so such a check is necessary, shouldn't we also do a similar check for alternate settings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking interface usage is a bit harder to track with minimal invasiveness, but might be missing something
I can remove the check but prefer to be better safe now then forgetting it later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let's keep that check for now then. We can maybe remove it once we have a better way of probing USB drivers instead of trying all drivers one by one. That theoretical new abstraction would probably have to keep track of configurations itself.
Kernel/Bus/USB/USBDevice.cpp
Outdated
@@ -97,4 +97,37 @@ ErrorOr<size_t> Device::control_transfer(u8 request_type, u8 request, u16 value, | |||
return TRY(m_default_pipe->submit_control_transfer(request_type, request, value, index, length, data)); | |||
} | |||
|
|||
ErrorOr<void> Device::activate_configuration(USBConfiguration const& configuration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally just call this function like the actual USB request it runs, set_configuration
.
And activate_interface
can probably be called something like set_configuration_and_interface
so it's clearer what it actually does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
// Note: The maximum packet size for the endpoints is 512 bytes on USB2 and 1024 bytes on USB3 | ||
// As the SenseIU is of flexible size we need to forcefully allocate some data here | ||
// The actual max size of the sense data is controlled by the MAXIMUM SENSE DATA LENGTH field in the | ||
// Control extension mode page of the device | ||
// The maximum size of the sense data is 252 bytes | ||
// Meaning the maximum size of the IU is 252+16=268 bytes | ||
// Just to be safe we allocate 512 bytes here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess it's ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I didn't mean to finish my review (Adding a response to a comment appears to submit reviews?).
Kernel/Bus/USB/USBDevice.cpp
Outdated
// FIXME: When we use the default alternate_setting of interface/the current alternate setting, we don't need to SET_INTERFACE it | ||
// but that gets a bit difficult to track | ||
TRY(control_transfer(USB_REQUEST_TRANSFER_DIRECTION_HOST_TO_DEVICE | USB_REQUEST_TYPE_STANDARD | USB_REQUEST_RECIPIENT_INTERFACE, USB_REQUEST_SET_INTERFACE, | ||
interface.descriptor().interface_id, interface.descriptor().alternate_setting, 0, nullptr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be interface.descriptor().alternate_setting, interface.descriptor().interface_id, 0, nullptr));
Kernel/Bus/USB/USBRequest.h
Outdated
@@ -41,6 +41,7 @@ static constexpr u8 USB_REQUEST_GET_DESCRIPTOR = 0x06; | |||
static constexpr u8 USB_REQUEST_SET_DESCRIPTOR = 0x07; | |||
static constexpr u8 USB_REQUEST_GET_CONFIGURATION = 0x08; | |||
static constexpr u8 USB_REQUEST_SET_CONFIGURATION = 0x09; | |||
static constexpr u8 USB_REQUEST_SET_INTERFACE = 0x11; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0x0b
|
||
if (uas_interface.has_value() && device.speed() != USB::Device::DeviceSpeed::SuperSpeed) { | ||
// FIXME: We only support UAS on version < 3.0 devices | ||
// as we don't support waiting ERDY transactions yet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These references to ERDY should probably replaced with streams (also in the commit message).
This makes it easier to access class specific descriptors, which are sometimes dependent on the descriptors immediately before them.
For now we only support USB <3.0 devices, as we don't support streams. We also don't leverage the benefits of UAS, as we pretend to have a queue depth of 1, ie are single threaded. To test this driver, you can use the following command: ``` SERENITY_BOOT_DRIVE=usb-uas Meta/serenity.sh run x86_64 Clang ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the way you added the offset to the function parameter. Make sure it has no leaks thoroughly.
Kernel/USBMS: Move the BOT/BBB driver to its own directory
Kernel/USB: Save all USB descriptors and allow iterating over them
This makes it easier to access class specific descriptors, which
are sometimes dependent on the device configuration immediately before
them.
Kernel/USBMS: Add a basic UAS driver
For now we only support USB <3.0 devices, as we don't lissten for
ERDY transaction packets.
We also don't leverage the benefits of UAS, as we pretend to have a
queue depth of 1, ie are single threaded.
To test this driver, you can use the following command:
SideNote: This can't legally fly drones
CC: @spholz