1 /***************************************************************************
5 copyright : (C) 2000 by Adaptec
7 July 30, 2001 First version being submitted
8 for inclusion in the kernel. V2.4
10 See Documentation/scsi/dpti.txt for history, notes, license info
12 ***************************************************************************/
14 /***************************************************************************
16 * This program is free software; you can redistribute it and/or modify *
17 * it under the terms of the GNU General Public License as published by *
18 * the Free Software Foundation; either version 2 of the License, or *
19 * (at your option) any later version. *
21 ***************************************************************************/
22 /***************************************************************************
23 * Sat Dec 20 2003 Go Taniguchi <go@turbolinux.co.jp>
24 - Support 2.6 kernel and DMA-mapping
25 - ioctl fix for raid tools
26 - use schedule_timeout in long long loop
27 **************************************************************************/
30 /*#define UARTDELAY 1 */
32 #include <linux/module.h>
34 MODULE_AUTHOR("Deanna Bonds, with _lots_ of help from Mark Salyzyn");
35 MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
37 ////////////////////////////////////////////////////////////////
39 #include <linux/ioctl.h> /* For SCSI-Passthrough */
40 #include <linux/uaccess.h>
42 #include <linux/stat.h>
43 #include <linux/slab.h> /* for kmalloc() */
44 #include <linux/pci.h> /* for PCI support */
45 #include <linux/proc_fs.h>
46 #include <linux/blkdev.h>
47 #include <linux/delay.h> /* for udelay */
48 #include <linux/interrupt.h>
49 #include <linux/kernel.h> /* for printk */
50 #include <linux/sched.h>
51 #include <linux/reboot.h>
52 #include <linux/spinlock.h>
53 #include <linux/dma-mapping.h>
55 #include <linux/timer.h>
56 #include <linux/string.h>
57 #include <linux/ioport.h>
58 #include <linux/mutex.h>
60 #include <asm/processor.h> /* for boot_cpu_data */
61 #include <asm/pgtable.h>
64 #include <scsi/scsi.h>
65 #include <scsi/scsi_cmnd.h>
66 #include <scsi/scsi_device.h>
67 #include <scsi/scsi_host.h>
68 #include <scsi/scsi_tcq.h>
70 #include "dpt/dptsig.h"
73 /*============================================================================
74 * Create a binary signature - this is read by dptsig
75 * Needed for our management apps
76 *============================================================================
78 static DEFINE_MUTEX(adpt_mutex);
79 static dpt_sig_S DPTI_sig = {
80 {'d', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION,
82 PROC_INTEL, PROC_386 | PROC_486 | PROC_PENTIUM | PROC_SEXIUM,
83 #elif defined(__ia64__)
84 PROC_INTEL, PROC_IA64,
85 #elif defined(__sparc__)
86 PROC_ULTRASPARC, PROC_ULTRASPARC,
87 #elif defined(__alpha__)
88 PROC_ALPHA, PROC_ALPHA,
92 FT_HBADRVR, 0, OEM_DPT, OS_LINUX, CAP_OVERLAP, DEV_ALL,
93 ADF_ALL_SC5, 0, 0, DPT_VERSION, DPT_REVISION, DPT_SUBREVISION,
94 DPT_MONTH, DPT_DAY, DPT_YEAR, "Adaptec Linux I2O RAID Driver"
100 /*============================================================================
102 *============================================================================
105 static DEFINE_MUTEX(adpt_configuration_lock);
107 static struct i2o_sys_tbl *sys_tbl;
108 static dma_addr_t sys_tbl_pa;
109 static int sys_tbl_ind;
110 static int sys_tbl_len;
112 static adpt_hba* hba_chain = NULL;
113 static int hba_count = 0;
115 static struct class *adpt_sysfs_class;
117 static long adpt_unlocked_ioctl(struct file *, unsigned int, unsigned long);
119 static long compat_adpt_ioctl(struct file *, unsigned int, unsigned long);
122 static const struct file_operations adpt_fops = {
123 .unlocked_ioctl = adpt_unlocked_ioctl,
125 .release = adpt_close,
127 .compat_ioctl = compat_adpt_ioctl,
129 .llseek = noop_llseek,
132 /* Structures and definitions for synchronous message posting.
133 * See adpt_i2o_post_wait() for description
135 struct adpt_i2o_post_wait_data
139 adpt_wait_queue_head_t *wq;
140 struct adpt_i2o_post_wait_data *next;
143 static struct adpt_i2o_post_wait_data *adpt_post_wait_queue = NULL;
144 static u32 adpt_post_wait_id = 0;
145 static DEFINE_SPINLOCK(adpt_post_wait_lock);
148 /*============================================================================
150 *============================================================================
153 static inline int dpt_dma64(adpt_hba *pHba)
155 return (sizeof(dma_addr_t) > 4 && (pHba)->dma64);
158 static inline u32 dma_high(dma_addr_t addr)
160 return upper_32_bits(addr);
163 static inline u32 dma_low(dma_addr_t addr)
168 static u8 adpt_read_blink_led(adpt_hba* host)
170 if (host->FwDebugBLEDflag_P) {
171 if( readb(host->FwDebugBLEDflag_P) == 0xbc ){
172 return readb(host->FwDebugBLEDvalue_P);
178 /*============================================================================
179 * Scsi host template interface functions
180 *============================================================================
184 static struct pci_device_id dptids[] = {
185 { PCI_DPT_VENDOR_ID, PCI_DPT_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
186 { PCI_DPT_VENDOR_ID, PCI_DPT_RAPTOR_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
191 MODULE_DEVICE_TABLE(pci,dptids);
193 static int adpt_detect(struct scsi_host_template* sht)
195 struct pci_dev *pDev = NULL;
199 PINFO("Detecting Adaptec I2O RAID controllers...\n");
201 /* search for all Adatpec I2O RAID cards */
202 while ((pDev = pci_get_device( PCI_DPT_VENDOR_ID, PCI_ANY_ID, pDev))) {
203 if(pDev->device == PCI_DPT_DEVICE_ID ||
204 pDev->device == PCI_DPT_RAPTOR_DEVICE_ID){
205 if(adpt_install_hba(sht, pDev) ){
206 PERROR("Could not Init an I2O RAID device\n");
207 PERROR("Will not try to detect others.\n");
214 /* In INIT state, Activate IOPs */
215 for (pHba = hba_chain; pHba; pHba = next) {
217 // Activate does get status , init outbound, and get hrt
218 if (adpt_i2o_activate_hba(pHba) < 0) {
219 adpt_i2o_delete_hba(pHba);
224 /* Active IOPs in HOLD state */
227 if (hba_chain == NULL)
231 * If build_sys_table fails, we kill everything and bail
232 * as we can't init the IOPs w/o a system table
234 if (adpt_i2o_build_sys_table() < 0) {
235 adpt_i2o_sys_shutdown();
239 PDEBUG("HBA's in HOLD state\n");
241 /* If IOP don't get online, we need to rebuild the System table */
242 for (pHba = hba_chain; pHba; pHba = pHba->next) {
243 if (adpt_i2o_online_hba(pHba) < 0) {
244 adpt_i2o_delete_hba(pHba);
245 goto rebuild_sys_tab;
249 /* Active IOPs now in OPERATIONAL state */
250 PDEBUG("HBA's in OPERATIONAL state\n");
252 printk("dpti: If you have a lot of devices this could take a few minutes.\n");
253 for (pHba = hba_chain; pHba; pHba = next) {
255 printk(KERN_INFO"%s: Reading the hardware resource table.\n", pHba->name);
256 if (adpt_i2o_lct_get(pHba) < 0){
257 adpt_i2o_delete_hba(pHba);
261 if (adpt_i2o_parse_lct(pHba) < 0){
262 adpt_i2o_delete_hba(pHba);
268 adpt_sysfs_class = class_create(THIS_MODULE, "dpt_i2o");
269 if (IS_ERR(adpt_sysfs_class)) {
270 printk(KERN_WARNING"dpti: unable to create dpt_i2o class\n");
271 adpt_sysfs_class = NULL;
274 for (pHba = hba_chain; pHba; pHba = next) {
276 if (adpt_scsi_host_alloc(pHba, sht) < 0){
277 adpt_i2o_delete_hba(pHba);
280 pHba->initialized = TRUE;
281 pHba->state &= ~DPTI_STATE_RESET;
282 if (adpt_sysfs_class) {
283 struct device *dev = device_create(adpt_sysfs_class,
284 NULL, MKDEV(DPTI_I2O_MAJOR, pHba->unit), NULL,
285 "dpti%d", pHba->unit);
287 printk(KERN_WARNING"dpti%d: unable to "
288 "create device in dpt_i2o class\n",
294 // Register our control device node
295 // nodes will need to be created in /dev to access this
296 // the nodes can not be created from within the driver
297 if (hba_count && register_chrdev(DPTI_I2O_MAJOR, DPT_DRIVER, &adpt_fops)) {
298 adpt_i2o_sys_shutdown();
306 * scsi_unregister will be called AFTER we return.
308 static int adpt_release(struct Scsi_Host *host)
310 adpt_hba* pHba = (adpt_hba*) host->hostdata[0];
311 // adpt_i2o_quiesce_hba(pHba);
312 adpt_i2o_delete_hba(pHba);
313 scsi_unregister(host);
318 static void adpt_inquiry(adpt_hba* pHba)
332 memset(msg, 0, sizeof(msg));
333 buf = dma_alloc_coherent(&pHba->pDev->dev, 80, &addr, GFP_KERNEL);
335 printk(KERN_ERR"%s: Could not allocate buffer\n",pHba->name);
338 memset((void*)buf, 0, 36);
341 direction = 0x00000000;
342 scsidir =0x40000000; // DATA IN (iop<--dev)
345 reqlen = 17; // SINGLE SGE, 64 bit
347 reqlen = 14; // SINGLE SGE, 32 bit
348 /* Stick the headers on */
349 msg[0] = reqlen<<16 | SGL_OFFSET_12;
350 msg[1] = (0xff<<24|HOST_TID<<12|ADAPTER_TID);
353 // Adaptec/DPT Private stuff
354 msg[4] = I2O_CMD_SCSI_EXEC|DPT_ORGANIZATION_ID<<16;
355 msg[5] = ADAPTER_TID | 1<<16 /* Interpret*/;
356 /* Direction, disconnect ok | sense data | simple queue , CDBLen */
357 // I2O_SCB_FLAG_ENABLE_DISCONNECT |
358 // I2O_SCB_FLAG_SIMPLE_QUEUE_TAG |
359 // I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
360 msg[6] = scsidir|0x20a00000| 6 /* cmd len*/;
364 memset(scb, 0, sizeof(scb));
365 // Write SCSI command into the message - always 16 byte block
372 // Don't care about the rest of scb
374 memcpy(mptr, scb, sizeof(scb));
376 lenptr=mptr++; /* Remember me - fill in when we know */
378 /* Now fill in the SGList and command */
380 if (dpt_dma64(pHba)) {
381 *mptr++ = (0x7C<<24)+(2<<16)+0x02; /* Enable 64 bit */
382 *mptr++ = 1 << PAGE_SHIFT;
383 *mptr++ = 0xD0000000|direction|len;
384 *mptr++ = dma_low(addr);
385 *mptr++ = dma_high(addr);
387 *mptr++ = 0xD0000000|direction|len;
391 // Send it on it's way
392 rcode = adpt_i2o_post_wait(pHba, msg, reqlen<<2, 120);
394 sprintf(pHba->detail, "Adaptec I2O RAID");
395 printk(KERN_INFO "%s: Inquiry Error (%d)\n",pHba->name,rcode);
396 if (rcode != -ETIME && rcode != -EINTR)
397 dma_free_coherent(&pHba->pDev->dev, 80, buf, addr);
399 memset(pHba->detail, 0, sizeof(pHba->detail));
400 memcpy(&(pHba->detail), "Vendor: Adaptec ", 16);
401 memcpy(&(pHba->detail[16]), " Model: ", 8);
402 memcpy(&(pHba->detail[24]), (u8*) &buf[16], 16);
403 memcpy(&(pHba->detail[40]), " FW: ", 4);
404 memcpy(&(pHba->detail[44]), (u8*) &buf[32], 4);
405 pHba->detail[48] = '\0'; /* precautionary */
406 dma_free_coherent(&pHba->pDev->dev, 80, buf, addr);
408 adpt_i2o_status_get(pHba);
413 static int adpt_slave_configure(struct scsi_device * device)
415 struct Scsi_Host *host = device->host;
418 pHba = (adpt_hba *) host->hostdata[0];
420 if (host->can_queue && device->tagged_supported) {
421 scsi_change_queue_depth(device,
422 host->can_queue - 1);
427 static int adpt_queue_lck(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *))
429 adpt_hba* pHba = NULL;
430 struct adpt_device* pDev = NULL; /* dpt per device information */
432 cmd->scsi_done = done;
434 * SCSI REQUEST_SENSE commands will be executed automatically by the
435 * Host Adapter for any errors, so they should not be executed
436 * explicitly unless the Sense Data is zero indicating that no error
440 if ((cmd->cmnd[0] == REQUEST_SENSE) && (cmd->sense_buffer[0] != 0)) {
441 cmd->result = (DID_OK << 16);
446 pHba = (adpt_hba*)cmd->device->host->hostdata[0];
452 if ((pHba->state) & DPTI_STATE_RESET)
453 return SCSI_MLQUEUE_HOST_BUSY;
455 // TODO if the cmd->device if offline then I may need to issue a bus rescan
456 // followed by a get_lct to see if the device is there anymore
457 if((pDev = (struct adpt_device*) (cmd->device->hostdata)) == NULL) {
459 * First command request for this device. Set up a pointer
460 * to the device structure. This should be a TEST_UNIT_READY
461 * command from scan_scsis_single.
463 if ((pDev = adpt_find_device(pHba, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun)) == NULL) {
464 // TODO: if any luns are at this bus, scsi id then fake a TEST_UNIT_READY and INQUIRY response
465 // with type 7F (for all luns less than the max for this bus,id) so the lun scan will continue.
466 cmd->result = (DID_NO_CONNECT << 16);
470 cmd->device->hostdata = pDev;
472 pDev->pScsi_dev = cmd->device;
475 * If we are being called from when the device is being reset,
476 * delay processing of the command until later.
478 if (pDev->state & DPTI_DEV_RESET ) {
481 return adpt_scsi_to_i2o(pHba, cmd, pDev);
484 static DEF_SCSI_QCMD(adpt_queue)
486 static int adpt_bios_param(struct scsi_device *sdev, struct block_device *dev,
487 sector_t capacity, int geom[])
493 // *** First lets set the default geometry ****
495 // If the capacity is less than ox2000
496 if (capacity < 0x2000 ) { // floppy
500 // else if between 0x2000 and 0x20000
501 else if (capacity < 0x20000) {
505 // else if between 0x20000 and 0x40000
506 else if (capacity < 0x40000) {
510 // else if between 0x4000 and 0x80000
511 else if (capacity < 0x80000) {
515 // else if greater than 0x80000
520 cylinders = sector_div(capacity, heads * sectors);
522 // Special case if CDROM
523 if(sdev->type == 5) { // CDROM
533 PDEBUG("adpt_bios_param: exit\n");
538 static const char *adpt_info(struct Scsi_Host *host)
542 pHba = (adpt_hba *) host->hostdata[0];
543 return (char *) (pHba->detail);
546 static int adpt_show_info(struct seq_file *m, struct Scsi_Host *host)
548 struct adpt_device* d;
554 // Find HBA (host bus adapter) we are looking for
555 mutex_lock(&adpt_configuration_lock);
556 for (pHba = hba_chain; pHba; pHba = pHba->next) {
557 if (pHba->host == host) {
558 break; /* found adapter */
561 mutex_unlock(&adpt_configuration_lock);
567 seq_printf(m, "Adaptec I2O RAID Driver Version: %s\n\n", DPT_I2O_VERSION);
568 seq_printf(m, "%s\n", pHba->detail);
569 seq_printf(m, "SCSI Host=scsi%d Control Node=/dev/%s irq=%d\n",
570 pHba->host->host_no, pHba->name, host->irq);
571 seq_printf(m, "\tpost fifo size = %d\n\treply fifo size = %d\n\tsg table size = %d\n\n",
572 host->can_queue, (int) pHba->reply_fifo_size , host->sg_tablesize);
574 seq_puts(m, "Devices:\n");
575 for(chan = 0; chan < MAX_CHANNEL; chan++) {
576 for(id = 0; id < MAX_ID; id++) {
577 d = pHba->channel[chan].device[id];
579 seq_printf(m,"\t%-24.24s", d->pScsi_dev->vendor);
580 seq_printf(m," Rev: %-8.8s\n", d->pScsi_dev->rev);
582 unit = d->pI2o_dev->lct_data.tid;
583 seq_printf(m, "\tTID=%d, (Channel=%d, Target=%d, Lun=%llu) (%s)\n\n",
584 unit, (int)d->scsi_channel, (int)d->scsi_id, d->scsi_lun,
585 scsi_device_online(d->pScsi_dev)? "online":"offline");
594 * Turn a struct scsi_cmnd * into a unique 32 bit 'context'.
596 static u32 adpt_cmd_to_context(struct scsi_cmnd *cmd)
598 return (u32)cmd->serial_number;
602 * Go from a u32 'context' to a struct scsi_cmnd * .
603 * This could probably be made more efficient.
605 static struct scsi_cmnd *
606 adpt_cmd_from_context(adpt_hba * pHba, u32 context)
608 struct scsi_cmnd * cmd;
609 struct scsi_device * d;
614 spin_unlock(pHba->host->host_lock);
615 shost_for_each_device(d, pHba->host) {
617 spin_lock_irqsave(&d->list_lock, flags);
618 list_for_each_entry(cmd, &d->cmd_list, list) {
619 if (((u32)cmd->serial_number == context)) {
620 spin_unlock_irqrestore(&d->list_lock, flags);
622 spin_lock(pHba->host->host_lock);
626 spin_unlock_irqrestore(&d->list_lock, flags);
628 spin_lock(pHba->host->host_lock);
633 /*===========================================================================
634 * Error Handling routines
635 *===========================================================================
638 static int adpt_abort(struct scsi_cmnd * cmd)
640 adpt_hba* pHba = NULL; /* host bus adapter structure */
641 struct adpt_device* dptdevice; /* dpt per device information */
645 if(cmd->serial_number == 0){
648 pHba = (adpt_hba*) cmd->device->host->hostdata[0];
649 printk(KERN_INFO"%s: Trying to Abort\n",pHba->name);
650 if ((dptdevice = (void*) (cmd->device->hostdata)) == NULL) {
651 printk(KERN_ERR "%s: Unable to abort: No device in cmnd\n",pHba->name);
655 memset(msg, 0, sizeof(msg));
656 msg[0] = FIVE_WORD_MSG_SIZE|SGL_OFFSET_0;
657 msg[1] = I2O_CMD_SCSI_ABORT<<24|HOST_TID<<12|dptdevice->tid;
660 msg[4] = adpt_cmd_to_context(cmd);
662 spin_lock_irq(pHba->host->host_lock);
663 rcode = adpt_i2o_post_wait(pHba, msg, sizeof(msg), FOREVER);
665 spin_unlock_irq(pHba->host->host_lock);
667 if(rcode == -EOPNOTSUPP ){
668 printk(KERN_INFO"%s: Abort cmd not supported\n",pHba->name);
671 printk(KERN_INFO"%s: Abort failed.\n",pHba->name);
674 printk(KERN_INFO"%s: Abort complete.\n",pHba->name);
679 #define I2O_DEVICE_RESET 0x27
680 // This is the same for BLK and SCSI devices
681 // NOTE this is wrong in the i2o.h definitions
682 // This is not currently supported by our adapter but we issue it anyway
683 static int adpt_device_reset(struct scsi_cmnd* cmd)
689 struct adpt_device* d = cmd->device->hostdata;
691 pHba = (void*) cmd->device->host->hostdata[0];
692 printk(KERN_INFO"%s: Trying to reset device\n",pHba->name);
694 printk(KERN_INFO"%s: Reset Device: Device Not found\n",pHba->name);
697 memset(msg, 0, sizeof(msg));
698 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
699 msg[1] = (I2O_DEVICE_RESET<<24|HOST_TID<<12|d->tid);
704 spin_lock_irq(pHba->host->host_lock);
705 old_state = d->state;
706 d->state |= DPTI_DEV_RESET;
707 rcode = adpt_i2o_post_wait(pHba, msg,sizeof(msg), FOREVER);
708 d->state = old_state;
710 spin_unlock_irq(pHba->host->host_lock);
712 if(rcode == -EOPNOTSUPP ){
713 printk(KERN_INFO"%s: Device reset not supported\n",pHba->name);
716 printk(KERN_INFO"%s: Device reset failed\n",pHba->name);
719 printk(KERN_INFO"%s: Device reset successful\n",pHba->name);
725 #define I2O_HBA_BUS_RESET 0x87
726 // This version of bus reset is called by the eh_error handler
727 static int adpt_bus_reset(struct scsi_cmnd* cmd)
733 pHba = (adpt_hba*)cmd->device->host->hostdata[0];
734 memset(msg, 0, sizeof(msg));
735 printk(KERN_WARNING"%s: Bus reset: SCSI Bus %d: tid: %d\n",pHba->name, cmd->device->channel,pHba->channel[cmd->device->channel].tid );
736 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
737 msg[1] = (I2O_HBA_BUS_RESET<<24|HOST_TID<<12|pHba->channel[cmd->device->channel].tid);
741 spin_lock_irq(pHba->host->host_lock);
742 rcode = adpt_i2o_post_wait(pHba, msg,sizeof(msg), FOREVER);
744 spin_unlock_irq(pHba->host->host_lock);
746 printk(KERN_WARNING"%s: Bus reset failed.\n",pHba->name);
749 printk(KERN_WARNING"%s: Bus reset success.\n",pHba->name);
754 // This version of reset is called by the eh_error_handler
755 static int __adpt_reset(struct scsi_cmnd* cmd)
759 pHba = (adpt_hba*)cmd->device->host->hostdata[0];
760 printk(KERN_WARNING"%s: Hba Reset: scsi id %d: tid: %d\n",pHba->name,cmd->device->channel,pHba->channel[cmd->device->channel].tid );
761 rcode = adpt_hba_reset(pHba);
763 printk(KERN_WARNING"%s: HBA reset complete\n",pHba->name);
766 printk(KERN_WARNING"%s: HBA reset failed (%x)\n",pHba->name, rcode);
771 static int adpt_reset(struct scsi_cmnd* cmd)
775 spin_lock_irq(cmd->device->host->host_lock);
776 rc = __adpt_reset(cmd);
777 spin_unlock_irq(cmd->device->host->host_lock);
782 // This version of reset is called by the ioctls and indirectly from eh_error_handler via adpt_reset
783 static int adpt_hba_reset(adpt_hba* pHba)
787 pHba->state |= DPTI_STATE_RESET;
789 // Activate does get status , init outbound, and get hrt
790 if ((rcode=adpt_i2o_activate_hba(pHba)) < 0) {
791 printk(KERN_ERR "%s: Could not activate\n", pHba->name);
792 adpt_i2o_delete_hba(pHba);
796 if ((rcode=adpt_i2o_build_sys_table()) < 0) {
797 adpt_i2o_delete_hba(pHba);
800 PDEBUG("%s: in HOLD state\n",pHba->name);
802 if ((rcode=adpt_i2o_online_hba(pHba)) < 0) {
803 adpt_i2o_delete_hba(pHba);
806 PDEBUG("%s: in OPERATIONAL state\n",pHba->name);
808 if ((rcode=adpt_i2o_lct_get(pHba)) < 0){
809 adpt_i2o_delete_hba(pHba);
813 if ((rcode=adpt_i2o_reparse_lct(pHba)) < 0){
814 adpt_i2o_delete_hba(pHba);
817 pHba->state &= ~DPTI_STATE_RESET;
819 adpt_fail_posted_scbs(pHba);
820 return 0; /* return success */
823 /*===========================================================================
825 *===========================================================================
829 static void adpt_i2o_sys_shutdown(void)
831 adpt_hba *pHba, *pNext;
832 struct adpt_i2o_post_wait_data *p1, *old;
834 printk(KERN_INFO"Shutting down Adaptec I2O controllers.\n");
835 printk(KERN_INFO" This could take a few minutes if there are many devices attached\n");
836 /* Delete all IOPs from the controller chain */
837 /* They should have already been released by the
840 for (pHba = hba_chain; pHba; pHba = pNext) {
842 adpt_i2o_delete_hba(pHba);
845 /* Remove any timedout entries from the wait queue. */
846 // spin_lock_irqsave(&adpt_post_wait_lock, flags);
847 /* Nothing should be outstanding at this point so just
850 for(p1 = adpt_post_wait_queue; p1;) {
855 // spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
856 adpt_post_wait_queue = NULL;
858 printk(KERN_INFO "Adaptec I2O controllers down.\n");
861 static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev)
864 adpt_hba* pHba = NULL;
866 ulong base_addr0_phys = 0;
867 ulong base_addr1_phys = 0;
868 u32 hba_map0_area_size = 0;
869 u32 hba_map1_area_size = 0;
870 void __iomem *base_addr_virt = NULL;
871 void __iomem *msg_addr_virt = NULL;
874 int raptorFlag = FALSE;
876 if(pci_enable_device(pDev)) {
880 if (pci_request_regions(pDev, "dpt_i2o")) {
881 PERROR("dpti: adpt_config_hba: pci request region failed\n");
885 pci_set_master(pDev);
888 * See if we should enable dma64 mode.
890 if (sizeof(dma_addr_t) > 4 &&
891 pci_set_dma_mask(pDev, DMA_BIT_MASK(64)) == 0) {
892 if (dma_get_required_mask(&pDev->dev) > DMA_BIT_MASK(32))
895 if (!dma64 && pci_set_dma_mask(pDev, DMA_BIT_MASK(32)) != 0)
898 /* adapter only supports message blocks below 4GB */
899 pci_set_consistent_dma_mask(pDev, DMA_BIT_MASK(32));
901 base_addr0_phys = pci_resource_start(pDev,0);
902 hba_map0_area_size = pci_resource_len(pDev,0);
904 // Check if standard PCI card or single BAR Raptor
905 if(pDev->device == PCI_DPT_DEVICE_ID){
906 if(pDev->subsystem_device >=0xc032 && pDev->subsystem_device <= 0xc03b){
907 // Raptor card with this device id needs 4M
908 hba_map0_area_size = 0x400000;
909 } else { // Not Raptor - it is a PCI card
910 if(hba_map0_area_size > 0x100000 ){
911 hba_map0_area_size = 0x100000;
914 } else {// Raptor split BAR config
915 // Use BAR1 in this configuration
916 base_addr1_phys = pci_resource_start(pDev,1);
917 hba_map1_area_size = pci_resource_len(pDev,1);
921 #if BITS_PER_LONG == 64
923 * The original Adaptec 64 bit driver has this comment here:
924 * "x86_64 machines need more optimal mappings"
926 * I assume some HBAs report ridiculously large mappings
927 * and we need to limit them on platforms with IOMMUs.
929 if (raptorFlag == TRUE) {
930 if (hba_map0_area_size > 128)
931 hba_map0_area_size = 128;
932 if (hba_map1_area_size > 524288)
933 hba_map1_area_size = 524288;
935 if (hba_map0_area_size > 524288)
936 hba_map0_area_size = 524288;
940 base_addr_virt = ioremap(base_addr0_phys,hba_map0_area_size);
941 if (!base_addr_virt) {
942 pci_release_regions(pDev);
943 PERROR("dpti: adpt_config_hba: io remap failed\n");
947 if(raptorFlag == TRUE) {
948 msg_addr_virt = ioremap(base_addr1_phys, hba_map1_area_size );
949 if (!msg_addr_virt) {
950 PERROR("dpti: adpt_config_hba: io remap failed on BAR1\n");
951 iounmap(base_addr_virt);
952 pci_release_regions(pDev);
956 msg_addr_virt = base_addr_virt;
959 // Allocate and zero the data structure
960 pHba = kzalloc(sizeof(adpt_hba), GFP_KERNEL);
962 if (msg_addr_virt != base_addr_virt)
963 iounmap(msg_addr_virt);
964 iounmap(base_addr_virt);
965 pci_release_regions(pDev);
969 mutex_lock(&adpt_configuration_lock);
971 if(hba_chain != NULL){
972 for(p = hba_chain; p->next; p = p->next);
978 pHba->unit = hba_count;
979 sprintf(pHba->name, "dpti%d", hba_count);
982 mutex_unlock(&adpt_configuration_lock);
985 pHba->base_addr_phys = base_addr0_phys;
987 // Set up the Virtual Base Address of the I2O Device
988 pHba->base_addr_virt = base_addr_virt;
989 pHba->msg_addr_virt = msg_addr_virt;
990 pHba->irq_mask = base_addr_virt+0x30;
991 pHba->post_port = base_addr_virt+0x40;
992 pHba->reply_port = base_addr_virt+0x44;
997 pHba->status_block = NULL;
998 pHba->post_count = 0;
999 pHba->state = DPTI_STATE_RESET;
1001 pHba->devices = NULL;
1002 pHba->dma64 = dma64;
1004 // Initializing the spinlocks
1005 spin_lock_init(&pHba->state_lock);
1006 spin_lock_init(&adpt_post_wait_lock);
1008 if(raptorFlag == 0){
1009 printk(KERN_INFO "Adaptec I2O RAID controller"
1010 " %d at %p size=%x irq=%d%s\n",
1011 hba_count-1, base_addr_virt,
1012 hba_map0_area_size, pDev->irq,
1013 dma64 ? " (64-bit DMA)" : "");
1015 printk(KERN_INFO"Adaptec I2O RAID controller %d irq=%d%s\n",
1016 hba_count-1, pDev->irq,
1017 dma64 ? " (64-bit DMA)" : "");
1018 printk(KERN_INFO" BAR0 %p - size= %x\n",base_addr_virt,hba_map0_area_size);
1019 printk(KERN_INFO" BAR1 %p - size= %x\n",msg_addr_virt,hba_map1_area_size);
1022 if (request_irq (pDev->irq, adpt_isr, IRQF_SHARED, pHba->name, pHba)) {
1023 printk(KERN_ERR"%s: Couldn't register IRQ %d\n", pHba->name, pDev->irq);
1024 adpt_i2o_delete_hba(pHba);
1032 static void adpt_i2o_delete_hba(adpt_hba* pHba)
1036 struct i2o_device* d;
1037 struct i2o_device* next;
1040 struct adpt_device* pDev;
1041 struct adpt_device* pNext;
1044 mutex_lock(&adpt_configuration_lock);
1045 // scsi_unregister calls our adpt_release which
1048 free_irq(pHba->host->irq, pHba);
1051 for( p1 = hba_chain; p1; p2 = p1,p1=p1->next){
1054 p2->next = p1->next;
1056 hba_chain = p1->next;
1063 mutex_unlock(&adpt_configuration_lock);
1065 iounmap(pHba->base_addr_virt);
1066 pci_release_regions(pHba->pDev);
1067 if(pHba->msg_addr_virt != pHba->base_addr_virt){
1068 iounmap(pHba->msg_addr_virt);
1070 if(pHba->FwDebugBuffer_P)
1071 iounmap(pHba->FwDebugBuffer_P);
1073 dma_free_coherent(&pHba->pDev->dev,
1074 pHba->hrt->num_entries * pHba->hrt->entry_len << 2,
1075 pHba->hrt, pHba->hrt_pa);
1078 dma_free_coherent(&pHba->pDev->dev, pHba->lct_size,
1079 pHba->lct, pHba->lct_pa);
1081 if(pHba->status_block) {
1082 dma_free_coherent(&pHba->pDev->dev, sizeof(i2o_status_block),
1083 pHba->status_block, pHba->status_block_pa);
1085 if(pHba->reply_pool) {
1086 dma_free_coherent(&pHba->pDev->dev,
1087 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
1088 pHba->reply_pool, pHba->reply_pool_pa);
1091 for(d = pHba->devices; d ; d = next){
1095 for(i = 0 ; i < pHba->top_scsi_channel ; i++){
1096 for(j = 0; j < MAX_ID; j++){
1097 if(pHba->channel[i].device[j] != NULL){
1098 for(pDev = pHba->channel[i].device[j]; pDev; pDev = pNext){
1099 pNext = pDev->next_lun;
1105 pci_dev_put(pHba->pDev);
1106 if (adpt_sysfs_class)
1107 device_destroy(adpt_sysfs_class,
1108 MKDEV(DPTI_I2O_MAJOR, pHba->unit));
1112 unregister_chrdev(DPTI_I2O_MAJOR, DPT_DRIVER);
1113 if (adpt_sysfs_class) {
1114 class_destroy(adpt_sysfs_class);
1115 adpt_sysfs_class = NULL;
1120 static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u64 lun)
1122 struct adpt_device* d;
1124 if(chan < 0 || chan >= MAX_CHANNEL)
1127 d = pHba->channel[chan].device[id];
1128 if(!d || d->tid == 0) {
1132 /* If it is the only lun at that address then this should match*/
1133 if(d->scsi_lun == lun){
1137 /* else we need to look through all the luns */
1138 for(d=d->next_lun ; d ; d = d->next_lun){
1139 if(d->scsi_lun == lun){
1147 static int adpt_i2o_post_wait(adpt_hba* pHba, u32* msg, int len, int timeout)
1149 // I used my own version of the WAIT_QUEUE_HEAD
1150 // to handle some version differences
1151 // When embedded in the kernel this could go back to the vanilla one
1152 ADPT_DECLARE_WAIT_QUEUE_HEAD(adpt_wq_i2o_post);
1155 struct adpt_i2o_post_wait_data *p1, *p2;
1156 struct adpt_i2o_post_wait_data *wait_data =
1157 kmalloc(sizeof(struct adpt_i2o_post_wait_data), GFP_ATOMIC);
1158 DECLARE_WAITQUEUE(wait, current);
1164 * The spin locking is needed to keep anyone from playing
1165 * with the queue pointers and id while we do the same
1167 spin_lock_irqsave(&adpt_post_wait_lock, flags);
1168 // TODO we need a MORE unique way of getting ids
1169 // to support async LCT get
1170 wait_data->next = adpt_post_wait_queue;
1171 adpt_post_wait_queue = wait_data;
1172 adpt_post_wait_id++;
1173 adpt_post_wait_id &= 0x7fff;
1174 wait_data->id = adpt_post_wait_id;
1175 spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
1177 wait_data->wq = &adpt_wq_i2o_post;
1178 wait_data->status = -ETIMEDOUT;
1180 add_wait_queue(&adpt_wq_i2o_post, &wait);
1182 msg[2] |= 0x80000000 | ((u32)wait_data->id);
1184 if((status = adpt_i2o_post_this(pHba, msg, len)) == 0){
1185 set_current_state(TASK_INTERRUPTIBLE);
1187 spin_unlock_irq(pHba->host->host_lock);
1191 timeout = schedule_timeout(timeout);
1193 // I/O issued, but cannot get result in
1194 // specified time. Freeing resorces is
1200 spin_lock_irq(pHba->host->host_lock);
1202 remove_wait_queue(&adpt_wq_i2o_post, &wait);
1204 if(status == -ETIMEDOUT){
1205 printk(KERN_INFO"dpti%d: POST WAIT TIMEOUT\n",pHba->unit);
1206 // We will have to free the wait_data memory during shutdown
1210 /* Remove the entry from the queue. */
1212 spin_lock_irqsave(&adpt_post_wait_lock, flags);
1213 for(p1 = adpt_post_wait_queue; p1; p2 = p1, p1 = p1->next) {
1214 if(p1 == wait_data) {
1215 if(p1->status == I2O_DETAIL_STATUS_UNSUPPORTED_FUNCTION ) {
1216 status = -EOPNOTSUPP;
1219 p2->next = p1->next;
1221 adpt_post_wait_queue = p1->next;
1226 spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
1234 static s32 adpt_i2o_post_this(adpt_hba* pHba, u32* data, int len)
1237 u32 m = EMPTY_QUEUE;
1239 ulong timeout = jiffies + 30*HZ;
1242 m = readl(pHba->post_port);
1243 if (m != EMPTY_QUEUE) {
1246 if(time_after(jiffies,timeout)){
1247 printk(KERN_WARNING"dpti%d: Timeout waiting for message frame!\n", pHba->unit);
1250 schedule_timeout_uninterruptible(1);
1251 } while(m == EMPTY_QUEUE);
1253 msg = pHba->msg_addr_virt + m;
1254 memcpy_toio(msg, data, len);
1258 writel(m, pHba->post_port);
1265 static void adpt_i2o_post_wait_complete(u32 context, int status)
1267 struct adpt_i2o_post_wait_data *p1 = NULL;
1269 * We need to search through the adpt_post_wait
1270 * queue to see if the given message is still
1271 * outstanding. If not, it means that the IOP
1272 * took longer to respond to the message than we
1273 * had allowed and timer has already expired.
1274 * Not much we can do about that except log
1275 * it for debug purposes, increase timeout, and recompile
1277 * Lock needed to keep anyone from moving queue pointers
1278 * around while we're looking through them.
1283 spin_lock(&adpt_post_wait_lock);
1284 for(p1 = adpt_post_wait_queue; p1; p1 = p1->next) {
1285 if(p1->id == context) {
1286 p1->status = status;
1287 spin_unlock(&adpt_post_wait_lock);
1288 wake_up_interruptible(p1->wq);
1292 spin_unlock(&adpt_post_wait_lock);
1293 // If this happens we lose commands that probably really completed
1294 printk(KERN_DEBUG"dpti: Could Not find task %d in wait queue\n",context);
1295 printk(KERN_DEBUG" Tasks in wait queue:\n");
1296 for(p1 = adpt_post_wait_queue; p1; p1 = p1->next) {
1297 printk(KERN_DEBUG" %d\n",p1->id);
1302 static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1307 u32 m = EMPTY_QUEUE ;
1308 ulong timeout = jiffies + (TMOUT_IOPRESET*HZ);
1310 if(pHba->initialized == FALSE) { // First time reset should be quick
1311 timeout = jiffies + (25*HZ);
1313 adpt_i2o_quiesce_hba(pHba);
1318 m = readl(pHba->post_port);
1319 if (m != EMPTY_QUEUE) {
1322 if(time_after(jiffies,timeout)){
1323 printk(KERN_WARNING"Timeout waiting for message!\n");
1326 schedule_timeout_uninterruptible(1);
1327 } while (m == EMPTY_QUEUE);
1329 status = dma_alloc_coherent(&pHba->pDev->dev, 4, &addr, GFP_KERNEL);
1330 if(status == NULL) {
1331 adpt_send_nop(pHba, m);
1332 printk(KERN_ERR"IOP reset failed - no free memory.\n");
1337 msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0;
1338 msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID;
1343 msg[6]=dma_low(addr);
1344 msg[7]=dma_high(addr);
1346 memcpy_toio(pHba->msg_addr_virt+m, msg, sizeof(msg));
1348 writel(m, pHba->post_port);
1351 while(*status == 0){
1352 if(time_after(jiffies,timeout)){
1353 printk(KERN_WARNING"%s: IOP Reset Timeout\n",pHba->name);
1354 /* We lose 4 bytes of "status" here, but we cannot
1355 free these because controller may awake and corrupt
1356 those bytes at any time */
1357 /* dma_free_coherent(&pHba->pDev->dev, 4, buf, addr); */
1361 schedule_timeout_uninterruptible(1);
1364 if(*status == 0x01 /*I2O_EXEC_IOP_RESET_IN_PROGRESS*/) {
1365 PDEBUG("%s: Reset in progress...\n", pHba->name);
1366 // Here we wait for message frame to become available
1367 // indicated that reset has finished
1370 m = readl(pHba->post_port);
1371 if (m != EMPTY_QUEUE) {
1374 if(time_after(jiffies,timeout)){
1375 printk(KERN_ERR "%s:Timeout waiting for IOP Reset.\n",pHba->name);
1376 /* We lose 4 bytes of "status" here, but we
1377 cannot free these because controller may
1378 awake and corrupt those bytes at any time */
1379 /* dma_free_coherent(&pHba->pDev->dev, 4, buf, addr); */
1382 schedule_timeout_uninterruptible(1);
1383 } while (m == EMPTY_QUEUE);
1385 adpt_send_nop(pHba, m);
1387 adpt_i2o_status_get(pHba);
1388 if(*status == 0x02 ||
1389 pHba->status_block->iop_state != ADAPTER_STATE_RESET) {
1390 printk(KERN_WARNING"%s: Reset reject, trying to clear\n",
1393 PDEBUG("%s: Reset completed.\n", pHba->name);
1396 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
1398 // This delay is to allow someone attached to the card through the debug UART to
1399 // set up the dump levels that they want before the rest of the initialization sequence
1406 static int adpt_i2o_parse_lct(adpt_hba* pHba)
1411 struct i2o_device *d;
1412 i2o_lct *lct = pHba->lct;
1416 u32 buf[10]; // larger than 7, or 8 ...
1417 struct adpt_device* pDev;
1420 printk(KERN_ERR "%s: LCT is empty???\n",pHba->name);
1424 max = lct->table_size;
1428 for(i=0;i<max;i++) {
1429 if( lct->lct_entry[i].user_tid != 0xfff){
1431 * If we have hidden devices, we need to inform the upper layers about
1432 * the possible maximum id reference to handle device access when
1433 * an array is disassembled. This code has no other purpose but to
1434 * allow us future access to devices that are currently hidden
1435 * behind arrays, hotspares or have not been configured (JBOD mode).
1437 if( lct->lct_entry[i].class_id != I2O_CLASS_RANDOM_BLOCK_STORAGE &&
1438 lct->lct_entry[i].class_id != I2O_CLASS_SCSI_PERIPHERAL &&
1439 lct->lct_entry[i].class_id != I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL ){
1442 tid = lct->lct_entry[i].tid;
1443 // I2O_DPT_DEVICE_INFO_GROUP_NO;
1444 if(adpt_i2o_query_scalar(pHba, tid, 0x8000, -1, buf, 32)<0) {
1447 bus_no = buf[0]>>16;
1449 scsi_lun = scsilun_to_int((struct scsi_lun *)&buf[2]);
1450 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
1451 printk(KERN_WARNING"%s: Channel number %d out of range \n", pHba->name, bus_no);
1454 if (scsi_id >= MAX_ID){
1455 printk(KERN_WARNING"%s: SCSI ID %d out of range \n", pHba->name, bus_no);
1458 if(bus_no > pHba->top_scsi_channel){
1459 pHba->top_scsi_channel = bus_no;
1461 if(scsi_id > pHba->top_scsi_id){
1462 pHba->top_scsi_id = scsi_id;
1464 if(scsi_lun > pHba->top_scsi_lun){
1465 pHba->top_scsi_lun = scsi_lun;
1469 d = kmalloc(sizeof(struct i2o_device), GFP_KERNEL);
1472 printk(KERN_CRIT"%s: Out of memory for I2O device data.\n",pHba->name);
1476 d->controller = pHba;
1479 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
1482 tid = d->lct_data.tid;
1483 adpt_i2o_report_hba_unit(pHba, d);
1484 adpt_i2o_install_device(pHba, d);
1487 for(d = pHba->devices; d ; d = d->next) {
1488 if(d->lct_data.class_id == I2O_CLASS_BUS_ADAPTER_PORT ||
1489 d->lct_data.class_id == I2O_CLASS_FIBRE_CHANNEL_PORT){
1490 tid = d->lct_data.tid;
1491 // TODO get the bus_no from hrt-but for now they are in order
1493 if(bus_no > pHba->top_scsi_channel){
1494 pHba->top_scsi_channel = bus_no;
1496 pHba->channel[bus_no].type = d->lct_data.class_id;
1497 pHba->channel[bus_no].tid = tid;
1498 if(adpt_i2o_query_scalar(pHba, tid, 0x0200, -1, buf, 28)>=0)
1500 pHba->channel[bus_no].scsi_id = buf[1];
1501 PDEBUG("Bus %d - SCSI ID %d.\n", bus_no, buf[1]);
1503 // TODO remove - this is just until we get from hrt
1505 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
1506 printk(KERN_WARNING"%s: Channel number %d out of range - LCT\n", pHba->name, bus_no);
1512 // Setup adpt_device table
1513 for(d = pHba->devices; d ; d = d->next) {
1514 if(d->lct_data.class_id == I2O_CLASS_RANDOM_BLOCK_STORAGE ||
1515 d->lct_data.class_id == I2O_CLASS_SCSI_PERIPHERAL ||
1516 d->lct_data.class_id == I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL ){
1518 tid = d->lct_data.tid;
1520 // I2O_DPT_DEVICE_INFO_GROUP_NO;
1521 if(adpt_i2o_query_scalar(pHba, tid, 0x8000, -1, buf, 32)>=0) {
1522 bus_no = buf[0]>>16;
1524 scsi_lun = scsilun_to_int((struct scsi_lun *)&buf[2]);
1525 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
1528 if (scsi_id >= MAX_ID) {
1531 if( pHba->channel[bus_no].device[scsi_id] == NULL){
1532 pDev = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
1536 pHba->channel[bus_no].device[scsi_id] = pDev;
1538 for( pDev = pHba->channel[bus_no].device[scsi_id];
1539 pDev->next_lun; pDev = pDev->next_lun){
1541 pDev->next_lun = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
1542 if(pDev->next_lun == NULL) {
1545 pDev = pDev->next_lun;
1548 pDev->scsi_channel = bus_no;
1549 pDev->scsi_id = scsi_id;
1550 pDev->scsi_lun = scsi_lun;
1553 pDev->type = (buf[0])&0xff;
1554 pDev->flags = (buf[0]>>8)&0xff;
1555 if(scsi_id > pHba->top_scsi_id){
1556 pHba->top_scsi_id = scsi_id;
1558 if(scsi_lun > pHba->top_scsi_lun){
1559 pHba->top_scsi_lun = scsi_lun;
1563 printk(KERN_WARNING"Could not find SCSI ID for %s\n",
1564 d->lct_data.identity_tag);
1573 * Each I2O controller has a chain of devices on it - these match
1574 * the useful parts of the LCT of the board.
1577 static int adpt_i2o_install_device(adpt_hba* pHba, struct i2o_device *d)
1579 mutex_lock(&adpt_configuration_lock);
1582 d->next=pHba->devices;
1584 if (pHba->devices != NULL){
1585 pHba->devices->prev=d;
1590 mutex_unlock(&adpt_configuration_lock);
1594 static int adpt_open(struct inode *inode, struct file *file)
1599 mutex_lock(&adpt_mutex);
1600 //TODO check for root access
1602 minor = iminor(inode);
1603 if (minor >= hba_count) {
1604 mutex_unlock(&adpt_mutex);
1607 mutex_lock(&adpt_configuration_lock);
1608 for (pHba = hba_chain; pHba; pHba = pHba->next) {
1609 if (pHba->unit == minor) {
1610 break; /* found adapter */
1614 mutex_unlock(&adpt_configuration_lock);
1615 mutex_unlock(&adpt_mutex);
1619 // if(pHba->in_use){
1620 // mutex_unlock(&adpt_configuration_lock);
1625 mutex_unlock(&adpt_configuration_lock);
1626 mutex_unlock(&adpt_mutex);
1631 static int adpt_close(struct inode *inode, struct file *file)
1636 minor = iminor(inode);
1637 if (minor >= hba_count) {
1640 mutex_lock(&adpt_configuration_lock);
1641 for (pHba = hba_chain; pHba; pHba = pHba->next) {
1642 if (pHba->unit == minor) {
1643 break; /* found adapter */
1646 mutex_unlock(&adpt_configuration_lock);
1656 #if defined __ia64__
1657 static void adpt_ia64_info(sysInfo_S* si)
1659 // This is all the info we need for now
1660 // We will add more info as our new
1661 // managmenent utility requires it
1662 si->processorType = PROC_IA64;
1666 #if defined __sparc__
1667 static void adpt_sparc_info(sysInfo_S* si)
1669 // This is all the info we need for now
1670 // We will add more info as our new
1671 // managmenent utility requires it
1672 si->processorType = PROC_ULTRASPARC;
1675 #if defined __alpha__
1676 static void adpt_alpha_info(sysInfo_S* si)
1678 // This is all the info we need for now
1679 // We will add more info as our new
1680 // managmenent utility requires it
1681 si->processorType = PROC_ALPHA;
1685 #if defined __i386__
1687 #include <uapi/asm/vm86.h>
1689 static void adpt_i386_info(sysInfo_S* si)
1691 // This is all the info we need for now
1692 // We will add more info as our new
1693 // managmenent utility requires it
1694 switch (boot_cpu_data.x86) {
1696 si->processorType = PROC_386;
1699 si->processorType = PROC_486;
1702 si->processorType = PROC_PENTIUM;
1704 default: // Just in case
1705 si->processorType = PROC_PENTIUM;
1712 * This routine returns information about the system. This does not effect
1713 * any logic and if the info is wrong - it doesn't matter.
1716 /* Get all the info we can not get from kernel services */
1717 static int adpt_system_info(void __user *buffer)
1721 memset(&si, 0, sizeof(si));
1723 si.osType = OS_LINUX;
1724 si.osMajorVersion = 0;
1725 si.osMinorVersion = 0;
1727 si.busType = SI_PCI_BUS;
1728 si.processorFamily = DPTI_sig.dsProcessorFamily;
1730 #if defined __i386__
1731 adpt_i386_info(&si);
1732 #elif defined (__ia64__)
1733 adpt_ia64_info(&si);
1734 #elif defined(__sparc__)
1735 adpt_sparc_info(&si);
1736 #elif defined (__alpha__)
1737 adpt_alpha_info(&si);
1739 si.processorType = 0xff ;
1741 if (copy_to_user(buffer, &si, sizeof(si))){
1742 printk(KERN_WARNING"dpti: Could not copy buffer TO user\n");
1749 static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1755 void __user *argp = (void __user *)arg;
1757 minor = iminor(inode);
1758 if (minor >= DPTI_MAX_HBA){
1761 mutex_lock(&adpt_configuration_lock);
1762 for (pHba = hba_chain; pHba; pHba = pHba->next) {
1763 if (pHba->unit == minor) {
1764 break; /* found adapter */
1767 mutex_unlock(&adpt_configuration_lock);
1772 while((volatile u32) pHba->state & DPTI_STATE_RESET )
1773 schedule_timeout_uninterruptible(2);
1776 // TODO: handle 3 cases
1778 if (copy_to_user(argp, &DPTI_sig, sizeof(DPTI_sig))) {
1784 drvrHBAinfo_S HbaInfo;
1786 #define FLG_OSD_PCI_VALID 0x0001
1787 #define FLG_OSD_DMA 0x0002
1788 #define FLG_OSD_I2O 0x0004
1789 memset(&HbaInfo, 0, sizeof(HbaInfo));
1790 HbaInfo.drvrHBAnum = pHba->unit;
1791 HbaInfo.baseAddr = (ulong) pHba->base_addr_phys;
1792 HbaInfo.blinkState = adpt_read_blink_led(pHba);
1793 HbaInfo.pciBusNum = pHba->pDev->bus->number;
1794 HbaInfo.pciDeviceNum=PCI_SLOT(pHba->pDev->devfn);
1795 HbaInfo.Interrupt = pHba->pDev->irq;
1796 HbaInfo.hbaFlags = FLG_OSD_PCI_VALID | FLG_OSD_DMA | FLG_OSD_I2O;
1797 if(copy_to_user(argp, &HbaInfo, sizeof(HbaInfo))){
1798 printk(KERN_WARNING"%s: Could not copy HbaInfo TO user\n",pHba->name);
1804 return adpt_system_info(argp);
1807 value = (u32)adpt_read_blink_led(pHba);
1808 if (copy_to_user(argp, &value, sizeof(value))) {
1815 spin_lock_irqsave(pHba->host->host_lock, flags);
1816 adpt_hba_reset(pHba);
1818 spin_unlock_irqrestore(pHba->host->host_lock, flags);
1830 static long adpt_unlocked_ioctl(struct file *file, uint cmd, ulong arg)
1832 struct inode *inode;
1835 inode = file_inode(file);
1837 mutex_lock(&adpt_mutex);
1838 ret = adpt_ioctl(inode, file, cmd, arg);
1839 mutex_unlock(&adpt_mutex);
1844 #ifdef CONFIG_COMPAT
1845 static long compat_adpt_ioctl(struct file *file,
1846 unsigned int cmd, unsigned long arg)
1848 struct inode *inode;
1851 inode = file_inode(file);
1853 mutex_lock(&adpt_mutex);
1863 case (DPT_TARGET_BUSY & 0xFFFF):
1864 case DPT_TARGET_BUSY:
1865 ret = adpt_ioctl(inode, file, cmd, arg);
1871 mutex_unlock(&adpt_mutex);
1877 static irqreturn_t adpt_isr(int irq, void *dev_id)
1879 struct scsi_cmnd* cmd;
1880 adpt_hba* pHba = dev_id;
1882 void __iomem *reply;
1889 printk(KERN_WARNING"adpt_isr: NULL dev_id\n");
1893 spin_lock_irqsave(pHba->host->host_lock, flags);
1895 while( readl(pHba->irq_mask) & I2O_INTERRUPT_PENDING_B) {
1896 m = readl(pHba->reply_port);
1897 if(m == EMPTY_QUEUE){
1898 // Try twice then give up
1900 m = readl(pHba->reply_port);
1901 if(m == EMPTY_QUEUE){
1902 // This really should not happen
1903 printk(KERN_ERR"dpti: Could not get reply frame\n");
1907 if (pHba->reply_pool_pa <= m &&
1908 m < pHba->reply_pool_pa +
1909 (pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4)) {
1910 reply = (u8 *)pHba->reply_pool +
1911 (m - pHba->reply_pool_pa);
1913 /* Ick, we should *never* be here */
1914 printk(KERN_ERR "dpti: reply frame not from pool\n");
1918 if (readl(reply) & MSG_FAIL) {
1919 u32 old_m = readl(reply+28);
1922 PDEBUG("%s: Failed message\n",pHba->name);
1923 if(old_m >= 0x100000){
1924 printk(KERN_ERR"%s: Bad preserved MFA (%x)- dropping frame\n",pHba->name,old_m);
1925 writel(m,pHba->reply_port);
1928 // Transaction context is 0 in failed reply frame
1929 msg = pHba->msg_addr_virt + old_m;
1930 old_context = readl(msg+12);
1931 writel(old_context, reply+12);
1932 adpt_send_nop(pHba, old_m);
1934 context = readl(reply+8);
1935 if(context & 0x80000000){ // Post wait message
1936 status = readl(reply+16);
1938 status &= 0xffff; /* Get detail status */
1940 status = I2O_POST_WAIT_OK;
1942 cmd = adpt_cmd_from_context(pHba, readl(reply+12));
1944 printk(KERN_WARNING"%s: Apparent SCSI cmd in Post Wait Context - cmd=%p context=%x\n", pHba->name, cmd, context);
1946 adpt_i2o_post_wait_complete(context, status);
1947 } else { // SCSI message
1948 cmd = adpt_cmd_from_context (pHba, readl(reply+12));
1950 scsi_dma_unmap(cmd);
1951 if(cmd->serial_number != 0) { // If not timedout
1952 adpt_i2o_to_scsi(reply, cmd);
1956 writel(m, pHba->reply_port);
1962 spin_unlock_irqrestore(pHba->host->host_lock, flags);
1963 return IRQ_RETVAL(handled);
1966 static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_device* d)
1969 u32 msg[MAX_MESSAGE_SIZE];
1981 memset(msg, 0 , sizeof(msg));
1982 len = scsi_bufflen(cmd);
1983 direction = 0x00000000;
1985 scsidir = 0x00000000; // DATA NO XFER
1988 * Set SCBFlags to indicate if data is being transferred
1989 * in or out, or no data transfer
1990 * Note: Do not have to verify index is less than 0 since
1991 * cmd->cmnd[0] is an unsigned char
1993 switch(cmd->sc_data_direction){
1994 case DMA_FROM_DEVICE:
1995 scsidir =0x40000000; // DATA IN (iop<--dev)
1998 direction=0x04000000; // SGL OUT
1999 scsidir =0x80000000; // DATA OUT (iop-->dev)
2003 case DMA_BIDIRECTIONAL:
2004 scsidir =0x40000000; // DATA IN (iop<--dev)
2005 // Assume In - and continue;
2008 printk(KERN_WARNING"%s: scsi opcode 0x%x not supported.\n",
2009 pHba->name, cmd->cmnd[0]);
2010 cmd->result = (DID_OK <<16) | (INITIATOR_ERROR << 8);
2011 cmd->scsi_done(cmd);
2015 // msg[0] is set later
2016 // I2O_CMD_SCSI_EXEC
2017 msg[1] = ((0xff<<24)|(HOST_TID<<12)|d->tid);
2019 msg[3] = adpt_cmd_to_context(cmd); /* Want SCSI control block back */
2020 // Our cards use the transaction context as the tag for queueing
2021 // Adaptec/DPT Private stuff
2022 msg[4] = I2O_CMD_SCSI_EXEC|(DPT_ORGANIZATION_ID<<16);
2024 /* Direction, disconnect ok | sense data | simple queue , CDBLen */
2025 // I2O_SCB_FLAG_ENABLE_DISCONNECT |
2026 // I2O_SCB_FLAG_SIMPLE_QUEUE_TAG |
2027 // I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
2028 msg[6] = scsidir|0x20a00000|cmd->cmd_len;
2032 // Write SCSI command into the message - always 16 byte block
2033 memset(mptr, 0, 16);
2034 memcpy(mptr, cmd->cmnd, cmd->cmd_len);
2036 lenptr=mptr++; /* Remember me - fill in when we know */
2037 if (dpt_dma64(pHba)) {
2038 reqlen = 16; // SINGLE SGE
2039 *mptr++ = (0x7C<<24)+(2<<16)+0x02; /* Enable 64 bit */
2040 *mptr++ = 1 << PAGE_SHIFT;
2042 reqlen = 14; // SINGLE SGE
2044 /* Now fill in the SGList and command */
2046 nseg = scsi_dma_map(cmd);
2049 struct scatterlist *sg;
2052 scsi_for_each_sg(cmd, sg, nseg, i) {
2054 *mptr++ = direction|0x10000000|sg_dma_len(sg);
2055 len+=sg_dma_len(sg);
2056 addr = sg_dma_address(sg);
2057 *mptr++ = dma_low(addr);
2058 if (dpt_dma64(pHba))
2059 *mptr++ = dma_high(addr);
2060 /* Make this an end of list */
2062 *lptr = direction|0xD0000000|sg_dma_len(sg);
2064 reqlen = mptr - msg;
2067 if(cmd->underflow && len != cmd->underflow){
2068 printk(KERN_WARNING"Cmd len %08X Cmd underflow %08X\n",
2069 len, cmd->underflow);
2076 /* Stick the headers on */
2077 msg[0] = reqlen<<16 | ((reqlen > 12) ? SGL_OFFSET_12 : SGL_OFFSET_0);
2079 // Send it on it's way
2080 rcode = adpt_i2o_post_this(pHba, msg, reqlen<<2);
2088 static s32 adpt_scsi_host_alloc(adpt_hba* pHba, struct scsi_host_template *sht)
2090 struct Scsi_Host *host;
2092 host = scsi_host_alloc(sht, sizeof(adpt_hba*));
2094 printk("%s: scsi_host_alloc returned NULL\n", pHba->name);
2097 host->hostdata[0] = (unsigned long)pHba;
2100 host->irq = pHba->pDev->irq;
2101 /* no IO ports, so don't have to set host->io_port and
2105 host->n_io_port = 0;
2106 /* see comments in scsi_host.h */
2108 host->max_lun = 256;
2109 host->max_channel = pHba->top_scsi_channel + 1;
2110 host->cmd_per_lun = 1;
2111 host->unique_id = (u32)sys_tbl_pa + pHba->unit;
2112 host->sg_tablesize = pHba->sg_tablesize;
2113 host->can_queue = pHba->post_fifo_size;
2114 host->use_cmd_list = 1;
2120 static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd)
2125 u32 reply_flags = readl(reply) & 0xff00; // Leave it shifted up 8 bits
2126 // I know this would look cleaner if I just read bytes
2127 // but the model I have been using for all the rest of the
2128 // io is in 4 byte words - so I keep that model
2129 u16 detailed_status = readl(reply+16) &0xffff;
2130 dev_status = (detailed_status & 0xff);
2131 hba_status = detailed_status >> 8;
2133 // calculate resid for sg
2134 scsi_set_resid(cmd, scsi_bufflen(cmd) - readl(reply+20));
2136 pHba = (adpt_hba*) cmd->device->host->hostdata[0];
2138 cmd->sense_buffer[0] = '\0'; // initialize sense valid flag to false
2140 if(!(reply_flags & MSG_FAIL)) {
2141 switch(detailed_status & I2O_SCSI_DSC_MASK) {
2142 case I2O_SCSI_DSC_SUCCESS:
2143 cmd->result = (DID_OK << 16);
2145 if (readl(reply+20) < cmd->underflow) {
2146 cmd->result = (DID_ERROR <<16);
2147 printk(KERN_WARNING"%s: SCSI CMD underflow\n",pHba->name);
2150 case I2O_SCSI_DSC_REQUEST_ABORTED:
2151 cmd->result = (DID_ABORT << 16);
2153 case I2O_SCSI_DSC_PATH_INVALID:
2154 case I2O_SCSI_DSC_DEVICE_NOT_PRESENT:
2155 case I2O_SCSI_DSC_SELECTION_TIMEOUT:
2156 case I2O_SCSI_DSC_COMMAND_TIMEOUT:
2157 case I2O_SCSI_DSC_NO_ADAPTER:
2158 case I2O_SCSI_DSC_RESOURCE_UNAVAILABLE:
2159 printk(KERN_WARNING"%s: SCSI Timeout-Device (%d,%d,%llu) hba status=0x%x, dev status=0x%x, cmd=0x%x\n",
2160 pHba->name, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun, hba_status, dev_status, cmd->cmnd[0]);
2161 cmd->result = (DID_TIME_OUT << 16);
2163 case I2O_SCSI_DSC_ADAPTER_BUSY:
2164 case I2O_SCSI_DSC_BUS_BUSY:
2165 cmd->result = (DID_BUS_BUSY << 16);
2167 case I2O_SCSI_DSC_SCSI_BUS_RESET:
2168 case I2O_SCSI_DSC_BDR_MESSAGE_SENT:
2169 cmd->result = (DID_RESET << 16);
2171 case I2O_SCSI_DSC_PARITY_ERROR_FAILURE:
2172 printk(KERN_WARNING"%s: SCSI CMD parity error\n",pHba->name);
2173 cmd->result = (DID_PARITY << 16);
2175 case I2O_SCSI_DSC_UNABLE_TO_ABORT:
2176 case I2O_SCSI_DSC_COMPLETE_WITH_ERROR:
2177 case I2O_SCSI_DSC_UNABLE_TO_TERMINATE:
2178 case I2O_SCSI_DSC_MR_MESSAGE_RECEIVED:
2179 case I2O_SCSI_DSC_AUTOSENSE_FAILED:
2180 case I2O_SCSI_DSC_DATA_OVERRUN:
2181 case I2O_SCSI_DSC_UNEXPECTED_BUS_FREE:
2182 case I2O_SCSI_DSC_SEQUENCE_FAILURE:
2183 case I2O_SCSI_DSC_REQUEST_LENGTH_ERROR:
2184 case I2O_SCSI_DSC_PROVIDE_FAILURE:
2185 case I2O_SCSI_DSC_REQUEST_TERMINATED:
2186 case I2O_SCSI_DSC_IDE_MESSAGE_SENT:
2187 case I2O_SCSI_DSC_UNACKNOWLEDGED_EVENT:
2188 case I2O_SCSI_DSC_MESSAGE_RECEIVED:
2189 case I2O_SCSI_DSC_INVALID_CDB:
2190 case I2O_SCSI_DSC_LUN_INVALID:
2191 case I2O_SCSI_DSC_SCSI_TID_INVALID:
2192 case I2O_SCSI_DSC_FUNCTION_UNAVAILABLE:
2193 case I2O_SCSI_DSC_NO_NEXUS:
2194 case I2O_SCSI_DSC_CDB_RECEIVED:
2195 case I2O_SCSI_DSC_LUN_ALREADY_ENABLED:
2196 case I2O_SCSI_DSC_QUEUE_FROZEN:
2197 case I2O_SCSI_DSC_REQUEST_INVALID:
2199 printk(KERN_WARNING"%s: SCSI error %0x-Device(%d,%d,%llu) hba_status=0x%x, dev_status=0x%x, cmd=0x%x\n",
2200 pHba->name, detailed_status & I2O_SCSI_DSC_MASK, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun,
2201 hba_status, dev_status, cmd->cmnd[0]);
2202 cmd->result = (DID_ERROR << 16);
2206 // copy over the request sense data if it was a check
2208 if (dev_status == SAM_STAT_CHECK_CONDITION) {
2209 u32 len = min(SCSI_SENSE_BUFFERSIZE, 40);
2210 // Copy over the sense data
2211 memcpy_fromio(cmd->sense_buffer, (reply+28) , len);
2212 if(cmd->sense_buffer[0] == 0x70 /* class 7 */ &&
2213 cmd->sense_buffer[2] == DATA_PROTECT ){
2214 /* This is to handle an array failed */
2215 cmd->result = (DID_TIME_OUT << 16);
2216 printk(KERN_WARNING"%s: SCSI Data Protect-Device (%d,%d,%llu) hba_status=0x%x, dev_status=0x%x, cmd=0x%x\n",
2217 pHba->name, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun,
2218 hba_status, dev_status, cmd->cmnd[0]);
2223 /* In this condtion we could not talk to the tid
2224 * the card rejected it. We should signal a retry
2225 * for a limitted number of retries.
2227 cmd->result = (DID_TIME_OUT << 16);
2228 printk(KERN_WARNING"%s: I2O MSG_FAIL - Device (%d,%d,%llu) tid=%d, cmd=0x%x\n",
2229 pHba->name, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun,
2230 ((struct adpt_device*)(cmd->device->hostdata))->tid, cmd->cmnd[0]);
2233 cmd->result |= (dev_status);
2235 if(cmd->scsi_done != NULL){
2236 cmd->scsi_done(cmd);
2242 static s32 adpt_rescan(adpt_hba* pHba)
2248 spin_lock_irqsave(pHba->host->host_lock, flags);
2249 if ((rcode=adpt_i2o_lct_get(pHba)) < 0)
2251 if ((rcode=adpt_i2o_reparse_lct(pHba)) < 0)
2255 spin_unlock_irqrestore(pHba->host->host_lock, flags);
2260 static s32 adpt_i2o_reparse_lct(adpt_hba* pHba)
2265 struct i2o_device *d;
2266 i2o_lct *lct = pHba->lct;
2270 u32 buf[10]; // at least 8 u32's
2271 struct adpt_device* pDev = NULL;
2272 struct i2o_device* pI2o_dev = NULL;
2275 printk(KERN_ERR "%s: LCT is empty???\n",pHba->name);
2279 max = lct->table_size;
2283 // Mark each drive as unscanned
2284 for (d = pHba->devices; d; d = d->next) {
2285 pDev =(struct adpt_device*) d->owner;
2289 pDev->state |= DPTI_DEV_UNSCANNED;
2292 printk(KERN_INFO "%s: LCT has %d entries.\n", pHba->name,max);
2294 for(i=0;i<max;i++) {
2295 if( lct->lct_entry[i].user_tid != 0xfff){
2299 if( lct->lct_entry[i].class_id == I2O_CLASS_RANDOM_BLOCK_STORAGE ||
2300 lct->lct_entry[i].class_id == I2O_CLASS_SCSI_PERIPHERAL ||
2301 lct->lct_entry[i].class_id == I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL ){
2302 tid = lct->lct_entry[i].tid;
2303 if(adpt_i2o_query_scalar(pHba, tid, 0x8000, -1, buf, 32)<0) {
2304 printk(KERN_ERR"%s: Could not query device\n",pHba->name);
2307 bus_no = buf[0]>>16;
2308 if (bus_no >= MAX_CHANNEL) { /* Something wrong skip it */
2310 "%s: Channel number %d out of range\n",
2311 pHba->name, bus_no);
2316 scsi_lun = scsilun_to_int((struct scsi_lun *)&buf[2]);
2317 pDev = pHba->channel[bus_no].device[scsi_id];
2320 if(pDev->scsi_lun == scsi_lun) {
2323 pDev = pDev->next_lun;
2325 if(!pDev ) { // Something new add it
2326 d = kmalloc(sizeof(struct i2o_device),
2330 printk(KERN_CRIT "Out of memory for I2O device data.\n");
2334 d->controller = pHba;
2337 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
2340 adpt_i2o_report_hba_unit(pHba, d);
2341 adpt_i2o_install_device(pHba, d);
2343 pDev = pHba->channel[bus_no].device[scsi_id];
2346 kzalloc(sizeof(struct adpt_device),
2351 pHba->channel[bus_no].device[scsi_id] = pDev;
2353 while (pDev->next_lun) {
2354 pDev = pDev->next_lun;
2356 pDev = pDev->next_lun =
2357 kzalloc(sizeof(struct adpt_device),
2363 pDev->tid = d->lct_data.tid;
2364 pDev->scsi_channel = bus_no;
2365 pDev->scsi_id = scsi_id;
2366 pDev->scsi_lun = scsi_lun;
2369 pDev->type = (buf[0])&0xff;
2370 pDev->flags = (buf[0]>>8)&0xff;
2371 // Too late, SCSI system has made up it's mind, but what the hey ...
2372 if(scsi_id > pHba->top_scsi_id){
2373 pHba->top_scsi_id = scsi_id;
2375 if(scsi_lun > pHba->top_scsi_lun){
2376 pHba->top_scsi_lun = scsi_lun;
2379 } // end of new i2o device
2381 // We found an old device - check it
2383 if(pDev->scsi_lun == scsi_lun) {
2384 if(!scsi_device_online(pDev->pScsi_dev)) {
2385 printk(KERN_WARNING"%s: Setting device (%d,%d,%llu) back online\n",
2386 pHba->name,bus_no,scsi_id,scsi_lun);
2387 if (pDev->pScsi_dev) {
2388 scsi_device_set_state(pDev->pScsi_dev, SDEV_RUNNING);
2392 if(d->lct_data.tid != tid) { // something changed
2394 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
2395 if (pDev->pScsi_dev) {
2396 pDev->pScsi_dev->changed = TRUE;
2397 pDev->pScsi_dev->removable = TRUE;
2400 // Found it - mark it scanned
2401 pDev->state = DPTI_DEV_ONLINE;
2404 pDev = pDev->next_lun;
2408 for (pI2o_dev = pHba->devices; pI2o_dev; pI2o_dev = pI2o_dev->next) {
2409 pDev =(struct adpt_device*) pI2o_dev->owner;
2413 // Drive offline drives that previously existed but could not be found
2415 if (pDev->state & DPTI_DEV_UNSCANNED){
2416 pDev->state = DPTI_DEV_OFFLINE;
2417 printk(KERN_WARNING"%s: Device (%d,%d,%llu) offline\n",pHba->name,pDev->scsi_channel,pDev->scsi_id,pDev->scsi_lun);
2418 if (pDev->pScsi_dev) {
2419 scsi_device_set_state(pDev->pScsi_dev, SDEV_OFFLINE);
2426 static void adpt_fail_posted_scbs(adpt_hba* pHba)
2428 struct scsi_cmnd* cmd = NULL;
2429 struct scsi_device* d = NULL;
2431 shost_for_each_device(d, pHba->host) {
2432 unsigned long flags;
2433 spin_lock_irqsave(&d->list_lock, flags);
2434 list_for_each_entry(cmd, &d->cmd_list, list) {
2435 if(cmd->serial_number == 0){
2438 cmd->result = (DID_OK << 16) | (QUEUE_FULL <<1);
2439 cmd->scsi_done(cmd);
2441 spin_unlock_irqrestore(&d->list_lock, flags);
2446 /*============================================================================
2447 * Routines from i2o subsystem
2448 *============================================================================
2454 * Bring an I2O controller into HOLD state. See the spec.
2456 static int adpt_i2o_activate_hba(adpt_hba* pHba)
2460 if(pHba->initialized ) {
2461 if (adpt_i2o_status_get(pHba) < 0) {
2462 if((rcode = adpt_i2o_reset_hba(pHba)) != 0){
2463 printk(KERN_WARNING"%s: Could NOT reset.\n", pHba->name);
2466 if (adpt_i2o_status_get(pHba) < 0) {
2467 printk(KERN_INFO "HBA not responding.\n");
2472 if(pHba->status_block->iop_state == ADAPTER_STATE_FAULTED) {
2473 printk(KERN_CRIT "%s: hardware fault\n", pHba->name);
2477 if (pHba->status_block->iop_state == ADAPTER_STATE_READY ||
2478 pHba->status_block->iop_state == ADAPTER_STATE_OPERATIONAL ||
2479 pHba->status_block->iop_state == ADAPTER_STATE_HOLD ||
2480 pHba->status_block->iop_state == ADAPTER_STATE_FAILED) {
2481 adpt_i2o_reset_hba(pHba);
2482 if (adpt_i2o_status_get(pHba) < 0 || pHba->status_block->iop_state != ADAPTER_STATE_RESET) {
2483 printk(KERN_ERR "%s: Failed to initialize.\n", pHba->name);
2488 if((rcode = adpt_i2o_reset_hba(pHba)) != 0){
2489 printk(KERN_WARNING"%s: Could NOT reset.\n", pHba->name);
2495 if (adpt_i2o_init_outbound_q(pHba) < 0) {
2501 if (adpt_i2o_hrt_get(pHba) < 0) {
2509 * Bring a controller online into OPERATIONAL state.
2512 static int adpt_i2o_online_hba(adpt_hba* pHba)
2514 if (adpt_i2o_systab_send(pHba) < 0)
2516 /* In READY state */
2518 if (adpt_i2o_enable_hba(pHba) < 0)
2521 /* In OPERATIONAL state */
2525 static s32 adpt_send_nop(adpt_hba*pHba,u32 m)
2528 ulong timeout = jiffies + 5*HZ;
2530 while(m == EMPTY_QUEUE){
2532 m = readl(pHba->post_port);
2533 if(m != EMPTY_QUEUE){
2536 if(time_after(jiffies,timeout)){
2537 printk(KERN_ERR "%s: Timeout waiting for message frame!\n",pHba->name);
2540 schedule_timeout_uninterruptible(1);
2542 msg = (u32 __iomem *)(pHba->msg_addr_virt + m);
2543 writel( THREE_WORD_MSG_SIZE | SGL_OFFSET_0,&msg[0]);
2544 writel( I2O_CMD_UTIL_NOP << 24 | HOST_TID << 12 | 0,&msg[1]);
2548 writel(m, pHba->post_port);
2553 static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
2557 u32 __iomem *msg = NULL;
2559 ulong timeout = jiffies + TMOUT_INITOUTBOUND*HZ;
2564 m = readl(pHba->post_port);
2565 if (m != EMPTY_QUEUE) {
2569 if(time_after(jiffies,timeout)){
2570 printk(KERN_WARNING"%s: Timeout waiting for message frame\n",pHba->name);
2573 schedule_timeout_uninterruptible(1);
2574 } while(m == EMPTY_QUEUE);
2576 msg=(u32 __iomem *)(pHba->msg_addr_virt+m);
2578 status = dma_alloc_coherent(&pHba->pDev->dev, 4, &addr, GFP_KERNEL);
2580 adpt_send_nop(pHba, m);
2581 printk(KERN_WARNING"%s: IOP reset failed - no free memory.\n",
2585 memset(status, 0, 4);
2587 writel(EIGHT_WORD_MSG_SIZE| SGL_OFFSET_6, &msg[0]);
2588 writel(I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID, &msg[1]);
2590 writel(0x0106, &msg[3]); /* Transaction context */
2591 writel(4096, &msg[4]); /* Host page frame size */
2592 writel((REPLY_FRAME_SIZE)<<16|0x80, &msg[5]); /* Outbound msg frame size and Initcode */
2593 writel(0xD0000004, &msg[6]); /* Simple SG LE, EOB */
2594 writel((u32)addr, &msg[7]);
2596 writel(m, pHba->post_port);
2599 // Wait for the reply status to come back
2602 if (*status != 0x01 /*I2O_EXEC_OUTBOUND_INIT_IN_PROGRESS*/) {
2607 if(time_after(jiffies,timeout)){
2608 printk(KERN_WARNING"%s: Timeout Initializing\n",pHba->name);
2609 /* We lose 4 bytes of "status" here, but we
2610 cannot free these because controller may
2611 awake and corrupt those bytes at any time */
2612 /* dma_free_coherent(&pHba->pDev->dev, 4, status, addr); */
2615 schedule_timeout_uninterruptible(1);
2618 // If the command was successful, fill the fifo with our reply
2620 if(*status != 0x04 /*I2O_EXEC_OUTBOUND_INIT_COMPLETE*/) {
2621 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
2624 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
2626 if(pHba->reply_pool != NULL) {
2627 dma_free_coherent(&pHba->pDev->dev,
2628 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
2629 pHba->reply_pool, pHba->reply_pool_pa);
2632 pHba->reply_pool = dma_alloc_coherent(&pHba->pDev->dev,
2633 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
2634 &pHba->reply_pool_pa, GFP_KERNEL);
2635 if (!pHba->reply_pool) {
2636 printk(KERN_ERR "%s: Could not allocate reply pool\n", pHba->name);
2639 memset(pHba->reply_pool, 0 , pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4);
2641 for(i = 0; i < pHba->reply_fifo_size; i++) {
2642 writel(pHba->reply_pool_pa + (i * REPLY_FRAME_SIZE * 4),
2646 adpt_i2o_status_get(pHba);
2652 * I2O System Table. Contains information about
2653 * all the IOPs in the system. Used to inform IOPs
2654 * about each other's existence.
2656 * sys_tbl_ver is the CurrentChangeIndicator that is
2657 * used by IOPs to track changes.
2662 static s32 adpt_i2o_status_get(adpt_hba* pHba)
2667 u8 *status_block=NULL;
2669 if(pHba->status_block == NULL) {
2670 pHba->status_block = dma_alloc_coherent(&pHba->pDev->dev,
2671 sizeof(i2o_status_block),
2672 &pHba->status_block_pa, GFP_KERNEL);
2673 if(pHba->status_block == NULL) {
2675 "dpti%d: Get Status Block failed; Out of memory. \n",
2680 memset(pHba->status_block, 0, sizeof(i2o_status_block));
2681 status_block = (u8*)(pHba->status_block);
2682 timeout = jiffies+TMOUT_GETSTATUS*HZ;
2685 m = readl(pHba->post_port);
2686 if (m != EMPTY_QUEUE) {
2689 if(time_after(jiffies,timeout)){
2690 printk(KERN_ERR "%s: Timeout waiting for message !\n",
2694 schedule_timeout_uninterruptible(1);
2695 } while(m==EMPTY_QUEUE);
2698 msg=(u32 __iomem *)(pHba->msg_addr_virt+m);
2700 writel(NINE_WORD_MSG_SIZE|SGL_OFFSET_0, &msg[0]);
2701 writel(I2O_CMD_STATUS_GET<<24|HOST_TID<<12|ADAPTER_TID, &msg[1]);
2706 writel( dma_low(pHba->status_block_pa), &msg[6]);
2707 writel( dma_high(pHba->status_block_pa), &msg[7]);
2708 writel(sizeof(i2o_status_block), &msg[8]); // 88 bytes
2711 writel(m, pHba->post_port);
2714 while(status_block[87]!=0xff){
2715 if(time_after(jiffies,timeout)){
2716 printk(KERN_ERR"dpti%d: Get status timeout.\n",
2721 schedule_timeout_uninterruptible(1);
2724 // Set up our number of outbound and inbound messages
2725 pHba->post_fifo_size = pHba->status_block->max_inbound_frames;
2726 if (pHba->post_fifo_size > MAX_TO_IOP_MESSAGES) {
2727 pHba->post_fifo_size = MAX_TO_IOP_MESSAGES;
2730 pHba->reply_fifo_size = pHba->status_block->max_outbound_frames;
2731 if (pHba->reply_fifo_size > MAX_FROM_IOP_MESSAGES) {
2732 pHba->reply_fifo_size = MAX_FROM_IOP_MESSAGES;
2735 // Calculate the Scatter Gather list size
2736 if (dpt_dma64(pHba)) {
2738 = ((pHba->status_block->inbound_frame_size * 4
2740 / (sizeof(struct sg_simple_element) + sizeof(u32)));
2743 = ((pHba->status_block->inbound_frame_size * 4
2745 / sizeof(struct sg_simple_element));
2747 if (pHba->sg_tablesize > SG_LIST_ELEMENTS) {
2748 pHba->sg_tablesize = SG_LIST_ELEMENTS;
2753 printk("dpti%d: State = ",pHba->unit);
2754 switch(pHba->status_block->iop_state) {
2768 printk("OPERATIONAL\n");
2774 printk("FAULTED\n");
2777 printk("%x (unknown!!)\n",pHba->status_block->iop_state);
2784 * Get the IOP's Logical Configuration Table
2786 static int adpt_i2o_lct_get(adpt_hba* pHba)
2792 if ((pHba->lct_size == 0) || (pHba->lct == NULL)){
2793 pHba->lct_size = pHba->status_block->expected_lct_size;
2796 if (pHba->lct == NULL) {
2797 pHba->lct = dma_alloc_coherent(&pHba->pDev->dev,
2798 pHba->lct_size, &pHba->lct_pa,
2800 if(pHba->lct == NULL) {
2801 printk(KERN_CRIT "%s: Lct Get failed. Out of memory.\n",
2806 memset(pHba->lct, 0, pHba->lct_size);
2808 msg[0] = EIGHT_WORD_MSG_SIZE|SGL_OFFSET_6;
2809 msg[1] = I2O_CMD_LCT_NOTIFY<<24 | HOST_TID<<12 | ADAPTER_TID;
2812 msg[4] = 0xFFFFFFFF; /* All devices */
2813 msg[5] = 0x00000000; /* Report now */
2814 msg[6] = 0xD0000000|pHba->lct_size;
2815 msg[7] = (u32)pHba->lct_pa;
2817 if ((ret=adpt_i2o_post_wait(pHba, msg, sizeof(msg), 360))) {
2818 printk(KERN_ERR "%s: LCT Get failed (status=%#10x.\n",
2820 printk(KERN_ERR"Adaptec: Error Reading Hardware.\n");
2824 if ((pHba->lct->table_size << 2) > pHba->lct_size) {
2825 pHba->lct_size = pHba->lct->table_size << 2;
2826 dma_free_coherent(&pHba->pDev->dev, pHba->lct_size,
2827 pHba->lct, pHba->lct_pa);
2830 } while (pHba->lct == NULL);
2832 PDEBUG("%s: Hardware resource table read.\n", pHba->name);
2835 // I2O_DPT_EXEC_IOP_BUFFERS_GROUP_NO;
2836 if(adpt_i2o_query_scalar(pHba, 0 , 0x8000, -1, buf, sizeof(buf))>=0) {
2837 pHba->FwDebugBufferSize = buf[1];
2838 pHba->FwDebugBuffer_P = ioremap(pHba->base_addr_phys + buf[0],
2839 pHba->FwDebugBufferSize);
2840 if (pHba->FwDebugBuffer_P) {
2841 pHba->FwDebugFlags_P = pHba->FwDebugBuffer_P +
2842 FW_DEBUG_FLAGS_OFFSET;
2843 pHba->FwDebugBLEDvalue_P = pHba->FwDebugBuffer_P +
2844 FW_DEBUG_BLED_OFFSET;
2845 pHba->FwDebugBLEDflag_P = pHba->FwDebugBLEDvalue_P + 1;
2846 pHba->FwDebugStrLength_P = pHba->FwDebugBuffer_P +
2847 FW_DEBUG_STR_LENGTH_OFFSET;
2848 pHba->FwDebugBuffer_P += buf[2];
2849 pHba->FwDebugFlags = 0;
2856 static int adpt_i2o_build_sys_table(void)
2858 adpt_hba* pHba = hba_chain;
2862 dma_free_coherent(&pHba->pDev->dev, sys_tbl_len,
2863 sys_tbl, sys_tbl_pa);
2865 sys_tbl_len = sizeof(struct i2o_sys_tbl) + // Header + IOPs
2866 (hba_count) * sizeof(struct i2o_sys_tbl_entry);
2868 sys_tbl = dma_alloc_coherent(&pHba->pDev->dev,
2869 sys_tbl_len, &sys_tbl_pa, GFP_KERNEL);
2871 printk(KERN_WARNING "SysTab Set failed. Out of memory.\n");
2874 memset(sys_tbl, 0, sys_tbl_len);
2876 sys_tbl->num_entries = hba_count;
2877 sys_tbl->version = I2OVERSION;
2878 sys_tbl->change_ind = sys_tbl_ind++;
2880 for(pHba = hba_chain; pHba; pHba = pHba->next) {
2882 // Get updated Status Block so we have the latest information
2883 if (adpt_i2o_status_get(pHba)) {
2884 sys_tbl->num_entries--;
2885 continue; // try next one
2888 sys_tbl->iops[count].org_id = pHba->status_block->org_id;
2889 sys_tbl->iops[count].iop_id = pHba->unit + 2;
2890 sys_tbl->iops[count].seg_num = 0;
2891 sys_tbl->iops[count].i2o_version = pHba->status_block->i2o_version;
2892 sys_tbl->iops[count].iop_state = pHba->status_block->iop_state;
2893 sys_tbl->iops[count].msg_type = pHba->status_block->msg_type;
2894 sys_tbl->iops[count].frame_size = pHba->status_block->inbound_frame_size;
2895 sys_tbl->iops[count].last_changed = sys_tbl_ind - 1; // ??
2896 sys_tbl->iops[count].iop_capabilities = pHba->status_block->iop_capabilities;
2897 addr = pHba->base_addr_phys + 0x40;
2898 sys_tbl->iops[count].inbound_low = dma_low(addr);
2899 sys_tbl->iops[count].inbound_high = dma_high(addr);
2906 u32 *table = (u32*)sys_tbl;
2907 printk(KERN_DEBUG"sys_tbl_len=%d in 32bit words\n",(sys_tbl_len >>2));
2908 for(count = 0; count < (sys_tbl_len >>2); count++) {
2909 printk(KERN_INFO "sys_tbl[%d] = %0#10x\n",
2910 count, table[count]);
2920 * Dump the information block associated with a given unit (TID)
2923 static void adpt_i2o_report_hba_unit(adpt_hba* pHba, struct i2o_device *d)
2926 int unit = d->lct_data.tid;
2928 printk(KERN_INFO "TID %3.3d ", unit);
2930 if(adpt_i2o_query_scalar(pHba, unit, 0xF100, 3, buf, 16)>=0)
2933 printk(" Vendor: %-12.12s", buf);
2935 if(adpt_i2o_query_scalar(pHba, unit, 0xF100, 4, buf, 16)>=0)
2938 printk(" Device: %-12.12s", buf);
2940 if(adpt_i2o_query_scalar(pHba, unit, 0xF100, 6, buf, 8)>=0)
2943 printk(" Rev: %-12.12s\n", buf);
2946 printk(KERN_INFO "\tClass: %.21s\n", adpt_i2o_get_class_name(d->lct_data.class_id));
2947 printk(KERN_INFO "\tSubclass: 0x%04X\n", d->lct_data.sub_class);
2948 printk(KERN_INFO "\tFlags: ");
2950 if(d->lct_data.device_flags&(1<<0))
2951 printk("C"); // ConfigDialog requested
2952 if(d->lct_data.device_flags&(1<<1))
2953 printk("U"); // Multi-user capable
2954 if(!(d->lct_data.device_flags&(1<<4)))
2955 printk("P"); // Peer service enabled!
2956 if(!(d->lct_data.device_flags&(1<<5)))
2957 printk("M"); // Mgmt service enabled!
2964 * Do i2o class name lookup
2966 static const char *adpt_i2o_get_class_name(int class)
2969 static char *i2o_class_name[] = {
2971 "Device Driver Module",
2976 "Fibre Channel Port",
2977 "Fibre Channel Device",
2981 "Floppy Controller",
2983 "Secondary Bus Port",
2984 "Peer Transport Agent",
2989 switch(class&0xFFF) {
2990 case I2O_CLASS_EXECUTIVE:
2994 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
2996 case I2O_CLASS_SEQUENTIAL_STORAGE:
3002 case I2O_CLASS_FIBRE_CHANNEL_PORT:
3004 case I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL:
3006 case I2O_CLASS_SCSI_PERIPHERAL:
3008 case I2O_CLASS_ATE_PORT:
3010 case I2O_CLASS_ATE_PERIPHERAL:
3012 case I2O_CLASS_FLOPPY_CONTROLLER:
3014 case I2O_CLASS_FLOPPY_DEVICE:
3016 case I2O_CLASS_BUS_ADAPTER_PORT:
3018 case I2O_CLASS_PEER_TRANSPORT_AGENT:
3020 case I2O_CLASS_PEER_TRANSPORT:
3023 return i2o_class_name[idx];
3028 static s32 adpt_i2o_hrt_get(adpt_hba* pHba)
3031 int ret, size = sizeof(i2o_hrt);
3034 if (pHba->hrt == NULL) {
3035 pHba->hrt = dma_alloc_coherent(&pHba->pDev->dev,
3036 size, &pHba->hrt_pa, GFP_KERNEL);
3037 if (pHba->hrt == NULL) {
3038 printk(KERN_CRIT "%s: Hrt Get failed; Out of memory.\n", pHba->name);
3043 msg[0]= SIX_WORD_MSG_SIZE| SGL_OFFSET_4;
3044 msg[1]= I2O_CMD_HRT_GET<<24 | HOST_TID<<12 | ADAPTER_TID;
3047 msg[4]= (0xD0000000 | size); /* Simple transaction */
3048 msg[5]= (u32)pHba->hrt_pa; /* Dump it here */
3050 if ((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg),20))) {
3051 printk(KERN_ERR "%s: Unable to get HRT (status=%#10x)\n", pHba->name, ret);
3055 if (pHba->hrt->num_entries * pHba->hrt->entry_len << 2 > size) {
3056 int newsize = pHba->hrt->num_entries * pHba->hrt->entry_len << 2;
3057 dma_free_coherent(&pHba->pDev->dev, size,
3058 pHba->hrt, pHba->hrt_pa);
3062 } while(pHba->hrt == NULL);
3067 * Query one scalar group value or a whole scalar group.
3069 static int adpt_i2o_query_scalar(adpt_hba* pHba, int tid,
3070 int group, int field, void *buf, int buflen)
3072 u16 opblk[] = { 1, 0, I2O_PARAMS_FIELD_GET, group, 1, field };
3074 dma_addr_t opblk_pa;
3076 dma_addr_t resblk_pa;
3080 /* 8 bytes for header */
3081 resblk_va = dma_alloc_coherent(&pHba->pDev->dev,
3082 sizeof(u8) * (8 + buflen), &resblk_pa, GFP_KERNEL);
3083 if (resblk_va == NULL) {
3084 printk(KERN_CRIT "%s: query scalar failed; Out of memory.\n", pHba->name);
3088 opblk_va = dma_alloc_coherent(&pHba->pDev->dev,
3089 sizeof(opblk), &opblk_pa, GFP_KERNEL);
3090 if (opblk_va == NULL) {
3091 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3092 resblk_va, resblk_pa);
3093 printk(KERN_CRIT "%s: query operation failed; Out of memory.\n",
3097 if (field == -1) /* whole group */
3100 memcpy(opblk_va, opblk, sizeof(opblk));
3101 size = adpt_i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET, pHba, tid,
3102 opblk_va, opblk_pa, sizeof(opblk),
3103 resblk_va, resblk_pa, sizeof(u8)*(8+buflen));
3104 dma_free_coherent(&pHba->pDev->dev, sizeof(opblk), opblk_va, opblk_pa);
3105 if (size == -ETIME) {
3106 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3107 resblk_va, resblk_pa);
3108 printk(KERN_WARNING "%s: issue params failed; Timed out.\n", pHba->name);
3110 } else if (size == -EINTR) {
3111 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3112 resblk_va, resblk_pa);
3113 printk(KERN_WARNING "%s: issue params failed; Interrupted.\n", pHba->name);
3117 memcpy(buf, resblk_va+8, buflen); /* cut off header */
3119 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3120 resblk_va, resblk_pa);
3128 /* Issue UTIL_PARAMS_GET or UTIL_PARAMS_SET
3130 * This function can be used for all UtilParamsGet/Set operations.
3131 * The OperationBlock is given in opblk-buffer,
3132 * and results are returned in resblk-buffer.
3133 * Note that the minimum sized resblk is 8 bytes and contains
3134 * ResultCount, ErrorInfoSize, BlockStatus and BlockSize.
3136 static int adpt_i2o_issue_params(int cmd, adpt_hba* pHba, int tid,
3137 void *opblk_va, dma_addr_t opblk_pa, int oplen,
3138 void *resblk_va, dma_addr_t resblk_pa, int reslen)
3141 u32 *res = (u32 *)resblk_va;
3144 msg[0] = NINE_WORD_MSG_SIZE | SGL_OFFSET_5;
3145 msg[1] = cmd << 24 | HOST_TID << 12 | tid;
3149 msg[5] = 0x54000000 | oplen; /* OperationBlock */
3150 msg[6] = (u32)opblk_pa;
3151 msg[7] = 0xD0000000 | reslen; /* ResultBlock */
3152 msg[8] = (u32)resblk_pa;
3154 if ((wait_status = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 20))) {
3155 printk("adpt_i2o_issue_params: post_wait failed (%p)\n", resblk_va);
3156 return wait_status; /* -DetailedStatus */
3159 if (res[1]&0x00FF0000) { /* BlockStatus != SUCCESS */
3160 printk(KERN_WARNING "%s: %s - Error:\n ErrorInfoSize = 0x%02x, "
3161 "BlockStatus = 0x%02x, BlockSize = 0x%04x\n",
3163 (cmd == I2O_CMD_UTIL_PARAMS_SET) ? "PARAMS_SET"
3165 res[1]>>24, (res[1]>>16)&0xFF, res[1]&0xFFFF);
3166 return -((res[1] >> 16) & 0xFF); /* -BlockStatus */
3169 return 4 + ((res[1] & 0x0000FFFF) << 2); /* bytes used in resblk */
3173 static s32 adpt_i2o_quiesce_hba(adpt_hba* pHba)
3178 adpt_i2o_status_get(pHba);
3180 /* SysQuiesce discarded if IOP not in READY or OPERATIONAL state */
3182 if((pHba->status_block->iop_state != ADAPTER_STATE_READY) &&
3183 (pHba->status_block->iop_state != ADAPTER_STATE_OPERATIONAL)){
3187 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
3188 msg[1] = I2O_CMD_SYS_QUIESCE<<24|HOST_TID<<12|ADAPTER_TID;
3192 if((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 240))) {
3193 printk(KERN_INFO"dpti%d: Unable to quiesce (status=%#x).\n",
3196 printk(KERN_INFO"dpti%d: Quiesced.\n",pHba->unit);
3199 adpt_i2o_status_get(pHba);
3205 * Enable IOP. Allows the IOP to resume external operations.
3207 static int adpt_i2o_enable_hba(adpt_hba* pHba)
3212 adpt_i2o_status_get(pHba);
3213 if(!pHba->status_block){
3216 /* Enable only allowed on READY state */
3217 if(pHba->status_block->iop_state == ADAPTER_STATE_OPERATIONAL)
3220 if(pHba->status_block->iop_state != ADAPTER_STATE_READY)
3223 msg[0]=FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
3224 msg[1]=I2O_CMD_SYS_ENABLE<<24|HOST_TID<<12|ADAPTER_TID;
3228 if ((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 240))) {
3229 printk(KERN_WARNING"%s: Could not enable (status=%#10x).\n",
3232 PDEBUG("%s: Enabled.\n", pHba->name);
3235 adpt_i2o_status_get(pHba);
3240 static int adpt_i2o_systab_send(adpt_hba* pHba)
3245 msg[0] = I2O_MESSAGE_SIZE(12) | SGL_OFFSET_6;
3246 msg[1] = I2O_CMD_SYS_TAB_SET<<24 | HOST_TID<<12 | ADAPTER_TID;
3249 msg[4] = (0<<16) | ((pHba->unit+2) << 12); /* Host 0 IOP ID (unit + 2) */
3250 msg[5] = 0; /* Segment 0 */
3253 * Provide three SGL-elements:
3254 * System table (SysTab), Private memory space declaration and
3255 * Private i/o space declaration
3257 msg[6] = 0x54000000 | sys_tbl_len;
3258 msg[7] = (u32)sys_tbl_pa;
3259 msg[8] = 0x54000000 | 0;
3261 msg[10] = 0xD4000000 | 0;
3264 if ((ret=adpt_i2o_post_wait(pHba, msg, sizeof(msg), 120))) {
3265 printk(KERN_INFO "%s: Unable to set SysTab (status=%#10x).\n",
3270 PINFO("%s: SysTab set.\n", pHba->name);
3278 /*============================================================================
3280 *============================================================================
3286 static static void adpt_delay(int millisec)
3289 for (i = 0; i < millisec; i++) {
3290 udelay(1000); /* delay for one millisecond */
3296 static struct scsi_host_template driver_template = {
3297 .module = THIS_MODULE,
3299 .proc_name = "dpt_i2o",
3300 .show_info = adpt_show_info,
3302 .queuecommand = adpt_queue,
3303 .eh_abort_handler = adpt_abort,
3304 .eh_device_reset_handler = adpt_device_reset,
3305 .eh_bus_reset_handler = adpt_bus_reset,
3306 .eh_host_reset_handler = adpt_reset,
3307 .bios_param = adpt_bios_param,
3308 .slave_configure = adpt_slave_configure,
3309 .can_queue = MAX_TO_IOP_MESSAGES,
3311 .use_clustering = ENABLE_CLUSTERING,
3314 static int __init adpt_init(void)
3317 adpt_hba *pHba, *next;
3319 printk("Loading Adaptec I2O RAID: Version " DPT_I2O_VERSION "\n");
3321 error = adpt_detect(&driver_template);
3324 if (hba_chain == NULL)
3327 for (pHba = hba_chain; pHba; pHba = pHba->next) {
3328 error = scsi_add_host(pHba->host, &pHba->pDev->dev);
3331 scsi_scan_host(pHba->host);
3335 for (pHba = hba_chain; pHba; pHba = next) {
3337 scsi_remove_host(pHba->host);
3342 static void __exit adpt_exit(void)
3344 adpt_hba *pHba, *next;
3346 for (pHba = hba_chain; pHba; pHba = pHba->next)
3347 scsi_remove_host(pHba->host);
3348 for (pHba = hba_chain; pHba; pHba = next) {
3350 adpt_release(pHba->host);
3354 module_init(adpt_init);
3355 module_exit(adpt_exit);
3357 MODULE_LICENSE("GPL");