2 * Disk Array driver for Compaq SMART2 Controllers
3 * Copyright 1998 Compaq Computer Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * Questions/Comments/Bugfixes to arrays@compaq.com
21 * If you want to make changes, improve or add functionality to this
22 * driver, you'll probably need the Compaq Array Controller Interface
23 * Specificiation (Document number ECG086/1198)
25 #include <linux/module.h>
26 #include <linux/version.h>
27 #include <linux/types.h>
28 #include <linux/pci.h>
29 #include <linux/kernel.h>
30 #include <linux/malloc.h>
31 #include <linux/delay.h>
32 #include <linux/major.h>
34 #include <linux/blkpg.h>
35 #include <linux/timer.h>
36 #include <linux/proc_fs.h>
37 #include <linux/hdreg.h>
38 #include <asm/uaccess.h>
39 #include <asm/spinlock.h>
43 #define SMART2_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
45 #define DRIVER_NAME "Compaq SMART2 Driver (v 1.0.4)"
46 #define DRIVER_VERSION SMART2_DRIVER_VERSION(1,0,4)
47 #define MAJOR_NR COMPAQ_SMART2_MAJOR
48 #include <linux/blk.h>
49 #include <linux/blkdev.h>
50 #include <linux/genhd.h>
55 #include "ida_ioctl.h"
57 #define READ_AHEAD 128
58 #define NR_CMDS 128 /* This could probably go as high as ~400 */
63 static int nr_ctlr
= 0;
64 static ctlr_info_t
*hba
[MAX_CTLR
] = { 0, 0, 0, 0, 0, 0, 0, 0 };
66 static int eisa
[8] = { 0, 0 ,0 ,0, 0, 0 ,0 ,0 };
68 #define NR_PRODUCTS (sizeof(products)/sizeof(struct board_type))
70 /* board_id = Subsystem Device ID & Vendor ID
71 * product = Marketing Name for the board
72 * access = Address of the struct of function pointers
74 struct board_type products
[] = {
75 { 0x0040110E, "IDA", &smart1_access
},
76 { 0x0140110E, "IDA-2", &smart1_access
},
77 { 0x1040110E, "IAES", &smart1_access
},
78 { 0x2040110E, "SMART", &smart1_access
},
79 { 0x3040110E, "SMART-2/E", &smart2e_access
},
80 { 0x40300E11, "SMART-2/P", &smart2_access
},
81 { 0x40310E11, "SMART-2SL", &smart2_access
},
82 { 0x40320E11, "Smart Array 3200", &smart2_access
},
83 { 0x40330E11, "Smart Array 3100ES", &smart2_access
},
84 { 0x40340E11, "Smart Array 221", &smart2_access
},
85 { 0x40400E11, "Integrated Array", &smart4_access
},
86 { 0x40500E11, "Smart Array 4200", &smart4_access
},
87 { 0x40510E11, "Smart Array 4250ES", &smart4_access
},
90 static struct hd_struct
* ida
;
91 static int * ida_sizes
;
92 static int * ida_blocksizes
;
93 static int * ida_hardsizes
;
94 static struct gendisk ida_gendisk
[MAX_CTLR
];
96 struct proc_dir_entry
*proc_array
= NULL
;
99 #define DBG(s) do { s } while(0)
100 /* Debug (general info)... */
101 #define DBGINFO(s) do { } while(0)
102 /* Debug Paranoid... */
103 #define DBGP(s) do { } while(0)
104 /* Debug Extra Paranoid... */
105 #define DBGPX(s) do { } while(0)
107 void cpqarray_init(void);
108 static int cpqarray_pci_detect(void);
109 static int cpqarray_pci_init(ctlr_info_t
*c
, unchar bus
, unchar device_fn
);
110 static ulong
remap_pci_mem(ulong base
, ulong size
);
111 static int cpqarray_eisa_detect(void);
112 static int pollcomplete(int ctlr
);
113 static void getgeometry(int ctlr
);
114 static void start_fwbk(int ctlr
);
116 static cmdlist_t
* cmd_alloc(ctlr_info_t
*h
);
117 static void cmd_free(ctlr_info_t
*h
, cmdlist_t
*c
);
126 unsigned int log_unit
);
128 static int ida_open(struct inode
*inode
, struct file
*filep
);
129 static int ida_release(struct inode
*inode
, struct file
*filep
);
130 static int ida_ioctl(struct inode
*inode
, struct file
*filep
, unsigned int cmd
, unsigned long arg
);
131 static int ida_ctlr_ioctl(int ctlr
, int dsk
, ida_ioctl_t
*io
);
133 static void do_ida_request(int i
);
135 * This is a hack. This driver eats a major number for each controller, and
136 * sets blkdev[xxx].request_fn to each one of these so the real request
137 * function knows what controller its working with.
139 #define DO_IDA_REQUEST(x) { do_ida_request(x); }
141 static void do_ida_request0(void) DO_IDA_REQUEST(0);
142 static void do_ida_request1(void) DO_IDA_REQUEST(1);
143 static void do_ida_request2(void) DO_IDA_REQUEST(2);
144 static void do_ida_request3(void) DO_IDA_REQUEST(3);
145 static void do_ida_request4(void) DO_IDA_REQUEST(4);
146 static void do_ida_request5(void) DO_IDA_REQUEST(5);
147 static void do_ida_request6(void) DO_IDA_REQUEST(6);
148 static void do_ida_request7(void) DO_IDA_REQUEST(7);
150 static void start_io(ctlr_info_t
*h
);
152 static inline void addQ(cmdlist_t
**Qptr
, cmdlist_t
*c
);
153 static inline cmdlist_t
*removeQ(cmdlist_t
**Qptr
, cmdlist_t
*c
);
154 static inline void complete_buffers(struct buffer_head
*bh
, int ok
);
155 static inline void complete_command(cmdlist_t
*cmd
, int timeout
);
157 static void do_ida_intr(int irq
, void *dev_id
, struct pt_regs
* regs
);
158 static void ida_timer(unsigned long tdata
);
159 static int frevalidate_logvol(kdev_t dev
);
160 static int revalidate_logvol(kdev_t dev
, int maxusage
);
161 static int revalidate_allvol(kdev_t dev
);
163 static void ida_procinit(int i
);
164 static int ida_proc_get_info(char *buffer
, char **start
, off_t offset
, int length
, int *eof
, void *data
);
166 static void ida_geninit(struct gendisk
*g
)
168 int ctlr
= g
-ida_gendisk
;
172 for(i
=0; i
<NWD
; i
++) {
173 drv
= &hba
[ctlr
]->drv
[i
];
176 ida
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)].nr_sects
=
177 ida_sizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)] =
180 for(j
=0; j
<16; j
++) {
181 ida_blocksizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)+j
] =
183 ida_hardsizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)+j
] =
186 ida_gendisk
[ctlr
].nr_real
++;
191 struct file_operations ida_fops
= {
192 NULL
, /* lseek - default */
193 block_read
, /* read - general block-dev read */
194 block_write
, /* write - general block-dev write */
195 NULL
, /* readdir - bad */
197 ida_ioctl
, /* ioctl */
199 ida_open
, /* open code */
201 ida_release
, /* release */
202 block_fsync
, /* fsync */
204 NULL
, /* Disk change */
205 frevalidate_logvol
, /* revalidate */
210 * Get us a file in /proc/array that says something about each controller.
211 * Create /proc/array if it doesn't exist yet.
213 static void ida_procinit(int i
)
215 struct proc_dir_entry
*pd
;
217 if (proc_array
== NULL
) {
218 proc_array
= create_proc_entry("array", S_IFDIR
|S_IRUGO
|S_IXUGO
,
220 if (!proc_array
) return;
223 pd
= create_proc_entry(hba
[i
]->devname
, S_IFREG
|S_IRUGO
, proc_array
);
225 pd
->read_proc
= ida_proc_get_info
;
230 * Report information about this controller.
232 static int ida_proc_get_info(char *buffer
, char **start
, off_t offset
, int length
, int *eof
, void *data
)
237 ctlr_info_t
*h
= (ctlr_info_t
*)data
;
239 #ifdef CPQ_PROC_PRINT_QUEUES
244 size
= sprintf(buffer
, "%s: Compaq %s Controller\n"
246 " Firmware Revision: %c%c%c%c\n"
247 " Controller Sig: %08lx\n"
248 " Memory Address: %08lx\n"
251 " Logical drives: %d\n"
252 " Physical drives: %d\n\n"
253 " Current Q depth: %d\n"
254 " Max Q depth since init: %d\n\n",
257 (unsigned long)h
->board_id
,
258 h
->firm_rev
[0], h
->firm_rev
[1], h
->firm_rev
[2], h
->firm_rev
[3],
259 (unsigned long)h
->ctlr_sig
, (unsigned long)h
->vaddr
,
260 (unsigned int) h
->ioaddr
, (unsigned int)h
->intr
,
261 h
->log_drives
, h
->phys_drives
,
262 h
->Qdepth
, h
->maxQsinceinit
);
264 pos
+= size
; len
+= size
;
266 size
= sprintf(buffer
+len
, "Logical Drive Info:\n");
267 pos
+= size
; len
+= size
;
269 for(i
=0; i
<h
->log_drives
; i
++) {
271 size
= sprintf(buffer
+len
, "ida/c%dd%d: blksz=%d nr_blks=%d\n",
272 ctlr
, i
, drv
->blk_size
, drv
->nr_blks
);
273 pos
+= size
; len
+= size
;
276 #ifdef CPQ_PROC_PRINT_QUEUES
277 size
= sprintf(buffer
+len
, "\nCurrent Queues:\n");
278 pos
+= size
; len
+= size
;
281 size
= sprintf(buffer
+len
, "reqQ = %p", c
); pos
+= size
; len
+= size
;
283 while(c
&& c
!= h
->reqQ
) {
284 size
= sprintf(buffer
+len
, "->%p", c
);
285 pos
+= size
; len
+= size
;
290 size
= sprintf(buffer
+len
, "\ncmpQ = %p", c
); pos
+= size
; len
+= size
;
292 while(c
&& c
!= h
->cmpQ
) {
293 size
= sprintf(buffer
+len
, "->%p", c
);
294 pos
+= size
; len
+= size
;
298 size
= sprintf(buffer
+len
, "\n"); pos
+= size
; len
+= size
;
300 size
= sprintf(buffer
+len
, "nr_allocs = %d\nnr_frees = %d\n",
301 h
->nr_allocs
, h
->nr_frees
);
302 pos
+= size
; len
+= size
;
305 *start
= buffer
+offset
;
314 MODULE_PARM(eisa
, "1-8i");
317 /* This is a bit of a hack... */
318 int init_module(void)
325 for(i
=0; i
<nr_ctlr
; i
++) {
326 ida_geninit(&ida_gendisk
[i
]);
328 if (ida_sizes
[(i
<<CTLR_SHIFT
) + (j
<<NWD_SHIFT
)])
329 resetup_one_dev(&ida_gendisk
[i
], j
);
333 void cleanup_module(void)
338 for(i
=0; i
<nr_ctlr
; i
++) {
339 hba
[i
]->access
.set_intr_mask(hba
[i
], 0);
340 free_irq(hba
[i
]->intr
, hba
[i
]);
341 iounmap((void*)hba
[i
]->vaddr
);
342 unregister_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
);
343 del_timer(&hba
[i
]->timer
);
344 remove_proc_entry(hba
[i
]->devname
, proc_array
);
345 kfree(hba
[i
]->cmd_pool
);
346 kfree(hba
[i
]->cmd_pool_bits
);
348 if (gendisk_head
== &ida_gendisk
[i
]) {
349 gendisk_head
= ida_gendisk
[i
].next
;
351 for(g
=gendisk_head
; g
; g
=g
->next
) {
352 if (g
->next
== &ida_gendisk
[i
]) {
353 g
->next
= ida_gendisk
[i
].next
;
359 remove_proc_entry("array", &proc_root
);
362 kfree(ida_hardsizes
);
363 kfree(ida_blocksizes
);
370 * This is it. Find all the controllers and register them. I really hate
371 * stealing all these major device numbers.
373 void cpqarray_init(void)
375 void (*request_fns
[MAX_CTLR
])(void) = {
376 do_ida_request0
, do_ida_request1
,
377 do_ida_request2
, do_ida_request3
,
378 do_ida_request4
, do_ida_request5
,
379 do_ida_request6
, do_ida_request7
,
383 /* detect controllers */
384 cpqarray_pci_detect();
385 cpqarray_eisa_detect();
390 printk(DRIVER_NAME
"\n");
391 printk("Found %d controller(s)\n", nr_ctlr
);
393 /* allocate space for disk structs */
394 ida
= kmalloc(sizeof(struct hd_struct
)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
398 ida_sizes
= kmalloc(sizeof(int)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
401 ida_blocksizes
= kmalloc(sizeof(int)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
402 if(ida_blocksizes
==NULL
)
404 ida_hardsizes
= kmalloc(sizeof(int)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
405 if(ida_hardsizes
==NULL
)
408 memset(ida
, 0, sizeof(struct hd_struct
)*nr_ctlr
*NWD
*16);
409 memset(ida_sizes
, 0, sizeof(int)*nr_ctlr
*NWD
*16);
410 memset(ida_blocksizes
, 0, sizeof(int)*nr_ctlr
*NWD
*16);
411 memset(ida_hardsizes
, 0, sizeof(int)*nr_ctlr
*NWD
*16);
412 memset(ida_gendisk
, 0, sizeof(struct gendisk
)*MAX_CTLR
);
415 * register block devices
416 * Find disks and fill in structs
417 * Get an interrupt, set the Q depth and get into /proc
419 for(i
=0; i
< nr_ctlr
; i
++) {
420 hba
[i
]->access
.set_intr_mask(hba
[i
], 0);
421 if (request_irq(hba
[i
]->intr
, do_ida_intr
,
422 SA_INTERRUPT
|SA_SHIRQ
, hba
[i
]->devname
, hba
[i
])) {
424 printk("Unable to get irq %d for %s\n",
425 hba
[i
]->intr
, hba
[i
]->devname
);
428 if (register_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
, &ida_fops
)) {
429 printk("Unable to get major number %d for ida\n",
434 hba
[i
]->cmd_pool
= (cmdlist_t
*)kmalloc(
435 NR_CMDS
* sizeof(cmdlist_t
), GFP_KERNEL
);
436 hba
[i
]->cmd_pool_bits
= (__u32
*)kmalloc(
437 ((NR_CMDS
+31)/32)*sizeof(__u32
), GFP_KERNEL
);
439 if(hba
[i
]->cmd_pool_bits
== NULL
|| hba
[i
]->cmd_pool
== NULL
)
442 if(hba
[i
]->cmd_pool_bits
)
443 kfree(hba
[i
]->cmd_pool_bits
);
445 kfree(hba
[i
]->cmd_pool
);
448 free_irq(hba
[j
]->intr
, hba
[j
]);
449 unregister_blkdev(MAJOR_NR
+j
, hba
[j
]->devname
);
450 kfree(hba
[j
]->cmd_pool_bits
);
451 kfree(hba
[j
]->cmd_pool
);
453 free_irq(hba
[i
]->intr
, hba
[i
]);
454 unregister_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
);
457 memset(hba
[i
]->cmd_pool
, 0, NR_CMDS
* sizeof(cmdlist_t
));
458 memset(hba
[i
]->cmd_pool_bits
, 0, ((NR_CMDS
+31)/32)*sizeof(__u32
));
459 printk("Finding drives on %s", hba
[i
]->devname
);
463 hba
[i
]->access
.set_intr_mask(hba
[i
], FIFO_NOT_EMPTY
);
466 ida_gendisk
[i
].major
= MAJOR_NR
+ i
;
467 ida_gendisk
[i
].major_name
= "ida";
468 ida_gendisk
[i
].minor_shift
= NWD_SHIFT
;
469 ida_gendisk
[i
].max_p
= 16;
470 ida_gendisk
[i
].max_nr
= 16;
471 ida_gendisk
[i
].init
= ida_geninit
;
472 ida_gendisk
[i
].part
= ida
+ (i
*256);
473 ida_gendisk
[i
].sizes
= ida_sizes
+ (i
*256);
474 /* ida_gendisk[i].nr_real is handled by getgeometry */
476 blk_dev
[MAJOR_NR
+i
].request_fn
= request_fns
[i
];
477 blksize_size
[MAJOR_NR
+i
] = ida_blocksizes
+ (i
*256);
478 hardsect_size
[MAJOR_NR
+i
] = ida_hardsizes
+ (i
*256);
479 read_ahead
[MAJOR_NR
+i
] = READ_AHEAD
;
481 /* Get on the disk list */
482 ida_gendisk
[i
].next
= gendisk_head
;
483 gendisk_head
= &ida_gendisk
[i
];
485 init_timer(&hba
[i
]->timer
);
486 hba
[i
]->timer
.expires
= jiffies
+ IDA_TIMER
;
487 hba
[i
]->timer
.data
= (unsigned long)hba
[i
];
488 hba
[i
]->timer
.function
= ida_timer
;
489 add_timer(&hba
[i
]->timer
);
495 kfree(ida_hardsizes
);
497 kfree(ida_blocksizes
);
503 printk(KERN_ERR
"cpqarray: out of memory.\n");
507 * Find the controller and initialize it
508 * Cannot use the class code to search, because older array controllers use
509 * 0x018000 and new ones use 0x010400. So I might as well search for each
510 * each device IDs, being there are only going to be three of them.
512 static int cpqarray_pci_detect(void)
515 unchar bus
=0, dev_fn
=0;
517 /* This seems dumb, surely we could use an array of types to match ?? */
519 for(index
=0; ; index
++) {
520 if (pcibios_find_device(PCI_VENDOR_ID_DEC
,
521 PCI_DEVICE_ID_COMPAQ_42XX
, index
, &bus
, &dev_fn
))
523 printk(KERN_DEBUG
"42XX Device has been found at %x %x\n",
525 if (index
== 1000000) break;
527 printk("This driver supports a maximum of "
532 hba
[nr_ctlr
] = kmalloc(sizeof(ctlr_info_t
), GFP_KERNEL
);
533 if(hba
[nr_ctlr
]==NULL
)
535 printk(KERN_ERR
"cpqarray: out of memory.\n");
538 memset(hba
[nr_ctlr
], 0, sizeof(ctlr_info_t
));
539 if (cpqarray_pci_init(hba
[nr_ctlr
], bus
, dev_fn
) != 0)
541 sprintf(hba
[nr_ctlr
]->devname
, "ida%d", nr_ctlr
);
542 hba
[nr_ctlr
]->ctlr
= nr_ctlr
;
546 for(index
=0; ; index
++) {
547 unsigned short subvendor
=0;
549 if (pcibios_find_device(PCI_VENDOR_ID_NCR
,
550 PCI_DEVICE_ID_NCR_53C1510
, index
, &bus
, &dev_fn
))
552 printk(KERN_DEBUG
"Integrated RAID Chip has been found at %x %x\n",
554 if(pcibios_read_config_word(bus
, dev_fn
,
555 PCI_SUBSYSTEM_VENDOR_ID
, &subvendor
))
557 printk(KERN_DEBUG
"cpqarray failed to read subvendor\n");
560 if(subvendor
!= PCI_VENDOR_ID_COMPAQ
)
562 printk(KERN_DEBUG
"Its a compaq RAID Chip\n");
563 if (index
== 1000000) break;
565 printk("This driver supports a maximum of "
570 hba
[nr_ctlr
] = kmalloc(sizeof(ctlr_info_t
), GFP_KERNEL
);
571 if(hba
[nr_ctlr
]==NULL
)
573 printk(KERN_ERR
"cpqarray: out of memory.\n");
576 memset(hba
[nr_ctlr
], 0, sizeof(ctlr_info_t
));
577 /* DOESNT THIS LEAK MEMORY ?????? - AC */
578 if (cpqarray_pci_init(hba
[nr_ctlr
], bus
, dev_fn
) != 0)
580 sprintf(hba
[nr_ctlr
]->devname
, "ida%d", nr_ctlr
);
581 hba
[nr_ctlr
]->ctlr
= nr_ctlr
;
585 for(index
=0; ; index
++) {
586 if (pcibios_find_device(PCI_VENDOR_ID_COMPAQ
,
587 PCI_DEVICE_ID_COMPAQ_SMART2P
, index
, &bus
, &dev_fn
))
590 if (index
== 1000000) break;
592 printk("This driver supports a maximum of "
597 hba
[nr_ctlr
] = kmalloc(sizeof(ctlr_info_t
), GFP_KERNEL
);
598 if(hba
[nr_ctlr
]==NULL
)
600 printk(KERN_ERR
"cpqarray: out of memory.\n");
603 memset(hba
[nr_ctlr
], 0, sizeof(ctlr_info_t
));
604 if (cpqarray_pci_init(hba
[nr_ctlr
], bus
, dev_fn
) != 0)
606 sprintf(hba
[nr_ctlr
]->devname
, "ida%d", nr_ctlr
);
607 hba
[nr_ctlr
]->ctlr
= nr_ctlr
;
614 * Find the IO address of the controller, its IRQ and so forth. Fill
615 * in some basic stuff into the ctlr_info_t structure.
617 static int cpqarray_pci_init(ctlr_info_t
*c
, unchar bus
, unchar device_fn
)
619 ushort vendor_id
, device_id
, command
;
620 unchar cache_line_size
, latency_timer
;
621 unchar irq
, revision
;
624 struct pci_dev
*pdev
;
628 pdev
= pci_find_slot(bus
, device_fn
);
629 vendor_id
= pdev
->vendor
;
630 device_id
= pdev
->device
;
634 addr
[i
] = pdev
->resource
[i
].flags
;
636 (void) pcibios_read_config_word(bus
, device_fn
,
637 PCI_COMMAND
,&command
);
638 (void) pcibios_read_config_byte(bus
, device_fn
,
639 PCI_CLASS_REVISION
,&revision
);
640 (void) pcibios_read_config_byte(bus
, device_fn
,
641 PCI_CACHE_LINE_SIZE
, &cache_line_size
);
642 (void) pcibios_read_config_byte(bus
, device_fn
,
643 PCI_LATENCY_TIMER
, &latency_timer
);
645 (void) pcibios_read_config_dword(bus
, device_fn
, 0x2c, &board_id
);
648 printk("vendor_id = %x\n", vendor_id
);
649 printk("device_id = %x\n", device_id
);
650 printk("command = %x\n", command
);
652 printk("addr[%d] = %x\n", i
, addr
[i
]);
653 printk("revision = %x\n", revision
);
654 printk("irq = %x\n", irq
);
655 printk("cache_line_size = %x\n", cache_line_size
);
656 printk("latency_timer = %x\n", latency_timer
);
657 printk("board_id = %x\n", board_id
);
661 c
->ioaddr
= addr
[0] & ~0x1;
664 * Memory base addr is first addr with the first bit _not_ set
667 if (!(addr
[i
] & 0x1)) {
668 c
->paddr
= pdev
->resource
[i
].start
;
671 c
->vaddr
= remap_pci_mem(c
->paddr
, 128);
672 c
->board_id
= board_id
;
674 for(i
=0; i
<NR_PRODUCTS
; i
++) {
675 if (board_id
== products
[i
].board_id
) {
676 c
->product_name
= products
[i
].product_name
;
677 c
->access
= *(products
[i
].access
);
681 if (i
== NR_PRODUCTS
) {
682 printk("Sorry, I don't know how to access the SMART Array"
683 " controller %08lx\n", (unsigned long)board_id
);
691 * Map (physical) PCI mem into (virtual) kernel space
693 static ulong
remap_pci_mem(ulong base
, ulong size
)
695 ulong page_base
= ((ulong
) base
) & PAGE_MASK
;
696 ulong page_offs
= ((ulong
) base
) - page_base
;
697 ulong page_remapped
= (ulong
) ioremap(page_base
, page_offs
+size
);
699 return (ulong
) (page_remapped
? (page_remapped
+ page_offs
) : 0UL);
703 * Copy the contents of the ints[] array passed to us by init.
705 void cpqarray_setup(char *str
, int *ints
)
708 for(i
=0; i
<ints
[0] && i
<8; i
++)
713 * Find an EISA controller's signature. Set up an hba if we find it.
715 static int cpqarray_eisa_detect(void)
721 while(i
<8 && eisa
[i
]) {
723 printk("This driver supports a maximum of "
727 board_id
= inl(eisa
[i
]+0xC80);
728 for(j
=0; j
< NR_PRODUCTS
; j
++)
729 if (board_id
== products
[j
].board_id
)
732 if (j
== NR_PRODUCTS
) {
733 printk("Sorry, I don't know how to access the SMART"
734 " Array controller %08lx\n", (unsigned long)board_id
);
737 hba
[nr_ctlr
] = kmalloc(sizeof(ctlr_info_t
), GFP_KERNEL
);
738 if(hba
[nr_ctlr
]==NULL
)
740 printk(KERN_ERR
"cpqarray: out of memory.\n");
743 memset(hba
[nr_ctlr
], 0, sizeof(ctlr_info_t
));
744 hba
[nr_ctlr
]->ioaddr
= eisa
[i
];
747 * Read the config register to find our interrupt
749 intr
= inb(eisa
[i
]+0xCC0) >> 4;
750 if (intr
& 1) intr
= 11;
751 else if (intr
& 2) intr
= 10;
752 else if (intr
& 4) intr
= 14;
753 else if (intr
& 8) intr
= 15;
755 hba
[nr_ctlr
]->intr
= intr
;
756 sprintf(hba
[nr_ctlr
]->devname
, "ida%d", nr_ctlr
);
757 hba
[nr_ctlr
]->product_name
= products
[j
].product_name
;
758 hba
[nr_ctlr
]->access
= *(products
[j
].access
);
759 hba
[nr_ctlr
]->ctlr
= nr_ctlr
;
760 hba
[nr_ctlr
]->board_id
= board_id
;
763 printk("i = %d, j = %d\n", i
, j
);
764 printk("irq = %x\n", intr
);
765 printk("product name = %s\n", products
[j
].product_name
);
766 printk("board_id = %x\n", board_id
);
778 * Open. Make sure the device is really there.
780 static int ida_open(struct inode
*inode
, struct file
*filep
)
782 int ctlr
= MAJOR(inode
->i_rdev
) - MAJOR_NR
;
783 int dsk
= MINOR(inode
->i_rdev
) >> NWD_SHIFT
;
785 DBGINFO(printk("ida_open %x (%x:%x)\n", inode
->i_rdev
, ctlr
, dsk
) );
786 if (ctlr
> MAX_CTLR
|| hba
[ctlr
] == NULL
)
789 if (!suser() && ida_sizes
[(ctlr
<< CTLR_SHIFT
) +
790 MINOR(inode
->i_rdev
)] == 0)
794 * Root is allowed to open raw volume zero even if its not configured
795 * so array config can still work. I don't think I really like this,
796 * but I'm already using way to many device nodes to claim another one
797 * for "raw controller".
800 && ida_sizes
[(ctlr
<< CTLR_SHIFT
) + MINOR(inode
->i_rdev
)] == 0
801 && MINOR(inode
->i_rdev
) != 0)
804 hba
[ctlr
]->drv
[dsk
].usage_count
++;
805 hba
[ctlr
]->usage_count
++;
813 static int ida_release(struct inode
*inode
, struct file
*filep
)
815 int ctlr
= MAJOR(inode
->i_rdev
) - MAJOR_NR
;
816 int dsk
= MINOR(inode
->i_rdev
) >> NWD_SHIFT
;
818 DBGINFO(printk("ida_release %x (%x:%x)\n", inode
->i_rdev
, ctlr
, dsk
) );
819 fsync_dev(inode
->i_rdev
);
821 hba
[ctlr
]->drv
[dsk
].usage_count
--;
822 hba
[ctlr
]->usage_count
--;
828 * Enqueuing and dequeuing functions for cmdlists.
830 static inline void addQ(cmdlist_t
**Qptr
, cmdlist_t
*c
)
834 c
->next
= c
->prev
= c
;
836 c
->prev
= (*Qptr
)->prev
;
838 (*Qptr
)->prev
->next
= c
;
843 static inline cmdlist_t
*removeQ(cmdlist_t
**Qptr
, cmdlist_t
*c
)
845 if (c
&& c
->next
!= c
) {
846 if (*Qptr
== c
) *Qptr
= c
->next
;
847 c
->prev
->next
= c
->next
;
848 c
->next
->prev
= c
->prev
;
856 * Get a request and submit it to the controller.
857 * This routine needs to grab all the requests it possibly can from the
858 * req Q and submit them. Interrupts are off (and need to be off) when you
859 * are in here (either via the dummy do_ida_request functions or by being
860 * called from the interrupt handler
862 static void do_ida_request(int ctlr
)
864 ctlr_info_t
*h
= hba
[ctlr
];
868 struct buffer_head
*bh
;
869 struct request
*creq
;
871 creq
= blk_dev
[MAJOR_NR
+ctlr
].current_request
;
872 if (creq
== NULL
|| creq
->rq_status
== RQ_INACTIVE
)
875 if (ctlr
!= MAJOR(creq
->rq_dev
)-MAJOR_NR
||
876 ctlr
> nr_ctlr
|| h
== NULL
) {
877 printk("doreq cmd for %d, %x at %p\n",
878 ctlr
, creq
->rq_dev
, creq
);
879 complete_buffers(creq
->bh
, 0);
883 if ((c
= cmd_alloc(h
)) == NULL
)
889 c
->hdr
.unit
= MINOR(creq
->rq_dev
) >> NWD_SHIFT
;
890 c
->hdr
.size
= sizeof(rblk_t
) >> 2;
891 c
->size
+= sizeof(rblk_t
);
893 c
->req
.hdr
.blk
= ida
[(ctlr
<<CTLR_SHIFT
) + MINOR(creq
->rq_dev
)].start_sect
+ creq
->sector
;
897 panic("bh == NULL?");
899 printk("sector=%d, nr_sectors=%d\n", creq
->sector
, creq
->nr_sectors
);
901 seg
= 0; lastdataend
= NULL
;
904 sect
+= bh
->b_size
/512;
906 if (bh
->b_size
% 512) {
907 printk("Oh damn. %d+%d, size = %d\n", creq
->sector
, sect
, bh
->b_size
);
908 panic("b_size %% 512 != 0");
911 if (bh
->b_data
== lastdataend
) {
912 c
->req
.sg
[seg
-1].size
+= bh
->b_size
;
913 lastdataend
+= bh
->b_size
;
915 c
->req
.sg
[seg
].size
= bh
->b_size
;
916 c
->req
.sg
[seg
].addr
= (__u32
)virt_to_bus(bh
->b_data
);
917 lastdataend
= bh
->b_data
+ bh
->b_size
;
923 DBGPX( printk("Submitting %d sectors in %d segments\n", sect
, seg
); );
924 c
->req
.hdr
.sg_cnt
= seg
;
925 c
->req
.hdr
.blk_cnt
= sect
;
927 creq
->sector
+= sect
;
928 creq
->nr_sectors
-= sect
;
930 /* Ready the next request:
931 * Fix up creq if we still have more buffers in the buffer chain, or
932 * mark this request as done and ready the next one.
934 if (creq
->nr_sectors
) {
937 printk("sector=%d, nr_sectors=%d, sect=%d, seg=%d\n",
938 creq
->sector
, creq
->nr_sectors
, sect
, seg
);
942 creq
->bh
= bh
->b_reqnext
;
943 bh
->b_reqnext
= NULL
;
944 DBGPX( printk("More to do on same request %p\n", creq
); );
946 DBGPX( printk("Done with %p, queueing %p\n", creq
, creq
->next
); );
947 creq
->rq_status
= RQ_INACTIVE
;
948 blk_dev
[MAJOR_NR
+ctlr
].current_request
= creq
->next
;
949 wake_up(&wait_for_request
);
952 c
->req
.hdr
.cmd
= (creq
->cmd
== READ
) ? IDA_READ
: IDA_WRITE
;
955 /* Put the request on the tail of the request queue */
958 if (h
->Qdepth
> h
->maxQsinceinit
) h
->maxQsinceinit
= h
->Qdepth
;
965 * start_io submits everything on a controller's request queue
966 * and moves it to the completion queue.
968 * Interrupts had better be off if you're in here
970 static void start_io(ctlr_info_t
*h
)
974 while((c
= h
->reqQ
) != NULL
) {
975 /* Can't do anything if we're busy */
976 if (h
->access
.fifo_full(h
) == 0)
979 /* Get the first entry from the request Q */
980 removeQ(&h
->reqQ
, c
);
983 /* Tell the controller to do our bidding */
984 h
->access
.submit_command(h
, c
);
986 /* Get onto the completion Q */
991 static inline void complete_buffers(struct buffer_head
*bh
, int ok
)
993 struct buffer_head
*xbh
;
996 bh
->b_reqnext
= NULL
;
998 bh
->b_end_io(bh
, ok
);
1004 * Mark all buffers that cmd was responsible for
1006 static inline void complete_command(cmdlist_t
*cmd
, int timeout
)
1011 if (cmd
->req
.hdr
.rcode
& RCODE_NONFATAL
&&
1012 (hba
[cmd
->ctlr
]->misc_tflags
& MISC_NONFATAL_WARN
) == 0) {
1013 sprintf(buf
, "Non Fatal error on ida/c%dd%d\n",
1014 cmd
->ctlr
, cmd
->hdr
.unit
);
1016 hba
[cmd
->ctlr
]->misc_tflags
|= MISC_NONFATAL_WARN
;
1018 if (cmd
->req
.hdr
.rcode
& RCODE_FATAL
) {
1019 sprintf(buf
, "Fatal error on ida/c%dd%d\n",
1020 cmd
->ctlr
, cmd
->hdr
.unit
);
1024 if (cmd
->req
.hdr
.rcode
& RCODE_INVREQ
) {
1025 sprintf(buf
, "Invalid request on ida/c%dd%d = (cmd=%x sect=%d cnt=%d sg=%d ret=%x)\n",
1026 cmd
->ctlr
, cmd
->hdr
.unit
, cmd
->req
.hdr
.cmd
,
1027 cmd
->req
.hdr
.blk
, cmd
->req
.hdr
.blk_cnt
,
1028 cmd
->req
.hdr
.sg_cnt
, cmd
->req
.hdr
.rcode
);
1032 if (timeout
) ok
= 0;
1033 complete_buffers(cmd
->bh
, ok
);
1037 * The controller will interrupt us upon completion of commands.
1038 * Find the command on the completion queue, remove it, tell the OS and
1039 * try to queue up more IO
1041 static void do_ida_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
1043 ctlr_info_t
*h
= dev_id
;
1045 unsigned long istat
;
1046 unsigned long flags
;
1050 istat
= h
->access
.intr_pending(h
);
1051 /* Is this interrupt for us? */
1056 * If there are completed commands in the completion queue,
1057 * we had better do something about it.
1059 spin_lock_irqsave(&io_request_lock
, flags
);
1060 if (istat
& FIFO_NOT_EMPTY
) {
1061 while((a
= h
->access
.command_completed(h
))) {
1063 if ((c
= h
->cmpQ
) == NULL
) goto bad_completion
;
1064 while(c
->busaddr
!= a
) {
1066 if (c
== h
->cmpQ
) break;
1069 * If we've found the command, take it off the
1070 * completion Q and free it
1072 if (c
->busaddr
== a
) {
1073 removeQ(&h
->cmpQ
, c
);
1074 if (c
->type
== CMD_RWREQ
) {
1075 complete_command(c
, 0);
1077 } else if (c
->type
== CMD_IOCTL_PEND
) {
1078 c
->type
= CMD_IOCTL_DONE
;
1083 printk("Completion of %08lx ignored\n", (unsigned long)a1
);
1088 * See if we can queue up some more IO
1090 do_ida_request(h
->ctlr
);
1091 spin_unlock_irqrestore(&io_request_lock
, flags
);
1095 * This timer was for timing out requests that haven't happened after
1096 * IDA_TIMEOUT. That wasn't such a good idea. This timer is used to
1097 * reset a flags structure so we don't flood the user with
1098 * "Non-Fatal error" messages.
1100 static void ida_timer(unsigned long tdata
)
1102 ctlr_info_t
*h
= (ctlr_info_t
*)tdata
;
1104 h
->timer
.expires
= jiffies
+ IDA_TIMER
;
1105 add_timer(&h
->timer
);
1110 * ida_ioctl does some miscellaneous stuff like reporting drive geometry,
1111 * setting readahead and submitting commands from userspace to the controller.
1113 static int ida_ioctl(struct inode
*inode
, struct file
*filep
, unsigned int cmd
, unsigned long arg
)
1115 int ctlr
= MAJOR(inode
->i_rdev
) - MAJOR_NR
;
1116 int dsk
= MINOR(inode
->i_rdev
) >> NWD_SHIFT
;
1119 struct hd_geometry
*geo
= (struct hd_geometry
*)arg
;
1120 ida_ioctl_t
*io
= (ida_ioctl_t
*)arg
;
1125 if (hba
[ctlr
]->drv
[dsk
].cylinders
) {
1126 diskinfo
[0] = hba
[ctlr
]->drv
[dsk
].heads
;
1127 diskinfo
[1] = hba
[ctlr
]->drv
[dsk
].sectors
;
1128 diskinfo
[2] = hba
[ctlr
]->drv
[dsk
].cylinders
;
1132 diskinfo
[2] = hba
[ctlr
]->drv
[dsk
].nr_blks
/ (0xff*0x3f);
1134 put_user(diskinfo
[0], &geo
->heads
);
1135 put_user(diskinfo
[1], &geo
->sectors
);
1136 put_user(diskinfo
[2], &geo
->cylinders
);
1137 put_user(ida
[(ctlr
<<CTLR_SHIFT
)+MINOR(inode
->i_rdev
)].start_sect
, &geo
->start
);
1140 return copy_to_user(&io
->c
.drv
,&hba
[ctlr
]->drv
[dsk
],sizeof(drv_info_t
));
1142 if (!arg
) return -EINVAL
;
1143 put_user(ida
[(ctlr
<<CTLR_SHIFT
)+MINOR(inode
->i_rdev
)].nr_sects
, (long*)arg
);
1146 return revalidate_logvol(inode
->i_rdev
, 1);
1148 if (!suser()) return -EPERM
;
1149 error
= copy_from_user(&my_io
, io
, sizeof(my_io
));
1150 if (error
) return error
;
1151 error
= ida_ctlr_ioctl(ctlr
, dsk
, &my_io
);
1152 if (error
) return error
;
1153 error
= copy_to_user(io
, &my_io
, sizeof(my_io
));
1156 if (!arg
) return -EINVAL
;
1157 put_user(hba
[ctlr
]->ctlr_sig
, (int*)arg
);
1159 case IDAREVALIDATEVOLS
:
1160 return revalidate_allvol(inode
->i_rdev
);
1161 case IDADRIVERVERSION
:
1162 if (!arg
) return -EINVAL
;
1163 put_user(DRIVER_VERSION
, (unsigned long*)arg
);
1172 return blk_ioctl(inode
->i_rdev
, cmd
, arg
);
1180 * ida_ctlr_ioctl is for passing commands to the controller from userspace.
1181 * The command block (io) has already been copied to kernel space for us,
1182 * however, any elements in the sglist need to be copied to kernel space
1183 * or copied back to userspace.
1185 * Only root may perform a controller passthru command, however I'm not doing
1186 * any serious sanity checking on the arguments. Doing an IDA_WRITE_MEDIA and
1187 * putting a 64M buffer in the sglist is probably a *bad* idea.
1189 static int ida_ctlr_ioctl(int ctlr
, int dsk
, ida_ioctl_t
*io
)
1191 ctlr_info_t
*h
= hba
[ctlr
];
1194 unsigned long flags
;
1197 if ((c
= cmd_alloc(NULL
)) == NULL
)
1200 c
->hdr
.unit
= (io
->unit
& UNITVALID
) ? (io
->unit
& ~UNITVALID
) : dsk
;
1201 c
->hdr
.size
= sizeof(rblk_t
) >> 2;
1202 c
->size
+= sizeof(rblk_t
);
1204 c
->req
.hdr
.cmd
= io
->cmd
;
1205 c
->req
.hdr
.blk
= io
->blk
;
1206 c
->req
.hdr
.blk_cnt
= io
->blk_cnt
;
1207 c
->type
= CMD_IOCTL_PEND
;
1209 /* Pre submit processing */
1212 p
= kmalloc(io
->sg
[0].size
, GFP_KERNEL
);
1213 if (!p
) { error
= -ENOMEM
; goto ioctl_err_exit
; }
1214 copy_from_user(p
, (void*)io
->sg
[0].addr
, io
->sg
[0].size
);
1215 c
->req
.bp
= virt_to_bus(&(io
->c
));
1216 c
->req
.sg
[0].size
= io
->sg
[0].size
;
1217 c
->req
.sg
[0].addr
= virt_to_bus(p
);
1218 c
->req
.hdr
.sg_cnt
= 1;
1221 p
= kmalloc(io
->sg
[0].size
, GFP_KERNEL
);
1222 if (!p
) { error
= -ENOMEM
; goto ioctl_err_exit
; }
1223 c
->req
.sg
[0].size
= io
->sg
[0].size
;
1224 c
->req
.sg
[0].addr
= virt_to_bus(p
);
1225 c
->req
.hdr
.sg_cnt
= 1;
1228 case IDA_WRITE_MEDIA
:
1229 case DIAG_PASS_THRU
:
1230 p
= kmalloc(io
->sg
[0].size
, GFP_KERNEL
);
1231 if (!p
) { error
= -ENOMEM
; goto ioctl_err_exit
; }
1232 copy_from_user(p
, (void*)io
->sg
[0].addr
, io
->sg
[0].size
);
1233 c
->req
.sg
[0].size
= io
->sg
[0].size
;
1234 c
->req
.sg
[0].addr
= virt_to_bus(p
);
1235 c
->req
.hdr
.sg_cnt
= 1;
1238 c
->req
.sg
[0].size
= sizeof(io
->c
);
1239 c
->req
.sg
[0].addr
= virt_to_bus(&io
->c
);
1240 c
->req
.hdr
.sg_cnt
= 1;
1243 /* Put the request on the tail of the request queue */
1244 spin_lock_irqsave(&io_request_lock
, flags
);
1248 spin_unlock_irqrestore(&io_request_lock
, flags
);
1250 /* Wait for completion */
1251 while(c
->type
!= CMD_IOCTL_DONE
)
1254 /* Post submit processing */
1258 case DIAG_PASS_THRU
:
1259 copy_to_user((void*)io
->sg
[0].addr
, p
, io
->sg
[0].size
);
1260 /* fall through and free p */
1262 case IDA_WRITE_MEDIA
:
1269 io
->rcode
= c
->req
.hdr
.rcode
;
1277 * Commands are pre-allocated in a large block. Here we use a simple bitmap
1278 * scheme to suballocte them to the driver. Operations that are not time
1279 * critical (and can wait for kmalloc and possibly sleep) can pass in NULL
1280 * as the first argument to get a new command.
1282 static cmdlist_t
* cmd_alloc(ctlr_info_t
*h
)
1288 c
= (cmdlist_t
*)kmalloc(sizeof(cmdlist_t
), GFP_KERNEL
);
1293 i
= find_first_zero_bit(h
->cmd_pool_bits
, NR_CMDS
);
1296 } while(test_and_set_bit(i
%32, h
->cmd_pool_bits
+(i
/32)) != 0);
1297 c
= h
->cmd_pool
+ i
;
1301 memset(c
, 0, sizeof(cmdlist_t
));
1302 c
->busaddr
= virt_to_bus(c
);
1306 static void cmd_free(ctlr_info_t
*h
, cmdlist_t
*c
)
1313 i
= c
- h
->cmd_pool
;
1314 clear_bit(i
%32, h
->cmd_pool_bits
+(i
/32));
1319 /***********************************************************************
1321 Send a command to an IDA using the memory mapped FIFO interface
1322 and wait for it to complete.
1323 This routine should only be called at init time.
1324 ***********************************************************************/
1331 unsigned int blkcnt
,
1332 unsigned int log_unit
)
1338 ctlr_info_t
*info_p
= hba
[ctlr
];
1340 c
= cmd_alloc(info_p
);
1342 c
->hdr
.unit
= log_unit
;
1344 c
->hdr
.size
= sizeof(rblk_t
) >> 2;
1345 c
->size
+= sizeof(rblk_t
);
1347 /* The request information. */
1348 c
->req
.hdr
.next
= 0;
1349 c
->req
.hdr
.rcode
= 0;
1351 c
->req
.hdr
.sg_cnt
= 1;
1352 c
->req
.hdr
.reserved
= 0;
1355 c
->req
.sg
[0].size
= 512;
1357 c
->req
.sg
[0].size
= size
;
1359 c
->req
.hdr
.blk
= blk
;
1360 c
->req
.hdr
.blk_cnt
= blkcnt
;
1361 c
->req
.hdr
.cmd
= (unsigned char) cmd
;
1362 c
->req
.sg
[0].addr
= (__u32
) virt_to_bus(buff
);
1366 info_p
->access
.set_intr_mask(info_p
, 0);
1367 /* Make sure there is room in the command FIFO */
1368 /* Actually it should be completely empty at this time. */
1369 for (i
= 200000; i
> 0; i
--) {
1370 temp
= info_p
->access
.fifo_full(info_p
);
1376 printk("ida%d: idaSendPciCmd FIFO full, waiting!\n",
1383 info_p
->access
.submit_command(info_p
, c
);
1384 complete
= pollcomplete(ctlr
);
1385 if (complete
!= 1) {
1386 if (complete
!= c
->busaddr
) {
1388 "ida%d: idaSendPciCmd "
1389 "Invalid command list address returned! (%08lx)\n",
1390 ctlr
, (unsigned long)complete
);
1391 cmd_free(info_p
, c
);
1396 "ida%d: idaSendPciCmd Timeout out, "
1397 "No command list address returned!\n",
1399 cmd_free(info_p
, c
);
1403 if (c
->req
.hdr
.rcode
& 0x00FE) {
1404 if (!(c
->req
.hdr
.rcode
& BIG_PROBLEM
)) {
1406 "ida%d: idaSendPciCmd, error: Controller failed "
1408 "cmd: 0x%x, return code = 0x%x\n",
1409 ctlr
, c
->req
.hdr
.cmd
, c
->req
.hdr
.rcode
);
1411 cmd_free(info_p
, c
);
1415 cmd_free(info_p
, c
);
1419 static int frevalidate_logvol(kdev_t dev
)
1421 return revalidate_logvol(dev
, 0);
1425 * revalidate_allvol is for online array config utilities. After a
1426 * utility reconfigures the drives in the array, it can use this function
1427 * (through an ioctl) to make the driver zap any previous disk structs for
1428 * that controller and get new ones.
1430 * Right now I'm using the getgeometry() function to do this, but this
1431 * function should probably be finer grained and allow you to revalidate one
1432 * particualar logical volume (instead of all of them on a particular
1435 static int revalidate_allvol(kdev_t dev
)
1438 unsigned long flags
;
1440 ctlr
= MAJOR(dev
) - MAJOR_NR
;
1441 if (MINOR(dev
) != 0)
1444 spin_lock_irqsave(&io_request_lock
, flags
);
1445 if (hba
[ctlr
]->usage_count
> 1) {
1446 spin_unlock_irqrestore(&io_request_lock
, flags
);
1447 printk("Device busy for volume revalidation (usage=%d)\n",
1448 hba
[ctlr
]->usage_count
);
1451 spin_unlock_irqrestore(&io_request_lock
, flags
);
1452 hba
[ctlr
]->usage_count
++;
1455 * Set the partition and block size structures for all volumes
1456 * on this controller to zero. We will reread all of this data
1458 memset(ida
+(ctlr
*256), 0, sizeof(struct hd_struct
)*NWD
*16);
1459 memset(ida_sizes
+(ctlr
*256), 0, sizeof(int)*NWD
*16);
1460 memset(ida_blocksizes
+(ctlr
*256), 0, sizeof(int)*NWD
*16);
1461 memset(ida_hardsizes
+(ctlr
*256), 0, sizeof(int)*NWD
*16);
1462 memset(hba
[ctlr
]->drv
, 0, sizeof(drv_info_t
)*NWD
);
1463 ida_gendisk
[ctlr
].nr_real
= 0;
1466 * Tell the array controller not to give us any interupts while
1467 * we check the new geometry. Then turn interrupts back on when
1470 hba
[ctlr
]->access
.set_intr_mask(hba
[ctlr
], 0);
1472 hba
[ctlr
]->access
.set_intr_mask(hba
[ctlr
], FIFO_NOT_EMPTY
);
1474 ida_geninit(&ida_gendisk
[ctlr
]);
1475 for(i
=0; i
<NWD
; i
++)
1476 if (ida_sizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)])
1477 revalidate_logvol(dev
+(i
<<NWD_SHIFT
), 2);
1479 hba
[ctlr
]->usage_count
--;
1483 /* Borrowed and adapted from sd.c */
1484 static int revalidate_logvol(kdev_t dev
, int maxusage
)
1487 struct gendisk
*gdev
;
1488 unsigned long flags
;
1493 target
= DEVICE_NR(dev
);
1494 ctlr
= MAJOR(dev
) - MAJOR_NR
;
1495 gdev
= &ida_gendisk
[ctlr
];
1497 spin_lock_irqsave(&io_request_lock
, flags
);
1498 if (hba
[ctlr
]->drv
[target
].usage_count
> maxusage
) {
1499 spin_unlock_irqrestore(&io_request_lock
, flags
);
1500 printk("Device busy for revalidation (usage=%d)\n",
1501 hba
[ctlr
]->drv
[target
].usage_count
);
1505 hba
[ctlr
]->drv
[target
].usage_count
++;
1506 spin_unlock_irqrestore(&io_request_lock
, flags
);
1508 max_p
= gdev
->max_p
;
1509 start
= target
<< gdev
->minor_shift
;
1511 for(i
=max_p
; i
>=0; i
--) {
1512 int minor
= start
+i
;
1513 kdev_t devi
= MKDEV(MAJOR_NR
+ ctlr
, minor
);
1514 struct super_block
*sb
= get_super(devi
);
1516 if (sb
) invalidate_inodes(sb
);
1517 invalidate_buffers(devi
);
1518 gdev
->part
[minor
].start_sect
= 0;
1519 gdev
->part
[minor
].nr_sects
= 0;
1521 /* reset the blocksize so we can read the partition table */
1522 blksize_size
[MAJOR_NR
+ctlr
][minor
] = 1024;
1525 gdev
->part
[start
].nr_sects
= hba
[ctlr
]->drv
[target
].nr_blks
;
1526 resetup_one_dev(gdev
, target
);
1527 hba
[ctlr
]->drv
[target
].usage_count
--;
1532 /********************************************************************
1534 Wait polling for a command to complete.
1535 The memory mapped FIFO is polled for the completion.
1536 Used only at init time, interrupts disabled.
1537 ********************************************************************/
1538 static int pollcomplete(int ctlr
)
1543 /* Wait (up to 2 seconds) for a command to complete */
1545 for (i
= 200000; i
> 0; i
--) {
1546 done
= hba
[ctlr
]->access
.command_completed(hba
[ctlr
]);
1548 udelay(10); /* a short fixed delay */
1552 /* Invalid address to tell caller we ran out of time */
1555 /*****************************************************************
1557 Starts controller firmwares background processing.
1558 Currently only the Integrated Raid controller needs this done.
1559 If the PCI mem address registers are written to after this,
1560 data corruption may occur
1561 *****************************************************************/
1562 static void start_fwbk(int ctlr
)
1564 id_ctlr_t
*id_ctlr_buf
;
1567 if( hba
[ctlr
]->board_id
!= 0x40400E11)
1568 /* Not a Integrated Raid, so there is nothing for us to do */
1570 printk(KERN_DEBUG
"Starting firmware's background processing\n");
1571 /* Command does not return anything, but idasend command needs a
1573 id_ctlr_buf
= (id_ctlr_t
*)kmalloc(sizeof(id_ctlr_t
), GFP_KERNEL
);
1574 if(id_ctlr_buf
==NULL
)
1576 printk(KERN_WARNING
"Out of memory. Unable to start background processing.\n");
1579 ret_code
= sendcmd(RESUME_BACKGROUND_ACTIVITY
, ctlr
,
1580 id_ctlr_buf
, 0, 0, 0, 0);
1581 if(ret_code
!= IO_OK
)
1582 printk(KERN_WARNING
"Unable to start background processing\n");
1585 /*****************************************************************
1587 Get ida logical volume geometry from the controller
1588 This is a large bit of code which once existed in two flavors,
1589 It is used only at init time.
1590 *****************************************************************/
1591 static void getgeometry(int ctlr
)
1593 id_log_drv_t
*id_ldrive
;
1594 id_ctlr_t
*id_ctlr_buf
;
1595 sense_log_drv_stat_t
*id_lstatus_buf
;
1596 config_t
*sense_config_buf
;
1597 unsigned int log_unit
, log_index
;
1600 ctlr_info_t
*info_p
= hba
[ctlr
];
1602 info_p
->log_drv_map
= 0;
1604 id_ldrive
= (id_log_drv_t
*)kmalloc(sizeof(id_log_drv_t
), GFP_KERNEL
);
1605 if(id_ldrive
== NULL
)
1607 id_ctlr_buf
= (id_ctlr_t
*)kmalloc(sizeof(id_ctlr_t
), GFP_KERNEL
);
1608 if(id_ctlr_buf
== NULL
)
1610 id_lstatus_buf
= (sense_log_drv_stat_t
*)kmalloc(sizeof(sense_log_drv_stat_t
), GFP_KERNEL
);
1611 if(id_lstatus_buf
== NULL
)
1613 sense_config_buf
= (config_t
*)kmalloc(sizeof(config_t
), GFP_KERNEL
);
1614 if(sense_config_buf
== NULL
)
1616 memset(id_ldrive
, 0, sizeof(id_log_drv_t
));
1617 memset(id_ctlr_buf
, 0, sizeof(id_ctlr_t
));
1618 memset(id_lstatus_buf
, 0, sizeof(sense_log_drv_stat_t
));
1619 memset(sense_config_buf
, 0, sizeof(config_t
));
1621 info_p
->phys_drives
= 0;
1622 info_p
->log_drv_map
= 0;
1623 info_p
->drv_assign_map
= 0;
1624 info_p
->drv_spare_map
= 0;
1625 info_p
->mp_failed_drv_map
= 0; /* only initialized here */
1626 /* Get controllers info for this logical drive */
1627 ret_code
= sendcmd(ID_CTLR
, ctlr
, id_ctlr_buf
, 0, 0, 0, 0);
1628 if (ret_code
== IO_ERROR
) {
1630 * If can't get controller info, set the logical drive map to 0,
1631 * so the idastubopen will fail on all logical drives
1632 * on the controller.
1634 goto geo_ret
; /* release the buf and return */
1636 info_p
->log_drives
= id_ctlr_buf
->nr_drvs
;;
1637 *(__u32
*)(info_p
->firm_rev
) = *(__u32
*)(id_ctlr_buf
->firm_rev
);
1638 info_p
->ctlr_sig
= id_ctlr_buf
->cfg_sig
;
1640 printk(" (%s)\n", info_p
->product_name
);
1642 * Initialize logical drive map to zero
1646 * Get drive geometry for all logical drives
1648 if (id_ctlr_buf
->nr_drvs
> 16)
1649 printk("ida%d: This driver supports 16 logical drives "
1650 "per controller.\n. Additional drives will not be "
1651 "detected\n", ctlr
);
1654 (log_index
< id_ctlr_buf
->nr_drvs
)
1655 && (log_unit
< NWD
);
1658 size
= sizeof(sense_log_drv_stat_t
);
1661 Send "Identify logical drive status" cmd
1663 ret_code
= sendcmd(SENSE_LOG_DRV_STAT
,
1664 ctlr
, id_lstatus_buf
, size
, 0, 0, log_unit
);
1665 if (ret_code
== IO_ERROR
) {
1667 If can't get logical drive status, set
1668 the logical drive map to 0, so the
1669 idastubopen will fail for all logical drives
1672 info_p
->log_drv_map
= 0;
1674 "ida%d: idaGetGeometry - Controller failed "
1675 "to report status of logical drive %d\n"
1676 "Access to this controller has been disabled\n",
1678 goto geo_ret
; /* release the buf and return */
1682 Make sure the logical drive is configured
1684 if (id_lstatus_buf
->status
!= LOG_NOT_CONF
) {
1685 ret_code
= sendcmd(ID_LOG_DRV
, ctlr
, id_ldrive
,
1686 sizeof(id_log_drv_t
), 0, 0, log_unit
);
1688 If error, the bit for this
1689 logical drive won't be set and
1690 idastubopen will return error.
1692 if (ret_code
!= IO_ERROR
) {
1693 drv
= &info_p
->drv
[log_unit
];
1694 drv
->blk_size
= id_ldrive
->blk_size
;
1695 drv
->nr_blks
= id_ldrive
->nr_blks
;
1696 drv
->cylinders
= id_ldrive
->drv
.cyl
;
1697 drv
->heads
= id_ldrive
->drv
.heads
;
1698 drv
->sectors
= id_ldrive
->drv
.sect_per_track
;
1699 info_p
->log_drv_map
|= (1 << log_unit
);
1701 printk("ida/c%dd%d: blksz=%d nr_blks=%d\n",
1702 ctlr
, log_unit
, drv
->blk_size
, drv
->nr_blks
);
1703 ret_code
= sendcmd(SENSE_CONFIG
,
1704 ctlr
, sense_config_buf
,
1705 sizeof(config_t
), 0, 0, log_unit
);
1706 if (ret_code
== IO_ERROR
) {
1707 info_p
->log_drv_map
= 0;
1708 goto geo_ret
; /* release the buf and return */
1710 info_p
->phys_drives
=
1711 sense_config_buf
->ctlr_phys_drv
;
1712 info_p
->drv_assign_map
1713 |= sense_config_buf
->drv_asgn_map
;
1714 info_p
->drv_assign_map
1715 |= sense_config_buf
->spare_asgn_map
;
1716 info_p
->drv_spare_map
1717 |= sense_config_buf
->spare_asgn_map
;
1718 } /* end of if no error on id_ldrive */
1719 log_index
= log_index
+ 1;
1720 } /* end of if logical drive configured */
1721 } /* end of for log_unit */
1723 kfree(sense_config_buf
);
1727 kfree(id_lstatus_buf
);