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.1)"
48 #define DRIVER_VERSION SMART2_DRIVER_VERSION(2,4,1)
50 /* Embedded module documentation macros - see modules.h */
51 /* Original author Chris Frantz - Compaq Computer Corporation */
52 MODULE_AUTHOR("Compaq Computer Corporation");
53 MODULE_DESCRIPTION("Driver for Compaq Smart2 Array Controllers");
55 #define MAJOR_NR COMPAQ_SMART2_MAJOR
56 #include <linux/blk.h>
57 #include <linux/blkdev.h>
58 #include <linux/genhd.h>
63 #include "ida_ioctl.h"
65 #define READ_AHEAD 128
66 #define NR_CMDS 128 /* This could probably go as high as ~400 */
72 static ctlr_info_t
*hba
[MAX_CTLR
];
76 #define NR_PRODUCTS (sizeof(products)/sizeof(struct board_type))
78 /* board_id = Subsystem Device ID & Vendor ID
79 * product = Marketing Name for the board
80 * access = Address of the struct of function pointers
82 static struct board_type products
[] = {
83 { 0x0040110E, "IDA", &smart1_access
},
84 { 0x0140110E, "IDA-2", &smart1_access
},
85 { 0x1040110E, "IAES", &smart1_access
},
86 { 0x2040110E, "SMART", &smart1_access
},
87 { 0x3040110E, "SMART-2/E", &smart2e_access
},
88 { 0x40300E11, "SMART-2/P", &smart2_access
},
89 { 0x40310E11, "SMART-2SL", &smart2_access
},
90 { 0x40320E11, "Smart Array 3200", &smart2_access
},
91 { 0x40330E11, "Smart Array 3100ES", &smart2_access
},
92 { 0x40340E11, "Smart Array 221", &smart2_access
},
93 { 0x40400E11, "Integrated Array", &smart4_access
},
94 { 0x40480E11, "Compaq Raid LC2", &smart4_access
},
95 { 0x40500E11, "Smart Array 4200", &smart4_access
},
96 { 0x40510E11, "Smart Array 4250ES", &smart4_access
},
97 { 0x40580E11, "Smart Array 431", &smart4_access
},
100 static struct hd_struct
* ida
;
101 static int * ida_sizes
;
102 static int * ida_blocksizes
;
103 static int * ida_hardsizes
;
104 static struct gendisk ida_gendisk
[MAX_CTLR
];
106 static struct proc_dir_entry
*proc_array
;
109 #define DBG(s) do { s } while(0)
110 /* Debug (general info)... */
111 #define DBGINFO(s) do { } while(0)
112 /* Debug Paranoid... */
113 #define DBGP(s) do { } while(0)
114 /* Debug Extra Paranoid... */
115 #define DBGPX(s) do { } while(0)
117 int cpqarray_init(void);
118 static int cpqarray_pci_detect(void);
119 static int cpqarray_pci_init(ctlr_info_t
*c
, struct pci_dev
*pdev
);
120 static void *remap_pci_mem(ulong base
, ulong size
);
121 static int cpqarray_eisa_detect(void);
122 static int pollcomplete(int ctlr
);
123 static void getgeometry(int ctlr
);
124 static void start_fwbk(int ctlr
);
126 static cmdlist_t
* cmd_alloc(ctlr_info_t
*h
);
127 static void cmd_free(ctlr_info_t
*h
, cmdlist_t
*c
);
136 unsigned int log_unit
);
138 static int ida_open(struct inode
*inode
, struct file
*filep
);
139 static int ida_release(struct inode
*inode
, struct file
*filep
);
140 static int ida_ioctl(struct inode
*inode
, struct file
*filep
, unsigned int cmd
, unsigned long arg
);
141 static int ida_ctlr_ioctl(int ctlr
, int dsk
, ida_ioctl_t
*io
);
143 static void do_ida_request(int i
);
145 * This is a hack. This driver eats a major number for each controller, and
146 * sets blkdev[xxx].request_fn to each one of these so the real request
147 * function knows what controller its working with.
149 #define DO_IDA_REQUEST(x) { do_ida_request(x); }
151 static void do_ida_request0(request_queue_t
* q
) DO_IDA_REQUEST(0);
152 static void do_ida_request1(request_queue_t
* q
) DO_IDA_REQUEST(1);
153 static void do_ida_request2(request_queue_t
* q
) DO_IDA_REQUEST(2);
154 static void do_ida_request3(request_queue_t
* q
) DO_IDA_REQUEST(3);
155 static void do_ida_request4(request_queue_t
* q
) DO_IDA_REQUEST(4);
156 static void do_ida_request5(request_queue_t
* q
) DO_IDA_REQUEST(5);
157 static void do_ida_request6(request_queue_t
* q
) DO_IDA_REQUEST(6);
158 static void do_ida_request7(request_queue_t
* q
) DO_IDA_REQUEST(7);
160 static void start_io(ctlr_info_t
*h
);
162 static inline void addQ(cmdlist_t
**Qptr
, cmdlist_t
*c
);
163 static inline cmdlist_t
*removeQ(cmdlist_t
**Qptr
, cmdlist_t
*c
);
164 static inline void complete_buffers(struct buffer_head
*bh
, int ok
);
165 static inline void complete_command(cmdlist_t
*cmd
, int timeout
);
167 static void do_ida_intr(int irq
, void *dev_id
, struct pt_regs
* regs
);
168 static void ida_timer(unsigned long tdata
);
169 static int frevalidate_logvol(kdev_t dev
);
170 static int revalidate_logvol(kdev_t dev
, int maxusage
);
171 static int revalidate_allvol(kdev_t dev
);
173 #ifdef CONFIG_PROC_FS
174 static void ida_procinit(int i
);
175 static int ida_proc_get_info(char *buffer
, char **start
, off_t offset
, int length
, int *eof
, void *data
);
177 static void ida_procinit(int i
) {}
178 static int ida_proc_get_info(char *buffer
, char **start
, off_t offset
,
179 int length
, int *eof
, void *data
) { return 0;}
182 static void ida_geninit(int ctlr
)
187 for(i
=0; i
<NWD
; i
++) {
188 drv
= &hba
[ctlr
]->drv
[i
];
191 ida
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)].nr_sects
=
192 ida_sizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)] =
195 for(j
=0; j
<16; j
++) {
196 ida_blocksizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)+j
] =
198 ida_hardsizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)+j
] =
201 ida_gendisk
[ctlr
].nr_real
++;
206 static struct block_device_operations ida_fops
= {
208 release
: ida_release
,
210 revalidate
: frevalidate_logvol
,
214 #ifdef CONFIG_PROC_FS
217 * Get us a file in /proc/array that says something about each controller.
218 * Create /proc/array if it doesn't exist yet.
220 static void __init
ida_procinit(int i
)
222 if (proc_array
== NULL
) {
223 proc_array
= proc_mkdir("driver/array", NULL
);
224 if (!proc_array
) return;
227 create_proc_read_entry(hba
[i
]->devname
, 0, proc_array
,
228 ida_proc_get_info
, hba
[i
]);
232 * Report information about this controller.
234 static int ida_proc_get_info(char *buffer
, char **start
, off_t offset
, int length
, int *eof
, void *data
)
239 ctlr_info_t
*h
= (ctlr_info_t
*)data
;
241 #ifdef CPQ_PROC_PRINT_QUEUES
246 size
= sprintf(buffer
, "%s: Compaq %s Controller\n"
248 " Firmware Revision: %c%c%c%c\n"
249 " Controller Sig: %08lx\n"
250 " Memory Address: %08lx\n"
253 " Logical drives: %d\n"
254 " Physical drives: %d\n\n"
255 " Current Q depth: %d\n"
256 " Max Q depth since init: %d\n\n",
259 (unsigned long)h
->board_id
,
260 h
->firm_rev
[0], h
->firm_rev
[1], h
->firm_rev
[2], h
->firm_rev
[3],
261 (unsigned long)h
->ctlr_sig
, (unsigned long)h
->vaddr
,
262 (unsigned int) h
->ioaddr
, (unsigned int)h
->intr
,
263 h
->log_drives
, h
->phys_drives
,
264 h
->Qdepth
, h
->maxQsinceinit
);
266 pos
+= size
; len
+= size
;
268 size
= sprintf(buffer
+len
, "Logical Drive Info:\n");
269 pos
+= size
; len
+= size
;
271 for(i
=0; i
<h
->log_drives
; i
++) {
273 size
= sprintf(buffer
+len
, "ida/c%dd%d: blksz=%d nr_blks=%d\n",
274 ctlr
, i
, drv
->blk_size
, drv
->nr_blks
);
275 pos
+= size
; len
+= size
;
278 #ifdef CPQ_PROC_PRINT_QUEUES
279 size
= sprintf(buffer
+len
, "\nCurrent Queues:\n");
280 pos
+= size
; len
+= size
;
283 size
= sprintf(buffer
+len
, "reqQ = %p", c
); pos
+= size
; len
+= size
;
285 while(c
&& c
!= h
->reqQ
) {
286 size
= sprintf(buffer
+len
, "->%p", c
);
287 pos
+= size
; len
+= size
;
292 size
= sprintf(buffer
+len
, "\ncmpQ = %p", c
); pos
+= size
; len
+= size
;
294 while(c
&& c
!= h
->cmpQ
) {
295 size
= sprintf(buffer
+len
, "->%p", c
);
296 pos
+= size
; len
+= size
;
300 size
= sprintf(buffer
+len
, "\n"); pos
+= size
; len
+= size
;
302 size
= sprintf(buffer
+len
, "nr_allocs = %d\nnr_frees = %d\n",
303 h
->nr_allocs
, h
->nr_frees
);
304 pos
+= size
; len
+= size
;
307 *start
= buffer
+offset
;
313 #endif /* CONFIG_PROC_FS */
317 MODULE_PARM(eisa
, "1-8i");
320 /* This is a bit of a hack... */
321 int __init
init_module(void)
323 if (cpqarray_init() == 0) /* all the block dev numbers already used */
324 return -EIO
; /* or no controllers were found */
328 void cleanup_module(void)
333 remove_proc_entry("driver/array", NULL
);
335 for(i
=0; i
<nr_ctlr
; i
++) {
336 hba
[i
]->access
.set_intr_mask(hba
[i
], 0);
337 free_irq(hba
[i
]->intr
, hba
[i
]);
338 iounmap(hba
[i
]->vaddr
);
339 unregister_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
);
340 del_timer(&hba
[i
]->timer
);
341 blk_cleanup_queue(BLK_DEFAULT_QUEUE(MAJOR_NR
+ i
));
342 remove_proc_entry(hba
[i
]->devname
, proc_array
);
343 kfree(hba
[i
]->cmd_pool
);
344 kfree(hba
[i
]->cmd_pool_bits
);
346 if (gendisk_head
== &ida_gendisk
[i
]) {
347 gendisk_head
= ida_gendisk
[i
].next
;
349 for(g
=gendisk_head
; g
; g
=g
->next
) {
350 if (g
->next
== &ida_gendisk
[i
]) {
351 g
->next
= ida_gendisk
[i
].next
;
360 kfree(ida_hardsizes
);
361 kfree(ida_blocksizes
);
366 * This is it. Find all the controllers and register them. I really hate
367 * stealing all these major device numbers.
368 * returns the number of block devices registered.
370 int __init
cpqarray_init(void)
372 void (*request_fns
[MAX_CTLR
])(request_queue_t
*) = {
373 do_ida_request0
, do_ida_request1
,
374 do_ida_request2
, do_ida_request3
,
375 do_ida_request4
, do_ida_request5
,
376 do_ida_request6
, do_ida_request7
,
379 int num_cntlrs_reg
= 0;
381 /* detect controllers */
382 cpqarray_pci_detect();
383 cpqarray_eisa_detect();
386 return(num_cntlrs_reg
);
388 printk(DRIVER_NAME
"\n");
389 printk("Found %d controller(s)\n", nr_ctlr
);
391 /* allocate space for disk structs */
392 ida
= kmalloc(sizeof(struct hd_struct
)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
395 printk( KERN_ERR
"cpqarray: out of memory");
396 return(num_cntlrs_reg
);
399 ida_sizes
= kmalloc(sizeof(int)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
403 printk( KERN_ERR
"cpqarray: out of memory");
404 return(num_cntlrs_reg
);
407 ida_blocksizes
= kmalloc(sizeof(int)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
408 if(ida_blocksizes
==NULL
)
412 printk( KERN_ERR
"cpqarray: out of memory");
413 return(num_cntlrs_reg
);
416 ida_hardsizes
= kmalloc(sizeof(int)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
417 if(ida_hardsizes
==NULL
)
421 kfree(ida_blocksizes
);
422 printk( KERN_ERR
"cpqarray: out of memory");
423 return(num_cntlrs_reg
);
426 memset(ida
, 0, sizeof(struct hd_struct
)*nr_ctlr
*NWD
*16);
427 memset(ida_sizes
, 0, sizeof(int)*nr_ctlr
*NWD
*16);
428 memset(ida_blocksizes
, 0, sizeof(int)*nr_ctlr
*NWD
*16);
429 memset(ida_hardsizes
, 0, sizeof(int)*nr_ctlr
*NWD
*16);
430 memset(ida_gendisk
, 0, sizeof(struct gendisk
)*MAX_CTLR
);
433 * register block devices
434 * Find disks and fill in structs
435 * Get an interrupt, set the Q depth and get into /proc
437 for(i
=0; i
< nr_ctlr
; i
++) {
438 /* If this successful it should insure that we are the only */
439 /* instance of the driver */
440 if (register_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
, &ida_fops
)) {
441 printk(KERN_ERR
"cpqarray: Unable to get major number %d for ida\n",
447 hba
[i
]->access
.set_intr_mask(hba
[i
], 0);
448 if (request_irq(hba
[i
]->intr
, do_ida_intr
,
449 SA_INTERRUPT
|SA_SHIRQ
, hba
[i
]->devname
, hba
[i
])) {
451 printk(KERN_ERR
"cpqarray: Unable to get irq %d for %s\n",
452 hba
[i
]->intr
, hba
[i
]->devname
);
453 unregister_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
);
457 hba
[i
]->cmd_pool
= (cmdlist_t
*)kmalloc(
458 NR_CMDS
* sizeof(cmdlist_t
), GFP_KERNEL
);
459 hba
[i
]->cmd_pool_bits
= (__u32
*)kmalloc(
460 ((NR_CMDS
+31)/32)*sizeof(__u32
), GFP_KERNEL
);
462 if(hba
[i
]->cmd_pool_bits
== NULL
|| hba
[i
]->cmd_pool
== NULL
)
465 if(hba
[i
]->cmd_pool_bits
)
466 kfree(hba
[i
]->cmd_pool_bits
);
468 kfree(hba
[i
]->cmd_pool
);
469 free_irq(hba
[i
]->intr
, hba
[i
]);
470 unregister_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
);
472 printk( KERN_ERR
"cpqarray: out of memory");
474 /* If num_cntlrs_reg == 0, no controllers worked.
475 * init_module will fail, so clean up global
476 * memory that clean_module would do.
479 if (num_cntlrs_reg
== 0)
483 kfree(ida_hardsizes
);
484 kfree(ida_blocksizes
);
486 return(num_cntlrs_reg
);
489 memset(hba
[i
]->cmd_pool
, 0, NR_CMDS
* sizeof(cmdlist_t
));
490 memset(hba
[i
]->cmd_pool_bits
, 0, ((NR_CMDS
+31)/32)*sizeof(__u32
));
491 printk(KERN_INFO
"cpqarray: Finding drives on %s",
496 hba
[i
]->access
.set_intr_mask(hba
[i
], FIFO_NOT_EMPTY
);
501 blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR
+ i
),
503 blk_queue_headactive(BLK_DEFAULT_QUEUE(MAJOR_NR
+ i
), 0);
504 blksize_size
[MAJOR_NR
+i
] = ida_blocksizes
+ (i
*256);
505 hardsect_size
[MAJOR_NR
+i
] = ida_hardsizes
+ (i
*256);
506 read_ahead
[MAJOR_NR
+i
] = READ_AHEAD
;
508 ida_gendisk
[i
].major
= MAJOR_NR
+ i
;
509 ida_gendisk
[i
].major_name
= "ida";
510 ida_gendisk
[i
].minor_shift
= NWD_SHIFT
;
511 ida_gendisk
[i
].max_p
= 16;
512 ida_gendisk
[i
].part
= ida
+ (i
*256);
513 ida_gendisk
[i
].sizes
= ida_sizes
+ (i
*256);
514 ida_gendisk
[i
].nr_real
= 0;
516 /* Get on the disk list */
517 ida_gendisk
[i
].next
= gendisk_head
;
518 gendisk_head
= &ida_gendisk
[i
];
520 init_timer(&hba
[i
]->timer
);
521 hba
[i
]->timer
.expires
= jiffies
+ IDA_TIMER
;
522 hba
[i
]->timer
.data
= (unsigned long)hba
[i
];
523 hba
[i
]->timer
.function
= ida_timer
;
524 add_timer(&hba
[i
]->timer
);
528 register_disk(&ida_gendisk
[i
],
529 MKDEV(MAJOR_NR
+i
,j
<<4),
530 16, &ida_fops
, hba
[i
]->drv
[j
].nr_blks
);
534 return(num_cntlrs_reg
);
538 * Find the controller and initialize it
539 * Cannot use the class code to search, because older array controllers use
540 * 0x018000 and new ones use 0x010400. So I might as well search for each
541 * each device IDs, being there are only going to be three of them.
543 static int cpqarray_pci_detect(void)
545 struct pci_dev
*pdev
;
547 #define IDA_BOARD_TYPES 3
548 static int ida_vendor_id
[IDA_BOARD_TYPES
] = { PCI_VENDOR_ID_DEC
,
549 PCI_VENDOR_ID_NCR
, PCI_VENDOR_ID_COMPAQ
};
550 static int ida_device_id
[IDA_BOARD_TYPES
] = { PCI_DEVICE_ID_COMPAQ_42XX
, PCI_DEVICE_ID_NCR_53C1510
, PCI_DEVICE_ID_COMPAQ_SMART2P
};
553 /* search for all PCI board types that could be for this driver */
554 for(brdtype
=0; brdtype
<IDA_BOARD_TYPES
; brdtype
++)
556 pdev
= pci_find_device(ida_vendor_id
[brdtype
],
557 ida_device_id
[brdtype
], NULL
);
559 printk(KERN_DEBUG
"cpqarray: Device %x has been found at %x %x\n",
560 ida_vendor_id
[brdtype
],
561 pdev
->bus
->number
, pdev
->devfn
);
563 printk(KERN_WARNING
"cpqarray: This driver"
564 " supports a maximum of 8 controllers.\n");
568 /* if it is a PCI_DEVICE_ID_NCR_53C1510, make sure it's the Compaq version of the chip */
570 if (ida_device_id
[brdtype
] == PCI_DEVICE_ID_NCR_53C1510
) {
571 unsigned short subvendor
=pdev
->subsystem_vendor
;
572 if(subvendor
!= PCI_VENDOR_ID_COMPAQ
)
575 "cpqarray: not a Compaq integrated array controller\n");
580 hba
[nr_ctlr
] = kmalloc(sizeof(ctlr_info_t
), GFP_KERNEL
); if(hba
[nr_ctlr
]==NULL
)
582 printk(KERN_ERR
"cpqarray: out of memory.\n");
585 memset(hba
[nr_ctlr
], 0, sizeof(ctlr_info_t
));
586 if (cpqarray_pci_init(hba
[nr_ctlr
], pdev
) != 0)
591 sprintf(hba
[nr_ctlr
]->devname
, "ida%d", nr_ctlr
);
592 hba
[nr_ctlr
]->ctlr
= nr_ctlr
;
595 pdev
= pci_find_device(ida_vendor_id
[brdtype
],
596 ida_device_id
[brdtype
], pdev
);
604 * Find the IO address of the controller, its IRQ and so forth. Fill
605 * in some basic stuff into the ctlr_info_t structure.
607 static int cpqarray_pci_init(ctlr_info_t
*c
, struct pci_dev
*pdev
)
609 ushort vendor_id
, device_id
, command
;
610 unchar cache_line_size
, latency_timer
;
611 unchar irq
, revision
;
612 unsigned long addr
[6];
618 vendor_id
= pdev
->vendor
;
619 device_id
= pdev
->device
;
623 addr
[i
] = pci_resource_start(pdev
, i
);
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] = %lx\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
);
653 if (pci_resource_flags(pdev
, i
) & IORESOURCE_MEM
) {
654 c
->paddr
= pci_resource_start (pdev
, i
);
659 c
->vaddr
= remap_pci_mem(c
->paddr
, 128);
662 c
->board_id
= board_id
;
664 for(i
=0; i
<NR_PRODUCTS
; i
++) {
665 if (board_id
== products
[i
].board_id
) {
666 c
->product_name
= products
[i
].product_name
;
667 c
->access
= *(products
[i
].access
);
671 if (i
== NR_PRODUCTS
) {
672 printk(KERN_WARNING
"cpqarray: Sorry, I don't know how"
673 " to access the SMART Array controller %08lx\n",
674 (unsigned long)board_id
);
682 * Map (physical) PCI mem into (virtual) kernel space
684 static void *remap_pci_mem(ulong base
, ulong size
)
686 ulong page_base
= ((ulong
) base
) & PAGE_MASK
;
687 ulong page_offs
= ((ulong
) base
) - page_base
;
688 void *page_remapped
= ioremap(page_base
, page_offs
+size
);
690 return (page_remapped
? (page_remapped
+ page_offs
) : NULL
);
694 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,13)
696 * Config string is a comma seperated set of i/o addresses of EISA cards.
698 static int cpqarray_setup(char *str
)
702 (void)get_options(str
, ARRAY_SIZE(ints
), ints
);
704 for(i
=0; i
<ints
[0] && i
<8; i
++)
709 __setup("smart2=", cpqarray_setup
);
714 * Copy the contents of the ints[] array passed to us by init.
716 void cpqarray_setup(char *str
, int *ints
)
719 for(i
=0; i
<ints
[0] && i
<8; i
++)
726 * Find an EISA controller's signature. Set up an hba if we find it.
728 static int cpqarray_eisa_detect(void)
734 while(i
<8 && eisa
[i
]) {
736 printk(KERN_WARNING
"cpqarray: This driver supports"
737 " a maximum of 8 controllers.\n");
740 board_id
= inl(eisa
[i
]+0xC80);
741 for(j
=0; j
< NR_PRODUCTS
; j
++)
742 if (board_id
== products
[j
].board_id
)
745 if (j
== NR_PRODUCTS
) {
746 printk(KERN_WARNING
"cpqarray: Sorry, I don't know how"
747 " to access the SMART Array controller %08lx\n", (unsigned long)board_id
);
750 hba
[nr_ctlr
] = (ctlr_info_t
*) kmalloc(sizeof(ctlr_info_t
), GFP_KERNEL
);
751 if(hba
[nr_ctlr
]==NULL
)
753 printk(KERN_ERR
"cpqarray: out of memory.\n");
756 memset(hba
[nr_ctlr
], 0, sizeof(ctlr_info_t
));
757 hba
[nr_ctlr
]->ioaddr
= eisa
[i
];
760 * Read the config register to find our interrupt
762 intr
= inb(eisa
[i
]+0xCC0) >> 4;
763 if (intr
& 1) intr
= 11;
764 else if (intr
& 2) intr
= 10;
765 else if (intr
& 4) intr
= 14;
766 else if (intr
& 8) intr
= 15;
768 hba
[nr_ctlr
]->intr
= intr
;
769 sprintf(hba
[nr_ctlr
]->devname
, "ida%d", nr_ctlr
);
770 hba
[nr_ctlr
]->product_name
= products
[j
].product_name
;
771 hba
[nr_ctlr
]->access
= *(products
[j
].access
);
772 hba
[nr_ctlr
]->ctlr
= nr_ctlr
;
773 hba
[nr_ctlr
]->board_id
= board_id
;
774 hba
[nr_ctlr
]->pci_dev
= NULL
; /* not PCI */
777 printk("i = %d, j = %d\n", i
, j
);
778 printk("irq = %x\n", intr
);
779 printk("product name = %s\n", products
[j
].product_name
);
780 printk("board_id = %x\n", board_id
);
792 * Open. Make sure the device is really there.
794 static int ida_open(struct inode
*inode
, struct file
*filep
)
796 int ctlr
= MAJOR(inode
->i_rdev
) - MAJOR_NR
;
797 int dsk
= MINOR(inode
->i_rdev
) >> NWD_SHIFT
;
799 DBGINFO(printk("ida_open %x (%x:%x)\n", inode
->i_rdev
, ctlr
, dsk
) );
800 if (ctlr
> MAX_CTLR
|| hba
[ctlr
] == NULL
)
803 if (!suser() && ida_sizes
[(ctlr
<< CTLR_SHIFT
) +
804 MINOR(inode
->i_rdev
)] == 0)
808 * Root is allowed to open raw volume zero even if its not configured
809 * so array config can still work. I don't think I really like this,
810 * but I'm already using way to many device nodes to claim another one
811 * for "raw controller".
814 && ida_sizes
[(ctlr
<< CTLR_SHIFT
) + MINOR(inode
->i_rdev
)] == 0
815 && MINOR(inode
->i_rdev
) != 0)
818 hba
[ctlr
]->drv
[dsk
].usage_count
++;
819 hba
[ctlr
]->usage_count
++;
827 static int ida_release(struct inode
*inode
, struct file
*filep
)
829 int ctlr
= MAJOR(inode
->i_rdev
) - MAJOR_NR
;
830 int dsk
= MINOR(inode
->i_rdev
) >> NWD_SHIFT
;
832 DBGINFO(printk("ida_release %x (%x:%x)\n", inode
->i_rdev
, ctlr
, dsk
) );
834 hba
[ctlr
]->drv
[dsk
].usage_count
--;
835 hba
[ctlr
]->usage_count
--;
841 * Enqueuing and dequeuing functions for cmdlists.
843 static inline void addQ(cmdlist_t
**Qptr
, cmdlist_t
*c
)
847 c
->next
= c
->prev
= c
;
849 c
->prev
= (*Qptr
)->prev
;
851 (*Qptr
)->prev
->next
= c
;
856 static inline cmdlist_t
*removeQ(cmdlist_t
**Qptr
, cmdlist_t
*c
)
858 if (c
&& c
->next
!= c
) {
859 if (*Qptr
== c
) *Qptr
= c
->next
;
860 c
->prev
->next
= c
->next
;
861 c
->next
->prev
= c
->prev
;
869 * Get a request and submit it to the controller.
870 * This routine needs to grab all the requests it possibly can from the
871 * req Q and submit them. Interrupts are off (and need to be off) when you
872 * are in here (either via the dummy do_ida_request functions or by being
873 * called from the interrupt handler
875 static void do_ida_request(int ctlr
)
877 ctlr_info_t
*h
= hba
[ctlr
];
881 struct list_head
* queue_head
;
882 struct buffer_head
*bh
;
883 struct request
*creq
;
885 queue_head
= &blk_dev
[MAJOR_NR
+ctlr
].request_queue
.queue_head
;
887 if (list_empty(queue_head
))
893 creq
= blkdev_entry_next_request(queue_head
);
894 if (creq
->rq_status
== RQ_INACTIVE
)
901 if (ctlr
!= MAJOR(creq
->rq_dev
)-MAJOR_NR
||
902 ctlr
> nr_ctlr
|| h
== NULL
)
904 printk(KERN_WARNING
"doreq cmd for %d, %x at %p\n",
905 ctlr
, creq
->rq_dev
, creq
);
906 complete_buffers(creq
->bh
, 0);
911 if ((c
= cmd_alloc(h
)) == NULL
)
920 c
->hdr
.unit
= MINOR(creq
->rq_dev
) >> NWD_SHIFT
;
921 c
->hdr
.size
= sizeof(rblk_t
) >> 2;
922 c
->size
+= sizeof(rblk_t
);
924 c
->req
.hdr
.blk
= ida
[(ctlr
<<CTLR_SHIFT
) + MINOR(creq
->rq_dev
)].start_sect
+ creq
->sector
;
928 panic("bh == NULL?");
930 printk("sector=%d, nr_sectors=%d\n", creq
->sector
, creq
->nr_sectors
);
932 seg
= 0; lastdataend
= NULL
;
935 sect
+= bh
->b_size
/512;
937 if (bh
->b_size
% 512) {
938 printk("Oh damn. %d+%d, size = %d\n", creq
->sector
, sect
, bh
->b_size
);
939 panic("b_size %% 512 != 0");
942 if (bh
->b_data
== lastdataend
) {
943 c
->req
.sg
[seg
-1].size
+= bh
->b_size
;
944 lastdataend
+= bh
->b_size
;
946 c
->req
.sg
[seg
].size
= bh
->b_size
;
947 c
->req
.sg
[seg
].addr
= (__u32
)virt_to_bus(bh
->b_data
);
948 lastdataend
= bh
->b_data
+ bh
->b_size
;
954 DBGPX( printk("Submitting %d sectors in %d segments\n", sect
, seg
); );
955 c
->req
.hdr
.sg_cnt
= seg
;
956 c
->req
.hdr
.blk_cnt
= sect
;
958 creq
->sector
+= sect
;
959 creq
->nr_sectors
-= sect
;
961 /* Ready the next request:
962 * Fix up creq if we still have more buffers in the buffer chain, or
963 * mark this request as done and ready the next one.
965 if (creq
->nr_sectors
) {
968 printk("sector=%d, nr_sectors=%d, sect=%d, seg=%d\n",
969 creq
->sector
, creq
->nr_sectors
, sect
, seg
);
973 creq
->bh
= bh
->b_reqnext
;
974 bh
->b_reqnext
= NULL
;
975 DBGPX( printk("More to do on same request %p\n", creq
); );
977 DBGPX( printk("Done with %p\n", creq
); );
978 blkdev_dequeue_request(creq
);
979 end_that_request_last(creq
);
982 c
->req
.hdr
.cmd
= (creq
->cmd
== READ
) ? IDA_READ
: IDA_WRITE
;
985 /* Put the request on the tail of the request queue */
988 if (h
->Qdepth
> h
->maxQsinceinit
)
989 h
->maxQsinceinit
= h
->Qdepth
;
995 * start_io submits everything on a controller's request queue
996 * and moves it to the completion queue.
998 * Interrupts had better be off if you're in here
1000 static void start_io(ctlr_info_t
*h
)
1004 while((c
= h
->reqQ
) != NULL
) {
1005 /* Can't do anything if we're busy */
1006 if (h
->access
.fifo_full(h
) == 0)
1009 /* Get the first entry from the request Q */
1010 removeQ(&h
->reqQ
, c
);
1013 /* Tell the controller to do our bidding */
1014 h
->access
.submit_command(h
, c
);
1016 /* Get onto the completion Q */
1021 static inline void complete_buffers(struct buffer_head
*bh
, int ok
)
1023 struct buffer_head
*xbh
;
1025 xbh
= bh
->b_reqnext
;
1026 bh
->b_reqnext
= NULL
;
1028 bh
->b_end_io(bh
, ok
);
1034 * Mark all buffers that cmd was responsible for
1036 static inline void complete_command(cmdlist_t
*cmd
, int timeout
)
1040 if (cmd
->req
.hdr
.rcode
& RCODE_NONFATAL
&&
1041 (hba
[cmd
->ctlr
]->misc_tflags
& MISC_NONFATAL_WARN
) == 0) {
1042 printk(KERN_WARNING
"Non Fatal error on ida/c%dd%d\n",
1043 cmd
->ctlr
, cmd
->hdr
.unit
);
1044 hba
[cmd
->ctlr
]->misc_tflags
|= MISC_NONFATAL_WARN
;
1046 if (cmd
->req
.hdr
.rcode
& RCODE_FATAL
) {
1047 printk(KERN_WARNING
"Fatal error on ida/c%dd%d\n",
1048 cmd
->ctlr
, cmd
->hdr
.unit
);
1051 if (cmd
->req
.hdr
.rcode
& RCODE_INVREQ
) {
1052 printk(KERN_WARNING
"Invalid request on ida/c%dd%d = (cmd=%x sect=%d cnt=%d sg=%d ret=%x)\n",
1053 cmd
->ctlr
, cmd
->hdr
.unit
, cmd
->req
.hdr
.cmd
,
1054 cmd
->req
.hdr
.blk
, cmd
->req
.hdr
.blk_cnt
,
1055 cmd
->req
.hdr
.sg_cnt
, cmd
->req
.hdr
.rcode
);
1058 if (timeout
) ok
= 0;
1059 complete_buffers(cmd
->bh
, ok
);
1063 * The controller will interrupt us upon completion of commands.
1064 * Find the command on the completion queue, remove it, tell the OS and
1065 * try to queue up more IO
1067 static void do_ida_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
1069 ctlr_info_t
*h
= dev_id
;
1071 unsigned long istat
;
1072 unsigned long flags
;
1076 istat
= h
->access
.intr_pending(h
);
1077 /* Is this interrupt for us? */
1082 * If there are completed commands in the completion queue,
1083 * we had better do something about it.
1085 spin_lock_irqsave(&io_request_lock
, flags
);
1086 if (istat
& FIFO_NOT_EMPTY
) {
1087 while((a
= h
->access
.command_completed(h
))) {
1089 if ((c
= h
->cmpQ
) == NULL
)
1091 printk(KERN_WARNING
"cpqarray: Completion of %08lx ignored\n", (unsigned long)a1
);
1094 while(c
->busaddr
!= a
) {
1100 * If we've found the command, take it off the
1101 * completion Q and free it
1103 if (c
->busaddr
== a
) {
1104 removeQ(&h
->cmpQ
, c
);
1105 if (c
->type
== CMD_RWREQ
) {
1106 complete_command(c
, 0);
1108 } else if (c
->type
== CMD_IOCTL_PEND
) {
1109 c
->type
= CMD_IOCTL_DONE
;
1117 * See if we can queue up some more IO
1119 do_ida_request(h
->ctlr
);
1120 spin_unlock_irqrestore(&io_request_lock
, flags
);
1124 * This timer was for timing out requests that haven't happened after
1125 * IDA_TIMEOUT. That wasn't such a good idea. This timer is used to
1126 * reset a flags structure so we don't flood the user with
1127 * "Non-Fatal error" messages.
1129 static void ida_timer(unsigned long tdata
)
1131 ctlr_info_t
*h
= (ctlr_info_t
*)tdata
;
1133 h
->timer
.expires
= jiffies
+ IDA_TIMER
;
1134 add_timer(&h
->timer
);
1139 * ida_ioctl does some miscellaneous stuff like reporting drive geometry,
1140 * setting readahead and submitting commands from userspace to the controller.
1142 static int ida_ioctl(struct inode
*inode
, struct file
*filep
, unsigned int cmd
, unsigned long arg
)
1144 int ctlr
= MAJOR(inode
->i_rdev
) - MAJOR_NR
;
1145 int dsk
= MINOR(inode
->i_rdev
) >> NWD_SHIFT
;
1148 struct hd_geometry
*geo
= (struct hd_geometry
*)arg
;
1149 ida_ioctl_t
*io
= (ida_ioctl_t
*)arg
;
1154 if (hba
[ctlr
]->drv
[dsk
].cylinders
) {
1155 diskinfo
[0] = hba
[ctlr
]->drv
[dsk
].heads
;
1156 diskinfo
[1] = hba
[ctlr
]->drv
[dsk
].sectors
;
1157 diskinfo
[2] = hba
[ctlr
]->drv
[dsk
].cylinders
;
1161 diskinfo
[2] = hba
[ctlr
]->drv
[dsk
].nr_blks
/ (0xff*0x3f);
1163 put_user(diskinfo
[0], &geo
->heads
);
1164 put_user(diskinfo
[1], &geo
->sectors
);
1165 put_user(diskinfo
[2], &geo
->cylinders
);
1166 put_user(ida
[(ctlr
<<CTLR_SHIFT
)+MINOR(inode
->i_rdev
)].start_sect
, &geo
->start
);
1169 return copy_to_user(&io
->c
.drv
,&hba
[ctlr
]->drv
[dsk
],sizeof(drv_info_t
));
1171 if (!arg
) return -EINVAL
;
1172 put_user(ida
[(ctlr
<<CTLR_SHIFT
)+MINOR(inode
->i_rdev
)].nr_sects
, (long*)arg
);
1175 return revalidate_logvol(inode
->i_rdev
, 1);
1177 if (!suser()) return -EPERM
;
1178 error
= copy_from_user(&my_io
, io
, sizeof(my_io
));
1179 if (error
) return error
;
1180 error
= ida_ctlr_ioctl(ctlr
, dsk
, &my_io
);
1181 if (error
) return error
;
1182 error
= copy_to_user(io
, &my_io
, sizeof(my_io
));
1185 if (!arg
) return -EINVAL
;
1186 put_user(hba
[ctlr
]->ctlr_sig
, (int*)arg
);
1188 case IDAREVALIDATEVOLS
:
1189 return revalidate_allvol(inode
->i_rdev
);
1190 case IDADRIVERVERSION
:
1191 if (!arg
) return -EINVAL
;
1192 put_user(DRIVER_VERSION
, (unsigned long*)arg
);
1197 ida_pci_info_struct pciinfo
;
1199 if (!arg
) return -EINVAL
;
1200 pciinfo
.bus
= hba
[ctlr
]->pci_dev
->bus
->number
;
1201 pciinfo
.dev_fn
= hba
[ctlr
]->pci_dev
->devfn
;
1202 pciinfo
.board_id
= hba
[ctlr
]->board_id
;
1203 if(copy_to_user((void *) arg
, &pciinfo
,
1204 sizeof( ida_pci_info_struct
)))
1215 return blk_ioctl(inode
->i_rdev
, cmd
, arg
);
1223 * ida_ctlr_ioctl is for passing commands to the controller from userspace.
1224 * The command block (io) has already been copied to kernel space for us,
1225 * however, any elements in the sglist need to be copied to kernel space
1226 * or copied back to userspace.
1228 * Only root may perform a controller passthru command, however I'm not doing
1229 * any serious sanity checking on the arguments. Doing an IDA_WRITE_MEDIA and
1230 * putting a 64M buffer in the sglist is probably a *bad* idea.
1232 static int ida_ctlr_ioctl(int ctlr
, int dsk
, ida_ioctl_t
*io
)
1234 ctlr_info_t
*h
= hba
[ctlr
];
1237 unsigned long flags
;
1240 if ((c
= cmd_alloc(NULL
)) == NULL
)
1243 c
->hdr
.unit
= (io
->unit
& UNITVALID
) ? (io
->unit
& ~UNITVALID
) : dsk
;
1244 c
->hdr
.size
= sizeof(rblk_t
) >> 2;
1245 c
->size
+= sizeof(rblk_t
);
1247 c
->req
.hdr
.cmd
= io
->cmd
;
1248 c
->req
.hdr
.blk
= io
->blk
;
1249 c
->req
.hdr
.blk_cnt
= io
->blk_cnt
;
1250 c
->type
= CMD_IOCTL_PEND
;
1252 /* Pre submit processing */
1255 p
= kmalloc(io
->sg
[0].size
, GFP_KERNEL
);
1262 copy_from_user(p
, (void*)io
->sg
[0].addr
, io
->sg
[0].size
);
1263 c
->req
.hdr
.blk
= virt_to_bus(&(io
->c
));
1264 c
->req
.sg
[0].size
= io
->sg
[0].size
;
1265 c
->req
.sg
[0].addr
= virt_to_bus(p
);
1266 c
->req
.hdr
.sg_cnt
= 1;
1269 p
= kmalloc(io
->sg
[0].size
, GFP_KERNEL
);
1277 c
->req
.sg
[0].size
= io
->sg
[0].size
;
1278 c
->req
.sg
[0].addr
= virt_to_bus(p
);
1279 c
->req
.hdr
.sg_cnt
= 1;
1282 case IDA_WRITE_MEDIA
:
1283 case DIAG_PASS_THRU
:
1284 p
= kmalloc(io
->sg
[0].size
, GFP_KERNEL
);
1291 copy_from_user(p
, (void*)io
->sg
[0].addr
, io
->sg
[0].size
);
1292 c
->req
.sg
[0].size
= io
->sg
[0].size
;
1293 c
->req
.sg
[0].addr
= virt_to_bus(p
);
1294 c
->req
.hdr
.sg_cnt
= 1;
1297 c
->req
.sg
[0].size
= sizeof(io
->c
);
1298 c
->req
.sg
[0].addr
= virt_to_bus(&io
->c
);
1299 c
->req
.hdr
.sg_cnt
= 1;
1302 /* Put the request on the tail of the request queue */
1303 spin_lock_irqsave(&io_request_lock
, flags
);
1307 spin_unlock_irqrestore(&io_request_lock
, flags
);
1309 /* Wait for completion */
1310 while(c
->type
!= CMD_IOCTL_DONE
)
1313 /* Post submit processing */
1317 case DIAG_PASS_THRU
:
1318 copy_to_user((void*)io
->sg
[0].addr
, p
, io
->sg
[0].size
);
1319 /* fall through and free p */
1321 case IDA_WRITE_MEDIA
:
1328 io
->rcode
= c
->req
.hdr
.rcode
;
1334 * Commands are pre-allocated in a large block. Here we use a simple bitmap
1335 * scheme to suballocte them to the driver. Operations that are not time
1336 * critical (and can wait for kmalloc and possibly sleep) can pass in NULL
1337 * as the first argument to get a new command.
1339 static cmdlist_t
* cmd_alloc(ctlr_info_t
*h
)
1345 c
= (cmdlist_t
*)kmalloc(sizeof(cmdlist_t
), GFP_KERNEL
);
1350 i
= find_first_zero_bit(h
->cmd_pool_bits
, NR_CMDS
);
1353 } while(test_and_set_bit(i
%32, h
->cmd_pool_bits
+(i
/32)) != 0);
1354 c
= h
->cmd_pool
+ i
;
1358 memset(c
, 0, sizeof(cmdlist_t
));
1359 c
->busaddr
= virt_to_bus(c
);
1363 static void cmd_free(ctlr_info_t
*h
, cmdlist_t
*c
)
1370 i
= c
- h
->cmd_pool
;
1371 clear_bit(i
%32, h
->cmd_pool_bits
+(i
/32));
1376 /***********************************************************************
1378 Send a command to an IDA using the memory mapped FIFO interface
1379 and wait for it to complete.
1380 This routine should only be called at init time.
1381 ***********************************************************************/
1388 unsigned int blkcnt
,
1389 unsigned int log_unit
)
1395 ctlr_info_t
*info_p
= hba
[ctlr
];
1397 c
= cmd_alloc(info_p
);
1401 c
->hdr
.unit
= log_unit
;
1403 c
->hdr
.size
= sizeof(rblk_t
) >> 2;
1404 c
->size
+= sizeof(rblk_t
);
1406 /* The request information. */
1407 c
->req
.hdr
.next
= 0;
1408 c
->req
.hdr
.rcode
= 0;
1410 c
->req
.hdr
.sg_cnt
= 1;
1411 c
->req
.hdr
.reserved
= 0;
1414 c
->req
.sg
[0].size
= 512;
1416 c
->req
.sg
[0].size
= size
;
1418 c
->req
.hdr
.blk
= blk
;
1419 c
->req
.hdr
.blk_cnt
= blkcnt
;
1420 c
->req
.hdr
.cmd
= (unsigned char) cmd
;
1421 c
->req
.sg
[0].addr
= (__u32
) virt_to_bus(buff
);
1425 info_p
->access
.set_intr_mask(info_p
, 0);
1426 /* Make sure there is room in the command FIFO */
1427 /* Actually it should be completely empty at this time. */
1428 for (i
= 200000; i
> 0; i
--) {
1429 temp
= info_p
->access
.fifo_full(info_p
);
1435 printk(KERN_WARNING
"cpqarray ida%d: idaSendPciCmd FIFO full,"
1436 " waiting!\n", ctlr
);
1442 info_p
->access
.submit_command(info_p
, c
);
1443 complete
= pollcomplete(ctlr
);
1444 if (complete
!= 1) {
1445 if (complete
!= c
->busaddr
) {
1446 printk( KERN_WARNING
1447 "cpqarray ida%d: idaSendPciCmd "
1448 "Invalid command list address returned! (%08lx)\n",
1449 ctlr
, (unsigned long)complete
);
1450 cmd_free(info_p
, c
);
1454 printk( KERN_WARNING
1455 "cpqarray ida%d: idaSendPciCmd Timeout out, "
1456 "No command list address returned!\n",
1458 cmd_free(info_p
, c
);
1462 if (c
->req
.hdr
.rcode
& 0x00FE) {
1463 if (!(c
->req
.hdr
.rcode
& BIG_PROBLEM
)) {
1464 printk( KERN_WARNING
1465 "cpqarray ida%d: idaSendPciCmd, error: "
1466 "Controller failed at init time "
1467 "cmd: 0x%x, return code = 0x%x\n",
1468 ctlr
, c
->req
.hdr
.cmd
, c
->req
.hdr
.rcode
);
1470 cmd_free(info_p
, c
);
1474 cmd_free(info_p
, c
);
1478 static int frevalidate_logvol(kdev_t dev
)
1480 return revalidate_logvol(dev
, 0);
1484 * revalidate_allvol is for online array config utilities. After a
1485 * utility reconfigures the drives in the array, it can use this function
1486 * (through an ioctl) to make the driver zap any previous disk structs for
1487 * that controller and get new ones.
1489 * Right now I'm using the getgeometry() function to do this, but this
1490 * function should probably be finer grained and allow you to revalidate one
1491 * particualar logical volume (instead of all of them on a particular
1494 static int revalidate_allvol(kdev_t dev
)
1497 unsigned long flags
;
1499 ctlr
= MAJOR(dev
) - MAJOR_NR
;
1500 if (MINOR(dev
) != 0)
1503 spin_lock_irqsave(&io_request_lock
, flags
);
1504 if (hba
[ctlr
]->usage_count
> 1) {
1505 spin_unlock_irqrestore(&io_request_lock
, flags
);
1506 printk(KERN_WARNING
"cpqarray: Device busy for volume"
1507 " revalidation (usage=%d)\n", hba
[ctlr
]->usage_count
);
1510 spin_unlock_irqrestore(&io_request_lock
, flags
);
1511 hba
[ctlr
]->usage_count
++;
1514 * Set the partition and block size structures for all volumes
1515 * on this controller to zero. We will reread all of this data
1517 memset(ida
+(ctlr
*256), 0, sizeof(struct hd_struct
)*NWD
*16);
1518 memset(ida_sizes
+(ctlr
*256), 0, sizeof(int)*NWD
*16);
1519 memset(ida_blocksizes
+(ctlr
*256), 0, sizeof(int)*NWD
*16);
1520 memset(ida_hardsizes
+(ctlr
*256), 0, sizeof(int)*NWD
*16);
1521 memset(hba
[ctlr
]->drv
, 0, sizeof(drv_info_t
)*NWD
);
1522 ida_gendisk
[ctlr
].nr_real
= 0;
1525 * Tell the array controller not to give us any interupts while
1526 * we check the new geometry. Then turn interrupts back on when
1529 hba
[ctlr
]->access
.set_intr_mask(hba
[ctlr
], 0);
1531 hba
[ctlr
]->access
.set_intr_mask(hba
[ctlr
], FIFO_NOT_EMPTY
);
1534 for(i
=0; i
<NWD
; i
++)
1535 if (ida_sizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)])
1536 revalidate_logvol(dev
+(i
<<NWD_SHIFT
), 2);
1538 hba
[ctlr
]->usage_count
--;
1542 /* Borrowed and adapted from sd.c */
1543 static int revalidate_logvol(kdev_t dev
, int maxusage
)
1546 struct gendisk
*gdev
;
1547 unsigned long flags
;
1552 target
= DEVICE_NR(dev
);
1553 ctlr
= MAJOR(dev
) - MAJOR_NR
;
1554 gdev
= &ida_gendisk
[ctlr
];
1556 spin_lock_irqsave(&io_request_lock
, flags
);
1557 if (hba
[ctlr
]->drv
[target
].usage_count
> maxusage
) {
1558 spin_unlock_irqrestore(&io_request_lock
, flags
);
1559 printk(KERN_WARNING
"cpqarray: Device busy for "
1560 "revalidation (usage=%d)\n",
1561 hba
[ctlr
]->drv
[target
].usage_count
);
1565 hba
[ctlr
]->drv
[target
].usage_count
++;
1566 spin_unlock_irqrestore(&io_request_lock
, flags
);
1568 max_p
= gdev
->max_p
;
1569 start
= target
<< gdev
->minor_shift
;
1571 for(i
=max_p
; i
>=0; i
--) {
1572 int minor
= start
+i
;
1573 kdev_t devi
= MKDEV(MAJOR_NR
+ ctlr
, minor
);
1574 struct super_block
*sb
= get_super(devi
);
1576 if (sb
) invalidate_inodes(sb
);
1577 invalidate_buffers(devi
);
1578 gdev
->part
[minor
].start_sect
= 0;
1579 gdev
->part
[minor
].nr_sects
= 0;
1581 /* reset the blocksize so we can read the partition table */
1582 blksize_size
[MAJOR_NR
+ctlr
][minor
] = 1024;
1585 /* 16 minors per disk... */
1586 grok_partitions(gdev
, target
, 16, hba
[ctlr
]->drv
[target
].nr_blks
);
1587 hba
[ctlr
]->drv
[target
].usage_count
--;
1592 /********************************************************************
1594 Wait polling for a command to complete.
1595 The memory mapped FIFO is polled for the completion.
1596 Used only at init time, interrupts disabled.
1597 ********************************************************************/
1598 static int pollcomplete(int ctlr
)
1603 /* Wait (up to 2 seconds) for a command to complete */
1605 for (i
= 200000; i
> 0; i
--) {
1606 done
= hba
[ctlr
]->access
.command_completed(hba
[ctlr
]);
1608 udelay(10); /* a short fixed delay */
1612 /* Invalid address to tell caller we ran out of time */
1615 /*****************************************************************
1617 Starts controller firmwares background processing.
1618 Currently only the Integrated Raid controller needs this done.
1619 If the PCI mem address registers are written to after this,
1620 data corruption may occur
1621 *****************************************************************/
1622 static void start_fwbk(int ctlr
)
1624 id_ctlr_t
*id_ctlr_buf
;
1627 if( (hba
[ctlr
]->board_id
!= 0x40400E11)
1628 && (hba
[ctlr
]->board_id
!= 0x40480E11) )
1630 /* Not a Integrated Raid, so there is nothing for us to do */
1632 printk(KERN_DEBUG
"cpqarray: Starting firmware's background"
1634 /* Command does not return anything, but idasend command needs a
1636 id_ctlr_buf
= (id_ctlr_t
*)kmalloc(sizeof(id_ctlr_t
), GFP_KERNEL
);
1637 if(id_ctlr_buf
==NULL
)
1639 printk(KERN_WARNING
"cpqarray: Out of memory. "
1640 "Unable to start background processing.\n");
1643 ret_code
= sendcmd(RESUME_BACKGROUND_ACTIVITY
, ctlr
,
1644 id_ctlr_buf
, 0, 0, 0, 0);
1645 if(ret_code
!= IO_OK
)
1646 printk(KERN_WARNING
"cpqarray: Unable to start"
1647 " background processing\n");
1651 /*****************************************************************
1653 Get ida logical volume geometry from the controller
1654 This is a large bit of code which once existed in two flavors,
1655 It is used only at init time.
1656 *****************************************************************/
1657 static void getgeometry(int ctlr
)
1659 id_log_drv_t
*id_ldrive
;
1660 id_ctlr_t
*id_ctlr_buf
;
1661 sense_log_drv_stat_t
*id_lstatus_buf
;
1662 config_t
*sense_config_buf
;
1663 unsigned int log_unit
, log_index
;
1666 ctlr_info_t
*info_p
= hba
[ctlr
];
1669 info_p
->log_drv_map
= 0;
1671 id_ldrive
= (id_log_drv_t
*)kmalloc(sizeof(id_log_drv_t
), GFP_KERNEL
);
1672 if(id_ldrive
== NULL
)
1674 printk( KERN_ERR
"cpqarray: out of memory.\n");
1678 id_ctlr_buf
= (id_ctlr_t
*)kmalloc(sizeof(id_ctlr_t
), GFP_KERNEL
);
1679 if(id_ctlr_buf
== NULL
)
1682 printk( KERN_ERR
"cpqarray: out of memory.\n");
1686 id_lstatus_buf
= (sense_log_drv_stat_t
*)kmalloc(sizeof(sense_log_drv_stat_t
), GFP_KERNEL
);
1687 if(id_lstatus_buf
== NULL
)
1691 printk( KERN_ERR
"cpqarray: out of memory.\n");
1695 sense_config_buf
= (config_t
*)kmalloc(sizeof(config_t
), GFP_KERNEL
);
1696 if(sense_config_buf
== NULL
)
1698 kfree(id_lstatus_buf
);
1701 printk( KERN_ERR
"cpqarray: out of memory.\n");
1705 memset(id_ldrive
, 0, sizeof(id_log_drv_t
));
1706 memset(id_ctlr_buf
, 0, sizeof(id_ctlr_t
));
1707 memset(id_lstatus_buf
, 0, sizeof(sense_log_drv_stat_t
));
1708 memset(sense_config_buf
, 0, sizeof(config_t
));
1710 info_p
->phys_drives
= 0;
1711 info_p
->log_drv_map
= 0;
1712 info_p
->drv_assign_map
= 0;
1713 info_p
->drv_spare_map
= 0;
1714 info_p
->mp_failed_drv_map
= 0; /* only initialized here */
1715 /* Get controllers info for this logical drive */
1716 ret_code
= sendcmd(ID_CTLR
, ctlr
, id_ctlr_buf
, 0, 0, 0, 0);
1717 if (ret_code
== IO_ERROR
) {
1719 * If can't get controller info, set the logical drive map to 0,
1720 * so the idastubopen will fail on all logical drives
1721 * on the controller.
1723 /* Free all the buffers and return */
1724 printk(KERN_ERR
"cpqarray: error sending ID controller\n");
1725 kfree(sense_config_buf
);
1726 kfree(id_lstatus_buf
);
1732 info_p
->log_drives
= id_ctlr_buf
->nr_drvs
;;
1734 info_p
->firm_rev
[i
] = id_ctlr_buf
->firm_rev
[i
];
1735 info_p
->ctlr_sig
= id_ctlr_buf
->cfg_sig
;
1737 printk(" (%s)\n", info_p
->product_name
);
1739 * Initialize logical drive map to zero
1743 * Get drive geometry for all logical drives
1745 if (id_ctlr_buf
->nr_drvs
> 16)
1746 printk(KERN_WARNING
"cpqarray ida%d: This driver supports "
1747 "16 logical drives per controller.\n. "
1748 " Additional drives will not be "
1749 "detected\n", ctlr
);
1752 (log_index
< id_ctlr_buf
->nr_drvs
)
1753 && (log_unit
< NWD
);
1756 size
= sizeof(sense_log_drv_stat_t
);
1759 Send "Identify logical drive status" cmd
1761 ret_code
= sendcmd(SENSE_LOG_DRV_STAT
,
1762 ctlr
, id_lstatus_buf
, size
, 0, 0, log_unit
);
1763 if (ret_code
== IO_ERROR
) {
1765 If can't get logical drive status, set
1766 the logical drive map to 0, so the
1767 idastubopen will fail for all logical drives
1770 info_p
->log_drv_map
= 0;
1771 printk( KERN_WARNING
1772 "cpqarray ida%d: idaGetGeometry - Controller"
1773 " failed to report status of logical drive %d\n"
1774 "Access to this controller has been disabled\n",
1776 /* Free all the buffers and return */
1777 kfree(sense_config_buf
);
1778 kfree(id_lstatus_buf
);
1784 Make sure the logical drive is configured
1786 if (id_lstatus_buf
->status
!= LOG_NOT_CONF
) {
1787 ret_code
= sendcmd(ID_LOG_DRV
, ctlr
, id_ldrive
,
1788 sizeof(id_log_drv_t
), 0, 0, log_unit
);
1790 If error, the bit for this
1791 logical drive won't be set and
1792 idastubopen will return error.
1794 if (ret_code
!= IO_ERROR
) {
1795 drv
= &info_p
->drv
[log_unit
];
1796 drv
->blk_size
= id_ldrive
->blk_size
;
1797 drv
->nr_blks
= id_ldrive
->nr_blks
;
1798 drv
->cylinders
= id_ldrive
->drv
.cyl
;
1799 drv
->heads
= id_ldrive
->drv
.heads
;
1800 drv
->sectors
= id_ldrive
->drv
.sect_per_track
;
1801 info_p
->log_drv_map
|= (1 << log_unit
);
1803 printk(KERN_INFO
"cpqarray ida/c%dd%d: blksz=%d nr_blks=%d\n",
1804 ctlr
, log_unit
, drv
->blk_size
, drv
->nr_blks
);
1805 ret_code
= sendcmd(SENSE_CONFIG
,
1806 ctlr
, sense_config_buf
,
1807 sizeof(config_t
), 0, 0, log_unit
);
1808 if (ret_code
== IO_ERROR
) {
1809 info_p
->log_drv_map
= 0;
1810 /* Free all the buffers and return */
1811 printk(KERN_ERR
"cpqarray: error sending sense config\n");
1812 kfree(sense_config_buf
);
1813 kfree(id_lstatus_buf
);
1819 info_p
->phys_drives
=
1820 sense_config_buf
->ctlr_phys_drv
;
1821 info_p
->drv_assign_map
1822 |= sense_config_buf
->drv_asgn_map
;
1823 info_p
->drv_assign_map
1824 |= sense_config_buf
->spare_asgn_map
;
1825 info_p
->drv_spare_map
1826 |= sense_config_buf
->spare_asgn_map
;
1827 } /* end of if no error on id_ldrive */
1828 log_index
= log_index
+ 1;
1829 } /* end of if logical drive configured */
1830 } /* end of for log_unit */
1831 kfree(sense_config_buf
);
1833 kfree(id_lstatus_buf
);