Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  FiberChannel transport specific attributes exported to sysfs.
0004  *
0005  *  Copyright (c) 2003 Silicon Graphics, Inc.  All rights reserved.
0006  *  Copyright (C) 2004-2007   James Smart, Emulex Corporation
0007  *    Rewrite for host, target, device, and remote port attributes,
0008  *    statistics, and service functions...
0009  */
0010 #ifndef SCSI_TRANSPORT_FC_H
0011 #define SCSI_TRANSPORT_FC_H
0012 
0013 #include <linux/sched.h>
0014 #include <linux/bsg-lib.h>
0015 #include <asm/unaligned.h>
0016 #include <scsi/scsi.h>
0017 #include <scsi/scsi_netlink.h>
0018 #include <scsi/scsi_host.h>
0019 
0020 struct scsi_transport_template;
0021 
0022 /*
0023  * FC Port definitions - Following FC HBAAPI guidelines
0024  *
0025  * Note: Not all binary values for the different fields match HBAAPI.
0026  *  Instead, we use densely packed ordinal values or enums.
0027  *  We get away with this as we never present the actual binary values
0028  *  externally. For sysfs, we always present the string that describes
0029  *  the value. Thus, an admin doesn't need a magic HBAAPI decoder ring
0030  *  to understand the values. The HBAAPI user-space library is free to
0031  *  convert the strings into the HBAAPI-specified binary values.
0032  *
0033  * Note: Not all HBAAPI-defined values are contained in the definitions
0034  *  below. Those not appropriate to an fc_host (e.g. FCP initiator) have
0035  *  been removed.
0036  */
0037 
0038 /*
0039  * fc_port_type: If you alter this, you also need to alter scsi_transport_fc.c
0040  * (for the ascii descriptions).
0041  */
0042 enum fc_port_type {
0043     FC_PORTTYPE_UNKNOWN,
0044     FC_PORTTYPE_OTHER,
0045     FC_PORTTYPE_NOTPRESENT,
0046     FC_PORTTYPE_NPORT,      /* Attached to FPort */
0047     FC_PORTTYPE_NLPORT,     /* (Public) Loop w/ FLPort */
0048     FC_PORTTYPE_LPORT,      /* (Private) Loop w/o FLPort */
0049     FC_PORTTYPE_PTP,        /* Point to Point w/ another NPort */
0050     FC_PORTTYPE_NPIV,       /* VPORT based on NPIV */
0051 };
0052 
0053 
0054 /*
0055  * fc_port_state: If you alter this, you also need to alter scsi_transport_fc.c
0056  * (for the ascii descriptions).
0057  */
0058 enum fc_port_state {
0059     FC_PORTSTATE_UNKNOWN,
0060     FC_PORTSTATE_NOTPRESENT,
0061     FC_PORTSTATE_ONLINE,
0062     FC_PORTSTATE_OFFLINE,       /* User has taken Port Offline */
0063     FC_PORTSTATE_BLOCKED,
0064     FC_PORTSTATE_BYPASSED,
0065     FC_PORTSTATE_DIAGNOSTICS,
0066     FC_PORTSTATE_LINKDOWN,
0067     FC_PORTSTATE_ERROR,
0068     FC_PORTSTATE_LOOPBACK,
0069     FC_PORTSTATE_DELETED,
0070     FC_PORTSTATE_MARGINAL,
0071 };
0072 
0073 
0074 /*
0075  * fc_vport_state: If you alter this, you also need to alter
0076  * scsi_transport_fc.c (for the ascii descriptions).
0077  */
0078 enum fc_vport_state {
0079     FC_VPORT_UNKNOWN,
0080     FC_VPORT_ACTIVE,
0081     FC_VPORT_DISABLED,
0082     FC_VPORT_LINKDOWN,
0083     FC_VPORT_INITIALIZING,
0084     FC_VPORT_NO_FABRIC_SUPP,
0085     FC_VPORT_NO_FABRIC_RSCS,
0086     FC_VPORT_FABRIC_LOGOUT,
0087     FC_VPORT_FABRIC_REJ_WWN,
0088     FC_VPORT_FAILED,
0089 };
0090 
0091 
0092 
0093 /*
0094  * FC Classes of Service
0095  * Note: values are not enumerated, as they can be "or'd" together
0096  * for reporting (e.g. report supported_classes). If you alter this list,
0097  * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
0098  */
0099 #define FC_COS_UNSPECIFIED      0
0100 #define FC_COS_CLASS1           2
0101 #define FC_COS_CLASS2           4
0102 #define FC_COS_CLASS3           8
0103 #define FC_COS_CLASS4           0x10
0104 #define FC_COS_CLASS6           0x40
0105 
0106 /*
0107  * FC Port Speeds
0108  * Note: values are not enumerated, as they can be "or'd" together
0109  * for reporting (e.g. report supported_speeds). If you alter this list,
0110  * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
0111  */
0112 #define FC_PORTSPEED_UNKNOWN        0 /* Unknown - transceiver
0113                          incapable of reporting */
0114 #define FC_PORTSPEED_1GBIT      1
0115 #define FC_PORTSPEED_2GBIT      2
0116 #define FC_PORTSPEED_10GBIT     4
0117 #define FC_PORTSPEED_4GBIT      8
0118 #define FC_PORTSPEED_8GBIT      0x10
0119 #define FC_PORTSPEED_16GBIT     0x20
0120 #define FC_PORTSPEED_32GBIT     0x40
0121 #define FC_PORTSPEED_20GBIT     0x80
0122 #define FC_PORTSPEED_40GBIT     0x100
0123 #define FC_PORTSPEED_50GBIT     0x200
0124 #define FC_PORTSPEED_100GBIT        0x400
0125 #define FC_PORTSPEED_25GBIT     0x800
0126 #define FC_PORTSPEED_64GBIT     0x1000
0127 #define FC_PORTSPEED_128GBIT        0x2000
0128 #define FC_PORTSPEED_256GBIT        0x4000
0129 #define FC_PORTSPEED_NOT_NEGOTIATED (1 << 15) /* Speed not established */
0130 
0131 /*
0132  * fc_tgtid_binding_type: If you alter this, you also need to alter
0133  * scsi_transport_fc.c (for the ascii descriptions).
0134  */
0135 enum fc_tgtid_binding_type  {
0136     FC_TGTID_BIND_NONE,
0137     FC_TGTID_BIND_BY_WWPN,
0138     FC_TGTID_BIND_BY_WWNN,
0139     FC_TGTID_BIND_BY_ID,
0140 };
0141 
0142 /*
0143  * FC Port Roles
0144  * Note: values are not enumerated, as they can be "or'd" together
0145  * for reporting (e.g. report roles). If you alter this list,
0146  * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
0147  */
0148 #define FC_PORT_ROLE_UNKNOWN            0x00
0149 #define FC_PORT_ROLE_FCP_TARGET         0x01
0150 #define FC_PORT_ROLE_FCP_INITIATOR      0x02
0151 #define FC_PORT_ROLE_IP_PORT            0x04
0152 #define FC_PORT_ROLE_FCP_DUMMY_INITIATOR    0x08
0153 #define FC_PORT_ROLE_NVME_INITIATOR     0x10
0154 #define FC_PORT_ROLE_NVME_TARGET        0x20
0155 #define FC_PORT_ROLE_NVME_DISCOVERY     0x40
0156 
0157 /* The following are for compatibility */
0158 #define FC_RPORT_ROLE_UNKNOWN           FC_PORT_ROLE_UNKNOWN
0159 #define FC_RPORT_ROLE_FCP_TARGET        FC_PORT_ROLE_FCP_TARGET
0160 #define FC_RPORT_ROLE_FCP_INITIATOR     FC_PORT_ROLE_FCP_INITIATOR
0161 #define FC_RPORT_ROLE_IP_PORT           FC_PORT_ROLE_IP_PORT
0162 
0163 
0164 /* Macro for use in defining Virtual Port attributes */
0165 #define FC_VPORT_ATTR(_name,_mode,_show,_store)     \
0166 struct device_attribute dev_attr_vport_##_name =    \
0167     __ATTR(_name,_mode,_show,_store)
0168 
0169 /*
0170  * fc_vport_identifiers: This set of data contains all elements
0171  * to uniquely identify and instantiate a FC virtual port.
0172  *
0173  * Notes:
0174  *   symbolic_name: The driver is to append the symbolic_name string data
0175  *      to the symbolic_node_name data that it generates by default.
0176  *      the resulting combination should then be registered with the switch.
0177  *      It is expected that things like Xen may stuff a VM title into
0178  *      this field.
0179  */
0180 #define FC_VPORT_SYMBOLIC_NAMELEN       64
0181 struct fc_vport_identifiers {
0182     u64 node_name;
0183     u64 port_name;
0184     u32 roles;
0185     bool disable;
0186     enum fc_port_type vport_type;   /* only FC_PORTTYPE_NPIV allowed */
0187     char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
0188 };
0189 
0190 /*
0191  * FC Virtual Port Attributes
0192  *
0193  * This structure exists for each FC port is a virtual FC port. Virtual
0194  * ports share the physical link with the Physical port. Each virtual
0195  * ports has a unique presence on the SAN, and may be instantiated via
0196  * NPIV, Virtual Fabrics, or via additional ALPAs. As the vport is a
0197  * unique presence, each vport has it's own view of the fabric,
0198  * authentication privilege, and priorities.
0199  *
0200  * A virtual port may support 1 or more FC4 roles. Typically it is a
0201  * FCP Initiator. It could be a FCP Target, or exist sole for an IP over FC
0202  * roles. FC port attributes for the vport will be reported on any
0203  * fc_host class object allocated for an FCP Initiator.
0204  *
0205  * --
0206  *
0207  * Fixed attributes are not expected to change. The driver is
0208  * expected to set these values after receiving the fc_vport structure
0209  * via the vport_create() call from the transport.
0210  * The transport fully manages all get functions w/o driver interaction.
0211  *
0212  * Dynamic attributes are expected to change. The driver participates
0213  * in all get/set operations via functions provided by the driver.
0214  *
0215  * Private attributes are transport-managed values. They are fully
0216  * managed by the transport w/o driver interaction.
0217  */
0218 
0219 struct fc_vport {
0220     /* Fixed Attributes */
0221 
0222     /* Dynamic Attributes */
0223 
0224     /* Private (Transport-managed) Attributes */
0225     enum fc_vport_state vport_state;
0226     enum fc_vport_state vport_last_state;
0227     u64 node_name;
0228     u64 port_name;
0229     u32 roles;
0230     u32 vport_id;       /* Admin Identifier for the vport */
0231     enum fc_port_type vport_type;
0232     char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
0233 
0234     /* exported data */
0235     void *dd_data;          /* Used for driver-specific storage */
0236 
0237     /* internal data */
0238     struct Scsi_Host *shost;    /* Physical Port Parent */
0239     unsigned int channel;
0240     u32 number;
0241     u8 flags;
0242     struct list_head peers;
0243     struct device dev;
0244     struct work_struct vport_delete_work;
0245 } __attribute__((aligned(sizeof(unsigned long))));
0246 
0247 /* bit field values for struct fc_vport "flags" field: */
0248 #define FC_VPORT_CREATING       0x01
0249 #define FC_VPORT_DELETING       0x02
0250 #define FC_VPORT_DELETED        0x04
0251 #define FC_VPORT_DEL            0x06    /* Any DELETE state */
0252 
0253 #define dev_to_vport(d)             \
0254     container_of(d, struct fc_vport, dev)
0255 #define transport_class_to_vport(dev)       \
0256     dev_to_vport(dev->parent)
0257 #define vport_to_shost(v)           \
0258     (v->shost)
0259 #define vport_to_shost_channel(v)       \
0260     (v->channel)
0261 #define vport_to_parent(v)          \
0262     (v->dev.parent)
0263 
0264 
0265 /* Error return codes for vport_create() callback */
0266 #define VPCERR_UNSUPPORTED      -ENOSYS     /* no driver/adapter
0267                                support */
0268 #define VPCERR_BAD_WWN          -ENOTUNIQ   /* driver validation
0269                                of WWNs failed */
0270 #define VPCERR_NO_FABRIC_SUPP       -EOPNOTSUPP /* Fabric connection
0271                                is loop or the
0272                                Fabric Port does
0273                                not support NPIV */
0274 
0275 /*
0276  * fc_rport_identifiers: This set of data contains all elements
0277  * to uniquely identify a remote FC port. The driver uses this data
0278  * to report the existence of a remote FC port in the topology. Internally,
0279  * the transport uses this data for attributes and to manage consistent
0280  * target id bindings.
0281  */
0282 struct fc_rport_identifiers {
0283     u64 node_name;
0284     u64 port_name;
0285     u32 port_id;
0286     u32 roles;
0287 };
0288 
0289 /*
0290  * Fabric Performance Impact Notification Statistics
0291  */
0292 struct fc_fpin_stats {
0293     /* Delivery */
0294     u64 dn;
0295     u64 dn_unknown;
0296     u64 dn_timeout;
0297     u64 dn_unable_to_route;
0298     u64 dn_device_specific;
0299 
0300     /* Link Integrity */
0301     u64 li;
0302     u64 li_failure_unknown;
0303     u64 li_link_failure_count;
0304     u64 li_loss_of_sync_count;
0305     u64 li_loss_of_signals_count;
0306     u64 li_prim_seq_err_count;
0307     u64 li_invalid_tx_word_count;
0308     u64 li_invalid_crc_count;
0309     u64 li_device_specific;
0310 
0311     /* Congestion/Peer Congestion */
0312     u64 cn;
0313     u64 cn_clear;
0314     u64 cn_lost_credit;
0315     u64 cn_credit_stall;
0316     u64 cn_oversubscription;
0317     u64 cn_device_specific;
0318 };
0319 
0320 /* Macro for use in defining Remote Port attributes */
0321 #define FC_RPORT_ATTR(_name,_mode,_show,_store)             \
0322 struct device_attribute dev_attr_rport_##_name =    \
0323     __ATTR(_name,_mode,_show,_store)
0324 
0325 
0326 /*
0327  * FC Remote Port Attributes
0328  *
0329  * This structure exists for each remote FC port that a LLDD notifies
0330  * the subsystem of.  A remote FC port may or may not be a SCSI Target,
0331  * also be a SCSI initiator, IP endpoint, etc. As such, the remote
0332  * port is considered a separate entity, independent of "role" (such
0333  * as scsi target).
0334  *
0335  * --
0336  *
0337  * Attributes are based on HBAAPI V2.0 definitions. Only those
0338  * attributes that are determinable by the local port (aka Host)
0339  * are contained.
0340  *
0341  * Fixed attributes are not expected to change. The driver is
0342  * expected to set these values after successfully calling
0343  * fc_remote_port_add(). The transport fully manages all get functions
0344  * w/o driver interaction.
0345  *
0346  * Dynamic attributes are expected to change. The driver participates
0347  * in all get/set operations via functions provided by the driver.
0348  *
0349  * Private attributes are transport-managed values. They are fully
0350  * managed by the transport w/o driver interaction.
0351  */
0352 
0353 struct fc_rport {   /* aka fc_starget_attrs */
0354     /* Fixed Attributes */
0355     u32 maxframe_size;
0356     u32 supported_classes;
0357 
0358     /* Dynamic Attributes */
0359     u32 dev_loss_tmo;   /* Remote Port loss timeout in seconds. */
0360     struct fc_fpin_stats fpin_stats;
0361 
0362     /* Private (Transport-managed) Attributes */
0363     u64 node_name;
0364     u64 port_name;
0365     u32 port_id;
0366     u32 roles;
0367     enum fc_port_state port_state;  /* Will only be ONLINE or UNKNOWN */
0368     u32 scsi_target_id;
0369     u32 fast_io_fail_tmo;
0370 
0371     /* exported data */
0372     void *dd_data;          /* Used for driver-specific storage */
0373 
0374     /* internal data */
0375     unsigned int channel;
0376     u32 number;
0377     u8 flags;
0378     struct list_head peers;
0379     struct device dev;
0380     struct delayed_work dev_loss_work;
0381     struct work_struct scan_work;
0382     struct delayed_work fail_io_work;
0383     struct work_struct stgt_delete_work;
0384     struct work_struct rport_delete_work;
0385     struct request_queue *rqst_q;   /* bsg support */
0386 } __attribute__((aligned(sizeof(unsigned long))));
0387 
0388 /* bit field values for struct fc_rport "flags" field: */
0389 #define FC_RPORT_DEVLOSS_PENDING    0x01
0390 #define FC_RPORT_SCAN_PENDING       0x02
0391 #define FC_RPORT_FAST_FAIL_TIMEDOUT 0x04
0392 #define FC_RPORT_DEVLOSS_CALLBK_DONE    0x08
0393 
0394 #define dev_to_rport(d)             \
0395     container_of(d, struct fc_rport, dev)
0396 #define transport_class_to_rport(dev)   \
0397     dev_to_rport(dev->parent)
0398 #define rport_to_shost(r)           \
0399     dev_to_shost(r->dev.parent)
0400 
0401 /*
0402  * FC SCSI Target Attributes
0403  *
0404  * The SCSI Target is considered an extension of a remote port (as
0405  * a remote port can be more than a SCSI Target). Within the scsi
0406  * subsystem, we leave the Target as a separate entity. Doing so
0407  * provides backward compatibility with prior FC transport api's,
0408  * and lets remote ports be handled entirely within the FC transport
0409  * and independently from the scsi subsystem. The drawback is that
0410  * some data will be duplicated.
0411  */
0412 
0413 struct fc_starget_attrs {   /* aka fc_target_attrs */
0414     /* Dynamic Attributes */
0415     u64 node_name;
0416     u64 port_name;
0417     u32 port_id;
0418 };
0419 
0420 #define fc_starget_node_name(x) \
0421     (((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
0422 #define fc_starget_port_name(x) \
0423     (((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
0424 #define fc_starget_port_id(x) \
0425     (((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
0426 
0427 #define starget_to_rport(s)         \
0428     scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL
0429 
0430 
0431 /*
0432  * FC Local Port (Host) Statistics
0433  */
0434 
0435 /* FC Statistics - Following FC HBAAPI v2.0 guidelines */
0436 struct fc_host_statistics {
0437     /* port statistics */
0438     u64 seconds_since_last_reset;
0439     u64 tx_frames;
0440     u64 tx_words;
0441     u64 rx_frames;
0442     u64 rx_words;
0443     u64 lip_count;
0444     u64 nos_count;
0445     u64 error_frames;
0446     u64 dumped_frames;
0447     u64 link_failure_count;
0448     u64 loss_of_sync_count;
0449     u64 loss_of_signal_count;
0450     u64 prim_seq_protocol_err_count;
0451     u64 invalid_tx_word_count;
0452     u64 invalid_crc_count;
0453 
0454     /* fc4 statistics  (only FCP supported currently) */
0455     u64 fcp_input_requests;
0456     u64 fcp_output_requests;
0457     u64 fcp_control_requests;
0458     u64 fcp_input_megabytes;
0459     u64 fcp_output_megabytes;
0460     u64 fcp_packet_alloc_failures;  /* fcp packet allocation failures */
0461     u64 fcp_packet_aborts;      /* fcp packet aborted */
0462     u64 fcp_frame_alloc_failures;   /* fcp frame allocation failures */
0463 
0464     /* fc exches statistics */
0465     u64 fc_no_free_exch;        /* no free exch memory */
0466     u64 fc_no_free_exch_xid;    /* no free exch id */
0467     u64 fc_xid_not_found;       /* exch not found for a response */
0468     u64 fc_xid_busy;        /* exch exist for new a request */
0469     u64 fc_seq_not_found;       /* seq is not found for exchange */
0470     u64 fc_non_bls_resp;        /* a non BLS response frame with
0471                        a sequence responder in new exch */
0472     /* Host Congestion Signals */
0473     u64 cn_sig_warn;
0474     u64 cn_sig_alarm;
0475 };
0476 
0477 
0478 /*
0479  * FC Event Codes - Polled and Async, following FC HBAAPI v2.0 guidelines
0480  */
0481 
0482 /*
0483  * fc_host_event_code: If you alter this, you also need to alter
0484  * scsi_transport_fc.c (for the ascii descriptions).
0485  */
0486 enum fc_host_event_code  {
0487     FCH_EVT_LIP         = 0x1,
0488     FCH_EVT_LINKUP          = 0x2,
0489     FCH_EVT_LINKDOWN        = 0x3,
0490     FCH_EVT_LIPRESET        = 0x4,
0491     FCH_EVT_RSCN            = 0x5,
0492     FCH_EVT_ADAPTER_CHANGE      = 0x103,
0493     FCH_EVT_PORT_UNKNOWN        = 0x200,
0494     FCH_EVT_PORT_OFFLINE        = 0x201,
0495     FCH_EVT_PORT_ONLINE     = 0x202,
0496     FCH_EVT_PORT_FABRIC     = 0x204,
0497     FCH_EVT_LINK_UNKNOWN        = 0x500,
0498     FCH_EVT_LINK_FPIN       = 0x501,
0499     FCH_EVT_VENDOR_UNIQUE       = 0xffff,
0500 };
0501 
0502 
0503 /*
0504  * FC Local Port (Host) Attributes
0505  *
0506  * Attributes are based on HBAAPI V2.0 definitions.
0507  * Note: OSDeviceName is determined by user-space library
0508  *
0509  * Fixed attributes are not expected to change. The driver is
0510  * expected to set these values after successfully calling scsi_add_host().
0511  * The transport fully manages all get functions w/o driver interaction.
0512  *
0513  * Dynamic attributes are expected to change. The driver participates
0514  * in all get/set operations via functions provided by the driver.
0515  *
0516  * Private attributes are transport-managed values. They are fully
0517  * managed by the transport w/o driver interaction.
0518  */
0519 
0520 #define FC_VENDOR_IDENTIFIER        8
0521 #define FC_FC4_LIST_SIZE        32
0522 #define FC_SYMBOLIC_NAME_SIZE       256
0523 #define FC_VERSION_STRING_SIZE      64
0524 #define FC_SERIAL_NUMBER_SIZE       64
0525 
0526 struct fc_host_attrs {
0527     /* Fixed Attributes */
0528     u64 node_name;
0529     u64 port_name;
0530     u64 permanent_port_name;
0531     u32 supported_classes;
0532     u8  supported_fc4s[FC_FC4_LIST_SIZE];
0533     u32 supported_speeds;
0534     u32 maxframe_size;
0535     u16 max_npiv_vports;
0536     u32 max_ct_payload;
0537     u32 num_ports;
0538     u32 num_discovered_ports;
0539     u32 bootbios_state;
0540     char serial_number[FC_SERIAL_NUMBER_SIZE];
0541     char manufacturer[FC_SERIAL_NUMBER_SIZE];
0542     char model[FC_SYMBOLIC_NAME_SIZE];
0543     char model_description[FC_SYMBOLIC_NAME_SIZE];
0544     char hardware_version[FC_VERSION_STRING_SIZE];
0545     char driver_version[FC_VERSION_STRING_SIZE];
0546     char firmware_version[FC_VERSION_STRING_SIZE];
0547     char optionrom_version[FC_VERSION_STRING_SIZE];
0548     char vendor_identifier[FC_VENDOR_IDENTIFIER];
0549     char bootbios_version[FC_SYMBOLIC_NAME_SIZE];
0550 
0551 
0552     /* Dynamic Attributes */
0553     u32 port_id;
0554     enum fc_port_type port_type;
0555     enum fc_port_state port_state;
0556     u8  active_fc4s[FC_FC4_LIST_SIZE];
0557     u32 speed;
0558     u64 fabric_name;
0559     char symbolic_name[FC_SYMBOLIC_NAME_SIZE];
0560     char system_hostname[FC_SYMBOLIC_NAME_SIZE];
0561     u32 dev_loss_tmo;
0562     struct fc_fpin_stats fpin_stats;
0563 
0564     /* Private (Transport-managed) Attributes */
0565     enum fc_tgtid_binding_type  tgtid_bind_type;
0566 
0567     /* internal data */
0568     struct list_head rports;
0569     struct list_head rport_bindings;
0570     struct list_head vports;
0571     u32 next_rport_number;
0572     u32 next_target_id;
0573     u32 next_vport_number;
0574     u16 npiv_vports_inuse;
0575 
0576     /* work queues for rport state manipulation */
0577     char work_q_name[20];
0578     struct workqueue_struct *work_q;
0579     char devloss_work_q_name[20];
0580     struct workqueue_struct *devloss_work_q;
0581 
0582     /* bsg support */
0583     struct request_queue *rqst_q;
0584 
0585     /* FDMI support version*/
0586     u8 fdmi_version;
0587 };
0588 
0589 #define shost_to_fc_host(x) \
0590     ((struct fc_host_attrs *)(x)->shost_data)
0591 
0592 #define fc_host_node_name(x) \
0593     (((struct fc_host_attrs *)(x)->shost_data)->node_name)
0594 #define fc_host_port_name(x)    \
0595     (((struct fc_host_attrs *)(x)->shost_data)->port_name)
0596 #define fc_host_permanent_port_name(x)  \
0597     (((struct fc_host_attrs *)(x)->shost_data)->permanent_port_name)
0598 #define fc_host_supported_classes(x)    \
0599     (((struct fc_host_attrs *)(x)->shost_data)->supported_classes)
0600 #define fc_host_supported_fc4s(x)   \
0601     (((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s)
0602 #define fc_host_supported_speeds(x) \
0603     (((struct fc_host_attrs *)(x)->shost_data)->supported_speeds)
0604 #define fc_host_maxframe_size(x)    \
0605     (((struct fc_host_attrs *)(x)->shost_data)->maxframe_size)
0606 #define fc_host_max_npiv_vports(x)  \
0607     (((struct fc_host_attrs *)(x)->shost_data)->max_npiv_vports)
0608 #define fc_host_serial_number(x)    \
0609     (((struct fc_host_attrs *)(x)->shost_data)->serial_number)
0610 #define fc_host_manufacturer(x) \
0611     (((struct fc_host_attrs *)(x)->shost_data)->manufacturer)
0612 #define fc_host_model(x)    \
0613     (((struct fc_host_attrs *)(x)->shost_data)->model)
0614 #define fc_host_model_description(x)    \
0615     (((struct fc_host_attrs *)(x)->shost_data)->model_description)
0616 #define fc_host_hardware_version(x) \
0617     (((struct fc_host_attrs *)(x)->shost_data)->hardware_version)
0618 #define fc_host_driver_version(x)   \
0619     (((struct fc_host_attrs *)(x)->shost_data)->driver_version)
0620 #define fc_host_firmware_version(x) \
0621     (((struct fc_host_attrs *)(x)->shost_data)->firmware_version)
0622 #define fc_host_optionrom_version(x)    \
0623     (((struct fc_host_attrs *)(x)->shost_data)->optionrom_version)
0624 #define fc_host_port_id(x)  \
0625     (((struct fc_host_attrs *)(x)->shost_data)->port_id)
0626 #define fc_host_port_type(x)    \
0627     (((struct fc_host_attrs *)(x)->shost_data)->port_type)
0628 #define fc_host_port_state(x)   \
0629     (((struct fc_host_attrs *)(x)->shost_data)->port_state)
0630 #define fc_host_active_fc4s(x)  \
0631     (((struct fc_host_attrs *)(x)->shost_data)->active_fc4s)
0632 #define fc_host_speed(x)    \
0633     (((struct fc_host_attrs *)(x)->shost_data)->speed)
0634 #define fc_host_fabric_name(x)  \
0635     (((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
0636 #define fc_host_symbolic_name(x)    \
0637     (((struct fc_host_attrs *)(x)->shost_data)->symbolic_name)
0638 #define fc_host_system_hostname(x)  \
0639     (((struct fc_host_attrs *)(x)->shost_data)->system_hostname)
0640 #define fc_host_tgtid_bind_type(x) \
0641     (((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
0642 #define fc_host_rports(x) \
0643     (((struct fc_host_attrs *)(x)->shost_data)->rports)
0644 #define fc_host_rport_bindings(x) \
0645     (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings)
0646 #define fc_host_vports(x) \
0647     (((struct fc_host_attrs *)(x)->shost_data)->vports)
0648 #define fc_host_next_rport_number(x) \
0649     (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number)
0650 #define fc_host_next_target_id(x) \
0651     (((struct fc_host_attrs *)(x)->shost_data)->next_target_id)
0652 #define fc_host_next_vport_number(x) \
0653     (((struct fc_host_attrs *)(x)->shost_data)->next_vport_number)
0654 #define fc_host_npiv_vports_inuse(x)    \
0655     (((struct fc_host_attrs *)(x)->shost_data)->npiv_vports_inuse)
0656 #define fc_host_work_q_name(x) \
0657     (((struct fc_host_attrs *)(x)->shost_data)->work_q_name)
0658 #define fc_host_work_q(x) \
0659     (((struct fc_host_attrs *)(x)->shost_data)->work_q)
0660 #define fc_host_devloss_work_q_name(x) \
0661     (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q_name)
0662 #define fc_host_devloss_work_q(x) \
0663     (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q)
0664 #define fc_host_dev_loss_tmo(x) \
0665     (((struct fc_host_attrs *)(x)->shost_data)->dev_loss_tmo)
0666 #define fc_host_max_ct_payload(x)  \
0667     (((struct fc_host_attrs *)(x)->shost_data)->max_ct_payload)
0668 #define fc_host_vendor_identifier(x)  \
0669     (((struct fc_host_attrs *)(x)->shost_data)->vendor_identifier)
0670 #define fc_host_num_discovered_ports(x)  \
0671     (((struct fc_host_attrs *)(x)->shost_data)->num_discovered_ports)
0672 #define fc_host_num_ports(x)  \
0673     (((struct fc_host_attrs *)(x)->shost_data)->num_ports)
0674 #define fc_host_bootbios_version(x)  \
0675     (((struct fc_host_attrs *)(x)->shost_data)->bootbios_version)
0676 #define fc_host_bootbios_state(x)  \
0677     (((struct fc_host_attrs *)(x)->shost_data)->bootbios_state)
0678 
0679 /* The functions by which the transport class and the driver communicate */
0680 struct fc_function_template {
0681     void    (*get_rport_dev_loss_tmo)(struct fc_rport *);
0682     void    (*set_rport_dev_loss_tmo)(struct fc_rport *, u32);
0683 
0684     void    (*get_starget_node_name)(struct scsi_target *);
0685     void    (*get_starget_port_name)(struct scsi_target *);
0686     void    (*get_starget_port_id)(struct scsi_target *);
0687 
0688     void    (*get_host_port_id)(struct Scsi_Host *);
0689     void    (*get_host_port_type)(struct Scsi_Host *);
0690     void    (*get_host_port_state)(struct Scsi_Host *);
0691     void    (*get_host_active_fc4s)(struct Scsi_Host *);
0692     void    (*get_host_speed)(struct Scsi_Host *);
0693     void    (*get_host_fabric_name)(struct Scsi_Host *);
0694     void    (*get_host_symbolic_name)(struct Scsi_Host *);
0695     void    (*set_host_system_hostname)(struct Scsi_Host *);
0696 
0697     struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
0698     void    (*reset_fc_host_stats)(struct Scsi_Host *);
0699 
0700     int (*issue_fc_host_lip)(struct Scsi_Host *);
0701 
0702     void    (*dev_loss_tmo_callbk)(struct fc_rport *);
0703     void    (*terminate_rport_io)(struct fc_rport *);
0704 
0705     void    (*set_vport_symbolic_name)(struct fc_vport *);
0706     int     (*vport_create)(struct fc_vport *, bool);
0707     int (*vport_disable)(struct fc_vport *, bool);
0708     int     (*vport_delete)(struct fc_vport *);
0709 
0710     /* bsg support */
0711     int (*bsg_request)(struct bsg_job *);
0712     int (*bsg_timeout)(struct bsg_job *);
0713 
0714     /* allocation lengths for host-specific data */
0715     u32             dd_fcrport_size;
0716     u32             dd_fcvport_size;
0717     u32             dd_bsg_size;
0718 
0719     /*
0720      * The driver sets these to tell the transport class it
0721      * wants the attributes displayed in sysfs.  If the show_ flag
0722      * is not set, the attribute will be private to the transport
0723      * class
0724      */
0725 
0726     /* remote port fixed attributes */
0727     unsigned long   show_rport_maxframe_size:1;
0728     unsigned long   show_rport_supported_classes:1;
0729     unsigned long   show_rport_dev_loss_tmo:1;
0730 
0731     /*
0732      * target dynamic attributes
0733      * These should all be "1" if the driver uses the remote port
0734      * add/delete functions (so attributes reflect rport values).
0735      */
0736     unsigned long   show_starget_node_name:1;
0737     unsigned long   show_starget_port_name:1;
0738     unsigned long   show_starget_port_id:1;
0739 
0740     /* host fixed attributes */
0741     unsigned long   show_host_node_name:1;
0742     unsigned long   show_host_port_name:1;
0743     unsigned long   show_host_permanent_port_name:1;
0744     unsigned long   show_host_supported_classes:1;
0745     unsigned long   show_host_supported_fc4s:1;
0746     unsigned long   show_host_supported_speeds:1;
0747     unsigned long   show_host_maxframe_size:1;
0748     unsigned long   show_host_serial_number:1;
0749     unsigned long   show_host_manufacturer:1;
0750     unsigned long   show_host_model:1;
0751     unsigned long   show_host_model_description:1;
0752     unsigned long   show_host_hardware_version:1;
0753     unsigned long   show_host_driver_version:1;
0754     unsigned long   show_host_firmware_version:1;
0755     unsigned long   show_host_optionrom_version:1;
0756     /* host dynamic attributes */
0757     unsigned long   show_host_port_id:1;
0758     unsigned long   show_host_port_type:1;
0759     unsigned long   show_host_port_state:1;
0760     unsigned long   show_host_active_fc4s:1;
0761     unsigned long   show_host_speed:1;
0762     unsigned long   show_host_fabric_name:1;
0763     unsigned long   show_host_symbolic_name:1;
0764     unsigned long   show_host_system_hostname:1;
0765 
0766     unsigned long   disable_target_scan:1;
0767 };
0768 
0769 /**
0770  * fc_remote_port_chkready - called to validate the remote port state
0771  *   prior to initiating io to the port.
0772  *
0773  * Returns a scsi result code that can be returned by the LLDD.
0774  *
0775  * @rport:  remote port to be checked
0776  **/
0777 static inline int
0778 fc_remote_port_chkready(struct fc_rport *rport)
0779 {
0780     int result;
0781 
0782     switch (rport->port_state) {
0783     case FC_PORTSTATE_ONLINE:
0784     case FC_PORTSTATE_MARGINAL:
0785         if (rport->roles & FC_PORT_ROLE_FCP_TARGET)
0786             result = 0;
0787         else if (rport->flags & FC_RPORT_DEVLOSS_PENDING)
0788             result = DID_IMM_RETRY << 16;
0789         else
0790             result = DID_NO_CONNECT << 16;
0791         break;
0792     case FC_PORTSTATE_BLOCKED:
0793         if (rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT)
0794             result = DID_TRANSPORT_FAILFAST << 16;
0795         else
0796             result = DID_IMM_RETRY << 16;
0797         break;
0798     default:
0799         result = DID_NO_CONNECT << 16;
0800         break;
0801     }
0802     return result;
0803 }
0804 
0805 static inline u64 wwn_to_u64(const u8 *wwn)
0806 {
0807     return get_unaligned_be64(wwn);
0808 }
0809 
0810 static inline void u64_to_wwn(u64 inm, u8 *wwn)
0811 {
0812     put_unaligned_be64(inm, wwn);
0813 }
0814 
0815 /**
0816  * fc_vport_set_state() - called to set a vport's state. Saves the old state,
0817  *   excepting the transitory states of initializing and sending the ELS
0818  *   traffic to instantiate the vport on the link.
0819  *
0820  * Assumes the driver has surrounded this with the proper locking to ensure
0821  * a coherent state change.
0822  *
0823  * @vport:  virtual port whose state is changing
0824  * @new_state:  new state
0825  **/
0826 static inline void
0827 fc_vport_set_state(struct fc_vport *vport, enum fc_vport_state new_state)
0828 {
0829     if ((new_state != FC_VPORT_UNKNOWN) &&
0830         (new_state != FC_VPORT_INITIALIZING))
0831         vport->vport_last_state = vport->vport_state;
0832     vport->vport_state = new_state;
0833 }
0834 
0835 struct scsi_transport_template *fc_attach_transport(
0836             struct fc_function_template *);
0837 void fc_release_transport(struct scsi_transport_template *);
0838 void fc_remove_host(struct Scsi_Host *);
0839 struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
0840             int channel, struct fc_rport_identifiers  *ids);
0841 void fc_remote_port_delete(struct fc_rport  *rport);
0842 void fc_remote_port_rolechg(struct fc_rport  *rport, u32 roles);
0843 int scsi_is_fc_rport(const struct device *);
0844 u32 fc_get_event_number(void);
0845 void fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
0846         enum fc_host_event_code event_code, u32 event_data);
0847 void fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
0848         u32 data_len, char *data_buf, u64 vendor_id);
0849 struct fc_rport *fc_find_rport_by_wwpn(struct Scsi_Host *shost, u64 wwpn);
0850 void fc_host_post_fc_event(struct Scsi_Host *shost, u32 event_number,
0851         enum fc_host_event_code event_code,
0852         u32 data_len, char *data_buf, u64 vendor_id);
0853     /* Note: when specifying vendor_id to fc_host_post_vendor_event()
0854      *   or fc_host_post_fc_event(), be sure to read the Vendor Type
0855      *   and ID formatting requirements specified in scsi_netlink.h
0856      * Note: when calling fc_host_post_fc_event(), vendor_id may be
0857      *   specified as 0.
0858      */
0859 void fc_host_fpin_rcv(struct Scsi_Host *shost, u32 fpin_len, char *fpin_buf);
0860 struct fc_vport *fc_vport_create(struct Scsi_Host *shost, int channel,
0861         struct fc_vport_identifiers *);
0862 int fc_vport_terminate(struct fc_vport *vport);
0863 int fc_block_rport(struct fc_rport *rport);
0864 int fc_block_scsi_eh(struct scsi_cmnd *cmnd);
0865 enum blk_eh_timer_return fc_eh_timed_out(struct scsi_cmnd *scmd);
0866 bool fc_eh_should_retry_cmd(struct scsi_cmnd *scmd);
0867 
0868 static inline struct Scsi_Host *fc_bsg_to_shost(struct bsg_job *job)
0869 {
0870     if (scsi_is_host_device(job->dev))
0871         return dev_to_shost(job->dev);
0872     return rport_to_shost(dev_to_rport(job->dev));
0873 }
0874 
0875 static inline struct fc_rport *fc_bsg_to_rport(struct bsg_job *job)
0876 {
0877     if (scsi_is_fc_rport(job->dev))
0878         return dev_to_rport(job->dev);
0879     return NULL;
0880 }
0881 
0882 #endif /* SCSI_TRANSPORT_FC_H */