qed_dev_api.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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_DEV_API_H
  33. #define _QED_DEV_API_H
  34. #include <linux/types.h>
  35. #include <linux/kernel.h>
  36. #include <linux/slab.h>
  37. #include <linux/qed/qed_chain.h>
  38. #include <linux/qed/qed_if.h>
  39. #include "qed_int.h"
  40. /**
  41. * @brief qed_init_dp - initialize the debug level
  42. *
  43. * @param cdev
  44. * @param dp_module
  45. * @param dp_level
  46. */
  47. void qed_init_dp(struct qed_dev *cdev,
  48. u32 dp_module,
  49. u8 dp_level);
  50. /**
  51. * @brief qed_init_struct - initialize the device structure to
  52. * its defaults
  53. *
  54. * @param cdev
  55. */
  56. void qed_init_struct(struct qed_dev *cdev);
  57. /**
  58. * @brief qed_resc_free -
  59. *
  60. * @param cdev
  61. */
  62. void qed_resc_free(struct qed_dev *cdev);
  63. /**
  64. * @brief qed_resc_alloc -
  65. *
  66. * @param cdev
  67. *
  68. * @return int
  69. */
  70. int qed_resc_alloc(struct qed_dev *cdev);
  71. /**
  72. * @brief qed_resc_setup -
  73. *
  74. * @param cdev
  75. */
  76. void qed_resc_setup(struct qed_dev *cdev);
  77. enum qed_override_force_load {
  78. QED_OVERRIDE_FORCE_LOAD_NONE,
  79. QED_OVERRIDE_FORCE_LOAD_ALWAYS,
  80. QED_OVERRIDE_FORCE_LOAD_NEVER,
  81. };
  82. struct qed_drv_load_params {
  83. /* Indicates whether the driver is running over a crash kernel.
  84. * As part of the load request, this will be used for providing the
  85. * driver role to the MFW.
  86. * In case of a crash kernel over PDA - this should be set to false.
  87. */
  88. bool is_crash_kernel;
  89. /* The timeout value that the MFW should use when locking the engine for
  90. * the driver load process.
  91. * A value of '0' means the default value, and '255' means no timeout.
  92. */
  93. u8 mfw_timeout_val;
  94. #define QED_LOAD_REQ_LOCK_TO_DEFAULT 0
  95. #define QED_LOAD_REQ_LOCK_TO_NONE 255
  96. /* Avoid engine reset when first PF loads on it */
  97. bool avoid_eng_reset;
  98. /* Allow overriding the default force load behavior */
  99. enum qed_override_force_load override_force_load;
  100. };
  101. struct qed_hw_init_params {
  102. /* Tunneling parameters */
  103. struct qed_tunn_start_params *p_tunn;
  104. bool b_hw_start;
  105. /* Interrupt mode [msix, inta, etc.] to use */
  106. enum qed_int_mode int_mode;
  107. /* NPAR tx switching to be used for vports for tx-switching */
  108. bool allow_npar_tx_switch;
  109. /* Binary fw data pointer in binary fw file */
  110. const u8 *bin_fw_data;
  111. /* Driver load parameters */
  112. struct qed_drv_load_params *p_drv_load_params;
  113. };
  114. /**
  115. * @brief qed_hw_init -
  116. *
  117. * @param cdev
  118. * @param p_params
  119. *
  120. * @return int
  121. */
  122. int qed_hw_init(struct qed_dev *cdev, struct qed_hw_init_params *p_params);
  123. /**
  124. * @brief qed_hw_timers_stop_all - stop the timers HW block
  125. *
  126. * @param cdev
  127. *
  128. * @return void
  129. */
  130. void qed_hw_timers_stop_all(struct qed_dev *cdev);
  131. /**
  132. * @brief qed_hw_stop -
  133. *
  134. * @param cdev
  135. *
  136. * @return int
  137. */
  138. int qed_hw_stop(struct qed_dev *cdev);
  139. /**
  140. * @brief qed_hw_stop_fastpath -should be called incase
  141. * slowpath is still required for the device,
  142. * but fastpath is not.
  143. *
  144. * @param cdev
  145. *
  146. */
  147. void qed_hw_stop_fastpath(struct qed_dev *cdev);
  148. /**
  149. * @brief qed_hw_start_fastpath -restart fastpath traffic,
  150. * only if hw_stop_fastpath was called
  151. *
  152. * @param cdev
  153. *
  154. */
  155. void qed_hw_start_fastpath(struct qed_hwfn *p_hwfn);
  156. /**
  157. * @brief qed_hw_prepare -
  158. *
  159. * @param cdev
  160. * @param personality - personality to initialize
  161. *
  162. * @return int
  163. */
  164. int qed_hw_prepare(struct qed_dev *cdev,
  165. int personality);
  166. /**
  167. * @brief qed_hw_remove -
  168. *
  169. * @param cdev
  170. */
  171. void qed_hw_remove(struct qed_dev *cdev);
  172. /**
  173. * @brief qed_ptt_acquire - Allocate a PTT window
  174. *
  175. * Should be called at the entry point to the driver (at the beginning of an
  176. * exported function)
  177. *
  178. * @param p_hwfn
  179. *
  180. * @return struct qed_ptt
  181. */
  182. struct qed_ptt *qed_ptt_acquire(struct qed_hwfn *p_hwfn);
  183. /**
  184. * @brief qed_ptt_release - Release PTT Window
  185. *
  186. * Should be called at the end of a flow - at the end of the function that
  187. * acquired the PTT.
  188. *
  189. *
  190. * @param p_hwfn
  191. * @param p_ptt
  192. */
  193. void qed_ptt_release(struct qed_hwfn *p_hwfn,
  194. struct qed_ptt *p_ptt);
  195. void qed_reset_vport_stats(struct qed_dev *cdev);
  196. enum qed_dmae_address_type_t {
  197. QED_DMAE_ADDRESS_HOST_VIRT,
  198. QED_DMAE_ADDRESS_HOST_PHYS,
  199. QED_DMAE_ADDRESS_GRC
  200. };
  201. /* value of flags If QED_DMAE_FLAG_RW_REPL_SRC flag is set and the
  202. * source is a block of length DMAE_MAX_RW_SIZE and the
  203. * destination is larger, the source block will be duplicated as
  204. * many times as required to fill the destination block. This is
  205. * used mostly to write a zeroed buffer to destination address
  206. * using DMA
  207. */
  208. #define QED_DMAE_FLAG_RW_REPL_SRC 0x00000001
  209. #define QED_DMAE_FLAG_VF_SRC 0x00000002
  210. #define QED_DMAE_FLAG_VF_DST 0x00000004
  211. #define QED_DMAE_FLAG_COMPLETION_DST 0x00000008
  212. struct qed_dmae_params {
  213. u32 flags; /* consists of QED_DMAE_FLAG_* values */
  214. u8 src_vfid;
  215. u8 dst_vfid;
  216. };
  217. /**
  218. * @brief qed_dmae_host2grc - copy data from source addr to
  219. * dmae registers using the given ptt
  220. *
  221. * @param p_hwfn
  222. * @param p_ptt
  223. * @param source_addr
  224. * @param grc_addr (dmae_data_offset)
  225. * @param size_in_dwords
  226. * @param flags (one of the flags defined above)
  227. */
  228. int
  229. qed_dmae_host2grc(struct qed_hwfn *p_hwfn,
  230. struct qed_ptt *p_ptt,
  231. u64 source_addr,
  232. u32 grc_addr,
  233. u32 size_in_dwords,
  234. u32 flags);
  235. /**
  236. * @brief qed_dmae_grc2host - Read data from dmae data offset
  237. * to source address using the given ptt
  238. *
  239. * @param p_ptt
  240. * @param grc_addr (dmae_data_offset)
  241. * @param dest_addr
  242. * @param size_in_dwords
  243. * @param flags - one of the flags defined above
  244. */
  245. int qed_dmae_grc2host(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  246. u32 grc_addr, dma_addr_t dest_addr, u32 size_in_dwords,
  247. u32 flags);
  248. /**
  249. * @brief qed_dmae_host2host - copy data from to source address
  250. * to a destination adress (for SRIOV) using the given ptt
  251. *
  252. * @param p_hwfn
  253. * @param p_ptt
  254. * @param source_addr
  255. * @param dest_addr
  256. * @param size_in_dwords
  257. * @param params
  258. */
  259. int qed_dmae_host2host(struct qed_hwfn *p_hwfn,
  260. struct qed_ptt *p_ptt,
  261. dma_addr_t source_addr,
  262. dma_addr_t dest_addr,
  263. u32 size_in_dwords, struct qed_dmae_params *p_params);
  264. /**
  265. * @brief qed_chain_alloc - Allocate and initialize a chain
  266. *
  267. * @param p_hwfn
  268. * @param intended_use
  269. * @param mode
  270. * @param num_elems
  271. * @param elem_size
  272. * @param p_chain
  273. *
  274. * @return int
  275. */
  276. int
  277. qed_chain_alloc(struct qed_dev *cdev,
  278. enum qed_chain_use_mode intended_use,
  279. enum qed_chain_mode mode,
  280. enum qed_chain_cnt_type cnt_type,
  281. u32 num_elems, size_t elem_size, struct qed_chain *p_chain);
  282. /**
  283. * @brief qed_chain_free - Free chain DMA memory
  284. *
  285. * @param p_hwfn
  286. * @param p_chain
  287. */
  288. void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain);
  289. /**
  290. * @@brief qed_fw_l2_queue - Get absolute L2 queue ID
  291. *
  292. * @param p_hwfn
  293. * @param src_id - relative to p_hwfn
  294. * @param dst_id - absolute per engine
  295. *
  296. * @return int
  297. */
  298. int qed_fw_l2_queue(struct qed_hwfn *p_hwfn,
  299. u16 src_id,
  300. u16 *dst_id);
  301. /**
  302. * @@brief qed_fw_vport - Get absolute vport ID
  303. *
  304. * @param p_hwfn
  305. * @param src_id - relative to p_hwfn
  306. * @param dst_id - absolute per engine
  307. *
  308. * @return int
  309. */
  310. int qed_fw_vport(struct qed_hwfn *p_hwfn,
  311. u8 src_id,
  312. u8 *dst_id);
  313. /**
  314. * @@brief qed_fw_rss_eng - Get absolute RSS engine ID
  315. *
  316. * @param p_hwfn
  317. * @param src_id - relative to p_hwfn
  318. * @param dst_id - absolute per engine
  319. *
  320. * @return int
  321. */
  322. int qed_fw_rss_eng(struct qed_hwfn *p_hwfn,
  323. u8 src_id,
  324. u8 *dst_id);
  325. /**
  326. * @brief qed_llh_add_mac_filter - configures a MAC filter in llh
  327. *
  328. * @param p_hwfn
  329. * @param p_ptt
  330. * @param p_filter - MAC to add
  331. */
  332. int qed_llh_add_mac_filter(struct qed_hwfn *p_hwfn,
  333. struct qed_ptt *p_ptt, u8 *p_filter);
  334. /**
  335. * @brief qed_llh_remove_mac_filter - removes a MAC filter from llh
  336. *
  337. * @param p_hwfn
  338. * @param p_ptt
  339. * @param p_filter - MAC to remove
  340. */
  341. void qed_llh_remove_mac_filter(struct qed_hwfn *p_hwfn,
  342. struct qed_ptt *p_ptt, u8 *p_filter);
  343. enum qed_llh_port_filter_type_t {
  344. QED_LLH_FILTER_ETHERTYPE,
  345. QED_LLH_FILTER_TCP_SRC_PORT,
  346. QED_LLH_FILTER_TCP_DEST_PORT,
  347. QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT,
  348. QED_LLH_FILTER_UDP_SRC_PORT,
  349. QED_LLH_FILTER_UDP_DEST_PORT,
  350. QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT
  351. };
  352. /**
  353. * @brief qed_llh_add_protocol_filter - configures a protocol filter in llh
  354. *
  355. * @param p_hwfn
  356. * @param p_ptt
  357. * @param source_port_or_eth_type - source port or ethertype to add
  358. * @param dest_port - destination port to add
  359. * @param type - type of filters and comparing
  360. */
  361. int
  362. qed_llh_add_protocol_filter(struct qed_hwfn *p_hwfn,
  363. struct qed_ptt *p_ptt,
  364. u16 source_port_or_eth_type,
  365. u16 dest_port,
  366. enum qed_llh_port_filter_type_t type);
  367. /**
  368. * @brief qed_llh_remove_protocol_filter - remove a protocol filter in llh
  369. *
  370. * @param p_hwfn
  371. * @param p_ptt
  372. * @param source_port_or_eth_type - source port or ethertype to add
  373. * @param dest_port - destination port to add
  374. * @param type - type of filters and comparing
  375. */
  376. void
  377. qed_llh_remove_protocol_filter(struct qed_hwfn *p_hwfn,
  378. struct qed_ptt *p_ptt,
  379. u16 source_port_or_eth_type,
  380. u16 dest_port,
  381. enum qed_llh_port_filter_type_t type);
  382. /**
  383. * *@brief Cleanup of previous driver remains prior to load
  384. *
  385. * @param p_hwfn
  386. * @param p_ptt
  387. * @param id - For PF, engine-relative. For VF, PF-relative.
  388. * @param is_vf - true iff cleanup is made for a VF.
  389. *
  390. * @return int
  391. */
  392. int qed_final_cleanup(struct qed_hwfn *p_hwfn,
  393. struct qed_ptt *p_ptt, u16 id, bool is_vf);
  394. /**
  395. * @brief qed_set_rxq_coalesce - Configure coalesce parameters for an Rx queue
  396. * The fact that we can configure coalescing to up to 511, but on varying
  397. * accuracy [the bigger the value the less accurate] up to a mistake of 3usec
  398. * for the highest values.
  399. *
  400. * @param p_hwfn
  401. * @param p_ptt
  402. * @param coalesce - Coalesce value in micro seconds.
  403. * @param qid - Queue index.
  404. * @param qid - SB Id
  405. *
  406. * @return int
  407. */
  408. int qed_set_rxq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  409. u16 coalesce, u8 qid, u16 sb_id);
  410. /**
  411. * @brief qed_set_txq_coalesce - Configure coalesce parameters for a Tx queue
  412. * While the API allows setting coalescing per-qid, all tx queues sharing a
  413. * SB should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
  414. * otherwise configuration would break.
  415. *
  416. * @param p_hwfn
  417. * @param p_ptt
  418. * @param coalesce - Coalesce value in micro seconds.
  419. * @param qid - Queue index.
  420. * @param qid - SB Id
  421. *
  422. * @return int
  423. */
  424. int qed_set_txq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  425. u16 coalesce, u8 qid, u16 sb_id);
  426. const char *qed_hw_get_resc_name(enum qed_resources res_id);
  427. #endif