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/version.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>
33 #include <linux/blkpg.h>
34 #include <linux/timer.h>
35 #include <linux/proc_fs.h>
36 #include <linux/init.h>
37 #include <linux/hdreg.h>
38 #include <linux/spinlock.h>
39 #include <asm/uaccess.h>
42 #include <linux/blk.h>
43 #include <linux/blkdev.h>
44 #include <linux/genhd.h>
46 #define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
47 #define DRIVER_NAME "HP CISS Driver (v 2.4.42)"
48 #define DRIVER_VERSION CCISS_DRIVER_VERSION(2,4,42)
50 /* Embedded module documentation macros - see modules.h */
51 MODULE_AUTHOR("Charles M. White III - Hewlett-Packard Company");
52 MODULE_DESCRIPTION("Driver for HP SA5xxx SA6xxx Controllers version 2.4.42");
53 MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400");
54 MODULE_LICENSE("GPL");
56 #include "cciss_cmd.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},
78 MODULE_DEVICE_TABLE(pci, cciss_pci_device_id);
80 #define NR_PRODUCTS (sizeof(products)/sizeof(struct board_type))
82 /* board_id = Subsystem Device ID & Vendor ID
83 * product = Marketing Name for the board
84 * access = Address of the struct of function pointers
86 static struct board_type products[] = {
87 { 0x40700E11, "Smart Array 5300", &SA5_access},
88 { 0x40800E11, "Smart Array 5i", &SA5B_access},
89 { 0x40820E11, "Smart Array 532", &SA5B_access},
90 { 0x40830E11, "Smart Array 5312", &SA5B_access},
91 { 0x409A0E11, "Smart Array 641", &SA5_access},
92 { 0x409B0E11, "Smart Array 642", &SA5_access},
93 { 0x409C0E11, "Smart Array 6400", &SA5_access},
96 /* How long to wait (in millesconds) for board to go into simple mode */
97 #define MAX_CONFIG_WAIT 1000
99 /*define how many times we will try a command because of bus resets */
100 #define MAX_CMD_RETRIES 3
102 #define READ_AHEAD 128
103 #define NR_CMDS 128 /* #commands that can be outstanding */
106 #define CCISS_DMA_MASK 0xFFFFFFFF /* 32 bit DMA */
108 static ctlr_info_t *hba[MAX_CTLR];
110 static struct proc_dir_entry *proc_cciss;
112 static void do_cciss_request(request_queue_t *q);
113 static int cciss_open(struct inode *inode, struct file *filep);
114 static int cciss_release(struct inode *inode, struct file *filep);
115 static int cciss_ioctl(struct inode *inode, struct file *filep,
116 unsigned int cmd, unsigned long arg);
118 static int revalidate_logvol(kdev_t dev, int maxusage);
119 static int frevalidate_logvol(kdev_t dev);
120 static int deregister_disk(int ctlr, int logvol);
121 static int register_new_disk(int cltr, int opened_vol, __u64 requested_lun);
122 static int cciss_rescan_disk(int cltr, int logvol);
124 static void cciss_getgeometry(int cntl_num);
126 static inline void addQ(CommandList_struct **Qptr, CommandList_struct *c);
127 static void start_io( ctlr_info_t *h);
129 #ifdef CONFIG_PROC_FS
130 static int cciss_proc_get_info(char *buffer, char **start, off_t offset,
131 int length, int *eof, void *data);
132 static void cciss_procinit(int i);
134 static int cciss_proc_get_info(char *buffer, char **start, off_t offset,
135 int length, int *eof, void *data) { return 0;}
136 static void cciss_procinit(int i) {}
137 #endif /* CONFIG_PROC_FS */
139 static struct block_device_operations cciss_fops = {
142 release: cciss_release,
144 revalidate: frevalidate_logvol,
147 #include "cciss_scsi.c" /* For SCSI tape support */
149 #define ENG_GIG 1048576000
150 #define ENG_GIG_FACTOR (ENG_GIG/512)
151 #define RAID_UNKNOWN 6
152 static const char *raid_label[] = {"0","4","1(0+1)","5","5+1","ADG",
155 * Report information about this controller.
157 #ifdef CONFIG_PROC_FS
158 static int cciss_proc_get_info(char *buffer, char **start, off_t offset,
159 int length, int *eof, void *data)
164 ctlr_info_t *h = (ctlr_info_t*)data;
165 drive_info_struct *drv;
167 unsigned int vol_sz, vol_sz_frac;
169 spin_lock_irqsave(&io_request_lock, flags);
170 if (h->busy_configuring) {
171 spin_unlock_irqrestore(&io_request_lock, flags);
174 h->busy_configuring = 1;
175 spin_unlock_irqrestore(&io_request_lock, flags);
178 size = sprintf(buffer, "%s: HP %s Controller\n"
179 "Board ID: 0x%08lx\n"
180 "Firmware Version: %c%c%c%c\n"
182 "Logical drives: %d\n"
183 "Current Q depth: %d\n"
184 "Current # commands on controller: %d\n"
185 "Max Q depth since init: %d\n"
186 "Max # commands on controller since init: %d\n"
187 "Max SG entries since init: %d\n\n",
190 (unsigned long)h->board_id,
191 h->firm_ver[0], h->firm_ver[1], h->firm_ver[2], h->firm_ver[3],
192 (unsigned int)h->intr,
194 h->Qdepth, h->commands_outstanding,
195 h->maxQsinceinit, h->max_outstanding, h->maxSG);
197 pos += size; len += size;
198 cciss_proc_tape_report(ctlr, buffer, &pos, &len);
199 for(i=0; i<=h->highest_lun; i++) {
201 if (drv->nr_blocks == 0)
203 vol_sz = drv->nr_blocks/ENG_GIG_FACTOR;
204 vol_sz_frac = (drv->nr_blocks%ENG_GIG_FACTOR)*100/ENG_GIG_FACTOR;
206 if (drv->raid_level > 5)
207 drv->raid_level = RAID_UNKNOWN;
208 size = sprintf(buffer+len, "cciss/c%dd%d:"
209 "\t%4d.%02dGB\tRAID %s\n",
210 ctlr, i, vol_sz,vol_sz_frac,
211 raid_label[drv->raid_level]);
212 pos += size, len += size;
216 *start = buffer+offset;
220 h->busy_configuring = 0;
225 cciss_proc_write(struct file *file, const char *buffer,
226 unsigned long count, void *data)
228 unsigned char cmd[80];
230 #ifdef CONFIG_CISS_SCSI_TAPE
231 ctlr_info_t *h = (ctlr_info_t *) data;
235 if (count > sizeof(cmd)-1)
237 if (copy_from_user(cmd, buffer, count))
241 if (cmd[len-1] == '\n')
243 # ifdef CONFIG_CISS_SCSI_TAPE
244 if (strcmp("engage scsi", cmd)==0) {
245 rc = cciss_engage_scsi(h->ctlr);
250 /* might be nice to have "disengage" too, but it's not
251 safely possible. (only 1 module use count, lock issues.) */
257 * Get us a file in /proc/cciss that says something about each controller.
258 * Create /proc/cciss if it doesn't exist yet.
260 static void __init cciss_procinit(int i)
262 struct proc_dir_entry *pde;
264 if (proc_cciss == NULL) {
265 proc_cciss = proc_mkdir("cciss", proc_root_driver);
267 printk("cciss: proc_mkdir failed\n");
272 pde = create_proc_read_entry(hba[i]->devname,
273 S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH,
274 proc_cciss, cciss_proc_get_info, hba[i]);
275 pde->write_proc = cciss_proc_write;
277 #endif /* CONFIG_PROC_FS */
280 * For operations that cannot sleep, a command block is allocated at init,
281 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track
282 * which ones are free or in use. For operations that can wait for kmalloc
283 * to possible sleep, this routine can be called with get_from_pool set to 0.
284 * cmd_free() MUST be called with a got_from_pool set to 0 if cmd_alloc was.
286 static CommandList_struct * cmd_alloc(ctlr_info_t *h, int get_from_pool)
288 CommandList_struct *c;
291 dma_addr_t cmd_dma_handle, err_dma_handle;
293 if (!get_from_pool) {
294 c = (CommandList_struct *) pci_alloc_consistent(
295 h->pdev, sizeof(CommandList_struct), &cmd_dma_handle);
298 memset(c, 0, sizeof(CommandList_struct));
300 c->err_info = (ErrorInfo_struct *)pci_alloc_consistent(
301 h->pdev, sizeof(ErrorInfo_struct),
304 if (c->err_info == NULL)
306 pci_free_consistent(h->pdev,
307 sizeof(CommandList_struct), c, cmd_dma_handle);
310 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
311 } else /* get it out of the controllers pool */
314 i = find_first_zero_bit(h->cmd_pool_bits, NR_CMDS);
317 } while(test_and_set_bit(i%32, h->cmd_pool_bits+(i/32)) != 0);
319 printk(KERN_DEBUG "cciss: using command buffer %d\n", i);
322 memset(c, 0, sizeof(CommandList_struct));
323 cmd_dma_handle = h->cmd_pool_dhandle
324 + i*sizeof(CommandList_struct);
325 c->err_info = h->errinfo_pool + i;
326 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
327 err_dma_handle = h->errinfo_pool_dhandle
328 + i*sizeof(ErrorInfo_struct);
332 c->busaddr = (__u32) cmd_dma_handle;
333 temp64.val = (__u64) err_dma_handle;
334 c->ErrDesc.Addr.lower = temp64.val32.lower;
335 c->ErrDesc.Addr.upper = temp64.val32.upper;
336 c->ErrDesc.Len = sizeof(ErrorInfo_struct);
345 * Frees a command block that was previously allocated with cmd_alloc().
347 static void cmd_free(ctlr_info_t *h, CommandList_struct *c, int got_from_pool)
352 if (!got_from_pool) {
353 temp64.val32.lower = c->ErrDesc.Addr.lower;
354 temp64.val32.upper = c->ErrDesc.Addr.upper;
355 pci_free_consistent(h->pdev, sizeof(ErrorInfo_struct),
356 c->err_info, (dma_addr_t) temp64.val);
357 pci_free_consistent(h->pdev, sizeof(CommandList_struct),
358 c, (dma_addr_t) c->busaddr);
362 clear_bit(i%32, h->cmd_pool_bits+(i/32));
368 * fills in the disk information.
370 static void cciss_geninit( int ctlr)
372 drive_info_struct *drv;
375 /* Loop through each real device */
376 hba[ctlr]->gendisk.nr_real = 0;
377 for(i=0; i< NWD; i++) {
378 drv = &(hba[ctlr]->drv[i]);
379 if (!(drv->nr_blocks))
381 hba[ctlr]->hd[i << NWD_SHIFT].nr_sects =
382 hba[ctlr]->sizes[i << NWD_SHIFT] = drv->nr_blocks;
384 /* for each partition */
385 for(j=0; j<MAX_PART; j++) {
386 hba[ctlr]->blocksizes[(i<<NWD_SHIFT) + j] = 1024;
388 hba[ctlr]->hardsizes[ (i<<NWD_SHIFT) + j] =
392 hba[ctlr]->gendisk.nr_real = hba[ctlr]->highest_lun+1;
395 * Open. Make sure the device is really there.
397 static int cciss_open(struct inode *inode, struct file *filep)
399 int ctlr = MAJOR(inode->i_rdev) - MAJOR_NR;
400 int dsk = MINOR(inode->i_rdev) >> NWD_SHIFT;
403 printk(KERN_DEBUG "cciss_open %x (%x:%x)\n", inode->i_rdev, ctlr, dsk);
404 #endif /* CCISS_DEBUG */
406 if (ctlr > MAX_CTLR || hba[ctlr] == NULL)
409 * Root is allowed to open raw volume zero even if its not configured
410 * so array config can still work. Root is also allowed to open any
411 * volume that has a LUN ID, so it can issue IOCTL to reread the
412 * disk information. I don't think I really like this.
413 * but I'm already using way to many device nodes to claim another one
414 * for "raw controller".
416 if (hba[ctlr]->sizes[MINOR(inode->i_rdev)] == 0) { /* not online? */
417 if (MINOR(inode->i_rdev) != 0) { /* not node 0? */
418 /* if not node 0 make sure it is a partition = 0 */
419 if (MINOR(inode->i_rdev) & 0x0f) {
421 /* if it is, make sure we have a LUN ID */
422 } else if (hba[ctlr]->drv[MINOR(inode->i_rdev)
423 >> NWD_SHIFT].LunID == 0) {
427 if (!capable(CAP_SYS_ADMIN))
431 hba[ctlr]->drv[dsk].usage_count++;
432 hba[ctlr]->usage_count++;
438 static int cciss_release(struct inode *inode, struct file *filep)
440 int ctlr = MAJOR(inode->i_rdev) - MAJOR_NR;
441 int dsk = MINOR(inode->i_rdev) >> NWD_SHIFT;
444 printk(KERN_DEBUG "cciss_release %x (%x:%x)\n", inode->i_rdev, ctlr, dsk);
445 #endif /* CCISS_DEBUG */
447 /* fsync_dev(inode->i_rdev); */
449 hba[ctlr]->drv[dsk].usage_count--;
450 hba[ctlr]->usage_count--;
457 static int cciss_ioctl(struct inode *inode, struct file *filep,
458 unsigned int cmd, unsigned long arg)
460 int ctlr = MAJOR(inode->i_rdev) - MAJOR_NR;
461 int dsk = MINOR(inode->i_rdev) >> NWD_SHIFT;
464 printk(KERN_DEBUG "cciss_ioctl: Called with cmd=%x %lx\n", cmd, arg);
465 #endif /* CCISS_DEBUG */
470 struct hd_geometry driver_geo;
471 if (hba[ctlr]->drv[dsk].cylinders) {
472 driver_geo.heads = hba[ctlr]->drv[dsk].heads;
473 driver_geo.sectors = hba[ctlr]->drv[dsk].sectors;
474 driver_geo.cylinders = hba[ctlr]->drv[dsk].cylinders;
476 driver_geo.heads = 0xff;
477 driver_geo.sectors = 0x3f;
478 driver_geo.cylinders =
479 hba[ctlr]->drv[dsk].nr_blocks / (0xff*0x3f);
482 hba[ctlr]->hd[MINOR(inode->i_rdev)].start_sect;
483 if (copy_to_user((void *) arg, &driver_geo,
484 sizeof( struct hd_geometry)))
488 case HDIO_GETGEO_BIG:
490 struct hd_big_geometry driver_geo;
491 if (hba[ctlr]->drv[dsk].cylinders) {
492 driver_geo.heads = hba[ctlr]->drv[dsk].heads;
493 driver_geo.sectors = hba[ctlr]->drv[dsk].sectors;
494 driver_geo.cylinders = hba[ctlr]->drv[dsk].cylinders;
496 driver_geo.heads = 0xff;
497 driver_geo.sectors = 0x3f;
498 driver_geo.cylinders =
499 hba[ctlr]->drv[dsk].nr_blocks / (0xff*0x3f);
502 hba[ctlr]->hd[MINOR(inode->i_rdev)].start_sect;
503 if (copy_to_user((void *) arg, &driver_geo,
504 sizeof( struct hd_big_geometry)))
509 if (!capable(CAP_SYS_ADMIN))
511 return revalidate_logvol(inode->i_rdev, 1);
524 return blk_ioctl(inode->i_rdev, cmd, arg);
525 case CCISS_GETPCIINFO:
527 cciss_pci_info_struct pciinfo;
531 pciinfo.bus = hba[ctlr]->pdev->bus->number;
532 pciinfo.dev_fn = hba[ctlr]->pdev->devfn;
533 pciinfo.board_id = hba[ctlr]->board_id;
534 if (copy_to_user((void *) arg, &pciinfo, sizeof( cciss_pci_info_struct )))
538 case CCISS_GETINTINFO:
540 cciss_coalint_struct intinfo;
541 ctlr_info_t *c = hba[ctlr];
545 intinfo.delay = readl(&c->cfgtable->HostWrite.CoalIntDelay);
546 intinfo.count = readl(&c->cfgtable->HostWrite.CoalIntCount);
547 if (copy_to_user((void *) arg, &intinfo, sizeof( cciss_coalint_struct )))
551 case CCISS_SETINTINFO:
553 cciss_coalint_struct intinfo;
554 ctlr_info_t *c = hba[ctlr];
560 if (!capable(CAP_SYS_ADMIN))
562 if (copy_from_user(&intinfo, (void *) arg, sizeof( cciss_coalint_struct)))
564 if ( (intinfo.delay == 0 ) && (intinfo.count == 0)) {
568 spin_lock_irqsave(&io_request_lock, flags);
569 /* Can only safely update if no commands outstanding */
570 if (c->commands_outstanding > 0 ) {
571 spin_unlock_irqrestore(&io_request_lock, flags);
574 /* Update the field, and then ring the doorbell */
575 writel( intinfo.delay,
576 &(c->cfgtable->HostWrite.CoalIntDelay));
577 writel( intinfo.count,
578 &(c->cfgtable->HostWrite.CoalIntCount));
579 writel( CFGTBL_ChangeReq, c->vaddr + SA5_DOORBELL);
581 for(i=0;i<MAX_CONFIG_WAIT;i++) {
582 if (!(readl(c->vaddr + SA5_DOORBELL)
585 /* delay and try again */
588 spin_unlock_irqrestore(&io_request_lock, flags);
589 if (i >= MAX_CONFIG_WAIT)
593 case CCISS_GETNODENAME:
595 NodeName_type NodeName;
596 ctlr_info_t *c = hba[ctlr];
602 NodeName[i] = readb(&c->cfgtable->ServerName[i]);
603 if (copy_to_user((void *) arg, NodeName, sizeof( NodeName_type)))
607 case CCISS_SETNODENAME:
609 NodeName_type NodeName;
610 ctlr_info_t *c = hba[ctlr];
616 if (!capable(CAP_SYS_ADMIN))
619 if (copy_from_user(NodeName, (void *) arg, sizeof( NodeName_type)))
622 spin_lock_irqsave(&io_request_lock, flags);
624 /* Update the field, and then ring the doorbell */
626 writeb( NodeName[i], &c->cfgtable->ServerName[i]);
628 writel( CFGTBL_ChangeReq, c->vaddr + SA5_DOORBELL);
630 for(i=0;i<MAX_CONFIG_WAIT;i++) {
631 if (!(readl(c->vaddr + SA5_DOORBELL)
634 /* delay and try again */
637 spin_unlock_irqrestore(&io_request_lock, flags);
638 if (i >= MAX_CONFIG_WAIT)
643 case CCISS_GETHEARTBEAT:
645 Heartbeat_type heartbeat;
646 ctlr_info_t *c = hba[ctlr];
650 heartbeat = readl(&c->cfgtable->HeartBeat);
651 if (copy_to_user((void *) arg, &heartbeat, sizeof( Heartbeat_type)))
655 case CCISS_GETBUSTYPES:
657 BusTypes_type BusTypes;
658 ctlr_info_t *c = hba[ctlr];
662 BusTypes = readl(&c->cfgtable->BusTypes);
663 if (copy_to_user((void *) arg, &BusTypes, sizeof( BusTypes_type) ))
667 case CCISS_GETFIRMVER:
669 FirmwareVer_type firmware;
673 memcpy(firmware, hba[ctlr]->firm_ver, 4);
675 if (copy_to_user((void *) arg, firmware, sizeof( FirmwareVer_type)))
679 case CCISS_GETDRIVVER:
681 DriverVer_type DriverVer = DRIVER_VERSION;
686 if (copy_to_user((void *) arg, &DriverVer, sizeof( DriverVer_type) ))
690 case CCISS_RESCANDISK:
692 return cciss_rescan_disk(ctlr, dsk);
694 case CCISS_DEREGDISK:
695 return deregister_disk(ctlr,dsk);
698 return register_new_disk(ctlr, dsk, 0);
699 case CCISS_REGNEWDISK:
705 if (copy_from_user(&new_logvol, (void *) arg,
708 return register_new_disk(ctlr, dsk, new_logvol);
710 case CCISS_GETLUNINFO:
712 LogvolInfo_struct luninfo;
716 luninfo.LunID = hba[ctlr]->drv[dsk].LunID;
717 luninfo.num_opens = hba[ctlr]->drv[dsk].usage_count;
719 /* count partitions 1 to 15 with sizes > 0 */
720 start = (dsk << NWD_SHIFT);
721 for(i=1; i <MAX_PART; i++) {
723 if (hba[ctlr]->sizes[minor] != 0)
726 luninfo.num_parts = num_parts;
727 if (copy_to_user((void *) arg, &luninfo,
728 sizeof( LogvolInfo_struct) ))
734 IOCTL_Command_struct iocommand;
735 ctlr_info_t *h = hba[ctlr];
736 CommandList_struct *c;
740 DECLARE_COMPLETION(wait);
745 if (!capable(CAP_SYS_RAWIO))
748 if (copy_from_user(&iocommand, (void *) arg, sizeof( IOCTL_Command_struct) ))
750 if ((iocommand.buf_size < 1) &&
751 (iocommand.Request.Type.Direction
755 /* Check kmalloc limits */
756 if (iocommand.buf_size > 128000)
758 if (iocommand.buf_size > 0) {
759 buff = kmalloc(iocommand.buf_size, GFP_KERNEL);
763 if (iocommand.Request.Type.Direction == XFER_WRITE) {
764 /* Copy the data into the buffer we created */
765 if (copy_from_user(buff, iocommand.buf, iocommand.buf_size))
771 if ((c = cmd_alloc(h , 0)) == NULL) {
775 /* Fill in the command type */
776 c->cmd_type = CMD_IOCTL_PEND;
777 /* Fill in Command Header */
778 c->Header.ReplyQueue = 0; /* unused in simple mode */
779 if (iocommand.buf_size > 0) { /* buffer to fill */
780 c->Header.SGList = 1;
781 c->Header.SGTotal= 1;
782 } else { /* no buffers to fill */
783 c->Header.SGList = 0;
784 c->Header.SGTotal= 0;
786 c->Header.LUN = iocommand.LUN_info;
787 c->Header.Tag.lower = c->busaddr; /* use the kernel address */
788 /* the cmd block for tag */
790 /* Fill in Request block */
791 c->Request = iocommand.Request;
793 /* Fill in the scatter gather information */
794 if (iocommand.buf_size > 0 ) {
795 temp64.val = pci_map_single( h->pdev, buff,
797 PCI_DMA_BIDIRECTIONAL);
798 c->SG[0].Addr.lower = temp64.val32.lower;
799 c->SG[0].Addr.upper = temp64.val32.upper;
800 c->SG[0].Len = iocommand.buf_size;
801 c->SG[0].Ext = 0; /* we are not chaining */
805 /* Put the request on the tail of the request queue */
806 spin_lock_irqsave(&io_request_lock, flags);
810 spin_unlock_irqrestore(&io_request_lock, flags);
812 wait_for_completion(&wait);
814 /* unlock the buffers from DMA */
815 temp64.val32.lower = c->SG[0].Addr.lower;
816 temp64.val32.upper = c->SG[0].Addr.upper;
817 pci_unmap_single( h->pdev, (dma_addr_t) temp64.val,
818 iocommand.buf_size, PCI_DMA_BIDIRECTIONAL);
820 /* Copy the error information out */
821 iocommand.error_info = *(c->err_info);
822 if (copy_to_user((void *) arg, &iocommand,
823 sizeof( IOCTL_Command_struct) ) ) {
829 if (iocommand.Request.Type.Direction == XFER_READ) {
830 /* Copy the data out of the buffer we created */
831 if (copy_to_user(iocommand.buf, buff,
832 iocommand.buf_size)) {
842 case CCISS_BIG_PASSTHRU:
844 BIG_IOCTL_Command_struct iocommand;
845 ctlr_info_t *h = hba[ctlr];
846 CommandList_struct *c;
847 char *buff[MAXSGENTRIES] = {NULL,};
848 int buff_size[MAXSGENTRIES] = {0,};
854 DECLARE_COMPLETION(wait);
859 if (!capable(CAP_SYS_RAWIO))
862 if (copy_from_user(&iocommand, (void *) arg, sizeof( BIG_IOCTL_Command_struct) ))
864 if ((iocommand.buf_size < 1) &&
865 (iocommand.Request.Type.Direction != XFER_NONE)) {
868 /* Check kmalloc limits using all SGs */
869 if (iocommand.malloc_size > MAX_KMALLOC_SIZE)
871 if (iocommand.buf_size > iocommand.malloc_size * MAXSGENTRIES)
873 if (iocommand.buf_size > 0) {
874 __u32 size_left_alloc = iocommand.buf_size;
875 BYTE *data_ptr = (BYTE *) iocommand.buf;
876 while (size_left_alloc > 0) {
877 buff_size[sg_used] = (size_left_alloc
878 > iocommand.malloc_size)
879 ? iocommand.malloc_size : size_left_alloc;
880 buff[sg_used] = kmalloc( buff_size[sg_used],
882 if (buff[sg_used] == NULL) {
886 if (iocommand.Request.Type.Direction ==
888 /* Copy the data into the buffer created */
889 if (copy_from_user(buff[sg_used], data_ptr,
890 buff_size[sg_used])) {
894 size_left_alloc -= buff_size[sg_used];
895 data_ptr += buff_size[sg_used];
900 if ((c = cmd_alloc(h , 0)) == NULL) {
904 /* Fill in the command type */
905 c->cmd_type = CMD_IOCTL_PEND;
906 /* Fill in Command Header */
907 c->Header.ReplyQueue = 0; /* unused in simple mode */
909 if (iocommand.buf_size > 0) { /* buffer to fill */
910 c->Header.SGList = sg_used;
911 c->Header.SGTotal= sg_used;
912 } else { /* no buffers to fill */
913 c->Header.SGList = 0;
914 c->Header.SGTotal= 0;
916 c->Header.LUN = iocommand.LUN_info;
917 c->Header.Tag.lower = c->busaddr; /* use the kernel address */
918 /* the cmd block for tag */
920 /* Fill in Request block */
921 c->Request = iocommand.Request;
922 /* Fill in the scatter gather information */
923 if (iocommand.buf_size > 0 ) {
925 for(i=0; i< sg_used; i++) {
926 temp64.val = pci_map_single( h->pdev, buff[i],
928 PCI_DMA_BIDIRECTIONAL);
930 c->SG[i].Addr.lower = temp64.val32.lower;
931 c->SG[i].Addr.upper = temp64.val32.upper;
932 c->SG[i].Len = buff_size[i];
933 c->SG[i].Ext = 0; /* we are not chaining */
937 /* Put the request on the tail of the request queue */
938 spin_lock_irqsave(&io_request_lock, flags);
942 spin_unlock_irqrestore(&io_request_lock, flags);
943 wait_for_completion(&wait);
944 /* unlock the buffers from DMA */
945 for(i=0; i< sg_used; i++) {
946 temp64.val32.lower = c->SG[i].Addr.lower;
947 temp64.val32.upper = c->SG[i].Addr.upper;
948 pci_unmap_single( h->pdev, (dma_addr_t) temp64.val,
949 buff_size[i], PCI_DMA_BIDIRECTIONAL);
951 /* Copy the error information out */
952 iocommand.error_info = *(c->err_info);
953 if (copy_to_user((void *) arg, &iocommand,
954 sizeof( IOCTL_Command_struct) ) ) {
959 if (iocommand.Request.Type.Direction == XFER_READ) {
960 /* Copy the data out of the buffer we created */
961 BYTE *ptr = (BYTE *) iocommand.buf;
962 for(i=0; i< sg_used; i++) {
963 if (copy_to_user(ptr, buff[i], buff_size[i])) {
977 for(i=0; i< sg_used; i++) {
989 /* Borrowed and adapted from sd.c */
990 static int revalidate_logvol(kdev_t dev, int maxusage)
993 struct gendisk *gdev;
999 target = MINOR(dev) >> NWD_SHIFT;
1000 ctlr = MAJOR(dev) - MAJOR_NR;
1001 gdev = &(hba[ctlr]->gendisk);
1003 spin_lock_irqsave(&io_request_lock, flags);
1004 if (hba[ctlr]->drv[target].usage_count > maxusage) {
1005 spin_unlock_irqrestore(&io_request_lock, flags);
1006 printk(KERN_WARNING "cciss: Device busy for "
1007 "revalidation (usage=%d)\n",
1008 hba[ctlr]->drv[target].usage_count);
1011 hba[ctlr]->drv[target].usage_count++;
1012 spin_unlock_irqrestore(&io_request_lock, flags);
1014 max_p = gdev->max_p;
1015 start = target << gdev->minor_shift;
1017 for(i=max_p-1; i>=0; i--) {
1018 int minor = start+i;
1019 invalidate_device(MKDEV(MAJOR_NR + ctlr, minor), 1);
1020 gdev->part[minor].start_sect = 0;
1021 gdev->part[minor].nr_sects = 0;
1023 /* reset the blocksize so we can read the partition table */
1024 blksize_size[MAJOR_NR+ctlr][minor] = 1024;
1026 /* setup partitions per disk */
1027 grok_partitions(gdev, target, MAX_PART,
1028 hba[ctlr]->drv[target].nr_blocks);
1029 hba[ctlr]->drv[target].usage_count--;
1033 static int frevalidate_logvol(kdev_t dev)
1036 printk(KERN_DEBUG "cciss: frevalidate has been called\n");
1037 #endif /* CCISS_DEBUG */
1038 return revalidate_logvol(dev, 0);
1040 static int deregister_disk(int ctlr, int logvol)
1042 unsigned long flags;
1043 struct gendisk *gdev = &(hba[ctlr]->gendisk);
1044 ctlr_info_t *h = hba[ctlr];
1045 int start, max_p, i;
1047 if (!capable(CAP_SYS_RAWIO))
1050 spin_lock_irqsave(&io_request_lock, flags);
1051 /* make sure logical volume is NOT is use */
1052 if (h->drv[logvol].usage_count > 1 || h->busy_configuring) {
1053 spin_unlock_irqrestore(&io_request_lock, flags);
1056 h->busy_configuring = 1;
1057 spin_unlock_irqrestore(&io_request_lock, flags);
1059 /* invalidate the devices and deregister the disk */
1060 max_p = gdev->max_p;
1061 start = logvol << gdev->minor_shift;
1062 for (i=max_p-1; i>=0; i--) {
1063 int minor = start+i;
1064 /* printk("invalidating( %d %d)\n", ctlr, minor); */
1065 invalidate_device(MKDEV(MAJOR_NR+ctlr, minor), 1);
1066 /* so open will now fail */
1067 h->sizes[minor] = 0;
1068 /* so it will no longer appear in /proc/partitions */
1069 gdev->part[minor].start_sect = 0;
1070 gdev->part[minor].nr_sects = 0;
1072 /* check to see if it was the last disk */
1073 if (logvol == h->highest_lun) {
1074 /* if so, find the new hightest lun */
1075 int i, newhighest =-1;
1076 for(i=0; i<h->highest_lun; i++) {
1077 /* if the disk has size > 0, it is available */
1078 if (h->sizes[i << gdev->minor_shift] != 0)
1081 h->highest_lun = newhighest;
1085 gdev->nr_real = h->highest_lun+1;
1086 /* zero out the disk size info */
1087 h->drv[logvol].nr_blocks = 0;
1088 h->drv[logvol].block_size = 0;
1089 h->drv[logvol].cylinders = 0;
1090 h->drv[logvol].LunID = 0;
1091 h->busy_configuring = 0;
1094 static int sendcmd_withirq(__u8 cmd,
1098 unsigned int use_unit_num,
1099 unsigned int log_unit,
1102 ctlr_info_t *h = hba[ctlr];
1103 CommandList_struct *c;
1104 u64bit buff_dma_handle;
1105 unsigned long flags;
1106 int return_status = IO_OK;
1107 DECLARE_COMPLETION(wait);
1109 if ((c = cmd_alloc(h , 0)) == NULL)
1111 c->cmd_type = CMD_IOCTL_PEND;
1112 /* Fill in Command Header */
1113 c->Header.ReplyQueue = 0; /* unused in simple mode */
1114 if (buff != NULL) { /* buffer to fill */
1115 c->Header.SGList = 1;
1116 c->Header.SGTotal= 1;
1118 /* no buffers to fill */
1119 c->Header.SGList = 0;
1120 c->Header.SGTotal= 0;
1122 c->Header.Tag.lower = c->busaddr; /* tag is phys addr of cmd */
1123 /* Fill in Request block */
1126 /* If the logical unit number is 0 then, this is going
1127 to controller so It's a physical command
1128 mode = 0 target = 0.
1129 So we have nothing to write.
1131 mode = 1 target = LUNID
1133 if (use_unit_num != 0) {
1134 c->Header.LUN.LogDev.VolId =
1135 hba[ctlr]->drv[log_unit].LunID;
1136 c->Header.LUN.LogDev.Mode = 1;
1138 if (page_code != 0) {
1139 c->Request.CDB[1] = 0x01;
1140 c->Request.CDB[2] = page_code;
1142 c->Request.CDBLen = 6;
1143 c->Request.Type.Type = TYPE_CMD;
1144 c->Request.Type.Attribute = ATTR_SIMPLE;
1145 c->Request.Type.Direction = XFER_READ; /* Read */
1146 c->Request.Timeout = 0; /* Don't time out */
1147 c->Request.CDB[0] = CISS_INQUIRY;
1148 c->Request.CDB[4] = size & 0xFF;
1150 case CISS_REPORT_LOG:
1151 /* Talking to controller so It's a physical command
1152 mode = 00 target = 0.
1153 So we have nothing to write.
1155 c->Request.CDBLen = 12;
1156 c->Request.Type.Type = TYPE_CMD;
1157 c->Request.Type.Attribute = ATTR_SIMPLE;
1158 c->Request.Type.Direction = XFER_READ; /* Read */
1159 c->Request.Timeout = 0; /* Don't time out */
1160 c->Request.CDB[0] = CISS_REPORT_LOG;
1161 c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */
1162 c->Request.CDB[7] = (size >> 16) & 0xFF;
1163 c->Request.CDB[8] = (size >> 8) & 0xFF;
1164 c->Request.CDB[9] = size & 0xFF;
1166 case CCISS_READ_CAPACITY:
1167 c->Header.LUN.LogDev.VolId=
1168 hba[ctlr]->drv[log_unit].LunID;
1169 c->Header.LUN.LogDev.Mode = 1;
1170 c->Request.CDBLen = 10;
1171 c->Request.Type.Type = TYPE_CMD; /* It is a command. */
1172 c->Request.Type.Attribute = ATTR_SIMPLE;
1173 c->Request.Type.Direction = XFER_READ; /* Read */
1174 c->Request.Timeout = 0; /* Don't time out */
1175 c->Request.CDB[0] = CCISS_READ_CAPACITY;
1179 "cciss: Unknown Command 0x%x sent attempted\n", cmd);
1184 /* Fill in the scatter gather information */
1186 buff_dma_handle.val = (__u64) pci_map_single( h->pdev,
1187 buff, size, PCI_DMA_BIDIRECTIONAL);
1188 c->SG[0].Addr.lower = buff_dma_handle.val32.lower;
1189 c->SG[0].Addr.upper = buff_dma_handle.val32.upper;
1190 c->SG[0].Len = size;
1191 c->SG[0].Ext = 0; /* we are not chaining */
1196 /* Put the request on the tail of the queue and send it */
1197 spin_lock_irqsave(&io_request_lock, flags);
1201 spin_unlock_irqrestore(&io_request_lock, flags);
1203 wait_for_completion(&wait);
1206 if (c->err_info->CommandStatus != 0) {
1207 /* an error has occurred */
1208 switch (c->err_info->CommandStatus) {
1209 case CMD_TARGET_STATUS:
1210 printk(KERN_WARNING "cciss: cmd %p has "
1211 " completed with errors\n", c);
1212 if (c->err_info->ScsiStatus) {
1213 printk(KERN_WARNING "cciss: cmd %p "
1214 "has SCSI Status = %x\n", c,
1215 c->err_info->ScsiStatus);
1218 case CMD_DATA_UNDERRUN:
1219 case CMD_DATA_OVERRUN:
1220 /* expected for inquire and report lun commands */
1223 printk(KERN_WARNING "cciss: cmd %p is "
1224 "reported invalid\n", c);
1225 return_status = IO_ERROR;
1227 case CMD_PROTOCOL_ERR:
1228 printk(KERN_WARNING "cciss: cmd %p has "
1229 "protocol error \n", c);
1230 return_status = IO_ERROR;
1232 case CMD_HARDWARE_ERR:
1233 printk(KERN_WARNING "cciss: cmd %p had "
1234 " hardware error\n", c);
1235 return_status = IO_ERROR;
1237 case CMD_CONNECTION_LOST:
1238 printk(KERN_WARNING "cciss: cmd %p had "
1239 "connection lost\n", c);
1240 return_status = IO_ERROR;
1243 printk(KERN_WARNING "cciss: cmd %p was "
1245 return_status = IO_ERROR;
1247 case CMD_ABORT_FAILED:
1248 printk(KERN_WARNING "cciss: cmd %p reports "
1249 "abort failed\n", c);
1250 return_status = IO_ERROR;
1252 case CMD_UNSOLICITED_ABORT:
1253 printk(KERN_WARNING "cciss: cmd %p aborted "
1254 "do to an unsolicited abort\n", c);
1255 if (c->retry_count < MAX_CMD_RETRIES)
1257 printk(KERN_WARNING "retrying cmd\n");
1259 /* erase the old error */
1261 memset(c->err_info, 0,
1262 sizeof(ErrorInfo_struct));
1263 return_status = IO_OK;
1264 INIT_COMPLETION(wait);
1268 return_status = IO_ERROR;
1271 printk(KERN_WARNING "cciss: cmd %p returned "
1272 "unknown status %x\n", c,
1273 c->err_info->CommandStatus);
1274 return_status = IO_ERROR;
1278 /* unlock the buffers from DMA */
1279 pci_unmap_single( h->pdev, (dma_addr_t) buff_dma_handle.val,
1280 size, PCI_DMA_BIDIRECTIONAL);
1282 return return_status;
1284 static int register_new_disk(int ctlr, int opened_vol, __u64 requested_lun)
1286 struct gendisk *gdev = &(hba[ctlr]->gendisk);
1287 ctlr_info_t *h = hba[ctlr];
1288 int start, max_p, i;
1291 int new_lun_found = 0;
1292 int new_lun_index = 0;
1293 int free_index_found = 0;
1295 ReportLunData_struct *ld_buff;
1296 ReadCapdata_struct *size_buff;
1297 InquiryData_struct *inq_buff;
1301 unsigned int block_size;
1302 unsigned int total_size;
1303 unsigned long flags;
1304 int req_lunid = (int) (requested_lun & (__u64) 0xffffffff);
1306 if (!capable(CAP_SYS_RAWIO))
1308 /* if we have no space in our disk array left to add anything */
1309 spin_lock_irqsave(&io_request_lock, flags);
1310 if (h->num_luns >= CISS_MAX_LUN) {
1311 spin_unlock_irqrestore(&io_request_lock, flags);
1314 if (h->busy_configuring) {
1315 spin_unlock_irqrestore(&io_request_lock, flags);
1318 h->busy_configuring = 1;
1319 spin_unlock_irqrestore(&io_request_lock, flags);
1321 ld_buff = kmalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
1322 if (ld_buff == NULL) {
1323 printk(KERN_ERR "cciss: out of memory\n");
1324 h->busy_configuring = 0;
1327 memset(ld_buff, 0, sizeof(ReportLunData_struct));
1328 size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
1329 if (size_buff == NULL) {
1330 printk(KERN_ERR "cciss: out of memory\n");
1332 h->busy_configuring = 0;
1335 inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
1336 if (inq_buff == NULL) {
1337 printk(KERN_ERR "cciss: out of memory\n");
1340 h->busy_configuring = 0;
1344 return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff,
1345 sizeof(ReportLunData_struct), 0, 0, 0 );
1347 if (return_code == IO_OK) {
1348 /* printk("LUN Data\n--------------------------\n"); */
1349 listlength |= (0xff &
1350 (unsigned int)(ld_buff->LUNListLength[0])) << 24;
1351 listlength |= (0xff &
1352 (unsigned int)(ld_buff->LUNListLength[1])) << 16;
1353 listlength |= (0xff &
1354 (unsigned int)(ld_buff->LUNListLength[2])) << 8;
1355 listlength |= 0xff &
1356 (unsigned int)(ld_buff->LUNListLength[3]);
1358 /* reading number of logical volumes failed */
1359 printk(KERN_WARNING "cciss: report logical volume"
1360 " command failed\n");
1362 h->busy_configuring = 0;
1365 num_luns = listlength / 8; /* 8 bytes pre entry */
1366 if (num_luns > CISS_MAX_LUN)
1367 num_luns = CISS_MAX_LUN;
1370 printk(KERN_DEBUG "Length = %x %x %x %x = %d\n", ld_buff->LUNListLength[0],
1371 ld_buff->LUNListLength[1], ld_buff->LUNListLength[2],
1372 ld_buff->LUNListLength[3], num_luns);
1374 for(i=0; i< num_luns; i++) {
1376 int lunID_found = 0;
1378 lunid = (0xff & (unsigned int)(ld_buff->LUN[i][3])) << 24;
1379 lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][2])) << 16;
1380 lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][1])) << 8;
1381 lunid |= 0xff & (unsigned int)(ld_buff->LUN[i][0]);
1383 /* check to see if this is a new lun */
1384 for(j=0; j <= h->highest_lun; j++) {
1386 printk("Checking %d %x against %x\n", j,h->drv[j].LunID,
1388 #endif /* CCISS_DEBUG */
1389 if (h->drv[j].LunID == lunid) {
1395 if (lunID_found == 1)
1397 else { /* new lun found */
1400 printk("new lun found at %d\n", i);
1401 #endif /* CCISS_DEBUG */
1402 if (req_lunid) /* we are looking for a specific lun */
1404 if (lunid != req_lunid)
1407 printk("new lun %x is not %x\n",
1409 #endif /* CCISS_DEBUG */
1418 if (!new_lun_found) {
1419 printk(KERN_DEBUG "cciss: New Logical Volume not found\n");
1420 h->busy_configuring = 0;
1423 /* Now find the free index */
1424 for(i=0; i <CISS_MAX_LUN; i++) {
1426 printk("Checking Index %d\n", i);
1427 #endif /* CCISS_DEBUG */
1428 if (hba[ctlr]->drv[i].LunID == 0) {
1430 printk("free index found at %d\n", i);
1431 #endif /* CCISS_DEBUG */
1432 free_index_found = 1;
1437 if (!free_index_found) {
1438 printk(KERN_WARNING "cciss: unable to find free slot for disk\n");
1439 h->busy_configuring = 0;
1443 logvol = free_index;
1444 hba[ctlr]->drv[logvol].LunID = lunid;
1445 /* there could be gaps in lun numbers, track hightest */
1446 if (hba[ctlr]->highest_lun < logvol)
1447 hba[ctlr]->highest_lun = logvol;
1449 memset(size_buff, 0, sizeof(ReadCapdata_struct));
1450 return_code = sendcmd_withirq(CCISS_READ_CAPACITY, ctlr,
1451 size_buff, sizeof(ReadCapdata_struct), 1,
1453 if (return_code == IO_OK) {
1454 total_size = (0xff &
1455 (unsigned int) size_buff->total_size[0]) << 24;
1456 total_size |= (0xff &
1457 (unsigned int) size_buff->total_size[1]) << 16;
1458 total_size |= (0xff &
1459 (unsigned int) size_buff->total_size[2]) << 8;
1460 total_size |= (0xff &
1461 (unsigned int) size_buff->total_size[3]);
1462 total_size++; /* command returns highest block address */
1464 block_size = (0xff &
1465 (unsigned int) size_buff->block_size[0]) << 24;
1466 block_size |= (0xff &
1467 (unsigned int) size_buff->block_size[1]) << 16;
1468 block_size |= (0xff &
1469 (unsigned int) size_buff->block_size[2]) << 8;
1470 block_size |= (0xff &
1471 (unsigned int) size_buff->block_size[3]);
1473 /* read capacity command failed */
1474 printk(KERN_WARNING "cciss: read capacity failed\n");
1476 block_size = BLOCK_SIZE;
1478 printk(KERN_INFO " blocks= %d block_size= %d\n",
1479 total_size, block_size);
1480 /* Execute the command to read the disk geometry */
1481 memset(inq_buff, 0, sizeof(InquiryData_struct));
1482 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr, inq_buff,
1483 sizeof(InquiryData_struct), 1, logvol ,0xC1 );
1484 if (return_code == IO_OK) {
1485 if (inq_buff->data_byte[8] == 0xFF) {
1487 "cciss: reading geometry failed, "
1488 "volume does not support reading geometry\n");
1490 hba[ctlr]->drv[logvol].block_size = block_size;
1491 hba[ctlr]->drv[logvol].nr_blocks = total_size;
1492 hba[ctlr]->drv[logvol].heads = 255;
1493 hba[ctlr]->drv[logvol].sectors = 32; /* secs/trk */
1494 hba[ctlr]->drv[logvol].cylinders = total_size / 255 /32;
1495 hba[ctlr]->drv[logvol].raid_level = RAID_UNKNOWN;
1497 hba[ctlr]->drv[logvol].block_size = block_size;
1498 hba[ctlr]->drv[logvol].nr_blocks = total_size;
1499 hba[ctlr]->drv[logvol].heads = inq_buff->data_byte[6];
1500 hba[ctlr]->drv[logvol].sectors = inq_buff->data_byte[7];
1501 hba[ctlr]->drv[logvol].cylinders =
1502 (inq_buff->data_byte[4] & 0xff) << 8;
1503 hba[ctlr]->drv[logvol].cylinders +=
1504 inq_buff->data_byte[5];
1505 hba[ctlr]->drv[logvol].raid_level =
1506 inq_buff->data_byte[8];
1509 /* Get geometry failed */
1510 printk(KERN_WARNING "cciss: reading geometry failed, "
1511 "continuing with default geometry\n");
1513 hba[ctlr]->drv[logvol].block_size = block_size;
1514 hba[ctlr]->drv[logvol].nr_blocks = total_size;
1515 hba[ctlr]->drv[logvol].heads = 255;
1516 hba[ctlr]->drv[logvol].sectors = 32; /* Sectors per track */
1517 hba[ctlr]->drv[logvol].cylinders = total_size / 255 / 32;
1519 if (hba[ctlr]->drv[logvol].raid_level > 5)
1520 hba[ctlr]->drv[logvol].raid_level = RAID_UNKNOWN;
1521 printk(KERN_INFO " heads= %d, sectors= %d, cylinders= %d RAID %s\n\n",
1522 hba[ctlr]->drv[logvol].heads,
1523 hba[ctlr]->drv[logvol].sectors,
1524 hba[ctlr]->drv[logvol].cylinders,
1525 raid_label[hba[ctlr]->drv[logvol].raid_level]);
1527 /* special case for c?d0, which may be opened even when
1528 it does not "exist". In that case, don't mess with usage count.
1529 Also, /dev/c1d1 could be used to re-add c0d0 so we can't just
1530 check whether logvol == 0, must check logvol != opened_vol */
1531 if (logvol != opened_vol)
1532 hba[ctlr]->drv[logvol].usage_count = 0;
1534 max_p = gdev->max_p;
1535 start = logvol<< gdev->minor_shift;
1536 hba[ctlr]->hd[start].nr_sects = total_size;
1537 hba[ctlr]->sizes[start] = total_size;
1539 for(i=max_p-1; i>=0; i--) {
1540 int minor = start+i;
1541 invalidate_device(MKDEV(MAJOR_NR + ctlr, minor), 1);
1542 gdev->part[minor].start_sect = 0;
1543 gdev->part[minor].nr_sects = 0;
1545 /* reset the blocksize so we can read the partition table */
1546 blksize_size[MAJOR_NR+ctlr][minor] = block_size;
1547 hba[ctlr]->hardsizes[minor] = block_size;
1550 ++hba[ctlr]->num_luns;
1551 gdev->nr_real = hba[ctlr]->highest_lun + 1;
1552 /* setup partitions per disk */
1553 grok_partitions(gdev, logvol, MAX_PART,
1554 hba[ctlr]->drv[logvol].nr_blocks);
1558 h->busy_configuring = 0;
1562 static int cciss_rescan_disk(int ctlr, int logvol)
1564 struct gendisk *gdev = &(hba[ctlr]->gendisk);
1565 int start, max_p, i;
1566 ReadCapdata_struct *size_buff;
1567 InquiryData_struct *inq_buff;
1569 unsigned int block_size;
1570 unsigned int total_size;
1572 if (!capable(CAP_SYS_RAWIO))
1574 if (hba[ctlr]->sizes[logvol << NWD_SHIFT] != 0) {
1575 /* disk is possible on line, return just a warning */
1578 size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
1579 if (size_buff == NULL) {
1580 printk(KERN_ERR "cciss: out of memory\n");
1583 inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
1584 if (inq_buff == NULL) {
1585 printk(KERN_ERR "cciss: out of memory\n");
1589 memset(size_buff, 0, sizeof(ReadCapdata_struct));
1590 return_code = sendcmd_withirq(CCISS_READ_CAPACITY, ctlr, size_buff,
1591 sizeof( ReadCapdata_struct), 1, logvol, 0 );
1592 if (return_code == IO_OK) {
1593 total_size = (0xff &
1594 (unsigned int)(size_buff->total_size[0])) << 24;
1595 total_size |= (0xff &
1596 (unsigned int)(size_buff->total_size[1])) << 16;
1597 total_size |= (0xff &
1598 (unsigned int)(size_buff->total_size[2])) << 8;
1599 total_size |= (0xff & (unsigned int)
1600 (size_buff->total_size[3]));
1601 total_size++; /* command returns highest block address */
1603 block_size = (0xff &
1604 (unsigned int)(size_buff->block_size[0])) << 24;
1605 block_size |= (0xff &
1606 (unsigned int)(size_buff->block_size[1])) << 16;
1607 block_size |= (0xff &
1608 (unsigned int)(size_buff->block_size[2])) << 8;
1609 block_size |= (0xff &
1610 (unsigned int)(size_buff->block_size[3]));
1611 } else { /* read capacity command failed */
1612 printk(KERN_WARNING "cciss: read capacity failed\n");
1613 total_size = block_size = 0;
1615 printk(KERN_INFO " blocks= %d block_size= %d\n",
1616 total_size, block_size);
1617 /* Execute the command to read the disk geometry */
1618 memset(inq_buff, 0, sizeof(InquiryData_struct));
1619 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr, inq_buff,
1620 sizeof(InquiryData_struct), 1, logvol ,0xC1 );
1621 if (return_code == IO_OK) {
1622 if (inq_buff->data_byte[8] == 0xFF) {
1623 printk(KERN_WARNING "cciss: reading geometry failed, "
1624 "volume does not support reading geometry\n");
1626 hba[ctlr]->drv[logvol].nr_blocks = total_size;
1627 hba[ctlr]->drv[logvol].heads = 255;
1628 hba[ctlr]->drv[logvol].sectors = 32; /* Sectors/track */
1629 hba[ctlr]->drv[logvol].cylinders = total_size / 255 /32;
1631 hba[ctlr]->drv[logvol].nr_blocks = total_size;
1632 hba[ctlr]->drv[logvol].heads = inq_buff->data_byte[6];
1633 hba[ctlr]->drv[logvol].sectors = inq_buff->data_byte[7];
1634 hba[ctlr]->drv[logvol].cylinders =
1635 (inq_buff->data_byte[4] & 0xff) << 8;
1636 hba[ctlr]->drv[logvol].cylinders +=
1637 inq_buff->data_byte[5];
1639 } else { /* Get geometry failed */
1640 printk(KERN_WARNING "cciss: reading geometry failed, "
1641 "continuing with default geometry\n");
1643 hba[ctlr]->drv[logvol].nr_blocks = total_size;
1644 hba[ctlr]->drv[logvol].heads = 255;
1645 hba[ctlr]->drv[logvol].sectors = 32; /* Sectors / track */
1646 hba[ctlr]->drv[logvol].cylinders = total_size / 255 /32;
1649 printk(KERN_INFO " heads= %d, sectors= %d, cylinders= %d \n\n",
1650 hba[ctlr]->drv[logvol].heads,
1651 hba[ctlr]->drv[logvol].sectors,
1652 hba[ctlr]->drv[logvol].cylinders);
1653 max_p = gdev->max_p;
1654 start = logvol<< gdev->minor_shift;
1655 hba[ctlr]->hd[start].nr_sects = hba[ctlr]->sizes[start]= total_size;
1657 for (i=max_p-1; i>=0; i--) {
1658 int minor = start+i;
1659 invalidate_device(MKDEV(MAJOR_NR + ctlr, minor), 1);
1660 gdev->part[minor].start_sect = 0;
1661 gdev->part[minor].nr_sects = 0;
1663 /* reset the blocksize so we can read the partition table */
1664 blksize_size[MAJOR_NR+ctlr][minor] = 1024;
1665 hba[ctlr]->hardsizes[minor] = block_size;
1668 /* setup partitions per disk */
1669 grok_partitions(gdev, logvol, MAX_PART,
1670 hba[ctlr]->drv[logvol].nr_blocks );
1677 * Wait polling for a command to complete.
1678 * The memory mapped FIFO is polled for the completion.
1679 * Used only at init time, interrupts disabled.
1681 static unsigned long pollcomplete(int ctlr)
1686 /* Wait (up to 20 seconds) for a command to complete */
1688 for (i = 20 * HZ; i > 0; i--) {
1689 done = hba[ctlr]->access.command_completed(hba[ctlr]);
1690 if (done == FIFO_EMPTY) {
1691 set_current_state(TASK_UNINTERRUPTIBLE);
1692 schedule_timeout(1);
1696 /* Invalid address to tell caller we ran out of time */
1700 * Send a command to the controller, and wait for it to complete.
1701 * Only used at init time.
1708 unsigned int use_unit_num, /* 0: address the controller,
1709 1: address logical volume log_unit,
1710 2: periph device address is scsi3addr */
1711 unsigned int log_unit,
1713 unsigned char *scsi3addr)
1715 CommandList_struct *c;
1717 unsigned long complete;
1718 ctlr_info_t *info_p= hba[ctlr];
1719 u64bit buff_dma_handle;
1722 c = cmd_alloc(info_p, 1);
1724 printk(KERN_WARNING "cciss: unable to get memory");
1727 /* Fill in Command Header */
1728 c->Header.ReplyQueue = 0; /* unused in simple mode */
1729 if (buff != NULL) { /* buffer to fill */
1730 c->Header.SGList = 1;
1731 c->Header.SGTotal= 1;
1732 } else { /* no buffers to fill */
1733 c->Header.SGList = 0;
1734 c->Header.SGTotal= 0;
1736 c->Header.Tag.lower = c->busaddr; /* use the kernel address */
1737 /* the cmd block for tag */
1738 /* Fill in Request block */
1741 /* If the logical unit number is 0 then, this is going
1742 to controller so It's a physical command
1743 mode = 0 target = 0.
1744 So we have nothing to write.
1745 otherwise, if use_unit_num == 1,
1746 mode = 1(volume set addressing) target = LUNID
1747 otherwise, if use_unit_num == 2,
1748 mode = 0(periph dev addr) target = scsi3addr
1750 if (use_unit_num == 1) {
1751 c->Header.LUN.LogDev.VolId=
1752 hba[ctlr]->drv[log_unit].LunID;
1753 c->Header.LUN.LogDev.Mode = 1;
1755 else if (use_unit_num == 2) {
1756 memcpy(c->Header.LUN.LunAddrBytes,scsi3addr,8);
1757 c->Header.LUN.LogDev.Mode = 0;
1761 /* are we trying to read a vital product page */
1762 if (page_code != 0) {
1763 c->Request.CDB[1] = 0x01;
1764 c->Request.CDB[2] = page_code;
1766 c->Request.CDBLen = 6;
1767 c->Request.Type.Type = TYPE_CMD; /* It is a command. */
1768 c->Request.Type.Attribute = ATTR_SIMPLE;
1769 c->Request.Type.Direction = XFER_READ; /* Read */
1770 c->Request.Timeout = 0; /* Don't time out */
1771 c->Request.CDB[0] = CISS_INQUIRY;
1772 c->Request.CDB[4] = size & 0xFF;
1774 case CISS_REPORT_LOG:
1775 case CISS_REPORT_PHYS:
1776 /* Talking to controller so It's a physical command
1777 mode = 00 target = 0.
1778 So we have nothing to write.
1780 c->Request.CDBLen = 12;
1781 c->Request.Type.Type = TYPE_CMD; /* It is a command. */
1782 c->Request.Type.Attribute = ATTR_SIMPLE;
1783 c->Request.Type.Direction = XFER_READ; /* Read */
1784 c->Request.Timeout = 0; /* Don't time out */
1785 c->Request.CDB[0] = cmd;
1786 c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */
1787 c->Request.CDB[7] = (size >> 16) & 0xFF;
1788 c->Request.CDB[8] = (size >> 8) & 0xFF;
1789 c->Request.CDB[9] = size & 0xFF;
1792 case CCISS_READ_CAPACITY:
1793 c->Header.LUN.LogDev.VolId=
1794 hba[ctlr]->drv[log_unit].LunID;
1795 c->Header.LUN.LogDev.Mode = 1;
1796 c->Request.CDBLen = 10;
1797 c->Request.Type.Type = TYPE_CMD; /* It is a command. */
1798 c->Request.Type.Attribute = ATTR_SIMPLE;
1799 c->Request.Type.Direction = XFER_READ; /* Read */
1800 c->Request.Timeout = 0; /* Don't time out */
1801 c->Request.CDB[0] = CCISS_READ_CAPACITY;
1803 case CCISS_CACHE_FLUSH:
1804 c->Request.CDBLen = 12;
1805 c->Request.Type.Type = TYPE_CMD; /* It is a command. */
1806 c->Request.Type.Attribute = ATTR_SIMPLE;
1807 c->Request.Type.Direction = XFER_WRITE; /* No data */
1808 c->Request.Timeout = 0; /* Don't time out */
1809 c->Request.CDB[0] = BMIC_WRITE; /* BMIC Passthru */
1810 c->Request.CDB[6] = BMIC_CACHE_FLUSH;
1814 "cciss: Unknown Command 0x%x sent attempted\n",
1816 cmd_free(info_p, c, 1);
1819 /* Fill in the scatter gather information */
1821 buff_dma_handle.val = (__u64) pci_map_single( info_p->pdev,
1822 buff, size, PCI_DMA_BIDIRECTIONAL);
1823 c->SG[0].Addr.lower = buff_dma_handle.val32.lower;
1824 c->SG[0].Addr.upper = buff_dma_handle.val32.upper;
1825 c->SG[0].Len = size;
1826 c->SG[0].Ext = 0; /* we are not chaining */
1833 printk(KERN_DEBUG "cciss: turning intr off\n");
1834 #endif /* CCISS_DEBUG */
1835 info_p->access.set_intr_mask(info_p, CCISS_INTR_OFF);
1837 /* Make sure there is room in the command FIFO */
1838 /* Actually it should be completely empty at this time. */
1839 for (i = 200000; i > 0; i--) {
1840 /* if fifo isn't full go */
1841 if (!(info_p->access.fifo_full(info_p))) {
1846 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
1847 " waiting!\n", ctlr);
1852 info_p->access.submit_command(info_p, c);
1853 complete = pollcomplete(ctlr);
1856 printk(KERN_DEBUG "cciss: command completed\n");
1857 #endif /* CCISS_DEBUG */
1859 if (complete != 1) {
1860 if ( (complete & CISS_ERROR_BIT)
1861 && (complete & ~CISS_ERROR_BIT) == c->busaddr) {
1862 /* if data overrun or underun on Report command
1865 if (((c->Request.CDB[0] == CISS_REPORT_LOG) ||
1866 (c->Request.CDB[0] == CISS_REPORT_PHYS) ||
1867 (c->Request.CDB[0] == CISS_INQUIRY)) &&
1868 ((c->err_info->CommandStatus ==
1869 CMD_DATA_OVERRUN) ||
1870 (c->err_info->CommandStatus ==
1873 complete = c->busaddr;
1875 if (c->err_info->CommandStatus ==
1876 CMD_UNSOLICITED_ABORT) {
1877 printk(KERN_WARNING "cciss: "
1878 "cmd %p aborted do "
1879 "to an unsolicited abort \n", c);
1880 if (c->retry_count < MAX_CMD_RETRIES) {
1884 /* erase the old error */
1886 memset(c->err_info, 0,
1887 sizeof(ErrorInfo_struct));
1891 "retried to many times\n");
1896 printk(KERN_WARNING "cciss cciss%d: sendcmd"
1897 " Error %x \n", ctlr,
1898 c->err_info->CommandStatus);
1899 printk(KERN_WARNING "cciss cciss%d: sendcmd"
1901 " size %x\n num %x value %x\n", ctlr,
1902 c->err_info->MoreErrInfo.Invalid_Cmd.offense_size,
1903 c->err_info->MoreErrInfo.Invalid_Cmd.offense_num,
1904 c->err_info->MoreErrInfo.Invalid_Cmd.offense_value);
1909 if (complete != c->busaddr) {
1910 printk( KERN_WARNING "cciss cciss%d: SendCmd "
1911 "Invalid command list address returned! (%lx)\n",
1917 printk( KERN_WARNING
1918 "cciss cciss%d: SendCmd Timeout out, "
1919 "No command list address returned!\n",
1925 /* unlock the data buffer from DMA */
1926 pci_unmap_single(info_p->pdev, (dma_addr_t) buff_dma_handle.val,
1927 size, PCI_DMA_BIDIRECTIONAL);
1928 cmd_free(info_p, c, 1);
1932 * Map (physical) PCI mem into (virtual) kernel space
1934 static ulong remap_pci_mem(ulong base, ulong size)
1936 ulong page_base = ((ulong) base) & PAGE_MASK;
1937 ulong page_offs = ((ulong) base) - page_base;
1938 ulong page_remapped = (ulong) ioremap(page_base, page_offs+size);
1940 return (ulong) (page_remapped ? (page_remapped + page_offs) : 0UL);
1944 * Enqueuing and dequeuing functions for cmdlists.
1946 static inline void addQ(CommandList_struct **Qptr, CommandList_struct *c)
1948 if (*Qptr == NULL) {
1950 c->next = c->prev = c;
1952 c->prev = (*Qptr)->prev;
1954 (*Qptr)->prev->next = c;
1959 static inline CommandList_struct *removeQ(CommandList_struct **Qptr,
1960 CommandList_struct *c)
1962 if (c && c->next != c) {
1963 if (*Qptr == c) *Qptr = c->next;
1964 c->prev->next = c->next;
1965 c->next->prev = c->prev;
1973 * Takes jobs of the Q and sends them to the hardware, then puts it on
1974 * the Q to wait for completion.
1976 static void start_io( ctlr_info_t *h)
1978 CommandList_struct *c;
1980 while(( c = h->reqQ) != NULL ) {
1981 /* can't do anything if fifo is full */
1982 if ((h->access.fifo_full(h))) {
1983 printk(KERN_WARNING "cciss: fifo full \n");
1986 /* Get the frist entry from the Request Q */
1987 removeQ(&(h->reqQ), c);
1990 /* Tell the controller execute command */
1991 h->access.submit_command(h, c);
1993 /* Put job onto the completed Q */
1994 addQ (&(h->cmpQ), c);
1998 static inline void complete_buffers( struct buffer_head *bh, int status)
2000 struct buffer_head *xbh;
2003 xbh = bh->b_reqnext;
2004 bh->b_reqnext = NULL;
2005 blk_finished_io(bh->b_size >> 9);
2006 bh->b_end_io(bh, status);
2010 /* This code assumes io_request_lock is already held */
2011 /* Zeros out the error record and then resends the command back */
2012 /* to the controller */
2013 static inline void resend_cciss_cmd( ctlr_info_t *h, CommandList_struct *c)
2015 /* erase the old error information */
2016 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
2018 /* add it to software queue and then send it to the controller */
2021 if (h->Qdepth > h->maxQsinceinit)
2022 h->maxQsinceinit = h->Qdepth;
2026 /* checks the status of the job and calls complete buffers to mark all
2027 * buffers for the completed job.
2029 static inline void complete_command( ctlr_info_t *h, CommandList_struct *cmd,
2040 if (cmd->err_info->CommandStatus != 0) {
2041 /* an error has occurred */
2042 switch (cmd->err_info->CommandStatus) {
2043 unsigned char sense_key;
2044 case CMD_TARGET_STATUS:
2047 if (cmd->err_info->ScsiStatus == 0x02) {
2048 printk(KERN_WARNING "cciss: cmd %p "
2049 "has CHECK CONDITION,"
2050 " sense key = 0x%x\n", cmd,
2051 cmd->err_info->SenseInfo[2]);
2052 /* check the sense key */
2054 cmd->err_info->SenseInfo[2];
2055 /* recovered error */
2056 if ( sense_key == 0x1)
2059 printk(KERN_WARNING "cciss: cmd %p "
2060 "has SCSI Status 0x%x\n",
2061 cmd, cmd->err_info->ScsiStatus);
2064 case CMD_DATA_UNDERRUN:
2065 printk(KERN_WARNING "cciss: cmd %p has"
2066 " completed with data underrun "
2069 case CMD_DATA_OVERRUN:
2070 printk(KERN_WARNING "cciss: cmd %p has"
2071 " completed with data overrun "
2075 printk(KERN_WARNING "cciss: cmd %p is "
2076 "reported invalid\n", cmd);
2079 case CMD_PROTOCOL_ERR:
2080 printk(KERN_WARNING "cciss: cmd %p has "
2081 "protocol error \n", cmd);
2084 case CMD_HARDWARE_ERR:
2085 printk(KERN_WARNING "cciss: cmd %p had "
2086 " hardware error\n", cmd);
2089 case CMD_CONNECTION_LOST:
2090 printk(KERN_WARNING "cciss: cmd %p had "
2091 "connection lost\n", cmd);
2095 printk(KERN_WARNING "cciss: cmd %p was "
2099 case CMD_ABORT_FAILED:
2100 printk(KERN_WARNING "cciss: cmd %p reports "
2101 "abort failed\n", cmd);
2104 case CMD_UNSOLICITED_ABORT:
2105 printk(KERN_WARNING "cciss: cmd %p aborted do "
2106 "to an unsolicited abort \n",
2108 if (cmd->retry_count < MAX_CMD_RETRIES) {
2115 "retried to many times\n");
2120 printk(KERN_WARNING "cciss: cmd %p timedout\n",
2125 printk(KERN_WARNING "cciss: cmd %p returned "
2126 "unknown status %x\n", cmd,
2127 cmd->err_info->CommandStatus);
2131 /* We need to return this command */
2133 resend_cciss_cmd(h,cmd);
2136 /* command did not need to be retried */
2137 /* unmap the DMA mapping for all the scatter gather elements */
2138 if (cmd->Request.Type.Direction == XFER_READ)
2139 ddir = PCI_DMA_FROMDEVICE;
2141 ddir = PCI_DMA_TODEVICE;
2142 for(i=0; i<cmd->Header.SGList; i++) {
2143 temp64.val32.lower = cmd->SG[i].Addr.lower;
2144 temp64.val32.upper = cmd->SG[i].Addr.upper;
2145 pci_unmap_page(hba[cmd->ctlr]->pdev,
2146 temp64.val, cmd->SG[i].Len, ddir);
2148 complete_buffers(cmd->rq->bh, status);
2150 printk("Done with %p\n", cmd->rq);
2151 #endif /* CCISS_DEBUG */
2152 end_that_request_last(cmd->rq);
2157 static inline int cpq_new_segment(request_queue_t *q, struct request *rq,
2160 if (rq->nr_segments < MAXSGENTRIES) {
2167 static int cpq_back_merge_fn(request_queue_t *q, struct request *rq,
2168 struct buffer_head *bh, int max_segments)
2170 if (blk_seg_merge_ok(rq->bhtail, bh))
2172 return cpq_new_segment(q, rq, max_segments);
2175 static int cpq_front_merge_fn(request_queue_t *q, struct request *rq,
2176 struct buffer_head *bh, int max_segments)
2178 if (blk_seg_merge_ok(bh, rq->bh))
2180 return cpq_new_segment(q, rq, max_segments);
2183 static int cpq_merge_requests_fn(request_queue_t *q, struct request *rq,
2184 struct request *nxt, int max_segments)
2186 int total_segments = rq->nr_segments + nxt->nr_segments;
2188 if (blk_seg_merge_ok(rq->bhtail, nxt->bh))
2191 if (total_segments > MAXSGENTRIES)
2194 rq->nr_segments = total_segments;
2199 * Get a request and submit it to the controller.
2200 * Currently we do one request at a time. Ideally we would like to send
2201 * everything to the controller on the first call, but there is a danger
2202 * of holding the io_request_lock for to long.
2204 static void do_cciss_request(request_queue_t *q)
2206 ctlr_info_t *h= q->queuedata;
2207 CommandList_struct *c;
2208 int log_unit, start_blk, seg;
2209 unsigned long long lastdataend;
2210 struct buffer_head *bh;
2211 struct list_head *queue_head = &q->queue_head;
2212 struct request *creq;
2214 struct scatterlist tmp_sg[MAXSGENTRIES];
2221 if (list_empty(queue_head))
2224 creq = blkdev_entry_next_request(queue_head);
2225 if (creq->nr_segments > MAXSGENTRIES)
2228 if (h->ctlr != MAJOR(creq->rq_dev)-MAJOR_NR ) {
2229 printk(KERN_WARNING "doreq cmd for %d, %x at %p\n",
2230 h->ctlr, creq->rq_dev, creq);
2231 blkdev_dequeue_request(creq);
2232 complete_buffers(creq->bh, 0);
2233 end_that_request_last(creq);
2237 if (( c = cmd_alloc(h, 1)) == NULL)
2240 blkdev_dequeue_request(creq);
2242 spin_unlock_irq(&io_request_lock);
2244 c->cmd_type = CMD_RWREQ;
2248 /* fill in the request */
2249 log_unit = MINOR(creq->rq_dev) >> NWD_SHIFT;
2250 c->Header.ReplyQueue = 0; /* unused in simple mode */
2251 c->Header.Tag.lower = c->busaddr; /* use the physical address */
2252 /* the cmd block for tag */
2253 c->Header.LUN.LogDev.VolId= hba[h->ctlr]->drv[log_unit].LunID;
2254 c->Header.LUN.LogDev.Mode = 1;
2255 c->Request.CDBLen = 10; /* 12 byte commands not in FW yet. */
2256 c->Request.Type.Type = TYPE_CMD; /* It is a command. */
2257 c->Request.Type.Attribute = ATTR_SIMPLE;
2258 c->Request.Type.Direction =
2259 (creq->cmd == READ) ? XFER_READ: XFER_WRITE;
2260 c->Request.Timeout = 0; /* Don't time out */
2261 c->Request.CDB[0] = (creq->cmd == READ) ? CCISS_READ : CCISS_WRITE;
2262 start_blk = hba[h->ctlr]->hd[MINOR(creq->rq_dev)].start_sect + creq->sector;
2265 panic("cciss: bh== NULL?");
2266 printk(KERN_DEBUG "cciss: sector =%d nr_sectors=%d\n",(int) creq->sector,
2267 (int) creq->nr_sectors);
2268 #endif /* CCISS_DEBUG */
2270 lastdataend = ~0ULL;
2272 if (bh_phys(bh) == lastdataend)
2273 { /* tack it on to the last segment */
2274 tmp_sg[seg-1].length +=bh->b_size;
2275 lastdataend += bh->b_size;
2277 if (seg == MAXSGENTRIES)
2279 tmp_sg[seg].page = bh->b_page;
2280 tmp_sg[seg].length = bh->b_size;
2281 tmp_sg[seg].offset = bh_offset(bh);
2282 lastdataend = bh_phys(bh) + bh->b_size;
2288 /* get the DMA records for the setup */
2289 if (c->Request.Type.Direction == XFER_READ)
2290 ddir = PCI_DMA_FROMDEVICE;
2292 ddir = PCI_DMA_TODEVICE;
2293 for (i=0; i<seg; i++) {
2294 c->SG[i].Len = tmp_sg[i].length;
2295 temp64.val = pci_map_page(h->pdev, tmp_sg[i].page,
2296 tmp_sg[i].offset, tmp_sg[i].length, ddir);
2297 c->SG[i].Addr.lower = temp64.val32.lower;
2298 c->SG[i].Addr.upper = temp64.val32.upper;
2299 c->SG[i].Ext = 0; /* we are not chaining */
2301 /* track how many SG entries we are using */
2306 printk(KERN_DEBUG "cciss: Submitting %d sectors in %d segments\n", sect, seg);
2307 #endif /* CCISS_DEBUG */
2309 c->Header.SGList = c->Header.SGTotal = seg;
2310 c->Request.CDB[1]= 0;
2311 c->Request.CDB[2]= (start_blk >> 24) & 0xff; /* MSB */
2312 c->Request.CDB[3]= (start_blk >> 16) & 0xff;
2313 c->Request.CDB[4]= (start_blk >> 8) & 0xff;
2314 c->Request.CDB[5]= start_blk & 0xff;
2315 c->Request.CDB[6]= 0; /* (sect >> 24) & 0xff; MSB */
2316 c->Request.CDB[7]= (creq->nr_sectors >> 8) & 0xff;
2317 c->Request.CDB[8]= creq->nr_sectors & 0xff;
2318 c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
2320 spin_lock_irq(&io_request_lock);
2324 if (h->Qdepth > h->maxQsinceinit)
2325 h->maxQsinceinit = h->Qdepth;
2333 static void do_cciss_intr(int irq, void *dev_id, struct pt_regs *regs)
2335 ctlr_info_t *h = dev_id;
2336 CommandList_struct *c;
2337 unsigned long flags;
2341 /* Is this interrupt for us? */
2342 if (h->access.intr_pending(h) == 0)
2346 * If there are completed commands in the completion queue,
2347 * we had better do something about it.
2349 spin_lock_irqsave(&io_request_lock, flags);
2350 while( h->access.intr_pending(h)) {
2351 while((a = h->access.command_completed(h)) != FIFO_EMPTY) {
2354 if ((c = h->cmpQ) == NULL) {
2355 printk(KERN_WARNING "cciss: Completion of %08lx ignored\n", (unsigned long)a1);
2358 while(c->busaddr != a) {
2364 * If we've found the command, take it off the
2365 * completion Q and free it
2367 if (c->busaddr == a) {
2368 removeQ(&h->cmpQ, c);
2369 if (c->cmd_type == CMD_RWREQ) {
2370 complete_command(h, c, 0);
2371 } else if (c->cmd_type == CMD_IOCTL_PEND) {
2372 complete(c->waiting);
2374 # ifdef CONFIG_CISS_SCSI_TAPE
2375 else if (c->cmd_type == CMD_SCSI) {
2376 complete_scsi_command(c, 0, a1);
2384 * See if we can queue up some more IO
2386 do_cciss_request(BLK_DEFAULT_QUEUE(MAJOR_NR + h->ctlr));
2387 spin_unlock_irqrestore(&io_request_lock, flags);
2390 * We cannot read the structure directly, for portablity we must use
2392 * This is for debug only.
2395 static void print_cfg_table( CfgTable_struct *tb)
2400 printk("Controller Configuration information\n");
2401 printk("------------------------------------\n");
2403 temp_name[i] = readb(&(tb->Signature[i]));
2405 printk(" Signature = %s\n", temp_name);
2406 printk(" Spec Number = %d\n", readl(&(tb->SpecValence)));
2407 printk(" Transport methods supported = 0x%x\n",
2408 readl(&(tb-> TransportSupport)));
2409 printk(" Transport methods active = 0x%x\n",
2410 readl(&(tb->TransportActive)));
2411 printk(" Requested transport Method = 0x%x\n",
2412 readl(&(tb->HostWrite.TransportRequest)));
2413 printk(" Coalese Interrupt Delay = 0x%x\n",
2414 readl(&(tb->HostWrite.CoalIntDelay)));
2415 printk(" Coalese Interrupt Count = 0x%x\n",
2416 readl(&(tb->HostWrite.CoalIntCount)));
2417 printk(" Max outstanding commands = 0x%d\n",
2418 readl(&(tb->CmdsOutMax)));
2419 printk(" Bus Types = 0x%x\n", readl(&(tb-> BusTypes)));
2421 temp_name[i] = readb(&(tb->ServerName[i]));
2422 temp_name[16] = '\0';
2423 printk(" Server Name = %s\n", temp_name);
2424 printk(" Heartbeat Counter = 0x%x\n\n\n",
2425 readl(&(tb->HeartBeat)));
2427 #endif /* CCISS_DEBUG */
2429 static void release_io_mem(ctlr_info_t *c)
2431 /* if IO mem was not protected do nothing */
2432 if (c->io_mem_addr == 0)
2434 release_region(c->io_mem_addr, c->io_mem_length);
2436 c->io_mem_length = 0;
2438 static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
2440 ushort vendor_id, device_id, command;
2441 unchar cache_line_size, latency_timer;
2442 unchar irq, revision;
2447 int cfg_base_addr_index;
2450 vendor_id = pdev->vendor;
2451 device_id = pdev->device;
2455 addr[i] = pdev->resource[i].start;
2457 if (pci_enable_device(pdev)) {
2458 printk(KERN_ERR "cciss: Unable to Enable PCI device\n");
2461 if (pci_set_dma_mask(pdev, CCISS_DMA_MASK ) != 0) {
2462 printk(KERN_ERR "cciss: Unable to set DMA mask\n");
2466 (void) pci_read_config_word(pdev, PCI_COMMAND,&command);
2467 (void) pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
2468 (void) pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE,
2470 (void) pci_read_config_byte(pdev, PCI_LATENCY_TIMER,
2473 (void) pci_read_config_dword(pdev, PCI_SUBSYSTEM_VENDOR_ID,
2476 /* check to see if controller has been disabled */
2477 if (!(command & 0x02)) {
2478 printk(KERN_WARNING "cciss: controller appears to be disabled\n");
2481 /* search for our IO range so we can protect it */
2482 for (i=0; i<6; i++) {
2483 /* is this an IO range */
2484 if (pdev->resource[i].flags & 0x01) {
2485 c->io_mem_addr = pdev->resource[i].start;
2486 c->io_mem_length = pdev->resource[i].end -
2487 pdev->resource[i].start +1;
2489 printk("IO value found base_addr[%d] %lx %lx\n", i,
2490 c->io_mem_addr, c->io_mem_length);
2491 #endif /* CCISS_DEBUG */
2492 /* register the IO range */
2493 if (!request_region( c->io_mem_addr,
2494 c->io_mem_length, "cciss")) {
2496 "cciss I/O memory range already in "
2497 "use addr=%lx length=%ld\n",
2498 c->io_mem_addr, c->io_mem_length);
2500 c->io_mem_length = 0;
2507 printk("vendor_id = %x\n", vendor_id);
2508 printk("device_id = %x\n", device_id);
2509 printk("command = %x\n", command);
2511 printk("addr[%d] = %x\n", i, addr[i]);
2512 printk("revision = %x\n", revision);
2513 printk("irq = %x\n", irq);
2514 printk("cache_line_size = %x\n", cache_line_size);
2515 printk("latency_timer = %x\n", latency_timer);
2516 printk("board_id = %x\n", board_id);
2517 #endif /* CCISS_DEBUG */
2522 * Memory base addr is first addr , the second points to the config
2526 c->paddr = addr[0] ; /* addressing mode bits already removed */
2528 printk("address 0 = %x\n", c->paddr);
2529 #endif /* CCISS_DEBUG */
2530 c->vaddr = remap_pci_mem(c->paddr, 200);
2532 /* get the address index number */
2533 cfg_base_addr = readl(c->vaddr + SA5_CTCFG_OFFSET);
2534 /* I am not prepared to deal with a 64 bit address value */
2535 cfg_base_addr &= 0xffff;
2537 printk("cfg base address = %x\n", cfg_base_addr);
2538 #endif /* CCISS_DEBUG */
2539 cfg_base_addr_index = (cfg_base_addr - PCI_BASE_ADDRESS_0)/4;
2541 printk("cfg base address index = %x\n", cfg_base_addr_index);
2542 #endif /* CCISS_DEBUG */
2544 cfg_offset = readl(c->vaddr + SA5_CTMEM_OFFSET);
2546 printk("cfg offset = %x\n", cfg_offset);
2547 #endif /* CCISS_DEBUG */
2548 c->cfgtable = (CfgTable_struct *)
2549 remap_pci_mem((addr[cfg_base_addr_index] & 0xfffffff0)
2550 + cfg_offset, sizeof(CfgTable_struct));
2551 c->board_id = board_id;
2554 print_cfg_table(c->cfgtable);
2555 #endif /* CCISS_DEBUG */
2557 for(i=0; i<NR_PRODUCTS; i++) {
2558 if (board_id == products[i].board_id) {
2559 c->product_name = products[i].product_name;
2560 c->access = *(products[i].access);
2564 if (i == NR_PRODUCTS) {
2565 printk(KERN_WARNING "cciss: Sorry, I don't know how"
2566 " to access the Smart Array controller %08lx\n",
2567 (unsigned long)board_id);
2570 if ( (readb(&c->cfgtable->Signature[0]) != 'C') ||
2571 (readb(&c->cfgtable->Signature[1]) != 'I') ||
2572 (readb(&c->cfgtable->Signature[2]) != 'S') ||
2573 (readb(&c->cfgtable->Signature[3]) != 'S') ) {
2574 printk("Does not appear to be a valid CISS config table\n");
2578 printk("Trying to put board into Simple mode\n");
2579 #endif /* CCISS_DEBUG */
2580 c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
2581 /* Update the field, and then ring the doorbell */
2582 writel( CFGTBL_Trans_Simple,
2583 &(c->cfgtable->HostWrite.TransportRequest));
2584 writel( CFGTBL_ChangeReq, c->vaddr + SA5_DOORBELL);
2586 for(i=0;i<MAX_CONFIG_WAIT;i++) {
2587 if (!(readl(c->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq))
2589 /* delay and try again */
2594 printk(KERN_DEBUG "I counter got to %d %x\n", i, readl(c->vaddr + SA5_DOORBELL));
2595 #endif /* CCISS_DEBUG */
2597 print_cfg_table(c->cfgtable);
2598 #endif /* CCISS_DEBUG */
2600 if (!(readl(&(c->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) {
2601 printk(KERN_WARNING "cciss: unable to get board into"
2610 * Gets information about the local volumes attached to the controller.
2612 static void cciss_getgeometry(int cntl_num)
2614 ReportLunData_struct *ld_buff;
2615 ReadCapdata_struct *size_buff;
2616 InquiryData_struct *inq_buff;
2624 ld_buff = kmalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
2625 if (ld_buff == NULL) {
2626 printk(KERN_ERR "cciss: out of memory\n");
2629 memset(ld_buff, 0, sizeof(ReportLunData_struct));
2630 size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
2631 if (size_buff == NULL) {
2632 printk(KERN_ERR "cciss: out of memory\n");
2636 inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
2637 if (inq_buff == NULL) {
2638 printk(KERN_ERR "cciss: out of memory\n");
2643 /* Get the firmware version */
2644 return_code = sendcmd(CISS_INQUIRY, cntl_num, inq_buff,
2645 sizeof(InquiryData_struct), 0, 0 ,0, NULL);
2646 if (return_code == IO_OK) {
2647 hba[cntl_num]->firm_ver[0] = inq_buff->data_byte[32];
2648 hba[cntl_num]->firm_ver[1] = inq_buff->data_byte[33];
2649 hba[cntl_num]->firm_ver[2] = inq_buff->data_byte[34];
2650 hba[cntl_num]->firm_ver[3] = inq_buff->data_byte[35];
2651 } else { /* send command failed */
2652 printk(KERN_WARNING "cciss: unable to determine firmware"
2653 " version of controller\n");
2655 /* Get the number of logical volumes */
2656 return_code = sendcmd(CISS_REPORT_LOG, cntl_num, ld_buff,
2657 sizeof(ReportLunData_struct), 0, 0, 0, NULL);
2659 if (return_code == IO_OK) {
2661 printk("LUN Data\n--------------------------\n");
2662 #endif /* CCISS_DEBUG */
2664 listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[0])) << 24;
2665 listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[1])) << 16;
2666 listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[2])) << 8;
2667 listlength |= 0xff & (unsigned int)(ld_buff->LUNListLength[3]);
2668 } else { /* reading number of logical volumes failed */
2669 printk(KERN_WARNING "cciss: report logical volume"
2670 " command failed\n");
2673 hba[cntl_num]->num_luns = listlength / 8; /* 8 bytes pre entry */
2674 if (hba[cntl_num]->num_luns > CISS_MAX_LUN) {
2675 printk(KERN_ERR "cciss: only %d number of logical volumes supported\n",
2677 hba[cntl_num]->num_luns = CISS_MAX_LUN;
2680 printk(KERN_DEBUG "Length = %x %x %x %x = %d\n", ld_buff->LUNListLength[0],
2681 ld_buff->LUNListLength[1], ld_buff->LUNListLength[2],
2682 ld_buff->LUNListLength[3], hba[cntl_num]->num_luns);
2683 #endif /* CCISS_DEBUG */
2685 hba[cntl_num]->highest_lun = hba[cntl_num]->num_luns-1;
2686 for(i=0; i< hba[cntl_num]->num_luns; i++) {
2687 lunid = (0xff & (unsigned int)(ld_buff->LUN[i][3])) << 24;
2688 lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][2])) << 16;
2689 lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][1])) << 8;
2690 lunid |= 0xff & (unsigned int)(ld_buff->LUN[i][0]);
2691 hba[cntl_num]->drv[i].LunID = lunid;
2694 printk(KERN_DEBUG "LUN[%d]: %x %x %x %x = %x\n", i,
2695 ld_buff->LUN[i][0], ld_buff->LUN[i][1],ld_buff->LUN[i][2],
2696 ld_buff->LUN[i][3], hba[cntl_num]->drv[i].LunID);
2697 #endif /* CCISS_DEBUG */
2699 memset(size_buff, 0, sizeof(ReadCapdata_struct));
2700 return_code = sendcmd(CCISS_READ_CAPACITY, cntl_num, size_buff,
2701 sizeof( ReadCapdata_struct), 1, i, 0, NULL);
2702 if (return_code == IO_OK) {
2703 total_size = (0xff &
2704 (unsigned int)(size_buff->total_size[0])) << 24;
2705 total_size |= (0xff &
2706 (unsigned int)(size_buff->total_size[1])) << 16;
2707 total_size |= (0xff &
2708 (unsigned int)(size_buff->total_size[2])) << 8;
2709 total_size |= (0xff & (unsigned int)
2710 (size_buff->total_size[3]));
2711 total_size++; /* command returns highest */
2714 block_size = (0xff &
2715 (unsigned int)(size_buff->block_size[0])) << 24;
2716 block_size |= (0xff &
2717 (unsigned int)(size_buff->block_size[1])) << 16;
2718 block_size |= (0xff &
2719 (unsigned int)(size_buff->block_size[2])) << 8;
2720 block_size |= (0xff &
2721 (unsigned int)(size_buff->block_size[3]));
2722 } else { /* read capacity command failed */
2723 printk(KERN_WARNING "cciss: read capacity failed\n");
2724 total_size = block_size = 0;
2726 printk(KERN_INFO " blocks= %d block_size= %d\n",
2727 total_size, block_size);
2729 /* Execute the command to read the disk geometry */
2730 memset(inq_buff, 0, sizeof(InquiryData_struct));
2731 return_code = sendcmd(CISS_INQUIRY, cntl_num, inq_buff,
2732 sizeof(InquiryData_struct), 1, i, 0xC1, NULL );
2733 if (return_code == IO_OK) {
2734 if (inq_buff->data_byte[8] == 0xFF) {
2735 printk(KERN_WARNING "cciss: reading geometry failed, volume does not support reading geometry\n");
2737 hba[cntl_num]->drv[i].block_size = block_size;
2738 hba[cntl_num]->drv[i].nr_blocks = total_size;
2739 hba[cntl_num]->drv[i].heads = 255;
2740 hba[cntl_num]->drv[i].sectors = 32; /* Sectors */
2742 hba[cntl_num]->drv[i].cylinders = total_size
2746 hba[cntl_num]->drv[i].block_size = block_size;
2747 hba[cntl_num]->drv[i].nr_blocks = total_size;
2748 hba[cntl_num]->drv[i].heads =
2749 inq_buff->data_byte[6];
2750 hba[cntl_num]->drv[i].sectors =
2751 inq_buff->data_byte[7];
2752 hba[cntl_num]->drv[i].cylinders =
2753 (inq_buff->data_byte[4] & 0xff) << 8;
2754 hba[cntl_num]->drv[i].cylinders +=
2755 inq_buff->data_byte[5];
2756 hba[cntl_num]->drv[i].raid_level =
2757 inq_buff->data_byte[8];
2760 else { /* Get geometry failed */
2761 printk(KERN_WARNING "cciss: reading geometry failed, continuing with default geometry\n");
2763 hba[cntl_num]->drv[i].block_size = block_size;
2764 hba[cntl_num]->drv[i].nr_blocks = total_size;
2765 hba[cntl_num]->drv[i].heads = 255;
2766 hba[cntl_num]->drv[i].sectors = 32; /* Sectors */
2768 hba[cntl_num]->drv[i].cylinders = total_size / 255 / 32;
2770 if (hba[cntl_num]->drv[i].raid_level > 5)
2771 hba[cntl_num]->drv[i].raid_level = RAID_UNKNOWN;
2772 printk(KERN_INFO " heads= %d, sectors= %d, cylinders= %d RAID %s\n\n",
2773 hba[cntl_num]->drv[i].heads,
2774 hba[cntl_num]->drv[i].sectors,
2775 hba[cntl_num]->drv[i].cylinders,
2776 raid_label[hba[cntl_num]->drv[i].raid_level]);
2783 /* Function to find the first free pointer into our hba[] array */
2784 /* Returns -1 if no free entries are left. */
2785 static int alloc_cciss_hba(void)
2788 for(i=0; i< MAX_CTLR; i++) {
2789 if (hba[i] == NULL) {
2790 hba[i] = kmalloc(sizeof(ctlr_info_t), GFP_KERNEL);
2792 printk(KERN_ERR "cciss: out of memory.\n");
2798 printk(KERN_WARNING "cciss: This driver supports a maximum"
2799 " of 8 controllers.\n");
2803 static void free_hba(int i)
2810 * This is it. Find all the controllers and register them. I really hate
2811 * stealing all these major device numbers.
2812 * returns the number of block devices registered.
2814 static int __init cciss_init_one(struct pci_dev *pdev,
2815 const struct pci_device_id *ent)
2821 printk(KERN_DEBUG "cciss: Device 0x%x has been found at"
2822 " bus %d dev %d func %d\n",
2823 pdev->device, pdev->bus->number, PCI_SLOT(pdev->devfn),
2824 PCI_FUNC(pdev->devfn));
2825 i = alloc_cciss_hba();
2828 memset(hba[i], 0, sizeof(ctlr_info_t));
2829 if (cciss_pci_init(hba[i], pdev) != 0) {
2833 sprintf(hba[i]->devname, "cciss%d", i);
2835 hba[i]->pdev = pdev;
2837 /* configure PCI DMA stuff */
2838 if (!pci_set_dma_mask(pdev, (u64) 0xffffffffffffffff))
2839 printk("cciss: using DAC cycles\n");
2840 else if (!pci_set_dma_mask(pdev, (u64) 0xffffffff))
2841 printk("cciss: not using DAC cycles\n");
2843 printk("cciss: no suitable DMA available\n");
2848 if (register_blkdev(MAJOR_NR+i, hba[i]->devname, &cciss_fops)) {
2849 printk(KERN_ERR "cciss: Unable to get major number "
2850 "%d for %s\n", MAJOR_NR+i, hba[i]->devname);
2851 release_io_mem(hba[i]);
2855 /* make sure the board interrupts are off */
2856 hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
2857 if (request_irq(hba[i]->intr, do_cciss_intr,
2858 SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM,
2859 hba[i]->devname, hba[i])) {
2861 printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
2862 hba[i]->intr, hba[i]->devname);
2863 unregister_blkdev( MAJOR_NR+i, hba[i]->devname);
2864 release_io_mem(hba[i]);
2868 hba[i]->cmd_pool_bits = (__u32*)kmalloc(
2869 ((NR_CMDS+31)/32)*sizeof(__u32), GFP_KERNEL);
2870 hba[i]->cmd_pool = (CommandList_struct *)pci_alloc_consistent(
2871 hba[i]->pdev, NR_CMDS * sizeof(CommandList_struct),
2872 &(hba[i]->cmd_pool_dhandle));
2873 hba[i]->errinfo_pool = (ErrorInfo_struct *)pci_alloc_consistent(
2874 hba[i]->pdev, NR_CMDS * sizeof( ErrorInfo_struct),
2875 &(hba[i]->errinfo_pool_dhandle));
2876 if ((hba[i]->cmd_pool_bits == NULL)
2877 || (hba[i]->cmd_pool == NULL)
2878 || (hba[i]->errinfo_pool == NULL)) {
2880 if (hba[i]->cmd_pool_bits)
2881 kfree(hba[i]->cmd_pool_bits);
2882 if (hba[i]->cmd_pool)
2883 pci_free_consistent(hba[i]->pdev,
2884 NR_CMDS * sizeof(CommandList_struct),
2885 hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle);
2886 if (hba[i]->errinfo_pool)
2887 pci_free_consistent(hba[i]->pdev,
2888 NR_CMDS * sizeof( ErrorInfo_struct),
2889 hba[i]->errinfo_pool,
2890 hba[i]->errinfo_pool_dhandle);
2891 free_irq(hba[i]->intr, hba[i]);
2892 unregister_blkdev(MAJOR_NR+i, hba[i]->devname);
2893 release_io_mem(hba[i]);
2895 printk( KERN_ERR "cciss: out of memory");
2899 /* Initialize the pdev driver private data.
2900 have it point to hba[i]. */
2901 pci_set_drvdata(pdev, hba[i]);
2902 /* command and error info recs zeroed out before
2904 memset(hba[i]->cmd_pool_bits, 0, ((NR_CMDS+31)/32)*sizeof(__u32));
2907 printk(KERN_DEBUG "Scanning for drives on controller cciss%d\n",i);
2908 #endif /* CCISS_DEBUG */
2910 cciss_getgeometry(i);
2912 cciss_find_non_disk_devices(i); /* find our tape drives, if any */
2914 /* Turn the interrupts on so we can service requests */
2915 hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
2919 q = BLK_DEFAULT_QUEUE(MAJOR_NR + i);
2920 q->queuedata = hba[i];
2921 blk_init_queue(q, do_cciss_request);
2922 blk_queue_bounce_limit(q, hba[i]->pdev->dma_mask);
2923 blk_queue_headactive(q, 0);
2925 /* fill in the other Kernel structs */
2926 blksize_size[MAJOR_NR+i] = hba[i]->blocksizes;
2927 hardsect_size[MAJOR_NR+i] = hba[i]->hardsizes;
2928 read_ahead[MAJOR_NR+i] = READ_AHEAD;
2930 /* Set the pointers to queue functions */
2931 q->back_merge_fn = cpq_back_merge_fn;
2932 q->front_merge_fn = cpq_front_merge_fn;
2933 q->merge_requests_fn = cpq_merge_requests_fn;
2936 /* Fill in the gendisk data */
2937 hba[i]->gendisk.major = MAJOR_NR + i;
2938 hba[i]->gendisk.major_name = "cciss";
2939 hba[i]->gendisk.minor_shift = NWD_SHIFT;
2940 hba[i]->gendisk.max_p = MAX_PART;
2941 hba[i]->gendisk.part = hba[i]->hd;
2942 hba[i]->gendisk.sizes = hba[i]->sizes;
2943 hba[i]->gendisk.nr_real = hba[i]->highest_lun+1;
2944 hba[i]->gendisk.fops = &cciss_fops;
2946 /* Get on the disk list */
2947 add_gendisk(&(hba[i]->gendisk));
2950 for(j=0; j<NWD; j++)
2951 register_disk(&(hba[i]->gendisk),
2952 MKDEV(MAJOR_NR+i, j <<4),
2953 MAX_PART, &cciss_fops,
2954 hba[i]->drv[j].nr_blocks);
2956 cciss_register_scsi(i, 1); /* hook ourself into SCSI subsystem */
2961 static void __devexit cciss_remove_one (struct pci_dev *pdev)
2963 ctlr_info_t *tmp_ptr;
2968 if (pci_get_drvdata(pdev) == NULL) {
2969 printk( KERN_ERR "cciss: Unable to remove device \n");
2972 tmp_ptr = pci_get_drvdata(pdev);
2974 if (hba[i] == NULL) {
2975 printk(KERN_ERR "cciss: device appears to "
2976 "already be removed \n");
2979 /* Turn board interrupts off and send the flush cache command */
2980 /* sendcmd will turn off interrupt, and send the flush...
2981 * To write all data in the battery backed cache to disks */
2982 memset(flush_buf, 0, 4);
2983 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4,0,0,0, NULL);
2984 if (return_code != IO_OK) {
2986 "Error Flushing cache on controller %d\n", i);
2988 free_irq(hba[i]->intr, hba[i]);
2989 pci_set_drvdata(pdev, NULL);
2990 iounmap((void*)hba[i]->vaddr);
2991 cciss_unregister_scsi(i); /* unhook from SCSI subsystem */
2992 unregister_blkdev(MAJOR_NR+i, hba[i]->devname);
2993 remove_proc_entry(hba[i]->devname, proc_cciss);
2996 /* remove it from the disk list */
2997 del_gendisk(&(hba[i]->gendisk));
2999 pci_free_consistent(hba[i]->pdev, NR_CMDS * sizeof(CommandList_struct),
3000 hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle);
3001 pci_free_consistent(hba[i]->pdev, NR_CMDS * sizeof( ErrorInfo_struct),
3002 hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle);
3003 kfree(hba[i]->cmd_pool_bits);
3004 release_io_mem(hba[i]);
3008 static struct pci_driver cciss_pci_driver = {
3010 probe: cciss_init_one,
3011 remove: __devexit_p(cciss_remove_one),
3012 id_table: cciss_pci_device_id, /* id_table */
3016 * This is it. Register the PCI driver information for the cards we control
3017 * the OS will call our registered routines when it finds one of our cards.
3019 int __init cciss_init(void)
3022 printk(KERN_INFO DRIVER_NAME "\n");
3023 /* Register for out PCI devices */
3024 if (pci_register_driver(&cciss_pci_driver) > 0 )
3032 static int __init init_cciss_module(void)
3035 return cciss_init();
3038 static void __exit cleanup_cciss_module(void)
3042 pci_unregister_driver(&cciss_pci_driver);
3043 /* double check that all controller entrys have been removed */
3044 for (i=0; i< MAX_CTLR; i++) {
3045 if (hba[i] != NULL) {
3046 printk(KERN_WARNING "cciss: had to remove"
3047 " controller %d\n", i);
3048 cciss_remove_one(hba[i]->pdev);
3051 remove_proc_entry("cciss", proc_root_driver);
3054 module_init(init_cciss_module);
3055 module_exit(cleanup_cciss_module);