drv_fcoe_fw_funcs.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* QLogic FCoE Offload Driver
  3. * Copyright (c) 2016-2018 Cavium Inc.
  4. */
  5. #include "drv_fcoe_fw_funcs.h"
  6. #include "drv_scsi_fw_funcs.h"
  7. #define FCOE_RX_ID (0xFFFFu)
  8. static inline void init_common_sqe(struct fcoe_task_params *task_params,
  9. enum fcoe_sqe_request_type request_type)
  10. {
  11. memset(task_params->sqe, 0, sizeof(*(task_params->sqe)));
  12. SET_FIELD(task_params->sqe->flags, FCOE_WQE_REQ_TYPE,
  13. request_type);
  14. task_params->sqe->task_id = task_params->itid;
  15. }
  16. int init_initiator_rw_fcoe_task(struct fcoe_task_params *task_params,
  17. struct scsi_sgl_task_params *sgl_task_params,
  18. struct regpair sense_data_buffer_phys_addr,
  19. u32 task_retry_id,
  20. u8 fcp_cmd_payload[32])
  21. {
  22. struct fcoe_task_context *ctx = task_params->context;
  23. const u8 val_byte = ctx->ystorm_ag_context.byte0;
  24. struct ustorm_fcoe_task_ag_ctx *u_ag_ctx;
  25. struct ystorm_fcoe_task_st_ctx *y_st_ctx;
  26. struct tstorm_fcoe_task_st_ctx *t_st_ctx;
  27. struct mstorm_fcoe_task_st_ctx *m_st_ctx;
  28. u32 io_size, val;
  29. bool slow_sgl;
  30. memset(ctx, 0, sizeof(*(ctx)));
  31. ctx->ystorm_ag_context.byte0 = val_byte;
  32. slow_sgl = scsi_is_slow_sgl(sgl_task_params->num_sges,
  33. sgl_task_params->small_mid_sge);
  34. io_size = (task_params->task_type == FCOE_TASK_TYPE_WRITE_INITIATOR ?
  35. task_params->tx_io_size : task_params->rx_io_size);
  36. /* Ystorm ctx */
  37. y_st_ctx = &ctx->ystorm_st_context;
  38. y_st_ctx->data_2_trns_rem = cpu_to_le32(io_size);
  39. y_st_ctx->task_rety_identifier = cpu_to_le32(task_retry_id);
  40. y_st_ctx->task_type = (u8)task_params->task_type;
  41. memcpy(&y_st_ctx->tx_info_union.fcp_cmd_payload,
  42. fcp_cmd_payload, sizeof(struct fcoe_fcp_cmd_payload));
  43. /* Tstorm ctx */
  44. t_st_ctx = &ctx->tstorm_st_context;
  45. t_st_ctx->read_only.dev_type = (u8)(task_params->is_tape_device == 1 ?
  46. FCOE_TASK_DEV_TYPE_TAPE :
  47. FCOE_TASK_DEV_TYPE_DISK);
  48. t_st_ctx->read_only.cid = cpu_to_le32(task_params->conn_cid);
  49. val = cpu_to_le32(task_params->cq_rss_number);
  50. t_st_ctx->read_only.glbl_q_num = val;
  51. t_st_ctx->read_only.fcp_cmd_trns_size = cpu_to_le32(io_size);
  52. t_st_ctx->read_only.task_type = (u8)task_params->task_type;
  53. SET_FIELD(t_st_ctx->read_write.flags,
  54. FCOE_TSTORM_FCOE_TASK_ST_CTX_READ_WRITE_EXP_FIRST_FRAME, 1);
  55. t_st_ctx->read_write.rx_id = cpu_to_le16(FCOE_RX_ID);
  56. /* Ustorm ctx */
  57. u_ag_ctx = &ctx->ustorm_ag_context;
  58. u_ag_ctx->global_cq_num = cpu_to_le32(task_params->cq_rss_number);
  59. /* Mstorm buffer for sense/rsp data placement */
  60. m_st_ctx = &ctx->mstorm_st_context;
  61. val = cpu_to_le32(sense_data_buffer_phys_addr.hi);
  62. m_st_ctx->rsp_buf_addr.hi = val;
  63. val = cpu_to_le32(sense_data_buffer_phys_addr.lo);
  64. m_st_ctx->rsp_buf_addr.lo = val;
  65. if (task_params->task_type == FCOE_TASK_TYPE_WRITE_INITIATOR) {
  66. /* Ystorm ctx */
  67. y_st_ctx->expect_first_xfer = 1;
  68. /* Set the amount of super SGEs. Can be up to 4. */
  69. SET_FIELD(y_st_ctx->sgl_mode,
  70. YSTORM_FCOE_TASK_ST_CTX_TX_SGL_MODE,
  71. (slow_sgl ? SCSI_TX_SLOW_SGL : SCSI_FAST_SGL));
  72. init_scsi_sgl_context(&y_st_ctx->sgl_params,
  73. &y_st_ctx->data_desc,
  74. sgl_task_params);
  75. /* Mstorm ctx */
  76. SET_FIELD(m_st_ctx->flags,
  77. MSTORM_FCOE_TASK_ST_CTX_TX_SGL_MODE,
  78. (slow_sgl ? SCSI_TX_SLOW_SGL : SCSI_FAST_SGL));
  79. m_st_ctx->sgl_params.sgl_num_sges =
  80. cpu_to_le16(sgl_task_params->num_sges);
  81. } else {
  82. /* Tstorm ctx */
  83. SET_FIELD(t_st_ctx->read_write.flags,
  84. FCOE_TSTORM_FCOE_TASK_ST_CTX_READ_WRITE_RX_SGL_MODE,
  85. (slow_sgl ? SCSI_TX_SLOW_SGL : SCSI_FAST_SGL));
  86. /* Mstorm ctx */
  87. m_st_ctx->data_2_trns_rem = cpu_to_le32(io_size);
  88. init_scsi_sgl_context(&m_st_ctx->sgl_params,
  89. &m_st_ctx->data_desc,
  90. sgl_task_params);
  91. }
  92. /* Init Sqe */
  93. init_common_sqe(task_params, SEND_FCOE_CMD);
  94. return 0;
  95. }
  96. int init_initiator_midpath_unsolicited_fcoe_task(
  97. struct fcoe_task_params *task_params,
  98. struct fcoe_tx_mid_path_params *mid_path_fc_header,
  99. struct scsi_sgl_task_params *tx_sgl_task_params,
  100. struct scsi_sgl_task_params *rx_sgl_task_params,
  101. u8 fw_to_place_fc_header)
  102. {
  103. struct fcoe_task_context *ctx = task_params->context;
  104. const u8 val_byte = ctx->ystorm_ag_context.byte0;
  105. struct ustorm_fcoe_task_ag_ctx *u_ag_ctx;
  106. struct ystorm_fcoe_task_st_ctx *y_st_ctx;
  107. struct tstorm_fcoe_task_st_ctx *t_st_ctx;
  108. struct mstorm_fcoe_task_st_ctx *m_st_ctx;
  109. u32 val;
  110. memset(ctx, 0, sizeof(*(ctx)));
  111. ctx->ystorm_ag_context.byte0 = val_byte;
  112. /* Init Ystorm */
  113. y_st_ctx = &ctx->ystorm_st_context;
  114. init_scsi_sgl_context(&y_st_ctx->sgl_params,
  115. &y_st_ctx->data_desc,
  116. tx_sgl_task_params);
  117. SET_FIELD(y_st_ctx->sgl_mode,
  118. YSTORM_FCOE_TASK_ST_CTX_TX_SGL_MODE, SCSI_FAST_SGL);
  119. y_st_ctx->data_2_trns_rem = cpu_to_le32(task_params->tx_io_size);
  120. y_st_ctx->task_type = (u8)task_params->task_type;
  121. memcpy(&y_st_ctx->tx_info_union.tx_params.mid_path,
  122. mid_path_fc_header, sizeof(struct fcoe_tx_mid_path_params));
  123. /* Init Mstorm */
  124. m_st_ctx = &ctx->mstorm_st_context;
  125. init_scsi_sgl_context(&m_st_ctx->sgl_params,
  126. &m_st_ctx->data_desc,
  127. rx_sgl_task_params);
  128. SET_FIELD(m_st_ctx->flags,
  129. MSTORM_FCOE_TASK_ST_CTX_MP_INCLUDE_FC_HEADER,
  130. fw_to_place_fc_header);
  131. m_st_ctx->data_2_trns_rem = cpu_to_le32(task_params->rx_io_size);
  132. /* Init Tstorm */
  133. t_st_ctx = &ctx->tstorm_st_context;
  134. t_st_ctx->read_only.cid = cpu_to_le32(task_params->conn_cid);
  135. val = cpu_to_le32(task_params->cq_rss_number);
  136. t_st_ctx->read_only.glbl_q_num = val;
  137. t_st_ctx->read_only.task_type = (u8)task_params->task_type;
  138. SET_FIELD(t_st_ctx->read_write.flags,
  139. FCOE_TSTORM_FCOE_TASK_ST_CTX_READ_WRITE_EXP_FIRST_FRAME, 1);
  140. t_st_ctx->read_write.rx_id = cpu_to_le16(FCOE_RX_ID);
  141. /* Init Ustorm */
  142. u_ag_ctx = &ctx->ustorm_ag_context;
  143. u_ag_ctx->global_cq_num = cpu_to_le32(task_params->cq_rss_number);
  144. /* Init SQE */
  145. init_common_sqe(task_params, SEND_FCOE_MIDPATH);
  146. task_params->sqe->additional_info_union.burst_length =
  147. tx_sgl_task_params->total_buffer_size;
  148. SET_FIELD(task_params->sqe->flags,
  149. FCOE_WQE_NUM_SGES, tx_sgl_task_params->num_sges);
  150. SET_FIELD(task_params->sqe->flags, FCOE_WQE_SGL_MODE,
  151. SCSI_FAST_SGL);
  152. return 0;
  153. }
  154. int init_initiator_abort_fcoe_task(struct fcoe_task_params *task_params)
  155. {
  156. init_common_sqe(task_params, SEND_FCOE_ABTS_REQUEST);
  157. return 0;
  158. }
  159. int init_initiator_cleanup_fcoe_task(struct fcoe_task_params *task_params)
  160. {
  161. init_common_sqe(task_params, FCOE_EXCHANGE_CLEANUP);
  162. return 0;
  163. }
  164. int init_initiator_sequence_recovery_fcoe_task(
  165. struct fcoe_task_params *task_params, u32 desired_offset)
  166. {
  167. init_common_sqe(task_params, FCOE_SEQUENCE_RECOVERY);
  168. task_params->sqe->additional_info_union.seq_rec_updated_offset =
  169. desired_offset;
  170. return 0;
  171. }