Bug 204521

Summary: [new driver] [request] Port rtsx from OpenBSD to FreeBSD
Product: Base System Reporter: evil.lombo
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Many People CC: Lutz.Bichler, ae, arrowd, bahlgren, btik-fbsd, chmiels, contact, danfe, dch, dirkx, driesm, emaste, flo, gljennjohn, gnikl, hlh, iain.holmes, info, jens.link, jkim, jlduran, jrmeadows, jsm, jyoung15, kamila, kidon, l.yotov, lme, lobo, ludensen, lwhsu, monwarez, nomoo, nwhitehorn, osa, probono, sergey.dyatko, sh+freebsd-bugzilla, thj, trueos, unitrunker, val, vangyzen, vishwin, zeus
Priority: --- Keywords: feature, patch
Version: CURRENT   
Hardware: Any   
OS: Any   
URL: https://lists.freebsd.org/pipermail/freebsd-questions/2015-February/264014.html
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=161719
Attachments:
Description Flags
Patch to add SD card insertion/removal
gljennjohn: maintainer-approval?
can read scr
none
dyndbg output of linux kernel driver
none
minimal can still read SCR
none
read works. write does not yet
none
add stop cmd from req and reposition sync_dma
none
Card Inserted dmesg
none
do not read BIPR to often..
none
Trace of rtsx during a vlc suspend/resume
none
commit 44ab5957e6 doesn't work (In reply to Henri Hennebert from comment #247)
none
In reply to Henri Hennebert from comment #260
none
lspci output for RTS5227 (Fujtsu H730)
none
dmesg (In reply to Henri Hennebert from comment #263) none

Description evil.lombo 2015-11-13 13:02:29 UTC
Hi,

in my quest to make FreeBSD fully operational in my laptop, I would like to know whether anyone is working on porting the OpenBSD rtsx to FreeBSD.

I have asked to Robert (https://lists.freebsd.org/pipermail/freebsd-questions/2015-February/264014.html) about its working on the module but he has not yet got the chance to start it.

If not, I'd try to develop it personally, but I have to be sure the better workflow: is it better to integrate it with sdhci/mmc modules or start it brand new?

Thanks,

Simone
Comment 1 Stefan Hagen 2018-06-14 11:39:43 UTC
Hello,

the request to port this driver came up again on freebsd-hackers again. Warner Losh gave some insight about what needs to be done to port rtsx.

https://lists.freebsd.org/pipermail/freebsd-hackers/2018-April/052520.html

This SD Card reader is built into a wide variety of Lenovo Laptops (x240 and up, t440/t540 and up, L440/L540 and up) Dell XPS Series, HP Spectre x360 and up.

Best Regards,
Stefan
Comment 2 Gleb Popov freebsd_committer freebsd_triage 2018-09-15 15:06:37 UTC
Adding myself to CC, as I also have this card reader in my notebook.

Simone, do you still plan to work on this?
Comment 3 Gleb Popov freebsd_committer freebsd_triage 2019-06-18 12:02:12 UTC
I have posted a bounty of $100 for this bug on BountySource: https://www.bountysource.com/issues/75687739-new-driver-request-port-rtsx-from-openbsd-to-freebsd

Hope this will give a spin.
Comment 4 Gleb Popov freebsd_committer freebsd_triage 2019-07-03 10:07:22 UTC
*** Bug 161719 has been marked as a duplicate of this bug. ***
Comment 5 Kamila Součková 2019-11-28 10:52:10 UTC
Started work on this: https://github.com/AnotherKamila/freebsd-rtsz . Very much WIP right now. I intend to make progress on this over the weekend, please ping me if you can help with testing.
Comment 6 Gleb Popov freebsd_committer freebsd_triage 2019-11-28 15:53:41 UTC
(In reply to Kamila Součková from comment #5)

Hi Kamilla, thanks for your interest. It worth noting that former FreeBSD member already started working on this, and it seems that he has made more progress than you. I'm not know if that means that you should abandon your work, though.
Comment 7 Kamila Součková 2019-11-28 16:06:22 UTC
(In reply to Gleb Popov from comment #6)

Hi, thank you for letting me know! Do you know who that was? I am aware of https://github.com/ruupert/rtsx/ , which seems to have been abandoned (and I am currently at the same stage, so also able to detect card presence, plus my code might be structured in a way that is more likely to be merged). Are you referring to this, or to something else?

Thanks a lot!
Comment 8 Gleb Popov freebsd_committer freebsd_triage 2019-11-28 16:10:42 UTC
(In reply to Kamila Součková from comment #7)

His name is Gary Jennejohn, here is relevant thread on the mailing list: https://lists.freebsd.org/pipermail/freebsd-hackers/2019-November/055200.html

His work is not public, but he reported that has quite a progress.
Comment 9 Henri Hennebert 2019-11-28 18:34:31 UTC
I have also a try at this problem:

https://github.com/hlh-restart/rtsx
Comment 10 Gary Jennejohn 2019-11-29 09:56:46 UTC
To hlh

I've been working on this driver for about 3 weeks.  I looked at your code and it looks quite good.  I'll give it a try and send some feedback.
Comment 11 Gary Jennejohn 2019-11-29 11:26:10 UTC
(In reply to Gary Jennejohn from comment #10)
The driver from hlh is much further along than mine.  Loading the module with a SD card plugged in actually results in MMC seeing the card and reading its capacity.  Plugging in a card after the module is loaded results in a spurious interrupt error, but that can probably be fixed without much trouble.

I had to add ``#include <sys/mutex.h>'' to get it to compile in my FreeBSD13 tree.

It doesn't work too well with my 522A and I see timeouts waiting for interrupts quite often.

In any case, my opinion is that this driver is the way forward and hlh should continue working on it.
Comment 12 Henri Hennebert 2019-11-29 12:09:44 UTC
(In reply to Gary Jennejohn from comment #11)
The detection of a new card inserted after the driver is loaded will be dealt later.

My main problem is that any read io return all 0 on timeout.
So I postpone the write problem.

I try to read the source of openbsd, netbsd and linux to no avail for now.

I almost lost...

Henri
Comment 13 Gary Jennejohn 2019-11-29 14:48:57 UTC
(In reply to hlh from comment #12)

I noticed that, immediately after loading the module, I can successfully run e.g.
dd if=/dev/mmcsd0 of=junk count=20 without errors or timeouts.  But, as you say,
the bytes are all 0x00.  Any further attempt to access the SD card results in a
CRC error.

In fact, I see LOTS of CRC errors (all RTSX_SD_CRC16_ERR) during start up.  I also see CMD7 failing quite often.

I've spent many hours looking at the Linux driver, which was written by Realtek.
There is so much special handling for each of the controllers that it almost seems hopeless to get a driver which works as well as what Linux has.

Whether the errors I see are due to pecularities of the 522a (Linux has lots of special code for this one) I can't say.
Comment 14 Gary Jennejohn 2019-11-30 11:49:24 UTC
(In reply to hlh from comment #12)

I installed OpenBSD on a sacrifical disk and it also returns all 0s when I read from the SD card.  I know there are data on the SD card because I can dump them using a USB2 multi-card reader.

Evidently, OpenBSD does not support my 522A all too well.

Hard to tell whether any errors occur because there's no debug output from the driver.  But then again, I was able to run dd multiple times without an error being reported (which may mean nothing if the driver suppresses errors).
Comment 15 Gary Jennejohn 2019-12-02 16:49:15 UTC
(In reply to Gary Jennejohn from comment #14)

I installed Debian Linux to check whether my Raltek controller really works.

The first read I did from the SD card returned all 0s.

After playing around for some time I discovered that the first megabyte (2048 sectors) was filled with 0s.  Apparently a result of the vendor formatting it with FAT32.

So, OpenBSD may also work if I run dd with skip=2048.

This might also be the reason why hlh is seeing 0s when he reads from his card.

Unfortunately, with the code from hlh I still see CRC errors which prevent me from using the my controller.
Comment 16 Henri Hennebert 2019-12-02 17:30:16 UTC
(In reply to Gary Jennejohn from comment #15)

I dump the sd card on another device and I get:


# hd sdcard.data
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 82  |................|
000001c0  03 00 0c fe ff ff 00 20  00 00 00 04 b7 03 00 00  |...þÿÿ. ........|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............Uª|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00002000

With `sysctl debug.bootverbose=1` I display some part of the buffer
and it is all 0.

On my pc with rtsx I get:

# dd bs=512 if=/dev/mmcsd0 of=sd.dump count=20
20+0 records in
20+0 records out
10240 bytes transferred in 0.785274 secs (13040 bytes/sec)
# hd sd.dump 
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00002800

:-(
Comment 17 Gary Jennejohn 2019-12-03 07:44:24 UTC
(In reply to hlh from comment #16)

My Realtek 522A does work correctly under OpenBSD.

There is some difference in behavior between the rtsx code in OpenBSD and what there is in the FreeBSD code we now have.  For example, I do not see CRC errors with OpenBSD.

But there may also be differences between the mmc/mmcsd code in OpenBSD and the corresponding code in FreeBSD.  Hard to say.
Comment 18 Lars Engels freebsd_committer freebsd_triage 2019-12-09 20:03:03 UTC
I have a Thinkpad T450s which has a rtsx reader supported by OpenBSD:

rtsx0 at pci1 dev 0 function 0 "Realtek RTS5227 Card Reader" rev 0x01: msi

I'm running FreeBSD 12.1 on it, so if I can test anything, ping me please.
Comment 19 Lars Engels freebsd_committer freebsd_triage 2019-12-09 20:03:43 UTC
Change state to "In Progress" as now there are some people working on it.
Comment 20 Alexey Dokuchaev freebsd_committer freebsd_triage 2019-12-10 03:21:00 UTC
I've given Henri's current GitHub code a spin today, on an RTS5227 (card=0x1992103c chip=0x522710ec).  I've built and loaded all three modules, with the card removed; it was not able to detect card insertion (every time I pushed the card in/out it just complained about spurious interrupt):

> rtsx0: <Realtek RTS5227 PCI MMC/SD Card Reader> mem 0xd4000000-0xd4000fff
> at device 0.0 on pci2
> rtsx0: Card removed
> rtsx0: Spurious interrupt - no active request
> rtsx0: Spurious interrupt - no active request
> rtsx0: Spurious interrupt - no active request
> rtsx0: Spurious interrupt - no active request
> rtsx0: Spurious interrupt - no active request
Things changed when I've unloaded rtsx.ko, plugged the card, and then loaded it again:

> rtsx0: <Realtek RTS5227 PCI MMC/SD Card Reader> mem 0xd4000000-0xd4000fff
> at device 0.0 on pci2
> rtsx0: Card inserted
> rtsx0: Attaching MMC bus failed [6]
> mmc0: <MMC/SD bus> on rtsx0
> mmcsd0: 129GB <SDHC 00000 1.0 SN A123456Z MFG 05/2014 by 27 SM> at mmc0
> 0.4MHz/1bit/256-block
> rtsx0: CRC error
> rtsx0: Soft reset
> mmcsd0: Error indicated: 2 Bad CRC
> rtsx0: CRC error
> rtsx0: Soft reset
> mmcsd0: Error indicated: 2 Bad CRC
> rtsx0: CRC error
> rtsx0: Soft reset
> mmcsd0: Error indicated: 2 Bad CRC
Those errors come from trying to read anything from /dev/mmcsd0 with dd(1), to no avail.  Sometimes it's possible to read one 512-byte sector off of it, but most of the times it yields an input/output error.
Comment 21 Gary Jennejohn 2019-12-10 08:13:23 UTC
(In reply to Alexey Dokuchaev from comment #20)
I've been looking at Henri's driver for some time.

Unfortunately, there are DMA errors when trying to read larger amounts of data from the SD card.  I've been adding debug output to the driver but haven't yet been able to pinpoint the cause of the errors.

The DMA errors result in the Controller Timeouts you've seen because no interrupt is being raised.

As a result e.g. CMD7 fails.  This is a very important command which is part of the card intialization process.

The SD card protocols are rather complex which makes understanding what is going on kind of difficult.

Since FreeBSD policy dictates that new drivers have to land in HEAD first, it will probably be some time before the driver appears in older versions.
Comment 22 Alexey Dokuchaev freebsd_committer freebsd_triage 2019-12-10 08:55:12 UTC
(In reply to Gary Jennejohn from comment #21)
> Since FreeBSD policy dictates that new drivers have to land in HEAD first,
> it will probably be some time before the driver appears in older versions.
I guess this part was reply to Lars Engels from comment #18:
> I'm running FreeBSD 12.1 on it, so if I can test anything, ping me please.
I don't think 12.1 vs -CURRENT would cause a difference here; all one has to do is to clone Henri's GitHub repo, type "make", and play with it on any relatively recent FreeBSD version/branch.  There's even no need to wait for it to land in HEAD (which, given the current state of the driver, is not immediately foreseeable anyway).
Comment 23 Gary Jennejohn 2019-12-10 09:28:00 UTC
(In reply to Alexey Dokuchaev from comment #22)
Yes, that's a good point.  If users of older FreeBSD versions could clone the driver and give it a spin then we'd have some useful information.
Comment 24 Alexey Dokuchaev freebsd_committer freebsd_triage 2019-12-12 01:16:39 UTC
Another strange observation which I didn't pay attention earlier: upon "kldload rtsx", the following lines appear in the kernel log before anything else:

> hdac1: <ATI (0x9902) HDA Controller> mem 0xd6044000-0xd6047fff at device 1.1
> on pci0
> hdac1: hdac_get_capabilities: Invalid corb size (0)
> device_attach: hdac1 attach returned 6
Admittedly, I have zero ideas what rtsx(4) has to do with HDA. :-/
Comment 25 Gary Jennejohn 2019-12-12 06:16:37 UTC
(In reply to Alexey Dokuchaev from comment #24)
rtsx has nothing at all to do with hda.  But the "kldload rtsx" results in the kernel rescanning all devices to find a match.

There were recently some changes in the hda code.  How current is your kernel?
Comment 26 Alexey Dokuchaev freebsd_committer freebsd_triage 2019-12-12 06:41:17 UTC
(In reply to Gary Jennejohn from comment #25)
> But the "kldload rtsx" results in the kernel rescanning all devices
> to find a match.
That should explain it, thanks.

> There were recently some changes in the hda code.  How current is your kernel?
Not the very latest one (septemberish r352614), I should probably update, but a bit afraid of some potentially boot-breaking USB/CAM problems being reported on the lists*.

*) https://lists.freebsd.org/pipermail/freebsd-current/2019-December/074914.html
Comment 27 Gary Jennejohn 2019-12-12 06:57:59 UTC
(In reply to Alexey Dokuchaev from comment #26)
I sort of understand your reluctance.

I never install a new kernel over the top of the old kernel.  Instead I do this
(as root, of course) in a bash alias:

mkdir -p /boot/test
cd /usr/src
make -s installkernel KODIR=/boot/test
nextboot -k test
cd

Then a reboot will boot the new kernel from /boot/test.  If it fails the next boot will use the old, known-good kernel.

If it succeeds then you can simply run "make installkernel" so that the standard kernel in /boot/kernel will be updated and used.
Comment 28 Gary Jennejohn 2019-12-12 10:33:23 UTC
Created attachment 209887 [details]
Patch to add SD card insertion/removal

A minor patch to Henri's code to add SD card insertion/removal handling.  Doesn't fix the DMA problems, but I felt like doing something else.

Shamelessly stolen from dwmmc.c
Comment 29 Alexey Dokuchaev freebsd_committer freebsd_triage 2019-12-12 10:49:06 UTC
(In reply to Gary Jennejohn from comment #28)
> A minor patch to Henri's code to add SD card insertion/removal handling.
Thanks, I confirm it does fix card detection problem for me.
Comment 30 Val Packett 2019-12-12 12:05:03 UTC
(In reply to Gary Jennejohn from comment #27)

> I never install a new kernel over the top of the old kernel.  Instead I do this

installkernel does this for you! the old kernel is always moved to /boot/kernel.old and you can select that in the bootloader.
Comment 31 Henri Hennebert 2019-12-12 13:32:07 UTC
(In reply to Gary Jennejohn from comment #28)

I update the git repository with the patch

Thanks a lot
Henri
Comment 32 Gary Jennejohn 2019-12-12 14:21:06 UTC
(In reply to Greg V from comment #30)
I'm well aware of what installkernel does.  But my way saves me the trouble of telling the bootloader to boot from kernel.old if the new kernel fails.  I can simply reboot and the known-working kernel under /boot/kernel will be loaded.
Comment 33 Gary Jennejohn 2019-12-21 08:12:49 UTC
I tried implementing rtsx_xfer_bounce() from the OpenBSD code.

OpenBSD uses this function when the upstream code does not pass in a list of DMA scatter-gather addresses.  Normally, the SD code in OpenBSD allocates its own DMA buffers and passes them to the driver.

Since FreeBSD does not do that - it either uses buffers on the kernel stack or buffers from a struct bio - it seemed logical to me to try rtsx_xfer_bouce().

The DMA transfer raises an interrupt, but the target buffer is always filled with 0s.

I'm running out of ideas on how to get DMA to work.

If I had a laptop I could tear apart I'd put a logic analyzer on the controller pins and compare the behavior between OpenBSD and FreeBSD.  Unfortunately, the laptop I have is a loaner and I can't do that.
Comment 34 Gary Jennejohn 2020-01-08 13:37:37 UTC
I reimplemented rtsx_xfer_bounce() so that it's pretty much one-to-one the same as the way OpenBSD does it.  But now the transfer always times out.  The DMA addresses returned by the kernel all look good and are within the 32-bit range.

If anyone is interested I can attach my code.  It's full of ifdef's and trace output.  Maybe other eyes can see what I can't.  I've looked at the code so much that I may be blind to any errors.

Comparing OpenBSD with the code I'm using doesn't reveal any obvious errors.  The DMA setup for using bounce buffers appears to be the same and the steps preceeding the DMA transfer also seem identical.

I'm at a loss to explain why DMA in FreeBSD does not work.

What I haven't yet tried is to do the DMA setup like dwmmc.c does it.  Guess I'll try that next.
Comment 35 Lyubomir 2020-01-09 16:10:31 UTC
Hi Gary,
All the best to all for the New 2020!
I am not a developer so I will not be able to help with the code but I have access to Lenovo T450 (mine), to a logic analyzer SALEAE Logic pro 16 (not mine :)) and I can also find another hdd to install OpenBSD on it. I would like to help but I would definitely need your guidance.
Do you think this will work?

Best regards,

Lyubo
Comment 36 Gary Jennejohn 2020-01-10 08:54:42 UTC
(In reply to Lyubomir from comment #35)
Thanks for the offer.  I did some research and the Realtek controllers used in laptops are basically black boxes.  They consist of a module with the electronics and the SD card holder and then a rather long cable which gets routed to a connecotr on the motherboard.  I was not able to find any documentation on the cable pinout.  Without that information it would not be possible to connect the SALEAE logic analyzer (I have two of them) to get useful traces.  So my idea to do this was not so good.

At one time there were PCIe cards with suitable Realtek controllers, but I haven't been able to find any on e.g. eBay.  The cards now available no longer use Realtek.
Comment 37 Gary Jennejohn 2020-01-18 09:24:33 UTC
(In reply to hlh from comment #31)
You should add sc->rtsx_intr_status = 0; prior to the call to rtsx_wait_intr() in rtsx_xfer()to be consistent.  This is the only place where that was not being done.  It doesn't change the behavior, but it can prevent false positives in rtsx_wait_intr().
Comment 38 Henri Hennebert 2020-01-18 09:58:39 UTC
(In reply to Gary Jennejohn from comment #37)
Update done. Thanks
Comment 39 Sergey V. Dyatko 2020-01-23 20:49:37 UTC
Hi, I have lenovo thinkpad t470p with 
none4@pci0:4:0:0:       class=0xff0000 rev=0x01 hdr=0x00 vendor=0x10ec device=0x522a subvendor=0x17aa subdevice=0x505d
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS522A PCI Express Card Reader'
and can test too
Comment 40 dirkx 2020-03-19 12:34:50 UTC
(In reply to Gary Jennejohn from comment #34)

if (len == 0) set it to min(maxbuff,len) at https://github.com/hlh-restart/rtsx/blob/fa2c5b66d00b7a4bec6eb0e5539b8edbd7a06a9b/rtsx.c#L1472 looks rather odd to me.
Comment 41 Gary Jennejohn 2020-03-19 13:46:26 UTC
(In reply to dirkx from comment #40)
The code is correct.  The {Net,Open}BSD upper layer code always sets xfer_len to the correct value.  FreeBSD does indeed have xfer_len, but the upper layer never sets it.  To simplify implementing the OpenBSD code (and avoid kernel panics) it was convenient for hlh to set xfer_len to a reasonable value.
I must admit that what's on github looks nothing like the code I've tested.  I've made massive changes to DMA code, added lots of variations on how transfers are done based on examining what OpneBSD and Linux do in various situations and added large amounts of debugging.  Unfortunately, nothing I've tried so far results in successful DMA transfers.
One test I did was to set a byte pattern in the virtual address of the DMA buffer, start the transfer (the controller claims that no errors occurred), and then dump the physical address of the buffer using /dev/mem.  The result was that NO bytes were transferred at all, i.e. the contents of the virtual and physical addresses were identical.
There is much more to the {Net,Open}BSD implementation than just the driver.  There is an upper layer which implements the SD Card Host Controller Specification.  It is somewhat different than what was implemented in FreeBSD.  I'm beginning to suspect that these differences may be contributing to the DMA problems.
Comment 42 Gary Jennejohn 2020-03-20 10:35:48 UTC
(In reply to hlh from comment #38)
The message from dirkx led me to look more closely at the OpenBSD code.
OpenBSD never sets intr_status to 0 before calling rtsx_wait_intr().
That makes sense because, theoretically, the interrupt could be raised before rtsx_wait_intr() is entered.  In that case, setting intr_status to 0 would overwrite its setting in the interrupt handler and result in a false timeout error.
I tested NOT setting intr_status to 0 and the driver works just as well (or badly) as before.  Actually, setting it to zero is not really necessary due to this code in rtsx_wait_intr(): sc->rtsx_intr_status &= ~status;
So, I suggest, but do not demand, at least commenting out the lines where intr_status is set to 0.  I leave it up to you.
Comment 43 Henri Hennebert 2020-03-20 13:18:19 UTC
(In reply to Gary Jennejohn from comment #42)

I am not sure this is a problem because sc->rtsx_intr_status is set
to 0 _before_ sending the command and so before the relevant
interrupt can be raised.
Comment 44 dirkx 2020-03-20 13:20:47 UTC
(In reply to hlh from comment #43)

So I put a few 'if (sc->rtsx_intr_status) printf..' just before the  sc->rtsx_intr_status=0; lines to check if there was (I assuse) something pending/non zero at the point this happens. And it seems to happy once or twice - exactly before the timeout.
Comment 45 dirkx 2020-03-20 13:21:18 UTC
(In reply to hlh from comment #43)

So I put a few 'if (sc->rtsx_intr_status) printf..' just before the  sc->rtsx_intr_status=0; lines to check if there was (I assuse) something pending/non zero at the point this happens. And it seems to happy once or twice - exactly before the timeout.
Comment 46 Henri Hennebert 2020-03-20 13:31:14 UTC
(In reply to dirkx from comment #44)
Strange, if you comment the sc->rtsx_intr_status=0 does the timeout disappear?
Comment 47 Gary Jennejohn 2020-03-20 13:57:50 UTC
(In reply to hlh from comment #46)
I see timeouts whether rtsx_intr_status is set to 0 or not.  But dirkx makes a valid point, if setting it to 0 occurs before the command is sent.  In any case, I didn't observe any adverse effects by not setting it to 0, but then again, setting it to 0 may also be harmless.
The timeouts semm to only occur when a transfer using rtsx_xfer_short() is attempted.  But these errors are only visible when boot_verbose is set to 1.
I also see quite a few CRC errors being generated (may be due to the SD card I'm using).
Comment 48 Henri Hennebert 2020-03-20 14:07:23 UTC
(In reply to Gary Jennejohn from comment #4(In reply to Gary Jennejohn from comment #47)

I also encounter CRC errors but if I boot with tails (https://tails.boum.org/)
I can play with the sdcard without problem. So CRC is a problem with the
Freebsd driver/system. Now I think that our problem is due to some wrong
initialization... But I can't find what :-(
Comment 49 Gary Jennejohn 2020-03-20 14:34:14 UTC
(In reply to hlh from comment #48)
Tails is Linux, and the Linux driver(s) were developed by Realtek.  Not surprising that it works.
I also tested with OpenBSD, which also works without error.
So I agree, something is missing in FreeBSD, although your driver seems to faithfully implement the OpenBSD rtsx.c.
But, as I wrote in a previous comment, there's a lot more to the OpenBSD code than just the driver itself.
Comment 50 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-06 05:24:32 UTC
Still does not work..

I looked into the bus width thing though.. it sets 1 bit even though capability is 4 bit
in mmc.c
mmc_app_decode_scr(uint32_t *raw_scr, struct mmc_scr *scr)
{
	unsigned int scr_struct;

	memset(scr, 0, sizeof(*scr));

	scr_struct = mmc_get_bits(raw_scr, 64, 60, 4);
	if (scr_struct != 0) {
		printf("Unrecognised SCR structure version %d\n",
		    scr_struct);
		return;
	}
	scr->sda_vsn = mmc_get_bits(raw_scr, 64, 56, 4);
	scr->bus_widths = mmc_get_bits(raw_scr, 64, 48, 4);
}
and in mmc_discover_cards function in mmc.c
if ((host_caps & MMC_CAP_4_BIT_DATA) &&
			    (ivar->scr.bus_widths & SD_SCR_BUS_WIDTH_4))
				ivar->bus_width = bus_width_4;

but bus_width is 1 and iirc 4 on openbsd so ivar->scr.bus_widths & SD_SCR_BUS_WIDTH_4 is false. Removing it sets the bus width to 4 bits, but still controller timeout.

so perhaps mmc_app_decode_scr does not apply to Realteks way of doing things?
Comment 51 Gary Jennejohn 2020-05-06 07:50:25 UTC
(In reply to Jesper Schmitz Mouridsen from comment #50)
AFAIKT the mmc code does what the standard requires.  The real problem is that SCR needs to read 64 bytes from the controller and the DMA fails so that the contents in the buffer are always 0.
Comment 52 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-21 15:07:36 UTC
looking hard at the linux driver dyndbg output I have managed to read the short data and getting bus witdh 4 from the SCR :-)
I will add a patch as soon as my code formatting is fixed..
Comment 53 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-21 17:17:52 UTC
Created attachment 214731 [details]
can read scr

This was the minimal changes I could make in order to read the scr.
The short data of data len 8 and 64  returns the same output as on openbsd.
I have not pin pointed the exact problem, but I'm using the cmd buffer more, and the sd_set_clock code has changed looking at the linux kernel. 
I hope some of you can have a look.
Comment 54 Gary Jennejohn 2020-05-21 17:49:13 UTC
(In reply to Jesper Schmitz Mouridsen from comment #53)
Thanks!  I'll look at it.  Note that your rtsx_pci_send_cmd() is basically the same as rtsx_send_cmd() already in the code.  The main difference is that your code synchronises the DMA buffers in the routine itself whereas the existing code does it after rtsx_send_cmd() returns.
Did you keep the Linux dyndbg output?  Could be interesting to look at.
Comment 55 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-21 18:18:56 UTC
Created attachment 214733 [details]
dyndbg output of linux kernel driver
Comment 56 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-21 18:21:18 UTC
(In reply to Gary Jennejohn from comment #54)
Yep rtsx_pci_send_cmd should be merged, note that it does not have mmc_cmd cmd as argument. The dmesg output is now attahced.
Comment 57 Gary Jennejohn 2020-05-22 06:44:42 UTC
(In reply to Jesper Schmitz Mouridsen from comment #56)
The mmc cmd is used to report an error to the MMC stack, if one occurs, so rtsx_send_cmd() would be the better choice in general.
Thanks for looking into this and for attaching the Linux output.
Comment 58 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-23 22:50:05 UTC
Created attachment 214797 [details]
minimal can still read SCR

looking closer I can now read SCR with one change.
RTSX_CLK_DIVIDE_MASK is zero also for RTSX_SDCLK_400KHZ.
Tested on 5209 and 5229

xfer besides dlen 8 and 64 still times out..
Comment 59 Henri Hennebert 2020-05-24 07:15:54 UTC
(In reply to Jesper Schmitz Mouridsen from comment #58)

I update git, thanks a lot for your time!
Comment 60 Gary Jennejohn 2020-05-24 07:58:31 UTC
(In reply to hlh from comment #59)
This is really excellent!  Next is to figure out how to do larger transfers.
Comment 61 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-25 10:24:59 UTC
Created attachment 214840 [details]
read works. write does not yet

Ok, this was trial and error inspecting what the linux kernel module does.
I even hardcoded a cfg2 value... so the quality can improve..
We need stil to make WRITE cmds work....
So DO NOT use on real data..
Comment 62 Gary Jennejohn 2020-05-25 11:42:00 UTC
(In reply to Jesper Schmitz Mouridsen from comment #61)
Well, you're making progress in any case.  The driver is in better shape than ever now.
Comment 63 Alexey Dokuchaev freebsd_committer freebsd_triage 2020-05-25 12:03:52 UTC
Good progress indeed.  However, you might want to make those patches more conforming to style(9), e.g. use tabs instead of spaces for indentation, as this will simplify inclusion of this code into the FreeBSD codebase.
Comment 64 Henri Hennebert 2020-05-25 17:21:38 UTC
(In reply to Jesper Schmitz Mouridsen from comment #61)

Really good job!

git updated.

I do the tab cleaning and made it read only for now because I get a crash
if I load rtsx with gnome running and some write operation is requested by
some component of gnome.
Comment 65 Henri Hennebert 2020-05-25 17:28:50 UTC
(In reply to hlh from comment #64)

In the git update, I swap the implementations of rtsx_bus_power_up()
and rtsx_bus_power_on() instead of swapping the calls in rtsx_mmcbr_update_ios().
Comment 66 Alexey Dokuchaev freebsd_committer freebsd_triage 2020-05-26 09:26:13 UTC
(In reply to hlh from comment #64)
> git updated.
Awesome!  I can confirm my RTS5227 (card=0x1992103c chip=0x522710ec) is able to read the SD card successfully now.
Comment 67 Henri Hennebert 2020-05-26 16:27:52 UTC
I complete/update the write code but when mounting a msdosfs I get:

panic: general protection fault
cpuid = 3
time = 1590504848
KDB: stack backtrace:
#0 0xffffffff80695005 at kdb_backtrace+0x65
#1 0xffffffff8064a7ab at vpanic+0x17b
#2 0xffffffff8064a623 at panic+0x43
#3 0xffffffff80a0b301 at trap_fatal+0x391
#4 0xffffffff80a0a787 at trap+0x67
#5 0xffffffff809e4728 at calltrap+0x8
#6 0xffffffff806f387e at bufwrite+0x1fe
#7 0xffffffff807294c0 at vn_fsync_buf+0x250
#8 0xffffffff80aaa84b at VOP_FSYNC_APV+0x7b
#9 0xffffffff806f3a0b at bufsync+0x3b
#10 0xffffffff8071410d at bufobj_invalbuf+0x1ad
#11 0xffffffff807173fe at vgonel+0x17e
#12 0xffffffff80717a46 at vgone+0x36
#13 0xffffffff8052a7f7 at devfs_delete+0x177
#14 0xffffffff8052ad36 at devfs_populate_loop+0x1e6
#15 0xffffffff8052ab3a at devfs_populate+0x2a
#16 0xffffffff8052fbbb at devfs_populate_vp+0x9b
#17 0xffffffff8052dc0b at devfs_lookup+0x2b
Uptime: 53m47s

with sysctl debug.bootverbose=1 :

rtsx0: rtsx_mmcbr_request(CMD17 arg 0x40001 flags 0x35 dlen 512 dflags 0x2)
rtsx0: rtsx_xfer_short() - Read xfer: 512 bytes with block size 512
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: rtsx_mmcbr_release_host()
rtsx0: rtsx_mmcbr_acquire_host()
rtsx0: rtsx_mmcbr_request(CMD17 arg 0x40000 flags 0x35 dlen 512 dflags 0x2)
rtsx0: rtsx_xfer_short() - Read xfer: 512 bytes with block size 512
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: rtsx_mmcbr_release_host()
rtsx0: rtsx_mmcbr_acquire_host()
rtsx0: rtsx_mmcbr_request(CMD17 arg 0x40001 flags 0x35 dlen 512 dflags 0x2)
rtsx0: rtsx_xfer_short() - Read xfer: 512 bytes with block size 512
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: rtsx_mmcbr_release_host()
rtsx0: rtsx_mmcbr_acquire_host()
rtsx0: rtsx_mmcbr_request(CMD17 arg 0x40000 flags 0x35 dlen 512 dflags 0x2)
rtsx0: rtsx_xfer_short() - Read xfer: 512 bytes with block size 512
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: rtsx_mmcbr_release_host()


Fatal trap 9: general protection fault while in kernel mode
Comment 68 Gary Jennejohn 2020-05-26 17:16:30 UTC
(In reply to hlh from comment #67)
Is the code already in git?
What happens if you mount read only?  I ask that because the fault is happening in bufwrite.
Comment 69 Henri Hennebert 2020-05-26 18:48:29 UTC
(In reply to Gary Jennejohn from comment #68)

The code is already in git.

I think that a mount read only _should_ work.

To be sure see line 1681-1682 to enforce only read requests. Than
you must mount read only.
Comment 70 Gary Jennejohn 2020-05-27 08:40:37 UTC
(In reply to hlh from comment #69)
Unfortunately, with my RTS522A I don't get as far as you do.
The very first CMD18 which reads 8192 bytes with a blocksize of 512 appears to succeed.  The MMC stack then immediately repeats the CMD18 which results in a CRC error.  After that ALL reads result in a CRC error no matter what the transfer size is.
Looks like the soft reset is not clearing the CRC error.  There must be a way to do that, I would think.
Of course, the SD card itself might be the problem.  I'll try a different card and report back.
But at least /dev/mmcsd0 was created :)
Comment 71 Gary Jennejohn 2020-05-27 08:50:11 UTC
(In reply to Gary Jennejohn from comment #70)
No, the card is not the problem.  Exactly the same behavior with a different card.
Comment 72 Lutz Bichler 2020-05-27 09:42:38 UTC
I have to change RTSX_TM_AUTO_READ2 to RTSX_TM_AUTO_READ1 in line 1698 to enable read-only mounts with a RTS522A.
Comment 73 Henri Hennebert 2020-05-27 10:15:30 UTC
(In reply to Lutz Bichler from comment #72)

I will replace READ2 by READ1: both are working for my RTL8411B.
Comment 74 Henri Hennebert 2020-05-27 10:54:03 UTC
On my Realtek RTL8411B write 512 bytes blocks is working - rtsx_xfer_short():

dd if=some_file of=/dev/mmcsd0 bs=512 count=x

dd if=/dev/mmcsd0 bs=512 count=x

With a bs > 512 [rtsx_xfer()] I get interrupt RTSX_TRANS_FAIL_INT :-(
Comment 75 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-27 12:45:39 UTC
(In reply to hlh from comment #74)
I can write with bs>512 on 5209 with tmode AUTO_WRITE4 instead of tmode AUTO_WRITE3, but I can not read after I have done a write operation.
Comment 76 Henri Hennebert 2020-05-27 12:57:04 UTC
(In reply to Jesper Schmitz Mouridsen from comment #75)

I update gitub.

I modify rtsx_xfer() according to linux sd_write_long_data()
https://elixir.bootlin.com/linux/v4.3.1/source/drivers/mmc/host/rtsx_pci_sdmmc.c#L499

I can write one block but the next write get a controller timeout and
all following read timeout too. I reset with kldunload rtsx && kldload rtsx.
Comment 77 Gary Jennejohn 2020-05-27 13:09:43 UTC
(In reply to hlh from comment #76)
If I limit MMCBR_IVAR_MAX_DATA to 1, i.e. max transfer of 512 bytes, in rtsx_read_ivar() then I can mount, read from and write to the SD card with no errors.
The change results in all transfers being done with rtsx_xfer_short(), of course.
So, rtsx_xfer() still needs some work.
Don't give up, you're making good progress.
Comment 78 Gary Jennejohn 2020-05-27 14:24:29 UTC
I notice that the driver currently limits the SD clock to a maximum of 50MHz.
In the Linux trace the clock is set to 208MHz.
I wonder whether the clock rate is contributing to the errors seen when rtsx_xfer() is used.  In particular, CMD18 trying to read 8192 bytes in a single transfer may be too fast for the controller/SD card to acheive at a lower clock rate.
Comment 79 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-27 14:38:28 UTC
I can make CMD25 succeed by adding 

  bus_dmamap_sync(sc->rtsx_data_dma_tag, sc->rtsx_data_dmamap, BUS_DMASYNC_POSTREAD);
        bus_dmamap_sync(sc->rtsx_data_dma_tag, sc->rtsx_data_dmamap, BUS_DMASYNC_POSTWRITE);

before the cmd->data->data is memcpy'ed to the data dma buffer.

to the current git source...

*BUT* the follwing/subsequent CMD17 and CMD18 fails..
Comment 80 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-27 14:41:40 UTC
(In reply to Jesper Schmitz Mouridsen from comment #79)

I meant
    bus_dmamap_sync(sc->rtsx_data_dma_tag, sc->rtsx_data_dmamap, BUS_DMASYNC_PREREAD);
    bus_dmamap_sync(sc->rtsx_data_dma_tag, sc->rtsx_data_dmamap, BUS_DMASYNC_PREWRITE);
Comment 81 Henri Hennebert 2020-05-27 14:47:05 UTC
(In reply to Jesper Schmitz Mouridsen from comment #80)

I try this but as before only the first write complete and then Controller timeout for subsequent operations.
Comment 82 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-27 15:37:34 UTC
(In reply to hlh from comment #81)
It works for me now 

	if (read)
        memcpy(cmd->data->data, sc->rtsx_data_dmamem, cmd->data->len);
    else
        rtsx_send_req_get_resp(sc,sc->rtsx_req->stop);
Comment 83 Henri Hennebert 2020-05-27 15:44:58 UTC
(In reply to Jesper Schmitz Mouridsen from comment #82)

WELL DONE!

Where do you find this trick?

Github updated!
Comment 84 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-27 15:46:13 UTC
Created attachment 214925 [details]
add stop cmd from req and reposition sync_dma

enables reads after write..
Comment 85 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-27 15:47:21 UTC
(In reply to hlh from comment #83)
Thanks,
it was in the dwmmc code...

} else if (sc->flags & PENDING_STOP && !sc->use_auto_stop) {
		sc->flags &= ~PENDING_STOP;
		dwmmc_start_cmd(sc, req->stop);
		return;
	}
Comment 86 Henri Hennebert 2020-05-27 16:07:23 UTC
With The current githup I can

gpart create -s GPT /dev/mmcsd0
gpart add -t freebsd-zfs /dev/mmcsd0
zpool create TEST /dev/mmcsd0p1
...populate the pool...
zpool scrub
zpool status TEST
  pool: TEST
 state: ONLINE
  scan: scrub repaired 0 in 0 days 00:00:17 with 0 errors on Wed May 27 18:01:58 2020
config:

	NAME        STATE     READ WRITE CKSUM
	TEST        ONLINE       0     0     0
	  mmcsd0p1  ONLINE       0     0     0

errors: No known data errors

This is a wonderful day!
Comment 87 Henri Hennebert 2020-05-27 16:16:51 UTC
(In reply to Jesper Schmitz Mouridsen from comment #84)
The bus_dmamap_sync() don't need to be positioned. I keep it at the 'old' place to be coherent with the rest of the code.
Comment 88 Gary Jennejohn 2020-05-27 16:59:07 UTC
Yay!  It works with my 522A also.  People with different controllers need to test this too.  If there are enough reports of success then maybe one of the FreeBSD committers following this (I think they're all ports committers) can convince a src committer to commit it to HEAD.
Comment 89 Lars Engels freebsd_committer freebsd_triage 2020-05-27 17:06:42 UTC
Thats awesome teamwork! 

I will test this on my T450s tomorrow and report back.
Comment 90 Eric van Gyzen freebsd_committer freebsd_triage 2020-05-27 17:12:00 UTC
I'm a src committer.  Let me know when you think it's ready, and I'll take a look.
Comment 91 Dave Cottlehuber freebsd_committer freebsd_triage 2020-05-27 17:16:32 UTC
Amazing! can we get all of this into a single patch (or a git branch)? I'm not
clear which ones of the attachments are needed. I can try it out on my laptop, but I'll need to build it on a bigger box first, before upgrading from 12.1R. Nice idea to try out a zpool, I'll do that too on my Dell XPS13.
Comment 92 Henri Hennebert 2020-05-27 17:19:34 UTC
(In reply to Dave Cottlehuber from comment #91)

Just checkout from https://github.com/hlh-restart/rtsx the latest master.
Comment 93 Jung-uk Kim freebsd_committer freebsd_triage 2020-05-27 17:22:33 UTC
(In reply to Eric van Gyzen from comment #90)
I can do it, too.  However, we need a) a manual page, i.e., rtsx(4) and b) thorough style(9) compliance check.  rtsx(4) doesn't have to be complete but we need something, e.g., supported devices, authors, origin, etc.  See sdhci(4) for example.
Comment 94 Henri Hennebert 2020-05-27 17:26:27 UTC
(In reply to Jung-uk Kim from comment #93)

I will do it in the following days. It will be something interesting for me to learn to do a man page ;-)
Comment 95 Florian Smeets freebsd_committer freebsd_triage 2020-05-27 18:13:16 UTC
FWIW, another successful test. Hardware is an Intel NUC8i5BE

rtsx0@pci0:2:0:0:	class=0xff0000 rev=0x01 hdr=0x00 vendor=0x10ec device=0x522a subvendor=0x8086 subdevice=0x2074
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS522A PCI Express Card Reader'


copied a couple of GB to an SD card successfully, while rsyncing src to it and checking out a ports tree.

Great work. Thanks.
Comment 96 Zeus Panchenko 2020-05-27 21:35:54 UTC
successful test on HP Probook 430 g2

many many thanks!

commit d605a27259dd147f866b4e2640f6289323c2a8c7

> dmesg
rtsx0: <Realtek RTS5227 PCI MMC/SD Card Reader> mem 0xc1200000-0xc1200fff at device 0.0 on pci2
rtsx0: Card inserted/removed
rtsx0: No request running
mmc0: <MMC/SD bus> on rtsx0
mmcsd0: 2GB <SD SD02G 3.8 SN A58756A6 MFG 05/2009 by 2 TM> at mmc0 50.0MHz/4bit/256-block

> pciconf -lv
rtsx0@pci0:7:0:0:       class=0xff0000 card=0x2246103c chip=0x522710ec rev=0x01 hdr=0x00
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS5227 PCI Express Card Reader'

> mount_msdosfs /dev/mmcsd0s1 /mnt/da0

> /usr/bin/time -h cp -r /usr/src/tools /mnt/da0/tmp/
7m56.35s (on linux 10m8s)

> /usr/bin/time -h mv /mnt/da0/tmp/tools /tmp
5m1.65s (on linux 1m28s)
Comment 97 Gary Jennejohn 2020-05-28 08:24:30 UTC
It would be useful if people were to include the FreeBSD version with which they tested.  If we can get reports of success with FreeBSD 11/12/13 then that might facilitate getting the driver merged with older versions.
I did all my testing using FreeBSD13.
Comment 98 Henri Hennebert 2020-05-28 08:31:50 UTC
(In reply to Gary Jennejohn from comment #97)

I do all developments and testing on

FreeBSD 12.1-STABLE #0 r360996

with Realtek RTL8411B PCI MMC/SD Card Reader
Comment 99 dirkx 2020-05-28 08:38:52 UTC
(In reply to hlh from comment #98)

Stock FreeBSD 12.1-RELEASE-p2 on a Realtek TRTS522A PCI reader.

Tested against several MSDOS/fat and ZFS formatted cards 4GB-64GB used in cross windows/macosx setting.
Comment 100 Gary Jennejohn 2020-05-28 08:43:43 UTC
(In reply to hlh from comment #98)
An excellent idea to also include the controller model.
I have the RTL522A.

It would be nice if we could get some tests with less common controllers like the 5209 and 525A.
Comment 101 Bengt Ahlgren 2020-05-28 09:58:53 UTC
(In reply to Gary Jennejohn from comment #97)
It does not compile on 11.4-STABLE:

rtsx.c:2072:21: error: use of undeclared identifier 'IO_SEND_OP_COND'
        if (cmd->opcode == IO_SEND_OP_COND &&

Copying that definition from 12-STABLE (sys/dev/mmc/mmcreg.h) makes it compile.

I only made a very simple test with one card, creating one file and read it back without issues.

I have a Thinkpad X250 with:

rtsx0@pci0:2:0:0:       class=0xff0000 card=0x222617aa chip=0x522710ec rev=0x01 hdr=0x00
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS5227 PCI Express Card Reader'

Great work, thanks a lot!
Comment 102 Gary Jennejohn 2020-05-28 10:17:57 UTC
(In reply to Bengt Ahlgren from comment #101)
Thanks!
This should be easy to fix with an #ifndef in rtsxreg.h since that gets included after the mmc header files.
Comment 103 Sergey V. Dyatko 2020-05-28 11:08:50 UTC
Hi, 
[tiger@laptop]:/tmp%uname -a
FreeBSD laptop.domain 13.0-CURRENT FreeBSD 13.0-CURRENT #1 r356767M: Sun Feb  9 23:29:26 +03 2020     root@laptop.domain:/usr/obj/usr/src/amd64.amd64/sys/GENERIC-NODEBUG  amd64

_without inserted card_

git clone https://github.com/hlh-restart/rtsx.git
cd rtsx
make
kldload ./rtsx.ko as root
dmesg:


rtsx0: <Realtek RTS522A PCI MMC/SD Card Reader> mem 0xf2100000-0xf2100fff at device 0.0 on pci4
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
mmc0: No compatible cards found on bus

should I insert card before kldload ?
Comment 104 Henri Hennebert 2020-05-28 11:18:22 UTC
(In reply to Sergey V. Dyatko from comment #103)

It work with no card inserted before kldload rtsx.

At least on Freebsd 12.1-STABLE with RTL8411B.

Maybe it's the card. Anyway try 
kldunload rtsx
inter card
kldload rtsx
Comment 105 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-28 11:22:59 UTC
(In reply to Sergey V. Dyatko from comment #103)
Can you replicate the problem,is it periodic or does it happen all the time?

Can you set sysctl hw.mmc.debug=9
and debug.bootverbose=1 and send the output.
Comment 106 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-28 11:31:57 UTC
with the module loaded inserting/removing the card from the reader repeatedly and fast results in the same errors.
Comment 107 Sergey V. Dyatko 2020-05-28 11:33:35 UTC
(In reply to Jesper Schmitz Mouridsen from comment #105)
laptop# kldunload rtsx
laptop#
<dmesg cut>
mmc0: detached
rtsx0: detached
pci4: <unknown> at device 0.0 (no driver attached)
</dmesg cut>
laptop# sysctl hw.mmc.debug=9
hw.mmc.debug: 0 -> 9
laptop# sysctl debug.bootverbose=1 
debug.bootverbose: 0 -> 1
laptop# kldload ./rtsx.ko
load: 0.33  cmd: kldload 96161 [rtsxintr] 1.73r 0.00u 0.05s 0% 1808k
load: 0.33  cmd: kldload 96161 [rtsxintr] 2.03r 0.00u 0.05s 0% 1808k
load: 0.33  cmd: kldload 96161 [rtsxintr] 2.22r 0.00u 0.06s 0% 1808k
load: 0.33  cmd: kldload 96161 [rtsxintr] 2.40r 0.00u 0.06s 0% 1808k
load: 0.33  cmd: kldload 96161 [rtsxintr] 2.57r 0.00u 0.06s 0% 1808k
load: 0.33  cmd: kldload 96161 [rtsxintr] 2.74r 0.00u 0.06s 0% 1808k
load: 0.33  cmd: kldload 96161 [rtsxintr] 2.91r 0.00u 0.06s 0% 1808k
load: 0.33  cmd: kldload 96161 [rtsxintr] 3.09r 0.00u 0.06s 0% 1808k
load: 0.33  cmd: kldload 96161 [rtsxintr] 3.27r 0.00u 0.06s 0% 1808k
load: 0.33  cmd: kldload 96161 [rtsxintr] 3.45r 0.00u 0.06s 0% 1808k
dmesg:
pci0: driver added                                                                                                                                                          
found-> vendor=0x8086, dev=0xa131, revid=0x31                                                                                                                                                                       
        domain=0, bus=0, slot=20, func=2                                                                                                                                                                            
        class=11-80-00, hdrtype=0x00, mfdev=0                                                                                                                                                                       
        cmdreg=0x0002, statreg=0x0010, cachelnsz=0 (dwords)                                                                                                                                                         
        lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)                                                                                                                                                
        intpin=c, irq=255                                                                                                                                                                               
        powerspec 3  supports D0 D3  current D0                                                                                                                                                                     
        MSI supports 1 message                                                                                                                                                                                      
pci0:0:20:2: reprobing on driver added 
found-> vendor=0x8086, dev=0xa13a, revid=0x31                                                                                                                                                                       
        domain=0, bus=0, slot=22, func=0                                                                                                                                                                            
        class=07-80-00, hdrtype=0x00, mfdev=1                                                                                                                                                                       
        cmdreg=0x0002, statreg=0x0010, cachelnsz=0 (dwords)                                                                                                                                                         
        lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)                                                                                                                                                
        intpin=a, irq=255                                                                                                                                                                               
        powerspec 3  supports D0 D3  current D0                                                                                                                                                                     
        MSI supports 1 message, 64 bit                                                                                                                                                                              
pci0:0:22:0: reprobing on driver added                                                                                                                                                                              
found-> vendor=0x8086, dev=0xa121, revid=0x31                                                                                                                                                                       
        domain=0, bus=0, slot=31, func=2                                                                                                                                                                            
        class=05-80-00, hdrtype=0x00, mfdev=1                                                                                                                                                                       
        cmdreg=0x0002, statreg=0x0000, cachelnsz=0 (dwords)                                                                                                                                                         
        lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)                                                                                                                                                
pci0:0:31:2: reprobing on driver added                                                                                                                                                                              
found-> vendor=0x8086, dev=0xa123, revid=0x31                                                                                                                                                                       
        domain=0, bus=0, slot=31, func=4                                                                                                                                                                            
        class=0c-05-00, hdrtype=0x00, mfdev=0                                                                                                                                                                       
        cmdreg=0x0003, statreg=0x0280, cachelnsz=0 (dwords)                                                                                                                                                         
        lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)                                                                                                                                                
        intpin=a, irq=255                                                                                                                                                                               
pci0:0:31:4: reprobing on driver added                                                                                                                                                                              
pci1: driver added                                                                                                                                                          
pci2: driver added                                                                                                                                                          
pci3: driver added                                                                                                                                                          
pci4: driver added                                                                                                                                                          
found-> vendor=0x10ec, dev=0x522a, revid=0x01                                                                                                                                                                       
        domain=0, bus=4, slot=0, func=0                                                                                                                                                                             
        class=ff-00-00, hdrtype=0x00, mfdev=0                                                                                                                                                                       
        cmdreg=0x0406, statreg=0x0010, cachelnsz=0 (dwords)                                                                                                                                                         
        lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)                                                                                                                                                
        intpin=a, irq=255                                                                                                                                                                               
        powerspec 3  supports D0 D1 D2 D3  current D0                                                                                                                                                               
        MSI supports 1 message, 64 bit         
                                   pci0:4:0:0: reprobing on driver added                                                                                                                                                                               
rtsx0: <Realtek RTS522A PCI MMC/SD Card Reader> mem 0xf2100000-0xf2100fff at device 0.0 on pci4                                                                                                                     
rtsx0: Attach - Vendor ID: 0x10ec - Device ID: 0x522a                                                                                                                                                               
rtsx0: attempting to allocate 1 MSI vectors (1 supported)                                                                                                                                                           
msi: routing MSI IRQ 138 to local APIC 2 vector 49                                                                                                                                                                  
rtsx0: using IRQ 138 for MSI                                                                                                                                                                                        
rtsx0: rtsx_irq_res_id: 1 - rtsx_res_id: 16                                                                                                                                                                         
rtsx0: rtsx_init() rtsx_flags = 0x0000                                                                                                                                                                              
rtsx0: Card inserted                                                                                                                                                                
rtsx0: Device attached                                                                                                                                                                      
pci5: driver added                                                                                                                                                          
mmc0: <MMC/SD bus> on rtsx0                                                                                                                                                                                     
rtsx0: rtsx_mmcbr_acquire_host()                                                                                                                                                                                    
rtsx0: Read ivar #9, value 0 / #0                                                                                                                                                                                   
rtsx0: Write ivar #7, value 0x1 / #1                                                                                                                                                                                
rtsx0: Read ivar #6, value 0x3c0000 / #3932160                                                                                                                                                                      
rtsx0: Write ivar #11, value 0x15 / #21                                                                                                                                                                             
rtsx0: Write ivar #0, value 0x1 / #1                                                                                                                                                                                
rtsx0: Write ivar #2, value 0 / #0                                                                                                                                                                                  
rtsx0: Write ivar #1, value 0 / #0                                                                                                                                                                                  
rtsx0: Write ivar #9, value 0x1 / #1                                                                                                                                                                                
rtsx0: Write ivar #3, value 0 / #0                                                                                                                                                                                  
rtsx0: rtsx_mmcbr_update_ios()                                                                                                                                                                                      
rtsx0: rtsx_bus_power_up()                                                                                                                                                                                  
rtsx0: Write ivar #12, value 0x2 / #2                                                                                                                                                                               
rtsx0: rtsx_mmcbr_switch_vccq(330)                                                                                                                                                                                  
rtsx0: Write ivar #3, value 0x61a80 / #400000                                                                                                                                                                       
rtsx0: Write ivar #14, value 0 / #0                                                                                                                                                                                 
rtsx0: Write ivar #9, value 0x2 / #2                                                                                                                                                                                
rtsx0: rtsx_mmcbr_update_ios()                                                                                                                                                                                      
rtsx0: rtsx_set_sd_clock(400000)                                                                                                                                                                                    
rtsx0: Write ivar #0, value 0x2 / #2                                                                                                                                                                                
mmc0: Probing bus                                                                                                                                                       
rtsx0: Write ivar #2, value 0x1 / #1                                                                                                                                                                                
rtsx0: rtsx_mmcbr_update_ios()                                                                                                                                                                                      
mmc0: REQUEST: CMD0 arg 0 flags 0x40                                                                                                                                                                                
rtsx0: rtsx_mmcbr_request(CMD0 arg 0 flags 0x40 dlen 0 dflags 0)                                                                                                                                                    
rtsx0: rtsx_send_cmd()                                                                                                                                                                      
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000                                                                                                                                                  
mmc0: CMD0 RESULT: 0                                                                                                                                                                
rtsx0: Write ivar #2, value 0 / #0                                                                                                                                                                                  
rtsx0: rtsx_mmcbr_update_ios()                                                                            
mmc0: REQUEST: CMD8 arg 0x1aa flags 0x75                                                                                                                                                                            
rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)                                                                                                                                                
rtsx0: rtsx_send_cmd()                                                                                                                                                                      
rtsx0: Controller timeout                                                                                                                                                                               
rtsx0: Soft reset                                                                                                                                                       
mmc0: CMD8 RESULT: 1                                                                                                                                                                
mmc0: REQUEST: CMD8 arg 0x1aa flags 0x75                                                                                                                                                                            
rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)                                                                                                                                                
rtsx0: rtsx_send_cmd()                                                                                                                                                                      
rtsx0: Controller timeout                                                                                                                                                                               
rtsx0: Soft reset                                                                                                                                                       
mmc0: CMD8 RESULT: 1                                                                                                                                                                
mmc0: REQUEST: CMD8 arg 0x1aa flags 0x75                                                                                                                                                                            
rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)                                                                                                                                                
rtsx0: rtsx_send_cmd()                                                                                                                                                                      
rtsx0: Controller timeout                                                                                                                                                                               
rtsx0: Soft reset                                                                                                                                                       
mmc0: CMD8 RESULT: 1                                                                                                                                                                
mmc0: REQUEST: CMD8 arg 0x1aa flags 0x75                                                                                                                                                                            
rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)                                                                                                                                                
rtsx0: rtsx_send_cmd()                                                                                                                                                                      
rtsx0: Controller timeout                                                                                                                                                                               
rtsx0: Soft reset                                                                                                                                                       
mmc0: CMD8 RESULT: 1                                                                                                                                                                
mmc0: REQUEST: CMD55 arg 0 flags 0x15                                                                                                                                                                               
rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)                                                                                                                                                   
rtsx0: rtsx_send_cmd()                                                                                                                                                                      
rtsx0: Controller timeout                                                                                                                                                                               
rtsx0: Soft reset                                                                                                                                                       
mmc0: CMD55 RESULT: 1                                                                                                                                                                   
mmc0: REQUEST: CMD55 arg 0 flags 0x15                                                                                                                                                                               
rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)                                                                                                                                                   
rtsx0: rtsx_send_cmd()                                                                                                                                                                      
rtsx0: Controller timeout                                                                                                                                                                               
rtsx0: Soft reset                                                                                                                                                       
mmc0: CMD55 RESULT: 1                                                                                                                                                                   
mmc0: REQUEST: CMD55 arg 0 flags 0x15                                                       
rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)                                                                                                                                                   
rtsx0: rtsx_send_cmd()                                                                                                                                                                      
rtsx0: Controller timeout
rtsx0: Soft reset
mmc0: CMD55 RESULT: 1
mmc0: REQUEST: CMD55 arg 0 flags 0x15
rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
mmc0: CMD55 RESULT: 1
mmc0: SD probe: failed
rtsx0: Write ivar #7, value 0 / #0
mmc0: REQUEST: CMD1 arg 0 flags 0x61
rtsx0: rtsx_mmcbr_request(CMD1 arg 0 flags 0x61 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
mmc0: CMD1 RESULT: 1
mmc0: REQUEST: CMD1 arg 0 flags 0x61
rtsx0: rtsx_mmcbr_request(CMD1 arg 0 flags 0x61 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
mmc0: CMD1 RESULT: 1
mmc0: REQUEST: CMD1 arg 0 flags 0x61
rtsx0: rtsx_mmcbr_request(CMD1 arg 0 flags 0x61 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
mmc0: CMD1 RESULT: 1
mmc0: REQUEST: CMD1 arg 0 flags 0x61
rtsx0: rtsx_mmcbr_request(CMD1 arg 0 flags 0x61 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
mmc0: CMD1 RESULT: 1
mmc0: MMC probe: failed
rtsx0: Write ivar #8, value 0 / #0
rtsx0: Read ivar #8, value 0 / #0
rtsx0: Read ivar #8, value 0 / #0
mmc0: Current OCR: 0x00000000
rtsx0: Read ivar #8, value 0 / #0
mmc0: No compatible cards found on bus
rtsx0: Write ivar #0, value 0x1 / #1
rtsx0: Write ivar #2, value 0 / #0
rtsx0: Write ivar #1, value 0 / #0
rtsx0: Write ivar #9, value 0 / #0
rtsx0: Write ivar #3, value 0 / #0
rtsx0: Write ivar #14, value 0 / #0
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_set_sd_clock(0)
rtsx0: rtsx_bus_power_off()
rtsx0: rtsx_mmcbr_release_host()

2hlh@restart.be: i'll try with card inserted in the evening, enocard right now :(
Comment 108 Zeus Panchenko 2020-05-28 11:47:45 UTC
(In addition to Zeus Panchenko comment #96)

FreeBSD 12.1-RELEASE-p1
Comment 109 jyoung15 2020-05-28 13:12:44 UTC
For another point of reference, it is still not working for me on a Lenovo P50s with a RTS522A.  The /dev/mmcsd0 file doesn't appear.  Using latest rtsx in github.

$ freebsd-version -kru
12.1-RELEASE-p5
12.1-RELEASE-p5
12.1-RELEASE-p5

$ pciconf -lv pci0:2:0:0    
rtsx0@pci0:2:0:0:       class=0xff0000 card=0x223317aa chip=0x522a10ec rev=0x01 hdr=0x00
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS522A PCI Express Card Reader'

The dmesg output with hw.mmc.debug=9 and debug.bootverbose=1 is shown below, after doing kldload rtsx, then removing/inserting the card.


[163] pci0: driver added
[163] found->	vendor=0x8086, dev=0x1911, revid=0x00
[163] 	domain=0, bus=0, slot=8, func=0
[163] 	class=08-80-00, hdrtype=0x00, mfdev=0
[163] 	cmdreg=0x0002, statreg=0x0010, cachelnsz=0 (dwords)
[163] 	lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
[163] 	intpin=a, irq=255
[163] 	powerspec 2  supports D0 D3  current D0
[163] 	MSI supports 1 message
[163] pci0:0:8:0: reprobing on driver added
[163] found->	vendor=0x8086, dev=0x9d31, revid=0x21
[163] 	domain=0, bus=0, slot=20, func=2
[163] 	class=11-80-00, hdrtype=0x00, mfdev=0
[163] 	cmdreg=0x0002, statreg=0x0010, cachelnsz=0 (dwords)
[163] 	lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
[163] 	intpin=c, irq=255
[163] 	powerspec 3  supports D0 D3  current D0
[163] 	MSI supports 1 message
[163] pci0:0:20:2: reprobing on driver added
[163] found->	vendor=0x8086, dev=0x9d3a, revid=0x21
[163] 	domain=0, bus=0, slot=22, func=0
[163] 	class=07-80-00, hdrtype=0x00, mfdev=1
[163] 	cmdreg=0x0002, statreg=0x0010, cachelnsz=0 (dwords)
[163] 	lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
[163] 	intpin=a, irq=255
[163] 	powerspec 3  supports D0 D3  current D0
[163] 	MSI supports 1 message, 64 bit
[163] pci0:0:22:0: reprobing on driver added
[163] found->	vendor=0x8086, dev=0x9d21, revid=0x21
[163] 	domain=0, bus=0, slot=31, func=2
[163] 	class=05-80-00, hdrtype=0x00, mfdev=1
[163] 	cmdreg=0x0002, statreg=0x0000, cachelnsz=0 (dwords)
[163] 	lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
[163] pci0:0:31:2: reprobing on driver added
[163] found->	vendor=0x8086, dev=0x9d23, revid=0x21
[163] 	domain=0, bus=0, slot=31, func=4
[163] 	class=0c-05-00, hdrtype=0x00, mfdev=0
[163] 	cmdreg=0x0003, statreg=0x0280, cachelnsz=0 (dwords)
[163] 	lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
[163] 	intpin=a, irq=255
[163] pci0:0:31:4: reprobing on driver added
[163] pci1: driver added
[163] found->	vendor=0x10ec, dev=0x522a, revid=0x01
[163] 	domain=0, bus=2, slot=0, func=0
[163] 	class=ff-00-00, hdrtype=0x00, mfdev=0
[163] 	cmdreg=0x0406, statreg=0x0010, cachelnsz=0 (dwords)
[163] 	lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
[163] 	intpin=a, irq=255
[163] 	powerspec 3  supports D0 D1 D2 D3  current D0
[163] 	MSI supports 1 message, 64 bit
[163] pci0:2:0:0: reprobing on driver added
[163] rtsx0: <Realtek RTS522A PCI MMC/SD Card Reader> mem 0xf4100000-0xf4100fff at device 0.0 on pci1
[163] rtsx0: Attach - Vendor ID: 0x10ec - Device ID: 0x522a
[163] rtsx0: attempting to allocate 1 MSI vectors (1 supported)
[163] msi: routing MSI IRQ 266 to local APIC 0 vector 59
[163] rtsx0: using IRQ 266 for MSI
[163] rtsx0: rtsx_irq_res_id: 1 - rtsx_res_id: 16
[163] rtsx0: rtsx_init() rtsx_flags = 0x0000
[163] rtsx0: Device attached
[163] pci2: driver added
[163] pci3: driver added
[186] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0x2010000
[186] rtsx0: Card inserted/removed
[186] rtsx0: No request running
[187] rtsx0: Card inserted
[187] mmc0: <MMC/SD bus> on rtsx0
[187] rtsx0: rtsx_mmcbr_acquire_host()
[187] rtsx0: Read ivar #9, value 0 / #0
[187] rtsx0: Write ivar #7, value 0x1 / #1
[187] rtsx0: Read ivar #6, value 0x3c0000 / #3932160
[187] rtsx0: Write ivar #11, value 0x15 / #21
[187] rtsx0: Write ivar #0, value 0x1 / #1
[187] rtsx0: Write ivar #2, value 0 / #0
[187] rtsx0: Write ivar #1, value 0 / #0
[187] rtsx0: Write ivar #9, value 0x1 / #1
[187] rtsx0: Write ivar #3, value 0 / #0
[187] rtsx0: rtsx_mmcbr_update_ios()
[187] rtsx0: rtsx_bus_power_up()
[187] rtsx0: Write ivar #12, value 0x2 / #2
[187] rtsx0: rtsx_mmcbr_switch_vccq(330)
[187] rtsx0: Write ivar #3, value 0x61a80 / #400000
[187] rtsx0: Write ivar #14, value 0 / #0
[187] rtsx0: Write ivar #9, value 0x2 / #2
[187] rtsx0: rtsx_mmcbr_update_ios()
[187] rtsx0: rtsx_set_sd_clock(400000)
[187] rtsx0: Write ivar #0, value 0x2 / #2
[187] mmc0: Probing bus
[187] rtsx0: Write ivar #2, value 0x1 / #1
[187] rtsx0: rtsx_mmcbr_update_ios()
[187] mmc0: REQUEST: CMD0 arg 0 flags 0x40
[187] rtsx0: rtsx_mmcbr_request(CMD0 arg 0 flags 0x40 dlen 0 dflags 0)
[187] rtsx0: rtsx_send_cmd()
[187] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0090000
[187] mmc0: CMD0 RESULT: 0
[187] rtsx0: Write ivar #2, value 0 / #0
[187] rtsx0: rtsx_mmcbr_update_ios()
[187] mmc0: REQUEST: CMD8 arg 0x1aa flags 0x75
[187] rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)
[187] rtsx0: rtsx_send_cmd()
[189] rtsx0: Controller timeout
[189] rtsx0: Soft reset
[189] mmc0: CMD8 RESULT: 1
[189] mmc0: REQUEST: CMD8 arg 0x1aa flags 0x75
[189] rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)
[189] rtsx0: rtsx_send_cmd()
[191] rtsx0: Controller timeout
[191] rtsx0: Soft reset
[191] mmc0: CMD8 RESULT: 1
[191] mmc0: REQUEST: CMD8 arg 0x1aa flags 0x75
[191] rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)
[191] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0x82080000
[193] rtsx0: Card inserted/removed
[193] rtsx0: No DMA transfert pending
[193] rtsx0: Controller timeout
[193] rtsx0: Soft reset
[193] mmc0: CMD8 RESULT: 1
[193] mmc0: REQUEST: CMD8 arg 0x1aa flags 0x75
[193] rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00000868 0x0000aa01 0x7dabff00 0x7dacff01 0x7dadffaa
[193] rtsx0: cmd->resp = 0x000001aa 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD8 RESULT: 0
[193] mmc0: SD 2.0 interface conditions: OK
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: SD probe: OK (OCR: 0x00ff8000)
[193] rtsx0: Write ivar #8, value 0xff8000 / #16744448
[193] rtsx0: Read ivar #8, value 0xff8000 / #16744448
[193] rtsx0: Write ivar #2, value 0x1 / #1
[193] rtsx0: rtsx_mmcbr_update_ios()
[193] mmc0: REQUEST: CMD0 arg 0 flags 0x40
[193] rtsx0: rtsx_mmcbr_request(CMD0 arg 0 flags 0x40 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] mmc0: CMD0 RESULT: 0
[193] rtsx0: Write ivar #2, value 0 / #0
[193] rtsx0: rtsx_mmcbr_update_ios()
[193] rtsx0: Read ivar #8, value 0xff8000 / #16744448
[193] mmc0: Current OCR: 0x00ff8000
[193] rtsx0: Read ivar #8, value 0xff8000 / #16744448
[193] rtsx0: Read ivar #7, value 0x1 / #1
[193] mmc0: REQUEST: CMD8 arg 0x1aa flags 0x75
[193] rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00000868 0x0000aa01 0x7dabff00 0x7dacff01 0x7dadffaa
[193] rtsx0: cmd->resp = 0x000001aa 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD8 RESULT: 0
[193] rtsx0: Read ivar #8, value 0xff8000 / #16744448
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002068 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00006820 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002068 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00006820 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000068 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff6800 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xff403f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0x40ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
[193] rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xffc03f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
[193] rtsx0: cmd->resp = 0xc0ff8000 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD41 RESULT: 0
[193] rtsx0: Read ivar #13, value 0x1 / #1
[193] mmc0: Probing cards
[193] mmc0: REQUEST: CMD2 arg 0 flags 0x67
[193] rtsx0: rtsx_mmcbr_request(CMD2 arg 0 flags 0x67 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x53033f68 0x314c5344 0xd8804736 0x01372470 0x00000024
[193] rtsx0: cmd->resp = 0x03534453 0x4c313647 0x80d87024 0x37012401
[193] mmc0: CMD2 RESULT: 0
[193] mmc0: New card detected (CID 035344534c31364780d8702437012401)
[193] rtsx0: rtsx_mmcbr_get_ro()
[193] rtsx0: Read ivar #7, value 0x1 / #1
[193] mmc0: REQUEST: CMD3 arg 0 flags 0x75
[193] rtsx0: rtsx_mmcbr_request(CMD3 arg 0 flags 0x75 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0xaaaa0368 0x00002005 0x7dabff00 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0xaaaa0520 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD3 RESULT: 0
[193] mmc0: REQUEST: CMD9 arg 0xaaaa0000 flags 0x67
[193] rtsx0: rtsx_mmcbr_request(CMD9 arg 0xaaaa0000 flags 0x67 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x0e403f68 0x595b3200 0xb2760000 0x400a807f 0x00000040
[193] rtsx0: cmd->resp = 0x400e0032 0x5b590000 0x76b27f80 0x0a404001
[193] mmc0: CMD9 RESULT: 0
[193] mmc0: New card detected (CSD 400e00325b59000076b27f800a404001)
[193] mmc0: REQUEST: CMD13 arg 0xaaaa0000 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD13 arg 0xaaaa0000 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00000d68 0x00000007 0x7dabffaa 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000700 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD13 RESULT: 0
[193] mmc0: REQUEST: CMD7 arg 0xaaaa0000 flags 0x1d
[193] rtsx0: rtsx_mmcbr_request(CMD7 arg 0xaaaa0000 flags 0x1d dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00000768 0x00000007 0x7dabffaa 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000700 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD7 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0xaaaa0000 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0xaaaa0000 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002009 0x7dabffaa 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000920 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD51 arg 0 flags 0x35 data 8
[193] rtsx0: rtsx_mmcbr_request(CMD51 arg 0 flags 0x35 dlen 8 dflags 0x2)
[193] rtsx0: rtsx_xfer_short() - Read xfer: 8 bytes with block size 8
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] mmc0: CMD51 RESULT: 0
[193] mmc0: REQUEST: CMD6 arg 0xffffff flags 0x35 data 64
[193] rtsx0: rtsx_mmcbr_request(CMD6 arg 0xffffff flags 0x35 dlen 64 dflags 0x2)
[193] rtsx0: rtsx_xfer_short() - Read xfer: 64 bytes with block size 64
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] mmc0: CMD6 RESULT: 0
[193] mmc0: REQUEST: CMD7 arg 0 flags 0
[193] rtsx0: rtsx_mmcbr_request(CMD7 arg 0 flags 0 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] mmc0: CMD7 RESULT: 0
[193] mmc0: REQUEST: CMD7 arg 0xaaaa0000 flags 0x1d
[193] rtsx0: rtsx_mmcbr_request(CMD7 arg 0xaaaa0000 flags 0x1d dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00000768 0x00000007 0x7dabffaa 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000700 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD7 RESULT: 0
[193] mmc0: REQUEST: CMD55 arg 0xaaaa0000 flags 0x15
[193] rtsx0: rtsx_mmcbr_request(CMD55 arg 0xaaaa0000 flags 0x15 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00003768 0x00002009 0x7dabffaa 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000920 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD55 RESULT: 0
[193] mmc0: REQUEST: CMD13 arg 0 flags 0x35 data 64
[193] rtsx0: rtsx_mmcbr_request(CMD13 arg 0 flags 0x35 dlen 64 dflags 0x2)
[193] rtsx0: rtsx_xfer_short() - Read xfer: 64 bytes with block size 64
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] mmc0: CMD13 RESULT: 0
[193] mmc0: Card at relative address 0xaaaa added:
[193] mmc0:  card: SDHC SL16G 8.0 SN D8702437 MFG 04/2018 by 3 SD
[193] mmc0:  quirks: 0
[193] mmc0:  bus: 4bit, 50MHz (high speed timing)
[193] mmc0:  memory: 31116288 blocks, erase sector 8192 blocks
[193] mmc0: REQUEST: CMD7 arg 0 flags 0
[193] rtsx0: rtsx_mmcbr_request(CMD7 arg 0 flags 0 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] mmc0: CMD7 RESULT: 0
[193] rtsx0: Read ivar #7, value 0x1 / #1
[193] mmc0: REQUEST: CMD7 arg 0xaaaa0000 flags 0x1d
[193] rtsx0: rtsx_mmcbr_request(CMD7 arg 0xaaaa0000 flags 0x1d dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00000768 0x00000007 0x7dabffaa 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000700 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD7 RESULT: 0
[193] mmc0: REQUEST: CMD7 arg 0 flags 0
[193] rtsx0: rtsx_mmcbr_request(CMD7 arg 0 flags 0 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] mmc0: CMD7 RESULT: 0
[193] rtsx0: Write ivar #0, value 0x2 / #2
[193] rtsx0: rtsx_mmcbr_update_ios()
[193] rtsx0: Read ivar #5, value 0x61a80 / #400000
[193] rtsx0: Read ivar #13, value 0x1 / #1
[193] rtsx0: Read ivar #13, value 0x1 / #1
[193] rtsx0: Read ivar #13, value 0x1 / #1
[193] mmc0: setting transfer rate to 0.400MHz (normal speed timing)
[193] mmc0: REQUEST: CMD7 arg 0xaaaa0000 flags 0x1d
[193] rtsx0: rtsx_mmcbr_request(CMD7 arg 0xaaaa0000 flags 0x1d dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: cmd_buffer: 0x00000768 0x00000007 0x7dabffaa 0x7dacff00 0x7dadff00
[193] rtsx0: cmd->resp = 0x00000700 0x00000000 0x00000000 0x00000000
[193] mmc0: CMD7 RESULT: 0
[193] rtsx0: Read ivar #7, value 0x1 / #1
[193] mmc0: REQUEST: CMD6 arg 0x80fffff0 flags 0x35 data 64
[193] rtsx0: rtsx_mmcbr_request(CMD6 arg 0x80fffff0 flags 0x35 dlen 64 dflags 0x2)
[193] rtsx0: rtsx_xfer_short() - Read xfer: 64 bytes with block size 64
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] mmc0: CMD6 RESULT: 0
[193] rtsx0: Write ivar #14, value 0 / #0
[193] rtsx0: rtsx_mmcbr_update_ios()
[193] rtsx0: Write ivar #3, value 0x61a80 / #400000
[193] rtsx0: rtsx_mmcbr_update_ios()
[193] rtsx0: rtsx_mmcbr_tune()
[193] rtsx0: Read ivar #14, value 0 / #0
[193] rtsx0: Read ivar #7, value 0x1 / #1
[193] mmc0: REQUEST: CMD7 arg 0 flags 0
[193] rtsx0: rtsx_mmcbr_request(CMD7 arg 0 flags 0 dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] mmc0: CMD7 RESULT: 0
[193] rtsx0: rtsx_mmcbr_release_host()
[193] rtsx0: Read ivar #15, value 0x100 / #256
[193] rtsx0: Read ivar #3, value 0x2faf080 / #50000000
[193] GEOM: new disk mmcsd0
[193] mmcsd0: 16GB <SDHC SL16G 8.0 SN D8702437 MFG 04/2018 by 3 SD> at mmc0 50.0MHz/4bit/256-block
[193] rtsx0: rtsx_mmcbr_acquire_host()
[193] mmc0: REQUEST: CMD7 arg 0xaaaa0000 flags 0x1drtsx0: 
[193] Card removed
[193] mmc0: rtsx0: Card at relative address 43690 deleted
[193] rtsx_mmcbr_request(CMD7 arg 0xaaaa0000 flags 0x1d dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[193] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[193] rtsx0: Soft reset
[193] mmc0: CMD7 RESULT: 1
[193] mmc0: REQUEST: CMD7 arg 0xaaaa0000 flags 0x1d
[193] rtsx0: rtsx_mmcbr_request(CMD7 arg 0xaaaa0000 flags 0x1d dlen 0 dflags 0)
[193] rtsx0: rtsx_send_cmd()
[195] rtsx0: Controller timeout
[195] rtsx0: Soft reset
[195] mmc0: CMD7 RESULT: 1
[195] mmc0: REQUEST: CMD7 arg 0xaaaa0000 flags 0x1d
[195] rtsx0: rtsx_mmcbr_request(CMD7 arg 0xaaaa0000 flags 0x1d dlen 0 dflags 0)
[195] rtsx0: rtsx_send_cmd()
[197] rtsx0: Controller timeout
[197] rtsx0: Soft reset
[197] mmc0: CMD7 RESULT: 1
[197] mmc0: REQUEST: CMD7 arg 0xaaaa0000 flags 0x1d
[197] rtsx0: rtsx_mmcbr_request(CMD7 arg 0xaaaa0000 flags 0x1d dlen 0 dflags 0)
[197] rtsx0: rtsx_send_cmd()
[199] rtsx0: Controller timeout
[199] rtsx0: Soft reset
[199] mmc0: CMD7 RESULT: 1
[199] mmc0: CMD7 failed, RESULT: 1
[199] mmc0: Card at relative address 43690 failed to select
[199] mmc0: REQUEST: CMD17 arg 0x1dacbff flags 0x35 data 512
[199] rtsx0: rtsx_mmcbr_request(CMD17 arg 0x1dacbff flags 0x35 dlen 512 dflags 0x2)
[199] rtsx0: rtsx_xfer_short() - Read xfer: 512 bytes with block size 512
[199] rtsx0: rtsx_send_cmd()
[199] rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000
[199] rtsx0: Soft reset
[199] mmc0: CMD17 RESULT: 1
[199] mmcsd0: Error indicated: 1 Timeout
[199] rtsx0: rtsx_mmcbr_release_host()
[199] rtsx0: Write ivar #0, value 0x1 / #1
[199] rtsx0: Write ivar #2, value 0 / #0
[199] rtsx0: Write ivar #1, value 0 / #0
[199] rtsx0: Write ivar #9, value 0 / #0
[199] rtsx0: Write ivar #3, value 0 / #0
[199] rtsx0: Write ivar #14, value 0 / #0
[199] rtsx0: rtsx_mmcbr_update_ios()
[199] rtsx0: rtsx_set_sd_clock(0)
[199] rtsx0: rtsx_bus_power_off()
[199] mmc0: detached
Comment 110 Henri Hennebert 2020-05-28 13:29:32 UTC
(In reply to jyoung15 from comment #109)

Just to be sure do you preload mmc and mmcsd
Comment 111 jyoung15 2020-05-28 13:36:41 UTC
(In reply to hlh from comment #110)

I am using the standard GENERIC kernel, which has those modules built-in.

$ kldstat | grep mmc
(empty output)

$ sudo kldload mmc       
kldload: can't load mmc: module already loaded or in kernel

$ sudo kldload mmcsd
kldload: can't load mmcsd: module already loaded or in kernel

If you think it will make a difference, I can comment out those devices in /usr/src/sys/amd64/conf/GENERIC and manually rebuild the kernel.
Comment 112 Henri Hennebert 2020-05-28 14:15:04 UTC
(In reply to hlh from comment #110)
(In reply to jyoung15 from comment #111)

No, don't change GENERIC. I ask because I have a specific kernel definition
without mmc and mmcsd and if I don't preload mmcsd, IIRC I encounter the same problem.

I find the following events:

- during the detection there is one interrupt "Card inserted/removed"

- mmc0: Card at relative address 0xaaaa added

- mmcsd0: 16GB <SDHC SL16G 8.0 SN D8702437 MFG 04/2018 by 3 SD> at mmc0

- rtsx0:  Card removed
  mmc0: rtsx0: Card at relative address 43690 deleted

The interrupt and the discrepancy of address is really strange.

Is the card well inserted: contact firmly established?
Comment 113 Jacob Meadows 2020-05-28 14:22:07 UTC
Thank you for all your hard work on this.  I have a Realtek RTS525A in my Dell Latitude E5570.  My FreeBSD version is 12.1-RELEASE-p5, and I am using the GENERIC kernel.  I just downloaded and installed the driver from Git, when loaded it will not show as attached to the device in pciconf, and no access to an SD card is available.  When I load the driver, dmesg outputs this:

pci0: driver added
found->	vendor=0x8086, dev=0x1903, revid=0x07
	domain=0, bus=0, slot=4, func=0
	class=11-80-00, hdrtype=0x00, mfdev=0
	cmdreg=0x0002, statreg=0x0090, cachelnsz=0 (dwords)
	lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
	intpin=a, irq=255
	powerspec 3  supports D0 D3  current D0
	MSI supports 1 message
pci0:0:4:0: reprobing on driver added
found->	vendor=0x8086, dev=0xa131, revid=0x31
	domain=0, bus=0, slot=20, func=2
	class=11-80-00, hdrtype=0x00, mfdev=0
	cmdreg=0x0002, statreg=0x0010, cachelnsz=0 (dwords)
	lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
	intpin=c, irq=255
	powerspec 3  supports D0 D3  current D0
	MSI supports 1 message
pci0:0:20:2: reprobing on driver added
found->	vendor=0x8086, dev=0xa13a, revid=0x31
	domain=0, bus=0, slot=22, func=0
	class=07-80-00, hdrtype=0x00, mfdev=1
	cmdreg=0x0002, statreg=0x0010, cachelnsz=0 (dwords)
	lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
	intpin=a, irq=255
	powerspec 3  supports D0 D3  current D0
	MSI supports 1 message, 64 bit
pci0:0:22:0: reprobing on driver added
found->	vendor=0x8086, dev=0xa121, revid=0x31
	domain=0, bus=0, slot=31, func=2
	class=05-80-00, hdrtype=0x00, mfdev=1
	cmdreg=0x0002, statreg=0x0000, cachelnsz=0 (dwords)
	lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
pci0:0:31:2: reprobing on driver added
pci1: driver added
pci2: driver added
pci3: driver added
found->	vendor=0x10ec, dev=0x525a, revid=0x01
	domain=0, bus=3, slot=0, func=0
	class=ff-00-00, hdrtype=0x00, mfdev=0
	cmdreg=0x0006, statreg=0x0010, cachelnsz=0 (dwords)
	lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
	intpin=a, irq=255
	powerspec 3  supports D0 D1 D2 D3  current D0
	MSI supports 1 message, 64 bit
pci0:3:0:0: reprobing on driver added
rtsx0: <Realtek RTS525A PCI MMC/SD Card Reader> mem 0xef000000-0xef000fff at device 0.0 on pci3
rtsx0: Attach - Vendor ID: 0x10ec - Device ID: 0x525a
rtsx0: attempting to allocate 1 MSI vectors (1 supported)
msi: routing MSI IRQ 270 to local APIC 4 vector 52
rtsx0: using IRQ 270 for MSI
rtsx0: Can't allocate memory resource for 16
device_attach: rtsx0 attach returned 6

pciconf -lv shows this for the device:
none4@pci0:3:0:0:	class=0xff0000 card=0x06df1028 chip=0x525a10ec rev=0x01 hdr=0x00
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS525A PCI Express Card Reader'
Comment 114 Lutz Bichler 2020-05-28 14:36:57 UTC
Does it change something if you add the following after line 2237: 

if (sc->rtsx_flags & RTSX_F_525A)
    sc->rtsx_res_id = PCIR_BAR(1);
Comment 115 Gary Jennejohn 2020-05-28 14:42:06 UTC
(In reply to Lutz Bichler from comment #114)
That should do it.  There should be a check in the code for the 525A because it must use a different PCI BAR from all the other controllers.
Comment 116 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-28 14:44:10 UTC
(In reply to Gary Jennejohn from comment #115)
Yup, all changes from https://github.com/openbsd/src/commit/2c295edd2d779a7f5269c2ae901559edbf040016 are not ported only the power related one
Comment 117 Henri Hennebert 2020-05-28 15:00:29 UTC
(In reply to Jesper Schmitz Mouridsen from comment #116)

pciconf -lb would be helpfull
Comment 118 Henri Hennebert 2020-05-28 15:14:25 UTC
(In reply to Lutz Bichler from comment #114)

I update github.
thanks
Comment 119 Henri Hennebert 2020-05-28 15:40:30 UTC
WARNING - during the style(9) update I mess something in card insert/remove.

A card remove produce a panic :-/
Comment 120 Henri Hennebert 2020-05-28 15:53:37 UTC
A stupid error corrected in rtsx_card_task()

github updated

sorry
Comment 121 Jacob Meadows 2020-05-28 17:14:43 UTC
(In reply to hlh from comment #118)
Thank you.  This (almost) worked.  The driver is now properly attached to the device, but I am having a similar (or same) problem as jyoung15 reported.  If you want, I can post my dmesg, but as it is similar to jyoung15's, and rather long, I will only post if you want it.
Comment 122 Henri Hennebert 2020-05-28 17:42:35 UTC
(In reply to Jacob Meadows from comment #121)
Do you see "Card inserted/removed" during the card detection as in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=204521#c112

(comment 112)

Post your log as a attachment
Comment 123 Jacob Meadows 2020-05-28 19:08:47 UTC
Created attachment 214987 [details]
Card Inserted dmesg
Comment 124 Jacob Meadows 2020-05-28 19:19:14 UTC
(In reply to hlh from comment #122)
I've added my dmesg as an attachment.  It is recognizing the card installed, but seems to be some errors.  When I remove the card, the driver recognizes that as well:

rtsx0: Interrupt handler - enabled: 0x32000000, status: 0x2000000
rtsx0: Card inserted/removed
rtsx0: No request running
rtsx0: Card removed
rtsx0: Write ivar #0, value 0x1 / #1
rtsx0: Write ivar #2, value 0 / #0
rtsx0: Write ivar #1, value 0 / #0
rtsx0: Write ivar #9, value 0 / #0
rtsx0: Write ivar #3, value 0 / #0
rtsx0: Write ivar #14, value 0 / #0
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_set_sd_clock(0)
rtsx0: rtsx_bus_power_off()
mmc0: detached

It's getting close.  I am so thankful for the work you have put in!
Comment 125 jyoung15 2020-05-28 19:38:23 UTC
I've made some progress with the issue I'm having.  I noticed in the dmesg output it seems to incorrectly detect when the card is inserted and removed.  Specifically the issue seems to be in rtsx_is_card_present.  As a very quick and dirty hack, I made this change so it always reports the card as present:

diff --git a/rtsx.c b/rtsx.c
index 0010bc7..a38668e 100644
--- a/rtsx.c
+++ b/rtsx.c
@@ -1122,7 +1122,8 @@ rtsx_is_card_present(struct rtsx_softc *sc)
        uint32_t status;
 
        status = READ4(sc, RTSX_BIPR);
-       return (status & RTSX_SD_EXIST);
+       // return (status & RTSX_SD_EXIST);
+       return RTSX_SD_EXIST;
 }


After making this change I'm able to see the device in /dev and mount the filesystem successfully.  So it seems the issue is related to detecting if the card is present on the BIPR register.
Comment 126 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-28 20:54:00 UTC
Created attachment 214992 [details]
do not read BIPR to often..

this could help #comment 125
Comment 127 jyoung15 2020-05-28 21:04:52 UTC
(In reply to Jesper Schmitz Mouridsen from comment #126)

Unfortunately there is no improvement with the patch.  Oddly it seems the card sensing is opposite of what it should be.

With this simple change, it seems to be working perfectly for me:

diff --git a/rtsx.c b/rtsx.c
index 13ce3df..4f5e34f 100644
--- a/rtsx.c
+++ b/rtsx.c
@@ -548,7 +548,7 @@ rtsx_is_card_present(struct rtsx_softc *sc)
        uint32_t status;
 
        status = READ4(sc, RTSX_BIPR);
-       return (status & RTSX_SD_EXIST);
+       return !(status & RTSX_SD_EXIST);
 }
 


With the above change, the /dev/mmcsd0 file appears when inserting the card and disappears when removing the card.  Also, the "rtsx0: Card removed" and "rtsx0: Card inserted" messages appear as expected (previously it would say removed when inserted and vice versa).  I can't explain why, but this works for me.
Comment 128 Lyubomir 2020-05-29 05:48:18 UTC
Thanks for the great work. I can confirm that it compiles and loads on:
Lenovo T450
pciconf -lv

rtsx0@pci0:2:0:0: class=0xff0000 card=0x503417aa chip=0x522710ec rev=0x01 hdr=0x00
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS5227 PCI Express Card Reader'

FreeBSD 12.1-RELEASE-p5 GENERIC amd64

I can also copy from and to the inserted card (2GB at the moment available).
dmesg

rtsx0: <Realtek RTS5227 PCI MMC/SD Card Reader> mem 0xf1100000-0xf1100fff irq 16 at device 0.0 on pci1
rtsx0: Card inserted/removed
rtsx0: No request running
mmc0: <MMC/SD bus> on rtsx0
mmcsd0: 32GB <SDHC USD00 0.2 SN 26157BA2 MFG 06/2016 by 156 SO> at mmc0 50.0MHz/4bit/256-block

Here is the output from the compilation:
t450:~/rtsx.git/trunk % make
machine -> /usr/src/sys/amd64/include
x86 -> /usr/src/sys/x86/include
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/kern/device_if.m -h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/kern/bus_if.m -h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/dev/pci/pci_if.m -h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/dev/mmc/mmcbr_if.m -h
Warning: Object directory not changed from original /usr/home/lyubd/rtsx.git/trunk
cc  "-ferror-limit=0"  -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include   -MD  -MF.depend.rtsx.o -MTrtsx.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error-tautological-compare -Wno-error-empty-body -Wno-error-parentheses-equality -Wno-error-unused-function -Wno-error-pointer-sign -Wno-error-shift-negative-value -Wno-address-of-packed-member  -mno-aes -mno-avx  -std=iso9899:1999 -c rtsx.c -o rtsx.o
rtsx.c:1180:1: warning: unused function 'rtsx_led_enable' [-Wunused-function]
rtsx_led_enable(struct rtsx_softc *sc)
^
rtsx.c:1199:1: warning: unused function 'rtsx_led_disable' [-Wunused-function]
rtsx_led_disable(struct rtsx_softc *sc)
^
2 warnings generated.
ld -m elf_x86_64_fbsd -d -warn-common --build-id=sha1 -r -d -o rtsx.ko rtsx.o
:> export_syms
awk -f /usr/src/sys/conf/kmod_syms.awk rtsx.ko  export_syms | xargs -J% objcopy % rtsx.ko
objcopy --strip-debug rtsx.ko

Regards,
Lyubomir
Comment 129 Zeus Panchenko 2020-05-29 06:28:57 UTC
when an empty microSD adaptor inserted first and the very microSD card inserted after that, I see CRC errors

kldunload/load doesn't help, only reboot

> uname
FreeBSD 12.1-RELEASE-p3 GENERIC amd64

> git log
commit d02fc0ebfc0983cc1ed9e00657b2316fda1c36fe


here dmesg output for these actions:
1. module unload/load
2. insert/remove microSD adaptor with card
3. insert an empty microSD adaptor
4. insert a card into the microSD adaptor

full dmesg uploaded here: https://pastebin.com/JVGvPKxm

> dmesg

rtsx0: detached
pci2: <unknown> at device 0.0 (no driver attached)
rtsx0: <Realtek RTS5227 PCI MMC/SD Card Reader> mem 0xc1200000-0xc1200fff at device 0.0 on pci2
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0x2010000
rtsx0: Card inserted/removed
rtsx0: No request running
rtsx0: Card inserted
mmc0: <MMC/SD bus> on rtsx0
rtsx0: rtsx_mmcbr_acquire_host()
rtsx0: Read ivar #9, value 0 / #0
rtsx0: Write ivar #7, value 0x1 / #1
rtsx0: Read ivar #6, value 0x3c0000 / #3932160
rtsx0: Write ivar #11, value 0x15 / #21
rtsx0: Write ivar #0, value 0x1 / #1
rtsx0: Write ivar #2, value 0 / #0
rtsx0: Write ivar #1, value 0 / #0
rtsx0: Write ivar #9, value 0x1 / #1
rtsx0: Write ivar #3, value 0 / #0
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_bus_power_up()
rtsx0: Write ivar #12, value 0x2 / #2
rtsx0: rtsx_mmcbr_switch_vccq(330)
rtsx0: Write ivar #3, value 0x61a80 / #400000
rtsx0: Write ivar #14, value 0 / #0
rtsx0: Write ivar #9, value 0x2 / #2
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_set_sd_clock(400000)
rtsx0: Write ivar #0, value 0x2 / #2
mmc0: Probing bus
rtsx0: Write ivar #2, value 0x1 / #1
rtsx0: rtsx_mmcbr_update_ios()
mmc0: REQUEST: CMD0 arg 0 flags 0x40
rtsx0: rtsx_mmcbr_request(CMD0 arg 0 flags 0x40 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0090000
mmc0: CMD0 RESULT: 0
rtsx0: Write ivar #2, value 0 / #0
rtsx0: rtsx_mmcbr_update_ios()
mmc0: REQUEST: CMD8 arg 0x1aa flags 0x75
rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0090000
rtsx0: cmd_buffer: 0x00000868 0x0000aa01 0x7dabff00 0x7dacff01 0x7dadffaa
rtsx0: cmd->resp = 0x000001aa 0x00000000 0x00000000 0x00000000
mmc0: CMD8 RESULT: 0
mmc0: SD 2.0 interface conditions: OK
mmc0: REQUEST: CMD55 arg 0 flags 0x15
rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0090000
rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
mmc0: CMD55 RESULT: 0
mmc0: REQUEST: CMD41 arg 0 flags 0x61
rtsx0: rtsx_mmcbr_request(CMD41 arg 0 flags 0x61 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0090000
rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabff00 0x7dacff00 0x7dadff00
rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
mmc0: CMD41 RESULT: 0
mmc0: SD probe: OK (OCR: 0x00ff8000)
rtsx0: Write ivar #8, value 0xff8000 / #16744448
rtsx0: Read ivar #8, value 0xff8000 / #16744448
rtsx0: Write ivar #2, value 0x1 / #1
rtsx0: rtsx_mmcbr_update_ios()
mmc0: REQUEST: CMD0 arg 0 flags 0x40
rtsx0: rtsx_mmcbr_request(CMD0 arg 0 flags 0x40 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0090000
mmc0: CMD0 RESULT: 0
rtsx0: Write ivar #2, value 0 / #0
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: Read ivar #8, value 0xff8000 / #16744448
mmc0: Current OCR: 0x00ff8000
rtsx0: Read ivar #8, value 0xff8000 / #16744448
rtsx0: Read ivar #7, value 0x1 / #1
mmc0: REQUEST: CMD8 arg 0x1aa flags 0x75
rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
...
mmc0: CMD41 RESULT: 0
mmc0: REQUEST: CMD55 arg 0 flags 0x15
rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0090000
rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
mmc0: CMD55 RESULT: 0
mmc0: REQUEST: CMD41 arg 0x40ff8000 flags 0x61
rtsx0: rtsx_mmcbr_request(CMD41 arg 0x40ff8000 flags 0x61 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0090000
rtsx0: cmd_buffer: 0xff003f68 0x00000080 0x7dabffff 0x7dacff80 0x7dadff00
rtsx0: cmd->resp = 0x00ff8000 0x00000000 0x00000000 0x00000000
mmc0: CMD41 RESULT: 0
mmc0: REQUEST: CMD55 arg 0 flags 0x15
rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0090000
rtsx0: cmd_buffer: 0x00003768 0x00002001 0x7dabff00 0x7dacff00 0x7dadff00
rtsx0: cmd->resp = 0x00000120 0x00000000 0x00000000 0x00000000
mmc0: CMD55 RESULT: 0
...
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0090000
mmc0: CMD7 RESULT: 0
rtsx0: rtsx_mmcbr_release_host()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0x2000000
rtsx0: Card inserted/removed
rtsx0: No request running
rtsx0: Card removed
rtsx0: Write ivar #0, value 0x1 / #1
rtsx0: Write ivar #2, value 0 / #0
rtsx0: Write ivar #1, value 0 / #0
rtsx0: Write ivar #9, value 0 / #0
rtsx0: Write ivar #3, value 0 / #0
rtsx0: Write ivar #14, value 0 / #0
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_set_sd_clock(0)
rtsx0: rtsx_bus_power_off()
mmc0: detached
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0x2010000
rtsx0: Card inserted/removed
rtsx0: No request running
rtsx0: Card inserted
mmc0: <MMC/SD bus> on rtsx0
rtsx0: rtsx_mmcbr_acquire_host()
rtsx0: Read ivar #9, value 0 / #0
rtsx0: Write ivar #7, value 0x1 / #1
rtsx0: Read ivar #6, value 0x3c0000 / #3932160
rtsx0: Write ivar #11, value 0x15 / #21
rtsx0: Write ivar #0, value 0x1 / #1
rtsx0: Write ivar #2, value 0 / #0
rtsx0: Write ivar #1, value 0 / #0
rtsx0: Write ivar #9, value 0x1 / #1
rtsx0: Write ivar #3, value 0 / #0
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_bus_power_up()
rtsx0: Write ivar #12, value 0x2 / #2
rtsx0: rtsx_mmcbr_switch_vccq(330)
rtsx0: Write ivar #3, value 0x61a80 / #400000
rtsx0: Write ivar #14, value 0 / #0
rtsx0: Write ivar #9, value 0x2 / #2
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_set_sd_clock(400000)
rtsx0: Write ivar #0, value 0x2 / #2
mmc0: Probing bus
rtsx0: Write ivar #2, value 0x1 / #1
rtsx0: rtsx_mmcbr_update_ios()
mmc0: REQUEST: CMD0 arg 0 flags 0x40
rtsx0: rtsx_mmcbr_request(CMD0 arg 0 flags 0x40 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
...
rtsx0: CRC error
rtsx0: Soft reset
mmc0: CMD17 RESULT: 2
rtsx0: rtsx_mmcbr_release_host()
rtsx0: rtsx_mmcbr_acquire_host()
mmc0: REQUEST: CMD17 arg 0x10 flags 0x35 data 512
rtsx0: rtsx_mmcbr_request(CMD17 arg 0x10 flags 0x35 dlen 512 dflags 0x2)
rtsx0: rtsx_xfer_short() - Read xfer: 512 bytes with block size 512
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0x90090080
rtsx0: CRC error
rtsx0: Soft reset
mmc0: CMD17 RESULT: 2
rtsx0: rtsx_mmcbr_release_host()
rtsx0: rtsx_mmcbr_acquire_host()
mmc0: REQUEST: CMD17 arg 0x80 flags 0x35 data 512
rtsx0: rtsx_mmcbr_request(CMD17 arg 0x80 flags 0x35 dlen 512 dflags 0x2)
rtsx0: rtsx_xfer_short() - Read xfer: 512 bytes with block size 512
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0x90090080
rtsx0: CRC error
rtsx0: Soft reset
mmc0: CMD17 RESULT: 2
rtsx0: rtsx_mmcbr_release_host()
rtsx0: rtsx_mmcbr_acquire_host()
mmc0: REQUEST: CMD17 arg 0 flags 0x35 data 512
rtsx0: rtsx_mmcbr_request(CMD17 arg 0 flags 0x35 dlen 512 dflags 0x2)
rtsx0: rtsx_xfer_short() - Read xfer: 512 bytes with block size 512
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0x90090080
rtsx0: CRC error
rtsx0: Soft reset
mmc0: CMD17 RESULT: 2
rtsx0: rtsx_mmcbr_release_host()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0x2000000
rtsx0: Card inserted/removed
rtsx0: No request running
rtsx0: Card removed
mmc0: Card at relative address 7 deleted
rtsx0: Write ivar #0, value 0x1 / #1
rtsx0: Write ivar #2, value 0 / #0
rtsx0: Write ivar #1, value 0 / #0
rtsx0: Write ivar #9, value 0 / #0
rtsx0: Write ivar #3, value 0 / #0
rtsx0: Write ivar #14, value 0 / #0
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_set_sd_clock(0)
rtsx0: rtsx_bus_power_off()
mmc0: detached
Comment 130 Gary Jennejohn 2020-05-29 06:50:21 UTC
(In reply to jyoung15 from comment #127)
This appears to be a strange bug in your hardware.  The Linux code also depends on the bit being set in BIPR to determine whether a card is inserted.  Since Realtek developed the Linux driver I'd have to say that it's the gold standard.
Comment 131 Henri Hennebert 2020-05-29 06:53:03 UTC
(In reply to jyoung15 from comment #127)
Just to check if ther is a timing problem, can you try:

diff --git a/rtsx.c b/rtsx.c
index 13ce3df..6da1b1c 100644
--- a/rtsx.c
+++ b/rtsx.c
@@ -547,6 +547,7 @@ rtsx_is_card_present(struct rtsx_softc *sc)
 {
        uint32_t status;
 
+       DELAY(200);
        status = READ4(sc, RTSX_BIPR);
        return (status & RTSX_SD_EXIST);
 }
Comment 132 Gary Jennejohn 2020-05-29 06:56:05 UTC
(In reply to hlh from comment #131)
Good idea.
Comment 133 Gary Jennejohn 2020-05-29 06:57:57 UTC
(In reply to Zeus Panchenko from comment #129)
I would suggest putting the SD card into the holder and then inserting it.  Poor contact of the card in the holder will lead to errors.
Comment 134 jyoung15 2020-05-29 12:42:04 UTC
(In reply to hlh from comment #131)

Unfortunately the added DELAY did not make any difference for me.  Regarding the comment about a hardware issue, this is a dual-boot laptop and the card reader works fine on Windows.  Anyway, I have found a workaround for my issue and the rtsx driver works fine otherwise.  Thanks to all involved for your efforts.
Comment 135 Henri Hennebert 2020-05-29 12:53:08 UTC
(In reply to jyoung15 from comment #134)
I can't change the source because it work for other RTS522A.
Really strange...
Comment 136 Henri Hennebert 2020-05-29 14:20:35 UTC
(In reply to jyoung15 from comment #134)

Just to be sure, as I mess up in power control, can you test with the new github.
Thanks.
Comment 137 Henri Hennebert 2020-05-29 14:22:11 UTC
(In reply to Jacob Meadows from comment #124)

As I mess up with power control, can you test again.
Thanks
Comment 138 Jacob Meadows 2020-05-29 15:45:02 UTC
(In reply to hlh from comment #137)
It is still not working, but the error messages are different.  It does detect the card being inserted and removed, but the /dev/mmc0 is not being created.  Here is the current dmesg when I insert a card.

rtsx0: Interrupt handler - enabled: 0x32000000, status: 0x2010000
rtsx0: Interrupt card inserted/removed
rtsx0: No request running
rtsx0: Card inserted
mmc0: <MMC/SD bus> on rtsx0
rtsx0: rtsx_mmcbr_acquire_host()
rtsx0: Read ivar #9, value 0 / #0
rtsx0: Write ivar #7, value 0x1 / #1
rtsx0: Read ivar #6, value 0x3c0000 / #3932160
rtsx0: Write ivar #11, value 0x15 / #21
rtsx0: Write ivar #0, value 0x1 / #1
rtsx0: Write ivar #2, value 0 / #0
rtsx0: Write ivar #1, value 0 / #0
rtsx0: Write ivar #9, value 0x1 / #1
rtsx0: Write ivar #3, value 0 / #0
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_bus_power_on()
rtsx0: Write ivar #12, value 0x2 / #2
rtsx0: rtsx_mmcbr_switch_vccq(330)
rtsx0: Write ivar #3, value 0x61a80 / #400000
rtsx0: Write ivar #14, value 0 / #0
rtsx0: Write ivar #9, value 0x2 / #2
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_set_sd_clock(400000)
rtsx0: Write ivar #0, value 0x2 / #2
mmc0: Probing bus
rtsx0: Write ivar #2, value 0x1 / #1
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_mmcbr_request(CMD0 arg 0 flags 0x40 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0010000
rtsx0: Write ivar #2, value 0 / #0
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
mmc0: SD probe: failed
rtsx0: Write ivar #7, value 0 / #0
rtsx0: rtsx_mmcbr_request(CMD1 arg 0 flags 0x61 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
wlan0: link state changed to UP
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: rtsx_mmcbr_request(CMD1 arg 0 flags 0x61 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: rtsx_mmcbr_request(CMD1 arg 0 flags 0x61 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: rtsx_mmcbr_request(CMD1 arg 0 flags 0x61 dlen 0 dflags 0)
rtsx0: rtsx_send_cmd()
rtsx0: Controller timeout
rtsx0: Soft reset
mmc0: MMC probe: failed
rtsx0: Write ivar #8, value 0 / #0
rtsx0: Read ivar #8, value 0 / #0
rtsx0: Read ivar #8, value 0 / #0
mmc0: Current OCR: 0x00000000
rtsx0: Read ivar #8, value 0 / #0
mmc0: No compatible cards found on bus
rtsx0: Write ivar #0, value 0x1 / #1
rtsx0: Write ivar #2, value 0 / #0
rtsx0: Write ivar #1, value 0 / #0
rtsx0: Write ivar #9, value 0 / #0
rtsx0: Write ivar #3, value 0 / #0
rtsx0: Write ivar #14, value 0 / #0
rtsx0: rtsx_mmcbr_update_ios()
rtsx0: rtsx_set_sd_clock(0)
rtsx0: rtsx_bus_power_off()
rtsx0: rtsx_mmcbr_release_host()
Comment 139 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-29 16:01:32 UTC
(In reply to hlh from comment #137)
Hi for 5209 and 5229 you do not want full power in bus power_on, it breaks, and might also break for RTS522A but I have only access to 5209 and 5229. I switched calls in #attachment 214840 [details], and you switched implementation in git instead.  Now it seems you have switched them back, and it breaks at least for 5209 and 5229
Comment 140 Henri Hennebert 2020-05-29 16:22:40 UTC
(In reply to Jesper Schmitz Mouridsen from comment #139)

I forget to put the right message when switching back the content of the power_xx(). So it is just in power_up and not power_on.

I found that rtsx_mmcbr_update_ios() never encounter a power_on.

You was right when you switch power_up and power_on because so you do a power_on when a power_up was requested.

In the github I push now, I change the switch in rtsx_mmcbr_update_ios()

        switch (ios->power_mode) {                                                                                                  
        case power_off:                                                                                                             
                if (sc->rtsx_power_mode != power_off) {                                                                             
                        rtsx_bus_power_off(sc);                                                                                     
                        sc->rtsx_power_mode = power_off;                                                                            
                }                                                                                                                   
                break;                                                                                                              
        case power_up:                                                                                                              
//              if (sc->rtsx_power_mode != power_up) {                                                                              
//                      rtsx_bus_power_up(sc);                                                                                      
//                      sc->rtsx_power_mode = power_up;                                                                             
//              }                                                                                                                   
//              break;                                                                                                              
        case power_on:                                                                                                              
                if (sc->rtsx_power_mode != power_on) {                                                                              
                        rtsx_bus_power_on(sc);                                                                                      
                        sc->rtsx_power_mode = power_on;                                                                             
                }                                                                                                                   
                break;                                                                                                              
        };

To be more coherent (if it is possible ;-)

Can you please test with this last update
thanks
Comment 141 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-29 16:40:50 UTC
(In reply to hlh from comment #140)
Yes, it works again.
Comment 142 Gary Jennejohn 2020-05-30 07:04:51 UTC
(In reply to jyoung15 from comment #134)
I wonder whether this strange behavior is generic to the Lenovo P50s or just on your laptop.  Would be good if we could get a report from another user of this laptop.
Considering that Lenovo provides its own Windows driver for the card reader, the fact that it works in Windows doesn't disprove that there's a bug.
Comment 143 Gary Jennejohn 2020-05-30 07:08:29 UTC
@hlh
I read the man page and it looks pretty good for a start.
Thanks for listing me as an author, alhough I didn't contribute much.  Can you use my gj@freebsd.org mail address?  I'm not an active committer any more but I do still have the mail address.
Thanks.
Comment 144 Gary Jennejohn 2020-05-30 07:55:07 UTC
(In reply to Gary Jennejohn from comment #142)
The reason I'm harping on this is, if the card detection inversion is common enough, it might be possible to get a config(8) option like RTSX_CARD_DETECT_INVERTED added which affected users could set in their kernel configuration files.  And then document it in the man page.
Comment 145 Henri Hennebert 2020-05-30 12:00:07 UTC
(In reply to Jacob Meadows from comment #138)

I pull some stuff for RTS525A from Linux

Can you please test with the last github
Comment 146 Jacob Meadows 2020-05-31 00:20:15 UTC
(In reply to hlh from comment #145)
This works!  I was able to successfully insert a 64GB SDXC card formatted in exFat, mount it with FUSE, read and write files about 4GB in size.  Thank you so much!

Dell Latitude E5570, with Realtek RTS525A PCI Express card reader, confirmed to work!
Comment 147 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-05-31 10:28:05 UTC
(In reply to Sergey V. Dyatko from comment #107)
Your dmesg says rtsx0: Card inserted, and you have no card inserted?

Perhaps you are hit by the inverted card detection on RTS522A problem that jyoung15@gmail.com worked around in #comment 127
Comment 148 Henri Hennebert 2020-05-31 16:10:58 UTC
(In reply to Jesper Schmitz Mouridsen from comment #147)

I add some specific code for RTS522A. there is one difference depending on the chip version. Maybe it solve the strange problem of card detection.
Comment 149 Gary Jennejohn 2020-06-01 07:42:11 UTC
(In reply to hlh from comment #148)
I can report that this change did not affect my 522A.
I now see non-fatal lock order reversals when I remove the SD card.  I don't remember seeing them last week.  But the kernel contains lots of this type of lock order reversal, so nothing to worry about.
Comment 150 Henri Hennebert 2020-06-01 08:27:58 UTC
(In reply to Gary Jennejohn from comment #149)

rtsx_handle_card_present() is called in rtsx_intr() with the LOCK active.
This function schedule immediately rtsx_card_task() and this one acquire the LOCK, make some processing and UNLOCK. maybe during this processing the rtsx_intr() complete and UNLOCK.
Comment 151 Henri Hennebert 2020-06-01 08:45:40 UTC
(In reply to hlh from comment #150)

maybe the culprit:

In a commit on May 28 in rtsx_card_task() I put the UNLOCK after
sc->rtsx_mmc_dev = NULL. It seems logical since sc struct is modified.

In your original code, the UNLOCK was before device_delete_child().
Comment 152 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-06-01 09:46:41 UTC
(In reply to hlh from comment #151)
lock order reversal: (Giant after non-sleepable)
 1st 0xfffff80004e0fc00 rtsx0 (rtsx) @ rtsx.c:513
 2nd 0xffffffff81802500 Giant (Giant) @ /usr/src/sys/kern/kern_synch.c:228
stack backtrace:
#0 0xffffffff80c2acc1 at witness_debugger+0x71
#1 0xffffffff80b9c844 at __mtx_lock_flags+0x94
#2 0xffffffff80bca5c6 at _sleep+0x366
#3 0xffffffff8071c341 at mmcsd_detach+0xe1
#4 0xffffffff80bf63ee at device_detach+0x18e
#5 0xffffffff80bf60c5 at device_delete_child+0x15
#6 0xffffffff8071a0c7 at mmc_delete_cards+0x97
#7 0xffffffff80712e43 at mmc_detach+0x23
#8 0xffffffff80bf63ee at device_detach+0x18e
#9 0xffffffff80bf60c5 at device_delete_child+0x15
#10 0xffffffff82322b0f at rtsx_card_task+0x1bf
#11 0xffffffff80c1d5fa at taskqueue_run_locked+0xaa
#12 0xffffffff80c1d50d at taskqueue_run+0x4d
#13 0xffffffff80b7f379 at ithread_loop+0x279
#14 0xffffffff80b7bec0 at fork_exit+0x80
#15 0xffffffff81031aae at fork_trampoline+0xe
uma_zalloc_debug: zone "256" with the following non-sleepable locks held:
exclusive sleep mutex rtsx0 (rtsx) r = 0 (0xfffff80004e0fc00) locked @ rtsx.c:513
unlocking before delete_device_child as you noted fixes it
Comment 153 Gary Jennejohn 2020-06-01 10:14:03 UTC
(In reply to Jesper Schmitz Mouridsen from comment #152)
Right, so unlock before device_delete_child() and re-lock before the write to sc->rtsx_mmc_dev.  It tried this change, it works and eliminates the lock reversal.
Comment 154 Henri Hennebert 2020-06-01 10:26:48 UTC
(In reply to Gary Jennejohn from comment #153)
LOCK / UNLOCK for sc->rtsx_mmc_dev = NULL; seems useless to me.
Comment 155 Gary Jennejohn 2020-06-01 10:42:22 UTC
(In reply to hlh from commsc->rtsx_mmc_devent #154)
This disagress with your comment in 151, which implies you were worried about modifying sc->rtsx_mmc_dev when it's not under the lock.  If that's the case then it should be re-locked beforehand.
IMO reacquiring the lock is no big deal.  It's not like this code is executed millions of time per second.  And it makes it clear exactly why the lock is being used.
Comment 156 Henri Hennebert 2020-06-01 10:58:26 UTC
(In reply to Gary Jennejohn from comment #155)

In this case:

       if (device_delete_child(sc->rtsx_dev, sc->rtsx_mmc_dev))
               device_printf(sc->rtsx_dev, "Detaching MMC bus failed\n");
       sc->rtsx_mmc_dev = NULL;
       RTSX_UNLOCK(sc);

The LOCK try to postpone a new occurrence of rtsx_card_task()
to reconnect a card.

In this case:

       RTSX_UNLOCK(sc);
       if (device_delete_child(sc->rtsx_dev, sc->rtsx_mmc_dev))
               device_printf(sc->rtsx_dev, "Detaching MMC bus failed\n");
       sc->rtsx_mmc_dev = NULL;


A new occurrence of rtsx_card_task() may reconnect a card and then
rtsx_mmc_dev is replace by NULL. And so even if it is bracketed by LOCL/UNLOCK.
Comment 157 Gary Jennejohn 2020-06-01 11:04:39 UTC
(In reply to hlh from comment #156)
OK, I'm convinced.  Now we both know why the original code was correct :)
Comment 158 Gleb Popov freebsd_committer freebsd_triage 2020-06-01 13:38:25 UTC
It is awesome to see progress on this.

I wrote a FreeBSD port that pulls sources from GitHub, compiles the kmod and installs it. We can use it to gain wider testing audience.

Henri, once you're confident with the code, add a tag and I will use it to commit the port.

And thanks again everyone involved!
Comment 159 Henri Hennebert 2020-06-01 14:15:25 UTC
(In reply to Gleb Popov from comment #158)

Thank you!

I am waiting for a test by jyoung15@gmail.com about the RTS522A.

Can you test the driver on your notebook and report the
Realtek device and FreeBSD version to complete the README.md

thanks
Comment 160 Gleb Popov freebsd_committer freebsd_triage 2020-06-01 20:18:49 UTC
Loading the driver results in

rtsx0: <Realtek RTS5229 PCI MMC/SD Card Reader> mem 0xdf100000-0xdf100fff at device 0.0 on pci4

but nothing else. mmc and mmcsd are already loaded.
Comment 161 Gleb Popov freebsd_committer freebsd_triage 2020-06-01 20:24:14 UTC
Oh, I inserted a card and new device appeared. I haven't done extensive testing, though,
Comment 162 Henri Hennebert 2020-06-02 05:37:34 UTC
(In reply to Gleb Popov from comment #161)

It is the first test for RTS5229.

Can you try read and write operation on /dec/mmcsd0

eg:

Create a zpool, populate it and then a zpool scrub.

If the content of the card is precious, at least create a file and check it.

Thanks in advance!
Comment 163 Gleb Popov freebsd_committer freebsd_triage 2020-06-03 15:34:37 UTC
(In reply to Henri Hennebert from comment #162)
The test was mostly successfull.

dd'ing from a random file to /dev/mmcsd0 was successfull. However, reading the file back resulted in 

rtsx0: Controller timeout
rtsx0: Soft reset
mmcsd0: Error indicated: 1 Timeout

This happens randomly after starting reading from the card, after reading about 50 Mb.

Playing with block size doesn't seem to change anything.

Creating a FAT filesystem and a file on it also worked.
Comment 164 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-06-03 18:10:57 UTC
Thanks gleb for the test.

Testing rtsx0@pci0:1:0:0: class=0xff0000 card=0x522910ec chip=0x522910ec rev=0x01 hdr=0x00
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS5229 PCI Express Card Reader'
    bar   [10] = type Memory, range 32, base rx91200000, size 4096, enabled
my self in my Lenovo ideapad 120S-14IAP I could not replicate. dd random to mmcsd0 as well as reading back did not fail.

I wonder how a bad card behaves...
Comment 165 Henri Hennebert 2020-06-03 18:26:12 UTC
(In reply to Jesper Schmitz Mouridsen from comment #164)

I am lost in the readers you test.

can you give the list of

card reader, freebsd version and make of the computer.
So I will complete the README.md

Thanks in advance.
Comment 166 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-06-03 18:40:51 UTC
(In reply to Henri Hennebert from comment #165)
Yes of course.

I have tested RTS5229 PCI Express Card Reader on Lenovo ideapad 120S-14IAP successfully on FreeBSD 12.1-RELEASE-p1

and on
        Manufacturer: LENOVO
        Product Name: 5017AA5
        Version: ThinkPad L520
rtsx0@pci0:4:0:0:       class=0xff0000 rev=0x01 hdr=0x00 vendor=0x10ec device=0x5209 subvendor=0x17aa subdevice=0x21dd
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS5209 PCI Express Card Reader'
    bar   [10] = type Memory, range 32, base rxf0600000, size 4096, enabled
with version FreeBSD 13.0-CURRENT #0 r361019 which also works successfully.
Comment 167 Henri Hennebert 2020-06-08 13:15:43 UTC
Hello everyone.

I update the definition of RTSX_PETXCFG and RTSX_SD30_DRIVE_SEL following
the corresponding definition in Linux.

I add tweaks for RTS5229 and RTS525A.

It would be really nice for everyone to test those update from the branch
tweak-RTS5229-RTS525A.

e.g.

cd /sys/dev/rtsx
git checkout tweak-RTS5229-RTS525A
/usr/obj/usr/src/amd64.amd64/sys/dev/rtsx/
make
make install
kldunload rtsx
kldload rtsx

and make read/write tests.

Thank you for your time.

Note there are now 2 issues on hlh-restart/rtsx
Comment 168 Gary Jennejohn 2020-06-08 13:50:15 UTC
Note that this line in rtsx/Makefile: CFLAGS="-ferror-limit=0" causes an error using FreeBSD13 and I had to comment it out.  Just FYI.
Comment 169 Sergey V. Dyatko 2020-06-08 13:54:33 UTC
(In reply to Henri Hennebert from comment #167)
Still no luck :(

[tiger@laptop]:~/tmp/rtsx%git status
On branch tweak-RTS5229-RTS525A
Your branch is up to date with 'origin/tweak-RTS5229-RTS525A'.

nothing to commit, working tree clean
[tiger@laptop]:~/tmp/rtsx%make
machine -> /usr/src/sys/amd64/include
x86 -> /usr/src/sys/x86/include
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/kern/device_if.m -h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/kern/bus_if.m -h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/dev/pci/pci_if.m -h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/dev/mmc/mmcbr_if.m -h
Warning: Object directory not changed from original /usr/home/tiger/tmp/rtsx
cc  "-ferror-limit=0"  -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include     -MD  -MF.depend.rtsx.o -MTrtsx.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error-tautological-compare -Wno-error-empty-body -Wno-error-parentheses-equality -Wno-error-unused-function -Wno-error-pointer-sign -Wno-error-shift-negative-value -Wno-address-of-packed-member -Wno-format-zero-length   -mno-aes -mno-avx  -std=iso9899:1999 -c rtsx.c -o rtsx.o
ld -m elf_x86_64_fbsd -d -warn-common --build-id=sha1 -T /usr/src/sys/conf/ldscript.kmod.amd64 -r -d  -o rtsx.ko rtsx.o
:> export_syms
awk -f /usr/src/sys/conf/kmod_syms.awk rtsx.ko  export_syms | xargs -J% objcopy % rtsx.ko
objcopy --strip-debug rtsx.ko

[tiger@laptop]:~/tmp/rtsx%sudo make install
install -T release -o root -g wheel -m 555   rtsx.ko /boot/modules/
kldxref /boot/modules
[tiger@laptop]:~/tmp/rtsx%kldstat -v | grep rtsx
31    1 0xffffffff83953000     81d8 rtsx.ko (/boot/modules/rtsx.ko)
                529 rtsx/mmc
                528 pci/rtsx
[tiger@laptop]:~/tmp/rtsx%sudo kldunload !$
sudo kldunload rtsx

messages:
Jun  8 16:49:50 laptop kernel: rtsx0: detached
Jun  8 16:49:50 laptop kernel: pci4: <unknown> at device 0.0 (no driver attached)

[tiger@laptop]:~/tmp/rtsx%sudo kldload rtsx
[tiger@laptop]:~/tmp/rtsx%

messages (But I have sd card inserted!):
Jun  8 16:50:41 laptop kernel: rtsx0: <Realtek RTS522A PCI MMC/SD Card Reader> mem 0xf2100000-0xf2100fff at device 0.0 on pci4
Jun  8 16:50:41 laptop kernel: rtsx0: Card absent
[tiger@laptop]:~/tmp/rtsx%ll /dev/mm*
ls: No match.

messages after I remove card:
Jun  8 16:52:08 laptop kernel: rtsx0: Interrupt card inserted/removed
Jun  8 16:52:08 laptop kernel: rtsx0: Card present
Jun  8 16:52:08 laptop kernel: rtsx0: No request running
Jun  8 16:52:08 laptop kernel: mmc0: <MMC/SD bus> on rtsx0
Jun  8 16:52:32 laptop kernel: rtsx0: Controller timeout
Jun  8 16:52:32 laptop kernel: rtsx0: Soft reset
Jun  8 16:52:32 laptop kernel: rtsx0: Controller timeout
Jun  8 16:52:32 laptop kernel: rtsx0: Soft reset
Jun  8 16:52:32 laptop kernel: rtsx0: Controller timeout
Jun  8 16:52:32 laptop kernel: rtsx0: Soft reset
Jun  8 16:52:32 laptop kernel: rtsx0: Controller timeout
Jun  8 16:52:32 laptop kernel: rtsx0: Soft reset
Jun  8 16:52:32 laptop kernel: rtsx0: Controller timeout
Jun  8 16:52:32 laptop kernel: rtsx0: Soft reset
Jun  8 16:52:32 laptop kernel: rtsx0: Controller timeout
Jun  8 16:52:32 laptop kernel: rtsx0: Soft reset
Jun  8 16:52:32 laptop kernel: rtsx0: Controller timeout
Jun  8 16:52:32 laptop kernel: rtsx0: Soft reset
Jun  8 16:52:32 laptop kernel: rtsx0: Controller timeout
Jun  8 16:52:32 laptop kernel: rtsx0: Soft reset
Jun  8 16:52:32 laptop kernel: rtsx0: Controller timeout
Jun  8 16:52:32 laptop kernel: rtsx0: Soft reset
Jun  8 16:52:32 laptop kernel: rtsx0: Controller timeout
Jun  8 16:52:32 laptop kernel: rtsx0: Soft reset
Jun  8 16:52:32 laptop kernel: rtsx0: Controller timeout
Jun  8 16:52:32 laptop kernel: rtsx0: Soft reset
Jun  8 16:52:32 laptop kernel: rtsx0: Controller timeout
Jun  8 16:52:32 laptop kernel: rtsx0: Soft reset
Jun  8 16:52:32 laptop kernel: mmc0: No compatible cards found on bus

and keyboard stop working for a ~30 sec
Now, plug card back:

Jun  8 16:53:55 laptop kernel: rtsx0: Interrupt card inserted/removed
Jun  8 16:53:55 laptop kernel: rtsx0: Card absent
Jun  8 16:53:55 laptop kernel: rtsx0: No request running
Jun  8 16:53:55 laptop kernel: mmc0: detached

Looks like attaching/detaching card swapped + I don't have any mmc* devices in both cases

it is FreeBSD 13.0-CURRENT #1 r356767M, Lenovo t470p
Comment 170 Henri Hennebert 2020-06-08 14:07:07 UTC
(In reply to Sergey V. Dyatko from comment #169)

Maybe you are hit by the same problem than jyoung15@gmail.com (comment 127)

add this patch

diff --git a/rtsx.c b/rtsx.c
index eeec3ae..de61465 100644
--- a/rtsx.c
+++ b/rtsx.c
@@ -559,7 +559,7 @@ rtsx_is_card_present(struct rtsx_softc *sc)
        uint32_t status;
 
        status = READ4(sc, RTSX_BIPR);
-       return (status & RTSX_SD_EXIST);
+       return !(status & RTSX_SD_EXIST);
 }
 
 static int

an try again.
Comment 171 Sergey V. Dyatko 2020-06-08 14:16:38 UTC
(In reply to Henri Hennebert from comment #170)

With this patch card inserting/removing detection works fine, yes
But /dev/mm* doesn't apeared still
After I insert card:

Jun  8 17:13:55 laptop kernel: rtsx0: Interrupt card inserted/removed
Jun  8 17:13:55 laptop kernel: rtsx0: Card present
Jun  8 17:13:55 laptop kernel: rtsx0: No request running
Jun  8 17:13:55 laptop kernel: mmc0: <MMC/SD bus> on rtsx0
Jun  8 17:14:08 laptop kernel: rtsx0: Controller timeout
Jun  8 17:14:08 laptop kernel: rtsx0: Soft reset
Jun  8 17:14:08 laptop kernel: rtsx0: Controller timeout
Jun  8 17:14:08 laptop kernel: rtsx0: Soft reset
Jun  8 17:14:08 laptop kernel: rtsx0: Controller timeout
Jun  8 17:14:08 laptop kernel: rtsx0: Soft reset
Jun  8 17:14:08 laptop kernel: rtsx0: Controller timeout
Jun  8 17:14:08 laptop kernel: rtsx0: Soft reset
Jun  8 17:14:08 laptop kernel: rtsx0: Controller timeout
Jun  8 17:14:08 laptop kernel: rtsx0: Soft reset
Jun  8 17:14:08 laptop kernel: rtsx0: Controller timeout
Jun  8 17:14:08 laptop kernel: rtsx0: Soft reset
Jun  8 17:14:19 laptop kernel: rtsx0: Controller timeout
Jun  8 17:14:19 laptop kernel: rtsx0: Soft reset
Jun  8 17:14:19 laptop kernel: rtsx0: Controller timeout
Jun  8 17:14:19 laptop kernel: rtsx0: Soft reset
Jun  8 17:14:19 laptop kernel: rtsx0: Controller timeout
Jun  8 17:14:19 laptop kernel: rtsx0: Soft reset
Jun  8 17:14:19 laptop kernel: rtsx0: Controller timeout
Jun  8 17:14:19 laptop kernel: rtsx0: Soft reset
Jun  8 17:14:19 laptop kernel: rtsx0: Controller timeout
Jun  8 17:14:19 laptop kernel: rtsx0: Soft reset
Jun  8 17:14:19 laptop kernel: rtsx0: Controller timeout
Jun  8 17:14:19 laptop kernel: rtsx0: Soft reset
Jun  8 17:14:19 laptop kernel: mmc0: No compatible cards found on bus

Is output with `debug.bootverbose=1` will be more resultative?
Comment 172 Henri Hennebert 2020-06-08 14:29:38 UTC
(In reply to Sergey V. Dyatko from comment #171)

First try insert/remove multiple time.

Try with another card if possible.

If nothing change then

set debug.bootverbose=1 and insert a card to confirm that it is CMD8 which timeout.

then reset debug.bootverbose=0 to not overload /var/log/messages.
Comment 173 Sergey V. Dyatko 2020-06-08 14:37:00 UTC
(In reply to Henri Hennebert from comment #172)

I inserted/removed the card 10 times just now, nothing has changed
messages with bootverbose:
Jun  8 17:34:20 laptop kernel: rtsx0: Card inserted                                                                                                                                                                 
Jun  8 17:34:20 laptop kernel: mmc0: <MMC/SD bus> on rtsx0                                                                                                                                                          
Jun  8 17:34:20 laptop kernel: rtsx0: rtsx_mmcbr_acquire_host()                                                                                                                                                     
Jun  8 17:34:20 laptop kernel: rtsx0: Read ivar #9, value 0 / #0                                                                                                                                                    
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #7, value 0x1 / #1                                                                                                                                                 
Jun  8 17:34:20 laptop kernel: rtsx0: Read ivar #6, value 0x3c0000 / #3932160                                                                                                                                       
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #11, value 0x15 / #21                                                                                                                                              
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #0, value 0x1 / #1                                                                                                                                                 
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #2, value 0 / #0                                                                                                                                                   
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #1, value 0 / #0                                                                                                                                                   
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #9, value 0x1 / #1                                                                                                                                                 
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #3, value 0 / #0                                                                                                                                                   
Jun  8 17:34:20 laptop kernel: rtsx0: rtsx_mmcbr_update_ios()                                                                                                                                                       
Jun  8 17:34:20 laptop kernel: rtsx0: rtsx_bus_power_on()                                                                                                                                                           
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #12, value 0x2 / #2                                                                                                                                                
Jun  8 17:34:20 laptop kernel: rtsx0: rtsx_mmcbr_switch_vccq(330)                                                                                                                                                   
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #3, value 0x61a80 / #400000                                                                                                                                        
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #14, value 0 / #0                                                                                                                                                  
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #9, value 0x2 / #2                                                                                                                                                 
Jun  8 17:34:20 laptop kernel: rtsx0: rtsx_mmcbr_update_ios()                                                                                                                                                       
Jun  8 17:34:20 laptop kernel: rtsx0: rtsx_set_sd_clock(400000)                                                                                                                                                     
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #0, value 0x2 / #2                                                                                                                                                 
Jun  8 17:34:20 laptop kernel: mmc0: Probing bus                                                                                                                                                                    
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #2, value 0x1 / #1                                                                                                                                                 
Jun  8 17:34:20 laptop kernel: rtsx0: rtsx_mmcbr_update_ios()                                                                                                                                                       
Jun  8 17:34:20 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD0 arg 0 flags 0x40 dlen 0 dflags 0)                                                                                                                     
Jun  8 17:34:20 laptop kernel: rtsx0: rtsx_send_cmd()                                                                                                                                                               
Jun  8 17:34:20 laptop kernel: rtsx0: Interrupt handler - enabled: 0x32000000, status: 0xa0080000                                                                                                                   
Jun  8 17:34:20 laptop kernel: rtsx0: Write ivar #2, value 0 / #0                                                                                                                                                   
Jun  8 17:34:20 laptop kernel: rtsx0: rtsx_mmcbr_update_ios()                                                                                                                                                       
Jun  8 17:34:20 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)                                                                                                                 
Jun  8 17:34:20 laptop kernel: rtsx0: rtsx_send_cmd()                                                                                                                                                               
Jun  8 17:34:38 laptop kernel: rtsx0: Controller timeout                                                                                                                                                            
Jun  8 17:34:38 laptop kernel: rtsx0: Soft reset                                                                                                                                                                    
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)                                                                                                                 
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_send_cmd()                                                                                                                                                               
Jun  8 17:34:38 laptop kernel: rtsx0: Controller timeout                                                                                                                                                            
Jun  8 17:34:38 laptop kernel: rtsx0: Soft reset                                                                                                                                                                    
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)                                                                                                                 
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_send_cmd()                                                                                                                                                               
Jun  8 17:34:38 laptop kernel: rtsx0: Controller timeout                                                                                                                                                            
Jun  8 17:34:38 laptop kernel: rtsx0: Soft reset                                                                                    
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD8 arg 0x1aa flags 0x75 dlen 0 dflags 0)                                                                                                                 
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_send_cmd()                                                                                                                                                               
Jun  8 17:34:38 laptop kernel: rtsx0: Controller timeout                                                                                                                                                            
Jun  8 17:34:38 laptop kernel: rtsx0: Soft reset
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_send_cmd()
Jun  8 17:34:38 laptop kernel: rtsx0: Controller timeout
Jun  8 17:34:38 laptop kernel: rtsx0: Soft reset
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_send_cmd()
Jun  8 17:34:38 laptop kernel: rtsx0: Controller timeout
Jun  8 17:34:38 laptop kernel: rtsx0: Soft reset
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_send_cmd()
Jun  8 17:34:38 laptop kernel: rtsx0: Controller timeout
Jun  8 17:34:38 laptop kernel: rtsx0: Soft reset
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD55 arg 0 flags 0x15 dlen 0 dflags 0)
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_send_cmd()
Jun  8 17:34:38 laptop kernel: rtsx0: Controller timeout
Jun  8 17:34:38 laptop kernel: rtsx0: Soft reset
Jun  8 17:34:38 laptop kernel: mmc0: SD probe: failed
Jun  8 17:34:38 laptop kernel: rtsx0: Write ivar #7, value 0 / #0
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD1 arg 0 flags 0x61 dlen 0 dflags 0)
Jun  8 17:34:38 laptop kernel: rtsx0: rtsx_send_cmd()
Jun  8 17:34:38 laptop kernel: rtsx0: Controller timeout
Jun  8 17:34:38 laptop kernel: rtsx0: Soft reset
Jun  8 17:34:44 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD1 arg 0 flags 0x61 dlen 0 dflags 0)
Jun  8 17:34:44 laptop kernel: rtsx0: rtsx_send_cmd()
Jun  8 17:34:44 laptop kernel: rtsx0: Controller timeout
Jun  8 17:34:44 laptop kernel: rtsx0: Soft reset
Jun  8 17:34:44 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD1 arg 0 flags 0x61 dlen 0 dflags 0)
Jun  8 17:34:44 laptop kernel: rtsx0: rtsx_send_cmd()
Jun  8 17:34:44 laptop kernel: rtsx0: Controller timeout
Jun  8 17:34:44 laptop kernel: rtsx0: Soft reset
Jun  8 17:34:44 laptop kernel: rtsx0: rtsx_mmcbr_request(CMD1 arg 0 flags 0x61 dlen 0 dflags 0)
Jun  8 17:34:44 laptop kernel: rtsx0: rtsx_send_cmd()
Jun  8 17:34:44 laptop kernel: rtsx0: Controller timeout
Jun  8 17:34:44 laptop kernel: rtsx0: Soft reset
Jun  8 17:34:44 laptop kernel: mmc0: MMC probe: failed
Jun  8 17:34:44 laptop kernel: rtsx0: Write ivar #8, value 0 / #0
Jun  8 17:34:44 laptop kernel: rtsx0: Read ivar #8, value 0 / #0
Jun  8 17:34:44 laptop syslogd: last message repeated 1 times
Jun  8 17:34:44 laptop kernel: mmc0: Current OCR: 0x00000000
Jun  8 17:34:44 laptop kernel: rtsx0: Read ivar #8, value 0 / #0
Jun  8 17:34:44 laptop kernel: mmc0: No compatible cards found on bus
Jun  8 17:34:44 laptop kernel: rtsx0: Write ivar #0, value 0x1 / #1
Jun  8 17:34:44 laptop kernel: rtsx0: Write ivar #2, value 0 / #0
Jun  8 17:34:44 laptop kernel: rtsx0: Write ivar #1, value 0 / #0
Jun  8 17:34:44 laptop kernel: rtsx0: Write ivar #9, value 0 / #0
Jun  8 17:34:44 laptop kernel: rtsx0: Write ivar #3, value 0 / #0
Jun  8 17:34:44 laptop kernel: rtsx0: Write ivar #14, value 0 / #0
Jun  8 17:34:44 laptop kernel: rtsx0: rtsx_mmcbr_update_ios()
Jun  8 17:34:44 laptop kernel: rtsx0: rtsx_set_sd_clock(0)
Jun  8 17:34:44 laptop kernel: rtsx0: rtsx_bus_power_off()
Jun  8 17:34:44 laptop kernel: rtsx0: rtsx_mmcbr_release_host()
Comment 174 Henri Hennebert 2020-06-08 16:13:38 UTC
(In reply to Sergey V. Dyatko from comment #173)

In case I do something stupid, can you re-test with the master branch
Comment 175 dirkx 2020-06-08 18:02:16 UTC
(In reply to Henri Hennebert from comment #174)

FWIIW - on a thinkpad - things still work perfectly -- dropping the

   rtsx0: No request running

message while not kernel-verbose mode would propably be goodness.
Comment 176 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-06-08 20:20:12 UTC
FWIW status: 0xa0080000 look wrong.. tells write protected card inserted it should have been reporting a0x0010000, unless of course it is a write protected card..
Comment 177 Henri Hennebert 2020-06-09 06:39:25 UTC
(In reply to Jesper Schmitz Mouridsen from comment #176)
I put a card with the read only switch and I was able to write on it.
So I think the write protect must be corrected in the driver:
- return correctly to mmcsd or
- implemented in the driver.
Comment 178 Sergey V. Dyatko 2020-06-09 12:36:01 UTC
(In reply to Henri Hennebert from comment #174)
after switching to master branch looks like I need to apply patch from https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=204521#c170 for correct insert/removal detection. 
[un]plugging card 2 times I got following:

Jun  9 15:09:06 laptop kernel: rtsx0: detached
Jun  9 15:09:06 laptop kernel: pci4: <unknown> at device 0.0 (no driver attached)
Jun  9 15:09:10 laptop kernel: rtsx0: <Realtek RTS522A PCI MMC/SD Card Reader> mem 0xf2100000-0xf2100fff at device 0.0 on pci4

Jun  9 15:09:27 laptop kernel: rtsx0: Interrupt card inserted/removed
Jun  9 15:09:27 laptop kernel: rtsx0: No request running
Jun  9 15:09:27 laptop kernel: mmc0: <MMC/SD bus> on rtsx0
Jun  9 15:09:35 laptop kernel: rtsx0: Controller timeout
Jun  9 15:09:35 laptop kernel: rtsx0: Soft reset
Jun  9 15:09:35 laptop kernel: rtsx0: Controller timeout
Jun  9 15:09:35 laptop kernel: rtsx0: Soft reset
Jun  9 15:09:35 laptop kernel: rtsx0: Controller timeout
Jun  9 15:09:35 laptop kernel: rtsx0: Soft reset
Jun  9 15:09:35 laptop kernel: rtsx0: Interrupt card inserted/removed
Jun  9 15:09:35 laptop kernel: rtsx0: Controller timeout
Jun  9 15:09:35 laptop kernel: rtsx0: Soft reset
Jun  9 15:09:35 laptop kernel: mmcsd0: 31GB <SDHC SD 0.0 SN 403F70FD MFG 01/2019 by 18 4V> at mmc0 50.0MHz/4bit/256-block
Jun  9 15:09:35 laptop kernel: rtsx0: Soft reset
Jun  9 15:09:41 laptop kernel: rtsx0: Controller timeout
Jun  9 15:09:41 laptop kernel: rtsx0: Soft reset
Jun  9 15:09:41 laptop kernel: rtsx0: Controller timeout
Jun  9 15:09:41 laptop kernel: rtsx0: Soft reset
Jun  9 15:09:41 laptop kernel: rtsx0: Controller timeout
Jun  9 15:09:41 laptop kernel: rtsx0: Soft reset
Jun  9 15:09:41 laptop kernel: mmc0: CMD7 failed, RESULT: 1
Jun  9 15:09:41 laptop kernel: mmc0: Card at relative address 1 failed to select
Jun  9 15:09:41 laptop kernel: rtsx0: Soft reset
Jun  9 15:09:41 laptop kernel: mmcsd0: Error indicated: 1 Timeout
Jun  9 15:09:41 laptop kernel: g_access(1003): provider mmcsd0 has error 6 set
Jun  9 15:09:41 laptop syslogd: last message repeated 3 times
Jun  9 15:09:41 laptop kernel: mmc0: detached

well. after apply patch I got 100% detection :)

laptop# mount_msdosfs /dev/mmcsd0s1 /mnt/
laptop# ll !$
ll /mnt/
total 160
drwxr-xr-x  1 root  wheel  32768 Oct  9  2019 .android_secure
drwxr-xr-x  1 root  wheel  32768 Oct  9  2019 Android
drwxr-xr-x  1 root  wheel  32768 Oct  9  2019 CARDV
drwxr-xr-x  1 root  wheel  32768 Oct  9  2019 DCIM
drwxr-xr-x  1 root  wheel  32768 Oct  9  2019 LOST.DIR

It is microsd card + adapter
Now I try card I tested before (yesterday):
Jun  9 15:18:40 laptop kernel: mmc0: detached
Jun  9 15:18:45 laptop kernel: rtsx0: Interrupt card inserted/removed
Jun  9 15:18:45 laptop kernel: rtsx0: No request running
Jun  9 15:18:45 laptop kernel: mmc0: <MMC/SD bus> on rtsx0
Jun  9 15:18:57 laptop kernel: rtsx0: Controller timeout
Jun  9 15:18:57 laptop kernel: rtsx0: Soft reset
Jun  9 15:18:57 laptop kernel: rtsx0: Controller timeout
Jun  9 15:18:57 laptop kernel: rtsx0: Soft reset
Jun  9 15:18:57 laptop kernel: rtsx0: Controller timeout
Jun  9 15:18:57 laptop kernel: rtsx0: Soft reset
Jun  9 15:18:57 laptop kernel: rtsx0: Controller timeout
Jun  9 15:18:57 laptop kernel: rtsx0: Soft reset
Jun  9 15:18:57 laptop kernel: rtsx0: Controller timeout
Jun  9 15:18:57 laptop kernel: rtsx0: Soft reset
Jun  9 15:18:57 laptop kernel: rtsx0: Controller timeout
Jun  9 15:18:57 laptop kernel: rtsx0: Soft reset
Jun  9 15:19:01 laptop kernel: rtsx0: Controller timeout
Jun  9 15:19:01 laptop kernel: rtsx0: Soft reset
Jun  9 15:19:01 laptop kernel: rtsx0: Controller timeout
Jun  9 15:19:01 laptop kernel: rtsx0: Soft reset
Jun  9 15:19:01 laptop kernel: mmc0: CMD8 failed, RESULT: 1
Jun  9 15:19:01 laptop kernel: mmcsd0: 128MB <SD SS128 5.8 SN 84845CEF MFG 01/2009 by 1 PA> at mmc0 50.0MHz/4bit/256-block

wow. It is detected and I can mount it!
laptop# mount_msdosfs /dev/mmcsd0s1 /mnt/
laptop# df -h !$
df -h /mnt/
Filesystem       Size    Used   Avail Capacity  Mounted on
/dev/mmcsd0s1    122M     32K    122M     0%    /mnt

now, I'll create GPT and zpool using this card:

laptop# gpart create -s GPT /dev/mmcsd0
mmcsd0 created
laptop# gpart add -t freebsd-zfs /dev/mmcsd0
mmcsd0p1 added
laptop# zpool create TEST /dev/mmcsd0p1

laptop# df -h  /TEST
Filesystem    Size    Used   Avail Capacity  Mounted on
TEST                    56M     96K     56M     0%    /TEST

laptop# gpart show mmcsd0
=>    40  250800  mmcsd0  GPT  (123M)
      40    2008          - free -  (1.0M)
    2048  247808       1  freebsd-zfs  (121M)
  249856     984          - free -  (492K)

copy some trash into it:

laptop# cp ~tiger/video/2020_0318_185503_081A.MOV /TEST/
load: 0.09  cmd: cp 9986 [tx->tx_sync_done_cv] 1.07r 0.00u 0.00s 0% 3280k
/home/tiger/video/2020_0318_185503_081A.MOV -> /TEST/2020_0318_185503_081A.MOV   0%
load: 0.06  cmd: cp 9986 [tx->tx_sync_done_cv] 27.47r 0.00u 0.00s 0% 3280k
/home/tiger/video/2020_0318_185503_081A.MOV -> /TEST/2020_0318_185503_081A.MOV   1%
cp: /TEST/2020_0318_185503_081A.MOV: No space left on device
[tiger@laptop]:~%df -h /TEST
Filesystem    Size    Used   Avail Capacity  Mounted on
TEST           55M     55M      0B   100%    /TEST
laptop# zpool scrub TEST
laptop# zpool status TEST
  pool: TEST
 state: ONLINE
  scan: scrub in progress since Tue Jun  9 15:30:04 2020
        56.4M scanned at 11.3M/s, 32.7M issued at 6.53M/s, 56.7M total
        0 repaired, 57.60% done, no estimated completion time
config:

        NAME        STATE     READ WRITE CKSUM
        TEST        ONLINE       0     0     0
          mmcsd0p1  ONLINE       0     0     0

errors: No known data errors
laptop# zpool status TEST
  pool: TEST
 state: ONLINE
  scan: scrub repaired 0 in 0 days 00:00:09 with 0 errors on Tue Jun  9 15:30:13 2020
config:

        NAME        STATE     READ WRITE CKSUM
        TEST        ONLINE       0     0     0
          mmcsd0p1  ONLINE       0     0     0

errors: No known data errors
Comment 179 Henri Hennebert 2020-06-09 14:39:29 UTC
(In reply to Sergey V. Dyatko from comment #178)

I do some update more update to tweak-RTS5229-RTS525A.

please test this branch. You must apply the patch to rtsx_is_card_present().
Comment 180 Sergey V. Dyatko 2020-06-09 14:52:43 UTC
(In reply to Henri Hennebert from comment #179)
Jun  9 17:51:52 laptop kernel: rtsx0: <Realtek RTS522A PCI MMC/SD Card Reader> mem 0xf2100000-0xf2100fff at device 0.0 on pci4
Jun  9 17:51:52 laptop kernel: rtsx0: Card present
Jun  9 17:51:52 laptop kernel: mmc0: <MMC/SD bus> on rtsx0
Jun  9 17:52:00 laptop kernel: rtsx0: Controller timeout
Jun  9 17:52:00 laptop kernel: rtsx0: Soft reset
Jun  9 17:52:00 laptop kernel: rtsx0: Controller timeout
Jun  9 17:52:00 laptop kernel: rtsx0: Soft reset
Jun  9 17:52:00 laptop kernel: rtsx0: Controller timeout
Jun  9 17:52:00 laptop kernel: rtsx0: Soft reset
Jun  9 17:52:00 laptop kernel: rtsx0: Controller timeout
Jun  9 17:52:00 laptop kernel: rtsx0: Soft reset
Jun  9 17:52:16 laptop kernel: rtsx0: Controller timeout
Jun  9 17:52:16 laptop kernel: rtsx0: Soft reset
Jun  9 17:52:16 laptop kernel: rtsx0: Controller timeout
Jun  9 17:52:16 laptop kernel: rtsx0: Soft reset
Jun  9 17:52:16 laptop kernel: rtsx0: Controller timeout
Jun  9 17:52:16 laptop kernel: rtsx0: Soft reset
Jun  9 17:52:16 laptop kernel: rtsx0: Controller timeout
Jun  9 17:52:16 laptop kernel: rtsx0: Soft reset
Jun  9 17:52:16 laptop kernel: rtsx0: Controller timeout
Jun  9 17:52:16 laptop kernel: rtsx0: Soft reset
Jun  9 17:52:16 laptop kernel: rtsx0: Controller timeout
Jun  9 17:52:16 laptop kernel: rtsx0: Soft reset
Jun  9 17:52:16 laptop kernel: rtsx0: Controller timeout
Jun  9 17:52:16 laptop kernel: rtsx0: Soft reset
Jun  9 17:52:16 laptop kernel: rtsx0: Controller timeout
Jun  9 17:52:16 laptop kernel: rtsx0: Soft reset
Jun  9 17:52:16 laptop kernel: mmc0: No compatible cards found on bus

with both cards from my previous comment. It is branch 
tweak-RTS5229-RTS525A + patched rtsx_is_card_present()
Comment 181 Henri Hennebert 2020-06-09 15:30:48 UTC
(In reply to Sergey V. Dyatko from comment #180)

Those diff are driving me crazy..

I just update tweak-RTS5229-RTS525A with some lines from master.

Please update and test.
Comment 182 Mario Lobo 2020-06-09 17:30:38 UTC
Hi;

ACER ASPIRE 5 A515-51G-C97B
FreeBSD 13.0-CURRENT #0 r360882
RTL8411B PCI Express Card Reader

I cloned https://github.com/hlh-restart/rtsx

make install
kldload rtsx

mmc0: <MMC/SD bus> on rtsx0
mmcsd0: 8GB <SDHC SU08G 8.0 SN 03518B4C MFG 08/2012 by 3 SD> at mmc0 50.0MHz/4bit/256-block

Inserting an SD first time, it yields:

rtsx0: Interrupt card inserted/removed
rtsx0: No request running

I can mount/unmount, copy, delete, anything.

OBS - The FIRST time I inserted/removed/reinserted the SD, it outputted:

mmc0: detached
rtsx0: Interrupt card inserted/removed
rtsx0: No request running
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
mmc0: ACMD41 failed, RESULT: 4
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Interrupt card inserted/removed
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
mmc0: detached

I unloaded/reloaded the module, and now it doesn't fail anymore. I tested insert/remove SD about 15 times and no error.

mount -t msdosfs /dev/mmcsd0s1 /mnt

/dev/mmcsd0s1    7.4G    6.8G    559M    93%    /mnt

So it's working fine here.
Comment 183 Sergey V. Dyatko 2020-06-09 18:43:33 UTC
(In reply to Henri Hennebert from comment #181)
with updated branch tweak-RTS5229-RTS525A and patch from #170:
kldload with card:
Jun  9 21:42:24 laptop kernel: rtsx0: <Realtek RTS522A PCI MMC/SD Card Reader> mem 0xf2100000-0xf2100fff at device 0.0 on pci4
Jun  9 21:42:24 laptop kernel: rtsx0: Card present
Jun  9 21:42:24 laptop kernel: mmc0: <MMC/SD bus>
Jun  9 21:42:24 laptop kernel:  on rtsx0
Jun  9 21:42:28 laptop kernel: rtsx0: Controller timeout
Jun  9 21:42:28 laptop kernel: rtsx0: Soft reset
Jun  9 21:42:28 laptop kernel: rtsx0: Controller timeout
Jun  9 21:42:28 laptop kernel: rtsx0: Soft reset
Jun  9 21:42:40 laptop kernel: rtsx0: Controller timeout
Jun  9 21:42:40 laptop kernel: rtsx0: Soft reset
Jun  9 21:42:40 laptop kernel: rtsx0: Controller timeout
Jun  9 21:42:40 laptop kernel: rtsx0: Soft reset
Jun  9 21:42:40 laptop kernel: rtsx0: Controller timeout
Jun  9 21:42:40 laptop kernel: rtsx0: Soft reset
Jun  9 21:42:40 laptop kernel: rtsx0: Controller timeout
Jun  9 21:42:40 laptop kernel: rtsx0: Soft reset
Jun  9 21:42:40 laptop kernel: rtsx0: Controller timeout
Jun  9 21:42:40 laptop kernel: rtsx0: Soft reset
Jun  9 21:42:40 laptop kernel: rtsx0: Controller timeout
Jun  9 21:42:40 laptop kernel: rtsx0: Soft reset
Jun  9 21:42:40 laptop kernel: mmc0: CMD8 failed, RESULT: 1
Jun  9 21:42:40 laptop kernel: mmcsd0: 128MB <SD SS128 5.8 SN 84845CEF MFG 01/2009 by 1 PA> (read-only) at mmc0 50.0MHz/4bit/256-block

laptop# mount_msdosfs /dev/mmcsd0 /mnt/
mount_msdosfs: /dev/mmcsd0: Read-only file system
Comment 184 Henri Hennebert 2020-06-10 11:18:35 UTC
(In reply to Sergey V. Dyatko from comment #183)

You encounter a read-only because I have added it in the tweak-RTS5229-RTS525A.

I update the tweak-RTS5229-RTS525A branch.

can you test if please.
Comment 185 Henri Hennebert 2020-06-10 11:50:06 UTC
(In reply to Mario Lobo from comment #182)

With my Acer Aspire E 15 E5-576-77W6 with RTL8411B I also encounter
the same problem (timeout) from time to time during insert. But it
is not easily reproduce. Moreover repeated insert/remove seems to
allow a detection of the card.

Thanks for your test!
Comment 186 Henri Hennebert 2020-06-10 12:23:26 UTC
After tagging the master branch I merge the tweak branch to master.

So now use the only branch master.

To access the master branch as of 2020-06-04 use the release with
tag '2020-06-04'.
Comment 187 Sergey V. Dyatko 2020-06-10 14:24:58 UTC
(In reply to Henri Hennebert from comment #186)

it is master + rtsx_is_card_present() patch:

Jun 10 17:24:34 laptop kernel: rtsx0: <Realtek RTS522A PCI MMC/SD Card Reader> mem 0xf2100000-0xf2100fff at device 0.0 on pci4
Jun 10 17:24:34 laptop kernel: rtsx0: Card present
Jun 10 17:24:34 laptop kernel: mmc0: <MMC/SD bus> on rtsx0
Jun 10 17:24:42 laptop kernel: rtsx0: Controller timeout
Jun 10 17:24:42 laptop kernel: rtsx0: Soft reset
Jun 10 17:24:42 laptop kernel: rtsx0: Controller timeout
Jun 10 17:24:42 laptop kernel: rtsx0: Soft reset
Jun 10 17:24:42 laptop kernel: rtsx0: Controller timeout
Jun 10 17:24:42 laptop kernel: rtsx0: Soft reset
Jun 10 17:24:51 laptop kernel: rtsx0: Controller timeout
Jun 10 17:24:51 laptop kernel: rtsx0: Soft reset
Jun 10 17:24:51 laptop kernel: rtsx0: Controller timeout
Jun 10 17:24:51 laptop kernel: rtsx0: Soft reset
Jun 10 17:24:51 laptop kernel: rtsx0: Controller timeout
Jun 10 17:24:51 laptop kernel: rtsx0: Soft reset
Jun 10 17:24:51 laptop kernel: rtsx0: Controller timeout
Jun 10 17:24:51 laptop kernel: rtsx0: Soft reset
Jun 10 17:24:51 laptop kernel: rtsx0: Controller timeout
Jun 10 17:24:51 laptop kernel: rtsx0: Soft reset
Jun 10 17:24:51 laptop kernel: mmc0: CMD8 failed, RESULT: 1
Jun 10 17:24:51 laptop kernel: mmcsd0: 128MB <SD SS128 5.8 SN 84845CEF MFG 01/2009 by 1 PA> (read-only) at mmc0 50.0MHz/4bit/256-block
Comment 188 Henri Hennebert 2020-06-10 14:30:31 UTC
(In reply to Sergey V. Dyatko from comment #187)

Save the timeout is it working?

Is your card switch on read-only?
Comment 189 Sergey V. Dyatko 2020-06-10 15:55:46 UTC
(In reply to Henri Hennebert from comment #188)
well
2 notes:
1. after suspend/resume card detection doesn't work (it was reported before?)
2. card wasn't write protected but when I locked it (lock on sd card):

Jun 10 18:51:33 laptop kernel: pci4: <unknown> at device 0.0 (no driver attached)
Jun 10 18:51:36 laptop kernel: rtsx0: <Realtek RTS522A PCI MMC/SD Card Reader> mem 0xf2100000-0xf2100fff at device 0.0 on pci4
Jun 10 18:51:36 laptop kernel: rtsx0: Card present
Jun 10 18:51:36 laptop kernel: mmc0: <MMC/SD bus> on rtsx0
Jun 10 18:51:40 laptop kernel: rtsx0: Controller timeout
Jun 10 18:51:40 laptop kernel: rtsx0: Soft reset
Jun 10 18:51:40 laptop kernel: rtsx0: Controller timeout
Jun 10 18:51:40 laptop kernel: rtsx0: Soft reset
Jun 10 18:51:42 laptop kernel: rtsx0: Controller timeout
Jun 10 18:51:42 laptop kernel: rtsx0: Soft reset
Jun 10 18:51:45 laptop kernel: rtsx0: Controller timeout
Jun 10 18:51:45 laptop kernel: rtsx0: Soft reset
Jun 10 18:51:48 laptop kernel: rtsx0: Controller timeout
Jun 10 18:51:48 laptop kernel: rtsx0: Soft reset
Jun 10 18:51:48 laptop kernel: rtsx0: Controller timeout
Jun 10 18:51:48 laptop kernel: rtsx0: Soft reset
Jun 10 18:51:51 laptop kernel: rtsx0: Controller timeout
Jun 10 18:51:51 laptop kernel: rtsx0: Soft reset
Jun 10 18:51:52 laptop kernel: rtsx0: Controller timeout
Jun 10 18:51:52 laptop kernel: rtsx0: Soft reset
Jun 10 18:51:52 laptop kernel: mmc0: CMD8 failed, RESULT: 1
Jun 10 18:51:52 laptop kernel: mmcsd0: 128MB <SD SS128 5.8 SN 84845CEF MFG 01/2009 by 1 PA> at mmc0 50.0MHz/4bit/256-block

I can mount it and copy files to sd-card, looks like in my case RO/RW should be inverted, as in attach/detach case
Comment 190 Henri Hennebert 2020-06-10 16:03:03 UTC
(In reply to Sergey V. Dyatko from comment #189)

1. The suspend/resume is not yet implemented, so it is normal.
2. I will ask jyoung15@gmail.com to test the ro inversion.

Thanks for our time.
Comment 191 jyoung15 2020-06-10 17:34:36 UTC
(In reply to Henri Hennebert from comment #190)

The write protection is inverted for me as well with the latest version on git:

Inserting the card with the toggle switch in the locked position:

[1292] rtsx0: Interrupt card inserted/removed
[1292] rtsx0: Card present
[1292] mmc0: <MMC/SD bus> on rtsx0
[1292] mmcsd0: 253MB <SD SU256 8.0 SN 2111EAC2 MFG 09/2008 by 3 SD> at mmc0 50.0MHz/4bit/256-block


Inserting the card with the toggle switch in the unlocked position:

[1387] rtsx0: Interrupt card inserted/removed
[1387] rtsx0: Card present
[1387] mmc0: <MMC/SD bus> on rtsx0
[1387] mmcsd0: 253MB <SD SU256 8.0 SN 2111EAC2 MFG 09/2008 by 3 SD> (read-only) at mmc0 50.0MHz/4bit/256-block


Note I still need to apply the inversion in rtsx_is_card_present as well.
Comment 192 Gary Jennejohn 2020-06-11 08:16:50 UTC
(In reply to jyoung15 from comment #191)
Just to confuse things even more, with the RTS522A in a Thinkpad X270 and verboseboot enabled I see:
kernel: rtsx0: rtsx_mmcbr_get_ro() - RW when the read-only switch is OFF
and
kernel: rtsx0: rtsx_mmcbr_get_ro() - RO when the read-only switch is ON

So, exactly as expected.
Comment 193 Henri Hennebert 2020-06-11 08:29:08 UTC
(In reply to jyoung15 from comment #191)
(In reply to jyoung15 from comment #192)

To take inversion into account I add the option RTSX_INVERSION

So on Lenovo P50 and Lenovo T470p you can build with

make -D RTSX_INVERSION
Comment 194 Sergey V. Dyatko 2020-06-11 09:02:38 UTC
(In reply to Henri Hennebert from comment #193)
lattest master, build with -D RTSX_INVERSION:
write protection off:
Jun 11 11:57:55 laptop kernel: rtsx0: <Realtek RTS522A! PCI MMC/SD Card Reader> mem 0xf2100000-0xf2100fff at device 0.0 on pci4
Jun 11 11:57:55 laptop kernel: rtsx0: Card present
Jun 11 11:57:55 laptop kernel: mmc0: <MMC/SD bus>
Jun 11 11:57:55 laptop kernel:  on rtsx0
Jun 11 11:57:58 laptop kernel: rtsx0: Controller timeout
Jun 11 11:57:58 laptop kernel: rtsx0: Soft reset
Jun 11 11:58:00 laptop kernel: rtsx0: Controller timeout
Jun 11 11:58:00 laptop kernel: rtsx0: Soft reset
Jun 11 11:58:03 laptop kernel: rtsx0: Controller timeout
Jun 11 11:58:03 laptop kernel: rtsx0: Soft reset
Jun 11 11:58:07 laptop kernel: rtsx0: Controller timeout
Jun 11 11:58:07 laptop kernel: rtsx0: Soft reset
Jun 11 11:58:07 laptop kernel: rtsx0: Controller timeout
Jun 11 11:58:07 laptop kernel: rtsx0: Soft reset
Jun 11 11:58:09 laptop kernel: rtsx0: Controller timeout
Jun 11 11:58:09 laptop kernel: rtsx0: Soft reset
Jun 11 11:58:10 laptop kernel: rtsx0: Controller timeout
Jun 11 11:58:10 laptop kernel: rtsx0: Soft reset
Jun 11 11:58:11 laptop kernel: rtsx0: Controller timeout
Jun 11 11:58:11 laptop kernel: rtsx0: Soft reset
Jun 11 11:58:11 laptop kernel: mmc0: CMD8 failed, RESULT: 1
Jun 11 11:58:11 laptop kernel: mmcsd0: 128MB <SD SS128 5.8 SN 84845CEF MFG 01/2009 by 1 PA> at mmc0 50.0MHz/4bit/256-block

With write-protection:
Jun 11 12:00:33 laptop kernel: rtsx0: Interrupt card inserted/removed
Jun 11 12:00:33 laptop kernel: rtsx0: Card absent
Jun 11 12:00:33 laptop kernel: mmc0: detached
Jun 11 12:00:40 laptop kernel: rtsx0: Interrupt card inserted/removed
Jun 11 12:00:40 laptop kernel: rtsx0: Card present
Jun 11 12:00:40 laptop kernel: mmc0: <MMC/SD bus> on rtsx0
Jun 11 12:00:42 laptop kernel: rtsx0: Controller timeout
Jun 11 12:00:42 laptop kernel: rtsx0: Soft reset
Jun 11 12:00:44 laptop kernel: rtsx0: Controller timeout
Jun 11 12:00:44 laptop kernel: rtsx0: Soft reset
Jun 11 12:00:46 laptop kernel: rtsx0: Controller timeout
Jun 11 12:00:46 laptop kernel: rtsx0: Soft reset
Jun 11 12:00:48 laptop kernel: rtsx0: Controller timeout
Jun 11 12:00:48 laptop kernel: rtsx0: Soft reset
Jun 11 12:00:50 laptop kernel: rtsx0: Controller timeout
Jun 11 12:00:50 laptop kernel: rtsx0: Soft reset
Jun 11 12:00:52 laptop kernel: rtsx0: Controller timeout
Jun 11 12:00:52 laptop kernel: rtsx0: Soft reset
Jun 11 12:00:54 laptop kernel: rtsx0: Controller timeout
Jun 11 12:00:54 laptop kernel: rtsx0: Soft reset
Jun 11 12:00:56 laptop kernel: rtsx0: Controller timeout
Jun 11 12:00:56 laptop kernel: rtsx0: Soft reset
Jun 11 12:00:56 laptop kernel: mmc0: CMD8 failed, RESULT: 1
Jun 11 12:00:56 laptop kernel: mmcsd0: 128MB <SD SS128 5.8 SN 84845CEF MFG 01/2009 by 1 PA> (read-only) at mmc0 50.0MHz/4bit/256-block


looks good, there is one annoying thing left - freeze while soft reseting. Issue with suspend/resume could be 'fixed' by editing rc.suspend|resume
Comment 195 Gary Jennejohn 2020-06-11 09:16:38 UTC
This is the code I have in my test version of the driver for suspend/resume.  Never tested, but it might save some time. NOTE that this is copy/paste so the formatting will probably need to be fixed!

/*
 * Device suspend routine.
 * do what rtsx_activate in OpenBSD does
 */
static int
rtsx_suspend(device_t dev)
{
 	struct rtsx_softc *sc = device_get_softc(dev);
	int i;
	uint16_t reg;

	RTSX_LOCK(sc);

	i = 0;
	for (reg = 0xFDA0; reg < 0xFDAE; reg++)
		(void)rtsx_read(sc, reg, &sc->regs[i++]);
	for (reg = 0xFD52; reg < 0xFD69; reg++)
		(void)rtsx_read(sc, reg, &sc->regs[i++]);
	for (reg = 0xFE20; reg < 0xFE34; reg++)
		(void)rtsx_read(sc, reg, &sc->regs[i++]);

	sc->regs4[0] = READ4(sc, RTSX_HCBAR);
	sc->regs4[1] = READ4(sc, RTSX_HCBCTLR);
	sc->regs4[2] = READ4(sc, RTSX_HDBAR);
	sc->regs4[3] = READ4(sc, RTSX_HDBCTLR);
	sc->regs4[4] = READ4(sc, RTSX_HAIMR);
	sc->regs4[5] = READ4(sc, RTSX_BIER);
	/* Not saving RTSX_BIPR. */

	RTSX_UNLOCK(sc);
	return (0);
}

/*
 * Device resume routine.
 * do what rtsx_activate in OpenBSD does
 */
static int
rtsx_resume(device_t dev)
{
 	struct rtsx_softc *sc = device_get_softc(dev);
	int i;
	uint16_t reg;

	RTSX_LOCK(sc);

	WRITE4(sc, RTSX_HCBAR, sc->regs4[0]);
	WRITE4(sc, RTSX_HCBCTLR, sc->regs4[1]);
	WRITE4(sc, RTSX_HDBAR, sc->regs4[2]);
	WRITE4(sc, RTSX_HDBCTLR, sc->regs4[3]);
	WRITE4(sc, RTSX_HAIMR, sc->regs4[4]);
	WRITE4(sc, RTSX_BIER, sc->regs4[5]);
	/* Not writing RTSX_BIPR since doing so would clear it. */

	i = 0;
	for (reg = 0xFDA0; reg < 0xFDAE; reg++)
		(void)rtsx_write(sc, reg, 0xff, sc->regs[i++]);
	for (reg = 0xFD52; reg < 0xFD69; reg++)
		(void)rtsx_write(sc, reg, 0xff, sc->regs[i++]);
	for (reg = 0xFE20; reg < 0xFE34; reg++)
		(void)rtsx_write(sc, reg, 0xff, sc->regs[i++]);

	RTSX_UNLOCK(sc);
	return (0);
}
Comment 196 Zeus Panchenko 2020-06-11 14:59:40 UTC
hi,

help!

for me commit a743790c0f7f06bc7fa966f0184f8eb53e29ec67 is absolutely broken

> uname
FreeBSD 12.1-RELEASE-p3 GENERIC  amd64

> psiconf -lv
rtsx0@pci0:7:0:0:	class=0xff0000 card=0x2246103c chip=0x522710ec rev=0x01 hdr=0x00
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS5227 PCI Express Card Reader'


on card mount I see, it is mounted Read-Only and after that this and panic

rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
mmcsd0: 2GB <SD SD02G 3.8 SN A58756A6 MFG 05/2009 by 2 TM> (read-only) at mmc0 50.0MHz/4bit/256-block
g_vfs_done():mmcsd0s1[WRITE(offset=16384, length=4096)]error = 30
g_vfs_done():mmcsd0s1[WRITE(offset=16384, length=4096)]error = 30
g_vfs_done():mmcsd0s1[WRITE(offset=16384, length=4096)]error = 30
fsync: giving up on dirty (error = 30) 0xfffff8017769b5a0: tag devfs, type VCHR
    usecount 1, writecount 0, refcount 472 rdev 0xfffff8013e961c00
    flags (VI_ACTIVE)
    v_object 0xfffff8011f967b00 ref 0 pages 470 cleanbuf 469 dirtybuf 1
    lock type devfs: UNLOCKED
	dev mmcsd0s1
Comment 197 Henri Hennebert 2020-06-11 15:02:06 UTC
I add suspend/resume code.

It work for me (stable/12.1 RTL8411B) if no I/O are in progress.

If suspend appends during I/O the card disappears (no more /dev/mmcsd0)

kldunload rtsx && kldload rtsx reset the problem.

so more head scratching is required...
Comment 198 Henri Hennebert 2020-06-11 15:08:18 UTC
(In reply to Zeus Panchenko from comment #196)

It seems you try to write when the card is detected read-only.

Can you reproduce with sysctl debug.bootverbose=1
Comment 199 Gleb Popov freebsd_committer freebsd_triage 2020-06-11 15:30:57 UTC
Henry, is "2020-06-06" a tag I may create a port for?
Comment 200 Henri Hennebert 2020-06-11 15:49:13 UTC
(In reply to Gleb Popov from comment #199)

I create tag 2020-06-11 for your port.

Build the port and test it.

Thank you for this!
Comment 201 Henri Hennebert 2020-06-11 15:51:46 UTC
(In reply to Gleb Popov from comment #199)

In the port add a note or better an option for:

On Lenovo P50 and Lenovo T470p, card detection and read-only switch are reversed. To adapt the driver: make -D RTSX_INVERSION.
Comment 202 commit-hook freebsd_committer freebsd_triage 2020-06-11 16:02:45 UTC
A commit references this bug:

Author: arrowd
Date: Thu Jun 11 16:02:23 UTC 2020
New revision: 538502
URL: https://svnweb.freebsd.org/changeset/ports/538502

Log:
  sysutils/rtsx-kmod: Add a port for a development version of the Realtek card readers driver.

  PR:		204521

Changes:
  head/sysutils/Makefile
  head/sysutils/rtsx-kmod/
  head/sysutils/rtsx-kmod/Makefile
  head/sysutils/rtsx-kmod/distinfo
  head/sysutils/rtsx-kmod/pkg-descr
  head/sysutils/rtsx-kmod/pkg-message
Comment 203 Gary Jennejohn 2020-06-11 16:04:42 UTC
(In reply to Henri Hennebert from comment #197)
I doubt that you need bus_generic_suspend() and bus_generic_resume() because mmc_suspend() and mmc_resume() do it automatically for you.  I don't know whether calling these functions twice would cause a problem, but there is really no need to do it in the driver itself.
I don't know whether suspending while an IO is in progress is expected to work.  mmcsd_suspend() does seem to wait for any in-flight IO to complete and calls mmcsd_flush_cache(), but I'm not entirely sure that it works.
Comment 204 Henri Hennebert 2020-06-11 16:13:31 UTC
(In reply to Gary Jennejohn from comment #203)

I try it without bus_generic_suspend() and bus_generic_resume()
and it don't work. When I them it work.
Comment 205 Gary Jennejohn 2020-06-11 16:36:20 UTC
(In reply to Henri Hennebert from comment #204)
Ok.  Makes me wonder in which order rtsx_{suspend,resume}, mmcsd_{suspend,resume} and mmc_{suspend,resume} are called.  They all have a DEVMETHOD device_suspend and a DEVMETHOD device_resume.
Comment 206 Gary Jennejohn 2020-06-11 16:45:41 UTC
(In reply to Gary Jennejohn from comment #205)
Of course, it could be that the dev being passed in is different for e.g. rtsx and mmc.  In that case it would make sense that rtsx also has to make the calls for its own dev.
Comment 207 Lars Engels freebsd_committer freebsd_triage 2020-06-11 17:45:52 UTC
I successfully tested several SD cards on 12.1 using the new port.

Thinkpad T450s

rtsx0@pci0:2:0:0:       class=0xff0000 card=0x503417aa chip=0x522710ec rev=0x01 hdr=0x00
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS5227 PCI Express Card Reader'
Comment 208 Gary Jennejohn 2020-06-13 08:47:06 UTC
(In reply to Henri Hennebert from comment #204)
Out of curiosity I decided to check whether saving and restoring the registers in suspend and resume is really necessary.
It turns out that the only necessary action required in suspend/resume is to call bus_generic_suspend() and bus_generic_resume().
Looking at the trace after resume makes it clear why that is the case.  MMC sends all the same CMDs after resume as it does when the module is first loaded.
Saving and restoring the registers is basically a waste of time since the actions taken by MMC during resume will modify the registers anyway.
After the resume I could immediately dd data from the SD card without any errors. I did not try mounting it, but if dd works then mounting should also work.
I tested with the RTS522A in a Thinkpad X270.  By the way I had to disable the TPM in order for resume to work.
Comment 209 Henri Hennebert 2020-06-13 09:00:18 UTC
(In reply to Gary Jennejohn from comment #208)

I will try this. 

BTW, I was able to start a dd ... status=progress (1GB) put the laptop to suspend (closing the lid), reopen and the dd is continuing smoothly. It work 3 times but after the 4th a chain of timeout/reset result in a lock of the dd. I can't kill it and the usb mouse was unusable (probably due to too much time lost in rtsx during the resume).
Comment 210 Gary Jennejohn 2020-06-13 09:12:52 UTC
(In reply to Henri Hennebert from comment #209)
I have an external USB disk attached which has all the sources etc. on it.
After resume, ls on the disk spat out all kinds of errors.  I had to umount and mount the disk to get it to work.
It appears that USB isn't being correctly re-initialized after suspend/resume.

It's really interesting that dd can pick up where it left off after suspend/resume, even if it fails after a few cycles.  I wonder whether the suspend/resume code in MMC is the cause.

As far as I can tell from looking at the driver sources rtsx is the only SD card reader driver which tries to support suspend/resume.
Comment 211 Henri Hennebert 2020-06-13 11:27:44 UTC
(In reply to Gary Jennejohn from comment #210)

I test, without rtsx loaded, with an usb disk and after resume the disk is lost.
The usb mouse too.

With the rtsx driver, if I vlc a video from the card, the resume is followed by a chain of timeout and the device /dev/mmcsd0 is lost.
Comment 212 Gary Jennejohn 2020-06-13 11:45:06 UTC
(In reply to Henri Hennebert from comment #211)
Did you do the vlc test with verbosedebug=1?  It might be enligtening to see whether/how vlc vs dd differs.  Of course, vlc is doing less linear accesses to the SD card than dd, since it's using a file system.  That can add all kinds of complications not directly related to the rtsx driver itself.

This might be interesting for Warner Losh (imp@), since AFAIK rtsx is the first driver which is trying to support suspend/resume.
Comment 213 Henri Hennebert 2020-06-13 13:59:32 UTC
Created attachment 215518 [details]
Trace of rtsx during a vlc suspend/resume
Comment 214 Henri Hennebert 2020-06-13 14:18:39 UTC
(In reply to Henri Hennebert from comment #213)

I do the test of vlc during suspend/resume.

Strangely the vlc freeze after resume (maybe on the sound) but the card is still accessible and can be read. The vlc can be killed and the usb mouse is ok.
I can run a new vlc without problem :-O

See attachment.

During a vlc I can see

Some CMD17/CMD18 (read up to 131072 bytes), a lot of CMD24/CMD25 (write) and long sequence of rtsx_mmcbr_release_host()/rtsx_mmcbr_acquire_host().
The file was on a card under zfs, this can explain the write operations.
Comment 215 unitrunker 2020-06-14 02:15:09 UTC
Ran this on a T440p with 12.1-RELEASE-p6

dmesg with invert option un-checked:

rtsx0: <Realtek RTS5227 PCI MMC/SD Card Reader> mem 0xf0500000-0xf0500fff at device 0.0 on pci1
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset
rtsx0: Controller timeout
rtsx0: Soft reset

dmesg with invert option checked:

rtsx0: <Realtek RTS5227! PCI MMC/SD Card Reader> mem 0xf0500000-0xf0500fff at device 0.0 on pci1
rtsx0: Card absent
Comment 216 unitrunker 2020-06-14 02:31:09 UTC
Above output same with what I found today in ports and what I cloned from today in github.
Comment 217 gnikl 2020-06-14 09:33:36 UTC
(In reply to commit-hook from comment #202)

Build fails on 11.3. With the following patch the build succeeds:

--cut--
--- rtsx.c~	2020-06-11 16:47:01.000000000 +0200
+++ rtsx.c	2020-06-14 10:51:27.873097000 +0200
@@ -37,10 +37,12 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <sys/types.h>
 #include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
 #include <sys/module.h>
 #include <sys/errno.h>
-#include <sys/kernel.h>
 #include <sys/bus.h>
 #include <sys/endian.h>
 #include <machine/bus.h>
--cut--

Note: The missing piece is "#include <sys/systm.h>". The other includes and the reordering are gleaned from other kernel sources referencing eg. bootverbose. I have no idea if there is a preferred include order.

Now the more interesting part: the driver works successfully with this device in a Fujitsu H730 laptop:

rtsx0@pci0:4:0:0:	class=0xff0000 card=0x187f10cf chip=0x522710ec rev=0x01 hdr=0x00
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS5227 PCI Express Card Reader'

The card status is detected properly, the inversion switch is not required. Reading from a msdosfs formatted 2GB card worked fine. Writing and suspend/resume was not tested yet.
Comment 218 Henri Hennebert 2020-06-14 10:31:48 UTC
(In reply to gnikl from comment #217)
(In reply to unitrunker from comment #216)

github updated:

- I add the include for FreeBSD 11

- I add more tweaks for RTS5227 to try to solve problem of unitrunker.

So please everyone with a RTS5227 should test the current master branch, thanks!
Comment 219 Thibault Payet 2020-06-14 12:41:02 UTC
Success story: I have a RTS5209 and using this driver I am able to mount sdcard,
and copy file on it (I tested by copying a backup of my msdosfs for raspberry pi).

Below the dmesg when inserting and then removing the card

rtsx0: <Realtek RTS5209 PCI MMC/SD Card Reader> mem 0xd1000000-0xd1000fff at device 0.0 on pci3
rtsx0: Card absent
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
mmcsd0: 16GB <SDHC SD 0.0 SN 17877DBF MFG 03/2018 by 18 4V> at mmc0 50.0MHz/4bit/256-block
rtsx0: Interrupt card inserted/removed
rtsx0: Card absent
mmc0: detached

I am using FreeBSD 12.1-RELEASE-p6
Comment 220 unitrunker 2020-06-15 03:39:10 UTC
Success on UFS formatted card:

rtsx0: <Realtek RTS5227 PCI MMC/SD Card Reader> mem 0xf0500000-0xf0500fff at device 0.0 on pci1
rtsx0: Card absent
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
mmcsd0: 256GB <SDHC SN256 8.0 SN xxxxxxxx MFG 02/2020 by 3 SD> at mmc0 50.0MHz/1bit/256-block
Comment 221 unitrunker 2020-06-15 04:01:00 UTC
I tried five cards.

One FAT32 formatted 16 GB and one UFS formatted 256 GB card worked.
A FAT32 formatted 8 GB and FAT32 formatted 32 GB card failed.
An NTFS formatted 256 GB card also failed.


FreeBSD 12.1-RELEASE-p6 GENERIC amd64
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Interrupt card inserted/removed
rtsx0: Card absent
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
mmc0: No compatible cards found on bus
mmc0: detached
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Interrupt card inserted/removed
rtsx0: Card absent
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
mmc0: No compatible cards found on bus
mmc0: detached
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
mmc0: No compatible cards found on bus
rtsx0: Interrupt card inserted/removed
rtsx0: Card absent
mmc0: detached
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD41
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
mmc0: ACMD41 failed, RESULT: 4
rtsx0: Controller timeout for CMD2
rtsx0: Soft reset
rtsx0: Controller timeout for CMD2
rtsx0: Soft reset
rtsx0: Controller timeout for CMD2
rtsx0: Soft reset
rtsx0: Controller timeout for CMD2
rtsx0: Soft reset
rtsx0: Interrupt card inserted/removed
rtsx0: Card absent
mmc0: detached
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
mmcsd0: 16GB <SDHC SS16G 8.0 SN xxxxxxxx MFG 05/2014 by 3 SD> at mmc0 50.0MHz/1bit/256-block
rtsx0: Interrupt card inserted/removed
rtsx0: Card absent
mmc0: detached
Comment 222 Henri Hennebert 2020-06-15 14:46:23 UTC
(In reply to unitrunker from comment #221)

Can you try the new master (4696b4c4...).

when inserting a card encounter a timeout, please remove it and reinsert it multiple time to see if it can detect it in the end.

Thanks for your time!
Comment 223 unitrunker 2020-06-16 04:26:22 UTC
four cards - 3 succeed. 4th one fails.

rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
mmcsd0: 256GB <SDHC SN256 8.0 SN xxxxxxxx MFG 02/2020 by 3 SD> at mmc0 50.0MHz/1bit/256-block
rtsx0: Interrupt card inserted/removed
rtsx0: Card absent
mmc0: detached
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
mmcsd0: 16GB <SDHC SS16G 8.0 SN xxxxxxxx MFG 05/2014 by 3 SD> at mmc0 50.0MHz/1bit/256-block
rtsx0: Interrupt card inserted/removed
rtsx0: Card absent
mmc0: detached
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
mmcsd0: 32GB <SDHC SL32G 8.0 SN xxxxxxxx MFG 10/2014 by 3 SD> at mmc0 50.0MHz/1bit/256-block
rtsx0: Interrupt card inserted/removed
rtsx0: Card absent
mmc0: detached
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
mmc0: No compatible cards found on bus
rtsx0: Interrupt card inserted/removed
rtsx0: Card absent
mmc0: detached
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
mmc0: No compatible cards found on bus
rtsx0: Interrupt card inserted/removed
rtsx0: Card absent
mmc0: detached
Comment 224 unitrunker 2020-06-16 04:29:55 UTC
Also I sometimes see a kernel panic at boot up.

rtsx0: Controller timeout for CMD8
rtsx0: Soft reset

Fatal trap 12: page fault while in kernel mode
cpuid = 3: apic id = 03
fault virtual address   = 0x530
fault code              = supervisor read data, page not present
instruction pointer     = 0x20:0xffffffff806ee7c5
stack pointer           = 0x28:0xffffffff82a29890
frame pointer           = 0x28:0xffffffff82a298f0
code segment            = base rx0, limit 0xfffff, type 0x1b
                        = DPL 0, pres 1, long 1, def32 0, gran 1
processor eflags        = interrupt enabled, resume, IOPL = 0
current process         = 0 (swapper)
type nummber            = 12
panic: page fault
cpuid = 0
time = 3
KDB: stack backtrace:
#0 0xffffffff80c1d307
#1 0xffffffff80bd063d
#2 0xffffffff89bd0493
#3 0xffffffff810a7dcc
#4 0xffffffff810a7e19
#5 0xffffffff810a740f
#6 0xffffffff81081bfc
#7 0xffffffff806f030f
#8 0xffffffff806f01f0
#9 0xffffffff80c07bb0
#10 0xffffffff80c07dd2
#11 0xffffffff80b66948
#12 0xffffffff8036b02c
Comment 225 Gary Jennejohn 2020-06-16 07:20:38 UTC
(In reply to unitrunker from comment #223)
What is the 4th card which fails?  Manufacturere, capacity, model?
The ones which work are all SDHC.  The one which fails may beed some spevial handling in the driver.
Comment 226 Gary Jennejohn 2020-06-16 07:24:09 UTC
(In reply to Gary Jennejohn from comment #225)
Unfortunately, this is not very useful information.  The location of the crash cannot be determined.
Did you get a crash dump?
Comment 227 unitrunker 2020-06-18 00:30:22 UTC
(In reply to Gary Jennejohn from comment #226)
Sorry - have not seen a crash dump yet. I've verified crash dumps work via sysctl debug.kdb.panic=1.
Comment 228 unitrunker 2020-06-18 00:37:03 UTC
(In reply to unitrunker from comment #224)
Missing backtrace symbols :

kdb_backtrace+0x67
vpanic+0x19d
panic+_0x43
trap_fatal+0x39c
trap_pfault_0x49
trap+0x29f
calltrap+0x8
mmc_go_discovery+0x9df
mmc_delayed_attach+0x30
run_interrupt_driven_config_hooks+0x100
boot_run_interrupt_driven_config_hooks+0x22
mi_startup+0x118
btext+0x2c
Comment 229 Zeus Panchenko 2020-06-18 06:53:02 UTC
master (15a1c4485ffbb8832d760b9647d67776a51a2b72) is broken for me

on boot, module reports present card while it is absent,
on card insertion, module reports detach
on removal it reports attach and attempts to detect card with heavy lags

I use Transcend microSD adaptor with 2Gb transcend card, 32Gb and 8Gb SiliconPower cards 

--[ dmesg ]-----------------------------------------------------------------
…
FreeBSD 12.1-RELEASE-p3 GENERIC amd64
…
rtsx0: <Realtek RTS5227 PCI MMC/SD Card Reader> mem 0xc1200000-0xc1200fff at device 0.0 on pci2
rtsx0: Card absent
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset

<<< card inserted >>>

rtsx0: Interrupt card inserted/removed
rtsx0: Card absent
mmc0: detached

<<< card removed >>>

rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD8
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
rtsx0: Controller timeout for CMD1
rtsx0: Soft reset
mmc0: No compatible cards found on bus
…
--[ dmesg ]-----------------------------------------------------------------

the working commit for the same test suite is d605a27259dd147f866b4e2640f6289323c2a8c7
Comment 230 Henri Hennebert 2020-06-18 07:40:30 UTC
(In reply to Zeus Panchenko from comment #229)

It is strange. Can you compile the module with:

make -D RTSX_INVERSION

Thanks and X-fingers
Comment 231 Gary Jennejohn 2020-06-18 09:23:17 UTC
(In reply to unitrunker from comment #228)
This is pretty weird.  Looking at my kernel. which has the same address for mmc_go_discovery() as your kernel, the panic is happening in a call to memset() in the first call to mmc_send_app_op_cond().
Apparently the compiler has optimized mmc_go_discovery() by inlining mmc_send_app_op_cond(), since that function is only used in mc_go_discovery().  This conclusion is supported by the fact that there is no entry for mmc_send_app_op_cond in the ELF header.
The really strange thing is that memset() is being called to zero out a struct mmc_command cmd which is on the kernel stack.  That should bever raise an error.  It should also never result in a calltrap, because this is an in-kernel call.
I must admit that I can see no way that this error could happen.
Comment 232 Zeus Panchenko 2020-06-18 11:17:29 UTC
(In reply to Henri Hennebert from comment #230)
it helped, now insert/remove is detected correctly

but

on card insert I'm getting this:

Jun 18 13:54:55 iz kernel: mmcsd0: 2GB <SD SD02G 3.8 SN A58756A6 MFG 05/2009 by 2 TM> (read-only) at mmc0 50.0MHz/1bit/256-block

on mount attempt, I'm getting

fs read-only and no mounted fs and after a couple of minutes panic and reboot

in logs this:

Jun 18 13:53:22 iz kernel: g_vfs_done():mmcsd0s1[WRITE(offset=16384, length=4096)]error = 30
Jun 18 13:53:22 iz syslogd: last message repeated 2 times
Jun 18 13:53:22 iz kernel: fsync: giving up on dirty (error = 30) 0xfffff802d79325a0: tag devfs, type VCHR
Jun 18 13:53:22 iz kernel:     usecount 1, writecount 0, refcount 472 rdev 0xfffff80132db9c00
Jun 18 13:53:22 iz kernel:     flags (VI_ACTIVE)
Jun 18 13:53:22 iz kernel:     v_object 0xfffff8028dd8d000 ref 0 pages 470 cleanbuf 469 dirtybuf 1
Jun 18 13:53:22 iz kernel:     lock type devfs: UNLOCKED
Jun 18 13:53:22 iz kernel:      dev mmcsd0s1
Comment 233 Gary Jennejohn 2020-06-18 12:26:02 UTC
(In reply to Zeus Panchenko from comment #232)
If the lock (read-only) tab was not set then that means two INVERSION defines are needed - one for card present and a different one for read-only.  Right now RTSX_INVERSION inverts both together.
So, was lock enabled?
Also, if you see that read-only is set then you must mount the filesystem as read-only.
Looks like there may be a bug in the VFS layer.
Comment 234 Henri Hennebert 2020-06-18 13:07:05 UTC
(In reply to Zeus Panchenko from comment #232)

Did you test on your HP Probook 430 g2 which was working before?

Did you test on a Lenovo P50 or Lenovo T470p?
Comment 235 Zeus Panchenko 2020-06-18 14:56:42 UTC
(In reply to Henri Hennebert from comment #234)

I have only HP PB 430 g2

master is broken, 15a1c448 works well (I'm checking out to it each time master fails to work)
Comment 236 Henri Hennebert 2020-06-18 16:41:10 UTC
(In reply to Zeus Panchenko from comment #235)

So between 15a1c448 and now, the card detection is inverted?
Comment 237 Zeus Panchenko 2020-06-18 17:04:57 UTC
(In reply to Henri Hennebert from comment #236)

yes, as I mentioned in #232, with inversion, insert/remove are detected correctly on master
Comment 238 Henri Hennebert 2020-06-18 18:10:33 UTC
(In reply to Zeus Panchenko from comment #237)
something really interesting to dig into. It may take some time but it itch me so ...
Comment 239 Dave Cottlehuber freebsd_committer freebsd_triage 2020-06-18 19:32:01 UTC
GTM here with 15a1c44 against 12.1Rp5

[179] rtsx0: <Realtek RTS525A PCI MMC/SD Card Reader> mem 0xdc100000-0xdc100fff at device 0.0 on pci3
[179] rtsx0: Card absent

mount/unmount, ro & rw to EFI partition.

more logs with debug.bootverbose=1 if needed https://gist.github.com/1b86f0c63575485423f90a8968e6baa2

I did get 1 panic already after successful unmount & device removal, I'll need to compile a debug kernel for next time.

Reading symbols from /boot/kernel/kernel...
(No debugging symbols found in /boot/kernel/kernel)
0xffffffff80c01eea in sched_switch ()
(kgdb) #0  0xffffffff80c01eea in sched_switch ()
#1  0xffffffff80bdbfb2 in mi_switch ()
#2  0xffffffff80c2bb85 in sleepq_catch_signals ()
#3  0xffffffff80c2b6bf in sleepq_wait_sig ()
#4  0xffffffff80b6a664 in _cv_wait_sig ()
#5  0xffffffff80c3c53f in seltdwait ()
#6  0xffffffff80c3c0cf in kern_select ()
#7  0xffffffff80c3c466 in sys_select ()
#8  0xffffffff810a8984 in amd64_syscall ()
#9  <signal handler called>
#10 0x00000008007b1dda in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fffffffcde8
(kgdb)
Comment 240 Henri Hennebert 2020-06-19 12:51:05 UTC
(In reply to Zeus Panchenko from comment #235)

> I have only HP PB 430 g2
> 
> master is broken, 15a1c448 works well (I'm checking out to it each time master > fails to work)

I am confused because 15a1c448 is the last master on 2020-06-18 when you put
your comment.

Anyway please try the current master: b1efa71bd7ebf308a59ae425d9b868e1f7c163b6

I don't have access to a RTS5227.

Thanks for your time and patience!
Comment 241 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-06-19 18:51:58 UTC
(In reply to Henri Hennebert from comment #240)
Perhaps you should consider asking the FreeBSD Foundation, for a little money and get your self some laptops from E-bay. I have not experience with the Foundation but I think this would be a worthy case :-)
https://www.freebsdfoundation.org/project-proposal-overview/
Comment 242 Gary Jennejohn 2020-06-20 06:34:55 UTC
(In reply to Jesper Schmitz Mouridsen from comment #241)
That's an interesting idea.  Several committers already offered to review the code, so that requirement is already covered.
Since arrwod@ added the driver as a port it's more or less already part of FreeBSD.
Maybe it's time to pay out the bounty?  Seems like Henri should get it.
Comment 243 Gleb Popov freebsd_committer freebsd_triage 2020-06-20 06:55:56 UTC
I'm absolutely for paying out the bounty, but I didn't track all the developments closely. Should the whole bounty go to Henry, or required to be spread between several developers?
Comment 244 Jesper Schmitz Mouridsen freebsd_committer freebsd_triage 2020-06-20 07:10:28 UTC
(In reply to Gleb Popov from comment #243)
I think it should go to Henri
Comment 245 Henri Hennebert 2020-06-20 07:19:15 UTC
(In reply to Jesper Schmitz Mouridsen from comment #241)
(In reply to Gleb Popov from comment #243)
(In reply to Jesper Schmitz Mouridsen from comment #244)

I don't need a RTS5227 because it is a process of trial and error and if someone is ready to test each iteration it should be fine.

For the bounty, I would send it to the FreeBSD foundation.
Comment 246 Gleb Popov freebsd_committer freebsd_triage 2020-06-20 07:20:31 UTC
(In reply to Henri Hennebert from comment #245)
Come on, you earned it. Please register on https://www.bountysource.com/ and claim https://www.bountysource.com/issues/75687739-new-driver-request-port-rtsx-from-openbsd-to-freebsd
Comment 247 Henri Hennebert 2020-06-20 07:26:42 UTC
(In reply to Zeus Panchenko from comment #237)

It would be interresting to test b1efa71bd7ebf308a59ae425d9b868e1f7c163b6
without inversion but commenting line 629-630 to see if detection is OK.

/*
	if (reg & 0x4000)
		sc->rtsx_flags |= RTSX_REVERSE_SOCKET;
*/
Comment 248 Henri Hennebert 2020-06-20 07:32:07 UTC
(In reply to Gleb Popov from comment #246)

I will do it and forward the bounty to the foundation after I buy a book on my wish list at amazon.co.uk. :-)
Comment 249 Gary Jennejohn 2020-06-20 08:14:30 UTC
(In reply to Henri Hennebert from comment #248)
Yes!  I personally didn't work on this project for the bounty but because I found it interesting and a way to contribute to the project.
Comment 250 gnikl 2020-06-20 08:49:14 UTC
(In reply to Henri Hennebert from comment #240)

FYI, b1efa71bd7ebf308a59ae425d9b868e1f7c163b6 does not work for RTS5227. That version produces timeouts and CMDx failures on my H730. During the initialization the machine is frozen so that I cannot switch virtual consoles but Ctrl-Alt-Del works ;) When the init code is done, the keyboard is operational again. Additionally with that version the card detection is inverted for me. Older versions (build through ports) have the card detection correct.

Now some further observations: With ports version 2020-06-11/2020-06-16 the driver works if I boot directly into FreeBSD when the machine is switched on. Rebooting the machine into Windows 7 and then back again into FreeBSD results in a non-working driver. If the card is inserted when loading the driver failure output is generated. If the card is not inserted while loading the driver, the driver prints information about the found HW but no card events are printed. Unloading the driver yields something about "nothing attached".

Furthermore somehow I managed to confuse the older driver versions as well, which then had the card detection inverted. I have to switched the machine off and wait for a certain amount of time to get the HW back in state that the older version like. I have no idea how I did that. Maybe booting Windows 7 first and then FreeBSD breaks the driver in a different way. IMHO this is a strong indication that the HW initialization by the driver is incomplete.
Comment 251 Henri Hennebert 2020-06-20 13:41:52 UTC
(In reply to gnikl from comment #250)

For the delay at startup, if a card is already inserted, it is due to the timeout in rtsx.

I put some more output at init of the chip (without bootverbose)

Please just test with the last master (1cb949167b42f3aac64f6a1bdb90540a825c14c2)

and report the output is /var/spool/messages or dmesg

I reread the init and poner_on/ pocer_off in linux and it seems that I mimic it but "Nobody's Perfect"...
Comment 252 Henri Hennebert 2020-06-20 16:07:22 UTC
(In reply to gnikl from comment #250)

I do some more reorg so please test with af4b601e5b55cdb12b7270672b4a824d944791c9
Comment 253 gnikl 2020-06-21 13:20:47 UTC
(In reply to Henri Hennebert from comment #252)

No change :-/ I don't have the /var/log/messages content available, sorry. The af4b... version locks the keyboard for some time when loaded after switching the laptop on and booting directly into FreeBSD. The pci_read_config in the 5227 block fails. At this point the driver can be unloaded but the eg. the normally working 25b5dac2d92 version does not work either. The card detection logic of that version is then also wrong. The 25b5dac2d92 version works when loaded after power-on when booted directly into FreeBSD. Card detection logic works as expected.
Comment 254 Mario Lobo 2020-06-21 14:52:25 UTC
Just a quick question.

I tested the driver on my RTL8411B and the git I cloned works perfectly, but I am wondering if the tweaks made to make the RT52xx chips work may affect the version I have now,

Is it OK to do a git pull?
Comment 255 Henri Hennebert 2020-06-21 15:27:16 UTC
(In reply to Mario Lobo from comment #254)

All the changes that I make are tested on my RTL8411B so you can update to the latest master without problem.
Comment 256 Henri Hennebert 2020-06-21 15:42:52 UTC
(In reply to gnikl from comment #253)

We will try to check the diff between d5a376b and 25b5dac when the computer is directly booted in FreeBSD without rtsx loaded at boot time.

So for 25b5dac:

<boot>
sysctl debug.bootverbose=1
kldload rtsx
insert card
sysctl debug.bootverbose=0

egrep 'mmc0|mmcsd0|rtsx0' /var/log/message >/tmp/msg

isolate the corresponding time period in /tmp/msg and put it as an attachment to this bug.

For d5a376b:

do the same.

I hope to see some information when I will compare the 2 attachments.

BTW does someone else with a RTS5227 encounter the same problem?

Thanks to everyone!
Comment 257 Zeus Panchenko 2020-06-22 08:00:56 UTC
Created attachment 215853 [details]
commit 44ab5957e6 doesn't work (In reply to Henri Hennebert from comment #247)
Comment 258 Zeus Panchenko 2020-06-22 08:02:44 UTC
(In reply to Henri Hennebert from comment #247)
1. git pull (to commit 44ab5957e6)
2. edit rtsx.c as you showed
3. make
4. sysctl debug.bootverbose=1
5. kldload /usr/local/src/rtsx/rtsx/rtsx.ko
6. insert card

on module load as well as on card insert/remove, keyboard freezes up to 1-2 minutes

output is attached with descr:
commit 44ab5957e6 doesn't work (In reply to Henri Hennebert from comment #247)
Comment 259 Henri Hennebert 2020-06-22 15:01:42 UTC
(In reply to gnikl from comment #253)

To see the problem with pci_read_config can you install port sysutils/pciutils

Then do

lspci -xxxx >/tmp/dump

isolate the output corresponding to Device 10ec:7227 and attach the result to this bug.

Thanks
Comment 260 Henri Hennebert 2020-06-22 16:03:41 UTC
(In reply to Zeus Panchenko from comment #257)
(In reply to gnikl from comment #253)

I change rtsx to not use vendor settings. please test 415995a (last commit).
Comment 261 Zeus Panchenko 2020-06-23 07:20:34 UTC
Created attachment 215874 [details]
In reply to Henri Hennebert from comment #260
Comment 262 Zeus Panchenko 2020-06-23 07:21:15 UTC
(In reply to Henri Hennebert from comment #260)

still the same (inversion and keyboard freeze on kldload and card insert/remove)

1. git pull (to commit 415995a)
2. make clean; make
3. sysctl debug.bootverbose=1
4. kldload /usr/local/src/rtsx/rtsx/rtsx.ko
5. insert card

log is attached
Comment 263 Henri Hennebert 2020-06-23 08:07:47 UTC
(In reply to Zeus Panchenko from comment #262)

I try to go back to  d605a27 step by step

Just test  106fb99 without bootverbose=1.

I go step by step because I want to pinpoint the problem of inversion of detection.

thank you for your patience and motivation.
Comment 264 gnikl 2020-06-23 16:59:33 UTC
(In reply to Henri Hennebert from comment #256)
(In reply to Henri Hennebert from comment #260)

I can report partial success for 106fb99f7c54616c3e853d942be4c2faf81c6d0b. There was a bug with RTSX_REVERSE_SOCKET for 5227 and 522A. With that fixed the card state is again detected successfully and I can access the card. I only tested booting into FreeBSD after power-on.

-- cut --
diff --git a/rtsx.c b/rtsx.c
index ae599ee..a4518e1 100644
--- a/rtsx.c
+++ b/rtsx.c
@@ -876,7 +876,7 @@ rtsx_init(struct rtsx_softc *sc)
 		RTSX_WRITE(sc, RTSX_SD30_CMD_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][1]);
 		RTSX_WRITE(sc, RTSX_SD30_DAT_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][2]);
 		/* Configure force_clock_req */
-		if (sc->rtsx_flags | RTSX_REVERSE_SOCKET)
+		if ((sc->rtsx_flags & RTSX_REVERSE_SOCKET) != 0)
 			RTSX_BITOP(sc, RTSX_PETXCFG, 0xB8, 0xB8);
 		else
 			RTSX_BITOP(sc, RTSX_PETXCFG, 0xB8, 0x88);
@@ -903,7 +903,7 @@ rtsx_init(struct rtsx_softc *sc)
 		RTSX_WRITE(sc, RTSX_SD30_CMD_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][1]);
 		RTSX_WRITE(sc, RTSX_SD30_DAT_DRIVE_SEL, driving_3v3[sc->rtsx_sd30_drive_sel_3v3][2]);
 		/* Configure force_clock_req */
-		if (sc->rtsx_flags | RTSX_REVERSE_SOCKET)
+		if ((sc->rtsx_flags & RTSX_REVERSE_SOCKET) != 0)
 			RTSX_BITOP(sc, RTSX_PETXCFG, 0xB8, 0xB8);
 		else
 			RTSX_BITOP(sc, RTSX_PETXCFG, 0xB8, 0x88);
-- cut --

(In reply to Henri Hennebert from comment #259)
Out of curiosity I activated the vendor code again which still fails but I suppose that is to be expected without a change in that part of the code. I forgot to get the lspci output. Are you still interested in that data?
Comment 265 Henri Hennebert 2020-06-23 17:53:38 UTC
(In reply to gnikl from comment #264)

First thank you for your test!

The RTSX_REVERSE_SOCKET is of no use here because it is only set in vendor settings.

The important diff are:

diff --git a/rtsx.c b/rtsx.c
index d22f912..ae599ee 100644
--- a/rtsx.c
+++ b/rtsx.c
@@ -776,8 +776,9 @@ rtsx_init(struct rtsx_softc *sc)
                /* Some magic numbers from linux driver */
                error = rtsx_write_phy(sc, 0x00, 0xB966);
        } else if (sc->rtsx_flags & RTSX_F_5227) {
-               /*!!!*/
-               RTSX_CLR(sc, RTSX_PM_CTRL3, RTSX_D3_DELINK_MODE_EN);
+               /*!!! added */
+//             RTSX_CLR(sc, RTSX_PM_CTRL3, RTSX_D3_DELINK_MODE_EN);
+
                /* Optimize RX sensitivity */
                error = rtsx_write_phy(sc, 0x00, 0xBA42);
        } else if (sc->rtsx_flags & RTSX_F_5229) {
@@ -832,6 +833,7 @@ rtsx_init(struct rtsx_softc *sc)
                 RTSX_FORCE_RST_CORE_EN | RTSX_NON_STICKY_RST_N_DBG);
 
        /* Card driving select */
+       /*!!! added */
        RTSX_WRITE(sc, RTSX_CARD_DRIVE_SEL, sc->rtsx_card_drive_sel);
 
        /* Enable SSC clock. */
@@ -855,7 +857,7 @@ rtsx_init(struct rtsx_softc *sc)
 
        /* Request clock by driving CLKREQ pin to zero. */
        /*!!!*/
-//     RTSX_SET(sc, RTSX_PETXCFG, RTSX_PETXCFG_CLKREQ_PIN);
+       RTSX_SET(sc, RTSX_PETXCFG, RTSX_PETXCFG_CLKREQ_PIN);
 
        /* Specific extra init */
        if (sc->rtsx_flags & RTSX_F_5227) {


It would be useful if you can retest 2 cases:

1. uniquely adding back RTSX_CLR(sc, RTSX_PM_CTRL3, RTSX_D3_DELINK_MODE_EN);

2. uniquely removing RTSX_SET(sc, RTSX_PETXCFG, RTSX_PETXCFG_CLKREQ_PIN);

For the lspci output, it is just for a better understanding in case vendor settings must be reintroduce.

To be honest I don't think I will reintroduce it because all go awry when, after wading through the linux source, I try to introduce vendor settings.

As we say in french "Le mieux est l'ennemi du bien". ;-)
Comment 266 gnikl 2020-06-23 20:06:41 UTC
Created attachment 215893 [details]
lspci output for RTS5227 (Fujtsu H730)
Comment 267 gnikl 2020-06-23 20:17:57 UTC
(In reply to Henri Hennebert from comment #265)

I added the lspci output. Maybe it has some value.

I modified the driver hopefully as requested.

> 1. uniquely adding back RTSX_CLR(sc, RTSX_PM_CTRL3, RTSX_D3_DELINK_MODE_EN);

I uncommented that line and kept the RTSX_SET uncommented. The sd card was usable with that modification.


> 2. uniquely removing RTSX_SET(sc, RTSX_PETXCFG, RTSX_PETXCFG_CLKREQ_PIN);

I commmented that line and kept the RTSX_CLR commented. The sd card was usable with that modification.

With both modifications the card detection worked and the card was usable. Unfortunately rebooting into FreeBSD from Windows is unchanged, the driver does not detect card insertion/removal.
Comment 268 Zeus Panchenko 2020-06-23 21:22:11 UTC
Created attachment 215894 [details]
dmesg (In reply to Henri Hennebert from comment #263)
Comment 269 Zeus Panchenko 2020-06-23 21:22:50 UTC
(In reply to Henri Hennebert from comment #263)
doesn't work for me :(
inversion is present, keyboard freeses on kldload or card insert/remove ... 
log is attached
Comment 270 Gary Jennejohn 2020-06-24 07:54:33 UTC
(In reply to gnikl from comment #267)
An lspci immediately after booting into FreeBSD from Windows 7 (without loading rtsx) could help Henri figure out what the Windows driver is setting in the registers to break the FreeBSD driver.
If you have rtsx integrated in the kernel then you'll have to remove it.
Comment 271 Henri Hennebert 2020-06-24 11:27:48 UTC
(In reply to gnikl from comment #267)

Thank you for your tests (exactly what I ask) and the lspci!

For the Windows problem, we will look at it later.

For now, as  Zeus Panchenko seems to have a special configuration of RTS5227 which don't work, I will create a branch for it and continue to explore this problem. If this can be solved, may be it will also be an answer to the Windows problem.

For now can you just test if the "Windows" problem exist with the all master at  d605a27.

Thanks!
Comment 272 Henri Hennebert 2020-06-24 11:57:03 UTC
(In reply to Zeus Panchenko from comment #269)

We are going to continue step by step.

Please checkout the branch  HP_PB_430_g2 

whithout make -D RTSX_INVERSION does it correctly detect the presence of a  card when it is inserted?

Does it correctly configure the card (creation of the /dev/mmcsd0 device)?

Thanks
Comment 273 gnikl 2020-06-24 19:57:31 UTC
(In reply to Henri Hennebert from comment #271)

> For now can you just test if the "Windows" problem exist with the all master at d605a27.

The RTSX_REVERSE_SOCKET problem is still present in that version. Did you forget to apply my patch?
Comment 274 Henri Hennebert 2020-06-25 06:06:11 UTC
(In reply to gnikl from comment #273)
OUPS, I forget to correct this. Done now in master and HP_PB_430_g2
Comment 275 gnikl 2020-06-25 20:23:58 UTC
(In reply to Henri Hennebert from comment #274)

28709c0e83c8e1cb99f1b553859c260f63d11fbf works when booted into FreeBSD [11.3] after power-on. At the first test I somehow managed to produce "SOFT RESET"s with CMD timeouts. I was unable to reproduce this behaviour a second time.
Comment 276 Henri Hennebert 2020-06-26 07:58:33 UTC
(In reply to gnikl from comment #275)
At least one good news.

For the next test I am interested in the output:

mmcsd0: ??GB <SD ...

To see the bus width and the frequency used.
Comment 277 Zeus Panchenko 2020-07-02 10:16:13 UTC
(In reply to Henri Hennebert from comment #272)

if I'm lucky card is detected but on mount attempt system panics



> Please checkout the branch  HP_PB_430_g2 

make went with one warning

rtsx.c:970:1: warning: unused function 'rtsx_map_sd_drive' [-Wunused-function]

> without make -D RTSX_INVERSION does it correctly detect the presence of a  card when it is inserted?

yes, on insert it reports present, on remove - absent

<<<<<<<<<< kldload >>>>>>>>>>
rtsx0: <Realtek RTS5227 PCI MMC/SD Card Reader> mem 0xc1200000-0xc1200fff at device 0.0 on pci2
rtsx0: Card absent

<<<<<<<<<< card inser >>>>>>>>>>
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
rtsx0: Controller timeout for CMD41
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset

<<<<<<<<<< sometimes it shows this and no mmcsd0 appears >>>>>>>>>>

mmc0: ACMD41 failed, RESULT: 4

<<<<<<<<<< card remove >>>>>>>>>>
rtsx0: Interrupt card inserted/removed
rtsx0: Card absent



> Does it correctly configure the card (creation of the /dev/mmcsd0 device)?

yes, it is (when it works)

<<<<<<<<<< card inser >>>>>>>>>>
rtsx0: Interrupt card inserted/removed
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
mmcsd0: 2GB <SD SD02G 3.8 SN A58756A6 MFG 05/2009 by 2 TM> (read-only) at mmc0 50.0MHz/4bit/256-block


ls -al /dev/mm*
crw-r-----  1 root  operator  0x2a1 Jul  2 11:36 /dev/mmcsd0
crw-r-----  1 root  operator  0x2a2 Jul  2 11:36 /dev/mmcsd0s1
Comment 278 Henri Hennebert 2020-07-02 10:56:13 UTC
(In reply to Zeus Panchenko from comment #277)

For the panic during mount, as the card is detected read-only, you must mount it read-only. Is the switch on the card on read-only?

The rtsx_map_sd_drive() not use is normal because I eliminate the vendor settings code.

I encounter from time to time the problem with:

rtsx0: Controller timeout for CMD41
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
rtsx0: Controller timeout for CMD55
rtsx0: Soft reset
mmc0: ACMD41 failed, RESULT: 4

and then:
rtsx0: Controller timeout for CMD2
rtsx0: Soft reset
rtsx0: Controller timeout for CMD2
rtsx0: Soft reset
rtsx0: Controller timeout for CMD2
rtsx0: Soft reset
rtsx0: Controller timeout for CMD2
rtsx0: Soft reset
mmc0: detached

But then if I remove the card and reinsert it, it is detected correctly.

Can you change the switch on the card and see if it is detected read-write?

Next it will be fine to test with the last master branch (20b8fc8) because I introduce some corrections.

Note that from 3 to 11 July I will be in holidays :-)

Thanks for your perseverance!
Comment 279 Zeus Panchenko 2020-07-06 08:07:10 UTC
(In reply to Henri Hennebert from comment #278)

> Is the switch on the card on read-only?

oh no ... shame on me ... yes, the switch was on ... :facepalm:

>  Can you change the switch on the card and see if it is detected read-write?

> Next it will be fine to test with the last master branch (20b8fc8) because
> I introduce some corrections.

confirm, now it works for me just as I expect it to

*thank* you!

> Note that from 3 to 11 July I will be in holidays :-)

have a nice time :)
Comment 280 Gleb Popov freebsd_committer freebsd_triage 2020-07-13 09:08:42 UTC
Temporarily close the bug to let Henry clain the bounty from https://www.bountysource.com/issues/75687739-new-driver-request-port-rtsx-from-openbsd-to-freebsd

The bug will be reopened after that.
Comment 281 Maxime Soulé 2020-07-19 19:54:31 UTC
Lenovo Thinkpad x260 + 12.1-RELEASE-p7 amd64 → b2a1844 OK

rtsx0@pci0:2:0:0:	class=0xff0000 card=0x504a17aa chip=0x522a10ec rev=0x01 hdr=0x00
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS522A PCI Express Card Reader'

Thank you for your work!
Comment 282 Zeus Panchenko 2020-07-19 21:31:57 UTC
confirm too, b2a1844 works well for me too
Comment 283 Henri Hennebert 2020-07-20 07:26:30 UTC
(In reply to Maxime Soulé from comment #281)
(In reply to Zeus Panchenko from comment #282)
Good news are always welcome :-)
Comment 284 Juan Ramón Molina Menor 2020-07-20 15:08:08 UTC
Lenovo Thinkpad S440 + 13.0-CURRENT

rtsx0@pci0:5:0:0:	class=0xff0000 rev=0x01 hdr=0x00 vendor=0x10ec device=0x5227 subvendor=0x17aa subdevice=0x501c card=0x504a17aa chip=0x522a10ec 
    vendor     = 'Realtek Semiconductor Co., Ltd.'
    device     = 'RTS5227 PCI Express Card Reader'

rtsx0: <Realtek RTS5227 PCI MMC/SD Card Reader> mem 0xf0400000-0xf0400fff at device 0.0 on pci4
rtsx0: card_drive_sel = 0x41, sd30_drive_sel_3v3 = 0x03, reverse_socket is true
rtsx0: Card present
mmc0: <MMC/SD bus> on rtsx0
mmcsd0: 4GB <SDHC SD04G 8.0 SN 503D95E6 MFG 07/2008 by 3 SD> at mmc0 50.0MHz/4bit/256-block


Thanks everybody!
Comment 285 Henri Hennebert 2020-07-20 18:30:19 UTC
Test of the new branch rtsx_set_sd_clock (cdf0314) is really needed.

Please help and

- if result is OK send device type and computer make to hlh@restart.be

- if result is KO post on bugzilla

Thanks VERY muck!
Comment 286 Henri Hennebert 2020-07-20 18:44:43 UTC
OUPS:

Thanks VERY MUCH
Comment 287 Zeus Panchenko 2020-07-23 12:07:35 UTC
(In reply to Henri Hennebert from comment #285)

for me 369e8b2f work well (same HP PB430g2)

email is sent
Comment 288 Dries Michiels freebsd_committer freebsd_triage 2020-07-25 12:09:44 UTC
Has this driver been committed to head yet? I see a lot of successes so I think its ready to be included?
Comment 289 dirkx 2020-07-25 12:12:24 UTC
+1 from me on that - it has been used in a production workflow on several IBM and dell laptops now for over 4 weeks and proven to be rock solid.
Comment 290 Henri Hennebert 2020-07-25 12:24:36 UTC
(In reply to Dries Michiels from comment #288)

For now there is an issue with RTS5229 when writing big file with dd :-/
https://github.com/hlh-restart/rtsx/issues/9
Comment 291 Henri Hennebert 2020-07-25 12:29:51 UTC
(In reply to dirkx from comment #289)

It would be very nice to test with the last instance:

Branch rtsx_set_sd_clock (be2a08c) which work very well on my RTL8411B.

I am interested to know your type of device and the make of your computer.

Can you test on a spare card something like:

dd if=/dev/random of=/dev/mmcsd0 bs=8192 count=10000

To see if the issue is only for RTS5229
Comment 292 Gleb Popov freebsd_committer freebsd_triage 2020-07-29 15:57:52 UTC
Reopening, the bounty has been paid out.
Comment 293 Gleb Popov freebsd_committer freebsd_triage 2020-08-01 10:41:25 UTC
Sorry for spamming, but it seems that Bountysource detected that the PR is opened again and blocked the cashout. Closing the PR again until I get an OK from Henri.
Comment 294 Henri Hennebert 2020-08-02 07:59:12 UTC
This morning I receive 320 Euro on my Paypal account.

Thank you to all donors and everyone for your help.

As planned, a donation of 295$ has been done to the FreeBSD Foundation.
Comment 295 Gleb Popov freebsd_committer freebsd_triage 2020-08-05 11:17:11 UTC
Reopening the bug.
Comment 296 commit-hook freebsd_committer freebsd_triage 2020-08-07 09:08:16 UTC
A commit references this bug:

Author: arrowd
Date: Fri Aug  7 09:07:40 UTC 2020
New revision: 544316
URL: https://svnweb.freebsd.org/changeset/ports/544316

Log:
  sysutils/rtsx-kmod: Update to 1.0f

  PR:		204521
  Reported by:	Henri Hennebert <hlh@restart.be>

Changes:
  head/sysutils/rtsx-kmod/Makefile
  head/sysutils/rtsx-kmod/distinfo
Comment 297 Tom "Ludensen" Christensen 2020-09-27 02:06:06 UTC
The pkg-message asks for reports.

Succesfully detected, mounted, read and wrote(5Gb image file) SD-card with this port on my Lenovo Thinkpad Yoga 1.

% uname -a
FreeBSD yoga.home 12.1-RELEASE-p10 FreeBSD 12.1-RELEASE-p10 GENERIC  amd64

THANK YOU for all the work!
Comment 298 Tom "Ludensen" Christensen 2020-09-27 02:09:32 UTC
Sorry, forgot

build-in RTS5227 PCI Express Card Reader
Comment 299 Philipp Engel 2020-10-02 13:11:31 UTC
Can confirm, rtsx-1.0.h,1 works with Realtek RTS522A (X270) on FreeBSD 12.1-RELEASE-p10. After loading the kernel module manually and inserting an SD card in the device, the keyboard stopped working. I cannot reproduce this behaviour, as this issue did not occur after a restart while loading the module at boot time.
Comment 300 Henri Hennebert 2020-10-02 15:15:38 UTC
(In reply to Philipp Engel from comment #299)
This keyboard problem seems linked to the inversion problem.

Does you have to set the INVERSION switch to have it working?

Can you reproduce the keyboard lock ?

Henri
Comment 301 Philipp Engel 2020-10-03 10:13:28 UTC
(In reply to Henri Hennebert from comment #300)

rtsx-kmod has been compiled with INVERSION off. I cannot reproduce this issue with: 

# kldunload rtsx
# kldload rtsx
Comment 302 Henri Hennebert 2020-10-03 10:16:51 UTC
(In reply to Philipp Engel from comment #301)
Thank you for your test.

So we will ignore for now this keyboard problem.
Comment 303 commit-hook freebsd_committer freebsd_triage 2020-11-24 21:29:47 UTC
A commit references this bug:

Author: jkim
Date: Tue Nov 24 21:28:45 UTC 2020
New revision: 367998
URL: https://svnweb.freebsd.org/changeset/base/367998

Log:
  Port rtsx(4) driver for Realtek SD card reader from OpenBSD.

  This driver provides support for Realtek PCI SD card readers.  It attaches
  mmc(4) bus on card insertion and detaches it on card removal.  It has been
  tested with RTS5209, RTS5227, RTS5229, RTS522A, RTS525A and RTL8411B.  It
  should also work with RTS5249, RTL8402 and RTL8411.

  PR:			204521
  Submitted by:		Henri Hennebert (hlh at restart dot be)
  Reviewed by:		imp, jkim
  Differential Revision:	https://reviews.freebsd.org/D26435

Changes:
  head/share/man/man4/Makefile
  head/share/man/man4/rtsx.4
  head/sys/amd64/conf/GENERIC
  head/sys/conf/NOTES
  head/sys/conf/files
  head/sys/dev/rtsx/
  head/sys/dev/rtsx/rtsx.c
  head/sys/dev/rtsx/rtsxreg.h
  head/sys/i386/conf/GENERIC
  head/sys/modules/Makefile
  head/sys/modules/rtsx/
  head/sys/modules/rtsx/Makefile