osbsd.h revision 136849
1136849Sscottl/* 2136849Sscottl * Copyright (c) 2003-2004 HighPoint Technologies, Inc. 3136849Sscottl * All rights reserved. 4136849Sscottl * 5136849Sscottl * Redistribution and use in source and binary forms, with or without 6136849Sscottl * modification, are permitted provided that the following conditions 7136849Sscottl * are met: 8136849Sscottl * 1. Redistributions of source code must retain the above copyright 9136849Sscottl * notice, this list of conditions and the following disclaimer. 10136849Sscottl * 2. Redistributions in binary form must reproduce the above copyright 11136849Sscottl * notice, this list of conditions and the following disclaimer in the 12136849Sscottl * documentation and/or other materials provided with the distribution. 13136849Sscottl * 14136849Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15136849Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16136849Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17136849Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18136849Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19136849Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20136849Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21136849Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22136849Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23136849Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24136849Sscottl * SUCH DAMAGE. 25136849Sscottl * 26136849Sscottl * $FreeBSD: head/sys/dev/hptmv/osbsd.h 136849 2004-10-24 05:37:23Z scottl $ 27136849Sscottl */ 28136849Sscottl#ifndef _OSBSD_H_ 29136849Sscottl#define _OSBSD_H_ 30136849Sscottl 31136849Sscottl#include <sys/bus.h> 32136849Sscottl#include <sys/resource.h> 33136849Sscottl#include <sys/eventhandler.h> 34136849Sscottl 35136849Sscottl#include <machine/bus_memio.h> 36136849Sscottl#include <machine/bus.h> 37136849Sscottl#include <machine/resource.h> 38136849Sscottl#include <machine/bus.h> 39136849Sscottl#include <sys/rman.h> 40136849Sscottl 41136849Sscottl#include <cam/cam.h> 42136849Sscottl#include <cam/cam_ccb.h> 43136849Sscottl#include <cam/cam_debug.h> 44136849Sscottl#include <cam/cam_sim.h> 45136849Sscottl#include <cam/cam_xpt_sim.h> 46136849Sscottl#include <cam/cam_periph.h> 47136849Sscottl#include <cam/scsi/scsi_all.h> 48136849Sscottl#include <cam/scsi/scsi_message.h> 49136849Sscottl 50136849Sscottlextern intrmask_t lock_driver(void); 51136849Sscottlextern void unlock_driver(intrmask_t spl); 52136849Sscottl 53136849Sscottltypedef struct 54136849Sscottl{ 55136849Sscottl UCHAR status; /* 0 nonbootable; 80h bootable */ 56136849Sscottl UCHAR start_head; 57136849Sscottl USHORT start_sector; 58136849Sscottl UCHAR type; 59136849Sscottl UCHAR end_head; 60136849Sscottl USHORT end_sector; 61136849Sscottl ULONG start_abs_sector; 62136849Sscottl ULONG num_of_sector; 63136849Sscottl} partition; 64136849Sscottl 65136849Sscottltypedef struct _INQUIRYDATA { 66136849Sscottl UCHAR DeviceType : 5; 67136849Sscottl UCHAR DeviceTypeQualifier : 3; 68136849Sscottl UCHAR DeviceTypeModifier : 7; 69136849Sscottl UCHAR RemovableMedia : 1; 70136849Sscottl UCHAR Versions; 71136849Sscottl UCHAR ResponseDataFormat; 72136849Sscottl UCHAR AdditionalLength; 73136849Sscottl UCHAR Reserved[2]; 74136849Sscottl UCHAR SoftReset : 1; 75136849Sscottl UCHAR CommandQueue : 1; 76136849Sscottl UCHAR Reserved2 : 1; 77136849Sscottl UCHAR LinkedCommands : 1; 78136849Sscottl UCHAR Synchronous : 1; 79136849Sscottl UCHAR Wide16Bit : 1; 80136849Sscottl UCHAR Wide32Bit : 1; 81136849Sscottl UCHAR RelativeAddressing : 1; 82136849Sscottl UCHAR VendorId[8]; 83136849Sscottl UCHAR ProductId[16]; 84136849Sscottl UCHAR ProductRevisionLevel[4]; 85136849Sscottl UCHAR VendorSpecific[20]; 86136849Sscottl UCHAR Reserved3[40]; 87136849Sscottl} INQUIRYDATA, *PINQUIRYDATA; 88136849Sscottl 89136849Sscottltypedef struct _READ_CAPACITY_DATA { 90136849Sscottl ULONG LogicalBlockAddress; 91136849Sscottl ULONG BytesPerBlock; 92136849Sscottl} READ_CAPACITY_DATA, *PREAD_CAPACITY_DATA; 93136849Sscottl 94136849Sscottl#define MV_IAL_HT_SACOALT_DEFAULT 1 95136849Sscottl#define MV_IAL_HT_SAITMTH_DEFAULT 1 96136849Sscottl 97136849Sscottl/****************************************/ 98136849Sscottl/* GENERAL Definitions */ 99136849Sscottl/****************************************/ 100136849Sscottl 101136849Sscottl/* Bits for HD_ERROR */ 102136849Sscottl#define NM_ERR 0x02 /* media present */ 103136849Sscottl#define ABRT_ERR 0x04 /* Command aborted */ 104136849Sscottl#define MCR_ERR 0x08 /* media change request */ 105136849Sscottl#define IDNF_ERR 0x10 /* ID field not found */ 106136849Sscottl#define MC_ERR 0x20 /* media changed */ 107136849Sscottl#define UNC_ERR 0x40 /* Uncorrect data */ 108136849Sscottl#define WP_ERR 0x40 /* write protect */ 109136849Sscottl#define ICRC_ERR 0x80 /* new meaning: CRC error during transfer */ 110136849Sscottl 111136849Sscottl#define REQUESTS_ARRAY_SIZE (9 * MV_EDMA_REQUEST_QUEUE_SIZE) /* 9 K bytes */ 112136849Sscottl#define RESPONSES_ARRAY_SIZE (12*MV_EDMA_RESPONSE_QUEUE_SIZE) /* 3 K bytes */ 113136849Sscottl 114136849Sscottl#define PRD_ENTRIES_PER_CMD (MAX_SG_DESCRIPTORS+1) 115136849Sscottl#define PRD_ENTRIES_SIZE (MV_EDMA_PRD_ENTRY_SIZE*PRD_ENTRIES_PER_CMD) 116136849Sscottl#define PRD_TABLES_FOR_VBUS (MV_SATA_CHANNELS_NUM*MV_EDMA_QUEUE_LENGTH) 117136849Sscottl 118136849Sscottltypedef enum _SataEvent { 119136849Sscottl SATA_EVENT_NO_CHANGE = 0, 120136849Sscottl SATA_EVENT_CHANNEL_CONNECTED, 121136849Sscottl SATA_EVENT_CHANNEL_DISCONNECTED 122136849Sscottl} SATA_EVENT; 123136849Sscottl 124136849Sscottltypedef ULONG_PTR dma_addr_t; 125136849Sscottl 126136849Sscottltypedef struct _MV_CHANNEL { 127136849Sscottl unsigned int maxUltraDmaModeSupported; 128136849Sscottl unsigned int maxDmaModeSupported; 129136849Sscottl unsigned int maxPioModeSupported; 130136849Sscottl MV_BOOLEAN online; 131136849Sscottl} MV_CHANNEL; 132136849Sscottl 133136849Sscottlstruct _privCommand; 134136849Sscottl 135136849Sscottltypedef struct IALAdapter { 136136849Sscottl struct cam_path *path; 137136849Sscottl device_t hpt_dev; /* bus device */ 138136849Sscottl struct resource *hpt_irq; /* interrupt */ 139136849Sscottl void *hpt_intr; /* interrupt handle */ 140136849Sscottl struct resource *mem_res; 141136849Sscottl bus_space_handle_t mem_bsh; 142136849Sscottl bus_space_tag_t mem_btag; 143136849Sscottl bus_dma_tag_t parent_dmat; 144136849Sscottl bus_dma_tag_t req_dmat; 145136849Sscottl bus_dmamap_t req_map; 146136849Sscottl bus_dma_tag_t resp_dmat; 147136849Sscottl bus_dmamap_t resp_map; 148136849Sscottl bus_dma_tag_t prd_dmat; 149136849Sscottl bus_dmamap_t prd_map; 150136849Sscottl bus_dma_tag_t buf_dmat; 151136849Sscottl 152136849Sscottl struct IALAdapter *next; 153136849Sscottl 154136849Sscottl MV_SATA_ADAPTER mvSataAdapter; 155136849Sscottl MV_CHANNEL mvChannel[MV_SATA_CHANNELS_NUM]; 156136849Sscottl MV_U8 *requestsArrayBaseAddr; 157136849Sscottl MV_U8 *requestsArrayBaseAlignedAddr; 158136849Sscottl dma_addr_t requestsArrayBaseDmaAddr; 159136849Sscottl dma_addr_t requestsArrayBaseDmaAlignedAddr; 160136849Sscottl MV_U8 *responsesArrayBaseAddr; 161136849Sscottl MV_U8 *responsesArrayBaseAlignedAddr; 162136849Sscottl dma_addr_t responsesArrayBaseDmaAddr; 163136849Sscottl dma_addr_t responsesArrayBaseDmaAlignedAddr; 164136849Sscottl SATA_EVENT sataEvents[MV_SATA_CHANNELS_NUM]; 165136849Sscottl 166136849Sscottl struct callout_handle event_timer_connect; 167136849Sscottl struct callout_handle event_timer_disconnect; 168136849Sscottl 169136849Sscottl struct _VBus VBus; 170136849Sscottl struct _VDevice VDevices[MV_SATA_CHANNELS_NUM]; 171136849Sscottl PCommand pCommandBlocks; 172136849Sscottl struct _privCommand *pPrivateBlocks; 173136849Sscottl TAILQ_HEAD(, _privCommand) PrivCmdTQH; 174136849Sscottl PUCHAR prdTableAddr; 175136849Sscottl ULONG prdTableDmaAddr; 176136849Sscottl void* pFreePRDLink; 177136849Sscottl 178136849Sscottl union ccb *pending_Q; 179136849Sscottl 180136849Sscottl MV_U8 outstandingCommands; 181136849Sscottl 182136849Sscottl UCHAR status; 183136849Sscottl UCHAR ver_601; 184136849Sscottl UCHAR beeping; 185136849Sscottl 186136849Sscottl eventhandler_tag eh; 187136849Sscottl} IAL_ADAPTER_T; 188136849Sscottl 189136849Sscottltypedef struct _privCommand { 190136849Sscottl TAILQ_ENTRY(_privCommand) PrivEntry; 191136849Sscottl IAL_ADAPTER_T *pAdapter; 192136849Sscottl union ccb *ccb; 193136849Sscottl bus_dmamap_t buf_map; 194136849Sscottl} *pPrivCommand; 195136849Sscottl 196136849Sscottlextern IAL_ADAPTER_T *gIal_Adapter; 197136849Sscottl 198136849Sscottl/*entry.c*/ 199136849Sscottltypedef void (*HPT_DPC)(IAL_ADAPTER_T *,void*,UCHAR); 200136849Sscottlint hpt_queue_dpc(HPT_DPC dpc, IAL_ADAPTER_T *pAdapter, void *arg, UCHAR flags); 201136849Sscottlvoid hpt_rebuild_data_block(IAL_ADAPTER_T *pAdapter, PVDevice pArray, 202136849Sscottl UCHAR flags); 203136849Sscottlvoid Check_Idle_Call(IAL_ADAPTER_T *pAdapter); 204136849Sscottlint Kernel_DeviceIoControl(_VBUS_ARG DWORD dwIoControlCode, PVOID lpInBuffer, 205136849Sscottl DWORD nInBufferSize, PVOID lpOutBuffer, DWORD nOutBufferSize, 206136849Sscottl PDWORD lpBytesReturned); 207136849Sscottlvoid fRescanAllDevice(_VBUS_ARG0); 208136849Sscottlint hpt_add_disk_to_array(_VBUS_ARG DEVICEID idArray, DEVICEID idDisk); 209136849Sscottl 210136849Sscottl 211136849Sscottl#define __str_direct(x) #x 212136849Sscottl#define __str(x) __str_direct(x) 213136849Sscottl#define KMSG_LEADING __str(PROC_DIR_NAME) ": " 214136849Sscottl#define hpt_printk(_x_) do { \ 215136849Sscottl printf(KMSG_LEADING); \ 216136849Sscottl printf _x_ ; \ 217136849Sscottl} while (0) 218136849Sscottl 219136849Sscottl#define DUPLICATE 0 220136849Sscottl#define INITIALIZE 1 221136849Sscottl#define REBUILD_PARITY 2 222136849Sscottl#define VERIFY 3 223136849Sscottl 224136849Sscottlextern char DRIVER_VERSION[]; 225136849Sscottl/**********************************************************/ 226136849Sscottlstatic __inline struct cam_periph * 227136849Sscottlhpt_get_periph(int path_id,int target_id) 228136849Sscottl{ 229136849Sscottl struct cam_periph *periph = NULL; 230136849Sscottl struct cam_path *path; 231136849Sscottl int status; 232136849Sscottl 233136849Sscottl status = xpt_create_path(&path, NULL, path_id, target_id, 0); 234136849Sscottl if (status == CAM_REQ_CMP) { 235136849Sscottl periph = cam_periph_find(path, NULL); 236136849Sscottl xpt_free_path(path); 237136849Sscottl if (periph != NULL) { 238136849Sscottl if (strncmp(periph->periph_name, "da", 2)) 239136849Sscottl periph = NULL; 240136849Sscottl } 241136849Sscottl } 242136849Sscottl return periph; 243136849Sscottl} 244136849Sscottl 245136849Sscottlstatic __inline void 246136849SscottlFreePrivCommand(IAL_ADAPTER_T *pAdapter, pPrivCommand prvCmd) 247136849Sscottl{ 248136849Sscottl TAILQ_INSERT_TAIL(&pAdapter->PrivCmdTQH, prvCmd, PrivEntry); 249136849Sscottl} 250136849Sscottl 251136849Sscottlstatic __inline pPrivCommand 252136849SscottlAllocPrivCommand(IAL_ADAPTER_T *pAdapter) 253136849Sscottl{ 254136849Sscottl pPrivCommand prvCmd; 255136849Sscottl 256136849Sscottl prvCmd = TAILQ_FIRST(&pAdapter->PrivCmdTQH); 257136849Sscottl if (prvCmd == NULL) 258136849Sscottl return NULL; 259136849Sscottl 260136849Sscottl TAILQ_REMOVE(&pAdapter->PrivCmdTQH, prvCmd, PrivEntry); 261136849Sscottl return (prvCmd); 262136849Sscottl} 263136849Sscottl 264136849Sscottlstatic __inline void 265136849Sscottlmv_reg_write_byte(MV_BUS_ADDR_T base, MV_U32 offset, MV_U8 val) 266136849Sscottl{ 267136849Sscottl IAL_ADAPTER_T *pAdapter; 268136849Sscottl 269136849Sscottl pAdapter = base; 270136849Sscottl bus_space_write_1(pAdapter->mem_btag, pAdapter->mem_bsh, offset, val); 271136849Sscottl} 272136849Sscottl 273136849Sscottlstatic __inline void 274136849Sscottlmv_reg_write_word(MV_BUS_ADDR_T base, MV_U32 offset, MV_U16 val) 275136849Sscottl{ 276136849Sscottl IAL_ADAPTER_T *pAdapter; 277136849Sscottl 278136849Sscottl pAdapter = base; 279136849Sscottl bus_space_write_2(pAdapter->mem_btag, pAdapter->mem_bsh, offset, val); 280136849Sscottl} 281136849Sscottl 282136849Sscottlstatic __inline void 283136849Sscottlmv_reg_write_dword(MV_BUS_ADDR_T base, MV_U32 offset, MV_U32 val) 284136849Sscottl{ 285136849Sscottl IAL_ADAPTER_T *pAdapter; 286136849Sscottl 287136849Sscottl pAdapter = base; 288136849Sscottl bus_space_write_4(pAdapter->mem_btag, pAdapter->mem_bsh, offset, val); 289136849Sscottl} 290136849Sscottl 291136849Sscottlstatic __inline MV_U8 292136849Sscottlmv_reg_read_byte(MV_BUS_ADDR_T base, MV_U32 offset) 293136849Sscottl{ 294136849Sscottl IAL_ADAPTER_T *pAdapter; 295136849Sscottl 296136849Sscottl pAdapter = base; 297136849Sscottl return (bus_space_read_1(pAdapter->mem_btag, pAdapter->mem_bsh, 298136849Sscottl offset)); 299136849Sscottl} 300136849Sscottl 301136849Sscottlstatic __inline MV_U16 302136849Sscottlmv_reg_read_word(MV_BUS_ADDR_T base, MV_U32 offset) 303136849Sscottl{ 304136849Sscottl IAL_ADAPTER_T *pAdapter; 305136849Sscottl 306136849Sscottl pAdapter = base; 307136849Sscottl return (bus_space_read_2(pAdapter->mem_btag, pAdapter->mem_bsh, 308136849Sscottl offset)); 309136849Sscottl} 310136849Sscottl 311136849Sscottlstatic __inline MV_U32 312136849Sscottlmv_reg_read_dword(MV_BUS_ADDR_T base, MV_U32 offset) 313136849Sscottl{ 314136849Sscottl IAL_ADAPTER_T *pAdapter; 315136849Sscottl 316136849Sscottl pAdapter = base; 317136849Sscottl return (bus_space_read_4(pAdapter->mem_btag, pAdapter->mem_bsh, 318136849Sscottl offset)); 319136849Sscottl} 320136849Sscottl 321136849Sscottl#endif 322