qed_int.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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_INT_H
  33. #define _QED_INT_H
  34. #include <linux/types.h>
  35. #include <linux/slab.h>
  36. #include "qed.h"
  37. /* Fields of IGU PF CONFIGRATION REGISTER */
  38. #define IGU_PF_CONF_FUNC_EN (0x1 << 0) /* function enable */
  39. #define IGU_PF_CONF_MSI_MSIX_EN (0x1 << 1) /* MSI/MSIX enable */
  40. #define IGU_PF_CONF_INT_LINE_EN (0x1 << 2) /* INT enable */
  41. #define IGU_PF_CONF_ATTN_BIT_EN (0x1 << 3) /* attention enable */
  42. #define IGU_PF_CONF_SINGLE_ISR_EN (0x1 << 4) /* single ISR mode enable */
  43. #define IGU_PF_CONF_SIMD_MODE (0x1 << 5) /* simd all ones mode */
  44. /* Fields of IGU VF CONFIGRATION REGISTER */
  45. #define IGU_VF_CONF_FUNC_EN (0x1 << 0) /* function enable */
  46. #define IGU_VF_CONF_MSI_MSIX_EN (0x1 << 1) /* MSI/MSIX enable */
  47. #define IGU_VF_CONF_SINGLE_ISR_EN (0x1 << 4) /* single ISR mode enable */
  48. #define IGU_VF_CONF_PARENT_MASK (0xF) /* Parent PF */
  49. #define IGU_VF_CONF_PARENT_SHIFT 5 /* Parent PF */
  50. /* Igu control commands
  51. */
  52. enum igu_ctrl_cmd {
  53. IGU_CTRL_CMD_TYPE_RD,
  54. IGU_CTRL_CMD_TYPE_WR,
  55. MAX_IGU_CTRL_CMD
  56. };
  57. /* Control register for the IGU command register
  58. */
  59. struct igu_ctrl_reg {
  60. u32 ctrl_data;
  61. #define IGU_CTRL_REG_FID_MASK 0xFFFF /* Opaque_FID */
  62. #define IGU_CTRL_REG_FID_SHIFT 0
  63. #define IGU_CTRL_REG_PXP_ADDR_MASK 0xFFF /* Command address */
  64. #define IGU_CTRL_REG_PXP_ADDR_SHIFT 16
  65. #define IGU_CTRL_REG_RESERVED_MASK 0x1
  66. #define IGU_CTRL_REG_RESERVED_SHIFT 28
  67. #define IGU_CTRL_REG_TYPE_MASK 0x1 /* use enum igu_ctrl_cmd */
  68. #define IGU_CTRL_REG_TYPE_SHIFT 31
  69. };
  70. enum qed_coalescing_fsm {
  71. QED_COAL_RX_STATE_MACHINE,
  72. QED_COAL_TX_STATE_MACHINE
  73. };
  74. /**
  75. * @brief qed_int_cau_conf_pi - configure cau for a given
  76. * status block
  77. *
  78. * @param p_hwfn
  79. * @param p_ptt
  80. * @param igu_sb_id
  81. * @param pi_index
  82. * @param state
  83. * @param timeset
  84. */
  85. void qed_int_cau_conf_pi(struct qed_hwfn *p_hwfn,
  86. struct qed_ptt *p_ptt,
  87. u16 igu_sb_id,
  88. u32 pi_index,
  89. enum qed_coalescing_fsm coalescing_fsm,
  90. u8 timeset);
  91. /**
  92. * @brief qed_int_igu_enable_int - enable device interrupts
  93. *
  94. * @param p_hwfn
  95. * @param p_ptt
  96. * @param int_mode - interrupt mode to use
  97. */
  98. void qed_int_igu_enable_int(struct qed_hwfn *p_hwfn,
  99. struct qed_ptt *p_ptt,
  100. enum qed_int_mode int_mode);
  101. /**
  102. * @brief qed_int_igu_disable_int - disable device interrupts
  103. *
  104. * @param p_hwfn
  105. * @param p_ptt
  106. */
  107. void qed_int_igu_disable_int(struct qed_hwfn *p_hwfn,
  108. struct qed_ptt *p_ptt);
  109. /**
  110. * @brief qed_int_igu_read_sisr_reg - Reads the single isr multiple dpc
  111. * register from igu.
  112. *
  113. * @param p_hwfn
  114. *
  115. * @return u64
  116. */
  117. u64 qed_int_igu_read_sisr_reg(struct qed_hwfn *p_hwfn);
  118. #define QED_SP_SB_ID 0xffff
  119. /**
  120. * @brief qed_int_sb_init - Initializes the sb_info structure.
  121. *
  122. * once the structure is initialized it can be passed to sb related functions.
  123. *
  124. * @param p_hwfn
  125. * @param p_ptt
  126. * @param sb_info points to an uninitialized (but
  127. * allocated) sb_info structure
  128. * @param sb_virt_addr
  129. * @param sb_phy_addr
  130. * @param sb_id the sb_id to be used (zero based in driver)
  131. * should use QED_SP_SB_ID for SP Status block
  132. *
  133. * @return int
  134. */
  135. int qed_int_sb_init(struct qed_hwfn *p_hwfn,
  136. struct qed_ptt *p_ptt,
  137. struct qed_sb_info *sb_info,
  138. void *sb_virt_addr,
  139. dma_addr_t sb_phy_addr,
  140. u16 sb_id);
  141. /**
  142. * @brief qed_int_sb_setup - Setup the sb.
  143. *
  144. * @param p_hwfn
  145. * @param p_ptt
  146. * @param sb_info initialized sb_info structure
  147. */
  148. void qed_int_sb_setup(struct qed_hwfn *p_hwfn,
  149. struct qed_ptt *p_ptt,
  150. struct qed_sb_info *sb_info);
  151. /**
  152. * @brief qed_int_sb_release - releases the sb_info structure.
  153. *
  154. * once the structure is released, it's memory can be freed
  155. *
  156. * @param p_hwfn
  157. * @param sb_info points to an allocated sb_info structure
  158. * @param sb_id the sb_id to be used (zero based in driver)
  159. * should never be equal to QED_SP_SB_ID
  160. * (SP Status block)
  161. *
  162. * @return int
  163. */
  164. int qed_int_sb_release(struct qed_hwfn *p_hwfn,
  165. struct qed_sb_info *sb_info,
  166. u16 sb_id);
  167. /**
  168. * @brief qed_int_sp_dpc - To be called when an interrupt is received on the
  169. * default status block.
  170. *
  171. * @param p_hwfn - pointer to hwfn
  172. *
  173. */
  174. void qed_int_sp_dpc(unsigned long hwfn_cookie);
  175. /**
  176. * @brief qed_int_get_num_sbs - get the number of status
  177. * blocks configured for this funciton in the igu.
  178. *
  179. * @param p_hwfn
  180. * @param p_sb_cnt_info
  181. *
  182. * @return int - number of status blocks configured
  183. */
  184. void qed_int_get_num_sbs(struct qed_hwfn *p_hwfn,
  185. struct qed_sb_cnt_info *p_sb_cnt_info);
  186. /**
  187. * @brief qed_int_disable_post_isr_release - performs the cleanup post ISR
  188. * release. The API need to be called after releasing all slowpath IRQs
  189. * of the device.
  190. *
  191. * @param cdev
  192. *
  193. */
  194. void qed_int_disable_post_isr_release(struct qed_dev *cdev);
  195. #define QED_CAU_DEF_RX_TIMER_RES 0
  196. #define QED_CAU_DEF_TX_TIMER_RES 0
  197. #define QED_SB_ATT_IDX 0x0001
  198. #define QED_SB_EVENT_MASK 0x0003
  199. #define SB_ALIGNED_SIZE(p_hwfn) \
  200. ALIGNED_TYPE_SIZE(struct status_block, p_hwfn)
  201. struct qed_igu_block {
  202. u8 status;
  203. #define QED_IGU_STATUS_FREE 0x01
  204. #define QED_IGU_STATUS_VALID 0x02
  205. #define QED_IGU_STATUS_PF 0x04
  206. u8 vector_number;
  207. u8 function_id;
  208. u8 is_pf;
  209. };
  210. struct qed_igu_map {
  211. struct qed_igu_block igu_blocks[MAX_TOT_SB_PER_PATH];
  212. };
  213. struct qed_igu_info {
  214. struct qed_igu_map igu_map;
  215. u16 igu_dsb_id;
  216. u16 igu_base_sb;
  217. u16 igu_base_sb_iov;
  218. u16 igu_sb_cnt;
  219. u16 igu_sb_cnt_iov;
  220. u16 free_blks;
  221. };
  222. /* TODO Names of function may change... */
  223. void qed_int_igu_init_pure_rt(struct qed_hwfn *p_hwfn,
  224. struct qed_ptt *p_ptt,
  225. bool b_set,
  226. bool b_slowpath);
  227. void qed_int_igu_init_rt(struct qed_hwfn *p_hwfn);
  228. /**
  229. * @brief qed_int_igu_read_cam - Reads the IGU CAM.
  230. * This function needs to be called during hardware
  231. * prepare. It reads the info from igu cam to know which
  232. * status block is the default / base status block etc.
  233. *
  234. * @param p_hwfn
  235. * @param p_ptt
  236. *
  237. * @return int
  238. */
  239. int qed_int_igu_read_cam(struct qed_hwfn *p_hwfn,
  240. struct qed_ptt *p_ptt);
  241. typedef int (*qed_int_comp_cb_t)(struct qed_hwfn *p_hwfn,
  242. void *cookie);
  243. /**
  244. * @brief qed_int_register_cb - Register callback func for
  245. * slowhwfn statusblock.
  246. *
  247. * Every protocol that uses the slowhwfn status block
  248. * should register a callback function that will be called
  249. * once there is an update of the sp status block.
  250. *
  251. * @param p_hwfn
  252. * @param comp_cb - function to be called when there is an
  253. * interrupt on the sp sb
  254. *
  255. * @param cookie - passed to the callback function
  256. * @param sb_idx - OUT parameter which gives the chosen index
  257. * for this protocol.
  258. * @param p_fw_cons - pointer to the actual address of the
  259. * consumer for this protocol.
  260. *
  261. * @return int
  262. */
  263. int qed_int_register_cb(struct qed_hwfn *p_hwfn,
  264. qed_int_comp_cb_t comp_cb,
  265. void *cookie,
  266. u8 *sb_idx,
  267. __le16 **p_fw_cons);
  268. /**
  269. * @brief qed_int_unregister_cb - Unregisters callback
  270. * function from sp sb.
  271. * Partner of qed_int_register_cb -> should be called
  272. * when no longer required.
  273. *
  274. * @param p_hwfn
  275. * @param pi
  276. *
  277. * @return int
  278. */
  279. int qed_int_unregister_cb(struct qed_hwfn *p_hwfn,
  280. u8 pi);
  281. /**
  282. * @brief qed_int_get_sp_sb_id - Get the slowhwfn sb id.
  283. *
  284. * @param p_hwfn
  285. *
  286. * @return u16
  287. */
  288. u16 qed_int_get_sp_sb_id(struct qed_hwfn *p_hwfn);
  289. /**
  290. * @brief Status block cleanup. Should be called for each status
  291. * block that will be used -> both PF / VF
  292. *
  293. * @param p_hwfn
  294. * @param p_ptt
  295. * @param sb_id - igu status block id
  296. * @param opaque - opaque fid of the sb owner.
  297. * @param b_set - set(1) / clear(0)
  298. */
  299. void qed_int_igu_init_pure_rt_single(struct qed_hwfn *p_hwfn,
  300. struct qed_ptt *p_ptt,
  301. u32 sb_id,
  302. u16 opaque,
  303. bool b_set);
  304. /**
  305. * @brief qed_int_cau_conf - configure cau for a given status
  306. * block
  307. *
  308. * @param p_hwfn
  309. * @param ptt
  310. * @param sb_phys
  311. * @param igu_sb_id
  312. * @param vf_number
  313. * @param vf_valid
  314. */
  315. void qed_int_cau_conf_sb(struct qed_hwfn *p_hwfn,
  316. struct qed_ptt *p_ptt,
  317. dma_addr_t sb_phys,
  318. u16 igu_sb_id,
  319. u16 vf_number,
  320. u8 vf_valid);
  321. /**
  322. * @brief qed_int_alloc
  323. *
  324. * @param p_hwfn
  325. * @param p_ptt
  326. *
  327. * @return int
  328. */
  329. int qed_int_alloc(struct qed_hwfn *p_hwfn,
  330. struct qed_ptt *p_ptt);
  331. /**
  332. * @brief qed_int_free
  333. *
  334. * @param p_hwfn
  335. */
  336. void qed_int_free(struct qed_hwfn *p_hwfn);
  337. /**
  338. * @brief qed_int_setup
  339. *
  340. * @param p_hwfn
  341. * @param p_ptt
  342. */
  343. void qed_int_setup(struct qed_hwfn *p_hwfn,
  344. struct qed_ptt *p_ptt);
  345. /**
  346. * @brief - Returns an Rx queue index appropriate for usage with given SB.
  347. *
  348. * @param p_hwfn
  349. * @param sb_id - absolute index of SB
  350. *
  351. * @return index of Rx queue
  352. */
  353. u16 qed_int_queue_id_from_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id);
  354. /**
  355. * @brief - Enable Interrupt & Attention for hw function
  356. *
  357. * @param p_hwfn
  358. * @param p_ptt
  359. * @param int_mode
  360. *
  361. * @return int
  362. */
  363. int qed_int_igu_enable(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  364. enum qed_int_mode int_mode);
  365. /**
  366. * @brief - Initialize CAU status block entry
  367. *
  368. * @param p_hwfn
  369. * @param p_sb_entry
  370. * @param pf_id
  371. * @param vf_number
  372. * @param vf_valid
  373. */
  374. void qed_init_cau_sb_entry(struct qed_hwfn *p_hwfn,
  375. struct cau_sb_entry *p_sb_entry,
  376. u8 pf_id,
  377. u16 vf_number,
  378. u8 vf_valid);
  379. int qed_int_set_timer_res(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  380. u8 timer_res, u16 sb_id, bool tx);
  381. #define QED_MAPPING_MEMORY_SIZE(dev) (NUM_OF_SBS(dev))
  382. #endif