aic79xx_osm.h revision 158651
1/*- 2 * FreeBSD platform specific driver option settings, data structures, 3 * function declarations and includes. 4 * 5 * Copyright (c) 1994-2001 Justin T. Gibbs. 6 * Copyright (c) 2001-2002 Adaptec Inc. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions, and the following disclaimer, 14 * without modification. 15 * 2. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * Alternatively, this software may be distributed under the terms of the 19 * GNU Public License ("GPL"). 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.h#23 $ 34 * 35 * $FreeBSD: head/sys/dev/aic7xxx/aic79xx_osm.h 158651 2006-05-16 14:37:58Z phk $ 36 */ 37 38#ifndef _AIC79XX_FREEBSD_H_ 39#define _AIC79XX_FREEBSD_H_ 40 41#include <opt_aic79xx.h> /* for config options */ 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/bus.h> /* For device_t */ 46#if __FreeBSD_version >= 500000 47#include <sys/endian.h> 48#endif 49#include <sys/eventhandler.h> 50#include <sys/kernel.h> 51#include <sys/malloc.h> 52#include <sys/module.h> 53#include <sys/queue.h> 54 55#define AIC_PCI_CONFIG 1 56#include <machine/bus.h> 57#include <machine/endian.h> 58#include <machine/resource.h> 59 60#include <sys/rman.h> 61 62#if __FreeBSD_version >= 500000 63#include <dev/pci/pcireg.h> 64#include <dev/pci/pcivar.h> 65#else 66#include <pci/pcireg.h> 67#include <pci/pcivar.h> 68#endif 69 70#include <cam/cam.h> 71#include <cam/cam_ccb.h> 72#include <cam/cam_debug.h> 73#include <cam/cam_sim.h> 74#include <cam/cam_xpt_sim.h> 75 76#include <cam/scsi/scsi_all.h> 77#include <cam/scsi/scsi_message.h> 78#include <cam/scsi/scsi_iu.h> 79 80#ifdef CAM_NEW_TRAN_CODE 81#define AHD_NEW_TRAN_SETTINGS 82#endif /* CAM_NEW_TRAN_CODE */ 83 84/****************************** Platform Macros *******************************/ 85#define SIM_IS_SCSIBUS_B(ahd, sim) \ 86 (0) 87#define SIM_CHANNEL(ahd, sim) \ 88 ('A') 89#define SIM_SCSI_ID(ahd, sim) \ 90 (ahd->our_id) 91#define SIM_PATH(ahd, sim) \ 92 (ahd->platform_data->path) 93#define BUILD_SCSIID(ahd, sim, target_id, our_id) \ 94 ((((target_id) << TID_SHIFT) & TID) | (our_id)) 95 96 97#define SCB_GET_SIM(ahd, scb) \ 98 ((ahd)->platform_data->sim) 99 100#ifndef offsetof 101#define offsetof(type, member) ((size_t)(&((type *)0)->member)) 102#endif 103 104/************************ Tunable Driver Parameters **************************/ 105/* 106 * The number of dma segments supported. The sequencer can handle any number 107 * of physically contiguous S/G entrys. To reduce the driver's memory 108 * consumption, we limit the number supported to be sufficient to handle 109 * the largest mapping supported by the kernel, MAXPHYS. Assuming the 110 * transfer is as fragmented as possible and unaligned, this turns out to 111 * be the number of paged sized transfers in MAXPHYS plus an extra element 112 * to handle any unaligned residual. The sequencer fetches SG elements 113 * in cacheline sized chucks, so make the number per-transaction an even 114 * multiple of 16 which should align us on even the largest of cacheline 115 * boundaries. 116 */ 117#define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16)) 118 119/* This driver supports target mode */ 120#ifdef NOT_YET 121#define AHD_TARGET_MODE 1 122#endif 123 124/************************** Softc/SCB Platform Data ***************************/ 125struct ahd_platform_data { 126 /* 127 * Hooks into the XPT. 128 */ 129 struct cam_sim *sim; 130 struct cam_path *path; 131 132 int regs_res_type[2]; 133 int regs_res_id[2]; 134 int irq_res_type; 135 struct resource *regs[2]; 136 struct resource *irq; 137 void *ih; 138 eventhandler_tag eh; 139 struct proc *recovery_thread; 140}; 141 142struct scb_platform_data { 143}; 144 145/***************************** Core Includes **********************************/ 146#ifdef AHD_REG_PRETTY_PRINT 147#define AIC_DEBUG_REGISTERS 1 148#else 149#define AIC_DEBUG_REGISTERS 0 150#endif 151#define AIC_CORE_INCLUDE <dev/aic7xxx/aic79xx.h> 152#define AIC_LIB_PREFIX ahd 153#define AIC_CONST_PREFIX AHD 154#include <dev/aic7xxx/aic_osm_lib.h> 155 156/*************************** Device Access ************************************/ 157#define ahd_inb(ahd, port) \ 158 bus_space_read_1((ahd)->tags[(port) >> 8], \ 159 (ahd)->bshs[(port) >> 8], (port) & 0xFF) 160 161#define ahd_outb(ahd, port, value) \ 162 bus_space_write_1((ahd)->tags[(port) >> 8], \ 163 (ahd)->bshs[(port) >> 8], (port) & 0xFF, value) 164 165#define ahd_inw_atomic(ahd, port) \ 166 aic_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8], \ 167 (ahd)->bshs[(port) >> 8], (port) & 0xFF)) 168 169#define ahd_outw_atomic(ahd, port, value) \ 170 bus_space_write_2((ahd)->tags[(port) >> 8], \ 171 (ahd)->bshs[(port) >> 8], \ 172 (port & 0xFF), aic_htole16(value)) 173 174#define ahd_outsb(ahd, port, valp, count) \ 175 bus_space_write_multi_1((ahd)->tags[(port) >> 8], \ 176 (ahd)->bshs[(port) >> 8], \ 177 (port & 0xFF), valp, count) 178 179#define ahd_insb(ahd, port, valp, count) \ 180 bus_space_read_multi_1((ahd)->tags[(port) >> 8], \ 181 (ahd)->bshs[(port) >> 8], \ 182 (port & 0xFF), valp, count) 183 184static __inline void ahd_flush_device_writes(struct ahd_softc *); 185 186static __inline void 187ahd_flush_device_writes(struct ahd_softc *ahd) 188{ 189 /* XXX Is this sufficient for all architectures??? */ 190 ahd_inb(ahd, INTSTAT); 191} 192 193/**************************** Locking Primitives ******************************/ 194/* Lock protecting internal data structures */ 195static __inline void ahd_lockinit(struct ahd_softc *); 196static __inline void ahd_lock(struct ahd_softc *, unsigned long *flags); 197static __inline void ahd_unlock(struct ahd_softc *, unsigned long *flags); 198 199/* Lock held during command compeletion to the upper layer */ 200static __inline void ahd_done_lockinit(struct ahd_softc *); 201static __inline void ahd_done_lock(struct ahd_softc *, unsigned long *flags); 202static __inline void ahd_done_unlock(struct ahd_softc *, unsigned long *flags); 203 204/* Lock held during ahd_list manipulation and ahd softc frees */ 205static __inline void ahd_list_lockinit(void); 206static __inline void ahd_list_lock(unsigned long *flags); 207static __inline void ahd_list_unlock(unsigned long *flags); 208 209static __inline void 210ahd_lockinit(struct ahd_softc *ahd) 211{ 212} 213 214static __inline void 215ahd_lock(struct ahd_softc *ahd, unsigned long *flags) 216{ 217 *flags = splcam(); 218} 219 220static __inline void 221ahd_unlock(struct ahd_softc *ahd, unsigned long *flags) 222{ 223 splx(*flags); 224} 225 226/* Lock held during command compeletion to the upper layer */ 227static __inline void 228ahd_done_lockinit(struct ahd_softc *ahd) 229{ 230} 231 232static __inline void 233ahd_done_lock(struct ahd_softc *ahd, unsigned long *flags) 234{ 235} 236 237static __inline void 238ahd_done_unlock(struct ahd_softc *ahd, unsigned long *flags) 239{ 240} 241 242/* Lock held during ahd_list manipulation and ahd softc frees */ 243static __inline void 244ahd_list_lockinit(void) 245{ 246} 247 248static __inline void 249ahd_list_lock(unsigned long *flags) 250{ 251} 252 253static __inline void 254ahd_list_unlock(unsigned long *flags) 255{ 256} 257 258/********************************** PCI ***************************************/ 259int ahd_pci_map_registers(struct ahd_softc *ahd); 260int ahd_pci_map_int(struct ahd_softc *ahd); 261 262/************************** Transaction Operations ****************************/ 263static __inline void aic_freeze_simq(struct aic_softc*); 264static __inline void aic_release_simq(struct aic_softc*); 265 266static __inline void 267aic_freeze_simq(struct aic_softc *aic) 268{ 269 xpt_freeze_simq(aic->platform_data->sim, /*count*/1); 270} 271 272static __inline void 273aic_release_simq(struct aic_softc *aic) 274{ 275 xpt_release_simq(aic->platform_data->sim, /*run queue*/TRUE); 276} 277/********************************* Debug **************************************/ 278static __inline void ahd_print_path(struct ahd_softc *, struct scb *); 279static __inline void ahd_platform_dump_card_state(struct ahd_softc *ahd); 280 281static __inline void 282ahd_print_path(struct ahd_softc *ahd, struct scb *scb) 283{ 284 xpt_print_path(scb->io_ctx->ccb_h.path); 285} 286 287static __inline void 288ahd_platform_dump_card_state(struct ahd_softc *ahd) 289{ 290 /* Nothing to do here for FreeBSD */ 291} 292/**************************** Transfer Settings *******************************/ 293void ahd_notify_xfer_settings_change(struct ahd_softc *, 294 struct ahd_devinfo *); 295void ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *, 296 int /*enable*/); 297 298/************************* Initialization/Teardown ****************************/ 299int ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg); 300void ahd_platform_free(struct ahd_softc *ahd); 301int ahd_map_int(struct ahd_softc *ahd); 302int ahd_attach(struct ahd_softc *); 303int ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd); 304int ahd_detach(device_t); 305#define ahd_platform_init(arg) 306 307 308/****************************** Interrupts ************************************/ 309void ahd_platform_intr(void *); 310static __inline void ahd_platform_flushwork(struct ahd_softc *ahd); 311static __inline void 312ahd_platform_flushwork(struct ahd_softc *ahd) 313{ 314} 315 316/************************ Misc Function Declarations **************************/ 317void ahd_done(struct ahd_softc *ahd, struct scb *scb); 318void ahd_send_async(struct ahd_softc *, char /*channel*/, 319 u_int /*target*/, u_int /*lun*/, ac_code, void *arg); 320#endif /* _AIC79XX_FREEBSD_H_ */ 321