qed_ll2.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /* QLogic qed NIC Driver
  2. *
  3. * Copyright (c) 2015 QLogic Corporation
  4. *
  5. * This software is available under the terms of the GNU General Public License
  6. * (GPL) Version 2, available from the file COPYING in the main directory of
  7. * this source tree.
  8. */
  9. #ifndef _QED_LL2_H
  10. #define _QED_LL2_H
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/list.h>
  14. #include <linux/mutex.h>
  15. #include <linux/slab.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/qed/qed_chain.h>
  18. #include <linux/qed/qed_ll2_if.h>
  19. #include "qed.h"
  20. #include "qed_hsi.h"
  21. #include "qed_sp.h"
  22. #define QED_MAX_NUM_OF_LL2_CONNECTIONS (4)
  23. enum qed_ll2_roce_flavor_type {
  24. QED_LL2_ROCE,
  25. QED_LL2_RROCE,
  26. MAX_QED_LL2_ROCE_FLAVOR_TYPE
  27. };
  28. enum qed_ll2_conn_type {
  29. QED_LL2_TYPE_RESERVED,
  30. QED_LL2_TYPE_ISCSI,
  31. QED_LL2_TYPE_TEST,
  32. QED_LL2_TYPE_ISCSI_OOO,
  33. QED_LL2_TYPE_RESERVED2,
  34. QED_LL2_TYPE_ROCE,
  35. QED_LL2_TYPE_RESERVED3,
  36. MAX_QED_LL2_RX_CONN_TYPE
  37. };
  38. enum qed_ll2_tx_dest {
  39. QED_LL2_TX_DEST_NW, /* Light L2 TX Destination to the Network */
  40. QED_LL2_TX_DEST_LB, /* Light L2 TX Destination to the Loopback */
  41. QED_LL2_TX_DEST_MAX
  42. };
  43. struct qed_ll2_rx_packet {
  44. struct list_head list_entry;
  45. struct core_rx_bd_with_buff_len *rxq_bd;
  46. dma_addr_t rx_buf_addr;
  47. u16 buf_length;
  48. void *cookie;
  49. u8 placement_offset;
  50. u16 parse_flags;
  51. u16 packet_length;
  52. u16 vlan;
  53. u32 opaque_data[2];
  54. };
  55. struct qed_ll2_tx_packet {
  56. struct list_head list_entry;
  57. u16 bd_used;
  58. u16 vlan;
  59. u16 l4_hdr_offset_w;
  60. u8 bd_flags;
  61. bool notify_fw;
  62. void *cookie;
  63. struct {
  64. struct core_tx_bd *txq_bd;
  65. dma_addr_t tx_frag;
  66. u16 frag_len;
  67. } bds_set[ETH_TX_MAX_BDS_PER_NON_LSO_PACKET];
  68. };
  69. struct qed_ll2_rx_queue {
  70. /* Lock protecting the Rx queue manipulation */
  71. spinlock_t lock;
  72. struct qed_chain rxq_chain;
  73. struct qed_chain rcq_chain;
  74. u8 rx_sb_index;
  75. bool b_cb_registred;
  76. __le16 *p_fw_cons;
  77. struct list_head active_descq;
  78. struct list_head free_descq;
  79. struct list_head posting_descq;
  80. struct qed_ll2_rx_packet *descq_array;
  81. void __iomem *set_prod_addr;
  82. };
  83. struct qed_ll2_tx_queue {
  84. /* Lock protecting the Tx queue manipulation */
  85. spinlock_t lock;
  86. struct qed_chain txq_chain;
  87. u8 tx_sb_index;
  88. bool b_cb_registred;
  89. __le16 *p_fw_cons;
  90. struct list_head active_descq;
  91. struct list_head free_descq;
  92. struct list_head sending_descq;
  93. struct qed_ll2_tx_packet *descq_array;
  94. struct qed_ll2_tx_packet *cur_send_packet;
  95. struct qed_ll2_tx_packet cur_completing_packet;
  96. u16 cur_completing_bd_idx;
  97. void __iomem *doorbell_addr;
  98. u16 bds_idx;
  99. u16 cur_send_frag_num;
  100. u16 cur_completing_frag_num;
  101. bool b_completing_packet;
  102. };
  103. struct qed_ll2_info {
  104. /* Lock protecting the state of LL2 */
  105. struct mutex mutex;
  106. enum qed_ll2_conn_type conn_type;
  107. u32 cid;
  108. u8 my_id;
  109. u8 queue_id;
  110. u8 tx_stats_id;
  111. bool b_active;
  112. u16 mtu;
  113. u8 rx_drop_ttl0_flg;
  114. u8 rx_vlan_removal_en;
  115. u8 tx_tc;
  116. enum core_tx_dest tx_dest;
  117. enum core_error_handle ai_err_packet_too_big;
  118. enum core_error_handle ai_err_no_buf;
  119. u8 tx_stats_en;
  120. struct qed_ll2_rx_queue rx_queue;
  121. struct qed_ll2_tx_queue tx_queue;
  122. u8 gsi_enable;
  123. };
  124. /**
  125. * @brief qed_ll2_acquire_connection - allocate resources,
  126. * starts rx & tx (if relevant) queues pair. Provides
  127. * connecion handler as output parameter.
  128. *
  129. * @param p_hwfn
  130. * @param p_params Contain various configuration properties
  131. * @param rx_num_desc
  132. * @param tx_num_desc
  133. *
  134. * @param p_connection_handle Output container for LL2 connection's handle
  135. *
  136. * @return 0 on success, failure otherwise
  137. */
  138. int qed_ll2_acquire_connection(struct qed_hwfn *p_hwfn,
  139. struct qed_ll2_info *p_params,
  140. u16 rx_num_desc,
  141. u16 tx_num_desc,
  142. u8 *p_connection_handle);
  143. /**
  144. * @brief qed_ll2_establish_connection - start previously
  145. * allocated LL2 queues pair
  146. *
  147. * @param p_hwfn
  148. * @param p_ptt
  149. * @param connection_handle LL2 connection's handle obtained from
  150. * qed_ll2_require_connection
  151. *
  152. * @return 0 on success, failure otherwise
  153. */
  154. int qed_ll2_establish_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
  155. /**
  156. * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue.
  157. *
  158. * @param p_hwfn
  159. * @param connection_handle LL2 connection's handle obtained from
  160. * qed_ll2_require_connection
  161. * @param addr rx (physical address) buffers to submit
  162. * @param cookie
  163. * @param notify_fw produce corresponding Rx BD immediately
  164. *
  165. * @return 0 on success, failure otherwise
  166. */
  167. int qed_ll2_post_rx_buffer(struct qed_hwfn *p_hwfn,
  168. u8 connection_handle,
  169. dma_addr_t addr,
  170. u16 buf_len, void *cookie, u8 notify_fw);
  171. /**
  172. * @brief qed_ll2_prepare_tx_packet - request for start Tx BD
  173. * to prepare Tx packet submission to FW.
  174. *
  175. * @param p_hwfn
  176. * @param connection_handle LL2 connection's handle obtained from
  177. * qed_ll2_require_connection
  178. * @param num_of_bds a number of requested BD equals a number of
  179. * fragments in Tx packet
  180. * @param vlan VLAN to insert to packet (if insertion set)
  181. * @param bd_flags
  182. * @param l4_hdr_offset_w L4 Header Offset from start of packet
  183. * (in words). This is needed if both l4_csum
  184. * and ipv6_ext are set
  185. * @param e_tx_dest indicates if the packet is to be transmitted via
  186. * loopback or to the network
  187. * @param first_frag
  188. * @param first_frag_len
  189. * @param cookie
  190. *
  191. * @param notify_fw
  192. *
  193. * @return 0 on success, failure otherwise
  194. */
  195. int qed_ll2_prepare_tx_packet(struct qed_hwfn *p_hwfn,
  196. u8 connection_handle,
  197. u8 num_of_bds,
  198. u16 vlan,
  199. u8 bd_flags,
  200. u16 l4_hdr_offset_w,
  201. enum qed_ll2_tx_dest e_tx_dest,
  202. enum qed_ll2_roce_flavor_type qed_roce_flavor,
  203. dma_addr_t first_frag,
  204. u16 first_frag_len, void *cookie, u8 notify_fw);
  205. /**
  206. * @brief qed_ll2_release_connection - releases resources
  207. * allocated for LL2 connection
  208. *
  209. * @param p_hwfn
  210. * @param connection_handle LL2 connection's handle obtained from
  211. * qed_ll2_require_connection
  212. */
  213. void qed_ll2_release_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
  214. /**
  215. * @brief qed_ll2_set_fragment_of_tx_packet - provides fragments to fill
  216. * Tx BD of BDs requested by
  217. * qed_ll2_prepare_tx_packet
  218. *
  219. * @param p_hwfn
  220. * @param connection_handle LL2 connection's handle
  221. * obtained from
  222. * qed_ll2_require_connection
  223. * @param addr
  224. * @param nbytes
  225. *
  226. * @return 0 on success, failure otherwise
  227. */
  228. int qed_ll2_set_fragment_of_tx_packet(struct qed_hwfn *p_hwfn,
  229. u8 connection_handle,
  230. dma_addr_t addr, u16 nbytes);
  231. /**
  232. * @brief qed_ll2_terminate_connection - stops Tx/Rx queues
  233. *
  234. *
  235. * @param p_hwfn
  236. * @param connection_handle LL2 connection's handle
  237. * obtained from
  238. * qed_ll2_require_connection
  239. *
  240. * @return 0 on success, failure otherwise
  241. */
  242. int qed_ll2_terminate_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
  243. /**
  244. * @brief qed_ll2_get_stats - get LL2 queue's statistics
  245. *
  246. *
  247. * @param p_hwfn
  248. * @param connection_handle LL2 connection's handle obtained from
  249. * qed_ll2_require_connection
  250. * @param p_stats
  251. *
  252. * @return 0 on success, failure otherwise
  253. */
  254. int qed_ll2_get_stats(struct qed_hwfn *p_hwfn,
  255. u8 connection_handle, struct qed_ll2_stats *p_stats);
  256. /**
  257. * @brief qed_ll2_alloc - Allocates LL2 connections set
  258. *
  259. * @param p_hwfn
  260. *
  261. * @return pointer to alocated qed_ll2_info or NULL
  262. */
  263. struct qed_ll2_info *qed_ll2_alloc(struct qed_hwfn *p_hwfn);
  264. /**
  265. * @brief qed_ll2_setup - Inits LL2 connections set
  266. *
  267. * @param p_hwfn
  268. * @param p_ll2_connections
  269. *
  270. */
  271. void qed_ll2_setup(struct qed_hwfn *p_hwfn,
  272. struct qed_ll2_info *p_ll2_connections);
  273. /**
  274. * @brief qed_ll2_free - Releases LL2 connections set
  275. *
  276. * @param p_hwfn
  277. * @param p_ll2_connections
  278. *
  279. */
  280. void qed_ll2_free(struct qed_hwfn *p_hwfn,
  281. struct qed_ll2_info *p_ll2_connections);
  282. #endif