Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /* Copyright 2014 Cisco Systems, Inc.  All rights reserved. */
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 /* UCSM default throttle count */
0036 #define SNIC_MAX_IO_REQ         50 /* scsi_cmnd tag map entries */
0037 #define SNIC_MIN_IO_REQ         8  /* Min IO throttle count */
0038 #define SNIC_IO_LOCKS           64 /* IO locks: power of 2 */
0039 #define SNIC_DFLT_QUEUE_DEPTH       32 /* Default Queue Depth */
0040 #define SNIC_MAX_QUEUE_DEPTH        64 /* Max Queue Depth */
0041 #define SNIC_DFLT_CMD_TIMEOUT       90 /* Extended tmo for FW */
0042 
0043 /*
0044  * Tag bits used for special requests.
0045  */
0046 #define SNIC_TAG_ABORT      BIT(30)     /* Tag indicating abort */
0047 #define SNIC_TAG_DEV_RST    BIT(29)     /* Tag for device reset */
0048 #define SNIC_TAG_IOCTL_DEV_RST  BIT(28)     /* Tag for User Device Reset */
0049 #define SNIC_TAG_MASK       (BIT(24) - 1)   /* Mask for lookup */
0050 #define SNIC_NO_TAG     -1
0051 
0052 /*
0053  * Command flags to identify the type of command and for other future use
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       /* msec */
0088 #define SNIC_LUN_RESET_TIMEOUT      30000       /* msec */
0089 #define SNIC_HOST_RESET_TIMEOUT     30000       /* msec */
0090 
0091 
0092 /*
0093  * These are protected by the hashed req_lock.
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 /* Hdr Status val unused by firmware */
0107 
0108 #define SNIC_MAX_TARGET         256
0109 #define SNIC_FLAGS_NONE         (0)
0110 
0111 /* snic module params */
0112 extern unsigned int snic_max_qdepth;
0113 
0114 /* snic debugging */
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 /* Soft assert */
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 /* firmware version information */
0228 struct snic_fw_info {
0229     u32 fw_ver;
0230     u32 hid;            /* u16 hid | u16 vnic id */
0231     u32 max_concur_ios;     /* max concurrent ios */
0232     u32 max_sgs_per_cmd;    /* max sgls per IO */
0233     u32 max_io_sz;      /* max io size supported */
0234     u32 hba_cap;        /* hba capabilities */
0235     u32 max_tgts;       /* max tgts supported */
0236     u16 io_tmo;         /* FW Extended timeout */
0237     struct completion *wait;    /* protected by snic lock*/
0238 };
0239 
0240 /*
0241  * snic_work item : defined to process asynchronous events
0242  */
0243 struct snic_work {
0244     struct work_struct work;
0245     u16 ev_id;
0246     u64 *ev_data;
0247 };
0248 
0249 /*
0250  * snic structure to represent SCSI vNIC
0251  */
0252 struct snic {
0253     /* snic specific members */
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;      /* stop processing link events */
0261 
0262     /* discovery related */
0263     struct snic_disc disc;
0264 
0265     /* Scsi Host info */
0266     struct Scsi_Host *shost;
0267 
0268     /* vnic related structures */
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     /* hw resource info */
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; /* retrieved from svnic_dev_link_status() */
0284     u32 link_down_cnt;
0285 
0286     /* pci related */
0287     struct pci_dev *pdev;
0288     struct snic_msix_entry msix[SNIC_MSIX_INTR_MAX];
0289 
0290     /* io related info */
0291     mempool_t *req_pool[SNIC_REQ_MAX_CACHES]; /* (??) */
0292     ____cacheline_aligned spinlock_t io_req_lock[SNIC_IO_LOCKS];
0293 
0294     /* Maintain snic specific commands, cmds with no tag in spl_cmd_list */
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;      /* io in flight counter */
0300 
0301     struct vnic_snic_config config;
0302 
0303     struct work_struct link_work;
0304 
0305     /* firmware information */
0306     struct snic_fw_info fwinfo;
0307 
0308     /* Work for processing Target related work */
0309     struct work_struct tgt_work;
0310 
0311     /* Work for processing Discovery */
0312     struct work_struct disc_work;
0313 
0314     /* stats related */
0315     unsigned int reset_stats;
0316     atomic64_t io_cmpl_skip;
0317     struct snic_stats s_stats;  /* Per SNIC driver stats */
0318 
0319     /* platform specific */
0320 #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
0321     struct dentry *stats_host;  /* Per snic debugfs root */
0322     struct dentry *stats_file;  /* Per snic debugfs file */
0323     struct dentry *reset_stats_file;/* Per snic reset stats file */
0324 #endif
0325 
0326     /* completion queue cache line section */
0327     ____cacheline_aligned struct vnic_cq cq[SNIC_CQ_MAX];
0328 
0329     /* work queue cache line section */
0330     ____cacheline_aligned struct vnic_wq wq[SNIC_WQ_MAX];
0331     spinlock_t wq_lock[SNIC_WQ_MAX];
0332 
0333     /* interrupt resource cache line section */
0334     ____cacheline_aligned struct vnic_intr intr[SNIC_MSIX_INTR_MAX];
0335 }; /* end of snic structure */
0336 
0337 /*
0338  * SNIC Driver's Global Data
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     /* debugfs related global data */
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 /* _SNIC_H */