fjes_hw.h 8.1 KB

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