Notes on porting FreeBSD network drivers to NetBSD
Introduction
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
FreeBSD: "BPF"
NetBSD: "BPFILTER"
[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>
(Nothing like SLIST in NetBSD)
[Name differences 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
FreeBSD: name:unit
NetBSD: xname
(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: no argument to xxxfree()
NetBSD: opaque argument to xxxfree()
FreeBSD: driver implements reference counting
NetBSD: automatic reference counting
FreeBSD has common ether_ioctl()
[Good - eliminates common code]
"struct ether_addr" member for address bytes
FreeBSD: "octet"
NetBSD: "ether_addr_octet"
[Gratuitous]
"ethercom" vs. "arpcom" in softc
[Technically, NetBSD is right]
Access to ethernet address
FreeBSD: in "arpcom", accessed there
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
FreeBSD: plain list at ifp->if_multiaddrs
NetBSD: special framework, part of "struct ethercom"
Differing members in "struct ifnet", and different
initialization (if_attach, ether_ifattach)
-xname vs name:unit
-FreeBSD: xxxinit() - for use by ether_ioctl()
-Ethernet address
Arguments to bpf functions
FreeBSD: ifp
NetBSD: ifp->if_bpf
Passing of received packets to upper layer
FreeBSD: ether header separate, to ether_input()
NetBSD: whole packet, indirectly through ifp->ifp_input
[Recent change in NetBSD]
NetBSD has an MII framework; drivers provide register access only