Deleted Added
full compact
netmap_kern.h (231198) netmap_kern.h (231594)
1/*
1/*
2 * Copyright (C) 2011 Matteo Landi, Luigi Rizzo. All rights reserved.
2 * Copyright (C) 2011-2012 Matteo Landi, Luigi Rizzo. 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

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

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/*
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

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

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/*
27 * $FreeBSD: head/sys/dev/netmap/netmap_kern.h 231198 2012-02-08 11:43:29Z luigi $
27 * $FreeBSD: head/sys/dev/netmap/netmap_kern.h 231594 2012-02-13 18:56:34Z luigi $
28 * $Id: netmap_kern.h 9795 2011-12-02 11:39:08Z luigi $
29 *
30 * The header contains the definitions of constants and function
31 * prototypes used only in kernelspace.
32 */
33
34#ifndef _NET_NETMAP_KERN_H_
35#define _NET_NETMAP_KERN_H_
36
28 * $Id: netmap_kern.h 9795 2011-12-02 11:39:08Z luigi $
29 *
30 * The header contains the definitions of constants and function
31 * prototypes used only in kernelspace.
32 */
33
34#ifndef _NET_NETMAP_KERN_H_
35#define _NET_NETMAP_KERN_H_
36
37#if defined(__FreeBSD__)
38#define NM_LOCK_T struct mtx
39#define NM_SELINFO_T struct selinfo
40#define MBUF_LEN(m) ((m)->m_pkthdr.len)
41#define NM_SEND_UP(ifp, m) ((ifp)->if_input)(ifp, m)
42#elif defined (__linux__)
43#define NM_LOCK_T spinlock_t
44#define NM_SELINFO_T wait_queue_head_t
45#define MBUF_LEN(m) ((m)->len)
46#define NM_SEND_UP(ifp, m) netif_rx(m)
47#else
48#error unsupported platform
49#endif
50
37#ifdef MALLOC_DECLARE
38MALLOC_DECLARE(M_NETMAP);
39#endif
40
41#define ND(format, ...)
42#define D(format, ...) \
43 do { \
44 struct timeval __xxts; \
45 microtime(&__xxts); \
46 printf("%03d.%06d %s [%d] " format "\n", \
47 (int)__xxts.tv_sec % 1000, (int)__xxts.tv_usec, \
48 __FUNCTION__, __LINE__, ##__VA_ARGS__); \
49 } while (0)
50
51struct netmap_adapter;
52
53/*
54 * private, kernel view of a ring.
55 *
51#ifdef MALLOC_DECLARE
52MALLOC_DECLARE(M_NETMAP);
53#endif
54
55#define ND(format, ...)
56#define D(format, ...) \
57 do { \
58 struct timeval __xxts; \
59 microtime(&__xxts); \
60 printf("%03d.%06d %s [%d] " format "\n", \
61 (int)__xxts.tv_sec % 1000, (int)__xxts.tv_usec, \
62 __FUNCTION__, __LINE__, ##__VA_ARGS__); \
63 } while (0)
64
65struct netmap_adapter;
66
67/*
68 * private, kernel view of a ring.
69 *
56 * XXX 20110627-todo
57 * The index in the NIC and netmap ring is offset by nkr_hwofs slots.
70 * The indexes in the NIC and netmap rings are offset by nkr_hwofs slots.
58 * This is so that, on a reset, buffers owned by userspace are not
59 * modified by the kernel. In particular:
71 * This is so that, on a reset, buffers owned by userspace are not
72 * modified by the kernel. In particular:
60 * RX rings: the next empty buffer (hwcur + hwavail + hwofs) coincides
73 * RX rings: the next empty buffer (hwcur + hwavail + hwofs) coincides with
61 * the next empty buffer as known by the hardware (next_to_check or so).
62 * TX rings: hwcur + hwofs coincides with next_to_send
63 */
64struct netmap_kring {
65 struct netmap_ring *ring;
66 u_int nr_hwcur;
67 int nr_hwavail;
68 u_int nr_kflags; /* private driver flags */
69#define NKR_PENDINTR 0x1 // Pending interrupt.
70 u_int nkr_num_slots;
71
72 int nkr_hwofs; /* offset between NIC and netmap ring */
74 * the next empty buffer as known by the hardware (next_to_check or so).
75 * TX rings: hwcur + hwofs coincides with next_to_send
76 */
77struct netmap_kring {
78 struct netmap_ring *ring;
79 u_int nr_hwcur;
80 int nr_hwavail;
81 u_int nr_kflags; /* private driver flags */
82#define NKR_PENDINTR 0x1 // Pending interrupt.
83 u_int nkr_num_slots;
84
85 int nkr_hwofs; /* offset between NIC and netmap ring */
73 struct netmap_adapter *na; // debugging
74 struct selinfo si; /* poll/select wait queue */
86 struct netmap_adapter *na;
87 NM_SELINFO_T si; /* poll/select wait queue */
88 NM_LOCK_T q_lock; /* used if no device lock available */
75} __attribute__((__aligned__(64)));
76
77/*
89} __attribute__((__aligned__(64)));
90
91/*
78 * This struct is part of and extends the 'struct adapter' (or
92 * This struct extends the 'struct adapter' (or
79 * equivalent) device descriptor. It contains all fields needed to
80 * support netmap operation.
81 */
82struct netmap_adapter {
83 int refcount; /* number of user-space descriptors using this
84 interface, which is equal to the number of
85 struct netmap_if objs in the mapped region. */
86
87 int separate_locks; /* set if the interface suports different
88 locks for rx, tx and core. */
89
90 u_int num_queues; /* number of tx/rx queue pairs: this is
91 a duplicate field needed to simplify the
92 signature of ``netmap_detach``. */
93
94 u_int num_tx_desc; /* number of descriptor in each queue */
95 u_int num_rx_desc;
93 * equivalent) device descriptor. It contains all fields needed to
94 * support netmap operation.
95 */
96struct netmap_adapter {
97 int refcount; /* number of user-space descriptors using this
98 interface, which is equal to the number of
99 struct netmap_if objs in the mapped region. */
100
101 int separate_locks; /* set if the interface suports different
102 locks for rx, tx and core. */
103
104 u_int num_queues; /* number of tx/rx queue pairs: this is
105 a duplicate field needed to simplify the
106 signature of ``netmap_detach``. */
107
108 u_int num_tx_desc; /* number of descriptor in each queue */
109 u_int num_rx_desc;
96 u_int buff_size;
110 u_int buff_size;
97
111
98 u_int flags;
112 //u_int flags; // XXX unused
99 /* tx_rings and rx_rings are private but allocated
100 * as a contiguous chunk of memory. Each array has
101 * N+1 entries, for the adapter queues and for the host queue.
102 */
103 struct netmap_kring *tx_rings; /* array of TX rings. */
104 struct netmap_kring *rx_rings; /* array of RX rings. */
105
106 /* copy of if_qflush and if_transmit pointers, to intercept
107 * packets from the network stack when netmap is active.
108 * XXX probably if_qflush is not necessary.
109 */
113 /* tx_rings and rx_rings are private but allocated
114 * as a contiguous chunk of memory. Each array has
115 * N+1 entries, for the adapter queues and for the host queue.
116 */
117 struct netmap_kring *tx_rings; /* array of TX rings. */
118 struct netmap_kring *rx_rings; /* array of RX rings. */
119
120 /* copy of if_qflush and if_transmit pointers, to intercept
121 * packets from the network stack when netmap is active.
122 * XXX probably if_qflush is not necessary.
123 */
110 void (*if_qflush)(struct ifnet *);
124 //void (*if_qflush)(struct ifnet *); // XXX unused
111 int (*if_transmit)(struct ifnet *, struct mbuf *);
112
113 /* references to the ifnet and device routines, used by
114 * the generic netmap functions.
115 */
116 struct ifnet *ifp; /* adapter is ifp->if_softc */
117
125 int (*if_transmit)(struct ifnet *, struct mbuf *);
126
127 /* references to the ifnet and device routines, used by
128 * the generic netmap functions.
129 */
130 struct ifnet *ifp; /* adapter is ifp->if_softc */
131
132 NM_LOCK_T core_lock; /* used if no device lock available */
133
118 int (*nm_register)(struct ifnet *, int onoff);
134 int (*nm_register)(struct ifnet *, int onoff);
119 void (*nm_lock)(void *, int what, u_int ringid);
120 int (*nm_txsync)(void *, u_int ring, int lock);
121 int (*nm_rxsync)(void *, u_int ring, int lock);
135 void (*nm_lock)(struct ifnet *, int what, u_int ringid);
136 int (*nm_txsync)(struct ifnet *, u_int ring, int lock);
137 int (*nm_rxsync)(struct ifnet *, u_int ring, int lock);
122};
123
124/*
125 * The combination of "enable" (ifp->if_capabilities &IFCAP_NETMAP)
126 * and refcount gives the status of the interface, namely:
127 *
128 * enable refcount Status
129 *

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

139/*
140 * parameters for (*nm_lock)(adapter, what, index)
141 */
142enum {
143 NETMAP_NO_LOCK = 0,
144 NETMAP_CORE_LOCK, NETMAP_CORE_UNLOCK,
145 NETMAP_TX_LOCK, NETMAP_TX_UNLOCK,
146 NETMAP_RX_LOCK, NETMAP_RX_UNLOCK,
138};
139
140/*
141 * The combination of "enable" (ifp->if_capabilities &IFCAP_NETMAP)
142 * and refcount gives the status of the interface, namely:
143 *
144 * enable refcount Status
145 *

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

155/*
156 * parameters for (*nm_lock)(adapter, what, index)
157 */
158enum {
159 NETMAP_NO_LOCK = 0,
160 NETMAP_CORE_LOCK, NETMAP_CORE_UNLOCK,
161 NETMAP_TX_LOCK, NETMAP_TX_UNLOCK,
162 NETMAP_RX_LOCK, NETMAP_RX_UNLOCK,
163#ifdef __FreeBSD__
164#define NETMAP_REG_LOCK NETMAP_CORE_LOCK
165#define NETMAP_REG_UNLOCK NETMAP_CORE_UNLOCK
166#else
167 NETMAP_REG_LOCK, NETMAP_REG_UNLOCK
168#endif
147};
148
149/*
150 * The following are support routines used by individual drivers to
151 * support netmap operation.
152 *
153 * netmap_attach() initializes a struct netmap_adapter, allocating the
154 * struct netmap_ring's and the struct selinfo.

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

246{
247 uint32_t i = slot->buf_idx;
248 void *ret = (i >= netmap_total_buffers) ? netmap_buffer_base :
249 netmap_buffer_base + (i *NETMAP_BUF_SIZE);
250 *pp = vtophys(ret);
251 return ret;
252}
253
169};
170
171/*
172 * The following are support routines used by individual drivers to
173 * support netmap operation.
174 *
175 * netmap_attach() initializes a struct netmap_adapter, allocating the
176 * struct netmap_ring's and the struct selinfo.

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

268{
269 uint32_t i = slot->buf_idx;
270 void *ret = (i >= netmap_total_buffers) ? netmap_buffer_base :
271 netmap_buffer_base + (i *NETMAP_BUF_SIZE);
272 *pp = vtophys(ret);
273 return ret;
274}
275
276/* default functions to handle rx/tx interrupts */
277int netmap_rx_irq(struct ifnet *, int, int *);
278#define netmap_tx_irq(_n, _q) netmap_rx_irq(_n, _q, NULL)
279#ifdef __linux__
280#define bus_dmamap_sync(_a, _b, _c) // wmb() or rmb() ?
281netdev_tx_t netmap_start_linux(struct sk_buff *skb, struct net_device *dev);
282#endif
254#endif /* _NET_NETMAP_KERN_H_ */
283#endif /* _NET_NETMAP_KERN_H_ */