Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* QLogic FCoE Offload Driver
0003  * Copyright (c) 2016-2018 Cavium Inc.
0004  */
0005 #include "drv_fcoe_fw_funcs.h"
0006 #include "drv_scsi_fw_funcs.h"
0007 
0008 #define FCOE_RX_ID (0xFFFFu)
0009 
0010 static inline void init_common_sqe(struct fcoe_task_params *task_params,
0011                    enum fcoe_sqe_request_type request_type)
0012 {
0013     memset(task_params->sqe, 0, sizeof(*(task_params->sqe)));
0014     SET_FIELD(task_params->sqe->flags, FCOE_WQE_REQ_TYPE,
0015           request_type);
0016     task_params->sqe->task_id = task_params->itid;
0017 }
0018 
0019 int init_initiator_rw_fcoe_task(struct fcoe_task_params *task_params,
0020                 struct scsi_sgl_task_params *sgl_task_params,
0021                 struct regpair sense_data_buffer_phys_addr,
0022                 u32 task_retry_id,
0023                 u8 fcp_cmd_payload[32])
0024 {
0025     struct fcoe_task_context *ctx = task_params->context;
0026     const u8 val_byte = ctx->ystorm_ag_context.byte0;
0027     struct ustorm_fcoe_task_ag_ctx *u_ag_ctx;
0028     struct ystorm_fcoe_task_st_ctx *y_st_ctx;
0029     struct tstorm_fcoe_task_st_ctx *t_st_ctx;
0030     struct mstorm_fcoe_task_st_ctx *m_st_ctx;
0031     u32 io_size, val;
0032     bool slow_sgl;
0033 
0034     memset(ctx, 0, sizeof(*(ctx)));
0035     ctx->ystorm_ag_context.byte0 = val_byte;
0036     slow_sgl = scsi_is_slow_sgl(sgl_task_params->num_sges,
0037                     sgl_task_params->small_mid_sge);
0038     io_size = (task_params->task_type == FCOE_TASK_TYPE_WRITE_INITIATOR ?
0039            task_params->tx_io_size : task_params->rx_io_size);
0040 
0041     /* Ystorm ctx */
0042     y_st_ctx = &ctx->ystorm_st_context;
0043     y_st_ctx->data_2_trns_rem = cpu_to_le32(io_size);
0044     y_st_ctx->task_rety_identifier = cpu_to_le32(task_retry_id);
0045     y_st_ctx->task_type = (u8)task_params->task_type;
0046     memcpy(&y_st_ctx->tx_info_union.fcp_cmd_payload,
0047            fcp_cmd_payload, sizeof(struct fcoe_fcp_cmd_payload));
0048 
0049     /* Tstorm ctx */
0050     t_st_ctx = &ctx->tstorm_st_context;
0051     t_st_ctx->read_only.dev_type = (u8)(task_params->is_tape_device == 1 ?
0052                         FCOE_TASK_DEV_TYPE_TAPE :
0053                         FCOE_TASK_DEV_TYPE_DISK);
0054     t_st_ctx->read_only.cid = cpu_to_le32(task_params->conn_cid);
0055     val = cpu_to_le32(task_params->cq_rss_number);
0056     t_st_ctx->read_only.glbl_q_num = val;
0057     t_st_ctx->read_only.fcp_cmd_trns_size = cpu_to_le32(io_size);
0058     t_st_ctx->read_only.task_type = (u8)task_params->task_type;
0059     SET_FIELD(t_st_ctx->read_write.flags,
0060           FCOE_TSTORM_FCOE_TASK_ST_CTX_READ_WRITE_EXP_FIRST_FRAME, 1);
0061     t_st_ctx->read_write.rx_id = cpu_to_le16(FCOE_RX_ID);
0062 
0063     /* Ustorm ctx */
0064     u_ag_ctx = &ctx->ustorm_ag_context;
0065     u_ag_ctx->global_cq_num = cpu_to_le32(task_params->cq_rss_number);
0066 
0067     /* Mstorm buffer for sense/rsp data placement */
0068     m_st_ctx = &ctx->mstorm_st_context;
0069     val = cpu_to_le32(sense_data_buffer_phys_addr.hi);
0070     m_st_ctx->rsp_buf_addr.hi = val;
0071     val = cpu_to_le32(sense_data_buffer_phys_addr.lo);
0072     m_st_ctx->rsp_buf_addr.lo = val;
0073 
0074     if (task_params->task_type == FCOE_TASK_TYPE_WRITE_INITIATOR) {
0075         /* Ystorm ctx */
0076         y_st_ctx->expect_first_xfer = 1;
0077 
0078         /* Set the amount of super SGEs. Can be up to 4. */
0079         SET_FIELD(y_st_ctx->sgl_mode,
0080               YSTORM_FCOE_TASK_ST_CTX_TX_SGL_MODE,
0081               (slow_sgl ? SCSI_TX_SLOW_SGL : SCSI_FAST_SGL));
0082         init_scsi_sgl_context(&y_st_ctx->sgl_params,
0083                       &y_st_ctx->data_desc,
0084                       sgl_task_params);
0085 
0086         /* Mstorm ctx */
0087         SET_FIELD(m_st_ctx->flags,
0088               MSTORM_FCOE_TASK_ST_CTX_TX_SGL_MODE,
0089               (slow_sgl ? SCSI_TX_SLOW_SGL : SCSI_FAST_SGL));
0090         m_st_ctx->sgl_params.sgl_num_sges =
0091             cpu_to_le16(sgl_task_params->num_sges);
0092     } else {
0093         /* Tstorm ctx */
0094         SET_FIELD(t_st_ctx->read_write.flags,
0095               FCOE_TSTORM_FCOE_TASK_ST_CTX_READ_WRITE_RX_SGL_MODE,
0096               (slow_sgl ? SCSI_TX_SLOW_SGL : SCSI_FAST_SGL));
0097 
0098         /* Mstorm ctx */
0099         m_st_ctx->data_2_trns_rem = cpu_to_le32(io_size);
0100         init_scsi_sgl_context(&m_st_ctx->sgl_params,
0101                       &m_st_ctx->data_desc,
0102                       sgl_task_params);
0103     }
0104 
0105     /* Init Sqe */
0106     init_common_sqe(task_params, SEND_FCOE_CMD);
0107 
0108     return 0;
0109 }
0110 
0111 int init_initiator_midpath_unsolicited_fcoe_task(
0112     struct fcoe_task_params *task_params,
0113     struct fcoe_tx_mid_path_params *mid_path_fc_header,
0114     struct scsi_sgl_task_params *tx_sgl_task_params,
0115     struct scsi_sgl_task_params *rx_sgl_task_params,
0116     u8 fw_to_place_fc_header)
0117 {
0118     struct fcoe_task_context *ctx = task_params->context;
0119     const u8 val_byte = ctx->ystorm_ag_context.byte0;
0120     struct ustorm_fcoe_task_ag_ctx *u_ag_ctx;
0121     struct ystorm_fcoe_task_st_ctx *y_st_ctx;
0122     struct tstorm_fcoe_task_st_ctx *t_st_ctx;
0123     struct mstorm_fcoe_task_st_ctx *m_st_ctx;
0124     u32 val;
0125 
0126     memset(ctx, 0, sizeof(*(ctx)));
0127     ctx->ystorm_ag_context.byte0 = val_byte;
0128 
0129     /* Init Ystorm */
0130     y_st_ctx = &ctx->ystorm_st_context;
0131     init_scsi_sgl_context(&y_st_ctx->sgl_params,
0132                   &y_st_ctx->data_desc,
0133                   tx_sgl_task_params);
0134     SET_FIELD(y_st_ctx->sgl_mode,
0135           YSTORM_FCOE_TASK_ST_CTX_TX_SGL_MODE, SCSI_FAST_SGL);
0136     y_st_ctx->data_2_trns_rem = cpu_to_le32(task_params->tx_io_size);
0137     y_st_ctx->task_type = (u8)task_params->task_type;
0138     memcpy(&y_st_ctx->tx_info_union.tx_params.mid_path,
0139            mid_path_fc_header, sizeof(struct fcoe_tx_mid_path_params));
0140 
0141     /* Init Mstorm */
0142     m_st_ctx = &ctx->mstorm_st_context;
0143     init_scsi_sgl_context(&m_st_ctx->sgl_params,
0144                   &m_st_ctx->data_desc,
0145                   rx_sgl_task_params);
0146     SET_FIELD(m_st_ctx->flags,
0147           MSTORM_FCOE_TASK_ST_CTX_MP_INCLUDE_FC_HEADER,
0148           fw_to_place_fc_header);
0149     m_st_ctx->data_2_trns_rem = cpu_to_le32(task_params->rx_io_size);
0150 
0151     /* Init Tstorm */
0152     t_st_ctx = &ctx->tstorm_st_context;
0153     t_st_ctx->read_only.cid = cpu_to_le32(task_params->conn_cid);
0154     val = cpu_to_le32(task_params->cq_rss_number);
0155     t_st_ctx->read_only.glbl_q_num = val;
0156     t_st_ctx->read_only.task_type = (u8)task_params->task_type;
0157     SET_FIELD(t_st_ctx->read_write.flags,
0158           FCOE_TSTORM_FCOE_TASK_ST_CTX_READ_WRITE_EXP_FIRST_FRAME, 1);
0159     t_st_ctx->read_write.rx_id = cpu_to_le16(FCOE_RX_ID);
0160 
0161     /* Init Ustorm */
0162     u_ag_ctx = &ctx->ustorm_ag_context;
0163     u_ag_ctx->global_cq_num = cpu_to_le32(task_params->cq_rss_number);
0164 
0165     /* Init SQE */
0166     init_common_sqe(task_params, SEND_FCOE_MIDPATH);
0167     task_params->sqe->additional_info_union.burst_length =
0168                     tx_sgl_task_params->total_buffer_size;
0169     SET_FIELD(task_params->sqe->flags,
0170           FCOE_WQE_NUM_SGES, tx_sgl_task_params->num_sges);
0171     SET_FIELD(task_params->sqe->flags, FCOE_WQE_SGL_MODE,
0172           SCSI_FAST_SGL);
0173 
0174     return 0;
0175 }
0176 
0177 int init_initiator_abort_fcoe_task(struct fcoe_task_params *task_params)
0178 {
0179     init_common_sqe(task_params, SEND_FCOE_ABTS_REQUEST);
0180     return 0;
0181 }
0182 
0183 int init_initiator_cleanup_fcoe_task(struct fcoe_task_params *task_params)
0184 {
0185     init_common_sqe(task_params, FCOE_EXCHANGE_CLEANUP);
0186     return 0;
0187 }
0188 
0189 int init_initiator_sequence_recovery_fcoe_task(
0190     struct fcoe_task_params *task_params, u32 desired_offset)
0191 {
0192     init_common_sqe(task_params, FCOE_SEQUENCE_RECOVERY);
0193     task_params->sqe->additional_info_union.seq_rec_updated_offset =
0194                                 desired_offset;
0195     return 0;
0196 }