2 * FUJITSU Extended Socket Network Device driver
3 * Copyright (c) 2015 FUJITSU LIMITED
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.
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
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/>.
17 * The full GNU General Public License is included in this distribution in
18 * the file called "COPYING".
25 #include <linux/netdevice.h>
26 #include <linux/if_vlan.h>
27 #include <linux/vmalloc.h>
29 #include "fjes_regs.h"
33 #define EP_BUFFER_SUPPORT_VLAN_MAX 4
34 #define EP_BUFFER_INFO_SIZE 4096
36 #define FJES_DEBUG_PAGE_SIZE 4096
37 #define FJES_DEBUG_BUFFER_SIZE (16 * FJES_DEBUG_PAGE_SIZE)
39 #define FJES_DEVICE_RESET_TIMEOUT ((17 + 1) * 3 * 8) /* sec */
40 #define FJES_COMMAND_REQ_TIMEOUT ((5 + 1) * 3 * 8) /* sec */
41 #define FJES_COMMAND_REQ_BUFF_TIMEOUT (60 * 3) /* sec */
42 #define FJES_COMMAND_EPSTOP_WAIT_TIMEOUT (1) /* sec */
44 #define FJES_CMD_REQ_ERR_INFO_PARAM (0x0001)
45 #define FJES_CMD_REQ_ERR_INFO_STATUS (0x0002)
47 #define FJES_CMD_REQ_RES_CODE_NORMAL (0)
48 #define FJES_CMD_REQ_RES_CODE_BUSY (1)
50 #define FJES_ZONING_STATUS_DISABLE (0x00)
51 #define FJES_ZONING_STATUS_ENABLE (0x01)
52 #define FJES_ZONING_STATUS_INVALID (0xFF)
54 #define FJES_ZONING_ZONE_TYPE_NONE (0xFF)
56 #define FJES_TX_DELAY_SEND_NONE (0)
57 #define FJES_TX_DELAY_SEND_PENDING (1)
59 #define FJES_RX_STOP_REQ_NONE (0x0)
60 #define FJES_RX_STOP_REQ_DONE (0x1)
61 #define FJES_RX_STOP_REQ_REQUEST (0x2)
62 #define FJES_RX_POLL_WORK (0x4)
63 #define FJES_RX_MTU_CHANGING_DONE (0x8)
65 #define EP_BUFFER_SIZE \
66 (((sizeof(union ep_buffer_info) + (128 * (64 * 1024))) \
67 / EP_BUFFER_INFO_SIZE) * EP_BUFFER_INFO_SIZE)
69 #define EP_RING_NUM(buffer_size, frame_size) \
70 (u32)((buffer_size) / (frame_size))
71 #define EP_RING_INDEX(_num, _max) (((_num) + (_max)) % (_max))
72 #define EP_RING_INDEX_INC(_num, _max) \
73 ((_num) = EP_RING_INDEX((_num) + 1, (_max)))
74 #define EP_RING_FULL(_head, _tail, _max) \
75 (0 == EP_RING_INDEX(((_tail) - (_head)), (_max)))
76 #define EP_RING_EMPTY(_head, _tail, _max) \
77 (1 == EP_RING_INDEX(((_tail) - (_head)), (_max)))
79 #define FJES_MTU_TO_BUFFER_SIZE(mtu) \
80 (ETH_HLEN + VLAN_HLEN + (mtu) + ETH_FCS_LEN)
81 #define FJES_MTU_TO_FRAME_SIZE(mtu) \
82 (sizeof(struct esmem_frame) + FJES_MTU_TO_BUFFER_SIZE(mtu))
83 #define FJES_MTU_DEFINE(size) \
84 ((size) - sizeof(struct esmem_frame) - \
85 (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
87 #define FJES_DEV_COMMAND_INFO_REQ_LEN (4)
88 #define FJES_DEV_COMMAND_INFO_RES_LEN(epnum) (8 + 2 * (epnum))
89 #define FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(txb, rxb) \
90 (24 + (8 * ((txb) / EP_BUFFER_INFO_SIZE + (rxb) / EP_BUFFER_INFO_SIZE)))
91 #define FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN (8)
92 #define FJES_DEV_COMMAND_UNSHARE_BUFFER_REQ_LEN (8)
93 #define FJES_DEV_COMMAND_UNSHARE_BUFFER_RES_LEN (8)
95 #define FJES_DEV_REQ_BUF_SIZE(maxep) \
96 FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(EP_BUFFER_SIZE, EP_BUFFER_SIZE)
97 #define FJES_DEV_RES_BUF_SIZE(maxep) \
98 FJES_DEV_COMMAND_INFO_RES_LEN(maxep)
100 #define FJES_DEV_COMMAND_START_DBG_REQ_LEN(byte) \
101 (16 + (8 * (byte) / FJES_DEBUG_PAGE_SIZE))
102 #define FJES_DEV_COMMAND_START_DBG_RES_LEN (8)
103 #define FJES_DEV_COMMAND_STOP_DBG_REQ_LEN (4)
104 #define FJES_DEV_COMMAND_STOP_DBG_RES_LEN (8)
112 /* EP partner status */
113 enum ep_partner_status
{
118 EP_PARTNER_STATUS_MAX
,
121 /* shared status region */
122 struct fjes_device_shared_info
{
127 /* structures for command control request data*/
128 union fjes_device_command_req
{
152 /* structures for command control response data */
153 union fjes_device_command_res
{
180 /* request command type */
181 enum fjes_dev_command_request_type
{
182 FJES_CMD_REQ_INFO
= 0x0001,
183 FJES_CMD_REQ_SHARE_BUFFER
= 0x0002,
184 FJES_CMD_REQ_UNSHARE_BUFFER
= 0x0004,
185 FJES_CMD_REQ_START_DEBUG
= 0x0100,
186 FJES_CMD_REQ_STOP_DEBUG
= 0x0200,
189 /* parameter for command control */
190 struct fjes_device_command_param
{
192 phys_addr_t req_start
;
194 phys_addr_t res_start
;
195 phys_addr_t share_start
;
198 /* error code for command control */
199 enum fjes_dev_command_response_e
{
200 FJES_CMD_STATUS_UNKNOWN
,
201 FJES_CMD_STATUS_NORMAL
,
202 FJES_CMD_STATUS_TIMEOUT
,
203 FJES_CMD_STATUS_ERROR_PARAM
,
204 FJES_CMD_STATUS_ERROR_STATUS
,
207 /* EP buffer information */
208 union ep_buffer_info
{
209 u8 raw
[EP_BUFFER_INFO_SIZE
];
211 struct _ep_buffer_info_common_t
{
215 struct _ep_buffer_info_v1_t
{
225 u8 mac_addr
[ETH_ALEN
];
236 u16 vlan_id
[EP_BUFFER_SUPPORT_VLAN_MAX
];
242 /* statistics of EP */
243 struct fjes_drv_ep_stats
{
244 u64 com_regist_buf_exec
;
245 u64 com_unregist_buf_exec
;
247 u64 send_intr_unshare
;
248 u64 send_intr_zoneupdate
;
250 u64 recv_intr_unshare
;
252 u64 recv_intr_zoneupdate
;
254 u64 tx_dropped_not_shared
;
255 u64 tx_dropped_ver_mismatch
;
256 u64 tx_dropped_buf_size_mismatch
;
257 u64 tx_dropped_vlanid_mismatch
;
260 /* buffer pair for Extended Partition */
261 struct ep_share_mem_info
{
262 struct epbuf_handler
{
265 union ep_buffer_info
*info
;
269 struct rtnl_link_stats64 net_stats
;
270 struct fjes_drv_ep_stats ep_stats
;
278 struct es_device_trace
{
292 struct fjes_hw_info
{
293 struct fjes_device_shared_info
*share
;
294 union fjes_device_command_req
*req_buf
;
296 union fjes_device_command_res
*res_buf
;
302 struct es_device_trace
*trace
;
305 struct mutex lock
; /* buffer lock*/
307 unsigned long buffer_share_bit
;
308 unsigned long buffer_unshare_reserve_bit
;
314 unsigned long txrx_stop_req_bit
;
315 unsigned long epstop_req_bit
;
316 struct work_struct update_zone_task
;
317 struct work_struct epstop_task
;
322 struct ep_share_mem_info
*ep_shm_info
;
324 struct fjes_hw_resource
{
332 struct fjes_hw_info hw_info
;
334 spinlock_t rx_status_lock
; /* spinlock for rx_status */
339 int fjes_hw_init(struct fjes_hw
*);
340 void fjes_hw_exit(struct fjes_hw
*);
341 int fjes_hw_reset(struct fjes_hw
*);
342 int fjes_hw_request_info(struct fjes_hw
*);
343 int fjes_hw_register_buff_addr(struct fjes_hw
*, int,
344 struct ep_share_mem_info
*);
345 int fjes_hw_unregister_buff_addr(struct fjes_hw
*, int);
346 void fjes_hw_init_command_registers(struct fjes_hw
*,
347 struct fjes_device_command_param
*);
348 void fjes_hw_setup_epbuf(struct epbuf_handler
*, u8
*, u32
);
349 int fjes_hw_raise_interrupt(struct fjes_hw
*, int, enum REG_ICTL_MASK
);
350 void fjes_hw_set_irqmask(struct fjes_hw
*, enum REG_ICTL_MASK
, bool);
351 u32
fjes_hw_capture_interrupt_status(struct fjes_hw
*);
352 void fjes_hw_raise_epstop(struct fjes_hw
*);
353 int fjes_hw_wait_epstop(struct fjes_hw
*);
354 enum ep_partner_status
355 fjes_hw_get_partner_ep_status(struct fjes_hw
*, int);
357 bool fjes_hw_epid_is_same_zone(struct fjes_hw
*, int);
358 int fjes_hw_epid_is_shared(struct fjes_device_shared_info
*, int);
359 bool fjes_hw_check_epbuf_version(struct epbuf_handler
*, u32
);
360 bool fjes_hw_check_mtu(struct epbuf_handler
*, u32
);
361 bool fjes_hw_check_vlan_id(struct epbuf_handler
*, u16
);
362 bool fjes_hw_set_vlan_id(struct epbuf_handler
*, u16
);
363 void fjes_hw_del_vlan_id(struct epbuf_handler
*, u16
);
364 bool fjes_hw_epbuf_rx_is_empty(struct epbuf_handler
*);
365 void *fjes_hw_epbuf_rx_curpkt_get_addr(struct epbuf_handler
*, size_t *);
366 void fjes_hw_epbuf_rx_curpkt_drop(struct epbuf_handler
*);
367 int fjes_hw_epbuf_tx_pkt_send(struct epbuf_handler
*, void *, size_t);
369 int fjes_hw_start_debug(struct fjes_hw
*);
370 int fjes_hw_stop_debug(struct fjes_hw
*);
371 #endif /* FJES_HW_H_ */