/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Copyright(c) 2007 Intel Corporation. All rights reserved.3*4* Maintained at www.Open-FCoE.org5*/67#ifndef _LIBFC_H_8#define _LIBFC_H_910#include <linux/timer.h>11#include <linux/if.h>12#include <linux/percpu.h>13#include <linux/refcount.h>1415#include <scsi/scsi_transport.h>16#include <scsi/scsi_transport_fc.h>17#include <scsi/scsi_bsg_fc.h>1819#include <scsi/fc/fc_fcp.h>20#include <scsi/fc/fc_ns.h>21#include <scsi/fc/fc_ms.h>22#include <scsi/fc/fc_els.h>23#include <scsi/fc/fc_gs.h>2425#include <scsi/fc_frame.h>2627#define FC_FC4_PROV_SIZE (FC_TYPE_FCP + 1) /* size of tables */2829/*30* libfc error codes31*/32#define FC_NO_ERR 0 /* no error */33#define FC_EX_TIMEOUT 1 /* Exchange timeout */34#define FC_EX_CLOSED 2 /* Exchange closed */35#define FC_EX_ALLOC_ERR 3 /* Exchange allocation failed */36#define FC_EX_XMIT_ERR 4 /* Exchange transmit failed */37#define FC_EX_ELS_RJT 5 /* ELS rejected */38#define FC_EX_INV_LOGIN 6 /* Login not completed */39#define FC_EX_SEQ_ERR 6 /* Exchange sequence error */4041/**42* enum fc_lport_state - Local port states43* @LPORT_ST_DISABLED: Disabled44* @LPORT_ST_FLOGI: Fabric login (FLOGI) sent45* @LPORT_ST_DNS: Waiting for name server remote port to become ready46* @LPORT_ST_RNN_ID: Register port name by ID (RNN_ID) sent47* @LPORT_ST_RSNN_NN: Waiting for host symbolic node name48* @LPORT_ST_RSPN_ID: Waiting for host symbolic port name49* @LPORT_ST_RFT_ID: Register Fibre Channel types by ID (RFT_ID) sent50* @LPORT_ST_RFF_ID: Register FC-4 Features by ID (RFF_ID) sent51* @LPORT_ST_FDMI: Waiting for mgmt server rport to become ready52* @LPORT_ST_RHBA: Register HBA53* @LPORT_ST_RPA: Register Port Attributes54* @LPORT_ST_DHBA: Deregister HBA55* @LPORT_ST_DPRT: Deregister Port56* @LPORT_ST_SCR: State Change Register (SCR) sent57* @LPORT_ST_READY: Ready for use58* @LPORT_ST_LOGO: Local port logout (LOGO) sent59* @LPORT_ST_RESET: Local port reset60*/61enum fc_lport_state {62LPORT_ST_DISABLED = 0,63LPORT_ST_FLOGI,64LPORT_ST_DNS,65LPORT_ST_RNN_ID,66LPORT_ST_RSNN_NN,67LPORT_ST_RSPN_ID,68LPORT_ST_RFT_ID,69LPORT_ST_RFF_ID,70LPORT_ST_FDMI,71LPORT_ST_RHBA,72LPORT_ST_RPA,73LPORT_ST_DHBA,74LPORT_ST_DPRT,75LPORT_ST_SCR,76LPORT_ST_READY,77LPORT_ST_LOGO,78LPORT_ST_RESET79};8081enum fc_disc_event {82DISC_EV_NONE = 0,83DISC_EV_SUCCESS,84DISC_EV_FAILED85};8687/**88* enum fc_rport_state - Remote port states89* @RPORT_ST_INIT: Initialized90* @RPORT_ST_FLOGI: Waiting for FLOGI completion for point-to-multipoint91* @RPORT_ST_PLOGI_WAIT: Waiting for peer to login for point-to-multipoint92* @RPORT_ST_PLOGI: Waiting for PLOGI completion93* @RPORT_ST_PRLI: Waiting for PRLI completion94* @RPORT_ST_RTV: Waiting for RTV completion95* @RPORT_ST_READY: Ready for use96* @RPORT_ST_ADISC: Discover Address sent97* @RPORT_ST_DELETE: Remote port being deleted98*/99enum fc_rport_state {100RPORT_ST_INIT,101RPORT_ST_FLOGI,102RPORT_ST_PLOGI_WAIT,103RPORT_ST_PLOGI,104RPORT_ST_PRLI,105RPORT_ST_RTV,106RPORT_ST_READY,107RPORT_ST_ADISC,108RPORT_ST_DELETE,109};110111/**112* struct fc_disc_port - temporary discovery port to hold rport identifiers113* @lp: Fibre Channel host port instance114* @peers: Node for list management during discovery and RSCN processing115* @rport_work: Work struct for starting the rport state machine116* @port_id: Port ID of the discovered port117*/118struct fc_disc_port {119struct fc_lport *lp;120struct list_head peers;121struct work_struct rport_work;122u32 port_id;123};124125/**126* enum fc_rport_event - Remote port events127* @RPORT_EV_NONE: No event128* @RPORT_EV_READY: Remote port is ready for use129* @RPORT_EV_FAILED: State machine failed, remote port is not ready130* @RPORT_EV_STOP: Remote port has been stopped131* @RPORT_EV_LOGO: Remote port logout (LOGO) sent132*/133enum fc_rport_event {134RPORT_EV_NONE = 0,135RPORT_EV_READY,136RPORT_EV_FAILED,137RPORT_EV_STOP,138RPORT_EV_LOGO139};140141struct fc_rport_priv;142143/**144* struct fc_rport_operations - Operations for a remote port145* @event_callback: Function to be called for remote port events146*/147struct fc_rport_operations {148void (*event_callback)(struct fc_lport *, struct fc_rport_priv *,149enum fc_rport_event);150};151152/**153* struct fc_rport_libfc_priv - libfc internal information about a remote port154* @local_port: The associated local port155* @rp_state: Indicates READY for I/O or DELETE when blocked156* @flags: REC and RETRY supported flags157* @e_d_tov: Error detect timeout value (in msec)158* @r_a_tov: Resource allocation timeout value (in msec)159*/160struct fc_rport_libfc_priv {161struct fc_lport *local_port;162enum fc_rport_state rp_state;163u16 flags;164#define FC_RP_FLAGS_REC_SUPPORTED (1 << 0)165#define FC_RP_FLAGS_RETRY (1 << 1)166#define FC_RP_STARTED (1 << 2)167#define FC_RP_FLAGS_CONF_REQ (1 << 3)168unsigned int e_d_tov;169unsigned int r_a_tov;170};171172/**173* struct fc_rport_priv - libfc remote port and discovery info174* @local_port: The associated local port175* @rport: The FC transport remote port176* @kref: Reference counter177* @rp_state: Enumeration that tracks progress of PLOGI, PRLI,178* and RTV exchanges179* @ids: The remote port identifiers and roles180* @flags: STARTED, REC and RETRY_SUPPORTED flags181* @max_seq: Maximum number of concurrent sequences182* @disc_id: The discovery identifier183* @maxframe_size: The maximum frame size184* @retries: The retry count for the current state185* @major_retries: The retry count for the entire PLOGI/PRLI state machine186* @e_d_tov: Error detect timeout value (in msec)187* @r_a_tov: Resource allocation timeout value (in msec)188* @rp_mutex: The mutex that protects the remote port189* @retry_work: Handle for retries190* @lld_event_callback: Callback when READY, FAILED or LOGO states complete191* @prli_count: Count of open PRLI sessions in providers192* @rcu: Structure used for freeing in an RCU-safe manner193*/194struct fc_rport_priv {195struct fc_lport *local_port;196struct fc_rport *rport;197struct kref kref;198enum fc_rport_state rp_state;199struct fc_rport_identifiers ids;200u16 flags;201u16 max_seq;202u16 disc_id;203u16 maxframe_size;204unsigned int retries;205unsigned int major_retries;206unsigned int e_d_tov;207unsigned int r_a_tov;208struct mutex rp_mutex;209struct delayed_work retry_work;210enum fc_rport_event event;211struct fc_rport_operations *ops;212struct list_head peers;213struct work_struct event_work;214u32 supported_classes;215u16 prli_count;216struct rcu_head rcu;217u16 sp_features;218u8 spp_type;219void (*lld_event_callback)(struct fc_lport *,220struct fc_rport_priv *,221enum fc_rport_event);222};223224/**225* struct fc_stats - fc stats structure226* @SecondsSinceLastReset: Seconds since the last reset227* @TxFrames: Number of transmitted frames228* @TxWords: Number of transmitted words229* @RxFrames: Number of received frames230* @RxWords: Number of received words231* @ErrorFrames: Number of received error frames232* @DumpedFrames: Number of dumped frames233* @FcpPktAllocFails: Number of fcp packet allocation failures234* @FcpPktAborts: Number of fcp packet aborts235* @FcpFrameAllocFails: Number of fcp frame allocation failures236* @LinkFailureCount: Number of link failures237* @LossOfSignalCount: Number for signal losses238* @InvalidTxWordCount: Number of invalid transmitted words239* @InvalidCRCCount: Number of invalid CRCs240* @InputRequests: Number of input requests241* @OutputRequests: Number of output requests242* @ControlRequests: Number of control requests243* @InputBytes: Number of received bytes244* @OutputBytes: Number of transmitted bytes245* @VLinkFailureCount: Number of virtual link failures246* @MissDiscAdvCount: Number of missing FIP discovery advertisement247*/248struct fc_stats {249u64 SecondsSinceLastReset;250u64 TxFrames;251u64 TxWords;252u64 RxFrames;253u64 RxWords;254u64 ErrorFrames;255u64 DumpedFrames;256u64 FcpPktAllocFails;257u64 FcpPktAborts;258u64 FcpFrameAllocFails;259u64 LinkFailureCount;260u64 LossOfSignalCount;261u64 InvalidTxWordCount;262u64 InvalidCRCCount;263u64 InputRequests;264u64 OutputRequests;265u64 ControlRequests;266u64 InputBytes;267u64 OutputBytes;268u64 VLinkFailureCount;269u64 MissDiscAdvCount;270};271272/**273* struct fc_seq_els_data - ELS data used for passing ELS specific responses274* @reason: The reason for rejection275* @explan: The explanation of the rejection276*277* Mainly used by the exchange manager layer.278*/279struct fc_seq_els_data {280enum fc_els_rjt_reason reason;281enum fc_els_rjt_explan explan;282};283284/**285* struct fc_fcp_pkt - FCP request structure (one for each scsi_cmnd request)286* @lp: The associated local port287* @state: The state of the I/O288* @ref_cnt: Reference count289* @scsi_pkt_lock: Lock to protect the SCSI packet (must be taken before the290* host_lock if both are to be held at the same time)291* @cmd: The SCSI command (set and clear with the host_lock held)292* @list: Tracks queued commands (accessed with the host_lock held)293* @timer: The command timer294* @tm_done: Completion indicator295* @wait_for_comp: Indicator to wait for completion of the I/O (in jiffies)296* @timer_delay: FCP packet timer delay in jiffies297* @data_len: The length of the data298* @cdb_cmd: The CDB command299* @xfer_len: The transfer length300* @xfer_ddp: Indicates if this transfer used DDP (XID of the exchange301* will be set here if DDP was setup)302* @xfer_contig_end: The offset into the buffer if the buffer is contiguous303* (Tx and Rx)304* @max_payload: The maximum payload size (in bytes)305* @io_status: SCSI result (upper 24 bits)306* @cdb_status: CDB status307* @status_code: FCP I/O status308* @scsi_comp_flags: Completion flags (bit 3 Underrun bit 2: overrun)309* @req_flags: Request flags (bit 0: read bit:1 write)310* @scsi_resid: SCSI residule length311* @rport: The remote port that the SCSI command is targeted at312* @seq_ptr: The sequence that will carry the SCSI command313* @recov_retry: Number of recovery retries314* @recov_seq: The sequence for REC or SRR315*/316struct fc_fcp_pkt {317spinlock_t scsi_pkt_lock;318refcount_t ref_cnt;319320/* SCSI command and data transfer information */321u32 data_len;322323/* SCSI I/O related information */324struct scsi_cmnd *cmd;325struct list_head list;326327/* Housekeeping information */328struct fc_lport *lp;329u8 state;330331/* SCSI/FCP return status */332u8 cdb_status;333u8 status_code;334u8 scsi_comp_flags;335u32 io_status;336u32 req_flags;337u32 scsi_resid;338339/* Transport related veriables */340size_t xfer_len;341struct fcp_cmnd cdb_cmd;342u32 xfer_contig_end;343u16 max_payload;344u16 xfer_ddp;345346/* Associated structures */347struct fc_rport *rport;348struct fc_seq *seq_ptr;349350/* Timeout/error related information */351struct timer_list timer;352int wait_for_comp;353int timer_delay;354u32 recov_retry;355struct fc_seq *recov_seq;356struct completion tm_done;357} ____cacheline_aligned_in_smp;358359/*360* @fsp should be tested and set under the scsi_pkt_queue lock361*/362struct libfc_cmd_priv {363struct fc_fcp_pkt *fsp;364u32 resid_len;365u8 status;366};367368/*369* Structure and function definitions for managing Fibre Channel Exchanges370* and Sequences371*372* fc_exch holds state for one exchange and links to its active sequence.373*374* fc_seq holds the state for an individual sequence.375*/376377struct fc_exch_mgr;378struct fc_exch_mgr_anchor;379extern u16 fc_cpu_mask; /* cpu mask for possible cpus */380381/**382* struct fc_seq - FC sequence383* @id: The sequence ID384* @ssb_stat: Status flags for the sequence status block (SSB)385* @cnt: Number of frames sent so far386* @rec_data: FC-4 value for REC387*/388struct fc_seq {389u8 id;390u16 ssb_stat;391u16 cnt;392u32 rec_data;393};394395#define FC_EX_DONE (1 << 0) /* ep is completed */396#define FC_EX_RST_CLEANUP (1 << 1) /* reset is forcing completion */397#define FC_EX_QUARANTINE (1 << 2) /* exch is quarantined */398399/**400* struct fc_exch - Fibre Channel Exchange401* @em: Exchange manager402* @pool: Exchange pool403* @state: The exchange's state404* @xid: The exchange ID405* @ex_list: Handle used by the EM to track free exchanges406* @ex_lock: Lock that protects the exchange407* @ex_refcnt: Reference count408* @timeout_work: Handle for timeout handler409* @lp: The local port that this exchange is on410* @oxid: Originator's exchange ID411* @rxid: Responder's exchange ID412* @oid: Originator's FCID413* @sid: Source FCID414* @did: Destination FCID415* @esb_stat: ESB exchange status416* @r_a_tov: Resource allocation time out value (in msecs)417* @seq_id: The next sequence ID to use418* @encaps: encapsulation information for lower-level driver419* @f_ctl: F_CTL flags for the sequence420* @fh_type: The frame type421* @class: The class of service422* @seq: The sequence in use on this exchange423* @resp_active: Number of tasks that are concurrently executing @resp().424* @resp_task: If @resp_active > 0, either the task executing @resp(), the425* task that has been interrupted to execute the soft-IRQ426* executing @resp() or NULL if more than one task is executing427* @resp concurrently.428* @resp_wq: Waitqueue for the tasks waiting on @resp_active.429* @resp: Callback for responses on this exchange430* @destructor: Called when destroying the exchange431* @arg: Passed as a void pointer to the resp() callback432*433* Locking notes: The ex_lock protects following items:434* state, esb_stat, f_ctl, seq.ssb_stat435* seq_id436* sequence allocation437*/438struct fc_exch {439spinlock_t ex_lock;440atomic_t ex_refcnt;441enum fc_class class;442struct fc_exch_mgr *em;443struct fc_exch_pool *pool;444struct list_head ex_list;445struct fc_lport *lp;446u32 esb_stat;447u8 state;448u8 fh_type;449u8 seq_id;450u8 encaps;451u16 xid;452u16 oxid;453u16 rxid;454u32 oid;455u32 sid;456u32 did;457u32 r_a_tov;458u32 f_ctl;459struct fc_seq seq;460int resp_active;461struct task_struct *resp_task;462wait_queue_head_t resp_wq;463void (*resp)(struct fc_seq *, struct fc_frame *, void *);464void *arg;465void (*destructor)(struct fc_seq *, void *);466struct delayed_work timeout_work;467} ____cacheline_aligned_in_smp;468#define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)469470471struct libfc_function_template {472/*473* Interface to send a FC frame474*475* STATUS: REQUIRED476*/477int (*frame_send)(struct fc_lport *, struct fc_frame *);478479/*480* Interface to send ELS/CT frames481*482* STATUS: OPTIONAL483*/484struct fc_seq *(*elsct_send)(struct fc_lport *, u32 did,485struct fc_frame *, unsigned int op,486void (*resp)(struct fc_seq *,487struct fc_frame *, void *arg),488void *arg, u32 timer_msec);489490/*491* Sets up the DDP context for a given exchange id on the given492* scatterlist if LLD supports DDP for large receive.493*494* STATUS: OPTIONAL495*/496int (*ddp_setup)(struct fc_lport *, u16, struct scatterlist *,497unsigned int);498/*499* Completes the DDP transfer and returns the length of data DDPed500* for the given exchange id.501*502* STATUS: OPTIONAL503*/504int (*ddp_done)(struct fc_lport *, u16);505/*506* Sets up the DDP context for a given exchange id on the given507* scatterlist if LLD supports DDP for target.508*509* STATUS: OPTIONAL510*/511int (*ddp_target)(struct fc_lport *, u16, struct scatterlist *,512unsigned int);513/*514* Allow LLD to fill its own Link Error Status Block515*516* STATUS: OPTIONAL517*/518void (*get_lesb)(struct fc_lport *, struct fc_els_lesb *lesb);519520/*521* Reset an exchange manager, completing all sequences and exchanges.522* If s_id is non-zero, reset only exchanges originating from that FID.523* If d_id is non-zero, reset only exchanges sending to that FID.524*525* STATUS: OPTIONAL526*/527void (*exch_mgr_reset)(struct fc_lport *, u32 s_id, u32 d_id);528529/*530* Set the local port FC_ID.531*532* This may be provided by the LLD to allow it to be533* notified when the local port is assigned a FC-ID.534*535* The frame, if non-NULL, is the incoming frame with the536* FLOGI LS_ACC or FLOGI, and may contain the granted MAC537* address for the LLD. The frame pointer may be NULL if538* no MAC is associated with this assignment (LOGO or PLOGI).539*540* If FC_ID is non-zero, r_a_tov and e_d_tov must be valid.541*542* Note: this is called with the local port mutex held.543*544* STATUS: OPTIONAL545*/546void (*lport_set_port_id)(struct fc_lport *, u32 port_id,547struct fc_frame *);548549/*550* Callback routine after the remote port is logged in551*552* STATUS: OPTIONAL553*/554void (*rport_event_callback)(struct fc_lport *,555struct fc_rport_priv *,556enum fc_rport_event);557558/*559* Send a fcp cmd from fsp pkt.560* Called with the SCSI host lock unlocked and irqs disabled.561*562* The resp handler is called when FCP_RSP received.563*564* STATUS: OPTIONAL565*/566int (*fcp_cmd_send)(struct fc_lport *, struct fc_fcp_pkt *,567void (*resp)(struct fc_seq *, struct fc_frame *,568void *));569570/*571* Cleanup the FCP layer, used during link down and reset572*573* STATUS: OPTIONAL574*/575void (*fcp_cleanup)(struct fc_lport *);576577/*578* Abort all I/O on a local port579*580* STATUS: OPTIONAL581*/582void (*fcp_abort_io)(struct fc_lport *);583584/*585* Receive a request for the discovery layer.586*587* STATUS: OPTIONAL588*/589void (*disc_recv_req)(struct fc_lport *, struct fc_frame *);590591/*592* Start discovery for a local port.593*594* STATUS: OPTIONAL595*/596void (*disc_start)(void (*disc_callback)(struct fc_lport *,597enum fc_disc_event),598struct fc_lport *);599600/*601* Stop discovery for a given lport. This will remove602* all discovered rports603*604* STATUS: OPTIONAL605*/606void (*disc_stop) (struct fc_lport *);607608/*609* Stop discovery for a given lport. This will block610* until all discovered rports are deleted from the611* FC transport class612*613* STATUS: OPTIONAL614*/615void (*disc_stop_final) (struct fc_lport *);616};617618/**619* struct fc_disc - Discovery context620* @retry_count: Number of retries621* @pending: 1 if discovery is pending, 0 if not622* @requested: 1 if discovery has been requested, 0 if not623* @seq_count: Number of sequences used for discovery624* @buf_len: Length of the discovery buffer625* @disc_id: Discovery ID626* @rports: List of discovered remote ports627* @priv: Private pointer for use by discovery code628* @disc_mutex: Mutex that protects the discovery context629* @partial_buf: Partial name buffer (if names are returned630* in multiple frames)631* @disc_work: handle for delayed work context632* @disc_callback: Callback routine called when discovery completes633*/634struct fc_disc {635unsigned char retry_count;636unsigned char pending;637unsigned char requested;638unsigned short seq_count;639unsigned char buf_len;640u16 disc_id;641642struct list_head rports;643void *priv;644struct mutex disc_mutex;645struct fc_gpn_ft_resp partial_buf;646struct delayed_work disc_work;647648void (*disc_callback)(struct fc_lport *,649enum fc_disc_event);650};651652/*653* Local port notifier and events.654*/655extern struct blocking_notifier_head fc_lport_notifier_head;656enum fc_lport_event {657FC_LPORT_EV_ADD,658FC_LPORT_EV_DEL,659};660661/**662* struct fc_lport - Local port663* @host: The SCSI host associated with a local port664* @ema_list: Exchange manager anchor list665* @dns_rdata: The directory server remote port666* @ms_rdata: The management server remote port667* @ptp_rdata: Point to point remote port668* @scsi_priv: FCP layer internal data669* @disc: Discovery context670* @vports: Child vports if N_Port671* @vport: Parent vport if VN_Port672* @tt: Libfc function template673* @link_up: Link state (1 = link up, 0 = link down)674* @qfull: Queue state (1 queue is full, 0 queue is not full)675* @state: Identifies the state676* @boot_time: Timestamp indicating when the local port came online677* @host_stats: SCSI host statistics678* @stats: FC local port stats (TODO separate libfc LLD stats)679* @retry_count: Number of retries in the current state680* @port_id: FC Port ID681* @wwpn: World Wide Port Name682* @wwnn: World Wide Node Name683* @service_params: Common service parameters684* @e_d_tov: Error detection timeout value685* @r_a_tov: Resource allocation timeout value686* @rnid_gen: RNID information687* @sg_supp: Indicates if scatter gather is supported688* @seq_offload: Indicates if sequence offload is supported689* @crc_offload: Indicates if CRC offload is supported690* @lro_enabled: Indicates if large receive offload is supported691* @does_npiv: Supports multiple vports692* @npiv_enabled: Switch/fabric allows NPIV693* @mfs: The maximum Fibre Channel payload size694* @max_retry_count: The maximum retry attempts695* @max_rport_retry_count: The maximum remote port retry attempts696* @rport_priv_size: Size needed by driver after struct fc_rport_priv697* @lro_xid: The maximum XID for LRO698* @lso_max: The maximum large offload send size699* @fcts: FC-4 type mask700* @lp_mutex: Mutex to protect the local port701* @list: Linkage on list of vport peers702* @retry_work: Handle to local port for delayed retry context703* @prov: Pointers available for use by passive FC-4 providers704* @lport_list: Linkage on module-wide list of local ports705*/706struct fc_lport {707/* Associations */708struct Scsi_Host *host;709struct list_head ema_list;710struct fc_rport_priv *dns_rdata;711struct fc_rport_priv *ms_rdata;712struct fc_rport_priv *ptp_rdata;713void *scsi_priv;714struct fc_disc disc;715716/* Virtual port information */717struct list_head vports;718struct fc_vport *vport;719720/* Operational Information */721struct libfc_function_template tt;722u8 link_up;723u8 qfull;724u16 vlan;725enum fc_lport_state state;726unsigned long boot_time;727struct fc_host_statistics host_stats;728struct fc_stats __percpu *stats;729u8 retry_count;730731/* Fabric information */732u32 port_id;733u64 wwpn;734u64 wwnn;735unsigned int service_params;736unsigned int e_d_tov;737unsigned int r_a_tov;738struct fc_els_rnid_gen rnid_gen;739740/* Capabilities */741u32 sg_supp:1;742u32 seq_offload:1;743u32 crc_offload:1;744u32 lro_enabled:1;745u32 does_npiv:1;746u32 npiv_enabled:1;747u32 point_to_multipoint:1;748u32 fdmi_enabled:1;749u32 mfs;750u8 max_retry_count;751u8 max_rport_retry_count;752u16 rport_priv_size;753u16 link_speed;754u16 link_supported_speeds;755u16 lro_xid;756unsigned int lso_max;757struct fc_ns_fts fcts;758759/* Miscellaneous */760struct mutex lp_mutex;761struct list_head list;762struct delayed_work retry_work;763void *prov[FC_FC4_PROV_SIZE];764struct list_head lport_list;765};766767/**768* struct fc4_prov - FC-4 provider registration769* @prli: Handler for incoming PRLI770* @prlo: Handler for session reset771* @recv: Handler for incoming request772* @module: Pointer to module. May be NULL.773*/774struct fc4_prov {775int (*prli)(struct fc_rport_priv *, u32 spp_len,776const struct fc_els_spp *spp_in,777struct fc_els_spp *spp_out);778void (*prlo)(struct fc_rport_priv *);779void (*recv)(struct fc_lport *, struct fc_frame *);780struct module *module;781};782783/*784* Register FC-4 provider with libfc.785*/786int fc_fc4_register_provider(enum fc_fh_type type, struct fc4_prov *);787void fc_fc4_deregister_provider(enum fc_fh_type type, struct fc4_prov *);788789/*790* FC_LPORT HELPER FUNCTIONS791*****************************/792793/**794* fc_lport_test_ready() - Determine if a local port is in the READY state795* @lport: The local port to test796*797* Returns: %true if local port is in the READY state, %false otherwise798*/799static inline int fc_lport_test_ready(struct fc_lport *lport)800{801return lport->state == LPORT_ST_READY;802}803804/**805* fc_set_wwnn() - Set the World Wide Node Name of a local port806* @lport: The local port whose WWNN is to be set807* @wwnn: The new WWNN808*/809static inline void fc_set_wwnn(struct fc_lport *lport, u64 wwnn)810{811lport->wwnn = wwnn;812}813814/**815* fc_set_wwpn() - Set the World Wide Port Name of a local port816* @lport: The local port whose WWPN is to be set817* @wwpn: The new WWPN818*/819static inline void fc_set_wwpn(struct fc_lport *lport, u64 wwpn)820{821lport->wwpn = wwpn;822}823824/**825* fc_lport_state_enter() - Change a local port's state826* @lport: The local port whose state is to change827* @state: The new state828*/829static inline void fc_lport_state_enter(struct fc_lport *lport,830enum fc_lport_state state)831{832if (state != lport->state)833lport->retry_count = 0;834lport->state = state;835}836837/**838* fc_lport_init_stats() - Allocate per-CPU statistics for a local port839* @lport: The local port whose statistics are to be initialized840*841* Returns: %0 on success, %-ENOMEM on failure842*/843static inline int fc_lport_init_stats(struct fc_lport *lport)844{845lport->stats = alloc_percpu(struct fc_stats);846if (!lport->stats)847return -ENOMEM;848return 0;849}850851/**852* fc_lport_free_stats() - Free memory for a local port's statistics853* @lport: The local port whose statistics are to be freed854*/855static inline void fc_lport_free_stats(struct fc_lport *lport)856{857free_percpu(lport->stats);858}859860/**861* lport_priv() - Return the private data from a local port862* @lport: The local port whose private data is to be retrieved863*864* Returns: the local port's private data pointer865*/866static inline void *lport_priv(const struct fc_lport *lport)867{868return (void *)(lport + 1);869}870871/**872* libfc_host_alloc() - Allocate a Scsi_Host with room for a local port and873* LLD private data874* @sht: The SCSI host template875* @priv_size: Size of private data876*877* Returns: libfc lport878*/879static inline struct fc_lport *880libfc_host_alloc(const struct scsi_host_template *sht, int priv_size)881{882struct fc_lport *lport;883struct Scsi_Host *shost;884885shost = scsi_host_alloc(sht, sizeof(*lport) + priv_size);886if (!shost)887return NULL;888lport = shost_priv(shost);889lport->host = shost;890INIT_LIST_HEAD(&lport->ema_list);891INIT_LIST_HEAD(&lport->vports);892return lport;893}894895/*896* FC_FCP HELPER FUNCTIONS897*****************************/898static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)899{900if (fsp && fsp->cmd)901return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE;902return false;903}904905/*906* LOCAL PORT LAYER907*****************************/908int fc_lport_init(struct fc_lport *);909int fc_lport_destroy(struct fc_lport *);910int fc_fabric_logoff(struct fc_lport *);911int fc_fabric_login(struct fc_lport *);912void __fc_linkup(struct fc_lport *);913void fc_linkup(struct fc_lport *);914void __fc_linkdown(struct fc_lport *);915void fc_linkdown(struct fc_lport *);916void fc_vport_setlink(struct fc_lport *);917void fc_vports_linkchange(struct fc_lport *);918int fc_lport_config(struct fc_lport *);919int fc_lport_reset(struct fc_lport *);920void fc_lport_recv(struct fc_lport *lport, struct fc_frame *fp);921int fc_set_mfs(struct fc_lport *, u32 mfs);922struct fc_lport *libfc_vport_create(struct fc_vport *, int privsize);923struct fc_lport *fc_vport_id_lookup(struct fc_lport *, u32 port_id);924int fc_lport_bsg_request(struct bsg_job *);925void fc_lport_set_local_id(struct fc_lport *, u32 port_id);926void fc_lport_iterate(void (*func)(struct fc_lport *, void *), void *);927928/*929* REMOTE PORT LAYER930*****************************/931void fc_rport_terminate_io(struct fc_rport *);932struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,933u32 port_id);934struct fc_rport_priv *fc_rport_create(struct fc_lport *, u32);935void fc_rport_destroy(struct kref *kref);936int fc_rport_login(struct fc_rport_priv *rdata);937int fc_rport_logoff(struct fc_rport_priv *rdata);938void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp);939void fc_rport_flush_queue(void);940941/*942* DISCOVERY LAYER943*****************************/944void fc_disc_init(struct fc_lport *);945void fc_disc_config(struct fc_lport *, void *);946947static inline struct fc_lport *fc_disc_lport(struct fc_disc *disc)948{949return container_of(disc, struct fc_lport, disc);950}951952/*953* FCP LAYER954*****************************/955int fc_fcp_init(struct fc_lport *);956void fc_fcp_destroy(struct fc_lport *);957958/*959* SCSI INTERACTION LAYER960*****************************/961int fc_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);962int fc_eh_abort(struct scsi_cmnd *);963int fc_eh_device_reset(struct scsi_cmnd *);964int fc_eh_host_reset(struct scsi_cmnd *);965int fc_sdev_init(struct scsi_device *);966967/*968* ELS/CT interface969*****************************/970int fc_elsct_init(struct fc_lport *);971struct fc_seq *fc_elsct_send(struct fc_lport *, u32 did,972struct fc_frame *,973unsigned int op,974void (*resp)(struct fc_seq *,975struct fc_frame *,976void *arg),977void *arg, u32 timer_msec);978void fc_lport_flogi_resp(struct fc_seq *, struct fc_frame *, void *);979void fc_lport_logo_resp(struct fc_seq *, struct fc_frame *, void *);980void fc_fill_reply_hdr(struct fc_frame *, const struct fc_frame *,981enum fc_rctl, u32 parm_offset);982void fc_fill_hdr(struct fc_frame *, const struct fc_frame *,983enum fc_rctl, u32 f_ctl, u16 seq_cnt, u32 parm_offset);984985986/*987* EXCHANGE MANAGER LAYER988*****************************/989int fc_exch_init(struct fc_lport *);990void fc_exch_update_stats(struct fc_lport *lport);991struct fc_seq *fc_exch_seq_send(struct fc_lport *lport,992struct fc_frame *fp,993void (*resp)(struct fc_seq *,994struct fc_frame *fp,995void *arg),996void (*destructor)(struct fc_seq *, void *),997void *arg, u32 timer_msec);998void fc_seq_els_rsp_send(struct fc_frame *, enum fc_els_cmd,999struct fc_seq_els_data *);1000struct fc_seq *fc_seq_start_next(struct fc_seq *sp);1001void fc_seq_set_resp(struct fc_seq *sp,1002void (*resp)(struct fc_seq *, struct fc_frame *, void *),1003void *arg);1004struct fc_seq *fc_seq_assign(struct fc_lport *lport, struct fc_frame *fp);1005void fc_seq_release(struct fc_seq *sp);1006struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *,1007struct fc_exch_mgr *,1008bool (*match)(struct fc_frame *));1009void fc_exch_mgr_del(struct fc_exch_mgr_anchor *);1010int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst);1011struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *, enum fc_class class,1012u16 min_xid, u16 max_xid,1013bool (*match)(struct fc_frame *));1014void fc_exch_mgr_free(struct fc_lport *);1015void fc_exch_recv(struct fc_lport *, struct fc_frame *);1016void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);1017int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp, struct fc_frame *fp);1018int fc_seq_exch_abort(const struct fc_seq *, unsigned int timer_msec);1019void fc_exch_done(struct fc_seq *sp);10201021/*1022* Functions for fc_functions_template1023*/1024void fc_get_host_speed(struct Scsi_Host *);1025void fc_get_host_port_state(struct Scsi_Host *);1026void fc_set_rport_loss_tmo(struct fc_rport *, u32 timeout);1027struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *);10281029#endif /* _LIBFC_H_ */103010311032