PageRenderTime 27ms CodeModel.GetById 51ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/ethernet/qlogic/qed/qed_sp.h

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