qed_dev_api.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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_tunnel_info *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. * @return int
  147. */
  148. int qed_hw_stop_fastpath(struct qed_dev *cdev);
  149. /**
  150. * @brief qed_hw_start_fastpath -restart fastpath traffic,
  151. * only if hw_stop_fastpath was called
  152. *
  153. * @param p_hwfn
  154. *
  155. * @return int
  156. */
  157. int qed_hw_start_fastpath(struct qed_hwfn *p_hwfn);
  158. /**
  159. * @brief qed_hw_prepare -
  160. *
  161. * @param cdev
  162. * @param personality - personality to initialize
  163. *
  164. * @return int
  165. */
  166. int qed_hw_prepare(struct qed_dev *cdev,
  167. int personality);
  168. /**
  169. * @brief qed_hw_remove -
  170. *
  171. * @param cdev
  172. */
  173. void qed_hw_remove(struct qed_dev *cdev);
  174. /**
  175. * @brief qed_ptt_acquire - Allocate a PTT window
  176. *
  177. * Should be called at the entry point to the driver (at the beginning of an
  178. * exported function)
  179. *
  180. * @param p_hwfn
  181. *
  182. * @return struct qed_ptt
  183. */
  184. struct qed_ptt *qed_ptt_acquire(struct qed_hwfn *p_hwfn);
  185. /**
  186. * @brief qed_ptt_release - Release PTT Window
  187. *
  188. * Should be called at the end of a flow - at the end of the function that
  189. * acquired the PTT.
  190. *
  191. *
  192. * @param p_hwfn
  193. * @param p_ptt
  194. */
  195. void qed_ptt_release(struct qed_hwfn *p_hwfn,
  196. struct qed_ptt *p_ptt);
  197. void qed_reset_vport_stats(struct qed_dev *cdev);
  198. enum qed_dmae_address_type_t {
  199. QED_DMAE_ADDRESS_HOST_VIRT,
  200. QED_DMAE_ADDRESS_HOST_PHYS,
  201. QED_DMAE_ADDRESS_GRC
  202. };
  203. /* value of flags If QED_DMAE_FLAG_RW_REPL_SRC flag is set and the
  204. * source is a block of length DMAE_MAX_RW_SIZE and the
  205. * destination is larger, the source block will be duplicated as
  206. * many times as required to fill the destination block. This is
  207. * used mostly to write a zeroed buffer to destination address
  208. * using DMA
  209. */
  210. #define QED_DMAE_FLAG_RW_REPL_SRC 0x00000001
  211. #define QED_DMAE_FLAG_VF_SRC 0x00000002
  212. #define QED_DMAE_FLAG_VF_DST 0x00000004
  213. #define QED_DMAE_FLAG_COMPLETION_DST 0x00000008
  214. struct qed_dmae_params {
  215. u32 flags; /* consists of QED_DMAE_FLAG_* values */
  216. u8 src_vfid;
  217. u8 dst_vfid;
  218. };
  219. /**
  220. * @brief qed_dmae_host2grc - copy data from source addr to
  221. * dmae registers using the given ptt
  222. *
  223. * @param p_hwfn
  224. * @param p_ptt
  225. * @param source_addr
  226. * @param grc_addr (dmae_data_offset)
  227. * @param size_in_dwords
  228. * @param flags (one of the flags defined above)
  229. */
  230. int
  231. qed_dmae_host2grc(struct qed_hwfn *p_hwfn,
  232. struct qed_ptt *p_ptt,
  233. u64 source_addr,
  234. u32 grc_addr,
  235. u32 size_in_dwords,
  236. u32 flags);
  237. /**
  238. * @brief qed_dmae_grc2host - Read data from dmae data offset
  239. * to source address using the given ptt
  240. *
  241. * @param p_ptt
  242. * @param grc_addr (dmae_data_offset)
  243. * @param dest_addr
  244. * @param size_in_dwords
  245. * @param flags - one of the flags defined above
  246. */
  247. int qed_dmae_grc2host(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  248. u32 grc_addr, dma_addr_t dest_addr, u32 size_in_dwords,
  249. u32 flags);
  250. /**
  251. * @brief qed_dmae_host2host - copy data from to source address
  252. * to a destination adress (for SRIOV) using the given ptt
  253. *
  254. * @param p_hwfn
  255. * @param p_ptt
  256. * @param source_addr
  257. * @param dest_addr
  258. * @param size_in_dwords
  259. * @param params
  260. */
  261. int qed_dmae_host2host(struct qed_hwfn *p_hwfn,
  262. struct qed_ptt *p_ptt,
  263. dma_addr_t source_addr,
  264. dma_addr_t dest_addr,
  265. u32 size_in_dwords, struct qed_dmae_params *p_params);
  266. /**
  267. * @brief qed_chain_alloc - Allocate and initialize a chain
  268. *
  269. * @param p_hwfn
  270. * @param intended_use
  271. * @param mode
  272. * @param num_elems
  273. * @param elem_size
  274. * @param p_chain
  275. * @param ext_pbl - a possible external PBL
  276. *
  277. * @return int
  278. */
  279. int
  280. qed_chain_alloc(struct qed_dev *cdev,
  281. enum qed_chain_use_mode intended_use,
  282. enum qed_chain_mode mode,
  283. enum qed_chain_cnt_type cnt_type,
  284. u32 num_elems,
  285. size_t elem_size,
  286. struct qed_chain *p_chain, struct qed_chain_ext_pbl *ext_pbl);
  287. /**
  288. * @brief qed_chain_free - Free chain DMA memory
  289. *
  290. * @param p_hwfn
  291. * @param p_chain
  292. */
  293. void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain);
  294. /**
  295. * @@brief qed_fw_l2_queue - Get absolute L2 queue ID
  296. *
  297. * @param p_hwfn
  298. * @param src_id - relative to p_hwfn
  299. * @param dst_id - absolute per engine
  300. *
  301. * @return int
  302. */
  303. int qed_fw_l2_queue(struct qed_hwfn *p_hwfn,
  304. u16 src_id,
  305. u16 *dst_id);
  306. /**
  307. * @@brief qed_fw_vport - Get absolute vport ID
  308. *
  309. * @param p_hwfn
  310. * @param src_id - relative to p_hwfn
  311. * @param dst_id - absolute per engine
  312. *
  313. * @return int
  314. */
  315. int qed_fw_vport(struct qed_hwfn *p_hwfn,
  316. u8 src_id,
  317. u8 *dst_id);
  318. /**
  319. * @@brief qed_fw_rss_eng - Get absolute RSS engine ID
  320. *
  321. * @param p_hwfn
  322. * @param src_id - relative to p_hwfn
  323. * @param dst_id - absolute per engine
  324. *
  325. * @return int
  326. */
  327. int qed_fw_rss_eng(struct qed_hwfn *p_hwfn,
  328. u8 src_id,
  329. u8 *dst_id);
  330. /**
  331. * @brief qed_llh_add_mac_filter - configures a MAC filter in llh
  332. *
  333. * @param p_hwfn
  334. * @param p_ptt
  335. * @param p_filter - MAC to add
  336. */
  337. int qed_llh_add_mac_filter(struct qed_hwfn *p_hwfn,
  338. struct qed_ptt *p_ptt, u8 *p_filter);
  339. /**
  340. * @brief qed_llh_remove_mac_filter - removes a MAC filter from llh
  341. *
  342. * @param p_hwfn
  343. * @param p_ptt
  344. * @param p_filter - MAC to remove
  345. */
  346. void qed_llh_remove_mac_filter(struct qed_hwfn *p_hwfn,
  347. struct qed_ptt *p_ptt, u8 *p_filter);
  348. enum qed_llh_port_filter_type_t {
  349. QED_LLH_FILTER_ETHERTYPE,
  350. QED_LLH_FILTER_TCP_SRC_PORT,
  351. QED_LLH_FILTER_TCP_DEST_PORT,
  352. QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT,
  353. QED_LLH_FILTER_UDP_SRC_PORT,
  354. QED_LLH_FILTER_UDP_DEST_PORT,
  355. QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT
  356. };
  357. /**
  358. * @brief qed_llh_add_protocol_filter - configures a protocol filter in llh
  359. *
  360. * @param p_hwfn
  361. * @param p_ptt
  362. * @param source_port_or_eth_type - source port or ethertype to add
  363. * @param dest_port - destination port to add
  364. * @param type - type of filters and comparing
  365. */
  366. int
  367. qed_llh_add_protocol_filter(struct qed_hwfn *p_hwfn,
  368. struct qed_ptt *p_ptt,
  369. u16 source_port_or_eth_type,
  370. u16 dest_port,
  371. enum qed_llh_port_filter_type_t type);
  372. /**
  373. * @brief qed_llh_remove_protocol_filter - remove a protocol filter in llh
  374. *
  375. * @param p_hwfn
  376. * @param p_ptt
  377. * @param source_port_or_eth_type - source port or ethertype to add
  378. * @param dest_port - destination port to add
  379. * @param type - type of filters and comparing
  380. */
  381. void
  382. qed_llh_remove_protocol_filter(struct qed_hwfn *p_hwfn,
  383. struct qed_ptt *p_ptt,
  384. u16 source_port_or_eth_type,
  385. u16 dest_port,
  386. enum qed_llh_port_filter_type_t type);
  387. /**
  388. * *@brief Cleanup of previous driver remains prior to load
  389. *
  390. * @param p_hwfn
  391. * @param p_ptt
  392. * @param id - For PF, engine-relative. For VF, PF-relative.
  393. * @param is_vf - true iff cleanup is made for a VF.
  394. *
  395. * @return int
  396. */
  397. int qed_final_cleanup(struct qed_hwfn *p_hwfn,
  398. struct qed_ptt *p_ptt, u16 id, bool is_vf);
  399. /**
  400. * @brief qed_get_queue_coalesce - Retrieve coalesce value for a given queue.
  401. *
  402. * @param p_hwfn
  403. * @param p_coal - store coalesce value read from the hardware.
  404. * @param p_handle
  405. *
  406. * @return int
  407. **/
  408. int qed_get_queue_coalesce(struct qed_hwfn *p_hwfn, u16 *coal, void *handle);
  409. /**
  410. * @brief qed_set_queue_coalesce - Configure coalesce parameters for Rx and
  411. * Tx queue. The fact that we can configure coalescing to up to 511, but on
  412. * varying accuracy [the bigger the value the less accurate] up to a mistake
  413. * of 3usec for the highest values.
  414. * While the API allows setting coalescing per-qid, all queues sharing a SB
  415. * should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
  416. * otherwise configuration would break.
  417. *
  418. *
  419. * @param rx_coal - Rx Coalesce value in micro seconds.
  420. * @param tx_coal - TX Coalesce value in micro seconds.
  421. * @param p_handle
  422. *
  423. * @return int
  424. **/
  425. int
  426. qed_set_queue_coalesce(u16 rx_coal, u16 tx_coal, void *p_handle);
  427. const char *qed_hw_get_resc_name(enum qed_resources res_id);
  428. #endif