3

I have a fairly large PCIe driver written on/for Linux, now I need to port it on FreeBSD. I don't yet know the BSD version, but I think at this point it's irrelevant, as I'd like to understand in general what major items will have to be modified during the porting efforts.

The good thing is that the driver is partitioned into OS independent "library" layer (OSI) and OS dependent, so it already has a "framework" permitting to port it on other OS-es, and I hope most of the efforts will be focused on OSI side. So far I see the following big chunks of work:

  1. init code, i.e. the OS-specific code that "plugs" the driver into system (similar to what init_module, cleanup_module does in Linux)
  2. code registering driver in a PCI core subsystem of the kernel
  3. character driver registration code 4) DMA operations

What else should I be paying attention to? This driver is a device doing hardware encryption, so it is offload device (ingress packets from NIC enter system normally and then diverted to the device).

If there are useful web links to description of BSD drivers development/porting (similar to LDD), I'd happily accept it :)

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
Mark
  • 6,052
  • 8
  • 61
  • 129
  • 2
    There is a chapter in the [handbook](http://www.freebsd.org/doc/en/books/arch-handbook/driverbasics.html), a more specific section on [pci devices](http://www.freebsd.org/doc/en_US.ISO8859-1/books/arch-handbook/pci.html), and an example in FreeBSD's [`/usr/share/examples/kld/cdev`](https://svnweb.freebsd.org/base/head/share/examples/kld/cdev/). There are also books like 'The Design and Implementation of the FreeBSD Operating System' and 'FreeBSD Device Drivers: A Guide for the Intrepid'. – kdhp Aug 22 '15 at 19:09
  • @kdhp, thanks for comment. Is there a significant difference writing driver ofr FreeBSD 6.x and 9.x/10.x releases? – Mark Aug 24 '15 at 13:29
  • 1
    The newest file in `/usr/share/examples/kld/cdev/module` is 9 years old, so the _basics_ should be the same. It may be worth noting that there are many permissively licensed examples, with long SVN histories, in the FreeBSD source tree. Also, manual pages in section 9 are part of the `FreeBSD Kernel Developer's Manual`, most of the kernel APIs are documented there. – kdhp Aug 24 '15 at 21:16

1 Answers1

10

In 2011, Jeff Roberson (and later Mellanox) added some shims to ease porting Linux drivers, which makes most of the code be used as-is, when he ported the Linux InfiniBand drivers to FreeBSD. So, assuming I am some newcomer from Linux driver development world, I'd start by looking at:

https://svnweb.freebsd.org/base/head/sys/ofed/include/linux/

Where you would find implementations of many required Linux driver API and their FreeBSD native counterpart.

There is another quickstart document by John-Mark, here, helpful for those who are already familiar with driver writing.

If you would prefer starting from the beginning, I think the FreeBSD Architecture Handbook would be an useful start point.

Additionally, there is a book by Kirk McKusick, Robert Watson and George Neville-Neil, titled "The Design and Implementation of the FreeBSD Operating System", the latest version at this time is 2nd edition, and the chapter 8 detailed device drivers.

Most device drivers are merely wrappers of hardware operation to fit OS interfaces, so a well layered driver should be relatively easy to port nowadays.

If you have questions, or is a vendor of hardware, you can also join various FreeBSD mailing lists (freebsd-drivers@, etc.).

LI Xin
  • 156
  • 3