aic79xx_osm.h revision 153072
1139749Simp/*- 297883Sgibbs * FreeBSD platform specific driver option settings, data structures, 397883Sgibbs * function declarations and includes. 497883Sgibbs * 597883Sgibbs * Copyright (c) 1994-2001 Justin T. Gibbs. 6102685Sgibbs * Copyright (c) 2001-2002 Adaptec Inc. 797883Sgibbs * All rights reserved. 897883Sgibbs * 997883Sgibbs * Redistribution and use in source and binary forms, with or without 1097883Sgibbs * modification, are permitted provided that the following conditions 1197883Sgibbs * are met: 1297883Sgibbs * 1. Redistributions of source code must retain the above copyright 1397883Sgibbs * notice, this list of conditions, and the following disclaimer, 1497883Sgibbs * without modification. 1597883Sgibbs * 2. The name of the author may not be used to endorse or promote products 1697883Sgibbs * derived from this software without specific prior written permission. 1797883Sgibbs * 1897883Sgibbs * Alternatively, this software may be distributed under the terms of the 1997883Sgibbs * GNU Public License ("GPL"). 2097883Sgibbs * 2197883Sgibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2297883Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2397883Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2497883Sgibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 2597883Sgibbs * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2697883Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2797883Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2897883Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2997883Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3097883Sgibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3197883Sgibbs * SUCH DAMAGE. 3297883Sgibbs * 33123579Sgibbs * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.h#23 $ 3497883Sgibbs * 3597883Sgibbs * $FreeBSD: head/sys/dev/aic7xxx/aic79xx_osm.h 153072 2005-12-04 02:12:43Z ru $ 3697883Sgibbs */ 3797883Sgibbs 3897883Sgibbs#ifndef _AIC79XX_FREEBSD_H_ 3997883Sgibbs#define _AIC79XX_FREEBSD_H_ 4097883Sgibbs 4197883Sgibbs#include <opt_aic79xx.h> /* for config options */ 4297883Sgibbs 4397883Sgibbs#include <sys/param.h> 4497883Sgibbs#include <sys/systm.h> 4597883Sgibbs#include <sys/bus.h> /* For device_t */ 46102685Sgibbs#if __FreeBSD_version >= 500000 47102685Sgibbs#include <sys/endian.h> 48102685Sgibbs#endif 4997883Sgibbs#include <sys/eventhandler.h> 5097883Sgibbs#include <sys/kernel.h> 5197883Sgibbs#include <sys/malloc.h> 52129879Sphk#include <sys/module.h> 5397883Sgibbs#include <sys/queue.h> 5497883Sgibbs 55123579Sgibbs#define AIC_PCI_CONFIG 1 5697883Sgibbs#include <machine/bus.h> 5797883Sgibbs#include <machine/endian.h> 5897883Sgibbs#include <machine/clock.h> 5997883Sgibbs#include <machine/resource.h> 6097883Sgibbs 6197883Sgibbs#include <sys/rman.h> 6297883Sgibbs 63119277Simp#if __FreeBSD_version >= 500000 64119277Simp#include <dev/pci/pcireg.h> 65119277Simp#include <dev/pci/pcivar.h> 66119277Simp#else 6797883Sgibbs#include <pci/pcireg.h> 6897883Sgibbs#include <pci/pcivar.h> 69119277Simp#endif 7097883Sgibbs 7197883Sgibbs#include <cam/cam.h> 7297883Sgibbs#include <cam/cam_ccb.h> 7397883Sgibbs#include <cam/cam_debug.h> 7497883Sgibbs#include <cam/cam_sim.h> 7597883Sgibbs#include <cam/cam_xpt_sim.h> 7697883Sgibbs 7797883Sgibbs#include <cam/scsi/scsi_all.h> 7897883Sgibbs#include <cam/scsi/scsi_message.h> 7997883Sgibbs#include <cam/scsi/scsi_iu.h> 8097883Sgibbs 8197883Sgibbs#ifdef CAM_NEW_TRAN_CODE 8297883Sgibbs#define AHD_NEW_TRAN_SETTINGS 8397883Sgibbs#endif /* CAM_NEW_TRAN_CODE */ 8497883Sgibbs 8597883Sgibbs/****************************** Platform Macros *******************************/ 8697883Sgibbs#define SIM_IS_SCSIBUS_B(ahd, sim) \ 8797883Sgibbs (0) 8897883Sgibbs#define SIM_CHANNEL(ahd, sim) \ 8997883Sgibbs ('A') 9097883Sgibbs#define SIM_SCSI_ID(ahd, sim) \ 9197883Sgibbs (ahd->our_id) 9297883Sgibbs#define SIM_PATH(ahd, sim) \ 9397883Sgibbs (ahd->platform_data->path) 9497883Sgibbs#define BUILD_SCSIID(ahd, sim, target_id, our_id) \ 9597883Sgibbs ((((target_id) << TID_SHIFT) & TID) | (our_id)) 9697883Sgibbs 9797883Sgibbs 9897883Sgibbs#define SCB_GET_SIM(ahd, scb) \ 9997883Sgibbs ((ahd)->platform_data->sim) 10097883Sgibbs 10197883Sgibbs#ifndef offsetof 10297883Sgibbs#define offsetof(type, member) ((size_t)(&((type *)0)->member)) 10397883Sgibbs#endif 10497883Sgibbs 10597883Sgibbs/************************ Tunable Driver Parameters **************************/ 10697883Sgibbs/* 10797883Sgibbs * The number of dma segments supported. The sequencer can handle any number 10897883Sgibbs * of physically contiguous S/G entrys. To reduce the driver's memory 10997883Sgibbs * consumption, we limit the number supported to be sufficient to handle 11097883Sgibbs * the largest mapping supported by the kernel, MAXPHYS. Assuming the 11197883Sgibbs * transfer is as fragmented as possible and unaligned, this turns out to 11297883Sgibbs * be the number of paged sized transfers in MAXPHYS plus an extra element 11397883Sgibbs * to handle any unaligned residual. The sequencer fetches SG elements 11497883Sgibbs * in cacheline sized chucks, so make the number per-transaction an even 11597883Sgibbs * multiple of 16 which should align us on even the largest of cacheline 11697883Sgibbs * boundaries. 11797883Sgibbs */ 11897883Sgibbs#define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16)) 11997883Sgibbs 12097883Sgibbs/* This driver supports target mode */ 121153072Sru#ifdef NOT_YET 12297883Sgibbs#define AHD_TARGET_MODE 1 12397883Sgibbs#endif 12497883Sgibbs 12597883Sgibbs/************************** Softc/SCB Platform Data ***************************/ 12697883Sgibbsstruct ahd_platform_data { 12797883Sgibbs /* 12897883Sgibbs * Hooks into the XPT. 12997883Sgibbs */ 13097883Sgibbs struct cam_sim *sim; 13197883Sgibbs struct cam_path *path; 13297883Sgibbs 13397883Sgibbs int regs_res_type[2]; 13497883Sgibbs int regs_res_id[2]; 13597883Sgibbs int irq_res_type; 13697883Sgibbs struct resource *regs[2]; 13797883Sgibbs struct resource *irq; 13897883Sgibbs void *ih; 13997883Sgibbs eventhandler_tag eh; 140123579Sgibbs struct proc *recovery_thread; 14197883Sgibbs}; 14297883Sgibbs 14397883Sgibbsstruct scb_platform_data { 14497883Sgibbs}; 14597883Sgibbs 14697883Sgibbs/***************************** Core Includes **********************************/ 147102685Sgibbs#if AHD_REG_PRETTY_PRINT 148102685Sgibbs#define AIC_DEBUG_REGISTERS 1 149102685Sgibbs#else 150102685Sgibbs#define AIC_DEBUG_REGISTERS 0 151102685Sgibbs#endif 152123579Sgibbs#define AIC_CORE_INCLUDE <dev/aic7xxx/aic79xx.h> 153123579Sgibbs#define AIC_LIB_PREFIX ahd 154123579Sgibbs#define AIC_CONST_PREFIX AHD 155123579Sgibbs#include <dev/aic7xxx/aic_osm_lib.h> 15697883Sgibbs 15797883Sgibbs/*************************** Device Access ************************************/ 15897883Sgibbs#define ahd_inb(ahd, port) \ 15997883Sgibbs bus_space_read_1((ahd)->tags[(port) >> 8], \ 16097883Sgibbs (ahd)->bshs[(port) >> 8], (port) & 0xFF) 16197883Sgibbs 16297883Sgibbs#define ahd_outb(ahd, port, value) \ 16397883Sgibbs bus_space_write_1((ahd)->tags[(port) >> 8], \ 16497883Sgibbs (ahd)->bshs[(port) >> 8], (port) & 0xFF, value) 16597883Sgibbs 16697883Sgibbs#define ahd_inw_atomic(ahd, port) \ 167123579Sgibbs aic_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8], \ 16897883Sgibbs (ahd)->bshs[(port) >> 8], (port) & 0xFF)) 16997883Sgibbs 17097883Sgibbs#define ahd_outw_atomic(ahd, port, value) \ 17197883Sgibbs bus_space_write_2((ahd)->tags[(port) >> 8], \ 17297883Sgibbs (ahd)->bshs[(port) >> 8], \ 173123579Sgibbs (port & 0xFF), aic_htole16(value)) 17497883Sgibbs 17597883Sgibbs#define ahd_outsb(ahd, port, valp, count) \ 17697883Sgibbs bus_space_write_multi_1((ahd)->tags[(port) >> 8], \ 17797883Sgibbs (ahd)->bshs[(port) >> 8], \ 17897883Sgibbs (port & 0xFF), valp, count) 17997883Sgibbs 18097883Sgibbs#define ahd_insb(ahd, port, valp, count) \ 18197883Sgibbs bus_space_read_multi_1((ahd)->tags[(port) >> 8], \ 18297883Sgibbs (ahd)->bshs[(port) >> 8], \ 18397883Sgibbs (port & 0xFF), valp, count) 18497883Sgibbs 18597883Sgibbsstatic __inline void ahd_flush_device_writes(struct ahd_softc *); 18697883Sgibbs 18797883Sgibbsstatic __inline void 18897883Sgibbsahd_flush_device_writes(struct ahd_softc *ahd) 18997883Sgibbs{ 19097883Sgibbs /* XXX Is this sufficient for all architectures??? */ 19197883Sgibbs ahd_inb(ahd, INTSTAT); 19297883Sgibbs} 19397883Sgibbs 19497883Sgibbs/**************************** Locking Primitives ******************************/ 19597883Sgibbs/* Lock protecting internal data structures */ 19697883Sgibbsstatic __inline void ahd_lockinit(struct ahd_softc *); 19797883Sgibbsstatic __inline void ahd_lock(struct ahd_softc *, unsigned long *flags); 19897883Sgibbsstatic __inline void ahd_unlock(struct ahd_softc *, unsigned long *flags); 19997883Sgibbs 20097883Sgibbs/* Lock held during command compeletion to the upper layer */ 20197883Sgibbsstatic __inline void ahd_done_lockinit(struct ahd_softc *); 20297883Sgibbsstatic __inline void ahd_done_lock(struct ahd_softc *, unsigned long *flags); 20397883Sgibbsstatic __inline void ahd_done_unlock(struct ahd_softc *, unsigned long *flags); 20497883Sgibbs 205102685Sgibbs/* Lock held during ahd_list manipulation and ahd softc frees */ 20697883Sgibbsstatic __inline void ahd_list_lockinit(void); 20797883Sgibbsstatic __inline void ahd_list_lock(unsigned long *flags); 20897883Sgibbsstatic __inline void ahd_list_unlock(unsigned long *flags); 20997883Sgibbs 21097883Sgibbsstatic __inline void 21197883Sgibbsahd_lockinit(struct ahd_softc *ahd) 21297883Sgibbs{ 21397883Sgibbs} 21497883Sgibbs 21597883Sgibbsstatic __inline void 21697883Sgibbsahd_lock(struct ahd_softc *ahd, unsigned long *flags) 21797883Sgibbs{ 21897883Sgibbs *flags = splcam(); 21997883Sgibbs} 22097883Sgibbs 22197883Sgibbsstatic __inline void 22297883Sgibbsahd_unlock(struct ahd_softc *ahd, unsigned long *flags) 22397883Sgibbs{ 22497883Sgibbs splx(*flags); 22597883Sgibbs} 22697883Sgibbs 22797883Sgibbs/* Lock held during command compeletion to the upper layer */ 22897883Sgibbsstatic __inline void 22997883Sgibbsahd_done_lockinit(struct ahd_softc *ahd) 23097883Sgibbs{ 23197883Sgibbs} 23297883Sgibbs 23397883Sgibbsstatic __inline void 23497883Sgibbsahd_done_lock(struct ahd_softc *ahd, unsigned long *flags) 23597883Sgibbs{ 23697883Sgibbs} 23797883Sgibbs 23897883Sgibbsstatic __inline void 23997883Sgibbsahd_done_unlock(struct ahd_softc *ahd, unsigned long *flags) 24097883Sgibbs{ 24197883Sgibbs} 24297883Sgibbs 243102685Sgibbs/* Lock held during ahd_list manipulation and ahd softc frees */ 24497883Sgibbsstatic __inline void 245115336Sgibbsahd_list_lockinit(void) 24697883Sgibbs{ 24797883Sgibbs} 24897883Sgibbs 24997883Sgibbsstatic __inline void 25097883Sgibbsahd_list_lock(unsigned long *flags) 25197883Sgibbs{ 25297883Sgibbs} 25397883Sgibbs 25497883Sgibbsstatic __inline void 25597883Sgibbsahd_list_unlock(unsigned long *flags) 25697883Sgibbs{ 25797883Sgibbs} 25897883Sgibbs 259123579Sgibbs/********************************** PCI ***************************************/ 260123579Sgibbsint ahd_pci_map_registers(struct ahd_softc *ahd); 261123579Sgibbsint ahd_pci_map_int(struct ahd_softc *ahd); 262123579Sgibbs 26397883Sgibbs/************************** Transaction Operations ****************************/ 264123579Sgibbsstatic __inline void aic_freeze_simq(struct aic_softc*); 265123579Sgibbsstatic __inline void aic_release_simq(struct aic_softc*); 26697883Sgibbs 26797883Sgibbsstatic __inline void 268123579Sgibbsaic_freeze_simq(struct aic_softc *aic) 26997883Sgibbs{ 270123579Sgibbs xpt_freeze_simq(aic->platform_data->sim, /*count*/1); 27197883Sgibbs} 27297883Sgibbs 27397883Sgibbsstatic __inline void 274123579Sgibbsaic_release_simq(struct aic_softc *aic) 27597883Sgibbs{ 276123579Sgibbs xpt_release_simq(aic->platform_data->sim, /*run queue*/TRUE); 27797883Sgibbs} 27897883Sgibbs/********************************* Debug **************************************/ 27997883Sgibbsstatic __inline void ahd_print_path(struct ahd_softc *, struct scb *); 28097883Sgibbsstatic __inline void ahd_platform_dump_card_state(struct ahd_softc *ahd); 28197883Sgibbs 28297883Sgibbsstatic __inline void 28397883Sgibbsahd_print_path(struct ahd_softc *ahd, struct scb *scb) 28497883Sgibbs{ 28597883Sgibbs xpt_print_path(scb->io_ctx->ccb_h.path); 28697883Sgibbs} 28797883Sgibbs 28897883Sgibbsstatic __inline void 28997883Sgibbsahd_platform_dump_card_state(struct ahd_softc *ahd) 29097883Sgibbs{ 29197883Sgibbs /* Nothing to do here for FreeBSD */ 29297883Sgibbs} 29397883Sgibbs/**************************** Transfer Settings *******************************/ 29497883Sgibbsvoid ahd_notify_xfer_settings_change(struct ahd_softc *, 29597883Sgibbs struct ahd_devinfo *); 29697883Sgibbsvoid ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *, 29797883Sgibbs int /*enable*/); 29897883Sgibbs 29997883Sgibbs/************************* Initialization/Teardown ****************************/ 30097883Sgibbsint ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg); 30197883Sgibbsvoid ahd_platform_free(struct ahd_softc *ahd); 30297883Sgibbsint ahd_map_int(struct ahd_softc *ahd); 30397883Sgibbsint ahd_attach(struct ahd_softc *); 30497883Sgibbsint ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd); 30597883Sgibbsint ahd_detach(device_t); 306107437Sscottl#define ahd_platform_init(arg) 30797883Sgibbs 308107437Sscottl 30997883Sgibbs/****************************** Interrupts ************************************/ 31097883Sgibbsvoid ahd_platform_intr(void *); 31197883Sgibbsstatic __inline void ahd_platform_flushwork(struct ahd_softc *ahd); 31297883Sgibbsstatic __inline void 31397883Sgibbsahd_platform_flushwork(struct ahd_softc *ahd) 31497883Sgibbs{ 31597883Sgibbs} 31697883Sgibbs 31797883Sgibbs/************************ Misc Function Declarations **************************/ 31897883Sgibbsvoid ahd_done(struct ahd_softc *ahd, struct scb *scb); 31997883Sgibbsvoid ahd_send_async(struct ahd_softc *, char /*channel*/, 32097883Sgibbs u_int /*target*/, u_int /*lun*/, ac_code, void *arg); 32197883Sgibbs#endif /* _AIC79XX_FREEBSD_H_ */ 322