Blame view

drivers/block/cciss.h 11.1 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
  #ifndef CCISS_H
  #define CCISS_H
  
  #include <linux/genhd.h>
b368c9dd6   Andrew Patterson   cciss: Use one sc...
5
  #include <linux/mutex.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
7
  
  #include "cciss_cmd.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
10
11
12
  #define NWD_SHIFT	4
  #define MAX_PART	(1 << NWD_SHIFT)
  
  #define IO_OK		0
  #define IO_ERROR	1
789a424ad   scameron@beardog.cca.cpqcorp.net   cciss: separate e...
13
  #define IO_NEEDS_RETRY  3
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14

7fe063268   Andrew Patterson   cciss: add cciss ...
15
16
17
  #define VENDOR_LEN	8
  #define MODEL_LEN	16
  #define REV_LEN		4
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
19
20
21
22
23
24
  struct ctlr_info;
  typedef struct ctlr_info ctlr_info_t;
  
  struct access_method {
  	void (*submit_command)(ctlr_info_t *h, CommandList_struct *c);
  	void (*set_intr_mask)(ctlr_info_t *h, unsigned long val);
  	unsigned long (*fifo_full)(ctlr_info_t *h);
1d1414419   Mike Miller   cciss: make inter...
25
  	bool (*intr_pending)(ctlr_info_t *h);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
27
28
29
  	unsigned long (*command_completed)(ctlr_info_t *h);
  };
  typedef struct _drive_info_struct
  {
39ccf9a64   Stephen M. Cameron   cciss: Preserve a...
30
  	unsigned char LunID[8];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
  	int 	usage_count;
ad2b93123   Mike Miller   [PATCH] cciss per...
32
  	struct request_queue *queue;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33
34
35
36
37
  	sector_t nr_blocks;
  	int	block_size;
  	int 	heads;
  	int	sectors;
  	int 	cylinders;
ddd474420   Mike Miller   [PATCH] cciss: ne...
38
39
  	int	raid_level; /* set to -1 to indicate that
  			     * the drive is not in use/configured
7fe063268   Andrew Patterson   cciss: add cciss ...
40
41
42
43
44
  			     */
  	int	busy_configuring; /* This is set when a drive is being removed
  				   * to prevent it from being opened or it's
  				   * queue from being started.
  				   */
9cef0d2f4   Stephen M. Cameron   cciss: Dynamicall...
45
  	struct	device dev;
7fe063268   Andrew Patterson   cciss: add cciss ...
46
47
48
49
50
51
  	__u8 serial_no[16]; /* from inquiry page 0x83,
  			     * not necc. null terminated.
  			     */
  	char vendor[VENDOR_LEN + 1]; /* SCSI vendor string */
  	char model[MODEL_LEN + 1];   /* SCSI model string */
  	char rev[REV_LEN + 1];       /* SCSI revision string */
9cef0d2f4   Stephen M. Cameron   cciss: Dynamicall...
52
  	char device_initialized;     /* indicates whether dev is initialized */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
  } drive_info_struct;
5c07a311a   Don Brace   cciss: Add enhanc...
54
  struct ctlr_info
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
56
57
58
  {
  	int	ctlr;
  	char	devname[8];
  	char    *product_name;
b028461d6   dann frazier   cciss: remove C99...
59
  	char	firm_ver[4]; /* Firmware version */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
61
62
63
  	struct pci_dev *pdev;
  	__u32	board_id;
  	void __iomem *vaddr;
  	unsigned long paddr;
f880632f9   Mike Miller   [PATCH] cciss: in...
64
  	int 	nr_cmds; /* Number of commands allowed on this controller */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
  	CfgTable_struct __iomem *cfgtable;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
69
70
71
72
73
  	int	interrupts_enabled;
  	int	major;
  	int 	max_commands;
  	int	commands_outstanding;
  	int 	max_outstanding; /* Debug */ 
  	int	num_luns;
  	int 	highest_lun;
  	int	usage_count;  /* number of opens all all minor devices */
5c07a311a   Don Brace   cciss: Add enhanc...
74
75
76
77
78
79
80
81
  	/* Need space for temp sg list
  	 * number of scatter/gathers supported
  	 * number of scatter/gathers in chained block
  	 */
  	struct	scatterlist **scatter_list;
  	int	maxsgentries;
  	int	chainsize;
  	int	max_cmd_sgentries;
dccc9b563   Stephen M. Cameron   cciss: simplify s...
82
  	SGDescriptor_struct **cmd_sg_list;
5c07a311a   Don Brace   cciss: Add enhanc...
83

5e216153c   Mike Miller   cciss: add perfor...
84
85
  #	define PERF_MODE_INT	0
  #	define DOORBELL_INT	1
fb86a35b9   Mike Miller   [PATCH] cciss: ad...
86
87
88
89
90
  #	define SIMPLE_MODE_INT	2
  #	define MEMQ_MODE_INT	3
  	unsigned int intr[4];
  	unsigned int msix_vector;
  	unsigned int msi_vector;
130495370   Joseph Handzik   cciss: Adds simpl...
91
  	int	intr_mode;
92c4231ae   Mike Miller   [PATCH] cciss: se...
92
  	int 	cciss_max_sectors;
00988a351   Mike Miller (OS Dev)   [PATCH] cciss: su...
93
94
95
  	BYTE	cciss_read;
  	BYTE	cciss_write;
  	BYTE	cciss_read_capacity;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96

b028461d6   dann frazier   cciss: remove C99...
97
  	/* information about each logical volume */
9cef0d2f4   Stephen M. Cameron   cciss: Dynamicall...
98
  	drive_info_struct *drv[CISS_MAX_LUN];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99
100
101
102
  
  	struct access_method access;
  
  	/* queue and queue Info */ 
e6e1ee936   Jens Axboe   cciss: reinstate ...
103
104
  	struct list_head reqQ;
  	struct list_head cmpQ;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105
106
107
108
  	unsigned int Qdepth;
  	unsigned int maxQsinceinit;
  	unsigned int maxSG;
  	spinlock_t lock;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109

b028461d6   dann frazier   cciss: remove C99...
110
  	/* pointers to command and error info pool */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
113
114
115
116
117
118
  	CommandList_struct 	*cmd_pool;
  	dma_addr_t		cmd_pool_dhandle; 
  	ErrorInfo_struct 	*errinfo_pool;
  	dma_addr_t		errinfo_pool_dhandle; 
          unsigned long  		*cmd_pool_bits;
  	int			nr_allocs;
  	int			nr_frees; 
  	int			busy_configuring;
1f8ef3806   Mike Miller   [PATCH] cciss: bu...
119
  	int			busy_initializing;
b368c9dd6   Andrew Patterson   cciss: Use one sc...
120
121
  	int			busy_scanning;
  	struct mutex		busy_shutting_down;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
122
123
124
125
126
  
  	/* This element holds the zero based queue number of the last
  	 * queue to be started.  It is used for fairness.
  	*/
  	int			next_to_run;
b028461d6   dann frazier   cciss: remove C99...
127
  	/* Disk structures we need to pass back */
799202cbd   Mike Miller   [PATCH] cciss: ad...
128
  	struct gendisk   *gendisk[CISS_MAX_LUN];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
  #ifdef CONFIG_CISS_SCSI_TAPE
aad9fb6f2   Stephen M. Cameron   cciss: do not use...
130
  	struct cciss_scsi_adapter_data_t *scsi_ctlr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131
  #endif
33079b219   Mike Miller   [PATCH] cciss: di...
132
  	unsigned char alive;
b368c9dd6   Andrew Patterson   cciss: Use one sc...
133
134
  	struct list_head scan_list;
  	struct completion scan_wait;
7fe063268   Andrew Patterson   cciss: add cciss ...
135
  	struct device dev;
5e216153c   Mike Miller   cciss: add perfor...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
  	/*
  	 * Performant mode tables.
  	 */
  	u32 trans_support;
  	u32 trans_offset;
  	struct TransTable_struct *transtable;
  	unsigned long transMethod;
  
  	/*
  	 * Performant mode completion buffer
  	 */
  	u64 *reply_pool;
  	dma_addr_t reply_pool_dhandle;
  	u64 *reply_pool_head;
  	size_t reply_pool_size;
  	unsigned char reply_pool_wraparound;
  	u32 *blockFetchTable;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153
  };
5e216153c   Mike Miller   cciss: add perfor...
154
155
  /*  Defining the diffent access_methods
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
   * Memory mapped FIFO interface (SMART 53xx cards)
   */
  #define SA5_DOORBELL	0x20
  #define SA5_REQUEST_PORT_OFFSET	0x40
  #define SA5_REPLY_INTR_MASK_OFFSET	0x34
  #define SA5_REPLY_PORT_OFFSET		0x44
  #define SA5_INTR_STATUS		0x30
  #define SA5_SCRATCHPAD_OFFSET	0xB0
  
  #define SA5_CTCFG_OFFSET	0xB4
  #define SA5_CTMEM_OFFSET	0xB8
  
  #define SA5_INTR_OFF		0x08
  #define SA5B_INTR_OFF		0x04
  #define SA5_INTR_PENDING	0x08
  #define SA5B_INTR_PENDING	0x04
  #define FIFO_EMPTY		0xffffffff	
  #define CCISS_FIRMWARE_READY	0xffff0000 /* value in scratchpad register */
5e216153c   Mike Miller   cciss: add perfor...
174
175
176
177
178
179
180
181
  /* Perf. mode flags */
  #define SA5_PERF_INTR_PENDING	0x04
  #define SA5_PERF_INTR_OFF	0x05
  #define SA5_OUTDB_STATUS_PERF_BIT	0x01
  #define SA5_OUTDB_CLEAR_PERF_BIT	0x01
  #define SA5_OUTDB_CLEAR         0xA0
  #define SA5_OUTDB_CLEAR_PERF_BIT        0x01
  #define SA5_OUTDB_STATUS        0x9C
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
182
183
184
185
186
  
  #define  CISS_ERROR_BIT		0x02
  
  #define CCISS_INTR_ON 	1 
  #define CCISS_INTR_OFF	0
e99ba1362   Stephen M. Cameron   cciss: factor out...
187
188
189
190
191
192
193
194
195
196
  
  
  /* CCISS_BOARD_READY_WAIT_SECS is how long to wait for a board
   * to become ready, in seconds, before giving up on it.
   * CCISS_BOARD_READY_POLL_INTERVAL_MSECS * is how long to wait
   * between polling the board to see if it is ready, in
   * milliseconds.  CCISS_BOARD_READY_ITERATIONS is derived
   * the above.
   */
  #define CCISS_BOARD_READY_WAIT_SECS (120)
19adbb925   Stephen M. Cameron   cciss: increase t...
197
  #define CCISS_BOARD_NOT_READY_WAIT_SECS (100)
e99ba1362   Stephen M. Cameron   cciss: factor out...
198
199
200
201
  #define CCISS_BOARD_READY_POLL_INTERVAL_MSECS (100)
  #define CCISS_BOARD_READY_ITERATIONS \
  	((CCISS_BOARD_READY_WAIT_SECS * 1000) / \
  		CCISS_BOARD_READY_POLL_INTERVAL_MSECS)
afa842fa6   Stephen M. Cameron   cciss: fix board ...
202
203
204
  #define CCISS_BOARD_NOT_READY_ITERATIONS \
  	((CCISS_BOARD_NOT_READY_WAIT_SECS * 1000) / \
  		CCISS_BOARD_READY_POLL_INTERVAL_MSECS)
83123cb11   Stephen M. Cameron   cciss: factor out...
205
  #define CCISS_POST_RESET_PAUSE_MSECS (3000)
3e28601fd   Stephen M. Cameron   cciss: increase t...
206
  #define CCISS_POST_RESET_NOOP_INTERVAL_MSECS (4000)
83123cb11   Stephen M. Cameron   cciss: factor out...
207
  #define CCISS_POST_RESET_NOOP_RETRIES (12)
3e28601fd   Stephen M. Cameron   cciss: increase t...
208
  #define CCISS_POST_RESET_NOOP_TIMEOUT_MSECS (10000)
e99ba1362   Stephen M. Cameron   cciss: factor out...
209

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
210
211
212
213
214
215
  /* 
  	Send the command to the hardware 
  */
  static void SA5_submit_command( ctlr_info_t *h, CommandList_struct *c) 
  {
  #ifdef CCISS_DEBUG
5e216153c   Mike Miller   cciss: add perfor...
216
217
218
219
  	printk(KERN_WARNING "cciss%d: Sending %08x - down to controller
  ",
  			h->ctlr, c->busaddr);
  #endif /* CCISS_DEBUG */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
220
           writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
07d0c38e7   Stephen M. Cameron   cciss: do not att...
221
  	readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  	 h->commands_outstanding++;
  	 if ( h->commands_outstanding > h->max_outstanding)
  		h->max_outstanding = h->commands_outstanding;
  }
  
  /*  
   *  This card is the opposite of the other cards.  
   *   0 turns interrupts on... 
   *   0x08 turns them off... 
   */
  static void SA5_intr_mask(ctlr_info_t *h, unsigned long val)
  {
  	if (val) 
  	{ /* Turn interrupts on */
  		h->interrupts_enabled = 1;
  		writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
9bd3c2048   Stephen M. Cameron   cciss: add readl ...
238
  		(void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
239
240
241
242
243
  	} else /* Turn them off */
  	{
  		h->interrupts_enabled = 0;
          	writel( SA5_INTR_OFF, 
  			h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
9bd3c2048   Stephen M. Cameron   cciss: add readl ...
244
  		(void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
245
246
247
248
249
250
251
252
253
254
255
256
257
  	}
  }
  /*
   *  This card is the opposite of the other cards.
   *   0 turns interrupts on...
   *   0x04 turns them off...
   */
  static void SA5B_intr_mask(ctlr_info_t *h, unsigned long val)
  {
          if (val)
          { /* Turn interrupts on */
  		h->interrupts_enabled = 1;
                  writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
9bd3c2048   Stephen M. Cameron   cciss: add readl ...
258
  		(void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
259
260
261
262
263
          } else /* Turn them off */
          {
  		h->interrupts_enabled = 0;
                  writel( SA5B_INTR_OFF,
                          h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
9bd3c2048   Stephen M. Cameron   cciss: add readl ...
264
  		(void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
265
266
          }
  }
5e216153c   Mike Miller   cciss: add perfor...
267
268
269
270
271
272
273
  
  /* Performant mode intr_mask */
  static void SA5_performant_intr_mask(ctlr_info_t *h, unsigned long val)
  {
  	if (val) { /* turn on interrupts */
  		h->interrupts_enabled = 1;
  		writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
9bd3c2048   Stephen M. Cameron   cciss: add readl ...
274
  		(void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
5e216153c   Mike Miller   cciss: add perfor...
275
276
277
278
  	} else {
  		h->interrupts_enabled = 0;
  		writel(SA5_PERF_INTR_OFF,
  				h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
9bd3c2048   Stephen M. Cameron   cciss: add readl ...
279
  		(void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
5e216153c   Mike Miller   cciss: add perfor...
280
281
  	}
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
  /*
   *  Returns true if fifo is full.  
   * 
   */ 
  static unsigned long SA5_fifo_full(ctlr_info_t *h)
  {
  	if( h->commands_outstanding >= h->max_commands)
  		return(1);
  	else 
  		return(0);
  
  }
  /* 
   *   returns value read from hardware. 
   *     returns FIFO_EMPTY if there is nothing to read 
   */ 
  static unsigned long SA5_completed(ctlr_info_t *h)
  {
  	unsigned long register_value 
  		= readl(h->vaddr + SA5_REPLY_PORT_OFFSET);
  	if(register_value != FIFO_EMPTY)
  	{
  		h->commands_outstanding--;
  #ifdef CCISS_DEBUG
  		printk("cciss:  Read %lx back from board
  ", register_value);
  #endif /* CCISS_DEBUG */ 
  	} 
  #ifdef CCISS_DEBUG
  	else
  	{
  		printk("cciss:  FIFO Empty read
  ");
  	}
  #endif 
  	return ( register_value); 
  
  }
5e216153c   Mike Miller   cciss: add perfor...
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
  
  /* Performant mode command completed */
  static unsigned long SA5_performant_completed(ctlr_info_t *h)
  {
  	unsigned long register_value = FIFO_EMPTY;
  
  	/* flush the controller write of the reply queue by reading
  	 * outbound doorbell status register.
  	 */
  	register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  	/* msi auto clears the interrupt pending bit. */
  	if (!(h->msi_vector || h->msix_vector)) {
  		writel(SA5_OUTDB_CLEAR_PERF_BIT, h->vaddr + SA5_OUTDB_CLEAR);
  		/* Do a read in order to flush the write to the controller
  		 * (as per spec.)
  		 */
  		register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  	}
  
  	if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
  		register_value = *(h->reply_pool_head);
  		(h->reply_pool_head)++;
  		h->commands_outstanding--;
  	} else {
  		register_value = FIFO_EMPTY;
  	}
  	/* Check for wraparound */
  	if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
  		h->reply_pool_head = h->reply_pool;
  		h->reply_pool_wraparound ^= 1;
  	}
  
  	return register_value;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
354
355
356
  /*
   *	Returns true if an interrupt is pending.. 
   */
1d1414419   Mike Miller   cciss: make inter...
357
  static bool SA5_intr_pending(ctlr_info_t *h)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
  {
  	unsigned long register_value  = 
  		readl(h->vaddr + SA5_INTR_STATUS);
  #ifdef CCISS_DEBUG
  	printk("cciss: intr_pending %lx
  ", register_value);
  #endif  /* CCISS_DEBUG */
  	if( register_value &  SA5_INTR_PENDING) 
  		return  1;	
  	return 0 ;
  }
  
  /*
   *      Returns true if an interrupt is pending..
   */
1d1414419   Mike Miller   cciss: make inter...
373
  static bool SA5B_intr_pending(ctlr_info_t *h)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
374
375
376
377
378
379
380
381
382
383
384
  {
          unsigned long register_value  =
                  readl(h->vaddr + SA5_INTR_STATUS);
  #ifdef CCISS_DEBUG
          printk("cciss: intr_pending %lx
  ", register_value);
  #endif  /* CCISS_DEBUG */
          if( register_value &  SA5B_INTR_PENDING)
                  return  1;
          return 0 ;
  }
5e216153c   Mike Miller   cciss: add perfor...
385
386
387
388
389
390
391
392
393
394
395
396
397
398
  static bool SA5_performant_intr_pending(ctlr_info_t *h)
  {
  	unsigned long register_value = readl(h->vaddr + SA5_INTR_STATUS);
  
  	if (!register_value)
  		return false;
  
  	if (h->msi_vector || h->msix_vector)
  		return true;
  
  	/* Read outbound doorbell to flush */
  	register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
  	return register_value & SA5_OUTDB_STATUS_PERF_BIT;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
  
  static struct access_method SA5_access = {
  	SA5_submit_command,
  	SA5_intr_mask,
  	SA5_fifo_full,
  	SA5_intr_pending,
  	SA5_completed,
  };
  
  static struct access_method SA5B_access = {
          SA5_submit_command,
          SA5B_intr_mask,
          SA5_fifo_full,
          SA5B_intr_pending,
          SA5_completed,
  };
5e216153c   Mike Miller   cciss: add perfor...
415
416
417
418
419
420
421
  static struct access_method SA5_performant_access = {
  	SA5_submit_command,
  	SA5_performant_intr_mask,
  	SA5_fifo_full,
  	SA5_performant_intr_pending,
  	SA5_performant_completed,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
422
423
424
425
  struct board_type {
  	__u32	board_id;
  	char	*product_name;
  	struct access_method *access;
f880632f9   Mike Miller   [PATCH] cciss: in...
426
  	int nr_cmds; /* Max cmds this kind of ctlr can handle. */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
427
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
428
  #endif /* CCISS_H */