Deleted Added
full compact
netmap_freebsd.c (259412) netmap_freebsd.c (260368)
1/*
1/*
2 * Copyright (C) 2013 Universita` di Pisa. All rights reserved.
2 * Copyright (C) 2013-2014 Universita` di Pisa. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the

--- 7 unchanged lines hidden (view full) ---

18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the

--- 7 unchanged lines hidden (view full) ---

18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26/* $FreeBSD: head/sys/dev/netmap/netmap_freebsd.c 259412 2013-12-15 08:37:24Z luigi $ */
26/* $FreeBSD: head/sys/dev/netmap/netmap_freebsd.c 260368 2014-01-06 12:53:15Z luigi $ */
27
28#include <sys/types.h>
29#include <sys/module.h>
30#include <sys/errno.h>
31#include <sys/param.h> /* defines used in kernel.h */
32#include <sys/kernel.h> /* types used in module initialization */
33#include <sys/conf.h> /* DEV_MODULE */
34

--- 46 unchanged lines hidden (view full) ---

81 }
82 ifp->if_input = gna->save_if_input;
83 gna->save_if_input = NULL;
84 }
85
86 return 0;
87}
88
27
28#include <sys/types.h>
29#include <sys/module.h>
30#include <sys/errno.h>
31#include <sys/param.h> /* defines used in kernel.h */
32#include <sys/kernel.h> /* types used in module initialization */
33#include <sys/conf.h> /* DEV_MODULE */
34

--- 46 unchanged lines hidden (view full) ---

81 }
82 ifp->if_input = gna->save_if_input;
83 gna->save_if_input = NULL;
84 }
85
86 return 0;
87}
88
89
89/*
90 * Intercept the packet steering routine in the tx path,
91 * so that we can decide which queue is used for an mbuf.
92 * Second argument is non-zero to intercept, 0 to restore.
93 *
90/*
91 * Intercept the packet steering routine in the tx path,
92 * so that we can decide which queue is used for an mbuf.
93 * Second argument is non-zero to intercept, 0 to restore.
94 *
95 * actually we also need to redirect the if_transmit ?
96 *
94 * XXX see if FreeBSD has such a mechanism
95 */
96void
97 * XXX see if FreeBSD has such a mechanism
98 */
99void
97netmap_catch_packet_steering(struct netmap_generic_adapter *na, int enable)
100netmap_catch_tx(struct netmap_generic_adapter *gna, int enable)
98{
101{
102 struct netmap_adapter *na = &gna->up.up;
103 struct ifnet *ifp = na->ifp;
104
99 if (enable) {
105 if (enable) {
106 na->if_transmit = ifp->if_transmit;
107 ifp->if_transmit = netmap_transmit;
100 } else {
108 } else {
109 ifp->if_transmit = na->if_transmit;
101 }
102}
103
110 }
111}
112
113
104/* Transmit routine used by generic_netmap_txsync(). Returns 0 on success
105 * and non-zero on error (which may be packet drops or other errors).
106 * addr and len identify the netmap buffer, m is the (preallocated)
107 * mbuf to use for transmissions.
108 *
109 * We should add a reference to the mbuf so the m_freem() at the end
110 * of the transmission does not consume resources.
111 *

--- 9 unchanged lines hidden (view full) ---

121 void *addr, u_int len, u_int ring_nr)
122{
123 int ret;
124
125 m->m_len = m->m_pkthdr.len = 0;
126
127 // copy data to the mbuf
128 m_copyback(m, 0, len, addr);
114/* Transmit routine used by generic_netmap_txsync(). Returns 0 on success
115 * and non-zero on error (which may be packet drops or other errors).
116 * addr and len identify the netmap buffer, m is the (preallocated)
117 * mbuf to use for transmissions.
118 *
119 * We should add a reference to the mbuf so the m_freem() at the end
120 * of the transmission does not consume resources.
121 *

--- 9 unchanged lines hidden (view full) ---

131 void *addr, u_int len, u_int ring_nr)
132{
133 int ret;
134
135 m->m_len = m->m_pkthdr.len = 0;
136
137 // copy data to the mbuf
138 m_copyback(m, 0, len, addr);
129
130 // inc refcount. We are alone, so we can skip the atomic
131 atomic_fetchadd_int(m->m_ext.ref_cnt, 1);
132 m->m_flags |= M_FLOWID;
133 m->m_pkthdr.flowid = ring_nr;
134 m->m_pkthdr.rcvif = ifp; /* used for tx notification */
139 // inc refcount. We are alone, so we can skip the atomic
140 atomic_fetchadd_int(m->m_ext.ref_cnt, 1);
141 m->m_flags |= M_FLOWID;
142 m->m_pkthdr.flowid = ring_nr;
143 m->m_pkthdr.rcvif = ifp; /* used for tx notification */
135 ret = ifp->if_transmit(ifp, m);
144 ret = NA(ifp)->if_transmit(ifp, m);
136 return ret;
137}
138
145 return ret;
146}
147
148
139/*
140 * The following two functions are empty until we have a generic
141 * way to extract the info from the ifp
142 */
143int
144generic_find_num_desc(struct ifnet *ifp, unsigned int *tx, unsigned int *rx)
145{
146 D("called");
147 return 0;
148}
149
149/*
150 * The following two functions are empty until we have a generic
151 * way to extract the info from the ifp
152 */
153int
154generic_find_num_desc(struct ifnet *ifp, unsigned int *tx, unsigned int *rx)
155{
156 D("called");
157 return 0;
158}
159
160
150void
151generic_find_num_queues(struct ifnet *ifp, u_int *txq, u_int *rxq)
152{
153 D("called");
154 *txq = 1;
155 *rxq = 1;
156}
157
161void
162generic_find_num_queues(struct ifnet *ifp, u_int *txq, u_int *rxq)
163{
164 D("called");
165 *txq = 1;
166 *rxq = 1;
167}
168
169
158void netmap_mitigation_init(struct netmap_generic_adapter *na)
159{
160 ND("called");
161 na->mit_pending = 0;
162}
163
164
165void netmap_mitigation_start(struct netmap_generic_adapter *na)
166{
167 ND("called");
168}
169
170void netmap_mitigation_init(struct netmap_generic_adapter *na)
171{
172 ND("called");
173 na->mit_pending = 0;
174}
175
176
177void netmap_mitigation_start(struct netmap_generic_adapter *na)
178{
179 ND("called");
180}
181
182
170void netmap_mitigation_restart(struct netmap_generic_adapter *na)
171{
172 ND("called");
173}
174
183void netmap_mitigation_restart(struct netmap_generic_adapter *na)
184{
185 ND("called");
186}
187
188
175int netmap_mitigation_active(struct netmap_generic_adapter *na)
176{
177 ND("called");
178 return 0;
179}
180
189int netmap_mitigation_active(struct netmap_generic_adapter *na)
190{
191 ND("called");
192 return 0;
193}
194
195
181void netmap_mitigation_cleanup(struct netmap_generic_adapter *na)
182{
183 ND("called");
184}
185
196void netmap_mitigation_cleanup(struct netmap_generic_adapter *na)
197{
198 ND("called");
199}
200
201
186/*
187 * In order to track whether pages are still mapped, we hook into
188 * the standard cdev_pager and intercept the constructor and
189 * destructor.
190 */
191
192struct netmap_vm_handle_t {
193 struct cdev *dev;
194 struct netmap_priv_d *priv;
195};
196
202/*
203 * In order to track whether pages are still mapped, we hook into
204 * the standard cdev_pager and intercept the constructor and
205 * destructor.
206 */
207
208struct netmap_vm_handle_t {
209 struct cdev *dev;
210 struct netmap_priv_d *priv;
211};
212
213
197static int
198netmap_dev_pager_ctor(void *handle, vm_ooffset_t size, vm_prot_t prot,
199 vm_ooffset_t foff, struct ucred *cred, u_short *color)
200{
201 struct netmap_vm_handle_t *vmh = handle;
202 D("handle %p size %jd prot %d foff %jd",
203 handle, (intmax_t)size, prot, (intmax_t)foff);
204 dev_ref(vmh->dev);

--- 8 unchanged lines hidden (view full) ---

213 struct cdev *dev = vmh->dev;
214 struct netmap_priv_d *priv = vmh->priv;
215 D("handle %p", handle);
216 netmap_dtor(priv);
217 free(vmh, M_DEVBUF);
218 dev_rel(dev);
219}
220
214static int
215netmap_dev_pager_ctor(void *handle, vm_ooffset_t size, vm_prot_t prot,
216 vm_ooffset_t foff, struct ucred *cred, u_short *color)
217{
218 struct netmap_vm_handle_t *vmh = handle;
219 D("handle %p size %jd prot %d foff %jd",
220 handle, (intmax_t)size, prot, (intmax_t)foff);
221 dev_ref(vmh->dev);

--- 8 unchanged lines hidden (view full) ---

230 struct cdev *dev = vmh->dev;
231 struct netmap_priv_d *priv = vmh->priv;
232 D("handle %p", handle);
233 netmap_dtor(priv);
234 free(vmh, M_DEVBUF);
235 dev_rel(dev);
236}
237
238
221static int
222netmap_dev_pager_fault(vm_object_t object, vm_ooffset_t offset,
223 int prot, vm_page_t *mres)
224{
225 struct netmap_vm_handle_t *vmh = object->handle;
226 struct netmap_priv_d *priv = vmh->priv;
227 vm_paddr_t paddr;
228 vm_page_t page;

--- 182 unchanged lines hidden ---
239static int
240netmap_dev_pager_fault(vm_object_t object, vm_ooffset_t offset,
241 int prot, vm_page_t *mres)
242{
243 struct netmap_vm_handle_t *vmh = object->handle;
244 struct netmap_priv_d *priv = vmh->priv;
245 vm_paddr_t paddr;
246 vm_page_t page;

--- 182 unchanged lines hidden ---