qed_int.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  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. #include <linux/types.h>
  9. #include <asm/byteorder.h>
  10. #include <linux/io.h>
  11. #include <linux/bitops.h>
  12. #include <linux/delay.h>
  13. #include <linux/dma-mapping.h>
  14. #include <linux/errno.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/kernel.h>
  17. #include <linux/pci.h>
  18. #include <linux/slab.h>
  19. #include <linux/string.h>
  20. #include "qed.h"
  21. #include "qed_hsi.h"
  22. #include "qed_hw.h"
  23. #include "qed_init_ops.h"
  24. #include "qed_int.h"
  25. #include "qed_mcp.h"
  26. #include "qed_reg_addr.h"
  27. #include "qed_sp.h"
  28. struct qed_pi_info {
  29. qed_int_comp_cb_t comp_cb;
  30. void *cookie;
  31. };
  32. struct qed_sb_sp_info {
  33. struct qed_sb_info sb_info;
  34. /* per protocol index data */
  35. struct qed_pi_info pi_info_arr[PIS_PER_SB];
  36. };
  37. #define SB_ATTN_ALIGNED_SIZE(p_hwfn) \
  38. ALIGNED_TYPE_SIZE(struct atten_status_block, p_hwfn)
  39. #define ATTN_STATE_BITS (0xfff)
  40. #define ATTN_BITS_MASKABLE (0x3ff)
  41. struct qed_sb_attn_info {
  42. /* Virtual & Physical address of the SB */
  43. struct atten_status_block *sb_attn;
  44. dma_addr_t sb_phys;
  45. /* Last seen running index */
  46. u16 index;
  47. /* Previously asserted attentions, which are still unasserted */
  48. u16 known_attn;
  49. /* Cleanup address for the link's general hw attention */
  50. u32 mfw_attn_addr;
  51. };
  52. static inline u16 qed_attn_update_idx(struct qed_hwfn *p_hwfn,
  53. struct qed_sb_attn_info *p_sb_desc)
  54. {
  55. u16 rc = 0;
  56. u16 index;
  57. /* Make certain HW write took affect */
  58. mmiowb();
  59. index = le16_to_cpu(p_sb_desc->sb_attn->sb_index);
  60. if (p_sb_desc->index != index) {
  61. p_sb_desc->index = index;
  62. rc = QED_SB_ATT_IDX;
  63. }
  64. /* Make certain we got a consistent view with HW */
  65. mmiowb();
  66. return rc;
  67. }
  68. /**
  69. * @brief qed_int_assertion - handles asserted attention bits
  70. *
  71. * @param p_hwfn
  72. * @param asserted_bits newly asserted bits
  73. * @return int
  74. */
  75. static int qed_int_assertion(struct qed_hwfn *p_hwfn,
  76. u16 asserted_bits)
  77. {
  78. struct qed_sb_attn_info *sb_attn_sw = p_hwfn->p_sb_attn;
  79. u32 igu_mask;
  80. /* Mask the source of the attention in the IGU */
  81. igu_mask = qed_rd(p_hwfn, p_hwfn->p_dpc_ptt,
  82. IGU_REG_ATTENTION_ENABLE);
  83. DP_VERBOSE(p_hwfn, NETIF_MSG_INTR, "IGU mask: 0x%08x --> 0x%08x\n",
  84. igu_mask, igu_mask & ~(asserted_bits & ATTN_BITS_MASKABLE));
  85. igu_mask &= ~(asserted_bits & ATTN_BITS_MASKABLE);
  86. qed_wr(p_hwfn, p_hwfn->p_dpc_ptt, IGU_REG_ATTENTION_ENABLE, igu_mask);
  87. DP_VERBOSE(p_hwfn, NETIF_MSG_INTR,
  88. "inner known ATTN state: 0x%04x --> 0x%04x\n",
  89. sb_attn_sw->known_attn,
  90. sb_attn_sw->known_attn | asserted_bits);
  91. sb_attn_sw->known_attn |= asserted_bits;
  92. /* Handle MCP events */
  93. if (asserted_bits & 0x100) {
  94. qed_mcp_handle_events(p_hwfn, p_hwfn->p_dpc_ptt);
  95. /* Clean the MCP attention */
  96. qed_wr(p_hwfn, p_hwfn->p_dpc_ptt,
  97. sb_attn_sw->mfw_attn_addr, 0);
  98. }
  99. DIRECT_REG_WR((u8 __iomem *)p_hwfn->regview +
  100. GTT_BAR0_MAP_REG_IGU_CMD +
  101. ((IGU_CMD_ATTN_BIT_SET_UPPER -
  102. IGU_CMD_INT_ACK_BASE) << 3),
  103. (u32)asserted_bits);
  104. DP_VERBOSE(p_hwfn, NETIF_MSG_INTR, "set cmd IGU: 0x%04x\n",
  105. asserted_bits);
  106. return 0;
  107. }
  108. /**
  109. * @brief - handles deassertion of previously asserted attentions.
  110. *
  111. * @param p_hwfn
  112. * @param deasserted_bits - newly deasserted bits
  113. * @return int
  114. *
  115. */
  116. static int qed_int_deassertion(struct qed_hwfn *p_hwfn,
  117. u16 deasserted_bits)
  118. {
  119. struct qed_sb_attn_info *sb_attn_sw = p_hwfn->p_sb_attn;
  120. u32 aeu_mask;
  121. if (deasserted_bits != 0x100)
  122. DP_ERR(p_hwfn, "Unexpected - non-link deassertion\n");
  123. /* Clear IGU indication for the deasserted bits */
  124. DIRECT_REG_WR((u8 __iomem *)p_hwfn->regview +
  125. GTT_BAR0_MAP_REG_IGU_CMD +
  126. ((IGU_CMD_ATTN_BIT_CLR_UPPER -
  127. IGU_CMD_INT_ACK_BASE) << 3),
  128. ~((u32)deasserted_bits));
  129. /* Unmask deasserted attentions in IGU */
  130. aeu_mask = qed_rd(p_hwfn, p_hwfn->p_dpc_ptt,
  131. IGU_REG_ATTENTION_ENABLE);
  132. aeu_mask |= (deasserted_bits & ATTN_BITS_MASKABLE);
  133. qed_wr(p_hwfn, p_hwfn->p_dpc_ptt, IGU_REG_ATTENTION_ENABLE, aeu_mask);
  134. /* Clear deassertion from inner state */
  135. sb_attn_sw->known_attn &= ~deasserted_bits;
  136. return 0;
  137. }
  138. static int qed_int_attentions(struct qed_hwfn *p_hwfn)
  139. {
  140. struct qed_sb_attn_info *p_sb_attn_sw = p_hwfn->p_sb_attn;
  141. struct atten_status_block *p_sb_attn = p_sb_attn_sw->sb_attn;
  142. u32 attn_bits = 0, attn_acks = 0;
  143. u16 asserted_bits, deasserted_bits;
  144. __le16 index;
  145. int rc = 0;
  146. /* Read current attention bits/acks - safeguard against attentions
  147. * by guaranting work on a synchronized timeframe
  148. */
  149. do {
  150. index = p_sb_attn->sb_index;
  151. attn_bits = le32_to_cpu(p_sb_attn->atten_bits);
  152. attn_acks = le32_to_cpu(p_sb_attn->atten_ack);
  153. } while (index != p_sb_attn->sb_index);
  154. p_sb_attn->sb_index = index;
  155. /* Attention / Deassertion are meaningful (and in correct state)
  156. * only when they differ and consistent with known state - deassertion
  157. * when previous attention & current ack, and assertion when current
  158. * attention with no previous attention
  159. */
  160. asserted_bits = (attn_bits & ~attn_acks & ATTN_STATE_BITS) &
  161. ~p_sb_attn_sw->known_attn;
  162. deasserted_bits = (~attn_bits & attn_acks & ATTN_STATE_BITS) &
  163. p_sb_attn_sw->known_attn;
  164. if ((asserted_bits & ~0x100) || (deasserted_bits & ~0x100)) {
  165. DP_INFO(p_hwfn,
  166. "Attention: Index: 0x%04x, Bits: 0x%08x, Acks: 0x%08x, asserted: 0x%04x, De-asserted 0x%04x [Prev. known: 0x%04x]\n",
  167. index, attn_bits, attn_acks, asserted_bits,
  168. deasserted_bits, p_sb_attn_sw->known_attn);
  169. } else if (asserted_bits == 0x100) {
  170. DP_INFO(p_hwfn,
  171. "MFW indication via attention\n");
  172. } else {
  173. DP_VERBOSE(p_hwfn, NETIF_MSG_INTR,
  174. "MFW indication [deassertion]\n");
  175. }
  176. if (asserted_bits) {
  177. rc = qed_int_assertion(p_hwfn, asserted_bits);
  178. if (rc)
  179. return rc;
  180. }
  181. if (deasserted_bits) {
  182. rc = qed_int_deassertion(p_hwfn, deasserted_bits);
  183. if (rc)
  184. return rc;
  185. }
  186. return rc;
  187. }
  188. static void qed_sb_ack_attn(struct qed_hwfn *p_hwfn,
  189. void __iomem *igu_addr,
  190. u32 ack_cons)
  191. {
  192. struct igu_prod_cons_update igu_ack = { 0 };
  193. igu_ack.sb_id_and_flags =
  194. ((ack_cons << IGU_PROD_CONS_UPDATE_SB_INDEX_SHIFT) |
  195. (1 << IGU_PROD_CONS_UPDATE_UPDATE_FLAG_SHIFT) |
  196. (IGU_INT_NOP << IGU_PROD_CONS_UPDATE_ENABLE_INT_SHIFT) |
  197. (IGU_SEG_ACCESS_ATTN <<
  198. IGU_PROD_CONS_UPDATE_SEGMENT_ACCESS_SHIFT));
  199. DIRECT_REG_WR(igu_addr, igu_ack.sb_id_and_flags);
  200. /* Both segments (interrupts & acks) are written to same place address;
  201. * Need to guarantee all commands will be received (in-order) by HW.
  202. */
  203. mmiowb();
  204. barrier();
  205. }
  206. void qed_int_sp_dpc(unsigned long hwfn_cookie)
  207. {
  208. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)hwfn_cookie;
  209. struct qed_pi_info *pi_info = NULL;
  210. struct qed_sb_attn_info *sb_attn;
  211. struct qed_sb_info *sb_info;
  212. int arr_size;
  213. u16 rc = 0;
  214. if (!p_hwfn->p_sp_sb) {
  215. DP_ERR(p_hwfn->cdev, "DPC called - no p_sp_sb\n");
  216. return;
  217. }
  218. sb_info = &p_hwfn->p_sp_sb->sb_info;
  219. arr_size = ARRAY_SIZE(p_hwfn->p_sp_sb->pi_info_arr);
  220. if (!sb_info) {
  221. DP_ERR(p_hwfn->cdev,
  222. "Status block is NULL - cannot ack interrupts\n");
  223. return;
  224. }
  225. if (!p_hwfn->p_sb_attn) {
  226. DP_ERR(p_hwfn->cdev, "DPC called - no p_sb_attn");
  227. return;
  228. }
  229. sb_attn = p_hwfn->p_sb_attn;
  230. DP_VERBOSE(p_hwfn, NETIF_MSG_INTR, "DPC Called! (hwfn %p %d)\n",
  231. p_hwfn, p_hwfn->my_id);
  232. /* Disable ack for def status block. Required both for msix +
  233. * inta in non-mask mode, in inta does no harm.
  234. */
  235. qed_sb_ack(sb_info, IGU_INT_DISABLE, 0);
  236. /* Gather Interrupts/Attentions information */
  237. if (!sb_info->sb_virt) {
  238. DP_ERR(
  239. p_hwfn->cdev,
  240. "Interrupt Status block is NULL - cannot check for new interrupts!\n");
  241. } else {
  242. u32 tmp_index = sb_info->sb_ack;
  243. rc = qed_sb_update_sb_idx(sb_info);
  244. DP_VERBOSE(p_hwfn->cdev, NETIF_MSG_INTR,
  245. "Interrupt indices: 0x%08x --> 0x%08x\n",
  246. tmp_index, sb_info->sb_ack);
  247. }
  248. if (!sb_attn || !sb_attn->sb_attn) {
  249. DP_ERR(
  250. p_hwfn->cdev,
  251. "Attentions Status block is NULL - cannot check for new attentions!\n");
  252. } else {
  253. u16 tmp_index = sb_attn->index;
  254. rc |= qed_attn_update_idx(p_hwfn, sb_attn);
  255. DP_VERBOSE(p_hwfn->cdev, NETIF_MSG_INTR,
  256. "Attention indices: 0x%08x --> 0x%08x\n",
  257. tmp_index, sb_attn->index);
  258. }
  259. /* Check if we expect interrupts at this time. if not just ack them */
  260. if (!(rc & QED_SB_EVENT_MASK)) {
  261. qed_sb_ack(sb_info, IGU_INT_ENABLE, 1);
  262. return;
  263. }
  264. /* Check the validity of the DPC ptt. If not ack interrupts and fail */
  265. if (!p_hwfn->p_dpc_ptt) {
  266. DP_NOTICE(p_hwfn->cdev, "Failed to allocate PTT\n");
  267. qed_sb_ack(sb_info, IGU_INT_ENABLE, 1);
  268. return;
  269. }
  270. if (rc & QED_SB_ATT_IDX)
  271. qed_int_attentions(p_hwfn);
  272. if (rc & QED_SB_IDX) {
  273. int pi;
  274. /* Look for a free index */
  275. for (pi = 0; pi < arr_size; pi++) {
  276. pi_info = &p_hwfn->p_sp_sb->pi_info_arr[pi];
  277. if (pi_info->comp_cb)
  278. pi_info->comp_cb(p_hwfn, pi_info->cookie);
  279. }
  280. }
  281. if (sb_attn && (rc & QED_SB_ATT_IDX))
  282. /* This should be done before the interrupts are enabled,
  283. * since otherwise a new attention will be generated.
  284. */
  285. qed_sb_ack_attn(p_hwfn, sb_info->igu_addr, sb_attn->index);
  286. qed_sb_ack(sb_info, IGU_INT_ENABLE, 1);
  287. }
  288. static void qed_int_sb_attn_free(struct qed_hwfn *p_hwfn)
  289. {
  290. struct qed_dev *cdev = p_hwfn->cdev;
  291. struct qed_sb_attn_info *p_sb = p_hwfn->p_sb_attn;
  292. if (p_sb) {
  293. if (p_sb->sb_attn)
  294. dma_free_coherent(&cdev->pdev->dev,
  295. SB_ATTN_ALIGNED_SIZE(p_hwfn),
  296. p_sb->sb_attn,
  297. p_sb->sb_phys);
  298. kfree(p_sb);
  299. }
  300. }
  301. static void qed_int_sb_attn_setup(struct qed_hwfn *p_hwfn,
  302. struct qed_ptt *p_ptt)
  303. {
  304. struct qed_sb_attn_info *sb_info = p_hwfn->p_sb_attn;
  305. memset(sb_info->sb_attn, 0, sizeof(*sb_info->sb_attn));
  306. sb_info->index = 0;
  307. sb_info->known_attn = 0;
  308. /* Configure Attention Status Block in IGU */
  309. qed_wr(p_hwfn, p_ptt, IGU_REG_ATTN_MSG_ADDR_L,
  310. lower_32_bits(p_hwfn->p_sb_attn->sb_phys));
  311. qed_wr(p_hwfn, p_ptt, IGU_REG_ATTN_MSG_ADDR_H,
  312. upper_32_bits(p_hwfn->p_sb_attn->sb_phys));
  313. }
  314. static void qed_int_sb_attn_init(struct qed_hwfn *p_hwfn,
  315. struct qed_ptt *p_ptt,
  316. void *sb_virt_addr,
  317. dma_addr_t sb_phy_addr)
  318. {
  319. struct qed_sb_attn_info *sb_info = p_hwfn->p_sb_attn;
  320. sb_info->sb_attn = sb_virt_addr;
  321. sb_info->sb_phys = sb_phy_addr;
  322. /* Set the address of cleanup for the mcp attention */
  323. sb_info->mfw_attn_addr = (p_hwfn->rel_pf_id << 3) +
  324. MISC_REG_AEU_GENERAL_ATTN_0;
  325. qed_int_sb_attn_setup(p_hwfn, p_ptt);
  326. }
  327. static int qed_int_sb_attn_alloc(struct qed_hwfn *p_hwfn,
  328. struct qed_ptt *p_ptt)
  329. {
  330. struct qed_dev *cdev = p_hwfn->cdev;
  331. struct qed_sb_attn_info *p_sb;
  332. void *p_virt;
  333. dma_addr_t p_phys = 0;
  334. /* SB struct */
  335. p_sb = kmalloc(sizeof(*p_sb), GFP_ATOMIC);
  336. if (!p_sb) {
  337. DP_NOTICE(cdev, "Failed to allocate `struct qed_sb_attn_info'\n");
  338. return -ENOMEM;
  339. }
  340. /* SB ring */
  341. p_virt = dma_alloc_coherent(&cdev->pdev->dev,
  342. SB_ATTN_ALIGNED_SIZE(p_hwfn),
  343. &p_phys, GFP_KERNEL);
  344. if (!p_virt) {
  345. DP_NOTICE(cdev, "Failed to allocate status block (attentions)\n");
  346. kfree(p_sb);
  347. return -ENOMEM;
  348. }
  349. /* Attention setup */
  350. p_hwfn->p_sb_attn = p_sb;
  351. qed_int_sb_attn_init(p_hwfn, p_ptt, p_virt, p_phys);
  352. return 0;
  353. }
  354. /* coalescing timeout = timeset << (timer_res + 1) */
  355. #define QED_CAU_DEF_RX_USECS 24
  356. #define QED_CAU_DEF_TX_USECS 48
  357. void qed_init_cau_sb_entry(struct qed_hwfn *p_hwfn,
  358. struct cau_sb_entry *p_sb_entry,
  359. u8 pf_id,
  360. u16 vf_number,
  361. u8 vf_valid)
  362. {
  363. u32 cau_state;
  364. memset(p_sb_entry, 0, sizeof(*p_sb_entry));
  365. SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_PF_NUMBER, pf_id);
  366. SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_VF_NUMBER, vf_number);
  367. SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_VF_VALID, vf_valid);
  368. SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_SB_TIMESET0, 0x7F);
  369. SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_SB_TIMESET1, 0x7F);
  370. /* setting the time resultion to a fixed value ( = 1) */
  371. SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_TIMER_RES0,
  372. QED_CAU_DEF_RX_TIMER_RES);
  373. SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_TIMER_RES1,
  374. QED_CAU_DEF_TX_TIMER_RES);
  375. cau_state = CAU_HC_DISABLE_STATE;
  376. if (p_hwfn->cdev->int_coalescing_mode == QED_COAL_MODE_ENABLE) {
  377. cau_state = CAU_HC_ENABLE_STATE;
  378. if (!p_hwfn->cdev->rx_coalesce_usecs)
  379. p_hwfn->cdev->rx_coalesce_usecs =
  380. QED_CAU_DEF_RX_USECS;
  381. if (!p_hwfn->cdev->tx_coalesce_usecs)
  382. p_hwfn->cdev->tx_coalesce_usecs =
  383. QED_CAU_DEF_TX_USECS;
  384. }
  385. SET_FIELD(p_sb_entry->data, CAU_SB_ENTRY_STATE0, cau_state);
  386. SET_FIELD(p_sb_entry->data, CAU_SB_ENTRY_STATE1, cau_state);
  387. }
  388. void qed_int_cau_conf_sb(struct qed_hwfn *p_hwfn,
  389. struct qed_ptt *p_ptt,
  390. dma_addr_t sb_phys,
  391. u16 igu_sb_id,
  392. u16 vf_number,
  393. u8 vf_valid)
  394. {
  395. struct cau_sb_entry sb_entry;
  396. u32 val;
  397. qed_init_cau_sb_entry(p_hwfn, &sb_entry, p_hwfn->rel_pf_id,
  398. vf_number, vf_valid);
  399. if (p_hwfn->hw_init_done) {
  400. val = CAU_REG_SB_ADDR_MEMORY + igu_sb_id * sizeof(u64);
  401. qed_wr(p_hwfn, p_ptt, val, lower_32_bits(sb_phys));
  402. qed_wr(p_hwfn, p_ptt, val + sizeof(u32),
  403. upper_32_bits(sb_phys));
  404. val = CAU_REG_SB_VAR_MEMORY + igu_sb_id * sizeof(u64);
  405. qed_wr(p_hwfn, p_ptt, val, sb_entry.data);
  406. qed_wr(p_hwfn, p_ptt, val + sizeof(u32), sb_entry.params);
  407. } else {
  408. /* Initialize Status Block Address */
  409. STORE_RT_REG_AGG(p_hwfn,
  410. CAU_REG_SB_ADDR_MEMORY_RT_OFFSET +
  411. igu_sb_id * 2,
  412. sb_phys);
  413. STORE_RT_REG_AGG(p_hwfn,
  414. CAU_REG_SB_VAR_MEMORY_RT_OFFSET +
  415. igu_sb_id * 2,
  416. sb_entry);
  417. }
  418. /* Configure pi coalescing if set */
  419. if (p_hwfn->cdev->int_coalescing_mode == QED_COAL_MODE_ENABLE) {
  420. u8 timeset = p_hwfn->cdev->rx_coalesce_usecs >>
  421. (QED_CAU_DEF_RX_TIMER_RES + 1);
  422. u8 num_tc = 1, i;
  423. qed_int_cau_conf_pi(p_hwfn, p_ptt, igu_sb_id, RX_PI,
  424. QED_COAL_RX_STATE_MACHINE,
  425. timeset);
  426. timeset = p_hwfn->cdev->tx_coalesce_usecs >>
  427. (QED_CAU_DEF_TX_TIMER_RES + 1);
  428. for (i = 0; i < num_tc; i++) {
  429. qed_int_cau_conf_pi(p_hwfn, p_ptt,
  430. igu_sb_id, TX_PI(i),
  431. QED_COAL_TX_STATE_MACHINE,
  432. timeset);
  433. }
  434. }
  435. }
  436. void qed_int_cau_conf_pi(struct qed_hwfn *p_hwfn,
  437. struct qed_ptt *p_ptt,
  438. u16 igu_sb_id,
  439. u32 pi_index,
  440. enum qed_coalescing_fsm coalescing_fsm,
  441. u8 timeset)
  442. {
  443. struct cau_pi_entry pi_entry;
  444. u32 sb_offset;
  445. u32 pi_offset;
  446. sb_offset = igu_sb_id * PIS_PER_SB;
  447. memset(&pi_entry, 0, sizeof(struct cau_pi_entry));
  448. SET_FIELD(pi_entry.prod, CAU_PI_ENTRY_PI_TIMESET, timeset);
  449. if (coalescing_fsm == QED_COAL_RX_STATE_MACHINE)
  450. SET_FIELD(pi_entry.prod, CAU_PI_ENTRY_FSM_SEL, 0);
  451. else
  452. SET_FIELD(pi_entry.prod, CAU_PI_ENTRY_FSM_SEL, 1);
  453. pi_offset = sb_offset + pi_index;
  454. if (p_hwfn->hw_init_done) {
  455. qed_wr(p_hwfn, p_ptt,
  456. CAU_REG_PI_MEMORY + pi_offset * sizeof(u32),
  457. *((u32 *)&(pi_entry)));
  458. } else {
  459. STORE_RT_REG(p_hwfn,
  460. CAU_REG_PI_MEMORY_RT_OFFSET + pi_offset,
  461. *((u32 *)&(pi_entry)));
  462. }
  463. }
  464. void qed_int_sb_setup(struct qed_hwfn *p_hwfn,
  465. struct qed_ptt *p_ptt,
  466. struct qed_sb_info *sb_info)
  467. {
  468. /* zero status block and ack counter */
  469. sb_info->sb_ack = 0;
  470. memset(sb_info->sb_virt, 0, sizeof(*sb_info->sb_virt));
  471. qed_int_cau_conf_sb(p_hwfn, p_ptt, sb_info->sb_phys,
  472. sb_info->igu_sb_id, 0, 0);
  473. }
  474. /**
  475. * @brief qed_get_igu_sb_id - given a sw sb_id return the
  476. * igu_sb_id
  477. *
  478. * @param p_hwfn
  479. * @param sb_id
  480. *
  481. * @return u16
  482. */
  483. static u16 qed_get_igu_sb_id(struct qed_hwfn *p_hwfn,
  484. u16 sb_id)
  485. {
  486. u16 igu_sb_id;
  487. /* Assuming continuous set of IGU SBs dedicated for given PF */
  488. if (sb_id == QED_SP_SB_ID)
  489. igu_sb_id = p_hwfn->hw_info.p_igu_info->igu_dsb_id;
  490. else
  491. igu_sb_id = sb_id + p_hwfn->hw_info.p_igu_info->igu_base_sb;
  492. DP_VERBOSE(p_hwfn, NETIF_MSG_INTR, "SB [%s] index is 0x%04x\n",
  493. (sb_id == QED_SP_SB_ID) ? "DSB" : "non-DSB", igu_sb_id);
  494. return igu_sb_id;
  495. }
  496. int qed_int_sb_init(struct qed_hwfn *p_hwfn,
  497. struct qed_ptt *p_ptt,
  498. struct qed_sb_info *sb_info,
  499. void *sb_virt_addr,
  500. dma_addr_t sb_phy_addr,
  501. u16 sb_id)
  502. {
  503. sb_info->sb_virt = sb_virt_addr;
  504. sb_info->sb_phys = sb_phy_addr;
  505. sb_info->igu_sb_id = qed_get_igu_sb_id(p_hwfn, sb_id);
  506. if (sb_id != QED_SP_SB_ID) {
  507. p_hwfn->sbs_info[sb_id] = sb_info;
  508. p_hwfn->num_sbs++;
  509. }
  510. sb_info->cdev = p_hwfn->cdev;
  511. /* The igu address will hold the absolute address that needs to be
  512. * written to for a specific status block
  513. */
  514. sb_info->igu_addr = (u8 __iomem *)p_hwfn->regview +
  515. GTT_BAR0_MAP_REG_IGU_CMD +
  516. (sb_info->igu_sb_id << 3);
  517. sb_info->flags |= QED_SB_INFO_INIT;
  518. qed_int_sb_setup(p_hwfn, p_ptt, sb_info);
  519. return 0;
  520. }
  521. int qed_int_sb_release(struct qed_hwfn *p_hwfn,
  522. struct qed_sb_info *sb_info,
  523. u16 sb_id)
  524. {
  525. if (sb_id == QED_SP_SB_ID) {
  526. DP_ERR(p_hwfn, "Do Not free sp sb using this function");
  527. return -EINVAL;
  528. }
  529. /* zero status block and ack counter */
  530. sb_info->sb_ack = 0;
  531. memset(sb_info->sb_virt, 0, sizeof(*sb_info->sb_virt));
  532. p_hwfn->sbs_info[sb_id] = NULL;
  533. p_hwfn->num_sbs--;
  534. return 0;
  535. }
  536. static void qed_int_sp_sb_free(struct qed_hwfn *p_hwfn)
  537. {
  538. struct qed_sb_sp_info *p_sb = p_hwfn->p_sp_sb;
  539. if (p_sb) {
  540. if (p_sb->sb_info.sb_virt)
  541. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  542. SB_ALIGNED_SIZE(p_hwfn),
  543. p_sb->sb_info.sb_virt,
  544. p_sb->sb_info.sb_phys);
  545. kfree(p_sb);
  546. }
  547. }
  548. static int qed_int_sp_sb_alloc(struct qed_hwfn *p_hwfn,
  549. struct qed_ptt *p_ptt)
  550. {
  551. struct qed_sb_sp_info *p_sb;
  552. dma_addr_t p_phys = 0;
  553. void *p_virt;
  554. /* SB struct */
  555. p_sb = kmalloc(sizeof(*p_sb), GFP_ATOMIC);
  556. if (!p_sb) {
  557. DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_sb_info'\n");
  558. return -ENOMEM;
  559. }
  560. /* SB ring */
  561. p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  562. SB_ALIGNED_SIZE(p_hwfn),
  563. &p_phys, GFP_KERNEL);
  564. if (!p_virt) {
  565. DP_NOTICE(p_hwfn, "Failed to allocate status block\n");
  566. kfree(p_sb);
  567. return -ENOMEM;
  568. }
  569. /* Status Block setup */
  570. p_hwfn->p_sp_sb = p_sb;
  571. qed_int_sb_init(p_hwfn, p_ptt, &p_sb->sb_info, p_virt,
  572. p_phys, QED_SP_SB_ID);
  573. memset(p_sb->pi_info_arr, 0, sizeof(p_sb->pi_info_arr));
  574. return 0;
  575. }
  576. static void qed_int_sp_sb_setup(struct qed_hwfn *p_hwfn,
  577. struct qed_ptt *p_ptt)
  578. {
  579. if (!p_hwfn)
  580. return;
  581. if (p_hwfn->p_sp_sb)
  582. qed_int_sb_setup(p_hwfn, p_ptt, &p_hwfn->p_sp_sb->sb_info);
  583. else
  584. DP_NOTICE(p_hwfn->cdev,
  585. "Failed to setup Slow path status block - NULL pointer\n");
  586. if (p_hwfn->p_sb_attn)
  587. qed_int_sb_attn_setup(p_hwfn, p_ptt);
  588. else
  589. DP_NOTICE(p_hwfn->cdev,
  590. "Failed to setup attentions status block - NULL pointer\n");
  591. }
  592. int qed_int_register_cb(struct qed_hwfn *p_hwfn,
  593. qed_int_comp_cb_t comp_cb,
  594. void *cookie,
  595. u8 *sb_idx,
  596. __le16 **p_fw_cons)
  597. {
  598. struct qed_sb_sp_info *p_sp_sb = p_hwfn->p_sp_sb;
  599. int qed_status = -ENOMEM;
  600. u8 pi;
  601. /* Look for a free index */
  602. for (pi = 0; pi < ARRAY_SIZE(p_sp_sb->pi_info_arr); pi++) {
  603. if (!p_sp_sb->pi_info_arr[pi].comp_cb) {
  604. p_sp_sb->pi_info_arr[pi].comp_cb = comp_cb;
  605. p_sp_sb->pi_info_arr[pi].cookie = cookie;
  606. *sb_idx = pi;
  607. *p_fw_cons = &p_sp_sb->sb_info.sb_virt->pi_array[pi];
  608. qed_status = 0;
  609. break;
  610. }
  611. }
  612. return qed_status;
  613. }
  614. int qed_int_unregister_cb(struct qed_hwfn *p_hwfn, u8 pi)
  615. {
  616. struct qed_sb_sp_info *p_sp_sb = p_hwfn->p_sp_sb;
  617. int qed_status = -ENOMEM;
  618. if (p_sp_sb->pi_info_arr[pi].comp_cb) {
  619. p_sp_sb->pi_info_arr[pi].comp_cb = NULL;
  620. p_sp_sb->pi_info_arr[pi].cookie = NULL;
  621. qed_status = 0;
  622. }
  623. return qed_status;
  624. }
  625. u16 qed_int_get_sp_sb_id(struct qed_hwfn *p_hwfn)
  626. {
  627. return p_hwfn->p_sp_sb->sb_info.igu_sb_id;
  628. }
  629. void qed_int_igu_enable_int(struct qed_hwfn *p_hwfn,
  630. struct qed_ptt *p_ptt,
  631. enum qed_int_mode int_mode)
  632. {
  633. u32 igu_pf_conf = IGU_PF_CONF_FUNC_EN | IGU_PF_CONF_ATTN_BIT_EN;
  634. p_hwfn->cdev->int_mode = int_mode;
  635. switch (p_hwfn->cdev->int_mode) {
  636. case QED_INT_MODE_INTA:
  637. igu_pf_conf |= IGU_PF_CONF_INT_LINE_EN;
  638. igu_pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  639. break;
  640. case QED_INT_MODE_MSI:
  641. igu_pf_conf |= IGU_PF_CONF_MSI_MSIX_EN;
  642. igu_pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  643. break;
  644. case QED_INT_MODE_MSIX:
  645. igu_pf_conf |= IGU_PF_CONF_MSI_MSIX_EN;
  646. break;
  647. case QED_INT_MODE_POLL:
  648. break;
  649. }
  650. qed_wr(p_hwfn, p_ptt, IGU_REG_PF_CONFIGURATION, igu_pf_conf);
  651. }
  652. int qed_int_igu_enable(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  653. enum qed_int_mode int_mode)
  654. {
  655. int rc, i;
  656. /* Mask non-link attentions */
  657. for (i = 0; i < 9; i++)
  658. qed_wr(p_hwfn, p_ptt,
  659. MISC_REG_AEU_ENABLE1_IGU_OUT_0 + (i << 2), 0);
  660. /* Configure AEU signal change to produce attentions for link */
  661. qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0xfff);
  662. qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0xfff);
  663. /* Flush the writes to IGU */
  664. mmiowb();
  665. /* Unmask AEU signals toward IGU */
  666. qed_wr(p_hwfn, p_ptt, MISC_REG_AEU_MASK_ATTN_IGU, 0xff);
  667. if ((int_mode != QED_INT_MODE_INTA) || IS_LEAD_HWFN(p_hwfn)) {
  668. rc = qed_slowpath_irq_req(p_hwfn);
  669. if (rc != 0) {
  670. DP_NOTICE(p_hwfn, "Slowpath IRQ request failed\n");
  671. return -EINVAL;
  672. }
  673. p_hwfn->b_int_requested = true;
  674. }
  675. /* Enable interrupt Generation */
  676. qed_int_igu_enable_int(p_hwfn, p_ptt, int_mode);
  677. p_hwfn->b_int_enabled = 1;
  678. return rc;
  679. }
  680. void qed_int_igu_disable_int(struct qed_hwfn *p_hwfn,
  681. struct qed_ptt *p_ptt)
  682. {
  683. p_hwfn->b_int_enabled = 0;
  684. qed_wr(p_hwfn, p_ptt, IGU_REG_PF_CONFIGURATION, 0);
  685. }
  686. #define IGU_CLEANUP_SLEEP_LENGTH (1000)
  687. void qed_int_igu_cleanup_sb(struct qed_hwfn *p_hwfn,
  688. struct qed_ptt *p_ptt,
  689. u32 sb_id,
  690. bool cleanup_set,
  691. u16 opaque_fid
  692. )
  693. {
  694. u32 pxp_addr = IGU_CMD_INT_ACK_BASE + sb_id;
  695. u32 sleep_cnt = IGU_CLEANUP_SLEEP_LENGTH;
  696. u32 data = 0;
  697. u32 cmd_ctrl = 0;
  698. u32 val = 0;
  699. u32 sb_bit = 0;
  700. u32 sb_bit_addr = 0;
  701. /* Set the data field */
  702. SET_FIELD(data, IGU_CLEANUP_CLEANUP_SET, cleanup_set ? 1 : 0);
  703. SET_FIELD(data, IGU_CLEANUP_CLEANUP_TYPE, 0);
  704. SET_FIELD(data, IGU_CLEANUP_COMMAND_TYPE, IGU_COMMAND_TYPE_SET);
  705. /* Set the control register */
  706. SET_FIELD(cmd_ctrl, IGU_CTRL_REG_PXP_ADDR, pxp_addr);
  707. SET_FIELD(cmd_ctrl, IGU_CTRL_REG_FID, opaque_fid);
  708. SET_FIELD(cmd_ctrl, IGU_CTRL_REG_TYPE, IGU_CTRL_CMD_TYPE_WR);
  709. qed_wr(p_hwfn, p_ptt, IGU_REG_COMMAND_REG_32LSB_DATA, data);
  710. barrier();
  711. qed_wr(p_hwfn, p_ptt, IGU_REG_COMMAND_REG_CTRL, cmd_ctrl);
  712. /* Flush the write to IGU */
  713. mmiowb();
  714. /* calculate where to read the status bit from */
  715. sb_bit = 1 << (sb_id % 32);
  716. sb_bit_addr = sb_id / 32 * sizeof(u32);
  717. sb_bit_addr += IGU_REG_CLEANUP_STATUS_0;
  718. /* Now wait for the command to complete */
  719. do {
  720. val = qed_rd(p_hwfn, p_ptt, sb_bit_addr);
  721. if ((val & sb_bit) == (cleanup_set ? sb_bit : 0))
  722. break;
  723. usleep_range(5000, 10000);
  724. } while (--sleep_cnt);
  725. if (!sleep_cnt)
  726. DP_NOTICE(p_hwfn,
  727. "Timeout waiting for clear status 0x%08x [for sb %d]\n",
  728. val, sb_id);
  729. }
  730. void qed_int_igu_init_pure_rt_single(struct qed_hwfn *p_hwfn,
  731. struct qed_ptt *p_ptt,
  732. u32 sb_id,
  733. u16 opaque,
  734. bool b_set)
  735. {
  736. int pi;
  737. /* Set */
  738. if (b_set)
  739. qed_int_igu_cleanup_sb(p_hwfn, p_ptt, sb_id, 1, opaque);
  740. /* Clear */
  741. qed_int_igu_cleanup_sb(p_hwfn, p_ptt, sb_id, 0, opaque);
  742. /* Clear the CAU for the SB */
  743. for (pi = 0; pi < 12; pi++)
  744. qed_wr(p_hwfn, p_ptt,
  745. CAU_REG_PI_MEMORY + (sb_id * 12 + pi) * 4, 0);
  746. }
  747. void qed_int_igu_init_pure_rt(struct qed_hwfn *p_hwfn,
  748. struct qed_ptt *p_ptt,
  749. bool b_set,
  750. bool b_slowpath)
  751. {
  752. u32 igu_base_sb = p_hwfn->hw_info.p_igu_info->igu_base_sb;
  753. u32 igu_sb_cnt = p_hwfn->hw_info.p_igu_info->igu_sb_cnt;
  754. u32 sb_id = 0;
  755. u32 val = 0;
  756. val = qed_rd(p_hwfn, p_ptt, IGU_REG_BLOCK_CONFIGURATION);
  757. val |= IGU_REG_BLOCK_CONFIGURATION_VF_CLEANUP_EN;
  758. val &= ~IGU_REG_BLOCK_CONFIGURATION_PXP_TPH_INTERFACE_EN;
  759. qed_wr(p_hwfn, p_ptt, IGU_REG_BLOCK_CONFIGURATION, val);
  760. DP_VERBOSE(p_hwfn, NETIF_MSG_INTR,
  761. "IGU cleaning SBs [%d,...,%d]\n",
  762. igu_base_sb, igu_base_sb + igu_sb_cnt - 1);
  763. for (sb_id = igu_base_sb; sb_id < igu_base_sb + igu_sb_cnt; sb_id++)
  764. qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt, sb_id,
  765. p_hwfn->hw_info.opaque_fid,
  766. b_set);
  767. if (b_slowpath) {
  768. sb_id = p_hwfn->hw_info.p_igu_info->igu_dsb_id;
  769. DP_VERBOSE(p_hwfn, NETIF_MSG_INTR,
  770. "IGU cleaning slowpath SB [%d]\n", sb_id);
  771. qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt, sb_id,
  772. p_hwfn->hw_info.opaque_fid,
  773. b_set);
  774. }
  775. }
  776. int qed_int_igu_read_cam(struct qed_hwfn *p_hwfn,
  777. struct qed_ptt *p_ptt)
  778. {
  779. struct qed_igu_info *p_igu_info;
  780. struct qed_igu_block *blk;
  781. u32 val;
  782. u16 sb_id;
  783. u16 prev_sb_id = 0xFF;
  784. p_hwfn->hw_info.p_igu_info = kzalloc(sizeof(*p_igu_info), GFP_ATOMIC);
  785. if (!p_hwfn->hw_info.p_igu_info)
  786. return -ENOMEM;
  787. p_igu_info = p_hwfn->hw_info.p_igu_info;
  788. /* Initialize base sb / sb cnt for PFs */
  789. p_igu_info->igu_base_sb = 0xffff;
  790. p_igu_info->igu_sb_cnt = 0;
  791. p_igu_info->igu_dsb_id = 0xffff;
  792. p_igu_info->igu_base_sb_iov = 0xffff;
  793. for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev);
  794. sb_id++) {
  795. blk = &p_igu_info->igu_map.igu_blocks[sb_id];
  796. val = qed_rd(p_hwfn, p_ptt,
  797. IGU_REG_MAPPING_MEMORY + sizeof(u32) * sb_id);
  798. /* stop scanning when hit first invalid PF entry */
  799. if (!GET_FIELD(val, IGU_MAPPING_LINE_VALID) &&
  800. GET_FIELD(val, IGU_MAPPING_LINE_PF_VALID))
  801. break;
  802. blk->status = QED_IGU_STATUS_VALID;
  803. blk->function_id = GET_FIELD(val,
  804. IGU_MAPPING_LINE_FUNCTION_NUMBER);
  805. blk->is_pf = GET_FIELD(val, IGU_MAPPING_LINE_PF_VALID);
  806. blk->vector_number = GET_FIELD(val,
  807. IGU_MAPPING_LINE_VECTOR_NUMBER);
  808. DP_VERBOSE(p_hwfn, NETIF_MSG_INTR,
  809. "IGU_BLOCK[sb_id]:%x:func_id = %d is_pf = %d vector_num = 0x%x\n",
  810. val, blk->function_id, blk->is_pf,
  811. blk->vector_number);
  812. if (blk->is_pf) {
  813. if (blk->function_id == p_hwfn->rel_pf_id) {
  814. blk->status |= QED_IGU_STATUS_PF;
  815. if (blk->vector_number == 0) {
  816. if (p_igu_info->igu_dsb_id == 0xffff)
  817. p_igu_info->igu_dsb_id = sb_id;
  818. } else {
  819. if (p_igu_info->igu_base_sb ==
  820. 0xffff) {
  821. p_igu_info->igu_base_sb = sb_id;
  822. } else if (prev_sb_id != sb_id - 1) {
  823. DP_NOTICE(p_hwfn->cdev,
  824. "consecutive igu vectors for HWFN %x broken",
  825. p_hwfn->rel_pf_id);
  826. break;
  827. }
  828. prev_sb_id = sb_id;
  829. /* we don't count the default */
  830. (p_igu_info->igu_sb_cnt)++;
  831. }
  832. }
  833. }
  834. }
  835. DP_VERBOSE(p_hwfn, NETIF_MSG_INTR,
  836. "IGU igu_base_sb=0x%x igu_sb_cnt=%d igu_dsb_id=0x%x\n",
  837. p_igu_info->igu_base_sb,
  838. p_igu_info->igu_sb_cnt,
  839. p_igu_info->igu_dsb_id);
  840. if (p_igu_info->igu_base_sb == 0xffff ||
  841. p_igu_info->igu_dsb_id == 0xffff ||
  842. p_igu_info->igu_sb_cnt == 0) {
  843. DP_NOTICE(p_hwfn,
  844. "IGU CAM returned invalid values igu_base_sb=0x%x igu_sb_cnt=%d igu_dsb_id=0x%x\n",
  845. p_igu_info->igu_base_sb,
  846. p_igu_info->igu_sb_cnt,
  847. p_igu_info->igu_dsb_id);
  848. return -EINVAL;
  849. }
  850. return 0;
  851. }
  852. /**
  853. * @brief Initialize igu runtime registers
  854. *
  855. * @param p_hwfn
  856. */
  857. void qed_int_igu_init_rt(struct qed_hwfn *p_hwfn)
  858. {
  859. u32 igu_pf_conf = 0;
  860. igu_pf_conf |= IGU_PF_CONF_FUNC_EN;
  861. STORE_RT_REG(p_hwfn, IGU_REG_PF_CONFIGURATION_RT_OFFSET, igu_pf_conf);
  862. }
  863. u64 qed_int_igu_read_sisr_reg(struct qed_hwfn *p_hwfn)
  864. {
  865. u64 intr_status = 0;
  866. u32 intr_status_lo = 0;
  867. u32 intr_status_hi = 0;
  868. u32 lsb_igu_cmd_addr = IGU_REG_SISR_MDPC_WMASK_LSB_UPPER -
  869. IGU_CMD_INT_ACK_BASE;
  870. u32 msb_igu_cmd_addr = IGU_REG_SISR_MDPC_WMASK_MSB_UPPER -
  871. IGU_CMD_INT_ACK_BASE;
  872. intr_status_lo = REG_RD(p_hwfn,
  873. GTT_BAR0_MAP_REG_IGU_CMD +
  874. lsb_igu_cmd_addr * 8);
  875. intr_status_hi = REG_RD(p_hwfn,
  876. GTT_BAR0_MAP_REG_IGU_CMD +
  877. msb_igu_cmd_addr * 8);
  878. intr_status = ((u64)intr_status_hi << 32) + (u64)intr_status_lo;
  879. return intr_status;
  880. }
  881. static void qed_int_sp_dpc_setup(struct qed_hwfn *p_hwfn)
  882. {
  883. tasklet_init(p_hwfn->sp_dpc,
  884. qed_int_sp_dpc, (unsigned long)p_hwfn);
  885. p_hwfn->b_sp_dpc_enabled = true;
  886. }
  887. static int qed_int_sp_dpc_alloc(struct qed_hwfn *p_hwfn)
  888. {
  889. p_hwfn->sp_dpc = kmalloc(sizeof(*p_hwfn->sp_dpc), GFP_ATOMIC);
  890. if (!p_hwfn->sp_dpc)
  891. return -ENOMEM;
  892. return 0;
  893. }
  894. static void qed_int_sp_dpc_free(struct qed_hwfn *p_hwfn)
  895. {
  896. kfree(p_hwfn->sp_dpc);
  897. }
  898. int qed_int_alloc(struct qed_hwfn *p_hwfn,
  899. struct qed_ptt *p_ptt)
  900. {
  901. int rc = 0;
  902. rc = qed_int_sp_dpc_alloc(p_hwfn);
  903. if (rc) {
  904. DP_ERR(p_hwfn->cdev, "Failed to allocate sp dpc mem\n");
  905. return rc;
  906. }
  907. rc = qed_int_sp_sb_alloc(p_hwfn, p_ptt);
  908. if (rc) {
  909. DP_ERR(p_hwfn->cdev, "Failed to allocate sp sb mem\n");
  910. return rc;
  911. }
  912. rc = qed_int_sb_attn_alloc(p_hwfn, p_ptt);
  913. if (rc) {
  914. DP_ERR(p_hwfn->cdev, "Failed to allocate sb attn mem\n");
  915. return rc;
  916. }
  917. return rc;
  918. }
  919. void qed_int_free(struct qed_hwfn *p_hwfn)
  920. {
  921. qed_int_sp_sb_free(p_hwfn);
  922. qed_int_sb_attn_free(p_hwfn);
  923. qed_int_sp_dpc_free(p_hwfn);
  924. }
  925. void qed_int_setup(struct qed_hwfn *p_hwfn,
  926. struct qed_ptt *p_ptt)
  927. {
  928. qed_int_sp_sb_setup(p_hwfn, p_ptt);
  929. qed_int_sp_dpc_setup(p_hwfn);
  930. }
  931. int qed_int_get_num_sbs(struct qed_hwfn *p_hwfn,
  932. int *p_iov_blks)
  933. {
  934. struct qed_igu_info *info = p_hwfn->hw_info.p_igu_info;
  935. if (!info)
  936. return 0;
  937. if (p_iov_blks)
  938. *p_iov_blks = info->free_blks;
  939. return info->igu_sb_cnt;
  940. }
  941. void qed_int_disable_post_isr_release(struct qed_dev *cdev)
  942. {
  943. int i;
  944. for_each_hwfn(cdev, i)
  945. cdev->hwfns[i].b_int_requested = false;
  946. }