diff options
| author | Luigi Rizzo <luigi@FreeBSD.org> | 2012-02-27 19:05:01 +0000 |
|---|---|---|
| committer | Luigi Rizzo <luigi@FreeBSD.org> | 2012-02-27 19:05:01 +0000 |
| commit | 64ae02c36579bad7d5e682589a0bc1023e359f9d (patch) | |
| tree | a547096f4399bc66370c43d717a40e4b79eb8401 /sys/dev/netmap/netmap_kern.h | |
| parent | d7ccbd70099774d72fd45fa7a0b942c360dd9878 (diff) | |
Notes
Diffstat (limited to 'sys/dev/netmap/netmap_kern.h')
| -rw-r--r-- | sys/dev/netmap/netmap_kern.h | 77 |
1 files changed, 34 insertions, 43 deletions
diff --git a/sys/dev/netmap/netmap_kern.h b/sys/dev/netmap/netmap_kern.h index 6e03570477734..7660d14fb0a96 100644 --- a/sys/dev/netmap/netmap_kern.h +++ b/sys/dev/netmap/netmap_kern.h @@ -25,7 +25,7 @@ /* * $FreeBSD$ - * $Id: netmap_kern.h 9795 2011-12-02 11:39:08Z luigi $ + * $Id: netmap_kern.h 10602 2012-02-21 16:47:55Z luigi $ * * The header contains the definitions of constants and function * prototypes used only in kernelspace. @@ -39,7 +39,7 @@ #define NM_SELINFO_T struct selinfo #define MBUF_LEN(m) ((m)->m_pkthdr.len) #define NM_SEND_UP(ifp, m) ((ifp)->if_input)(ifp, m) -#elif defined (__linux__) +#elif defined (linux) #define NM_LOCK_T spinlock_t #define NM_SELINFO_T wait_queue_head_t #define MBUF_LEN(m) ((m)->len) @@ -65,7 +65,14 @@ MALLOC_DECLARE(M_NETMAP); struct netmap_adapter; /* - * private, kernel view of a ring. + * private, kernel view of a ring. Keeps track of the status of + * a ring across system calls. + * + * nr_hwcur index of the next buffer to refill. + * It corresponds to ring->cur - ring->reserved + * + * nr_hwavail the number of slots "owned" by userspace. + * nr_hwavail =:= ring->avail + ring->reserved * * The indexes in the NIC and netmap rings are offset by nkr_hwofs slots. * This is so that, on a reset, buffers owned by userspace are not @@ -101,13 +108,14 @@ struct netmap_adapter { int separate_locks; /* set if the interface suports different locks for rx, tx and core. */ - u_int num_queues; /* number of tx/rx queue pairs: this is + u_int num_rx_queues; /* number of tx/rx queue pairs: this is a duplicate field needed to simplify the signature of ``netmap_detach``. */ + u_int num_tx_queues; // if nonzero, overrides num_queues XXX u_int num_tx_desc; /* number of descriptor in each queue */ u_int num_rx_desc; - u_int buff_size; + u_int buff_size; // XXX deprecate, use NETMAP_BUF_SIZE //u_int flags; // XXX unused /* tx_rings and rx_rings are private but allocated @@ -117,6 +125,8 @@ struct netmap_adapter { struct netmap_kring *tx_rings; /* array of TX rings. */ struct netmap_kring *rx_rings; /* array of RX rings. */ + NM_SELINFO_T tx_si, rx_si; /* global wait queues */ + /* copy of if_qflush and if_transmit pointers, to intercept * packets from the network stack when netmap is active. * XXX probably if_qflush is not necessary. @@ -135,6 +145,9 @@ struct netmap_adapter { void (*nm_lock)(struct ifnet *, int what, u_int ringid); int (*nm_txsync)(struct ifnet *, u_int ring, int lock); int (*nm_rxsync)(struct ifnet *, u_int ring, int lock); +#ifdef linux + struct net_device_ops nm_ndo; +#endif /* linux */ }; /* @@ -254,55 +267,33 @@ netmap_reload_map(bus_dma_tag_t tag, bus_dmamap_t map, void *buf) * functions to map NIC to KRING indexes (n2k) and vice versa (k2n) */ static inline int -netmap_ridx_n2k(struct netmap_adapter *na, int ring, int nic_idx) +netmap_idx_n2k(struct netmap_kring *kr, int idx) { - int kring_idx = nic_idx + na->rx_rings[ring].nkr_hwofs; - if (kring_idx < 0) - return kring_idx + na->num_rx_desc; - else if (kring_idx < na->num_rx_desc) - return kring_idx; + int n = kr->nkr_num_slots; + idx += kr->nkr_hwofs; + if (idx < 0) + return idx + n; + else if (idx < n) + return idx; else - return kring_idx - na->num_rx_desc; -} - -static inline int -netmap_tidx_n2k(struct netmap_adapter *na, int ring, int nic_idx) -{ - int kring_idx = nic_idx + na->tx_rings[ring].nkr_hwofs; - if (kring_idx < 0) - return kring_idx + na->num_tx_desc; - else if (kring_idx < na->num_tx_desc) - return kring_idx; - else - return kring_idx - na->num_tx_desc; + return idx - n; } static inline int -netmap_ridx_k2n(struct netmap_adapter *na, int ring, int kring_idx) +netmap_idx_k2n(struct netmap_kring *kr, int idx) { - int nic_idx = kring_idx - na->rx_rings[ring].nkr_hwofs; - if (nic_idx < 0) - return nic_idx + na->num_rx_desc; - else if (nic_idx < na->num_rx_desc) - return nic_idx; + int n = kr->nkr_num_slots; + idx -= kr->nkr_hwofs; + if (idx < 0) + return idx + n; + else if (idx < n) + return idx; else - return nic_idx - na->num_rx_desc; + return idx - n; } -static inline int -netmap_tidx_k2n(struct netmap_adapter *na, int ring, int kring_idx) -{ - int nic_idx = kring_idx - na->tx_rings[ring].nkr_hwofs; - if (nic_idx < 0) - return nic_idx + na->num_tx_desc; - else if (nic_idx < na->num_tx_desc) - return nic_idx; - else - return nic_idx - na->num_tx_desc; -} - /* * NMB return the virtual address of a buffer (buffer 0 on bad index) * PNMB also fills the physical address |
