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 remove_proc_entry(hba
[i
]->devname
, proc_array
);
335 kfree(hba
[i
]->cmd_pool
);
336 kfree(hba
[i
]->cmd_pool_bits
);
338 if (gendisk_head
== &ida_gendisk
[i
]) {
339 gendisk_head
= ida_gendisk
[i
].next
;
341 for(g
=gendisk_head
; g
; g
=g
->next
) {
342 if (g
->next
== &ida_gendisk
[i
]) {
343 g
->next
= ida_gendisk
[i
].next
;
352 kfree(ida_hardsizes
);
353 kfree(ida_blocksizes
);
358 * This is it. Find all the controllers and register them. I really hate
359 * stealing all these major device numbers.
360 * returns the number of block devices registered.
362 int __init
cpqarray_init(void)
364 void (*request_fns
[MAX_CTLR
])(request_queue_t
*) = {
365 do_ida_request0
, do_ida_request1
,
366 do_ida_request2
, do_ida_request3
,
367 do_ida_request4
, do_ida_request5
,
368 do_ida_request6
, do_ida_request7
,
371 int num_cntlrs_reg
= 0;
373 /* detect controllers */
374 cpqarray_pci_detect();
375 cpqarray_eisa_detect();
378 return(num_cntlrs_reg
);
380 printk(DRIVER_NAME
"\n");
381 printk("Found %d controller(s)\n", nr_ctlr
);
383 /* allocate space for disk structs */
384 ida
= kmalloc(sizeof(struct hd_struct
)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
387 printk( KERN_ERR
"cpqarray: out of memory");
388 return(num_cntlrs_reg
);
391 ida_sizes
= kmalloc(sizeof(int)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
395 printk( KERN_ERR
"cpqarray: out of memory");
396 return(num_cntlrs_reg
);
399 ida_blocksizes
= kmalloc(sizeof(int)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
400 if(ida_blocksizes
==NULL
)
404 printk( KERN_ERR
"cpqarray: out of memory");
405 return(num_cntlrs_reg
);
408 ida_hardsizes
= kmalloc(sizeof(int)*nr_ctlr
*NWD
*16, GFP_KERNEL
);
409 if(ida_hardsizes
==NULL
)
413 kfree(ida_blocksizes
);
414 printk( KERN_ERR
"cpqarray: out of memory");
415 return(num_cntlrs_reg
);
418 memset(ida
, 0, sizeof(struct hd_struct
)*nr_ctlr
*NWD
*16);
419 memset(ida_sizes
, 0, sizeof(int)*nr_ctlr
*NWD
*16);
420 memset(ida_blocksizes
, 0, sizeof(int)*nr_ctlr
*NWD
*16);
421 memset(ida_hardsizes
, 0, sizeof(int)*nr_ctlr
*NWD
*16);
422 memset(ida_gendisk
, 0, sizeof(struct gendisk
)*MAX_CTLR
);
425 * register block devices
426 * Find disks and fill in structs
427 * Get an interrupt, set the Q depth and get into /proc
429 for(i
=0; i
< nr_ctlr
; i
++) {
430 /* If this successful it should insure that we are the only */
431 /* instance of the driver */
432 if (register_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
, &ida_fops
)) {
433 printk(KERN_ERR
"cpqarray: Unable to get major number %d for ida\n",
439 hba
[i
]->access
.set_intr_mask(hba
[i
], 0);
440 if (request_irq(hba
[i
]->intr
, do_ida_intr
,
441 SA_INTERRUPT
|SA_SHIRQ
, hba
[i
]->devname
, hba
[i
])) {
443 printk(KERN_ERR
"cpqarray: Unable to get irq %d for %s\n",
444 hba
[i
]->intr
, hba
[i
]->devname
);
445 unregister_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
);
449 hba
[i
]->cmd_pool
= (cmdlist_t
*)kmalloc(
450 NR_CMDS
* sizeof(cmdlist_t
), GFP_KERNEL
);
451 hba
[i
]->cmd_pool_bits
= (__u32
*)kmalloc(
452 ((NR_CMDS
+31)/32)*sizeof(__u32
), GFP_KERNEL
);
454 if(hba
[i
]->cmd_pool_bits
== NULL
|| hba
[i
]->cmd_pool
== NULL
)
457 if(hba
[i
]->cmd_pool_bits
)
458 kfree(hba
[i
]->cmd_pool_bits
);
460 kfree(hba
[i
]->cmd_pool
);
461 free_irq(hba
[i
]->intr
, hba
[i
]);
462 unregister_blkdev(MAJOR_NR
+i
, hba
[i
]->devname
);
464 printk( KERN_ERR
"cpqarray: out of memory");
466 /* If num_cntlrs_reg == 0, no controllers worked.
467 * init_module will fail, so clean up global
468 * memory that clean_module would do.
471 if (num_cntlrs_reg
== 0)
475 kfree(ida_hardsizes
);
476 kfree(ida_blocksizes
);
478 return(num_cntlrs_reg
);
481 memset(hba
[i
]->cmd_pool
, 0, NR_CMDS
* sizeof(cmdlist_t
));
482 memset(hba
[i
]->cmd_pool_bits
, 0, ((NR_CMDS
+31)/32)*sizeof(__u32
));
483 printk(KERN_INFO
"cpqarray: Finding drives on %s",
488 hba
[i
]->access
.set_intr_mask(hba
[i
], FIFO_NOT_EMPTY
);
493 blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR
+ i
),
495 blk_queue_headactive(BLK_DEFAULT_QUEUE(MAJOR_NR
+ i
), 0);
496 blksize_size
[MAJOR_NR
+i
] = ida_blocksizes
+ (i
*256);
497 hardsect_size
[MAJOR_NR
+i
] = ida_hardsizes
+ (i
*256);
498 read_ahead
[MAJOR_NR
+i
] = READ_AHEAD
;
500 ida_gendisk
[i
].major
= MAJOR_NR
+ i
;
501 ida_gendisk
[i
].major_name
= "ida";
502 ida_gendisk
[i
].minor_shift
= NWD_SHIFT
;
503 ida_gendisk
[i
].max_p
= 16;
504 ida_gendisk
[i
].part
= ida
+ (i
*256);
505 ida_gendisk
[i
].sizes
= ida_sizes
+ (i
*256);
506 ida_gendisk
[i
].nr_real
= 0;
508 /* Get on the disk list */
509 ida_gendisk
[i
].next
= gendisk_head
;
510 gendisk_head
= &ida_gendisk
[i
];
512 init_timer(&hba
[i
]->timer
);
513 hba
[i
]->timer
.expires
= jiffies
+ IDA_TIMER
;
514 hba
[i
]->timer
.data
= (unsigned long)hba
[i
];
515 hba
[i
]->timer
.function
= ida_timer
;
516 add_timer(&hba
[i
]->timer
);
520 register_disk(&ida_gendisk
[i
],
521 MKDEV(MAJOR_NR
+i
,j
<<4),
522 16, &ida_fops
, hba
[i
]->drv
[j
].nr_blks
);
526 return(num_cntlrs_reg
);
530 * Find the controller and initialize it
531 * Cannot use the class code to search, because older array controllers use
532 * 0x018000 and new ones use 0x010400. So I might as well search for each
533 * each device IDs, being there are only going to be three of them.
535 static int cpqarray_pci_detect(void)
538 unchar bus
=0, dev_fn
=0;
540 #define IDA_BOARD_TYPES 3
541 static int ida_vendor_id
[IDA_BOARD_TYPES
] = { PCI_VENDOR_ID_DEC
,
542 PCI_VENDOR_ID_NCR
, PCI_VENDOR_ID_COMPAQ
};
543 static int ida_device_id
[IDA_BOARD_TYPES
] = { PCI_DEVICE_ID_COMPAQ_42XX
, PCI_DEVICE_ID_NCR_53C1510
, PCI_DEVICE_ID_COMPAQ_SMART2P
};
546 /* search for all PCI board types that could be for this driver */
547 for(brdtype
=0; brdtype
<IDA_BOARD_TYPES
; brdtype
++)
549 for(index
=0; ; index
++) {
550 if (pcibios_find_device(ida_vendor_id
[brdtype
],
551 ida_device_id
[brdtype
], index
, &bus
, &dev_fn
))
553 printk(KERN_DEBUG
"cpqarray: Device %x has been found at %x %x\n",
554 ida_vendor_id
[brdtype
], bus
, dev_fn
);
555 if (index
== 1000000) break;
557 printk(KERN_WARNING
"cpqarray: This driver"
558 " supports a maximum of 8 controllers.\n");
562 /* if it is a PCI_DEVICE_ID_NCR_53C1510, make sure it's the Compaq version of the chip */
564 if (ida_device_id
[brdtype
] == PCI_DEVICE_ID_NCR_53C1510
) {
565 unsigned short subvendor
=0;
566 if(pcibios_read_config_word(bus
, dev_fn
,
567 PCI_SUBSYSTEM_VENDOR_ID
, &subvendor
))
569 printk(KERN_DEBUG
"cpqarray: failed to read subvendor\n");
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
], bus
, dev_fn
) != 0)
591 sprintf(hba
[nr_ctlr
]->devname
, "ida%d", nr_ctlr
);
592 hba
[nr_ctlr
]->ctlr
= nr_ctlr
;
602 * Find the IO address of the controller, its IRQ and so forth. Fill
603 * in some basic stuff into the ctlr_info_t structure.
605 static int cpqarray_pci_init(ctlr_info_t
*c
, unchar bus
, unchar device_fn
)
607 ushort vendor_id
, device_id
, command
;
608 unchar cache_line_size
, latency_timer
;
609 unchar irq
, revision
;
612 struct pci_dev
*pdev
;
616 pdev
= pci_find_slot(bus
, device_fn
);
617 vendor_id
= pdev
->vendor
;
618 device_id
= pdev
->device
;
622 addr
[i
] = pdev
->resource
[i
].flags
;
624 if (pci_enable_device(pdev
))
627 pci_read_config_word(pdev
, PCI_COMMAND
, &command
);
628 pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &revision
);
629 pci_read_config_byte(pdev
, PCI_CACHE_LINE_SIZE
, &cache_line_size
);
630 pci_read_config_byte(pdev
, PCI_LATENCY_TIMER
, &latency_timer
);
632 pci_read_config_dword(pdev
, 0x2c, &board_id
);
635 printk("vendor_id = %x\n", vendor_id
);
636 printk("device_id = %x\n", device_id
);
637 printk("command = %x\n", command
);
639 printk("addr[%d] = %x\n", i
, addr
[i
]);
640 printk("revision = %x\n", revision
);
641 printk("irq = %x\n", irq
);
642 printk("cache_line_size = %x\n", cache_line_size
);
643 printk("latency_timer = %x\n", latency_timer
);
644 printk("board_id = %x\n", board_id
);
648 c
->ioaddr
= addr
[0] & ~0x1;
651 * Memory base addr is first addr with the first bit _not_ set
654 if (!(addr
[i
] & 0x1)) {
655 c
->paddr
= pci_resource_start (pdev
, i
);
658 c
->vaddr
= remap_pci_mem(c
->paddr
, 128);
659 c
->board_id
= board_id
;
661 for(i
=0; i
<NR_PRODUCTS
; i
++) {
662 if (board_id
== products
[i
].board_id
) {
663 c
->product_name
= products
[i
].product_name
;
664 c
->access
= *(products
[i
].access
);
668 if (i
== NR_PRODUCTS
) {
669 printk(KERN_WARNING
"cpqarray: Sorry, I don't know how"
670 " to access the SMART Array controller %08lx\n",
671 (unsigned long)board_id
);
679 * Map (physical) PCI mem into (virtual) kernel space
681 static ulong
remap_pci_mem(ulong base
, ulong size
)
683 ulong page_base
= ((ulong
) base
) & PAGE_MASK
;
684 ulong page_offs
= ((ulong
) base
) - page_base
;
685 ulong page_remapped
= (ulong
) ioremap(page_base
, page_offs
+size
);
687 return (ulong
) (page_remapped
? (page_remapped
+ page_offs
) : 0UL);
691 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,13)
693 * Config string is a comma seperated set of i/o addresses of EISA cards.
695 static int cpqarray_setup(char *str
)
699 (void)get_options(str
, ARRAY_SIZE(ints
), ints
);
701 for(i
=0; i
<ints
[0] && i
<8; i
++)
706 __setup("smart2=", cpqarray_setup
);
711 * Copy the contents of the ints[] array passed to us by init.
713 void cpqarray_setup(char *str
, int *ints
)
716 for(i
=0; i
<ints
[0] && i
<8; i
++)
723 * Find an EISA controller's signature. Set up an hba if we find it.
725 static int cpqarray_eisa_detect(void)
731 while(i
<8 && eisa
[i
]) {
733 printk(KERN_WARNING
"cpqarray: This driver supports"
734 " a maximum of 8 controllers.\n");
737 board_id
= inl(eisa
[i
]+0xC80);
738 for(j
=0; j
< NR_PRODUCTS
; j
++)
739 if (board_id
== products
[j
].board_id
)
742 if (j
== NR_PRODUCTS
) {
743 printk(KERN_WARNING
"cpqarray: Sorry, I don't know how"
744 " to access the SMART Array controller %08lx\n", (unsigned long)board_id
);
747 hba
[nr_ctlr
] = (ctlr_info_t
*) kmalloc(sizeof(ctlr_info_t
), GFP_KERNEL
);
748 if(hba
[nr_ctlr
]==NULL
)
750 printk(KERN_ERR
"cpqarray: out of memory.\n");
753 memset(hba
[nr_ctlr
], 0, sizeof(ctlr_info_t
));
754 hba
[nr_ctlr
]->ioaddr
= eisa
[i
];
757 * Read the config register to find our interrupt
759 intr
= inb(eisa
[i
]+0xCC0) >> 4;
760 if (intr
& 1) intr
= 11;
761 else if (intr
& 2) intr
= 10;
762 else if (intr
& 4) intr
= 14;
763 else if (intr
& 8) intr
= 15;
765 hba
[nr_ctlr
]->intr
= intr
;
766 sprintf(hba
[nr_ctlr
]->devname
, "ida%d", nr_ctlr
);
767 hba
[nr_ctlr
]->product_name
= products
[j
].product_name
;
768 hba
[nr_ctlr
]->access
= *(products
[j
].access
);
769 hba
[nr_ctlr
]->ctlr
= nr_ctlr
;
770 hba
[nr_ctlr
]->board_id
= board_id
;
773 printk("i = %d, j = %d\n", i
, j
);
774 printk("irq = %x\n", intr
);
775 printk("product name = %s\n", products
[j
].product_name
);
776 printk("board_id = %x\n", board_id
);
788 * Open. Make sure the device is really there.
790 static int ida_open(struct inode
*inode
, struct file
*filep
)
792 int ctlr
= MAJOR(inode
->i_rdev
) - MAJOR_NR
;
793 int dsk
= MINOR(inode
->i_rdev
) >> NWD_SHIFT
;
795 DBGINFO(printk("ida_open %x (%x:%x)\n", inode
->i_rdev
, ctlr
, dsk
) );
796 if (ctlr
> MAX_CTLR
|| hba
[ctlr
] == NULL
)
799 if (!suser() && ida_sizes
[(ctlr
<< CTLR_SHIFT
) +
800 MINOR(inode
->i_rdev
)] == 0)
804 * Root is allowed to open raw volume zero even if its not configured
805 * so array config can still work. I don't think I really like this,
806 * but I'm already using way to many device nodes to claim another one
807 * for "raw controller".
810 && ida_sizes
[(ctlr
<< CTLR_SHIFT
) + MINOR(inode
->i_rdev
)] == 0
811 && MINOR(inode
->i_rdev
) != 0)
814 hba
[ctlr
]->drv
[dsk
].usage_count
++;
815 hba
[ctlr
]->usage_count
++;
823 static int ida_release(struct inode
*inode
, struct file
*filep
)
825 int ctlr
= MAJOR(inode
->i_rdev
) - MAJOR_NR
;
826 int dsk
= MINOR(inode
->i_rdev
) >> NWD_SHIFT
;
828 DBGINFO(printk("ida_release %x (%x:%x)\n", inode
->i_rdev
, ctlr
, dsk
) );
830 hba
[ctlr
]->drv
[dsk
].usage_count
--;
831 hba
[ctlr
]->usage_count
--;
837 * Enqueuing and dequeuing functions for cmdlists.
839 static inline void addQ(cmdlist_t
**Qptr
, cmdlist_t
*c
)
843 c
->next
= c
->prev
= c
;
845 c
->prev
= (*Qptr
)->prev
;
847 (*Qptr
)->prev
->next
= c
;
852 static inline cmdlist_t
*removeQ(cmdlist_t
**Qptr
, cmdlist_t
*c
)
854 if (c
&& c
->next
!= c
) {
855 if (*Qptr
== c
) *Qptr
= c
->next
;
856 c
->prev
->next
= c
->next
;
857 c
->next
->prev
= c
->prev
;
865 * Get a request and submit it to the controller.
866 * This routine needs to grab all the requests it possibly can from the
867 * req Q and submit them. Interrupts are off (and need to be off) when you
868 * are in here (either via the dummy do_ida_request functions or by being
869 * called from the interrupt handler
871 static void do_ida_request(int ctlr
)
873 ctlr_info_t
*h
= hba
[ctlr
];
877 struct list_head
* queue_head
;
878 struct buffer_head
*bh
;
879 struct request
*creq
;
881 queue_head
= &blk_dev
[MAJOR_NR
+ctlr
].request_queue
.queue_head
;
883 if (list_empty(queue_head
))
889 creq
= blkdev_entry_next_request(queue_head
);
890 if (creq
->rq_status
== RQ_INACTIVE
)
897 if (ctlr
!= MAJOR(creq
->rq_dev
)-MAJOR_NR
||
898 ctlr
> nr_ctlr
|| h
== NULL
)
900 printk("doreq cmd for %d, %x at %p\n",
901 ctlr
, creq
->rq_dev
, creq
);
902 complete_buffers(creq
->bh
, 0);
907 if ((c
= cmd_alloc(h
)) == NULL
)
916 c
->hdr
.unit
= MINOR(creq
->rq_dev
) >> NWD_SHIFT
;
917 c
->hdr
.size
= sizeof(rblk_t
) >> 2;
918 c
->size
+= sizeof(rblk_t
);
920 c
->req
.hdr
.blk
= ida
[(ctlr
<<CTLR_SHIFT
) + MINOR(creq
->rq_dev
)].start_sect
+ creq
->sector
;
924 panic("bh == NULL?");
926 printk("sector=%d, nr_sectors=%d\n", creq
->sector
, creq
->nr_sectors
);
928 seg
= 0; lastdataend
= NULL
;
931 sect
+= bh
->b_size
/512;
933 if (bh
->b_size
% 512) {
934 printk("Oh damn. %d+%d, size = %d\n", creq
->sector
, sect
, bh
->b_size
);
935 panic("b_size %% 512 != 0");
938 if (bh
->b_data
== lastdataend
) {
939 c
->req
.sg
[seg
-1].size
+= bh
->b_size
;
940 lastdataend
+= bh
->b_size
;
942 c
->req
.sg
[seg
].size
= bh
->b_size
;
943 c
->req
.sg
[seg
].addr
= (__u32
)virt_to_bus(bh
->b_data
);
944 lastdataend
= bh
->b_data
+ bh
->b_size
;
950 DBGPX( printk("Submitting %d sectors in %d segments\n", sect
, seg
); );
951 c
->req
.hdr
.sg_cnt
= seg
;
952 c
->req
.hdr
.blk_cnt
= sect
;
954 creq
->sector
+= sect
;
955 creq
->nr_sectors
-= sect
;
957 /* Ready the next request:
958 * Fix up creq if we still have more buffers in the buffer chain, or
959 * mark this request as done and ready the next one.
961 if (creq
->nr_sectors
) {
964 printk("sector=%d, nr_sectors=%d, sect=%d, seg=%d\n",
965 creq
->sector
, creq
->nr_sectors
, sect
, seg
);
969 creq
->bh
= bh
->b_reqnext
;
970 bh
->b_reqnext
= NULL
;
971 DBGPX( printk("More to do on same request %p\n", creq
); );
973 DBGPX( printk("Done with %p\n", creq
); );
974 blkdev_dequeue_request(creq
);
975 end_that_request_last(creq
);
978 c
->req
.hdr
.cmd
= (creq
->cmd
== READ
) ? IDA_READ
: IDA_WRITE
;
981 /* Put the request on the tail of the request queue */
984 if (h
->Qdepth
> h
->maxQsinceinit
)
985 h
->maxQsinceinit
= h
->Qdepth
;
991 * start_io submits everything on a controller's request queue
992 * and moves it to the completion queue.
994 * Interrupts had better be off if you're in here
996 static void start_io(ctlr_info_t
*h
)
1000 while((c
= h
->reqQ
) != NULL
) {
1001 /* Can't do anything if we're busy */
1002 if (h
->access
.fifo_full(h
) == 0)
1005 /* Get the first entry from the request Q */
1006 removeQ(&h
->reqQ
, c
);
1009 /* Tell the controller to do our bidding */
1010 h
->access
.submit_command(h
, c
);
1012 /* Get onto the completion Q */
1017 static inline void complete_buffers(struct buffer_head
*bh
, int ok
)
1019 struct buffer_head
*xbh
;
1021 xbh
= bh
->b_reqnext
;
1022 bh
->b_reqnext
= NULL
;
1024 bh
->b_end_io(bh
, ok
);
1030 * Mark all buffers that cmd was responsible for
1032 static inline void complete_command(cmdlist_t
*cmd
, int timeout
)
1036 if (cmd
->req
.hdr
.rcode
& RCODE_NONFATAL
&&
1037 (hba
[cmd
->ctlr
]->misc_tflags
& MISC_NONFATAL_WARN
) == 0) {
1038 printk(KERN_WARNING
"Non Fatal error on ida/c%dd%d\n",
1039 cmd
->ctlr
, cmd
->hdr
.unit
);
1040 hba
[cmd
->ctlr
]->misc_tflags
|= MISC_NONFATAL_WARN
;
1042 if (cmd
->req
.hdr
.rcode
& RCODE_FATAL
) {
1043 printk(KERN_WARNING
"Fatal error on ida/c%dd%d\n",
1044 cmd
->ctlr
, cmd
->hdr
.unit
);
1047 if (cmd
->req
.hdr
.rcode
& RCODE_INVREQ
) {
1048 printk(KERN_WARNING
"Invalid request on ida/c%dd%d = (cmd=%x sect=%d cnt=%d sg=%d ret=%x)\n",
1049 cmd
->ctlr
, cmd
->hdr
.unit
, cmd
->req
.hdr
.cmd
,
1050 cmd
->req
.hdr
.blk
, cmd
->req
.hdr
.blk_cnt
,
1051 cmd
->req
.hdr
.sg_cnt
, cmd
->req
.hdr
.rcode
);
1054 if (timeout
) ok
= 0;
1055 complete_buffers(cmd
->bh
, ok
);
1059 * The controller will interrupt us upon completion of commands.
1060 * Find the command on the completion queue, remove it, tell the OS and
1061 * try to queue up more IO
1063 static void do_ida_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
1065 ctlr_info_t
*h
= dev_id
;
1067 unsigned long istat
;
1068 unsigned long flags
;
1072 istat
= h
->access
.intr_pending(h
);
1073 /* Is this interrupt for us? */
1078 * If there are completed commands in the completion queue,
1079 * we had better do something about it.
1081 spin_lock_irqsave(&io_request_lock
, flags
);
1082 if (istat
& FIFO_NOT_EMPTY
) {
1083 while((a
= h
->access
.command_completed(h
))) {
1085 if ((c
= h
->cmpQ
) == NULL
)
1087 printk(KERN_WARNING
"cpqarray: Completion of %08lx ignored\n", (unsigned long)a1
);
1090 while(c
->busaddr
!= a
) {
1096 * If we've found the command, take it off the
1097 * completion Q and free it
1099 if (c
->busaddr
== a
) {
1100 removeQ(&h
->cmpQ
, c
);
1101 if (c
->type
== CMD_RWREQ
) {
1102 complete_command(c
, 0);
1104 } else if (c
->type
== CMD_IOCTL_PEND
) {
1105 c
->type
= CMD_IOCTL_DONE
;
1113 * See if we can queue up some more IO
1115 do_ida_request(h
->ctlr
);
1116 spin_unlock_irqrestore(&io_request_lock
, flags
);
1120 * This timer was for timing out requests that haven't happened after
1121 * IDA_TIMEOUT. That wasn't such a good idea. This timer is used to
1122 * reset a flags structure so we don't flood the user with
1123 * "Non-Fatal error" messages.
1125 static void ida_timer(unsigned long tdata
)
1127 ctlr_info_t
*h
= (ctlr_info_t
*)tdata
;
1129 h
->timer
.expires
= jiffies
+ IDA_TIMER
;
1130 add_timer(&h
->timer
);
1135 * ida_ioctl does some miscellaneous stuff like reporting drive geometry,
1136 * setting readahead and submitting commands from userspace to the controller.
1138 static int ida_ioctl(struct inode
*inode
, struct file
*filep
, unsigned int cmd
, unsigned long arg
)
1140 int ctlr
= MAJOR(inode
->i_rdev
) - MAJOR_NR
;
1141 int dsk
= MINOR(inode
->i_rdev
) >> NWD_SHIFT
;
1144 struct hd_geometry
*geo
= (struct hd_geometry
*)arg
;
1145 ida_ioctl_t
*io
= (ida_ioctl_t
*)arg
;
1150 if (hba
[ctlr
]->drv
[dsk
].cylinders
) {
1151 diskinfo
[0] = hba
[ctlr
]->drv
[dsk
].heads
;
1152 diskinfo
[1] = hba
[ctlr
]->drv
[dsk
].sectors
;
1153 diskinfo
[2] = hba
[ctlr
]->drv
[dsk
].cylinders
;
1157 diskinfo
[2] = hba
[ctlr
]->drv
[dsk
].nr_blks
/ (0xff*0x3f);
1159 put_user(diskinfo
[0], &geo
->heads
);
1160 put_user(diskinfo
[1], &geo
->sectors
);
1161 put_user(diskinfo
[2], &geo
->cylinders
);
1162 put_user(ida
[(ctlr
<<CTLR_SHIFT
)+MINOR(inode
->i_rdev
)].start_sect
, &geo
->start
);
1165 return copy_to_user(&io
->c
.drv
,&hba
[ctlr
]->drv
[dsk
],sizeof(drv_info_t
));
1167 if (!arg
) return -EINVAL
;
1168 put_user(ida
[(ctlr
<<CTLR_SHIFT
)+MINOR(inode
->i_rdev
)].nr_sects
, (long*)arg
);
1171 return revalidate_logvol(inode
->i_rdev
, 1);
1173 if (!suser()) return -EPERM
;
1174 error
= copy_from_user(&my_io
, io
, sizeof(my_io
));
1175 if (error
) return error
;
1176 error
= ida_ctlr_ioctl(ctlr
, dsk
, &my_io
);
1177 if (error
) return error
;
1178 error
= copy_to_user(io
, &my_io
, sizeof(my_io
));
1181 if (!arg
) return -EINVAL
;
1182 put_user(hba
[ctlr
]->ctlr_sig
, (int*)arg
);
1184 case IDAREVALIDATEVOLS
:
1185 return revalidate_allvol(inode
->i_rdev
);
1186 case IDADRIVERVERSION
:
1187 if (!arg
) return -EINVAL
;
1188 put_user(DRIVER_VERSION
, (unsigned long*)arg
);
1197 return blk_ioctl(inode
->i_rdev
, cmd
, arg
);
1205 * ida_ctlr_ioctl is for passing commands to the controller from userspace.
1206 * The command block (io) has already been copied to kernel space for us,
1207 * however, any elements in the sglist need to be copied to kernel space
1208 * or copied back to userspace.
1210 * Only root may perform a controller passthru command, however I'm not doing
1211 * any serious sanity checking on the arguments. Doing an IDA_WRITE_MEDIA and
1212 * putting a 64M buffer in the sglist is probably a *bad* idea.
1214 static int ida_ctlr_ioctl(int ctlr
, int dsk
, ida_ioctl_t
*io
)
1216 ctlr_info_t
*h
= hba
[ctlr
];
1219 unsigned long flags
;
1222 if ((c
= cmd_alloc(NULL
)) == NULL
)
1225 c
->hdr
.unit
= (io
->unit
& UNITVALID
) ? (io
->unit
& ~UNITVALID
) : dsk
;
1226 c
->hdr
.size
= sizeof(rblk_t
) >> 2;
1227 c
->size
+= sizeof(rblk_t
);
1229 c
->req
.hdr
.cmd
= io
->cmd
;
1230 c
->req
.hdr
.blk
= io
->blk
;
1231 c
->req
.hdr
.blk_cnt
= io
->blk_cnt
;
1232 c
->type
= CMD_IOCTL_PEND
;
1234 /* Pre submit processing */
1237 p
= kmalloc(io
->sg
[0].size
, GFP_KERNEL
);
1244 copy_from_user(p
, (void*)io
->sg
[0].addr
, io
->sg
[0].size
);
1245 c
->req
.hdr
.blk
= virt_to_bus(&(io
->c
));
1246 c
->req
.sg
[0].size
= io
->sg
[0].size
;
1247 c
->req
.sg
[0].addr
= virt_to_bus(p
);
1248 c
->req
.hdr
.sg_cnt
= 1;
1251 p
= kmalloc(io
->sg
[0].size
, GFP_KERNEL
);
1259 c
->req
.sg
[0].size
= io
->sg
[0].size
;
1260 c
->req
.sg
[0].addr
= virt_to_bus(p
);
1261 c
->req
.hdr
.sg_cnt
= 1;
1264 case IDA_WRITE_MEDIA
:
1265 case DIAG_PASS_THRU
:
1266 p
= kmalloc(io
->sg
[0].size
, GFP_KERNEL
);
1273 copy_from_user(p
, (void*)io
->sg
[0].addr
, io
->sg
[0].size
);
1274 c
->req
.sg
[0].size
= io
->sg
[0].size
;
1275 c
->req
.sg
[0].addr
= virt_to_bus(p
);
1276 c
->req
.hdr
.sg_cnt
= 1;
1279 c
->req
.sg
[0].size
= sizeof(io
->c
);
1280 c
->req
.sg
[0].addr
= virt_to_bus(&io
->c
);
1281 c
->req
.hdr
.sg_cnt
= 1;
1284 /* Put the request on the tail of the request queue */
1285 spin_lock_irqsave(&io_request_lock
, flags
);
1289 spin_unlock_irqrestore(&io_request_lock
, flags
);
1291 /* Wait for completion */
1292 while(c
->type
!= CMD_IOCTL_DONE
)
1295 /* Post submit processing */
1299 case DIAG_PASS_THRU
:
1300 copy_to_user((void*)io
->sg
[0].addr
, p
, io
->sg
[0].size
);
1301 /* fall through and free p */
1303 case IDA_WRITE_MEDIA
:
1310 io
->rcode
= c
->req
.hdr
.rcode
;
1316 * Commands are pre-allocated in a large block. Here we use a simple bitmap
1317 * scheme to suballocte them to the driver. Operations that are not time
1318 * critical (and can wait for kmalloc and possibly sleep) can pass in NULL
1319 * as the first argument to get a new command.
1321 static cmdlist_t
* cmd_alloc(ctlr_info_t
*h
)
1327 c
= (cmdlist_t
*)kmalloc(sizeof(cmdlist_t
), GFP_KERNEL
);
1332 i
= find_first_zero_bit(h
->cmd_pool_bits
, NR_CMDS
);
1335 } while(test_and_set_bit(i
%32, h
->cmd_pool_bits
+(i
/32)) != 0);
1336 c
= h
->cmd_pool
+ i
;
1340 memset(c
, 0, sizeof(cmdlist_t
));
1341 c
->busaddr
= virt_to_bus(c
);
1345 static void cmd_free(ctlr_info_t
*h
, cmdlist_t
*c
)
1352 i
= c
- h
->cmd_pool
;
1353 clear_bit(i
%32, h
->cmd_pool_bits
+(i
/32));
1358 /***********************************************************************
1360 Send a command to an IDA using the memory mapped FIFO interface
1361 and wait for it to complete.
1362 This routine should only be called at init time.
1363 ***********************************************************************/
1370 unsigned int blkcnt
,
1371 unsigned int log_unit
)
1377 ctlr_info_t
*info_p
= hba
[ctlr
];
1379 c
= cmd_alloc(info_p
);
1381 c
->hdr
.unit
= log_unit
;
1383 c
->hdr
.size
= sizeof(rblk_t
) >> 2;
1384 c
->size
+= sizeof(rblk_t
);
1386 /* The request information. */
1387 c
->req
.hdr
.next
= 0;
1388 c
->req
.hdr
.rcode
= 0;
1390 c
->req
.hdr
.sg_cnt
= 1;
1391 c
->req
.hdr
.reserved
= 0;
1394 c
->req
.sg
[0].size
= 512;
1396 c
->req
.sg
[0].size
= size
;
1398 c
->req
.hdr
.blk
= blk
;
1399 c
->req
.hdr
.blk_cnt
= blkcnt
;
1400 c
->req
.hdr
.cmd
= (unsigned char) cmd
;
1401 c
->req
.sg
[0].addr
= (__u32
) virt_to_bus(buff
);
1405 info_p
->access
.set_intr_mask(info_p
, 0);
1406 /* Make sure there is room in the command FIFO */
1407 /* Actually it should be completely empty at this time. */
1408 for (i
= 200000; i
> 0; i
--) {
1409 temp
= info_p
->access
.fifo_full(info_p
);
1415 printk(KERN_WARNING
"cpqarray ida%d: idaSendPciCmd FIFO full,"
1416 " waiting!\n", ctlr
);
1422 info_p
->access
.submit_command(info_p
, c
);
1423 complete
= pollcomplete(ctlr
);
1424 if (complete
!= 1) {
1425 if (complete
!= c
->busaddr
) {
1426 printk( KERN_WARNING
1427 "cpqarray ida%d: idaSendPciCmd "
1428 "Invalid command list address returned! (%08lx)\n",
1429 ctlr
, (unsigned long)complete
);
1430 cmd_free(info_p
, c
);
1434 printk( KERN_WARNING
1435 "cpqarray ida%d: idaSendPciCmd Timeout out, "
1436 "No command list address returned!\n",
1438 cmd_free(info_p
, c
);
1442 if (c
->req
.hdr
.rcode
& 0x00FE) {
1443 if (!(c
->req
.hdr
.rcode
& BIG_PROBLEM
)) {
1444 printk( KERN_WARNING
1445 "cpqarray ida%d: idaSendPciCmd, error: "
1446 "Controller failed at init time "
1447 "cmd: 0x%x, return code = 0x%x\n",
1448 ctlr
, c
->req
.hdr
.cmd
, c
->req
.hdr
.rcode
);
1450 cmd_free(info_p
, c
);
1454 cmd_free(info_p
, c
);
1458 static int frevalidate_logvol(kdev_t dev
)
1460 return revalidate_logvol(dev
, 0);
1464 * revalidate_allvol is for online array config utilities. After a
1465 * utility reconfigures the drives in the array, it can use this function
1466 * (through an ioctl) to make the driver zap any previous disk structs for
1467 * that controller and get new ones.
1469 * Right now I'm using the getgeometry() function to do this, but this
1470 * function should probably be finer grained and allow you to revalidate one
1471 * particualar logical volume (instead of all of them on a particular
1474 static int revalidate_allvol(kdev_t dev
)
1477 unsigned long flags
;
1479 ctlr
= MAJOR(dev
) - MAJOR_NR
;
1480 if (MINOR(dev
) != 0)
1483 spin_lock_irqsave(&io_request_lock
, flags
);
1484 if (hba
[ctlr
]->usage_count
> 1) {
1485 spin_unlock_irqrestore(&io_request_lock
, flags
);
1486 printk(KERN_WARNING
"cpqarray: Device busy for volume"
1487 " revalidation (usage=%d)\n", hba
[ctlr
]->usage_count
);
1490 spin_unlock_irqrestore(&io_request_lock
, flags
);
1491 hba
[ctlr
]->usage_count
++;
1494 * Set the partition and block size structures for all volumes
1495 * on this controller to zero. We will reread all of this data
1497 memset(ida
+(ctlr
*256), 0, sizeof(struct hd_struct
)*NWD
*16);
1498 memset(ida_sizes
+(ctlr
*256), 0, sizeof(int)*NWD
*16);
1499 memset(ida_blocksizes
+(ctlr
*256), 0, sizeof(int)*NWD
*16);
1500 memset(ida_hardsizes
+(ctlr
*256), 0, sizeof(int)*NWD
*16);
1501 memset(hba
[ctlr
]->drv
, 0, sizeof(drv_info_t
)*NWD
);
1502 ida_gendisk
[ctlr
].nr_real
= 0;
1505 * Tell the array controller not to give us any interupts while
1506 * we check the new geometry. Then turn interrupts back on when
1509 hba
[ctlr
]->access
.set_intr_mask(hba
[ctlr
], 0);
1511 hba
[ctlr
]->access
.set_intr_mask(hba
[ctlr
], FIFO_NOT_EMPTY
);
1514 for(i
=0; i
<NWD
; i
++)
1515 if (ida_sizes
[(ctlr
<<CTLR_SHIFT
) + (i
<<NWD_SHIFT
)])
1516 revalidate_logvol(dev
+(i
<<NWD_SHIFT
), 2);
1518 hba
[ctlr
]->usage_count
--;
1522 /* Borrowed and adapted from sd.c */
1523 static int revalidate_logvol(kdev_t dev
, int maxusage
)
1526 struct gendisk
*gdev
;
1527 unsigned long flags
;
1532 target
= DEVICE_NR(dev
);
1533 ctlr
= MAJOR(dev
) - MAJOR_NR
;
1534 gdev
= &ida_gendisk
[ctlr
];
1536 spin_lock_irqsave(&io_request_lock
, flags
);
1537 if (hba
[ctlr
]->drv
[target
].usage_count
> maxusage
) {
1538 spin_unlock_irqrestore(&io_request_lock
, flags
);
1539 printk(KERN_WARNING
"cpqarray: Device busy for "
1540 "revalidation (usage=%d)\n",
1541 hba
[ctlr
]->drv
[target
].usage_count
);
1545 hba
[ctlr
]->drv
[target
].usage_count
++;
1546 spin_unlock_irqrestore(&io_request_lock
, flags
);
1548 max_p
= gdev
->max_p
;
1549 start
= target
<< gdev
->minor_shift
;
1551 for(i
=max_p
; i
>=0; i
--) {
1552 int minor
= start
+i
;
1553 kdev_t devi
= MKDEV(MAJOR_NR
+ ctlr
, minor
);
1554 struct super_block
*sb
= get_super(devi
);
1556 if (sb
) invalidate_inodes(sb
);
1557 invalidate_buffers(devi
);
1558 gdev
->part
[minor
].start_sect
= 0;
1559 gdev
->part
[minor
].nr_sects
= 0;
1561 /* reset the blocksize so we can read the partition table */
1562 blksize_size
[MAJOR_NR
+ctlr
][minor
] = 1024;
1565 /* 16 minors per disk... */
1566 grok_partitions(gdev
, target
, 16, hba
[ctlr
]->drv
[target
].nr_blks
);
1567 hba
[ctlr
]->drv
[target
].usage_count
--;
1572 /********************************************************************
1574 Wait polling for a command to complete.
1575 The memory mapped FIFO is polled for the completion.
1576 Used only at init time, interrupts disabled.
1577 ********************************************************************/
1578 static int pollcomplete(int ctlr
)
1583 /* Wait (up to 2 seconds) for a command to complete */
1585 for (i
= 200000; i
> 0; i
--) {
1586 done
= hba
[ctlr
]->access
.command_completed(hba
[ctlr
]);
1588 udelay(10); /* a short fixed delay */
1592 /* Invalid address to tell caller we ran out of time */
1595 /*****************************************************************
1597 Starts controller firmwares background processing.
1598 Currently only the Integrated Raid controller needs this done.
1599 If the PCI mem address registers are written to after this,
1600 data corruption may occur
1601 *****************************************************************/
1602 static void start_fwbk(int ctlr
)
1604 id_ctlr_t
*id_ctlr_buf
;
1607 if( (hba
[ctlr
]->board_id
!= 0x40400E11)
1608 && (hba
[ctlr
]->board_id
!= 0x40480E11) )
1610 /* Not a Integrated Raid, so there is nothing for us to do */
1612 printk(KERN_DEBUG
"cpqarray: Starting firmware's background"
1614 /* Command does not return anything, but idasend command needs a
1616 id_ctlr_buf
= (id_ctlr_t
*)kmalloc(sizeof(id_ctlr_t
), GFP_KERNEL
);
1617 if(id_ctlr_buf
==NULL
)
1619 printk(KERN_WARNING
"cpqarray: Out of memory. "
1620 "Unable to start background processing.\n");
1623 ret_code
= sendcmd(RESUME_BACKGROUND_ACTIVITY
, ctlr
,
1624 id_ctlr_buf
, 0, 0, 0, 0);
1625 if(ret_code
!= IO_OK
)
1626 printk(KERN_WARNING
"cpqarray: Unable to start"
1627 " background processing\n");
1631 /*****************************************************************
1633 Get ida logical volume geometry from the controller
1634 This is a large bit of code which once existed in two flavors,
1635 It is used only at init time.
1636 *****************************************************************/
1637 static void getgeometry(int ctlr
)
1639 id_log_drv_t
*id_ldrive
;
1640 id_ctlr_t
*id_ctlr_buf
;
1641 sense_log_drv_stat_t
*id_lstatus_buf
;
1642 config_t
*sense_config_buf
;
1643 unsigned int log_unit
, log_index
;
1646 ctlr_info_t
*info_p
= hba
[ctlr
];
1648 info_p
->log_drv_map
= 0;
1650 id_ldrive
= (id_log_drv_t
*)kmalloc(sizeof(id_log_drv_t
), GFP_KERNEL
);
1651 if(id_ldrive
== NULL
)
1653 printk( KERN_ERR
"cpqarray: out of memory.\n");
1657 id_ctlr_buf
= (id_ctlr_t
*)kmalloc(sizeof(id_ctlr_t
), GFP_KERNEL
);
1658 if(id_ctlr_buf
== NULL
)
1661 printk( KERN_ERR
"cpqarray: out of memory.\n");
1665 id_lstatus_buf
= (sense_log_drv_stat_t
*)kmalloc(sizeof(sense_log_drv_stat_t
), GFP_KERNEL
);
1666 if(id_lstatus_buf
== NULL
)
1670 printk( KERN_ERR
"cpqarray: out of memory.\n");
1674 sense_config_buf
= (config_t
*)kmalloc(sizeof(config_t
), GFP_KERNEL
);
1675 if(sense_config_buf
== NULL
)
1677 kfree(id_lstatus_buf
);
1680 printk( KERN_ERR
"cpqarray: out of memory.\n");
1684 memset(id_ldrive
, 0, sizeof(id_log_drv_t
));
1685 memset(id_ctlr_buf
, 0, sizeof(id_ctlr_t
));
1686 memset(id_lstatus_buf
, 0, sizeof(sense_log_drv_stat_t
));
1687 memset(sense_config_buf
, 0, sizeof(config_t
));
1689 info_p
->phys_drives
= 0;
1690 info_p
->log_drv_map
= 0;
1691 info_p
->drv_assign_map
= 0;
1692 info_p
->drv_spare_map
= 0;
1693 info_p
->mp_failed_drv_map
= 0; /* only initialized here */
1694 /* Get controllers info for this logical drive */
1695 ret_code
= sendcmd(ID_CTLR
, ctlr
, id_ctlr_buf
, 0, 0, 0, 0);
1696 if (ret_code
== IO_ERROR
) {
1698 * If can't get controller info, set the logical drive map to 0,
1699 * so the idastubopen will fail on all logical drives
1700 * on the controller.
1702 /* Free all the buffers and return */
1703 printk(KERN_ERR
"cpqarray: error sending ID controller\n");
1704 kfree(sense_config_buf
);
1705 kfree(id_lstatus_buf
);
1711 info_p
->log_drives
= id_ctlr_buf
->nr_drvs
;;
1712 *(__u32
*)(info_p
->firm_rev
) = *(__u32
*)(id_ctlr_buf
->firm_rev
);
1713 info_p
->ctlr_sig
= id_ctlr_buf
->cfg_sig
;
1715 printk(" (%s)\n", info_p
->product_name
);
1717 * Initialize logical drive map to zero
1721 * Get drive geometry for all logical drives
1723 if (id_ctlr_buf
->nr_drvs
> 16)
1724 printk(KERN_WARNING
"cpqarray ida%d: This driver supports "
1725 "16 logical drives per controller.\n. "
1726 " Additional drives will not be "
1727 "detected\n", ctlr
);
1730 (log_index
< id_ctlr_buf
->nr_drvs
)
1731 && (log_unit
< NWD
);
1734 size
= sizeof(sense_log_drv_stat_t
);
1737 Send "Identify logical drive status" cmd
1739 ret_code
= sendcmd(SENSE_LOG_DRV_STAT
,
1740 ctlr
, id_lstatus_buf
, size
, 0, 0, log_unit
);
1741 if (ret_code
== IO_ERROR
) {
1743 If can't get logical drive status, set
1744 the logical drive map to 0, so the
1745 idastubopen will fail for all logical drives
1748 info_p
->log_drv_map
= 0;
1749 printk( KERN_WARNING
1750 "cpqarray ida%d: idaGetGeometry - Controller"
1751 " failed to report status of logical drive %d\n"
1752 "Access to this controller has been disabled\n",
1754 /* Free all the buffers and return */
1755 kfree(sense_config_buf
);
1756 kfree(id_lstatus_buf
);
1762 Make sure the logical drive is configured
1764 if (id_lstatus_buf
->status
!= LOG_NOT_CONF
) {
1765 ret_code
= sendcmd(ID_LOG_DRV
, ctlr
, id_ldrive
,
1766 sizeof(id_log_drv_t
), 0, 0, log_unit
);
1768 If error, the bit for this
1769 logical drive won't be set and
1770 idastubopen will return error.
1772 if (ret_code
!= IO_ERROR
) {
1773 drv
= &info_p
->drv
[log_unit
];
1774 drv
->blk_size
= id_ldrive
->blk_size
;
1775 drv
->nr_blks
= id_ldrive
->nr_blks
;
1776 drv
->cylinders
= id_ldrive
->drv
.cyl
;
1777 drv
->heads
= id_ldrive
->drv
.heads
;
1778 drv
->sectors
= id_ldrive
->drv
.sect_per_track
;
1779 info_p
->log_drv_map
|= (1 << log_unit
);
1781 printk(KERN_INFO
"cpqarray ida/c%dd%d: blksz=%d nr_blks=%d\n",
1782 ctlr
, log_unit
, drv
->blk_size
, drv
->nr_blks
);
1783 ret_code
= sendcmd(SENSE_CONFIG
,
1784 ctlr
, sense_config_buf
,
1785 sizeof(config_t
), 0, 0, log_unit
);
1786 if (ret_code
== IO_ERROR
) {
1787 info_p
->log_drv_map
= 0;
1788 /* Free all the buffers and return */
1789 printk(KERN_ERR
"cpqarray: error sending sense config\n");
1790 kfree(sense_config_buf
);
1791 kfree(id_lstatus_buf
);
1797 info_p
->phys_drives
=
1798 sense_config_buf
->ctlr_phys_drv
;
1799 info_p
->drv_assign_map
1800 |= sense_config_buf
->drv_asgn_map
;
1801 info_p
->drv_assign_map
1802 |= sense_config_buf
->spare_asgn_map
;
1803 info_p
->drv_spare_map
1804 |= sense_config_buf
->spare_asgn_map
;
1805 } /* end of if no error on id_ldrive */
1806 log_index
= log_index
+ 1;
1807 } /* end of if logical drive configured */
1808 } /* end of for log_unit */
1809 kfree(sense_config_buf
);
1811 kfree(id_lstatus_buf
);