Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *  FUJITSU Extended Socket Network Device driver
0004  *  Copyright (c) 2015 FUJITSU LIMITED
0005  */
0006 
0007 #ifndef FJES_HW_H_
0008 #define FJES_HW_H_
0009 
0010 #include <linux/netdevice.h>
0011 #include <linux/if_vlan.h>
0012 #include <linux/vmalloc.h>
0013 
0014 #include "fjes_regs.h"
0015 
0016 struct fjes_hw;
0017 
0018 #define EP_BUFFER_SUPPORT_VLAN_MAX 4
0019 #define EP_BUFFER_INFO_SIZE 4096
0020 
0021 #define FJES_DEBUG_PAGE_SIZE 4096
0022 #define FJES_DEBUG_BUFFER_SIZE  (16 * FJES_DEBUG_PAGE_SIZE)
0023 
0024 #define FJES_DEVICE_RESET_TIMEOUT  ((17 + 1) * 3 * 8) /* sec */
0025 #define FJES_COMMAND_REQ_TIMEOUT  ((5 + 1) * 3 * 8) /* sec */
0026 #define FJES_COMMAND_REQ_BUFF_TIMEOUT   (60 * 3) /* sec */
0027 #define FJES_COMMAND_EPSTOP_WAIT_TIMEOUT    (1) /* sec */
0028 
0029 #define FJES_CMD_REQ_ERR_INFO_PARAM  (0x0001)
0030 #define FJES_CMD_REQ_ERR_INFO_STATUS (0x0002)
0031 
0032 #define FJES_CMD_REQ_RES_CODE_NORMAL (0)
0033 #define FJES_CMD_REQ_RES_CODE_BUSY   (1)
0034 
0035 #define FJES_ZONING_STATUS_DISABLE  (0x00)
0036 #define FJES_ZONING_STATUS_ENABLE   (0x01)
0037 #define FJES_ZONING_STATUS_INVALID  (0xFF)
0038 
0039 #define FJES_ZONING_ZONE_TYPE_NONE (0xFF)
0040 
0041 #define FJES_TX_DELAY_SEND_NONE     (0)
0042 #define FJES_TX_DELAY_SEND_PENDING  (1)
0043 
0044 #define FJES_RX_STOP_REQ_NONE       (0x0)
0045 #define FJES_RX_STOP_REQ_DONE       (0x1)
0046 #define FJES_RX_STOP_REQ_REQUEST    (0x2)
0047 #define FJES_RX_POLL_WORK       (0x4)
0048 #define FJES_RX_MTU_CHANGING_DONE   (0x8)
0049 
0050 #define EP_BUFFER_SIZE \
0051     (((sizeof(union ep_buffer_info) + (128 * (64 * 1024))) \
0052         / EP_BUFFER_INFO_SIZE) * EP_BUFFER_INFO_SIZE)
0053 
0054 #define EP_RING_NUM(buffer_size, frame_size) \
0055         (u32)((buffer_size) / (frame_size))
0056 #define EP_RING_INDEX(_num, _max) (((_num) + (_max)) % (_max))
0057 #define EP_RING_INDEX_INC(_num, _max) \
0058     ((_num) = EP_RING_INDEX((_num) + 1, (_max)))
0059 #define EP_RING_FULL(_head, _tail, _max)                \
0060     (0 == EP_RING_INDEX(((_tail) - (_head)), (_max)))
0061 #define EP_RING_EMPTY(_head, _tail, _max) \
0062     (1 == EP_RING_INDEX(((_tail) - (_head)), (_max)))
0063 
0064 #define FJES_MTU_TO_BUFFER_SIZE(mtu) \
0065     (ETH_HLEN + VLAN_HLEN + (mtu) + ETH_FCS_LEN)
0066 #define FJES_MTU_TO_FRAME_SIZE(mtu) \
0067     (sizeof(struct esmem_frame) + FJES_MTU_TO_BUFFER_SIZE(mtu))
0068 #define FJES_MTU_DEFINE(size) \
0069     ((size) - sizeof(struct esmem_frame) - \
0070     (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
0071 
0072 #define FJES_DEV_COMMAND_INFO_REQ_LEN   (4)
0073 #define FJES_DEV_COMMAND_INFO_RES_LEN(epnum) (8 + 2 * (epnum))
0074 #define FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(txb, rxb) \
0075     (24 + (8 * ((txb) / EP_BUFFER_INFO_SIZE + (rxb) / EP_BUFFER_INFO_SIZE)))
0076 #define FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN   (8)
0077 #define FJES_DEV_COMMAND_UNSHARE_BUFFER_REQ_LEN (8)
0078 #define FJES_DEV_COMMAND_UNSHARE_BUFFER_RES_LEN (8)
0079 
0080 #define FJES_DEV_REQ_BUF_SIZE(maxep) \
0081     FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(EP_BUFFER_SIZE, EP_BUFFER_SIZE)
0082 #define FJES_DEV_RES_BUF_SIZE(maxep) \
0083     FJES_DEV_COMMAND_INFO_RES_LEN(maxep)
0084 
0085 #define FJES_DEV_COMMAND_START_DBG_REQ_LEN(byte) \
0086     (16 + (8 * (byte) / FJES_DEBUG_PAGE_SIZE))
0087 #define FJES_DEV_COMMAND_START_DBG_RES_LEN (8)
0088 #define FJES_DEV_COMMAND_STOP_DBG_REQ_LEN (4)
0089 #define FJES_DEV_COMMAND_STOP_DBG_RES_LEN (8)
0090 
0091 /* Frame & MTU */
0092 struct esmem_frame {
0093     __le32 frame_size;
0094     u8 frame_data[];
0095 };
0096 
0097 /* EP partner status */
0098 enum ep_partner_status {
0099     EP_PARTNER_UNSHARE,
0100     EP_PARTNER_SHARED,
0101     EP_PARTNER_WAITING,
0102     EP_PARTNER_COMPLETE,
0103     EP_PARTNER_STATUS_MAX,
0104 };
0105 
0106 /* shared status region */
0107 struct fjes_device_shared_info {
0108     int epnum;
0109     u8 ep_status[];
0110 };
0111 
0112 /* structures for command control request data*/
0113 union fjes_device_command_req {
0114     struct {
0115         __le32 length;
0116     } info;
0117     struct {
0118         __le32 length;
0119         __le32 epid;
0120         __le64 buffer[];
0121     } share_buffer;
0122     struct {
0123         __le32 length;
0124         __le32 epid;
0125     } unshare_buffer;
0126     struct {
0127         __le32 length;
0128         __le32 mode;
0129         __le64 buffer_len;
0130         __le64 buffer[];
0131     } start_trace;
0132     struct {
0133         __le32 length;
0134     } stop_trace;
0135 };
0136 
0137 /* structures for command control response data */
0138 union fjes_device_command_res {
0139     struct {
0140         __le32 length;
0141         __le32 code;
0142         struct {
0143             u8 es_status;
0144             u8 zone;
0145         } info[];
0146     } info;
0147     struct {
0148         __le32 length;
0149         __le32 code;
0150     } share_buffer;
0151     struct {
0152         __le32 length;
0153         __le32 code;
0154     } unshare_buffer;
0155     struct {
0156         __le32 length;
0157         __le32 code;
0158     } start_trace;
0159     struct {
0160         __le32 length;
0161         __le32 code;
0162     } stop_trace;
0163 };
0164 
0165 /* request command type */
0166 enum fjes_dev_command_request_type {
0167     FJES_CMD_REQ_INFO       = 0x0001,
0168     FJES_CMD_REQ_SHARE_BUFFER   = 0x0002,
0169     FJES_CMD_REQ_UNSHARE_BUFFER = 0x0004,
0170     FJES_CMD_REQ_START_DEBUG    = 0x0100,
0171     FJES_CMD_REQ_STOP_DEBUG     = 0x0200,
0172 };
0173 
0174 /* parameter for command control */
0175 struct fjes_device_command_param {
0176     u32 req_len;
0177     phys_addr_t req_start;
0178     u32 res_len;
0179     phys_addr_t res_start;
0180     phys_addr_t share_start;
0181 };
0182 
0183 /* error code for command control */
0184 enum fjes_dev_command_response_e {
0185     FJES_CMD_STATUS_UNKNOWN,
0186     FJES_CMD_STATUS_NORMAL,
0187     FJES_CMD_STATUS_TIMEOUT,
0188     FJES_CMD_STATUS_ERROR_PARAM,
0189     FJES_CMD_STATUS_ERROR_STATUS,
0190 };
0191 
0192 /* EP buffer information */
0193 union ep_buffer_info {
0194     u8 raw[EP_BUFFER_INFO_SIZE];
0195 
0196     struct _ep_buffer_info_common_t {
0197         u32 version;
0198     } common;
0199 
0200     struct _ep_buffer_info_v1_t {
0201         u32 version;
0202         u32 info_size;
0203 
0204         u32 buffer_size;
0205         u16 count_max;
0206 
0207         u16 _rsv_1;
0208 
0209         u32 frame_max;
0210         u8 mac_addr[ETH_ALEN];
0211 
0212         u16 _rsv_2;
0213         u32 _rsv_3;
0214 
0215         u16 tx_status;
0216         u16 rx_status;
0217 
0218         u32 head;
0219         u32 tail;
0220 
0221         u16 vlan_id[EP_BUFFER_SUPPORT_VLAN_MAX];
0222 
0223     } v1i;
0224 
0225 };
0226 
0227 /* statistics of EP */
0228 struct fjes_drv_ep_stats {
0229     u64 com_regist_buf_exec;
0230     u64 com_unregist_buf_exec;
0231     u64 send_intr_rx;
0232     u64 send_intr_unshare;
0233     u64 send_intr_zoneupdate;
0234     u64 recv_intr_rx;
0235     u64 recv_intr_unshare;
0236     u64 recv_intr_stop;
0237     u64 recv_intr_zoneupdate;
0238     u64 tx_buffer_full;
0239     u64 tx_dropped_not_shared;
0240     u64 tx_dropped_ver_mismatch;
0241     u64 tx_dropped_buf_size_mismatch;
0242     u64 tx_dropped_vlanid_mismatch;
0243 };
0244 
0245 /* buffer pair for Extended Partition */
0246 struct ep_share_mem_info {
0247     struct epbuf_handler {
0248         void *buffer;
0249         size_t size;
0250         union ep_buffer_info *info;
0251         u8 *ring;
0252     } tx, rx;
0253 
0254     struct rtnl_link_stats64 net_stats;
0255     struct fjes_drv_ep_stats ep_stats;
0256 
0257     u16 tx_status_work;
0258 
0259     u8 es_status;
0260     u8 zone;
0261 };
0262 
0263 struct es_device_trace {
0264     u32 record_num;
0265     u32 current_record;
0266     u32 status_flag;
0267     u32 _rsv;
0268 
0269     struct {
0270             u16 epid;
0271             u16 dir_offset;
0272             u32 data;
0273             u64 tsc;
0274     } record[];
0275 };
0276 
0277 struct fjes_hw_info {
0278     struct fjes_device_shared_info *share;
0279     union fjes_device_command_req *req_buf;
0280     u64 req_buf_size;
0281     union fjes_device_command_res *res_buf;
0282     u64 res_buf_size;
0283 
0284     int *my_epid;
0285     int *max_epid;
0286 
0287     struct es_device_trace *trace;
0288     u64 trace_size;
0289 
0290     struct mutex lock; /* buffer lock*/
0291 
0292     unsigned long buffer_share_bit;
0293     unsigned long buffer_unshare_reserve_bit;
0294 };
0295 
0296 struct fjes_hw {
0297     void *back;
0298 
0299     unsigned long txrx_stop_req_bit;
0300     unsigned long epstop_req_bit;
0301     struct work_struct update_zone_task;
0302     struct work_struct epstop_task;
0303 
0304     int my_epid;
0305     int max_epid;
0306 
0307     struct ep_share_mem_info *ep_shm_info;
0308 
0309     struct fjes_hw_resource {
0310         u64 start;
0311         u64 size;
0312         int irq;
0313     } hw_res;
0314 
0315     u8 *base;
0316 
0317     struct fjes_hw_info hw_info;
0318 
0319     spinlock_t rx_status_lock; /* spinlock for rx_status */
0320 
0321     u32 debug_mode;
0322 };
0323 
0324 int fjes_hw_init(struct fjes_hw *);
0325 void fjes_hw_exit(struct fjes_hw *);
0326 int fjes_hw_reset(struct fjes_hw *);
0327 int fjes_hw_request_info(struct fjes_hw *);
0328 int fjes_hw_register_buff_addr(struct fjes_hw *, int,
0329                    struct ep_share_mem_info *);
0330 int fjes_hw_unregister_buff_addr(struct fjes_hw *, int);
0331 void fjes_hw_init_command_registers(struct fjes_hw *,
0332                     struct fjes_device_command_param *);
0333 void fjes_hw_setup_epbuf(struct epbuf_handler *, const u8 *, u32);
0334 int fjes_hw_raise_interrupt(struct fjes_hw *, int, enum REG_ICTL_MASK);
0335 void fjes_hw_set_irqmask(struct fjes_hw *, enum REG_ICTL_MASK, bool);
0336 u32 fjes_hw_capture_interrupt_status(struct fjes_hw *);
0337 void fjes_hw_raise_epstop(struct fjes_hw *);
0338 int fjes_hw_wait_epstop(struct fjes_hw *);
0339 enum ep_partner_status
0340     fjes_hw_get_partner_ep_status(struct fjes_hw *, int);
0341 
0342 bool fjes_hw_epid_is_same_zone(struct fjes_hw *, int);
0343 int fjes_hw_epid_is_shared(struct fjes_device_shared_info *, int);
0344 bool fjes_hw_check_epbuf_version(struct epbuf_handler *, u32);
0345 bool fjes_hw_check_mtu(struct epbuf_handler *, u32);
0346 bool fjes_hw_check_vlan_id(struct epbuf_handler *, u16);
0347 bool fjes_hw_set_vlan_id(struct epbuf_handler *, u16);
0348 void fjes_hw_del_vlan_id(struct epbuf_handler *, u16);
0349 bool fjes_hw_epbuf_rx_is_empty(struct epbuf_handler *);
0350 void *fjes_hw_epbuf_rx_curpkt_get_addr(struct epbuf_handler *, size_t *);
0351 void fjes_hw_epbuf_rx_curpkt_drop(struct epbuf_handler *);
0352 int fjes_hw_epbuf_tx_pkt_send(struct epbuf_handler *, void *, size_t);
0353 
0354 int fjes_hw_start_debug(struct fjes_hw *);
0355 int fjes_hw_stop_debug(struct fjes_hw *);
0356 #endif /* FJES_HW_H_ */