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();
305 static void adpt_release(adpt_hba *pHba)
307 struct Scsi_Host *shost = pHba->host;
309 scsi_remove_host(shost);
310 // adpt_i2o_quiesce_hba(pHba);
311 adpt_i2o_delete_hba(pHba);
312 scsi_host_put(shost);
316 static void adpt_inquiry(adpt_hba* pHba)
330 memset(msg, 0, sizeof(msg));
331 buf = dma_alloc_coherent(&pHba->pDev->dev, 80, &addr, GFP_KERNEL);
333 printk(KERN_ERR"%s: Could not allocate buffer\n",pHba->name);
336 memset((void*)buf, 0, 36);
339 direction = 0x00000000;
340 scsidir =0x40000000; // DATA IN (iop<--dev)
343 reqlen = 17; // SINGLE SGE, 64 bit
345 reqlen = 14; // SINGLE SGE, 32 bit
346 /* Stick the headers on */
347 msg[0] = reqlen<<16 | SGL_OFFSET_12;
348 msg[1] = (0xff<<24|HOST_TID<<12|ADAPTER_TID);
351 // Adaptec/DPT Private stuff
352 msg[4] = I2O_CMD_SCSI_EXEC|DPT_ORGANIZATION_ID<<16;
353 msg[5] = ADAPTER_TID | 1<<16 /* Interpret*/;
354 /* Direction, disconnect ok | sense data | simple queue , CDBLen */
355 // I2O_SCB_FLAG_ENABLE_DISCONNECT |
356 // I2O_SCB_FLAG_SIMPLE_QUEUE_TAG |
357 // I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
358 msg[6] = scsidir|0x20a00000| 6 /* cmd len*/;
362 memset(scb, 0, sizeof(scb));
363 // Write SCSI command into the message - always 16 byte block
370 // Don't care about the rest of scb
372 memcpy(mptr, scb, sizeof(scb));
374 lenptr=mptr++; /* Remember me - fill in when we know */
376 /* Now fill in the SGList and command */
378 if (dpt_dma64(pHba)) {
379 *mptr++ = (0x7C<<24)+(2<<16)+0x02; /* Enable 64 bit */
380 *mptr++ = 1 << PAGE_SHIFT;
381 *mptr++ = 0xD0000000|direction|len;
382 *mptr++ = dma_low(addr);
383 *mptr++ = dma_high(addr);
385 *mptr++ = 0xD0000000|direction|len;
389 // Send it on it's way
390 rcode = adpt_i2o_post_wait(pHba, msg, reqlen<<2, 120);
392 sprintf(pHba->detail, "Adaptec I2O RAID");
393 printk(KERN_INFO "%s: Inquiry Error (%d)\n",pHba->name,rcode);
394 if (rcode != -ETIME && rcode != -EINTR)
395 dma_free_coherent(&pHba->pDev->dev, 80, buf, addr);
397 memset(pHba->detail, 0, sizeof(pHba->detail));
398 memcpy(&(pHba->detail), "Vendor: Adaptec ", 16);
399 memcpy(&(pHba->detail[16]), " Model: ", 8);
400 memcpy(&(pHba->detail[24]), (u8*) &buf[16], 16);
401 memcpy(&(pHba->detail[40]), " FW: ", 4);
402 memcpy(&(pHba->detail[44]), (u8*) &buf[32], 4);
403 pHba->detail[48] = '\0'; /* precautionary */
404 dma_free_coherent(&pHba->pDev->dev, 80, buf, addr);
406 adpt_i2o_status_get(pHba);
411 static int adpt_slave_configure(struct scsi_device * device)
413 struct Scsi_Host *host = device->host;
416 pHba = (adpt_hba *) host->hostdata[0];
418 if (host->can_queue && device->tagged_supported) {
419 scsi_change_queue_depth(device,
420 host->can_queue - 1);
425 static int adpt_queue_lck(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *))
427 adpt_hba* pHba = NULL;
428 struct adpt_device* pDev = NULL; /* dpt per device information */
430 cmd->scsi_done = done;
432 * SCSI REQUEST_SENSE commands will be executed automatically by the
433 * Host Adapter for any errors, so they should not be executed
434 * explicitly unless the Sense Data is zero indicating that no error
438 if ((cmd->cmnd[0] == REQUEST_SENSE) && (cmd->sense_buffer[0] != 0)) {
439 cmd->result = (DID_OK << 16);
444 pHba = (adpt_hba*)cmd->device->host->hostdata[0];
450 if ((pHba->state) & DPTI_STATE_RESET)
451 return SCSI_MLQUEUE_HOST_BUSY;
453 // TODO if the cmd->device if offline then I may need to issue a bus rescan
454 // followed by a get_lct to see if the device is there anymore
455 if((pDev = (struct adpt_device*) (cmd->device->hostdata)) == NULL) {
457 * First command request for this device. Set up a pointer
458 * to the device structure. This should be a TEST_UNIT_READY
459 * command from scan_scsis_single.
461 if ((pDev = adpt_find_device(pHba, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun)) == NULL) {
462 // TODO: if any luns are at this bus, scsi id then fake a TEST_UNIT_READY and INQUIRY response
463 // with type 7F (for all luns less than the max for this bus,id) so the lun scan will continue.
464 cmd->result = (DID_NO_CONNECT << 16);
468 cmd->device->hostdata = pDev;
470 pDev->pScsi_dev = cmd->device;
473 * If we are being called from when the device is being reset,
474 * delay processing of the command until later.
476 if (pDev->state & DPTI_DEV_RESET ) {
479 return adpt_scsi_to_i2o(pHba, cmd, pDev);
482 static DEF_SCSI_QCMD(adpt_queue)
484 static int adpt_bios_param(struct scsi_device *sdev, struct block_device *dev,
485 sector_t capacity, int geom[])
491 // *** First lets set the default geometry ****
493 // If the capacity is less than ox2000
494 if (capacity < 0x2000 ) { // floppy
498 // else if between 0x2000 and 0x20000
499 else if (capacity < 0x20000) {
503 // else if between 0x20000 and 0x40000
504 else if (capacity < 0x40000) {
508 // else if between 0x4000 and 0x80000
509 else if (capacity < 0x80000) {
513 // else if greater than 0x80000
518 cylinders = sector_div(capacity, heads * sectors);
520 // Special case if CDROM
521 if(sdev->type == 5) { // CDROM
531 PDEBUG("adpt_bios_param: exit\n");
536 static const char *adpt_info(struct Scsi_Host *host)
540 pHba = (adpt_hba *) host->hostdata[0];
541 return (char *) (pHba->detail);
544 static int adpt_show_info(struct seq_file *m, struct Scsi_Host *host)
546 struct adpt_device* d;
552 // Find HBA (host bus adapter) we are looking for
553 mutex_lock(&adpt_configuration_lock);
554 for (pHba = hba_chain; pHba; pHba = pHba->next) {
555 if (pHba->host == host) {
556 break; /* found adapter */
559 mutex_unlock(&adpt_configuration_lock);
565 seq_printf(m, "Adaptec I2O RAID Driver Version: %s\n\n", DPT_I2O_VERSION);
566 seq_printf(m, "%s\n", pHba->detail);
567 seq_printf(m, "SCSI Host=scsi%d Control Node=/dev/%s irq=%d\n",
568 pHba->host->host_no, pHba->name, host->irq);
569 seq_printf(m, "\tpost fifo size = %d\n\treply fifo size = %d\n\tsg table size = %d\n\n",
570 host->can_queue, (int) pHba->reply_fifo_size , host->sg_tablesize);
572 seq_puts(m, "Devices:\n");
573 for(chan = 0; chan < MAX_CHANNEL; chan++) {
574 for(id = 0; id < MAX_ID; id++) {
575 d = pHba->channel[chan].device[id];
577 seq_printf(m,"\t%-24.24s", d->pScsi_dev->vendor);
578 seq_printf(m," Rev: %-8.8s\n", d->pScsi_dev->rev);
580 unit = d->pI2o_dev->lct_data.tid;
581 seq_printf(m, "\tTID=%d, (Channel=%d, Target=%d, Lun=%llu) (%s)\n\n",
582 unit, (int)d->scsi_channel, (int)d->scsi_id, d->scsi_lun,
583 scsi_device_online(d->pScsi_dev)? "online":"offline");
592 * Turn a struct scsi_cmnd * into a unique 32 bit 'context'.
594 static u32 adpt_cmd_to_context(struct scsi_cmnd *cmd)
596 return (u32)cmd->serial_number;
600 * Go from a u32 'context' to a struct scsi_cmnd * .
601 * This could probably be made more efficient.
603 static struct scsi_cmnd *
604 adpt_cmd_from_context(adpt_hba * pHba, u32 context)
606 struct scsi_cmnd * cmd;
607 struct scsi_device * d;
612 spin_unlock(pHba->host->host_lock);
613 shost_for_each_device(d, pHba->host) {
615 spin_lock_irqsave(&d->list_lock, flags);
616 list_for_each_entry(cmd, &d->cmd_list, list) {
617 if (((u32)cmd->serial_number == context)) {
618 spin_unlock_irqrestore(&d->list_lock, flags);
620 spin_lock(pHba->host->host_lock);
624 spin_unlock_irqrestore(&d->list_lock, flags);
626 spin_lock(pHba->host->host_lock);
631 /*===========================================================================
632 * Error Handling routines
633 *===========================================================================
636 static int adpt_abort(struct scsi_cmnd * cmd)
638 adpt_hba* pHba = NULL; /* host bus adapter structure */
639 struct adpt_device* dptdevice; /* dpt per device information */
643 if(cmd->serial_number == 0){
646 pHba = (adpt_hba*) cmd->device->host->hostdata[0];
647 printk(KERN_INFO"%s: Trying to Abort\n",pHba->name);
648 if ((dptdevice = (void*) (cmd->device->hostdata)) == NULL) {
649 printk(KERN_ERR "%s: Unable to abort: No device in cmnd\n",pHba->name);
653 memset(msg, 0, sizeof(msg));
654 msg[0] = FIVE_WORD_MSG_SIZE|SGL_OFFSET_0;
655 msg[1] = I2O_CMD_SCSI_ABORT<<24|HOST_TID<<12|dptdevice->tid;
658 msg[4] = adpt_cmd_to_context(cmd);
660 spin_lock_irq(pHba->host->host_lock);
661 rcode = adpt_i2o_post_wait(pHba, msg, sizeof(msg), FOREVER);
663 spin_unlock_irq(pHba->host->host_lock);
665 if(rcode == -EOPNOTSUPP ){
666 printk(KERN_INFO"%s: Abort cmd not supported\n",pHba->name);
669 printk(KERN_INFO"%s: Abort failed.\n",pHba->name);
672 printk(KERN_INFO"%s: Abort complete.\n",pHba->name);
677 #define I2O_DEVICE_RESET 0x27
678 // This is the same for BLK and SCSI devices
679 // NOTE this is wrong in the i2o.h definitions
680 // This is not currently supported by our adapter but we issue it anyway
681 static int adpt_device_reset(struct scsi_cmnd* cmd)
687 struct adpt_device* d = cmd->device->hostdata;
689 pHba = (void*) cmd->device->host->hostdata[0];
690 printk(KERN_INFO"%s: Trying to reset device\n",pHba->name);
692 printk(KERN_INFO"%s: Reset Device: Device Not found\n",pHba->name);
695 memset(msg, 0, sizeof(msg));
696 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
697 msg[1] = (I2O_DEVICE_RESET<<24|HOST_TID<<12|d->tid);
702 spin_lock_irq(pHba->host->host_lock);
703 old_state = d->state;
704 d->state |= DPTI_DEV_RESET;
705 rcode = adpt_i2o_post_wait(pHba, msg,sizeof(msg), FOREVER);
706 d->state = old_state;
708 spin_unlock_irq(pHba->host->host_lock);
710 if(rcode == -EOPNOTSUPP ){
711 printk(KERN_INFO"%s: Device reset not supported\n",pHba->name);
714 printk(KERN_INFO"%s: Device reset failed\n",pHba->name);
717 printk(KERN_INFO"%s: Device reset successful\n",pHba->name);
723 #define I2O_HBA_BUS_RESET 0x87
724 // This version of bus reset is called by the eh_error handler
725 static int adpt_bus_reset(struct scsi_cmnd* cmd)
731 pHba = (adpt_hba*)cmd->device->host->hostdata[0];
732 memset(msg, 0, sizeof(msg));
733 printk(KERN_WARNING"%s: Bus reset: SCSI Bus %d: tid: %d\n",pHba->name, cmd->device->channel,pHba->channel[cmd->device->channel].tid );
734 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
735 msg[1] = (I2O_HBA_BUS_RESET<<24|HOST_TID<<12|pHba->channel[cmd->device->channel].tid);
739 spin_lock_irq(pHba->host->host_lock);
740 rcode = adpt_i2o_post_wait(pHba, msg,sizeof(msg), FOREVER);
742 spin_unlock_irq(pHba->host->host_lock);
744 printk(KERN_WARNING"%s: Bus reset failed.\n",pHba->name);
747 printk(KERN_WARNING"%s: Bus reset success.\n",pHba->name);
752 // This version of reset is called by the eh_error_handler
753 static int __adpt_reset(struct scsi_cmnd* cmd)
759 pHba = (adpt_hba*)cmd->device->host->hostdata[0];
760 strncpy(name, pHba->name, sizeof(name));
761 printk(KERN_WARNING"%s: Hba Reset: scsi id %d: tid: %d\n", name, cmd->device->channel, pHba->channel[cmd->device->channel].tid);
762 rcode = adpt_hba_reset(pHba);
764 printk(KERN_WARNING"%s: HBA reset complete\n", name);
767 printk(KERN_WARNING"%s: HBA reset failed (%x)\n", name, rcode);
772 static int adpt_reset(struct scsi_cmnd* cmd)
776 spin_lock_irq(cmd->device->host->host_lock);
777 rc = __adpt_reset(cmd);
778 spin_unlock_irq(cmd->device->host->host_lock);
783 // This version of reset is called by the ioctls and indirectly from eh_error_handler via adpt_reset
784 static int adpt_hba_reset(adpt_hba* pHba)
788 pHba->state |= DPTI_STATE_RESET;
790 // Activate does get status , init outbound, and get hrt
791 if ((rcode=adpt_i2o_activate_hba(pHba)) < 0) {
792 printk(KERN_ERR "%s: Could not activate\n", pHba->name);
793 adpt_i2o_delete_hba(pHba);
797 if ((rcode=adpt_i2o_build_sys_table()) < 0) {
798 adpt_i2o_delete_hba(pHba);
801 PDEBUG("%s: in HOLD state\n",pHba->name);
803 if ((rcode=adpt_i2o_online_hba(pHba)) < 0) {
804 adpt_i2o_delete_hba(pHba);
807 PDEBUG("%s: in OPERATIONAL state\n",pHba->name);
809 if ((rcode=adpt_i2o_lct_get(pHba)) < 0){
810 adpt_i2o_delete_hba(pHba);
814 if ((rcode=adpt_i2o_reparse_lct(pHba)) < 0){
815 adpt_i2o_delete_hba(pHba);
818 pHba->state &= ~DPTI_STATE_RESET;
820 adpt_fail_posted_scbs(pHba);
821 return 0; /* return success */
824 /*===========================================================================
826 *===========================================================================
830 static void adpt_i2o_sys_shutdown(void)
832 adpt_hba *pHba, *pNext;
833 struct adpt_i2o_post_wait_data *p1, *old;
835 printk(KERN_INFO"Shutting down Adaptec I2O controllers.\n");
836 printk(KERN_INFO" This could take a few minutes if there are many devices attached\n");
837 /* Delete all IOPs from the controller chain */
838 /* They should have already been released by the
841 for (pHba = hba_chain; pHba; pHba = pNext) {
843 adpt_i2o_delete_hba(pHba);
846 /* Remove any timedout entries from the wait queue. */
847 // spin_lock_irqsave(&adpt_post_wait_lock, flags);
848 /* Nothing should be outstanding at this point so just
851 for(p1 = adpt_post_wait_queue; p1;) {
856 // spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
857 adpt_post_wait_queue = NULL;
859 printk(KERN_INFO "Adaptec I2O controllers down.\n");
862 static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev)
865 adpt_hba* pHba = NULL;
867 ulong base_addr0_phys = 0;
868 ulong base_addr1_phys = 0;
869 u32 hba_map0_area_size = 0;
870 u32 hba_map1_area_size = 0;
871 void __iomem *base_addr_virt = NULL;
872 void __iomem *msg_addr_virt = NULL;
875 int raptorFlag = FALSE;
877 if(pci_enable_device(pDev)) {
881 if (pci_request_regions(pDev, "dpt_i2o")) {
882 PERROR("dpti: adpt_config_hba: pci request region failed\n");
886 pci_set_master(pDev);
889 * See if we should enable dma64 mode.
891 if (sizeof(dma_addr_t) > 4 &&
892 pci_set_dma_mask(pDev, DMA_BIT_MASK(64)) == 0) {
893 if (dma_get_required_mask(&pDev->dev) > DMA_BIT_MASK(32))
896 if (!dma64 && pci_set_dma_mask(pDev, DMA_BIT_MASK(32)) != 0)
899 /* adapter only supports message blocks below 4GB */
900 pci_set_consistent_dma_mask(pDev, DMA_BIT_MASK(32));
902 base_addr0_phys = pci_resource_start(pDev,0);
903 hba_map0_area_size = pci_resource_len(pDev,0);
905 // Check if standard PCI card or single BAR Raptor
906 if(pDev->device == PCI_DPT_DEVICE_ID){
907 if(pDev->subsystem_device >=0xc032 && pDev->subsystem_device <= 0xc03b){
908 // Raptor card with this device id needs 4M
909 hba_map0_area_size = 0x400000;
910 } else { // Not Raptor - it is a PCI card
911 if(hba_map0_area_size > 0x100000 ){
912 hba_map0_area_size = 0x100000;
915 } else {// Raptor split BAR config
916 // Use BAR1 in this configuration
917 base_addr1_phys = pci_resource_start(pDev,1);
918 hba_map1_area_size = pci_resource_len(pDev,1);
922 #if BITS_PER_LONG == 64
924 * The original Adaptec 64 bit driver has this comment here:
925 * "x86_64 machines need more optimal mappings"
927 * I assume some HBAs report ridiculously large mappings
928 * and we need to limit them on platforms with IOMMUs.
930 if (raptorFlag == TRUE) {
931 if (hba_map0_area_size > 128)
932 hba_map0_area_size = 128;
933 if (hba_map1_area_size > 524288)
934 hba_map1_area_size = 524288;
936 if (hba_map0_area_size > 524288)
937 hba_map0_area_size = 524288;
941 base_addr_virt = ioremap(base_addr0_phys,hba_map0_area_size);
942 if (!base_addr_virt) {
943 pci_release_regions(pDev);
944 PERROR("dpti: adpt_config_hba: io remap failed\n");
948 if(raptorFlag == TRUE) {
949 msg_addr_virt = ioremap(base_addr1_phys, hba_map1_area_size );
950 if (!msg_addr_virt) {
951 PERROR("dpti: adpt_config_hba: io remap failed on BAR1\n");
952 iounmap(base_addr_virt);
953 pci_release_regions(pDev);
957 msg_addr_virt = base_addr_virt;
960 // Allocate and zero the data structure
961 pHba = kzalloc(sizeof(adpt_hba), GFP_KERNEL);
963 if (msg_addr_virt != base_addr_virt)
964 iounmap(msg_addr_virt);
965 iounmap(base_addr_virt);
966 pci_release_regions(pDev);
970 mutex_lock(&adpt_configuration_lock);
972 if(hba_chain != NULL){
973 for(p = hba_chain; p->next; p = p->next);
979 pHba->unit = hba_count;
980 sprintf(pHba->name, "dpti%d", hba_count);
983 mutex_unlock(&adpt_configuration_lock);
986 pHba->base_addr_phys = base_addr0_phys;
988 // Set up the Virtual Base Address of the I2O Device
989 pHba->base_addr_virt = base_addr_virt;
990 pHba->msg_addr_virt = msg_addr_virt;
991 pHba->irq_mask = base_addr_virt+0x30;
992 pHba->post_port = base_addr_virt+0x40;
993 pHba->reply_port = base_addr_virt+0x44;
998 pHba->status_block = NULL;
999 pHba->post_count = 0;
1000 pHba->state = DPTI_STATE_RESET;
1002 pHba->devices = NULL;
1003 pHba->dma64 = dma64;
1005 // Initializing the spinlocks
1006 spin_lock_init(&pHba->state_lock);
1007 spin_lock_init(&adpt_post_wait_lock);
1009 if(raptorFlag == 0){
1010 printk(KERN_INFO "Adaptec I2O RAID controller"
1011 " %d at %p size=%x irq=%d%s\n",
1012 hba_count-1, base_addr_virt,
1013 hba_map0_area_size, pDev->irq,
1014 dma64 ? " (64-bit DMA)" : "");
1016 printk(KERN_INFO"Adaptec I2O RAID controller %d irq=%d%s\n",
1017 hba_count-1, pDev->irq,
1018 dma64 ? " (64-bit DMA)" : "");
1019 printk(KERN_INFO" BAR0 %p - size= %x\n",base_addr_virt,hba_map0_area_size);
1020 printk(KERN_INFO" BAR1 %p - size= %x\n",msg_addr_virt,hba_map1_area_size);
1023 if (request_irq (pDev->irq, adpt_isr, IRQF_SHARED, pHba->name, pHba)) {
1024 printk(KERN_ERR"%s: Couldn't register IRQ %d\n", pHba->name, pDev->irq);
1025 adpt_i2o_delete_hba(pHba);
1033 static void adpt_i2o_delete_hba(adpt_hba* pHba)
1037 struct i2o_device* d;
1038 struct i2o_device* next;
1041 struct adpt_device* pDev;
1042 struct adpt_device* pNext;
1045 mutex_lock(&adpt_configuration_lock);
1047 free_irq(pHba->host->irq, pHba);
1050 for( p1 = hba_chain; p1; p2 = p1,p1=p1->next){
1053 p2->next = p1->next;
1055 hba_chain = p1->next;
1062 mutex_unlock(&adpt_configuration_lock);
1064 iounmap(pHba->base_addr_virt);
1065 pci_release_regions(pHba->pDev);
1066 if(pHba->msg_addr_virt != pHba->base_addr_virt){
1067 iounmap(pHba->msg_addr_virt);
1069 if(pHba->FwDebugBuffer_P)
1070 iounmap(pHba->FwDebugBuffer_P);
1072 dma_free_coherent(&pHba->pDev->dev,
1073 pHba->hrt->num_entries * pHba->hrt->entry_len << 2,
1074 pHba->hrt, pHba->hrt_pa);
1077 dma_free_coherent(&pHba->pDev->dev, pHba->lct_size,
1078 pHba->lct, pHba->lct_pa);
1080 if(pHba->status_block) {
1081 dma_free_coherent(&pHba->pDev->dev, sizeof(i2o_status_block),
1082 pHba->status_block, pHba->status_block_pa);
1084 if(pHba->reply_pool) {
1085 dma_free_coherent(&pHba->pDev->dev,
1086 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
1087 pHba->reply_pool, pHba->reply_pool_pa);
1090 for(d = pHba->devices; d ; d = next){
1094 for(i = 0 ; i < pHba->top_scsi_channel ; i++){
1095 for(j = 0; j < MAX_ID; j++){
1096 if(pHba->channel[i].device[j] != NULL){
1097 for(pDev = pHba->channel[i].device[j]; pDev; pDev = pNext){
1098 pNext = pDev->next_lun;
1104 pci_dev_put(pHba->pDev);
1105 if (adpt_sysfs_class)
1106 device_destroy(adpt_sysfs_class,
1107 MKDEV(DPTI_I2O_MAJOR, pHba->unit));
1111 unregister_chrdev(DPTI_I2O_MAJOR, DPT_DRIVER);
1112 if (adpt_sysfs_class) {
1113 class_destroy(adpt_sysfs_class);
1114 adpt_sysfs_class = NULL;
1119 static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u64 lun)
1121 struct adpt_device* d;
1123 if(chan < 0 || chan >= MAX_CHANNEL)
1126 d = pHba->channel[chan].device[id];
1127 if(!d || d->tid == 0) {
1131 /* If it is the only lun at that address then this should match*/
1132 if(d->scsi_lun == lun){
1136 /* else we need to look through all the luns */
1137 for(d=d->next_lun ; d ; d = d->next_lun){
1138 if(d->scsi_lun == lun){
1146 static int adpt_i2o_post_wait(adpt_hba* pHba, u32* msg, int len, int timeout)
1148 // I used my own version of the WAIT_QUEUE_HEAD
1149 // to handle some version differences
1150 // When embedded in the kernel this could go back to the vanilla one
1151 ADPT_DECLARE_WAIT_QUEUE_HEAD(adpt_wq_i2o_post);
1154 struct adpt_i2o_post_wait_data *p1, *p2;
1155 struct adpt_i2o_post_wait_data *wait_data =
1156 kmalloc(sizeof(struct adpt_i2o_post_wait_data), GFP_ATOMIC);
1157 DECLARE_WAITQUEUE(wait, current);
1163 * The spin locking is needed to keep anyone from playing
1164 * with the queue pointers and id while we do the same
1166 spin_lock_irqsave(&adpt_post_wait_lock, flags);
1167 // TODO we need a MORE unique way of getting ids
1168 // to support async LCT get
1169 wait_data->next = adpt_post_wait_queue;
1170 adpt_post_wait_queue = wait_data;
1171 adpt_post_wait_id++;
1172 adpt_post_wait_id &= 0x7fff;
1173 wait_data->id = adpt_post_wait_id;
1174 spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
1176 wait_data->wq = &adpt_wq_i2o_post;
1177 wait_data->status = -ETIMEDOUT;
1179 add_wait_queue(&adpt_wq_i2o_post, &wait);
1181 msg[2] |= 0x80000000 | ((u32)wait_data->id);
1183 if((status = adpt_i2o_post_this(pHba, msg, len)) == 0){
1184 set_current_state(TASK_INTERRUPTIBLE);
1186 spin_unlock_irq(pHba->host->host_lock);
1190 timeout = schedule_timeout(timeout);
1192 // I/O issued, but cannot get result in
1193 // specified time. Freeing resorces is
1199 spin_lock_irq(pHba->host->host_lock);
1201 remove_wait_queue(&adpt_wq_i2o_post, &wait);
1203 if(status == -ETIMEDOUT){
1204 printk(KERN_INFO"dpti%d: POST WAIT TIMEOUT\n",pHba->unit);
1205 // We will have to free the wait_data memory during shutdown
1209 /* Remove the entry from the queue. */
1211 spin_lock_irqsave(&adpt_post_wait_lock, flags);
1212 for(p1 = adpt_post_wait_queue; p1; p2 = p1, p1 = p1->next) {
1213 if(p1 == wait_data) {
1214 if(p1->status == I2O_DETAIL_STATUS_UNSUPPORTED_FUNCTION ) {
1215 status = -EOPNOTSUPP;
1218 p2->next = p1->next;
1220 adpt_post_wait_queue = p1->next;
1225 spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
1233 static s32 adpt_i2o_post_this(adpt_hba* pHba, u32* data, int len)
1236 u32 m = EMPTY_QUEUE;
1238 ulong timeout = jiffies + 30*HZ;
1241 m = readl(pHba->post_port);
1242 if (m != EMPTY_QUEUE) {
1245 if(time_after(jiffies,timeout)){
1246 printk(KERN_WARNING"dpti%d: Timeout waiting for message frame!\n", pHba->unit);
1249 schedule_timeout_uninterruptible(1);
1250 } while(m == EMPTY_QUEUE);
1252 msg = pHba->msg_addr_virt + m;
1253 memcpy_toio(msg, data, len);
1257 writel(m, pHba->post_port);
1264 static void adpt_i2o_post_wait_complete(u32 context, int status)
1266 struct adpt_i2o_post_wait_data *p1 = NULL;
1268 * We need to search through the adpt_post_wait
1269 * queue to see if the given message is still
1270 * outstanding. If not, it means that the IOP
1271 * took longer to respond to the message than we
1272 * had allowed and timer has already expired.
1273 * Not much we can do about that except log
1274 * it for debug purposes, increase timeout, and recompile
1276 * Lock needed to keep anyone from moving queue pointers
1277 * around while we're looking through them.
1282 spin_lock(&adpt_post_wait_lock);
1283 for(p1 = adpt_post_wait_queue; p1; p1 = p1->next) {
1284 if(p1->id == context) {
1285 p1->status = status;
1286 spin_unlock(&adpt_post_wait_lock);
1287 wake_up_interruptible(p1->wq);
1291 spin_unlock(&adpt_post_wait_lock);
1292 // If this happens we lose commands that probably really completed
1293 printk(KERN_DEBUG"dpti: Could Not find task %d in wait queue\n",context);
1294 printk(KERN_DEBUG" Tasks in wait queue:\n");
1295 for(p1 = adpt_post_wait_queue; p1; p1 = p1->next) {
1296 printk(KERN_DEBUG" %d\n",p1->id);
1301 static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1306 u32 m = EMPTY_QUEUE ;
1307 ulong timeout = jiffies + (TMOUT_IOPRESET*HZ);
1309 if(pHba->initialized == FALSE) { // First time reset should be quick
1310 timeout = jiffies + (25*HZ);
1312 adpt_i2o_quiesce_hba(pHba);
1317 m = readl(pHba->post_port);
1318 if (m != EMPTY_QUEUE) {
1321 if(time_after(jiffies,timeout)){
1322 printk(KERN_WARNING"Timeout waiting for message!\n");
1325 schedule_timeout_uninterruptible(1);
1326 } while (m == EMPTY_QUEUE);
1328 status = dma_alloc_coherent(&pHba->pDev->dev, 4, &addr, GFP_KERNEL);
1329 if(status == NULL) {
1330 adpt_send_nop(pHba, m);
1331 printk(KERN_ERR"IOP reset failed - no free memory.\n");
1336 msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0;
1337 msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID;
1342 msg[6]=dma_low(addr);
1343 msg[7]=dma_high(addr);
1345 memcpy_toio(pHba->msg_addr_virt+m, msg, sizeof(msg));
1347 writel(m, pHba->post_port);
1350 while(*status == 0){
1351 if(time_after(jiffies,timeout)){
1352 printk(KERN_WARNING"%s: IOP Reset Timeout\n",pHba->name);
1353 /* We lose 4 bytes of "status" here, but we cannot
1354 free these because controller may awake and corrupt
1355 those bytes at any time */
1356 /* dma_free_coherent(&pHba->pDev->dev, 4, buf, addr); */
1360 schedule_timeout_uninterruptible(1);
1363 if(*status == 0x01 /*I2O_EXEC_IOP_RESET_IN_PROGRESS*/) {
1364 PDEBUG("%s: Reset in progress...\n", pHba->name);
1365 // Here we wait for message frame to become available
1366 // indicated that reset has finished
1369 m = readl(pHba->post_port);
1370 if (m != EMPTY_QUEUE) {
1373 if(time_after(jiffies,timeout)){
1374 printk(KERN_ERR "%s:Timeout waiting for IOP Reset.\n",pHba->name);
1375 /* We lose 4 bytes of "status" here, but we
1376 cannot free these because controller may
1377 awake and corrupt those bytes at any time */
1378 /* dma_free_coherent(&pHba->pDev->dev, 4, buf, addr); */
1381 schedule_timeout_uninterruptible(1);
1382 } while (m == EMPTY_QUEUE);
1384 adpt_send_nop(pHba, m);
1386 adpt_i2o_status_get(pHba);
1387 if(*status == 0x02 ||
1388 pHba->status_block->iop_state != ADAPTER_STATE_RESET) {
1389 printk(KERN_WARNING"%s: Reset reject, trying to clear\n",
1392 PDEBUG("%s: Reset completed.\n", pHba->name);
1395 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
1397 // This delay is to allow someone attached to the card through the debug UART to
1398 // set up the dump levels that they want before the rest of the initialization sequence
1405 static int adpt_i2o_parse_lct(adpt_hba* pHba)
1410 struct i2o_device *d;
1411 i2o_lct *lct = pHba->lct;
1415 u32 buf[10]; // larger than 7, or 8 ...
1416 struct adpt_device* pDev;
1419 printk(KERN_ERR "%s: LCT is empty???\n",pHba->name);
1423 max = lct->table_size;
1427 for(i=0;i<max;i++) {
1428 if( lct->lct_entry[i].user_tid != 0xfff){
1430 * If we have hidden devices, we need to inform the upper layers about
1431 * the possible maximum id reference to handle device access when
1432 * an array is disassembled. This code has no other purpose but to
1433 * allow us future access to devices that are currently hidden
1434 * behind arrays, hotspares or have not been configured (JBOD mode).
1436 if( lct->lct_entry[i].class_id != I2O_CLASS_RANDOM_BLOCK_STORAGE &&
1437 lct->lct_entry[i].class_id != I2O_CLASS_SCSI_PERIPHERAL &&
1438 lct->lct_entry[i].class_id != I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL ){
1441 tid = lct->lct_entry[i].tid;
1442 // I2O_DPT_DEVICE_INFO_GROUP_NO;
1443 if(adpt_i2o_query_scalar(pHba, tid, 0x8000, -1, buf, 32)<0) {
1446 bus_no = buf[0]>>16;
1448 scsi_lun = scsilun_to_int((struct scsi_lun *)&buf[2]);
1449 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
1450 printk(KERN_WARNING"%s: Channel number %d out of range \n", pHba->name, bus_no);
1453 if (scsi_id >= MAX_ID){
1454 printk(KERN_WARNING"%s: SCSI ID %d out of range \n", pHba->name, bus_no);
1457 if(bus_no > pHba->top_scsi_channel){
1458 pHba->top_scsi_channel = bus_no;
1460 if(scsi_id > pHba->top_scsi_id){
1461 pHba->top_scsi_id = scsi_id;
1463 if(scsi_lun > pHba->top_scsi_lun){
1464 pHba->top_scsi_lun = scsi_lun;
1468 d = kmalloc(sizeof(struct i2o_device), GFP_KERNEL);
1471 printk(KERN_CRIT"%s: Out of memory for I2O device data.\n",pHba->name);
1475 d->controller = pHba;
1478 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
1481 tid = d->lct_data.tid;
1482 adpt_i2o_report_hba_unit(pHba, d);
1483 adpt_i2o_install_device(pHba, d);
1486 for(d = pHba->devices; d ; d = d->next) {
1487 if(d->lct_data.class_id == I2O_CLASS_BUS_ADAPTER_PORT ||
1488 d->lct_data.class_id == I2O_CLASS_FIBRE_CHANNEL_PORT){
1489 tid = d->lct_data.tid;
1490 // TODO get the bus_no from hrt-but for now they are in order
1492 if(bus_no > pHba->top_scsi_channel){
1493 pHba->top_scsi_channel = bus_no;
1495 pHba->channel[bus_no].type = d->lct_data.class_id;
1496 pHba->channel[bus_no].tid = tid;
1497 if(adpt_i2o_query_scalar(pHba, tid, 0x0200, -1, buf, 28)>=0)
1499 pHba->channel[bus_no].scsi_id = buf[1];
1500 PDEBUG("Bus %d - SCSI ID %d.\n", bus_no, buf[1]);
1502 // TODO remove - this is just until we get from hrt
1504 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
1505 printk(KERN_WARNING"%s: Channel number %d out of range - LCT\n", pHba->name, bus_no);
1511 // Setup adpt_device table
1512 for(d = pHba->devices; d ; d = d->next) {
1513 if(d->lct_data.class_id == I2O_CLASS_RANDOM_BLOCK_STORAGE ||
1514 d->lct_data.class_id == I2O_CLASS_SCSI_PERIPHERAL ||
1515 d->lct_data.class_id == I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL ){
1517 tid = d->lct_data.tid;
1519 // I2O_DPT_DEVICE_INFO_GROUP_NO;
1520 if(adpt_i2o_query_scalar(pHba, tid, 0x8000, -1, buf, 32)>=0) {
1521 bus_no = buf[0]>>16;
1523 scsi_lun = scsilun_to_int((struct scsi_lun *)&buf[2]);
1524 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
1527 if (scsi_id >= MAX_ID) {
1530 if( pHba->channel[bus_no].device[scsi_id] == NULL){
1531 pDev = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
1535 pHba->channel[bus_no].device[scsi_id] = pDev;
1537 for( pDev = pHba->channel[bus_no].device[scsi_id];
1538 pDev->next_lun; pDev = pDev->next_lun){
1540 pDev->next_lun = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
1541 if(pDev->next_lun == NULL) {
1544 pDev = pDev->next_lun;
1547 pDev->scsi_channel = bus_no;
1548 pDev->scsi_id = scsi_id;
1549 pDev->scsi_lun = scsi_lun;
1552 pDev->type = (buf[0])&0xff;
1553 pDev->flags = (buf[0]>>8)&0xff;
1554 if(scsi_id > pHba->top_scsi_id){
1555 pHba->top_scsi_id = scsi_id;
1557 if(scsi_lun > pHba->top_scsi_lun){
1558 pHba->top_scsi_lun = scsi_lun;
1562 printk(KERN_WARNING"Could not find SCSI ID for %s\n",
1563 d->lct_data.identity_tag);
1572 * Each I2O controller has a chain of devices on it - these match
1573 * the useful parts of the LCT of the board.
1576 static int adpt_i2o_install_device(adpt_hba* pHba, struct i2o_device *d)
1578 mutex_lock(&adpt_configuration_lock);
1581 d->next=pHba->devices;
1583 if (pHba->devices != NULL){
1584 pHba->devices->prev=d;
1589 mutex_unlock(&adpt_configuration_lock);
1593 static int adpt_open(struct inode *inode, struct file *file)
1598 mutex_lock(&adpt_mutex);
1599 //TODO check for root access
1601 minor = iminor(inode);
1602 if (minor >= hba_count) {
1603 mutex_unlock(&adpt_mutex);
1606 mutex_lock(&adpt_configuration_lock);
1607 for (pHba = hba_chain; pHba; pHba = pHba->next) {
1608 if (pHba->unit == minor) {
1609 break; /* found adapter */
1613 mutex_unlock(&adpt_configuration_lock);
1614 mutex_unlock(&adpt_mutex);
1618 // if(pHba->in_use){
1619 // mutex_unlock(&adpt_configuration_lock);
1624 mutex_unlock(&adpt_configuration_lock);
1625 mutex_unlock(&adpt_mutex);
1630 static int adpt_close(struct inode *inode, struct file *file)
1635 minor = iminor(inode);
1636 if (minor >= hba_count) {
1639 mutex_lock(&adpt_configuration_lock);
1640 for (pHba = hba_chain; pHba; pHba = pHba->next) {
1641 if (pHba->unit == minor) {
1642 break; /* found adapter */
1645 mutex_unlock(&adpt_configuration_lock);
1655 #if defined __ia64__
1656 static void adpt_ia64_info(sysInfo_S* si)
1658 // This is all the info we need for now
1659 // We will add more info as our new
1660 // managmenent utility requires it
1661 si->processorType = PROC_IA64;
1665 #if defined __sparc__
1666 static void adpt_sparc_info(sysInfo_S* si)
1668 // This is all the info we need for now
1669 // We will add more info as our new
1670 // managmenent utility requires it
1671 si->processorType = PROC_ULTRASPARC;
1674 #if defined __alpha__
1675 static void adpt_alpha_info(sysInfo_S* si)
1677 // This is all the info we need for now
1678 // We will add more info as our new
1679 // managmenent utility requires it
1680 si->processorType = PROC_ALPHA;
1684 #if defined __i386__
1686 #include <uapi/asm/vm86.h>
1688 static void adpt_i386_info(sysInfo_S* si)
1690 // This is all the info we need for now
1691 // We will add more info as our new
1692 // managmenent utility requires it
1693 switch (boot_cpu_data.x86) {
1695 si->processorType = PROC_386;
1698 si->processorType = PROC_486;
1701 si->processorType = PROC_PENTIUM;
1703 default: // Just in case
1704 si->processorType = PROC_PENTIUM;
1711 * This routine returns information about the system. This does not effect
1712 * any logic and if the info is wrong - it doesn't matter.
1715 /* Get all the info we can not get from kernel services */
1716 static int adpt_system_info(void __user *buffer)
1720 memset(&si, 0, sizeof(si));
1722 si.osType = OS_LINUX;
1723 si.osMajorVersion = 0;
1724 si.osMinorVersion = 0;
1726 si.busType = SI_PCI_BUS;
1727 si.processorFamily = DPTI_sig.dsProcessorFamily;
1729 #if defined __i386__
1730 adpt_i386_info(&si);
1731 #elif defined (__ia64__)
1732 adpt_ia64_info(&si);
1733 #elif defined(__sparc__)
1734 adpt_sparc_info(&si);
1735 #elif defined (__alpha__)
1736 adpt_alpha_info(&si);
1738 si.processorType = 0xff ;
1740 if (copy_to_user(buffer, &si, sizeof(si))){
1741 printk(KERN_WARNING"dpti: Could not copy buffer TO user\n");
1748 static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1754 void __user *argp = (void __user *)arg;
1756 minor = iminor(inode);
1757 if (minor >= DPTI_MAX_HBA){
1760 mutex_lock(&adpt_configuration_lock);
1761 for (pHba = hba_chain; pHba; pHba = pHba->next) {
1762 if (pHba->unit == minor) {
1763 break; /* found adapter */
1766 mutex_unlock(&adpt_configuration_lock);
1771 while((volatile u32) pHba->state & DPTI_STATE_RESET )
1772 schedule_timeout_uninterruptible(2);
1775 // TODO: handle 3 cases
1777 if (copy_to_user(argp, &DPTI_sig, sizeof(DPTI_sig))) {
1783 drvrHBAinfo_S HbaInfo;
1785 #define FLG_OSD_PCI_VALID 0x0001
1786 #define FLG_OSD_DMA 0x0002
1787 #define FLG_OSD_I2O 0x0004
1788 memset(&HbaInfo, 0, sizeof(HbaInfo));
1789 HbaInfo.drvrHBAnum = pHba->unit;
1790 HbaInfo.baseAddr = (ulong) pHba->base_addr_phys;
1791 HbaInfo.blinkState = adpt_read_blink_led(pHba);
1792 HbaInfo.pciBusNum = pHba->pDev->bus->number;
1793 HbaInfo.pciDeviceNum=PCI_SLOT(pHba->pDev->devfn);
1794 HbaInfo.Interrupt = pHba->pDev->irq;
1795 HbaInfo.hbaFlags = FLG_OSD_PCI_VALID | FLG_OSD_DMA | FLG_OSD_I2O;
1796 if(copy_to_user(argp, &HbaInfo, sizeof(HbaInfo))){
1797 printk(KERN_WARNING"%s: Could not copy HbaInfo TO user\n",pHba->name);
1803 return adpt_system_info(argp);
1806 value = (u32)adpt_read_blink_led(pHba);
1807 if (copy_to_user(argp, &value, sizeof(value))) {
1813 struct Scsi_Host *shost = pHba->host;
1816 spin_lock_irqsave(shost->host_lock, flags);
1817 adpt_hba_reset(pHba);
1819 spin_unlock_irqrestore(shost->host_lock, flags);
1832 static long adpt_unlocked_ioctl(struct file *file, uint cmd, ulong arg)
1834 struct inode *inode;
1837 inode = file_inode(file);
1839 mutex_lock(&adpt_mutex);
1840 ret = adpt_ioctl(inode, file, cmd, arg);
1841 mutex_unlock(&adpt_mutex);
1846 #ifdef CONFIG_COMPAT
1847 static long compat_adpt_ioctl(struct file *file,
1848 unsigned int cmd, unsigned long arg)
1850 struct inode *inode;
1853 inode = file_inode(file);
1855 mutex_lock(&adpt_mutex);
1865 case (DPT_TARGET_BUSY & 0xFFFF):
1866 case DPT_TARGET_BUSY:
1867 ret = adpt_ioctl(inode, file, cmd, arg);
1873 mutex_unlock(&adpt_mutex);
1879 static irqreturn_t adpt_isr(int irq, void *dev_id)
1881 struct scsi_cmnd* cmd;
1882 adpt_hba* pHba = dev_id;
1884 void __iomem *reply;
1891 printk(KERN_WARNING"adpt_isr: NULL dev_id\n");
1895 spin_lock_irqsave(pHba->host->host_lock, flags);
1897 while( readl(pHba->irq_mask) & I2O_INTERRUPT_PENDING_B) {
1898 m = readl(pHba->reply_port);
1899 if(m == EMPTY_QUEUE){
1900 // Try twice then give up
1902 m = readl(pHba->reply_port);
1903 if(m == EMPTY_QUEUE){
1904 // This really should not happen
1905 printk(KERN_ERR"dpti: Could not get reply frame\n");
1909 if (pHba->reply_pool_pa <= m &&
1910 m < pHba->reply_pool_pa +
1911 (pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4)) {
1912 reply = (u8 *)pHba->reply_pool +
1913 (m - pHba->reply_pool_pa);
1915 /* Ick, we should *never* be here */
1916 printk(KERN_ERR "dpti: reply frame not from pool\n");
1920 if (readl(reply) & MSG_FAIL) {
1921 u32 old_m = readl(reply+28);
1924 PDEBUG("%s: Failed message\n",pHba->name);
1925 if(old_m >= 0x100000){
1926 printk(KERN_ERR"%s: Bad preserved MFA (%x)- dropping frame\n",pHba->name,old_m);
1927 writel(m,pHba->reply_port);
1930 // Transaction context is 0 in failed reply frame
1931 msg = pHba->msg_addr_virt + old_m;
1932 old_context = readl(msg+12);
1933 writel(old_context, reply+12);
1934 adpt_send_nop(pHba, old_m);
1936 context = readl(reply+8);
1937 if(context & 0x80000000){ // Post wait message
1938 status = readl(reply+16);
1940 status &= 0xffff; /* Get detail status */
1942 status = I2O_POST_WAIT_OK;
1944 cmd = adpt_cmd_from_context(pHba, readl(reply+12));
1946 printk(KERN_WARNING"%s: Apparent SCSI cmd in Post Wait Context - cmd=%p context=%x\n", pHba->name, cmd, context);
1948 adpt_i2o_post_wait_complete(context, status);
1949 } else { // SCSI message
1950 cmd = adpt_cmd_from_context (pHba, readl(reply+12));
1952 scsi_dma_unmap(cmd);
1953 if(cmd->serial_number != 0) { // If not timedout
1954 adpt_i2o_to_scsi(reply, cmd);
1958 writel(m, pHba->reply_port);
1964 spin_unlock_irqrestore(pHba->host->host_lock, flags);
1965 return IRQ_RETVAL(handled);
1968 static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_device* d)
1971 u32 msg[MAX_MESSAGE_SIZE];
1983 memset(msg, 0 , sizeof(msg));
1984 len = scsi_bufflen(cmd);
1985 direction = 0x00000000;
1987 scsidir = 0x00000000; // DATA NO XFER
1990 * Set SCBFlags to indicate if data is being transferred
1991 * in or out, or no data transfer
1992 * Note: Do not have to verify index is less than 0 since
1993 * cmd->cmnd[0] is an unsigned char
1995 switch(cmd->sc_data_direction){
1996 case DMA_FROM_DEVICE:
1997 scsidir =0x40000000; // DATA IN (iop<--dev)
2000 direction=0x04000000; // SGL OUT
2001 scsidir =0x80000000; // DATA OUT (iop-->dev)
2005 case DMA_BIDIRECTIONAL:
2006 scsidir =0x40000000; // DATA IN (iop<--dev)
2007 // Assume In - and continue;
2010 printk(KERN_WARNING"%s: scsi opcode 0x%x not supported.\n",
2011 pHba->name, cmd->cmnd[0]);
2012 cmd->result = (DID_OK <<16) | (INITIATOR_ERROR << 8);
2013 cmd->scsi_done(cmd);
2017 // msg[0] is set later
2018 // I2O_CMD_SCSI_EXEC
2019 msg[1] = ((0xff<<24)|(HOST_TID<<12)|d->tid);
2021 msg[3] = adpt_cmd_to_context(cmd); /* Want SCSI control block back */
2022 // Our cards use the transaction context as the tag for queueing
2023 // Adaptec/DPT Private stuff
2024 msg[4] = I2O_CMD_SCSI_EXEC|(DPT_ORGANIZATION_ID<<16);
2026 /* Direction, disconnect ok | sense data | simple queue , CDBLen */
2027 // I2O_SCB_FLAG_ENABLE_DISCONNECT |
2028 // I2O_SCB_FLAG_SIMPLE_QUEUE_TAG |
2029 // I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
2030 msg[6] = scsidir|0x20a00000|cmd->cmd_len;
2034 // Write SCSI command into the message - always 16 byte block
2035 memset(mptr, 0, 16);
2036 memcpy(mptr, cmd->cmnd, cmd->cmd_len);
2038 lenptr=mptr++; /* Remember me - fill in when we know */
2039 if (dpt_dma64(pHba)) {
2040 reqlen = 16; // SINGLE SGE
2041 *mptr++ = (0x7C<<24)+(2<<16)+0x02; /* Enable 64 bit */
2042 *mptr++ = 1 << PAGE_SHIFT;
2044 reqlen = 14; // SINGLE SGE
2046 /* Now fill in the SGList and command */
2048 nseg = scsi_dma_map(cmd);
2051 struct scatterlist *sg;
2054 scsi_for_each_sg(cmd, sg, nseg, i) {
2056 *mptr++ = direction|0x10000000|sg_dma_len(sg);
2057 len+=sg_dma_len(sg);
2058 addr = sg_dma_address(sg);
2059 *mptr++ = dma_low(addr);
2060 if (dpt_dma64(pHba))
2061 *mptr++ = dma_high(addr);
2062 /* Make this an end of list */
2064 *lptr = direction|0xD0000000|sg_dma_len(sg);
2066 reqlen = mptr - msg;
2069 if(cmd->underflow && len != cmd->underflow){
2070 printk(KERN_WARNING"Cmd len %08X Cmd underflow %08X\n",
2071 len, cmd->underflow);
2078 /* Stick the headers on */
2079 msg[0] = reqlen<<16 | ((reqlen > 12) ? SGL_OFFSET_12 : SGL_OFFSET_0);
2081 // Send it on it's way
2082 rcode = adpt_i2o_post_this(pHba, msg, reqlen<<2);
2090 static s32 adpt_scsi_host_alloc(adpt_hba* pHba, struct scsi_host_template *sht)
2092 struct Scsi_Host *host;
2094 host = scsi_host_alloc(sht, sizeof(adpt_hba*));
2096 printk("%s: scsi_host_alloc returned NULL\n", pHba->name);
2099 host->hostdata[0] = (unsigned long)pHba;
2102 host->irq = pHba->pDev->irq;
2103 /* no IO ports, so don't have to set host->io_port and
2107 host->n_io_port = 0;
2108 /* see comments in scsi_host.h */
2110 host->max_lun = 256;
2111 host->max_channel = pHba->top_scsi_channel + 1;
2112 host->cmd_per_lun = 1;
2113 host->unique_id = (u32)sys_tbl_pa + pHba->unit;
2114 host->sg_tablesize = pHba->sg_tablesize;
2115 host->can_queue = pHba->post_fifo_size;
2116 host->use_cmd_list = 1;
2122 static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd)
2127 u32 reply_flags = readl(reply) & 0xff00; // Leave it shifted up 8 bits
2128 // I know this would look cleaner if I just read bytes
2129 // but the model I have been using for all the rest of the
2130 // io is in 4 byte words - so I keep that model
2131 u16 detailed_status = readl(reply+16) &0xffff;
2132 dev_status = (detailed_status & 0xff);
2133 hba_status = detailed_status >> 8;
2135 // calculate resid for sg
2136 scsi_set_resid(cmd, scsi_bufflen(cmd) - readl(reply+20));
2138 pHba = (adpt_hba*) cmd->device->host->hostdata[0];
2140 cmd->sense_buffer[0] = '\0'; // initialize sense valid flag to false
2142 if(!(reply_flags & MSG_FAIL)) {
2143 switch(detailed_status & I2O_SCSI_DSC_MASK) {
2144 case I2O_SCSI_DSC_SUCCESS:
2145 cmd->result = (DID_OK << 16);
2147 if (readl(reply+20) < cmd->underflow) {
2148 cmd->result = (DID_ERROR <<16);
2149 printk(KERN_WARNING"%s: SCSI CMD underflow\n",pHba->name);
2152 case I2O_SCSI_DSC_REQUEST_ABORTED:
2153 cmd->result = (DID_ABORT << 16);
2155 case I2O_SCSI_DSC_PATH_INVALID:
2156 case I2O_SCSI_DSC_DEVICE_NOT_PRESENT:
2157 case I2O_SCSI_DSC_SELECTION_TIMEOUT:
2158 case I2O_SCSI_DSC_COMMAND_TIMEOUT:
2159 case I2O_SCSI_DSC_NO_ADAPTER:
2160 case I2O_SCSI_DSC_RESOURCE_UNAVAILABLE:
2161 printk(KERN_WARNING"%s: SCSI Timeout-Device (%d,%d,%llu) hba status=0x%x, dev status=0x%x, cmd=0x%x\n",
2162 pHba->name, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun, hba_status, dev_status, cmd->cmnd[0]);
2163 cmd->result = (DID_TIME_OUT << 16);
2165 case I2O_SCSI_DSC_ADAPTER_BUSY:
2166 case I2O_SCSI_DSC_BUS_BUSY:
2167 cmd->result = (DID_BUS_BUSY << 16);
2169 case I2O_SCSI_DSC_SCSI_BUS_RESET:
2170 case I2O_SCSI_DSC_BDR_MESSAGE_SENT:
2171 cmd->result = (DID_RESET << 16);
2173 case I2O_SCSI_DSC_PARITY_ERROR_FAILURE:
2174 printk(KERN_WARNING"%s: SCSI CMD parity error\n",pHba->name);
2175 cmd->result = (DID_PARITY << 16);
2177 case I2O_SCSI_DSC_UNABLE_TO_ABORT:
2178 case I2O_SCSI_DSC_COMPLETE_WITH_ERROR:
2179 case I2O_SCSI_DSC_UNABLE_TO_TERMINATE:
2180 case I2O_SCSI_DSC_MR_MESSAGE_RECEIVED:
2181 case I2O_SCSI_DSC_AUTOSENSE_FAILED:
2182 case I2O_SCSI_DSC_DATA_OVERRUN:
2183 case I2O_SCSI_DSC_UNEXPECTED_BUS_FREE:
2184 case I2O_SCSI_DSC_SEQUENCE_FAILURE:
2185 case I2O_SCSI_DSC_REQUEST_LENGTH_ERROR:
2186 case I2O_SCSI_DSC_PROVIDE_FAILURE:
2187 case I2O_SCSI_DSC_REQUEST_TERMINATED:
2188 case I2O_SCSI_DSC_IDE_MESSAGE_SENT:
2189 case I2O_SCSI_DSC_UNACKNOWLEDGED_EVENT:
2190 case I2O_SCSI_DSC_MESSAGE_RECEIVED:
2191 case I2O_SCSI_DSC_INVALID_CDB:
2192 case I2O_SCSI_DSC_LUN_INVALID:
2193 case I2O_SCSI_DSC_SCSI_TID_INVALID:
2194 case I2O_SCSI_DSC_FUNCTION_UNAVAILABLE:
2195 case I2O_SCSI_DSC_NO_NEXUS:
2196 case I2O_SCSI_DSC_CDB_RECEIVED:
2197 case I2O_SCSI_DSC_LUN_ALREADY_ENABLED:
2198 case I2O_SCSI_DSC_QUEUE_FROZEN:
2199 case I2O_SCSI_DSC_REQUEST_INVALID:
2201 printk(KERN_WARNING"%s: SCSI error %0x-Device(%d,%d,%llu) hba_status=0x%x, dev_status=0x%x, cmd=0x%x\n",
2202 pHba->name, detailed_status & I2O_SCSI_DSC_MASK, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun,
2203 hba_status, dev_status, cmd->cmnd[0]);
2204 cmd->result = (DID_ERROR << 16);
2208 // copy over the request sense data if it was a check
2210 if (dev_status == SAM_STAT_CHECK_CONDITION) {
2211 u32 len = min(SCSI_SENSE_BUFFERSIZE, 40);
2212 // Copy over the sense data
2213 memcpy_fromio(cmd->sense_buffer, (reply+28) , len);
2214 if(cmd->sense_buffer[0] == 0x70 /* class 7 */ &&
2215 cmd->sense_buffer[2] == DATA_PROTECT ){
2216 /* This is to handle an array failed */
2217 cmd->result = (DID_TIME_OUT << 16);
2218 printk(KERN_WARNING"%s: SCSI Data Protect-Device (%d,%d,%llu) hba_status=0x%x, dev_status=0x%x, cmd=0x%x\n",
2219 pHba->name, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun,
2220 hba_status, dev_status, cmd->cmnd[0]);
2225 /* In this condtion we could not talk to the tid
2226 * the card rejected it. We should signal a retry
2227 * for a limitted number of retries.
2229 cmd->result = (DID_TIME_OUT << 16);
2230 printk(KERN_WARNING"%s: I2O MSG_FAIL - Device (%d,%d,%llu) tid=%d, cmd=0x%x\n",
2231 pHba->name, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun,
2232 ((struct adpt_device*)(cmd->device->hostdata))->tid, cmd->cmnd[0]);
2235 cmd->result |= (dev_status);
2237 if(cmd->scsi_done != NULL){
2238 cmd->scsi_done(cmd);
2244 static s32 adpt_rescan(adpt_hba* pHba)
2250 spin_lock_irqsave(pHba->host->host_lock, flags);
2251 if ((rcode=adpt_i2o_lct_get(pHba)) < 0)
2253 if ((rcode=adpt_i2o_reparse_lct(pHba)) < 0)
2257 spin_unlock_irqrestore(pHba->host->host_lock, flags);
2262 static s32 adpt_i2o_reparse_lct(adpt_hba* pHba)
2267 struct i2o_device *d;
2268 i2o_lct *lct = pHba->lct;
2272 u32 buf[10]; // at least 8 u32's
2273 struct adpt_device* pDev = NULL;
2274 struct i2o_device* pI2o_dev = NULL;
2277 printk(KERN_ERR "%s: LCT is empty???\n",pHba->name);
2281 max = lct->table_size;
2285 // Mark each drive as unscanned
2286 for (d = pHba->devices; d; d = d->next) {
2287 pDev =(struct adpt_device*) d->owner;
2291 pDev->state |= DPTI_DEV_UNSCANNED;
2294 printk(KERN_INFO "%s: LCT has %d entries.\n", pHba->name,max);
2296 for(i=0;i<max;i++) {
2297 if( lct->lct_entry[i].user_tid != 0xfff){
2301 if( lct->lct_entry[i].class_id == I2O_CLASS_RANDOM_BLOCK_STORAGE ||
2302 lct->lct_entry[i].class_id == I2O_CLASS_SCSI_PERIPHERAL ||
2303 lct->lct_entry[i].class_id == I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL ){
2304 tid = lct->lct_entry[i].tid;
2305 if(adpt_i2o_query_scalar(pHba, tid, 0x8000, -1, buf, 32)<0) {
2306 printk(KERN_ERR"%s: Could not query device\n",pHba->name);
2309 bus_no = buf[0]>>16;
2310 if (bus_no >= MAX_CHANNEL) { /* Something wrong skip it */
2312 "%s: Channel number %d out of range\n",
2313 pHba->name, bus_no);
2318 scsi_lun = scsilun_to_int((struct scsi_lun *)&buf[2]);
2319 pDev = pHba->channel[bus_no].device[scsi_id];
2322 if(pDev->scsi_lun == scsi_lun) {
2325 pDev = pDev->next_lun;
2327 if(!pDev ) { // Something new add it
2328 d = kmalloc(sizeof(struct i2o_device),
2332 printk(KERN_CRIT "Out of memory for I2O device data.\n");
2336 d->controller = pHba;
2339 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
2342 adpt_i2o_report_hba_unit(pHba, d);
2343 adpt_i2o_install_device(pHba, d);
2345 pDev = pHba->channel[bus_no].device[scsi_id];
2348 kzalloc(sizeof(struct adpt_device),
2353 pHba->channel[bus_no].device[scsi_id] = pDev;
2355 while (pDev->next_lun) {
2356 pDev = pDev->next_lun;
2358 pDev = pDev->next_lun =
2359 kzalloc(sizeof(struct adpt_device),
2365 pDev->tid = d->lct_data.tid;
2366 pDev->scsi_channel = bus_no;
2367 pDev->scsi_id = scsi_id;
2368 pDev->scsi_lun = scsi_lun;
2371 pDev->type = (buf[0])&0xff;
2372 pDev->flags = (buf[0]>>8)&0xff;
2373 // Too late, SCSI system has made up it's mind, but what the hey ...
2374 if(scsi_id > pHba->top_scsi_id){
2375 pHba->top_scsi_id = scsi_id;
2377 if(scsi_lun > pHba->top_scsi_lun){
2378 pHba->top_scsi_lun = scsi_lun;
2381 } // end of new i2o device
2383 // We found an old device - check it
2385 if(pDev->scsi_lun == scsi_lun) {
2386 if(!scsi_device_online(pDev->pScsi_dev)) {
2387 printk(KERN_WARNING"%s: Setting device (%d,%d,%llu) back online\n",
2388 pHba->name,bus_no,scsi_id,scsi_lun);
2389 if (pDev->pScsi_dev) {
2390 scsi_device_set_state(pDev->pScsi_dev, SDEV_RUNNING);
2394 if(d->lct_data.tid != tid) { // something changed
2396 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
2397 if (pDev->pScsi_dev) {
2398 pDev->pScsi_dev->changed = TRUE;
2399 pDev->pScsi_dev->removable = TRUE;
2402 // Found it - mark it scanned
2403 pDev->state = DPTI_DEV_ONLINE;
2406 pDev = pDev->next_lun;
2410 for (pI2o_dev = pHba->devices; pI2o_dev; pI2o_dev = pI2o_dev->next) {
2411 pDev =(struct adpt_device*) pI2o_dev->owner;
2415 // Drive offline drives that previously existed but could not be found
2417 if (pDev->state & DPTI_DEV_UNSCANNED){
2418 pDev->state = DPTI_DEV_OFFLINE;
2419 printk(KERN_WARNING"%s: Device (%d,%d,%llu) offline\n",pHba->name,pDev->scsi_channel,pDev->scsi_id,pDev->scsi_lun);
2420 if (pDev->pScsi_dev) {
2421 scsi_device_set_state(pDev->pScsi_dev, SDEV_OFFLINE);
2428 static void adpt_fail_posted_scbs(adpt_hba* pHba)
2430 struct scsi_cmnd* cmd = NULL;
2431 struct scsi_device* d = NULL;
2433 shost_for_each_device(d, pHba->host) {
2434 unsigned long flags;
2435 spin_lock_irqsave(&d->list_lock, flags);
2436 list_for_each_entry(cmd, &d->cmd_list, list) {
2437 if(cmd->serial_number == 0){
2440 cmd->result = (DID_OK << 16) | (QUEUE_FULL <<1);
2441 cmd->scsi_done(cmd);
2443 spin_unlock_irqrestore(&d->list_lock, flags);
2448 /*============================================================================
2449 * Routines from i2o subsystem
2450 *============================================================================
2456 * Bring an I2O controller into HOLD state. See the spec.
2458 static int adpt_i2o_activate_hba(adpt_hba* pHba)
2462 if(pHba->initialized ) {
2463 if (adpt_i2o_status_get(pHba) < 0) {
2464 if((rcode = adpt_i2o_reset_hba(pHba)) != 0){
2465 printk(KERN_WARNING"%s: Could NOT reset.\n", pHba->name);
2468 if (adpt_i2o_status_get(pHba) < 0) {
2469 printk(KERN_INFO "HBA not responding.\n");
2474 if(pHba->status_block->iop_state == ADAPTER_STATE_FAULTED) {
2475 printk(KERN_CRIT "%s: hardware fault\n", pHba->name);
2479 if (pHba->status_block->iop_state == ADAPTER_STATE_READY ||
2480 pHba->status_block->iop_state == ADAPTER_STATE_OPERATIONAL ||
2481 pHba->status_block->iop_state == ADAPTER_STATE_HOLD ||
2482 pHba->status_block->iop_state == ADAPTER_STATE_FAILED) {
2483 adpt_i2o_reset_hba(pHba);
2484 if (adpt_i2o_status_get(pHba) < 0 || pHba->status_block->iop_state != ADAPTER_STATE_RESET) {
2485 printk(KERN_ERR "%s: Failed to initialize.\n", pHba->name);
2490 if((rcode = adpt_i2o_reset_hba(pHba)) != 0){
2491 printk(KERN_WARNING"%s: Could NOT reset.\n", pHba->name);
2497 if (adpt_i2o_init_outbound_q(pHba) < 0) {
2503 if (adpt_i2o_hrt_get(pHba) < 0) {
2511 * Bring a controller online into OPERATIONAL state.
2514 static int adpt_i2o_online_hba(adpt_hba* pHba)
2516 if (adpt_i2o_systab_send(pHba) < 0)
2518 /* In READY state */
2520 if (adpt_i2o_enable_hba(pHba) < 0)
2523 /* In OPERATIONAL state */
2527 static s32 adpt_send_nop(adpt_hba*pHba,u32 m)
2530 ulong timeout = jiffies + 5*HZ;
2532 while(m == EMPTY_QUEUE){
2534 m = readl(pHba->post_port);
2535 if(m != EMPTY_QUEUE){
2538 if(time_after(jiffies,timeout)){
2539 printk(KERN_ERR "%s: Timeout waiting for message frame!\n",pHba->name);
2542 schedule_timeout_uninterruptible(1);
2544 msg = (u32 __iomem *)(pHba->msg_addr_virt + m);
2545 writel( THREE_WORD_MSG_SIZE | SGL_OFFSET_0,&msg[0]);
2546 writel( I2O_CMD_UTIL_NOP << 24 | HOST_TID << 12 | 0,&msg[1]);
2550 writel(m, pHba->post_port);
2555 static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
2559 u32 __iomem *msg = NULL;
2561 ulong timeout = jiffies + TMOUT_INITOUTBOUND*HZ;
2566 m = readl(pHba->post_port);
2567 if (m != EMPTY_QUEUE) {
2571 if(time_after(jiffies,timeout)){
2572 printk(KERN_WARNING"%s: Timeout waiting for message frame\n",pHba->name);
2575 schedule_timeout_uninterruptible(1);
2576 } while(m == EMPTY_QUEUE);
2578 msg=(u32 __iomem *)(pHba->msg_addr_virt+m);
2580 status = dma_alloc_coherent(&pHba->pDev->dev, 4, &addr, GFP_KERNEL);
2582 adpt_send_nop(pHba, m);
2583 printk(KERN_WARNING"%s: IOP reset failed - no free memory.\n",
2587 memset(status, 0, 4);
2589 writel(EIGHT_WORD_MSG_SIZE| SGL_OFFSET_6, &msg[0]);
2590 writel(I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID, &msg[1]);
2592 writel(0x0106, &msg[3]); /* Transaction context */
2593 writel(4096, &msg[4]); /* Host page frame size */
2594 writel((REPLY_FRAME_SIZE)<<16|0x80, &msg[5]); /* Outbound msg frame size and Initcode */
2595 writel(0xD0000004, &msg[6]); /* Simple SG LE, EOB */
2596 writel((u32)addr, &msg[7]);
2598 writel(m, pHba->post_port);
2601 // Wait for the reply status to come back
2604 if (*status != 0x01 /*I2O_EXEC_OUTBOUND_INIT_IN_PROGRESS*/) {
2609 if(time_after(jiffies,timeout)){
2610 printk(KERN_WARNING"%s: Timeout Initializing\n",pHba->name);
2611 /* We lose 4 bytes of "status" here, but we
2612 cannot free these because controller may
2613 awake and corrupt those bytes at any time */
2614 /* dma_free_coherent(&pHba->pDev->dev, 4, status, addr); */
2617 schedule_timeout_uninterruptible(1);
2620 // If the command was successful, fill the fifo with our reply
2622 if(*status != 0x04 /*I2O_EXEC_OUTBOUND_INIT_COMPLETE*/) {
2623 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
2626 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
2628 if(pHba->reply_pool != NULL) {
2629 dma_free_coherent(&pHba->pDev->dev,
2630 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
2631 pHba->reply_pool, pHba->reply_pool_pa);
2634 pHba->reply_pool = dma_alloc_coherent(&pHba->pDev->dev,
2635 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
2636 &pHba->reply_pool_pa, GFP_KERNEL);
2637 if (!pHba->reply_pool) {
2638 printk(KERN_ERR "%s: Could not allocate reply pool\n", pHba->name);
2641 memset(pHba->reply_pool, 0 , pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4);
2643 for(i = 0; i < pHba->reply_fifo_size; i++) {
2644 writel(pHba->reply_pool_pa + (i * REPLY_FRAME_SIZE * 4),
2648 adpt_i2o_status_get(pHba);
2654 * I2O System Table. Contains information about
2655 * all the IOPs in the system. Used to inform IOPs
2656 * about each other's existence.
2658 * sys_tbl_ver is the CurrentChangeIndicator that is
2659 * used by IOPs to track changes.
2664 static s32 adpt_i2o_status_get(adpt_hba* pHba)
2669 u8 *status_block=NULL;
2671 if(pHba->status_block == NULL) {
2672 pHba->status_block = dma_alloc_coherent(&pHba->pDev->dev,
2673 sizeof(i2o_status_block),
2674 &pHba->status_block_pa, GFP_KERNEL);
2675 if(pHba->status_block == NULL) {
2677 "dpti%d: Get Status Block failed; Out of memory. \n",
2682 memset(pHba->status_block, 0, sizeof(i2o_status_block));
2683 status_block = (u8*)(pHba->status_block);
2684 timeout = jiffies+TMOUT_GETSTATUS*HZ;
2687 m = readl(pHba->post_port);
2688 if (m != EMPTY_QUEUE) {
2691 if(time_after(jiffies,timeout)){
2692 printk(KERN_ERR "%s: Timeout waiting for message !\n",
2696 schedule_timeout_uninterruptible(1);
2697 } while(m==EMPTY_QUEUE);
2700 msg=(u32 __iomem *)(pHba->msg_addr_virt+m);
2702 writel(NINE_WORD_MSG_SIZE|SGL_OFFSET_0, &msg[0]);
2703 writel(I2O_CMD_STATUS_GET<<24|HOST_TID<<12|ADAPTER_TID, &msg[1]);
2708 writel( dma_low(pHba->status_block_pa), &msg[6]);
2709 writel( dma_high(pHba->status_block_pa), &msg[7]);
2710 writel(sizeof(i2o_status_block), &msg[8]); // 88 bytes
2713 writel(m, pHba->post_port);
2716 while(status_block[87]!=0xff){
2717 if(time_after(jiffies,timeout)){
2718 printk(KERN_ERR"dpti%d: Get status timeout.\n",
2723 schedule_timeout_uninterruptible(1);
2726 // Set up our number of outbound and inbound messages
2727 pHba->post_fifo_size = pHba->status_block->max_inbound_frames;
2728 if (pHba->post_fifo_size > MAX_TO_IOP_MESSAGES) {
2729 pHba->post_fifo_size = MAX_TO_IOP_MESSAGES;
2732 pHba->reply_fifo_size = pHba->status_block->max_outbound_frames;
2733 if (pHba->reply_fifo_size > MAX_FROM_IOP_MESSAGES) {
2734 pHba->reply_fifo_size = MAX_FROM_IOP_MESSAGES;
2737 // Calculate the Scatter Gather list size
2738 if (dpt_dma64(pHba)) {
2740 = ((pHba->status_block->inbound_frame_size * 4
2742 / (sizeof(struct sg_simple_element) + sizeof(u32)));
2745 = ((pHba->status_block->inbound_frame_size * 4
2747 / sizeof(struct sg_simple_element));
2749 if (pHba->sg_tablesize > SG_LIST_ELEMENTS) {
2750 pHba->sg_tablesize = SG_LIST_ELEMENTS;
2755 printk("dpti%d: State = ",pHba->unit);
2756 switch(pHba->status_block->iop_state) {
2770 printk("OPERATIONAL\n");
2776 printk("FAULTED\n");
2779 printk("%x (unknown!!)\n",pHba->status_block->iop_state);
2786 * Get the IOP's Logical Configuration Table
2788 static int adpt_i2o_lct_get(adpt_hba* pHba)
2794 if ((pHba->lct_size == 0) || (pHba->lct == NULL)){
2795 pHba->lct_size = pHba->status_block->expected_lct_size;
2798 if (pHba->lct == NULL) {
2799 pHba->lct = dma_alloc_coherent(&pHba->pDev->dev,
2800 pHba->lct_size, &pHba->lct_pa,
2802 if(pHba->lct == NULL) {
2803 printk(KERN_CRIT "%s: Lct Get failed. Out of memory.\n",
2808 memset(pHba->lct, 0, pHba->lct_size);
2810 msg[0] = EIGHT_WORD_MSG_SIZE|SGL_OFFSET_6;
2811 msg[1] = I2O_CMD_LCT_NOTIFY<<24 | HOST_TID<<12 | ADAPTER_TID;
2814 msg[4] = 0xFFFFFFFF; /* All devices */
2815 msg[5] = 0x00000000; /* Report now */
2816 msg[6] = 0xD0000000|pHba->lct_size;
2817 msg[7] = (u32)pHba->lct_pa;
2819 if ((ret=adpt_i2o_post_wait(pHba, msg, sizeof(msg), 360))) {
2820 printk(KERN_ERR "%s: LCT Get failed (status=%#10x.\n",
2822 printk(KERN_ERR"Adaptec: Error Reading Hardware.\n");
2826 if ((pHba->lct->table_size << 2) > pHba->lct_size) {
2827 pHba->lct_size = pHba->lct->table_size << 2;
2828 dma_free_coherent(&pHba->pDev->dev, pHba->lct_size,
2829 pHba->lct, pHba->lct_pa);
2832 } while (pHba->lct == NULL);
2834 PDEBUG("%s: Hardware resource table read.\n", pHba->name);
2837 // I2O_DPT_EXEC_IOP_BUFFERS_GROUP_NO;
2838 if(adpt_i2o_query_scalar(pHba, 0 , 0x8000, -1, buf, sizeof(buf))>=0) {
2839 pHba->FwDebugBufferSize = buf[1];
2840 pHba->FwDebugBuffer_P = ioremap(pHba->base_addr_phys + buf[0],
2841 pHba->FwDebugBufferSize);
2842 if (pHba->FwDebugBuffer_P) {
2843 pHba->FwDebugFlags_P = pHba->FwDebugBuffer_P +
2844 FW_DEBUG_FLAGS_OFFSET;
2845 pHba->FwDebugBLEDvalue_P = pHba->FwDebugBuffer_P +
2846 FW_DEBUG_BLED_OFFSET;
2847 pHba->FwDebugBLEDflag_P = pHba->FwDebugBLEDvalue_P + 1;
2848 pHba->FwDebugStrLength_P = pHba->FwDebugBuffer_P +
2849 FW_DEBUG_STR_LENGTH_OFFSET;
2850 pHba->FwDebugBuffer_P += buf[2];
2851 pHba->FwDebugFlags = 0;
2858 static int adpt_i2o_build_sys_table(void)
2860 adpt_hba* pHba = hba_chain;
2864 dma_free_coherent(&pHba->pDev->dev, sys_tbl_len,
2865 sys_tbl, sys_tbl_pa);
2867 sys_tbl_len = sizeof(struct i2o_sys_tbl) + // Header + IOPs
2868 (hba_count) * sizeof(struct i2o_sys_tbl_entry);
2870 sys_tbl = dma_alloc_coherent(&pHba->pDev->dev,
2871 sys_tbl_len, &sys_tbl_pa, GFP_KERNEL);
2873 printk(KERN_WARNING "SysTab Set failed. Out of memory.\n");
2876 memset(sys_tbl, 0, sys_tbl_len);
2878 sys_tbl->num_entries = hba_count;
2879 sys_tbl->version = I2OVERSION;
2880 sys_tbl->change_ind = sys_tbl_ind++;
2882 for(pHba = hba_chain; pHba; pHba = pHba->next) {
2884 // Get updated Status Block so we have the latest information
2885 if (adpt_i2o_status_get(pHba)) {
2886 sys_tbl->num_entries--;
2887 continue; // try next one
2890 sys_tbl->iops[count].org_id = pHba->status_block->org_id;
2891 sys_tbl->iops[count].iop_id = pHba->unit + 2;
2892 sys_tbl->iops[count].seg_num = 0;
2893 sys_tbl->iops[count].i2o_version = pHba->status_block->i2o_version;
2894 sys_tbl->iops[count].iop_state = pHba->status_block->iop_state;
2895 sys_tbl->iops[count].msg_type = pHba->status_block->msg_type;
2896 sys_tbl->iops[count].frame_size = pHba->status_block->inbound_frame_size;
2897 sys_tbl->iops[count].last_changed = sys_tbl_ind - 1; // ??
2898 sys_tbl->iops[count].iop_capabilities = pHba->status_block->iop_capabilities;
2899 addr = pHba->base_addr_phys + 0x40;
2900 sys_tbl->iops[count].inbound_low = dma_low(addr);
2901 sys_tbl->iops[count].inbound_high = dma_high(addr);
2908 u32 *table = (u32*)sys_tbl;
2909 printk(KERN_DEBUG"sys_tbl_len=%d in 32bit words\n",(sys_tbl_len >>2));
2910 for(count = 0; count < (sys_tbl_len >>2); count++) {
2911 printk(KERN_INFO "sys_tbl[%d] = %0#10x\n",
2912 count, table[count]);
2922 * Dump the information block associated with a given unit (TID)
2925 static void adpt_i2o_report_hba_unit(adpt_hba* pHba, struct i2o_device *d)
2928 int unit = d->lct_data.tid;
2930 printk(KERN_INFO "TID %3.3d ", unit);
2932 if(adpt_i2o_query_scalar(pHba, unit, 0xF100, 3, buf, 16)>=0)
2935 printk(" Vendor: %-12.12s", buf);
2937 if(adpt_i2o_query_scalar(pHba, unit, 0xF100, 4, buf, 16)>=0)
2940 printk(" Device: %-12.12s", buf);
2942 if(adpt_i2o_query_scalar(pHba, unit, 0xF100, 6, buf, 8)>=0)
2945 printk(" Rev: %-12.12s\n", buf);
2948 printk(KERN_INFO "\tClass: %.21s\n", adpt_i2o_get_class_name(d->lct_data.class_id));
2949 printk(KERN_INFO "\tSubclass: 0x%04X\n", d->lct_data.sub_class);
2950 printk(KERN_INFO "\tFlags: ");
2952 if(d->lct_data.device_flags&(1<<0))
2953 printk("C"); // ConfigDialog requested
2954 if(d->lct_data.device_flags&(1<<1))
2955 printk("U"); // Multi-user capable
2956 if(!(d->lct_data.device_flags&(1<<4)))
2957 printk("P"); // Peer service enabled!
2958 if(!(d->lct_data.device_flags&(1<<5)))
2959 printk("M"); // Mgmt service enabled!
2966 * Do i2o class name lookup
2968 static const char *adpt_i2o_get_class_name(int class)
2971 static char *i2o_class_name[] = {
2973 "Device Driver Module",
2978 "Fibre Channel Port",
2979 "Fibre Channel Device",
2983 "Floppy Controller",
2985 "Secondary Bus Port",
2986 "Peer Transport Agent",
2991 switch(class&0xFFF) {
2992 case I2O_CLASS_EXECUTIVE:
2996 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
2998 case I2O_CLASS_SEQUENTIAL_STORAGE:
3004 case I2O_CLASS_FIBRE_CHANNEL_PORT:
3006 case I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL:
3008 case I2O_CLASS_SCSI_PERIPHERAL:
3010 case I2O_CLASS_ATE_PORT:
3012 case I2O_CLASS_ATE_PERIPHERAL:
3014 case I2O_CLASS_FLOPPY_CONTROLLER:
3016 case I2O_CLASS_FLOPPY_DEVICE:
3018 case I2O_CLASS_BUS_ADAPTER_PORT:
3020 case I2O_CLASS_PEER_TRANSPORT_AGENT:
3022 case I2O_CLASS_PEER_TRANSPORT:
3025 return i2o_class_name[idx];
3030 static s32 adpt_i2o_hrt_get(adpt_hba* pHba)
3033 int ret, size = sizeof(i2o_hrt);
3036 if (pHba->hrt == NULL) {
3037 pHba->hrt = dma_alloc_coherent(&pHba->pDev->dev,
3038 size, &pHba->hrt_pa, GFP_KERNEL);
3039 if (pHba->hrt == NULL) {
3040 printk(KERN_CRIT "%s: Hrt Get failed; Out of memory.\n", pHba->name);
3045 msg[0]= SIX_WORD_MSG_SIZE| SGL_OFFSET_4;
3046 msg[1]= I2O_CMD_HRT_GET<<24 | HOST_TID<<12 | ADAPTER_TID;
3049 msg[4]= (0xD0000000 | size); /* Simple transaction */
3050 msg[5]= (u32)pHba->hrt_pa; /* Dump it here */
3052 if ((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg),20))) {
3053 printk(KERN_ERR "%s: Unable to get HRT (status=%#10x)\n", pHba->name, ret);
3057 if (pHba->hrt->num_entries * pHba->hrt->entry_len << 2 > size) {
3058 int newsize = pHba->hrt->num_entries * pHba->hrt->entry_len << 2;
3059 dma_free_coherent(&pHba->pDev->dev, size,
3060 pHba->hrt, pHba->hrt_pa);
3064 } while(pHba->hrt == NULL);
3069 * Query one scalar group value or a whole scalar group.
3071 static int adpt_i2o_query_scalar(adpt_hba* pHba, int tid,
3072 int group, int field, void *buf, int buflen)
3074 u16 opblk[] = { 1, 0, I2O_PARAMS_FIELD_GET, group, 1, field };
3076 dma_addr_t opblk_pa;
3078 dma_addr_t resblk_pa;
3082 /* 8 bytes for header */
3083 resblk_va = dma_alloc_coherent(&pHba->pDev->dev,
3084 sizeof(u8) * (8 + buflen), &resblk_pa, GFP_KERNEL);
3085 if (resblk_va == NULL) {
3086 printk(KERN_CRIT "%s: query scalar failed; Out of memory.\n", pHba->name);
3090 opblk_va = dma_alloc_coherent(&pHba->pDev->dev,
3091 sizeof(opblk), &opblk_pa, GFP_KERNEL);
3092 if (opblk_va == NULL) {
3093 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3094 resblk_va, resblk_pa);
3095 printk(KERN_CRIT "%s: query operation failed; Out of memory.\n",
3099 if (field == -1) /* whole group */
3102 memcpy(opblk_va, opblk, sizeof(opblk));
3103 size = adpt_i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET, pHba, tid,
3104 opblk_va, opblk_pa, sizeof(opblk),
3105 resblk_va, resblk_pa, sizeof(u8)*(8+buflen));
3106 dma_free_coherent(&pHba->pDev->dev, sizeof(opblk), opblk_va, opblk_pa);
3107 if (size == -ETIME) {
3108 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3109 resblk_va, resblk_pa);
3110 printk(KERN_WARNING "%s: issue params failed; Timed out.\n", pHba->name);
3112 } else if (size == -EINTR) {
3113 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3114 resblk_va, resblk_pa);
3115 printk(KERN_WARNING "%s: issue params failed; Interrupted.\n", pHba->name);
3119 memcpy(buf, resblk_va+8, buflen); /* cut off header */
3121 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3122 resblk_va, resblk_pa);
3130 /* Issue UTIL_PARAMS_GET or UTIL_PARAMS_SET
3132 * This function can be used for all UtilParamsGet/Set operations.
3133 * The OperationBlock is given in opblk-buffer,
3134 * and results are returned in resblk-buffer.
3135 * Note that the minimum sized resblk is 8 bytes and contains
3136 * ResultCount, ErrorInfoSize, BlockStatus and BlockSize.
3138 static int adpt_i2o_issue_params(int cmd, adpt_hba* pHba, int tid,
3139 void *opblk_va, dma_addr_t opblk_pa, int oplen,
3140 void *resblk_va, dma_addr_t resblk_pa, int reslen)
3143 u32 *res = (u32 *)resblk_va;
3146 msg[0] = NINE_WORD_MSG_SIZE | SGL_OFFSET_5;
3147 msg[1] = cmd << 24 | HOST_TID << 12 | tid;
3151 msg[5] = 0x54000000 | oplen; /* OperationBlock */
3152 msg[6] = (u32)opblk_pa;
3153 msg[7] = 0xD0000000 | reslen; /* ResultBlock */
3154 msg[8] = (u32)resblk_pa;
3156 if ((wait_status = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 20))) {
3157 printk("adpt_i2o_issue_params: post_wait failed (%p)\n", resblk_va);
3158 return wait_status; /* -DetailedStatus */
3161 if (res[1]&0x00FF0000) { /* BlockStatus != SUCCESS */
3162 printk(KERN_WARNING "%s: %s - Error:\n ErrorInfoSize = 0x%02x, "
3163 "BlockStatus = 0x%02x, BlockSize = 0x%04x\n",
3165 (cmd == I2O_CMD_UTIL_PARAMS_SET) ? "PARAMS_SET"
3167 res[1]>>24, (res[1]>>16)&0xFF, res[1]&0xFFFF);
3168 return -((res[1] >> 16) & 0xFF); /* -BlockStatus */
3171 return 4 + ((res[1] & 0x0000FFFF) << 2); /* bytes used in resblk */
3175 static s32 adpt_i2o_quiesce_hba(adpt_hba* pHba)
3180 adpt_i2o_status_get(pHba);
3182 /* SysQuiesce discarded if IOP not in READY or OPERATIONAL state */
3184 if((pHba->status_block->iop_state != ADAPTER_STATE_READY) &&
3185 (pHba->status_block->iop_state != ADAPTER_STATE_OPERATIONAL)){
3189 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
3190 msg[1] = I2O_CMD_SYS_QUIESCE<<24|HOST_TID<<12|ADAPTER_TID;
3194 if((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 240))) {
3195 printk(KERN_INFO"dpti%d: Unable to quiesce (status=%#x).\n",
3198 printk(KERN_INFO"dpti%d: Quiesced.\n",pHba->unit);
3201 adpt_i2o_status_get(pHba);
3207 * Enable IOP. Allows the IOP to resume external operations.
3209 static int adpt_i2o_enable_hba(adpt_hba* pHba)
3214 adpt_i2o_status_get(pHba);
3215 if(!pHba->status_block){
3218 /* Enable only allowed on READY state */
3219 if(pHba->status_block->iop_state == ADAPTER_STATE_OPERATIONAL)
3222 if(pHba->status_block->iop_state != ADAPTER_STATE_READY)
3225 msg[0]=FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
3226 msg[1]=I2O_CMD_SYS_ENABLE<<24|HOST_TID<<12|ADAPTER_TID;
3230 if ((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 240))) {
3231 printk(KERN_WARNING"%s: Could not enable (status=%#10x).\n",
3234 PDEBUG("%s: Enabled.\n", pHba->name);
3237 adpt_i2o_status_get(pHba);
3242 static int adpt_i2o_systab_send(adpt_hba* pHba)
3247 msg[0] = I2O_MESSAGE_SIZE(12) | SGL_OFFSET_6;
3248 msg[1] = I2O_CMD_SYS_TAB_SET<<24 | HOST_TID<<12 | ADAPTER_TID;
3251 msg[4] = (0<<16) | ((pHba->unit+2) << 12); /* Host 0 IOP ID (unit + 2) */
3252 msg[5] = 0; /* Segment 0 */
3255 * Provide three SGL-elements:
3256 * System table (SysTab), Private memory space declaration and
3257 * Private i/o space declaration
3259 msg[6] = 0x54000000 | sys_tbl_len;
3260 msg[7] = (u32)sys_tbl_pa;
3261 msg[8] = 0x54000000 | 0;
3263 msg[10] = 0xD4000000 | 0;
3266 if ((ret=adpt_i2o_post_wait(pHba, msg, sizeof(msg), 120))) {
3267 printk(KERN_INFO "%s: Unable to set SysTab (status=%#10x).\n",
3272 PINFO("%s: SysTab set.\n", pHba->name);
3280 /*============================================================================
3282 *============================================================================
3288 static static void adpt_delay(int millisec)
3291 for (i = 0; i < millisec; i++) {
3292 udelay(1000); /* delay for one millisecond */
3298 static struct scsi_host_template driver_template = {
3299 .module = THIS_MODULE,
3301 .proc_name = "dpt_i2o",
3302 .show_info = adpt_show_info,
3304 .queuecommand = adpt_queue,
3305 .eh_abort_handler = adpt_abort,
3306 .eh_device_reset_handler = adpt_device_reset,
3307 .eh_bus_reset_handler = adpt_bus_reset,
3308 .eh_host_reset_handler = adpt_reset,
3309 .bios_param = adpt_bios_param,
3310 .slave_configure = adpt_slave_configure,
3311 .can_queue = MAX_TO_IOP_MESSAGES,
3313 .use_clustering = ENABLE_CLUSTERING,
3316 static int __init adpt_init(void)
3319 adpt_hba *pHba, *next;
3321 printk("Loading Adaptec I2O RAID: Version " DPT_I2O_VERSION "\n");
3323 error = adpt_detect(&driver_template);
3326 if (hba_chain == NULL)
3329 for (pHba = hba_chain; pHba; pHba = pHba->next) {
3330 error = scsi_add_host(pHba->host, &pHba->pDev->dev);
3333 scsi_scan_host(pHba->host);
3337 for (pHba = hba_chain; pHba; pHba = next) {
3339 scsi_remove_host(pHba->host);
3344 static void __exit adpt_exit(void)
3346 adpt_hba *pHba, *next;
3348 for (pHba = hba_chain; pHba; pHba = next) {
3354 module_init(adpt_init);
3355 module_exit(adpt_exit);
3357 MODULE_LICENSE("GPL");