linux/include/scsi/scsi_transport_fc.h

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 *  FiberChannel transport specific attributes exported to sysfs.
 *
 *  Copyright (c) 2003 Silicon Graphics, Inc.  All rights reserved.
 *  Copyright (C) 2004-2007   James Smart, Emulex Corporation
 *    Rewrite for host, target, device, and remote port attributes,
 *    statistics, and service functions...
 */
#ifndef SCSI_TRANSPORT_FC_H
#define SCSI_TRANSPORT_FC_H

#include <linux/sched.h>
#include <linux/bsg-lib.h>
#include <linux/unaligned.h>
#include <scsi/scsi.h>
#include <scsi/scsi_netlink.h>
#include <scsi/scsi_host.h>

struct scsi_transport_template;

/*
 * FC Port definitions - Following FC HBAAPI guidelines
 *
 * Note: Not all binary values for the different fields match HBAAPI.
 *  Instead, we use densely packed ordinal values or enums.
 *  We get away with this as we never present the actual binary values
 *  externally. For sysfs, we always present the string that describes
 *  the value. Thus, an admin doesn't need a magic HBAAPI decoder ring
 *  to understand the values. The HBAAPI user-space library is free to
 *  convert the strings into the HBAAPI-specified binary values.
 *
 * Note: Not all HBAAPI-defined values are contained in the definitions
 *  below. Those not appropriate to an fc_host (e.g. FCP initiator) have
 *  been removed.
 */

/*
 * fc_port_type: If you alter this, you also need to alter scsi_transport_fc.c
 * (for the ascii descriptions).
 */
enum fc_port_type {};


/*
 * fc_port_state: If you alter this, you also need to alter scsi_transport_fc.c
 * (for the ascii descriptions).
 */
enum fc_port_state {};


/*
 * fc_vport_state: If you alter this, you also need to alter
 * scsi_transport_fc.c (for the ascii descriptions).
 */
enum fc_vport_state {};



/*
 * FC Classes of Service
 * Note: values are not enumerated, as they can be "or'd" together
 * for reporting (e.g. report supported_classes). If you alter this list,
 * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
 */
#define FC_COS_UNSPECIFIED
#define FC_COS_CLASS1
#define FC_COS_CLASS2
#define FC_COS_CLASS3
#define FC_COS_CLASS4
#define FC_COS_CLASS6

/*
 * FC Port Speeds
 * Note: values are not enumerated, as they can be "or'd" together
 * for reporting (e.g. report supported_speeds). If you alter this list,
 * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
 */
#define FC_PORTSPEED_UNKNOWN
#define FC_PORTSPEED_1GBIT
#define FC_PORTSPEED_2GBIT
#define FC_PORTSPEED_10GBIT
#define FC_PORTSPEED_4GBIT
#define FC_PORTSPEED_8GBIT
#define FC_PORTSPEED_16GBIT
#define FC_PORTSPEED_32GBIT
#define FC_PORTSPEED_20GBIT
#define FC_PORTSPEED_40GBIT
#define FC_PORTSPEED_50GBIT
#define FC_PORTSPEED_100GBIT
#define FC_PORTSPEED_25GBIT
#define FC_PORTSPEED_64GBIT
#define FC_PORTSPEED_128GBIT
#define FC_PORTSPEED_256GBIT
#define FC_PORTSPEED_NOT_NEGOTIATED

/*
 * fc_tgtid_binding_type: If you alter this, you also need to alter
 * scsi_transport_fc.c (for the ascii descriptions).
 */
enum fc_tgtid_binding_type  {};

/*
 * FC Port Roles
 * Note: values are not enumerated, as they can be "or'd" together
 * for reporting (e.g. report roles). If you alter this list,
 * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
 */
#define FC_PORT_ROLE_UNKNOWN
#define FC_PORT_ROLE_FCP_TARGET
#define FC_PORT_ROLE_FCP_INITIATOR
#define FC_PORT_ROLE_IP_PORT
#define FC_PORT_ROLE_FCP_DUMMY_INITIATOR
#define FC_PORT_ROLE_NVME_INITIATOR
#define FC_PORT_ROLE_NVME_TARGET
#define FC_PORT_ROLE_NVME_DISCOVERY

/* The following are for compatibility */
#define FC_RPORT_ROLE_UNKNOWN
#define FC_RPORT_ROLE_FCP_TARGET
#define FC_RPORT_ROLE_FCP_INITIATOR
#define FC_RPORT_ROLE_IP_PORT


/* Macro for use in defining Virtual Port attributes */
#define FC_VPORT_ATTR(_name,_mode,_show,_store)

/*
 * fc_vport_identifiers: This set of data contains all elements
 * to uniquely identify and instantiate a FC virtual port.
 *
 * Notes:
 *   symbolic_name: The driver is to append the symbolic_name string data
 *      to the symbolic_node_name data that it generates by default.
 *      the resulting combination should then be registered with the switch.
 *      It is expected that things like Xen may stuff a VM title into
 *      this field.
 */
#define FC_VPORT_SYMBOLIC_NAMELEN
struct fc_vport_identifiers {};

/*
 * FC Virtual Port Attributes
 *
 * This structure exists for each FC port is a virtual FC port. Virtual
 * ports share the physical link with the Physical port. Each virtual
 * ports has a unique presence on the SAN, and may be instantiated via
 * NPIV, Virtual Fabrics, or via additional ALPAs. As the vport is a
 * unique presence, each vport has it's own view of the fabric,
 * authentication privilege, and priorities.
 *
 * A virtual port may support 1 or more FC4 roles. Typically it is a
 * FCP Initiator. It could be a FCP Target, or exist sole for an IP over FC
 * roles. FC port attributes for the vport will be reported on any
 * fc_host class object allocated for an FCP Initiator.
 *
 * --
 *
 * Fixed attributes are not expected to change. The driver is
 * expected to set these values after receiving the fc_vport structure
 * via the vport_create() call from the transport.
 * The transport fully manages all get functions w/o driver interaction.
 *
 * Dynamic attributes are expected to change. The driver participates
 * in all get/set operations via functions provided by the driver.
 *
 * Private attributes are transport-managed values. They are fully
 * managed by the transport w/o driver interaction.
 */

struct fc_vport {} __attribute__((aligned));

/* bit field values for struct fc_vport "flags" field: */
#define FC_VPORT_CREATING
#define FC_VPORT_DELETING
#define FC_VPORT_DELETED
#define FC_VPORT_DEL

#define dev_to_vport(d)
#define transport_class_to_vport(dev)
#define vport_to_shost(v)
#define vport_to_shost_channel(v)
#define vport_to_parent(v)


/* Error return codes for vport_create() callback */
#define VPCERR_UNSUPPORTED
#define VPCERR_BAD_WWN
#define VPCERR_NO_FABRIC_SUPP

/*
 * fc_rport_identifiers: This set of data contains all elements
 * to uniquely identify a remote FC port. The driver uses this data
 * to report the existence of a remote FC port in the topology. Internally,
 * the transport uses this data for attributes and to manage consistent
 * target id bindings.
 */
struct fc_rport_identifiers {};

/*
 * Fabric Performance Impact Notification Statistics
 */
struct fc_fpin_stats {};

/* Macro for use in defining Remote Port attributes */
#define FC_RPORT_ATTR(_name,_mode,_show,_store)


/*
 * FC Remote Port Attributes
 *
 * This structure exists for each remote FC port that a LLDD notifies
 * the subsystem of.  A remote FC port may or may not be a SCSI Target,
 * also be a SCSI initiator, IP endpoint, etc. As such, the remote
 * port is considered a separate entity, independent of "role" (such
 * as scsi target).
 *
 * --
 *
 * Attributes are based on HBAAPI V2.0 definitions. Only those
 * attributes that are determinable by the local port (aka Host)
 * are contained.
 *
 * Fixed attributes are not expected to change. The driver is
 * expected to set these values after successfully calling
 * fc_remote_port_add(). The transport fully manages all get functions
 * w/o driver interaction.
 *
 * Dynamic attributes are expected to change. The driver participates
 * in all get/set operations via functions provided by the driver.
 *
 * Private attributes are transport-managed values. They are fully
 * managed by the transport w/o driver interaction.
 */

struct fc_rport {} __attribute__((aligned));

/* bit field values for struct fc_rport "flags" field: */
#define FC_RPORT_DEVLOSS_PENDING
#define FC_RPORT_SCAN_PENDING
#define FC_RPORT_FAST_FAIL_TIMEDOUT
#define FC_RPORT_DEVLOSS_CALLBK_DONE

#define dev_to_rport(d)
#define transport_class_to_rport(dev)
#define rport_to_shost(r)

/*
 * FC SCSI Target Attributes
 *
 * The SCSI Target is considered an extension of a remote port (as
 * a remote port can be more than a SCSI Target). Within the scsi
 * subsystem, we leave the Target as a separate entity. Doing so
 * provides backward compatibility with prior FC transport api's,
 * and lets remote ports be handled entirely within the FC transport
 * and independently from the scsi subsystem. The drawback is that
 * some data will be duplicated.
 */

struct fc_starget_attrs {};

#define fc_starget_node_name(x)
#define fc_starget_port_name(x)
#define fc_starget_port_id(x)

#define starget_to_rport(s)


/*
 * FC Local Port (Host) Statistics
 */

/* FC Statistics - Following FC HBAAPI v2.0 guidelines */
struct fc_host_statistics {};


/*
 * FC Event Codes - Polled and Async, following FC HBAAPI v2.0 guidelines
 */

/*
 * fc_host_event_code: If you alter this, you also need to alter
 * scsi_transport_fc.c (for the ascii descriptions).
 */
enum fc_host_event_code  {};


/*
 * FC Local Port (Host) Attributes
 *
 * Attributes are based on HBAAPI V2.0 definitions.
 * Note: OSDeviceName is determined by user-space library
 *
 * Fixed attributes are not expected to change. The driver is
 * expected to set these values after successfully calling scsi_add_host().
 * The transport fully manages all get functions w/o driver interaction.
 *
 * Dynamic attributes are expected to change. The driver participates
 * in all get/set operations via functions provided by the driver.
 *
 * Private attributes are transport-managed values. They are fully
 * managed by the transport w/o driver interaction.
 */

#define FC_VENDOR_IDENTIFIER
#define FC_FC4_LIST_SIZE
#define FC_SYMBOLIC_NAME_SIZE
#define FC_VERSION_STRING_SIZE
#define FC_SERIAL_NUMBER_SIZE

struct fc_host_attrs {};

#define shost_to_fc_host(x)

#define fc_host_node_name(x)
#define fc_host_port_name(x)
#define fc_host_permanent_port_name(x)
#define fc_host_supported_classes(x)
#define fc_host_supported_fc4s(x)
#define fc_host_supported_speeds(x)
#define fc_host_maxframe_size(x)
#define fc_host_max_npiv_vports(x)
#define fc_host_serial_number(x)
#define fc_host_manufacturer(x)
#define fc_host_model(x)
#define fc_host_model_description(x)
#define fc_host_hardware_version(x)
#define fc_host_driver_version(x)
#define fc_host_firmware_version(x)
#define fc_host_optionrom_version(x)
#define fc_host_port_id(x)
#define fc_host_port_type(x)
#define fc_host_port_state(x)
#define fc_host_active_fc4s(x)
#define fc_host_speed(x)
#define fc_host_fabric_name(x)
#define fc_host_symbolic_name(x)
#define fc_host_system_hostname(x)
#define fc_host_tgtid_bind_type(x)
#define fc_host_rports(x)
#define fc_host_rport_bindings(x)
#define fc_host_vports(x)
#define fc_host_next_rport_number(x)
#define fc_host_next_target_id(x)
#define fc_host_next_vport_number(x)
#define fc_host_npiv_vports_inuse(x)
#define fc_host_work_q(x)
#define fc_host_devloss_work_q(x)
#define fc_host_dev_loss_tmo(x)
#define fc_host_max_ct_payload(x)
#define fc_host_vendor_identifier(x)
#define fc_host_num_discovered_ports(x)
#define fc_host_num_ports(x)
#define fc_host_bootbios_version(x)
#define fc_host_bootbios_state(x)

/* The functions by which the transport class and the driver communicate */
struct fc_function_template {};

/**
 * fc_remote_port_chkready - called to validate the remote port state
 *   prior to initiating io to the port.
 * @rport:	remote port to be checked
 *
 * Returns: a scsi result code that can be returned by the LLDD.
 **/
static inline int
fc_remote_port_chkready(struct fc_rport *rport)
{}

static inline u64 wwn_to_u64(const u8 *wwn)
{}

static inline void u64_to_wwn(u64 inm, u8 *wwn)
{}

/**
 * fc_vport_set_state() - called to set a vport's state. Saves the old state,
 *   excepting the transitory states of initializing and sending the ELS
 *   traffic to instantiate the vport on the link.
 *
 * Assumes the driver has surrounded this with the proper locking to ensure
 * a coherent state change.
 *
 * @vport:	virtual port whose state is changing
 * @new_state:  new state
 **/
static inline void
fc_vport_set_state(struct fc_vport *vport, enum fc_vport_state new_state)
{}

struct scsi_transport_template *fc_attach_transport(
			struct fc_function_template *);
void fc_release_transport(struct scsi_transport_template *);
void fc_remove_host(struct Scsi_Host *);
struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
			int channel, struct fc_rport_identifiers  *ids);
void fc_remote_port_delete(struct fc_rport  *rport);
void fc_remote_port_rolechg(struct fc_rport  *rport, u32 roles);
int scsi_is_fc_rport(const struct device *);
u32 fc_get_event_number(void);
void fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
		enum fc_host_event_code event_code, u32 event_data);
void fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
		u32 data_len, char *data_buf, u64 vendor_id);
struct fc_rport *fc_find_rport_by_wwpn(struct Scsi_Host *shost, u64 wwpn);
void fc_host_post_fc_event(struct Scsi_Host *shost, u32 event_number,
		enum fc_host_event_code event_code,
		u32 data_len, char *data_buf, u64 vendor_id);
	/* Note: when specifying vendor_id to fc_host_post_vendor_event()
	 *   or fc_host_post_fc_event(), be sure to read the Vendor Type
	 *   and ID formatting requirements specified in scsi_netlink.h
	 * Note: when calling fc_host_post_fc_event(), vendor_id may be
	 *   specified as 0.
	 */
void fc_host_fpin_rcv(struct Scsi_Host *shost, u32 fpin_len, char *fpin_buf,
		u8 event_acknowledge);
struct fc_vport *fc_vport_create(struct Scsi_Host *shost, int channel,
		struct fc_vport_identifiers *);
int fc_vport_terminate(struct fc_vport *vport);
int fc_block_rport(struct fc_rport *rport);
int fc_block_scsi_eh(struct scsi_cmnd *cmnd);
enum scsi_timeout_action fc_eh_timed_out(struct scsi_cmnd *scmd);
bool fc_eh_should_retry_cmd(struct scsi_cmnd *scmd);

static inline struct Scsi_Host *fc_bsg_to_shost(struct bsg_job *job)
{}

static inline struct fc_rport *fc_bsg_to_rport(struct bsg_job *job)
{}

#endif /* SCSI_TRANSPORT_FC_H */