Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
0004  * Copyright (c) 2014- QLogic Corporation.
0005  * All rights reserved
0006  * www.qlogic.com
0007  *
0008  * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
0009  */
0010 
0011 #ifndef __BFA_SVC_H__
0012 #define __BFA_SVC_H__
0013 
0014 #include "bfa_cs.h"
0015 #include "bfi_ms.h"
0016 
0017 
0018 /*
0019  * Scatter-gather DMA related defines
0020  */
0021 #define BFA_SGPG_MIN    (16)
0022 #define BFA_SGPG_MAX    (8192)
0023 
0024 /*
0025  * Alignment macro for SG page allocation
0026  */
0027 #define BFA_SGPG_ROUNDUP(_l) (((_l) + (sizeof(struct bfi_sgpg_s) - 1))  \
0028                   & ~(sizeof(struct bfi_sgpg_s) - 1))
0029 
0030 struct bfa_sgpg_wqe_s {
0031     struct list_head qe;    /*  queue sg page element   */
0032     int nsgpg;      /*  pages to be allocated   */
0033     int nsgpg_total;    /*  total pages required    */
0034     void    (*cbfn) (void *cbarg);  /*  callback function   */
0035     void    *cbarg;     /*  callback arg        */
0036     struct list_head sgpg_q;    /*  queue of alloced sgpgs  */
0037 };
0038 
0039 struct bfa_sgpg_s {
0040     struct list_head  qe;   /*  queue sg page element   */
0041     struct bfi_sgpg_s *sgpg;    /*  va of SG page       */
0042     union bfi_addr_u sgpg_pa;   /*  pa of SG page       */
0043 };
0044 
0045 /*
0046  * Given number of SG elements, BFA_SGPG_NPAGE() returns the number of
0047  * SG pages required.
0048  */
0049 #define BFA_SGPG_NPAGE(_nsges)  (((_nsges) / BFI_SGPG_DATA_SGES) + 1)
0050 
0051 /* Max SGPG dma segs required */
0052 #define BFA_SGPG_DMA_SEGS   \
0053     BFI_MEM_DMA_NSEGS(BFA_SGPG_MAX, (uint32_t)sizeof(struct bfi_sgpg_s))
0054 
0055 struct bfa_sgpg_mod_s {
0056     struct bfa_s *bfa;
0057     int     num_sgpgs;  /*  number of SG pages      */
0058     int     free_sgpgs; /*  number of free SG pages */
0059     struct list_head    sgpg_q;     /*  queue of free SG pages */
0060     struct list_head    sgpg_wait_q;    /*  wait queue for SG pages */
0061     struct bfa_mem_dma_s    dma_seg[BFA_SGPG_DMA_SEGS];
0062     struct bfa_mem_kva_s    kva_seg;
0063 };
0064 #define BFA_SGPG_MOD(__bfa) (&(__bfa)->modules.sgpg_mod)
0065 #define BFA_MEM_SGPG_KVA(__bfa) (&(BFA_SGPG_MOD(__bfa)->kva_seg))
0066 
0067 bfa_status_t bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q,
0068                  int nsgpgs);
0069 void bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs);
0070 void bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe,
0071             void (*cbfn) (void *cbarg), void *cbarg);
0072 void bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpgs);
0073 void bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe);
0074 
0075 
0076 /*
0077  * FCXP related defines
0078  */
0079 #define BFA_FCXP_MIN        (1)
0080 #define BFA_FCXP_MAX        (256)
0081 #define BFA_FCXP_MAX_IBUF_SZ    (2 * 1024 + 256)
0082 #define BFA_FCXP_MAX_LBUF_SZ    (4 * 1024 + 256)
0083 
0084 /* Max FCXP dma segs required */
0085 #define BFA_FCXP_DMA_SEGS                       \
0086     BFI_MEM_DMA_NSEGS(BFA_FCXP_MAX,                 \
0087         (u32)BFA_FCXP_MAX_IBUF_SZ + BFA_FCXP_MAX_LBUF_SZ)
0088 
0089 struct bfa_fcxp_mod_s {
0090     struct bfa_s      *bfa;     /* backpointer to BFA */
0091     struct bfa_fcxp_s *fcxp_list;   /* array of FCXPs */
0092     u16 num_fcxps;  /* max num FCXP requests */
0093     struct list_head fcxp_req_free_q; /* free FCXPs used for sending req */
0094     struct list_head fcxp_rsp_free_q; /* free FCXPs used for sending req */
0095     struct list_head fcxp_active_q; /* active FCXPs */
0096     struct list_head req_wait_q;    /* wait queue for free req_fcxp */
0097     struct list_head rsp_wait_q;    /* wait queue for free rsp_fcxp */
0098     struct list_head fcxp_req_unused_q; /* unused req_fcxps */
0099     struct list_head fcxp_rsp_unused_q; /* unused rsp_fcxps */
0100     u32 req_pld_sz;
0101     u32 rsp_pld_sz;
0102     struct bfa_mem_dma_s dma_seg[BFA_FCXP_DMA_SEGS];
0103     struct bfa_mem_kva_s kva_seg;
0104 };
0105 
0106 #define BFA_FCXP_MOD(__bfa)     (&(__bfa)->modules.fcxp_mod)
0107 #define BFA_FCXP_FROM_TAG(__mod, __tag) (&(__mod)->fcxp_list[__tag])
0108 #define BFA_MEM_FCXP_KVA(__bfa) (&(BFA_FCXP_MOD(__bfa)->kva_seg))
0109 
0110 typedef void    (*fcxp_send_cb_t) (struct bfa_s *ioc, struct bfa_fcxp_s *fcxp,
0111                    void *cb_arg, bfa_status_t req_status,
0112                    u32 rsp_len, u32 resid_len,
0113                    struct fchs_s *rsp_fchs);
0114 
0115 typedef u64 (*bfa_fcxp_get_sgaddr_t) (void *bfad_fcxp, int sgeid);
0116 typedef u32 (*bfa_fcxp_get_sglen_t) (void *bfad_fcxp, int sgeid);
0117 typedef void (*bfa_cb_fcxp_send_t) (void *bfad_fcxp, struct bfa_fcxp_s *fcxp,
0118                     void *cbarg, enum bfa_status req_status,
0119                     u32 rsp_len, u32 resid_len,
0120                     struct fchs_s *rsp_fchs);
0121 typedef void (*bfa_fcxp_alloc_cbfn_t) (void *cbarg, struct bfa_fcxp_s *fcxp);
0122 
0123 
0124 
0125 /*
0126  * Information needed for a FCXP request
0127  */
0128 struct bfa_fcxp_req_info_s {
0129     struct bfa_rport_s *bfa_rport;
0130                     /* Pointer to the bfa rport that was
0131                      * returned from bfa_rport_create().
0132                      * This could be left NULL for WKA or
0133                      * for FCXP interactions before the
0134                      * rport nexus is established
0135                      */
0136     struct fchs_s   fchs;   /*  request FC header structure */
0137     u8      cts;    /*  continuous sequence */
0138     u8      class;  /*  FC class for the request/response */
0139     u16 max_frmsz;  /*  max send frame size */
0140     u16 vf_id;  /*  vsan tag if applicable */
0141     u8      lp_tag; /*  lport tag */
0142     u32 req_tot_len;    /*  request payload total length */
0143 };
0144 
0145 struct bfa_fcxp_rsp_info_s {
0146     struct fchs_s   rsp_fchs;
0147                 /* Response frame's FC header will
0148                  * be sent back in this field */
0149     u8      rsp_timeout;
0150                 /* timeout in seconds, 0-no response */
0151     u8      rsvd2[3];
0152     u32 rsp_maxlen; /*  max response length expected */
0153 };
0154 
0155 struct bfa_fcxp_s {
0156     struct list_head    qe;     /*  fcxp queue element */
0157     bfa_sm_t    sm;     /*  state machine */
0158     void        *caller;    /*  driver or fcs */
0159     struct bfa_fcxp_mod_s *fcxp_mod;
0160     /*  back pointer to fcxp mod */
0161     u16 fcxp_tag;   /*  internal tag */
0162     struct bfa_fcxp_req_info_s req_info;
0163     /*  request info */
0164     struct bfa_fcxp_rsp_info_s rsp_info;
0165     /*  response info */
0166     u8  use_ireqbuf;    /*  use internal req buf */
0167     u8      use_irspbuf;    /*  use internal rsp buf */
0168     u32 nreq_sgles; /*  num request SGLEs */
0169     u32 nrsp_sgles; /*  num response SGLEs */
0170     struct list_head req_sgpg_q;    /*  SG pages for request buf */
0171     struct list_head req_sgpg_wqe;  /*  wait queue for req SG page */
0172     struct list_head rsp_sgpg_q;    /*  SG pages for response buf */
0173     struct list_head rsp_sgpg_wqe;  /*  wait queue for rsp SG page */
0174 
0175     bfa_fcxp_get_sgaddr_t req_sga_cbfn;
0176     /*  SG elem addr user function */
0177     bfa_fcxp_get_sglen_t req_sglen_cbfn;
0178     /*  SG elem len user function */
0179     bfa_fcxp_get_sgaddr_t rsp_sga_cbfn;
0180     /*  SG elem addr user function */
0181     bfa_fcxp_get_sglen_t rsp_sglen_cbfn;
0182     /*  SG elem len user function */
0183     bfa_cb_fcxp_send_t send_cbfn;   /*  send completion callback */
0184     void        *send_cbarg;    /*  callback arg */
0185     struct bfa_sge_s   req_sge[BFA_FCXP_MAX_SGES];
0186     /*  req SG elems */
0187     struct bfa_sge_s   rsp_sge[BFA_FCXP_MAX_SGES];
0188     /*  rsp SG elems */
0189     u8      rsp_status; /*  comp: rsp status */
0190     u32 rsp_len;    /*  comp: actual response len */
0191     u32 residue_len;    /*  comp: residual rsp length */
0192     struct fchs_s   rsp_fchs;   /*  comp: response fchs */
0193     struct bfa_cb_qe_s    hcb_qe;   /*  comp: callback qelem */
0194     struct bfa_reqq_wait_s  reqq_wqe;
0195     bfa_boolean_t   reqq_waiting;
0196     bfa_boolean_t   req_rsp;    /* Used to track req/rsp fcxp */
0197 };
0198 
0199 struct bfa_fcxp_wqe_s {
0200     struct list_head        qe;
0201     bfa_fcxp_alloc_cbfn_t   alloc_cbfn;
0202     void        *alloc_cbarg;
0203     void        *caller;
0204     struct bfa_s    *bfa;
0205     int     nreq_sgles;
0206     int     nrsp_sgles;
0207     bfa_fcxp_get_sgaddr_t   req_sga_cbfn;
0208     bfa_fcxp_get_sglen_t    req_sglen_cbfn;
0209     bfa_fcxp_get_sgaddr_t   rsp_sga_cbfn;
0210     bfa_fcxp_get_sglen_t    rsp_sglen_cbfn;
0211 };
0212 
0213 #define BFA_FCXP_REQ_PLD(_fcxp)     (bfa_fcxp_get_reqbuf(_fcxp))
0214 #define BFA_FCXP_RSP_FCHS(_fcxp)    (&((_fcxp)->rsp_info.fchs))
0215 #define BFA_FCXP_RSP_PLD(_fcxp)     (bfa_fcxp_get_rspbuf(_fcxp))
0216 
0217 #define BFA_FCXP_REQ_PLD_PA(_fcxp)                        \
0218     bfa_mem_get_dmabuf_pa((_fcxp)->fcxp_mod, (_fcxp)->fcxp_tag,       \
0219         (_fcxp)->fcxp_mod->req_pld_sz + (_fcxp)->fcxp_mod->rsp_pld_sz)
0220 
0221 /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */
0222 #define BFA_FCXP_RSP_PLD_PA(_fcxp)                         \
0223     (bfa_mem_get_dmabuf_pa((_fcxp)->fcxp_mod, (_fcxp)->fcxp_tag,           \
0224           (_fcxp)->fcxp_mod->req_pld_sz + (_fcxp)->fcxp_mod->rsp_pld_sz) + \
0225           (_fcxp)->fcxp_mod->req_pld_sz)
0226 
0227 void    bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
0228 
0229 
0230 /*
0231  * RPORT related defines
0232  */
0233 enum bfa_rport_event {
0234     BFA_RPORT_SM_CREATE = 1,    /*  rport create event          */
0235     BFA_RPORT_SM_DELETE = 2,    /*  deleting an existing rport  */
0236     BFA_RPORT_SM_ONLINE = 3,    /*  rport is online             */
0237     BFA_RPORT_SM_OFFLINE    = 4,    /*  rport is offline            */
0238     BFA_RPORT_SM_FWRSP  = 5,    /*  firmware response           */
0239     BFA_RPORT_SM_HWFAIL = 6,    /*  IOC h/w failure             */
0240     BFA_RPORT_SM_QOS_SCN    = 7,    /*  QoS SCN from firmware       */
0241     BFA_RPORT_SM_SET_SPEED  = 8,    /*  Set Rport Speed             */
0242     BFA_RPORT_SM_QRESUME    = 9,    /*  space in requeue queue      */
0243 };
0244 
0245 #define BFA_RPORT_MIN   4
0246 
0247 struct bfa_rport_mod_s {
0248     struct bfa_rport_s *rps_list;   /*  list of rports  */
0249     struct list_head    rp_free_q;  /*  free bfa_rports */
0250     struct list_head    rp_active_q;    /*  free bfa_rports */
0251     struct list_head    rp_unused_q;    /*  unused bfa rports  */
0252     u16 num_rports; /*  number of rports    */
0253     struct bfa_mem_kva_s    kva_seg;
0254 };
0255 
0256 #define BFA_RPORT_MOD(__bfa)    (&(__bfa)->modules.rport_mod)
0257 #define BFA_MEM_RPORT_KVA(__bfa) (&(BFA_RPORT_MOD(__bfa)->kva_seg))
0258 
0259 /*
0260  * Convert rport tag to RPORT
0261  */
0262 #define BFA_RPORT_FROM_TAG(__bfa, _tag)             \
0263     (BFA_RPORT_MOD(__bfa)->rps_list +           \
0264      ((_tag) & (BFA_RPORT_MOD(__bfa)->num_rports - 1)))
0265 
0266 /*
0267  * protected functions
0268  */
0269 void    bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
0270 void    bfa_rport_res_recfg(struct bfa_s *bfa, u16 num_rport_fw);
0271 
0272 /*
0273  *  BFA rport information.
0274  */
0275 struct bfa_rport_info_s {
0276     u16 max_frmsz;  /*  max rcv pdu size            */
0277     u32 pid:24, /*  remote port ID          */
0278         lp_tag:8;   /*  tag             */
0279     u32 local_pid:24,   /*  local port ID           */
0280         cisc:8; /*  CIRO supported          */
0281     u8  fc_class;   /*  supported FC classes. enum fc_cos */
0282     u8  vf_en;      /*  virtual fabric enable       */
0283     u16 vf_id;      /*  virtual fabric ID           */
0284     enum bfa_port_speed speed;  /*  Rport's current speed       */
0285 };
0286 
0287 /*
0288  * BFA rport data structure
0289  */
0290 struct bfa_rport_s {
0291     struct list_head    qe; /*  queue element           */
0292     bfa_sm_t    sm;     /*  state machine           */
0293     struct bfa_s    *bfa;       /*  backpointer to BFA          */
0294     void        *rport_drv; /*  fcs/driver rport object     */
0295     u16 fw_handle;  /*  firmware rport handle       */
0296     u16 rport_tag;  /*  BFA rport tag           */
0297     u8  lun_mask;   /*  LUN mask flag           */
0298     struct bfa_rport_info_s rport_info; /*  rport info from fcs/driver */
0299     struct bfa_reqq_wait_s reqq_wait; /*  to wait for room in reqq     */
0300     struct bfa_cb_qe_s hcb_qe;  /*  BFA callback qelem          */
0301     struct bfa_rport_hal_stats_s stats; /*  BFA rport statistics        */
0302     struct bfa_rport_qos_attr_s qos_attr;
0303     union a {
0304         bfa_status_t    status; /*  f/w status */
0305         void        *fw_msg; /*  QoS scn event          */
0306     } event_arg;
0307 };
0308 #define BFA_RPORT_FC_COS(_rport)    ((_rport)->rport_info.fc_class)
0309 
0310 
0311 /*
0312  * UF - unsolicited receive related defines
0313  */
0314 
0315 #define BFA_UF_MIN  (4)
0316 #define BFA_UF_MAX  (256)
0317 
0318 struct bfa_uf_s {
0319     struct list_head    qe; /*  queue element       */
0320     struct bfa_s        *bfa;   /*  bfa instance        */
0321     u16 uf_tag;     /*  identifying tag fw msgs */
0322     u16 vf_id;
0323     u16 src_rport_handle;
0324     u16 rsvd;
0325     u8      *data_ptr;
0326     u16 data_len;   /*  actual receive length   */
0327     u16 pb_len;     /*  posted buffer length    */
0328     void        *buf_kva;   /*  buffer virtual address  */
0329     u64 buf_pa;     /*  buffer physical address */
0330     struct bfa_cb_qe_s hcb_qe;  /*  comp: BFA comp qelem    */
0331     struct bfa_sge_s sges[BFI_SGE_INLINE_MAX];
0332 };
0333 
0334 /*
0335  *      Callback prototype for unsolicited frame receive handler.
0336  *
0337  * @param[in]           cbarg           callback arg for receive handler
0338  * @param[in]           uf              unsolicited frame descriptor
0339  *
0340  * @return None
0341  */
0342 typedef void (*bfa_cb_uf_recv_t) (void *cbarg, struct bfa_uf_s *uf);
0343 
0344 #define BFA_UF_BUFSZ    (2 * 1024 + 256)
0345 
0346 struct bfa_uf_buf_s {
0347     u8  d[BFA_UF_BUFSZ];
0348 };
0349 
0350 #define BFA_PER_UF_DMA_SZ   \
0351     (u32)BFA_ROUNDUP(sizeof(struct bfa_uf_buf_s), BFA_DMA_ALIGN_SZ)
0352 
0353 /* Max UF dma segs required */
0354 #define BFA_UF_DMA_SEGS BFI_MEM_DMA_NSEGS(BFA_UF_MAX, BFA_PER_UF_DMA_SZ)
0355 
0356 struct bfa_uf_mod_s {
0357     struct bfa_s *bfa;      /*  back pointer to BFA */
0358     struct bfa_uf_s *uf_list;   /*  array of UFs */
0359     u16 num_ufs;    /*  num unsolicited rx frames */
0360     struct list_head    uf_free_q;  /*  free UFs */
0361     struct list_head    uf_posted_q;    /*  UFs posted to IOC */
0362     struct list_head    uf_unused_q;    /*  unused UF's */
0363     struct bfi_uf_buf_post_s *uf_buf_posts;
0364     /*  pre-built UF post msgs */
0365     bfa_cb_uf_recv_t ufrecv;    /*  uf recv handler function */
0366     void        *cbarg;     /*  uf receive handler arg */
0367     struct bfa_mem_dma_s    dma_seg[BFA_UF_DMA_SEGS];
0368     struct bfa_mem_kva_s    kva_seg;
0369 };
0370 
0371 #define BFA_UF_MOD(__bfa)   (&(__bfa)->modules.uf_mod)
0372 #define BFA_MEM_UF_KVA(__bfa)   (&(BFA_UF_MOD(__bfa)->kva_seg))
0373 
0374 #define ufm_pbs_pa(_ufmod, _uftag)                  \
0375     bfa_mem_get_dmabuf_pa(_ufmod, _uftag, BFA_PER_UF_DMA_SZ)
0376 
0377 void    bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
0378 void    bfa_uf_res_recfg(struct bfa_s *bfa, u16 num_uf_fw);
0379 
0380 /*
0381  * LPS - bfa lport login/logout service interface
0382  */
0383 struct bfa_lps_s {
0384     struct list_head    qe; /*  queue element       */
0385     struct bfa_s    *bfa;       /*  parent bfa instance */
0386     bfa_sm_t    sm;     /*  finite state machine    */
0387     u8      bfa_tag;    /*  lport tag       */
0388     u8      fw_tag;     /*  lport fw tag                */
0389     u8      reqq;       /*  lport request queue */
0390     u8      alpa;       /*  ALPA for loop topologies    */
0391     u32 lp_pid;     /*  lport port ID       */
0392     bfa_boolean_t   fdisc;      /*  snd FDISC instead of FLOGI  */
0393     bfa_boolean_t   auth_en;    /*  enable authentication   */
0394     bfa_boolean_t   auth_req;   /*  authentication required */
0395     bfa_boolean_t   npiv_en;    /*  NPIV is allowed by peer */
0396     bfa_boolean_t   fport;      /*  attached peer is F_PORT */
0397     bfa_boolean_t   brcd_switch;    /*  attached peer is brcd sw    */
0398     bfa_status_t    status;     /*  login status        */
0399     u16     pdusz;      /*  max receive PDU size    */
0400     u16     pr_bbcred;  /*  BB_CREDIT from peer     */
0401     u8      lsrjt_rsn;  /*  LSRJT reason        */
0402     u8      lsrjt_expl; /*  LSRJT explanation       */
0403     u8      lun_mask;   /*  LUN mask flag       */
0404     wwn_t       pwwn;       /*  port wwn of lport       */
0405     wwn_t       nwwn;       /*  node wwn of lport       */
0406     wwn_t       pr_pwwn;    /*  port wwn of lport peer  */
0407     wwn_t       pr_nwwn;    /*  node wwn of lport peer  */
0408     mac_t       lp_mac;     /*  fpma/spma MAC for lport */
0409     mac_t       fcf_mac;    /*  FCF MAC of lport        */
0410     struct bfa_reqq_wait_s  wqe;    /*  request wait queue element  */
0411     void        *uarg;      /*  user callback arg       */
0412     struct bfa_cb_qe_s hcb_qe;  /*  comp: callback qelem    */
0413     struct bfi_lps_login_rsp_s *loginrsp;
0414     bfa_eproto_status_t ext_status;
0415 };
0416 
0417 struct bfa_lps_mod_s {
0418     struct list_head        lps_free_q;
0419     struct list_head        lps_active_q;
0420     struct list_head        lps_login_q;
0421     struct bfa_lps_s    *lps_arr;
0422     int         num_lps;
0423     struct bfa_mem_kva_s    kva_seg;
0424 };
0425 
0426 #define BFA_LPS_MOD(__bfa)      (&(__bfa)->modules.lps_mod)
0427 #define BFA_LPS_FROM_TAG(__mod, __tag)  (&(__mod)->lps_arr[__tag])
0428 #define BFA_MEM_LPS_KVA(__bfa)  (&(BFA_LPS_MOD(__bfa)->kva_seg))
0429 
0430 /*
0431  * external functions
0432  */
0433 void    bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
0434 
0435 
0436 /*
0437  * FCPORT related defines
0438  */
0439 
0440 #define BFA_FCPORT(_bfa)    (&((_bfa)->modules.port))
0441 
0442 /*
0443  * Link notification data structure
0444  */
0445 struct bfa_fcport_ln_s {
0446     struct bfa_fcport_s *fcport;
0447     bfa_sm_t        sm;
0448     struct bfa_cb_qe_s  ln_qe;  /*  BFA callback queue elem for ln */
0449     enum bfa_port_linkstate ln_event; /*  ln event for callback */
0450 };
0451 
0452 struct bfa_fcport_trunk_s {
0453     struct bfa_trunk_attr_s attr;
0454 };
0455 
0456 /*
0457  * BFA FC port data structure
0458  */
0459 struct bfa_fcport_s {
0460     struct bfa_s        *bfa;   /*  parent BFA instance */
0461     bfa_sm_t        sm; /*  port state machine */
0462     wwn_t           nwwn;   /*  node wwn of physical port */
0463     wwn_t           pwwn;   /*  port wwn of physical oprt */
0464     enum bfa_port_speed speed_sup;
0465     /*  supported speeds */
0466     enum bfa_port_speed speed;  /*  current speed */
0467     enum bfa_port_topology topology;    /*  current topology */
0468     u8          rsvd[3];
0469     u8          myalpa; /*  my ALPA in LOOP topology */
0470     u8          alpabm_valid; /* alpa bitmap valid or not */
0471     struct fc_alpabm_s  alpabm; /* alpa bitmap */
0472     struct bfa_port_cfg_s   cfg;    /*  current port configuration */
0473     bfa_boolean_t       use_flash_cfg; /* get port cfg from flash */
0474     struct bfa_qos_attr_s  qos_attr;   /* QoS Attributes */
0475     struct bfa_qos_vc_attr_s qos_vc_attr;  /*  VC info from ELP */
0476     struct bfa_reqq_wait_s  reqq_wait;
0477     /*  to wait for room in reqq */
0478     struct bfa_reqq_wait_s  svcreq_wait;
0479     /*  to wait for room in reqq */
0480     struct bfa_reqq_wait_s  stats_reqq_wait;
0481     /*  to wait for room in reqq (stats) */
0482     void            *event_cbarg;
0483     void            (*event_cbfn) (void *cbarg,
0484                            enum bfa_port_linkstate event);
0485     union {
0486         union bfi_fcport_i2h_msg_u i2hmsg;
0487     } event_arg;
0488     void            *bfad;  /*  BFA driver handle */
0489     struct bfa_fcport_ln_s  ln; /*  Link Notification */
0490     struct bfa_cb_qe_s  hcb_qe; /*  BFA callback queue elem */
0491     struct bfa_timer_s  timer;  /*  timer */
0492     u32     msgtag; /*  fimrware msg tag for reply */
0493     u8          *stats_kva;
0494     u64     stats_pa;
0495     union bfa_fcport_stats_u *stats;
0496     bfa_status_t        stats_status; /*  stats/statsclr status */
0497     struct list_head    stats_pending_q;
0498     struct list_head    statsclr_pending_q;
0499     bfa_boolean_t       stats_qfull;
0500     time64_t        stats_reset_time; /*  stats reset time stamp */
0501     bfa_boolean_t       diag_busy; /*  diag busy status */
0502     bfa_boolean_t       beacon; /*  port beacon status */
0503     bfa_boolean_t       link_e2e_beacon; /*  link beacon status */
0504     struct bfa_fcport_trunk_s trunk;
0505     u16     fcoe_vlan;
0506     struct bfa_mem_dma_s    fcport_dma;
0507     bfa_boolean_t       stats_dma_ready;
0508     struct bfa_bbcr_attr_s  bbcr_attr;
0509     enum bfa_fec_state_s    fec_state;
0510 };
0511 
0512 #define BFA_FCPORT_MOD(__bfa)   (&(__bfa)->modules.fcport)
0513 #define BFA_MEM_FCPORT_DMA(__bfa) (&(BFA_FCPORT_MOD(__bfa)->fcport_dma))
0514 
0515 /*
0516  * protected functions
0517  */
0518 void bfa_fcport_init(struct bfa_s *bfa);
0519 void bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
0520 
0521 /*
0522  * bfa fcport API functions
0523  */
0524 bfa_status_t bfa_fcport_enable(struct bfa_s *bfa);
0525 bfa_status_t bfa_fcport_disable(struct bfa_s *bfa);
0526 bfa_status_t bfa_fcport_cfg_speed(struct bfa_s *bfa,
0527                   enum bfa_port_speed speed);
0528 enum bfa_port_speed bfa_fcport_get_speed(struct bfa_s *bfa);
0529 bfa_status_t bfa_fcport_cfg_topology(struct bfa_s *bfa,
0530                      enum bfa_port_topology topo);
0531 enum bfa_port_topology bfa_fcport_get_topology(struct bfa_s *bfa);
0532 enum bfa_port_topology bfa_fcport_get_cfg_topology(struct bfa_s *bfa);
0533 bfa_status_t bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa);
0534 bfa_boolean_t bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa);
0535 u8 bfa_fcport_get_myalpa(struct bfa_s *bfa);
0536 bfa_status_t bfa_fcport_clr_hardalpa(struct bfa_s *bfa);
0537 bfa_status_t bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxsize);
0538 u16 bfa_fcport_get_maxfrsize(struct bfa_s *bfa);
0539 u8 bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa);
0540 void bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr);
0541 wwn_t bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node);
0542 void bfa_fcport_event_register(struct bfa_s *bfa,
0543             void (*event_cbfn) (void *cbarg,
0544             enum bfa_port_linkstate event), void *event_cbarg);
0545 bfa_boolean_t bfa_fcport_is_disabled(struct bfa_s *bfa);
0546 bfa_boolean_t bfa_fcport_is_dport(struct bfa_s *bfa);
0547 bfa_boolean_t bfa_fcport_is_ddport(struct bfa_s *bfa);
0548 bfa_status_t bfa_fcport_set_qos_bw(struct bfa_s *bfa,
0549                    struct bfa_qos_bw_s *qos_bw);
0550 enum bfa_port_speed bfa_fcport_get_ratelim_speed(struct bfa_s *bfa);
0551 
0552 void bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit);
0553 bfa_boolean_t     bfa_fcport_is_ratelim(struct bfa_s *bfa);
0554 void bfa_fcport_beacon(void *dev, bfa_boolean_t beacon,
0555             bfa_boolean_t link_e2e_beacon);
0556 bfa_boolean_t   bfa_fcport_is_linkup(struct bfa_s *bfa);
0557 bfa_status_t bfa_fcport_get_stats(struct bfa_s *bfa,
0558             struct bfa_cb_pending_q_s *cb);
0559 bfa_status_t bfa_fcport_clear_stats(struct bfa_s *bfa,
0560             struct bfa_cb_pending_q_s *cb);
0561 bfa_boolean_t bfa_fcport_is_qos_enabled(struct bfa_s *bfa);
0562 bfa_boolean_t bfa_fcport_is_trunk_enabled(struct bfa_s *bfa);
0563 void bfa_fcport_dportenable(struct bfa_s *bfa);
0564 void bfa_fcport_dportdisable(struct bfa_s *bfa);
0565 bfa_status_t bfa_fcport_is_pbcdisabled(struct bfa_s *bfa);
0566 void bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state);
0567 bfa_status_t bfa_fcport_cfg_bbcr(struct bfa_s *bfa,
0568             bfa_boolean_t on_off, u8 bb_scn);
0569 bfa_status_t bfa_fcport_get_bbcr_attr(struct bfa_s *bfa,
0570             struct bfa_bbcr_attr_s *bbcr_attr);
0571 
0572 /*
0573  * bfa rport API functions
0574  */
0575 struct bfa_rport_s *bfa_rport_create(struct bfa_s *bfa, void *rport_drv);
0576 void bfa_rport_online(struct bfa_rport_s *rport,
0577               struct bfa_rport_info_s *rport_info);
0578 void bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed);
0579 void bfa_cb_rport_online(void *rport);
0580 void bfa_cb_rport_offline(void *rport);
0581 void bfa_cb_rport_qos_scn_flowid(void *rport,
0582                  struct bfa_rport_qos_attr_s old_qos_attr,
0583                  struct bfa_rport_qos_attr_s new_qos_attr);
0584 void bfa_cb_rport_scn_online(struct bfa_s *bfa);
0585 void bfa_cb_rport_scn_offline(struct bfa_s *bfa);
0586 void bfa_cb_rport_scn_no_dev(void *rp);
0587 void bfa_cb_rport_qos_scn_prio(void *rport,
0588                    struct bfa_rport_qos_attr_s old_qos_attr,
0589                    struct bfa_rport_qos_attr_s new_qos_attr);
0590 
0591 /*
0592  *  Rport LUN masking related
0593  */
0594 #define BFA_RPORT_TAG_INVALID   0xffff
0595 #define BFA_LP_TAG_INVALID  0xff
0596 void    bfa_rport_set_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp);
0597 void    bfa_rport_unset_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp);
0598 
0599 /*
0600  * bfa fcxp API functions
0601  */
0602 struct bfa_fcxp_s *bfa_fcxp_req_rsp_alloc(void *bfad_fcxp, struct bfa_s *bfa,
0603                   int nreq_sgles, int nrsp_sgles,
0604                   bfa_fcxp_get_sgaddr_t get_req_sga,
0605                   bfa_fcxp_get_sglen_t get_req_sglen,
0606                   bfa_fcxp_get_sgaddr_t get_rsp_sga,
0607                   bfa_fcxp_get_sglen_t get_rsp_sglen,
0608                   bfa_boolean_t req);
0609 void bfa_fcxp_req_rsp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
0610                 bfa_fcxp_alloc_cbfn_t alloc_cbfn,
0611                 void *cbarg, void *bfad_fcxp,
0612                 int nreq_sgles, int nrsp_sgles,
0613                 bfa_fcxp_get_sgaddr_t get_req_sga,
0614                 bfa_fcxp_get_sglen_t get_req_sglen,
0615                 bfa_fcxp_get_sgaddr_t get_rsp_sga,
0616                 bfa_fcxp_get_sglen_t get_rsp_sglen,
0617                 bfa_boolean_t req);
0618 void bfa_fcxp_walloc_cancel(struct bfa_s *bfa,
0619                 struct bfa_fcxp_wqe_s *wqe);
0620 void bfa_fcxp_discard(struct bfa_fcxp_s *fcxp);
0621 
0622 void *bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp);
0623 void *bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp);
0624 
0625 void bfa_fcxp_free(struct bfa_fcxp_s *fcxp);
0626 
0627 void bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
0628            u16 vf_id, u8 lp_tag,
0629            bfa_boolean_t cts, enum fc_cos cos,
0630            u32 reqlen, struct fchs_s *fchs,
0631            bfa_cb_fcxp_send_t cbfn,
0632            void *cbarg,
0633            u32 rsp_maxlen, u8 rsp_timeout);
0634 bfa_status_t bfa_fcxp_abort(struct bfa_fcxp_s *fcxp);
0635 u32 bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp);
0636 u32 bfa_fcxp_get_maxrsp(struct bfa_s *bfa);
0637 void bfa_fcxp_res_recfg(struct bfa_s *bfa, u16 num_fcxp_fw);
0638 
0639 static inline void *
0640 bfa_uf_get_frmbuf(struct bfa_uf_s *uf)
0641 {
0642     return uf->data_ptr;
0643 }
0644 
0645 static inline   u16
0646 bfa_uf_get_frmlen(struct bfa_uf_s *uf)
0647 {
0648     return uf->data_len;
0649 }
0650 
0651 /*
0652  * bfa uf API functions
0653  */
0654 void bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv,
0655               void *cbarg);
0656 void bfa_uf_free(struct bfa_uf_s *uf);
0657 
0658 /*
0659  * bfa lport service api
0660  */
0661 
0662 u32 bfa_lps_get_max_vport(struct bfa_s *bfa);
0663 struct bfa_lps_s *bfa_lps_alloc(struct bfa_s *bfa);
0664 void bfa_lps_delete(struct bfa_lps_s *lps);
0665 void bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa,
0666            u16 pdusz, wwn_t pwwn, wwn_t nwwn,
0667            bfa_boolean_t auth_en);
0668 void bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz,
0669            wwn_t pwwn, wwn_t nwwn);
0670 void bfa_lps_fdisclogo(struct bfa_lps_s *lps);
0671 void bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, u32 n2n_pid);
0672 u8 bfa_lps_get_fwtag(struct bfa_s *bfa, u8 lp_tag);
0673 u32 bfa_lps_get_base_pid(struct bfa_s *bfa);
0674 u8 bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid);
0675 void bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status);
0676 void bfa_cb_lps_flogo_comp(void *bfad, void *uarg);
0677 void bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status);
0678 void bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg);
0679 void bfa_cb_lps_cvl_event(void *bfad, void *uarg);
0680 
0681 /* FAA specific APIs */
0682 bfa_status_t bfa_faa_query(struct bfa_s *bfa, struct bfa_faa_attr_s *attr,
0683             bfa_cb_iocfc_t cbfn, void *cbarg);
0684 
0685 /*
0686  *  FC DIAG data structure
0687  */
0688 struct bfa_fcdiag_qtest_s {
0689     struct bfa_diag_qtest_result_s *result;
0690     bfa_cb_diag_t   cbfn;
0691     void        *cbarg;
0692     struct bfa_timer_s  timer;
0693     u32 status;
0694     u32 count;
0695     u8  lock;
0696     u8  queue;
0697     u8  all;
0698     u8  timer_active;
0699 };
0700 
0701 struct bfa_fcdiag_lb_s {
0702     bfa_cb_diag_t   cbfn;
0703     void            *cbarg;
0704     void            *result;
0705     bfa_boolean_t   lock;
0706     u32        status;
0707 };
0708 
0709 struct bfa_dport_s {
0710     struct bfa_s    *bfa;       /* Back pointer to BFA  */
0711     bfa_sm_t    sm;     /* finite state machine */
0712     struct bfa_reqq_wait_s reqq_wait;
0713     bfa_cb_diag_t   cbfn;
0714     void        *cbarg;
0715     union bfi_diag_dport_msg_u i2hmsg;
0716     u8      test_state; /* enum dport_test_state  */
0717     u8      dynamic;    /* boolean_t  */
0718     u8      rsvd[2];
0719     u32     lpcnt;
0720     u32     payload;    /* user defined payload pattern */
0721     wwn_t       rp_pwwn;
0722     wwn_t       rp_nwwn;
0723     struct bfa_diag_dport_result_s result;
0724 };
0725 
0726 struct bfa_fcdiag_s {
0727     struct bfa_s    *bfa;           /* Back pointer to BFA */
0728     struct bfa_trc_mod_s   *trcmod;
0729     struct bfa_fcdiag_lb_s lb;
0730     struct bfa_fcdiag_qtest_s qtest;
0731     struct bfa_dport_s  dport;
0732 };
0733 
0734 #define BFA_FCDIAG_MOD(__bfa)   (&(__bfa)->modules.fcdiag)
0735 
0736 void    bfa_fcdiag_intr(struct bfa_s *bfa, struct bfi_msg_s *msg);
0737 
0738 bfa_status_t    bfa_fcdiag_loopback(struct bfa_s *bfa,
0739                 enum bfa_port_opmode opmode,
0740                 enum bfa_port_speed speed, u32 lpcnt, u32 pat,
0741                 struct bfa_diag_loopback_result_s *result,
0742                 bfa_cb_diag_t cbfn, void *cbarg);
0743 bfa_status_t    bfa_fcdiag_queuetest(struct bfa_s *bfa, u32 ignore,
0744             u32 queue, struct bfa_diag_qtest_result_s *result,
0745             bfa_cb_diag_t cbfn, void *cbarg);
0746 bfa_status_t    bfa_fcdiag_lb_is_running(struct bfa_s *bfa);
0747 bfa_status_t    bfa_dport_enable(struct bfa_s *bfa, u32 lpcnt, u32 pat,
0748                     bfa_cb_diag_t cbfn, void *cbarg);
0749 bfa_status_t    bfa_dport_disable(struct bfa_s *bfa, bfa_cb_diag_t cbfn,
0750                   void *cbarg);
0751 bfa_status_t    bfa_dport_start(struct bfa_s *bfa, u32 lpcnt, u32 pat,
0752                 bfa_cb_diag_t cbfn, void *cbarg);
0753 bfa_status_t    bfa_dport_show(struct bfa_s *bfa,
0754                 struct bfa_diag_dport_result_s *result);
0755 
0756 #endif /* __BFA_SVC_H__ */