AHCI mode not restored during sleep-wakeup cycle
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mactel Support |
In Progress
|
Undecided
|
Bernhard Froemel |
Bug Description
The SATA controller operates by default in IDE mode and there is no known EFI setting to override this behavior. Fortunately, it can be put into AHCI mode before the Linux kernel is booted (e.g. by Grub2 *) ).
SSD disks perform much better in AHCI mode. On my laptop, both Intel SSD 320 and a Cruzial RealSSD C300 performed great in the beginning, but system responsiveness degraded soon to a point where system load was around 6 to 7 during updates (apt-get dist-upgrade) and second long freezes during normal work (e.g. browsing, responding to emails, heck - even when using vim in a terminal! ...).
Unfortunately there is a drawback when putting the SATA controller into AHCI mode: AHCI is not restored during sleep-wakeup cycles and thus the system crashes badly after wakeup, because it suddently finds only an IDE controller.
We need to patch (e.g. the SATA driver?) and check which mode the controller had been in, before the laptop was sent to sleep and restore the previous mode.
*) How to put the SATA controller into AHCI mode [1]:
MBP 6,2 (or any other 5 series/3400 series chipset based MBP)
put this line before 'set root=...':
setpci -d 8086:3b28 90.b=60
(that command sets bit 5 and 6 on register 0x90 -- lookup Intel document number 322169 for details)
Greg White (gwhite-kupulau) wrote : | #1 |
Bernhard Froemel (froemel) wrote : | #2 |
Great!
Could you please post your patch or link to it?
Greg White (gwhite-kupulau) wrote : | #3 |
This is in drivers/
static bool mbp_force_ahci;
module_
MODULE_
static bool quirk_mbp_
{
printk(KERN_INFO "Quirking ahci device %04x:%04x\n", pdev->vendor, pdev->device);
pci_write_
pdev->class = PCI_CLASS_
// pci_write_
pci_write_
pci_write_
/* The PCI device ID will have been changed */
pci_read_
printk(KERN_DEBUG "ICH AHCI quirk: SATA AHCI controller has device ID %04x:%04x\n", pdev->vendor, pdev->device);
return false;
}
static void quirk_mbp_
{
int ret = 0;
if (!mbp_force_ahci)
return;
if (quirk_
return; /* nothing to do */
/* Try to allocate the resource on BAR 5.
* If we have a bad alignment, don't even try,
* thus neatly avoiding a scary warning.
*/
if (pci_resource_
ret = pci_assign_
if (!ret) {
printk (KERN_INFO "Quirked ICH SATA controller to AHCI mode\n");
return;
}
mbp_force_ahci = 0;
printk (KERN_ERR "MBP ICH AHCI quirk: pci_assign_resource returned %d\n", ret);
}
/* On resume, the device will have been reset to IDE mode, so we need to re-quirk */
static void quirk_mbp_
{
if (mbp_force_ahci && !quirk_
pci_update_
printk (KERN_INFO "Re-quirked ICH SATA controller to AHCI mode\n");
}
}
DECLARE_
DECLARE_
DECLARE_
DECLARE_
DECLARE_
DECLARE_
-------
Bernhard Froemel (froemel) wrote : | #4 |
Thanks!
> And this is in drivers/
> [...]
I see your reservation concerning the changes here... we are not going to get that upstream: there could be side-effects with other quirks.
I have a different suggestion which is hooked in a little bit earlier, but does not require changes in pci-driver.c: instead of starting to handle the "wrong" device and change it into the "correct" one, this patch will put the SATA controller into the desired mode *before* the PCI subsystem sees it.
My patch uses a kernel command parameter too, but also registers the mode of the SATA device controller during startup (e.g. if someone has set it into AHCI via grub2). Resume should be handled correctly in any case (see the comments for details).
I put this yesterday in place and tested it a few times: seems to work fine for me. It should be easy to handle the other devices for iMac 8,1 and 11,1 too - for now I tested only my MBP 6,2.
Note that the patch is nearly upstream-ready, but I want to test it a few weeks/months before actual submission.
> IIRC, earlier MBP's required a 0x40 instead of a 0x60 written to config word 0x90.
That's chipset specific. I guess 0x60 will not harm where previously 0x40 "was required" (of course it's best to look it up in the datasheets). Bit 6 is the important part (AHCI mode) - bit 5 (6 SATA ports instead of 2 on controller 1) is a suggestion from the Intel 5 series datasheet and may be reserved/unused in previous chipsets.
Changed in mactel-support: | |
assignee: | nobody → Bernhard Froemel (froemel) |
status: | New → In Progress |
Daniel Graziotin (dgraziotin) wrote : | #5 |
I am about to install Ubuntu 11.10 beta 1 on my Macbook Pro 6,2 with a Crucial C300 ssd.
I am confortable on applying patches on vanilla kernels to be used in distributions such as Slackware, but not on Ubuntu kernels (and generate the corresponding .deb files).
Can anybody please mail me with detailed instructions on how to apply this two patches (the attached one and the posted one) against the kernel sources and successfully generate and boot the kernel in Ubuntu?
I may try it either on the stable 11.04 release or the 11.10 beta 1 (which I've already downloaded). Any suggestions on which one to pick?
I may obviously report bugs and perform some tests for you!
Best Regards
Daniel Graziotin (dgraziotin) wrote : | #6 |
I think I managed to got it working:
dmesg|grep -i ahci
[ 0.000000] Kernel command line: BOOT_IMAGE=
[ 0.671966] [i5s_3400s ** FIXUP] SATA controller mode: NON AHCI (0x3c00)
[ 0.671967] [i5s_3400s ** FIXUP] Putting SATA controller into AHCI (0x3c60)
[ 1.294111] ahci 0000:00:1f.2: version 3.0
[ 1.294138] ahci 0000:00:1f.2: PCI INT B -> GSI 19 (level, low) -> IRQ 19
[ 1.294198] ahci 0000:00:1f.2: irq 41 for MSI/MSI-X
[ 1.294271] ahci 0000:00:1f.2: AHCI 0001.0300 32 slots 4 ports 3 Gbps 0x3 impl SATA mode
[ 1.294275] ahci 0000:00:1f.2: flags: 64bit ncq sntf pm led clo pio slum part ems apst
[ 1.294280] ahci 0000:00:1f.2: setting latency timer to 64
[ 1.300513] scsi0 : ahci
[ 1.300650] scsi1 : ahci
[ 1.300730] scsi2 : ahci
[ 1.300801] scsi3 : ahci
Can you confirm is using AHCI? Suspend works.
Bernhard Froemel (froemel) wrote : | #7 |
> Can anybody please mail me with detailed instructions on how to
> apply this two patches (the attached one and the posted one)
Please only apply one of the patches (either Greg's or mine).
Concerning compiling & packaging:
https:/
> [ 0.671966] [i5s_3400s ** FIXUP] SATA controller mode: NON AHCI (0x3c00)
> [ 0.671967] [i5s_3400s ** FIXUP] Putting SATA controller into AHCI (0x3c60)
Yes looking good. Note that there was an issue with my patch:
http://
The issue should not be a problem as long as you use AHCI (but will probably result in a crash if you use IDE and do a standby/resume cycle).
I'll update the patch here. Unfortunately, people on the linux-ide list don't seem too happy about the patch, although there are no other requests to revise it.
> Can you confirm is using AHCI? Suspend works.
Yes, the controller is in AHCI mode now. You can easily confirm by:
# lspci | grep AHCI
Bernhard Froemel (froemel) wrote : | #8 |
Daniel Graziotin (dgraziotin) wrote : | #9 |
Thank you very much for your answer. I also confirm that the new patch works like a charm on 11.10 beta 1, kernel 3.0.4
Anders Rønningen (andersronningen) wrote : | #10 |
Patch still working like a charm for you guys? I'm also keen to try this out. Do anyone care to post the instructions on how to patch and apply this to the kernel on 11.10? Something like this?
apt-get install linux-source
<patch>
<compile>
put in /boot alongside the other kernels (or overwrite?)
repeat every time the kernel is updated.
Daniel Graziotin (dgraziotin) wrote : | #11 |
Here is a very well-written step-by-step guide on re-compling Ubuntu Kernel: http://
Bernhard Froemel (froemel) wrote : | #12 |
First: maybe it would be good if other people generate some heat on this thread:
http://
and ask what's missing to get that into the kernel. As soon as it's 'in' (and I am not implying that it must be my particular patch, but any patch that enables the missing functionality), we don't need to manually patch anymore ;)
> Do anyone care to post the instructions on how to patch and apply this to the kernel on 11.10?
Usually this is just a (but proceed with care - just wrote this out of my head):
sudo -s # obtain root, beware!
apt-get install linux-source kernel-package
cd /usr/src/
cp /boot/config-<your current kernel config> ./.config
make oldconfig
cat /tmp/i5s_
make-kpkg --initrd --append-to-version c1 kernel_image
(that append-to-version stuff is just useful to easier distinguish the kernel from other (default distribution) kernels).
After make-kpkg finishes, the linux-image-*.deb is ready in the parent directory and can be installed by dpkg -i <deb file>.
More deatils: https:/
Tomodachi (tomodachi) wrote : | #13 |
why just not boot your computers into efi mode?
then the controller is in AHCI mode by default
mamo@xerxes:
[ 1.324986] ahci 0000:00:0b.0: AHCI 0001.0200 32 slots 6 ports 3 Gbps 0x3 impl SATA mode
Bernhard Froemel (froemel) wrote : | #14 |
@Tomodachi: What model do you have? I use a MBP 6,2 and there pure EFI has problems on Linux: At least one year ago, there was no drivers from Nvidia that supported the graphics adapter on systems in EFI mode.. although it *seems* to be only a small problem: http://
Alex Murray (alexmurray) wrote : | #15 |
@Bernhard - actually the problem is that on the MBP5x, 6,x and 7,x the backlight is controlled via the gmux so a new driver is needed - I've updated the existing apple-bl driver to support this and it is available in my ppa https:/
Anders Rønningen (andersronningen) wrote : | #16 |
Does all of this put together mean that if we run in efi mode and have the latest apple-bl driver from alexmurray things should work well (including suspend/wakeup)?
Pedro Nariyoshi (pedro-nariyoshi) wrote : | #17 |
@Anders: I don't think so, I have a MBP 8,1 and booting in EFI (with grub2-efi) does not help me to get AHCI mode on, I can force it using the 'setpci' on grub (actually I have a script that puts it on every linux entry everytime I do a update-grub). Unfortunately, after suspend, it still goes back to ata mode (actually, I'm not sure what happens, the rootfilesystem simply becomes unaccessible, but I guess that's what's happening). I've disabled AHCI for now (or rather, haven't enabled it), but I do hope the patch gets merged into mainline kernel.
PS.: I'm running precise x64
Bernhard Froemel (froemel) wrote : | #18 |
Sorry for getting back to this so late.
@Alex: works great. I am using EFI mode and mainly the Intel graphics adapter on my MBP6,2 for about 3 months now.
@Anders: at least for 6,x MBPs.
@Pedro: thats bad -- seems like earlier firmware/models default to AHCI when booted in pure EFI and newer don't. To confirm this, could you please verify that you're really in pure EFI mode?
e.g.: load efivars (modprobe efivars) and look for /sys/firmware/
or look for EFI range messages in your kernel log (dmesg):
> NX (Execute Disable) protection: active
> EFI v1.10 by Apple
> ACPI=0x8b70e000 ACPI 2.0=0x8b70e014 SMBIOS=0x8b674000
> Kernel-defined memdesc doesn't match the one from EFI!
> EFI: mem00: type=7, attr=0xf, range=[
> EFI: mem01: type=0, attr=0xf, range=[
> EFI: mem02: type=10, attr=0xf, range=[
> ...
> but I do hope the patch gets merged into mainline kernel.
My hopes aren't too high. I haven't heard anything from the maintainer and that usually means: no, sorry.
Pedro Nariyoshi (pedro-nariyoshi) wrote : | #19 |
@Bernard: After I load the efivars module (which gives no erros), then I do a "$lsmod | grep efivars", but get nothing. Also I can't find the /sys/firmware/efi folder. "dmesg | tail" gives me nothing special either. Weird, I just assumed since I was using grub-efi, I would be in EFI mode. Any idea what I might be doing wrong? (I'm using refit and grub-efi-amd64)
About the patch, seems pretty straight-forwards. Just adds a booting parameter. Even though it's a "dirty fix", seems reasonable to me to add it.
Pedro Nariyoshi (pedro-nariyoshi) wrote : | #20 |
@Bernard: You were right, I was not in EFI mode. I've followed http://
Pedro Nariyoshi (pedro-nariyoshi) wrote : | #21 |
I've checked what does update-grub do, and it's just a bash script that calls grub-mkconfig. So I guess I'll just modify update-grub to change the folder.
analogue (analogue-yahoo) wrote : | #22 |
Have any of the patches that fix this made it upstream yet?
Pedro Nariyoshi (pedro-nariyoshi) wrote : | #23 |
Hey Analogue,
The easiest way to solve this is to install grub-efi instead of grub-pc. There is a bunch of stuff about efi that I don't understand very well, but my advice is:
-Use Disk Utility to partition your drive (apparently OSX doesn't like other OSes touching the partition tables)
-Install Ubuntu using grub-efi option. If you are doing this on top of a existing Ubuntu installation, mount the EFI partition to /boot/efi and install grub-efi.
-When booted through EFI, the system will automatically use AHCI.
If you don't want to use EFI, I think there's no solution for it.
analogue (analogue-yahoo) wrote : | #24 |
Pedro,
I'm using refit (http://
Pedro Nariyoshi (pedro-nariyoshi) wrote : Re: [Bug 817017] Re: AHCI mode not restored during sleep-wakeup cycle | #25 |
Yes,
I originally used refit as well. It has one problem. It will not detect
grub-efi as Linux, it will only show a diamond shaped symbol indicating it
as a EFI bootloader.
I currently use refind (http://
You should check it out.
(Sometimes Grub might set itself to be run before refind/refit. In this
case, you can boot in OSX and "bless" it (just as if you were installing
refit again).
Pedro Nariyoshi
On Wed, Jan 30, 2013 at 1:08 PM, analogue <email address hidden> wrote:
> Pedro,
>
> I'm using refit (http://
> with grub-efi?
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https:/
>
> Title:
> AHCI mode not restored during sleep-wakeup cycle
>
> Status in Mactel Support:
> In Progress
>
> Bug description:
> The SATA controller operates by default in IDE mode and there is no
> known EFI setting to override this behavior. Fortunately, it can be put
> into AHCI mode before the Linux kernel is booted (e.g. by Grub2 *) ).
> SSD disks perform much better in AHCI mode. On my laptop, both Intel SSD
> 320 and a Cruzial RealSSD C300 performed great in the beginning, but system
> responsiveness degraded soon to a point where system load was around 6 to 7
> during updates (apt-get dist-upgrade) and second long freezes during normal
> work (e.g. browsing, responding to emails, heck - even when using vim in a
> terminal! ...).
>
> Unfortunately there is a drawback when putting the SATA controller into
> AHCI mode: AHCI is not restored during sleep-wakeup cycles and thus the
> system crashes badly after wakeup, because it suddently finds only an IDE
> controller.
> We need to patch (e.g. the SATA driver?) and check which mode the
> controller had been in, before the laptop was sent to sleep and restore the
> previous mode.
>
> *) How to put the SATA controller into AHCI mode [1]:
> MBP 6,2 (or any other 5 series/3400 series chipset based MBP)
> put this line before 'set root=...':
> setpci -d 8086:3b28 90.b=60
> (that command sets bit 5 and 6 on register 0x90 -- lookup Intel document
> number 322169 for details)
>
> [1] http://
>
> To manage notifications about this bug go to:
> https:/
>
Adam Dingle (adam-yorba) wrote : | #26 |
Pedro, you wrote
> Install Ubuntu using grub-efi option. If you are doing this on top of a existing Ubuntu installation, mount the EFI partition to /boot/efi and install grub-efi.
Could you explain in a little more detail how to do this, or point to a Web page that explains how?
Pedro Nariyoshi (pedro-nariyoshi) wrote : | #27 |
Sure, I can't point out to a single website since I found out about this more or less by trial and error. The ArchWiki is a good source however.
First, I mounted my efi partition at /boot/efi. This can be achieved my using a line like this on /etc/fstab:
UUID=70D6-1701 /boot/efi vfat defaults 0 0
(substitute 70D6-1701 with the UUID of your efi partition, you can check it with "sudo blkid | grep EFI" )
(If you want to just mount it once, you can run "sudo mount /dev/sdXX /boot/efi", where /dev/sdXX is your efi partition)
Then I installed grub-efi:
sudo apt-get install grub-efi
(it will install the necessary efi components such as efibootmgr)
I think this will already install grub-efi to your drive, but if you want to make sure do a:
sudo grub-install /dev/sda
(warning, this will set grub as the primary boot option, if you have refit or refind installed, they will not run as default, to run them you'll have to hold the right-hand "alt-option" key during boot)
Adam Dingle (adam-yorba) wrote : | #28 |
Pedro, thanks a lot for the additional info. I do have rEFInd installed and I like it. Is it not possible to use grub-efi and also have rEFInd run as default?
Pedro Nariyoshi (pedro-nariyoshi) wrote : | #29 |
Yes, it is. But you will have to "rebless" it. (Set it as default, otherwise, it will still be installed, but grub will load automatically instead)
To do this, boot on OSX and set refind as default again. I usually run the install.sh script after that, but you can try something like:
sudo bless --setBoot --folder /efi/refind --file /efi/refind/
(More info here: http://
Adam Dingle (adam-yorba) wrote : | #30 |
Pedro, thanks again for this helpful information.
The good news: I was able to get my machine (a MacBookPro9,1) to boot using EFI. Rather than modifying an existing install, I simply reinstalled Ubuntu using the 64-bit non-Mac live image, which is able to set up an EFI install. (rEFInd can boot this image.)
The bad news: Resuming is still not working. When I attempt to resume from suspend after an EFI boot I do see my desktop background, so I believe that AHCI mode is active, but the system is unresponsive. I filed a separate bug for this at bug #1186818.
Phil Colbourn (philcolbourn) wrote : | #31 |
Is this already fixed in 3.8.0-25 (and possibly earlier versions)?
I have a macbookpro2,1 and macbookpro4,1 and once AHCI mode is enabled I can sleep/resume fine - so far.
I enable AHCI mode using setpci -s 0:1f.2 90.b=40 in grub or via a patched MBR called patchedcode.bin (some say to use 60 but I now think that 40 is correct value based on Intel ICH7/8 datasheets).
http://
Pedro Nariyoshi (pedro-nariyoshi) wrote : | #32 |
What does "dmesg | grep ahci" show?
I don't know about using BIOS and then using setpci anymore, but it might
be fixed. I guess the only ones who can really tell are the guys who
published this patch over here.
Pedro Nariyoshi
On Sat, Jun 15, 2013 at 9:19 AM, Phil Colbourn <email address hidden>wrote:
> Is this already fixed in 3.8.0-25 (and possibly earlier versions)?
>
> I have a macbookpro2,1 and macbookpro4,1 and once AHCI mode is enabled I
> can sleep/resume fine - so far.
>
> I enable AHCI mode using setpci -s 0:1f.2 90.b=40 in grub or via a
> patched MBR called patchedcode.bin (some say to use 60 but I now think
> that 40 is correct value based on Intel ICH7/8 datasheets).
>
> http://
> hub-8-datasheet.pdf page 486.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https:/
>
> Title:
> AHCI mode not restored during sleep-wakeup cycle
>
> Status in Mactel Support:
> In Progress
>
> Bug description:
> The SATA controller operates by default in IDE mode and there is no
> known EFI setting to override this behavior. Fortunately, it can be put
> into AHCI mode before the Linux kernel is booted (e.g. by Grub2 *) ).
> SSD disks perform much better in AHCI mode. On my laptop, both Intel SSD
> 320 and a Cruzial RealSSD C300 performed great in the beginning, but system
> responsiveness degraded soon to a point where system load was around 6 to 7
> during updates (apt-get dist-upgrade) and second long freezes during normal
> work (e.g. browsing, responding to emails, heck - even when using vim in a
> terminal! ...).
>
> Unfortunately there is a drawback when putting the SATA controller into
> AHCI mode: AHCI is not restored during sleep-wakeup cycles and thus the
> system crashes badly after wakeup, because it suddently finds only an IDE
> controller.
> We need to patch (e.g. the SATA driver?) and check which mode the
> controller had been in, before the laptop was sent to sleep and restore the
> previous mode.
>
> *) How to put the SATA controller into AHCI mode [1]:
> MBP 6,2 (or any other 5 series/3400 series chipset based MBP)
> put this line before 'set root=...':
> setpci -d 8086:3b28 90.b=60
> (that command sets bit 5 and 6 on register 0x90 -- lookup Intel document
> number 322169 for details)
>
> [1] http://
>
> To manage notifications about this bug go to:
> https:/
>
Phil Colbourn (philcolbourn) wrote : | #33 |
$ dmesg | grep -i ahci
[ 3.446820] ahci 0000:00:1f.2: version 3.0
[ 3.446834] ahci 0000:00:1f.2: enabling device (0005 -> 0007)
[ 3.446910] ahci 0000:00:1f.2: irq 45 for MSI/MSI-X
[ 3.446973] ahci: SSS flag set, parallel bus scan disabled
[ 3.447007] ahci 0000:00:1f.2: AHCI 0001.0100 32 slots 4 ports 1.5 Gbps 0x4 impl SATA mode
[ 3.447012] ahci 0000:00:1f.2: flags: 64bit ncq ilck stag pm led clo pio slum part
[ 3.447018] ahci 0000:00:1f.2: setting latency timer to 64
[ 3.451086] scsi2 : ahci
[ 3.454794] scsi3 : ahci
[ 3.479022] scsi4 : ahci
[ 3.481944] scsi5 : ahci
[ 124.425204] ahci 0000:00:1f.2: setting latency timer to 64
Pedro Nariyoshi (pedro-nariyoshi) wrote : | #34 |
Interesting. Although I'm pretty happy with grub-efi :P
Feels safer and more elegant than setting pci parameters directly :9
Should we mark it as fixed?
Dominik (dominalien) wrote : | #35 |
This is definitely not fixed. I wish I could run the MBP 6,2 with EFI, but then the proprietary driver for the nvidia card doesn't work, so that's not an option (I play games).
I just tested again (seeing what Phil wrote in #31 above), booting with the setpci option and after resuming the computer spat out a ton of ATA errors and froze. Ubuntu 14.04, 3.13 kernel.
I have kernel patches which handle this - I added a quirk to put it into AHCI mode, then requirk on resume.
This required a somewhat scary patch to pci_driver.c, to make sure that quirks were fired *before* device initialization to work right.