qed_int.h 9.7 KB

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