remove trailing whitespaces
[dpdk.git] / examples / l2fwd-ivshmem / include / common.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _IVSHMEM_COMMON_H_
35 #define _IVSHMEM_COMMON_H_
36
37 #define RTE_LOGTYPE_L2FWD_IVSHMEM RTE_LOGTYPE_USER1
38
39 #define CTRL_MZ_NAME "CTRL_MEMZONE"
40 #define MBUF_MP_NAME "MBUF_MEMPOOL"
41 #define RX_RING_PREFIX "RX_"
42 #define TX_RING_PREFIX "TX_"
43
44 /* A tsc-based timer responsible for triggering statistics printout */
45 #define TIMER_MILLISECOND 2000000ULL /* around 1ms at 2 Ghz */
46 #define MAX_TIMER_PERIOD 86400 /* 1 day max */
47 static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000; /* default period is 10 seconds */
48
49 #define DIM(x)\
50         (sizeof(x)/sizeof(x)[0])
51
52 #define MAX_PKT_BURST 32
53
54 const struct rte_memzone * ctrl_mz;
55
56 enum l2fwd_state {
57         STATE_NONE = 0,
58         STATE_FWD,
59         STATE_EXIT,
60         STATE_FAIL
61 };
62
63 /* Per-port statistics struct */
64 struct port_statistics {
65         uint64_t tx;
66         uint64_t rx;
67         uint64_t dropped;
68 } __rte_cache_aligned;
69
70 struct mbuf_table {
71         unsigned len;
72         struct rte_mbuf *m_table[MAX_PKT_BURST * 2]; /**< allow up to two bursts */
73 };
74
75 struct vm_port_param {
76         struct rte_ring * rx_ring;         /**< receiving ring for current port */
77         struct rte_ring * tx_ring;         /**< transmitting ring for current port */
78         struct vm_port_param * dst;        /**< current port's destination port */
79         volatile struct port_statistics stats;      /**< statistics for current port */
80         struct ether_addr ethaddr;         /**< Ethernet address of the port */
81 };
82
83 /* control structure, to synchronize host and VM */
84 struct ivshmem_ctrl {
85         rte_spinlock_t lock;
86         uint8_t nb_ports;                /**< total nr of ports */
87         volatile enum l2fwd_state state; /**< report state */
88         struct vm_port_param vm_ports[RTE_MAX_ETHPORTS];
89 };
90
91 struct ivshmem_ctrl * ctrl;
92
93 static unsigned int l2fwd_ivshmem_rx_queue_per_lcore = 1;
94
95 static void sighandler(int __rte_unused s)
96 {
97         ctrl->state = STATE_EXIT;
98 }
99
100 static void sigsetup(void)
101 {
102            struct sigaction sigIntHandler;
103
104            sigIntHandler.sa_handler = sighandler;
105            sigemptyset(&sigIntHandler.sa_mask);
106            sigIntHandler.sa_flags = 0;
107
108            sigaction(SIGINT, &sigIntHandler, NULL);
109 }
110
111 #endif /* _IVSHMEM_COMMON_H_ */