drm/tests: hdmi: Fix memory leaks in drm_display_mode_from_cea_vic()
[drm/drm-misc.git] / drivers / scsi / snic / snic.h
blob32f5a34b6987e39132a39932a4373c334bc50f49
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright 2014 Cisco Systems, Inc. All rights reserved. */
4 #ifndef _SNIC_H_
5 #define _SNIC_H_
7 #include <linux/module.h>
8 #include <linux/netdevice.h>
9 #include <linux/workqueue.h>
10 #include <linux/bitops.h>
11 #include <linux/mempool.h>
12 #include <scsi/scsi_cmnd.h>
13 #include <scsi/scsi.h>
14 #include <scsi/scsi_host.h>
16 #include "snic_disc.h"
17 #include "snic_io.h"
18 #include "snic_res.h"
19 #include "snic_trc.h"
20 #include "snic_stats.h"
21 #include "vnic_dev.h"
22 #include "vnic_wq.h"
23 #include "vnic_cq.h"
24 #include "vnic_intr.h"
25 #include "vnic_stats.h"
26 #include "vnic_snic.h"
28 #define SNIC_DRV_NAME "snic"
29 #define SNIC_DRV_DESCRIPTION "Cisco SCSI NIC Driver"
30 #define SNIC_DRV_VERSION "0.0.1.18"
31 #define PFX SNIC_DRV_NAME ":"
32 #define DFX SNIC_DRV_NAME "%d: "
34 #define DESC_CLEAN_LOW_WATERMARK 8
35 #define SNIC_UCSM_DFLT_THROTTLE_CNT_BLD 16 /* UCSM default throttle count */
36 #define SNIC_MAX_IO_REQ 50 /* scsi_cmnd tag map entries */
37 #define SNIC_MIN_IO_REQ 8 /* Min IO throttle count */
38 #define SNIC_IO_LOCKS 64 /* IO locks: power of 2 */
39 #define SNIC_DFLT_QUEUE_DEPTH 32 /* Default Queue Depth */
40 #define SNIC_MAX_QUEUE_DEPTH 64 /* Max Queue Depth */
41 #define SNIC_DFLT_CMD_TIMEOUT 90 /* Extended tmo for FW */
44 * Tag bits used for special requests.
46 #define SNIC_TAG_ABORT BIT(30) /* Tag indicating abort */
47 #define SNIC_TAG_DEV_RST BIT(29) /* Tag for device reset */
48 #define SNIC_TAG_IOCTL_DEV_RST BIT(28) /* Tag for User Device Reset */
49 #define SNIC_TAG_MASK (BIT(24) - 1) /* Mask for lookup */
50 #define SNIC_NO_TAG -1
53 * Command flags to identify the type of command and for other future use
55 #define SNIC_NO_FLAGS 0
56 #define SNIC_IO_INITIALIZED BIT(0)
57 #define SNIC_IO_ISSUED BIT(1)
58 #define SNIC_IO_DONE BIT(2)
59 #define SNIC_IO_REQ_NULL BIT(3)
60 #define SNIC_IO_ABTS_PENDING BIT(4)
61 #define SNIC_IO_ABORTED BIT(5)
62 #define SNIC_IO_ABTS_ISSUED BIT(6)
63 #define SNIC_IO_TERM_ISSUED BIT(7)
64 #define SNIC_IO_ABTS_TIMEDOUT BIT(8)
65 #define SNIC_IO_ABTS_TERM_DONE BIT(9)
66 #define SNIC_IO_ABTS_TERM_REQ_NULL BIT(10)
67 #define SNIC_IO_ABTS_TERM_TIMEDOUT BIT(11)
68 #define SNIC_IO_INTERNAL_TERM_PENDING BIT(12)
69 #define SNIC_IO_INTERNAL_TERM_ISSUED BIT(13)
70 #define SNIC_DEVICE_RESET BIT(14)
71 #define SNIC_DEV_RST_ISSUED BIT(15)
72 #define SNIC_DEV_RST_TIMEDOUT BIT(16)
73 #define SNIC_DEV_RST_ABTS_ISSUED BIT(17)
74 #define SNIC_DEV_RST_TERM_ISSUED BIT(18)
75 #define SNIC_DEV_RST_DONE BIT(19)
76 #define SNIC_DEV_RST_REQ_NULL BIT(20)
77 #define SNIC_DEV_RST_ABTS_DONE BIT(21)
78 #define SNIC_DEV_RST_TERM_DONE BIT(22)
79 #define SNIC_DEV_RST_ABTS_PENDING BIT(23)
80 #define SNIC_DEV_RST_PENDING BIT(24)
81 #define SNIC_DEV_RST_NOTSUP BIT(25)
82 #define SNIC_SCSI_CLEANUP BIT(26)
83 #define SNIC_HOST_RESET_ISSUED BIT(27)
84 #define SNIC_HOST_RESET_CMD_TERM \
85 (SNIC_DEV_RST_NOTSUP | SNIC_SCSI_CLEANUP | SNIC_HOST_RESET_ISSUED)
87 #define SNIC_ABTS_TIMEOUT 30000 /* msec */
88 #define SNIC_LUN_RESET_TIMEOUT 30000 /* msec */
89 #define SNIC_HOST_RESET_TIMEOUT 30000 /* msec */
93 * These are protected by the hashed req_lock.
95 #define CMD_SP(Cmnd) \
96 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->rqi)
97 #define CMD_STATE(Cmnd) \
98 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->state)
99 #define CMD_ABTS_STATUS(Cmnd) \
100 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->abts_status)
101 #define CMD_LR_STATUS(Cmnd) \
102 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->lr_status)
103 #define CMD_FLAGS(Cmnd) \
104 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->flags)
106 #define SNIC_INVALID_CODE 0x100 /* Hdr Status val unused by firmware */
108 #define SNIC_MAX_TARGET 256
109 #define SNIC_FLAGS_NONE (0)
111 /* snic module params */
112 extern unsigned int snic_max_qdepth;
114 /* snic debugging */
115 extern unsigned int snic_log_level;
117 #define SNIC_MAIN_LOGGING 0x1
118 #define SNIC_SCSI_LOGGING 0x2
119 #define SNIC_ISR_LOGGING 0x8
120 #define SNIC_DESC_LOGGING 0x10
122 #define SNIC_CHECK_LOGGING(LEVEL, CMD) \
123 do { \
124 if (unlikely(snic_log_level & LEVEL)) \
125 do { \
126 CMD; \
127 } while (0); \
128 } while (0)
130 #define SNIC_MAIN_DBG(host, fmt, args...) \
131 SNIC_CHECK_LOGGING(SNIC_MAIN_LOGGING, \
132 shost_printk(KERN_INFO, host, fmt, ## args);)
134 #define SNIC_SCSI_DBG(host, fmt, args...) \
135 SNIC_CHECK_LOGGING(SNIC_SCSI_LOGGING, \
136 shost_printk(KERN_INFO, host, fmt, ##args);)
138 #define SNIC_DISC_DBG(host, fmt, args...) \
139 SNIC_CHECK_LOGGING(SNIC_SCSI_LOGGING, \
140 shost_printk(KERN_INFO, host, fmt, ##args);)
142 #define SNIC_ISR_DBG(host, fmt, args...) \
143 SNIC_CHECK_LOGGING(SNIC_ISR_LOGGING, \
144 shost_printk(KERN_INFO, host, fmt, ##args);)
146 #define SNIC_HOST_ERR(host, fmt, args...) \
147 shost_printk(KERN_ERR, host, fmt, ##args)
149 #define SNIC_HOST_INFO(host, fmt, args...) \
150 shost_printk(KERN_INFO, host, fmt, ##args)
152 #define SNIC_INFO(fmt, args...) \
153 pr_info(PFX fmt, ## args)
155 #define SNIC_DBG(fmt, args...) \
156 pr_info(PFX fmt, ## args)
158 #define SNIC_ERR(fmt, args...) \
159 pr_err(PFX fmt, ## args)
161 #ifdef DEBUG
162 #define SNIC_BUG_ON(EXPR) \
163 ({ \
164 if (EXPR) { \
165 SNIC_ERR("SNIC BUG(%s)\n", #EXPR); \
166 BUG_ON(EXPR); \
169 #else
170 #define SNIC_BUG_ON(EXPR) \
171 ({ \
172 if (EXPR) { \
173 SNIC_ERR("SNIC BUG(%s) at %s : %d\n", \
174 #EXPR, __func__, __LINE__); \
175 WARN_ON_ONCE(EXPR); \
178 #endif
180 /* Soft assert */
181 #define SNIC_ASSERT_NOT_IMPL(EXPR) \
182 ({ \
183 if (EXPR) {\
184 SNIC_INFO("Functionality not impl'ed at %s:%d\n", \
185 __func__, __LINE__); \
186 WARN_ON_ONCE(EXPR); \
191 extern const char *snic_state_str[];
193 enum snic_intx_intr_index {
194 SNIC_INTX_WQ_RQ_COPYWQ,
195 SNIC_INTX_ERR,
196 SNIC_INTX_NOTIFY,
197 SNIC_INTX_INTR_MAX,
200 enum snic_msix_intr_index {
201 SNIC_MSIX_WQ,
202 SNIC_MSIX_IO_CMPL,
203 SNIC_MSIX_ERR_NOTIFY,
204 SNIC_MSIX_INTR_MAX,
207 #define SNIC_INTRHDLR_NAMSZ (2 * IFNAMSIZ)
208 struct snic_msix_entry {
209 int requested;
210 char devname[SNIC_INTRHDLR_NAMSZ];
211 irqreturn_t (*isr)(int, void *);
212 void *devid;
215 enum snic_state {
216 SNIC_INIT = 0,
217 SNIC_ERROR,
218 SNIC_ONLINE,
219 SNIC_OFFLINE,
220 SNIC_FWRESET,
223 #define SNIC_WQ_MAX 1
224 #define SNIC_CQ_IO_CMPL_MAX 1
225 #define SNIC_CQ_MAX (SNIC_WQ_MAX + SNIC_CQ_IO_CMPL_MAX)
227 /* firmware version information */
228 struct snic_fw_info {
229 u32 fw_ver;
230 u32 hid; /* u16 hid | u16 vnic id */
231 u32 max_concur_ios; /* max concurrent ios */
232 u32 max_sgs_per_cmd; /* max sgls per IO */
233 u32 max_io_sz; /* max io size supported */
234 u32 hba_cap; /* hba capabilities */
235 u32 max_tgts; /* max tgts supported */
236 u16 io_tmo; /* FW Extended timeout */
237 struct completion *wait; /* protected by snic lock*/
241 * snic_work item : defined to process asynchronous events
243 struct snic_work {
244 struct work_struct work;
245 u16 ev_id;
246 u64 *ev_data;
250 * snic structure to represent SCSI vNIC
252 struct snic {
253 /* snic specific members */
254 struct list_head list;
255 char name[IFNAMSIZ];
256 atomic_t state;
257 spinlock_t snic_lock;
258 struct completion *remove_wait;
259 bool in_remove;
260 bool stop_link_events; /* stop processing link events */
262 /* discovery related */
263 struct snic_disc disc;
265 /* Scsi Host info */
266 struct Scsi_Host *shost;
268 /* vnic related structures */
269 struct vnic_dev_bar bar0;
271 struct vnic_stats *stats;
272 unsigned long stats_time;
273 unsigned long stats_reset_time;
275 struct vnic_dev *vdev;
277 /* hw resource info */
278 unsigned int wq_count;
279 unsigned int cq_count;
280 unsigned int intr_count;
281 unsigned int err_intr_offset;
283 int link_status; /* retrieved from svnic_dev_link_status() */
284 u32 link_down_cnt;
286 /* pci related */
287 struct pci_dev *pdev;
288 struct snic_msix_entry msix[SNIC_MSIX_INTR_MAX];
290 /* io related info */
291 mempool_t *req_pool[SNIC_REQ_MAX_CACHES]; /* (??) */
292 ____cacheline_aligned spinlock_t io_req_lock[SNIC_IO_LOCKS];
294 /* Maintain snic specific commands, cmds with no tag in spl_cmd_list */
295 ____cacheline_aligned spinlock_t spl_cmd_lock;
296 struct list_head spl_cmd_list;
298 unsigned int max_tag_id;
299 atomic_t ios_inflight; /* io in flight counter */
301 struct vnic_snic_config config;
303 struct work_struct link_work;
305 /* firmware information */
306 struct snic_fw_info fwinfo;
308 /* Work for processing Target related work */
309 struct work_struct tgt_work;
311 /* Work for processing Discovery */
312 struct work_struct disc_work;
314 /* stats related */
315 unsigned int reset_stats;
316 atomic64_t io_cmpl_skip;
317 struct snic_stats s_stats; /* Per SNIC driver stats */
319 /* platform specific */
320 #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
321 struct dentry *stats_host; /* Per snic debugfs root */
322 struct dentry *stats_file; /* Per snic debugfs file */
323 struct dentry *reset_stats_file;/* Per snic reset stats file */
324 #endif
326 /* completion queue cache line section */
327 ____cacheline_aligned struct vnic_cq cq[SNIC_CQ_MAX];
329 /* work queue cache line section */
330 ____cacheline_aligned struct vnic_wq wq[SNIC_WQ_MAX];
331 spinlock_t wq_lock[SNIC_WQ_MAX];
333 /* interrupt resource cache line section */
334 ____cacheline_aligned struct vnic_intr intr[SNIC_MSIX_INTR_MAX];
335 }; /* end of snic structure */
338 * SNIC Driver's Global Data
340 struct snic_global {
341 struct list_head snic_list;
342 spinlock_t snic_list_lock;
344 struct kmem_cache *req_cache[SNIC_REQ_MAX_CACHES];
346 struct workqueue_struct *event_q;
348 #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
349 /* debugfs related global data */
350 struct dentry *trc_root;
351 struct dentry *stats_root;
353 struct snic_trc trc ____cacheline_aligned;
354 #endif
357 extern struct snic_global *snic_glob;
359 int snic_glob_init(void);
360 void snic_glob_cleanup(void);
362 extern struct workqueue_struct *snic_event_queue;
363 extern const struct attribute_group *snic_host_groups[];
365 int snic_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
366 int snic_abort_cmd(struct scsi_cmnd *);
367 int snic_device_reset(struct scsi_cmnd *);
368 int snic_host_reset(struct scsi_cmnd *);
369 int snic_reset(struct Scsi_Host *, struct scsi_cmnd *);
370 void snic_shutdown_scsi_cleanup(struct snic *);
373 int snic_request_intr(struct snic *);
374 void snic_free_intr(struct snic *);
375 int snic_set_intr_mode(struct snic *);
376 void snic_clear_intr_mode(struct snic *);
378 int snic_fwcq_cmpl_handler(struct snic *, int);
379 int snic_wq_cmpl_handler(struct snic *, int);
380 void snic_free_wq_buf(struct vnic_wq *, struct vnic_wq_buf *);
383 void snic_log_q_error(struct snic *);
384 void snic_handle_link_event(struct snic *);
385 void snic_handle_link(struct work_struct *);
387 int snic_queue_exch_ver_req(struct snic *);
388 void snic_io_exch_ver_cmpl_handler(struct snic *, struct snic_fw_req *);
390 int snic_queue_wq_desc(struct snic *, void *os_buf, u16 len);
392 void snic_handle_untagged_req(struct snic *, struct snic_req_info *);
393 void snic_release_untagged_req(struct snic *, struct snic_req_info *);
394 void snic_free_all_untagged_reqs(struct snic *);
395 int snic_get_conf(struct snic *);
396 void snic_set_state(struct snic *, enum snic_state);
397 int snic_get_state(struct snic *);
398 const char *snic_state_to_str(unsigned int);
399 void snic_hex_dump(char *, char *, int);
400 void snic_print_desc(const char *fn, char *os_buf, int len);
401 const char *show_opcode_name(int val);
402 #endif /* _SNIC_H */