haze: fix usb 3.0 support

This commit is contained in:
Liam 2023-04-17 14:52:02 -04:00
commit af08ec6ffd
4 changed files with 30 additions and 24 deletions

View file

@ -20,7 +20,8 @@
namespace haze { namespace haze {
constexpr inline u32 PtpUsbBulkHighSpeedMaxPacketLength = 0x200; constexpr inline u32 PtpUsbBulkHighSpeedMaxPacketLength = 0x200;
constexpr inline u32 PtpUsbBulkSuperSpeedMaxPacketLength = 0x400;
constexpr inline u32 PtpUsbBulkHeaderLength = 2 * sizeof(u32) + 2 * sizeof(u16); constexpr inline u32 PtpUsbBulkHeaderLength = 2 * sizeof(u32) + 2 * sizeof(u16);
constexpr inline u32 PtpStringMaxLength = 255; constexpr inline u32 PtpStringMaxLength = 255;

View file

@ -43,7 +43,6 @@ namespace haze {
Event *GetCompletionEvent(UsbSessionEndpoint ep) const; Event *GetCompletionEvent(UsbSessionEndpoint ep) const;
Result TransferAsync(UsbSessionEndpoint ep, void *buffer, u32 size, u32 *out_urb_id); Result TransferAsync(UsbSessionEndpoint ep, void *buffer, u32 size, u32 *out_urb_id);
Result GetTransferResult(UsbSessionEndpoint ep, u32 urb_id, u32 *out_transferred_size); Result GetTransferResult(UsbSessionEndpoint ep, u32 urb_id, u32 *out_transferred_size);
Result SetZeroLengthTermination(bool enable);
}; };
} }

View file

@ -28,7 +28,6 @@ namespace haze {
/* Set up a new USB session. */ /* Set up a new USB session. */
R_TRY(g_usb_session.Initialize(interface_info, id_vendor, id_product)); R_TRY(g_usb_session.Initialize(interface_info, id_vendor, id_product));
R_TRY(g_usb_session.SetZeroLengthTermination(false));
R_SUCCEED(); R_SUCCEED();
} }

View file

@ -102,13 +102,21 @@ namespace haze {
.bEndpointAddress = USB_ENDPOINT_IN, .bEndpointAddress = USB_ENDPOINT_IN,
.bmAttributes = USB_TRANSFER_TYPE_INTERRUPT, .bmAttributes = USB_TRANSFER_TYPE_INTERRUPT,
.wMaxPacketSize = 0x18, .wMaxPacketSize = 0x18,
.bInterval = 0x4, .bInterval = 0x6,
}; };
struct usb_ss_endpoint_companion_descriptor endpoint_companion = { struct usb_ss_endpoint_companion_descriptor endpoint_companion = {
.bLength = sizeof(struct usb_ss_endpoint_companion_descriptor), .bLength = sizeof(struct usb_ss_endpoint_companion_descriptor),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMPANION, .bDescriptorType = USB_DT_SS_ENDPOINT_COMPANION,
.bMaxBurst = 0x0F, .bMaxBurst = 0x0f,
.bmAttributes = 0x00,
.wBytesPerInterval = 0x00,
};
struct usb_ss_endpoint_companion_descriptor endpoint_companion_interrupt = {
.bLength = sizeof(struct usb_ss_endpoint_companion_descriptor),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMPANION,
.bMaxBurst = 0x00,
.bmAttributes = 0x00, .bmAttributes = 0x00,
.wBytesPerInterval = 0x00, .wBytesPerInterval = 0x00,
}; };
@ -131,13 +139,15 @@ namespace haze {
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_High, std::addressof(endpoint_descriptor_interrupt), USB_DT_ENDPOINT_SIZE)); R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_High, std::addressof(endpoint_descriptor_interrupt), USB_DT_ENDPOINT_SIZE));
/* Super speed config. */ /* Super speed config. */
endpoint_descriptor_in.wMaxPacketSize = PtpUsbBulkSuperSpeedMaxPacketLength;
endpoint_descriptor_out.wMaxPacketSize = PtpUsbBulkSuperSpeedMaxPacketLength;
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(interface_descriptor), USB_DT_INTERFACE_SIZE)); R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(interface_descriptor), USB_DT_INTERFACE_SIZE));
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(endpoint_descriptor_in), USB_DT_ENDPOINT_SIZE)); R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(endpoint_descriptor_in), USB_DT_ENDPOINT_SIZE));
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(endpoint_companion), USB_DT_SS_ENDPOINT_COMPANION_SIZE)); R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(endpoint_companion), USB_DT_SS_ENDPOINT_COMPANION_SIZE));
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(endpoint_descriptor_out), USB_DT_ENDPOINT_SIZE)); R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(endpoint_descriptor_out), USB_DT_ENDPOINT_SIZE));
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(endpoint_companion), USB_DT_SS_ENDPOINT_COMPANION_SIZE)); R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(endpoint_companion), USB_DT_SS_ENDPOINT_COMPANION_SIZE));
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(endpoint_descriptor_interrupt), USB_DT_ENDPOINT_SIZE)); R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(endpoint_descriptor_interrupt), USB_DT_ENDPOINT_SIZE));
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(endpoint_companion), USB_DT_SS_ENDPOINT_COMPANION_SIZE)); R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Super, std::addressof(endpoint_companion_interrupt), USB_DT_SS_ENDPOINT_COMPANION_SIZE));
/* Set up endpoints. */ /* Set up endpoints. */
R_TRY(usbDsInterface_RegisterEndpoint(m_interface, std::addressof(m_endpoints[UsbSessionEndpoint_Write]), endpoint_descriptor_in.bEndpointAddress)); R_TRY(usbDsInterface_RegisterEndpoint(m_interface, std::addressof(m_endpoints[UsbSessionEndpoint_Write]), endpoint_descriptor_in.bEndpointAddress));
@ -190,28 +200,29 @@ namespace haze {
0x02, /* .bNumDeviceCaps */ 0x02, /* .bNumDeviceCaps */
/* USB 2.0 */ /* USB 2.0 */
0x07, /* .bLength */ 0x07, /* .bLength */
USB_DT_DEVICE_CAPABILITY, /* .bDescriptorType */ USB_DT_DEVICE_CAPABILITY, /* .bDescriptorType */
0x02, /* .bDevCapabilityType */ 0x02, /* .bDevCapabilityType */
0x02, 0x00, 0x00, 0x00, /* .bmAttributes */ 0x02, 0x00, 0x00, 0x00, /* .bmAttributes */
/* USB 3.0 */ /* USB 3.0 */
0x0A, /* .bLength */ 0x0a, /* .bLength */
USB_DT_DEVICE_CAPABILITY, /* .bDescriptorType */ USB_DT_DEVICE_CAPABILITY, /* .bDescriptorType */
0x03, /* .bDevCapabilityType */ 0x03, /* .bDevCapabilityType */
0x00, /* .bmAttributes */ 0x00, /* .bmAttributes */
0x0C, 0x00, /* .wSpeedSupported */ 0x0c, 0x00, /* .wSpeedSupported */
0x03, /* .bFunctionalitySupport */ 0x03, /* .bFunctionalitySupport */
0x00, /* .bU1DevExitLat */ 0x00, /* .bU1DevExitLat */
0x00, 0x00 /* .bU2DevExitLat */ 0x00, 0x00 /* .bU2DevExitLat */
}; };
R_TRY(usbDsSetBinaryObjectStore(bos, sizeof(bos))); R_TRY(usbDsSetBinaryObjectStore(bos, sizeof(bos)));
} }
R_TRY(hosversionAtLeast(5, 0, 0) ? this->Initialize5x(info) : this->Initialize1x(info));
if (hosversionAtLeast(5, 0, 0)) { if (hosversionAtLeast(5, 0, 0)) {
R_TRY(this->Initialize5x(info));
R_TRY(usbDsEnable()); R_TRY(usbDsEnable());
} else {
R_TRY(this->Initialize1x(info));
} }
R_SUCCEED(); R_SUCCEED();
@ -247,8 +258,4 @@ namespace haze {
R_SUCCEED(); R_SUCCEED();
} }
Result UsbSession::SetZeroLengthTermination(bool enable) {
R_RETURN(usbDsEndpoint_SetZlt(m_endpoints[UsbSessionEndpoint_Write], enable));
}
} }