Bug 204521 - [new driver] [request] Port rtsx from OpenBSD to FreeBSD
Summary: [new driver] [request] Port rtsx from OpenBSD to FreeBSD
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs mailing list
URL: https://lists.freebsd.org/pipermail/f...
Keywords: feature, needs-patch
: 161719 (view as bug list)
Depends on:
Reported: 2015-11-13 13:02 UTC by evil.lombo
Modified: 2019-12-03 07:44 UTC (History)
25 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description evil.lombo 2015-11-13 13:02:29 UTC

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?


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

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.


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,
Comment 2 Gleb Popov freebsd_committer 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 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 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 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 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 hlh 2019-11-28 18:34:31 UTC
I have also a try at this problem:

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 hlh 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...

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 hlh 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  |................|

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  |................|

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.