qed_int.h 9.5 KB

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