4 Porting low level drivers from FreeBSD
6 * Fixup #include lines.
8 <dev/pci/blah.h> -> <bus/pci/blah.h>
9 <dev/blah/blah.h> -> <dev/netif/blah/blah.h>
10 <net80211/blah.h> -> <netproto/802_11/blah.h>
12 remove <machine/bus.h>
13 remove <machine/resource.h>
21 pci_find_cap -> pci_find_extcap
23 In kmalloc calls, M_NOWAIT -> M_INTWAIT
27 m_collapse(m, M_NOWAIT, blah) -> m_defrag(m, M_NOWAIT)
29 bus_dmamap_load_mbuf_sg(dmat, map, m, segs, &nsegs, BUS_DMA_NOWAIT) ->
30 bus_dmamap_load_mbuf_segment(dmat, map, m, segs, maxscatter,
31 &nsegs, BUS_DMA_NOWAIT);
33 The maxscatter argument depends on the driver, '1' if you do not
38 IFQ_SET_MAXLEN(), ifp->if_snd.ifq_drv_maxlen = blah, IFQ_SET_READY() ->
39 ifq_set_maxlen(&ifp->if_snd, blah)
41 if_start() and if_ioctl() have an additional argument.
43 void blah_start(struct ifnet *, struct ifaltq_subque *);
44 int blah_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
46 In this situation the additional argument can usually be ignored.
48 if_inc_counter(ifp, IFCOUNTER_BLAH, 1) -> IFNET_STAT_INC(ifp, blah, 1)
49 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1) -> IFNET_STAT_INC(ifp, oerrors, 1)
51 if_drv_flags used with IFF_DRV_RUNNING ->
52 if_flags used with IFF_RUNNING
54 if_drv_flags used with IFF_DRV_OACTIVE ->
55 ifq_is_oactive(), ifq_set_oactive(), ifq_clr_oactive() as appropriate.
57 Be very careful here, review your patches to make sure you aren't
58 testing the wrong field against the IFF_* macro. All OACTIVE chanages
59 must use our API calls and not test the flag(s) directly.
61 * Change all struct mtx and related locking api calls and macros
62 to use struct lock (lockmgr locks).
64 struct mtx -> struct lock
66 lockmgr(lk, LK_EXCUSIVE)
67 lockmgr(lk, LK_RELEASE)
68 lockinit(lk, wmesg, 0, flags) (typically 0 or LK_CANRECURSE)
69 KKASSERT(lockstatus(lk) == LK_EXCUSIVE) (asserting held)
70 KKASSERT(lockstatus(lk) != LK_EXCUSIVE) (asserting not held)
72 * msleep() calls typically have to become lksleep() calls. However,
73 in these situations the wlan_global_serializer might also be held
74 and must be released, so it is best to wrap it in your own blahsleep()
75 function which does this in addition to the lksleep():
77 blah_sleep(struct blah_softc *sc, void *wchan,
78 int flags, const char *wmsg, int timo)
83 iws = wlan_is_serialized()
85 wlan_serialize_exit();
86 error = lksleep(wchan, appropriatelock, flags, wmsg, timo);
88 wlan_serialize_enter();
92 * Firmware loading and/or the general network init function may have
93 to release wlan_global_serializer similarly to how the blah_sleep()
94 releases it for the duration of the init function and firmware load.
96 * You may need a modevent infrastructure for module loading. See the
97 original driver for code or one of the drivers already ported, like
98 netif/ath or netif/iwn
100 * SYSCTL macros in FreeBSD may have a CTLFLAG_RWTUN which for us is
101 just CTLFLAG_RW plus an additional TUNABLE* macro (see netif/ath
104 * taskq_start_threads() API is slightly different.
106 taskqueue_start_threads(tq, 1, 0, name) ->
107 taskqueue_start_threads(tq, 1, TDPRI_KERN_DAEMON, -1, name)
109 * bus_setup_intr() is different.
111 bus_setup_intr(dev, irq, INTR_TYPE_NET | INTR_MPSAFE,
112 NULL, intrfunc, sc, &handle) ->
113 bus_setup_intr(dev, irq, INTR_MPSAFE,
114 intrfunc, sc, &handle, &wlan_global_serializer)
116 * callout API. callout_init_mtx() is already macrod to
119 callout_stop() -> callout_stop_sync()
120 callout_sched() -> must be converted to the proper callout_reset(...)
121 call (function must be re-provided).
123 * bus_dma_tag_create() API is dfferent.
125 bus_dma_tag_create(tag, alignment,
127 BUS_SPACE_MAXADDR_32BIT,
135 bus_dma_tag_create(tag, alignment,
137 BUS_SPACE_MAXADDR_32BIT,
141 BUS_DMA_NOWAIT, &dma->tag);
143 * device_printf() may be used with "%6D". This is a FreeBSD specific
144 conversion specifier that was removed from DragonFly. There is a
145 generic kether_ntoa() helper function that can be used for printing
146 MAC addresses. ath(4) also has an ath_hal_ether_sprintf() for this
147 purpose and the wlan stack has an ether_sprintf(). Simply removing
148 the __printflike() to silence the warning is wrong since that will
149 still not print the MAC address correctly (due to removed support
150 in the kprintf() functions).