qed_ll2.h 8.9 KB

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