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/smp_lock.h>
53 #include <linux/spinlock.h>
54 #include <linux/dma-mapping.h>
56 #include <linux/timer.h>
57 #include <linux/string.h>
58 #include <linux/ioport.h>
59 #include <linux/mutex.h>
61 #include <asm/processor.h> /* for boot_cpu_data */
62 #include <asm/pgtable.h>
63 #include <asm/io.h> /* for virt_to_bus, etc. */
65 #include <scsi/scsi.h>
66 #include <scsi/scsi_cmnd.h>
67 #include <scsi/scsi_device.h>
68 #include <scsi/scsi_host.h>
69 #include <scsi/scsi_tcq.h>
71 #include "dpt/dptsig.h"
74 /*============================================================================
75 * Create a binary signature - this is read by dptsig
76 * Needed for our management apps
77 *============================================================================
79 static dpt_sig_S DPTI_sig
= {
80 {'d', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION
,
82 PROC_INTEL
, PROC_386
| PROC_486
| PROC_PENTIUM
| PROC_SEXIUM
,
83 #elif defined(__ia64__)
84 PROC_INTEL
, PROC_IA64
,
85 #elif defined(__sparc__)
86 PROC_ULTRASPARC
, PROC_ULTRASPARC
,
87 #elif defined(__alpha__)
88 PROC_ALPHA
, PROC_ALPHA
,
92 FT_HBADRVR
, 0, OEM_DPT
, OS_LINUX
, CAP_OVERLAP
, DEV_ALL
,
93 ADF_ALL_SC5
, 0, 0, DPT_VERSION
, DPT_REVISION
, DPT_SUBREVISION
,
94 DPT_MONTH
, DPT_DAY
, DPT_YEAR
, "Adaptec Linux I2O RAID Driver"
100 /*============================================================================
102 *============================================================================
105 static DEFINE_MUTEX(adpt_configuration_lock
);
107 static struct i2o_sys_tbl
*sys_tbl
;
108 static dma_addr_t sys_tbl_pa
;
109 static int sys_tbl_ind
;
110 static int sys_tbl_len
;
112 static adpt_hba
* hba_chain
= NULL
;
113 static int hba_count
= 0;
115 static struct class *adpt_sysfs_class
;
117 static long adpt_unlocked_ioctl(struct file
*, unsigned int, unsigned long);
119 static long compat_adpt_ioctl(struct file
*, unsigned int, unsigned long);
122 static const struct file_operations adpt_fops
= {
123 .unlocked_ioctl
= adpt_unlocked_ioctl
,
125 .release
= adpt_close
,
127 .compat_ioctl
= compat_adpt_ioctl
,
131 /* Structures and definitions for synchronous message posting.
132 * See adpt_i2o_post_wait() for description
134 struct adpt_i2o_post_wait_data
138 adpt_wait_queue_head_t
*wq
;
139 struct adpt_i2o_post_wait_data
*next
;
142 static struct adpt_i2o_post_wait_data
*adpt_post_wait_queue
= NULL
;
143 static u32 adpt_post_wait_id
= 0;
144 static DEFINE_SPINLOCK(adpt_post_wait_lock
);
147 /*============================================================================
149 *============================================================================
152 static inline int dpt_dma64(adpt_hba
*pHba
)
154 return (sizeof(dma_addr_t
) > 4 && (pHba
)->dma64
);
157 static inline u32
dma_high(dma_addr_t addr
)
159 return upper_32_bits(addr
);
162 static inline u32
dma_low(dma_addr_t addr
)
167 static u8
adpt_read_blink_led(adpt_hba
* host
)
169 if (host
->FwDebugBLEDflag_P
) {
170 if( readb(host
->FwDebugBLEDflag_P
) == 0xbc ){
171 return readb(host
->FwDebugBLEDvalue_P
);
177 /*============================================================================
178 * Scsi host template interface functions
179 *============================================================================
182 static struct pci_device_id dptids
[] = {
183 { PCI_DPT_VENDOR_ID
, PCI_DPT_DEVICE_ID
, PCI_ANY_ID
, PCI_ANY_ID
,},
184 { PCI_DPT_VENDOR_ID
, PCI_DPT_RAPTOR_DEVICE_ID
, PCI_ANY_ID
, PCI_ANY_ID
,},
187 MODULE_DEVICE_TABLE(pci
,dptids
);
189 static int adpt_detect(struct scsi_host_template
* sht
)
191 struct pci_dev
*pDev
= NULL
;
195 PINFO("Detecting Adaptec I2O RAID controllers...\n");
197 /* search for all Adatpec I2O RAID cards */
198 while ((pDev
= pci_get_device( PCI_DPT_VENDOR_ID
, PCI_ANY_ID
, pDev
))) {
199 if(pDev
->device
== PCI_DPT_DEVICE_ID
||
200 pDev
->device
== PCI_DPT_RAPTOR_DEVICE_ID
){
201 if(adpt_install_hba(sht
, pDev
) ){
202 PERROR("Could not Init an I2O RAID device\n");
203 PERROR("Will not try to detect others.\n");
210 /* In INIT state, Activate IOPs */
211 for (pHba
= hba_chain
; pHba
; pHba
= next
) {
213 // Activate does get status , init outbound, and get hrt
214 if (adpt_i2o_activate_hba(pHba
) < 0) {
215 adpt_i2o_delete_hba(pHba
);
220 /* Active IOPs in HOLD state */
223 if (hba_chain
== NULL
)
227 * If build_sys_table fails, we kill everything and bail
228 * as we can't init the IOPs w/o a system table
230 if (adpt_i2o_build_sys_table() < 0) {
231 adpt_i2o_sys_shutdown();
235 PDEBUG("HBA's in HOLD state\n");
237 /* If IOP don't get online, we need to rebuild the System table */
238 for (pHba
= hba_chain
; pHba
; pHba
= pHba
->next
) {
239 if (adpt_i2o_online_hba(pHba
) < 0) {
240 adpt_i2o_delete_hba(pHba
);
241 goto rebuild_sys_tab
;
245 /* Active IOPs now in OPERATIONAL state */
246 PDEBUG("HBA's in OPERATIONAL state\n");
248 printk("dpti: If you have a lot of devices this could take a few minutes.\n");
249 for (pHba
= hba_chain
; pHba
; pHba
= next
) {
251 printk(KERN_INFO
"%s: Reading the hardware resource table.\n", pHba
->name
);
252 if (adpt_i2o_lct_get(pHba
) < 0){
253 adpt_i2o_delete_hba(pHba
);
257 if (adpt_i2o_parse_lct(pHba
) < 0){
258 adpt_i2o_delete_hba(pHba
);
264 adpt_sysfs_class
= class_create(THIS_MODULE
, "dpt_i2o");
265 if (IS_ERR(adpt_sysfs_class
)) {
266 printk(KERN_WARNING
"dpti: unable to create dpt_i2o class\n");
267 adpt_sysfs_class
= NULL
;
270 for (pHba
= hba_chain
; pHba
; pHba
= next
) {
272 if (adpt_scsi_host_alloc(pHba
, sht
) < 0){
273 adpt_i2o_delete_hba(pHba
);
276 pHba
->initialized
= TRUE
;
277 pHba
->state
&= ~DPTI_STATE_RESET
;
278 if (adpt_sysfs_class
) {
279 struct device
*dev
= device_create(adpt_sysfs_class
,
280 NULL
, MKDEV(DPTI_I2O_MAJOR
, pHba
->unit
), NULL
,
281 "dpti%d", pHba
->unit
);
283 printk(KERN_WARNING
"dpti%d: unable to "
284 "create device in dpt_i2o class\n",
290 // Register our control device node
291 // nodes will need to be created in /dev to access this
292 // the nodes can not be created from within the driver
293 if (hba_count
&& register_chrdev(DPTI_I2O_MAJOR
, DPT_DRIVER
, &adpt_fops
)) {
294 adpt_i2o_sys_shutdown();
302 * scsi_unregister will be called AFTER we return.
304 static int adpt_release(struct Scsi_Host
*host
)
306 adpt_hba
* pHba
= (adpt_hba
*) host
->hostdata
[0];
307 // adpt_i2o_quiesce_hba(pHba);
308 adpt_i2o_delete_hba(pHba
);
309 scsi_unregister(host
);
314 static void adpt_inquiry(adpt_hba
* pHba
)
328 memset(msg
, 0, sizeof(msg
));
329 buf
= dma_alloc_coherent(&pHba
->pDev
->dev
, 80, &addr
, GFP_KERNEL
);
331 printk(KERN_ERR
"%s: Could not allocate buffer\n",pHba
->name
);
334 memset((void*)buf
, 0, 36);
337 direction
= 0x00000000;
338 scsidir
=0x40000000; // DATA IN (iop<--dev)
341 reqlen
= 17; // SINGLE SGE, 64 bit
343 reqlen
= 14; // SINGLE SGE, 32 bit
344 /* Stick the headers on */
345 msg
[0] = reqlen
<<16 | SGL_OFFSET_12
;
346 msg
[1] = (0xff<<24|HOST_TID
<<12|ADAPTER_TID
);
349 // Adaptec/DPT Private stuff
350 msg
[4] = I2O_CMD_SCSI_EXEC
|DPT_ORGANIZATION_ID
<<16;
351 msg
[5] = ADAPTER_TID
| 1<<16 /* Interpret*/;
352 /* Direction, disconnect ok | sense data | simple queue , CDBLen */
353 // I2O_SCB_FLAG_ENABLE_DISCONNECT |
354 // I2O_SCB_FLAG_SIMPLE_QUEUE_TAG |
355 // I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
356 msg
[6] = scsidir
|0x20a00000| 6 /* cmd len*/;
360 memset(scb
, 0, sizeof(scb
));
361 // Write SCSI command into the message - always 16 byte block
368 // Don't care about the rest of scb
370 memcpy(mptr
, scb
, sizeof(scb
));
372 lenptr
=mptr
++; /* Remember me - fill in when we know */
374 /* Now fill in the SGList and command */
376 if (dpt_dma64(pHba
)) {
377 *mptr
++ = (0x7C<<24)+(2<<16)+0x02; /* Enable 64 bit */
378 *mptr
++ = 1 << PAGE_SHIFT
;
379 *mptr
++ = 0xD0000000|direction
|len
;
380 *mptr
++ = dma_low(addr
);
381 *mptr
++ = dma_high(addr
);
383 *mptr
++ = 0xD0000000|direction
|len
;
387 // Send it on it's way
388 rcode
= adpt_i2o_post_wait(pHba
, msg
, reqlen
<<2, 120);
390 sprintf(pHba
->detail
, "Adaptec I2O RAID");
391 printk(KERN_INFO
"%s: Inquiry Error (%d)\n",pHba
->name
,rcode
);
392 if (rcode
!= -ETIME
&& rcode
!= -EINTR
)
393 dma_free_coherent(&pHba
->pDev
->dev
, 80, buf
, addr
);
395 memset(pHba
->detail
, 0, sizeof(pHba
->detail
));
396 memcpy(&(pHba
->detail
), "Vendor: Adaptec ", 16);
397 memcpy(&(pHba
->detail
[16]), " Model: ", 8);
398 memcpy(&(pHba
->detail
[24]), (u8
*) &buf
[16], 16);
399 memcpy(&(pHba
->detail
[40]), " FW: ", 4);
400 memcpy(&(pHba
->detail
[44]), (u8
*) &buf
[32], 4);
401 pHba
->detail
[48] = '\0'; /* precautionary */
402 dma_free_coherent(&pHba
->pDev
->dev
, 80, buf
, addr
);
404 adpt_i2o_status_get(pHba
);
409 static int adpt_slave_configure(struct scsi_device
* device
)
411 struct Scsi_Host
*host
= device
->host
;
414 pHba
= (adpt_hba
*) host
->hostdata
[0];
416 if (host
->can_queue
&& device
->tagged_supported
) {
417 scsi_adjust_queue_depth(device
, MSG_SIMPLE_TAG
,
418 host
->can_queue
- 1);
420 scsi_adjust_queue_depth(device
, 0, 1);
425 static int adpt_queue(struct scsi_cmnd
* cmd
, void (*done
) (struct scsi_cmnd
*))
427 adpt_hba
* pHba
= NULL
;
428 struct adpt_device
* pDev
= NULL
; /* dpt per device information */
430 cmd
->scsi_done
= done
;
432 * SCSI REQUEST_SENSE commands will be executed automatically by the
433 * Host Adapter for any errors, so they should not be executed
434 * explicitly unless the Sense Data is zero indicating that no error
438 if ((cmd
->cmnd
[0] == REQUEST_SENSE
) && (cmd
->sense_buffer
[0] != 0)) {
439 cmd
->result
= (DID_OK
<< 16);
444 pHba
= (adpt_hba
*)cmd
->device
->host
->hostdata
[0];
451 * TODO: I need to block here if I am processing ioctl cmds
452 * but if the outstanding cmds all finish before the ioctl,
453 * the scsi-core will not know to start sending cmds to me again.
454 * I need to a way to restart the scsi-cores queues or should I block
455 * calling scsi_done on the outstanding cmds instead
456 * for now we don't set the IOCTL state
458 if(((pHba
->state
) & DPTI_STATE_IOCTL
) || ((pHba
->state
) & DPTI_STATE_RESET
)) {
459 pHba
->host
->last_reset
= jiffies
;
460 pHba
->host
->resetting
= 1;
464 // TODO if the cmd->device if offline then I may need to issue a bus rescan
465 // followed by a get_lct to see if the device is there anymore
466 if((pDev
= (struct adpt_device
*) (cmd
->device
->hostdata
)) == NULL
) {
468 * First command request for this device. Set up a pointer
469 * to the device structure. This should be a TEST_UNIT_READY
470 * command from scan_scsis_single.
472 if ((pDev
= adpt_find_device(pHba
, (u32
)cmd
->device
->channel
, (u32
)cmd
->device
->id
, (u32
)cmd
->device
->lun
)) == NULL
) {
473 // TODO: if any luns are at this bus, scsi id then fake a TEST_UNIT_READY and INQUIRY response
474 // with type 7F (for all luns less than the max for this bus,id) so the lun scan will continue.
475 cmd
->result
= (DID_NO_CONNECT
<< 16);
479 cmd
->device
->hostdata
= pDev
;
481 pDev
->pScsi_dev
= cmd
->device
;
484 * If we are being called from when the device is being reset,
485 * delay processing of the command until later.
487 if (pDev
->state
& DPTI_DEV_RESET
) {
490 return adpt_scsi_to_i2o(pHba
, cmd
, pDev
);
493 static int adpt_bios_param(struct scsi_device
*sdev
, struct block_device
*dev
,
494 sector_t capacity
, int geom
[])
500 // *** First lets set the default geometry ****
502 // If the capacity is less than ox2000
503 if (capacity
< 0x2000 ) { // floppy
507 // else if between 0x2000 and 0x20000
508 else if (capacity
< 0x20000) {
512 // else if between 0x20000 and 0x40000
513 else if (capacity
< 0x40000) {
517 // else if between 0x4000 and 0x80000
518 else if (capacity
< 0x80000) {
522 // else if greater than 0x80000
527 cylinders
= sector_div(capacity
, heads
* sectors
);
529 // Special case if CDROM
530 if(sdev
->type
== 5) { // CDROM
540 PDEBUG("adpt_bios_param: exit\n");
545 static const char *adpt_info(struct Scsi_Host
*host
)
549 pHba
= (adpt_hba
*) host
->hostdata
[0];
550 return (char *) (pHba
->detail
);
553 static int adpt_proc_info(struct Scsi_Host
*host
, char *buffer
, char **start
, off_t offset
,
554 int length
, int inout
)
556 struct adpt_device
* d
;
568 * The user has done a write and wants us to take the
569 * data in the buffer and do something with it.
570 * proc_scsiwrite calls us with inout = 1
572 * Read data from buffer (writing to us) - NOT SUPPORTED
578 * inout = 0 means the user has done a read and wants information
579 * returned, so we write information about the cards into the buffer
580 * proc_scsiread() calls us with inout = 0
583 // Find HBA (host bus adapter) we are looking for
584 mutex_lock(&adpt_configuration_lock
);
585 for (pHba
= hba_chain
; pHba
; pHba
= pHba
->next
) {
586 if (pHba
->host
== host
) {
587 break; /* found adapter */
590 mutex_unlock(&adpt_configuration_lock
);
596 len
= sprintf(buffer
, "Adaptec I2O RAID Driver Version: %s\n\n", DPT_I2O_VERSION
);
597 len
+= sprintf(buffer
+len
, "%s\n", pHba
->detail
);
598 len
+= sprintf(buffer
+len
, "SCSI Host=scsi%d Control Node=/dev/%s irq=%d\n",
599 pHba
->host
->host_no
, pHba
->name
, host
->irq
);
600 len
+= sprintf(buffer
+len
, "\tpost fifo size = %d\n\treply fifo size = %d\n\tsg table size = %d\n\n",
601 host
->can_queue
, (int) pHba
->reply_fifo_size
, host
->sg_tablesize
);
606 if(pos
> offset
+ length
) {
611 * If we haven't even written to where we last left
612 * off (the last time we were called), reset the
618 len
+= sprintf(buffer
+len
, "Devices:\n");
619 for(chan
= 0; chan
< MAX_CHANNEL
; chan
++) {
620 for(id
= 0; id
< MAX_ID
; id
++) {
621 d
= pHba
->channel
[chan
].device
[id
];
623 len
+= sprintf(buffer
+len
,"\t%-24.24s", d
->pScsi_dev
->vendor
);
624 len
+= sprintf(buffer
+len
," Rev: %-8.8s\n", d
->pScsi_dev
->rev
);
629 if(pos
> offset
+ length
) {
637 unit
= d
->pI2o_dev
->lct_data
.tid
;
638 len
+= sprintf(buffer
+len
, "\tTID=%d, (Channel=%d, Target=%d, Lun=%d) (%s)\n\n",
639 unit
, (int)d
->scsi_channel
, (int)d
->scsi_id
, (int)d
->scsi_lun
,
640 scsi_device_online(d
->pScsi_dev
)? "online":"offline");
644 if(pos
> offset
+ length
) {
658 * begin is where we last checked our position with regards to offset
659 * begin is always less than offset. len is relative to begin. It
660 * is the number of bytes written past begin
664 /* stop the output and calculate the correct length */
665 *(buffer
+ len
) = '\0';
667 *start
= buffer
+ (offset
- begin
); /* Start of wanted data */
668 len
-= (offset
- begin
);
679 * Turn a struct scsi_cmnd * into a unique 32 bit 'context'.
681 static u32
adpt_cmd_to_context(struct scsi_cmnd
*cmd
)
683 return (u32
)cmd
->serial_number
;
687 * Go from a u32 'context' to a struct scsi_cmnd * .
688 * This could probably be made more efficient.
690 static struct scsi_cmnd
*
691 adpt_cmd_from_context(adpt_hba
* pHba
, u32 context
)
693 struct scsi_cmnd
* cmd
;
694 struct scsi_device
* d
;
699 spin_unlock(pHba
->host
->host_lock
);
700 shost_for_each_device(d
, pHba
->host
) {
702 spin_lock_irqsave(&d
->list_lock
, flags
);
703 list_for_each_entry(cmd
, &d
->cmd_list
, list
) {
704 if (((u32
)cmd
->serial_number
== context
)) {
705 spin_unlock_irqrestore(&d
->list_lock
, flags
);
707 spin_lock(pHba
->host
->host_lock
);
711 spin_unlock_irqrestore(&d
->list_lock
, flags
);
713 spin_lock(pHba
->host
->host_lock
);
719 * Turn a pointer to ioctl reply data into an u32 'context'
721 static u32
adpt_ioctl_to_context(adpt_hba
* pHba
, void *reply
)
723 #if BITS_PER_LONG == 32
724 return (u32
)(unsigned long)reply
;
729 spin_lock_irqsave(pHba
->host
->host_lock
, flags
);
730 nr
= ARRAY_SIZE(pHba
->ioctl_reply_context
);
731 for (i
= 0; i
< nr
; i
++) {
732 if (pHba
->ioctl_reply_context
[i
] == NULL
) {
733 pHba
->ioctl_reply_context
[i
] = reply
;
737 spin_unlock_irqrestore(pHba
->host
->host_lock
, flags
);
740 printk(KERN_WARNING
"%s: Too many outstanding "
741 "ioctl commands\n", pHba
->name
);
750 * Go from an u32 'context' to a pointer to ioctl reply data.
752 static void *adpt_ioctl_from_context(adpt_hba
*pHba
, u32 context
)
754 #if BITS_PER_LONG == 32
755 return (void *)(unsigned long)context
;
757 void *p
= pHba
->ioctl_reply_context
[context
];
758 pHba
->ioctl_reply_context
[context
] = NULL
;
764 /*===========================================================================
765 * Error Handling routines
766 *===========================================================================
769 static int adpt_abort(struct scsi_cmnd
* cmd
)
771 adpt_hba
* pHba
= NULL
; /* host bus adapter structure */
772 struct adpt_device
* dptdevice
; /* dpt per device information */
776 if(cmd
->serial_number
== 0){
779 pHba
= (adpt_hba
*) cmd
->device
->host
->hostdata
[0];
780 printk(KERN_INFO
"%s: Trying to Abort cmd=%ld\n",pHba
->name
, cmd
->serial_number
);
781 if ((dptdevice
= (void*) (cmd
->device
->hostdata
)) == NULL
) {
782 printk(KERN_ERR
"%s: Unable to abort: No device in cmnd\n",pHba
->name
);
786 memset(msg
, 0, sizeof(msg
));
787 msg
[0] = FIVE_WORD_MSG_SIZE
|SGL_OFFSET_0
;
788 msg
[1] = I2O_CMD_SCSI_ABORT
<<24|HOST_TID
<<12|dptdevice
->tid
;
791 msg
[4] = adpt_cmd_to_context(cmd
);
793 spin_lock_irq(pHba
->host
->host_lock
);
794 rcode
= adpt_i2o_post_wait(pHba
, msg
, sizeof(msg
), FOREVER
);
796 spin_unlock_irq(pHba
->host
->host_lock
);
798 if(rcode
== -EOPNOTSUPP
){
799 printk(KERN_INFO
"%s: Abort cmd not supported\n",pHba
->name
);
802 printk(KERN_INFO
"%s: Abort cmd=%ld failed.\n",pHba
->name
, cmd
->serial_number
);
805 printk(KERN_INFO
"%s: Abort cmd=%ld complete.\n",pHba
->name
, cmd
->serial_number
);
810 #define I2O_DEVICE_RESET 0x27
811 // This is the same for BLK and SCSI devices
812 // NOTE this is wrong in the i2o.h definitions
813 // This is not currently supported by our adapter but we issue it anyway
814 static int adpt_device_reset(struct scsi_cmnd
* cmd
)
820 struct adpt_device
* d
= cmd
->device
->hostdata
;
822 pHba
= (void*) cmd
->device
->host
->hostdata
[0];
823 printk(KERN_INFO
"%s: Trying to reset device\n",pHba
->name
);
825 printk(KERN_INFO
"%s: Reset Device: Device Not found\n",pHba
->name
);
828 memset(msg
, 0, sizeof(msg
));
829 msg
[0] = FOUR_WORD_MSG_SIZE
|SGL_OFFSET_0
;
830 msg
[1] = (I2O_DEVICE_RESET
<<24|HOST_TID
<<12|d
->tid
);
835 spin_lock_irq(pHba
->host
->host_lock
);
836 old_state
= d
->state
;
837 d
->state
|= DPTI_DEV_RESET
;
838 rcode
= adpt_i2o_post_wait(pHba
, msg
,sizeof(msg
), FOREVER
);
839 d
->state
= old_state
;
841 spin_unlock_irq(pHba
->host
->host_lock
);
843 if(rcode
== -EOPNOTSUPP
){
844 printk(KERN_INFO
"%s: Device reset not supported\n",pHba
->name
);
847 printk(KERN_INFO
"%s: Device reset failed\n",pHba
->name
);
850 printk(KERN_INFO
"%s: Device reset successful\n",pHba
->name
);
856 #define I2O_HBA_BUS_RESET 0x87
857 // This version of bus reset is called by the eh_error handler
858 static int adpt_bus_reset(struct scsi_cmnd
* cmd
)
864 pHba
= (adpt_hba
*)cmd
->device
->host
->hostdata
[0];
865 memset(msg
, 0, sizeof(msg
));
866 printk(KERN_WARNING
"%s: Bus reset: SCSI Bus %d: tid: %d\n",pHba
->name
, cmd
->device
->channel
,pHba
->channel
[cmd
->device
->channel
].tid
);
867 msg
[0] = FOUR_WORD_MSG_SIZE
|SGL_OFFSET_0
;
868 msg
[1] = (I2O_HBA_BUS_RESET
<<24|HOST_TID
<<12|pHba
->channel
[cmd
->device
->channel
].tid
);
872 spin_lock_irq(pHba
->host
->host_lock
);
873 rcode
= adpt_i2o_post_wait(pHba
, msg
,sizeof(msg
), FOREVER
);
875 spin_unlock_irq(pHba
->host
->host_lock
);
877 printk(KERN_WARNING
"%s: Bus reset failed.\n",pHba
->name
);
880 printk(KERN_WARNING
"%s: Bus reset success.\n",pHba
->name
);
885 // This version of reset is called by the eh_error_handler
886 static int __adpt_reset(struct scsi_cmnd
* cmd
)
890 pHba
= (adpt_hba
*)cmd
->device
->host
->hostdata
[0];
891 printk(KERN_WARNING
"%s: Hba Reset: scsi id %d: tid: %d\n",pHba
->name
,cmd
->device
->channel
,pHba
->channel
[cmd
->device
->channel
].tid
);
892 rcode
= adpt_hba_reset(pHba
);
894 printk(KERN_WARNING
"%s: HBA reset complete\n",pHba
->name
);
897 printk(KERN_WARNING
"%s: HBA reset failed (%x)\n",pHba
->name
, rcode
);
902 static int adpt_reset(struct scsi_cmnd
* cmd
)
906 spin_lock_irq(cmd
->device
->host
->host_lock
);
907 rc
= __adpt_reset(cmd
);
908 spin_unlock_irq(cmd
->device
->host
->host_lock
);
913 // This version of reset is called by the ioctls and indirectly from eh_error_handler via adpt_reset
914 static int adpt_hba_reset(adpt_hba
* pHba
)
918 pHba
->state
|= DPTI_STATE_RESET
;
920 // Activate does get status , init outbound, and get hrt
921 if ((rcode
=adpt_i2o_activate_hba(pHba
)) < 0) {
922 printk(KERN_ERR
"%s: Could not activate\n", pHba
->name
);
923 adpt_i2o_delete_hba(pHba
);
927 if ((rcode
=adpt_i2o_build_sys_table()) < 0) {
928 adpt_i2o_delete_hba(pHba
);
931 PDEBUG("%s: in HOLD state\n",pHba
->name
);
933 if ((rcode
=adpt_i2o_online_hba(pHba
)) < 0) {
934 adpt_i2o_delete_hba(pHba
);
937 PDEBUG("%s: in OPERATIONAL state\n",pHba
->name
);
939 if ((rcode
=adpt_i2o_lct_get(pHba
)) < 0){
940 adpt_i2o_delete_hba(pHba
);
944 if ((rcode
=adpt_i2o_reparse_lct(pHba
)) < 0){
945 adpt_i2o_delete_hba(pHba
);
948 pHba
->state
&= ~DPTI_STATE_RESET
;
950 adpt_fail_posted_scbs(pHba
);
951 return 0; /* return success */
954 /*===========================================================================
956 *===========================================================================
960 static void adpt_i2o_sys_shutdown(void)
962 adpt_hba
*pHba
, *pNext
;
963 struct adpt_i2o_post_wait_data
*p1
, *old
;
965 printk(KERN_INFO
"Shutting down Adaptec I2O controllers.\n");
966 printk(KERN_INFO
" This could take a few minutes if there are many devices attached\n");
967 /* Delete all IOPs from the controller chain */
968 /* They should have already been released by the
971 for (pHba
= hba_chain
; pHba
; pHba
= pNext
) {
973 adpt_i2o_delete_hba(pHba
);
976 /* Remove any timedout entries from the wait queue. */
977 // spin_lock_irqsave(&adpt_post_wait_lock, flags);
978 /* Nothing should be outstanding at this point so just
981 for(p1
= adpt_post_wait_queue
; p1
;) {
986 // spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
987 adpt_post_wait_queue
= NULL
;
989 printk(KERN_INFO
"Adaptec I2O controllers down.\n");
992 static int adpt_install_hba(struct scsi_host_template
* sht
, struct pci_dev
* pDev
)
995 adpt_hba
* pHba
= NULL
;
997 ulong base_addr0_phys
= 0;
998 ulong base_addr1_phys
= 0;
999 u32 hba_map0_area_size
= 0;
1000 u32 hba_map1_area_size
= 0;
1001 void __iomem
*base_addr_virt
= NULL
;
1002 void __iomem
*msg_addr_virt
= NULL
;
1005 int raptorFlag
= FALSE
;
1007 if(pci_enable_device(pDev
)) {
1011 if (pci_request_regions(pDev
, "dpt_i2o")) {
1012 PERROR("dpti: adpt_config_hba: pci request region failed\n");
1016 pci_set_master(pDev
);
1019 * See if we should enable dma64 mode.
1021 if (sizeof(dma_addr_t
) > 4 &&
1022 pci_set_dma_mask(pDev
, DMA_BIT_MASK(64)) == 0) {
1023 if (dma_get_required_mask(&pDev
->dev
) > DMA_BIT_MASK(32))
1026 if (!dma64
&& pci_set_dma_mask(pDev
, DMA_BIT_MASK(32)) != 0)
1029 /* adapter only supports message blocks below 4GB */
1030 pci_set_consistent_dma_mask(pDev
, DMA_BIT_MASK(32));
1032 base_addr0_phys
= pci_resource_start(pDev
,0);
1033 hba_map0_area_size
= pci_resource_len(pDev
,0);
1035 // Check if standard PCI card or single BAR Raptor
1036 if(pDev
->device
== PCI_DPT_DEVICE_ID
){
1037 if(pDev
->subsystem_device
>=0xc032 && pDev
->subsystem_device
<= 0xc03b){
1038 // Raptor card with this device id needs 4M
1039 hba_map0_area_size
= 0x400000;
1040 } else { // Not Raptor - it is a PCI card
1041 if(hba_map0_area_size
> 0x100000 ){
1042 hba_map0_area_size
= 0x100000;
1045 } else {// Raptor split BAR config
1046 // Use BAR1 in this configuration
1047 base_addr1_phys
= pci_resource_start(pDev
,1);
1048 hba_map1_area_size
= pci_resource_len(pDev
,1);
1052 #if BITS_PER_LONG == 64
1054 * The original Adaptec 64 bit driver has this comment here:
1055 * "x86_64 machines need more optimal mappings"
1057 * I assume some HBAs report ridiculously large mappings
1058 * and we need to limit them on platforms with IOMMUs.
1060 if (raptorFlag
== TRUE
) {
1061 if (hba_map0_area_size
> 128)
1062 hba_map0_area_size
= 128;
1063 if (hba_map1_area_size
> 524288)
1064 hba_map1_area_size
= 524288;
1066 if (hba_map0_area_size
> 524288)
1067 hba_map0_area_size
= 524288;
1071 base_addr_virt
= ioremap(base_addr0_phys
,hba_map0_area_size
);
1072 if (!base_addr_virt
) {
1073 pci_release_regions(pDev
);
1074 PERROR("dpti: adpt_config_hba: io remap failed\n");
1078 if(raptorFlag
== TRUE
) {
1079 msg_addr_virt
= ioremap(base_addr1_phys
, hba_map1_area_size
);
1080 if (!msg_addr_virt
) {
1081 PERROR("dpti: adpt_config_hba: io remap failed on BAR1\n");
1082 iounmap(base_addr_virt
);
1083 pci_release_regions(pDev
);
1087 msg_addr_virt
= base_addr_virt
;
1090 // Allocate and zero the data structure
1091 pHba
= kzalloc(sizeof(adpt_hba
), GFP_KERNEL
);
1093 if (msg_addr_virt
!= base_addr_virt
)
1094 iounmap(msg_addr_virt
);
1095 iounmap(base_addr_virt
);
1096 pci_release_regions(pDev
);
1100 mutex_lock(&adpt_configuration_lock
);
1102 if(hba_chain
!= NULL
){
1103 for(p
= hba_chain
; p
->next
; p
= p
->next
);
1109 pHba
->unit
= hba_count
;
1110 sprintf(pHba
->name
, "dpti%d", hba_count
);
1113 mutex_unlock(&adpt_configuration_lock
);
1116 pHba
->base_addr_phys
= base_addr0_phys
;
1118 // Set up the Virtual Base Address of the I2O Device
1119 pHba
->base_addr_virt
= base_addr_virt
;
1120 pHba
->msg_addr_virt
= msg_addr_virt
;
1121 pHba
->irq_mask
= base_addr_virt
+0x30;
1122 pHba
->post_port
= base_addr_virt
+0x40;
1123 pHba
->reply_port
= base_addr_virt
+0x44;
1128 pHba
->status_block
= NULL
;
1129 pHba
->post_count
= 0;
1130 pHba
->state
= DPTI_STATE_RESET
;
1132 pHba
->devices
= NULL
;
1133 pHba
->dma64
= dma64
;
1135 // Initializing the spinlocks
1136 spin_lock_init(&pHba
->state_lock
);
1137 spin_lock_init(&adpt_post_wait_lock
);
1139 if(raptorFlag
== 0){
1140 printk(KERN_INFO
"Adaptec I2O RAID controller"
1141 " %d at %p size=%x irq=%d%s\n",
1142 hba_count
-1, base_addr_virt
,
1143 hba_map0_area_size
, pDev
->irq
,
1144 dma64
? " (64-bit DMA)" : "");
1146 printk(KERN_INFO
"Adaptec I2O RAID controller %d irq=%d%s\n",
1147 hba_count
-1, pDev
->irq
,
1148 dma64
? " (64-bit DMA)" : "");
1149 printk(KERN_INFO
" BAR0 %p - size= %x\n",base_addr_virt
,hba_map0_area_size
);
1150 printk(KERN_INFO
" BAR1 %p - size= %x\n",msg_addr_virt
,hba_map1_area_size
);
1153 if (request_irq (pDev
->irq
, adpt_isr
, IRQF_SHARED
, pHba
->name
, pHba
)) {
1154 printk(KERN_ERR
"%s: Couldn't register IRQ %d\n", pHba
->name
, pDev
->irq
);
1155 adpt_i2o_delete_hba(pHba
);
1163 static void adpt_i2o_delete_hba(adpt_hba
* pHba
)
1167 struct i2o_device
* d
;
1168 struct i2o_device
* next
;
1171 struct adpt_device
* pDev
;
1172 struct adpt_device
* pNext
;
1175 mutex_lock(&adpt_configuration_lock
);
1176 // scsi_unregister calls our adpt_release which
1179 free_irq(pHba
->host
->irq
, pHba
);
1182 for( p1
= hba_chain
; p1
; p2
= p1
,p1
=p1
->next
){
1185 p2
->next
= p1
->next
;
1187 hba_chain
= p1
->next
;
1194 mutex_unlock(&adpt_configuration_lock
);
1196 iounmap(pHba
->base_addr_virt
);
1197 pci_release_regions(pHba
->pDev
);
1198 if(pHba
->msg_addr_virt
!= pHba
->base_addr_virt
){
1199 iounmap(pHba
->msg_addr_virt
);
1201 if(pHba
->FwDebugBuffer_P
)
1202 iounmap(pHba
->FwDebugBuffer_P
);
1204 dma_free_coherent(&pHba
->pDev
->dev
,
1205 pHba
->hrt
->num_entries
* pHba
->hrt
->entry_len
<< 2,
1206 pHba
->hrt
, pHba
->hrt_pa
);
1209 dma_free_coherent(&pHba
->pDev
->dev
, pHba
->lct_size
,
1210 pHba
->lct
, pHba
->lct_pa
);
1212 if(pHba
->status_block
) {
1213 dma_free_coherent(&pHba
->pDev
->dev
, sizeof(i2o_status_block
),
1214 pHba
->status_block
, pHba
->status_block_pa
);
1216 if(pHba
->reply_pool
) {
1217 dma_free_coherent(&pHba
->pDev
->dev
,
1218 pHba
->reply_fifo_size
* REPLY_FRAME_SIZE
* 4,
1219 pHba
->reply_pool
, pHba
->reply_pool_pa
);
1222 for(d
= pHba
->devices
; d
; d
= next
){
1226 for(i
= 0 ; i
< pHba
->top_scsi_channel
; i
++){
1227 for(j
= 0; j
< MAX_ID
; j
++){
1228 if(pHba
->channel
[i
].device
[j
] != NULL
){
1229 for(pDev
= pHba
->channel
[i
].device
[j
]; pDev
; pDev
= pNext
){
1230 pNext
= pDev
->next_lun
;
1236 pci_dev_put(pHba
->pDev
);
1237 if (adpt_sysfs_class
)
1238 device_destroy(adpt_sysfs_class
,
1239 MKDEV(DPTI_I2O_MAJOR
, pHba
->unit
));
1243 unregister_chrdev(DPTI_I2O_MAJOR
, DPT_DRIVER
);
1244 if (adpt_sysfs_class
) {
1245 class_destroy(adpt_sysfs_class
);
1246 adpt_sysfs_class
= NULL
;
1251 static struct adpt_device
* adpt_find_device(adpt_hba
* pHba
, u32 chan
, u32 id
, u32 lun
)
1253 struct adpt_device
* d
;
1255 if(chan
< 0 || chan
>= MAX_CHANNEL
)
1258 if( pHba
->channel
[chan
].device
== NULL
){
1259 printk(KERN_DEBUG
"Adaptec I2O RAID: Trying to find device before they are allocated\n");
1263 d
= pHba
->channel
[chan
].device
[id
];
1264 if(!d
|| d
->tid
== 0) {
1268 /* If it is the only lun at that address then this should match*/
1269 if(d
->scsi_lun
== lun
){
1273 /* else we need to look through all the luns */
1274 for(d
=d
->next_lun
; d
; d
= d
->next_lun
){
1275 if(d
->scsi_lun
== lun
){
1283 static int adpt_i2o_post_wait(adpt_hba
* pHba
, u32
* msg
, int len
, int timeout
)
1285 // I used my own version of the WAIT_QUEUE_HEAD
1286 // to handle some version differences
1287 // When embedded in the kernel this could go back to the vanilla one
1288 ADPT_DECLARE_WAIT_QUEUE_HEAD(adpt_wq_i2o_post
);
1291 struct adpt_i2o_post_wait_data
*p1
, *p2
;
1292 struct adpt_i2o_post_wait_data
*wait_data
=
1293 kmalloc(sizeof(struct adpt_i2o_post_wait_data
), GFP_ATOMIC
);
1294 DECLARE_WAITQUEUE(wait
, current
);
1300 * The spin locking is needed to keep anyone from playing
1301 * with the queue pointers and id while we do the same
1303 spin_lock_irqsave(&adpt_post_wait_lock
, flags
);
1304 // TODO we need a MORE unique way of getting ids
1305 // to support async LCT get
1306 wait_data
->next
= adpt_post_wait_queue
;
1307 adpt_post_wait_queue
= wait_data
;
1308 adpt_post_wait_id
++;
1309 adpt_post_wait_id
&= 0x7fff;
1310 wait_data
->id
= adpt_post_wait_id
;
1311 spin_unlock_irqrestore(&adpt_post_wait_lock
, flags
);
1313 wait_data
->wq
= &adpt_wq_i2o_post
;
1314 wait_data
->status
= -ETIMEDOUT
;
1316 add_wait_queue(&adpt_wq_i2o_post
, &wait
);
1318 msg
[2] |= 0x80000000 | ((u32
)wait_data
->id
);
1320 if((status
= adpt_i2o_post_this(pHba
, msg
, len
)) == 0){
1321 set_current_state(TASK_INTERRUPTIBLE
);
1323 spin_unlock_irq(pHba
->host
->host_lock
);
1327 timeout
= schedule_timeout(timeout
);
1329 // I/O issued, but cannot get result in
1330 // specified time. Freeing resorces is
1336 spin_lock_irq(pHba
->host
->host_lock
);
1338 remove_wait_queue(&adpt_wq_i2o_post
, &wait
);
1340 if(status
== -ETIMEDOUT
){
1341 printk(KERN_INFO
"dpti%d: POST WAIT TIMEOUT\n",pHba
->unit
);
1342 // We will have to free the wait_data memory during shutdown
1346 /* Remove the entry from the queue. */
1348 spin_lock_irqsave(&adpt_post_wait_lock
, flags
);
1349 for(p1
= adpt_post_wait_queue
; p1
; p2
= p1
, p1
= p1
->next
) {
1350 if(p1
== wait_data
) {
1351 if(p1
->status
== I2O_DETAIL_STATUS_UNSUPPORTED_FUNCTION
) {
1352 status
= -EOPNOTSUPP
;
1355 p2
->next
= p1
->next
;
1357 adpt_post_wait_queue
= p1
->next
;
1362 spin_unlock_irqrestore(&adpt_post_wait_lock
, flags
);
1370 static s32
adpt_i2o_post_this(adpt_hba
* pHba
, u32
* data
, int len
)
1373 u32 m
= EMPTY_QUEUE
;
1375 ulong timeout
= jiffies
+ 30*HZ
;
1378 m
= readl(pHba
->post_port
);
1379 if (m
!= EMPTY_QUEUE
) {
1382 if(time_after(jiffies
,timeout
)){
1383 printk(KERN_WARNING
"dpti%d: Timeout waiting for message frame!\n", pHba
->unit
);
1386 schedule_timeout_uninterruptible(1);
1387 } while(m
== EMPTY_QUEUE
);
1389 msg
= pHba
->msg_addr_virt
+ m
;
1390 memcpy_toio(msg
, data
, len
);
1394 writel(m
, pHba
->post_port
);
1401 static void adpt_i2o_post_wait_complete(u32 context
, int status
)
1403 struct adpt_i2o_post_wait_data
*p1
= NULL
;
1405 * We need to search through the adpt_post_wait
1406 * queue to see if the given message is still
1407 * outstanding. If not, it means that the IOP
1408 * took longer to respond to the message than we
1409 * had allowed and timer has already expired.
1410 * Not much we can do about that except log
1411 * it for debug purposes, increase timeout, and recompile
1413 * Lock needed to keep anyone from moving queue pointers
1414 * around while we're looking through them.
1419 spin_lock(&adpt_post_wait_lock
);
1420 for(p1
= adpt_post_wait_queue
; p1
; p1
= p1
->next
) {
1421 if(p1
->id
== context
) {
1422 p1
->status
= status
;
1423 spin_unlock(&adpt_post_wait_lock
);
1424 wake_up_interruptible(p1
->wq
);
1428 spin_unlock(&adpt_post_wait_lock
);
1429 // If this happens we lose commands that probably really completed
1430 printk(KERN_DEBUG
"dpti: Could Not find task %d in wait queue\n",context
);
1431 printk(KERN_DEBUG
" Tasks in wait queue:\n");
1432 for(p1
= adpt_post_wait_queue
; p1
; p1
= p1
->next
) {
1433 printk(KERN_DEBUG
" %d\n",p1
->id
);
1438 static s32
adpt_i2o_reset_hba(adpt_hba
* pHba
)
1443 u32 m
= EMPTY_QUEUE
;
1444 ulong timeout
= jiffies
+ (TMOUT_IOPRESET
*HZ
);
1446 if(pHba
->initialized
== FALSE
) { // First time reset should be quick
1447 timeout
= jiffies
+ (25*HZ
);
1449 adpt_i2o_quiesce_hba(pHba
);
1454 m
= readl(pHba
->post_port
);
1455 if (m
!= EMPTY_QUEUE
) {
1458 if(time_after(jiffies
,timeout
)){
1459 printk(KERN_WARNING
"Timeout waiting for message!\n");
1462 schedule_timeout_uninterruptible(1);
1463 } while (m
== EMPTY_QUEUE
);
1465 status
= dma_alloc_coherent(&pHba
->pDev
->dev
, 4, &addr
, GFP_KERNEL
);
1466 if(status
== NULL
) {
1467 adpt_send_nop(pHba
, m
);
1468 printk(KERN_ERR
"IOP reset failed - no free memory.\n");
1473 msg
[0]=EIGHT_WORD_MSG_SIZE
|SGL_OFFSET_0
;
1474 msg
[1]=I2O_CMD_ADAPTER_RESET
<<24|HOST_TID
<<12|ADAPTER_TID
;
1479 msg
[6]=dma_low(addr
);
1480 msg
[7]=dma_high(addr
);
1482 memcpy_toio(pHba
->msg_addr_virt
+m
, msg
, sizeof(msg
));
1484 writel(m
, pHba
->post_port
);
1487 while(*status
== 0){
1488 if(time_after(jiffies
,timeout
)){
1489 printk(KERN_WARNING
"%s: IOP Reset Timeout\n",pHba
->name
);
1490 /* We lose 4 bytes of "status" here, but we cannot
1491 free these because controller may awake and corrupt
1492 those bytes at any time */
1493 /* dma_free_coherent(&pHba->pDev->dev, 4, buf, addr); */
1497 schedule_timeout_uninterruptible(1);
1500 if(*status
== 0x01 /*I2O_EXEC_IOP_RESET_IN_PROGRESS*/) {
1501 PDEBUG("%s: Reset in progress...\n", pHba
->name
);
1502 // Here we wait for message frame to become available
1503 // indicated that reset has finished
1506 m
= readl(pHba
->post_port
);
1507 if (m
!= EMPTY_QUEUE
) {
1510 if(time_after(jiffies
,timeout
)){
1511 printk(KERN_ERR
"%s:Timeout waiting for IOP Reset.\n",pHba
->name
);
1512 /* We lose 4 bytes of "status" here, but we
1513 cannot free these because controller may
1514 awake and corrupt those bytes at any time */
1515 /* dma_free_coherent(&pHba->pDev->dev, 4, buf, addr); */
1518 schedule_timeout_uninterruptible(1);
1519 } while (m
== EMPTY_QUEUE
);
1521 adpt_send_nop(pHba
, m
);
1523 adpt_i2o_status_get(pHba
);
1524 if(*status
== 0x02 ||
1525 pHba
->status_block
->iop_state
!= ADAPTER_STATE_RESET
) {
1526 printk(KERN_WARNING
"%s: Reset reject, trying to clear\n",
1529 PDEBUG("%s: Reset completed.\n", pHba
->name
);
1532 dma_free_coherent(&pHba
->pDev
->dev
, 4, status
, addr
);
1534 // This delay is to allow someone attached to the card through the debug UART to
1535 // set up the dump levels that they want before the rest of the initialization sequence
1542 static int adpt_i2o_parse_lct(adpt_hba
* pHba
)
1547 struct i2o_device
*d
;
1548 i2o_lct
*lct
= pHba
->lct
;
1552 u32 buf
[10]; // larger than 7, or 8 ...
1553 struct adpt_device
* pDev
;
1556 printk(KERN_ERR
"%s: LCT is empty???\n",pHba
->name
);
1560 max
= lct
->table_size
;
1564 for(i
=0;i
<max
;i
++) {
1565 if( lct
->lct_entry
[i
].user_tid
!= 0xfff){
1567 * If we have hidden devices, we need to inform the upper layers about
1568 * the possible maximum id reference to handle device access when
1569 * an array is disassembled. This code has no other purpose but to
1570 * allow us future access to devices that are currently hidden
1571 * behind arrays, hotspares or have not been configured (JBOD mode).
1573 if( lct
->lct_entry
[i
].class_id
!= I2O_CLASS_RANDOM_BLOCK_STORAGE
&&
1574 lct
->lct_entry
[i
].class_id
!= I2O_CLASS_SCSI_PERIPHERAL
&&
1575 lct
->lct_entry
[i
].class_id
!= I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL
){
1578 tid
= lct
->lct_entry
[i
].tid
;
1579 // I2O_DPT_DEVICE_INFO_GROUP_NO;
1580 if(adpt_i2o_query_scalar(pHba
, tid
, 0x8000, -1, buf
, 32)<0) {
1583 bus_no
= buf
[0]>>16;
1585 scsi_lun
= (buf
[2]>>8 )&0xff;
1586 if(bus_no
>= MAX_CHANNEL
) { // Something wrong skip it
1587 printk(KERN_WARNING
"%s: Channel number %d out of range \n", pHba
->name
, bus_no
);
1590 if (scsi_id
>= MAX_ID
){
1591 printk(KERN_WARNING
"%s: SCSI ID %d out of range \n", pHba
->name
, bus_no
);
1594 if(bus_no
> pHba
->top_scsi_channel
){
1595 pHba
->top_scsi_channel
= bus_no
;
1597 if(scsi_id
> pHba
->top_scsi_id
){
1598 pHba
->top_scsi_id
= scsi_id
;
1600 if(scsi_lun
> pHba
->top_scsi_lun
){
1601 pHba
->top_scsi_lun
= scsi_lun
;
1605 d
= kmalloc(sizeof(struct i2o_device
), GFP_KERNEL
);
1608 printk(KERN_CRIT
"%s: Out of memory for I2O device data.\n",pHba
->name
);
1612 d
->controller
= pHba
;
1615 memcpy(&d
->lct_data
, &lct
->lct_entry
[i
], sizeof(i2o_lct_entry
));
1618 tid
= d
->lct_data
.tid
;
1619 adpt_i2o_report_hba_unit(pHba
, d
);
1620 adpt_i2o_install_device(pHba
, d
);
1623 for(d
= pHba
->devices
; d
; d
= d
->next
) {
1624 if(d
->lct_data
.class_id
== I2O_CLASS_BUS_ADAPTER_PORT
||
1625 d
->lct_data
.class_id
== I2O_CLASS_FIBRE_CHANNEL_PORT
){
1626 tid
= d
->lct_data
.tid
;
1627 // TODO get the bus_no from hrt-but for now they are in order
1629 if(bus_no
> pHba
->top_scsi_channel
){
1630 pHba
->top_scsi_channel
= bus_no
;
1632 pHba
->channel
[bus_no
].type
= d
->lct_data
.class_id
;
1633 pHba
->channel
[bus_no
].tid
= tid
;
1634 if(adpt_i2o_query_scalar(pHba
, tid
, 0x0200, -1, buf
, 28)>=0)
1636 pHba
->channel
[bus_no
].scsi_id
= buf
[1];
1637 PDEBUG("Bus %d - SCSI ID %d.\n", bus_no
, buf
[1]);
1639 // TODO remove - this is just until we get from hrt
1641 if(bus_no
>= MAX_CHANNEL
) { // Something wrong skip it
1642 printk(KERN_WARNING
"%s: Channel number %d out of range - LCT\n", pHba
->name
, bus_no
);
1648 // Setup adpt_device table
1649 for(d
= pHba
->devices
; d
; d
= d
->next
) {
1650 if(d
->lct_data
.class_id
== I2O_CLASS_RANDOM_BLOCK_STORAGE
||
1651 d
->lct_data
.class_id
== I2O_CLASS_SCSI_PERIPHERAL
||
1652 d
->lct_data
.class_id
== I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL
){
1654 tid
= d
->lct_data
.tid
;
1656 // I2O_DPT_DEVICE_INFO_GROUP_NO;
1657 if(adpt_i2o_query_scalar(pHba
, tid
, 0x8000, -1, buf
, 32)>=0) {
1658 bus_no
= buf
[0]>>16;
1660 scsi_lun
= (buf
[2]>>8 )&0xff;
1661 if(bus_no
>= MAX_CHANNEL
) { // Something wrong skip it
1664 if (scsi_id
>= MAX_ID
) {
1667 if( pHba
->channel
[bus_no
].device
[scsi_id
] == NULL
){
1668 pDev
= kzalloc(sizeof(struct adpt_device
),GFP_KERNEL
);
1672 pHba
->channel
[bus_no
].device
[scsi_id
] = pDev
;
1674 for( pDev
= pHba
->channel
[bus_no
].device
[scsi_id
];
1675 pDev
->next_lun
; pDev
= pDev
->next_lun
){
1677 pDev
->next_lun
= kzalloc(sizeof(struct adpt_device
),GFP_KERNEL
);
1678 if(pDev
->next_lun
== NULL
) {
1681 pDev
= pDev
->next_lun
;
1684 pDev
->scsi_channel
= bus_no
;
1685 pDev
->scsi_id
= scsi_id
;
1686 pDev
->scsi_lun
= scsi_lun
;
1689 pDev
->type
= (buf
[0])&0xff;
1690 pDev
->flags
= (buf
[0]>>8)&0xff;
1691 if(scsi_id
> pHba
->top_scsi_id
){
1692 pHba
->top_scsi_id
= scsi_id
;
1694 if(scsi_lun
> pHba
->top_scsi_lun
){
1695 pHba
->top_scsi_lun
= scsi_lun
;
1699 printk(KERN_WARNING
"Could not find SCSI ID for %s\n",
1700 d
->lct_data
.identity_tag
);
1709 * Each I2O controller has a chain of devices on it - these match
1710 * the useful parts of the LCT of the board.
1713 static int adpt_i2o_install_device(adpt_hba
* pHba
, struct i2o_device
*d
)
1715 mutex_lock(&adpt_configuration_lock
);
1718 d
->next
=pHba
->devices
;
1720 if (pHba
->devices
!= NULL
){
1721 pHba
->devices
->prev
=d
;
1726 mutex_unlock(&adpt_configuration_lock
);
1730 static int adpt_open(struct inode
*inode
, struct file
*file
)
1736 //TODO check for root access
1738 minor
= iminor(inode
);
1739 if (minor
>= hba_count
) {
1743 mutex_lock(&adpt_configuration_lock
);
1744 for (pHba
= hba_chain
; pHba
; pHba
= pHba
->next
) {
1745 if (pHba
->unit
== minor
) {
1746 break; /* found adapter */
1750 mutex_unlock(&adpt_configuration_lock
);
1755 // if(pHba->in_use){
1756 // mutex_unlock(&adpt_configuration_lock);
1761 mutex_unlock(&adpt_configuration_lock
);
1767 static int adpt_close(struct inode
*inode
, struct file
*file
)
1772 minor
= iminor(inode
);
1773 if (minor
>= hba_count
) {
1776 mutex_lock(&adpt_configuration_lock
);
1777 for (pHba
= hba_chain
; pHba
; pHba
= pHba
->next
) {
1778 if (pHba
->unit
== minor
) {
1779 break; /* found adapter */
1782 mutex_unlock(&adpt_configuration_lock
);
1793 static int adpt_i2o_passthru(adpt_hba
* pHba
, u32 __user
*arg
)
1795 u32 msg
[MAX_MESSAGE_SIZE
];
1799 u32 __user
*user_msg
= arg
;
1800 u32 __user
* user_reply
= NULL
;
1801 void *sg_list
[pHba
->sg_tablesize
];
1811 memset(&msg
, 0, MAX_MESSAGE_SIZE
*4);
1812 // get user msg size in u32s
1813 if(get_user(size
, &user_msg
[0])){
1818 user_reply
= &user_msg
[size
];
1819 if(size
> MAX_MESSAGE_SIZE
){
1822 size
*= 4; // Convert to bytes
1824 /* Copy in the user's I2O command */
1825 if(copy_from_user(msg
, user_msg
, size
)) {
1828 get_user(reply_size
, &user_reply
[0]);
1829 reply_size
= reply_size
>>16;
1830 if(reply_size
> REPLY_FRAME_SIZE
){
1831 reply_size
= REPLY_FRAME_SIZE
;
1834 reply
= kzalloc(REPLY_FRAME_SIZE
*4, GFP_KERNEL
);
1836 printk(KERN_WARNING
"%s: Could not allocate reply buffer\n",pHba
->name
);
1839 sg_offset
= (msg
[0]>>4)&0xf;
1840 msg
[2] = 0x40000000; // IOCTL context
1841 msg
[3] = adpt_ioctl_to_context(pHba
, reply
);
1842 if (msg
[3] == (u32
)-1)
1845 memset(sg_list
,0, sizeof(sg_list
[0])*pHba
->sg_tablesize
);
1847 // TODO add 64 bit API
1848 struct sg_simple_element
*sg
= (struct sg_simple_element
*) (msg
+sg_offset
);
1849 sg_count
= (size
- sg_offset
*4) / sizeof(struct sg_simple_element
);
1850 if (sg_count
> pHba
->sg_tablesize
){
1851 printk(KERN_DEBUG
"%s:IOCTL SG List too large (%u)\n", pHba
->name
,sg_count
);
1856 for(i
= 0; i
< sg_count
; i
++) {
1859 if (!(sg
[i
].flag_count
& 0x10000000 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT*/)) {
1860 printk(KERN_DEBUG
"%s:Bad SG element %d - not simple (%x)\n",pHba
->name
,i
, sg
[i
].flag_count
);
1864 sg_size
= sg
[i
].flag_count
& 0xffffff;
1865 /* Allocate memory for the transfer */
1866 p
= dma_alloc_coherent(&pHba
->pDev
->dev
, sg_size
, &addr
, GFP_KERNEL
);
1868 printk(KERN_DEBUG
"%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
1869 pHba
->name
,sg_size
,i
,sg_count
);
1873 sg_list
[sg_index
++] = p
; // sglist indexed with input frame, not our internal frame.
1874 /* Copy in the user's SG buffer if necessary */
1875 if(sg
[i
].flag_count
& 0x04000000 /*I2O_SGL_FLAGS_DIR*/) {
1876 // sg_simple_element API is 32 bit
1877 if (copy_from_user(p
,(void __user
*)(ulong
)sg
[i
].addr_bus
, sg_size
)) {
1878 printk(KERN_DEBUG
"%s: Could not copy SG buf %d FROM user\n",pHba
->name
,i
);
1883 /* sg_simple_element API is 32 bit, but addr < 4GB */
1884 sg
[i
].addr_bus
= addr
;
1890 spin_lock_irqsave(pHba
->host
->host_lock
, flags
);
1891 // This state stops any new commands from enterring the
1892 // controller while processing the ioctl
1893 // pHba->state |= DPTI_STATE_IOCTL;
1894 // We can't set this now - The scsi subsystem sets host_blocked and
1895 // the queue empties and stops. We need a way to restart the queue
1896 rcode
= adpt_i2o_post_wait(pHba
, msg
, size
, FOREVER
);
1898 printk("adpt_i2o_passthru: post wait failed %d %p\n",
1900 // pHba->state &= ~DPTI_STATE_IOCTL;
1902 spin_unlock_irqrestore(pHba
->host
->host_lock
, flags
);
1903 } while(rcode
== -ETIMEDOUT
);
1910 /* Copy back the Scatter Gather buffers back to user space */
1912 // TODO add 64 bit API
1913 struct sg_simple_element
* sg
;
1916 // re-acquire the original message to handle correctly the sg copy operation
1917 memset(&msg
, 0, MAX_MESSAGE_SIZE
*4);
1918 // get user msg size in u32s
1919 if(get_user(size
, &user_msg
[0])){
1925 if (size
> MAX_MESSAGE_SIZE
) {
1929 /* Copy in the user's I2O command */
1930 if (copy_from_user (msg
, user_msg
, size
)) {
1934 sg_count
= (size
- sg_offset
*4) / sizeof(struct sg_simple_element
);
1936 // TODO add 64 bit API
1937 sg
= (struct sg_simple_element
*)(msg
+ sg_offset
);
1938 for (j
= 0; j
< sg_count
; j
++) {
1939 /* Copy out the SG list to user's buffer if necessary */
1940 if(! (sg
[j
].flag_count
& 0x4000000 /*I2O_SGL_FLAGS_DIR*/)) {
1941 sg_size
= sg
[j
].flag_count
& 0xffffff;
1942 // sg_simple_element API is 32 bit
1943 if (copy_to_user((void __user
*)(ulong
)sg
[j
].addr_bus
,sg_list
[j
], sg_size
)) {
1944 printk(KERN_WARNING
"%s: Could not copy %p TO user %x\n",pHba
->name
, sg_list
[j
], sg
[j
].addr_bus
);
1952 /* Copy back the reply to user space */
1954 // we wrote our own values for context - now restore the user supplied ones
1955 if(copy_from_user(reply
+2, user_msg
+2, sizeof(u32
)*2)) {
1956 printk(KERN_WARNING
"%s: Could not copy message context FROM user\n",pHba
->name
);
1959 if(copy_to_user(user_reply
, reply
, reply_size
)) {
1960 printk(KERN_WARNING
"%s: Could not copy reply TO user\n",pHba
->name
);
1967 if (rcode
!= -ETIME
&& rcode
!= -EINTR
) {
1968 struct sg_simple_element
*sg
=
1969 (struct sg_simple_element
*) (msg
+sg_offset
);
1972 if(sg_list
[--sg_index
]) {
1973 dma_free_coherent(&pHba
->pDev
->dev
,
1974 sg
[sg_index
].flag_count
& 0xffffff,
1976 sg
[sg_index
].addr_bus
);
1983 #if defined __ia64__
1984 static void adpt_ia64_info(sysInfo_S
* si
)
1986 // This is all the info we need for now
1987 // We will add more info as our new
1988 // managmenent utility requires it
1989 si
->processorType
= PROC_IA64
;
1993 #if defined __sparc__
1994 static void adpt_sparc_info(sysInfo_S
* si
)
1996 // This is all the info we need for now
1997 // We will add more info as our new
1998 // managmenent utility requires it
1999 si
->processorType
= PROC_ULTRASPARC
;
2002 #if defined __alpha__
2003 static void adpt_alpha_info(sysInfo_S
* si
)
2005 // This is all the info we need for now
2006 // We will add more info as our new
2007 // managmenent utility requires it
2008 si
->processorType
= PROC_ALPHA
;
2012 #if defined __i386__
2013 static void adpt_i386_info(sysInfo_S
* si
)
2015 // This is all the info we need for now
2016 // We will add more info as our new
2017 // managmenent utility requires it
2018 switch (boot_cpu_data
.x86
) {
2020 si
->processorType
= PROC_386
;
2023 si
->processorType
= PROC_486
;
2026 si
->processorType
= PROC_PENTIUM
;
2028 default: // Just in case
2029 si
->processorType
= PROC_PENTIUM
;
2036 * This routine returns information about the system. This does not effect
2037 * any logic and if the info is wrong - it doesn't matter.
2040 /* Get all the info we can not get from kernel services */
2041 static int adpt_system_info(void __user
*buffer
)
2045 memset(&si
, 0, sizeof(si
));
2047 si
.osType
= OS_LINUX
;
2048 si
.osMajorVersion
= 0;
2049 si
.osMinorVersion
= 0;
2051 si
.busType
= SI_PCI_BUS
;
2052 si
.processorFamily
= DPTI_sig
.dsProcessorFamily
;
2054 #if defined __i386__
2055 adpt_i386_info(&si
);
2056 #elif defined (__ia64__)
2057 adpt_ia64_info(&si
);
2058 #elif defined(__sparc__)
2059 adpt_sparc_info(&si
);
2060 #elif defined (__alpha__)
2061 adpt_alpha_info(&si
);
2063 si
.processorType
= 0xff ;
2065 if (copy_to_user(buffer
, &si
, sizeof(si
))){
2066 printk(KERN_WARNING
"dpti: Could not copy buffer TO user\n");
2073 static int adpt_ioctl(struct inode
*inode
, struct file
*file
, uint cmd
, ulong arg
)
2079 void __user
*argp
= (void __user
*)arg
;
2081 minor
= iminor(inode
);
2082 if (minor
>= DPTI_MAX_HBA
){
2085 mutex_lock(&adpt_configuration_lock
);
2086 for (pHba
= hba_chain
; pHba
; pHba
= pHba
->next
) {
2087 if (pHba
->unit
== minor
) {
2088 break; /* found adapter */
2091 mutex_unlock(&adpt_configuration_lock
);
2096 while((volatile u32
) pHba
->state
& DPTI_STATE_RESET
)
2097 schedule_timeout_uninterruptible(2);
2100 // TODO: handle 3 cases
2102 if (copy_to_user(argp
, &DPTI_sig
, sizeof(DPTI_sig
))) {
2107 return adpt_i2o_passthru(pHba
, argp
);
2110 drvrHBAinfo_S HbaInfo
;
2112 #define FLG_OSD_PCI_VALID 0x0001
2113 #define FLG_OSD_DMA 0x0002
2114 #define FLG_OSD_I2O 0x0004
2115 memset(&HbaInfo
, 0, sizeof(HbaInfo
));
2116 HbaInfo
.drvrHBAnum
= pHba
->unit
;
2117 HbaInfo
.baseAddr
= (ulong
) pHba
->base_addr_phys
;
2118 HbaInfo
.blinkState
= adpt_read_blink_led(pHba
);
2119 HbaInfo
.pciBusNum
= pHba
->pDev
->bus
->number
;
2120 HbaInfo
.pciDeviceNum
=PCI_SLOT(pHba
->pDev
->devfn
);
2121 HbaInfo
.Interrupt
= pHba
->pDev
->irq
;
2122 HbaInfo
.hbaFlags
= FLG_OSD_PCI_VALID
| FLG_OSD_DMA
| FLG_OSD_I2O
;
2123 if(copy_to_user(argp
, &HbaInfo
, sizeof(HbaInfo
))){
2124 printk(KERN_WARNING
"%s: Could not copy HbaInfo TO user\n",pHba
->name
);
2130 return adpt_system_info(argp
);
2133 value
= (u32
)adpt_read_blink_led(pHba
);
2134 if (copy_to_user(argp
, &value
, sizeof(value
))) {
2141 spin_lock_irqsave(pHba
->host
->host_lock
, flags
);
2142 adpt_hba_reset(pHba
);
2144 spin_unlock_irqrestore(pHba
->host
->host_lock
, flags
);
2156 static long adpt_unlocked_ioctl(struct file
*file
, uint cmd
, ulong arg
)
2158 struct inode
*inode
;
2161 inode
= file
->f_dentry
->d_inode
;
2164 ret
= adpt_ioctl(inode
, file
, cmd
, arg
);
2170 #ifdef CONFIG_COMPAT
2171 static long compat_adpt_ioctl(struct file
*file
,
2172 unsigned int cmd
, unsigned long arg
)
2174 struct inode
*inode
;
2177 inode
= file
->f_dentry
->d_inode
;
2189 case (DPT_TARGET_BUSY
& 0xFFFF):
2190 case DPT_TARGET_BUSY
:
2191 ret
= adpt_ioctl(inode
, file
, cmd
, arg
);
2203 static irqreturn_t
adpt_isr(int irq
, void *dev_id
)
2205 struct scsi_cmnd
* cmd
;
2206 adpt_hba
* pHba
= dev_id
;
2208 void __iomem
*reply
;
2215 printk(KERN_WARNING
"adpt_isr: NULL dev_id\n");
2219 spin_lock_irqsave(pHba
->host
->host_lock
, flags
);
2221 while( readl(pHba
->irq_mask
) & I2O_INTERRUPT_PENDING_B
) {
2222 m
= readl(pHba
->reply_port
);
2223 if(m
== EMPTY_QUEUE
){
2224 // Try twice then give up
2226 m
= readl(pHba
->reply_port
);
2227 if(m
== EMPTY_QUEUE
){
2228 // This really should not happen
2229 printk(KERN_ERR
"dpti: Could not get reply frame\n");
2233 if (pHba
->reply_pool_pa
<= m
&&
2234 m
< pHba
->reply_pool_pa
+
2235 (pHba
->reply_fifo_size
* REPLY_FRAME_SIZE
* 4)) {
2236 reply
= (u8
*)pHba
->reply_pool
+
2237 (m
- pHba
->reply_pool_pa
);
2239 /* Ick, we should *never* be here */
2240 printk(KERN_ERR
"dpti: reply frame not from pool\n");
2241 reply
= (u8
*)bus_to_virt(m
);
2244 if (readl(reply
) & MSG_FAIL
) {
2245 u32 old_m
= readl(reply
+28);
2248 PDEBUG("%s: Failed message\n",pHba
->name
);
2249 if(old_m
>= 0x100000){
2250 printk(KERN_ERR
"%s: Bad preserved MFA (%x)- dropping frame\n",pHba
->name
,old_m
);
2251 writel(m
,pHba
->reply_port
);
2254 // Transaction context is 0 in failed reply frame
2255 msg
= pHba
->msg_addr_virt
+ old_m
;
2256 old_context
= readl(msg
+12);
2257 writel(old_context
, reply
+12);
2258 adpt_send_nop(pHba
, old_m
);
2260 context
= readl(reply
+8);
2261 if(context
& 0x40000000){ // IOCTL
2262 void *p
= adpt_ioctl_from_context(pHba
, readl(reply
+12));
2264 memcpy_fromio(p
, reply
, REPLY_FRAME_SIZE
* 4);
2266 // All IOCTLs will also be post wait
2268 if(context
& 0x80000000){ // Post wait message
2269 status
= readl(reply
+16);
2271 status
&= 0xffff; /* Get detail status */
2273 status
= I2O_POST_WAIT_OK
;
2275 if(!(context
& 0x40000000)) {
2276 cmd
= adpt_cmd_from_context(pHba
,
2279 printk(KERN_WARNING
"%s: Apparent SCSI cmd in Post Wait Context - cmd=%p context=%x\n", pHba
->name
, cmd
, context
);
2282 adpt_i2o_post_wait_complete(context
, status
);
2283 } else { // SCSI message
2284 cmd
= adpt_cmd_from_context (pHba
, readl(reply
+12));
2286 scsi_dma_unmap(cmd
);
2287 if(cmd
->serial_number
!= 0) { // If not timedout
2288 adpt_i2o_to_scsi(reply
, cmd
);
2292 writel(m
, pHba
->reply_port
);
2298 spin_unlock_irqrestore(pHba
->host
->host_lock
, flags
);
2299 return IRQ_RETVAL(handled
);
2302 static s32
adpt_scsi_to_i2o(adpt_hba
* pHba
, struct scsi_cmnd
* cmd
, struct adpt_device
* d
)
2305 u32 msg
[MAX_MESSAGE_SIZE
];
2317 memset(msg
, 0 , sizeof(msg
));
2318 len
= scsi_bufflen(cmd
);
2319 direction
= 0x00000000;
2321 scsidir
= 0x00000000; // DATA NO XFER
2324 * Set SCBFlags to indicate if data is being transferred
2325 * in or out, or no data transfer
2326 * Note: Do not have to verify index is less than 0 since
2327 * cmd->cmnd[0] is an unsigned char
2329 switch(cmd
->sc_data_direction
){
2330 case DMA_FROM_DEVICE
:
2331 scsidir
=0x40000000; // DATA IN (iop<--dev)
2334 direction
=0x04000000; // SGL OUT
2335 scsidir
=0x80000000; // DATA OUT (iop-->dev)
2339 case DMA_BIDIRECTIONAL
:
2340 scsidir
=0x40000000; // DATA IN (iop<--dev)
2341 // Assume In - and continue;
2344 printk(KERN_WARNING
"%s: scsi opcode 0x%x not supported.\n",
2345 pHba
->name
, cmd
->cmnd
[0]);
2346 cmd
->result
= (DID_OK
<<16) | (INITIATOR_ERROR
<< 8);
2347 cmd
->scsi_done(cmd
);
2351 // msg[0] is set later
2352 // I2O_CMD_SCSI_EXEC
2353 msg
[1] = ((0xff<<24)|(HOST_TID
<<12)|d
->tid
);
2355 msg
[3] = adpt_cmd_to_context(cmd
); /* Want SCSI control block back */
2356 // Our cards use the transaction context as the tag for queueing
2357 // Adaptec/DPT Private stuff
2358 msg
[4] = I2O_CMD_SCSI_EXEC
|(DPT_ORGANIZATION_ID
<<16);
2360 /* Direction, disconnect ok | sense data | simple queue , CDBLen */
2361 // I2O_SCB_FLAG_ENABLE_DISCONNECT |
2362 // I2O_SCB_FLAG_SIMPLE_QUEUE_TAG |
2363 // I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
2364 msg
[6] = scsidir
|0x20a00000|cmd
->cmd_len
;
2368 // Write SCSI command into the message - always 16 byte block
2369 memset(mptr
, 0, 16);
2370 memcpy(mptr
, cmd
->cmnd
, cmd
->cmd_len
);
2372 lenptr
=mptr
++; /* Remember me - fill in when we know */
2373 if (dpt_dma64(pHba
)) {
2374 reqlen
= 16; // SINGLE SGE
2375 *mptr
++ = (0x7C<<24)+(2<<16)+0x02; /* Enable 64 bit */
2376 *mptr
++ = 1 << PAGE_SHIFT
;
2378 reqlen
= 14; // SINGLE SGE
2380 /* Now fill in the SGList and command */
2382 nseg
= scsi_dma_map(cmd
);
2385 struct scatterlist
*sg
;
2388 scsi_for_each_sg(cmd
, sg
, nseg
, i
) {
2390 *mptr
++ = direction
|0x10000000|sg_dma_len(sg
);
2391 len
+=sg_dma_len(sg
);
2392 addr
= sg_dma_address(sg
);
2393 *mptr
++ = dma_low(addr
);
2394 if (dpt_dma64(pHba
))
2395 *mptr
++ = dma_high(addr
);
2396 /* Make this an end of list */
2398 *lptr
= direction
|0xD0000000|sg_dma_len(sg
);
2400 reqlen
= mptr
- msg
;
2403 if(cmd
->underflow
&& len
!= cmd
->underflow
){
2404 printk(KERN_WARNING
"Cmd len %08X Cmd underflow %08X\n",
2405 len
, cmd
->underflow
);
2412 /* Stick the headers on */
2413 msg
[0] = reqlen
<<16 | ((reqlen
> 12) ? SGL_OFFSET_12
: SGL_OFFSET_0
);
2415 // Send it on it's way
2416 rcode
= adpt_i2o_post_this(pHba
, msg
, reqlen
<<2);
2424 static s32
adpt_scsi_host_alloc(adpt_hba
* pHba
, struct scsi_host_template
*sht
)
2426 struct Scsi_Host
*host
;
2428 host
= scsi_host_alloc(sht
, sizeof(adpt_hba
*));
2430 printk("%s: scsi_host_alloc returned NULL\n", pHba
->name
);
2433 host
->hostdata
[0] = (unsigned long)pHba
;
2436 host
->irq
= pHba
->pDev
->irq
;
2437 /* no IO ports, so don't have to set host->io_port and
2441 host
->n_io_port
= 0;
2442 /* see comments in scsi_host.h */
2444 host
->max_lun
= 256;
2445 host
->max_channel
= pHba
->top_scsi_channel
+ 1;
2446 host
->cmd_per_lun
= 1;
2447 host
->unique_id
= (u32
)sys_tbl_pa
+ pHba
->unit
;
2448 host
->sg_tablesize
= pHba
->sg_tablesize
;
2449 host
->can_queue
= pHba
->post_fifo_size
;
2455 static s32
adpt_i2o_to_scsi(void __iomem
*reply
, struct scsi_cmnd
* cmd
)
2460 u32 reply_flags
= readl(reply
) & 0xff00; // Leave it shifted up 8 bits
2461 // I know this would look cleaner if I just read bytes
2462 // but the model I have been using for all the rest of the
2463 // io is in 4 byte words - so I keep that model
2464 u16 detailed_status
= readl(reply
+16) &0xffff;
2465 dev_status
= (detailed_status
& 0xff);
2466 hba_status
= detailed_status
>> 8;
2468 // calculate resid for sg
2469 scsi_set_resid(cmd
, scsi_bufflen(cmd
) - readl(reply
+20));
2471 pHba
= (adpt_hba
*) cmd
->device
->host
->hostdata
[0];
2473 cmd
->sense_buffer
[0] = '\0'; // initialize sense valid flag to false
2475 if(!(reply_flags
& MSG_FAIL
)) {
2476 switch(detailed_status
& I2O_SCSI_DSC_MASK
) {
2477 case I2O_SCSI_DSC_SUCCESS
:
2478 cmd
->result
= (DID_OK
<< 16);
2480 if (readl(reply
+20) < cmd
->underflow
) {
2481 cmd
->result
= (DID_ERROR
<<16);
2482 printk(KERN_WARNING
"%s: SCSI CMD underflow\n",pHba
->name
);
2485 case I2O_SCSI_DSC_REQUEST_ABORTED
:
2486 cmd
->result
= (DID_ABORT
<< 16);
2488 case I2O_SCSI_DSC_PATH_INVALID
:
2489 case I2O_SCSI_DSC_DEVICE_NOT_PRESENT
:
2490 case I2O_SCSI_DSC_SELECTION_TIMEOUT
:
2491 case I2O_SCSI_DSC_COMMAND_TIMEOUT
:
2492 case I2O_SCSI_DSC_NO_ADAPTER
:
2493 case I2O_SCSI_DSC_RESOURCE_UNAVAILABLE
:
2494 printk(KERN_WARNING
"%s: SCSI Timeout-Device (%d,%d,%d) hba status=0x%x, dev status=0x%x, cmd=0x%x\n",
2495 pHba
->name
, (u32
)cmd
->device
->channel
, (u32
)cmd
->device
->id
, (u32
)cmd
->device
->lun
, hba_status
, dev_status
, cmd
->cmnd
[0]);
2496 cmd
->result
= (DID_TIME_OUT
<< 16);
2498 case I2O_SCSI_DSC_ADAPTER_BUSY
:
2499 case I2O_SCSI_DSC_BUS_BUSY
:
2500 cmd
->result
= (DID_BUS_BUSY
<< 16);
2502 case I2O_SCSI_DSC_SCSI_BUS_RESET
:
2503 case I2O_SCSI_DSC_BDR_MESSAGE_SENT
:
2504 cmd
->result
= (DID_RESET
<< 16);
2506 case I2O_SCSI_DSC_PARITY_ERROR_FAILURE
:
2507 printk(KERN_WARNING
"%s: SCSI CMD parity error\n",pHba
->name
);
2508 cmd
->result
= (DID_PARITY
<< 16);
2510 case I2O_SCSI_DSC_UNABLE_TO_ABORT
:
2511 case I2O_SCSI_DSC_COMPLETE_WITH_ERROR
:
2512 case I2O_SCSI_DSC_UNABLE_TO_TERMINATE
:
2513 case I2O_SCSI_DSC_MR_MESSAGE_RECEIVED
:
2514 case I2O_SCSI_DSC_AUTOSENSE_FAILED
:
2515 case I2O_SCSI_DSC_DATA_OVERRUN
:
2516 case I2O_SCSI_DSC_UNEXPECTED_BUS_FREE
:
2517 case I2O_SCSI_DSC_SEQUENCE_FAILURE
:
2518 case I2O_SCSI_DSC_REQUEST_LENGTH_ERROR
:
2519 case I2O_SCSI_DSC_PROVIDE_FAILURE
:
2520 case I2O_SCSI_DSC_REQUEST_TERMINATED
:
2521 case I2O_SCSI_DSC_IDE_MESSAGE_SENT
:
2522 case I2O_SCSI_DSC_UNACKNOWLEDGED_EVENT
:
2523 case I2O_SCSI_DSC_MESSAGE_RECEIVED
:
2524 case I2O_SCSI_DSC_INVALID_CDB
:
2525 case I2O_SCSI_DSC_LUN_INVALID
:
2526 case I2O_SCSI_DSC_SCSI_TID_INVALID
:
2527 case I2O_SCSI_DSC_FUNCTION_UNAVAILABLE
:
2528 case I2O_SCSI_DSC_NO_NEXUS
:
2529 case I2O_SCSI_DSC_CDB_RECEIVED
:
2530 case I2O_SCSI_DSC_LUN_ALREADY_ENABLED
:
2531 case I2O_SCSI_DSC_QUEUE_FROZEN
:
2532 case I2O_SCSI_DSC_REQUEST_INVALID
:
2534 printk(KERN_WARNING
"%s: SCSI error %0x-Device(%d,%d,%d) hba_status=0x%x, dev_status=0x%x, cmd=0x%x\n",
2535 pHba
->name
, detailed_status
& I2O_SCSI_DSC_MASK
, (u32
)cmd
->device
->channel
, (u32
)cmd
->device
->id
, (u32
)cmd
->device
->lun
,
2536 hba_status
, dev_status
, cmd
->cmnd
[0]);
2537 cmd
->result
= (DID_ERROR
<< 16);
2541 // copy over the request sense data if it was a check
2543 if (dev_status
== SAM_STAT_CHECK_CONDITION
) {
2544 u32 len
= min(SCSI_SENSE_BUFFERSIZE
, 40);
2545 // Copy over the sense data
2546 memcpy_fromio(cmd
->sense_buffer
, (reply
+28) , len
);
2547 if(cmd
->sense_buffer
[0] == 0x70 /* class 7 */ &&
2548 cmd
->sense_buffer
[2] == DATA_PROTECT
){
2549 /* This is to handle an array failed */
2550 cmd
->result
= (DID_TIME_OUT
<< 16);
2551 printk(KERN_WARNING
"%s: SCSI Data Protect-Device (%d,%d,%d) hba_status=0x%x, dev_status=0x%x, cmd=0x%x\n",
2552 pHba
->name
, (u32
)cmd
->device
->channel
, (u32
)cmd
->device
->id
, (u32
)cmd
->device
->lun
,
2553 hba_status
, dev_status
, cmd
->cmnd
[0]);
2558 /* In this condtion we could not talk to the tid
2559 * the card rejected it. We should signal a retry
2560 * for a limitted number of retries.
2562 cmd
->result
= (DID_TIME_OUT
<< 16);
2563 printk(KERN_WARNING
"%s: I2O MSG_FAIL - Device (%d,%d,%d) tid=%d, cmd=0x%x\n",
2564 pHba
->name
, (u32
)cmd
->device
->channel
, (u32
)cmd
->device
->id
, (u32
)cmd
->device
->lun
,
2565 ((struct adpt_device
*)(cmd
->device
->hostdata
))->tid
, cmd
->cmnd
[0]);
2568 cmd
->result
|= (dev_status
);
2570 if(cmd
->scsi_done
!= NULL
){
2571 cmd
->scsi_done(cmd
);
2577 static s32
adpt_rescan(adpt_hba
* pHba
)
2583 spin_lock_irqsave(pHba
->host
->host_lock
, flags
);
2584 if ((rcode
=adpt_i2o_lct_get(pHba
)) < 0)
2586 if ((rcode
=adpt_i2o_reparse_lct(pHba
)) < 0)
2590 spin_unlock_irqrestore(pHba
->host
->host_lock
, flags
);
2595 static s32
adpt_i2o_reparse_lct(adpt_hba
* pHba
)
2600 struct i2o_device
*d
;
2601 i2o_lct
*lct
= pHba
->lct
;
2605 u32 buf
[10]; // at least 8 u32's
2606 struct adpt_device
* pDev
= NULL
;
2607 struct i2o_device
* pI2o_dev
= NULL
;
2610 printk(KERN_ERR
"%s: LCT is empty???\n",pHba
->name
);
2614 max
= lct
->table_size
;
2618 // Mark each drive as unscanned
2619 for (d
= pHba
->devices
; d
; d
= d
->next
) {
2620 pDev
=(struct adpt_device
*) d
->owner
;
2624 pDev
->state
|= DPTI_DEV_UNSCANNED
;
2627 printk(KERN_INFO
"%s: LCT has %d entries.\n", pHba
->name
,max
);
2629 for(i
=0;i
<max
;i
++) {
2630 if( lct
->lct_entry
[i
].user_tid
!= 0xfff){
2634 if( lct
->lct_entry
[i
].class_id
== I2O_CLASS_RANDOM_BLOCK_STORAGE
||
2635 lct
->lct_entry
[i
].class_id
== I2O_CLASS_SCSI_PERIPHERAL
||
2636 lct
->lct_entry
[i
].class_id
== I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL
){
2637 tid
= lct
->lct_entry
[i
].tid
;
2638 if(adpt_i2o_query_scalar(pHba
, tid
, 0x8000, -1, buf
, 32)<0) {
2639 printk(KERN_ERR
"%s: Could not query device\n",pHba
->name
);
2642 bus_no
= buf
[0]>>16;
2643 if (bus_no
>= MAX_CHANNEL
) { /* Something wrong skip it */
2645 "%s: Channel number %d out of range\n",
2646 pHba
->name
, bus_no
);
2651 scsi_lun
= (buf
[2]>>8 )&0xff;
2652 pDev
= pHba
->channel
[bus_no
].device
[scsi_id
];
2655 if(pDev
->scsi_lun
== scsi_lun
) {
2658 pDev
= pDev
->next_lun
;
2660 if(!pDev
) { // Something new add it
2661 d
= kmalloc(sizeof(struct i2o_device
),
2665 printk(KERN_CRIT
"Out of memory for I2O device data.\n");
2669 d
->controller
= pHba
;
2672 memcpy(&d
->lct_data
, &lct
->lct_entry
[i
], sizeof(i2o_lct_entry
));
2675 adpt_i2o_report_hba_unit(pHba
, d
);
2676 adpt_i2o_install_device(pHba
, d
);
2678 pDev
= pHba
->channel
[bus_no
].device
[scsi_id
];
2681 kzalloc(sizeof(struct adpt_device
),
2686 pHba
->channel
[bus_no
].device
[scsi_id
] = pDev
;
2688 while (pDev
->next_lun
) {
2689 pDev
= pDev
->next_lun
;
2691 pDev
= pDev
->next_lun
=
2692 kzalloc(sizeof(struct adpt_device
),
2698 pDev
->tid
= d
->lct_data
.tid
;
2699 pDev
->scsi_channel
= bus_no
;
2700 pDev
->scsi_id
= scsi_id
;
2701 pDev
->scsi_lun
= scsi_lun
;
2704 pDev
->type
= (buf
[0])&0xff;
2705 pDev
->flags
= (buf
[0]>>8)&0xff;
2706 // Too late, SCSI system has made up it's mind, but what the hey ...
2707 if(scsi_id
> pHba
->top_scsi_id
){
2708 pHba
->top_scsi_id
= scsi_id
;
2710 if(scsi_lun
> pHba
->top_scsi_lun
){
2711 pHba
->top_scsi_lun
= scsi_lun
;
2714 } // end of new i2o device
2716 // We found an old device - check it
2718 if(pDev
->scsi_lun
== scsi_lun
) {
2719 if(!scsi_device_online(pDev
->pScsi_dev
)) {
2720 printk(KERN_WARNING
"%s: Setting device (%d,%d,%d) back online\n",
2721 pHba
->name
,bus_no
,scsi_id
,scsi_lun
);
2722 if (pDev
->pScsi_dev
) {
2723 scsi_device_set_state(pDev
->pScsi_dev
, SDEV_RUNNING
);
2727 if(d
->lct_data
.tid
!= tid
) { // something changed
2729 memcpy(&d
->lct_data
, &lct
->lct_entry
[i
], sizeof(i2o_lct_entry
));
2730 if (pDev
->pScsi_dev
) {
2731 pDev
->pScsi_dev
->changed
= TRUE
;
2732 pDev
->pScsi_dev
->removable
= TRUE
;
2735 // Found it - mark it scanned
2736 pDev
->state
= DPTI_DEV_ONLINE
;
2739 pDev
= pDev
->next_lun
;
2743 for (pI2o_dev
= pHba
->devices
; pI2o_dev
; pI2o_dev
= pI2o_dev
->next
) {
2744 pDev
=(struct adpt_device
*) pI2o_dev
->owner
;
2748 // Drive offline drives that previously existed but could not be found
2750 if (pDev
->state
& DPTI_DEV_UNSCANNED
){
2751 pDev
->state
= DPTI_DEV_OFFLINE
;
2752 printk(KERN_WARNING
"%s: Device (%d,%d,%d) offline\n",pHba
->name
,pDev
->scsi_channel
,pDev
->scsi_id
,pDev
->scsi_lun
);
2753 if (pDev
->pScsi_dev
) {
2754 scsi_device_set_state(pDev
->pScsi_dev
, SDEV_OFFLINE
);
2761 static void adpt_fail_posted_scbs(adpt_hba
* pHba
)
2763 struct scsi_cmnd
* cmd
= NULL
;
2764 struct scsi_device
* d
= NULL
;
2766 shost_for_each_device(d
, pHba
->host
) {
2767 unsigned long flags
;
2768 spin_lock_irqsave(&d
->list_lock
, flags
);
2769 list_for_each_entry(cmd
, &d
->cmd_list
, list
) {
2770 if(cmd
->serial_number
== 0){
2773 cmd
->result
= (DID_OK
<< 16) | (QUEUE_FULL
<<1);
2774 cmd
->scsi_done(cmd
);
2776 spin_unlock_irqrestore(&d
->list_lock
, flags
);
2781 /*============================================================================
2782 * Routines from i2o subsystem
2783 *============================================================================
2789 * Bring an I2O controller into HOLD state. See the spec.
2791 static int adpt_i2o_activate_hba(adpt_hba
* pHba
)
2795 if(pHba
->initialized
) {
2796 if (adpt_i2o_status_get(pHba
) < 0) {
2797 if((rcode
= adpt_i2o_reset_hba(pHba
)) != 0){
2798 printk(KERN_WARNING
"%s: Could NOT reset.\n", pHba
->name
);
2801 if (adpt_i2o_status_get(pHba
) < 0) {
2802 printk(KERN_INFO
"HBA not responding.\n");
2807 if(pHba
->status_block
->iop_state
== ADAPTER_STATE_FAULTED
) {
2808 printk(KERN_CRIT
"%s: hardware fault\n", pHba
->name
);
2812 if (pHba
->status_block
->iop_state
== ADAPTER_STATE_READY
||
2813 pHba
->status_block
->iop_state
== ADAPTER_STATE_OPERATIONAL
||
2814 pHba
->status_block
->iop_state
== ADAPTER_STATE_HOLD
||
2815 pHba
->status_block
->iop_state
== ADAPTER_STATE_FAILED
) {
2816 adpt_i2o_reset_hba(pHba
);
2817 if (adpt_i2o_status_get(pHba
) < 0 || pHba
->status_block
->iop_state
!= ADAPTER_STATE_RESET
) {
2818 printk(KERN_ERR
"%s: Failed to initialize.\n", pHba
->name
);
2823 if((rcode
= adpt_i2o_reset_hba(pHba
)) != 0){
2824 printk(KERN_WARNING
"%s: Could NOT reset.\n", pHba
->name
);
2830 if (adpt_i2o_init_outbound_q(pHba
) < 0) {
2836 if (adpt_i2o_hrt_get(pHba
) < 0) {
2844 * Bring a controller online into OPERATIONAL state.
2847 static int adpt_i2o_online_hba(adpt_hba
* pHba
)
2849 if (adpt_i2o_systab_send(pHba
) < 0) {
2850 adpt_i2o_delete_hba(pHba
);
2853 /* In READY state */
2855 if (adpt_i2o_enable_hba(pHba
) < 0) {
2856 adpt_i2o_delete_hba(pHba
);
2860 /* In OPERATIONAL state */
2864 static s32
adpt_send_nop(adpt_hba
*pHba
,u32 m
)
2867 ulong timeout
= jiffies
+ 5*HZ
;
2869 while(m
== EMPTY_QUEUE
){
2871 m
= readl(pHba
->post_port
);
2872 if(m
!= EMPTY_QUEUE
){
2875 if(time_after(jiffies
,timeout
)){
2876 printk(KERN_ERR
"%s: Timeout waiting for message frame!\n",pHba
->name
);
2879 schedule_timeout_uninterruptible(1);
2881 msg
= (u32 __iomem
*)(pHba
->msg_addr_virt
+ m
);
2882 writel( THREE_WORD_MSG_SIZE
| SGL_OFFSET_0
,&msg
[0]);
2883 writel( I2O_CMD_UTIL_NOP
<< 24 | HOST_TID
<< 12 | 0,&msg
[1]);
2887 writel(m
, pHba
->post_port
);
2892 static s32
adpt_i2o_init_outbound_q(adpt_hba
* pHba
)
2896 u32 __iomem
*msg
= NULL
;
2898 ulong timeout
= jiffies
+ TMOUT_INITOUTBOUND
*HZ
;
2903 m
= readl(pHba
->post_port
);
2904 if (m
!= EMPTY_QUEUE
) {
2908 if(time_after(jiffies
,timeout
)){
2909 printk(KERN_WARNING
"%s: Timeout waiting for message frame\n",pHba
->name
);
2912 schedule_timeout_uninterruptible(1);
2913 } while(m
== EMPTY_QUEUE
);
2915 msg
=(u32 __iomem
*)(pHba
->msg_addr_virt
+m
);
2917 status
= dma_alloc_coherent(&pHba
->pDev
->dev
, 4, &addr
, GFP_KERNEL
);
2919 adpt_send_nop(pHba
, m
);
2920 printk(KERN_WARNING
"%s: IOP reset failed - no free memory.\n",
2924 memset(status
, 0, 4);
2926 writel(EIGHT_WORD_MSG_SIZE
| SGL_OFFSET_6
, &msg
[0]);
2927 writel(I2O_CMD_OUTBOUND_INIT
<<24 | HOST_TID
<<12 | ADAPTER_TID
, &msg
[1]);
2929 writel(0x0106, &msg
[3]); /* Transaction context */
2930 writel(4096, &msg
[4]); /* Host page frame size */
2931 writel((REPLY_FRAME_SIZE
)<<16|0x80, &msg
[5]); /* Outbound msg frame size and Initcode */
2932 writel(0xD0000004, &msg
[6]); /* Simple SG LE, EOB */
2933 writel((u32
)addr
, &msg
[7]);
2935 writel(m
, pHba
->post_port
);
2938 // Wait for the reply status to come back
2941 if (*status
!= 0x01 /*I2O_EXEC_OUTBOUND_INIT_IN_PROGRESS*/) {
2946 if(time_after(jiffies
,timeout
)){
2947 printk(KERN_WARNING
"%s: Timeout Initializing\n",pHba
->name
);
2948 /* We lose 4 bytes of "status" here, but we
2949 cannot free these because controller may
2950 awake and corrupt those bytes at any time */
2951 /* dma_free_coherent(&pHba->pDev->dev, 4, status, addr); */
2954 schedule_timeout_uninterruptible(1);
2957 // If the command was successful, fill the fifo with our reply
2959 if(*status
!= 0x04 /*I2O_EXEC_OUTBOUND_INIT_COMPLETE*/) {
2960 dma_free_coherent(&pHba
->pDev
->dev
, 4, status
, addr
);
2963 dma_free_coherent(&pHba
->pDev
->dev
, 4, status
, addr
);
2965 if(pHba
->reply_pool
!= NULL
) {
2966 dma_free_coherent(&pHba
->pDev
->dev
,
2967 pHba
->reply_fifo_size
* REPLY_FRAME_SIZE
* 4,
2968 pHba
->reply_pool
, pHba
->reply_pool_pa
);
2971 pHba
->reply_pool
= dma_alloc_coherent(&pHba
->pDev
->dev
,
2972 pHba
->reply_fifo_size
* REPLY_FRAME_SIZE
* 4,
2973 &pHba
->reply_pool_pa
, GFP_KERNEL
);
2974 if (!pHba
->reply_pool
) {
2975 printk(KERN_ERR
"%s: Could not allocate reply pool\n", pHba
->name
);
2978 memset(pHba
->reply_pool
, 0 , pHba
->reply_fifo_size
* REPLY_FRAME_SIZE
* 4);
2980 for(i
= 0; i
< pHba
->reply_fifo_size
; i
++) {
2981 writel(pHba
->reply_pool_pa
+ (i
* REPLY_FRAME_SIZE
* 4),
2985 adpt_i2o_status_get(pHba
);
2991 * I2O System Table. Contains information about
2992 * all the IOPs in the system. Used to inform IOPs
2993 * about each other's existence.
2995 * sys_tbl_ver is the CurrentChangeIndicator that is
2996 * used by IOPs to track changes.
3001 static s32
adpt_i2o_status_get(adpt_hba
* pHba
)
3006 u8
*status_block
=NULL
;
3008 if(pHba
->status_block
== NULL
) {
3009 pHba
->status_block
= dma_alloc_coherent(&pHba
->pDev
->dev
,
3010 sizeof(i2o_status_block
),
3011 &pHba
->status_block_pa
, GFP_KERNEL
);
3012 if(pHba
->status_block
== NULL
) {
3014 "dpti%d: Get Status Block failed; Out of memory. \n",
3019 memset(pHba
->status_block
, 0, sizeof(i2o_status_block
));
3020 status_block
= (u8
*)(pHba
->status_block
);
3021 timeout
= jiffies
+TMOUT_GETSTATUS
*HZ
;
3024 m
= readl(pHba
->post_port
);
3025 if (m
!= EMPTY_QUEUE
) {
3028 if(time_after(jiffies
,timeout
)){
3029 printk(KERN_ERR
"%s: Timeout waiting for message !\n",
3033 schedule_timeout_uninterruptible(1);
3034 } while(m
==EMPTY_QUEUE
);
3037 msg
=(u32 __iomem
*)(pHba
->msg_addr_virt
+m
);
3039 writel(NINE_WORD_MSG_SIZE
|SGL_OFFSET_0
, &msg
[0]);
3040 writel(I2O_CMD_STATUS_GET
<<24|HOST_TID
<<12|ADAPTER_TID
, &msg
[1]);
3045 writel( dma_low(pHba
->status_block_pa
), &msg
[6]);
3046 writel( dma_high(pHba
->status_block_pa
), &msg
[7]);
3047 writel(sizeof(i2o_status_block
), &msg
[8]); // 88 bytes
3050 writel(m
, pHba
->post_port
);
3053 while(status_block
[87]!=0xff){
3054 if(time_after(jiffies
,timeout
)){
3055 printk(KERN_ERR
"dpti%d: Get status timeout.\n",
3060 schedule_timeout_uninterruptible(1);
3063 // Set up our number of outbound and inbound messages
3064 pHba
->post_fifo_size
= pHba
->status_block
->max_inbound_frames
;
3065 if (pHba
->post_fifo_size
> MAX_TO_IOP_MESSAGES
) {
3066 pHba
->post_fifo_size
= MAX_TO_IOP_MESSAGES
;
3069 pHba
->reply_fifo_size
= pHba
->status_block
->max_outbound_frames
;
3070 if (pHba
->reply_fifo_size
> MAX_FROM_IOP_MESSAGES
) {
3071 pHba
->reply_fifo_size
= MAX_FROM_IOP_MESSAGES
;
3074 // Calculate the Scatter Gather list size
3075 if (dpt_dma64(pHba
)) {
3077 = ((pHba
->status_block
->inbound_frame_size
* 4
3079 / (sizeof(struct sg_simple_element
) + sizeof(u32
)));
3082 = ((pHba
->status_block
->inbound_frame_size
* 4
3084 / sizeof(struct sg_simple_element
));
3086 if (pHba
->sg_tablesize
> SG_LIST_ELEMENTS
) {
3087 pHba
->sg_tablesize
= SG_LIST_ELEMENTS
;
3092 printk("dpti%d: State = ",pHba
->unit
);
3093 switch(pHba
->status_block
->iop_state
) {
3107 printk("OPERATIONAL\n");
3113 printk("FAULTED\n");
3116 printk("%x (unknown!!)\n",pHba
->status_block
->iop_state
);
3123 * Get the IOP's Logical Configuration Table
3125 static int adpt_i2o_lct_get(adpt_hba
* pHba
)
3131 if ((pHba
->lct_size
== 0) || (pHba
->lct
== NULL
)){
3132 pHba
->lct_size
= pHba
->status_block
->expected_lct_size
;
3135 if (pHba
->lct
== NULL
) {
3136 pHba
->lct
= dma_alloc_coherent(&pHba
->pDev
->dev
,
3137 pHba
->lct_size
, &pHba
->lct_pa
,
3139 if(pHba
->lct
== NULL
) {
3140 printk(KERN_CRIT
"%s: Lct Get failed. Out of memory.\n",
3145 memset(pHba
->lct
, 0, pHba
->lct_size
);
3147 msg
[0] = EIGHT_WORD_MSG_SIZE
|SGL_OFFSET_6
;
3148 msg
[1] = I2O_CMD_LCT_NOTIFY
<<24 | HOST_TID
<<12 | ADAPTER_TID
;
3151 msg
[4] = 0xFFFFFFFF; /* All devices */
3152 msg
[5] = 0x00000000; /* Report now */
3153 msg
[6] = 0xD0000000|pHba
->lct_size
;
3154 msg
[7] = (u32
)pHba
->lct_pa
;
3156 if ((ret
=adpt_i2o_post_wait(pHba
, msg
, sizeof(msg
), 360))) {
3157 printk(KERN_ERR
"%s: LCT Get failed (status=%#10x.\n",
3159 printk(KERN_ERR
"Adaptec: Error Reading Hardware.\n");
3163 if ((pHba
->lct
->table_size
<< 2) > pHba
->lct_size
) {
3164 pHba
->lct_size
= pHba
->lct
->table_size
<< 2;
3165 dma_free_coherent(&pHba
->pDev
->dev
, pHba
->lct_size
,
3166 pHba
->lct
, pHba
->lct_pa
);
3169 } while (pHba
->lct
== NULL
);
3171 PDEBUG("%s: Hardware resource table read.\n", pHba
->name
);
3174 // I2O_DPT_EXEC_IOP_BUFFERS_GROUP_NO;
3175 if(adpt_i2o_query_scalar(pHba
, 0 , 0x8000, -1, buf
, sizeof(buf
))>=0) {
3176 pHba
->FwDebugBufferSize
= buf
[1];
3177 pHba
->FwDebugBuffer_P
= ioremap(pHba
->base_addr_phys
+ buf
[0],
3178 pHba
->FwDebugBufferSize
);
3179 if (pHba
->FwDebugBuffer_P
) {
3180 pHba
->FwDebugFlags_P
= pHba
->FwDebugBuffer_P
+
3181 FW_DEBUG_FLAGS_OFFSET
;
3182 pHba
->FwDebugBLEDvalue_P
= pHba
->FwDebugBuffer_P
+
3183 FW_DEBUG_BLED_OFFSET
;
3184 pHba
->FwDebugBLEDflag_P
= pHba
->FwDebugBLEDvalue_P
+ 1;
3185 pHba
->FwDebugStrLength_P
= pHba
->FwDebugBuffer_P
+
3186 FW_DEBUG_STR_LENGTH_OFFSET
;
3187 pHba
->FwDebugBuffer_P
+= buf
[2];
3188 pHba
->FwDebugFlags
= 0;
3195 static int adpt_i2o_build_sys_table(void)
3197 adpt_hba
* pHba
= hba_chain
;
3201 dma_free_coherent(&pHba
->pDev
->dev
, sys_tbl_len
,
3202 sys_tbl
, sys_tbl_pa
);
3204 sys_tbl_len
= sizeof(struct i2o_sys_tbl
) + // Header + IOPs
3205 (hba_count
) * sizeof(struct i2o_sys_tbl_entry
);
3207 sys_tbl
= dma_alloc_coherent(&pHba
->pDev
->dev
,
3208 sys_tbl_len
, &sys_tbl_pa
, GFP_KERNEL
);
3210 printk(KERN_WARNING
"SysTab Set failed. Out of memory.\n");
3213 memset(sys_tbl
, 0, sys_tbl_len
);
3215 sys_tbl
->num_entries
= hba_count
;
3216 sys_tbl
->version
= I2OVERSION
;
3217 sys_tbl
->change_ind
= sys_tbl_ind
++;
3219 for(pHba
= hba_chain
; pHba
; pHba
= pHba
->next
) {
3221 // Get updated Status Block so we have the latest information
3222 if (adpt_i2o_status_get(pHba
)) {
3223 sys_tbl
->num_entries
--;
3224 continue; // try next one
3227 sys_tbl
->iops
[count
].org_id
= pHba
->status_block
->org_id
;
3228 sys_tbl
->iops
[count
].iop_id
= pHba
->unit
+ 2;
3229 sys_tbl
->iops
[count
].seg_num
= 0;
3230 sys_tbl
->iops
[count
].i2o_version
= pHba
->status_block
->i2o_version
;
3231 sys_tbl
->iops
[count
].iop_state
= pHba
->status_block
->iop_state
;
3232 sys_tbl
->iops
[count
].msg_type
= pHba
->status_block
->msg_type
;
3233 sys_tbl
->iops
[count
].frame_size
= pHba
->status_block
->inbound_frame_size
;
3234 sys_tbl
->iops
[count
].last_changed
= sys_tbl_ind
- 1; // ??
3235 sys_tbl
->iops
[count
].iop_capabilities
= pHba
->status_block
->iop_capabilities
;
3236 addr
= pHba
->base_addr_phys
+ 0x40;
3237 sys_tbl
->iops
[count
].inbound_low
= dma_low(addr
);
3238 sys_tbl
->iops
[count
].inbound_high
= dma_high(addr
);
3245 u32
*table
= (u32
*)sys_tbl
;
3246 printk(KERN_DEBUG
"sys_tbl_len=%d in 32bit words\n",(sys_tbl_len
>>2));
3247 for(count
= 0; count
< (sys_tbl_len
>>2); count
++) {
3248 printk(KERN_INFO
"sys_tbl[%d] = %0#10x\n",
3249 count
, table
[count
]);
3259 * Dump the information block associated with a given unit (TID)
3262 static void adpt_i2o_report_hba_unit(adpt_hba
* pHba
, struct i2o_device
*d
)
3265 int unit
= d
->lct_data
.tid
;
3267 printk(KERN_INFO
"TID %3.3d ", unit
);
3269 if(adpt_i2o_query_scalar(pHba
, unit
, 0xF100, 3, buf
, 16)>=0)
3272 printk(" Vendor: %-12.12s", buf
);
3274 if(adpt_i2o_query_scalar(pHba
, unit
, 0xF100, 4, buf
, 16)>=0)
3277 printk(" Device: %-12.12s", buf
);
3279 if(adpt_i2o_query_scalar(pHba
, unit
, 0xF100, 6, buf
, 8)>=0)
3282 printk(" Rev: %-12.12s\n", buf
);
3285 printk(KERN_INFO
"\tClass: %.21s\n", adpt_i2o_get_class_name(d
->lct_data
.class_id
));
3286 printk(KERN_INFO
"\tSubclass: 0x%04X\n", d
->lct_data
.sub_class
);
3287 printk(KERN_INFO
"\tFlags: ");
3289 if(d
->lct_data
.device_flags
&(1<<0))
3290 printk("C"); // ConfigDialog requested
3291 if(d
->lct_data
.device_flags
&(1<<1))
3292 printk("U"); // Multi-user capable
3293 if(!(d
->lct_data
.device_flags
&(1<<4)))
3294 printk("P"); // Peer service enabled!
3295 if(!(d
->lct_data
.device_flags
&(1<<5)))
3296 printk("M"); // Mgmt service enabled!
3303 * Do i2o class name lookup
3305 static const char *adpt_i2o_get_class_name(int class)
3308 static char *i2o_class_name
[] = {
3310 "Device Driver Module",
3315 "Fibre Channel Port",
3316 "Fibre Channel Device",
3320 "Floppy Controller",
3322 "Secondary Bus Port",
3323 "Peer Transport Agent",
3328 switch(class&0xFFF) {
3329 case I2O_CLASS_EXECUTIVE
:
3333 case I2O_CLASS_RANDOM_BLOCK_STORAGE
:
3335 case I2O_CLASS_SEQUENTIAL_STORAGE
:
3341 case I2O_CLASS_FIBRE_CHANNEL_PORT
:
3343 case I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL
:
3345 case I2O_CLASS_SCSI_PERIPHERAL
:
3347 case I2O_CLASS_ATE_PORT
:
3349 case I2O_CLASS_ATE_PERIPHERAL
:
3351 case I2O_CLASS_FLOPPY_CONTROLLER
:
3353 case I2O_CLASS_FLOPPY_DEVICE
:
3355 case I2O_CLASS_BUS_ADAPTER_PORT
:
3357 case I2O_CLASS_PEER_TRANSPORT_AGENT
:
3359 case I2O_CLASS_PEER_TRANSPORT
:
3362 return i2o_class_name
[idx
];
3367 static s32
adpt_i2o_hrt_get(adpt_hba
* pHba
)
3370 int ret
, size
= sizeof(i2o_hrt
);
3373 if (pHba
->hrt
== NULL
) {
3374 pHba
->hrt
= dma_alloc_coherent(&pHba
->pDev
->dev
,
3375 size
, &pHba
->hrt_pa
, GFP_KERNEL
);
3376 if (pHba
->hrt
== NULL
) {
3377 printk(KERN_CRIT
"%s: Hrt Get failed; Out of memory.\n", pHba
->name
);
3382 msg
[0]= SIX_WORD_MSG_SIZE
| SGL_OFFSET_4
;
3383 msg
[1]= I2O_CMD_HRT_GET
<<24 | HOST_TID
<<12 | ADAPTER_TID
;
3386 msg
[4]= (0xD0000000 | size
); /* Simple transaction */
3387 msg
[5]= (u32
)pHba
->hrt_pa
; /* Dump it here */
3389 if ((ret
= adpt_i2o_post_wait(pHba
, msg
, sizeof(msg
),20))) {
3390 printk(KERN_ERR
"%s: Unable to get HRT (status=%#10x)\n", pHba
->name
, ret
);
3394 if (pHba
->hrt
->num_entries
* pHba
->hrt
->entry_len
<< 2 > size
) {
3395 int newsize
= pHba
->hrt
->num_entries
* pHba
->hrt
->entry_len
<< 2;
3396 dma_free_coherent(&pHba
->pDev
->dev
, size
,
3397 pHba
->hrt
, pHba
->hrt_pa
);
3401 } while(pHba
->hrt
== NULL
);
3406 * Query one scalar group value or a whole scalar group.
3408 static int adpt_i2o_query_scalar(adpt_hba
* pHba
, int tid
,
3409 int group
, int field
, void *buf
, int buflen
)
3411 u16 opblk
[] = { 1, 0, I2O_PARAMS_FIELD_GET
, group
, 1, field
};
3413 dma_addr_t opblk_pa
;
3415 dma_addr_t resblk_pa
;
3419 /* 8 bytes for header */
3420 resblk_va
= dma_alloc_coherent(&pHba
->pDev
->dev
,
3421 sizeof(u8
) * (8 + buflen
), &resblk_pa
, GFP_KERNEL
);
3422 if (resblk_va
== NULL
) {
3423 printk(KERN_CRIT
"%s: query scalar failed; Out of memory.\n", pHba
->name
);
3427 opblk_va
= dma_alloc_coherent(&pHba
->pDev
->dev
,
3428 sizeof(opblk
), &opblk_pa
, GFP_KERNEL
);
3429 if (opblk_va
== NULL
) {
3430 dma_free_coherent(&pHba
->pDev
->dev
, sizeof(u8
) * (8+buflen
),
3431 resblk_va
, resblk_pa
);
3432 printk(KERN_CRIT
"%s: query operatio failed; Out of memory.\n",
3436 if (field
== -1) /* whole group */
3439 memcpy(opblk_va
, opblk
, sizeof(opblk
));
3440 size
= adpt_i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET
, pHba
, tid
,
3441 opblk_va
, opblk_pa
, sizeof(opblk
),
3442 resblk_va
, resblk_pa
, sizeof(u8
)*(8+buflen
));
3443 dma_free_coherent(&pHba
->pDev
->dev
, sizeof(opblk
), opblk_va
, opblk_pa
);
3444 if (size
== -ETIME
) {
3445 dma_free_coherent(&pHba
->pDev
->dev
, sizeof(u8
) * (8+buflen
),
3446 resblk_va
, resblk_pa
);
3447 printk(KERN_WARNING
"%s: issue params failed; Timed out.\n", pHba
->name
);
3449 } else if (size
== -EINTR
) {
3450 dma_free_coherent(&pHba
->pDev
->dev
, sizeof(u8
) * (8+buflen
),
3451 resblk_va
, resblk_pa
);
3452 printk(KERN_WARNING
"%s: issue params failed; Interrupted.\n", pHba
->name
);
3456 memcpy(buf
, resblk_va
+8, buflen
); /* cut off header */
3458 dma_free_coherent(&pHba
->pDev
->dev
, sizeof(u8
) * (8+buflen
),
3459 resblk_va
, resblk_pa
);
3467 /* Issue UTIL_PARAMS_GET or UTIL_PARAMS_SET
3469 * This function can be used for all UtilParamsGet/Set operations.
3470 * The OperationBlock is given in opblk-buffer,
3471 * and results are returned in resblk-buffer.
3472 * Note that the minimum sized resblk is 8 bytes and contains
3473 * ResultCount, ErrorInfoSize, BlockStatus and BlockSize.
3475 static int adpt_i2o_issue_params(int cmd
, adpt_hba
* pHba
, int tid
,
3476 void *opblk_va
, dma_addr_t opblk_pa
, int oplen
,
3477 void *resblk_va
, dma_addr_t resblk_pa
, int reslen
)
3480 u32
*res
= (u32
*)resblk_va
;
3483 msg
[0] = NINE_WORD_MSG_SIZE
| SGL_OFFSET_5
;
3484 msg
[1] = cmd
<< 24 | HOST_TID
<< 12 | tid
;
3488 msg
[5] = 0x54000000 | oplen
; /* OperationBlock */
3489 msg
[6] = (u32
)opblk_pa
;
3490 msg
[7] = 0xD0000000 | reslen
; /* ResultBlock */
3491 msg
[8] = (u32
)resblk_pa
;
3493 if ((wait_status
= adpt_i2o_post_wait(pHba
, msg
, sizeof(msg
), 20))) {
3494 printk("adpt_i2o_issue_params: post_wait failed (%p)\n", resblk_va
);
3495 return wait_status
; /* -DetailedStatus */
3498 if (res
[1]&0x00FF0000) { /* BlockStatus != SUCCESS */
3499 printk(KERN_WARNING
"%s: %s - Error:\n ErrorInfoSize = 0x%02x, "
3500 "BlockStatus = 0x%02x, BlockSize = 0x%04x\n",
3502 (cmd
== I2O_CMD_UTIL_PARAMS_SET
) ? "PARAMS_SET"
3504 res
[1]>>24, (res
[1]>>16)&0xFF, res
[1]&0xFFFF);
3505 return -((res
[1] >> 16) & 0xFF); /* -BlockStatus */
3508 return 4 + ((res
[1] & 0x0000FFFF) << 2); /* bytes used in resblk */
3512 static s32
adpt_i2o_quiesce_hba(adpt_hba
* pHba
)
3517 adpt_i2o_status_get(pHba
);
3519 /* SysQuiesce discarded if IOP not in READY or OPERATIONAL state */
3521 if((pHba
->status_block
->iop_state
!= ADAPTER_STATE_READY
) &&
3522 (pHba
->status_block
->iop_state
!= ADAPTER_STATE_OPERATIONAL
)){
3526 msg
[0] = FOUR_WORD_MSG_SIZE
|SGL_OFFSET_0
;
3527 msg
[1] = I2O_CMD_SYS_QUIESCE
<<24|HOST_TID
<<12|ADAPTER_TID
;
3531 if((ret
= adpt_i2o_post_wait(pHba
, msg
, sizeof(msg
), 240))) {
3532 printk(KERN_INFO
"dpti%d: Unable to quiesce (status=%#x).\n",
3535 printk(KERN_INFO
"dpti%d: Quiesced.\n",pHba
->unit
);
3538 adpt_i2o_status_get(pHba
);
3544 * Enable IOP. Allows the IOP to resume external operations.
3546 static int adpt_i2o_enable_hba(adpt_hba
* pHba
)
3551 adpt_i2o_status_get(pHba
);
3552 if(!pHba
->status_block
){
3555 /* Enable only allowed on READY state */
3556 if(pHba
->status_block
->iop_state
== ADAPTER_STATE_OPERATIONAL
)
3559 if(pHba
->status_block
->iop_state
!= ADAPTER_STATE_READY
)
3562 msg
[0]=FOUR_WORD_MSG_SIZE
|SGL_OFFSET_0
;
3563 msg
[1]=I2O_CMD_SYS_ENABLE
<<24|HOST_TID
<<12|ADAPTER_TID
;
3567 if ((ret
= adpt_i2o_post_wait(pHba
, msg
, sizeof(msg
), 240))) {
3568 printk(KERN_WARNING
"%s: Could not enable (status=%#10x).\n",
3571 PDEBUG("%s: Enabled.\n", pHba
->name
);
3574 adpt_i2o_status_get(pHba
);
3579 static int adpt_i2o_systab_send(adpt_hba
* pHba
)
3584 msg
[0] = I2O_MESSAGE_SIZE(12) | SGL_OFFSET_6
;
3585 msg
[1] = I2O_CMD_SYS_TAB_SET
<<24 | HOST_TID
<<12 | ADAPTER_TID
;
3588 msg
[4] = (0<<16) | ((pHba
->unit
+2) << 12); /* Host 0 IOP ID (unit + 2) */
3589 msg
[5] = 0; /* Segment 0 */
3592 * Provide three SGL-elements:
3593 * System table (SysTab), Private memory space declaration and
3594 * Private i/o space declaration
3596 msg
[6] = 0x54000000 | sys_tbl_len
;
3597 msg
[7] = (u32
)sys_tbl_pa
;
3598 msg
[8] = 0x54000000 | 0;
3600 msg
[10] = 0xD4000000 | 0;
3603 if ((ret
=adpt_i2o_post_wait(pHba
, msg
, sizeof(msg
), 120))) {
3604 printk(KERN_INFO
"%s: Unable to set SysTab (status=%#10x).\n",
3609 PINFO("%s: SysTab set.\n", pHba
->name
);
3617 /*============================================================================
3619 *============================================================================
3625 static static void adpt_delay(int millisec
)
3628 for (i
= 0; i
< millisec
; i
++) {
3629 udelay(1000); /* delay for one millisecond */
3635 static struct scsi_host_template driver_template
= {
3636 .module
= THIS_MODULE
,
3638 .proc_name
= "dpt_i2o",
3639 .proc_info
= adpt_proc_info
,
3641 .queuecommand
= adpt_queue
,
3642 .eh_abort_handler
= adpt_abort
,
3643 .eh_device_reset_handler
= adpt_device_reset
,
3644 .eh_bus_reset_handler
= adpt_bus_reset
,
3645 .eh_host_reset_handler
= adpt_reset
,
3646 .bios_param
= adpt_bios_param
,
3647 .slave_configure
= adpt_slave_configure
,
3648 .can_queue
= MAX_TO_IOP_MESSAGES
,
3651 .use_clustering
= ENABLE_CLUSTERING
,
3654 static int __init
adpt_init(void)
3657 adpt_hba
*pHba
, *next
;
3659 printk("Loading Adaptec I2O RAID: Version " DPT_I2O_VERSION
"\n");
3661 error
= adpt_detect(&driver_template
);
3664 if (hba_chain
== NULL
)
3667 for (pHba
= hba_chain
; pHba
; pHba
= pHba
->next
) {
3668 error
= scsi_add_host(pHba
->host
, &pHba
->pDev
->dev
);
3671 scsi_scan_host(pHba
->host
);
3675 for (pHba
= hba_chain
; pHba
; pHba
= next
) {
3677 scsi_remove_host(pHba
->host
);
3682 static void __exit
adpt_exit(void)
3684 adpt_hba
*pHba
, *next
;
3686 for (pHba
= hba_chain
; pHba
; pHba
= pHba
->next
)
3687 scsi_remove_host(pHba
->host
);
3688 for (pHba
= hba_chain
; pHba
; pHba
= next
) {
3690 adpt_release(pHba
->host
);
3694 module_init(adpt_init
);
3695 module_exit(adpt_exit
);
3697 MODULE_LICENSE("GPL");