Taku Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
| 31 | struct 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 Izumi | 3bb025d | 2015-08-21 17:29:21 +0900 | [diff] [blame] | 37 | #define FJES_COMMAND_REQ_TIMEOUT (5 + 1) /* sec */ |
Taku Izumi | 7950e6c | 2015-08-21 17:29:22 +0900 | [diff] [blame] | 38 | #define FJES_COMMAND_REQ_BUFF_TIMEOUT (8 * 3) /* sec */ |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 39 | #define FJES_COMMAND_EPSTOP_WAIT_TIMEOUT (1) /* sec */ |
Taku Izumi | 3bb025d | 2015-08-21 17:29:21 +0900 | [diff] [blame] | 40 | |
| 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 Izumi | 7950e6c | 2015-08-21 17:29:22 +0900 | [diff] [blame] | 45 | #define FJES_CMD_REQ_RES_CODE_BUSY (1) |
Taku Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 46 | |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 47 | #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 Izumi | 9acf51c | 2015-08-21 17:29:24 +0900 | [diff] [blame^] | 53 | #define FJES_TX_DELAY_SEND_NONE (0) |
| 54 | #define FJES_TX_DELAY_SEND_PENDING (1) |
| 55 | |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 56 | #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 Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 61 | #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 Izumi | 9acf51c | 2015-08-21 17:29:24 +0900 | [diff] [blame^] | 67 | #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 Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 72 | |
| 73 | #define FJES_MTU_TO_BUFFER_SIZE(mtu) \ |
| 74 | (ETH_HLEN + VLAN_HLEN + (mtu) + ETH_FCS_LEN) |
| 75 | #define FJES_MTU_TO_FRAME_SIZE(mtu) \ |
| 76 | (sizeof(struct esmem_frame) + FJES_MTU_TO_BUFFER_SIZE(mtu)) |
| 77 | #define FJES_MTU_DEFINE(size) \ |
| 78 | ((size) - sizeof(struct esmem_frame) - \ |
| 79 | (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)) |
| 80 | |
Taku Izumi | 3bb025d | 2015-08-21 17:29:21 +0900 | [diff] [blame] | 81 | #define FJES_DEV_COMMAND_INFO_REQ_LEN (4) |
Taku Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 82 | #define FJES_DEV_COMMAND_INFO_RES_LEN(epnum) (8 + 2 * (epnum)) |
| 83 | #define FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(txb, rxb) \ |
| 84 | (24 + (8 * ((txb) / EP_BUFFER_INFO_SIZE + (rxb) / EP_BUFFER_INFO_SIZE))) |
Taku Izumi | 7950e6c | 2015-08-21 17:29:22 +0900 | [diff] [blame] | 85 | #define FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN (8) |
| 86 | #define FJES_DEV_COMMAND_UNSHARE_BUFFER_REQ_LEN (8) |
| 87 | #define FJES_DEV_COMMAND_UNSHARE_BUFFER_RES_LEN (8) |
Taku Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 88 | |
| 89 | #define FJES_DEV_REQ_BUF_SIZE(maxep) \ |
| 90 | FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(EP_BUFFER_SIZE, EP_BUFFER_SIZE) |
| 91 | #define FJES_DEV_RES_BUF_SIZE(maxep) \ |
| 92 | FJES_DEV_COMMAND_INFO_RES_LEN(maxep) |
| 93 | |
| 94 | /* Frame & MTU */ |
| 95 | struct esmem_frame { |
| 96 | __le32 frame_size; |
| 97 | u8 frame_data[]; |
| 98 | }; |
| 99 | |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 100 | /* EP partner status */ |
| 101 | enum ep_partner_status { |
| 102 | EP_PARTNER_UNSHARE, |
| 103 | EP_PARTNER_SHARED, |
| 104 | EP_PARTNER_WAITING, |
| 105 | EP_PARTNER_COMPLETE, |
| 106 | EP_PARTNER_STATUS_MAX, |
| 107 | }; |
| 108 | |
Taku Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 109 | /* shared status region */ |
| 110 | struct fjes_device_shared_info { |
| 111 | int epnum; |
| 112 | u8 ep_status[]; |
| 113 | }; |
| 114 | |
| 115 | /* structures for command control request data*/ |
| 116 | union fjes_device_command_req { |
| 117 | struct { |
| 118 | __le32 length; |
| 119 | } info; |
| 120 | struct { |
| 121 | __le32 length; |
| 122 | __le32 epid; |
| 123 | __le64 buffer[]; |
| 124 | } share_buffer; |
| 125 | struct { |
| 126 | __le32 length; |
| 127 | __le32 epid; |
| 128 | } unshare_buffer; |
| 129 | struct { |
| 130 | __le32 length; |
| 131 | __le32 mode; |
| 132 | __le64 buffer_len; |
| 133 | __le64 buffer[]; |
| 134 | } start_trace; |
| 135 | struct { |
| 136 | __le32 length; |
| 137 | } stop_trace; |
| 138 | }; |
| 139 | |
| 140 | /* structures for command control response data */ |
| 141 | union fjes_device_command_res { |
| 142 | struct { |
| 143 | __le32 length; |
| 144 | __le32 code; |
| 145 | struct { |
| 146 | u8 es_status; |
| 147 | u8 zone; |
| 148 | } info[]; |
| 149 | } info; |
| 150 | struct { |
| 151 | __le32 length; |
| 152 | __le32 code; |
| 153 | } share_buffer; |
| 154 | struct { |
| 155 | __le32 length; |
| 156 | __le32 code; |
| 157 | } unshare_buffer; |
| 158 | struct { |
| 159 | __le32 length; |
| 160 | __le32 code; |
| 161 | } start_trace; |
| 162 | struct { |
| 163 | __le32 length; |
| 164 | __le32 code; |
| 165 | } stop_trace; |
| 166 | }; |
| 167 | |
Taku Izumi | 3bb025d | 2015-08-21 17:29:21 +0900 | [diff] [blame] | 168 | /* request command type */ |
| 169 | enum fjes_dev_command_request_type { |
| 170 | FJES_CMD_REQ_INFO = 0x0001, |
| 171 | FJES_CMD_REQ_SHARE_BUFFER = 0x0002, |
| 172 | FJES_CMD_REQ_UNSHARE_BUFFER = 0x0004, |
| 173 | }; |
| 174 | |
Taku Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 175 | /* parameter for command control */ |
| 176 | struct fjes_device_command_param { |
| 177 | u32 req_len; |
| 178 | phys_addr_t req_start; |
| 179 | u32 res_len; |
| 180 | phys_addr_t res_start; |
| 181 | phys_addr_t share_start; |
| 182 | }; |
| 183 | |
Taku Izumi | 3bb025d | 2015-08-21 17:29:21 +0900 | [diff] [blame] | 184 | /* error code for command control */ |
| 185 | enum fjes_dev_command_response_e { |
| 186 | FJES_CMD_STATUS_UNKNOWN, |
| 187 | FJES_CMD_STATUS_NORMAL, |
| 188 | FJES_CMD_STATUS_TIMEOUT, |
| 189 | FJES_CMD_STATUS_ERROR_PARAM, |
| 190 | FJES_CMD_STATUS_ERROR_STATUS, |
| 191 | }; |
| 192 | |
Taku Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 193 | /* EP buffer information */ |
| 194 | union ep_buffer_info { |
| 195 | u8 raw[EP_BUFFER_INFO_SIZE]; |
| 196 | |
| 197 | struct _ep_buffer_info_common_t { |
| 198 | u32 version; |
| 199 | } common; |
| 200 | |
| 201 | struct _ep_buffer_info_v1_t { |
| 202 | u32 version; |
| 203 | u32 info_size; |
| 204 | |
| 205 | u32 buffer_size; |
| 206 | u16 count_max; |
| 207 | |
| 208 | u16 _rsv_1; |
| 209 | |
| 210 | u32 frame_max; |
| 211 | u8 mac_addr[ETH_ALEN]; |
| 212 | |
| 213 | u16 _rsv_2; |
| 214 | u32 _rsv_3; |
| 215 | |
| 216 | u16 tx_status; |
| 217 | u16 rx_status; |
| 218 | |
| 219 | u32 head; |
| 220 | u32 tail; |
| 221 | |
| 222 | u16 vlan_id[EP_BUFFER_SUPPORT_VLAN_MAX]; |
| 223 | |
| 224 | } v1i; |
| 225 | |
| 226 | }; |
| 227 | |
| 228 | /* buffer pair for Extended Partition */ |
| 229 | struct ep_share_mem_info { |
| 230 | struct epbuf_handler { |
| 231 | void *buffer; |
| 232 | size_t size; |
| 233 | union ep_buffer_info *info; |
| 234 | u8 *ring; |
| 235 | } tx, rx; |
| 236 | |
| 237 | struct rtnl_link_stats64 net_stats; |
| 238 | |
| 239 | u16 tx_status_work; |
| 240 | |
| 241 | u8 es_status; |
| 242 | u8 zone; |
| 243 | }; |
| 244 | |
| 245 | struct es_device_trace { |
| 246 | u32 record_num; |
| 247 | u32 current_record; |
| 248 | u32 status_flag; |
| 249 | u32 _rsv; |
| 250 | |
| 251 | struct { |
| 252 | u16 epid; |
| 253 | u16 dir_offset; |
| 254 | u32 data; |
| 255 | u64 tsc; |
| 256 | } record[]; |
| 257 | }; |
| 258 | |
| 259 | struct fjes_hw_info { |
| 260 | struct fjes_device_shared_info *share; |
| 261 | union fjes_device_command_req *req_buf; |
| 262 | u64 req_buf_size; |
| 263 | union fjes_device_command_res *res_buf; |
| 264 | u64 res_buf_size; |
| 265 | |
| 266 | int *my_epid; |
| 267 | int *max_epid; |
| 268 | |
| 269 | struct es_device_trace *trace; |
| 270 | u64 trace_size; |
| 271 | |
| 272 | struct mutex lock; /* buffer lock*/ |
| 273 | |
| 274 | unsigned long buffer_share_bit; |
| 275 | unsigned long buffer_unshare_reserve_bit; |
| 276 | }; |
| 277 | |
| 278 | struct fjes_hw { |
| 279 | void *back; |
| 280 | |
| 281 | unsigned long txrx_stop_req_bit; |
| 282 | unsigned long epstop_req_bit; |
| 283 | |
| 284 | int my_epid; |
| 285 | int max_epid; |
| 286 | |
| 287 | struct ep_share_mem_info *ep_shm_info; |
| 288 | |
| 289 | struct fjes_hw_resource { |
| 290 | u64 start; |
| 291 | u64 size; |
| 292 | int irq; |
| 293 | } hw_res; |
| 294 | |
| 295 | u8 *base; |
| 296 | |
| 297 | struct fjes_hw_info hw_info; |
| 298 | }; |
| 299 | |
| 300 | int fjes_hw_init(struct fjes_hw *); |
Taku Izumi | a18aaec | 2015-08-21 17:29:19 +0900 | [diff] [blame] | 301 | void fjes_hw_exit(struct fjes_hw *); |
Taku Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 302 | int fjes_hw_reset(struct fjes_hw *); |
Taku Izumi | 3bb025d | 2015-08-21 17:29:21 +0900 | [diff] [blame] | 303 | int fjes_hw_request_info(struct fjes_hw *); |
Taku Izumi | 7950e6c | 2015-08-21 17:29:22 +0900 | [diff] [blame] | 304 | int fjes_hw_register_buff_addr(struct fjes_hw *, int, |
| 305 | struct ep_share_mem_info *); |
| 306 | int fjes_hw_unregister_buff_addr(struct fjes_hw *, int); |
Taku Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 307 | void fjes_hw_init_command_registers(struct fjes_hw *, |
| 308 | struct fjes_device_command_param *); |
| 309 | void fjes_hw_setup_epbuf(struct epbuf_handler *, u8 *, u32); |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 310 | int fjes_hw_raise_interrupt(struct fjes_hw *, int, enum REG_ICTL_MASK); |
Taku Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 311 | void fjes_hw_set_irqmask(struct fjes_hw *, enum REG_ICTL_MASK, bool); |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 312 | u32 fjes_hw_capture_interrupt_status(struct fjes_hw *); |
| 313 | void fjes_hw_raise_epstop(struct fjes_hw *); |
| 314 | int fjes_hw_wait_epstop(struct fjes_hw *); |
| 315 | enum ep_partner_status |
| 316 | fjes_hw_get_partner_ep_status(struct fjes_hw *, int); |
| 317 | |
| 318 | bool fjes_hw_epid_is_same_zone(struct fjes_hw *, int); |
| 319 | int fjes_hw_epid_is_shared(struct fjes_device_shared_info *, int); |
Taku Izumi | 9acf51c | 2015-08-21 17:29:24 +0900 | [diff] [blame^] | 320 | bool fjes_hw_check_epbuf_version(struct epbuf_handler *, u32); |
| 321 | bool fjes_hw_check_mtu(struct epbuf_handler *, u32); |
| 322 | bool fjes_hw_check_vlan_id(struct epbuf_handler *, u16); |
| 323 | int fjes_hw_epbuf_tx_pkt_send(struct epbuf_handler *, void *, size_t); |
Taku Izumi | 8cdc3f6 | 2015-08-21 17:29:18 +0900 | [diff] [blame] | 324 | |
| 325 | #endif /* FJES_HW_H_ */ |