fjes_hw.h 9.0 KB

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