H A D | fc_fcp.c | 149 struct fc_fcp_pkt *fsp; fc_fcp_pkt_alloc() local 151 fsp = mempool_alloc(si->scsi_pkt_pool, gfp); fc_fcp_pkt_alloc() 152 if (fsp) { fc_fcp_pkt_alloc() 153 memset(fsp, 0, sizeof(*fsp)); fc_fcp_pkt_alloc() 154 fsp->lp = lport; fc_fcp_pkt_alloc() 155 fsp->xfer_ddp = FC_XID_UNKNOWN; fc_fcp_pkt_alloc() 156 atomic_set(&fsp->ref_cnt, 1); fc_fcp_pkt_alloc() 157 init_timer(&fsp->timer); fc_fcp_pkt_alloc() 158 fsp->timer.data = (unsigned long)fsp; fc_fcp_pkt_alloc() 159 INIT_LIST_HEAD(&fsp->list); fc_fcp_pkt_alloc() 160 spin_lock_init(&fsp->scsi_pkt_lock); fc_fcp_pkt_alloc() 165 return fsp; fc_fcp_pkt_alloc() 170 * @fsp: The FCP packet to be released 175 static void fc_fcp_pkt_release(struct fc_fcp_pkt *fsp) fc_fcp_pkt_release() argument 177 if (atomic_dec_and_test(&fsp->ref_cnt)) { fc_fcp_pkt_release() 178 struct fc_fcp_internal *si = fc_get_scsi_internal(fsp->lp); fc_fcp_pkt_release() 180 mempool_free(fsp, si->scsi_pkt_pool); fc_fcp_pkt_release() 186 * @fsp: The FCP packet to be held 188 static void fc_fcp_pkt_hold(struct fc_fcp_pkt *fsp) fc_fcp_pkt_hold() argument 190 atomic_inc(&fsp->ref_cnt); fc_fcp_pkt_hold() 196 * @fsp: The FCP packet to be released 204 static void fc_fcp_pkt_destroy(struct fc_seq *seq, void *fsp) fc_fcp_pkt_destroy() argument 206 fc_fcp_pkt_release(fsp); fc_fcp_pkt_destroy() 211 * @fsp: The FCP packet to be locked and incremented 223 * have a function that they call to verify the fsp and grab a ref if 226 static inline int fc_fcp_lock_pkt(struct fc_fcp_pkt *fsp) fc_fcp_lock_pkt() argument 228 spin_lock_bh(&fsp->scsi_pkt_lock); fc_fcp_lock_pkt() 229 if (fsp->state & FC_SRB_COMPL) { fc_fcp_lock_pkt() 230 spin_unlock_bh(&fsp->scsi_pkt_lock); fc_fcp_lock_pkt() 234 fc_fcp_pkt_hold(fsp); fc_fcp_lock_pkt() 241 * @fsp: The FCP packet to be unlocked and decremented 243 static inline void fc_fcp_unlock_pkt(struct fc_fcp_pkt *fsp) fc_fcp_unlock_pkt() argument 245 spin_unlock_bh(&fsp->scsi_pkt_lock); fc_fcp_unlock_pkt() 246 fc_fcp_pkt_release(fsp); fc_fcp_unlock_pkt() 251 * @fsp: The FCP packet to start a timer for 254 static void fc_fcp_timer_set(struct fc_fcp_pkt *fsp, unsigned long delay) fc_fcp_timer_set() argument 256 if (!(fsp->state & FC_SRB_COMPL)) fc_fcp_timer_set() 257 mod_timer(&fsp->timer, jiffies + delay); fc_fcp_timer_set() 263 * @fsp: The FCP packet to abort exchanges on 265 static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp) fc_fcp_send_abort() argument 267 if (!fsp->seq_ptr) fc_fcp_send_abort() 270 per_cpu_ptr(fsp->lp->stats, get_cpu())->FcpPktAborts++; fc_fcp_send_abort() 273 fsp->state |= FC_SRB_ABORT_PENDING; fc_fcp_send_abort() 274 return fsp->lp->tt.seq_exch_abort(fsp->seq_ptr, 0); fc_fcp_send_abort() 279 * @fsp: The FCP packet to be retried 286 static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp) fc_fcp_retry_cmd() argument 288 if (fsp->seq_ptr) { fc_fcp_retry_cmd() 289 fsp->lp->tt.exch_done(fsp->seq_ptr); fc_fcp_retry_cmd() 290 fsp->seq_ptr = NULL; fc_fcp_retry_cmd() 293 fsp->state &= ~FC_SRB_ABORT_PENDING; fc_fcp_retry_cmd() 294 fsp->io_status = 0; fc_fcp_retry_cmd() 295 fsp->status_code = FC_ERROR; fc_fcp_retry_cmd() 296 fc_fcp_complete_locked(fsp); fc_fcp_retry_cmd() 301 * @fsp: The FCP packet that will manage the DDP frames 304 void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid) fc_fcp_ddp_setup() argument 308 lport = fsp->lp; fc_fcp_ddp_setup() 309 if ((fsp->req_flags & FC_SRB_READ) && fc_fcp_ddp_setup() 311 if (lport->tt.ddp_setup(lport, xid, scsi_sglist(fsp->cmd), fc_fcp_ddp_setup() 312 scsi_sg_count(fsp->cmd))) fc_fcp_ddp_setup() 313 fsp->xfer_ddp = xid; fc_fcp_ddp_setup() 320 * @fsp: The FCP packet that DDP had been used on 322 void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp) fc_fcp_ddp_done() argument 326 if (!fsp) fc_fcp_ddp_done() 329 if (fsp->xfer_ddp == FC_XID_UNKNOWN) fc_fcp_ddp_done() 332 lport = fsp->lp; fc_fcp_ddp_done() 334 fsp->xfer_len = lport->tt.ddp_done(lport, fsp->xfer_ddp); fc_fcp_ddp_done() 335 fsp->xfer_ddp = FC_XID_UNKNOWN; fc_fcp_ddp_done() 438 * @fsp: The FCP packet the data is on 441 static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) fc_fcp_recv_data() argument 443 struct scsi_cmnd *sc = fsp->cmd; fc_fcp_recv_data() 444 struct fc_lport *lport = fsp->lp; fc_fcp_recv_data() 470 if (fsp->xfer_ddp != FC_XID_UNKNOWN) { fc_fcp_recv_data() 471 fc_fcp_ddp_done(fsp); fc_fcp_recv_data() 472 FC_FCP_DBG(fsp, "DDP I/O in fc_fcp_recv_data set ERROR\n"); fc_fcp_recv_data() 476 if (offset + len > fsp->data_len) { fc_fcp_recv_data() 481 FC_FCP_DBG(fsp, "data received past end. len %zx offset %zx " fc_fcp_recv_data() 482 "data_len %x\n", len, offset, fsp->data_len); fc_fcp_recv_data() 488 if (offset != fsp->xfer_len) fc_fcp_recv_data() 489 fsp->state |= FC_SRB_DISCONTIG; fc_fcp_recv_data() 522 if (fsp->state & FC_SRB_DISCONTIG) { fc_fcp_recv_data() 530 if (fsp->xfer_contig_end == start_offset) fc_fcp_recv_data() 531 fsp->xfer_contig_end += copy_len; fc_fcp_recv_data() 532 fsp->xfer_len += copy_len; fc_fcp_recv_data() 538 if (unlikely(fsp->state & FC_SRB_RCV_STATUS) && fc_fcp_recv_data() 539 fsp->xfer_len == fsp->data_len - fsp->scsi_resid) fc_fcp_recv_data() 540 fc_fcp_complete_locked(fsp); fc_fcp_recv_data() 543 fc_fcp_recovery(fsp, host_bcode); fc_fcp_recv_data() 548 * @fsp: The FCP packet the data is on 559 static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, fc_fcp_send_data() argument 566 struct fc_lport *lport = fsp->lp; fc_fcp_send_data() 581 if (unlikely(offset + seq_blen > fsp->data_len)) { fc_fcp_send_data() 583 FC_FCP_DBG(fsp, "xfer-ready past end. seq_blen %zx " fc_fcp_send_data() 585 fc_fcp_send_abort(fsp); fc_fcp_send_data() 587 } else if (offset != fsp->xfer_len) { fc_fcp_send_data() 589 FC_FCP_DBG(fsp, "xfer-ready non-contiguous. " fc_fcp_send_data() 596 * to max FC frame payload previously set in fsp->max_payload. fc_fcp_send_data() 598 t_blen = fsp->max_payload; fc_fcp_send_data() 601 FC_FCP_DBG(fsp, "fsp=%p:lso:blen=%zx lso_max=0x%x t_blen=%zx\n", fc_fcp_send_data() 602 fsp, seq_blen, lport->lso_max, t_blen); fc_fcp_send_data() 607 sc = fsp->cmd; fc_fcp_send_data() 640 fr_max_payload(fp) = fsp->max_payload; fc_fcp_send_data() 697 fsp->xfer_len += seq_blen; /* premature count? */ fc_fcp_send_data() 703 * @fsp: The FCP packet that is being aborted 706 static void fc_fcp_abts_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) fc_fcp_abts_resp() argument 731 fsp->state |= FC_SRB_ABORTED; fc_fcp_abts_resp() 732 fsp->state &= ~FC_SRB_ABORT_PENDING; fc_fcp_abts_resp() 734 if (fsp->wait_for_comp) fc_fcp_abts_resp() 735 complete(&fsp->tm_done); fc_fcp_abts_resp() 737 fc_fcp_complete_locked(fsp); fc_fcp_abts_resp() 752 struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)arg; fc_fcp_recv() local 753 struct fc_lport *lport = fsp->lp; fc_fcp_recv() 760 fc_fcp_error(fsp, fp); fc_fcp_recv() 769 if (fc_fcp_lock_pkt(fsp)) fc_fcp_recv() 773 fc_fcp_abts_resp(fsp, fp); fc_fcp_recv() 777 if (fsp->state & (FC_SRB_ABORTED | FC_SRB_ABORT_PENDING)) fc_fcp_recv() 789 rc = fc_fcp_send_data(fsp, seq, fc_fcp_recv() 793 seq->rec_data = fsp->xfer_len; fc_fcp_recv() 800 fc_fcp_recv_data(fsp, fp); fc_fcp_recv() 801 seq->rec_data = fsp->xfer_contig_end; fc_fcp_recv() 805 fc_fcp_resp(fsp, fp); fc_fcp_recv() 807 FC_FCP_DBG(fsp, "unexpected frame. r_ctl %x\n", r_ctl); fc_fcp_recv() 810 fc_fcp_unlock_pkt(fsp); fc_fcp_recv() 817 * @fsp: The FCP packet the response is for 820 static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) fc_fcp_resp() argument 838 fsp->cdb_status = fc_rp->fr_status; fc_fcp_resp() 840 fsp->scsi_comp_flags = flags; fc_fcp_resp() 841 expected_len = fsp->data_len; fc_fcp_resp() 844 fc_fcp_ddp_done(fsp); fc_fcp_resp() 857 if (fsp->wait_for_comp) { fc_fcp_resp() 859 fsp->cdb_status = fc_rp_info->rsp_code; fc_fcp_resp() 860 complete(&fsp->tm_done); fc_fcp_resp() 872 memcpy(fsp->cmd->sense_buffer, fc_fcp_resp() 880 fsp->scsi_resid = ntohl(rp_ex->fr_resid); fc_fcp_resp() 891 (scsi_bufflen(fsp->cmd) - fc_fcp_resp() 892 fsp->scsi_resid) < fsp->cmd->underflow) fc_fcp_resp() 894 expected_len -= fsp->scsi_resid; fc_fcp_resp() 896 fsp->status_code = FC_ERROR; fc_fcp_resp() 900 fsp->state |= FC_SRB_RCV_STATUS; fc_fcp_resp() 905 if (unlikely(fsp->cdb_status == SAM_STAT_GOOD && fc_fcp_resp() 906 fsp->xfer_len != expected_len)) { fc_fcp_resp() 907 if (fsp->xfer_len < expected_len) { fc_fcp_resp() 913 fc_fcp_timer_set(fsp, 2); fc_fcp_resp() 916 fsp->status_code = FC_DATA_OVRRUN; fc_fcp_resp() 917 FC_FCP_DBG(fsp, "tgt %6.6x xfer len %zx greater than expected, " fc_fcp_resp() 919 fsp->rport->port_id, fc_fcp_resp() 920 fsp->xfer_len, expected_len, fsp->data_len); fc_fcp_resp() 922 fc_fcp_complete_locked(fsp); fc_fcp_resp() 926 FC_FCP_DBG(fsp, "short FCP response. flags 0x%x len %u respl %u " fc_fcp_resp() 929 fsp->status_code = FC_ERROR; fc_fcp_resp() 930 fc_fcp_complete_locked(fsp); fc_fcp_resp() 936 * @fsp: The FCP packet to be completed 941 static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp) fc_fcp_complete_locked() argument 943 struct fc_lport *lport = fsp->lp; fc_fcp_complete_locked() 948 if (fsp->state & FC_SRB_ABORT_PENDING) fc_fcp_complete_locked() 951 if (fsp->state & FC_SRB_ABORTED) { fc_fcp_complete_locked() 952 if (!fsp->status_code) fc_fcp_complete_locked() 953 fsp->status_code = FC_CMD_ABORTED; fc_fcp_complete_locked() 959 if (fsp->cdb_status == SAM_STAT_GOOD && fc_fcp_complete_locked() 960 fsp->xfer_len < fsp->data_len && !fsp->io_status && fc_fcp_complete_locked() 961 (!(fsp->scsi_comp_flags & FCP_RESID_UNDER) || fc_fcp_complete_locked() 962 fsp->xfer_len < fsp->data_len - fsp->scsi_resid)) fc_fcp_complete_locked() 963 fsp->status_code = FC_DATA_UNDRUN; fc_fcp_complete_locked() 966 seq = fsp->seq_ptr; fc_fcp_complete_locked() 968 fsp->seq_ptr = NULL; fc_fcp_complete_locked() 969 if (unlikely(fsp->scsi_comp_flags & FCP_CONF_REQ)) { fc_fcp_complete_locked() 974 conf_frame = fc_fcp_frame_alloc(fsp->lp, 0); fc_fcp_complete_locked() 992 if (fsp->cmd) fc_fcp_complete_locked() 993 fc_io_compl(fsp); fc_fcp_complete_locked() 998 * @fsp: The FCP packet whose exchanges should be canceled 1001 static void fc_fcp_cleanup_cmd(struct fc_fcp_pkt *fsp, int error) fc_fcp_cleanup_cmd() argument 1003 struct fc_lport *lport = fsp->lp; fc_fcp_cleanup_cmd() 1005 if (fsp->seq_ptr) { fc_fcp_cleanup_cmd() 1006 lport->tt.exch_done(fsp->seq_ptr); fc_fcp_cleanup_cmd() 1007 fsp->seq_ptr = NULL; fc_fcp_cleanup_cmd() 1009 fsp->status_code = error; fc_fcp_cleanup_cmd() 1025 struct fc_fcp_pkt *fsp; fc_fcp_cleanup_each_cmd() local 1031 list_for_each_entry(fsp, &si->scsi_pkt_queue, list) { fc_fcp_cleanup_each_cmd() 1032 sc_cmd = fsp->cmd; fc_fcp_cleanup_each_cmd() 1039 fc_fcp_pkt_hold(fsp); fc_fcp_cleanup_each_cmd() 1042 spin_lock_bh(&fsp->scsi_pkt_lock); fc_fcp_cleanup_each_cmd() 1043 if (!(fsp->state & FC_SRB_COMPL)) { fc_fcp_cleanup_each_cmd() 1044 fsp->state |= FC_SRB_COMPL; fc_fcp_cleanup_each_cmd() 1054 spin_unlock_bh(&fsp->scsi_pkt_lock); fc_fcp_cleanup_each_cmd() 1056 fc_fcp_cleanup_cmd(fsp, error); fc_fcp_cleanup_each_cmd() 1058 spin_lock_bh(&fsp->scsi_pkt_lock); fc_fcp_cleanup_each_cmd() 1059 fc_io_compl(fsp); fc_fcp_cleanup_each_cmd() 1061 spin_unlock_bh(&fsp->scsi_pkt_lock); fc_fcp_cleanup_each_cmd() 1063 fc_fcp_pkt_release(fsp); fc_fcp_cleanup_each_cmd() 1086 * @fsp: The FCP packet to send 1091 static int fc_fcp_pkt_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp) fc_fcp_pkt_send() argument 1097 fsp->cmd->SCp.ptr = (char *)fsp; fc_fcp_pkt_send() 1098 fsp->cdb_cmd.fc_dl = htonl(fsp->data_len); fc_fcp_pkt_send() 1099 fsp->cdb_cmd.fc_flags = fsp->req_flags & ~FCP_CFL_LEN_MASK; fc_fcp_pkt_send() 1101 int_to_scsilun(fsp->cmd->device->lun, &fsp->cdb_cmd.fc_lun); fc_fcp_pkt_send() 1102 memcpy(fsp->cdb_cmd.fc_cdb, fsp->cmd->cmnd, fsp->cmd->cmd_len); fc_fcp_pkt_send() 1105 list_add_tail(&fsp->list, &si->scsi_pkt_queue); fc_fcp_pkt_send() 1107 rc = lport->tt.fcp_cmd_send(lport, fsp, fc_fcp_recv); fc_fcp_pkt_send() 1110 fsp->cmd->SCp.ptr = NULL; fc_fcp_pkt_send() 1111 list_del(&fsp->list); fc_fcp_pkt_send() 1120 * @fsp: the FCP packet 1124 static inline unsigned int get_fsp_rec_tov(struct fc_fcp_pkt *fsp) get_fsp_rec_tov() argument 1126 struct fc_rport_libfc_priv *rpriv = fsp->rport->dd_data; get_fsp_rec_tov() 1134 * @fsp: The FCP packet the command is on 1137 static int fc_fcp_cmd_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp, fc_fcp_cmd_send() argument 1146 const size_t len = sizeof(fsp->cdb_cmd); fc_fcp_cmd_send() 1149 if (fc_fcp_lock_pkt(fsp)) fc_fcp_cmd_send() 1152 fp = fc_fcp_frame_alloc(lport, sizeof(fsp->cdb_cmd)); fc_fcp_cmd_send() 1158 memcpy(fc_frame_payload_get(fp, len), &fsp->cdb_cmd, len); fc_fcp_cmd_send() 1159 fr_fsp(fp) = fsp; fc_fcp_cmd_send() 1160 rport = fsp->rport; fc_fcp_cmd_send() 1161 fsp->max_payload = rport->maxframe_size; fc_fcp_cmd_send() 1169 fsp, 0); fc_fcp_cmd_send() 1174 fsp->seq_ptr = seq; fc_fcp_cmd_send() 1175 fc_fcp_pkt_hold(fsp); /* hold for fc_fcp_pkt_destroy */ fc_fcp_cmd_send() 1177 setup_timer(&fsp->timer, fc_fcp_timeout, (unsigned long)fsp); fc_fcp_cmd_send() 1179 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp)); fc_fcp_cmd_send() 1182 fc_fcp_unlock_pkt(fsp); fc_fcp_cmd_send() 1188 * @fsp: The FCP packet the error is on 1191 static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) fc_fcp_error() argument 1195 if (fc_fcp_lock_pkt(fsp)) fc_fcp_error() 1199 fc_fcp_retry_cmd(fsp); fc_fcp_error() 1207 fsp->state &= ~FC_SRB_ABORT_PENDING; fc_fcp_error() 1208 fsp->status_code = FC_CMD_PLOGO; fc_fcp_error() 1209 fc_fcp_complete_locked(fsp); fc_fcp_error() 1211 fc_fcp_unlock_pkt(fsp); fc_fcp_error() 1216 * @fsp: The FCP packet to abort on 1220 static int fc_fcp_pkt_abort(struct fc_fcp_pkt *fsp) fc_fcp_pkt_abort() argument 1225 if (fc_fcp_send_abort(fsp)) fc_fcp_pkt_abort() 1228 init_completion(&fsp->tm_done); fc_fcp_pkt_abort() 1229 fsp->wait_for_comp = 1; fc_fcp_pkt_abort() 1231 spin_unlock_bh(&fsp->scsi_pkt_lock); fc_fcp_pkt_abort() 1232 ticks_left = wait_for_completion_timeout(&fsp->tm_done, fc_fcp_pkt_abort() 1234 spin_lock_bh(&fsp->scsi_pkt_lock); fc_fcp_pkt_abort() 1235 fsp->wait_for_comp = 0; fc_fcp_pkt_abort() 1238 FC_FCP_DBG(fsp, "target abort cmd failed\n"); fc_fcp_pkt_abort() 1239 } else if (fsp->state & FC_SRB_ABORTED) { fc_fcp_pkt_abort() 1240 FC_FCP_DBG(fsp, "target abort cmd passed\n"); fc_fcp_pkt_abort() 1242 fc_fcp_complete_locked(fsp); fc_fcp_pkt_abort() 1254 struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)data; fc_lun_reset_send() local 1255 struct fc_lport *lport = fsp->lp; fc_lun_reset_send() 1257 if (lport->tt.fcp_cmd_send(lport, fsp, fc_tm_done)) { fc_lun_reset_send() 1258 if (fsp->recov_retry++ >= FC_MAX_RECOV_RETRY) fc_lun_reset_send() 1260 if (fc_fcp_lock_pkt(fsp)) fc_lun_reset_send() 1262 setup_timer(&fsp->timer, fc_lun_reset_send, (unsigned long)fsp); fc_lun_reset_send() 1263 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp)); fc_lun_reset_send() 1264 fc_fcp_unlock_pkt(fsp); fc_lun_reset_send() 1272 * @fsp: The FCP packet that identifies the LUN to be reset 1276 static int fc_lun_reset(struct fc_lport *lport, struct fc_fcp_pkt *fsp, fc_lun_reset() argument 1281 fsp->cdb_cmd.fc_dl = htonl(fsp->data_len); fc_lun_reset() 1282 fsp->cdb_cmd.fc_tm_flags = FCP_TMF_LUN_RESET; fc_lun_reset() 1283 int_to_scsilun(lun, &fsp->cdb_cmd.fc_lun); fc_lun_reset() 1285 fsp->wait_for_comp = 1; fc_lun_reset() 1286 init_completion(&fsp->tm_done); fc_lun_reset() 1288 fc_lun_reset_send((unsigned long)fsp); fc_lun_reset() 1294 rc = wait_for_completion_timeout(&fsp->tm_done, FC_SCSI_TM_TOV); fc_lun_reset() 1296 spin_lock_bh(&fsp->scsi_pkt_lock); fc_lun_reset() 1297 fsp->state |= FC_SRB_COMPL; fc_lun_reset() 1298 spin_unlock_bh(&fsp->scsi_pkt_lock); fc_lun_reset() 1300 del_timer_sync(&fsp->timer); fc_lun_reset() 1302 spin_lock_bh(&fsp->scsi_pkt_lock); fc_lun_reset() 1303 if (fsp->seq_ptr) { fc_lun_reset() 1304 lport->tt.exch_done(fsp->seq_ptr); fc_lun_reset() 1305 fsp->seq_ptr = NULL; fc_lun_reset() 1307 fsp->wait_for_comp = 0; fc_lun_reset() 1308 spin_unlock_bh(&fsp->scsi_pkt_lock); fc_lun_reset() 1316 if (fsp->cdb_status != FCP_TMF_CMPL) fc_lun_reset() 1332 struct fc_fcp_pkt *fsp = arg; fc_tm_done() local 1345 if (fc_fcp_lock_pkt(fsp)) fc_tm_done() 1351 if (!fsp->seq_ptr || !fsp->wait_for_comp) fc_tm_done() 1356 fc_fcp_resp(fsp, fp); fc_tm_done() 1357 fsp->seq_ptr = NULL; fc_tm_done() 1358 fsp->lp->tt.exch_done(seq); fc_tm_done() 1360 fc_fcp_unlock_pkt(fsp); fc_tm_done() 1387 struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)data; fc_fcp_timeout() local 1388 struct fc_rport *rport = fsp->rport; fc_fcp_timeout() 1391 if (fc_fcp_lock_pkt(fsp)) fc_fcp_timeout() 1394 if (fsp->cdb_cmd.fc_tm_flags) fc_fcp_timeout() 1397 fsp->state |= FC_SRB_FCP_PROCESSING_TMO; fc_fcp_timeout() 1400 fc_fcp_rec(fsp); fc_fcp_timeout() 1401 else if (fsp->state & FC_SRB_RCV_STATUS) fc_fcp_timeout() 1402 fc_fcp_complete_locked(fsp); fc_fcp_timeout() 1404 fc_fcp_recovery(fsp, FC_TIMED_OUT); fc_fcp_timeout() 1405 fsp->state &= ~FC_SRB_FCP_PROCESSING_TMO; fc_fcp_timeout() 1407 fc_fcp_unlock_pkt(fsp); fc_fcp_timeout() 1412 * @fsp: The FCP packet to send the REC request on 1414 static void fc_fcp_rec(struct fc_fcp_pkt *fsp) fc_fcp_rec() argument 1421 lport = fsp->lp; fc_fcp_rec() 1422 rport = fsp->rport; fc_fcp_rec() 1424 if (!fsp->seq_ptr || rpriv->rp_state != RPORT_ST_READY) { fc_fcp_rec() 1425 fsp->status_code = FC_HRD_ERROR; fc_fcp_rec() 1426 fsp->io_status = 0; fc_fcp_rec() 1427 fc_fcp_complete_locked(fsp); fc_fcp_rec() 1435 fr_seq(fp) = fsp->seq_ptr; fc_fcp_rec() 1440 fc_fcp_rec_resp, fsp, fc_fcp_rec() 1442 fc_fcp_pkt_hold(fsp); /* hold while REC outstanding */ fc_fcp_rec() 1446 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) fc_fcp_rec() 1447 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp)); fc_fcp_rec() 1449 fc_fcp_recovery(fsp, FC_TIMED_OUT); fc_fcp_rec() 1465 struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)arg; fc_fcp_rec_resp() local 1476 fc_fcp_rec_error(fsp, fp); fc_fcp_rec_resp() 1480 if (fc_fcp_lock_pkt(fsp)) fc_fcp_rec_resp() 1483 fsp->recov_retry = 0; fc_fcp_rec_resp() 1489 FC_FCP_DBG(fsp, "device %x unexpected REC reject " fc_fcp_rec_resp() 1491 fsp->rport->port_id, rjt->er_reason, fc_fcp_rec_resp() 1495 FC_FCP_DBG(fsp, "device does not support REC\n"); fc_fcp_rec_resp() 1496 rpriv = fsp->rport->dd_data; fc_fcp_rec_resp() 1513 fsp->xfer_len == 0) { fc_fcp_rec_resp() 1514 fc_fcp_retry_cmd(fsp); fc_fcp_rec_resp() 1517 fc_fcp_recovery(fsp, FC_ERROR); fc_fcp_rec_resp() 1521 if (fsp->state & FC_SRB_ABORTED) fc_fcp_rec_resp() 1524 data_dir = fsp->cmd->sc_data_direction; fc_fcp_rec_resp() 1547 } else if (fsp->xfer_contig_end == offset) { fc_fcp_rec_resp() 1550 offset = fsp->xfer_contig_end; fc_fcp_rec_resp() 1553 fc_fcp_srr(fsp, r_ctl, offset); fc_fcp_rec_resp() 1559 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp)); fc_fcp_rec_resp() 1580 if (offset < fsp->data_len) fc_fcp_rec_resp() 1582 } else if (offset == fsp->xfer_contig_end) { fc_fcp_rec_resp() 1584 } else if (fsp->xfer_contig_end < offset) { fc_fcp_rec_resp() 1585 offset = fsp->xfer_contig_end; fc_fcp_rec_resp() 1587 fc_fcp_srr(fsp, r_ctl, offset); fc_fcp_rec_resp() 1591 fc_fcp_unlock_pkt(fsp); fc_fcp_rec_resp() 1593 fc_fcp_pkt_release(fsp); /* drop hold for outstanding REC */ fc_fcp_rec_resp() 1599 * @fsp: The FCP packet the error is on 1602 static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) fc_fcp_rec_error() argument 1606 if (fc_fcp_lock_pkt(fsp)) fc_fcp_rec_error() 1611 fc_fcp_retry_cmd(fsp); fc_fcp_rec_error() 1615 FC_FCP_DBG(fsp, "REC %p fid %6.6x error unexpected error %d\n", fc_fcp_rec_error() 1616 fsp, fsp->rport->port_id, error); fc_fcp_rec_error() 1617 fsp->status_code = FC_CMD_PLOGO; fc_fcp_rec_error() 1625 FC_FCP_DBG(fsp, "REC fid %6.6x error error %d retry %d/%d\n", fc_fcp_rec_error() 1626 fsp->rport->port_id, error, fsp->recov_retry, fc_fcp_rec_error() 1628 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) fc_fcp_rec_error() 1629 fc_fcp_rec(fsp); fc_fcp_rec_error() 1631 fc_fcp_recovery(fsp, FC_ERROR); fc_fcp_rec_error() 1634 fc_fcp_unlock_pkt(fsp); fc_fcp_rec_error() 1636 fc_fcp_pkt_release(fsp); /* drop hold for outstanding REC */ fc_fcp_rec_error() 1641 * @fsp: The FCP pkt that needs to be aborted 1643 static void fc_fcp_recovery(struct fc_fcp_pkt *fsp, u8 code) fc_fcp_recovery() argument 1645 fsp->status_code = code; fc_fcp_recovery() 1646 fsp->cdb_status = 0; fc_fcp_recovery() 1647 fsp->io_status = 0; fc_fcp_recovery() 1652 fc_fcp_send_abort(fsp); fc_fcp_recovery() 1657 * @fsp: The FCP packet the SRR is to be sent on 1662 static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum fc_rctl r_ctl, u32 offset) fc_fcp_srr() argument 1664 struct fc_lport *lport = fsp->lp; fc_fcp_srr() 1667 struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr); fc_fcp_srr() 1673 rport = fsp->rport; fc_fcp_srr() 1695 rec_tov = get_fsp_rec_tov(fsp); fc_fcp_srr() 1698 fsp, jiffies_to_msecs(rec_tov)); fc_fcp_srr() 1702 fsp->recov_seq = seq; fc_fcp_srr() 1703 fsp->xfer_len = offset; fc_fcp_srr() 1704 fsp->xfer_contig_end = offset; fc_fcp_srr() 1705 fsp->state &= ~FC_SRB_RCV_STATUS; fc_fcp_srr() 1706 fc_fcp_pkt_hold(fsp); /* hold for outstanding SRR */ fc_fcp_srr() 1709 fc_fcp_retry_cmd(fsp); fc_fcp_srr() 1720 struct fc_fcp_pkt *fsp = arg; fc_fcp_srr_resp() local 1724 fc_fcp_srr_error(fsp, fp); fc_fcp_srr_resp() 1728 if (fc_fcp_lock_pkt(fsp)) fc_fcp_srr_resp() 1740 fc_fcp_unlock_pkt(fsp); fc_fcp_srr_resp() 1746 fsp->recov_retry = 0; fc_fcp_srr_resp() 1747 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp)); fc_fcp_srr_resp() 1751 fc_fcp_recovery(fsp, FC_ERROR); fc_fcp_srr_resp() 1754 fc_fcp_unlock_pkt(fsp); fc_fcp_srr_resp() 1756 fsp->lp->tt.exch_done(seq); fc_fcp_srr_resp() 1762 * @fsp: The FCP packet that the SRR error is on 1765 static void fc_fcp_srr_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) fc_fcp_srr_error() argument 1767 if (fc_fcp_lock_pkt(fsp)) fc_fcp_srr_error() 1771 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) fc_fcp_srr_error() 1772 fc_fcp_rec(fsp); fc_fcp_srr_error() 1774 fc_fcp_recovery(fsp, FC_TIMED_OUT); fc_fcp_srr_error() 1779 fc_fcp_retry_cmd(fsp); fc_fcp_srr_error() 1782 fc_fcp_unlock_pkt(fsp); fc_fcp_srr_error() 1784 fsp->lp->tt.exch_done(fsp->recov_seq); fc_fcp_srr_error() 1809 struct fc_fcp_pkt *fsp; fc_queuecommand() local 1841 fsp = fc_fcp_pkt_alloc(lport, GFP_ATOMIC); fc_queuecommand() 1842 if (fsp == NULL) { fc_queuecommand() 1850 fsp->cmd = sc_cmd; /* save the cmd */ fc_queuecommand() 1851 fsp->rport = rport; /* set the remote port ptr */ fc_queuecommand() 1856 fsp->data_len = scsi_bufflen(sc_cmd); fc_queuecommand() 1857 fsp->xfer_len = 0; fc_queuecommand() 1864 fsp->req_flags = FC_SRB_READ; fc_queuecommand() 1866 stats->InputBytes += fsp->data_len; fc_queuecommand() 1868 fsp->req_flags = FC_SRB_WRITE; fc_queuecommand() 1870 stats->OutputBytes += fsp->data_len; fc_queuecommand() 1872 fsp->req_flags = 0; fc_queuecommand() 1882 rval = fc_fcp_pkt_send(lport, fsp); fc_queuecommand() 1884 fsp->state = FC_SRB_FREE; fc_queuecommand() 1885 fc_fcp_pkt_release(fsp); fc_queuecommand() 1895 * @fsp: The FCP packet that is complete 1900 static void fc_io_compl(struct fc_fcp_pkt *fsp) fc_io_compl() argument 1908 fc_fcp_ddp_done(fsp); fc_io_compl() 1910 fsp->state |= FC_SRB_COMPL; fc_io_compl() 1911 if (!(fsp->state & FC_SRB_FCP_PROCESSING_TMO)) { fc_io_compl() 1912 spin_unlock_bh(&fsp->scsi_pkt_lock); fc_io_compl() 1913 del_timer_sync(&fsp->timer); fc_io_compl() 1914 spin_lock_bh(&fsp->scsi_pkt_lock); fc_io_compl() 1917 lport = fsp->lp; fc_io_compl() 1927 sc_cmd = fsp->cmd; fc_io_compl() 1928 CMD_SCSI_STATUS(sc_cmd) = fsp->cdb_status; fc_io_compl() 1929 switch (fsp->status_code) { fc_io_compl() 1931 if (fsp->cdb_status == 0) { fc_io_compl() 1936 if (fsp->scsi_resid) fc_io_compl() 1937 CMD_RESID_LEN(sc_cmd) = fsp->scsi_resid; fc_io_compl() 1943 sc_cmd->result = (DID_OK << 16) | fsp->cdb_status; fc_io_compl() 1947 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " fc_io_compl() 1952 if ((fsp->cdb_status == 0) && !(fsp->req_flags & FC_SRB_READ)) { fc_io_compl() 1957 if (fsp->state & FC_SRB_RCV_STATUS) { fc_io_compl() 1960 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml" fc_io_compl() 1968 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " fc_io_compl() 1970 CMD_RESID_LEN(sc_cmd) = fsp->scsi_resid; fc_io_compl() 1971 sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status; fc_io_compl() 1978 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " fc_io_compl() 1980 sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status; fc_io_compl() 1983 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " fc_io_compl() 1985 sc_cmd->result = (DID_ERROR << 16) | fsp->io_status; fc_io_compl() 1988 FC_FCP_DBG(fsp, "Returning DID_RESET to scsi-ml " fc_io_compl() 1993 FC_FCP_DBG(fsp, "Returning DID_NO_CONNECT to scsi-ml " fc_io_compl() 1998 FC_FCP_DBG(fsp, "Returning DID_PARITY to scsi-ml " fc_io_compl() 2003 FC_FCP_DBG(fsp, "Returning DID_BUS_BUSY to scsi-ml " fc_io_compl() 2005 sc_cmd->result = (DID_BUS_BUSY << 16) | fsp->io_status; fc_io_compl() 2008 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml " fc_io_compl() 2014 if (lport->state != LPORT_ST_READY && fsp->status_code != FC_COMPLETE) fc_io_compl() 2018 list_del(&fsp->list); fc_io_compl() 2024 fc_fcp_pkt_release(fsp); fc_io_compl() 2036 struct fc_fcp_pkt *fsp; fc_eh_abort() local 2055 fsp = CMD_SP(sc_cmd); fc_eh_abort() 2056 if (!fsp) { fc_eh_abort() 2061 /* grab a ref so the fsp and sc_cmd cannot be released from under us */ fc_eh_abort() 2062 fc_fcp_pkt_hold(fsp); fc_eh_abort() 2065 if (fc_fcp_lock_pkt(fsp)) { fc_eh_abort() 2071 rc = fc_fcp_pkt_abort(fsp); fc_eh_abort() 2072 fc_fcp_unlock_pkt(fsp); fc_eh_abort() 2075 fc_fcp_pkt_release(fsp); fc_eh_abort() 2090 struct fc_fcp_pkt *fsp; fc_eh_device_reset() local 2106 fsp = fc_fcp_pkt_alloc(lport, GFP_NOIO); fc_eh_device_reset() 2107 if (fsp == NULL) { fc_eh_device_reset() 2117 fsp->rport = rport; /* set the remote port ptr */ fc_eh_device_reset() 2122 rc = fc_lun_reset(lport, fsp, scmd_id(sc_cmd), sc_cmd->device->lun); fc_eh_device_reset() 2123 fsp->state = FC_SRB_FREE; fc_eh_device_reset() 2124 fc_fcp_pkt_release(fsp); fc_eh_device_reset()
|