Lines Matching refs:fsp

134 	struct fc_fcp_pkt *fsp;  in fc_fcp_pkt_alloc()  local
136 fsp = mempool_alloc(si->scsi_pkt_pool, gfp); in fc_fcp_pkt_alloc()
137 if (fsp) { in fc_fcp_pkt_alloc()
138 memset(fsp, 0, sizeof(*fsp)); 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()
148 return fsp; in fc_fcp_pkt_alloc()
158 static void fc_fcp_pkt_release(struct fc_fcp_pkt *fsp) in fc_fcp_pkt_release() argument
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()
171 static void fc_fcp_pkt_hold(struct fc_fcp_pkt *fsp) in fc_fcp_pkt_hold() argument
173 refcount_inc(&fsp->ref_cnt); in fc_fcp_pkt_hold()
187 static void fc_fcp_pkt_destroy(struct fc_seq *seq, void *fsp) in fc_fcp_pkt_destroy() argument
189 fc_fcp_pkt_release(fsp); in fc_fcp_pkt_destroy()
209 static inline int fc_fcp_lock_pkt(struct fc_fcp_pkt *fsp) in fc_fcp_lock_pkt() argument
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()
217 fc_fcp_pkt_hold(fsp); in fc_fcp_lock_pkt()
226 static inline void fc_fcp_unlock_pkt(struct fc_fcp_pkt *fsp) in fc_fcp_unlock_pkt() argument
228 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_fcp_unlock_pkt()
229 fc_fcp_pkt_release(fsp); in fc_fcp_unlock_pkt()
237 static void fc_fcp_timer_set(struct fc_fcp_pkt *fsp, unsigned long delay) in fc_fcp_timer_set() argument
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()
245 static void fc_fcp_abort_done(struct fc_fcp_pkt *fsp) in fc_fcp_abort_done() argument
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()
253 fc_fcp_complete_locked(fsp); in fc_fcp_abort_done()
261 static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp) in fc_fcp_send_abort() argument
265 if (!fsp->seq_ptr) in fc_fcp_send_abort()
268 if (fsp->state & FC_SRB_ABORT_PENDING) { in fc_fcp_send_abort()
269 FC_FCP_DBG(fsp, "abort already pending\n"); in fc_fcp_send_abort()
273 this_cpu_inc(fsp->lp->stats->FcpPktAborts); in fc_fcp_send_abort()
275 fsp->state |= FC_SRB_ABORT_PENDING; in fc_fcp_send_abort()
276 rc = fc_seq_exch_abort(fsp->seq_ptr, 0); in fc_fcp_send_abort()
282 fc_fcp_abort_done(fsp); in fc_fcp_send_abort()
298 static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp, int status_code) in fc_fcp_retry_cmd() argument
300 if (fsp->seq_ptr) { in fc_fcp_retry_cmd()
301 fc_exch_done(fsp->seq_ptr); in fc_fcp_retry_cmd()
302 fsp->seq_ptr = NULL; in fc_fcp_retry_cmd()
305 fsp->state &= ~FC_SRB_ABORT_PENDING; in fc_fcp_retry_cmd()
306 fsp->io_status = 0; in fc_fcp_retry_cmd()
307 fsp->status_code = status_code; in fc_fcp_retry_cmd()
308 fc_fcp_complete_locked(fsp); in fc_fcp_retry_cmd()
316 void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid) in fc_fcp_ddp_setup() argument
320 lport = fsp->lp; in fc_fcp_ddp_setup()
321 if ((fsp->req_flags & FC_SRB_READ) && in fc_fcp_ddp_setup()
323 if (lport->tt.ddp_setup(lport, xid, scsi_sglist(fsp->cmd), in fc_fcp_ddp_setup()
324 scsi_sg_count(fsp->cmd))) in fc_fcp_ddp_setup()
325 fsp->xfer_ddp = xid; in fc_fcp_ddp_setup()
334 void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp) in fc_fcp_ddp_done() argument
338 if (!fsp) in fc_fcp_ddp_done()
341 if (fsp->xfer_ddp == FC_XID_UNKNOWN) in fc_fcp_ddp_done()
344 lport = fsp->lp; in fc_fcp_ddp_done()
346 fsp->xfer_len = lport->tt.ddp_done(lport, fsp->xfer_ddp); in fc_fcp_ddp_done()
347 fsp->xfer_ddp = FC_XID_UNKNOWN; in fc_fcp_ddp_done()
457 static inline unsigned int get_fsp_rec_tov(struct fc_fcp_pkt *fsp) in get_fsp_rec_tov() argument
459 struct fc_rport_libfc_priv *rpriv = fsp->rport->dd_data; in get_fsp_rec_tov()
472 static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) in fc_fcp_recv_data() argument
474 struct scsi_cmnd *sc = fsp->cmd; in fc_fcp_recv_data()
475 struct fc_lport *lport = fsp->lp; in fc_fcp_recv_data()
500 if (fsp->xfer_ddp != FC_XID_UNKNOWN) { in fc_fcp_recv_data()
501 fc_fcp_ddp_done(fsp); in fc_fcp_recv_data()
502 FC_FCP_DBG(fsp, "DDP I/O in fc_fcp_recv_data set ERROR\n"); in fc_fcp_recv_data()
506 if (offset + len > fsp->data_len) { in fc_fcp_recv_data()
511 FC_FCP_DBG(fsp, "data received past end. len %zx offset %zx " in fc_fcp_recv_data()
512 "data_len %x\n", len, offset, fsp->data_len); in fc_fcp_recv_data()
518 if (offset != fsp->xfer_len) in fc_fcp_recv_data()
519 fsp->state |= FC_SRB_DISCONTIG; in fc_fcp_recv_data()
550 if (fsp->state & FC_SRB_DISCONTIG) { in fc_fcp_recv_data()
558 if (fsp->xfer_contig_end == start_offset) in fc_fcp_recv_data()
559 fsp->xfer_contig_end += copy_len; in fc_fcp_recv_data()
560 fsp->xfer_len += copy_len; in fc_fcp_recv_data()
566 if (unlikely(fsp->state & FC_SRB_RCV_STATUS) && in fc_fcp_recv_data()
567 fsp->xfer_len == fsp->data_len - fsp->scsi_resid) { in fc_fcp_recv_data()
568 FC_FCP_DBG( fsp, "complete out-of-order sequence\n" ); in fc_fcp_recv_data()
569 fc_fcp_complete_locked(fsp); in fc_fcp_recv_data()
573 fc_fcp_recovery(fsp, host_bcode); in fc_fcp_recv_data()
589 static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, in fc_fcp_send_data() argument
596 struct fc_lport *lport = fsp->lp; in fc_fcp_send_data()
611 if (unlikely(offset + seq_blen > fsp->data_len)) { in fc_fcp_send_data()
613 FC_FCP_DBG(fsp, "xfer-ready past end. seq_blen %zx " in fc_fcp_send_data()
615 fc_fcp_send_abort(fsp); in fc_fcp_send_data()
617 } else if (offset != fsp->xfer_len) { in fc_fcp_send_data()
619 FC_FCP_DBG(fsp, "xfer-ready non-contiguous. " in fc_fcp_send_data()
628 t_blen = fsp->max_payload; in fc_fcp_send_data()
631 FC_FCP_DBG(fsp, "fsp=%p:lso:blen=%zx lso_max=0x%x t_blen=%zx\n", in fc_fcp_send_data()
632 fsp, seq_blen, lport->lso_max, t_blen); in fc_fcp_send_data()
637 sc = fsp->cmd; in fc_fcp_send_data()
670 fr_max_payload(fp) = fsp->max_payload; in fc_fcp_send_data()
727 fsp->xfer_len += seq_blen; /* premature count? */ in fc_fcp_send_data()
736 static void fc_fcp_abts_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) in fc_fcp_abts_resp() argument
761 fc_fcp_abort_done(fsp); in fc_fcp_abts_resp()
775 struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)arg; in fc_fcp_recv() local
776 struct fc_lport *lport = fsp->lp; in fc_fcp_recv()
783 fc_fcp_error(fsp, fp); in fc_fcp_recv()
791 FC_FCP_DBG(fsp, "lport state %d, ignoring r_ctl %x\n", in fc_fcp_recv()
795 if (fc_fcp_lock_pkt(fsp)) in fc_fcp_recv()
799 fc_fcp_abts_resp(fsp, fp); in fc_fcp_recv()
803 if (fsp->state & (FC_SRB_ABORTED | FC_SRB_ABORT_PENDING)) { in fc_fcp_recv()
804 FC_FCP_DBG(fsp, "command aborted, ignoring r_ctl %x\n", r_ctl); in fc_fcp_recv()
817 rc = fc_fcp_send_data(fsp, seq, in fc_fcp_recv()
821 seq->rec_data = fsp->xfer_len; in fc_fcp_recv()
828 fc_fcp_recv_data(fsp, fp); in fc_fcp_recv()
829 seq->rec_data = fsp->xfer_contig_end; in fc_fcp_recv()
833 fc_fcp_resp(fsp, fp); in fc_fcp_recv()
835 FC_FCP_DBG(fsp, "unexpected frame. r_ctl %x\n", r_ctl); in fc_fcp_recv()
838 fc_fcp_unlock_pkt(fsp); in fc_fcp_recv()
848 static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) in fc_fcp_resp() argument
866 fsp->cdb_status = fc_rp->fr_status; in fc_fcp_resp()
868 fsp->scsi_comp_flags = flags; in fc_fcp_resp()
869 expected_len = fsp->data_len; in fc_fcp_resp()
872 fc_fcp_ddp_done(fsp); in fc_fcp_resp()
885 if (fsp->wait_for_comp) { in fc_fcp_resp()
887 fsp->cdb_status = fc_rp_info->rsp_code; in fc_fcp_resp()
888 complete(&fsp->tm_done); in fc_fcp_resp()
900 memcpy(fsp->cmd->sense_buffer, in fc_fcp_resp()
908 fsp->scsi_resid = ntohl(rp_ex->fr_resid); in fc_fcp_resp()
919 (scsi_bufflen(fsp->cmd) - in fc_fcp_resp()
920 fsp->scsi_resid) < fsp->cmd->underflow) in fc_fcp_resp()
922 expected_len -= fsp->scsi_resid; in fc_fcp_resp()
924 fsp->status_code = FC_ERROR; in fc_fcp_resp()
928 fsp->state |= FC_SRB_RCV_STATUS; in fc_fcp_resp()
933 if (unlikely(fsp->cdb_status == SAM_STAT_GOOD && in fc_fcp_resp()
934 fsp->xfer_len != expected_len)) { in fc_fcp_resp()
935 if (fsp->xfer_len < expected_len) { in fc_fcp_resp()
941 if (fsp->lp->qfull) { in fc_fcp_resp()
942 FC_FCP_DBG(fsp, "tgt %6.6x queue busy retry\n", in fc_fcp_resp()
943 fsp->rport->port_id); in fc_fcp_resp()
946 FC_FCP_DBG(fsp, "tgt %6.6x xfer len %zx data underrun " in fc_fcp_resp()
948 fsp->rport->port_id, in fc_fcp_resp()
949 fsp->xfer_len, expected_len, fsp->data_len); in fc_fcp_resp()
950 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp)); in fc_fcp_resp()
953 fsp->status_code = FC_DATA_OVRRUN; in fc_fcp_resp()
954 FC_FCP_DBG(fsp, "tgt %6.6x xfer len %zx greater than expected, " in fc_fcp_resp()
956 fsp->rport->port_id, in fc_fcp_resp()
957 fsp->xfer_len, expected_len, fsp->data_len); in fc_fcp_resp()
959 fc_fcp_complete_locked(fsp); in fc_fcp_resp()
963 FC_FCP_DBG(fsp, "short FCP response. flags 0x%x len %u respl %u " in fc_fcp_resp()
966 fsp->status_code = FC_ERROR; in fc_fcp_resp()
967 fc_fcp_complete_locked(fsp); in fc_fcp_resp()
978 static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp) in fc_fcp_complete_locked() argument
980 struct fc_lport *lport = fsp->lp; in fc_fcp_complete_locked()
985 if (fsp->state & FC_SRB_ABORT_PENDING) in fc_fcp_complete_locked()
988 if (fsp->state & FC_SRB_ABORTED) { in fc_fcp_complete_locked()
989 if (!fsp->status_code) in fc_fcp_complete_locked()
990 fsp->status_code = FC_CMD_ABORTED; in fc_fcp_complete_locked()
996 if (fsp->cdb_status == SAM_STAT_GOOD && in fc_fcp_complete_locked()
997 fsp->xfer_len < fsp->data_len && !fsp->io_status && in fc_fcp_complete_locked()
998 (!(fsp->scsi_comp_flags & FCP_RESID_UNDER) || in fc_fcp_complete_locked()
999 fsp->xfer_len < fsp->data_len - fsp->scsi_resid)) { in fc_fcp_complete_locked()
1000 FC_FCP_DBG(fsp, "data underrun, xfer %zx data %x\n", in fc_fcp_complete_locked()
1001 fsp->xfer_len, fsp->data_len); in fc_fcp_complete_locked()
1002 fsp->status_code = FC_DATA_UNDRUN; in fc_fcp_complete_locked()
1006 seq = fsp->seq_ptr; in fc_fcp_complete_locked()
1008 fsp->seq_ptr = NULL; in fc_fcp_complete_locked()
1009 if (unlikely(fsp->scsi_comp_flags & FCP_CONF_REQ)) { in fc_fcp_complete_locked()
1014 conf_frame = fc_fcp_frame_alloc(fsp->lp, 0); in fc_fcp_complete_locked()
1032 if (fsp->cmd) in fc_fcp_complete_locked()
1033 fc_io_compl(fsp); in fc_fcp_complete_locked()
1041 static void fc_fcp_cleanup_cmd(struct fc_fcp_pkt *fsp, int error) in fc_fcp_cleanup_cmd() argument
1043 if (fsp->seq_ptr) { in fc_fcp_cleanup_cmd()
1044 fc_exch_done(fsp->seq_ptr); in fc_fcp_cleanup_cmd()
1045 fsp->seq_ptr = NULL; in fc_fcp_cleanup_cmd()
1047 fsp->status_code = error; in fc_fcp_cleanup_cmd()
1063 struct fc_fcp_pkt *fsp; in fc_fcp_cleanup_each_cmd() local
1069 list_for_each_entry(fsp, &si->scsi_pkt_queue, list) { in fc_fcp_cleanup_each_cmd()
1070 sc_cmd = fsp->cmd; in fc_fcp_cleanup_each_cmd()
1077 fc_fcp_pkt_hold(fsp); in fc_fcp_cleanup_each_cmd()
1080 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_fcp_cleanup_each_cmd()
1081 if (!(fsp->state & FC_SRB_COMPL)) { in fc_fcp_cleanup_each_cmd()
1082 fsp->state |= FC_SRB_COMPL; in fc_fcp_cleanup_each_cmd()
1092 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_fcp_cleanup_each_cmd()
1094 fc_fcp_cleanup_cmd(fsp, error); in fc_fcp_cleanup_each_cmd()
1096 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_fcp_cleanup_each_cmd()
1097 fc_io_compl(fsp); in fc_fcp_cleanup_each_cmd()
1099 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_fcp_cleanup_each_cmd()
1101 fc_fcp_pkt_release(fsp); in fc_fcp_cleanup_each_cmd()
1129 static int fc_fcp_pkt_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp) in fc_fcp_pkt_send() argument
1135 libfc_priv(fsp->cmd)->fsp = fsp; in fc_fcp_pkt_send()
1136 fsp->cdb_cmd.fc_dl = htonl(fsp->data_len); in fc_fcp_pkt_send()
1137 fsp->cdb_cmd.fc_flags = fsp->req_flags & ~FCP_CFL_LEN_MASK; in fc_fcp_pkt_send()
1139 int_to_scsilun(fsp->cmd->device->lun, &fsp->cdb_cmd.fc_lun); in fc_fcp_pkt_send()
1140 memcpy(fsp->cdb_cmd.fc_cdb, fsp->cmd->cmnd, fsp->cmd->cmd_len); in fc_fcp_pkt_send()
1143 list_add_tail(&fsp->list, &si->scsi_pkt_queue); in fc_fcp_pkt_send()
1145 rc = lport->tt.fcp_cmd_send(lport, fsp, fc_fcp_recv); in fc_fcp_pkt_send()
1148 libfc_priv(fsp->cmd)->fsp = NULL; in fc_fcp_pkt_send()
1149 list_del(&fsp->list); in fc_fcp_pkt_send()
1162 static int fc_fcp_cmd_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp, in fc_fcp_cmd_send() argument
1171 const size_t len = sizeof(fsp->cdb_cmd); in fc_fcp_cmd_send()
1174 if (fc_fcp_lock_pkt(fsp)) in fc_fcp_cmd_send()
1177 fp = fc_fcp_frame_alloc(lport, sizeof(fsp->cdb_cmd)); in fc_fcp_cmd_send()
1183 memcpy(fc_frame_payload_get(fp, len), &fsp->cdb_cmd, len); in fc_fcp_cmd_send()
1184 fr_fsp(fp) = fsp; in fc_fcp_cmd_send()
1185 rport = fsp->rport; in fc_fcp_cmd_send()
1186 fsp->max_payload = rport->maxframe_size; in fc_fcp_cmd_send()
1193 seq = fc_exch_seq_send(lport, fp, resp, fc_fcp_pkt_destroy, fsp, 0); in fc_fcp_cmd_send()
1198 fsp->seq_ptr = seq; in fc_fcp_cmd_send()
1199 fc_fcp_pkt_hold(fsp); /* hold for fc_fcp_pkt_destroy */ in fc_fcp_cmd_send()
1201 fsp->timer.function = fc_fcp_timeout; in fc_fcp_cmd_send()
1203 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp)); in fc_fcp_cmd_send()
1206 fc_fcp_unlock_pkt(fsp); in fc_fcp_cmd_send()
1215 static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) in fc_fcp_error() argument
1219 if (fc_fcp_lock_pkt(fsp)) in fc_fcp_error()
1223 fc_fcp_retry_cmd(fsp, FC_ERROR); in fc_fcp_error()
1231 fsp->state &= ~FC_SRB_ABORT_PENDING; in fc_fcp_error()
1232 fsp->status_code = FC_CMD_PLOGO; in fc_fcp_error()
1233 fc_fcp_complete_locked(fsp); in fc_fcp_error()
1235 fc_fcp_unlock_pkt(fsp); in fc_fcp_error()
1244 static int fc_fcp_pkt_abort(struct fc_fcp_pkt *fsp) in fc_fcp_pkt_abort() argument
1249 FC_FCP_DBG(fsp, "pkt abort state %x\n", fsp->state); in fc_fcp_pkt_abort()
1250 if (fc_fcp_send_abort(fsp)) { in fc_fcp_pkt_abort()
1251 FC_FCP_DBG(fsp, "failed to send abort\n"); in fc_fcp_pkt_abort()
1255 if (fsp->state & FC_SRB_ABORTED) { in fc_fcp_pkt_abort()
1256 FC_FCP_DBG(fsp, "target abort cmd completed\n"); in fc_fcp_pkt_abort()
1260 init_completion(&fsp->tm_done); in fc_fcp_pkt_abort()
1261 fsp->wait_for_comp = 1; in fc_fcp_pkt_abort()
1263 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_fcp_pkt_abort()
1264 ticks_left = wait_for_completion_timeout(&fsp->tm_done, in fc_fcp_pkt_abort()
1266 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_fcp_pkt_abort()
1267 fsp->wait_for_comp = 0; in fc_fcp_pkt_abort()
1270 FC_FCP_DBG(fsp, "target abort cmd failed\n"); in fc_fcp_pkt_abort()
1271 } else if (fsp->state & FC_SRB_ABORTED) { in fc_fcp_pkt_abort()
1272 FC_FCP_DBG(fsp, "target abort cmd passed\n"); in fc_fcp_pkt_abort()
1274 fc_fcp_complete_locked(fsp); in fc_fcp_pkt_abort()
1286 struct fc_fcp_pkt *fsp = from_timer(fsp, t, timer); in fc_lun_reset_send() local
1287 struct fc_lport *lport = fsp->lp; in fc_lun_reset_send()
1289 if (lport->tt.fcp_cmd_send(lport, fsp, fc_tm_done)) { in fc_lun_reset_send()
1290 if (fsp->recov_retry++ >= FC_MAX_RECOV_RETRY) in fc_lun_reset_send()
1292 if (fc_fcp_lock_pkt(fsp)) in fc_lun_reset_send()
1294 fsp->timer.function = fc_lun_reset_send; in fc_lun_reset_send()
1295 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp)); in fc_lun_reset_send()
1296 fc_fcp_unlock_pkt(fsp); in fc_lun_reset_send()
1308 static int fc_lun_reset(struct fc_lport *lport, struct fc_fcp_pkt *fsp, in fc_lun_reset() argument
1313 fsp->cdb_cmd.fc_dl = htonl(fsp->data_len); in fc_lun_reset()
1314 fsp->cdb_cmd.fc_tm_flags = FCP_TMF_LUN_RESET; in fc_lun_reset()
1315 int_to_scsilun(lun, &fsp->cdb_cmd.fc_lun); in fc_lun_reset()
1317 fsp->wait_for_comp = 1; in fc_lun_reset()
1318 init_completion(&fsp->tm_done); in fc_lun_reset()
1320 fc_lun_reset_send(&fsp->timer); in fc_lun_reset()
1326 rc = wait_for_completion_timeout(&fsp->tm_done, FC_SCSI_TM_TOV); in fc_lun_reset()
1328 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_lun_reset()
1329 fsp->state |= FC_SRB_COMPL; in fc_lun_reset()
1330 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_lun_reset()
1332 del_timer_sync(&fsp->timer); in fc_lun_reset()
1334 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_lun_reset()
1335 if (fsp->seq_ptr) { in fc_lun_reset()
1336 fc_exch_done(fsp->seq_ptr); in fc_lun_reset()
1337 fsp->seq_ptr = NULL; in fc_lun_reset()
1339 fsp->wait_for_comp = 0; in fc_lun_reset()
1340 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_lun_reset()
1348 if (fsp->cdb_status != FCP_TMF_CMPL) in fc_lun_reset()
1364 struct fc_fcp_pkt *fsp = arg; in fc_tm_done() local
1377 if (fc_fcp_lock_pkt(fsp)) in fc_tm_done()
1383 if (!fsp->seq_ptr || !fsp->wait_for_comp) in fc_tm_done()
1388 fc_fcp_resp(fsp, fp); in fc_tm_done()
1389 fsp->seq_ptr = NULL; in fc_tm_done()
1392 fc_fcp_unlock_pkt(fsp); in fc_tm_done()
1419 struct fc_fcp_pkt *fsp = from_timer(fsp, t, timer); in fc_fcp_timeout() local
1420 struct fc_rport *rport = fsp->rport; in fc_fcp_timeout()
1423 if (fc_fcp_lock_pkt(fsp)) in fc_fcp_timeout()
1426 if (fsp->cdb_cmd.fc_tm_flags) in fc_fcp_timeout()
1429 if (fsp->lp->qfull) { in fc_fcp_timeout()
1430 FC_FCP_DBG(fsp, "fcp timeout, resetting timer delay %d\n", in fc_fcp_timeout()
1431 fsp->timer_delay); in fc_fcp_timeout()
1432 fsp->timer.function = fc_fcp_timeout; in fc_fcp_timeout()
1433 fc_fcp_timer_set(fsp, fsp->timer_delay); in fc_fcp_timeout()
1436 FC_FCP_DBG(fsp, "fcp timeout, delay %d flags %x state %x\n", in fc_fcp_timeout()
1437 fsp->timer_delay, rpriv->flags, fsp->state); in fc_fcp_timeout()
1438 fsp->state |= FC_SRB_FCP_PROCESSING_TMO; in fc_fcp_timeout()
1441 fc_fcp_rec(fsp); in fc_fcp_timeout()
1442 else if (fsp->state & FC_SRB_RCV_STATUS) in fc_fcp_timeout()
1443 fc_fcp_complete_locked(fsp); in fc_fcp_timeout()
1445 fc_fcp_recovery(fsp, FC_TIMED_OUT); in fc_fcp_timeout()
1446 fsp->state &= ~FC_SRB_FCP_PROCESSING_TMO; in fc_fcp_timeout()
1448 fc_fcp_unlock_pkt(fsp); in fc_fcp_timeout()
1455 static void fc_fcp_rec(struct fc_fcp_pkt *fsp) in fc_fcp_rec() argument
1462 lport = fsp->lp; in fc_fcp_rec()
1463 rport = fsp->rport; in fc_fcp_rec()
1465 if (!fsp->seq_ptr || rpriv->rp_state != RPORT_ST_READY) { in fc_fcp_rec()
1466 fsp->status_code = FC_HRD_ERROR; in fc_fcp_rec()
1467 fsp->io_status = 0; in fc_fcp_rec()
1468 fc_fcp_complete_locked(fsp); in fc_fcp_rec()
1476 fr_seq(fp) = fsp->seq_ptr; in fc_fcp_rec()
1481 fc_fcp_rec_resp, fsp, in fc_fcp_rec()
1483 fc_fcp_pkt_hold(fsp); /* hold while REC outstanding */ in fc_fcp_rec()
1487 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) in fc_fcp_rec()
1488 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp)); in fc_fcp_rec()
1490 fc_fcp_recovery(fsp, FC_TIMED_OUT); in fc_fcp_rec()
1506 struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)arg; in fc_fcp_rec_resp() local
1517 fc_fcp_rec_error(fsp, fp); in fc_fcp_rec_resp()
1521 if (fc_fcp_lock_pkt(fsp)) in fc_fcp_rec_resp()
1524 fsp->recov_retry = 0; in fc_fcp_rec_resp()
1530 FC_FCP_DBG(fsp, in fc_fcp_rec_resp()
1532 fsp->rport->port_id, rjt->er_reason, in fc_fcp_rec_resp()
1536 FC_FCP_DBG(fsp, "device does not support REC\n"); in fc_fcp_rec_resp()
1537 rpriv = fsp->rport->dd_data; in fc_fcp_rec_resp()
1547 FC_FCP_DBG(fsp, "device %x REC reject %d/%d\n", in fc_fcp_rec_resp()
1548 fsp->rport->port_id, rjt->er_reason, in fc_fcp_rec_resp()
1557 struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr); in fc_fcp_rec_resp()
1559 fsp->state |= FC_SRB_ABORTED; in fc_fcp_rec_resp()
1560 fc_fcp_retry_cmd(fsp, FC_TRANS_RESET); in fc_fcp_rec_resp()
1563 fc_fcp_recovery(fsp, FC_TRANS_RESET); in fc_fcp_rec_resp()
1567 if (fsp->state & FC_SRB_ABORTED) in fc_fcp_rec_resp()
1570 data_dir = fsp->cmd->sc_data_direction; in fc_fcp_rec_resp()
1593 } else if (fsp->xfer_contig_end == offset) { in fc_fcp_rec_resp()
1596 offset = fsp->xfer_contig_end; in fc_fcp_rec_resp()
1599 fc_fcp_srr(fsp, r_ctl, offset); in fc_fcp_rec_resp()
1605 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp)); in fc_fcp_rec_resp()
1626 if (offset < fsp->data_len) in fc_fcp_rec_resp()
1628 } else if (offset == fsp->xfer_contig_end) { in fc_fcp_rec_resp()
1630 } else if (fsp->xfer_contig_end < offset) { in fc_fcp_rec_resp()
1631 offset = fsp->xfer_contig_end; in fc_fcp_rec_resp()
1633 fc_fcp_srr(fsp, r_ctl, offset); in fc_fcp_rec_resp()
1637 fc_fcp_unlock_pkt(fsp); in fc_fcp_rec_resp()
1639 fc_fcp_pkt_release(fsp); /* drop hold for outstanding REC */ in fc_fcp_rec_resp()
1648 static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) in fc_fcp_rec_error() argument
1652 if (fc_fcp_lock_pkt(fsp)) in fc_fcp_rec_error()
1657 FC_FCP_DBG(fsp, "REC %p fid %6.6x exchange closed\n", in fc_fcp_rec_error()
1658 fsp, fsp->rport->port_id); in fc_fcp_rec_error()
1659 fc_fcp_retry_cmd(fsp, FC_ERROR); in fc_fcp_rec_error()
1663 FC_FCP_DBG(fsp, "REC %p fid %6.6x error unexpected error %d\n", in fc_fcp_rec_error()
1664 fsp, fsp->rport->port_id, error); in fc_fcp_rec_error()
1665 fsp->status_code = FC_CMD_PLOGO; in fc_fcp_rec_error()
1673 FC_FCP_DBG(fsp, "REC %p fid %6.6x exchange timeout retry %d/%d\n", in fc_fcp_rec_error()
1674 fsp, fsp->rport->port_id, fsp->recov_retry, in fc_fcp_rec_error()
1676 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) in fc_fcp_rec_error()
1677 fc_fcp_rec(fsp); in fc_fcp_rec_error()
1679 fc_fcp_recovery(fsp, FC_TIMED_OUT); in fc_fcp_rec_error()
1682 fc_fcp_unlock_pkt(fsp); in fc_fcp_rec_error()
1684 fc_fcp_pkt_release(fsp); /* drop hold for outstanding REC */ in fc_fcp_rec_error()
1692 static void fc_fcp_recovery(struct fc_fcp_pkt *fsp, u8 code) in fc_fcp_recovery() argument
1694 FC_FCP_DBG(fsp, "start recovery code %x\n", code); in fc_fcp_recovery()
1695 fsp->status_code = code; in fc_fcp_recovery()
1696 fsp->cdb_status = 0; in fc_fcp_recovery()
1697 fsp->io_status = 0; in fc_fcp_recovery()
1698 if (!fsp->cmd) in fc_fcp_recovery()
1703 fc_fcp_send_abort(fsp); in fc_fcp_recovery()
1714 static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum fc_rctl r_ctl, u32 offset) in fc_fcp_srr() argument
1716 struct fc_lport *lport = fsp->lp; in fc_fcp_srr()
1719 struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr); in fc_fcp_srr()
1724 rport = fsp->rport; in fc_fcp_srr()
1748 fsp, get_fsp_rec_tov(fsp)); in fc_fcp_srr()
1752 fsp->recov_seq = seq; in fc_fcp_srr()
1753 fsp->xfer_len = offset; in fc_fcp_srr()
1754 fsp->xfer_contig_end = offset; in fc_fcp_srr()
1755 fsp->state &= ~FC_SRB_RCV_STATUS; in fc_fcp_srr()
1756 fc_fcp_pkt_hold(fsp); /* hold for outstanding SRR */ in fc_fcp_srr()
1759 fc_fcp_retry_cmd(fsp, FC_TRANS_RESET); in fc_fcp_srr()
1770 struct fc_fcp_pkt *fsp = arg; in fc_fcp_srr_resp() local
1774 fc_fcp_srr_error(fsp, fp); in fc_fcp_srr_resp()
1778 if (fc_fcp_lock_pkt(fsp)) in fc_fcp_srr_resp()
1790 fc_fcp_unlock_pkt(fsp); in fc_fcp_srr_resp()
1796 fsp->recov_retry = 0; in fc_fcp_srr_resp()
1797 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp)); in fc_fcp_srr_resp()
1801 fc_fcp_recovery(fsp, FC_ERROR); in fc_fcp_srr_resp()
1804 fc_fcp_unlock_pkt(fsp); in fc_fcp_srr_resp()
1815 static void fc_fcp_srr_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) in fc_fcp_srr_error() argument
1817 if (fc_fcp_lock_pkt(fsp)) in fc_fcp_srr_error()
1821 FC_FCP_DBG(fsp, "SRR timeout, retries %d\n", fsp->recov_retry); in fc_fcp_srr_error()
1822 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) in fc_fcp_srr_error()
1823 fc_fcp_rec(fsp); in fc_fcp_srr_error()
1825 fc_fcp_recovery(fsp, FC_TIMED_OUT); in fc_fcp_srr_error()
1828 FC_FCP_DBG(fsp, "SRR error, exchange closed\n"); in fc_fcp_srr_error()
1831 fc_fcp_retry_cmd(fsp, FC_ERROR); in fc_fcp_srr_error()
1834 fc_fcp_unlock_pkt(fsp); in fc_fcp_srr_error()
1836 fc_exch_done(fsp->recov_seq); in fc_fcp_srr_error()
1861 struct fc_fcp_pkt *fsp; in fc_queuecommand() local
1894 fsp = fc_fcp_pkt_alloc(lport, GFP_ATOMIC); in fc_queuecommand()
1895 if (fsp == NULL) { in fc_queuecommand()
1903 fsp->cmd = sc_cmd; /* save the cmd */ in fc_queuecommand()
1904 fsp->rport = rport; /* set the remote port ptr */ in fc_queuecommand()
1909 fsp->data_len = scsi_bufflen(sc_cmd); in fc_queuecommand()
1910 fsp->xfer_len = 0; in fc_queuecommand()
1916 fsp->req_flags = FC_SRB_READ; in fc_queuecommand()
1918 this_cpu_add(lport->stats->InputBytes, fsp->data_len); in fc_queuecommand()
1920 fsp->req_flags = FC_SRB_WRITE; in fc_queuecommand()
1922 this_cpu_add(lport->stats->OutputBytes, fsp->data_len); in fc_queuecommand()
1924 fsp->req_flags = 0; in fc_queuecommand()
1933 rval = fc_fcp_pkt_send(lport, fsp); in fc_queuecommand()
1935 fsp->state = FC_SRB_FREE; in fc_queuecommand()
1936 fc_fcp_pkt_release(fsp); in fc_queuecommand()
1951 static void fc_io_compl(struct fc_fcp_pkt *fsp) in fc_io_compl() argument
1959 fc_fcp_ddp_done(fsp); in fc_io_compl()
1961 fsp->state |= FC_SRB_COMPL; in fc_io_compl()
1962 if (!(fsp->state & FC_SRB_FCP_PROCESSING_TMO)) { in fc_io_compl()
1963 spin_unlock_bh(&fsp->scsi_pkt_lock); in fc_io_compl()
1964 del_timer_sync(&fsp->timer); in fc_io_compl()
1965 spin_lock_bh(&fsp->scsi_pkt_lock); in fc_io_compl()
1968 lport = fsp->lp; in fc_io_compl()
1978 sc_cmd = fsp->cmd; in fc_io_compl()
1979 libfc_priv(sc_cmd)->status = fsp->cdb_status; in fc_io_compl()
1980 switch (fsp->status_code) { in fc_io_compl()
1982 if (fsp->cdb_status == 0) { in fc_io_compl()
1987 if (fsp->scsi_resid) in fc_io_compl()
1988 libfc_priv(sc_cmd)->resid_len = fsp->scsi_resid; in fc_io_compl()
1994 sc_cmd->result = (DID_OK << 16) | fsp->cdb_status; in fc_io_compl()
1998 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " in fc_io_compl()
2003 if ((fsp->cdb_status == 0) && !(fsp->req_flags & FC_SRB_READ)) { in fc_io_compl()
2008 if (fsp->state & FC_SRB_RCV_STATUS) { in fc_io_compl()
2011 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml" in fc_io_compl()
2019 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " in fc_io_compl()
2021 libfc_priv(sc_cmd)->resid_len = fsp->scsi_resid; in fc_io_compl()
2022 sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status; in fc_io_compl()
2029 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " in fc_io_compl()
2031 sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status; in fc_io_compl()
2035 FC_FCP_DBG(fsp, "Returning DID_TIME_OUT to scsi-ml " in fc_io_compl()
2038 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " in fc_io_compl()
2042 sc_cmd->result |= fsp->io_status; in fc_io_compl()
2045 FC_FCP_DBG(fsp, "Returning DID_RESET to scsi-ml " in fc_io_compl()
2050 FC_FCP_DBG(fsp, "Returning DID_SOFT_ERROR to scsi-ml " in fc_io_compl()
2055 FC_FCP_DBG(fsp, "Returning DID_NO_CONNECT to scsi-ml " in fc_io_compl()
2060 FC_FCP_DBG(fsp, "Returning DID_PARITY to scsi-ml " in fc_io_compl()
2065 FC_FCP_DBG(fsp, "Returning DID_TIME_OUT to scsi-ml " in fc_io_compl()
2070 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " in fc_io_compl()
2076 if (lport->state != LPORT_ST_READY && fsp->status_code != FC_COMPLETE) in fc_io_compl()
2080 list_del(&fsp->list); in fc_io_compl()
2081 libfc_priv(sc_cmd)->fsp = NULL; in fc_io_compl()
2086 fc_fcp_pkt_release(fsp); in fc_io_compl()
2098 struct fc_fcp_pkt *fsp; in fc_eh_abort() local
2117 fsp = libfc_priv(sc_cmd)->fsp; in fc_eh_abort()
2118 if (!fsp) { in fc_eh_abort()
2124 fc_fcp_pkt_hold(fsp); in fc_eh_abort()
2127 if (fc_fcp_lock_pkt(fsp)) { in fc_eh_abort()
2133 rc = fc_fcp_pkt_abort(fsp); in fc_eh_abort()
2134 fc_fcp_unlock_pkt(fsp); in fc_eh_abort()
2137 fc_fcp_pkt_release(fsp); in fc_eh_abort()
2152 struct fc_fcp_pkt *fsp; in fc_eh_device_reset() local
2168 fsp = fc_fcp_pkt_alloc(lport, GFP_NOIO); in fc_eh_device_reset()
2169 if (fsp == NULL) { in fc_eh_device_reset()
2179 fsp->rport = rport; /* set the remote port ptr */ in fc_eh_device_reset()
2184 rc = fc_lun_reset(lport, fsp, scmd_id(sc_cmd), sc_cmd->device->lun); in fc_eh_device_reset()
2185 fsp->state = FC_SRB_FREE; in fc_eh_device_reset()
2186 fc_fcp_pkt_release(fsp); in fc_eh_device_reset()