2 * Copyright (C) 2018 Giuseppe Lettieri
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #if defined(__FreeBSD__)
29 #include <sys/cdefs.h> /* prerequisite */
31 #include <sys/types.h>
32 #include <sys/errno.h>
33 #include <sys/param.h> /* defines used in kernel.h */
34 #include <sys/kernel.h> /* types used in module initialization */
35 #include <sys/malloc.h>
38 #include <sys/rwlock.h>
39 #include <sys/selinfo.h>
40 #include <sys/sysctl.h>
41 #include <sys/socket.h> /* sockaddrs */
43 #include <net/if_var.h>
44 #include <machine/bus.h> /* bus_dmamap_* */
45 #include <sys/refcount.h>
52 #elif defined(__APPLE__)
54 #warning OSX support is only partial
62 #error Unsupported platform
64 #endif /* unsupported */
70 #include <net/netmap.h>
71 #include <dev/netmap/netmap_kern.h>
72 #include <dev/netmap/netmap_mem2.h>
77 netmap_null_sync(struct netmap_kring *kring, int flags)
85 netmap_null_krings_create(struct netmap_adapter *na)
87 return netmap_krings_create(na, 0);
91 netmap_null_reg(struct netmap_adapter *na, int onoff)
93 if (na->active_fds == 0) {
95 na->na_flags |= NAF_NETMAP_ON;
97 na->na_flags &= ~NAF_NETMAP_ON;
103 netmap_null_bdg_attach(const char *name, struct netmap_adapter *na,
113 netmap_get_null_na(struct nmreq_header *hdr, struct netmap_adapter **na,
114 struct netmap_mem_d *nmd, int create)
116 struct nmreq_register *req = (struct nmreq_register *)(uintptr_t)hdr->nr_body;
117 struct netmap_null_adapter *nna;
120 if (req->nr_mode != NR_REG_NULL) {
121 nm_prdis("not a null port");
126 nm_prerr("null ports cannot be re-opened");
131 nm_prerr("null ports must use an existing allocator");
135 nna = nm_os_malloc(sizeof(*nna));
140 snprintf(nna->up.name, sizeof(nna->up.name), "null:%s", hdr->nr_name);
142 nna->up.nm_txsync = netmap_null_sync;
143 nna->up.nm_rxsync = netmap_null_sync;
144 nna->up.nm_register = netmap_null_reg;
145 nna->up.nm_krings_create = netmap_null_krings_create;
146 nna->up.nm_krings_delete = netmap_krings_delete;
147 nna->up.nm_bdg_attach = netmap_null_bdg_attach;
148 nna->up.nm_mem = netmap_mem_get(nmd);
150 nna->up.num_tx_rings = req->nr_tx_rings;
151 nna->up.num_rx_rings = req->nr_rx_rings;
152 nna->up.num_tx_desc = req->nr_tx_slots;
153 nna->up.num_rx_desc = req->nr_rx_slots;
154 error = netmap_attach_common(&nna->up);
158 netmap_adapter_get(*na);
159 nm_prdis("created null %s", nna->up.name);
170 #endif /* WITH_NMNULL */