hlh-restart/rtsx

freebsd 13.1 issues on THINKPAD x250

Closed this issue · 15 comments

Computer description

THINKPAD X250

Hardware description

The output of 
` pciconf -lvb rtsx0 `
`rtsx0@pci0:2:0:0:	class=0xff0000 rev=0x01 hdr=0x00 vendor=0x10ec device=0x5227 subvendor=0x17aa subdevice=0x2226
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS5227 PCI Express Card Reader'
    bar   [10] = type Memory, range 32, base 0xf1100000, size 4096, enabled`
and
` sysctl dev.rtsx 
dev.rtsx.0.write_count: 0
dev.rtsx.0.read_count: 92
dev.rtsx.0.debug_mask: 0
dev.rtsx.0.force_timing: 0
dev.rtsx.0.inversion: 0
dev.rtsx.0.read_only: 1
dev.rtsx.0.timeout_cmd: 1
dev.rtsx.0.timeout_io: 10
dev.rtsx.0.%parent: pci1
dev.rtsx.0.%pnpinfo: vendor=0x10ec device=0x5227 subvendor=0x17aa subdevice=0x2226 class=0xff0000
dev.rtsx.0.%location: slot=0 function=0 dbsf=pci0:2:0:0
dev.rtsx.0.%driver: rtsx
dev.rtsx.0.%desc: 2.1d Realtek RTS5227 PCIe MMC/SD Card Reader
dev.rtsx.%parent: `

FreeBSD version
13.1 BETA1

The output of ` uname -a `
`FreeBSD x250 13.1-BETA1 FreeBSD 13.1-BETA1 #0 releng/13.1-n249974-ad329796bdb: Thu Mar 10 02:30:25 UTC 2022     root@releng3.nyi.freebsd.org:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64`

Describe the bug

Trying to mount SDCARD fails and after sleep it comes very slow and gives timeout error

Console messages

The output of `dmesg | egrep "rtsx0|mmc0|mmcsd0" `
`rtsx0: <2.1d Realtek RTS5227 PCIe MMC/SD Card Reader> mem 0xf1100000-0xf1100fff at device 0.0 on pci1
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
rtsx0: A card is detected
mmc0: <MMC/SD bus> on rtsx0
mmcsd0: 62GB <SDHC SD64G 6.0 SN DA7B8E1C MFG 06/2019 by 39 PH> (read-only) at mmc0 50.0MHz/4bit/2048-block
rtsx0: Suspend
rtsx0: Resume
rtsx0: Controller timeout for CMD0
rtsx0: Controller timeout for CMD0
rtsx0: Controller timeout for CMD0
rtsx0: Controller timeout for CMD0
rtsx0: Controller timeout for CMD8
rtsx0: Controller timeout for CMD8
rtsx0: Controller timeout for CMD8
rtsx0: Controller timeout for CMD8
rtsx0: Controller timeout for CMD55
rtsx0: Controller timeout for CMD55
rtsx0: Controller timeout for CMD55
rtsx0: Controller timeout for CMD55
rtsx0: Controller timeout for CMD1
rtsx0: Controller timeout for CMD1
rtsx0: Controller timeout for CMD1
rtsx0: Controller timeout for CMD1
mmc0: No compatible cards found on bus`

now after lsblk it is not visible any more

 lsblk
DEVICE         MAJ:MIN SIZE TYPE                                          LABEL MOUNT
ada0             0:93  447G GPT                                               - -
  <FREE>         -:-   1.0M -                                                 - -
  ada0p1         0:96  100M efi                                         gpt/EFI /boot/efi
  ada0p2         0:97   16M ms-reserved        gpt/Microsoft%20reserved%20partition -
  ada0p3         0:98  300G ms-basic-data          gpt/Basic%20data%20partition -
  ada0p4         0:99  509M ms-recovery                                       - -
  ada0p5         0:100  39G freebsd-ufs                                       - /
  ada0p6         0:101 8.0G freebsd-swap                                      - SWAP
  ada0p7         0:102 8.0G linux-swap                                        - -
  ada0p8         0:103  92G linux-data                                        - -

can you please help me with this
thank

The problem seems to be due to a suspend/resume. I try it on my on Acer Aspire E 15 E5-576-77W6 with
a RTL8411B and is working under 13.1-PRERELEASE. I know this test is not of real help for you. Maybe the suspend/resume must me completed for a RTS5227.
If you have no filesystem mounted on /dev/mmcsd0?? can you try to remove and reinsert the SD card after resume.
Note; your card is in read-only mode - see rtsx(4) in the BUG entry. (if you mount a filesystem, it must be mounted in read-only mode).

I have tried to
1 ) switch the read only on and off
2 ) tried to insert card after resume and remove before suspend
3 ) even if enabled inversion the timeout is gone but the card never mounts

I am lost and cannot use freebsd now as I use the SD CARD as a storage for files across multi boot system

Reinsert card does nothing only a reboot

Did the driver work correctly in a previous version of FreeBSD?
The read-only switch can be set to off?
After a reboot, the filesystem can be mounted? (before any suspend°
I think that the inversion is not needed in your case.

To add the possibility of quick testing:
If you are using the GENERIC kernel, comment for now the line:
#---device rtsx

Rebuild and reinstall kernel:
rm -r /usr/obj/usr/src/amd64.amd64/sys/GENERIC
cd /usr/src
make kernel
and reboot

In a working directory, e.g.:
cd ~
git clone -b master https://github.com/hlh-restart/rtsx
cd rtsx
git patch </tmp/rtsx.txt
make
cp rtsx.ko /boot/kernel
kldload rtsx

and test

rtsx.txt

Did the driver work correctly in a previous version of FreeBSD?
The read-only switch can be set to off?
After a reboot, the filesystem can be mounted? (before any suspend°
I think that the inversion is not needed in your case.

No actually this is my third trial to move to BSD on my laptop but fails
When I tied 11 and 12 before when 12 was current my laptop was not even come out of sleep after install rtsx

After a fresh boot the volume mounts successfully using ntfs-3g
And stable until a zzz is initiated

To add the possibility of quick testing:
If you are using the GENERIC kernel, comment for now the line:
#---device rtsx

Rebuild and reinstall kernel:
rm -r /usr/obj/usr/src/amd64.amd64/sys/GENERIC
cd /usr/src
make kernel
and reboot

In a working directory, e.g.:
cd ~
git clone -b master https://github.com/hlh-restart/rtsx
cd rtsx
git patch </tmp/rtsx.txt
make
cp rtsx.ko /boot/kernel
kldload rtsx

and test

rtsx.txt

Ok as soon I get back to my laptop I would happily try that
Thank you for your effort

SOLVED 👍
thank you .. can you please add some sysctl to activate this fix ondemand ?

SOLVED +1 thank you .. can you please add some sysctl to activate this fix ondemand ?

I am confused, I receive this mail:

I have just finished your instrucions

1. now when I boot its detected and i can mount successfully
2. when zzz and resume the delay still there and timeout messages
3. the only differnce is that now i can kldunload and kldload rtsx and no kernel panic any more and it works only after that before I had to reboot

the only issue now is that it delays to resume because of timeout messages and i have to reload rtsx module so the device being detected again

And now you say that it is solved :-o

SOLVED +1 thank you .. can you please add some sysctl to activate this fix ondemand ?

I am confused, I receive this mail:

I have just finished your instrucions

1. now when I boot its detected and i can mount successfully
2. when zzz and resume the delay still there and timeout messages
3. the only differnce is that now i can kldunload and kldload rtsx and no kernel panic any more and it works only after that before I had to reboot

the only issue now is that it delays to resume because of timeout messages and i have to reload rtsx module so the device being detected again

And now you say that it is solved :-o

sorry for that I did make a mistake and loded the modules rtsx instead of kernel rtsx so it was the same but I second looked and found out I was still loading the old ko
My great respect to you

can you please add this code to the main branch and if need it can be disables/enabled by user through sysctl ?

I have no commit right. I will ask someone to push this update but I'm not sure it will be accepted because we are near the release date...
Anyway I will update the github and ask to update the port sysutils/rtsx-kmod which is compatible with 13, 12 and 11.
Happy to be helpful

The update has been committed to stable/13 and releng/13.1.

I think there is another issue but sure its related or not but if the sd card is mounted and the laptop ener sleep mode then X server will crash but if its not it wont crash
i am using automountd .. may be this fix by init the device might causes this issue ? it there something I could do !
thanks

I think there is another issue but sure its related or not but if the sd card is mounted and the laptop enter sleep mode then X server will crash but if its not it wont crash

I am not used to automount...

If you mount the SD card with automount, can you test without automount and mounting the SD card manually.

I did diasbled SDCARD from BIOS and it is not related .. it was DRM KMOD issue and was fixed by updating to drm-devel-kmod
sorry for disturbance.

No problem. Better so!