qed_sp_commands.c 4.4 KB

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