snic.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /*
  2. * Copyright 2014 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. */
  17. #ifndef _SNIC_H_
  18. #define _SNIC_H_
  19. #include <linux/module.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/bitops.h>
  23. #include <linux/mempool.h>
  24. #include <scsi/scsi_cmnd.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_host.h>
  27. #include "snic_disc.h"
  28. #include "snic_io.h"
  29. #include "snic_res.h"
  30. #include "snic_trc.h"
  31. #include "snic_stats.h"
  32. #include "vnic_dev.h"
  33. #include "vnic_wq.h"
  34. #include "vnic_cq.h"
  35. #include "vnic_intr.h"
  36. #include "vnic_stats.h"
  37. #include "vnic_snic.h"
  38. #define SNIC_DRV_NAME "snic"
  39. #define SNIC_DRV_DESCRIPTION "Cisco SCSI NIC Driver"
  40. #define SNIC_DRV_VERSION "0.0.1.18"
  41. #define PFX SNIC_DRV_NAME ":"
  42. #define DFX SNIC_DRV_NAME "%d: "
  43. #define DESC_CLEAN_LOW_WATERMARK 8
  44. #define SNIC_UCSM_DFLT_THROTTLE_CNT_BLD 16 /* UCSM default throttle count */
  45. #define SNIC_MAX_IO_REQ 50 /* scsi_cmnd tag map entries */
  46. #define SNIC_MIN_IO_REQ 8 /* Min IO throttle count */
  47. #define SNIC_IO_LOCKS 64 /* IO locks: power of 2 */
  48. #define SNIC_DFLT_QUEUE_DEPTH 32 /* Default Queue Depth */
  49. #define SNIC_MAX_QUEUE_DEPTH 64 /* Max Queue Depth */
  50. #define SNIC_DFLT_CMD_TIMEOUT 90 /* Extended tmo for FW */
  51. /*
  52. * Tag bits used for special requests.
  53. */
  54. #define SNIC_TAG_ABORT BIT(30) /* Tag indicating abort */
  55. #define SNIC_TAG_DEV_RST BIT(29) /* Tag for device reset */
  56. #define SNIC_TAG_IOCTL_DEV_RST BIT(28) /* Tag for User Device Reset */
  57. #define SNIC_TAG_MASK (BIT(24) - 1) /* Mask for lookup */
  58. #define SNIC_NO_TAG -1
  59. /*
  60. * Command flags to identify the type of command and for other future use
  61. */
  62. #define SNIC_NO_FLAGS 0
  63. #define SNIC_IO_INITIALIZED BIT(0)
  64. #define SNIC_IO_ISSUED BIT(1)
  65. #define SNIC_IO_DONE BIT(2)
  66. #define SNIC_IO_REQ_NULL BIT(3)
  67. #define SNIC_IO_ABTS_PENDING BIT(4)
  68. #define SNIC_IO_ABORTED BIT(5)
  69. #define SNIC_IO_ABTS_ISSUED BIT(6)
  70. #define SNIC_IO_TERM_ISSUED BIT(7)
  71. #define SNIC_IO_ABTS_TIMEDOUT BIT(8)
  72. #define SNIC_IO_ABTS_TERM_DONE BIT(9)
  73. #define SNIC_IO_ABTS_TERM_REQ_NULL BIT(10)
  74. #define SNIC_IO_ABTS_TERM_TIMEDOUT BIT(11)
  75. #define SNIC_IO_INTERNAL_TERM_PENDING BIT(12)
  76. #define SNIC_IO_INTERNAL_TERM_ISSUED BIT(13)
  77. #define SNIC_DEVICE_RESET BIT(14)
  78. #define SNIC_DEV_RST_ISSUED BIT(15)
  79. #define SNIC_DEV_RST_TIMEDOUT BIT(16)
  80. #define SNIC_DEV_RST_ABTS_ISSUED BIT(17)
  81. #define SNIC_DEV_RST_TERM_ISSUED BIT(18)
  82. #define SNIC_DEV_RST_DONE BIT(19)
  83. #define SNIC_DEV_RST_REQ_NULL BIT(20)
  84. #define SNIC_DEV_RST_ABTS_DONE BIT(21)
  85. #define SNIC_DEV_RST_TERM_DONE BIT(22)
  86. #define SNIC_DEV_RST_ABTS_PENDING BIT(23)
  87. #define SNIC_DEV_RST_PENDING BIT(24)
  88. #define SNIC_DEV_RST_NOTSUP BIT(25)
  89. #define SNIC_SCSI_CLEANUP BIT(26)
  90. #define SNIC_HOST_RESET_ISSUED BIT(27)
  91. #define SNIC_ABTS_TIMEOUT 30000 /* msec */
  92. #define SNIC_LUN_RESET_TIMEOUT 30000 /* msec */
  93. #define SNIC_HOST_RESET_TIMEOUT 30000 /* msec */
  94. /*
  95. * These are protected by the hashed req_lock.
  96. */
  97. #define CMD_SP(Cmnd) \
  98. (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->rqi)
  99. #define CMD_STATE(Cmnd) \
  100. (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->state)
  101. #define CMD_ABTS_STATUS(Cmnd) \
  102. (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->abts_status)
  103. #define CMD_LR_STATUS(Cmnd) \
  104. (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->lr_status)
  105. #define CMD_FLAGS(Cmnd) \
  106. (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->flags)
  107. #define SNIC_INVALID_CODE 0x100 /* Hdr Status val unused by firmware */
  108. #define SNIC_MAX_TARGET 256
  109. #define SNIC_FLAGS_NONE (0)
  110. /* snic module params */
  111. extern unsigned int snic_max_qdepth;
  112. /* snic debugging */
  113. extern unsigned int snic_log_level;
  114. #define SNIC_MAIN_LOGGING 0x1
  115. #define SNIC_SCSI_LOGGING 0x2
  116. #define SNIC_ISR_LOGGING 0x8
  117. #define SNIC_DESC_LOGGING 0x10
  118. #define SNIC_CHECK_LOGGING(LEVEL, CMD) \
  119. do { \
  120. if (unlikely(snic_log_level & LEVEL)) \
  121. do { \
  122. CMD; \
  123. } while (0); \
  124. } while (0)
  125. #define SNIC_MAIN_DBG(host, fmt, args...) \
  126. SNIC_CHECK_LOGGING(SNIC_MAIN_LOGGING, \
  127. shost_printk(KERN_INFO, host, fmt, ## args);)
  128. #define SNIC_SCSI_DBG(host, fmt, args...) \
  129. SNIC_CHECK_LOGGING(SNIC_SCSI_LOGGING, \
  130. shost_printk(KERN_INFO, host, fmt, ##args);)
  131. #define SNIC_DISC_DBG(host, fmt, args...) \
  132. SNIC_CHECK_LOGGING(SNIC_SCSI_LOGGING, \
  133. shost_printk(KERN_INFO, host, fmt, ##args);)
  134. #define SNIC_ISR_DBG(host, fmt, args...) \
  135. SNIC_CHECK_LOGGING(SNIC_ISR_LOGGING, \
  136. shost_printk(KERN_INFO, host, fmt, ##args);)
  137. #define SNIC_HOST_ERR(host, fmt, args...) \
  138. shost_printk(KERN_ERR, host, fmt, ##args)
  139. #define SNIC_HOST_INFO(host, fmt, args...) \
  140. shost_printk(KERN_INFO, host, fmt, ##args)
  141. #define SNIC_INFO(fmt, args...) \
  142. pr_info(PFX fmt, ## args)
  143. #define SNIC_DBG(fmt, args...) \
  144. pr_info(PFX fmt, ## args)
  145. #define SNIC_ERR(fmt, args...) \
  146. pr_err(PFX fmt, ## args)
  147. #ifdef DEBUG
  148. #define SNIC_BUG_ON(EXPR) \
  149. ({ \
  150. if (EXPR) { \
  151. SNIC_ERR("SNIC BUG(%s)\n", #EXPR); \
  152. BUG_ON(EXPR); \
  153. } \
  154. })
  155. #else
  156. #define SNIC_BUG_ON(EXPR) \
  157. ({ \
  158. if (EXPR) { \
  159. SNIC_ERR("SNIC BUG(%s) at %s : %d\n", \
  160. #EXPR, __func__, __LINE__); \
  161. WARN_ON_ONCE(EXPR); \
  162. } \
  163. })
  164. #endif
  165. /* Soft assert */
  166. #define SNIC_ASSERT_NOT_IMPL(EXPR) \
  167. ({ \
  168. if (EXPR) {\
  169. SNIC_INFO("Functionality not impl'ed at %s:%d\n", \
  170. __func__, __LINE__); \
  171. WARN_ON_ONCE(EXPR); \
  172. } \
  173. })
  174. extern const char *snic_state_str[];
  175. enum snic_intx_intr_index {
  176. SNIC_INTX_WQ_RQ_COPYWQ,
  177. SNIC_INTX_ERR,
  178. SNIC_INTX_NOTIFY,
  179. SNIC_INTX_INTR_MAX,
  180. };
  181. enum snic_msix_intr_index {
  182. SNIC_MSIX_WQ,
  183. SNIC_MSIX_IO_CMPL,
  184. SNIC_MSIX_ERR_NOTIFY,
  185. SNIC_MSIX_INTR_MAX,
  186. };
  187. struct snic_msix_entry {
  188. int requested;
  189. char devname[IFNAMSIZ];
  190. irqreturn_t (*isr)(int, void *);
  191. void *devid;
  192. };
  193. enum snic_state {
  194. SNIC_INIT = 0,
  195. SNIC_ERROR,
  196. SNIC_ONLINE,
  197. SNIC_OFFLINE,
  198. SNIC_FWRESET,
  199. };
  200. #define SNIC_WQ_MAX 1
  201. #define SNIC_CQ_IO_CMPL_MAX 1
  202. #define SNIC_CQ_MAX (SNIC_WQ_MAX + SNIC_CQ_IO_CMPL_MAX)
  203. /* firmware version information */
  204. struct snic_fw_info {
  205. u32 fw_ver;
  206. u32 hid; /* u16 hid | u16 vnic id */
  207. u32 max_concur_ios; /* max concurrent ios */
  208. u32 max_sgs_per_cmd; /* max sgls per IO */
  209. u32 max_io_sz; /* max io size supported */
  210. u32 hba_cap; /* hba capabilities */
  211. u32 max_tgts; /* max tgts supported */
  212. u16 io_tmo; /* FW Extended timeout */
  213. struct completion *wait; /* protected by snic lock*/
  214. };
  215. /*
  216. * snic_work item : defined to process asynchronous events
  217. */
  218. struct snic_work {
  219. struct work_struct work;
  220. u16 ev_id;
  221. u64 *ev_data;
  222. };
  223. /*
  224. * snic structure to represent SCSI vNIC
  225. */
  226. struct snic {
  227. /* snic specific members */
  228. struct list_head list;
  229. char name[IFNAMSIZ];
  230. atomic_t state;
  231. spinlock_t snic_lock;
  232. struct completion *remove_wait;
  233. bool in_remove;
  234. bool stop_link_events; /* stop processing link events */
  235. /* discovery related */
  236. struct snic_disc disc;
  237. /* Scsi Host info */
  238. struct Scsi_Host *shost;
  239. /* vnic related structures */
  240. struct vnic_dev_bar bar0;
  241. struct vnic_stats *stats;
  242. unsigned long stats_time;
  243. unsigned long stats_reset_time;
  244. struct vnic_dev *vdev;
  245. /* hw resource info */
  246. unsigned int wq_count;
  247. unsigned int cq_count;
  248. unsigned int intr_count;
  249. unsigned int err_intr_offset;
  250. int link_status; /* retrieved from svnic_dev_link_status() */
  251. u32 link_down_cnt;
  252. /* pci related */
  253. struct pci_dev *pdev;
  254. struct msix_entry msix_entry[SNIC_MSIX_INTR_MAX];
  255. struct snic_msix_entry msix[SNIC_MSIX_INTR_MAX];
  256. /* io related info */
  257. mempool_t *req_pool[SNIC_REQ_MAX_CACHES]; /* (??) */
  258. ____cacheline_aligned spinlock_t io_req_lock[SNIC_IO_LOCKS];
  259. /* Maintain snic specific commands, cmds with no tag in spl_cmd_list */
  260. ____cacheline_aligned spinlock_t spl_cmd_lock;
  261. struct list_head spl_cmd_list;
  262. unsigned int max_tag_id;
  263. atomic_t ios_inflight; /* io in flight counter */
  264. struct vnic_snic_config config;
  265. struct work_struct link_work;
  266. /* firmware information */
  267. struct snic_fw_info fwinfo;
  268. /* Work for processing Target related work */
  269. struct work_struct tgt_work;
  270. /* Work for processing Discovery */
  271. struct work_struct disc_work;
  272. /* stats related */
  273. unsigned int reset_stats;
  274. atomic64_t io_cmpl_skip;
  275. struct snic_stats s_stats; /* Per SNIC driver stats */
  276. /* platform specific */
  277. #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
  278. struct dentry *stats_host; /* Per snic debugfs root */
  279. struct dentry *stats_file; /* Per snic debugfs file */
  280. struct dentry *reset_stats_file;/* Per snic reset stats file */
  281. #endif
  282. /* completion queue cache line section */
  283. ____cacheline_aligned struct vnic_cq cq[SNIC_CQ_MAX];
  284. /* work queue cache line section */
  285. ____cacheline_aligned struct vnic_wq wq[SNIC_WQ_MAX];
  286. spinlock_t wq_lock[SNIC_WQ_MAX];
  287. /* interrupt resource cache line section */
  288. ____cacheline_aligned struct vnic_intr intr[SNIC_MSIX_INTR_MAX];
  289. }; /* end of snic structure */
  290. /*
  291. * SNIC Driver's Global Data
  292. */
  293. struct snic_global {
  294. struct list_head snic_list;
  295. spinlock_t snic_list_lock;
  296. struct kmem_cache *req_cache[SNIC_REQ_MAX_CACHES];
  297. struct workqueue_struct *event_q;
  298. #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
  299. /* debugfs related global data */
  300. struct dentry *trc_root;
  301. struct dentry *stats_root;
  302. struct snic_trc trc ____cacheline_aligned;
  303. #endif
  304. };
  305. extern struct snic_global *snic_glob;
  306. int snic_glob_init(void);
  307. void snic_glob_cleanup(void);
  308. extern struct workqueue_struct *snic_event_queue;
  309. extern struct device_attribute *snic_attrs[];
  310. int snic_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
  311. int snic_abort_cmd(struct scsi_cmnd *);
  312. int snic_device_reset(struct scsi_cmnd *);
  313. int snic_host_reset(struct scsi_cmnd *);
  314. int snic_reset(struct Scsi_Host *, struct scsi_cmnd *);
  315. void snic_shutdown_scsi_cleanup(struct snic *);
  316. int snic_request_intr(struct snic *);
  317. void snic_free_intr(struct snic *);
  318. int snic_set_intr_mode(struct snic *);
  319. void snic_clear_intr_mode(struct snic *);
  320. int snic_fwcq_cmpl_handler(struct snic *, int);
  321. int snic_wq_cmpl_handler(struct snic *, int);
  322. void snic_free_wq_buf(struct vnic_wq *, struct vnic_wq_buf *);
  323. void snic_log_q_error(struct snic *);
  324. void snic_handle_link_event(struct snic *);
  325. void snic_handle_link(struct work_struct *);
  326. int snic_queue_exch_ver_req(struct snic *);
  327. int snic_io_exch_ver_cmpl_handler(struct snic *, struct snic_fw_req *);
  328. int snic_queue_wq_desc(struct snic *, void *os_buf, u16 len);
  329. void snic_handle_untagged_req(struct snic *, struct snic_req_info *);
  330. void snic_release_untagged_req(struct snic *, struct snic_req_info *);
  331. void snic_free_all_untagged_reqs(struct snic *);
  332. int snic_get_conf(struct snic *);
  333. void snic_set_state(struct snic *, enum snic_state);
  334. int snic_get_state(struct snic *);
  335. const char *snic_state_to_str(unsigned int);
  336. void snic_hex_dump(char *, char *, int);
  337. void snic_print_desc(const char *fn, char *os_buf, int len);
  338. const char *show_opcode_name(int val);
  339. #endif /* _SNIC_H */