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