2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
8 #include "qla_target.h"
10 #include <linux/blkdev.h>
11 #include <linux/delay.h>
13 #include <scsi/scsi_tcq.h>
16 * qla2x00_get_cmd_direction() - Determine control_flag data direction.
19 * Returns the proper CF_* direction based on CDB.
21 static inline uint16_t
22 qla2x00_get_cmd_direction(srb_t
*sp
)
25 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
26 struct scsi_qla_host
*vha
= sp
->vha
;
30 /* Set transfer direction */
31 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
) {
33 vha
->qla_stats
.output_bytes
+= scsi_bufflen(cmd
);
34 vha
->qla_stats
.output_requests
++;
35 } else if (cmd
->sc_data_direction
== DMA_FROM_DEVICE
) {
37 vha
->qla_stats
.input_bytes
+= scsi_bufflen(cmd
);
38 vha
->qla_stats
.input_requests
++;
44 * qla2x00_calc_iocbs_32() - Determine number of Command Type 2 and
45 * Continuation Type 0 IOCBs to allocate.
47 * @dsds: number of data segment decriptors needed
49 * Returns the number of IOCB entries needed to store @dsds.
52 qla2x00_calc_iocbs_32(uint16_t dsds
)
58 iocbs
+= (dsds
- 3) / 7;
66 * qla2x00_calc_iocbs_64() - Determine number of Command Type 3 and
67 * Continuation Type 1 IOCBs to allocate.
69 * @dsds: number of data segment decriptors needed
71 * Returns the number of IOCB entries needed to store @dsds.
74 qla2x00_calc_iocbs_64(uint16_t dsds
)
80 iocbs
+= (dsds
- 2) / 5;
88 * qla2x00_prep_cont_type0_iocb() - Initialize a Continuation Type 0 IOCB.
91 * Returns a pointer to the Continuation Type 0 IOCB packet.
93 static inline cont_entry_t
*
94 qla2x00_prep_cont_type0_iocb(struct scsi_qla_host
*vha
)
96 cont_entry_t
*cont_pkt
;
97 struct req_que
*req
= vha
->req
;
98 /* Adjust ring index. */
100 if (req
->ring_index
== req
->length
) {
102 req
->ring_ptr
= req
->ring
;
107 cont_pkt
= (cont_entry_t
*)req
->ring_ptr
;
109 /* Load packet defaults. */
110 *((uint32_t *)(&cont_pkt
->entry_type
)) = cpu_to_le32(CONTINUE_TYPE
);
116 * qla2x00_prep_cont_type1_iocb() - Initialize a Continuation Type 1 IOCB.
119 * Returns a pointer to the continuation type 1 IOCB packet.
121 static inline cont_a64_entry_t
*
122 qla2x00_prep_cont_type1_iocb(scsi_qla_host_t
*vha
, struct req_que
*req
)
124 cont_a64_entry_t
*cont_pkt
;
126 /* Adjust ring index. */
128 if (req
->ring_index
== req
->length
) {
130 req
->ring_ptr
= req
->ring
;
135 cont_pkt
= (cont_a64_entry_t
*)req
->ring_ptr
;
137 /* Load packet defaults. */
138 *((uint32_t *)(&cont_pkt
->entry_type
)) = IS_QLAFX00(vha
->hw
) ?
139 cpu_to_le32(CONTINUE_A64_TYPE_FX00
) :
140 cpu_to_le32(CONTINUE_A64_TYPE
);
146 qla24xx_configure_prot_mode(srb_t
*sp
, uint16_t *fw_prot_opts
)
148 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
149 uint8_t guard
= scsi_host_get_guard(cmd
->device
->host
);
151 /* We always use DIFF Bundling for best performance */
154 /* Translate SCSI opcode to a protection opcode */
155 switch (scsi_get_prot_op(cmd
)) {
156 case SCSI_PROT_READ_STRIP
:
157 *fw_prot_opts
|= PO_MODE_DIF_REMOVE
;
159 case SCSI_PROT_WRITE_INSERT
:
160 *fw_prot_opts
|= PO_MODE_DIF_INSERT
;
162 case SCSI_PROT_READ_INSERT
:
163 *fw_prot_opts
|= PO_MODE_DIF_INSERT
;
165 case SCSI_PROT_WRITE_STRIP
:
166 *fw_prot_opts
|= PO_MODE_DIF_REMOVE
;
168 case SCSI_PROT_READ_PASS
:
169 case SCSI_PROT_WRITE_PASS
:
170 if (guard
& SHOST_DIX_GUARD_IP
)
171 *fw_prot_opts
|= PO_MODE_DIF_TCP_CKSUM
;
173 *fw_prot_opts
|= PO_MODE_DIF_PASS
;
175 default: /* Normal Request */
176 *fw_prot_opts
|= PO_MODE_DIF_PASS
;
180 return scsi_prot_sg_count(cmd
);
184 * qla2x00_build_scsi_iocbs_32() - Build IOCB command utilizing 32bit
185 * capable IOCB types.
187 * @sp: SRB command to process
188 * @cmd_pkt: Command type 2 IOCB
189 * @tot_dsds: Total number of segments to transfer
191 void qla2x00_build_scsi_iocbs_32(srb_t
*sp
, cmd_entry_t
*cmd_pkt
,
196 scsi_qla_host_t
*vha
;
197 struct scsi_cmnd
*cmd
;
198 struct scatterlist
*sg
;
201 cmd
= GET_CMD_SP(sp
);
203 /* Update entry type to indicate Command Type 2 IOCB */
204 *((uint32_t *)(&cmd_pkt
->entry_type
)) =
205 cpu_to_le32(COMMAND_TYPE
);
207 /* No data transfer */
208 if (!scsi_bufflen(cmd
) || cmd
->sc_data_direction
== DMA_NONE
) {
209 cmd_pkt
->byte_count
= cpu_to_le32(0);
214 cmd_pkt
->control_flags
|= cpu_to_le16(qla2x00_get_cmd_direction(sp
));
216 /* Three DSDs are available in the Command Type 2 IOCB */
218 cur_dsd
= (uint32_t *)&cmd_pkt
->dseg_0_address
;
220 /* Load data segments */
221 scsi_for_each_sg(cmd
, sg
, tot_dsds
, i
) {
222 cont_entry_t
*cont_pkt
;
224 /* Allocate additional continuation packets? */
225 if (avail_dsds
== 0) {
227 * Seven DSDs are available in the Continuation
230 cont_pkt
= qla2x00_prep_cont_type0_iocb(vha
);
231 cur_dsd
= (uint32_t *)&cont_pkt
->dseg_0_address
;
235 *cur_dsd
++ = cpu_to_le32(sg_dma_address(sg
));
236 *cur_dsd
++ = cpu_to_le32(sg_dma_len(sg
));
242 * qla2x00_build_scsi_iocbs_64() - Build IOCB command utilizing 64bit
243 * capable IOCB types.
245 * @sp: SRB command to process
246 * @cmd_pkt: Command type 3 IOCB
247 * @tot_dsds: Total number of segments to transfer
249 void qla2x00_build_scsi_iocbs_64(srb_t
*sp
, cmd_entry_t
*cmd_pkt
,
254 scsi_qla_host_t
*vha
;
255 struct scsi_cmnd
*cmd
;
256 struct scatterlist
*sg
;
259 cmd
= GET_CMD_SP(sp
);
261 /* Update entry type to indicate Command Type 3 IOCB */
262 *((uint32_t *)(&cmd_pkt
->entry_type
)) = cpu_to_le32(COMMAND_A64_TYPE
);
264 /* No data transfer */
265 if (!scsi_bufflen(cmd
) || cmd
->sc_data_direction
== DMA_NONE
) {
266 cmd_pkt
->byte_count
= cpu_to_le32(0);
271 cmd_pkt
->control_flags
|= cpu_to_le16(qla2x00_get_cmd_direction(sp
));
273 /* Two DSDs are available in the Command Type 3 IOCB */
275 cur_dsd
= (uint32_t *)&cmd_pkt
->dseg_0_address
;
277 /* Load data segments */
278 scsi_for_each_sg(cmd
, sg
, tot_dsds
, i
) {
280 cont_a64_entry_t
*cont_pkt
;
282 /* Allocate additional continuation packets? */
283 if (avail_dsds
== 0) {
285 * Five DSDs are available in the Continuation
288 cont_pkt
= qla2x00_prep_cont_type1_iocb(vha
, vha
->req
);
289 cur_dsd
= (uint32_t *)cont_pkt
->dseg_0_address
;
293 sle_dma
= sg_dma_address(sg
);
294 *cur_dsd
++ = cpu_to_le32(LSD(sle_dma
));
295 *cur_dsd
++ = cpu_to_le32(MSD(sle_dma
));
296 *cur_dsd
++ = cpu_to_le32(sg_dma_len(sg
));
302 * qla2x00_start_scsi() - Send a SCSI command to the ISP
303 * @sp: command to send to the ISP
305 * Returns non-zero if a failure occurred, else zero.
308 qla2x00_start_scsi(srb_t
*sp
)
312 scsi_qla_host_t
*vha
;
313 struct scsi_cmnd
*cmd
;
317 cmd_entry_t
*cmd_pkt
;
321 struct device_reg_2xxx __iomem
*reg
;
322 struct qla_hw_data
*ha
;
326 /* Setup device pointers. */
329 reg
= &ha
->iobase
->isp
;
330 cmd
= GET_CMD_SP(sp
);
331 req
= ha
->req_q_map
[0];
332 rsp
= ha
->rsp_q_map
[0];
333 /* So we know we haven't pci_map'ed anything yet */
336 /* Send marker if required */
337 if (vha
->marker_needed
!= 0) {
338 if (qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
) !=
340 return (QLA_FUNCTION_FAILED
);
342 vha
->marker_needed
= 0;
345 /* Acquire ring specific lock */
346 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
348 /* Check for room in outstanding command list. */
349 handle
= req
->current_outstanding_cmd
;
350 for (index
= 1; index
< req
->num_outstanding_cmds
; index
++) {
352 if (handle
== req
->num_outstanding_cmds
)
354 if (!req
->outstanding_cmds
[handle
])
357 if (index
== req
->num_outstanding_cmds
)
360 /* Map the sg table so we have an accurate count of sg entries needed */
361 if (scsi_sg_count(cmd
)) {
362 nseg
= dma_map_sg(&ha
->pdev
->dev
, scsi_sglist(cmd
),
363 scsi_sg_count(cmd
), cmd
->sc_data_direction
);
371 /* Calculate the number of request entries needed. */
372 req_cnt
= ha
->isp_ops
->calc_req_entries(tot_dsds
);
373 if (req
->cnt
< (req_cnt
+ 2)) {
374 cnt
= RD_REG_WORD_RELAXED(ISP_REQ_Q_OUT(ha
, reg
));
375 if (req
->ring_index
< cnt
)
376 req
->cnt
= cnt
- req
->ring_index
;
378 req
->cnt
= req
->length
-
379 (req
->ring_index
- cnt
);
380 /* If still no head room then bail out */
381 if (req
->cnt
< (req_cnt
+ 2))
385 /* Build command packet */
386 req
->current_outstanding_cmd
= handle
;
387 req
->outstanding_cmds
[handle
] = sp
;
389 cmd
->host_scribble
= (unsigned char *)(unsigned long)handle
;
392 cmd_pkt
= (cmd_entry_t
*)req
->ring_ptr
;
393 cmd_pkt
->handle
= handle
;
394 /* Zero out remaining portion of packet. */
395 clr_ptr
= (uint32_t *)cmd_pkt
+ 2;
396 memset(clr_ptr
, 0, REQUEST_ENTRY_SIZE
- 8);
397 cmd_pkt
->dseg_count
= cpu_to_le16(tot_dsds
);
399 /* Set target ID and LUN number*/
400 SET_TARGET_ID(ha
, cmd_pkt
->target
, sp
->fcport
->loop_id
);
401 cmd_pkt
->lun
= cpu_to_le16(cmd
->device
->lun
);
402 cmd_pkt
->control_flags
= cpu_to_le16(CF_SIMPLE_TAG
);
404 /* Load SCSI command packet. */
405 memcpy(cmd_pkt
->scsi_cdb
, cmd
->cmnd
, cmd
->cmd_len
);
406 cmd_pkt
->byte_count
= cpu_to_le32((uint32_t)scsi_bufflen(cmd
));
408 /* Build IOCB segments */
409 ha
->isp_ops
->build_iocbs(sp
, cmd_pkt
, tot_dsds
);
411 /* Set total data segment count. */
412 cmd_pkt
->entry_count
= (uint8_t)req_cnt
;
415 /* Adjust ring index. */
417 if (req
->ring_index
== req
->length
) {
419 req
->ring_ptr
= req
->ring
;
423 sp
->flags
|= SRB_DMA_VALID
;
425 /* Set chip new ring index. */
426 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), req
->ring_index
);
427 RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha
, reg
)); /* PCI Posting. */
429 /* Manage unprocessed RIO/ZIO commands in response queue. */
430 if (vha
->flags
.process_response_queue
&&
431 rsp
->ring_ptr
->signature
!= RESPONSE_PROCESSED
)
432 qla2x00_process_response_queue(rsp
);
434 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
435 return (QLA_SUCCESS
);
441 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
443 return (QLA_FUNCTION_FAILED
);
447 * qla2x00_start_iocbs() - Execute the IOCB command
450 qla2x00_start_iocbs(struct scsi_qla_host
*vha
, struct req_que
*req
)
452 struct qla_hw_data
*ha
= vha
->hw
;
453 device_reg_t
*reg
= ISP_QUE_REG(ha
, req
->id
);
455 if (IS_P3P_TYPE(ha
)) {
456 qla82xx_start_iocbs(vha
);
458 /* Adjust ring index. */
460 if (req
->ring_index
== req
->length
) {
462 req
->ring_ptr
= req
->ring
;
466 /* Set chip new ring index. */
467 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
468 WRT_REG_DWORD(req
->req_q_in
, req
->ring_index
);
469 RD_REG_DWORD_RELAXED(&ha
->iobase
->isp24
.hccr
);
470 } else if (IS_QLAFX00(ha
)) {
471 WRT_REG_DWORD(®
->ispfx00
.req_q_in
, req
->ring_index
);
472 RD_REG_DWORD_RELAXED(®
->ispfx00
.req_q_in
);
473 QLAFX00_SET_HST_INTR(ha
, ha
->rqstq_intr_code
);
474 } else if (IS_FWI2_CAPABLE(ha
)) {
475 WRT_REG_DWORD(®
->isp24
.req_q_in
, req
->ring_index
);
476 RD_REG_DWORD_RELAXED(®
->isp24
.req_q_in
);
478 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, ®
->isp
),
480 RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha
, ®
->isp
));
486 * qla2x00_marker() - Send a marker IOCB to the firmware.
490 * @type: marker modifier
492 * Can be called from both normal and interrupt context.
494 * Returns non-zero if a failure occurred, else zero.
497 __qla2x00_marker(struct scsi_qla_host
*vha
, struct req_que
*req
,
498 struct rsp_que
*rsp
, uint16_t loop_id
,
499 uint64_t lun
, uint8_t type
)
502 struct mrk_entry_24xx
*mrk24
= NULL
;
504 struct qla_hw_data
*ha
= vha
->hw
;
505 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
507 req
= ha
->req_q_map
[0];
508 mrk
= (mrk_entry_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
510 ql_log(ql_log_warn
, base_vha
, 0x3026,
511 "Failed to allocate Marker IOCB.\n");
513 return (QLA_FUNCTION_FAILED
);
516 mrk
->entry_type
= MARKER_TYPE
;
517 mrk
->modifier
= type
;
518 if (type
!= MK_SYNC_ALL
) {
519 if (IS_FWI2_CAPABLE(ha
)) {
520 mrk24
= (struct mrk_entry_24xx
*) mrk
;
521 mrk24
->nport_handle
= cpu_to_le16(loop_id
);
522 int_to_scsilun(lun
, (struct scsi_lun
*)&mrk24
->lun
);
523 host_to_fcp_swap(mrk24
->lun
, sizeof(mrk24
->lun
));
524 mrk24
->vp_index
= vha
->vp_idx
;
525 mrk24
->handle
= MAKE_HANDLE(req
->id
, mrk24
->handle
);
527 SET_TARGET_ID(ha
, mrk
->target
, loop_id
);
528 mrk
->lun
= cpu_to_le16((uint16_t)lun
);
533 qla2x00_start_iocbs(vha
, req
);
535 return (QLA_SUCCESS
);
539 qla2x00_marker(struct scsi_qla_host
*vha
, struct req_que
*req
,
540 struct rsp_que
*rsp
, uint16_t loop_id
, uint64_t lun
,
544 unsigned long flags
= 0;
546 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
547 ret
= __qla2x00_marker(vha
, req
, rsp
, loop_id
, lun
, type
);
548 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
554 * qla2x00_issue_marker
557 * Caller CAN have hardware lock held as specified by ha_locked parameter.
558 * Might release it, then reaquire.
560 int qla2x00_issue_marker(scsi_qla_host_t
*vha
, int ha_locked
)
563 if (__qla2x00_marker(vha
, vha
->req
, vha
->req
->rsp
, 0, 0,
564 MK_SYNC_ALL
) != QLA_SUCCESS
)
565 return QLA_FUNCTION_FAILED
;
567 if (qla2x00_marker(vha
, vha
->req
, vha
->req
->rsp
, 0, 0,
568 MK_SYNC_ALL
) != QLA_SUCCESS
)
569 return QLA_FUNCTION_FAILED
;
571 vha
->marker_needed
= 0;
577 qla24xx_build_scsi_type_6_iocbs(srb_t
*sp
, struct cmd_type_6
*cmd_pkt
,
580 uint32_t *cur_dsd
= NULL
;
581 scsi_qla_host_t
*vha
;
582 struct qla_hw_data
*ha
;
583 struct scsi_cmnd
*cmd
;
584 struct scatterlist
*cur_seg
;
588 uint8_t first_iocb
= 1;
589 uint32_t dsd_list_len
;
590 struct dsd_dma
*dsd_ptr
;
593 cmd
= GET_CMD_SP(sp
);
595 /* Update entry type to indicate Command Type 3 IOCB */
596 *((uint32_t *)(&cmd_pkt
->entry_type
)) = cpu_to_le32(COMMAND_TYPE_6
);
598 /* No data transfer */
599 if (!scsi_bufflen(cmd
) || cmd
->sc_data_direction
== DMA_NONE
) {
600 cmd_pkt
->byte_count
= cpu_to_le32(0);
607 /* Set transfer direction */
608 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
) {
609 cmd_pkt
->control_flags
= cpu_to_le16(CF_WRITE_DATA
);
610 vha
->qla_stats
.output_bytes
+= scsi_bufflen(cmd
);
611 vha
->qla_stats
.output_requests
++;
612 } else if (cmd
->sc_data_direction
== DMA_FROM_DEVICE
) {
613 cmd_pkt
->control_flags
= cpu_to_le16(CF_READ_DATA
);
614 vha
->qla_stats
.input_bytes
+= scsi_bufflen(cmd
);
615 vha
->qla_stats
.input_requests
++;
618 cur_seg
= scsi_sglist(cmd
);
619 ctx
= GET_CMD_CTX_SP(sp
);
622 avail_dsds
= (tot_dsds
> QLA_DSDS_PER_IOCB
) ?
623 QLA_DSDS_PER_IOCB
: tot_dsds
;
624 tot_dsds
-= avail_dsds
;
625 dsd_list_len
= (avail_dsds
+ 1) * QLA_DSD_SIZE
;
627 dsd_ptr
= list_first_entry(&ha
->gbl_dsd_list
,
628 struct dsd_dma
, list
);
629 next_dsd
= dsd_ptr
->dsd_addr
;
630 list_del(&dsd_ptr
->list
);
632 list_add_tail(&dsd_ptr
->list
, &ctx
->dsd_list
);
638 dsd_seg
= (uint32_t *)&cmd_pkt
->fcp_data_dseg_address
;
639 *dsd_seg
++ = cpu_to_le32(LSD(dsd_ptr
->dsd_list_dma
));
640 *dsd_seg
++ = cpu_to_le32(MSD(dsd_ptr
->dsd_list_dma
));
641 cmd_pkt
->fcp_data_dseg_len
= cpu_to_le32(dsd_list_len
);
643 *cur_dsd
++ = cpu_to_le32(LSD(dsd_ptr
->dsd_list_dma
));
644 *cur_dsd
++ = cpu_to_le32(MSD(dsd_ptr
->dsd_list_dma
));
645 *cur_dsd
++ = cpu_to_le32(dsd_list_len
);
647 cur_dsd
= (uint32_t *)next_dsd
;
651 sle_dma
= sg_dma_address(cur_seg
);
652 *cur_dsd
++ = cpu_to_le32(LSD(sle_dma
));
653 *cur_dsd
++ = cpu_to_le32(MSD(sle_dma
));
654 *cur_dsd
++ = cpu_to_le32(sg_dma_len(cur_seg
));
655 cur_seg
= sg_next(cur_seg
);
660 /* Null termination */
664 cmd_pkt
->control_flags
|= CF_DATA_SEG_DESCR_ENABLE
;
669 * qla24xx_calc_dsd_lists() - Determine number of DSD list required
670 * for Command Type 6.
672 * @dsds: number of data segment decriptors needed
674 * Returns the number of dsd list needed to store @dsds.
676 static inline uint16_t
677 qla24xx_calc_dsd_lists(uint16_t dsds
)
679 uint16_t dsd_lists
= 0;
681 dsd_lists
= (dsds
/QLA_DSDS_PER_IOCB
);
682 if (dsds
% QLA_DSDS_PER_IOCB
)
689 * qla24xx_build_scsi_iocbs() - Build IOCB command utilizing Command Type 7
692 * @sp: SRB command to process
693 * @cmd_pkt: Command type 3 IOCB
694 * @tot_dsds: Total number of segments to transfer
695 * @req: pointer to request queue
698 qla24xx_build_scsi_iocbs(srb_t
*sp
, struct cmd_type_7
*cmd_pkt
,
699 uint16_t tot_dsds
, struct req_que
*req
)
703 scsi_qla_host_t
*vha
;
704 struct scsi_cmnd
*cmd
;
705 struct scatterlist
*sg
;
708 cmd
= GET_CMD_SP(sp
);
710 /* Update entry type to indicate Command Type 3 IOCB */
711 *((uint32_t *)(&cmd_pkt
->entry_type
)) = cpu_to_le32(COMMAND_TYPE_7
);
713 /* No data transfer */
714 if (!scsi_bufflen(cmd
) || cmd
->sc_data_direction
== DMA_NONE
) {
715 cmd_pkt
->byte_count
= cpu_to_le32(0);
721 /* Set transfer direction */
722 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
) {
723 cmd_pkt
->task_mgmt_flags
= cpu_to_le16(TMF_WRITE_DATA
);
724 vha
->qla_stats
.output_bytes
+= scsi_bufflen(cmd
);
725 vha
->qla_stats
.output_requests
++;
726 } else if (cmd
->sc_data_direction
== DMA_FROM_DEVICE
) {
727 cmd_pkt
->task_mgmt_flags
= cpu_to_le16(TMF_READ_DATA
);
728 vha
->qla_stats
.input_bytes
+= scsi_bufflen(cmd
);
729 vha
->qla_stats
.input_requests
++;
732 /* One DSD is available in the Command Type 3 IOCB */
734 cur_dsd
= (uint32_t *)&cmd_pkt
->dseg_0_address
;
736 /* Load data segments */
738 scsi_for_each_sg(cmd
, sg
, tot_dsds
, i
) {
740 cont_a64_entry_t
*cont_pkt
;
742 /* Allocate additional continuation packets? */
743 if (avail_dsds
== 0) {
745 * Five DSDs are available in the Continuation
748 cont_pkt
= qla2x00_prep_cont_type1_iocb(vha
, req
);
749 cur_dsd
= (uint32_t *)cont_pkt
->dseg_0_address
;
753 sle_dma
= sg_dma_address(sg
);
754 *cur_dsd
++ = cpu_to_le32(LSD(sle_dma
));
755 *cur_dsd
++ = cpu_to_le32(MSD(sle_dma
));
756 *cur_dsd
++ = cpu_to_le32(sg_dma_len(sg
));
761 struct fw_dif_context
{
764 uint8_t ref_tag_mask
[4]; /* Validation/Replacement Mask*/
765 uint8_t app_tag_mask
[2]; /* Validation/Replacement Mask*/
769 * qla24xx_set_t10dif_tags_from_cmd - Extract Ref and App tags from SCSI command
773 qla24xx_set_t10dif_tags(srb_t
*sp
, struct fw_dif_context
*pkt
,
774 unsigned int protcnt
)
776 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
778 switch (scsi_get_prot_type(cmd
)) {
779 case SCSI_PROT_DIF_TYPE0
:
781 * No check for ql2xenablehba_err_chk, as it would be an
782 * I/O error if hba tag generation is not done.
784 pkt
->ref_tag
= cpu_to_le32((uint32_t)
785 (0xffffffff & scsi_get_lba(cmd
)));
787 if (!qla2x00_hba_err_chk_enabled(sp
))
790 pkt
->ref_tag_mask
[0] = 0xff;
791 pkt
->ref_tag_mask
[1] = 0xff;
792 pkt
->ref_tag_mask
[2] = 0xff;
793 pkt
->ref_tag_mask
[3] = 0xff;
797 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to
798 * match LBA in CDB + N
800 case SCSI_PROT_DIF_TYPE2
:
801 pkt
->app_tag
= cpu_to_le16(0);
802 pkt
->app_tag_mask
[0] = 0x0;
803 pkt
->app_tag_mask
[1] = 0x0;
805 pkt
->ref_tag
= cpu_to_le32((uint32_t)
806 (0xffffffff & scsi_get_lba(cmd
)));
808 if (!qla2x00_hba_err_chk_enabled(sp
))
811 /* enable ALL bytes of the ref tag */
812 pkt
->ref_tag_mask
[0] = 0xff;
813 pkt
->ref_tag_mask
[1] = 0xff;
814 pkt
->ref_tag_mask
[2] = 0xff;
815 pkt
->ref_tag_mask
[3] = 0xff;
818 /* For Type 3 protection: 16 bit GUARD only */
819 case SCSI_PROT_DIF_TYPE3
:
820 pkt
->ref_tag_mask
[0] = pkt
->ref_tag_mask
[1] =
821 pkt
->ref_tag_mask
[2] = pkt
->ref_tag_mask
[3] =
826 * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and
829 case SCSI_PROT_DIF_TYPE1
:
830 pkt
->ref_tag
= cpu_to_le32((uint32_t)
831 (0xffffffff & scsi_get_lba(cmd
)));
832 pkt
->app_tag
= cpu_to_le16(0);
833 pkt
->app_tag_mask
[0] = 0x0;
834 pkt
->app_tag_mask
[1] = 0x0;
836 if (!qla2x00_hba_err_chk_enabled(sp
))
839 /* enable ALL bytes of the ref tag */
840 pkt
->ref_tag_mask
[0] = 0xff;
841 pkt
->ref_tag_mask
[1] = 0xff;
842 pkt
->ref_tag_mask
[2] = 0xff;
843 pkt
->ref_tag_mask
[3] = 0xff;
849 qla24xx_get_one_block_sg(uint32_t blk_sz
, struct qla2_sgx
*sgx
,
852 struct scatterlist
*sg
;
853 uint32_t cumulative_partial
, sg_len
;
854 dma_addr_t sg_dma_addr
;
856 if (sgx
->num_bytes
== sgx
->tot_bytes
)
860 cumulative_partial
= sgx
->tot_partial
;
862 sg_dma_addr
= sg_dma_address(sg
);
863 sg_len
= sg_dma_len(sg
);
865 sgx
->dma_addr
= sg_dma_addr
+ sgx
->bytes_consumed
;
867 if ((cumulative_partial
+ (sg_len
- sgx
->bytes_consumed
)) >= blk_sz
) {
868 sgx
->dma_len
= (blk_sz
- cumulative_partial
);
869 sgx
->tot_partial
= 0;
870 sgx
->num_bytes
+= blk_sz
;
873 sgx
->dma_len
= sg_len
- sgx
->bytes_consumed
;
874 sgx
->tot_partial
+= sgx
->dma_len
;
878 sgx
->bytes_consumed
+= sgx
->dma_len
;
880 if (sg_len
== sgx
->bytes_consumed
) {
884 sgx
->bytes_consumed
= 0;
891 qla24xx_walk_and_build_sglist_no_difb(struct qla_hw_data
*ha
, srb_t
*sp
,
892 uint32_t *dsd
, uint16_t tot_dsds
, struct qla_tc_param
*tc
)
895 uint8_t avail_dsds
= 0;
896 uint32_t dsd_list_len
;
897 struct dsd_dma
*dsd_ptr
;
898 struct scatterlist
*sg_prot
;
899 uint32_t *cur_dsd
= dsd
;
900 uint16_t used_dsds
= tot_dsds
;
901 uint32_t prot_int
; /* protection interval */
905 uint32_t sle_dma_len
, tot_prot_dma_len
= 0;
906 struct scsi_cmnd
*cmd
;
908 memset(&sgx
, 0, sizeof(struct qla2_sgx
));
910 cmd
= GET_CMD_SP(sp
);
911 prot_int
= cmd
->device
->sector_size
;
913 sgx
.tot_bytes
= scsi_bufflen(cmd
);
914 sgx
.cur_sg
= scsi_sglist(cmd
);
917 sg_prot
= scsi_prot_sglist(cmd
);
919 prot_int
= tc
->blk_sz
;
920 sgx
.tot_bytes
= tc
->bufflen
;
922 sg_prot
= tc
->prot_sg
;
928 while (qla24xx_get_one_block_sg(prot_int
, &sgx
, &partial
)) {
930 sle_dma
= sgx
.dma_addr
;
931 sle_dma_len
= sgx
.dma_len
;
933 /* Allocate additional continuation packets? */
934 if (avail_dsds
== 0) {
935 avail_dsds
= (used_dsds
> QLA_DSDS_PER_IOCB
) ?
936 QLA_DSDS_PER_IOCB
: used_dsds
;
937 dsd_list_len
= (avail_dsds
+ 1) * 12;
938 used_dsds
-= avail_dsds
;
940 /* allocate tracking DS */
941 dsd_ptr
= kzalloc(sizeof(struct dsd_dma
), GFP_ATOMIC
);
945 /* allocate new list */
946 dsd_ptr
->dsd_addr
= next_dsd
=
947 dma_pool_alloc(ha
->dl_dma_pool
, GFP_ATOMIC
,
948 &dsd_ptr
->dsd_list_dma
);
952 * Need to cleanup only this dsd_ptr, rest
953 * will be done by sp_free_dma()
960 list_add_tail(&dsd_ptr
->list
,
961 &((struct crc_context
*)
962 sp
->u
.scmd
.ctx
)->dsd_list
);
964 sp
->flags
|= SRB_CRC_CTX_DSD_VALID
;
966 list_add_tail(&dsd_ptr
->list
,
967 &(tc
->ctx
->dsd_list
));
968 *tc
->ctx_dsd_alloced
= 1;
972 /* add new list to cmd iocb or last list */
973 *cur_dsd
++ = cpu_to_le32(LSD(dsd_ptr
->dsd_list_dma
));
974 *cur_dsd
++ = cpu_to_le32(MSD(dsd_ptr
->dsd_list_dma
));
975 *cur_dsd
++ = dsd_list_len
;
976 cur_dsd
= (uint32_t *)next_dsd
;
978 *cur_dsd
++ = cpu_to_le32(LSD(sle_dma
));
979 *cur_dsd
++ = cpu_to_le32(MSD(sle_dma
));
980 *cur_dsd
++ = cpu_to_le32(sle_dma_len
);
984 /* Got a full protection interval */
985 sle_dma
= sg_dma_address(sg_prot
) + tot_prot_dma_len
;
988 tot_prot_dma_len
+= sle_dma_len
;
989 if (tot_prot_dma_len
== sg_dma_len(sg_prot
)) {
990 tot_prot_dma_len
= 0;
991 sg_prot
= sg_next(sg_prot
);
994 partial
= 1; /* So as to not re-enter this block */
998 /* Null termination */
1006 qla24xx_walk_and_build_sglist(struct qla_hw_data
*ha
, srb_t
*sp
, uint32_t *dsd
,
1007 uint16_t tot_dsds
, struct qla_tc_param
*tc
)
1010 uint8_t avail_dsds
= 0;
1011 uint32_t dsd_list_len
;
1012 struct dsd_dma
*dsd_ptr
;
1013 struct scatterlist
*sg
, *sgl
;
1014 uint32_t *cur_dsd
= dsd
;
1016 uint16_t used_dsds
= tot_dsds
;
1017 struct scsi_cmnd
*cmd
;
1020 cmd
= GET_CMD_SP(sp
);
1021 sgl
= scsi_sglist(cmd
);
1030 for_each_sg(sgl
, sg
, tot_dsds
, i
) {
1033 /* Allocate additional continuation packets? */
1034 if (avail_dsds
== 0) {
1035 avail_dsds
= (used_dsds
> QLA_DSDS_PER_IOCB
) ?
1036 QLA_DSDS_PER_IOCB
: used_dsds
;
1037 dsd_list_len
= (avail_dsds
+ 1) * 12;
1038 used_dsds
-= avail_dsds
;
1040 /* allocate tracking DS */
1041 dsd_ptr
= kzalloc(sizeof(struct dsd_dma
), GFP_ATOMIC
);
1045 /* allocate new list */
1046 dsd_ptr
->dsd_addr
= next_dsd
=
1047 dma_pool_alloc(ha
->dl_dma_pool
, GFP_ATOMIC
,
1048 &dsd_ptr
->dsd_list_dma
);
1052 * Need to cleanup only this dsd_ptr, rest
1053 * will be done by sp_free_dma()
1060 list_add_tail(&dsd_ptr
->list
,
1061 &((struct crc_context
*)
1062 sp
->u
.scmd
.ctx
)->dsd_list
);
1064 sp
->flags
|= SRB_CRC_CTX_DSD_VALID
;
1066 list_add_tail(&dsd_ptr
->list
,
1067 &(tc
->ctx
->dsd_list
));
1068 *tc
->ctx_dsd_alloced
= 1;
1071 /* add new list to cmd iocb or last list */
1072 *cur_dsd
++ = cpu_to_le32(LSD(dsd_ptr
->dsd_list_dma
));
1073 *cur_dsd
++ = cpu_to_le32(MSD(dsd_ptr
->dsd_list_dma
));
1074 *cur_dsd
++ = dsd_list_len
;
1075 cur_dsd
= (uint32_t *)next_dsd
;
1077 sle_dma
= sg_dma_address(sg
);
1079 *cur_dsd
++ = cpu_to_le32(LSD(sle_dma
));
1080 *cur_dsd
++ = cpu_to_le32(MSD(sle_dma
));
1081 *cur_dsd
++ = cpu_to_le32(sg_dma_len(sg
));
1085 /* Null termination */
1093 qla24xx_walk_and_build_prot_sglist(struct qla_hw_data
*ha
, srb_t
*sp
,
1094 uint32_t *dsd
, uint16_t tot_dsds
, struct qla_tc_param
*tc
)
1097 uint8_t avail_dsds
= 0;
1098 uint32_t dsd_list_len
;
1099 struct dsd_dma
*dsd_ptr
;
1100 struct scatterlist
*sg
, *sgl
;
1102 struct scsi_cmnd
*cmd
;
1103 uint32_t *cur_dsd
= dsd
;
1104 uint16_t used_dsds
= tot_dsds
;
1105 struct scsi_qla_host
*vha
;
1108 cmd
= GET_CMD_SP(sp
);
1109 sgl
= scsi_prot_sglist(cmd
);
1119 ql_dbg(ql_dbg_tgt
, vha
, 0xe021,
1120 "%s: enter\n", __func__
);
1122 for_each_sg(sgl
, sg
, tot_dsds
, i
) {
1125 /* Allocate additional continuation packets? */
1126 if (avail_dsds
== 0) {
1127 avail_dsds
= (used_dsds
> QLA_DSDS_PER_IOCB
) ?
1128 QLA_DSDS_PER_IOCB
: used_dsds
;
1129 dsd_list_len
= (avail_dsds
+ 1) * 12;
1130 used_dsds
-= avail_dsds
;
1132 /* allocate tracking DS */
1133 dsd_ptr
= kzalloc(sizeof(struct dsd_dma
), GFP_ATOMIC
);
1137 /* allocate new list */
1138 dsd_ptr
->dsd_addr
= next_dsd
=
1139 dma_pool_alloc(ha
->dl_dma_pool
, GFP_ATOMIC
,
1140 &dsd_ptr
->dsd_list_dma
);
1144 * Need to cleanup only this dsd_ptr, rest
1145 * will be done by sp_free_dma()
1152 list_add_tail(&dsd_ptr
->list
,
1153 &((struct crc_context
*)
1154 sp
->u
.scmd
.ctx
)->dsd_list
);
1156 sp
->flags
|= SRB_CRC_CTX_DSD_VALID
;
1158 list_add_tail(&dsd_ptr
->list
,
1159 &(tc
->ctx
->dsd_list
));
1160 *tc
->ctx_dsd_alloced
= 1;
1163 /* add new list to cmd iocb or last list */
1164 *cur_dsd
++ = cpu_to_le32(LSD(dsd_ptr
->dsd_list_dma
));
1165 *cur_dsd
++ = cpu_to_le32(MSD(dsd_ptr
->dsd_list_dma
));
1166 *cur_dsd
++ = dsd_list_len
;
1167 cur_dsd
= (uint32_t *)next_dsd
;
1169 sle_dma
= sg_dma_address(sg
);
1171 *cur_dsd
++ = cpu_to_le32(LSD(sle_dma
));
1172 *cur_dsd
++ = cpu_to_le32(MSD(sle_dma
));
1173 *cur_dsd
++ = cpu_to_le32(sg_dma_len(sg
));
1177 /* Null termination */
1185 * qla24xx_build_scsi_crc_2_iocbs() - Build IOCB command utilizing Command
1186 * Type 6 IOCB types.
1188 * @sp: SRB command to process
1189 * @cmd_pkt: Command type 3 IOCB
1190 * @tot_dsds: Total number of segments to transfer
1193 qla24xx_build_scsi_crc_2_iocbs(srb_t
*sp
, struct cmd_type_crc_2
*cmd_pkt
,
1194 uint16_t tot_dsds
, uint16_t tot_prot_dsds
, uint16_t fw_prot_opts
)
1196 uint32_t *cur_dsd
, *fcp_dl
;
1197 scsi_qla_host_t
*vha
;
1198 struct scsi_cmnd
*cmd
;
1199 uint32_t total_bytes
= 0;
1200 uint32_t data_bytes
;
1202 uint8_t bundling
= 1;
1205 struct crc_context
*crc_ctx_pkt
= NULL
;
1206 struct qla_hw_data
*ha
;
1207 uint8_t additional_fcpcdb_len
;
1208 uint16_t fcp_cmnd_len
;
1209 struct fcp_cmnd
*fcp_cmnd
;
1210 dma_addr_t crc_ctx_dma
;
1212 cmd
= GET_CMD_SP(sp
);
1214 /* Update entry type to indicate Command Type CRC_2 IOCB */
1215 *((uint32_t *)(&cmd_pkt
->entry_type
)) = cpu_to_le32(COMMAND_TYPE_CRC_2
);
1220 /* No data transfer */
1221 data_bytes
= scsi_bufflen(cmd
);
1222 if (!data_bytes
|| cmd
->sc_data_direction
== DMA_NONE
) {
1223 cmd_pkt
->byte_count
= cpu_to_le32(0);
1227 cmd_pkt
->vp_index
= sp
->vha
->vp_idx
;
1229 /* Set transfer direction */
1230 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
) {
1231 cmd_pkt
->control_flags
=
1232 cpu_to_le16(CF_WRITE_DATA
);
1233 } else if (cmd
->sc_data_direction
== DMA_FROM_DEVICE
) {
1234 cmd_pkt
->control_flags
=
1235 cpu_to_le16(CF_READ_DATA
);
1238 if ((scsi_get_prot_op(cmd
) == SCSI_PROT_READ_INSERT
) ||
1239 (scsi_get_prot_op(cmd
) == SCSI_PROT_WRITE_STRIP
) ||
1240 (scsi_get_prot_op(cmd
) == SCSI_PROT_READ_STRIP
) ||
1241 (scsi_get_prot_op(cmd
) == SCSI_PROT_WRITE_INSERT
))
1244 /* Allocate CRC context from global pool */
1245 crc_ctx_pkt
= sp
->u
.scmd
.ctx
=
1246 dma_pool_alloc(ha
->dl_dma_pool
, GFP_ATOMIC
, &crc_ctx_dma
);
1249 goto crc_queuing_error
;
1251 /* Zero out CTX area. */
1252 clr_ptr
= (uint8_t *)crc_ctx_pkt
;
1253 memset(clr_ptr
, 0, sizeof(*crc_ctx_pkt
));
1255 crc_ctx_pkt
->crc_ctx_dma
= crc_ctx_dma
;
1257 sp
->flags
|= SRB_CRC_CTX_DMA_VALID
;
1260 crc_ctx_pkt
->handle
= cmd_pkt
->handle
;
1262 INIT_LIST_HEAD(&crc_ctx_pkt
->dsd_list
);
1264 qla24xx_set_t10dif_tags(sp
, (struct fw_dif_context
*)
1265 &crc_ctx_pkt
->ref_tag
, tot_prot_dsds
);
1267 cmd_pkt
->crc_context_address
[0] = cpu_to_le32(LSD(crc_ctx_dma
));
1268 cmd_pkt
->crc_context_address
[1] = cpu_to_le32(MSD(crc_ctx_dma
));
1269 cmd_pkt
->crc_context_len
= CRC_CONTEXT_LEN_FW
;
1271 /* Determine SCSI command length -- align to 4 byte boundary */
1272 if (cmd
->cmd_len
> 16) {
1273 additional_fcpcdb_len
= cmd
->cmd_len
- 16;
1274 if ((cmd
->cmd_len
% 4) != 0) {
1275 /* SCSI cmd > 16 bytes must be multiple of 4 */
1276 goto crc_queuing_error
;
1278 fcp_cmnd_len
= 12 + cmd
->cmd_len
+ 4;
1280 additional_fcpcdb_len
= 0;
1281 fcp_cmnd_len
= 12 + 16 + 4;
1284 fcp_cmnd
= &crc_ctx_pkt
->fcp_cmnd
;
1286 fcp_cmnd
->additional_cdb_len
= additional_fcpcdb_len
;
1287 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
1288 fcp_cmnd
->additional_cdb_len
|= 1;
1289 else if (cmd
->sc_data_direction
== DMA_FROM_DEVICE
)
1290 fcp_cmnd
->additional_cdb_len
|= 2;
1292 int_to_scsilun(cmd
->device
->lun
, &fcp_cmnd
->lun
);
1293 memcpy(fcp_cmnd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1294 cmd_pkt
->fcp_cmnd_dseg_len
= cpu_to_le16(fcp_cmnd_len
);
1295 cmd_pkt
->fcp_cmnd_dseg_address
[0] = cpu_to_le32(
1296 LSD(crc_ctx_dma
+ CRC_CONTEXT_FCPCMND_OFF
));
1297 cmd_pkt
->fcp_cmnd_dseg_address
[1] = cpu_to_le32(
1298 MSD(crc_ctx_dma
+ CRC_CONTEXT_FCPCMND_OFF
));
1299 fcp_cmnd
->task_management
= 0;
1300 fcp_cmnd
->task_attribute
= TSK_SIMPLE
;
1302 cmd_pkt
->fcp_rsp_dseg_len
= 0; /* Let response come in status iocb */
1304 /* Compute dif len and adjust data len to incude protection */
1306 blk_size
= cmd
->device
->sector_size
;
1307 dif_bytes
= (data_bytes
/ blk_size
) * 8;
1309 switch (scsi_get_prot_op(GET_CMD_SP(sp
))) {
1310 case SCSI_PROT_READ_INSERT
:
1311 case SCSI_PROT_WRITE_STRIP
:
1312 total_bytes
= data_bytes
;
1313 data_bytes
+= dif_bytes
;
1316 case SCSI_PROT_READ_STRIP
:
1317 case SCSI_PROT_WRITE_INSERT
:
1318 case SCSI_PROT_READ_PASS
:
1319 case SCSI_PROT_WRITE_PASS
:
1320 total_bytes
= data_bytes
+ dif_bytes
;
1326 if (!qla2x00_hba_err_chk_enabled(sp
))
1327 fw_prot_opts
|= 0x10; /* Disable Guard tag checking */
1328 /* HBA error checking enabled */
1329 else if (IS_PI_UNINIT_CAPABLE(ha
)) {
1330 if ((scsi_get_prot_type(GET_CMD_SP(sp
)) == SCSI_PROT_DIF_TYPE1
)
1331 || (scsi_get_prot_type(GET_CMD_SP(sp
)) ==
1332 SCSI_PROT_DIF_TYPE2
))
1333 fw_prot_opts
|= BIT_10
;
1334 else if (scsi_get_prot_type(GET_CMD_SP(sp
)) ==
1335 SCSI_PROT_DIF_TYPE3
)
1336 fw_prot_opts
|= BIT_11
;
1340 cur_dsd
= (uint32_t *) &crc_ctx_pkt
->u
.nobundling
.data_address
;
1343 * Configure Bundling if we need to fetch interlaving
1344 * protection PCI accesses
1346 fw_prot_opts
|= PO_ENABLE_DIF_BUNDLING
;
1347 crc_ctx_pkt
->u
.bundling
.dif_byte_count
= cpu_to_le32(dif_bytes
);
1348 crc_ctx_pkt
->u
.bundling
.dseg_count
= cpu_to_le16(tot_dsds
-
1350 cur_dsd
= (uint32_t *) &crc_ctx_pkt
->u
.bundling
.data_address
;
1353 /* Finish the common fields of CRC pkt */
1354 crc_ctx_pkt
->blk_size
= cpu_to_le16(blk_size
);
1355 crc_ctx_pkt
->prot_opts
= cpu_to_le16(fw_prot_opts
);
1356 crc_ctx_pkt
->byte_count
= cpu_to_le32(data_bytes
);
1357 crc_ctx_pkt
->guard_seed
= cpu_to_le16(0);
1358 /* Fibre channel byte count */
1359 cmd_pkt
->byte_count
= cpu_to_le32(total_bytes
);
1360 fcp_dl
= (uint32_t *)(crc_ctx_pkt
->fcp_cmnd
.cdb
+ 16 +
1361 additional_fcpcdb_len
);
1362 *fcp_dl
= htonl(total_bytes
);
1364 if (!data_bytes
|| cmd
->sc_data_direction
== DMA_NONE
) {
1365 cmd_pkt
->byte_count
= cpu_to_le32(0);
1368 /* Walks data segments */
1370 cmd_pkt
->control_flags
|= cpu_to_le16(CF_DATA_SEG_DESCR_ENABLE
);
1372 if (!bundling
&& tot_prot_dsds
) {
1373 if (qla24xx_walk_and_build_sglist_no_difb(ha
, sp
,
1374 cur_dsd
, tot_dsds
, NULL
))
1375 goto crc_queuing_error
;
1376 } else if (qla24xx_walk_and_build_sglist(ha
, sp
, cur_dsd
,
1377 (tot_dsds
- tot_prot_dsds
), NULL
))
1378 goto crc_queuing_error
;
1380 if (bundling
&& tot_prot_dsds
) {
1381 /* Walks dif segments */
1382 cmd_pkt
->control_flags
|= cpu_to_le16(CF_DIF_SEG_DESCR_ENABLE
);
1383 cur_dsd
= (uint32_t *) &crc_ctx_pkt
->u
.bundling
.dif_address
;
1384 if (qla24xx_walk_and_build_prot_sglist(ha
, sp
, cur_dsd
,
1385 tot_prot_dsds
, NULL
))
1386 goto crc_queuing_error
;
1391 /* Cleanup will be performed by the caller */
1393 return QLA_FUNCTION_FAILED
;
1397 * qla24xx_start_scsi() - Send a SCSI command to the ISP
1398 * @sp: command to send to the ISP
1400 * Returns non-zero if a failure occurred, else zero.
1403 qla24xx_start_scsi(srb_t
*sp
)
1406 unsigned long flags
;
1410 struct cmd_type_7
*cmd_pkt
;
1414 struct req_que
*req
= NULL
;
1415 struct rsp_que
*rsp
= NULL
;
1416 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
1417 struct scsi_qla_host
*vha
= sp
->vha
;
1418 struct qla_hw_data
*ha
= vha
->hw
;
1420 /* Setup device pointers. */
1424 /* So we know we haven't pci_map'ed anything yet */
1427 /* Send marker if required */
1428 if (vha
->marker_needed
!= 0) {
1429 if (qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
) !=
1431 return QLA_FUNCTION_FAILED
;
1432 vha
->marker_needed
= 0;
1435 /* Acquire ring specific lock */
1436 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1438 /* Check for room in outstanding command list. */
1439 handle
= req
->current_outstanding_cmd
;
1440 for (index
= 1; index
< req
->num_outstanding_cmds
; index
++) {
1442 if (handle
== req
->num_outstanding_cmds
)
1444 if (!req
->outstanding_cmds
[handle
])
1447 if (index
== req
->num_outstanding_cmds
)
1450 /* Map the sg table so we have an accurate count of sg entries needed */
1451 if (scsi_sg_count(cmd
)) {
1452 nseg
= dma_map_sg(&ha
->pdev
->dev
, scsi_sglist(cmd
),
1453 scsi_sg_count(cmd
), cmd
->sc_data_direction
);
1454 if (unlikely(!nseg
))
1460 req_cnt
= qla24xx_calc_iocbs(vha
, tot_dsds
);
1461 if (req
->cnt
< (req_cnt
+ 2)) {
1462 cnt
= IS_SHADOW_REG_CAPABLE(ha
) ? *req
->out_ptr
:
1463 RD_REG_DWORD_RELAXED(req
->req_q_out
);
1464 if (req
->ring_index
< cnt
)
1465 req
->cnt
= cnt
- req
->ring_index
;
1467 req
->cnt
= req
->length
-
1468 (req
->ring_index
- cnt
);
1469 if (req
->cnt
< (req_cnt
+ 2))
1473 /* Build command packet. */
1474 req
->current_outstanding_cmd
= handle
;
1475 req
->outstanding_cmds
[handle
] = sp
;
1476 sp
->handle
= handle
;
1477 cmd
->host_scribble
= (unsigned char *)(unsigned long)handle
;
1478 req
->cnt
-= req_cnt
;
1480 cmd_pkt
= (struct cmd_type_7
*)req
->ring_ptr
;
1481 cmd_pkt
->handle
= MAKE_HANDLE(req
->id
, handle
);
1483 /* Zero out remaining portion of packet. */
1484 /* tagged queuing modifier -- default is TSK_SIMPLE (0). */
1485 clr_ptr
= (uint32_t *)cmd_pkt
+ 2;
1486 memset(clr_ptr
, 0, REQUEST_ENTRY_SIZE
- 8);
1487 cmd_pkt
->dseg_count
= cpu_to_le16(tot_dsds
);
1489 /* Set NPORT-ID and LUN number*/
1490 cmd_pkt
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
1491 cmd_pkt
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
1492 cmd_pkt
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
1493 cmd_pkt
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
1494 cmd_pkt
->vp_index
= sp
->vha
->vp_idx
;
1496 int_to_scsilun(cmd
->device
->lun
, &cmd_pkt
->lun
);
1497 host_to_fcp_swap((uint8_t *)&cmd_pkt
->lun
, sizeof(cmd_pkt
->lun
));
1499 cmd_pkt
->task
= TSK_SIMPLE
;
1501 /* Load SCSI command packet. */
1502 memcpy(cmd_pkt
->fcp_cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1503 host_to_fcp_swap(cmd_pkt
->fcp_cdb
, sizeof(cmd_pkt
->fcp_cdb
));
1505 cmd_pkt
->byte_count
= cpu_to_le32((uint32_t)scsi_bufflen(cmd
));
1507 /* Build IOCB segments */
1508 qla24xx_build_scsi_iocbs(sp
, cmd_pkt
, tot_dsds
, req
);
1510 /* Set total data segment count. */
1511 cmd_pkt
->entry_count
= (uint8_t)req_cnt
;
1513 /* Adjust ring index. */
1515 if (req
->ring_index
== req
->length
) {
1516 req
->ring_index
= 0;
1517 req
->ring_ptr
= req
->ring
;
1521 sp
->flags
|= SRB_DMA_VALID
;
1523 /* Set chip new ring index. */
1524 WRT_REG_DWORD(req
->req_q_in
, req
->ring_index
);
1525 RD_REG_DWORD_RELAXED(&ha
->iobase
->isp24
.hccr
);
1527 /* Manage unprocessed RIO/ZIO commands in response queue. */
1528 if (vha
->flags
.process_response_queue
&&
1529 rsp
->ring_ptr
->signature
!= RESPONSE_PROCESSED
)
1530 qla24xx_process_response_queue(vha
, rsp
);
1532 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1537 scsi_dma_unmap(cmd
);
1539 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1541 return QLA_FUNCTION_FAILED
;
1545 * qla24xx_dif_start_scsi() - Send a SCSI command to the ISP
1546 * @sp: command to send to the ISP
1548 * Returns non-zero if a failure occurred, else zero.
1551 qla24xx_dif_start_scsi(srb_t
*sp
)
1554 unsigned long flags
;
1559 uint16_t req_cnt
= 0;
1561 uint16_t tot_prot_dsds
;
1562 uint16_t fw_prot_opts
= 0;
1563 struct req_que
*req
= NULL
;
1564 struct rsp_que
*rsp
= NULL
;
1565 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
1566 struct scsi_qla_host
*vha
= sp
->vha
;
1567 struct qla_hw_data
*ha
= vha
->hw
;
1568 struct cmd_type_crc_2
*cmd_pkt
;
1569 uint32_t status
= 0;
1571 #define QDSS_GOT_Q_SPACE BIT_0
1573 /* Only process protection or >16 cdb in this routine */
1574 if (scsi_get_prot_op(cmd
) == SCSI_PROT_NORMAL
) {
1575 if (cmd
->cmd_len
<= 16)
1576 return qla24xx_start_scsi(sp
);
1579 /* Setup device pointers. */
1583 /* So we know we haven't pci_map'ed anything yet */
1586 /* Send marker if required */
1587 if (vha
->marker_needed
!= 0) {
1588 if (qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
) !=
1590 return QLA_FUNCTION_FAILED
;
1591 vha
->marker_needed
= 0;
1594 /* Acquire ring specific lock */
1595 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1597 /* Check for room in outstanding command list. */
1598 handle
= req
->current_outstanding_cmd
;
1599 for (index
= 1; index
< req
->num_outstanding_cmds
; index
++) {
1601 if (handle
== req
->num_outstanding_cmds
)
1603 if (!req
->outstanding_cmds
[handle
])
1607 if (index
== req
->num_outstanding_cmds
)
1610 /* Compute number of required data segments */
1611 /* Map the sg table so we have an accurate count of sg entries needed */
1612 if (scsi_sg_count(cmd
)) {
1613 nseg
= dma_map_sg(&ha
->pdev
->dev
, scsi_sglist(cmd
),
1614 scsi_sg_count(cmd
), cmd
->sc_data_direction
);
1615 if (unlikely(!nseg
))
1618 sp
->flags
|= SRB_DMA_VALID
;
1620 if ((scsi_get_prot_op(cmd
) == SCSI_PROT_READ_INSERT
) ||
1621 (scsi_get_prot_op(cmd
) == SCSI_PROT_WRITE_STRIP
)) {
1622 struct qla2_sgx sgx
;
1625 memset(&sgx
, 0, sizeof(struct qla2_sgx
));
1626 sgx
.tot_bytes
= scsi_bufflen(cmd
);
1627 sgx
.cur_sg
= scsi_sglist(cmd
);
1631 while (qla24xx_get_one_block_sg(
1632 cmd
->device
->sector_size
, &sgx
, &partial
))
1638 /* number of required data segments */
1641 /* Compute number of required protection segments */
1642 if (qla24xx_configure_prot_mode(sp
, &fw_prot_opts
)) {
1643 nseg
= dma_map_sg(&ha
->pdev
->dev
, scsi_prot_sglist(cmd
),
1644 scsi_prot_sg_count(cmd
), cmd
->sc_data_direction
);
1645 if (unlikely(!nseg
))
1648 sp
->flags
|= SRB_CRC_PROT_DMA_VALID
;
1650 if ((scsi_get_prot_op(cmd
) == SCSI_PROT_READ_INSERT
) ||
1651 (scsi_get_prot_op(cmd
) == SCSI_PROT_WRITE_STRIP
)) {
1652 nseg
= scsi_bufflen(cmd
) / cmd
->device
->sector_size
;
1659 /* Total Data and protection sg segment(s) */
1660 tot_prot_dsds
= nseg
;
1662 if (req
->cnt
< (req_cnt
+ 2)) {
1663 cnt
= IS_SHADOW_REG_CAPABLE(ha
) ? *req
->out_ptr
:
1664 RD_REG_DWORD_RELAXED(req
->req_q_out
);
1665 if (req
->ring_index
< cnt
)
1666 req
->cnt
= cnt
- req
->ring_index
;
1668 req
->cnt
= req
->length
-
1669 (req
->ring_index
- cnt
);
1670 if (req
->cnt
< (req_cnt
+ 2))
1674 status
|= QDSS_GOT_Q_SPACE
;
1676 /* Build header part of command packet (excluding the OPCODE). */
1677 req
->current_outstanding_cmd
= handle
;
1678 req
->outstanding_cmds
[handle
] = sp
;
1679 sp
->handle
= handle
;
1680 cmd
->host_scribble
= (unsigned char *)(unsigned long)handle
;
1681 req
->cnt
-= req_cnt
;
1683 /* Fill-in common area */
1684 cmd_pkt
= (struct cmd_type_crc_2
*)req
->ring_ptr
;
1685 cmd_pkt
->handle
= MAKE_HANDLE(req
->id
, handle
);
1687 clr_ptr
= (uint32_t *)cmd_pkt
+ 2;
1688 memset(clr_ptr
, 0, REQUEST_ENTRY_SIZE
- 8);
1690 /* Set NPORT-ID and LUN number*/
1691 cmd_pkt
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
1692 cmd_pkt
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
1693 cmd_pkt
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
1694 cmd_pkt
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
1696 int_to_scsilun(cmd
->device
->lun
, &cmd_pkt
->lun
);
1697 host_to_fcp_swap((uint8_t *)&cmd_pkt
->lun
, sizeof(cmd_pkt
->lun
));
1699 /* Total Data and protection segment(s) */
1700 cmd_pkt
->dseg_count
= cpu_to_le16(tot_dsds
);
1702 /* Build IOCB segments and adjust for data protection segments */
1703 if (qla24xx_build_scsi_crc_2_iocbs(sp
, (struct cmd_type_crc_2
*)
1704 req
->ring_ptr
, tot_dsds
, tot_prot_dsds
, fw_prot_opts
) !=
1708 cmd_pkt
->entry_count
= (uint8_t)req_cnt
;
1709 /* Specify response queue number where completion should happen */
1710 cmd_pkt
->entry_status
= (uint8_t) rsp
->id
;
1711 cmd_pkt
->timeout
= cpu_to_le16(0);
1714 /* Adjust ring index. */
1716 if (req
->ring_index
== req
->length
) {
1717 req
->ring_index
= 0;
1718 req
->ring_ptr
= req
->ring
;
1722 /* Set chip new ring index. */
1723 WRT_REG_DWORD(req
->req_q_in
, req
->ring_index
);
1724 RD_REG_DWORD_RELAXED(&ha
->iobase
->isp24
.hccr
);
1726 /* Manage unprocessed RIO/ZIO commands in response queue. */
1727 if (vha
->flags
.process_response_queue
&&
1728 rsp
->ring_ptr
->signature
!= RESPONSE_PROCESSED
)
1729 qla24xx_process_response_queue(vha
, rsp
);
1731 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1736 if (status
& QDSS_GOT_Q_SPACE
) {
1737 req
->outstanding_cmds
[handle
] = NULL
;
1738 req
->cnt
+= req_cnt
;
1740 /* Cleanup will be performed by the caller (queuecommand) */
1742 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1743 return QLA_FUNCTION_FAILED
;
1747 * qla2xxx_start_scsi_mq() - Send a SCSI command to the ISP
1748 * @sp: command to send to the ISP
1750 * Returns non-zero if a failure occurred, else zero.
1753 qla2xxx_start_scsi_mq(srb_t
*sp
)
1756 unsigned long flags
;
1760 struct cmd_type_7
*cmd_pkt
;
1764 struct req_que
*req
= NULL
;
1765 struct rsp_que
*rsp
= NULL
;
1766 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
1767 struct scsi_qla_host
*vha
= sp
->fcport
->vha
;
1768 struct qla_hw_data
*ha
= vha
->hw
;
1769 struct qla_qpair
*qpair
= sp
->qpair
;
1771 /* Setup qpair pointers */
1775 /* So we know we haven't pci_map'ed anything yet */
1778 /* Send marker if required */
1779 if (vha
->marker_needed
!= 0) {
1780 if (qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
) !=
1782 return QLA_FUNCTION_FAILED
;
1783 vha
->marker_needed
= 0;
1786 /* Acquire qpair specific lock */
1787 spin_lock_irqsave(&qpair
->qp_lock
, flags
);
1789 /* Check for room in outstanding command list. */
1790 handle
= req
->current_outstanding_cmd
;
1791 for (index
= 1; index
< req
->num_outstanding_cmds
; index
++) {
1793 if (handle
== req
->num_outstanding_cmds
)
1795 if (!req
->outstanding_cmds
[handle
])
1798 if (index
== req
->num_outstanding_cmds
)
1801 /* Map the sg table so we have an accurate count of sg entries needed */
1802 if (scsi_sg_count(cmd
)) {
1803 nseg
= dma_map_sg(&ha
->pdev
->dev
, scsi_sglist(cmd
),
1804 scsi_sg_count(cmd
), cmd
->sc_data_direction
);
1805 if (unlikely(!nseg
))
1811 req_cnt
= qla24xx_calc_iocbs(vha
, tot_dsds
);
1812 if (req
->cnt
< (req_cnt
+ 2)) {
1813 cnt
= IS_SHADOW_REG_CAPABLE(ha
) ? *req
->out_ptr
:
1814 RD_REG_DWORD_RELAXED(req
->req_q_out
);
1815 if (req
->ring_index
< cnt
)
1816 req
->cnt
= cnt
- req
->ring_index
;
1818 req
->cnt
= req
->length
-
1819 (req
->ring_index
- cnt
);
1820 if (req
->cnt
< (req_cnt
+ 2))
1824 /* Build command packet. */
1825 req
->current_outstanding_cmd
= handle
;
1826 req
->outstanding_cmds
[handle
] = sp
;
1827 sp
->handle
= handle
;
1828 cmd
->host_scribble
= (unsigned char *)(unsigned long)handle
;
1829 req
->cnt
-= req_cnt
;
1831 cmd_pkt
= (struct cmd_type_7
*)req
->ring_ptr
;
1832 cmd_pkt
->handle
= MAKE_HANDLE(req
->id
, handle
);
1834 /* Zero out remaining portion of packet. */
1835 /* tagged queuing modifier -- default is TSK_SIMPLE (0). */
1836 clr_ptr
= (uint32_t *)cmd_pkt
+ 2;
1837 memset(clr_ptr
, 0, REQUEST_ENTRY_SIZE
- 8);
1838 cmd_pkt
->dseg_count
= cpu_to_le16(tot_dsds
);
1840 /* Set NPORT-ID and LUN number*/
1841 cmd_pkt
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
1842 cmd_pkt
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
1843 cmd_pkt
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
1844 cmd_pkt
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
1845 cmd_pkt
->vp_index
= sp
->fcport
->vha
->vp_idx
;
1847 int_to_scsilun(cmd
->device
->lun
, &cmd_pkt
->lun
);
1848 host_to_fcp_swap((uint8_t *)&cmd_pkt
->lun
, sizeof(cmd_pkt
->lun
));
1850 cmd_pkt
->task
= TSK_SIMPLE
;
1852 /* Load SCSI command packet. */
1853 memcpy(cmd_pkt
->fcp_cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1854 host_to_fcp_swap(cmd_pkt
->fcp_cdb
, sizeof(cmd_pkt
->fcp_cdb
));
1856 cmd_pkt
->byte_count
= cpu_to_le32((uint32_t)scsi_bufflen(cmd
));
1858 /* Build IOCB segments */
1859 qla24xx_build_scsi_iocbs(sp
, cmd_pkt
, tot_dsds
, req
);
1861 /* Set total data segment count. */
1862 cmd_pkt
->entry_count
= (uint8_t)req_cnt
;
1864 /* Adjust ring index. */
1866 if (req
->ring_index
== req
->length
) {
1867 req
->ring_index
= 0;
1868 req
->ring_ptr
= req
->ring
;
1872 sp
->flags
|= SRB_DMA_VALID
;
1874 /* Set chip new ring index. */
1875 WRT_REG_DWORD(req
->req_q_in
, req
->ring_index
);
1877 /* Manage unprocessed RIO/ZIO commands in response queue. */
1878 if (vha
->flags
.process_response_queue
&&
1879 rsp
->ring_ptr
->signature
!= RESPONSE_PROCESSED
)
1880 qla24xx_process_response_queue(vha
, rsp
);
1882 spin_unlock_irqrestore(&qpair
->qp_lock
, flags
);
1887 scsi_dma_unmap(cmd
);
1889 spin_unlock_irqrestore(&qpair
->qp_lock
, flags
);
1891 return QLA_FUNCTION_FAILED
;
1896 * qla2xxx_dif_start_scsi_mq() - Send a SCSI command to the ISP
1897 * @sp: command to send to the ISP
1899 * Returns non-zero if a failure occurred, else zero.
1902 qla2xxx_dif_start_scsi_mq(srb_t
*sp
)
1905 unsigned long flags
;
1910 uint16_t req_cnt
= 0;
1912 uint16_t tot_prot_dsds
;
1913 uint16_t fw_prot_opts
= 0;
1914 struct req_que
*req
= NULL
;
1915 struct rsp_que
*rsp
= NULL
;
1916 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
1917 struct scsi_qla_host
*vha
= sp
->fcport
->vha
;
1918 struct qla_hw_data
*ha
= vha
->hw
;
1919 struct cmd_type_crc_2
*cmd_pkt
;
1920 uint32_t status
= 0;
1921 struct qla_qpair
*qpair
= sp
->qpair
;
1923 #define QDSS_GOT_Q_SPACE BIT_0
1925 /* Check for host side state */
1926 if (!qpair
->online
) {
1927 cmd
->result
= DID_NO_CONNECT
<< 16;
1928 return QLA_INTERFACE_ERROR
;
1931 if (!qpair
->difdix_supported
&&
1932 scsi_get_prot_op(cmd
) != SCSI_PROT_NORMAL
) {
1933 cmd
->result
= DID_NO_CONNECT
<< 16;
1934 return QLA_INTERFACE_ERROR
;
1937 /* Only process protection or >16 cdb in this routine */
1938 if (scsi_get_prot_op(cmd
) == SCSI_PROT_NORMAL
) {
1939 if (cmd
->cmd_len
<= 16)
1940 return qla2xxx_start_scsi_mq(sp
);
1943 /* Setup qpair pointers */
1947 /* So we know we haven't pci_map'ed anything yet */
1950 /* Send marker if required */
1951 if (vha
->marker_needed
!= 0) {
1952 if (qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
) !=
1954 return QLA_FUNCTION_FAILED
;
1955 vha
->marker_needed
= 0;
1958 /* Acquire ring specific lock */
1959 spin_lock_irqsave(&qpair
->qp_lock
, flags
);
1961 /* Check for room in outstanding command list. */
1962 handle
= req
->current_outstanding_cmd
;
1963 for (index
= 1; index
< req
->num_outstanding_cmds
; index
++) {
1965 if (handle
== req
->num_outstanding_cmds
)
1967 if (!req
->outstanding_cmds
[handle
])
1971 if (index
== req
->num_outstanding_cmds
)
1974 /* Compute number of required data segments */
1975 /* Map the sg table so we have an accurate count of sg entries needed */
1976 if (scsi_sg_count(cmd
)) {
1977 nseg
= dma_map_sg(&ha
->pdev
->dev
, scsi_sglist(cmd
),
1978 scsi_sg_count(cmd
), cmd
->sc_data_direction
);
1979 if (unlikely(!nseg
))
1982 sp
->flags
|= SRB_DMA_VALID
;
1984 if ((scsi_get_prot_op(cmd
) == SCSI_PROT_READ_INSERT
) ||
1985 (scsi_get_prot_op(cmd
) == SCSI_PROT_WRITE_STRIP
)) {
1986 struct qla2_sgx sgx
;
1989 memset(&sgx
, 0, sizeof(struct qla2_sgx
));
1990 sgx
.tot_bytes
= scsi_bufflen(cmd
);
1991 sgx
.cur_sg
= scsi_sglist(cmd
);
1995 while (qla24xx_get_one_block_sg(
1996 cmd
->device
->sector_size
, &sgx
, &partial
))
2002 /* number of required data segments */
2005 /* Compute number of required protection segments */
2006 if (qla24xx_configure_prot_mode(sp
, &fw_prot_opts
)) {
2007 nseg
= dma_map_sg(&ha
->pdev
->dev
, scsi_prot_sglist(cmd
),
2008 scsi_prot_sg_count(cmd
), cmd
->sc_data_direction
);
2009 if (unlikely(!nseg
))
2012 sp
->flags
|= SRB_CRC_PROT_DMA_VALID
;
2014 if ((scsi_get_prot_op(cmd
) == SCSI_PROT_READ_INSERT
) ||
2015 (scsi_get_prot_op(cmd
) == SCSI_PROT_WRITE_STRIP
)) {
2016 nseg
= scsi_bufflen(cmd
) / cmd
->device
->sector_size
;
2023 /* Total Data and protection sg segment(s) */
2024 tot_prot_dsds
= nseg
;
2026 if (req
->cnt
< (req_cnt
+ 2)) {
2027 cnt
= IS_SHADOW_REG_CAPABLE(ha
) ? *req
->out_ptr
:
2028 RD_REG_DWORD_RELAXED(req
->req_q_out
);
2029 if (req
->ring_index
< cnt
)
2030 req
->cnt
= cnt
- req
->ring_index
;
2032 req
->cnt
= req
->length
-
2033 (req
->ring_index
- cnt
);
2034 if (req
->cnt
< (req_cnt
+ 2))
2038 status
|= QDSS_GOT_Q_SPACE
;
2040 /* Build header part of command packet (excluding the OPCODE). */
2041 req
->current_outstanding_cmd
= handle
;
2042 req
->outstanding_cmds
[handle
] = sp
;
2043 sp
->handle
= handle
;
2044 cmd
->host_scribble
= (unsigned char *)(unsigned long)handle
;
2045 req
->cnt
-= req_cnt
;
2047 /* Fill-in common area */
2048 cmd_pkt
= (struct cmd_type_crc_2
*)req
->ring_ptr
;
2049 cmd_pkt
->handle
= MAKE_HANDLE(req
->id
, handle
);
2051 clr_ptr
= (uint32_t *)cmd_pkt
+ 2;
2052 memset(clr_ptr
, 0, REQUEST_ENTRY_SIZE
- 8);
2054 /* Set NPORT-ID and LUN number*/
2055 cmd_pkt
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
2056 cmd_pkt
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
2057 cmd_pkt
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
2058 cmd_pkt
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
2060 int_to_scsilun(cmd
->device
->lun
, &cmd_pkt
->lun
);
2061 host_to_fcp_swap((uint8_t *)&cmd_pkt
->lun
, sizeof(cmd_pkt
->lun
));
2063 /* Total Data and protection segment(s) */
2064 cmd_pkt
->dseg_count
= cpu_to_le16(tot_dsds
);
2066 /* Build IOCB segments and adjust for data protection segments */
2067 if (qla24xx_build_scsi_crc_2_iocbs(sp
, (struct cmd_type_crc_2
*)
2068 req
->ring_ptr
, tot_dsds
, tot_prot_dsds
, fw_prot_opts
) !=
2072 cmd_pkt
->entry_count
= (uint8_t)req_cnt
;
2073 cmd_pkt
->timeout
= cpu_to_le16(0);
2076 /* Adjust ring index. */
2078 if (req
->ring_index
== req
->length
) {
2079 req
->ring_index
= 0;
2080 req
->ring_ptr
= req
->ring
;
2084 /* Set chip new ring index. */
2085 WRT_REG_DWORD(req
->req_q_in
, req
->ring_index
);
2087 /* Manage unprocessed RIO/ZIO commands in response queue. */
2088 if (vha
->flags
.process_response_queue
&&
2089 rsp
->ring_ptr
->signature
!= RESPONSE_PROCESSED
)
2090 qla24xx_process_response_queue(vha
, rsp
);
2092 spin_unlock_irqrestore(&qpair
->qp_lock
, flags
);
2097 if (status
& QDSS_GOT_Q_SPACE
) {
2098 req
->outstanding_cmds
[handle
] = NULL
;
2099 req
->cnt
+= req_cnt
;
2101 /* Cleanup will be performed by the caller (queuecommand) */
2103 spin_unlock_irqrestore(&qpair
->qp_lock
, flags
);
2104 return QLA_FUNCTION_FAILED
;
2107 /* Generic Control-SRB manipulation functions. */
2109 /* hardware_lock assumed to be held. */
2111 qla2x00_alloc_iocbs_ready(scsi_qla_host_t
*vha
, srb_t
*sp
)
2113 if (qla2x00_reset_active(vha
))
2116 return qla2x00_alloc_iocbs(vha
, sp
);
2120 qla2x00_alloc_iocbs(scsi_qla_host_t
*vha
, srb_t
*sp
)
2122 struct qla_hw_data
*ha
= vha
->hw
;
2123 struct req_que
*req
= ha
->req_q_map
[0];
2124 device_reg_t
*reg
= ISP_QUE_REG(ha
, req
->id
);
2125 uint32_t index
, handle
;
2127 uint16_t cnt
, req_cnt
;
2134 goto skip_cmd_array
;
2136 /* Check for room in outstanding command list. */
2137 handle
= req
->current_outstanding_cmd
;
2138 for (index
= 1; index
< req
->num_outstanding_cmds
; index
++) {
2140 if (handle
== req
->num_outstanding_cmds
)
2142 if (!req
->outstanding_cmds
[handle
])
2145 if (index
== req
->num_outstanding_cmds
) {
2146 ql_log(ql_log_warn
, vha
, 0x700b,
2147 "No room on outstanding cmd array.\n");
2151 /* Prep command array. */
2152 req
->current_outstanding_cmd
= handle
;
2153 req
->outstanding_cmds
[handle
] = sp
;
2154 sp
->handle
= handle
;
2156 /* Adjust entry-counts as needed. */
2157 if (sp
->type
!= SRB_SCSI_CMD
)
2158 req_cnt
= sp
->iocbs
;
2161 /* Check for room on request queue. */
2162 if (req
->cnt
< req_cnt
+ 2) {
2163 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
))
2164 cnt
= RD_REG_DWORD(®
->isp25mq
.req_q_out
);
2165 else if (IS_P3P_TYPE(ha
))
2166 cnt
= RD_REG_DWORD(®
->isp82
.req_q_out
);
2167 else if (IS_FWI2_CAPABLE(ha
))
2168 cnt
= RD_REG_DWORD(®
->isp24
.req_q_out
);
2169 else if (IS_QLAFX00(ha
))
2170 cnt
= RD_REG_DWORD(®
->ispfx00
.req_q_out
);
2172 cnt
= qla2x00_debounce_register(
2173 ISP_REQ_Q_OUT(ha
, ®
->isp
));
2175 if (req
->ring_index
< cnt
)
2176 req
->cnt
= cnt
- req
->ring_index
;
2178 req
->cnt
= req
->length
-
2179 (req
->ring_index
- cnt
);
2181 if (req
->cnt
< req_cnt
+ 2)
2185 req
->cnt
-= req_cnt
;
2186 pkt
= req
->ring_ptr
;
2187 memset(pkt
, 0, REQUEST_ENTRY_SIZE
);
2188 if (IS_QLAFX00(ha
)) {
2189 WRT_REG_BYTE((void __iomem
*)&pkt
->entry_count
, req_cnt
);
2190 WRT_REG_WORD((void __iomem
*)&pkt
->handle
, handle
);
2192 pkt
->entry_count
= req_cnt
;
2193 pkt
->handle
= handle
;
2197 vha
->tgt_counters
.num_alloc_iocb_failed
++;
2202 qla24xx_login_iocb(srb_t
*sp
, struct logio_entry_24xx
*logio
)
2204 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
2206 logio
->entry_type
= LOGINOUT_PORT_IOCB_TYPE
;
2207 logio
->control_flags
= cpu_to_le16(LCF_COMMAND_PLOGI
);
2208 if (lio
->u
.logio
.flags
& SRB_LOGIN_COND_PLOGI
)
2209 logio
->control_flags
|= cpu_to_le16(LCF_COND_PLOGI
);
2210 if (lio
->u
.logio
.flags
& SRB_LOGIN_SKIP_PRLI
)
2211 logio
->control_flags
|= cpu_to_le16(LCF_SKIP_PRLI
);
2212 logio
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
2213 logio
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
2214 logio
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
2215 logio
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
2216 logio
->vp_index
= sp
->vha
->vp_idx
;
2220 qla2x00_login_iocb(srb_t
*sp
, struct mbx_entry
*mbx
)
2222 struct qla_hw_data
*ha
= sp
->vha
->hw
;
2223 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
2226 mbx
->entry_type
= MBX_IOCB_TYPE
;
2227 SET_TARGET_ID(ha
, mbx
->loop_id
, sp
->fcport
->loop_id
);
2228 mbx
->mb0
= cpu_to_le16(MBC_LOGIN_FABRIC_PORT
);
2229 opts
= lio
->u
.logio
.flags
& SRB_LOGIN_COND_PLOGI
? BIT_0
: 0;
2230 opts
|= lio
->u
.logio
.flags
& SRB_LOGIN_SKIP_PRLI
? BIT_1
: 0;
2231 if (HAS_EXTENDED_IDS(ha
)) {
2232 mbx
->mb1
= cpu_to_le16(sp
->fcport
->loop_id
);
2233 mbx
->mb10
= cpu_to_le16(opts
);
2235 mbx
->mb1
= cpu_to_le16((sp
->fcport
->loop_id
<< 8) | opts
);
2237 mbx
->mb2
= cpu_to_le16(sp
->fcport
->d_id
.b
.domain
);
2238 mbx
->mb3
= cpu_to_le16(sp
->fcport
->d_id
.b
.area
<< 8 |
2239 sp
->fcport
->d_id
.b
.al_pa
);
2240 mbx
->mb9
= cpu_to_le16(sp
->vha
->vp_idx
);
2244 qla24xx_logout_iocb(srb_t
*sp
, struct logio_entry_24xx
*logio
)
2246 logio
->entry_type
= LOGINOUT_PORT_IOCB_TYPE
;
2247 logio
->control_flags
=
2248 cpu_to_le16(LCF_COMMAND_LOGO
|LCF_IMPL_LOGO
);
2249 if (!sp
->fcport
->se_sess
||
2250 !sp
->fcport
->keep_nport_handle
)
2251 logio
->control_flags
|= cpu_to_le16(LCF_FREE_NPORT
);
2252 logio
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
2253 logio
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
2254 logio
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
2255 logio
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
2256 logio
->vp_index
= sp
->vha
->vp_idx
;
2260 qla2x00_logout_iocb(srb_t
*sp
, struct mbx_entry
*mbx
)
2262 struct qla_hw_data
*ha
= sp
->vha
->hw
;
2264 mbx
->entry_type
= MBX_IOCB_TYPE
;
2265 SET_TARGET_ID(ha
, mbx
->loop_id
, sp
->fcport
->loop_id
);
2266 mbx
->mb0
= cpu_to_le16(MBC_LOGOUT_FABRIC_PORT
);
2267 mbx
->mb1
= HAS_EXTENDED_IDS(ha
) ?
2268 cpu_to_le16(sp
->fcport
->loop_id
):
2269 cpu_to_le16(sp
->fcport
->loop_id
<< 8);
2270 mbx
->mb2
= cpu_to_le16(sp
->fcport
->d_id
.b
.domain
);
2271 mbx
->mb3
= cpu_to_le16(sp
->fcport
->d_id
.b
.area
<< 8 |
2272 sp
->fcport
->d_id
.b
.al_pa
);
2273 mbx
->mb9
= cpu_to_le16(sp
->vha
->vp_idx
);
2274 /* Implicit: mbx->mbx10 = 0. */
2278 qla24xx_adisc_iocb(srb_t
*sp
, struct logio_entry_24xx
*logio
)
2280 logio
->entry_type
= LOGINOUT_PORT_IOCB_TYPE
;
2281 logio
->control_flags
= cpu_to_le16(LCF_COMMAND_ADISC
);
2282 logio
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
2283 logio
->vp_index
= sp
->vha
->vp_idx
;
2287 qla2x00_adisc_iocb(srb_t
*sp
, struct mbx_entry
*mbx
)
2289 struct qla_hw_data
*ha
= sp
->vha
->hw
;
2291 mbx
->entry_type
= MBX_IOCB_TYPE
;
2292 SET_TARGET_ID(ha
, mbx
->loop_id
, sp
->fcport
->loop_id
);
2293 mbx
->mb0
= cpu_to_le16(MBC_GET_PORT_DATABASE
);
2294 if (HAS_EXTENDED_IDS(ha
)) {
2295 mbx
->mb1
= cpu_to_le16(sp
->fcport
->loop_id
);
2296 mbx
->mb10
= cpu_to_le16(BIT_0
);
2298 mbx
->mb1
= cpu_to_le16((sp
->fcport
->loop_id
<< 8) | BIT_0
);
2300 mbx
->mb2
= cpu_to_le16(MSW(ha
->async_pd_dma
));
2301 mbx
->mb3
= cpu_to_le16(LSW(ha
->async_pd_dma
));
2302 mbx
->mb6
= cpu_to_le16(MSW(MSD(ha
->async_pd_dma
)));
2303 mbx
->mb7
= cpu_to_le16(LSW(MSD(ha
->async_pd_dma
)));
2304 mbx
->mb9
= cpu_to_le16(sp
->vha
->vp_idx
);
2308 qla24xx_tm_iocb(srb_t
*sp
, struct tsk_mgmt_entry
*tsk
)
2312 struct fc_port
*fcport
= sp
->fcport
;
2313 scsi_qla_host_t
*vha
= fcport
->vha
;
2314 struct qla_hw_data
*ha
= vha
->hw
;
2315 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
2316 struct req_que
*req
= vha
->req
;
2318 flags
= iocb
->u
.tmf
.flags
;
2319 lun
= iocb
->u
.tmf
.lun
;
2321 tsk
->entry_type
= TSK_MGMT_IOCB_TYPE
;
2322 tsk
->entry_count
= 1;
2323 tsk
->handle
= MAKE_HANDLE(req
->id
, tsk
->handle
);
2324 tsk
->nport_handle
= cpu_to_le16(fcport
->loop_id
);
2325 tsk
->timeout
= cpu_to_le16(ha
->r_a_tov
/ 10 * 2);
2326 tsk
->control_flags
= cpu_to_le32(flags
);
2327 tsk
->port_id
[0] = fcport
->d_id
.b
.al_pa
;
2328 tsk
->port_id
[1] = fcport
->d_id
.b
.area
;
2329 tsk
->port_id
[2] = fcport
->d_id
.b
.domain
;
2330 tsk
->vp_index
= fcport
->vha
->vp_idx
;
2332 if (flags
== TCF_LUN_RESET
) {
2333 int_to_scsilun(lun
, &tsk
->lun
);
2334 host_to_fcp_swap((uint8_t *)&tsk
->lun
,
2340 qla2x00_els_dcmd_sp_free(void *data
)
2343 struct srb_iocb
*elsio
= &sp
->u
.iocb_cmd
;
2347 if (elsio
->u
.els_logo
.els_logo_pyld
)
2348 dma_free_coherent(&sp
->vha
->hw
->pdev
->dev
, DMA_POOL_SIZE
,
2349 elsio
->u
.els_logo
.els_logo_pyld
,
2350 elsio
->u
.els_logo
.els_logo_pyld_dma
);
2352 del_timer(&elsio
->timer
);
2357 qla2x00_els_dcmd_iocb_timeout(void *data
)
2360 fc_port_t
*fcport
= sp
->fcport
;
2361 struct scsi_qla_host
*vha
= sp
->vha
;
2362 struct qla_hw_data
*ha
= vha
->hw
;
2363 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
2364 unsigned long flags
= 0;
2366 ql_dbg(ql_dbg_io
, vha
, 0x3069,
2367 "%s Timeout, hdl=%x, portid=%02x%02x%02x\n",
2368 sp
->name
, sp
->handle
, fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2369 fcport
->d_id
.b
.al_pa
);
2371 /* Abort the exchange */
2372 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2373 if (ha
->isp_ops
->abort_command(sp
)) {
2374 ql_dbg(ql_dbg_io
, vha
, 0x3070,
2375 "mbx abort_command failed.\n");
2377 ql_dbg(ql_dbg_io
, vha
, 0x3071,
2378 "mbx abort_command success.\n");
2380 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2382 complete(&lio
->u
.els_logo
.comp
);
2386 qla2x00_els_dcmd_sp_done(void *ptr
, int res
)
2389 fc_port_t
*fcport
= sp
->fcport
;
2390 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
2391 struct scsi_qla_host
*vha
= sp
->vha
;
2393 ql_dbg(ql_dbg_io
, vha
, 0x3072,
2394 "%s hdl=%x, portid=%02x%02x%02x done\n",
2395 sp
->name
, sp
->handle
, fcport
->d_id
.b
.domain
,
2396 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
2398 complete(&lio
->u
.els_logo
.comp
);
2402 qla24xx_els_dcmd_iocb(scsi_qla_host_t
*vha
, int els_opcode
,
2403 port_id_t remote_did
)
2406 fc_port_t
*fcport
= NULL
;
2407 struct srb_iocb
*elsio
= NULL
;
2408 struct qla_hw_data
*ha
= vha
->hw
;
2409 struct els_logo_payload logo_pyld
;
2410 int rval
= QLA_SUCCESS
;
2412 fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2414 ql_log(ql_log_info
, vha
, 0x70e5, "fcport allocation failed\n");
2418 /* Alloc SRB structure */
2419 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
2422 ql_log(ql_log_info
, vha
, 0x70e6,
2423 "SRB allocation failed\n");
2427 elsio
= &sp
->u
.iocb_cmd
;
2428 fcport
->loop_id
= 0xFFFF;
2429 fcport
->d_id
.b
.domain
= remote_did
.b
.domain
;
2430 fcport
->d_id
.b
.area
= remote_did
.b
.area
;
2431 fcport
->d_id
.b
.al_pa
= remote_did
.b
.al_pa
;
2433 ql_dbg(ql_dbg_io
, vha
, 0x3073, "portid=%02x%02x%02x done\n",
2434 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
2436 sp
->type
= SRB_ELS_DCMD
;
2437 sp
->name
= "ELS_DCMD";
2438 sp
->fcport
= fcport
;
2439 qla2x00_init_timer(sp
, ELS_DCMD_TIMEOUT
);
2440 elsio
->timeout
= qla2x00_els_dcmd_iocb_timeout
;
2441 sp
->done
= qla2x00_els_dcmd_sp_done
;
2442 sp
->free
= qla2x00_els_dcmd_sp_free
;
2444 elsio
->u
.els_logo
.els_logo_pyld
= dma_alloc_coherent(&ha
->pdev
->dev
,
2445 DMA_POOL_SIZE
, &elsio
->u
.els_logo
.els_logo_pyld_dma
,
2448 if (!elsio
->u
.els_logo
.els_logo_pyld
) {
2450 return QLA_FUNCTION_FAILED
;
2453 memset(&logo_pyld
, 0, sizeof(struct els_logo_payload
));
2455 elsio
->u
.els_logo
.els_cmd
= els_opcode
;
2456 logo_pyld
.opcode
= els_opcode
;
2457 logo_pyld
.s_id
[0] = vha
->d_id
.b
.al_pa
;
2458 logo_pyld
.s_id
[1] = vha
->d_id
.b
.area
;
2459 logo_pyld
.s_id
[2] = vha
->d_id
.b
.domain
;
2460 host_to_fcp_swap(logo_pyld
.s_id
, sizeof(uint32_t));
2461 memcpy(&logo_pyld
.wwpn
, vha
->port_name
, WWN_SIZE
);
2463 memcpy(elsio
->u
.els_logo
.els_logo_pyld
, &logo_pyld
,
2464 sizeof(struct els_logo_payload
));
2466 rval
= qla2x00_start_sp(sp
);
2467 if (rval
!= QLA_SUCCESS
) {
2469 return QLA_FUNCTION_FAILED
;
2472 ql_dbg(ql_dbg_io
, vha
, 0x3074,
2473 "%s LOGO sent, hdl=%x, loopid=%x, portid=%02x%02x%02x.\n",
2474 sp
->name
, sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2475 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
2477 wait_for_completion(&elsio
->u
.els_logo
.comp
);
2484 qla24xx_els_logo_iocb(srb_t
*sp
, struct els_entry_24xx
*els_iocb
)
2486 scsi_qla_host_t
*vha
= sp
->vha
;
2487 struct srb_iocb
*elsio
= &sp
->u
.iocb_cmd
;
2489 els_iocb
->entry_type
= ELS_IOCB_TYPE
;
2490 els_iocb
->entry_count
= 1;
2491 els_iocb
->sys_define
= 0;
2492 els_iocb
->entry_status
= 0;
2493 els_iocb
->handle
= sp
->handle
;
2494 els_iocb
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
2495 els_iocb
->tx_dsd_count
= 1;
2496 els_iocb
->vp_index
= vha
->vp_idx
;
2497 els_iocb
->sof_type
= EST_SOFI3
;
2498 els_iocb
->rx_dsd_count
= 0;
2499 els_iocb
->opcode
= elsio
->u
.els_logo
.els_cmd
;
2501 els_iocb
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
2502 els_iocb
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
2503 els_iocb
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
2504 els_iocb
->control_flags
= 0;
2506 els_iocb
->tx_byte_count
= sizeof(struct els_logo_payload
);
2507 els_iocb
->tx_address
[0] =
2508 cpu_to_le32(LSD(elsio
->u
.els_logo
.els_logo_pyld_dma
));
2509 els_iocb
->tx_address
[1] =
2510 cpu_to_le32(MSD(elsio
->u
.els_logo
.els_logo_pyld_dma
));
2511 els_iocb
->tx_len
= cpu_to_le32(sizeof(struct els_logo_payload
));
2513 els_iocb
->rx_byte_count
= 0;
2514 els_iocb
->rx_address
[0] = 0;
2515 els_iocb
->rx_address
[1] = 0;
2516 els_iocb
->rx_len
= 0;
2518 sp
->vha
->qla_stats
.control_requests
++;
2522 qla24xx_els_iocb(srb_t
*sp
, struct els_entry_24xx
*els_iocb
)
2524 struct bsg_job
*bsg_job
= sp
->u
.bsg_job
;
2525 struct fc_bsg_request
*bsg_request
= bsg_job
->request
;
2527 els_iocb
->entry_type
= ELS_IOCB_TYPE
;
2528 els_iocb
->entry_count
= 1;
2529 els_iocb
->sys_define
= 0;
2530 els_iocb
->entry_status
= 0;
2531 els_iocb
->handle
= sp
->handle
;
2532 els_iocb
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
2533 els_iocb
->tx_dsd_count
= cpu_to_le16(bsg_job
->request_payload
.sg_cnt
);
2534 els_iocb
->vp_index
= sp
->vha
->vp_idx
;
2535 els_iocb
->sof_type
= EST_SOFI3
;
2536 els_iocb
->rx_dsd_count
= cpu_to_le16(bsg_job
->reply_payload
.sg_cnt
);
2539 sp
->type
== SRB_ELS_CMD_RPT
?
2540 bsg_request
->rqst_data
.r_els
.els_code
:
2541 bsg_request
->rqst_data
.h_els
.command_code
;
2542 els_iocb
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
2543 els_iocb
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
2544 els_iocb
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
2545 els_iocb
->control_flags
= 0;
2546 els_iocb
->rx_byte_count
=
2547 cpu_to_le32(bsg_job
->reply_payload
.payload_len
);
2548 els_iocb
->tx_byte_count
=
2549 cpu_to_le32(bsg_job
->request_payload
.payload_len
);
2551 els_iocb
->tx_address
[0] = cpu_to_le32(LSD(sg_dma_address
2552 (bsg_job
->request_payload
.sg_list
)));
2553 els_iocb
->tx_address
[1] = cpu_to_le32(MSD(sg_dma_address
2554 (bsg_job
->request_payload
.sg_list
)));
2555 els_iocb
->tx_len
= cpu_to_le32(sg_dma_len
2556 (bsg_job
->request_payload
.sg_list
));
2558 els_iocb
->rx_address
[0] = cpu_to_le32(LSD(sg_dma_address
2559 (bsg_job
->reply_payload
.sg_list
)));
2560 els_iocb
->rx_address
[1] = cpu_to_le32(MSD(sg_dma_address
2561 (bsg_job
->reply_payload
.sg_list
)));
2562 els_iocb
->rx_len
= cpu_to_le32(sg_dma_len
2563 (bsg_job
->reply_payload
.sg_list
));
2565 sp
->vha
->qla_stats
.control_requests
++;
2569 qla2x00_ct_iocb(srb_t
*sp
, ms_iocb_entry_t
*ct_iocb
)
2571 uint16_t avail_dsds
;
2573 struct scatterlist
*sg
;
2576 scsi_qla_host_t
*vha
= sp
->vha
;
2577 struct qla_hw_data
*ha
= vha
->hw
;
2578 struct bsg_job
*bsg_job
= sp
->u
.bsg_job
;
2579 int loop_iterartion
= 0;
2580 int entry_count
= 1;
2582 memset(ct_iocb
, 0, sizeof(ms_iocb_entry_t
));
2583 ct_iocb
->entry_type
= CT_IOCB_TYPE
;
2584 ct_iocb
->entry_status
= 0;
2585 ct_iocb
->handle1
= sp
->handle
;
2586 SET_TARGET_ID(ha
, ct_iocb
->loop_id
, sp
->fcport
->loop_id
);
2587 ct_iocb
->status
= cpu_to_le16(0);
2588 ct_iocb
->control_flags
= cpu_to_le16(0);
2589 ct_iocb
->timeout
= 0;
2590 ct_iocb
->cmd_dsd_count
=
2591 cpu_to_le16(bsg_job
->request_payload
.sg_cnt
);
2592 ct_iocb
->total_dsd_count
=
2593 cpu_to_le16(bsg_job
->request_payload
.sg_cnt
+ 1);
2594 ct_iocb
->req_bytecount
=
2595 cpu_to_le32(bsg_job
->request_payload
.payload_len
);
2596 ct_iocb
->rsp_bytecount
=
2597 cpu_to_le32(bsg_job
->reply_payload
.payload_len
);
2599 ct_iocb
->dseg_req_address
[0] = cpu_to_le32(LSD(sg_dma_address
2600 (bsg_job
->request_payload
.sg_list
)));
2601 ct_iocb
->dseg_req_address
[1] = cpu_to_le32(MSD(sg_dma_address
2602 (bsg_job
->request_payload
.sg_list
)));
2603 ct_iocb
->dseg_req_length
= ct_iocb
->req_bytecount
;
2605 ct_iocb
->dseg_rsp_address
[0] = cpu_to_le32(LSD(sg_dma_address
2606 (bsg_job
->reply_payload
.sg_list
)));
2607 ct_iocb
->dseg_rsp_address
[1] = cpu_to_le32(MSD(sg_dma_address
2608 (bsg_job
->reply_payload
.sg_list
)));
2609 ct_iocb
->dseg_rsp_length
= ct_iocb
->rsp_bytecount
;
2612 cur_dsd
= (uint32_t *)ct_iocb
->dseg_rsp_address
;
2614 tot_dsds
= bsg_job
->reply_payload
.sg_cnt
;
2616 for_each_sg(bsg_job
->reply_payload
.sg_list
, sg
, tot_dsds
, index
) {
2618 cont_a64_entry_t
*cont_pkt
;
2620 /* Allocate additional continuation packets? */
2621 if (avail_dsds
== 0) {
2623 * Five DSDs are available in the Cont.
2626 cont_pkt
= qla2x00_prep_cont_type1_iocb(vha
,
2627 vha
->hw
->req_q_map
[0]);
2628 cur_dsd
= (uint32_t *) cont_pkt
->dseg_0_address
;
2633 sle_dma
= sg_dma_address(sg
);
2634 *cur_dsd
++ = cpu_to_le32(LSD(sle_dma
));
2635 *cur_dsd
++ = cpu_to_le32(MSD(sle_dma
));
2636 *cur_dsd
++ = cpu_to_le32(sg_dma_len(sg
));
2640 ct_iocb
->entry_count
= entry_count
;
2642 sp
->vha
->qla_stats
.control_requests
++;
2646 qla24xx_ct_iocb(srb_t
*sp
, struct ct_entry_24xx
*ct_iocb
)
2648 uint16_t avail_dsds
;
2650 struct scatterlist
*sg
;
2653 scsi_qla_host_t
*vha
= sp
->vha
;
2654 struct qla_hw_data
*ha
= vha
->hw
;
2655 struct bsg_job
*bsg_job
= sp
->u
.bsg_job
;
2656 int loop_iterartion
= 0;
2657 int entry_count
= 1;
2659 ct_iocb
->entry_type
= CT_IOCB_TYPE
;
2660 ct_iocb
->entry_status
= 0;
2661 ct_iocb
->sys_define
= 0;
2662 ct_iocb
->handle
= sp
->handle
;
2664 ct_iocb
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
2665 ct_iocb
->vp_index
= sp
->vha
->vp_idx
;
2666 ct_iocb
->comp_status
= cpu_to_le16(0);
2668 ct_iocb
->cmd_dsd_count
=
2669 cpu_to_le16(bsg_job
->request_payload
.sg_cnt
);
2670 ct_iocb
->timeout
= 0;
2671 ct_iocb
->rsp_dsd_count
=
2672 cpu_to_le16(bsg_job
->reply_payload
.sg_cnt
);
2673 ct_iocb
->rsp_byte_count
=
2674 cpu_to_le32(bsg_job
->reply_payload
.payload_len
);
2675 ct_iocb
->cmd_byte_count
=
2676 cpu_to_le32(bsg_job
->request_payload
.payload_len
);
2677 ct_iocb
->dseg_0_address
[0] = cpu_to_le32(LSD(sg_dma_address
2678 (bsg_job
->request_payload
.sg_list
)));
2679 ct_iocb
->dseg_0_address
[1] = cpu_to_le32(MSD(sg_dma_address
2680 (bsg_job
->request_payload
.sg_list
)));
2681 ct_iocb
->dseg_0_len
= cpu_to_le32(sg_dma_len
2682 (bsg_job
->request_payload
.sg_list
));
2685 cur_dsd
= (uint32_t *)ct_iocb
->dseg_1_address
;
2687 tot_dsds
= bsg_job
->reply_payload
.sg_cnt
;
2689 for_each_sg(bsg_job
->reply_payload
.sg_list
, sg
, tot_dsds
, index
) {
2691 cont_a64_entry_t
*cont_pkt
;
2693 /* Allocate additional continuation packets? */
2694 if (avail_dsds
== 0) {
2696 * Five DSDs are available in the Cont.
2699 cont_pkt
= qla2x00_prep_cont_type1_iocb(vha
,
2701 cur_dsd
= (uint32_t *) cont_pkt
->dseg_0_address
;
2706 sle_dma
= sg_dma_address(sg
);
2707 *cur_dsd
++ = cpu_to_le32(LSD(sle_dma
));
2708 *cur_dsd
++ = cpu_to_le32(MSD(sle_dma
));
2709 *cur_dsd
++ = cpu_to_le32(sg_dma_len(sg
));
2713 ct_iocb
->entry_count
= entry_count
;
2717 * qla82xx_start_scsi() - Send a SCSI command to the ISP
2718 * @sp: command to send to the ISP
2720 * Returns non-zero if a failure occurred, else zero.
2723 qla82xx_start_scsi(srb_t
*sp
)
2726 unsigned long flags
;
2727 struct scsi_cmnd
*cmd
;
2734 struct device_reg_82xx __iomem
*reg
;
2737 uint8_t additional_cdb_len
;
2738 struct ct6_dsd
*ctx
;
2739 struct scsi_qla_host
*vha
= sp
->vha
;
2740 struct qla_hw_data
*ha
= vha
->hw
;
2741 struct req_que
*req
= NULL
;
2742 struct rsp_que
*rsp
= NULL
;
2744 /* Setup device pointers. */
2745 reg
= &ha
->iobase
->isp82
;
2746 cmd
= GET_CMD_SP(sp
);
2748 rsp
= ha
->rsp_q_map
[0];
2750 /* So we know we haven't pci_map'ed anything yet */
2753 dbval
= 0x04 | (ha
->portnum
<< 5);
2755 /* Send marker if required */
2756 if (vha
->marker_needed
!= 0) {
2757 if (qla2x00_marker(vha
, req
,
2758 rsp
, 0, 0, MK_SYNC_ALL
) != QLA_SUCCESS
) {
2759 ql_log(ql_log_warn
, vha
, 0x300c,
2760 "qla2x00_marker failed for cmd=%p.\n", cmd
);
2761 return QLA_FUNCTION_FAILED
;
2763 vha
->marker_needed
= 0;
2766 /* Acquire ring specific lock */
2767 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2769 /* Check for room in outstanding command list. */
2770 handle
= req
->current_outstanding_cmd
;
2771 for (index
= 1; index
< req
->num_outstanding_cmds
; index
++) {
2773 if (handle
== req
->num_outstanding_cmds
)
2775 if (!req
->outstanding_cmds
[handle
])
2778 if (index
== req
->num_outstanding_cmds
)
2781 /* Map the sg table so we have an accurate count of sg entries needed */
2782 if (scsi_sg_count(cmd
)) {
2783 nseg
= dma_map_sg(&ha
->pdev
->dev
, scsi_sglist(cmd
),
2784 scsi_sg_count(cmd
), cmd
->sc_data_direction
);
2785 if (unlikely(!nseg
))
2792 if (tot_dsds
> ql2xshiftctondsd
) {
2793 struct cmd_type_6
*cmd_pkt
;
2794 uint16_t more_dsd_lists
= 0;
2795 struct dsd_dma
*dsd_ptr
;
2798 more_dsd_lists
= qla24xx_calc_dsd_lists(tot_dsds
);
2799 if ((more_dsd_lists
+ ha
->gbl_dsd_inuse
) >= NUM_DSD_CHAIN
) {
2800 ql_dbg(ql_dbg_io
, vha
, 0x300d,
2801 "Num of DSD list %d is than %d for cmd=%p.\n",
2802 more_dsd_lists
+ ha
->gbl_dsd_inuse
, NUM_DSD_CHAIN
,
2807 if (more_dsd_lists
<= ha
->gbl_dsd_avail
)
2808 goto sufficient_dsds
;
2810 more_dsd_lists
-= ha
->gbl_dsd_avail
;
2812 for (i
= 0; i
< more_dsd_lists
; i
++) {
2813 dsd_ptr
= kzalloc(sizeof(struct dsd_dma
), GFP_ATOMIC
);
2815 ql_log(ql_log_fatal
, vha
, 0x300e,
2816 "Failed to allocate memory for dsd_dma "
2817 "for cmd=%p.\n", cmd
);
2821 dsd_ptr
->dsd_addr
= dma_pool_alloc(ha
->dl_dma_pool
,
2822 GFP_ATOMIC
, &dsd_ptr
->dsd_list_dma
);
2823 if (!dsd_ptr
->dsd_addr
) {
2825 ql_log(ql_log_fatal
, vha
, 0x300f,
2826 "Failed to allocate memory for dsd_addr "
2827 "for cmd=%p.\n", cmd
);
2830 list_add_tail(&dsd_ptr
->list
, &ha
->gbl_dsd_list
);
2831 ha
->gbl_dsd_avail
++;
2837 if (req
->cnt
< (req_cnt
+ 2)) {
2838 cnt
= (uint16_t)RD_REG_DWORD_RELAXED(
2839 ®
->req_q_out
[0]);
2840 if (req
->ring_index
< cnt
)
2841 req
->cnt
= cnt
- req
->ring_index
;
2843 req
->cnt
= req
->length
-
2844 (req
->ring_index
- cnt
);
2845 if (req
->cnt
< (req_cnt
+ 2))
2849 ctx
= sp
->u
.scmd
.ctx
=
2850 mempool_alloc(ha
->ctx_mempool
, GFP_ATOMIC
);
2852 ql_log(ql_log_fatal
, vha
, 0x3010,
2853 "Failed to allocate ctx for cmd=%p.\n", cmd
);
2857 memset(ctx
, 0, sizeof(struct ct6_dsd
));
2858 ctx
->fcp_cmnd
= dma_pool_alloc(ha
->fcp_cmnd_dma_pool
,
2859 GFP_ATOMIC
, &ctx
->fcp_cmnd_dma
);
2860 if (!ctx
->fcp_cmnd
) {
2861 ql_log(ql_log_fatal
, vha
, 0x3011,
2862 "Failed to allocate fcp_cmnd for cmd=%p.\n", cmd
);
2866 /* Initialize the DSD list and dma handle */
2867 INIT_LIST_HEAD(&ctx
->dsd_list
);
2868 ctx
->dsd_use_cnt
= 0;
2870 if (cmd
->cmd_len
> 16) {
2871 additional_cdb_len
= cmd
->cmd_len
- 16;
2872 if ((cmd
->cmd_len
% 4) != 0) {
2873 /* SCSI command bigger than 16 bytes must be
2876 ql_log(ql_log_warn
, vha
, 0x3012,
2877 "scsi cmd len %d not multiple of 4 "
2878 "for cmd=%p.\n", cmd
->cmd_len
, cmd
);
2879 goto queuing_error_fcp_cmnd
;
2881 ctx
->fcp_cmnd_len
= 12 + cmd
->cmd_len
+ 4;
2883 additional_cdb_len
= 0;
2884 ctx
->fcp_cmnd_len
= 12 + 16 + 4;
2887 cmd_pkt
= (struct cmd_type_6
*)req
->ring_ptr
;
2888 cmd_pkt
->handle
= MAKE_HANDLE(req
->id
, handle
);
2890 /* Zero out remaining portion of packet. */
2891 /* tagged queuing modifier -- default is TSK_SIMPLE (0). */
2892 clr_ptr
= (uint32_t *)cmd_pkt
+ 2;
2893 memset(clr_ptr
, 0, REQUEST_ENTRY_SIZE
- 8);
2894 cmd_pkt
->dseg_count
= cpu_to_le16(tot_dsds
);
2896 /* Set NPORT-ID and LUN number*/
2897 cmd_pkt
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
2898 cmd_pkt
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
2899 cmd_pkt
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
2900 cmd_pkt
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
2901 cmd_pkt
->vp_index
= sp
->vha
->vp_idx
;
2903 /* Build IOCB segments */
2904 if (qla24xx_build_scsi_type_6_iocbs(sp
, cmd_pkt
, tot_dsds
))
2905 goto queuing_error_fcp_cmnd
;
2907 int_to_scsilun(cmd
->device
->lun
, &cmd_pkt
->lun
);
2908 host_to_fcp_swap((uint8_t *)&cmd_pkt
->lun
, sizeof(cmd_pkt
->lun
));
2910 /* build FCP_CMND IU */
2911 memset(ctx
->fcp_cmnd
, 0, sizeof(struct fcp_cmnd
));
2912 int_to_scsilun(cmd
->device
->lun
, &ctx
->fcp_cmnd
->lun
);
2913 ctx
->fcp_cmnd
->additional_cdb_len
= additional_cdb_len
;
2915 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
2916 ctx
->fcp_cmnd
->additional_cdb_len
|= 1;
2917 else if (cmd
->sc_data_direction
== DMA_FROM_DEVICE
)
2918 ctx
->fcp_cmnd
->additional_cdb_len
|= 2;
2920 /* Populate the FCP_PRIO. */
2921 if (ha
->flags
.fcp_prio_enabled
)
2922 ctx
->fcp_cmnd
->task_attribute
|=
2923 sp
->fcport
->fcp_prio
<< 3;
2925 memcpy(ctx
->fcp_cmnd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
2927 fcp_dl
= (uint32_t *)(ctx
->fcp_cmnd
->cdb
+ 16 +
2928 additional_cdb_len
);
2929 *fcp_dl
= htonl((uint32_t)scsi_bufflen(cmd
));
2931 cmd_pkt
->fcp_cmnd_dseg_len
= cpu_to_le16(ctx
->fcp_cmnd_len
);
2932 cmd_pkt
->fcp_cmnd_dseg_address
[0] =
2933 cpu_to_le32(LSD(ctx
->fcp_cmnd_dma
));
2934 cmd_pkt
->fcp_cmnd_dseg_address
[1] =
2935 cpu_to_le32(MSD(ctx
->fcp_cmnd_dma
));
2937 sp
->flags
|= SRB_FCP_CMND_DMA_VALID
;
2938 cmd_pkt
->byte_count
= cpu_to_le32((uint32_t)scsi_bufflen(cmd
));
2939 /* Set total data segment count. */
2940 cmd_pkt
->entry_count
= (uint8_t)req_cnt
;
2941 /* Specify response queue number where
2942 * completion should happen
2944 cmd_pkt
->entry_status
= (uint8_t) rsp
->id
;
2946 struct cmd_type_7
*cmd_pkt
;
2947 req_cnt
= qla24xx_calc_iocbs(vha
, tot_dsds
);
2948 if (req
->cnt
< (req_cnt
+ 2)) {
2949 cnt
= (uint16_t)RD_REG_DWORD_RELAXED(
2950 ®
->req_q_out
[0]);
2951 if (req
->ring_index
< cnt
)
2952 req
->cnt
= cnt
- req
->ring_index
;
2954 req
->cnt
= req
->length
-
2955 (req
->ring_index
- cnt
);
2957 if (req
->cnt
< (req_cnt
+ 2))
2960 cmd_pkt
= (struct cmd_type_7
*)req
->ring_ptr
;
2961 cmd_pkt
->handle
= MAKE_HANDLE(req
->id
, handle
);
2963 /* Zero out remaining portion of packet. */
2964 /* tagged queuing modifier -- default is TSK_SIMPLE (0).*/
2965 clr_ptr
= (uint32_t *)cmd_pkt
+ 2;
2966 memset(clr_ptr
, 0, REQUEST_ENTRY_SIZE
- 8);
2967 cmd_pkt
->dseg_count
= cpu_to_le16(tot_dsds
);
2969 /* Set NPORT-ID and LUN number*/
2970 cmd_pkt
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
2971 cmd_pkt
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
2972 cmd_pkt
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
2973 cmd_pkt
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
2974 cmd_pkt
->vp_index
= sp
->vha
->vp_idx
;
2976 int_to_scsilun(cmd
->device
->lun
, &cmd_pkt
->lun
);
2977 host_to_fcp_swap((uint8_t *)&cmd_pkt
->lun
,
2978 sizeof(cmd_pkt
->lun
));
2980 /* Populate the FCP_PRIO. */
2981 if (ha
->flags
.fcp_prio_enabled
)
2982 cmd_pkt
->task
|= sp
->fcport
->fcp_prio
<< 3;
2984 /* Load SCSI command packet. */
2985 memcpy(cmd_pkt
->fcp_cdb
, cmd
->cmnd
, cmd
->cmd_len
);
2986 host_to_fcp_swap(cmd_pkt
->fcp_cdb
, sizeof(cmd_pkt
->fcp_cdb
));
2988 cmd_pkt
->byte_count
= cpu_to_le32((uint32_t)scsi_bufflen(cmd
));
2990 /* Build IOCB segments */
2991 qla24xx_build_scsi_iocbs(sp
, cmd_pkt
, tot_dsds
, req
);
2993 /* Set total data segment count. */
2994 cmd_pkt
->entry_count
= (uint8_t)req_cnt
;
2995 /* Specify response queue number where
2996 * completion should happen.
2998 cmd_pkt
->entry_status
= (uint8_t) rsp
->id
;
3001 /* Build command packet. */
3002 req
->current_outstanding_cmd
= handle
;
3003 req
->outstanding_cmds
[handle
] = sp
;
3004 sp
->handle
= handle
;
3005 cmd
->host_scribble
= (unsigned char *)(unsigned long)handle
;
3006 req
->cnt
-= req_cnt
;
3009 /* Adjust ring index. */
3011 if (req
->ring_index
== req
->length
) {
3012 req
->ring_index
= 0;
3013 req
->ring_ptr
= req
->ring
;
3017 sp
->flags
|= SRB_DMA_VALID
;
3019 /* Set chip new ring index. */
3020 /* write, read and verify logic */
3021 dbval
= dbval
| (req
->id
<< 8) | (req
->ring_index
<< 16);
3023 qla82xx_wr_32(ha
, (uintptr_t __force
)ha
->nxdb_wr_ptr
, dbval
);
3025 WRT_REG_DWORD(ha
->nxdb_wr_ptr
, dbval
);
3027 while (RD_REG_DWORD(ha
->nxdb_rd_ptr
) != dbval
) {
3028 WRT_REG_DWORD(ha
->nxdb_wr_ptr
, dbval
);
3033 /* Manage unprocessed RIO/ZIO commands in response queue. */
3034 if (vha
->flags
.process_response_queue
&&
3035 rsp
->ring_ptr
->signature
!= RESPONSE_PROCESSED
)
3036 qla24xx_process_response_queue(vha
, rsp
);
3038 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3041 queuing_error_fcp_cmnd
:
3042 dma_pool_free(ha
->fcp_cmnd_dma_pool
, ctx
->fcp_cmnd
, ctx
->fcp_cmnd_dma
);
3045 scsi_dma_unmap(cmd
);
3047 if (sp
->u
.scmd
.ctx
) {
3048 mempool_free(sp
->u
.scmd
.ctx
, ha
->ctx_mempool
);
3049 sp
->u
.scmd
.ctx
= NULL
;
3051 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3053 return QLA_FUNCTION_FAILED
;
3057 qla24xx_abort_iocb(srb_t
*sp
, struct abort_entry_24xx
*abt_iocb
)
3059 struct srb_iocb
*aio
= &sp
->u
.iocb_cmd
;
3060 scsi_qla_host_t
*vha
= sp
->vha
;
3061 struct req_que
*req
= vha
->req
;
3063 memset(abt_iocb
, 0, sizeof(struct abort_entry_24xx
));
3064 abt_iocb
->entry_type
= ABORT_IOCB_TYPE
;
3065 abt_iocb
->entry_count
= 1;
3066 abt_iocb
->handle
= cpu_to_le32(MAKE_HANDLE(req
->id
, sp
->handle
));
3067 abt_iocb
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
3068 abt_iocb
->handle_to_abort
=
3069 cpu_to_le32(MAKE_HANDLE(req
->id
, aio
->u
.abt
.cmd_hndl
));
3070 abt_iocb
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
3071 abt_iocb
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
3072 abt_iocb
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
3073 abt_iocb
->vp_index
= vha
->vp_idx
;
3074 abt_iocb
->req_que_no
= cpu_to_le16(req
->id
);
3075 /* Send the command to the firmware */
3080 qla2x00_mb_iocb(srb_t
*sp
, struct mbx_24xx_entry
*mbx
)
3084 mbx
->entry_type
= MBX_IOCB_TYPE
;
3085 mbx
->handle
= sp
->handle
;
3086 sz
= min(ARRAY_SIZE(mbx
->mb
), ARRAY_SIZE(sp
->u
.iocb_cmd
.u
.mbx
.out_mb
));
3088 for (i
= 0; i
< sz
; i
++)
3089 mbx
->mb
[i
] = cpu_to_le16(sp
->u
.iocb_cmd
.u
.mbx
.out_mb
[i
]);
3093 qla2x00_ctpthru_cmd_iocb(srb_t
*sp
, struct ct_entry_24xx
*ct_pkt
)
3095 sp
->u
.iocb_cmd
.u
.ctarg
.iocb
= ct_pkt
;
3096 qla24xx_prep_ms_iocb(sp
->vha
, &sp
->u
.iocb_cmd
.u
.ctarg
);
3097 ct_pkt
->handle
= sp
->handle
;
3100 static void qla2x00_send_notify_ack_iocb(srb_t
*sp
,
3101 struct nack_to_isp
*nack
)
3103 struct imm_ntfy_from_isp
*ntfy
= sp
->u
.iocb_cmd
.u
.nack
.ntfy
;
3105 nack
->entry_type
= NOTIFY_ACK_TYPE
;
3106 nack
->entry_count
= 1;
3107 nack
->ox_id
= ntfy
->ox_id
;
3109 nack
->u
.isp24
.handle
= sp
->handle
;
3110 nack
->u
.isp24
.nport_handle
= ntfy
->u
.isp24
.nport_handle
;
3111 if (le16_to_cpu(ntfy
->u
.isp24
.status
) == IMM_NTFY_ELS
) {
3112 nack
->u
.isp24
.flags
= ntfy
->u
.isp24
.flags
&
3113 cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB
);
3115 nack
->u
.isp24
.srr_rx_id
= ntfy
->u
.isp24
.srr_rx_id
;
3116 nack
->u
.isp24
.status
= ntfy
->u
.isp24
.status
;
3117 nack
->u
.isp24
.status_subcode
= ntfy
->u
.isp24
.status_subcode
;
3118 nack
->u
.isp24
.fw_handle
= ntfy
->u
.isp24
.fw_handle
;
3119 nack
->u
.isp24
.exchange_address
= ntfy
->u
.isp24
.exchange_address
;
3120 nack
->u
.isp24
.srr_rel_offs
= ntfy
->u
.isp24
.srr_rel_offs
;
3121 nack
->u
.isp24
.srr_ui
= ntfy
->u
.isp24
.srr_ui
;
3122 nack
->u
.isp24
.srr_flags
= 0;
3123 nack
->u
.isp24
.srr_reject_code
= 0;
3124 nack
->u
.isp24
.srr_reject_code_expl
= 0;
3125 nack
->u
.isp24
.vp_index
= ntfy
->u
.isp24
.vp_index
;
3129 qla2x00_start_sp(srb_t
*sp
)
3132 scsi_qla_host_t
*vha
= sp
->vha
;
3133 struct qla_hw_data
*ha
= vha
->hw
;
3135 unsigned long flags
;
3137 rval
= QLA_FUNCTION_FAILED
;
3138 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3139 pkt
= qla2x00_alloc_iocbs(vha
, sp
);
3141 ql_log(ql_log_warn
, vha
, 0x700c,
3142 "qla2x00_alloc_iocbs failed.\n");
3149 IS_FWI2_CAPABLE(ha
) ?
3150 qla24xx_login_iocb(sp
, pkt
) :
3151 qla2x00_login_iocb(sp
, pkt
);
3153 case SRB_LOGOUT_CMD
:
3154 IS_FWI2_CAPABLE(ha
) ?
3155 qla24xx_logout_iocb(sp
, pkt
) :
3156 qla2x00_logout_iocb(sp
, pkt
);
3158 case SRB_ELS_CMD_RPT
:
3159 case SRB_ELS_CMD_HST
:
3160 qla24xx_els_iocb(sp
, pkt
);
3163 IS_FWI2_CAPABLE(ha
) ?
3164 qla24xx_ct_iocb(sp
, pkt
) :
3165 qla2x00_ct_iocb(sp
, pkt
);
3168 IS_FWI2_CAPABLE(ha
) ?
3169 qla24xx_adisc_iocb(sp
, pkt
) :
3170 qla2x00_adisc_iocb(sp
, pkt
);
3174 qlafx00_tm_iocb(sp
, pkt
) :
3175 qla24xx_tm_iocb(sp
, pkt
);
3177 case SRB_FXIOCB_DCMD
:
3178 case SRB_FXIOCB_BCMD
:
3179 qlafx00_fxdisc_iocb(sp
, pkt
);
3183 qlafx00_abort_iocb(sp
, pkt
) :
3184 qla24xx_abort_iocb(sp
, pkt
);
3187 qla24xx_els_logo_iocb(sp
, pkt
);
3189 case SRB_CT_PTHRU_CMD
:
3190 qla2x00_ctpthru_cmd_iocb(sp
, pkt
);
3193 qla2x00_mb_iocb(sp
, pkt
);
3195 case SRB_NACK_PLOGI
:
3198 qla2x00_send_notify_ack_iocb(sp
, pkt
);
3205 qla2x00_start_iocbs(vha
, ha
->req_q_map
[0]);
3207 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3212 qla25xx_build_bidir_iocb(srb_t
*sp
, struct scsi_qla_host
*vha
,
3213 struct cmd_bidir
*cmd_pkt
, uint32_t tot_dsds
)
3215 uint16_t avail_dsds
;
3217 uint32_t req_data_len
= 0;
3218 uint32_t rsp_data_len
= 0;
3219 struct scatterlist
*sg
;
3221 int entry_count
= 1;
3222 struct bsg_job
*bsg_job
= sp
->u
.bsg_job
;
3224 /*Update entry type to indicate bidir command */
3225 *((uint32_t *)(&cmd_pkt
->entry_type
)) =
3226 cpu_to_le32(COMMAND_BIDIRECTIONAL
);
3228 /* Set the transfer direction, in this set both flags
3229 * Also set the BD_WRAP_BACK flag, firmware will take care
3230 * assigning DID=SID for outgoing pkts.
3232 cmd_pkt
->wr_dseg_count
= cpu_to_le16(bsg_job
->request_payload
.sg_cnt
);
3233 cmd_pkt
->rd_dseg_count
= cpu_to_le16(bsg_job
->reply_payload
.sg_cnt
);
3234 cmd_pkt
->control_flags
= cpu_to_le16(BD_WRITE_DATA
| BD_READ_DATA
|
3237 req_data_len
= rsp_data_len
= bsg_job
->request_payload
.payload_len
;
3238 cmd_pkt
->wr_byte_count
= cpu_to_le32(req_data_len
);
3239 cmd_pkt
->rd_byte_count
= cpu_to_le32(rsp_data_len
);
3240 cmd_pkt
->timeout
= cpu_to_le16(qla2x00_get_async_timeout(vha
) + 2);
3242 vha
->bidi_stats
.transfer_bytes
+= req_data_len
;
3243 vha
->bidi_stats
.io_count
++;
3245 vha
->qla_stats
.output_bytes
+= req_data_len
;
3246 vha
->qla_stats
.output_requests
++;
3248 /* Only one dsd is available for bidirectional IOCB, remaining dsds
3249 * are bundled in continuation iocb
3252 cur_dsd
= (uint32_t *)&cmd_pkt
->fcp_data_dseg_address
;
3256 for_each_sg(bsg_job
->request_payload
.sg_list
, sg
,
3257 bsg_job
->request_payload
.sg_cnt
, index
) {
3259 cont_a64_entry_t
*cont_pkt
;
3261 /* Allocate additional continuation packets */
3262 if (avail_dsds
== 0) {
3263 /* Continuation type 1 IOCB can accomodate
3266 cont_pkt
= qla2x00_prep_cont_type1_iocb(vha
, vha
->req
);
3267 cur_dsd
= (uint32_t *) cont_pkt
->dseg_0_address
;
3271 sle_dma
= sg_dma_address(sg
);
3272 *cur_dsd
++ = cpu_to_le32(LSD(sle_dma
));
3273 *cur_dsd
++ = cpu_to_le32(MSD(sle_dma
));
3274 *cur_dsd
++ = cpu_to_le32(sg_dma_len(sg
));
3277 /* For read request DSD will always goes to continuation IOCB
3278 * and follow the write DSD. If there is room on the current IOCB
3279 * then it is added to that IOCB else new continuation IOCB is
3282 for_each_sg(bsg_job
->reply_payload
.sg_list
, sg
,
3283 bsg_job
->reply_payload
.sg_cnt
, index
) {
3285 cont_a64_entry_t
*cont_pkt
;
3287 /* Allocate additional continuation packets */
3288 if (avail_dsds
== 0) {
3289 /* Continuation type 1 IOCB can accomodate
3292 cont_pkt
= qla2x00_prep_cont_type1_iocb(vha
, vha
->req
);
3293 cur_dsd
= (uint32_t *) cont_pkt
->dseg_0_address
;
3297 sle_dma
= sg_dma_address(sg
);
3298 *cur_dsd
++ = cpu_to_le32(LSD(sle_dma
));
3299 *cur_dsd
++ = cpu_to_le32(MSD(sle_dma
));
3300 *cur_dsd
++ = cpu_to_le32(sg_dma_len(sg
));
3303 /* This value should be same as number of IOCB required for this cmd */
3304 cmd_pkt
->entry_count
= entry_count
;
3308 qla2x00_start_bidir(srb_t
*sp
, struct scsi_qla_host
*vha
, uint32_t tot_dsds
)
3311 struct qla_hw_data
*ha
= vha
->hw
;
3312 unsigned long flags
;
3318 struct cmd_bidir
*cmd_pkt
= NULL
;
3319 struct rsp_que
*rsp
;
3320 struct req_que
*req
;
3321 int rval
= EXT_STATUS_OK
;
3325 rsp
= ha
->rsp_q_map
[0];
3328 /* Send marker if required */
3329 if (vha
->marker_needed
!= 0) {
3330 if (qla2x00_marker(vha
, req
,
3331 rsp
, 0, 0, MK_SYNC_ALL
) != QLA_SUCCESS
)
3332 return EXT_STATUS_MAILBOX
;
3333 vha
->marker_needed
= 0;
3336 /* Acquire ring specific lock */
3337 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3339 /* Check for room in outstanding command list. */
3340 handle
= req
->current_outstanding_cmd
;
3341 for (index
= 1; index
< req
->num_outstanding_cmds
; index
++) {
3343 if (handle
== req
->num_outstanding_cmds
)
3345 if (!req
->outstanding_cmds
[handle
])
3349 if (index
== req
->num_outstanding_cmds
) {
3350 rval
= EXT_STATUS_BUSY
;
3354 /* Calculate number of IOCB required */
3355 req_cnt
= qla24xx_calc_iocbs(vha
, tot_dsds
);
3357 /* Check for room on request queue. */
3358 if (req
->cnt
< req_cnt
+ 2) {
3359 cnt
= IS_SHADOW_REG_CAPABLE(ha
) ? *req
->out_ptr
:
3360 RD_REG_DWORD_RELAXED(req
->req_q_out
);
3361 if (req
->ring_index
< cnt
)
3362 req
->cnt
= cnt
- req
->ring_index
;
3364 req
->cnt
= req
->length
-
3365 (req
->ring_index
- cnt
);
3367 if (req
->cnt
< req_cnt
+ 2) {
3368 rval
= EXT_STATUS_BUSY
;
3372 cmd_pkt
= (struct cmd_bidir
*)req
->ring_ptr
;
3373 cmd_pkt
->handle
= MAKE_HANDLE(req
->id
, handle
);
3375 /* Zero out remaining portion of packet. */
3376 /* tagged queuing modifier -- default is TSK_SIMPLE (0).*/
3377 clr_ptr
= (uint32_t *)cmd_pkt
+ 2;
3378 memset(clr_ptr
, 0, REQUEST_ENTRY_SIZE
- 8);
3380 /* Set NPORT-ID (of vha)*/
3381 cmd_pkt
->nport_handle
= cpu_to_le16(vha
->self_login_loop_id
);
3382 cmd_pkt
->port_id
[0] = vha
->d_id
.b
.al_pa
;
3383 cmd_pkt
->port_id
[1] = vha
->d_id
.b
.area
;
3384 cmd_pkt
->port_id
[2] = vha
->d_id
.b
.domain
;
3386 qla25xx_build_bidir_iocb(sp
, vha
, cmd_pkt
, tot_dsds
);
3387 cmd_pkt
->entry_status
= (uint8_t) rsp
->id
;
3388 /* Build command packet. */
3389 req
->current_outstanding_cmd
= handle
;
3390 req
->outstanding_cmds
[handle
] = sp
;
3391 sp
->handle
= handle
;
3392 req
->cnt
-= req_cnt
;
3394 /* Send the command to the firmware */
3396 qla2x00_start_iocbs(vha
, req
);
3398 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);