1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic iSCSI Offload Driver
4 * Copyright (c) 2016 Cavium Inc.
7 #include <linux/blkdev.h>
8 #include <scsi/scsi_tcq.h>
9 #include <linux/delay.h>
12 #include "qedi_iscsi.h"
14 #include "qedi_fw_iscsi.h"
15 #include "qedi_fw_scsi.h"
17 static int qedi_send_iscsi_tmf(struct qedi_conn
*qedi_conn
,
18 struct iscsi_task
*mtask
);
20 void qedi_iscsi_unmap_sg_list(struct qedi_cmd
*cmd
)
22 struct scsi_cmnd
*sc
= cmd
->scsi_cmd
;
24 if (cmd
->io_tbl
.sge_valid
&& sc
) {
25 cmd
->io_tbl
.sge_valid
= 0;
30 static void qedi_process_logout_resp(struct qedi_ctx
*qedi
,
32 struct iscsi_task
*task
,
33 struct qedi_conn
*qedi_conn
)
35 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
36 struct iscsi_logout_rsp
*resp_hdr
;
37 struct iscsi_session
*session
= conn
->session
;
38 struct iscsi_logout_response_hdr
*cqe_logout_response
;
41 cmd
= (struct qedi_cmd
*)task
->dd_data
;
42 cqe_logout_response
= &cqe
->cqe_common
.iscsi_hdr
.logout_response
;
43 spin_lock(&session
->back_lock
);
44 resp_hdr
= (struct iscsi_logout_rsp
*)&qedi_conn
->gen_pdu
.resp_hdr
;
45 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
46 resp_hdr
->opcode
= cqe_logout_response
->opcode
;
47 resp_hdr
->flags
= cqe_logout_response
->flags
;
48 resp_hdr
->hlength
= 0;
50 resp_hdr
->itt
= build_itt(cqe
->cqe_solicited
.itid
, conn
->session
->age
);
51 resp_hdr
->statsn
= cpu_to_be32(cqe_logout_response
->stat_sn
);
52 resp_hdr
->exp_cmdsn
= cpu_to_be32(cqe_logout_response
->exp_cmd_sn
);
53 resp_hdr
->max_cmdsn
= cpu_to_be32(cqe_logout_response
->max_cmd_sn
);
55 resp_hdr
->t2wait
= cpu_to_be32(cqe_logout_response
->time_2_wait
);
56 resp_hdr
->t2retain
= cpu_to_be32(cqe_logout_response
->time_2_retain
);
58 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_TID
,
59 "Freeing tid=0x%x for cid=0x%x\n",
60 cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
62 if (likely(cmd
->io_cmd_in_list
)) {
63 cmd
->io_cmd_in_list
= false;
64 list_del_init(&cmd
->io_cmd
);
65 qedi_conn
->active_cmd_count
--;
67 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
68 "Active cmd list node already deleted, tid=0x%x, cid=0x%x, io_cmd_node=%p\n",
69 cmd
->task_id
, qedi_conn
->iscsi_conn_id
,
73 cmd
->state
= RESPONSE_RECEIVED
;
74 qedi_clear_task_idx(qedi
, cmd
->task_id
);
75 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr
, NULL
, 0);
77 spin_unlock(&session
->back_lock
);
80 static void qedi_process_text_resp(struct qedi_ctx
*qedi
,
82 struct iscsi_task
*task
,
83 struct qedi_conn
*qedi_conn
)
85 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
86 struct iscsi_session
*session
= conn
->session
;
87 struct e4_iscsi_task_context
*task_ctx
;
88 struct iscsi_text_rsp
*resp_hdr_ptr
;
89 struct iscsi_text_response_hdr
*cqe_text_response
;
93 cmd
= (struct qedi_cmd
*)task
->dd_data
;
94 task_ctx
= qedi_get_task_mem(&qedi
->tasks
, cmd
->task_id
);
96 cqe_text_response
= &cqe
->cqe_common
.iscsi_hdr
.text_response
;
97 spin_lock(&session
->back_lock
);
98 resp_hdr_ptr
= (struct iscsi_text_rsp
*)&qedi_conn
->gen_pdu
.resp_hdr
;
99 memset(resp_hdr_ptr
, 0, sizeof(struct iscsi_hdr
));
100 resp_hdr_ptr
->opcode
= cqe_text_response
->opcode
;
101 resp_hdr_ptr
->flags
= cqe_text_response
->flags
;
102 resp_hdr_ptr
->hlength
= 0;
104 hton24(resp_hdr_ptr
->dlength
,
105 (cqe_text_response
->hdr_second_dword
&
106 ISCSI_TEXT_RESPONSE_HDR_DATA_SEG_LEN_MASK
));
108 resp_hdr_ptr
->itt
= build_itt(cqe
->cqe_solicited
.itid
,
110 resp_hdr_ptr
->ttt
= cqe_text_response
->ttt
;
111 resp_hdr_ptr
->statsn
= cpu_to_be32(cqe_text_response
->stat_sn
);
112 resp_hdr_ptr
->exp_cmdsn
= cpu_to_be32(cqe_text_response
->exp_cmd_sn
);
113 resp_hdr_ptr
->max_cmdsn
= cpu_to_be32(cqe_text_response
->max_cmd_sn
);
115 pld_len
= cqe_text_response
->hdr_second_dword
&
116 ISCSI_TEXT_RESPONSE_HDR_DATA_SEG_LEN_MASK
;
117 qedi_conn
->gen_pdu
.resp_wr_ptr
= qedi_conn
->gen_pdu
.resp_buf
+ pld_len
;
119 memset(task_ctx
, '\0', sizeof(*task_ctx
));
121 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_TID
,
122 "Freeing tid=0x%x for cid=0x%x\n",
123 cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
125 if (likely(cmd
->io_cmd_in_list
)) {
126 cmd
->io_cmd_in_list
= false;
127 list_del_init(&cmd
->io_cmd
);
128 qedi_conn
->active_cmd_count
--;
130 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
131 "Active cmd list node already deleted, tid=0x%x, cid=0x%x, io_cmd_node=%p\n",
132 cmd
->task_id
, qedi_conn
->iscsi_conn_id
,
136 cmd
->state
= RESPONSE_RECEIVED
;
137 qedi_clear_task_idx(qedi
, cmd
->task_id
);
139 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr_ptr
,
140 qedi_conn
->gen_pdu
.resp_buf
,
141 (qedi_conn
->gen_pdu
.resp_wr_ptr
-
142 qedi_conn
->gen_pdu
.resp_buf
));
143 spin_unlock(&session
->back_lock
);
146 static void qedi_tmf_resp_work(struct work_struct
*work
)
148 struct qedi_cmd
*qedi_cmd
=
149 container_of(work
, struct qedi_cmd
, tmf_work
);
150 struct qedi_conn
*qedi_conn
= qedi_cmd
->conn
;
151 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
152 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
153 struct iscsi_session
*session
= conn
->session
;
154 struct iscsi_tm_rsp
*resp_hdr_ptr
;
157 set_bit(QEDI_CONN_FW_CLEANUP
, &qedi_conn
->flags
);
158 resp_hdr_ptr
= (struct iscsi_tm_rsp
*)qedi_cmd
->tmf_resp_buf
;
160 iscsi_block_session(session
->cls_session
);
161 rval
= qedi_cleanup_all_io(qedi
, qedi_conn
, qedi_cmd
->task
, true);
163 qedi_clear_task_idx(qedi
, qedi_cmd
->task_id
);
164 iscsi_unblock_session(session
->cls_session
);
168 iscsi_unblock_session(session
->cls_session
);
169 qedi_clear_task_idx(qedi
, qedi_cmd
->task_id
);
171 spin_lock(&session
->back_lock
);
172 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr_ptr
, NULL
, 0);
173 spin_unlock(&session
->back_lock
);
177 clear_bit(QEDI_CONN_FW_CLEANUP
, &qedi_conn
->flags
);
180 static void qedi_process_tmf_resp(struct qedi_ctx
*qedi
,
181 union iscsi_cqe
*cqe
,
182 struct iscsi_task
*task
,
183 struct qedi_conn
*qedi_conn
)
186 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
187 struct iscsi_session
*session
= conn
->session
;
188 struct iscsi_tmf_response_hdr
*cqe_tmp_response
;
189 struct iscsi_tm_rsp
*resp_hdr_ptr
;
190 struct iscsi_tm
*tmf_hdr
;
191 struct qedi_cmd
*qedi_cmd
= NULL
;
193 cqe_tmp_response
= &cqe
->cqe_common
.iscsi_hdr
.tmf_response
;
195 qedi_cmd
= task
->dd_data
;
196 qedi_cmd
->tmf_resp_buf
= kzalloc(sizeof(*resp_hdr_ptr
), GFP_ATOMIC
);
197 if (!qedi_cmd
->tmf_resp_buf
) {
198 QEDI_ERR(&qedi
->dbg_ctx
,
199 "Failed to allocate resp buf, cid=0x%x\n",
200 qedi_conn
->iscsi_conn_id
);
204 spin_lock(&session
->back_lock
);
205 resp_hdr_ptr
= (struct iscsi_tm_rsp
*)qedi_cmd
->tmf_resp_buf
;
206 memset(resp_hdr_ptr
, 0, sizeof(struct iscsi_tm_rsp
));
208 /* Fill up the header */
209 resp_hdr_ptr
->opcode
= cqe_tmp_response
->opcode
;
210 resp_hdr_ptr
->flags
= cqe_tmp_response
->hdr_flags
;
211 resp_hdr_ptr
->response
= cqe_tmp_response
->hdr_response
;
212 resp_hdr_ptr
->hlength
= 0;
214 hton24(resp_hdr_ptr
->dlength
,
215 (cqe_tmp_response
->hdr_second_dword
&
216 ISCSI_TMF_RESPONSE_HDR_DATA_SEG_LEN_MASK
));
217 resp_hdr_ptr
->itt
= build_itt(cqe
->cqe_solicited
.itid
,
219 resp_hdr_ptr
->statsn
= cpu_to_be32(cqe_tmp_response
->stat_sn
);
220 resp_hdr_ptr
->exp_cmdsn
= cpu_to_be32(cqe_tmp_response
->exp_cmd_sn
);
221 resp_hdr_ptr
->max_cmdsn
= cpu_to_be32(cqe_tmp_response
->max_cmd_sn
);
223 tmf_hdr
= (struct iscsi_tm
*)qedi_cmd
->task
->hdr
;
225 if (likely(qedi_cmd
->io_cmd_in_list
)) {
226 qedi_cmd
->io_cmd_in_list
= false;
227 list_del_init(&qedi_cmd
->io_cmd
);
228 qedi_conn
->active_cmd_count
--;
231 if (((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
232 ISCSI_TM_FUNC_LOGICAL_UNIT_RESET
) ||
233 ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
234 ISCSI_TM_FUNC_TARGET_WARM_RESET
) ||
235 ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
236 ISCSI_TM_FUNC_TARGET_COLD_RESET
)) {
237 INIT_WORK(&qedi_cmd
->tmf_work
, qedi_tmf_resp_work
);
238 queue_work(qedi
->tmf_thread
, &qedi_cmd
->tmf_work
);
242 qedi_clear_task_idx(qedi
, qedi_cmd
->task_id
);
244 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr_ptr
, NULL
, 0);
248 spin_unlock(&session
->back_lock
);
251 static void qedi_process_login_resp(struct qedi_ctx
*qedi
,
252 union iscsi_cqe
*cqe
,
253 struct iscsi_task
*task
,
254 struct qedi_conn
*qedi_conn
)
256 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
257 struct iscsi_session
*session
= conn
->session
;
258 struct e4_iscsi_task_context
*task_ctx
;
259 struct iscsi_login_rsp
*resp_hdr_ptr
;
260 struct iscsi_login_response_hdr
*cqe_login_response
;
261 struct qedi_cmd
*cmd
;
264 cmd
= (struct qedi_cmd
*)task
->dd_data
;
266 cqe_login_response
= &cqe
->cqe_common
.iscsi_hdr
.login_response
;
267 task_ctx
= qedi_get_task_mem(&qedi
->tasks
, cmd
->task_id
);
269 spin_lock(&session
->back_lock
);
270 resp_hdr_ptr
= (struct iscsi_login_rsp
*)&qedi_conn
->gen_pdu
.resp_hdr
;
271 memset(resp_hdr_ptr
, 0, sizeof(struct iscsi_login_rsp
));
272 resp_hdr_ptr
->opcode
= cqe_login_response
->opcode
;
273 resp_hdr_ptr
->flags
= cqe_login_response
->flags_attr
;
274 resp_hdr_ptr
->hlength
= 0;
276 hton24(resp_hdr_ptr
->dlength
,
277 (cqe_login_response
->hdr_second_dword
&
278 ISCSI_LOGIN_RESPONSE_HDR_DATA_SEG_LEN_MASK
));
279 resp_hdr_ptr
->itt
= build_itt(cqe
->cqe_solicited
.itid
,
281 resp_hdr_ptr
->tsih
= cqe_login_response
->tsih
;
282 resp_hdr_ptr
->statsn
= cpu_to_be32(cqe_login_response
->stat_sn
);
283 resp_hdr_ptr
->exp_cmdsn
= cpu_to_be32(cqe_login_response
->exp_cmd_sn
);
284 resp_hdr_ptr
->max_cmdsn
= cpu_to_be32(cqe_login_response
->max_cmd_sn
);
285 resp_hdr_ptr
->status_class
= cqe_login_response
->status_class
;
286 resp_hdr_ptr
->status_detail
= cqe_login_response
->status_detail
;
287 pld_len
= cqe_login_response
->hdr_second_dword
&
288 ISCSI_LOGIN_RESPONSE_HDR_DATA_SEG_LEN_MASK
;
289 qedi_conn
->gen_pdu
.resp_wr_ptr
= qedi_conn
->gen_pdu
.resp_buf
+ pld_len
;
291 if (likely(cmd
->io_cmd_in_list
)) {
292 cmd
->io_cmd_in_list
= false;
293 list_del_init(&cmd
->io_cmd
);
294 qedi_conn
->active_cmd_count
--;
297 memset(task_ctx
, '\0', sizeof(*task_ctx
));
299 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr_ptr
,
300 qedi_conn
->gen_pdu
.resp_buf
,
301 (qedi_conn
->gen_pdu
.resp_wr_ptr
-
302 qedi_conn
->gen_pdu
.resp_buf
));
304 spin_unlock(&session
->back_lock
);
305 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_TID
,
306 "Freeing tid=0x%x for cid=0x%x\n",
307 cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
308 cmd
->state
= RESPONSE_RECEIVED
;
309 qedi_clear_task_idx(qedi
, cmd
->task_id
);
312 static void qedi_get_rq_bdq_buf(struct qedi_ctx
*qedi
,
313 struct iscsi_cqe_unsolicited
*cqe
,
318 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
319 "pld_len [%d], bdq_prod_idx [%d], idx [%d]\n",
320 len
, qedi
->bdq_prod_idx
,
321 (qedi
->bdq_prod_idx
% qedi
->rq_num_entries
));
323 /* Obtain buffer address from rqe_opaque */
324 idx
= cqe
->rqe_opaque
;
325 if (idx
> (QEDI_BDQ_NUM
- 1)) {
326 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
327 "wrong idx %d returned by FW, dropping the unsolicited pkt\n",
332 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
333 "rqe_opaque [0x%p], idx [%d]\n", cqe
->rqe_opaque
, idx
);
335 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
336 "unsol_cqe_type = %d\n", cqe
->unsol_cqe_type
);
337 switch (cqe
->unsol_cqe_type
) {
338 case ISCSI_CQE_UNSOLICITED_SINGLE
:
339 case ISCSI_CQE_UNSOLICITED_FIRST
:
341 memcpy(ptr
, (void *)qedi
->bdq
[idx
].buf_addr
, len
);
343 case ISCSI_CQE_UNSOLICITED_MIDDLE
:
344 case ISCSI_CQE_UNSOLICITED_LAST
:
351 static void qedi_put_rq_bdq_buf(struct qedi_ctx
*qedi
,
352 struct iscsi_cqe_unsolicited
*cqe
,
359 /* Obtain buffer address from rqe_opaque */
360 idx
= cqe
->rqe_opaque
;
361 if (idx
> (QEDI_BDQ_NUM
- 1)) {
362 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
363 "wrong idx %d returned by FW, dropping the unsolicited pkt\n",
368 pbl
= (struct scsi_bd
*)qedi
->bdq_pbl
;
369 pbl
+= (qedi
->bdq_prod_idx
% qedi
->rq_num_entries
);
370 pbl
->address
.hi
= cpu_to_le32(QEDI_U64_HI(qedi
->bdq
[idx
].buf_dma
));
371 pbl
->address
.lo
= cpu_to_le32(QEDI_U64_LO(qedi
->bdq
[idx
].buf_dma
));
372 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
373 "pbl [0x%p] pbl->address hi [0x%llx] lo [0x%llx] idx [%d]\n",
374 pbl
, pbl
->address
.hi
, pbl
->address
.lo
, idx
);
375 pbl
->opaque
.iscsi_opaque
.reserved_zero
[0] = 0;
376 pbl
->opaque
.iscsi_opaque
.reserved_zero
[1] = 0;
377 pbl
->opaque
.iscsi_opaque
.reserved_zero
[2] = 0;
378 pbl
->opaque
.iscsi_opaque
.opaque
= cpu_to_le32(idx
);
380 /* Increment producer to let f/w know we've handled the frame */
381 qedi
->bdq_prod_idx
+= count
;
383 writew(qedi
->bdq_prod_idx
, qedi
->bdq_primary_prod
);
384 tmp
= readw(qedi
->bdq_primary_prod
);
386 writew(qedi
->bdq_prod_idx
, qedi
->bdq_secondary_prod
);
387 tmp
= readw(qedi
->bdq_secondary_prod
);
390 static void qedi_unsol_pdu_adjust_bdq(struct qedi_ctx
*qedi
,
391 struct iscsi_cqe_unsolicited
*cqe
,
392 u32 pdu_len
, u32 num_bdqs
,
395 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
396 "num_bdqs [%d]\n", num_bdqs
);
398 qedi_get_rq_bdq_buf(qedi
, cqe
, bdq_data
, pdu_len
);
399 qedi_put_rq_bdq_buf(qedi
, cqe
, (num_bdqs
+ 1));
402 static int qedi_process_nopin_mesg(struct qedi_ctx
*qedi
,
403 union iscsi_cqe
*cqe
,
404 struct iscsi_task
*task
,
405 struct qedi_conn
*qedi_conn
, u16 que_idx
)
407 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
408 struct iscsi_session
*session
= conn
->session
;
409 struct iscsi_nop_in_hdr
*cqe_nop_in
;
410 struct iscsi_nopin
*hdr
;
411 struct qedi_cmd
*cmd
;
412 int tgt_async_nop
= 0;
414 u32 pdu_len
, num_bdqs
;
415 char bdq_data
[QEDI_BDQ_BUF_SIZE
];
418 spin_lock_bh(&session
->back_lock
);
419 cqe_nop_in
= &cqe
->cqe_common
.iscsi_hdr
.nop_in
;
421 pdu_len
= cqe_nop_in
->hdr_second_dword
&
422 ISCSI_NOP_IN_HDR_DATA_SEG_LEN_MASK
;
423 num_bdqs
= pdu_len
/ QEDI_BDQ_BUF_SIZE
;
425 hdr
= (struct iscsi_nopin
*)&qedi_conn
->gen_pdu
.resp_hdr
;
426 memset(hdr
, 0, sizeof(struct iscsi_hdr
));
427 hdr
->opcode
= cqe_nop_in
->opcode
;
428 hdr
->max_cmdsn
= cpu_to_be32(cqe_nop_in
->max_cmd_sn
);
429 hdr
->exp_cmdsn
= cpu_to_be32(cqe_nop_in
->exp_cmd_sn
);
430 hdr
->statsn
= cpu_to_be32(cqe_nop_in
->stat_sn
);
431 hdr
->ttt
= cpu_to_be32(cqe_nop_in
->ttt
);
433 if (cqe
->cqe_common
.cqe_type
== ISCSI_CQE_TYPE_UNSOLICITED
) {
434 spin_lock_irqsave(&qedi
->hba_lock
, flags
);
435 qedi_unsol_pdu_adjust_bdq(qedi
, &cqe
->cqe_unsolicited
,
436 pdu_len
, num_bdqs
, bdq_data
);
437 hdr
->itt
= RESERVED_ITT
;
439 spin_unlock_irqrestore(&qedi
->hba_lock
, flags
);
443 /* Response to one of our nop-outs */
446 hdr
->flags
= ISCSI_FLAG_CMD_FINAL
;
447 hdr
->itt
= build_itt(cqe
->cqe_solicited
.itid
,
451 memcpy(&hdr
->lun
, lun
, sizeof(struct scsi_lun
));
452 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_TID
,
453 "Freeing tid=0x%x for cid=0x%x\n",
454 cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
455 cmd
->state
= RESPONSE_RECEIVED
;
456 spin_lock(&qedi_conn
->list_lock
);
457 if (likely(cmd
->io_cmd_in_list
)) {
458 cmd
->io_cmd_in_list
= false;
459 list_del_init(&cmd
->io_cmd
);
460 qedi_conn
->active_cmd_count
--;
463 spin_unlock(&qedi_conn
->list_lock
);
464 qedi_clear_task_idx(qedi
, cmd
->task_id
);
468 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, bdq_data
, pdu_len
);
470 spin_unlock_bh(&session
->back_lock
);
471 return tgt_async_nop
;
474 static void qedi_process_async_mesg(struct qedi_ctx
*qedi
,
475 union iscsi_cqe
*cqe
,
476 struct iscsi_task
*task
,
477 struct qedi_conn
*qedi_conn
,
480 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
481 struct iscsi_session
*session
= conn
->session
;
482 struct iscsi_async_msg_hdr
*cqe_async_msg
;
483 struct iscsi_async
*resp_hdr
;
485 u32 pdu_len
, num_bdqs
;
486 char bdq_data
[QEDI_BDQ_BUF_SIZE
];
489 spin_lock_bh(&session
->back_lock
);
491 cqe_async_msg
= &cqe
->cqe_common
.iscsi_hdr
.async_msg
;
492 pdu_len
= cqe_async_msg
->hdr_second_dword
&
493 ISCSI_ASYNC_MSG_HDR_DATA_SEG_LEN_MASK
;
494 num_bdqs
= pdu_len
/ QEDI_BDQ_BUF_SIZE
;
496 if (cqe
->cqe_common
.cqe_type
== ISCSI_CQE_TYPE_UNSOLICITED
) {
497 spin_lock_irqsave(&qedi
->hba_lock
, flags
);
498 qedi_unsol_pdu_adjust_bdq(qedi
, &cqe
->cqe_unsolicited
,
499 pdu_len
, num_bdqs
, bdq_data
);
500 spin_unlock_irqrestore(&qedi
->hba_lock
, flags
);
503 resp_hdr
= (struct iscsi_async
*)&qedi_conn
->gen_pdu
.resp_hdr
;
504 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
505 resp_hdr
->opcode
= cqe_async_msg
->opcode
;
506 resp_hdr
->flags
= 0x80;
508 lun
[0] = cpu_to_be32(cqe_async_msg
->lun
.lo
);
509 lun
[1] = cpu_to_be32(cqe_async_msg
->lun
.hi
);
510 memcpy(&resp_hdr
->lun
, lun
, sizeof(struct scsi_lun
));
511 resp_hdr
->exp_cmdsn
= cpu_to_be32(cqe_async_msg
->exp_cmd_sn
);
512 resp_hdr
->max_cmdsn
= cpu_to_be32(cqe_async_msg
->max_cmd_sn
);
513 resp_hdr
->statsn
= cpu_to_be32(cqe_async_msg
->stat_sn
);
515 resp_hdr
->async_event
= cqe_async_msg
->async_event
;
516 resp_hdr
->async_vcode
= cqe_async_msg
->async_vcode
;
518 resp_hdr
->param1
= cpu_to_be16(cqe_async_msg
->param1_rsrv
);
519 resp_hdr
->param2
= cpu_to_be16(cqe_async_msg
->param2_rsrv
);
520 resp_hdr
->param3
= cpu_to_be16(cqe_async_msg
->param3_rsrv
);
522 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr
, bdq_data
,
525 spin_unlock_bh(&session
->back_lock
);
528 static void qedi_process_reject_mesg(struct qedi_ctx
*qedi
,
529 union iscsi_cqe
*cqe
,
530 struct iscsi_task
*task
,
531 struct qedi_conn
*qedi_conn
,
534 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
535 struct iscsi_session
*session
= conn
->session
;
536 struct iscsi_reject_hdr
*cqe_reject
;
537 struct iscsi_reject
*hdr
;
538 u32 pld_len
, num_bdqs
;
541 spin_lock_bh(&session
->back_lock
);
542 cqe_reject
= &cqe
->cqe_common
.iscsi_hdr
.reject
;
543 pld_len
= cqe_reject
->hdr_second_dword
&
544 ISCSI_REJECT_HDR_DATA_SEG_LEN_MASK
;
545 num_bdqs
= pld_len
/ QEDI_BDQ_BUF_SIZE
;
547 if (cqe
->cqe_common
.cqe_type
== ISCSI_CQE_TYPE_UNSOLICITED
) {
548 spin_lock_irqsave(&qedi
->hba_lock
, flags
);
549 qedi_unsol_pdu_adjust_bdq(qedi
, &cqe
->cqe_unsolicited
,
550 pld_len
, num_bdqs
, conn
->data
);
551 spin_unlock_irqrestore(&qedi
->hba_lock
, flags
);
553 hdr
= (struct iscsi_reject
*)&qedi_conn
->gen_pdu
.resp_hdr
;
554 memset(hdr
, 0, sizeof(struct iscsi_hdr
));
555 hdr
->opcode
= cqe_reject
->opcode
;
556 hdr
->reason
= cqe_reject
->hdr_reason
;
557 hdr
->flags
= cqe_reject
->hdr_flags
;
558 hton24(hdr
->dlength
, (cqe_reject
->hdr_second_dword
&
559 ISCSI_REJECT_HDR_DATA_SEG_LEN_MASK
));
560 hdr
->max_cmdsn
= cpu_to_be32(cqe_reject
->max_cmd_sn
);
561 hdr
->exp_cmdsn
= cpu_to_be32(cqe_reject
->exp_cmd_sn
);
562 hdr
->statsn
= cpu_to_be32(cqe_reject
->stat_sn
);
563 hdr
->ffffffff
= cpu_to_be32(0xffffffff);
565 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
,
566 conn
->data
, pld_len
);
567 spin_unlock_bh(&session
->back_lock
);
570 static void qedi_scsi_completion(struct qedi_ctx
*qedi
,
571 union iscsi_cqe
*cqe
,
572 struct iscsi_task
*task
,
573 struct iscsi_conn
*conn
)
575 struct scsi_cmnd
*sc_cmd
;
576 struct qedi_cmd
*cmd
= task
->dd_data
;
577 struct iscsi_session
*session
= conn
->session
;
578 struct iscsi_scsi_rsp
*hdr
;
579 struct iscsi_data_in_hdr
*cqe_data_in
;
581 struct qedi_conn
*qedi_conn
;
585 iscsi_cid
= cqe
->cqe_common
.conn_id
;
586 qedi_conn
= qedi
->cid_que
.conn_cid_tbl
[iscsi_cid
];
588 cqe_data_in
= &cqe
->cqe_common
.iscsi_hdr
.data_in
;
590 cqe
->cqe_common
.error_bitmap
.error_bits
.cqe_error_status_bits
;
592 spin_lock_bh(&session
->back_lock
);
593 /* get the scsi command */
594 sc_cmd
= cmd
->scsi_cmd
;
597 QEDI_WARN(&qedi
->dbg_ctx
, "sc_cmd is NULL!\n");
601 if (!sc_cmd
->SCp
.ptr
) {
602 QEDI_WARN(&qedi
->dbg_ctx
,
603 "SCp.ptr is NULL, returned in another context.\n");
607 if (!sc_cmd
->request
) {
608 QEDI_WARN(&qedi
->dbg_ctx
,
609 "sc_cmd->request is NULL, sc_cmd=%p.\n",
614 if (!sc_cmd
->request
->q
) {
615 QEDI_WARN(&qedi
->dbg_ctx
,
616 "request->q is NULL so request is not valid, sc_cmd=%p.\n",
621 qedi_iscsi_unmap_sg_list(cmd
);
623 hdr
= (struct iscsi_scsi_rsp
*)task
->hdr
;
624 hdr
->opcode
= cqe_data_in
->opcode
;
625 hdr
->max_cmdsn
= cpu_to_be32(cqe_data_in
->max_cmd_sn
);
626 hdr
->exp_cmdsn
= cpu_to_be32(cqe_data_in
->exp_cmd_sn
);
627 hdr
->itt
= build_itt(cqe
->cqe_solicited
.itid
, conn
->session
->age
);
628 hdr
->response
= cqe_data_in
->reserved1
;
629 hdr
->cmd_status
= cqe_data_in
->status_rsvd
;
630 hdr
->flags
= cqe_data_in
->flags
;
631 hdr
->residual_count
= cpu_to_be32(cqe_data_in
->residual_count
);
633 if (hdr
->cmd_status
== SAM_STAT_CHECK_CONDITION
) {
634 datalen
= cqe_data_in
->reserved2
&
635 ISCSI_COMMON_HDR_DATA_SEG_LEN_MASK
;
636 memcpy((char *)conn
->data
, (char *)cmd
->sense_buffer
, datalen
);
639 /* If f/w reports data underrun err then set residual to IO transfer
640 * length, set Underrun flag and clear Overrun flag explicitly
642 if (unlikely(cqe_err_bits
&&
643 GET_FIELD(cqe_err_bits
, CQE_ERROR_BITMAP_UNDER_RUN_ERR
))) {
644 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
645 "Under flow itt=0x%x proto flags=0x%x tid=0x%x cid 0x%x fw resid 0x%x sc dlen 0x%x\n",
646 hdr
->itt
, cqe_data_in
->flags
, cmd
->task_id
,
647 qedi_conn
->iscsi_conn_id
, hdr
->residual_count
,
648 scsi_bufflen(sc_cmd
));
649 hdr
->residual_count
= cpu_to_be32(scsi_bufflen(sc_cmd
));
650 hdr
->flags
|= ISCSI_FLAG_CMD_UNDERFLOW
;
651 hdr
->flags
&= (~ISCSI_FLAG_CMD_OVERFLOW
);
654 spin_lock(&qedi_conn
->list_lock
);
655 if (likely(cmd
->io_cmd_in_list
)) {
656 cmd
->io_cmd_in_list
= false;
657 list_del_init(&cmd
->io_cmd
);
658 qedi_conn
->active_cmd_count
--;
660 spin_unlock(&qedi_conn
->list_lock
);
662 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_TID
,
663 "Freeing tid=0x%x for cid=0x%x\n",
664 cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
665 cmd
->state
= RESPONSE_RECEIVED
;
667 qedi_trace_io(qedi
, task
, cmd
->task_id
, QEDI_IO_TRACE_RSP
);
669 qedi_clear_task_idx(qedi
, cmd
->task_id
);
670 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
,
671 conn
->data
, datalen
);
673 spin_unlock_bh(&session
->back_lock
);
676 static void qedi_mtask_completion(struct qedi_ctx
*qedi
,
677 union iscsi_cqe
*cqe
,
678 struct iscsi_task
*task
,
679 struct qedi_conn
*conn
, uint16_t que_idx
)
681 struct iscsi_conn
*iscsi_conn
;
684 hdr_opcode
= cqe
->cqe_common
.iscsi_hdr
.common
.hdr_first_byte
;
685 iscsi_conn
= conn
->cls_conn
->dd_data
;
687 switch (hdr_opcode
) {
688 case ISCSI_OPCODE_SCSI_RESPONSE
:
689 case ISCSI_OPCODE_DATA_IN
:
690 qedi_scsi_completion(qedi
, cqe
, task
, iscsi_conn
);
692 case ISCSI_OPCODE_LOGIN_RESPONSE
:
693 qedi_process_login_resp(qedi
, cqe
, task
, conn
);
695 case ISCSI_OPCODE_TMF_RESPONSE
:
696 qedi_process_tmf_resp(qedi
, cqe
, task
, conn
);
698 case ISCSI_OPCODE_TEXT_RESPONSE
:
699 qedi_process_text_resp(qedi
, cqe
, task
, conn
);
701 case ISCSI_OPCODE_LOGOUT_RESPONSE
:
702 qedi_process_logout_resp(qedi
, cqe
, task
, conn
);
704 case ISCSI_OPCODE_NOP_IN
:
705 qedi_process_nopin_mesg(qedi
, cqe
, task
, conn
, que_idx
);
708 QEDI_ERR(&qedi
->dbg_ctx
, "unknown opcode\n");
712 static void qedi_process_nopin_local_cmpl(struct qedi_ctx
*qedi
,
713 struct iscsi_cqe_solicited
*cqe
,
714 struct iscsi_task
*task
,
715 struct qedi_conn
*qedi_conn
)
717 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
718 struct iscsi_session
*session
= conn
->session
;
719 struct qedi_cmd
*cmd
= task
->dd_data
;
721 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_UNSOL
,
722 "itid=0x%x, cmd task id=0x%x\n",
723 cqe
->itid
, cmd
->task_id
);
725 cmd
->state
= RESPONSE_RECEIVED
;
726 qedi_clear_task_idx(qedi
, cmd
->task_id
);
728 spin_lock_bh(&session
->back_lock
);
729 __iscsi_put_task(task
);
730 spin_unlock_bh(&session
->back_lock
);
733 static void qedi_process_cmd_cleanup_resp(struct qedi_ctx
*qedi
,
734 struct iscsi_cqe_solicited
*cqe
,
735 struct iscsi_task
*task
,
736 struct iscsi_conn
*conn
)
738 struct qedi_work_map
*work
, *work_tmp
;
739 u32 proto_itt
= cqe
->itid
;
743 struct qedi_cmd
*qedi_cmd
= NULL
;
746 struct qedi_conn
*qedi_conn
;
747 struct qedi_cmd
*dbg_cmd
;
748 struct iscsi_task
*mtask
;
749 struct iscsi_tm
*tmf_hdr
= NULL
;
751 iscsi_cid
= cqe
->conn_id
;
752 qedi_conn
= qedi
->cid_que
.conn_cid_tbl
[iscsi_cid
];
754 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
755 "icid not found 0x%x\n", cqe
->conn_id
);
759 /* Based on this itt get the corresponding qedi_cmd */
760 spin_lock_bh(&qedi_conn
->tmf_work_lock
);
761 list_for_each_entry_safe(work
, work_tmp
, &qedi_conn
->tmf_work_list
,
763 if (work
->rtid
== proto_itt
) {
764 /* We found the command */
765 qedi_cmd
= work
->qedi_cmd
;
766 if (!qedi_cmd
->list_tmf_work
) {
767 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
768 "TMF work not found, cqe->tid=0x%x, cid=0x%x\n",
769 proto_itt
, qedi_conn
->iscsi_conn_id
);
773 mtask
= qedi_cmd
->task
;
774 tmf_hdr
= (struct iscsi_tm
*)mtask
->hdr
;
777 list_del_init(&work
->list
);
779 qedi_cmd
->list_tmf_work
= NULL
;
782 spin_unlock_bh(&qedi_conn
->tmf_work_lock
);
785 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
786 "TMF work, cqe->tid=0x%x, tmf flags=0x%x, cid=0x%x\n",
787 proto_itt
, tmf_hdr
->flags
, qedi_conn
->iscsi_conn_id
);
789 if ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
790 ISCSI_TM_FUNC_ABORT_TASK
) {
791 spin_lock_bh(&conn
->session
->back_lock
);
793 protoitt
= build_itt(get_itt(tmf_hdr
->rtt
),
795 task
= iscsi_itt_to_task(conn
, protoitt
);
797 spin_unlock_bh(&conn
->session
->back_lock
);
800 QEDI_NOTICE(&qedi
->dbg_ctx
,
801 "IO task completed, tmf rtt=0x%x, cid=0x%x\n",
802 get_itt(tmf_hdr
->rtt
),
803 qedi_conn
->iscsi_conn_id
);
807 dbg_cmd
= task
->dd_data
;
809 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
810 "Abort tmf rtt=0x%x, i/o itt=0x%x, i/o tid=0x%x, cid=0x%x\n",
811 get_itt(tmf_hdr
->rtt
), get_itt(task
->itt
),
812 dbg_cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
814 if (qedi_cmd
->state
== CLEANUP_WAIT_FAILED
)
815 qedi_cmd
->state
= CLEANUP_RECV
;
817 qedi_clear_task_idx(qedi_conn
->qedi
, rtid
);
819 spin_lock(&qedi_conn
->list_lock
);
820 list_del_init(&dbg_cmd
->io_cmd
);
821 qedi_conn
->active_cmd_count
--;
822 spin_unlock(&qedi_conn
->list_lock
);
823 qedi_cmd
->state
= CLEANUP_RECV
;
824 wake_up_interruptible(&qedi_conn
->wait_queue
);
826 } else if (qedi_conn
->cmd_cleanup_req
> 0) {
827 spin_lock_bh(&conn
->session
->back_lock
);
828 qedi_get_proto_itt(qedi
, cqe
->itid
, &ptmp_itt
);
829 protoitt
= build_itt(ptmp_itt
, conn
->session
->age
);
830 task
= iscsi_itt_to_task(conn
, protoitt
);
831 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
832 "cleanup io itid=0x%x, protoitt=0x%x, cmd_cleanup_cmpl=%d, cid=0x%x\n",
833 cqe
->itid
, protoitt
, qedi_conn
->cmd_cleanup_cmpl
,
834 qedi_conn
->iscsi_conn_id
);
836 spin_unlock_bh(&conn
->session
->back_lock
);
838 QEDI_NOTICE(&qedi
->dbg_ctx
,
839 "task is null, itid=0x%x, cid=0x%x\n",
840 cqe
->itid
, qedi_conn
->iscsi_conn_id
);
843 qedi_conn
->cmd_cleanup_cmpl
++;
844 wake_up(&qedi_conn
->wait_queue
);
846 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_TID
,
847 "Freeing tid=0x%x for cid=0x%x\n",
848 cqe
->itid
, qedi_conn
->iscsi_conn_id
);
849 qedi_clear_task_idx(qedi_conn
->qedi
, cqe
->itid
);
852 qedi_get_proto_itt(qedi
, cqe
->itid
, &ptmp_itt
);
853 protoitt
= build_itt(ptmp_itt
, conn
->session
->age
);
854 task
= iscsi_itt_to_task(conn
, protoitt
);
855 QEDI_ERR(&qedi
->dbg_ctx
,
856 "Delayed or untracked cleanup response, itt=0x%x, tid=0x%x, cid=0x%x, task=%p\n",
857 protoitt
, cqe
->itid
, qedi_conn
->iscsi_conn_id
, task
);
861 void qedi_fp_process_cqes(struct qedi_work
*work
)
863 struct qedi_ctx
*qedi
= work
->qedi
;
864 union iscsi_cqe
*cqe
= &work
->cqe
;
865 struct iscsi_task
*task
= NULL
;
866 struct iscsi_nopout
*nopout_hdr
;
867 struct qedi_conn
*q_conn
;
868 struct iscsi_conn
*conn
;
869 struct qedi_cmd
*qedi_cmd
;
873 u16 que_idx
= work
->que_idx
;
876 comp_type
= cqe
->cqe_common
.cqe_type
;
877 hdr_opcode
= cqe
->cqe_common
.iscsi_hdr
.common
.hdr_first_byte
;
879 cqe
->cqe_common
.error_bitmap
.error_bits
.cqe_error_status_bits
;
881 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
882 "fw_cid=0x%x, cqe type=0x%x, opcode=0x%x\n",
883 cqe
->cqe_common
.conn_id
, comp_type
, hdr_opcode
);
885 if (comp_type
>= MAX_ISCSI_CQES_TYPE
) {
886 QEDI_WARN(&qedi
->dbg_ctx
, "Invalid CqE type\n");
890 iscsi_cid
= cqe
->cqe_common
.conn_id
;
891 q_conn
= qedi
->cid_que
.conn_cid_tbl
[iscsi_cid
];
893 QEDI_WARN(&qedi
->dbg_ctx
,
894 "Session no longer exists for cid=0x%x!!\n",
899 conn
= q_conn
->cls_conn
->dd_data
;
901 if (unlikely(cqe_err_bits
&&
902 GET_FIELD(cqe_err_bits
,
903 CQE_ERROR_BITMAP_DATA_DIGEST_ERR
))) {
904 iscsi_conn_failure(conn
, ISCSI_ERR_DATA_DGST
);
909 case ISCSI_CQE_TYPE_SOLICITED
:
910 case ISCSI_CQE_TYPE_SOLICITED_WITH_SENSE
:
911 qedi_cmd
= container_of(work
, struct qedi_cmd
, cqe_work
);
912 task
= qedi_cmd
->task
;
914 QEDI_WARN(&qedi
->dbg_ctx
, "task is NULL\n");
918 /* Process NOPIN local completion */
919 nopout_hdr
= (struct iscsi_nopout
*)task
->hdr
;
920 if ((nopout_hdr
->itt
== RESERVED_ITT
) &&
921 (cqe
->cqe_solicited
.itid
!= (u16
)RESERVED_ITT
)) {
922 qedi_process_nopin_local_cmpl(qedi
, &cqe
->cqe_solicited
,
925 cqe
->cqe_solicited
.itid
=
926 qedi_get_itt(cqe
->cqe_solicited
);
927 /* Process other solicited responses */
928 qedi_mtask_completion(qedi
, cqe
, task
, q_conn
, que_idx
);
931 case ISCSI_CQE_TYPE_UNSOLICITED
:
932 switch (hdr_opcode
) {
933 case ISCSI_OPCODE_NOP_IN
:
934 qedi_process_nopin_mesg(qedi
, cqe
, task
, q_conn
,
937 case ISCSI_OPCODE_ASYNC_MSG
:
938 qedi_process_async_mesg(qedi
, cqe
, task
, q_conn
,
941 case ISCSI_OPCODE_REJECT
:
942 qedi_process_reject_mesg(qedi
, cqe
, task
, q_conn
,
946 goto exit_fp_process
;
947 case ISCSI_CQE_TYPE_DUMMY
:
948 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
, "Dummy CqE\n");
949 goto exit_fp_process
;
950 case ISCSI_CQE_TYPE_TASK_CLEANUP
:
951 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
, "CleanUp CqE\n");
952 qedi_process_cmd_cleanup_resp(qedi
, &cqe
->cqe_solicited
, task
,
954 goto exit_fp_process
;
956 QEDI_ERR(&qedi
->dbg_ctx
, "Error cqe.\n");
964 static void qedi_ring_doorbell(struct qedi_conn
*qedi_conn
)
966 struct iscsi_db_data dbell
= { 0 };
970 dbell
.params
|= DB_DEST_XCM
<< ISCSI_DB_DATA_DEST_SHIFT
;
971 dbell
.params
|= DB_AGG_CMD_SET
<< ISCSI_DB_DATA_AGG_CMD_SHIFT
;
973 DQ_XCM_ISCSI_SQ_PROD_CMD
<< ISCSI_DB_DATA_AGG_VAL_SEL_SHIFT
;
975 dbell
.sq_prod
= qedi_conn
->ep
->fw_sq_prod_idx
;
976 writel(*(u32
*)&dbell
, qedi_conn
->ep
->p_doorbell
);
978 /* Make sure fw write idx is coherent, and include both memory barriers
979 * as a failsafe as for some architectures the call is the same but on
980 * others they are two different assembly operations.
983 QEDI_INFO(&qedi_conn
->qedi
->dbg_ctx
, QEDI_LOG_MP_REQ
,
984 "prod_idx=0x%x, fw_prod_idx=0x%x, cid=0x%x\n",
985 qedi_conn
->ep
->sq_prod_idx
, qedi_conn
->ep
->fw_sq_prod_idx
,
986 qedi_conn
->iscsi_conn_id
);
989 static u16
qedi_get_wqe_idx(struct qedi_conn
*qedi_conn
)
991 struct qedi_endpoint
*ep
;
995 rval
= ep
->sq_prod_idx
;
997 /* Increament SQ index */
999 ep
->fw_sq_prod_idx
++;
1000 if (ep
->sq_prod_idx
== QEDI_SQ_SIZE
)
1001 ep
->sq_prod_idx
= 0;
1006 int qedi_send_iscsi_login(struct qedi_conn
*qedi_conn
,
1007 struct iscsi_task
*task
)
1009 struct iscsi_login_req_hdr login_req_pdu_header
;
1010 struct scsi_sgl_task_params tx_sgl_task_params
;
1011 struct scsi_sgl_task_params rx_sgl_task_params
;
1012 struct iscsi_task_params task_params
;
1013 struct e4_iscsi_task_context
*fw_task_ctx
;
1014 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1015 struct iscsi_login_req
*login_hdr
;
1016 struct scsi_sge
*resp_sge
= NULL
;
1017 struct qedi_cmd
*qedi_cmd
;
1018 struct qedi_endpoint
*ep
;
1023 resp_sge
= (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
1024 qedi_cmd
= (struct qedi_cmd
*)task
->dd_data
;
1026 login_hdr
= (struct iscsi_login_req
*)task
->hdr
;
1028 tid
= qedi_get_task_idx(qedi
);
1033 (struct e4_iscsi_task_context
*)qedi_get_task_mem(&qedi
->tasks
,
1035 memset(fw_task_ctx
, 0, sizeof(struct e4_iscsi_task_context
));
1037 qedi_cmd
->task_id
= tid
;
1039 memset(&task_params
, 0, sizeof(task_params
));
1040 memset(&login_req_pdu_header
, 0, sizeof(login_req_pdu_header
));
1041 memset(&tx_sgl_task_params
, 0, sizeof(tx_sgl_task_params
));
1042 memset(&rx_sgl_task_params
, 0, sizeof(rx_sgl_task_params
));
1043 /* Update header info */
1044 login_req_pdu_header
.opcode
= login_hdr
->opcode
;
1045 login_req_pdu_header
.version_min
= login_hdr
->min_version
;
1046 login_req_pdu_header
.version_max
= login_hdr
->max_version
;
1047 login_req_pdu_header
.flags_attr
= login_hdr
->flags
;
1048 login_req_pdu_header
.isid_tabc
= swab32p((u32
*)login_hdr
->isid
);
1049 login_req_pdu_header
.isid_d
= swab16p((u16
*)&login_hdr
->isid
[4]);
1051 login_req_pdu_header
.tsih
= login_hdr
->tsih
;
1052 login_req_pdu_header
.hdr_second_dword
= ntoh24(login_hdr
->dlength
);
1054 qedi_update_itt_map(qedi
, tid
, task
->itt
, qedi_cmd
);
1055 login_req_pdu_header
.itt
= qedi_set_itt(tid
, get_itt(task
->itt
));
1056 login_req_pdu_header
.cid
= qedi_conn
->iscsi_conn_id
;
1057 login_req_pdu_header
.cmd_sn
= be32_to_cpu(login_hdr
->cmdsn
);
1058 login_req_pdu_header
.exp_stat_sn
= be32_to_cpu(login_hdr
->exp_statsn
);
1059 login_req_pdu_header
.exp_stat_sn
= 0;
1061 /* Fill tx AHS and rx buffer */
1062 tx_sgl_task_params
.sgl
=
1063 (struct scsi_sge
*)qedi_conn
->gen_pdu
.req_bd_tbl
;
1064 tx_sgl_task_params
.sgl_phys_addr
.lo
=
1065 (u32
)(qedi_conn
->gen_pdu
.req_dma_addr
);
1066 tx_sgl_task_params
.sgl_phys_addr
.hi
=
1067 (u32
)((u64
)qedi_conn
->gen_pdu
.req_dma_addr
>> 32);
1068 tx_sgl_task_params
.total_buffer_size
= ntoh24(login_hdr
->dlength
);
1069 tx_sgl_task_params
.num_sges
= 1;
1071 rx_sgl_task_params
.sgl
=
1072 (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
1073 rx_sgl_task_params
.sgl_phys_addr
.lo
=
1074 (u32
)(qedi_conn
->gen_pdu
.resp_dma_addr
);
1075 rx_sgl_task_params
.sgl_phys_addr
.hi
=
1076 (u32
)((u64
)qedi_conn
->gen_pdu
.resp_dma_addr
>> 32);
1077 rx_sgl_task_params
.total_buffer_size
= resp_sge
->sge_len
;
1078 rx_sgl_task_params
.num_sges
= 1;
1080 /* Fill fw input params */
1081 task_params
.context
= fw_task_ctx
;
1082 task_params
.conn_icid
= (u16
)qedi_conn
->iscsi_conn_id
;
1083 task_params
.itid
= tid
;
1084 task_params
.cq_rss_number
= 0;
1085 task_params
.tx_io_size
= ntoh24(login_hdr
->dlength
);
1086 task_params
.rx_io_size
= resp_sge
->sge_len
;
1088 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
1089 task_params
.sqe
= &ep
->sq
[sq_idx
];
1091 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
1092 rval
= init_initiator_login_request_task(&task_params
,
1093 &login_req_pdu_header
,
1094 &tx_sgl_task_params
,
1095 &rx_sgl_task_params
);
1099 spin_lock(&qedi_conn
->list_lock
);
1100 list_add_tail(&qedi_cmd
->io_cmd
, &qedi_conn
->active_cmd_list
);
1101 qedi_cmd
->io_cmd_in_list
= true;
1102 qedi_conn
->active_cmd_count
++;
1103 spin_unlock(&qedi_conn
->list_lock
);
1105 qedi_ring_doorbell(qedi_conn
);
1109 int qedi_send_iscsi_logout(struct qedi_conn
*qedi_conn
,
1110 struct iscsi_task
*task
)
1112 struct iscsi_logout_req_hdr logout_pdu_header
;
1113 struct scsi_sgl_task_params tx_sgl_task_params
;
1114 struct scsi_sgl_task_params rx_sgl_task_params
;
1115 struct iscsi_task_params task_params
;
1116 struct e4_iscsi_task_context
*fw_task_ctx
;
1117 struct iscsi_logout
*logout_hdr
= NULL
;
1118 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1119 struct qedi_cmd
*qedi_cmd
;
1120 struct qedi_endpoint
*ep
;
1125 qedi_cmd
= (struct qedi_cmd
*)task
->dd_data
;
1126 logout_hdr
= (struct iscsi_logout
*)task
->hdr
;
1129 tid
= qedi_get_task_idx(qedi
);
1134 (struct e4_iscsi_task_context
*)qedi_get_task_mem(&qedi
->tasks
,
1136 memset(fw_task_ctx
, 0, sizeof(struct e4_iscsi_task_context
));
1138 qedi_cmd
->task_id
= tid
;
1140 memset(&task_params
, 0, sizeof(task_params
));
1141 memset(&logout_pdu_header
, 0, sizeof(logout_pdu_header
));
1142 memset(&tx_sgl_task_params
, 0, sizeof(tx_sgl_task_params
));
1143 memset(&rx_sgl_task_params
, 0, sizeof(rx_sgl_task_params
));
1145 /* Update header info */
1146 logout_pdu_header
.opcode
= logout_hdr
->opcode
;
1147 logout_pdu_header
.reason_code
= 0x80 | logout_hdr
->flags
;
1148 qedi_update_itt_map(qedi
, tid
, task
->itt
, qedi_cmd
);
1149 logout_pdu_header
.itt
= qedi_set_itt(tid
, get_itt(task
->itt
));
1150 logout_pdu_header
.exp_stat_sn
= be32_to_cpu(logout_hdr
->exp_statsn
);
1151 logout_pdu_header
.cmd_sn
= be32_to_cpu(logout_hdr
->cmdsn
);
1152 logout_pdu_header
.cid
= qedi_conn
->iscsi_conn_id
;
1154 /* Fill fw input params */
1155 task_params
.context
= fw_task_ctx
;
1156 task_params
.conn_icid
= (u16
)qedi_conn
->iscsi_conn_id
;
1157 task_params
.itid
= tid
;
1158 task_params
.cq_rss_number
= 0;
1159 task_params
.tx_io_size
= 0;
1160 task_params
.rx_io_size
= 0;
1162 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
1163 task_params
.sqe
= &ep
->sq
[sq_idx
];
1164 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
1166 rval
= init_initiator_logout_request_task(&task_params
,
1172 spin_lock(&qedi_conn
->list_lock
);
1173 list_add_tail(&qedi_cmd
->io_cmd
, &qedi_conn
->active_cmd_list
);
1174 qedi_cmd
->io_cmd_in_list
= true;
1175 qedi_conn
->active_cmd_count
++;
1176 spin_unlock(&qedi_conn
->list_lock
);
1178 qedi_ring_doorbell(qedi_conn
);
1182 int qedi_cleanup_all_io(struct qedi_ctx
*qedi
, struct qedi_conn
*qedi_conn
,
1183 struct iscsi_task
*task
, bool in_recovery
)
1186 struct iscsi_task
*ctask
;
1187 struct qedi_cmd
*cmd
, *cmd_tmp
;
1188 struct iscsi_tm
*tmf_hdr
;
1189 unsigned int lun
= 0;
1190 bool lun_reset
= false;
1191 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
1192 struct iscsi_session
*session
= conn
->session
;
1194 /* From recovery, task is NULL or from tmf resp valid task */
1196 tmf_hdr
= (struct iscsi_tm
*)task
->hdr
;
1198 if ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
1199 ISCSI_TM_FUNC_LOGICAL_UNIT_RESET
) {
1201 lun
= scsilun_to_int(&tmf_hdr
->lun
);
1205 qedi_conn
->cmd_cleanup_req
= 0;
1206 qedi_conn
->cmd_cleanup_cmpl
= 0;
1208 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1209 "active_cmd_count=%d, cid=0x%x, in_recovery=%d, lun_reset=%d\n",
1210 qedi_conn
->active_cmd_count
, qedi_conn
->iscsi_conn_id
,
1211 in_recovery
, lun_reset
);
1214 spin_lock_bh(&session
->back_lock
);
1216 spin_lock(&qedi_conn
->list_lock
);
1218 list_for_each_entry_safe(cmd
, cmd_tmp
, &qedi_conn
->active_cmd_list
,
1225 if (cmd
->scsi_cmd
&& cmd
->scsi_cmd
->device
) {
1226 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1227 "tid=0x%x itt=0x%x scsi_cmd_ptr=%p device=%p task_state=%d cmd_state=0%x cid=0x%x\n",
1228 cmd
->task_id
, get_itt(ctask
->itt
),
1229 cmd
->scsi_cmd
, cmd
->scsi_cmd
->device
,
1230 ctask
->state
, cmd
->state
,
1231 qedi_conn
->iscsi_conn_id
);
1232 if (cmd
->scsi_cmd
->device
->lun
!= lun
)
1236 qedi_conn
->cmd_cleanup_req
++;
1237 qedi_iscsi_cleanup_task(ctask
, true);
1239 list_del_init(&cmd
->io_cmd
);
1240 qedi_conn
->active_cmd_count
--;
1241 QEDI_WARN(&qedi
->dbg_ctx
,
1242 "Deleted active cmd list node io_cmd=%p, cid=0x%x\n",
1243 &cmd
->io_cmd
, qedi_conn
->iscsi_conn_id
);
1246 spin_unlock(&qedi_conn
->list_lock
);
1249 spin_unlock_bh(&session
->back_lock
);
1251 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1252 "cmd_cleanup_req=%d, cid=0x%x\n",
1253 qedi_conn
->cmd_cleanup_req
,
1254 qedi_conn
->iscsi_conn_id
);
1256 rval
= wait_event_interruptible_timeout(qedi_conn
->wait_queue
,
1257 ((qedi_conn
->cmd_cleanup_req
==
1258 qedi_conn
->cmd_cleanup_cmpl
) ||
1262 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1263 "i/o cmd_cleanup_req=%d, equal to cmd_cleanup_cmpl=%d, cid=0x%x\n",
1264 qedi_conn
->cmd_cleanup_req
,
1265 qedi_conn
->cmd_cleanup_cmpl
,
1266 qedi_conn
->iscsi_conn_id
);
1271 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1272 "i/o cmd_cleanup_req=%d, not equal to cmd_cleanup_cmpl=%d, cid=0x%x\n",
1273 qedi_conn
->cmd_cleanup_req
,
1274 qedi_conn
->cmd_cleanup_cmpl
,
1275 qedi_conn
->iscsi_conn_id
);
1277 iscsi_host_for_each_session(qedi
->shost
,
1278 qedi_mark_device_missing
);
1279 qedi_ops
->common
->drain(qedi
->cdev
);
1281 /* Enable IOs for all other sessions except current.*/
1282 if (!wait_event_interruptible_timeout(qedi_conn
->wait_queue
,
1283 (qedi_conn
->cmd_cleanup_req
==
1284 qedi_conn
->cmd_cleanup_cmpl
),
1286 iscsi_host_for_each_session(qedi
->shost
,
1287 qedi_mark_device_available
);
1291 iscsi_host_for_each_session(qedi
->shost
,
1292 qedi_mark_device_available
);
1297 void qedi_clearsq(struct qedi_ctx
*qedi
, struct qedi_conn
*qedi_conn
,
1298 struct iscsi_task
*task
)
1300 struct qedi_endpoint
*qedi_ep
;
1303 qedi_ep
= qedi_conn
->ep
;
1304 qedi_conn
->cmd_cleanup_req
= 0;
1305 qedi_conn
->cmd_cleanup_cmpl
= 0;
1308 QEDI_WARN(&qedi
->dbg_ctx
,
1309 "Cannot proceed, ep already disconnected, cid=0x%x\n",
1310 qedi_conn
->iscsi_conn_id
);
1314 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1315 "Clearing SQ for cid=0x%x, conn=%p, ep=%p\n",
1316 qedi_conn
->iscsi_conn_id
, qedi_conn
, qedi_ep
);
1318 qedi_ops
->clear_sq(qedi
->cdev
, qedi_ep
->handle
);
1320 rval
= qedi_cleanup_all_io(qedi
, qedi_conn
, task
, true);
1322 QEDI_ERR(&qedi
->dbg_ctx
,
1323 "fatal error, need hard reset, cid=0x%x\n",
1324 qedi_conn
->iscsi_conn_id
);
1329 static int qedi_wait_for_cleanup_request(struct qedi_ctx
*qedi
,
1330 struct qedi_conn
*qedi_conn
,
1331 struct iscsi_task
*task
,
1332 struct qedi_cmd
*qedi_cmd
,
1333 struct qedi_work_map
*list_work
)
1335 struct qedi_cmd
*cmd
= (struct qedi_cmd
*)task
->dd_data
;
1338 wait
= wait_event_interruptible_timeout(qedi_conn
->wait_queue
,
1339 ((qedi_cmd
->state
==
1341 ((qedi_cmd
->type
== TYPEIO
) &&
1343 RESPONSE_RECEIVED
))),
1346 qedi_cmd
->state
= CLEANUP_WAIT_FAILED
;
1348 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1349 "Cleanup timedout tid=0x%x, issue connection recovery, cid=0x%x\n",
1350 cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
1357 static void qedi_tmf_work(struct work_struct
*work
)
1359 struct qedi_cmd
*qedi_cmd
=
1360 container_of(work
, struct qedi_cmd
, tmf_work
);
1361 struct qedi_conn
*qedi_conn
= qedi_cmd
->conn
;
1362 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1363 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
1364 struct qedi_work_map
*list_work
= NULL
;
1365 struct iscsi_task
*mtask
;
1366 struct qedi_cmd
*cmd
;
1367 struct iscsi_task
*ctask
;
1368 struct iscsi_tm
*tmf_hdr
;
1372 mtask
= qedi_cmd
->task
;
1373 tmf_hdr
= (struct iscsi_tm
*)mtask
->hdr
;
1374 set_bit(QEDI_CONN_FW_CLEANUP
, &qedi_conn
->flags
);
1376 ctask
= iscsi_itt_to_task(conn
, tmf_hdr
->rtt
);
1377 if (!ctask
|| !ctask
->sc
) {
1378 QEDI_ERR(&qedi
->dbg_ctx
, "Task already completed\n");
1382 cmd
= (struct qedi_cmd
*)ctask
->dd_data
;
1383 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1384 "Abort tmf rtt=0x%x, cmd itt=0x%x, cmd tid=0x%x, cid=0x%x\n",
1385 get_itt(tmf_hdr
->rtt
), get_itt(ctask
->itt
), cmd
->task_id
,
1386 qedi_conn
->iscsi_conn_id
);
1388 if (qedi_do_not_recover
) {
1389 QEDI_ERR(&qedi
->dbg_ctx
, "DONT SEND CLEANUP/ABORT %d\n",
1390 qedi_do_not_recover
);
1394 list_work
= kzalloc(sizeof(*list_work
), GFP_ATOMIC
);
1396 QEDI_ERR(&qedi
->dbg_ctx
, "Memory allocation failed\n");
1400 qedi_cmd
->type
= TYPEIO
;
1401 list_work
->qedi_cmd
= qedi_cmd
;
1402 list_work
->rtid
= cmd
->task_id
;
1403 list_work
->state
= QEDI_WORK_SCHEDULED
;
1404 qedi_cmd
->list_tmf_work
= list_work
;
1406 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1407 "Queue tmf work=%p, list node=%p, cid=0x%x, tmf flags=0x%x\n",
1408 list_work
->ptr_tmf_work
, list_work
, qedi_conn
->iscsi_conn_id
,
1411 spin_lock_bh(&qedi_conn
->tmf_work_lock
);
1412 list_add_tail(&list_work
->list
, &qedi_conn
->tmf_work_list
);
1413 spin_unlock_bh(&qedi_conn
->tmf_work_lock
);
1415 qedi_iscsi_cleanup_task(ctask
, false);
1417 rval
= qedi_wait_for_cleanup_request(qedi
, qedi_conn
, ctask
, qedi_cmd
,
1420 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1421 "FW cleanup got escalated, cid=0x%x\n",
1422 qedi_conn
->iscsi_conn_id
);
1426 tid
= qedi_get_task_idx(qedi
);
1428 QEDI_ERR(&qedi
->dbg_ctx
, "Invalid tid, cid=0x%x\n",
1429 qedi_conn
->iscsi_conn_id
);
1433 qedi_cmd
->task_id
= tid
;
1434 qedi_send_iscsi_tmf(qedi_conn
, qedi_cmd
->task
);
1437 clear_bit(QEDI_CONN_FW_CLEANUP
, &qedi_conn
->flags
);
1441 spin_lock_bh(&qedi_conn
->tmf_work_lock
);
1442 if (!qedi_cmd
->list_tmf_work
) {
1443 list_del_init(&list_work
->list
);
1444 qedi_cmd
->list_tmf_work
= NULL
;
1447 spin_unlock_bh(&qedi_conn
->tmf_work_lock
);
1449 spin_lock(&qedi_conn
->list_lock
);
1450 list_del_init(&cmd
->io_cmd
);
1451 qedi_conn
->active_cmd_count
--;
1452 spin_unlock(&qedi_conn
->list_lock
);
1454 clear_bit(QEDI_CONN_FW_CLEANUP
, &qedi_conn
->flags
);
1457 static int qedi_send_iscsi_tmf(struct qedi_conn
*qedi_conn
,
1458 struct iscsi_task
*mtask
)
1460 struct iscsi_tmf_request_hdr tmf_pdu_header
;
1461 struct iscsi_task_params task_params
;
1462 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1463 struct e4_iscsi_task_context
*fw_task_ctx
;
1464 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
1465 struct iscsi_task
*ctask
;
1466 struct iscsi_tm
*tmf_hdr
;
1467 struct qedi_cmd
*qedi_cmd
;
1468 struct qedi_cmd
*cmd
;
1469 struct qedi_endpoint
*ep
;
1475 tmf_hdr
= (struct iscsi_tm
*)mtask
->hdr
;
1476 qedi_cmd
= (struct qedi_cmd
*)mtask
->dd_data
;
1481 tid
= qedi_get_task_idx(qedi
);
1486 (struct e4_iscsi_task_context
*)qedi_get_task_mem(&qedi
->tasks
,
1488 memset(fw_task_ctx
, 0, sizeof(struct e4_iscsi_task_context
));
1490 qedi_cmd
->task_id
= tid
;
1492 memset(&task_params
, 0, sizeof(task_params
));
1493 memset(&tmf_pdu_header
, 0, sizeof(tmf_pdu_header
));
1495 /* Update header info */
1496 qedi_update_itt_map(qedi
, tid
, mtask
->itt
, qedi_cmd
);
1497 tmf_pdu_header
.itt
= qedi_set_itt(tid
, get_itt(mtask
->itt
));
1498 tmf_pdu_header
.cmd_sn
= be32_to_cpu(tmf_hdr
->cmdsn
);
1500 memcpy(scsi_lun
, &tmf_hdr
->lun
, sizeof(struct scsi_lun
));
1501 tmf_pdu_header
.lun
.lo
= be32_to_cpu(scsi_lun
[0]);
1502 tmf_pdu_header
.lun
.hi
= be32_to_cpu(scsi_lun
[1]);
1504 if ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
1505 ISCSI_TM_FUNC_ABORT_TASK
) {
1506 ctask
= iscsi_itt_to_task(conn
, tmf_hdr
->rtt
);
1507 if (!ctask
|| !ctask
->sc
) {
1508 QEDI_ERR(&qedi
->dbg_ctx
,
1509 "Could not get reference task\n");
1512 cmd
= (struct qedi_cmd
*)ctask
->dd_data
;
1513 tmf_pdu_header
.rtt
=
1514 qedi_set_itt(cmd
->task_id
,
1515 get_itt(tmf_hdr
->rtt
));
1517 tmf_pdu_header
.rtt
= ISCSI_RESERVED_TAG
;
1520 tmf_pdu_header
.opcode
= tmf_hdr
->opcode
;
1521 tmf_pdu_header
.function
= tmf_hdr
->flags
;
1522 tmf_pdu_header
.hdr_second_dword
= ntoh24(tmf_hdr
->dlength
);
1523 tmf_pdu_header
.ref_cmd_sn
= be32_to_cpu(tmf_hdr
->refcmdsn
);
1525 /* Fill fw input params */
1526 task_params
.context
= fw_task_ctx
;
1527 task_params
.conn_icid
= (u16
)qedi_conn
->iscsi_conn_id
;
1528 task_params
.itid
= tid
;
1529 task_params
.cq_rss_number
= 0;
1530 task_params
.tx_io_size
= 0;
1531 task_params
.rx_io_size
= 0;
1533 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
1534 task_params
.sqe
= &ep
->sq
[sq_idx
];
1536 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
1537 rval
= init_initiator_tmf_request_task(&task_params
,
1542 spin_lock(&qedi_conn
->list_lock
);
1543 list_add_tail(&qedi_cmd
->io_cmd
, &qedi_conn
->active_cmd_list
);
1544 qedi_cmd
->io_cmd_in_list
= true;
1545 qedi_conn
->active_cmd_count
++;
1546 spin_unlock(&qedi_conn
->list_lock
);
1548 qedi_ring_doorbell(qedi_conn
);
1552 int qedi_iscsi_abort_work(struct qedi_conn
*qedi_conn
,
1553 struct iscsi_task
*mtask
)
1555 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1556 struct iscsi_tm
*tmf_hdr
;
1557 struct qedi_cmd
*qedi_cmd
= (struct qedi_cmd
*)mtask
->dd_data
;
1560 tmf_hdr
= (struct iscsi_tm
*)mtask
->hdr
;
1561 qedi_cmd
->task
= mtask
;
1563 /* If abort task then schedule the work and return */
1564 if ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
1565 ISCSI_TM_FUNC_ABORT_TASK
) {
1566 qedi_cmd
->state
= CLEANUP_WAIT
;
1567 INIT_WORK(&qedi_cmd
->tmf_work
, qedi_tmf_work
);
1568 queue_work(qedi
->tmf_thread
, &qedi_cmd
->tmf_work
);
1570 } else if (((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
1571 ISCSI_TM_FUNC_LOGICAL_UNIT_RESET
) ||
1572 ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
1573 ISCSI_TM_FUNC_TARGET_WARM_RESET
) ||
1574 ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
1575 ISCSI_TM_FUNC_TARGET_COLD_RESET
)) {
1576 tid
= qedi_get_task_idx(qedi
);
1578 QEDI_ERR(&qedi
->dbg_ctx
, "Invalid tid, cid=0x%x\n",
1579 qedi_conn
->iscsi_conn_id
);
1582 qedi_cmd
->task_id
= tid
;
1584 qedi_send_iscsi_tmf(qedi_conn
, qedi_cmd
->task
);
1587 QEDI_ERR(&qedi
->dbg_ctx
, "Invalid tmf, cid=0x%x\n",
1588 qedi_conn
->iscsi_conn_id
);
1595 int qedi_send_iscsi_text(struct qedi_conn
*qedi_conn
,
1596 struct iscsi_task
*task
)
1598 struct iscsi_text_request_hdr text_request_pdu_header
;
1599 struct scsi_sgl_task_params tx_sgl_task_params
;
1600 struct scsi_sgl_task_params rx_sgl_task_params
;
1601 struct iscsi_task_params task_params
;
1602 struct e4_iscsi_task_context
*fw_task_ctx
;
1603 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1604 struct iscsi_text
*text_hdr
;
1605 struct scsi_sge
*req_sge
= NULL
;
1606 struct scsi_sge
*resp_sge
= NULL
;
1607 struct qedi_cmd
*qedi_cmd
;
1608 struct qedi_endpoint
*ep
;
1613 req_sge
= (struct scsi_sge
*)qedi_conn
->gen_pdu
.req_bd_tbl
;
1614 resp_sge
= (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
1615 qedi_cmd
= (struct qedi_cmd
*)task
->dd_data
;
1616 text_hdr
= (struct iscsi_text
*)task
->hdr
;
1619 tid
= qedi_get_task_idx(qedi
);
1624 (struct e4_iscsi_task_context
*)qedi_get_task_mem(&qedi
->tasks
,
1626 memset(fw_task_ctx
, 0, sizeof(struct e4_iscsi_task_context
));
1628 qedi_cmd
->task_id
= tid
;
1630 memset(&task_params
, 0, sizeof(task_params
));
1631 memset(&text_request_pdu_header
, 0, sizeof(text_request_pdu_header
));
1632 memset(&tx_sgl_task_params
, 0, sizeof(tx_sgl_task_params
));
1633 memset(&rx_sgl_task_params
, 0, sizeof(rx_sgl_task_params
));
1635 /* Update header info */
1636 text_request_pdu_header
.opcode
= text_hdr
->opcode
;
1637 text_request_pdu_header
.flags_attr
= text_hdr
->flags
;
1639 qedi_update_itt_map(qedi
, tid
, task
->itt
, qedi_cmd
);
1640 text_request_pdu_header
.itt
= qedi_set_itt(tid
, get_itt(task
->itt
));
1641 text_request_pdu_header
.ttt
= text_hdr
->ttt
;
1642 text_request_pdu_header
.cmd_sn
= be32_to_cpu(text_hdr
->cmdsn
);
1643 text_request_pdu_header
.exp_stat_sn
= be32_to_cpu(text_hdr
->exp_statsn
);
1644 text_request_pdu_header
.hdr_second_dword
= ntoh24(text_hdr
->dlength
);
1646 /* Fill tx AHS and rx buffer */
1647 tx_sgl_task_params
.sgl
=
1648 (struct scsi_sge
*)qedi_conn
->gen_pdu
.req_bd_tbl
;
1649 tx_sgl_task_params
.sgl_phys_addr
.lo
=
1650 (u32
)(qedi_conn
->gen_pdu
.req_dma_addr
);
1651 tx_sgl_task_params
.sgl_phys_addr
.hi
=
1652 (u32
)((u64
)qedi_conn
->gen_pdu
.req_dma_addr
>> 32);
1653 tx_sgl_task_params
.total_buffer_size
= req_sge
->sge_len
;
1654 tx_sgl_task_params
.num_sges
= 1;
1656 rx_sgl_task_params
.sgl
=
1657 (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
1658 rx_sgl_task_params
.sgl_phys_addr
.lo
=
1659 (u32
)(qedi_conn
->gen_pdu
.resp_dma_addr
);
1660 rx_sgl_task_params
.sgl_phys_addr
.hi
=
1661 (u32
)((u64
)qedi_conn
->gen_pdu
.resp_dma_addr
>> 32);
1662 rx_sgl_task_params
.total_buffer_size
= resp_sge
->sge_len
;
1663 rx_sgl_task_params
.num_sges
= 1;
1665 /* Fill fw input params */
1666 task_params
.context
= fw_task_ctx
;
1667 task_params
.conn_icid
= (u16
)qedi_conn
->iscsi_conn_id
;
1668 task_params
.itid
= tid
;
1669 task_params
.cq_rss_number
= 0;
1670 task_params
.tx_io_size
= ntoh24(text_hdr
->dlength
);
1671 task_params
.rx_io_size
= resp_sge
->sge_len
;
1673 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
1674 task_params
.sqe
= &ep
->sq
[sq_idx
];
1676 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
1677 rval
= init_initiator_text_request_task(&task_params
,
1678 &text_request_pdu_header
,
1679 &tx_sgl_task_params
,
1680 &rx_sgl_task_params
);
1684 spin_lock(&qedi_conn
->list_lock
);
1685 list_add_tail(&qedi_cmd
->io_cmd
, &qedi_conn
->active_cmd_list
);
1686 qedi_cmd
->io_cmd_in_list
= true;
1687 qedi_conn
->active_cmd_count
++;
1688 spin_unlock(&qedi_conn
->list_lock
);
1690 qedi_ring_doorbell(qedi_conn
);
1694 int qedi_send_iscsi_nopout(struct qedi_conn
*qedi_conn
,
1695 struct iscsi_task
*task
,
1696 char *datap
, int data_len
, int unsol
)
1698 struct iscsi_nop_out_hdr nop_out_pdu_header
;
1699 struct scsi_sgl_task_params tx_sgl_task_params
;
1700 struct scsi_sgl_task_params rx_sgl_task_params
;
1701 struct iscsi_task_params task_params
;
1702 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1703 struct e4_iscsi_task_context
*fw_task_ctx
;
1704 struct iscsi_nopout
*nopout_hdr
;
1705 struct scsi_sge
*resp_sge
= NULL
;
1706 struct qedi_cmd
*qedi_cmd
;
1707 struct qedi_endpoint
*ep
;
1713 resp_sge
= (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
1714 qedi_cmd
= (struct qedi_cmd
*)task
->dd_data
;
1715 nopout_hdr
= (struct iscsi_nopout
*)task
->hdr
;
1718 tid
= qedi_get_task_idx(qedi
);
1723 (struct e4_iscsi_task_context
*)qedi_get_task_mem(&qedi
->tasks
,
1725 memset(fw_task_ctx
, 0, sizeof(struct e4_iscsi_task_context
));
1727 qedi_cmd
->task_id
= tid
;
1729 memset(&task_params
, 0, sizeof(task_params
));
1730 memset(&nop_out_pdu_header
, 0, sizeof(nop_out_pdu_header
));
1731 memset(&tx_sgl_task_params
, 0, sizeof(tx_sgl_task_params
));
1732 memset(&rx_sgl_task_params
, 0, sizeof(rx_sgl_task_params
));
1734 /* Update header info */
1735 nop_out_pdu_header
.opcode
= nopout_hdr
->opcode
;
1736 SET_FIELD(nop_out_pdu_header
.flags_attr
, ISCSI_NOP_OUT_HDR_CONST1
, 1);
1737 SET_FIELD(nop_out_pdu_header
.flags_attr
, ISCSI_NOP_OUT_HDR_RSRV
, 0);
1739 memcpy(scsi_lun
, &nopout_hdr
->lun
, sizeof(struct scsi_lun
));
1740 nop_out_pdu_header
.lun
.lo
= be32_to_cpu(scsi_lun
[0]);
1741 nop_out_pdu_header
.lun
.hi
= be32_to_cpu(scsi_lun
[1]);
1742 nop_out_pdu_header
.cmd_sn
= be32_to_cpu(nopout_hdr
->cmdsn
);
1743 nop_out_pdu_header
.exp_stat_sn
= be32_to_cpu(nopout_hdr
->exp_statsn
);
1745 qedi_update_itt_map(qedi
, tid
, task
->itt
, qedi_cmd
);
1747 if (nopout_hdr
->ttt
!= ISCSI_TTT_ALL_ONES
) {
1748 nop_out_pdu_header
.itt
= be32_to_cpu(nopout_hdr
->itt
);
1749 nop_out_pdu_header
.ttt
= be32_to_cpu(nopout_hdr
->ttt
);
1751 nop_out_pdu_header
.itt
= qedi_set_itt(tid
, get_itt(task
->itt
));
1752 nop_out_pdu_header
.ttt
= ISCSI_TTT_ALL_ONES
;
1754 spin_lock(&qedi_conn
->list_lock
);
1755 list_add_tail(&qedi_cmd
->io_cmd
, &qedi_conn
->active_cmd_list
);
1756 qedi_cmd
->io_cmd_in_list
= true;
1757 qedi_conn
->active_cmd_count
++;
1758 spin_unlock(&qedi_conn
->list_lock
);
1761 /* Fill tx AHS and rx buffer */
1763 tx_sgl_task_params
.sgl
=
1764 (struct scsi_sge
*)qedi_conn
->gen_pdu
.req_bd_tbl
;
1765 tx_sgl_task_params
.sgl_phys_addr
.lo
=
1766 (u32
)(qedi_conn
->gen_pdu
.req_dma_addr
);
1767 tx_sgl_task_params
.sgl_phys_addr
.hi
=
1768 (u32
)((u64
)qedi_conn
->gen_pdu
.req_dma_addr
>> 32);
1769 tx_sgl_task_params
.total_buffer_size
= data_len
;
1770 tx_sgl_task_params
.num_sges
= 1;
1772 rx_sgl_task_params
.sgl
=
1773 (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
1774 rx_sgl_task_params
.sgl_phys_addr
.lo
=
1775 (u32
)(qedi_conn
->gen_pdu
.resp_dma_addr
);
1776 rx_sgl_task_params
.sgl_phys_addr
.hi
=
1777 (u32
)((u64
)qedi_conn
->gen_pdu
.resp_dma_addr
>> 32);
1778 rx_sgl_task_params
.total_buffer_size
= resp_sge
->sge_len
;
1779 rx_sgl_task_params
.num_sges
= 1;
1782 /* Fill fw input params */
1783 task_params
.context
= fw_task_ctx
;
1784 task_params
.conn_icid
= (u16
)qedi_conn
->iscsi_conn_id
;
1785 task_params
.itid
= tid
;
1786 task_params
.cq_rss_number
= 0;
1787 task_params
.tx_io_size
= data_len
;
1788 task_params
.rx_io_size
= resp_sge
->sge_len
;
1790 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
1791 task_params
.sqe
= &ep
->sq
[sq_idx
];
1793 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
1794 rval
= init_initiator_nop_out_task(&task_params
,
1795 &nop_out_pdu_header
,
1796 &tx_sgl_task_params
,
1797 &rx_sgl_task_params
);
1801 qedi_ring_doorbell(qedi_conn
);
1805 static int qedi_split_bd(struct qedi_cmd
*cmd
, u64 addr
, int sg_len
,
1808 struct scsi_sge
*bd
= cmd
->io_tbl
.sge_tbl
;
1809 int frag_size
, sg_frags
;
1814 if (addr
% QEDI_PAGE_SIZE
)
1816 (QEDI_PAGE_SIZE
- (addr
% QEDI_PAGE_SIZE
));
1818 frag_size
= (sg_len
> QEDI_BD_SPLIT_SZ
) ? 0 :
1819 (sg_len
% QEDI_BD_SPLIT_SZ
);
1822 frag_size
= QEDI_BD_SPLIT_SZ
;
1824 bd
[bd_index
+ sg_frags
].sge_addr
.lo
= (addr
& 0xffffffff);
1825 bd
[bd_index
+ sg_frags
].sge_addr
.hi
= (addr
>> 32);
1826 bd
[bd_index
+ sg_frags
].sge_len
= (u16
)frag_size
;
1827 QEDI_INFO(&cmd
->conn
->qedi
->dbg_ctx
, QEDI_LOG_IO
,
1828 "split sge %d: addr=%llx, len=%x",
1829 (bd_index
+ sg_frags
), addr
, frag_size
);
1831 addr
+= (u64
)frag_size
;
1833 sg_len
-= frag_size
;
1838 static int qedi_map_scsi_sg(struct qedi_ctx
*qedi
, struct qedi_cmd
*cmd
)
1840 struct scsi_cmnd
*sc
= cmd
->scsi_cmd
;
1841 struct scsi_sge
*bd
= cmd
->io_tbl
.sge_tbl
;
1842 struct scatterlist
*sg
;
1851 WARN_ON(scsi_sg_count(sc
) > QEDI_ISCSI_MAX_BDS_PER_CMD
);
1853 sg_count
= dma_map_sg(&qedi
->pdev
->dev
, scsi_sglist(sc
),
1854 scsi_sg_count(sc
), sc
->sc_data_direction
);
1857 * New condition to send single SGE as cached-SGL.
1858 * Single SGE with length less than 64K.
1860 sg
= scsi_sglist(sc
);
1861 if ((sg_count
== 1) && (sg_dma_len(sg
) <= MAX_SGLEN_FOR_CACHESGL
)) {
1862 sg_len
= sg_dma_len(sg
);
1863 addr
= (u64
)sg_dma_address(sg
);
1865 bd
[bd_count
].sge_addr
.lo
= (addr
& 0xffffffff);
1866 bd
[bd_count
].sge_addr
.hi
= (addr
>> 32);
1867 bd
[bd_count
].sge_len
= (u16
)sg_len
;
1869 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_IO
,
1870 "single-cached-sgl: bd_count:%d addr=%llx, len=%x",
1871 sg_count
, addr
, sg_len
);
1876 scsi_for_each_sg(sc
, sg
, sg_count
, i
) {
1877 sg_len
= sg_dma_len(sg
);
1878 addr
= (u64
)sg_dma_address(sg
);
1879 end_addr
= (addr
+ sg_len
);
1882 * first sg elem in the 'list',
1883 * check if end addr is page-aligned.
1885 if ((i
== 0) && (sg_count
> 1) && (end_addr
% QEDI_PAGE_SIZE
))
1886 cmd
->use_slowpath
= true;
1889 * last sg elem in the 'list',
1890 * check if start addr is page-aligned.
1892 else if ((i
== (sg_count
- 1)) &&
1893 (sg_count
> 1) && (addr
% QEDI_PAGE_SIZE
))
1894 cmd
->use_slowpath
= true;
1897 * middle sg elements in list,
1898 * check if start and end addr is page-aligned
1900 else if ((i
!= 0) && (i
!= (sg_count
- 1)) &&
1901 ((addr
% QEDI_PAGE_SIZE
) ||
1902 (end_addr
% QEDI_PAGE_SIZE
)))
1903 cmd
->use_slowpath
= true;
1905 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_IO
, "sg[%d] size=0x%x",
1908 if (sg_len
> QEDI_BD_SPLIT_SZ
) {
1909 sg_frags
= qedi_split_bd(cmd
, addr
, sg_len
, bd_count
);
1912 bd
[bd_count
].sge_addr
.lo
= addr
& 0xffffffff;
1913 bd
[bd_count
].sge_addr
.hi
= addr
>> 32;
1914 bd
[bd_count
].sge_len
= sg_len
;
1916 byte_count
+= sg_len
;
1917 bd_count
+= sg_frags
;
1920 if (byte_count
!= scsi_bufflen(sc
))
1921 QEDI_ERR(&qedi
->dbg_ctx
,
1922 "byte_count = %d != scsi_bufflen = %d\n", byte_count
,
1925 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_IO
, "byte_count = %d\n",
1928 WARN_ON(byte_count
!= scsi_bufflen(sc
));
1933 static void qedi_iscsi_map_sg_list(struct qedi_cmd
*cmd
)
1936 struct scsi_cmnd
*sc
= cmd
->scsi_cmd
;
1938 if (scsi_sg_count(sc
)) {
1939 bd_count
= qedi_map_scsi_sg(cmd
->conn
->qedi
, cmd
);
1943 struct scsi_sge
*bd
= cmd
->io_tbl
.sge_tbl
;
1945 bd
[0].sge_addr
.lo
= 0;
1946 bd
[0].sge_addr
.hi
= 0;
1950 cmd
->io_tbl
.sge_valid
= bd_count
;
1953 static void qedi_cpy_scsi_cdb(struct scsi_cmnd
*sc
, u32
*dstp
)
1959 lpcnt
= sc
->cmd_len
/ sizeof(dword
);
1960 srcp
= (u8
*)sc
->cmnd
;
1962 memcpy(&dword
, (const void *)srcp
, 4);
1963 *dstp
= cpu_to_be32(dword
);
1967 if (sc
->cmd_len
& 0x3) {
1968 dword
= (u32
)srcp
[0] | ((u32
)srcp
[1] << 8);
1969 *dstp
= cpu_to_be32(dword
);
1973 void qedi_trace_io(struct qedi_ctx
*qedi
, struct iscsi_task
*task
,
1974 u16 tid
, int8_t direction
)
1976 struct qedi_io_log
*io_log
;
1977 struct iscsi_conn
*conn
= task
->conn
;
1978 struct qedi_conn
*qedi_conn
= conn
->dd_data
;
1979 struct scsi_cmnd
*sc_cmd
= task
->sc
;
1980 unsigned long flags
;
1982 spin_lock_irqsave(&qedi
->io_trace_lock
, flags
);
1984 io_log
= &qedi
->io_trace_buf
[qedi
->io_trace_idx
];
1985 io_log
->direction
= direction
;
1986 io_log
->task_id
= tid
;
1987 io_log
->cid
= qedi_conn
->iscsi_conn_id
;
1988 io_log
->lun
= sc_cmd
->device
->lun
;
1989 io_log
->op
= sc_cmd
->cmnd
[0];
1990 io_log
->lba
[0] = sc_cmd
->cmnd
[2];
1991 io_log
->lba
[1] = sc_cmd
->cmnd
[3];
1992 io_log
->lba
[2] = sc_cmd
->cmnd
[4];
1993 io_log
->lba
[3] = sc_cmd
->cmnd
[5];
1994 io_log
->bufflen
= scsi_bufflen(sc_cmd
);
1995 io_log
->sg_count
= scsi_sg_count(sc_cmd
);
1996 io_log
->fast_sgs
= qedi
->fast_sgls
;
1997 io_log
->cached_sgs
= qedi
->cached_sgls
;
1998 io_log
->slow_sgs
= qedi
->slow_sgls
;
1999 io_log
->cached_sge
= qedi
->use_cached_sge
;
2000 io_log
->slow_sge
= qedi
->use_slow_sge
;
2001 io_log
->fast_sge
= qedi
->use_fast_sge
;
2002 io_log
->result
= sc_cmd
->result
;
2003 io_log
->jiffies
= jiffies
;
2004 io_log
->blk_req_cpu
= smp_processor_id();
2006 if (direction
== QEDI_IO_TRACE_REQ
) {
2007 /* For requests we only care about the submission CPU */
2008 io_log
->req_cpu
= smp_processor_id() % qedi
->num_queues
;
2009 io_log
->intr_cpu
= 0;
2010 io_log
->blk_rsp_cpu
= 0;
2011 } else if (direction
== QEDI_IO_TRACE_RSP
) {
2012 io_log
->req_cpu
= smp_processor_id() % qedi
->num_queues
;
2013 io_log
->intr_cpu
= qedi
->intr_cpu
;
2014 io_log
->blk_rsp_cpu
= smp_processor_id();
2017 qedi
->io_trace_idx
++;
2018 if (qedi
->io_trace_idx
== QEDI_IO_TRACE_SIZE
)
2019 qedi
->io_trace_idx
= 0;
2021 qedi
->use_cached_sge
= false;
2022 qedi
->use_slow_sge
= false;
2023 qedi
->use_fast_sge
= false;
2025 spin_unlock_irqrestore(&qedi
->io_trace_lock
, flags
);
2028 int qedi_iscsi_send_ioreq(struct iscsi_task
*task
)
2030 struct iscsi_conn
*conn
= task
->conn
;
2031 struct iscsi_session
*session
= conn
->session
;
2032 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
->cls_session
);
2033 struct qedi_ctx
*qedi
= iscsi_host_priv(shost
);
2034 struct qedi_conn
*qedi_conn
= conn
->dd_data
;
2035 struct qedi_cmd
*cmd
= task
->dd_data
;
2036 struct scsi_cmnd
*sc
= task
->sc
;
2037 struct iscsi_cmd_hdr cmd_pdu_header
;
2038 struct scsi_sgl_task_params tx_sgl_task_params
;
2039 struct scsi_sgl_task_params rx_sgl_task_params
;
2040 struct scsi_sgl_task_params
*prx_sgl
= NULL
;
2041 struct scsi_sgl_task_params
*ptx_sgl
= NULL
;
2042 struct iscsi_task_params task_params
;
2043 struct iscsi_conn_params conn_params
;
2044 struct scsi_initiator_cmd_params cmd_params
;
2045 struct e4_iscsi_task_context
*fw_task_ctx
;
2046 struct iscsi_cls_conn
*cls_conn
;
2047 struct iscsi_scsi_req
*hdr
= (struct iscsi_scsi_req
*)task
->hdr
;
2048 enum iscsi_task_type task_type
= MAX_ISCSI_TASK_TYPE
;
2049 struct qedi_endpoint
*ep
;
2057 cls_conn
= qedi_conn
->cls_conn
;
2058 conn
= cls_conn
->dd_data
;
2060 qedi_iscsi_map_sg_list(cmd
);
2061 int_to_scsilun(sc
->device
->lun
, (struct scsi_lun
*)scsi_lun
);
2063 tid
= qedi_get_task_idx(qedi
);
2068 (struct e4_iscsi_task_context
*)qedi_get_task_mem(&qedi
->tasks
,
2070 memset(fw_task_ctx
, 0, sizeof(struct e4_iscsi_task_context
));
2074 memset(&task_params
, 0, sizeof(task_params
));
2075 memset(&cmd_pdu_header
, 0, sizeof(cmd_pdu_header
));
2076 memset(&tx_sgl_task_params
, 0, sizeof(tx_sgl_task_params
));
2077 memset(&rx_sgl_task_params
, 0, sizeof(rx_sgl_task_params
));
2078 memset(&conn_params
, 0, sizeof(conn_params
));
2079 memset(&cmd_params
, 0, sizeof(cmd_params
));
2081 cq_idx
= smp_processor_id() % qedi
->num_queues
;
2082 /* Update header info */
2083 SET_FIELD(cmd_pdu_header
.flags_attr
, ISCSI_CMD_HDR_ATTR
,
2085 if (hdr
->cdb
[0] != TEST_UNIT_READY
) {
2086 if (sc
->sc_data_direction
== DMA_TO_DEVICE
) {
2087 SET_FIELD(cmd_pdu_header
.flags_attr
,
2088 ISCSI_CMD_HDR_WRITE
, 1);
2089 task_type
= ISCSI_TASK_TYPE_INITIATOR_WRITE
;
2091 SET_FIELD(cmd_pdu_header
.flags_attr
,
2092 ISCSI_CMD_HDR_READ
, 1);
2093 task_type
= ISCSI_TASK_TYPE_INITIATOR_READ
;
2097 cmd_pdu_header
.lun
.lo
= be32_to_cpu(scsi_lun
[0]);
2098 cmd_pdu_header
.lun
.hi
= be32_to_cpu(scsi_lun
[1]);
2100 qedi_update_itt_map(qedi
, tid
, task
->itt
, cmd
);
2101 cmd_pdu_header
.itt
= qedi_set_itt(tid
, get_itt(task
->itt
));
2102 cmd_pdu_header
.expected_transfer_length
= cpu_to_be32(hdr
->data_length
);
2103 cmd_pdu_header
.hdr_second_dword
= ntoh24(hdr
->dlength
);
2104 cmd_pdu_header
.cmd_sn
= be32_to_cpu(hdr
->cmdsn
);
2105 cmd_pdu_header
.hdr_first_byte
= hdr
->opcode
;
2106 qedi_cpy_scsi_cdb(sc
, (u32
*)cmd_pdu_header
.cdb
);
2108 /* Fill tx AHS and rx buffer */
2109 if (task_type
== ISCSI_TASK_TYPE_INITIATOR_WRITE
) {
2110 tx_sgl_task_params
.sgl
= cmd
->io_tbl
.sge_tbl
;
2111 tx_sgl_task_params
.sgl_phys_addr
.lo
=
2112 (u32
)(cmd
->io_tbl
.sge_tbl_dma
);
2113 tx_sgl_task_params
.sgl_phys_addr
.hi
=
2114 (u32
)((u64
)cmd
->io_tbl
.sge_tbl_dma
>> 32);
2115 tx_sgl_task_params
.total_buffer_size
= scsi_bufflen(sc
);
2116 tx_sgl_task_params
.num_sges
= cmd
->io_tbl
.sge_valid
;
2117 if (cmd
->use_slowpath
)
2118 tx_sgl_task_params
.small_mid_sge
= true;
2119 } else if (task_type
== ISCSI_TASK_TYPE_INITIATOR_READ
) {
2120 rx_sgl_task_params
.sgl
= cmd
->io_tbl
.sge_tbl
;
2121 rx_sgl_task_params
.sgl_phys_addr
.lo
=
2122 (u32
)(cmd
->io_tbl
.sge_tbl_dma
);
2123 rx_sgl_task_params
.sgl_phys_addr
.hi
=
2124 (u32
)((u64
)cmd
->io_tbl
.sge_tbl_dma
>> 32);
2125 rx_sgl_task_params
.total_buffer_size
= scsi_bufflen(sc
);
2126 rx_sgl_task_params
.num_sges
= cmd
->io_tbl
.sge_valid
;
2129 /* Add conn param */
2130 conn_params
.first_burst_length
= conn
->session
->first_burst
;
2131 conn_params
.max_send_pdu_length
= conn
->max_xmit_dlength
;
2132 conn_params
.max_burst_length
= conn
->session
->max_burst
;
2133 if (conn
->session
->initial_r2t_en
)
2134 conn_params
.initial_r2t
= true;
2135 if (conn
->session
->imm_data_en
)
2136 conn_params
.immediate_data
= true;
2138 /* Add cmd params */
2139 cmd_params
.sense_data_buffer_phys_addr
.lo
= (u32
)cmd
->sense_buffer_dma
;
2140 cmd_params
.sense_data_buffer_phys_addr
.hi
=
2141 (u32
)((u64
)cmd
->sense_buffer_dma
>> 32);
2142 /* Fill fw input params */
2143 task_params
.context
= fw_task_ctx
;
2144 task_params
.conn_icid
= (u16
)qedi_conn
->iscsi_conn_id
;
2145 task_params
.itid
= tid
;
2146 task_params
.cq_rss_number
= cq_idx
;
2147 if (task_type
== ISCSI_TASK_TYPE_INITIATOR_WRITE
)
2148 task_params
.tx_io_size
= scsi_bufflen(sc
);
2149 else if (task_type
== ISCSI_TASK_TYPE_INITIATOR_READ
)
2150 task_params
.rx_io_size
= scsi_bufflen(sc
);
2152 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
2153 task_params
.sqe
= &ep
->sq
[sq_idx
];
2155 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_IO
,
2156 "%s: %s-SGL: sg_len=0x%x num_sges=0x%x first-sge-lo=0x%x first-sge-hi=0x%x\n",
2157 (task_type
== ISCSI_TASK_TYPE_INITIATOR_WRITE
) ?
2158 "Write " : "Read ", (cmd
->io_tbl
.sge_valid
== 1) ?
2159 "Single" : (cmd
->use_slowpath
? "SLOW" : "FAST"),
2160 (u16
)cmd
->io_tbl
.sge_valid
, scsi_bufflen(sc
),
2161 (u32
)(cmd
->io_tbl
.sge_tbl_dma
),
2162 (u32
)((u64
)cmd
->io_tbl
.sge_tbl_dma
>> 32));
2164 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
2166 if (task_params
.tx_io_size
!= 0)
2167 ptx_sgl
= &tx_sgl_task_params
;
2168 if (task_params
.rx_io_size
!= 0)
2169 prx_sgl
= &rx_sgl_task_params
;
2171 rval
= init_initiator_rw_iscsi_task(&task_params
, &conn_params
,
2172 &cmd_params
, &cmd_pdu_header
,
2178 spin_lock(&qedi_conn
->list_lock
);
2179 list_add_tail(&cmd
->io_cmd
, &qedi_conn
->active_cmd_list
);
2180 cmd
->io_cmd_in_list
= true;
2181 qedi_conn
->active_cmd_count
++;
2182 spin_unlock(&qedi_conn
->list_lock
);
2184 qedi_ring_doorbell(qedi_conn
);
2188 int qedi_iscsi_cleanup_task(struct iscsi_task
*task
, bool mark_cmd_node_deleted
)
2190 struct iscsi_task_params task_params
;
2191 struct qedi_endpoint
*ep
;
2192 struct iscsi_conn
*conn
= task
->conn
;
2193 struct qedi_conn
*qedi_conn
= conn
->dd_data
;
2194 struct qedi_cmd
*cmd
= task
->dd_data
;
2198 QEDI_INFO(&qedi_conn
->qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
2199 "issue cleanup tid=0x%x itt=0x%x task_state=%d cmd_state=0%x cid=0x%x\n",
2200 cmd
->task_id
, get_itt(task
->itt
), task
->state
,
2201 cmd
->state
, qedi_conn
->iscsi_conn_id
);
2203 memset(&task_params
, 0, sizeof(task_params
));
2206 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
2208 task_params
.sqe
= &ep
->sq
[sq_idx
];
2209 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
2210 task_params
.itid
= cmd
->task_id
;
2212 rval
= init_cleanup_task(&task_params
);
2216 qedi_ring_doorbell(qedi_conn
);