Lines Matching refs:fsp
138 struct fc_fcp_pkt *fsp;
140 fsp = mempool_alloc(si->scsi_pkt_pool, gfp);
141 if (fsp) {
142 memset(fsp, 0, sizeof(*fsp));
143 fsp->lp = lport;
144 fsp->xfer_ddp = FC_XID_UNKNOWN;
145 refcount_set(&fsp->ref_cnt, 1);
146 timer_setup(&fsp->timer, NULL, 0);
147 INIT_LIST_HEAD(&fsp->list);
148 spin_lock_init(&fsp->scsi_pkt_lock);
153 return fsp;
158 * @fsp: The FCP packet to be released
163 static void fc_fcp_pkt_release(struct fc_fcp_pkt *fsp)
165 if (refcount_dec_and_test(&fsp->ref_cnt)) {
166 struct fc_fcp_internal *si = fc_get_scsi_internal(fsp->lp);
168 mempool_free(fsp, si->scsi_pkt_pool);
174 * @fsp: The FCP packet to be held
176 static void fc_fcp_pkt_hold(struct fc_fcp_pkt *fsp)
178 refcount_inc(&fsp->ref_cnt);
184 * @fsp: The FCP packet to be released
192 static void fc_fcp_pkt_destroy(struct fc_seq *seq, void *fsp)
194 fc_fcp_pkt_release(fsp);
199 * @fsp: The FCP packet to be locked and incremented
211 * have a function that they call to verify the fsp and grab a ref if
214 static inline int fc_fcp_lock_pkt(struct fc_fcp_pkt *fsp)
216 spin_lock_bh(&fsp->scsi_pkt_lock);
217 if (fsp->state & FC_SRB_COMPL) {
218 spin_unlock_bh(&fsp->scsi_pkt_lock);
222 fc_fcp_pkt_hold(fsp);
229 * @fsp: The FCP packet to be unlocked and decremented
231 static inline void fc_fcp_unlock_pkt(struct fc_fcp_pkt *fsp)
233 spin_unlock_bh(&fsp->scsi_pkt_lock);
234 fc_fcp_pkt_release(fsp);
239 * @fsp: The FCP packet to start a timer for
242 static void fc_fcp_timer_set(struct fc_fcp_pkt *fsp, unsigned long delay)
244 if (!(fsp->state & FC_SRB_COMPL)) {
245 mod_timer(&fsp->timer, jiffies + delay);
246 fsp->timer_delay = delay;
250 static void fc_fcp_abort_done(struct fc_fcp_pkt *fsp)
252 fsp->state |= FC_SRB_ABORTED;
253 fsp->state &= ~FC_SRB_ABORT_PENDING;
255 if (fsp->wait_for_comp)
256 complete(&fsp->tm_done);
258 fc_fcp_complete_locked(fsp);
264 * @fsp: The FCP packet to abort exchanges on
266 static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp)
270 if (!fsp->seq_ptr)
273 if (fsp->state & FC_SRB_ABORT_PENDING) {
274 FC_FCP_DBG(fsp, "abort already pending\n");
278 per_cpu_ptr(fsp->lp->stats, get_cpu())->FcpPktAborts++;
281 fsp->state |= FC_SRB_ABORT_PENDING;
282 rc = fc_seq_exch_abort(fsp->seq_ptr, 0);
288 fc_fcp_abort_done(fsp);
296 * @fsp: The FCP packet to be retried
304 static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp, int status_code)
306 if (fsp->seq_ptr) {
307 fc_exch_done(fsp->seq_ptr);
308 fsp->seq_ptr = NULL;
311 fsp->state &= ~FC_SRB_ABORT_PENDING;
312 fsp->io_status = 0;
313 fsp->status_code = status_code;
314 fc_fcp_complete_locked(fsp);
319 * @fsp: The FCP packet that will manage the DDP frames
322 void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid)
326 lport = fsp->lp;
327 if ((fsp->req_flags & FC_SRB_READ) &&
329 if (lport->tt.ddp_setup(lport, xid, scsi_sglist(fsp->cmd),
330 scsi_sg_count(fsp->cmd)))
331 fsp->xfer_ddp = xid;
338 * @fsp: The FCP packet that DDP had been used on
340 void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp)
344 if (!fsp)
347 if (fsp->xfer_ddp == FC_XID_UNKNOWN)
350 lport = fsp->lp;
352 fsp->xfer_len = lport->tt.ddp_done(lport, fsp->xfer_ddp);
353 fsp->xfer_ddp = FC_XID_UNKNOWN;
460 * @fsp: the FCP packet
464 static inline unsigned int get_fsp_rec_tov(struct fc_fcp_pkt *fsp)
466 struct fc_rport_libfc_priv *rpriv = fsp->rport->dd_data;
476 * @fsp: The FCP packet the data is on
479 static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
481 struct scsi_cmnd *sc = fsp->cmd;
482 struct fc_lport *lport = fsp->lp;
508 if (fsp->xfer_ddp != FC_XID_UNKNOWN) {
509 fc_fcp_ddp_done(fsp);
510 FC_FCP_DBG(fsp, "DDP I/O in fc_fcp_recv_data set ERROR\n");
514 if (offset + len > fsp->data_len) {
519 FC_FCP_DBG(fsp, "data received past end. len %zx offset %zx "
520 "data_len %x\n", len, offset, fsp->data_len);
526 if (offset != fsp->xfer_len)
527 fsp->state |= FC_SRB_DISCONTIG;
560 if (fsp->state & FC_SRB_DISCONTIG) {
568 if (fsp->xfer_contig_end == start_offset)
569 fsp->xfer_contig_end += copy_len;
570 fsp->xfer_len += copy_len;
576 if (unlikely(fsp->state & FC_SRB_RCV_STATUS) &&
577 fsp->xfer_len == fsp->data_len - fsp->scsi_resid) {
578 FC_FCP_DBG( fsp, "complete out-of-order sequence\n" );
579 fc_fcp_complete_locked(fsp);
583 fc_fcp_recovery(fsp, host_bcode);
588 * @fsp: The FCP packet the data is on
599 static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq,
606 struct fc_lport *lport = fsp->lp;
621 if (unlikely(offset + seq_blen > fsp->data_len)) {
623 FC_FCP_DBG(fsp, "xfer-ready past end. seq_blen %zx "
625 fc_fcp_send_abort(fsp);
627 } else if (offset != fsp->xfer_len) {
629 FC_FCP_DBG(fsp, "xfer-ready non-contiguous. "
636 * to max FC frame payload previously set in fsp->max_payload.
638 t_blen = fsp->max_payload;
641 FC_FCP_DBG(fsp, "fsp=%p:lso:blen=%zx lso_max=0x%x t_blen=%zx\n",
642 fsp, seq_blen, lport->lso_max, t_blen);
647 sc = fsp->cmd;
680 fr_max_payload(fp) = fsp->max_payload;
737 fsp->xfer_len += seq_blen; /* premature count? */
743 * @fsp: The FCP packet that is being aborted
746 static void fc_fcp_abts_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
771 fc_fcp_abort_done(fsp);
785 struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)arg;
786 struct fc_lport *lport = fsp->lp;
793 fc_fcp_error(fsp, fp);
801 FC_FCP_DBG(fsp, "lport state %d, ignoring r_ctl %x\n",
805 if (fc_fcp_lock_pkt(fsp))
809 fc_fcp_abts_resp(fsp, fp);
813 if (fsp->state & (FC_SRB_ABORTED | FC_SRB_ABORT_PENDING)) {
814 FC_FCP_DBG(fsp, "command aborted, ignoring r_ctl %x\n", r_ctl);
827 rc = fc_fcp_send_data(fsp, seq,
831 seq->rec_data = fsp->xfer_len;
838 fc_fcp_recv_data(fsp, fp);
839 seq->rec_data = fsp->xfer_contig_end;
843 fc_fcp_resp(fsp, fp);
845 FC_FCP_DBG(fsp, "unexpected frame. r_ctl %x\n", r_ctl);
848 fc_fcp_unlock_pkt(fsp);
855 * @fsp: The FCP packet the response is for
858 static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
876 fsp->cdb_status = fc_rp->fr_status;
878 fsp->scsi_comp_flags = flags;
879 expected_len = fsp->data_len;
882 fc_fcp_ddp_done(fsp);
895 if (fsp->wait_for_comp) {
897 fsp->cdb_status = fc_rp_info->rsp_code;
898 complete(&fsp->tm_done);
910 memcpy(fsp->cmd->sense_buffer,
918 fsp->scsi_resid = ntohl(rp_ex->fr_resid);
929 (scsi_bufflen(fsp->cmd) -
930 fsp->scsi_resid) < fsp->cmd->underflow)
932 expected_len -= fsp->scsi_resid;
934 fsp->status_code = FC_ERROR;
938 fsp->state |= FC_SRB_RCV_STATUS;
943 if (unlikely(fsp->cdb_status == SAM_STAT_GOOD &&
944 fsp->xfer_len != expected_len)) {
945 if (fsp->xfer_len < expected_len) {
951 if (fsp->lp->qfull) {
952 FC_FCP_DBG(fsp, "tgt %6.6x queue busy retry\n",
953 fsp->rport->port_id);
956 FC_FCP_DBG(fsp, "tgt %6.6x xfer len %zx data underrun "
958 fsp->rport->port_id,
959 fsp->xfer_len, expected_len, fsp->data_len);
960 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
963 fsp->status_code = FC_DATA_OVRRUN;
964 FC_FCP_DBG(fsp, "tgt %6.6x xfer len %zx greater than expected, "
966 fsp->rport->port_id,
967 fsp->xfer_len, expected_len, fsp->data_len);
969 fc_fcp_complete_locked(fsp);
973 FC_FCP_DBG(fsp, "short FCP response. flags 0x%x len %u respl %u "
976 fsp->status_code = FC_ERROR;
977 fc_fcp_complete_locked(fsp);
983 * @fsp: The FCP packet to be completed
988 static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp)
990 struct fc_lport *lport = fsp->lp;
995 if (fsp->state & FC_SRB_ABORT_PENDING)
998 if (fsp->state & FC_SRB_ABORTED) {
999 if (!fsp->status_code)
1000 fsp->status_code = FC_CMD_ABORTED;
1006 if (fsp->cdb_status == SAM_STAT_GOOD &&
1007 fsp->xfer_len < fsp->data_len && !fsp->io_status &&
1008 (!(fsp->scsi_comp_flags & FCP_RESID_UNDER) ||
1009 fsp->xfer_len < fsp->data_len - fsp->scsi_resid)) {
1010 FC_FCP_DBG(fsp, "data underrun, xfer %zx data %x\n",
1011 fsp->xfer_len, fsp->data_len);
1012 fsp->status_code = FC_DATA_UNDRUN;
1016 seq = fsp->seq_ptr;
1018 fsp->seq_ptr = NULL;
1019 if (unlikely(fsp->scsi_comp_flags & FCP_CONF_REQ)) {
1024 conf_frame = fc_fcp_frame_alloc(fsp->lp, 0);
1042 if (fsp->cmd)
1043 fc_io_compl(fsp);
1048 * @fsp: The FCP packet whose exchanges should be canceled
1051 static void fc_fcp_cleanup_cmd(struct fc_fcp_pkt *fsp, int error)
1053 if (fsp->seq_ptr) {
1054 fc_exch_done(fsp->seq_ptr);
1055 fsp->seq_ptr = NULL;
1057 fsp->status_code = error;
1073 struct fc_fcp_pkt *fsp;
1079 list_for_each_entry(fsp, &si->scsi_pkt_queue, list) {
1080 sc_cmd = fsp->cmd;
1087 fc_fcp_pkt_hold(fsp);
1090 spin_lock_bh(&fsp->scsi_pkt_lock);
1091 if (!(fsp->state & FC_SRB_COMPL)) {
1092 fsp->state |= FC_SRB_COMPL;
1102 spin_unlock_bh(&fsp->scsi_pkt_lock);
1104 fc_fcp_cleanup_cmd(fsp, error);
1106 spin_lock_bh(&fsp->scsi_pkt_lock);
1107 fc_io_compl(fsp);
1109 spin_unlock_bh(&fsp->scsi_pkt_lock);
1111 fc_fcp_pkt_release(fsp);
1134 * @fsp: The FCP packet to send
1139 static int fc_fcp_pkt_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp)
1145 fsp->cmd->SCp.ptr = (char *)fsp;
1146 fsp->cdb_cmd.fc_dl = htonl(fsp->data_len);
1147 fsp->cdb_cmd.fc_flags = fsp->req_flags & ~FCP_CFL_LEN_MASK;
1149 int_to_scsilun(fsp->cmd->device->lun, &fsp->cdb_cmd.fc_lun);
1150 memcpy(fsp->cdb_cmd.fc_cdb, fsp->cmd->cmnd, fsp->cmd->cmd_len);
1153 list_add_tail(&fsp->list, &si->scsi_pkt_queue);
1155 rc = lport->tt.fcp_cmd_send(lport, fsp, fc_fcp_recv);
1158 fsp->cmd->SCp.ptr = NULL;
1159 list_del(&fsp->list);
1169 * @fsp: The FCP packet the command is on
1172 static int fc_fcp_cmd_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp,
1181 const size_t len = sizeof(fsp->cdb_cmd);
1184 if (fc_fcp_lock_pkt(fsp))
1187 fp = fc_fcp_frame_alloc(lport, sizeof(fsp->cdb_cmd));
1193 memcpy(fc_frame_payload_get(fp, len), &fsp->cdb_cmd, len);
1194 fr_fsp(fp) = fsp;
1195 rport = fsp->rport;
1196 fsp->max_payload = rport->maxframe_size;
1203 seq = fc_exch_seq_send(lport, fp, resp, fc_fcp_pkt_destroy, fsp, 0);
1208 fsp->seq_ptr = seq;
1209 fc_fcp_pkt_hold(fsp); /* hold for fc_fcp_pkt_destroy */
1211 fsp->timer.function = fc_fcp_timeout;
1213 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
1216 fc_fcp_unlock_pkt(fsp);
1222 * @fsp: The FCP packet the error is on
1225 static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
1229 if (fc_fcp_lock_pkt(fsp))
1233 fc_fcp_retry_cmd(fsp, FC_ERROR);
1241 fsp->state &= ~FC_SRB_ABORT_PENDING;
1242 fsp->status_code = FC_CMD_PLOGO;
1243 fc_fcp_complete_locked(fsp);
1245 fc_fcp_unlock_pkt(fsp);
1250 * @fsp: The FCP packet to abort on
1254 static int fc_fcp_pkt_abort(struct fc_fcp_pkt *fsp)
1259 FC_FCP_DBG(fsp, "pkt abort state %x\n", fsp->state);
1260 if (fc_fcp_send_abort(fsp)) {
1261 FC_FCP_DBG(fsp, "failed to send abort\n");
1265 if (fsp->state & FC_SRB_ABORTED) {
1266 FC_FCP_DBG(fsp, "target abort cmd completed\n");
1270 init_completion(&fsp->tm_done);
1271 fsp->wait_for_comp = 1;
1273 spin_unlock_bh(&fsp->scsi_pkt_lock);
1274 ticks_left = wait_for_completion_timeout(&fsp->tm_done,
1276 spin_lock_bh(&fsp->scsi_pkt_lock);
1277 fsp->wait_for_comp = 0;
1280 FC_FCP_DBG(fsp, "target abort cmd failed\n");
1281 } else if (fsp->state & FC_SRB_ABORTED) {
1282 FC_FCP_DBG(fsp, "target abort cmd passed\n");
1284 fc_fcp_complete_locked(fsp);
1296 struct fc_fcp_pkt *fsp = from_timer(fsp, t, timer);
1297 struct fc_lport *lport = fsp->lp;
1299 if (lport->tt.fcp_cmd_send(lport, fsp, fc_tm_done)) {
1300 if (fsp->recov_retry++ >= FC_MAX_RECOV_RETRY)
1302 if (fc_fcp_lock_pkt(fsp))
1304 fsp->timer.function = fc_lun_reset_send;
1305 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
1306 fc_fcp_unlock_pkt(fsp);
1314 * @fsp: The FCP packet that identifies the LUN to be reset
1318 static int fc_lun_reset(struct fc_lport *lport, struct fc_fcp_pkt *fsp,
1323 fsp->cdb_cmd.fc_dl = htonl(fsp->data_len);
1324 fsp->cdb_cmd.fc_tm_flags = FCP_TMF_LUN_RESET;
1325 int_to_scsilun(lun, &fsp->cdb_cmd.fc_lun);
1327 fsp->wait_for_comp = 1;
1328 init_completion(&fsp->tm_done);
1330 fc_lun_reset_send(&fsp->timer);
1336 rc = wait_for_completion_timeout(&fsp->tm_done, FC_SCSI_TM_TOV);
1338 spin_lock_bh(&fsp->scsi_pkt_lock);
1339 fsp->state |= FC_SRB_COMPL;
1340 spin_unlock_bh(&fsp->scsi_pkt_lock);
1342 del_timer_sync(&fsp->timer);
1344 spin_lock_bh(&fsp->scsi_pkt_lock);
1345 if (fsp->seq_ptr) {
1346 fc_exch_done(fsp->seq_ptr);
1347 fsp->seq_ptr = NULL;
1349 fsp->wait_for_comp = 0;
1350 spin_unlock_bh(&fsp->scsi_pkt_lock);
1358 if (fsp->cdb_status != FCP_TMF_CMPL)
1374 struct fc_fcp_pkt *fsp = arg;
1387 if (fc_fcp_lock_pkt(fsp))
1393 if (!fsp->seq_ptr || !fsp->wait_for_comp)
1398 fc_fcp_resp(fsp, fp);
1399 fsp->seq_ptr = NULL;
1402 fc_fcp_unlock_pkt(fsp);
1429 struct fc_fcp_pkt *fsp = from_timer(fsp, t, timer);
1430 struct fc_rport *rport = fsp->rport;
1433 if (fc_fcp_lock_pkt(fsp))
1436 if (fsp->cdb_cmd.fc_tm_flags)
1439 if (fsp->lp->qfull) {
1440 FC_FCP_DBG(fsp, "fcp timeout, resetting timer delay %d\n",
1441 fsp->timer_delay);
1442 fsp->timer.function = fc_fcp_timeout;
1443 fc_fcp_timer_set(fsp, fsp->timer_delay);
1446 FC_FCP_DBG(fsp, "fcp timeout, delay %d flags %x state %x\n",
1447 fsp->timer_delay, rpriv->flags, fsp->state);
1448 fsp->state |= FC_SRB_FCP_PROCESSING_TMO;
1451 fc_fcp_rec(fsp);
1452 else if (fsp->state & FC_SRB_RCV_STATUS)
1453 fc_fcp_complete_locked(fsp);
1455 fc_fcp_recovery(fsp, FC_TIMED_OUT);
1456 fsp->state &= ~FC_SRB_FCP_PROCESSING_TMO;
1458 fc_fcp_unlock_pkt(fsp);
1463 * @fsp: The FCP packet to send the REC request on
1465 static void fc_fcp_rec(struct fc_fcp_pkt *fsp)
1472 lport = fsp->lp;
1473 rport = fsp->rport;
1475 if (!fsp->seq_ptr || rpriv->rp_state != RPORT_ST_READY) {
1476 fsp->status_code = FC_HRD_ERROR;
1477 fsp->io_status = 0;
1478 fc_fcp_complete_locked(fsp);
1486 fr_seq(fp) = fsp->seq_ptr;
1491 fc_fcp_rec_resp, fsp,
1493 fc_fcp_pkt_hold(fsp); /* hold while REC outstanding */
1497 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY)
1498 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
1500 fc_fcp_recovery(fsp, FC_TIMED_OUT);
1516 struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)arg;
1527 fc_fcp_rec_error(fsp, fp);
1531 if (fc_fcp_lock_pkt(fsp))
1534 fsp->recov_retry = 0;
1540 FC_FCP_DBG(fsp,
1542 fsp->rport->port_id, rjt->er_reason,
1546 FC_FCP_DBG(fsp, "device does not support REC\n");
1547 rpriv = fsp->rport->dd_data;
1557 FC_FCP_DBG(fsp, "device %x REC reject %d/%d\n",
1558 fsp->rport->port_id, rjt->er_reason,
1567 struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr);
1569 fsp->state |= FC_SRB_ABORTED;
1570 fc_fcp_retry_cmd(fsp, FC_TRANS_RESET);
1573 fc_fcp_recovery(fsp, FC_TRANS_RESET);
1577 if (fsp->state & FC_SRB_ABORTED)
1580 data_dir = fsp->cmd->sc_data_direction;
1603 } else if (fsp->xfer_contig_end == offset) {
1606 offset = fsp->xfer_contig_end;
1609 fc_fcp_srr(fsp, r_ctl, offset);
1615 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
1636 if (offset < fsp->data_len)
1638 } else if (offset == fsp->xfer_contig_end) {
1640 } else if (fsp->xfer_contig_end < offset) {
1641 offset = fsp->xfer_contig_end;
1643 fc_fcp_srr(fsp, r_ctl, offset);
1647 fc_fcp_unlock_pkt(fsp);
1649 fc_fcp_pkt_release(fsp); /* drop hold for outstanding REC */
1655 * @fsp: The FCP packet the error is on
1658 static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
1662 if (fc_fcp_lock_pkt(fsp))
1667 FC_FCP_DBG(fsp, "REC %p fid %6.6x exchange closed\n",
1668 fsp, fsp->rport->port_id);
1669 fc_fcp_retry_cmd(fsp, FC_ERROR);
1673 FC_FCP_DBG(fsp, "REC %p fid %6.6x error unexpected error %d\n",
1674 fsp, fsp->rport->port_id, error);
1675 fsp->status_code = FC_CMD_PLOGO;
1683 FC_FCP_DBG(fsp, "REC %p fid %6.6x exchange timeout retry %d/%d\n",
1684 fsp, fsp->rport->port_id, fsp->recov_retry,
1686 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY)
1687 fc_fcp_rec(fsp);
1689 fc_fcp_recovery(fsp, FC_TIMED_OUT);
1692 fc_fcp_unlock_pkt(fsp);
1694 fc_fcp_pkt_release(fsp); /* drop hold for outstanding REC */
1699 * @fsp: The FCP pkt that needs to be aborted
1702 static void fc_fcp_recovery(struct fc_fcp_pkt *fsp, u8 code)
1704 FC_FCP_DBG(fsp, "start recovery code %x\n", code);
1705 fsp->status_code = code;
1706 fsp->cdb_status = 0;
1707 fsp->io_status = 0;
1708 if (!fsp->cmd)
1713 fc_fcp_send_abort(fsp);
1718 * @fsp: The FCP packet the SRR is to be sent on
1724 static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum fc_rctl r_ctl, u32 offset)
1726 struct fc_lport *lport = fsp->lp;
1729 struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr);
1734 rport = fsp->rport;
1758 fsp, get_fsp_rec_tov(fsp));
1762 fsp->recov_seq = seq;
1763 fsp->xfer_len = offset;
1764 fsp->xfer_contig_end = offset;
1765 fsp->state &= ~FC_SRB_RCV_STATUS;
1766 fc_fcp_pkt_hold(fsp); /* hold for outstanding SRR */
1769 fc_fcp_retry_cmd(fsp, FC_TRANS_RESET);
1780 struct fc_fcp_pkt *fsp = arg;
1784 fc_fcp_srr_error(fsp, fp);
1788 if (fc_fcp_lock_pkt(fsp))
1800 fc_fcp_unlock_pkt(fsp);
1806 fsp->recov_retry = 0;
1807 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
1811 fc_fcp_recovery(fsp, FC_ERROR);
1814 fc_fcp_unlock_pkt(fsp);
1822 * @fsp: The FCP packet that the SRR error is on
1825 static void fc_fcp_srr_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
1827 if (fc_fcp_lock_pkt(fsp))
1831 FC_FCP_DBG(fsp, "SRR timeout, retries %d\n", fsp->recov_retry);
1832 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY)
1833 fc_fcp_rec(fsp);
1835 fc_fcp_recovery(fsp, FC_TIMED_OUT);
1838 FC_FCP_DBG(fsp, "SRR error, exchange closed\n");
1841 fc_fcp_retry_cmd(fsp, FC_ERROR);
1844 fc_fcp_unlock_pkt(fsp);
1846 fc_exch_done(fsp->recov_seq);
1871 struct fc_fcp_pkt *fsp;
1905 fsp = fc_fcp_pkt_alloc(lport, GFP_ATOMIC);
1906 if (fsp == NULL) {
1914 fsp->cmd = sc_cmd; /* save the cmd */
1915 fsp->rport = rport; /* set the remote port ptr */
1920 fsp->data_len = scsi_bufflen(sc_cmd);
1921 fsp->xfer_len = 0;
1928 fsp->req_flags = FC_SRB_READ;
1930 stats->InputBytes += fsp->data_len;
1932 fsp->req_flags = FC_SRB_WRITE;
1934 stats->OutputBytes += fsp->data_len;
1936 fsp->req_flags = 0;
1946 rval = fc_fcp_pkt_send(lport, fsp);
1948 fsp->state = FC_SRB_FREE;
1949 fc_fcp_pkt_release(fsp);
1959 * @fsp: The FCP packet that is complete
1964 static void fc_io_compl(struct fc_fcp_pkt *fsp)
1972 fc_fcp_ddp_done(fsp);
1974 fsp->state |= FC_SRB_COMPL;
1975 if (!(fsp->state & FC_SRB_FCP_PROCESSING_TMO)) {
1976 spin_unlock_bh(&fsp->scsi_pkt_lock);
1977 del_timer_sync(&fsp->timer);
1978 spin_lock_bh(&fsp->scsi_pkt_lock);
1981 lport = fsp->lp;
1991 sc_cmd = fsp->cmd;
1992 CMD_SCSI_STATUS(sc_cmd) = fsp->cdb_status;
1993 switch (fsp->status_code) {
1995 if (fsp->cdb_status == 0) {
2000 if (fsp->scsi_resid)
2001 CMD_RESID_LEN(sc_cmd) = fsp->scsi_resid;
2007 sc_cmd->result = (DID_OK << 16) | fsp->cdb_status;
2011 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
2016 if ((fsp->cdb_status == 0) && !(fsp->req_flags & FC_SRB_READ)) {
2021 if (fsp->state & FC_SRB_RCV_STATUS) {
2024 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml"
2032 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
2034 CMD_RESID_LEN(sc_cmd) = fsp->scsi_resid;
2035 sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status;
2042 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
2044 sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status;
2048 FC_FCP_DBG(fsp, "Returning DID_TIME_OUT to scsi-ml "
2051 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
2055 sc_cmd->result |= fsp->io_status;
2058 FC_FCP_DBG(fsp, "Returning DID_RESET to scsi-ml "
2063 FC_FCP_DBG(fsp, "Returning DID_SOFT_ERROR to scsi-ml "
2068 FC_FCP_DBG(fsp, "Returning DID_NO_CONNECT to scsi-ml "
2073 FC_FCP_DBG(fsp, "Returning DID_PARITY to scsi-ml "
2078 FC_FCP_DBG(fsp, "Returning DID_BUS_BUSY to scsi-ml "
2080 sc_cmd->result = (DID_BUS_BUSY << 16) | fsp->io_status;
2083 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
2089 if (lport->state != LPORT_ST_READY && fsp->status_code != FC_COMPLETE)
2093 list_del(&fsp->list);
2099 fc_fcp_pkt_release(fsp);
2111 struct fc_fcp_pkt *fsp;
2130 fsp = CMD_SP(sc_cmd);
2131 if (!fsp) {
2136 /* grab a ref so the fsp and sc_cmd cannot be released from under us */
2137 fc_fcp_pkt_hold(fsp);
2140 if (fc_fcp_lock_pkt(fsp)) {
2146 rc = fc_fcp_pkt_abort(fsp);
2147 fc_fcp_unlock_pkt(fsp);
2150 fc_fcp_pkt_release(fsp);
2165 struct fc_fcp_pkt *fsp;
2181 fsp = fc_fcp_pkt_alloc(lport, GFP_NOIO);
2182 if (fsp == NULL) {
2192 fsp->rport = rport; /* set the remote port ptr */
2197 rc = fc_lun_reset(lport, fsp, scmd_id(sc_cmd), sc_cmd->device->lun);
2198 fsp->state = FC_SRB_FREE;
2199 fc_fcp_pkt_release(fsp);