qed_sp.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015 QLogic Corporation
  3. *
  4. * This software is available under the terms of the GNU General Public License
  5. * (GPL) Version 2, available from the file COPYING in the main directory of
  6. * this source tree.
  7. */
  8. #ifndef _QED_SP_H
  9. #define _QED_SP_H
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/list.h>
  13. #include <linux/slab.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/qed/qed_chain.h>
  16. #include "qed.h"
  17. #include "qed_hsi.h"
  18. enum spq_mode {
  19. QED_SPQ_MODE_BLOCK, /* Client will poll a designated mem. address */
  20. QED_SPQ_MODE_CB, /* Client supplies a callback */
  21. QED_SPQ_MODE_EBLOCK, /* QED should block until completion */
  22. };
  23. struct qed_spq_comp_cb {
  24. void (*function)(struct qed_hwfn *,
  25. void *,
  26. union event_ring_data *,
  27. u8 fw_return_code);
  28. void *cookie;
  29. };
  30. /**
  31. * @brief qed_eth_cqe_completion - handles the completion of a
  32. * ramrod on the cqe ring
  33. *
  34. * @param p_hwfn
  35. * @param cqe
  36. *
  37. * @return int
  38. */
  39. int qed_eth_cqe_completion(struct qed_hwfn *p_hwfn,
  40. struct eth_slow_path_rx_cqe *cqe);
  41. /**
  42. * @file
  43. *
  44. * QED Slow-hwfn queue interface
  45. */
  46. union ramrod_data {
  47. struct pf_start_ramrod_data pf_start;
  48. struct pf_update_ramrod_data pf_update;
  49. struct rx_queue_start_ramrod_data rx_queue_start;
  50. struct rx_queue_update_ramrod_data rx_queue_update;
  51. struct rx_queue_stop_ramrod_data rx_queue_stop;
  52. struct tx_queue_start_ramrod_data tx_queue_start;
  53. struct tx_queue_stop_ramrod_data tx_queue_stop;
  54. struct vport_start_ramrod_data vport_start;
  55. struct vport_stop_ramrod_data vport_stop;
  56. struct vport_update_ramrod_data vport_update;
  57. struct vport_filter_update_ramrod_data vport_filter_update;
  58. struct rdma_init_func_ramrod_data rdma_init_func;
  59. struct rdma_close_func_ramrod_data rdma_close_func;
  60. struct rdma_register_tid_ramrod_data rdma_register_tid;
  61. struct rdma_deregister_tid_ramrod_data rdma_deregister_tid;
  62. struct roce_create_qp_resp_ramrod_data roce_create_qp_resp;
  63. struct roce_create_qp_req_ramrod_data roce_create_qp_req;
  64. struct roce_modify_qp_resp_ramrod_data roce_modify_qp_resp;
  65. struct roce_modify_qp_req_ramrod_data roce_modify_qp_req;
  66. struct roce_query_qp_resp_ramrod_data roce_query_qp_resp;
  67. struct roce_query_qp_req_ramrod_data roce_query_qp_req;
  68. struct roce_destroy_qp_resp_ramrod_data roce_destroy_qp_resp;
  69. struct roce_destroy_qp_req_ramrod_data roce_destroy_qp_req;
  70. struct rdma_create_cq_ramrod_data rdma_create_cq;
  71. struct rdma_resize_cq_ramrod_data rdma_resize_cq;
  72. struct rdma_destroy_cq_ramrod_data rdma_destroy_cq;
  73. struct rdma_srq_create_ramrod_data rdma_create_srq;
  74. struct rdma_srq_destroy_ramrod_data rdma_destroy_srq;
  75. struct rdma_srq_modify_ramrod_data rdma_modify_srq;
  76. struct iscsi_slow_path_hdr iscsi_empty;
  77. struct iscsi_init_ramrod_params iscsi_init;
  78. struct iscsi_spe_func_dstry iscsi_destroy;
  79. struct iscsi_spe_conn_offload iscsi_conn_offload;
  80. struct iscsi_conn_update_ramrod_params iscsi_conn_update;
  81. struct iscsi_spe_conn_termination iscsi_conn_terminate;
  82. struct vf_start_ramrod_data vf_start;
  83. struct vf_stop_ramrod_data vf_stop;
  84. };
  85. #define EQ_MAX_CREDIT 0xffffffff
  86. enum spq_priority {
  87. QED_SPQ_PRIORITY_NORMAL,
  88. QED_SPQ_PRIORITY_HIGH,
  89. };
  90. union qed_spq_req_comp {
  91. struct qed_spq_comp_cb cb;
  92. u64 *done_addr;
  93. };
  94. struct qed_spq_comp_done {
  95. u64 done;
  96. u8 fw_return_code;
  97. };
  98. struct qed_spq_entry {
  99. struct list_head list;
  100. u8 flags;
  101. /* HSI slow path element */
  102. struct slow_path_element elem;
  103. union ramrod_data ramrod;
  104. enum spq_priority priority;
  105. /* pending queue for this entry */
  106. struct list_head *queue;
  107. enum spq_mode comp_mode;
  108. struct qed_spq_comp_cb comp_cb;
  109. struct qed_spq_comp_done comp_done; /* SPQ_MODE_EBLOCK */
  110. };
  111. struct qed_eq {
  112. struct qed_chain chain;
  113. u8 eq_sb_index; /* index within the SB */
  114. __le16 *p_fw_cons; /* ptr to index value */
  115. };
  116. struct qed_consq {
  117. struct qed_chain chain;
  118. };
  119. struct qed_spq {
  120. spinlock_t lock; /* SPQ lock */
  121. struct list_head unlimited_pending;
  122. struct list_head pending;
  123. struct list_head completion_pending;
  124. struct list_head free_pool;
  125. struct qed_chain chain;
  126. /* allocated dma-able memory for spq entries (+ramrod data) */
  127. dma_addr_t p_phys;
  128. struct qed_spq_entry *p_virt;
  129. #define SPQ_RING_SIZE \
  130. (CORE_SPQE_PAGE_SIZE_BYTES / sizeof(struct slow_path_element))
  131. /* Bitmap for handling out-of-order completions */
  132. DECLARE_BITMAP(p_comp_bitmap, SPQ_RING_SIZE);
  133. u8 comp_bitmap_idx;
  134. /* Statistics */
  135. u32 unlimited_pending_count;
  136. u32 normal_count;
  137. u32 high_count;
  138. u32 comp_sent_count;
  139. u32 comp_count;
  140. u32 cid;
  141. };
  142. /**
  143. * @brief qed_spq_post - Posts a Slow hwfn request to FW, or lacking that
  144. * Pends it to the future list.
  145. *
  146. * @param p_hwfn
  147. * @param p_req
  148. *
  149. * @return int
  150. */
  151. int qed_spq_post(struct qed_hwfn *p_hwfn,
  152. struct qed_spq_entry *p_ent,
  153. u8 *fw_return_code);
  154. /**
  155. * @brief qed_spq_allocate - Alloocates & initializes the SPQ and EQ.
  156. *
  157. * @param p_hwfn
  158. *
  159. * @return int
  160. */
  161. int qed_spq_alloc(struct qed_hwfn *p_hwfn);
  162. /**
  163. * @brief qed_spq_setup - Reset the SPQ to its start state.
  164. *
  165. * @param p_hwfn
  166. */
  167. void qed_spq_setup(struct qed_hwfn *p_hwfn);
  168. /**
  169. * @brief qed_spq_deallocate - Deallocates the given SPQ struct.
  170. *
  171. * @param p_hwfn
  172. */
  173. void qed_spq_free(struct qed_hwfn *p_hwfn);
  174. /**
  175. * @brief qed_spq_get_entry - Obtain an entrry from the spq
  176. * free pool list.
  177. *
  178. *
  179. *
  180. * @param p_hwfn
  181. * @param pp_ent
  182. *
  183. * @return int
  184. */
  185. int
  186. qed_spq_get_entry(struct qed_hwfn *p_hwfn,
  187. struct qed_spq_entry **pp_ent);
  188. /**
  189. * @brief qed_spq_return_entry - Return an entry to spq free
  190. * pool list
  191. *
  192. * @param p_hwfn
  193. * @param p_ent
  194. */
  195. void qed_spq_return_entry(struct qed_hwfn *p_hwfn,
  196. struct qed_spq_entry *p_ent);
  197. /**
  198. * @brief qed_eq_allocate - Allocates & initializes an EQ struct
  199. *
  200. * @param p_hwfn
  201. * @param num_elem number of elements in the eq
  202. *
  203. * @return struct qed_eq* - a newly allocated structure; NULL upon error.
  204. */
  205. struct qed_eq *qed_eq_alloc(struct qed_hwfn *p_hwfn,
  206. u16 num_elem);
  207. /**
  208. * @brief qed_eq_setup - Reset the SPQ to its start state.
  209. *
  210. * @param p_hwfn
  211. * @param p_eq
  212. */
  213. void qed_eq_setup(struct qed_hwfn *p_hwfn,
  214. struct qed_eq *p_eq);
  215. /**
  216. * @brief qed_eq_deallocate - deallocates the given EQ struct.
  217. *
  218. * @param p_hwfn
  219. * @param p_eq
  220. */
  221. void qed_eq_free(struct qed_hwfn *p_hwfn,
  222. struct qed_eq *p_eq);
  223. /**
  224. * @brief qed_eq_prod_update - update the FW with default EQ producer
  225. *
  226. * @param p_hwfn
  227. * @param prod
  228. */
  229. void qed_eq_prod_update(struct qed_hwfn *p_hwfn,
  230. u16 prod);
  231. /**
  232. * @brief qed_eq_completion - Completes currently pending EQ elements
  233. *
  234. * @param p_hwfn
  235. * @param cookie
  236. *
  237. * @return int
  238. */
  239. int qed_eq_completion(struct qed_hwfn *p_hwfn,
  240. void *cookie);
  241. /**
  242. * @brief qed_spq_completion - Completes a single event
  243. *
  244. * @param p_hwfn
  245. * @param echo - echo value from cookie (used for determining completion)
  246. * @param p_data - data from cookie (used in callback function if applicable)
  247. *
  248. * @return int
  249. */
  250. int qed_spq_completion(struct qed_hwfn *p_hwfn,
  251. __le16 echo,
  252. u8 fw_return_code,
  253. union event_ring_data *p_data);
  254. /**
  255. * @brief qed_spq_get_cid - Given p_hwfn, return cid for the hwfn's SPQ
  256. *
  257. * @param p_hwfn
  258. *
  259. * @return u32 - SPQ CID
  260. */
  261. u32 qed_spq_get_cid(struct qed_hwfn *p_hwfn);
  262. /**
  263. * @brief qed_consq_alloc - Allocates & initializes an ConsQ
  264. * struct
  265. *
  266. * @param p_hwfn
  267. *
  268. * @return struct qed_eq* - a newly allocated structure; NULL upon error.
  269. */
  270. struct qed_consq *qed_consq_alloc(struct qed_hwfn *p_hwfn);
  271. /**
  272. * @brief qed_consq_setup - Reset the ConsQ to its start
  273. * state.
  274. *
  275. * @param p_hwfn
  276. * @param p_eq
  277. */
  278. void qed_consq_setup(struct qed_hwfn *p_hwfn,
  279. struct qed_consq *p_consq);
  280. /**
  281. * @brief qed_consq_free - deallocates the given ConsQ struct.
  282. *
  283. * @param p_hwfn
  284. * @param p_eq
  285. */
  286. void qed_consq_free(struct qed_hwfn *p_hwfn,
  287. struct qed_consq *p_consq);
  288. /**
  289. * @file
  290. *
  291. * @brief Slow-hwfn low-level commands (Ramrods) function definitions.
  292. */
  293. #define QED_SP_EQ_COMPLETION 0x01
  294. #define QED_SP_CQE_COMPLETION 0x02
  295. struct qed_sp_init_data {
  296. u32 cid;
  297. u16 opaque_fid;
  298. /* Information regarding operation upon sending & completion */
  299. enum spq_mode comp_mode;
  300. struct qed_spq_comp_cb *p_comp_data;
  301. };
  302. int qed_sp_init_request(struct qed_hwfn *p_hwfn,
  303. struct qed_spq_entry **pp_ent,
  304. u8 cmd,
  305. u8 protocol,
  306. struct qed_sp_init_data *p_data);
  307. /**
  308. * @brief qed_sp_pf_start - PF Function Start Ramrod
  309. *
  310. * This ramrod is sent to initialize a physical function (PF). It will
  311. * configure the function related parameters and write its completion to the
  312. * event ring specified in the parameters.
  313. *
  314. * Ramrods complete on the common event ring for the PF. This ring is
  315. * allocated by the driver on host memory and its parameters are written
  316. * to the internal RAM of the UStorm by the Function Start Ramrod.
  317. *
  318. * @param p_hwfn
  319. * @param p_tunn
  320. * @param mode
  321. * @param allow_npar_tx_switch
  322. *
  323. * @return int
  324. */
  325. int qed_sp_pf_start(struct qed_hwfn *p_hwfn,
  326. struct qed_tunn_start_params *p_tunn,
  327. enum qed_mf_mode mode, bool allow_npar_tx_switch);
  328. /**
  329. * @brief qed_sp_pf_update - PF Function Update Ramrod
  330. *
  331. * This ramrod updates function-related parameters. Every parameter can be
  332. * updated independently, according to configuration flags.
  333. *
  334. * @param p_hwfn
  335. *
  336. * @return int
  337. */
  338. int qed_sp_pf_update(struct qed_hwfn *p_hwfn);
  339. /**
  340. * @brief qed_sp_pf_stop - PF Function Stop Ramrod
  341. *
  342. * This ramrod is sent to close a Physical Function (PF). It is the last ramrod
  343. * sent and the last completion written to the PFs Event Ring. This ramrod also
  344. * deletes the context for the Slowhwfn connection on this PF.
  345. *
  346. * @note Not required for first packet.
  347. *
  348. * @param p_hwfn
  349. *
  350. * @return int
  351. */
  352. int qed_sp_pf_stop(struct qed_hwfn *p_hwfn);
  353. int qed_sp_pf_update_tunn_cfg(struct qed_hwfn *p_hwfn,
  354. struct qed_tunn_update_params *p_tunn,
  355. enum spq_mode comp_mode,
  356. struct qed_spq_comp_cb *p_comp_data);
  357. /**
  358. * @brief qed_sp_heartbeat_ramrod - Send empty Ramrod
  359. *
  360. * @param p_hwfn
  361. *
  362. * @return int
  363. */
  364. int qed_sp_heartbeat_ramrod(struct qed_hwfn *p_hwfn);
  365. #endif