blob: 1445ac99d6e316da52f3534b67be34f53f0e30d7 [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
Taku Izumida5a2382016-04-15 11:25:21 +090036#define FJES_DEVICE_RESET_TIMEOUT ((17 + 1) * 3 * 8) /* sec */
37#define FJES_COMMAND_REQ_TIMEOUT ((5 + 1) * 3 * 8) /* sec */
38#define FJES_COMMAND_REQ_BUFF_TIMEOUT (60 * 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)
Taku Izumi16bbec32016-04-15 11:25:40 +090060#define FJES_RX_MTU_CHANGING_DONE (0x8)
Taku Izumie5d486d2015-08-21 17:29:23 +090061
Taku Izumi8cdc3f62015-08-21 17:29:18 +090062#define EP_BUFFER_SIZE \
63 (((sizeof(union ep_buffer_info) + (128 * (64 * 1024))) \
64 / EP_BUFFER_INFO_SIZE) * EP_BUFFER_INFO_SIZE)
65
66#define EP_RING_NUM(buffer_size, frame_size) \
67 (u32)((buffer_size) / (frame_size))
Taku Izumi9acf51c2015-08-21 17:29:24 +090068#define EP_RING_INDEX(_num, _max) (((_num) + (_max)) % (_max))
69#define EP_RING_INDEX_INC(_num, _max) \
70 ((_num) = EP_RING_INDEX((_num) + 1, (_max)))
71#define EP_RING_FULL(_head, _tail, _max) \
72 (0 == EP_RING_INDEX(((_tail) - (_head)), (_max)))
Taku Izumi26585932015-08-21 17:29:27 +090073#define EP_RING_EMPTY(_head, _tail, _max) \
74 (1 == EP_RING_INDEX(((_tail) - (_head)), (_max)))
Taku Izumi8cdc3f62015-08-21 17:29:18 +090075
76#define FJES_MTU_TO_BUFFER_SIZE(mtu) \
77 (ETH_HLEN + VLAN_HLEN + (mtu) + ETH_FCS_LEN)
78#define FJES_MTU_TO_FRAME_SIZE(mtu) \
79 (sizeof(struct esmem_frame) + FJES_MTU_TO_BUFFER_SIZE(mtu))
80#define FJES_MTU_DEFINE(size) \
81 ((size) - sizeof(struct esmem_frame) - \
82 (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
83
Taku Izumi3bb025d2015-08-21 17:29:21 +090084#define FJES_DEV_COMMAND_INFO_REQ_LEN (4)
Taku Izumi8cdc3f62015-08-21 17:29:18 +090085#define FJES_DEV_COMMAND_INFO_RES_LEN(epnum) (8 + 2 * (epnum))
86#define FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(txb, rxb) \
87 (24 + (8 * ((txb) / EP_BUFFER_INFO_SIZE + (rxb) / EP_BUFFER_INFO_SIZE)))
Taku Izumi7950e6c2015-08-21 17:29:22 +090088#define FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN (8)
89#define FJES_DEV_COMMAND_UNSHARE_BUFFER_REQ_LEN (8)
90#define FJES_DEV_COMMAND_UNSHARE_BUFFER_RES_LEN (8)
Taku Izumi8cdc3f62015-08-21 17:29:18 +090091
92#define FJES_DEV_REQ_BUF_SIZE(maxep) \
93 FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(EP_BUFFER_SIZE, EP_BUFFER_SIZE)
94#define FJES_DEV_RES_BUF_SIZE(maxep) \
95 FJES_DEV_COMMAND_INFO_RES_LEN(maxep)
96
97/* Frame & MTU */
98struct esmem_frame {
99 __le32 frame_size;
100 u8 frame_data[];
101};
102
Taku Izumie5d486d2015-08-21 17:29:23 +0900103/* EP partner status */
104enum ep_partner_status {
105 EP_PARTNER_UNSHARE,
106 EP_PARTNER_SHARED,
107 EP_PARTNER_WAITING,
108 EP_PARTNER_COMPLETE,
109 EP_PARTNER_STATUS_MAX,
110};
111
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900112/* shared status region */
113struct fjes_device_shared_info {
114 int epnum;
115 u8 ep_status[];
116};
117
118/* structures for command control request data*/
119union fjes_device_command_req {
120 struct {
121 __le32 length;
122 } info;
123 struct {
124 __le32 length;
125 __le32 epid;
126 __le64 buffer[];
127 } share_buffer;
128 struct {
129 __le32 length;
130 __le32 epid;
131 } unshare_buffer;
132 struct {
133 __le32 length;
134 __le32 mode;
135 __le64 buffer_len;
136 __le64 buffer[];
137 } start_trace;
138 struct {
139 __le32 length;
140 } stop_trace;
141};
142
143/* structures for command control response data */
144union fjes_device_command_res {
145 struct {
146 __le32 length;
147 __le32 code;
148 struct {
149 u8 es_status;
150 u8 zone;
151 } info[];
152 } info;
153 struct {
154 __le32 length;
155 __le32 code;
156 } share_buffer;
157 struct {
158 __le32 length;
159 __le32 code;
160 } unshare_buffer;
161 struct {
162 __le32 length;
163 __le32 code;
164 } start_trace;
165 struct {
166 __le32 length;
167 __le32 code;
168 } stop_trace;
169};
170
Taku Izumi3bb025d2015-08-21 17:29:21 +0900171/* request command type */
172enum fjes_dev_command_request_type {
173 FJES_CMD_REQ_INFO = 0x0001,
174 FJES_CMD_REQ_SHARE_BUFFER = 0x0002,
175 FJES_CMD_REQ_UNSHARE_BUFFER = 0x0004,
176};
177
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900178/* parameter for command control */
179struct fjes_device_command_param {
180 u32 req_len;
181 phys_addr_t req_start;
182 u32 res_len;
183 phys_addr_t res_start;
184 phys_addr_t share_start;
185};
186
Taku Izumi3bb025d2015-08-21 17:29:21 +0900187/* error code for command control */
188enum fjes_dev_command_response_e {
189 FJES_CMD_STATUS_UNKNOWN,
190 FJES_CMD_STATUS_NORMAL,
191 FJES_CMD_STATUS_TIMEOUT,
192 FJES_CMD_STATUS_ERROR_PARAM,
193 FJES_CMD_STATUS_ERROR_STATUS,
194};
195
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900196/* EP buffer information */
197union ep_buffer_info {
198 u8 raw[EP_BUFFER_INFO_SIZE];
199
200 struct _ep_buffer_info_common_t {
201 u32 version;
202 } common;
203
204 struct _ep_buffer_info_v1_t {
205 u32 version;
206 u32 info_size;
207
208 u32 buffer_size;
209 u16 count_max;
210
211 u16 _rsv_1;
212
213 u32 frame_max;
214 u8 mac_addr[ETH_ALEN];
215
216 u16 _rsv_2;
217 u32 _rsv_3;
218
219 u16 tx_status;
220 u16 rx_status;
221
222 u32 head;
223 u32 tail;
224
225 u16 vlan_id[EP_BUFFER_SUPPORT_VLAN_MAX];
226
227 } v1i;
228
229};
230
231/* buffer pair for Extended Partition */
232struct ep_share_mem_info {
233 struct epbuf_handler {
234 void *buffer;
235 size_t size;
236 union ep_buffer_info *info;
237 u8 *ring;
238 } tx, rx;
239
240 struct rtnl_link_stats64 net_stats;
241
242 u16 tx_status_work;
243
244 u8 es_status;
245 u8 zone;
246};
247
248struct es_device_trace {
249 u32 record_num;
250 u32 current_record;
251 u32 status_flag;
252 u32 _rsv;
253
254 struct {
255 u16 epid;
256 u16 dir_offset;
257 u32 data;
258 u64 tsc;
259 } record[];
260};
261
262struct fjes_hw_info {
263 struct fjes_device_shared_info *share;
264 union fjes_device_command_req *req_buf;
265 u64 req_buf_size;
266 union fjes_device_command_res *res_buf;
267 u64 res_buf_size;
268
269 int *my_epid;
270 int *max_epid;
271
272 struct es_device_trace *trace;
273 u64 trace_size;
274
275 struct mutex lock; /* buffer lock*/
276
277 unsigned long buffer_share_bit;
278 unsigned long buffer_unshare_reserve_bit;
279};
280
281struct fjes_hw {
282 void *back;
283
284 unsigned long txrx_stop_req_bit;
285 unsigned long epstop_req_bit;
Taku Izumi785f28e2015-08-21 17:29:35 +0900286 struct work_struct update_zone_task;
Taku Izumib5a91522015-08-21 17:29:36 +0900287 struct work_struct epstop_task;
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900288
289 int my_epid;
290 int max_epid;
291
292 struct ep_share_mem_info *ep_shm_info;
293
294 struct fjes_hw_resource {
295 u64 start;
296 u64 size;
297 int irq;
298 } hw_res;
299
300 u8 *base;
301
302 struct fjes_hw_info hw_info;
Taku Izumibd5a2562016-04-15 11:25:46 +0900303
304 spinlock_t rx_status_lock; /* spinlock for rx_status */
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900305};
306
307int fjes_hw_init(struct fjes_hw *);
Taku Izumia18aaec2015-08-21 17:29:19 +0900308void fjes_hw_exit(struct fjes_hw *);
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900309int fjes_hw_reset(struct fjes_hw *);
Taku Izumi3bb025d2015-08-21 17:29:21 +0900310int fjes_hw_request_info(struct fjes_hw *);
Taku Izumi7950e6c2015-08-21 17:29:22 +0900311int fjes_hw_register_buff_addr(struct fjes_hw *, int,
312 struct ep_share_mem_info *);
313int fjes_hw_unregister_buff_addr(struct fjes_hw *, int);
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900314void fjes_hw_init_command_registers(struct fjes_hw *,
315 struct fjes_device_command_param *);
316void fjes_hw_setup_epbuf(struct epbuf_handler *, u8 *, u32);
Taku Izumie5d486d2015-08-21 17:29:23 +0900317int fjes_hw_raise_interrupt(struct fjes_hw *, int, enum REG_ICTL_MASK);
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900318void fjes_hw_set_irqmask(struct fjes_hw *, enum REG_ICTL_MASK, bool);
Taku Izumie5d486d2015-08-21 17:29:23 +0900319u32 fjes_hw_capture_interrupt_status(struct fjes_hw *);
320void fjes_hw_raise_epstop(struct fjes_hw *);
321int fjes_hw_wait_epstop(struct fjes_hw *);
322enum ep_partner_status
323 fjes_hw_get_partner_ep_status(struct fjes_hw *, int);
324
325bool fjes_hw_epid_is_same_zone(struct fjes_hw *, int);
326int fjes_hw_epid_is_shared(struct fjes_device_shared_info *, int);
Taku Izumi9acf51c2015-08-21 17:29:24 +0900327bool fjes_hw_check_epbuf_version(struct epbuf_handler *, u32);
328bool fjes_hw_check_mtu(struct epbuf_handler *, u32);
329bool fjes_hw_check_vlan_id(struct epbuf_handler *, u16);
Taku Izumi3e3fedd2015-08-21 17:29:31 +0900330bool fjes_hw_set_vlan_id(struct epbuf_handler *, u16);
331void fjes_hw_del_vlan_id(struct epbuf_handler *, u16);
Taku Izumi26585932015-08-21 17:29:27 +0900332bool fjes_hw_epbuf_rx_is_empty(struct epbuf_handler *);
333void *fjes_hw_epbuf_rx_curpkt_get_addr(struct epbuf_handler *, size_t *);
334void fjes_hw_epbuf_rx_curpkt_drop(struct epbuf_handler *);
Taku Izumi9acf51c2015-08-21 17:29:24 +0900335int fjes_hw_epbuf_tx_pkt_send(struct epbuf_handler *, void *, size_t);
Taku Izumi8cdc3f62015-08-21 17:29:18 +0900336
337#endif /* FJES_HW_H_ */