1 /*****************************************************************************/ 2 /* ips.c -- driver for the IBM ServeRAID controller */ 4 /* Written By: Keith Mitchell, IBM Corporation */ 6 /* Copyright (C) 1999 IBM Corporation */ 8 /* This program is free software; you can redistribute it and/or modify */ 9 /* it under the terms of the GNU General Public License as published by */ 10 /* the Free Software Foundation; either version 2 of the License, or */ 11 /* (at your option) any later version. */ 13 /* This program is distributed in the hope that it will be useful, */ 14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 16 /* GNU General Public License for more details. */ 19 /* THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR */ 20 /* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT */ 21 /* LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, */ 22 /* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is */ 23 /* solely responsible for determining the appropriateness of using and */ 24 /* distributing the Program and assumes all risks associated with its */ 25 /* exercise of rights under this Agreement, including but not limited to */ 26 /* the risks and costs of program errors, damage to or loss of data, */ 27 /* programs or equipment, and unavailability or interruption of operations. */ 29 /* DISCLAIMER OF LIABILITY */ 30 /* NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY */ 31 /* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL */ 32 /* DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND */ 33 /* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR */ 34 /* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE */ 35 /* USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED */ 36 /* HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES */ 38 /* You should have received a copy of the GNU General Public License */ 39 /* along with this program; if not, write to the Free Software */ 40 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 42 /* Bugs/Comments/Suggestions should be mailed to: */ 43 /* ipslinux@us.ibm.com */ 45 /*****************************************************************************/ 47 /*****************************************************************************/ 50 /* 0.99.02 - Breakup commands that are bigger than 8 * the stripe size */ 51 /* 0.99.03 - Make interrupt routine handle all completed request on the */ 52 /* adapter not just the first one */ 53 /* - Make sure passthru commands get woken up if we run out of */ 55 /* - Send all of the commands on the queue at once rather than */ 56 /* one at a time since the card will support it. */ 57 /* 0.99.04 - Fix race condition in the passthru mechanism -- this required */ 58 /* the interface to the utilities to change */ 59 /* - Fix error recovery code */ 60 /* 0.99.05 - Fix an oops when we get certain passthru commands */ 61 /* 1.00.00 - Initial Public Release */ 62 /* Functionally equivalent to 0.99.05 */ 64 /*****************************************************************************/ 67 * Conditional Compilation directives for this driver: 69 * NO_IPS_RESET - Don't reset the controller (no matter what) 70 * IPS_DEBUG - More verbose error messages 71 * IPS_PCI_PROBE_DEBUG - Print out more detail on the PCI probe 76 #include <linux/module.h> 80 #include <asm/byteorder.h> 81 #include <linux/stddef.h> 82 #include <linux/version.h> 83 #include <linux/string.h> 84 #include <linux/errno.h> 85 #include <linux/kernel.h> 86 #include <linux/ioport.h> 87 #include <linux/malloc.h> 88 #include <linux/delay.h> 89 #include <linux/sched.h> 90 #include <linux/pci.h> 91 #include <linux/proc_fs.h> 93 #include <linux/blk.h> 94 #include <linux/types.h> 96 #ifndef NO_IPS_CMDLINE 105 #include <linux/stat.h> 106 #include <linux/config.h> 107 #include <linux/spinlock.h> 108 #include <linux/smp.h> 113 #define IPS_VERSION_HIGH"1.00"/* MUST be 4 chars */ 114 #define IPS_VERSION_LOW".00 "/* MUST be 4 chars */ 116 struct proc_dir_entry proc_scsi_ips
= { 117 #if !defined(PROC_SCSI_IPS) 118 0,/* Use dynamic inode allocation */ 123 S_IFDIR
| S_IRUGO
| S_IXUGO
,2 126 #if LINUX_VERSION_CODE < LinuxVersionCode(2,1,93) 127 #include <linux/bios32.h> 130 #if !defined(__i386__) 131 #error"This driver has only been tested on the x86 platform" 134 #if LINUX_VERSION_CODE < LinuxVersionCode(2,2,0) 135 #error"This driver only works with kernel 2.2.0 and later" 138 #if !defined(NO_IPS_CMDLINE) && ((SG_BIG_BUFF < 8192) || !defined(SG_BIG_BUFF)) 139 #error"To use the command-line interface you need to define SG_BIG_BUFF" 143 #define DBG(s) printk(KERN_NOTICE s"\n"); MDELAY(2*ONE_SEC) 144 #elif IPS_DEBUG >= 11 145 #define DBG(s) printk(KERN_NOTICE s"\n") 153 static const char* ips_name
="ips"; 154 static struct Scsi_Host
* ips_sh
[IPS_MAX_ADAPTERS
];/* Array of host controller structures */ 155 static ips_ha_t
* ips_ha
[IPS_MAX_ADAPTERS
];/* Array of HA structures */ 156 static unsigned int ips_num_controllers
=0; 157 static int ips_cmd_timeout
=60; 158 static int ips_reset_timeout
=60*5; 160 #define MAX_ADAPTER_NAME 6 162 static char ips_adapter_name
[][30] = { 165 "ServeRAID on motherboard", 166 "ServeRAID on motherboard", 172 * Function prototypes 174 intips_detect(Scsi_Host_Template
*); 175 intips_release(struct Scsi_Host
*); 176 intips_abort(Scsi_Cmnd
*); 177 intips_reset(Scsi_Cmnd
*,unsigned int); 178 intips_eh_abort(Scsi_Cmnd
*); 179 intips_eh_reset(Scsi_Cmnd
*); 180 intips_queue(Scsi_Cmnd
*,void(*) (Scsi_Cmnd
*)); 181 intips_biosparam(Disk
*, kdev_t
,int*); 182 const char*ips_info(struct Scsi_Host
*); 183 voiddo_ipsintr(int,void*,struct pt_regs
*); 184 static intips_hainit(ips_ha_t
*); 185 static intips_map_status(ips_scb_t
*, ips_stat_t
*); 186 static intips_send(ips_ha_t
*, ips_scb_t
*, scb_callback
); 187 static intips_send_wait(ips_ha_t
*, ips_scb_t
*,int); 188 static intips_send_cmd(ips_ha_t
*, ips_scb_t
*); 189 static intips_chkstatus(ips_ha_t
*); 190 static intips_online(ips_ha_t
*, ips_scb_t
*); 191 static intips_inquiry(ips_ha_t
*, ips_scb_t
*); 192 static intips_rdcap(ips_ha_t
*, ips_scb_t
*); 193 static intips_msense(ips_ha_t
*, ips_scb_t
*); 194 static intips_reqsen(ips_ha_t
*, ips_scb_t
*); 195 static intips_allocatescbs(ips_ha_t
*); 196 static intips_reset_adapter(ips_ha_t
*); 197 static intips_statupd(ips_ha_t
*); 198 static intips_issue(ips_ha_t
*, ips_scb_t
*); 199 static intips_isintr(ips_ha_t
*); 200 static intips_wait(ips_ha_t
*,int,int); 201 static intips_write_driver_status(ips_ha_t
*); 202 static intips_read_adapter_status(ips_ha_t
*); 203 static intips_read_subsystem_parameters(ips_ha_t
*); 204 static intips_read_config(ips_ha_t
*); 205 static intips_clear_adapter(ips_ha_t
*); 206 static intips_readwrite_page5(ips_ha_t
*,int); 207 static voidips_intr(ips_ha_t
*); 208 static voidips_next(ips_ha_t
*); 209 static voidipsintr_blocking(ips_ha_t
*,struct ips_scb
*); 210 static voidipsintr_done(ips_ha_t
*,struct ips_scb
*); 211 static voidips_done(ips_ha_t
*, ips_scb_t
*); 212 static voidips_free(ips_ha_t
*); 213 static voidips_init_scb(ips_ha_t
*, ips_scb_t
*); 214 static voidips_freescb(ips_ha_t
*, ips_scb_t
*); 215 static voidips_statinit(ips_ha_t
*); 216 static ips_scb_t
*ips_getscb(ips_ha_t
*); 217 staticinlinevoidips_putq_scb_head(ips_scb_queue_t
*, ips_scb_t
*); 218 staticinlinevoidips_putq_scb_tail(ips_scb_queue_t
*, ips_scb_t
*); 219 staticinline ips_scb_t
*ips_removeq_scb_head(ips_scb_queue_t
*); 220 staticinline ips_scb_t
*ips_removeq_scb(ips_scb_queue_t
*, ips_scb_t
*); 221 staticinlinevoidips_putq_wait_head(ips_wait_queue_t
*, Scsi_Cmnd
*); 222 staticinlinevoidips_putq_wait_tail(ips_wait_queue_t
*, Scsi_Cmnd
*); 223 staticinline Scsi_Cmnd
*ips_removeq_wait_head(ips_wait_queue_t
*); 224 staticinline Scsi_Cmnd
*ips_removeq_wait(ips_wait_queue_t
*, Scsi_Cmnd
*); 226 #ifndef NO_IPS_CMDLINE 227 static intips_is_passthru(Scsi_Cmnd
*); 228 static intips_make_passthru(ips_ha_t
*, Scsi_Cmnd
*, ips_scb_t
*); 229 static intips_usrcmd(ips_ha_t
*, ips_passthru_t
*, ips_scb_t
*); 232 intips_proc_info(char*,char**, off_t
,int,int,int); 233 static intips_host_info(ips_ha_t
*,char*, off_t
,int); 234 static voidcopy_mem_info(INFOSTR
*,char*,int); 235 static intcopy_info(INFOSTR
*,char*, ...); 237 /*--------------------------------------------------------------------------*/ 238 /* Exported Functions */ 239 /*--------------------------------------------------------------------------*/ 241 /****************************************************************************/ 243 /* Routine Name: ips_detect */ 245 /* Routine Description: */ 247 /* Detect and initialize the driver */ 249 /****************************************************************************/ 251 ips_detect(Scsi_Host_Template
*SHT
) { 252 struct Scsi_Host
*sh
; 260 struct pci_dev
*dev
= NULL
; 264 SHT
->proc_info
= ips_proc_info
; 265 SHT
->proc_dir
= &proc_scsi_ips
; 267 #if defined(CONFIG_PCI) 269 /* initalize number of controllers */ 270 ips_num_controllers
=0; 275 for(index
=0; index
< IPS_MAX_ADAPTERS
; index
++) { 277 if(!(dev
=pci_find_device(IPS_VENDORID
, IPS_DEVICEID
, dev
))) 280 /* stuff that we get in dev */ 282 bus
= dev
->bus
->number
; 284 io_addr
= dev
->resource
[0].start
; 286 /* get planer status */ 287 if(pci_read_config_word(dev
,0x04, &planer
)) { 288 printk(KERN_WARNING
"(%s%d) can't get planer status.\n", 294 /* check I/O address */ 295 if((dev
->resource
[0].flags
& PCI_BASE_ADDRESS_SPACE
) != PCI_BASE_ADDRESS_SPACE_IO
) 298 /* check to see if an onboard planer controller is disabled */ 299 if(!(planer
&0x000C)) { 301 #ifdef IPS_PCI_PROBE_DEBUG 302 printk(KERN_NOTICE
"(%s%d) detect, Onboard ServeRAID disabled by BIOS\n", 309 #ifdef IPS_PCI_PROBE_DEBUG 310 printk(KERN_NOTICE
"(%s%d) detect bus %d, func %x, irq %d, io %x\n", 311 ips_name
, index
, bus
, func
, irq
, io_addr
); 314 /* found a controller */ 315 sh
=scsi_register(SHT
,sizeof(ips_ha_t
)); 318 printk(KERN_WARNING
"(%s%d) Unable to register controller with SCSI subsystem - skipping controller\n", 325 memset(ha
,0,sizeof(ips_ha_t
)); 327 /* Initialize spin lock */ 328 spin_lock_init(&ha
->scb_lock
); 329 spin_lock_init(&ha
->copp_lock
); 331 ips_sh
[ips_num_controllers
] = sh
; 332 ips_ha
[ips_num_controllers
] = ha
; 333 ips_num_controllers
++; 336 ha
->enq
=kmalloc(sizeof(ENQCMD
), GFP_KERNEL
|GFP_DMA
); 339 printk(KERN_WARNING
"(%s%d) Unable to allocate host inquiry structure - skipping contoller\n", 347 ha
->adapt
=kmalloc(sizeof(ADAPTER_AREA
), GFP_KERNEL
|GFP_DMA
); 350 printk(KERN_WARNING
"(%s%d) Unable to allocate host adapt structure - skipping controller\n", 358 ha
->conf
=kmalloc(sizeof(CONFCMD
), GFP_KERNEL
|GFP_DMA
); 361 printk(KERN_WARNING
"(%s%d) Unable to allocate host conf structure - skipping controller\n", 369 ha
->nvram
=kmalloc(sizeof(NVRAM_PAGE5
), GFP_KERNEL
|GFP_DMA
); 372 printk(KERN_WARNING
"(%s%d) Unable to allocate host nvram structure - skipping controller\n", 380 ha
->subsys
=kmalloc(sizeof(SUBSYS_PARAM
), GFP_KERNEL
|GFP_DMA
); 383 printk(KERN_WARNING
"(%s%d) Unable to allocate host subsystem structure - skipping controller\n", 391 ha
->dummy
=kmalloc(sizeof(BASIC_IO_CMD
), GFP_KERNEL
|GFP_DMA
); 394 printk(KERN_WARNING
"(%s%d) Unable to allocate host dummy structure - skipping controller\n", 402 /* Store away needed values for later use */ 403 sh
->io_port
= io_addr
; 405 sh
->unique_id
= io_addr
; 407 sh
->select_queue_depths
= NULL
; 408 sh
->sg_tablesize
= sh
->hostt
->sg_tablesize
; 409 sh
->can_queue
= sh
->hostt
->can_queue
; 410 sh
->cmd_per_lun
= sh
->hostt
->cmd_per_lun
; 411 sh
->unchecked_isa_dma
= sh
->hostt
->unchecked_isa_dma
; 412 sh
->use_clustering
= sh
->hostt
->use_clustering
; 413 sh
->wish_block
= FALSE
; 415 /* Store info in HA structure */ 416 ha
->io_addr
= io_addr
; 418 ha
->host_num
= index
; 420 /* install the interrupt handler */ 421 if(request_irq(irq
, do_ipsintr
, SA_SHIRQ
, ips_name
, ha
)) { 422 printk(KERN_WARNING
"(%s%d) unable to install interrupt handler - skipping controller\n", 431 * Allocate a temporary SCB for initialization 433 ha
->scbs
= (ips_scb_t
*)kmalloc(sizeof(ips_scb_t
), GFP_KERNEL
|GFP_DMA
); 435 /* couldn't allocate a temp SCB */ 436 printk(KERN_WARNING
"(%s%d) unable to allocate CCBs - skipping contoller\n", 444 memset(ha
->scbs
,0,sizeof(ips_scb_t
)); 445 ha
->scbs
->sg_list
= (SG_LIST
*)kmalloc(sizeof(SG_LIST
) * MAX_SG_ELEMENTS
, GFP_KERNEL
|GFP_DMA
); 446 if(!ha
->scbs
->sg_list
) { 447 /* couldn't allocate a temp SCB S/G list */ 448 printk(KERN_WARNING
"(%s%d) unable to allocate CCBs - skipping contoller\n", 458 if(!ips_hainit(ha
)) { 459 printk(KERN_WARNING
"(%s%d) unable to initialize controller - skipping\n", 468 * Free the temporary SCB 470 kfree(ha
->scbs
->sg_list
); 475 if(!ips_allocatescbs(ha
)) { 476 printk(KERN_WARNING
"(%s%d) unable to allocate CCBs - skipping contoller\n", 484 /* finish setting values */ 485 sh
->max_id
= ha
->ntargets
; 486 sh
->max_lun
= ha
->nlun
; 487 sh
->max_channel
= ha
->nbus
; 488 sh
->can_queue
= ha
->max_cmds
-1; 491 return(ips_num_controllers
); 495 /* No PCI -- No ServeRAID */ 497 #endif/* CONFIG_PCI */ 500 /****************************************************************************/ 502 /* Routine Name: ips_release */ 504 /* Routine Description: */ 506 /* Remove a driver */ 508 /****************************************************************************/ 510 ips_release(struct Scsi_Host
*sh
) { 517 for(i
=0; i
< IPS_MAX_ADAPTERS
&& ips_sh
[i
] != sh
; i
++); 519 if(i
== IPS_MAX_ADAPTERS
) 520 panic("(%s) release, invalid Scsi_Host pointer.\n", 528 /* flush the cache on the controller */ 529 scb
= &ha
->scbs
[ha
->max_cmds
-1]; 531 ips_init_scb(ha
, scb
); 533 scb
->timeout
= ips_cmd_timeout
; 534 scb
->cdb
[0] = FLUSH_CACHE
; 536 scb
->cmd
.flush_cache
.op_code
= FLUSH_CACHE
; 537 scb
->cmd
.flush_cache
.command_id
=IPS_COMMAND_ID(ha
, scb
); 538 scb
->cmd
.flush_cache
.state
= NORM_STATE
; 539 scb
->cmd
.flush_cache
.reserved
=0; 540 scb
->cmd
.flush_cache
.reserved2
=0; 541 scb
->cmd
.flush_cache
.reserved3
=0; 542 scb
->cmd
.flush_cache
.reserved4
=0; 544 printk("(%s%d) Flushing Cache.\n", ips_name
, ha
->host_num
); 547 if(ips_send_wait(ha
, scb
, ips_cmd_timeout
) == IPS_FAILURE
) 548 printk("(%s%d) Incomplete Flush.\n", ips_name
, ha
->host_num
); 550 printk("(%s%d) Flushing Complete.\n", ips_name
, ha
->host_num
); 555 /* free extra memory */ 559 free_irq(ha
->irq
, ha
); 561 /* unregister with SCSI sub system */ 567 /****************************************************************************/ 569 /* Routine Name: ips_eh_abort */ 571 /* Routine Description: */ 573 /* Abort a command (using the new error code stuff) */ 575 /****************************************************************************/ 577 ips_eh_abort(Scsi_Cmnd
*SC
) { 585 ha
= (ips_ha_t
*) SC
->host
->hostdata
; 593 if(SC
->serial_number
!= SC
->serial_number_at_timeout
) { 594 /* HMM, looks like a bogus command */ 596 printk(KERN_NOTICE
"Abort called with bogus scsi command\n"); 602 if(test_and_set_bit(IPS_IN_ABORT
, &ha
->flags
)) 605 /* See if the command is on the wait queue */ 606 if(ips_removeq_wait(&ha
->scb_waitlist
, SC
) || 607 ips_removeq_wait(&ha
->copp_waitlist
, SC
)) { 608 /* command not sent yet */ 609 clear_bit(IPS_IN_ABORT
, &ha
->flags
); 613 /* command must have already been sent */ 614 clear_bit(IPS_IN_ABORT
, &ha
->flags
); 620 /****************************************************************************/ 622 /* Routine Name: ips_abort */ 624 /* Routine Description: */ 626 /* Abort a command */ 628 /****************************************************************************/ 630 ips_abort(Scsi_Cmnd
*SC
) { 636 return(SCSI_ABORT_SNOOZE
); 638 ha
= (ips_ha_t
*) SC
->host
->hostdata
; 641 return(SCSI_ABORT_SNOOZE
); 644 return(SCSI_ABORT_SNOOZE
); 646 if(SC
->serial_number
!= SC
->serial_number_at_timeout
) { 647 /* HMM, looks like a bogus command */ 649 printk(KERN_NOTICE
"Abort called with bogus scsi command\n"); 652 return(SCSI_ABORT_NOT_RUNNING
); 655 if(test_and_set_bit(IPS_IN_ABORT
, &ha
->flags
)) 656 return(SCSI_ABORT_SNOOZE
); 658 /* See if the command is on the wait queue */ 659 if(ips_removeq_wait(&ha
->scb_waitlist
, SC
) || 660 ips_removeq_wait(&ha
->copp_waitlist
, SC
)) { 661 /* command not sent yet */ 662 clear_bit(IPS_IN_ABORT
, &ha
->flags
); 664 return(SCSI_ABORT_PENDING
); 666 /* command must have already been sent */ 667 clear_bit(IPS_IN_ABORT
, &ha
->flags
); 669 return(SCSI_ABORT_SNOOZE
); 673 /****************************************************************************/ 675 /* Routine Name: ips_eh_reset */ 677 /* Routine Description: */ 679 /* Reset the controller (with new eh error code) */ 681 /****************************************************************************/ 683 ips_eh_reset(Scsi_Cmnd
*SC
) { 696 printk(KERN_NOTICE
"Reset called with NULL scsi command\n"); 702 ha
= (ips_ha_t
*) SC
->host
->hostdata
; 707 printk(KERN_NOTICE
"Reset called with NULL ha struct\n"); 716 if(test_and_set_bit(IPS_IN_RESET
, &ha
->flags
)) 719 /* See if the command is on the waiting queue */ 720 if(ips_removeq_wait(&ha
->scb_waitlist
, SC
) || 721 ips_removeq_wait(&ha
->copp_waitlist
, SC
)) { 722 /* command not sent yet */ 723 clear_bit(IPS_IN_ABORT
, &ha
->flags
); 729 * command must have already been sent 730 * reset the controller 732 if(!ips_reset_adapter(ha
)) { 733 clear_bit(IPS_IN_RESET
, &ha
->flags
); 738 if(!ips_clear_adapter(ha
)) { 739 clear_bit(IPS_IN_RESET
, &ha
->flags
); 744 /* Now fail all of the active commands */ 746 printk(KERN_WARNING
"(%s%d) Failing active commands\n", 747 ips_name
, ha
->host_num
); 749 while((scb
=ips_removeq_scb_head(&ha
->scb_activelist
))) { 750 scb
->scsi_cmd
->result
= DID_RESET
<<16; 751 scb
->scsi_cmd
->scsi_done(scb
->scsi_cmd
); 752 ips_freescb(ha
, scb
); 755 /* Reset the number of active IOCTLs */ 758 clear_bit(IPS_IN_RESET
, &ha
->flags
); 760 if(!test_bit(IPS_IN_INTR
, &ha
->flags
)) { 762 * Only execute the next command when 763 * we are not being called from the 764 * interrupt handler. The interrupt 765 * handler wants to do this and since 766 * interrupts are turned off here.... 773 #endif/* NO_IPS_RESET */ 777 /****************************************************************************/ 779 /* Routine Name: ips_reset */ 781 /* Routine Description: */ 783 /* Reset the controller */ 785 /****************************************************************************/ 787 ips_reset(Scsi_Cmnd
*SC
,unsigned int flags
) { 794 return(SCSI_RESET_SNOOZE
); 800 printk(KERN_NOTICE
"Reset called with NULL scsi command\n"); 803 return(SCSI_RESET_SNOOZE
); 806 ha
= (ips_ha_t
*) SC
->host
->hostdata
; 811 printk(KERN_NOTICE
"Reset called with NULL ha struct\n"); 814 return(SCSI_RESET_SNOOZE
); 818 return(SCSI_RESET_SNOOZE
); 820 if(test_and_set_bit(IPS_IN_RESET
, &ha
->flags
)) 821 return(SCSI_RESET_SNOOZE
); 823 /* See if the command is on the waiting queue */ 824 if(ips_removeq_wait(&ha
->scb_waitlist
, SC
) || 825 ips_removeq_wait(&ha
->copp_waitlist
, SC
)) { 826 /* command not sent yet */ 827 clear_bit(IPS_IN_ABORT
, &ha
->flags
); 829 return(SCSI_RESET_SNOOZE
); 832 /* reset the controller */ 833 if(!ips_reset_adapter(ha
)) { 834 clear_bit(IPS_IN_RESET
, &ha
->flags
); 836 return(SCSI_RESET_ERROR
); 839 if(!ips_clear_adapter(ha
)) { 840 clear_bit(IPS_IN_RESET
, &ha
->flags
); 842 return(SCSI_RESET_ERROR
); 845 /* Now fail all of the active commands */ 847 printk(KERN_WARNING
"(%s%d) Failing active commands\n", 848 ips_name
, ha
->host_num
); 850 while((scb
=ips_removeq_scb_head(&ha
->scb_activelist
))) { 851 scb
->scsi_cmd
->result
= DID_RESET
<<16; 852 scb
->scsi_cmd
->scsi_done(scb
->scsi_cmd
); 853 ips_freescb(ha
, scb
); 856 /* Reset the number of active IOCTLs */ 859 clear_bit(IPS_IN_RESET
, &ha
->flags
); 861 if(!test_bit(IPS_IN_INTR
, &ha
->flags
)) { 863 * Only execute the next command when 864 * we are not being called from the 865 * interrupt handler. The interrupt 866 * handler wants to do this and since 867 * interrupts are turned off here.... 872 return(SCSI_RESET_SUCCESS
); 874 #endif/* NO_IPS_RESET */ 878 /****************************************************************************/ 880 /* Routine Name: ips_queue */ 882 /* Routine Description: */ 884 /* Send a command to the controller */ 886 /****************************************************************************/ 888 ips_queue(Scsi_Cmnd
*SC
,void(*done
) (Scsi_Cmnd
*)) { 893 ha
= (ips_ha_t
*) SC
->host
->hostdata
; 901 #ifndef NO_IPS_CMDLINE 902 if(ips_is_passthru(SC
)) { 903 if(ha
->copp_waitlist
.count
== IPS_MAX_IOCTL_QUEUE
) { 904 SC
->result
= DID_BUS_BUSY
<<16; 911 if(ha
->scb_waitlist
.count
== IPS_MAX_QUEUE
) { 912 SC
->result
= DID_BUS_BUSY
<<16; 918 #ifndef NO_IPS_CMDLINE 922 SC
->scsi_done
= done
; 925 printk(KERN_NOTICE
"%s: ips_queue: cmd 0x%X (%d %d %d)\n", 936 #ifndef NO_IPS_CMDLINE 937 if(ips_is_passthru(SC
)) 938 ips_putq_wait_tail(&ha
->copp_waitlist
, SC
); 941 ips_putq_wait_tail(&ha
->scb_waitlist
, SC
); 943 if((!test_bit(IPS_IN_INTR
, &ha
->flags
)) && 944 (!test_bit(IPS_IN_ABORT
, &ha
->flags
)) && 945 (!test_bit(IPS_IN_RESET
, &ha
->flags
))) 951 /****************************************************************************/ 953 /* Routine Name: ips_biosparam */ 955 /* Routine Description: */ 957 /* Set bios geometry for the controller */ 959 /****************************************************************************/ 961 ips_biosparam(Disk
*disk
, kdev_t dev
,int geom
[]) { 967 DBG("ips_biosparam"); 969 ha
= (ips_ha_t
*) disk
->device
->host
->hostdata
; 972 /* ?!?! host adater info invalid */ 978 if(!ips_read_adapter_status(ha
)) 979 /* ?!?! Enquiry command failed */ 982 if((disk
->capacity
>0x400000) && 983 ((ha
->enq
->ucMiscFlag
&0x8) ==0)) { 984 heads
= NORM_MODE_HEADS
; 985 sectors
= NORM_MODE_SECTORS
; 987 heads
= COMP_MODE_HEADS
; 988 sectors
= COMP_MODE_SECTORS
; 991 cylinders
= disk
->capacity
/ (heads
* sectors
); 994 printk(KERN_NOTICE
"Geometry: heads: %d, sectors: %d, cylinders: %d\n", 995 heads
, sectors
, cylinders
); 1000 geom
[2] = cylinders
; 1005 /****************************************************************************/ 1007 /* Routine Name: do_ipsintr */ 1009 /* Routine Description: */ 1011 /* Wrapper for the interrupt handler */ 1013 /****************************************************************************/ 1015 do_ipsintr(int irq
,void*dev_id
,struct pt_regs
*regs
) { 1017 unsigned int cpu_flags
; 1021 ha
= (ips_ha_t
*) dev_id
; 1023 spin_lock_irqsave(&io_request_lock
, cpu_flags
); 1025 if(test_and_set_bit(IPS_IN_INTR
, &ha
->flags
)) { 1026 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
); 1032 clear_bit(IPS_IN_INTR
, &ha
->flags
); 1033 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
); 1039 clear_bit(IPS_IN_INTR
, &ha
->flags
); 1040 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
); 1047 clear_bit(IPS_IN_INTR
, &ha
->flags
); 1049 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
); 1052 /****************************************************************************/ 1054 /* Routine Name: ips_intr */ 1056 /* Routine Description: */ 1058 /* Polling interrupt handler */ 1060 /* ASSUMES interrupts are disabled */ 1062 /****************************************************************************/ 1064 ips_intr(ips_ha_t
*ha
) { 1077 while(ips_isintr(ha
)) { 1080 if((status
=ips_chkstatus(ha
)) <0) { 1081 /* unexpected interrupt - no ccb */ 1082 printk(KERN_WARNING
"(%s%d) Spurious interrupt; no ccb.\n", 1083 ips_name
, ha
->host_num
); 1087 scb
= (ips_scb_t
*) sp
->scb_addr
; 1090 * use the callback function to finish things up 1091 * NOTE: interrupts are OFF for this 1093 (*scb
->callback
) (ha
, scb
); 1096 clear_bit(IPS_IN_INTR
, &ha
->flags
); 1099 /****************************************************************************/ 1101 /* Routine Name: ips_info */ 1103 /* Routine Description: */ 1105 /* Return info about the driver */ 1107 /****************************************************************************/ 1109 ips_info(struct Scsi_Host
*SH
) { 1110 static char buffer
[256]; 1122 memset(bp
,0,sizeof(buffer
)); 1124 strcpy(bp
,"IBM PCI ServeRAID "); 1125 strcat(bp
, IPS_VERSION_HIGH
); 1126 strcat(bp
, IPS_VERSION_LOW
); 1129 ha
->ad_type
<= MAX_ADAPTER_NAME
) { 1131 strcat(bp
, ips_adapter_name
[ha
->ad_type
-1]); 1138 /****************************************************************************/ 1140 /* Routine Name: ips_proc_info */ 1142 /* Routine Description: */ 1144 /* The passthru interface for the driver */ 1146 /****************************************************************************/ 1148 ips_proc_info(char*buffer
,char**start
, off_t offset
, 1149 int length
,int hostno
,int func
) { 1152 ips_ha_t
*ha
= NULL
; 1154 DBG("ips_proc_info"); 1156 /* Find our host structure */ 1157 for(i
=0; i
< ips_num_controllers
; i
++) { 1158 if(ips_sh
[i
] && ips_sh
[i
]->host_no
== hostno
) { 1159 ha
= (ips_ha_t
*) ips_sh
[i
]->hostdata
; 1176 ret
=ips_host_info(ha
, buffer
, offset
, length
); 1182 /*--------------------------------------------------------------------------*/ 1183 /* Helper Functions */ 1184 /*--------------------------------------------------------------------------*/ 1186 #ifndef NO_IPS_CMDLINE 1188 /****************************************************************************/ 1190 /* Routine Name: ips_is_passthru */ 1192 /* Routine Description: */ 1194 /* Determine if the specified SCSI command is really a passthru command */ 1196 /****************************************************************************/ 1198 ips_is_passthru(Scsi_Cmnd
*SC
) { 1199 DBG("ips_is_passthru"); 1204 if((SC
->channel
==0) && 1205 (SC
->target
== IPS_ADAPTER_ID
) && 1207 (SC
->cmnd
[0] ==0x0d) && 1208 (SC
->request_bufflen
) && 1210 (((char*) SC
->request_buffer
)[0] =='C') && 1211 (((char*) SC
->request_buffer
)[1] =='O') && 1212 (((char*) SC
->request_buffer
)[2] =='P') && 1213 (((char*) SC
->request_buffer
)[3] =='P')) { 1220 /****************************************************************************/ 1222 /* Routine Name: ips_is_passthru */ 1224 /* Routine Description: */ 1226 /* Make a passthru command out of the info in the Scsi block */ 1228 /****************************************************************************/ 1230 ips_make_passthru(ips_ha_t
*ha
, Scsi_Cmnd
*SC
, ips_scb_t
*scb
) { 1233 DBG("ips_make_passthru"); 1235 if(!SC
->request_bufflen
|| !SC
->request_buffer
) { 1237 #if IPS_DEBUG_PT >= 1 1238 printk(KERN_NOTICE
"(%s%d) No passthru structure\n", 1239 ips_name
, ha
->host_num
); 1242 return(IPS_FAILURE
); 1245 if(SC
->request_bufflen
<sizeof(ips_passthru_t
)) { 1247 #if IPS_DEBUG_PT >= 1 1248 printk(KERN_NOTICE
"(%s%d) Passthru structure wrong size\n", 1249 ips_name
, ha
->host_num
); 1252 return(IPS_FAILURE
); 1255 if((((char*) SC
->request_buffer
)[0] !='C') || 1256 (((char*) SC
->request_buffer
)[1] !='O') || 1257 (((char*) SC
->request_buffer
)[2] !='P') || 1258 (((char*) SC
->request_buffer
)[3] !='P')) { 1259 /* signature doesn't match */ 1260 #if IPS_DEBUG_PT >= 1 1261 printk(KERN_NOTICE
"(%s%d) Wrong signature on passthru structure.\n", 1262 ips_name
, ha
->host_num
); 1265 return(IPS_FAILURE
); 1268 pt
= (ips_passthru_t
*) SC
->request_buffer
; 1271 if(SC
->request_bufflen
< (sizeof(ips_passthru_t
) + pt
->CmdBSize
)) { 1273 #if IPS_DEBUG_PT >= 1 1274 printk(KERN_NOTICE
"(%s%d) Passthru structure wrong size\n", 1275 ips_name
, ha
->host_num
); 1278 return(IPS_FAILURE
); 1281 switch(pt
->CoppCmd
) { 1283 memcpy(SC
->request_buffer
+sizeof(ips_passthru_t
), 1284 &ips_num_controllers
,sizeof(int)); 1285 SC
->result
= DID_OK
<<16; 1287 return(IPS_SUCCESS_IMM
); 1289 memcpy(SC
->request_buffer
+sizeof(ips_passthru_t
), 1290 ha
,sizeof(ips_ha_t
)); 1291 SC
->result
= DID_OK
<<16; 1293 return(IPS_SUCCESS_IMM
); 1295 if(ips_usrcmd(ha
, pt
, scb
)) 1296 return(IPS_SUCCESS
); 1298 return(IPS_FAILURE
); 1302 return(IPS_FAILURE
); 1305 /****************************************************************************/ 1307 /* Routine Name: ips_usrcmd */ 1309 /* Routine Description: */ 1311 /* Process a user command and make it ready to send */ 1313 /****************************************************************************/ 1315 ips_usrcmd(ips_ha_t
*ha
, ips_passthru_t
*pt
, ips_scb_t
*scb
) { 1320 if((!scb
) || (!pt
) || (!ha
)) 1323 /* Save the S/G list pointer so it doesn't get clobbered */ 1324 sg_list
= scb
->sg_list
; 1326 /* copy in the CP */ 1327 memcpy(&scb
->cmd
, &pt
->CoppCP
.cmd
,sizeof(IOCTL_INFO
)); 1328 memcpy(&scb
->dcdb
, &pt
->CoppCP
.dcdb
,sizeof(DCDB_TABLE
)); 1330 /* FIX stuff that might be wrong */ 1331 scb
->sg_list
= sg_list
; 1332 scb
->scb_busaddr
=VIRT_TO_BUS(scb
); 1340 scb
->callback
= ipsintr_done
; 1341 scb
->timeout
= ips_cmd_timeout
; 1342 scb
->cmd
.basic_io
.command_id
=IPS_COMMAND_ID(ha
, scb
); 1344 /* we don't support DCDB/READ/WRITE Scatter Gather */ 1345 if((scb
->cmd
.basic_io
.op_code
== READ_SCATTER_GATHER
) || 1346 (scb
->cmd
.basic_io
.op_code
== WRITE_SCATTER_GATHER
) || 1347 (scb
->cmd
.basic_io
.op_code
== DIRECT_CDB_SCATTER_GATHER
)) 1350 if(pt
->CmdBSize
&& pt
->CmdBuffer
) { 1351 scb
->data_busaddr
=VIRT_TO_BUS(scb
->scsi_cmd
->request_buffer
+sizeof(ips_passthru_t
)); 1353 scb
->data_busaddr
=0L; 1357 if(scb
->cmd
.dcdb
.op_code
== DIRECT_CDB
) { 1358 scb
->cmd
.dcdb
.dcdb_address
=VIRT_TO_BUS(&scb
->dcdb
); 1359 scb
->dcdb
.buffer_pointer
= scb
->data_busaddr
; 1361 scb
->cmd
.basic_io
.sg_addr
= scb
->data_busaddr
; 1367 scb
->timeout
= pt
->TimeOut
; 1369 if(pt
->TimeOut
<=10) 1370 scb
->dcdb
.cmd_attribute
|= TIMEOUT_10
; 1371 else if(pt
->TimeOut
<=60) 1372 scb
->dcdb
.cmd_attribute
|= TIMEOUT_60
; 1374 scb
->dcdb
.cmd_attribute
|= TIMEOUT_20M
; 1378 scb
->scsi_cmd
->result
= DID_ERROR
<<16; 1384 /****************************************************************************/ 1386 /* Routine Name: ips_cleanup_passthru */ 1388 /* Routine Description: */ 1390 /* Cleanup after a passthru command */ 1392 /****************************************************************************/ 1394 ips_cleanup_passthru(ips_scb_t
*scb
) { 1397 DBG("ips_cleanup_passthru"); 1399 if((!scb
) || (!scb
->scsi_cmd
) || (!scb
->scsi_cmd
->request_buffer
)) { 1400 #if IPS_DEBUG_PT >= 1 1401 printk(KERN_NOTICE
"IPS couldn't cleanup\n"); 1407 pt
= (ips_passthru_t
*) scb
->scsi_cmd
->request_buffer
; 1409 /* Copy data back to the user */ 1410 pt
->BasicStatus
= scb
->basic_status
; 1411 pt
->ExtendedStatus
= scb
->extended_status
; 1413 scb
->scsi_cmd
->result
= DID_OK
<<16; 1418 /****************************************************************************/ 1420 /* Routine Name: ips_host_info */ 1422 /* Routine Description: */ 1424 /* The passthru interface for the driver */ 1426 /****************************************************************************/ 1428 ips_host_info(ips_ha_t
*ha
,char*ptr
, off_t offset
,int len
) { 1431 DBG("ips_host_info"); 1435 info
.offset
= offset
; 1438 copy_info(&info
,"\nIBM ServeRAID General Information:\n\n"); 1440 if((ha
->nvram
->signature
== NVRAM_PAGE5_SIGNATURE
) && 1441 (ha
->nvram
->adapter_type
!=0)) 1442 copy_info(&info
,"\tController Type : %s\n", ips_adapter_name
[ha
->ad_type
-1]); 1444 copy_info(&info
,"\tController Type : Unknown\n"); 1446 copy_info(&info
,"\tIO port address : 0x%lx\n", ha
->io_addr
); 1447 copy_info(&info
,"\tIRQ number : %d\n", ha
->irq
); 1449 if(ha
->nvram
->signature
== NVRAM_PAGE5_SIGNATURE
) 1450 copy_info(&info
,"\tBIOS Version : %c%c%c%c%c%c%c%c\n", 1451 ha
->nvram
->bios_high
[0], ha
->nvram
->bios_high
[1], 1452 ha
->nvram
->bios_high
[2], ha
->nvram
->bios_high
[3], 1453 ha
->nvram
->bios_low
[0], ha
->nvram
->bios_low
[1], 1454 ha
->nvram
->bios_low
[2], ha
->nvram
->bios_low
[3]); 1456 copy_info(&info
,"\tFirmware Version : %c%c%c%c%c%c%c%c\n", 1457 ha
->enq
->CodeBlkVersion
[0], ha
->enq
->CodeBlkVersion
[1], 1458 ha
->enq
->CodeBlkVersion
[2], ha
->enq
->CodeBlkVersion
[3], 1459 ha
->enq
->CodeBlkVersion
[4], ha
->enq
->CodeBlkVersion
[5], 1460 ha
->enq
->CodeBlkVersion
[6], ha
->enq
->CodeBlkVersion
[7]); 1462 copy_info(&info
,"\tBoot Block Version : %c%c%c%c%c%c%c%c\n", 1463 ha
->enq
->BootBlkVersion
[0], ha
->enq
->BootBlkVersion
[1], 1464 ha
->enq
->BootBlkVersion
[2], ha
->enq
->BootBlkVersion
[3], 1465 ha
->enq
->BootBlkVersion
[4], ha
->enq
->BootBlkVersion
[5], 1466 ha
->enq
->BootBlkVersion
[6], ha
->enq
->BootBlkVersion
[7]); 1468 copy_info(&info
,"\tDriver Version : %s%s\n", 1469 IPS_VERSION_HIGH
, IPS_VERSION_LOW
); 1471 copy_info(&info
,"\tMax Physical Devices : %d\n", 1472 ha
->enq
->ucMaxPhysicalDevices
); 1473 copy_info(&info
,"\tMax Active Commands : %d\n", 1475 copy_info(&info
,"\tCurrent Queued Commands : %d\n", 1476 ha
->scb_waitlist
.count
); 1477 copy_info(&info
,"\tCurrent Active Commands : %d\n", 1478 ha
->scb_activelist
.count
- ha
->num_ioctl
); 1479 copy_info(&info
,"\tCurrent Queued PT Commands : %d\n", 1480 ha
->copp_waitlist
.count
); 1481 copy_info(&info
,"\tCurrent Active PT Commands : %d\n", 1484 copy_info(&info
,"\n"); 1486 return(info
.pos
> info
.offset
? info
.pos
- info
.offset
:0); 1489 /****************************************************************************/ 1491 /* Routine Name: copy_mem_info */ 1493 /* Routine Description: */ 1495 /* Copy data into an INFOSTR structure */ 1497 /****************************************************************************/ 1499 copy_mem_info(INFOSTR
*info
,char*data
,int len
) { 1500 DBG("copy_mem_info"); 1502 if(info
->pos
+ len
> info
->length
) 1503 len
= info
->length
- info
->pos
; 1505 if(info
->pos
+ len
< info
->offset
) { 1510 if(info
->pos
< info
->offset
) { 1511 data
+= (info
->offset
- info
->pos
); 1512 len
-= (info
->offset
- info
->pos
); 1516 memcpy(info
->buffer
+ info
->pos
, data
, len
); 1521 /****************************************************************************/ 1523 /* Routine Name: copy_info */ 1525 /* Routine Description: */ 1527 /* printf style wrapper for an info structure */ 1529 /****************************************************************************/ 1531 copy_info(INFOSTR
*info
,char*fmt
, ...) { 1538 va_start(args
, fmt
); 1539 len
=vsprintf(buf
, fmt
, args
); 1542 copy_mem_info(info
, buf
, len
); 1547 /****************************************************************************/ 1549 /* Routine Name: ips_hainit */ 1551 /* Routine Description: */ 1553 /* Initialize the controller */ 1555 /* NOTE: Assumes to be called from with a lock */ 1557 /****************************************************************************/ 1559 ips_hainit(ips_ha_t
*ha
) { 1567 /* initialize status queue */ 1570 /* Setup HBA ID's */ 1571 if(!ips_read_config(ha
)) { 1573 #ifndef NO_IPS_RESET 1575 /* Try to reset the controller and try again */ 1576 if(!ips_reset_adapter(ha
)) { 1577 printk(KERN_WARNING
"(%s%d) unable to reset controller.\n", 1578 ips_name
, ha
->host_num
); 1583 if(!ips_clear_adapter(ha
)) { 1584 printk(KERN_WARNING
"(%s%d) unable to initialize controller.\n", 1585 ips_name
, ha
->host_num
); 1592 if(!ips_read_config(ha
)) { 1593 printk(KERN_WARNING
"(%s%d) unable to read config from controller.\n", 1594 ips_name
, ha
->host_num
); 1600 /* write driver version */ 1601 if(!ips_write_driver_status(ha
)) { 1602 printk(KERN_WARNING
"(%s%d) unable to write driver info to controller.\n", 1603 ips_name
, ha
->host_num
); 1608 if(!ips_read_adapter_status(ha
)) { 1609 printk(KERN_WARNING
"(%s%d) unable to read controller status.\n", 1610 ips_name
, ha
->host_num
); 1615 if(!ips_read_subsystem_parameters(ha
)) { 1616 printk(KERN_WARNING
"(%s%d) unable to read subsystem parameters.\n", 1617 ips_name
, ha
->host_num
); 1622 /* set limits on SID, LUN, BUS */ 1623 ha
->ntargets
= MAX_TARGETS
+1; 1625 ha
->nbus
= (ha
->enq
->ucMaxPhysicalDevices
/ MAX_TARGETS
); 1627 switch(ha
->conf
->logical_drive
[0].ucStripeSize
) { 1629 ha
->max_xfer
=0x10000; 1633 ha
->max_xfer
=0x20000; 1637 ha
->max_xfer
=0x40000; 1642 ha
->max_xfer
=0x80000; 1646 /* setup max concurrent commands */ 1647 if(ha
->subsys
->param
[4] &0x1) { 1648 /* Use the new method */ 1649 ha
->max_cmds
= ha
->enq
->ucConcurrentCmdCount
; 1651 /* use the old method */ 1652 switch(ha
->conf
->logical_drive
[0].ucStripeSize
) { 1672 /* set controller IDs */ 1673 ha
->ha_id
[0] = IPS_ADAPTER_ID
; 1674 for(i
=1; i
< ha
->nbus
; i
++) 1675 ha
->ha_id
[i
] = ha
->conf
->init_id
[i
-1] &0x1f; 1680 /****************************************************************************/ 1682 /* Routine Name: ips_next */ 1684 /* Routine Description: */ 1686 /* Take the next command off the queue and send it to the controller */ 1688 /* ASSUMED to be called from within a lock */ 1690 /****************************************************************************/ 1692 ips_next(ips_ha_t
*ha
) { 1702 #ifndef NO_IPS_CMDLINE 1704 * Send passthru commands 1705 * These have priority over normal I/O 1706 * but shouldn't affect performance too much 1707 * since we limit the number that can be active 1708 * on the card at any one time 1710 while((ha
->num_ioctl
< IPS_MAX_IOCTL
) && 1711 (ha
->copp_waitlist
.head
) && 1712 (scb
=ips_getscb(ha
))) { 1713 SC
=ips_removeq_wait_head(&ha
->copp_waitlist
); 1715 ret
=ips_make_passthru(ha
, SC
, scb
); 1720 scb
->scsi_cmd
->result
= DID_ERROR
<<16; 1721 scb
->scsi_cmd
->scsi_done(scb
->scsi_cmd
); 1723 ips_freescb(ha
, scb
); 1725 case IPS_SUCCESS_IMM
: 1727 scb
->scsi_cmd
->scsi_done(scb
->scsi_cmd
); 1728 ips_freescb(ha
, scb
); 1734 if(ret
!= IPS_SUCCESS
) 1737 ret
=ips_send_cmd(ha
, scb
); 1739 if(ret
== IPS_SUCCESS
) { 1740 ips_putq_scb_head(&ha
->scb_activelist
, scb
); 1747 scb
->scsi_cmd
->result
= DID_ERROR
<<16; 1748 scb
->scsi_cmd
->scsi_done(scb
->scsi_cmd
); 1751 ips_freescb(ha
, scb
); 1753 case IPS_SUCCESS_IMM
: 1755 scb
->scsi_cmd
->scsi_done(scb
->scsi_cmd
); 1756 ips_freescb(ha
, scb
); 1765 * Send "Normal" I/O commands 1767 while((ha
->scb_waitlist
.head
) && 1768 (scb
=ips_getscb(ha
))) { 1769 SC
=ips_removeq_wait_head(&ha
->scb_waitlist
); 1771 SC
->result
= DID_OK
; 1772 SC
->host_scribble
= NULL
; 1774 memset(SC
->sense_buffer
,0,sizeof(SC
->sense_buffer
)); 1776 scb
->target_id
= SC
->target
; 1778 scb
->bus
= SC
->channel
; 1782 scb
->callback
= ipsintr_done
; 1783 scb
->timeout
= ips_cmd_timeout
; 1784 memset(&scb
->cmd
,0,4); 1786 /* copy in the CDB */ 1787 memcpy(scb
->cdb
, SC
->cmnd
, SC
->cmd_len
); 1789 /* Now handle the data buffer */ 1791 struct scatterlist
*sg
; 1794 sg
= SC
->request_buffer
; 1796 for(i
=0; i
< SC
->use_sg
; i
++) { 1797 scb
->sg_list
[i
].address
=VIRT_TO_BUS(sg
[i
].address
); 1798 scb
->sg_list
[i
].length
= sg
[i
].length
; 1800 if(scb
->data_len
+ sg
[i
].length
> ha
->max_xfer
) { 1802 * Data Breakup required 1808 scb
->data_len
+= sg
[i
].length
; 1812 scb
->sg_len
= SC
->use_sg
; 1814 scb
->sg_len
= scb
->breakup
; 1816 scb
->dcdb
.transfer_length
= scb
->data_len
; 1817 scb
->data_busaddr
=VIRT_TO_BUS(scb
->sg_list
); 1819 if(SC
->request_bufflen
) { 1820 if(SC
->request_bufflen
> ha
->max_xfer
) { 1822 * Data breakup required 1825 scb
->data_len
= ha
->max_xfer
; 1827 scb
->data_len
= SC
->request_bufflen
; 1830 scb
->dcdb
.transfer_length
= scb
->data_len
; 1831 scb
->data_busaddr
=VIRT_TO_BUS(SC
->request_buffer
); 1834 scb
->data_busaddr
=0L; 1837 scb
->dcdb
.transfer_length
=0; 1842 if((scb
->scsi_cmd
->request
.cmd
== READ
) && (SC
->request_bufflen
)) 1843 scb
->dcdb
.cmd_attribute
|= DATA_IN
; 1845 if((scb
->scsi_cmd
->request
.cmd
== WRITE
) && (SC
->request_bufflen
)) 1846 scb
->dcdb
.cmd_attribute
|= DATA_OUT
; 1848 if(scb
->data_len
>= IPS_MAX_XFER
) { 1849 scb
->dcdb
.cmd_attribute
|= TRANSFER_64K
; 1850 scb
->dcdb
.transfer_length
=0; 1853 ret
=ips_send_cmd(ha
, scb
); 1855 if(ret
== IPS_SUCCESS
) 1856 ips_putq_scb_head(&ha
->scb_activelist
, scb
); 1861 scb
->scsi_cmd
->result
= DID_ERROR
<<16; 1862 scb
->scsi_cmd
->scsi_done(scb
->scsi_cmd
); 1865 ips_freescb(ha
, scb
); 1867 case IPS_SUCCESS_IMM
: 1869 scb
->scsi_cmd
->scsi_done(scb
->scsi_cmd
); 1870 ips_freescb(ha
, scb
); 1878 /****************************************************************************/ 1880 /* Routine Name: ips_putq_scb_head */ 1882 /* Routine Description: */ 1884 /* Add an item to the head of the queue */ 1886 /* ASSUMED to be called from within a lock */ 1888 /****************************************************************************/ 1890 ips_putq_scb_head(ips_scb_queue_t
*queue
, ips_scb_t
*item
) { 1891 DBG("ips_putq_scb_head"); 1896 item
->q_next
= queue
->head
; 1905 /****************************************************************************/ 1907 /* Routine Name: ips_putq_scb_tail */ 1909 /* Routine Description: */ 1911 /* Add an item to the tail of the queue */ 1913 /* ASSUMED to be called from within a lock */ 1915 /****************************************************************************/ 1917 ips_putq_scb_tail(ips_scb_queue_t
*queue
, ips_scb_t
*item
) { 1918 DBG("ips_putq_scb_tail"); 1923 item
->q_next
= NULL
; 1926 queue
->tail
->q_next
= item
; 1936 /****************************************************************************/ 1938 /* Routine Name: ips_removeq_scb_head */ 1940 /* Routine Description: */ 1942 /* Remove the head of the queue */ 1944 /* ASSUMED to be called from within a lock */ 1946 /****************************************************************************/ 1947 staticinline ips_scb_t
* 1948 ips_removeq_scb_head(ips_scb_queue_t
*queue
) { 1951 DBG("ips_removeq_scb_head"); 1958 queue
->head
= item
->q_next
; 1959 item
->q_next
= NULL
; 1961 if(queue
->tail
== item
) 1969 /****************************************************************************/ 1971 /* Routine Name: ips_removeq_scb */ 1973 /* Routine Description: */ 1975 /* Remove an item from a queue */ 1977 /* ASSUMED to be called from within a lock */ 1979 /****************************************************************************/ 1980 staticinline ips_scb_t
* 1981 ips_removeq_scb(ips_scb_queue_t
*queue
, ips_scb_t
*item
) { 1984 DBG("ips_removeq_scb"); 1989 if(item
== queue
->head
) 1990 return(ips_removeq_scb_head(queue
)); 1994 while((p
) && (item
!= p
->q_next
)) 1999 p
->q_next
= item
->q_next
; 2004 item
->q_next
= NULL
; 2013 /****************************************************************************/ 2015 /* Routine Name: ips_putq_wait_head */ 2017 /* Routine Description: */ 2019 /* Add an item to the head of the queue */ 2021 /* ASSUMED to be called from within a lock */ 2023 /****************************************************************************/ 2025 ips_putq_wait_head(ips_wait_queue_t
*queue
, Scsi_Cmnd
*item
) { 2026 DBG("ips_putq_wait_head"); 2031 item
->host_scribble
= (char*) queue
->head
; 2040 /****************************************************************************/ 2042 /* Routine Name: ips_putq_wait_tail */ 2044 /* Routine Description: */ 2046 /* Add an item to the tail of the queue */ 2048 /* ASSUMED to be called from within a lock */ 2050 /****************************************************************************/ 2052 ips_putq_wait_tail(ips_wait_queue_t
*queue
, Scsi_Cmnd
*item
) { 2053 DBG("ips_putq_wait_tail"); 2058 item
->host_scribble
= NULL
; 2061 queue
->tail
->host_scribble
= (char*)item
; 2071 /****************************************************************************/ 2073 /* Routine Name: ips_removeq_wait_head */ 2075 /* Routine Description: */ 2077 /* Remove the head of the queue */ 2079 /* ASSUMED to be called from within a lock */ 2081 /****************************************************************************/ 2082 staticinline Scsi_Cmnd
* 2083 ips_removeq_wait_head(ips_wait_queue_t
*queue
) { 2086 DBG("ips_removeq_wait_head"); 2093 queue
->head
= (Scsi_Cmnd
*) item
->host_scribble
; 2094 item
->host_scribble
= NULL
; 2096 if(queue
->tail
== item
) 2104 /****************************************************************************/ 2106 /* Routine Name: ips_removeq_wait */ 2108 /* Routine Description: */ 2110 /* Remove an item from a queue */ 2112 /* ASSUMED to be called from within a lock */ 2114 /****************************************************************************/ 2115 staticinline Scsi_Cmnd
* 2116 ips_removeq_wait(ips_wait_queue_t
*queue
, Scsi_Cmnd
*item
) { 2119 DBG("ips_removeq_wait"); 2124 if(item
== queue
->head
) 2125 return(ips_removeq_wait_head(queue
)); 2129 while((p
) && (item
!= (Scsi_Cmnd
*) p
->host_scribble
)) 2130 p
= (Scsi_Cmnd
*) p
->host_scribble
; 2134 p
->host_scribble
= item
->host_scribble
; 2136 if(!item
->host_scribble
) 2139 item
->host_scribble
= NULL
; 2148 /****************************************************************************/ 2150 /* Routine Name: ipsintr_blocking */ 2152 /* Routine Description: */ 2154 /* Finalize an interrupt for internal commands */ 2156 /****************************************************************************/ 2158 ipsintr_blocking(ips_ha_t
*ha
, ips_scb_t
*scb
) { 2159 DBG("ipsintr_blocking"); 2161 if((ha
->waitflag
== TRUE
) && 2162 (ha
->cmd_in_progress
== scb
->cdb
[0])) { 2163 ha
->waitflag
= FALSE
; 2169 /****************************************************************************/ 2171 /* Routine Name: ipsintr_done */ 2173 /* Routine Description: */ 2175 /* Finalize an interrupt for non-internal commands */ 2177 /****************************************************************************/ 2179 ipsintr_done(ips_ha_t
*ha
, ips_scb_t
*scb
) { 2180 DBG("ipsintr_done"); 2182 if(scb
->scsi_cmd
== NULL
) { 2183 /* unexpected interrupt */ 2184 printk(KERN_WARNING
"(%s%d) Spurious interrupt; scsi_cmd not set.\n", 2185 ips_name
, ha
->host_num
); 2193 /****************************************************************************/ 2195 /* Routine Name: ips_done */ 2197 /* Routine Description: */ 2199 /* Do housekeeping on completed commands */ 2201 /****************************************************************************/ 2203 ips_done(ips_ha_t
*ha
, ips_scb_t
*scb
) { 2211 #ifndef NO_IPS_CMDLINE 2212 if((scb
->scsi_cmd
) && (ips_is_passthru(scb
->scsi_cmd
))) { 2213 ips_cleanup_passthru(scb
); 2218 * Check to see if this command had too much 2219 * data and had to be broke up. If so, queue 2220 * the rest of the data and continue. 2223 /* we had a data breakup */ 2226 bk_save
= scb
->breakup
; 2229 if(scb
->scsi_cmd
->use_sg
) { 2231 struct scatterlist
*sg
; 2234 sg
= scb
->scsi_cmd
->request_buffer
; 2238 for(i
= bk_save
; i
< scb
->scsi_cmd
->use_sg
; i
++) { 2239 scb
->sg_list
[i
- bk_save
].address
=VIRT_TO_BUS(sg
[i
].address
); 2240 scb
->sg_list
[i
- bk_save
].length
= sg
[i
].length
; 2242 if(scb
->data_len
+ sg
[i
].length
> ha
->max_xfer
) { 2244 * Data Breakup required 2250 scb
->data_len
+= sg
[i
].length
; 2254 scb
->sg_len
= scb
->scsi_cmd
->use_sg
- bk_save
; 2256 scb
->sg_len
= scb
->breakup
- bk_save
; 2258 scb
->dcdb
.transfer_length
= scb
->data_len
; 2259 scb
->data_busaddr
=VIRT_TO_BUS(scb
->sg_list
); 2261 /* Non S/G Request */ 2262 if(scb
->scsi_cmd
->request_bufflen
- (bk_save
* ha
->max_xfer
)) { 2263 /* Further breakup required */ 2264 scb
->data_len
= ha
->max_xfer
; 2265 scb
->data_busaddr
=VIRT_TO_BUS(scb
->scsi_cmd
->request_buffer
+ (bk_save
* ha
->max_xfer
)); 2266 scb
->breakup
= bk_save
+1; 2268 scb
->data_len
= scb
->scsi_cmd
->request_bufflen
- (bk_save
* ha
->max_xfer
); 2269 scb
->data_busaddr
=VIRT_TO_BUS(scb
->scsi_cmd
->request_buffer
+ (bk_save
* ha
->max_xfer
)); 2272 scb
->dcdb
.transfer_length
= scb
->data_len
; 2276 if((scb
->scsi_cmd
->request
.cmd
== READ
) && (scb
->data_len
)) 2277 scb
->dcdb
.cmd_attribute
|= DATA_IN
; 2279 if((scb
->scsi_cmd
->request
.cmd
== WRITE
) && (scb
->data_len
)) 2280 scb
->dcdb
.cmd_attribute
|= DATA_OUT
; 2282 if(scb
->data_len
>= IPS_MAX_XFER
) { 2283 scb
->dcdb
.cmd_attribute
|= TRANSFER_64K
; 2284 scb
->dcdb
.transfer_length
=0; 2287 ret
=ips_send_cmd(ha
, scb
); 2292 scb
->scsi_cmd
->result
= DID_ERROR
<<16; 2293 scb
->scsi_cmd
->scsi_done(scb
->scsi_cmd
); 2296 ips_freescb(ha
, scb
); 2298 case IPS_SUCCESS_IMM
: 2300 scb
->scsi_cmd
->result
= DID_ERROR
<<16; 2301 scb
->scsi_cmd
->scsi_done(scb
->scsi_cmd
); 2304 ips_freescb(ha
, scb
); 2312 #ifndef NO_IPS_CMDLINE 2313 }/* end if passthru */ 2316 /* call back to SCSI layer */ 2317 scb
->scsi_cmd
->scsi_done(scb
->scsi_cmd
); 2318 ips_freescb(ha
, scb
); 2320 /* do the next command */ 2324 /****************************************************************************/ 2326 /* Routine Name: ips_map_status */ 2328 /* Routine Description: */ 2330 /* Map ServeRAID error codes to Linux Error Codes */ 2332 /****************************************************************************/ 2334 ips_map_status(ips_scb_t
*scb
, ips_stat_t
*sp
) { 2337 DBG("ips_map_status"); 2340 /* copy SCSI status and sense data for DCDB commands */ 2341 memcpy(scb
->scsi_cmd
->sense_buffer
, scb
->dcdb
.sense_info
, 2342 sizeof(scb
->scsi_cmd
->sense_buffer
)); 2343 scb
->scsi_cmd
->result
= scb
->dcdb
.scsi_status
; 2345 scb
->scsi_cmd
->result
=0; 2347 /* default driver error */ 2348 errcode
= DID_ERROR
; 2350 switch(scb
->basic_status
& GSC_STATUS_MASK
) { 2352 errcode
= DID_TIME_OUT
; 2357 case INVAL_PARM_BLK
: 2359 case CMD_CMPLT_WERROR
: 2362 case PHYS_DRV_ERROR
: 2364 * For physical drive errors that 2365 * are not on a logical drive should 2366 * be DID_OK. The SCSI errcode will 2367 * show what the real error is. 2372 switch(scb
->extended_status
) { 2373 case SELECTION_TIMEOUT
: 2375 scb
->scsi_cmd
->result
|= DID_TIME_OUT
<<16; 2380 case DATA_OVER_UNDER_RUN
: 2381 if((scb
->bus
) && (scb
->dcdb
.transfer_length
< scb
->data_len
)) { 2382 if((scb
->scsi_cmd
->cmnd
[0] == INQUIRY
) && 2383 ((((char*) scb
->scsi_cmd
->buffer
)[0] &0x1f) == TYPE_DISK
)) { 2384 /* underflow -- no error */ 2385 /* restrict access to physical DASD */ 2386 errcode
= DID_TIME_OUT
; 2390 /* normal underflow Occured */ 2391 if(scb
->dcdb
.transfer_length
>= scb
->scsi_cmd
->underflow
) { 2392 scb
->scsi_cmd
->result
|= DID_OK
<<16; 2400 /* don't fail recovered errors */ 2402 scb
->scsi_cmd
->result
|= DID_OK
<<16; 2408 case EXT_HOST_RESET
: 2409 case EXT_DEVICE_RESET
: 2410 errcode
= DID_RESET
; 2413 case EXT_CHECK_CONDITION
: 2418 scb
->scsi_cmd
->result
|= (errcode
<<16); 2423 /****************************************************************************/ 2425 /* Routine Name: ips_send */ 2427 /* Routine Description: */ 2429 /* Wrapper for ips_send_cmd */ 2431 /****************************************************************************/ 2433 ips_send(ips_ha_t
*ha
, ips_scb_t
*scb
, scb_callback callback
) { 2438 scb
->callback
= callback
; 2440 ret
=ips_send_cmd(ha
, scb
); 2445 /****************************************************************************/ 2447 /* Routine Name: ips_send_wait */ 2449 /* Routine Description: */ 2451 /* Send a command to the controller and wait for it to return */ 2453 /****************************************************************************/ 2455 ips_send_wait(ips_ha_t
*ha
, ips_scb_t
*scb
,int timeout
) { 2458 DBG("ips_send_wait"); 2460 ha
->waitflag
= TRUE
; 2461 ha
->cmd_in_progress
= scb
->cdb
[0]; 2463 ret
=ips_send(ha
, scb
, ipsintr_blocking
); 2465 if((ret
== IPS_FAILURE
) || (ret
== IPS_SUCCESS_IMM
)) 2468 ret
=ips_wait(ha
, timeout
, IPS_INTR_OFF
); 2473 /****************************************************************************/ 2475 /* Routine Name: ips_send_cmd */ 2477 /* Routine Description: */ 2479 /* Map SCSI commands to ServeRAID commands for logical drives */ 2481 /****************************************************************************/ 2483 ips_send_cmd(ips_ha_t
*ha
, ips_scb_t
*scb
) { 2486 DBG("ips_send_cmd"); 2490 if(!scb
->scsi_cmd
) { 2491 /* internal command */ 2494 /* ServeRAID commands can't be issued */ 2495 /* to real devices -- fail them */ 2496 if((ha
->waitflag
== TRUE
) && 2497 (ha
->cmd_in_progress
== scb
->cdb
[0])) { 2498 ha
->waitflag
= FALSE
; 2503 #ifndef NO_IPS_CMDLINE 2504 }else if((scb
->bus
==0) && (!ips_is_passthru(scb
->scsi_cmd
))) { 2506 }else if(scb
->bus
==0) { 2508 /* command to logical bus -- interpret */ 2509 ret
= IPS_SUCCESS_IMM
; 2511 switch(scb
->scsi_cmd
->cmnd
[0]) { 2512 case ALLOW_MEDIUM_REMOVAL
: 2515 case WRITE_FILEMARKS
: 2517 scb
->scsi_cmd
->result
= DID_ERROR
<<16; 2521 scb
->scsi_cmd
->result
= DID_OK
<<16; 2523 case TEST_UNIT_READY
: 2525 if(scb
->target_id
== IPS_ADAPTER_ID
) { 2527 * Either we have a TUR 2528 * or we have a SCSI inquiry 2530 if(scb
->scsi_cmd
->cmnd
[0] == TEST_UNIT_READY
) 2531 scb
->scsi_cmd
->result
= DID_OK
<<16; 2533 if(scb
->scsi_cmd
->cmnd
[0] == INQUIRY
) { 2536 memset(&inq
,0,sizeof(INQUIRYDATA
)); 2538 inq
.DeviceType
= TYPE_PROCESSOR
; 2539 inq
.DeviceTypeQualifier
=0; 2540 inq
.RemoveableMedia
=0; 2541 inq
.Versions
=0x1;/* SCSI I */ 2542 inq
.AdditionalLength
=31; 2543 strncpy(inq
.VendorId
,"IBM ",8); 2544 strncpy(inq
.ProductId
,"SERVERAID ",16); 2545 strncpy(inq
.ProductRevisionLevel
,"1.00",4); 2547 memcpy(scb
->scsi_cmd
->request_buffer
, &inq
, scb
->scsi_cmd
->request_bufflen
); 2549 scb
->scsi_cmd
->result
= DID_OK
<<16; 2552 scb
->cmd
.logical_info
.op_code
= GET_LOGICAL_DRIVE_INFO
; 2553 scb
->cmd
.logical_info
.command_id
=IPS_COMMAND_ID(ha
, scb
); 2554 scb
->cmd
.logical_info
.buffer_addr
=VIRT_TO_BUS(&ha
->adapt
->logical_drive_info
); 2555 scb
->cmd
.logical_info
.reserved
=0; 2556 scb
->cmd
.logical_info
.reserved2
=0; 2563 ips_reqsen(ha
, scb
); 2564 scb
->scsi_cmd
->result
= DID_OK
<<16; 2570 scb
->cmd
.basic_io
.op_code
= 2571 (scb
->scsi_cmd
->cmnd
[0] == READ_6
) ? IPS_READ
: IPS_WRITE
; 2573 scb
->cmd
.basic_io
.op_code
= 2574 (scb
->scsi_cmd
->cmnd
[0] == READ_6
) ? READ_SCATTER_GATHER
: WRITE_SCATTER_GATHER
; 2577 scb
->cmd
.basic_io
.command_id
=IPS_COMMAND_ID(ha
, scb
); 2578 scb
->cmd
.basic_io
.log_drv
= scb
->target_id
; 2579 scb
->cmd
.basic_io
.sg_count
= scb
->sg_len
; 2580 scb
->cmd
.basic_io
.sg_addr
= scb
->data_busaddr
; 2582 if(scb
->cmd
.basic_io
.lba
) 2583 scb
->cmd
.basic_io
.lba
+= scb
->cmd
.basic_io
.sector_count
; 2585 scb
->cmd
.basic_io
.lba
= (((scb
->scsi_cmd
->cmnd
[1] &0x1f) <<16) | 2586 (scb
->scsi_cmd
->cmnd
[2] <<8) | 2587 (scb
->scsi_cmd
->cmnd
[3])); 2589 scb
->cmd
.basic_io
.sector_count
= scb
->data_len
/ IPS_BLKSIZE
; 2591 if(scb
->cmd
.basic_io
.sector_count
==0) 2592 scb
->cmd
.basic_io
.sector_count
=256; 2594 scb
->cmd
.basic_io
.reserved
=0; 2601 scb
->cmd
.basic_io
.op_code
= 2602 (scb
->scsi_cmd
->cmnd
[0] == READ_10
) ? IPS_READ
: IPS_WRITE
; 2604 scb
->cmd
.basic_io
.op_code
= 2605 (scb
->scsi_cmd
->cmnd
[0] == READ_10
) ? READ_SCATTER_GATHER
: WRITE_SCATTER_GATHER
; 2608 scb
->cmd
.basic_io
.command_id
=IPS_COMMAND_ID(ha
, scb
); 2609 scb
->cmd
.basic_io
.log_drv
= scb
->target_id
; 2610 scb
->cmd
.basic_io
.sg_count
= scb
->sg_len
; 2611 scb
->cmd
.basic_io
.sg_addr
= scb
->data_busaddr
; 2613 if(scb
->cmd
.basic_io
.lba
) 2614 scb
->cmd
.basic_io
.lba
+= scb
->cmd
.basic_io
.sector_count
; 2616 scb
->cmd
.basic_io
.lba
= ((scb
->scsi_cmd
->cmnd
[2] <<24) | 2617 (scb
->scsi_cmd
->cmnd
[3] <<16) | 2618 (scb
->scsi_cmd
->cmnd
[4] <<8) | 2619 scb
->scsi_cmd
->cmnd
[5]); 2621 scb
->cmd
.basic_io
.sector_count
= scb
->data_len
/ IPS_BLKSIZE
; 2623 scb
->cmd
.basic_io
.reserved
=0; 2625 if(scb
->cmd
.basic_io
.sector_count
==0) { 2627 * This is a null condition 2628 * we don't have to do anything 2631 scb
->scsi_cmd
->result
= DID_OK
<<16; 2639 scb
->scsi_cmd
->result
= DID_OK
<<16; 2643 scb
->cmd
.basic_io
.op_code
= ENQUIRY
; 2644 scb
->cmd
.basic_io
.command_id
=IPS_COMMAND_ID(ha
, scb
); 2645 scb
->cmd
.basic_io
.sg_addr
=VIRT_TO_BUS(ha
->enq
); 2650 scb
->cmd
.logical_info
.op_code
= GET_LOGICAL_DRIVE_INFO
; 2651 scb
->cmd
.logical_info
.command_id
=IPS_COMMAND_ID(ha
, scb
); 2652 scb
->cmd
.logical_info
.buffer_addr
=VIRT_TO_BUS(&ha
->adapt
->logical_drive_info
); 2653 scb
->cmd
.logical_info
.reserved
=0; 2654 scb
->cmd
.logical_info
.reserved2
=0; 2655 scb
->cmd
.logical_info
.reserved3
=0; 2659 case SEND_DIAGNOSTIC
: 2660 case REASSIGN_BLOCKS
: 2664 case READ_DEFECT_DATA
: 2667 scb
->scsi_cmd
->result
= DID_OK
<<16; 2671 scb
->scsi_cmd
->result
= DID_ERROR
<<16; 2676 if(ret
== IPS_SUCCESS_IMM
) 2682 scb
->cmd
.dcdb
.op_code
= DIRECT_CDB
; 2684 scb
->cmd
.dcdb
.op_code
= DIRECT_CDB_SCATTER_GATHER
; 2686 scb
->cmd
.dcdb
.command_id
=IPS_COMMAND_ID(ha
, scb
); 2687 scb
->cmd
.dcdb
.dcdb_address
=VIRT_TO_BUS(&scb
->dcdb
); 2688 scb
->cmd
.dcdb
.reserved
=0; 2689 scb
->cmd
.dcdb
.reserved2
=0; 2690 scb
->cmd
.dcdb
.reserved3
=0; 2692 scb
->dcdb
.device_address
= ((scb
->bus
-1) <<4) | scb
->target_id
; 2693 scb
->dcdb
.cmd_attribute
|= DISCONNECT_ALLOWED
; 2696 if(scb
->timeout
<=10) 2697 scb
->dcdb
.cmd_attribute
|= TIMEOUT_10
; 2698 else if(scb
->timeout
<=60) 2699 scb
->dcdb
.cmd_attribute
|= TIMEOUT_60
; 2701 scb
->dcdb
.cmd_attribute
|= TIMEOUT_20M
; 2704 if(!(scb
->dcdb
.cmd_attribute
& TIMEOUT_20M
)) 2705 scb
->dcdb
.cmd_attribute
|= TIMEOUT_20M
; 2707 scb
->dcdb
.sense_length
=sizeof(scb
->scsi_cmd
->sense_buffer
); 2708 scb
->dcdb
.buffer_pointer
= scb
->data_busaddr
; 2709 scb
->dcdb
.sg_count
= scb
->sg_len
; 2710 scb
->dcdb
.cdb_length
= scb
->scsi_cmd
->cmd_len
; 2711 memcpy(scb
->dcdb
.scsi_cdb
, scb
->scsi_cmd
->cmnd
, scb
->scsi_cmd
->cmd_len
); 2714 return(ips_issue(ha
, scb
)); 2717 /****************************************************************************/ 2719 /* Routine Name: ips_chk_status */ 2721 /* Routine Description: */ 2723 /* Check the status of commands to logical drives */ 2725 /****************************************************************************/ 2727 ips_chkstatus(ips_ha_t
*ha
) { 2729 ips_stat_t
*sp
= &ha
->sp
; 2736 DBG("ips_chkstatus"); 2738 command_id
=ips_statupd(ha
); 2740 if(command_id
> (MAX_CMDS
-1)) { 2741 printk(KERN_NOTICE
"(%s%d) invalid command id received: %d\n", 2742 ips_name
, ha
->host_num
, command_id
); 2747 scb
= &ha
->scbs
[command_id
]; 2748 sp
->scb_addr
= (u32
) scb
; 2750 scb
->basic_status
= basic_status
= ha
->adapt
->p_status_tail
->basic_status
& BASIC_STATUS_MASK
; 2751 scb
->extended_status
= ext_status
= ha
->adapt
->p_status_tail
->extended_status
; 2753 /* Remove the item from the active queue */ 2754 ips_removeq_scb(&ha
->scb_activelist
, scb
); 2757 /* internal commands are handled in do_ipsintr */ 2760 #ifndef NO_IPS_CMDLINE 2761 if((scb
->scsi_cmd
) && (ips_is_passthru(scb
->scsi_cmd
))) 2762 /* passthru - just returns the raw result */ 2769 if(((basic_status
& GSC_STATUS_MASK
) == SSUCCESS
) || 2770 ((basic_status
& GSC_STATUS_MASK
) == RECOVERED_ERROR
)) { 2774 if((basic_status
& GSC_STATUS_MASK
) == RECOVERED_ERROR
) { 2775 printk(KERN_NOTICE
"(%s%d) Recovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x\n", 2776 ips_name
, ha
->host_num
, 2777 scb
->cmd
.basic_io
.op_code
, basic_status
, ext_status
); 2781 switch(scb
->scsi_cmd
->cmnd
[0]) { 2782 case ALLOW_MEDIUM_REMOVAL
: 2785 case WRITE_FILEMARKS
: 2787 errcode
= DID_ERROR
; 2794 case TEST_UNIT_READY
: 2795 if(!ips_online(ha
, scb
)) { 2796 errcode
= DID_TIME_OUT
; 2802 if(ips_online(ha
, scb
)) { 2803 ips_inquiry(ha
, scb
); 2805 errcode
= DID_TIME_OUT
; 2811 ips_reqsen(ha
, scb
); 2823 if(!ips_online(ha
, scb
) || !ips_msense(ha
, scb
)) { 2824 errcode
= DID_ERROR
; 2830 if(ips_online(ha
, scb
)) 2833 errcode
= DID_TIME_OUT
; 2838 case SEND_DIAGNOSTIC
: 2839 case REASSIGN_BLOCKS
: 2843 errcode
= DID_ERROR
; 2849 case READ_DEFECT_DATA
: 2855 errcode
= DID_ERROR
; 2859 scb
->scsi_cmd
->result
= errcode
<<16; 2860 }else{/* bus == 0 */ 2861 /* restrict access to physical drives */ 2862 if((scb
->scsi_cmd
->cmnd
[0] == INQUIRY
) && 2863 ((((char*) scb
->scsi_cmd
->buffer
)[0] &0x1f) == TYPE_DISK
)) { 2865 scb
->scsi_cmd
->result
= DID_TIME_OUT
<<16; 2870 }else{/* recovered error / success */ 2873 printk(KERN_NOTICE
"(%s%d) Unrecovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x\n", 2874 ips_name
, ha
->host_num
, 2875 scb
->cmd
.basic_io
.op_code
, basic_status
, ext_status
); 2879 ret
=ips_map_status(scb
, sp
); 2885 /****************************************************************************/ 2887 /* Routine Name: ips_online */ 2889 /* Routine Description: */ 2891 /* Determine if a logical drive is online */ 2893 /****************************************************************************/ 2895 ips_online(ips_ha_t
*ha
, ips_scb_t
*scb
) { 2898 if(scb
->target_id
>= MAX_LOGICAL_DRIVES
) 2901 if((scb
->basic_status
& GSC_STATUS_MASK
) >1) { 2902 memset(&ha
->adapt
->logical_drive_info
,0,sizeof(ha
->adapt
->logical_drive_info
)); 2907 if(scb
->target_id
< ha
->adapt
->logical_drive_info
.no_of_log_drive
&& 2908 ha
->adapt
->logical_drive_info
.drive_info
[scb
->target_id
].state
!= OFF_LINE
&& 2909 ha
->adapt
->logical_drive_info
.drive_info
[scb
->target_id
].state
!= FREE
&& 2910 ha
->adapt
->logical_drive_info
.drive_info
[scb
->target_id
].state
!= CRS
&& 2911 ha
->adapt
->logical_drive_info
.drive_info
[scb
->target_id
].state
!= SYS
) 2917 /****************************************************************************/ 2919 /* Routine Name: ips_inquiry */ 2921 /* Routine Description: */ 2923 /* Simulate an inquiry command to a logical drive */ 2925 /****************************************************************************/ 2927 ips_inquiry(ips_ha_t
*ha
, ips_scb_t
*scb
) { 2932 memset(&inq
,0,sizeof(INQUIRYDATA
)); 2934 inq
.DeviceType
= TYPE_DISK
; 2935 inq
.DeviceTypeQualifier
=0; 2936 inq
.RemoveableMedia
=0; 2937 inq
.Versions
=0x1;/* SCSI I */ 2938 inq
.AdditionalLength
=31; 2939 strncpy(inq
.VendorId
,"IBM ",8); 2940 strncpy(inq
.ProductId
,"SERVERAID ",16); 2941 strncpy(inq
.ProductRevisionLevel
,"1.00",4); 2943 memcpy(scb
->scsi_cmd
->request_buffer
, &inq
, scb
->scsi_cmd
->request_bufflen
); 2948 /****************************************************************************/ 2950 /* Routine Name: ips_rdcap */ 2952 /* Routine Description: */ 2954 /* Simulate a read capacity command to a logical drive */ 2956 /****************************************************************************/ 2958 ips_rdcap(ips_ha_t
*ha
, ips_scb_t
*scb
) { 2963 if(scb
->scsi_cmd
->bufflen
<8) 2966 cap
= (CAPACITY_T
*) scb
->scsi_cmd
->request_buffer
; 2968 cap
->lba
=htonl(ha
->adapt
->logical_drive_info
.drive_info
[scb
->target_id
].sector_count
-1); 2969 cap
->len
=htonl((u32
) IPS_BLKSIZE
); 2974 /****************************************************************************/ 2976 /* Routine Name: ips_msense */ 2978 /* Routine Description: */ 2980 /* Simulate a mode sense command to a logical drive */ 2982 /****************************************************************************/ 2984 ips_msense(ips_ha_t
*ha
, ips_scb_t
*scb
) { 2992 if(ha
->enq
->ulDriveSize
[scb
->target_id
] >0x400000&& 2993 (ha
->enq
->ucMiscFlag
&0x8) ==0) { 2994 heads
= NORM_MODE_HEADS
; 2995 sectors
= NORM_MODE_SECTORS
; 2997 heads
= COMP_MODE_HEADS
; 2998 sectors
= COMP_MODE_SECTORS
; 3001 cylinders
= ha
->enq
->ulDriveSize
[scb
->target_id
] / (heads
* sectors
); 3003 mdata
.plh
.plh_type
=0; 3004 mdata
.plh
.plh_wp
=0; 3005 mdata
.plh
.plh_bdl
=8; 3007 switch(scb
->scsi_cmd
->cmnd
[2] &0x3f) { 3008 case0x03:/* page 3 */ 3009 mdata
.pdata
.pg3
.pg_pc
=0x3; 3010 mdata
.pdata
.pg3
.pg_res1
=0; 3011 mdata
.pdata
.pg3
.pg_len
=sizeof(DADF_T
); 3012 mdata
.plh
.plh_len
=3+ mdata
.plh
.plh_bdl
+ mdata
.pdata
.pg3
.pg_len
; 3013 mdata
.pdata
.pg3
.pg_trk_z
=0; 3014 mdata
.pdata
.pg3
.pg_asec_z
=0; 3015 mdata
.pdata
.pg3
.pg_atrk_z
=0; 3016 mdata
.pdata
.pg3
.pg_atrk_v
=0; 3017 mdata
.pdata
.pg3
.pg_sec_t
=htons(sectors
); 3018 mdata
.pdata
.pg3
.pg_bytes_s
=htons(IPS_BLKSIZE
); 3019 mdata
.pdata
.pg3
.pg_intl
=htons(1); 3020 mdata
.pdata
.pg3
.pg_trkskew
=0; 3021 mdata
.pdata
.pg3
.pg_cylskew
=0; 3022 mdata
.pdata
.pg3
.pg_res2
=0; 3023 mdata
.pdata
.pg3
.pg_ins
=0; 3024 mdata
.pdata
.pg3
.pg_surf
=0; 3025 mdata
.pdata
.pg3
.pg_rmb
=0; 3026 mdata
.pdata
.pg3
.pg_hsec
=0; 3027 mdata
.pdata
.pg3
.pg_ssec
=1; 3031 mdata
.pdata
.pg4
.pg_pc
=0x4; 3032 mdata
.pdata
.pg4
.pg_res1
=0; 3033 mdata
.pdata
.pg4
.pg_len
=sizeof(RDDG_T
); 3034 mdata
.plh
.plh_len
=3+ mdata
.plh
.plh_bdl
+ mdata
.pdata
.pg4
.pg_len
; 3035 mdata
.pdata
.pg4
.pg_cylu
= (cylinders
>>8) &0xffff; 3036 mdata
.pdata
.pg4
.pg_cyll
= cylinders
&0xff; 3037 mdata
.pdata
.pg4
.pg_head
= heads
; 3038 mdata
.pdata
.pg4
.pg_wrpcompu
=0; 3039 mdata
.pdata
.pg4
.pg_wrpcompl
=0; 3040 mdata
.pdata
.pg4
.pg_redwrcur
=0; 3041 mdata
.pdata
.pg4
.pg_drstep
=htons(1); 3042 mdata
.pdata
.pg4
.pg_landu
=0; 3043 mdata
.pdata
.pg4
.pg_landl
=0; 3044 mdata
.pdata
.pg4
.pg_res2
=0; 3050 memcpy(scb
->scsi_cmd
->request_buffer
, &mdata
, scb
->scsi_cmd
->request_bufflen
); 3055 /****************************************************************************/ 3057 /* Routine Name: ips_reqsen */ 3059 /* Routine Description: */ 3061 /* Simulate a request sense command to a logical drive */ 3063 /****************************************************************************/ 3065 ips_reqsen(ips_ha_t
*ha
, ips_scb_t
*scb
) { 3070 sp
= (char*) scb
->scsi_cmd
->sense_buffer
; 3071 memset(sp
,0,sizeof(scb
->scsi_cmd
->sense_buffer
)); 3081 /****************************************************************************/ 3083 /* Routine Name: ips_free */ 3085 /* Routine Description: */ 3087 /* Free any allocated space for this controller */ 3089 /****************************************************************************/ 3091 ips_free(ips_ha_t
*ha
) { 3128 for(i
=0; i
< ha
->max_cmds
; i
++) { 3129 if(ha
->scbs
[i
].sg_list
) 3130 kfree(ha
->scbs
[i
].sg_list
); 3139 /****************************************************************************/ 3141 /* Routine Name: ips_allocatescbs */ 3143 /* Routine Description: */ 3145 /* Allocate the command blocks */ 3147 /****************************************************************************/ 3149 ips_allocatescbs(ips_ha_t
*ha
) { 3153 DBG("ips_allocatescbs"); 3155 /* Allocate memory for the CCBs */ 3156 ha
->scbs
= (ips_scb_t
*)kmalloc(ha
->max_cmds
*sizeof(ips_scb_t
), GFP_KERNEL
|GFP_DMA
); 3158 memset(ha
->scbs
,0, ha
->max_cmds
*sizeof(ips_scb_t
)); 3160 for(i
=0; i
< ha
->max_cmds
; i
++) { 3161 scb_p
= &ha
->scbs
[i
]; 3163 /* allocate S/G list */ 3164 scb_p
->sg_list
= (SG_LIST
*)kmalloc(sizeof(SG_LIST
) * MAX_SG_ELEMENTS
, GFP_KERNEL
|GFP_DMA
); 3166 if(! scb_p
->sg_list
) 3169 /* add to the free list */ 3170 if(i
< ha
->max_cmds
-1) { 3171 scb_p
->q_next
= ha
->scb_freelist
; 3172 ha
->scb_freelist
= scb_p
; 3180 /****************************************************************************/ 3182 /* Routine Name: ips_init_scb */ 3184 /* Routine Description: */ 3186 /* Initialize a CCB to default values */ 3188 /****************************************************************************/ 3190 ips_init_scb(ips_ha_t
*ha
, ips_scb_t
*scb
) { 3193 DBG("ips_init_scb"); 3198 sg_list
= scb
->sg_list
; 3201 memset(scb
,0,sizeof(ips_scb_t
)); 3202 memset(ha
->dummy
,0,sizeof(BASIC_IO_CMD
)); 3204 /* Initialize dummy command bucket */ 3205 ha
->dummy
->op_code
=0xFF; 3206 ha
->dummy
->ccsar
=VIRT_TO_BUS(ha
->dummy
); 3207 ha
->dummy
->command_id
= MAX_CMDS
; 3209 /* set bus address of scb */ 3210 scb
->scb_busaddr
=VIRT_TO_BUS(scb
); 3211 scb
->sg_list
= sg_list
; 3214 scb
->cmd
.basic_io
.cccr
= ILE
; 3215 scb
->cmd
.basic_io
.ccsar
=VIRT_TO_BUS(ha
->dummy
); 3218 /****************************************************************************/ 3220 /* Routine Name: ips_get_scb */ 3222 /* Routine Description: */ 3224 /* Initialize a CCB to default values */ 3226 /* ASSUMED to be callled from within a lock */ 3228 /****************************************************************************/ 3230 ips_getscb(ips_ha_t
*ha
) { 3232 unsigned int cpu_flags
; 3236 spin_lock_irqsave(&ha
->scb_lock
, cpu_flags
); 3237 if((scb
= ha
->scb_freelist
) == NULL
) { 3238 spin_unlock_irqrestore(&ha
->scb_lock
, cpu_flags
); 3243 ha
->scb_freelist
= scb
->q_next
; 3246 spin_unlock_irqrestore(&ha
->scb_lock
, cpu_flags
); 3248 ips_init_scb(ha
, scb
); 3253 /****************************************************************************/ 3255 /* Routine Name: ips_free_scb */ 3257 /* Routine Description: */ 3259 /* Return an unused CCB back to the free list */ 3261 /* ASSUMED to be called from within a lock */ 3263 /****************************************************************************/ 3265 ips_freescb(ips_ha_t
*ha
, ips_scb_t
*scb
) { 3266 unsigned int cpu_flags
; 3270 /* check to make sure this is not our "special" scb */ 3271 if(IPS_COMMAND_ID(ha
, scb
) < (ha
->max_cmds
-1)) { 3272 spin_lock_irqsave(&ha
->scb_lock
, cpu_flags
); 3273 scb
->q_next
= ha
->scb_freelist
; 3274 ha
->scb_freelist
= scb
; 3275 spin_unlock_irqrestore(&ha
->scb_lock
, cpu_flags
); 3279 /****************************************************************************/ 3281 /* Routine Name: ips_reset_adapter */ 3283 /* Routine Description: */ 3285 /* Reset the controller */ 3287 /****************************************************************************/ 3289 ips_reset_adapter(ips_ha_t
*ha
) { 3292 u8 PostByte
[MAX_POST_BYTES
]; 3293 u8 ConfigByte
[MAX_CONFIG_BYTES
]; 3297 DBG("ips_reset_adapter"); 3300 printk(KERN_WARNING
"ips_reset_adapter: io addr: %x, irq: %d\n", 3301 ha
->io_addr
, ha
->irq
); 3306 while(reset_counter
<2) { 3309 outb(RST
, ha
->io_addr
+ SCPR
); 3311 outb(0, ha
->io_addr
+ SCPR
); 3314 for(i
=0; i
< MAX_POST_BYTES
; i
++) { 3315 for(j
=0; j
<45; j
++) { 3316 Isr
=inb(ha
->io_addr
+ HISR
); 3325 if(reset_counter
<2) 3332 PostByte
[i
] =inb(ha
->io_addr
+ ISPR
); 3333 outb(Isr
, ha
->io_addr
+ HISR
); 3336 if(PostByte
[0] < GOOD_POST_BASIC_STATUS
) { 3337 printk("(%s%d) reset controller fails (post status %x %x).\n", 3338 ips_name
, ha
->host_num
, PostByte
[0], PostByte
[1]); 3343 for(i
=0; i
< MAX_CONFIG_BYTES
; i
++) { 3344 for(j
=0; j
<240; j
++) { 3345 Isr
=inb(ha
->io_addr
+ HISR
); 3349 MDELAY(ONE_SEC
);/* 100 msec */ 3354 if(reset_counter
<2) 3361 ConfigByte
[i
] =inb(ha
->io_addr
+ ISPR
); 3362 outb(Isr
, ha
->io_addr
+ HISR
); 3365 if(ConfigByte
[0] ==0&& ConfigByte
[1] ==2) { 3366 printk("(%s%d) reset controller fails (status %x %x).\n", 3367 ips_name
, ha
->host_num
, ConfigByte
[0], ConfigByte
[1]); 3372 for(i
=0; i
<240; i
++) { 3373 Cbsp
=inb(ha
->io_addr
+ CBSP
); 3383 if(reset_counter
<2) 3391 outw(0x1010, ha
->io_addr
+ CCCR
); 3393 /* Enable busmastering */ 3394 outb(EBM
, ha
->io_addr
+ SCPR
); 3396 /* setup status queues */ 3399 /* Enable interrupts */ 3400 outb(EI
, ha
->io_addr
+ HISR
); 3402 /* if we get here then everything went OK */ 3409 /****************************************************************************/ 3411 /* Routine Name: ips_statinit */ 3413 /* Routine Description: */ 3415 /* Initialize the status queues on the controller */ 3417 /****************************************************************************/ 3419 ips_statinit(ips_ha_t
*ha
) { 3420 u32 phys_status_start
; 3422 DBG("ips_statinit"); 3424 ha
->adapt
->p_status_start
= ha
->adapt
->status
; 3425 ha
->adapt
->p_status_end
= ha
->adapt
->status
+ MAX_CMDS
; 3426 ha
->adapt
->p_status_tail
= ha
->adapt
->status
; 3428 phys_status_start
=VIRT_TO_BUS(ha
->adapt
->status
); 3429 outl(phys_status_start
, ha
->io_addr
+ SQSR
); 3430 outl(phys_status_start
+ STATUS_Q_SIZE
, ha
->io_addr
+ SQER
); 3431 outl(phys_status_start
+ STATUS_SIZE
, ha
->io_addr
+ SQHR
); 3432 outl(phys_status_start
, ha
->io_addr
+ SQTR
); 3434 ha
->adapt
->hw_status_start
= phys_status_start
; 3435 ha
->adapt
->hw_status_tail
= phys_status_start
; 3438 /****************************************************************************/ 3440 /* Routine Name: ips_statupd */ 3442 /* Routine Description: */ 3444 /* Remove an element from the status queue */ 3446 /****************************************************************************/ 3448 ips_statupd(ips_ha_t
*ha
) { 3453 if(ha
->adapt
->p_status_tail
!= ha
->adapt
->p_status_end
) { 3454 ha
->adapt
->p_status_tail
++; 3455 ha
->adapt
->hw_status_tail
+=sizeof(STATUS
); 3457 ha
->adapt
->p_status_tail
= ha
->adapt
->p_status_start
; 3458 ha
->adapt
->hw_status_tail
= ha
->adapt
->hw_status_start
; 3461 outl(ha
->adapt
->hw_status_tail
, ha
->io_addr
+ SQTR
); 3463 command_id
= ha
->adapt
->p_status_tail
->command_id
; 3468 /****************************************************************************/ 3470 /* Routine Name: ips_issue */ 3472 /* Routine Description: */ 3474 /* Send a command down to the controller */ 3476 /* ASSUMED to be called from within a lock */ 3478 /****************************************************************************/ 3480 ips_issue(ips_ha_t
*ha
, ips_scb_t
*scb
) { 3488 printk(KERN_NOTICE
"%s: ips_issue: cmd 0x%X id %d (%d %d %d)\n", 3491 scb
->cmd
.basic_io
.command_id
, 3496 printk(KERN_NOTICE
"%s: ips_issue: logical cmd id %d\n", 3498 scb
->cmd
.basic_io
.command_id
); 3506 while((val
=inw(ha
->io_addr
+ CCCR
)) & SEMAPHORE
) { 3509 if(++TimeOut
>= SEMAPHORE_TIMEOUT
) { 3510 if(!(val
& START_STOP_BIT
)) 3513 printk(KERN_WARNING
"(%s%d) ips_issue val [0x%x].\n", 3514 ips_name
, ha
->host_num
, val
); 3515 printk(KERN_WARNING
"(%s%d) ips_issue semaphore chk timeout.\n", 3516 ips_name
, ha
->host_num
); 3518 return(IPS_FAILURE
); 3522 outl(scb
->scb_busaddr
, ha
->io_addr
+ CCSAR
); 3523 outw(START_COMMAND
, ha
->io_addr
+ CCCR
); 3525 return(IPS_SUCCESS
); 3528 /****************************************************************************/ 3530 /* Routine Name: ips_isintr */ 3532 /* Routine Description: */ 3534 /* Test to see if an interrupt is for us */ 3536 /****************************************************************************/ 3538 ips_isintr(ips_ha_t
*ha
) { 3543 Isr
=inb(ha
->io_addr
+ HISR
); 3546 /* ?!?! Nothing really there */ 3551 else if(Isr
& (SQO
| GHI
)) { 3552 /* status queue overflow or GHI */ 3553 /* just clear the interrupt */ 3554 outb(Isr
, ha
->io_addr
+ HISR
); 3560 /****************************************************************************/ 3562 /* Routine Name: ips_wait */ 3564 /* Routine Description: */ 3566 /* Wait for a command to complete */ 3568 /****************************************************************************/ 3570 ips_wait(ips_ha_t
*ha
,int time
,int intr
) { 3577 time
*= ONE_SEC
;/* convert seconds to milliseconds */ 3580 if(intr
== IPS_INTR_OFF
) { 3581 if(ha
->waitflag
== FALSE
) { 3583 * controller generated an interupt to 3584 * acknowledge completion of the command 3585 * and ips_intr() has serviced the interrupt. 3592 * NOTE: Interrupts are disabled here 3593 * On an SMP system interrupts will only 3594 * be disabled on one processor. 3595 * So, ultimately we still need to set the 3596 * "I'm in the interrupt handler flag" 3598 while(test_and_set_bit(IPS_IN_INTR
, &ha
->flags
)) 3603 clear_bit(IPS_IN_INTR
, &ha
->flags
); 3606 if(ha
->waitflag
== FALSE
) { 3612 UDELAY(1000);/* 1 milisecond */ 3619 /****************************************************************************/ 3621 /* Routine Name: ips_write_driver_status */ 3623 /* Routine Description: */ 3625 /* Write OS/Driver version to Page 5 of the nvram on the controller */ 3627 /****************************************************************************/ 3629 ips_write_driver_status(ips_ha_t
*ha
) { 3630 DBG("ips_write_driver_status"); 3632 if(!ips_readwrite_page5(ha
, FALSE
)) { 3633 printk(KERN_WARNING
"(%s%d) unable to read NVRAM page 5.\n", 3634 ips_name
, ha
->host_num
); 3639 /* check to make sure the page has a valid */ 3641 if(ha
->nvram
->signature
!= NVRAM_PAGE5_SIGNATURE
) { 3643 printk("(%s%d) NVRAM page 5 has an invalid signature: %X.\n", 3644 ips_name
, ha
->host_num
, ha
->nvram
->signature
); 3650 printk("(%s%d) Ad Type: %d, Ad Slot: %d, BIOS: %c%c%c%c %c%c%c%c.\n", 3651 ips_name
, ha
->host_num
, ha
->nvram
->adapter_type
, ha
->nvram
->adapter_slot
, 3652 ha
->nvram
->bios_high
[0], ha
->nvram
->bios_high
[1], 3653 ha
->nvram
->bios_high
[2], ha
->nvram
->bios_high
[3], 3654 ha
->nvram
->bios_low
[0], ha
->nvram
->bios_low
[1], 3655 ha
->nvram
->bios_low
[2], ha
->nvram
->bios_low
[3]); 3658 /* save controller type */ 3659 ha
->ad_type
= ha
->nvram
->adapter_type
; 3661 /* change values (as needed) */ 3662 ha
->nvram
->operating_system
= OS_LINUX
; 3663 strncpy((char*) ha
->nvram
->driver_high
, IPS_VERSION_HIGH
,4); 3664 strncpy((char*) ha
->nvram
->driver_low
, IPS_VERSION_LOW
,4); 3666 /* now update the page */ 3667 if(!ips_readwrite_page5(ha
, TRUE
)) { 3668 printk(KERN_WARNING
"(%s%d) unable to write NVRAM page 5.\n", 3669 ips_name
, ha
->host_num
); 3677 /****************************************************************************/ 3679 /* Routine Name: ips_read_adapter_status */ 3681 /* Routine Description: */ 3683 /* Do an Inquiry command to the adapter */ 3685 /****************************************************************************/ 3687 ips_read_adapter_status(ips_ha_t
*ha
) { 3691 DBG("ips_read_adapter_status"); 3693 scb
= &ha
->scbs
[ha
->max_cmds
-1]; 3695 ips_init_scb(ha
, scb
); 3697 scb
->timeout
= ips_cmd_timeout
; 3698 scb
->cdb
[0] = ENQUIRY
; 3700 scb
->cmd
.basic_io
.op_code
= ENQUIRY
; 3701 scb
->cmd
.basic_io
.command_id
=IPS_COMMAND_ID(ha
, scb
); 3702 scb
->cmd
.basic_io
.sg_count
=0; 3703 scb
->cmd
.basic_io
.sg_addr
=VIRT_TO_BUS(ha
->enq
); 3704 scb
->cmd
.basic_io
.lba
=0; 3705 scb
->cmd
.basic_io
.sector_count
=0; 3706 scb
->cmd
.basic_io
.log_drv
=0; 3707 scb
->cmd
.basic_io
.reserved
=0; 3710 ret
=ips_send_wait(ha
, scb
, ips_cmd_timeout
); 3711 if((ret
== IPS_FAILURE
) || (ret
== IPS_SUCCESS_IMM
)) 3717 /****************************************************************************/ 3719 /* Routine Name: ips_read_subsystem_parameters */ 3721 /* Routine Description: */ 3723 /* Read subsystem parameters from the adapter */ 3725 /****************************************************************************/ 3727 ips_read_subsystem_parameters(ips_ha_t
*ha
) { 3731 DBG("ips_read_subsystem_parameters"); 3733 scb
= &ha
->scbs
[ha
->max_cmds
-1]; 3735 ips_init_scb(ha
, scb
); 3737 scb
->timeout
= ips_cmd_timeout
; 3738 scb
->cdb
[0] = GET_SUBSYS_PARAM
; 3740 scb
->cmd
.basic_io
.op_code
= GET_SUBSYS_PARAM
; 3741 scb
->cmd
.basic_io
.command_id
=IPS_COMMAND_ID(ha
, scb
); 3742 scb
->cmd
.basic_io
.sg_count
=0; 3743 scb
->cmd
.basic_io
.sg_addr
=VIRT_TO_BUS(ha
->subsys
); 3744 scb
->cmd
.basic_io
.lba
=0; 3745 scb
->cmd
.basic_io
.sector_count
=0; 3746 scb
->cmd
.basic_io
.log_drv
=0; 3747 scb
->cmd
.basic_io
.reserved
=0; 3750 ret
=ips_send_wait(ha
, scb
, ips_cmd_timeout
); 3751 if((ret
== IPS_FAILURE
) || (ret
== IPS_SUCCESS_IMM
)) 3757 /****************************************************************************/ 3759 /* Routine Name: ips_read_config */ 3761 /* Routine Description: */ 3763 /* Read the configuration on the adapter */ 3765 /****************************************************************************/ 3767 ips_read_config(ips_ha_t
*ha
) { 3772 DBG("ips_read_config"); 3774 /* set defaults for initiator IDs */ 3775 ha
->conf
->init_id
[0] = IPS_ADAPTER_ID
; 3776 for(i
=1; i
<4; i
++) 3777 ha
->conf
->init_id
[i
] =7; 3779 scb
= &ha
->scbs
[ha
->max_cmds
-1]; 3781 ips_init_scb(ha
, scb
); 3783 scb
->timeout
= ips_cmd_timeout
; 3784 scb
->cdb
[0] = READ_NVRAM_CONFIGURATION
; 3786 scb
->cmd
.basic_io
.op_code
= READ_NVRAM_CONFIGURATION
; 3787 scb
->cmd
.basic_io
.command_id
=IPS_COMMAND_ID(ha
, scb
); 3788 scb
->cmd
.basic_io
.sg_addr
=VIRT_TO_BUS(ha
->conf
); 3791 if(((ret
=ips_send_wait(ha
, scb
, ips_cmd_timeout
)) == IPS_FAILURE
) || 3792 (ret
== IPS_SUCCESS_IMM
) || 3793 ((scb
->basic_status
& GSC_STATUS_MASK
) >1)) { 3795 memset(ha
->conf
,0,sizeof(CONFCMD
)); 3797 /* reset initiator IDs */ 3798 ha
->conf
->init_id
[0] = IPS_ADAPTER_ID
; 3799 for(i
=1; i
<4; i
++) 3800 ha
->conf
->init_id
[i
] =7; 3808 /****************************************************************************/ 3810 /* Routine Name: ips_readwrite_page5 */ 3812 /* Routine Description: */ 3814 /* Read the configuration on the adapter */ 3816 /****************************************************************************/ 3818 ips_readwrite_page5(ips_ha_t
*ha
,int write
) { 3822 DBG("ips_readwrite_page5"); 3824 scb
= &ha
->scbs
[ha
->max_cmds
-1]; 3826 ips_init_scb(ha
, scb
); 3828 scb
->timeout
= ips_cmd_timeout
; 3829 scb
->cdb
[0] = RW_NVRAM_PAGE
; 3831 scb
->cmd
.nvram
.op_code
= RW_NVRAM_PAGE
; 3832 scb
->cmd
.nvram
.command_id
=IPS_COMMAND_ID(ha
, scb
); 3833 scb
->cmd
.nvram
.page
=5; 3834 scb
->cmd
.nvram
.write
= write
; 3835 scb
->cmd
.nvram
.buffer_addr
=VIRT_TO_BUS(ha
->nvram
); 3836 scb
->cmd
.nvram
.reserved
=0; 3837 scb
->cmd
.nvram
.reserved2
=0; 3839 /* issue the command */ 3840 if(((ret
=ips_send_wait(ha
, scb
, ips_cmd_timeout
)) == IPS_FAILURE
) || 3841 (ret
== IPS_SUCCESS_IMM
) || 3842 ((scb
->basic_status
& GSC_STATUS_MASK
) >1)) { 3844 memset(ha
->nvram
,0,sizeof(NVRAM_PAGE5
)); 3852 /****************************************************************************/ 3854 /* Routine Name: ips_clear_adapter */ 3856 /* Routine Description: */ 3858 /* Clear the stripe lock tables */ 3860 /****************************************************************************/ 3862 ips_clear_adapter(ips_ha_t
*ha
) { 3866 DBG("ips_clear_adapter"); 3868 scb
= &ha
->scbs
[ha
->max_cmds
-1]; 3870 ips_init_scb(ha
, scb
); 3872 scb
->timeout
= ips_reset_timeout
; 3873 scb
->cdb
[0] = CONFIG_SYNC
; 3875 scb
->cmd
.config_sync
.op_code
= CONFIG_SYNC
; 3876 scb
->cmd
.config_sync
.command_id
=IPS_COMMAND_ID(ha
, scb
); 3877 scb
->cmd
.config_sync
.channel
=0; 3878 scb
->cmd
.config_sync
.source_target
= POCL
; 3879 scb
->cmd
.config_sync
.reserved
=0; 3880 scb
->cmd
.config_sync
.reserved2
=0; 3881 scb
->cmd
.config_sync
.reserved3
=0; 3884 ret
=ips_send_wait(ha
, scb
, ips_reset_timeout
); 3885 if((ret
== IPS_FAILURE
) || (ret
== IPS_SUCCESS_IMM
)) 3888 /* send unlock stripe command */ 3889 ips_init_scb(ha
, scb
); 3891 scb
->cdb
[0] = GET_ERASE_ERROR_TABLE
; 3892 scb
->timeout
= ips_reset_timeout
; 3894 scb
->cmd
.unlock_stripe
.op_code
= GET_ERASE_ERROR_TABLE
; 3895 scb
->cmd
.unlock_stripe
.command_id
=IPS_COMMAND_ID(ha
, scb
); 3896 scb
->cmd
.unlock_stripe
.log_drv
=0; 3897 scb
->cmd
.unlock_stripe
.control
= CSL
; 3898 scb
->cmd
.unlock_stripe
.reserved
=0; 3899 scb
->cmd
.unlock_stripe
.reserved2
=0; 3900 scb
->cmd
.unlock_stripe
.reserved3
=0; 3903 ret
=ips_send_wait(ha
, scb
, ips_reset_timeout
); 3904 if((ret
== IPS_FAILURE
) || (ret
== IPS_SUCCESS_IMM
)) 3910 #if defined (MODULE) 3912 Scsi_Host_Template driver_template
= IPS
; 3914 #include"scsi_module.c" 3920 * Overrides for Emacs so that we almost follow Linus's tabbing style. 3921 * Emacs will notice this stuff at the end of the file and automatically 3922 * adjust the settings for this buffer only. This must remain at the end 3924 * --------------------------------------------------------------------------- 3927 * c-brace-imaginary-offset: 0 3928 * c-brace-offset: -2 3929 * c-argdecl-indent: 2 3930 * c-label-offset: -2 3931 * c-continued-statement-offset: 2 3932 * c-continued-brace-offset: 0 3933 * indent-tabs-mode: nil