xref: /linux/include/scsi/libfc.h (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
1a61127c2SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
242e9a92fSRobert Love /*
342e9a92fSRobert Love  * Copyright(c) 2007 Intel Corporation. All rights reserved.
442e9a92fSRobert Love  *
542e9a92fSRobert Love  * Maintained at www.Open-FCoE.org
642e9a92fSRobert Love  */
742e9a92fSRobert Love 
842e9a92fSRobert Love #ifndef _LIBFC_H_
942e9a92fSRobert Love #define _LIBFC_H_
1042e9a92fSRobert Love 
1142e9a92fSRobert Love #include <linux/timer.h>
1242e9a92fSRobert Love #include <linux/if.h>
13582b45bcSRobert Love #include <linux/percpu.h>
1422c70d1aSElena Reshetova #include <linux/refcount.h>
1542e9a92fSRobert Love 
1642e9a92fSRobert Love #include <scsi/scsi_transport.h>
1742e9a92fSRobert Love #include <scsi/scsi_transport_fc.h>
18a51ab396SSteve Ma #include <scsi/scsi_bsg_fc.h>
1942e9a92fSRobert Love 
2042e9a92fSRobert Love #include <scsi/fc/fc_fcp.h>
2142e9a92fSRobert Love #include <scsi/fc/fc_ns.h>
22d78c317fSNeerav Parikh #include <scsi/fc/fc_ms.h>
2342e9a92fSRobert Love #include <scsi/fc/fc_els.h>
2442e9a92fSRobert Love #include <scsi/fc/fc_gs.h>
2542e9a92fSRobert Love 
2642e9a92fSRobert Love #include <scsi/fc_frame.h>
2742e9a92fSRobert Love 
2896ad8464SJoe Eykholt #define	FC_FC4_PROV_SIZE	(FC_TYPE_FCP + 1)	/* size of tables */
2996ad8464SJoe Eykholt 
3042e9a92fSRobert Love /*
3142e9a92fSRobert Love  * libfc error codes
3242e9a92fSRobert Love  */
3342e9a92fSRobert Love #define	FC_NO_ERR	0	/* no error */
3442e9a92fSRobert Love #define	FC_EX_TIMEOUT	1	/* Exchange timeout */
3542e9a92fSRobert Love #define	FC_EX_CLOSED	2	/* Exchange closed */
369f9504a7SHannes Reinecke #define FC_EX_ALLOC_ERR	3	/* Exchange allocation failed */
379f9504a7SHannes Reinecke #define FC_EX_XMIT_ERR	4	/* Exchange transmit failed */
389f9504a7SHannes Reinecke #define FC_EX_ELS_RJT	5	/* ELS rejected */
399f9504a7SHannes Reinecke #define FC_EX_INV_LOGIN	6	/* Login not completed */
409f9504a7SHannes Reinecke #define FC_EX_SEQ_ERR	6	/* Exchange sequence error */
4142e9a92fSRobert Love 
423a3b42bfSRobert Love /**
433a3b42bfSRobert Love  * enum fc_lport_state - Local port states
443a3b42bfSRobert Love  * @LPORT_ST_DISABLED: Disabled
453a3b42bfSRobert Love  * @LPORT_ST_FLOGI:    Fabric login (FLOGI) sent
463a3b42bfSRobert Love  * @LPORT_ST_DNS:      Waiting for name server remote port to become ready
47*9cef74a9SRandy Dunlap  * @LPORT_ST_RNN_ID:   Register port name by ID (RNN_ID) sent
48*9cef74a9SRandy Dunlap  * @LPORT_ST_RSNN_NN:  Waiting for host symbolic node name
49*9cef74a9SRandy Dunlap  * @LPORT_ST_RSPN_ID:  Waiting for host symbolic port name
503a3b42bfSRobert Love  * @LPORT_ST_RFT_ID:   Register Fibre Channel types by ID (RFT_ID) sent
51ab593b18SJoe Eykholt  * @LPORT_ST_RFF_ID:   Register FC-4 Features by ID (RFF_ID) sent
52d78c317fSNeerav Parikh  * @LPORT_ST_FDMI:     Waiting for mgmt server rport to become ready
53*9cef74a9SRandy Dunlap  * @LPORT_ST_RHBA:     Register HBA
54*9cef74a9SRandy Dunlap  * @LPORT_ST_RPA:      Register Port Attributes
55*9cef74a9SRandy Dunlap  * @LPORT_ST_DHBA:     Deregister HBA
56*9cef74a9SRandy Dunlap  * @LPORT_ST_DPRT:     Deregister Port
573a3b42bfSRobert Love  * @LPORT_ST_SCR:      State Change Register (SCR) sent
583a3b42bfSRobert Love  * @LPORT_ST_READY:    Ready for use
593a3b42bfSRobert Love  * @LPORT_ST_LOGO:     Local port logout (LOGO) sent
603a3b42bfSRobert Love  * @LPORT_ST_RESET:    Local port reset
6142e9a92fSRobert Love  */
6242e9a92fSRobert Love enum fc_lport_state {
63b1d9fd55SJoe Eykholt 	LPORT_ST_DISABLED = 0,
6442e9a92fSRobert Love 	LPORT_ST_FLOGI,
6542e9a92fSRobert Love 	LPORT_ST_DNS,
66c9c7bd7aSChris Leech 	LPORT_ST_RNN_ID,
675baa17c3SChris Leech 	LPORT_ST_RSNN_NN,
68c9866a54SChris Leech 	LPORT_ST_RSPN_ID,
6942e9a92fSRobert Love 	LPORT_ST_RFT_ID,
70ab593b18SJoe Eykholt 	LPORT_ST_RFF_ID,
71d78c317fSNeerav Parikh 	LPORT_ST_FDMI,
72d78c317fSNeerav Parikh 	LPORT_ST_RHBA,
73d78c317fSNeerav Parikh 	LPORT_ST_RPA,
74d78c317fSNeerav Parikh 	LPORT_ST_DHBA,
75d78c317fSNeerav Parikh 	LPORT_ST_DPRT,
7642e9a92fSRobert Love 	LPORT_ST_SCR,
7742e9a92fSRobert Love 	LPORT_ST_READY,
7842e9a92fSRobert Love 	LPORT_ST_LOGO,
7942e9a92fSRobert Love 	LPORT_ST_RESET
8042e9a92fSRobert Love };
8142e9a92fSRobert Love 
8242e9a92fSRobert Love enum fc_disc_event {
8342e9a92fSRobert Love 	DISC_EV_NONE = 0,
8442e9a92fSRobert Love 	DISC_EV_SUCCESS,
8542e9a92fSRobert Love 	DISC_EV_FAILED
8642e9a92fSRobert Love };
8742e9a92fSRobert Love 
883a3b42bfSRobert Love /**
893a3b42bfSRobert Love  * enum fc_rport_state - Remote port states
903a3b42bfSRobert Love  * @RPORT_ST_INIT:    Initialized
91a7b12a27SJoe Eykholt  * @RPORT_ST_FLOGI:   Waiting for FLOGI completion for point-to-multipoint
92a7b12a27SJoe Eykholt  * @RPORT_ST_PLOGI_WAIT:   Waiting for peer to login for point-to-multipoint
933a3b42bfSRobert Love  * @RPORT_ST_PLOGI:   Waiting for PLOGI completion
943a3b42bfSRobert Love  * @RPORT_ST_PRLI:    Waiting for PRLI completion
953a3b42bfSRobert Love  * @RPORT_ST_RTV:     Waiting for RTV completion
963a3b42bfSRobert Love  * @RPORT_ST_READY:   Ready for use
973a3b42bfSRobert Love  * @RPORT_ST_ADISC:   Discover Address sent
983a3b42bfSRobert Love  * @RPORT_ST_DELETE:  Remote port being deleted
993a3b42bfSRobert Love */
10042e9a92fSRobert Love enum fc_rport_state {
1013a3b42bfSRobert Love 	RPORT_ST_INIT,
102a7b12a27SJoe Eykholt 	RPORT_ST_FLOGI,
103a7b12a27SJoe Eykholt 	RPORT_ST_PLOGI_WAIT,
1043a3b42bfSRobert Love 	RPORT_ST_PLOGI,
1053a3b42bfSRobert Love 	RPORT_ST_PRLI,
1063a3b42bfSRobert Love 	RPORT_ST_RTV,
1073a3b42bfSRobert Love 	RPORT_ST_READY,
1083a3b42bfSRobert Love 	RPORT_ST_ADISC,
1093a3b42bfSRobert Love 	RPORT_ST_DELETE,
11042e9a92fSRobert Love };
11142e9a92fSRobert Love 
11242e9a92fSRobert Love /**
11342e9a92fSRobert Love  * struct fc_disc_port - temporary discovery port to hold rport identifiers
11442e9a92fSRobert Love  * @lp:         Fibre Channel host port instance
1159737e6a7SRobert Love  * @peers:      Node for list management during discovery and RSCN processing
1169737e6a7SRobert Love  * @rport_work: Work struct for starting the rport state machine
1179737e6a7SRobert Love  * @port_id:    Port ID of the discovered port
11842e9a92fSRobert Love  */
11942e9a92fSRobert Love struct fc_disc_port {
12042e9a92fSRobert Love 	struct fc_lport    *lp;
12142e9a92fSRobert Love 	struct list_head   peers;
12242e9a92fSRobert Love 	struct work_struct rport_work;
1239737e6a7SRobert Love 	u32		   port_id;
12442e9a92fSRobert Love };
12542e9a92fSRobert Love 
1263a3b42bfSRobert Love /**
1273a3b42bfSRobert Love  * enum fc_rport_event - Remote port events
1283a3b42bfSRobert Love  * @RPORT_EV_NONE:   No event
1293a3b42bfSRobert Love  * @RPORT_EV_READY:  Remote port is ready for use
1303a3b42bfSRobert Love  * @RPORT_EV_FAILED: State machine failed, remote port is not ready
1313a3b42bfSRobert Love  * @RPORT_EV_STOP:   Remote port has been stopped
1323a3b42bfSRobert Love  * @RPORT_EV_LOGO:   Remote port logout (LOGO) sent
1333a3b42bfSRobert Love  */
13442e9a92fSRobert Love enum fc_rport_event {
13542e9a92fSRobert Love 	RPORT_EV_NONE = 0,
1364c0f62b5SJoe Eykholt 	RPORT_EV_READY,
13742e9a92fSRobert Love 	RPORT_EV_FAILED,
13842e9a92fSRobert Love 	RPORT_EV_STOP,
13942e9a92fSRobert Love 	RPORT_EV_LOGO
14042e9a92fSRobert Love };
14142e9a92fSRobert Love 
1429fb9d328SJoe Eykholt struct fc_rport_priv;
1439fb9d328SJoe Eykholt 
1443a3b42bfSRobert Love /**
1453a3b42bfSRobert Love  * struct fc_rport_operations - Operations for a remote port
1463a3b42bfSRobert Love  * @event_callback: Function to be called for remote port events
1473a3b42bfSRobert Love  */
14842e9a92fSRobert Love struct fc_rport_operations {
1499fb9d328SJoe Eykholt 	void (*event_callback)(struct fc_lport *, struct fc_rport_priv *,
15042e9a92fSRobert Love 			       enum fc_rport_event);
15142e9a92fSRobert Love };
15242e9a92fSRobert Love 
15342e9a92fSRobert Love /**
15442e9a92fSRobert Love  * struct fc_rport_libfc_priv - libfc internal information about a remote port
1553a3b42bfSRobert Love  * @local_port: The associated local port
1563a3b42bfSRobert Love  * @rp_state:   Indicates READY for I/O or DELETE when blocked
1579e9d0452SJoe Eykholt  * @flags:      REC and RETRY supported flags
1583a3b42bfSRobert Love  * @e_d_tov:    Error detect timeout value (in msec)
1593a3b42bfSRobert Love  * @r_a_tov:    Resource allocation timeout value (in msec)
1609e9d0452SJoe Eykholt  */
1619e9d0452SJoe Eykholt struct fc_rport_libfc_priv {
1629e9d0452SJoe Eykholt 	struct fc_lport		   *local_port;
1639e9d0452SJoe Eykholt 	enum fc_rport_state	   rp_state;
1649e9d0452SJoe Eykholt 	u16			   flags;
1659e9d0452SJoe Eykholt 	#define FC_RP_FLAGS_REC_SUPPORTED	(1 << 0)
1669e9d0452SJoe Eykholt 	#define FC_RP_FLAGS_RETRY		(1 << 1)
1674b2164d4SJoe Eykholt 	#define FC_RP_STARTED			(1 << 2)
16875a2792dSBhanu Prakash Gollapudi 	#define FC_RP_FLAGS_CONF_REQ		(1 << 3)
1699e9d0452SJoe Eykholt 	unsigned int		   e_d_tov;
1709e9d0452SJoe Eykholt 	unsigned int		   r_a_tov;
1719e9d0452SJoe Eykholt };
1729e9d0452SJoe Eykholt 
1739e9d0452SJoe Eykholt /**
1743a3b42bfSRobert Love  * struct fc_rport_priv - libfc remote port and discovery info
1753a3b42bfSRobert Love  * @local_port:     The associated local port
1763a3b42bfSRobert Love  * @rport:          The FC transport remote port
1773a3b42bfSRobert Love  * @kref:           Reference counter
1783a3b42bfSRobert Love  * @rp_state:       Enumeration that tracks progress of PLOGI, PRLI,
1793a3b42bfSRobert Love  *                  and RTV exchanges
1803a3b42bfSRobert Love  * @ids:            The remote port identifiers and roles
1814b2164d4SJoe Eykholt  * @flags:          STARTED, REC and RETRY_SUPPORTED flags
1823a3b42bfSRobert Love  * @max_seq:        Maximum number of concurrent sequences
1833a3b42bfSRobert Love  * @disc_id:        The discovery identifier
1843a3b42bfSRobert Love  * @maxframe_size:  The maximum frame size
1853a3b42bfSRobert Love  * @retries:        The retry count for the current state
186f034260dSJoe Eykholt  * @major_retries:  The retry count for the entire PLOGI/PRLI state machine
1873a3b42bfSRobert Love  * @e_d_tov:        Error detect timeout value (in msec)
1883a3b42bfSRobert Love  * @r_a_tov:        Resource allocation timeout value (in msec)
1893a3b42bfSRobert Love  * @rp_mutex:       The mutex that protects the remote port
1903a3b42bfSRobert Love  * @retry_work:     Handle for retries
191*9cef74a9SRandy Dunlap  * @lld_event_callback: Callback when READY, FAILED or LOGO states complete
19296ad8464SJoe Eykholt  * @prli_count:     Count of open PRLI sessions in providers
19342e90414SJoe Eykholt  * @rcu:	    Structure used for freeing in an RCU-safe manner
19442e9a92fSRobert Love  */
1959e9d0452SJoe Eykholt struct fc_rport_priv {
19642e9a92fSRobert Love 	struct fc_lport		    *local_port;
197f211fa51SJoe Eykholt 	struct fc_rport		    *rport;
198f211fa51SJoe Eykholt 	struct kref		    kref;
19942e9a92fSRobert Love 	enum fc_rport_state	    rp_state;
200f211fa51SJoe Eykholt 	struct fc_rport_identifiers ids;
20142e9a92fSRobert Love 	u16			    flags;
20242e9a92fSRobert Love 	u16			    max_seq;
2030f6c6149SJoe Eykholt 	u16			    disc_id;
204f211fa51SJoe Eykholt 	u16			    maxframe_size;
20542e9a92fSRobert Love 	unsigned int		    retries;
206f034260dSJoe Eykholt 	unsigned int		    major_retries;
20742e9a92fSRobert Love 	unsigned int		    e_d_tov;
20842e9a92fSRobert Love 	unsigned int		    r_a_tov;
20942e9a92fSRobert Love 	struct mutex		    rp_mutex;
21042e9a92fSRobert Love 	struct delayed_work	    retry_work;
21142e9a92fSRobert Love 	enum fc_rport_event	    event;
21242e9a92fSRobert Love 	struct fc_rport_operations  *ops;
21342e9a92fSRobert Love 	struct list_head	    peers;
21442e9a92fSRobert Love 	struct work_struct	    event_work;
215f211fa51SJoe Eykholt 	u32			    supported_classes;
21696ad8464SJoe Eykholt 	u16			    prli_count;
21742e90414SJoe Eykholt 	struct rcu_head		    rcu;
21875a2792dSBhanu Prakash Gollapudi 	u16			    sp_features;
21975a2792dSBhanu Prakash Gollapudi 	u8			    spp_type;
22075a2792dSBhanu Prakash Gollapudi 	void			    (*lld_event_callback)(struct fc_lport *,
22175a2792dSBhanu Prakash Gollapudi 						      struct fc_rport_priv *,
22275a2792dSBhanu Prakash Gollapudi 						      enum fc_rport_event);
22342e9a92fSRobert Love };
22442e9a92fSRobert Love 
2253a3b42bfSRobert Love /**
2261bd49b48SVasu Dev  * struct fc_stats - fc stats structure
2273a3b42bfSRobert Love  * @SecondsSinceLastReset: Seconds since the last reset
2283a3b42bfSRobert Love  * @TxFrames:              Number of transmitted frames
2293a3b42bfSRobert Love  * @TxWords:               Number of transmitted words
2303a3b42bfSRobert Love  * @RxFrames:              Number of received frames
2313a3b42bfSRobert Love  * @RxWords:               Number of received words
2323a3b42bfSRobert Love  * @ErrorFrames:           Number of received error frames
2333a3b42bfSRobert Love  * @DumpedFrames:          Number of dumped frames
2340f02a665SVasu Dev  * @FcpPktAllocFails:      Number of fcp packet allocation failures
2350f02a665SVasu Dev  * @FcpPktAborts:          Number of fcp packet aborts
2360f02a665SVasu Dev  * @FcpFrameAllocFails:    Number of fcp frame allocation failures
2373a3b42bfSRobert Love  * @LinkFailureCount:      Number of link failures
2383a3b42bfSRobert Love  * @LossOfSignalCount:     Number for signal losses
2393a3b42bfSRobert Love  * @InvalidTxWordCount:    Number of invalid transmitted words
2403a3b42bfSRobert Love  * @InvalidCRCCount:       Number of invalid CRCs
2413a3b42bfSRobert Love  * @InputRequests:         Number of input requests
2423a3b42bfSRobert Love  * @OutputRequests:        Number of output requests
2433a3b42bfSRobert Love  * @ControlRequests:       Number of control requests
2445f0e385fSJoe Eykholt  * @InputBytes:            Number of received bytes
2455f0e385fSJoe Eykholt  * @OutputBytes:           Number of transmitted bytes
2466580bbd0SYi Zou  * @VLinkFailureCount:     Number of virtual link failures
2476580bbd0SYi Zou  * @MissDiscAdvCount:      Number of missing FIP discovery advertisement
24842e9a92fSRobert Love  */
2491bd49b48SVasu Dev struct fc_stats {
25042e9a92fSRobert Love 	u64		SecondsSinceLastReset;
25142e9a92fSRobert Love 	u64		TxFrames;
25242e9a92fSRobert Love 	u64		TxWords;
25342e9a92fSRobert Love 	u64		RxFrames;
25442e9a92fSRobert Love 	u64		RxWords;
25542e9a92fSRobert Love 	u64		ErrorFrames;
25642e9a92fSRobert Love 	u64		DumpedFrames;
2570f02a665SVasu Dev 	u64		FcpPktAllocFails;
2580f02a665SVasu Dev 	u64		FcpPktAborts;
2590f02a665SVasu Dev 	u64		FcpFrameAllocFails;
26042e9a92fSRobert Love 	u64		LinkFailureCount;
26142e9a92fSRobert Love 	u64		LossOfSignalCount;
26242e9a92fSRobert Love 	u64		InvalidTxWordCount;
26342e9a92fSRobert Love 	u64		InvalidCRCCount;
26442e9a92fSRobert Love 	u64		InputRequests;
26542e9a92fSRobert Love 	u64		OutputRequests;
26642e9a92fSRobert Love 	u64		ControlRequests;
2675f0e385fSJoe Eykholt 	u64		InputBytes;
2685f0e385fSJoe Eykholt 	u64		OutputBytes;
2696580bbd0SYi Zou 	u64		VLinkFailureCount;
2706580bbd0SYi Zou 	u64		MissDiscAdvCount;
27142e9a92fSRobert Love };
27242e9a92fSRobert Love 
2733a3b42bfSRobert Love /**
2743a3b42bfSRobert Love  * struct fc_seq_els_data - ELS data used for passing ELS specific responses
2753a3b42bfSRobert Love  * @reason: The reason for rejection
27625985edcSLucas De Marchi  * @explan: The explanation of the rejection
2773a3b42bfSRobert Love  *
2783a3b42bfSRobert Love  * Mainly used by the exchange manager layer.
27942e9a92fSRobert Love  */
28042e9a92fSRobert Love struct fc_seq_els_data {
28142e9a92fSRobert Love 	enum fc_els_rjt_reason reason;
28242e9a92fSRobert Love 	enum fc_els_rjt_explan explan;
28342e9a92fSRobert Love };
28442e9a92fSRobert Love 
2853a3b42bfSRobert Love /**
2863a3b42bfSRobert Love  * struct fc_fcp_pkt - FCP request structure (one for each scsi_cmnd request)
2873a3b42bfSRobert Love  * @lp:              The associated local port
2883a3b42bfSRobert Love  * @state:           The state of the I/O
2893a3b42bfSRobert Love  * @ref_cnt:         Reference count
2903a3b42bfSRobert Love  * @scsi_pkt_lock:   Lock to protect the SCSI packet (must be taken before the
2913a3b42bfSRobert Love  *                   host_lock if both are to be held at the same time)
2923a3b42bfSRobert Love  * @cmd:             The SCSI command (set and clear with the host_lock held)
2933a3b42bfSRobert Love  * @list:            Tracks queued commands (accessed with the host_lock held)
2943a3b42bfSRobert Love  * @timer:           The command timer
2953a3b42bfSRobert Love  * @tm_done:         Completion indicator
2963a3b42bfSRobert Love  * @wait_for_comp:   Indicator to wait for completion of the I/O (in jiffies)
297*9cef74a9SRandy Dunlap  * @timer_delay:     FCP packet timer delay in jiffies
2983a3b42bfSRobert Love  * @data_len:        The length of the data
2993a3b42bfSRobert Love  * @cdb_cmd:         The CDB command
3003a3b42bfSRobert Love  * @xfer_len:        The transfer length
3013a3b42bfSRobert Love  * @xfer_ddp:        Indicates if this transfer used DDP (XID of the exchange
3023a3b42bfSRobert Love  *                   will be set here if DDP was setup)
3033a3b42bfSRobert Love  * @xfer_contig_end: The offset into the buffer if the buffer is contiguous
3043a3b42bfSRobert Love  *                   (Tx and Rx)
3053a3b42bfSRobert Love  * @max_payload:     The maximum payload size (in bytes)
3063a3b42bfSRobert Love  * @io_status:       SCSI result (upper 24 bits)
3073a3b42bfSRobert Love  * @cdb_status:      CDB status
3083a3b42bfSRobert Love  * @status_code:     FCP I/O status
3093a3b42bfSRobert Love  * @scsi_comp_flags: Completion flags (bit 3 Underrun bit 2: overrun)
3103a3b42bfSRobert Love  * @req_flags:       Request flags (bit 0: read bit:1 write)
3113a3b42bfSRobert Love  * @scsi_resid:      SCSI residule length
3123a3b42bfSRobert Love  * @rport:           The remote port that the SCSI command is targeted at
3133a3b42bfSRobert Love  * @seq_ptr:         The sequence that will carry the SCSI command
3143a3b42bfSRobert Love  * @recov_retry:     Number of recovery retries
3153a3b42bfSRobert Love  * @recov_seq:       The sequence for REC or SRR
31642e9a92fSRobert Love  */
31742e9a92fSRobert Love struct fc_fcp_pkt {
3183a3b42bfSRobert Love 	spinlock_t	  scsi_pkt_lock;
31922c70d1aSElena Reshetova 	refcount_t	  ref_cnt;
320ed26cfecSVasu Dev 
321ed26cfecSVasu Dev 	/* SCSI command and data transfer information */
322ed26cfecSVasu Dev 	u32		  data_len;
3233a3b42bfSRobert Love 
3243a3b42bfSRobert Love 	/* SCSI I/O related information */
3253a3b42bfSRobert Love 	struct scsi_cmnd  *cmd;
3263a3b42bfSRobert Love 	struct list_head  list;
3273a3b42bfSRobert Love 
328ed26cfecSVasu Dev 	/* Housekeeping information */
329ed26cfecSVasu Dev 	struct fc_lport   *lp;
330ed26cfecSVasu Dev 	u8		  state;
33142e9a92fSRobert Love 
3323a3b42bfSRobert Love 	/* SCSI/FCP return status */
33342e9a92fSRobert Love 	u8		  cdb_status;
3343a3b42bfSRobert Love 	u8		  status_code;
33542e9a92fSRobert Love 	u8		  scsi_comp_flags;
336ed26cfecSVasu Dev 	u32		  io_status;
3373a3b42bfSRobert Love 	u32		  req_flags;
3383a3b42bfSRobert Love 	u32		  scsi_resid;
33942e9a92fSRobert Love 
340ed26cfecSVasu Dev 	/* Transport related veriables */
341ed26cfecSVasu Dev 	size_t		  xfer_len;
342ed26cfecSVasu Dev 	struct fcp_cmnd   cdb_cmd;
343ed26cfecSVasu Dev 	u32		  xfer_contig_end;
344ed26cfecSVasu Dev 	u16		  max_payload;
345ed26cfecSVasu Dev 	u16		  xfer_ddp;
346ed26cfecSVasu Dev 
3473a3b42bfSRobert Love 	/* Associated structures */
3483a3b42bfSRobert Love 	struct fc_rport	  *rport;
3493a3b42bfSRobert Love 	struct fc_seq	  *seq_ptr;
3503a3b42bfSRobert Love 
351ed26cfecSVasu Dev 	/* Timeout/error related information */
352ed26cfecSVasu Dev 	struct timer_list timer;
353ed26cfecSVasu Dev 	int		  wait_for_comp;
354ad3120cfSHannes Reinecke 	int		  timer_delay;
355ed26cfecSVasu Dev 	u32		  recov_retry;
3563a3b42bfSRobert Love 	struct fc_seq	  *recov_seq;
357ed26cfecSVasu Dev 	struct completion tm_done;
358ed26cfecSVasu Dev } ____cacheline_aligned_in_smp;
35942e9a92fSRobert Love 
36042e9a92fSRobert Love /*
3615d21aa36SBart Van Assche  * @fsp should be tested and set under the scsi_pkt_queue lock
3625d21aa36SBart Van Assche  */
3635d21aa36SBart Van Assche struct libfc_cmd_priv {
3645d21aa36SBart Van Assche 	struct fc_fcp_pkt *fsp;
3655d21aa36SBart Van Assche 	u32 resid_len;
3665d21aa36SBart Van Assche 	u8 status;
3675d21aa36SBart Van Assche };
3685d21aa36SBart Van Assche 
3695d21aa36SBart Van Assche /*
37042e9a92fSRobert Love  * Structure and function definitions for managing Fibre Channel Exchanges
37142e9a92fSRobert Love  * and Sequences
37242e9a92fSRobert Love  *
37342e9a92fSRobert Love  * fc_exch holds state for one exchange and links to its active sequence.
37442e9a92fSRobert Love  *
37542e9a92fSRobert Love  * fc_seq holds the state for an individual sequence.
37642e9a92fSRobert Love  */
37742e9a92fSRobert Love 
37842e9a92fSRobert Love struct fc_exch_mgr;
37996316099SVasu Dev struct fc_exch_mgr_anchor;
380e4bc50beSVasu Dev extern u16 fc_cpu_mask;	/* cpu mask for possible cpus */
38142e9a92fSRobert Love 
3823a3b42bfSRobert Love /**
3833a3b42bfSRobert Love  * struct fc_seq - FC sequence
3843a3b42bfSRobert Love  * @id:       The sequence ID
3853a3b42bfSRobert Love  * @ssb_stat: Status flags for the sequence status block (SSB)
3863a3b42bfSRobert Love  * @cnt:      Number of frames sent so far
3873a3b42bfSRobert Love  * @rec_data: FC-4 value for REC
38842e9a92fSRobert Love  */
38942e9a92fSRobert Love struct fc_seq {
3903a3b42bfSRobert Love 	u8  id;
3913a3b42bfSRobert Love 	u16 ssb_stat;
3923a3b42bfSRobert Love 	u16 cnt;
3933a3b42bfSRobert Love 	u32 rec_data;
39442e9a92fSRobert Love };
39542e9a92fSRobert Love 
39642e9a92fSRobert Love #define FC_EX_DONE		(1 << 0) /* ep is completed */
39742e9a92fSRobert Love #define FC_EX_RST_CLEANUP	(1 << 1) /* reset is forcing completion */
3989ca1e182SHannes Reinecke #define FC_EX_QUARANTINE	(1 << 2) /* exch is quarantined */
39942e9a92fSRobert Love 
4003a3b42bfSRobert Love /**
4013a3b42bfSRobert Love  * struct fc_exch - Fibre Channel Exchange
4023a3b42bfSRobert Love  * @em:           Exchange manager
4033a3b42bfSRobert Love  * @pool:         Exchange pool
4043a3b42bfSRobert Love  * @state:        The exchange's state
4053a3b42bfSRobert Love  * @xid:          The exchange ID
4063a3b42bfSRobert Love  * @ex_list:      Handle used by the EM to track free exchanges
4073a3b42bfSRobert Love  * @ex_lock:      Lock that protects the exchange
4083a3b42bfSRobert Love  * @ex_refcnt:    Reference count
4093a3b42bfSRobert Love  * @timeout_work: Handle for timeout handler
4103a3b42bfSRobert Love  * @lp:           The local port that this exchange is on
4113a3b42bfSRobert Love  * @oxid:         Originator's exchange ID
4123a3b42bfSRobert Love  * @rxid:         Responder's exchange ID
4133a3b42bfSRobert Love  * @oid:          Originator's FCID
4143a3b42bfSRobert Love  * @sid:          Source FCID
4153a3b42bfSRobert Love  * @did:          Destination FCID
4163a3b42bfSRobert Love  * @esb_stat:     ESB exchange status
41740d6b939SZhen Lei  * @r_a_tov:      Resource allocation time out value (in msecs)
4183a3b42bfSRobert Love  * @seq_id:       The next sequence ID to use
419f60e12e9SJoe Eykholt  * @encaps:       encapsulation information for lower-level driver
4203a3b42bfSRobert Love  * @f_ctl:        F_CTL flags for the sequence
4213a3b42bfSRobert Love  * @fh_type:      The frame type
4223a3b42bfSRobert Love  * @class:        The class of service
4233a3b42bfSRobert Love  * @seq:          The sequence in use on this exchange
4247030fd62SBart Van Assche  * @resp_active:  Number of tasks that are concurrently executing @resp().
4257030fd62SBart Van Assche  * @resp_task:    If @resp_active > 0, either the task executing @resp(), the
4267030fd62SBart Van Assche  *                task that has been interrupted to execute the soft-IRQ
4277030fd62SBart Van Assche  *                executing @resp() or NULL if more than one task is executing
4287030fd62SBart Van Assche  *                @resp concurrently.
4297030fd62SBart Van Assche  * @resp_wq:      Waitqueue for the tasks waiting on @resp_active.
4303a3b42bfSRobert Love  * @resp:         Callback for responses on this exchange
4313a3b42bfSRobert Love  * @destructor:   Called when destroying the exchange
4323a3b42bfSRobert Love  * @arg:          Passed as a void pointer to the resp() callback
43342e9a92fSRobert Love  *
43442e9a92fSRobert Love  * Locking notes: The ex_lock protects following items:
43542e9a92fSRobert Love  *	state, esb_stat, f_ctl, seq.ssb_stat
43642e9a92fSRobert Love  *	seq_id
43742e9a92fSRobert Love  *	sequence allocation
43842e9a92fSRobert Love  */
43942e9a92fSRobert Love struct fc_exch {
4403a3b42bfSRobert Love 	spinlock_t	    ex_lock;
4413a3b42bfSRobert Love 	atomic_t	    ex_refcnt;
44249a19889SVasu Dev 	enum fc_class	    class;
44349a19889SVasu Dev 	struct fc_exch_mgr  *em;
44449a19889SVasu Dev 	struct fc_exch_pool *pool;
44549a19889SVasu Dev 	struct list_head    ex_list;
4463a3b42bfSRobert Love 	struct fc_lport	    *lp;
44749a19889SVasu Dev 	u32		    esb_stat;
44849a19889SVasu Dev 	u8		    state;
44949a19889SVasu Dev 	u8		    fh_type;
45049a19889SVasu Dev 	u8		    seq_id;
45149a19889SVasu Dev 	u8		    encaps;
45249a19889SVasu Dev 	u16		    xid;
4533a3b42bfSRobert Love 	u16		    oxid;
4543a3b42bfSRobert Love 	u16		    rxid;
4553a3b42bfSRobert Love 	u32		    oid;
4563a3b42bfSRobert Love 	u32		    sid;
4573a3b42bfSRobert Love 	u32		    did;
4583a3b42bfSRobert Love 	u32		    r_a_tov;
4593a3b42bfSRobert Love 	u32		    f_ctl;
4603a3b42bfSRobert Love 	struct fc_seq       seq;
4617030fd62SBart Van Assche 	int		    resp_active;
4627030fd62SBart Van Assche 	struct task_struct  *resp_task;
4637030fd62SBart Van Assche 	wait_queue_head_t   resp_wq;
46442e9a92fSRobert Love 	void		    (*resp)(struct fc_seq *, struct fc_frame *, void *);
46542e9a92fSRobert Love 	void		    *arg;
4663a3b42bfSRobert Love 	void		    (*destructor)(struct fc_seq *, void *);
46749a19889SVasu Dev 	struct delayed_work timeout_work;
46849a19889SVasu Dev } ____cacheline_aligned_in_smp;
46942e9a92fSRobert Love #define	fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
47042e9a92fSRobert Love 
47142e9a92fSRobert Love 
4723a3b42bfSRobert Love struct libfc_function_template {
47342e9a92fSRobert Love 	/*
47442e9a92fSRobert Love 	 * Interface to send a FC frame
4750ae4d4aeSRobert Love 	 *
4760ae4d4aeSRobert Love 	 * STATUS: REQUIRED
47742e9a92fSRobert Love 	 */
4783a3b42bfSRobert Love 	int (*frame_send)(struct fc_lport *, struct fc_frame *);
47942e9a92fSRobert Love 
48042e9a92fSRobert Love 	/*
4810ae4d4aeSRobert Love 	 * Interface to send ELS/CT frames
4820ae4d4aeSRobert Love 	 *
4830ae4d4aeSRobert Love 	 * STATUS: OPTIONAL
48442e9a92fSRobert Love 	 */
4853a3b42bfSRobert Love 	struct fc_seq *(*elsct_send)(struct fc_lport *, u32 did,
4863a3b42bfSRobert Love 				     struct fc_frame *, unsigned int op,
48742e9a92fSRobert Love 				     void (*resp)(struct fc_seq *,
4883a3b42bfSRobert Love 					     struct fc_frame *, void *arg),
48942e9a92fSRobert Love 				     void *arg, u32 timer_msec);
49042e9a92fSRobert Love 
49142e9a92fSRobert Love 	/*
492b277d2aaSYi Zou 	 * Sets up the DDP context for a given exchange id on the given
493b277d2aaSYi Zou 	 * scatterlist if LLD supports DDP for large receive.
494b277d2aaSYi Zou 	 *
495b277d2aaSYi Zou 	 * STATUS: OPTIONAL
496b277d2aaSYi Zou 	 */
4973a3b42bfSRobert Love 	int (*ddp_setup)(struct fc_lport *, u16, struct scatterlist *,
4983a3b42bfSRobert Love 			 unsigned int);
499b277d2aaSYi Zou 	/*
500b277d2aaSYi Zou 	 * Completes the DDP transfer and returns the length of data DDPed
501b277d2aaSYi Zou 	 * for the given exchange id.
502b277d2aaSYi Zou 	 *
503b277d2aaSYi Zou 	 * STATUS: OPTIONAL
504b277d2aaSYi Zou 	 */
5053a3b42bfSRobert Love 	int (*ddp_done)(struct fc_lport *, u16);
506b277d2aaSYi Zou 	/*
50733dc362bSYi Zou 	 * Sets up the DDP context for a given exchange id on the given
5081bd49b48SVasu Dev 	 * scatterlist if LLD supports DDP for target.
50933dc362bSYi Zou 	 *
51033dc362bSYi Zou 	 * STATUS: OPTIONAL
51133dc362bSYi Zou 	 */
51233dc362bSYi Zou 	int (*ddp_target)(struct fc_lport *, u16, struct scatterlist *,
51333dc362bSYi Zou 			  unsigned int);
51433dc362bSYi Zou 	/*
515b84056bfSYi Zou 	 * Allow LLD to fill its own Link Error Status Block
516b84056bfSYi Zou 	 *
517b84056bfSYi Zou 	 * STATUS: OPTIONAL
518b84056bfSYi Zou 	 */
519b84056bfSYi Zou 	void (*get_lesb)(struct fc_lport *, struct fc_els_lesb *lesb);
52042e9a92fSRobert Love 
52142e9a92fSRobert Love 	/*
52242e9a92fSRobert Love 	 * Reset an exchange manager, completing all sequences and exchanges.
52342e9a92fSRobert Love 	 * If s_id is non-zero, reset only exchanges originating from that FID.
52442e9a92fSRobert Love 	 * If d_id is non-zero, reset only exchanges sending to that FID.
5250ae4d4aeSRobert Love 	 *
5260ae4d4aeSRobert Love 	 * STATUS: OPTIONAL
52742e9a92fSRobert Love 	 */
5283a3b42bfSRobert Love 	void (*exch_mgr_reset)(struct fc_lport *, u32 s_id, u32 d_id);
52942e9a92fSRobert Love 
5300ae4d4aeSRobert Love 	/*
531093bb6a2SJoe Eykholt 	 * Set the local port FC_ID.
532093bb6a2SJoe Eykholt 	 *
533093bb6a2SJoe Eykholt 	 * This may be provided by the LLD to allow it to be
534093bb6a2SJoe Eykholt 	 * notified when the local port is assigned a FC-ID.
535093bb6a2SJoe Eykholt 	 *
536093bb6a2SJoe Eykholt 	 * The frame, if non-NULL, is the incoming frame with the
537093bb6a2SJoe Eykholt 	 * FLOGI LS_ACC or FLOGI, and may contain the granted MAC
538093bb6a2SJoe Eykholt 	 * address for the LLD.  The frame pointer may be NULL if
539093bb6a2SJoe Eykholt 	 * no MAC is associated with this assignment (LOGO or PLOGI).
540093bb6a2SJoe Eykholt 	 *
541093bb6a2SJoe Eykholt 	 * If FC_ID is non-zero, r_a_tov and e_d_tov must be valid.
542093bb6a2SJoe Eykholt 	 *
543093bb6a2SJoe Eykholt 	 * Note: this is called with the local port mutex held.
544093bb6a2SJoe Eykholt 	 *
545093bb6a2SJoe Eykholt 	 * STATUS: OPTIONAL
546093bb6a2SJoe Eykholt 	 */
547093bb6a2SJoe Eykholt 	void (*lport_set_port_id)(struct fc_lport *, u32 port_id,
548093bb6a2SJoe Eykholt 				  struct fc_frame *);
549093bb6a2SJoe Eykholt 
550093bb6a2SJoe Eykholt 	/*
55175a2792dSBhanu Prakash Gollapudi 	 * Callback routine after the remote port is logged in
55275a2792dSBhanu Prakash Gollapudi 	 *
55375a2792dSBhanu Prakash Gollapudi 	 * STATUS: OPTIONAL
55475a2792dSBhanu Prakash Gollapudi 	 */
55575a2792dSBhanu Prakash Gollapudi 	void (*rport_event_callback)(struct fc_lport *,
55675a2792dSBhanu Prakash Gollapudi 				     struct fc_rport_priv *,
55775a2792dSBhanu Prakash Gollapudi 				     enum fc_rport_event);
55875a2792dSBhanu Prakash Gollapudi 
55975a2792dSBhanu Prakash Gollapudi 	/*
56042e9a92fSRobert Love 	 * Send a fcp cmd from fsp pkt.
56142e9a92fSRobert Love 	 * Called with the SCSI host lock unlocked and irqs disabled.
56242e9a92fSRobert Love 	 *
56342e9a92fSRobert Love 	 * The resp handler is called when FCP_RSP received.
56442e9a92fSRobert Love 	 *
5650ae4d4aeSRobert Love 	 * STATUS: OPTIONAL
56642e9a92fSRobert Love 	 */
5673a3b42bfSRobert Love 	int (*fcp_cmd_send)(struct fc_lport *, struct fc_fcp_pkt *,
5683a3b42bfSRobert Love 			    void (*resp)(struct fc_seq *, struct fc_frame *,
5693a3b42bfSRobert Love 					 void *));
57042e9a92fSRobert Love 
57142e9a92fSRobert Love 	/*
57225985edcSLucas De Marchi 	 * Cleanup the FCP layer, used during link down and reset
5730ae4d4aeSRobert Love 	 *
5740ae4d4aeSRobert Love 	 * STATUS: OPTIONAL
57542e9a92fSRobert Love 	 */
5763a3b42bfSRobert Love 	void (*fcp_cleanup)(struct fc_lport *);
57742e9a92fSRobert Love 
57842e9a92fSRobert Love 	/*
57942e9a92fSRobert Love 	 * Abort all I/O on a local port
5800ae4d4aeSRobert Love 	 *
5810ae4d4aeSRobert Love 	 * STATUS: OPTIONAL
58242e9a92fSRobert Love 	 */
5833a3b42bfSRobert Love 	void (*fcp_abort_io)(struct fc_lport *);
58442e9a92fSRobert Love 
5850ae4d4aeSRobert Love 	/*
5860ae4d4aeSRobert Love 	 * Receive a request for the discovery layer.
5870ae4d4aeSRobert Love 	 *
5880ae4d4aeSRobert Love 	 * STATUS: OPTIONAL
58942e9a92fSRobert Love 	 */
59092261156SJoe Eykholt 	void (*disc_recv_req)(struct fc_lport *, struct fc_frame *);
59142e9a92fSRobert Love 
59242e9a92fSRobert Love 	/*
59342e9a92fSRobert Love 	 * Start discovery for a local port.
5940ae4d4aeSRobert Love 	 *
5950ae4d4aeSRobert Love 	 * STATUS: OPTIONAL
59642e9a92fSRobert Love 	 */
59742e9a92fSRobert Love 	void (*disc_start)(void (*disc_callback)(struct fc_lport *,
59842e9a92fSRobert Love 						 enum fc_disc_event),
59942e9a92fSRobert Love 			   struct fc_lport *);
60042e9a92fSRobert Love 
60142e9a92fSRobert Love 	/*
60242e9a92fSRobert Love 	 * Stop discovery for a given lport. This will remove
60342e9a92fSRobert Love 	 * all discovered rports
6040ae4d4aeSRobert Love 	 *
6050ae4d4aeSRobert Love 	 * STATUS: OPTIONAL
60642e9a92fSRobert Love 	 */
60742e9a92fSRobert Love 	void (*disc_stop) (struct fc_lport *);
60842e9a92fSRobert Love 
60942e9a92fSRobert Love 	/*
61042e9a92fSRobert Love 	 * Stop discovery for a given lport. This will block
61142e9a92fSRobert Love 	 * until all discovered rports are deleted from the
61242e9a92fSRobert Love 	 * FC transport class
6130ae4d4aeSRobert Love 	 *
6140ae4d4aeSRobert Love 	 * STATUS: OPTIONAL
61542e9a92fSRobert Love 	 */
61642e9a92fSRobert Love 	void (*disc_stop_final) (struct fc_lport *);
61742e9a92fSRobert Love };
61842e9a92fSRobert Love 
6193a3b42bfSRobert Love /**
6203a3b42bfSRobert Love  * struct fc_disc - Discovery context
6213a3b42bfSRobert Love  * @retry_count:   Number of retries
6223a3b42bfSRobert Love  * @pending:       1 if discovery is pending, 0 if not
623c531b9b4SBhanu Prakash Gollapudi  * @requested:     1 if discovery has been requested, 0 if not
6243a3b42bfSRobert Love  * @seq_count:     Number of sequences used for discovery
6253a3b42bfSRobert Love  * @buf_len:       Length of the discovery buffer
6263a3b42bfSRobert Love  * @disc_id:       Discovery ID
6273a3b42bfSRobert Love  * @rports:        List of discovered remote ports
6280685230cSJoe Eykholt  * @priv:          Private pointer for use by discovery code
6293a3b42bfSRobert Love  * @disc_mutex:    Mutex that protects the discovery context
6303a3b42bfSRobert Love  * @partial_buf:   Partial name buffer (if names are returned
6313a3b42bfSRobert Love  *                 in multiple frames)
6323a3b42bfSRobert Love  * @disc_work:     handle for delayed work context
6333a3b42bfSRobert Love  * @disc_callback: Callback routine called when discovery completes
6343a3b42bfSRobert Love  */
63542e9a92fSRobert Love struct fc_disc {
63642e9a92fSRobert Love 	unsigned char	      retry_count;
63742e9a92fSRobert Love 	unsigned char	      pending;
63842e9a92fSRobert Love 	unsigned char	      requested;
63942e9a92fSRobert Love 	unsigned short	      seq_count;
64042e9a92fSRobert Love 	unsigned char	      buf_len;
6410f6c6149SJoe Eykholt 	u16		      disc_id;
64242e9a92fSRobert Love 
64342e9a92fSRobert Love 	struct list_head      rports;
6440685230cSJoe Eykholt 	void		      *priv;
64542e9a92fSRobert Love 	struct mutex	      disc_mutex;
6463a3b42bfSRobert Love 	struct fc_gpn_ft_resp partial_buf;
64742e9a92fSRobert Love 	struct delayed_work   disc_work;
6483a3b42bfSRobert Love 
6493a3b42bfSRobert Love 	void (*disc_callback)(struct fc_lport *,
6503a3b42bfSRobert Love 			      enum fc_disc_event);
65142e9a92fSRobert Love };
65242e9a92fSRobert Love 
65370d53b04SJoe Eykholt /*
65470d53b04SJoe Eykholt  * Local port notifier and events.
65570d53b04SJoe Eykholt  */
65670d53b04SJoe Eykholt extern struct blocking_notifier_head fc_lport_notifier_head;
65770d53b04SJoe Eykholt enum fc_lport_event {
65870d53b04SJoe Eykholt 	FC_LPORT_EV_ADD,
65970d53b04SJoe Eykholt 	FC_LPORT_EV_DEL,
66070d53b04SJoe Eykholt };
66170d53b04SJoe Eykholt 
6623a3b42bfSRobert Love /**
6633a3b42bfSRobert Love  * struct fc_lport - Local port
6643a3b42bfSRobert Love  * @host:                  The SCSI host associated with a local port
6653a3b42bfSRobert Love  * @ema_list:              Exchange manager anchor list
6663a3b42bfSRobert Love  * @dns_rdata:             The directory server remote port
667d78c317fSNeerav Parikh  * @ms_rdata:		   The management server remote port
6683a3b42bfSRobert Love  * @ptp_rdata:             Point to point remote port
6693a3b42bfSRobert Love  * @scsi_priv:             FCP layer internal data
6703a3b42bfSRobert Love  * @disc:                  Discovery context
6713a3b42bfSRobert Love  * @vports:                Child vports if N_Port
6723a3b42bfSRobert Love  * @vport:                 Parent vport if VN_Port
6733a3b42bfSRobert Love  * @tt:                    Libfc function template
6743a3b42bfSRobert Love  * @link_up:               Link state (1 = link up, 0 = link down)
6753a3b42bfSRobert Love  * @qfull:                 Queue state (1 queue is full, 0 queue is not full)
6763a3b42bfSRobert Love  * @state:                 Identifies the state
6773a3b42bfSRobert Love  * @boot_time:             Timestamp indicating when the local port came online
6783a3b42bfSRobert Love  * @host_stats:            SCSI host statistics
6791bd49b48SVasu Dev  * @stats:                 FC local port stats (TODO separate libfc LLD stats)
6803a3b42bfSRobert Love  * @retry_count:           Number of retries in the current state
6817b2787ecSRobert Love  * @port_id:               FC Port ID
6823a3b42bfSRobert Love  * @wwpn:                  World Wide Port Name
6833a3b42bfSRobert Love  * @wwnn:                  World Wide Node Name
6843a3b42bfSRobert Love  * @service_params:        Common service parameters
6853a3b42bfSRobert Love  * @e_d_tov:               Error detection timeout value
68640d6b939SZhen Lei  * @r_a_tov:               Resource allocation timeout value
6873a3b42bfSRobert Love  * @rnid_gen:              RNID information
6883a3b42bfSRobert Love  * @sg_supp:               Indicates if scatter gather is supported
6893a3b42bfSRobert Love  * @seq_offload:           Indicates if sequence offload is supported
6903a3b42bfSRobert Love  * @crc_offload:           Indicates if CRC offload is supported
6913a3b42bfSRobert Love  * @lro_enabled:           Indicates if large receive offload is supported
6923a3b42bfSRobert Love  * @does_npiv:             Supports multiple vports
6933a3b42bfSRobert Love  * @npiv_enabled:          Switch/fabric allows NPIV
6943a3b42bfSRobert Love  * @mfs:                   The maximum Fibre Channel payload size
6953a3b42bfSRobert Love  * @max_retry_count:       The maximum retry attempts
6963a3b42bfSRobert Love  * @max_rport_retry_count: The maximum remote port retry attempts
697f90377abSJoe Eykholt  * @rport_priv_size:       Size needed by driver after struct fc_rport_priv
6983a3b42bfSRobert Love  * @lro_xid:               The maximum XID for LRO
6993a3b42bfSRobert Love  * @lso_max:               The maximum large offload send size
7003a3b42bfSRobert Love  * @fcts:                  FC-4 type mask
7013a3b42bfSRobert Love  * @lp_mutex:              Mutex to protect the local port
70270d53b04SJoe Eykholt  * @list:                  Linkage on list of vport peers
7033a3b42bfSRobert Love  * @retry_work:            Handle to local port for delayed retry context
704baf9fdf0SJoe Eykholt  * @prov:		   Pointers available for use by passive FC-4 providers
70570d53b04SJoe Eykholt  * @lport_list:            Linkage on module-wide list of local ports
7063a3b42bfSRobert Love  */
70742e9a92fSRobert Love struct fc_lport {
70842e9a92fSRobert Love 	/* Associations */
70942e9a92fSRobert Love 	struct Scsi_Host	       *host;
71096316099SVasu Dev 	struct list_head	       ema_list;
7113a3b42bfSRobert Love 	struct fc_rport_priv	       *dns_rdata;
712d78c317fSNeerav Parikh 	struct fc_rport_priv	       *ms_rdata;
7133a3b42bfSRobert Love 	struct fc_rport_priv	       *ptp_rdata;
71442e9a92fSRobert Love 	void			       *scsi_priv;
71542e9a92fSRobert Love 	struct fc_disc		       disc;
71642e9a92fSRobert Love 
7173a3b42bfSRobert Love 	/* Virtual port information */
7183a3b42bfSRobert Love 	struct list_head	       vports;
7193a3b42bfSRobert Love 	struct fc_vport		       *vport;
7203a3b42bfSRobert Love 
72142e9a92fSRobert Love 	/* Operational Information */
72242e9a92fSRobert Love 	struct libfc_function_template tt;
723bc0e17f6SVasu Dev 	u8			       link_up;
724bc0e17f6SVasu Dev 	u8			       qfull;
7259a6cf881SHannes Reinecke 	u16			       vlan;
72642e9a92fSRobert Love 	enum fc_lport_state	       state;
72742e9a92fSRobert Love 	unsigned long		       boot_time;
72842e9a92fSRobert Love 	struct fc_host_statistics      host_stats;
7291bd49b48SVasu Dev 	struct fc_stats	__percpu       *stats;
73042e9a92fSRobert Love 	u8			       retry_count;
73142e9a92fSRobert Love 
7323a3b42bfSRobert Love 	/* Fabric information */
7337b2787ecSRobert Love 	u32			       port_id;
7343a3b42bfSRobert Love 	u64			       wwpn;
7353a3b42bfSRobert Love 	u64			       wwnn;
73642e9a92fSRobert Love 	unsigned int		       service_params;
73742e9a92fSRobert Love 	unsigned int		       e_d_tov;
73842e9a92fSRobert Love 	unsigned int		       r_a_tov;
7393a3b42bfSRobert Love 	struct fc_els_rnid_gen	       rnid_gen;
7403a3b42bfSRobert Love 
7413a3b42bfSRobert Love 	/* Capabilities */
7423a3b42bfSRobert Love 	u32			       sg_supp:1;
7433a3b42bfSRobert Love 	u32			       seq_offload:1;
7443a3b42bfSRobert Love 	u32			       crc_offload:1;
7453a3b42bfSRobert Love 	u32			       lro_enabled:1;
7463a3b42bfSRobert Love 	u32			       does_npiv:1;
7473a3b42bfSRobert Love 	u32			       npiv_enabled:1;
7483726f358SJoe Eykholt 	u32			       point_to_multipoint:1;
749d78c317fSNeerav Parikh 	u32			       fdmi_enabled:1;
7503a3b42bfSRobert Love 	u32			       mfs;
75142e9a92fSRobert Love 	u8			       max_retry_count;
752a3666955SAbhijeet Joglekar 	u8			       max_rport_retry_count;
753f90377abSJoe Eykholt 	u16			       rport_priv_size;
75442e9a92fSRobert Love 	u16			       link_speed;
75542e9a92fSRobert Love 	u16			       link_supported_speeds;
7563a3b42bfSRobert Love 	u16			       lro_xid;
7573a3b42bfSRobert Love 	unsigned int		       lso_max;
7583a3b42bfSRobert Love 	struct fc_ns_fts	       fcts;
75942e9a92fSRobert Love 
76042e9a92fSRobert Love 	/* Miscellaneous */
7613a3b42bfSRobert Love 	struct mutex		       lp_mutex;
7623a3b42bfSRobert Love 	struct list_head	       list;
76342e9a92fSRobert Love 	struct delayed_work	       retry_work;
764baf9fdf0SJoe Eykholt 	void			       *prov[FC_FC4_PROV_SIZE];
76570d53b04SJoe Eykholt 	struct list_head	       lport_list;
76642e9a92fSRobert Love };
76742e9a92fSRobert Love 
76896ad8464SJoe Eykholt /**
76996ad8464SJoe Eykholt  * struct fc4_prov - FC-4 provider registration
77096ad8464SJoe Eykholt  * @prli:               Handler for incoming PRLI
77196ad8464SJoe Eykholt  * @prlo:               Handler for session reset
77296ad8464SJoe Eykholt  * @recv:		Handler for incoming request
77396ad8464SJoe Eykholt  * @module:		Pointer to module.  May be NULL.
77496ad8464SJoe Eykholt  */
77596ad8464SJoe Eykholt struct fc4_prov {
77696ad8464SJoe Eykholt 	int (*prli)(struct fc_rport_priv *, u32 spp_len,
77796ad8464SJoe Eykholt 		    const struct fc_els_spp *spp_in,
77896ad8464SJoe Eykholt 		    struct fc_els_spp *spp_out);
77996ad8464SJoe Eykholt 	void (*prlo)(struct fc_rport_priv *);
78096ad8464SJoe Eykholt 	void (*recv)(struct fc_lport *, struct fc_frame *);
78196ad8464SJoe Eykholt 	struct module *module;
78296ad8464SJoe Eykholt };
78396ad8464SJoe Eykholt 
78496ad8464SJoe Eykholt /*
78596ad8464SJoe Eykholt  * Register FC-4 provider with libfc.
78696ad8464SJoe Eykholt  */
78796ad8464SJoe Eykholt int fc_fc4_register_provider(enum fc_fh_type type, struct fc4_prov *);
78896ad8464SJoe Eykholt void fc_fc4_deregister_provider(enum fc_fh_type type, struct fc4_prov *);
78996ad8464SJoe Eykholt 
79034f42a07SRobert Love /*
79142e9a92fSRobert Love  * FC_LPORT HELPER FUNCTIONS
79242e9a92fSRobert Love  *****************************/
7933a3b42bfSRobert Love 
7943a3b42bfSRobert Love /**
7953a3b42bfSRobert Love  * fc_lport_test_ready() - Determine if a local port is in the READY state
7963a3b42bfSRobert Love  * @lport: The local port to test
797*9cef74a9SRandy Dunlap  *
798*9cef74a9SRandy Dunlap  * Returns: %true if local port is in the READY state, %false otherwise
7993a3b42bfSRobert Love  */
fc_lport_test_ready(struct fc_lport * lport)8003a3b42bfSRobert Love static inline int fc_lport_test_ready(struct fc_lport *lport)
80142e9a92fSRobert Love {
8023a3b42bfSRobert Love 	return lport->state == LPORT_ST_READY;
80342e9a92fSRobert Love }
80442e9a92fSRobert Love 
8053a3b42bfSRobert Love /**
8063a3b42bfSRobert Love  * fc_set_wwnn() - Set the World Wide Node Name of a local port
8073a3b42bfSRobert Love  * @lport: The local port whose WWNN is to be set
8083a3b42bfSRobert Love  * @wwnn:  The new WWNN
8093a3b42bfSRobert Love  */
fc_set_wwnn(struct fc_lport * lport,u64 wwnn)8103a3b42bfSRobert Love static inline void fc_set_wwnn(struct fc_lport *lport, u64 wwnn)
81142e9a92fSRobert Love {
8123a3b42bfSRobert Love 	lport->wwnn = wwnn;
81342e9a92fSRobert Love }
81442e9a92fSRobert Love 
8153a3b42bfSRobert Love /**
8163a3b42bfSRobert Love  * fc_set_wwpn() - Set the World Wide Port Name of a local port
8173a3b42bfSRobert Love  * @lport: The local port whose WWPN is to be set
81867d35e70SFam Zheng  * @wwpn:  The new WWPN
8193a3b42bfSRobert Love  */
fc_set_wwpn(struct fc_lport * lport,u64 wwpn)82067d35e70SFam Zheng static inline void fc_set_wwpn(struct fc_lport *lport, u64 wwpn)
82142e9a92fSRobert Love {
82267d35e70SFam Zheng 	lport->wwpn = wwpn;
82342e9a92fSRobert Love }
82442e9a92fSRobert Love 
8253a3b42bfSRobert Love /**
8263a3b42bfSRobert Love  * fc_lport_state_enter() - Change a local port's state
8273a3b42bfSRobert Love  * @lport: The local port whose state is to change
8283a3b42bfSRobert Love  * @state: The new state
8293a3b42bfSRobert Love  */
fc_lport_state_enter(struct fc_lport * lport,enum fc_lport_state state)8303a3b42bfSRobert Love static inline void fc_lport_state_enter(struct fc_lport *lport,
83142e9a92fSRobert Love 					enum fc_lport_state state)
83242e9a92fSRobert Love {
8333a3b42bfSRobert Love 	if (state != lport->state)
8343a3b42bfSRobert Love 		lport->retry_count = 0;
8353a3b42bfSRobert Love 	lport->state = state;
83642e9a92fSRobert Love }
83742e9a92fSRobert Love 
8383a3b42bfSRobert Love /**
8393a3b42bfSRobert Love  * fc_lport_init_stats() - Allocate per-CPU statistics for a local port
8403a3b42bfSRobert Love  * @lport: The local port whose statistics are to be initialized
841*9cef74a9SRandy Dunlap  *
842*9cef74a9SRandy Dunlap  * Returns: %0 on success, %-ENOMEM on failure
8433a3b42bfSRobert Love  */
fc_lport_init_stats(struct fc_lport * lport)8443a3b42bfSRobert Love static inline int fc_lport_init_stats(struct fc_lport *lport)
845582b45bcSRobert Love {
8461bd49b48SVasu Dev 	lport->stats = alloc_percpu(struct fc_stats);
8471bd49b48SVasu Dev 	if (!lport->stats)
848582b45bcSRobert Love 		return -ENOMEM;
849582b45bcSRobert Love 	return 0;
850582b45bcSRobert Love }
851582b45bcSRobert Love 
8523a3b42bfSRobert Love /**
8533a3b42bfSRobert Love  * fc_lport_free_stats() - Free memory for a local port's statistics
8543a3b42bfSRobert Love  * @lport: The local port whose statistics are to be freed
8553a3b42bfSRobert Love  */
fc_lport_free_stats(struct fc_lport * lport)8563a3b42bfSRobert Love static inline void fc_lport_free_stats(struct fc_lport *lport)
857582b45bcSRobert Love {
8581bd49b48SVasu Dev 	free_percpu(lport->stats);
859a0a25da2SVasu Dev }
860a0a25da2SVasu Dev 
861a0a25da2SVasu Dev /**
8623a3b42bfSRobert Love  * lport_priv() - Return the private data from a local port
86340d6b939SZhen Lei  * @lport: The local port whose private data is to be retrieved
864*9cef74a9SRandy Dunlap  *
865*9cef74a9SRandy Dunlap  * Returns: the local port's private data pointer
8663a3b42bfSRobert Love  */
lport_priv(const struct fc_lport * lport)8673a3b42bfSRobert Love static inline void *lport_priv(const struct fc_lport *lport)
8683a3b42bfSRobert Love {
8693a3b42bfSRobert Love 	return (void *)(lport + 1);
8703a3b42bfSRobert Love }
8713a3b42bfSRobert Love 
8723a3b42bfSRobert Love /**
8733a3b42bfSRobert Love  * libfc_host_alloc() - Allocate a Scsi_Host with room for a local port and
8743a3b42bfSRobert Love  *                      LLD private data
8753a3b42bfSRobert Love  * @sht:       The SCSI host template
8763a3b42bfSRobert Love  * @priv_size: Size of private data
877a0a25da2SVasu Dev  *
87886221969SChris Leech  * Returns: libfc lport
879a0a25da2SVasu Dev  */
88086221969SChris Leech static inline struct fc_lport *
libfc_host_alloc(const struct scsi_host_template * sht,int priv_size)881e0d3f2c6SBart Van Assche libfc_host_alloc(const struct scsi_host_template *sht, int priv_size)
882a0a25da2SVasu Dev {
88386221969SChris Leech 	struct fc_lport *lport;
88486221969SChris Leech 	struct Scsi_Host *shost;
88586221969SChris Leech 
88686221969SChris Leech 	shost = scsi_host_alloc(sht, sizeof(*lport) + priv_size);
88786221969SChris Leech 	if (!shost)
88886221969SChris Leech 		return NULL;
88986221969SChris Leech 	lport = shost_priv(shost);
89086221969SChris Leech 	lport->host = shost;
89186221969SChris Leech 	INIT_LIST_HEAD(&lport->ema_list);
892174e1ebfSChris Leech 	INIT_LIST_HEAD(&lport->vports);
89386221969SChris Leech 	return lport;
894a0a25da2SVasu Dev }
89542e9a92fSRobert Love 
89634f42a07SRobert Love /*
8973a3b42bfSRobert Love  * FC_FCP HELPER FUNCTIONS
8983a3b42bfSRobert Love  *****************************/
fc_fcp_is_read(const struct fc_fcp_pkt * fsp)8993a3b42bfSRobert Love static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)
9003a3b42bfSRobert Love {
9013a3b42bfSRobert Love 	if (fsp && fsp->cmd)
9023a3b42bfSRobert Love 		return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE;
9033a3b42bfSRobert Love 	return false;
9043a3b42bfSRobert Love }
9053a3b42bfSRobert Love 
9063a3b42bfSRobert Love /*
90742e9a92fSRobert Love  * LOCAL PORT LAYER
90842e9a92fSRobert Love  *****************************/
9093a3b42bfSRobert Love int fc_lport_init(struct fc_lport *);
9103a3b42bfSRobert Love int fc_lport_destroy(struct fc_lport *);
9113a3b42bfSRobert Love int fc_fabric_logoff(struct fc_lport *);
9123a3b42bfSRobert Love int fc_fabric_login(struct fc_lport *);
9138faecddbSChris Leech void __fc_linkup(struct fc_lport *);
91442e9a92fSRobert Love void fc_linkup(struct fc_lport *);
9158faecddbSChris Leech void __fc_linkdown(struct fc_lport *);
91642e9a92fSRobert Love void fc_linkdown(struct fc_lport *);
9173a3b42bfSRobert Love void fc_vport_setlink(struct fc_lport *);
9183a3b42bfSRobert Love void fc_vports_linkchange(struct fc_lport *);
91942e9a92fSRobert Love int fc_lport_config(struct fc_lport *);
92042e9a92fSRobert Love int fc_lport_reset(struct fc_lport *);
921c5cb444cSHannes Reinecke void fc_lport_recv(struct fc_lport *lport, struct fc_frame *fp);
9223a3b42bfSRobert Love int fc_set_mfs(struct fc_lport *, u32 mfs);
9233a3b42bfSRobert Love struct fc_lport *libfc_vport_create(struct fc_vport *, int privsize);
9243a3b42bfSRobert Love struct fc_lport *fc_vport_id_lookup(struct fc_lport *, u32 port_id);
92575cc8cfcSJohannes Thumshirn int fc_lport_bsg_request(struct bsg_job *);
9263726f358SJoe Eykholt void fc_lport_set_local_id(struct fc_lport *, u32 port_id);
92770d53b04SJoe Eykholt void fc_lport_iterate(void (*func)(struct fc_lport *, void *), void *);
928a51ab396SSteve Ma 
929a51ab396SSteve Ma /*
93042e9a92fSRobert Love  * REMOTE PORT LAYER
93142e9a92fSRobert Love  *****************************/
9323a3b42bfSRobert Love void fc_rport_terminate_io(struct fc_rport *);
933e87b7777SHannes Reinecke struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
934e87b7777SHannes Reinecke 				      u32 port_id);
9352580064bSHannes Reinecke struct fc_rport_priv *fc_rport_create(struct fc_lport *, u32);
936944ef968SHannes Reinecke void fc_rport_destroy(struct kref *kref);
93705d7d3b0SHannes Reinecke int fc_rport_login(struct fc_rport_priv *rdata);
938c96c792aSHannes Reinecke int fc_rport_logoff(struct fc_rport_priv *rdata);
939e76ee65fSHannes Reinecke void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp);
9405922a957SHannes Reinecke void fc_rport_flush_queue(void);
94142e9a92fSRobert Love 
94234f42a07SRobert Love /*
94342e9a92fSRobert Love  * DISCOVERY LAYER
94442e9a92fSRobert Love  *****************************/
9450807619dSRobert Love void fc_disc_init(struct fc_lport *);
9460807619dSRobert Love void fc_disc_config(struct fc_lport *, void *);
94742e9a92fSRobert Love 
fc_disc_lport(struct fc_disc * disc)9480685230cSJoe Eykholt static inline struct fc_lport *fc_disc_lport(struct fc_disc *disc)
9490685230cSJoe Eykholt {
9500685230cSJoe Eykholt 	return container_of(disc, struct fc_lport, disc);
9510685230cSJoe Eykholt }
9520685230cSJoe Eykholt 
95334f42a07SRobert Love /*
9543a3b42bfSRobert Love  * FCP LAYER
95542e9a92fSRobert Love  *****************************/
95642e9a92fSRobert Love int fc_fcp_init(struct fc_lport *);
95742e9a92fSRobert Love void fc_fcp_destroy(struct fc_lport *);
95842e9a92fSRobert Love 
95934f42a07SRobert Love /*
9603a3b42bfSRobert Love  * SCSI INTERACTION LAYER
9613a3b42bfSRobert Love  *****************************/
962f281233dSJeff Garzik int fc_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
9633a3b42bfSRobert Love int fc_eh_abort(struct scsi_cmnd *);
9643a3b42bfSRobert Love int fc_eh_device_reset(struct scsi_cmnd *);
9653a3b42bfSRobert Love int fc_eh_host_reset(struct scsi_cmnd *);
9663a3b42bfSRobert Love int fc_slave_alloc(struct scsi_device *);
9673a3b42bfSRobert Love 
9683a3b42bfSRobert Love /*
96942e9a92fSRobert Love  * ELS/CT interface
97042e9a92fSRobert Love  *****************************/
9713a3b42bfSRobert Love int fc_elsct_init(struct fc_lport *);
9723a3b42bfSRobert Love struct fc_seq *fc_elsct_send(struct fc_lport *, u32 did,
9733a3b42bfSRobert Love 				    struct fc_frame *,
97411b56188SChris Leech 				    unsigned int op,
97511b56188SChris Leech 				    void (*resp)(struct fc_seq *,
9763a3b42bfSRobert Love 						 struct fc_frame *,
97711b56188SChris Leech 						 void *arg),
97811b56188SChris Leech 				    void *arg, u32 timer_msec);
97911b56188SChris Leech void fc_lport_flogi_resp(struct fc_seq *, struct fc_frame *, void *);
98011b56188SChris Leech void fc_lport_logo_resp(struct fc_seq *, struct fc_frame *, void *);
98124f089e2SJoe Eykholt void fc_fill_reply_hdr(struct fc_frame *, const struct fc_frame *,
98224f089e2SJoe Eykholt 		       enum fc_rctl, u32 parm_offset);
98324f089e2SJoe Eykholt void fc_fill_hdr(struct fc_frame *, const struct fc_frame *,
98424f089e2SJoe Eykholt 		 enum fc_rctl, u32 f_ctl, u16 seq_cnt, u32 parm_offset);
98542e9a92fSRobert Love 
98642e9a92fSRobert Love 
98734f42a07SRobert Love /*
98842e9a92fSRobert Love  * EXCHANGE MANAGER LAYER
98942e9a92fSRobert Love  *****************************/
9903a3b42bfSRobert Love int fc_exch_init(struct fc_lport *);
9914e5fae7aSVasu Dev void fc_exch_update_stats(struct fc_lport *lport);
9923afd2d15SHannes Reinecke struct fc_seq *fc_exch_seq_send(struct fc_lport *lport,
9933afd2d15SHannes Reinecke 				struct fc_frame *fp,
9943afd2d15SHannes Reinecke 				void (*resp)(struct fc_seq *,
9953afd2d15SHannes Reinecke 					     struct fc_frame *fp,
9963afd2d15SHannes Reinecke 					     void *arg),
9973afd2d15SHannes Reinecke 				void (*destructor)(struct fc_seq *, void *),
9983afd2d15SHannes Reinecke 				void *arg, u32 timer_msec);
9997ab24dd1SHannes Reinecke void fc_seq_els_rsp_send(struct fc_frame *, enum fc_els_cmd,
10007ab24dd1SHannes Reinecke 			 struct fc_seq_els_data *);
1001c6865b30SHannes Reinecke struct fc_seq *fc_seq_start_next(struct fc_seq *sp);
1002f1d61e6eSHannes Reinecke void fc_seq_set_resp(struct fc_seq *sp,
1003f1d61e6eSHannes Reinecke 		     void (*resp)(struct fc_seq *, struct fc_frame *, void *),
1004f1d61e6eSHannes Reinecke 		     void *arg);
100596d564e2SHannes Reinecke struct fc_seq *fc_seq_assign(struct fc_lport *lport, struct fc_frame *fp);
10069625cc48SHannes Reinecke void fc_seq_release(struct fc_seq *sp);
10073a3b42bfSRobert Love struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *,
10083a3b42bfSRobert Love 					   struct fc_exch_mgr *,
100996316099SVasu Dev 					   bool (*match)(struct fc_frame *));
10103a3b42bfSRobert Love void fc_exch_mgr_del(struct fc_exch_mgr_anchor *);
1011174e1ebfSChris Leech int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst);
10123a3b42bfSRobert Love struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *, enum fc_class class,
10133a3b42bfSRobert Love 				      u16 min_xid, u16 max_xid,
101452ff878cSVasu Dev 				      bool (*match)(struct fc_frame *));
10153a3b42bfSRobert Love void fc_exch_mgr_free(struct fc_lport *);
10163a3b42bfSRobert Love void fc_exch_recv(struct fc_lport *, struct fc_frame *);
10171f6ff364SAbhijeet Joglekar void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);
10180cac937dSHannes Reinecke int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp, struct fc_frame *fp);
10190ebaed17SHannes Reinecke int fc_seq_exch_abort(const struct fc_seq *, unsigned int timer_msec);
1020768c72ccSHannes Reinecke void fc_exch_done(struct fc_seq *sp);
102142e9a92fSRobert Love 
102242e9a92fSRobert Love /*
102342e9a92fSRobert Love  * Functions for fc_functions_template
102442e9a92fSRobert Love  */
10253a3b42bfSRobert Love void fc_get_host_speed(struct Scsi_Host *);
10263a3b42bfSRobert Love void fc_get_host_port_state(struct Scsi_Host *);
10273a3b42bfSRobert Love void fc_set_rport_loss_tmo(struct fc_rport *, u32 timeout);
102842e9a92fSRobert Love struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *);
102942e9a92fSRobert Love 
103042e9a92fSRobert Love #endif /* _LIBFC_H_ */
1031