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