qed_sp.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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 rx_update_gft_filter_data rx_update_gft;
  81. struct vport_update_ramrod_data vport_update;
  82. struct core_rx_start_ramrod_data core_rx_queue_start;
  83. struct core_rx_stop_ramrod_data core_rx_queue_stop;
  84. struct core_tx_start_ramrod_data core_tx_queue_start;
  85. struct core_tx_stop_ramrod_data core_tx_queue_stop;
  86. struct vport_filter_update_ramrod_data vport_filter_update;
  87. struct rdma_init_func_ramrod_data rdma_init_func;
  88. struct rdma_close_func_ramrod_data rdma_close_func;
  89. struct rdma_register_tid_ramrod_data rdma_register_tid;
  90. struct rdma_deregister_tid_ramrod_data rdma_deregister_tid;
  91. struct roce_create_qp_resp_ramrod_data roce_create_qp_resp;
  92. struct roce_create_qp_req_ramrod_data roce_create_qp_req;
  93. struct roce_modify_qp_resp_ramrod_data roce_modify_qp_resp;
  94. struct roce_modify_qp_req_ramrod_data roce_modify_qp_req;
  95. struct roce_query_qp_resp_ramrod_data roce_query_qp_resp;
  96. struct roce_query_qp_req_ramrod_data roce_query_qp_req;
  97. struct roce_destroy_qp_resp_ramrod_data roce_destroy_qp_resp;
  98. struct roce_destroy_qp_req_ramrod_data roce_destroy_qp_req;
  99. struct roce_init_func_ramrod_data roce_init_func;
  100. struct rdma_create_cq_ramrod_data rdma_create_cq;
  101. struct rdma_destroy_cq_ramrod_data rdma_destroy_cq;
  102. struct rdma_srq_create_ramrod_data rdma_create_srq;
  103. struct rdma_srq_destroy_ramrod_data rdma_destroy_srq;
  104. struct rdma_srq_modify_ramrod_data rdma_modify_srq;
  105. struct iwarp_create_qp_ramrod_data iwarp_create_qp;
  106. struct iwarp_tcp_offload_ramrod_data iwarp_tcp_offload;
  107. struct iwarp_mpa_offload_ramrod_data iwarp_mpa_offload;
  108. struct iwarp_modify_qp_ramrod_data iwarp_modify_qp;
  109. struct iwarp_init_func_ramrod_data iwarp_init_func;
  110. struct fcoe_init_ramrod_params fcoe_init;
  111. struct fcoe_conn_offload_ramrod_params fcoe_conn_ofld;
  112. struct fcoe_conn_terminate_ramrod_params fcoe_conn_terminate;
  113. struct fcoe_stat_ramrod_params fcoe_stat;
  114. struct iscsi_slow_path_hdr iscsi_empty;
  115. struct iscsi_init_ramrod_params iscsi_init;
  116. struct iscsi_spe_func_dstry iscsi_destroy;
  117. struct iscsi_spe_conn_offload iscsi_conn_offload;
  118. struct iscsi_conn_update_ramrod_params iscsi_conn_update;
  119. struct iscsi_spe_conn_mac_update iscsi_conn_mac_update;
  120. struct iscsi_spe_conn_termination iscsi_conn_terminate;
  121. struct vf_start_ramrod_data vf_start;
  122. struct vf_stop_ramrod_data vf_stop;
  123. };
  124. #define EQ_MAX_CREDIT 0xffffffff
  125. enum spq_priority {
  126. QED_SPQ_PRIORITY_NORMAL,
  127. QED_SPQ_PRIORITY_HIGH,
  128. };
  129. union qed_spq_req_comp {
  130. struct qed_spq_comp_cb cb;
  131. u64 *done_addr;
  132. };
  133. struct qed_spq_comp_done {
  134. unsigned int done;
  135. u8 fw_return_code;
  136. };
  137. struct qed_spq_entry {
  138. struct list_head list;
  139. u8 flags;
  140. /* HSI slow path element */
  141. struct slow_path_element elem;
  142. union ramrod_data ramrod;
  143. enum spq_priority priority;
  144. /* pending queue for this entry */
  145. struct list_head *queue;
  146. enum spq_mode comp_mode;
  147. struct qed_spq_comp_cb comp_cb;
  148. struct qed_spq_comp_done comp_done; /* SPQ_MODE_EBLOCK */
  149. };
  150. struct qed_eq {
  151. struct qed_chain chain;
  152. u8 eq_sb_index; /* index within the SB */
  153. __le16 *p_fw_cons; /* ptr to index value */
  154. };
  155. struct qed_consq {
  156. struct qed_chain chain;
  157. };
  158. typedef int
  159. (*qed_spq_async_comp_cb)(struct qed_hwfn *p_hwfn,
  160. u8 opcode,
  161. u16 echo,
  162. union event_ring_data *data,
  163. u8 fw_return_code);
  164. int
  165. qed_spq_register_async_cb(struct qed_hwfn *p_hwfn,
  166. enum protocol_type protocol_id,
  167. qed_spq_async_comp_cb cb);
  168. void
  169. qed_spq_unregister_async_cb(struct qed_hwfn *p_hwfn,
  170. enum protocol_type protocol_id);
  171. struct qed_spq {
  172. spinlock_t lock; /* SPQ lock */
  173. struct list_head unlimited_pending;
  174. struct list_head pending;
  175. struct list_head completion_pending;
  176. struct list_head free_pool;
  177. struct qed_chain chain;
  178. /* allocated dma-able memory for spq entries (+ramrod data) */
  179. dma_addr_t p_phys;
  180. struct qed_spq_entry *p_virt;
  181. #define SPQ_RING_SIZE \
  182. (CORE_SPQE_PAGE_SIZE_BYTES / sizeof(struct slow_path_element))
  183. /* Bitmap for handling out-of-order completions */
  184. DECLARE_BITMAP(p_comp_bitmap, SPQ_RING_SIZE);
  185. u8 comp_bitmap_idx;
  186. /* Statistics */
  187. u32 unlimited_pending_count;
  188. u32 normal_count;
  189. u32 high_count;
  190. u32 comp_sent_count;
  191. u32 comp_count;
  192. u32 cid;
  193. qed_spq_async_comp_cb async_comp_cb[MAX_PROTOCOL_TYPE];
  194. };
  195. /**
  196. * @brief qed_spq_post - Posts a Slow hwfn request to FW, or lacking that
  197. * Pends it to the future list.
  198. *
  199. * @param p_hwfn
  200. * @param p_req
  201. *
  202. * @return int
  203. */
  204. int qed_spq_post(struct qed_hwfn *p_hwfn,
  205. struct qed_spq_entry *p_ent,
  206. u8 *fw_return_code);
  207. /**
  208. * @brief qed_spq_allocate - Alloocates & initializes the SPQ and EQ.
  209. *
  210. * @param p_hwfn
  211. *
  212. * @return int
  213. */
  214. int qed_spq_alloc(struct qed_hwfn *p_hwfn);
  215. /**
  216. * @brief qed_spq_setup - Reset the SPQ to its start state.
  217. *
  218. * @param p_hwfn
  219. */
  220. void qed_spq_setup(struct qed_hwfn *p_hwfn);
  221. /**
  222. * @brief qed_spq_deallocate - Deallocates the given SPQ struct.
  223. *
  224. * @param p_hwfn
  225. */
  226. void qed_spq_free(struct qed_hwfn *p_hwfn);
  227. /**
  228. * @brief qed_spq_get_entry - Obtain an entrry from the spq
  229. * free pool list.
  230. *
  231. *
  232. *
  233. * @param p_hwfn
  234. * @param pp_ent
  235. *
  236. * @return int
  237. */
  238. int
  239. qed_spq_get_entry(struct qed_hwfn *p_hwfn,
  240. struct qed_spq_entry **pp_ent);
  241. /**
  242. * @brief qed_spq_return_entry - Return an entry to spq free
  243. * pool list
  244. *
  245. * @param p_hwfn
  246. * @param p_ent
  247. */
  248. void qed_spq_return_entry(struct qed_hwfn *p_hwfn,
  249. struct qed_spq_entry *p_ent);
  250. /**
  251. * @brief qed_eq_allocate - Allocates & initializes an EQ struct
  252. *
  253. * @param p_hwfn
  254. * @param num_elem number of elements in the eq
  255. *
  256. * @return int
  257. */
  258. int qed_eq_alloc(struct qed_hwfn *p_hwfn, u16 num_elem);
  259. /**
  260. * @brief qed_eq_setup - Reset the EQ to its start state.
  261. *
  262. * @param p_hwfn
  263. */
  264. void qed_eq_setup(struct qed_hwfn *p_hwfn);
  265. /**
  266. * @brief qed_eq_free - deallocates the given EQ struct.
  267. *
  268. * @param p_hwfn
  269. */
  270. void qed_eq_free(struct qed_hwfn *p_hwfn);
  271. /**
  272. * @brief qed_eq_prod_update - update the FW with default EQ producer
  273. *
  274. * @param p_hwfn
  275. * @param prod
  276. */
  277. void qed_eq_prod_update(struct qed_hwfn *p_hwfn,
  278. u16 prod);
  279. /**
  280. * @brief qed_eq_completion - Completes currently pending EQ elements
  281. *
  282. * @param p_hwfn
  283. * @param cookie
  284. *
  285. * @return int
  286. */
  287. int qed_eq_completion(struct qed_hwfn *p_hwfn,
  288. void *cookie);
  289. /**
  290. * @brief qed_spq_completion - Completes a single event
  291. *
  292. * @param p_hwfn
  293. * @param echo - echo value from cookie (used for determining completion)
  294. * @param p_data - data from cookie (used in callback function if applicable)
  295. *
  296. * @return int
  297. */
  298. int qed_spq_completion(struct qed_hwfn *p_hwfn,
  299. __le16 echo,
  300. u8 fw_return_code,
  301. union event_ring_data *p_data);
  302. /**
  303. * @brief qed_spq_get_cid - Given p_hwfn, return cid for the hwfn's SPQ
  304. *
  305. * @param p_hwfn
  306. *
  307. * @return u32 - SPQ CID
  308. */
  309. u32 qed_spq_get_cid(struct qed_hwfn *p_hwfn);
  310. /**
  311. * @brief qed_consq_alloc - Allocates & initializes an ConsQ
  312. * struct
  313. *
  314. * @param p_hwfn
  315. *
  316. * @return int
  317. */
  318. int qed_consq_alloc(struct qed_hwfn *p_hwfn);
  319. /**
  320. * @brief qed_consq_setup - Reset the ConsQ to its start state.
  321. *
  322. * @param p_hwfn
  323. */
  324. void qed_consq_setup(struct qed_hwfn *p_hwfn);
  325. /**
  326. * @brief qed_consq_free - deallocates the given ConsQ struct.
  327. *
  328. * @param p_hwfn
  329. */
  330. void qed_consq_free(struct qed_hwfn *p_hwfn);
  331. /**
  332. * @file
  333. *
  334. * @brief Slow-hwfn low-level commands (Ramrods) function definitions.
  335. */
  336. #define QED_SP_EQ_COMPLETION 0x01
  337. #define QED_SP_CQE_COMPLETION 0x02
  338. struct qed_sp_init_data {
  339. u32 cid;
  340. u16 opaque_fid;
  341. /* Information regarding operation upon sending & completion */
  342. enum spq_mode comp_mode;
  343. struct qed_spq_comp_cb *p_comp_data;
  344. };
  345. int qed_sp_init_request(struct qed_hwfn *p_hwfn,
  346. struct qed_spq_entry **pp_ent,
  347. u8 cmd,
  348. u8 protocol,
  349. struct qed_sp_init_data *p_data);
  350. /**
  351. * @brief qed_sp_pf_start - PF Function Start Ramrod
  352. *
  353. * This ramrod is sent to initialize a physical function (PF). It will
  354. * configure the function related parameters and write its completion to the
  355. * event ring specified in the parameters.
  356. *
  357. * Ramrods complete on the common event ring for the PF. This ring is
  358. * allocated by the driver on host memory and its parameters are written
  359. * to the internal RAM of the UStorm by the Function Start Ramrod.
  360. *
  361. * @param p_hwfn
  362. * @param p_ptt
  363. * @param p_tunn
  364. * @param allow_npar_tx_switch
  365. *
  366. * @return int
  367. */
  368. int qed_sp_pf_start(struct qed_hwfn *p_hwfn,
  369. struct qed_ptt *p_ptt,
  370. struct qed_tunnel_info *p_tunn,
  371. bool allow_npar_tx_switch);
  372. /**
  373. * @brief qed_sp_pf_update - PF Function Update Ramrod
  374. *
  375. * This ramrod updates function-related parameters. Every parameter can be
  376. * updated independently, according to configuration flags.
  377. *
  378. * @param p_hwfn
  379. *
  380. * @return int
  381. */
  382. int qed_sp_pf_update(struct qed_hwfn *p_hwfn);
  383. /**
  384. * @brief qed_sp_pf_update_stag - Update firmware of new outer tag
  385. *
  386. * @param p_hwfn
  387. *
  388. * @return int
  389. */
  390. int qed_sp_pf_update_stag(struct qed_hwfn *p_hwfn);
  391. /**
  392. * @brief qed_sp_pf_stop - PF Function Stop Ramrod
  393. *
  394. * This ramrod is sent to close a Physical Function (PF). It is the last ramrod
  395. * sent and the last completion written to the PFs Event Ring. This ramrod also
  396. * deletes the context for the Slowhwfn connection on this PF.
  397. *
  398. * @note Not required for first packet.
  399. *
  400. * @param p_hwfn
  401. *
  402. * @return int
  403. */
  404. /**
  405. * @brief qed_sp_pf_update_ufp - PF ufp update Ramrod
  406. *
  407. * @param p_hwfn
  408. *
  409. * @return int
  410. */
  411. int qed_sp_pf_update_ufp(struct qed_hwfn *p_hwfn);
  412. int qed_sp_pf_stop(struct qed_hwfn *p_hwfn);
  413. int qed_sp_pf_update_tunn_cfg(struct qed_hwfn *p_hwfn,
  414. struct qed_ptt *p_ptt,
  415. struct qed_tunnel_info *p_tunn,
  416. enum spq_mode comp_mode,
  417. struct qed_spq_comp_cb *p_comp_data);
  418. /**
  419. * @brief qed_sp_heartbeat_ramrod - Send empty Ramrod
  420. *
  421. * @param p_hwfn
  422. *
  423. * @return int
  424. */
  425. int qed_sp_heartbeat_ramrod(struct qed_hwfn *p_hwfn);
  426. #endif