Date: Fri, 10 Feb 2017 18:39:23 +0800 (CST)
From: "Jia-Ju Bai" <baijiaju1990%163.com@localhost>
I find the Realtek 8169 driver is built in the kernel, but how to
built it as a kernel module and load it at runtime?
I assume you mean re(4). Nobody has written the code to make that
driver modular. re(4) has multiple bus interfaces, PCI and Cardbus,
so it needs at least two modules:
1. a module called re for the common bus-independent code;
2. a module called if_re_pci for the PCI attachment;
and, if you care about Cardbus,
3. a module called if_re_cardbus for the Cardbus attachment.
Each module needs (a) a directory in sys/modules/ with a Makefile, and
(b) a MODULE declaration and <modulename>_modcmd function in one of
its associated .c files. The bus attachment module also needs an
ioconf file mimicking the kernel config.
There's an example of this for ath(4): sys/modules/ath,
sys/modules/if_ath_pci. For re, you need `.PATH: ${S}/dev/ic' and
`SRCS=rtl8169.c', if I have guessed right from sys/conf/files; for
if_re_pci, you need `.PATH: ${S}/dev/pci' and `SRCS=if_re_pci.c'. The
ioconf for if_re_pci should be just like the ioconf for if_ath_pci,
but with `re' substituted for `ath'. The MODULE declarations and
<modulename>_modcmd functions should look similar to what you find in
dev/ic/ath_netbsd.c and dev/pci/if_ath_pci.c.