qed_int.c 29 KB

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