Commit | Line | Data |
---|---|---|
8cdc3f6c TI |
1 | /* |
2 | * FUJITSU Extended Socket Network Device driver | |
3 | * Copyright (c) 2015 FUJITSU LIMITED | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms and conditions of the GNU General Public License, | |
7 | * version 2, as published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along with | |
15 | * this program; if not, see <http://www.gnu.org/licenses/>. | |
16 | * | |
17 | * The full GNU General Public License is included in this distribution in | |
18 | * the file called "COPYING". | |
19 | * | |
20 | */ | |
21 | ||
22 | #ifndef FJES_HW_H_ | |
23 | #define FJES_HW_H_ | |
24 | ||
25 | #include <linux/netdevice.h> | |
26 | #include <linux/if_vlan.h> | |
27 | #include <linux/vmalloc.h> | |
28 | ||
29 | #include "fjes_regs.h" | |
30 | ||
31 | struct fjes_hw; | |
32 | ||
33 | #define EP_BUFFER_SUPPORT_VLAN_MAX 4 | |
34 | #define EP_BUFFER_INFO_SIZE 4096 | |
35 | ||
36 | #define FJES_DEVICE_RESET_TIMEOUT ((17 + 1) * 3) /* sec */ | |
37 | ||
38 | #define EP_BUFFER_SIZE \ | |
39 | (((sizeof(union ep_buffer_info) + (128 * (64 * 1024))) \ | |
40 | / EP_BUFFER_INFO_SIZE) * EP_BUFFER_INFO_SIZE) | |
41 | ||
42 | #define EP_RING_NUM(buffer_size, frame_size) \ | |
43 | (u32)((buffer_size) / (frame_size)) | |
44 | ||
45 | #define FJES_MTU_TO_BUFFER_SIZE(mtu) \ | |
46 | (ETH_HLEN + VLAN_HLEN + (mtu) + ETH_FCS_LEN) | |
47 | #define FJES_MTU_TO_FRAME_SIZE(mtu) \ | |
48 | (sizeof(struct esmem_frame) + FJES_MTU_TO_BUFFER_SIZE(mtu)) | |
49 | #define FJES_MTU_DEFINE(size) \ | |
50 | ((size) - sizeof(struct esmem_frame) - \ | |
51 | (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)) | |
52 | ||
53 | #define FJES_DEV_COMMAND_INFO_RES_LEN(epnum) (8 + 2 * (epnum)) | |
54 | #define FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(txb, rxb) \ | |
55 | (24 + (8 * ((txb) / EP_BUFFER_INFO_SIZE + (rxb) / EP_BUFFER_INFO_SIZE))) | |
56 | ||
57 | #define FJES_DEV_REQ_BUF_SIZE(maxep) \ | |
58 | FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(EP_BUFFER_SIZE, EP_BUFFER_SIZE) | |
59 | #define FJES_DEV_RES_BUF_SIZE(maxep) \ | |
60 | FJES_DEV_COMMAND_INFO_RES_LEN(maxep) | |
61 | ||
62 | /* Frame & MTU */ | |
63 | struct esmem_frame { | |
64 | __le32 frame_size; | |
65 | u8 frame_data[]; | |
66 | }; | |
67 | ||
68 | /* shared status region */ | |
69 | struct fjes_device_shared_info { | |
70 | int epnum; | |
71 | u8 ep_status[]; | |
72 | }; | |
73 | ||
74 | /* structures for command control request data*/ | |
75 | union fjes_device_command_req { | |
76 | struct { | |
77 | __le32 length; | |
78 | } info; | |
79 | struct { | |
80 | __le32 length; | |
81 | __le32 epid; | |
82 | __le64 buffer[]; | |
83 | } share_buffer; | |
84 | struct { | |
85 | __le32 length; | |
86 | __le32 epid; | |
87 | } unshare_buffer; | |
88 | struct { | |
89 | __le32 length; | |
90 | __le32 mode; | |
91 | __le64 buffer_len; | |
92 | __le64 buffer[]; | |
93 | } start_trace; | |
94 | struct { | |
95 | __le32 length; | |
96 | } stop_trace; | |
97 | }; | |
98 | ||
99 | /* structures for command control response data */ | |
100 | union fjes_device_command_res { | |
101 | struct { | |
102 | __le32 length; | |
103 | __le32 code; | |
104 | struct { | |
105 | u8 es_status; | |
106 | u8 zone; | |
107 | } info[]; | |
108 | } info; | |
109 | struct { | |
110 | __le32 length; | |
111 | __le32 code; | |
112 | } share_buffer; | |
113 | struct { | |
114 | __le32 length; | |
115 | __le32 code; | |
116 | } unshare_buffer; | |
117 | struct { | |
118 | __le32 length; | |
119 | __le32 code; | |
120 | } start_trace; | |
121 | struct { | |
122 | __le32 length; | |
123 | __le32 code; | |
124 | } stop_trace; | |
125 | }; | |
126 | ||
127 | /* parameter for command control */ | |
128 | struct fjes_device_command_param { | |
129 | u32 req_len; | |
130 | phys_addr_t req_start; | |
131 | u32 res_len; | |
132 | phys_addr_t res_start; | |
133 | phys_addr_t share_start; | |
134 | }; | |
135 | ||
136 | /* EP buffer information */ | |
137 | union ep_buffer_info { | |
138 | u8 raw[EP_BUFFER_INFO_SIZE]; | |
139 | ||
140 | struct _ep_buffer_info_common_t { | |
141 | u32 version; | |
142 | } common; | |
143 | ||
144 | struct _ep_buffer_info_v1_t { | |
145 | u32 version; | |
146 | u32 info_size; | |
147 | ||
148 | u32 buffer_size; | |
149 | u16 count_max; | |
150 | ||
151 | u16 _rsv_1; | |
152 | ||
153 | u32 frame_max; | |
154 | u8 mac_addr[ETH_ALEN]; | |
155 | ||
156 | u16 _rsv_2; | |
157 | u32 _rsv_3; | |
158 | ||
159 | u16 tx_status; | |
160 | u16 rx_status; | |
161 | ||
162 | u32 head; | |
163 | u32 tail; | |
164 | ||
165 | u16 vlan_id[EP_BUFFER_SUPPORT_VLAN_MAX]; | |
166 | ||
167 | } v1i; | |
168 | ||
169 | }; | |
170 | ||
171 | /* buffer pair for Extended Partition */ | |
172 | struct ep_share_mem_info { | |
173 | struct epbuf_handler { | |
174 | void *buffer; | |
175 | size_t size; | |
176 | union ep_buffer_info *info; | |
177 | u8 *ring; | |
178 | } tx, rx; | |
179 | ||
180 | struct rtnl_link_stats64 net_stats; | |
181 | ||
182 | u16 tx_status_work; | |
183 | ||
184 | u8 es_status; | |
185 | u8 zone; | |
186 | }; | |
187 | ||
188 | struct es_device_trace { | |
189 | u32 record_num; | |
190 | u32 current_record; | |
191 | u32 status_flag; | |
192 | u32 _rsv; | |
193 | ||
194 | struct { | |
195 | u16 epid; | |
196 | u16 dir_offset; | |
197 | u32 data; | |
198 | u64 tsc; | |
199 | } record[]; | |
200 | }; | |
201 | ||
202 | struct fjes_hw_info { | |
203 | struct fjes_device_shared_info *share; | |
204 | union fjes_device_command_req *req_buf; | |
205 | u64 req_buf_size; | |
206 | union fjes_device_command_res *res_buf; | |
207 | u64 res_buf_size; | |
208 | ||
209 | int *my_epid; | |
210 | int *max_epid; | |
211 | ||
212 | struct es_device_trace *trace; | |
213 | u64 trace_size; | |
214 | ||
215 | struct mutex lock; /* buffer lock*/ | |
216 | ||
217 | unsigned long buffer_share_bit; | |
218 | unsigned long buffer_unshare_reserve_bit; | |
219 | }; | |
220 | ||
221 | struct fjes_hw { | |
222 | void *back; | |
223 | ||
224 | unsigned long txrx_stop_req_bit; | |
225 | unsigned long epstop_req_bit; | |
226 | ||
227 | int my_epid; | |
228 | int max_epid; | |
229 | ||
230 | struct ep_share_mem_info *ep_shm_info; | |
231 | ||
232 | struct fjes_hw_resource { | |
233 | u64 start; | |
234 | u64 size; | |
235 | int irq; | |
236 | } hw_res; | |
237 | ||
238 | u8 *base; | |
239 | ||
240 | struct fjes_hw_info hw_info; | |
241 | }; | |
242 | ||
243 | int fjes_hw_init(struct fjes_hw *); | |
a18aaec2 | 244 | void fjes_hw_exit(struct fjes_hw *); |
8cdc3f6c TI |
245 | int fjes_hw_reset(struct fjes_hw *); |
246 | ||
247 | void fjes_hw_init_command_registers(struct fjes_hw *, | |
248 | struct fjes_device_command_param *); | |
249 | void fjes_hw_setup_epbuf(struct epbuf_handler *, u8 *, u32); | |
250 | void fjes_hw_set_irqmask(struct fjes_hw *, enum REG_ICTL_MASK, bool); | |
251 | ||
252 | #endif /* FJES_HW_H_ */ |