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 <asm/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>
62 #include <asm/io.h> /* for virt_to_bus, etc. */
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 dpt_sig_S DPTI_sig = {
79 {'d', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION,
81 PROC_INTEL, PROC_386 | PROC_486 | PROC_PENTIUM | PROC_SEXIUM,
82 #elif defined(__ia64__)
83 PROC_INTEL, PROC_IA64,
84 #elif defined(__sparc__)
85 PROC_ULTRASPARC, PROC_ULTRASPARC,
86 #elif defined(__alpha__)
87 PROC_ALPHA, PROC_ALPHA,
91 FT_HBADRVR, 0, OEM_DPT, OS_LINUX, CAP_OVERLAP, DEV_ALL,
92 ADF_ALL_SC5, 0, 0, DPT_VERSION, DPT_REVISION, DPT_SUBREVISION,
93 DPT_MONTH, DPT_DAY, DPT_YEAR, "Adaptec Linux I2O RAID Driver"
99 /*============================================================================
101 *============================================================================
104 static DEFINE_MUTEX(adpt_configuration_lock);
106 static struct i2o_sys_tbl *sys_tbl;
107 static dma_addr_t sys_tbl_pa;
108 static int sys_tbl_ind;
109 static int sys_tbl_len;
111 static adpt_hba* hba_chain = NULL;
112 static int hba_count = 0;
114 static const struct file_operations adpt_fops = {
117 .release = adpt_close
120 /* Structures and definitions for synchronous message posting.
121 * See adpt_i2o_post_wait() for description
123 struct adpt_i2o_post_wait_data
127 adpt_wait_queue_head_t *wq;
128 struct adpt_i2o_post_wait_data *next;
131 static struct adpt_i2o_post_wait_data *adpt_post_wait_queue = NULL;
132 static u32 adpt_post_wait_id = 0;
133 static DEFINE_SPINLOCK(adpt_post_wait_lock);
136 /*============================================================================
138 *============================================================================
141 static inline u32 dma_high(dma_addr_t addr)
143 return upper_32_bits(addr);
146 static inline u32 dma_low(dma_addr_t addr)
151 static u8 adpt_read_blink_led(adpt_hba* host)
153 if(host->FwDebugBLEDflag_P != 0) {
154 if( readb(host->FwDebugBLEDflag_P) == 0xbc ){
155 return readb(host->FwDebugBLEDvalue_P);
161 /*============================================================================
162 * Scsi host template interface functions
163 *============================================================================
166 static struct pci_device_id dptids[] = {
167 { PCI_DPT_VENDOR_ID, PCI_DPT_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
168 { PCI_DPT_VENDOR_ID, PCI_DPT_RAPTOR_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
171 MODULE_DEVICE_TABLE(pci,dptids);
173 static int adpt_detect(struct scsi_host_template* sht)
175 struct pci_dev *pDev = NULL;
178 PINFO("Detecting Adaptec I2O RAID controllers...\n");
180 /* search for all Adatpec I2O RAID cards */
181 while ((pDev = pci_get_device( PCI_DPT_VENDOR_ID, PCI_ANY_ID, pDev))) {
182 if(pDev->device == PCI_DPT_DEVICE_ID ||
183 pDev->device == PCI_DPT_RAPTOR_DEVICE_ID){
184 if(adpt_install_hba(sht, pDev) ){
185 PERROR("Could not Init an I2O RAID device\n");
186 PERROR("Will not try to detect others.\n");
193 /* In INIT state, Activate IOPs */
194 for (pHba = hba_chain; pHba; pHba = pHba->next) {
195 // Activate does get status , init outbound, and get hrt
196 if (adpt_i2o_activate_hba(pHba) < 0) {
197 adpt_i2o_delete_hba(pHba);
202 /* Active IOPs in HOLD state */
205 if (hba_chain == NULL)
209 * If build_sys_table fails, we kill everything and bail
210 * as we can't init the IOPs w/o a system table
212 if (adpt_i2o_build_sys_table() < 0) {
213 adpt_i2o_sys_shutdown();
217 PDEBUG("HBA's in HOLD state\n");
219 /* If IOP don't get online, we need to rebuild the System table */
220 for (pHba = hba_chain; pHba; pHba = pHba->next) {
221 if (adpt_i2o_online_hba(pHba) < 0) {
222 adpt_i2o_delete_hba(pHba);
223 goto rebuild_sys_tab;
227 /* Active IOPs now in OPERATIONAL state */
228 PDEBUG("HBA's in OPERATIONAL state\n");
230 printk("dpti: If you have a lot of devices this could take a few minutes.\n");
231 for (pHba = hba_chain; pHba; pHba = pHba->next) {
232 printk(KERN_INFO"%s: Reading the hardware resource table.\n", pHba->name);
233 if (adpt_i2o_lct_get(pHba) < 0){
234 adpt_i2o_delete_hba(pHba);
238 if (adpt_i2o_parse_lct(pHba) < 0){
239 adpt_i2o_delete_hba(pHba);
245 for (pHba = hba_chain; pHba; pHba = pHba->next) {
246 if (adpt_scsi_host_alloc(pHba, sht) < 0){
247 adpt_i2o_delete_hba(pHba);
250 pHba->initialized = TRUE;
251 pHba->state &= ~DPTI_STATE_RESET;
254 // Register our control device node
255 // nodes will need to be created in /dev to access this
256 // the nodes can not be created from within the driver
257 if (hba_count && register_chrdev(DPTI_I2O_MAJOR, DPT_DRIVER, &adpt_fops)) {
258 adpt_i2o_sys_shutdown();
266 * scsi_unregister will be called AFTER we return.
268 static int adpt_release(struct Scsi_Host *host)
270 adpt_hba* pHba = (adpt_hba*) host->hostdata[0];
271 // adpt_i2o_quiesce_hba(pHba);
272 adpt_i2o_delete_hba(pHba);
273 scsi_unregister(host);
278 static void adpt_inquiry(adpt_hba* pHba)
292 memset(msg, 0, sizeof(msg));
293 buf = dma_alloc_coherent(&pHba->pDev->dev, 80, &addr, GFP_KERNEL);
295 printk(KERN_ERR"%s: Could not allocate buffer\n",pHba->name);
298 memset((void*)buf, 0, 36);
301 direction = 0x00000000;
302 scsidir =0x40000000; // DATA IN (iop<--dev)
304 reqlen = 14; // SINGLE SGE
305 /* Stick the headers on */
306 msg[0] = reqlen<<16 | SGL_OFFSET_12;
307 msg[1] = (0xff<<24|HOST_TID<<12|ADAPTER_TID);
310 // Adaptec/DPT Private stuff
311 msg[4] = I2O_CMD_SCSI_EXEC|DPT_ORGANIZATION_ID<<16;
312 msg[5] = ADAPTER_TID | 1<<16 /* Interpret*/;
313 /* Direction, disconnect ok | sense data | simple queue , CDBLen */
314 // I2O_SCB_FLAG_ENABLE_DISCONNECT |
315 // I2O_SCB_FLAG_SIMPLE_QUEUE_TAG |
316 // I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
317 msg[6] = scsidir|0x20a00000| 6 /* cmd len*/;
321 memset(scb, 0, sizeof(scb));
322 // Write SCSI command into the message - always 16 byte block
329 // Don't care about the rest of scb
331 memcpy(mptr, scb, sizeof(scb));
333 lenptr=mptr++; /* Remember me - fill in when we know */
335 /* Now fill in the SGList and command */
337 *mptr++ = 0xD0000000|direction|len;
340 // Send it on it's way
341 rcode = adpt_i2o_post_wait(pHba, msg, reqlen<<2, 120);
343 sprintf(pHba->detail, "Adaptec I2O RAID");
344 printk(KERN_INFO "%s: Inquiry Error (%d)\n",pHba->name,rcode);
345 if (rcode != -ETIME && rcode != -EINTR)
346 dma_free_coherent(&pHba->pDev->dev, 80, buf, addr);
348 memset(pHba->detail, 0, sizeof(pHba->detail));
349 memcpy(&(pHba->detail), "Vendor: Adaptec ", 16);
350 memcpy(&(pHba->detail[16]), " Model: ", 8);
351 memcpy(&(pHba->detail[24]), (u8*) &buf[16], 16);
352 memcpy(&(pHba->detail[40]), " FW: ", 4);
353 memcpy(&(pHba->detail[44]), (u8*) &buf[32], 4);
354 pHba->detail[48] = '\0'; /* precautionary */
355 dma_free_coherent(&pHba->pDev->dev, 80, buf, addr);
357 adpt_i2o_status_get(pHba);
362 static int adpt_slave_configure(struct scsi_device * device)
364 struct Scsi_Host *host = device->host;
367 pHba = (adpt_hba *) host->hostdata[0];
369 if (host->can_queue && device->tagged_supported) {
370 scsi_adjust_queue_depth(device, MSG_SIMPLE_TAG,
371 host->can_queue - 1);
373 scsi_adjust_queue_depth(device, 0, 1);
378 static int adpt_queue(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *))
380 adpt_hba* pHba = NULL;
381 struct adpt_device* pDev = NULL; /* dpt per device information */
383 cmd->scsi_done = done;
385 * SCSI REQUEST_SENSE commands will be executed automatically by the
386 * Host Adapter for any errors, so they should not be executed
387 * explicitly unless the Sense Data is zero indicating that no error
391 if ((cmd->cmnd[0] == REQUEST_SENSE) && (cmd->sense_buffer[0] != 0)) {
392 cmd->result = (DID_OK << 16);
397 pHba = (adpt_hba*)cmd->device->host->hostdata[0];
404 * TODO: I need to block here if I am processing ioctl cmds
405 * but if the outstanding cmds all finish before the ioctl,
406 * the scsi-core will not know to start sending cmds to me again.
407 * I need to a way to restart the scsi-cores queues or should I block
408 * calling scsi_done on the outstanding cmds instead
409 * for now we don't set the IOCTL state
411 if(((pHba->state) & DPTI_STATE_IOCTL) || ((pHba->state) & DPTI_STATE_RESET)) {
412 pHba->host->last_reset = jiffies;
413 pHba->host->resetting = 1;
417 // TODO if the cmd->device if offline then I may need to issue a bus rescan
418 // followed by a get_lct to see if the device is there anymore
419 if((pDev = (struct adpt_device*) (cmd->device->hostdata)) == NULL) {
421 * First command request for this device. Set up a pointer
422 * to the device structure. This should be a TEST_UNIT_READY
423 * command from scan_scsis_single.
425 if ((pDev = adpt_find_device(pHba, (u32)cmd->device->channel, (u32)cmd->device->id, (u32)cmd->device->lun)) == NULL) {
426 // TODO: if any luns are at this bus, scsi id then fake a TEST_UNIT_READY and INQUIRY response
427 // with type 7F (for all luns less than the max for this bus,id) so the lun scan will continue.
428 cmd->result = (DID_NO_CONNECT << 16);
432 cmd->device->hostdata = pDev;
434 pDev->pScsi_dev = cmd->device;
437 * If we are being called from when the device is being reset,
438 * delay processing of the command until later.
440 if (pDev->state & DPTI_DEV_RESET ) {
443 return adpt_scsi_to_i2o(pHba, cmd, pDev);
446 static int adpt_bios_param(struct scsi_device *sdev, struct block_device *dev,
447 sector_t capacity, int geom[])
453 // *** First lets set the default geometry ****
455 // If the capacity is less than ox2000
456 if (capacity < 0x2000 ) { // floppy
460 // else if between 0x2000 and 0x20000
461 else if (capacity < 0x20000) {
465 // else if between 0x20000 and 0x40000
466 else if (capacity < 0x40000) {
470 // else if between 0x4000 and 0x80000
471 else if (capacity < 0x80000) {
475 // else if greater than 0x80000
480 cylinders = sector_div(capacity, heads * sectors);
482 // Special case if CDROM
483 if(sdev->type == 5) { // CDROM
493 PDEBUG("adpt_bios_param: exit\n");
498 static const char *adpt_info(struct Scsi_Host *host)
502 pHba = (adpt_hba *) host->hostdata[0];
503 return (char *) (pHba->detail);
506 static int adpt_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
507 int length, int inout)
509 struct adpt_device* d;
521 * The user has done a write and wants us to take the
522 * data in the buffer and do something with it.
523 * proc_scsiwrite calls us with inout = 1
525 * Read data from buffer (writing to us) - NOT SUPPORTED
531 * inout = 0 means the user has done a read and wants information
532 * returned, so we write information about the cards into the buffer
533 * proc_scsiread() calls us with inout = 0
536 // Find HBA (host bus adapter) we are looking for
537 mutex_lock(&adpt_configuration_lock);
538 for (pHba = hba_chain; pHba; pHba = pHba->next) {
539 if (pHba->host == host) {
540 break; /* found adapter */
543 mutex_unlock(&adpt_configuration_lock);
549 len = sprintf(buffer , "Adaptec I2O RAID Driver Version: %s\n\n", DPT_I2O_VERSION);
550 len += sprintf(buffer+len, "%s\n", pHba->detail);
551 len += sprintf(buffer+len, "SCSI Host=scsi%d Control Node=/dev/%s irq=%d\n",
552 pHba->host->host_no, pHba->name, host->irq);
553 len += sprintf(buffer+len, "\tpost fifo size = %d\n\treply fifo size = %d\n\tsg table size = %d\n\n",
554 host->can_queue, (int) pHba->reply_fifo_size , host->sg_tablesize);
559 if(pos > offset + length) {
564 * If we haven't even written to where we last left
565 * off (the last time we were called), reset the
571 len += sprintf(buffer+len, "Devices:\n");
572 for(chan = 0; chan < MAX_CHANNEL; chan++) {
573 for(id = 0; id < MAX_ID; id++) {
574 d = pHba->channel[chan].device[id];
576 len += sprintf(buffer+len,"\t%-24.24s", d->pScsi_dev->vendor);
577 len += sprintf(buffer+len," Rev: %-8.8s\n", d->pScsi_dev->rev);
582 if(pos > offset + length) {
590 unit = d->pI2o_dev->lct_data.tid;
591 len += sprintf(buffer+len, "\tTID=%d, (Channel=%d, Target=%d, Lun=%d) (%s)\n\n",
592 unit, (int)d->scsi_channel, (int)d->scsi_id, (int)d->scsi_lun,
593 scsi_device_online(d->pScsi_dev)? "online":"offline");
597 if(pos > offset + length) {
611 * begin is where we last checked our position with regards to offset
612 * begin is always less than offset. len is relative to begin. It
613 * is the number of bytes written past begin
617 /* stop the output and calculate the correct length */
618 *(buffer + len) = '\0';
620 *start = buffer + (offset - begin); /* Start of wanted data */
621 len -= (offset - begin);
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 cmd=%ld\n",pHba->name, cmd->serial_number);
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;
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 cmd=%ld failed.\n",pHba->name, cmd->serial_number);
672 printk(KERN_INFO"%s: Abort cmd=%ld complete.\n",pHba->name, cmd->serial_number);
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)
757 pHba = (adpt_hba*)cmd->device->host->hostdata[0];
758 printk(KERN_WARNING"%s: Hba Reset: scsi id %d: tid: %d\n",pHba->name,cmd->device->channel,pHba->channel[cmd->device->channel].tid );
759 rcode = adpt_hba_reset(pHba);
761 printk(KERN_WARNING"%s: HBA reset complete\n",pHba->name);
764 printk(KERN_WARNING"%s: HBA reset failed (%x)\n",pHba->name, rcode);
769 static int adpt_reset(struct scsi_cmnd* cmd)
773 spin_lock_irq(cmd->device->host->host_lock);
774 rc = __adpt_reset(cmd);
775 spin_unlock_irq(cmd->device->host->host_lock);
780 // This version of reset is called by the ioctls and indirectly from eh_error_handler via adpt_reset
781 static int adpt_hba_reset(adpt_hba* pHba)
785 pHba->state |= DPTI_STATE_RESET;
787 // Activate does get status , init outbound, and get hrt
788 if ((rcode=adpt_i2o_activate_hba(pHba)) < 0) {
789 printk(KERN_ERR "%s: Could not activate\n", pHba->name);
790 adpt_i2o_delete_hba(pHba);
794 if ((rcode=adpt_i2o_build_sys_table()) < 0) {
795 adpt_i2o_delete_hba(pHba);
798 PDEBUG("%s: in HOLD state\n",pHba->name);
800 if ((rcode=adpt_i2o_online_hba(pHba)) < 0) {
801 adpt_i2o_delete_hba(pHba);
804 PDEBUG("%s: in OPERATIONAL state\n",pHba->name);
806 if ((rcode=adpt_i2o_lct_get(pHba)) < 0){
807 adpt_i2o_delete_hba(pHba);
811 if ((rcode=adpt_i2o_reparse_lct(pHba)) < 0){
812 adpt_i2o_delete_hba(pHba);
815 pHba->state &= ~DPTI_STATE_RESET;
817 adpt_fail_posted_scbs(pHba);
818 return 0; /* return success */
821 /*===========================================================================
823 *===========================================================================
827 static void adpt_i2o_sys_shutdown(void)
829 adpt_hba *pHba, *pNext;
830 struct adpt_i2o_post_wait_data *p1, *old;
832 printk(KERN_INFO"Shutting down Adaptec I2O controllers.\n");
833 printk(KERN_INFO" This could take a few minutes if there are many devices attached\n");
834 /* Delete all IOPs from the controller chain */
835 /* They should have already been released by the
838 for (pHba = hba_chain; pHba; pHba = pNext) {
840 adpt_i2o_delete_hba(pHba);
843 /* Remove any timedout entries from the wait queue. */
844 // spin_lock_irqsave(&adpt_post_wait_lock, flags);
845 /* Nothing should be outstanding at this point so just
848 for(p1 = adpt_post_wait_queue; p1;) {
853 // spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
854 adpt_post_wait_queue = NULL;
856 printk(KERN_INFO "Adaptec I2O controllers down.\n");
859 static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev)
862 adpt_hba* pHba = NULL;
864 ulong base_addr0_phys = 0;
865 ulong base_addr1_phys = 0;
866 u32 hba_map0_area_size = 0;
867 u32 hba_map1_area_size = 0;
868 void __iomem *base_addr_virt = NULL;
869 void __iomem *msg_addr_virt = NULL;
871 int raptorFlag = FALSE;
873 if(pci_enable_device(pDev)) {
877 if (pci_request_regions(pDev, "dpt_i2o")) {
878 PERROR("dpti: adpt_config_hba: pci request region failed\n");
882 pci_set_master(pDev);
883 if (pci_set_dma_mask(pDev, DMA_32BIT_MASK))
886 /* adapter only supports message blocks below 4GB */
887 pci_set_consistent_dma_mask(pDev, DMA_32BIT_MASK);
889 base_addr0_phys = pci_resource_start(pDev,0);
890 hba_map0_area_size = pci_resource_len(pDev,0);
892 // Check if standard PCI card or single BAR Raptor
893 if(pDev->device == PCI_DPT_DEVICE_ID){
894 if(pDev->subsystem_device >=0xc032 && pDev->subsystem_device <= 0xc03b){
895 // Raptor card with this device id needs 4M
896 hba_map0_area_size = 0x400000;
897 } else { // Not Raptor - it is a PCI card
898 if(hba_map0_area_size > 0x100000 ){
899 hba_map0_area_size = 0x100000;
902 } else {// Raptor split BAR config
903 // Use BAR1 in this configuration
904 base_addr1_phys = pci_resource_start(pDev,1);
905 hba_map1_area_size = pci_resource_len(pDev,1);
909 base_addr_virt = ioremap(base_addr0_phys,hba_map0_area_size);
910 if (!base_addr_virt) {
911 pci_release_regions(pDev);
912 PERROR("dpti: adpt_config_hba: io remap failed\n");
916 if(raptorFlag == TRUE) {
917 msg_addr_virt = ioremap(base_addr1_phys, hba_map1_area_size );
918 if (!msg_addr_virt) {
919 PERROR("dpti: adpt_config_hba: io remap failed on BAR1\n");
920 iounmap(base_addr_virt);
921 pci_release_regions(pDev);
925 msg_addr_virt = base_addr_virt;
928 // Allocate and zero the data structure
929 pHba = kzalloc(sizeof(adpt_hba), GFP_KERNEL);
931 if (msg_addr_virt != base_addr_virt)
932 iounmap(msg_addr_virt);
933 iounmap(base_addr_virt);
934 pci_release_regions(pDev);
938 mutex_lock(&adpt_configuration_lock);
940 if(hba_chain != NULL){
941 for(p = hba_chain; p->next; p = p->next);
947 pHba->unit = hba_count;
948 sprintf(pHba->name, "dpti%d", hba_count);
951 mutex_unlock(&adpt_configuration_lock);
954 pHba->base_addr_phys = base_addr0_phys;
956 // Set up the Virtual Base Address of the I2O Device
957 pHba->base_addr_virt = base_addr_virt;
958 pHba->msg_addr_virt = msg_addr_virt;
959 pHba->irq_mask = base_addr_virt+0x30;
960 pHba->post_port = base_addr_virt+0x40;
961 pHba->reply_port = base_addr_virt+0x44;
966 pHba->status_block = NULL;
967 pHba->post_count = 0;
968 pHba->state = DPTI_STATE_RESET;
970 pHba->devices = NULL;
972 // Initializing the spinlocks
973 spin_lock_init(&pHba->state_lock);
974 spin_lock_init(&adpt_post_wait_lock);
977 printk(KERN_INFO"Adaptec I2O RAID controller %d at %p size=%x irq=%d\n",
978 hba_count-1, base_addr_virt, hba_map0_area_size, pDev->irq);
980 printk(KERN_INFO"Adaptec I2O RAID controller %d irq=%d\n",hba_count-1, pDev->irq);
981 printk(KERN_INFO" BAR0 %p - size= %x\n",base_addr_virt,hba_map0_area_size);
982 printk(KERN_INFO" BAR1 %p - size= %x\n",msg_addr_virt,hba_map1_area_size);
985 if (request_irq (pDev->irq, adpt_isr, IRQF_SHARED, pHba->name, pHba)) {
986 printk(KERN_ERR"%s: Couldn't register IRQ %d\n", pHba->name, pDev->irq);
987 adpt_i2o_delete_hba(pHba);
995 static void adpt_i2o_delete_hba(adpt_hba* pHba)
999 struct i2o_device* d;
1000 struct i2o_device* next;
1003 struct adpt_device* pDev;
1004 struct adpt_device* pNext;
1007 mutex_lock(&adpt_configuration_lock);
1008 // scsi_unregister calls our adpt_release which
1011 free_irq(pHba->host->irq, pHba);
1014 for( p1 = hba_chain; p1; p2 = p1,p1=p1->next){
1017 p2->next = p1->next;
1019 hba_chain = p1->next;
1026 mutex_unlock(&adpt_configuration_lock);
1028 iounmap(pHba->base_addr_virt);
1029 pci_release_regions(pHba->pDev);
1030 if(pHba->msg_addr_virt != pHba->base_addr_virt){
1031 iounmap(pHba->msg_addr_virt);
1034 dma_free_coherent(&pHba->pDev->dev,
1035 pHba->hrt->num_entries * pHba->hrt->entry_len << 2,
1036 pHba->hrt, pHba->hrt_pa);
1039 dma_free_coherent(&pHba->pDev->dev, pHba->lct_size,
1040 pHba->lct, pHba->lct_pa);
1042 if(pHba->status_block) {
1043 dma_free_coherent(&pHba->pDev->dev, sizeof(i2o_status_block),
1044 pHba->status_block, pHba->status_block_pa);
1046 if(pHba->reply_pool) {
1047 dma_free_coherent(&pHba->pDev->dev,
1048 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
1049 pHba->reply_pool, pHba->reply_pool_pa);
1052 for(d = pHba->devices; d ; d = next){
1056 for(i = 0 ; i < pHba->top_scsi_channel ; i++){
1057 for(j = 0; j < MAX_ID; j++){
1058 if(pHba->channel[i].device[j] != NULL){
1059 for(pDev = pHba->channel[i].device[j]; pDev; pDev = pNext){
1060 pNext = pDev->next_lun;
1066 pci_dev_put(pHba->pDev);
1070 unregister_chrdev(DPTI_I2O_MAJOR, DPT_DRIVER);
1074 static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u32 lun)
1076 struct adpt_device* d;
1078 if(chan < 0 || chan >= MAX_CHANNEL)
1081 if( pHba->channel[chan].device == NULL){
1082 printk(KERN_DEBUG"Adaptec I2O RAID: Trying to find device before they are allocated\n");
1086 d = pHba->channel[chan].device[id];
1087 if(!d || d->tid == 0) {
1091 /* If it is the only lun at that address then this should match*/
1092 if(d->scsi_lun == lun){
1096 /* else we need to look through all the luns */
1097 for(d=d->next_lun ; d ; d = d->next_lun){
1098 if(d->scsi_lun == lun){
1106 static int adpt_i2o_post_wait(adpt_hba* pHba, u32* msg, int len, int timeout)
1108 // I used my own version of the WAIT_QUEUE_HEAD
1109 // to handle some version differences
1110 // When embedded in the kernel this could go back to the vanilla one
1111 ADPT_DECLARE_WAIT_QUEUE_HEAD(adpt_wq_i2o_post);
1114 struct adpt_i2o_post_wait_data *p1, *p2;
1115 struct adpt_i2o_post_wait_data *wait_data =
1116 kmalloc(sizeof(struct adpt_i2o_post_wait_data),GFP_KERNEL);
1117 DECLARE_WAITQUEUE(wait, current);
1123 * The spin locking is needed to keep anyone from playing
1124 * with the queue pointers and id while we do the same
1126 spin_lock_irqsave(&adpt_post_wait_lock, flags);
1127 // TODO we need a MORE unique way of getting ids
1128 // to support async LCT get
1129 wait_data->next = adpt_post_wait_queue;
1130 adpt_post_wait_queue = wait_data;
1131 adpt_post_wait_id++;
1132 adpt_post_wait_id &= 0x7fff;
1133 wait_data->id = adpt_post_wait_id;
1134 spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
1136 wait_data->wq = &adpt_wq_i2o_post;
1137 wait_data->status = -ETIMEDOUT;
1139 add_wait_queue(&adpt_wq_i2o_post, &wait);
1141 msg[2] |= 0x80000000 | ((u32)wait_data->id);
1143 if((status = adpt_i2o_post_this(pHba, msg, len)) == 0){
1144 set_current_state(TASK_INTERRUPTIBLE);
1146 spin_unlock_irq(pHba->host->host_lock);
1150 timeout = schedule_timeout(timeout);
1152 // I/O issued, but cannot get result in
1153 // specified time. Freeing resorces is
1159 spin_lock_irq(pHba->host->host_lock);
1161 remove_wait_queue(&adpt_wq_i2o_post, &wait);
1163 if(status == -ETIMEDOUT){
1164 printk(KERN_INFO"dpti%d: POST WAIT TIMEOUT\n",pHba->unit);
1165 // We will have to free the wait_data memory during shutdown
1169 /* Remove the entry from the queue. */
1171 spin_lock_irqsave(&adpt_post_wait_lock, flags);
1172 for(p1 = adpt_post_wait_queue; p1; p2 = p1, p1 = p1->next) {
1173 if(p1 == wait_data) {
1174 if(p1->status == I2O_DETAIL_STATUS_UNSUPPORTED_FUNCTION ) {
1175 status = -EOPNOTSUPP;
1178 p2->next = p1->next;
1180 adpt_post_wait_queue = p1->next;
1185 spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
1193 static s32 adpt_i2o_post_this(adpt_hba* pHba, u32* data, int len)
1196 u32 m = EMPTY_QUEUE;
1198 ulong timeout = jiffies + 30*HZ;
1201 m = readl(pHba->post_port);
1202 if (m != EMPTY_QUEUE) {
1205 if(time_after(jiffies,timeout)){
1206 printk(KERN_WARNING"dpti%d: Timeout waiting for message frame!\n", pHba->unit);
1209 schedule_timeout_uninterruptible(1);
1210 } while(m == EMPTY_QUEUE);
1212 msg = pHba->msg_addr_virt + m;
1213 memcpy_toio(msg, data, len);
1217 writel(m, pHba->post_port);
1224 static void adpt_i2o_post_wait_complete(u32 context, int status)
1226 struct adpt_i2o_post_wait_data *p1 = NULL;
1228 * We need to search through the adpt_post_wait
1229 * queue to see if the given message is still
1230 * outstanding. If not, it means that the IOP
1231 * took longer to respond to the message than we
1232 * had allowed and timer has already expired.
1233 * Not much we can do about that except log
1234 * it for debug purposes, increase timeout, and recompile
1236 * Lock needed to keep anyone from moving queue pointers
1237 * around while we're looking through them.
1242 spin_lock(&adpt_post_wait_lock);
1243 for(p1 = adpt_post_wait_queue; p1; p1 = p1->next) {
1244 if(p1->id == context) {
1245 p1->status = status;
1246 spin_unlock(&adpt_post_wait_lock);
1247 wake_up_interruptible(p1->wq);
1251 spin_unlock(&adpt_post_wait_lock);
1252 // If this happens we lose commands that probably really completed
1253 printk(KERN_DEBUG"dpti: Could Not find task %d in wait queue\n",context);
1254 printk(KERN_DEBUG" Tasks in wait queue:\n");
1255 for(p1 = adpt_post_wait_queue; p1; p1 = p1->next) {
1256 printk(KERN_DEBUG" %d\n",p1->id);
1261 static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1266 u32 m = EMPTY_QUEUE ;
1267 ulong timeout = jiffies + (TMOUT_IOPRESET*HZ);
1269 if(pHba->initialized == FALSE) { // First time reset should be quick
1270 timeout = jiffies + (25*HZ);
1272 adpt_i2o_quiesce_hba(pHba);
1277 m = readl(pHba->post_port);
1278 if (m != EMPTY_QUEUE) {
1281 if(time_after(jiffies,timeout)){
1282 printk(KERN_WARNING"Timeout waiting for message!\n");
1285 schedule_timeout_uninterruptible(1);
1286 } while (m == EMPTY_QUEUE);
1288 status = dma_alloc_coherent(&pHba->pDev->dev, 4, &addr, GFP_KERNEL);
1289 if(status == NULL) {
1290 adpt_send_nop(pHba, m);
1291 printk(KERN_ERR"IOP reset failed - no free memory.\n");
1296 msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0;
1297 msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID;
1302 msg[6]=dma_low(addr);
1303 msg[7]=dma_high(addr);
1305 memcpy_toio(pHba->msg_addr_virt+m, msg, sizeof(msg));
1307 writel(m, pHba->post_port);
1310 while(*status == 0){
1311 if(time_after(jiffies,timeout)){
1312 printk(KERN_WARNING"%s: IOP Reset Timeout\n",pHba->name);
1313 /* We lose 4 bytes of "status" here, but we cannot
1314 free these because controller may awake and corrupt
1315 those bytes at any time */
1316 /* dma_free_coherent(&pHba->pDev->dev, 4, buf, addr); */
1320 schedule_timeout_uninterruptible(1);
1323 if(*status == 0x01 /*I2O_EXEC_IOP_RESET_IN_PROGRESS*/) {
1324 PDEBUG("%s: Reset in progress...\n", pHba->name);
1325 // Here we wait for message frame to become available
1326 // indicated that reset has finished
1329 m = readl(pHba->post_port);
1330 if (m != EMPTY_QUEUE) {
1333 if(time_after(jiffies,timeout)){
1334 printk(KERN_ERR "%s:Timeout waiting for IOP Reset.\n",pHba->name);
1335 /* We lose 4 bytes of "status" here, but we
1336 cannot free these because controller may
1337 awake and corrupt those bytes at any time */
1338 /* dma_free_coherent(&pHba->pDev->dev, 4, buf, addr); */
1341 schedule_timeout_uninterruptible(1);
1342 } while (m == EMPTY_QUEUE);
1344 adpt_send_nop(pHba, m);
1346 adpt_i2o_status_get(pHba);
1347 if(*status == 0x02 ||
1348 pHba->status_block->iop_state != ADAPTER_STATE_RESET) {
1349 printk(KERN_WARNING"%s: Reset reject, trying to clear\n",
1352 PDEBUG("%s: Reset completed.\n", pHba->name);
1355 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
1357 // This delay is to allow someone attached to the card through the debug UART to
1358 // set up the dump levels that they want before the rest of the initialization sequence
1365 static int adpt_i2o_parse_lct(adpt_hba* pHba)
1370 struct i2o_device *d;
1371 i2o_lct *lct = pHba->lct;
1375 u32 buf[10]; // larger than 7, or 8 ...
1376 struct adpt_device* pDev;
1379 printk(KERN_ERR "%s: LCT is empty???\n",pHba->name);
1383 max = lct->table_size;
1387 for(i=0;i<max;i++) {
1388 if( lct->lct_entry[i].user_tid != 0xfff){
1390 * If we have hidden devices, we need to inform the upper layers about
1391 * the possible maximum id reference to handle device access when
1392 * an array is disassembled. This code has no other purpose but to
1393 * allow us future access to devices that are currently hidden
1394 * behind arrays, hotspares or have not been configured (JBOD mode).
1396 if( lct->lct_entry[i].class_id != I2O_CLASS_RANDOM_BLOCK_STORAGE &&
1397 lct->lct_entry[i].class_id != I2O_CLASS_SCSI_PERIPHERAL &&
1398 lct->lct_entry[i].class_id != I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL ){
1401 tid = lct->lct_entry[i].tid;
1402 // I2O_DPT_DEVICE_INFO_GROUP_NO;
1403 if(adpt_i2o_query_scalar(pHba, tid, 0x8000, -1, buf, 32)<0) {
1406 bus_no = buf[0]>>16;
1408 scsi_lun = (buf[2]>>8 )&0xff;
1409 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
1410 printk(KERN_WARNING"%s: Channel number %d out of range \n", pHba->name, bus_no);
1413 if (scsi_id >= MAX_ID){
1414 printk(KERN_WARNING"%s: SCSI ID %d out of range \n", pHba->name, bus_no);
1417 if(bus_no > pHba->top_scsi_channel){
1418 pHba->top_scsi_channel = bus_no;
1420 if(scsi_id > pHba->top_scsi_id){
1421 pHba->top_scsi_id = scsi_id;
1423 if(scsi_lun > pHba->top_scsi_lun){
1424 pHba->top_scsi_lun = scsi_lun;
1428 d = kmalloc(sizeof(struct i2o_device), GFP_KERNEL);
1431 printk(KERN_CRIT"%s: Out of memory for I2O device data.\n",pHba->name);
1435 d->controller = pHba;
1438 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
1441 tid = d->lct_data.tid;
1442 adpt_i2o_report_hba_unit(pHba, d);
1443 adpt_i2o_install_device(pHba, d);
1446 for(d = pHba->devices; d ; d = d->next) {
1447 if(d->lct_data.class_id == I2O_CLASS_BUS_ADAPTER_PORT ||
1448 d->lct_data.class_id == I2O_CLASS_FIBRE_CHANNEL_PORT){
1449 tid = d->lct_data.tid;
1450 // TODO get the bus_no from hrt-but for now they are in order
1452 if(bus_no > pHba->top_scsi_channel){
1453 pHba->top_scsi_channel = bus_no;
1455 pHba->channel[bus_no].type = d->lct_data.class_id;
1456 pHba->channel[bus_no].tid = tid;
1457 if(adpt_i2o_query_scalar(pHba, tid, 0x0200, -1, buf, 28)>=0)
1459 pHba->channel[bus_no].scsi_id = buf[1];
1460 PDEBUG("Bus %d - SCSI ID %d.\n", bus_no, buf[1]);
1462 // TODO remove - this is just until we get from hrt
1464 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
1465 printk(KERN_WARNING"%s: Channel number %d out of range - LCT\n", pHba->name, bus_no);
1471 // Setup adpt_device table
1472 for(d = pHba->devices; d ; d = d->next) {
1473 if(d->lct_data.class_id == I2O_CLASS_RANDOM_BLOCK_STORAGE ||
1474 d->lct_data.class_id == I2O_CLASS_SCSI_PERIPHERAL ||
1475 d->lct_data.class_id == I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL ){
1477 tid = d->lct_data.tid;
1479 // I2O_DPT_DEVICE_INFO_GROUP_NO;
1480 if(adpt_i2o_query_scalar(pHba, tid, 0x8000, -1, buf, 32)>=0) {
1481 bus_no = buf[0]>>16;
1483 scsi_lun = (buf[2]>>8 )&0xff;
1484 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
1487 if (scsi_id >= MAX_ID) {
1490 if( pHba->channel[bus_no].device[scsi_id] == NULL){
1491 pDev = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
1495 pHba->channel[bus_no].device[scsi_id] = pDev;
1497 for( pDev = pHba->channel[bus_no].device[scsi_id];
1498 pDev->next_lun; pDev = pDev->next_lun){
1500 pDev->next_lun = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
1501 if(pDev->next_lun == NULL) {
1504 pDev = pDev->next_lun;
1507 pDev->scsi_channel = bus_no;
1508 pDev->scsi_id = scsi_id;
1509 pDev->scsi_lun = scsi_lun;
1512 pDev->type = (buf[0])&0xff;
1513 pDev->flags = (buf[0]>>8)&0xff;
1514 if(scsi_id > pHba->top_scsi_id){
1515 pHba->top_scsi_id = scsi_id;
1517 if(scsi_lun > pHba->top_scsi_lun){
1518 pHba->top_scsi_lun = scsi_lun;
1522 printk(KERN_WARNING"Could not find SCSI ID for %s\n",
1523 d->lct_data.identity_tag);
1532 * Each I2O controller has a chain of devices on it - these match
1533 * the useful parts of the LCT of the board.
1536 static int adpt_i2o_install_device(adpt_hba* pHba, struct i2o_device *d)
1538 mutex_lock(&adpt_configuration_lock);
1541 d->next=pHba->devices;
1543 if (pHba->devices != NULL){
1544 pHba->devices->prev=d;
1549 mutex_unlock(&adpt_configuration_lock);
1553 static int adpt_open(struct inode *inode, struct file *file)
1558 //TODO check for root access
1560 minor = iminor(inode);
1561 if (minor >= hba_count) {
1564 mutex_lock(&adpt_configuration_lock);
1565 for (pHba = hba_chain; pHba; pHba = pHba->next) {
1566 if (pHba->unit == minor) {
1567 break; /* found adapter */
1571 mutex_unlock(&adpt_configuration_lock);
1575 // if(pHba->in_use){
1576 // mutex_unlock(&adpt_configuration_lock);
1581 mutex_unlock(&adpt_configuration_lock);
1586 static int adpt_close(struct inode *inode, struct file *file)
1591 minor = iminor(inode);
1592 if (minor >= hba_count) {
1595 mutex_lock(&adpt_configuration_lock);
1596 for (pHba = hba_chain; pHba; pHba = pHba->next) {
1597 if (pHba->unit == minor) {
1598 break; /* found adapter */
1601 mutex_unlock(&adpt_configuration_lock);
1612 static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
1614 u32 msg[MAX_MESSAGE_SIZE];
1618 u32 __user *user_msg = arg;
1619 u32 __user * user_reply = NULL;
1620 void *sg_list[pHba->sg_tablesize];
1630 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
1631 // get user msg size in u32s
1632 if(get_user(size, &user_msg[0])){
1637 user_reply = &user_msg[size];
1638 if(size > MAX_MESSAGE_SIZE){
1641 size *= 4; // Convert to bytes
1643 /* Copy in the user's I2O command */
1644 if(copy_from_user(msg, user_msg, size)) {
1647 get_user(reply_size, &user_reply[0]);
1648 reply_size = reply_size>>16;
1649 if(reply_size > REPLY_FRAME_SIZE){
1650 reply_size = REPLY_FRAME_SIZE;
1653 reply = kzalloc(REPLY_FRAME_SIZE*4, GFP_KERNEL);
1655 printk(KERN_WARNING"%s: Could not allocate reply buffer\n",pHba->name);
1658 sg_offset = (msg[0]>>4)&0xf;
1659 msg[2] = 0x40000000; // IOCTL context
1660 msg[3] = (u32)reply;
1661 memset(sg_list,0, sizeof(sg_list[0])*pHba->sg_tablesize);
1664 struct sg_simple_element *sg = (struct sg_simple_element*) (msg+sg_offset);
1665 sg_count = (size - sg_offset*4) / sizeof(struct sg_simple_element);
1666 if (sg_count > pHba->sg_tablesize){
1667 printk(KERN_DEBUG"%s:IOCTL SG List too large (%u)\n", pHba->name,sg_count);
1672 for(i = 0; i < sg_count; i++) {
1675 if (!(sg[i].flag_count & 0x10000000 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT*/)) {
1676 printk(KERN_DEBUG"%s:Bad SG element %d - not simple (%x)\n",pHba->name,i, sg[i].flag_count);
1680 sg_size = sg[i].flag_count & 0xffffff;
1681 /* Allocate memory for the transfer */
1682 p = dma_alloc_coherent(&pHba->pDev->dev, sg_size, &addr, GFP_KERNEL);
1684 printk(KERN_DEBUG"%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
1685 pHba->name,sg_size,i,sg_count);
1689 sg_list[sg_index++] = p; // sglist indexed with input frame, not our internal frame.
1690 /* Copy in the user's SG buffer if necessary */
1691 if(sg[i].flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR*/) {
1693 if (copy_from_user(p,(void __user *)sg[i].addr_bus, sg_size)) {
1694 printk(KERN_DEBUG"%s: Could not copy SG buf %d FROM user\n",pHba->name,i);
1700 sg[i].addr_bus = (u32)virt_to_bus(p);
1706 spin_lock_irqsave(pHba->host->host_lock, flags);
1707 // This state stops any new commands from enterring the
1708 // controller while processing the ioctl
1709 // pHba->state |= DPTI_STATE_IOCTL;
1710 // We can't set this now - The scsi subsystem sets host_blocked and
1711 // the queue empties and stops. We need a way to restart the queue
1712 rcode = adpt_i2o_post_wait(pHba, msg, size, FOREVER);
1714 printk("adpt_i2o_passthru: post wait failed %d %p\n",
1716 // pHba->state &= ~DPTI_STATE_IOCTL;
1718 spin_unlock_irqrestore(pHba->host->host_lock, flags);
1719 } while(rcode == -ETIMEDOUT);
1726 /* Copy back the Scatter Gather buffers back to user space */
1729 struct sg_simple_element* sg;
1732 // re-acquire the original message to handle correctly the sg copy operation
1733 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
1734 // get user msg size in u32s
1735 if(get_user(size, &user_msg[0])){
1741 /* Copy in the user's I2O command */
1742 if (copy_from_user (msg, user_msg, size)) {
1746 sg_count = (size - sg_offset*4) / sizeof(struct sg_simple_element);
1749 sg = (struct sg_simple_element*)(msg + sg_offset);
1750 for (j = 0; j < sg_count; j++) {
1751 /* Copy out the SG list to user's buffer if necessary */
1752 if(! (sg[j].flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR*/)) {
1753 sg_size = sg[j].flag_count & 0xffffff;
1755 if (copy_to_user((void __user *)sg[j].addr_bus,sg_list[j], sg_size)) {
1756 printk(KERN_WARNING"%s: Could not copy %p TO user %x\n",pHba->name, sg_list[j], sg[j].addr_bus);
1764 /* Copy back the reply to user space */
1766 // we wrote our own values for context - now restore the user supplied ones
1767 if(copy_from_user(reply+2, user_msg+2, sizeof(u32)*2)) {
1768 printk(KERN_WARNING"%s: Could not copy message context FROM user\n",pHba->name);
1771 if(copy_to_user(user_reply, reply, reply_size)) {
1772 printk(KERN_WARNING"%s: Could not copy reply TO user\n",pHba->name);
1779 if (rcode != -ETIME && rcode != -EINTR) {
1780 struct sg_simple_element *sg =
1781 (struct sg_simple_element*) (msg +sg_offset);
1784 if(sg_list[--sg_index]) {
1785 dma_free_coherent(&pHba->pDev->dev,
1786 sg[sg_index].flag_count & 0xffffff,
1788 sg[sg_index].addr_bus);
1797 * This routine returns information about the system. This does not effect
1798 * any logic and if the info is wrong - it doesn't matter.
1801 /* Get all the info we can not get from kernel services */
1802 static int adpt_system_info(void __user *buffer)
1806 memset(&si, 0, sizeof(si));
1808 si.osType = OS_LINUX;
1809 si.osMajorVersion = 0;
1810 si.osMinorVersion = 0;
1812 si.busType = SI_PCI_BUS;
1813 si.processorFamily = DPTI_sig.dsProcessorFamily;
1815 #if defined __i386__
1816 adpt_i386_info(&si);
1817 #elif defined (__ia64__)
1818 adpt_ia64_info(&si);
1819 #elif defined(__sparc__)
1820 adpt_sparc_info(&si);
1821 #elif defined (__alpha__)
1822 adpt_alpha_info(&si);
1824 si.processorType = 0xff ;
1826 if(copy_to_user(buffer, &si, sizeof(si))){
1827 printk(KERN_WARNING"dpti: Could not copy buffer TO user\n");
1834 #if defined __ia64__
1835 static void adpt_ia64_info(sysInfo_S* si)
1837 // This is all the info we need for now
1838 // We will add more info as our new
1839 // managmenent utility requires it
1840 si->processorType = PROC_IA64;
1845 #if defined __sparc__
1846 static void adpt_sparc_info(sysInfo_S* si)
1848 // This is all the info we need for now
1849 // We will add more info as our new
1850 // managmenent utility requires it
1851 si->processorType = PROC_ULTRASPARC;
1855 #if defined __alpha__
1856 static void adpt_alpha_info(sysInfo_S* si)
1858 // This is all the info we need for now
1859 // We will add more info as our new
1860 // managmenent utility requires it
1861 si->processorType = PROC_ALPHA;
1865 #if defined __i386__
1867 static void adpt_i386_info(sysInfo_S* si)
1869 // This is all the info we need for now
1870 // We will add more info as our new
1871 // managmenent utility requires it
1872 switch (boot_cpu_data.x86) {
1874 si->processorType = PROC_386;
1877 si->processorType = PROC_486;
1880 si->processorType = PROC_PENTIUM;
1882 default: // Just in case
1883 si->processorType = PROC_PENTIUM;
1891 static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd,
1898 void __user *argp = (void __user *)arg;
1900 minor = iminor(inode);
1901 if (minor >= DPTI_MAX_HBA){
1904 mutex_lock(&adpt_configuration_lock);
1905 for (pHba = hba_chain; pHba; pHba = pHba->next) {
1906 if (pHba->unit == minor) {
1907 break; /* found adapter */
1910 mutex_unlock(&adpt_configuration_lock);
1915 while((volatile u32) pHba->state & DPTI_STATE_RESET )
1916 schedule_timeout_uninterruptible(2);
1919 // TODO: handle 3 cases
1921 if (copy_to_user(argp, &DPTI_sig, sizeof(DPTI_sig))) {
1926 return adpt_i2o_passthru(pHba, argp);
1929 drvrHBAinfo_S HbaInfo;
1931 #define FLG_OSD_PCI_VALID 0x0001
1932 #define FLG_OSD_DMA 0x0002
1933 #define FLG_OSD_I2O 0x0004
1934 memset(&HbaInfo, 0, sizeof(HbaInfo));
1935 HbaInfo.drvrHBAnum = pHba->unit;
1936 HbaInfo.baseAddr = (ulong) pHba->base_addr_phys;
1937 HbaInfo.blinkState = adpt_read_blink_led(pHba);
1938 HbaInfo.pciBusNum = pHba->pDev->bus->number;
1939 HbaInfo.pciDeviceNum=PCI_SLOT(pHba->pDev->devfn);
1940 HbaInfo.Interrupt = pHba->pDev->irq;
1941 HbaInfo.hbaFlags = FLG_OSD_PCI_VALID | FLG_OSD_DMA | FLG_OSD_I2O;
1942 if(copy_to_user(argp, &HbaInfo, sizeof(HbaInfo))){
1943 printk(KERN_WARNING"%s: Could not copy HbaInfo TO user\n",pHba->name);
1949 return adpt_system_info(argp);
1952 value = (u32)adpt_read_blink_led(pHba);
1953 if (copy_to_user(argp, &value, sizeof(value))) {
1960 spin_lock_irqsave(pHba->host->host_lock, flags);
1961 adpt_hba_reset(pHba);
1963 spin_unlock_irqrestore(pHba->host->host_lock, flags);
1976 static irqreturn_t adpt_isr(int irq, void *dev_id)
1978 struct scsi_cmnd* cmd;
1979 adpt_hba* pHba = dev_id;
1981 void __iomem *reply;
1988 printk(KERN_WARNING"adpt_isr: NULL dev_id\n");
1992 spin_lock_irqsave(pHba->host->host_lock, flags);
1994 while( readl(pHba->irq_mask) & I2O_INTERRUPT_PENDING_B) {
1995 m = readl(pHba->reply_port);
1996 if(m == EMPTY_QUEUE){
1997 // Try twice then give up
1999 m = readl(pHba->reply_port);
2000 if(m == EMPTY_QUEUE){
2001 // This really should not happen
2002 printk(KERN_ERR"dpti: Could not get reply frame\n");
2006 if (pHba->reply_pool_pa <= m &&
2007 m < pHba->reply_pool_pa +
2008 (pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4)) {
2009 reply = (u8 *)pHba->reply_pool +
2010 (m - pHba->reply_pool_pa);
2012 /* Ick, we should *never* be here */
2013 printk(KERN_ERR "dpti: reply frame not from pool\n");
2014 reply = (u8 *)bus_to_virt(m);
2017 if (readl(reply) & MSG_FAIL) {
2018 u32 old_m = readl(reply+28);
2021 PDEBUG("%s: Failed message\n",pHba->name);
2022 if(old_m >= 0x100000){
2023 printk(KERN_ERR"%s: Bad preserved MFA (%x)- dropping frame\n",pHba->name,old_m);
2024 writel(m,pHba->reply_port);
2027 // Transaction context is 0 in failed reply frame
2028 msg = pHba->msg_addr_virt + old_m;
2029 old_context = readl(msg+12);
2030 writel(old_context, reply+12);
2031 adpt_send_nop(pHba, old_m);
2033 context = readl(reply+8);
2034 if(context & 0x40000000){ // IOCTL
2035 void *p = (void *)readl(reply+12);
2037 memcpy_fromio(p, reply, REPLY_FRAME_SIZE * 4);
2039 // All IOCTLs will also be post wait
2041 if(context & 0x80000000){ // Post wait message
2042 status = readl(reply+16);
2044 status &= 0xffff; /* Get detail status */
2046 status = I2O_POST_WAIT_OK;
2048 if(!(context & 0x40000000)) {
2049 cmd = (struct scsi_cmnd*) readl(reply+12);
2051 printk(KERN_WARNING"%s: Apparent SCSI cmd in Post Wait Context - cmd=%p context=%x\n", pHba->name, cmd, context);
2054 adpt_i2o_post_wait_complete(context, status);
2055 } else { // SCSI message
2056 cmd = (struct scsi_cmnd*) readl(reply+12);
2058 scsi_dma_unmap(cmd);
2059 if(cmd->serial_number != 0) { // If not timedout
2060 adpt_i2o_to_scsi(reply, cmd);
2064 writel(m, pHba->reply_port);
2070 spin_unlock_irqrestore(pHba->host->host_lock, flags);
2071 return IRQ_RETVAL(handled);
2074 static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_device* d)
2077 u32 msg[MAX_MESSAGE_SIZE];
2087 memset(msg, 0 , sizeof(msg));
2088 len = scsi_bufflen(cmd);
2089 direction = 0x00000000;
2091 scsidir = 0x00000000; // DATA NO XFER
2094 * Set SCBFlags to indicate if data is being transferred
2095 * in or out, or no data transfer
2096 * Note: Do not have to verify index is less than 0 since
2097 * cmd->cmnd[0] is an unsigned char
2099 switch(cmd->sc_data_direction){
2100 case DMA_FROM_DEVICE:
2101 scsidir =0x40000000; // DATA IN (iop<--dev)
2104 direction=0x04000000; // SGL OUT
2105 scsidir =0x80000000; // DATA OUT (iop-->dev)
2109 case DMA_BIDIRECTIONAL:
2110 scsidir =0x40000000; // DATA IN (iop<--dev)
2111 // Assume In - and continue;
2114 printk(KERN_WARNING"%s: scsi opcode 0x%x not supported.\n",
2115 pHba->name, cmd->cmnd[0]);
2116 cmd->result = (DID_OK <<16) | (INITIATOR_ERROR << 8);
2117 cmd->scsi_done(cmd);
2121 // msg[0] is set later
2122 // I2O_CMD_SCSI_EXEC
2123 msg[1] = ((0xff<<24)|(HOST_TID<<12)|d->tid);
2125 msg[3] = (u32)cmd; /* We want the SCSI control block back */
2126 // Our cards use the transaction context as the tag for queueing
2127 // Adaptec/DPT Private stuff
2128 msg[4] = I2O_CMD_SCSI_EXEC|(DPT_ORGANIZATION_ID<<16);
2130 /* Direction, disconnect ok | sense data | simple queue , CDBLen */
2131 // I2O_SCB_FLAG_ENABLE_DISCONNECT |
2132 // I2O_SCB_FLAG_SIMPLE_QUEUE_TAG |
2133 // I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
2134 msg[6] = scsidir|0x20a00000|cmd->cmd_len;
2138 // Write SCSI command into the message - always 16 byte block
2139 memset(mptr, 0, 16);
2140 memcpy(mptr, cmd->cmnd, cmd->cmd_len);
2142 lenptr=mptr++; /* Remember me - fill in when we know */
2143 reqlen = 14; // SINGLE SGE
2144 /* Now fill in the SGList and command */
2146 nseg = scsi_dma_map(cmd);
2149 struct scatterlist *sg;
2152 scsi_for_each_sg(cmd, sg, nseg, i) {
2153 *mptr++ = direction|0x10000000|sg_dma_len(sg);
2154 len+=sg_dma_len(sg);
2155 *mptr++ = sg_dma_address(sg);
2156 /* Make this an end of list */
2158 mptr[-2] = direction|0xD0000000|sg_dma_len(sg);
2160 reqlen = mptr - msg;
2163 if(cmd->underflow && len != cmd->underflow){
2164 printk(KERN_WARNING"Cmd len %08X Cmd underflow %08X\n",
2165 len, cmd->underflow);
2172 /* Stick the headers on */
2173 msg[0] = reqlen<<16 | ((reqlen > 12) ? SGL_OFFSET_12 : SGL_OFFSET_0);
2175 // Send it on it's way
2176 rcode = adpt_i2o_post_this(pHba, msg, reqlen<<2);
2184 static s32 adpt_scsi_host_alloc(adpt_hba* pHba, struct scsi_host_template *sht)
2186 struct Scsi_Host *host;
2188 host = scsi_host_alloc(sht, sizeof(adpt_hba*));
2190 printk("%s: scsi_host_alloc returned NULL\n", pHba->name);
2193 host->hostdata[0] = (unsigned long)pHba;
2196 host->irq = pHba->pDev->irq;
2197 /* no IO ports, so don't have to set host->io_port and
2201 host->n_io_port = 0;
2202 /* see comments in scsi_host.h */
2204 host->max_lun = 256;
2205 host->max_channel = pHba->top_scsi_channel + 1;
2206 host->cmd_per_lun = 1;
2207 host->unique_id = (u32)sys_tbl_pa + pHba->unit;
2208 host->sg_tablesize = pHba->sg_tablesize;
2209 host->can_queue = pHba->post_fifo_size;
2215 static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd)
2220 u32 reply_flags = readl(reply) & 0xff00; // Leave it shifted up 8 bits
2221 // I know this would look cleaner if I just read bytes
2222 // but the model I have been using for all the rest of the
2223 // io is in 4 byte words - so I keep that model
2224 u16 detailed_status = readl(reply+16) &0xffff;
2225 dev_status = (detailed_status & 0xff);
2226 hba_status = detailed_status >> 8;
2228 // calculate resid for sg
2229 scsi_set_resid(cmd, scsi_bufflen(cmd) - readl(reply+5));
2231 pHba = (adpt_hba*) cmd->device->host->hostdata[0];
2233 cmd->sense_buffer[0] = '\0'; // initialize sense valid flag to false
2235 if(!(reply_flags & MSG_FAIL)) {
2236 switch(detailed_status & I2O_SCSI_DSC_MASK) {
2237 case I2O_SCSI_DSC_SUCCESS:
2238 cmd->result = (DID_OK << 16);
2240 if(readl(reply+5) < cmd->underflow ) {
2241 cmd->result = (DID_ERROR <<16);
2242 printk(KERN_WARNING"%s: SCSI CMD underflow\n",pHba->name);
2245 case I2O_SCSI_DSC_REQUEST_ABORTED:
2246 cmd->result = (DID_ABORT << 16);
2248 case I2O_SCSI_DSC_PATH_INVALID:
2249 case I2O_SCSI_DSC_DEVICE_NOT_PRESENT:
2250 case I2O_SCSI_DSC_SELECTION_TIMEOUT:
2251 case I2O_SCSI_DSC_COMMAND_TIMEOUT:
2252 case I2O_SCSI_DSC_NO_ADAPTER:
2253 case I2O_SCSI_DSC_RESOURCE_UNAVAILABLE:
2254 printk(KERN_WARNING"%s: SCSI Timeout-Device (%d,%d,%d) hba status=0x%x, dev status=0x%x, cmd=0x%x\n",
2255 pHba->name, (u32)cmd->device->channel, (u32)cmd->device->id, (u32)cmd->device->lun, hba_status, dev_status, cmd->cmnd[0]);
2256 cmd->result = (DID_TIME_OUT << 16);
2258 case I2O_SCSI_DSC_ADAPTER_BUSY:
2259 case I2O_SCSI_DSC_BUS_BUSY:
2260 cmd->result = (DID_BUS_BUSY << 16);
2262 case I2O_SCSI_DSC_SCSI_BUS_RESET:
2263 case I2O_SCSI_DSC_BDR_MESSAGE_SENT:
2264 cmd->result = (DID_RESET << 16);
2266 case I2O_SCSI_DSC_PARITY_ERROR_FAILURE:
2267 printk(KERN_WARNING"%s: SCSI CMD parity error\n",pHba->name);
2268 cmd->result = (DID_PARITY << 16);
2270 case I2O_SCSI_DSC_UNABLE_TO_ABORT:
2271 case I2O_SCSI_DSC_COMPLETE_WITH_ERROR:
2272 case I2O_SCSI_DSC_UNABLE_TO_TERMINATE:
2273 case I2O_SCSI_DSC_MR_MESSAGE_RECEIVED:
2274 case I2O_SCSI_DSC_AUTOSENSE_FAILED:
2275 case I2O_SCSI_DSC_DATA_OVERRUN:
2276 case I2O_SCSI_DSC_UNEXPECTED_BUS_FREE:
2277 case I2O_SCSI_DSC_SEQUENCE_FAILURE:
2278 case I2O_SCSI_DSC_REQUEST_LENGTH_ERROR:
2279 case I2O_SCSI_DSC_PROVIDE_FAILURE:
2280 case I2O_SCSI_DSC_REQUEST_TERMINATED:
2281 case I2O_SCSI_DSC_IDE_MESSAGE_SENT:
2282 case I2O_SCSI_DSC_UNACKNOWLEDGED_EVENT:
2283 case I2O_SCSI_DSC_MESSAGE_RECEIVED:
2284 case I2O_SCSI_DSC_INVALID_CDB:
2285 case I2O_SCSI_DSC_LUN_INVALID:
2286 case I2O_SCSI_DSC_SCSI_TID_INVALID:
2287 case I2O_SCSI_DSC_FUNCTION_UNAVAILABLE:
2288 case I2O_SCSI_DSC_NO_NEXUS:
2289 case I2O_SCSI_DSC_CDB_RECEIVED:
2290 case I2O_SCSI_DSC_LUN_ALREADY_ENABLED:
2291 case I2O_SCSI_DSC_QUEUE_FROZEN:
2292 case I2O_SCSI_DSC_REQUEST_INVALID:
2294 printk(KERN_WARNING"%s: SCSI error %0x-Device(%d,%d,%d) hba_status=0x%x, dev_status=0x%x, cmd=0x%x\n",
2295 pHba->name, detailed_status & I2O_SCSI_DSC_MASK, (u32)cmd->device->channel, (u32)cmd->device->id, (u32)cmd->device->lun,
2296 hba_status, dev_status, cmd->cmnd[0]);
2297 cmd->result = (DID_ERROR << 16);
2301 // copy over the request sense data if it was a check
2303 if (dev_status == SAM_STAT_CHECK_CONDITION) {
2304 u32 len = min(SCSI_SENSE_BUFFERSIZE, 40);
2305 // Copy over the sense data
2306 memcpy_fromio(cmd->sense_buffer, (reply+28) , len);
2307 if(cmd->sense_buffer[0] == 0x70 /* class 7 */ &&
2308 cmd->sense_buffer[2] == DATA_PROTECT ){
2309 /* This is to handle an array failed */
2310 cmd->result = (DID_TIME_OUT << 16);
2311 printk(KERN_WARNING"%s: SCSI Data Protect-Device (%d,%d,%d) hba_status=0x%x, dev_status=0x%x, cmd=0x%x\n",
2312 pHba->name, (u32)cmd->device->channel, (u32)cmd->device->id, (u32)cmd->device->lun,
2313 hba_status, dev_status, cmd->cmnd[0]);
2318 /* In this condtion we could not talk to the tid
2319 * the card rejected it. We should signal a retry
2320 * for a limitted number of retries.
2322 cmd->result = (DID_TIME_OUT << 16);
2323 printk(KERN_WARNING"%s: I2O MSG_FAIL - Device (%d,%d,%d) tid=%d, cmd=0x%x\n",
2324 pHba->name, (u32)cmd->device->channel, (u32)cmd->device->id, (u32)cmd->device->lun,
2325 ((struct adpt_device*)(cmd->device->hostdata))->tid, cmd->cmnd[0]);
2328 cmd->result |= (dev_status);
2330 if(cmd->scsi_done != NULL){
2331 cmd->scsi_done(cmd);
2337 static s32 adpt_rescan(adpt_hba* pHba)
2343 spin_lock_irqsave(pHba->host->host_lock, flags);
2344 if ((rcode=adpt_i2o_lct_get(pHba)) < 0)
2346 if ((rcode=adpt_i2o_reparse_lct(pHba)) < 0)
2350 spin_unlock_irqrestore(pHba->host->host_lock, flags);
2355 static s32 adpt_i2o_reparse_lct(adpt_hba* pHba)
2360 struct i2o_device *d;
2361 i2o_lct *lct = pHba->lct;
2365 u32 buf[10]; // at least 8 u32's
2366 struct adpt_device* pDev = NULL;
2367 struct i2o_device* pI2o_dev = NULL;
2370 printk(KERN_ERR "%s: LCT is empty???\n",pHba->name);
2374 max = lct->table_size;
2378 // Mark each drive as unscanned
2379 for (d = pHba->devices; d; d = d->next) {
2380 pDev =(struct adpt_device*) d->owner;
2384 pDev->state |= DPTI_DEV_UNSCANNED;
2387 printk(KERN_INFO "%s: LCT has %d entries.\n", pHba->name,max);
2389 for(i=0;i<max;i++) {
2390 if( lct->lct_entry[i].user_tid != 0xfff){
2394 if( lct->lct_entry[i].class_id == I2O_CLASS_RANDOM_BLOCK_STORAGE ||
2395 lct->lct_entry[i].class_id == I2O_CLASS_SCSI_PERIPHERAL ||
2396 lct->lct_entry[i].class_id == I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL ){
2397 tid = lct->lct_entry[i].tid;
2398 if(adpt_i2o_query_scalar(pHba, tid, 0x8000, -1, buf, 32)<0) {
2399 printk(KERN_ERR"%s: Could not query device\n",pHba->name);
2402 bus_no = buf[0]>>16;
2404 scsi_lun = (buf[2]>>8 )&0xff;
2405 pDev = pHba->channel[bus_no].device[scsi_id];
2408 if(pDev->scsi_lun == scsi_lun) {
2411 pDev = pDev->next_lun;
2413 if(!pDev ) { // Something new add it
2414 d = kmalloc(sizeof(struct i2o_device), GFP_KERNEL);
2417 printk(KERN_CRIT "Out of memory for I2O device data.\n");
2421 d->controller = pHba;
2424 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
2427 adpt_i2o_report_hba_unit(pHba, d);
2428 adpt_i2o_install_device(pHba, d);
2430 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
2431 printk(KERN_WARNING"%s: Channel number %d out of range \n", pHba->name, bus_no);
2434 pDev = pHba->channel[bus_no].device[scsi_id];
2436 pDev = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
2440 pHba->channel[bus_no].device[scsi_id] = pDev;
2442 while (pDev->next_lun) {
2443 pDev = pDev->next_lun;
2445 pDev = pDev->next_lun = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
2450 pDev->tid = d->lct_data.tid;
2451 pDev->scsi_channel = bus_no;
2452 pDev->scsi_id = scsi_id;
2453 pDev->scsi_lun = scsi_lun;
2456 pDev->type = (buf[0])&0xff;
2457 pDev->flags = (buf[0]>>8)&0xff;
2458 // Too late, SCSI system has made up it's mind, but what the hey ...
2459 if(scsi_id > pHba->top_scsi_id){
2460 pHba->top_scsi_id = scsi_id;
2462 if(scsi_lun > pHba->top_scsi_lun){
2463 pHba->top_scsi_lun = scsi_lun;
2466 } // end of new i2o device
2468 // We found an old device - check it
2470 if(pDev->scsi_lun == scsi_lun) {
2471 if(!scsi_device_online(pDev->pScsi_dev)) {
2472 printk(KERN_WARNING"%s: Setting device (%d,%d,%d) back online\n",
2473 pHba->name,bus_no,scsi_id,scsi_lun);
2474 if (pDev->pScsi_dev) {
2475 scsi_device_set_state(pDev->pScsi_dev, SDEV_RUNNING);
2479 if(d->lct_data.tid != tid) { // something changed
2481 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
2482 if (pDev->pScsi_dev) {
2483 pDev->pScsi_dev->changed = TRUE;
2484 pDev->pScsi_dev->removable = TRUE;
2487 // Found it - mark it scanned
2488 pDev->state = DPTI_DEV_ONLINE;
2491 pDev = pDev->next_lun;
2495 for (pI2o_dev = pHba->devices; pI2o_dev; pI2o_dev = pI2o_dev->next) {
2496 pDev =(struct adpt_device*) pI2o_dev->owner;
2500 // Drive offline drives that previously existed but could not be found
2502 if (pDev->state & DPTI_DEV_UNSCANNED){
2503 pDev->state = DPTI_DEV_OFFLINE;
2504 printk(KERN_WARNING"%s: Device (%d,%d,%d) offline\n",pHba->name,pDev->scsi_channel,pDev->scsi_id,pDev->scsi_lun);
2505 if (pDev->pScsi_dev) {
2506 scsi_device_set_state(pDev->pScsi_dev, SDEV_OFFLINE);
2513 static void adpt_fail_posted_scbs(adpt_hba* pHba)
2515 struct scsi_cmnd* cmd = NULL;
2516 struct scsi_device* d = NULL;
2518 shost_for_each_device(d, pHba->host) {
2519 unsigned long flags;
2520 spin_lock_irqsave(&d->list_lock, flags);
2521 list_for_each_entry(cmd, &d->cmd_list, list) {
2522 if(cmd->serial_number == 0){
2525 cmd->result = (DID_OK << 16) | (QUEUE_FULL <<1);
2526 cmd->scsi_done(cmd);
2528 spin_unlock_irqrestore(&d->list_lock, flags);
2533 /*============================================================================
2534 * Routines from i2o subsystem
2535 *============================================================================
2541 * Bring an I2O controller into HOLD state. See the spec.
2543 static int adpt_i2o_activate_hba(adpt_hba* pHba)
2547 if(pHba->initialized ) {
2548 if (adpt_i2o_status_get(pHba) < 0) {
2549 if((rcode = adpt_i2o_reset_hba(pHba)) != 0){
2550 printk(KERN_WARNING"%s: Could NOT reset.\n", pHba->name);
2553 if (adpt_i2o_status_get(pHba) < 0) {
2554 printk(KERN_INFO "HBA not responding.\n");
2559 if(pHba->status_block->iop_state == ADAPTER_STATE_FAULTED) {
2560 printk(KERN_CRIT "%s: hardware fault\n", pHba->name);
2564 if (pHba->status_block->iop_state == ADAPTER_STATE_READY ||
2565 pHba->status_block->iop_state == ADAPTER_STATE_OPERATIONAL ||
2566 pHba->status_block->iop_state == ADAPTER_STATE_HOLD ||
2567 pHba->status_block->iop_state == ADAPTER_STATE_FAILED) {
2568 adpt_i2o_reset_hba(pHba);
2569 if (adpt_i2o_status_get(pHba) < 0 || pHba->status_block->iop_state != ADAPTER_STATE_RESET) {
2570 printk(KERN_ERR "%s: Failed to initialize.\n", pHba->name);
2575 if((rcode = adpt_i2o_reset_hba(pHba)) != 0){
2576 printk(KERN_WARNING"%s: Could NOT reset.\n", pHba->name);
2582 if (adpt_i2o_init_outbound_q(pHba) < 0) {
2588 if (adpt_i2o_hrt_get(pHba) < 0) {
2596 * Bring a controller online into OPERATIONAL state.
2599 static int adpt_i2o_online_hba(adpt_hba* pHba)
2601 if (adpt_i2o_systab_send(pHba) < 0) {
2602 adpt_i2o_delete_hba(pHba);
2605 /* In READY state */
2607 if (adpt_i2o_enable_hba(pHba) < 0) {
2608 adpt_i2o_delete_hba(pHba);
2612 /* In OPERATIONAL state */
2616 static s32 adpt_send_nop(adpt_hba*pHba,u32 m)
2619 ulong timeout = jiffies + 5*HZ;
2621 while(m == EMPTY_QUEUE){
2623 m = readl(pHba->post_port);
2624 if(m != EMPTY_QUEUE){
2627 if(time_after(jiffies,timeout)){
2628 printk(KERN_ERR "%s: Timeout waiting for message frame!\n",pHba->name);
2631 schedule_timeout_uninterruptible(1);
2633 msg = (u32 __iomem *)(pHba->msg_addr_virt + m);
2634 writel( THREE_WORD_MSG_SIZE | SGL_OFFSET_0,&msg[0]);
2635 writel( I2O_CMD_UTIL_NOP << 24 | HOST_TID << 12 | 0,&msg[1]);
2639 writel(m, pHba->post_port);
2644 static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
2648 u32 __iomem *msg = NULL;
2650 ulong timeout = jiffies + TMOUT_INITOUTBOUND*HZ;
2655 m = readl(pHba->post_port);
2656 if (m != EMPTY_QUEUE) {
2660 if(time_after(jiffies,timeout)){
2661 printk(KERN_WARNING"%s: Timeout waiting for message frame\n",pHba->name);
2664 schedule_timeout_uninterruptible(1);
2665 } while(m == EMPTY_QUEUE);
2667 msg=(u32 __iomem *)(pHba->msg_addr_virt+m);
2669 status = dma_alloc_coherent(&pHba->pDev->dev, 4, &addr, GFP_KERNEL);
2671 adpt_send_nop(pHba, m);
2672 printk(KERN_WARNING"%s: IOP reset failed - no free memory.\n",
2676 memset(status, 0, 4);
2678 writel(EIGHT_WORD_MSG_SIZE| SGL_OFFSET_6, &msg[0]);
2679 writel(I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID, &msg[1]);
2681 writel(0x0106, &msg[3]); /* Transaction context */
2682 writel(4096, &msg[4]); /* Host page frame size */
2683 writel((REPLY_FRAME_SIZE)<<16|0x80, &msg[5]); /* Outbound msg frame size and Initcode */
2684 writel(0xD0000004, &msg[6]); /* Simple SG LE, EOB */
2685 writel((u32)addr, &msg[7]);
2687 writel(m, pHba->post_port);
2690 // Wait for the reply status to come back
2693 if (*status != 0x01 /*I2O_EXEC_OUTBOUND_INIT_IN_PROGRESS*/) {
2698 if(time_after(jiffies,timeout)){
2699 printk(KERN_WARNING"%s: Timeout Initializing\n",pHba->name);
2700 /* We lose 4 bytes of "status" here, but we
2701 cannot free these because controller may
2702 awake and corrupt those bytes at any time */
2703 /* dma_free_coherent(&pHba->pDev->dev, 4, status, addr); */
2706 schedule_timeout_uninterruptible(1);
2709 // If the command was successful, fill the fifo with our reply
2711 if(*status != 0x04 /*I2O_EXEC_OUTBOUND_INIT_COMPLETE*/) {
2712 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
2715 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
2717 if(pHba->reply_pool != NULL) {
2718 dma_free_coherent(&pHba->pDev->dev,
2719 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
2720 pHba->reply_pool, pHba->reply_pool_pa);
2723 pHba->reply_pool = dma_alloc_coherent(&pHba->pDev->dev,
2724 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
2725 &pHba->reply_pool_pa, GFP_KERNEL);
2726 if (!pHba->reply_pool) {
2727 printk(KERN_ERR "%s: Could not allocate reply pool\n", pHba->name);
2730 memset(pHba->reply_pool, 0 , pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4);
2732 for(i = 0; i < pHba->reply_fifo_size; i++) {
2733 writel(pHba->reply_pool_pa + (i * REPLY_FRAME_SIZE * 4),
2737 adpt_i2o_status_get(pHba);
2743 * I2O System Table. Contains information about
2744 * all the IOPs in the system. Used to inform IOPs
2745 * about each other's existence.
2747 * sys_tbl_ver is the CurrentChangeIndicator that is
2748 * used by IOPs to track changes.
2753 static s32 adpt_i2o_status_get(adpt_hba* pHba)
2758 u8 *status_block=NULL;
2760 if(pHba->status_block == NULL) {
2761 pHba->status_block = dma_alloc_coherent(&pHba->pDev->dev,
2762 sizeof(i2o_status_block),
2763 &pHba->status_block_pa, GFP_KERNEL);
2764 if(pHba->status_block == NULL) {
2766 "dpti%d: Get Status Block failed; Out of memory. \n",
2771 memset(pHba->status_block, 0, sizeof(i2o_status_block));
2772 status_block = (u8*)(pHba->status_block);
2773 timeout = jiffies+TMOUT_GETSTATUS*HZ;
2776 m = readl(pHba->post_port);
2777 if (m != EMPTY_QUEUE) {
2780 if(time_after(jiffies,timeout)){
2781 printk(KERN_ERR "%s: Timeout waiting for message !\n",
2785 schedule_timeout_uninterruptible(1);
2786 } while(m==EMPTY_QUEUE);
2789 msg=(u32 __iomem *)(pHba->msg_addr_virt+m);
2791 writel(NINE_WORD_MSG_SIZE|SGL_OFFSET_0, &msg[0]);
2792 writel(I2O_CMD_STATUS_GET<<24|HOST_TID<<12|ADAPTER_TID, &msg[1]);
2797 writel( dma_low(pHba->status_block_pa), &msg[6]);
2798 writel( dma_high(pHba->status_block_pa), &msg[7]);
2799 writel(sizeof(i2o_status_block), &msg[8]); // 88 bytes
2802 writel(m, pHba->post_port);
2805 while(status_block[87]!=0xff){
2806 if(time_after(jiffies,timeout)){
2807 printk(KERN_ERR"dpti%d: Get status timeout.\n",
2812 schedule_timeout_uninterruptible(1);
2815 // Set up our number of outbound and inbound messages
2816 pHba->post_fifo_size = pHba->status_block->max_inbound_frames;
2817 if (pHba->post_fifo_size > MAX_TO_IOP_MESSAGES) {
2818 pHba->post_fifo_size = MAX_TO_IOP_MESSAGES;
2821 pHba->reply_fifo_size = pHba->status_block->max_outbound_frames;
2822 if (pHba->reply_fifo_size > MAX_FROM_IOP_MESSAGES) {
2823 pHba->reply_fifo_size = MAX_FROM_IOP_MESSAGES;
2826 // Calculate the Scatter Gather list size
2827 pHba->sg_tablesize = (pHba->status_block->inbound_frame_size * 4 -40)/ sizeof(struct sg_simple_element);
2828 if (pHba->sg_tablesize > SG_LIST_ELEMENTS) {
2829 pHba->sg_tablesize = SG_LIST_ELEMENTS;
2834 printk("dpti%d: State = ",pHba->unit);
2835 switch(pHba->status_block->iop_state) {
2849 printk("OPERATIONAL\n");
2855 printk("FAULTED\n");
2858 printk("%x (unknown!!)\n",pHba->status_block->iop_state);
2865 * Get the IOP's Logical Configuration Table
2867 static int adpt_i2o_lct_get(adpt_hba* pHba)
2873 if ((pHba->lct_size == 0) || (pHba->lct == NULL)){
2874 pHba->lct_size = pHba->status_block->expected_lct_size;
2877 if (pHba->lct == NULL) {
2878 pHba->lct = dma_alloc_coherent(&pHba->pDev->dev,
2879 pHba->lct_size, &pHba->lct_pa,
2881 if(pHba->lct == NULL) {
2882 printk(KERN_CRIT "%s: Lct Get failed. Out of memory.\n",
2887 memset(pHba->lct, 0, pHba->lct_size);
2889 msg[0] = EIGHT_WORD_MSG_SIZE|SGL_OFFSET_6;
2890 msg[1] = I2O_CMD_LCT_NOTIFY<<24 | HOST_TID<<12 | ADAPTER_TID;
2893 msg[4] = 0xFFFFFFFF; /* All devices */
2894 msg[5] = 0x00000000; /* Report now */
2895 msg[6] = 0xD0000000|pHba->lct_size;
2896 msg[7] = (u32)pHba->lct_pa;
2898 if ((ret=adpt_i2o_post_wait(pHba, msg, sizeof(msg), 360))) {
2899 printk(KERN_ERR "%s: LCT Get failed (status=%#10x.\n",
2901 printk(KERN_ERR"Adaptec: Error Reading Hardware.\n");
2905 if ((pHba->lct->table_size << 2) > pHba->lct_size) {
2906 pHba->lct_size = pHba->lct->table_size << 2;
2907 dma_free_coherent(&pHba->pDev->dev, pHba->lct_size,
2908 pHba->lct, pHba->lct_pa);
2911 } while (pHba->lct == NULL);
2913 PDEBUG("%s: Hardware resource table read.\n", pHba->name);
2916 // I2O_DPT_EXEC_IOP_BUFFERS_GROUP_NO;
2917 if(adpt_i2o_query_scalar(pHba, 0 , 0x8000, -1, buf, sizeof(buf))>=0) {
2918 pHba->FwDebugBufferSize = buf[1];
2919 pHba->FwDebugBuffer_P = pHba->base_addr_virt + buf[0];
2920 pHba->FwDebugFlags_P = pHba->FwDebugBuffer_P + FW_DEBUG_FLAGS_OFFSET;
2921 pHba->FwDebugBLEDvalue_P = pHba->FwDebugBuffer_P + FW_DEBUG_BLED_OFFSET;
2922 pHba->FwDebugBLEDflag_P = pHba->FwDebugBLEDvalue_P + 1;
2923 pHba->FwDebugStrLength_P = pHba->FwDebugBuffer_P + FW_DEBUG_STR_LENGTH_OFFSET;
2924 pHba->FwDebugBuffer_P += buf[2];
2925 pHba->FwDebugFlags = 0;
2931 static int adpt_i2o_build_sys_table(void)
2933 adpt_hba* pHba = hba_chain;
2937 dma_free_coherent(&pHba->pDev->dev, sys_tbl_len,
2938 sys_tbl, sys_tbl_pa);
2940 sys_tbl_len = sizeof(struct i2o_sys_tbl) + // Header + IOPs
2941 (hba_count) * sizeof(struct i2o_sys_tbl_entry);
2943 sys_tbl = dma_alloc_coherent(&pHba->pDev->dev,
2944 sys_tbl_len, &sys_tbl_pa, GFP_KERNEL);
2946 printk(KERN_WARNING "SysTab Set failed. Out of memory.\n");
2949 memset(sys_tbl, 0, sys_tbl_len);
2951 sys_tbl->num_entries = hba_count;
2952 sys_tbl->version = I2OVERSION;
2953 sys_tbl->change_ind = sys_tbl_ind++;
2955 for(pHba = hba_chain; pHba; pHba = pHba->next) {
2957 // Get updated Status Block so we have the latest information
2958 if (adpt_i2o_status_get(pHba)) {
2959 sys_tbl->num_entries--;
2960 continue; // try next one
2963 sys_tbl->iops[count].org_id = pHba->status_block->org_id;
2964 sys_tbl->iops[count].iop_id = pHba->unit + 2;
2965 sys_tbl->iops[count].seg_num = 0;
2966 sys_tbl->iops[count].i2o_version = pHba->status_block->i2o_version;
2967 sys_tbl->iops[count].iop_state = pHba->status_block->iop_state;
2968 sys_tbl->iops[count].msg_type = pHba->status_block->msg_type;
2969 sys_tbl->iops[count].frame_size = pHba->status_block->inbound_frame_size;
2970 sys_tbl->iops[count].last_changed = sys_tbl_ind - 1; // ??
2971 sys_tbl->iops[count].iop_capabilities = pHba->status_block->iop_capabilities;
2972 addr = pHba->base_addr_phys + 0x40;
2973 sys_tbl->iops[count].inbound_low = dma_low(addr);
2974 sys_tbl->iops[count].inbound_high = dma_high(addr);
2981 u32 *table = (u32*)sys_tbl;
2982 printk(KERN_DEBUG"sys_tbl_len=%d in 32bit words\n",(sys_tbl_len >>2));
2983 for(count = 0; count < (sys_tbl_len >>2); count++) {
2984 printk(KERN_INFO "sys_tbl[%d] = %0#10x\n",
2985 count, table[count]);
2995 * Dump the information block associated with a given unit (TID)
2998 static void adpt_i2o_report_hba_unit(adpt_hba* pHba, struct i2o_device *d)
3001 int unit = d->lct_data.tid;
3003 printk(KERN_INFO "TID %3.3d ", unit);
3005 if(adpt_i2o_query_scalar(pHba, unit, 0xF100, 3, buf, 16)>=0)
3008 printk(" Vendor: %-12.12s", buf);
3010 if(adpt_i2o_query_scalar(pHba, unit, 0xF100, 4, buf, 16)>=0)
3013 printk(" Device: %-12.12s", buf);
3015 if(adpt_i2o_query_scalar(pHba, unit, 0xF100, 6, buf, 8)>=0)
3018 printk(" Rev: %-12.12s\n", buf);
3021 printk(KERN_INFO "\tClass: %.21s\n", adpt_i2o_get_class_name(d->lct_data.class_id));
3022 printk(KERN_INFO "\tSubclass: 0x%04X\n", d->lct_data.sub_class);
3023 printk(KERN_INFO "\tFlags: ");
3025 if(d->lct_data.device_flags&(1<<0))
3026 printk("C"); // ConfigDialog requested
3027 if(d->lct_data.device_flags&(1<<1))
3028 printk("U"); // Multi-user capable
3029 if(!(d->lct_data.device_flags&(1<<4)))
3030 printk("P"); // Peer service enabled!
3031 if(!(d->lct_data.device_flags&(1<<5)))
3032 printk("M"); // Mgmt service enabled!
3039 * Do i2o class name lookup
3041 static const char *adpt_i2o_get_class_name(int class)
3044 static char *i2o_class_name[] = {
3046 "Device Driver Module",
3051 "Fibre Channel Port",
3052 "Fibre Channel Device",
3056 "Floppy Controller",
3058 "Secondary Bus Port",
3059 "Peer Transport Agent",
3064 switch(class&0xFFF) {
3065 case I2O_CLASS_EXECUTIVE:
3069 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
3071 case I2O_CLASS_SEQUENTIAL_STORAGE:
3077 case I2O_CLASS_FIBRE_CHANNEL_PORT:
3079 case I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL:
3081 case I2O_CLASS_SCSI_PERIPHERAL:
3083 case I2O_CLASS_ATE_PORT:
3085 case I2O_CLASS_ATE_PERIPHERAL:
3087 case I2O_CLASS_FLOPPY_CONTROLLER:
3089 case I2O_CLASS_FLOPPY_DEVICE:
3091 case I2O_CLASS_BUS_ADAPTER_PORT:
3093 case I2O_CLASS_PEER_TRANSPORT_AGENT:
3095 case I2O_CLASS_PEER_TRANSPORT:
3098 return i2o_class_name[idx];
3103 static s32 adpt_i2o_hrt_get(adpt_hba* pHba)
3106 int ret, size = sizeof(i2o_hrt);
3109 if (pHba->hrt == NULL) {
3110 pHba->hrt = dma_alloc_coherent(&pHba->pDev->dev,
3111 size, &pHba->hrt_pa, GFP_KERNEL);
3112 if (pHba->hrt == NULL) {
3113 printk(KERN_CRIT "%s: Hrt Get failed; Out of memory.\n", pHba->name);
3118 msg[0]= SIX_WORD_MSG_SIZE| SGL_OFFSET_4;
3119 msg[1]= I2O_CMD_HRT_GET<<24 | HOST_TID<<12 | ADAPTER_TID;
3122 msg[4]= (0xD0000000 | size); /* Simple transaction */
3123 msg[5]= (u32)pHba->hrt_pa; /* Dump it here */
3125 if ((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg),20))) {
3126 printk(KERN_ERR "%s: Unable to get HRT (status=%#10x)\n", pHba->name, ret);
3130 if (pHba->hrt->num_entries * pHba->hrt->entry_len << 2 > size) {
3131 int newsize = pHba->hrt->num_entries * pHba->hrt->entry_len << 2;
3132 dma_free_coherent(&pHba->pDev->dev, size,
3133 pHba->hrt, pHba->hrt_pa);
3137 } while(pHba->hrt == NULL);
3142 * Query one scalar group value or a whole scalar group.
3144 static int adpt_i2o_query_scalar(adpt_hba* pHba, int tid,
3145 int group, int field, void *buf, int buflen)
3147 u16 opblk[] = { 1, 0, I2O_PARAMS_FIELD_GET, group, 1, field };
3149 dma_addr_t opblk_pa;
3151 dma_addr_t resblk_pa;
3155 /* 8 bytes for header */
3156 resblk_va = dma_alloc_coherent(&pHba->pDev->dev,
3157 sizeof(u8) * (8 + buflen), &resblk_pa, GFP_KERNEL);
3158 if (resblk_va == NULL) {
3159 printk(KERN_CRIT "%s: query scalar failed; Out of memory.\n", pHba->name);
3163 opblk_va = dma_alloc_coherent(&pHba->pDev->dev,
3164 sizeof(opblk), &opblk_pa, GFP_KERNEL);
3165 if (opblk_va == NULL) {
3166 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3167 resblk_va, resblk_pa);
3168 printk(KERN_CRIT "%s: query operatio failed; Out of memory.\n",
3172 if (field == -1) /* whole group */
3175 memcpy(opblk_va, opblk, sizeof(opblk));
3176 size = adpt_i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET, pHba, tid,
3177 opblk_va, opblk_pa, sizeof(opblk),
3178 resblk_va, resblk_pa, sizeof(u8)*(8+buflen));
3179 dma_free_coherent(&pHba->pDev->dev, sizeof(opblk), opblk_va, opblk_pa);
3180 if (size == -ETIME) {
3181 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3182 resblk_va, resblk_pa);
3183 printk(KERN_WARNING "%s: issue params failed; Timed out.\n", pHba->name);
3185 } else if (size == -EINTR) {
3186 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3187 resblk_va, resblk_pa);
3188 printk(KERN_WARNING "%s: issue params failed; Interrupted.\n", pHba->name);
3192 memcpy(buf, resblk_va+8, buflen); /* cut off header */
3194 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3195 resblk_va, resblk_pa);
3203 /* Issue UTIL_PARAMS_GET or UTIL_PARAMS_SET
3205 * This function can be used for all UtilParamsGet/Set operations.
3206 * The OperationBlock is given in opblk-buffer,
3207 * and results are returned in resblk-buffer.
3208 * Note that the minimum sized resblk is 8 bytes and contains
3209 * ResultCount, ErrorInfoSize, BlockStatus and BlockSize.
3211 static int adpt_i2o_issue_params(int cmd, adpt_hba* pHba, int tid,
3212 void *opblk_va, dma_addr_t opblk_pa, int oplen,
3213 void *resblk_va, dma_addr_t resblk_pa, int reslen)
3216 u32 *res = (u32 *)resblk_va;
3219 msg[0] = NINE_WORD_MSG_SIZE | SGL_OFFSET_5;
3220 msg[1] = cmd << 24 | HOST_TID << 12 | tid;
3224 msg[5] = 0x54000000 | oplen; /* OperationBlock */
3225 msg[6] = (u32)opblk_pa;
3226 msg[7] = 0xD0000000 | reslen; /* ResultBlock */
3227 msg[8] = (u32)resblk_pa;
3229 if ((wait_status = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 20))) {
3230 printk("adpt_i2o_issue_params: post_wait failed (%p)\n", resblk_va);
3231 return wait_status; /* -DetailedStatus */
3234 if (res[1]&0x00FF0000) { /* BlockStatus != SUCCESS */
3235 printk(KERN_WARNING "%s: %s - Error:\n ErrorInfoSize = 0x%02x, "
3236 "BlockStatus = 0x%02x, BlockSize = 0x%04x\n",
3238 (cmd == I2O_CMD_UTIL_PARAMS_SET) ? "PARAMS_SET"
3240 res[1]>>24, (res[1]>>16)&0xFF, res[1]&0xFFFF);
3241 return -((res[1] >> 16) & 0xFF); /* -BlockStatus */
3244 return 4 + ((res[1] & 0x0000FFFF) << 2); /* bytes used in resblk */
3248 static s32 adpt_i2o_quiesce_hba(adpt_hba* pHba)
3253 adpt_i2o_status_get(pHba);
3255 /* SysQuiesce discarded if IOP not in READY or OPERATIONAL state */
3257 if((pHba->status_block->iop_state != ADAPTER_STATE_READY) &&
3258 (pHba->status_block->iop_state != ADAPTER_STATE_OPERATIONAL)){
3262 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
3263 msg[1] = I2O_CMD_SYS_QUIESCE<<24|HOST_TID<<12|ADAPTER_TID;
3267 if((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 240))) {
3268 printk(KERN_INFO"dpti%d: Unable to quiesce (status=%#x).\n",
3271 printk(KERN_INFO"dpti%d: Quiesced.\n",pHba->unit);
3274 adpt_i2o_status_get(pHba);
3280 * Enable IOP. Allows the IOP to resume external operations.
3282 static int adpt_i2o_enable_hba(adpt_hba* pHba)
3287 adpt_i2o_status_get(pHba);
3288 if(!pHba->status_block){
3291 /* Enable only allowed on READY state */
3292 if(pHba->status_block->iop_state == ADAPTER_STATE_OPERATIONAL)
3295 if(pHba->status_block->iop_state != ADAPTER_STATE_READY)
3298 msg[0]=FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
3299 msg[1]=I2O_CMD_SYS_ENABLE<<24|HOST_TID<<12|ADAPTER_TID;
3303 if ((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 240))) {
3304 printk(KERN_WARNING"%s: Could not enable (status=%#10x).\n",
3307 PDEBUG("%s: Enabled.\n", pHba->name);
3310 adpt_i2o_status_get(pHba);
3315 static int adpt_i2o_systab_send(adpt_hba* pHba)
3320 msg[0] = I2O_MESSAGE_SIZE(12) | SGL_OFFSET_6;
3321 msg[1] = I2O_CMD_SYS_TAB_SET<<24 | HOST_TID<<12 | ADAPTER_TID;
3324 msg[4] = (0<<16) | ((pHba->unit+2) << 12); /* Host 0 IOP ID (unit + 2) */
3325 msg[5] = 0; /* Segment 0 */
3328 * Provide three SGL-elements:
3329 * System table (SysTab), Private memory space declaration and
3330 * Private i/o space declaration
3332 msg[6] = 0x54000000 | sys_tbl_len;
3333 msg[7] = (u32)sys_tbl_pa;
3334 msg[8] = 0x54000000 | 0;
3336 msg[10] = 0xD4000000 | 0;
3339 if ((ret=adpt_i2o_post_wait(pHba, msg, sizeof(msg), 120))) {
3340 printk(KERN_INFO "%s: Unable to set SysTab (status=%#10x).\n",
3345 PINFO("%s: SysTab set.\n", pHba->name);
3353 /*============================================================================
3355 *============================================================================
3361 static static void adpt_delay(int millisec)
3364 for (i = 0; i < millisec; i++) {
3365 udelay(1000); /* delay for one millisecond */
3371 static struct scsi_host_template driver_template = {
3372 .module = THIS_MODULE,
3374 .proc_name = "dpt_i2o",
3375 .proc_info = adpt_proc_info,
3377 .queuecommand = adpt_queue,
3378 .eh_abort_handler = adpt_abort,
3379 .eh_device_reset_handler = adpt_device_reset,
3380 .eh_bus_reset_handler = adpt_bus_reset,
3381 .eh_host_reset_handler = adpt_reset,
3382 .bios_param = adpt_bios_param,
3383 .slave_configure = adpt_slave_configure,
3384 .can_queue = MAX_TO_IOP_MESSAGES,
3387 .use_clustering = ENABLE_CLUSTERING,
3390 static int __init adpt_init(void)
3393 adpt_hba *pHba, *next;
3395 printk("Loading Adaptec I2O RAID: Version " DPT_I2O_VERSION "\n");
3397 error = adpt_detect(&driver_template);
3400 if (hba_chain == NULL)
3403 for (pHba = hba_chain; pHba; pHba = pHba->next) {
3404 error = scsi_add_host(pHba->host, &pHba->pDev->dev);
3407 scsi_scan_host(pHba->host);
3411 for (pHba = hba_chain; pHba; pHba = next) {
3413 scsi_remove_host(pHba->host);
3418 static void __exit adpt_exit(void)
3420 adpt_hba *pHba, *next;
3422 for (pHba = hba_chain; pHba; pHba = pHba->next)
3423 scsi_remove_host(pHba->host);
3424 for (pHba = hba_chain; pHba; pHba = next) {
3426 adpt_release(pHba->host);
3430 module_init(adpt_init);
3431 module_exit(adpt_exit);
3433 MODULE_LICENSE("GPL");