blob: 24b5fd75501a60b450c6f349f1230711b022d725 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef CCISS_H
2#define CCISS_H
3
4#include <linux/genhd.h>
Andrew Pattersonb368c9d2009-09-17 13:46:58 -05005#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
7#include "cciss_cmd.h"
8
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#define NWD_SHIFT 4
11#define MAX_PART (1 << NWD_SHIFT)
12
13#define IO_OK 0
14#define IO_ERROR 1
scameron@beardog.cca.cpqcorp.net789a4242009-06-08 16:05:56 -050015#define IO_NEEDS_RETRY 3
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Andrew Patterson7fe06322009-06-02 14:48:39 +020017#define VENDOR_LEN 8
18#define MODEL_LEN 16
19#define REV_LEN 4
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021struct ctlr_info;
22typedef struct ctlr_info ctlr_info_t;
23
24struct access_method {
25 void (*submit_command)(ctlr_info_t *h, CommandList_struct *c);
26 void (*set_intr_mask)(ctlr_info_t *h, unsigned long val);
27 unsigned long (*fifo_full)(ctlr_info_t *h);
Mike Miller1d141442010-06-02 12:58:04 -070028 bool (*intr_pending)(ctlr_info_t *h);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 unsigned long (*command_completed)(ctlr_info_t *h);
30};
31typedef struct _drive_info_struct
32{
Stephen M. Cameron39ccf9a2009-09-17 13:48:00 -050033 unsigned char LunID[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 int usage_count;
Mike Millerad2b9312005-07-28 01:07:31 -070035 struct request_queue *queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 sector_t nr_blocks;
37 int block_size;
38 int heads;
39 int sectors;
40 int cylinders;
Mike Millerddd47442005-09-13 01:25:22 -070041 int raid_level; /* set to -1 to indicate that
42 * the drive is not in use/configured
Andrew Patterson7fe06322009-06-02 14:48:39 +020043 */
44 int busy_configuring; /* This is set when a drive is being removed
45 * to prevent it from being opened or it's
46 * queue from being started.
47 */
Stephen M. Cameron9cef0d22009-09-17 13:48:31 -050048 struct device dev;
Andrew Patterson7fe06322009-06-02 14:48:39 +020049 __u8 serial_no[16]; /* from inquiry page 0x83,
50 * not necc. null terminated.
51 */
52 char vendor[VENDOR_LEN + 1]; /* SCSI vendor string */
53 char model[MODEL_LEN + 1]; /* SCSI model string */
54 char rev[REV_LEN + 1]; /* SCSI revision string */
Stephen M. Cameron9cef0d22009-09-17 13:48:31 -050055 char device_initialized; /* indicates whether dev is initialized */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056} drive_info_struct;
57
Don Brace5c07a312009-11-12 12:50:01 -060058struct ctlr_info
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
60 int ctlr;
61 char devname[8];
62 char *product_name;
dann frazierb0284612010-02-17 16:53:31 -070063 char firm_ver[4]; /* Firmware version */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 struct pci_dev *pdev;
65 __u32 board_id;
66 void __iomem *vaddr;
67 unsigned long paddr;
Mike Millerf8806322006-12-06 20:35:01 -080068 int nr_cmds; /* Number of commands allowed on this controller */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 CfgTable_struct __iomem *cfgtable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 int interrupts_enabled;
71 int major;
72 int max_commands;
73 int commands_outstanding;
74 int max_outstanding; /* Debug */
75 int num_luns;
76 int highest_lun;
77 int usage_count; /* number of opens all all minor devices */
Don Brace5c07a312009-11-12 12:50:01 -060078 /* Need space for temp sg list
79 * number of scatter/gathers supported
80 * number of scatter/gathers in chained block
81 */
82 struct scatterlist **scatter_list;
83 int maxsgentries;
84 int chainsize;
85 int max_cmd_sgentries;
Stephen M. Camerondccc9b52010-02-26 16:01:27 -060086 SGDescriptor_struct **cmd_sg_list;
Don Brace5c07a312009-11-12 12:50:01 -060087
Mike Miller5e216152010-06-02 12:58:06 -070088# define PERF_MODE_INT 0
89# define DOORBELL_INT 1
Mike Millerfb86a352006-01-08 01:03:50 -080090# define SIMPLE_MODE_INT 2
91# define MEMQ_MODE_INT 3
92 unsigned int intr[4];
Joseph Handzik13049532011-08-08 11:40:15 +020093 int intr_mode;
Mike Miller92c4231a2006-12-06 20:35:06 -080094 int cciss_max_sectors;
Mike Miller (OS Dev)00988a32006-09-30 23:27:23 -070095 BYTE cciss_read;
96 BYTE cciss_write;
97 BYTE cciss_read_capacity;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
dann frazierb0284612010-02-17 16:53:31 -070099 /* information about each logical volume */
Stephen M. Cameron9cef0d22009-09-17 13:48:31 -0500100 drive_info_struct *drv[CISS_MAX_LUN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102 struct access_method access;
103
104 /* queue and queue Info */
Jens Axboee6e1ee92011-01-10 21:50:33 +0100105 struct list_head reqQ;
106 struct list_head cmpQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 unsigned int Qdepth;
108 unsigned int maxQsinceinit;
109 unsigned int maxSG;
110 spinlock_t lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
dann frazierb0284612010-02-17 16:53:31 -0700112 /* pointers to command and error info pool */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 CommandList_struct *cmd_pool;
114 dma_addr_t cmd_pool_dhandle;
115 ErrorInfo_struct *errinfo_pool;
116 dma_addr_t errinfo_pool_dhandle;
117 unsigned long *cmd_pool_bits;
118 int nr_allocs;
119 int nr_frees;
120 int busy_configuring;
Mike Miller1f8ef382005-09-13 01:25:21 -0700121 int busy_initializing;
Andrew Pattersonb368c9d2009-09-17 13:46:58 -0500122 int busy_scanning;
123 struct mutex busy_shutting_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 /* This element holds the zero based queue number of the last
126 * queue to be started. It is used for fairness.
127 */
128 int next_to_run;
129
dann frazierb0284612010-02-17 16:53:31 -0700130 /* Disk structures we need to pass back */
Mike Miller799202c2006-12-06 20:35:12 -0800131 struct gendisk *gendisk[CISS_MAX_LUN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#ifdef CONFIG_CISS_SCSI_TAPE
Stephen M. Cameronaad9fb62010-02-26 16:01:42 -0600133 struct cciss_scsi_adapter_data_t *scsi_ctlr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif
Mike Miller33079b22005-09-13 01:25:22 -0700135 unsigned char alive;
Andrew Pattersonb368c9d2009-09-17 13:46:58 -0500136 struct list_head scan_list;
137 struct completion scan_wait;
Andrew Patterson7fe06322009-06-02 14:48:39 +0200138 struct device dev;
Mike Miller5e216152010-06-02 12:58:06 -0700139 /*
140 * Performant mode tables.
141 */
142 u32 trans_support;
143 u32 trans_offset;
144 struct TransTable_struct *transtable;
145 unsigned long transMethod;
146
147 /*
148 * Performant mode completion buffer
149 */
150 u64 *reply_pool;
151 dma_addr_t reply_pool_dhandle;
152 u64 *reply_pool_head;
153 size_t reply_pool_size;
154 unsigned char reply_pool_wraparound;
155 u32 *blockFetchTable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156};
157
Mike Miller5e216152010-06-02 12:58:06 -0700158/* Defining the diffent access_methods
159 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 * Memory mapped FIFO interface (SMART 53xx cards)
161 */
162#define SA5_DOORBELL 0x20
163#define SA5_REQUEST_PORT_OFFSET 0x40
164#define SA5_REPLY_INTR_MASK_OFFSET 0x34
165#define SA5_REPLY_PORT_OFFSET 0x44
166#define SA5_INTR_STATUS 0x30
167#define SA5_SCRATCHPAD_OFFSET 0xB0
168
169#define SA5_CTCFG_OFFSET 0xB4
170#define SA5_CTMEM_OFFSET 0xB8
171
172#define SA5_INTR_OFF 0x08
173#define SA5B_INTR_OFF 0x04
174#define SA5_INTR_PENDING 0x08
175#define SA5B_INTR_PENDING 0x04
176#define FIFO_EMPTY 0xffffffff
177#define CCISS_FIRMWARE_READY 0xffff0000 /* value in scratchpad register */
Mike Miller5e216152010-06-02 12:58:06 -0700178/* Perf. mode flags */
179#define SA5_PERF_INTR_PENDING 0x04
180#define SA5_PERF_INTR_OFF 0x05
181#define SA5_OUTDB_STATUS_PERF_BIT 0x01
182#define SA5_OUTDB_CLEAR_PERF_BIT 0x01
183#define SA5_OUTDB_CLEAR 0xA0
184#define SA5_OUTDB_CLEAR_PERF_BIT 0x01
185#define SA5_OUTDB_STATUS 0x9C
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188#define CISS_ERROR_BIT 0x02
189
190#define CCISS_INTR_ON 1
191#define CCISS_INTR_OFF 0
Stephen M. Camerone99ba132010-07-19 13:45:15 -0500192
193
194/* CCISS_BOARD_READY_WAIT_SECS is how long to wait for a board
195 * to become ready, in seconds, before giving up on it.
196 * CCISS_BOARD_READY_POLL_INTERVAL_MSECS * is how long to wait
197 * between polling the board to see if it is ready, in
198 * milliseconds. CCISS_BOARD_READY_ITERATIONS is derived
199 * the above.
200 */
201#define CCISS_BOARD_READY_WAIT_SECS (120)
Stephen M. Cameron19adbb92011-05-03 14:53:31 -0500202#define CCISS_BOARD_NOT_READY_WAIT_SECS (100)
Stephen M. Camerone99ba132010-07-19 13:45:15 -0500203#define CCISS_BOARD_READY_POLL_INTERVAL_MSECS (100)
204#define CCISS_BOARD_READY_ITERATIONS \
205 ((CCISS_BOARD_READY_WAIT_SECS * 1000) / \
206 CCISS_BOARD_READY_POLL_INTERVAL_MSECS)
Stephen M. Cameronafa842f2010-10-22 14:21:07 -0500207#define CCISS_BOARD_NOT_READY_ITERATIONS \
208 ((CCISS_BOARD_NOT_READY_WAIT_SECS * 1000) / \
209 CCISS_BOARD_READY_POLL_INTERVAL_MSECS)
Stephen M. Cameron83123cb2010-07-19 13:46:17 -0500210#define CCISS_POST_RESET_PAUSE_MSECS (3000)
Stephen M. Cameron3e286012011-05-03 14:53:41 -0500211#define CCISS_POST_RESET_NOOP_INTERVAL_MSECS (4000)
Stephen M. Cameron83123cb2010-07-19 13:46:17 -0500212#define CCISS_POST_RESET_NOOP_RETRIES (12)
Stephen M. Cameron3e286012011-05-03 14:53:41 -0500213#define CCISS_POST_RESET_NOOP_TIMEOUT_MSECS (10000)
Stephen M. Camerone99ba132010-07-19 13:45:15 -0500214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215/*
216 Send the command to the hardware
217*/
218static void SA5_submit_command( ctlr_info_t *h, CommandList_struct *c)
219{
220#ifdef CCISS_DEBUG
Mike Miller5e216152010-06-02 12:58:06 -0700221 printk(KERN_WARNING "cciss%d: Sending %08x - down to controller\n",
222 h->ctlr, c->busaddr);
223#endif /* CCISS_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
Stephen M. Cameron07d0c382011-07-09 09:04:12 +0200225 readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 h->commands_outstanding++;
227 if ( h->commands_outstanding > h->max_outstanding)
228 h->max_outstanding = h->commands_outstanding;
229}
230
231/*
232 * This card is the opposite of the other cards.
233 * 0 turns interrupts on...
234 * 0x08 turns them off...
235 */
236static void SA5_intr_mask(ctlr_info_t *h, unsigned long val)
237{
238 if (val)
239 { /* Turn interrupts on */
240 h->interrupts_enabled = 1;
241 writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Stephen M. Cameron9bd3c202011-05-03 14:52:54 -0500242 (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 } else /* Turn them off */
244 {
245 h->interrupts_enabled = 0;
246 writel( SA5_INTR_OFF,
247 h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Stephen M. Cameron9bd3c202011-05-03 14:52:54 -0500248 (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
250}
251/*
252 * This card is the opposite of the other cards.
253 * 0 turns interrupts on...
254 * 0x04 turns them off...
255 */
256static void SA5B_intr_mask(ctlr_info_t *h, unsigned long val)
257{
258 if (val)
259 { /* Turn interrupts on */
260 h->interrupts_enabled = 1;
261 writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Stephen M. Cameron9bd3c202011-05-03 14:52:54 -0500262 (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 } else /* Turn them off */
264 {
265 h->interrupts_enabled = 0;
266 writel( SA5B_INTR_OFF,
267 h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Stephen M. Cameron9bd3c202011-05-03 14:52:54 -0500268 (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 }
270}
Mike Miller5e216152010-06-02 12:58:06 -0700271
272/* Performant mode intr_mask */
273static void SA5_performant_intr_mask(ctlr_info_t *h, unsigned long val)
274{
275 if (val) { /* turn on interrupts */
276 h->interrupts_enabled = 1;
277 writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Stephen M. Cameron9bd3c202011-05-03 14:52:54 -0500278 (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Mike Miller5e216152010-06-02 12:58:06 -0700279 } else {
280 h->interrupts_enabled = 0;
281 writel(SA5_PERF_INTR_OFF,
282 h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Stephen M. Cameron9bd3c202011-05-03 14:52:54 -0500283 (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Mike Miller5e216152010-06-02 12:58:06 -0700284 }
285}
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287/*
288 * Returns true if fifo is full.
289 *
290 */
291static unsigned long SA5_fifo_full(ctlr_info_t *h)
292{
293 if( h->commands_outstanding >= h->max_commands)
294 return(1);
295 else
296 return(0);
297
298}
299/*
300 * returns value read from hardware.
301 * returns FIFO_EMPTY if there is nothing to read
302 */
303static unsigned long SA5_completed(ctlr_info_t *h)
304{
305 unsigned long register_value
306 = readl(h->vaddr + SA5_REPLY_PORT_OFFSET);
307 if(register_value != FIFO_EMPTY)
308 {
309 h->commands_outstanding--;
310#ifdef CCISS_DEBUG
311 printk("cciss: Read %lx back from board\n", register_value);
312#endif /* CCISS_DEBUG */
313 }
314#ifdef CCISS_DEBUG
315 else
316 {
317 printk("cciss: FIFO Empty read\n");
318 }
319#endif
320 return ( register_value);
321
322}
Mike Miller5e216152010-06-02 12:58:06 -0700323
324/* Performant mode command completed */
325static unsigned long SA5_performant_completed(ctlr_info_t *h)
326{
327 unsigned long register_value = FIFO_EMPTY;
328
329 /* flush the controller write of the reply queue by reading
330 * outbound doorbell status register.
331 */
332 register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
333 /* msi auto clears the interrupt pending bit. */
Christoph Hellwigc5c9b262017-02-08 00:13:20 +0100334 if (!(h->pdev->msi_enabled || h->pdev->msix_enabled)) {
Mike Miller5e216152010-06-02 12:58:06 -0700335 writel(SA5_OUTDB_CLEAR_PERF_BIT, h->vaddr + SA5_OUTDB_CLEAR);
336 /* Do a read in order to flush the write to the controller
337 * (as per spec.)
338 */
339 register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
340 }
341
342 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
343 register_value = *(h->reply_pool_head);
344 (h->reply_pool_head)++;
345 h->commands_outstanding--;
346 } else {
347 register_value = FIFO_EMPTY;
348 }
349 /* Check for wraparound */
350 if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
351 h->reply_pool_head = h->reply_pool;
352 h->reply_pool_wraparound ^= 1;
353 }
354
355 return register_value;
356}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357/*
358 * Returns true if an interrupt is pending..
359 */
Mike Miller1d141442010-06-02 12:58:04 -0700360static bool SA5_intr_pending(ctlr_info_t *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
362 unsigned long register_value =
363 readl(h->vaddr + SA5_INTR_STATUS);
364#ifdef CCISS_DEBUG
365 printk("cciss: intr_pending %lx\n", register_value);
366#endif /* CCISS_DEBUG */
367 if( register_value & SA5_INTR_PENDING)
368 return 1;
369 return 0 ;
370}
371
372/*
373 * Returns true if an interrupt is pending..
374 */
Mike Miller1d141442010-06-02 12:58:04 -0700375static bool SA5B_intr_pending(ctlr_info_t *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
377 unsigned long register_value =
378 readl(h->vaddr + SA5_INTR_STATUS);
379#ifdef CCISS_DEBUG
380 printk("cciss: intr_pending %lx\n", register_value);
381#endif /* CCISS_DEBUG */
382 if( register_value & SA5B_INTR_PENDING)
383 return 1;
384 return 0 ;
385}
386
Mike Miller5e216152010-06-02 12:58:06 -0700387static bool SA5_performant_intr_pending(ctlr_info_t *h)
388{
389 unsigned long register_value = readl(h->vaddr + SA5_INTR_STATUS);
390
391 if (!register_value)
392 return false;
393
Christoph Hellwigc5c9b262017-02-08 00:13:20 +0100394 if (h->pdev->msi_enabled || h->pdev->msix_enabled)
Mike Miller5e216152010-06-02 12:58:06 -0700395 return true;
396
397 /* Read outbound doorbell to flush */
398 register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
399 return register_value & SA5_OUTDB_STATUS_PERF_BIT;
400}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402static struct access_method SA5_access = {
Kees Cook5f5fca62016-12-16 17:05:30 -0800403 .submit_command = SA5_submit_command,
404 .set_intr_mask = SA5_intr_mask,
405 .fifo_full = SA5_fifo_full,
406 .intr_pending = SA5_intr_pending,
407 .command_completed = SA5_completed,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408};
409
410static struct access_method SA5B_access = {
Kees Cook5f5fca62016-12-16 17:05:30 -0800411 .submit_command = SA5_submit_command,
412 .set_intr_mask = SA5B_intr_mask,
413 .fifo_full = SA5_fifo_full,
414 .intr_pending = SA5B_intr_pending,
415 .command_completed = SA5_completed,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416};
417
Mike Miller5e216152010-06-02 12:58:06 -0700418static struct access_method SA5_performant_access = {
Kees Cook5f5fca62016-12-16 17:05:30 -0800419 .submit_command = SA5_submit_command,
420 .set_intr_mask = SA5_performant_intr_mask,
421 .fifo_full = SA5_fifo_full,
422 .intr_pending = SA5_performant_intr_pending,
423 .command_completed = SA5_performant_completed,
Mike Miller5e216152010-06-02 12:58:06 -0700424};
425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426struct board_type {
427 __u32 board_id;
428 char *product_name;
429 struct access_method *access;
Mike Millerf8806322006-12-06 20:35:01 -0800430 int nr_cmds; /* Max cmds this kind of ctlr can handle. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431};
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#endif /* CCISS_H */