1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /***************************************************************************
6 copyright : (C) 2000 by Adaptec
8 July 30, 2001 First version being submitted
9 for inclusion in the kernel. V2.4
11 See Documentation/scsi/dpti.rst for history, notes, license info
13 ***************************************************************************/
15 /***************************************************************************
18 ***************************************************************************/
19 /***************************************************************************
20 * Sat Dec 20 2003 Go Taniguchi <go@turbolinux.co.jp>
21 - Support 2.6 kernel and DMA-mapping
22 - ioctl fix for raid tools
23 - use schedule_timeout in long long loop
24 **************************************************************************/
27 /*#define UARTDELAY 1 */
29 #include <linux/module.h>
30 #include <linux/pgtable.h>
32 MODULE_AUTHOR("Deanna Bonds, with _lots_ of help from Mark Salyzyn");
33 MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
35 ////////////////////////////////////////////////////////////////
37 #include <linux/ioctl.h> /* For SCSI-Passthrough */
38 #include <linux/uaccess.h>
40 #include <linux/stat.h>
41 #include <linux/slab.h> /* for kmalloc() */
42 #include <linux/pci.h> /* for PCI support */
43 #include <linux/proc_fs.h>
44 #include <linux/blkdev.h>
45 #include <linux/delay.h> /* for udelay */
46 #include <linux/interrupt.h>
47 #include <linux/kernel.h> /* for printk */
48 #include <linux/sched.h>
49 #include <linux/reboot.h>
50 #include <linux/spinlock.h>
51 #include <linux/dma-mapping.h>
53 #include <linux/timer.h>
54 #include <linux/string.h>
55 #include <linux/ioport.h>
56 #include <linux/mutex.h>
58 #include <asm/processor.h> /* for boot_cpu_data */
61 #include <scsi/scsi.h>
62 #include <scsi/scsi_cmnd.h>
63 #include <scsi/scsi_device.h>
64 #include <scsi/scsi_host.h>
65 #include <scsi/scsi_tcq.h>
67 #include "dpt/dptsig.h"
70 /*============================================================================
71 * Create a binary signature - this is read by dptsig
72 * Needed for our management apps
73 *============================================================================
75 static DEFINE_MUTEX(adpt_mutex);
76 static dpt_sig_S DPTI_sig = {
77 {'d', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION,
79 PROC_INTEL, PROC_386 | PROC_486 | PROC_PENTIUM | PROC_SEXIUM,
80 #elif defined(__ia64__)
81 PROC_INTEL, PROC_IA64,
82 #elif defined(__sparc__)
83 PROC_ULTRASPARC, PROC_ULTRASPARC,
84 #elif defined(__alpha__)
85 PROC_ALPHA, PROC_ALPHA,
89 FT_HBADRVR, 0, OEM_DPT, OS_LINUX, CAP_OVERLAP, DEV_ALL,
90 ADF_ALL_SC5, 0, 0, DPT_VERSION, DPT_REVISION, DPT_SUBREVISION,
91 DPT_MONTH, DPT_DAY, DPT_YEAR, "Adaptec Linux I2O RAID Driver"
97 /*============================================================================
99 *============================================================================
102 static DEFINE_MUTEX(adpt_configuration_lock);
104 static struct i2o_sys_tbl *sys_tbl;
105 static dma_addr_t sys_tbl_pa;
106 static int sys_tbl_ind;
107 static int sys_tbl_len;
109 static adpt_hba* hba_chain = NULL;
110 static int hba_count = 0;
112 static struct class *adpt_sysfs_class;
114 static long adpt_unlocked_ioctl(struct file *, unsigned int, unsigned long);
116 static long compat_adpt_ioctl(struct file *, unsigned int, unsigned long);
119 static const struct file_operations adpt_fops = {
120 .unlocked_ioctl = adpt_unlocked_ioctl,
122 .release = adpt_close,
124 .compat_ioctl = compat_adpt_ioctl,
126 .llseek = noop_llseek,
129 /* Structures and definitions for synchronous message posting.
130 * See adpt_i2o_post_wait() for description
132 struct adpt_i2o_post_wait_data
136 adpt_wait_queue_head_t *wq;
137 struct adpt_i2o_post_wait_data *next;
140 static struct adpt_i2o_post_wait_data *adpt_post_wait_queue = NULL;
141 static u32 adpt_post_wait_id = 0;
142 static DEFINE_SPINLOCK(adpt_post_wait_lock);
145 /*============================================================================
147 *============================================================================
150 static inline int dpt_dma64(adpt_hba *pHba)
152 return (sizeof(dma_addr_t) > 4 && (pHba)->dma64);
155 static inline u32 dma_high(dma_addr_t addr)
157 return upper_32_bits(addr);
160 static inline u32 dma_low(dma_addr_t addr)
165 static u8 adpt_read_blink_led(adpt_hba* host)
167 if (host->FwDebugBLEDflag_P) {
168 if( readb(host->FwDebugBLEDflag_P) == 0xbc ){
169 return readb(host->FwDebugBLEDvalue_P);
175 /*============================================================================
176 * Scsi host template interface functions
177 *============================================================================
181 static struct pci_device_id dptids[] = {
182 { PCI_DPT_VENDOR_ID, PCI_DPT_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
183 { PCI_DPT_VENDOR_ID, PCI_DPT_RAPTOR_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
188 MODULE_DEVICE_TABLE(pci,dptids);
190 static int adpt_detect(struct scsi_host_template* sht)
192 struct pci_dev *pDev = NULL;
196 PINFO("Detecting Adaptec I2O RAID controllers...\n");
198 /* search for all Adatpec I2O RAID cards */
199 while ((pDev = pci_get_device( PCI_DPT_VENDOR_ID, PCI_ANY_ID, pDev))) {
200 if(pDev->device == PCI_DPT_DEVICE_ID ||
201 pDev->device == PCI_DPT_RAPTOR_DEVICE_ID){
202 if(adpt_install_hba(sht, pDev) ){
203 PERROR("Could not Init an I2O RAID device\n");
204 PERROR("Will not try to detect others.\n");
211 /* In INIT state, Activate IOPs */
212 for (pHba = hba_chain; pHba; pHba = next) {
214 // Activate does get status , init outbound, and get hrt
215 if (adpt_i2o_activate_hba(pHba) < 0) {
216 adpt_i2o_delete_hba(pHba);
221 /* Active IOPs in HOLD state */
224 if (hba_chain == NULL)
228 * If build_sys_table fails, we kill everything and bail
229 * as we can't init the IOPs w/o a system table
231 if (adpt_i2o_build_sys_table() < 0) {
232 adpt_i2o_sys_shutdown();
236 PDEBUG("HBA's in HOLD state\n");
238 /* If IOP don't get online, we need to rebuild the System table */
239 for (pHba = hba_chain; pHba; pHba = pHba->next) {
240 if (adpt_i2o_online_hba(pHba) < 0) {
241 adpt_i2o_delete_hba(pHba);
242 goto rebuild_sys_tab;
246 /* Active IOPs now in OPERATIONAL state */
247 PDEBUG("HBA's in OPERATIONAL state\n");
249 printk("dpti: If you have a lot of devices this could take a few minutes.\n");
250 for (pHba = hba_chain; pHba; pHba = next) {
252 printk(KERN_INFO"%s: Reading the hardware resource table.\n", pHba->name);
253 if (adpt_i2o_lct_get(pHba) < 0){
254 adpt_i2o_delete_hba(pHba);
258 if (adpt_i2o_parse_lct(pHba) < 0){
259 adpt_i2o_delete_hba(pHba);
265 adpt_sysfs_class = class_create(THIS_MODULE, "dpt_i2o");
266 if (IS_ERR(adpt_sysfs_class)) {
267 printk(KERN_WARNING"dpti: unable to create dpt_i2o class\n");
268 adpt_sysfs_class = NULL;
271 for (pHba = hba_chain; pHba; pHba = next) {
273 if (adpt_scsi_host_alloc(pHba, sht) < 0){
274 adpt_i2o_delete_hba(pHba);
277 pHba->initialized = TRUE;
278 pHba->state &= ~DPTI_STATE_RESET;
279 if (adpt_sysfs_class) {
280 struct device *dev = device_create(adpt_sysfs_class,
281 NULL, MKDEV(DPTI_I2O_MAJOR, pHba->unit), NULL,
282 "dpti%d", pHba->unit);
284 printk(KERN_WARNING"dpti%d: unable to "
285 "create device in dpt_i2o class\n",
291 // Register our control device node
292 // nodes will need to be created in /dev to access this
293 // the nodes can not be created from within the driver
294 if (hba_count && register_chrdev(DPTI_I2O_MAJOR, DPT_DRIVER, &adpt_fops)) {
295 adpt_i2o_sys_shutdown();
302 static void adpt_release(adpt_hba *pHba)
304 struct Scsi_Host *shost = pHba->host;
306 scsi_remove_host(shost);
307 // adpt_i2o_quiesce_hba(pHba);
308 adpt_i2o_delete_hba(pHba);
309 scsi_host_put(shost);
313 static void adpt_inquiry(adpt_hba* pHba)
327 memset(msg, 0, sizeof(msg));
328 buf = dma_alloc_coherent(&pHba->pDev->dev, 80, &addr, GFP_KERNEL);
330 printk(KERN_ERR"%s: Could not allocate buffer\n",pHba->name);
333 memset((void*)buf, 0, 36);
336 direction = 0x00000000;
337 scsidir =0x40000000; // DATA IN (iop<--dev)
340 reqlen = 17; // SINGLE SGE, 64 bit
342 reqlen = 14; // SINGLE SGE, 32 bit
343 /* Stick the headers on */
344 msg[0] = reqlen<<16 | SGL_OFFSET_12;
345 msg[1] = (0xff<<24|HOST_TID<<12|ADAPTER_TID);
348 // Adaptec/DPT Private stuff
349 msg[4] = I2O_CMD_SCSI_EXEC|DPT_ORGANIZATION_ID<<16;
350 msg[5] = ADAPTER_TID | 1<<16 /* Interpret*/;
351 /* Direction, disconnect ok | sense data | simple queue , CDBLen */
352 // I2O_SCB_FLAG_ENABLE_DISCONNECT |
353 // I2O_SCB_FLAG_SIMPLE_QUEUE_TAG |
354 // I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
355 msg[6] = scsidir|0x20a00000| 6 /* cmd len*/;
359 memset(scb, 0, sizeof(scb));
360 // Write SCSI command into the message - always 16 byte block
367 // Don't care about the rest of scb
369 memcpy(mptr, scb, sizeof(scb));
371 lenptr=mptr++; /* Remember me - fill in when we know */
373 /* Now fill in the SGList and command */
375 if (dpt_dma64(pHba)) {
376 *mptr++ = (0x7C<<24)+(2<<16)+0x02; /* Enable 64 bit */
377 *mptr++ = 1 << PAGE_SHIFT;
378 *mptr++ = 0xD0000000|direction|len;
379 *mptr++ = dma_low(addr);
380 *mptr++ = dma_high(addr);
382 *mptr++ = 0xD0000000|direction|len;
386 // Send it on it's way
387 rcode = adpt_i2o_post_wait(pHba, msg, reqlen<<2, 120);
389 sprintf(pHba->detail, "Adaptec I2O RAID");
390 printk(KERN_INFO "%s: Inquiry Error (%d)\n",pHba->name,rcode);
391 if (rcode != -ETIME && rcode != -EINTR)
392 dma_free_coherent(&pHba->pDev->dev, 80, buf, addr);
394 memset(pHba->detail, 0, sizeof(pHba->detail));
395 memcpy(&(pHba->detail), "Vendor: Adaptec ", 16);
396 memcpy(&(pHba->detail[16]), " Model: ", 8);
397 memcpy(&(pHba->detail[24]), (u8*) &buf[16], 16);
398 memcpy(&(pHba->detail[40]), " FW: ", 4);
399 memcpy(&(pHba->detail[44]), (u8*) &buf[32], 4);
400 pHba->detail[48] = '\0'; /* precautionary */
401 dma_free_coherent(&pHba->pDev->dev, 80, buf, addr);
403 adpt_i2o_status_get(pHba);
408 static int adpt_slave_configure(struct scsi_device * device)
410 struct Scsi_Host *host = device->host;
412 if (host->can_queue && device->tagged_supported) {
413 scsi_change_queue_depth(device,
414 host->can_queue - 1);
419 static int adpt_queue_lck(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *))
421 adpt_hba* pHba = NULL;
422 struct adpt_device* pDev = NULL; /* dpt per device information */
424 cmd->scsi_done = done;
426 * SCSI REQUEST_SENSE commands will be executed automatically by the
427 * Host Adapter for any errors, so they should not be executed
428 * explicitly unless the Sense Data is zero indicating that no error
432 if ((cmd->cmnd[0] == REQUEST_SENSE) && (cmd->sense_buffer[0] != 0)) {
433 cmd->result = (DID_OK << 16);
438 pHba = (adpt_hba*)cmd->device->host->hostdata[0];
444 if ((pHba->state) & DPTI_STATE_RESET)
445 return SCSI_MLQUEUE_HOST_BUSY;
447 // TODO if the cmd->device if offline then I may need to issue a bus rescan
448 // followed by a get_lct to see if the device is there anymore
449 if((pDev = (struct adpt_device*) (cmd->device->hostdata)) == NULL) {
451 * First command request for this device. Set up a pointer
452 * to the device structure. This should be a TEST_UNIT_READY
453 * command from scan_scsis_single.
455 if ((pDev = adpt_find_device(pHba, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun)) == NULL) {
456 // TODO: if any luns are at this bus, scsi id then fake a TEST_UNIT_READY and INQUIRY response
457 // with type 7F (for all luns less than the max for this bus,id) so the lun scan will continue.
458 cmd->result = (DID_NO_CONNECT << 16);
462 cmd->device->hostdata = pDev;
464 pDev->pScsi_dev = cmd->device;
467 * If we are being called from when the device is being reset,
468 * delay processing of the command until later.
470 if (pDev->state & DPTI_DEV_RESET ) {
473 return adpt_scsi_to_i2o(pHba, cmd, pDev);
476 static DEF_SCSI_QCMD(adpt_queue)
478 static int adpt_bios_param(struct scsi_device *sdev, struct block_device *dev,
479 sector_t capacity, int geom[])
485 // *** First lets set the default geometry ****
487 // If the capacity is less than ox2000
488 if (capacity < 0x2000 ) { // floppy
492 // else if between 0x2000 and 0x20000
493 else if (capacity < 0x20000) {
497 // else if between 0x20000 and 0x40000
498 else if (capacity < 0x40000) {
502 // else if between 0x4000 and 0x80000
503 else if (capacity < 0x80000) {
507 // else if greater than 0x80000
512 cylinders = sector_div(capacity, heads * sectors);
514 // Special case if CDROM
515 if(sdev->type == 5) { // CDROM
525 PDEBUG("adpt_bios_param: exit\n");
530 static const char *adpt_info(struct Scsi_Host *host)
534 pHba = (adpt_hba *) host->hostdata[0];
535 return (char *) (pHba->detail);
538 static int adpt_show_info(struct seq_file *m, struct Scsi_Host *host)
540 struct adpt_device* d;
546 // Find HBA (host bus adapter) we are looking for
547 mutex_lock(&adpt_configuration_lock);
548 for (pHba = hba_chain; pHba; pHba = pHba->next) {
549 if (pHba->host == host) {
550 break; /* found adapter */
553 mutex_unlock(&adpt_configuration_lock);
559 seq_printf(m, "Adaptec I2O RAID Driver Version: %s\n\n", DPT_I2O_VERSION);
560 seq_printf(m, "%s\n", pHba->detail);
561 seq_printf(m, "SCSI Host=scsi%d Control Node=/dev/%s irq=%d\n",
562 pHba->host->host_no, pHba->name, host->irq);
563 seq_printf(m, "\tpost fifo size = %d\n\treply fifo size = %d\n\tsg table size = %d\n\n",
564 host->can_queue, (int) pHba->reply_fifo_size , host->sg_tablesize);
566 seq_puts(m, "Devices:\n");
567 for(chan = 0; chan < MAX_CHANNEL; chan++) {
568 for(id = 0; id < MAX_ID; id++) {
569 d = pHba->channel[chan].device[id];
571 seq_printf(m,"\t%-24.24s", d->pScsi_dev->vendor);
572 seq_printf(m," Rev: %-8.8s\n", d->pScsi_dev->rev);
574 unit = d->pI2o_dev->lct_data.tid;
575 seq_printf(m, "\tTID=%d, (Channel=%d, Target=%d, Lun=%llu) (%s)\n\n",
576 unit, (int)d->scsi_channel, (int)d->scsi_id, d->scsi_lun,
577 scsi_device_online(d->pScsi_dev)? "online":"offline");
585 /*===========================================================================
586 * Error Handling routines
587 *===========================================================================
590 static int adpt_abort(struct scsi_cmnd * cmd)
592 adpt_hba* pHba = NULL; /* host bus adapter structure */
593 struct adpt_device* dptdevice; /* dpt per device information */
597 pHba = (adpt_hba*) cmd->device->host->hostdata[0];
598 printk(KERN_INFO"%s: Trying to Abort\n",pHba->name);
599 if ((dptdevice = (void*) (cmd->device->hostdata)) == NULL) {
600 printk(KERN_ERR "%s: Unable to abort: No device in cmnd\n",pHba->name);
604 memset(msg, 0, sizeof(msg));
605 msg[0] = FIVE_WORD_MSG_SIZE|SGL_OFFSET_0;
606 msg[1] = I2O_CMD_SCSI_ABORT<<24|HOST_TID<<12|dptdevice->tid;
609 /* Add 1 to avoid firmware treating it as invalid command */
610 msg[4] = cmd->request->tag + 1;
612 spin_lock_irq(pHba->host->host_lock);
613 rcode = adpt_i2o_post_wait(pHba, msg, sizeof(msg), FOREVER);
615 spin_unlock_irq(pHba->host->host_lock);
617 if(rcode == -EOPNOTSUPP ){
618 printk(KERN_INFO"%s: Abort cmd not supported\n",pHba->name);
621 printk(KERN_INFO"%s: Abort failed.\n",pHba->name);
624 printk(KERN_INFO"%s: Abort complete.\n",pHba->name);
629 #define I2O_DEVICE_RESET 0x27
630 // This is the same for BLK and SCSI devices
631 // NOTE this is wrong in the i2o.h definitions
632 // This is not currently supported by our adapter but we issue it anyway
633 static int adpt_device_reset(struct scsi_cmnd* cmd)
639 struct adpt_device* d = cmd->device->hostdata;
641 pHba = (void*) cmd->device->host->hostdata[0];
642 printk(KERN_INFO"%s: Trying to reset device\n",pHba->name);
644 printk(KERN_INFO"%s: Reset Device: Device Not found\n",pHba->name);
647 memset(msg, 0, sizeof(msg));
648 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
649 msg[1] = (I2O_DEVICE_RESET<<24|HOST_TID<<12|d->tid);
654 spin_lock_irq(pHba->host->host_lock);
655 old_state = d->state;
656 d->state |= DPTI_DEV_RESET;
657 rcode = adpt_i2o_post_wait(pHba, msg,sizeof(msg), FOREVER);
658 d->state = old_state;
660 spin_unlock_irq(pHba->host->host_lock);
662 if(rcode == -EOPNOTSUPP ){
663 printk(KERN_INFO"%s: Device reset not supported\n",pHba->name);
666 printk(KERN_INFO"%s: Device reset failed\n",pHba->name);
669 printk(KERN_INFO"%s: Device reset successful\n",pHba->name);
675 #define I2O_HBA_BUS_RESET 0x87
676 // This version of bus reset is called by the eh_error handler
677 static int adpt_bus_reset(struct scsi_cmnd* cmd)
683 pHba = (adpt_hba*)cmd->device->host->hostdata[0];
684 memset(msg, 0, sizeof(msg));
685 printk(KERN_WARNING"%s: Bus reset: SCSI Bus %d: tid: %d\n",pHba->name, cmd->device->channel,pHba->channel[cmd->device->channel].tid );
686 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
687 msg[1] = (I2O_HBA_BUS_RESET<<24|HOST_TID<<12|pHba->channel[cmd->device->channel].tid);
691 spin_lock_irq(pHba->host->host_lock);
692 rcode = adpt_i2o_post_wait(pHba, msg,sizeof(msg), FOREVER);
694 spin_unlock_irq(pHba->host->host_lock);
696 printk(KERN_WARNING"%s: Bus reset failed.\n",pHba->name);
699 printk(KERN_WARNING"%s: Bus reset success.\n",pHba->name);
704 // This version of reset is called by the eh_error_handler
705 static int __adpt_reset(struct scsi_cmnd* cmd)
711 pHba = (adpt_hba*)cmd->device->host->hostdata[0];
712 strncpy(name, pHba->name, sizeof(name));
713 printk(KERN_WARNING"%s: Hba Reset: scsi id %d: tid: %d\n", name, cmd->device->channel, pHba->channel[cmd->device->channel].tid);
714 rcode = adpt_hba_reset(pHba);
716 printk(KERN_WARNING"%s: HBA reset complete\n", name);
719 printk(KERN_WARNING"%s: HBA reset failed (%x)\n", name, rcode);
724 static int adpt_reset(struct scsi_cmnd* cmd)
728 spin_lock_irq(cmd->device->host->host_lock);
729 rc = __adpt_reset(cmd);
730 spin_unlock_irq(cmd->device->host->host_lock);
735 // This version of reset is called by the ioctls and indirectly from eh_error_handler via adpt_reset
736 static int adpt_hba_reset(adpt_hba* pHba)
740 pHba->state |= DPTI_STATE_RESET;
742 // Activate does get status , init outbound, and get hrt
743 if ((rcode=adpt_i2o_activate_hba(pHba)) < 0) {
744 printk(KERN_ERR "%s: Could not activate\n", pHba->name);
745 adpt_i2o_delete_hba(pHba);
749 if ((rcode=adpt_i2o_build_sys_table()) < 0) {
750 adpt_i2o_delete_hba(pHba);
753 PDEBUG("%s: in HOLD state\n",pHba->name);
755 if ((rcode=adpt_i2o_online_hba(pHba)) < 0) {
756 adpt_i2o_delete_hba(pHba);
759 PDEBUG("%s: in OPERATIONAL state\n",pHba->name);
761 if ((rcode=adpt_i2o_lct_get(pHba)) < 0){
762 adpt_i2o_delete_hba(pHba);
766 if ((rcode=adpt_i2o_reparse_lct(pHba)) < 0){
767 adpt_i2o_delete_hba(pHba);
770 pHba->state &= ~DPTI_STATE_RESET;
772 scsi_host_complete_all_commands(pHba->host, DID_RESET);
773 return 0; /* return success */
776 /*===========================================================================
778 *===========================================================================
782 static void adpt_i2o_sys_shutdown(void)
784 adpt_hba *pHba, *pNext;
785 struct adpt_i2o_post_wait_data *p1, *old;
787 printk(KERN_INFO "Shutting down Adaptec I2O controllers.\n");
788 printk(KERN_INFO " This could take a few minutes if there are many devices attached\n");
789 /* Delete all IOPs from the controller chain */
790 /* They should have already been released by the
793 for (pHba = hba_chain; pHba; pHba = pNext) {
795 adpt_i2o_delete_hba(pHba);
798 /* Remove any timedout entries from the wait queue. */
799 // spin_lock_irqsave(&adpt_post_wait_lock, flags);
800 /* Nothing should be outstanding at this point so just
803 for(p1 = adpt_post_wait_queue; p1;) {
808 // spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
809 adpt_post_wait_queue = NULL;
811 printk(KERN_INFO "Adaptec I2O controllers down.\n");
814 static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev)
817 adpt_hba* pHba = NULL;
819 ulong base_addr0_phys = 0;
820 ulong base_addr1_phys = 0;
821 u32 hba_map0_area_size = 0;
822 u32 hba_map1_area_size = 0;
823 void __iomem *base_addr_virt = NULL;
824 void __iomem *msg_addr_virt = NULL;
827 int raptorFlag = FALSE;
829 if(pci_enable_device(pDev)) {
833 if (pci_request_regions(pDev, "dpt_i2o")) {
834 PERROR("dpti: adpt_config_hba: pci request region failed\n");
838 pci_set_master(pDev);
841 * See if we should enable dma64 mode.
843 if (sizeof(dma_addr_t) > 4 &&
844 dma_get_required_mask(&pDev->dev) > DMA_BIT_MASK(32) &&
845 dma_set_mask(&pDev->dev, DMA_BIT_MASK(64)) == 0)
848 if (!dma64 && dma_set_mask(&pDev->dev, DMA_BIT_MASK(32)) != 0)
851 /* adapter only supports message blocks below 4GB */
852 dma_set_coherent_mask(&pDev->dev, DMA_BIT_MASK(32));
854 base_addr0_phys = pci_resource_start(pDev,0);
855 hba_map0_area_size = pci_resource_len(pDev,0);
857 // Check if standard PCI card or single BAR Raptor
858 if(pDev->device == PCI_DPT_DEVICE_ID){
859 if(pDev->subsystem_device >=0xc032 && pDev->subsystem_device <= 0xc03b){
860 // Raptor card with this device id needs 4M
861 hba_map0_area_size = 0x400000;
862 } else { // Not Raptor - it is a PCI card
863 if(hba_map0_area_size > 0x100000 ){
864 hba_map0_area_size = 0x100000;
867 } else {// Raptor split BAR config
868 // Use BAR1 in this configuration
869 base_addr1_phys = pci_resource_start(pDev,1);
870 hba_map1_area_size = pci_resource_len(pDev,1);
874 #if BITS_PER_LONG == 64
876 * The original Adaptec 64 bit driver has this comment here:
877 * "x86_64 machines need more optimal mappings"
879 * I assume some HBAs report ridiculously large mappings
880 * and we need to limit them on platforms with IOMMUs.
882 if (raptorFlag == TRUE) {
883 if (hba_map0_area_size > 128)
884 hba_map0_area_size = 128;
885 if (hba_map1_area_size > 524288)
886 hba_map1_area_size = 524288;
888 if (hba_map0_area_size > 524288)
889 hba_map0_area_size = 524288;
893 base_addr_virt = ioremap(base_addr0_phys,hba_map0_area_size);
894 if (!base_addr_virt) {
895 pci_release_regions(pDev);
896 PERROR("dpti: adpt_config_hba: io remap failed\n");
900 if(raptorFlag == TRUE) {
901 msg_addr_virt = ioremap(base_addr1_phys, hba_map1_area_size );
902 if (!msg_addr_virt) {
903 PERROR("dpti: adpt_config_hba: io remap failed on BAR1\n");
904 iounmap(base_addr_virt);
905 pci_release_regions(pDev);
909 msg_addr_virt = base_addr_virt;
912 // Allocate and zero the data structure
913 pHba = kzalloc(sizeof(adpt_hba), GFP_KERNEL);
915 if (msg_addr_virt != base_addr_virt)
916 iounmap(msg_addr_virt);
917 iounmap(base_addr_virt);
918 pci_release_regions(pDev);
922 mutex_lock(&adpt_configuration_lock);
924 if(hba_chain != NULL){
925 for(p = hba_chain; p->next; p = p->next);
931 pHba->unit = hba_count;
932 sprintf(pHba->name, "dpti%d", hba_count);
935 mutex_unlock(&adpt_configuration_lock);
938 pHba->base_addr_phys = base_addr0_phys;
940 // Set up the Virtual Base Address of the I2O Device
941 pHba->base_addr_virt = base_addr_virt;
942 pHba->msg_addr_virt = msg_addr_virt;
943 pHba->irq_mask = base_addr_virt+0x30;
944 pHba->post_port = base_addr_virt+0x40;
945 pHba->reply_port = base_addr_virt+0x44;
950 pHba->status_block = NULL;
951 pHba->post_count = 0;
952 pHba->state = DPTI_STATE_RESET;
954 pHba->devices = NULL;
957 // Initializing the spinlocks
958 spin_lock_init(&pHba->state_lock);
959 spin_lock_init(&adpt_post_wait_lock);
962 printk(KERN_INFO "Adaptec I2O RAID controller"
963 " %d at %p size=%x irq=%d%s\n",
964 hba_count-1, base_addr_virt,
965 hba_map0_area_size, pDev->irq,
966 dma64 ? " (64-bit DMA)" : "");
968 printk(KERN_INFO"Adaptec I2O RAID controller %d irq=%d%s\n",
969 hba_count-1, pDev->irq,
970 dma64 ? " (64-bit DMA)" : "");
971 printk(KERN_INFO" BAR0 %p - size= %x\n",base_addr_virt,hba_map0_area_size);
972 printk(KERN_INFO" BAR1 %p - size= %x\n",msg_addr_virt,hba_map1_area_size);
975 if (request_irq (pDev->irq, adpt_isr, IRQF_SHARED, pHba->name, pHba)) {
976 printk(KERN_ERR"%s: Couldn't register IRQ %d\n", pHba->name, pDev->irq);
977 adpt_i2o_delete_hba(pHba);
985 static void adpt_i2o_delete_hba(adpt_hba* pHba)
989 struct i2o_device* d;
990 struct i2o_device* next;
993 struct adpt_device* pDev;
994 struct adpt_device* pNext;
997 mutex_lock(&adpt_configuration_lock);
999 free_irq(pHba->host->irq, pHba);
1002 for( p1 = hba_chain; p1; p2 = p1,p1=p1->next){
1005 p2->next = p1->next;
1007 hba_chain = p1->next;
1014 mutex_unlock(&adpt_configuration_lock);
1016 iounmap(pHba->base_addr_virt);
1017 pci_release_regions(pHba->pDev);
1018 if(pHba->msg_addr_virt != pHba->base_addr_virt){
1019 iounmap(pHba->msg_addr_virt);
1021 if(pHba->FwDebugBuffer_P)
1022 iounmap(pHba->FwDebugBuffer_P);
1024 dma_free_coherent(&pHba->pDev->dev,
1025 pHba->hrt->num_entries * pHba->hrt->entry_len << 2,
1026 pHba->hrt, pHba->hrt_pa);
1029 dma_free_coherent(&pHba->pDev->dev, pHba->lct_size,
1030 pHba->lct, pHba->lct_pa);
1032 if(pHba->status_block) {
1033 dma_free_coherent(&pHba->pDev->dev, sizeof(i2o_status_block),
1034 pHba->status_block, pHba->status_block_pa);
1036 if(pHba->reply_pool) {
1037 dma_free_coherent(&pHba->pDev->dev,
1038 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
1039 pHba->reply_pool, pHba->reply_pool_pa);
1042 for(d = pHba->devices; d ; d = next){
1046 for(i = 0 ; i < pHba->top_scsi_channel ; i++){
1047 for(j = 0; j < MAX_ID; j++){
1048 if(pHba->channel[i].device[j] != NULL){
1049 for(pDev = pHba->channel[i].device[j]; pDev; pDev = pNext){
1050 pNext = pDev->next_lun;
1056 pci_dev_put(pHba->pDev);
1057 if (adpt_sysfs_class)
1058 device_destroy(adpt_sysfs_class,
1059 MKDEV(DPTI_I2O_MAJOR, pHba->unit));
1063 unregister_chrdev(DPTI_I2O_MAJOR, DPT_DRIVER);
1064 if (adpt_sysfs_class) {
1065 class_destroy(adpt_sysfs_class);
1066 adpt_sysfs_class = NULL;
1071 static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u64 lun)
1073 struct adpt_device* d;
1075 if (chan >= MAX_CHANNEL)
1078 d = pHba->channel[chan].device[id];
1079 if(!d || d->tid == 0) {
1083 /* If it is the only lun at that address then this should match*/
1084 if(d->scsi_lun == lun){
1088 /* else we need to look through all the luns */
1089 for(d=d->next_lun ; d ; d = d->next_lun){
1090 if(d->scsi_lun == lun){
1098 static int adpt_i2o_post_wait(adpt_hba* pHba, u32* msg, int len, int timeout)
1100 // I used my own version of the WAIT_QUEUE_HEAD
1101 // to handle some version differences
1102 // When embedded in the kernel this could go back to the vanilla one
1103 ADPT_DECLARE_WAIT_QUEUE_HEAD(adpt_wq_i2o_post);
1106 struct adpt_i2o_post_wait_data *p1, *p2;
1107 struct adpt_i2o_post_wait_data *wait_data =
1108 kmalloc(sizeof(struct adpt_i2o_post_wait_data), GFP_ATOMIC);
1109 DECLARE_WAITQUEUE(wait, current);
1115 * The spin locking is needed to keep anyone from playing
1116 * with the queue pointers and id while we do the same
1118 spin_lock_irqsave(&adpt_post_wait_lock, flags);
1119 // TODO we need a MORE unique way of getting ids
1120 // to support async LCT get
1121 wait_data->next = adpt_post_wait_queue;
1122 adpt_post_wait_queue = wait_data;
1123 adpt_post_wait_id++;
1124 adpt_post_wait_id &= 0x7fff;
1125 wait_data->id = adpt_post_wait_id;
1126 spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
1128 wait_data->wq = &adpt_wq_i2o_post;
1129 wait_data->status = -ETIMEDOUT;
1131 add_wait_queue(&adpt_wq_i2o_post, &wait);
1133 msg[2] |= 0x80000000 | ((u32)wait_data->id);
1135 if((status = adpt_i2o_post_this(pHba, msg, len)) == 0){
1136 set_current_state(TASK_INTERRUPTIBLE);
1138 spin_unlock_irq(pHba->host->host_lock);
1142 timeout = schedule_timeout(timeout);
1144 // I/O issued, but cannot get result in
1145 // specified time. Freeing resorces is
1151 spin_lock_irq(pHba->host->host_lock);
1153 remove_wait_queue(&adpt_wq_i2o_post, &wait);
1155 if(status == -ETIMEDOUT){
1156 printk(KERN_INFO"dpti%d: POST WAIT TIMEOUT\n",pHba->unit);
1157 // We will have to free the wait_data memory during shutdown
1161 /* Remove the entry from the queue. */
1163 spin_lock_irqsave(&adpt_post_wait_lock, flags);
1164 for(p1 = adpt_post_wait_queue; p1; p2 = p1, p1 = p1->next) {
1165 if(p1 == wait_data) {
1166 if(p1->status == I2O_DETAIL_STATUS_UNSUPPORTED_FUNCTION ) {
1167 status = -EOPNOTSUPP;
1170 p2->next = p1->next;
1172 adpt_post_wait_queue = p1->next;
1177 spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
1185 static s32 adpt_i2o_post_this(adpt_hba* pHba, u32* data, int len)
1188 u32 m = EMPTY_QUEUE;
1190 ulong timeout = jiffies + 30*HZ;
1193 m = readl(pHba->post_port);
1194 if (m != EMPTY_QUEUE) {
1197 if(time_after(jiffies,timeout)){
1198 printk(KERN_WARNING"dpti%d: Timeout waiting for message frame!\n", pHba->unit);
1201 schedule_timeout_uninterruptible(1);
1202 } while(m == EMPTY_QUEUE);
1204 msg = pHba->msg_addr_virt + m;
1205 memcpy_toio(msg, data, len);
1209 writel(m, pHba->post_port);
1216 static void adpt_i2o_post_wait_complete(u32 context, int status)
1218 struct adpt_i2o_post_wait_data *p1 = NULL;
1220 * We need to search through the adpt_post_wait
1221 * queue to see if the given message is still
1222 * outstanding. If not, it means that the IOP
1223 * took longer to respond to the message than we
1224 * had allowed and timer has already expired.
1225 * Not much we can do about that except log
1226 * it for debug purposes, increase timeout, and recompile
1228 * Lock needed to keep anyone from moving queue pointers
1229 * around while we're looking through them.
1234 spin_lock(&adpt_post_wait_lock);
1235 for(p1 = adpt_post_wait_queue; p1; p1 = p1->next) {
1236 if(p1->id == context) {
1237 p1->status = status;
1238 spin_unlock(&adpt_post_wait_lock);
1239 wake_up_interruptible(p1->wq);
1243 spin_unlock(&adpt_post_wait_lock);
1244 // If this happens we lose commands that probably really completed
1245 printk(KERN_DEBUG"dpti: Could Not find task %d in wait queue\n",context);
1246 printk(KERN_DEBUG" Tasks in wait queue:\n");
1247 for(p1 = adpt_post_wait_queue; p1; p1 = p1->next) {
1248 printk(KERN_DEBUG" %d\n",p1->id);
1253 static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1258 u32 m = EMPTY_QUEUE ;
1259 ulong timeout = jiffies + (TMOUT_IOPRESET*HZ);
1261 if(pHba->initialized == FALSE) { // First time reset should be quick
1262 timeout = jiffies + (25*HZ);
1264 adpt_i2o_quiesce_hba(pHba);
1269 m = readl(pHba->post_port);
1270 if (m != EMPTY_QUEUE) {
1273 if(time_after(jiffies,timeout)){
1274 printk(KERN_WARNING"Timeout waiting for message!\n");
1277 schedule_timeout_uninterruptible(1);
1278 } while (m == EMPTY_QUEUE);
1280 status = dma_alloc_coherent(&pHba->pDev->dev, 4, &addr, GFP_KERNEL);
1281 if(status == NULL) {
1282 adpt_send_nop(pHba, m);
1283 printk(KERN_ERR"IOP reset failed - no free memory.\n");
1287 msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0;
1288 msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID;
1293 msg[6]=dma_low(addr);
1294 msg[7]=dma_high(addr);
1296 memcpy_toio(pHba->msg_addr_virt+m, msg, sizeof(msg));
1298 writel(m, pHba->post_port);
1301 while(*status == 0){
1302 if(time_after(jiffies,timeout)){
1303 printk(KERN_WARNING"%s: IOP Reset Timeout\n",pHba->name);
1304 /* We lose 4 bytes of "status" here, but we cannot
1305 free these because controller may awake and corrupt
1306 those bytes at any time */
1307 /* dma_free_coherent(&pHba->pDev->dev, 4, buf, addr); */
1311 schedule_timeout_uninterruptible(1);
1314 if(*status == 0x01 /*I2O_EXEC_IOP_RESET_IN_PROGRESS*/) {
1315 PDEBUG("%s: Reset in progress...\n", pHba->name);
1316 // Here we wait for message frame to become available
1317 // indicated that reset has finished
1320 m = readl(pHba->post_port);
1321 if (m != EMPTY_QUEUE) {
1324 if(time_after(jiffies,timeout)){
1325 printk(KERN_ERR "%s:Timeout waiting for IOP Reset.\n",pHba->name);
1326 /* We lose 4 bytes of "status" here, but we
1327 cannot free these because controller may
1328 awake and corrupt those bytes at any time */
1329 /* dma_free_coherent(&pHba->pDev->dev, 4, buf, addr); */
1332 schedule_timeout_uninterruptible(1);
1333 } while (m == EMPTY_QUEUE);
1335 adpt_send_nop(pHba, m);
1337 adpt_i2o_status_get(pHba);
1338 if(*status == 0x02 ||
1339 pHba->status_block->iop_state != ADAPTER_STATE_RESET) {
1340 printk(KERN_WARNING"%s: Reset reject, trying to clear\n",
1343 PDEBUG("%s: Reset completed.\n", pHba->name);
1346 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
1348 // This delay is to allow someone attached to the card through the debug UART to
1349 // set up the dump levels that they want before the rest of the initialization sequence
1356 static int adpt_i2o_parse_lct(adpt_hba* pHba)
1361 struct i2o_device *d;
1362 i2o_lct *lct = pHba->lct;
1366 u32 buf[10]; // larger than 7, or 8 ...
1367 struct adpt_device* pDev;
1370 printk(KERN_ERR "%s: LCT is empty???\n",pHba->name);
1374 max = lct->table_size;
1378 for(i=0;i<max;i++) {
1379 if( lct->lct_entry[i].user_tid != 0xfff){
1381 * If we have hidden devices, we need to inform the upper layers about
1382 * the possible maximum id reference to handle device access when
1383 * an array is disassembled. This code has no other purpose but to
1384 * allow us future access to devices that are currently hidden
1385 * behind arrays, hotspares or have not been configured (JBOD mode).
1387 if( lct->lct_entry[i].class_id != I2O_CLASS_RANDOM_BLOCK_STORAGE &&
1388 lct->lct_entry[i].class_id != I2O_CLASS_SCSI_PERIPHERAL &&
1389 lct->lct_entry[i].class_id != I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL ){
1392 tid = lct->lct_entry[i].tid;
1393 // I2O_DPT_DEVICE_INFO_GROUP_NO;
1394 if(adpt_i2o_query_scalar(pHba, tid, 0x8000, -1, buf, 32)<0) {
1397 bus_no = buf[0]>>16;
1399 scsi_lun = scsilun_to_int((struct scsi_lun *)&buf[2]);
1400 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
1401 printk(KERN_WARNING"%s: Channel number %d out of range \n", pHba->name, bus_no);
1404 if (scsi_id >= MAX_ID){
1405 printk(KERN_WARNING"%s: SCSI ID %d out of range \n", pHba->name, bus_no);
1408 if(bus_no > pHba->top_scsi_channel){
1409 pHba->top_scsi_channel = bus_no;
1411 if(scsi_id > pHba->top_scsi_id){
1412 pHba->top_scsi_id = scsi_id;
1414 if(scsi_lun > pHba->top_scsi_lun){
1415 pHba->top_scsi_lun = scsi_lun;
1419 d = kmalloc(sizeof(struct i2o_device), GFP_KERNEL);
1422 printk(KERN_CRIT"%s: Out of memory for I2O device data.\n",pHba->name);
1426 d->controller = pHba;
1429 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
1432 tid = d->lct_data.tid;
1433 adpt_i2o_report_hba_unit(pHba, d);
1434 adpt_i2o_install_device(pHba, d);
1437 for(d = pHba->devices; d ; d = d->next) {
1438 if(d->lct_data.class_id == I2O_CLASS_BUS_ADAPTER_PORT ||
1439 d->lct_data.class_id == I2O_CLASS_FIBRE_CHANNEL_PORT){
1440 tid = d->lct_data.tid;
1441 // TODO get the bus_no from hrt-but for now they are in order
1443 if(bus_no > pHba->top_scsi_channel){
1444 pHba->top_scsi_channel = bus_no;
1446 pHba->channel[bus_no].type = d->lct_data.class_id;
1447 pHba->channel[bus_no].tid = tid;
1448 if(adpt_i2o_query_scalar(pHba, tid, 0x0200, -1, buf, 28)>=0)
1450 pHba->channel[bus_no].scsi_id = buf[1];
1451 PDEBUG("Bus %d - SCSI ID %d.\n", bus_no, buf[1]);
1453 // TODO remove - this is just until we get from hrt
1455 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
1456 printk(KERN_WARNING"%s: Channel number %d out of range - LCT\n", pHba->name, bus_no);
1462 // Setup adpt_device table
1463 for(d = pHba->devices; d ; d = d->next) {
1464 if(d->lct_data.class_id == I2O_CLASS_RANDOM_BLOCK_STORAGE ||
1465 d->lct_data.class_id == I2O_CLASS_SCSI_PERIPHERAL ||
1466 d->lct_data.class_id == I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL ){
1468 tid = d->lct_data.tid;
1470 // I2O_DPT_DEVICE_INFO_GROUP_NO;
1471 if(adpt_i2o_query_scalar(pHba, tid, 0x8000, -1, buf, 32)>=0) {
1472 bus_no = buf[0]>>16;
1474 scsi_lun = scsilun_to_int((struct scsi_lun *)&buf[2]);
1475 if(bus_no >= MAX_CHANNEL) { // Something wrong skip it
1478 if (scsi_id >= MAX_ID) {
1481 if( pHba->channel[bus_no].device[scsi_id] == NULL){
1482 pDev = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
1486 pHba->channel[bus_no].device[scsi_id] = pDev;
1488 for( pDev = pHba->channel[bus_no].device[scsi_id];
1489 pDev->next_lun; pDev = pDev->next_lun){
1491 pDev->next_lun = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
1492 if(pDev->next_lun == NULL) {
1495 pDev = pDev->next_lun;
1498 pDev->scsi_channel = bus_no;
1499 pDev->scsi_id = scsi_id;
1500 pDev->scsi_lun = scsi_lun;
1503 pDev->type = (buf[0])&0xff;
1504 pDev->flags = (buf[0]>>8)&0xff;
1505 if(scsi_id > pHba->top_scsi_id){
1506 pHba->top_scsi_id = scsi_id;
1508 if(scsi_lun > pHba->top_scsi_lun){
1509 pHba->top_scsi_lun = scsi_lun;
1513 printk(KERN_WARNING"Could not find SCSI ID for %s\n",
1514 d->lct_data.identity_tag);
1523 * Each I2O controller has a chain of devices on it - these match
1524 * the useful parts of the LCT of the board.
1527 static int adpt_i2o_install_device(adpt_hba* pHba, struct i2o_device *d)
1529 mutex_lock(&adpt_configuration_lock);
1532 d->next=pHba->devices;
1534 if (pHba->devices != NULL){
1535 pHba->devices->prev=d;
1540 mutex_unlock(&adpt_configuration_lock);
1544 static int adpt_open(struct inode *inode, struct file *file)
1549 mutex_lock(&adpt_mutex);
1550 //TODO check for root access
1552 minor = iminor(inode);
1553 if (minor >= hba_count) {
1554 mutex_unlock(&adpt_mutex);
1557 mutex_lock(&adpt_configuration_lock);
1558 for (pHba = hba_chain; pHba; pHba = pHba->next) {
1559 if (pHba->unit == minor) {
1560 break; /* found adapter */
1564 mutex_unlock(&adpt_configuration_lock);
1565 mutex_unlock(&adpt_mutex);
1569 // if(pHba->in_use){
1570 // mutex_unlock(&adpt_configuration_lock);
1575 mutex_unlock(&adpt_configuration_lock);
1576 mutex_unlock(&adpt_mutex);
1581 static int adpt_close(struct inode *inode, struct file *file)
1586 minor = iminor(inode);
1587 if (minor >= hba_count) {
1590 mutex_lock(&adpt_configuration_lock);
1591 for (pHba = hba_chain; pHba; pHba = pHba->next) {
1592 if (pHba->unit == minor) {
1593 break; /* found adapter */
1596 mutex_unlock(&adpt_configuration_lock);
1606 #if defined __ia64__
1607 static void adpt_ia64_info(sysInfo_S* si)
1609 // This is all the info we need for now
1610 // We will add more info as our new
1611 // managmenent utility requires it
1612 si->processorType = PROC_IA64;
1616 #if defined __sparc__
1617 static void adpt_sparc_info(sysInfo_S* si)
1619 // This is all the info we need for now
1620 // We will add more info as our new
1621 // managmenent utility requires it
1622 si->processorType = PROC_ULTRASPARC;
1625 #if defined __alpha__
1626 static void adpt_alpha_info(sysInfo_S* si)
1628 // This is all the info we need for now
1629 // We will add more info as our new
1630 // managmenent utility requires it
1631 si->processorType = PROC_ALPHA;
1635 #if defined __i386__
1637 #include <uapi/asm/vm86.h>
1639 static void adpt_i386_info(sysInfo_S* si)
1641 // This is all the info we need for now
1642 // We will add more info as our new
1643 // managmenent utility requires it
1644 switch (boot_cpu_data.x86) {
1646 si->processorType = PROC_386;
1649 si->processorType = PROC_486;
1652 si->processorType = PROC_PENTIUM;
1654 default: // Just in case
1655 si->processorType = PROC_PENTIUM;
1662 * This routine returns information about the system. This does not effect
1663 * any logic and if the info is wrong - it doesn't matter.
1666 /* Get all the info we can not get from kernel services */
1667 static int adpt_system_info(void __user *buffer)
1671 memset(&si, 0, sizeof(si));
1673 si.osType = OS_LINUX;
1674 si.osMajorVersion = 0;
1675 si.osMinorVersion = 0;
1677 si.busType = SI_PCI_BUS;
1678 si.processorFamily = DPTI_sig.dsProcessorFamily;
1680 #if defined __i386__
1681 adpt_i386_info(&si);
1682 #elif defined (__ia64__)
1683 adpt_ia64_info(&si);
1684 #elif defined(__sparc__)
1685 adpt_sparc_info(&si);
1686 #elif defined (__alpha__)
1687 adpt_alpha_info(&si);
1689 si.processorType = 0xff ;
1691 if (copy_to_user(buffer, &si, sizeof(si))){
1692 printk(KERN_WARNING"dpti: Could not copy buffer TO user\n");
1699 static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1705 void __user *argp = (void __user *)arg;
1707 minor = iminor(inode);
1708 if (minor >= DPTI_MAX_HBA){
1711 mutex_lock(&adpt_configuration_lock);
1712 for (pHba = hba_chain; pHba; pHba = pHba->next) {
1713 if (pHba->unit == minor) {
1714 break; /* found adapter */
1717 mutex_unlock(&adpt_configuration_lock);
1722 while((volatile u32) pHba->state & DPTI_STATE_RESET )
1723 schedule_timeout_uninterruptible(2);
1726 // TODO: handle 3 cases
1728 if (copy_to_user(argp, &DPTI_sig, sizeof(DPTI_sig))) {
1734 drvrHBAinfo_S HbaInfo;
1736 #define FLG_OSD_PCI_VALID 0x0001
1737 #define FLG_OSD_DMA 0x0002
1738 #define FLG_OSD_I2O 0x0004
1739 memset(&HbaInfo, 0, sizeof(HbaInfo));
1740 HbaInfo.drvrHBAnum = pHba->unit;
1741 HbaInfo.baseAddr = (ulong) pHba->base_addr_phys;
1742 HbaInfo.blinkState = adpt_read_blink_led(pHba);
1743 HbaInfo.pciBusNum = pHba->pDev->bus->number;
1744 HbaInfo.pciDeviceNum=PCI_SLOT(pHba->pDev->devfn);
1745 HbaInfo.Interrupt = pHba->pDev->irq;
1746 HbaInfo.hbaFlags = FLG_OSD_PCI_VALID | FLG_OSD_DMA | FLG_OSD_I2O;
1747 if(copy_to_user(argp, &HbaInfo, sizeof(HbaInfo))){
1748 printk(KERN_WARNING"%s: Could not copy HbaInfo TO user\n",pHba->name);
1754 return adpt_system_info(argp);
1757 value = (u32)adpt_read_blink_led(pHba);
1758 if (copy_to_user(argp, &value, sizeof(value))) {
1764 struct Scsi_Host *shost = pHba->host;
1767 spin_lock_irqsave(shost->host_lock, flags);
1768 adpt_hba_reset(pHba);
1770 spin_unlock_irqrestore(shost->host_lock, flags);
1783 static long adpt_unlocked_ioctl(struct file *file, uint cmd, ulong arg)
1785 struct inode *inode;
1788 inode = file_inode(file);
1790 mutex_lock(&adpt_mutex);
1791 ret = adpt_ioctl(inode, file, cmd, arg);
1792 mutex_unlock(&adpt_mutex);
1797 #ifdef CONFIG_COMPAT
1798 static long compat_adpt_ioctl(struct file *file,
1799 unsigned int cmd, unsigned long arg)
1801 struct inode *inode;
1804 inode = file_inode(file);
1806 mutex_lock(&adpt_mutex);
1816 case (DPT_TARGET_BUSY & 0xFFFF):
1817 case DPT_TARGET_BUSY:
1818 ret = adpt_ioctl(inode, file, cmd, arg);
1824 mutex_unlock(&adpt_mutex);
1830 static irqreturn_t adpt_isr(int irq, void *dev_id)
1832 struct scsi_cmnd* cmd;
1833 adpt_hba* pHba = dev_id;
1835 void __iomem *reply;
1842 printk(KERN_WARNING"adpt_isr: NULL dev_id\n");
1846 spin_lock_irqsave(pHba->host->host_lock, flags);
1848 while( readl(pHba->irq_mask) & I2O_INTERRUPT_PENDING_B) {
1849 m = readl(pHba->reply_port);
1850 if(m == EMPTY_QUEUE){
1851 // Try twice then give up
1853 m = readl(pHba->reply_port);
1854 if(m == EMPTY_QUEUE){
1855 // This really should not happen
1856 printk(KERN_ERR"dpti: Could not get reply frame\n");
1860 if (pHba->reply_pool_pa <= m &&
1861 m < pHba->reply_pool_pa +
1862 (pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4)) {
1863 reply = (u8 *)pHba->reply_pool +
1864 (m - pHba->reply_pool_pa);
1866 /* Ick, we should *never* be here */
1867 printk(KERN_ERR "dpti: reply frame not from pool\n");
1871 if (readl(reply) & MSG_FAIL) {
1872 u32 old_m = readl(reply+28);
1875 PDEBUG("%s: Failed message\n",pHba->name);
1876 if(old_m >= 0x100000){
1877 printk(KERN_ERR"%s: Bad preserved MFA (%x)- dropping frame\n",pHba->name,old_m);
1878 writel(m,pHba->reply_port);
1881 // Transaction context is 0 in failed reply frame
1882 msg = pHba->msg_addr_virt + old_m;
1883 old_context = readl(msg+12);
1884 writel(old_context, reply+12);
1885 adpt_send_nop(pHba, old_m);
1887 context = readl(reply+8);
1888 if(context & 0x80000000){ // Post wait message
1889 status = readl(reply+16);
1891 status &= 0xffff; /* Get detail status */
1893 status = I2O_POST_WAIT_OK;
1896 * The request tag is one less than the command tag
1897 * as the firmware might treat a 0 tag as invalid
1899 cmd = scsi_host_find_tag(pHba->host,
1900 readl(reply + 12) - 1);
1902 printk(KERN_WARNING"%s: Apparent SCSI cmd in Post Wait Context - cmd=%p context=%x\n", pHba->name, cmd, context);
1904 adpt_i2o_post_wait_complete(context, status);
1905 } else { // SCSI message
1907 * The request tag is one less than the command tag
1908 * as the firmware might treat a 0 tag as invalid
1910 cmd = scsi_host_find_tag(pHba->host,
1911 readl(reply + 12) - 1);
1913 scsi_dma_unmap(cmd);
1914 adpt_i2o_scsi_complete(reply, cmd);
1917 writel(m, pHba->reply_port);
1923 spin_unlock_irqrestore(pHba->host->host_lock, flags);
1924 return IRQ_RETVAL(handled);
1927 static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_device* d)
1930 u32 msg[MAX_MESSAGE_SIZE];
1942 memset(msg, 0 , sizeof(msg));
1943 len = scsi_bufflen(cmd);
1944 direction = 0x00000000;
1946 scsidir = 0x00000000; // DATA NO XFER
1949 * Set SCBFlags to indicate if data is being transferred
1950 * in or out, or no data transfer
1951 * Note: Do not have to verify index is less than 0 since
1952 * cmd->cmnd[0] is an unsigned char
1954 switch(cmd->sc_data_direction){
1955 case DMA_FROM_DEVICE:
1956 scsidir =0x40000000; // DATA IN (iop<--dev)
1959 direction=0x04000000; // SGL OUT
1960 scsidir =0x80000000; // DATA OUT (iop-->dev)
1964 case DMA_BIDIRECTIONAL:
1965 scsidir =0x40000000; // DATA IN (iop<--dev)
1966 // Assume In - and continue;
1969 printk(KERN_WARNING"%s: scsi opcode 0x%x not supported.\n",
1970 pHba->name, cmd->cmnd[0]);
1971 cmd->result = (DID_OK <<16) | (INITIATOR_ERROR << 8);
1972 cmd->scsi_done(cmd);
1976 // msg[0] is set later
1977 // I2O_CMD_SCSI_EXEC
1978 msg[1] = ((0xff<<24)|(HOST_TID<<12)|d->tid);
1980 /* Add 1 to avoid firmware treating it as invalid command */
1981 msg[3] = cmd->request->tag + 1;
1982 // Our cards use the transaction context as the tag for queueing
1983 // Adaptec/DPT Private stuff
1984 msg[4] = I2O_CMD_SCSI_EXEC|(DPT_ORGANIZATION_ID<<16);
1986 /* Direction, disconnect ok | sense data | simple queue , CDBLen */
1987 // I2O_SCB_FLAG_ENABLE_DISCONNECT |
1988 // I2O_SCB_FLAG_SIMPLE_QUEUE_TAG |
1989 // I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
1990 msg[6] = scsidir|0x20a00000|cmd->cmd_len;
1994 // Write SCSI command into the message - always 16 byte block
1995 memset(mptr, 0, 16);
1996 memcpy(mptr, cmd->cmnd, cmd->cmd_len);
1998 lenptr=mptr++; /* Remember me - fill in when we know */
1999 if (dpt_dma64(pHba)) {
2000 reqlen = 16; // SINGLE SGE
2001 *mptr++ = (0x7C<<24)+(2<<16)+0x02; /* Enable 64 bit */
2002 *mptr++ = 1 << PAGE_SHIFT;
2004 reqlen = 14; // SINGLE SGE
2006 /* Now fill in the SGList and command */
2008 nseg = scsi_dma_map(cmd);
2011 struct scatterlist *sg;
2014 scsi_for_each_sg(cmd, sg, nseg, i) {
2016 *mptr++ = direction|0x10000000|sg_dma_len(sg);
2017 len+=sg_dma_len(sg);
2018 addr = sg_dma_address(sg);
2019 *mptr++ = dma_low(addr);
2020 if (dpt_dma64(pHba))
2021 *mptr++ = dma_high(addr);
2022 /* Make this an end of list */
2024 *lptr = direction|0xD0000000|sg_dma_len(sg);
2026 reqlen = mptr - msg;
2029 if(cmd->underflow && len != cmd->underflow){
2030 printk(KERN_WARNING"Cmd len %08X Cmd underflow %08X\n",
2031 len, cmd->underflow);
2038 /* Stick the headers on */
2039 msg[0] = reqlen<<16 | ((reqlen > 12) ? SGL_OFFSET_12 : SGL_OFFSET_0);
2041 // Send it on it's way
2042 rcode = adpt_i2o_post_this(pHba, msg, reqlen<<2);
2050 static s32 adpt_scsi_host_alloc(adpt_hba* pHba, struct scsi_host_template *sht)
2052 struct Scsi_Host *host;
2054 host = scsi_host_alloc(sht, sizeof(adpt_hba*));
2056 printk("%s: scsi_host_alloc returned NULL\n", pHba->name);
2059 host->hostdata[0] = (unsigned long)pHba;
2062 host->irq = pHba->pDev->irq;
2063 /* no IO ports, so don't have to set host->io_port and
2067 host->n_io_port = 0;
2068 /* see comments in scsi_host.h */
2070 host->max_lun = 256;
2071 host->max_channel = pHba->top_scsi_channel + 1;
2072 host->cmd_per_lun = 1;
2073 host->unique_id = (u32)sys_tbl_pa + pHba->unit;
2074 host->sg_tablesize = pHba->sg_tablesize;
2075 host->can_queue = pHba->post_fifo_size;
2081 static void adpt_i2o_scsi_complete(void __iomem *reply, struct scsi_cmnd *cmd)
2086 u32 reply_flags = readl(reply) & 0xff00; // Leave it shifted up 8 bits
2087 // I know this would look cleaner if I just read bytes
2088 // but the model I have been using for all the rest of the
2089 // io is in 4 byte words - so I keep that model
2090 u16 detailed_status = readl(reply+16) &0xffff;
2091 dev_status = (detailed_status & 0xff);
2092 hba_status = detailed_status >> 8;
2094 // calculate resid for sg
2095 scsi_set_resid(cmd, scsi_bufflen(cmd) - readl(reply+20));
2097 pHba = (adpt_hba*) cmd->device->host->hostdata[0];
2099 cmd->sense_buffer[0] = '\0'; // initialize sense valid flag to false
2101 if(!(reply_flags & MSG_FAIL)) {
2102 switch(detailed_status & I2O_SCSI_DSC_MASK) {
2103 case I2O_SCSI_DSC_SUCCESS:
2104 cmd->result = (DID_OK << 16);
2106 if (readl(reply+20) < cmd->underflow) {
2107 cmd->result = (DID_ERROR <<16);
2108 printk(KERN_WARNING"%s: SCSI CMD underflow\n",pHba->name);
2111 case I2O_SCSI_DSC_REQUEST_ABORTED:
2112 cmd->result = (DID_ABORT << 16);
2114 case I2O_SCSI_DSC_PATH_INVALID:
2115 case I2O_SCSI_DSC_DEVICE_NOT_PRESENT:
2116 case I2O_SCSI_DSC_SELECTION_TIMEOUT:
2117 case I2O_SCSI_DSC_COMMAND_TIMEOUT:
2118 case I2O_SCSI_DSC_NO_ADAPTER:
2119 case I2O_SCSI_DSC_RESOURCE_UNAVAILABLE:
2120 printk(KERN_WARNING"%s: SCSI Timeout-Device (%d,%d,%llu) hba status=0x%x, dev status=0x%x, cmd=0x%x\n",
2121 pHba->name, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun, hba_status, dev_status, cmd->cmnd[0]);
2122 cmd->result = (DID_TIME_OUT << 16);
2124 case I2O_SCSI_DSC_ADAPTER_BUSY:
2125 case I2O_SCSI_DSC_BUS_BUSY:
2126 cmd->result = (DID_BUS_BUSY << 16);
2128 case I2O_SCSI_DSC_SCSI_BUS_RESET:
2129 case I2O_SCSI_DSC_BDR_MESSAGE_SENT:
2130 cmd->result = (DID_RESET << 16);
2132 case I2O_SCSI_DSC_PARITY_ERROR_FAILURE:
2133 printk(KERN_WARNING"%s: SCSI CMD parity error\n",pHba->name);
2134 cmd->result = (DID_PARITY << 16);
2136 case I2O_SCSI_DSC_UNABLE_TO_ABORT:
2137 case I2O_SCSI_DSC_COMPLETE_WITH_ERROR:
2138 case I2O_SCSI_DSC_UNABLE_TO_TERMINATE:
2139 case I2O_SCSI_DSC_MR_MESSAGE_RECEIVED:
2140 case I2O_SCSI_DSC_AUTOSENSE_FAILED:
2141 case I2O_SCSI_DSC_DATA_OVERRUN:
2142 case I2O_SCSI_DSC_UNEXPECTED_BUS_FREE:
2143 case I2O_SCSI_DSC_SEQUENCE_FAILURE:
2144 case I2O_SCSI_DSC_REQUEST_LENGTH_ERROR:
2145 case I2O_SCSI_DSC_PROVIDE_FAILURE:
2146 case I2O_SCSI_DSC_REQUEST_TERMINATED:
2147 case I2O_SCSI_DSC_IDE_MESSAGE_SENT:
2148 case I2O_SCSI_DSC_UNACKNOWLEDGED_EVENT:
2149 case I2O_SCSI_DSC_MESSAGE_RECEIVED:
2150 case I2O_SCSI_DSC_INVALID_CDB:
2151 case I2O_SCSI_DSC_LUN_INVALID:
2152 case I2O_SCSI_DSC_SCSI_TID_INVALID:
2153 case I2O_SCSI_DSC_FUNCTION_UNAVAILABLE:
2154 case I2O_SCSI_DSC_NO_NEXUS:
2155 case I2O_SCSI_DSC_CDB_RECEIVED:
2156 case I2O_SCSI_DSC_LUN_ALREADY_ENABLED:
2157 case I2O_SCSI_DSC_QUEUE_FROZEN:
2158 case I2O_SCSI_DSC_REQUEST_INVALID:
2160 printk(KERN_WARNING"%s: SCSI error %0x-Device(%d,%d,%llu) hba_status=0x%x, dev_status=0x%x, cmd=0x%x\n",
2161 pHba->name, detailed_status & I2O_SCSI_DSC_MASK, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun,
2162 hba_status, dev_status, cmd->cmnd[0]);
2163 cmd->result = (DID_ERROR << 16);
2167 // copy over the request sense data if it was a check
2169 if (dev_status == SAM_STAT_CHECK_CONDITION) {
2170 u32 len = min(SCSI_SENSE_BUFFERSIZE, 40);
2171 // Copy over the sense data
2172 memcpy_fromio(cmd->sense_buffer, (reply+28) , len);
2173 if(cmd->sense_buffer[0] == 0x70 /* class 7 */ &&
2174 cmd->sense_buffer[2] == DATA_PROTECT ){
2175 /* This is to handle an array failed */
2176 cmd->result = (DID_TIME_OUT << 16);
2177 printk(KERN_WARNING"%s: SCSI Data Protect-Device (%d,%d,%llu) hba_status=0x%x, dev_status=0x%x, cmd=0x%x\n",
2178 pHba->name, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun,
2179 hba_status, dev_status, cmd->cmnd[0]);
2184 /* In this condtion we could not talk to the tid
2185 * the card rejected it. We should signal a retry
2186 * for a limitted number of retries.
2188 cmd->result = (DID_TIME_OUT << 16);
2189 printk(KERN_WARNING"%s: I2O MSG_FAIL - Device (%d,%d,%llu) tid=%d, cmd=0x%x\n",
2190 pHba->name, (u32)cmd->device->channel, (u32)cmd->device->id, cmd->device->lun,
2191 ((struct adpt_device*)(cmd->device->hostdata))->tid, cmd->cmnd[0]);
2194 cmd->result |= (dev_status);
2196 if(cmd->scsi_done != NULL){
2197 cmd->scsi_done(cmd);
2202 static s32 adpt_rescan(adpt_hba* pHba)
2208 spin_lock_irqsave(pHba->host->host_lock, flags);
2209 if ((rcode=adpt_i2o_lct_get(pHba)) < 0)
2211 if ((rcode=adpt_i2o_reparse_lct(pHba)) < 0)
2215 spin_unlock_irqrestore(pHba->host->host_lock, flags);
2220 static s32 adpt_i2o_reparse_lct(adpt_hba* pHba)
2225 struct i2o_device *d;
2226 i2o_lct *lct = pHba->lct;
2230 u32 buf[10]; // at least 8 u32's
2231 struct adpt_device* pDev = NULL;
2232 struct i2o_device* pI2o_dev = NULL;
2235 printk(KERN_ERR "%s: LCT is empty???\n",pHba->name);
2239 max = lct->table_size;
2243 // Mark each drive as unscanned
2244 for (d = pHba->devices; d; d = d->next) {
2245 pDev =(struct adpt_device*) d->owner;
2249 pDev->state |= DPTI_DEV_UNSCANNED;
2252 printk(KERN_INFO "%s: LCT has %d entries.\n", pHba->name,max);
2254 for(i=0;i<max;i++) {
2255 if( lct->lct_entry[i].user_tid != 0xfff){
2259 if( lct->lct_entry[i].class_id == I2O_CLASS_RANDOM_BLOCK_STORAGE ||
2260 lct->lct_entry[i].class_id == I2O_CLASS_SCSI_PERIPHERAL ||
2261 lct->lct_entry[i].class_id == I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL ){
2262 tid = lct->lct_entry[i].tid;
2263 if(adpt_i2o_query_scalar(pHba, tid, 0x8000, -1, buf, 32)<0) {
2264 printk(KERN_ERR"%s: Could not query device\n",pHba->name);
2267 bus_no = buf[0]>>16;
2268 if (bus_no >= MAX_CHANNEL) { /* Something wrong skip it */
2270 "%s: Channel number %d out of range\n",
2271 pHba->name, bus_no);
2276 scsi_lun = scsilun_to_int((struct scsi_lun *)&buf[2]);
2277 pDev = pHba->channel[bus_no].device[scsi_id];
2280 if(pDev->scsi_lun == scsi_lun) {
2283 pDev = pDev->next_lun;
2285 if(!pDev ) { // Something new add it
2286 d = kmalloc(sizeof(struct i2o_device),
2290 printk(KERN_CRIT "Out of memory for I2O device data.\n");
2294 d->controller = pHba;
2297 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
2300 adpt_i2o_report_hba_unit(pHba, d);
2301 adpt_i2o_install_device(pHba, d);
2303 pDev = pHba->channel[bus_no].device[scsi_id];
2306 kzalloc(sizeof(struct adpt_device),
2311 pHba->channel[bus_no].device[scsi_id] = pDev;
2313 while (pDev->next_lun) {
2314 pDev = pDev->next_lun;
2316 pDev = pDev->next_lun =
2317 kzalloc(sizeof(struct adpt_device),
2323 pDev->tid = d->lct_data.tid;
2324 pDev->scsi_channel = bus_no;
2325 pDev->scsi_id = scsi_id;
2326 pDev->scsi_lun = scsi_lun;
2329 pDev->type = (buf[0])&0xff;
2330 pDev->flags = (buf[0]>>8)&0xff;
2331 // Too late, SCSI system has made up it's mind, but what the hey ...
2332 if(scsi_id > pHba->top_scsi_id){
2333 pHba->top_scsi_id = scsi_id;
2335 if(scsi_lun > pHba->top_scsi_lun){
2336 pHba->top_scsi_lun = scsi_lun;
2339 } // end of new i2o device
2341 // We found an old device - check it
2343 if(pDev->scsi_lun == scsi_lun) {
2344 if(!scsi_device_online(pDev->pScsi_dev)) {
2345 printk(KERN_WARNING"%s: Setting device (%d,%d,%llu) back online\n",
2346 pHba->name,bus_no,scsi_id,scsi_lun);
2347 if (pDev->pScsi_dev) {
2348 scsi_device_set_state(pDev->pScsi_dev, SDEV_RUNNING);
2352 if(d->lct_data.tid != tid) { // something changed
2354 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
2355 if (pDev->pScsi_dev) {
2356 pDev->pScsi_dev->changed = TRUE;
2357 pDev->pScsi_dev->removable = TRUE;
2360 // Found it - mark it scanned
2361 pDev->state = DPTI_DEV_ONLINE;
2364 pDev = pDev->next_lun;
2368 for (pI2o_dev = pHba->devices; pI2o_dev; pI2o_dev = pI2o_dev->next) {
2369 pDev =(struct adpt_device*) pI2o_dev->owner;
2373 // Drive offline drives that previously existed but could not be found
2375 if (pDev->state & DPTI_DEV_UNSCANNED){
2376 pDev->state = DPTI_DEV_OFFLINE;
2377 printk(KERN_WARNING"%s: Device (%d,%d,%llu) offline\n",pHba->name,pDev->scsi_channel,pDev->scsi_id,pDev->scsi_lun);
2378 if (pDev->pScsi_dev) {
2379 scsi_device_set_state(pDev->pScsi_dev, SDEV_OFFLINE);
2386 /*============================================================================
2387 * Routines from i2o subsystem
2388 *============================================================================
2394 * Bring an I2O controller into HOLD state. See the spec.
2396 static int adpt_i2o_activate_hba(adpt_hba* pHba)
2400 if(pHba->initialized ) {
2401 if (adpt_i2o_status_get(pHba) < 0) {
2402 if((rcode = adpt_i2o_reset_hba(pHba)) != 0){
2403 printk(KERN_WARNING"%s: Could NOT reset.\n", pHba->name);
2406 if (adpt_i2o_status_get(pHba) < 0) {
2407 printk(KERN_INFO "HBA not responding.\n");
2412 if(pHba->status_block->iop_state == ADAPTER_STATE_FAULTED) {
2413 printk(KERN_CRIT "%s: hardware fault\n", pHba->name);
2417 if (pHba->status_block->iop_state == ADAPTER_STATE_READY ||
2418 pHba->status_block->iop_state == ADAPTER_STATE_OPERATIONAL ||
2419 pHba->status_block->iop_state == ADAPTER_STATE_HOLD ||
2420 pHba->status_block->iop_state == ADAPTER_STATE_FAILED) {
2421 adpt_i2o_reset_hba(pHba);
2422 if (adpt_i2o_status_get(pHba) < 0 || pHba->status_block->iop_state != ADAPTER_STATE_RESET) {
2423 printk(KERN_ERR "%s: Failed to initialize.\n", pHba->name);
2428 if((rcode = adpt_i2o_reset_hba(pHba)) != 0){
2429 printk(KERN_WARNING"%s: Could NOT reset.\n", pHba->name);
2435 if (adpt_i2o_init_outbound_q(pHba) < 0) {
2441 if (adpt_i2o_hrt_get(pHba) < 0) {
2449 * Bring a controller online into OPERATIONAL state.
2452 static int adpt_i2o_online_hba(adpt_hba* pHba)
2454 if (adpt_i2o_systab_send(pHba) < 0)
2456 /* In READY state */
2458 if (adpt_i2o_enable_hba(pHba) < 0)
2461 /* In OPERATIONAL state */
2465 static s32 adpt_send_nop(adpt_hba*pHba,u32 m)
2468 ulong timeout = jiffies + 5*HZ;
2470 while(m == EMPTY_QUEUE){
2472 m = readl(pHba->post_port);
2473 if(m != EMPTY_QUEUE){
2476 if(time_after(jiffies,timeout)){
2477 printk(KERN_ERR "%s: Timeout waiting for message frame!\n",pHba->name);
2480 schedule_timeout_uninterruptible(1);
2482 msg = (u32 __iomem *)(pHba->msg_addr_virt + m);
2483 writel( THREE_WORD_MSG_SIZE | SGL_OFFSET_0,&msg[0]);
2484 writel( I2O_CMD_UTIL_NOP << 24 | HOST_TID << 12 | 0,&msg[1]);
2488 writel(m, pHba->post_port);
2493 static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
2497 u32 __iomem *msg = NULL;
2499 ulong timeout = jiffies + TMOUT_INITOUTBOUND*HZ;
2504 m = readl(pHba->post_port);
2505 if (m != EMPTY_QUEUE) {
2509 if(time_after(jiffies,timeout)){
2510 printk(KERN_WARNING"%s: Timeout waiting for message frame\n",pHba->name);
2513 schedule_timeout_uninterruptible(1);
2514 } while(m == EMPTY_QUEUE);
2516 msg=(u32 __iomem *)(pHba->msg_addr_virt+m);
2518 status = dma_alloc_coherent(&pHba->pDev->dev, 4, &addr, GFP_KERNEL);
2520 adpt_send_nop(pHba, m);
2521 printk(KERN_WARNING"%s: IOP reset failed - no free memory.\n",
2526 writel(EIGHT_WORD_MSG_SIZE| SGL_OFFSET_6, &msg[0]);
2527 writel(I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID, &msg[1]);
2529 writel(0x0106, &msg[3]); /* Transaction context */
2530 writel(4096, &msg[4]); /* Host page frame size */
2531 writel((REPLY_FRAME_SIZE)<<16|0x80, &msg[5]); /* Outbound msg frame size and Initcode */
2532 writel(0xD0000004, &msg[6]); /* Simple SG LE, EOB */
2533 writel((u32)addr, &msg[7]);
2535 writel(m, pHba->post_port);
2538 // Wait for the reply status to come back
2541 if (*status != 0x01 /*I2O_EXEC_OUTBOUND_INIT_IN_PROGRESS*/) {
2546 if(time_after(jiffies,timeout)){
2547 printk(KERN_WARNING"%s: Timeout Initializing\n",pHba->name);
2548 /* We lose 4 bytes of "status" here, but we
2549 cannot free these because controller may
2550 awake and corrupt those bytes at any time */
2551 /* dma_free_coherent(&pHba->pDev->dev, 4, status, addr); */
2554 schedule_timeout_uninterruptible(1);
2557 // If the command was successful, fill the fifo with our reply
2559 if(*status != 0x04 /*I2O_EXEC_OUTBOUND_INIT_COMPLETE*/) {
2560 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
2563 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
2565 if(pHba->reply_pool != NULL) {
2566 dma_free_coherent(&pHba->pDev->dev,
2567 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
2568 pHba->reply_pool, pHba->reply_pool_pa);
2571 pHba->reply_pool = dma_alloc_coherent(&pHba->pDev->dev,
2572 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
2573 &pHba->reply_pool_pa, GFP_KERNEL);
2574 if (!pHba->reply_pool) {
2575 printk(KERN_ERR "%s: Could not allocate reply pool\n", pHba->name);
2579 for(i = 0; i < pHba->reply_fifo_size; i++) {
2580 writel(pHba->reply_pool_pa + (i * REPLY_FRAME_SIZE * 4),
2584 adpt_i2o_status_get(pHba);
2590 * I2O System Table. Contains information about
2591 * all the IOPs in the system. Used to inform IOPs
2592 * about each other's existence.
2594 * sys_tbl_ver is the CurrentChangeIndicator that is
2595 * used by IOPs to track changes.
2600 static s32 adpt_i2o_status_get(adpt_hba* pHba)
2605 u8 *status_block=NULL;
2607 if(pHba->status_block == NULL) {
2608 pHba->status_block = dma_alloc_coherent(&pHba->pDev->dev,
2609 sizeof(i2o_status_block),
2610 &pHba->status_block_pa, GFP_KERNEL);
2611 if(pHba->status_block == NULL) {
2613 "dpti%d: Get Status Block failed; Out of memory. \n",
2618 memset(pHba->status_block, 0, sizeof(i2o_status_block));
2619 status_block = (u8*)(pHba->status_block);
2620 timeout = jiffies+TMOUT_GETSTATUS*HZ;
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 !\n",
2632 schedule_timeout_uninterruptible(1);
2633 } while(m==EMPTY_QUEUE);
2636 msg=(u32 __iomem *)(pHba->msg_addr_virt+m);
2638 writel(NINE_WORD_MSG_SIZE|SGL_OFFSET_0, &msg[0]);
2639 writel(I2O_CMD_STATUS_GET<<24|HOST_TID<<12|ADAPTER_TID, &msg[1]);
2644 writel( dma_low(pHba->status_block_pa), &msg[6]);
2645 writel( dma_high(pHba->status_block_pa), &msg[7]);
2646 writel(sizeof(i2o_status_block), &msg[8]); // 88 bytes
2649 writel(m, pHba->post_port);
2652 while(status_block[87]!=0xff){
2653 if(time_after(jiffies,timeout)){
2654 printk(KERN_ERR"dpti%d: Get status timeout.\n",
2659 schedule_timeout_uninterruptible(1);
2662 // Set up our number of outbound and inbound messages
2663 pHba->post_fifo_size = pHba->status_block->max_inbound_frames;
2664 if (pHba->post_fifo_size > MAX_TO_IOP_MESSAGES) {
2665 pHba->post_fifo_size = MAX_TO_IOP_MESSAGES;
2668 pHba->reply_fifo_size = pHba->status_block->max_outbound_frames;
2669 if (pHba->reply_fifo_size > MAX_FROM_IOP_MESSAGES) {
2670 pHba->reply_fifo_size = MAX_FROM_IOP_MESSAGES;
2673 // Calculate the Scatter Gather list size
2674 if (dpt_dma64(pHba)) {
2676 = ((pHba->status_block->inbound_frame_size * 4
2678 / (sizeof(struct sg_simple_element) + sizeof(u32)));
2681 = ((pHba->status_block->inbound_frame_size * 4
2683 / sizeof(struct sg_simple_element));
2685 if (pHba->sg_tablesize > SG_LIST_ELEMENTS) {
2686 pHba->sg_tablesize = SG_LIST_ELEMENTS;
2691 printk("dpti%d: State = ",pHba->unit);
2692 switch(pHba->status_block->iop_state) {
2706 printk("OPERATIONAL\n");
2712 printk("FAULTED\n");
2715 printk("%x (unknown!!)\n",pHba->status_block->iop_state);
2722 * Get the IOP's Logical Configuration Table
2724 static int adpt_i2o_lct_get(adpt_hba* pHba)
2730 if ((pHba->lct_size == 0) || (pHba->lct == NULL)){
2731 pHba->lct_size = pHba->status_block->expected_lct_size;
2734 if (pHba->lct == NULL) {
2735 pHba->lct = dma_alloc_coherent(&pHba->pDev->dev,
2736 pHba->lct_size, &pHba->lct_pa,
2738 if(pHba->lct == NULL) {
2739 printk(KERN_CRIT "%s: Lct Get failed. Out of memory.\n",
2744 memset(pHba->lct, 0, pHba->lct_size);
2746 msg[0] = EIGHT_WORD_MSG_SIZE|SGL_OFFSET_6;
2747 msg[1] = I2O_CMD_LCT_NOTIFY<<24 | HOST_TID<<12 | ADAPTER_TID;
2750 msg[4] = 0xFFFFFFFF; /* All devices */
2751 msg[5] = 0x00000000; /* Report now */
2752 msg[6] = 0xD0000000|pHba->lct_size;
2753 msg[7] = (u32)pHba->lct_pa;
2755 if ((ret=adpt_i2o_post_wait(pHba, msg, sizeof(msg), 360))) {
2756 printk(KERN_ERR "%s: LCT Get failed (status=%#10x.\n",
2758 printk(KERN_ERR"Adaptec: Error Reading Hardware.\n");
2762 if ((pHba->lct->table_size << 2) > pHba->lct_size) {
2763 pHba->lct_size = pHba->lct->table_size << 2;
2764 dma_free_coherent(&pHba->pDev->dev, pHba->lct_size,
2765 pHba->lct, pHba->lct_pa);
2768 } while (pHba->lct == NULL);
2770 PDEBUG("%s: Hardware resource table read.\n", pHba->name);
2773 // I2O_DPT_EXEC_IOP_BUFFERS_GROUP_NO;
2774 if(adpt_i2o_query_scalar(pHba, 0 , 0x8000, -1, buf, sizeof(buf))>=0) {
2775 pHba->FwDebugBufferSize = buf[1];
2776 pHba->FwDebugBuffer_P = ioremap(pHba->base_addr_phys + buf[0],
2777 pHba->FwDebugBufferSize);
2778 if (pHba->FwDebugBuffer_P) {
2779 pHba->FwDebugFlags_P = pHba->FwDebugBuffer_P +
2780 FW_DEBUG_FLAGS_OFFSET;
2781 pHba->FwDebugBLEDvalue_P = pHba->FwDebugBuffer_P +
2782 FW_DEBUG_BLED_OFFSET;
2783 pHba->FwDebugBLEDflag_P = pHba->FwDebugBLEDvalue_P + 1;
2784 pHba->FwDebugStrLength_P = pHba->FwDebugBuffer_P +
2785 FW_DEBUG_STR_LENGTH_OFFSET;
2786 pHba->FwDebugBuffer_P += buf[2];
2787 pHba->FwDebugFlags = 0;
2794 static int adpt_i2o_build_sys_table(void)
2796 adpt_hba* pHba = hba_chain;
2800 dma_free_coherent(&pHba->pDev->dev, sys_tbl_len,
2801 sys_tbl, sys_tbl_pa);
2803 sys_tbl_len = sizeof(struct i2o_sys_tbl) + // Header + IOPs
2804 (hba_count) * sizeof(struct i2o_sys_tbl_entry);
2806 sys_tbl = dma_alloc_coherent(&pHba->pDev->dev,
2807 sys_tbl_len, &sys_tbl_pa, GFP_KERNEL);
2809 printk(KERN_WARNING "SysTab Set failed. Out of memory.\n");
2813 sys_tbl->num_entries = hba_count;
2814 sys_tbl->version = I2OVERSION;
2815 sys_tbl->change_ind = sys_tbl_ind++;
2817 for(pHba = hba_chain; pHba; pHba = pHba->next) {
2819 // Get updated Status Block so we have the latest information
2820 if (adpt_i2o_status_get(pHba)) {
2821 sys_tbl->num_entries--;
2822 continue; // try next one
2825 sys_tbl->iops[count].org_id = pHba->status_block->org_id;
2826 sys_tbl->iops[count].iop_id = pHba->unit + 2;
2827 sys_tbl->iops[count].seg_num = 0;
2828 sys_tbl->iops[count].i2o_version = pHba->status_block->i2o_version;
2829 sys_tbl->iops[count].iop_state = pHba->status_block->iop_state;
2830 sys_tbl->iops[count].msg_type = pHba->status_block->msg_type;
2831 sys_tbl->iops[count].frame_size = pHba->status_block->inbound_frame_size;
2832 sys_tbl->iops[count].last_changed = sys_tbl_ind - 1; // ??
2833 sys_tbl->iops[count].iop_capabilities = pHba->status_block->iop_capabilities;
2834 addr = pHba->base_addr_phys + 0x40;
2835 sys_tbl->iops[count].inbound_low = dma_low(addr);
2836 sys_tbl->iops[count].inbound_high = dma_high(addr);
2843 u32 *table = (u32*)sys_tbl;
2844 printk(KERN_DEBUG"sys_tbl_len=%d in 32bit words\n",(sys_tbl_len >>2));
2845 for(count = 0; count < (sys_tbl_len >>2); count++) {
2846 printk(KERN_INFO "sys_tbl[%d] = %0#10x\n",
2847 count, table[count]);
2857 * Dump the information block associated with a given unit (TID)
2860 static void adpt_i2o_report_hba_unit(adpt_hba* pHba, struct i2o_device *d)
2863 int unit = d->lct_data.tid;
2865 printk(KERN_INFO "TID %3.3d ", unit);
2867 if(adpt_i2o_query_scalar(pHba, unit, 0xF100, 3, buf, 16)>=0)
2870 printk(" Vendor: %-12.12s", buf);
2872 if(adpt_i2o_query_scalar(pHba, unit, 0xF100, 4, buf, 16)>=0)
2875 printk(" Device: %-12.12s", buf);
2877 if(adpt_i2o_query_scalar(pHba, unit, 0xF100, 6, buf, 8)>=0)
2880 printk(" Rev: %-12.12s\n", buf);
2883 printk(KERN_INFO "\tClass: %.21s\n", adpt_i2o_get_class_name(d->lct_data.class_id));
2884 printk(KERN_INFO "\tSubclass: 0x%04X\n", d->lct_data.sub_class);
2885 printk(KERN_INFO "\tFlags: ");
2887 if(d->lct_data.device_flags&(1<<0))
2888 printk("C"); // ConfigDialog requested
2889 if(d->lct_data.device_flags&(1<<1))
2890 printk("U"); // Multi-user capable
2891 if(!(d->lct_data.device_flags&(1<<4)))
2892 printk("P"); // Peer service enabled!
2893 if(!(d->lct_data.device_flags&(1<<5)))
2894 printk("M"); // Mgmt service enabled!
2901 * Do i2o class name lookup
2903 static const char *adpt_i2o_get_class_name(int class)
2906 static char *i2o_class_name[] = {
2908 "Device Driver Module",
2913 "Fibre Channel Port",
2914 "Fibre Channel Device",
2918 "Floppy Controller",
2920 "Secondary Bus Port",
2921 "Peer Transport Agent",
2926 switch(class&0xFFF) {
2927 case I2O_CLASS_EXECUTIVE:
2931 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
2933 case I2O_CLASS_SEQUENTIAL_STORAGE:
2939 case I2O_CLASS_FIBRE_CHANNEL_PORT:
2941 case I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL:
2943 case I2O_CLASS_SCSI_PERIPHERAL:
2945 case I2O_CLASS_ATE_PORT:
2947 case I2O_CLASS_ATE_PERIPHERAL:
2949 case I2O_CLASS_FLOPPY_CONTROLLER:
2951 case I2O_CLASS_FLOPPY_DEVICE:
2953 case I2O_CLASS_BUS_ADAPTER_PORT:
2955 case I2O_CLASS_PEER_TRANSPORT_AGENT:
2957 case I2O_CLASS_PEER_TRANSPORT:
2960 return i2o_class_name[idx];
2965 static s32 adpt_i2o_hrt_get(adpt_hba* pHba)
2968 int ret, size = sizeof(i2o_hrt);
2971 if (pHba->hrt == NULL) {
2972 pHba->hrt = dma_alloc_coherent(&pHba->pDev->dev,
2973 size, &pHba->hrt_pa, GFP_KERNEL);
2974 if (pHba->hrt == NULL) {
2975 printk(KERN_CRIT "%s: Hrt Get failed; Out of memory.\n", pHba->name);
2980 msg[0]= SIX_WORD_MSG_SIZE| SGL_OFFSET_4;
2981 msg[1]= I2O_CMD_HRT_GET<<24 | HOST_TID<<12 | ADAPTER_TID;
2984 msg[4]= (0xD0000000 | size); /* Simple transaction */
2985 msg[5]= (u32)pHba->hrt_pa; /* Dump it here */
2987 if ((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg),20))) {
2988 printk(KERN_ERR "%s: Unable to get HRT (status=%#10x)\n", pHba->name, ret);
2992 if (pHba->hrt->num_entries * pHba->hrt->entry_len << 2 > size) {
2993 int newsize = pHba->hrt->num_entries * pHba->hrt->entry_len << 2;
2994 dma_free_coherent(&pHba->pDev->dev, size,
2995 pHba->hrt, pHba->hrt_pa);
2999 } while(pHba->hrt == NULL);
3004 * Query one scalar group value or a whole scalar group.
3006 static int adpt_i2o_query_scalar(adpt_hba* pHba, int tid,
3007 int group, int field, void *buf, int buflen)
3009 u16 opblk[] = { 1, 0, I2O_PARAMS_FIELD_GET, group, 1, field };
3011 dma_addr_t opblk_pa;
3013 dma_addr_t resblk_pa;
3017 /* 8 bytes for header */
3018 resblk_va = dma_alloc_coherent(&pHba->pDev->dev,
3019 sizeof(u8) * (8 + buflen), &resblk_pa, GFP_KERNEL);
3020 if (resblk_va == NULL) {
3021 printk(KERN_CRIT "%s: query scalar failed; Out of memory.\n", pHba->name);
3025 opblk_va = dma_alloc_coherent(&pHba->pDev->dev,
3026 sizeof(opblk), &opblk_pa, GFP_KERNEL);
3027 if (opblk_va == NULL) {
3028 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3029 resblk_va, resblk_pa);
3030 printk(KERN_CRIT "%s: query operation failed; Out of memory.\n",
3034 if (field == -1) /* whole group */
3037 memcpy(opblk_va, opblk, sizeof(opblk));
3038 size = adpt_i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET, pHba, tid,
3039 opblk_va, opblk_pa, sizeof(opblk),
3040 resblk_va, resblk_pa, sizeof(u8)*(8+buflen));
3041 dma_free_coherent(&pHba->pDev->dev, sizeof(opblk), opblk_va, opblk_pa);
3042 if (size == -ETIME) {
3043 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3044 resblk_va, resblk_pa);
3045 printk(KERN_WARNING "%s: issue params failed; Timed out.\n", pHba->name);
3047 } else if (size == -EINTR) {
3048 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3049 resblk_va, resblk_pa);
3050 printk(KERN_WARNING "%s: issue params failed; Interrupted.\n", pHba->name);
3054 memcpy(buf, resblk_va+8, buflen); /* cut off header */
3056 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3057 resblk_va, resblk_pa);
3065 /* Issue UTIL_PARAMS_GET or UTIL_PARAMS_SET
3067 * This function can be used for all UtilParamsGet/Set operations.
3068 * The OperationBlock is given in opblk-buffer,
3069 * and results are returned in resblk-buffer.
3070 * Note that the minimum sized resblk is 8 bytes and contains
3071 * ResultCount, ErrorInfoSize, BlockStatus and BlockSize.
3073 static int adpt_i2o_issue_params(int cmd, adpt_hba* pHba, int tid,
3074 void *opblk_va, dma_addr_t opblk_pa, int oplen,
3075 void *resblk_va, dma_addr_t resblk_pa, int reslen)
3078 u32 *res = (u32 *)resblk_va;
3081 msg[0] = NINE_WORD_MSG_SIZE | SGL_OFFSET_5;
3082 msg[1] = cmd << 24 | HOST_TID << 12 | tid;
3086 msg[5] = 0x54000000 | oplen; /* OperationBlock */
3087 msg[6] = (u32)opblk_pa;
3088 msg[7] = 0xD0000000 | reslen; /* ResultBlock */
3089 msg[8] = (u32)resblk_pa;
3091 if ((wait_status = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 20))) {
3092 printk("adpt_i2o_issue_params: post_wait failed (%p)\n", resblk_va);
3093 return wait_status; /* -DetailedStatus */
3096 if (res[1]&0x00FF0000) { /* BlockStatus != SUCCESS */
3097 printk(KERN_WARNING "%s: %s - Error:\n ErrorInfoSize = 0x%02x, "
3098 "BlockStatus = 0x%02x, BlockSize = 0x%04x\n",
3100 (cmd == I2O_CMD_UTIL_PARAMS_SET) ? "PARAMS_SET"
3102 res[1]>>24, (res[1]>>16)&0xFF, res[1]&0xFFFF);
3103 return -((res[1] >> 16) & 0xFF); /* -BlockStatus */
3106 return 4 + ((res[1] & 0x0000FFFF) << 2); /* bytes used in resblk */
3110 static s32 adpt_i2o_quiesce_hba(adpt_hba* pHba)
3115 adpt_i2o_status_get(pHba);
3117 /* SysQuiesce discarded if IOP not in READY or OPERATIONAL state */
3119 if((pHba->status_block->iop_state != ADAPTER_STATE_READY) &&
3120 (pHba->status_block->iop_state != ADAPTER_STATE_OPERATIONAL)){
3124 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
3125 msg[1] = I2O_CMD_SYS_QUIESCE<<24|HOST_TID<<12|ADAPTER_TID;
3129 if((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 240))) {
3130 printk(KERN_INFO"dpti%d: Unable to quiesce (status=%#x).\n",
3133 printk(KERN_INFO"dpti%d: Quiesced.\n",pHba->unit);
3136 adpt_i2o_status_get(pHba);
3142 * Enable IOP. Allows the IOP to resume external operations.
3144 static int adpt_i2o_enable_hba(adpt_hba* pHba)
3149 adpt_i2o_status_get(pHba);
3150 if(!pHba->status_block){
3153 /* Enable only allowed on READY state */
3154 if(pHba->status_block->iop_state == ADAPTER_STATE_OPERATIONAL)
3157 if(pHba->status_block->iop_state != ADAPTER_STATE_READY)
3160 msg[0]=FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
3161 msg[1]=I2O_CMD_SYS_ENABLE<<24|HOST_TID<<12|ADAPTER_TID;
3165 if ((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 240))) {
3166 printk(KERN_WARNING"%s: Could not enable (status=%#10x).\n",
3169 PDEBUG("%s: Enabled.\n", pHba->name);
3172 adpt_i2o_status_get(pHba);
3177 static int adpt_i2o_systab_send(adpt_hba* pHba)
3182 msg[0] = I2O_MESSAGE_SIZE(12) | SGL_OFFSET_6;
3183 msg[1] = I2O_CMD_SYS_TAB_SET<<24 | HOST_TID<<12 | ADAPTER_TID;
3186 msg[4] = (0<<16) | ((pHba->unit+2) << 12); /* Host 0 IOP ID (unit + 2) */
3187 msg[5] = 0; /* Segment 0 */
3190 * Provide three SGL-elements:
3191 * System table (SysTab), Private memory space declaration and
3192 * Private i/o space declaration
3194 msg[6] = 0x54000000 | sys_tbl_len;
3195 msg[7] = (u32)sys_tbl_pa;
3196 msg[8] = 0x54000000 | 0;
3198 msg[10] = 0xD4000000 | 0;
3201 if ((ret=adpt_i2o_post_wait(pHba, msg, sizeof(msg), 120))) {
3202 printk(KERN_INFO "%s: Unable to set SysTab (status=%#10x).\n",
3207 PINFO("%s: SysTab set.\n", pHba->name);
3215 /*============================================================================
3217 *============================================================================
3223 static static void adpt_delay(int millisec)
3226 for (i = 0; i < millisec; i++) {
3227 udelay(1000); /* delay for one millisecond */
3233 static struct scsi_host_template driver_template = {
3234 .module = THIS_MODULE,
3236 .proc_name = "dpt_i2o",
3237 .show_info = adpt_show_info,
3239 .queuecommand = adpt_queue,
3240 .eh_abort_handler = adpt_abort,
3241 .eh_device_reset_handler = adpt_device_reset,
3242 .eh_bus_reset_handler = adpt_bus_reset,
3243 .eh_host_reset_handler = adpt_reset,
3244 .bios_param = adpt_bios_param,
3245 .slave_configure = adpt_slave_configure,
3246 .can_queue = MAX_TO_IOP_MESSAGES,
3250 static int __init adpt_init(void)
3253 adpt_hba *pHba, *next;
3255 printk("Loading Adaptec I2O RAID: Version " DPT_I2O_VERSION "\n");
3257 error = adpt_detect(&driver_template);
3260 if (hba_chain == NULL)
3263 for (pHba = hba_chain; pHba; pHba = pHba->next) {
3264 error = scsi_add_host(pHba->host, &pHba->pDev->dev);
3267 scsi_scan_host(pHba->host);
3271 for (pHba = hba_chain; pHba; pHba = next) {
3273 scsi_remove_host(pHba->host);
3278 static void __exit adpt_exit(void)
3280 adpt_hba *pHba, *next;
3282 for (pHba = hba_chain; pHba; pHba = next) {
3288 module_init(adpt_init);
3289 module_exit(adpt_exit);
3291 MODULE_LICENSE("GPL");