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