1 /* QLogic FCoE Offload Driver
2 * Copyright (c) 2016-2017 Cavium Inc.
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
8 #include "drv_fcoe_fw_funcs.h"
9 #include "drv_scsi_fw_funcs.h"
11 #define FCOE_RX_ID (0xFFFFu)
13 static inline void init_common_sqe(struct fcoe_task_params
*task_params
,
14 enum fcoe_sqe_request_type request_type
)
16 memset(task_params
->sqe
, 0, sizeof(*(task_params
->sqe
)));
17 SET_FIELD(task_params
->sqe
->flags
, FCOE_WQE_REQ_TYPE
,
19 task_params
->sqe
->task_id
= task_params
->itid
;
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
,
26 u8 fcp_cmd_payload
[32])
28 struct e4_fcoe_task_context
*ctx
= task_params
->context
;
29 const u8 val_byte
= ctx
->ystorm_ag_context
.byte0
;
30 struct e4_ustorm_fcoe_task_ag_ctx
*u_ag_ctx
;
31 struct ystorm_fcoe_task_st_ctx
*y_st_ctx
;
32 struct tstorm_fcoe_task_st_ctx
*t_st_ctx
;
33 struct mstorm_fcoe_task_st_ctx
*m_st_ctx
;
37 memset(ctx
, 0, sizeof(*(ctx
)));
38 ctx
->ystorm_ag_context
.byte0
= val_byte
;
39 slow_sgl
= scsi_is_slow_sgl(sgl_task_params
->num_sges
,
40 sgl_task_params
->small_mid_sge
);
41 io_size
= (task_params
->task_type
== FCOE_TASK_TYPE_WRITE_INITIATOR
?
42 task_params
->tx_io_size
: task_params
->rx_io_size
);
45 y_st_ctx
= &ctx
->ystorm_st_context
;
46 y_st_ctx
->data_2_trns_rem
= cpu_to_le32(io_size
);
47 y_st_ctx
->task_rety_identifier
= cpu_to_le32(task_retry_id
);
48 y_st_ctx
->task_type
= (u8
)task_params
->task_type
;
49 memcpy(&y_st_ctx
->tx_info_union
.fcp_cmd_payload
,
50 fcp_cmd_payload
, sizeof(struct fcoe_fcp_cmd_payload
));
53 t_st_ctx
= &ctx
->tstorm_st_context
;
54 t_st_ctx
->read_only
.dev_type
= (u8
)(task_params
->is_tape_device
== 1 ?
55 FCOE_TASK_DEV_TYPE_TAPE
:
56 FCOE_TASK_DEV_TYPE_DISK
);
57 t_st_ctx
->read_only
.cid
= cpu_to_le32(task_params
->conn_cid
);
58 val
= cpu_to_le32(task_params
->cq_rss_number
);
59 t_st_ctx
->read_only
.glbl_q_num
= val
;
60 t_st_ctx
->read_only
.fcp_cmd_trns_size
= cpu_to_le32(io_size
);
61 t_st_ctx
->read_only
.task_type
= (u8
)task_params
->task_type
;
62 SET_FIELD(t_st_ctx
->read_write
.flags
,
63 FCOE_TSTORM_FCOE_TASK_ST_CTX_READ_WRITE_EXP_FIRST_FRAME
, 1);
64 t_st_ctx
->read_write
.rx_id
= cpu_to_le16(FCOE_RX_ID
);
67 u_ag_ctx
= &ctx
->ustorm_ag_context
;
68 u_ag_ctx
->global_cq_num
= cpu_to_le32(task_params
->cq_rss_number
);
70 /* Mstorm buffer for sense/rsp data placement */
71 m_st_ctx
= &ctx
->mstorm_st_context
;
72 val
= cpu_to_le32(sense_data_buffer_phys_addr
.hi
);
73 m_st_ctx
->rsp_buf_addr
.hi
= val
;
74 val
= cpu_to_le32(sense_data_buffer_phys_addr
.lo
);
75 m_st_ctx
->rsp_buf_addr
.lo
= val
;
77 if (task_params
->task_type
== FCOE_TASK_TYPE_WRITE_INITIATOR
) {
79 y_st_ctx
->expect_first_xfer
= 1;
81 /* Set the amount of super SGEs. Can be up to 4. */
82 SET_FIELD(y_st_ctx
->sgl_mode
,
83 YSTORM_FCOE_TASK_ST_CTX_TX_SGL_MODE
,
84 (slow_sgl
? SCSI_TX_SLOW_SGL
: SCSI_FAST_SGL
));
85 init_scsi_sgl_context(&y_st_ctx
->sgl_params
,
90 SET_FIELD(m_st_ctx
->flags
,
91 MSTORM_FCOE_TASK_ST_CTX_TX_SGL_MODE
,
92 (slow_sgl
? SCSI_TX_SLOW_SGL
: SCSI_FAST_SGL
));
93 m_st_ctx
->sgl_params
.sgl_num_sges
=
94 cpu_to_le16(sgl_task_params
->num_sges
);
97 SET_FIELD(t_st_ctx
->read_write
.flags
,
98 FCOE_TSTORM_FCOE_TASK_ST_CTX_READ_WRITE_RX_SGL_MODE
,
99 (slow_sgl
? SCSI_TX_SLOW_SGL
: SCSI_FAST_SGL
));
102 m_st_ctx
->data_2_trns_rem
= cpu_to_le32(io_size
);
103 init_scsi_sgl_context(&m_st_ctx
->sgl_params
,
104 &m_st_ctx
->data_desc
,
109 init_common_sqe(task_params
, SEND_FCOE_CMD
);
114 int init_initiator_midpath_unsolicited_fcoe_task(
115 struct fcoe_task_params
*task_params
,
116 struct fcoe_tx_mid_path_params
*mid_path_fc_header
,
117 struct scsi_sgl_task_params
*tx_sgl_task_params
,
118 struct scsi_sgl_task_params
*rx_sgl_task_params
,
119 u8 fw_to_place_fc_header
)
121 struct e4_fcoe_task_context
*ctx
= task_params
->context
;
122 const u8 val_byte
= ctx
->ystorm_ag_context
.byte0
;
123 struct e4_ustorm_fcoe_task_ag_ctx
*u_ag_ctx
;
124 struct ystorm_fcoe_task_st_ctx
*y_st_ctx
;
125 struct tstorm_fcoe_task_st_ctx
*t_st_ctx
;
126 struct mstorm_fcoe_task_st_ctx
*m_st_ctx
;
129 memset(ctx
, 0, sizeof(*(ctx
)));
130 ctx
->ystorm_ag_context
.byte0
= val_byte
;
133 y_st_ctx
= &ctx
->ystorm_st_context
;
134 init_scsi_sgl_context(&y_st_ctx
->sgl_params
,
135 &y_st_ctx
->data_desc
,
137 SET_FIELD(y_st_ctx
->sgl_mode
,
138 YSTORM_FCOE_TASK_ST_CTX_TX_SGL_MODE
, SCSI_FAST_SGL
);
139 y_st_ctx
->data_2_trns_rem
= cpu_to_le32(task_params
->tx_io_size
);
140 y_st_ctx
->task_type
= (u8
)task_params
->task_type
;
141 memcpy(&y_st_ctx
->tx_info_union
.tx_params
.mid_path
,
142 mid_path_fc_header
, sizeof(struct fcoe_tx_mid_path_params
));
145 m_st_ctx
= &ctx
->mstorm_st_context
;
146 init_scsi_sgl_context(&m_st_ctx
->sgl_params
,
147 &m_st_ctx
->data_desc
,
149 SET_FIELD(m_st_ctx
->flags
,
150 MSTORM_FCOE_TASK_ST_CTX_MP_INCLUDE_FC_HEADER
,
151 fw_to_place_fc_header
);
152 m_st_ctx
->data_2_trns_rem
= cpu_to_le32(task_params
->rx_io_size
);
155 t_st_ctx
= &ctx
->tstorm_st_context
;
156 t_st_ctx
->read_only
.cid
= cpu_to_le32(task_params
->conn_cid
);
157 val
= cpu_to_le32(task_params
->cq_rss_number
);
158 t_st_ctx
->read_only
.glbl_q_num
= val
;
159 t_st_ctx
->read_only
.task_type
= (u8
)task_params
->task_type
;
160 SET_FIELD(t_st_ctx
->read_write
.flags
,
161 FCOE_TSTORM_FCOE_TASK_ST_CTX_READ_WRITE_EXP_FIRST_FRAME
, 1);
162 t_st_ctx
->read_write
.rx_id
= cpu_to_le16(FCOE_RX_ID
);
165 u_ag_ctx
= &ctx
->ustorm_ag_context
;
166 u_ag_ctx
->global_cq_num
= cpu_to_le32(task_params
->cq_rss_number
);
169 init_common_sqe(task_params
, SEND_FCOE_MIDPATH
);
170 task_params
->sqe
->additional_info_union
.burst_length
=
171 tx_sgl_task_params
->total_buffer_size
;
172 SET_FIELD(task_params
->sqe
->flags
,
173 FCOE_WQE_NUM_SGES
, tx_sgl_task_params
->num_sges
);
174 SET_FIELD(task_params
->sqe
->flags
, FCOE_WQE_SGL_MODE
,
180 int init_initiator_abort_fcoe_task(struct fcoe_task_params
*task_params
)
182 init_common_sqe(task_params
, SEND_FCOE_ABTS_REQUEST
);
186 int init_initiator_cleanup_fcoe_task(struct fcoe_task_params
*task_params
)
188 init_common_sqe(task_params
, FCOE_EXCHANGE_CLEANUP
);
192 int init_initiator_sequence_recovery_fcoe_task(
193 struct fcoe_task_params
*task_params
, u32 desired_offset
)
195 init_common_sqe(task_params
, FCOE_SEQUENCE_RECOVERY
);
196 task_params
->sqe
->additional_info_union
.seq_rec_updated_offset
=