qed_int.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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_igu_enable_int - enable device interrupts
  76. *
  77. * @param p_hwfn
  78. * @param p_ptt
  79. * @param int_mode - interrupt mode to use
  80. */
  81. void qed_int_igu_enable_int(struct qed_hwfn *p_hwfn,
  82. struct qed_ptt *p_ptt,
  83. enum qed_int_mode int_mode);
  84. /**
  85. * @brief qed_int_igu_disable_int - disable device interrupts
  86. *
  87. * @param p_hwfn
  88. * @param p_ptt
  89. */
  90. void qed_int_igu_disable_int(struct qed_hwfn *p_hwfn,
  91. struct qed_ptt *p_ptt);
  92. /**
  93. * @brief qed_int_igu_read_sisr_reg - Reads the single isr multiple dpc
  94. * register from igu.
  95. *
  96. * @param p_hwfn
  97. *
  98. * @return u64
  99. */
  100. u64 qed_int_igu_read_sisr_reg(struct qed_hwfn *p_hwfn);
  101. #define QED_SP_SB_ID 0xffff
  102. /**
  103. * @brief qed_int_sb_init - Initializes the sb_info structure.
  104. *
  105. * once the structure is initialized it can be passed to sb related functions.
  106. *
  107. * @param p_hwfn
  108. * @param p_ptt
  109. * @param sb_info points to an uninitialized (but
  110. * allocated) sb_info structure
  111. * @param sb_virt_addr
  112. * @param sb_phy_addr
  113. * @param sb_id the sb_id to be used (zero based in driver)
  114. * should use QED_SP_SB_ID for SP Status block
  115. *
  116. * @return int
  117. */
  118. int qed_int_sb_init(struct qed_hwfn *p_hwfn,
  119. struct qed_ptt *p_ptt,
  120. struct qed_sb_info *sb_info,
  121. void *sb_virt_addr,
  122. dma_addr_t sb_phy_addr,
  123. u16 sb_id);
  124. /**
  125. * @brief qed_int_sb_setup - Setup the sb.
  126. *
  127. * @param p_hwfn
  128. * @param p_ptt
  129. * @param sb_info initialized sb_info structure
  130. */
  131. void qed_int_sb_setup(struct qed_hwfn *p_hwfn,
  132. struct qed_ptt *p_ptt,
  133. struct qed_sb_info *sb_info);
  134. /**
  135. * @brief qed_int_sb_release - releases the sb_info structure.
  136. *
  137. * once the structure is released, it's memory can be freed
  138. *
  139. * @param p_hwfn
  140. * @param sb_info points to an allocated sb_info structure
  141. * @param sb_id the sb_id to be used (zero based in driver)
  142. * should never be equal to QED_SP_SB_ID
  143. * (SP Status block)
  144. *
  145. * @return int
  146. */
  147. int qed_int_sb_release(struct qed_hwfn *p_hwfn,
  148. struct qed_sb_info *sb_info,
  149. u16 sb_id);
  150. /**
  151. * @brief qed_int_sp_dpc - To be called when an interrupt is received on the
  152. * default status block.
  153. *
  154. * @param p_hwfn - pointer to hwfn
  155. *
  156. */
  157. void qed_int_sp_dpc(unsigned long hwfn_cookie);
  158. /**
  159. * @brief qed_int_get_num_sbs - get the number of status
  160. * blocks configured for this funciton in the igu.
  161. *
  162. * @param p_hwfn
  163. * @param p_sb_cnt_info
  164. *
  165. * @return int - number of status blocks configured
  166. */
  167. void qed_int_get_num_sbs(struct qed_hwfn *p_hwfn,
  168. struct qed_sb_cnt_info *p_sb_cnt_info);
  169. /**
  170. * @brief qed_int_disable_post_isr_release - performs the cleanup post ISR
  171. * release. The API need to be called after releasing all slowpath IRQs
  172. * of the device.
  173. *
  174. * @param cdev
  175. *
  176. */
  177. void qed_int_disable_post_isr_release(struct qed_dev *cdev);
  178. #define QED_CAU_DEF_RX_TIMER_RES 0
  179. #define QED_CAU_DEF_TX_TIMER_RES 0
  180. #define QED_SB_ATT_IDX 0x0001
  181. #define QED_SB_EVENT_MASK 0x0003
  182. #define SB_ALIGNED_SIZE(p_hwfn) \
  183. ALIGNED_TYPE_SIZE(struct status_block_e4, p_hwfn)
  184. #define QED_SB_INVALID_IDX 0xffff
  185. struct qed_igu_block {
  186. u8 status;
  187. #define QED_IGU_STATUS_FREE 0x01
  188. #define QED_IGU_STATUS_VALID 0x02
  189. #define QED_IGU_STATUS_PF 0x04
  190. #define QED_IGU_STATUS_DSB 0x08
  191. u8 vector_number;
  192. u8 function_id;
  193. u8 is_pf;
  194. /* Index inside IGU [meant for back reference] */
  195. u16 igu_sb_id;
  196. struct qed_sb_info *sb_info;
  197. };
  198. struct qed_igu_info {
  199. struct qed_igu_block entry[MAX_TOT_SB_PER_PATH];
  200. u16 igu_dsb_id;
  201. struct qed_sb_cnt_info usage;
  202. bool b_allow_pf_vf_change;
  203. };
  204. /**
  205. * @brief - Make sure the IGU CAM reflects the resources provided by MFW
  206. *
  207. * @param p_hwfn
  208. * @param p_ptt
  209. */
  210. int qed_int_igu_reset_cam(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
  211. /**
  212. * @brief Translate the weakly-defined client sb-id into an IGU sb-id
  213. *
  214. * @param p_hwfn
  215. * @param sb_id - user provided sb_id
  216. *
  217. * @return an index inside IGU CAM where the SB resides
  218. */
  219. u16 qed_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id);
  220. /**
  221. * @brief return a pointer to an unused valid SB
  222. *
  223. * @param p_hwfn
  224. * @param b_is_pf - true iff we want a SB belonging to a PF
  225. *
  226. * @return point to an igu_block, NULL if none is available
  227. */
  228. struct qed_igu_block *qed_get_igu_free_sb(struct qed_hwfn *p_hwfn,
  229. bool b_is_pf);
  230. void qed_int_igu_init_pure_rt(struct qed_hwfn *p_hwfn,
  231. struct qed_ptt *p_ptt,
  232. bool b_set,
  233. bool b_slowpath);
  234. void qed_int_igu_init_rt(struct qed_hwfn *p_hwfn);
  235. /**
  236. * @brief qed_int_igu_read_cam - Reads the IGU CAM.
  237. * This function needs to be called during hardware
  238. * prepare. It reads the info from igu cam to know which
  239. * status block is the default / base status block etc.
  240. *
  241. * @param p_hwfn
  242. * @param p_ptt
  243. *
  244. * @return int
  245. */
  246. int qed_int_igu_read_cam(struct qed_hwfn *p_hwfn,
  247. struct qed_ptt *p_ptt);
  248. typedef int (*qed_int_comp_cb_t)(struct qed_hwfn *p_hwfn,
  249. void *cookie);
  250. /**
  251. * @brief qed_int_register_cb - Register callback func for
  252. * slowhwfn statusblock.
  253. *
  254. * Every protocol that uses the slowhwfn status block
  255. * should register a callback function that will be called
  256. * once there is an update of the sp status block.
  257. *
  258. * @param p_hwfn
  259. * @param comp_cb - function to be called when there is an
  260. * interrupt on the sp sb
  261. *
  262. * @param cookie - passed to the callback function
  263. * @param sb_idx - OUT parameter which gives the chosen index
  264. * for this protocol.
  265. * @param p_fw_cons - pointer to the actual address of the
  266. * consumer for this protocol.
  267. *
  268. * @return int
  269. */
  270. int qed_int_register_cb(struct qed_hwfn *p_hwfn,
  271. qed_int_comp_cb_t comp_cb,
  272. void *cookie,
  273. u8 *sb_idx,
  274. __le16 **p_fw_cons);
  275. /**
  276. * @brief qed_int_unregister_cb - Unregisters callback
  277. * function from sp sb.
  278. * Partner of qed_int_register_cb -> should be called
  279. * when no longer required.
  280. *
  281. * @param p_hwfn
  282. * @param pi
  283. *
  284. * @return int
  285. */
  286. int qed_int_unregister_cb(struct qed_hwfn *p_hwfn,
  287. u8 pi);
  288. /**
  289. * @brief qed_int_get_sp_sb_id - Get the slowhwfn sb id.
  290. *
  291. * @param p_hwfn
  292. *
  293. * @return u16
  294. */
  295. u16 qed_int_get_sp_sb_id(struct qed_hwfn *p_hwfn);
  296. /**
  297. * @brief Status block cleanup. Should be called for each status
  298. * block that will be used -> both PF / VF
  299. *
  300. * @param p_hwfn
  301. * @param p_ptt
  302. * @param igu_sb_id - igu status block id
  303. * @param opaque - opaque fid of the sb owner.
  304. * @param b_set - set(1) / clear(0)
  305. */
  306. void qed_int_igu_init_pure_rt_single(struct qed_hwfn *p_hwfn,
  307. struct qed_ptt *p_ptt,
  308. u16 igu_sb_id,
  309. u16 opaque,
  310. bool b_set);
  311. /**
  312. * @brief qed_int_cau_conf - configure cau for a given status
  313. * block
  314. *
  315. * @param p_hwfn
  316. * @param ptt
  317. * @param sb_phys
  318. * @param igu_sb_id
  319. * @param vf_number
  320. * @param vf_valid
  321. */
  322. void qed_int_cau_conf_sb(struct qed_hwfn *p_hwfn,
  323. struct qed_ptt *p_ptt,
  324. dma_addr_t sb_phys,
  325. u16 igu_sb_id,
  326. u16 vf_number,
  327. u8 vf_valid);
  328. /**
  329. * @brief qed_int_alloc
  330. *
  331. * @param p_hwfn
  332. * @param p_ptt
  333. *
  334. * @return int
  335. */
  336. int qed_int_alloc(struct qed_hwfn *p_hwfn,
  337. struct qed_ptt *p_ptt);
  338. /**
  339. * @brief qed_int_free
  340. *
  341. * @param p_hwfn
  342. */
  343. void qed_int_free(struct qed_hwfn *p_hwfn);
  344. /**
  345. * @brief qed_int_setup
  346. *
  347. * @param p_hwfn
  348. * @param p_ptt
  349. */
  350. void qed_int_setup(struct qed_hwfn *p_hwfn,
  351. struct qed_ptt *p_ptt);
  352. /**
  353. * @brief - Enable Interrupt & Attention for hw function
  354. *
  355. * @param p_hwfn
  356. * @param p_ptt
  357. * @param int_mode
  358. *
  359. * @return int
  360. */
  361. int qed_int_igu_enable(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  362. enum qed_int_mode int_mode);
  363. /**
  364. * @brief - Initialize CAU status block entry
  365. *
  366. * @param p_hwfn
  367. * @param p_sb_entry
  368. * @param pf_id
  369. * @param vf_number
  370. * @param vf_valid
  371. */
  372. void qed_init_cau_sb_entry(struct qed_hwfn *p_hwfn,
  373. struct cau_sb_entry *p_sb_entry,
  374. u8 pf_id,
  375. u16 vf_number,
  376. u8 vf_valid);
  377. int qed_int_set_timer_res(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  378. u8 timer_res, u16 sb_id, bool tx);
  379. #define QED_MAPPING_MEMORY_SIZE(dev) (NUM_OF_SBS(dev))
  380. #endif