1 /*****************************************************************************/
2 /* ips.h -- driver for the IBM ServeRAID adapter */
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 /*****************************************************************************/
50 #include <linux/config.h>
51 #include <asm/uaccess.h>
55 extern int ips_detect(Scsi_Host_Template
*);
56 extern int ips_release(struct Scsi_Host
*);
57 extern int ips_abort(Scsi_Cmnd
*);
58 extern int ips_reset(Scsi_Cmnd
*, unsigned int);
59 extern int ips_eh_abort(Scsi_Cmnd
*);
60 extern int ips_eh_reset(Scsi_Cmnd
*);
61 extern int ips_queue(Scsi_Cmnd
*, void (*) (Scsi_Cmnd
*));
62 extern int ips_biosparam(Disk
*, kdev_t
, int *);
63 extern const char * ips_info(struct Scsi_Host
*);
64 extern void do_ipsintr(int, void *, struct pt_regs
*);
69 #ifndef LinuxVersionCode
70 #define LinuxVersionCode(x,y,z) (((x)<<16)+((y)<<8)+(z))
73 #define HA(x) ((ips_ha_t *) x->hostdata)
74 #define IPS_COMMAND_ID(ha, scb) (int) (scb - ha->scbs)
75 #define VIRT_TO_BUS(x) (unsigned int)virt_to_bus((void *) x)
80 #define verify_area_20(t,a,sz) (0) /* success */
81 #define PUT_USER put_user
82 #define __PUT_USER __put_user
83 #define PUT_USER_RET put_user_ret
84 #define GET_USER get_user
85 #define __GET_USER __get_user
86 #define GET_USER_RET get_user_ret
89 * Adapter address map equates
91 #define HISR 0x08 /* Host Interrupt Status Reg */
92 #define CCSAR 0x10 /* Cmd Channel System Addr Reg */
93 #define CCCR 0x14 /* Cmd Channel Control Reg */
94 #define SQHR 0x20 /* Status Q Head Reg */
95 #define SQTR 0x24 /* Status Q Tail Reg */
96 #define SQER 0x28 /* Status Q End Reg */
97 #define SQSR 0x2C /* Status Q Start Reg */
98 #define SCPR 0x05 /* Subsystem control port reg */
99 #define ISPR 0x06 /* interrupt status port reg */
100 #define CBSP 0x07 /* CBSP register */
103 * Adapter register bit equates
105 #define GHI 0x04 /* HISR General Host Interrupt */
106 #define SQO 0x02 /* HISR Status Q Overflow */
107 #define SCE 0x01 /* HISR Status Channel Enqueue */
108 #define SEMAPHORE 0x08 /* CCCR Semaphore Bit */
109 #define ILE 0x10 /* CCCR ILE Bit */
110 #define START_COMMAND 0x101A /* CCCR Start Command Channel */
111 #define START_STOP_BIT 0x0002 /* CCCR Start/Stop Bit */
112 #define RST 0x80 /* SCPR Reset Bit */
113 #define EBM 0x02 /* SCPR Enable Bus Master */
114 #define EI 0x80 /* HISR Enable Interrupts */
115 #define OP 0x01 /* OP bit in CBSP */
118 * Adapter Command ID Equates
120 #define GET_LOGICAL_DRIVE_INFO 0x19
121 #define GET_SUBSYS_PARAM 0x40
122 #define READ_NVRAM_CONFIGURATION 0x38
123 #define RW_NVRAM_PAGE 0xBC
124 #define IPS_READ 0x02
125 #define IPS_WRITE 0x03
127 #define FLUSH_CACHE 0x0A
128 #define NORM_STATE 0x00
129 #define READ_SCATTER_GATHER 0x82
130 #define WRITE_SCATTER_GATHER 0x83
131 #define DIRECT_CDB 0x04
132 #define DIRECT_CDB_SCATTER_GATHER 0x84
133 #define CONFIG_SYNC 0x58
135 #define GET_ERASE_ERROR_TABLE 0x17
136 #define RESET_CHANNEL 0x1A
138 #define ADAPT_RESET 0xFF
143 #define IPS_MAX_ADAPTERS 16
144 #define IPS_MAX_IOCTL 1
145 #define IPS_MAX_IOCTL_QUEUE 8
146 #define IPS_MAX_QUEUE 128
147 #define IPS_BLKSIZE 512
148 #define MAX_SG_ELEMENTS 17
149 #define MAX_LOGICAL_DRIVES 8
150 #define MAX_CHANNELS 3
151 #define MAX_TARGETS 15
152 #define MAX_CHUNKS 16
154 #define IPS_MAX_XFER 0x10000
155 #define COMP_MODE_HEADS 128
156 #define COMP_MODE_SECTORS 32
157 #define NORM_MODE_HEADS 254
158 #define NORM_MODE_SECTORS 63
159 #define NVRAM_PAGE5_SIGNATURE 0xFFDDBB99
160 #define MAX_POST_BYTES 0x02
161 #define MAX_CONFIG_BYTES 0x02
162 #define GOOD_POST_BASIC_STATUS 0x80
163 #define SEMAPHORE_TIMEOUT 2000
164 #define IPS_INTR_OFF 0
165 #define IPS_INTR_ON 1
166 #define IPS_ADAPTER_ID 0xF
167 #define IPS_VENDORID 0x1014
168 #define IPS_DEVICEID 0x002E
169 #define TIMEOUT_10 0x10
170 #define TIMEOUT_60 0x20
171 #define TIMEOUT_20M 0x30
172 #define STATUS_SIZE 4
173 #define STATUS_Q_SIZE (MAX_CMDS+1) * STATUS_SIZE
178 * Adapter Basic Status Codes
180 #define BASIC_STATUS_MASK 0xFF
181 #define GSC_STATUS_MASK 0x0F
182 #define SSUCCESS 0x00
183 #define RECOVERED_ERROR 0x01
184 #define IPS_CHECK_CONDITION 0x02
185 #define INVAL_OPCO 0x03
186 #define INVAL_CMD_BLK 0x04
187 #define INVAL_PARM_BLK 0x05
188 #define IPS_BUSY 0x08
189 #define ADAPT_HARDWARE_ERROR 0x09
190 #define ADAPT_FIRMWARE_ERROR 0x0A
191 #define CMD_CMPLT_WERROR 0x0C
192 #define LOG_DRV_ERROR 0x0D
193 #define CMD_TIMEOUT 0x0E
194 #define PHYS_DRV_ERROR 0x0F
197 * Adapter Extended Status Equates
199 #define SELECTION_TIMEOUT 0xF0
200 #define DATA_OVER_UNDER_RUN 0xF2
201 #define EXT_HOST_RESET 0xF7
202 #define EXT_DEVICE_RESET 0xF8
203 #define EXT_RECOVERY 0xFC
204 #define EXT_CHECK_CONDITION 0xFF
207 * Operating System Defines
209 #define OS_WINDOWS_NT 0x01
210 #define OS_NETWARE 0x02
211 #define OS_OPENSERVER 0x03
212 #define OS_UNIXWARE 0x04
213 #define OS_SOLARIS 0x05
215 #define OS_LINUX 0x07
216 #define OS_FREEBSD 0x08
219 * Adapter Command/Status Packet Definitions
221 #define IPS_SUCCESS 0x01 /* Successfully completed */
222 #define IPS_SUCCESS_IMM 0x02 /* Success - Immediately */
223 #define IPS_FAILURE 0x04 /* Completed with Error */
226 * Logical Drive Equates
228 #define OFF_LINE 0x02
237 #define NO_DISCONNECT 0x00
238 #define DISCONNECT_ALLOWED 0x80
239 #define NO_AUTO_REQUEST_SENSE 0x40
241 #define DATA_OUT 0x02
242 #define TRANSFER_64K 0x08
243 #define NOTIMEOUT 0x00
244 #define TIMEOUT10 0x10
245 #define TIMEOUT60 0x20
246 #define TIMEOUT20M 0x30
249 * Host adapter Flags (bit numbers)
251 #define IPS_IN_INTR 0
252 #define IPS_IN_ABORT 1
253 #define IPS_IN_RESET 2
258 #define SCB_ACTIVE 0x00001
259 #define SCB_WAITING 0x00002
264 #define COPPUSRCMD (('C'<<8) | 65)
265 #define IPS_NUMCTRLS (('C'<<8) | 68)
266 #define IPS_CTRLINFO (('C'<<8) | 69)
277 detect : ips_detect, \
278 release : ips_release, \
281 queuecommand : ips_queue, \
282 eh_strategy_handler : NULL, \
283 eh_abort_handler : ips_eh_abort, \
284 eh_device_reset_handler : NULL, \
285 eh_bus_reset_handler : NULL, \
286 eh_host_reset_handler : ips_eh_reset, \
289 slave_attach : NULL, \
290 bios_param : ips_biosparam, \
293 sg_tablesize : MAX_SG_ELEMENTS, \
296 unchecked_isa_dma : 0, \
297 use_clustering : ENABLE_CLUSTERING, \
298 use_new_eh_code : 1 \
302 * IBM PCI Raid Command Formats
315 } BASIC_IO_CMD
, *PBASIC_IO_CMD
;
326 } LOGICAL_INFO
, *PLOGICAL_INFO
;
336 } IOCTL_INFO
, *PIOCTL_INFO
;
347 } DCDB_CMD
, *PDCDB_CMD
;
359 } CONFIG_SYNC_CMD
, *PCONFIG_SYNC_CMD
;
371 } UNLOCK_STRIPE_CMD
, *PUNLOCK_STRIPE_CMD
;
383 } FLUSH_CACHE_CMD
, *PFLUSH_CACHE_CMD
;
395 } STATUS_CMD
, *PSTATUS_CMD
;
407 } NVRAM_CMD
, *PNVRAM_CMD
;
410 BASIC_IO_CMD basic_io
;
411 LOGICAL_INFO logical_info
;
412 IOCTL_INFO ioctl_info
;
414 CONFIG_SYNC_CMD config_sync
;
415 UNLOCK_STRIPE_CMD unlock_stripe
;
416 FLUSH_CACHE_CMD flush_cache
;
419 } HOST_COMMAND
, *PHOST_COMMAND
;
427 } DRIVE_INFO
, *PDRIVE_INFO
;
432 DRIVE_INFO drive_info
[MAX_LOGICAL_DRIVES
];
433 } LOGICAL_DRIVE_INFO
, *PLOGICAL_DRIVE_INFO
;
445 } NON_DISK_DEVICE_INFO
, *PNON_DISK_DEVICE_INFO
;
460 } DCDB_TABLE
, *PDCDB_TABLE
;
463 volatile u8 reserved
;
464 volatile u8 command_id
;
465 volatile u8 basic_status
;
466 volatile u8 extended_status
;
470 STATUS status
[MAX_CMDS
+ 1];
471 volatile PSTATUS p_status_start
;
472 volatile PSTATUS p_status_end
;
473 volatile PSTATUS p_status_tail
;
474 volatile u32 hw_status_start
;
475 volatile u32 hw_status_tail
;
476 LOGICAL_DRIVE_INFO logical_drive_info
;
477 } ADAPTER_AREA
, *PADAPTER_AREA
;
488 u8 CodeBlkVersion
[8];
489 u8 BootBlkVersion
[8];
490 u32 ulDriveSize
[MAX_LOGICAL_DRIVES
];
491 u8 ucConcurrentCmdCount
;
492 u8 ucMaxPhysicalDevices
;
493 u16 usFlashRepgmCount
;
494 u8 ucDefunctDiskCount
;
496 u8 ucOfflineLogDrvCount
;
497 u8 ucCriticalDrvCount
;
498 u16 usConfigUpdateCount
;
501 u16 usAddrDeadDisk
[MAX_CHANNELS
* MAX_TARGETS
];
511 } DEVSTATE
, *PDEVSTATE
;
530 CHUNK chunk
[MAX_CHUNKS
];
531 } LOGICAL_DRIVE
, *PLOGICAL_DRIVE
;
541 } HARDWARE_DISC
, *PHARDWARE_DISC
;
553 u32 usCfgDrvUpdateCnt
:16;
554 u32 ConcurDrvStartCnt
:4;
556 u32 auto_rearrange
:1;
565 HARDWARE_DISC hardware_disc
;
566 LOGICAL_DRIVE logical_drive
[MAX_LOGICAL_DRIVES
];
567 DEVSTATE dev
[MAX_CHANNELS
][MAX_TARGETS
+1];
570 } CONFCMD
, *PCONFCMD
;
585 } NVRAM_PAGE5
, *PNVRAM_PAGE5
;
587 typedef struct _SUBSYS_PARAM
{
589 } SUBSYS_PARAM
, *PSUBSYS_PARAM
;
592 * Inquiry Data Format
596 u8 DeviceTypeQualifier
:3;
597 u8 DeviceTypeModifier
:7;
598 u8 RemoveableMedia
:1;
600 u8 ResponseDataFormat
;
610 u8 RelativeAddressing
:1;
613 u8 ProductRevisionLevel
[4];
614 u8 VendorSpecific
[20];
616 } INQUIRYDATA
, *PINQUIRYDATA
;
619 * Read Capacity Data Format
630 u8 pg_pc
:6; /* Page Code */
631 u8 pg_res1
:2; /* Reserved */
632 u8 pg_len
; /* Page Length */
633 u16 pg_trk_z
; /* Tracks per zone */
634 u16 pg_asec_z
; /* Alternate sectors per zone */
635 u16 pg_atrk_z
; /* Alternate tracks per zone */
636 u16 pg_atrk_v
; /* Alternate tracks per volume */
637 u16 pg_sec_t
; /* Sectors per track */
638 u16 pg_bytes_s
; /* Bytes per physical sectors */
639 u16 pg_intl
; /* Interleave */
640 u16 pg_trkskew
; /* Track skew factor */
641 u16 pg_cylskew
; /* Cylinder Skew Factor */
642 u32 pg_res2
:27; /* Reserved */
643 u32 pg_ins
:1; /* Inhibit Slave */
644 u32 pg_surf
:1; /* Allocate Surface Sectors */
645 u32 pg_rmb
:1; /* Removeable */
646 u32 pg_hsec
:1; /* Hard sector formatting */
647 u32 pg_ssec
:1; /* Soft sector formatting */
651 u8 pg_pc
:6; /* Page Code */
652 u8 pg_res1
:2; /* Reserved */
653 u8 pg_len
; /* Page Length */
654 u16 pg_cylu
; /* Number of cylinders (upper) */
655 u8 pg_cyll
; /* Number of cylinders (lower) */
656 u8 pg_head
; /* Number of heads */
657 u16 pg_wrpcompu
; /* Write precomp (upper) */
658 u32 pg_wrpcompl
:8; /* Write precomp (lower) */
659 u32 pg_redwrcur
:24; /* Reduced write current */
660 u32 pg_drstep
:16; /* Drive step rate */
661 u32 pg_landu
:16; /* Landing zone cylinder (upper) */
662 u32 pg_landl
:8; /* Landing zone cylinder (lower) */
663 u32 pg_res2
:24; /* Reserved */
678 u8 plh_len
; /* Data length */
679 u8 plh_type
; /* Medium type */
680 u8 plh_res
:7; /* Reserved */
681 u8 plh_wp
:1; /* Write protect */
682 u8 plh_bdl
; /* Block descriptor length */
687 struct blk_desc blk_desc
;
696 * Scatter Gather list format
698 typedef struct ips_sglist
{
701 } SG_LIST
, *PSG_LIST
;
703 typedef struct _INFOSTR
{
713 typedef struct ips_stat
{
721 typedef struct ips_scb_queue
{
722 struct ips_scb
*head
;
723 struct ips_scb
*tail
;
730 typedef struct ips_wait_queue
{
736 typedef struct ips_ha
{
737 u8 ha_id
[MAX_CHANNELS
+1];
738 u32 io_addr
; /* Base I/O address */
739 u8 irq
; /* IRQ for adapter */
740 u8 ntargets
; /* Number of targets */
741 u8 nbus
; /* Number of buses */
742 u8 nlun
; /* Number of Luns */
743 u16 ad_type
; /* Adapter type */
744 u16 host_num
; /* Adapter number */
745 u32 max_xfer
; /* Maximum Xfer size */
746 u32 max_cmds
; /* Max concurrent commands */
747 u32 num_ioctl
; /* Number of Ioctls */
748 ips_stat_t sp
; /* Status packer pointer */
749 struct ips_scb
*scbs
; /* Array of all CCBS */
750 struct ips_scb
*scb_freelist
; /* SCB free list */
751 ips_wait_queue_t scb_waitlist
; /* Pending SCB list */
752 ips_wait_queue_t copp_waitlist
; /* Pending PT list */
753 ips_scb_queue_t scb_activelist
; /* Active SCB list */
754 BASIC_IO_CMD
*dummy
; /* dummy command */
755 ADAPTER_AREA
*adapt
; /* Adapter status area */
756 ENQCMD
*enq
; /* Adapter Enquiry data */
757 CONFCMD
*conf
; /* Adapter config data */
758 NVRAM_PAGE5
*nvram
; /* NVRAM page 5 data */
759 SUBSYS_PARAM
*subsys
; /* Subsystem parameters */
760 u32 cmd_in_progress
; /* Current command in progress*/
761 u32 flags
; /* HA flags */
762 u8 waitflag
; /* are we waiting for cmd */
764 u32 reserved
:16; /* reserved space */
765 wait_queue_head_t copp_queue
; /* passthru sync queue */
767 #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,0)
769 spinlock_t copp_lock
;
773 typedef void (*scb_callback
) (ips_ha_t
*, struct ips_scb
*);
778 typedef struct ips_scb
{
797 struct ips_scb
*q_next
;
798 scb_callback callback
;
802 * Passthru Command Format
822 * Overrides for Emacs so that we almost follow Linus's tabbing style.
823 * Emacs will notice this stuff at the end of the file and automatically
824 * adjust the settings for this buffer only. This must remain at the end
826 * ---------------------------------------------------------------------------
829 * c-brace-imaginary-offset: 0
831 * c-argdecl-indent: 2
833 * c-continued-statement-offset: 2
834 * c-continued-brace-offset: 0
835 * indent-tabs-mode: nil