0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
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
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
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
0083
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
0092 #define csio_scsi_cmnd(req) ((req)->scratch1)
0093
0094 struct csio_scsi_stats {
0095 uint64_t n_tot_success;
0096 uint32_t n_rn_nr_error;
0097
0098
0099 uint32_t n_hw_nr_error;
0100
0101
0102 uint32_t n_dmamap_error;
0103 uint32_t n_unsupp_sge_error;
0104
0105
0106 uint32_t n_no_req_error;
0107 uint32_t n_busy_error;
0108 uint32_t n_hosterror;
0109 uint32_t n_rsperror;
0110 uint32_t n_autosense;
0111 uint32_t n_ovflerror;
0112 uint32_t n_unflerror;
0113 uint32_t n_rdev_nr_error;
0114
0115
0116 uint32_t n_rdev_lost_error;
0117 uint32_t n_rdev_logo_error;
0118 uint32_t n_link_down_error;
0119 uint32_t n_no_xchg_error;
0120 uint32_t n_unknown_error;
0121 uint32_t n_aborted;
0122 uint32_t n_abrt_timedout;
0123 uint32_t n_abrt_fail;
0124 uint32_t n_abrt_dups;
0125 uint32_t n_abrt_race_comp;
0126
0127
0128 uint32_t n_abrt_busy_error;
0129
0130
0131 uint32_t n_closed;
0132 uint32_t n_cls_busy_error;
0133
0134
0135 uint32_t n_active;
0136 uint32_t n_tm_active;
0137 uint32_t n_wcbfn;
0138
0139
0140 uint32_t n_free_ioreq;
0141 uint32_t n_free_ddp;
0142 uint32_t n_unaligned;
0143 uint32_t n_inval_cplop;
0144 uint32_t n_inval_scsiop;
0145 };
0146
0147 struct csio_scsim {
0148 struct csio_hw *hw;
0149 uint8_t max_sge;
0150 uint8_t proto_cmd_len;
0151
0152
0153 uint16_t proto_rsp_len;
0154
0155
0156 spinlock_t freelist_lock;
0157 struct list_head active_q;
0158 struct list_head ioreq_freelist;
0159 struct list_head ddp_freelist;
0160 struct csio_scsi_stats stats;
0161 };
0162
0163
0164 enum csio_scsi_ev {
0165 CSIO_SCSIE_START_IO = 1,
0166 CSIO_SCSIE_START_TM,
0167 CSIO_SCSIE_COMPLETED,
0168 CSIO_SCSIE_ABORT,
0169 CSIO_SCSIE_ABORTED,
0170 CSIO_SCSIE_CLOSE,
0171 CSIO_SCSIE_CLOSED,
0172 CSIO_SCSIE_DRVCLEANUP,
0173
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;
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
0291
0292
0293
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
0304
0305
0306
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
0317
0318
0319
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
0330
0331
0332
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