qed_sp_commands.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/bitops.h>
  11. #include <linux/errno.h>
  12. #include <linux/kernel.h>
  13. #include <linux/string.h>
  14. #include "qed.h"
  15. #include <linux/qed/qed_chain.h>
  16. #include "qed_cxt.h"
  17. #include "qed_hsi.h"
  18. #include "qed_hw.h"
  19. #include "qed_int.h"
  20. #include "qed_reg_addr.h"
  21. #include "qed_sp.h"
  22. int qed_sp_init_request(struct qed_hwfn *p_hwfn,
  23. struct qed_spq_entry **pp_ent,
  24. u32 cid,
  25. u16 opaque_fid,
  26. u8 cmd,
  27. u8 protocol,
  28. struct qed_sp_init_request_params *p_params)
  29. {
  30. int rc = -EINVAL;
  31. struct qed_spq_entry *p_ent = NULL;
  32. u32 opaque_cid = opaque_fid << 16 | cid;
  33. if (!pp_ent)
  34. return -ENOMEM;
  35. rc = qed_spq_get_entry(p_hwfn, pp_ent);
  36. if (rc != 0)
  37. return rc;
  38. p_ent = *pp_ent;
  39. p_ent->elem.hdr.cid = cpu_to_le32(opaque_cid);
  40. p_ent->elem.hdr.cmd_id = cmd;
  41. p_ent->elem.hdr.protocol_id = protocol;
  42. p_ent->priority = QED_SPQ_PRIORITY_NORMAL;
  43. p_ent->comp_mode = p_params->comp_mode;
  44. p_ent->comp_done.done = 0;
  45. switch (p_ent->comp_mode) {
  46. case QED_SPQ_MODE_EBLOCK:
  47. p_ent->comp_cb.cookie = &p_ent->comp_done;
  48. break;
  49. case QED_SPQ_MODE_BLOCK:
  50. if (!p_params->p_comp_data)
  51. return -EINVAL;
  52. p_ent->comp_cb.cookie = p_params->p_comp_data->cookie;
  53. break;
  54. case QED_SPQ_MODE_CB:
  55. if (!p_params->p_comp_data)
  56. p_ent->comp_cb.function = NULL;
  57. else
  58. p_ent->comp_cb = *p_params->p_comp_data;
  59. break;
  60. default:
  61. DP_NOTICE(p_hwfn, "Unknown SPQE completion mode %d\n",
  62. p_ent->comp_mode);
  63. return -EINVAL;
  64. }
  65. DP_VERBOSE(p_hwfn, QED_MSG_SPQ,
  66. "Initialized: CID %08x cmd %02x protocol %02x data_addr %lu comp_mode [%s]\n",
  67. opaque_cid, cmd, protocol,
  68. (unsigned long)&p_ent->ramrod,
  69. D_TRINE(p_ent->comp_mode, QED_SPQ_MODE_EBLOCK,
  70. QED_SPQ_MODE_BLOCK, "MODE_EBLOCK", "MODE_BLOCK",
  71. "MODE_CB"));
  72. if (p_params->ramrod_data_size)
  73. memset(&p_ent->ramrod, 0, p_params->ramrod_data_size);
  74. return 0;
  75. }
  76. int qed_sp_pf_start(struct qed_hwfn *p_hwfn,
  77. enum mf_mode mode)
  78. {
  79. struct qed_sp_init_request_params params;
  80. struct pf_start_ramrod_data *p_ramrod = NULL;
  81. u16 sb = qed_int_get_sp_sb_id(p_hwfn);
  82. u8 sb_index = p_hwfn->p_eq->eq_sb_index;
  83. struct qed_spq_entry *p_ent = NULL;
  84. int rc = -EINVAL;
  85. /* update initial eq producer */
  86. qed_eq_prod_update(p_hwfn,
  87. qed_chain_get_prod_idx(&p_hwfn->p_eq->chain));
  88. memset(&params, 0, sizeof(params));
  89. params.ramrod_data_size = sizeof(*p_ramrod);
  90. params.comp_mode = QED_SPQ_MODE_EBLOCK;
  91. rc = qed_sp_init_request(p_hwfn,
  92. &p_ent,
  93. qed_spq_get_cid(p_hwfn),
  94. p_hwfn->hw_info.opaque_fid,
  95. COMMON_RAMROD_PF_START,
  96. PROTOCOLID_COMMON,
  97. &params);
  98. if (rc)
  99. return rc;
  100. p_ramrod = &p_ent->ramrod.pf_start;
  101. p_ramrod->event_ring_sb_id = cpu_to_le16(sb);
  102. p_ramrod->event_ring_sb_index = sb_index;
  103. p_ramrod->path_id = QED_PATH_ID(p_hwfn);
  104. p_ramrod->dont_log_ramrods = 0;
  105. p_ramrod->log_type_mask = cpu_to_le16(0xf);
  106. p_ramrod->mf_mode = mode;
  107. p_ramrod->outer_tag = p_hwfn->hw_info.ovlan;
  108. /* Place EQ address in RAMROD */
  109. p_ramrod->event_ring_pbl_addr.hi =
  110. DMA_HI_LE(p_hwfn->p_eq->chain.pbl.p_phys_table);
  111. p_ramrod->event_ring_pbl_addr.lo =
  112. DMA_LO_LE(p_hwfn->p_eq->chain.pbl.p_phys_table);
  113. p_ramrod->event_ring_num_pages = (u8)p_hwfn->p_eq->chain.page_cnt;
  114. p_ramrod->consolid_q_pbl_addr.hi =
  115. DMA_HI_LE(p_hwfn->p_consq->chain.pbl.p_phys_table);
  116. p_ramrod->consolid_q_pbl_addr.lo =
  117. DMA_LO_LE(p_hwfn->p_consq->chain.pbl.p_phys_table);
  118. p_hwfn->hw_info.personality = PERSONALITY_ETH;
  119. DP_VERBOSE(p_hwfn, QED_MSG_SPQ,
  120. "Setting event_ring_sb [id %04x index %02x], mf [%s] outer_tag [%d]\n",
  121. sb, sb_index,
  122. (p_ramrod->mf_mode == SF) ? "SF" : "Multi-Pf",
  123. p_ramrod->outer_tag);
  124. return qed_spq_post(p_hwfn, p_ent, NULL);
  125. }
  126. int qed_sp_pf_stop(struct qed_hwfn *p_hwfn)
  127. {
  128. struct qed_sp_init_request_params params;
  129. struct qed_spq_entry *p_ent = NULL;
  130. int rc = -EINVAL;
  131. memset(&params, 0, sizeof(params));
  132. params.comp_mode = QED_SPQ_MODE_EBLOCK;
  133. rc = qed_sp_init_request(p_hwfn, &p_ent, qed_spq_get_cid(p_hwfn),
  134. p_hwfn->hw_info.opaque_fid,
  135. COMMON_RAMROD_PF_STOP, PROTOCOLID_COMMON,
  136. &params);
  137. if (rc)
  138. return rc;
  139. return qed_spq_post(p_hwfn, p_ent, NULL);
  140. }