1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * FUJITSU Extended Socket Network Device driver
4 * Copyright (c) 2015 FUJITSU LIMITED
10 #include <linux/netdevice.h>
11 #include <linux/if_vlan.h>
12 #include <linux/vmalloc.h>
14 #include "fjes_regs.h"
18 #define EP_BUFFER_SUPPORT_VLAN_MAX 4
19 #define EP_BUFFER_INFO_SIZE 4096
21 #define FJES_DEBUG_PAGE_SIZE 4096
22 #define FJES_DEBUG_BUFFER_SIZE (16 * FJES_DEBUG_PAGE_SIZE)
24 #define FJES_DEVICE_RESET_TIMEOUT ((17 + 1) * 3 * 8) /* sec */
25 #define FJES_COMMAND_REQ_TIMEOUT ((5 + 1) * 3 * 8) /* sec */
26 #define FJES_COMMAND_REQ_BUFF_TIMEOUT (60 * 3) /* sec */
27 #define FJES_COMMAND_EPSTOP_WAIT_TIMEOUT (1) /* sec */
29 #define FJES_CMD_REQ_ERR_INFO_PARAM (0x0001)
30 #define FJES_CMD_REQ_ERR_INFO_STATUS (0x0002)
32 #define FJES_CMD_REQ_RES_CODE_NORMAL (0)
33 #define FJES_CMD_REQ_RES_CODE_BUSY (1)
35 #define FJES_ZONING_STATUS_DISABLE (0x00)
36 #define FJES_ZONING_STATUS_ENABLE (0x01)
37 #define FJES_ZONING_STATUS_INVALID (0xFF)
39 #define FJES_ZONING_ZONE_TYPE_NONE (0xFF)
41 #define FJES_TX_DELAY_SEND_NONE (0)
42 #define FJES_TX_DELAY_SEND_PENDING (1)
44 #define FJES_RX_STOP_REQ_NONE (0x0)
45 #define FJES_RX_STOP_REQ_DONE (0x1)
46 #define FJES_RX_STOP_REQ_REQUEST (0x2)
47 #define FJES_RX_POLL_WORK (0x4)
48 #define FJES_RX_MTU_CHANGING_DONE (0x8)
50 #define EP_BUFFER_SIZE \
51 (((sizeof(union ep_buffer_info) + (128 * (64 * 1024))) \
52 / EP_BUFFER_INFO_SIZE) * EP_BUFFER_INFO_SIZE)
54 #define EP_RING_NUM(buffer_size, frame_size) \
55 (u32)((buffer_size) / (frame_size))
56 #define EP_RING_INDEX(_num, _max) (((_num) + (_max)) % (_max))
57 #define EP_RING_INDEX_INC(_num, _max) \
58 ((_num) = EP_RING_INDEX((_num) + 1, (_max)))
59 #define EP_RING_FULL(_head, _tail, _max) \
60 (0 == EP_RING_INDEX(((_tail) - (_head)), (_max)))
61 #define EP_RING_EMPTY(_head, _tail, _max) \
62 (1 == EP_RING_INDEX(((_tail) - (_head)), (_max)))
64 #define FJES_MTU_TO_BUFFER_SIZE(mtu) \
65 (ETH_HLEN + VLAN_HLEN + (mtu) + ETH_FCS_LEN)
66 #define FJES_MTU_TO_FRAME_SIZE(mtu) \
67 (sizeof(struct esmem_frame) + FJES_MTU_TO_BUFFER_SIZE(mtu))
68 #define FJES_MTU_DEFINE(size) \
69 ((size) - sizeof(struct esmem_frame) - \
70 (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
72 #define FJES_DEV_COMMAND_INFO_REQ_LEN (4)
73 #define FJES_DEV_COMMAND_INFO_RES_LEN(epnum) (8 + 2 * (epnum))
74 #define FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(txb, rxb) \
75 (24 + (8 * ((txb) / EP_BUFFER_INFO_SIZE + (rxb) / EP_BUFFER_INFO_SIZE)))
76 #define FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN (8)
77 #define FJES_DEV_COMMAND_UNSHARE_BUFFER_REQ_LEN (8)
78 #define FJES_DEV_COMMAND_UNSHARE_BUFFER_RES_LEN (8)
80 #define FJES_DEV_REQ_BUF_SIZE(maxep) \
81 FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(EP_BUFFER_SIZE, EP_BUFFER_SIZE)
82 #define FJES_DEV_RES_BUF_SIZE(maxep) \
83 FJES_DEV_COMMAND_INFO_RES_LEN(maxep)
85 #define FJES_DEV_COMMAND_START_DBG_REQ_LEN(byte) \
86 (16 + (8 * (byte) / FJES_DEBUG_PAGE_SIZE))
87 #define FJES_DEV_COMMAND_START_DBG_RES_LEN (8)
88 #define FJES_DEV_COMMAND_STOP_DBG_REQ_LEN (4)
89 #define FJES_DEV_COMMAND_STOP_DBG_RES_LEN (8)
97 /* EP partner status */
98 enum ep_partner_status
{
103 EP_PARTNER_STATUS_MAX
,
106 /* shared status region */
107 struct fjes_device_shared_info
{
112 /* structures for command control request data*/
113 union fjes_device_command_req
{
137 /* structures for command control response data */
138 union fjes_device_command_res
{
165 /* request command type */
166 enum fjes_dev_command_request_type
{
167 FJES_CMD_REQ_INFO
= 0x0001,
168 FJES_CMD_REQ_SHARE_BUFFER
= 0x0002,
169 FJES_CMD_REQ_UNSHARE_BUFFER
= 0x0004,
170 FJES_CMD_REQ_START_DEBUG
= 0x0100,
171 FJES_CMD_REQ_STOP_DEBUG
= 0x0200,
174 /* parameter for command control */
175 struct fjes_device_command_param
{
177 phys_addr_t req_start
;
179 phys_addr_t res_start
;
180 phys_addr_t share_start
;
183 /* error code for command control */
184 enum fjes_dev_command_response_e
{
185 FJES_CMD_STATUS_UNKNOWN
,
186 FJES_CMD_STATUS_NORMAL
,
187 FJES_CMD_STATUS_TIMEOUT
,
188 FJES_CMD_STATUS_ERROR_PARAM
,
189 FJES_CMD_STATUS_ERROR_STATUS
,
192 /* EP buffer information */
193 union ep_buffer_info
{
194 u8 raw
[EP_BUFFER_INFO_SIZE
];
196 struct _ep_buffer_info_common_t
{
200 struct _ep_buffer_info_v1_t
{
210 u8 mac_addr
[ETH_ALEN
];
221 u16 vlan_id
[EP_BUFFER_SUPPORT_VLAN_MAX
];
227 /* statistics of EP */
228 struct fjes_drv_ep_stats
{
229 u64 com_regist_buf_exec
;
230 u64 com_unregist_buf_exec
;
232 u64 send_intr_unshare
;
233 u64 send_intr_zoneupdate
;
235 u64 recv_intr_unshare
;
237 u64 recv_intr_zoneupdate
;
239 u64 tx_dropped_not_shared
;
240 u64 tx_dropped_ver_mismatch
;
241 u64 tx_dropped_buf_size_mismatch
;
242 u64 tx_dropped_vlanid_mismatch
;
245 /* buffer pair for Extended Partition */
246 struct ep_share_mem_info
{
247 struct epbuf_handler
{
250 union ep_buffer_info
*info
;
254 struct rtnl_link_stats64 net_stats
;
255 struct fjes_drv_ep_stats ep_stats
;
263 struct es_device_trace
{
277 struct fjes_hw_info
{
278 struct fjes_device_shared_info
*share
;
279 union fjes_device_command_req
*req_buf
;
281 union fjes_device_command_res
*res_buf
;
287 struct es_device_trace
*trace
;
290 struct mutex lock
; /* buffer lock*/
292 unsigned long buffer_share_bit
;
293 unsigned long buffer_unshare_reserve_bit
;
299 unsigned long txrx_stop_req_bit
;
300 unsigned long epstop_req_bit
;
301 struct work_struct update_zone_task
;
302 struct work_struct epstop_task
;
307 struct ep_share_mem_info
*ep_shm_info
;
309 struct fjes_hw_resource
{
317 struct fjes_hw_info hw_info
;
319 spinlock_t rx_status_lock
; /* spinlock for rx_status */
324 int fjes_hw_init(struct fjes_hw
*);
325 void fjes_hw_exit(struct fjes_hw
*);
326 int fjes_hw_reset(struct fjes_hw
*);
327 int fjes_hw_request_info(struct fjes_hw
*);
328 int fjes_hw_register_buff_addr(struct fjes_hw
*, int,
329 struct ep_share_mem_info
*);
330 int fjes_hw_unregister_buff_addr(struct fjes_hw
*, int);
331 void fjes_hw_init_command_registers(struct fjes_hw
*,
332 struct fjes_device_command_param
*);
333 void fjes_hw_setup_epbuf(struct epbuf_handler
*, u8
*, u32
);
334 int fjes_hw_raise_interrupt(struct fjes_hw
*, int, enum REG_ICTL_MASK
);
335 void fjes_hw_set_irqmask(struct fjes_hw
*, enum REG_ICTL_MASK
, bool);
336 u32
fjes_hw_capture_interrupt_status(struct fjes_hw
*);
337 void fjes_hw_raise_epstop(struct fjes_hw
*);
338 int fjes_hw_wait_epstop(struct fjes_hw
*);
339 enum ep_partner_status
340 fjes_hw_get_partner_ep_status(struct fjes_hw
*, int);
342 bool fjes_hw_epid_is_same_zone(struct fjes_hw
*, int);
343 int fjes_hw_epid_is_shared(struct fjes_device_shared_info
*, int);
344 bool fjes_hw_check_epbuf_version(struct epbuf_handler
*, u32
);
345 bool fjes_hw_check_mtu(struct epbuf_handler
*, u32
);
346 bool fjes_hw_check_vlan_id(struct epbuf_handler
*, u16
);
347 bool fjes_hw_set_vlan_id(struct epbuf_handler
*, u16
);
348 void fjes_hw_del_vlan_id(struct epbuf_handler
*, u16
);
349 bool fjes_hw_epbuf_rx_is_empty(struct epbuf_handler
*);
350 void *fjes_hw_epbuf_rx_curpkt_get_addr(struct epbuf_handler
*, size_t *);
351 void fjes_hw_epbuf_rx_curpkt_drop(struct epbuf_handler
*);
352 int fjes_hw_epbuf_tx_pkt_send(struct epbuf_handler
*, void *, size_t);
354 int fjes_hw_start_debug(struct fjes_hw
*);
355 int fjes_hw_stop_debug(struct fjes_hw
*);
356 #endif /* FJES_HW_H_ */