aic79xx_osm.h revision 153072
1198090Srdivacky/*- 2198090Srdivacky * FreeBSD platform specific driver option settings, data structures, 3198090Srdivacky * function declarations and includes. 4198090Srdivacky * 5198090Srdivacky * Copyright (c) 1994-2001 Justin T. Gibbs. 6198090Srdivacky * Copyright (c) 2001-2002 Adaptec Inc. 7198090Srdivacky * All rights reserved. 8198090Srdivacky * 9198090Srdivacky * Redistribution and use in source and binary forms, with or without 10198090Srdivacky * modification, are permitted provided that the following conditions 11198090Srdivacky * are met: 12198090Srdivacky * 1. Redistributions of source code must retain the above copyright 13198090Srdivacky * notice, this list of conditions, and the following disclaimer, 14198090Srdivacky * without modification. 15198090Srdivacky * 2. The name of the author may not be used to endorse or promote products 16198892Srdivacky * derived from this software without specific prior written permission. 17198090Srdivacky * 18198090Srdivacky * Alternatively, this software may be distributed under the terms of the 19198090Srdivacky * GNU Public License ("GPL"). 20198090Srdivacky * 21198090Srdivacky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 22202878Srdivacky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23202878Srdivacky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24208599Srdivacky * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 25202878Srdivacky * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26198090Srdivacky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27198090Srdivacky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28198090Srdivacky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29203954Srdivacky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30198090Srdivacky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31198090Srdivacky * SUCH DAMAGE. 32198090Srdivacky * 33198090Srdivacky * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.h#23 $ 34198090Srdivacky * 35198090Srdivacky * $FreeBSD: head/sys/dev/aic7xxx/aic79xx_osm.h 153072 2005-12-04 02:12:43Z ru $ 36198090Srdivacky */ 37198090Srdivacky 38198090Srdivacky#ifndef _AIC79XX_FREEBSD_H_ 39207618Srdivacky#define _AIC79XX_FREEBSD_H_ 40198090Srdivacky 41198090Srdivacky#include <opt_aic79xx.h> /* for config options */ 42198090Srdivacky 43198090Srdivacky#include <sys/param.h> 44198090Srdivacky#include <sys/systm.h> 45198090Srdivacky#include <sys/bus.h> /* For device_t */ 46198090Srdivacky#if __FreeBSD_version >= 500000 47198090Srdivacky#include <sys/endian.h> 48198090Srdivacky#endif 49198090Srdivacky#include <sys/eventhandler.h> 50198090Srdivacky#include <sys/kernel.h> 51198090Srdivacky#include <sys/malloc.h> 52203954Srdivacky#include <sys/module.h> 53198090Srdivacky#include <sys/queue.h> 54203954Srdivacky 55202878Srdivacky#define AIC_PCI_CONFIG 1 56203954Srdivacky#include <machine/bus.h> 57198090Srdivacky#include <machine/endian.h> 58198090Srdivacky#include <machine/clock.h> 59202878Srdivacky#include <machine/resource.h> 60198090Srdivacky 61198090Srdivacky#include <sys/rman.h> 62202878Srdivacky 63202878Srdivacky#if __FreeBSD_version >= 500000 64202878Srdivacky#include <dev/pci/pcireg.h> 65198090Srdivacky#include <dev/pci/pcivar.h> 66198090Srdivacky#else 67198090Srdivacky#include <pci/pcireg.h> 68198090Srdivacky#include <pci/pcivar.h> 69198090Srdivacky#endif 70198090Srdivacky 71212904Sdim#include <cam/cam.h> 72198090Srdivacky#include <cam/cam_ccb.h> 73212904Sdim#include <cam/cam_debug.h> 74205218Srdivacky#include <cam/cam_sim.h> 75198090Srdivacky#include <cam/cam_xpt_sim.h> 76198090Srdivacky 77198090Srdivacky#include <cam/scsi/scsi_all.h> 78198090Srdivacky#include <cam/scsi/scsi_message.h> 79198090Srdivacky#include <cam/scsi/scsi_iu.h> 80198090Srdivacky 81198090Srdivacky#ifdef CAM_NEW_TRAN_CODE 82198090Srdivacky#define AHD_NEW_TRAN_SETTINGS 83198090Srdivacky#endif /* CAM_NEW_TRAN_CODE */ 84198090Srdivacky 85198090Srdivacky/****************************** Platform Macros *******************************/ 86198090Srdivacky#define SIM_IS_SCSIBUS_B(ahd, sim) \ 87198090Srdivacky (0) 88198090Srdivacky#define SIM_CHANNEL(ahd, sim) \ 89198090Srdivacky ('A') 90198090Srdivacky#define SIM_SCSI_ID(ahd, sim) \ 91198090Srdivacky (ahd->our_id) 92198090Srdivacky#define SIM_PATH(ahd, sim) \ 93198090Srdivacky (ahd->platform_data->path) 94198090Srdivacky#define BUILD_SCSIID(ahd, sim, target_id, our_id) \ 95198090Srdivacky ((((target_id) << TID_SHIFT) & TID) | (our_id)) 96198090Srdivacky 97198090Srdivacky 98198090Srdivacky#define SCB_GET_SIM(ahd, scb) \ 99198090Srdivacky ((ahd)->platform_data->sim) 100198090Srdivacky 101198090Srdivacky#ifndef offsetof 102198090Srdivacky#define offsetof(type, member) ((size_t)(&((type *)0)->member)) 103198090Srdivacky#endif 104198090Srdivacky 105/************************ Tunable Driver Parameters **************************/ 106/* 107 * The number of dma segments supported. The sequencer can handle any number 108 * of physically contiguous S/G entrys. To reduce the driver's memory 109 * consumption, we limit the number supported to be sufficient to handle 110 * the largest mapping supported by the kernel, MAXPHYS. Assuming the 111 * transfer is as fragmented as possible and unaligned, this turns out to 112 * be the number of paged sized transfers in MAXPHYS plus an extra element 113 * to handle any unaligned residual. The sequencer fetches SG elements 114 * in cacheline sized chucks, so make the number per-transaction an even 115 * multiple of 16 which should align us on even the largest of cacheline 116 * boundaries. 117 */ 118#define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16)) 119 120/* This driver supports target mode */ 121#ifdef NOT_YET 122#define AHD_TARGET_MODE 1 123#endif 124 125/************************** Softc/SCB Platform Data ***************************/ 126struct ahd_platform_data { 127 /* 128 * Hooks into the XPT. 129 */ 130 struct cam_sim *sim; 131 struct cam_path *path; 132 133 int regs_res_type[2]; 134 int regs_res_id[2]; 135 int irq_res_type; 136 struct resource *regs[2]; 137 struct resource *irq; 138 void *ih; 139 eventhandler_tag eh; 140 struct proc *recovery_thread; 141}; 142 143struct scb_platform_data { 144}; 145 146/***************************** Core Includes **********************************/ 147#if AHD_REG_PRETTY_PRINT 148#define AIC_DEBUG_REGISTERS 1 149#else 150#define AIC_DEBUG_REGISTERS 0 151#endif 152#define AIC_CORE_INCLUDE <dev/aic7xxx/aic79xx.h> 153#define AIC_LIB_PREFIX ahd 154#define AIC_CONST_PREFIX AHD 155#include <dev/aic7xxx/aic_osm_lib.h> 156 157/*************************** Device Access ************************************/ 158#define ahd_inb(ahd, port) \ 159 bus_space_read_1((ahd)->tags[(port) >> 8], \ 160 (ahd)->bshs[(port) >> 8], (port) & 0xFF) 161 162#define ahd_outb(ahd, port, value) \ 163 bus_space_write_1((ahd)->tags[(port) >> 8], \ 164 (ahd)->bshs[(port) >> 8], (port) & 0xFF, value) 165 166#define ahd_inw_atomic(ahd, port) \ 167 aic_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8], \ 168 (ahd)->bshs[(port) >> 8], (port) & 0xFF)) 169 170#define ahd_outw_atomic(ahd, port, value) \ 171 bus_space_write_2((ahd)->tags[(port) >> 8], \ 172 (ahd)->bshs[(port) >> 8], \ 173 (port & 0xFF), aic_htole16(value)) 174 175#define ahd_outsb(ahd, port, valp, count) \ 176 bus_space_write_multi_1((ahd)->tags[(port) >> 8], \ 177 (ahd)->bshs[(port) >> 8], \ 178 (port & 0xFF), valp, count) 179 180#define ahd_insb(ahd, port, valp, count) \ 181 bus_space_read_multi_1((ahd)->tags[(port) >> 8], \ 182 (ahd)->bshs[(port) >> 8], \ 183 (port & 0xFF), valp, count) 184 185static __inline void ahd_flush_device_writes(struct ahd_softc *); 186 187static __inline void 188ahd_flush_device_writes(struct ahd_softc *ahd) 189{ 190 /* XXX Is this sufficient for all architectures??? */ 191 ahd_inb(ahd, INTSTAT); 192} 193 194/**************************** Locking Primitives ******************************/ 195/* Lock protecting internal data structures */ 196static __inline void ahd_lockinit(struct ahd_softc *); 197static __inline void ahd_lock(struct ahd_softc *, unsigned long *flags); 198static __inline void ahd_unlock(struct ahd_softc *, unsigned long *flags); 199 200/* Lock held during command compeletion to the upper layer */ 201static __inline void ahd_done_lockinit(struct ahd_softc *); 202static __inline void ahd_done_lock(struct ahd_softc *, unsigned long *flags); 203static __inline void ahd_done_unlock(struct ahd_softc *, unsigned long *flags); 204 205/* Lock held during ahd_list manipulation and ahd softc frees */ 206static __inline void ahd_list_lockinit(void); 207static __inline void ahd_list_lock(unsigned long *flags); 208static __inline void ahd_list_unlock(unsigned long *flags); 209 210static __inline void 211ahd_lockinit(struct ahd_softc *ahd) 212{ 213} 214 215static __inline void 216ahd_lock(struct ahd_softc *ahd, unsigned long *flags) 217{ 218 *flags = splcam(); 219} 220 221static __inline void 222ahd_unlock(struct ahd_softc *ahd, unsigned long *flags) 223{ 224 splx(*flags); 225} 226 227/* Lock held during command compeletion to the upper layer */ 228static __inline void 229ahd_done_lockinit(struct ahd_softc *ahd) 230{ 231} 232 233static __inline void 234ahd_done_lock(struct ahd_softc *ahd, unsigned long *flags) 235{ 236} 237 238static __inline void 239ahd_done_unlock(struct ahd_softc *ahd, unsigned long *flags) 240{ 241} 242 243/* Lock held during ahd_list manipulation and ahd softc frees */ 244static __inline void 245ahd_list_lockinit(void) 246{ 247} 248 249static __inline void 250ahd_list_lock(unsigned long *flags) 251{ 252} 253 254static __inline void 255ahd_list_unlock(unsigned long *flags) 256{ 257} 258 259/********************************** PCI ***************************************/ 260int ahd_pci_map_registers(struct ahd_softc *ahd); 261int ahd_pci_map_int(struct ahd_softc *ahd); 262 263/************************** Transaction Operations ****************************/ 264static __inline void aic_freeze_simq(struct aic_softc*); 265static __inline void aic_release_simq(struct aic_softc*); 266 267static __inline void 268aic_freeze_simq(struct aic_softc *aic) 269{ 270 xpt_freeze_simq(aic->platform_data->sim, /*count*/1); 271} 272 273static __inline void 274aic_release_simq(struct aic_softc *aic) 275{ 276 xpt_release_simq(aic->platform_data->sim, /*run queue*/TRUE); 277} 278/********************************* Debug **************************************/ 279static __inline void ahd_print_path(struct ahd_softc *, struct scb *); 280static __inline void ahd_platform_dump_card_state(struct ahd_softc *ahd); 281 282static __inline void 283ahd_print_path(struct ahd_softc *ahd, struct scb *scb) 284{ 285 xpt_print_path(scb->io_ctx->ccb_h.path); 286} 287 288static __inline void 289ahd_platform_dump_card_state(struct ahd_softc *ahd) 290{ 291 /* Nothing to do here for FreeBSD */ 292} 293/**************************** Transfer Settings *******************************/ 294void ahd_notify_xfer_settings_change(struct ahd_softc *, 295 struct ahd_devinfo *); 296void ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *, 297 int /*enable*/); 298 299/************************* Initialization/Teardown ****************************/ 300int ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg); 301void ahd_platform_free(struct ahd_softc *ahd); 302int ahd_map_int(struct ahd_softc *ahd); 303int ahd_attach(struct ahd_softc *); 304int ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd); 305int ahd_detach(device_t); 306#define ahd_platform_init(arg) 307 308 309/****************************** Interrupts ************************************/ 310void ahd_platform_intr(void *); 311static __inline void ahd_platform_flushwork(struct ahd_softc *ahd); 312static __inline void 313ahd_platform_flushwork(struct ahd_softc *ahd) 314{ 315} 316 317/************************ Misc Function Declarations **************************/ 318void ahd_done(struct ahd_softc *ahd, struct scb *scb); 319void ahd_send_async(struct ahd_softc *, char /*channel*/, 320 u_int /*target*/, u_int /*lun*/, ac_code, void *arg); 321#endif /* _AIC79XX_FREEBSD_H_ */ 322