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/config.h> /* CONFIG_PROC_FS */
26 #include <linux/module.h>
27 #include <linux/version.h>
28 #include <linux/types.h>
29 #include <linux/pci.h>
30 #include <linux/kernel.h>
31 #include <linux/malloc.h>
32 #include <linux/delay.h>
33 #include <linux/major.h>
35 #include <linux/blkpg.h>
36 #include <linux/timer.h>
37 #include <linux/proc_fs.h>
38 #include <linux/init.h>
39 #include <linux/hdreg.h>
40 #include <linux/spinlock.h>
41 #include <asm/uaccess.h>
45 #define SMART2_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
47 #define DRIVER_NAME "Compaq SMART2 Driver (v 2.4.0)"
48 #define DRIVER_VERSION SMART2_DRIVER_VERSION(2,4,0)
49 #define MAJOR_NR COMPAQ_SMART2_MAJOR
50 #include <linux/blk.h>
51 #include <linux/blkdev.h>
52 #include <linux/genhd.h>
57 #include "ida_ioctl.h"
59 #define READ_AHEAD 128
60 #define NR_CMDS 128 /* This could probably go as high as ~400 */
65 static int nr_ctlr
= 0;
66 static ctlr_info_t
*hba
[MAX_CTLR
] = { 0, 0, 0, 0, 0, 0, 0, 0 };
68 static int eisa
[8] = { 0, 0 ,0 ,0, 0, 0 ,0 ,0 };
70 #define NR_PRODUCTS (sizeof(products)/sizeof(struct board_type))
72 /* board_id = Subsystem Device ID & Vendor ID
73 * product = Marketing Name for the board
74 * access = Address of the struct of function pointers
76 static struct board_type products
[] = {
77 { 0x0040110E, "IDA", &smart1_access
},
78 { 0x0140110E, "IDA-2", &smart1_access
},
79 { 0x1040110E, "IAES", &smart1_access
},
80 { 0x2040110E, "SMART", &smart1_access
},
81 { 0x3040110E, "SMART-2/E", &smart2e_access
},
82 { 0x40300E11, "SMART-2/P", &smart2_access
},
83 { 0x40310E11, "SMART-2SL", &smart2_access
},
84 { 0x40320E11, "Smart Array 3200", &smart2_access
},
85 { 0x40330E11, "Smart Array 3100ES", &smart2_access
},
86 { 0x40340E11, "Smart Array 221", &smart2_access
},
87 { 0x40400E11, "Integrated Array", &smart4_access
},
88 { 0x40500E11, "Smart Array 4200", &smart4_access
},
89 { 0x40510E11, "Smart Array 4250ES", &smart4_access
},
90 { 0x40580E11, "Smart Array 431", &smart4_access
},
93 static struct hd_struct
* ida
;
94 static int * ida_sizes
;
95 static int * ida_blocksizes
;
96 static int * ida_hardsizes
;
97 static struct gendisk ida_gendisk
[MAX_CTLR
];
99 static struct proc_dir_entry
*proc_array
= NULL
;
102 #define DBG(s) do { s } while(0)
103 /* Debug (general info)... */
104 #define DBGINFO(s) do { } while(0)
105 /* Debug Paranoid... */
106 #define DBGP(s) do { } while(0)
107 /* Debug Extra Paranoid... */
108 #define DBGPX(s) do { } while(0)
110 int cpqarray_init(void);
111 static int cpqarray_pci_detect(void);
112 static int cpqarray_pci_init(ctlr_info_t
*c
, unchar bus
, unchar device_fn
);
113 static ulong
remap_pci_mem(ulong base
, ulong size
);
114 static int cpqarray_eisa_detect(void);
115 static int pollcomplete(int ctlr
);
116 static void getgeometry(int ctlr
);
117 static void start_fwbk(int ctlr
);
119 static cmdlist_t
* cmd_alloc(ctlr_info_t
*h
);
120 static void cmd_free(ctlr_info_t
*h
, cmdlist_t
*c
);
129 unsigned int log_unit
);
131 static int ida_open(struct inode
*inode
, struct file
*filep
);
132 static int ida_release(struct inode
*inode
, struct file
*filep
);
133 static int ida_ioctl(struct inode
*inode
, struct file
*filep
, unsigned int cmd
, unsigned long arg
);
134 static int ida_ctlr_ioctl(int ctlr
, int dsk
, ida_ioctl_t
*io
);
136 static void do_ida_request(int i
);
138 * This is a hack. This driver eats a major number for each controller, and
139 * sets blkdev[xxx].request_fn to each one of these so the real request
140 * function knows what controller its working with.
142 #define DO_IDA_REQUEST(x) { do_ida_request(x); }
144 static void do_ida_request0(request_queue_t
* q
) DO_IDA_REQUEST(0);
145 static void do_ida_request1(request_queue_t
* q
) DO_IDA_REQUEST(1);
146 static void do_ida_request2(request_queue_t
* q
) DO_IDA_REQUEST(2);
147 static void do_ida_request3(request_queue_t
* q
) DO_IDA_REQUEST(3);
148 static void do_ida_request4(request_queue_t
* q
) DO_IDA_REQUEST(4);
149 static void do_ida_request5(request_queue_t
* q
) DO_IDA_REQUEST(5);
150 static void do_ida_request6(request_queue_t
* q
) DO_IDA_REQUEST(6);
151 static void do_ida_request7(request_queue_t
* q
) DO_IDA_REQUEST(7);
153 static void start_io(ctlr_info_t
*h
);
155 static inline void addQ(cmdlist_t
**Qptr
, cmdlist_t
*c
);
156 static inline cmdlist_t
*removeQ(cmdlist_t
**Qptr
, cmdlist_t
*c
);
157 static inline void complete_buffers(struct buffer_head
*bh
, int ok
);
158 static inline void complete_command(cmdlist_t
*cmd
, int timeout
);
160 static void do_ida_intr(int irq
, void *dev_id
, struct pt_regs
* regs
);
161 static void ida_timer(unsigned long tdata
);
162 static int frevalidate_logvol(kdev_t dev
);
163 static int revalidate_logvol(kdev_t dev
, int maxusage
);
164 static int revalidate_allvol(kdev_t dev
);
166 #ifdef CONFIG_PROC_FS
167 static void ida_procinit(int i
);
168 static int ida_proc_get_info(char *buffer
, char **start
, off_t offset
, int length
, int *eof
, void *data
);
170 static void ida_procinit(int i
) {}
171 static int ida_proc_get_info(char *buffer
, char **start
, off_t offset
,
172 int length
, int *eof
, void *data
) {}
175 static void ida_geninit(int ctlr
)
180 for(i
=0; i
<NWD
; i
++) {
181 drv
= &hba
[ctlr
]->drv
[i
];
184 ida
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)].nr_sects
=
185 ida_sizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)] =
188 for(j
=0; j
<16; j
++) {
189 ida_blocksizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)+j
] =
191 ida_hardsizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)+j
] =
194 ida_gendisk
[ctlr
].nr_real
++;
199 static struct block_device_operations ida_fops
= {
201 release
: ida_release
,
203 revalidate
: frevalidate_logvol
,
207 #ifdef CONFIG_PROC_FS
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 __init
ida_procinit(int i
)
215 if (proc_array
== NULL
) {
216 proc_array
= proc_mkdir("driver/array", NULL
);
217 if (!proc_array
) return;
220 create_proc_read_entry(hba
[i
]->devname
, 0, proc_array
,
221 ida_proc_get_info
, hba
[i
]);
225 * Report information about this controller.
227 static int ida_proc_get_info(char *buffer
, char **start
, off_t offset
, int length
, int *eof
, void *data
)
232 ctlr_info_t
*h
= (ctlr_info_t
*)data
;
234 #ifdef CPQ_PROC_PRINT_QUEUES
239 size
= sprintf(buffer
, "%s: Compaq %s Controller\n"
241 " Firmware Revision: %c%c%c%c\n"
242 " Controller Sig: %08lx\n"
243 " Memory Address: %08lx\n"
246 " Logical drives: %d\n"
247 " Physical drives: %d\n\n"
248 " Current Q depth: %d\n"
249 " Max Q depth since init: %d\n\n",
252 (unsigned long)h
->board_id
,
253 h
->firm_rev
[0], h
->firm_rev
[1], h
->firm_rev
[2], h
->firm_rev
[3],
254 (unsigned long)h
->ctlr_sig
, (unsigned long)h
->vaddr
,
255 (unsigned int) h
->ioaddr
, (unsigned int)h
->intr
,
256 h
->log_drives
, h
->phys_drives
,
257 h
->Qdepth
, h
->maxQsinceinit
);
259 pos
+= size
; len
+= size
;
261 size
= sprintf(buffer
+len
, "Logical Drive Info:\n");
262 pos
+= size
; len
+= size
;
264 for(i
=0; i
<h
->log_drives
; i
++) {
266 size
= sprintf(buffer
+len
, "ida/c%dd%d: blksz=%d nr_blks=%d\n",
267 ctlr
, i
, drv
->blk_size
, drv
->nr_blks
);
268 pos
+= size
; len
+= size
;
271 #ifdef CPQ_PROC_PRINT_QUEUES
272 size
= sprintf(buffer
+len
, "\nCurrent Queues:\n");
273 pos
+= size
; len
+= size
;
276 size
= sprintf(buffer
+len
, "reqQ = %p", c
); pos
+= size
; len
+= size
;
278 while(c
&& c
!= h
->reqQ
) {
279 size
= sprintf(buffer
+len
, "->%p", c
);
280 pos
+= size
; len
+= size
;
285 size
= sprintf(buffer
+len
, "\ncmpQ = %p", c
); pos
+= size
; len
+= size
;
287 while(c
&& c
!= h
->cmpQ
) {
288 size
= sprintf(buffer
+len
, "->%p", c
);
289 pos
+= size
; len
+= size
;
293 size
= sprintf(buffer
+len
, "\n"); pos
+= size
; len
+= size
;
295 size
= sprintf(buffer
+len
, "nr_allocs = %d\nnr_frees = %d\n",
296 h
->nr_allocs
, h
->nr_frees
);
297 pos
+= size
; len
+= size
;
300 *start
= buffer
+offset
;
306 #endif /* CONFIG_PROC_FS */
310 MODULE_PARM(eisa
, "1-8i");
313 /* This is a bit of a hack... */
314 int __init
init_module(void)
316 if (cpqarray_init() == 0) /* all the block dev numbers already used */
317 return -EIO
; /* or no controllers were found */
321 void cleanup_module(void)
326 remove_proc_entry("driver/array", NULL
);
328 for(i
=0; i
<nr_ctlr
; i
++) {
329 hba
[i
]->access
.set_intr_mask(hba
[i
], 0);
330 free_irq(hba
[i
]->intr
, hba
[i
]);
331 iounmap((void*)hba
[i
]->vaddr
);
332 unregister_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
);
333 del_timer(&hba
[i
]->timer
);
334 blk_cleanup_queue(BLK_DEFAULT_QUEUE(MAJOR_NR
+ i
));
335 remove_proc_entry(hba
[i
]->devname
, proc_array
);
336 kfree(hba
[i
]->cmd_pool
);
337 kfree(hba
[i
]->cmd_pool_bits
);
339 if (gendisk_head
== &ida_gendisk
[i
]) {
340 gendisk_head
= ida_gendisk
[i
].next
;
342 for(g
=gendisk_head
; g
; g
=g
->next
) {
343 if (g
->next
== &ida_gendisk
[i
]) {
344 g
->next
= ida_gendisk
[i
].next
;
353 kfree(ida_hardsizes
);
354 kfree(ida_blocksizes
);
359 * This is it. Find all the controllers and register them. I really hate
360 * stealing all these major device numbers.
361 * returns the number of block devices registered.
363 int __init
cpqarray_init(void)
365 void (*request_fns
[MAX_CTLR
])(request_queue_t
*) = {
366 do_ida_request0
, do_ida_request1
,
367 do_ida_request2
, do_ida_request3
,
368 do_ida_request4
, do_ida_request5
,
369 do_ida_request6
, do_ida_request7
,
372 int num_cntlrs_reg
= 0;
374 /* detect controllers */
375 cpqarray_pci_detect();
376 cpqarray_eisa_detect();
379 return(num_cntlrs_reg
);
381 printk(DRIVER_NAME
"\n");
382 printk("Found %d controller(s)\n", nr_ctlr
);
384 /* allocate space for disk structs */
385 ida
= kmalloc(sizeof(struct hd_struct
)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
388 printk( KERN_ERR
"cpqarray: out of memory");
389 return(num_cntlrs_reg
);
392 ida_sizes
= kmalloc(sizeof(int)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
396 printk( KERN_ERR
"cpqarray: out of memory");
397 return(num_cntlrs_reg
);
400 ida_blocksizes
= kmalloc(sizeof(int)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
401 if(ida_blocksizes
==NULL
)
405 printk( KERN_ERR
"cpqarray: out of memory");
406 return(num_cntlrs_reg
);
409 ida_hardsizes
= kmalloc(sizeof(int)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
410 if(ida_hardsizes
==NULL
)
414 kfree(ida_blocksizes
);
415 printk( KERN_ERR
"cpqarray: out of memory");
416 return(num_cntlrs_reg
);
419 memset(ida
, 0, sizeof(struct hd_struct
)*nr_ctlr
*NWD
*16);
420 memset(ida_sizes
, 0, sizeof(int)*nr_ctlr
*NWD
*16);
421 memset(ida_blocksizes
, 0, sizeof(int)*nr_ctlr
*NWD
*16);
422 memset(ida_hardsizes
, 0, sizeof(int)*nr_ctlr
*NWD
*16);
423 memset(ida_gendisk
, 0, sizeof(struct gendisk
)*MAX_CTLR
);
426 * register block devices
427 * Find disks and fill in structs
428 * Get an interrupt, set the Q depth and get into /proc
430 for(i
=0; i
< nr_ctlr
; i
++) {
431 /* If this successful it should insure that we are the only */
432 /* instance of the driver */
433 if (register_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
, &ida_fops
)) {
434 printk(KERN_ERR
"cpqarray: Unable to get major number %d for ida\n",
440 hba
[i
]->access
.set_intr_mask(hba
[i
], 0);
441 if (request_irq(hba
[i
]->intr
, do_ida_intr
,
442 SA_INTERRUPT
|SA_SHIRQ
, hba
[i
]->devname
, hba
[i
])) {
444 printk(KERN_ERR
"cpqarray: Unable to get irq %d for %s\n",
445 hba
[i
]->intr
, hba
[i
]->devname
);
446 unregister_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
);
450 hba
[i
]->cmd_pool
= (cmdlist_t
*)kmalloc(
451 NR_CMDS
* sizeof(cmdlist_t
), GFP_KERNEL
);
452 hba
[i
]->cmd_pool_bits
= (__u32
*)kmalloc(
453 ((NR_CMDS
+31)/32)*sizeof(__u32
), GFP_KERNEL
);
455 if(hba
[i
]->cmd_pool_bits
== NULL
|| hba
[i
]->cmd_pool
== NULL
)
458 if(hba
[i
]->cmd_pool_bits
)
459 kfree(hba
[i
]->cmd_pool_bits
);
461 kfree(hba
[i
]->cmd_pool
);
462 free_irq(hba
[i
]->intr
, hba
[i
]);
463 unregister_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
);
465 printk( KERN_ERR
"cpqarray: out of memory");
467 /* If num_cntlrs_reg == 0, no controllers worked.
468 * init_module will fail, so clean up global
469 * memory that clean_module would do.
472 if (num_cntlrs_reg
== 0)
476 kfree(ida_hardsizes
);
477 kfree(ida_blocksizes
);
479 return(num_cntlrs_reg
);
482 memset(hba
[i
]->cmd_pool
, 0, NR_CMDS
* sizeof(cmdlist_t
));
483 memset(hba
[i
]->cmd_pool_bits
, 0, ((NR_CMDS
+31)/32)*sizeof(__u32
));
484 printk(KERN_INFO
"cpqarray: Finding drives on %s",
489 hba
[i
]->access
.set_intr_mask(hba
[i
], FIFO_NOT_EMPTY
);
494 blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR
+ i
),
496 blk_queue_headactive(BLK_DEFAULT_QUEUE(MAJOR_NR
+ i
), 0);
497 blksize_size
[MAJOR_NR
+i
] = ida_blocksizes
+ (i
*256);
498 hardsect_size
[MAJOR_NR
+i
] = ida_hardsizes
+ (i
*256);
499 read_ahead
[MAJOR_NR
+i
] = READ_AHEAD
;
501 ida_gendisk
[i
].major
= MAJOR_NR
+ i
;
502 ida_gendisk
[i
].major_name
= "ida";
503 ida_gendisk
[i
].minor_shift
= NWD_SHIFT
;
504 ida_gendisk
[i
].max_p
= 16;
505 ida_gendisk
[i
].part
= ida
+ (i
*256);
506 ida_gendisk
[i
].sizes
= ida_sizes
+ (i
*256);
507 ida_gendisk
[i
].nr_real
= 0;
509 /* Get on the disk list */
510 ida_gendisk
[i
].next
= gendisk_head
;
511 gendisk_head
= &ida_gendisk
[i
];
513 init_timer(&hba
[i
]->timer
);
514 hba
[i
]->timer
.expires
= jiffies
+ IDA_TIMER
;
515 hba
[i
]->timer
.data
= (unsigned long)hba
[i
];
516 hba
[i
]->timer
.function
= ida_timer
;
517 add_timer(&hba
[i
]->timer
);
521 register_disk(&ida_gendisk
[i
],
522 MKDEV(MAJOR_NR
+i
,j
<<4),
523 16, &ida_fops
, hba
[i
]->drv
[j
].nr_blks
);
527 return(num_cntlrs_reg
);
531 * Find the controller and initialize it
532 * Cannot use the class code to search, because older array controllers use
533 * 0x018000 and new ones use 0x010400. So I might as well search for each
534 * each device IDs, being there are only going to be three of them.
536 static int cpqarray_pci_detect(void)
539 unchar bus
=0, dev_fn
=0;
541 #define IDA_BOARD_TYPES 3
542 static int ida_vendor_id
[IDA_BOARD_TYPES
] = { PCI_VENDOR_ID_DEC
,
543 PCI_VENDOR_ID_NCR
, PCI_VENDOR_ID_COMPAQ
};
544 static int ida_device_id
[IDA_BOARD_TYPES
] = { PCI_DEVICE_ID_COMPAQ_42XX
, PCI_DEVICE_ID_NCR_53C1510
, PCI_DEVICE_ID_COMPAQ_SMART2P
};
547 /* search for all PCI board types that could be for this driver */
548 for(brdtype
=0; brdtype
<IDA_BOARD_TYPES
; brdtype
++)
550 for(index
=0; ; index
++) {
551 if (pcibios_find_device(ida_vendor_id
[brdtype
],
552 ida_device_id
[brdtype
], index
, &bus
, &dev_fn
))
554 printk(KERN_DEBUG
"cpqarray: Device %x has been found at %x %x\n",
555 ida_vendor_id
[brdtype
], bus
, dev_fn
);
556 if (index
== 1000000) break;
558 printk(KERN_WARNING
"cpqarray: This driver"
559 " supports a maximum of 8 controllers.\n");
563 /* if it is a PCI_DEVICE_ID_NCR_53C1510, make sure it's the Compaq version of the chip */
565 if (ida_device_id
[brdtype
] == PCI_DEVICE_ID_NCR_53C1510
) {
566 unsigned short subvendor
=0;
567 if(pcibios_read_config_word(bus
, dev_fn
,
568 PCI_SUBSYSTEM_VENDOR_ID
, &subvendor
))
570 printk(KERN_DEBUG
"cpqarray: failed to read subvendor\n");
573 if(subvendor
!= PCI_VENDOR_ID_COMPAQ
)
576 "cpqarray: not a Compaq integrated array controller\n");
581 hba
[nr_ctlr
] = kmalloc(sizeof(ctlr_info_t
), GFP_KERNEL
); if(hba
[nr_ctlr
]==NULL
)
583 printk(KERN_ERR
"cpqarray: out of memory.\n");
586 memset(hba
[nr_ctlr
], 0, sizeof(ctlr_info_t
));
587 if (cpqarray_pci_init(hba
[nr_ctlr
], bus
, dev_fn
) != 0)
592 sprintf(hba
[nr_ctlr
]->devname
, "ida%d", nr_ctlr
);
593 hba
[nr_ctlr
]->ctlr
= nr_ctlr
;
603 * Find the IO address of the controller, its IRQ and so forth. Fill
604 * in some basic stuff into the ctlr_info_t structure.
606 static int cpqarray_pci_init(ctlr_info_t
*c
, unchar bus
, unchar device_fn
)
608 ushort vendor_id
, device_id
, command
;
609 unchar cache_line_size
, latency_timer
;
610 unchar irq
, revision
;
613 struct pci_dev
*pdev
;
617 pdev
= pci_find_slot(bus
, device_fn
);
618 vendor_id
= pdev
->vendor
;
619 device_id
= pdev
->device
;
623 addr
[i
] = pdev
->resource
[i
].flags
;
625 if (pci_enable_device(pdev
))
628 pci_read_config_word(pdev
, PCI_COMMAND
, &command
);
629 pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &revision
);
630 pci_read_config_byte(pdev
, PCI_CACHE_LINE_SIZE
, &cache_line_size
);
631 pci_read_config_byte(pdev
, PCI_LATENCY_TIMER
, &latency_timer
);
633 pci_read_config_dword(pdev
, 0x2c, &board_id
);
636 printk("vendor_id = %x\n", vendor_id
);
637 printk("device_id = %x\n", device_id
);
638 printk("command = %x\n", command
);
640 printk("addr[%d] = %x\n", i
, addr
[i
]);
641 printk("revision = %x\n", revision
);
642 printk("irq = %x\n", irq
);
643 printk("cache_line_size = %x\n", cache_line_size
);
644 printk("latency_timer = %x\n", latency_timer
);
645 printk("board_id = %x\n", board_id
);
649 c
->ioaddr
= addr
[0] & ~0x1;
652 * Memory base addr is first addr with the first bit _not_ set
655 if (!(addr
[i
] & 0x1)) {
656 c
->paddr
= pci_resource_start (pdev
, i
);
659 c
->vaddr
= remap_pci_mem(c
->paddr
, 128);
660 c
->board_id
= board_id
;
662 for(i
=0; i
<NR_PRODUCTS
; i
++) {
663 if (board_id
== products
[i
].board_id
) {
664 c
->product_name
= products
[i
].product_name
;
665 c
->access
= *(products
[i
].access
);
669 if (i
== NR_PRODUCTS
) {
670 printk(KERN_WARNING
"cpqarray: Sorry, I don't know how"
671 " to access the SMART Array controller %08lx\n",
672 (unsigned long)board_id
);
680 * Map (physical) PCI mem into (virtual) kernel space
682 static ulong
remap_pci_mem(ulong base
, ulong size
)
684 ulong page_base
= ((ulong
) base
) & PAGE_MASK
;
685 ulong page_offs
= ((ulong
) base
) - page_base
;
686 ulong page_remapped
= (ulong
) ioremap(page_base
, page_offs
+size
);
688 return (ulong
) (page_remapped
? (page_remapped
+ page_offs
) : 0UL);
692 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,13)
694 * Config string is a comma seperated set of i/o addresses of EISA cards.
696 static int cpqarray_setup(char *str
)
700 (void)get_options(str
, ARRAY_SIZE(ints
), ints
);
702 for(i
=0; i
<ints
[0] && i
<8; i
++)
707 __setup("smart2=", cpqarray_setup
);
712 * Copy the contents of the ints[] array passed to us by init.
714 void cpqarray_setup(char *str
, int *ints
)
717 for(i
=0; i
<ints
[0] && i
<8; i
++)
724 * Find an EISA controller's signature. Set up an hba if we find it.
726 static int cpqarray_eisa_detect(void)
732 while(i
<8 && eisa
[i
]) {
734 printk(KERN_WARNING
"cpqarray: This driver supports"
735 " a maximum of 8 controllers.\n");
738 board_id
= inl(eisa
[i
]+0xC80);
739 for(j
=0; j
< NR_PRODUCTS
; j
++)
740 if (board_id
== products
[j
].board_id
)
743 if (j
== NR_PRODUCTS
) {
744 printk(KERN_WARNING
"cpqarray: Sorry, I don't know how"
745 " to access the SMART Array controller %08lx\n", (unsigned long)board_id
);
748 hba
[nr_ctlr
] = (ctlr_info_t
*) kmalloc(sizeof(ctlr_info_t
), GFP_KERNEL
);
749 if(hba
[nr_ctlr
]==NULL
)
751 printk(KERN_ERR
"cpqarray: out of memory.\n");
754 memset(hba
[nr_ctlr
], 0, sizeof(ctlr_info_t
));
755 hba
[nr_ctlr
]->ioaddr
= eisa
[i
];
758 * Read the config register to find our interrupt
760 intr
= inb(eisa
[i
]+0xCC0) >> 4;
761 if (intr
& 1) intr
= 11;
762 else if (intr
& 2) intr
= 10;
763 else if (intr
& 4) intr
= 14;
764 else if (intr
& 8) intr
= 15;
766 hba
[nr_ctlr
]->intr
= intr
;
767 sprintf(hba
[nr_ctlr
]->devname
, "ida%d", nr_ctlr
);
768 hba
[nr_ctlr
]->product_name
= products
[j
].product_name
;
769 hba
[nr_ctlr
]->access
= *(products
[j
].access
);
770 hba
[nr_ctlr
]->ctlr
= nr_ctlr
;
771 hba
[nr_ctlr
]->board_id
= board_id
;
774 printk("i = %d, j = %d\n", i
, j
);
775 printk("irq = %x\n", intr
);
776 printk("product name = %s\n", products
[j
].product_name
);
777 printk("board_id = %x\n", board_id
);
789 * Open. Make sure the device is really there.
791 static int ida_open(struct inode
*inode
, struct file
*filep
)
793 int ctlr
= MAJOR(inode
->i_rdev
) - MAJOR_NR
;
794 int dsk
= MINOR(inode
->i_rdev
) >> NWD_SHIFT
;
796 DBGINFO(printk("ida_open %x (%x:%x)\n", inode
->i_rdev
, ctlr
, dsk
) );
797 if (ctlr
> MAX_CTLR
|| hba
[ctlr
] == NULL
)
800 if (!suser() && ida_sizes
[(ctlr
<< CTLR_SHIFT
) +
801 MINOR(inode
->i_rdev
)] == 0)
805 * Root is allowed to open raw volume zero even if its not configured
806 * so array config can still work. I don't think I really like this,
807 * but I'm already using way to many device nodes to claim another one
808 * for "raw controller".
811 && ida_sizes
[(ctlr
<< CTLR_SHIFT
) + MINOR(inode
->i_rdev
)] == 0
812 && MINOR(inode
->i_rdev
) != 0)
815 hba
[ctlr
]->drv
[dsk
].usage_count
++;
816 hba
[ctlr
]->usage_count
++;
824 static int ida_release(struct inode
*inode
, struct file
*filep
)
826 int ctlr
= MAJOR(inode
->i_rdev
) - MAJOR_NR
;
827 int dsk
= MINOR(inode
->i_rdev
) >> NWD_SHIFT
;
829 DBGINFO(printk("ida_release %x (%x:%x)\n", inode
->i_rdev
, ctlr
, dsk
) );
831 hba
[ctlr
]->drv
[dsk
].usage_count
--;
832 hba
[ctlr
]->usage_count
--;
838 * Enqueuing and dequeuing functions for cmdlists.
840 static inline void addQ(cmdlist_t
**Qptr
, cmdlist_t
*c
)
844 c
->next
= c
->prev
= c
;
846 c
->prev
= (*Qptr
)->prev
;
848 (*Qptr
)->prev
->next
= c
;
853 static inline cmdlist_t
*removeQ(cmdlist_t
**Qptr
, cmdlist_t
*c
)
855 if (c
&& c
->next
!= c
) {
856 if (*Qptr
== c
) *Qptr
= c
->next
;
857 c
->prev
->next
= c
->next
;
858 c
->next
->prev
= c
->prev
;
866 * Get a request and submit it to the controller.
867 * This routine needs to grab all the requests it possibly can from the
868 * req Q and submit them. Interrupts are off (and need to be off) when you
869 * are in here (either via the dummy do_ida_request functions or by being
870 * called from the interrupt handler
872 static void do_ida_request(int ctlr
)
874 ctlr_info_t
*h
= hba
[ctlr
];
878 struct list_head
* queue_head
;
879 struct buffer_head
*bh
;
880 struct request
*creq
;
882 queue_head
= &blk_dev
[MAJOR_NR
+ctlr
].request_queue
.queue_head
;
884 if (list_empty(queue_head
))
890 creq
= blkdev_entry_next_request(queue_head
);
891 if (creq
->rq_status
== RQ_INACTIVE
)
898 if (ctlr
!= MAJOR(creq
->rq_dev
)-MAJOR_NR
||
899 ctlr
> nr_ctlr
|| h
== NULL
)
901 printk("doreq cmd for %d, %x at %p\n",
902 ctlr
, creq
->rq_dev
, creq
);
903 complete_buffers(creq
->bh
, 0);
908 if ((c
= cmd_alloc(h
)) == NULL
)
917 c
->hdr
.unit
= MINOR(creq
->rq_dev
) >> NWD_SHIFT
;
918 c
->hdr
.size
= sizeof(rblk_t
) >> 2;
919 c
->size
+= sizeof(rblk_t
);
921 c
->req
.hdr
.blk
= ida
[(ctlr
<<CTLR_SHIFT
) + MINOR(creq
->rq_dev
)].start_sect
+ creq
->sector
;
925 panic("bh == NULL?");
927 printk("sector=%d, nr_sectors=%d\n", creq
->sector
, creq
->nr_sectors
);
929 seg
= 0; lastdataend
= NULL
;
932 sect
+= bh
->b_size
/512;
934 if (bh
->b_size
% 512) {
935 printk("Oh damn. %d+%d, size = %d\n", creq
->sector
, sect
, bh
->b_size
);
936 panic("b_size %% 512 != 0");
939 if (bh
->b_data
== lastdataend
) {
940 c
->req
.sg
[seg
-1].size
+= bh
->b_size
;
941 lastdataend
+= bh
->b_size
;
943 c
->req
.sg
[seg
].size
= bh
->b_size
;
944 c
->req
.sg
[seg
].addr
= (__u32
)virt_to_bus(bh
->b_data
);
945 lastdataend
= bh
->b_data
+ bh
->b_size
;
951 DBGPX( printk("Submitting %d sectors in %d segments\n", sect
, seg
); );
952 c
->req
.hdr
.sg_cnt
= seg
;
953 c
->req
.hdr
.blk_cnt
= sect
;
955 creq
->sector
+= sect
;
956 creq
->nr_sectors
-= sect
;
958 /* Ready the next request:
959 * Fix up creq if we still have more buffers in the buffer chain, or
960 * mark this request as done and ready the next one.
962 if (creq
->nr_sectors
) {
965 printk("sector=%d, nr_sectors=%d, sect=%d, seg=%d\n",
966 creq
->sector
, creq
->nr_sectors
, sect
, seg
);
970 creq
->bh
= bh
->b_reqnext
;
971 bh
->b_reqnext
= NULL
;
972 DBGPX( printk("More to do on same request %p\n", creq
); );
974 DBGPX( printk("Done with %p\n", creq
); );
975 blkdev_dequeue_request(creq
);
976 end_that_request_last(creq
);
979 c
->req
.hdr
.cmd
= (creq
->cmd
== READ
) ? IDA_READ
: IDA_WRITE
;
982 /* Put the request on the tail of the request queue */
985 if (h
->Qdepth
> h
->maxQsinceinit
)
986 h
->maxQsinceinit
= h
->Qdepth
;
992 * start_io submits everything on a controller's request queue
993 * and moves it to the completion queue.
995 * Interrupts had better be off if you're in here
997 static void start_io(ctlr_info_t
*h
)
1001 while((c
= h
->reqQ
) != NULL
) {
1002 /* Can't do anything if we're busy */
1003 if (h
->access
.fifo_full(h
) == 0)
1006 /* Get the first entry from the request Q */
1007 removeQ(&h
->reqQ
, c
);
1010 /* Tell the controller to do our bidding */
1011 h
->access
.submit_command(h
, c
);
1013 /* Get onto the completion Q */
1018 static inline void complete_buffers(struct buffer_head
*bh
, int ok
)
1020 struct buffer_head
*xbh
;
1022 xbh
= bh
->b_reqnext
;
1023 bh
->b_reqnext
= NULL
;
1025 bh
->b_end_io(bh
, ok
);
1031 * Mark all buffers that cmd was responsible for
1033 static inline void complete_command(cmdlist_t
*cmd
, int timeout
)
1037 if (cmd
->req
.hdr
.rcode
& RCODE_NONFATAL
&&
1038 (hba
[cmd
->ctlr
]->misc_tflags
& MISC_NONFATAL_WARN
) == 0) {
1039 printk(KERN_WARNING
"Non Fatal error on ida/c%dd%d\n",
1040 cmd
->ctlr
, cmd
->hdr
.unit
);
1041 hba
[cmd
->ctlr
]->misc_tflags
|= MISC_NONFATAL_WARN
;
1043 if (cmd
->req
.hdr
.rcode
& RCODE_FATAL
) {
1044 printk(KERN_WARNING
"Fatal error on ida/c%dd%d\n",
1045 cmd
->ctlr
, cmd
->hdr
.unit
);
1048 if (cmd
->req
.hdr
.rcode
& RCODE_INVREQ
) {
1049 printk(KERN_WARNING
"Invalid request on ida/c%dd%d = (cmd=%x sect=%d cnt=%d sg=%d ret=%x)\n",
1050 cmd
->ctlr
, cmd
->hdr
.unit
, cmd
->req
.hdr
.cmd
,
1051 cmd
->req
.hdr
.blk
, cmd
->req
.hdr
.blk_cnt
,
1052 cmd
->req
.hdr
.sg_cnt
, cmd
->req
.hdr
.rcode
);
1055 if (timeout
) ok
= 0;
1056 complete_buffers(cmd
->bh
, ok
);
1060 * The controller will interrupt us upon completion of commands.
1061 * Find the command on the completion queue, remove it, tell the OS and
1062 * try to queue up more IO
1064 static void do_ida_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
1066 ctlr_info_t
*h
= dev_id
;
1068 unsigned long istat
;
1069 unsigned long flags
;
1073 istat
= h
->access
.intr_pending(h
);
1074 /* Is this interrupt for us? */
1079 * If there are completed commands in the completion queue,
1080 * we had better do something about it.
1082 spin_lock_irqsave(&io_request_lock
, flags
);
1083 if (istat
& FIFO_NOT_EMPTY
) {
1084 while((a
= h
->access
.command_completed(h
))) {
1086 if ((c
= h
->cmpQ
) == NULL
)
1088 printk(KERN_WARNING
"cpqarray: Completion of %08lx ignored\n", (unsigned long)a1
);
1091 while(c
->busaddr
!= a
) {
1097 * If we've found the command, take it off the
1098 * completion Q and free it
1100 if (c
->busaddr
== a
) {
1101 removeQ(&h
->cmpQ
, c
);
1102 if (c
->type
== CMD_RWREQ
) {
1103 complete_command(c
, 0);
1105 } else if (c
->type
== CMD_IOCTL_PEND
) {
1106 c
->type
= CMD_IOCTL_DONE
;
1114 * See if we can queue up some more IO
1116 do_ida_request(h
->ctlr
);
1117 spin_unlock_irqrestore(&io_request_lock
, flags
);
1121 * This timer was for timing out requests that haven't happened after
1122 * IDA_TIMEOUT. That wasn't such a good idea. This timer is used to
1123 * reset a flags structure so we don't flood the user with
1124 * "Non-Fatal error" messages.
1126 static void ida_timer(unsigned long tdata
)
1128 ctlr_info_t
*h
= (ctlr_info_t
*)tdata
;
1130 h
->timer
.expires
= jiffies
+ IDA_TIMER
;
1131 add_timer(&h
->timer
);
1136 * ida_ioctl does some miscellaneous stuff like reporting drive geometry,
1137 * setting readahead and submitting commands from userspace to the controller.
1139 static int ida_ioctl(struct inode
*inode
, struct file
*filep
, unsigned int cmd
, unsigned long arg
)
1141 int ctlr
= MAJOR(inode
->i_rdev
) - MAJOR_NR
;
1142 int dsk
= MINOR(inode
->i_rdev
) >> NWD_SHIFT
;
1145 struct hd_geometry
*geo
= (struct hd_geometry
*)arg
;
1146 ida_ioctl_t
*io
= (ida_ioctl_t
*)arg
;
1151 if (hba
[ctlr
]->drv
[dsk
].cylinders
) {
1152 diskinfo
[0] = hba
[ctlr
]->drv
[dsk
].heads
;
1153 diskinfo
[1] = hba
[ctlr
]->drv
[dsk
].sectors
;
1154 diskinfo
[2] = hba
[ctlr
]->drv
[dsk
].cylinders
;
1158 diskinfo
[2] = hba
[ctlr
]->drv
[dsk
].nr_blks
/ (0xff*0x3f);
1160 put_user(diskinfo
[0], &geo
->heads
);
1161 put_user(diskinfo
[1], &geo
->sectors
);
1162 put_user(diskinfo
[2], &geo
->cylinders
);
1163 put_user(ida
[(ctlr
<<CTLR_SHIFT
)+MINOR(inode
->i_rdev
)].start_sect
, &geo
->start
);
1166 return copy_to_user(&io
->c
.drv
,&hba
[ctlr
]->drv
[dsk
],sizeof(drv_info_t
));
1168 if (!arg
) return -EINVAL
;
1169 put_user(ida
[(ctlr
<<CTLR_SHIFT
)+MINOR(inode
->i_rdev
)].nr_sects
, (long*)arg
);
1172 return revalidate_logvol(inode
->i_rdev
, 1);
1174 if (!suser()) return -EPERM
;
1175 error
= copy_from_user(&my_io
, io
, sizeof(my_io
));
1176 if (error
) return error
;
1177 error
= ida_ctlr_ioctl(ctlr
, dsk
, &my_io
);
1178 if (error
) return error
;
1179 error
= copy_to_user(io
, &my_io
, sizeof(my_io
));
1182 if (!arg
) return -EINVAL
;
1183 put_user(hba
[ctlr
]->ctlr_sig
, (int*)arg
);
1185 case IDAREVALIDATEVOLS
:
1186 return revalidate_allvol(inode
->i_rdev
);
1187 case IDADRIVERVERSION
:
1188 if (!arg
) return -EINVAL
;
1189 put_user(DRIVER_VERSION
, (unsigned long*)arg
);
1198 return blk_ioctl(inode
->i_rdev
, cmd
, arg
);
1206 * ida_ctlr_ioctl is for passing commands to the controller from userspace.
1207 * The command block (io) has already been copied to kernel space for us,
1208 * however, any elements in the sglist need to be copied to kernel space
1209 * or copied back to userspace.
1211 * Only root may perform a controller passthru command, however I'm not doing
1212 * any serious sanity checking on the arguments. Doing an IDA_WRITE_MEDIA and
1213 * putting a 64M buffer in the sglist is probably a *bad* idea.
1215 static int ida_ctlr_ioctl(int ctlr
, int dsk
, ida_ioctl_t
*io
)
1217 ctlr_info_t
*h
= hba
[ctlr
];
1220 unsigned long flags
;
1223 if ((c
= cmd_alloc(NULL
)) == NULL
)
1226 c
->hdr
.unit
= (io
->unit
& UNITVALID
) ? (io
->unit
& ~UNITVALID
) : dsk
;
1227 c
->hdr
.size
= sizeof(rblk_t
) >> 2;
1228 c
->size
+= sizeof(rblk_t
);
1230 c
->req
.hdr
.cmd
= io
->cmd
;
1231 c
->req
.hdr
.blk
= io
->blk
;
1232 c
->req
.hdr
.blk_cnt
= io
->blk_cnt
;
1233 c
->type
= CMD_IOCTL_PEND
;
1235 /* Pre submit processing */
1238 p
= kmalloc(io
->sg
[0].size
, GFP_KERNEL
);
1245 copy_from_user(p
, (void*)io
->sg
[0].addr
, io
->sg
[0].size
);
1246 c
->req
.hdr
.blk
= virt_to_bus(&(io
->c
));
1247 c
->req
.sg
[0].size
= io
->sg
[0].size
;
1248 c
->req
.sg
[0].addr
= virt_to_bus(p
);
1249 c
->req
.hdr
.sg_cnt
= 1;
1252 p
= kmalloc(io
->sg
[0].size
, GFP_KERNEL
);
1260 c
->req
.sg
[0].size
= io
->sg
[0].size
;
1261 c
->req
.sg
[0].addr
= virt_to_bus(p
);
1262 c
->req
.hdr
.sg_cnt
= 1;
1265 case IDA_WRITE_MEDIA
:
1266 case DIAG_PASS_THRU
:
1267 p
= kmalloc(io
->sg
[0].size
, GFP_KERNEL
);
1274 copy_from_user(p
, (void*)io
->sg
[0].addr
, io
->sg
[0].size
);
1275 c
->req
.sg
[0].size
= io
->sg
[0].size
;
1276 c
->req
.sg
[0].addr
= virt_to_bus(p
);
1277 c
->req
.hdr
.sg_cnt
= 1;
1280 c
->req
.sg
[0].size
= sizeof(io
->c
);
1281 c
->req
.sg
[0].addr
= virt_to_bus(&io
->c
);
1282 c
->req
.hdr
.sg_cnt
= 1;
1285 /* Put the request on the tail of the request queue */
1286 spin_lock_irqsave(&io_request_lock
, flags
);
1290 spin_unlock_irqrestore(&io_request_lock
, flags
);
1292 /* Wait for completion */
1293 while(c
->type
!= CMD_IOCTL_DONE
)
1296 /* Post submit processing */
1300 case DIAG_PASS_THRU
:
1301 copy_to_user((void*)io
->sg
[0].addr
, p
, io
->sg
[0].size
);
1302 /* fall through and free p */
1304 case IDA_WRITE_MEDIA
:
1311 io
->rcode
= c
->req
.hdr
.rcode
;
1317 * Commands are pre-allocated in a large block. Here we use a simple bitmap
1318 * scheme to suballocte them to the driver. Operations that are not time
1319 * critical (and can wait for kmalloc and possibly sleep) can pass in NULL
1320 * as the first argument to get a new command.
1322 static cmdlist_t
* cmd_alloc(ctlr_info_t
*h
)
1328 c
= (cmdlist_t
*)kmalloc(sizeof(cmdlist_t
), GFP_KERNEL
);
1333 i
= find_first_zero_bit(h
->cmd_pool_bits
, NR_CMDS
);
1336 } while(test_and_set_bit(i
%32, h
->cmd_pool_bits
+(i
/32)) != 0);
1337 c
= h
->cmd_pool
+ i
;
1341 memset(c
, 0, sizeof(cmdlist_t
));
1342 c
->busaddr
= virt_to_bus(c
);
1346 static void cmd_free(ctlr_info_t
*h
, cmdlist_t
*c
)
1353 i
= c
- h
->cmd_pool
;
1354 clear_bit(i
%32, h
->cmd_pool_bits
+(i
/32));
1359 /***********************************************************************
1361 Send a command to an IDA using the memory mapped FIFO interface
1362 and wait for it to complete.
1363 This routine should only be called at init time.
1364 ***********************************************************************/
1371 unsigned int blkcnt
,
1372 unsigned int log_unit
)
1378 ctlr_info_t
*info_p
= hba
[ctlr
];
1380 c
= cmd_alloc(info_p
);
1382 c
->hdr
.unit
= log_unit
;
1384 c
->hdr
.size
= sizeof(rblk_t
) >> 2;
1385 c
->size
+= sizeof(rblk_t
);
1387 /* The request information. */
1388 c
->req
.hdr
.next
= 0;
1389 c
->req
.hdr
.rcode
= 0;
1391 c
->req
.hdr
.sg_cnt
= 1;
1392 c
->req
.hdr
.reserved
= 0;
1395 c
->req
.sg
[0].size
= 512;
1397 c
->req
.sg
[0].size
= size
;
1399 c
->req
.hdr
.blk
= blk
;
1400 c
->req
.hdr
.blk_cnt
= blkcnt
;
1401 c
->req
.hdr
.cmd
= (unsigned char) cmd
;
1402 c
->req
.sg
[0].addr
= (__u32
) virt_to_bus(buff
);
1406 info_p
->access
.set_intr_mask(info_p
, 0);
1407 /* Make sure there is room in the command FIFO */
1408 /* Actually it should be completely empty at this time. */
1409 for (i
= 200000; i
> 0; i
--) {
1410 temp
= info_p
->access
.fifo_full(info_p
);
1416 printk(KERN_WARNING
"cpqarray ida%d: idaSendPciCmd FIFO full,"
1417 " waiting!\n", ctlr
);
1423 info_p
->access
.submit_command(info_p
, c
);
1424 complete
= pollcomplete(ctlr
);
1425 if (complete
!= 1) {
1426 if (complete
!= c
->busaddr
) {
1427 printk( KERN_WARNING
1428 "cpqarray ida%d: idaSendPciCmd "
1429 "Invalid command list address returned! (%08lx)\n",
1430 ctlr
, (unsigned long)complete
);
1431 cmd_free(info_p
, c
);
1435 printk( KERN_WARNING
1436 "cpqarray ida%d: idaSendPciCmd Timeout out, "
1437 "No command list address returned!\n",
1439 cmd_free(info_p
, c
);
1443 if (c
->req
.hdr
.rcode
& 0x00FE) {
1444 if (!(c
->req
.hdr
.rcode
& BIG_PROBLEM
)) {
1445 printk( KERN_WARNING
1446 "cpqarray ida%d: idaSendPciCmd, error: "
1447 "Controller failed at init time "
1448 "cmd: 0x%x, return code = 0x%x\n",
1449 ctlr
, c
->req
.hdr
.cmd
, c
->req
.hdr
.rcode
);
1451 cmd_free(info_p
, c
);
1455 cmd_free(info_p
, c
);
1459 static int frevalidate_logvol(kdev_t dev
)
1461 return revalidate_logvol(dev
, 0);
1465 * revalidate_allvol is for online array config utilities. After a
1466 * utility reconfigures the drives in the array, it can use this function
1467 * (through an ioctl) to make the driver zap any previous disk structs for
1468 * that controller and get new ones.
1470 * Right now I'm using the getgeometry() function to do this, but this
1471 * function should probably be finer grained and allow you to revalidate one
1472 * particualar logical volume (instead of all of them on a particular
1475 static int revalidate_allvol(kdev_t dev
)
1478 unsigned long flags
;
1480 ctlr
= MAJOR(dev
) - MAJOR_NR
;
1481 if (MINOR(dev
) != 0)
1484 spin_lock_irqsave(&io_request_lock
, flags
);
1485 if (hba
[ctlr
]->usage_count
> 1) {
1486 spin_unlock_irqrestore(&io_request_lock
, flags
);
1487 printk(KERN_WARNING
"cpqarray: Device busy for volume"
1488 " revalidation (usage=%d)\n", hba
[ctlr
]->usage_count
);
1491 spin_unlock_irqrestore(&io_request_lock
, flags
);
1492 hba
[ctlr
]->usage_count
++;
1495 * Set the partition and block size structures for all volumes
1496 * on this controller to zero. We will reread all of this data
1498 memset(ida
+(ctlr
*256), 0, sizeof(struct hd_struct
)*NWD
*16);
1499 memset(ida_sizes
+(ctlr
*256), 0, sizeof(int)*NWD
*16);
1500 memset(ida_blocksizes
+(ctlr
*256), 0, sizeof(int)*NWD
*16);
1501 memset(ida_hardsizes
+(ctlr
*256), 0, sizeof(int)*NWD
*16);
1502 memset(hba
[ctlr
]->drv
, 0, sizeof(drv_info_t
)*NWD
);
1503 ida_gendisk
[ctlr
].nr_real
= 0;
1506 * Tell the array controller not to give us any interupts while
1507 * we check the new geometry. Then turn interrupts back on when
1510 hba
[ctlr
]->access
.set_intr_mask(hba
[ctlr
], 0);
1512 hba
[ctlr
]->access
.set_intr_mask(hba
[ctlr
], FIFO_NOT_EMPTY
);
1515 for(i
=0; i
<NWD
; i
++)
1516 if (ida_sizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)])
1517 revalidate_logvol(dev
+(i
<<NWD_SHIFT
), 2);
1519 hba
[ctlr
]->usage_count
--;
1523 /* Borrowed and adapted from sd.c */
1524 static int revalidate_logvol(kdev_t dev
, int maxusage
)
1527 struct gendisk
*gdev
;
1528 unsigned long flags
;
1533 target
= DEVICE_NR(dev
);
1534 ctlr
= MAJOR(dev
) - MAJOR_NR
;
1535 gdev
= &ida_gendisk
[ctlr
];
1537 spin_lock_irqsave(&io_request_lock
, flags
);
1538 if (hba
[ctlr
]->drv
[target
].usage_count
> maxusage
) {
1539 spin_unlock_irqrestore(&io_request_lock
, flags
);
1540 printk(KERN_WARNING
"cpqarray: Device busy for "
1541 "revalidation (usage=%d)\n",
1542 hba
[ctlr
]->drv
[target
].usage_count
);
1546 hba
[ctlr
]->drv
[target
].usage_count
++;
1547 spin_unlock_irqrestore(&io_request_lock
, flags
);
1549 max_p
= gdev
->max_p
;
1550 start
= target
<< gdev
->minor_shift
;
1552 for(i
=max_p
; i
>=0; i
--) {
1553 int minor
= start
+i
;
1554 kdev_t devi
= MKDEV(MAJOR_NR
+ ctlr
, minor
);
1555 struct super_block
*sb
= get_super(devi
);
1557 if (sb
) invalidate_inodes(sb
);
1558 invalidate_buffers(devi
);
1559 gdev
->part
[minor
].start_sect
= 0;
1560 gdev
->part
[minor
].nr_sects
= 0;
1562 /* reset the blocksize so we can read the partition table */
1563 blksize_size
[MAJOR_NR
+ctlr
][minor
] = 1024;
1566 /* 16 minors per disk... */
1567 grok_partitions(gdev
, target
, 16, hba
[ctlr
]->drv
[target
].nr_blks
);
1568 hba
[ctlr
]->drv
[target
].usage_count
--;
1573 /********************************************************************
1575 Wait polling for a command to complete.
1576 The memory mapped FIFO is polled for the completion.
1577 Used only at init time, interrupts disabled.
1578 ********************************************************************/
1579 static int pollcomplete(int ctlr
)
1584 /* Wait (up to 2 seconds) for a command to complete */
1586 for (i
= 200000; i
> 0; i
--) {
1587 done
= hba
[ctlr
]->access
.command_completed(hba
[ctlr
]);
1589 udelay(10); /* a short fixed delay */
1593 /* Invalid address to tell caller we ran out of time */
1596 /*****************************************************************
1598 Starts controller firmwares background processing.
1599 Currently only the Integrated Raid controller needs this done.
1600 If the PCI mem address registers are written to after this,
1601 data corruption may occur
1602 *****************************************************************/
1603 static void start_fwbk(int ctlr
)
1605 id_ctlr_t
*id_ctlr_buf
;
1608 if( (hba
[ctlr
]->board_id
!= 0x40400E11)
1609 && (hba
[ctlr
]->board_id
!= 0x40480E11) )
1611 /* Not a Integrated Raid, so there is nothing for us to do */
1613 printk(KERN_DEBUG
"cpqarray: Starting firmware's background"
1615 /* Command does not return anything, but idasend command needs a
1617 id_ctlr_buf
= (id_ctlr_t
*)kmalloc(sizeof(id_ctlr_t
), GFP_KERNEL
);
1618 if(id_ctlr_buf
==NULL
)
1620 printk(KERN_WARNING
"cpqarray: Out of memory. "
1621 "Unable to start background processing.\n");
1624 ret_code
= sendcmd(RESUME_BACKGROUND_ACTIVITY
, ctlr
,
1625 id_ctlr_buf
, 0, 0, 0, 0);
1626 if(ret_code
!= IO_OK
)
1627 printk(KERN_WARNING
"cpqarray: Unable to start"
1628 " background processing\n");
1632 /*****************************************************************
1634 Get ida logical volume geometry from the controller
1635 This is a large bit of code which once existed in two flavors,
1636 It is used only at init time.
1637 *****************************************************************/
1638 static void getgeometry(int ctlr
)
1640 id_log_drv_t
*id_ldrive
;
1641 id_ctlr_t
*id_ctlr_buf
;
1642 sense_log_drv_stat_t
*id_lstatus_buf
;
1643 config_t
*sense_config_buf
;
1644 unsigned int log_unit
, log_index
;
1647 ctlr_info_t
*info_p
= hba
[ctlr
];
1649 info_p
->log_drv_map
= 0;
1651 id_ldrive
= (id_log_drv_t
*)kmalloc(sizeof(id_log_drv_t
), GFP_KERNEL
);
1652 if(id_ldrive
== NULL
)
1654 printk( KERN_ERR
"cpqarray: out of memory.\n");
1658 id_ctlr_buf
= (id_ctlr_t
*)kmalloc(sizeof(id_ctlr_t
), GFP_KERNEL
);
1659 if(id_ctlr_buf
== NULL
)
1662 printk( KERN_ERR
"cpqarray: out of memory.\n");
1666 id_lstatus_buf
= (sense_log_drv_stat_t
*)kmalloc(sizeof(sense_log_drv_stat_t
), GFP_KERNEL
);
1667 if(id_lstatus_buf
== NULL
)
1671 printk( KERN_ERR
"cpqarray: out of memory.\n");
1675 sense_config_buf
= (config_t
*)kmalloc(sizeof(config_t
), GFP_KERNEL
);
1676 if(sense_config_buf
== NULL
)
1678 kfree(id_lstatus_buf
);
1681 printk( KERN_ERR
"cpqarray: out of memory.\n");
1685 memset(id_ldrive
, 0, sizeof(id_log_drv_t
));
1686 memset(id_ctlr_buf
, 0, sizeof(id_ctlr_t
));
1687 memset(id_lstatus_buf
, 0, sizeof(sense_log_drv_stat_t
));
1688 memset(sense_config_buf
, 0, sizeof(config_t
));
1690 info_p
->phys_drives
= 0;
1691 info_p
->log_drv_map
= 0;
1692 info_p
->drv_assign_map
= 0;
1693 info_p
->drv_spare_map
= 0;
1694 info_p
->mp_failed_drv_map
= 0; /* only initialized here */
1695 /* Get controllers info for this logical drive */
1696 ret_code
= sendcmd(ID_CTLR
, ctlr
, id_ctlr_buf
, 0, 0, 0, 0);
1697 if (ret_code
== IO_ERROR
) {
1699 * If can't get controller info, set the logical drive map to 0,
1700 * so the idastubopen will fail on all logical drives
1701 * on the controller.
1703 /* Free all the buffers and return */
1704 printk(KERN_ERR
"cpqarray: error sending ID controller\n");
1705 kfree(sense_config_buf
);
1706 kfree(id_lstatus_buf
);
1712 info_p
->log_drives
= id_ctlr_buf
->nr_drvs
;;
1713 *(__u32
*)(info_p
->firm_rev
) = *(__u32
*)(id_ctlr_buf
->firm_rev
);
1714 info_p
->ctlr_sig
= id_ctlr_buf
->cfg_sig
;
1716 printk(" (%s)\n", info_p
->product_name
);
1718 * Initialize logical drive map to zero
1722 * Get drive geometry for all logical drives
1724 if (id_ctlr_buf
->nr_drvs
> 16)
1725 printk(KERN_WARNING
"cpqarray ida%d: This driver supports "
1726 "16 logical drives per controller.\n. "
1727 " Additional drives will not be "
1728 "detected\n", ctlr
);
1731 (log_index
< id_ctlr_buf
->nr_drvs
)
1732 && (log_unit
< NWD
);
1735 size
= sizeof(sense_log_drv_stat_t
);
1738 Send "Identify logical drive status" cmd
1740 ret_code
= sendcmd(SENSE_LOG_DRV_STAT
,
1741 ctlr
, id_lstatus_buf
, size
, 0, 0, log_unit
);
1742 if (ret_code
== IO_ERROR
) {
1744 If can't get logical drive status, set
1745 the logical drive map to 0, so the
1746 idastubopen will fail for all logical drives
1749 info_p
->log_drv_map
= 0;
1750 printk( KERN_WARNING
1751 "cpqarray ida%d: idaGetGeometry - Controller"
1752 " failed to report status of logical drive %d\n"
1753 "Access to this controller has been disabled\n",
1755 /* Free all the buffers and return */
1756 kfree(sense_config_buf
);
1757 kfree(id_lstatus_buf
);
1763 Make sure the logical drive is configured
1765 if (id_lstatus_buf
->status
!= LOG_NOT_CONF
) {
1766 ret_code
= sendcmd(ID_LOG_DRV
, ctlr
, id_ldrive
,
1767 sizeof(id_log_drv_t
), 0, 0, log_unit
);
1769 If error, the bit for this
1770 logical drive won't be set and
1771 idastubopen will return error.
1773 if (ret_code
!= IO_ERROR
) {
1774 drv
= &info_p
->drv
[log_unit
];
1775 drv
->blk_size
= id_ldrive
->blk_size
;
1776 drv
->nr_blks
= id_ldrive
->nr_blks
;
1777 drv
->cylinders
= id_ldrive
->drv
.cyl
;
1778 drv
->heads
= id_ldrive
->drv
.heads
;
1779 drv
->sectors
= id_ldrive
->drv
.sect_per_track
;
1780 info_p
->log_drv_map
|= (1 << log_unit
);
1782 printk(KERN_INFO
"cpqarray ida/c%dd%d: blksz=%d nr_blks=%d\n",
1783 ctlr
, log_unit
, drv
->blk_size
, drv
->nr_blks
);
1784 ret_code
= sendcmd(SENSE_CONFIG
,
1785 ctlr
, sense_config_buf
,
1786 sizeof(config_t
), 0, 0, log_unit
);
1787 if (ret_code
== IO_ERROR
) {
1788 info_p
->log_drv_map
= 0;
1789 /* Free all the buffers and return */
1790 printk(KERN_ERR
"cpqarray: error sending sense config\n");
1791 kfree(sense_config_buf
);
1792 kfree(id_lstatus_buf
);
1798 info_p
->phys_drives
=
1799 sense_config_buf
->ctlr_phys_drv
;
1800 info_p
->drv_assign_map
1801 |= sense_config_buf
->drv_asgn_map
;
1802 info_p
->drv_assign_map
1803 |= sense_config_buf
->spare_asgn_map
;
1804 info_p
->drv_spare_map
1805 |= sense_config_buf
->spare_asgn_map
;
1806 } /* end of if no error on id_ldrive */
1807 log_index
= log_index
+ 1;
1808 } /* end of if logical drive configured */
1809 } /* end of for log_unit */
1810 kfree(sense_config_buf
);
1812 kfree(id_lstatus_buf
);