qed_sp.h 12 KB

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