cciss: separate error processing and command retrying code in sendcmd_withirq_core()
[safe/jmp/linux-2.6] / drivers / block / cciss.h
1 #ifndef CCISS_H
2 #define CCISS_H
3
4 #include <linux/genhd.h>
5
6 #include "cciss_cmd.h"
7
8
9 #define NWD_SHIFT       4
10 #define MAX_PART        (1 << NWD_SHIFT)
11
12 #define IO_OK           0
13 #define IO_ERROR        1
14 #define IO_NEEDS_RETRY  3
15
16 #define VENDOR_LEN      8
17 #define MODEL_LEN       16
18 #define REV_LEN         4
19
20 struct ctlr_info;
21 typedef struct ctlr_info ctlr_info_t;
22
23 struct access_method {
24         void (*submit_command)(ctlr_info_t *h, CommandList_struct *c);
25         void (*set_intr_mask)(ctlr_info_t *h, unsigned long val);
26         unsigned long (*fifo_full)(ctlr_info_t *h);
27         unsigned long (*intr_pending)(ctlr_info_t *h);
28         unsigned long (*command_completed)(ctlr_info_t *h);
29 };
30 typedef struct _drive_info_struct
31 {
32         __u32   LunID;  
33         int     usage_count;
34         struct request_queue *queue;
35         sector_t nr_blocks;
36         int     block_size;
37         int     heads;
38         int     sectors;
39         int     cylinders;
40         int     raid_level; /* set to -1 to indicate that
41                              * the drive is not in use/configured
42                              */
43         int     busy_configuring; /* This is set when a drive is being removed
44                                    * to prevent it from being opened or it's
45                                    * queue from being started.
46                                    */
47         struct  device dev;
48         __u8 serial_no[16]; /* from inquiry page 0x83,
49                              * not necc. null terminated.
50                              */
51         char vendor[VENDOR_LEN + 1]; /* SCSI vendor string */
52         char model[MODEL_LEN + 1];   /* SCSI model string */
53         char rev[REV_LEN + 1];       /* SCSI revision string */
54 } drive_info_struct;
55
56 #ifdef CONFIG_CISS_SCSI_TAPE
57
58 struct sendcmd_reject_list {
59         int ncompletions;
60         unsigned long *complete; /* array of NR_CMDS tags */
61 };
62
63 #endif
64 struct ctlr_info 
65 {
66         int     ctlr;
67         char    devname[8];
68         char    *product_name;
69         char    firm_ver[4]; // Firmware version 
70         struct pci_dev *pdev;
71         __u32   board_id;
72         void __iomem *vaddr;
73         unsigned long paddr;
74         int     nr_cmds; /* Number of commands allowed on this controller */
75         CfgTable_struct __iomem *cfgtable;
76         int     interrupts_enabled;
77         int     major;
78         int     max_commands;
79         int     commands_outstanding;
80         int     max_outstanding; /* Debug */ 
81         int     num_luns;
82         int     highest_lun;
83         int     usage_count;  /* number of opens all all minor devices */
84 #       define DOORBELL_INT     0
85 #       define PERF_MODE_INT    1
86 #       define SIMPLE_MODE_INT  2
87 #       define MEMQ_MODE_INT    3
88         unsigned int intr[4];
89         unsigned int msix_vector;
90         unsigned int msi_vector;
91         int     cciss_max_sectors;
92         BYTE    cciss_read;
93         BYTE    cciss_write;
94         BYTE    cciss_read_capacity;
95
96         // information about each logical volume
97         drive_info_struct drv[CISS_MAX_LUN];
98
99         struct access_method access;
100
101         /* queue and queue Info */ 
102         struct hlist_head reqQ;
103         struct hlist_head cmpQ;
104         unsigned int Qdepth;
105         unsigned int maxQsinceinit;
106         unsigned int maxSG;
107         spinlock_t lock;
108
109         //* pointers to command and error info pool */ 
110         CommandList_struct      *cmd_pool;
111         dma_addr_t              cmd_pool_dhandle; 
112         ErrorInfo_struct        *errinfo_pool;
113         dma_addr_t              errinfo_pool_dhandle; 
114         unsigned long           *cmd_pool_bits;
115         int                     nr_allocs;
116         int                     nr_frees; 
117         int                     busy_configuring;
118         int                     busy_initializing;
119
120         /* This element holds the zero based queue number of the last
121          * queue to be started.  It is used for fairness.
122         */
123         int                     next_to_run;
124
125         // Disk structures we need to pass back
126         struct gendisk   *gendisk[CISS_MAX_LUN];
127 #ifdef CONFIG_CISS_SCSI_TAPE
128         void *scsi_ctlr; /* ptr to structure containing scsi related stuff */
129         /* list of block side commands the scsi error handling sucked up */
130         /* and saved for later processing */
131         struct sendcmd_reject_list scsi_rejects;
132 #endif
133         unsigned char alive;
134         struct completion *rescan_wait;
135         struct task_struct *cciss_scan_thread;
136         struct device dev;
137 };
138
139 /*  Defining the diffent access_menthods */
140 /*
141  * Memory mapped FIFO interface (SMART 53xx cards)
142  */
143 #define SA5_DOORBELL    0x20
144 #define SA5_REQUEST_PORT_OFFSET 0x40
145 #define SA5_REPLY_INTR_MASK_OFFSET      0x34
146 #define SA5_REPLY_PORT_OFFSET           0x44
147 #define SA5_INTR_STATUS         0x30
148 #define SA5_SCRATCHPAD_OFFSET   0xB0
149
150 #define SA5_CTCFG_OFFSET        0xB4
151 #define SA5_CTMEM_OFFSET        0xB8
152
153 #define SA5_INTR_OFF            0x08
154 #define SA5B_INTR_OFF           0x04
155 #define SA5_INTR_PENDING        0x08
156 #define SA5B_INTR_PENDING       0x04
157 #define FIFO_EMPTY              0xffffffff      
158 #define CCISS_FIRMWARE_READY    0xffff0000 /* value in scratchpad register */
159
160 #define  CISS_ERROR_BIT         0x02
161
162 #define CCISS_INTR_ON   1 
163 #define CCISS_INTR_OFF  0
164 /* 
165         Send the command to the hardware 
166 */
167 static void SA5_submit_command( ctlr_info_t *h, CommandList_struct *c) 
168 {
169 #ifdef CCISS_DEBUG
170          printk("Sending %x - down to controller\n", c->busaddr );
171 #endif /* CCISS_DEBUG */ 
172          writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
173          h->commands_outstanding++;
174          if ( h->commands_outstanding > h->max_outstanding)
175                 h->max_outstanding = h->commands_outstanding;
176 }
177
178 /*  
179  *  This card is the opposite of the other cards.  
180  *   0 turns interrupts on... 
181  *   0x08 turns them off... 
182  */
183 static void SA5_intr_mask(ctlr_info_t *h, unsigned long val)
184 {
185         if (val) 
186         { /* Turn interrupts on */
187                 h->interrupts_enabled = 1;
188                 writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
189         } else /* Turn them off */
190         {
191                 h->interrupts_enabled = 0;
192                 writel( SA5_INTR_OFF, 
193                         h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
194         }
195 }
196 /*
197  *  This card is the opposite of the other cards.
198  *   0 turns interrupts on...
199  *   0x04 turns them off...
200  */
201 static void SA5B_intr_mask(ctlr_info_t *h, unsigned long val)
202 {
203         if (val)
204         { /* Turn interrupts on */
205                 h->interrupts_enabled = 1;
206                 writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
207         } else /* Turn them off */
208         {
209                 h->interrupts_enabled = 0;
210                 writel( SA5B_INTR_OFF,
211                         h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
212         }
213 }
214 /*
215  *  Returns true if fifo is full.  
216  * 
217  */ 
218 static unsigned long SA5_fifo_full(ctlr_info_t *h)
219 {
220         if( h->commands_outstanding >= h->max_commands)
221                 return(1);
222         else 
223                 return(0);
224
225 }
226 /* 
227  *   returns value read from hardware. 
228  *     returns FIFO_EMPTY if there is nothing to read 
229  */ 
230 static unsigned long SA5_completed(ctlr_info_t *h)
231 {
232         unsigned long register_value 
233                 = readl(h->vaddr + SA5_REPLY_PORT_OFFSET);
234         if(register_value != FIFO_EMPTY)
235         {
236                 h->commands_outstanding--;
237 #ifdef CCISS_DEBUG
238                 printk("cciss:  Read %lx back from board\n", register_value);
239 #endif /* CCISS_DEBUG */ 
240         } 
241 #ifdef CCISS_DEBUG
242         else
243         {
244                 printk("cciss:  FIFO Empty read\n");
245         }
246 #endif 
247         return ( register_value); 
248
249 }
250 /*
251  *      Returns true if an interrupt is pending.. 
252  */
253 static unsigned long SA5_intr_pending(ctlr_info_t *h)
254 {
255         unsigned long register_value  = 
256                 readl(h->vaddr + SA5_INTR_STATUS);
257 #ifdef CCISS_DEBUG
258         printk("cciss: intr_pending %lx\n", register_value);
259 #endif  /* CCISS_DEBUG */
260         if( register_value &  SA5_INTR_PENDING) 
261                 return  1;      
262         return 0 ;
263 }
264
265 /*
266  *      Returns true if an interrupt is pending..
267  */
268 static unsigned long SA5B_intr_pending(ctlr_info_t *h)
269 {
270         unsigned long register_value  =
271                 readl(h->vaddr + SA5_INTR_STATUS);
272 #ifdef CCISS_DEBUG
273         printk("cciss: intr_pending %lx\n", register_value);
274 #endif  /* CCISS_DEBUG */
275         if( register_value &  SA5B_INTR_PENDING)
276                 return  1;
277         return 0 ;
278 }
279
280
281 static struct access_method SA5_access = {
282         SA5_submit_command,
283         SA5_intr_mask,
284         SA5_fifo_full,
285         SA5_intr_pending,
286         SA5_completed,
287 };
288
289 static struct access_method SA5B_access = {
290         SA5_submit_command,
291         SA5B_intr_mask,
292         SA5_fifo_full,
293         SA5B_intr_pending,
294         SA5_completed,
295 };
296
297 struct board_type {
298         __u32   board_id;
299         char    *product_name;
300         struct access_method *access;
301         int nr_cmds; /* Max cmds this kind of ctlr can handle. */
302 };
303
304 #define CCISS_LOCK(i)   (&hba[i]->lock)
305
306 #endif /* CCISS_H */
307