xref: /f-stack/dpdk/drivers/net/ark/ark_global.h (revision 031be553)
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright (c) 2015-2017 Atomic Rules LLC
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 copyright holder 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 _ARK_GLOBAL_H_
35 #define _ARK_GLOBAL_H_
36 
37 #include <time.h>
38 #include <assert.h>
39 
40 #include <rte_mbuf.h>
41 #include <rte_ethdev.h>
42 #include <rte_malloc.h>
43 #include <rte_memcpy.h>
44 #include <rte_string_fns.h>
45 #include <rte_cycles.h>
46 #include <rte_kvargs.h>
47 #include <rte_dev.h>
48 #include <rte_version.h>
49 
50 #include "ark_pktdir.h"
51 #include "ark_pktgen.h"
52 #include "ark_pktchkr.h"
53 
54 #define ETH_ARK_ARG_MAXLEN	64
55 #define ARK_SYSCTRL_BASE  0x0
56 #define ARK_PKTGEN_BASE   0x10000
57 #define ARK_MPU_RX_BASE   0x20000
58 #define ARK_UDM_BASE      0x30000
59 #define ARK_MPU_TX_BASE   0x40000
60 #define ARK_DDM_BASE      0x60000
61 #define ARK_CMAC_BASE     0x80000
62 #define ARK_PKTDIR_BASE   0xa0000
63 #define ARK_PKTCHKR_BASE  0x90000
64 #define ARK_RCPACING_BASE 0xb0000
65 #define ARK_EXTERNAL_BASE 0x100000
66 #define ARK_MPU_QOFFSET   0x00100
67 #define ARK_MAX_PORTS     RTE_MAX_ETHPORTS
68 
69 #define offset8(n)     n
70 #define offset16(n)   ((n) / 2)
71 #define offset32(n)   ((n) / 4)
72 #define offset64(n)   ((n) / 8)
73 
74 /* Maximum length of arg list in bytes */
75 #define ARK_MAX_ARG_LEN 256
76 
77 /*
78  * Structure to store private data for each PF/VF instance.
79  */
80 #define def_ptr(type, name) \
81 	union type {		   \
82 		uint64_t *t64;	   \
83 		uint32_t *t32;	   \
84 		uint16_t *t16;	   \
85 		uint8_t  *t8;	   \
86 		void     *v;	   \
87 	} name
88 
89 struct ark_user_ext {
90 	void *(*dev_init)(struct rte_eth_dev *, void *abar, int port_id);
91 	void (*dev_uninit)(struct rte_eth_dev *, void *);
92 	int (*dev_get_port_count)(struct rte_eth_dev *, void *);
93 	int (*dev_configure)(struct rte_eth_dev *, void *);
94 	int (*dev_start)(struct rte_eth_dev *, void *);
95 	void (*dev_stop)(struct rte_eth_dev *, void *);
96 	void (*dev_close)(struct rte_eth_dev *, void *);
97 	int (*link_update)(struct rte_eth_dev *, int wait_to_complete, void *);
98 	int (*dev_set_link_up)(struct rte_eth_dev *, void *);
99 	int (*dev_set_link_down)(struct rte_eth_dev *, void *);
100 	int (*stats_get)(struct rte_eth_dev *, struct rte_eth_stats *, void *);
101 	void (*stats_reset)(struct rte_eth_dev *, void *);
102 	void (*mac_addr_add)(struct rte_eth_dev *,
103 						  struct ether_addr *,
104 						 uint32_t,
105 						 uint32_t,
106 						 void *);
107 	void (*mac_addr_remove)(struct rte_eth_dev *, uint32_t, void *);
108 	void (*mac_addr_set)(struct rte_eth_dev *, struct ether_addr *, void *);
109 	int (*set_mtu)(struct rte_eth_dev *, uint16_t, void *);
110 };
111 
112 struct ark_adapter {
113 	/* User extension private data */
114 	void *user_data[ARK_MAX_PORTS];
115 
116 	/* Pointers to packet generator and checker */
117 	int start_pg;
118 	ark_pkt_gen_t pg;
119 	ark_pkt_chkr_t pc;
120 	ark_pkt_dir_t pd;
121 
122 	int num_ports;
123 
124 	/* Packet generator/checker args */
125 	char pkt_gen_args[ARK_MAX_ARG_LEN];
126 	char pkt_chkr_args[ARK_MAX_ARG_LEN];
127 	uint32_t pkt_dir_v;
128 
129 	/* eth device */
130 	struct rte_eth_dev *eth_dev;
131 
132 	void *d_handle;
133 	struct ark_user_ext user_ext;
134 
135 	/* Our Bar 0 */
136 	uint8_t *bar0;
137 
138 	/* Application Bar */
139 	uint8_t *a_bar;
140 
141 	/* Arkville demo block offsets */
142 	def_ptr(sys_ctrl, sysctrl);
143 	def_ptr(pkt_gen, pktgen);
144 	def_ptr(mpu_rx, mpurx);
145 	def_ptr(UDM, udm);
146 	def_ptr(mpu_tx, mputx);
147 	def_ptr(DDM, ddm);
148 	def_ptr(CMAC, cmac);
149 	def_ptr(external, external);
150 	def_ptr(pkt_dir, pktdir);
151 	def_ptr(pkt_chkr, pktchkr);
152 
153 	int started;
154 	uint16_t rx_queues;
155 	uint16_t tx_queues;
156 
157 	struct ark_rqpace_t *rqpacing;
158 };
159 
160 typedef uint32_t *ark_t;
161 
162 #endif
163