2 * QLogic iSCSI Offload Driver
3 * Copyright (c) 2016 Cavium Inc.
5 * This software is available under the terms of the GNU General Public License
6 * (GPL) Version 2, available from the file COPYING in the main directory of
10 #include <linux/blkdev.h>
11 #include <scsi/scsi_tcq.h>
12 #include <linux/delay.h>
15 #include "qedi_iscsi.h"
17 #include "qedi_fw_iscsi.h"
18 #include "qedi_fw_scsi.h"
20 static int qedi_send_iscsi_tmf(struct qedi_conn
*qedi_conn
,
21 struct iscsi_task
*mtask
);
23 void qedi_iscsi_unmap_sg_list(struct qedi_cmd
*cmd
)
25 struct scsi_cmnd
*sc
= cmd
->scsi_cmd
;
27 if (cmd
->io_tbl
.sge_valid
&& sc
) {
28 cmd
->io_tbl
.sge_valid
= 0;
33 static void qedi_process_logout_resp(struct qedi_ctx
*qedi
,
35 struct iscsi_task
*task
,
36 struct qedi_conn
*qedi_conn
)
38 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
39 struct iscsi_logout_rsp
*resp_hdr
;
40 struct iscsi_session
*session
= conn
->session
;
41 struct iscsi_logout_response_hdr
*cqe_logout_response
;
44 cmd
= (struct qedi_cmd
*)task
->dd_data
;
45 cqe_logout_response
= &cqe
->cqe_common
.iscsi_hdr
.logout_response
;
46 spin_lock(&session
->back_lock
);
47 resp_hdr
= (struct iscsi_logout_rsp
*)&qedi_conn
->gen_pdu
.resp_hdr
;
48 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
49 resp_hdr
->opcode
= cqe_logout_response
->opcode
;
50 resp_hdr
->flags
= cqe_logout_response
->flags
;
51 resp_hdr
->hlength
= 0;
53 resp_hdr
->itt
= build_itt(cqe
->cqe_solicited
.itid
, conn
->session
->age
);
54 resp_hdr
->statsn
= cpu_to_be32(cqe_logout_response
->stat_sn
);
55 resp_hdr
->exp_cmdsn
= cpu_to_be32(cqe_logout_response
->exp_cmd_sn
);
56 resp_hdr
->max_cmdsn
= cpu_to_be32(cqe_logout_response
->max_cmd_sn
);
58 resp_hdr
->t2wait
= cpu_to_be32(cqe_logout_response
->time_2_wait
);
59 resp_hdr
->t2retain
= cpu_to_be32(cqe_logout_response
->time_2_retain
);
61 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_TID
,
62 "Freeing tid=0x%x for cid=0x%x\n",
63 cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
65 if (likely(cmd
->io_cmd_in_list
)) {
66 cmd
->io_cmd_in_list
= false;
67 list_del_init(&cmd
->io_cmd
);
68 qedi_conn
->active_cmd_count
--;
70 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
71 "Active cmd list node already deleted, tid=0x%x, cid=0x%x, io_cmd_node=%p\n",
72 cmd
->task_id
, qedi_conn
->iscsi_conn_id
,
76 cmd
->state
= RESPONSE_RECEIVED
;
77 qedi_clear_task_idx(qedi
, cmd
->task_id
);
78 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr
, NULL
, 0);
80 spin_unlock(&session
->back_lock
);
83 static void qedi_process_text_resp(struct qedi_ctx
*qedi
,
85 struct iscsi_task
*task
,
86 struct qedi_conn
*qedi_conn
)
88 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
89 struct iscsi_session
*session
= conn
->session
;
90 struct e4_iscsi_task_context
*task_ctx
;
91 struct iscsi_text_rsp
*resp_hdr_ptr
;
92 struct iscsi_text_response_hdr
*cqe_text_response
;
96 cmd
= (struct qedi_cmd
*)task
->dd_data
;
97 task_ctx
= qedi_get_task_mem(&qedi
->tasks
, cmd
->task_id
);
99 cqe_text_response
= &cqe
->cqe_common
.iscsi_hdr
.text_response
;
100 spin_lock(&session
->back_lock
);
101 resp_hdr_ptr
= (struct iscsi_text_rsp
*)&qedi_conn
->gen_pdu
.resp_hdr
;
102 memset(resp_hdr_ptr
, 0, sizeof(struct iscsi_hdr
));
103 resp_hdr_ptr
->opcode
= cqe_text_response
->opcode
;
104 resp_hdr_ptr
->flags
= cqe_text_response
->flags
;
105 resp_hdr_ptr
->hlength
= 0;
107 hton24(resp_hdr_ptr
->dlength
,
108 (cqe_text_response
->hdr_second_dword
&
109 ISCSI_TEXT_RESPONSE_HDR_DATA_SEG_LEN_MASK
));
111 resp_hdr_ptr
->itt
= build_itt(cqe
->cqe_solicited
.itid
,
113 resp_hdr_ptr
->ttt
= cqe_text_response
->ttt
;
114 resp_hdr_ptr
->statsn
= cpu_to_be32(cqe_text_response
->stat_sn
);
115 resp_hdr_ptr
->exp_cmdsn
= cpu_to_be32(cqe_text_response
->exp_cmd_sn
);
116 resp_hdr_ptr
->max_cmdsn
= cpu_to_be32(cqe_text_response
->max_cmd_sn
);
118 pld_len
= cqe_text_response
->hdr_second_dword
&
119 ISCSI_TEXT_RESPONSE_HDR_DATA_SEG_LEN_MASK
;
120 qedi_conn
->gen_pdu
.resp_wr_ptr
= qedi_conn
->gen_pdu
.resp_buf
+ pld_len
;
122 memset(task_ctx
, '\0', sizeof(*task_ctx
));
124 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_TID
,
125 "Freeing tid=0x%x for cid=0x%x\n",
126 cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
128 if (likely(cmd
->io_cmd_in_list
)) {
129 cmd
->io_cmd_in_list
= false;
130 list_del_init(&cmd
->io_cmd
);
131 qedi_conn
->active_cmd_count
--;
133 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
134 "Active cmd list node already deleted, tid=0x%x, cid=0x%x, io_cmd_node=%p\n",
135 cmd
->task_id
, qedi_conn
->iscsi_conn_id
,
139 cmd
->state
= RESPONSE_RECEIVED
;
140 qedi_clear_task_idx(qedi
, cmd
->task_id
);
142 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr_ptr
,
143 qedi_conn
->gen_pdu
.resp_buf
,
144 (qedi_conn
->gen_pdu
.resp_wr_ptr
-
145 qedi_conn
->gen_pdu
.resp_buf
));
146 spin_unlock(&session
->back_lock
);
149 static void qedi_tmf_resp_work(struct work_struct
*work
)
151 struct qedi_cmd
*qedi_cmd
=
152 container_of(work
, struct qedi_cmd
, tmf_work
);
153 struct qedi_conn
*qedi_conn
= qedi_cmd
->conn
;
154 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
155 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
156 struct iscsi_session
*session
= conn
->session
;
157 struct iscsi_tm_rsp
*resp_hdr_ptr
;
158 struct iscsi_cls_session
*cls_sess
;
161 set_bit(QEDI_CONN_FW_CLEANUP
, &qedi_conn
->flags
);
162 resp_hdr_ptr
= (struct iscsi_tm_rsp
*)qedi_cmd
->tmf_resp_buf
;
163 cls_sess
= iscsi_conn_to_session(qedi_conn
->cls_conn
);
165 iscsi_block_session(session
->cls_session
);
166 rval
= qedi_cleanup_all_io(qedi
, qedi_conn
, qedi_cmd
->task
, true);
168 qedi_clear_task_idx(qedi
, qedi_cmd
->task_id
);
169 iscsi_unblock_session(session
->cls_session
);
173 iscsi_unblock_session(session
->cls_session
);
174 qedi_clear_task_idx(qedi
, qedi_cmd
->task_id
);
176 spin_lock(&session
->back_lock
);
177 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr_ptr
, NULL
, 0);
178 spin_unlock(&session
->back_lock
);
182 clear_bit(QEDI_CONN_FW_CLEANUP
, &qedi_conn
->flags
);
185 static void qedi_process_tmf_resp(struct qedi_ctx
*qedi
,
186 union iscsi_cqe
*cqe
,
187 struct iscsi_task
*task
,
188 struct qedi_conn
*qedi_conn
)
191 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
192 struct iscsi_session
*session
= conn
->session
;
193 struct iscsi_tmf_response_hdr
*cqe_tmp_response
;
194 struct iscsi_tm_rsp
*resp_hdr_ptr
;
195 struct iscsi_tm
*tmf_hdr
;
196 struct qedi_cmd
*qedi_cmd
= NULL
;
198 cqe_tmp_response
= &cqe
->cqe_common
.iscsi_hdr
.tmf_response
;
200 qedi_cmd
= task
->dd_data
;
201 qedi_cmd
->tmf_resp_buf
= kzalloc(sizeof(*resp_hdr_ptr
), GFP_ATOMIC
);
202 if (!qedi_cmd
->tmf_resp_buf
) {
203 QEDI_ERR(&qedi
->dbg_ctx
,
204 "Failed to allocate resp buf, cid=0x%x\n",
205 qedi_conn
->iscsi_conn_id
);
209 spin_lock(&session
->back_lock
);
210 resp_hdr_ptr
= (struct iscsi_tm_rsp
*)qedi_cmd
->tmf_resp_buf
;
211 memset(resp_hdr_ptr
, 0, sizeof(struct iscsi_tm_rsp
));
213 /* Fill up the header */
214 resp_hdr_ptr
->opcode
= cqe_tmp_response
->opcode
;
215 resp_hdr_ptr
->flags
= cqe_tmp_response
->hdr_flags
;
216 resp_hdr_ptr
->response
= cqe_tmp_response
->hdr_response
;
217 resp_hdr_ptr
->hlength
= 0;
219 hton24(resp_hdr_ptr
->dlength
,
220 (cqe_tmp_response
->hdr_second_dword
&
221 ISCSI_TMF_RESPONSE_HDR_DATA_SEG_LEN_MASK
));
222 resp_hdr_ptr
->itt
= build_itt(cqe
->cqe_solicited
.itid
,
224 resp_hdr_ptr
->statsn
= cpu_to_be32(cqe_tmp_response
->stat_sn
);
225 resp_hdr_ptr
->exp_cmdsn
= cpu_to_be32(cqe_tmp_response
->exp_cmd_sn
);
226 resp_hdr_ptr
->max_cmdsn
= cpu_to_be32(cqe_tmp_response
->max_cmd_sn
);
228 tmf_hdr
= (struct iscsi_tm
*)qedi_cmd
->task
->hdr
;
230 if (likely(qedi_cmd
->io_cmd_in_list
)) {
231 qedi_cmd
->io_cmd_in_list
= false;
232 list_del_init(&qedi_cmd
->io_cmd
);
233 qedi_conn
->active_cmd_count
--;
236 if (((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
237 ISCSI_TM_FUNC_LOGICAL_UNIT_RESET
) ||
238 ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
239 ISCSI_TM_FUNC_TARGET_WARM_RESET
) ||
240 ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
241 ISCSI_TM_FUNC_TARGET_COLD_RESET
)) {
242 INIT_WORK(&qedi_cmd
->tmf_work
, qedi_tmf_resp_work
);
243 queue_work(qedi
->tmf_thread
, &qedi_cmd
->tmf_work
);
247 qedi_clear_task_idx(qedi
, qedi_cmd
->task_id
);
249 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr_ptr
, NULL
, 0);
253 spin_unlock(&session
->back_lock
);
256 static void qedi_process_login_resp(struct qedi_ctx
*qedi
,
257 union iscsi_cqe
*cqe
,
258 struct iscsi_task
*task
,
259 struct qedi_conn
*qedi_conn
)
261 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
262 struct iscsi_session
*session
= conn
->session
;
263 struct e4_iscsi_task_context
*task_ctx
;
264 struct iscsi_login_rsp
*resp_hdr_ptr
;
265 struct iscsi_login_response_hdr
*cqe_login_response
;
266 struct qedi_cmd
*cmd
;
269 cmd
= (struct qedi_cmd
*)task
->dd_data
;
271 cqe_login_response
= &cqe
->cqe_common
.iscsi_hdr
.login_response
;
272 task_ctx
= qedi_get_task_mem(&qedi
->tasks
, cmd
->task_id
);
274 spin_lock(&session
->back_lock
);
275 resp_hdr_ptr
= (struct iscsi_login_rsp
*)&qedi_conn
->gen_pdu
.resp_hdr
;
276 memset(resp_hdr_ptr
, 0, sizeof(struct iscsi_login_rsp
));
277 resp_hdr_ptr
->opcode
= cqe_login_response
->opcode
;
278 resp_hdr_ptr
->flags
= cqe_login_response
->flags_attr
;
279 resp_hdr_ptr
->hlength
= 0;
281 hton24(resp_hdr_ptr
->dlength
,
282 (cqe_login_response
->hdr_second_dword
&
283 ISCSI_LOGIN_RESPONSE_HDR_DATA_SEG_LEN_MASK
));
284 resp_hdr_ptr
->itt
= build_itt(cqe
->cqe_solicited
.itid
,
286 resp_hdr_ptr
->tsih
= cqe_login_response
->tsih
;
287 resp_hdr_ptr
->statsn
= cpu_to_be32(cqe_login_response
->stat_sn
);
288 resp_hdr_ptr
->exp_cmdsn
= cpu_to_be32(cqe_login_response
->exp_cmd_sn
);
289 resp_hdr_ptr
->max_cmdsn
= cpu_to_be32(cqe_login_response
->max_cmd_sn
);
290 resp_hdr_ptr
->status_class
= cqe_login_response
->status_class
;
291 resp_hdr_ptr
->status_detail
= cqe_login_response
->status_detail
;
292 pld_len
= cqe_login_response
->hdr_second_dword
&
293 ISCSI_LOGIN_RESPONSE_HDR_DATA_SEG_LEN_MASK
;
294 qedi_conn
->gen_pdu
.resp_wr_ptr
= qedi_conn
->gen_pdu
.resp_buf
+ pld_len
;
296 if (likely(cmd
->io_cmd_in_list
)) {
297 cmd
->io_cmd_in_list
= false;
298 list_del_init(&cmd
->io_cmd
);
299 qedi_conn
->active_cmd_count
--;
302 memset(task_ctx
, '\0', sizeof(*task_ctx
));
304 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr_ptr
,
305 qedi_conn
->gen_pdu
.resp_buf
,
306 (qedi_conn
->gen_pdu
.resp_wr_ptr
-
307 qedi_conn
->gen_pdu
.resp_buf
));
309 spin_unlock(&session
->back_lock
);
310 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_TID
,
311 "Freeing tid=0x%x for cid=0x%x\n",
312 cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
313 cmd
->state
= RESPONSE_RECEIVED
;
314 qedi_clear_task_idx(qedi
, cmd
->task_id
);
317 static void qedi_get_rq_bdq_buf(struct qedi_ctx
*qedi
,
318 struct iscsi_cqe_unsolicited
*cqe
,
323 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
324 "pld_len [%d], bdq_prod_idx [%d], idx [%d]\n",
325 len
, qedi
->bdq_prod_idx
,
326 (qedi
->bdq_prod_idx
% qedi
->rq_num_entries
));
328 /* Obtain buffer address from rqe_opaque */
329 idx
= cqe
->rqe_opaque
;
330 if (idx
> (QEDI_BDQ_NUM
- 1)) {
331 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
332 "wrong idx %d returned by FW, dropping the unsolicited pkt\n",
337 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
338 "rqe_opaque [0x%p], idx [%d]\n", cqe
->rqe_opaque
, idx
);
340 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
341 "unsol_cqe_type = %d\n", cqe
->unsol_cqe_type
);
342 switch (cqe
->unsol_cqe_type
) {
343 case ISCSI_CQE_UNSOLICITED_SINGLE
:
344 case ISCSI_CQE_UNSOLICITED_FIRST
:
346 memcpy(ptr
, (void *)qedi
->bdq
[idx
].buf_addr
, len
);
348 case ISCSI_CQE_UNSOLICITED_MIDDLE
:
349 case ISCSI_CQE_UNSOLICITED_LAST
:
356 static void qedi_put_rq_bdq_buf(struct qedi_ctx
*qedi
,
357 struct iscsi_cqe_unsolicited
*cqe
,
364 /* Obtain buffer address from rqe_opaque */
365 idx
= cqe
->rqe_opaque
;
366 if (idx
> (QEDI_BDQ_NUM
- 1)) {
367 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
368 "wrong idx %d returned by FW, dropping the unsolicited pkt\n",
373 pbl
= (struct scsi_bd
*)qedi
->bdq_pbl
;
374 pbl
+= (qedi
->bdq_prod_idx
% qedi
->rq_num_entries
);
375 pbl
->address
.hi
= cpu_to_le32(QEDI_U64_HI(qedi
->bdq
[idx
].buf_dma
));
376 pbl
->address
.lo
= cpu_to_le32(QEDI_U64_LO(qedi
->bdq
[idx
].buf_dma
));
377 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
378 "pbl [0x%p] pbl->address hi [0x%llx] lo [0x%llx] idx [%d]\n",
379 pbl
, pbl
->address
.hi
, pbl
->address
.lo
, idx
);
380 pbl
->opaque
.iscsi_opaque
.reserved_zero
[0] = 0;
381 pbl
->opaque
.iscsi_opaque
.reserved_zero
[1] = 0;
382 pbl
->opaque
.iscsi_opaque
.reserved_zero
[2] = 0;
383 pbl
->opaque
.iscsi_opaque
.opaque
= cpu_to_le32(idx
);
385 /* Increment producer to let f/w know we've handled the frame */
386 qedi
->bdq_prod_idx
+= count
;
388 writew(qedi
->bdq_prod_idx
, qedi
->bdq_primary_prod
);
389 tmp
= readw(qedi
->bdq_primary_prod
);
391 writew(qedi
->bdq_prod_idx
, qedi
->bdq_secondary_prod
);
392 tmp
= readw(qedi
->bdq_secondary_prod
);
395 static void qedi_unsol_pdu_adjust_bdq(struct qedi_ctx
*qedi
,
396 struct iscsi_cqe_unsolicited
*cqe
,
397 u32 pdu_len
, u32 num_bdqs
,
400 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
401 "num_bdqs [%d]\n", num_bdqs
);
403 qedi_get_rq_bdq_buf(qedi
, cqe
, bdq_data
, pdu_len
);
404 qedi_put_rq_bdq_buf(qedi
, cqe
, (num_bdqs
+ 1));
407 static int qedi_process_nopin_mesg(struct qedi_ctx
*qedi
,
408 union iscsi_cqe
*cqe
,
409 struct iscsi_task
*task
,
410 struct qedi_conn
*qedi_conn
, u16 que_idx
)
412 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
413 struct iscsi_session
*session
= conn
->session
;
414 struct iscsi_nop_in_hdr
*cqe_nop_in
;
415 struct iscsi_nopin
*hdr
;
416 struct qedi_cmd
*cmd
;
417 int tgt_async_nop
= 0;
419 u32 pdu_len
, num_bdqs
;
420 char bdq_data
[QEDI_BDQ_BUF_SIZE
];
423 spin_lock_bh(&session
->back_lock
);
424 cqe_nop_in
= &cqe
->cqe_common
.iscsi_hdr
.nop_in
;
426 pdu_len
= cqe_nop_in
->hdr_second_dword
&
427 ISCSI_NOP_IN_HDR_DATA_SEG_LEN_MASK
;
428 num_bdqs
= pdu_len
/ QEDI_BDQ_BUF_SIZE
;
430 hdr
= (struct iscsi_nopin
*)&qedi_conn
->gen_pdu
.resp_hdr
;
431 memset(hdr
, 0, sizeof(struct iscsi_hdr
));
432 hdr
->opcode
= cqe_nop_in
->opcode
;
433 hdr
->max_cmdsn
= cpu_to_be32(cqe_nop_in
->max_cmd_sn
);
434 hdr
->exp_cmdsn
= cpu_to_be32(cqe_nop_in
->exp_cmd_sn
);
435 hdr
->statsn
= cpu_to_be32(cqe_nop_in
->stat_sn
);
436 hdr
->ttt
= cpu_to_be32(cqe_nop_in
->ttt
);
438 if (cqe
->cqe_common
.cqe_type
== ISCSI_CQE_TYPE_UNSOLICITED
) {
439 spin_lock_irqsave(&qedi
->hba_lock
, flags
);
440 qedi_unsol_pdu_adjust_bdq(qedi
, &cqe
->cqe_unsolicited
,
441 pdu_len
, num_bdqs
, bdq_data
);
442 hdr
->itt
= RESERVED_ITT
;
444 spin_unlock_irqrestore(&qedi
->hba_lock
, flags
);
448 /* Response to one of our nop-outs */
451 hdr
->flags
= ISCSI_FLAG_CMD_FINAL
;
452 hdr
->itt
= build_itt(cqe
->cqe_solicited
.itid
,
456 memcpy(&hdr
->lun
, lun
, sizeof(struct scsi_lun
));
457 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_TID
,
458 "Freeing tid=0x%x for cid=0x%x\n",
459 cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
460 cmd
->state
= RESPONSE_RECEIVED
;
461 spin_lock(&qedi_conn
->list_lock
);
462 if (likely(cmd
->io_cmd_in_list
)) {
463 cmd
->io_cmd_in_list
= false;
464 list_del_init(&cmd
->io_cmd
);
465 qedi_conn
->active_cmd_count
--;
468 spin_unlock(&qedi_conn
->list_lock
);
469 qedi_clear_task_idx(qedi
, cmd
->task_id
);
473 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, bdq_data
, pdu_len
);
475 spin_unlock_bh(&session
->back_lock
);
476 return tgt_async_nop
;
479 static void qedi_process_async_mesg(struct qedi_ctx
*qedi
,
480 union iscsi_cqe
*cqe
,
481 struct iscsi_task
*task
,
482 struct qedi_conn
*qedi_conn
,
485 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
486 struct iscsi_session
*session
= conn
->session
;
487 struct iscsi_async_msg_hdr
*cqe_async_msg
;
488 struct iscsi_async
*resp_hdr
;
490 u32 pdu_len
, num_bdqs
;
491 char bdq_data
[QEDI_BDQ_BUF_SIZE
];
494 spin_lock_bh(&session
->back_lock
);
496 cqe_async_msg
= &cqe
->cqe_common
.iscsi_hdr
.async_msg
;
497 pdu_len
= cqe_async_msg
->hdr_second_dword
&
498 ISCSI_ASYNC_MSG_HDR_DATA_SEG_LEN_MASK
;
499 num_bdqs
= pdu_len
/ QEDI_BDQ_BUF_SIZE
;
501 if (cqe
->cqe_common
.cqe_type
== ISCSI_CQE_TYPE_UNSOLICITED
) {
502 spin_lock_irqsave(&qedi
->hba_lock
, flags
);
503 qedi_unsol_pdu_adjust_bdq(qedi
, &cqe
->cqe_unsolicited
,
504 pdu_len
, num_bdqs
, bdq_data
);
505 spin_unlock_irqrestore(&qedi
->hba_lock
, flags
);
508 resp_hdr
= (struct iscsi_async
*)&qedi_conn
->gen_pdu
.resp_hdr
;
509 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
510 resp_hdr
->opcode
= cqe_async_msg
->opcode
;
511 resp_hdr
->flags
= 0x80;
513 lun
[0] = cpu_to_be32(cqe_async_msg
->lun
.lo
);
514 lun
[1] = cpu_to_be32(cqe_async_msg
->lun
.hi
);
515 memcpy(&resp_hdr
->lun
, lun
, sizeof(struct scsi_lun
));
516 resp_hdr
->exp_cmdsn
= cpu_to_be32(cqe_async_msg
->exp_cmd_sn
);
517 resp_hdr
->max_cmdsn
= cpu_to_be32(cqe_async_msg
->max_cmd_sn
);
518 resp_hdr
->statsn
= cpu_to_be32(cqe_async_msg
->stat_sn
);
520 resp_hdr
->async_event
= cqe_async_msg
->async_event
;
521 resp_hdr
->async_vcode
= cqe_async_msg
->async_vcode
;
523 resp_hdr
->param1
= cpu_to_be16(cqe_async_msg
->param1_rsrv
);
524 resp_hdr
->param2
= cpu_to_be16(cqe_async_msg
->param2_rsrv
);
525 resp_hdr
->param3
= cpu_to_be16(cqe_async_msg
->param3_rsrv
);
527 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr
, bdq_data
,
530 spin_unlock_bh(&session
->back_lock
);
533 static void qedi_process_reject_mesg(struct qedi_ctx
*qedi
,
534 union iscsi_cqe
*cqe
,
535 struct iscsi_task
*task
,
536 struct qedi_conn
*qedi_conn
,
539 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
540 struct iscsi_session
*session
= conn
->session
;
541 struct iscsi_reject_hdr
*cqe_reject
;
542 struct iscsi_reject
*hdr
;
543 u32 pld_len
, num_bdqs
;
546 spin_lock_bh(&session
->back_lock
);
547 cqe_reject
= &cqe
->cqe_common
.iscsi_hdr
.reject
;
548 pld_len
= cqe_reject
->hdr_second_dword
&
549 ISCSI_REJECT_HDR_DATA_SEG_LEN_MASK
;
550 num_bdqs
= pld_len
/ QEDI_BDQ_BUF_SIZE
;
552 if (cqe
->cqe_common
.cqe_type
== ISCSI_CQE_TYPE_UNSOLICITED
) {
553 spin_lock_irqsave(&qedi
->hba_lock
, flags
);
554 qedi_unsol_pdu_adjust_bdq(qedi
, &cqe
->cqe_unsolicited
,
555 pld_len
, num_bdqs
, conn
->data
);
556 spin_unlock_irqrestore(&qedi
->hba_lock
, flags
);
558 hdr
= (struct iscsi_reject
*)&qedi_conn
->gen_pdu
.resp_hdr
;
559 memset(hdr
, 0, sizeof(struct iscsi_hdr
));
560 hdr
->opcode
= cqe_reject
->opcode
;
561 hdr
->reason
= cqe_reject
->hdr_reason
;
562 hdr
->flags
= cqe_reject
->hdr_flags
;
563 hton24(hdr
->dlength
, (cqe_reject
->hdr_second_dword
&
564 ISCSI_REJECT_HDR_DATA_SEG_LEN_MASK
));
565 hdr
->max_cmdsn
= cpu_to_be32(cqe_reject
->max_cmd_sn
);
566 hdr
->exp_cmdsn
= cpu_to_be32(cqe_reject
->exp_cmd_sn
);
567 hdr
->statsn
= cpu_to_be32(cqe_reject
->stat_sn
);
568 hdr
->ffffffff
= cpu_to_be32(0xffffffff);
570 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
,
571 conn
->data
, pld_len
);
572 spin_unlock_bh(&session
->back_lock
);
575 static void qedi_scsi_completion(struct qedi_ctx
*qedi
,
576 union iscsi_cqe
*cqe
,
577 struct iscsi_task
*task
,
578 struct iscsi_conn
*conn
)
580 struct scsi_cmnd
*sc_cmd
;
581 struct qedi_cmd
*cmd
= task
->dd_data
;
582 struct iscsi_session
*session
= conn
->session
;
583 struct iscsi_scsi_rsp
*hdr
;
584 struct iscsi_data_in_hdr
*cqe_data_in
;
586 struct qedi_conn
*qedi_conn
;
590 iscsi_cid
= cqe
->cqe_common
.conn_id
;
591 qedi_conn
= qedi
->cid_que
.conn_cid_tbl
[iscsi_cid
];
593 cqe_data_in
= &cqe
->cqe_common
.iscsi_hdr
.data_in
;
595 cqe
->cqe_common
.error_bitmap
.error_bits
.cqe_error_status_bits
;
597 spin_lock_bh(&session
->back_lock
);
598 /* get the scsi command */
599 sc_cmd
= cmd
->scsi_cmd
;
602 QEDI_WARN(&qedi
->dbg_ctx
, "sc_cmd is NULL!\n");
606 if (!sc_cmd
->SCp
.ptr
) {
607 QEDI_WARN(&qedi
->dbg_ctx
,
608 "SCp.ptr is NULL, returned in another context.\n");
612 if (!sc_cmd
->request
) {
613 QEDI_WARN(&qedi
->dbg_ctx
,
614 "sc_cmd->request is NULL, sc_cmd=%p.\n",
619 if (!sc_cmd
->request
->special
) {
620 QEDI_WARN(&qedi
->dbg_ctx
,
621 "request->special is NULL so request not valid, sc_cmd=%p.\n",
626 if (!sc_cmd
->request
->q
) {
627 QEDI_WARN(&qedi
->dbg_ctx
,
628 "request->q is NULL so request is not valid, sc_cmd=%p.\n",
633 qedi_iscsi_unmap_sg_list(cmd
);
635 hdr
= (struct iscsi_scsi_rsp
*)task
->hdr
;
636 hdr
->opcode
= cqe_data_in
->opcode
;
637 hdr
->max_cmdsn
= cpu_to_be32(cqe_data_in
->max_cmd_sn
);
638 hdr
->exp_cmdsn
= cpu_to_be32(cqe_data_in
->exp_cmd_sn
);
639 hdr
->itt
= build_itt(cqe
->cqe_solicited
.itid
, conn
->session
->age
);
640 hdr
->response
= cqe_data_in
->reserved1
;
641 hdr
->cmd_status
= cqe_data_in
->status_rsvd
;
642 hdr
->flags
= cqe_data_in
->flags
;
643 hdr
->residual_count
= cpu_to_be32(cqe_data_in
->residual_count
);
645 if (hdr
->cmd_status
== SAM_STAT_CHECK_CONDITION
) {
646 datalen
= cqe_data_in
->reserved2
&
647 ISCSI_COMMON_HDR_DATA_SEG_LEN_MASK
;
648 memcpy((char *)conn
->data
, (char *)cmd
->sense_buffer
, datalen
);
651 /* If f/w reports data underrun err then set residual to IO transfer
652 * length, set Underrun flag and clear Overrun flag explicitly
654 if (unlikely(cqe_err_bits
&&
655 GET_FIELD(cqe_err_bits
, CQE_ERROR_BITMAP_UNDER_RUN_ERR
))) {
656 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
657 "Under flow itt=0x%x proto flags=0x%x tid=0x%x cid 0x%x fw resid 0x%x sc dlen 0x%x\n",
658 hdr
->itt
, cqe_data_in
->flags
, cmd
->task_id
,
659 qedi_conn
->iscsi_conn_id
, hdr
->residual_count
,
660 scsi_bufflen(sc_cmd
));
661 hdr
->residual_count
= cpu_to_be32(scsi_bufflen(sc_cmd
));
662 hdr
->flags
|= ISCSI_FLAG_CMD_UNDERFLOW
;
663 hdr
->flags
&= (~ISCSI_FLAG_CMD_OVERFLOW
);
666 spin_lock(&qedi_conn
->list_lock
);
667 if (likely(cmd
->io_cmd_in_list
)) {
668 cmd
->io_cmd_in_list
= false;
669 list_del_init(&cmd
->io_cmd
);
670 qedi_conn
->active_cmd_count
--;
672 spin_unlock(&qedi_conn
->list_lock
);
674 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_TID
,
675 "Freeing tid=0x%x for cid=0x%x\n",
676 cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
677 cmd
->state
= RESPONSE_RECEIVED
;
679 qedi_trace_io(qedi
, task
, cmd
->task_id
, QEDI_IO_TRACE_RSP
);
681 qedi_clear_task_idx(qedi
, cmd
->task_id
);
682 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
,
683 conn
->data
, datalen
);
685 spin_unlock_bh(&session
->back_lock
);
688 static void qedi_mtask_completion(struct qedi_ctx
*qedi
,
689 union iscsi_cqe
*cqe
,
690 struct iscsi_task
*task
,
691 struct qedi_conn
*conn
, uint16_t que_idx
)
693 struct iscsi_conn
*iscsi_conn
;
696 hdr_opcode
= cqe
->cqe_common
.iscsi_hdr
.common
.hdr_first_byte
;
697 iscsi_conn
= conn
->cls_conn
->dd_data
;
699 switch (hdr_opcode
) {
700 case ISCSI_OPCODE_SCSI_RESPONSE
:
701 case ISCSI_OPCODE_DATA_IN
:
702 qedi_scsi_completion(qedi
, cqe
, task
, iscsi_conn
);
704 case ISCSI_OPCODE_LOGIN_RESPONSE
:
705 qedi_process_login_resp(qedi
, cqe
, task
, conn
);
707 case ISCSI_OPCODE_TMF_RESPONSE
:
708 qedi_process_tmf_resp(qedi
, cqe
, task
, conn
);
710 case ISCSI_OPCODE_TEXT_RESPONSE
:
711 qedi_process_text_resp(qedi
, cqe
, task
, conn
);
713 case ISCSI_OPCODE_LOGOUT_RESPONSE
:
714 qedi_process_logout_resp(qedi
, cqe
, task
, conn
);
716 case ISCSI_OPCODE_NOP_IN
:
717 qedi_process_nopin_mesg(qedi
, cqe
, task
, conn
, que_idx
);
720 QEDI_ERR(&qedi
->dbg_ctx
, "unknown opcode\n");
724 static void qedi_process_nopin_local_cmpl(struct qedi_ctx
*qedi
,
725 struct iscsi_cqe_solicited
*cqe
,
726 struct iscsi_task
*task
,
727 struct qedi_conn
*qedi_conn
)
729 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
730 struct iscsi_session
*session
= conn
->session
;
731 struct qedi_cmd
*cmd
= task
->dd_data
;
733 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_UNSOL
,
734 "itid=0x%x, cmd task id=0x%x\n",
735 cqe
->itid
, cmd
->task_id
);
737 cmd
->state
= RESPONSE_RECEIVED
;
738 qedi_clear_task_idx(qedi
, cmd
->task_id
);
740 spin_lock_bh(&session
->back_lock
);
741 __iscsi_put_task(task
);
742 spin_unlock_bh(&session
->back_lock
);
745 static void qedi_process_cmd_cleanup_resp(struct qedi_ctx
*qedi
,
746 struct iscsi_cqe_solicited
*cqe
,
747 struct iscsi_task
*task
,
748 struct iscsi_conn
*conn
)
750 struct qedi_work_map
*work
, *work_tmp
;
751 u32 proto_itt
= cqe
->itid
;
755 struct qedi_cmd
*qedi_cmd
= NULL
;
758 struct qedi_conn
*qedi_conn
;
759 struct qedi_cmd
*dbg_cmd
;
760 struct iscsi_task
*mtask
;
761 struct iscsi_tm
*tmf_hdr
= NULL
;
763 iscsi_cid
= cqe
->conn_id
;
764 qedi_conn
= qedi
->cid_que
.conn_cid_tbl
[iscsi_cid
];
766 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
767 "icid not found 0x%x\n", cqe
->conn_id
);
771 /* Based on this itt get the corresponding qedi_cmd */
772 spin_lock_bh(&qedi_conn
->tmf_work_lock
);
773 list_for_each_entry_safe(work
, work_tmp
, &qedi_conn
->tmf_work_list
,
775 if (work
->rtid
== proto_itt
) {
776 /* We found the command */
777 qedi_cmd
= work
->qedi_cmd
;
778 if (!qedi_cmd
->list_tmf_work
) {
779 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
780 "TMF work not found, cqe->tid=0x%x, cid=0x%x\n",
781 proto_itt
, qedi_conn
->iscsi_conn_id
);
785 mtask
= qedi_cmd
->task
;
786 tmf_hdr
= (struct iscsi_tm
*)mtask
->hdr
;
789 list_del_init(&work
->list
);
791 qedi_cmd
->list_tmf_work
= NULL
;
794 spin_unlock_bh(&qedi_conn
->tmf_work_lock
);
797 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
798 "TMF work, cqe->tid=0x%x, tmf flags=0x%x, cid=0x%x\n",
799 proto_itt
, tmf_hdr
->flags
, qedi_conn
->iscsi_conn_id
);
801 if ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
802 ISCSI_TM_FUNC_ABORT_TASK
) {
803 spin_lock_bh(&conn
->session
->back_lock
);
805 protoitt
= build_itt(get_itt(tmf_hdr
->rtt
),
807 task
= iscsi_itt_to_task(conn
, protoitt
);
809 spin_unlock_bh(&conn
->session
->back_lock
);
812 QEDI_NOTICE(&qedi
->dbg_ctx
,
813 "IO task completed, tmf rtt=0x%x, cid=0x%x\n",
814 get_itt(tmf_hdr
->rtt
),
815 qedi_conn
->iscsi_conn_id
);
819 dbg_cmd
= task
->dd_data
;
821 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
822 "Abort tmf rtt=0x%x, i/o itt=0x%x, i/o tid=0x%x, cid=0x%x\n",
823 get_itt(tmf_hdr
->rtt
), get_itt(task
->itt
),
824 dbg_cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
826 if (qedi_cmd
->state
== CLEANUP_WAIT_FAILED
)
827 qedi_cmd
->state
= CLEANUP_RECV
;
829 qedi_clear_task_idx(qedi_conn
->qedi
, rtid
);
831 spin_lock(&qedi_conn
->list_lock
);
832 list_del_init(&dbg_cmd
->io_cmd
);
833 qedi_conn
->active_cmd_count
--;
834 spin_unlock(&qedi_conn
->list_lock
);
835 qedi_cmd
->state
= CLEANUP_RECV
;
836 wake_up_interruptible(&qedi_conn
->wait_queue
);
838 } else if (qedi_conn
->cmd_cleanup_req
> 0) {
839 spin_lock_bh(&conn
->session
->back_lock
);
840 qedi_get_proto_itt(qedi
, cqe
->itid
, &ptmp_itt
);
841 protoitt
= build_itt(ptmp_itt
, conn
->session
->age
);
842 task
= iscsi_itt_to_task(conn
, protoitt
);
843 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
844 "cleanup io itid=0x%x, protoitt=0x%x, cmd_cleanup_cmpl=%d, cid=0x%x\n",
845 cqe
->itid
, protoitt
, qedi_conn
->cmd_cleanup_cmpl
,
846 qedi_conn
->iscsi_conn_id
);
848 spin_unlock_bh(&conn
->session
->back_lock
);
850 QEDI_NOTICE(&qedi
->dbg_ctx
,
851 "task is null, itid=0x%x, cid=0x%x\n",
852 cqe
->itid
, qedi_conn
->iscsi_conn_id
);
855 qedi_conn
->cmd_cleanup_cmpl
++;
856 wake_up(&qedi_conn
->wait_queue
);
858 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_TID
,
859 "Freeing tid=0x%x for cid=0x%x\n",
860 cqe
->itid
, qedi_conn
->iscsi_conn_id
);
861 qedi_clear_task_idx(qedi_conn
->qedi
, cqe
->itid
);
864 qedi_get_proto_itt(qedi
, cqe
->itid
, &ptmp_itt
);
865 protoitt
= build_itt(ptmp_itt
, conn
->session
->age
);
866 task
= iscsi_itt_to_task(conn
, protoitt
);
867 QEDI_ERR(&qedi
->dbg_ctx
,
868 "Delayed or untracked cleanup response, itt=0x%x, tid=0x%x, cid=0x%x, task=%p\n",
869 protoitt
, cqe
->itid
, qedi_conn
->iscsi_conn_id
, task
);
873 void qedi_fp_process_cqes(struct qedi_work
*work
)
875 struct qedi_ctx
*qedi
= work
->qedi
;
876 union iscsi_cqe
*cqe
= &work
->cqe
;
877 struct iscsi_task
*task
= NULL
;
878 struct iscsi_nopout
*nopout_hdr
;
879 struct qedi_conn
*q_conn
;
880 struct iscsi_conn
*conn
;
881 struct qedi_cmd
*qedi_cmd
;
885 u16 que_idx
= work
->que_idx
;
888 comp_type
= cqe
->cqe_common
.cqe_type
;
889 hdr_opcode
= cqe
->cqe_common
.iscsi_hdr
.common
.hdr_first_byte
;
891 cqe
->cqe_common
.error_bitmap
.error_bits
.cqe_error_status_bits
;
893 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_CONN
,
894 "fw_cid=0x%x, cqe type=0x%x, opcode=0x%x\n",
895 cqe
->cqe_common
.conn_id
, comp_type
, hdr_opcode
);
897 if (comp_type
>= MAX_ISCSI_CQES_TYPE
) {
898 QEDI_WARN(&qedi
->dbg_ctx
, "Invalid CqE type\n");
902 iscsi_cid
= cqe
->cqe_common
.conn_id
;
903 q_conn
= qedi
->cid_que
.conn_cid_tbl
[iscsi_cid
];
905 QEDI_WARN(&qedi
->dbg_ctx
,
906 "Session no longer exists for cid=0x%x!!\n",
911 conn
= q_conn
->cls_conn
->dd_data
;
913 if (unlikely(cqe_err_bits
&&
914 GET_FIELD(cqe_err_bits
,
915 CQE_ERROR_BITMAP_DATA_DIGEST_ERR
))) {
916 iscsi_conn_failure(conn
, ISCSI_ERR_DATA_DGST
);
921 case ISCSI_CQE_TYPE_SOLICITED
:
922 case ISCSI_CQE_TYPE_SOLICITED_WITH_SENSE
:
923 qedi_cmd
= container_of(work
, struct qedi_cmd
, cqe_work
);
924 task
= qedi_cmd
->task
;
926 QEDI_WARN(&qedi
->dbg_ctx
, "task is NULL\n");
930 /* Process NOPIN local completion */
931 nopout_hdr
= (struct iscsi_nopout
*)task
->hdr
;
932 if ((nopout_hdr
->itt
== RESERVED_ITT
) &&
933 (cqe
->cqe_solicited
.itid
!= (u16
)RESERVED_ITT
)) {
934 qedi_process_nopin_local_cmpl(qedi
, &cqe
->cqe_solicited
,
937 cqe
->cqe_solicited
.itid
=
938 qedi_get_itt(cqe
->cqe_solicited
);
939 /* Process other solicited responses */
940 qedi_mtask_completion(qedi
, cqe
, task
, q_conn
, que_idx
);
943 case ISCSI_CQE_TYPE_UNSOLICITED
:
944 switch (hdr_opcode
) {
945 case ISCSI_OPCODE_NOP_IN
:
946 qedi_process_nopin_mesg(qedi
, cqe
, task
, q_conn
,
949 case ISCSI_OPCODE_ASYNC_MSG
:
950 qedi_process_async_mesg(qedi
, cqe
, task
, q_conn
,
953 case ISCSI_OPCODE_REJECT
:
954 qedi_process_reject_mesg(qedi
, cqe
, task
, q_conn
,
958 goto exit_fp_process
;
959 case ISCSI_CQE_TYPE_DUMMY
:
960 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
, "Dummy CqE\n");
961 goto exit_fp_process
;
962 case ISCSI_CQE_TYPE_TASK_CLEANUP
:
963 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
, "CleanUp CqE\n");
964 qedi_process_cmd_cleanup_resp(qedi
, &cqe
->cqe_solicited
, task
,
966 goto exit_fp_process
;
968 QEDI_ERR(&qedi
->dbg_ctx
, "Error cqe.\n");
976 static void qedi_ring_doorbell(struct qedi_conn
*qedi_conn
)
978 struct iscsi_db_data dbell
= { 0 };
982 dbell
.params
|= DB_DEST_XCM
<< ISCSI_DB_DATA_DEST_SHIFT
;
983 dbell
.params
|= DB_AGG_CMD_SET
<< ISCSI_DB_DATA_AGG_CMD_SHIFT
;
985 DQ_XCM_ISCSI_SQ_PROD_CMD
<< ISCSI_DB_DATA_AGG_VAL_SEL_SHIFT
;
987 dbell
.sq_prod
= qedi_conn
->ep
->fw_sq_prod_idx
;
988 writel(*(u32
*)&dbell
, qedi_conn
->ep
->p_doorbell
);
990 /* Make sure fw write idx is coherent, and include both memory barriers
991 * as a failsafe as for some architectures the call is the same but on
992 * others they are two different assembly operations.
996 QEDI_INFO(&qedi_conn
->qedi
->dbg_ctx
, QEDI_LOG_MP_REQ
,
997 "prod_idx=0x%x, fw_prod_idx=0x%x, cid=0x%x\n",
998 qedi_conn
->ep
->sq_prod_idx
, qedi_conn
->ep
->fw_sq_prod_idx
,
999 qedi_conn
->iscsi_conn_id
);
1002 static u16
qedi_get_wqe_idx(struct qedi_conn
*qedi_conn
)
1004 struct qedi_endpoint
*ep
;
1008 rval
= ep
->sq_prod_idx
;
1010 /* Increament SQ index */
1012 ep
->fw_sq_prod_idx
++;
1013 if (ep
->sq_prod_idx
== QEDI_SQ_SIZE
)
1014 ep
->sq_prod_idx
= 0;
1019 int qedi_send_iscsi_login(struct qedi_conn
*qedi_conn
,
1020 struct iscsi_task
*task
)
1022 struct iscsi_login_req_hdr login_req_pdu_header
;
1023 struct scsi_sgl_task_params tx_sgl_task_params
;
1024 struct scsi_sgl_task_params rx_sgl_task_params
;
1025 struct iscsi_task_params task_params
;
1026 struct e4_iscsi_task_context
*fw_task_ctx
;
1027 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1028 struct iscsi_login_req
*login_hdr
;
1029 struct scsi_sge
*resp_sge
= NULL
;
1030 struct qedi_cmd
*qedi_cmd
;
1031 struct qedi_endpoint
*ep
;
1036 resp_sge
= (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
1037 qedi_cmd
= (struct qedi_cmd
*)task
->dd_data
;
1039 login_hdr
= (struct iscsi_login_req
*)task
->hdr
;
1041 tid
= qedi_get_task_idx(qedi
);
1046 (struct e4_iscsi_task_context
*)qedi_get_task_mem(&qedi
->tasks
,
1048 memset(fw_task_ctx
, 0, sizeof(struct e4_iscsi_task_context
));
1050 qedi_cmd
->task_id
= tid
;
1052 memset(&task_params
, 0, sizeof(task_params
));
1053 memset(&login_req_pdu_header
, 0, sizeof(login_req_pdu_header
));
1054 memset(&tx_sgl_task_params
, 0, sizeof(tx_sgl_task_params
));
1055 memset(&rx_sgl_task_params
, 0, sizeof(rx_sgl_task_params
));
1056 /* Update header info */
1057 login_req_pdu_header
.opcode
= login_hdr
->opcode
;
1058 login_req_pdu_header
.version_min
= login_hdr
->min_version
;
1059 login_req_pdu_header
.version_max
= login_hdr
->max_version
;
1060 login_req_pdu_header
.flags_attr
= login_hdr
->flags
;
1061 login_req_pdu_header
.isid_tabc
= swab32p((u32
*)login_hdr
->isid
);
1062 login_req_pdu_header
.isid_d
= swab16p((u16
*)&login_hdr
->isid
[4]);
1064 login_req_pdu_header
.tsih
= login_hdr
->tsih
;
1065 login_req_pdu_header
.hdr_second_dword
= ntoh24(login_hdr
->dlength
);
1067 qedi_update_itt_map(qedi
, tid
, task
->itt
, qedi_cmd
);
1068 login_req_pdu_header
.itt
= qedi_set_itt(tid
, get_itt(task
->itt
));
1069 login_req_pdu_header
.cid
= qedi_conn
->iscsi_conn_id
;
1070 login_req_pdu_header
.cmd_sn
= be32_to_cpu(login_hdr
->cmdsn
);
1071 login_req_pdu_header
.exp_stat_sn
= be32_to_cpu(login_hdr
->exp_statsn
);
1072 login_req_pdu_header
.exp_stat_sn
= 0;
1074 /* Fill tx AHS and rx buffer */
1075 tx_sgl_task_params
.sgl
=
1076 (struct scsi_sge
*)qedi_conn
->gen_pdu
.req_bd_tbl
;
1077 tx_sgl_task_params
.sgl_phys_addr
.lo
=
1078 (u32
)(qedi_conn
->gen_pdu
.req_dma_addr
);
1079 tx_sgl_task_params
.sgl_phys_addr
.hi
=
1080 (u32
)((u64
)qedi_conn
->gen_pdu
.req_dma_addr
>> 32);
1081 tx_sgl_task_params
.total_buffer_size
= ntoh24(login_hdr
->dlength
);
1082 tx_sgl_task_params
.num_sges
= 1;
1084 rx_sgl_task_params
.sgl
=
1085 (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
1086 rx_sgl_task_params
.sgl_phys_addr
.lo
=
1087 (u32
)(qedi_conn
->gen_pdu
.resp_dma_addr
);
1088 rx_sgl_task_params
.sgl_phys_addr
.hi
=
1089 (u32
)((u64
)qedi_conn
->gen_pdu
.resp_dma_addr
>> 32);
1090 rx_sgl_task_params
.total_buffer_size
= resp_sge
->sge_len
;
1091 rx_sgl_task_params
.num_sges
= 1;
1093 /* Fill fw input params */
1094 task_params
.context
= fw_task_ctx
;
1095 task_params
.conn_icid
= (u16
)qedi_conn
->iscsi_conn_id
;
1096 task_params
.itid
= tid
;
1097 task_params
.cq_rss_number
= 0;
1098 task_params
.tx_io_size
= ntoh24(login_hdr
->dlength
);
1099 task_params
.rx_io_size
= resp_sge
->sge_len
;
1101 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
1102 task_params
.sqe
= &ep
->sq
[sq_idx
];
1104 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
1105 rval
= init_initiator_login_request_task(&task_params
,
1106 &login_req_pdu_header
,
1107 &tx_sgl_task_params
,
1108 &rx_sgl_task_params
);
1112 spin_lock(&qedi_conn
->list_lock
);
1113 list_add_tail(&qedi_cmd
->io_cmd
, &qedi_conn
->active_cmd_list
);
1114 qedi_cmd
->io_cmd_in_list
= true;
1115 qedi_conn
->active_cmd_count
++;
1116 spin_unlock(&qedi_conn
->list_lock
);
1118 qedi_ring_doorbell(qedi_conn
);
1122 int qedi_send_iscsi_logout(struct qedi_conn
*qedi_conn
,
1123 struct iscsi_task
*task
)
1125 struct iscsi_logout_req_hdr logout_pdu_header
;
1126 struct scsi_sgl_task_params tx_sgl_task_params
;
1127 struct scsi_sgl_task_params rx_sgl_task_params
;
1128 struct iscsi_task_params task_params
;
1129 struct e4_iscsi_task_context
*fw_task_ctx
;
1130 struct iscsi_logout
*logout_hdr
= NULL
;
1131 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1132 struct qedi_cmd
*qedi_cmd
;
1133 struct qedi_endpoint
*ep
;
1138 qedi_cmd
= (struct qedi_cmd
*)task
->dd_data
;
1139 logout_hdr
= (struct iscsi_logout
*)task
->hdr
;
1142 tid
= qedi_get_task_idx(qedi
);
1147 (struct e4_iscsi_task_context
*)qedi_get_task_mem(&qedi
->tasks
,
1149 memset(fw_task_ctx
, 0, sizeof(struct e4_iscsi_task_context
));
1151 qedi_cmd
->task_id
= tid
;
1153 memset(&task_params
, 0, sizeof(task_params
));
1154 memset(&logout_pdu_header
, 0, sizeof(logout_pdu_header
));
1155 memset(&tx_sgl_task_params
, 0, sizeof(tx_sgl_task_params
));
1156 memset(&rx_sgl_task_params
, 0, sizeof(rx_sgl_task_params
));
1158 /* Update header info */
1159 logout_pdu_header
.opcode
= logout_hdr
->opcode
;
1160 logout_pdu_header
.reason_code
= 0x80 | logout_hdr
->flags
;
1161 qedi_update_itt_map(qedi
, tid
, task
->itt
, qedi_cmd
);
1162 logout_pdu_header
.itt
= qedi_set_itt(tid
, get_itt(task
->itt
));
1163 logout_pdu_header
.exp_stat_sn
= be32_to_cpu(logout_hdr
->exp_statsn
);
1164 logout_pdu_header
.cmd_sn
= be32_to_cpu(logout_hdr
->cmdsn
);
1165 logout_pdu_header
.cid
= qedi_conn
->iscsi_conn_id
;
1167 /* Fill fw input params */
1168 task_params
.context
= fw_task_ctx
;
1169 task_params
.conn_icid
= (u16
)qedi_conn
->iscsi_conn_id
;
1170 task_params
.itid
= tid
;
1171 task_params
.cq_rss_number
= 0;
1172 task_params
.tx_io_size
= 0;
1173 task_params
.rx_io_size
= 0;
1175 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
1176 task_params
.sqe
= &ep
->sq
[sq_idx
];
1177 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
1179 rval
= init_initiator_logout_request_task(&task_params
,
1185 spin_lock(&qedi_conn
->list_lock
);
1186 list_add_tail(&qedi_cmd
->io_cmd
, &qedi_conn
->active_cmd_list
);
1187 qedi_cmd
->io_cmd_in_list
= true;
1188 qedi_conn
->active_cmd_count
++;
1189 spin_unlock(&qedi_conn
->list_lock
);
1191 qedi_ring_doorbell(qedi_conn
);
1195 int qedi_cleanup_all_io(struct qedi_ctx
*qedi
, struct qedi_conn
*qedi_conn
,
1196 struct iscsi_task
*task
, bool in_recovery
)
1199 struct iscsi_task
*ctask
;
1200 struct qedi_cmd
*cmd
, *cmd_tmp
;
1201 struct iscsi_tm
*tmf_hdr
;
1202 unsigned int lun
= 0;
1203 bool lun_reset
= false;
1204 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
1205 struct iscsi_session
*session
= conn
->session
;
1207 /* From recovery, task is NULL or from tmf resp valid task */
1209 tmf_hdr
= (struct iscsi_tm
*)task
->hdr
;
1211 if ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
1212 ISCSI_TM_FUNC_LOGICAL_UNIT_RESET
) {
1214 lun
= scsilun_to_int(&tmf_hdr
->lun
);
1218 qedi_conn
->cmd_cleanup_req
= 0;
1219 qedi_conn
->cmd_cleanup_cmpl
= 0;
1221 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1222 "active_cmd_count=%d, cid=0x%x, in_recovery=%d, lun_reset=%d\n",
1223 qedi_conn
->active_cmd_count
, qedi_conn
->iscsi_conn_id
,
1224 in_recovery
, lun_reset
);
1227 spin_lock_bh(&session
->back_lock
);
1229 spin_lock(&qedi_conn
->list_lock
);
1231 list_for_each_entry_safe(cmd
, cmd_tmp
, &qedi_conn
->active_cmd_list
,
1238 if (cmd
->scsi_cmd
&& cmd
->scsi_cmd
->device
) {
1239 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1240 "tid=0x%x itt=0x%x scsi_cmd_ptr=%p device=%p task_state=%d cmd_state=0%x cid=0x%x\n",
1241 cmd
->task_id
, get_itt(ctask
->itt
),
1242 cmd
->scsi_cmd
, cmd
->scsi_cmd
->device
,
1243 ctask
->state
, cmd
->state
,
1244 qedi_conn
->iscsi_conn_id
);
1245 if (cmd
->scsi_cmd
->device
->lun
!= lun
)
1249 qedi_conn
->cmd_cleanup_req
++;
1250 qedi_iscsi_cleanup_task(ctask
, true);
1252 list_del_init(&cmd
->io_cmd
);
1253 qedi_conn
->active_cmd_count
--;
1254 QEDI_WARN(&qedi
->dbg_ctx
,
1255 "Deleted active cmd list node io_cmd=%p, cid=0x%x\n",
1256 &cmd
->io_cmd
, qedi_conn
->iscsi_conn_id
);
1259 spin_unlock(&qedi_conn
->list_lock
);
1262 spin_unlock_bh(&session
->back_lock
);
1264 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1265 "cmd_cleanup_req=%d, cid=0x%x\n",
1266 qedi_conn
->cmd_cleanup_req
,
1267 qedi_conn
->iscsi_conn_id
);
1269 rval
= wait_event_interruptible_timeout(qedi_conn
->wait_queue
,
1270 ((qedi_conn
->cmd_cleanup_req
==
1271 qedi_conn
->cmd_cleanup_cmpl
) ||
1275 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1276 "i/o cmd_cleanup_req=%d, equal to cmd_cleanup_cmpl=%d, cid=0x%x\n",
1277 qedi_conn
->cmd_cleanup_req
,
1278 qedi_conn
->cmd_cleanup_cmpl
,
1279 qedi_conn
->iscsi_conn_id
);
1284 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1285 "i/o cmd_cleanup_req=%d, not equal to cmd_cleanup_cmpl=%d, cid=0x%x\n",
1286 qedi_conn
->cmd_cleanup_req
,
1287 qedi_conn
->cmd_cleanup_cmpl
,
1288 qedi_conn
->iscsi_conn_id
);
1290 iscsi_host_for_each_session(qedi
->shost
,
1291 qedi_mark_device_missing
);
1292 qedi_ops
->common
->drain(qedi
->cdev
);
1294 /* Enable IOs for all other sessions except current.*/
1295 if (!wait_event_interruptible_timeout(qedi_conn
->wait_queue
,
1296 (qedi_conn
->cmd_cleanup_req
==
1297 qedi_conn
->cmd_cleanup_cmpl
),
1299 iscsi_host_for_each_session(qedi
->shost
,
1300 qedi_mark_device_available
);
1304 iscsi_host_for_each_session(qedi
->shost
,
1305 qedi_mark_device_available
);
1310 void qedi_clearsq(struct qedi_ctx
*qedi
, struct qedi_conn
*qedi_conn
,
1311 struct iscsi_task
*task
)
1313 struct qedi_endpoint
*qedi_ep
;
1316 qedi_ep
= qedi_conn
->ep
;
1317 qedi_conn
->cmd_cleanup_req
= 0;
1318 qedi_conn
->cmd_cleanup_cmpl
= 0;
1321 QEDI_WARN(&qedi
->dbg_ctx
,
1322 "Cannot proceed, ep already disconnected, cid=0x%x\n",
1323 qedi_conn
->iscsi_conn_id
);
1327 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1328 "Clearing SQ for cid=0x%x, conn=%p, ep=%p\n",
1329 qedi_conn
->iscsi_conn_id
, qedi_conn
, qedi_ep
);
1331 qedi_ops
->clear_sq(qedi
->cdev
, qedi_ep
->handle
);
1333 rval
= qedi_cleanup_all_io(qedi
, qedi_conn
, task
, true);
1335 QEDI_ERR(&qedi
->dbg_ctx
,
1336 "fatal error, need hard reset, cid=0x%x\n",
1337 qedi_conn
->iscsi_conn_id
);
1342 static int qedi_wait_for_cleanup_request(struct qedi_ctx
*qedi
,
1343 struct qedi_conn
*qedi_conn
,
1344 struct iscsi_task
*task
,
1345 struct qedi_cmd
*qedi_cmd
,
1346 struct qedi_work_map
*list_work
)
1348 struct qedi_cmd
*cmd
= (struct qedi_cmd
*)task
->dd_data
;
1351 wait
= wait_event_interruptible_timeout(qedi_conn
->wait_queue
,
1352 ((qedi_cmd
->state
==
1354 ((qedi_cmd
->type
== TYPEIO
) &&
1356 RESPONSE_RECEIVED
))),
1359 qedi_cmd
->state
= CLEANUP_WAIT_FAILED
;
1361 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1362 "Cleanup timedout tid=0x%x, issue connection recovery, cid=0x%x\n",
1363 cmd
->task_id
, qedi_conn
->iscsi_conn_id
);
1370 static void qedi_tmf_work(struct work_struct
*work
)
1372 struct qedi_cmd
*qedi_cmd
=
1373 container_of(work
, struct qedi_cmd
, tmf_work
);
1374 struct qedi_conn
*qedi_conn
= qedi_cmd
->conn
;
1375 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1376 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
1377 struct iscsi_cls_session
*cls_sess
;
1378 struct qedi_work_map
*list_work
= NULL
;
1379 struct iscsi_task
*mtask
;
1380 struct qedi_cmd
*cmd
;
1381 struct iscsi_task
*ctask
;
1382 struct iscsi_tm
*tmf_hdr
;
1386 mtask
= qedi_cmd
->task
;
1387 tmf_hdr
= (struct iscsi_tm
*)mtask
->hdr
;
1388 cls_sess
= iscsi_conn_to_session(qedi_conn
->cls_conn
);
1389 set_bit(QEDI_CONN_FW_CLEANUP
, &qedi_conn
->flags
);
1391 ctask
= iscsi_itt_to_task(conn
, tmf_hdr
->rtt
);
1392 if (!ctask
|| !ctask
->sc
) {
1393 QEDI_ERR(&qedi
->dbg_ctx
, "Task already completed\n");
1397 cmd
= (struct qedi_cmd
*)ctask
->dd_data
;
1398 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1399 "Abort tmf rtt=0x%x, cmd itt=0x%x, cmd tid=0x%x, cid=0x%x\n",
1400 get_itt(tmf_hdr
->rtt
), get_itt(ctask
->itt
), cmd
->task_id
,
1401 qedi_conn
->iscsi_conn_id
);
1403 if (qedi_do_not_recover
) {
1404 QEDI_ERR(&qedi
->dbg_ctx
, "DONT SEND CLEANUP/ABORT %d\n",
1405 qedi_do_not_recover
);
1409 list_work
= kzalloc(sizeof(*list_work
), GFP_ATOMIC
);
1411 QEDI_ERR(&qedi
->dbg_ctx
, "Memory allocation failed\n");
1415 qedi_cmd
->type
= TYPEIO
;
1416 list_work
->qedi_cmd
= qedi_cmd
;
1417 list_work
->rtid
= cmd
->task_id
;
1418 list_work
->state
= QEDI_WORK_SCHEDULED
;
1419 qedi_cmd
->list_tmf_work
= list_work
;
1421 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
1422 "Queue tmf work=%p, list node=%p, cid=0x%x, tmf flags=0x%x\n",
1423 list_work
->ptr_tmf_work
, list_work
, qedi_conn
->iscsi_conn_id
,
1426 spin_lock_bh(&qedi_conn
->tmf_work_lock
);
1427 list_add_tail(&list_work
->list
, &qedi_conn
->tmf_work_list
);
1428 spin_unlock_bh(&qedi_conn
->tmf_work_lock
);
1430 qedi_iscsi_cleanup_task(ctask
, false);
1432 rval
= qedi_wait_for_cleanup_request(qedi
, qedi_conn
, ctask
, qedi_cmd
,
1435 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_INFO
,
1436 "FW cleanup got escalated, cid=0x%x\n",
1437 qedi_conn
->iscsi_conn_id
);
1441 tid
= qedi_get_task_idx(qedi
);
1443 QEDI_ERR(&qedi
->dbg_ctx
, "Invalid tid, cid=0x%x\n",
1444 qedi_conn
->iscsi_conn_id
);
1448 qedi_cmd
->task_id
= tid
;
1449 qedi_send_iscsi_tmf(qedi_conn
, qedi_cmd
->task
);
1452 clear_bit(QEDI_CONN_FW_CLEANUP
, &qedi_conn
->flags
);
1456 spin_lock_bh(&qedi_conn
->tmf_work_lock
);
1457 if (!qedi_cmd
->list_tmf_work
) {
1458 list_del_init(&list_work
->list
);
1459 qedi_cmd
->list_tmf_work
= NULL
;
1462 spin_unlock_bh(&qedi_conn
->tmf_work_lock
);
1464 spin_lock(&qedi_conn
->list_lock
);
1465 list_del_init(&cmd
->io_cmd
);
1466 qedi_conn
->active_cmd_count
--;
1467 spin_unlock(&qedi_conn
->list_lock
);
1469 clear_bit(QEDI_CONN_FW_CLEANUP
, &qedi_conn
->flags
);
1472 static int qedi_send_iscsi_tmf(struct qedi_conn
*qedi_conn
,
1473 struct iscsi_task
*mtask
)
1475 struct iscsi_tmf_request_hdr tmf_pdu_header
;
1476 struct iscsi_task_params task_params
;
1477 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1478 struct e4_iscsi_task_context
*fw_task_ctx
;
1479 struct iscsi_conn
*conn
= qedi_conn
->cls_conn
->dd_data
;
1480 struct iscsi_task
*ctask
;
1481 struct iscsi_tm
*tmf_hdr
;
1482 struct qedi_cmd
*qedi_cmd
;
1483 struct qedi_cmd
*cmd
;
1484 struct qedi_endpoint
*ep
;
1490 tmf_hdr
= (struct iscsi_tm
*)mtask
->hdr
;
1491 qedi_cmd
= (struct qedi_cmd
*)mtask
->dd_data
;
1496 tid
= qedi_get_task_idx(qedi
);
1501 (struct e4_iscsi_task_context
*)qedi_get_task_mem(&qedi
->tasks
,
1503 memset(fw_task_ctx
, 0, sizeof(struct e4_iscsi_task_context
));
1505 qedi_cmd
->task_id
= tid
;
1507 memset(&task_params
, 0, sizeof(task_params
));
1508 memset(&tmf_pdu_header
, 0, sizeof(tmf_pdu_header
));
1510 /* Update header info */
1511 qedi_update_itt_map(qedi
, tid
, mtask
->itt
, qedi_cmd
);
1512 tmf_pdu_header
.itt
= qedi_set_itt(tid
, get_itt(mtask
->itt
));
1513 tmf_pdu_header
.cmd_sn
= be32_to_cpu(tmf_hdr
->cmdsn
);
1515 memcpy(scsi_lun
, &tmf_hdr
->lun
, sizeof(struct scsi_lun
));
1516 tmf_pdu_header
.lun
.lo
= be32_to_cpu(scsi_lun
[0]);
1517 tmf_pdu_header
.lun
.hi
= be32_to_cpu(scsi_lun
[1]);
1519 if ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
1520 ISCSI_TM_FUNC_ABORT_TASK
) {
1521 ctask
= iscsi_itt_to_task(conn
, tmf_hdr
->rtt
);
1522 if (!ctask
|| !ctask
->sc
) {
1523 QEDI_ERR(&qedi
->dbg_ctx
,
1524 "Could not get reference task\n");
1527 cmd
= (struct qedi_cmd
*)ctask
->dd_data
;
1528 tmf_pdu_header
.rtt
=
1529 qedi_set_itt(cmd
->task_id
,
1530 get_itt(tmf_hdr
->rtt
));
1532 tmf_pdu_header
.rtt
= ISCSI_RESERVED_TAG
;
1535 tmf_pdu_header
.opcode
= tmf_hdr
->opcode
;
1536 tmf_pdu_header
.function
= tmf_hdr
->flags
;
1537 tmf_pdu_header
.hdr_second_dword
= ntoh24(tmf_hdr
->dlength
);
1538 tmf_pdu_header
.ref_cmd_sn
= be32_to_cpu(tmf_hdr
->refcmdsn
);
1540 /* Fill fw input params */
1541 task_params
.context
= fw_task_ctx
;
1542 task_params
.conn_icid
= (u16
)qedi_conn
->iscsi_conn_id
;
1543 task_params
.itid
= tid
;
1544 task_params
.cq_rss_number
= 0;
1545 task_params
.tx_io_size
= 0;
1546 task_params
.rx_io_size
= 0;
1548 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
1549 task_params
.sqe
= &ep
->sq
[sq_idx
];
1551 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
1552 rval
= init_initiator_tmf_request_task(&task_params
,
1557 spin_lock(&qedi_conn
->list_lock
);
1558 list_add_tail(&qedi_cmd
->io_cmd
, &qedi_conn
->active_cmd_list
);
1559 qedi_cmd
->io_cmd_in_list
= true;
1560 qedi_conn
->active_cmd_count
++;
1561 spin_unlock(&qedi_conn
->list_lock
);
1563 qedi_ring_doorbell(qedi_conn
);
1567 int qedi_iscsi_abort_work(struct qedi_conn
*qedi_conn
,
1568 struct iscsi_task
*mtask
)
1570 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1571 struct iscsi_tm
*tmf_hdr
;
1572 struct qedi_cmd
*qedi_cmd
= (struct qedi_cmd
*)mtask
->dd_data
;
1575 tmf_hdr
= (struct iscsi_tm
*)mtask
->hdr
;
1576 qedi_cmd
->task
= mtask
;
1578 /* If abort task then schedule the work and return */
1579 if ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
1580 ISCSI_TM_FUNC_ABORT_TASK
) {
1581 qedi_cmd
->state
= CLEANUP_WAIT
;
1582 INIT_WORK(&qedi_cmd
->tmf_work
, qedi_tmf_work
);
1583 queue_work(qedi
->tmf_thread
, &qedi_cmd
->tmf_work
);
1585 } else if (((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
1586 ISCSI_TM_FUNC_LOGICAL_UNIT_RESET
) ||
1587 ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
1588 ISCSI_TM_FUNC_TARGET_WARM_RESET
) ||
1589 ((tmf_hdr
->flags
& ISCSI_FLAG_TM_FUNC_MASK
) ==
1590 ISCSI_TM_FUNC_TARGET_COLD_RESET
)) {
1591 tid
= qedi_get_task_idx(qedi
);
1593 QEDI_ERR(&qedi
->dbg_ctx
, "Invalid tid, cid=0x%x\n",
1594 qedi_conn
->iscsi_conn_id
);
1597 qedi_cmd
->task_id
= tid
;
1599 qedi_send_iscsi_tmf(qedi_conn
, qedi_cmd
->task
);
1602 QEDI_ERR(&qedi
->dbg_ctx
, "Invalid tmf, cid=0x%x\n",
1603 qedi_conn
->iscsi_conn_id
);
1610 int qedi_send_iscsi_text(struct qedi_conn
*qedi_conn
,
1611 struct iscsi_task
*task
)
1613 struct iscsi_text_request_hdr text_request_pdu_header
;
1614 struct scsi_sgl_task_params tx_sgl_task_params
;
1615 struct scsi_sgl_task_params rx_sgl_task_params
;
1616 struct iscsi_task_params task_params
;
1617 struct e4_iscsi_task_context
*fw_task_ctx
;
1618 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1619 struct iscsi_text
*text_hdr
;
1620 struct scsi_sge
*req_sge
= NULL
;
1621 struct scsi_sge
*resp_sge
= NULL
;
1622 struct qedi_cmd
*qedi_cmd
;
1623 struct qedi_endpoint
*ep
;
1628 req_sge
= (struct scsi_sge
*)qedi_conn
->gen_pdu
.req_bd_tbl
;
1629 resp_sge
= (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
1630 qedi_cmd
= (struct qedi_cmd
*)task
->dd_data
;
1631 text_hdr
= (struct iscsi_text
*)task
->hdr
;
1634 tid
= qedi_get_task_idx(qedi
);
1639 (struct e4_iscsi_task_context
*)qedi_get_task_mem(&qedi
->tasks
,
1641 memset(fw_task_ctx
, 0, sizeof(struct e4_iscsi_task_context
));
1643 qedi_cmd
->task_id
= tid
;
1645 memset(&task_params
, 0, sizeof(task_params
));
1646 memset(&text_request_pdu_header
, 0, sizeof(text_request_pdu_header
));
1647 memset(&tx_sgl_task_params
, 0, sizeof(tx_sgl_task_params
));
1648 memset(&rx_sgl_task_params
, 0, sizeof(rx_sgl_task_params
));
1650 /* Update header info */
1651 text_request_pdu_header
.opcode
= text_hdr
->opcode
;
1652 text_request_pdu_header
.flags_attr
= text_hdr
->flags
;
1654 qedi_update_itt_map(qedi
, tid
, task
->itt
, qedi_cmd
);
1655 text_request_pdu_header
.itt
= qedi_set_itt(tid
, get_itt(task
->itt
));
1656 text_request_pdu_header
.ttt
= text_hdr
->ttt
;
1657 text_request_pdu_header
.cmd_sn
= be32_to_cpu(text_hdr
->cmdsn
);
1658 text_request_pdu_header
.exp_stat_sn
= be32_to_cpu(text_hdr
->exp_statsn
);
1659 text_request_pdu_header
.hdr_second_dword
= ntoh24(text_hdr
->dlength
);
1661 /* Fill tx AHS and rx buffer */
1662 tx_sgl_task_params
.sgl
=
1663 (struct scsi_sge
*)qedi_conn
->gen_pdu
.req_bd_tbl
;
1664 tx_sgl_task_params
.sgl_phys_addr
.lo
=
1665 (u32
)(qedi_conn
->gen_pdu
.req_dma_addr
);
1666 tx_sgl_task_params
.sgl_phys_addr
.hi
=
1667 (u32
)((u64
)qedi_conn
->gen_pdu
.req_dma_addr
>> 32);
1668 tx_sgl_task_params
.total_buffer_size
= req_sge
->sge_len
;
1669 tx_sgl_task_params
.num_sges
= 1;
1671 rx_sgl_task_params
.sgl
=
1672 (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
1673 rx_sgl_task_params
.sgl_phys_addr
.lo
=
1674 (u32
)(qedi_conn
->gen_pdu
.resp_dma_addr
);
1675 rx_sgl_task_params
.sgl_phys_addr
.hi
=
1676 (u32
)((u64
)qedi_conn
->gen_pdu
.resp_dma_addr
>> 32);
1677 rx_sgl_task_params
.total_buffer_size
= resp_sge
->sge_len
;
1678 rx_sgl_task_params
.num_sges
= 1;
1680 /* Fill fw input params */
1681 task_params
.context
= fw_task_ctx
;
1682 task_params
.conn_icid
= (u16
)qedi_conn
->iscsi_conn_id
;
1683 task_params
.itid
= tid
;
1684 task_params
.cq_rss_number
= 0;
1685 task_params
.tx_io_size
= ntoh24(text_hdr
->dlength
);
1686 task_params
.rx_io_size
= resp_sge
->sge_len
;
1688 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
1689 task_params
.sqe
= &ep
->sq
[sq_idx
];
1691 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
1692 rval
= init_initiator_text_request_task(&task_params
,
1693 &text_request_pdu_header
,
1694 &tx_sgl_task_params
,
1695 &rx_sgl_task_params
);
1699 spin_lock(&qedi_conn
->list_lock
);
1700 list_add_tail(&qedi_cmd
->io_cmd
, &qedi_conn
->active_cmd_list
);
1701 qedi_cmd
->io_cmd_in_list
= true;
1702 qedi_conn
->active_cmd_count
++;
1703 spin_unlock(&qedi_conn
->list_lock
);
1705 qedi_ring_doorbell(qedi_conn
);
1709 int qedi_send_iscsi_nopout(struct qedi_conn
*qedi_conn
,
1710 struct iscsi_task
*task
,
1711 char *datap
, int data_len
, int unsol
)
1713 struct iscsi_nop_out_hdr nop_out_pdu_header
;
1714 struct scsi_sgl_task_params tx_sgl_task_params
;
1715 struct scsi_sgl_task_params rx_sgl_task_params
;
1716 struct iscsi_task_params task_params
;
1717 struct qedi_ctx
*qedi
= qedi_conn
->qedi
;
1718 struct e4_iscsi_task_context
*fw_task_ctx
;
1719 struct iscsi_nopout
*nopout_hdr
;
1720 struct scsi_sge
*resp_sge
= NULL
;
1721 struct qedi_cmd
*qedi_cmd
;
1722 struct qedi_endpoint
*ep
;
1728 resp_sge
= (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
1729 qedi_cmd
= (struct qedi_cmd
*)task
->dd_data
;
1730 nopout_hdr
= (struct iscsi_nopout
*)task
->hdr
;
1733 tid
= qedi_get_task_idx(qedi
);
1738 (struct e4_iscsi_task_context
*)qedi_get_task_mem(&qedi
->tasks
,
1740 memset(fw_task_ctx
, 0, sizeof(struct e4_iscsi_task_context
));
1742 qedi_cmd
->task_id
= tid
;
1744 memset(&task_params
, 0, sizeof(task_params
));
1745 memset(&nop_out_pdu_header
, 0, sizeof(nop_out_pdu_header
));
1746 memset(&tx_sgl_task_params
, 0, sizeof(tx_sgl_task_params
));
1747 memset(&rx_sgl_task_params
, 0, sizeof(rx_sgl_task_params
));
1749 /* Update header info */
1750 nop_out_pdu_header
.opcode
= nopout_hdr
->opcode
;
1751 SET_FIELD(nop_out_pdu_header
.flags_attr
, ISCSI_NOP_OUT_HDR_CONST1
, 1);
1752 SET_FIELD(nop_out_pdu_header
.flags_attr
, ISCSI_NOP_OUT_HDR_RSRV
, 0);
1754 memcpy(scsi_lun
, &nopout_hdr
->lun
, sizeof(struct scsi_lun
));
1755 nop_out_pdu_header
.lun
.lo
= be32_to_cpu(scsi_lun
[0]);
1756 nop_out_pdu_header
.lun
.hi
= be32_to_cpu(scsi_lun
[1]);
1757 nop_out_pdu_header
.cmd_sn
= be32_to_cpu(nopout_hdr
->cmdsn
);
1758 nop_out_pdu_header
.exp_stat_sn
= be32_to_cpu(nopout_hdr
->exp_statsn
);
1760 qedi_update_itt_map(qedi
, tid
, task
->itt
, qedi_cmd
);
1762 if (nopout_hdr
->ttt
!= ISCSI_TTT_ALL_ONES
) {
1763 nop_out_pdu_header
.itt
= be32_to_cpu(nopout_hdr
->itt
);
1764 nop_out_pdu_header
.ttt
= be32_to_cpu(nopout_hdr
->ttt
);
1766 nop_out_pdu_header
.itt
= qedi_set_itt(tid
, get_itt(task
->itt
));
1767 nop_out_pdu_header
.ttt
= ISCSI_TTT_ALL_ONES
;
1769 spin_lock(&qedi_conn
->list_lock
);
1770 list_add_tail(&qedi_cmd
->io_cmd
, &qedi_conn
->active_cmd_list
);
1771 qedi_cmd
->io_cmd_in_list
= true;
1772 qedi_conn
->active_cmd_count
++;
1773 spin_unlock(&qedi_conn
->list_lock
);
1776 /* Fill tx AHS and rx buffer */
1778 tx_sgl_task_params
.sgl
=
1779 (struct scsi_sge
*)qedi_conn
->gen_pdu
.req_bd_tbl
;
1780 tx_sgl_task_params
.sgl_phys_addr
.lo
=
1781 (u32
)(qedi_conn
->gen_pdu
.req_dma_addr
);
1782 tx_sgl_task_params
.sgl_phys_addr
.hi
=
1783 (u32
)((u64
)qedi_conn
->gen_pdu
.req_dma_addr
>> 32);
1784 tx_sgl_task_params
.total_buffer_size
= data_len
;
1785 tx_sgl_task_params
.num_sges
= 1;
1787 rx_sgl_task_params
.sgl
=
1788 (struct scsi_sge
*)qedi_conn
->gen_pdu
.resp_bd_tbl
;
1789 rx_sgl_task_params
.sgl_phys_addr
.lo
=
1790 (u32
)(qedi_conn
->gen_pdu
.resp_dma_addr
);
1791 rx_sgl_task_params
.sgl_phys_addr
.hi
=
1792 (u32
)((u64
)qedi_conn
->gen_pdu
.resp_dma_addr
>> 32);
1793 rx_sgl_task_params
.total_buffer_size
= resp_sge
->sge_len
;
1794 rx_sgl_task_params
.num_sges
= 1;
1797 /* Fill fw input params */
1798 task_params
.context
= fw_task_ctx
;
1799 task_params
.conn_icid
= (u16
)qedi_conn
->iscsi_conn_id
;
1800 task_params
.itid
= tid
;
1801 task_params
.cq_rss_number
= 0;
1802 task_params
.tx_io_size
= data_len
;
1803 task_params
.rx_io_size
= resp_sge
->sge_len
;
1805 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
1806 task_params
.sqe
= &ep
->sq
[sq_idx
];
1808 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
1809 rval
= init_initiator_nop_out_task(&task_params
,
1810 &nop_out_pdu_header
,
1811 &tx_sgl_task_params
,
1812 &rx_sgl_task_params
);
1816 qedi_ring_doorbell(qedi_conn
);
1820 static int qedi_split_bd(struct qedi_cmd
*cmd
, u64 addr
, int sg_len
,
1823 struct scsi_sge
*bd
= cmd
->io_tbl
.sge_tbl
;
1824 int frag_size
, sg_frags
;
1829 if (addr
% QEDI_PAGE_SIZE
)
1831 (QEDI_PAGE_SIZE
- (addr
% QEDI_PAGE_SIZE
));
1833 frag_size
= (sg_len
> QEDI_BD_SPLIT_SZ
) ? 0 :
1834 (sg_len
% QEDI_BD_SPLIT_SZ
);
1837 frag_size
= QEDI_BD_SPLIT_SZ
;
1839 bd
[bd_index
+ sg_frags
].sge_addr
.lo
= (addr
& 0xffffffff);
1840 bd
[bd_index
+ sg_frags
].sge_addr
.hi
= (addr
>> 32);
1841 bd
[bd_index
+ sg_frags
].sge_len
= (u16
)frag_size
;
1842 QEDI_INFO(&cmd
->conn
->qedi
->dbg_ctx
, QEDI_LOG_IO
,
1843 "split sge %d: addr=%llx, len=%x",
1844 (bd_index
+ sg_frags
), addr
, frag_size
);
1846 addr
+= (u64
)frag_size
;
1848 sg_len
-= frag_size
;
1853 static int qedi_map_scsi_sg(struct qedi_ctx
*qedi
, struct qedi_cmd
*cmd
)
1855 struct scsi_cmnd
*sc
= cmd
->scsi_cmd
;
1856 struct scsi_sge
*bd
= cmd
->io_tbl
.sge_tbl
;
1857 struct scatterlist
*sg
;
1866 WARN_ON(scsi_sg_count(sc
) > QEDI_ISCSI_MAX_BDS_PER_CMD
);
1868 sg_count
= dma_map_sg(&qedi
->pdev
->dev
, scsi_sglist(sc
),
1869 scsi_sg_count(sc
), sc
->sc_data_direction
);
1872 * New condition to send single SGE as cached-SGL.
1873 * Single SGE with length less than 64K.
1875 sg
= scsi_sglist(sc
);
1876 if ((sg_count
== 1) && (sg_dma_len(sg
) <= MAX_SGLEN_FOR_CACHESGL
)) {
1877 sg_len
= sg_dma_len(sg
);
1878 addr
= (u64
)sg_dma_address(sg
);
1880 bd
[bd_count
].sge_addr
.lo
= (addr
& 0xffffffff);
1881 bd
[bd_count
].sge_addr
.hi
= (addr
>> 32);
1882 bd
[bd_count
].sge_len
= (u16
)sg_len
;
1884 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_IO
,
1885 "single-cashed-sgl: bd_count:%d addr=%llx, len=%x",
1886 sg_count
, addr
, sg_len
);
1891 scsi_for_each_sg(sc
, sg
, sg_count
, i
) {
1892 sg_len
= sg_dma_len(sg
);
1893 addr
= (u64
)sg_dma_address(sg
);
1894 end_addr
= (addr
+ sg_len
);
1897 * first sg elem in the 'list',
1898 * check if end addr is page-aligned.
1900 if ((i
== 0) && (sg_count
> 1) && (end_addr
% QEDI_PAGE_SIZE
))
1901 cmd
->use_slowpath
= true;
1904 * last sg elem in the 'list',
1905 * check if start addr is page-aligned.
1907 else if ((i
== (sg_count
- 1)) &&
1908 (sg_count
> 1) && (addr
% QEDI_PAGE_SIZE
))
1909 cmd
->use_slowpath
= true;
1912 * middle sg elements in list,
1913 * check if start and end addr is page-aligned
1915 else if ((i
!= 0) && (i
!= (sg_count
- 1)) &&
1916 ((addr
% QEDI_PAGE_SIZE
) ||
1917 (end_addr
% QEDI_PAGE_SIZE
)))
1918 cmd
->use_slowpath
= true;
1920 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_IO
, "sg[%d] size=0x%x",
1923 if (sg_len
> QEDI_BD_SPLIT_SZ
) {
1924 sg_frags
= qedi_split_bd(cmd
, addr
, sg_len
, bd_count
);
1927 bd
[bd_count
].sge_addr
.lo
= addr
& 0xffffffff;
1928 bd
[bd_count
].sge_addr
.hi
= addr
>> 32;
1929 bd
[bd_count
].sge_len
= sg_len
;
1931 byte_count
+= sg_len
;
1932 bd_count
+= sg_frags
;
1935 if (byte_count
!= scsi_bufflen(sc
))
1936 QEDI_ERR(&qedi
->dbg_ctx
,
1937 "byte_count = %d != scsi_bufflen = %d\n", byte_count
,
1940 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_IO
, "byte_count = %d\n",
1943 WARN_ON(byte_count
!= scsi_bufflen(sc
));
1948 static void qedi_iscsi_map_sg_list(struct qedi_cmd
*cmd
)
1951 struct scsi_cmnd
*sc
= cmd
->scsi_cmd
;
1953 if (scsi_sg_count(sc
)) {
1954 bd_count
= qedi_map_scsi_sg(cmd
->conn
->qedi
, cmd
);
1958 struct scsi_sge
*bd
= cmd
->io_tbl
.sge_tbl
;
1960 bd
[0].sge_addr
.lo
= 0;
1961 bd
[0].sge_addr
.hi
= 0;
1965 cmd
->io_tbl
.sge_valid
= bd_count
;
1968 static void qedi_cpy_scsi_cdb(struct scsi_cmnd
*sc
, u32
*dstp
)
1974 lpcnt
= sc
->cmd_len
/ sizeof(dword
);
1975 srcp
= (u8
*)sc
->cmnd
;
1977 memcpy(&dword
, (const void *)srcp
, 4);
1978 *dstp
= cpu_to_be32(dword
);
1982 if (sc
->cmd_len
& 0x3) {
1983 dword
= (u32
)srcp
[0] | ((u32
)srcp
[1] << 8);
1984 *dstp
= cpu_to_be32(dword
);
1988 void qedi_trace_io(struct qedi_ctx
*qedi
, struct iscsi_task
*task
,
1989 u16 tid
, int8_t direction
)
1991 struct qedi_io_log
*io_log
;
1992 struct iscsi_conn
*conn
= task
->conn
;
1993 struct qedi_conn
*qedi_conn
= conn
->dd_data
;
1994 struct scsi_cmnd
*sc_cmd
= task
->sc
;
1995 unsigned long flags
;
1997 spin_lock_irqsave(&qedi
->io_trace_lock
, flags
);
1999 io_log
= &qedi
->io_trace_buf
[qedi
->io_trace_idx
];
2000 io_log
->direction
= direction
;
2001 io_log
->task_id
= tid
;
2002 io_log
->cid
= qedi_conn
->iscsi_conn_id
;
2003 io_log
->lun
= sc_cmd
->device
->lun
;
2004 io_log
->op
= sc_cmd
->cmnd
[0];
2005 io_log
->lba
[0] = sc_cmd
->cmnd
[2];
2006 io_log
->lba
[1] = sc_cmd
->cmnd
[3];
2007 io_log
->lba
[2] = sc_cmd
->cmnd
[4];
2008 io_log
->lba
[3] = sc_cmd
->cmnd
[5];
2009 io_log
->bufflen
= scsi_bufflen(sc_cmd
);
2010 io_log
->sg_count
= scsi_sg_count(sc_cmd
);
2011 io_log
->fast_sgs
= qedi
->fast_sgls
;
2012 io_log
->cached_sgs
= qedi
->cached_sgls
;
2013 io_log
->slow_sgs
= qedi
->slow_sgls
;
2014 io_log
->cached_sge
= qedi
->use_cached_sge
;
2015 io_log
->slow_sge
= qedi
->use_slow_sge
;
2016 io_log
->fast_sge
= qedi
->use_fast_sge
;
2017 io_log
->result
= sc_cmd
->result
;
2018 io_log
->jiffies
= jiffies
;
2019 io_log
->blk_req_cpu
= smp_processor_id();
2021 if (direction
== QEDI_IO_TRACE_REQ
) {
2022 /* For requests we only care about the submission CPU */
2023 io_log
->req_cpu
= smp_processor_id() % qedi
->num_queues
;
2024 io_log
->intr_cpu
= 0;
2025 io_log
->blk_rsp_cpu
= 0;
2026 } else if (direction
== QEDI_IO_TRACE_RSP
) {
2027 io_log
->req_cpu
= smp_processor_id() % qedi
->num_queues
;
2028 io_log
->intr_cpu
= qedi
->intr_cpu
;
2029 io_log
->blk_rsp_cpu
= smp_processor_id();
2032 qedi
->io_trace_idx
++;
2033 if (qedi
->io_trace_idx
== QEDI_IO_TRACE_SIZE
)
2034 qedi
->io_trace_idx
= 0;
2036 qedi
->use_cached_sge
= false;
2037 qedi
->use_slow_sge
= false;
2038 qedi
->use_fast_sge
= false;
2040 spin_unlock_irqrestore(&qedi
->io_trace_lock
, flags
);
2043 int qedi_iscsi_send_ioreq(struct iscsi_task
*task
)
2045 struct iscsi_conn
*conn
= task
->conn
;
2046 struct iscsi_session
*session
= conn
->session
;
2047 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
->cls_session
);
2048 struct qedi_ctx
*qedi
= iscsi_host_priv(shost
);
2049 struct qedi_conn
*qedi_conn
= conn
->dd_data
;
2050 struct qedi_cmd
*cmd
= task
->dd_data
;
2051 struct scsi_cmnd
*sc
= task
->sc
;
2052 struct iscsi_cmd_hdr cmd_pdu_header
;
2053 struct scsi_sgl_task_params tx_sgl_task_params
;
2054 struct scsi_sgl_task_params rx_sgl_task_params
;
2055 struct scsi_sgl_task_params
*prx_sgl
= NULL
;
2056 struct scsi_sgl_task_params
*ptx_sgl
= NULL
;
2057 struct iscsi_task_params task_params
;
2058 struct iscsi_conn_params conn_params
;
2059 struct scsi_initiator_cmd_params cmd_params
;
2060 struct e4_iscsi_task_context
*fw_task_ctx
;
2061 struct iscsi_cls_conn
*cls_conn
;
2062 struct iscsi_scsi_req
*hdr
= (struct iscsi_scsi_req
*)task
->hdr
;
2063 enum iscsi_task_type task_type
= MAX_ISCSI_TASK_TYPE
;
2064 struct qedi_endpoint
*ep
;
2072 cls_conn
= qedi_conn
->cls_conn
;
2073 conn
= cls_conn
->dd_data
;
2075 qedi_iscsi_map_sg_list(cmd
);
2076 int_to_scsilun(sc
->device
->lun
, (struct scsi_lun
*)scsi_lun
);
2078 tid
= qedi_get_task_idx(qedi
);
2083 (struct e4_iscsi_task_context
*)qedi_get_task_mem(&qedi
->tasks
,
2085 memset(fw_task_ctx
, 0, sizeof(struct e4_iscsi_task_context
));
2089 memset(&task_params
, 0, sizeof(task_params
));
2090 memset(&cmd_pdu_header
, 0, sizeof(cmd_pdu_header
));
2091 memset(&tx_sgl_task_params
, 0, sizeof(tx_sgl_task_params
));
2092 memset(&rx_sgl_task_params
, 0, sizeof(rx_sgl_task_params
));
2093 memset(&conn_params
, 0, sizeof(conn_params
));
2094 memset(&cmd_params
, 0, sizeof(cmd_params
));
2096 cq_idx
= smp_processor_id() % qedi
->num_queues
;
2097 /* Update header info */
2098 SET_FIELD(cmd_pdu_header
.flags_attr
, ISCSI_CMD_HDR_ATTR
,
2100 if (hdr
->cdb
[0] != TEST_UNIT_READY
) {
2101 if (sc
->sc_data_direction
== DMA_TO_DEVICE
) {
2102 SET_FIELD(cmd_pdu_header
.flags_attr
,
2103 ISCSI_CMD_HDR_WRITE
, 1);
2104 task_type
= ISCSI_TASK_TYPE_INITIATOR_WRITE
;
2106 SET_FIELD(cmd_pdu_header
.flags_attr
,
2107 ISCSI_CMD_HDR_READ
, 1);
2108 task_type
= ISCSI_TASK_TYPE_INITIATOR_READ
;
2112 cmd_pdu_header
.lun
.lo
= be32_to_cpu(scsi_lun
[0]);
2113 cmd_pdu_header
.lun
.hi
= be32_to_cpu(scsi_lun
[1]);
2115 qedi_update_itt_map(qedi
, tid
, task
->itt
, cmd
);
2116 cmd_pdu_header
.itt
= qedi_set_itt(tid
, get_itt(task
->itt
));
2117 cmd_pdu_header
.expected_transfer_length
= cpu_to_be32(hdr
->data_length
);
2118 cmd_pdu_header
.hdr_second_dword
= ntoh24(hdr
->dlength
);
2119 cmd_pdu_header
.cmd_sn
= be32_to_cpu(hdr
->cmdsn
);
2120 cmd_pdu_header
.hdr_first_byte
= hdr
->opcode
;
2121 qedi_cpy_scsi_cdb(sc
, (u32
*)cmd_pdu_header
.cdb
);
2123 /* Fill tx AHS and rx buffer */
2124 if (task_type
== ISCSI_TASK_TYPE_INITIATOR_WRITE
) {
2125 tx_sgl_task_params
.sgl
= cmd
->io_tbl
.sge_tbl
;
2126 tx_sgl_task_params
.sgl_phys_addr
.lo
=
2127 (u32
)(cmd
->io_tbl
.sge_tbl_dma
);
2128 tx_sgl_task_params
.sgl_phys_addr
.hi
=
2129 (u32
)((u64
)cmd
->io_tbl
.sge_tbl_dma
>> 32);
2130 tx_sgl_task_params
.total_buffer_size
= scsi_bufflen(sc
);
2131 tx_sgl_task_params
.num_sges
= cmd
->io_tbl
.sge_valid
;
2132 if (cmd
->use_slowpath
)
2133 tx_sgl_task_params
.small_mid_sge
= true;
2134 } else if (task_type
== ISCSI_TASK_TYPE_INITIATOR_READ
) {
2135 rx_sgl_task_params
.sgl
= cmd
->io_tbl
.sge_tbl
;
2136 rx_sgl_task_params
.sgl_phys_addr
.lo
=
2137 (u32
)(cmd
->io_tbl
.sge_tbl_dma
);
2138 rx_sgl_task_params
.sgl_phys_addr
.hi
=
2139 (u32
)((u64
)cmd
->io_tbl
.sge_tbl_dma
>> 32);
2140 rx_sgl_task_params
.total_buffer_size
= scsi_bufflen(sc
);
2141 rx_sgl_task_params
.num_sges
= cmd
->io_tbl
.sge_valid
;
2144 /* Add conn param */
2145 conn_params
.first_burst_length
= conn
->session
->first_burst
;
2146 conn_params
.max_send_pdu_length
= conn
->max_xmit_dlength
;
2147 conn_params
.max_burst_length
= conn
->session
->max_burst
;
2148 if (conn
->session
->initial_r2t_en
)
2149 conn_params
.initial_r2t
= true;
2150 if (conn
->session
->imm_data_en
)
2151 conn_params
.immediate_data
= true;
2153 /* Add cmd params */
2154 cmd_params
.sense_data_buffer_phys_addr
.lo
= (u32
)cmd
->sense_buffer_dma
;
2155 cmd_params
.sense_data_buffer_phys_addr
.hi
=
2156 (u32
)((u64
)cmd
->sense_buffer_dma
>> 32);
2157 /* Fill fw input params */
2158 task_params
.context
= fw_task_ctx
;
2159 task_params
.conn_icid
= (u16
)qedi_conn
->iscsi_conn_id
;
2160 task_params
.itid
= tid
;
2161 task_params
.cq_rss_number
= cq_idx
;
2162 if (task_type
== ISCSI_TASK_TYPE_INITIATOR_WRITE
)
2163 task_params
.tx_io_size
= scsi_bufflen(sc
);
2164 else if (task_type
== ISCSI_TASK_TYPE_INITIATOR_READ
)
2165 task_params
.rx_io_size
= scsi_bufflen(sc
);
2167 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
2168 task_params
.sqe
= &ep
->sq
[sq_idx
];
2170 QEDI_INFO(&qedi
->dbg_ctx
, QEDI_LOG_IO
,
2171 "%s: %s-SGL: sg_len=0x%x num_sges=0x%x first-sge-lo=0x%x first-sge-hi=0x%x\n",
2172 (task_type
== ISCSI_TASK_TYPE_INITIATOR_WRITE
) ?
2173 "Write " : "Read ", (cmd
->io_tbl
.sge_valid
== 1) ?
2174 "Single" : (cmd
->use_slowpath
? "SLOW" : "FAST"),
2175 (u16
)cmd
->io_tbl
.sge_valid
, scsi_bufflen(sc
),
2176 (u32
)(cmd
->io_tbl
.sge_tbl_dma
),
2177 (u32
)((u64
)cmd
->io_tbl
.sge_tbl_dma
>> 32));
2179 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
2181 if (task_params
.tx_io_size
!= 0)
2182 ptx_sgl
= &tx_sgl_task_params
;
2183 if (task_params
.rx_io_size
!= 0)
2184 prx_sgl
= &rx_sgl_task_params
;
2186 rval
= init_initiator_rw_iscsi_task(&task_params
, &conn_params
,
2187 &cmd_params
, &cmd_pdu_header
,
2193 spin_lock(&qedi_conn
->list_lock
);
2194 list_add_tail(&cmd
->io_cmd
, &qedi_conn
->active_cmd_list
);
2195 cmd
->io_cmd_in_list
= true;
2196 qedi_conn
->active_cmd_count
++;
2197 spin_unlock(&qedi_conn
->list_lock
);
2199 qedi_ring_doorbell(qedi_conn
);
2203 int qedi_iscsi_cleanup_task(struct iscsi_task
*task
, bool mark_cmd_node_deleted
)
2205 struct iscsi_task_params task_params
;
2206 struct qedi_endpoint
*ep
;
2207 struct iscsi_conn
*conn
= task
->conn
;
2208 struct qedi_conn
*qedi_conn
= conn
->dd_data
;
2209 struct qedi_cmd
*cmd
= task
->dd_data
;
2213 QEDI_INFO(&qedi_conn
->qedi
->dbg_ctx
, QEDI_LOG_SCSI_TM
,
2214 "issue cleanup tid=0x%x itt=0x%x task_state=%d cmd_state=0%x cid=0x%x\n",
2215 cmd
->task_id
, get_itt(task
->itt
), task
->state
,
2216 cmd
->state
, qedi_conn
->iscsi_conn_id
);
2218 memset(&task_params
, 0, sizeof(task_params
));
2221 sq_idx
= qedi_get_wqe_idx(qedi_conn
);
2223 task_params
.sqe
= &ep
->sq
[sq_idx
];
2224 memset(task_params
.sqe
, 0, sizeof(struct iscsi_wqe
));
2225 task_params
.itid
= cmd
->task_id
;
2227 rval
= init_cleanup_task(&task_params
);
2231 qedi_ring_doorbell(qedi_conn
);