qed_ll2.h 7.4 KB

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