Jump to content

GenericUSBXHCI USB 3.0 driver for OS X with source

xHC USB 3.0

  • Please log in to reply
568 replies to this topic

#1
Zenith432

Zenith432

    InsanelyMac Sage

  • Developers
  • 416 posts
  • Gender:Male

*
POPULAR

I've been working on an open source USB 3.0 driver for OS X for a while, and decided it's stable enough to be published.

Implements USB SuperSpeed and HighSpeed root hubs, and accepts SS, HS, FS, LS devices. I've benchmarked a SS drive at the highest speed it's capable of with it.

If you benchmark drives, use block sizes of 128Kbyte or higher power of two - as those are optimal.

I've fixed the issue with interrupters. MSI is used on all chips except FL1000, which is known to have problems with it. Uses pin interrupt on FL1000.

Sleep Issue - Attempts to enable PME on all chips. If PME is supported, uses XHCI suspend/resume. If resume fails, resets the xHC and lets IOUSBFamily reenumerate devices (this causes disconnection messages.) If PME is not supported, reverts to shutdown/reset which will always reenumerate.
If PME is not supported, there'll be a message in syslog "xHC will be unloaded across sleep".
In case of restore error during wakeup, there'll be a message in syslog "xHC Restore Error".

Limitations: Isochronous endpoints are not supported yet. This includes anything having to do with audio or video (webcams too.) If you try to connect devices with isoch endpoints, and OS X has an upper layer driver for the device, it'll fail to configure the device and you'll probably see some messages about it from IOUSBFamily in syslog.

Some kernel flags
- "-gux_nosleep" forces Sleep to always use the shudown/reset method.
- "-gux_nomsi" forces use of pin interrupt instead of msi.
- For Intel Series 7 chipset only (Panther Point.)
"-gux_defer_usb2" causes the xHC to defer the management of USB2 ports and their devices to one of the EHC controllers on the PCH (south-bridge). This option can usually also be configured in the BIOS for Intel Series 7 chipsets.
"-gux_no_idle" disables some feature for idle-mode on Intel's chip. I couldn't test this, so I added an option to disable it.

There is a debugging tool called "xhcdump" that prints various aspects of xHC internal state. Run without options for a list things it can dump.

Note 1: If system doesn't wake from sleep, try the power button before reporting. USB keyboards don't always work during sleep.
Note 2: For Intel Series 7 - if you'd like USB 2.0 ports 1 - 4 to be managed by xhci, it's recommended you configure the bios setting to route these ports to xhci. This ensures devices don't get enumerated on ehci before being switched to xhci.
Note 3: Some Intel Series 7 motherboards have a hardware issue that causes instant-wakeup when put to sleep. Use '-gux_defer_usb2' to resolve this.

If you would like to contribute in the development, particularly to add code for a chipset that you have and can test - feel welcome to do so.

Binaries contain

  • build for OSes 10.7.5, 10.8.x, 10.9. [Earlier OSes not supported.]
  • xhcdump utility..

Binaries v1.2.7.

Sources are here.
Bugs may be reported here.

Older Binaries:
Archive
 

Edit [October 25 2013]: Release 1.2.7

  • Implemented miscellaneous errata for Intel series 8, Intel series 7, FL 1100, Etron, ASMedia 1042.
  • Optimize stream management.
  • Reorganized diagnostics.
  • Fixed some bugs.

Edit [October 1 2013]: Release 1.2.6

  • Added support for VMware virtual xHC device in Workstation 10/Fusion 6.
  • Fixed serious bug that would cause KPs with any USB3 driver supporting streams endpoints.
  • Fixed support for streams endpoints to use earlier allocation of rings.
  • Cleaned up and simplified some of the code that creates control endpoints.
  • [October 9 Update] Fixed KP when waking from unpowered sleep with streams drive.
  • [October 22 Update] Integrated workaround for using UAS drives on Etron xHCs, OS 10.8.5 or later.

Edit [September 13 2013]: Release 1.2.5

  • Support for OS 10.8.5, OS 10.9.
  • Support for Lynx Point/Intel Series 8 with 16 xHC ports (8 dual ports).

Edit [June 11 2013]: Release 1.2.4

  • Overhauled error-handling of non-isoch transfers. Fixed a couple of bugs with KP potential related to transfers.
  • Optimized handling of transfer timeouts.
  • Added kext version to 'xhcdump caps' + a couple of diagnostic counters to 'xhcdump running'

Edit [June 5 2013]: Release 1.2.3

  • Improved handling of bios semaphore for legacy USB - eliminates a problem that causes some bioses to crash during sleep.
  • Made sequence for entering sleep mode more robust and safer.
  • Eliminated potential memory corruption if xhci commands time out.
  • Eliminated some potential memory leaks, fixed some minor bugs, made some minor optimizations and added a bit more logging.

Edit [June 2 2013]: Release 1.2.2

  • Fixed extra-current errors mentioned in posts #85, #90.
  • Fixed minor issue with 32-bit build.
  • Fixed issue with chips that stop clocks for power reduction.
  • Added some logging to help debugging.

Edit [May 20 2013]: Release 1.2.1

  • Fixed alignment bug that made 32-bit build for OS 10.7.5 fail.

Edit [May 19 2013]: Release 1.2.0

  • Implemented support for Isochronous Endpoints. Should now support webcams, etc... (real-time audio/video streaming).
  • Updated UIM interface changes in OS 10.8.3.
  • Added workaround for Intel Series 7 chipset that causes instant-wakeup-on-sleep on some motherboards.

Edit [May 19 2013]: Release 1.1.6.

  • Fixed two critical bugs and seven minor bugs.

Edit [May 12 2013]: Release 1.1.5.

  • Fixed one critical bug and two minor bugs.

Edit [March 23 2013]: Release 1.1.4.

  • Reverted change that caused regression discussed in post #41. Turns out 11 msec means 11 msec and not a msec less. :D
  • Packaged common binary for 10.7.5 + 10.8.x, as suggested in post #39.

Edit [March 22 2013]: Release 1.1.3.

  • Prevent instant-wakeup and spontaneous reboot on ASM1042.
  • Eliminated some race conditions on power-state and port-status changes that may cause KPs.

Edit [March 19 2013]: Release 1.1.

  • Made suspend/resume code safer from KPs.
  • Fixed an issue with use of shared pin interrupt.
  • Added diagnostic counters for some errors. These are printed by 'xhcdump running' if non-zero.

Edit [March 17 2013]: Uploaded 1.1a4 with

  • Fix for xHC that lack 64-bit physical-addressing (ASM1042)
  • Prints some more information in xhcdump caps/running
  • Added kernel flag '-gux_nomsi' to force use of pin interrupt
  • 'xhcdump options' shows kernel flags supported by kext

Edit [March 11 2013]: Uploaded 1.1a3 with

  • Added code to discard spurious events that are a likely cause of stalls described in post #10.
  • Made error handling of events more robust and fixed some minor bugs in processing of transfers.

Edit [March 8 2013]: Uploaded 1.1a2 with code added to take ownership of xHC from bios.


Edited by Zenith432, 25 October 2013 - 07:13 AM.


#2
DrBrains

DrBrains

    InsanelyMac Protégé

  • Members
  • Pip
  • 6 posts
Sorry to be the first to report a not working. Acer S3 intel i3 with Intel Series 7 chipset. OSX 10.8.2 stock kext did not work, but was reporting usb 3.0. With your kext it shows both USB 3.0 and USB 2.0

Without the -gux_defer_usb2 flag I am missing the HD webcam showing up in System Information. Plugging in a usb 3.0 device into the usb port "stalls" the system for about 15 seconds. It comes back without anything showing as connected. Plugin a usb 2.0 device does work since it is deferred to the USB 2.0 kext from the stock kext. Without the "defer" flag, usb 2.0 doesn't show up either.

I'm sure it is a strange combination on my ultrabook, I had problems with video as well since on a Series 7 OSX expects intel 4000HD and not the 3000HD. I had no luck with other kext before.

#3
Zenith432

Zenith432

    InsanelyMac Sage

  • Developers
  • 416 posts
  • Gender:Male

Without the -gux_defer_usb2 flag I am missing the HD webcam showing up in System Information.

Ok, Thanks. A webcam is not likely to work at all as the driver does not support isoch endpoints (I mentioned this.)
As for the stall - can you run "xhcdump running" once the keyboard is responsive (and also after the 15 seconds if it's not the same time.) and PM me the result (or post.) It contains a dump of the state of the ports. Also, "xhcdump caps" could help (shows the chip caps.)

#4
DrBrains

DrBrains

    InsanelyMac Protégé

  • Members
  • Pip
  • 6 posts
As requested: the xhcdump caps and running output.

These are without any kernel flags. I assume these will give the best results.

Attached Files



#5
Zenith432

Zenith432

    InsanelyMac Sage

  • Developers
  • 416 posts
  • Gender:Male

As requested: the xhcdump caps and running output.

The dump shows that ports 1-3 are disconnected, and on port 4 there's a high-speed device that was properly reset and enabled. If that's the HD webcam you mentioned, it's just not going to work for the time-being because isoch endpoints are not supported (sorry). If it's some other device, next thing to check is "xhcdump slots" which will dump your connected devices, and then "xhcdump endpoints <slotnumber>" which shows the configured endpoints on the device.

#6
DrBrains

DrBrains

    InsanelyMac Protégé

  • Members
  • Pip
  • 6 posts
I attached 3 screen dumps:

First shot is how I am running without your Kext
Second shot is after installing your kext with Kext Helper B7 (before reboot)
Third shot is after reboot and your kext installed.

There is no change in any of the xhcdump output before or after I plug in a USB device

Attached Files



#7
iFIRE

iFIRE

    InsanelyMacaholic

  • Moderators
  • 3,769 posts
  • Gender:Male
  • Location:Bcn-Spain
Kext Helper B7 !!!!! :stretcher: :D

#8
Zenith432

Zenith432

    InsanelyMac Sage

  • Developers
  • 416 posts
  • Gender:Male

I attached 3 screen dumps:

The kext I attached in post #1, does not support webcams or any other USB device that uses real-time audio or video streaming. Such devices use isoch endpoints.
I plan to add isoch support, but it requires some work, so will take time. If the cam is all you need a driver for, use AppleUSBEHCI.kext (which I assume is active in screenshot #1, although the shot doesn't show it.)
The kext does support bulk and interrupt endpoints, which includes things like disk drives, mice, keyboard, printers, probably digital cameras. Especially, USB3 ports are used for superspeed disk drives.
The reason that the camera info shows up in shot #2 is because that's obtained through the device's control endpoint. Once the OS finds a specific driver for your camera (assuming you have one), it tries to configure the isoch endpoint and fails...
The only curious part is why it doesn't show up at all after reboot. That could be because the cam driver soft-ejects the camera after several attempts to configure it or a timeout. I don't see the point in speculating why a device that can't work anyhow sometimes shows up and sometimes doesn't. If you have a device that's supposed to work with this kext (see above), and it doesn't show up - that's a problem.

I tried my own webcam with my kext, and it shows up in System Info both before and after boot, but I don't have an OS X driver for it, so it never gets configured (not even with AppleUSBEHCI.)

Update: I notice another possible reason why no devices are showing up after boot - according to caps.txt you posted, USB legacy is enabled on the xHC and it's owned by the bios. This is a known issue with AppleUSBXHCI too. If you could verify for me that no device works on boot, I'll add some code to take ownership of the xHC from the bios, and we'll see if that fixes the problem.

Edited by Zenith432, 07 March 2013 - 10:27 PM.


#9
Zenith432

Zenith432

    InsanelyMac Sage

  • Developers
  • 416 posts
  • Gender:Male
Dr. Brains: I added code to take ownership from the bios - uploaded v1.1.a2 (in post #1.)

I hope this fixes the problem with no device showing up after boot.

webcam should still not work due to isoch. One workaround for this is to boot with "-gux_defer_usb2". This switches the USB2 ports to EHCI, where isoch is supported. You should still be able to use superspeed devices with the kext that show up under the superspeed hub.

Thanks for helping me figure this out.

Edited by Zenith432, 08 March 2013 - 11:59 AM.


#10
DrBrains

DrBrains

    InsanelyMac Protégé

  • Members
  • Pip
  • 6 posts
Hi,

there is a lot of improvement with the new version. My USB 3.0 external harddrive gets detected and shows under Super Speed. No more system stalls when inserting the device.

Copying data over from external to internal drive does show something funny: It looks like it is reading a block of data, then stops, reads a block again (blocks as in around 64mb at a time). This is by looking at the progress bar during copy and the drive activity led on the external drive.

Copying the same file under windows 7 (x64 home premium with usb 3.0 driver) look more smooth, and the activity light continues flashing without "pause".

the xhcdump runnning and caps didn't change.

Edit: I did some benchmarks and this shows a transferspeed of around 43MB/s. This could be the HDD inself not the USB 3.0 host/kext. I will try tomorrow with a different HDD. Windows benchmark show the same drive around 45MB/s (different benchmark software, so not really fair to compare 1 to 1)

Attached Files



#11
Onixs

Onixs

    Since 2007

  • Members
  • PipPipPipPipPipPipPip
  • 706 posts
  • Gender:Male
Zenith432

I tried compiling it...

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Kernel.framework/Headers/IOKit/usb/USB.h:32:14: 'IOKit/usb/IOUSBPriv.h' file not found

#12
Zenith432

Zenith432

    InsanelyMac Sage

  • Developers
  • 416 posts
  • Gender:Male
rals2007: Get IOUSBPriv.h from here and copy it under Kernel.framework/Headers/IOKit/usb in the SDK you're compiling with.

#13
Philz

Philz

    InsanelyMac Protégé

  • Members
  • PipPip
  • 51 posts
So is this better than you patched method? (http://www.insanelym...82/page__st__60)

I'm only now in need of USB3 with my ASUS Maximus IV GENEZ/GEN3 board and trying to find the best way to do so. It uses Asmedia chipset for the two ports (and two by front panel connector).

Back when I originally built the system the methods of getting it to work-along with sleep and other things-was a fiasco... So which of these methods is best zenith? I want to incorporate whatever solution into a writeup of the board!

Thanks a million-
Phil

#14
Onixs

Onixs

    Since 2007

  • Members
  • PipPipPipPipPipPipPip
  • 706 posts
  • Gender:Male
Hi

Is there a possibility you can also build one for SL.

Thanks!

#15
Zenith432

Zenith432

    InsanelyMac Sage

  • Developers
  • 416 posts
  • Gender:Male

Is there a possibility you can also build one for SL.

No. SL IOUSBFamily has no support for superspeed devices. The layout of base class IOUSBControllerV3 is older, and GenericUSBXHCI will crash-n-burn if loaded. If fact, I'm not certain which versions of Lion run this kext. I'm pretty sure 10.7.5 does, but don't know about earlier ones.

DrBrains: for the stalls you describe in post #10, try updated build 1.1a3 in post #1.

#16
DrBrains

DrBrains

    InsanelyMac Protégé

  • Members
  • Pip
  • 6 posts
I installed 1.1a3 version. Best version until now. It improved benchmark transfer by about 3MB/s on my test harddrive to 87MB/s (WD5000BPVT)

Didn't notice any stalls.

#17
nai22

nai22

    InsanelyMac Protégé

  • Members
  • Pip
  • 36 posts
what a wonderful kext, all freezing problems on device plugin gone. thank you so much. speed is great on lion 10.7.5. lacie bye bye :thumbsup_anim:

#18
shiecldk

shiecldk

    InsanelyMac Geek

  • Members
  • PipPipPipPip
  • 222 posts
  • Gender:Male
  • Location:Taiwan
Good work! :thumbsup_anim: You're awesome...

But be careful about tonymac... :P

#19
nai22

nai22

    InsanelyMac Protégé

  • Members
  • Pip
  • 36 posts

Good work! :thumbsup_anim: You're awesome...

But be careful about tonymac... :P


hahaha thats true, tonymac steal other hard work without asking for their permission

#20
Philz

Philz

    InsanelyMac Protégé

  • Members
  • PipPip
  • 51 posts
I'm getting nothing, finally got around to trying this, but not on 10.8.2. Rather the 10.8.3 that just got released, I dumped Caps/Running to a file if that helps but it's not recognizing anything and NOTHING in Console.app. It shows up in system profiler but no devices when plugged in...

It's ASmedia from what I know...

Phil

Attached Files

  • Attached File  Dump.rtf   4.86KB   30 downloads







6 user(s) are reading this topic

1 members, 5 guests, 0 anonymous users


© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy