Index: head/sys/dev/aic7xxx/aic79xx_osm.h =================================================================== --- head/sys/dev/aic7xxx/aic79xx_osm.h (revision 358353) +++ head/sys/dev/aic7xxx/aic79xx_osm.h (revision 358354) @@ -1,280 +1,273 @@ /*- * FreeBSD platform specific driver option settings, data structures, * function declarations and includes. * * Copyright (c) 1994-2001 Justin T. Gibbs. * Copyright (c) 2001-2002 Adaptec Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU Public License ("GPL"). * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.h#23 $ * * $FreeBSD$ */ #ifndef _AIC79XX_FREEBSD_H_ #define _AIC79XX_FREEBSD_H_ #include "opt_aic79xx.h" /* for config options */ #include #include #include /* For device_t */ -#if __FreeBSD_version >= 500000 #include -#endif #include #include #include #include #include #include #define AIC_PCI_CONFIG 1 #include #include #include #include -#if __FreeBSD_version >= 500000 #include #include -#else -#include -#include -#endif #include #include #include #include #include #include #include #include /****************************** Platform Macros *******************************/ #define SIM_IS_SCSIBUS_B(ahd, sim) \ (0) #define SIM_CHANNEL(ahd, sim) \ ('A') #define SIM_SCSI_ID(ahd, sim) \ (ahd->our_id) #define SIM_PATH(ahd, sim) \ (ahd->platform_data->path) #define BUILD_SCSIID(ahd, sim, target_id, our_id) \ ((((target_id) << TID_SHIFT) & TID) | (our_id)) #define SCB_GET_SIM(ahd, scb) \ ((ahd)->platform_data->sim) #ifndef offsetof #define offsetof(type, member) ((size_t)(&((type *)0)->member)) #endif /************************ Tunable Driver Parameters **************************/ /* * The number of dma segments supported. The sequencer can handle any number * of physically contiguous S/G entrys. To reduce the driver's memory * consumption, we limit the number supported to be sufficient to handle * the largest mapping supported by the legacy kernel MAXPHYS setting of * 128K. This can be increased once some testing is done. Assuming the * transfer is as fragmented as possible and unaligned, this turns out to * be the number of paged sized transfers in MAXPHYS plus an extra element * to handle any unaligned residual. The sequencer fetches SG elements * in cacheline sized chucks, so make the number per-transaction an even * multiple of 16 which should align us on even the largest of cacheline * boundaries. */ #define AHD_MAXPHYS (128 * 1024) #define AHD_NSEG (roundup(btoc(AHD_MAXPHYS) + 1, 16)) /* This driver supports target mode */ #ifdef NOT_YET #define AHD_TARGET_MODE 1 #endif /************************** Softc/SCB Platform Data ***************************/ struct ahd_platform_data { /* * Hooks into the XPT. */ struct cam_sim *sim; struct cam_path *path; int regs_res_type[2]; int regs_res_id[2]; int irq_res_type; struct resource *regs[2]; struct resource *irq; void *ih; eventhandler_tag eh; struct proc *recovery_thread; struct mtx mtx; }; struct scb_platform_data { }; /***************************** Core Includes **********************************/ #ifdef AHD_REG_PRETTY_PRINT #define AIC_DEBUG_REGISTERS 1 #else #define AIC_DEBUG_REGISTERS 0 #endif #define AIC_CORE_INCLUDE #define AIC_LIB_PREFIX ahd #define AIC_CONST_PREFIX AHD #include /*************************** Device Access ************************************/ #define ahd_inb(ahd, port) \ bus_space_read_1((ahd)->tags[(port) >> 8], \ (ahd)->bshs[(port) >> 8], (port) & 0xFF) #define ahd_outb(ahd, port, value) \ bus_space_write_1((ahd)->tags[(port) >> 8], \ (ahd)->bshs[(port) >> 8], (port) & 0xFF, value) #define ahd_inw_atomic(ahd, port) \ aic_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8], \ (ahd)->bshs[(port) >> 8], (port) & 0xFF)) #define ahd_outw_atomic(ahd, port, value) \ bus_space_write_2((ahd)->tags[(port) >> 8], \ (ahd)->bshs[(port) >> 8], \ (port & 0xFF), aic_htole16(value)) #define ahd_outsb(ahd, port, valp, count) \ bus_space_write_multi_1((ahd)->tags[(port) >> 8], \ (ahd)->bshs[(port) >> 8], \ (port & 0xFF), valp, count) #define ahd_insb(ahd, port, valp, count) \ bus_space_read_multi_1((ahd)->tags[(port) >> 8], \ (ahd)->bshs[(port) >> 8], \ (port & 0xFF), valp, count) static __inline void ahd_flush_device_writes(struct ahd_softc *); static __inline void ahd_flush_device_writes(struct ahd_softc *ahd) { /* XXX Is this sufficient for all architectures??? */ ahd_inb(ahd, INTSTAT); } /**************************** Locking Primitives ******************************/ /* Lock protecting internal data structures */ static __inline void ahd_lockinit(struct ahd_softc *); static __inline void ahd_lock(struct ahd_softc *); static __inline void ahd_unlock(struct ahd_softc *); static __inline void ahd_lockinit(struct ahd_softc *ahd) { mtx_init(&ahd->platform_data->mtx, "ahd_lock", NULL, MTX_DEF); } static __inline void ahd_lock(struct ahd_softc *ahd) { mtx_lock(&ahd->platform_data->mtx); } static __inline void ahd_unlock(struct ahd_softc *ahd) { mtx_unlock(&ahd->platform_data->mtx); } /********************************** PCI ***************************************/ int ahd_pci_map_registers(struct ahd_softc *ahd); int ahd_pci_map_int(struct ahd_softc *ahd); /************************** Transaction Operations ****************************/ static __inline void aic_freeze_simq(struct aic_softc*); static __inline void aic_release_simq(struct aic_softc*); static __inline void aic_freeze_simq(struct aic_softc *aic) { xpt_freeze_simq(aic->platform_data->sim, /*count*/1); } static __inline void aic_release_simq(struct aic_softc *aic) { xpt_release_simq(aic->platform_data->sim, /*run queue*/TRUE); } /********************************* Debug **************************************/ static __inline void ahd_print_path(struct ahd_softc *, struct scb *); static __inline void ahd_platform_dump_card_state(struct ahd_softc *ahd); static __inline void ahd_print_path(struct ahd_softc *ahd, struct scb *scb) { xpt_print_path(scb->io_ctx->ccb_h.path); } static __inline void ahd_platform_dump_card_state(struct ahd_softc *ahd) { /* Nothing to do here for FreeBSD */ } /**************************** Transfer Settings *******************************/ void ahd_notify_xfer_settings_change(struct ahd_softc *, struct ahd_devinfo *); void ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *, int /*enable*/); /************************* Initialization/Teardown ****************************/ int ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg); void ahd_platform_free(struct ahd_softc *ahd); int ahd_map_int(struct ahd_softc *ahd); int ahd_attach(struct ahd_softc *); int ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd); void ahd_sysctl(struct ahd_softc *ahd); int ahd_detach(device_t); #define ahd_platform_init(arg) /****************************** Interrupts ************************************/ void ahd_platform_intr(void *); static __inline void ahd_platform_flushwork(struct ahd_softc *ahd); static __inline void ahd_platform_flushwork(struct ahd_softc *ahd) { } /************************ Misc Function Declarations **************************/ void ahd_done(struct ahd_softc *ahd, struct scb *scb); void ahd_send_async(struct ahd_softc *, char /*channel*/, u_int /*target*/, u_int /*lun*/, ac_code, void *arg); #endif /* _AIC79XX_FREEBSD_H_ */ Index: head/sys/dev/aic7xxx/aic7xxx_osm.h =================================================================== --- head/sys/dev/aic7xxx/aic7xxx_osm.h (revision 358353) +++ head/sys/dev/aic7xxx/aic7xxx_osm.h (revision 358354) @@ -1,276 +1,259 @@ /*- * FreeBSD platform specific driver option settings, data structures, * function declarations and includes. * * Copyright (c) 1994-2001 Justin T. Gibbs. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU Public License ("GPL"). * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.h#18 $ * * $FreeBSD$ */ #ifndef _AIC7XXX_FREEBSD_H_ #define _AIC7XXX_FREEBSD_H_ #include "opt_aic7xxx.h" /* for config options */ #include #include #include /* For device_t */ -#if __FreeBSD_version >= 500000 #include -#endif #include #include #include #include #include -#if __FreeBSD_version < 500000 -#include -#else -#define NPCI 1 -#endif - -#if NPCI > 0 #define AIC_PCI_CONFIG 1 -#endif #include #include #include #include -#if NPCI > 0 -#if __FreeBSD_version >= 500000 #include #include -#else -#include -#include -#endif -#endif #include #include #include #include #include #include #include /*************************** Attachment Bookkeeping ***************************/ extern devclass_t ahc_devclass; /****************************** Platform Macros *******************************/ #define SIM_IS_SCSIBUS_B(ahc, sim) \ ((sim) == ahc->platform_data->sim_b) #define SIM_CHANNEL(ahc, sim) \ (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A') #define SIM_SCSI_ID(ahc, sim) \ (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id) #define SIM_PATH(ahc, sim) \ (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \ : ahc->platform_data->path) #define BUILD_SCSIID(ahc, sim, target_id, our_id) \ ((((target_id) << TID_SHIFT) & TID) | (our_id) \ | (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0)) #define SCB_GET_SIM(ahc, scb) \ (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \ : (ahc)->platform_data->sim_b) #ifndef offsetof #define offsetof(type, member) ((size_t)(&((type *)0)->member)) #endif /************************ Tunable Driver Parameters **************************/ /* * The number of dma segments supported. The sequencer can handle any number * of physically contiguous S/G entrys. To reduce the driver's memory * consumption, we limit the number supported to be sufficient to handle * the largest mapping supported by the legacy kernel MAXPHYS setting of * 128K. This can be increased once some testing is done. Assuming the * be the number of paged sized transfers in MAXPHYS plus an extra element * to handle any unaligned residual. The sequencer fetches SG elements * in cacheline sized chucks, so make the number per-transaction an even * multiple of 16 which should align us on even the largest of cacheline * boundaries. */ #define AHC_MAXPHYS (128 * 1024) #define AHC_NSEG (roundup(btoc(AHC_MAXPHYS) + 1, 16)) /* This driver supports target mode */ #define AHC_TARGET_MODE 1 /************************** Softc/SCB Platform Data ***************************/ struct ahc_platform_data { /* * Hooks into the XPT. */ struct cam_sim *sim; struct cam_sim *sim_b; struct cam_path *path; struct cam_path *path_b; int regs_res_type; int regs_res_id; int irq_res_type; struct resource *regs; struct resource *irq; void *ih; eventhandler_tag eh; struct proc *recovery_thread; struct mtx mtx; }; struct scb_platform_data { }; /***************************** Core Includes **********************************/ #ifdef AHC_REG_PRETTY_PRINT #define AIC_DEBUG_REGISTERS 1 #else #define AIC_DEBUG_REGISTERS 0 #endif #define AIC_CORE_INCLUDE #define AIC_LIB_PREFIX ahc #define AIC_CONST_PREFIX AHC #include /*************************** Device Access ************************************/ #define ahc_inb(ahc, port) \ bus_space_read_1((ahc)->tag, (ahc)->bsh, port) #define ahc_outb(ahc, port, value) \ bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value) #define ahc_outsb(ahc, port, valp, count) \ bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count) #define ahc_insb(ahc, port, valp, count) \ bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count) static __inline void ahc_flush_device_writes(struct ahc_softc *); static __inline void ahc_flush_device_writes(struct ahc_softc *ahc) { /* XXX Is this sufficient for all architectures??? */ ahc_inb(ahc, INTSTAT); } /**************************** Locking Primitives ******************************/ /* Lock protecting internal data structures */ static __inline void ahc_lockinit(struct ahc_softc *); static __inline void ahc_lock(struct ahc_softc *); static __inline void ahc_unlock(struct ahc_softc *); static __inline void ahc_lockinit(struct ahc_softc *ahc) { mtx_init(&ahc->platform_data->mtx, "ahc_lock", NULL, MTX_DEF); } static __inline void ahc_lock(struct ahc_softc *ahc) { mtx_lock(&ahc->platform_data->mtx); } static __inline void ahc_unlock(struct ahc_softc *ahc) { mtx_unlock(&ahc->platform_data->mtx); } /************************* Initialization/Teardown ****************************/ int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg); void ahc_platform_free(struct ahc_softc *ahc); int ahc_map_int(struct ahc_softc *ahc); int ahc_attach(struct ahc_softc *); int ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc); int ahc_detach(device_t); /********************************** PCI ***************************************/ #ifdef AIC_PCI_CONFIG int ahc_pci_map_registers(struct ahc_softc *ahc); #define ahc_pci_map_int ahc_map_int #endif /*AIC_PCI_CONFIG*/ /******************************** VL/EISA/ISA *********************************/ int aic7770_map_registers(struct ahc_softc *ahc, u_int port); static __inline int aic7770_map_int(struct ahc_softc *, int); static __inline int aic7770_map_int(struct ahc_softc *ahc, int irq) { /* * The IRQ is unused in the FreeBSD * implementation since the ISA attachment * registers the IRQ with newbus before * the core is called. */ return ahc_map_int(ahc); } /********************************* Debug **************************************/ static __inline void ahc_print_path(struct ahc_softc *, struct scb *); static __inline void ahc_platform_dump_card_state(struct ahc_softc *ahc); static __inline void ahc_print_path(struct ahc_softc *ahc, struct scb *scb) { xpt_print_path(scb->io_ctx->ccb_h.path); } static __inline void ahc_platform_dump_card_state(struct ahc_softc *ahc) { /* Nothing to do here for FreeBSD */ } /**************************** Transfer Settings *******************************/ void ahc_notify_xfer_settings_change(struct ahc_softc *, struct ahc_devinfo *); void ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *, int /*enable*/); /****************************** Interrupts ************************************/ void ahc_platform_intr(void *); static __inline void ahc_platform_flushwork(struct ahc_softc *ahc); static __inline void ahc_platform_flushwork(struct ahc_softc *ahc) { } /************************ Misc Function Declarations **************************/ void ahc_done(struct ahc_softc *ahc, struct scb *scb); void ahc_send_async(struct ahc_softc *, char /*channel*/, u_int /*target*/, u_int /*lun*/, ac_code, void *arg); #endif /* _AIC7XXX_FREEBSD_H_ */ Index: head/sys/dev/aic7xxx/aic_osm_lib.c =================================================================== --- head/sys/dev/aic7xxx/aic_osm_lib.c (revision 358353) +++ head/sys/dev/aic7xxx/aic_osm_lib.c (revision 358354) @@ -1,150 +1,133 @@ /*- * FreeBSD OSM Library for the aic7xxx aic79xx based Adaptec SCSI controllers * * Copyright (c) 1994-2002 Justin T. Gibbs. * Copyright (c) 2001-2003 Adaptec Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU Public License ("GPL"). * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic_osm_lib.c#5 $ */ #include __FBSDID("$FreeBSD$"); static void aic_recovery_thread(void *arg); void aic_set_recoveryscb(struct aic_softc *aic, struct scb *scb) { if ((scb->flags & SCB_RECOVERY_SCB) == 0) { struct scb *list_scb; scb->flags |= SCB_RECOVERY_SCB; AIC_SCB_DATA(aic)->recovery_scbs++; /* * Go through all of our pending SCBs and remove * any scheduled timeouts for them. We will reschedule * them after we've successfully fixed this problem. */ LIST_FOREACH(list_scb, &aic->pending_scbs, pending_links) { callout_stop(&scb->io_timer); } } } void aic_platform_timeout(void *arg) { struct scb *scb; scb = (struct scb *)arg; aic_lock(scb->aic_softc); aic_timeout(scb); aic_unlock(scb->aic_softc); } int aic_spawn_recovery_thread(struct aic_softc *aic) { int error; error = aic_kthread_create(aic_recovery_thread, aic, &aic->platform_data->recovery_thread, /*flags*/0, /*altstack*/0, "aic_recovery%d", aic->unit); return (error); } /* * Lock is not held on entry. */ void aic_terminate_recovery_thread(struct aic_softc *aic) { if (aic->platform_data->recovery_thread == NULL) { return; } aic->flags |= AIC_SHUTDOWN_RECOVERY; wakeup(aic); /* * Sleep on a slightly different location * for this interlock just for added safety. */ msleep(aic->platform_data, &aic->platform_data->mtx, PUSER, "thtrm", 0); } static void aic_recovery_thread(void *arg) { struct aic_softc *aic; aic = (struct aic_softc *)arg; aic_lock(aic); for (;;) { if (LIST_EMPTY(&aic->timedout_scbs) != 0 && (aic->flags & AIC_SHUTDOWN_RECOVERY) == 0) msleep(aic, &aic->platform_data->mtx, PUSER, "idle", 0); if ((aic->flags & AIC_SHUTDOWN_RECOVERY) != 0) break; aic_recover_commands(aic); } aic->platform_data->recovery_thread = NULL; wakeup(aic->platform_data); aic_unlock(aic); kproc_exit(0); } void aic_calc_geometry(struct ccb_calc_geometry *ccg, int extended) { -#if __FreeBSD_version >= 500000 cam_calc_geometry(ccg, extended); -#else - uint32_t size_mb; - uint32_t secs_per_cylinder; - - size_mb = ccg->volume_size / ((1024L * 1024L) / ccg->block_size); - if (size_mb > 1024 && extended) { - ccg->heads = 255; - ccg->secs_per_track = 63; - } else { - ccg->heads = 64; - ccg->secs_per_track = 32; - } - secs_per_cylinder = ccg->heads * ccg->secs_per_track; - ccg->cylinders = ccg->volume_size / secs_per_cylinder; - ccg->ccb_h.status = CAM_REQ_CMP; -#endif } Index: head/sys/dev/aic7xxx/aic_osm_lib.h =================================================================== --- head/sys/dev/aic7xxx/aic_osm_lib.h (revision 358353) +++ head/sys/dev/aic7xxx/aic_osm_lib.h (revision 358354) @@ -1,448 +1,405 @@ /*- * FreeBSD platform specific, shared driver option settings, data structures, * function declarations and includes. * * Copyright (c) 1994-2001 Justin T. Gibbs. * Copyright (c) 2001-2003 Adaptec Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU Public License ("GPL"). * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic_osm_lib.h#5 $ * * $FreeBSD$ */ /******************************** OS Includes *********************************/ -#if __FreeBSD_version >= 500000 #include -#endif /*************************** Library Symbol Mapping ***************************/ #define AIC_LIB_ENTRY_CONCAT(x, prefix) prefix ## x #define AIC_LIB_ENTRY_EXPAND(x, prefix) AIC_LIB_ENTRY_CONCAT(x, prefix) #define AIC_LIB_ENTRY(x) AIC_LIB_ENTRY_EXPAND(x, AIC_LIB_PREFIX) #define AIC_CONST_ENTRY(x) AIC_LIB_ENTRY_EXPAND(x,AIC_CONST_PREFIX) #define aic_softc AIC_LIB_ENTRY(_softc) #define aic_tailq AIC_LIB_ENTRY(_tailq) #define aic_transinfo AIC_LIB_ENTRY(_transinfo) #define aic_platform_data AIC_LIB_ENTRY(_platform_data) #define aic_devinfo AIC_LIB_ENTRY(_devinfo) #define aic_lock AIC_LIB_ENTRY(_lock) #define aic_unlock AIC_LIB_ENTRY(_unlock) #define aic_callback_t AIC_LIB_ENTRY(_callback_t) #define aic_platform_freeze_devq AIC_LIB_ENTRY(_platform_freeze_devq) #define aic_platform_abort_scbs AIC_LIB_ENTRY(_platform_abort_scbs) #define aic_platform_timeout AIC_LIB_ENTRY(_platform_timeout) #define aic_timeout AIC_LIB_ENTRY(_timeout) #define aic_set_recoveryscb AIC_LIB_ENTRY(_set_recoveryscb) #define aic_spawn_recovery_thread AIC_LIB_ENTRY(_spawn_recovery_thread) #define aic_wakeup_recovery_thread AIC_LIB_ENTRY(_wakeup_recovery_thread) #define aic_terminate_recovery_thread \ AIC_LIB_ENTRY(_terminate_recovery_thread) #define aic_recovery_thread AIC_LIB_ENTRY(_recovery_thread) #define aic_recover_commands AIC_LIB_ENTRY(_recover_commands) #define aic_calc_geometry AIC_LIB_ENTRY(_calc_geometry) #define AIC_RESOURCE_SHORTAGE AIC_CONST_ENTRY(_RESOURCE_SHORTAGE) #define AIC_SHUTDOWN_RECOVERY AIC_CONST_ENTRY(_SHUTDOWN_RECOVERY) /********************************* Byte Order *********************************/ -#if __FreeBSD_version >= 500000 #define aic_htobe16(x) htobe16(x) #define aic_htobe32(x) htobe32(x) #define aic_htobe64(x) htobe64(x) #define aic_htole16(x) htole16(x) #define aic_htole32(x) htole32(x) #define aic_htole64(x) htole64(x) #define aic_be16toh(x) be16toh(x) #define aic_be32toh(x) be32toh(x) #define aic_be64toh(x) be64toh(x) #define aic_le16toh(x) le16toh(x) #define aic_le32toh(x) le32toh(x) #define aic_le64toh(x) le64toh(x) -#else -#define aic_htobe16(x) (x) -#define aic_htobe32(x) (x) -#define aic_htobe64(x) (x) -#define aic_htole16(x) (x) -#define aic_htole32(x) (x) -#define aic_htole64(x) (x) -#define aic_be16toh(x) (x) -#define aic_be32toh(x) (x) -#define aic_be64toh(x) (x) -#define aic_le16toh(x) (x) -#define aic_le32toh(x) (x) -#define aic_le64toh(x) (x) -#endif - /************************* Forward Declarations *******************************/ typedef device_t aic_dev_softc_t; typedef union ccb *aic_io_ctx_t; struct aic_softc; struct scb; /*************************** Timer DataStructures *****************************/ typedef struct callout aic_timer_t; /****************************** Error Recovery ********************************/ void aic_set_recoveryscb(struct aic_softc *aic, struct scb *scb); callout_func_t aic_platform_timeout; int aic_spawn_recovery_thread(struct aic_softc *aic); void aic_terminate_recovery_thread(struct aic_softc *aic); static __inline void aic_wakeup_recovery_thread(struct aic_softc *aic); static __inline void aic_wakeup_recovery_thread(struct aic_softc *aic) { wakeup(aic); } /****************************** Kernel Threads ********************************/ -#if __FreeBSD_version > 500005 -#if __FreeBSD_version > 800001 #define aic_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ kproc_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) -#else -#define aic_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ - kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) -#endif -#else -#define aic_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ - kthread_create(func, farg, proc_ptr, fmtstr, arg) -#endif /******************************* Bus Space/DMA ********************************/ -#if __FreeBSD_version >= 501102 #define aic_dma_tag_create(aic, parent_tag, alignment, boundary, \ lowaddr, highaddr, filter, filterarg, \ maxsize, nsegments, maxsegsz, flags, \ dma_tagp) \ bus_dma_tag_create(parent_tag, alignment, boundary, \ lowaddr, highaddr, filter, filterarg, \ maxsize, nsegments, maxsegsz, flags, \ busdma_lock_mutex, &aic->platform_data->mtx, \ dma_tagp) -#else -#define aic_dma_tag_create(aic, parent_tag, alignment, boundary, \ - lowaddr, highaddr, filter, filterarg, \ - maxsize, nsegments, maxsegsz, flags, \ - dma_tagp) \ - bus_dma_tag_create(parent_tag, alignment, boundary, \ - lowaddr, highaddr, filter, filterarg, \ - maxsize, nsegments, maxsegsz, flags, \ - dma_tagp) -#endif #define aic_dma_tag_destroy(aic, tag) \ bus_dma_tag_destroy(tag) #define aic_dmamem_alloc(aic, dmat, vaddr, flags, mapp) \ bus_dmamem_alloc(dmat, vaddr, flags, mapp) #define aic_dmamem_free(aic, dmat, vaddr, map) \ bus_dmamem_free(dmat, vaddr, map) #define aic_dmamap_create(aic, tag, flags, mapp) \ bus_dmamap_create(tag, flags, mapp) #define aic_dmamap_destroy(aic, tag, map) \ bus_dmamap_destroy(tag, map) #define aic_dmamap_load(aic, dmat, map, addr, buflen, callback, \ callback_arg, flags) \ bus_dmamap_load(dmat, map, addr, buflen, callback, callback_arg, flags) #define aic_dmamap_unload(aic, tag, map) \ bus_dmamap_unload(tag, map) /* XXX Need to update Bus DMA for partial map syncs */ #define aic_dmamap_sync(aic, dma_tag, dmamap, offset, len, op) \ bus_dmamap_sync(dma_tag, dmamap, op) /***************************** Core Includes **********************************/ #include AIC_CORE_INCLUDE /***************************** Timer Facilities *******************************/ -#if __FreeBSD_version >= 500000 #define aic_timer_init(timer) callout_init(timer, /*mpsafe*/1) -#else -#define aic_timer_init callout_init -#endif #define aic_timer_stop callout_stop static __inline void aic_timer_reset(aic_timer_t *, u_int, aic_callback_t *, void *); static __inline u_int aic_get_timeout(struct scb *); static __inline void aic_scb_timer_reset(struct scb *, u_int); static __inline void aic_timer_reset(aic_timer_t *timer, u_int msec, aic_callback_t *func, void *arg) { uint64_t time; time = msec; time *= hz; time /= 1000; callout_reset(timer, time, func, arg); } static __inline u_int aic_get_timeout(struct scb *scb) { return (scb->io_ctx->ccb_h.timeout); } static __inline void aic_scb_timer_reset(struct scb *scb, u_int msec) { uint64_t time; time = msec; time *= hz; time /= 1000; callout_reset(&scb->io_timer, time, aic_platform_timeout, scb); } static __inline void aic_scb_timer_start(struct scb *scb) { if (AIC_SCB_DATA(scb->aic_softc)->recovery_scbs == 0 && scb->io_ctx->ccb_h.timeout != CAM_TIME_INFINITY) { aic_scb_timer_reset(scb, scb->io_ctx->ccb_h.timeout); } } /************************** Transaction Operations ****************************/ static __inline void aic_set_transaction_status(struct scb *, uint32_t); static __inline void aic_set_scsi_status(struct scb *, uint32_t); static __inline uint32_t aic_get_transaction_status(struct scb *); static __inline uint32_t aic_get_scsi_status(struct scb *); static __inline void aic_set_transaction_tag(struct scb *, int, u_int); static __inline u_long aic_get_transfer_length(struct scb *); static __inline int aic_get_transfer_dir(struct scb *); static __inline void aic_set_residual(struct scb *, u_long); static __inline void aic_set_sense_residual(struct scb *, u_long); static __inline u_long aic_get_residual(struct scb *); static __inline int aic_perform_autosense(struct scb *); static __inline uint32_t aic_get_sense_bufsize(struct aic_softc*, struct scb*); static __inline void aic_freeze_ccb(union ccb *ccb); static __inline void aic_freeze_scb(struct scb *scb); static __inline void aic_platform_freeze_devq(struct aic_softc *, struct scb *); static __inline int aic_platform_abort_scbs(struct aic_softc *aic, int target, char channel, int lun, u_int tag, role_t role, uint32_t status); static __inline void aic_set_transaction_status(struct scb *scb, uint32_t status) { scb->io_ctx->ccb_h.status &= ~CAM_STATUS_MASK; scb->io_ctx->ccb_h.status |= status; } static __inline void aic_set_scsi_status(struct scb *scb, uint32_t status) { scb->io_ctx->csio.scsi_status = status; } static __inline uint32_t aic_get_transaction_status(struct scb *scb) { return (scb->io_ctx->ccb_h.status & CAM_STATUS_MASK); } static __inline uint32_t aic_get_scsi_status(struct scb *scb) { return (scb->io_ctx->csio.scsi_status); } static __inline void aic_set_transaction_tag(struct scb *scb, int enabled, u_int type) { scb->io_ctx->csio.tag_action = type; if (enabled) scb->io_ctx->ccb_h.flags |= CAM_TAG_ACTION_VALID; else scb->io_ctx->ccb_h.flags &= ~CAM_TAG_ACTION_VALID; } static __inline u_long aic_get_transfer_length(struct scb *scb) { return (scb->io_ctx->csio.dxfer_len); } static __inline int aic_get_transfer_dir(struct scb *scb) { return (scb->io_ctx->ccb_h.flags & CAM_DIR_MASK); } static __inline void aic_set_residual(struct scb *scb, u_long resid) { scb->io_ctx->csio.resid = resid; } static __inline void aic_set_sense_residual(struct scb *scb, u_long resid) { scb->io_ctx->csio.sense_resid = resid; } static __inline u_long aic_get_residual(struct scb *scb) { return (scb->io_ctx->csio.resid); } static __inline int aic_perform_autosense(struct scb *scb) { return (!(scb->io_ctx->ccb_h.flags & CAM_DIS_AUTOSENSE)); } static __inline uint32_t aic_get_sense_bufsize(struct aic_softc *aic, struct scb *scb) { return (sizeof(struct scsi_sense_data)); } static __inline void aic_freeze_ccb(union ccb *ccb) { if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) { ccb->ccb_h.status |= CAM_DEV_QFRZN; xpt_freeze_devq(ccb->ccb_h.path, /*count*/1); } } static __inline void aic_freeze_scb(struct scb *scb) { aic_freeze_ccb(scb->io_ctx); } static __inline void aic_platform_freeze_devq(struct aic_softc *aic, struct scb *scb) { /* Nothing to do here for FreeBSD */ } static __inline int aic_platform_abort_scbs(struct aic_softc *aic, int target, char channel, int lun, u_int tag, role_t role, uint32_t status) { /* Nothing to do here for FreeBSD */ return (0); } static __inline void aic_platform_scb_free(struct aic_softc *aic, struct scb *scb) { /* What do we do to generically handle driver resource shortages??? */ if ((aic->flags & AIC_RESOURCE_SHORTAGE) != 0 && scb->io_ctx != NULL && (scb->io_ctx->ccb_h.status & CAM_RELEASE_SIMQ) == 0) { scb->io_ctx->ccb_h.status |= CAM_RELEASE_SIMQ; aic->flags &= ~AIC_RESOURCE_SHORTAGE; } scb->io_ctx = NULL; } /*************************** CAM CCB Operations *******************************/ void aic_calc_geometry(struct ccb_calc_geometry *ccg, int extended); /****************************** OS Primitives *********************************/ #define aic_delay DELAY /********************************** PCI ***************************************/ #ifdef AIC_PCI_CONFIG static __inline uint32_t aic_pci_read_config(aic_dev_softc_t pci, int reg, int width); static __inline void aic_pci_write_config(aic_dev_softc_t pci, int reg, uint32_t value, int width); static __inline int aic_get_pci_function(aic_dev_softc_t); static __inline int aic_get_pci_slot(aic_dev_softc_t); static __inline int aic_get_pci_bus(aic_dev_softc_t); static __inline uint32_t aic_pci_read_config(aic_dev_softc_t pci, int reg, int width) { return (pci_read_config(pci, reg, width)); } static __inline void aic_pci_write_config(aic_dev_softc_t pci, int reg, uint32_t value, int width) { pci_write_config(pci, reg, value, width); } static __inline int aic_get_pci_function(aic_dev_softc_t pci) { return (pci_get_function(pci)); } static __inline int aic_get_pci_slot(aic_dev_softc_t pci) { return (pci_get_slot(pci)); } static __inline int aic_get_pci_bus(aic_dev_softc_t pci) { return (pci_get_bus(pci)); } typedef enum { AIC_POWER_STATE_D0 = PCI_POWERSTATE_D0, AIC_POWER_STATE_D1 = PCI_POWERSTATE_D1, AIC_POWER_STATE_D2 = PCI_POWERSTATE_D2, AIC_POWER_STATE_D3 = PCI_POWERSTATE_D3 } aic_power_state; static __inline int aic_power_state_change(struct aic_softc *aic, aic_power_state new_state); static __inline int aic_power_state_change(struct aic_softc *aic, aic_power_state new_state) { return (pci_set_powerstate(aic->dev_softc, new_state)); } #endif