Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 2021 Broadcom. All Rights Reserved. The term
0004  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
0005  */
0006 
0007 #ifndef __EFCLIB_H__
0008 #define __EFCLIB_H__
0009 
0010 #include "scsi/fc/fc_els.h"
0011 #include "scsi/fc/fc_fs.h"
0012 #include "scsi/fc/fc_ns.h"
0013 #include "scsi/fc/fc_gs.h"
0014 #include "scsi/fc_frame.h"
0015 #include "../include/efc_common.h"
0016 #include "../libefc_sli/sli4.h"
0017 
0018 #define EFC_SERVICE_PARMS_LENGTH    120
0019 #define EFC_NAME_LENGTH         32
0020 #define EFC_SM_NAME_LENGTH      64
0021 #define EFC_DISPLAY_BUS_INFO_LENGTH 16
0022 
0023 #define EFC_WWN_LENGTH          32
0024 
0025 #define EFC_FC_ELS_DEFAULT_RETRIES  3
0026 
0027 /* Timeouts */
0028 #define EFC_FC_ELS_SEND_DEFAULT_TIMEOUT 0
0029 #define EFC_FC_FLOGI_TIMEOUT_SEC    5
0030 #define EFC_SHUTDOWN_TIMEOUT_USEC   30000000
0031 
0032 /* Return values for calls from base driver to libefc */
0033 #define EFC_SCSI_CALL_COMPLETE      0
0034 #define EFC_SCSI_CALL_ASYNC     1
0035 
0036 /* Local port topology */
0037 enum efc_nport_topology {
0038     EFC_NPORT_TOPO_UNKNOWN = 0,
0039     EFC_NPORT_TOPO_FABRIC,
0040     EFC_NPORT_TOPO_P2P,
0041     EFC_NPORT_TOPO_FC_AL,
0042 };
0043 
0044 #define enable_target_rscn(efc)     1
0045 
0046 enum efc_node_shutd_rsn {
0047     EFC_NODE_SHUTDOWN_DEFAULT = 0,
0048     EFC_NODE_SHUTDOWN_EXPLICIT_LOGO,
0049     EFC_NODE_SHUTDOWN_IMPLICIT_LOGO,
0050 };
0051 
0052 enum efc_node_send_ls_acc {
0053     EFC_NODE_SEND_LS_ACC_NONE = 0,
0054     EFC_NODE_SEND_LS_ACC_PLOGI,
0055     EFC_NODE_SEND_LS_ACC_PRLI,
0056 };
0057 
0058 #define EFC_LINK_STATUS_UP      0
0059 #define EFC_LINK_STATUS_DOWN        1
0060 
0061 /* State machine context header  */
0062 struct efc_sm_ctx {
0063     void (*current_state)(struct efc_sm_ctx *ctx,
0064                   u32 evt, void *arg);
0065 
0066     const char  *description;
0067     void        *app;
0068 };
0069 
0070 /* Description of discovered Fabric Domain */
0071 struct efc_domain_record {
0072     u32     index;
0073     u32     priority;
0074     u8      address[6];
0075     u8      wwn[8];
0076     union {
0077         u8  vlan[512];
0078         u8  loop[128];
0079     } map;
0080     u32     speed;
0081     u32     fc_id;
0082     bool        is_loop;
0083     bool        is_nport;
0084 };
0085 
0086 /* Domain events */
0087 enum efc_hw_domain_event {
0088     EFC_HW_DOMAIN_ALLOC_OK,
0089     EFC_HW_DOMAIN_ALLOC_FAIL,
0090     EFC_HW_DOMAIN_ATTACH_OK,
0091     EFC_HW_DOMAIN_ATTACH_FAIL,
0092     EFC_HW_DOMAIN_FREE_OK,
0093     EFC_HW_DOMAIN_FREE_FAIL,
0094     EFC_HW_DOMAIN_LOST,
0095     EFC_HW_DOMAIN_FOUND,
0096     EFC_HW_DOMAIN_CHANGED,
0097 };
0098 
0099 /**
0100  * Fibre Channel port object
0101  *
0102  * @list_entry:     nport list entry
0103  * @ref:        reference count, each node takes a reference
0104  * @release:        function to free nport object
0105  * @efc:        pointer back to efc
0106  * @instance_index: unique instance index value
0107  * @display_name:   port display name
0108  * @is_vport:       Is NPIV port
0109  * @free_req_pending:   pending request to free resources
0110  * @attached:       mark attached if reg VPI succeeds
0111  * @p2p_winner:     TRUE if we're the point-to-point winner
0112  * @domain:     pointer back to domain
0113  * @wwpn:       port wwpn
0114  * @wwnn:       port wwnn
0115  * @tgt_data:       target backend private port data
0116  * @ini_data:       initiator backend private port data
0117  * @indicator:      VPI
0118  * @fc_id:      port FC address
0119  * @dma:        memory for Service Parameters
0120  * @wwnn_str:       wwpn string
0121  * @sli_wwpn:       SLI provided wwpn
0122  * @sli_wwnn:       SLI provided wwnn
0123  * @sm:         nport state machine context
0124  * @lookup:     fc_id to node lookup object
0125  * @enable_ini:     SCSI initiator enabled for this port
0126  * @enable_tgt:     SCSI target enabled for this port
0127  * @enable_rscn:    port will be expecting RSCN
0128  * @shutting_down:  nport in process of shutting down
0129  * @p2p_port_id:    our port id for point-to-point
0130  * @topology:       topology: fabric/p2p/unknown
0131  * @service_params: login parameters
0132  * @p2p_remote_port_id: remote node's port id for point-to-point
0133  */
0134 
0135 struct efc_nport {
0136     struct list_head    list_entry;
0137     struct kref     ref;
0138     void            (*release)(struct kref *arg);
0139     struct efc      *efc;
0140     u32         instance_index;
0141     char            display_name[EFC_NAME_LENGTH];
0142     bool            is_vport;
0143     bool            free_req_pending;
0144     bool            attached;
0145     bool            attaching;
0146     bool            p2p_winner;
0147     struct efc_domain   *domain;
0148     u64         wwpn;
0149     u64         wwnn;
0150     void            *tgt_data;
0151     void            *ini_data;
0152 
0153     u32         indicator;
0154     u32         fc_id;
0155     struct efc_dma      dma;
0156 
0157     u8          wwnn_str[EFC_WWN_LENGTH];
0158     __be64          sli_wwpn;
0159     __be64          sli_wwnn;
0160 
0161     struct efc_sm_ctx   sm;
0162     struct xarray       lookup;
0163     bool            enable_ini;
0164     bool            enable_tgt;
0165     bool            enable_rscn;
0166     bool            shutting_down;
0167     u32         p2p_port_id;
0168     enum efc_nport_topology topology;
0169     u8          service_params[EFC_SERVICE_PARMS_LENGTH];
0170     u32         p2p_remote_port_id;
0171 };
0172 
0173 /**
0174  * Fibre Channel domain object
0175  *
0176  * This object is a container for the various SLI components needed
0177  * to connect to the domain of a FC or FCoE switch
0178  * @efc:        pointer back to efc
0179  * @instance_index: unique instance index value
0180  * @display_name:   Node display name
0181  * @nport_list:     linked list of nports associated with this domain
0182  * @ref:        Reference count, each nport takes a reference
0183  * @release:        Function to free domain object
0184  * @ini_domain:     initiator backend private domain data
0185  * @tgt_domain:     target backend private domain data
0186  * @sm:         state machine context
0187  * @fcf:        FC Forwarder table index
0188  * @fcf_indicator:  FCFI
0189  * @indicator:      VFI
0190  * @nport_count:    Number of nports allocated
0191  * @dma:        memory for Service Parameters
0192  * @fcf_wwn:        WWN for FCF/switch
0193  * @drvsm:      driver domain sm context
0194  * @attached:       set true after attach completes
0195  * @is_fc:      is FC
0196  * @is_loop:        is loop topology
0197  * @is_nlport:      is public loop
0198  * @domain_found_pending:A domain found is pending, drec is updated
0199  * @req_domain_free:    True if domain object should be free'd
0200  * @req_accept_frames:  set in domain state machine to enable frames
0201  * @domain_notify_pend: Set in domain SM to avoid duplicate node event post
0202  * @pending_drec:   Pending drec if a domain found is pending
0203  * @service_params: any nports service parameters
0204  * @flogi_service_params:Fabric/P2p service parameters from FLOGI
0205  * @lookup:     d_id to node lookup object
0206  * @nport:      Pointer to first (physical) SLI port
0207  */
0208 struct efc_domain {
0209     struct efc      *efc;
0210     char            display_name[EFC_NAME_LENGTH];
0211     struct list_head    nport_list;
0212     struct kref     ref;
0213     void            (*release)(struct kref *arg);
0214     void            *ini_domain;
0215     void            *tgt_domain;
0216 
0217     /* Declarations private to HW/SLI */
0218     u32         fcf;
0219     u32         fcf_indicator;
0220     u32         indicator;
0221     u32         nport_count;
0222     struct efc_dma      dma;
0223 
0224     /* Declarations private to FC trannport */
0225     u64         fcf_wwn;
0226     struct efc_sm_ctx   drvsm;
0227     bool            attached;
0228     bool            is_fc;
0229     bool            is_loop;
0230     bool            is_nlport;
0231     bool            domain_found_pending;
0232     bool            req_domain_free;
0233     bool            req_accept_frames;
0234     bool            domain_notify_pend;
0235 
0236     struct efc_domain_record pending_drec;
0237     u8          service_params[EFC_SERVICE_PARMS_LENGTH];
0238     u8          flogi_service_params[EFC_SERVICE_PARMS_LENGTH];
0239 
0240     struct xarray       lookup;
0241 
0242     struct efc_nport    *nport;
0243 };
0244 
0245 /**
0246  * Remote Node object
0247  *
0248  * This object represents a connection between the SLI port and another
0249  * Nx_Port on the fabric. Note this can be either a well known port such
0250  * as a F_Port (i.e. ff:ff:fe) or another N_Port.
0251  * @indicator:      RPI
0252  * @fc_id:      FC address
0253  * @attached:       true if attached
0254  * @nport:      associated SLI port
0255  * @node:       associated node
0256  */
0257 struct efc_remote_node {
0258     u32         indicator;
0259     u32         index;
0260     u32         fc_id;
0261 
0262     bool            attached;
0263 
0264     struct efc_nport    *nport;
0265     void            *node;
0266 };
0267 
0268 /**
0269  * FC Node object
0270  * @efc:        pointer back to efc structure
0271  * @display_name:   Node display name
0272  * @nort:       Assosiated nport pointer.
0273  * @hold_frames:    hold incoming frames if true
0274  * @els_io_enabled: Enable allocating els ios for this node
0275  * @els_ios_lock:   lock to protect the els ios list
0276  * @els_ios_list:   ELS I/O's for this node
0277  * @ini_node:       backend initiator private node data
0278  * @tgt_node:       backend target private node data
0279  * @rnode:      Remote node
0280  * @sm:         state machine context
0281  * @evtdepth:       current event posting nesting depth
0282  * @req_free:       this node is to be free'd
0283  * @attached:       node is attached (REGLOGIN complete)
0284  * @fcp_enabled:    node is enabled to handle FCP
0285  * @rscn_pending:   for name server node RSCN is pending
0286  * @send_plogi:     send PLOGI accept, upon completion of node attach
0287  * @send_plogi_acc: TRUE if io_alloc() is enabled.
0288  * @send_ls_acc:    type of LS acc to send
0289  * @ls_acc_io:      SCSI IO for LS acc
0290  * @ls_acc_oxid:    OX_ID for pending accept
0291  * @ls_acc_did:     D_ID for pending accept
0292  * @shutdown_reason:    reason for node shutdown
0293  * @sparm_dma_buf:  service parameters buffer
0294  * @service_params: plogi/acc frame from remote device
0295  * @pend_frames_lock:   lock for inbound pending frames list
0296  * @pend_frames:    inbound pending frames list
0297  * @pend_frames_processed:count of frames processed in hold frames interval
0298  * @ox_id_in_use:   used to verify one at a time us of ox_id
0299  * @els_retries_remaining:for ELS, number of retries remaining
0300  * @els_req_cnt:    number of outstanding ELS requests
0301  * @els_cmpl_cnt:   number of outstanding ELS completions
0302  * @abort_cnt:      Abort counter for debugging purpos
0303  * @current_state_name: current node state
0304  * @prev_state_name:    previous node state
0305  * @current_evt:    current event
0306  * @prev_evt:       previous event
0307  * @targ:       node is target capable
0308  * @init:       node is init capable
0309  * @refound:        Handle node refound case when node is being deleted
0310  * @els_io_pend_list:   list of pending (not yet processed) ELS IOs
0311  * @els_io_active_list: list of active (processed) ELS IOs
0312  * @nodedb_state:   Node debugging, saved state
0313  * @gidpt_delay_timer:  GIDPT delay timer
0314  * @time_last_gidpt_msec:Start time of last target RSCN GIDPT
0315  * @wwnn:       remote port WWNN
0316  * @wwpn:       remote port WWPN
0317  */
0318 struct efc_node {
0319     struct efc      *efc;
0320     char            display_name[EFC_NAME_LENGTH];
0321     struct efc_nport    *nport;
0322     struct kref     ref;
0323     void            (*release)(struct kref *arg);
0324     bool            hold_frames;
0325     bool            els_io_enabled;
0326     bool            send_plogi_acc;
0327     bool            send_plogi;
0328     bool            rscn_pending;
0329     bool            fcp_enabled;
0330     bool            attached;
0331     bool            req_free;
0332 
0333     spinlock_t      els_ios_lock;
0334     struct list_head    els_ios_list;
0335     void            *ini_node;
0336     void            *tgt_node;
0337 
0338     struct efc_remote_node  rnode;
0339     /* Declarations private to FC trannport */
0340     struct efc_sm_ctx   sm;
0341     u32         evtdepth;
0342 
0343     enum efc_node_send_ls_acc send_ls_acc;
0344     void            *ls_acc_io;
0345     u32         ls_acc_oxid;
0346     u32         ls_acc_did;
0347     enum efc_node_shutd_rsn shutdown_reason;
0348     bool            targ;
0349     bool            init;
0350     bool            refound;
0351     struct efc_dma      sparm_dma_buf;
0352     u8          service_params[EFC_SERVICE_PARMS_LENGTH];
0353     spinlock_t      pend_frames_lock;
0354     struct list_head    pend_frames;
0355     u32         pend_frames_processed;
0356     u32         ox_id_in_use;
0357     u32         els_retries_remaining;
0358     u32         els_req_cnt;
0359     u32         els_cmpl_cnt;
0360     u32         abort_cnt;
0361 
0362     char            current_state_name[EFC_SM_NAME_LENGTH];
0363     char            prev_state_name[EFC_SM_NAME_LENGTH];
0364     int         current_evt;
0365     int         prev_evt;
0366 
0367     void (*nodedb_state)(struct efc_sm_ctx *ctx,
0368                  u32 evt, void *arg);
0369     struct timer_list   gidpt_delay_timer;
0370     u64         time_last_gidpt_msec;
0371 
0372     char            wwnn[EFC_WWN_LENGTH];
0373     char            wwpn[EFC_WWN_LENGTH];
0374 };
0375 
0376 /**
0377  * NPIV port
0378  *
0379  * Collection of the information required to restore a virtual port across
0380  * link events
0381  * @wwnn:       node name
0382  * @wwpn:       port name
0383  * @fc_id:      port id
0384  * @tgt_data:       target backend pointer
0385  * @ini_data:       initiator backend pointe
0386  * @nport:      Used to match record after attaching for update
0387  *
0388  */
0389 
0390 struct efc_vport {
0391     struct list_head    list_entry;
0392     u64         wwnn;
0393     u64         wwpn;
0394     u32         fc_id;
0395     bool            enable_tgt;
0396     bool            enable_ini;
0397     void            *tgt_data;
0398     void            *ini_data;
0399     struct efc_nport    *nport;
0400 };
0401 
0402 #define node_printf(node, fmt, args...) \
0403     efc_log_info(node->efc, "[%s] " fmt, node->display_name, ##args)
0404 
0405 /* Node SM IO Context Callback structure */
0406 struct efc_node_cb {
0407     int         status;
0408     int         ext_status;
0409     struct efc_hw_rq_buffer *header;
0410     struct efc_hw_rq_buffer *payload;
0411     struct efc_dma      els_rsp;
0412 
0413     /* Actual length of data received */
0414     int         rsp_len;
0415 };
0416 
0417 struct efc_hw_rq_buffer {
0418     u16         rqindex;
0419     struct efc_dma      dma;
0420 };
0421 
0422 /**
0423  * FC sequence object
0424  *
0425  * Defines a general FC sequence object
0426  * @hw:         HW that owns this sequence
0427  * @fcfi:       FCFI associated with sequence
0428  * @header:     Received frame header
0429  * @payload:        Received frame header
0430  * @hw_priv:        HW private context
0431  */
0432 struct efc_hw_sequence {
0433     struct list_head    list_entry;
0434     void            *hw;
0435     u8          fcfi;
0436     struct efc_hw_rq_buffer *header;
0437     struct efc_hw_rq_buffer *payload;
0438     void            *hw_priv;
0439 };
0440 
0441 enum efc_disc_io_type {
0442     EFC_DISC_IO_ELS_REQ,
0443     EFC_DISC_IO_ELS_RESP,
0444     EFC_DISC_IO_CT_REQ,
0445     EFC_DISC_IO_CT_RESP
0446 };
0447 
0448 struct efc_io_els_params {
0449     u32             s_id;
0450     u16             ox_id;
0451     u8              timeout;
0452 };
0453 
0454 struct efc_io_ct_params {
0455     u8              r_ctl;
0456     u8              type;
0457     u8              df_ctl;
0458     u8              timeout;
0459     u16             ox_id;
0460 };
0461 
0462 union efc_disc_io_param {
0463     struct efc_io_els_params els;
0464     struct efc_io_ct_params ct;
0465 };
0466 
0467 struct efc_disc_io {
0468     struct efc_dma      req;         /* send buffer */
0469     struct efc_dma      rsp;         /* receive buffer */
0470     enum efc_disc_io_type   io_type;     /* EFC_DISC_IO_TYPE enum*/
0471     u16         xmit_len;    /* Length of els request*/
0472     u16         rsp_len;     /* Max length of rsps to be rcvd */
0473     u32         rpi;         /* Registered RPI */
0474     u32         vpi;         /* VPI for this nport */
0475     u32         s_id;
0476     u32         d_id;
0477     bool            rpi_registered; /* if false, use tmp RPI */
0478     union efc_disc_io_param iparam;
0479 };
0480 
0481 /* Return value indiacating the sequence can not be freed */
0482 #define EFC_HW_SEQ_HOLD     0
0483 /* Return value indiacating the sequence can be freed */
0484 #define EFC_HW_SEQ_FREE     1
0485 
0486 struct libefc_function_template {
0487     /*Sport*/
0488     int (*new_nport)(struct efc *efc, struct efc_nport *sp);
0489     void (*del_nport)(struct efc *efc, struct efc_nport *sp);
0490 
0491     /*Scsi Node*/
0492     int (*scsi_new_node)(struct efc *efc, struct efc_node *n);
0493     int (*scsi_del_node)(struct efc *efc, struct efc_node *n, int reason);
0494 
0495     int (*issue_mbox_rqst)(void *efct, void *buf, void *cb, void *arg);
0496     /*Send ELS IO*/
0497     int (*send_els)(struct efc *efc, struct efc_disc_io *io);
0498     /*Send BLS IO*/
0499     int (*send_bls)(struct efc *efc, u32 type, struct sli_bls_params *bls);
0500     /*Free HW frame*/
0501     int (*hw_seq_free)(struct efc *efc, struct efc_hw_sequence *seq);
0502 };
0503 
0504 #define EFC_LOG_LIB     0x01
0505 #define EFC_LOG_NODE        0x02
0506 #define EFC_LOG_PORT        0x04
0507 #define EFC_LOG_DOMAIN      0x08
0508 #define EFC_LOG_ELS     0x10
0509 #define EFC_LOG_DOMAIN_SM   0x20
0510 #define EFC_LOG_SM      0x40
0511 
0512 /* efc library port structure */
0513 struct efc {
0514     void            *base;
0515     struct pci_dev      *pci;
0516     struct sli4     *sli;
0517     u32         fcfi;
0518     u64         req_wwpn;
0519     u64         req_wwnn;
0520 
0521     u64         def_wwpn;
0522     u64         def_wwnn;
0523     u64         max_xfer_size;
0524     mempool_t       *node_pool;
0525     struct dma_pool     *node_dma_pool;
0526     u32         nodes_count;
0527 
0528     u32         link_status;
0529 
0530     struct list_head    vport_list;
0531     /* lock to protect the vport list */
0532     spinlock_t      vport_lock;
0533 
0534     struct libefc_function_template tt;
0535     /* lock to protect the discovery library.
0536      * Refer to efclib.c for more details.
0537      */
0538     spinlock_t      lock;
0539 
0540     bool            enable_ini;
0541     bool            enable_tgt;
0542 
0543     u32         log_level;
0544 
0545     struct efc_domain   *domain;
0546     void (*domain_free_cb)(struct efc *efc, void *arg);
0547     void            *domain_free_cb_arg;
0548 
0549     u64         tgt_rscn_delay_msec;
0550     u64         tgt_rscn_period_msec;
0551 
0552     bool            external_loopback;
0553     u32         nodedb_mask;
0554     u32         logmask;
0555     mempool_t       *els_io_pool;
0556     atomic_t        els_io_alloc_failed_count;
0557 
0558     /* hold pending frames */
0559     bool            hold_frames;
0560     /* lock to protect pending frames list access */
0561     spinlock_t      pend_frames_lock;
0562     struct list_head    pend_frames;
0563     /* count of pending frames that were processed */
0564     u32         pend_frames_processed;
0565 
0566 };
0567 
0568 /*
0569  * EFC library registration
0570  * **********************************/
0571 int efcport_init(struct efc *efc);
0572 void efcport_destroy(struct efc *efc);
0573 /*
0574  * EFC Domain
0575  * **********************************/
0576 int efc_domain_cb(void *arg, int event, void *data);
0577 void
0578 efc_register_domain_free_cb(struct efc *efc,
0579                 void (*callback)(struct efc *efc, void *arg),
0580                 void *arg);
0581 
0582 /*
0583  * EFC nport
0584  * **********************************/
0585 void efc_nport_cb(void *arg, int event, void *data);
0586 struct efc_vport *
0587 efc_vport_create_spec(struct efc *efc, u64 wwnn, u64 wwpn, u32 fc_id,
0588               bool enable_ini, bool enable_tgt,
0589               void *tgt_data, void *ini_data);
0590 int efc_nport_vport_new(struct efc_domain *domain, u64 wwpn,
0591             u64 wwnn, u32 fc_id, bool ini, bool tgt,
0592             void *tgt_data, void *ini_data);
0593 int efc_nport_vport_del(struct efc *efc, struct efc_domain *domain,
0594             u64 wwpn, u64 wwnn);
0595 
0596 void efc_vport_del_all(struct efc *efc);
0597 
0598 /*
0599  * EFC Node
0600  * **********************************/
0601 int efc_remote_node_cb(void *arg, int event, void *data);
0602 void efc_node_fcid_display(u32 fc_id, char *buffer, u32 buf_len);
0603 void efc_node_post_shutdown(struct efc_node *node, void *arg);
0604 u64 efc_node_get_wwpn(struct efc_node *node);
0605 
0606 /*
0607  * EFC FCP/ELS/CT interface
0608  * **********************************/
0609 void efc_dispatch_frame(struct efc *efc, struct efc_hw_sequence *seq);
0610 void efc_disc_io_complete(struct efc_disc_io *io, u32 len, u32 status,
0611               u32 ext_status);
0612 
0613 /*
0614  * EFC SCSI INTERACTION LAYER
0615  * **********************************/
0616 void efc_scsi_sess_reg_complete(struct efc_node *node, u32 status);
0617 void efc_scsi_del_initiator_complete(struct efc *efc, struct efc_node *node);
0618 void efc_scsi_del_target_complete(struct efc *efc, struct efc_node *node);
0619 void efc_scsi_io_list_empty(struct efc *efc, struct efc_node *node);
0620 
0621 #endif /* __EFCLIB_H__ */