Notes on porting FreeBSD network drivers to NetBSD


Matthias Drochner has collected these notes of differences encountered while porting FreeBSD network drivers to NetBSD, in the hope that it will be helpful.

Simple include file and definition stuff

  • #include file names/locations are quite different

  • packetfilter: "BPF" on FreeBSD, "BPFILTER" on NetBSD. [Looks gratuitous; seems to differ a lot between OSes (DEC: "packetfilter")]

  • NetBSD needs to include "opt_inet.h" and "opt_ns.h"

  • Global variable "bootverbose" doesn't exist on NetBSD

  • NetBSD has central PCI ID database and PCI register definitions

  • if_media: FreeBSD: IFM_1000_SX, NetBSD: IFM_1000_FX [There is nothing like 1000_FX - NetBSD is wrong]

  • Different stuff in <sys/queue.h> (There is nothing like SLIST in NetBSD; Name differences are gratuitous, but an SLIST-like thing could be useful for NetBSD (less overhead than SIMPLEQ)).

Framework, not network specific

  • Different autoconfiguration framework

  • Printouts with device name: name:unit on FreeBSD, xname on NetBSD (Similar in "struct ifnet")

  • Interrupt handler void on FreeBSD, int on NetBSD [Detection of stray interrupts???]

  • bus.h: access to virtual address for mapped range (it is usually best to just avoid linear mappings, since not all hardware supports it, but when absolutely necessary, BUS_SPACE_MAP_LINEAR should provide this) [Missing in NetBSD's bus_space framework. Potential source of inportability, use bus_space_xxx if feasible.]

  • bus_dma issues (FreeBSD has still old functions)

Network stuff

  • External mbuf storage handling: FreeBSD has no argument to xxxfree() and the driver implements reference counting. NetBSD has an opaque argument to xxxfree() and does automatic reference counting.

  • FreeBSD has common ether_ioctl() [Good - eliminates common code]

  • "struct ether_addr" member for address bytes: FreeBSD uses "octet", NetBSD has "ether_addr_octet". [Gratuitous]

  • "ethercom" vs. "arpcom" in softc [Technically, NetBSD is right]

  • Access to ethernet address: on FreeBSD in "arpcom", accessed there, on NetBSD passed to ether_ifattach(), accessed through ifp (LLADDR() - watch out for alignment problems!) [NetBSD can't deal with address changes at runtime]

  • Multicast address list: on FreeBSD a plain list at ifp->if_multiaddrs, on NetBSD a special framework, part of "struct ethercom"

  • Differing members in "struct ifnet", and different initialization (if_attach, ether_ifattach): xname vs name:unit, on FreeBSD xxxinit() is for use by ether_ioctl(), Ethernet address

  • Arguments to bpf functions: ipf on FreeBSD, ifp->if_bpf on NetBSD

  • Passing of received packets to upper layer: on FreeBSD: ether header separate, to ether_input(); on NetBSD: whole packet, indirectly through ifp->ifp_input

  • NetBSD has an MII framework; drivers provide register access only

Back to NetBSD Documentation: Kernel