/*-1* FreeBSD platform specific driver option settings, data structures,2* function declarations and includes.3*4* Copyright (c) 1994-2001 Justin T. Gibbs.5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions, and the following disclaimer,12* without modification.13* 2. The name of the author may not be used to endorse or promote products14* derived from this software without specific prior written permission.15*16* Alternatively, this software may be distributed under the terms of the17* GNU Public License ("GPL").18*19* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR23* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*31* $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.h#18 $32*/3334#ifndef _AIC7XXX_FREEBSD_H_35#define _AIC7XXX_FREEBSD_H_3637#include "opt_aic7xxx.h" /* for config options */3839#include <sys/param.h>40#include <sys/systm.h>41#include <sys/bus.h> /* For device_t */42#include <sys/endian.h>43#include <sys/eventhandler.h>44#include <sys/kernel.h>45#include <sys/malloc.h>46#include <sys/module.h>47#include <sys/queue.h>4849#define AIC_PCI_CONFIG 150#include <machine/bus.h>51#include <machine/endian.h>52#include <machine/resource.h>5354#include <sys/rman.h>5556#include <dev/pci/pcireg.h>57#include <dev/pci/pcivar.h>5859#include <cam/cam.h>60#include <cam/cam_ccb.h>61#include <cam/cam_debug.h>62#include <cam/cam_sim.h>63#include <cam/cam_xpt_sim.h>6465#include <cam/scsi/scsi_all.h>66#include <cam/scsi/scsi_message.h>6768/****************************** Platform Macros *******************************/69#define SIM_IS_SCSIBUS_B(ahc, sim) \70((sim) == ahc->platform_data->sim_b)71#define SIM_CHANNEL(ahc, sim) \72(((sim) == ahc->platform_data->sim_b) ? 'B' : 'A')73#define SIM_SCSI_ID(ahc, sim) \74(((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id)75#define SIM_PATH(ahc, sim) \76(((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \77: ahc->platform_data->path)78#define BUILD_SCSIID(ahc, sim, target_id, our_id) \79((((target_id) << TID_SHIFT) & TID) | (our_id) \80| (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0))8182#define SCB_GET_SIM(ahc, scb) \83(SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \84: (ahc)->platform_data->sim_b)8586#ifndef offsetof87#define offsetof(type, member) ((size_t)(&((type *)0)->member))88#endif8990/************************ Tunable Driver Parameters **************************/91/*92* The number of dma segments supported. The sequencer can handle any number93* of physically contiguous S/G entrys. To reduce the driver's memory94* consumption, we limit the number supported to be sufficient to handle95* the largest mapping supported by the legacy kernel MAXPHYS setting of96* 128K. This can be increased once some testing is done. Assuming the97* be the number of paged sized transfers in MAXPHYS plus an extra element98* to handle any unaligned residual. The sequencer fetches SG elements99* in cacheline sized chucks, so make the number per-transaction an even100* multiple of 16 which should align us on even the largest of cacheline101* boundaries.102*/103#define AHC_MAXPHYS (128 * 1024)104#define AHC_NSEG (roundup(btoc(AHC_MAXPHYS) + 1, 16))105106/* This driver supports target mode */107#define AHC_TARGET_MODE 1108109/************************** Softc/SCB Platform Data ***************************/110struct ahc_platform_data {111/*112* Hooks into the XPT.113*/114struct cam_sim *sim;115struct cam_sim *sim_b;116struct cam_path *path;117struct cam_path *path_b;118119int regs_res_type;120int regs_res_id;121int irq_res_type;122struct resource *regs;123struct resource *irq;124void *ih;125eventhandler_tag eh;126struct proc *recovery_thread;127struct mtx mtx;128};129130struct scb_platform_data {131};132133/***************************** Core Includes **********************************/134#ifdef AHC_REG_PRETTY_PRINT135#define AIC_DEBUG_REGISTERS 1136#else137#define AIC_DEBUG_REGISTERS 0138#endif139#define AIC_CORE_INCLUDE <dev/aic7xxx/aic7xxx.h>140#define AIC_LIB_PREFIX ahc141#define AIC_CONST_PREFIX AHC142#include <dev/aic7xxx/aic_osm_lib.h>143144/*************************** Device Access ************************************/145#define ahc_inb(ahc, port) \146bus_space_read_1((ahc)->tag, (ahc)->bsh, port)147148#define ahc_outb(ahc, port, value) \149bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)150151#define ahc_outsb(ahc, port, valp, count) \152bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)153154#define ahc_insb(ahc, port, valp, count) \155bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)156157static __inline void ahc_flush_device_writes(struct ahc_softc *);158159static __inline void160ahc_flush_device_writes(struct ahc_softc *ahc)161{162/* XXX Is this sufficient for all architectures??? */163ahc_inb(ahc, INTSTAT);164}165166/**************************** Locking Primitives ******************************/167/* Lock protecting internal data structures */168static __inline void ahc_lockinit(struct ahc_softc *);169static __inline void ahc_lock(struct ahc_softc *);170static __inline void ahc_unlock(struct ahc_softc *);171172static __inline void173ahc_lockinit(struct ahc_softc *ahc)174{175mtx_init(&ahc->platform_data->mtx, "ahc_lock", NULL, MTX_DEF);176}177178static __inline void179ahc_lock(struct ahc_softc *ahc)180{181mtx_lock(&ahc->platform_data->mtx);182}183184static __inline void185ahc_unlock(struct ahc_softc *ahc)186{187mtx_unlock(&ahc->platform_data->mtx);188}189190/************************* Initialization/Teardown ****************************/191int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);192void ahc_platform_free(struct ahc_softc *ahc);193int ahc_map_int(struct ahc_softc *ahc);194int ahc_attach(struct ahc_softc *);195int ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc);196int ahc_detach(device_t);197198/********************************** PCI ***************************************/199#ifdef AIC_PCI_CONFIG200int ahc_pci_map_registers(struct ahc_softc *ahc);201#define ahc_pci_map_int ahc_map_int202#endif /*AIC_PCI_CONFIG*/203204/******************************** VL/EISA/ISA *********************************/205int aic7770_map_registers(struct ahc_softc *ahc, u_int port);206static __inline int aic7770_map_int(struct ahc_softc *, int);207208static __inline int209aic7770_map_int(struct ahc_softc *ahc, int irq)210{211/*212* The IRQ is unused in the FreeBSD213* implementation since the ISA attachment214* registers the IRQ with newbus before215* the core is called.216*/217return ahc_map_int(ahc);218}219220/********************************* Debug **************************************/221static __inline void ahc_print_path(struct ahc_softc *, struct scb *);222static __inline void ahc_platform_dump_card_state(struct ahc_softc *ahc);223224static __inline void225ahc_print_path(struct ahc_softc *ahc, struct scb *scb)226{227xpt_print_path(scb->io_ctx->ccb_h.path);228}229230static __inline void231ahc_platform_dump_card_state(struct ahc_softc *ahc)232{233/* Nothing to do here for FreeBSD */234}235/**************************** Transfer Settings *******************************/236void ahc_notify_xfer_settings_change(struct ahc_softc *,237struct ahc_devinfo *);238void ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *,239int /*enable*/);240241/****************************** Interrupts ************************************/242void ahc_platform_intr(void *);243static __inline void ahc_platform_flushwork(struct ahc_softc *ahc);244static __inline void245ahc_platform_flushwork(struct ahc_softc *ahc)246{247}248249/************************ Misc Function Declarations **************************/250void ahc_done(struct ahc_softc *ahc, struct scb *scb);251void ahc_send_async(struct ahc_softc *, char /*channel*/,252u_int /*target*/, u_int /*lun*/, ac_code, void *arg);253#endif /* _AIC7XXX_FREEBSD_H_ */254255256