fjes_hw.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * FUJITSU Extended Socket Network Device driver
  4. * Copyright (c) 2015 FUJITSU LIMITED
  5. */
  6. #ifndef FJES_HW_H_
  7. #define FJES_HW_H_
  8. #include <linux/netdevice.h>
  9. #include <linux/if_vlan.h>
  10. #include <linux/vmalloc.h>
  11. #include "fjes_regs.h"
  12. struct fjes_hw;
  13. #define EP_BUFFER_SUPPORT_VLAN_MAX 4
  14. #define EP_BUFFER_INFO_SIZE 4096
  15. #define FJES_DEBUG_PAGE_SIZE 4096
  16. #define FJES_DEBUG_BUFFER_SIZE (16 * FJES_DEBUG_PAGE_SIZE)
  17. #define FJES_DEVICE_RESET_TIMEOUT ((17 + 1) * 3 * 8) /* sec */
  18. #define FJES_COMMAND_REQ_TIMEOUT ((5 + 1) * 3 * 8) /* sec */
  19. #define FJES_COMMAND_REQ_BUFF_TIMEOUT (60 * 3) /* sec */
  20. #define FJES_COMMAND_EPSTOP_WAIT_TIMEOUT (1) /* sec */
  21. #define FJES_CMD_REQ_ERR_INFO_PARAM (0x0001)
  22. #define FJES_CMD_REQ_ERR_INFO_STATUS (0x0002)
  23. #define FJES_CMD_REQ_RES_CODE_NORMAL (0)
  24. #define FJES_CMD_REQ_RES_CODE_BUSY (1)
  25. #define FJES_ZONING_STATUS_DISABLE (0x00)
  26. #define FJES_ZONING_STATUS_ENABLE (0x01)
  27. #define FJES_ZONING_STATUS_INVALID (0xFF)
  28. #define FJES_ZONING_ZONE_TYPE_NONE (0xFF)
  29. #define FJES_TX_DELAY_SEND_NONE (0)
  30. #define FJES_TX_DELAY_SEND_PENDING (1)
  31. #define FJES_RX_STOP_REQ_NONE (0x0)
  32. #define FJES_RX_STOP_REQ_DONE (0x1)
  33. #define FJES_RX_STOP_REQ_REQUEST (0x2)
  34. #define FJES_RX_POLL_WORK (0x4)
  35. #define FJES_RX_MTU_CHANGING_DONE (0x8)
  36. #define EP_BUFFER_SIZE \
  37. (((sizeof(union ep_buffer_info) + (128 * (64 * 1024))) \
  38. / EP_BUFFER_INFO_SIZE) * EP_BUFFER_INFO_SIZE)
  39. #define EP_RING_NUM(buffer_size, frame_size) \
  40. (u32)((buffer_size) / (frame_size))
  41. #define EP_RING_INDEX(_num, _max) (((_num) + (_max)) % (_max))
  42. #define EP_RING_INDEX_INC(_num, _max) \
  43. ((_num) = EP_RING_INDEX((_num) + 1, (_max)))
  44. #define EP_RING_FULL(_head, _tail, _max) \
  45. (0 == EP_RING_INDEX(((_tail) - (_head)), (_max)))
  46. #define EP_RING_EMPTY(_head, _tail, _max) \
  47. (1 == EP_RING_INDEX(((_tail) - (_head)), (_max)))
  48. #define FJES_MTU_TO_BUFFER_SIZE(mtu) \
  49. (ETH_HLEN + VLAN_HLEN + (mtu) + ETH_FCS_LEN)
  50. #define FJES_MTU_TO_FRAME_SIZE(mtu) \
  51. (sizeof(struct esmem_frame) + FJES_MTU_TO_BUFFER_SIZE(mtu))
  52. #define FJES_MTU_DEFINE(size) \
  53. ((size) - sizeof(struct esmem_frame) - \
  54. (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
  55. #define FJES_DEV_COMMAND_INFO_REQ_LEN (4)
  56. #define FJES_DEV_COMMAND_INFO_RES_LEN(epnum) (8 + 2 * (epnum))
  57. #define FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(txb, rxb) \
  58. (24 + (8 * ((txb) / EP_BUFFER_INFO_SIZE + (rxb) / EP_BUFFER_INFO_SIZE)))
  59. #define FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN (8)
  60. #define FJES_DEV_COMMAND_UNSHARE_BUFFER_REQ_LEN (8)
  61. #define FJES_DEV_COMMAND_UNSHARE_BUFFER_RES_LEN (8)
  62. #define FJES_DEV_REQ_BUF_SIZE(maxep) \
  63. FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(EP_BUFFER_SIZE, EP_BUFFER_SIZE)
  64. #define FJES_DEV_RES_BUF_SIZE(maxep) \
  65. FJES_DEV_COMMAND_INFO_RES_LEN(maxep)
  66. #define FJES_DEV_COMMAND_START_DBG_REQ_LEN(byte) \
  67. (16 + (8 * (byte) / FJES_DEBUG_PAGE_SIZE))
  68. #define FJES_DEV_COMMAND_START_DBG_RES_LEN (8)
  69. #define FJES_DEV_COMMAND_STOP_DBG_REQ_LEN (4)
  70. #define FJES_DEV_COMMAND_STOP_DBG_RES_LEN (8)
  71. /* Frame & MTU */
  72. struct esmem_frame {
  73. __le32 frame_size;
  74. u8 frame_data[];
  75. };
  76. /* EP partner status */
  77. enum ep_partner_status {
  78. EP_PARTNER_UNSHARE,
  79. EP_PARTNER_SHARED,
  80. EP_PARTNER_WAITING,
  81. EP_PARTNER_COMPLETE,
  82. EP_PARTNER_STATUS_MAX,
  83. };
  84. /* shared status region */
  85. struct fjes_device_shared_info {
  86. int epnum;
  87. u8 ep_status[];
  88. };
  89. /* structures for command control request data*/
  90. union fjes_device_command_req {
  91. struct {
  92. __le32 length;
  93. } info;
  94. struct {
  95. __le32 length;
  96. __le32 epid;
  97. __le64 buffer[];
  98. } share_buffer;
  99. struct {
  100. __le32 length;
  101. __le32 epid;
  102. } unshare_buffer;
  103. struct {
  104. __le32 length;
  105. __le32 mode;
  106. __le64 buffer_len;
  107. __le64 buffer[];
  108. } start_trace;
  109. struct {
  110. __le32 length;
  111. } stop_trace;
  112. };
  113. /* structures for command control response data */
  114. union fjes_device_command_res {
  115. struct {
  116. __le32 length;
  117. __le32 code;
  118. struct {
  119. u8 es_status;
  120. u8 zone;
  121. } info[];
  122. } info;
  123. struct {
  124. __le32 length;
  125. __le32 code;
  126. } share_buffer;
  127. struct {
  128. __le32 length;
  129. __le32 code;
  130. } unshare_buffer;
  131. struct {
  132. __le32 length;
  133. __le32 code;
  134. } start_trace;
  135. struct {
  136. __le32 length;
  137. __le32 code;
  138. } stop_trace;
  139. };
  140. /* request command type */
  141. enum fjes_dev_command_request_type {
  142. FJES_CMD_REQ_INFO = 0x0001,
  143. FJES_CMD_REQ_SHARE_BUFFER = 0x0002,
  144. FJES_CMD_REQ_UNSHARE_BUFFER = 0x0004,
  145. FJES_CMD_REQ_START_DEBUG = 0x0100,
  146. FJES_CMD_REQ_STOP_DEBUG = 0x0200,
  147. };
  148. /* parameter for command control */
  149. struct fjes_device_command_param {
  150. u32 req_len;
  151. phys_addr_t req_start;
  152. u32 res_len;
  153. phys_addr_t res_start;
  154. phys_addr_t share_start;
  155. };
  156. /* error code for command control */
  157. enum fjes_dev_command_response_e {
  158. FJES_CMD_STATUS_UNKNOWN,
  159. FJES_CMD_STATUS_NORMAL,
  160. FJES_CMD_STATUS_TIMEOUT,
  161. FJES_CMD_STATUS_ERROR_PARAM,
  162. FJES_CMD_STATUS_ERROR_STATUS,
  163. };
  164. /* EP buffer information */
  165. union ep_buffer_info {
  166. u8 raw[EP_BUFFER_INFO_SIZE];
  167. struct _ep_buffer_info_common_t {
  168. u32 version;
  169. } common;
  170. struct _ep_buffer_info_v1_t {
  171. u32 version;
  172. u32 info_size;
  173. u32 buffer_size;
  174. u16 count_max;
  175. u16 _rsv_1;
  176. u32 frame_max;
  177. u8 mac_addr[ETH_ALEN];
  178. u16 _rsv_2;
  179. u32 _rsv_3;
  180. u16 tx_status;
  181. u16 rx_status;
  182. u32 head;
  183. u32 tail;
  184. u16 vlan_id[EP_BUFFER_SUPPORT_VLAN_MAX];
  185. } v1i;
  186. };
  187. /* statistics of EP */
  188. struct fjes_drv_ep_stats {
  189. u64 com_regist_buf_exec;
  190. u64 com_unregist_buf_exec;
  191. u64 send_intr_rx;
  192. u64 send_intr_unshare;
  193. u64 send_intr_zoneupdate;
  194. u64 recv_intr_rx;
  195. u64 recv_intr_unshare;
  196. u64 recv_intr_stop;
  197. u64 recv_intr_zoneupdate;
  198. u64 tx_buffer_full;
  199. u64 tx_dropped_not_shared;
  200. u64 tx_dropped_ver_mismatch;
  201. u64 tx_dropped_buf_size_mismatch;
  202. u64 tx_dropped_vlanid_mismatch;
  203. };
  204. /* buffer pair for Extended Partition */
  205. struct ep_share_mem_info {
  206. struct epbuf_handler {
  207. void *buffer;
  208. size_t size;
  209. union ep_buffer_info *info;
  210. u8 *ring;
  211. } tx, rx;
  212. struct rtnl_link_stats64 net_stats;
  213. struct fjes_drv_ep_stats ep_stats;
  214. u16 tx_status_work;
  215. u8 es_status;
  216. u8 zone;
  217. };
  218. struct es_device_trace {
  219. u32 record_num;
  220. u32 current_record;
  221. u32 status_flag;
  222. u32 _rsv;
  223. struct {
  224. u16 epid;
  225. u16 dir_offset;
  226. u32 data;
  227. u64 tsc;
  228. } record[];
  229. };
  230. struct fjes_hw_info {
  231. struct fjes_device_shared_info *share;
  232. union fjes_device_command_req *req_buf;
  233. u64 req_buf_size;
  234. union fjes_device_command_res *res_buf;
  235. u64 res_buf_size;
  236. int *my_epid;
  237. int *max_epid;
  238. struct es_device_trace *trace;
  239. u64 trace_size;
  240. struct mutex lock; /* buffer lock*/
  241. unsigned long buffer_share_bit;
  242. unsigned long buffer_unshare_reserve_bit;
  243. };
  244. struct fjes_hw {
  245. void *back;
  246. unsigned long txrx_stop_req_bit;
  247. unsigned long epstop_req_bit;
  248. struct work_struct update_zone_task;
  249. struct work_struct epstop_task;
  250. int my_epid;
  251. int max_epid;
  252. struct ep_share_mem_info *ep_shm_info;
  253. struct fjes_hw_resource {
  254. u64 start;
  255. u64 size;
  256. int irq;
  257. } hw_res;
  258. u8 *base;
  259. struct fjes_hw_info hw_info;
  260. spinlock_t rx_status_lock; /* spinlock for rx_status */
  261. u32 debug_mode;
  262. };
  263. int fjes_hw_init(struct fjes_hw *);
  264. void fjes_hw_exit(struct fjes_hw *);
  265. int fjes_hw_reset(struct fjes_hw *);
  266. int fjes_hw_request_info(struct fjes_hw *);
  267. int fjes_hw_register_buff_addr(struct fjes_hw *, int,
  268. struct ep_share_mem_info *);
  269. int fjes_hw_unregister_buff_addr(struct fjes_hw *, int);
  270. void fjes_hw_init_command_registers(struct fjes_hw *,
  271. struct fjes_device_command_param *);
  272. void fjes_hw_setup_epbuf(struct epbuf_handler *, u8 *, u32);
  273. int fjes_hw_raise_interrupt(struct fjes_hw *, int, enum REG_ICTL_MASK);
  274. void fjes_hw_set_irqmask(struct fjes_hw *, enum REG_ICTL_MASK, bool);
  275. u32 fjes_hw_capture_interrupt_status(struct fjes_hw *);
  276. void fjes_hw_raise_epstop(struct fjes_hw *);
  277. int fjes_hw_wait_epstop(struct fjes_hw *);
  278. enum ep_partner_status
  279. fjes_hw_get_partner_ep_status(struct fjes_hw *, int);
  280. bool fjes_hw_epid_is_same_zone(struct fjes_hw *, int);
  281. int fjes_hw_epid_is_shared(struct fjes_device_shared_info *, int);
  282. bool fjes_hw_check_epbuf_version(struct epbuf_handler *, u32);
  283. bool fjes_hw_check_mtu(struct epbuf_handler *, u32);
  284. bool fjes_hw_check_vlan_id(struct epbuf_handler *, u16);
  285. bool fjes_hw_set_vlan_id(struct epbuf_handler *, u16);
  286. void fjes_hw_del_vlan_id(struct epbuf_handler *, u16);
  287. bool fjes_hw_epbuf_rx_is_empty(struct epbuf_handler *);
  288. void *fjes_hw_epbuf_rx_curpkt_get_addr(struct epbuf_handler *, size_t *);
  289. void fjes_hw_epbuf_rx_curpkt_drop(struct epbuf_handler *);
  290. int fjes_hw_epbuf_tx_pkt_send(struct epbuf_handler *, void *, size_t);
  291. int fjes_hw_start_debug(struct fjes_hw *);
  292. int fjes_hw_stop_debug(struct fjes_hw *);
  293. #endif /* FJES_HW_H_ */