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_FCPIM_H__
0012 #define __BFA_FCPIM_H__
0013 
0014 #include "bfa.h"
0015 #include "bfa_svc.h"
0016 #include "bfi_ms.h"
0017 #include "bfa_defs_svc.h"
0018 #include "bfa_cs.h"
0019 
0020 /* FCP module related definitions */
0021 #define BFA_IO_MAX  BFI_IO_MAX
0022 #define BFA_FWTIO_MAX   2000
0023 
0024 struct bfa_fcp_mod_s;
0025 struct bfa_iotag_s {
0026     struct list_head    qe; /* queue element    */
0027     u16 tag;            /* FW IO tag        */
0028 };
0029 
0030 struct bfa_itn_s {
0031     bfa_isr_func_t isr;
0032 };
0033 
0034 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
0035         void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
0036 void bfa_itn_isr(struct bfa_s *bfa, struct bfi_msg_s *m);
0037 void bfa_iotag_attach(struct bfa_fcp_mod_s *fcp);
0038 void bfa_fcp_res_recfg(struct bfa_s *bfa, u16 num_ioim_fw, u16 max_ioim_fw);
0039 
0040 #define BFA_FCP_MOD(_hal)   (&(_hal)->modules.fcp_mod)
0041 #define BFA_MEM_FCP_KVA(__bfa)  (&(BFA_FCP_MOD(__bfa)->kva_seg))
0042 #define BFA_IOTAG_FROM_TAG(_fcp, _tag)  \
0043     (&(_fcp)->iotag_arr[(_tag & BFA_IOIM_IOTAG_MASK)])
0044 #define BFA_ITN_FROM_TAG(_fcp, _tag)    \
0045     ((_fcp)->itn_arr + ((_tag) & ((_fcp)->num_itns - 1)))
0046 #define BFA_SNSINFO_FROM_TAG(_fcp, _tag) \
0047     bfa_mem_get_dmabuf_kva(_fcp, (_tag & BFA_IOIM_IOTAG_MASK),  \
0048     BFI_IOIM_SNSLEN)
0049 
0050 
0051 #define BFA_ITNIM_MIN   32
0052 #define BFA_ITNIM_MAX   1024
0053 
0054 #define BFA_IOIM_MIN    8
0055 #define BFA_IOIM_MAX    2000
0056 
0057 #define BFA_TSKIM_MIN   4
0058 #define BFA_TSKIM_MAX   512
0059 #define BFA_FCPIM_PATHTOV_DEF   (30 * 1000) /* in millisecs */
0060 #define BFA_FCPIM_PATHTOV_MAX   (90 * 1000) /* in millisecs */
0061 
0062 
0063 #define bfa_itnim_ioprofile_update(__itnim, __index)            \
0064     (__itnim->ioprofile.iocomps[__index]++)
0065 
0066 #define BFA_IOIM_RETRY_TAG_OFFSET 11
0067 #define BFA_IOIM_IOTAG_MASK 0x07ff /* 2K IOs */
0068 #define BFA_IOIM_RETRY_MAX 7
0069 
0070 /* Buckets are are 512 bytes to 2MB */
0071 static inline u32
0072 bfa_ioim_get_index(u32 n) {
0073     int pos = 0;
0074     if (n >= (1UL)<<22)
0075         return BFA_IOBUCKET_MAX - 1;
0076     n >>= 8;
0077     if (n >= (1UL)<<16) {
0078         n >>= 16;
0079         pos += 16;
0080     }
0081     if (n >= 1 << 8) {
0082         n >>= 8;
0083         pos += 8;
0084     }
0085     if (n >= 1 << 4) {
0086         n >>= 4;
0087         pos += 4;
0088     }
0089     if (n >= 1 << 2) {
0090         n >>= 2;
0091         pos += 2;
0092     }
0093     if (n >= 1 << 1)
0094         pos += 1;
0095 
0096     return (n == 0) ? (0) : pos;
0097 }
0098 
0099 /*
0100  * forward declarations
0101  */
0102 struct bfa_ioim_s;
0103 struct bfa_tskim_s;
0104 struct bfad_ioim_s;
0105 struct bfad_tskim_s;
0106 
0107 typedef void    (*bfa_fcpim_profile_t) (struct bfa_ioim_s *ioim);
0108 
0109 struct bfa_fcpim_s {
0110     struct bfa_s        *bfa;
0111     struct bfa_fcp_mod_s    *fcp;
0112     struct bfa_itnim_s  *itnim_arr;
0113     struct bfa_ioim_s   *ioim_arr;
0114     struct bfa_ioim_sp_s    *ioim_sp_arr;
0115     struct bfa_tskim_s  *tskim_arr;
0116     int         num_itnims;
0117     int         num_tskim_reqs;
0118     u32         path_tov;
0119     u16         q_depth;
0120     u8          reqq;       /*  Request queue to be used */
0121     struct list_head    itnim_q;    /*  queue of active itnim */
0122     struct list_head    ioim_resfree_q; /*  IOs waiting for f/w */
0123     struct list_head    ioim_comp_q;    /*  IO global comp Q    */
0124     struct list_head    tskim_free_q;
0125     struct list_head    tskim_unused_q; /* Unused tskim Q */
0126     u32         ios_active; /*  current active IOs  */
0127     u32         delay_comp;
0128     struct bfa_fcpim_del_itn_stats_s del_itn_stats;
0129     bfa_boolean_t       ioredirect;
0130     bfa_boolean_t       io_profile;
0131     time64_t        io_profile_start_time;
0132     bfa_fcpim_profile_t     profile_comp;
0133     bfa_fcpim_profile_t     profile_start;
0134 };
0135 
0136 /* Max FCP dma segs required */
0137 #define BFA_FCP_DMA_SEGS    BFI_IOIM_SNSBUF_SEGS
0138 
0139 struct bfa_fcp_mod_s {
0140     struct bfa_s        *bfa;
0141     struct list_head    iotag_ioim_free_q;  /* free IO resources */
0142     struct list_head    iotag_tio_free_q;   /* free IO resources */
0143     struct list_head    iotag_unused_q; /* unused IO resources*/
0144     struct bfa_iotag_s  *iotag_arr;
0145     struct bfa_itn_s    *itn_arr;
0146     int         max_ioim_reqs;
0147     int         num_ioim_reqs;
0148     int         num_fwtio_reqs;
0149     int         num_itns;
0150     struct bfa_dma_s    snsbase[BFA_FCP_DMA_SEGS];
0151     struct bfa_fcpim_s  fcpim;
0152     struct bfa_mem_dma_s    dma_seg[BFA_FCP_DMA_SEGS];
0153     struct bfa_mem_kva_s    kva_seg;
0154     int         throttle_update_required;
0155 };
0156 
0157 /*
0158  * BFA IO (initiator mode)
0159  */
0160 struct bfa_ioim_s {
0161     struct list_head    qe;     /*  queue elememt   */
0162     bfa_sm_t        sm;     /*  BFA ioim state machine */
0163     struct bfa_s        *bfa;       /*  BFA module  */
0164     struct bfa_fcpim_s  *fcpim;     /*  parent fcpim module */
0165     struct bfa_itnim_s  *itnim;     /*  i-t-n nexus for this IO  */
0166     struct bfad_ioim_s  *dio;       /*  driver IO handle    */
0167     u16         iotag;      /*  FWI IO tag  */
0168     u16         abort_tag;  /*  unqiue abort request tag */
0169     u16         nsges;      /*  number of SG elements */
0170     u16         nsgpgs;     /*  number of SG pages  */
0171     struct bfa_sgpg_s   *sgpg;      /*  first SG page   */
0172     struct list_head    sgpg_q;     /*  allocated SG pages  */
0173     struct bfa_cb_qe_s  hcb_qe;     /*  bfa callback qelem  */
0174     bfa_cb_cbfn_t       io_cbfn;    /*  IO completion handler */
0175     struct bfa_ioim_sp_s    *iosp;      /*  slow-path IO handling */
0176     u8          reqq;       /*  Request queue for I/O */
0177     u8          mode;       /*  IO is passthrough or not */
0178     u64         start_time; /*  IO's Profile start val */
0179 };
0180 
0181 struct bfa_ioim_sp_s {
0182     struct bfi_msg_s    comp_rspmsg;    /*  IO comp f/w response */
0183     struct bfa_sgpg_wqe_s   sgpg_wqe;   /*  waitq elem for sgpg */
0184     struct bfa_reqq_wait_s  reqq_wait;  /*  to wait for room in reqq */
0185     bfa_boolean_t       abort_explicit; /*  aborted by OS   */
0186     struct bfa_tskim_s  *tskim;     /*  Relevant TM cmd */
0187 };
0188 
0189 /*
0190  * BFA Task management command (initiator mode)
0191  */
0192 struct bfa_tskim_s {
0193     struct list_head    qe;
0194     bfa_sm_t        sm;
0195     struct bfa_s        *bfa;   /*  BFA module  */
0196     struct bfa_fcpim_s  *fcpim; /*  parent fcpim module */
0197     struct bfa_itnim_s  *itnim; /*  i-t-n nexus for this IO  */
0198     struct bfad_tskim_s *dtsk;  /*  driver task mgmt cmnd   */
0199     bfa_boolean_t       notify; /*  notify itnim on TM comp  */
0200     struct scsi_lun     lun;    /*  lun if applicable   */
0201     enum fcp_tm_cmnd    tm_cmnd; /*  task management command  */
0202     u16         tsk_tag; /*  FWI IO tag */
0203     u8          tsecs;  /*  timeout in seconds  */
0204     struct bfa_reqq_wait_s  reqq_wait;   /*  to wait for room in reqq */
0205     struct list_head    io_q;   /*  queue of affected IOs   */
0206     struct bfa_wc_s     wc; /*  waiting counter */
0207     struct bfa_cb_qe_s  hcb_qe; /*  bfa callback qelem  */
0208     enum bfi_tskim_status   tsk_status;  /*  TM status  */
0209 };
0210 
0211 /*
0212  * BFA i-t-n (initiator mode)
0213  */
0214 struct bfa_itnim_s {
0215     struct list_head    qe; /*  queue element   */
0216     bfa_sm_t        sm; /*  i-t-n im BFA state machine  */
0217     struct bfa_s        *bfa;   /*  bfa instance    */
0218     struct bfa_rport_s  *rport; /*  bfa rport   */
0219     void            *ditn;  /*  driver i-t-n structure  */
0220     struct bfi_mhdr_s   mhdr;   /*  pre-built mhdr  */
0221     u8          msg_no; /*  itnim/rport firmware handle */
0222     u8          reqq;   /*  CQ for requests */
0223     struct bfa_cb_qe_s  hcb_qe; /*  bfa callback qelem  */
0224     struct list_head pending_q; /*  queue of pending IO requests */
0225     struct list_head io_q;      /*  queue of active IO requests */
0226     struct list_head io_cleanup_q;  /*  IO being cleaned up */
0227     struct list_head tsk_q;     /*  queue of active TM commands */
0228     struct list_head  delay_comp_q; /*  queue of failed inflight cmds */
0229     bfa_boolean_t   seq_rec;    /*  SQER supported  */
0230     bfa_boolean_t   is_online;  /*  itnim is ONLINE for IO  */
0231     bfa_boolean_t   iotov_active;   /*  IO TOV timer is active   */
0232     struct bfa_wc_s wc;     /*  waiting counter */
0233     struct bfa_timer_s timer;   /*  pending IO TOV   */
0234     struct bfa_reqq_wait_s reqq_wait; /*  to wait for room in reqq */
0235     struct bfa_fcpim_s *fcpim;  /*  fcpim module    */
0236     struct bfa_itnim_iostats_s  stats;
0237     struct bfa_itnim_ioprofile_s  ioprofile;
0238 };
0239 
0240 #define bfa_itnim_is_online(_itnim) ((_itnim)->is_online)
0241 #define BFA_FCPIM(_hal) (&(_hal)->modules.fcp_mod.fcpim)
0242 #define BFA_IOIM_TAG_2_ID(_iotag)   ((_iotag) & BFA_IOIM_IOTAG_MASK)
0243 #define BFA_IOIM_FROM_TAG(_fcpim, _iotag)   \
0244     (&fcpim->ioim_arr[(_iotag & BFA_IOIM_IOTAG_MASK)])
0245 #define BFA_TSKIM_FROM_TAG(_fcpim, _tmtag)  \
0246     (&fcpim->tskim_arr[_tmtag & (fcpim->num_tskim_reqs - 1)])
0247 
0248 #define bfa_io_profile_start_time(_bfa) \
0249     ((_bfa)->modules.fcp_mod.fcpim.io_profile_start_time)
0250 #define bfa_fcpim_get_io_profile(_bfa)  \
0251     ((_bfa)->modules.fcp_mod.fcpim.io_profile)
0252 #define bfa_ioim_update_iotag(__ioim) do {              \
0253     uint16_t k = (__ioim)->iotag >> BFA_IOIM_RETRY_TAG_OFFSET;  \
0254     k++; (__ioim)->iotag &= BFA_IOIM_IOTAG_MASK;            \
0255     (__ioim)->iotag |= k << BFA_IOIM_RETRY_TAG_OFFSET;      \
0256 } while (0)
0257 
0258 static inline bfa_boolean_t
0259 bfa_ioim_maxretry_reached(struct bfa_ioim_s *ioim)
0260 {
0261     uint16_t k = ioim->iotag >> BFA_IOIM_RETRY_TAG_OFFSET;
0262     if (k < BFA_IOIM_RETRY_MAX)
0263         return BFA_FALSE;
0264     return BFA_TRUE;
0265 }
0266 
0267 /*
0268  * function prototypes
0269  */
0270 void    bfa_ioim_attach(struct bfa_fcpim_s *fcpim);
0271 void    bfa_ioim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
0272 void    bfa_ioim_good_comp_isr(struct bfa_s *bfa,
0273                     struct bfi_msg_s *msg);
0274 void    bfa_ioim_cleanup(struct bfa_ioim_s *ioim);
0275 void    bfa_ioim_cleanup_tm(struct bfa_ioim_s *ioim,
0276                     struct bfa_tskim_s *tskim);
0277 void    bfa_ioim_iocdisable(struct bfa_ioim_s *ioim);
0278 void    bfa_ioim_tov(struct bfa_ioim_s *ioim);
0279 
0280 void    bfa_tskim_attach(struct bfa_fcpim_s *fcpim);
0281 void    bfa_tskim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
0282 void    bfa_tskim_iodone(struct bfa_tskim_s *tskim);
0283 void    bfa_tskim_iocdisable(struct bfa_tskim_s *tskim);
0284 void    bfa_tskim_cleanup(struct bfa_tskim_s *tskim);
0285 void    bfa_tskim_res_recfg(struct bfa_s *bfa, u16 num_tskim_fw);
0286 
0287 void    bfa_itnim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len);
0288 void    bfa_itnim_attach(struct bfa_fcpim_s *fcpim);
0289 void    bfa_itnim_iocdisable(struct bfa_itnim_s *itnim);
0290 void    bfa_itnim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
0291 void    bfa_itnim_iodone(struct bfa_itnim_s *itnim);
0292 void    bfa_itnim_tskdone(struct bfa_itnim_s *itnim);
0293 bfa_boolean_t   bfa_itnim_hold_io(struct bfa_itnim_s *itnim);
0294 
0295 /*
0296  * bfa fcpim module API functions
0297  */
0298 void    bfa_fcpim_path_tov_set(struct bfa_s *bfa, u16 path_tov);
0299 u16 bfa_fcpim_path_tov_get(struct bfa_s *bfa);
0300 u16 bfa_fcpim_qdepth_get(struct bfa_s *bfa);
0301 bfa_status_t bfa_fcpim_port_iostats(struct bfa_s *bfa,
0302             struct bfa_itnim_iostats_s *stats, u8 lp_tag);
0303 void bfa_fcpim_add_stats(struct bfa_itnim_iostats_s *fcpim_stats,
0304             struct bfa_itnim_iostats_s *itnim_stats);
0305 bfa_status_t bfa_fcpim_profile_on(struct bfa_s *bfa, time64_t time);
0306 bfa_status_t bfa_fcpim_profile_off(struct bfa_s *bfa);
0307 
0308 #define bfa_fcpim_ioredirect_enabled(__bfa)             \
0309     (((struct bfa_fcpim_s *)(BFA_FCPIM(__bfa)))->ioredirect)
0310 
0311 #define bfa_fcpim_get_next_reqq(__bfa, __qid)               \
0312 {                                   \
0313     struct bfa_fcpim_s *__fcpim = BFA_FCPIM(__bfa);      \
0314     __fcpim->reqq++;                        \
0315     __fcpim->reqq &= (BFI_IOC_MAX_CQS - 1);      \
0316     *(__qid) = __fcpim->reqq;                   \
0317 }
0318 
0319 #define bfa_iocfc_map_msg_to_qid(__msg, __qid)              \
0320     *(__qid) = (u8)((__msg) & (BFI_IOC_MAX_CQS - 1));
0321 /*
0322  * bfa itnim API functions
0323  */
0324 struct bfa_itnim_s *bfa_itnim_create(struct bfa_s *bfa,
0325         struct bfa_rport_s *rport, void *itnim);
0326 void bfa_itnim_delete(struct bfa_itnim_s *itnim);
0327 void bfa_itnim_online(struct bfa_itnim_s *itnim, bfa_boolean_t seq_rec);
0328 void bfa_itnim_offline(struct bfa_itnim_s *itnim);
0329 void bfa_itnim_clear_stats(struct bfa_itnim_s *itnim);
0330 bfa_status_t bfa_itnim_get_ioprofile(struct bfa_itnim_s *itnim,
0331             struct bfa_itnim_ioprofile_s *ioprofile);
0332 
0333 #define bfa_itnim_get_reqq(__ioim) (((struct bfa_ioim_s *)__ioim)->itnim->reqq)
0334 
0335 /*
0336  * BFA completion callback for bfa_itnim_online().
0337  */
0338 void    bfa_cb_itnim_online(void *itnim);
0339 
0340 /*
0341  * BFA completion callback for bfa_itnim_offline().
0342  */
0343 void    bfa_cb_itnim_offline(void *itnim);
0344 void    bfa_cb_itnim_tov_begin(void *itnim);
0345 void    bfa_cb_itnim_tov(void *itnim);
0346 
0347 /*
0348  * BFA notification to FCS/driver for second level error recovery.
0349  * Atleast one I/O request has timedout and target is unresponsive to
0350  * repeated abort requests. Second level error recovery should be initiated
0351  * by starting implicit logout and recovery procedures.
0352  */
0353 void    bfa_cb_itnim_sler(void *itnim);
0354 
0355 /*
0356  * bfa ioim API functions
0357  */
0358 struct bfa_ioim_s   *bfa_ioim_alloc(struct bfa_s *bfa,
0359                     struct bfad_ioim_s *dio,
0360                     struct bfa_itnim_s *itnim,
0361                     u16 nsgles);
0362 
0363 void        bfa_ioim_free(struct bfa_ioim_s *ioim);
0364 void        bfa_ioim_start(struct bfa_ioim_s *ioim);
0365 bfa_status_t    bfa_ioim_abort(struct bfa_ioim_s *ioim);
0366 void        bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim,
0367                       bfa_boolean_t iotov);
0368 /*
0369  * I/O completion notification.
0370  *
0371  * @param[in]       dio         driver IO structure
0372  * @param[in]       io_status       IO completion status
0373  * @param[in]       scsi_status     SCSI status returned by target
0374  * @param[in]       sns_len         SCSI sense length, 0 if none
0375  * @param[in]       sns_info        SCSI sense data, if any
0376  * @param[in]       residue         Residual length
0377  *
0378  * @return None
0379  */
0380 void bfa_cb_ioim_done(void *bfad, struct bfad_ioim_s *dio,
0381             enum bfi_ioim_status io_status,
0382             u8 scsi_status, int sns_len,
0383             u8 *sns_info, s32 residue);
0384 
0385 /*
0386  * I/O good completion notification.
0387  */
0388 void bfa_cb_ioim_good_comp(void *bfad, struct bfad_ioim_s *dio);
0389 
0390 /*
0391  * I/O abort completion notification
0392  */
0393 void bfa_cb_ioim_abort(void *bfad, struct bfad_ioim_s *dio);
0394 
0395 /*
0396  * bfa tskim API functions
0397  */
0398 struct bfa_tskim_s *bfa_tskim_alloc(struct bfa_s *bfa,
0399             struct bfad_tskim_s *dtsk);
0400 void bfa_tskim_free(struct bfa_tskim_s *tskim);
0401 void bfa_tskim_start(struct bfa_tskim_s *tskim,
0402             struct bfa_itnim_s *itnim, struct scsi_lun lun,
0403             enum fcp_tm_cmnd tm, u8 t_secs);
0404 void bfa_cb_tskim_done(void *bfad, struct bfad_tskim_s *dtsk,
0405             enum bfi_tskim_status tsk_status);
0406 
0407 void    bfa_fcpim_lunmask_rp_update(struct bfa_s *bfa, wwn_t lp_wwn,
0408             wwn_t rp_wwn, u16 rp_tag, u8 lp_tag);
0409 bfa_status_t    bfa_fcpim_lunmask_update(struct bfa_s *bfa, u32 on_off);
0410 bfa_status_t    bfa_fcpim_lunmask_query(struct bfa_s *bfa, void *buf);
0411 bfa_status_t    bfa_fcpim_lunmask_delete(struct bfa_s *bfa, u16 vf_id,
0412                 wwn_t *pwwn, wwn_t rpwwn, struct scsi_lun lun);
0413 bfa_status_t    bfa_fcpim_lunmask_add(struct bfa_s *bfa, u16 vf_id,
0414                 wwn_t *pwwn, wwn_t rpwwn, struct scsi_lun lun);
0415 bfa_status_t    bfa_fcpim_lunmask_clear(struct bfa_s *bfa);
0416 u16     bfa_fcpim_read_throttle(struct bfa_s *bfa);
0417 bfa_status_t    bfa_fcpim_write_throttle(struct bfa_s *bfa, u16 value);
0418 bfa_status_t    bfa_fcpim_throttle_set(struct bfa_s *bfa, u16 value);
0419 bfa_status_t    bfa_fcpim_throttle_get(struct bfa_s *bfa, void *buf);
0420 u16     bfa_fcpim_get_throttle_cfg(struct bfa_s *bfa, u16 drv_cfg_param);
0421 
0422 #endif /* __BFA_FCPIM_H__ */