Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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