qed_ll2.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. struct qed_ll2_rx_packet {
  47. struct list_head list_entry;
  48. struct core_rx_bd_with_buff_len *rxq_bd;
  49. dma_addr_t rx_buf_addr;
  50. u16 buf_length;
  51. void *cookie;
  52. u8 placement_offset;
  53. u16 parse_flags;
  54. u16 packet_length;
  55. u16 vlan;
  56. u32 opaque_data[2];
  57. };
  58. struct qed_ll2_tx_packet {
  59. struct list_head list_entry;
  60. u16 bd_used;
  61. u16 vlan;
  62. u16 l4_hdr_offset_w;
  63. u8 bd_flags;
  64. bool notify_fw;
  65. void *cookie;
  66. struct {
  67. struct core_tx_bd *txq_bd;
  68. dma_addr_t tx_frag;
  69. u16 frag_len;
  70. } bds_set[ETH_TX_MAX_BDS_PER_NON_LSO_PACKET];
  71. };
  72. struct qed_ll2_rx_queue {
  73. /* Lock protecting the Rx queue manipulation */
  74. spinlock_t lock;
  75. struct qed_chain rxq_chain;
  76. struct qed_chain rcq_chain;
  77. u8 rx_sb_index;
  78. bool b_cb_registred;
  79. __le16 *p_fw_cons;
  80. struct list_head active_descq;
  81. struct list_head free_descq;
  82. struct list_head posting_descq;
  83. struct qed_ll2_rx_packet *descq_array;
  84. void __iomem *set_prod_addr;
  85. };
  86. struct qed_ll2_tx_queue {
  87. /* Lock protecting the Tx queue manipulation */
  88. spinlock_t lock;
  89. struct qed_chain txq_chain;
  90. u8 tx_sb_index;
  91. bool b_cb_registred;
  92. __le16 *p_fw_cons;
  93. struct list_head active_descq;
  94. struct list_head free_descq;
  95. struct list_head sending_descq;
  96. struct qed_ll2_tx_packet *descq_array;
  97. struct qed_ll2_tx_packet *cur_send_packet;
  98. struct qed_ll2_tx_packet cur_completing_packet;
  99. u16 cur_completing_bd_idx;
  100. void __iomem *doorbell_addr;
  101. u16 bds_idx;
  102. u16 cur_send_frag_num;
  103. u16 cur_completing_frag_num;
  104. bool b_completing_packet;
  105. };
  106. struct qed_ll2_info {
  107. /* Lock protecting the state of LL2 */
  108. struct mutex mutex;
  109. struct qed_ll2_acquire_data_inputs input;
  110. u32 cid;
  111. u8 my_id;
  112. u8 queue_id;
  113. u8 tx_stats_id;
  114. bool b_active;
  115. enum core_tx_dest tx_dest;
  116. u8 tx_stats_en;
  117. struct qed_ll2_rx_queue rx_queue;
  118. struct qed_ll2_tx_queue tx_queue;
  119. struct qed_ll2_cbs cbs;
  120. };
  121. /**
  122. * @brief qed_ll2_acquire_connection - allocate resources,
  123. * starts rx & tx (if relevant) queues pair. Provides
  124. * connecion handler as output parameter.
  125. *
  126. *
  127. * @param cxt - pointer to the hw-function [opaque to some]
  128. * @param data - describes connection parameters
  129. * @return int
  130. */
  131. int qed_ll2_acquire_connection(void *cxt, struct qed_ll2_acquire_data *data);
  132. /**
  133. * @brief qed_ll2_establish_connection - start previously
  134. * allocated LL2 queues pair
  135. *
  136. * @param cxt - pointer to the hw-function [opaque to some]
  137. * @param p_ptt
  138. * @param connection_handle LL2 connection's handle obtained from
  139. * qed_ll2_require_connection
  140. *
  141. * @return 0 on success, failure otherwise
  142. */
  143. int qed_ll2_establish_connection(void *cxt, u8 connection_handle);
  144. /**
  145. * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue.
  146. *
  147. * @param cxt - pointer to the hw-function [opaque to some]
  148. * @param connection_handle LL2 connection's handle obtained from
  149. * qed_ll2_require_connection
  150. * @param addr rx (physical address) buffers to submit
  151. * @param cookie
  152. * @param notify_fw produce corresponding Rx BD immediately
  153. *
  154. * @return 0 on success, failure otherwise
  155. */
  156. int qed_ll2_post_rx_buffer(void *cxt,
  157. u8 connection_handle,
  158. dma_addr_t addr,
  159. u16 buf_len, void *cookie, u8 notify_fw);
  160. /**
  161. * @brief qed_ll2_prepare_tx_packet - request for start Tx BD
  162. * to prepare Tx packet submission to FW.
  163. *
  164. * @param cxt - pointer to the hw-function [opaque to some]
  165. * @param connection_handle
  166. * @param pkt - info regarding the tx packet
  167. * @param notify_fw - issue doorbell to fw for this packet
  168. *
  169. * @return 0 on success, failure otherwise
  170. */
  171. int qed_ll2_prepare_tx_packet(void *cxt,
  172. u8 connection_handle,
  173. struct qed_ll2_tx_pkt_info *pkt,
  174. bool notify_fw);
  175. /**
  176. * @brief qed_ll2_release_connection - releases resources
  177. * allocated for LL2 connection
  178. *
  179. * @param cxt - pointer to the hw-function [opaque to some]
  180. * @param connection_handle LL2 connection's handle obtained from
  181. * qed_ll2_require_connection
  182. */
  183. void qed_ll2_release_connection(void *cxt, u8 connection_handle);
  184. /**
  185. * @brief qed_ll2_set_fragment_of_tx_packet - provides fragments to fill
  186. * Tx BD of BDs requested by
  187. * qed_ll2_prepare_tx_packet
  188. *
  189. * @param cxt - pointer to the hw-function [opaque to some]
  190. * @param connection_handle LL2 connection's handle
  191. * obtained from
  192. * qed_ll2_require_connection
  193. * @param addr
  194. * @param nbytes
  195. *
  196. * @return 0 on success, failure otherwise
  197. */
  198. int qed_ll2_set_fragment_of_tx_packet(void *cxt,
  199. u8 connection_handle,
  200. dma_addr_t addr, u16 nbytes);
  201. /**
  202. * @brief qed_ll2_terminate_connection - stops Tx/Rx queues
  203. *
  204. *
  205. * @param cxt - pointer to the hw-function [opaque to some]
  206. * @param connection_handle LL2 connection's handle
  207. * obtained from
  208. * qed_ll2_require_connection
  209. *
  210. * @return 0 on success, failure otherwise
  211. */
  212. int qed_ll2_terminate_connection(void *cxt, u8 connection_handle);
  213. /**
  214. * @brief qed_ll2_get_stats - get LL2 queue's statistics
  215. *
  216. *
  217. * @param cxt - pointer to the hw-function [opaque to some]
  218. * @param connection_handle LL2 connection's handle obtained from
  219. * qed_ll2_require_connection
  220. * @param p_stats
  221. *
  222. * @return 0 on success, failure otherwise
  223. */
  224. int qed_ll2_get_stats(void *cxt,
  225. u8 connection_handle, struct qed_ll2_stats *p_stats);
  226. /**
  227. * @brief qed_ll2_alloc - Allocates LL2 connections set
  228. *
  229. * @param p_hwfn
  230. *
  231. * @return int
  232. */
  233. int qed_ll2_alloc(struct qed_hwfn *p_hwfn);
  234. /**
  235. * @brief qed_ll2_setup - Inits LL2 connections set
  236. *
  237. * @param p_hwfn
  238. *
  239. */
  240. void qed_ll2_setup(struct qed_hwfn *p_hwfn);
  241. /**
  242. * @brief qed_ll2_free - Releases LL2 connections set
  243. *
  244. * @param p_hwfn
  245. *
  246. */
  247. void qed_ll2_free(struct qed_hwfn *p_hwfn);
  248. #endif