Lines Matching +full:single +full:- +full:tt
1 // SPDX-License-Identifier: GPL-2.0-only
7 * Maintained at www.Open-FCoE.org
41 #define FC_SRB_DISCONTIG (1 << 4) /* non-sequential data recvd */
54 * struct fc_fcp_internal - FCP layer internal data
71 #define fc_get_scsi_internal(x) ((struct fc_fcp_internal *)(x)->scsi_priv)
124 * fc_fcp_pkt_alloc() - Allocate a fcp_pkt
136 fsp = mempool_alloc(si->scsi_pkt_pool, gfp); in fc_fcp_pkt_alloc()
139 fsp->lp = lport; in fc_fcp_pkt_alloc()
140 fsp->xfer_ddp = FC_XID_UNKNOWN; in fc_fcp_pkt_alloc()
141 refcount_set(&fsp->ref_cnt, 1); in fc_fcp_pkt_alloc()
142 timer_setup(&fsp->timer, NULL, 0); in fc_fcp_pkt_alloc()
143 INIT_LIST_HEAD(&fsp->list); in fc_fcp_pkt_alloc()
144 spin_lock_init(&fsp->scsi_pkt_lock); in fc_fcp_pkt_alloc()
146 this_cpu_inc(lport->stats->FcpPktAllocFails); in fc_fcp_pkt_alloc()
152 * fc_fcp_pkt_release() - Release hold on a fcp_pkt
160 if (refcount_dec_and_test(&fsp->ref_cnt)) { in fc_fcp_pkt_release()
161 struct fc_fcp_internal *si = fc_get_scsi_internal(fsp->lp); in fc_fcp_pkt_release()
163 mempool_free(fsp, si->scsi_pkt_pool); in fc_fcp_pkt_release()
168 * fc_fcp_pkt_hold() - Hold a fcp_pkt
173 refcount_inc(&fsp->ref_cnt); in fc_fcp_pkt_hold()
177 * fc_fcp_pkt_destroy() - Release hold on a fcp_pkt
193 * fc_fcp_lock_pkt() - Lock a fcp_pkt and increase its reference count
196 * We should only return error if we return a command to SCSI-ml before
199 * each other on the wire/network-layer.
211 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_fcp_lock_pkt()
212 if (fsp->state & FC_SRB_COMPL) { in fc_fcp_lock_pkt()
213 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_fcp_lock_pkt()
214 return -EPERM; in fc_fcp_lock_pkt()
222 * fc_fcp_unlock_pkt() - Release a fcp_pkt's lock and decrement its
228 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_fcp_unlock_pkt()
233 * fc_fcp_timer_set() - Start a timer for a fcp_pkt
239 if (!(fsp->state & FC_SRB_COMPL)) { in fc_fcp_timer_set()
240 mod_timer(&fsp->timer, jiffies + delay); in fc_fcp_timer_set()
241 fsp->timer_delay = delay; in fc_fcp_timer_set()
247 fsp->state |= FC_SRB_ABORTED; in fc_fcp_abort_done()
248 fsp->state &= ~FC_SRB_ABORT_PENDING; in fc_fcp_abort_done()
250 if (fsp->wait_for_comp) in fc_fcp_abort_done()
251 complete(&fsp->tm_done); in fc_fcp_abort_done()
257 * fc_fcp_send_abort() - Send an abort for exchanges associated with a
265 if (!fsp->seq_ptr) in fc_fcp_send_abort()
266 return -EINVAL; in fc_fcp_send_abort()
268 this_cpu_inc(fsp->lp->stats->FcpPktAborts); in fc_fcp_send_abort()
270 fsp->state |= FC_SRB_ABORT_PENDING; in fc_fcp_send_abort()
271 rc = fc_seq_exch_abort(fsp->seq_ptr, 0); in fc_fcp_send_abort()
273 * fc_seq_exch_abort() might return -ENXIO if in fc_fcp_send_abort()
276 if (rc == -ENXIO) { in fc_fcp_send_abort()
284 * fc_fcp_retry_cmd() - Retry a fcp_pkt
290 * fc_io_compl() will notify the SCSI-ml that the I/O is done.
291 * The SCSI-ml will retry the command.
295 if (fsp->seq_ptr) { in fc_fcp_retry_cmd()
296 fc_exch_done(fsp->seq_ptr); in fc_fcp_retry_cmd()
297 fsp->seq_ptr = NULL; in fc_fcp_retry_cmd()
300 fsp->state &= ~FC_SRB_ABORT_PENDING; in fc_fcp_retry_cmd()
301 fsp->io_status = 0; in fc_fcp_retry_cmd()
302 fsp->status_code = status_code; in fc_fcp_retry_cmd()
307 * fc_fcp_ddp_setup() - Calls a LLD's ddp_setup routine to set up DDP context
315 lport = fsp->lp; in fc_fcp_ddp_setup()
316 if ((fsp->req_flags & FC_SRB_READ) && in fc_fcp_ddp_setup()
317 (lport->lro_enabled) && (lport->tt.ddp_setup)) { in fc_fcp_ddp_setup()
318 if (lport->tt.ddp_setup(lport, xid, scsi_sglist(fsp->cmd), in fc_fcp_ddp_setup()
319 scsi_sg_count(fsp->cmd))) in fc_fcp_ddp_setup()
320 fsp->xfer_ddp = xid; in fc_fcp_ddp_setup()
325 * fc_fcp_ddp_done() - Calls a LLD's ddp_done routine to release any
336 if (fsp->xfer_ddp == FC_XID_UNKNOWN) in fc_fcp_ddp_done()
339 lport = fsp->lp; in fc_fcp_ddp_done()
340 if (lport->tt.ddp_done) { in fc_fcp_ddp_done()
341 fsp->xfer_len = lport->tt.ddp_done(lport, fsp->xfer_ddp); in fc_fcp_ddp_done()
342 fsp->xfer_ddp = FC_XID_UNKNOWN; in fc_fcp_ddp_done()
347 * fc_fcp_can_queue_ramp_up() - increases can_queue
356 spin_lock_irqsave(lport->host->host_lock, flags); in fc_fcp_can_queue_ramp_up()
358 if (si->last_can_queue_ramp_up_time && in fc_fcp_can_queue_ramp_up()
359 (time_before(jiffies, si->last_can_queue_ramp_up_time + in fc_fcp_can_queue_ramp_up()
363 if (time_before(jiffies, si->last_can_queue_ramp_down_time + in fc_fcp_can_queue_ramp_up()
367 si->last_can_queue_ramp_up_time = jiffies; in fc_fcp_can_queue_ramp_up()
369 can_queue = lport->host->can_queue << 1; in fc_fcp_can_queue_ramp_up()
370 if (can_queue >= si->max_can_queue) { in fc_fcp_can_queue_ramp_up()
371 can_queue = si->max_can_queue; in fc_fcp_can_queue_ramp_up()
372 si->last_can_queue_ramp_down_time = 0; in fc_fcp_can_queue_ramp_up()
374 lport->host->can_queue = can_queue; in fc_fcp_can_queue_ramp_up()
375 shost_printk(KERN_ERR, lport->host, "libfc: increased " in fc_fcp_can_queue_ramp_up()
379 spin_unlock_irqrestore(lport->host->host_lock, flags); in fc_fcp_can_queue_ramp_up()
383 * fc_fcp_can_queue_ramp_down() - reduces can_queue
399 spin_lock_irqsave(lport->host->host_lock, flags); in fc_fcp_can_queue_ramp_down()
401 if (si->last_can_queue_ramp_down_time && in fc_fcp_can_queue_ramp_down()
402 (time_before(jiffies, si->last_can_queue_ramp_down_time + in fc_fcp_can_queue_ramp_down()
406 si->last_can_queue_ramp_down_time = jiffies; in fc_fcp_can_queue_ramp_down()
408 can_queue = lport->host->can_queue; in fc_fcp_can_queue_ramp_down()
412 lport->host->can_queue = can_queue; in fc_fcp_can_queue_ramp_down()
416 spin_unlock_irqrestore(lport->host->host_lock, flags); in fc_fcp_can_queue_ramp_down()
421 * fc_fcp_frame_alloc() - Allocates fc_frame structure and buffer.
437 this_cpu_inc(lport->stats->FcpFrameAllocFails); in fc_fcp_frame_alloc()
440 shost_printk(KERN_ERR, lport->host, in fc_fcp_frame_alloc()
442 "reducing can_queue to %d.\n", lport->host->can_queue); in fc_fcp_frame_alloc()
447 * get_fsp_rec_tov() - Helper function to get REC_TOV
450 * Returns rec tov in jiffies as rpriv->e_d_tov + 1 second
454 struct fc_rport_libfc_priv *rpriv = fsp->rport->dd_data; in get_fsp_rec_tov()
457 if (rpriv && rpriv->e_d_tov > e_d_tov) in get_fsp_rec_tov()
458 e_d_tov = rpriv->e_d_tov; in get_fsp_rec_tov()
463 * fc_fcp_recv_data() - Handler for receiving SCSI-FCP data from a target
469 struct scsi_cmnd *sc = fsp->cmd; in fc_fcp_recv_data()
470 struct fc_lport *lport = fsp->lp; in fc_fcp_recv_data()
483 offset = ntohl(fh->fh_parm_offset); in fc_fcp_recv_data()
485 len = fr_len(fp) - sizeof(*fh); in fc_fcp_recv_data()
492 * Indicate error to scsi-ml because something went wrong with the in fc_fcp_recv_data()
495 if (fsp->xfer_ddp != FC_XID_UNKNOWN) { in fc_fcp_recv_data()
501 if (offset + len > fsp->data_len) { in fc_fcp_recv_data()
507 "data_len %x\n", len, offset, fsp->data_len); in fc_fcp_recv_data()
509 /* Data is corrupted indicate scsi-ml should retry */ in fc_fcp_recv_data()
513 if (offset != fsp->xfer_len) in fc_fcp_recv_data()
514 fsp->state |= FC_SRB_DISCONTIG; in fc_fcp_recv_data()
528 crc = crc32(crc, buf + len, 4 - (len % 4)); in fc_fcp_recv_data()
532 this_cpu_inc(lport->stats->ErrorFrames); in fc_fcp_recv_data()
534 if (this_cpu_inc_return(lport->stats->InvalidCRCCount) < FC_MAX_ERROR_CNT) in fc_fcp_recv_data()
537 lport->port_id); in fc_fcp_recv_data()
545 if (fsp->state & FC_SRB_DISCONTIG) { in fc_fcp_recv_data()
553 if (fsp->xfer_contig_end == start_offset) in fc_fcp_recv_data()
554 fsp->xfer_contig_end += copy_len; in fc_fcp_recv_data()
555 fsp->xfer_len += copy_len; in fc_fcp_recv_data()
561 if (unlikely(fsp->state & FC_SRB_RCV_STATUS) && in fc_fcp_recv_data()
562 fsp->xfer_len == fsp->data_len - fsp->scsi_resid) { in fc_fcp_recv_data()
563 FC_FCP_DBG( fsp, "complete out-of-order sequence\n" ); in fc_fcp_recv_data()
572 * fc_fcp_send_data() - Send SCSI data to a target
580 * seq_blen amount of data in single frame, otherwise send
591 struct fc_lport *lport = fsp->lp; in fc_fcp_send_data()
602 int using_sg = lport->sg_supp; in fc_fcp_send_data()
606 if (unlikely(offset + seq_blen > fsp->data_len)) { in fc_fcp_send_data()
608 FC_FCP_DBG(fsp, "xfer-ready past end. seq_blen %zx " in fc_fcp_send_data()
612 } else if (offset != fsp->xfer_len) { in fc_fcp_send_data()
613 /* Out of Order Data Request - no problem, but unexpected. */ in fc_fcp_send_data()
614 FC_FCP_DBG(fsp, "xfer-ready non-contiguous. " in fc_fcp_send_data()
621 * to max FC frame payload previously set in fsp->max_payload. in fc_fcp_send_data()
623 t_blen = fsp->max_payload; in fc_fcp_send_data()
624 if (lport->seq_offload) { in fc_fcp_send_data()
625 t_blen = min(seq_blen, (size_t)lport->lso_max); in fc_fcp_send_data()
627 fsp, seq_blen, lport->lso_max, t_blen); in fc_fcp_send_data()
631 t_blen &= ~(512 - 1); /* round down to block size */ in fc_fcp_send_data()
632 sc = fsp->cmd; in fc_fcp_send_data()
644 if (offset >= sg->length) { in fc_fcp_send_data()
645 offset -= sg->length; in fc_fcp_send_data()
654 * handle odd lengths in non-linear skbs. in fc_fcp_send_data()
661 return -ENOMEM; in fc_fcp_send_data()
665 fr_max_payload(fp) = fsp->max_payload; in fc_fcp_send_data()
668 off = offset + sg->offset; in fc_fcp_send_data()
669 sg_bytes = min(tlen, sg->length - offset); in fc_fcp_send_data()
671 (size_t) (PAGE_SIZE - (off & ~PAGE_MASK))); in fc_fcp_send_data()
676 skb_shinfo(fp_skb(fp))->nr_frags, in fc_fcp_send_data()
678 fp_skb(fp)->data_len += sg_bytes; in fc_fcp_send_data()
680 fp_skb(fp)->truesize += PAGE_SIZE; in fc_fcp_send_data()
694 tlen -= sg_bytes; in fc_fcp_send_data()
695 remaining -= sg_bytes; in fc_fcp_send_data()
697 if ((skb_shinfo(fp_skb(fp))->nr_frags < FC_FRAME_SG_LEN) && in fc_fcp_send_data()
709 fc_fill_fc_hdr(fp, FC_RCTL_DD_SOL_DATA, ep->did, ep->sid, in fc_fcp_send_data()
722 fsp->xfer_len += seq_blen; /* premature count? */ in fc_fcp_send_data()
727 * fc_fcp_abts_resp() - Receive an ABTS response
738 switch (fh->fh_r_ctl) { in fc_fcp_abts_resp()
743 if (brp && brp->br_reason == FC_BA_RJT_LOG_ERR) in fc_fcp_abts_resp()
749 * and scsi-ml recover in this case, in fc_fcp_abts_resp()
760 * fc_fcp_recv() - Receive an FCP frame
771 struct fc_lport *lport = fsp->lp; in fc_fcp_recv()
783 r_ctl = fh->fh_r_ctl; in fc_fcp_recv()
785 if (lport->state != LPORT_ST_READY) { in fc_fcp_recv()
787 lport->state, r_ctl); in fc_fcp_recv()
793 if (fh->fh_type == FC_TYPE_BLS) { in fc_fcp_recv()
798 if (fsp->state & (FC_SRB_ABORTED | FC_SRB_ABORT_PENDING)) { in fc_fcp_recv()
813 (size_t) ntohl(dd->ft_data_ro), in fc_fcp_recv()
814 (size_t) ntohl(dd->ft_burst_len)); in fc_fcp_recv()
816 seq->rec_data = fsp->xfer_len; in fc_fcp_recv()
824 seq->rec_data = fsp->xfer_contig_end; in fc_fcp_recv()
839 * fc_fcp_resp() - Handler for FCP responses
859 plen -= sizeof(*fh); in fc_fcp_resp()
861 fsp->cdb_status = fc_rp->fr_status; in fc_fcp_resp()
862 flags = fc_rp->fr_flags; in fc_fcp_resp()
863 fsp->scsi_comp_flags = flags; in fc_fcp_resp()
864 expected_len = fsp->data_len; in fc_fcp_resp()
869 if (unlikely((flags & ~FCP_CONF_REQ) || fc_rp->fr_status)) { in fc_fcp_resp()
876 respl = ntohl(rp_ex->fr_rsp_len); in fc_fcp_resp()
880 if (fsp->wait_for_comp) { in fc_fcp_resp()
882 fsp->cdb_status = fc_rp_info->rsp_code; in fc_fcp_resp()
883 complete(&fsp->tm_done); in fc_fcp_resp()
892 snsl = ntohl(rp_ex->fr_sns_len); in fc_fcp_resp()
895 memcpy(fsp->cmd->sense_buffer, in fc_fcp_resp()
900 if (plen < sizeof(*fc_rp) + sizeof(rp_ex->fr_resid)) in fc_fcp_resp()
903 fsp->scsi_resid = ntohl(rp_ex->fr_resid); in fc_fcp_resp()
905 * The cmnd->underflow is the minimum number of in fc_fcp_resp()
913 (fc_rp->fr_status == 0) && in fc_fcp_resp()
914 (scsi_bufflen(fsp->cmd) - in fc_fcp_resp()
915 fsp->scsi_resid) < fsp->cmd->underflow) in fc_fcp_resp()
917 expected_len -= fsp->scsi_resid; in fc_fcp_resp()
919 fsp->status_code = FC_ERROR; in fc_fcp_resp()
923 fsp->state |= FC_SRB_RCV_STATUS; in fc_fcp_resp()
928 if (unlikely(fsp->cdb_status == SAM_STAT_GOOD && in fc_fcp_resp()
929 fsp->xfer_len != expected_len)) { in fc_fcp_resp()
930 if (fsp->xfer_len < expected_len) { in fc_fcp_resp()
936 if (fsp->lp->qfull) { in fc_fcp_resp()
938 fsp->rport->port_id); in fc_fcp_resp()
943 fsp->rport->port_id, in fc_fcp_resp()
944 fsp->xfer_len, expected_len, fsp->data_len); in fc_fcp_resp()
948 fsp->status_code = FC_DATA_OVRRUN; in fc_fcp_resp()
951 fsp->rport->port_id, in fc_fcp_resp()
952 fsp->xfer_len, expected_len, fsp->data_len); in fc_fcp_resp()
961 fsp->status_code = FC_ERROR; in fc_fcp_resp()
966 * fc_fcp_complete_locked() - Complete processing of a fcp_pkt with the
975 struct fc_lport *lport = fsp->lp; in fc_fcp_complete_locked()
980 if (fsp->state & FC_SRB_ABORT_PENDING) in fc_fcp_complete_locked()
983 if (fsp->state & FC_SRB_ABORTED) { in fc_fcp_complete_locked()
984 if (!fsp->status_code) in fc_fcp_complete_locked()
985 fsp->status_code = FC_CMD_ABORTED; in fc_fcp_complete_locked()
991 if (fsp->cdb_status == SAM_STAT_GOOD && in fc_fcp_complete_locked()
992 fsp->xfer_len < fsp->data_len && !fsp->io_status && in fc_fcp_complete_locked()
993 (!(fsp->scsi_comp_flags & FCP_RESID_UNDER) || in fc_fcp_complete_locked()
994 fsp->xfer_len < fsp->data_len - fsp->scsi_resid)) { in fc_fcp_complete_locked()
996 fsp->xfer_len, fsp->data_len); in fc_fcp_complete_locked()
997 fsp->status_code = FC_DATA_UNDRUN; in fc_fcp_complete_locked()
1001 seq = fsp->seq_ptr; in fc_fcp_complete_locked()
1003 fsp->seq_ptr = NULL; in fc_fcp_complete_locked()
1004 if (unlikely(fsp->scsi_comp_flags & FCP_CONF_REQ)) { in fc_fcp_complete_locked()
1009 conf_frame = fc_fcp_frame_alloc(fsp->lp, 0); in fc_fcp_complete_locked()
1015 ep->did, ep->sid, in fc_fcp_complete_locked()
1027 if (fsp->cmd) in fc_fcp_complete_locked()
1032 * fc_fcp_cleanup_cmd() - Cancel the active exchange on a fcp_pkt
1038 if (fsp->seq_ptr) { in fc_fcp_cleanup_cmd()
1039 fc_exch_done(fsp->seq_ptr); in fc_fcp_cleanup_cmd()
1040 fsp->seq_ptr = NULL; in fc_fcp_cleanup_cmd()
1042 fsp->status_code = error; in fc_fcp_cleanup_cmd()
1046 * fc_fcp_cleanup_each_cmd() - Cancel all exchanges on a local port
1052 * If lun or id is -1, they are ignored.
1062 spin_lock_irqsave(&si->scsi_queue_lock, flags); in fc_fcp_cleanup_each_cmd()
1064 list_for_each_entry(fsp, &si->scsi_pkt_queue, list) { in fc_fcp_cleanup_each_cmd()
1065 sc_cmd = fsp->cmd; in fc_fcp_cleanup_each_cmd()
1066 if (id != -1 && scmd_id(sc_cmd) != id) in fc_fcp_cleanup_each_cmd()
1069 if (lun != -1 && sc_cmd->device->lun != lun) in fc_fcp_cleanup_each_cmd()
1073 spin_unlock_irqrestore(&si->scsi_queue_lock, flags); in fc_fcp_cleanup_each_cmd()
1075 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_fcp_cleanup_each_cmd()
1076 if (!(fsp->state & FC_SRB_COMPL)) { in fc_fcp_cleanup_each_cmd()
1077 fsp->state |= FC_SRB_COMPL; in fc_fcp_cleanup_each_cmd()
1087 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_fcp_cleanup_each_cmd()
1091 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_fcp_cleanup_each_cmd()
1094 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_fcp_cleanup_each_cmd()
1097 spin_lock_irqsave(&si->scsi_queue_lock, flags); in fc_fcp_cleanup_each_cmd()
1104 spin_unlock_irqrestore(&si->scsi_queue_lock, flags); in fc_fcp_cleanup_each_cmd()
1108 * fc_fcp_abort_io() - Abort all FCP-SCSI exchanges on a local port
1113 fc_fcp_cleanup_each_cmd(lport, -1, -1, FC_HRD_ERROR); in fc_fcp_abort_io()
1117 * fc_fcp_pkt_send() - Send a fcp_pkt
1121 * Return: Zero for success and -1 for failure
1130 libfc_priv(fsp->cmd)->fsp = fsp; in fc_fcp_pkt_send()
1131 fsp->cdb_cmd.fc_dl = htonl(fsp->data_len); in fc_fcp_pkt_send()
1132 fsp->cdb_cmd.fc_flags = fsp->req_flags & ~FCP_CFL_LEN_MASK; in fc_fcp_pkt_send()
1134 int_to_scsilun(fsp->cmd->device->lun, &fsp->cdb_cmd.fc_lun); in fc_fcp_pkt_send()
1135 memcpy(fsp->cdb_cmd.fc_cdb, fsp->cmd->cmnd, fsp->cmd->cmd_len); in fc_fcp_pkt_send()
1137 spin_lock_irqsave(&si->scsi_queue_lock, flags); in fc_fcp_pkt_send()
1138 list_add_tail(&fsp->list, &si->scsi_pkt_queue); in fc_fcp_pkt_send()
1139 spin_unlock_irqrestore(&si->scsi_queue_lock, flags); in fc_fcp_pkt_send()
1140 rc = lport->tt.fcp_cmd_send(lport, fsp, fc_fcp_recv); in fc_fcp_pkt_send()
1142 spin_lock_irqsave(&si->scsi_queue_lock, flags); in fc_fcp_pkt_send()
1143 libfc_priv(fsp->cmd)->fsp = NULL; in fc_fcp_pkt_send()
1144 list_del(&fsp->list); in fc_fcp_pkt_send()
1145 spin_unlock_irqrestore(&si->scsi_queue_lock, flags); in fc_fcp_pkt_send()
1152 * fc_fcp_cmd_send() - Send a FCP command
1166 const size_t len = sizeof(fsp->cdb_cmd); in fc_fcp_cmd_send()
1172 fp = fc_fcp_frame_alloc(lport, sizeof(fsp->cdb_cmd)); in fc_fcp_cmd_send()
1174 rc = -1; in fc_fcp_cmd_send()
1178 memcpy(fc_frame_payload_get(fp, len), &fsp->cdb_cmd, len); in fc_fcp_cmd_send()
1180 rport = fsp->rport; in fc_fcp_cmd_send()
1181 fsp->max_payload = rport->maxframe_size; in fc_fcp_cmd_send()
1182 rpriv = rport->dd_data; in fc_fcp_cmd_send()
1184 fc_fill_fc_hdr(fp, FC_RCTL_DD_UNSOL_CMD, rport->port_id, in fc_fcp_cmd_send()
1185 rpriv->local_port->port_id, FC_TYPE_FCP, in fc_fcp_cmd_send()
1190 rc = -1; in fc_fcp_cmd_send()
1193 fsp->seq_ptr = seq; in fc_fcp_cmd_send()
1196 fsp->timer.function = fc_fcp_timeout; in fc_fcp_cmd_send()
1197 if (rpriv->flags & FC_RP_FLAGS_REC_SUPPORTED) in fc_fcp_cmd_send()
1206 * fc_fcp_error() - Handler for FCP layer errors
1217 if (error == -FC_EX_CLOSED) { in fc_fcp_error()
1226 fsp->state &= ~FC_SRB_ABORT_PENDING; in fc_fcp_error()
1227 fsp->status_code = FC_CMD_PLOGO; in fc_fcp_error()
1234 * fc_fcp_pkt_abort() - Abort a fcp_pkt
1244 FC_FCP_DBG(fsp, "pkt abort state %x\n", fsp->state); in fc_fcp_pkt_abort()
1250 if (fsp->state & FC_SRB_ABORTED) { in fc_fcp_pkt_abort()
1255 init_completion(&fsp->tm_done); in fc_fcp_pkt_abort()
1256 fsp->wait_for_comp = 1; in fc_fcp_pkt_abort()
1258 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_fcp_pkt_abort()
1259 ticks_left = wait_for_completion_timeout(&fsp->tm_done, in fc_fcp_pkt_abort()
1261 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_fcp_pkt_abort()
1262 fsp->wait_for_comp = 0; in fc_fcp_pkt_abort()
1266 } else if (fsp->state & FC_SRB_ABORTED) { in fc_fcp_pkt_abort()
1276 * fc_lun_reset_send() - Send LUN reset command
1282 struct fc_lport *lport = fsp->lp; in fc_lun_reset_send()
1284 if (lport->tt.fcp_cmd_send(lport, fsp, fc_tm_done)) { in fc_lun_reset_send()
1285 if (fsp->recov_retry++ >= FC_MAX_RECOV_RETRY) in fc_lun_reset_send()
1289 fsp->timer.function = fc_lun_reset_send; in fc_lun_reset_send()
1296 * fc_lun_reset() - Send a LUN RESET command to a device
1308 fsp->cdb_cmd.fc_dl = htonl(fsp->data_len); in fc_lun_reset()
1309 fsp->cdb_cmd.fc_tm_flags = FCP_TMF_LUN_RESET; in fc_lun_reset()
1310 int_to_scsilun(lun, &fsp->cdb_cmd.fc_lun); in fc_lun_reset()
1312 fsp->wait_for_comp = 1; in fc_lun_reset()
1313 init_completion(&fsp->tm_done); in fc_lun_reset()
1315 fc_lun_reset_send(&fsp->timer); in fc_lun_reset()
1321 rc = wait_for_completion_timeout(&fsp->tm_done, FC_SCSI_TM_TOV); in fc_lun_reset()
1323 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_lun_reset()
1324 fsp->state |= FC_SRB_COMPL; in fc_lun_reset()
1325 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_lun_reset()
1327 del_timer_sync(&fsp->timer); in fc_lun_reset()
1329 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_lun_reset()
1330 if (fsp->seq_ptr) { in fc_lun_reset()
1331 fc_exch_done(fsp->seq_ptr); in fc_lun_reset()
1332 fsp->seq_ptr = NULL; in fc_lun_reset()
1334 fsp->wait_for_comp = 0; in fc_lun_reset()
1335 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_lun_reset()
1343 if (fsp->cdb_status != FCP_TMF_CMPL) in fc_lun_reset()
1352 * fc_tm_done() - Task Management response handler
1367 * scsi-eh will escalate for when either happens. in fc_tm_done()
1378 if (!fsp->seq_ptr || !fsp->wait_for_comp) in fc_tm_done()
1382 if (fh->fh_type != FC_TYPE_BLS) in fc_tm_done()
1384 fsp->seq_ptr = NULL; in fc_tm_done()
1393 * fc_fcp_cleanup() - Cleanup all FCP exchanges on a local port
1398 fc_fcp_cleanup_each_cmd(lport, -1, -1, FC_ERROR); in fc_fcp_cleanup()
1402 * fc_fcp_timeout() - Handler for fcp_pkt timeouts
1415 struct fc_rport *rport = fsp->rport; in fc_fcp_timeout()
1416 struct fc_rport_libfc_priv *rpriv = rport->dd_data; in fc_fcp_timeout()
1421 if (fsp->cdb_cmd.fc_tm_flags) in fc_fcp_timeout()
1424 if (fsp->lp->qfull) { in fc_fcp_timeout()
1426 fsp->timer_delay); in fc_fcp_timeout()
1427 fsp->timer.function = fc_fcp_timeout; in fc_fcp_timeout()
1428 fc_fcp_timer_set(fsp, fsp->timer_delay); in fc_fcp_timeout()
1432 fsp->timer_delay, rpriv->flags, fsp->state); in fc_fcp_timeout()
1433 fsp->state |= FC_SRB_FCP_PROCESSING_TMO; in fc_fcp_timeout()
1435 if (rpriv->flags & FC_RP_FLAGS_REC_SUPPORTED) in fc_fcp_timeout()
1437 else if (fsp->state & FC_SRB_RCV_STATUS) in fc_fcp_timeout()
1441 fsp->state &= ~FC_SRB_FCP_PROCESSING_TMO; in fc_fcp_timeout()
1447 * fc_fcp_rec() - Send a REC ELS request
1457 lport = fsp->lp; in fc_fcp_rec()
1458 rport = fsp->rport; in fc_fcp_rec()
1459 rpriv = rport->dd_data; in fc_fcp_rec()
1460 if (!fsp->seq_ptr || rpriv->rp_state != RPORT_ST_READY) { in fc_fcp_rec()
1461 fsp->status_code = FC_HRD_ERROR; in fc_fcp_rec()
1462 fsp->io_status = 0; in fc_fcp_rec()
1471 fr_seq(fp) = fsp->seq_ptr; in fc_fcp_rec()
1472 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rport->port_id, in fc_fcp_rec()
1473 rpriv->local_port->port_id, FC_TYPE_ELS, in fc_fcp_rec()
1475 if (lport->tt.elsct_send(lport, rport->port_id, fp, ELS_REC, in fc_fcp_rec()
1477 2 * lport->r_a_tov)) { in fc_fcp_rec()
1482 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) in fc_fcp_rec()
1489 * fc_fcp_rec_resp() - Handler for REC ELS responses
1519 fsp->recov_retry = 0; in fc_fcp_rec_resp()
1523 switch (rjt->er_reason) { in fc_fcp_rec_resp()
1527 fsp->rport->port_id, rjt->er_reason, in fc_fcp_rec_resp()
1528 rjt->er_explan); in fc_fcp_rec_resp()
1532 rpriv = fsp->rport->dd_data; in fc_fcp_rec_resp()
1538 rpriv->flags &= ~FC_RP_FLAGS_REC_SUPPORTED; in fc_fcp_rec_resp()
1543 fsp->rport->port_id, rjt->er_reason, in fc_fcp_rec_resp()
1544 rjt->er_explan); in fc_fcp_rec_resp()
1551 if (rjt->er_explan == ELS_EXPL_OXID_RXID) { in fc_fcp_rec_resp()
1552 struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr); in fc_fcp_rec_resp()
1553 ep->state |= FC_EX_QUARANTINE; in fc_fcp_rec_resp()
1554 fsp->state |= FC_SRB_ABORTED; in fc_fcp_rec_resp()
1562 if (fsp->state & FC_SRB_ABORTED) in fc_fcp_rec_resp()
1565 data_dir = fsp->cmd->sc_data_direction; in fc_fcp_rec_resp()
1567 offset = ntohl(recp->reca_fc4value); in fc_fcp_rec_resp()
1568 e_stat = ntohl(recp->reca_e_stat); in fc_fcp_rec_resp()
1584 * Recovery via SRR relies on in-order-delivery. in fc_fcp_rec_resp()
1588 } else if (fsp->xfer_contig_end == offset) { in fc_fcp_rec_resp()
1591 offset = fsp->xfer_contig_end; in fc_fcp_rec_resp()
1621 if (offset < fsp->data_len) in fc_fcp_rec_resp()
1623 } else if (offset == fsp->xfer_contig_end) { in fc_fcp_rec_resp()
1625 } else if (fsp->xfer_contig_end < offset) { in fc_fcp_rec_resp()
1626 offset = fsp->xfer_contig_end; in fc_fcp_rec_resp()
1639 * fc_fcp_rec_error() - Handler for REC errors
1651 case -FC_EX_CLOSED: in fc_fcp_rec_error()
1653 fsp, fsp->rport->port_id); in fc_fcp_rec_error()
1659 fsp, fsp->rport->port_id, error); in fc_fcp_rec_error()
1660 fsp->status_code = FC_CMD_PLOGO; in fc_fcp_rec_error()
1663 case -FC_EX_TIMEOUT: in fc_fcp_rec_error()
1669 fsp, fsp->rport->port_id, fsp->recov_retry, in fc_fcp_rec_error()
1671 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) in fc_fcp_rec_error()
1683 * fc_fcp_recovery() - Handler for fcp_pkt recovery
1690 fsp->status_code = code; in fc_fcp_recovery()
1691 fsp->cdb_status = 0; in fc_fcp_recovery()
1692 fsp->io_status = 0; in fc_fcp_recovery()
1695 * scsi-ml escalate. in fc_fcp_recovery()
1701 * fc_fcp_srr() - Send a SRR request (Sequence Retransmission Request)
1710 struct fc_lport *lport = fsp->lp; in fc_fcp_srr()
1713 struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr); in fc_fcp_srr()
1718 rport = fsp->rport; in fc_fcp_srr()
1719 rpriv = rport->dd_data; in fc_fcp_srr()
1721 if (!(rpriv->flags & FC_RP_FLAGS_RETRY) || in fc_fcp_srr()
1722 rpriv->rp_state != RPORT_ST_READY) in fc_fcp_srr()
1730 srr->srr_op = ELS_SRR; in fc_fcp_srr()
1731 srr->srr_ox_id = htons(ep->oxid); in fc_fcp_srr()
1732 srr->srr_rx_id = htons(ep->rxid); in fc_fcp_srr()
1733 srr->srr_r_ctl = r_ctl; in fc_fcp_srr()
1734 srr->srr_rel_off = htonl(offset); in fc_fcp_srr()
1736 fc_fill_fc_hdr(fp, FC_RCTL_ELS4_REQ, rport->port_id, in fc_fcp_srr()
1737 rpriv->local_port->port_id, FC_TYPE_FCP, in fc_fcp_srr()
1746 fsp->recov_seq = seq; in fc_fcp_srr()
1747 fsp->xfer_len = offset; in fc_fcp_srr()
1748 fsp->xfer_contig_end = offset; in fc_fcp_srr()
1749 fsp->state &= ~FC_SRB_RCV_STATUS; in fc_fcp_srr()
1757 * fc_fcp_srr_resp() - Handler for SRR response
1778 * the ep. But if fc_fcp_srr_error had got -FC_EX_TIMEOUT, in fc_fcp_srr_resp()
1783 if (fh->fh_type == FC_TYPE_BLS) { in fc_fcp_srr_resp()
1790 fsp->recov_retry = 0; in fc_fcp_srr_resp()
1805 * fc_fcp_srr_error() - Handler for SRR errors
1814 case -FC_EX_TIMEOUT: in fc_fcp_srr_error()
1815 FC_FCP_DBG(fsp, "SRR timeout, retries %d\n", fsp->recov_retry); in fc_fcp_srr_error()
1816 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) in fc_fcp_srr_error()
1821 case -FC_EX_CLOSED: /* e.g., link failure */ in fc_fcp_srr_error()
1830 fc_exch_done(fsp->recov_seq); in fc_fcp_srr_error()
1834 * fc_fcp_lport_queue_ready() - Determine if the lport and it's queue is ready
1840 return (lport->state == LPORT_ST_READY) && in fc_fcp_lport_queue_ready()
1841 lport->link_up && !lport->qfull; in fc_fcp_lport_queue_ready()
1845 * fc_queuecommand() - The queuecommand function of the SCSI template
1854 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); in fc_queuecommand()
1861 sc_cmd->result = rval; in fc_queuecommand()
1866 if (!*(struct fc_remote_port **)rport->dd_data) { in fc_queuecommand()
1871 sc_cmd->result = DID_IMM_RETRY << 16; in fc_queuecommand()
1877 if (lport->qfull) { in fc_queuecommand()
1879 shost_printk(KERN_ERR, lport->host, in fc_queuecommand()
1882 lport->host->can_queue); in fc_queuecommand()
1897 fsp->cmd = sc_cmd; /* save the cmd */ in fc_queuecommand()
1898 fsp->rport = rport; /* set the remote port ptr */ in fc_queuecommand()
1903 fsp->data_len = scsi_bufflen(sc_cmd); in fc_queuecommand()
1904 fsp->xfer_len = 0; in fc_queuecommand()
1909 if (sc_cmd->sc_data_direction == DMA_FROM_DEVICE) { in fc_queuecommand()
1910 fsp->req_flags = FC_SRB_READ; in fc_queuecommand()
1911 this_cpu_inc(lport->stats->InputRequests); in fc_queuecommand()
1912 this_cpu_add(lport->stats->InputBytes, fsp->data_len); in fc_queuecommand()
1913 } else if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) { in fc_queuecommand()
1914 fsp->req_flags = FC_SRB_WRITE; in fc_queuecommand()
1915 this_cpu_inc(lport->stats->OutputRequests); in fc_queuecommand()
1916 this_cpu_add(lport->stats->OutputBytes, fsp->data_len); in fc_queuecommand()
1918 fsp->req_flags = 0; in fc_queuecommand()
1919 this_cpu_inc(lport->stats->ControlRequests); in fc_queuecommand()
1924 * if we get -1 return then put the request in the pending in fc_queuecommand()
1929 fsp->state = FC_SRB_FREE; in fc_queuecommand()
1939 * fc_io_compl() - Handle responses for completed commands
1955 fsp->state |= FC_SRB_COMPL; in fc_io_compl()
1956 if (!(fsp->state & FC_SRB_FCP_PROCESSING_TMO)) { in fc_io_compl()
1957 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_io_compl()
1958 del_timer_sync(&fsp->timer); in fc_io_compl()
1959 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_io_compl()
1962 lport = fsp->lp; in fc_io_compl()
1969 if (si->last_can_queue_ramp_down_time) in fc_io_compl()
1972 sc_cmd = fsp->cmd; in fc_io_compl()
1973 libfc_priv(sc_cmd)->status = fsp->cdb_status; in fc_io_compl()
1974 switch (fsp->status_code) { in fc_io_compl()
1976 if (fsp->cdb_status == 0) { in fc_io_compl()
1980 sc_cmd->result = DID_OK << 16; in fc_io_compl()
1981 if (fsp->scsi_resid) in fc_io_compl()
1982 libfc_priv(sc_cmd)->resid_len = fsp->scsi_resid; in fc_io_compl()
1988 sc_cmd->result = (DID_OK << 16) | fsp->cdb_status; in fc_io_compl()
1992 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " in fc_io_compl()
1994 sc_cmd->result = DID_ERROR << 16; in fc_io_compl()
1997 if ((fsp->cdb_status == 0) && !(fsp->req_flags & FC_SRB_READ)) { in fc_io_compl()
2002 if (fsp->state & FC_SRB_RCV_STATUS) { in fc_io_compl()
2003 sc_cmd->result = DID_OK << 16; in fc_io_compl()
2005 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml" in fc_io_compl()
2007 sc_cmd->result = DID_ERROR << 16; in fc_io_compl()
2013 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " in fc_io_compl()
2015 libfc_priv(sc_cmd)->resid_len = fsp->scsi_resid; in fc_io_compl()
2016 sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status; in fc_io_compl()
2023 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " in fc_io_compl()
2025 sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status; in fc_io_compl()
2028 if (host_byte(sc_cmd->result) == DID_TIME_OUT) in fc_io_compl()
2029 FC_FCP_DBG(fsp, "Returning DID_TIME_OUT to scsi-ml " in fc_io_compl()
2032 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " in fc_io_compl()
2036 sc_cmd->result |= fsp->io_status; in fc_io_compl()
2039 FC_FCP_DBG(fsp, "Returning DID_RESET to scsi-ml " in fc_io_compl()
2041 sc_cmd->result = (DID_RESET << 16); in fc_io_compl()
2044 FC_FCP_DBG(fsp, "Returning DID_SOFT_ERROR to scsi-ml " in fc_io_compl()
2046 sc_cmd->result = (DID_SOFT_ERROR << 16); in fc_io_compl()
2049 FC_FCP_DBG(fsp, "Returning DID_NO_CONNECT to scsi-ml " in fc_io_compl()
2051 sc_cmd->result = (DID_NO_CONNECT << 16); in fc_io_compl()
2054 FC_FCP_DBG(fsp, "Returning DID_PARITY to scsi-ml " in fc_io_compl()
2056 sc_cmd->result = (DID_PARITY << 16); in fc_io_compl()
2059 FC_FCP_DBG(fsp, "Returning DID_BUS_BUSY to scsi-ml " in fc_io_compl()
2061 sc_cmd->result = (DID_BUS_BUSY << 16) | fsp->io_status; in fc_io_compl()
2064 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " in fc_io_compl()
2066 sc_cmd->result = (DID_ERROR << 16); in fc_io_compl()
2070 if (lport->state != LPORT_ST_READY && fsp->status_code != FC_COMPLETE) in fc_io_compl()
2071 sc_cmd->result = (DID_TRANSPORT_DISRUPTED << 16); in fc_io_compl()
2073 spin_lock_irqsave(&si->scsi_queue_lock, flags); in fc_io_compl()
2074 list_del(&fsp->list); in fc_io_compl()
2075 libfc_priv(sc_cmd)->fsp = NULL; in fc_io_compl()
2076 spin_unlock_irqrestore(&si->scsi_queue_lock, flags); in fc_io_compl()
2084 * fc_eh_abort() - Abort a command
2103 lport = shost_priv(sc_cmd->device->host); in fc_eh_abort()
2104 if (lport->state != LPORT_ST_READY) in fc_eh_abort()
2106 else if (!lport->link_up) in fc_eh_abort()
2110 spin_lock_irqsave(&si->scsi_queue_lock, flags); in fc_eh_abort()
2111 fsp = libfc_priv(sc_cmd)->fsp; in fc_eh_abort()
2114 spin_unlock_irqrestore(&si->scsi_queue_lock, flags); in fc_eh_abort()
2119 spin_unlock_irqrestore(&si->scsi_queue_lock, flags); in fc_eh_abort()
2137 * fc_eh_device_reset() - Reset a single LUN
2147 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); in fc_eh_device_reset()
2155 lport = shost_priv(sc_cmd->device->host); in fc_eh_device_reset()
2157 if (lport->state != LPORT_ST_READY) in fc_eh_device_reset()
2160 FC_SCSI_DBG(lport, "Resetting rport (%6.6x)\n", rport->port_id); in fc_eh_device_reset()
2173 fsp->rport = rport; /* set the remote port ptr */ in fc_eh_device_reset()
2178 rc = fc_lun_reset(lport, fsp, scmd_id(sc_cmd), sc_cmd->device->lun); in fc_eh_device_reset()
2179 fsp->state = FC_SRB_FREE; in fc_eh_device_reset()
2188 * fc_eh_host_reset() - Reset a Scsi_Host.
2193 struct Scsi_Host *shost = sc_cmd->device->host; in fc_eh_host_reset()
2207 "on port (%6.6x)\n", lport->port_id); in fc_eh_host_reset()
2212 lport->port_id); in fc_eh_host_reset()
2219 * fc_slave_alloc() - Configure the queue depth of a Scsi_Host
2230 return -ENXIO; in fc_slave_alloc()
2238 * fc_fcp_destroy() - Tear down the FCP layer for a given local port
2245 if (!list_empty(&si->scsi_pkt_queue)) in fc_fcp_destroy()
2247 "port (%6.6x)\n", lport->port_id); in fc_fcp_destroy()
2249 mempool_destroy(si->scsi_pkt_pool); in fc_fcp_destroy()
2251 lport->scsi_priv = NULL; in fc_fcp_destroy()
2265 rc = -ENOMEM; in fc_setup_fcp()
2277 * fc_fcp_init() - Initialize the FCP layer for a local port
2285 if (!lport->tt.fcp_cmd_send) in fc_fcp_init()
2286 lport->tt.fcp_cmd_send = fc_fcp_cmd_send; in fc_fcp_init()
2288 if (!lport->tt.fcp_cleanup) in fc_fcp_init()
2289 lport->tt.fcp_cleanup = fc_fcp_cleanup; in fc_fcp_init()
2291 if (!lport->tt.fcp_abort_io) in fc_fcp_init()
2292 lport->tt.fcp_abort_io = fc_fcp_abort_io; in fc_fcp_init()
2296 return -ENOMEM; in fc_fcp_init()
2297 lport->scsi_priv = si; in fc_fcp_init()
2298 si->max_can_queue = lport->host->can_queue; in fc_fcp_init()
2299 INIT_LIST_HEAD(&si->scsi_pkt_queue); in fc_fcp_init()
2300 spin_lock_init(&si->scsi_queue_lock); in fc_fcp_init()
2302 si->scsi_pkt_pool = mempool_create_slab_pool(2, scsi_pkt_cachep); in fc_fcp_init()
2303 if (!si->scsi_pkt_pool) { in fc_fcp_init()
2304 rc = -ENOMEM; in fc_fcp_init()