1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 3*0Sstevel@tonic-gate * Use is subject to license terms. 4*0Sstevel@tonic-gate */ 5*0Sstevel@tonic-gate /* 6*0Sstevel@tonic-gate * Copyright (c) 1999,2000 Michael Smith 7*0Sstevel@tonic-gate * Copyright (c) 2000 BSDi 8*0Sstevel@tonic-gate * All rights reserved. 9*0Sstevel@tonic-gate * 10*0Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 11*0Sstevel@tonic-gate * modification, are permitted provided that the following conditions 12*0Sstevel@tonic-gate * are met: 13*0Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 14*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 15*0Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 16*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 17*0Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 18*0Sstevel@tonic-gate * 19*0Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20*0Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21*0Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22*0Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23*0Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24*0Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25*0Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26*0Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27*0Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28*0Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29*0Sstevel@tonic-gate * SUCH DAMAGE. 30*0Sstevel@tonic-gate * 31*0Sstevel@tonic-gate * Copyright (c) 2002 Eric Moore 32*0Sstevel@tonic-gate * Copyright (c) 2002 LSI Logic Corporation 33*0Sstevel@tonic-gate * All rights reserved. 34*0Sstevel@tonic-gate * 35*0Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 36*0Sstevel@tonic-gate * modification, are permitted provided that the following conditions 37*0Sstevel@tonic-gate * are met: 38*0Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 39*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 40*0Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 41*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 42*0Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 43*0Sstevel@tonic-gate * 3. The party using or redistributing the source code and binary forms 44*0Sstevel@tonic-gate * agrees to the disclaimer below and the terms and conditions set forth 45*0Sstevel@tonic-gate * herein. 46*0Sstevel@tonic-gate * 47*0Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 48*0Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49*0Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50*0Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 51*0Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52*0Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53*0Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54*0Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55*0Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56*0Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57*0Sstevel@tonic-gate * SUCH DAMAGE. 58*0Sstevel@tonic-gate */ 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate #ifndef _AMRVAR_H 61*0Sstevel@tonic-gate #define _AMRVAR_H 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate #ifdef __cplusplus 66*0Sstevel@tonic-gate extern "C" { 67*0Sstevel@tonic-gate #endif 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate #define AMR_DEBUG 70*0Sstevel@tonic-gate #ifdef AMR_DEBUG 71*0Sstevel@tonic-gate #define AMRDB_PRINT(fmt) if (amr_debug_var) cmn_err fmt 72*0Sstevel@tonic-gate #else 73*0Sstevel@tonic-gate #define AMRDB_PRINT(fmt) 74*0Sstevel@tonic-gate #endif 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate #define AMRDB_PANIC(fmt) cmn_err fmt 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate #define AMR_PERIODIC_TIMEOUT 60 79*0Sstevel@tonic-gate #define AMR_RETRYCOUNT 10000 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate /* for scsi commands */ 82*0Sstevel@tonic-gate #ifndef SD_MODE_SENSE_PAGE3_CODE 83*0Sstevel@tonic-gate #define SD_MODE_SENSE_PAGE3_CODE 0x03 84*0Sstevel@tonic-gate #endif 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate #ifndef SD_MODE_SENSE_PAGE4_CODE 87*0Sstevel@tonic-gate #define SD_MODE_SENSE_PAGE4_CODE 0x04 88*0Sstevel@tonic-gate #endif 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate #ifndef SCMD_SYNCHRONIZE_CACHE 91*0Sstevel@tonic-gate #define SCMD_SYNCHRONIZE_CACHE 0x35 92*0Sstevel@tonic-gate #endif 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate #define AMR_DEFAULT_SECTORS 512 95*0Sstevel@tonic-gate #define AMR_DEFAULT_HEADS 255 96*0Sstevel@tonic-gate #define AMR_DEFAULT_CYLINDERS 63 97*0Sstevel@tonic-gate #define AMR_DEFAULT_ROTATIONS 10000 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate #define AMR_INQ_ADDITIONAL_LEN 31 100*0Sstevel@tonic-gate #define AMR_INQ_ANSI_VER 2 101*0Sstevel@tonic-gate #define AMR_INQ_RESP_DATA_FORMAT 2 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate #define AMR_PRODUCT_INFO_SIZE \ 104*0Sstevel@tonic-gate sizeof (((struct scsi_inquiry *)(NULL))->inq_pid) 105*0Sstevel@tonic-gate #define AMR_FIRMWARE_VER_SIZE \ 106*0Sstevel@tonic-gate sizeof (((struct scsi_inquiry *)(NULL))->inq_revision) 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate #define AMR_LAST_COOKIE_TAG 0xffffffff 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate /* 111*0Sstevel@tonic-gate * Per-logical-drive datastructure 112*0Sstevel@tonic-gate */ 113*0Sstevel@tonic-gate struct amr_logdrive 114*0Sstevel@tonic-gate { 115*0Sstevel@tonic-gate uint32_t al_size; 116*0Sstevel@tonic-gate uint8_t al_state; 117*0Sstevel@tonic-gate uint8_t al_properties; 118*0Sstevel@tonic-gate }; 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate /* 121*0Sstevel@tonic-gate * Per-command control structure. 122*0Sstevel@tonic-gate */ 123*0Sstevel@tonic-gate struct amr_command 124*0Sstevel@tonic-gate { 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate struct amr_command *ac_prev; 127*0Sstevel@tonic-gate struct amr_command *ac_next; 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate struct amr_softs *ac_softs; 130*0Sstevel@tonic-gate uint8_t ac_slot; 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate uint8_t ac_status; 133*0Sstevel@tonic-gate uint32_t ac_flags; 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate struct buf *ac_buf; 136*0Sstevel@tonic-gate uint32_t cmdlen; 137*0Sstevel@tonic-gate struct scsi_pkt *pkt; 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate void *ac_data; 140*0Sstevel@tonic-gate size_t ac_length; 141*0Sstevel@tonic-gate uint32_t ac_dataphys; 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate ddi_dma_handle_t sg_dma_handle; 144*0Sstevel@tonic-gate ddi_dma_cookie_t sg_dma_cookie; 145*0Sstevel@tonic-gate uint_t sg_dma_cookien; 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate ddi_dma_handle_t buffer_dma_handle; 148*0Sstevel@tonic-gate ddi_dma_cookie_t buffer_dma_cookie; 149*0Sstevel@tonic-gate ddi_acc_handle_t buffer_acc_handle; 150*0Sstevel@tonic-gate uint_t num_of_cookie; 151*0Sstevel@tonic-gate uint_t num_of_win; 152*0Sstevel@tonic-gate uint_t current_cookie; 153*0Sstevel@tonic-gate uint_t current_win; 154*0Sstevel@tonic-gate uint32_t data_transfered; 155*0Sstevel@tonic-gate uint32_t transfer_size; 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate struct amr_mailbox mailbox; 158*0Sstevel@tonic-gate struct amr_sgentry sgtable[AMR_NSEG]; 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate time_t ac_timestamp; 161*0Sstevel@tonic-gate }; 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gate /* 164*0Sstevel@tonic-gate * ac_flags values in amr_command 165*0Sstevel@tonic-gate */ 166*0Sstevel@tonic-gate #define AMR_CMD_DATAIN (1<<0) 167*0Sstevel@tonic-gate #define AMR_CMD_DATAOUT (1<<1) 168*0Sstevel@tonic-gate #define AMR_CMD_CCB_DATAIN (1<<2) 169*0Sstevel@tonic-gate #define AMR_CMD_CCB_DATAOUT (1<<3) 170*0Sstevel@tonic-gate #define AMR_CMD_PRIORITY (1<<4) 171*0Sstevel@tonic-gate #define AMR_CMD_MAPPED (1<<5) 172*0Sstevel@tonic-gate #define AMR_CMD_SLEEP (1<<6) 173*0Sstevel@tonic-gate #define AMR_CMD_BUSY (1<<7) 174*0Sstevel@tonic-gate #define AMR_CMD_PKT_CONSISTENT (1<<8) 175*0Sstevel@tonic-gate #define AMR_CMD_PKT_DMA_PARTIAL (1<<9) 176*0Sstevel@tonic-gate #define AMR_CMD_GOT_SLOT (1<<10) 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate struct sg_item { 179*0Sstevel@tonic-gate struct amr_sgentry *sg_table; 180*0Sstevel@tonic-gate ddi_dma_handle_t sg_handle; 181*0Sstevel@tonic-gate ddi_acc_handle_t sg_acc_handle; 182*0Sstevel@tonic-gate uint32_t sg_phyaddr; 183*0Sstevel@tonic-gate }; 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate struct product_info { 186*0Sstevel@tonic-gate uint8_t pi_firmware_ver[AMR_FIRMWARE_VER_SIZE+1]; 187*0Sstevel@tonic-gate uint8_t pi_product_name[AMR_PRODUCT_INFO_SIZE+1]; 188*0Sstevel@tonic-gate }; 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate /* 191*0Sstevel@tonic-gate * Per-controller-instance data 192*0Sstevel@tonic-gate */ 193*0Sstevel@tonic-gate struct amr_softs 194*0Sstevel@tonic-gate { 195*0Sstevel@tonic-gate /* bus attachments */ 196*0Sstevel@tonic-gate dev_info_t *dev_info_p; 197*0Sstevel@tonic-gate ddi_acc_handle_t pciconfig_handle; 198*0Sstevel@tonic-gate ddi_acc_handle_t regsmap_handle; 199*0Sstevel@tonic-gate ddi_iblock_cookie_t iblock_cookiep; 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gate ddi_dma_handle_t mbox_dma_handle; 202*0Sstevel@tonic-gate ddi_acc_handle_t mbox_acc_handle; 203*0Sstevel@tonic-gate ddi_dma_cookie_t mbox_dma_cookie; 204*0Sstevel@tonic-gate uint_t mbox_dma_cookien; 205*0Sstevel@tonic-gate 206*0Sstevel@tonic-gate /* controller limits and features */ 207*0Sstevel@tonic-gate uint8_t maxio; /* maximum number of I/O transactions */ 208*0Sstevel@tonic-gate uint8_t maxdrives; /* max number of logical drives */ 209*0Sstevel@tonic-gate uint8_t maxchan; /* count of SCSI channels */ 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate uint8_t amr_nlogdrives; 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate /* connected logical drives */ 214*0Sstevel@tonic-gate struct amr_logdrive logic_drive[AMR_MAXLD]; 215*0Sstevel@tonic-gate 216*0Sstevel@tonic-gate /* product info of the card */ 217*0Sstevel@tonic-gate struct product_info amr_product_info; 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate /* controller state */ 220*0Sstevel@tonic-gate uint32_t state; 221*0Sstevel@tonic-gate 222*0Sstevel@tonic-gate struct amr_mailbox *mailbox; 223*0Sstevel@tonic-gate void *mbox; 224*0Sstevel@tonic-gate uint32_t mbox_phyaddr; 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gate /* per-controller poll command */ 227*0Sstevel@tonic-gate kmutex_t cmd_mutex; 228*0Sstevel@tonic-gate kcondvar_t cmd_cv; 229*0Sstevel@tonic-gate 230*0Sstevel@tonic-gate uint32_t amr_busyslots; 231*0Sstevel@tonic-gate struct amr_command *busycmd[AMR_MAXCMD]; 232*0Sstevel@tonic-gate struct sg_item sg_items[AMR_MAXCMD]; 233*0Sstevel@tonic-gate uint32_t sg_max_count; 234*0Sstevel@tonic-gate struct amr_command *waiting_q_head; 235*0Sstevel@tonic-gate struct amr_command *waiting_q_tail; 236*0Sstevel@tonic-gate kmutex_t queue_mutex; 237*0Sstevel@tonic-gate 238*0Sstevel@tonic-gate /* periodic status check */ 239*0Sstevel@tonic-gate timeout_id_t timeout_t; 240*0Sstevel@tonic-gate kmutex_t periodic_mutex; 241*0Sstevel@tonic-gate 242*0Sstevel@tonic-gate scsi_hba_tran_t *hba_tran; 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gate ddi_taskq_t *amr_taskq; 245*0Sstevel@tonic-gate uint32_t amr_interrupts_counter; 246*0Sstevel@tonic-gate }; 247*0Sstevel@tonic-gate 248*0Sstevel@tonic-gate /* 249*0Sstevel@tonic-gate * state values in amr_softs 250*0Sstevel@tonic-gate */ 251*0Sstevel@tonic-gate #define AMR_STATE_OPEN (1<<0) 252*0Sstevel@tonic-gate #define AMR_STATE_SUSPEND (1<<1) 253*0Sstevel@tonic-gate #define AMR_STATE_CARD_DETECTED (1<<2) 254*0Sstevel@tonic-gate #define AMR_STATE_BUS_MASTER_ENABLED (1<<3) 255*0Sstevel@tonic-gate #define AMR_STATE_SOFT_STATE_SETUP (1<<4) 256*0Sstevel@tonic-gate #define AMR_STATE_PCI_CONFIG_SETUP (1<<5) 257*0Sstevel@tonic-gate #define AMR_STATE_PCI_MEM_MAPPED (1<<6) 258*0Sstevel@tonic-gate #define AMR_STATE_KMUTEX_INITED (1<<7) 259*0Sstevel@tonic-gate #define AMR_STATE_MAILBOX_SETUP (1<<8) 260*0Sstevel@tonic-gate #define AMR_STATE_SG_TABLES_SETUP (1<<9) 261*0Sstevel@tonic-gate #define AMR_STATE_INTR_SETUP (1<<10) 262*0Sstevel@tonic-gate #define AMR_STATE_TASKQ_SETUP (1<<11) 263*0Sstevel@tonic-gate #define AMR_STATE_TRAN_SETUP (1<<12) 264*0Sstevel@tonic-gate #define AMR_STATE_TIMEOUT_ENABLED (1<<13) 265*0Sstevel@tonic-gate 266*0Sstevel@tonic-gate #ifdef __cplusplus 267*0Sstevel@tonic-gate } 268*0Sstevel@tonic-gate #endif 269*0Sstevel@tonic-gate 270*0Sstevel@tonic-gate #endif /* _AMRVAR_H */ 271