Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright(c) 2007 Intel Corporation. All rights reserved.
0004  *
0005  * Maintained at www.Open-FCoE.org
0006  */
0007 
0008 #ifndef _LIBFC_H_
0009 #define _LIBFC_H_
0010 
0011 #include <linux/timer.h>
0012 #include <linux/if.h>
0013 #include <linux/percpu.h>
0014 #include <linux/refcount.h>
0015 
0016 #include <scsi/scsi_transport.h>
0017 #include <scsi/scsi_transport_fc.h>
0018 #include <scsi/scsi_bsg_fc.h>
0019 
0020 #include <scsi/fc/fc_fcp.h>
0021 #include <scsi/fc/fc_ns.h>
0022 #include <scsi/fc/fc_ms.h>
0023 #include <scsi/fc/fc_els.h>
0024 #include <scsi/fc/fc_gs.h>
0025 
0026 #include <scsi/fc_frame.h>
0027 
0028 #define FC_FC4_PROV_SIZE    (FC_TYPE_FCP + 1)   /* size of tables */
0029 
0030 /*
0031  * libfc error codes
0032  */
0033 #define FC_NO_ERR   0   /* no error */
0034 #define FC_EX_TIMEOUT   1   /* Exchange timeout */
0035 #define FC_EX_CLOSED    2   /* Exchange closed */
0036 #define FC_EX_ALLOC_ERR 3   /* Exchange allocation failed */
0037 #define FC_EX_XMIT_ERR  4   /* Exchange transmit failed */
0038 #define FC_EX_ELS_RJT   5   /* ELS rejected */
0039 #define FC_EX_INV_LOGIN 6   /* Login not completed */
0040 #define FC_EX_SEQ_ERR   6   /* Exchange sequence error */
0041 
0042 /**
0043  * enum fc_lport_state - Local port states
0044  * @LPORT_ST_DISABLED: Disabled
0045  * @LPORT_ST_FLOGI:    Fabric login (FLOGI) sent
0046  * @LPORT_ST_DNS:      Waiting for name server remote port to become ready
0047  * @LPORT_ST_RPN_ID:   Register port name by ID (RPN_ID) sent
0048  * @LPORT_ST_RFT_ID:   Register Fibre Channel types by ID (RFT_ID) sent
0049  * @LPORT_ST_RFF_ID:   Register FC-4 Features by ID (RFF_ID) sent
0050  * @LPORT_ST_FDMI:     Waiting for mgmt server rport to become ready
0051  * @LPORT_ST_RHBA:
0052  * @LPORT_ST_SCR:      State Change Register (SCR) sent
0053  * @LPORT_ST_READY:    Ready for use
0054  * @LPORT_ST_LOGO:     Local port logout (LOGO) sent
0055  * @LPORT_ST_RESET:    Local port reset
0056  */
0057 enum fc_lport_state {
0058     LPORT_ST_DISABLED = 0,
0059     LPORT_ST_FLOGI,
0060     LPORT_ST_DNS,
0061     LPORT_ST_RNN_ID,
0062     LPORT_ST_RSNN_NN,
0063     LPORT_ST_RSPN_ID,
0064     LPORT_ST_RFT_ID,
0065     LPORT_ST_RFF_ID,
0066     LPORT_ST_FDMI,
0067     LPORT_ST_RHBA,
0068     LPORT_ST_RPA,
0069     LPORT_ST_DHBA,
0070     LPORT_ST_DPRT,
0071     LPORT_ST_SCR,
0072     LPORT_ST_READY,
0073     LPORT_ST_LOGO,
0074     LPORT_ST_RESET
0075 };
0076 
0077 enum fc_disc_event {
0078     DISC_EV_NONE = 0,
0079     DISC_EV_SUCCESS,
0080     DISC_EV_FAILED
0081 };
0082 
0083 /**
0084  * enum fc_rport_state - Remote port states
0085  * @RPORT_ST_INIT:    Initialized
0086  * @RPORT_ST_FLOGI:   Waiting for FLOGI completion for point-to-multipoint
0087  * @RPORT_ST_PLOGI_WAIT:   Waiting for peer to login for point-to-multipoint
0088  * @RPORT_ST_PLOGI:   Waiting for PLOGI completion
0089  * @RPORT_ST_PRLI:    Waiting for PRLI completion
0090  * @RPORT_ST_RTV:     Waiting for RTV completion
0091  * @RPORT_ST_READY:   Ready for use
0092  * @RPORT_ST_ADISC:   Discover Address sent
0093  * @RPORT_ST_DELETE:  Remote port being deleted
0094 */
0095 enum fc_rport_state {
0096     RPORT_ST_INIT,
0097     RPORT_ST_FLOGI,
0098     RPORT_ST_PLOGI_WAIT,
0099     RPORT_ST_PLOGI,
0100     RPORT_ST_PRLI,
0101     RPORT_ST_RTV,
0102     RPORT_ST_READY,
0103     RPORT_ST_ADISC,
0104     RPORT_ST_DELETE,
0105 };
0106 
0107 /**
0108  * struct fc_disc_port - temporary discovery port to hold rport identifiers
0109  * @lp:         Fibre Channel host port instance
0110  * @peers:      Node for list management during discovery and RSCN processing
0111  * @rport_work: Work struct for starting the rport state machine
0112  * @port_id:    Port ID of the discovered port
0113  */
0114 struct fc_disc_port {
0115     struct fc_lport    *lp;
0116     struct list_head   peers;
0117     struct work_struct rport_work;
0118     u32        port_id;
0119 };
0120 
0121 /**
0122  * enum fc_rport_event - Remote port events
0123  * @RPORT_EV_NONE:   No event
0124  * @RPORT_EV_READY:  Remote port is ready for use
0125  * @RPORT_EV_FAILED: State machine failed, remote port is not ready
0126  * @RPORT_EV_STOP:   Remote port has been stopped
0127  * @RPORT_EV_LOGO:   Remote port logout (LOGO) sent
0128  */
0129 enum fc_rport_event {
0130     RPORT_EV_NONE = 0,
0131     RPORT_EV_READY,
0132     RPORT_EV_FAILED,
0133     RPORT_EV_STOP,
0134     RPORT_EV_LOGO
0135 };
0136 
0137 struct fc_rport_priv;
0138 
0139 /**
0140  * struct fc_rport_operations - Operations for a remote port
0141  * @event_callback: Function to be called for remote port events
0142  */
0143 struct fc_rport_operations {
0144     void (*event_callback)(struct fc_lport *, struct fc_rport_priv *,
0145                    enum fc_rport_event);
0146 };
0147 
0148 /**
0149  * struct fc_rport_libfc_priv - libfc internal information about a remote port
0150  * @local_port: The associated local port
0151  * @rp_state:   Indicates READY for I/O or DELETE when blocked
0152  * @flags:      REC and RETRY supported flags
0153  * @e_d_tov:    Error detect timeout value (in msec)
0154  * @r_a_tov:    Resource allocation timeout value (in msec)
0155  */
0156 struct fc_rport_libfc_priv {
0157     struct fc_lport        *local_port;
0158     enum fc_rport_state    rp_state;
0159     u16            flags;
0160     #define FC_RP_FLAGS_REC_SUPPORTED   (1 << 0)
0161     #define FC_RP_FLAGS_RETRY       (1 << 1)
0162     #define FC_RP_STARTED           (1 << 2)
0163     #define FC_RP_FLAGS_CONF_REQ        (1 << 3)
0164     unsigned int           e_d_tov;
0165     unsigned int           r_a_tov;
0166 };
0167 
0168 /**
0169  * struct fc_rport_priv - libfc remote port and discovery info
0170  * @local_port:     The associated local port
0171  * @rport:          The FC transport remote port
0172  * @kref:           Reference counter
0173  * @rp_state:       Enumeration that tracks progress of PLOGI, PRLI,
0174  *                  and RTV exchanges
0175  * @ids:            The remote port identifiers and roles
0176  * @flags:          STARTED, REC and RETRY_SUPPORTED flags
0177  * @max_seq:        Maximum number of concurrent sequences
0178  * @disc_id:        The discovery identifier
0179  * @maxframe_size:  The maximum frame size
0180  * @retries:        The retry count for the current state
0181  * @major_retries:  The retry count for the entire PLOGI/PRLI state machine
0182  * @e_d_tov:        Error detect timeout value (in msec)
0183  * @r_a_tov:        Resource allocation timeout value (in msec)
0184  * @rp_mutex:       The mutex that protects the remote port
0185  * @retry_work:     Handle for retries
0186  * @event_callback: Callback when READY, FAILED or LOGO states complete
0187  * @prli_count:     Count of open PRLI sessions in providers
0188  * @rcu:        Structure used for freeing in an RCU-safe manner
0189  */
0190 struct fc_rport_priv {
0191     struct fc_lport         *local_port;
0192     struct fc_rport         *rport;
0193     struct kref         kref;
0194     enum fc_rport_state     rp_state;
0195     struct fc_rport_identifiers ids;
0196     u16             flags;
0197     u16             max_seq;
0198     u16             disc_id;
0199     u16             maxframe_size;
0200     unsigned int            retries;
0201     unsigned int            major_retries;
0202     unsigned int            e_d_tov;
0203     unsigned int            r_a_tov;
0204     struct mutex            rp_mutex;
0205     struct delayed_work     retry_work;
0206     enum fc_rport_event     event;
0207     struct fc_rport_operations  *ops;
0208     struct list_head        peers;
0209     struct work_struct      event_work;
0210     u32             supported_classes;
0211     u16             prli_count;
0212     struct rcu_head         rcu;
0213     u16             sp_features;
0214     u8              spp_type;
0215     void                (*lld_event_callback)(struct fc_lport *,
0216                               struct fc_rport_priv *,
0217                               enum fc_rport_event);
0218 };
0219 
0220 /**
0221  * struct fc_stats - fc stats structure
0222  * @SecondsSinceLastReset: Seconds since the last reset
0223  * @TxFrames:              Number of transmitted frames
0224  * @TxWords:               Number of transmitted words
0225  * @RxFrames:              Number of received frames
0226  * @RxWords:               Number of received words
0227  * @ErrorFrames:           Number of received error frames
0228  * @DumpedFrames:          Number of dumped frames
0229  * @FcpPktAllocFails:      Number of fcp packet allocation failures
0230  * @FcpPktAborts:          Number of fcp packet aborts
0231  * @FcpFrameAllocFails:    Number of fcp frame allocation failures
0232  * @LinkFailureCount:      Number of link failures
0233  * @LossOfSignalCount:     Number for signal losses
0234  * @InvalidTxWordCount:    Number of invalid transmitted words
0235  * @InvalidCRCCount:       Number of invalid CRCs
0236  * @InputRequests:         Number of input requests
0237  * @OutputRequests:        Number of output requests
0238  * @ControlRequests:       Number of control requests
0239  * @InputBytes:            Number of received bytes
0240  * @OutputBytes:           Number of transmitted bytes
0241  * @VLinkFailureCount:     Number of virtual link failures
0242  * @MissDiscAdvCount:      Number of missing FIP discovery advertisement
0243  */
0244 struct fc_stats {
0245     u64     SecondsSinceLastReset;
0246     u64     TxFrames;
0247     u64     TxWords;
0248     u64     RxFrames;
0249     u64     RxWords;
0250     u64     ErrorFrames;
0251     u64     DumpedFrames;
0252     u64     FcpPktAllocFails;
0253     u64     FcpPktAborts;
0254     u64     FcpFrameAllocFails;
0255     u64     LinkFailureCount;
0256     u64     LossOfSignalCount;
0257     u64     InvalidTxWordCount;
0258     u64     InvalidCRCCount;
0259     u64     InputRequests;
0260     u64     OutputRequests;
0261     u64     ControlRequests;
0262     u64     InputBytes;
0263     u64     OutputBytes;
0264     u64     VLinkFailureCount;
0265     u64     MissDiscAdvCount;
0266 };
0267 
0268 /**
0269  * struct fc_seq_els_data - ELS data used for passing ELS specific responses
0270  * @reason: The reason for rejection
0271  * @explan: The explanation of the rejection
0272  *
0273  * Mainly used by the exchange manager layer.
0274  */
0275 struct fc_seq_els_data {
0276     enum fc_els_rjt_reason reason;
0277     enum fc_els_rjt_explan explan;
0278 };
0279 
0280 /**
0281  * struct fc_fcp_pkt - FCP request structure (one for each scsi_cmnd request)
0282  * @lp:              The associated local port
0283  * @state:           The state of the I/O
0284  * @ref_cnt:         Reference count
0285  * @scsi_pkt_lock:   Lock to protect the SCSI packet (must be taken before the
0286  *                   host_lock if both are to be held at the same time)
0287  * @cmd:             The SCSI command (set and clear with the host_lock held)
0288  * @list:            Tracks queued commands (accessed with the host_lock held)
0289  * @timer:           The command timer
0290  * @tm_done:         Completion indicator
0291  * @wait_for_comp:   Indicator to wait for completion of the I/O (in jiffies)
0292  * @data_len:        The length of the data
0293  * @cdb_cmd:         The CDB command
0294  * @xfer_len:        The transfer length
0295  * @xfer_ddp:        Indicates if this transfer used DDP (XID of the exchange
0296  *                   will be set here if DDP was setup)
0297  * @xfer_contig_end: The offset into the buffer if the buffer is contiguous
0298  *                   (Tx and Rx)
0299  * @max_payload:     The maximum payload size (in bytes)
0300  * @io_status:       SCSI result (upper 24 bits)
0301  * @cdb_status:      CDB status
0302  * @status_code:     FCP I/O status
0303  * @scsi_comp_flags: Completion flags (bit 3 Underrun bit 2: overrun)
0304  * @req_flags:       Request flags (bit 0: read bit:1 write)
0305  * @scsi_resid:      SCSI residule length
0306  * @rport:           The remote port that the SCSI command is targeted at
0307  * @seq_ptr:         The sequence that will carry the SCSI command
0308  * @recov_retry:     Number of recovery retries
0309  * @recov_seq:       The sequence for REC or SRR
0310  */
0311 struct fc_fcp_pkt {
0312     spinlock_t    scsi_pkt_lock;
0313     refcount_t    ref_cnt;
0314 
0315     /* SCSI command and data transfer information */
0316     u32       data_len;
0317 
0318     /* SCSI I/O related information */
0319     struct scsi_cmnd  *cmd;
0320     struct list_head  list;
0321 
0322     /* Housekeeping information */
0323     struct fc_lport   *lp;
0324     u8        state;
0325 
0326     /* SCSI/FCP return status */
0327     u8        cdb_status;
0328     u8        status_code;
0329     u8        scsi_comp_flags;
0330     u32       io_status;
0331     u32       req_flags;
0332     u32       scsi_resid;
0333 
0334     /* Transport related veriables */
0335     size_t        xfer_len;
0336     struct fcp_cmnd   cdb_cmd;
0337     u32       xfer_contig_end;
0338     u16       max_payload;
0339     u16       xfer_ddp;
0340 
0341     /* Associated structures */
0342     struct fc_rport   *rport;
0343     struct fc_seq     *seq_ptr;
0344 
0345     /* Timeout/error related information */
0346     struct timer_list timer;
0347     int       wait_for_comp;
0348     int       timer_delay;
0349     u32       recov_retry;
0350     struct fc_seq     *recov_seq;
0351     struct completion tm_done;
0352 } ____cacheline_aligned_in_smp;
0353 
0354 /*
0355  * @fsp should be tested and set under the scsi_pkt_queue lock
0356  */
0357 struct libfc_cmd_priv {
0358     struct fc_fcp_pkt *fsp;
0359     u32 resid_len;
0360     u8 status;
0361 };
0362 
0363 /*
0364  * Structure and function definitions for managing Fibre Channel Exchanges
0365  * and Sequences
0366  *
0367  * fc_exch holds state for one exchange and links to its active sequence.
0368  *
0369  * fc_seq holds the state for an individual sequence.
0370  */
0371 
0372 struct fc_exch_mgr;
0373 struct fc_exch_mgr_anchor;
0374 extern u16 fc_cpu_mask; /* cpu mask for possible cpus */
0375 
0376 /**
0377  * struct fc_seq - FC sequence
0378  * @id:       The sequence ID
0379  * @ssb_stat: Status flags for the sequence status block (SSB)
0380  * @cnt:      Number of frames sent so far
0381  * @rec_data: FC-4 value for REC
0382  */
0383 struct fc_seq {
0384     u8  id;
0385     u16 ssb_stat;
0386     u16 cnt;
0387     u32 rec_data;
0388 };
0389 
0390 #define FC_EX_DONE      (1 << 0) /* ep is completed */
0391 #define FC_EX_RST_CLEANUP   (1 << 1) /* reset is forcing completion */
0392 #define FC_EX_QUARANTINE    (1 << 2) /* exch is quarantined */
0393 
0394 /**
0395  * struct fc_exch - Fibre Channel Exchange
0396  * @em:           Exchange manager
0397  * @pool:         Exchange pool
0398  * @state:        The exchange's state
0399  * @xid:          The exchange ID
0400  * @ex_list:      Handle used by the EM to track free exchanges
0401  * @ex_lock:      Lock that protects the exchange
0402  * @ex_refcnt:    Reference count
0403  * @timeout_work: Handle for timeout handler
0404  * @lp:           The local port that this exchange is on
0405  * @oxid:         Originator's exchange ID
0406  * @rxid:         Responder's exchange ID
0407  * @oid:          Originator's FCID
0408  * @sid:          Source FCID
0409  * @did:          Destination FCID
0410  * @esb_stat:     ESB exchange status
0411  * @r_a_tov:      Resource allocation time out value (in msecs)
0412  * @seq_id:       The next sequence ID to use
0413  * @encaps:       encapsulation information for lower-level driver
0414  * @f_ctl:        F_CTL flags for the sequence
0415  * @fh_type:      The frame type
0416  * @class:        The class of service
0417  * @seq:          The sequence in use on this exchange
0418  * @resp_active:  Number of tasks that are concurrently executing @resp().
0419  * @resp_task:    If @resp_active > 0, either the task executing @resp(), the
0420  *                task that has been interrupted to execute the soft-IRQ
0421  *                executing @resp() or NULL if more than one task is executing
0422  *                @resp concurrently.
0423  * @resp_wq:      Waitqueue for the tasks waiting on @resp_active.
0424  * @resp:         Callback for responses on this exchange
0425  * @destructor:   Called when destroying the exchange
0426  * @arg:          Passed as a void pointer to the resp() callback
0427  *
0428  * Locking notes: The ex_lock protects following items:
0429  *  state, esb_stat, f_ctl, seq.ssb_stat
0430  *  seq_id
0431  *  sequence allocation
0432  */
0433 struct fc_exch {
0434     spinlock_t      ex_lock;
0435     atomic_t        ex_refcnt;
0436     enum fc_class       class;
0437     struct fc_exch_mgr  *em;
0438     struct fc_exch_pool *pool;
0439     struct list_head    ex_list;
0440     struct fc_lport     *lp;
0441     u32         esb_stat;
0442     u8          state;
0443     u8          fh_type;
0444     u8          seq_id;
0445     u8          encaps;
0446     u16         xid;
0447     u16         oxid;
0448     u16         rxid;
0449     u32         oid;
0450     u32         sid;
0451     u32         did;
0452     u32         r_a_tov;
0453     u32         f_ctl;
0454     struct fc_seq       seq;
0455     int         resp_active;
0456     struct task_struct  *resp_task;
0457     wait_queue_head_t   resp_wq;
0458     void            (*resp)(struct fc_seq *, struct fc_frame *, void *);
0459     void            *arg;
0460     void            (*destructor)(struct fc_seq *, void *);
0461     struct delayed_work timeout_work;
0462 } ____cacheline_aligned_in_smp;
0463 #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
0464 
0465 
0466 struct libfc_function_template {
0467     /*
0468      * Interface to send a FC frame
0469      *
0470      * STATUS: REQUIRED
0471      */
0472     int (*frame_send)(struct fc_lport *, struct fc_frame *);
0473 
0474     /*
0475      * Interface to send ELS/CT frames
0476      *
0477      * STATUS: OPTIONAL
0478      */
0479     struct fc_seq *(*elsct_send)(struct fc_lport *, u32 did,
0480                      struct fc_frame *, unsigned int op,
0481                      void (*resp)(struct fc_seq *,
0482                          struct fc_frame *, void *arg),
0483                      void *arg, u32 timer_msec);
0484 
0485     /*
0486      * Sets up the DDP context for a given exchange id on the given
0487      * scatterlist if LLD supports DDP for large receive.
0488      *
0489      * STATUS: OPTIONAL
0490      */
0491     int (*ddp_setup)(struct fc_lport *, u16, struct scatterlist *,
0492              unsigned int);
0493     /*
0494      * Completes the DDP transfer and returns the length of data DDPed
0495      * for the given exchange id.
0496      *
0497      * STATUS: OPTIONAL
0498      */
0499     int (*ddp_done)(struct fc_lport *, u16);
0500     /*
0501      * Sets up the DDP context for a given exchange id on the given
0502      * scatterlist if LLD supports DDP for target.
0503      *
0504      * STATUS: OPTIONAL
0505      */
0506     int (*ddp_target)(struct fc_lport *, u16, struct scatterlist *,
0507               unsigned int);
0508     /*
0509      * Allow LLD to fill its own Link Error Status Block
0510      *
0511      * STATUS: OPTIONAL
0512      */
0513     void (*get_lesb)(struct fc_lport *, struct fc_els_lesb *lesb);
0514 
0515     /*
0516      * Reset an exchange manager, completing all sequences and exchanges.
0517      * If s_id is non-zero, reset only exchanges originating from that FID.
0518      * If d_id is non-zero, reset only exchanges sending to that FID.
0519      *
0520      * STATUS: OPTIONAL
0521      */
0522     void (*exch_mgr_reset)(struct fc_lport *, u32 s_id, u32 d_id);
0523 
0524     /*
0525      * Set the local port FC_ID.
0526      *
0527      * This may be provided by the LLD to allow it to be
0528      * notified when the local port is assigned a FC-ID.
0529      *
0530      * The frame, if non-NULL, is the incoming frame with the
0531      * FLOGI LS_ACC or FLOGI, and may contain the granted MAC
0532      * address for the LLD.  The frame pointer may be NULL if
0533      * no MAC is associated with this assignment (LOGO or PLOGI).
0534      *
0535      * If FC_ID is non-zero, r_a_tov and e_d_tov must be valid.
0536      *
0537      * Note: this is called with the local port mutex held.
0538      *
0539      * STATUS: OPTIONAL
0540      */
0541     void (*lport_set_port_id)(struct fc_lport *, u32 port_id,
0542                   struct fc_frame *);
0543 
0544     /*
0545      * Callback routine after the remote port is logged in
0546      *
0547      * STATUS: OPTIONAL
0548      */
0549     void (*rport_event_callback)(struct fc_lport *,
0550                      struct fc_rport_priv *,
0551                      enum fc_rport_event);
0552 
0553     /*
0554      * Send a fcp cmd from fsp pkt.
0555      * Called with the SCSI host lock unlocked and irqs disabled.
0556      *
0557      * The resp handler is called when FCP_RSP received.
0558      *
0559      * STATUS: OPTIONAL
0560      */
0561     int (*fcp_cmd_send)(struct fc_lport *, struct fc_fcp_pkt *,
0562                 void (*resp)(struct fc_seq *, struct fc_frame *,
0563                      void *));
0564 
0565     /*
0566      * Cleanup the FCP layer, used during link down and reset
0567      *
0568      * STATUS: OPTIONAL
0569      */
0570     void (*fcp_cleanup)(struct fc_lport *);
0571 
0572     /*
0573      * Abort all I/O on a local port
0574      *
0575      * STATUS: OPTIONAL
0576      */
0577     void (*fcp_abort_io)(struct fc_lport *);
0578 
0579     /*
0580      * Receive a request for the discovery layer.
0581      *
0582      * STATUS: OPTIONAL
0583      */
0584     void (*disc_recv_req)(struct fc_lport *, struct fc_frame *);
0585 
0586     /*
0587      * Start discovery for a local port.
0588      *
0589      * STATUS: OPTIONAL
0590      */
0591     void (*disc_start)(void (*disc_callback)(struct fc_lport *,
0592                          enum fc_disc_event),
0593                struct fc_lport *);
0594 
0595     /*
0596      * Stop discovery for a given lport. This will remove
0597      * all discovered rports
0598      *
0599      * STATUS: OPTIONAL
0600      */
0601     void (*disc_stop) (struct fc_lport *);
0602 
0603     /*
0604      * Stop discovery for a given lport. This will block
0605      * until all discovered rports are deleted from the
0606      * FC transport class
0607      *
0608      * STATUS: OPTIONAL
0609      */
0610     void (*disc_stop_final) (struct fc_lport *);
0611 };
0612 
0613 /**
0614  * struct fc_disc - Discovery context
0615  * @retry_count:   Number of retries
0616  * @pending:       1 if discovery is pending, 0 if not
0617  * @requested:     1 if discovery has been requested, 0 if not
0618  * @seq_count:     Number of sequences used for discovery
0619  * @buf_len:       Length of the discovery buffer
0620  * @disc_id:       Discovery ID
0621  * @rports:        List of discovered remote ports
0622  * @priv:          Private pointer for use by discovery code
0623  * @disc_mutex:    Mutex that protects the discovery context
0624  * @partial_buf:   Partial name buffer (if names are returned
0625  *                 in multiple frames)
0626  * @disc_work:     handle for delayed work context
0627  * @disc_callback: Callback routine called when discovery completes
0628  */
0629 struct fc_disc {
0630     unsigned char         retry_count;
0631     unsigned char         pending;
0632     unsigned char         requested;
0633     unsigned short        seq_count;
0634     unsigned char         buf_len;
0635     u16           disc_id;
0636 
0637     struct list_head      rports;
0638     void              *priv;
0639     struct mutex          disc_mutex;
0640     struct fc_gpn_ft_resp partial_buf;
0641     struct delayed_work   disc_work;
0642 
0643     void (*disc_callback)(struct fc_lport *,
0644                   enum fc_disc_event);
0645 };
0646 
0647 /*
0648  * Local port notifier and events.
0649  */
0650 extern struct blocking_notifier_head fc_lport_notifier_head;
0651 enum fc_lport_event {
0652     FC_LPORT_EV_ADD,
0653     FC_LPORT_EV_DEL,
0654 };
0655 
0656 /**
0657  * struct fc_lport - Local port
0658  * @host:                  The SCSI host associated with a local port
0659  * @ema_list:              Exchange manager anchor list
0660  * @dns_rdata:             The directory server remote port
0661  * @ms_rdata:          The management server remote port
0662  * @ptp_rdata:             Point to point remote port
0663  * @scsi_priv:             FCP layer internal data
0664  * @disc:                  Discovery context
0665  * @vports:                Child vports if N_Port
0666  * @vport:                 Parent vport if VN_Port
0667  * @tt:                    Libfc function template
0668  * @link_up:               Link state (1 = link up, 0 = link down)
0669  * @qfull:                 Queue state (1 queue is full, 0 queue is not full)
0670  * @state:                 Identifies the state
0671  * @boot_time:             Timestamp indicating when the local port came online
0672  * @host_stats:            SCSI host statistics
0673  * @stats:                 FC local port stats (TODO separate libfc LLD stats)
0674  * @retry_count:           Number of retries in the current state
0675  * @port_id:               FC Port ID
0676  * @wwpn:                  World Wide Port Name
0677  * @wwnn:                  World Wide Node Name
0678  * @service_params:        Common service parameters
0679  * @e_d_tov:               Error detection timeout value
0680  * @r_a_tov:               Resource allocation timeout value
0681  * @rnid_gen:              RNID information
0682  * @sg_supp:               Indicates if scatter gather is supported
0683  * @seq_offload:           Indicates if sequence offload is supported
0684  * @crc_offload:           Indicates if CRC offload is supported
0685  * @lro_enabled:           Indicates if large receive offload is supported
0686  * @does_npiv:             Supports multiple vports
0687  * @npiv_enabled:          Switch/fabric allows NPIV
0688  * @mfs:                   The maximum Fibre Channel payload size
0689  * @max_retry_count:       The maximum retry attempts
0690  * @max_rport_retry_count: The maximum remote port retry attempts
0691  * @rport_priv_size:       Size needed by driver after struct fc_rport_priv
0692  * @lro_xid:               The maximum XID for LRO
0693  * @lso_max:               The maximum large offload send size
0694  * @fcts:                  FC-4 type mask
0695  * @lp_mutex:              Mutex to protect the local port
0696  * @list:                  Linkage on list of vport peers
0697  * @retry_work:            Handle to local port for delayed retry context
0698  * @prov:          Pointers available for use by passive FC-4 providers
0699  * @lport_list:            Linkage on module-wide list of local ports
0700  */
0701 struct fc_lport {
0702     /* Associations */
0703     struct Scsi_Host           *host;
0704     struct list_head           ema_list;
0705     struct fc_rport_priv           *dns_rdata;
0706     struct fc_rport_priv           *ms_rdata;
0707     struct fc_rport_priv           *ptp_rdata;
0708     void                   *scsi_priv;
0709     struct fc_disc             disc;
0710 
0711     /* Virtual port information */
0712     struct list_head           vports;
0713     struct fc_vport            *vport;
0714 
0715     /* Operational Information */
0716     struct libfc_function_template tt;
0717     u8                 link_up;
0718     u8                 qfull;
0719     u16                vlan;
0720     enum fc_lport_state        state;
0721     unsigned long              boot_time;
0722     struct fc_host_statistics      host_stats;
0723     struct fc_stats __percpu       *stats;
0724     u8                 retry_count;
0725 
0726     /* Fabric information */
0727     u32                port_id;
0728     u64                wwpn;
0729     u64                wwnn;
0730     unsigned int               service_params;
0731     unsigned int               e_d_tov;
0732     unsigned int               r_a_tov;
0733     struct fc_els_rnid_gen         rnid_gen;
0734 
0735     /* Capabilities */
0736     u32                sg_supp:1;
0737     u32                seq_offload:1;
0738     u32                crc_offload:1;
0739     u32                lro_enabled:1;
0740     u32                does_npiv:1;
0741     u32                npiv_enabled:1;
0742     u32                point_to_multipoint:1;
0743     u32                fdmi_enabled:1;
0744     u32                mfs;
0745     u8                 max_retry_count;
0746     u8                 max_rport_retry_count;
0747     u16                rport_priv_size;
0748     u16                link_speed;
0749     u16                link_supported_speeds;
0750     u16                lro_xid;
0751     unsigned int               lso_max;
0752     struct fc_ns_fts           fcts;
0753 
0754     /* Miscellaneous */
0755     struct mutex               lp_mutex;
0756     struct list_head           list;
0757     struct delayed_work        retry_work;
0758     void                   *prov[FC_FC4_PROV_SIZE];
0759     struct list_head           lport_list;
0760 };
0761 
0762 /**
0763  * struct fc4_prov - FC-4 provider registration
0764  * @prli:               Handler for incoming PRLI
0765  * @prlo:               Handler for session reset
0766  * @recv:       Handler for incoming request
0767  * @module:     Pointer to module.  May be NULL.
0768  */
0769 struct fc4_prov {
0770     int (*prli)(struct fc_rport_priv *, u32 spp_len,
0771             const struct fc_els_spp *spp_in,
0772             struct fc_els_spp *spp_out);
0773     void (*prlo)(struct fc_rport_priv *);
0774     void (*recv)(struct fc_lport *, struct fc_frame *);
0775     struct module *module;
0776 };
0777 
0778 /*
0779  * Register FC-4 provider with libfc.
0780  */
0781 int fc_fc4_register_provider(enum fc_fh_type type, struct fc4_prov *);
0782 void fc_fc4_deregister_provider(enum fc_fh_type type, struct fc4_prov *);
0783 
0784 /*
0785  * FC_LPORT HELPER FUNCTIONS
0786  *****************************/
0787 
0788 /**
0789  * fc_lport_test_ready() - Determine if a local port is in the READY state
0790  * @lport: The local port to test
0791  */
0792 static inline int fc_lport_test_ready(struct fc_lport *lport)
0793 {
0794     return lport->state == LPORT_ST_READY;
0795 }
0796 
0797 /**
0798  * fc_set_wwnn() - Set the World Wide Node Name of a local port
0799  * @lport: The local port whose WWNN is to be set
0800  * @wwnn:  The new WWNN
0801  */
0802 static inline void fc_set_wwnn(struct fc_lport *lport, u64 wwnn)
0803 {
0804     lport->wwnn = wwnn;
0805 }
0806 
0807 /**
0808  * fc_set_wwpn() - Set the World Wide Port Name of a local port
0809  * @lport: The local port whose WWPN is to be set
0810  * @wwpn:  The new WWPN
0811  */
0812 static inline void fc_set_wwpn(struct fc_lport *lport, u64 wwpn)
0813 {
0814     lport->wwpn = wwpn;
0815 }
0816 
0817 /**
0818  * fc_lport_state_enter() - Change a local port's state
0819  * @lport: The local port whose state is to change
0820  * @state: The new state
0821  */
0822 static inline void fc_lport_state_enter(struct fc_lport *lport,
0823                     enum fc_lport_state state)
0824 {
0825     if (state != lport->state)
0826         lport->retry_count = 0;
0827     lport->state = state;
0828 }
0829 
0830 /**
0831  * fc_lport_init_stats() - Allocate per-CPU statistics for a local port
0832  * @lport: The local port whose statistics are to be initialized
0833  */
0834 static inline int fc_lport_init_stats(struct fc_lport *lport)
0835 {
0836     lport->stats = alloc_percpu(struct fc_stats);
0837     if (!lport->stats)
0838         return -ENOMEM;
0839     return 0;
0840 }
0841 
0842 /**
0843  * fc_lport_free_stats() - Free memory for a local port's statistics
0844  * @lport: The local port whose statistics are to be freed
0845  */
0846 static inline void fc_lport_free_stats(struct fc_lport *lport)
0847 {
0848     free_percpu(lport->stats);
0849 }
0850 
0851 /**
0852  * lport_priv() - Return the private data from a local port
0853  * @lport: The local port whose private data is to be retrieved
0854  */
0855 static inline void *lport_priv(const struct fc_lport *lport)
0856 {
0857     return (void *)(lport + 1);
0858 }
0859 
0860 /**
0861  * libfc_host_alloc() - Allocate a Scsi_Host with room for a local port and
0862  *                      LLD private data
0863  * @sht:       The SCSI host template
0864  * @priv_size: Size of private data
0865  *
0866  * Returns: libfc lport
0867  */
0868 static inline struct fc_lport *
0869 libfc_host_alloc(struct scsi_host_template *sht, int priv_size)
0870 {
0871     struct fc_lport *lport;
0872     struct Scsi_Host *shost;
0873 
0874     shost = scsi_host_alloc(sht, sizeof(*lport) + priv_size);
0875     if (!shost)
0876         return NULL;
0877     lport = shost_priv(shost);
0878     lport->host = shost;
0879     INIT_LIST_HEAD(&lport->ema_list);
0880     INIT_LIST_HEAD(&lport->vports);
0881     return lport;
0882 }
0883 
0884 /*
0885  * FC_FCP HELPER FUNCTIONS
0886  *****************************/
0887 static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)
0888 {
0889     if (fsp && fsp->cmd)
0890         return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE;
0891     return false;
0892 }
0893 
0894 /*
0895  * LOCAL PORT LAYER
0896  *****************************/
0897 int fc_lport_init(struct fc_lport *);
0898 int fc_lport_destroy(struct fc_lport *);
0899 int fc_fabric_logoff(struct fc_lport *);
0900 int fc_fabric_login(struct fc_lport *);
0901 void __fc_linkup(struct fc_lport *);
0902 void fc_linkup(struct fc_lport *);
0903 void __fc_linkdown(struct fc_lport *);
0904 void fc_linkdown(struct fc_lport *);
0905 void fc_vport_setlink(struct fc_lport *);
0906 void fc_vports_linkchange(struct fc_lport *);
0907 int fc_lport_config(struct fc_lport *);
0908 int fc_lport_reset(struct fc_lport *);
0909 void fc_lport_recv(struct fc_lport *lport, struct fc_frame *fp);
0910 int fc_set_mfs(struct fc_lport *, u32 mfs);
0911 struct fc_lport *libfc_vport_create(struct fc_vport *, int privsize);
0912 struct fc_lport *fc_vport_id_lookup(struct fc_lport *, u32 port_id);
0913 int fc_lport_bsg_request(struct bsg_job *);
0914 void fc_lport_set_local_id(struct fc_lport *, u32 port_id);
0915 void fc_lport_iterate(void (*func)(struct fc_lport *, void *), void *);
0916 
0917 /*
0918  * REMOTE PORT LAYER
0919  *****************************/
0920 void fc_rport_terminate_io(struct fc_rport *);
0921 struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
0922                       u32 port_id);
0923 struct fc_rport_priv *fc_rport_create(struct fc_lport *, u32);
0924 void fc_rport_destroy(struct kref *kref);
0925 int fc_rport_login(struct fc_rport_priv *rdata);
0926 int fc_rport_logoff(struct fc_rport_priv *rdata);
0927 void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp);
0928 void fc_rport_flush_queue(void);
0929 
0930 /*
0931  * DISCOVERY LAYER
0932  *****************************/
0933 void fc_disc_init(struct fc_lport *);
0934 void fc_disc_config(struct fc_lport *, void *);
0935 
0936 static inline struct fc_lport *fc_disc_lport(struct fc_disc *disc)
0937 {
0938     return container_of(disc, struct fc_lport, disc);
0939 }
0940 
0941 /*
0942  * FCP LAYER
0943  *****************************/
0944 int fc_fcp_init(struct fc_lport *);
0945 void fc_fcp_destroy(struct fc_lport *);
0946 
0947 /*
0948  * SCSI INTERACTION LAYER
0949  *****************************/
0950 int fc_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
0951 int fc_eh_abort(struct scsi_cmnd *);
0952 int fc_eh_device_reset(struct scsi_cmnd *);
0953 int fc_eh_host_reset(struct scsi_cmnd *);
0954 int fc_slave_alloc(struct scsi_device *);
0955 
0956 /*
0957  * ELS/CT interface
0958  *****************************/
0959 int fc_elsct_init(struct fc_lport *);
0960 struct fc_seq *fc_elsct_send(struct fc_lport *, u32 did,
0961                     struct fc_frame *,
0962                     unsigned int op,
0963                     void (*resp)(struct fc_seq *,
0964                          struct fc_frame *,
0965                          void *arg),
0966                     void *arg, u32 timer_msec);
0967 void fc_lport_flogi_resp(struct fc_seq *, struct fc_frame *, void *);
0968 void fc_lport_logo_resp(struct fc_seq *, struct fc_frame *, void *);
0969 void fc_fill_reply_hdr(struct fc_frame *, const struct fc_frame *,
0970                enum fc_rctl, u32 parm_offset);
0971 void fc_fill_hdr(struct fc_frame *, const struct fc_frame *,
0972          enum fc_rctl, u32 f_ctl, u16 seq_cnt, u32 parm_offset);
0973 
0974 
0975 /*
0976  * EXCHANGE MANAGER LAYER
0977  *****************************/
0978 int fc_exch_init(struct fc_lport *);
0979 void fc_exch_update_stats(struct fc_lport *lport);
0980 struct fc_seq *fc_exch_seq_send(struct fc_lport *lport,
0981                 struct fc_frame *fp,
0982                 void (*resp)(struct fc_seq *,
0983                          struct fc_frame *fp,
0984                          void *arg),
0985                 void (*destructor)(struct fc_seq *, void *),
0986                 void *arg, u32 timer_msec);
0987 void fc_seq_els_rsp_send(struct fc_frame *, enum fc_els_cmd,
0988              struct fc_seq_els_data *);
0989 struct fc_seq *fc_seq_start_next(struct fc_seq *sp);
0990 void fc_seq_set_resp(struct fc_seq *sp,
0991              void (*resp)(struct fc_seq *, struct fc_frame *, void *),
0992              void *arg);
0993 struct fc_seq *fc_seq_assign(struct fc_lport *lport, struct fc_frame *fp);
0994 void fc_seq_release(struct fc_seq *sp);
0995 struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *,
0996                        struct fc_exch_mgr *,
0997                        bool (*match)(struct fc_frame *));
0998 void fc_exch_mgr_del(struct fc_exch_mgr_anchor *);
0999 int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst);
1000 struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *, enum fc_class class,
1001                       u16 min_xid, u16 max_xid,
1002                       bool (*match)(struct fc_frame *));
1003 void fc_exch_mgr_free(struct fc_lport *);
1004 void fc_exch_recv(struct fc_lport *, struct fc_frame *);
1005 void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);
1006 int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp, struct fc_frame *fp);
1007 int fc_seq_exch_abort(const struct fc_seq *, unsigned int timer_msec);
1008 void fc_exch_done(struct fc_seq *sp);
1009 
1010 /*
1011  * Functions for fc_functions_template
1012  */
1013 void fc_get_host_speed(struct Scsi_Host *);
1014 void fc_get_host_port_state(struct Scsi_Host *);
1015 void fc_set_rport_loss_tmo(struct fc_rport *, u32 timeout);
1016 struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *);
1017 
1018 #endif /* _LIBFC_H_ */