1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/module.h>
23#include <linux/delay.h>
24#include <linux/kernel.h>
25#include <linux/types.h>
26#include <linux/spinlock.h>
27#include <linux/scatterlist.h>
28#include <linux/err.h>
29#include <linux/crc32.h>
30#include <linux/slab.h>
31
32#include <scsi/scsi_tcq.h>
33#include <scsi/scsi.h>
34#include <scsi/scsi_host.h>
35#include <scsi/scsi_device.h>
36#include <scsi/scsi_cmnd.h>
37
38#include <scsi/fc/fc_fc2.h>
39
40#include <scsi/libfc.h>
41#include <scsi/fc_encode.h>
42
43#include "fc_libfc.h"
44
45static struct kmem_cache *scsi_pkt_cachep;
46
47
48#define FC_SRB_FREE 0
49#define FC_SRB_CMD_SENT (1 << 0)
50#define FC_SRB_RCV_STATUS (1 << 1)
51#define FC_SRB_ABORT_PENDING (1 << 2)
52#define FC_SRB_ABORTED (1 << 3)
53#define FC_SRB_DISCONTIG (1 << 4)
54#define FC_SRB_COMPL (1 << 5)
55#define FC_SRB_FCP_PROCESSING_TMO (1 << 6)
56
57#define FC_SRB_READ (1 << 1)
58#define FC_SRB_WRITE (1 << 0)
59
60
61
62
63#define CMD_SP(Cmnd) ((struct fc_fcp_pkt *)(Cmnd)->SCp.ptr)
64#define CMD_ENTRY_STATUS(Cmnd) ((Cmnd)->SCp.have_data_in)
65#define CMD_COMPL_STATUS(Cmnd) ((Cmnd)->SCp.this_residual)
66#define CMD_SCSI_STATUS(Cmnd) ((Cmnd)->SCp.Status)
67#define CMD_RESID_LEN(Cmnd) ((Cmnd)->SCp.buffers_residual)
68
69
70
71
72
73
74
75
76
77
78struct fc_fcp_internal {
79 mempool_t *scsi_pkt_pool;
80 spinlock_t scsi_queue_lock;
81 struct list_head scsi_pkt_queue;
82 unsigned long last_can_queue_ramp_down_time;
83 unsigned long last_can_queue_ramp_up_time;
84 int max_can_queue;
85};
86
87#define fc_get_scsi_internal(x) ((struct fc_fcp_internal *)(x)->scsi_priv)
88
89
90
91
92
93static void fc_fcp_recv_data(struct fc_fcp_pkt *, struct fc_frame *);
94static void fc_fcp_recv(struct fc_seq *, struct fc_frame *, void *);
95static void fc_fcp_resp(struct fc_fcp_pkt *, struct fc_frame *);
96static void fc_fcp_complete_locked(struct fc_fcp_pkt *);
97static void fc_tm_done(struct fc_seq *, struct fc_frame *, void *);
98static void fc_fcp_error(struct fc_fcp_pkt *, struct fc_frame *);
99static void fc_fcp_recovery(struct fc_fcp_pkt *, u8 code);
100static void fc_fcp_timeout(struct timer_list *);
101static void fc_fcp_rec(struct fc_fcp_pkt *);
102static void fc_fcp_rec_error(struct fc_fcp_pkt *, struct fc_frame *);
103static void fc_fcp_rec_resp(struct fc_seq *, struct fc_frame *, void *);
104static void fc_io_compl(struct fc_fcp_pkt *);
105
106static void fc_fcp_srr(struct fc_fcp_pkt *, enum fc_rctl, u32);
107static void fc_fcp_srr_resp(struct fc_seq *, struct fc_frame *, void *);
108static void fc_fcp_srr_error(struct fc_fcp_pkt *, struct fc_frame *);
109
110
111
112
113#define FC_COMPLETE 0
114#define FC_CMD_ABORTED 1
115#define FC_CMD_RESET 2
116#define FC_CMD_PLOGO 3
117#define FC_SNS_RCV 4
118#define FC_TRANS_ERR 5
119#define FC_DATA_OVRRUN 6
120#define FC_DATA_UNDRUN 7
121#define FC_ERROR 8
122#define FC_HRD_ERROR 9
123#define FC_CRC_ERROR 10
124#define FC_TIMED_OUT 11
125#define FC_TRANS_RESET 12
126
127
128
129
130#define FC_SCSI_TM_TOV (10 * HZ)
131#define FC_HOST_RESET_TIMEOUT (30 * HZ)
132#define FC_CAN_QUEUE_PERIOD (60 * HZ)
133
134#define FC_MAX_ERROR_CNT 5
135#define FC_MAX_RECOV_RETRY 3
136
137#define FC_FCP_DFLT_QUEUE_DEPTH 32
138
139
140
141
142
143
144
145
146
147static struct fc_fcp_pkt *fc_fcp_pkt_alloc(struct fc_lport *lport, gfp_t gfp)
148{
149 struct fc_fcp_internal *si = fc_get_scsi_internal(lport);
150 struct fc_fcp_pkt *fsp;
151
152 fsp = mempool_alloc(si->scsi_pkt_pool, gfp);
153 if (fsp) {
154 memset(fsp, 0, sizeof(*fsp));
155 fsp->lp = lport;
156 fsp->xfer_ddp = FC_XID_UNKNOWN;
157 refcount_set(&fsp->ref_cnt, 1);
158 timer_setup(&fsp->timer, NULL, 0);
159 INIT_LIST_HEAD(&fsp->list);
160 spin_lock_init(&fsp->scsi_pkt_lock);
161 } else {
162 per_cpu_ptr(lport->stats, get_cpu())->FcpPktAllocFails++;
163 put_cpu();
164 }
165 return fsp;
166}
167
168
169
170
171
172
173
174
175static void fc_fcp_pkt_release(struct fc_fcp_pkt *fsp)
176{
177 if (refcount_dec_and_test(&fsp->ref_cnt)) {
178 struct fc_fcp_internal *si = fc_get_scsi_internal(fsp->lp);
179
180 mempool_free(fsp, si->scsi_pkt_pool);
181 }
182}
183
184
185
186
187
188static void fc_fcp_pkt_hold(struct fc_fcp_pkt *fsp)
189{
190 refcount_inc(&fsp->ref_cnt);
191}
192
193
194
195
196
197
198
199
200
201
202
203
204static void fc_fcp_pkt_destroy(struct fc_seq *seq, void *fsp)
205{
206 fc_fcp_pkt_release(fsp);
207}
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226static inline int fc_fcp_lock_pkt(struct fc_fcp_pkt *fsp)
227{
228 spin_lock_bh(&fsp->scsi_pkt_lock);
229 if (fsp->state & FC_SRB_COMPL) {
230 spin_unlock_bh(&fsp->scsi_pkt_lock);
231 return -EPERM;
232 }
233
234 fc_fcp_pkt_hold(fsp);
235 return 0;
236}
237
238
239
240
241
242
243static inline void fc_fcp_unlock_pkt(struct fc_fcp_pkt *fsp)
244{
245 spin_unlock_bh(&fsp->scsi_pkt_lock);
246 fc_fcp_pkt_release(fsp);
247}
248
249
250
251
252
253
254static void fc_fcp_timer_set(struct fc_fcp_pkt *fsp, unsigned long delay)
255{
256 if (!(fsp->state & FC_SRB_COMPL)) {
257 mod_timer(&fsp->timer, jiffies + delay);
258 fsp->timer_delay = delay;
259 }
260}
261
262static void fc_fcp_abort_done(struct fc_fcp_pkt *fsp)
263{
264 fsp->state |= FC_SRB_ABORTED;
265 fsp->state &= ~FC_SRB_ABORT_PENDING;
266
267 if (fsp->wait_for_comp)
268 complete(&fsp->tm_done);
269 else
270 fc_fcp_complete_locked(fsp);
271}
272
273
274
275
276
277
278static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp)
279{
280 int rc;
281
282 if (!fsp->seq_ptr)
283 return -EINVAL;
284
285 per_cpu_ptr(fsp->lp->stats, get_cpu())->FcpPktAborts++;
286 put_cpu();
287
288 fsp->state |= FC_SRB_ABORT_PENDING;
289 rc = fc_seq_exch_abort(fsp->seq_ptr, 0);
290
291
292
293
294 if (rc == -ENXIO) {
295 fc_fcp_abort_done(fsp);
296 rc = 0;
297 }
298 return rc;
299}
300
301
302
303
304
305
306
307
308
309
310static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp, int status_code)
311{
312 if (fsp->seq_ptr) {
313 fc_exch_done(fsp->seq_ptr);
314 fsp->seq_ptr = NULL;
315 }
316
317 fsp->state &= ~FC_SRB_ABORT_PENDING;
318 fsp->io_status = 0;
319 fsp->status_code = status_code;
320 fc_fcp_complete_locked(fsp);
321}
322
323
324
325
326
327
328void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid)
329{
330 struct fc_lport *lport;
331
332 lport = fsp->lp;
333 if ((fsp->req_flags & FC_SRB_READ) &&
334 (lport->lro_enabled) && (lport->tt.ddp_setup)) {
335 if (lport->tt.ddp_setup(lport, xid, scsi_sglist(fsp->cmd),
336 scsi_sg_count(fsp->cmd)))
337 fsp->xfer_ddp = xid;
338 }
339}
340
341
342
343
344
345
346void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp)
347{
348 struct fc_lport *lport;
349
350 if (!fsp)
351 return;
352
353 if (fsp->xfer_ddp == FC_XID_UNKNOWN)
354 return;
355
356 lport = fsp->lp;
357 if (lport->tt.ddp_done) {
358 fsp->xfer_len = lport->tt.ddp_done(lport, fsp->xfer_ddp);
359 fsp->xfer_ddp = FC_XID_UNKNOWN;
360 }
361}
362
363
364
365
366
367static void fc_fcp_can_queue_ramp_up(struct fc_lport *lport)
368{
369 struct fc_fcp_internal *si = fc_get_scsi_internal(lport);
370 unsigned long flags;
371 int can_queue;
372
373 spin_lock_irqsave(lport->host->host_lock, flags);
374
375 if (si->last_can_queue_ramp_up_time &&
376 (time_before(jiffies, si->last_can_queue_ramp_up_time +
377 FC_CAN_QUEUE_PERIOD)))
378 goto unlock;
379
380 if (time_before(jiffies, si->last_can_queue_ramp_down_time +
381 FC_CAN_QUEUE_PERIOD))
382 goto unlock;
383
384 si->last_can_queue_ramp_up_time = jiffies;
385
386 can_queue = lport->host->can_queue << 1;
387 if (can_queue >= si->max_can_queue) {
388 can_queue = si->max_can_queue;
389 si->last_can_queue_ramp_down_time = 0;
390 }
391 lport->host->can_queue = can_queue;
392 shost_printk(KERN_ERR, lport->host, "libfc: increased "
393 "can_queue to %d.\n", can_queue);
394
395unlock:
396 spin_unlock_irqrestore(lport->host->host_lock, flags);
397}
398
399
400
401
402
403
404
405
406
407
408
409static bool fc_fcp_can_queue_ramp_down(struct fc_lport *lport)
410{
411 struct fc_fcp_internal *si = fc_get_scsi_internal(lport);
412 unsigned long flags;
413 int can_queue;
414 bool changed = false;
415
416 spin_lock_irqsave(lport->host->host_lock, flags);
417
418 if (si->last_can_queue_ramp_down_time &&
419 (time_before(jiffies, si->last_can_queue_ramp_down_time +
420 FC_CAN_QUEUE_PERIOD)))
421 goto unlock;
422
423 si->last_can_queue_ramp_down_time = jiffies;
424
425 can_queue = lport->host->can_queue;
426 can_queue >>= 1;
427 if (!can_queue)
428 can_queue = 1;
429 lport->host->can_queue = can_queue;
430 changed = true;
431
432unlock:
433 spin_unlock_irqrestore(lport->host->host_lock, flags);
434 return changed;
435}
436
437
438
439
440
441
442
443
444
445static inline struct fc_frame *fc_fcp_frame_alloc(struct fc_lport *lport,
446 size_t len)
447{
448 struct fc_frame *fp;
449
450 fp = fc_frame_alloc(lport, len);
451 if (likely(fp))
452 return fp;
453
454 per_cpu_ptr(lport->stats, get_cpu())->FcpFrameAllocFails++;
455 put_cpu();
456
457 fc_fcp_can_queue_ramp_down(lport);
458 shost_printk(KERN_ERR, lport->host,
459 "libfc: Could not allocate frame, "
460 "reducing can_queue to %d.\n", lport->host->can_queue);
461 return NULL;
462}
463
464
465
466
467
468
469
470static inline unsigned int get_fsp_rec_tov(struct fc_fcp_pkt *fsp)
471{
472 struct fc_rport_libfc_priv *rpriv = fsp->rport->dd_data;
473 unsigned int e_d_tov = FC_DEF_E_D_TOV;
474
475 if (rpriv && rpriv->e_d_tov > e_d_tov)
476 e_d_tov = rpriv->e_d_tov;
477 return msecs_to_jiffies(e_d_tov) + HZ;
478}
479
480
481
482
483
484
485static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
486{
487 struct scsi_cmnd *sc = fsp->cmd;
488 struct fc_lport *lport = fsp->lp;
489 struct fc_stats *stats;
490 struct fc_frame_header *fh;
491 size_t start_offset;
492 size_t offset;
493 u32 crc;
494 u32 copy_len = 0;
495 size_t len;
496 void *buf;
497 struct scatterlist *sg;
498 u32 nents;
499 u8 host_bcode = FC_COMPLETE;
500
501 fh = fc_frame_header_get(fp);
502 offset = ntohl(fh->fh_parm_offset);
503 start_offset = offset;
504 len = fr_len(fp) - sizeof(*fh);
505 buf = fc_frame_payload_get(fp, 0);
506
507
508
509
510
511
512
513
514 if (fsp->xfer_ddp != FC_XID_UNKNOWN) {
515 fc_fcp_ddp_done(fsp);
516 FC_FCP_DBG(fsp, "DDP I/O in fc_fcp_recv_data set ERROR\n");
517 host_bcode = FC_ERROR;
518 goto err;
519 }
520 if (offset + len > fsp->data_len) {
521
522 if ((fr_flags(fp) & FCPHF_CRC_UNCHECKED) &&
523 fc_frame_crc_check(fp))
524 goto crc_err;
525 FC_FCP_DBG(fsp, "data received past end. len %zx offset %zx "
526 "data_len %x\n", len, offset, fsp->data_len);
527
528
529 host_bcode = FC_DATA_OVRRUN;
530 goto err;
531 }
532 if (offset != fsp->xfer_len)
533 fsp->state |= FC_SRB_DISCONTIG;
534
535 sg = scsi_sglist(sc);
536 nents = scsi_sg_count(sc);
537
538 if (!(fr_flags(fp) & FCPHF_CRC_UNCHECKED)) {
539 copy_len = fc_copy_buffer_to_sglist(buf, len, sg, &nents,
540 &offset, NULL);
541 } else {
542 crc = crc32(~0, (u8 *) fh, sizeof(*fh));
543 copy_len = fc_copy_buffer_to_sglist(buf, len, sg, &nents,
544 &offset, &crc);
545 buf = fc_frame_payload_get(fp, 0);
546 if (len % 4)
547 crc = crc32(crc, buf + len, 4 - (len % 4));
548
549 if (~crc != le32_to_cpu(fr_crc(fp))) {
550crc_err:
551 stats = per_cpu_ptr(lport->stats, get_cpu());
552 stats->ErrorFrames++;
553
554 if (stats->InvalidCRCCount++ < FC_MAX_ERROR_CNT)
555 printk(KERN_WARNING "libfc: CRC error on data "
556 "frame for port (%6.6x)\n",
557 lport->port_id);
558 put_cpu();
559
560
561
562
563
564
565
566 if (fsp->state & FC_SRB_DISCONTIG) {
567 host_bcode = FC_CRC_ERROR;
568 goto err;
569 }
570 return;
571 }
572 }
573
574 if (fsp->xfer_contig_end == start_offset)
575 fsp->xfer_contig_end += copy_len;
576 fsp->xfer_len += copy_len;
577
578
579
580
581
582 if (unlikely(fsp->state & FC_SRB_RCV_STATUS) &&
583 fsp->xfer_len == fsp->data_len - fsp->scsi_resid) {
584 FC_FCP_DBG( fsp, "complete out-of-order sequence\n" );
585 fc_fcp_complete_locked(fsp);
586 }
587 return;
588err:
589 fc_fcp_recovery(fsp, host_bcode);
590}
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq,
606 size_t offset, size_t seq_blen)
607{
608 struct fc_exch *ep;
609 struct scsi_cmnd *sc;
610 struct scatterlist *sg;
611 struct fc_frame *fp = NULL;
612 struct fc_lport *lport = fsp->lp;
613 struct page *page;
614 size_t remaining;
615 size_t t_blen;
616 size_t tlen;
617 size_t sg_bytes;
618 size_t frame_offset, fh_parm_offset;
619 size_t off;
620 int error;
621 void *data = NULL;
622 void *page_addr;
623 int using_sg = lport->sg_supp;
624 u32 f_ctl;
625
626 WARN_ON(seq_blen <= 0);
627 if (unlikely(offset + seq_blen > fsp->data_len)) {
628
629 FC_FCP_DBG(fsp, "xfer-ready past end. seq_blen %zx "
630 "offset %zx\n", seq_blen, offset);
631 fc_fcp_send_abort(fsp);
632 return 0;
633 } else if (offset != fsp->xfer_len) {
634
635 FC_FCP_DBG(fsp, "xfer-ready non-contiguous. "
636 "seq_blen %zx offset %zx\n", seq_blen, offset);
637 }
638
639
640
641
642
643
644 t_blen = fsp->max_payload;
645 if (lport->seq_offload) {
646 t_blen = min(seq_blen, (size_t)lport->lso_max);
647 FC_FCP_DBG(fsp, "fsp=%p:lso:blen=%zx lso_max=0x%x t_blen=%zx\n",
648 fsp, seq_blen, lport->lso_max, t_blen);
649 }
650
651 if (t_blen > 512)
652 t_blen &= ~(512 - 1);
653 sc = fsp->cmd;
654
655 remaining = seq_blen;
656 fh_parm_offset = frame_offset = offset;
657 tlen = 0;
658 seq = fc_seq_start_next(seq);
659 f_ctl = FC_FC_REL_OFF;
660 WARN_ON(!seq);
661
662 sg = scsi_sglist(sc);
663
664 while (remaining > 0 && sg) {
665 if (offset >= sg->length) {
666 offset -= sg->length;
667 sg = sg_next(sg);
668 continue;
669 }
670 if (!fp) {
671 tlen = min(t_blen, remaining);
672
673
674
675
676
677
678 if (tlen % 4)
679 using_sg = 0;
680 fp = fc_frame_alloc(lport, using_sg ? 0 : tlen);
681 if (!fp)
682 return -ENOMEM;
683
684 data = fc_frame_header_get(fp) + 1;
685 fh_parm_offset = frame_offset;
686 fr_max_payload(fp) = fsp->max_payload;
687 }
688
689 off = offset + sg->offset;
690 sg_bytes = min(tlen, sg->length - offset);
691 sg_bytes = min(sg_bytes,
692 (size_t) (PAGE_SIZE - (off & ~PAGE_MASK)));
693 page = sg_page(sg) + (off >> PAGE_SHIFT);
694 if (using_sg) {
695 get_page(page);
696 skb_fill_page_desc(fp_skb(fp),
697 skb_shinfo(fp_skb(fp))->nr_frags,
698 page, off & ~PAGE_MASK, sg_bytes);
699 fp_skb(fp)->data_len += sg_bytes;
700 fr_len(fp) += sg_bytes;
701 fp_skb(fp)->truesize += PAGE_SIZE;
702 } else {
703
704
705
706
707 page_addr = kmap_atomic(page);
708 memcpy(data, (char *)page_addr + (off & ~PAGE_MASK),
709 sg_bytes);
710 kunmap_atomic(page_addr);
711 data += sg_bytes;
712 }
713 offset += sg_bytes;
714 frame_offset += sg_bytes;
715 tlen -= sg_bytes;
716 remaining -= sg_bytes;
717
718 if ((skb_shinfo(fp_skb(fp))->nr_frags < FC_FRAME_SG_LEN) &&
719 (tlen))
720 continue;
721
722
723
724
725
726 if (remaining == 0)
727 f_ctl |= FC_FC_SEQ_INIT | FC_FC_END_SEQ;
728
729 ep = fc_seq_exch(seq);
730 fc_fill_fc_hdr(fp, FC_RCTL_DD_SOL_DATA, ep->did, ep->sid,
731 FC_TYPE_FCP, f_ctl, fh_parm_offset);
732
733
734
735
736 error = fc_seq_send(lport, seq, fp);
737 if (error) {
738 WARN_ON(1);
739 return error;
740 }
741 fp = NULL;
742 }
743 fsp->xfer_len += seq_blen;
744 return 0;
745}
746
747
748
749
750
751
752static void fc_fcp_abts_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
753{
754 int ba_done = 1;
755 struct fc_ba_rjt *brp;
756 struct fc_frame_header *fh;
757
758 fh = fc_frame_header_get(fp);
759 switch (fh->fh_r_ctl) {
760 case FC_RCTL_BA_ACC:
761 break;
762 case FC_RCTL_BA_RJT:
763 brp = fc_frame_payload_get(fp, sizeof(*brp));
764 if (brp && brp->br_reason == FC_BA_RJT_LOG_ERR)
765 break;
766
767 default:
768
769
770
771
772
773 ba_done = 0;
774 }
775
776 if (ba_done)
777 fc_fcp_abort_done(fsp);
778}
779
780
781
782
783
784
785
786
787
788
789static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg)
790{
791 struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)arg;
792 struct fc_lport *lport = fsp->lp;
793 struct fc_frame_header *fh;
794 struct fcp_txrdy *dd;
795 u8 r_ctl;
796 int rc = 0;
797
798 if (IS_ERR(fp)) {
799 fc_fcp_error(fsp, fp);
800 return;
801 }
802
803 fh = fc_frame_header_get(fp);
804 r_ctl = fh->fh_r_ctl;
805
806 if (lport->state != LPORT_ST_READY) {
807 FC_FCP_DBG(fsp, "lport state %d, ignoring r_ctl %x\n",
808 lport->state, r_ctl);
809 goto out;
810 }
811 if (fc_fcp_lock_pkt(fsp))
812 goto out;
813
814 if (fh->fh_type == FC_TYPE_BLS) {
815 fc_fcp_abts_resp(fsp, fp);
816 goto unlock;
817 }
818
819 if (fsp->state & (FC_SRB_ABORTED | FC_SRB_ABORT_PENDING)) {
820 FC_FCP_DBG(fsp, "command aborted, ignoring r_ctl %x\n", r_ctl);
821 goto unlock;
822 }
823
824 if (r_ctl == FC_RCTL_DD_DATA_DESC) {
825
826
827
828
829 WARN_ON(fr_flags(fp) & FCPHF_CRC_UNCHECKED);
830 dd = fc_frame_payload_get(fp, sizeof(*dd));
831 WARN_ON(!dd);
832
833 rc = fc_fcp_send_data(fsp, seq,
834 (size_t) ntohl(dd->ft_data_ro),
835 (size_t) ntohl(dd->ft_burst_len));
836 if (!rc)
837 seq->rec_data = fsp->xfer_len;
838 } else if (r_ctl == FC_RCTL_DD_SOL_DATA) {
839
840
841
842
843 WARN_ON(fr_len(fp) < sizeof(*fh));
844 fc_fcp_recv_data(fsp, fp);
845 seq->rec_data = fsp->xfer_contig_end;
846 } else if (r_ctl == FC_RCTL_DD_CMD_STATUS) {
847 WARN_ON(fr_flags(fp) & FCPHF_CRC_UNCHECKED);
848
849 fc_fcp_resp(fsp, fp);
850 } else {
851 FC_FCP_DBG(fsp, "unexpected frame. r_ctl %x\n", r_ctl);
852 }
853unlock:
854 fc_fcp_unlock_pkt(fsp);
855out:
856 fc_frame_free(fp);
857}
858
859
860
861
862
863
864static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
865{
866 struct fc_frame_header *fh;
867 struct fcp_resp *fc_rp;
868 struct fcp_resp_ext *rp_ex;
869 struct fcp_resp_rsp_info *fc_rp_info;
870 u32 plen;
871 u32 expected_len;
872 u32 respl = 0;
873 u32 snsl = 0;
874 u8 flags = 0;
875
876 plen = fr_len(fp);
877 fh = (struct fc_frame_header *)fr_hdr(fp);
878 if (unlikely(plen < sizeof(*fh) + sizeof(*fc_rp)))
879 goto len_err;
880 plen -= sizeof(*fh);
881 fc_rp = (struct fcp_resp *)(fh + 1);
882 fsp->cdb_status = fc_rp->fr_status;
883 flags = fc_rp->fr_flags;
884 fsp->scsi_comp_flags = flags;
885 expected_len = fsp->data_len;
886
887
888 fc_fcp_ddp_done(fsp);
889
890 if (unlikely((flags & ~FCP_CONF_REQ) || fc_rp->fr_status)) {
891 rp_ex = (void *)(fc_rp + 1);
892 if (flags & (FCP_RSP_LEN_VAL | FCP_SNS_LEN_VAL)) {
893 if (plen < sizeof(*fc_rp) + sizeof(*rp_ex))
894 goto len_err;
895 fc_rp_info = (struct fcp_resp_rsp_info *)(rp_ex + 1);
896 if (flags & FCP_RSP_LEN_VAL) {
897 respl = ntohl(rp_ex->fr_rsp_len);
898 if ((respl != FCP_RESP_RSP_INFO_LEN4) &&
899 (respl != FCP_RESP_RSP_INFO_LEN8))
900 goto len_err;
901 if (fsp->wait_for_comp) {
902
903 fsp->cdb_status = fc_rp_info->rsp_code;
904 complete(&fsp->tm_done);
905
906
907
908
909 return;
910 }
911 }
912 if (flags & FCP_SNS_LEN_VAL) {
913 snsl = ntohl(rp_ex->fr_sns_len);
914 if (snsl > SCSI_SENSE_BUFFERSIZE)
915 snsl = SCSI_SENSE_BUFFERSIZE;
916 memcpy(fsp->cmd->sense_buffer,
917 (char *)fc_rp_info + respl, snsl);
918 }
919 }
920 if (flags & (FCP_RESID_UNDER | FCP_RESID_OVER)) {
921 if (plen < sizeof(*fc_rp) + sizeof(rp_ex->fr_resid))
922 goto len_err;
923 if (flags & FCP_RESID_UNDER) {
924 fsp->scsi_resid = ntohl(rp_ex->fr_resid);
925
926
927
928
929
930
931
932
933 if (!(flags & FCP_SNS_LEN_VAL) &&
934 (fc_rp->fr_status == 0) &&
935 (scsi_bufflen(fsp->cmd) -
936 fsp->scsi_resid) < fsp->cmd->underflow)
937 goto err;
938 expected_len -= fsp->scsi_resid;
939 } else {
940 fsp->status_code = FC_ERROR;
941 }
942 }
943 }
944 fsp->state |= FC_SRB_RCV_STATUS;
945
946
947
948
949 if (unlikely(fsp->cdb_status == SAM_STAT_GOOD &&
950 fsp->xfer_len != expected_len)) {
951 if (fsp->xfer_len < expected_len) {
952
953
954
955
956
957 if (fsp->lp->qfull) {
958 FC_FCP_DBG(fsp, "tgt %6.6x queue busy retry\n",
959 fsp->rport->port_id);
960 return;
961 }
962 FC_FCP_DBG(fsp, "tgt %6.6x xfer len %zx data underrun "
963 "len %x, data len %x\n",
964 fsp->rport->port_id,
965 fsp->xfer_len, expected_len, fsp->data_len);
966 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
967 return;
968 }
969 fsp->status_code = FC_DATA_OVRRUN;
970 FC_FCP_DBG(fsp, "tgt %6.6x xfer len %zx greater than expected, "
971 "len %x, data len %x\n",
972 fsp->rport->port_id,
973 fsp->xfer_len, expected_len, fsp->data_len);
974 }
975 fc_fcp_complete_locked(fsp);
976 return;
977
978len_err:
979 FC_FCP_DBG(fsp, "short FCP response. flags 0x%x len %u respl %u "
980 "snsl %u\n", flags, fr_len(fp), respl, snsl);
981err:
982 fsp->status_code = FC_ERROR;
983 fc_fcp_complete_locked(fsp);
984}
985
986
987
988
989
990
991
992
993
994static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp)
995{
996 struct fc_lport *lport = fsp->lp;
997 struct fc_seq *seq;
998 struct fc_exch *ep;
999 u32 f_ctl;
1000
1001 if (fsp->state & FC_SRB_ABORT_PENDING)
1002 return;
1003
1004 if (fsp->state & FC_SRB_ABORTED) {
1005 if (!fsp->status_code)
1006 fsp->status_code = FC_CMD_ABORTED;
1007 } else {
1008
1009
1010
1011
1012 if (fsp->cdb_status == SAM_STAT_GOOD &&
1013 fsp->xfer_len < fsp->data_len && !fsp->io_status &&
1014 (!(fsp->scsi_comp_flags & FCP_RESID_UNDER) ||
1015 fsp->xfer_len < fsp->data_len - fsp->scsi_resid)) {
1016 FC_FCP_DBG(fsp, "data underrun, xfer %zx data %x\n",
1017 fsp->xfer_len, fsp->data_len);
1018 fsp->status_code = FC_DATA_UNDRUN;
1019 }
1020 }
1021
1022 seq = fsp->seq_ptr;
1023 if (seq) {
1024 fsp->seq_ptr = NULL;
1025 if (unlikely(fsp->scsi_comp_flags & FCP_CONF_REQ)) {
1026 struct fc_frame *conf_frame;
1027 struct fc_seq *csp;
1028
1029 csp = fc_seq_start_next(seq);
1030 conf_frame = fc_fcp_frame_alloc(fsp->lp, 0);
1031 if (conf_frame) {
1032 f_ctl = FC_FC_SEQ_INIT;
1033 f_ctl |= FC_FC_LAST_SEQ | FC_FC_END_SEQ;
1034 ep = fc_seq_exch(seq);
1035 fc_fill_fc_hdr(conf_frame, FC_RCTL_DD_SOL_CTL,
1036 ep->did, ep->sid,
1037 FC_TYPE_FCP, f_ctl, 0);
1038 fc_seq_send(lport, csp, conf_frame);
1039 }
1040 }
1041 fc_exch_done(seq);
1042 }
1043
1044
1045
1046
1047
1048 if (fsp->cmd)
1049 fc_io_compl(fsp);
1050}
1051
1052
1053
1054
1055
1056
1057static void fc_fcp_cleanup_cmd(struct fc_fcp_pkt *fsp, int error)
1058{
1059 if (fsp->seq_ptr) {
1060 fc_exch_done(fsp->seq_ptr);
1061 fsp->seq_ptr = NULL;
1062 }
1063 fsp->status_code = error;
1064}
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075static void fc_fcp_cleanup_each_cmd(struct fc_lport *lport, unsigned int id,
1076 unsigned int lun, int error)
1077{
1078 struct fc_fcp_internal *si = fc_get_scsi_internal(lport);
1079 struct fc_fcp_pkt *fsp;
1080 struct scsi_cmnd *sc_cmd;
1081 unsigned long flags;
1082
1083 spin_lock_irqsave(&si->scsi_queue_lock, flags);
1084restart:
1085 list_for_each_entry(fsp, &si->scsi_pkt_queue, list) {
1086 sc_cmd = fsp->cmd;
1087 if (id != -1 && scmd_id(sc_cmd) != id)
1088 continue;
1089
1090 if (lun != -1 && sc_cmd->device->lun != lun)
1091 continue;
1092
1093 fc_fcp_pkt_hold(fsp);
1094 spin_unlock_irqrestore(&si->scsi_queue_lock, flags);
1095
1096 spin_lock_bh(&fsp->scsi_pkt_lock);
1097 if (!(fsp->state & FC_SRB_COMPL)) {
1098 fsp->state |= FC_SRB_COMPL;
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108 spin_unlock_bh(&fsp->scsi_pkt_lock);
1109
1110 fc_fcp_cleanup_cmd(fsp, error);
1111
1112 spin_lock_bh(&fsp->scsi_pkt_lock);
1113 fc_io_compl(fsp);
1114 }
1115 spin_unlock_bh(&fsp->scsi_pkt_lock);
1116
1117 fc_fcp_pkt_release(fsp);
1118 spin_lock_irqsave(&si->scsi_queue_lock, flags);
1119
1120
1121
1122
1123 goto restart;
1124 }
1125 spin_unlock_irqrestore(&si->scsi_queue_lock, flags);
1126}
1127
1128
1129
1130
1131
1132static void fc_fcp_abort_io(struct fc_lport *lport)
1133{
1134 fc_fcp_cleanup_each_cmd(lport, -1, -1, FC_HRD_ERROR);
1135}
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145static int fc_fcp_pkt_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp)
1146{
1147 struct fc_fcp_internal *si = fc_get_scsi_internal(lport);
1148 unsigned long flags;
1149 int rc;
1150
1151 fsp->cmd->SCp.ptr = (char *)fsp;
1152 fsp->cdb_cmd.fc_dl = htonl(fsp->data_len);
1153 fsp->cdb_cmd.fc_flags = fsp->req_flags & ~FCP_CFL_LEN_MASK;
1154
1155 int_to_scsilun(fsp->cmd->device->lun, &fsp->cdb_cmd.fc_lun);
1156 memcpy(fsp->cdb_cmd.fc_cdb, fsp->cmd->cmnd, fsp->cmd->cmd_len);
1157
1158 spin_lock_irqsave(&si->scsi_queue_lock, flags);
1159 list_add_tail(&fsp->list, &si->scsi_pkt_queue);
1160 spin_unlock_irqrestore(&si->scsi_queue_lock, flags);
1161 rc = lport->tt.fcp_cmd_send(lport, fsp, fc_fcp_recv);
1162 if (unlikely(rc)) {
1163 spin_lock_irqsave(&si->scsi_queue_lock, flags);
1164 fsp->cmd->SCp.ptr = NULL;
1165 list_del(&fsp->list);
1166 spin_unlock_irqrestore(&si->scsi_queue_lock, flags);
1167 }
1168
1169 return rc;
1170}
1171
1172
1173
1174
1175
1176
1177
1178static int fc_fcp_cmd_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp,
1179 void (*resp)(struct fc_seq *,
1180 struct fc_frame *fp,
1181 void *arg))
1182{
1183 struct fc_frame *fp;
1184 struct fc_seq *seq;
1185 struct fc_rport *rport;
1186 struct fc_rport_libfc_priv *rpriv;
1187 const size_t len = sizeof(fsp->cdb_cmd);
1188 int rc = 0;
1189
1190 if (fc_fcp_lock_pkt(fsp))
1191 return 0;
1192
1193 fp = fc_fcp_frame_alloc(lport, sizeof(fsp->cdb_cmd));
1194 if (!fp) {
1195 rc = -1;
1196 goto unlock;
1197 }
1198
1199 memcpy(fc_frame_payload_get(fp, len), &fsp->cdb_cmd, len);
1200 fr_fsp(fp) = fsp;
1201 rport = fsp->rport;
1202 fsp->max_payload = rport->maxframe_size;
1203 rpriv = rport->dd_data;
1204
1205 fc_fill_fc_hdr(fp, FC_RCTL_DD_UNSOL_CMD, rport->port_id,
1206 rpriv->local_port->port_id, FC_TYPE_FCP,
1207 FC_FCTL_REQ, 0);
1208
1209 seq = fc_exch_seq_send(lport, fp, resp, fc_fcp_pkt_destroy, fsp, 0);
1210 if (!seq) {
1211 rc = -1;
1212 goto unlock;
1213 }
1214 fsp->seq_ptr = seq;
1215 fc_fcp_pkt_hold(fsp);
1216
1217 fsp->timer.function = fc_fcp_timeout;
1218 if (rpriv->flags & FC_RP_FLAGS_REC_SUPPORTED)
1219 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
1220
1221unlock:
1222 fc_fcp_unlock_pkt(fsp);
1223 return rc;
1224}
1225
1226
1227
1228
1229
1230
1231static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
1232{
1233 int error = PTR_ERR(fp);
1234
1235 if (fc_fcp_lock_pkt(fsp))
1236 return;
1237
1238 if (error == -FC_EX_CLOSED) {
1239 fc_fcp_retry_cmd(fsp, FC_ERROR);
1240 goto unlock;
1241 }
1242
1243
1244
1245
1246
1247 fsp->state &= ~FC_SRB_ABORT_PENDING;
1248 fsp->status_code = FC_CMD_PLOGO;
1249 fc_fcp_complete_locked(fsp);
1250unlock:
1251 fc_fcp_unlock_pkt(fsp);
1252}
1253
1254
1255
1256
1257
1258
1259
1260static int fc_fcp_pkt_abort(struct fc_fcp_pkt *fsp)
1261{
1262 int rc = FAILED;
1263 unsigned long ticks_left;
1264
1265 FC_FCP_DBG(fsp, "pkt abort state %x\n", fsp->state);
1266 if (fc_fcp_send_abort(fsp)) {
1267 FC_FCP_DBG(fsp, "failed to send abort\n");
1268 return FAILED;
1269 }
1270
1271 if (fsp->state & FC_SRB_ABORTED) {
1272 FC_FCP_DBG(fsp, "target abort cmd completed\n");
1273 return SUCCESS;
1274 }
1275
1276 init_completion(&fsp->tm_done);
1277 fsp->wait_for_comp = 1;
1278
1279 spin_unlock_bh(&fsp->scsi_pkt_lock);
1280 ticks_left = wait_for_completion_timeout(&fsp->tm_done,
1281 FC_SCSI_TM_TOV);
1282 spin_lock_bh(&fsp->scsi_pkt_lock);
1283 fsp->wait_for_comp = 0;
1284
1285 if (!ticks_left) {
1286 FC_FCP_DBG(fsp, "target abort cmd failed\n");
1287 } else if (fsp->state & FC_SRB_ABORTED) {
1288 FC_FCP_DBG(fsp, "target abort cmd passed\n");
1289 rc = SUCCESS;
1290 fc_fcp_complete_locked(fsp);
1291 }
1292
1293 return rc;
1294}
1295
1296
1297
1298
1299
1300static void fc_lun_reset_send(struct timer_list *t)
1301{
1302 struct fc_fcp_pkt *fsp = from_timer(fsp, t, timer);
1303 struct fc_lport *lport = fsp->lp;
1304
1305 if (lport->tt.fcp_cmd_send(lport, fsp, fc_tm_done)) {
1306 if (fsp->recov_retry++ >= FC_MAX_RECOV_RETRY)
1307 return;
1308 if (fc_fcp_lock_pkt(fsp))
1309 return;
1310 fsp->timer.function = fc_lun_reset_send;
1311 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
1312 fc_fcp_unlock_pkt(fsp);
1313 }
1314}
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324static int fc_lun_reset(struct fc_lport *lport, struct fc_fcp_pkt *fsp,
1325 unsigned int id, unsigned int lun)
1326{
1327 int rc;
1328
1329 fsp->cdb_cmd.fc_dl = htonl(fsp->data_len);
1330 fsp->cdb_cmd.fc_tm_flags = FCP_TMF_LUN_RESET;
1331 int_to_scsilun(lun, &fsp->cdb_cmd.fc_lun);
1332
1333 fsp->wait_for_comp = 1;
1334 init_completion(&fsp->tm_done);
1335
1336 fc_lun_reset_send(&fsp->timer);
1337
1338
1339
1340
1341
1342 rc = wait_for_completion_timeout(&fsp->tm_done, FC_SCSI_TM_TOV);
1343
1344 spin_lock_bh(&fsp->scsi_pkt_lock);
1345 fsp->state |= FC_SRB_COMPL;
1346 spin_unlock_bh(&fsp->scsi_pkt_lock);
1347
1348 del_timer_sync(&fsp->timer);
1349
1350 spin_lock_bh(&fsp->scsi_pkt_lock);
1351 if (fsp->seq_ptr) {
1352 fc_exch_done(fsp->seq_ptr);
1353 fsp->seq_ptr = NULL;
1354 }
1355 fsp->wait_for_comp = 0;
1356 spin_unlock_bh(&fsp->scsi_pkt_lock);
1357
1358 if (!rc) {
1359 FC_SCSI_DBG(lport, "lun reset failed\n");
1360 return FAILED;
1361 }
1362
1363
1364 if (fsp->cdb_status != FCP_TMF_CMPL)
1365 return FAILED;
1366
1367 FC_SCSI_DBG(lport, "lun reset to lun %u completed\n", lun);
1368 fc_fcp_cleanup_each_cmd(lport, id, lun, FC_CMD_ABORTED);
1369 return SUCCESS;
1370}
1371
1372
1373
1374
1375
1376
1377
1378static void fc_tm_done(struct fc_seq *seq, struct fc_frame *fp, void *arg)
1379{
1380 struct fc_fcp_pkt *fsp = arg;
1381 struct fc_frame_header *fh;
1382
1383 if (IS_ERR(fp)) {
1384
1385
1386
1387
1388
1389
1390 return;
1391 }
1392
1393 if (fc_fcp_lock_pkt(fsp))
1394 goto out;
1395
1396
1397
1398
1399 if (!fsp->seq_ptr || !fsp->wait_for_comp)
1400 goto out_unlock;
1401
1402 fh = fc_frame_header_get(fp);
1403 if (fh->fh_type != FC_TYPE_BLS)
1404 fc_fcp_resp(fsp, fp);
1405 fsp->seq_ptr = NULL;
1406 fc_exch_done(seq);
1407out_unlock:
1408 fc_fcp_unlock_pkt(fsp);
1409out:
1410 fc_frame_free(fp);
1411}
1412
1413
1414
1415
1416
1417static void fc_fcp_cleanup(struct fc_lport *lport)
1418{
1419 fc_fcp_cleanup_each_cmd(lport, -1, -1, FC_ERROR);
1420}
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433static void fc_fcp_timeout(struct timer_list *t)
1434{
1435 struct fc_fcp_pkt *fsp = from_timer(fsp, t, timer);
1436 struct fc_rport *rport = fsp->rport;
1437 struct fc_rport_libfc_priv *rpriv = rport->dd_data;
1438
1439 if (fc_fcp_lock_pkt(fsp))
1440 return;
1441
1442 if (fsp->cdb_cmd.fc_tm_flags)
1443 goto unlock;
1444
1445 if (fsp->lp->qfull) {
1446 FC_FCP_DBG(fsp, "fcp timeout, resetting timer delay %d\n",
1447 fsp->timer_delay);
1448 fsp->timer.function = fc_fcp_timeout;
1449 fc_fcp_timer_set(fsp, fsp->timer_delay);
1450 goto unlock;
1451 }
1452 FC_FCP_DBG(fsp, "fcp timeout, delay %d flags %x state %x\n",
1453 fsp->timer_delay, rpriv->flags, fsp->state);
1454 fsp->state |= FC_SRB_FCP_PROCESSING_TMO;
1455
1456 if (rpriv->flags & FC_RP_FLAGS_REC_SUPPORTED)
1457 fc_fcp_rec(fsp);
1458 else if (fsp->state & FC_SRB_RCV_STATUS)
1459 fc_fcp_complete_locked(fsp);
1460 else
1461 fc_fcp_recovery(fsp, FC_TIMED_OUT);
1462 fsp->state &= ~FC_SRB_FCP_PROCESSING_TMO;
1463unlock:
1464 fc_fcp_unlock_pkt(fsp);
1465}
1466
1467
1468
1469
1470
1471static void fc_fcp_rec(struct fc_fcp_pkt *fsp)
1472{
1473 struct fc_lport *lport;
1474 struct fc_frame *fp;
1475 struct fc_rport *rport;
1476 struct fc_rport_libfc_priv *rpriv;
1477
1478 lport = fsp->lp;
1479 rport = fsp->rport;
1480 rpriv = rport->dd_data;
1481 if (!fsp->seq_ptr || rpriv->rp_state != RPORT_ST_READY) {
1482 fsp->status_code = FC_HRD_ERROR;
1483 fsp->io_status = 0;
1484 fc_fcp_complete_locked(fsp);
1485 return;
1486 }
1487
1488 fp = fc_fcp_frame_alloc(lport, sizeof(struct fc_els_rec));
1489 if (!fp)
1490 goto retry;
1491
1492 fr_seq(fp) = fsp->seq_ptr;
1493 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rport->port_id,
1494 rpriv->local_port->port_id, FC_TYPE_ELS,
1495 FC_FCTL_REQ, 0);
1496 if (lport->tt.elsct_send(lport, rport->port_id, fp, ELS_REC,
1497 fc_fcp_rec_resp, fsp,
1498 2 * lport->r_a_tov)) {
1499 fc_fcp_pkt_hold(fsp);
1500 return;
1501 }
1502retry:
1503 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY)
1504 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
1505 else
1506 fc_fcp_recovery(fsp, FC_TIMED_OUT);
1507}
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520static void fc_fcp_rec_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg)
1521{
1522 struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)arg;
1523 struct fc_els_rec_acc *recp;
1524 struct fc_els_ls_rjt *rjt;
1525 u32 e_stat;
1526 u8 opcode;
1527 u32 offset;
1528 enum dma_data_direction data_dir;
1529 enum fc_rctl r_ctl;
1530 struct fc_rport_libfc_priv *rpriv;
1531
1532 if (IS_ERR(fp)) {
1533 fc_fcp_rec_error(fsp, fp);
1534 return;
1535 }
1536
1537 if (fc_fcp_lock_pkt(fsp))
1538 goto out;
1539
1540 fsp->recov_retry = 0;
1541 opcode = fc_frame_payload_op(fp);
1542 if (opcode == ELS_LS_RJT) {
1543 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1544 switch (rjt->er_reason) {
1545 default:
1546 FC_FCP_DBG(fsp,
1547 "device %x invalid REC reject %d/%d\n",
1548 fsp->rport->port_id, rjt->er_reason,
1549 rjt->er_explan);
1550
1551 case ELS_RJT_UNSUP:
1552 FC_FCP_DBG(fsp, "device does not support REC\n");
1553 rpriv = fsp->rport->dd_data;
1554
1555
1556
1557
1558
1559 rpriv->flags &= ~FC_RP_FLAGS_REC_SUPPORTED;
1560 break;
1561 case ELS_RJT_LOGIC:
1562 case ELS_RJT_UNAB:
1563 FC_FCP_DBG(fsp, "device %x REC reject %d/%d\n",
1564 fsp->rport->port_id, rjt->er_reason,
1565 rjt->er_explan);
1566
1567
1568
1569
1570
1571
1572 if (rjt->er_explan == ELS_EXPL_OXID_RXID) {
1573 struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr);
1574 ep->state |= FC_EX_QUARANTINE;
1575 fsp->state |= FC_SRB_ABORTED;
1576 fc_fcp_retry_cmd(fsp, FC_TRANS_RESET);
1577 break;
1578 }
1579 fc_fcp_recovery(fsp, FC_TRANS_RESET);
1580 break;
1581 }
1582 } else if (opcode == ELS_LS_ACC) {
1583 if (fsp->state & FC_SRB_ABORTED)
1584 goto unlock_out;
1585
1586 data_dir = fsp->cmd->sc_data_direction;
1587 recp = fc_frame_payload_get(fp, sizeof(*recp));
1588 offset = ntohl(recp->reca_fc4value);
1589 e_stat = ntohl(recp->reca_e_stat);
1590
1591 if (e_stat & ESB_ST_COMPLETE) {
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607 if (data_dir == DMA_TO_DEVICE) {
1608 r_ctl = FC_RCTL_DD_CMD_STATUS;
1609 } else if (fsp->xfer_contig_end == offset) {
1610 r_ctl = FC_RCTL_DD_CMD_STATUS;
1611 } else {
1612 offset = fsp->xfer_contig_end;
1613 r_ctl = FC_RCTL_DD_SOL_DATA;
1614 }
1615 fc_fcp_srr(fsp, r_ctl, offset);
1616 } else if (e_stat & ESB_ST_SEQ_INIT) {
1617
1618
1619
1620
1621 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
1622 } else {
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639 r_ctl = FC_RCTL_DD_SOL_DATA;
1640 if (data_dir == DMA_TO_DEVICE) {
1641 r_ctl = FC_RCTL_DD_CMD_STATUS;
1642 if (offset < fsp->data_len)
1643 r_ctl = FC_RCTL_DD_DATA_DESC;
1644 } else if (offset == fsp->xfer_contig_end) {
1645 r_ctl = FC_RCTL_DD_CMD_STATUS;
1646 } else if (fsp->xfer_contig_end < offset) {
1647 offset = fsp->xfer_contig_end;
1648 }
1649 fc_fcp_srr(fsp, r_ctl, offset);
1650 }
1651 }
1652unlock_out:
1653 fc_fcp_unlock_pkt(fsp);
1654out:
1655 fc_fcp_pkt_release(fsp);
1656 fc_frame_free(fp);
1657}
1658
1659
1660
1661
1662
1663
1664static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
1665{
1666 int error = PTR_ERR(fp);
1667
1668 if (fc_fcp_lock_pkt(fsp))
1669 goto out;
1670
1671 switch (error) {
1672 case -FC_EX_CLOSED:
1673 FC_FCP_DBG(fsp, "REC %p fid %6.6x exchange closed\n",
1674 fsp, fsp->rport->port_id);
1675 fc_fcp_retry_cmd(fsp, FC_ERROR);
1676 break;
1677
1678 default:
1679 FC_FCP_DBG(fsp, "REC %p fid %6.6x error unexpected error %d\n",
1680 fsp, fsp->rport->port_id, error);
1681 fsp->status_code = FC_CMD_PLOGO;
1682
1683
1684 case -FC_EX_TIMEOUT:
1685
1686
1687
1688
1689 FC_FCP_DBG(fsp, "REC %p fid %6.6x exchange timeout retry %d/%d\n",
1690 fsp, fsp->rport->port_id, fsp->recov_retry,
1691 FC_MAX_RECOV_RETRY);
1692 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY)
1693 fc_fcp_rec(fsp);
1694 else
1695 fc_fcp_recovery(fsp, FC_ERROR);
1696 break;
1697 }
1698 fc_fcp_unlock_pkt(fsp);
1699out:
1700 fc_fcp_pkt_release(fsp);
1701}
1702
1703
1704
1705
1706
1707static void fc_fcp_recovery(struct fc_fcp_pkt *fsp, u8 code)
1708{
1709 FC_FCP_DBG(fsp, "start recovery code %x\n", code);
1710 fsp->status_code = code;
1711 fsp->cdb_status = 0;
1712 fsp->io_status = 0;
1713
1714
1715
1716
1717 fc_fcp_send_abort(fsp);
1718}
1719
1720
1721
1722
1723
1724
1725
1726
1727static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum fc_rctl r_ctl, u32 offset)
1728{
1729 struct fc_lport *lport = fsp->lp;
1730 struct fc_rport *rport;
1731 struct fc_rport_libfc_priv *rpriv;
1732 struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr);
1733 struct fc_seq *seq;
1734 struct fcp_srr *srr;
1735 struct fc_frame *fp;
1736
1737 rport = fsp->rport;
1738 rpriv = rport->dd_data;
1739
1740 if (!(rpriv->flags & FC_RP_FLAGS_RETRY) ||
1741 rpriv->rp_state != RPORT_ST_READY)
1742 goto retry;
1743 fp = fc_fcp_frame_alloc(lport, sizeof(*srr));
1744 if (!fp)
1745 goto retry;
1746
1747 srr = fc_frame_payload_get(fp, sizeof(*srr));
1748 memset(srr, 0, sizeof(*srr));
1749 srr->srr_op = ELS_SRR;
1750 srr->srr_ox_id = htons(ep->oxid);
1751 srr->srr_rx_id = htons(ep->rxid);
1752 srr->srr_r_ctl = r_ctl;
1753 srr->srr_rel_off = htonl(offset);
1754
1755 fc_fill_fc_hdr(fp, FC_RCTL_ELS4_REQ, rport->port_id,
1756 rpriv->local_port->port_id, FC_TYPE_FCP,
1757 FC_FCTL_REQ, 0);
1758
1759 seq = fc_exch_seq_send(lport, fp, fc_fcp_srr_resp,
1760 fc_fcp_pkt_destroy,
1761 fsp, get_fsp_rec_tov(fsp));
1762 if (!seq)
1763 goto retry;
1764
1765 fsp->recov_seq = seq;
1766 fsp->xfer_len = offset;
1767 fsp->xfer_contig_end = offset;
1768 fsp->state &= ~FC_SRB_RCV_STATUS;
1769 fc_fcp_pkt_hold(fsp);
1770 return;
1771retry:
1772 fc_fcp_retry_cmd(fsp, FC_TRANS_RESET);
1773}
1774
1775
1776
1777
1778
1779
1780
1781static void fc_fcp_srr_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg)
1782{
1783 struct fc_fcp_pkt *fsp = arg;
1784 struct fc_frame_header *fh;
1785
1786 if (IS_ERR(fp)) {
1787 fc_fcp_srr_error(fsp, fp);
1788 return;
1789 }
1790
1791 if (fc_fcp_lock_pkt(fsp))
1792 goto out;
1793
1794 fh = fc_frame_header_get(fp);
1795
1796
1797
1798
1799
1800
1801
1802 if (fh->fh_type == FC_TYPE_BLS) {
1803 fc_fcp_unlock_pkt(fsp);
1804 return;
1805 }
1806
1807 switch (fc_frame_payload_op(fp)) {
1808 case ELS_LS_ACC:
1809 fsp->recov_retry = 0;
1810 fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
1811 break;
1812 case ELS_LS_RJT:
1813 default:
1814 fc_fcp_recovery(fsp, FC_ERROR);
1815 break;
1816 }
1817 fc_fcp_unlock_pkt(fsp);
1818out:
1819 fc_exch_done(seq);
1820 fc_frame_free(fp);
1821}
1822
1823
1824
1825
1826
1827
1828static void fc_fcp_srr_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
1829{
1830 if (fc_fcp_lock_pkt(fsp))
1831 goto out;
1832 switch (PTR_ERR(fp)) {
1833 case -FC_EX_TIMEOUT:
1834 FC_FCP_DBG(fsp, "SRR timeout, retries %d\n", fsp->recov_retry);
1835 if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY)
1836 fc_fcp_rec(fsp);
1837 else
1838 fc_fcp_recovery(fsp, FC_TIMED_OUT);
1839 break;
1840 case -FC_EX_CLOSED:
1841 FC_FCP_DBG(fsp, "SRR error, exchange closed\n");
1842
1843 default:
1844 fc_fcp_retry_cmd(fsp, FC_ERROR);
1845 break;
1846 }
1847 fc_fcp_unlock_pkt(fsp);
1848out:
1849 fc_exch_done(fsp->recov_seq);
1850}
1851
1852
1853
1854
1855
1856static inline int fc_fcp_lport_queue_ready(struct fc_lport *lport)
1857{
1858
1859 return (lport->state == LPORT_ST_READY) &&
1860 lport->link_up && !lport->qfull;
1861}
1862
1863
1864
1865
1866
1867
1868
1869
1870int fc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *sc_cmd)
1871{
1872 struct fc_lport *lport = shost_priv(shost);
1873 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device));
1874 struct fc_fcp_pkt *fsp;
1875 int rval;
1876 int rc = 0;
1877 struct fc_stats *stats;
1878
1879 rval = fc_remote_port_chkready(rport);
1880 if (rval) {
1881 sc_cmd->result = rval;
1882 sc_cmd->scsi_done(sc_cmd);
1883 return 0;
1884 }
1885
1886 if (!*(struct fc_remote_port **)rport->dd_data) {
1887
1888
1889
1890
1891 sc_cmd->result = DID_IMM_RETRY << 16;
1892 sc_cmd->scsi_done(sc_cmd);
1893 goto out;
1894 }
1895
1896 if (!fc_fcp_lport_queue_ready(lport)) {
1897 if (lport->qfull) {
1898 if (fc_fcp_can_queue_ramp_down(lport))
1899 shost_printk(KERN_ERR, lport->host,
1900 "libfc: queue full, "
1901 "reducing can_queue to %d.\n",
1902 lport->host->can_queue);
1903 }
1904 rc = SCSI_MLQUEUE_HOST_BUSY;
1905 goto out;
1906 }
1907
1908 fsp = fc_fcp_pkt_alloc(lport, GFP_ATOMIC);
1909 if (fsp == NULL) {
1910 rc = SCSI_MLQUEUE_HOST_BUSY;
1911 goto out;
1912 }
1913
1914
1915
1916
1917 fsp->cmd = sc_cmd;
1918 fsp->rport = rport;
1919
1920
1921
1922
1923 fsp->data_len = scsi_bufflen(sc_cmd);
1924 fsp->xfer_len = 0;
1925
1926
1927
1928
1929 stats = per_cpu_ptr(lport->stats, get_cpu());
1930 if (sc_cmd->sc_data_direction == DMA_FROM_DEVICE) {
1931 fsp->req_flags = FC_SRB_READ;
1932 stats->InputRequests++;
1933 stats->InputBytes += fsp->data_len;
1934 } else if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) {
1935 fsp->req_flags = FC_SRB_WRITE;
1936 stats->OutputRequests++;
1937 stats->OutputBytes += fsp->data_len;
1938 } else {
1939 fsp->req_flags = 0;
1940 stats->ControlRequests++;
1941 }
1942 put_cpu();
1943
1944
1945
1946
1947
1948
1949 rval = fc_fcp_pkt_send(lport, fsp);
1950 if (rval != 0) {
1951 fsp->state = FC_SRB_FREE;
1952 fc_fcp_pkt_release(fsp);
1953 rc = SCSI_MLQUEUE_HOST_BUSY;
1954 }
1955out:
1956 return rc;
1957}
1958EXPORT_SYMBOL(fc_queuecommand);
1959
1960
1961
1962
1963
1964
1965
1966
1967static void fc_io_compl(struct fc_fcp_pkt *fsp)
1968{
1969 struct fc_fcp_internal *si;
1970 struct scsi_cmnd *sc_cmd;
1971 struct fc_lport *lport;
1972 unsigned long flags;
1973
1974
1975 fc_fcp_ddp_done(fsp);
1976
1977 fsp->state |= FC_SRB_COMPL;
1978 if (!(fsp->state & FC_SRB_FCP_PROCESSING_TMO)) {
1979 spin_unlock_bh(&fsp->scsi_pkt_lock);
1980 del_timer_sync(&fsp->timer);
1981 spin_lock_bh(&fsp->scsi_pkt_lock);
1982 }
1983
1984 lport = fsp->lp;
1985 si = fc_get_scsi_internal(lport);
1986
1987
1988
1989
1990
1991 if (si->last_can_queue_ramp_down_time)
1992 fc_fcp_can_queue_ramp_up(lport);
1993
1994 sc_cmd = fsp->cmd;
1995 CMD_SCSI_STATUS(sc_cmd) = fsp->cdb_status;
1996 switch (fsp->status_code) {
1997 case FC_COMPLETE:
1998 if (fsp->cdb_status == 0) {
1999
2000
2001
2002 sc_cmd->result = DID_OK << 16;
2003 if (fsp->scsi_resid)
2004 CMD_RESID_LEN(sc_cmd) = fsp->scsi_resid;
2005 } else {
2006
2007
2008
2009
2010 sc_cmd->result = (DID_OK << 16) | fsp->cdb_status;
2011 }
2012 break;
2013 case FC_ERROR:
2014 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
2015 "due to FC_ERROR\n");
2016 sc_cmd->result = DID_ERROR << 16;
2017 break;
2018 case FC_DATA_UNDRUN:
2019 if ((fsp->cdb_status == 0) && !(fsp->req_flags & FC_SRB_READ)) {
2020
2021
2022
2023
2024 if (fsp->state & FC_SRB_RCV_STATUS) {
2025 sc_cmd->result = DID_OK << 16;
2026 } else {
2027 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml"
2028 " due to FC_DATA_UNDRUN (trans)\n");
2029 sc_cmd->result = DID_ERROR << 16;
2030 }
2031 } else {
2032
2033
2034
2035 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
2036 "due to FC_DATA_UNDRUN (scsi)\n");
2037 CMD_RESID_LEN(sc_cmd) = fsp->scsi_resid;
2038 sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status;
2039 }
2040 break;
2041 case FC_DATA_OVRRUN:
2042
2043
2044
2045 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
2046 "due to FC_DATA_OVRRUN\n");
2047 sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status;
2048 break;
2049 case FC_CMD_ABORTED:
2050 if (host_byte(sc_cmd->result) == DID_TIME_OUT)
2051 FC_FCP_DBG(fsp, "Returning DID_TIME_OUT to scsi-ml "
2052 "due to FC_CMD_ABORTED\n");
2053 else {
2054 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
2055 "due to FC_CMD_ABORTED\n");
2056 set_host_byte(sc_cmd, DID_ERROR);
2057 }
2058 sc_cmd->result |= fsp->io_status;
2059 break;
2060 case FC_CMD_RESET:
2061 FC_FCP_DBG(fsp, "Returning DID_RESET to scsi-ml "
2062 "due to FC_CMD_RESET\n");
2063 sc_cmd->result = (DID_RESET << 16);
2064 break;
2065 case FC_TRANS_RESET:
2066 FC_FCP_DBG(fsp, "Returning DID_SOFT_ERROR to scsi-ml "
2067 "due to FC_TRANS_RESET\n");
2068 sc_cmd->result = (DID_SOFT_ERROR << 16);
2069 break;
2070 case FC_HRD_ERROR:
2071 FC_FCP_DBG(fsp, "Returning DID_NO_CONNECT to scsi-ml "
2072 "due to FC_HRD_ERROR\n");
2073 sc_cmd->result = (DID_NO_CONNECT << 16);
2074 break;
2075 case FC_CRC_ERROR:
2076 FC_FCP_DBG(fsp, "Returning DID_PARITY to scsi-ml "
2077 "due to FC_CRC_ERROR\n");
2078 sc_cmd->result = (DID_PARITY << 16);
2079 break;
2080 case FC_TIMED_OUT:
2081 FC_FCP_DBG(fsp, "Returning DID_BUS_BUSY to scsi-ml "
2082 "due to FC_TIMED_OUT\n");
2083 sc_cmd->result = (DID_BUS_BUSY << 16) | fsp->io_status;
2084 break;
2085 default:
2086 FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
2087 "due to unknown error\n");
2088 sc_cmd->result = (DID_ERROR << 16);
2089 break;
2090 }
2091
2092 if (lport->state != LPORT_ST_READY && fsp->status_code != FC_COMPLETE)
2093 sc_cmd->result = (DID_TRANSPORT_DISRUPTED << 16);
2094
2095 spin_lock_irqsave(&si->scsi_queue_lock, flags);
2096 list_del(&fsp->list);
2097 sc_cmd->SCp.ptr = NULL;
2098 spin_unlock_irqrestore(&si->scsi_queue_lock, flags);
2099 sc_cmd->scsi_done(sc_cmd);
2100
2101
2102 fc_fcp_pkt_release(fsp);
2103}
2104
2105
2106
2107
2108
2109
2110
2111
2112int fc_eh_abort(struct scsi_cmnd *sc_cmd)
2113{
2114 struct fc_fcp_pkt *fsp;
2115 struct fc_lport *lport;
2116 struct fc_fcp_internal *si;
2117 int rc = FAILED;
2118 unsigned long flags;
2119 int rval;
2120
2121 rval = fc_block_scsi_eh(sc_cmd);
2122 if (rval)
2123 return rval;
2124
2125 lport = shost_priv(sc_cmd->device->host);
2126 if (lport->state != LPORT_ST_READY)
2127 return rc;
2128 else if (!lport->link_up)
2129 return rc;
2130
2131 si = fc_get_scsi_internal(lport);
2132 spin_lock_irqsave(&si->scsi_queue_lock, flags);
2133 fsp = CMD_SP(sc_cmd);
2134 if (!fsp) {
2135
2136 spin_unlock_irqrestore(&si->scsi_queue_lock, flags);
2137 return SUCCESS;
2138 }
2139
2140 fc_fcp_pkt_hold(fsp);
2141 spin_unlock_irqrestore(&si->scsi_queue_lock, flags);
2142
2143 if (fc_fcp_lock_pkt(fsp)) {
2144
2145 rc = SUCCESS;
2146 goto release_pkt;
2147 }
2148
2149 rc = fc_fcp_pkt_abort(fsp);
2150 fc_fcp_unlock_pkt(fsp);
2151
2152release_pkt:
2153 fc_fcp_pkt_release(fsp);
2154 return rc;
2155}
2156EXPORT_SYMBOL(fc_eh_abort);
2157
2158
2159
2160
2161
2162
2163
2164
2165int fc_eh_device_reset(struct scsi_cmnd *sc_cmd)
2166{
2167 struct fc_lport *lport;
2168 struct fc_fcp_pkt *fsp;
2169 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device));
2170 int rc = FAILED;
2171 int rval;
2172
2173 rval = fc_block_scsi_eh(sc_cmd);
2174 if (rval)
2175 return rval;
2176
2177 lport = shost_priv(sc_cmd->device->host);
2178
2179 if (lport->state != LPORT_ST_READY)
2180 return rc;
2181
2182 FC_SCSI_DBG(lport, "Resetting rport (%6.6x)\n", rport->port_id);
2183
2184 fsp = fc_fcp_pkt_alloc(lport, GFP_NOIO);
2185 if (fsp == NULL) {
2186 printk(KERN_WARNING "libfc: could not allocate scsi_pkt\n");
2187 goto out;
2188 }
2189
2190
2191
2192
2193
2194
2195 fsp->rport = rport;
2196
2197
2198
2199
2200 rc = fc_lun_reset(lport, fsp, scmd_id(sc_cmd), sc_cmd->device->lun);
2201 fsp->state = FC_SRB_FREE;
2202 fc_fcp_pkt_release(fsp);
2203
2204out:
2205 return rc;
2206}
2207EXPORT_SYMBOL(fc_eh_device_reset);
2208
2209
2210
2211
2212
2213int fc_eh_host_reset(struct scsi_cmnd *sc_cmd)
2214{
2215 struct Scsi_Host *shost = sc_cmd->device->host;
2216 struct fc_lport *lport = shost_priv(shost);
2217 unsigned long wait_tmo;
2218
2219 FC_SCSI_DBG(lport, "Resetting host\n");
2220
2221 fc_lport_reset(lport);
2222 wait_tmo = jiffies + FC_HOST_RESET_TIMEOUT;
2223 while (!fc_fcp_lport_queue_ready(lport) && time_before(jiffies,
2224 wait_tmo))
2225 msleep(1000);
2226
2227 if (fc_fcp_lport_queue_ready(lport)) {
2228 shost_printk(KERN_INFO, shost, "libfc: Host reset succeeded "
2229 "on port (%6.6x)\n", lport->port_id);
2230 return SUCCESS;
2231 } else {
2232 shost_printk(KERN_INFO, shost, "libfc: Host reset failed, "
2233 "port (%6.6x) is not ready.\n",
2234 lport->port_id);
2235 return FAILED;
2236 }
2237}
2238EXPORT_SYMBOL(fc_eh_host_reset);
2239
2240
2241
2242
2243
2244
2245
2246
2247int fc_slave_alloc(struct scsi_device *sdev)
2248{
2249 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
2250
2251 if (!rport || fc_remote_port_chkready(rport))
2252 return -ENXIO;
2253
2254 scsi_change_queue_depth(sdev, FC_FCP_DFLT_QUEUE_DEPTH);
2255 return 0;
2256}
2257EXPORT_SYMBOL(fc_slave_alloc);
2258
2259
2260
2261
2262
2263void fc_fcp_destroy(struct fc_lport *lport)
2264{
2265 struct fc_fcp_internal *si = fc_get_scsi_internal(lport);
2266
2267 if (!list_empty(&si->scsi_pkt_queue))
2268 printk(KERN_ERR "libfc: Leaked SCSI packets when destroying "
2269 "port (%6.6x)\n", lport->port_id);
2270
2271 mempool_destroy(si->scsi_pkt_pool);
2272 kfree(si);
2273 lport->scsi_priv = NULL;
2274}
2275EXPORT_SYMBOL(fc_fcp_destroy);
2276
2277int fc_setup_fcp(void)
2278{
2279 int rc = 0;
2280
2281 scsi_pkt_cachep = kmem_cache_create("libfc_fcp_pkt",
2282 sizeof(struct fc_fcp_pkt),
2283 0, SLAB_HWCACHE_ALIGN, NULL);
2284 if (!scsi_pkt_cachep) {
2285 printk(KERN_ERR "libfc: Unable to allocate SRB cache, "
2286 "module load failed!");
2287 rc = -ENOMEM;
2288 }
2289
2290 return rc;
2291}
2292
2293void fc_destroy_fcp(void)
2294{
2295 kmem_cache_destroy(scsi_pkt_cachep);
2296}
2297
2298
2299
2300
2301
2302int fc_fcp_init(struct fc_lport *lport)
2303{
2304 int rc;
2305 struct fc_fcp_internal *si;
2306
2307 if (!lport->tt.fcp_cmd_send)
2308 lport->tt.fcp_cmd_send = fc_fcp_cmd_send;
2309
2310 if (!lport->tt.fcp_cleanup)
2311 lport->tt.fcp_cleanup = fc_fcp_cleanup;
2312
2313 if (!lport->tt.fcp_abort_io)
2314 lport->tt.fcp_abort_io = fc_fcp_abort_io;
2315
2316 si = kzalloc(sizeof(struct fc_fcp_internal), GFP_KERNEL);
2317 if (!si)
2318 return -ENOMEM;
2319 lport->scsi_priv = si;
2320 si->max_can_queue = lport->host->can_queue;
2321 INIT_LIST_HEAD(&si->scsi_pkt_queue);
2322 spin_lock_init(&si->scsi_queue_lock);
2323
2324 si->scsi_pkt_pool = mempool_create_slab_pool(2, scsi_pkt_cachep);
2325 if (!si->scsi_pkt_pool) {
2326 rc = -ENOMEM;
2327 goto free_internal;
2328 }
2329 return 0;
2330
2331free_internal:
2332 kfree(si);
2333 return rc;
2334}
2335EXPORT_SYMBOL(fc_fcp_init);
2336