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