Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is part of the Chelsio FCoE driver for Linux.
0003  *
0004  * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
0005  *
0006  * This software is available to you under a choice of one of two
0007  * licenses.  You may choose to be licensed under the terms of the GNU
0008  * General Public License (GPL) Version 2, available from the file
0009  * COPYING in the main directory of this source tree, or the
0010  * OpenIB.org BSD license below:
0011  *
0012  *     Redistribution and use in source and binary forms, with or
0013  *     without modification, are permitted provided that the following
0014  *     conditions are met:
0015  *
0016  *      - Redistributions of source code must retain the above
0017  *        copyright notice, this list of conditions and the following
0018  *        disclaimer.
0019  *
0020  *      - Redistributions in binary form must reproduce the above
0021  *        copyright notice, this list of conditions and the following
0022  *        disclaimer in the documentation and/or other materials
0023  *        provided with the distribution.
0024  *
0025  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0026  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0027  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0028  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0029  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0030  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0031  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0032  * SOFTWARE.
0033  */
0034 
0035 #ifndef __CSIO_SCSI_H__
0036 #define __CSIO_SCSI_H__
0037 
0038 #include <linux/spinlock_types.h>
0039 #include <linux/completion.h>
0040 #include <scsi/scsi.h>
0041 #include <scsi/scsi_cmnd.h>
0042 #include <scsi/scsi_device.h>
0043 #include <scsi/scsi_host.h>
0044 #include <scsi/scsi_eh.h>
0045 #include <scsi/scsi_tcq.h>
0046 #include <scsi/fc/fc_fcp.h>
0047 
0048 #include "csio_defs.h"
0049 #include "csio_wr.h"
0050 
0051 extern struct scsi_host_template csio_fcoe_shost_template;
0052 extern struct scsi_host_template csio_fcoe_shost_vport_template;
0053 
0054 extern int csio_scsi_eqsize;
0055 extern int csio_scsi_iqlen;
0056 extern int csio_scsi_ioreqs;
0057 extern uint32_t csio_max_scan_tmo;
0058 extern uint32_t csio_delta_scan_tmo;
0059 extern int csio_lun_qdepth;
0060 
0061 /*
0062  **************************** NOTE *******************************
0063  * How do we calculate MAX FCoE SCSI SGEs? Here is the math:
0064  * Max Egress WR size = 512 bytes
0065  * One SCSI egress WR has the following fixed no of bytes:
0066  *      48 (sizeof(struct fw_scsi_write[read]_wr)) - FW WR
0067  *    + 32 (sizeof(struct fc_fcp_cmnd)) - Immediate FCP_CMD
0068  *    ------
0069  *      80
0070  *    ------
0071  * That leaves us with 512 - 96 = 432 bytes for data SGE. Using
0072  * struct ulptx_sgl header for the SGE consumes:
0073  *  - 4 bytes for cmnd_sge.
0074  *  - 12 bytes for the first SGL.
0075  * That leaves us with 416 bytes for the remaining SGE pairs. Which is
0076  * is 416 / 24 (size(struct ulptx_sge_pair)) = 17 SGE pairs,
0077  * or 34 SGEs. Adding the first SGE fetches us 35 SGEs.
0078  */
0079 #define CSIO_SCSI_MAX_SGE       35
0080 #define CSIO_SCSI_ABRT_TMO_MS       60000
0081 #define CSIO_SCSI_LUNRST_TMO_MS     60000
0082 #define CSIO_SCSI_TM_POLL_MS        2000    /* should be less than
0083                          * all TM timeouts.
0084                          */
0085 #define CSIO_SCSI_IQ_WRSZ       128
0086 #define CSIO_SCSI_IQSIZE        (csio_scsi_iqlen * CSIO_SCSI_IQ_WRSZ)
0087 
0088 #define CSIO_MAX_SNS_LEN        128
0089 #define CSIO_SCSI_RSP_LEN   (FCP_RESP_WITH_EXT + 4 + CSIO_MAX_SNS_LEN)
0090 
0091 /* Reference to scsi_cmnd */
0092 #define csio_scsi_cmnd(req)     ((req)->scratch1)
0093 
0094 struct csio_scsi_stats {
0095     uint64_t        n_tot_success;  /* Total number of good I/Os */
0096     uint32_t        n_rn_nr_error;  /* No. of remote-node-not-
0097                          * ready errors
0098                          */
0099     uint32_t        n_hw_nr_error;  /* No. of hw-module-not-
0100                          * ready errors
0101                          */
0102     uint32_t        n_dmamap_error; /* No. of DMA map erros */
0103     uint32_t        n_unsupp_sge_error; /* No. of too-many-SGes
0104                              * errors.
0105                              */
0106     uint32_t        n_no_req_error; /* No. of Out-of-ioreqs error */
0107     uint32_t        n_busy_error;   /* No. of -EBUSY errors */
0108     uint32_t        n_hosterror;    /* No. of FW_HOSTERROR I/O */
0109     uint32_t        n_rsperror; /* No. of response errors */
0110     uint32_t        n_autosense;    /* No. of auto sense replies */
0111     uint32_t        n_ovflerror;    /* No. of overflow errors */
0112     uint32_t        n_unflerror;    /* No. of underflow errors */
0113     uint32_t        n_rdev_nr_error;/* No. of rdev not
0114                          * ready errors
0115                          */
0116     uint32_t        n_rdev_lost_error;/* No. of rdev lost errors */
0117     uint32_t        n_rdev_logo_error;/* No. of rdev logo errors */
0118     uint32_t        n_link_down_error;/* No. of link down errors */
0119     uint32_t        n_no_xchg_error; /* No. no exchange error */
0120     uint32_t        n_unknown_error;/* No. of unhandled errors */
0121     uint32_t        n_aborted;  /* No. of aborted I/Os */
0122     uint32_t        n_abrt_timedout; /* No. of abort timedouts */
0123     uint32_t        n_abrt_fail;    /* No. of abort failures */
0124     uint32_t        n_abrt_dups;    /* No. of duplicate aborts */
0125     uint32_t        n_abrt_race_comp; /* No. of aborts that raced
0126                            * with completions.
0127                            */
0128     uint32_t        n_abrt_busy_error;/* No. of abort failures
0129                            * due to -EBUSY.
0130                            */
0131     uint32_t        n_closed;   /* No. of closed I/Os */
0132     uint32_t        n_cls_busy_error; /* No. of close failures
0133                            * due to -EBUSY.
0134                            */
0135     uint32_t        n_active;   /* No. of IOs in active_q */
0136     uint32_t        n_tm_active;    /* No. of TMs in active_q */
0137     uint32_t        n_wcbfn;    /* No. of I/Os in worker
0138                          * cbfn q
0139                          */
0140     uint32_t        n_free_ioreq;   /* No. of freelist entries */
0141     uint32_t        n_free_ddp; /* No. of DDP freelist */
0142     uint32_t        n_unaligned;    /* No. of Unaligned SGls */
0143     uint32_t        n_inval_cplop;  /* No. invalid CPL op's in IQ */
0144     uint32_t        n_inval_scsiop; /* No. invalid scsi op's in IQ*/
0145 };
0146 
0147 struct csio_scsim {
0148     struct csio_hw      *hw;        /* Pointer to HW moduel */
0149     uint8_t         max_sge;    /* Max SGE */
0150     uint8_t         proto_cmd_len;  /* Proto specific SCSI
0151                          * cmd length
0152                          */
0153     uint16_t        proto_rsp_len;  /* Proto specific SCSI
0154                          * response length
0155                          */
0156     spinlock_t      freelist_lock;  /* Lock for ioreq freelist */
0157     struct list_head    active_q;   /* Outstanding SCSI I/Os */
0158     struct list_head    ioreq_freelist; /* Free list of ioreq's */
0159     struct list_head    ddp_freelist;   /* DDP descriptor freelist */
0160     struct csio_scsi_stats  stats;      /* This module's statistics */
0161 };
0162 
0163 /* State machine defines */
0164 enum csio_scsi_ev {
0165     CSIO_SCSIE_START_IO = 1,        /* Start a regular SCSI IO */
0166     CSIO_SCSIE_START_TM,            /* Start a TM IO */
0167     CSIO_SCSIE_COMPLETED,           /* IO Completed */
0168     CSIO_SCSIE_ABORT,           /* Abort IO */
0169     CSIO_SCSIE_ABORTED,         /* IO Aborted */
0170     CSIO_SCSIE_CLOSE,           /* Close exchange */
0171     CSIO_SCSIE_CLOSED,          /* Exchange closed */
0172     CSIO_SCSIE_DRVCLEANUP,          /* Driver wants to manually
0173                          * cleanup this I/O.
0174                          */
0175 };
0176 
0177 enum csio_scsi_lev {
0178     CSIO_LEV_ALL = 1,
0179     CSIO_LEV_LNODE,
0180     CSIO_LEV_RNODE,
0181     CSIO_LEV_LUN,
0182 };
0183 
0184 struct csio_scsi_level_data {
0185     enum csio_scsi_lev  level;
0186     struct csio_rnode   *rnode;
0187     struct csio_lnode   *lnode;
0188     uint64_t        oslun;
0189 };
0190 
0191 struct csio_cmd_priv {
0192     uint8_t fc_tm_flags;    /* task management flags */
0193     uint16_t wr_status;
0194 };
0195 
0196 static inline struct csio_cmd_priv *csio_priv(struct scsi_cmnd *cmd)
0197 {
0198     return scsi_cmd_priv(cmd);
0199 }
0200 
0201 static inline struct csio_ioreq *
0202 csio_get_scsi_ioreq(struct csio_scsim *scm)
0203 {
0204     struct csio_sm *req;
0205 
0206     if (likely(!list_empty(&scm->ioreq_freelist))) {
0207         req = list_first_entry(&scm->ioreq_freelist,
0208                        struct csio_sm, sm_list);
0209         list_del_init(&req->sm_list);
0210         CSIO_DEC_STATS(scm, n_free_ioreq);
0211         return (struct csio_ioreq *)req;
0212     } else
0213         return NULL;
0214 }
0215 
0216 static inline void
0217 csio_put_scsi_ioreq(struct csio_scsim *scm, struct csio_ioreq *ioreq)
0218 {
0219     list_add_tail(&ioreq->sm.sm_list, &scm->ioreq_freelist);
0220     CSIO_INC_STATS(scm, n_free_ioreq);
0221 }
0222 
0223 static inline void
0224 csio_put_scsi_ioreq_list(struct csio_scsim *scm, struct list_head *reqlist,
0225              int n)
0226 {
0227     list_splice_init(reqlist, &scm->ioreq_freelist);
0228     scm->stats.n_free_ioreq += n;
0229 }
0230 
0231 static inline struct csio_dma_buf *
0232 csio_get_scsi_ddp(struct csio_scsim *scm)
0233 {
0234     struct csio_dma_buf *ddp;
0235 
0236     if (likely(!list_empty(&scm->ddp_freelist))) {
0237         ddp = list_first_entry(&scm->ddp_freelist,
0238                        struct csio_dma_buf, list);
0239         list_del_init(&ddp->list);
0240         CSIO_DEC_STATS(scm, n_free_ddp);
0241         return ddp;
0242     } else
0243         return NULL;
0244 }
0245 
0246 static inline void
0247 csio_put_scsi_ddp(struct csio_scsim *scm, struct csio_dma_buf *ddp)
0248 {
0249     list_add_tail(&ddp->list, &scm->ddp_freelist);
0250     CSIO_INC_STATS(scm, n_free_ddp);
0251 }
0252 
0253 static inline void
0254 csio_put_scsi_ddp_list(struct csio_scsim *scm, struct list_head *reqlist,
0255              int n)
0256 {
0257     list_splice_tail_init(reqlist, &scm->ddp_freelist);
0258     scm->stats.n_free_ddp += n;
0259 }
0260 
0261 static inline void
0262 csio_scsi_completed(struct csio_ioreq *ioreq, struct list_head *cbfn_q)
0263 {
0264     csio_post_event(&ioreq->sm, CSIO_SCSIE_COMPLETED);
0265     if (csio_list_deleted(&ioreq->sm.sm_list))
0266         list_add_tail(&ioreq->sm.sm_list, cbfn_q);
0267 }
0268 
0269 static inline void
0270 csio_scsi_aborted(struct csio_ioreq *ioreq, struct list_head *cbfn_q)
0271 {
0272     csio_post_event(&ioreq->sm, CSIO_SCSIE_ABORTED);
0273     list_add_tail(&ioreq->sm.sm_list, cbfn_q);
0274 }
0275 
0276 static inline void
0277 csio_scsi_closed(struct csio_ioreq *ioreq, struct list_head *cbfn_q)
0278 {
0279     csio_post_event(&ioreq->sm, CSIO_SCSIE_CLOSED);
0280     list_add_tail(&ioreq->sm.sm_list, cbfn_q);
0281 }
0282 
0283 static inline void
0284 csio_scsi_drvcleanup(struct csio_ioreq *ioreq)
0285 {
0286     csio_post_event(&ioreq->sm, CSIO_SCSIE_DRVCLEANUP);
0287 }
0288 
0289 /*
0290  * csio_scsi_start_io - Kick starts the IO SM.
0291  * @req: io request SM.
0292  *
0293  * needs to be called with lock held.
0294  */
0295 static inline int
0296 csio_scsi_start_io(struct csio_ioreq *ioreq)
0297 {
0298     csio_post_event(&ioreq->sm, CSIO_SCSIE_START_IO);
0299     return ioreq->drv_status;
0300 }
0301 
0302 /*
0303  * csio_scsi_start_tm - Kicks off the Task management IO SM.
0304  * @req: io request SM.
0305  *
0306  * needs to be called with lock held.
0307  */
0308 static inline int
0309 csio_scsi_start_tm(struct csio_ioreq *ioreq)
0310 {
0311     csio_post_event(&ioreq->sm, CSIO_SCSIE_START_TM);
0312     return ioreq->drv_status;
0313 }
0314 
0315 /*
0316  * csio_scsi_abort - Abort an IO request
0317  * @req: io request SM.
0318  *
0319  * needs to be called with lock held.
0320  */
0321 static inline int
0322 csio_scsi_abort(struct csio_ioreq *ioreq)
0323 {
0324     csio_post_event(&ioreq->sm, CSIO_SCSIE_ABORT);
0325     return ioreq->drv_status;
0326 }
0327 
0328 /*
0329  * csio_scsi_close - Close an IO request
0330  * @req: io request SM.
0331  *
0332  * needs to be called with lock held.
0333  */
0334 static inline int
0335 csio_scsi_close(struct csio_ioreq *ioreq)
0336 {
0337     csio_post_event(&ioreq->sm, CSIO_SCSIE_CLOSE);
0338     return ioreq->drv_status;
0339 }
0340 
0341 void csio_scsi_cleanup_io_q(struct csio_scsim *, struct list_head *);
0342 int csio_scsim_cleanup_io(struct csio_scsim *, bool abort);
0343 int csio_scsim_cleanup_io_lnode(struct csio_scsim *,
0344                       struct csio_lnode *);
0345 struct csio_ioreq *csio_scsi_cmpl_handler(struct csio_hw *, void *, uint32_t,
0346                       struct csio_fl_dma_buf *,
0347                       void *, uint8_t **);
0348 int csio_scsi_qconfig(struct csio_hw *);
0349 int csio_scsim_init(struct csio_scsim *, struct csio_hw *);
0350 void csio_scsim_exit(struct csio_scsim *);
0351 
0352 #endif /* __CSIO_SCSI_H__ */