1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef _SNIC_H_
19#define _SNIC_H_
20
21#include <linux/module.h>
22#include <linux/netdevice.h>
23#include <linux/workqueue.h>
24#include <linux/bitops.h>
25#include <linux/mempool.h>
26#include <scsi/scsi_cmnd.h>
27#include <scsi/scsi.h>
28#include <scsi/scsi_host.h>
29
30#include "snic_disc.h"
31#include "snic_io.h"
32#include "snic_res.h"
33#include "snic_trc.h"
34#include "snic_stats.h"
35#include "vnic_dev.h"
36#include "vnic_wq.h"
37#include "vnic_cq.h"
38#include "vnic_intr.h"
39#include "vnic_stats.h"
40#include "vnic_snic.h"
41
42#define SNIC_DRV_NAME "snic"
43#define SNIC_DRV_DESCRIPTION "Cisco SCSI NIC Driver"
44#define SNIC_DRV_VERSION "0.0.1.18"
45#define PFX SNIC_DRV_NAME ":"
46#define DFX SNIC_DRV_NAME "%d: "
47
48#define DESC_CLEAN_LOW_WATERMARK 8
49#define SNIC_UCSM_DFLT_THROTTLE_CNT_BLD 16
50#define SNIC_MAX_IO_REQ 50
51#define SNIC_MIN_IO_REQ 8
52#define SNIC_IO_LOCKS 64
53#define SNIC_DFLT_QUEUE_DEPTH 32
54#define SNIC_MAX_QUEUE_DEPTH 64
55#define SNIC_DFLT_CMD_TIMEOUT 90
56
57
58
59
60#define SNIC_TAG_ABORT BIT(30)
61#define SNIC_TAG_DEV_RST BIT(29)
62#define SNIC_TAG_IOCTL_DEV_RST BIT(28)
63#define SNIC_TAG_MASK (BIT(24) - 1)
64#define SNIC_NO_TAG -1
65
66
67
68
69#define SNIC_NO_FLAGS 0
70#define SNIC_IO_INITIALIZED BIT(0)
71#define SNIC_IO_ISSUED BIT(1)
72#define SNIC_IO_DONE BIT(2)
73#define SNIC_IO_REQ_NULL BIT(3)
74#define SNIC_IO_ABTS_PENDING BIT(4)
75#define SNIC_IO_ABORTED BIT(5)
76#define SNIC_IO_ABTS_ISSUED BIT(6)
77#define SNIC_IO_TERM_ISSUED BIT(7)
78#define SNIC_IO_ABTS_TIMEDOUT BIT(8)
79#define SNIC_IO_ABTS_TERM_DONE BIT(9)
80#define SNIC_IO_ABTS_TERM_REQ_NULL BIT(10)
81#define SNIC_IO_ABTS_TERM_TIMEDOUT BIT(11)
82#define SNIC_IO_INTERNAL_TERM_PENDING BIT(12)
83#define SNIC_IO_INTERNAL_TERM_ISSUED BIT(13)
84#define SNIC_DEVICE_RESET BIT(14)
85#define SNIC_DEV_RST_ISSUED BIT(15)
86#define SNIC_DEV_RST_TIMEDOUT BIT(16)
87#define SNIC_DEV_RST_ABTS_ISSUED BIT(17)
88#define SNIC_DEV_RST_TERM_ISSUED BIT(18)
89#define SNIC_DEV_RST_DONE BIT(19)
90#define SNIC_DEV_RST_REQ_NULL BIT(20)
91#define SNIC_DEV_RST_ABTS_DONE BIT(21)
92#define SNIC_DEV_RST_TERM_DONE BIT(22)
93#define SNIC_DEV_RST_ABTS_PENDING BIT(23)
94#define SNIC_DEV_RST_PENDING BIT(24)
95#define SNIC_DEV_RST_NOTSUP BIT(25)
96#define SNIC_SCSI_CLEANUP BIT(26)
97#define SNIC_HOST_RESET_ISSUED BIT(27)
98#define SNIC_HOST_RESET_CMD_TERM \
99 (SNIC_DEV_RST_NOTSUP | SNIC_SCSI_CLEANUP | SNIC_HOST_RESET_ISSUED)
100
101#define SNIC_ABTS_TIMEOUT 30000
102#define SNIC_LUN_RESET_TIMEOUT 30000
103#define SNIC_HOST_RESET_TIMEOUT 30000
104
105
106
107
108
109#define CMD_SP(Cmnd) \
110 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->rqi)
111#define CMD_STATE(Cmnd) \
112 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->state)
113#define CMD_ABTS_STATUS(Cmnd) \
114 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->abts_status)
115#define CMD_LR_STATUS(Cmnd) \
116 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->lr_status)
117#define CMD_FLAGS(Cmnd) \
118 (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->flags)
119
120#define SNIC_INVALID_CODE 0x100
121
122#define SNIC_MAX_TARGET 256
123#define SNIC_FLAGS_NONE (0)
124
125
126extern unsigned int snic_max_qdepth;
127
128
129extern unsigned int snic_log_level;
130
131#define SNIC_MAIN_LOGGING 0x1
132#define SNIC_SCSI_LOGGING 0x2
133#define SNIC_ISR_LOGGING 0x8
134#define SNIC_DESC_LOGGING 0x10
135
136#define SNIC_CHECK_LOGGING(LEVEL, CMD) \
137do { \
138 if (unlikely(snic_log_level & LEVEL)) \
139 do { \
140 CMD; \
141 } while (0); \
142} while (0)
143
144#define SNIC_MAIN_DBG(host, fmt, args...) \
145 SNIC_CHECK_LOGGING(SNIC_MAIN_LOGGING, \
146 shost_printk(KERN_INFO, host, fmt, ## args);)
147
148#define SNIC_SCSI_DBG(host, fmt, args...) \
149 SNIC_CHECK_LOGGING(SNIC_SCSI_LOGGING, \
150 shost_printk(KERN_INFO, host, fmt, ##args);)
151
152#define SNIC_DISC_DBG(host, fmt, args...) \
153 SNIC_CHECK_LOGGING(SNIC_SCSI_LOGGING, \
154 shost_printk(KERN_INFO, host, fmt, ##args);)
155
156#define SNIC_ISR_DBG(host, fmt, args...) \
157 SNIC_CHECK_LOGGING(SNIC_ISR_LOGGING, \
158 shost_printk(KERN_INFO, host, fmt, ##args);)
159
160#define SNIC_HOST_ERR(host, fmt, args...) \
161 shost_printk(KERN_ERR, host, fmt, ##args)
162
163#define SNIC_HOST_INFO(host, fmt, args...) \
164 shost_printk(KERN_INFO, host, fmt, ##args)
165
166#define SNIC_INFO(fmt, args...) \
167 pr_info(PFX fmt, ## args)
168
169#define SNIC_DBG(fmt, args...) \
170 pr_info(PFX fmt, ## args)
171
172#define SNIC_ERR(fmt, args...) \
173 pr_err(PFX fmt, ## args)
174
175#ifdef DEBUG
176#define SNIC_BUG_ON(EXPR) \
177 ({ \
178 if (EXPR) { \
179 SNIC_ERR("SNIC BUG(%s)\n", #EXPR); \
180 BUG_ON(EXPR); \
181 } \
182 })
183#else
184#define SNIC_BUG_ON(EXPR) \
185 ({ \
186 if (EXPR) { \
187 SNIC_ERR("SNIC BUG(%s) at %s : %d\n", \
188 #EXPR, __func__, __LINE__); \
189 WARN_ON_ONCE(EXPR); \
190 } \
191 })
192#endif
193
194
195#define SNIC_ASSERT_NOT_IMPL(EXPR) \
196 ({ \
197 if (EXPR) {\
198 SNIC_INFO("Functionality not impl'ed at %s:%d\n", \
199 __func__, __LINE__); \
200 WARN_ON_ONCE(EXPR); \
201 } \
202 })
203
204
205extern const char *snic_state_str[];
206
207enum snic_intx_intr_index {
208 SNIC_INTX_WQ_RQ_COPYWQ,
209 SNIC_INTX_ERR,
210 SNIC_INTX_NOTIFY,
211 SNIC_INTX_INTR_MAX,
212};
213
214enum snic_msix_intr_index {
215 SNIC_MSIX_WQ,
216 SNIC_MSIX_IO_CMPL,
217 SNIC_MSIX_ERR_NOTIFY,
218 SNIC_MSIX_INTR_MAX,
219};
220
221#define SNIC_INTRHDLR_NAMSZ (2 * IFNAMSIZ)
222struct snic_msix_entry {
223 int requested;
224 char devname[SNIC_INTRHDLR_NAMSZ];
225 irqreturn_t (*isr)(int, void *);
226 void *devid;
227};
228
229enum snic_state {
230 SNIC_INIT = 0,
231 SNIC_ERROR,
232 SNIC_ONLINE,
233 SNIC_OFFLINE,
234 SNIC_FWRESET,
235};
236
237#define SNIC_WQ_MAX 1
238#define SNIC_CQ_IO_CMPL_MAX 1
239#define SNIC_CQ_MAX (SNIC_WQ_MAX + SNIC_CQ_IO_CMPL_MAX)
240
241
242struct snic_fw_info {
243 u32 fw_ver;
244 u32 hid;
245 u32 max_concur_ios;
246 u32 max_sgs_per_cmd;
247 u32 max_io_sz;
248 u32 hba_cap;
249 u32 max_tgts;
250 u16 io_tmo;
251 struct completion *wait;
252};
253
254
255
256
257struct snic_work {
258 struct work_struct work;
259 u16 ev_id;
260 u64 *ev_data;
261};
262
263
264
265
266struct snic {
267
268 struct list_head list;
269 char name[IFNAMSIZ];
270 atomic_t state;
271 spinlock_t snic_lock;
272 struct completion *remove_wait;
273 bool in_remove;
274 bool stop_link_events;
275
276
277 struct snic_disc disc;
278
279
280 struct Scsi_Host *shost;
281
282
283 struct vnic_dev_bar bar0;
284
285 struct vnic_stats *stats;
286 unsigned long stats_time;
287 unsigned long stats_reset_time;
288
289 struct vnic_dev *vdev;
290
291
292 unsigned int wq_count;
293 unsigned int cq_count;
294 unsigned int intr_count;
295 unsigned int err_intr_offset;
296
297 int link_status;
298 u32 link_down_cnt;
299
300
301 struct pci_dev *pdev;
302 struct snic_msix_entry msix[SNIC_MSIX_INTR_MAX];
303
304
305 mempool_t *req_pool[SNIC_REQ_MAX_CACHES];
306 ____cacheline_aligned spinlock_t io_req_lock[SNIC_IO_LOCKS];
307
308
309 ____cacheline_aligned spinlock_t spl_cmd_lock;
310 struct list_head spl_cmd_list;
311
312 unsigned int max_tag_id;
313 atomic_t ios_inflight;
314
315 struct vnic_snic_config config;
316
317 struct work_struct link_work;
318
319
320 struct snic_fw_info fwinfo;
321
322
323 struct work_struct tgt_work;
324
325
326 struct work_struct disc_work;
327
328
329 unsigned int reset_stats;
330 atomic64_t io_cmpl_skip;
331 struct snic_stats s_stats;
332
333
334#ifdef CONFIG_SCSI_SNIC_DEBUG_FS
335 struct dentry *stats_host;
336 struct dentry *stats_file;
337 struct dentry *reset_stats_file;
338#endif
339
340
341 ____cacheline_aligned struct vnic_cq cq[SNIC_CQ_MAX];
342
343
344 ____cacheline_aligned struct vnic_wq wq[SNIC_WQ_MAX];
345 spinlock_t wq_lock[SNIC_WQ_MAX];
346
347
348 ____cacheline_aligned struct vnic_intr intr[SNIC_MSIX_INTR_MAX];
349};
350
351
352
353
354struct snic_global {
355 struct list_head snic_list;
356 spinlock_t snic_list_lock;
357
358 struct kmem_cache *req_cache[SNIC_REQ_MAX_CACHES];
359
360 struct workqueue_struct *event_q;
361
362#ifdef CONFIG_SCSI_SNIC_DEBUG_FS
363
364 struct dentry *trc_root;
365 struct dentry *stats_root;
366
367 struct snic_trc trc ____cacheline_aligned;
368#endif
369};
370
371extern struct snic_global *snic_glob;
372
373int snic_glob_init(void);
374void snic_glob_cleanup(void);
375
376extern struct workqueue_struct *snic_event_queue;
377extern struct device_attribute *snic_attrs[];
378
379int snic_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
380int snic_abort_cmd(struct scsi_cmnd *);
381int snic_device_reset(struct scsi_cmnd *);
382int snic_host_reset(struct scsi_cmnd *);
383int snic_reset(struct Scsi_Host *, struct scsi_cmnd *);
384void snic_shutdown_scsi_cleanup(struct snic *);
385
386
387int snic_request_intr(struct snic *);
388void snic_free_intr(struct snic *);
389int snic_set_intr_mode(struct snic *);
390void snic_clear_intr_mode(struct snic *);
391
392int snic_fwcq_cmpl_handler(struct snic *, int);
393int snic_wq_cmpl_handler(struct snic *, int);
394void snic_free_wq_buf(struct vnic_wq *, struct vnic_wq_buf *);
395
396
397void snic_log_q_error(struct snic *);
398void snic_handle_link_event(struct snic *);
399void snic_handle_link(struct work_struct *);
400
401int snic_queue_exch_ver_req(struct snic *);
402void snic_io_exch_ver_cmpl_handler(struct snic *, struct snic_fw_req *);
403
404int snic_queue_wq_desc(struct snic *, void *os_buf, u16 len);
405
406void snic_handle_untagged_req(struct snic *, struct snic_req_info *);
407void snic_release_untagged_req(struct snic *, struct snic_req_info *);
408void snic_free_all_untagged_reqs(struct snic *);
409int snic_get_conf(struct snic *);
410void snic_set_state(struct snic *, enum snic_state);
411int snic_get_state(struct snic *);
412const char *snic_state_to_str(unsigned int);
413void snic_hex_dump(char *, char *, int);
414void snic_print_desc(const char *fn, char *os_buf, int len);
415const char *show_opcode_name(int val);
416#endif
417