[PATCH] More modules.txt removals
[linux-2.6/history.git] / drivers / block / cciss.c
blobd4f508644b1f28d5d23c69a03b742660182b618c
1 /*
2 * Disk Array driver for HP SA 5xxx and 6xxx Controllers
3 * Copyright 2000, 2002 Hewlett-Packard Development Company, L.P.
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 Cciss-discuss@lists.sourceforge.net
23 #include <linux/config.h> /* CONFIG_PROC_FS */
24 #include <linux/module.h>
25 #include <linux/interrupt.h>
26 #include <linux/types.h>
27 #include <linux/pci.h>
28 #include <linux/kernel.h>
29 #include <linux/slab.h>
30 #include <linux/delay.h>
31 #include <linux/major.h>
32 #include <linux/fs.h>
33 #include <linux/bio.h>
34 #include <linux/blkpg.h>
35 #include <linux/timer.h>
36 #include <linux/proc_fs.h>
37 #include <linux/init.h>
38 #include <linux/hdreg.h>
39 #include <linux/spinlock.h>
40 #include <asm/uaccess.h>
41 #include <asm/io.h>
43 #include <linux/blkdev.h>
44 #include <linux/genhd.h>
45 #include <linux/completion.h>
47 #define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
48 #define DRIVER_NAME "Compaq CISS Driver (v 2.5.0)"
49 #define DRIVER_VERSION CCISS_DRIVER_VERSION(2,5,0)
51 /* Embedded module documentation macros - see modules.h */
52 MODULE_AUTHOR("Charles M. White III - Compaq Computer Corporation");
53 MODULE_DESCRIPTION("Driver for Compaq Smart Array Controller 5xxx v. 2.5.0");
54 MODULE_LICENSE("GPL");
56 #include "cciss_cmd.h"
57 #include "cciss.h"
58 #include <linux/cciss_ioctl.h>
60 /* define the PCI info for the cards we can control */
61 const struct pci_device_id cciss_pci_device_id[] = {
62 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISS,
63 0x0E11, 0x4070, 0, 0, 0},
64 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB,
65 0x0E11, 0x4080, 0, 0, 0},
66 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB,
67 0x0E11, 0x4082, 0, 0, 0},
68 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB,
69 0x0E11, 0x4083, 0, 0, 0},
70 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
71 0x0E11, 0x409A, 0, 0, 0},
72 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
73 0x0E11, 0x409B, 0, 0, 0},
74 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
75 0x0E11, 0x409C, 0, 0, 0},
76 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
77 0x0E11, 0x409D, 0, 0, 0},
78 {0,}
80 MODULE_DEVICE_TABLE(pci, cciss_pci_device_id);
82 #define NR_PRODUCTS (sizeof(products)/sizeof(struct board_type))
84 /* board_id = Subsystem Device ID & Vendor ID
85 * product = Marketing Name for the board
86 * access = Address of the struct of function pointers
88 static struct board_type products[] = {
89 { 0x40700E11, "Smart Array 5300", &SA5_access },
90 { 0x40800E11, "Smart Array 5i", &SA5B_access},
91 { 0x40820E11, "Smart Array 532", &SA5B_access},
92 { 0x40830E11, "Smart Array 5312", &SA5B_access},
93 { 0x409A0E11, "Smart Array 641", &SA5_access},
94 { 0x409B0E11, "Smart Array 642", &SA5_access},
95 { 0x409C0E11, "Smart Array 6400", &SA5_access},
96 { 0x409D0E11, "Smart Array 6400 EM", &SA5_access},
99 /* How long to wait (in millesconds) for board to go into simple mode */
100 #define MAX_CONFIG_WAIT 30000
101 #define MAX_IOCTL_CONFIG_WAIT 1000
103 /*define how many times we will try a command because of bus resets */
104 #define MAX_CMD_RETRIES 3
106 #define READ_AHEAD 128
107 #define NR_CMDS 384 /* #commands that can be outstanding */
108 #define MAX_CTLR 8
110 #define CCISS_DMA_MASK 0xFFFFFFFF /* 32 bit DMA */
112 static ctlr_info_t *hba[MAX_CTLR];
114 static void do_cciss_request(request_queue_t *q);
115 static int cciss_open(struct inode *inode, struct file *filep);
116 static int cciss_release(struct inode *inode, struct file *filep);
117 static int cciss_ioctl(struct inode *inode, struct file *filep,
118 unsigned int cmd, unsigned long arg);
120 static int revalidate_allvol(ctlr_info_t *host);
121 static int cciss_revalidate(struct gendisk *disk);
122 static int deregister_disk(struct gendisk *disk);
123 static int register_new_disk(ctlr_info_t *h);
125 static void cciss_getgeometry(int cntl_num);
127 static inline void addQ(CommandList_struct **Qptr, CommandList_struct *c);
128 static void start_io( ctlr_info_t *h);
129 static int sendcmd( __u8 cmd, int ctlr, void *buff, size_t size,
130 unsigned int use_unit_num, unsigned int log_unit, __u8 page_code,
131 unsigned char *scsi3addr, int cmd_type);
133 #ifdef CONFIG_PROC_FS
134 static int cciss_proc_get_info(char *buffer, char **start, off_t offset,
135 int length, int *eof, void *data);
136 static void cciss_procinit(int i);
137 #else
138 static void cciss_procinit(int i) {}
139 #endif /* CONFIG_PROC_FS */
141 static struct block_device_operations cciss_fops = {
142 .owner = THIS_MODULE,
143 .open = cciss_open,
144 .release = cciss_release,
145 .ioctl = cciss_ioctl,
146 .revalidate_disk= cciss_revalidate,
149 #include "cciss_scsi.c" /* For SCSI tape support */
152 * Report information about this controller.
154 #ifdef CONFIG_PROC_FS
156 static struct proc_dir_entry *proc_cciss;
158 static int cciss_proc_get_info(char *buffer, char **start, off_t offset,
159 int length, int *eof, void *data)
161 off_t pos = 0;
162 off_t len = 0;
163 int size, i, ctlr;
164 ctlr_info_t *h = (ctlr_info_t*)data;
165 drive_info_struct *drv;
167 ctlr = h->ctlr;
168 size = sprintf(buffer, "%s: Compaq %s Controller\n"
169 " Board ID: 0x%08lx\n"
170 " Firmware Version: %c%c%c%c\n"
171 " Memory Address: 0x%08lx\n"
172 " IRQ: %d\n"
173 " Logical drives: %d\n"
174 " Highest Logical Volume ID: %d\n"
175 " Current Q depth: %d\n"
176 " Max Q depth since init: %d\n"
177 " Max # commands on controller since init: %d\n"
178 " Max SG entries since init: %d\n\n",
179 h->devname,
180 h->product_name,
181 (unsigned long)h->board_id,
182 h->firm_ver[0], h->firm_ver[1], h->firm_ver[2], h->firm_ver[3],
183 (unsigned long)h->vaddr,
184 (unsigned int)h->intr,
185 h->num_luns,
186 h->highest_lun,
187 h->Qdepth, h->maxQsinceinit, h->max_outstanding, h->maxSG);
189 pos += size; len += size;
190 cciss_proc_tape_report(ctlr, buffer, &pos, &len);
191 for(i=0; i<h->highest_lun; i++) {
192 drv = &h->drv[i];
193 if (drv->block_size == 0)
194 continue;
195 size = sprintf(buffer+len, "cciss/c%dd%d: blksz=%d nr_blocks=%llu\n",
196 ctlr, i, drv->block_size, (unsigned long long)drv->nr_blocks);
197 pos += size; len += size;
200 size = sprintf(buffer+len, "nr_allocs = %d\nnr_frees = %d\n",
201 h->nr_allocs, h->nr_frees);
202 pos += size; len += size;
204 *eof = 1;
205 *start = buffer+offset;
206 len -= offset;
207 if (len>length)
208 len = length;
209 return len;
212 static int
213 cciss_proc_write(struct file *file, const char *buffer,
214 unsigned long count, void *data)
216 unsigned char cmd[80];
217 int len;
218 #ifdef CONFIG_CISS_SCSI_TAPE
219 ctlr_info_t *h = (ctlr_info_t *) data;
220 int rc;
221 #endif
223 if (count > sizeof(cmd)-1) return -EINVAL;
224 if (copy_from_user(cmd, buffer, count)) return -EFAULT;
225 cmd[count] = '\0';
226 len = strlen(cmd); // above 3 lines ensure safety
227 if (cmd[len-1] == '\n')
228 cmd[--len] = '\0';
229 # ifdef CONFIG_CISS_SCSI_TAPE
230 if (strcmp("engage scsi", cmd)==0) {
231 rc = cciss_engage_scsi(h->ctlr);
232 if (rc != 0) return -rc;
233 return count;
235 /* might be nice to have "disengage" too, but it's not
236 safely possible. (only 1 module use count, lock issues.) */
237 # endif
238 return -EINVAL;
242 * Get us a file in /proc/cciss that says something about each controller.
243 * Create /proc/cciss if it doesn't exist yet.
245 static void __devinit cciss_procinit(int i)
247 struct proc_dir_entry *pde;
249 if (proc_cciss == NULL) {
250 proc_cciss = proc_mkdir("cciss", proc_root_driver);
251 if (!proc_cciss)
252 return;
255 pde = create_proc_read_entry(hba[i]->devname,
256 S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH,
257 proc_cciss, cciss_proc_get_info, hba[i]);
258 pde->write_proc = cciss_proc_write;
260 #endif /* CONFIG_PROC_FS */
263 * For operations that cannot sleep, a command block is allocated at init,
264 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track
265 * which ones are free or in use. For operations that can wait for kmalloc
266 * to possible sleep, this routine can be called with get_from_pool set to 0.
267 * cmd_free() MUST be called with a got_from_pool set to 0 if cmd_alloc was.
269 static CommandList_struct * cmd_alloc(ctlr_info_t *h, int get_from_pool)
271 CommandList_struct *c;
272 int i;
273 u64bit temp64;
274 dma_addr_t cmd_dma_handle, err_dma_handle;
276 if (!get_from_pool)
278 c = (CommandList_struct *) pci_alloc_consistent(
279 h->pdev, sizeof(CommandList_struct), &cmd_dma_handle);
280 if(c==NULL)
281 return NULL;
282 memset(c, 0, sizeof(CommandList_struct));
284 c->err_info = (ErrorInfo_struct *)pci_alloc_consistent(
285 h->pdev, sizeof(ErrorInfo_struct),
286 &err_dma_handle);
288 if (c->err_info == NULL)
290 pci_free_consistent(h->pdev,
291 sizeof(CommandList_struct), c, cmd_dma_handle);
292 return NULL;
294 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
295 } else /* get it out of the controllers pool */
297 do {
298 i = find_first_zero_bit(h->cmd_pool_bits, NR_CMDS);
299 if (i == NR_CMDS)
300 return NULL;
301 } while(test_and_set_bit(i & (BITS_PER_LONG - 1), h->cmd_pool_bits+(i/BITS_PER_LONG)) != 0);
302 #ifdef CCISS_DEBUG
303 printk(KERN_DEBUG "cciss: using command buffer %d\n", i);
304 #endif
305 c = h->cmd_pool + i;
306 memset(c, 0, sizeof(CommandList_struct));
307 cmd_dma_handle = h->cmd_pool_dhandle
308 + i*sizeof(CommandList_struct);
309 c->err_info = h->errinfo_pool + i;
310 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
311 err_dma_handle = h->errinfo_pool_dhandle
312 + i*sizeof(ErrorInfo_struct);
313 h->nr_allocs++;
316 c->busaddr = (__u32) cmd_dma_handle;
317 temp64.val = (__u64) err_dma_handle;
318 c->ErrDesc.Addr.lower = temp64.val32.lower;
319 c->ErrDesc.Addr.upper = temp64.val32.upper;
320 c->ErrDesc.Len = sizeof(ErrorInfo_struct);
322 c->ctlr = h->ctlr;
323 return c;
329 * Frees a command block that was previously allocated with cmd_alloc().
331 static void cmd_free(ctlr_info_t *h, CommandList_struct *c, int got_from_pool)
333 int i;
334 u64bit temp64;
336 if( !got_from_pool)
338 temp64.val32.lower = c->ErrDesc.Addr.lower;
339 temp64.val32.upper = c->ErrDesc.Addr.upper;
340 pci_free_consistent(h->pdev, sizeof(ErrorInfo_struct),
341 c->err_info, (dma_addr_t) temp64.val);
342 pci_free_consistent(h->pdev, sizeof(CommandList_struct),
343 c, (dma_addr_t) c->busaddr);
344 } else
346 i = c - h->cmd_pool;
347 clear_bit(i&(BITS_PER_LONG-1), h->cmd_pool_bits+(i/BITS_PER_LONG));
348 h->nr_frees++;
352 static inline ctlr_info_t *get_host(struct gendisk *disk)
354 return disk->queue->queuedata;
357 static inline drive_info_struct *get_drv(struct gendisk *disk)
359 return disk->private_data;
363 * Open. Make sure the device is really there.
365 static int cciss_open(struct inode *inode, struct file *filep)
367 ctlr_info_t *host = get_host(inode->i_bdev->bd_disk);
368 drive_info_struct *drv = get_drv(inode->i_bdev->bd_disk);
370 #ifdef CCISS_DEBUG
371 printk(KERN_DEBUG "cciss_open %s\n", inode->i_bdev->bd_disk->disk_name);
372 #endif /* CCISS_DEBUG */
375 * Root is allowed to open raw volume zero even if it's not configured
376 * so array config can still work. I don't think I really like this,
377 * but I'm already using way to many device nodes to claim another one
378 * for "raw controller".
380 if (drv->nr_blocks == 0) {
381 if (iminor(inode) != 0)
382 return -ENXIO;
383 if (!capable(CAP_SYS_ADMIN))
384 return -EPERM;
386 drv->usage_count++;
387 host->usage_count++;
388 return 0;
391 * Close. Sync first.
393 static int cciss_release(struct inode *inode, struct file *filep)
395 ctlr_info_t *host = get_host(inode->i_bdev->bd_disk);
396 drive_info_struct *drv = get_drv(inode->i_bdev->bd_disk);
398 #ifdef CCISS_DEBUG
399 printk(KERN_DEBUG "cciss_release %s\n", inode->i_bdev->bd_disk->disk_name);
400 #endif /* CCISS_DEBUG */
402 drv->usage_count--;
403 host->usage_count--;
404 return 0;
408 * ioctl
410 static int cciss_ioctl(struct inode *inode, struct file *filep,
411 unsigned int cmd, unsigned long arg)
413 struct block_device *bdev = inode->i_bdev;
414 struct gendisk *disk = bdev->bd_disk;
415 ctlr_info_t *host = get_host(disk);
416 drive_info_struct *drv = get_drv(disk);
417 int ctlr = host->ctlr;
419 #ifdef CCISS_DEBUG
420 printk(KERN_DEBUG "cciss_ioctl: Called with cmd=%x %lx\n", cmd, arg);
421 #endif /* CCISS_DEBUG */
423 switch(cmd) {
424 case HDIO_GETGEO:
426 struct hd_geometry driver_geo;
427 if (drv->cylinders) {
428 driver_geo.heads = drv->heads;
429 driver_geo.sectors = drv->sectors;
430 driver_geo.cylinders = drv->cylinders;
431 } else {
432 driver_geo.heads = 0xff;
433 driver_geo.sectors = 0x3f;
434 driver_geo.cylinders = (int)drv->nr_blocks / (0xff*0x3f);
436 driver_geo.start= get_start_sect(inode->i_bdev);
437 if (copy_to_user((void *) arg, &driver_geo,
438 sizeof( struct hd_geometry)))
439 return -EFAULT;
440 return(0);
443 case CCISS_GETPCIINFO:
445 cciss_pci_info_struct pciinfo;
447 if (!arg) return -EINVAL;
448 pciinfo.bus = host->pdev->bus->number;
449 pciinfo.dev_fn = host->pdev->devfn;
450 pciinfo.board_id = host->board_id;
451 if (copy_to_user((void *) arg, &pciinfo, sizeof( cciss_pci_info_struct )))
452 return -EFAULT;
453 return(0);
455 case CCISS_GETINTINFO:
457 cciss_coalint_struct intinfo;
458 if (!arg) return -EINVAL;
459 intinfo.delay = readl(&host->cfgtable->HostWrite.CoalIntDelay);
460 intinfo.count = readl(&host->cfgtable->HostWrite.CoalIntCount);
461 if (copy_to_user((void *) arg, &intinfo, sizeof( cciss_coalint_struct )))
462 return -EFAULT;
463 return(0);
465 case CCISS_SETINTINFO:
467 cciss_coalint_struct intinfo;
468 unsigned long flags;
469 int i;
471 if (!arg) return -EINVAL;
472 if (!capable(CAP_SYS_ADMIN)) return -EPERM;
473 if (copy_from_user(&intinfo, (void *) arg, sizeof( cciss_coalint_struct)))
474 return -EFAULT;
475 if ( (intinfo.delay == 0 ) && (intinfo.count == 0))
478 // printk("cciss_ioctl: delay and count cannot be 0\n");
479 return( -EINVAL);
481 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
482 /* Update the field, and then ring the doorbell */
483 writel( intinfo.delay,
484 &(host->cfgtable->HostWrite.CoalIntDelay));
485 writel( intinfo.count,
486 &(host->cfgtable->HostWrite.CoalIntCount));
487 writel( CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL);
489 for(i=0;i<MAX_IOCTL_CONFIG_WAIT;i++) {
490 if (!(readl(host->vaddr + SA5_DOORBELL)
491 & CFGTBL_ChangeReq))
492 break;
493 /* delay and try again */
494 udelay(1000);
496 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
497 if (i >= MAX_IOCTL_CONFIG_WAIT)
498 return -EAGAIN;
499 return(0);
501 case CCISS_GETNODENAME:
503 NodeName_type NodeName;
504 int i;
506 if (!arg) return -EINVAL;
507 for(i=0;i<16;i++)
508 NodeName[i] = readb(&host->cfgtable->ServerName[i]);
509 if (copy_to_user((void *) arg, NodeName, sizeof( NodeName_type)))
510 return -EFAULT;
511 return(0);
513 case CCISS_SETNODENAME:
515 NodeName_type NodeName;
516 unsigned long flags;
517 int i;
519 if (!arg) return -EINVAL;
520 if (!capable(CAP_SYS_ADMIN)) return -EPERM;
522 if (copy_from_user(NodeName, (void *) arg, sizeof( NodeName_type)))
523 return -EFAULT;
525 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
527 /* Update the field, and then ring the doorbell */
528 for(i=0;i<16;i++)
529 writeb( NodeName[i], &host->cfgtable->ServerName[i]);
531 writel( CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL);
533 for(i=0;i<MAX_IOCTL_CONFIG_WAIT;i++) {
534 if (!(readl(host->vaddr + SA5_DOORBELL)
535 & CFGTBL_ChangeReq))
536 break;
537 /* delay and try again */
538 udelay(1000);
540 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
541 if (i >= MAX_IOCTL_CONFIG_WAIT)
542 return -EAGAIN;
543 return(0);
546 case CCISS_GETHEARTBEAT:
548 Heartbeat_type heartbeat;
550 if (!arg) return -EINVAL;
551 heartbeat = readl(&host->cfgtable->HeartBeat);
552 if (copy_to_user((void *) arg, &heartbeat, sizeof( Heartbeat_type)))
553 return -EFAULT;
554 return(0);
556 case CCISS_GETBUSTYPES:
558 BusTypes_type BusTypes;
560 if (!arg) return -EINVAL;
561 BusTypes = readl(&host->cfgtable->BusTypes);
562 if (copy_to_user((void *) arg, &BusTypes, sizeof( BusTypes_type) ))
563 return -EFAULT;
564 return(0);
566 case CCISS_GETFIRMVER:
568 FirmwareVer_type firmware;
570 if (!arg) return -EINVAL;
571 memcpy(firmware, host->firm_ver, 4);
573 if (copy_to_user((void *) arg, firmware, sizeof( FirmwareVer_type)))
574 return -EFAULT;
575 return(0);
577 case CCISS_GETDRIVVER:
579 DriverVer_type DriverVer = DRIVER_VERSION;
581 if (!arg) return -EINVAL;
583 if (copy_to_user((void *) arg, &DriverVer, sizeof( DriverVer_type) ))
584 return -EFAULT;
585 return(0);
588 case CCISS_REVALIDVOLS:
589 if (bdev != bdev->bd_contains || drv != host->drv)
590 return -ENXIO;
591 return revalidate_allvol(host);
593 case CCISS_GETLUNINFO: {
594 LogvolInfo_struct luninfo;
595 int i;
597 luninfo.LunID = drv->LunID;
598 luninfo.num_opens = drv->usage_count;
599 luninfo.num_parts = 0;
600 /* count partitions 1 to 15 with sizes > 0 */
601 for(i=1; i <MAX_PART; i++) {
602 if (!disk->part[i])
603 continue;
604 if (disk->part[i]->nr_sects != 0)
605 luninfo.num_parts++;
607 if (copy_to_user((void *) arg, &luninfo,
608 sizeof(LogvolInfo_struct)))
609 return -EFAULT;
610 return(0);
612 case CCISS_DEREGDISK:
613 return deregister_disk(disk);
615 case CCISS_REGNEWD:
616 return register_new_disk(host);
618 case CCISS_PASSTHRU:
620 IOCTL_Command_struct iocommand;
621 CommandList_struct *c;
622 char *buff = NULL;
623 u64bit temp64;
624 unsigned long flags;
625 DECLARE_COMPLETION(wait);
627 if (!arg) return -EINVAL;
629 if (!capable(CAP_SYS_RAWIO)) return -EPERM;
631 if (copy_from_user(&iocommand, (void *) arg, sizeof( IOCTL_Command_struct) ))
632 return -EFAULT;
633 if((iocommand.buf_size < 1) &&
634 (iocommand.Request.Type.Direction != XFER_NONE))
636 return -EINVAL;
638 #if 0 /* 'buf_size' member is 16-bits, and always smaller than kmalloc limit */
639 /* Check kmalloc limits */
640 if(iocommand.buf_size > 128000)
641 return -EINVAL;
642 #endif
643 if(iocommand.buf_size > 0)
645 buff = kmalloc(iocommand.buf_size, GFP_KERNEL);
646 if( buff == NULL)
647 return -EFAULT;
649 if (iocommand.Request.Type.Direction == XFER_WRITE)
651 /* Copy the data into the buffer we created */
652 if (copy_from_user(buff, iocommand.buf, iocommand.buf_size))
654 kfree(buff);
655 return -EFAULT;
658 if ((c = cmd_alloc(host , 0)) == NULL)
660 kfree(buff);
661 return -ENOMEM;
663 // Fill in the command type
664 c->cmd_type = CMD_IOCTL_PEND;
665 // Fill in Command Header
666 c->Header.ReplyQueue = 0; // unused in simple mode
667 if( iocommand.buf_size > 0) // buffer to fill
669 c->Header.SGList = 1;
670 c->Header.SGTotal= 1;
671 } else // no buffers to fill
673 c->Header.SGList = 0;
674 c->Header.SGTotal= 0;
676 c->Header.LUN = iocommand.LUN_info;
677 c->Header.Tag.lower = c->busaddr; // use the kernel address the cmd block for tag
679 // Fill in Request block
680 c->Request = iocommand.Request;
682 // Fill in the scatter gather information
683 if (iocommand.buf_size > 0 )
685 temp64.val = pci_map_single( host->pdev, buff,
686 iocommand.buf_size,
687 PCI_DMA_BIDIRECTIONAL);
688 c->SG[0].Addr.lower = temp64.val32.lower;
689 c->SG[0].Addr.upper = temp64.val32.upper;
690 c->SG[0].Len = iocommand.buf_size;
691 c->SG[0].Ext = 0; // we are not chaining
693 c->waiting = &wait;
695 /* Put the request on the tail of the request queue */
696 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
697 addQ(&host->reqQ, c);
698 host->Qdepth++;
699 start_io(host);
700 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
702 wait_for_completion(&wait);
704 /* unlock the buffers from DMA */
705 temp64.val32.lower = c->SG[0].Addr.lower;
706 temp64.val32.upper = c->SG[0].Addr.upper;
707 pci_unmap_single( host->pdev, (dma_addr_t) temp64.val,
708 iocommand.buf_size, PCI_DMA_BIDIRECTIONAL);
710 /* Copy the error information out */
711 iocommand.error_info = *(c->err_info);
712 if ( copy_to_user((void *) arg, &iocommand, sizeof( IOCTL_Command_struct) ) )
714 kfree(buff);
715 cmd_free(host, c, 0);
716 return( -EFAULT);
719 if (iocommand.Request.Type.Direction == XFER_READ)
721 /* Copy the data out of the buffer we created */
722 if (copy_to_user(iocommand.buf, buff, iocommand.buf_size))
724 kfree(buff);
725 cmd_free(host, c, 0);
726 return -EFAULT;
729 kfree(buff);
730 cmd_free(host, c, 0);
731 return(0);
733 case CCISS_BIG_PASSTHRU: {
734 BIG_IOCTL_Command_struct *ioc;
735 CommandList_struct *c;
736 unsigned char **buff = NULL;
737 int *buff_size = NULL;
738 u64bit temp64;
739 unsigned long flags;
740 BYTE sg_used = 0;
741 int status = 0;
742 int i;
743 DECLARE_COMPLETION(wait);
744 __u32 left;
745 __u32 sz;
746 BYTE *data_ptr;
748 if (!arg)
749 return -EINVAL;
750 if (!capable(CAP_SYS_RAWIO))
751 return -EPERM;
752 ioc = (BIG_IOCTL_Command_struct *)
753 kmalloc(sizeof(*ioc), GFP_KERNEL);
754 if (!ioc) {
755 status = -ENOMEM;
756 goto cleanup1;
758 if (copy_from_user(ioc, (void *) arg, sizeof(*ioc))) {
759 status = -EFAULT;
760 goto cleanup1;
762 if ((ioc->buf_size < 1) &&
763 (ioc->Request.Type.Direction != XFER_NONE)) {
764 status = -EINVAL;
765 goto cleanup1;
767 /* Check kmalloc limits using all SGs */
768 if (ioc->malloc_size > MAX_KMALLOC_SIZE) {
769 status = -EINVAL;
770 goto cleanup1;
772 if (ioc->buf_size > ioc->malloc_size * MAXSGENTRIES) {
773 status = -EINVAL;
774 goto cleanup1;
776 buff = (unsigned char **) kmalloc(MAXSGENTRIES *
777 sizeof(char *), GFP_KERNEL);
778 if (!buff) {
779 status = -ENOMEM;
780 goto cleanup1;
782 memset(buff, 0, MAXSGENTRIES);
783 buff_size = (int *) kmalloc(MAXSGENTRIES * sizeof(int),
784 GFP_KERNEL);
785 if (!buff_size) {
786 status = -ENOMEM;
787 goto cleanup1;
789 left = ioc->buf_size;
790 data_ptr = (BYTE *) ioc->buf;
791 while (left) {
792 sz = (left > ioc->malloc_size) ? ioc->malloc_size : left;
793 buff_size[sg_used] = sz;
794 buff[sg_used] = kmalloc(sz, GFP_KERNEL);
795 if (buff[sg_used] == NULL) {
796 status = -ENOMEM;
797 goto cleanup1;
799 if (ioc->Request.Type.Direction == XFER_WRITE &&
800 copy_from_user(buff[sg_used], data_ptr, sz)) {
801 status = -ENOMEM;
802 goto cleanup1;
804 left -= sz;
805 data_ptr += sz;
806 sg_used++;
808 if ((c = cmd_alloc(host , 0)) == NULL) {
809 status = -ENOMEM;
810 goto cleanup1;
812 c->cmd_type = CMD_IOCTL_PEND;
813 c->Header.ReplyQueue = 0;
815 if( ioc->buf_size > 0) {
816 c->Header.SGList = sg_used;
817 c->Header.SGTotal= sg_used;
818 } else {
819 c->Header.SGList = 0;
820 c->Header.SGTotal= 0;
822 c->Header.LUN = ioc->LUN_info;
823 c->Header.Tag.lower = c->busaddr;
825 c->Request = ioc->Request;
826 if (ioc->buf_size > 0 ) {
827 int i;
828 for(i=0; i<sg_used; i++) {
829 temp64.val = pci_map_single( host->pdev, buff[i],
830 buff_size[i],
831 PCI_DMA_BIDIRECTIONAL);
832 c->SG[i].Addr.lower = temp64.val32.lower;
833 c->SG[i].Addr.upper = temp64.val32.upper;
834 c->SG[i].Len = buff_size[i];
835 c->SG[i].Ext = 0; /* we are not chaining */
838 c->waiting = &wait;
839 /* Put the request on the tail of the request queue */
840 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
841 addQ(&host->reqQ, c);
842 host->Qdepth++;
843 start_io(host);
844 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
845 wait_for_completion(&wait);
846 /* unlock the buffers from DMA */
847 for(i=0; i<sg_used; i++) {
848 temp64.val32.lower = c->SG[i].Addr.lower;
849 temp64.val32.upper = c->SG[i].Addr.upper;
850 pci_unmap_single( host->pdev, (dma_addr_t) temp64.val,
851 buff_size[i], PCI_DMA_BIDIRECTIONAL);
853 /* Copy the error information out */
854 ioc->error_info = *(c->err_info);
855 if (copy_to_user((void *) arg, ioc, sizeof(*ioc))) {
856 cmd_free(host, c, 0);
857 status = -EFAULT;
858 goto cleanup1;
860 if (ioc->Request.Type.Direction == XFER_READ) {
861 /* Copy the data out of the buffer we created */
862 BYTE *ptr = (BYTE *) ioc->buf;
863 for(i=0; i< sg_used; i++) {
864 if (copy_to_user(ptr, buff[i], buff_size[i])) {
865 cmd_free(host, c, 0);
866 status = -EFAULT;
867 goto cleanup1;
869 ptr += buff_size[i];
872 cmd_free(host, c, 0);
873 status = 0;
874 cleanup1:
875 if (buff) {
876 for(i=0; i<sg_used; i++)
877 if(buff[i] != NULL)
878 kfree(buff[i]);
879 kfree(buff);
881 if (buff_size)
882 kfree(buff_size);
883 if (ioc)
884 kfree(ioc);
885 return(status);
887 default:
888 return -EBADRQC;
893 static int cciss_revalidate(struct gendisk *disk)
895 drive_info_struct *drv = disk->private_data;
896 set_capacity(disk, drv->nr_blocks);
897 return 0;
901 * revalidate_allvol is for online array config utilities. After a
902 * utility reconfigures the drives in the array, it can use this function
903 * (through an ioctl) to make the driver zap any previous disk structs for
904 * that controller and get new ones.
906 * Right now I'm using the getgeometry() function to do this, but this
907 * function should probably be finer grained and allow you to revalidate one
908 * particualar logical volume (instead of all of them on a particular
909 * controller).
911 static int revalidate_allvol(ctlr_info_t *host)
913 int ctlr = host->ctlr, i;
914 unsigned long flags;
916 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
917 if (host->usage_count > 1) {
918 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
919 printk(KERN_WARNING "cciss: Device busy for volume"
920 " revalidation (usage=%d)\n", host->usage_count);
921 return -EBUSY;
923 host->usage_count++;
924 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
926 for(i=0; i< NWD; i++) {
927 struct gendisk *disk = host->gendisk[i];
928 if (disk->flags & GENHD_FL_UP)
929 del_gendisk(disk);
933 * Set the partition and block size structures for all volumes
934 * on this controller to zero. We will reread all of this data
936 memset(host->drv, 0, sizeof(drive_info_struct)
937 * CISS_MAX_LUN);
939 * Tell the array controller not to give us any interrupts while
940 * we check the new geometry. Then turn interrupts back on when
941 * we're done.
943 host->access.set_intr_mask(host, CCISS_INTR_OFF);
944 cciss_getgeometry(ctlr);
945 host->access.set_intr_mask(host, CCISS_INTR_ON);
947 /* Loop through each real device */
948 for (i = 0; i < NWD; i++) {
949 struct gendisk *disk = host->gendisk[i];
950 drive_info_struct *drv = &(host->drv[i]);
951 if (!drv->nr_blocks)
952 continue;
953 blk_queue_hardsect_size(host->queue, drv->block_size);
954 set_capacity(disk, drv->nr_blocks);
955 add_disk(disk);
957 host->usage_count--;
958 return 0;
961 static int deregister_disk(struct gendisk *disk)
963 unsigned long flags;
964 ctlr_info_t *h = get_host(disk);
965 drive_info_struct *drv = get_drv(disk);
966 int ctlr = h->ctlr;
968 if (!capable(CAP_SYS_RAWIO))
969 return -EPERM;
971 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
972 /* make sure logical volume is NOT is use */
973 if( drv->usage_count > 1) {
974 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
975 return -EBUSY;
977 drv->usage_count++;
978 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
980 /* invalidate the devices and deregister the disk */
981 if (disk->flags & GENHD_FL_UP)
982 del_gendisk(disk);
983 /* check to see if it was the last disk */
984 if (drv == h->drv + h->highest_lun) {
985 /* if so, find the new hightest lun */
986 int i, newhighest =-1;
987 for(i=0; i<h->highest_lun; i++) {
988 /* if the disk has size > 0, it is available */
989 if (h->drv[i].nr_blocks)
990 newhighest = i;
992 h->highest_lun = newhighest;
995 --h->num_luns;
996 /* zero out the disk size info */
997 drv->nr_blocks = 0;
998 drv->block_size = 0;
999 drv->cylinders = 0;
1000 drv->LunID = 0;
1001 return(0);
1003 static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
1004 size_t size,
1005 unsigned int use_unit_num, /* 0: address the controller,
1006 1: address logical volume log_unit,
1007 2: periph device address is scsi3addr */
1008 unsigned int log_unit, __u8 page_code, unsigned char *scsi3addr,
1009 int cmd_type)
1011 ctlr_info_t *h= hba[ctlr];
1012 u64bit buff_dma_handle;
1013 int status = IO_OK;
1015 c->cmd_type = CMD_IOCTL_PEND;
1016 c->Header.ReplyQueue = 0;
1017 if( buff != NULL) {
1018 c->Header.SGList = 1;
1019 c->Header.SGTotal= 1;
1020 } else {
1021 c->Header.SGList = 0;
1022 c->Header.SGTotal= 0;
1024 c->Header.Tag.lower = c->busaddr;
1026 c->Request.Type.Type = cmd_type;
1027 if (cmd_type == TYPE_CMD) {
1028 switch(cmd) {
1029 case CISS_INQUIRY:
1030 /* If the logical unit number is 0 then, this is going
1031 to controller so It's a physical command
1032 mode = 0 target = 0. So we have nothing to write.
1033 otherwise, if use_unit_num == 1,
1034 mode = 1(volume set addressing) target = LUNID
1035 otherwise, if use_unit_num == 2,
1036 mode = 0(periph dev addr) target = scsi3addr */
1037 if (use_unit_num == 1) {
1038 c->Header.LUN.LogDev.VolId=
1039 h->drv[log_unit].LunID;
1040 c->Header.LUN.LogDev.Mode = 1;
1041 } else if (use_unit_num == 2) {
1042 memcpy(c->Header.LUN.LunAddrBytes,scsi3addr,8);
1043 c->Header.LUN.LogDev.Mode = 0;
1045 /* are we trying to read a vital product page */
1046 if(page_code != 0) {
1047 c->Request.CDB[1] = 0x01;
1048 c->Request.CDB[2] = page_code;
1050 c->Request.CDBLen = 6;
1051 c->Request.Type.Attribute = ATTR_SIMPLE;
1052 c->Request.Type.Direction = XFER_READ;
1053 c->Request.Timeout = 0;
1054 c->Request.CDB[0] = CISS_INQUIRY;
1055 c->Request.CDB[4] = size & 0xFF;
1056 break;
1057 case CISS_REPORT_LOG:
1058 case CISS_REPORT_PHYS:
1059 /* Talking to controller so It's a physical command
1060 mode = 00 target = 0. Nothing to write.
1062 c->Request.CDBLen = 12;
1063 c->Request.Type.Attribute = ATTR_SIMPLE;
1064 c->Request.Type.Direction = XFER_READ;
1065 c->Request.Timeout = 0;
1066 c->Request.CDB[0] = cmd;
1067 c->Request.CDB[6] = (size >> 24) & 0xFF; //MSB
1068 c->Request.CDB[7] = (size >> 16) & 0xFF;
1069 c->Request.CDB[8] = (size >> 8) & 0xFF;
1070 c->Request.CDB[9] = size & 0xFF;
1071 break;
1073 case CCISS_READ_CAPACITY:
1074 c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID;
1075 c->Header.LUN.LogDev.Mode = 1;
1076 c->Request.CDBLen = 10;
1077 c->Request.Type.Attribute = ATTR_SIMPLE;
1078 c->Request.Type.Direction = XFER_READ;
1079 c->Request.Timeout = 0;
1080 c->Request.CDB[0] = cmd;
1081 break;
1082 case CCISS_CACHE_FLUSH:
1083 c->Request.CDBLen = 12;
1084 c->Request.Type.Attribute = ATTR_SIMPLE;
1085 c->Request.Type.Direction = XFER_WRITE;
1086 c->Request.Timeout = 0;
1087 c->Request.CDB[0] = BMIC_WRITE;
1088 c->Request.CDB[6] = BMIC_CACHE_FLUSH;
1089 break;
1090 default:
1091 printk(KERN_WARNING
1092 "cciss%d: Unknown Command 0x%c\n", ctlr, cmd);
1093 return(IO_ERROR);
1095 } else if (cmd_type == TYPE_MSG) {
1096 switch (cmd) {
1097 case 3: /* No-Op message */
1098 c->Request.CDBLen = 1;
1099 c->Request.Type.Attribute = ATTR_SIMPLE;
1100 c->Request.Type.Direction = XFER_WRITE;
1101 c->Request.Timeout = 0;
1102 c->Request.CDB[0] = cmd;
1103 break;
1104 default:
1105 printk(KERN_WARNING
1106 "cciss%d: unknown message type %d\n",
1107 ctlr, cmd);
1108 return IO_ERROR;
1110 } else {
1111 printk(KERN_WARNING
1112 "cciss%d: unknown command type %d\n", ctlr, cmd_type);
1113 return IO_ERROR;
1115 /* Fill in the scatter gather information */
1116 if (size > 0) {
1117 buff_dma_handle.val = (__u64) pci_map_single(h->pdev,
1118 buff, size, PCI_DMA_BIDIRECTIONAL);
1119 c->SG[0].Addr.lower = buff_dma_handle.val32.lower;
1120 c->SG[0].Addr.upper = buff_dma_handle.val32.upper;
1121 c->SG[0].Len = size;
1122 c->SG[0].Ext = 0; /* we are not chaining */
1124 return status;
1126 static int sendcmd_withirq(__u8 cmd,
1127 int ctlr,
1128 void *buff,
1129 size_t size,
1130 unsigned int use_unit_num,
1131 unsigned int log_unit,
1132 __u8 page_code,
1133 int cmd_type)
1135 ctlr_info_t *h = hba[ctlr];
1136 CommandList_struct *c;
1137 u64bit buff_dma_handle;
1138 unsigned long flags;
1139 int return_status;
1140 DECLARE_COMPLETION(wait);
1142 if ((c = cmd_alloc(h , 0)) == NULL)
1143 return -ENOMEM;
1144 return_status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num,
1145 log_unit, page_code, NULL, cmd_type);
1146 if (return_status != IO_OK) {
1147 cmd_free(h, c, 0);
1148 return return_status;
1150 resend_cmd2:
1151 c->waiting = &wait;
1153 /* Put the request on the tail of the queue and send it */
1154 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
1155 addQ(&h->reqQ, c);
1156 h->Qdepth++;
1157 start_io(h);
1158 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
1160 wait_for_completion(&wait);
1162 if(c->err_info->CommandStatus != 0)
1163 { /* an error has occurred */
1164 switch(c->err_info->CommandStatus)
1166 case CMD_TARGET_STATUS:
1167 printk(KERN_WARNING "cciss: cmd %p has "
1168 " completed with errors\n", c);
1169 if( c->err_info->ScsiStatus)
1171 printk(KERN_WARNING "cciss: cmd %p "
1172 "has SCSI Status = %x\n",
1174 c->err_info->ScsiStatus);
1177 break;
1178 case CMD_DATA_UNDERRUN:
1179 case CMD_DATA_OVERRUN:
1180 /* expected for inquire and report lun commands */
1181 break;
1182 case CMD_INVALID:
1183 printk(KERN_WARNING "cciss: Cmd %p is "
1184 "reported invalid\n", c);
1185 return_status = IO_ERROR;
1186 break;
1187 case CMD_PROTOCOL_ERR:
1188 printk(KERN_WARNING "cciss: cmd %p has "
1189 "protocol error \n", c);
1190 return_status = IO_ERROR;
1191 break;
1192 case CMD_HARDWARE_ERR:
1193 printk(KERN_WARNING "cciss: cmd %p had "
1194 " hardware error\n", c);
1195 return_status = IO_ERROR;
1196 break;
1197 case CMD_CONNECTION_LOST:
1198 printk(KERN_WARNING "cciss: cmd %p had "
1199 "connection lost\n", c);
1200 return_status = IO_ERROR;
1201 break;
1202 case CMD_ABORTED:
1203 printk(KERN_WARNING "cciss: cmd %p was "
1204 "aborted\n", c);
1205 return_status = IO_ERROR;
1206 break;
1207 case CMD_ABORT_FAILED:
1208 printk(KERN_WARNING "cciss: cmd %p reports "
1209 "abort failed\n", c);
1210 return_status = IO_ERROR;
1211 break;
1212 case CMD_UNSOLICITED_ABORT:
1213 printk(KERN_WARNING
1214 "cciss%d: unsolicited abort %p\n",
1215 ctlr, c);
1216 if (c->retry_count < MAX_CMD_RETRIES) {
1217 printk(KERN_WARNING
1218 "cciss%d: retrying %p\n",
1219 ctlr, c);
1220 c->retry_count++;
1221 /* erase the old error information */
1222 memset(c->err_info, 0,
1223 sizeof(ErrorInfo_struct));
1224 return_status = IO_OK;
1225 INIT_COMPLETION(wait);
1226 goto resend_cmd2;
1228 return_status = IO_ERROR;
1229 break;
1230 default:
1231 printk(KERN_WARNING "cciss: cmd %p returned "
1232 "unknown status %x\n", c,
1233 c->err_info->CommandStatus);
1234 return_status = IO_ERROR;
1237 /* unlock the buffers from DMA */
1238 pci_unmap_single( h->pdev, (dma_addr_t) buff_dma_handle.val,
1239 size, PCI_DMA_BIDIRECTIONAL);
1240 cmd_free(h, c, 0);
1241 return(return_status);
1244 static void cciss_geometry_inquiry(int ctlr, int logvol,
1245 int withirq, unsigned int total_size,
1246 unsigned int block_size, InquiryData_struct *inq_buff,
1247 drive_info_struct *drv)
1249 int return_code;
1250 memset(inq_buff, 0, sizeof(InquiryData_struct));
1251 if (withirq)
1252 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr,
1253 inq_buff, sizeof(*inq_buff), 1, logvol ,0xC1, TYPE_CMD);
1254 else
1255 return_code = sendcmd(CISS_INQUIRY, ctlr, inq_buff,
1256 sizeof(*inq_buff), 1, logvol ,0xC1, NULL, TYPE_CMD);
1257 if (return_code == IO_OK) {
1258 if(inq_buff->data_byte[8] == 0xFF) {
1259 printk(KERN_WARNING
1260 "cciss: reading geometry failed, volume "
1261 "does not support reading geometry\n");
1262 drv->block_size = block_size;
1263 drv->nr_blocks = total_size;
1264 drv->heads = 255;
1265 drv->sectors = 32; // Sectors per track
1266 drv->cylinders = total_size / 255 / 32;
1267 } else {
1268 drv->block_size = block_size;
1269 drv->nr_blocks = total_size;
1270 drv->heads = inq_buff->data_byte[6];
1271 drv->sectors = inq_buff->data_byte[7];
1272 drv->cylinders = (inq_buff->data_byte[4] & 0xff) << 8;
1273 drv->cylinders += inq_buff->data_byte[5];
1275 } else { /* Get geometry failed */
1276 printk(KERN_WARNING "cciss: reading geometry failed, "
1277 "continuing with default geometry\n");
1278 drv->block_size = block_size;
1279 drv->nr_blocks = total_size;
1280 drv->heads = 255;
1281 drv->sectors = 32; // Sectors per track
1282 drv->cylinders = total_size / 255 / 32;
1284 printk(KERN_INFO " heads= %d, sectors= %d, cylinders= %d\n\n",
1285 drv->heads, drv->sectors, drv->cylinders);
1287 static void
1288 cciss_read_capacity(int ctlr, int logvol, ReadCapdata_struct *buf,
1289 int withirq, unsigned int *total_size, unsigned int *block_size)
1291 int return_code;
1292 memset(buf, 0, sizeof(*buf));
1293 if (withirq)
1294 return_code = sendcmd_withirq(CCISS_READ_CAPACITY,
1295 ctlr, buf, sizeof(*buf), 1, logvol, 0, TYPE_CMD);
1296 else
1297 return_code = sendcmd(CCISS_READ_CAPACITY,
1298 ctlr, buf, sizeof(*buf), 1, logvol, 0, NULL, TYPE_CMD);
1299 if (return_code == IO_OK) {
1300 *total_size = be32_to_cpu(*((__u32 *) &buf->total_size[0]))+1;
1301 *block_size = be32_to_cpu(*((__u32 *) &buf->block_size[0]));
1302 } else { /* read capacity command failed */
1303 printk(KERN_WARNING "cciss: read capacity failed\n");
1304 *total_size = 0;
1305 *block_size = BLOCK_SIZE;
1307 printk(KERN_INFO " blocks= %d block_size= %d\n",
1308 *total_size, *block_size);
1309 return;
1311 static int register_new_disk(ctlr_info_t *h)
1313 struct gendisk *disk;
1314 int ctlr = h->ctlr;
1315 int i;
1316 int num_luns;
1317 int logvol;
1318 int new_lun_found = 0;
1319 int new_lun_index = 0;
1320 int free_index_found = 0;
1321 int free_index = 0;
1322 ReportLunData_struct *ld_buff = NULL;
1323 ReadCapdata_struct *size_buff = NULL;
1324 InquiryData_struct *inq_buff = NULL;
1325 int return_code;
1326 int listlength = 0;
1327 __u32 lunid = 0;
1328 unsigned int block_size;
1329 unsigned int total_size;
1331 if (!capable(CAP_SYS_RAWIO))
1332 return -EPERM;
1333 /* if we have no space in our disk array left to add anything */
1334 if( h->num_luns >= CISS_MAX_LUN)
1335 return -EINVAL;
1337 ld_buff = kmalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
1338 if (ld_buff == NULL)
1339 goto mem_msg;
1340 memset(ld_buff, 0, sizeof(ReportLunData_struct));
1341 size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
1342 if (size_buff == NULL)
1343 goto mem_msg;
1344 inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
1345 if (inq_buff == NULL)
1346 goto mem_msg;
1348 return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff,
1349 sizeof(ReportLunData_struct), 0, 0, 0, TYPE_CMD);
1351 if( return_code == IO_OK)
1354 // printk("LUN Data\n--------------------------\n");
1356 listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[0])) << 24;
1357 listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[1])) << 16;
1358 listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[2])) << 8;
1359 listlength |= 0xff & (unsigned int)(ld_buff->LUNListLength[3]);
1360 } else /* reading number of logical volumes failed */
1362 printk(KERN_WARNING "cciss: report logical volume"
1363 " command failed\n");
1364 listlength = 0;
1365 goto free_err;
1367 num_luns = listlength / 8; // 8 bytes pre entry
1368 if (num_luns > CISS_MAX_LUN)
1370 num_luns = CISS_MAX_LUN;
1372 #ifdef CCISS_DEBUG
1373 printk(KERN_DEBUG "Length = %x %x %x %x = %d\n", ld_buff->LUNListLength[0],
1374 ld_buff->LUNListLength[1], ld_buff->LUNListLength[2],
1375 ld_buff->LUNListLength[3], num_luns);
1376 #endif
1377 for(i=0; i< num_luns; i++)
1379 int j;
1380 int lunID_found = 0;
1382 lunid = (0xff & (unsigned int)(ld_buff->LUN[i][3])) << 24;
1383 lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][2])) << 16;
1384 lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][1])) << 8;
1385 lunid |= 0xff & (unsigned int)(ld_buff->LUN[i][0]);
1387 /* check to see if this is a new lun */
1388 for(j=0; j <= h->highest_lun; j++)
1390 #ifdef CCISS_DEBUG
1391 printk("Checking %d %x against %x\n", j,h->drv[j].LunID,
1392 lunid);
1393 #endif /* CCISS_DEBUG */
1394 if (h->drv[j].LunID == lunid)
1396 lunID_found = 1;
1397 break;
1401 if( lunID_found == 1)
1402 continue;
1403 else
1404 { /* It is the new lun we have been looking for */
1405 #ifdef CCISS_DEBUG
1406 printk("new lun found at %d\n", i);
1407 #endif /* CCISS_DEBUG */
1408 new_lun_index = i;
1409 new_lun_found = 1;
1410 break;
1413 if (!new_lun_found)
1415 printk(KERN_WARNING "cciss: New Logical Volume not found\n");
1416 goto free_err;
1418 /* Now find the free index */
1419 for(i=0; i <CISS_MAX_LUN; i++)
1421 #ifdef CCISS_DEBUG
1422 printk("Checking Index %d\n", i);
1423 #endif /* CCISS_DEBUG */
1424 if(h->drv[i].LunID == 0)
1426 #ifdef CCISS_DEBUG
1427 printk("free index found at %d\n", i);
1428 #endif /* CCISS_DEBUG */
1429 free_index_found = 1;
1430 free_index = i;
1431 break;
1434 if (!free_index_found)
1436 printk(KERN_WARNING "cciss: unable to find free slot for disk\n");
1437 goto free_err;
1440 logvol = free_index;
1441 h->drv[logvol].LunID = lunid;
1442 /* there could be gaps in lun numbers, track hightest */
1443 if(h->highest_lun < lunid)
1444 h->highest_lun = logvol;
1445 cciss_read_capacity(ctlr, logvol, size_buff, 1,
1446 &total_size, &block_size);
1447 cciss_geometry_inquiry(ctlr, logvol, 1, total_size, block_size,
1448 inq_buff, &h->drv[logvol]);
1449 h->drv[logvol].usage_count = 0;
1450 ++h->num_luns;
1451 /* setup partitions per disk */
1452 disk = h->gendisk[logvol];
1453 set_capacity(disk, h->drv[logvol].nr_blocks);
1454 add_disk(disk);
1455 freeret:
1456 kfree(ld_buff);
1457 kfree(size_buff);
1458 kfree(inq_buff);
1459 return (logvol);
1460 mem_msg:
1461 printk(KERN_ERR "cciss: out of memory\n");
1462 free_err:
1463 logvol = -1;
1464 goto freeret;
1467 * Wait polling for a command to complete.
1468 * The memory mapped FIFO is polled for the completion.
1469 * Used only at init time, interrupts from the HBA are disabled.
1471 static unsigned long pollcomplete(int ctlr)
1473 unsigned long done;
1474 int i;
1476 /* Wait (up to 20 seconds) for a command to complete */
1478 for (i = 20 * HZ; i > 0; i--) {
1479 done = hba[ctlr]->access.command_completed(hba[ctlr]);
1480 if (done == FIFO_EMPTY) {
1481 set_current_state(TASK_UNINTERRUPTIBLE);
1482 schedule_timeout(1);
1483 } else
1484 return (done);
1486 /* Invalid address to tell caller we ran out of time */
1487 return 1;
1490 * Send a command to the controller, and wait for it to complete.
1491 * Only used at init time.
1493 static int sendcmd(
1494 __u8 cmd,
1495 int ctlr,
1496 void *buff,
1497 size_t size,
1498 unsigned int use_unit_num, /* 0: address the controller,
1499 1: address logical volume log_unit,
1500 2: periph device address is scsi3addr */
1501 unsigned int log_unit,
1502 __u8 page_code,
1503 unsigned char *scsi3addr,
1504 int cmd_type)
1506 CommandList_struct *c;
1507 int i;
1508 unsigned long complete;
1509 ctlr_info_t *info_p= hba[ctlr];
1510 u64bit buff_dma_handle;
1511 int status;
1513 if ((c = cmd_alloc(info_p, 1)) == NULL) {
1514 printk(KERN_WARNING "cciss: unable to get memory");
1515 return(IO_ERROR);
1517 status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num,
1518 log_unit, page_code, scsi3addr, cmd_type);
1519 if (status != IO_OK) {
1520 cmd_free(info_p, c, 1);
1521 return status;
1523 resend_cmd1:
1525 * Disable interrupt
1527 #ifdef CCISS_DEBUG
1528 printk(KERN_DEBUG "cciss: turning intr off\n");
1529 #endif /* CCISS_DEBUG */
1530 info_p->access.set_intr_mask(info_p, CCISS_INTR_OFF);
1532 /* Make sure there is room in the command FIFO */
1533 /* Actually it should be completely empty at this time. */
1534 for (i = 200000; i > 0; i--)
1536 /* if fifo isn't full go */
1537 if (!(info_p->access.fifo_full(info_p)))
1540 break;
1542 udelay(10);
1543 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
1544 " waiting!\n", ctlr);
1547 * Send the cmd
1549 info_p->access.submit_command(info_p, c);
1550 complete = pollcomplete(ctlr);
1552 #ifdef CCISS_DEBUG
1553 printk(KERN_DEBUG "cciss: command completed\n");
1554 #endif /* CCISS_DEBUG */
1556 if (complete != 1) {
1557 if ( (complete & CISS_ERROR_BIT)
1558 && (complete & ~CISS_ERROR_BIT) == c->busaddr)
1560 /* if data overrun or underun on Report command
1561 ignore it
1563 if (((c->Request.CDB[0] == CISS_REPORT_LOG) ||
1564 (c->Request.CDB[0] == CISS_REPORT_PHYS) ||
1565 (c->Request.CDB[0] == CISS_INQUIRY)) &&
1566 ((c->err_info->CommandStatus ==
1567 CMD_DATA_OVERRUN) ||
1568 (c->err_info->CommandStatus ==
1569 CMD_DATA_UNDERRUN)
1572 complete = c->busaddr;
1573 } else {
1574 if (c->err_info->CommandStatus ==
1575 CMD_UNSOLICITED_ABORT) {
1576 printk(KERN_WARNING "cciss%d: "
1577 "unsolicited abort %p\n",
1578 ctlr, c);
1579 if (c->retry_count < MAX_CMD_RETRIES) {
1580 printk(KERN_WARNING
1581 "cciss%d: retrying %p\n",
1582 ctlr, c);
1583 c->retry_count++;
1584 /* erase the old error */
1585 /* information */
1586 memset(c->err_info, 0,
1587 sizeof(ErrorInfo_struct));
1588 goto resend_cmd1;
1589 } else {
1590 printk(KERN_WARNING
1591 "cciss%d: retried %p too "
1592 "many times\n", ctlr, c);
1593 status = IO_ERROR;
1594 goto cleanup1;
1597 printk(KERN_WARNING "ciss ciss%d: sendcmd"
1598 " Error %x \n", ctlr,
1599 c->err_info->CommandStatus);
1600 printk(KERN_WARNING "ciss ciss%d: sendcmd"
1601 " offensive info\n"
1602 " size %x\n num %x value %x\n", ctlr,
1603 c->err_info->MoreErrInfo.Invalid_Cmd.offense_size,
1604 c->err_info->MoreErrInfo.Invalid_Cmd.offense_num,
1605 c->err_info->MoreErrInfo.Invalid_Cmd.offense_value);
1606 status = IO_ERROR;
1607 goto cleanup1;
1610 if (complete != c->busaddr) {
1611 printk( KERN_WARNING "cciss cciss%d: SendCmd "
1612 "Invalid command list address returned! (%lx)\n",
1613 ctlr, complete);
1614 status = IO_ERROR;
1615 goto cleanup1;
1617 } else {
1618 printk( KERN_WARNING
1619 "cciss cciss%d: SendCmd Timeout out, "
1620 "No command list address returned!\n",
1621 ctlr);
1622 status = IO_ERROR;
1625 cleanup1:
1626 /* unlock the data buffer from DMA */
1627 pci_unmap_single(info_p->pdev, (dma_addr_t) buff_dma_handle.val,
1628 size, PCI_DMA_BIDIRECTIONAL);
1629 cmd_free(info_p, c, 1);
1630 return (status);
1633 * Map (physical) PCI mem into (virtual) kernel space
1635 static ulong remap_pci_mem(ulong base, ulong size)
1637 ulong page_base = ((ulong) base) & PAGE_MASK;
1638 ulong page_offs = ((ulong) base) - page_base;
1639 ulong page_remapped = (ulong) ioremap(page_base, page_offs+size);
1641 return (ulong) (page_remapped ? (page_remapped + page_offs) : 0UL);
1645 * Enqueuing and dequeuing functions for cmdlists.
1647 static inline void addQ(CommandList_struct **Qptr, CommandList_struct *c)
1649 if (*Qptr == NULL) {
1650 *Qptr = c;
1651 c->next = c->prev = c;
1652 } else {
1653 c->prev = (*Qptr)->prev;
1654 c->next = (*Qptr);
1655 (*Qptr)->prev->next = c;
1656 (*Qptr)->prev = c;
1660 static inline CommandList_struct *removeQ(CommandList_struct **Qptr,
1661 CommandList_struct *c)
1663 if (c && c->next != c) {
1664 if (*Qptr == c) *Qptr = c->next;
1665 c->prev->next = c->next;
1666 c->next->prev = c->prev;
1667 } else {
1668 *Qptr = NULL;
1670 return c;
1674 * Takes jobs of the Q and sends them to the hardware, then puts it on
1675 * the Q to wait for completion.
1677 static void start_io( ctlr_info_t *h)
1679 CommandList_struct *c;
1681 while(( c = h->reqQ) != NULL )
1683 /* can't do anything if fifo is full */
1684 if ((h->access.fifo_full(h))) {
1685 printk(KERN_WARNING "cciss: fifo full\n");
1686 break;
1689 /* Get the frist entry from the Request Q */
1690 removeQ(&(h->reqQ), c);
1691 h->Qdepth--;
1693 /* Tell the controller execute command */
1694 h->access.submit_command(h, c);
1696 /* Put job onto the completed Q */
1697 addQ (&(h->cmpQ), c);
1701 static inline void complete_buffers(struct bio *bio, int status)
1703 while (bio) {
1704 struct bio *xbh = bio->bi_next;
1705 int nr_sectors = bio_sectors(bio);
1707 bio->bi_next = NULL;
1708 blk_finished_io(len);
1709 bio_endio(bio, nr_sectors << 9, status ? 0 : -EIO);
1710 bio = xbh;
1714 /* Assumes that CCISS_LOCK(h->ctlr) is held. */
1715 /* Zeros out the error record and then resends the command back */
1716 /* to the controller */
1717 static inline void resend_cciss_cmd( ctlr_info_t *h, CommandList_struct *c)
1719 /* erase the old error information */
1720 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
1722 /* add it to software queue and then send it to the controller */
1723 addQ(&(h->reqQ),c);
1724 h->Qdepth++;
1725 if(h->Qdepth > h->maxQsinceinit)
1726 h->maxQsinceinit = h->Qdepth;
1728 start_io(h);
1730 /* checks the status of the job and calls complete buffers to mark all
1731 * buffers for the completed job.
1733 static inline void complete_command( ctlr_info_t *h, CommandList_struct *cmd,
1734 int timeout)
1736 int status = 1;
1737 int i;
1738 int retry_cmd = 0;
1739 u64bit temp64;
1741 if (timeout)
1742 status = 0;
1744 if(cmd->err_info->CommandStatus != 0)
1745 { /* an error has occurred */
1746 switch(cmd->err_info->CommandStatus)
1748 unsigned char sense_key;
1749 case CMD_TARGET_STATUS:
1750 status = 0;
1752 if( cmd->err_info->ScsiStatus == 0x02)
1754 printk(KERN_WARNING "cciss: cmd %p "
1755 "has CHECK CONDITION "
1756 " byte 2 = 0x%x\n", cmd,
1757 cmd->err_info->SenseInfo[2]
1759 /* check the sense key */
1760 sense_key = 0xf &
1761 cmd->err_info->SenseInfo[2];
1762 /* no status or recovered error */
1763 if((sense_key == 0x0) ||
1764 (sense_key == 0x1))
1766 status = 1;
1768 } else
1770 printk(KERN_WARNING "cciss: cmd %p "
1771 "has SCSI Status 0x%x\n",
1772 cmd, cmd->err_info->ScsiStatus);
1774 break;
1775 case CMD_DATA_UNDERRUN:
1776 printk(KERN_WARNING "cciss: cmd %p has"
1777 " completed with data underrun "
1778 "reported\n", cmd);
1779 break;
1780 case CMD_DATA_OVERRUN:
1781 printk(KERN_WARNING "cciss: cmd %p has"
1782 " completed with data overrun "
1783 "reported\n", cmd);
1784 break;
1785 case CMD_INVALID:
1786 printk(KERN_WARNING "cciss: cmd %p is "
1787 "reported invalid\n", cmd);
1788 status = 0;
1789 break;
1790 case CMD_PROTOCOL_ERR:
1791 printk(KERN_WARNING "cciss: cmd %p has "
1792 "protocol error \n", cmd);
1793 status = 0;
1794 break;
1795 case CMD_HARDWARE_ERR:
1796 printk(KERN_WARNING "cciss: cmd %p had "
1797 " hardware error\n", cmd);
1798 status = 0;
1799 break;
1800 case CMD_CONNECTION_LOST:
1801 printk(KERN_WARNING "cciss: cmd %p had "
1802 "connection lost\n", cmd);
1803 status=0;
1804 break;
1805 case CMD_ABORTED:
1806 printk(KERN_WARNING "cciss: cmd %p was "
1807 "aborted\n", cmd);
1808 status=0;
1809 break;
1810 case CMD_ABORT_FAILED:
1811 printk(KERN_WARNING "cciss: cmd %p reports "
1812 "abort failed\n", cmd);
1813 status=0;
1814 break;
1815 case CMD_UNSOLICITED_ABORT:
1816 printk(KERN_WARNING "cciss%d: unsolicited "
1817 "abort %p\n", h->ctlr, cmd);
1818 if (cmd->retry_count < MAX_CMD_RETRIES) {
1819 retry_cmd=1;
1820 printk(KERN_WARNING
1821 "cciss%d: retrying %p\n",
1822 h->ctlr, cmd);
1823 cmd->retry_count++;
1824 } else
1825 printk(KERN_WARNING
1826 "cciss%d: %p retried too "
1827 "many times\n", h->ctlr, cmd);
1828 status=0;
1829 break;
1830 case CMD_TIMEOUT:
1831 printk(KERN_WARNING "cciss: cmd %p timedout\n",
1832 cmd);
1833 status=0;
1834 break;
1835 default:
1836 printk(KERN_WARNING "cciss: cmd %p returned "
1837 "unknown status %x\n", cmd,
1838 cmd->err_info->CommandStatus);
1839 status=0;
1842 /* We need to return this command */
1843 if(retry_cmd) {
1844 resend_cciss_cmd(h,cmd);
1845 return;
1847 /* command did not need to be retried */
1848 /* unmap the DMA mapping for all the scatter gather elements */
1849 for(i=0; i<cmd->Header.SGList; i++) {
1850 temp64.val32.lower = cmd->SG[i].Addr.lower;
1851 temp64.val32.upper = cmd->SG[i].Addr.upper;
1852 pci_unmap_page(hba[cmd->ctlr]->pdev,
1853 temp64.val, cmd->SG[i].Len,
1854 (cmd->Request.Type.Direction == XFER_READ) ?
1855 PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE);
1857 complete_buffers(cmd->rq->bio, status);
1859 #ifdef CCISS_DEBUG
1860 printk("Done with %p\n", cmd->rq);
1861 #endif /* CCISS_DEBUG */
1863 end_that_request_last(cmd->rq);
1864 cmd_free(h,cmd,1);
1868 * Get a request and submit it to the controller.
1870 static void do_cciss_request(request_queue_t *q)
1872 ctlr_info_t *h= q->queuedata;
1873 CommandList_struct *c;
1874 int start_blk, seg;
1875 struct request *creq;
1876 u64bit temp64;
1877 struct scatterlist tmp_sg[MAXSGENTRIES];
1878 drive_info_struct *drv;
1879 int i, dir;
1881 if (blk_queue_plugged(q))
1882 goto startio;
1884 queue:
1885 creq = elv_next_request(q);
1886 if (!creq)
1887 goto startio;
1889 if (creq->nr_phys_segments > MAXSGENTRIES)
1890 BUG();
1892 if (( c = cmd_alloc(h, 1)) == NULL)
1893 goto full;
1895 blkdev_dequeue_request(creq);
1897 spin_unlock_irq(q->queue_lock);
1899 c->cmd_type = CMD_RWREQ;
1900 c->rq = creq;
1902 /* fill in the request */
1903 drv = creq->rq_disk->private_data;
1904 c->Header.ReplyQueue = 0; // unused in simple mode
1905 c->Header.Tag.lower = c->busaddr; // use the physical address the cmd block for tag
1906 c->Header.LUN.LogDev.VolId= drv->LunID;
1907 c->Header.LUN.LogDev.Mode = 1;
1908 c->Request.CDBLen = 10; // 12 byte commands not in FW yet;
1909 c->Request.Type.Type = TYPE_CMD; // It is a command.
1910 c->Request.Type.Attribute = ATTR_SIMPLE;
1911 c->Request.Type.Direction =
1912 (rq_data_dir(creq) == READ) ? XFER_READ: XFER_WRITE;
1913 c->Request.Timeout = 0; // Don't time out
1914 c->Request.CDB[0] = (rq_data_dir(creq) == READ) ? CCISS_READ : CCISS_WRITE;
1915 start_blk = creq->sector;
1916 #ifdef CCISS_DEBUG
1917 printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n",(int) creq->sector,
1918 (int) creq->nr_sectors);
1919 #endif /* CCISS_DEBUG */
1921 seg = blk_rq_map_sg(q, creq, tmp_sg);
1923 /* get the DMA records for the setup */
1924 if (c->Request.Type.Direction == XFER_READ)
1925 dir = PCI_DMA_FROMDEVICE;
1926 else
1927 dir = PCI_DMA_TODEVICE;
1929 for (i=0; i<seg; i++)
1931 c->SG[i].Len = tmp_sg[i].length;
1932 temp64.val = (__u64) pci_map_page(h->pdev, tmp_sg[i].page,
1933 tmp_sg[i].offset, tmp_sg[i].length,
1934 dir);
1935 c->SG[i].Addr.lower = temp64.val32.lower;
1936 c->SG[i].Addr.upper = temp64.val32.upper;
1937 c->SG[i].Ext = 0; // we are not chaining
1939 /* track how many SG entries we are using */
1940 if( seg > h->maxSG)
1941 h->maxSG = seg;
1943 #ifdef CCISS_DEBUG
1944 printk(KERN_DEBUG "cciss: Submitting %d sectors in %d segments\n", creq->nr_sectors, seg);
1945 #endif /* CCISS_DEBUG */
1947 c->Header.SGList = c->Header.SGTotal = seg;
1948 c->Request.CDB[1]= 0;
1949 c->Request.CDB[2]= (start_blk >> 24) & 0xff; //MSB
1950 c->Request.CDB[3]= (start_blk >> 16) & 0xff;
1951 c->Request.CDB[4]= (start_blk >> 8) & 0xff;
1952 c->Request.CDB[5]= start_blk & 0xff;
1953 c->Request.CDB[6]= 0; // (sect >> 24) & 0xff; MSB
1954 c->Request.CDB[7]= (creq->nr_sectors >> 8) & 0xff;
1955 c->Request.CDB[8]= creq->nr_sectors & 0xff;
1956 c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
1958 spin_lock_irq(q->queue_lock);
1960 addQ(&(h->reqQ),c);
1961 h->Qdepth++;
1962 if(h->Qdepth > h->maxQsinceinit)
1963 h->maxQsinceinit = h->Qdepth;
1965 goto queue;
1966 full:
1967 blk_stop_queue(q);
1968 startio:
1969 start_io(h);
1972 static irqreturn_t do_cciss_intr(int irq, void *dev_id, struct pt_regs *regs)
1974 ctlr_info_t *h = dev_id;
1975 CommandList_struct *c;
1976 unsigned long flags;
1977 __u32 a, a1;
1980 /* Is this interrupt for us? */
1981 if ( h->access.intr_pending(h) == 0)
1982 return IRQ_NONE;
1985 * If there are completed commands in the completion queue,
1986 * we had better do something about it.
1988 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
1989 while( h->access.intr_pending(h))
1991 while((a = h->access.command_completed(h)) != FIFO_EMPTY)
1993 a1 = a;
1994 a &= ~3;
1995 if ((c = h->cmpQ) == NULL)
1997 printk(KERN_WARNING "cciss: Completion of %08lx ignored\n", (unsigned long)a1);
1998 continue;
2000 while(c->busaddr != a) {
2001 c = c->next;
2002 if (c == h->cmpQ)
2003 break;
2006 * If we've found the command, take it off the
2007 * completion Q and free it
2009 if (c->busaddr == a) {
2010 removeQ(&h->cmpQ, c);
2011 if (c->cmd_type == CMD_RWREQ) {
2012 complete_command(h, c, 0);
2013 } else if (c->cmd_type == CMD_IOCTL_PEND) {
2014 complete(c->waiting);
2016 # ifdef CONFIG_CISS_SCSI_TAPE
2017 else if (c->cmd_type == CMD_SCSI)
2018 complete_scsi_command(c, 0, a1);
2019 # endif
2020 continue;
2026 * See if we can queue up some more IO
2028 blk_start_queue(h->queue);
2029 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
2030 return IRQ_HANDLED;
2033 * We cannot read the structure directly, for portablity we must use
2034 * the io functions.
2035 * This is for debug only.
2037 #ifdef CCISS_DEBUG
2038 static void print_cfg_table( CfgTable_struct *tb)
2040 int i;
2041 char temp_name[17];
2043 printk("Controller Configuration information\n");
2044 printk("------------------------------------\n");
2045 for(i=0;i<4;i++)
2046 temp_name[i] = readb(&(tb->Signature[i]));
2047 temp_name[4]='\0';
2048 printk(" Signature = %s\n", temp_name);
2049 printk(" Spec Number = %d\n", readl(&(tb->SpecValence)));
2050 printk(" Transport methods supported = 0x%x\n",
2051 readl(&(tb-> TransportSupport)));
2052 printk(" Transport methods active = 0x%x\n",
2053 readl(&(tb->TransportActive)));
2054 printk(" Requested transport Method = 0x%x\n",
2055 readl(&(tb->HostWrite.TransportRequest)));
2056 printk(" Coalese Interrupt Delay = 0x%x\n",
2057 readl(&(tb->HostWrite.CoalIntDelay)));
2058 printk(" Coalese Interrupt Count = 0x%x\n",
2059 readl(&(tb->HostWrite.CoalIntCount)));
2060 printk(" Max outstanding commands = 0x%d\n",
2061 readl(&(tb->CmdsOutMax)));
2062 printk(" Bus Types = 0x%x\n", readl(&(tb-> BusTypes)));
2063 for(i=0;i<16;i++)
2064 temp_name[i] = readb(&(tb->ServerName[i]));
2065 temp_name[16] = '\0';
2066 printk(" Server Name = %s\n", temp_name);
2067 printk(" Heartbeat Counter = 0x%x\n\n\n",
2068 readl(&(tb->HeartBeat)));
2070 #endif /* CCISS_DEBUG */
2072 static void release_io_mem(ctlr_info_t *c)
2074 /* if IO mem was not protected do nothing */
2075 if( c->io_mem_addr == 0)
2076 return;
2077 release_region(c->io_mem_addr, c->io_mem_length);
2078 c->io_mem_addr = 0;
2079 c->io_mem_length = 0;
2081 static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
2083 ushort vendor_id, device_id, command;
2084 unchar cache_line_size, latency_timer;
2085 unchar irq, revision;
2086 uint addr[6];
2087 __u32 board_id, scratchpad = 0;
2088 int cfg_offset;
2089 int cfg_base_addr;
2090 int cfg_base_addr_index;
2091 int i;
2093 if (pci_enable_device(pdev))
2095 printk(KERN_ERR "cciss: Unable to Enable PCI device\n");
2096 return( -1);
2098 if (pci_set_dma_mask(pdev, CCISS_DMA_MASK ) != 0)
2100 printk(KERN_ERR "cciss: Unable to set DMA mask\n");
2101 return(-1);
2104 vendor_id = pdev->vendor;
2105 device_id = pdev->device;
2106 irq = pdev->irq;
2108 for(i=0; i<6; i++)
2109 addr[i] = pdev->resource[i].start;
2111 (void) pci_read_config_word(pdev, PCI_COMMAND,&command);
2112 (void) pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
2113 (void) pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE,
2114 &cache_line_size);
2115 (void) pci_read_config_byte(pdev, PCI_LATENCY_TIMER,
2116 &latency_timer);
2117 (void) pci_read_config_dword(pdev, PCI_SUBSYSTEM_VENDOR_ID,
2118 &board_id);
2120 /* check to see if controller has been disabled */
2121 if(!(command & 0x02))
2123 printk(KERN_WARNING "cciss: controller appears to be disabled\n");
2124 return(-1);
2127 /* search for our IO range so we can protect it */
2128 for(i=0; i<6; i++)
2130 /* is this an IO range */
2131 if( pdev->resource[i].flags & 0x01 )
2133 c->io_mem_addr = pdev->resource[i].start;
2134 c->io_mem_length = pdev->resource[i].end -
2135 pdev->resource[i].start +1;
2136 #ifdef CCISS_DEBUG
2137 printk("IO value found base_addr[%d] %lx %lx\n", i,
2138 c->io_mem_addr, c->io_mem_length);
2139 #endif /* CCISS_DEBUG */
2140 /* register the IO range */
2141 if(!request_region( c->io_mem_addr,
2142 c->io_mem_length, "cciss"))
2144 printk(KERN_WARNING "cciss I/O memory range already in use addr=%lx length=%ld\n",
2145 c->io_mem_addr, c->io_mem_length);
2146 c->io_mem_addr= 0;
2147 c->io_mem_length = 0;
2149 break;
2153 #ifdef CCISS_DEBUG
2154 printk("vendor_id = %x\n", vendor_id);
2155 printk("device_id = %x\n", device_id);
2156 printk("command = %x\n", command);
2157 for(i=0; i<6; i++)
2158 printk("addr[%d] = %x\n", i, addr[i]);
2159 printk("revision = %x\n", revision);
2160 printk("irq = %x\n", irq);
2161 printk("cache_line_size = %x\n", cache_line_size);
2162 printk("latency_timer = %x\n", latency_timer);
2163 printk("board_id = %x\n", board_id);
2164 #endif /* CCISS_DEBUG */
2166 c->intr = irq;
2169 * Memory base addr is first addr , the second points to the config
2170 * table
2173 c->paddr = addr[0] ; /* addressing mode bits already removed */
2174 #ifdef CCISS_DEBUG
2175 printk("address 0 = %x\n", c->paddr);
2176 #endif /* CCISS_DEBUG */
2177 c->vaddr = remap_pci_mem(c->paddr, 200);
2179 /* Wait for the board to become ready. (PCI hotplug needs this.)
2180 * We poll for up to 120 secs, once per 100ms. */
2181 for (i=0; i < 1200; i++) {
2182 scratchpad = readl(c->vaddr + SA5_SCRATCHPAD_OFFSET);
2183 if (scratchpad == CCISS_FIRMWARE_READY)
2184 break;
2185 set_current_state(TASK_INTERRUPTIBLE);
2186 schedule_timeout(HZ / 10); /* wait 100ms */
2188 if (scratchpad != CCISS_FIRMWARE_READY) {
2189 printk(KERN_WARNING "cciss: Board not ready. Timed out.\n");
2190 return -1;
2193 /* get the address index number */
2194 cfg_base_addr = readl(c->vaddr + SA5_CTCFG_OFFSET);
2195 /* I am not prepared to deal with a 64 bit address value */
2196 cfg_base_addr &= 0xffff;
2197 #ifdef CCISS_DEBUG
2198 printk("cfg base address = %x\n", cfg_base_addr);
2199 #endif /* CCISS_DEBUG */
2200 cfg_base_addr_index = (cfg_base_addr - PCI_BASE_ADDRESS_0)/4;
2201 #ifdef CCISS_DEBUG
2202 printk("cfg base address index = %x\n", cfg_base_addr_index);
2203 #endif /* CCISS_DEBUG */
2205 cfg_offset = readl(c->vaddr + SA5_CTMEM_OFFSET);
2206 #ifdef CCISS_DEBUG
2207 printk("cfg offset = %x\n", cfg_offset);
2208 #endif /* CCISS_DEBUG */
2209 c->cfgtable = (CfgTable_struct *)
2210 remap_pci_mem((addr[cfg_base_addr_index] & 0xfffffff0)
2211 + cfg_offset, sizeof(CfgTable_struct));
2212 c->board_id = board_id;
2214 #ifdef CCISS_DEBUG
2215 print_cfg_table(c->cfgtable);
2216 #endif /* CCISS_DEBUG */
2218 for(i=0; i<NR_PRODUCTS; i++) {
2219 if (board_id == products[i].board_id) {
2220 c->product_name = products[i].product_name;
2221 c->access = *(products[i].access);
2222 break;
2225 if (i == NR_PRODUCTS) {
2226 printk(KERN_WARNING "cciss: Sorry, I don't know how"
2227 " to access the Smart Array controller %08lx\n",
2228 (unsigned long)board_id);
2229 return -1;
2231 if ( (readb(&c->cfgtable->Signature[0]) != 'C') ||
2232 (readb(&c->cfgtable->Signature[1]) != 'I') ||
2233 (readb(&c->cfgtable->Signature[2]) != 'S') ||
2234 (readb(&c->cfgtable->Signature[3]) != 'S') )
2236 printk("Does not appear to be a valid CISS config table\n");
2237 return -1;
2239 #ifdef CCISS_DEBUG
2240 printk("Trying to put board into Simple mode\n");
2241 #endif /* CCISS_DEBUG */
2242 c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
2243 /* Update the field, and then ring the doorbell */
2244 writel( CFGTBL_Trans_Simple,
2245 &(c->cfgtable->HostWrite.TransportRequest));
2246 writel( CFGTBL_ChangeReq, c->vaddr + SA5_DOORBELL);
2248 /* under certain very rare conditions, this can take awhile.
2249 * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right
2250 * as we enter this code.) */
2251 for(i=0;i<MAX_CONFIG_WAIT;i++) {
2252 if (!(readl(c->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq))
2253 break;
2254 /* delay and try again */
2255 set_current_state(TASK_INTERRUPTIBLE);
2256 schedule_timeout(10);
2259 #ifdef CCISS_DEBUG
2260 printk(KERN_DEBUG "I counter got to %d %x\n", i, readl(c->vaddr + SA5_DOORBELL));
2261 #endif /* CCISS_DEBUG */
2262 #ifdef CCISS_DEBUG
2263 print_cfg_table(c->cfgtable);
2264 #endif /* CCISS_DEBUG */
2266 if (!(readl(&(c->cfgtable->TransportActive)) & CFGTBL_Trans_Simple))
2268 printk(KERN_WARNING "cciss: unable to get board into"
2269 " simple mode\n");
2270 return -1;
2272 return 0;
2277 * Gets information about the local volumes attached to the controller.
2279 static void cciss_getgeometry(int cntl_num)
2281 ReportLunData_struct *ld_buff;
2282 ReadCapdata_struct *size_buff;
2283 InquiryData_struct *inq_buff;
2284 int return_code;
2285 int i;
2286 int listlength = 0;
2287 __u32 lunid = 0;
2288 int block_size;
2289 int total_size;
2291 ld_buff = kmalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
2292 if (ld_buff == NULL)
2294 printk(KERN_ERR "cciss: out of memory\n");
2295 return;
2297 memset(ld_buff, 0, sizeof(ReportLunData_struct));
2298 size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
2299 if (size_buff == NULL)
2301 printk(KERN_ERR "cciss: out of memory\n");
2302 kfree(ld_buff);
2303 return;
2305 inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
2306 if (inq_buff == NULL)
2308 printk(KERN_ERR "cciss: out of memory\n");
2309 kfree(ld_buff);
2310 kfree(size_buff);
2311 return;
2313 /* Get the firmware version */
2314 return_code = sendcmd(CISS_INQUIRY, cntl_num, inq_buff,
2315 sizeof(InquiryData_struct), 0, 0 ,0, NULL, TYPE_CMD);
2316 if (return_code == IO_OK)
2318 hba[cntl_num]->firm_ver[0] = inq_buff->data_byte[32];
2319 hba[cntl_num]->firm_ver[1] = inq_buff->data_byte[33];
2320 hba[cntl_num]->firm_ver[2] = inq_buff->data_byte[34];
2321 hba[cntl_num]->firm_ver[3] = inq_buff->data_byte[35];
2322 } else /* send command failed */
2324 printk(KERN_WARNING "cciss: unable to determine firmware"
2325 " version of controller\n");
2327 /* Get the number of logical volumes */
2328 return_code = sendcmd(CISS_REPORT_LOG, cntl_num, ld_buff,
2329 sizeof(ReportLunData_struct), 0, 0, 0, NULL, TYPE_CMD);
2331 if( return_code == IO_OK)
2333 #ifdef CCISS_DEBUG
2334 printk("LUN Data\n--------------------------\n");
2335 #endif /* CCISS_DEBUG */
2337 listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[0])) << 24;
2338 listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[1])) << 16;
2339 listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[2])) << 8;
2340 listlength |= 0xff & (unsigned int)(ld_buff->LUNListLength[3]);
2341 } else /* reading number of logical volumes failed */
2343 printk(KERN_WARNING "cciss: report logical volume"
2344 " command failed\n");
2345 listlength = 0;
2347 hba[cntl_num]->num_luns = listlength / 8; // 8 bytes pre entry
2348 if (hba[cntl_num]->num_luns > CISS_MAX_LUN)
2350 printk(KERN_ERR "ciss: only %d number of logical volumes supported\n",
2351 CISS_MAX_LUN);
2352 hba[cntl_num]->num_luns = CISS_MAX_LUN;
2354 #ifdef CCISS_DEBUG
2355 printk(KERN_DEBUG "Length = %x %x %x %x = %d\n", ld_buff->LUNListLength[0],
2356 ld_buff->LUNListLength[1], ld_buff->LUNListLength[2],
2357 ld_buff->LUNListLength[3], hba[cntl_num]->num_luns);
2358 #endif /* CCISS_DEBUG */
2360 hba[cntl_num]->highest_lun = hba[cntl_num]->num_luns-1;
2361 for(i=0; i< hba[cntl_num]->num_luns; i++)
2364 lunid = (0xff & (unsigned int)(ld_buff->LUN[i][3])) << 24;
2365 lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][2])) << 16;
2366 lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][1])) << 8;
2367 lunid |= 0xff & (unsigned int)(ld_buff->LUN[i][0]);
2369 hba[cntl_num]->drv[i].LunID = lunid;
2372 #ifdef CCISS_DEBUG
2373 printk(KERN_DEBUG "LUN[%d]: %x %x %x %x = %x\n", i,
2374 ld_buff->LUN[i][0], ld_buff->LUN[i][1],ld_buff->LUN[i][2],
2375 ld_buff->LUN[i][3], hba[cntl_num]->drv[i].LunID);
2376 #endif /* CCISS_DEBUG */
2377 cciss_read_capacity(cntl_num, i, size_buff, 0,
2378 &total_size, &block_size);
2379 cciss_geometry_inquiry(cntl_num, i, 0, total_size, block_size,
2380 inq_buff, &hba[cntl_num]->drv[i]);
2382 kfree(ld_buff);
2383 kfree(size_buff);
2384 kfree(inq_buff);
2387 /* Function to find the first free pointer into our hba[] array */
2388 /* Returns -1 if no free entries are left. */
2389 static int alloc_cciss_hba(void)
2391 struct gendisk *disk[NWD];
2392 int i, n;
2393 for (n = 0; n < NWD; n++) {
2394 disk[n] = alloc_disk(1 << NWD_SHIFT);
2395 if (!disk[n])
2396 goto out;
2399 for(i=0; i< MAX_CTLR; i++) {
2400 if (!hba[i]) {
2401 ctlr_info_t *p;
2402 p = kmalloc(sizeof(ctlr_info_t), GFP_KERNEL);
2403 if (!p)
2404 goto Enomem;
2405 memset(p, 0, sizeof(ctlr_info_t));
2406 for (n = 0; n < NWD; n++)
2407 p->gendisk[n] = disk[n];
2408 hba[i] = p;
2409 return i;
2412 printk(KERN_WARNING "cciss: This driver supports a maximum"
2413 " of 8 controllers.\n");
2414 goto out;
2415 Enomem:
2416 printk(KERN_ERR "cciss: out of memory.\n");
2417 out:
2418 while (n--)
2419 put_disk(disk[n]);
2420 return -1;
2423 static void free_hba(int i)
2425 ctlr_info_t *p = hba[i];
2426 int n;
2428 hba[i] = NULL;
2429 for (n = 0; n < NWD; n++)
2430 put_disk(p->gendisk[n]);
2431 kfree(p);
2435 * This is it. Find all the controllers and register them. I really hate
2436 * stealing all these major device numbers.
2437 * returns the number of block devices registered.
2439 static int __devinit cciss_init_one(struct pci_dev *pdev,
2440 const struct pci_device_id *ent)
2442 request_queue_t *q;
2443 int i;
2444 int j;
2446 printk(KERN_DEBUG "cciss: Device 0x%x has been found at"
2447 " bus %d dev %d func %d\n",
2448 pdev->device, pdev->bus->number, PCI_SLOT(pdev->devfn),
2449 PCI_FUNC(pdev->devfn));
2450 i = alloc_cciss_hba();
2451 if( i < 0 )
2452 return (-1);
2453 if (cciss_pci_init(hba[i], pdev) != 0)
2454 goto clean1;
2456 sprintf(hba[i]->devname, "cciss%d", i);
2457 hba[i]->ctlr = i;
2458 hba[i]->pdev = pdev;
2460 /* configure PCI DMA stuff */
2461 if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL))
2462 printk("cciss: using DAC cycles\n");
2463 else if (!pci_set_dma_mask(pdev, 0xffffffff))
2464 printk("cciss: not using DAC cycles\n");
2465 else {
2466 printk("cciss: no suitable DMA available\n");
2467 goto clean1;
2470 if (register_blkdev(COMPAQ_CISS_MAJOR+i, hba[i]->devname)) {
2471 printk(KERN_ERR "cciss: Unable to register device %s\n",
2472 hba[i]->devname);
2473 goto clean1;
2476 /* make sure the board interrupts are off */
2477 hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
2478 if( request_irq(hba[i]->intr, do_cciss_intr,
2479 SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM,
2480 hba[i]->devname, hba[i])) {
2481 printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
2482 hba[i]->intr, hba[i]->devname);
2483 goto clean2;
2485 hba[i]->cmd_pool_bits = kmalloc(((NR_CMDS+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long), GFP_KERNEL);
2486 hba[i]->cmd_pool = (CommandList_struct *)pci_alloc_consistent(
2487 hba[i]->pdev, NR_CMDS * sizeof(CommandList_struct),
2488 &(hba[i]->cmd_pool_dhandle));
2489 hba[i]->errinfo_pool = (ErrorInfo_struct *)pci_alloc_consistent(
2490 hba[i]->pdev, NR_CMDS * sizeof( ErrorInfo_struct),
2491 &(hba[i]->errinfo_pool_dhandle));
2492 if((hba[i]->cmd_pool_bits == NULL)
2493 || (hba[i]->cmd_pool == NULL)
2494 || (hba[i]->errinfo_pool == NULL)) {
2495 printk( KERN_ERR "cciss: out of memory");
2496 goto clean4;
2499 spin_lock_init(&hba[i]->lock);
2500 q = blk_init_queue(do_cciss_request, &hba[i]->lock);
2501 if (!q)
2502 goto clean4;
2504 hba[i]->queue = q;
2505 q->queuedata = hba[i];
2507 /* Initialize the pdev driver private data.
2508 have it point to hba[i]. */
2509 pci_set_drvdata(pdev, hba[i]);
2510 /* command and error info recs zeroed out before
2511 they are used */
2512 memset(hba[i]->cmd_pool_bits, 0, ((NR_CMDS+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long));
2514 #ifdef CCISS_DEBUG
2515 printk(KERN_DEBUG "Scanning for drives on controller cciss%d\n",i);
2516 #endif /* CCISS_DEBUG */
2518 cciss_getgeometry(i);
2520 cciss_scsi_setup(i);
2522 /* Turn the interrupts on so we can service requests */
2523 hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
2525 cciss_procinit(i);
2527 blk_queue_bounce_limit(q, hba[i]->pdev->dma_mask);
2529 /* This is a hardware imposed limit. */
2530 blk_queue_max_hw_segments(q, MAXSGENTRIES);
2532 /* This is a limit in the driver and could be eliminated. */
2533 blk_queue_max_phys_segments(q, MAXSGENTRIES);
2535 blk_queue_max_sectors(q, 512);
2538 for(j=0; j<NWD; j++) {
2539 drive_info_struct *drv = &(hba[i]->drv[j]);
2540 struct gendisk *disk = hba[i]->gendisk[j];
2542 sprintf(disk->disk_name, "cciss/c%dd%d", i, j);
2543 sprintf(disk->devfs_name, "cciss/host%d/target%d", i, j);
2544 disk->major = COMPAQ_CISS_MAJOR + i;
2545 disk->first_minor = j << NWD_SHIFT;
2546 disk->fops = &cciss_fops;
2547 disk->queue = hba[i]->queue;
2548 disk->private_data = drv;
2549 if( !(drv->nr_blocks))
2550 continue;
2551 blk_queue_hardsect_size(hba[i]->queue, drv->block_size);
2552 set_capacity(disk, drv->nr_blocks);
2553 add_disk(disk);
2555 return(1);
2557 clean4:
2558 if(hba[i]->cmd_pool_bits)
2559 kfree(hba[i]->cmd_pool_bits);
2560 if(hba[i]->cmd_pool)
2561 pci_free_consistent(hba[i]->pdev,
2562 NR_CMDS * sizeof(CommandList_struct),
2563 hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle);
2564 if(hba[i]->errinfo_pool)
2565 pci_free_consistent(hba[i]->pdev,
2566 NR_CMDS * sizeof( ErrorInfo_struct),
2567 hba[i]->errinfo_pool,
2568 hba[i]->errinfo_pool_dhandle);
2569 free_irq(hba[i]->intr, hba[i]);
2570 clean2:
2571 unregister_blkdev(COMPAQ_CISS_MAJOR+i, hba[i]->devname);
2572 clean1:
2573 release_io_mem(hba[i]);
2574 free_hba(i);
2575 return(-1);
2578 static void __devexit cciss_remove_one (struct pci_dev *pdev)
2580 ctlr_info_t *tmp_ptr;
2581 int i, j;
2582 char flush_buf[4];
2583 int return_code;
2585 if (pci_get_drvdata(pdev) == NULL)
2587 printk( KERN_ERR "cciss: Unable to remove device \n");
2588 return;
2590 tmp_ptr = pci_get_drvdata(pdev);
2591 i = tmp_ptr->ctlr;
2592 if (hba[i] == NULL)
2594 printk(KERN_ERR "cciss: device appears to "
2595 "already be removed \n");
2596 return;
2598 /* Turn board interrupts off and send the flush cache command */
2599 /* sendcmd will turn off interrupt, and send the flush...
2600 * To write all data in the battery backed cache to disks */
2601 memset(flush_buf, 0, 4);
2602 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0, 0, 0, NULL,
2603 TYPE_CMD);
2604 if(return_code != IO_OK)
2606 printk(KERN_WARNING "Error Flushing cache on controller %d\n",
2609 free_irq(hba[i]->intr, hba[i]);
2610 pci_set_drvdata(pdev, NULL);
2611 iounmap((void*)hba[i]->vaddr);
2612 cciss_unregister_scsi(i); /* unhook from SCSI subsystem */
2613 blk_cleanup_queue(hba[i]->queue);
2614 unregister_blkdev(COMPAQ_CISS_MAJOR+i, hba[i]->devname);
2615 remove_proc_entry(hba[i]->devname, proc_cciss);
2617 /* remove it from the disk list */
2618 for (j = 0; j < NWD; j++) {
2619 struct gendisk *disk = hba[i]->gendisk[j];
2620 if (disk->flags & GENHD_FL_UP)
2621 del_gendisk(disk);
2624 pci_free_consistent(hba[i]->pdev, NR_CMDS * sizeof(CommandList_struct),
2625 hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle);
2626 pci_free_consistent(hba[i]->pdev, NR_CMDS * sizeof( ErrorInfo_struct),
2627 hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle);
2628 kfree(hba[i]->cmd_pool_bits);
2629 release_io_mem(hba[i]);
2630 free_hba(i);
2633 static struct pci_driver cciss_pci_driver = {
2634 .name = "cciss",
2635 .probe = cciss_init_one,
2636 .remove = __devexit_p(cciss_remove_one),
2637 .id_table = cciss_pci_device_id, /* id_table */
2641 * This is it. Register the PCI driver information for the cards we control
2642 * the OS will call our registered routines when it finds one of our cards.
2644 int __init cciss_init(void)
2646 printk(KERN_INFO DRIVER_NAME "\n");
2648 /* Register for our PCI devices */
2649 return pci_register_driver(&cciss_pci_driver);
2652 static int __init init_cciss_module(void)
2654 return ( cciss_init());
2657 static void __exit cleanup_cciss_module(void)
2659 int i;
2661 pci_unregister_driver(&cciss_pci_driver);
2662 /* double check that all controller entrys have been removed */
2663 for (i=0; i< MAX_CTLR; i++)
2665 if (hba[i] != NULL)
2667 printk(KERN_WARNING "cciss: had to remove"
2668 " controller %d\n", i);
2669 cciss_remove_one(hba[i]->pdev);
2672 remove_proc_entry("cciss", proc_root_driver);
2675 module_init(init_cciss_module);
2676 module_exit(cleanup_cciss_module);