blob: 95e632b363c1a60b7438e1623fba080f14df7bd4 [file] [log] [blame]
Taku Izumi8cdc3f62015-08-21 17:29:18 +09001/*
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
31struct 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 */
Taku Izumi3bb025d2015-08-21 17:29:21 +090037#define FJES_COMMAND_REQ_TIMEOUT (5 + 1) /* sec */
Taku Izumi7950e6c2015-08-21 17:29:22 +090038#define FJES_COMMAND_REQ_BUFF_TIMEOUT (8 * 3) /* sec */
Taku Izumie5d486d2015-08-21 17:29:23 +090039#define FJES_COMMAND_EPSTOP_WAIT_TIMEOUT (1) /* sec */
Taku Izumi3bb025d2015-08-21 17:29:21 +090040
41#define FJES_CMD_REQ_ERR_INFO_PARAM (0x0001)
42#define FJES_CMD_REQ_ERR_INFO_STATUS (0x0002)
43
44#define FJES_CMD_REQ_RES_CODE_NORMAL (0)
Taku Izumi7950e6c2015-08-21 17:29:22 +090045#define FJES_CMD_REQ_RES_CODE_BUSY (1)
Taku Izumi8cdc3f62015-08-21 17:29:18 +090046
Taku Izumie5d486d2015-08-21 17:29:23 +090047#define FJES_ZONING_STATUS_DISABLE (0x00)
48#define FJES_ZONING_STATUS_ENABLE (0x01)
49#define FJES_ZONING_STATUS_INVALID (0xFF)
50
51#define FJES_ZONING_ZONE_TYPE_NONE (0xFF)
52
Taku Izumi9acf51c2015-08-21 17:29:24 +090053#define FJES_TX_DELAY_SEND_NONE (0)
54#define FJES_TX_DELAY_SEND_PENDING (1)
55
Taku Izumie5d486d2015-08-21 17:29:23 +090056#define FJES_RX_STOP_REQ_NONE (0x0)
57#define FJES_RX_STOP_REQ_DONE (0x1)
58#define FJES_RX_STOP_REQ_REQUEST (0x2)
59#define FJES_RX_POLL_WORK (0x4)
60
Taku Izumi8cdc3f62015-08-21 17:29:18 +090061#define EP_BUFFER_SIZE \
62 (((sizeof(union ep_buffer_info) + (128 * (64 * 1024))) \
63 / EP_BUFFER_INFO_SIZE) * EP_BUFFER_INFO_SIZE)
64
65#define EP_RING_NUM(buffer_size, frame_size) \
66 (u32)((buffer_size) / (frame_size))
Taku Izumi9acf51c2015-08-21 17:29:24 +090067#define EP_RING_INDEX(_num, _max) (((_num) + (_max)) % (_max))
68#define EP_RING_INDEX_INC(_num, _max) \
69 ((_num) = EP_RING_INDEX((_num) + 1, (_max)))
70#define EP_RING_FULL(_head, _tail, _max) \
71 (0 == EP_RING_INDEX(((_tail) - (_head)), (_max)))
Taku Izumi26585932015-08-21 17:29:27 +090072#define EP_RING_EMPTY(_head, _tail, _max) \
73 (1 == EP_RING_INDEX(((_tail) - (_head)), (_max)))
Taku Izumi8cdc3f62015-08-21 17:29:18 +090074
75#define FJES_MTU_TO_BUFFER_SIZE(mtu) \
76 (ETH_HLEN + VLAN_HLEN + (mtu) + ETH_FCS_LEN)
77#define FJES_MTU_TO_FRAME_SIZE(mtu) \
78 (sizeof(struct esmem_frame) + FJES_MTU_TO_BUFFER_SIZE(mtu))
79#define FJES_MTU_DEFINE(size) \
80 ((size) - sizeof(struct esmem_frame) - \
81 (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
82
Taku Izumi3bb025d2015-08-21 17:29:21 +090083#define FJES_DEV_COMMAND_INFO_REQ_LEN (4)
Taku Izumi8cdc3f62015-08-21 17:29:18 +090084#define FJES_DEV_COMMAND_INFO_RES_LEN(epnum) (8 + 2 * (epnum))
85#define FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(txb, rxb) \
86 (24 + (8 * ((txb) / EP_BUFFER_INFO_SIZE + (rxb) / EP_BUFFER_INFO_SIZE)))
Taku Izumi7950e6c2015-08-21 17:29:22 +090087#define FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN (8)
88#define FJES_DEV_COMMAND_UNSHARE_BUFFER_REQ_LEN (8)
89#define FJES_DEV_COMMAND_UNSHARE_BUFFER_RES_LEN (8)
Taku Izumi8cdc3f62015-08-21 17:29:18 +090090
91#define FJES_DEV_REQ_BUF_SIZE(maxep) \
92 FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(EP_BUFFER_SIZE, EP_BUFFER_SIZE)
93#define FJES_DEV_RES_BUF_SIZE(maxep) \
94 FJES_DEV_COMMAND_INFO_RES_LEN(maxep)
95
96/* Frame & MTU */
97struct esmem_frame {
98 __le32 frame_size;
99 u8 frame_data[];
100};
101
Taku Izumie5d486d2015-08-21 17:29:23 +0900102/* EP partner status */
103enum ep_partner_status {
104 EP_PARTNER_UNSHARE,
105 EP_PARTNER_SHARED,
106 EP_PARTNER_WAITING,
107 EP_PARTNER_COMPLETE,
108 EP_PARTNER_STATUS_MAX,
109};
110
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900111/* shared status region */
112struct fjes_device_shared_info {
113 int epnum;
114 u8 ep_status[];
115};
116
117/* structures for command control request data*/
118union fjes_device_command_req {
119 struct {
120 __le32 length;
121 } info;
122 struct {
123 __le32 length;
124 __le32 epid;
125 __le64 buffer[];
126 } share_buffer;
127 struct {
128 __le32 length;
129 __le32 epid;
130 } unshare_buffer;
131 struct {
132 __le32 length;
133 __le32 mode;
134 __le64 buffer_len;
135 __le64 buffer[];
136 } start_trace;
137 struct {
138 __le32 length;
139 } stop_trace;
140};
141
142/* structures for command control response data */
143union fjes_device_command_res {
144 struct {
145 __le32 length;
146 __le32 code;
147 struct {
148 u8 es_status;
149 u8 zone;
150 } info[];
151 } info;
152 struct {
153 __le32 length;
154 __le32 code;
155 } share_buffer;
156 struct {
157 __le32 length;
158 __le32 code;
159 } unshare_buffer;
160 struct {
161 __le32 length;
162 __le32 code;
163 } start_trace;
164 struct {
165 __le32 length;
166 __le32 code;
167 } stop_trace;
168};
169
Taku Izumi3bb025d2015-08-21 17:29:21 +0900170/* request command type */
171enum fjes_dev_command_request_type {
172 FJES_CMD_REQ_INFO = 0x0001,
173 FJES_CMD_REQ_SHARE_BUFFER = 0x0002,
174 FJES_CMD_REQ_UNSHARE_BUFFER = 0x0004,
175};
176
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900177/* parameter for command control */
178struct fjes_device_command_param {
179 u32 req_len;
180 phys_addr_t req_start;
181 u32 res_len;
182 phys_addr_t res_start;
183 phys_addr_t share_start;
184};
185
Taku Izumi3bb025d2015-08-21 17:29:21 +0900186/* error code for command control */
187enum fjes_dev_command_response_e {
188 FJES_CMD_STATUS_UNKNOWN,
189 FJES_CMD_STATUS_NORMAL,
190 FJES_CMD_STATUS_TIMEOUT,
191 FJES_CMD_STATUS_ERROR_PARAM,
192 FJES_CMD_STATUS_ERROR_STATUS,
193};
194
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900195/* EP buffer information */
196union ep_buffer_info {
197 u8 raw[EP_BUFFER_INFO_SIZE];
198
199 struct _ep_buffer_info_common_t {
200 u32 version;
201 } common;
202
203 struct _ep_buffer_info_v1_t {
204 u32 version;
205 u32 info_size;
206
207 u32 buffer_size;
208 u16 count_max;
209
210 u16 _rsv_1;
211
212 u32 frame_max;
213 u8 mac_addr[ETH_ALEN];
214
215 u16 _rsv_2;
216 u32 _rsv_3;
217
218 u16 tx_status;
219 u16 rx_status;
220
221 u32 head;
222 u32 tail;
223
224 u16 vlan_id[EP_BUFFER_SUPPORT_VLAN_MAX];
225
226 } v1i;
227
228};
229
230/* buffer pair for Extended Partition */
231struct ep_share_mem_info {
232 struct epbuf_handler {
233 void *buffer;
234 size_t size;
235 union ep_buffer_info *info;
236 u8 *ring;
237 } tx, rx;
238
239 struct rtnl_link_stats64 net_stats;
240
241 u16 tx_status_work;
242
243 u8 es_status;
244 u8 zone;
245};
246
247struct es_device_trace {
248 u32 record_num;
249 u32 current_record;
250 u32 status_flag;
251 u32 _rsv;
252
253 struct {
254 u16 epid;
255 u16 dir_offset;
256 u32 data;
257 u64 tsc;
258 } record[];
259};
260
261struct fjes_hw_info {
262 struct fjes_device_shared_info *share;
263 union fjes_device_command_req *req_buf;
264 u64 req_buf_size;
265 union fjes_device_command_res *res_buf;
266 u64 res_buf_size;
267
268 int *my_epid;
269 int *max_epid;
270
271 struct es_device_trace *trace;
272 u64 trace_size;
273
274 struct mutex lock; /* buffer lock*/
275
276 unsigned long buffer_share_bit;
277 unsigned long buffer_unshare_reserve_bit;
278};
279
280struct fjes_hw {
281 void *back;
282
283 unsigned long txrx_stop_req_bit;
284 unsigned long epstop_req_bit;
285
286 int my_epid;
287 int max_epid;
288
289 struct ep_share_mem_info *ep_shm_info;
290
291 struct fjes_hw_resource {
292 u64 start;
293 u64 size;
294 int irq;
295 } hw_res;
296
297 u8 *base;
298
299 struct fjes_hw_info hw_info;
300};
301
302int fjes_hw_init(struct fjes_hw *);
Taku Izumia18aaec2015-08-21 17:29:19 +0900303void fjes_hw_exit(struct fjes_hw *);
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900304int fjes_hw_reset(struct fjes_hw *);
Taku Izumi3bb025d2015-08-21 17:29:21 +0900305int fjes_hw_request_info(struct fjes_hw *);
Taku Izumi7950e6c2015-08-21 17:29:22 +0900306int fjes_hw_register_buff_addr(struct fjes_hw *, int,
307 struct ep_share_mem_info *);
308int fjes_hw_unregister_buff_addr(struct fjes_hw *, int);
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900309void fjes_hw_init_command_registers(struct fjes_hw *,
310 struct fjes_device_command_param *);
311void fjes_hw_setup_epbuf(struct epbuf_handler *, u8 *, u32);
Taku Izumie5d486d2015-08-21 17:29:23 +0900312int fjes_hw_raise_interrupt(struct fjes_hw *, int, enum REG_ICTL_MASK);
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900313void fjes_hw_set_irqmask(struct fjes_hw *, enum REG_ICTL_MASK, bool);
Taku Izumie5d486d2015-08-21 17:29:23 +0900314u32 fjes_hw_capture_interrupt_status(struct fjes_hw *);
315void fjes_hw_raise_epstop(struct fjes_hw *);
316int fjes_hw_wait_epstop(struct fjes_hw *);
317enum ep_partner_status
318 fjes_hw_get_partner_ep_status(struct fjes_hw *, int);
319
320bool fjes_hw_epid_is_same_zone(struct fjes_hw *, int);
321int fjes_hw_epid_is_shared(struct fjes_device_shared_info *, int);
Taku Izumi9acf51c2015-08-21 17:29:24 +0900322bool fjes_hw_check_epbuf_version(struct epbuf_handler *, u32);
323bool fjes_hw_check_mtu(struct epbuf_handler *, u32);
324bool fjes_hw_check_vlan_id(struct epbuf_handler *, u16);
Taku Izumi3e3fedd2015-08-21 17:29:31 +0900325bool fjes_hw_set_vlan_id(struct epbuf_handler *, u16);
326void fjes_hw_del_vlan_id(struct epbuf_handler *, u16);
Taku Izumi26585932015-08-21 17:29:27 +0900327bool fjes_hw_epbuf_rx_is_empty(struct epbuf_handler *);
328void *fjes_hw_epbuf_rx_curpkt_get_addr(struct epbuf_handler *, size_t *);
329void fjes_hw_epbuf_rx_curpkt_drop(struct epbuf_handler *);
Taku Izumi9acf51c2015-08-21 17:29:24 +0900330int fjes_hw_epbuf_tx_pkt_send(struct epbuf_handler *, void *, size_t);
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900331
332#endif /* FJES_HW_H_ */