1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright(c) 2007 Intel Corporation. All rights reserved.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Maintained at www.Open-FCoE.org
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #ifndef _LIBFC_H_
9*4882a593Smuzhiyun #define _LIBFC_H_
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <linux/timer.h>
12*4882a593Smuzhiyun #include <linux/if.h>
13*4882a593Smuzhiyun #include <linux/percpu.h>
14*4882a593Smuzhiyun #include <linux/refcount.h>
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #include <scsi/scsi_transport.h>
17*4882a593Smuzhiyun #include <scsi/scsi_transport_fc.h>
18*4882a593Smuzhiyun #include <scsi/scsi_bsg_fc.h>
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #include <scsi/fc/fc_fcp.h>
21*4882a593Smuzhiyun #include <scsi/fc/fc_ns.h>
22*4882a593Smuzhiyun #include <scsi/fc/fc_ms.h>
23*4882a593Smuzhiyun #include <scsi/fc/fc_els.h>
24*4882a593Smuzhiyun #include <scsi/fc/fc_gs.h>
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #include <scsi/fc_frame.h>
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun #define FC_FC4_PROV_SIZE (FC_TYPE_FCP + 1) /* size of tables */
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun /*
31*4882a593Smuzhiyun * libfc error codes
32*4882a593Smuzhiyun */
33*4882a593Smuzhiyun #define FC_NO_ERR 0 /* no error */
34*4882a593Smuzhiyun #define FC_EX_TIMEOUT 1 /* Exchange timeout */
35*4882a593Smuzhiyun #define FC_EX_CLOSED 2 /* Exchange closed */
36*4882a593Smuzhiyun #define FC_EX_ALLOC_ERR 3 /* Exchange allocation failed */
37*4882a593Smuzhiyun #define FC_EX_XMIT_ERR 4 /* Exchange transmit failed */
38*4882a593Smuzhiyun #define FC_EX_ELS_RJT 5 /* ELS rejected */
39*4882a593Smuzhiyun #define FC_EX_INV_LOGIN 6 /* Login not completed */
40*4882a593Smuzhiyun #define FC_EX_SEQ_ERR 6 /* Exchange sequence error */
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun /**
43*4882a593Smuzhiyun * enum fc_lport_state - Local port states
44*4882a593Smuzhiyun * @LPORT_ST_DISABLED: Disabled
45*4882a593Smuzhiyun * @LPORT_ST_FLOGI: Fabric login (FLOGI) sent
46*4882a593Smuzhiyun * @LPORT_ST_DNS: Waiting for name server remote port to become ready
47*4882a593Smuzhiyun * @LPORT_ST_RPN_ID: Register port name by ID (RPN_ID) sent
48*4882a593Smuzhiyun * @LPORT_ST_RFT_ID: Register Fibre Channel types by ID (RFT_ID) sent
49*4882a593Smuzhiyun * @LPORT_ST_RFF_ID: Register FC-4 Features by ID (RFF_ID) sent
50*4882a593Smuzhiyun * @LPORT_ST_FDMI: Waiting for mgmt server rport to become ready
51*4882a593Smuzhiyun * @LPORT_ST_RHBA:
52*4882a593Smuzhiyun * @LPORT_ST_SCR: State Change Register (SCR) sent
53*4882a593Smuzhiyun * @LPORT_ST_READY: Ready for use
54*4882a593Smuzhiyun * @LPORT_ST_LOGO: Local port logout (LOGO) sent
55*4882a593Smuzhiyun * @LPORT_ST_RESET: Local port reset
56*4882a593Smuzhiyun */
57*4882a593Smuzhiyun enum fc_lport_state {
58*4882a593Smuzhiyun LPORT_ST_DISABLED = 0,
59*4882a593Smuzhiyun LPORT_ST_FLOGI,
60*4882a593Smuzhiyun LPORT_ST_DNS,
61*4882a593Smuzhiyun LPORT_ST_RNN_ID,
62*4882a593Smuzhiyun LPORT_ST_RSNN_NN,
63*4882a593Smuzhiyun LPORT_ST_RSPN_ID,
64*4882a593Smuzhiyun LPORT_ST_RFT_ID,
65*4882a593Smuzhiyun LPORT_ST_RFF_ID,
66*4882a593Smuzhiyun LPORT_ST_FDMI,
67*4882a593Smuzhiyun LPORT_ST_RHBA,
68*4882a593Smuzhiyun LPORT_ST_RPA,
69*4882a593Smuzhiyun LPORT_ST_DHBA,
70*4882a593Smuzhiyun LPORT_ST_DPRT,
71*4882a593Smuzhiyun LPORT_ST_SCR,
72*4882a593Smuzhiyun LPORT_ST_READY,
73*4882a593Smuzhiyun LPORT_ST_LOGO,
74*4882a593Smuzhiyun LPORT_ST_RESET
75*4882a593Smuzhiyun };
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun enum fc_disc_event {
78*4882a593Smuzhiyun DISC_EV_NONE = 0,
79*4882a593Smuzhiyun DISC_EV_SUCCESS,
80*4882a593Smuzhiyun DISC_EV_FAILED
81*4882a593Smuzhiyun };
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun /**
84*4882a593Smuzhiyun * enum fc_rport_state - Remote port states
85*4882a593Smuzhiyun * @RPORT_ST_INIT: Initialized
86*4882a593Smuzhiyun * @RPORT_ST_FLOGI: Waiting for FLOGI completion for point-to-multipoint
87*4882a593Smuzhiyun * @RPORT_ST_PLOGI_WAIT: Waiting for peer to login for point-to-multipoint
88*4882a593Smuzhiyun * @RPORT_ST_PLOGI: Waiting for PLOGI completion
89*4882a593Smuzhiyun * @RPORT_ST_PRLI: Waiting for PRLI completion
90*4882a593Smuzhiyun * @RPORT_ST_RTV: Waiting for RTV completion
91*4882a593Smuzhiyun * @RPORT_ST_READY: Ready for use
92*4882a593Smuzhiyun * @RPORT_ST_ADISC: Discover Address sent
93*4882a593Smuzhiyun * @RPORT_ST_DELETE: Remote port being deleted
94*4882a593Smuzhiyun */
95*4882a593Smuzhiyun enum fc_rport_state {
96*4882a593Smuzhiyun RPORT_ST_INIT,
97*4882a593Smuzhiyun RPORT_ST_FLOGI,
98*4882a593Smuzhiyun RPORT_ST_PLOGI_WAIT,
99*4882a593Smuzhiyun RPORT_ST_PLOGI,
100*4882a593Smuzhiyun RPORT_ST_PRLI,
101*4882a593Smuzhiyun RPORT_ST_RTV,
102*4882a593Smuzhiyun RPORT_ST_READY,
103*4882a593Smuzhiyun RPORT_ST_ADISC,
104*4882a593Smuzhiyun RPORT_ST_DELETE,
105*4882a593Smuzhiyun };
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun /**
108*4882a593Smuzhiyun * struct fc_disc_port - temporary discovery port to hold rport identifiers
109*4882a593Smuzhiyun * @lp: Fibre Channel host port instance
110*4882a593Smuzhiyun * @peers: Node for list management during discovery and RSCN processing
111*4882a593Smuzhiyun * @rport_work: Work struct for starting the rport state machine
112*4882a593Smuzhiyun * @port_id: Port ID of the discovered port
113*4882a593Smuzhiyun */
114*4882a593Smuzhiyun struct fc_disc_port {
115*4882a593Smuzhiyun struct fc_lport *lp;
116*4882a593Smuzhiyun struct list_head peers;
117*4882a593Smuzhiyun struct work_struct rport_work;
118*4882a593Smuzhiyun u32 port_id;
119*4882a593Smuzhiyun };
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun /**
122*4882a593Smuzhiyun * enum fc_rport_event - Remote port events
123*4882a593Smuzhiyun * @RPORT_EV_NONE: No event
124*4882a593Smuzhiyun * @RPORT_EV_READY: Remote port is ready for use
125*4882a593Smuzhiyun * @RPORT_EV_FAILED: State machine failed, remote port is not ready
126*4882a593Smuzhiyun * @RPORT_EV_STOP: Remote port has been stopped
127*4882a593Smuzhiyun * @RPORT_EV_LOGO: Remote port logout (LOGO) sent
128*4882a593Smuzhiyun */
129*4882a593Smuzhiyun enum fc_rport_event {
130*4882a593Smuzhiyun RPORT_EV_NONE = 0,
131*4882a593Smuzhiyun RPORT_EV_READY,
132*4882a593Smuzhiyun RPORT_EV_FAILED,
133*4882a593Smuzhiyun RPORT_EV_STOP,
134*4882a593Smuzhiyun RPORT_EV_LOGO
135*4882a593Smuzhiyun };
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun struct fc_rport_priv;
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun /**
140*4882a593Smuzhiyun * struct fc_rport_operations - Operations for a remote port
141*4882a593Smuzhiyun * @event_callback: Function to be called for remote port events
142*4882a593Smuzhiyun */
143*4882a593Smuzhiyun struct fc_rport_operations {
144*4882a593Smuzhiyun void (*event_callback)(struct fc_lport *, struct fc_rport_priv *,
145*4882a593Smuzhiyun enum fc_rport_event);
146*4882a593Smuzhiyun };
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun /**
149*4882a593Smuzhiyun * struct fc_rport_libfc_priv - libfc internal information about a remote port
150*4882a593Smuzhiyun * @local_port: The associated local port
151*4882a593Smuzhiyun * @rp_state: Indicates READY for I/O or DELETE when blocked
152*4882a593Smuzhiyun * @flags: REC and RETRY supported flags
153*4882a593Smuzhiyun * @e_d_tov: Error detect timeout value (in msec)
154*4882a593Smuzhiyun * @r_a_tov: Resource allocation timeout value (in msec)
155*4882a593Smuzhiyun */
156*4882a593Smuzhiyun struct fc_rport_libfc_priv {
157*4882a593Smuzhiyun struct fc_lport *local_port;
158*4882a593Smuzhiyun enum fc_rport_state rp_state;
159*4882a593Smuzhiyun u16 flags;
160*4882a593Smuzhiyun #define FC_RP_FLAGS_REC_SUPPORTED (1 << 0)
161*4882a593Smuzhiyun #define FC_RP_FLAGS_RETRY (1 << 1)
162*4882a593Smuzhiyun #define FC_RP_STARTED (1 << 2)
163*4882a593Smuzhiyun #define FC_RP_FLAGS_CONF_REQ (1 << 3)
164*4882a593Smuzhiyun unsigned int e_d_tov;
165*4882a593Smuzhiyun unsigned int r_a_tov;
166*4882a593Smuzhiyun };
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun /**
169*4882a593Smuzhiyun * struct fc_rport_priv - libfc remote port and discovery info
170*4882a593Smuzhiyun * @local_port: The associated local port
171*4882a593Smuzhiyun * @rport: The FC transport remote port
172*4882a593Smuzhiyun * @kref: Reference counter
173*4882a593Smuzhiyun * @rp_state: Enumeration that tracks progress of PLOGI, PRLI,
174*4882a593Smuzhiyun * and RTV exchanges
175*4882a593Smuzhiyun * @ids: The remote port identifiers and roles
176*4882a593Smuzhiyun * @flags: STARTED, REC and RETRY_SUPPORTED flags
177*4882a593Smuzhiyun * @max_seq: Maximum number of concurrent sequences
178*4882a593Smuzhiyun * @disc_id: The discovery identifier
179*4882a593Smuzhiyun * @maxframe_size: The maximum frame size
180*4882a593Smuzhiyun * @retries: The retry count for the current state
181*4882a593Smuzhiyun * @major_retries: The retry count for the entire PLOGI/PRLI state machine
182*4882a593Smuzhiyun * @e_d_tov: Error detect timeout value (in msec)
183*4882a593Smuzhiyun * @r_a_tov: Resource allocation timeout value (in msec)
184*4882a593Smuzhiyun * @rp_mutex: The mutex that protects the remote port
185*4882a593Smuzhiyun * @retry_work: Handle for retries
186*4882a593Smuzhiyun * @event_callback: Callback when READY, FAILED or LOGO states complete
187*4882a593Smuzhiyun * @prli_count: Count of open PRLI sessions in providers
188*4882a593Smuzhiyun * @rcu: Structure used for freeing in an RCU-safe manner
189*4882a593Smuzhiyun */
190*4882a593Smuzhiyun struct fc_rport_priv {
191*4882a593Smuzhiyun struct fc_lport *local_port;
192*4882a593Smuzhiyun struct fc_rport *rport;
193*4882a593Smuzhiyun struct kref kref;
194*4882a593Smuzhiyun enum fc_rport_state rp_state;
195*4882a593Smuzhiyun struct fc_rport_identifiers ids;
196*4882a593Smuzhiyun u16 flags;
197*4882a593Smuzhiyun u16 max_seq;
198*4882a593Smuzhiyun u16 disc_id;
199*4882a593Smuzhiyun u16 maxframe_size;
200*4882a593Smuzhiyun unsigned int retries;
201*4882a593Smuzhiyun unsigned int major_retries;
202*4882a593Smuzhiyun unsigned int e_d_tov;
203*4882a593Smuzhiyun unsigned int r_a_tov;
204*4882a593Smuzhiyun struct mutex rp_mutex;
205*4882a593Smuzhiyun struct delayed_work retry_work;
206*4882a593Smuzhiyun enum fc_rport_event event;
207*4882a593Smuzhiyun struct fc_rport_operations *ops;
208*4882a593Smuzhiyun struct list_head peers;
209*4882a593Smuzhiyun struct work_struct event_work;
210*4882a593Smuzhiyun u32 supported_classes;
211*4882a593Smuzhiyun u16 prli_count;
212*4882a593Smuzhiyun struct rcu_head rcu;
213*4882a593Smuzhiyun u16 sp_features;
214*4882a593Smuzhiyun u8 spp_type;
215*4882a593Smuzhiyun void (*lld_event_callback)(struct fc_lport *,
216*4882a593Smuzhiyun struct fc_rport_priv *,
217*4882a593Smuzhiyun enum fc_rport_event);
218*4882a593Smuzhiyun };
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun /**
221*4882a593Smuzhiyun * struct fc_stats - fc stats structure
222*4882a593Smuzhiyun * @SecondsSinceLastReset: Seconds since the last reset
223*4882a593Smuzhiyun * @TxFrames: Number of transmitted frames
224*4882a593Smuzhiyun * @TxWords: Number of transmitted words
225*4882a593Smuzhiyun * @RxFrames: Number of received frames
226*4882a593Smuzhiyun * @RxWords: Number of received words
227*4882a593Smuzhiyun * @ErrorFrames: Number of received error frames
228*4882a593Smuzhiyun * @DumpedFrames: Number of dumped frames
229*4882a593Smuzhiyun * @FcpPktAllocFails: Number of fcp packet allocation failures
230*4882a593Smuzhiyun * @FcpPktAborts: Number of fcp packet aborts
231*4882a593Smuzhiyun * @FcpFrameAllocFails: Number of fcp frame allocation failures
232*4882a593Smuzhiyun * @LinkFailureCount: Number of link failures
233*4882a593Smuzhiyun * @LossOfSignalCount: Number for signal losses
234*4882a593Smuzhiyun * @InvalidTxWordCount: Number of invalid transmitted words
235*4882a593Smuzhiyun * @InvalidCRCCount: Number of invalid CRCs
236*4882a593Smuzhiyun * @InputRequests: Number of input requests
237*4882a593Smuzhiyun * @OutputRequests: Number of output requests
238*4882a593Smuzhiyun * @ControlRequests: Number of control requests
239*4882a593Smuzhiyun * @InputBytes: Number of received bytes
240*4882a593Smuzhiyun * @OutputBytes: Number of transmitted bytes
241*4882a593Smuzhiyun * @VLinkFailureCount: Number of virtual link failures
242*4882a593Smuzhiyun * @MissDiscAdvCount: Number of missing FIP discovery advertisement
243*4882a593Smuzhiyun */
244*4882a593Smuzhiyun struct fc_stats {
245*4882a593Smuzhiyun u64 SecondsSinceLastReset;
246*4882a593Smuzhiyun u64 TxFrames;
247*4882a593Smuzhiyun u64 TxWords;
248*4882a593Smuzhiyun u64 RxFrames;
249*4882a593Smuzhiyun u64 RxWords;
250*4882a593Smuzhiyun u64 ErrorFrames;
251*4882a593Smuzhiyun u64 DumpedFrames;
252*4882a593Smuzhiyun u64 FcpPktAllocFails;
253*4882a593Smuzhiyun u64 FcpPktAborts;
254*4882a593Smuzhiyun u64 FcpFrameAllocFails;
255*4882a593Smuzhiyun u64 LinkFailureCount;
256*4882a593Smuzhiyun u64 LossOfSignalCount;
257*4882a593Smuzhiyun u64 InvalidTxWordCount;
258*4882a593Smuzhiyun u64 InvalidCRCCount;
259*4882a593Smuzhiyun u64 InputRequests;
260*4882a593Smuzhiyun u64 OutputRequests;
261*4882a593Smuzhiyun u64 ControlRequests;
262*4882a593Smuzhiyun u64 InputBytes;
263*4882a593Smuzhiyun u64 OutputBytes;
264*4882a593Smuzhiyun u64 VLinkFailureCount;
265*4882a593Smuzhiyun u64 MissDiscAdvCount;
266*4882a593Smuzhiyun };
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun /**
269*4882a593Smuzhiyun * struct fc_seq_els_data - ELS data used for passing ELS specific responses
270*4882a593Smuzhiyun * @reason: The reason for rejection
271*4882a593Smuzhiyun * @explan: The explanation of the rejection
272*4882a593Smuzhiyun *
273*4882a593Smuzhiyun * Mainly used by the exchange manager layer.
274*4882a593Smuzhiyun */
275*4882a593Smuzhiyun struct fc_seq_els_data {
276*4882a593Smuzhiyun enum fc_els_rjt_reason reason;
277*4882a593Smuzhiyun enum fc_els_rjt_explan explan;
278*4882a593Smuzhiyun };
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun /**
281*4882a593Smuzhiyun * struct fc_fcp_pkt - FCP request structure (one for each scsi_cmnd request)
282*4882a593Smuzhiyun * @lp: The associated local port
283*4882a593Smuzhiyun * @state: The state of the I/O
284*4882a593Smuzhiyun * @ref_cnt: Reference count
285*4882a593Smuzhiyun * @scsi_pkt_lock: Lock to protect the SCSI packet (must be taken before the
286*4882a593Smuzhiyun * host_lock if both are to be held at the same time)
287*4882a593Smuzhiyun * @cmd: The SCSI command (set and clear with the host_lock held)
288*4882a593Smuzhiyun * @list: Tracks queued commands (accessed with the host_lock held)
289*4882a593Smuzhiyun * @timer: The command timer
290*4882a593Smuzhiyun * @tm_done: Completion indicator
291*4882a593Smuzhiyun * @wait_for_comp: Indicator to wait for completion of the I/O (in jiffies)
292*4882a593Smuzhiyun * @data_len: The length of the data
293*4882a593Smuzhiyun * @cdb_cmd: The CDB command
294*4882a593Smuzhiyun * @xfer_len: The transfer length
295*4882a593Smuzhiyun * @xfer_ddp: Indicates if this transfer used DDP (XID of the exchange
296*4882a593Smuzhiyun * will be set here if DDP was setup)
297*4882a593Smuzhiyun * @xfer_contig_end: The offset into the buffer if the buffer is contiguous
298*4882a593Smuzhiyun * (Tx and Rx)
299*4882a593Smuzhiyun * @max_payload: The maximum payload size (in bytes)
300*4882a593Smuzhiyun * @io_status: SCSI result (upper 24 bits)
301*4882a593Smuzhiyun * @cdb_status: CDB status
302*4882a593Smuzhiyun * @status_code: FCP I/O status
303*4882a593Smuzhiyun * @scsi_comp_flags: Completion flags (bit 3 Underrun bit 2: overrun)
304*4882a593Smuzhiyun * @req_flags: Request flags (bit 0: read bit:1 write)
305*4882a593Smuzhiyun * @scsi_resid: SCSI residule length
306*4882a593Smuzhiyun * @rport: The remote port that the SCSI command is targeted at
307*4882a593Smuzhiyun * @seq_ptr: The sequence that will carry the SCSI command
308*4882a593Smuzhiyun * @recov_retry: Number of recovery retries
309*4882a593Smuzhiyun * @recov_seq: The sequence for REC or SRR
310*4882a593Smuzhiyun */
311*4882a593Smuzhiyun struct fc_fcp_pkt {
312*4882a593Smuzhiyun spinlock_t scsi_pkt_lock;
313*4882a593Smuzhiyun refcount_t ref_cnt;
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun /* SCSI command and data transfer information */
316*4882a593Smuzhiyun u32 data_len;
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun /* SCSI I/O related information */
319*4882a593Smuzhiyun struct scsi_cmnd *cmd;
320*4882a593Smuzhiyun struct list_head list;
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun /* Housekeeping information */
323*4882a593Smuzhiyun struct fc_lport *lp;
324*4882a593Smuzhiyun u8 state;
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun /* SCSI/FCP return status */
327*4882a593Smuzhiyun u8 cdb_status;
328*4882a593Smuzhiyun u8 status_code;
329*4882a593Smuzhiyun u8 scsi_comp_flags;
330*4882a593Smuzhiyun u32 io_status;
331*4882a593Smuzhiyun u32 req_flags;
332*4882a593Smuzhiyun u32 scsi_resid;
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun /* Transport related veriables */
335*4882a593Smuzhiyun size_t xfer_len;
336*4882a593Smuzhiyun struct fcp_cmnd cdb_cmd;
337*4882a593Smuzhiyun u32 xfer_contig_end;
338*4882a593Smuzhiyun u16 max_payload;
339*4882a593Smuzhiyun u16 xfer_ddp;
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun /* Associated structures */
342*4882a593Smuzhiyun struct fc_rport *rport;
343*4882a593Smuzhiyun struct fc_seq *seq_ptr;
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun /* Timeout/error related information */
346*4882a593Smuzhiyun struct timer_list timer;
347*4882a593Smuzhiyun int wait_for_comp;
348*4882a593Smuzhiyun int timer_delay;
349*4882a593Smuzhiyun u32 recov_retry;
350*4882a593Smuzhiyun struct fc_seq *recov_seq;
351*4882a593Smuzhiyun struct completion tm_done;
352*4882a593Smuzhiyun } ____cacheline_aligned_in_smp;
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun /*
355*4882a593Smuzhiyun * Structure and function definitions for managing Fibre Channel Exchanges
356*4882a593Smuzhiyun * and Sequences
357*4882a593Smuzhiyun *
358*4882a593Smuzhiyun * fc_exch holds state for one exchange and links to its active sequence.
359*4882a593Smuzhiyun *
360*4882a593Smuzhiyun * fc_seq holds the state for an individual sequence.
361*4882a593Smuzhiyun */
362*4882a593Smuzhiyun
363*4882a593Smuzhiyun struct fc_exch_mgr;
364*4882a593Smuzhiyun struct fc_exch_mgr_anchor;
365*4882a593Smuzhiyun extern u16 fc_cpu_mask; /* cpu mask for possible cpus */
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun /**
368*4882a593Smuzhiyun * struct fc_seq - FC sequence
369*4882a593Smuzhiyun * @id: The sequence ID
370*4882a593Smuzhiyun * @ssb_stat: Status flags for the sequence status block (SSB)
371*4882a593Smuzhiyun * @cnt: Number of frames sent so far
372*4882a593Smuzhiyun * @rec_data: FC-4 value for REC
373*4882a593Smuzhiyun */
374*4882a593Smuzhiyun struct fc_seq {
375*4882a593Smuzhiyun u8 id;
376*4882a593Smuzhiyun u16 ssb_stat;
377*4882a593Smuzhiyun u16 cnt;
378*4882a593Smuzhiyun u32 rec_data;
379*4882a593Smuzhiyun };
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun #define FC_EX_DONE (1 << 0) /* ep is completed */
382*4882a593Smuzhiyun #define FC_EX_RST_CLEANUP (1 << 1) /* reset is forcing completion */
383*4882a593Smuzhiyun #define FC_EX_QUARANTINE (1 << 2) /* exch is quarantined */
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun /**
386*4882a593Smuzhiyun * struct fc_exch - Fibre Channel Exchange
387*4882a593Smuzhiyun * @em: Exchange manager
388*4882a593Smuzhiyun * @pool: Exchange pool
389*4882a593Smuzhiyun * @state: The exchange's state
390*4882a593Smuzhiyun * @xid: The exchange ID
391*4882a593Smuzhiyun * @ex_list: Handle used by the EM to track free exchanges
392*4882a593Smuzhiyun * @ex_lock: Lock that protects the exchange
393*4882a593Smuzhiyun * @ex_refcnt: Reference count
394*4882a593Smuzhiyun * @timeout_work: Handle for timeout handler
395*4882a593Smuzhiyun * @lp: The local port that this exchange is on
396*4882a593Smuzhiyun * @oxid: Originator's exchange ID
397*4882a593Smuzhiyun * @rxid: Responder's exchange ID
398*4882a593Smuzhiyun * @oid: Originator's FCID
399*4882a593Smuzhiyun * @sid: Source FCID
400*4882a593Smuzhiyun * @did: Destination FCID
401*4882a593Smuzhiyun * @esb_stat: ESB exchange status
402*4882a593Smuzhiyun * @r_a_tov: Resouce allocation time out value (in msecs)
403*4882a593Smuzhiyun * @seq_id: The next sequence ID to use
404*4882a593Smuzhiyun * @encaps: encapsulation information for lower-level driver
405*4882a593Smuzhiyun * @f_ctl: F_CTL flags for the sequence
406*4882a593Smuzhiyun * @fh_type: The frame type
407*4882a593Smuzhiyun * @class: The class of service
408*4882a593Smuzhiyun * @seq: The sequence in use on this exchange
409*4882a593Smuzhiyun * @resp_active: Number of tasks that are concurrently executing @resp().
410*4882a593Smuzhiyun * @resp_task: If @resp_active > 0, either the task executing @resp(), the
411*4882a593Smuzhiyun * task that has been interrupted to execute the soft-IRQ
412*4882a593Smuzhiyun * executing @resp() or NULL if more than one task is executing
413*4882a593Smuzhiyun * @resp concurrently.
414*4882a593Smuzhiyun * @resp_wq: Waitqueue for the tasks waiting on @resp_active.
415*4882a593Smuzhiyun * @resp: Callback for responses on this exchange
416*4882a593Smuzhiyun * @destructor: Called when destroying the exchange
417*4882a593Smuzhiyun * @arg: Passed as a void pointer to the resp() callback
418*4882a593Smuzhiyun *
419*4882a593Smuzhiyun * Locking notes: The ex_lock protects following items:
420*4882a593Smuzhiyun * state, esb_stat, f_ctl, seq.ssb_stat
421*4882a593Smuzhiyun * seq_id
422*4882a593Smuzhiyun * sequence allocation
423*4882a593Smuzhiyun */
424*4882a593Smuzhiyun struct fc_exch {
425*4882a593Smuzhiyun spinlock_t ex_lock;
426*4882a593Smuzhiyun atomic_t ex_refcnt;
427*4882a593Smuzhiyun enum fc_class class;
428*4882a593Smuzhiyun struct fc_exch_mgr *em;
429*4882a593Smuzhiyun struct fc_exch_pool *pool;
430*4882a593Smuzhiyun struct list_head ex_list;
431*4882a593Smuzhiyun struct fc_lport *lp;
432*4882a593Smuzhiyun u32 esb_stat;
433*4882a593Smuzhiyun u8 state;
434*4882a593Smuzhiyun u8 fh_type;
435*4882a593Smuzhiyun u8 seq_id;
436*4882a593Smuzhiyun u8 encaps;
437*4882a593Smuzhiyun u16 xid;
438*4882a593Smuzhiyun u16 oxid;
439*4882a593Smuzhiyun u16 rxid;
440*4882a593Smuzhiyun u32 oid;
441*4882a593Smuzhiyun u32 sid;
442*4882a593Smuzhiyun u32 did;
443*4882a593Smuzhiyun u32 r_a_tov;
444*4882a593Smuzhiyun u32 f_ctl;
445*4882a593Smuzhiyun struct fc_seq seq;
446*4882a593Smuzhiyun int resp_active;
447*4882a593Smuzhiyun struct task_struct *resp_task;
448*4882a593Smuzhiyun wait_queue_head_t resp_wq;
449*4882a593Smuzhiyun void (*resp)(struct fc_seq *, struct fc_frame *, void *);
450*4882a593Smuzhiyun void *arg;
451*4882a593Smuzhiyun void (*destructor)(struct fc_seq *, void *);
452*4882a593Smuzhiyun struct delayed_work timeout_work;
453*4882a593Smuzhiyun } ____cacheline_aligned_in_smp;
454*4882a593Smuzhiyun #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun struct libfc_function_template {
458*4882a593Smuzhiyun /*
459*4882a593Smuzhiyun * Interface to send a FC frame
460*4882a593Smuzhiyun *
461*4882a593Smuzhiyun * STATUS: REQUIRED
462*4882a593Smuzhiyun */
463*4882a593Smuzhiyun int (*frame_send)(struct fc_lport *, struct fc_frame *);
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun /*
466*4882a593Smuzhiyun * Interface to send ELS/CT frames
467*4882a593Smuzhiyun *
468*4882a593Smuzhiyun * STATUS: OPTIONAL
469*4882a593Smuzhiyun */
470*4882a593Smuzhiyun struct fc_seq *(*elsct_send)(struct fc_lport *, u32 did,
471*4882a593Smuzhiyun struct fc_frame *, unsigned int op,
472*4882a593Smuzhiyun void (*resp)(struct fc_seq *,
473*4882a593Smuzhiyun struct fc_frame *, void *arg),
474*4882a593Smuzhiyun void *arg, u32 timer_msec);
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun /*
477*4882a593Smuzhiyun * Sets up the DDP context for a given exchange id on the given
478*4882a593Smuzhiyun * scatterlist if LLD supports DDP for large receive.
479*4882a593Smuzhiyun *
480*4882a593Smuzhiyun * STATUS: OPTIONAL
481*4882a593Smuzhiyun */
482*4882a593Smuzhiyun int (*ddp_setup)(struct fc_lport *, u16, struct scatterlist *,
483*4882a593Smuzhiyun unsigned int);
484*4882a593Smuzhiyun /*
485*4882a593Smuzhiyun * Completes the DDP transfer and returns the length of data DDPed
486*4882a593Smuzhiyun * for the given exchange id.
487*4882a593Smuzhiyun *
488*4882a593Smuzhiyun * STATUS: OPTIONAL
489*4882a593Smuzhiyun */
490*4882a593Smuzhiyun int (*ddp_done)(struct fc_lport *, u16);
491*4882a593Smuzhiyun /*
492*4882a593Smuzhiyun * Sets up the DDP context for a given exchange id on the given
493*4882a593Smuzhiyun * scatterlist if LLD supports DDP for target.
494*4882a593Smuzhiyun *
495*4882a593Smuzhiyun * STATUS: OPTIONAL
496*4882a593Smuzhiyun */
497*4882a593Smuzhiyun int (*ddp_target)(struct fc_lport *, u16, struct scatterlist *,
498*4882a593Smuzhiyun unsigned int);
499*4882a593Smuzhiyun /*
500*4882a593Smuzhiyun * Allow LLD to fill its own Link Error Status Block
501*4882a593Smuzhiyun *
502*4882a593Smuzhiyun * STATUS: OPTIONAL
503*4882a593Smuzhiyun */
504*4882a593Smuzhiyun void (*get_lesb)(struct fc_lport *, struct fc_els_lesb *lesb);
505*4882a593Smuzhiyun
506*4882a593Smuzhiyun /*
507*4882a593Smuzhiyun * Reset an exchange manager, completing all sequences and exchanges.
508*4882a593Smuzhiyun * If s_id is non-zero, reset only exchanges originating from that FID.
509*4882a593Smuzhiyun * If d_id is non-zero, reset only exchanges sending to that FID.
510*4882a593Smuzhiyun *
511*4882a593Smuzhiyun * STATUS: OPTIONAL
512*4882a593Smuzhiyun */
513*4882a593Smuzhiyun void (*exch_mgr_reset)(struct fc_lport *, u32 s_id, u32 d_id);
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun /*
516*4882a593Smuzhiyun * Set the local port FC_ID.
517*4882a593Smuzhiyun *
518*4882a593Smuzhiyun * This may be provided by the LLD to allow it to be
519*4882a593Smuzhiyun * notified when the local port is assigned a FC-ID.
520*4882a593Smuzhiyun *
521*4882a593Smuzhiyun * The frame, if non-NULL, is the incoming frame with the
522*4882a593Smuzhiyun * FLOGI LS_ACC or FLOGI, and may contain the granted MAC
523*4882a593Smuzhiyun * address for the LLD. The frame pointer may be NULL if
524*4882a593Smuzhiyun * no MAC is associated with this assignment (LOGO or PLOGI).
525*4882a593Smuzhiyun *
526*4882a593Smuzhiyun * If FC_ID is non-zero, r_a_tov and e_d_tov must be valid.
527*4882a593Smuzhiyun *
528*4882a593Smuzhiyun * Note: this is called with the local port mutex held.
529*4882a593Smuzhiyun *
530*4882a593Smuzhiyun * STATUS: OPTIONAL
531*4882a593Smuzhiyun */
532*4882a593Smuzhiyun void (*lport_set_port_id)(struct fc_lport *, u32 port_id,
533*4882a593Smuzhiyun struct fc_frame *);
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun /*
536*4882a593Smuzhiyun * Callback routine after the remote port is logged in
537*4882a593Smuzhiyun *
538*4882a593Smuzhiyun * STATUS: OPTIONAL
539*4882a593Smuzhiyun */
540*4882a593Smuzhiyun void (*rport_event_callback)(struct fc_lport *,
541*4882a593Smuzhiyun struct fc_rport_priv *,
542*4882a593Smuzhiyun enum fc_rport_event);
543*4882a593Smuzhiyun
544*4882a593Smuzhiyun /*
545*4882a593Smuzhiyun * Send a fcp cmd from fsp pkt.
546*4882a593Smuzhiyun * Called with the SCSI host lock unlocked and irqs disabled.
547*4882a593Smuzhiyun *
548*4882a593Smuzhiyun * The resp handler is called when FCP_RSP received.
549*4882a593Smuzhiyun *
550*4882a593Smuzhiyun * STATUS: OPTIONAL
551*4882a593Smuzhiyun */
552*4882a593Smuzhiyun int (*fcp_cmd_send)(struct fc_lport *, struct fc_fcp_pkt *,
553*4882a593Smuzhiyun void (*resp)(struct fc_seq *, struct fc_frame *,
554*4882a593Smuzhiyun void *));
555*4882a593Smuzhiyun
556*4882a593Smuzhiyun /*
557*4882a593Smuzhiyun * Cleanup the FCP layer, used during link down and reset
558*4882a593Smuzhiyun *
559*4882a593Smuzhiyun * STATUS: OPTIONAL
560*4882a593Smuzhiyun */
561*4882a593Smuzhiyun void (*fcp_cleanup)(struct fc_lport *);
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun /*
564*4882a593Smuzhiyun * Abort all I/O on a local port
565*4882a593Smuzhiyun *
566*4882a593Smuzhiyun * STATUS: OPTIONAL
567*4882a593Smuzhiyun */
568*4882a593Smuzhiyun void (*fcp_abort_io)(struct fc_lport *);
569*4882a593Smuzhiyun
570*4882a593Smuzhiyun /*
571*4882a593Smuzhiyun * Receive a request for the discovery layer.
572*4882a593Smuzhiyun *
573*4882a593Smuzhiyun * STATUS: OPTIONAL
574*4882a593Smuzhiyun */
575*4882a593Smuzhiyun void (*disc_recv_req)(struct fc_lport *, struct fc_frame *);
576*4882a593Smuzhiyun
577*4882a593Smuzhiyun /*
578*4882a593Smuzhiyun * Start discovery for a local port.
579*4882a593Smuzhiyun *
580*4882a593Smuzhiyun * STATUS: OPTIONAL
581*4882a593Smuzhiyun */
582*4882a593Smuzhiyun void (*disc_start)(void (*disc_callback)(struct fc_lport *,
583*4882a593Smuzhiyun enum fc_disc_event),
584*4882a593Smuzhiyun struct fc_lport *);
585*4882a593Smuzhiyun
586*4882a593Smuzhiyun /*
587*4882a593Smuzhiyun * Stop discovery for a given lport. This will remove
588*4882a593Smuzhiyun * all discovered rports
589*4882a593Smuzhiyun *
590*4882a593Smuzhiyun * STATUS: OPTIONAL
591*4882a593Smuzhiyun */
592*4882a593Smuzhiyun void (*disc_stop) (struct fc_lport *);
593*4882a593Smuzhiyun
594*4882a593Smuzhiyun /*
595*4882a593Smuzhiyun * Stop discovery for a given lport. This will block
596*4882a593Smuzhiyun * until all discovered rports are deleted from the
597*4882a593Smuzhiyun * FC transport class
598*4882a593Smuzhiyun *
599*4882a593Smuzhiyun * STATUS: OPTIONAL
600*4882a593Smuzhiyun */
601*4882a593Smuzhiyun void (*disc_stop_final) (struct fc_lport *);
602*4882a593Smuzhiyun };
603*4882a593Smuzhiyun
604*4882a593Smuzhiyun /**
605*4882a593Smuzhiyun * struct fc_disc - Discovery context
606*4882a593Smuzhiyun * @retry_count: Number of retries
607*4882a593Smuzhiyun * @pending: 1 if discovery is pending, 0 if not
608*4882a593Smuzhiyun * @requested: 1 if discovery has been requested, 0 if not
609*4882a593Smuzhiyun * @seq_count: Number of sequences used for discovery
610*4882a593Smuzhiyun * @buf_len: Length of the discovery buffer
611*4882a593Smuzhiyun * @disc_id: Discovery ID
612*4882a593Smuzhiyun * @rports: List of discovered remote ports
613*4882a593Smuzhiyun * @priv: Private pointer for use by discovery code
614*4882a593Smuzhiyun * @disc_mutex: Mutex that protects the discovery context
615*4882a593Smuzhiyun * @partial_buf: Partial name buffer (if names are returned
616*4882a593Smuzhiyun * in multiple frames)
617*4882a593Smuzhiyun * @disc_work: handle for delayed work context
618*4882a593Smuzhiyun * @disc_callback: Callback routine called when discovery completes
619*4882a593Smuzhiyun */
620*4882a593Smuzhiyun struct fc_disc {
621*4882a593Smuzhiyun unsigned char retry_count;
622*4882a593Smuzhiyun unsigned char pending;
623*4882a593Smuzhiyun unsigned char requested;
624*4882a593Smuzhiyun unsigned short seq_count;
625*4882a593Smuzhiyun unsigned char buf_len;
626*4882a593Smuzhiyun u16 disc_id;
627*4882a593Smuzhiyun
628*4882a593Smuzhiyun struct list_head rports;
629*4882a593Smuzhiyun void *priv;
630*4882a593Smuzhiyun struct mutex disc_mutex;
631*4882a593Smuzhiyun struct fc_gpn_ft_resp partial_buf;
632*4882a593Smuzhiyun struct delayed_work disc_work;
633*4882a593Smuzhiyun
634*4882a593Smuzhiyun void (*disc_callback)(struct fc_lport *,
635*4882a593Smuzhiyun enum fc_disc_event);
636*4882a593Smuzhiyun };
637*4882a593Smuzhiyun
638*4882a593Smuzhiyun /*
639*4882a593Smuzhiyun * Local port notifier and events.
640*4882a593Smuzhiyun */
641*4882a593Smuzhiyun extern struct blocking_notifier_head fc_lport_notifier_head;
642*4882a593Smuzhiyun enum fc_lport_event {
643*4882a593Smuzhiyun FC_LPORT_EV_ADD,
644*4882a593Smuzhiyun FC_LPORT_EV_DEL,
645*4882a593Smuzhiyun };
646*4882a593Smuzhiyun
647*4882a593Smuzhiyun /**
648*4882a593Smuzhiyun * struct fc_lport - Local port
649*4882a593Smuzhiyun * @host: The SCSI host associated with a local port
650*4882a593Smuzhiyun * @ema_list: Exchange manager anchor list
651*4882a593Smuzhiyun * @dns_rdata: The directory server remote port
652*4882a593Smuzhiyun * @ms_rdata: The management server remote port
653*4882a593Smuzhiyun * @ptp_rdata: Point to point remote port
654*4882a593Smuzhiyun * @scsi_priv: FCP layer internal data
655*4882a593Smuzhiyun * @disc: Discovery context
656*4882a593Smuzhiyun * @vports: Child vports if N_Port
657*4882a593Smuzhiyun * @vport: Parent vport if VN_Port
658*4882a593Smuzhiyun * @tt: Libfc function template
659*4882a593Smuzhiyun * @link_up: Link state (1 = link up, 0 = link down)
660*4882a593Smuzhiyun * @qfull: Queue state (1 queue is full, 0 queue is not full)
661*4882a593Smuzhiyun * @state: Identifies the state
662*4882a593Smuzhiyun * @boot_time: Timestamp indicating when the local port came online
663*4882a593Smuzhiyun * @host_stats: SCSI host statistics
664*4882a593Smuzhiyun * @stats: FC local port stats (TODO separate libfc LLD stats)
665*4882a593Smuzhiyun * @retry_count: Number of retries in the current state
666*4882a593Smuzhiyun * @port_id: FC Port ID
667*4882a593Smuzhiyun * @wwpn: World Wide Port Name
668*4882a593Smuzhiyun * @wwnn: World Wide Node Name
669*4882a593Smuzhiyun * @service_params: Common service parameters
670*4882a593Smuzhiyun * @e_d_tov: Error detection timeout value
671*4882a593Smuzhiyun * @r_a_tov: Resouce allocation timeout value
672*4882a593Smuzhiyun * @rnid_gen: RNID information
673*4882a593Smuzhiyun * @sg_supp: Indicates if scatter gather is supported
674*4882a593Smuzhiyun * @seq_offload: Indicates if sequence offload is supported
675*4882a593Smuzhiyun * @crc_offload: Indicates if CRC offload is supported
676*4882a593Smuzhiyun * @lro_enabled: Indicates if large receive offload is supported
677*4882a593Smuzhiyun * @does_npiv: Supports multiple vports
678*4882a593Smuzhiyun * @npiv_enabled: Switch/fabric allows NPIV
679*4882a593Smuzhiyun * @mfs: The maximum Fibre Channel payload size
680*4882a593Smuzhiyun * @max_retry_count: The maximum retry attempts
681*4882a593Smuzhiyun * @max_rport_retry_count: The maximum remote port retry attempts
682*4882a593Smuzhiyun * @rport_priv_size: Size needed by driver after struct fc_rport_priv
683*4882a593Smuzhiyun * @lro_xid: The maximum XID for LRO
684*4882a593Smuzhiyun * @lso_max: The maximum large offload send size
685*4882a593Smuzhiyun * @fcts: FC-4 type mask
686*4882a593Smuzhiyun * @lp_mutex: Mutex to protect the local port
687*4882a593Smuzhiyun * @list: Linkage on list of vport peers
688*4882a593Smuzhiyun * @retry_work: Handle to local port for delayed retry context
689*4882a593Smuzhiyun * @prov: Pointers available for use by passive FC-4 providers
690*4882a593Smuzhiyun * @lport_list: Linkage on module-wide list of local ports
691*4882a593Smuzhiyun */
692*4882a593Smuzhiyun struct fc_lport {
693*4882a593Smuzhiyun /* Associations */
694*4882a593Smuzhiyun struct Scsi_Host *host;
695*4882a593Smuzhiyun struct list_head ema_list;
696*4882a593Smuzhiyun struct fc_rport_priv *dns_rdata;
697*4882a593Smuzhiyun struct fc_rport_priv *ms_rdata;
698*4882a593Smuzhiyun struct fc_rport_priv *ptp_rdata;
699*4882a593Smuzhiyun void *scsi_priv;
700*4882a593Smuzhiyun struct fc_disc disc;
701*4882a593Smuzhiyun
702*4882a593Smuzhiyun /* Virtual port information */
703*4882a593Smuzhiyun struct list_head vports;
704*4882a593Smuzhiyun struct fc_vport *vport;
705*4882a593Smuzhiyun
706*4882a593Smuzhiyun /* Operational Information */
707*4882a593Smuzhiyun struct libfc_function_template tt;
708*4882a593Smuzhiyun u8 link_up;
709*4882a593Smuzhiyun u8 qfull;
710*4882a593Smuzhiyun u16 vlan;
711*4882a593Smuzhiyun enum fc_lport_state state;
712*4882a593Smuzhiyun unsigned long boot_time;
713*4882a593Smuzhiyun struct fc_host_statistics host_stats;
714*4882a593Smuzhiyun struct fc_stats __percpu *stats;
715*4882a593Smuzhiyun u8 retry_count;
716*4882a593Smuzhiyun
717*4882a593Smuzhiyun /* Fabric information */
718*4882a593Smuzhiyun u32 port_id;
719*4882a593Smuzhiyun u64 wwpn;
720*4882a593Smuzhiyun u64 wwnn;
721*4882a593Smuzhiyun unsigned int service_params;
722*4882a593Smuzhiyun unsigned int e_d_tov;
723*4882a593Smuzhiyun unsigned int r_a_tov;
724*4882a593Smuzhiyun struct fc_els_rnid_gen rnid_gen;
725*4882a593Smuzhiyun
726*4882a593Smuzhiyun /* Capabilities */
727*4882a593Smuzhiyun u32 sg_supp:1;
728*4882a593Smuzhiyun u32 seq_offload:1;
729*4882a593Smuzhiyun u32 crc_offload:1;
730*4882a593Smuzhiyun u32 lro_enabled:1;
731*4882a593Smuzhiyun u32 does_npiv:1;
732*4882a593Smuzhiyun u32 npiv_enabled:1;
733*4882a593Smuzhiyun u32 point_to_multipoint:1;
734*4882a593Smuzhiyun u32 fdmi_enabled:1;
735*4882a593Smuzhiyun u32 mfs;
736*4882a593Smuzhiyun u8 max_retry_count;
737*4882a593Smuzhiyun u8 max_rport_retry_count;
738*4882a593Smuzhiyun u16 rport_priv_size;
739*4882a593Smuzhiyun u16 link_speed;
740*4882a593Smuzhiyun u16 link_supported_speeds;
741*4882a593Smuzhiyun u16 lro_xid;
742*4882a593Smuzhiyun unsigned int lso_max;
743*4882a593Smuzhiyun struct fc_ns_fts fcts;
744*4882a593Smuzhiyun
745*4882a593Smuzhiyun /* Miscellaneous */
746*4882a593Smuzhiyun struct mutex lp_mutex;
747*4882a593Smuzhiyun struct list_head list;
748*4882a593Smuzhiyun struct delayed_work retry_work;
749*4882a593Smuzhiyun void *prov[FC_FC4_PROV_SIZE];
750*4882a593Smuzhiyun struct list_head lport_list;
751*4882a593Smuzhiyun };
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun /**
754*4882a593Smuzhiyun * struct fc4_prov - FC-4 provider registration
755*4882a593Smuzhiyun * @prli: Handler for incoming PRLI
756*4882a593Smuzhiyun * @prlo: Handler for session reset
757*4882a593Smuzhiyun * @recv: Handler for incoming request
758*4882a593Smuzhiyun * @module: Pointer to module. May be NULL.
759*4882a593Smuzhiyun */
760*4882a593Smuzhiyun struct fc4_prov {
761*4882a593Smuzhiyun int (*prli)(struct fc_rport_priv *, u32 spp_len,
762*4882a593Smuzhiyun const struct fc_els_spp *spp_in,
763*4882a593Smuzhiyun struct fc_els_spp *spp_out);
764*4882a593Smuzhiyun void (*prlo)(struct fc_rport_priv *);
765*4882a593Smuzhiyun void (*recv)(struct fc_lport *, struct fc_frame *);
766*4882a593Smuzhiyun struct module *module;
767*4882a593Smuzhiyun };
768*4882a593Smuzhiyun
769*4882a593Smuzhiyun /*
770*4882a593Smuzhiyun * Register FC-4 provider with libfc.
771*4882a593Smuzhiyun */
772*4882a593Smuzhiyun int fc_fc4_register_provider(enum fc_fh_type type, struct fc4_prov *);
773*4882a593Smuzhiyun void fc_fc4_deregister_provider(enum fc_fh_type type, struct fc4_prov *);
774*4882a593Smuzhiyun
775*4882a593Smuzhiyun /*
776*4882a593Smuzhiyun * FC_LPORT HELPER FUNCTIONS
777*4882a593Smuzhiyun *****************************/
778*4882a593Smuzhiyun
779*4882a593Smuzhiyun /**
780*4882a593Smuzhiyun * fc_lport_test_ready() - Determine if a local port is in the READY state
781*4882a593Smuzhiyun * @lport: The local port to test
782*4882a593Smuzhiyun */
fc_lport_test_ready(struct fc_lport * lport)783*4882a593Smuzhiyun static inline int fc_lport_test_ready(struct fc_lport *lport)
784*4882a593Smuzhiyun {
785*4882a593Smuzhiyun return lport->state == LPORT_ST_READY;
786*4882a593Smuzhiyun }
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun /**
789*4882a593Smuzhiyun * fc_set_wwnn() - Set the World Wide Node Name of a local port
790*4882a593Smuzhiyun * @lport: The local port whose WWNN is to be set
791*4882a593Smuzhiyun * @wwnn: The new WWNN
792*4882a593Smuzhiyun */
fc_set_wwnn(struct fc_lport * lport,u64 wwnn)793*4882a593Smuzhiyun static inline void fc_set_wwnn(struct fc_lport *lport, u64 wwnn)
794*4882a593Smuzhiyun {
795*4882a593Smuzhiyun lport->wwnn = wwnn;
796*4882a593Smuzhiyun }
797*4882a593Smuzhiyun
798*4882a593Smuzhiyun /**
799*4882a593Smuzhiyun * fc_set_wwpn() - Set the World Wide Port Name of a local port
800*4882a593Smuzhiyun * @lport: The local port whose WWPN is to be set
801*4882a593Smuzhiyun * @wwpn: The new WWPN
802*4882a593Smuzhiyun */
fc_set_wwpn(struct fc_lport * lport,u64 wwpn)803*4882a593Smuzhiyun static inline void fc_set_wwpn(struct fc_lport *lport, u64 wwpn)
804*4882a593Smuzhiyun {
805*4882a593Smuzhiyun lport->wwpn = wwpn;
806*4882a593Smuzhiyun }
807*4882a593Smuzhiyun
808*4882a593Smuzhiyun /**
809*4882a593Smuzhiyun * fc_lport_state_enter() - Change a local port's state
810*4882a593Smuzhiyun * @lport: The local port whose state is to change
811*4882a593Smuzhiyun * @state: The new state
812*4882a593Smuzhiyun */
fc_lport_state_enter(struct fc_lport * lport,enum fc_lport_state state)813*4882a593Smuzhiyun static inline void fc_lport_state_enter(struct fc_lport *lport,
814*4882a593Smuzhiyun enum fc_lport_state state)
815*4882a593Smuzhiyun {
816*4882a593Smuzhiyun if (state != lport->state)
817*4882a593Smuzhiyun lport->retry_count = 0;
818*4882a593Smuzhiyun lport->state = state;
819*4882a593Smuzhiyun }
820*4882a593Smuzhiyun
821*4882a593Smuzhiyun /**
822*4882a593Smuzhiyun * fc_lport_init_stats() - Allocate per-CPU statistics for a local port
823*4882a593Smuzhiyun * @lport: The local port whose statistics are to be initialized
824*4882a593Smuzhiyun */
fc_lport_init_stats(struct fc_lport * lport)825*4882a593Smuzhiyun static inline int fc_lport_init_stats(struct fc_lport *lport)
826*4882a593Smuzhiyun {
827*4882a593Smuzhiyun lport->stats = alloc_percpu(struct fc_stats);
828*4882a593Smuzhiyun if (!lport->stats)
829*4882a593Smuzhiyun return -ENOMEM;
830*4882a593Smuzhiyun return 0;
831*4882a593Smuzhiyun }
832*4882a593Smuzhiyun
833*4882a593Smuzhiyun /**
834*4882a593Smuzhiyun * fc_lport_free_stats() - Free memory for a local port's statistics
835*4882a593Smuzhiyun * @lport: The local port whose statistics are to be freed
836*4882a593Smuzhiyun */
fc_lport_free_stats(struct fc_lport * lport)837*4882a593Smuzhiyun static inline void fc_lport_free_stats(struct fc_lport *lport)
838*4882a593Smuzhiyun {
839*4882a593Smuzhiyun free_percpu(lport->stats);
840*4882a593Smuzhiyun }
841*4882a593Smuzhiyun
842*4882a593Smuzhiyun /**
843*4882a593Smuzhiyun * lport_priv() - Return the private data from a local port
844*4882a593Smuzhiyun * @lport: The local port whose private data is to be retreived
845*4882a593Smuzhiyun */
lport_priv(const struct fc_lport * lport)846*4882a593Smuzhiyun static inline void *lport_priv(const struct fc_lport *lport)
847*4882a593Smuzhiyun {
848*4882a593Smuzhiyun return (void *)(lport + 1);
849*4882a593Smuzhiyun }
850*4882a593Smuzhiyun
851*4882a593Smuzhiyun /**
852*4882a593Smuzhiyun * libfc_host_alloc() - Allocate a Scsi_Host with room for a local port and
853*4882a593Smuzhiyun * LLD private data
854*4882a593Smuzhiyun * @sht: The SCSI host template
855*4882a593Smuzhiyun * @priv_size: Size of private data
856*4882a593Smuzhiyun *
857*4882a593Smuzhiyun * Returns: libfc lport
858*4882a593Smuzhiyun */
859*4882a593Smuzhiyun static inline struct fc_lport *
libfc_host_alloc(struct scsi_host_template * sht,int priv_size)860*4882a593Smuzhiyun libfc_host_alloc(struct scsi_host_template *sht, int priv_size)
861*4882a593Smuzhiyun {
862*4882a593Smuzhiyun struct fc_lport *lport;
863*4882a593Smuzhiyun struct Scsi_Host *shost;
864*4882a593Smuzhiyun
865*4882a593Smuzhiyun shost = scsi_host_alloc(sht, sizeof(*lport) + priv_size);
866*4882a593Smuzhiyun if (!shost)
867*4882a593Smuzhiyun return NULL;
868*4882a593Smuzhiyun lport = shost_priv(shost);
869*4882a593Smuzhiyun lport->host = shost;
870*4882a593Smuzhiyun INIT_LIST_HEAD(&lport->ema_list);
871*4882a593Smuzhiyun INIT_LIST_HEAD(&lport->vports);
872*4882a593Smuzhiyun return lport;
873*4882a593Smuzhiyun }
874*4882a593Smuzhiyun
875*4882a593Smuzhiyun /*
876*4882a593Smuzhiyun * FC_FCP HELPER FUNCTIONS
877*4882a593Smuzhiyun *****************************/
fc_fcp_is_read(const struct fc_fcp_pkt * fsp)878*4882a593Smuzhiyun static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)
879*4882a593Smuzhiyun {
880*4882a593Smuzhiyun if (fsp && fsp->cmd)
881*4882a593Smuzhiyun return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE;
882*4882a593Smuzhiyun return false;
883*4882a593Smuzhiyun }
884*4882a593Smuzhiyun
885*4882a593Smuzhiyun /*
886*4882a593Smuzhiyun * LOCAL PORT LAYER
887*4882a593Smuzhiyun *****************************/
888*4882a593Smuzhiyun int fc_lport_init(struct fc_lport *);
889*4882a593Smuzhiyun int fc_lport_destroy(struct fc_lport *);
890*4882a593Smuzhiyun int fc_fabric_logoff(struct fc_lport *);
891*4882a593Smuzhiyun int fc_fabric_login(struct fc_lport *);
892*4882a593Smuzhiyun void __fc_linkup(struct fc_lport *);
893*4882a593Smuzhiyun void fc_linkup(struct fc_lport *);
894*4882a593Smuzhiyun void __fc_linkdown(struct fc_lport *);
895*4882a593Smuzhiyun void fc_linkdown(struct fc_lport *);
896*4882a593Smuzhiyun void fc_vport_setlink(struct fc_lport *);
897*4882a593Smuzhiyun void fc_vports_linkchange(struct fc_lport *);
898*4882a593Smuzhiyun int fc_lport_config(struct fc_lport *);
899*4882a593Smuzhiyun int fc_lport_reset(struct fc_lport *);
900*4882a593Smuzhiyun void fc_lport_recv(struct fc_lport *lport, struct fc_frame *fp);
901*4882a593Smuzhiyun int fc_set_mfs(struct fc_lport *, u32 mfs);
902*4882a593Smuzhiyun struct fc_lport *libfc_vport_create(struct fc_vport *, int privsize);
903*4882a593Smuzhiyun struct fc_lport *fc_vport_id_lookup(struct fc_lport *, u32 port_id);
904*4882a593Smuzhiyun int fc_lport_bsg_request(struct bsg_job *);
905*4882a593Smuzhiyun void fc_lport_set_local_id(struct fc_lport *, u32 port_id);
906*4882a593Smuzhiyun void fc_lport_iterate(void (*func)(struct fc_lport *, void *), void *);
907*4882a593Smuzhiyun
908*4882a593Smuzhiyun /*
909*4882a593Smuzhiyun * REMOTE PORT LAYER
910*4882a593Smuzhiyun *****************************/
911*4882a593Smuzhiyun void fc_rport_terminate_io(struct fc_rport *);
912*4882a593Smuzhiyun struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
913*4882a593Smuzhiyun u32 port_id);
914*4882a593Smuzhiyun struct fc_rport_priv *fc_rport_create(struct fc_lport *, u32);
915*4882a593Smuzhiyun void fc_rport_destroy(struct kref *kref);
916*4882a593Smuzhiyun int fc_rport_login(struct fc_rport_priv *rdata);
917*4882a593Smuzhiyun int fc_rport_logoff(struct fc_rport_priv *rdata);
918*4882a593Smuzhiyun void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp);
919*4882a593Smuzhiyun void fc_rport_flush_queue(void);
920*4882a593Smuzhiyun
921*4882a593Smuzhiyun /*
922*4882a593Smuzhiyun * DISCOVERY LAYER
923*4882a593Smuzhiyun *****************************/
924*4882a593Smuzhiyun void fc_disc_init(struct fc_lport *);
925*4882a593Smuzhiyun void fc_disc_config(struct fc_lport *, void *);
926*4882a593Smuzhiyun
fc_disc_lport(struct fc_disc * disc)927*4882a593Smuzhiyun static inline struct fc_lport *fc_disc_lport(struct fc_disc *disc)
928*4882a593Smuzhiyun {
929*4882a593Smuzhiyun return container_of(disc, struct fc_lport, disc);
930*4882a593Smuzhiyun }
931*4882a593Smuzhiyun
932*4882a593Smuzhiyun /*
933*4882a593Smuzhiyun * FCP LAYER
934*4882a593Smuzhiyun *****************************/
935*4882a593Smuzhiyun int fc_fcp_init(struct fc_lport *);
936*4882a593Smuzhiyun void fc_fcp_destroy(struct fc_lport *);
937*4882a593Smuzhiyun
938*4882a593Smuzhiyun /*
939*4882a593Smuzhiyun * SCSI INTERACTION LAYER
940*4882a593Smuzhiyun *****************************/
941*4882a593Smuzhiyun int fc_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
942*4882a593Smuzhiyun int fc_eh_abort(struct scsi_cmnd *);
943*4882a593Smuzhiyun int fc_eh_device_reset(struct scsi_cmnd *);
944*4882a593Smuzhiyun int fc_eh_host_reset(struct scsi_cmnd *);
945*4882a593Smuzhiyun int fc_slave_alloc(struct scsi_device *);
946*4882a593Smuzhiyun
947*4882a593Smuzhiyun /*
948*4882a593Smuzhiyun * ELS/CT interface
949*4882a593Smuzhiyun *****************************/
950*4882a593Smuzhiyun int fc_elsct_init(struct fc_lport *);
951*4882a593Smuzhiyun struct fc_seq *fc_elsct_send(struct fc_lport *, u32 did,
952*4882a593Smuzhiyun struct fc_frame *,
953*4882a593Smuzhiyun unsigned int op,
954*4882a593Smuzhiyun void (*resp)(struct fc_seq *,
955*4882a593Smuzhiyun struct fc_frame *,
956*4882a593Smuzhiyun void *arg),
957*4882a593Smuzhiyun void *arg, u32 timer_msec);
958*4882a593Smuzhiyun void fc_lport_flogi_resp(struct fc_seq *, struct fc_frame *, void *);
959*4882a593Smuzhiyun void fc_lport_logo_resp(struct fc_seq *, struct fc_frame *, void *);
960*4882a593Smuzhiyun void fc_fill_reply_hdr(struct fc_frame *, const struct fc_frame *,
961*4882a593Smuzhiyun enum fc_rctl, u32 parm_offset);
962*4882a593Smuzhiyun void fc_fill_hdr(struct fc_frame *, const struct fc_frame *,
963*4882a593Smuzhiyun enum fc_rctl, u32 f_ctl, u16 seq_cnt, u32 parm_offset);
964*4882a593Smuzhiyun
965*4882a593Smuzhiyun
966*4882a593Smuzhiyun /*
967*4882a593Smuzhiyun * EXCHANGE MANAGER LAYER
968*4882a593Smuzhiyun *****************************/
969*4882a593Smuzhiyun int fc_exch_init(struct fc_lport *);
970*4882a593Smuzhiyun void fc_exch_update_stats(struct fc_lport *lport);
971*4882a593Smuzhiyun struct fc_seq *fc_exch_seq_send(struct fc_lport *lport,
972*4882a593Smuzhiyun struct fc_frame *fp,
973*4882a593Smuzhiyun void (*resp)(struct fc_seq *,
974*4882a593Smuzhiyun struct fc_frame *fp,
975*4882a593Smuzhiyun void *arg),
976*4882a593Smuzhiyun void (*destructor)(struct fc_seq *, void *),
977*4882a593Smuzhiyun void *arg, u32 timer_msec);
978*4882a593Smuzhiyun void fc_seq_els_rsp_send(struct fc_frame *, enum fc_els_cmd,
979*4882a593Smuzhiyun struct fc_seq_els_data *);
980*4882a593Smuzhiyun struct fc_seq *fc_seq_start_next(struct fc_seq *sp);
981*4882a593Smuzhiyun void fc_seq_set_resp(struct fc_seq *sp,
982*4882a593Smuzhiyun void (*resp)(struct fc_seq *, struct fc_frame *, void *),
983*4882a593Smuzhiyun void *arg);
984*4882a593Smuzhiyun struct fc_seq *fc_seq_assign(struct fc_lport *lport, struct fc_frame *fp);
985*4882a593Smuzhiyun void fc_seq_release(struct fc_seq *sp);
986*4882a593Smuzhiyun struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *,
987*4882a593Smuzhiyun struct fc_exch_mgr *,
988*4882a593Smuzhiyun bool (*match)(struct fc_frame *));
989*4882a593Smuzhiyun void fc_exch_mgr_del(struct fc_exch_mgr_anchor *);
990*4882a593Smuzhiyun int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst);
991*4882a593Smuzhiyun struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *, enum fc_class class,
992*4882a593Smuzhiyun u16 min_xid, u16 max_xid,
993*4882a593Smuzhiyun bool (*match)(struct fc_frame *));
994*4882a593Smuzhiyun void fc_exch_mgr_free(struct fc_lport *);
995*4882a593Smuzhiyun void fc_exch_recv(struct fc_lport *, struct fc_frame *);
996*4882a593Smuzhiyun void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);
997*4882a593Smuzhiyun int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp, struct fc_frame *fp);
998*4882a593Smuzhiyun int fc_seq_exch_abort(const struct fc_seq *, unsigned int timer_msec);
999*4882a593Smuzhiyun void fc_exch_done(struct fc_seq *sp);
1000*4882a593Smuzhiyun
1001*4882a593Smuzhiyun /*
1002*4882a593Smuzhiyun * Functions for fc_functions_template
1003*4882a593Smuzhiyun */
1004*4882a593Smuzhiyun void fc_get_host_speed(struct Scsi_Host *);
1005*4882a593Smuzhiyun void fc_get_host_port_state(struct Scsi_Host *);
1006*4882a593Smuzhiyun void fc_set_rport_loss_tmo(struct fc_rport *, u32 timeout);
1007*4882a593Smuzhiyun struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *);
1008*4882a593Smuzhiyun
1009*4882a593Smuzhiyun #endif /* _LIBFC_H_ */
1010