aic79xx_openbsd.h revision 1.4
1/* $OpenBSD: aic79xx_openbsd.h,v 1.4 2004/08/06 01:29:19 marco Exp $ */ 2/* 3 * FreeBSD platform specific driver option settings, data structures, 4 * function declarations and includes. 5 * 6 * Copyright (c) 1994-2001 Justin T. Gibbs. 7 * Copyright (c) 2001-2002 Adaptec Inc. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions, and the following disclaimer, 15 * without modification. 16 * 2. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * Alternatively, this software may be distributed under the terms of the 20 * GNU Public License ("GPL"). 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * $FreeBSD: src/sys/dev/aic7xxx/aic79xx_osm.h,v 1.13 2003/12/17 00:02:09 gibbs Exp $ 35 * 36 * Additional copyrights by: 37 * Milos Urbanek 38 * Kenneth R. Westerback 39 * Marco Peereboom 40 * 41 */ 42 43#ifndef _AIC79XX_OPENBSD_H_ 44#define _AIC79XX_OPENBSD_H_ 45 46#include "pci.h" /* for config options */ 47 48#include <sys/param.h> 49#include <sys/kernel.h> 50#include <sys/systm.h> 51#include <sys/device.h> 52#include <sys/malloc.h> 53#include <sys/buf.h> 54#include <sys/proc.h> 55#include <sys/queue.h> 56 57#define AIC_PCI_CONFIG 1 58#include <dev/pci/pcireg.h> 59#include <dev/pci/pcivar.h> 60 61#include <machine/bus.h> 62#include <machine/intr.h> 63 64#include <scsi/scsi_all.h> 65#include <scsi/scsi_message.h> 66#include <scsi/scsi_debug.h> 67#include <scsi/scsiconf.h> 68 69#include <uvm/uvm_extern.h> 70 71#ifdef DEBUG 72#define bootverbose 1 73#else 74#define bootverbose 0 75#endif 76/****************************** Platform Macros *******************************/ 77#define SCSI_IS_SCSIBUS_B(ahd, sc_link) \ 78 (0) 79#define SCSI_CHANNEL(ahd, sc_link) \ 80 ('A') 81#define SCSI_SCSI_ID(ahd, sc_link) \ 82 (ahd->our_id) 83#define BUILD_SCSIID(ahd, sc_link, target_id, our_id) \ 84 ((((target_id) << TID_SHIFT) & TID) | (our_id)) 85 86#ifndef offsetof 87#define offsetof(type, member) ((size_t)(&((type *)0)->member)) 88#endif 89 90/************************* Forward Declarations *******************************/ 91typedef struct pci_attach_args * ahd_dev_softc_t; 92 93/***************************** Bus Space/DMA **********************************/ 94 95/* XXX Need to update Bus DMA for partial map syncs */ 96#define ahd_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op) \ 97 bus_dmamap_sync(dma_tag, dmamap, offset, len, op) 98 99/************************ Tunable Driver Parameters **************************/ 100/* 101 * The number of dma segments supported. The sequencer can handle any number 102 * of physically contiguous S/G entrys. To reduce the driver's memory 103 * consumption, we limit the number supported to be sufficient to handle 104 * the largest mapping supported by the kernel, MAXPHYS. Assuming the 105 * transfer is as fragmented as possible and unaligned, this turns out to 106 * be the number of paged sized transfers in MAXPHYS plus an extra element 107 * to handle any unaligned residual. The sequencer fetches SG elements 108 * in cacheline sized chucks, so make the number per-transaction an even 109 * multiple of 16 which should align us on even the largest of cacheline 110 * boundaries. 111 */ 112#define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16)) 113 114/* This driver supports target mode */ 115// #define AHD_TARGET_MODE 1 116 117/************************** Softc/SCB Platform Data ***************************/ 118struct ahd_platform_data { 119}; 120 121struct scb_platform_data { 122}; 123 124/********************************* Byte Order *********************************/ 125#define ahd_htobe16(x) htobe16(x) 126#define ahd_htobe32(x) htobe32(x) 127#define ahd_htobe64(x) htobe64(x) 128#define ahd_htole16(x) htole16(x) 129#define ahd_htole32(x) htole32(x) 130#define ahd_htole64(x) htole64(x) 131 132#define ahd_be16toh(x) be16toh(x) 133#define ahd_be32toh(x) be32toh(x) 134#define ahd_be64toh(x) be64toh(x) 135#define ahd_le16toh(x) letoh16(x) 136#define ahd_le32toh(x) letoh32(x) 137#define ahd_le64toh(x) letoh64(x) 138 139/************************** Timer DataStructures ******************************/ 140typedef struct timeout ahd_timer_t; 141 142/***************************** Core Includes **********************************/ 143 144#if AHD_REG_PRETTY_PRINT 145#define AIC_DEBUG_REGISTERS 1 146#else 147#define AIC_DEBUG_REGISTERS 0 148#endif 149#include <dev/ic/aic79xx.h> 150 151/***************************** Timer Facilities *******************************/ 152void ahd_timeout(void*); 153void ahd_timer_reset(ahd_timer_t *, u_int, ahd_callback_t *, void *); 154void ahd_scb_timer_reset(struct scb *, u_int); 155 156ahd_callback_t ahd_reset_poll; 157ahd_callback_t ahd_stat_timer; 158 159#define ahd_timer_init callout_init 160#define ahd_timer_stop callout_stop 161 162/*************************** Device Access ************************************/ 163#define ahd_inb(ahd, port) \ 164 bus_space_read_1((ahd)->tags[(port) >> 8], \ 165 (ahd)->bshs[(port) >> 8], (port) & 0xFF) 166 167#define ahd_outb(ahd, port, value) \ 168 bus_space_write_1((ahd)->tags[(port) >> 8], \ 169 (ahd)->bshs[(port) >> 8], (port) & 0xFF, value) 170 171#define ahd_inw_atomic(ahd, port) \ 172 ahd_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8], \ 173 (ahd)->bshs[(port) >> 8], (port) & 0xFF)) 174 175#define ahd_outw_atomic(ahd, port, value) \ 176 bus_space_write_2((ahd)->tags[(port) >> 8], \ 177 (ahd)->bshs[(port) >> 8], \ 178 (port & 0xFF), ahd_htole16(value)) 179 180#define ahd_outsb(ahd, port, valp, count) \ 181 bus_space_write_multi_1((ahd)->tags[(port) >> 8], \ 182 (ahd)->bshs[(port) >> 8], \ 183 (port & 0xFF), valp, count) 184 185#define ahd_insb(ahd, port, valp, count) \ 186 bus_space_read_multi_1((ahd)->tags[(port) >> 8], \ 187 (ahd)->bshs[(port) >> 8], \ 188 (port & 0xFF), valp, count) 189 190void ahd_flush_device_writes(struct ahd_softc *); 191 192/**************************** Locking Primitives ******************************/ 193/* Lock protecting internal data structures */ 194void ahd_lockinit(struct ahd_softc *); 195void ahd_lock(struct ahd_softc *, int *flags); 196void ahd_unlock(struct ahd_softc *, int *flags); 197 198/* Lock held during command compeletion to the upper layer */ 199void ahd_done_lockinit(struct ahd_softc *); 200void ahd_done_lock(struct ahd_softc *, int *flags); 201void ahd_done_unlock(struct ahd_softc *, int *flags); 202 203/* Lock held during ahd_list manipulation and ahd softc frees */ 204void ahd_list_lockinit(void); 205void ahd_list_lock(int *flags); 206void ahd_list_unlock(int *flags); 207 208/****************************** OS Primitives *********************************/ 209#define ahd_delay DELAY 210 211/************************** Transaction Operations ****************************/ 212void ahd_set_transaction_status(struct scb *, uint32_t); 213void ahd_set_scsi_status(struct scb *, uint32_t); 214uint32_t ahd_get_transaction_status(struct scb *); 215uint32_t ahd_get_scsi_status(struct scb *); 216void ahd_set_transaction_tag(struct scb *, int, u_int); 217u_long ahd_get_transfer_length(struct scb *); 218int ahd_get_transfer_dir(struct scb *); 219void ahd_set_residual(struct scb *, u_long); 220void ahd_set_sense_residual(struct scb *, u_long); 221u_long ahd_get_residual(struct scb *); 222int ahd_perform_autosense(struct scb *); 223uint32_t ahd_get_sense_bufsize(struct ahd_softc*, struct scb*); 224void ahd_freeze_simq(struct ahd_softc *); 225void ahd_release_simq(struct ahd_softc *); 226void ahd_freeze_scb(struct scb *); 227void ahd_platform_freeze_devq(struct ahd_softc *, struct scb *); 228int ahd_platform_abort_scbs(struct ahd_softc *, int, 229 char, int, u_int, role_t, uint32_t); 230void ahd_platform_scb_free(struct ahd_softc *, struct scb *); 231 232/********************************** PCI ***************************************/ 233/*#if AHD_PCI_CONFIG > 0*/ 234uint32_t ahd_pci_read_config(ahd_dev_softc_t, int, int); 235void ahd_pci_write_config(ahd_dev_softc_t, int, 236 uint32_t, int); 237int ahd_get_pci_function(ahd_dev_softc_t); 238int ahd_get_pci_slot(ahd_dev_softc_t); 239int ahd_get_pci_bus(ahd_dev_softc_t); 240 241int ahd_pci_map_registers(struct ahd_softc *); 242int ahd_pci_map_int(struct ahd_softc *); 243/*#endif*/ 244 245typedef enum 246{ 247 AHD_POWER_STATE_D0, 248 AHD_POWER_STATE_D1, 249 AHD_POWER_STATE_D2, 250 AHD_POWER_STATE_D3 251} ahd_power_state; 252 253void ahd_power_state_change(struct ahd_softc *, ahd_power_state); 254 255/******************************** VL/EISA *************************************/ 256int aic7770_map_registers(struct ahd_softc *); 257int aic7770_map_int(struct ahd_softc *, int); 258 259/********************************* Debug **************************************/ 260void ahd_print_path(struct ahd_softc *, struct scb *); 261void ahd_platform_dump_card_state(struct ahd_softc *ahd); 262 263/**************************** Transfer Settings *******************************/ 264void ahd_notify_xfer_settings_change(struct ahd_softc *, 265 struct ahd_devinfo *); 266void ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *, 267 ahd_queue_alg); 268 269/************************* Initialization/Teardown ****************************/ 270int ahd_platform_alloc(struct ahd_softc *, void *); 271void ahd_platform_free(struct ahd_softc *); 272int ahd_attach(struct ahd_softc *); 273int ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd); 274int ahd_detach(struct device *, int); 275#define ahd_platform_init 276 277/****************************** Interrupts ************************************/ 278int ahd_platform_intr(void *); 279void ahd_platform_flushwork(struct ahd_softc *ahd); 280/************************ Misc Function Declarations **************************/ 281void ahd_done(struct ahd_softc *, struct scb *); 282void ahd_send_async(struct ahd_softc *, char /*channel*/, 283 u_int /*target*/, u_int /*lun*/, ac_code, void *arg); 284/************************ SCSI task management **************************/ 285#define SIU_TASKMGMT_NONE 0x00 286#define SIU_TASKMGMT_ABORT_TASK 0x01 287#define SIU_TASKMGMT_ABORT_TASK_SET 0x02 288#define SIU_TASKMGMT_CLEAR_TASK_SET 0x04 289#define SIU_TASKMGMT_LUN_RESET 0x08 290#define SIU_TASKMGMT_TARGET_RESET 0x20 291#define SIU_TASKMGMT_CLEAR_ACA 0x40 292#endif /* _AIC79XX_OPENBSD_H_ */ 293