0001
0002
0003
0004 #ifndef _SNIC_H_
0005 #define _SNIC_H_
0006
0007 #include <linux/module.h>
0008 #include <linux/netdevice.h>
0009 #include <linux/workqueue.h>
0010 #include <linux/bitops.h>
0011 #include <linux/mempool.h>
0012 #include <scsi/scsi_cmnd.h>
0013 #include <scsi/scsi.h>
0014 #include <scsi/scsi_host.h>
0015
0016 #include "snic_disc.h"
0017 #include "snic_io.h"
0018 #include "snic_res.h"
0019 #include "snic_trc.h"
0020 #include "snic_stats.h"
0021 #include "vnic_dev.h"
0022 #include "vnic_wq.h"
0023 #include "vnic_cq.h"
0024 #include "vnic_intr.h"
0025 #include "vnic_stats.h"
0026 #include "vnic_snic.h"
0027
0028 #define SNIC_DRV_NAME "snic"
0029 #define SNIC_DRV_DESCRIPTION "Cisco SCSI NIC Driver"
0030 #define SNIC_DRV_VERSION "0.0.1.18"
0031 #define PFX SNIC_DRV_NAME ":"
0032 #define DFX SNIC_DRV_NAME "%d: "
0033
0034 #define DESC_CLEAN_LOW_WATERMARK 8
0035 #define SNIC_UCSM_DFLT_THROTTLE_CNT_BLD 16
0036 #define SNIC_MAX_IO_REQ 50
0037 #define SNIC_MIN_IO_REQ 8
0038 #define SNIC_IO_LOCKS 64
0039 #define SNIC_DFLT_QUEUE_DEPTH 32
0040 #define SNIC_MAX_QUEUE_DEPTH 64
0041 #define SNIC_DFLT_CMD_TIMEOUT 90
0042
0043
0044
0045
0046 #define SNIC_TAG_ABORT BIT(30)
0047 #define SNIC_TAG_DEV_RST BIT(29)
0048 #define SNIC_TAG_IOCTL_DEV_RST BIT(28)
0049 #define SNIC_TAG_MASK (BIT(24) - 1)
0050 #define SNIC_NO_TAG -1
0051
0052
0053
0054
0055 #define SNIC_NO_FLAGS 0
0056 #define SNIC_IO_INITIALIZED BIT(0)
0057 #define SNIC_IO_ISSUED BIT(1)
0058 #define SNIC_IO_DONE BIT(2)
0059 #define SNIC_IO_REQ_NULL BIT(3)
0060 #define SNIC_IO_ABTS_PENDING BIT(4)
0061 #define SNIC_IO_ABORTED BIT(5)
0062 #define SNIC_IO_ABTS_ISSUED BIT(6)
0063 #define SNIC_IO_TERM_ISSUED BIT(7)
0064 #define SNIC_IO_ABTS_TIMEDOUT BIT(8)
0065 #define SNIC_IO_ABTS_TERM_DONE BIT(9)
0066 #define SNIC_IO_ABTS_TERM_REQ_NULL BIT(10)
0067 #define SNIC_IO_ABTS_TERM_TIMEDOUT BIT(11)
0068 #define SNIC_IO_INTERNAL_TERM_PENDING BIT(12)
0069 #define SNIC_IO_INTERNAL_TERM_ISSUED BIT(13)
0070 #define SNIC_DEVICE_RESET BIT(14)
0071 #define SNIC_DEV_RST_ISSUED BIT(15)
0072 #define SNIC_DEV_RST_TIMEDOUT BIT(16)
0073 #define SNIC_DEV_RST_ABTS_ISSUED BIT(17)
0074 #define SNIC_DEV_RST_TERM_ISSUED BIT(18)
0075 #define SNIC_DEV_RST_DONE BIT(19)
0076 #define SNIC_DEV_RST_REQ_NULL BIT(20)
0077 #define SNIC_DEV_RST_ABTS_DONE BIT(21)
0078 #define SNIC_DEV_RST_TERM_DONE BIT(22)
0079 #define SNIC_DEV_RST_ABTS_PENDING BIT(23)
0080 #define SNIC_DEV_RST_PENDING BIT(24)
0081 #define SNIC_DEV_RST_NOTSUP BIT(25)
0082 #define SNIC_SCSI_CLEANUP BIT(26)
0083 #define SNIC_HOST_RESET_ISSUED BIT(27)
0084 #define SNIC_HOST_RESET_CMD_TERM \
0085 (SNIC_DEV_RST_NOTSUP | SNIC_SCSI_CLEANUP | SNIC_HOST_RESET_ISSUED)
0086
0087 #define SNIC_ABTS_TIMEOUT 30000
0088 #define SNIC_LUN_RESET_TIMEOUT 30000
0089 #define SNIC_HOST_RESET_TIMEOUT 30000
0090
0091
0092
0093
0094
0095 #define CMD_SP(Cmnd) \
0096 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->rqi)
0097 #define CMD_STATE(Cmnd) \
0098 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->state)
0099 #define CMD_ABTS_STATUS(Cmnd) \
0100 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->abts_status)
0101 #define CMD_LR_STATUS(Cmnd) \
0102 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->lr_status)
0103 #define CMD_FLAGS(Cmnd) \
0104 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->flags)
0105
0106 #define SNIC_INVALID_CODE 0x100
0107
0108 #define SNIC_MAX_TARGET 256
0109 #define SNIC_FLAGS_NONE (0)
0110
0111
0112 extern unsigned int snic_max_qdepth;
0113
0114
0115 extern unsigned int snic_log_level;
0116
0117 #define SNIC_MAIN_LOGGING 0x1
0118 #define SNIC_SCSI_LOGGING 0x2
0119 #define SNIC_ISR_LOGGING 0x8
0120 #define SNIC_DESC_LOGGING 0x10
0121
0122 #define SNIC_CHECK_LOGGING(LEVEL, CMD) \
0123 do { \
0124 if (unlikely(snic_log_level & LEVEL)) \
0125 do { \
0126 CMD; \
0127 } while (0); \
0128 } while (0)
0129
0130 #define SNIC_MAIN_DBG(host, fmt, args...) \
0131 SNIC_CHECK_LOGGING(SNIC_MAIN_LOGGING, \
0132 shost_printk(KERN_INFO, host, fmt, ## args);)
0133
0134 #define SNIC_SCSI_DBG(host, fmt, args...) \
0135 SNIC_CHECK_LOGGING(SNIC_SCSI_LOGGING, \
0136 shost_printk(KERN_INFO, host, fmt, ##args);)
0137
0138 #define SNIC_DISC_DBG(host, fmt, args...) \
0139 SNIC_CHECK_LOGGING(SNIC_SCSI_LOGGING, \
0140 shost_printk(KERN_INFO, host, fmt, ##args);)
0141
0142 #define SNIC_ISR_DBG(host, fmt, args...) \
0143 SNIC_CHECK_LOGGING(SNIC_ISR_LOGGING, \
0144 shost_printk(KERN_INFO, host, fmt, ##args);)
0145
0146 #define SNIC_HOST_ERR(host, fmt, args...) \
0147 shost_printk(KERN_ERR, host, fmt, ##args)
0148
0149 #define SNIC_HOST_INFO(host, fmt, args...) \
0150 shost_printk(KERN_INFO, host, fmt, ##args)
0151
0152 #define SNIC_INFO(fmt, args...) \
0153 pr_info(PFX fmt, ## args)
0154
0155 #define SNIC_DBG(fmt, args...) \
0156 pr_info(PFX fmt, ## args)
0157
0158 #define SNIC_ERR(fmt, args...) \
0159 pr_err(PFX fmt, ## args)
0160
0161 #ifdef DEBUG
0162 #define SNIC_BUG_ON(EXPR) \
0163 ({ \
0164 if (EXPR) { \
0165 SNIC_ERR("SNIC BUG(%s)\n", #EXPR); \
0166 BUG_ON(EXPR); \
0167 } \
0168 })
0169 #else
0170 #define SNIC_BUG_ON(EXPR) \
0171 ({ \
0172 if (EXPR) { \
0173 SNIC_ERR("SNIC BUG(%s) at %s : %d\n", \
0174 #EXPR, __func__, __LINE__); \
0175 WARN_ON_ONCE(EXPR); \
0176 } \
0177 })
0178 #endif
0179
0180
0181 #define SNIC_ASSERT_NOT_IMPL(EXPR) \
0182 ({ \
0183 if (EXPR) {\
0184 SNIC_INFO("Functionality not impl'ed at %s:%d\n", \
0185 __func__, __LINE__); \
0186 WARN_ON_ONCE(EXPR); \
0187 } \
0188 })
0189
0190
0191 extern const char *snic_state_str[];
0192
0193 enum snic_intx_intr_index {
0194 SNIC_INTX_WQ_RQ_COPYWQ,
0195 SNIC_INTX_ERR,
0196 SNIC_INTX_NOTIFY,
0197 SNIC_INTX_INTR_MAX,
0198 };
0199
0200 enum snic_msix_intr_index {
0201 SNIC_MSIX_WQ,
0202 SNIC_MSIX_IO_CMPL,
0203 SNIC_MSIX_ERR_NOTIFY,
0204 SNIC_MSIX_INTR_MAX,
0205 };
0206
0207 #define SNIC_INTRHDLR_NAMSZ (2 * IFNAMSIZ)
0208 struct snic_msix_entry {
0209 int requested;
0210 char devname[SNIC_INTRHDLR_NAMSZ];
0211 irqreturn_t (*isr)(int, void *);
0212 void *devid;
0213 };
0214
0215 enum snic_state {
0216 SNIC_INIT = 0,
0217 SNIC_ERROR,
0218 SNIC_ONLINE,
0219 SNIC_OFFLINE,
0220 SNIC_FWRESET,
0221 };
0222
0223 #define SNIC_WQ_MAX 1
0224 #define SNIC_CQ_IO_CMPL_MAX 1
0225 #define SNIC_CQ_MAX (SNIC_WQ_MAX + SNIC_CQ_IO_CMPL_MAX)
0226
0227
0228 struct snic_fw_info {
0229 u32 fw_ver;
0230 u32 hid;
0231 u32 max_concur_ios;
0232 u32 max_sgs_per_cmd;
0233 u32 max_io_sz;
0234 u32 hba_cap;
0235 u32 max_tgts;
0236 u16 io_tmo;
0237 struct completion *wait;
0238 };
0239
0240
0241
0242
0243 struct snic_work {
0244 struct work_struct work;
0245 u16 ev_id;
0246 u64 *ev_data;
0247 };
0248
0249
0250
0251
0252 struct snic {
0253
0254 struct list_head list;
0255 char name[IFNAMSIZ];
0256 atomic_t state;
0257 spinlock_t snic_lock;
0258 struct completion *remove_wait;
0259 bool in_remove;
0260 bool stop_link_events;
0261
0262
0263 struct snic_disc disc;
0264
0265
0266 struct Scsi_Host *shost;
0267
0268
0269 struct vnic_dev_bar bar0;
0270
0271 struct vnic_stats *stats;
0272 unsigned long stats_time;
0273 unsigned long stats_reset_time;
0274
0275 struct vnic_dev *vdev;
0276
0277
0278 unsigned int wq_count;
0279 unsigned int cq_count;
0280 unsigned int intr_count;
0281 unsigned int err_intr_offset;
0282
0283 int link_status;
0284 u32 link_down_cnt;
0285
0286
0287 struct pci_dev *pdev;
0288 struct snic_msix_entry msix[SNIC_MSIX_INTR_MAX];
0289
0290
0291 mempool_t *req_pool[SNIC_REQ_MAX_CACHES];
0292 ____cacheline_aligned spinlock_t io_req_lock[SNIC_IO_LOCKS];
0293
0294
0295 ____cacheline_aligned spinlock_t spl_cmd_lock;
0296 struct list_head spl_cmd_list;
0297
0298 unsigned int max_tag_id;
0299 atomic_t ios_inflight;
0300
0301 struct vnic_snic_config config;
0302
0303 struct work_struct link_work;
0304
0305
0306 struct snic_fw_info fwinfo;
0307
0308
0309 struct work_struct tgt_work;
0310
0311
0312 struct work_struct disc_work;
0313
0314
0315 unsigned int reset_stats;
0316 atomic64_t io_cmpl_skip;
0317 struct snic_stats s_stats;
0318
0319
0320 #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
0321 struct dentry *stats_host;
0322 struct dentry *stats_file;
0323 struct dentry *reset_stats_file;
0324 #endif
0325
0326
0327 ____cacheline_aligned struct vnic_cq cq[SNIC_CQ_MAX];
0328
0329
0330 ____cacheline_aligned struct vnic_wq wq[SNIC_WQ_MAX];
0331 spinlock_t wq_lock[SNIC_WQ_MAX];
0332
0333
0334 ____cacheline_aligned struct vnic_intr intr[SNIC_MSIX_INTR_MAX];
0335 };
0336
0337
0338
0339
0340 struct snic_global {
0341 struct list_head snic_list;
0342 spinlock_t snic_list_lock;
0343
0344 struct kmem_cache *req_cache[SNIC_REQ_MAX_CACHES];
0345
0346 struct workqueue_struct *event_q;
0347
0348 #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
0349
0350 struct dentry *trc_root;
0351 struct dentry *stats_root;
0352
0353 struct snic_trc trc ____cacheline_aligned;
0354 #endif
0355 };
0356
0357 extern struct snic_global *snic_glob;
0358
0359 int snic_glob_init(void);
0360 void snic_glob_cleanup(void);
0361
0362 extern struct workqueue_struct *snic_event_queue;
0363 extern const struct attribute_group *snic_host_groups[];
0364
0365 int snic_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
0366 int snic_abort_cmd(struct scsi_cmnd *);
0367 int snic_device_reset(struct scsi_cmnd *);
0368 int snic_host_reset(struct scsi_cmnd *);
0369 int snic_reset(struct Scsi_Host *, struct scsi_cmnd *);
0370 void snic_shutdown_scsi_cleanup(struct snic *);
0371
0372
0373 int snic_request_intr(struct snic *);
0374 void snic_free_intr(struct snic *);
0375 int snic_set_intr_mode(struct snic *);
0376 void snic_clear_intr_mode(struct snic *);
0377
0378 int snic_fwcq_cmpl_handler(struct snic *, int);
0379 int snic_wq_cmpl_handler(struct snic *, int);
0380 void snic_free_wq_buf(struct vnic_wq *, struct vnic_wq_buf *);
0381
0382
0383 void snic_log_q_error(struct snic *);
0384 void snic_handle_link_event(struct snic *);
0385 void snic_handle_link(struct work_struct *);
0386
0387 int snic_queue_exch_ver_req(struct snic *);
0388 void snic_io_exch_ver_cmpl_handler(struct snic *, struct snic_fw_req *);
0389
0390 int snic_queue_wq_desc(struct snic *, void *os_buf, u16 len);
0391
0392 void snic_handle_untagged_req(struct snic *, struct snic_req_info *);
0393 void snic_release_untagged_req(struct snic *, struct snic_req_info *);
0394 void snic_free_all_untagged_reqs(struct snic *);
0395 int snic_get_conf(struct snic *);
0396 void snic_set_state(struct snic *, enum snic_state);
0397 int snic_get_state(struct snic *);
0398 const char *snic_state_to_str(unsigned int);
0399 void snic_hex_dump(char *, char *, int);
0400 void snic_print_desc(const char *fn, char *os_buf, int len);
0401 const char *show_opcode_name(int val);
0402 #endif