2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/blkdev.h>
10 #include <linux/delay.h>
12 #include <scsi/scsi_tcq.h>
14 static void qla2x00_isp_cmd(struct scsi_qla_host *, struct req_que *);
16 static void qla25xx_set_que(srb_t *, struct rsp_que **);
18 * qla2x00_get_cmd_direction() - Determine control_flag data direction.
21 * Returns the proper CF_* direction based on CDB.
23 static inline uint16_t
24 qla2x00_get_cmd_direction(srb_t *sp)
30 /* Set transfer direction */
31 if (sp->cmd->sc_data_direction == DMA_TO_DEVICE) {
33 sp->fcport->vha->hw->qla_stats.output_bytes +=
34 scsi_bufflen(sp->cmd);
35 } else if (sp->cmd->sc_data_direction == DMA_FROM_DEVICE) {
37 sp->fcport->vha->hw->qla_stats.input_bytes +=
38 scsi_bufflen(sp->cmd);
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)) =
111 __constant_cpu_to_le32(CONTINUE_TYPE);
117 * qla2x00_prep_cont_type1_iocb() - Initialize a Continuation Type 1 IOCB.
120 * Returns a pointer to the continuation type 1 IOCB packet.
122 static inline cont_a64_entry_t *
123 qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *vha, struct req_que *req)
125 cont_a64_entry_t *cont_pkt;
127 /* Adjust ring index. */
129 if (req->ring_index == req->length) {
131 req->ring_ptr = req->ring;
136 cont_pkt = (cont_a64_entry_t *)req->ring_ptr;
138 /* Load packet defaults. */
139 *((uint32_t *)(&cont_pkt->entry_type)) =
140 __constant_cpu_to_le32(CONTINUE_A64_TYPE);
146 qla24xx_configure_prot_mode(srb_t *sp, uint16_t *fw_prot_opts)
148 uint8_t guard = scsi_host_get_guard(sp->cmd->device->host);
150 /* We only support T10 DIF right now */
151 if (guard != SHOST_DIX_GUARD_CRC) {
152 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3007,
153 "Unsupported guard: %d for cmd=%p.\n", guard, sp->cmd);
157 /* We always use DIFF Bundling for best performance */
160 /* Translate SCSI opcode to a protection opcode */
161 switch (scsi_get_prot_op(sp->cmd)) {
162 case SCSI_PROT_READ_STRIP:
163 *fw_prot_opts |= PO_MODE_DIF_REMOVE;
165 case SCSI_PROT_WRITE_INSERT:
166 *fw_prot_opts |= PO_MODE_DIF_INSERT;
168 case SCSI_PROT_READ_INSERT:
169 *fw_prot_opts |= PO_MODE_DIF_INSERT;
171 case SCSI_PROT_WRITE_STRIP:
172 *fw_prot_opts |= PO_MODE_DIF_REMOVE;
174 case SCSI_PROT_READ_PASS:
175 *fw_prot_opts |= PO_MODE_DIF_PASS;
177 case SCSI_PROT_WRITE_PASS:
178 *fw_prot_opts |= PO_MODE_DIF_PASS;
180 default: /* Normal Request */
181 *fw_prot_opts |= PO_MODE_DIF_PASS;
185 return scsi_prot_sg_count(sp->cmd);
189 * qla2x00_build_scsi_iocbs_32() - Build IOCB command utilizing 32bit
190 * capable IOCB types.
192 * @sp: SRB command to process
193 * @cmd_pkt: Command type 2 IOCB
194 * @tot_dsds: Total number of segments to transfer
196 void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt,
201 scsi_qla_host_t *vha;
202 struct scsi_cmnd *cmd;
203 struct scatterlist *sg;
208 /* Update entry type to indicate Command Type 2 IOCB */
209 *((uint32_t *)(&cmd_pkt->entry_type)) =
210 __constant_cpu_to_le32(COMMAND_TYPE);
212 /* No data transfer */
213 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
214 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
218 vha = sp->fcport->vha;
219 cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp));
221 /* Three DSDs are available in the Command Type 2 IOCB */
223 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
225 /* Load data segments */
226 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
227 cont_entry_t *cont_pkt;
229 /* Allocate additional continuation packets? */
230 if (avail_dsds == 0) {
232 * Seven DSDs are available in the Continuation
235 cont_pkt = qla2x00_prep_cont_type0_iocb(vha);
236 cur_dsd = (uint32_t *)&cont_pkt->dseg_0_address;
240 *cur_dsd++ = cpu_to_le32(sg_dma_address(sg));
241 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
247 * qla2x00_build_scsi_iocbs_64() - Build IOCB command utilizing 64bit
248 * capable IOCB types.
250 * @sp: SRB command to process
251 * @cmd_pkt: Command type 3 IOCB
252 * @tot_dsds: Total number of segments to transfer
254 void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt,
259 scsi_qla_host_t *vha;
260 struct scsi_cmnd *cmd;
261 struct scatterlist *sg;
266 /* Update entry type to indicate Command Type 3 IOCB */
267 *((uint32_t *)(&cmd_pkt->entry_type)) =
268 __constant_cpu_to_le32(COMMAND_A64_TYPE);
270 /* No data transfer */
271 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
272 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
276 vha = sp->fcport->vha;
277 cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp));
279 /* Two DSDs are available in the Command Type 3 IOCB */
281 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
283 /* Load data segments */
284 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
286 cont_a64_entry_t *cont_pkt;
288 /* Allocate additional continuation packets? */
289 if (avail_dsds == 0) {
291 * Five DSDs are available in the Continuation
294 cont_pkt = qla2x00_prep_cont_type1_iocb(vha, vha->req);
295 cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
299 sle_dma = sg_dma_address(sg);
300 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
301 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
302 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
308 * qla2x00_start_scsi() - Send a SCSI command to the ISP
309 * @sp: command to send to the ISP
311 * Returns non-zero if a failure occurred, else zero.
314 qla2x00_start_scsi(srb_t *sp)
318 scsi_qla_host_t *vha;
319 struct scsi_cmnd *cmd;
323 cmd_entry_t *cmd_pkt;
327 struct device_reg_2xxx __iomem *reg;
328 struct qla_hw_data *ha;
333 /* Setup device pointers. */
335 vha = sp->fcport->vha;
337 reg = &ha->iobase->isp;
339 req = ha->req_q_map[0];
340 rsp = ha->rsp_q_map[0];
341 /* So we know we haven't pci_map'ed anything yet */
344 /* Send marker if required */
345 if (vha->marker_needed != 0) {
346 if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
348 return (QLA_FUNCTION_FAILED);
350 vha->marker_needed = 0;
353 /* Acquire ring specific lock */
354 spin_lock_irqsave(&ha->hardware_lock, flags);
356 /* Check for room in outstanding command list. */
357 handle = req->current_outstanding_cmd;
358 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
360 if (handle == MAX_OUTSTANDING_COMMANDS)
362 if (!req->outstanding_cmds[handle])
365 if (index == MAX_OUTSTANDING_COMMANDS)
368 /* Map the sg table so we have an accurate count of sg entries needed */
369 if (scsi_sg_count(cmd)) {
370 nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
371 scsi_sg_count(cmd), cmd->sc_data_direction);
379 /* Calculate the number of request entries needed. */
380 req_cnt = ha->isp_ops->calc_req_entries(tot_dsds);
381 if (req->cnt < (req_cnt + 2)) {
382 cnt = RD_REG_WORD_RELAXED(ISP_REQ_Q_OUT(ha, reg));
383 if (req->ring_index < cnt)
384 req->cnt = cnt - req->ring_index;
386 req->cnt = req->length -
387 (req->ring_index - cnt);
389 if (req->cnt < (req_cnt + 2))
392 /* Build command packet */
393 req->current_outstanding_cmd = handle;
394 req->outstanding_cmds[handle] = sp;
396 sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle;
399 cmd_pkt = (cmd_entry_t *)req->ring_ptr;
400 cmd_pkt->handle = handle;
401 /* Zero out remaining portion of packet. */
402 clr_ptr = (uint32_t *)cmd_pkt + 2;
403 memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
404 cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
406 /* Set target ID and LUN number*/
407 SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id);
408 cmd_pkt->lun = cpu_to_le16(sp->cmd->device->lun);
410 /* Update tagged queuing modifier */
411 if (scsi_populate_tag_msg(cmd, tag)) {
413 case HEAD_OF_QUEUE_TAG:
414 cmd_pkt->control_flags =
415 __constant_cpu_to_le16(CF_HEAD_TAG);
417 case ORDERED_QUEUE_TAG:
418 cmd_pkt->control_flags =
419 __constant_cpu_to_le16(CF_ORDERED_TAG);
422 cmd_pkt->control_flags =
423 __constant_cpu_to_le16(CF_SIMPLE_TAG);
427 cmd_pkt->control_flags = __constant_cpu_to_le16(CF_SIMPLE_TAG);
430 /* Load SCSI command packet. */
431 memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len);
432 cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
434 /* Build IOCB segments */
435 ha->isp_ops->build_iocbs(sp, cmd_pkt, tot_dsds);
437 /* Set total data segment count. */
438 cmd_pkt->entry_count = (uint8_t)req_cnt;
441 /* Adjust ring index. */
443 if (req->ring_index == req->length) {
445 req->ring_ptr = req->ring;
449 sp->flags |= SRB_DMA_VALID;
451 /* Set chip new ring index. */
452 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), req->ring_index);
453 RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, reg)); /* PCI Posting. */
455 /* Manage unprocessed RIO/ZIO commands in response queue. */
456 if (vha->flags.process_response_queue &&
457 rsp->ring_ptr->signature != RESPONSE_PROCESSED)
458 qla2x00_process_response_queue(rsp);
460 spin_unlock_irqrestore(&ha->hardware_lock, flags);
461 return (QLA_SUCCESS);
467 spin_unlock_irqrestore(&ha->hardware_lock, flags);
469 return (QLA_FUNCTION_FAILED);
473 * qla2x00_marker() - Send a marker IOCB to the firmware.
477 * @type: marker modifier
479 * Can be called from both normal and interrupt context.
481 * Returns non-zero if a failure occurred, else zero.
484 __qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req,
485 struct rsp_que *rsp, uint16_t loop_id,
486 uint16_t lun, uint8_t type)
489 struct mrk_entry_24xx *mrk24;
490 struct qla_hw_data *ha = vha->hw;
491 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
494 mrk = (mrk_entry_t *)qla2x00_alloc_iocbs(vha, 0);
496 ql_log(ql_log_warn, base_vha, 0x3026,
497 "Failed to allocate Marker IOCB.\n");
499 return (QLA_FUNCTION_FAILED);
502 mrk->entry_type = MARKER_TYPE;
503 mrk->modifier = type;
504 if (type != MK_SYNC_ALL) {
505 if (IS_FWI2_CAPABLE(ha)) {
506 mrk24 = (struct mrk_entry_24xx *) mrk;
507 mrk24->nport_handle = cpu_to_le16(loop_id);
508 mrk24->lun[1] = LSB(lun);
509 mrk24->lun[2] = MSB(lun);
510 host_to_fcp_swap(mrk24->lun, sizeof(mrk24->lun));
511 mrk24->vp_index = vha->vp_idx;
512 mrk24->handle = MAKE_HANDLE(req->id, mrk24->handle);
514 SET_TARGET_ID(ha, mrk->target, loop_id);
515 mrk->lun = cpu_to_le16(lun);
520 qla2x00_isp_cmd(vha, req);
522 return (QLA_SUCCESS);
526 qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req,
527 struct rsp_que *rsp, uint16_t loop_id, uint16_t lun,
531 unsigned long flags = 0;
533 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
534 ret = __qla2x00_marker(vha, req, rsp, loop_id, lun, type);
535 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
541 * qla2x00_isp_cmd() - Modify the request ring pointer.
544 * Note: The caller must hold the hardware lock before calling this routine.
547 qla2x00_isp_cmd(struct scsi_qla_host *vha, struct req_que *req)
549 struct qla_hw_data *ha = vha->hw;
550 device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
551 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
553 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x302d,
555 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302e,
556 (uint8_t *)req->ring_ptr, REQUEST_ENTRY_SIZE);
558 /* Adjust ring index. */
560 if (req->ring_index == req->length) {
562 req->ring_ptr = req->ring;
566 /* Set chip new ring index. */
567 if (IS_QLA82XX(ha)) {
568 uint32_t dbval = 0x04 | (ha->portnum << 5);
570 /* write, read and verify logic */
571 dbval = dbval | (req->id << 8) | (req->ring_index << 16);
573 qla82xx_wr_32(ha, ha->nxdb_wr_ptr, dbval);
576 (unsigned long __iomem *)ha->nxdb_wr_ptr,
579 while (RD_REG_DWORD(ha->nxdb_rd_ptr) != dbval) {
580 WRT_REG_DWORD((unsigned long __iomem *)
581 ha->nxdb_wr_ptr, dbval);
585 } else if (ha->mqenable) {
586 /* Set chip new ring index. */
587 WRT_REG_DWORD(®->isp25mq.req_q_in, req->ring_index);
588 RD_REG_DWORD(&ioreg->hccr);
590 if (IS_FWI2_CAPABLE(ha)) {
591 WRT_REG_DWORD(®->isp24.req_q_in, req->ring_index);
592 RD_REG_DWORD_RELAXED(®->isp24.req_q_in);
594 WRT_REG_WORD(ISP_REQ_Q_IN(ha, ®->isp),
596 RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, ®->isp));
603 * qla24xx_calc_iocbs() - Determine number of Command Type 3 and
604 * Continuation Type 1 IOCBs to allocate.
606 * @dsds: number of data segment decriptors needed
608 * Returns the number of IOCB entries needed to store @dsds.
611 qla24xx_calc_iocbs(scsi_qla_host_t *vha, uint16_t dsds)
617 iocbs += (dsds - 1) / 5;
625 * qla24xx_build_scsi_iocbs() - Build IOCB command utilizing Command Type 7
628 * @sp: SRB command to process
629 * @cmd_pkt: Command type 3 IOCB
630 * @tot_dsds: Total number of segments to transfer
633 qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt,
638 scsi_qla_host_t *vha;
639 struct scsi_cmnd *cmd;
640 struct scatterlist *sg;
646 /* Update entry type to indicate Command Type 3 IOCB */
647 *((uint32_t *)(&cmd_pkt->entry_type)) =
648 __constant_cpu_to_le32(COMMAND_TYPE_7);
650 /* No data transfer */
651 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
652 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
656 vha = sp->fcport->vha;
659 /* Set transfer direction */
660 if (cmd->sc_data_direction == DMA_TO_DEVICE) {
661 cmd_pkt->task_mgmt_flags =
662 __constant_cpu_to_le16(TMF_WRITE_DATA);
663 sp->fcport->vha->hw->qla_stats.output_bytes +=
664 scsi_bufflen(sp->cmd);
665 } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
666 cmd_pkt->task_mgmt_flags =
667 __constant_cpu_to_le16(TMF_READ_DATA);
668 sp->fcport->vha->hw->qla_stats.input_bytes +=
669 scsi_bufflen(sp->cmd);
672 /* One DSD is available in the Command Type 3 IOCB */
674 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
676 /* Load data segments */
678 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
680 cont_a64_entry_t *cont_pkt;
682 /* Allocate additional continuation packets? */
683 if (avail_dsds == 0) {
685 * Five DSDs are available in the Continuation
688 cont_pkt = qla2x00_prep_cont_type1_iocb(vha, vha->req);
689 cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
693 sle_dma = sg_dma_address(sg);
694 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
695 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
696 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
701 struct fw_dif_context {
704 uint8_t ref_tag_mask[4]; /* Validation/Replacement Mask*/
705 uint8_t app_tag_mask[2]; /* Validation/Replacement Mask*/
709 * qla24xx_set_t10dif_tags_from_cmd - Extract Ref and App tags from SCSI command
713 qla24xx_set_t10dif_tags(srb_t *sp, struct fw_dif_context *pkt,
714 unsigned int protcnt)
716 struct scsi_cmnd *cmd = sp->cmd;
717 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
719 switch (scsi_get_prot_type(cmd)) {
720 case SCSI_PROT_DIF_TYPE0:
722 * No check for ql2xenablehba_err_chk, as it would be an
723 * I/O error if hba tag generation is not done.
725 pkt->ref_tag = cpu_to_le32((uint32_t)
726 (0xffffffff & scsi_get_lba(cmd)));
728 if (!qla2x00_hba_err_chk_enabled(sp))
731 pkt->ref_tag_mask[0] = 0xff;
732 pkt->ref_tag_mask[1] = 0xff;
733 pkt->ref_tag_mask[2] = 0xff;
734 pkt->ref_tag_mask[3] = 0xff;
738 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to
739 * match LBA in CDB + N
741 case SCSI_PROT_DIF_TYPE2:
742 pkt->app_tag = __constant_cpu_to_le16(0);
743 pkt->app_tag_mask[0] = 0x0;
744 pkt->app_tag_mask[1] = 0x0;
746 pkt->ref_tag = cpu_to_le32((uint32_t)
747 (0xffffffff & scsi_get_lba(cmd)));
749 if (!qla2x00_hba_err_chk_enabled(sp))
752 /* enable ALL bytes of the ref tag */
753 pkt->ref_tag_mask[0] = 0xff;
754 pkt->ref_tag_mask[1] = 0xff;
755 pkt->ref_tag_mask[2] = 0xff;
756 pkt->ref_tag_mask[3] = 0xff;
759 /* For Type 3 protection: 16 bit GUARD only */
760 case SCSI_PROT_DIF_TYPE3:
761 pkt->ref_tag_mask[0] = pkt->ref_tag_mask[1] =
762 pkt->ref_tag_mask[2] = pkt->ref_tag_mask[3] =
767 * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and
770 case SCSI_PROT_DIF_TYPE1:
771 pkt->ref_tag = cpu_to_le32((uint32_t)
772 (0xffffffff & scsi_get_lba(cmd)));
773 pkt->app_tag = __constant_cpu_to_le16(0);
774 pkt->app_tag_mask[0] = 0x0;
775 pkt->app_tag_mask[1] = 0x0;
777 if (!qla2x00_hba_err_chk_enabled(sp))
780 /* enable ALL bytes of the ref tag */
781 pkt->ref_tag_mask[0] = 0xff;
782 pkt->ref_tag_mask[1] = 0xff;
783 pkt->ref_tag_mask[2] = 0xff;
784 pkt->ref_tag_mask[3] = 0xff;
788 ql_dbg(ql_dbg_io, vha, 0x3009,
789 "Setting protection Tags: (BIG) ref tag = 0x%x, app tag = 0x%x, "
790 "prot SG count %d, cmd lba 0x%x, prot_type=%u cmd=%p.\n",
791 pkt->ref_tag, pkt->app_tag, protcnt, (int)scsi_get_lba(cmd),
792 scsi_get_prot_type(cmd), cmd);
796 dma_addr_t dma_addr; /* OUT */
797 uint32_t dma_len; /* OUT */
799 uint32_t tot_bytes; /* IN */
800 struct scatterlist *cur_sg; /* IN */
802 /* for book keeping, bzero on initial invocation */
803 uint32_t bytes_consumed;
805 uint32_t tot_partial;
813 qla24xx_get_one_block_sg(uint32_t blk_sz, struct qla2_sgx *sgx,
816 struct scatterlist *sg;
817 uint32_t cumulative_partial, sg_len;
818 dma_addr_t sg_dma_addr;
820 if (sgx->num_bytes == sgx->tot_bytes)
824 cumulative_partial = sgx->tot_partial;
826 sg_dma_addr = sg_dma_address(sg);
827 sg_len = sg_dma_len(sg);
829 sgx->dma_addr = sg_dma_addr + sgx->bytes_consumed;
831 if ((cumulative_partial + (sg_len - sgx->bytes_consumed)) >= blk_sz) {
832 sgx->dma_len = (blk_sz - cumulative_partial);
833 sgx->tot_partial = 0;
834 sgx->num_bytes += blk_sz;
837 sgx->dma_len = sg_len - sgx->bytes_consumed;
838 sgx->tot_partial += sgx->dma_len;
842 sgx->bytes_consumed += sgx->dma_len;
844 if (sg_len == sgx->bytes_consumed) {
848 sgx->bytes_consumed = 0;
855 qla24xx_walk_and_build_sglist_no_difb(struct qla_hw_data *ha, srb_t *sp,
856 uint32_t *dsd, uint16_t tot_dsds)
859 uint8_t avail_dsds = 0;
860 uint32_t dsd_list_len;
861 struct dsd_dma *dsd_ptr;
862 struct scatterlist *sg_prot;
863 uint32_t *cur_dsd = dsd;
864 uint16_t used_dsds = tot_dsds;
870 uint32_t sle_dma_len, tot_prot_dma_len = 0;
871 struct scsi_cmnd *cmd = sp->cmd;
873 prot_int = cmd->device->sector_size;
875 memset(&sgx, 0, sizeof(struct qla2_sgx));
876 sgx.tot_bytes = scsi_bufflen(sp->cmd);
877 sgx.cur_sg = scsi_sglist(sp->cmd);
880 sg_prot = scsi_prot_sglist(sp->cmd);
882 while (qla24xx_get_one_block_sg(prot_int, &sgx, &partial)) {
884 sle_dma = sgx.dma_addr;
885 sle_dma_len = sgx.dma_len;
887 /* Allocate additional continuation packets? */
888 if (avail_dsds == 0) {
889 avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ?
890 QLA_DSDS_PER_IOCB : used_dsds;
891 dsd_list_len = (avail_dsds + 1) * 12;
892 used_dsds -= avail_dsds;
894 /* allocate tracking DS */
895 dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC);
899 /* allocate new list */
900 dsd_ptr->dsd_addr = next_dsd =
901 dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC,
902 &dsd_ptr->dsd_list_dma);
906 * Need to cleanup only this dsd_ptr, rest
907 * will be done by sp_free_dma()
913 list_add_tail(&dsd_ptr->list,
914 &((struct crc_context *)sp->ctx)->dsd_list);
916 sp->flags |= SRB_CRC_CTX_DSD_VALID;
918 /* add new list to cmd iocb or last list */
919 *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
920 *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
921 *cur_dsd++ = dsd_list_len;
922 cur_dsd = (uint32_t *)next_dsd;
924 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
925 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
926 *cur_dsd++ = cpu_to_le32(sle_dma_len);
930 /* Got a full protection interval */
931 sle_dma = sg_dma_address(sg_prot) + tot_prot_dma_len;
934 tot_prot_dma_len += sle_dma_len;
935 if (tot_prot_dma_len == sg_dma_len(sg_prot)) {
936 tot_prot_dma_len = 0;
937 sg_prot = sg_next(sg_prot);
940 partial = 1; /* So as to not re-enter this block */
944 /* Null termination */
951 qla24xx_walk_and_build_sglist(struct qla_hw_data *ha, srb_t *sp, uint32_t *dsd,
955 uint8_t avail_dsds = 0;
956 uint32_t dsd_list_len;
957 struct dsd_dma *dsd_ptr;
958 struct scatterlist *sg;
959 uint32_t *cur_dsd = dsd;
961 uint16_t used_dsds = tot_dsds;
962 scsi_qla_host_t *vha = shost_priv(sp->cmd->device->host);
966 scsi_for_each_sg(sp->cmd, sg, tot_dsds, i) {
969 /* Allocate additional continuation packets? */
970 if (avail_dsds == 0) {
971 avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ?
972 QLA_DSDS_PER_IOCB : used_dsds;
973 dsd_list_len = (avail_dsds + 1) * 12;
974 used_dsds -= avail_dsds;
976 /* allocate tracking DS */
977 dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC);
981 /* allocate new list */
982 dsd_ptr->dsd_addr = next_dsd =
983 dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC,
984 &dsd_ptr->dsd_list_dma);
988 * Need to cleanup only this dsd_ptr, rest
989 * will be done by sp_free_dma()
995 list_add_tail(&dsd_ptr->list,
996 &((struct crc_context *)sp->ctx)->dsd_list);
998 sp->flags |= SRB_CRC_CTX_DSD_VALID;
1000 /* add new list to cmd iocb or last list */
1001 *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
1002 *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
1003 *cur_dsd++ = dsd_list_len;
1004 cur_dsd = (uint32_t *)next_dsd;
1006 sle_dma = sg_dma_address(sg);
1007 ql_dbg(ql_dbg_io, vha, 0x300a,
1008 "sg entry %d - addr=0x%x 0x%x, " "len=%d for cmd=%p.\n",
1009 cur_dsd, i, LSD(sle_dma), MSD(sle_dma), sg_dma_len(sg),
1011 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
1012 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
1013 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
1016 if (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_PASS) {
1017 cp = page_address(sg_page(sg)) + sg->offset;
1018 ql_dbg(ql_dbg_io, vha, 0x300b,
1019 "User data buffer=%p for cmd=%p.\n", cp, sp->cmd);
1022 /* Null termination */
1030 qla24xx_walk_and_build_prot_sglist(struct qla_hw_data *ha, srb_t *sp,
1035 uint8_t avail_dsds = 0;
1036 uint32_t dsd_list_len;
1037 struct dsd_dma *dsd_ptr;
1038 struct scatterlist *sg;
1040 struct scsi_cmnd *cmd;
1041 uint32_t *cur_dsd = dsd;
1042 uint16_t used_dsds = tot_dsds;
1043 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1048 scsi_for_each_prot_sg(cmd, sg, tot_dsds, i) {
1051 /* Allocate additional continuation packets? */
1052 if (avail_dsds == 0) {
1053 avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ?
1054 QLA_DSDS_PER_IOCB : used_dsds;
1055 dsd_list_len = (avail_dsds + 1) * 12;
1056 used_dsds -= avail_dsds;
1058 /* allocate tracking DS */
1059 dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC);
1063 /* allocate new list */
1064 dsd_ptr->dsd_addr = next_dsd =
1065 dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC,
1066 &dsd_ptr->dsd_list_dma);
1070 * Need to cleanup only this dsd_ptr, rest
1071 * will be done by sp_free_dma()
1077 list_add_tail(&dsd_ptr->list,
1078 &((struct crc_context *)sp->ctx)->dsd_list);
1080 sp->flags |= SRB_CRC_CTX_DSD_VALID;
1082 /* add new list to cmd iocb or last list */
1083 *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
1084 *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
1085 *cur_dsd++ = dsd_list_len;
1086 cur_dsd = (uint32_t *)next_dsd;
1088 sle_dma = sg_dma_address(sg);
1089 if (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_PASS) {
1090 ql_dbg(ql_dbg_io, vha, 0x3027,
1091 "%s(): %p, sg_entry %d - "
1092 "addr=0x%x0x%x, len=%d.\n",
1093 __func__, cur_dsd, i,
1094 LSD(sle_dma), MSD(sle_dma), sg_dma_len(sg));
1096 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
1097 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
1098 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
1100 if (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_PASS) {
1101 cp = page_address(sg_page(sg)) + sg->offset;
1102 ql_dbg(ql_dbg_io, vha, 0x3028,
1103 "%s(): Protection Data buffer = %p.\n", __func__,
1108 /* Null termination */
1116 * qla24xx_build_scsi_crc_2_iocbs() - Build IOCB command utilizing Command
1117 * Type 6 IOCB types.
1119 * @sp: SRB command to process
1120 * @cmd_pkt: Command type 3 IOCB
1121 * @tot_dsds: Total number of segments to transfer
1124 qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
1125 uint16_t tot_dsds, uint16_t tot_prot_dsds, uint16_t fw_prot_opts)
1127 uint32_t *cur_dsd, *fcp_dl;
1128 scsi_qla_host_t *vha;
1129 struct scsi_cmnd *cmd;
1130 struct scatterlist *cur_seg;
1132 uint32_t total_bytes = 0;
1133 uint32_t data_bytes;
1135 uint8_t bundling = 1;
1138 struct crc_context *crc_ctx_pkt = NULL;
1139 struct qla_hw_data *ha;
1140 uint8_t additional_fcpcdb_len;
1141 uint16_t fcp_cmnd_len;
1142 struct fcp_cmnd *fcp_cmnd;
1143 dma_addr_t crc_ctx_dma;
1149 /* Update entry type to indicate Command Type CRC_2 IOCB */
1150 *((uint32_t *)(&cmd_pkt->entry_type)) =
1151 __constant_cpu_to_le32(COMMAND_TYPE_CRC_2);
1153 vha = sp->fcport->vha;
1156 /* No data transfer */
1157 data_bytes = scsi_bufflen(cmd);
1158 if (!data_bytes || cmd->sc_data_direction == DMA_NONE) {
1159 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
1163 cmd_pkt->vp_index = sp->fcport->vp_idx;
1165 /* Set transfer direction */
1166 if (cmd->sc_data_direction == DMA_TO_DEVICE) {
1167 cmd_pkt->control_flags =
1168 __constant_cpu_to_le16(CF_WRITE_DATA);
1169 } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
1170 cmd_pkt->control_flags =
1171 __constant_cpu_to_le16(CF_READ_DATA);
1174 if ((scsi_get_prot_op(sp->cmd) == SCSI_PROT_READ_INSERT) ||
1175 (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_STRIP) ||
1176 (scsi_get_prot_op(sp->cmd) == SCSI_PROT_READ_STRIP) ||
1177 (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_INSERT))
1180 /* Allocate CRC context from global pool */
1181 crc_ctx_pkt = sp->ctx = dma_pool_alloc(ha->dl_dma_pool,
1182 GFP_ATOMIC, &crc_ctx_dma);
1185 goto crc_queuing_error;
1187 /* Zero out CTX area. */
1188 clr_ptr = (uint8_t *)crc_ctx_pkt;
1189 memset(clr_ptr, 0, sizeof(*crc_ctx_pkt));
1191 crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma;
1193 sp->flags |= SRB_CRC_CTX_DMA_VALID;
1196 crc_ctx_pkt->handle = cmd_pkt->handle;
1198 INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list);
1200 qla24xx_set_t10dif_tags(sp, (struct fw_dif_context *)
1201 &crc_ctx_pkt->ref_tag, tot_prot_dsds);
1203 cmd_pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma));
1204 cmd_pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma));
1205 cmd_pkt->crc_context_len = CRC_CONTEXT_LEN_FW;
1207 /* Determine SCSI command length -- align to 4 byte boundary */
1208 if (cmd->cmd_len > 16) {
1209 additional_fcpcdb_len = cmd->cmd_len - 16;
1210 if ((cmd->cmd_len % 4) != 0) {
1211 /* SCSI cmd > 16 bytes must be multiple of 4 */
1212 goto crc_queuing_error;
1214 fcp_cmnd_len = 12 + cmd->cmd_len + 4;
1216 additional_fcpcdb_len = 0;
1217 fcp_cmnd_len = 12 + 16 + 4;
1220 fcp_cmnd = &crc_ctx_pkt->fcp_cmnd;
1222 fcp_cmnd->additional_cdb_len = additional_fcpcdb_len;
1223 if (cmd->sc_data_direction == DMA_TO_DEVICE)
1224 fcp_cmnd->additional_cdb_len |= 1;
1225 else if (cmd->sc_data_direction == DMA_FROM_DEVICE)
1226 fcp_cmnd->additional_cdb_len |= 2;
1228 int_to_scsilun(sp->cmd->device->lun, &fcp_cmnd->lun);
1229 memcpy(fcp_cmnd->cdb, cmd->cmnd, cmd->cmd_len);
1230 cmd_pkt->fcp_cmnd_dseg_len = cpu_to_le16(fcp_cmnd_len);
1231 cmd_pkt->fcp_cmnd_dseg_address[0] = cpu_to_le32(
1232 LSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF));
1233 cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32(
1234 MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF));
1235 fcp_cmnd->task_management = 0;
1238 * Update tagged queuing modifier if using command tag queuing
1240 if (scsi_populate_tag_msg(cmd, tag)) {
1242 case HEAD_OF_QUEUE_TAG:
1243 fcp_cmnd->task_attribute = TSK_HEAD_OF_QUEUE;
1245 case ORDERED_QUEUE_TAG:
1246 fcp_cmnd->task_attribute = TSK_ORDERED;
1249 fcp_cmnd->task_attribute = TSK_SIMPLE;
1253 fcp_cmnd->task_attribute = TSK_SIMPLE;
1256 cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */
1258 /* Compute dif len and adjust data len to incude protection */
1260 blk_size = cmd->device->sector_size;
1261 dif_bytes = (data_bytes / blk_size) * 8;
1263 switch (scsi_get_prot_op(sp->cmd)) {
1264 case SCSI_PROT_READ_INSERT:
1265 case SCSI_PROT_WRITE_STRIP:
1266 total_bytes = data_bytes;
1267 data_bytes += dif_bytes;
1270 case SCSI_PROT_READ_STRIP:
1271 case SCSI_PROT_WRITE_INSERT:
1272 case SCSI_PROT_READ_PASS:
1273 case SCSI_PROT_WRITE_PASS:
1274 total_bytes = data_bytes + dif_bytes;
1280 if (!qla2x00_hba_err_chk_enabled(sp))
1281 fw_prot_opts |= 0x10; /* Disable Guard tag checking */
1284 cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address;
1287 * Configure Bundling if we need to fetch interlaving
1288 * protection PCI accesses
1290 fw_prot_opts |= PO_ENABLE_DIF_BUNDLING;
1291 crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes);
1292 crc_ctx_pkt->u.bundling.dseg_count = cpu_to_le16(tot_dsds -
1294 cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address;
1297 /* Finish the common fields of CRC pkt */
1298 crc_ctx_pkt->blk_size = cpu_to_le16(blk_size);
1299 crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts);
1300 crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes);
1301 crc_ctx_pkt->guard_seed = __constant_cpu_to_le16(0);
1302 /* Fibre channel byte count */
1303 cmd_pkt->byte_count = cpu_to_le32(total_bytes);
1304 fcp_dl = (uint32_t *)(crc_ctx_pkt->fcp_cmnd.cdb + 16 +
1305 additional_fcpcdb_len);
1306 *fcp_dl = htonl(total_bytes);
1308 if (!data_bytes || cmd->sc_data_direction == DMA_NONE) {
1309 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
1312 /* Walks data segments */
1314 cmd_pkt->control_flags |=
1315 __constant_cpu_to_le16(CF_DATA_SEG_DESCR_ENABLE);
1317 if (!bundling && tot_prot_dsds) {
1318 if (qla24xx_walk_and_build_sglist_no_difb(ha, sp,
1320 goto crc_queuing_error;
1321 } else if (qla24xx_walk_and_build_sglist(ha, sp, cur_dsd,
1322 (tot_dsds - tot_prot_dsds)))
1323 goto crc_queuing_error;
1325 if (bundling && tot_prot_dsds) {
1326 /* Walks dif segments */
1327 cur_seg = scsi_prot_sglist(cmd);
1328 cmd_pkt->control_flags |=
1329 __constant_cpu_to_le16(CF_DIF_SEG_DESCR_ENABLE);
1330 cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address;
1331 if (qla24xx_walk_and_build_prot_sglist(ha, sp, cur_dsd,
1333 goto crc_queuing_error;
1338 /* Cleanup will be performed by the caller */
1340 return QLA_FUNCTION_FAILED;
1344 * qla24xx_start_scsi() - Send a SCSI command to the ISP
1345 * @sp: command to send to the ISP
1347 * Returns non-zero if a failure occurred, else zero.
1350 qla24xx_start_scsi(srb_t *sp)
1353 unsigned long flags;
1357 struct cmd_type_7 *cmd_pkt;
1361 struct req_que *req = NULL;
1362 struct rsp_que *rsp = NULL;
1363 struct scsi_cmnd *cmd = sp->cmd;
1364 struct scsi_qla_host *vha = sp->fcport->vha;
1365 struct qla_hw_data *ha = vha->hw;
1368 /* Setup device pointers. */
1371 qla25xx_set_que(sp, &rsp);
1374 /* So we know we haven't pci_map'ed anything yet */
1377 /* Send marker if required */
1378 if (vha->marker_needed != 0) {
1379 if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
1381 return QLA_FUNCTION_FAILED;
1382 vha->marker_needed = 0;
1385 /* Acquire ring specific lock */
1386 spin_lock_irqsave(&ha->hardware_lock, flags);
1388 /* Check for room in outstanding command list. */
1389 handle = req->current_outstanding_cmd;
1390 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1392 if (handle == MAX_OUTSTANDING_COMMANDS)
1394 if (!req->outstanding_cmds[handle])
1397 if (index == MAX_OUTSTANDING_COMMANDS) {
1401 /* Map the sg table so we have an accurate count of sg entries needed */
1402 if (scsi_sg_count(cmd)) {
1403 nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
1404 scsi_sg_count(cmd), cmd->sc_data_direction);
1405 if (unlikely(!nseg))
1411 req_cnt = qla24xx_calc_iocbs(vha, tot_dsds);
1412 if (req->cnt < (req_cnt + 2)) {
1413 cnt = RD_REG_DWORD_RELAXED(req->req_q_out);
1415 if (req->ring_index < cnt)
1416 req->cnt = cnt - req->ring_index;
1418 req->cnt = req->length -
1419 (req->ring_index - cnt);
1421 if (req->cnt < (req_cnt + 2))
1424 /* Build command packet. */
1425 req->current_outstanding_cmd = handle;
1426 req->outstanding_cmds[handle] = sp;
1427 sp->handle = handle;
1428 sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle;
1429 req->cnt -= req_cnt;
1431 cmd_pkt = (struct cmd_type_7 *)req->ring_ptr;
1432 cmd_pkt->handle = MAKE_HANDLE(req->id, handle);
1434 /* Zero out remaining portion of packet. */
1435 /* tagged queuing modifier -- default is TSK_SIMPLE (0). */
1436 clr_ptr = (uint32_t *)cmd_pkt + 2;
1437 memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
1438 cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
1440 /* Set NPORT-ID and LUN number*/
1441 cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1442 cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
1443 cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
1444 cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
1445 cmd_pkt->vp_index = sp->fcport->vp_idx;
1447 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun);
1448 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
1450 /* Update tagged queuing modifier -- default is TSK_SIMPLE (0). */
1451 if (scsi_populate_tag_msg(cmd, tag)) {
1453 case HEAD_OF_QUEUE_TAG:
1454 cmd_pkt->task = TSK_HEAD_OF_QUEUE;
1456 case ORDERED_QUEUE_TAG:
1457 cmd_pkt->task = TSK_ORDERED;
1460 cmd_pkt->task = TSK_SIMPLE;
1464 cmd_pkt->task = TSK_SIMPLE;
1467 /* Load SCSI command packet. */
1468 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len);
1469 host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb));
1471 cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
1473 /* Build IOCB segments */
1474 qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds);
1476 /* Set total data segment count. */
1477 cmd_pkt->entry_count = (uint8_t)req_cnt;
1478 /* Specify response queue number where completion should happen */
1479 cmd_pkt->entry_status = (uint8_t) rsp->id;
1481 /* Adjust ring index. */
1483 if (req->ring_index == req->length) {
1484 req->ring_index = 0;
1485 req->ring_ptr = req->ring;
1489 sp->flags |= SRB_DMA_VALID;
1491 /* Set chip new ring index. */
1492 WRT_REG_DWORD(req->req_q_in, req->ring_index);
1493 RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr);
1495 /* Manage unprocessed RIO/ZIO commands in response queue. */
1496 if (vha->flags.process_response_queue &&
1497 rsp->ring_ptr->signature != RESPONSE_PROCESSED)
1498 qla24xx_process_response_queue(vha, rsp);
1500 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1505 scsi_dma_unmap(cmd);
1507 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1509 return QLA_FUNCTION_FAILED;
1514 * qla24xx_dif_start_scsi() - Send a SCSI command to the ISP
1515 * @sp: command to send to the ISP
1517 * Returns non-zero if a failure occurred, else zero.
1520 qla24xx_dif_start_scsi(srb_t *sp)
1523 unsigned long flags;
1528 uint16_t req_cnt = 0;
1530 uint16_t tot_prot_dsds;
1531 uint16_t fw_prot_opts = 0;
1532 struct req_que *req = NULL;
1533 struct rsp_que *rsp = NULL;
1534 struct scsi_cmnd *cmd = sp->cmd;
1535 struct scsi_qla_host *vha = sp->fcport->vha;
1536 struct qla_hw_data *ha = vha->hw;
1537 struct cmd_type_crc_2 *cmd_pkt;
1538 uint32_t status = 0;
1540 #define QDSS_GOT_Q_SPACE BIT_0
1542 /* Only process protection or >16 cdb in this routine */
1543 if (scsi_get_prot_op(cmd) == SCSI_PROT_NORMAL) {
1544 if (cmd->cmd_len <= 16)
1545 return qla24xx_start_scsi(sp);
1548 /* Setup device pointers. */
1550 qla25xx_set_que(sp, &rsp);
1553 /* So we know we haven't pci_map'ed anything yet */
1556 /* Send marker if required */
1557 if (vha->marker_needed != 0) {
1558 if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
1560 return QLA_FUNCTION_FAILED;
1561 vha->marker_needed = 0;
1564 /* Acquire ring specific lock */
1565 spin_lock_irqsave(&ha->hardware_lock, flags);
1567 /* Check for room in outstanding command list. */
1568 handle = req->current_outstanding_cmd;
1569 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1571 if (handle == MAX_OUTSTANDING_COMMANDS)
1573 if (!req->outstanding_cmds[handle])
1577 if (index == MAX_OUTSTANDING_COMMANDS)
1580 /* Compute number of required data segments */
1581 /* Map the sg table so we have an accurate count of sg entries needed */
1582 if (scsi_sg_count(cmd)) {
1583 nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
1584 scsi_sg_count(cmd), cmd->sc_data_direction);
1585 if (unlikely(!nseg))
1588 sp->flags |= SRB_DMA_VALID;
1590 if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) ||
1591 (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) {
1592 struct qla2_sgx sgx;
1595 memset(&sgx, 0, sizeof(struct qla2_sgx));
1596 sgx.tot_bytes = scsi_bufflen(cmd);
1597 sgx.cur_sg = scsi_sglist(cmd);
1601 while (qla24xx_get_one_block_sg(
1602 cmd->device->sector_size, &sgx, &partial))
1608 /* number of required data segments */
1611 /* Compute number of required protection segments */
1612 if (qla24xx_configure_prot_mode(sp, &fw_prot_opts)) {
1613 nseg = dma_map_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
1614 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
1615 if (unlikely(!nseg))
1618 sp->flags |= SRB_CRC_PROT_DMA_VALID;
1620 if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) ||
1621 (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) {
1622 nseg = scsi_bufflen(cmd) / cmd->device->sector_size;
1629 /* Total Data and protection sg segment(s) */
1630 tot_prot_dsds = nseg;
1632 if (req->cnt < (req_cnt + 2)) {
1633 cnt = RD_REG_DWORD_RELAXED(req->req_q_out);
1635 if (req->ring_index < cnt)
1636 req->cnt = cnt - req->ring_index;
1638 req->cnt = req->length -
1639 (req->ring_index - cnt);
1642 if (req->cnt < (req_cnt + 2))
1645 status |= QDSS_GOT_Q_SPACE;
1647 /* Build header part of command packet (excluding the OPCODE). */
1648 req->current_outstanding_cmd = handle;
1649 req->outstanding_cmds[handle] = sp;
1650 sp->handle = handle;
1651 sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle;
1652 req->cnt -= req_cnt;
1654 /* Fill-in common area */
1655 cmd_pkt = (struct cmd_type_crc_2 *)req->ring_ptr;
1656 cmd_pkt->handle = MAKE_HANDLE(req->id, handle);
1658 clr_ptr = (uint32_t *)cmd_pkt + 2;
1659 memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
1661 /* Set NPORT-ID and LUN number*/
1662 cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1663 cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
1664 cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
1665 cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
1667 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun);
1668 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
1670 /* Total Data and protection segment(s) */
1671 cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
1673 /* Build IOCB segments and adjust for data protection segments */
1674 if (qla24xx_build_scsi_crc_2_iocbs(sp, (struct cmd_type_crc_2 *)
1675 req->ring_ptr, tot_dsds, tot_prot_dsds, fw_prot_opts) !=
1679 cmd_pkt->entry_count = (uint8_t)req_cnt;
1680 /* Specify response queue number where completion should happen */
1681 cmd_pkt->entry_status = (uint8_t) rsp->id;
1682 cmd_pkt->timeout = __constant_cpu_to_le16(0);
1685 /* Adjust ring index. */
1687 if (req->ring_index == req->length) {
1688 req->ring_index = 0;
1689 req->ring_ptr = req->ring;
1693 /* Set chip new ring index. */
1694 WRT_REG_DWORD(req->req_q_in, req->ring_index);
1695 RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr);
1697 /* Manage unprocessed RIO/ZIO commands in response queue. */
1698 if (vha->flags.process_response_queue &&
1699 rsp->ring_ptr->signature != RESPONSE_PROCESSED)
1700 qla24xx_process_response_queue(vha, rsp);
1702 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1707 if (status & QDSS_GOT_Q_SPACE) {
1708 req->outstanding_cmds[handle] = NULL;
1709 req->cnt += req_cnt;
1711 /* Cleanup will be performed by the caller (queuecommand) */
1713 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1714 return QLA_FUNCTION_FAILED;
1718 static void qla25xx_set_que(srb_t *sp, struct rsp_que **rsp)
1720 struct scsi_cmnd *cmd = sp->cmd;
1721 struct qla_hw_data *ha = sp->fcport->vha->hw;
1722 int affinity = cmd->request->cpu;
1724 if (ha->flags.cpu_affinity_enabled && affinity >= 0 &&
1725 affinity < ha->max_rsp_queues - 1)
1726 *rsp = ha->rsp_q_map[affinity + 1];
1728 *rsp = ha->rsp_q_map[0];
1731 /* Generic Control-SRB manipulation functions. */
1733 qla2x00_alloc_iocbs(scsi_qla_host_t *vha, srb_t *sp)
1735 struct qla_hw_data *ha = vha->hw;
1736 struct req_que *req = ha->req_q_map[0];
1737 device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
1738 uint32_t index, handle;
1740 uint16_t cnt, req_cnt;
1747 goto skip_cmd_array;
1749 /* Check for room in outstanding command list. */
1750 handle = req->current_outstanding_cmd;
1751 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1753 if (handle == MAX_OUTSTANDING_COMMANDS)
1755 if (!req->outstanding_cmds[handle])
1758 if (index == MAX_OUTSTANDING_COMMANDS) {
1759 ql_log(ql_log_warn, vha, 0x700b,
1760 "No room on oustanding cmd array.\n");
1764 /* Prep command array. */
1765 req->current_outstanding_cmd = handle;
1766 req->outstanding_cmds[handle] = sp;
1767 sp->handle = handle;
1770 /* Check for room on request queue. */
1771 if (req->cnt < req_cnt) {
1773 cnt = RD_REG_DWORD(®->isp25mq.req_q_out);
1774 else if (IS_QLA82XX(ha))
1775 cnt = RD_REG_DWORD(®->isp82.req_q_out);
1776 else if (IS_FWI2_CAPABLE(ha))
1777 cnt = RD_REG_DWORD(®->isp24.req_q_out);
1779 cnt = qla2x00_debounce_register(
1780 ISP_REQ_Q_OUT(ha, ®->isp));
1782 if (req->ring_index < cnt)
1783 req->cnt = cnt - req->ring_index;
1785 req->cnt = req->length -
1786 (req->ring_index - cnt);
1788 if (req->cnt < req_cnt)
1792 req->cnt -= req_cnt;
1793 pkt = req->ring_ptr;
1794 memset(pkt, 0, REQUEST_ENTRY_SIZE);
1795 pkt->entry_count = req_cnt;
1796 pkt->handle = handle;
1803 qla2x00_start_iocbs(srb_t *sp)
1805 struct qla_hw_data *ha = sp->fcport->vha->hw;
1806 struct req_que *req = ha->req_q_map[0];
1807 device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
1808 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1810 if (IS_QLA82XX(ha)) {
1811 qla82xx_start_iocbs(sp);
1813 /* Adjust ring index. */
1815 if (req->ring_index == req->length) {
1816 req->ring_index = 0;
1817 req->ring_ptr = req->ring;
1821 /* Set chip new ring index. */
1823 WRT_REG_DWORD(®->isp25mq.req_q_in, req->ring_index);
1824 RD_REG_DWORD(&ioreg->hccr);
1825 } else if (IS_QLA82XX(ha)) {
1826 qla82xx_start_iocbs(sp);
1827 } else if (IS_FWI2_CAPABLE(ha)) {
1828 WRT_REG_DWORD(®->isp24.req_q_in, req->ring_index);
1829 RD_REG_DWORD_RELAXED(®->isp24.req_q_in);
1831 WRT_REG_WORD(ISP_REQ_Q_IN(ha, ®->isp),
1833 RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, ®->isp));
1839 qla24xx_login_iocb(srb_t *sp, struct logio_entry_24xx *logio)
1841 struct srb_ctx *ctx = sp->ctx;
1842 struct srb_iocb *lio = ctx->u.iocb_cmd;
1844 logio->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1845 logio->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
1846 if (lio->u.logio.flags & SRB_LOGIN_COND_PLOGI)
1847 logio->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
1848 if (lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI)
1849 logio->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
1850 logio->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1851 logio->port_id[0] = sp->fcport->d_id.b.al_pa;
1852 logio->port_id[1] = sp->fcport->d_id.b.area;
1853 logio->port_id[2] = sp->fcport->d_id.b.domain;
1854 logio->vp_index = sp->fcport->vp_idx;
1858 qla2x00_login_iocb(srb_t *sp, struct mbx_entry *mbx)
1860 struct qla_hw_data *ha = sp->fcport->vha->hw;
1861 struct srb_ctx *ctx = sp->ctx;
1862 struct srb_iocb *lio = ctx->u.iocb_cmd;
1865 mbx->entry_type = MBX_IOCB_TYPE;
1866 SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id);
1867 mbx->mb0 = cpu_to_le16(MBC_LOGIN_FABRIC_PORT);
1868 opts = lio->u.logio.flags & SRB_LOGIN_COND_PLOGI ? BIT_0 : 0;
1869 opts |= lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI ? BIT_1 : 0;
1870 if (HAS_EXTENDED_IDS(ha)) {
1871 mbx->mb1 = cpu_to_le16(sp->fcport->loop_id);
1872 mbx->mb10 = cpu_to_le16(opts);
1874 mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | opts);
1876 mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain);
1877 mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 |
1878 sp->fcport->d_id.b.al_pa);
1879 mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx);
1883 qla24xx_logout_iocb(srb_t *sp, struct logio_entry_24xx *logio)
1885 logio->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1886 logio->control_flags =
1887 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1888 logio->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1889 logio->port_id[0] = sp->fcport->d_id.b.al_pa;
1890 logio->port_id[1] = sp->fcport->d_id.b.area;
1891 logio->port_id[2] = sp->fcport->d_id.b.domain;
1892 logio->vp_index = sp->fcport->vp_idx;
1896 qla2x00_logout_iocb(srb_t *sp, struct mbx_entry *mbx)
1898 struct qla_hw_data *ha = sp->fcport->vha->hw;
1900 mbx->entry_type = MBX_IOCB_TYPE;
1901 SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id);
1902 mbx->mb0 = cpu_to_le16(MBC_LOGOUT_FABRIC_PORT);
1903 mbx->mb1 = HAS_EXTENDED_IDS(ha) ?
1904 cpu_to_le16(sp->fcport->loop_id):
1905 cpu_to_le16(sp->fcport->loop_id << 8);
1906 mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain);
1907 mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 |
1908 sp->fcport->d_id.b.al_pa);
1909 mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx);
1910 /* Implicit: mbx->mbx10 = 0. */
1914 qla24xx_adisc_iocb(srb_t *sp, struct logio_entry_24xx *logio)
1916 logio->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1917 logio->control_flags = cpu_to_le16(LCF_COMMAND_ADISC);
1918 logio->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1919 logio->vp_index = sp->fcport->vp_idx;
1923 qla2x00_adisc_iocb(srb_t *sp, struct mbx_entry *mbx)
1925 struct qla_hw_data *ha = sp->fcport->vha->hw;
1927 mbx->entry_type = MBX_IOCB_TYPE;
1928 SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id);
1929 mbx->mb0 = cpu_to_le16(MBC_GET_PORT_DATABASE);
1930 if (HAS_EXTENDED_IDS(ha)) {
1931 mbx->mb1 = cpu_to_le16(sp->fcport->loop_id);
1932 mbx->mb10 = cpu_to_le16(BIT_0);
1934 mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | BIT_0);
1936 mbx->mb2 = cpu_to_le16(MSW(ha->async_pd_dma));
1937 mbx->mb3 = cpu_to_le16(LSW(ha->async_pd_dma));
1938 mbx->mb6 = cpu_to_le16(MSW(MSD(ha->async_pd_dma)));
1939 mbx->mb7 = cpu_to_le16(LSW(MSD(ha->async_pd_dma)));
1940 mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx);
1944 qla24xx_tm_iocb(srb_t *sp, struct tsk_mgmt_entry *tsk)
1948 struct fc_port *fcport = sp->fcport;
1949 scsi_qla_host_t *vha = fcport->vha;
1950 struct qla_hw_data *ha = vha->hw;
1951 struct srb_ctx *ctx = sp->ctx;
1952 struct srb_iocb *iocb = ctx->u.iocb_cmd;
1953 struct req_que *req = vha->req;
1955 flags = iocb->u.tmf.flags;
1956 lun = iocb->u.tmf.lun;
1958 tsk->entry_type = TSK_MGMT_IOCB_TYPE;
1959 tsk->entry_count = 1;
1960 tsk->handle = MAKE_HANDLE(req->id, tsk->handle);
1961 tsk->nport_handle = cpu_to_le16(fcport->loop_id);
1962 tsk->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
1963 tsk->control_flags = cpu_to_le32(flags);
1964 tsk->port_id[0] = fcport->d_id.b.al_pa;
1965 tsk->port_id[1] = fcport->d_id.b.area;
1966 tsk->port_id[2] = fcport->d_id.b.domain;
1967 tsk->vp_index = fcport->vp_idx;
1969 if (flags == TCF_LUN_RESET) {
1970 int_to_scsilun(lun, &tsk->lun);
1971 host_to_fcp_swap((uint8_t *)&tsk->lun,
1977 qla24xx_els_iocb(srb_t *sp, struct els_entry_24xx *els_iocb)
1979 struct fc_bsg_job *bsg_job = ((struct srb_ctx *)sp->ctx)->u.bsg_job;
1981 els_iocb->entry_type = ELS_IOCB_TYPE;
1982 els_iocb->entry_count = 1;
1983 els_iocb->sys_define = 0;
1984 els_iocb->entry_status = 0;
1985 els_iocb->handle = sp->handle;
1986 els_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1987 els_iocb->tx_dsd_count = __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
1988 els_iocb->vp_index = sp->fcport->vp_idx;
1989 els_iocb->sof_type = EST_SOFI3;
1990 els_iocb->rx_dsd_count = __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt);
1993 (((struct srb_ctx *)sp->ctx)->type == SRB_ELS_CMD_RPT) ?
1994 bsg_job->request->rqst_data.r_els.els_code :
1995 bsg_job->request->rqst_data.h_els.command_code;
1996 els_iocb->port_id[0] = sp->fcport->d_id.b.al_pa;
1997 els_iocb->port_id[1] = sp->fcport->d_id.b.area;
1998 els_iocb->port_id[2] = sp->fcport->d_id.b.domain;
1999 els_iocb->control_flags = 0;
2000 els_iocb->rx_byte_count =
2001 cpu_to_le32(bsg_job->reply_payload.payload_len);
2002 els_iocb->tx_byte_count =
2003 cpu_to_le32(bsg_job->request_payload.payload_len);
2005 els_iocb->tx_address[0] = cpu_to_le32(LSD(sg_dma_address
2006 (bsg_job->request_payload.sg_list)));
2007 els_iocb->tx_address[1] = cpu_to_le32(MSD(sg_dma_address
2008 (bsg_job->request_payload.sg_list)));
2009 els_iocb->tx_len = cpu_to_le32(sg_dma_len
2010 (bsg_job->request_payload.sg_list));
2012 els_iocb->rx_address[0] = cpu_to_le32(LSD(sg_dma_address
2013 (bsg_job->reply_payload.sg_list)));
2014 els_iocb->rx_address[1] = cpu_to_le32(MSD(sg_dma_address
2015 (bsg_job->reply_payload.sg_list)));
2016 els_iocb->rx_len = cpu_to_le32(sg_dma_len
2017 (bsg_job->reply_payload.sg_list));
2021 qla2x00_ct_iocb(srb_t *sp, ms_iocb_entry_t *ct_iocb)
2023 uint16_t avail_dsds;
2025 struct scatterlist *sg;
2028 scsi_qla_host_t *vha = sp->fcport->vha;
2029 struct qla_hw_data *ha = vha->hw;
2030 struct fc_bsg_job *bsg_job = ((struct srb_ctx *)sp->ctx)->u.bsg_job;
2031 int loop_iterartion = 0;
2032 int cont_iocb_prsnt = 0;
2033 int entry_count = 1;
2035 memset(ct_iocb, 0, sizeof(ms_iocb_entry_t));
2036 ct_iocb->entry_type = CT_IOCB_TYPE;
2037 ct_iocb->entry_status = 0;
2038 ct_iocb->handle1 = sp->handle;
2039 SET_TARGET_ID(ha, ct_iocb->loop_id, sp->fcport->loop_id);
2040 ct_iocb->status = __constant_cpu_to_le16(0);
2041 ct_iocb->control_flags = __constant_cpu_to_le16(0);
2042 ct_iocb->timeout = 0;
2043 ct_iocb->cmd_dsd_count =
2044 __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
2045 ct_iocb->total_dsd_count =
2046 __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt + 1);
2047 ct_iocb->req_bytecount =
2048 cpu_to_le32(bsg_job->request_payload.payload_len);
2049 ct_iocb->rsp_bytecount =
2050 cpu_to_le32(bsg_job->reply_payload.payload_len);
2052 ct_iocb->dseg_req_address[0] = cpu_to_le32(LSD(sg_dma_address
2053 (bsg_job->request_payload.sg_list)));
2054 ct_iocb->dseg_req_address[1] = cpu_to_le32(MSD(sg_dma_address
2055 (bsg_job->request_payload.sg_list)));
2056 ct_iocb->dseg_req_length = ct_iocb->req_bytecount;
2058 ct_iocb->dseg_rsp_address[0] = cpu_to_le32(LSD(sg_dma_address
2059 (bsg_job->reply_payload.sg_list)));
2060 ct_iocb->dseg_rsp_address[1] = cpu_to_le32(MSD(sg_dma_address
2061 (bsg_job->reply_payload.sg_list)));
2062 ct_iocb->dseg_rsp_length = ct_iocb->rsp_bytecount;
2065 cur_dsd = (uint32_t *)ct_iocb->dseg_rsp_address;
2067 tot_dsds = bsg_job->reply_payload.sg_cnt;
2069 for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) {
2071 cont_a64_entry_t *cont_pkt;
2073 /* Allocate additional continuation packets? */
2074 if (avail_dsds == 0) {
2076 * Five DSDs are available in the Cont.
2079 cont_pkt = qla2x00_prep_cont_type1_iocb(vha,
2080 vha->hw->req_q_map[0]);
2081 cur_dsd = (uint32_t *) cont_pkt->dseg_0_address;
2083 cont_iocb_prsnt = 1;
2087 sle_dma = sg_dma_address(sg);
2088 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
2089 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
2090 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
2094 ct_iocb->entry_count = entry_count;
2098 qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb)
2100 uint16_t avail_dsds;
2102 struct scatterlist *sg;
2105 scsi_qla_host_t *vha = sp->fcport->vha;
2106 struct qla_hw_data *ha = vha->hw;
2107 struct fc_bsg_job *bsg_job = ((struct srb_ctx *)sp->ctx)->u.bsg_job;
2108 int loop_iterartion = 0;
2109 int cont_iocb_prsnt = 0;
2110 int entry_count = 1;
2112 ct_iocb->entry_type = CT_IOCB_TYPE;
2113 ct_iocb->entry_status = 0;
2114 ct_iocb->sys_define = 0;
2115 ct_iocb->handle = sp->handle;
2117 ct_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
2118 ct_iocb->vp_index = sp->fcport->vp_idx;
2119 ct_iocb->comp_status = __constant_cpu_to_le16(0);
2121 ct_iocb->cmd_dsd_count =
2122 __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
2123 ct_iocb->timeout = 0;
2124 ct_iocb->rsp_dsd_count =
2125 __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt);
2126 ct_iocb->rsp_byte_count =
2127 cpu_to_le32(bsg_job->reply_payload.payload_len);
2128 ct_iocb->cmd_byte_count =
2129 cpu_to_le32(bsg_job->request_payload.payload_len);
2130 ct_iocb->dseg_0_address[0] = cpu_to_le32(LSD(sg_dma_address
2131 (bsg_job->request_payload.sg_list)));
2132 ct_iocb->dseg_0_address[1] = cpu_to_le32(MSD(sg_dma_address
2133 (bsg_job->request_payload.sg_list)));
2134 ct_iocb->dseg_0_len = cpu_to_le32(sg_dma_len
2135 (bsg_job->request_payload.sg_list));
2138 cur_dsd = (uint32_t *)ct_iocb->dseg_1_address;
2140 tot_dsds = bsg_job->reply_payload.sg_cnt;
2142 for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) {
2144 cont_a64_entry_t *cont_pkt;
2146 /* Allocate additional continuation packets? */
2147 if (avail_dsds == 0) {
2149 * Five DSDs are available in the Cont.
2152 cont_pkt = qla2x00_prep_cont_type1_iocb(vha,
2154 cur_dsd = (uint32_t *) cont_pkt->dseg_0_address;
2156 cont_iocb_prsnt = 1;
2160 sle_dma = sg_dma_address(sg);
2161 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
2162 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
2163 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
2167 ct_iocb->entry_count = entry_count;
2171 qla2x00_start_sp(srb_t *sp)
2174 struct qla_hw_data *ha = sp->fcport->vha->hw;
2176 struct srb_ctx *ctx = sp->ctx;
2177 unsigned long flags;
2179 rval = QLA_FUNCTION_FAILED;
2180 spin_lock_irqsave(&ha->hardware_lock, flags);
2181 pkt = qla2x00_alloc_iocbs(sp->fcport->vha, sp);
2183 ql_log(ql_log_warn, sp->fcport->vha, 0x700c,
2184 "qla2x00_alloc_iocbs failed.\n");
2189 switch (ctx->type) {
2191 IS_FWI2_CAPABLE(ha) ?
2192 qla24xx_login_iocb(sp, pkt) :
2193 qla2x00_login_iocb(sp, pkt);
2195 case SRB_LOGOUT_CMD:
2196 IS_FWI2_CAPABLE(ha) ?
2197 qla24xx_logout_iocb(sp, pkt) :
2198 qla2x00_logout_iocb(sp, pkt);
2200 case SRB_ELS_CMD_RPT:
2201 case SRB_ELS_CMD_HST:
2202 qla24xx_els_iocb(sp, pkt);
2205 IS_FWI2_CAPABLE(ha) ?
2206 qla24xx_ct_iocb(sp, pkt) :
2207 qla2x00_ct_iocb(sp, pkt);
2210 IS_FWI2_CAPABLE(ha) ?
2211 qla24xx_adisc_iocb(sp, pkt) :
2212 qla2x00_adisc_iocb(sp, pkt);
2215 qla24xx_tm_iocb(sp, pkt);
2222 qla2x00_start_iocbs(sp);
2224 spin_unlock_irqrestore(&ha->hardware_lock, flags);