qed_dev_api.h 11 KB

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