Suspend issue on macbook air 6.2

kernel
suspend

#1

Suspend is not working properly on a macbook air 6.2.

When I suspend it will try to suspend but wakes up immediately.

I have tried “echo XHC1 > /proc/acpi/wakeup”. No luck. I disabled everything i /proc/acpi/wakeup. But I think it is related to device usb2 as output from journalctl shows below:

dec 31 15:24:09 mba kernel: dpm_run_callback(): usb_dev_suspend+0x0/0x10 returns -16
dec 31 15:24:09 mba kernel: PM: Device usb2 failed to suspend async: error -16
dec 31 15:24:09 mba kernel: sd 0:0:0:0: [sda] Synchronizing SCSI cache
dec 31 15:24:09 mba kernel: sd 0:0:0:0: [sda] Stopping disk
dec 31 15:24:09 mba kernel: PM: Some devices failed to suspend, or early wake event detected
dec 31 15:24:09 mba kernel: sd 0:0:0:0: [sda] Starting disk
dec 31 15:24:09 mba kernel: OOM killer enabled.
dec 31 15:24:09 mba systemd-sleep[3027]: Failed to write /sys/power/state: Device or resource busy

It happens with every kernel I tried.

Any ideas? Thanks in advance.


#2

The problem is not present with kernel 4.18.20-1.

But with 4.19.13-1 and 4.20.0-1 the problems is there.


#5

The problem is still there with 4.20.1 and 4.14.92 and 4.19.14 :frowning_face:


#6

Please post:

inxi -Fxxxz

lsmod

What USB devices are you using? have you tried disconnecting all USB peripherals before suspending.

Perhaps try the 4.14 real time kernel.

Try this before suspending:

sudo modprobe -r xhci_hcd xhci_pci

Then test if you can suspend.


#7
~ $ inxi -Fxxxz
System:    Host: mba Kernel: 4.20.1-1-MANJARO x86_64 bits: 64 compiler: gcc v: 8.2.1 Desktop: Gnome 3.30.2 wm: gnome-shell 
           dm: GDM 3.30.2 Distro: Manjaro Linux 
Machine:   Type: Laptop System: Apple product: MacBookAir6,2 v: 1.0 serial: <filter> Chassis: type: 10 v: Mac-7DF21CB3ED6977E5 
           serial: <filter> 
           Mobo: Apple model: Mac-7DF21CB3ED6977E5 v: MacBookAir6,2 serial: <filter> UEFI: Apple 
           v: MBA61.88Z.0099.B26.1612221826 date: 12/22/2016 
Battery:   ID-1: BAT0 charge: 34.2 Wh condition: 44.7/54.3 Wh (82%) volts: 7.9/7.6 model: SMP bq20z451 type: Li-ion 
           serial: N/A status: Discharging cycles: 710 
CPU:       Topology: Dual Core model: Intel Core i5-4250U bits: 64 type: MT MCP arch: Haswell rev: 1 L2 cache: 3072 KiB 
           flags: lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx bogomips: 15207 
           Speed: 799 MHz min/max: 800/2600 MHz Core speeds (MHz): 1: 800 2: 800 3: 800 4: 803 
Graphics:  Device-1: Intel Haswell-ULT Integrated Graphics vendor: Apple driver: i915 v: kernel bus ID: 00:02.0 
           chip ID: 8086:0a26 
           Display: x11 server: X.org 1.20.3 driver: intel unloaded: modesetting alternate: fbdev,vesa compositor: gnome-shell 
           resolution: <xdpyinfo missing> 
           OpenGL: renderer: Mesa DRI Intel Haswell Mobile v: 4.5 Mesa 18.3.1 compat-v: 3.0 direct render: Yes 
Audio:     Device-1: Intel Haswell-ULT HD Audio vendor: Apple driver: snd_hda_intel v: kernel bus ID: 00:03.0 
           chip ID: 8086:0a0c 
           Device-2: Intel 8 Series HD Audio driver: snd_hda_intel v: kernel bus ID: 00:1b.0 chip ID: 8086:9c20 
           Device-3: Broadcom and subsidiaries 720p FaceTime HD Camera driver: bdc-pci bus ID: 02:00.0 chip ID: 14e4:1570 
           Sound Server: ALSA v: k4.20.1-1-MANJARO 
Network:   Device-1: Broadcom and subsidiaries BCM4360 802.11ac Wireless Network Adapter vendor: Apple driver: wl v: kernel 
           port: efa0 bus ID: 03:00.0 chip ID: 14e4:43a0 
           IF: wlp3s0 state: up mac: <filter> 
Drives:    Local Storage: total: 113.00 GiB used: 22.24 GiB (19.7%) 
           ID-1: /dev/sda vendor: Apple model: SSD SM0128F size: 113.00 GiB speed: 6.0 Gb/s serial: <filter> rev: EA1Q 
           scheme: GPT 
Partition: ID-1: / size: 65.25 GiB used: 22.24 GiB (34.1%) fs: ext4 dev: /dev/sda6 
           ID-2: swap-1 size: 4.10 GiB used: 0 KiB (0.0%) fs: swap dev: /dev/sda4 
Sensors:   System Temperatures: cpu: 26.7 C mobo: N/A 
           Fan Speeds (RPM): N/A 
Info:      Processes: 238 Uptime: 48m Memory: 3.79 GiB used: 1.39 GiB (36.5%) Init: systemd v: 239 Compilers: gcc: N/A 
           Shell: zsh v: 5.6.2 running in: tilda inxi: 3.0.28 
~ $ lsmod
Module                  Size  Used by
fuse                  131072  5
snd_hda_codec_hdmi     61440  1
btusb                  57344  0
btrtl                  20480  1 btusb
btbcm                  16384  1 btusb
btintel                28672  1 btusb
bluetooth             651264  5 btrtl,btintel,btbcm,btusb
intel_rapl             28672  0
input_leds             16384  0
x86_pkg_temp_thermal    20480  0
intel_powerclamp       20480  0
coretemp               20480  0
kvm_intel             245760  0
ecdh_generic           24576  1 bluetooth
i915                 2109440  18
hid_apple              16384  0
ofpart                 20480  0
wl                   6463488  0
cmdlinepart            16384  0
intel_spi_platform     16384  0
intel_spi              24576  1 intel_spi_platform
spi_nor                45056  1 intel_spi
crct10dif_pclmul       16384  1
kvmgt                  32768  0
hid_generic            16384  0
crc32_pclmul           16384  0
vfio_mdev              16384  0
iTCO_wdt               16384  0
mdev                   24576  2 kvmgt,vfio_mdev
mtd                    73728  5 cmdlinepart,intel_spi,ofpart
vfio_iommu_type1       32768  0
vfio                   36864  3 kvmgt,vfio_mdev,vfio_iommu_type1
iTCO_vendor_support    16384  1 iTCO_wdt
ghash_clmulni_intel    16384  0
kvm                   741376  2 kvmgt,kvm_intel
joydev                 28672  0
snd_hda_codec_cirrus    20480  1
snd_hda_codec_generic    90112  1 snd_hda_codec_cirrus
mousedev               24576  0
irqbypass              16384  1 kvm
i2c_algo_bit           16384  1 i915
uas                    28672  0
snd_hda_intel          49152  8
drm_kms_helper        208896  1 i915
cfg80211              778240  1 wl
snd_hda_codec         155648  4 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec_cirrus
usb_storage            73728  1 uas
aesni_intel           200704  0
aes_x86_64             20480  1 aesni_intel
applesmc               24576  0
crypto_simd            16384  1 aesni_intel
cryptd                 28672  3 crypto_simd,ghash_clmulni_intel,aesni_intel
input_polldev          20480  1 applesmc
snd_hda_core           98304  5 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda_codec_cirrus
glue_helper            16384  1 aesni_intel
drm                   499712  7 drm_kms_helper,i915
intel_cstate           16384  0
intel_uncore          135168  0
snd_hwdep              16384  1 snd_hda_codec
intel_rapl_perf        16384  0
snd_pcm               135168  4 snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda_core
thunderbolt           155648  0
intel_gtt              24576  1 i915
agpgart                53248  2 intel_gtt,drm
pcspkr                 16384  0
snd_timer              40960  1 snd_pcm
i2c_i801               36864  0
snd                   102400  23 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hwdep,snd_hda_intel,snd_hda_codec,snd_timer,snd_pcm
mei_me                 45056  0
syscopyarea            16384  1 drm_kms_helper
sysfillrect            16384  1 drm_kms_helper
usbhid                 61440  0
sysimgblt              16384  1 drm_kms_helper
fb_sys_fops            16384  1 drm_kms_helper
lpc_ich                28672  0
rfkill                 28672  6 bluetooth,cfg80211
mei                   114688  1 mei_me
bdc_pci                16384  0
soundcore              16384  1 snd
hid                   143360  3 usbhid,hid_apple,hid_generic
bcm5974                24576  0
acpi_als               20480  0
sbs                    20480  0
kfifo_buf              16384  1 acpi_als
sbshc                  16384  1 sbs
industrialio           86016  2 acpi_als,kfifo_buf
evdev                  24576  18
spi_pxa2xx_platform    32768  0
mac_hid                16384  0
apple_bl               20480  0
pcc_cpufreq            20480  0
ac                     16384  0
uinput                 20480  0
crypto_user            20480  0
ip_tables              32768  0
x_tables               49152  1 ip_tables
ext4                  749568  1
crc32c_generic         16384  0
crc16                  16384  2 bluetooth,ext4
mbcache                16384  1 ext4
jbd2                  131072  1 ext4
fscrypto               32768  1 ext4
sd_mod                 57344  3
ahci                   40960  2
libahci                40960  1 ahci
libata                282624  2 libahci,ahci
xhci_pci               20480  0
scsi_mod              258048  4 sd_mod,usb_storage,uas,libata
xhci_hcd              262144  1 xhci_pci
crc32c_intel           24576  2
~ $ sudo modprobe -r xhci_hcd xhci_pci                                                                                                                  
modprobe: FATAL: Module xhci_hcd is in use.

I’m going to try 4.14 rt.


#8

How can I disconnect all USB peripherals before suspending?

I have tried disabling everything in /proc/acpi/wakeup. No luck.


#9

The 4.14 real time kernel did not fix the issue.


#10

I meant if you were using a usb keyboard, mouse, usb hub etc etc.

You could try running this as a script before suspend:

#!/bin/bash
#reset all of USB1/2/3 ports
for i in /sys/bus/pci/drivers/[uoex]hci_hcd/*:*; do
  [ -e "$i" ] || continue
  echo "${i##*/}" > "${i%/*}/unbind"
done

#11

I meant if you were using a usb keyboard, mouse, usb hub etc etc.

I’m not using any usb peripherals.


#12

Try the script, don’t forget to make it executable.


#13

The script works. It suspends :smiley:.

But when it turns back on keyboard is not working. How can I run a script that reverse your script after suspend?


#14

That is to be expected as it is only half the script. There was no point in having you write 2 scripts if the first did not work.

I will explain what you need to do. You need to write 2 scripts and 2 systemd unit files. I will give you the basics on what you need. Here is the second part of the script.

#!/bin/bash
#reset all of USB1/2/3 ports
for i in /sys/bus/pci/drivers/[uoex]hci_hcd/*:*; do
  [ -e "$i" ] || continue
  echo "${i##*/}" > "${i%/*}/unbind"
  echo "${i##*/}" > "${i%/*}/bind"
done

The 2 scripts should be located/named:

/usr/local/sbin/usb_off.sh

/usr/local/sbin/usb_on.sh

I will post the required systemd service files after I have finished writing them.


#15

You must create two services and two scripts that will automatically stop and restart the USB bus upon suspend/resume.

Systemd suspend unit file:

/etc/systemd/system/usb-off.service

Systemd suspend service file contents:

#/etc/systemd/system/usb-off.service
#sudo systemctl enable usb-off.service
#sudo systemctl start usb-off.service
#sudo systemctl status usb-off.service
#sudo systemctl daemon-reload
[Unit]
Description=Disable USB upon suspend
Before=sleep.target
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/sbin/usb_off.sh

[Install]
WantedBy=sleep.target

Corresponding script that is to be executed before suspending:

Suspend script:

/usr/local/sbin/usb_off.sh

Suspend script contents:

#sudo nano /usr/local/sbin/usb_off.sh
#sudo chmod +x /usr/local/sbin/usb_off.sh
#!/bin/bash
#reset all of USB1/2/3 ports
for i in /sys/bus/pci/drivers/[uoex]hci_hcd/*:*; do
  [ -e "$i" ] || continue
  echo "${i##*/}" > "${i%/*}/unbind"
done

Systemd resume unit file:

/etc/systemd/system/usb-on.service

Systemd resume service file contents:

#/etc/systemd/system/usb-on.service
#sudo systemctl enable usb-on.service
#sudo systemctl start usb-on.service
#sudo systemctl status usb-on.service
#sudo systemctl daemon-reload
[Unit]
Description=Enable USB upon resume
After=suspend.target
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/sbin/usb_on.sh

[Install]
WantedBy=suspend.target

Corresponding script that is to be executed upon resume:

Resume script:

/usr/local/sbin/usb_on.sh

Resume script contents:

#sudo nano /usr/local/sbin/usb_on.sh
#sudo chmod +x /usr/local/sbin/usb_on.sh
#!/bin/bash
#reset all of USB1/2/3 ports
for i in /sys/bus/pci/drivers/[uoex]hci_hcd/*:*; do
  [ -e "$i" ] || continue
  echo "${i##*/}" > "${i%/*}/unbind"
  echo "${i##*/}" > "${i%/*}/bind"
done

Ensure both scripts are executable, then enable both services, and restart.


#16

@tbg Thank you so much for all your help.

I created the 4 files and enabled both services with “systemctl enable”. I have also tested both service with “systemctl start” and both works fine:

  • The “systemctl start usb-off.service” disables the keyboard as expected
  • The “systemctl start usb-on.service” disables it only for a very short period and then it works again.

Unfortunately when I suspend the keyboard will not start to work again when laptop resumes.


#17

That is very unfortunate, as I thought this was a very nice solution. I may be able to fix the keyboard issue by rmmoding/modprobing the correct associated modules.

Would you have time to work on this again tomorrow as I think I need a break.

Please post:

sudo systemctl status usb-on.service

#18

Of course. No hurry :-).

sudo systemctl status usb-on.service
● usb-on.service - Enable USB upon resume
   Loaded: loaded (/etc/systemd/system/usb-on.service; enabled; vendor preset: disabled)
   Active: inactive (dead)


#19

Change the resume unit to this:

#/etc/systemd/system/usb-on.service
#sudo systemctl enable usb-on.service
#sudo systemctl start usb-on.service
#sudo systemctl status usb-on.service
#sudo systemctl daemon-reload
[Unit]
Description=Enable USB upon resume
After=suspend.target
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/bin/sleep 10
ExecStart=/usr/local/sbin/usb_on.sh; rmmod hid_apple; sleep 10; modprobe hid_apple
StandardError=syslog

[Install]
WantedBy=suspend.target

Then restart.

(edited check for changes)

If that works you can reduce the sleep times.


#20

I tried it. But when I start the resume service, it fails. Systemd says “no such file or directory” (see below). But the file is there. I can run the script via the absolute path written below.

~ $ systemctl status usb-on.service                                                                                                                     master
● usb-on.service - Enable USB upon resume
   Loaded: loaded (/etc/systemd/system/usb-on.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2019-01-20 14:58:55 CET; 2min 21s ago
  Process: 1323 ExecStart=/usr/local/sbin/usb_on.sh; rmmod hid_apple; sleep 10; modprobe hid_apple (code=exited, status=203/EXEC)
  Process: 1308 ExecStartPre=/usr/bin/sleep 10 (code=exited, status=0/SUCCESS)
 Main PID: 1323 (code=exited, status=203/EXEC)

jan 20 14:58:45 mba systemd[1]: usb-on.service: Unit not needed anymore. Stopping.
jan 20 14:58:45 mba systemd[1]: usb-on.service: Failed to enqueue stop job, ignoring: Transaction is destructive.
jan 20 14:58:45 mba systemd[1]: Starting Enable USB upon resume...
jan 20 14:58:55 mba systemd[1]: usb-on.service: Unit not needed anymore. Stopping.
jan 20 14:58:55 mba systemd[1]: usb-on.service: Failed to enqueue stop job, ignoring: Transaction is destructive.
jan 20 14:58:55 mba systemd[1323]: usb-on.service: Failed to execute command: No such file or directory
jan 20 14:58:55 mba systemd[1323]: usb-on.service: Failed at step EXEC spawning /usr/local/sbin/usb_on.sh;: No such file or directory
jan 20 14:58:55 mba systemd[1]: usb-on.service: Main process exited, code=exited, status=203/EXEC
jan 20 14:58:55 mba systemd[1]: usb-on.service: Failed with result 'exit-code'.
jan 20 14:58:55 mba systemd[1]: Failed to start Enable USB upon resume.


#21

I will need you to run a few tests before we can make further progress with your keyboard issue.

Run this command before attempting a suspend:

nmcli networking off

If you could not suspend successfully the run:

nmcli networking on

Next, close all open programs before executing this command:

sudo rmmod hid_apple; sleep 5; sudo modprobe hid_apple

It is possible you may experience a freeze after this command.

Please report on all tests, and post the exact inputs and outputs of all commands, and any errors you may receive.

Have you run both USB scripts from the terminal to make sure they are both working correctly when run consecutively.

Have a USB thumb drive plugged into one of your USB ports before executing the scripts.

First, run the USB off script.

sudo /usr/local/sbin/usb_off.sh

After the script has run the thumb drive should be unmounted, and no longer be displayed in your file manager.

Next execute the USB on script:

sudo /usr/local/sbin/usb_on.sh

This script should refresh any devices on your USB bus.

Your USB thumb drive should reappear after the script is completed.

Again, please report on all tests. Post the exact inputs and outputs of all commands, and any errors you may receive.

Hopefully we can get this fixed up for you.


#22

@tbg Thank you for everything. I very much appreciate your help.

nmcli networking off

No output and suspend still not working.

sudo rmmod hid_apple; sleep 5; sudo modprobe hid_apple

No output and suspend still not working.

sudo /usr/local/sbin/usb_on.sh

The usb thumb disappears and comes back within a few seconds.

I tried

sudo /usr/local/sbin/usb_off.sh && /usr/local/sbin/usb_on.sh

but everything freezes.

Suspend still works perfectly on 4.18.20. So maybe I should just stick with this.