xref: /OK3568_Linux_fs/kernel/include/scsi/scsi_transport_fc.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *  FiberChannel transport specific attributes exported to sysfs.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *  Copyright (c) 2003 Silicon Graphics, Inc.  All rights reserved.
6*4882a593Smuzhiyun  *  Copyright (C) 2004-2007   James Smart, Emulex Corporation
7*4882a593Smuzhiyun  *    Rewrite for host, target, device, and remote port attributes,
8*4882a593Smuzhiyun  *    statistics, and service functions...
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun #ifndef SCSI_TRANSPORT_FC_H
11*4882a593Smuzhiyun #define SCSI_TRANSPORT_FC_H
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <linux/sched.h>
14*4882a593Smuzhiyun #include <linux/bsg-lib.h>
15*4882a593Smuzhiyun #include <asm/unaligned.h>
16*4882a593Smuzhiyun #include <scsi/scsi.h>
17*4882a593Smuzhiyun #include <scsi/scsi_netlink.h>
18*4882a593Smuzhiyun #include <scsi/scsi_host.h>
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun struct scsi_transport_template;
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /*
23*4882a593Smuzhiyun  * FC Port definitions - Following FC HBAAPI guidelines
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * Note: Not all binary values for the different fields match HBAAPI.
26*4882a593Smuzhiyun  *  Instead, we use densely packed ordinal values or enums.
27*4882a593Smuzhiyun  *  We get away with this as we never present the actual binary values
28*4882a593Smuzhiyun  *  externally. For sysfs, we always present the string that describes
29*4882a593Smuzhiyun  *  the value. Thus, an admin doesn't need a magic HBAAPI decoder ring
30*4882a593Smuzhiyun  *  to understand the values. The HBAAPI user-space library is free to
31*4882a593Smuzhiyun  *  convert the strings into the HBAAPI-specified binary values.
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  * Note: Not all HBAAPI-defined values are contained in the definitions
34*4882a593Smuzhiyun  *  below. Those not appropriate to an fc_host (e.g. FCP initiator) have
35*4882a593Smuzhiyun  *  been removed.
36*4882a593Smuzhiyun  */
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun /*
39*4882a593Smuzhiyun  * fc_port_type: If you alter this, you also need to alter scsi_transport_fc.c
40*4882a593Smuzhiyun  * (for the ascii descriptions).
41*4882a593Smuzhiyun  */
42*4882a593Smuzhiyun enum fc_port_type {
43*4882a593Smuzhiyun 	FC_PORTTYPE_UNKNOWN,
44*4882a593Smuzhiyun 	FC_PORTTYPE_OTHER,
45*4882a593Smuzhiyun 	FC_PORTTYPE_NOTPRESENT,
46*4882a593Smuzhiyun 	FC_PORTTYPE_NPORT,		/* Attached to FPort */
47*4882a593Smuzhiyun 	FC_PORTTYPE_NLPORT,		/* (Public) Loop w/ FLPort */
48*4882a593Smuzhiyun 	FC_PORTTYPE_LPORT,		/* (Private) Loop w/o FLPort */
49*4882a593Smuzhiyun 	FC_PORTTYPE_PTP,		/* Point to Point w/ another NPort */
50*4882a593Smuzhiyun 	FC_PORTTYPE_NPIV,		/* VPORT based on NPIV */
51*4882a593Smuzhiyun };
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /*
55*4882a593Smuzhiyun  * fc_port_state: If you alter this, you also need to alter scsi_transport_fc.c
56*4882a593Smuzhiyun  * (for the ascii descriptions).
57*4882a593Smuzhiyun  */
58*4882a593Smuzhiyun enum fc_port_state {
59*4882a593Smuzhiyun 	FC_PORTSTATE_UNKNOWN,
60*4882a593Smuzhiyun 	FC_PORTSTATE_NOTPRESENT,
61*4882a593Smuzhiyun 	FC_PORTSTATE_ONLINE,
62*4882a593Smuzhiyun 	FC_PORTSTATE_OFFLINE,		/* User has taken Port Offline */
63*4882a593Smuzhiyun 	FC_PORTSTATE_BLOCKED,
64*4882a593Smuzhiyun 	FC_PORTSTATE_BYPASSED,
65*4882a593Smuzhiyun 	FC_PORTSTATE_DIAGNOSTICS,
66*4882a593Smuzhiyun 	FC_PORTSTATE_LINKDOWN,
67*4882a593Smuzhiyun 	FC_PORTSTATE_ERROR,
68*4882a593Smuzhiyun 	FC_PORTSTATE_LOOPBACK,
69*4882a593Smuzhiyun 	FC_PORTSTATE_DELETED,
70*4882a593Smuzhiyun };
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun /*
74*4882a593Smuzhiyun  * fc_vport_state: If you alter this, you also need to alter
75*4882a593Smuzhiyun  * scsi_transport_fc.c (for the ascii descriptions).
76*4882a593Smuzhiyun  */
77*4882a593Smuzhiyun enum fc_vport_state {
78*4882a593Smuzhiyun 	FC_VPORT_UNKNOWN,
79*4882a593Smuzhiyun 	FC_VPORT_ACTIVE,
80*4882a593Smuzhiyun 	FC_VPORT_DISABLED,
81*4882a593Smuzhiyun 	FC_VPORT_LINKDOWN,
82*4882a593Smuzhiyun 	FC_VPORT_INITIALIZING,
83*4882a593Smuzhiyun 	FC_VPORT_NO_FABRIC_SUPP,
84*4882a593Smuzhiyun 	FC_VPORT_NO_FABRIC_RSCS,
85*4882a593Smuzhiyun 	FC_VPORT_FABRIC_LOGOUT,
86*4882a593Smuzhiyun 	FC_VPORT_FABRIC_REJ_WWN,
87*4882a593Smuzhiyun 	FC_VPORT_FAILED,
88*4882a593Smuzhiyun };
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun /*
93*4882a593Smuzhiyun  * FC Classes of Service
94*4882a593Smuzhiyun  * Note: values are not enumerated, as they can be "or'd" together
95*4882a593Smuzhiyun  * for reporting (e.g. report supported_classes). If you alter this list,
96*4882a593Smuzhiyun  * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
97*4882a593Smuzhiyun  */
98*4882a593Smuzhiyun #define FC_COS_UNSPECIFIED		0
99*4882a593Smuzhiyun #define FC_COS_CLASS1			2
100*4882a593Smuzhiyun #define FC_COS_CLASS2			4
101*4882a593Smuzhiyun #define FC_COS_CLASS3			8
102*4882a593Smuzhiyun #define FC_COS_CLASS4			0x10
103*4882a593Smuzhiyun #define FC_COS_CLASS6			0x40
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /*
106*4882a593Smuzhiyun  * FC Port Speeds
107*4882a593Smuzhiyun  * Note: values are not enumerated, as they can be "or'd" together
108*4882a593Smuzhiyun  * for reporting (e.g. report supported_speeds). If you alter this list,
109*4882a593Smuzhiyun  * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
110*4882a593Smuzhiyun  */
111*4882a593Smuzhiyun #define FC_PORTSPEED_UNKNOWN		0 /* Unknown - transceiver
112*4882a593Smuzhiyun 					     incapable of reporting */
113*4882a593Smuzhiyun #define FC_PORTSPEED_1GBIT		1
114*4882a593Smuzhiyun #define FC_PORTSPEED_2GBIT		2
115*4882a593Smuzhiyun #define FC_PORTSPEED_10GBIT		4
116*4882a593Smuzhiyun #define FC_PORTSPEED_4GBIT		8
117*4882a593Smuzhiyun #define FC_PORTSPEED_8GBIT		0x10
118*4882a593Smuzhiyun #define FC_PORTSPEED_16GBIT		0x20
119*4882a593Smuzhiyun #define FC_PORTSPEED_32GBIT		0x40
120*4882a593Smuzhiyun #define FC_PORTSPEED_20GBIT		0x80
121*4882a593Smuzhiyun #define FC_PORTSPEED_40GBIT		0x100
122*4882a593Smuzhiyun #define FC_PORTSPEED_50GBIT		0x200
123*4882a593Smuzhiyun #define FC_PORTSPEED_100GBIT		0x400
124*4882a593Smuzhiyun #define FC_PORTSPEED_25GBIT		0x800
125*4882a593Smuzhiyun #define FC_PORTSPEED_64GBIT		0x1000
126*4882a593Smuzhiyun #define FC_PORTSPEED_128GBIT		0x2000
127*4882a593Smuzhiyun #define FC_PORTSPEED_256GBIT		0x4000
128*4882a593Smuzhiyun #define FC_PORTSPEED_NOT_NEGOTIATED	(1 << 15) /* Speed not established */
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun /*
131*4882a593Smuzhiyun  * fc_tgtid_binding_type: If you alter this, you also need to alter
132*4882a593Smuzhiyun  * scsi_transport_fc.c (for the ascii descriptions).
133*4882a593Smuzhiyun  */
134*4882a593Smuzhiyun enum fc_tgtid_binding_type  {
135*4882a593Smuzhiyun 	FC_TGTID_BIND_NONE,
136*4882a593Smuzhiyun 	FC_TGTID_BIND_BY_WWPN,
137*4882a593Smuzhiyun 	FC_TGTID_BIND_BY_WWNN,
138*4882a593Smuzhiyun 	FC_TGTID_BIND_BY_ID,
139*4882a593Smuzhiyun };
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun /*
142*4882a593Smuzhiyun  * FC Port Roles
143*4882a593Smuzhiyun  * Note: values are not enumerated, as they can be "or'd" together
144*4882a593Smuzhiyun  * for reporting (e.g. report roles). If you alter this list,
145*4882a593Smuzhiyun  * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
146*4882a593Smuzhiyun  */
147*4882a593Smuzhiyun #define FC_PORT_ROLE_UNKNOWN			0x00
148*4882a593Smuzhiyun #define FC_PORT_ROLE_FCP_TARGET			0x01
149*4882a593Smuzhiyun #define FC_PORT_ROLE_FCP_INITIATOR		0x02
150*4882a593Smuzhiyun #define FC_PORT_ROLE_IP_PORT			0x04
151*4882a593Smuzhiyun #define FC_PORT_ROLE_FCP_DUMMY_INITIATOR	0x08
152*4882a593Smuzhiyun #define FC_PORT_ROLE_NVME_INITIATOR		0x10
153*4882a593Smuzhiyun #define FC_PORT_ROLE_NVME_TARGET		0x20
154*4882a593Smuzhiyun #define FC_PORT_ROLE_NVME_DISCOVERY		0x40
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun /* The following are for compatibility */
157*4882a593Smuzhiyun #define FC_RPORT_ROLE_UNKNOWN			FC_PORT_ROLE_UNKNOWN
158*4882a593Smuzhiyun #define FC_RPORT_ROLE_FCP_TARGET		FC_PORT_ROLE_FCP_TARGET
159*4882a593Smuzhiyun #define FC_RPORT_ROLE_FCP_INITIATOR		FC_PORT_ROLE_FCP_INITIATOR
160*4882a593Smuzhiyun #define FC_RPORT_ROLE_IP_PORT			FC_PORT_ROLE_IP_PORT
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun /* Macro for use in defining Virtual Port attributes */
164*4882a593Smuzhiyun #define FC_VPORT_ATTR(_name,_mode,_show,_store)		\
165*4882a593Smuzhiyun struct device_attribute dev_attr_vport_##_name = 	\
166*4882a593Smuzhiyun 	__ATTR(_name,_mode,_show,_store)
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun /*
169*4882a593Smuzhiyun  * fc_vport_identifiers: This set of data contains all elements
170*4882a593Smuzhiyun  * to uniquely identify and instantiate a FC virtual port.
171*4882a593Smuzhiyun  *
172*4882a593Smuzhiyun  * Notes:
173*4882a593Smuzhiyun  *   symbolic_name: The driver is to append the symbolic_name string data
174*4882a593Smuzhiyun  *      to the symbolic_node_name data that it generates by default.
175*4882a593Smuzhiyun  *      the resulting combination should then be registered with the switch.
176*4882a593Smuzhiyun  *      It is expected that things like Xen may stuff a VM title into
177*4882a593Smuzhiyun  *      this field.
178*4882a593Smuzhiyun  */
179*4882a593Smuzhiyun #define FC_VPORT_SYMBOLIC_NAMELEN		64
180*4882a593Smuzhiyun struct fc_vport_identifiers {
181*4882a593Smuzhiyun 	u64 node_name;
182*4882a593Smuzhiyun 	u64 port_name;
183*4882a593Smuzhiyun 	u32 roles;
184*4882a593Smuzhiyun 	bool disable;
185*4882a593Smuzhiyun 	enum fc_port_type vport_type;	/* only FC_PORTTYPE_NPIV allowed */
186*4882a593Smuzhiyun 	char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
187*4882a593Smuzhiyun };
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun /*
190*4882a593Smuzhiyun  * FC Virtual Port Attributes
191*4882a593Smuzhiyun  *
192*4882a593Smuzhiyun  * This structure exists for each FC port is a virtual FC port. Virtual
193*4882a593Smuzhiyun  * ports share the physical link with the Physical port. Each virtual
194*4882a593Smuzhiyun  * ports has a unique presence on the SAN, and may be instantiated via
195*4882a593Smuzhiyun  * NPIV, Virtual Fabrics, or via additional ALPAs. As the vport is a
196*4882a593Smuzhiyun  * unique presence, each vport has it's own view of the fabric,
197*4882a593Smuzhiyun  * authentication privilege, and priorities.
198*4882a593Smuzhiyun  *
199*4882a593Smuzhiyun  * A virtual port may support 1 or more FC4 roles. Typically it is a
200*4882a593Smuzhiyun  * FCP Initiator. It could be a FCP Target, or exist sole for an IP over FC
201*4882a593Smuzhiyun  * roles. FC port attributes for the vport will be reported on any
202*4882a593Smuzhiyun  * fc_host class object allocated for an FCP Initiator.
203*4882a593Smuzhiyun  *
204*4882a593Smuzhiyun  * --
205*4882a593Smuzhiyun  *
206*4882a593Smuzhiyun  * Fixed attributes are not expected to change. The driver is
207*4882a593Smuzhiyun  * expected to set these values after receiving the fc_vport structure
208*4882a593Smuzhiyun  * via the vport_create() call from the transport.
209*4882a593Smuzhiyun  * The transport fully manages all get functions w/o driver interaction.
210*4882a593Smuzhiyun  *
211*4882a593Smuzhiyun  * Dynamic attributes are expected to change. The driver participates
212*4882a593Smuzhiyun  * in all get/set operations via functions provided by the driver.
213*4882a593Smuzhiyun  *
214*4882a593Smuzhiyun  * Private attributes are transport-managed values. They are fully
215*4882a593Smuzhiyun  * managed by the transport w/o driver interaction.
216*4882a593Smuzhiyun  */
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun struct fc_vport {
219*4882a593Smuzhiyun 	/* Fixed Attributes */
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun 	/* Dynamic Attributes */
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun 	/* Private (Transport-managed) Attributes */
224*4882a593Smuzhiyun 	enum fc_vport_state vport_state;
225*4882a593Smuzhiyun 	enum fc_vport_state vport_last_state;
226*4882a593Smuzhiyun 	u64 node_name;
227*4882a593Smuzhiyun 	u64 port_name;
228*4882a593Smuzhiyun 	u32 roles;
229*4882a593Smuzhiyun 	u32 vport_id;		/* Admin Identifier for the vport */
230*4882a593Smuzhiyun 	enum fc_port_type vport_type;
231*4882a593Smuzhiyun 	char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun 	/* exported data */
234*4882a593Smuzhiyun 	void *dd_data;			/* Used for driver-specific storage */
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun 	/* internal data */
237*4882a593Smuzhiyun 	struct Scsi_Host *shost;	/* Physical Port Parent */
238*4882a593Smuzhiyun 	unsigned int channel;
239*4882a593Smuzhiyun 	u32 number;
240*4882a593Smuzhiyun 	u8 flags;
241*4882a593Smuzhiyun 	struct list_head peers;
242*4882a593Smuzhiyun 	struct device dev;
243*4882a593Smuzhiyun 	struct work_struct vport_delete_work;
244*4882a593Smuzhiyun } __attribute__((aligned(sizeof(unsigned long))));
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun /* bit field values for struct fc_vport "flags" field: */
247*4882a593Smuzhiyun #define FC_VPORT_CREATING		0x01
248*4882a593Smuzhiyun #define FC_VPORT_DELETING		0x02
249*4882a593Smuzhiyun #define FC_VPORT_DELETED		0x04
250*4882a593Smuzhiyun #define FC_VPORT_DEL			0x06	/* Any DELETE state */
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun #define	dev_to_vport(d)				\
253*4882a593Smuzhiyun 	container_of(d, struct fc_vport, dev)
254*4882a593Smuzhiyun #define transport_class_to_vport(dev)		\
255*4882a593Smuzhiyun 	dev_to_vport(dev->parent)
256*4882a593Smuzhiyun #define vport_to_shost(v)			\
257*4882a593Smuzhiyun 	(v->shost)
258*4882a593Smuzhiyun #define vport_to_shost_channel(v)		\
259*4882a593Smuzhiyun 	(v->channel)
260*4882a593Smuzhiyun #define vport_to_parent(v)			\
261*4882a593Smuzhiyun 	(v->dev.parent)
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun /* Error return codes for vport_create() callback */
265*4882a593Smuzhiyun #define VPCERR_UNSUPPORTED		-ENOSYS		/* no driver/adapter
266*4882a593Smuzhiyun 							   support */
267*4882a593Smuzhiyun #define VPCERR_BAD_WWN			-ENOTUNIQ	/* driver validation
268*4882a593Smuzhiyun 							   of WWNs failed */
269*4882a593Smuzhiyun #define VPCERR_NO_FABRIC_SUPP		-EOPNOTSUPP	/* Fabric connection
270*4882a593Smuzhiyun 							   is loop or the
271*4882a593Smuzhiyun 							   Fabric Port does
272*4882a593Smuzhiyun 							   not support NPIV */
273*4882a593Smuzhiyun 
274*4882a593Smuzhiyun /*
275*4882a593Smuzhiyun  * fc_rport_identifiers: This set of data contains all elements
276*4882a593Smuzhiyun  * to uniquely identify a remote FC port. The driver uses this data
277*4882a593Smuzhiyun  * to report the existence of a remote FC port in the topology. Internally,
278*4882a593Smuzhiyun  * the transport uses this data for attributes and to manage consistent
279*4882a593Smuzhiyun  * target id bindings.
280*4882a593Smuzhiyun  */
281*4882a593Smuzhiyun struct fc_rport_identifiers {
282*4882a593Smuzhiyun 	u64 node_name;
283*4882a593Smuzhiyun 	u64 port_name;
284*4882a593Smuzhiyun 	u32 port_id;
285*4882a593Smuzhiyun 	u32 roles;
286*4882a593Smuzhiyun };
287*4882a593Smuzhiyun 
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun /* Macro for use in defining Remote Port attributes */
290*4882a593Smuzhiyun #define FC_RPORT_ATTR(_name,_mode,_show,_store)				\
291*4882a593Smuzhiyun struct device_attribute dev_attr_rport_##_name = 	\
292*4882a593Smuzhiyun 	__ATTR(_name,_mode,_show,_store)
293*4882a593Smuzhiyun 
294*4882a593Smuzhiyun 
295*4882a593Smuzhiyun /*
296*4882a593Smuzhiyun  * FC Remote Port Attributes
297*4882a593Smuzhiyun  *
298*4882a593Smuzhiyun  * This structure exists for each remote FC port that a LLDD notifies
299*4882a593Smuzhiyun  * the subsystem of.  A remote FC port may or may not be a SCSI Target,
300*4882a593Smuzhiyun  * also be a SCSI initiator, IP endpoint, etc. As such, the remote
301*4882a593Smuzhiyun  * port is considered a separate entity, independent of "role" (such
302*4882a593Smuzhiyun  * as scsi target).
303*4882a593Smuzhiyun  *
304*4882a593Smuzhiyun  * --
305*4882a593Smuzhiyun  *
306*4882a593Smuzhiyun  * Attributes are based on HBAAPI V2.0 definitions. Only those
307*4882a593Smuzhiyun  * attributes that are determinable by the local port (aka Host)
308*4882a593Smuzhiyun  * are contained.
309*4882a593Smuzhiyun  *
310*4882a593Smuzhiyun  * Fixed attributes are not expected to change. The driver is
311*4882a593Smuzhiyun  * expected to set these values after successfully calling
312*4882a593Smuzhiyun  * fc_remote_port_add(). The transport fully manages all get functions
313*4882a593Smuzhiyun  * w/o driver interaction.
314*4882a593Smuzhiyun  *
315*4882a593Smuzhiyun  * Dynamic attributes are expected to change. The driver participates
316*4882a593Smuzhiyun  * in all get/set operations via functions provided by the driver.
317*4882a593Smuzhiyun  *
318*4882a593Smuzhiyun  * Private attributes are transport-managed values. They are fully
319*4882a593Smuzhiyun  * managed by the transport w/o driver interaction.
320*4882a593Smuzhiyun  */
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun struct fc_rport {	/* aka fc_starget_attrs */
323*4882a593Smuzhiyun 	/* Fixed Attributes */
324*4882a593Smuzhiyun 	u32 maxframe_size;
325*4882a593Smuzhiyun 	u32 supported_classes;
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	/* Dynamic Attributes */
328*4882a593Smuzhiyun 	u32 dev_loss_tmo;	/* Remote Port loss timeout in seconds. */
329*4882a593Smuzhiyun 
330*4882a593Smuzhiyun 	/* Private (Transport-managed) Attributes */
331*4882a593Smuzhiyun 	u64 node_name;
332*4882a593Smuzhiyun 	u64 port_name;
333*4882a593Smuzhiyun 	u32 port_id;
334*4882a593Smuzhiyun 	u32 roles;
335*4882a593Smuzhiyun 	enum fc_port_state port_state;	/* Will only be ONLINE or UNKNOWN */
336*4882a593Smuzhiyun 	u32 scsi_target_id;
337*4882a593Smuzhiyun 	u32 fast_io_fail_tmo;
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun 	/* exported data */
340*4882a593Smuzhiyun 	void *dd_data;			/* Used for driver-specific storage */
341*4882a593Smuzhiyun 
342*4882a593Smuzhiyun 	/* internal data */
343*4882a593Smuzhiyun 	unsigned int channel;
344*4882a593Smuzhiyun 	u32 number;
345*4882a593Smuzhiyun 	u8 flags;
346*4882a593Smuzhiyun 	struct list_head peers;
347*4882a593Smuzhiyun 	struct device dev;
348*4882a593Smuzhiyun  	struct delayed_work dev_loss_work;
349*4882a593Smuzhiyun  	struct work_struct scan_work;
350*4882a593Smuzhiyun  	struct delayed_work fail_io_work;
351*4882a593Smuzhiyun  	struct work_struct stgt_delete_work;
352*4882a593Smuzhiyun 	struct work_struct rport_delete_work;
353*4882a593Smuzhiyun 	struct request_queue *rqst_q;	/* bsg support */
354*4882a593Smuzhiyun } __attribute__((aligned(sizeof(unsigned long))));
355*4882a593Smuzhiyun 
356*4882a593Smuzhiyun /* bit field values for struct fc_rport "flags" field: */
357*4882a593Smuzhiyun #define FC_RPORT_DEVLOSS_PENDING	0x01
358*4882a593Smuzhiyun #define FC_RPORT_SCAN_PENDING		0x02
359*4882a593Smuzhiyun #define FC_RPORT_FAST_FAIL_TIMEDOUT	0x04
360*4882a593Smuzhiyun #define FC_RPORT_DEVLOSS_CALLBK_DONE	0x08
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun #define	dev_to_rport(d)				\
363*4882a593Smuzhiyun 	container_of(d, struct fc_rport, dev)
364*4882a593Smuzhiyun #define transport_class_to_rport(dev)	\
365*4882a593Smuzhiyun 	dev_to_rport(dev->parent)
366*4882a593Smuzhiyun #define rport_to_shost(r)			\
367*4882a593Smuzhiyun 	dev_to_shost(r->dev.parent)
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun /*
370*4882a593Smuzhiyun  * FC SCSI Target Attributes
371*4882a593Smuzhiyun  *
372*4882a593Smuzhiyun  * The SCSI Target is considered an extension of a remote port (as
373*4882a593Smuzhiyun  * a remote port can be more than a SCSI Target). Within the scsi
374*4882a593Smuzhiyun  * subsystem, we leave the Target as a separate entity. Doing so
375*4882a593Smuzhiyun  * provides backward compatibility with prior FC transport api's,
376*4882a593Smuzhiyun  * and lets remote ports be handled entirely within the FC transport
377*4882a593Smuzhiyun  * and independently from the scsi subsystem. The drawback is that
378*4882a593Smuzhiyun  * some data will be duplicated.
379*4882a593Smuzhiyun  */
380*4882a593Smuzhiyun 
381*4882a593Smuzhiyun struct fc_starget_attrs {	/* aka fc_target_attrs */
382*4882a593Smuzhiyun 	/* Dynamic Attributes */
383*4882a593Smuzhiyun 	u64 node_name;
384*4882a593Smuzhiyun 	u64 port_name;
385*4882a593Smuzhiyun 	u32 port_id;
386*4882a593Smuzhiyun };
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun #define fc_starget_node_name(x) \
389*4882a593Smuzhiyun 	(((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
390*4882a593Smuzhiyun #define fc_starget_port_name(x)	\
391*4882a593Smuzhiyun 	(((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
392*4882a593Smuzhiyun #define fc_starget_port_id(x) \
393*4882a593Smuzhiyun 	(((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun #define starget_to_rport(s)			\
396*4882a593Smuzhiyun 	scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL
397*4882a593Smuzhiyun 
398*4882a593Smuzhiyun 
399*4882a593Smuzhiyun /*
400*4882a593Smuzhiyun  * FC Local Port (Host) Statistics
401*4882a593Smuzhiyun  */
402*4882a593Smuzhiyun 
403*4882a593Smuzhiyun /* FC Statistics - Following FC HBAAPI v2.0 guidelines */
404*4882a593Smuzhiyun struct fc_host_statistics {
405*4882a593Smuzhiyun 	/* port statistics */
406*4882a593Smuzhiyun 	u64 seconds_since_last_reset;
407*4882a593Smuzhiyun 	u64 tx_frames;
408*4882a593Smuzhiyun 	u64 tx_words;
409*4882a593Smuzhiyun 	u64 rx_frames;
410*4882a593Smuzhiyun 	u64 rx_words;
411*4882a593Smuzhiyun 	u64 lip_count;
412*4882a593Smuzhiyun 	u64 nos_count;
413*4882a593Smuzhiyun 	u64 error_frames;
414*4882a593Smuzhiyun 	u64 dumped_frames;
415*4882a593Smuzhiyun 	u64 link_failure_count;
416*4882a593Smuzhiyun 	u64 loss_of_sync_count;
417*4882a593Smuzhiyun 	u64 loss_of_signal_count;
418*4882a593Smuzhiyun 	u64 prim_seq_protocol_err_count;
419*4882a593Smuzhiyun 	u64 invalid_tx_word_count;
420*4882a593Smuzhiyun 	u64 invalid_crc_count;
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun 	/* fc4 statistics  (only FCP supported currently) */
423*4882a593Smuzhiyun 	u64 fcp_input_requests;
424*4882a593Smuzhiyun 	u64 fcp_output_requests;
425*4882a593Smuzhiyun 	u64 fcp_control_requests;
426*4882a593Smuzhiyun 	u64 fcp_input_megabytes;
427*4882a593Smuzhiyun 	u64 fcp_output_megabytes;
428*4882a593Smuzhiyun 	u64 fcp_packet_alloc_failures;	/* fcp packet allocation failures */
429*4882a593Smuzhiyun 	u64 fcp_packet_aborts;		/* fcp packet aborted */
430*4882a593Smuzhiyun 	u64 fcp_frame_alloc_failures;	/* fcp frame allocation failures */
431*4882a593Smuzhiyun 
432*4882a593Smuzhiyun 	/* fc exches statistics */
433*4882a593Smuzhiyun 	u64 fc_no_free_exch;		/* no free exch memory */
434*4882a593Smuzhiyun 	u64 fc_no_free_exch_xid;	/* no free exch id */
435*4882a593Smuzhiyun 	u64 fc_xid_not_found;		/* exch not found for a response */
436*4882a593Smuzhiyun 	u64 fc_xid_busy;		/* exch exist for new a request */
437*4882a593Smuzhiyun 	u64 fc_seq_not_found;		/* seq is not found for exchange */
438*4882a593Smuzhiyun 	u64 fc_non_bls_resp;		/* a non BLS response frame with
439*4882a593Smuzhiyun 					   a sequence responder in new exch */
440*4882a593Smuzhiyun };
441*4882a593Smuzhiyun 
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun /*
444*4882a593Smuzhiyun  * FC Event Codes - Polled and Async, following FC HBAAPI v2.0 guidelines
445*4882a593Smuzhiyun  */
446*4882a593Smuzhiyun 
447*4882a593Smuzhiyun /*
448*4882a593Smuzhiyun  * fc_host_event_code: If you alter this, you also need to alter
449*4882a593Smuzhiyun  * scsi_transport_fc.c (for the ascii descriptions).
450*4882a593Smuzhiyun  */
451*4882a593Smuzhiyun enum fc_host_event_code  {
452*4882a593Smuzhiyun 	FCH_EVT_LIP			= 0x1,
453*4882a593Smuzhiyun 	FCH_EVT_LINKUP			= 0x2,
454*4882a593Smuzhiyun 	FCH_EVT_LINKDOWN		= 0x3,
455*4882a593Smuzhiyun 	FCH_EVT_LIPRESET		= 0x4,
456*4882a593Smuzhiyun 	FCH_EVT_RSCN			= 0x5,
457*4882a593Smuzhiyun 	FCH_EVT_ADAPTER_CHANGE		= 0x103,
458*4882a593Smuzhiyun 	FCH_EVT_PORT_UNKNOWN		= 0x200,
459*4882a593Smuzhiyun 	FCH_EVT_PORT_OFFLINE		= 0x201,
460*4882a593Smuzhiyun 	FCH_EVT_PORT_ONLINE		= 0x202,
461*4882a593Smuzhiyun 	FCH_EVT_PORT_FABRIC		= 0x204,
462*4882a593Smuzhiyun 	FCH_EVT_LINK_UNKNOWN		= 0x500,
463*4882a593Smuzhiyun 	FCH_EVT_LINK_FPIN		= 0x501,
464*4882a593Smuzhiyun 	FCH_EVT_VENDOR_UNIQUE		= 0xffff,
465*4882a593Smuzhiyun };
466*4882a593Smuzhiyun 
467*4882a593Smuzhiyun 
468*4882a593Smuzhiyun /*
469*4882a593Smuzhiyun  * FC Local Port (Host) Attributes
470*4882a593Smuzhiyun  *
471*4882a593Smuzhiyun  * Attributes are based on HBAAPI V2.0 definitions.
472*4882a593Smuzhiyun  * Note: OSDeviceName is determined by user-space library
473*4882a593Smuzhiyun  *
474*4882a593Smuzhiyun  * Fixed attributes are not expected to change. The driver is
475*4882a593Smuzhiyun  * expected to set these values after successfully calling scsi_add_host().
476*4882a593Smuzhiyun  * The transport fully manages all get functions w/o driver interaction.
477*4882a593Smuzhiyun  *
478*4882a593Smuzhiyun  * Dynamic attributes are expected to change. The driver participates
479*4882a593Smuzhiyun  * in all get/set operations via functions provided by the driver.
480*4882a593Smuzhiyun  *
481*4882a593Smuzhiyun  * Private attributes are transport-managed values. They are fully
482*4882a593Smuzhiyun  * managed by the transport w/o driver interaction.
483*4882a593Smuzhiyun  */
484*4882a593Smuzhiyun 
485*4882a593Smuzhiyun #define FC_FC4_LIST_SIZE		32
486*4882a593Smuzhiyun #define FC_SYMBOLIC_NAME_SIZE		256
487*4882a593Smuzhiyun #define FC_VERSION_STRING_SIZE		64
488*4882a593Smuzhiyun #define FC_SERIAL_NUMBER_SIZE		80
489*4882a593Smuzhiyun 
490*4882a593Smuzhiyun struct fc_host_attrs {
491*4882a593Smuzhiyun 	/* Fixed Attributes */
492*4882a593Smuzhiyun 	u64 node_name;
493*4882a593Smuzhiyun 	u64 port_name;
494*4882a593Smuzhiyun 	u64 permanent_port_name;
495*4882a593Smuzhiyun 	u32 supported_classes;
496*4882a593Smuzhiyun 	u8  supported_fc4s[FC_FC4_LIST_SIZE];
497*4882a593Smuzhiyun 	u32 supported_speeds;
498*4882a593Smuzhiyun 	u32 maxframe_size;
499*4882a593Smuzhiyun 	u16 max_npiv_vports;
500*4882a593Smuzhiyun 	char serial_number[FC_SERIAL_NUMBER_SIZE];
501*4882a593Smuzhiyun 	char manufacturer[FC_SERIAL_NUMBER_SIZE];
502*4882a593Smuzhiyun 	char model[FC_SYMBOLIC_NAME_SIZE];
503*4882a593Smuzhiyun 	char model_description[FC_SYMBOLIC_NAME_SIZE];
504*4882a593Smuzhiyun 	char hardware_version[FC_VERSION_STRING_SIZE];
505*4882a593Smuzhiyun 	char driver_version[FC_VERSION_STRING_SIZE];
506*4882a593Smuzhiyun 	char firmware_version[FC_VERSION_STRING_SIZE];
507*4882a593Smuzhiyun 	char optionrom_version[FC_VERSION_STRING_SIZE];
508*4882a593Smuzhiyun 
509*4882a593Smuzhiyun 	/* Dynamic Attributes */
510*4882a593Smuzhiyun 	u32 port_id;
511*4882a593Smuzhiyun 	enum fc_port_type port_type;
512*4882a593Smuzhiyun 	enum fc_port_state port_state;
513*4882a593Smuzhiyun 	u8  active_fc4s[FC_FC4_LIST_SIZE];
514*4882a593Smuzhiyun 	u32 speed;
515*4882a593Smuzhiyun 	u64 fabric_name;
516*4882a593Smuzhiyun 	char symbolic_name[FC_SYMBOLIC_NAME_SIZE];
517*4882a593Smuzhiyun 	char system_hostname[FC_SYMBOLIC_NAME_SIZE];
518*4882a593Smuzhiyun 	u32 dev_loss_tmo;
519*4882a593Smuzhiyun 
520*4882a593Smuzhiyun 	/* Private (Transport-managed) Attributes */
521*4882a593Smuzhiyun 	enum fc_tgtid_binding_type  tgtid_bind_type;
522*4882a593Smuzhiyun 
523*4882a593Smuzhiyun 	/* internal data */
524*4882a593Smuzhiyun 	struct list_head rports;
525*4882a593Smuzhiyun 	struct list_head rport_bindings;
526*4882a593Smuzhiyun 	struct list_head vports;
527*4882a593Smuzhiyun 	u32 next_rport_number;
528*4882a593Smuzhiyun 	u32 next_target_id;
529*4882a593Smuzhiyun 	u32 next_vport_number;
530*4882a593Smuzhiyun 	u16 npiv_vports_inuse;
531*4882a593Smuzhiyun 
532*4882a593Smuzhiyun 	/* work queues for rport state manipulation */
533*4882a593Smuzhiyun 	char work_q_name[20];
534*4882a593Smuzhiyun 	struct workqueue_struct *work_q;
535*4882a593Smuzhiyun 	char devloss_work_q_name[20];
536*4882a593Smuzhiyun 	struct workqueue_struct *devloss_work_q;
537*4882a593Smuzhiyun 
538*4882a593Smuzhiyun 	/* bsg support */
539*4882a593Smuzhiyun 	struct request_queue *rqst_q;
540*4882a593Smuzhiyun };
541*4882a593Smuzhiyun 
542*4882a593Smuzhiyun #define shost_to_fc_host(x) \
543*4882a593Smuzhiyun 	((struct fc_host_attrs *)(x)->shost_data)
544*4882a593Smuzhiyun 
545*4882a593Smuzhiyun #define fc_host_node_name(x) \
546*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->node_name)
547*4882a593Smuzhiyun #define fc_host_port_name(x)	\
548*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->port_name)
549*4882a593Smuzhiyun #define fc_host_permanent_port_name(x)	\
550*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->permanent_port_name)
551*4882a593Smuzhiyun #define fc_host_supported_classes(x)	\
552*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->supported_classes)
553*4882a593Smuzhiyun #define fc_host_supported_fc4s(x)	\
554*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s)
555*4882a593Smuzhiyun #define fc_host_supported_speeds(x)	\
556*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->supported_speeds)
557*4882a593Smuzhiyun #define fc_host_maxframe_size(x)	\
558*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->maxframe_size)
559*4882a593Smuzhiyun #define fc_host_max_npiv_vports(x)	\
560*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->max_npiv_vports)
561*4882a593Smuzhiyun #define fc_host_serial_number(x)	\
562*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->serial_number)
563*4882a593Smuzhiyun #define fc_host_manufacturer(x)	\
564*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->manufacturer)
565*4882a593Smuzhiyun #define fc_host_model(x)	\
566*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->model)
567*4882a593Smuzhiyun #define fc_host_model_description(x)	\
568*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->model_description)
569*4882a593Smuzhiyun #define fc_host_hardware_version(x)	\
570*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->hardware_version)
571*4882a593Smuzhiyun #define fc_host_driver_version(x)	\
572*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->driver_version)
573*4882a593Smuzhiyun #define fc_host_firmware_version(x)	\
574*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->firmware_version)
575*4882a593Smuzhiyun #define fc_host_optionrom_version(x)	\
576*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->optionrom_version)
577*4882a593Smuzhiyun #define fc_host_port_id(x)	\
578*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->port_id)
579*4882a593Smuzhiyun #define fc_host_port_type(x)	\
580*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->port_type)
581*4882a593Smuzhiyun #define fc_host_port_state(x)	\
582*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->port_state)
583*4882a593Smuzhiyun #define fc_host_active_fc4s(x)	\
584*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->active_fc4s)
585*4882a593Smuzhiyun #define fc_host_speed(x)	\
586*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->speed)
587*4882a593Smuzhiyun #define fc_host_fabric_name(x)	\
588*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
589*4882a593Smuzhiyun #define fc_host_symbolic_name(x)	\
590*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->symbolic_name)
591*4882a593Smuzhiyun #define fc_host_system_hostname(x)	\
592*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->system_hostname)
593*4882a593Smuzhiyun #define fc_host_tgtid_bind_type(x) \
594*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
595*4882a593Smuzhiyun #define fc_host_rports(x) \
596*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->rports)
597*4882a593Smuzhiyun #define fc_host_rport_bindings(x) \
598*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->rport_bindings)
599*4882a593Smuzhiyun #define fc_host_vports(x) \
600*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->vports)
601*4882a593Smuzhiyun #define fc_host_next_rport_number(x) \
602*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->next_rport_number)
603*4882a593Smuzhiyun #define fc_host_next_target_id(x) \
604*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->next_target_id)
605*4882a593Smuzhiyun #define fc_host_next_vport_number(x) \
606*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->next_vport_number)
607*4882a593Smuzhiyun #define fc_host_npiv_vports_inuse(x)	\
608*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->npiv_vports_inuse)
609*4882a593Smuzhiyun #define fc_host_work_q_name(x) \
610*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->work_q_name)
611*4882a593Smuzhiyun #define fc_host_work_q(x) \
612*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->work_q)
613*4882a593Smuzhiyun #define fc_host_devloss_work_q_name(x) \
614*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q_name)
615*4882a593Smuzhiyun #define fc_host_devloss_work_q(x) \
616*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q)
617*4882a593Smuzhiyun #define fc_host_dev_loss_tmo(x) \
618*4882a593Smuzhiyun 	(((struct fc_host_attrs *)(x)->shost_data)->dev_loss_tmo)
619*4882a593Smuzhiyun 
620*4882a593Smuzhiyun /* The functions by which the transport class and the driver communicate */
621*4882a593Smuzhiyun struct fc_function_template {
622*4882a593Smuzhiyun 	void    (*get_rport_dev_loss_tmo)(struct fc_rport *);
623*4882a593Smuzhiyun 	void	(*set_rport_dev_loss_tmo)(struct fc_rport *, u32);
624*4882a593Smuzhiyun 
625*4882a593Smuzhiyun 	void	(*get_starget_node_name)(struct scsi_target *);
626*4882a593Smuzhiyun 	void	(*get_starget_port_name)(struct scsi_target *);
627*4882a593Smuzhiyun 	void 	(*get_starget_port_id)(struct scsi_target *);
628*4882a593Smuzhiyun 
629*4882a593Smuzhiyun 	void 	(*get_host_port_id)(struct Scsi_Host *);
630*4882a593Smuzhiyun 	void	(*get_host_port_type)(struct Scsi_Host *);
631*4882a593Smuzhiyun 	void	(*get_host_port_state)(struct Scsi_Host *);
632*4882a593Smuzhiyun 	void	(*get_host_active_fc4s)(struct Scsi_Host *);
633*4882a593Smuzhiyun 	void	(*get_host_speed)(struct Scsi_Host *);
634*4882a593Smuzhiyun 	void	(*get_host_fabric_name)(struct Scsi_Host *);
635*4882a593Smuzhiyun 	void	(*get_host_symbolic_name)(struct Scsi_Host *);
636*4882a593Smuzhiyun 	void	(*set_host_system_hostname)(struct Scsi_Host *);
637*4882a593Smuzhiyun 
638*4882a593Smuzhiyun 	struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
639*4882a593Smuzhiyun 	void	(*reset_fc_host_stats)(struct Scsi_Host *);
640*4882a593Smuzhiyun 
641*4882a593Smuzhiyun 	int	(*issue_fc_host_lip)(struct Scsi_Host *);
642*4882a593Smuzhiyun 
643*4882a593Smuzhiyun 	void    (*dev_loss_tmo_callbk)(struct fc_rport *);
644*4882a593Smuzhiyun 	void	(*terminate_rport_io)(struct fc_rport *);
645*4882a593Smuzhiyun 
646*4882a593Smuzhiyun 	void	(*set_vport_symbolic_name)(struct fc_vport *);
647*4882a593Smuzhiyun 	int  	(*vport_create)(struct fc_vport *, bool);
648*4882a593Smuzhiyun 	int	(*vport_disable)(struct fc_vport *, bool);
649*4882a593Smuzhiyun 	int  	(*vport_delete)(struct fc_vport *);
650*4882a593Smuzhiyun 
651*4882a593Smuzhiyun 	/* bsg support */
652*4882a593Smuzhiyun 	int	(*bsg_request)(struct bsg_job *);
653*4882a593Smuzhiyun 	int	(*bsg_timeout)(struct bsg_job *);
654*4882a593Smuzhiyun 
655*4882a593Smuzhiyun 	/* allocation lengths for host-specific data */
656*4882a593Smuzhiyun 	u32	 			dd_fcrport_size;
657*4882a593Smuzhiyun 	u32	 			dd_fcvport_size;
658*4882a593Smuzhiyun 	u32				dd_bsg_size;
659*4882a593Smuzhiyun 
660*4882a593Smuzhiyun 	/*
661*4882a593Smuzhiyun 	 * The driver sets these to tell the transport class it
662*4882a593Smuzhiyun 	 * wants the attributes displayed in sysfs.  If the show_ flag
663*4882a593Smuzhiyun 	 * is not set, the attribute will be private to the transport
664*4882a593Smuzhiyun 	 * class
665*4882a593Smuzhiyun 	 */
666*4882a593Smuzhiyun 
667*4882a593Smuzhiyun 	/* remote port fixed attributes */
668*4882a593Smuzhiyun 	unsigned long	show_rport_maxframe_size:1;
669*4882a593Smuzhiyun 	unsigned long	show_rport_supported_classes:1;
670*4882a593Smuzhiyun 	unsigned long   show_rport_dev_loss_tmo:1;
671*4882a593Smuzhiyun 
672*4882a593Smuzhiyun 	/*
673*4882a593Smuzhiyun 	 * target dynamic attributes
674*4882a593Smuzhiyun 	 * These should all be "1" if the driver uses the remote port
675*4882a593Smuzhiyun 	 * add/delete functions (so attributes reflect rport values).
676*4882a593Smuzhiyun 	 */
677*4882a593Smuzhiyun 	unsigned long	show_starget_node_name:1;
678*4882a593Smuzhiyun 	unsigned long	show_starget_port_name:1;
679*4882a593Smuzhiyun 	unsigned long	show_starget_port_id:1;
680*4882a593Smuzhiyun 
681*4882a593Smuzhiyun 	/* host fixed attributes */
682*4882a593Smuzhiyun 	unsigned long	show_host_node_name:1;
683*4882a593Smuzhiyun 	unsigned long	show_host_port_name:1;
684*4882a593Smuzhiyun 	unsigned long	show_host_permanent_port_name:1;
685*4882a593Smuzhiyun 	unsigned long	show_host_supported_classes:1;
686*4882a593Smuzhiyun 	unsigned long	show_host_supported_fc4s:1;
687*4882a593Smuzhiyun 	unsigned long	show_host_supported_speeds:1;
688*4882a593Smuzhiyun 	unsigned long	show_host_maxframe_size:1;
689*4882a593Smuzhiyun 	unsigned long	show_host_serial_number:1;
690*4882a593Smuzhiyun 	unsigned long	show_host_manufacturer:1;
691*4882a593Smuzhiyun 	unsigned long	show_host_model:1;
692*4882a593Smuzhiyun 	unsigned long	show_host_model_description:1;
693*4882a593Smuzhiyun 	unsigned long	show_host_hardware_version:1;
694*4882a593Smuzhiyun 	unsigned long	show_host_driver_version:1;
695*4882a593Smuzhiyun 	unsigned long	show_host_firmware_version:1;
696*4882a593Smuzhiyun 	unsigned long	show_host_optionrom_version:1;
697*4882a593Smuzhiyun 	/* host dynamic attributes */
698*4882a593Smuzhiyun 	unsigned long	show_host_port_id:1;
699*4882a593Smuzhiyun 	unsigned long	show_host_port_type:1;
700*4882a593Smuzhiyun 	unsigned long	show_host_port_state:1;
701*4882a593Smuzhiyun 	unsigned long	show_host_active_fc4s:1;
702*4882a593Smuzhiyun 	unsigned long	show_host_speed:1;
703*4882a593Smuzhiyun 	unsigned long	show_host_fabric_name:1;
704*4882a593Smuzhiyun 	unsigned long	show_host_symbolic_name:1;
705*4882a593Smuzhiyun 	unsigned long	show_host_system_hostname:1;
706*4882a593Smuzhiyun 
707*4882a593Smuzhiyun 	unsigned long	disable_target_scan:1;
708*4882a593Smuzhiyun };
709*4882a593Smuzhiyun 
710*4882a593Smuzhiyun 
711*4882a593Smuzhiyun /**
712*4882a593Smuzhiyun  * fc_remote_port_chkready - called to validate the remote port state
713*4882a593Smuzhiyun  *   prior to initiating io to the port.
714*4882a593Smuzhiyun  *
715*4882a593Smuzhiyun  * Returns a scsi result code that can be returned by the LLDD.
716*4882a593Smuzhiyun  *
717*4882a593Smuzhiyun  * @rport:	remote port to be checked
718*4882a593Smuzhiyun  **/
719*4882a593Smuzhiyun static inline int
fc_remote_port_chkready(struct fc_rport * rport)720*4882a593Smuzhiyun fc_remote_port_chkready(struct fc_rport *rport)
721*4882a593Smuzhiyun {
722*4882a593Smuzhiyun 	int result;
723*4882a593Smuzhiyun 
724*4882a593Smuzhiyun 	switch (rport->port_state) {
725*4882a593Smuzhiyun 	case FC_PORTSTATE_ONLINE:
726*4882a593Smuzhiyun 		if (rport->roles & FC_PORT_ROLE_FCP_TARGET)
727*4882a593Smuzhiyun 			result = 0;
728*4882a593Smuzhiyun 		else if (rport->flags & FC_RPORT_DEVLOSS_PENDING)
729*4882a593Smuzhiyun 			result = DID_IMM_RETRY << 16;
730*4882a593Smuzhiyun 		else
731*4882a593Smuzhiyun 			result = DID_NO_CONNECT << 16;
732*4882a593Smuzhiyun 		break;
733*4882a593Smuzhiyun 	case FC_PORTSTATE_BLOCKED:
734*4882a593Smuzhiyun 		if (rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT)
735*4882a593Smuzhiyun 			result = DID_TRANSPORT_FAILFAST << 16;
736*4882a593Smuzhiyun 		else
737*4882a593Smuzhiyun 			result = DID_IMM_RETRY << 16;
738*4882a593Smuzhiyun 		break;
739*4882a593Smuzhiyun 	default:
740*4882a593Smuzhiyun 		result = DID_NO_CONNECT << 16;
741*4882a593Smuzhiyun 		break;
742*4882a593Smuzhiyun 	}
743*4882a593Smuzhiyun 	return result;
744*4882a593Smuzhiyun }
745*4882a593Smuzhiyun 
wwn_to_u64(const u8 * wwn)746*4882a593Smuzhiyun static inline u64 wwn_to_u64(const u8 *wwn)
747*4882a593Smuzhiyun {
748*4882a593Smuzhiyun 	return get_unaligned_be64(wwn);
749*4882a593Smuzhiyun }
750*4882a593Smuzhiyun 
u64_to_wwn(u64 inm,u8 * wwn)751*4882a593Smuzhiyun static inline void u64_to_wwn(u64 inm, u8 *wwn)
752*4882a593Smuzhiyun {
753*4882a593Smuzhiyun 	put_unaligned_be64(inm, wwn);
754*4882a593Smuzhiyun }
755*4882a593Smuzhiyun 
756*4882a593Smuzhiyun /**
757*4882a593Smuzhiyun  * fc_vport_set_state() - called to set a vport's state. Saves the old state,
758*4882a593Smuzhiyun  *   excepting the transitory states of initializing and sending the ELS
759*4882a593Smuzhiyun  *   traffic to instantiate the vport on the link.
760*4882a593Smuzhiyun  *
761*4882a593Smuzhiyun  * Assumes the driver has surrounded this with the proper locking to ensure
762*4882a593Smuzhiyun  * a coherent state change.
763*4882a593Smuzhiyun  *
764*4882a593Smuzhiyun  * @vport:	virtual port whose state is changing
765*4882a593Smuzhiyun  * @new_state:  new state
766*4882a593Smuzhiyun  **/
767*4882a593Smuzhiyun static inline void
fc_vport_set_state(struct fc_vport * vport,enum fc_vport_state new_state)768*4882a593Smuzhiyun fc_vport_set_state(struct fc_vport *vport, enum fc_vport_state new_state)
769*4882a593Smuzhiyun {
770*4882a593Smuzhiyun 	if ((new_state != FC_VPORT_UNKNOWN) &&
771*4882a593Smuzhiyun 	    (new_state != FC_VPORT_INITIALIZING))
772*4882a593Smuzhiyun 		vport->vport_last_state = vport->vport_state;
773*4882a593Smuzhiyun 	vport->vport_state = new_state;
774*4882a593Smuzhiyun }
775*4882a593Smuzhiyun 
776*4882a593Smuzhiyun struct scsi_transport_template *fc_attach_transport(
777*4882a593Smuzhiyun 			struct fc_function_template *);
778*4882a593Smuzhiyun void fc_release_transport(struct scsi_transport_template *);
779*4882a593Smuzhiyun void fc_remove_host(struct Scsi_Host *);
780*4882a593Smuzhiyun struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
781*4882a593Smuzhiyun 			int channel, struct fc_rport_identifiers  *ids);
782*4882a593Smuzhiyun void fc_remote_port_delete(struct fc_rport  *rport);
783*4882a593Smuzhiyun void fc_remote_port_rolechg(struct fc_rport  *rport, u32 roles);
784*4882a593Smuzhiyun int scsi_is_fc_rport(const struct device *);
785*4882a593Smuzhiyun u32 fc_get_event_number(void);
786*4882a593Smuzhiyun void fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
787*4882a593Smuzhiyun 		enum fc_host_event_code event_code, u32 event_data);
788*4882a593Smuzhiyun void fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
789*4882a593Smuzhiyun 		u32 data_len, char *data_buf, u64 vendor_id);
790*4882a593Smuzhiyun void fc_host_post_fc_event(struct Scsi_Host *shost, u32 event_number,
791*4882a593Smuzhiyun 		enum fc_host_event_code event_code,
792*4882a593Smuzhiyun 		u32 data_len, char *data_buf, u64 vendor_id);
793*4882a593Smuzhiyun 	/* Note: when specifying vendor_id to fc_host_post_vendor_event()
794*4882a593Smuzhiyun 	 *   or fc_host_post_fc_event(), be sure to read the Vendor Type
795*4882a593Smuzhiyun 	 *   and ID formatting requirements specified in scsi_netlink.h
796*4882a593Smuzhiyun 	 * Note: when calling fc_host_post_fc_event(), vendor_id may be
797*4882a593Smuzhiyun 	 *   specified as 0.
798*4882a593Smuzhiyun 	 */
799*4882a593Smuzhiyun void fc_host_fpin_rcv(struct Scsi_Host *shost, u32 fpin_len, char *fpin_buf);
800*4882a593Smuzhiyun struct fc_vport *fc_vport_create(struct Scsi_Host *shost, int channel,
801*4882a593Smuzhiyun 		struct fc_vport_identifiers *);
802*4882a593Smuzhiyun int fc_vport_terminate(struct fc_vport *vport);
803*4882a593Smuzhiyun int fc_block_rport(struct fc_rport *rport);
804*4882a593Smuzhiyun int fc_block_scsi_eh(struct scsi_cmnd *cmnd);
805*4882a593Smuzhiyun enum blk_eh_timer_return fc_eh_timed_out(struct scsi_cmnd *scmd);
806*4882a593Smuzhiyun 
fc_bsg_to_shost(struct bsg_job * job)807*4882a593Smuzhiyun static inline struct Scsi_Host *fc_bsg_to_shost(struct bsg_job *job)
808*4882a593Smuzhiyun {
809*4882a593Smuzhiyun 	if (scsi_is_host_device(job->dev))
810*4882a593Smuzhiyun 		return dev_to_shost(job->dev);
811*4882a593Smuzhiyun 	return rport_to_shost(dev_to_rport(job->dev));
812*4882a593Smuzhiyun }
813*4882a593Smuzhiyun 
fc_bsg_to_rport(struct bsg_job * job)814*4882a593Smuzhiyun static inline struct fc_rport *fc_bsg_to_rport(struct bsg_job *job)
815*4882a593Smuzhiyun {
816*4882a593Smuzhiyun 	if (scsi_is_fc_rport(job->dev))
817*4882a593Smuzhiyun 		return dev_to_rport(job->dev);
818*4882a593Smuzhiyun 	return NULL;
819*4882a593Smuzhiyun }
820*4882a593Smuzhiyun 
821*4882a593Smuzhiyun #endif /* SCSI_TRANSPORT_FC_H */
822