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$ 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/queue.h> 52 53 #if __FreeBSD_version < 500000 54 #include <pci.h> 55 #else 56 #define NPCI 1 57 #endif 58 59 #if NPCI > 0 60 #define AIC_PCI_CONFIG 1 61 #include <machine/bus_memio.h> 62 #endif 63 #include <machine/bus_pio.h> 64 #include <machine/bus.h> 65 #include <machine/endian.h> 66 #include <machine/clock.h> 67 #include <machine/resource.h> 68 69 #include <sys/rman.h> 70 71 #if NPCI > 0 72 #if __FreeBSD_version >= 500000 73 #include <dev/pci/pcireg.h> 74 #include <dev/pci/pcivar.h> 75 #else 76 #include <pci/pcireg.h> 77 #include <pci/pcivar.h> 78 #endif 79 #endif 80 81 #include <cam/cam.h> 82 #include <cam/cam_ccb.h> 83 #include <cam/cam_debug.h> 84 #include <cam/cam_sim.h> 85 #include <cam/cam_xpt_sim.h> 86 87 #include <cam/scsi/scsi_all.h> 88 #include <cam/scsi/scsi_message.h> 89 90 #ifdef CAM_NEW_TRAN_CODE 91 #define AHC_NEW_TRAN_SETTINGS 92 #endif /* CAM_NEW_TRAN_CODE */ 93 94 /*************************** Attachment Bookkeeping ***************************/ 95 extern devclass_t ahc_devclass; 96 97 /****************************** Platform Macros *******************************/ 98 #define SIM_IS_SCSIBUS_B(ahc, sim) \ 99 ((sim) == ahc->platform_data->sim_b) 100 #define SIM_CHANNEL(ahc, sim) \ 101 (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A') 102 #define SIM_SCSI_ID(ahc, sim) \ 103 (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id) 104 #define SIM_PATH(ahc, sim) \ 105 (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \ 106 : ahc->platform_data->path) 107 #define BUILD_SCSIID(ahc, sim, target_id, our_id) \ 108 ((((target_id) << TID_SHIFT) & TID) | (our_id) \ 109 | (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0)) 110 111 #define SCB_GET_SIM(ahc, scb) \ 112 (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \ 113 : (ahc)->platform_data->sim_b) 114 115 #ifndef offsetof 116 #define offsetof(type, member) ((size_t)(&((type *)0)->member)) 117 #endif 118 119 /************************ Tunable Driver Parameters **************************/ 120 /* 121 * The number of dma segments supported. The sequencer can handle any number 122 * of physically contiguous S/G entrys. To reduce the driver's memory 123 * consumption, we limit the number supported to be sufficient to handle 124 * the largest mapping supported by the kernel, MAXPHYS. Assuming the 125 * transfer is as fragmented as possible and unaligned, this turns out to 126 * be the number of paged sized transfers in MAXPHYS plus an extra element 127 * to handle any unaligned residual. The sequencer fetches SG elements 128 * in cacheline sized chucks, so make the number per-transaction an even 129 * multiple of 16 which should align us on even the largest of cacheline 130 * boundaries. 131 */ 132 #define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16)) 133 134 /* This driver supports target mode */ 135 #define AHC_TARGET_MODE 1 136 137 /************************** Softc/SCB Platform Data ***************************/ 138 struct ahc_platform_data { 139 /* 140 * Hooks into the XPT. 141 */ 142 struct cam_sim *sim; 143 struct cam_sim *sim_b; 144 struct cam_path *path; 145 struct cam_path *path_b; 146 147 int regs_res_type; 148 int regs_res_id; 149 int irq_res_type; 150 struct resource *regs; 151 struct resource *irq; 152 void *ih; 153 eventhandler_tag eh; 154 struct proc *recovery_thread; 155 }; 156 157 struct scb_platform_data { 158 }; 159 160 /***************************** Core Includes **********************************/ 161 #if AHC_REG_PRETTY_PRINT 162 #define AIC_DEBUG_REGISTERS 1 163 #else 164 #define AIC_DEBUG_REGISTERS 0 165 #endif 166 #define AIC_CORE_INCLUDE <dev/aic7xxx/aic7xxx.h> 167 #define AIC_LIB_PREFIX ahc 168 #define AIC_CONST_PREFIX AHC 169 #include <dev/aic7xxx/aic_osm_lib.h> 170 171 /*************************** Device Access ************************************/ 172 #define ahc_inb(ahc, port) \ 173 bus_space_read_1((ahc)->tag, (ahc)->bsh, port) 174 175 #define ahc_outb(ahc, port, value) \ 176 bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value) 177 178 #define ahc_outsb(ahc, port, valp, count) \ 179 bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count) 180 181 #define ahc_insb(ahc, port, valp, count) \ 182 bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count) 183 184 static __inline void ahc_flush_device_writes(struct ahc_softc *); 185 186 static __inline void 187 ahc_flush_device_writes(struct ahc_softc *ahc) 188 { 189 /* XXX Is this sufficient for all architectures??? */ 190 ahc_inb(ahc, INTSTAT); 191 } 192 193 /**************************** Locking Primitives ******************************/ 194 /* Lock protecting internal data structures */ 195 static __inline void ahc_lockinit(struct ahc_softc *); 196 static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags); 197 static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags); 198 199 /* Lock held during command compeletion to the upper layer */ 200 static __inline void ahc_done_lockinit(struct ahc_softc *); 201 static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *flags); 202 static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *flags); 203 204 /* Lock held during ahc_list manipulation and ahc softc frees */ 205 static __inline void ahc_list_lockinit(void); 206 static __inline void ahc_list_lock(unsigned long *flags); 207 static __inline void ahc_list_unlock(unsigned long *flags); 208 209 static __inline void 210 ahc_lockinit(struct ahc_softc *ahc) 211 { 212 } 213 214 static __inline void 215 ahc_lock(struct ahc_softc *ahc, unsigned long *flags) 216 { 217 *flags = splcam(); 218 } 219 220 static __inline void 221 ahc_unlock(struct ahc_softc *ahc, unsigned long *flags) 222 { 223 splx(*flags); 224 } 225 226 /* Lock held during command compeletion to the upper layer */ 227 static __inline void 228 ahc_done_lockinit(struct ahc_softc *ahc) 229 { 230 } 231 232 static __inline void 233 ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags) 234 { 235 } 236 237 static __inline void 238 ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags) 239 { 240 } 241 242 /* Lock held during ahc_list manipulation and ahc softc frees */ 243 static __inline void 244 ahc_list_lockinit(void) 245 { 246 } 247 248 static __inline void 249 ahc_list_lock(unsigned long *flags) 250 { 251 } 252 253 static __inline void 254 ahc_list_unlock(unsigned long *flags) 255 { 256 } 257 258 /********************************** PCI ***************************************/ 259 #ifdef AIC_PCI_CONFIG 260 int ahc_pci_map_registers(struct ahc_softc *ahc); 261 int ahc_pci_map_int(struct ahc_softc *ahc); 262 #endif /*AIC_PCI_CONFIG*/ 263 264 /******************************** VL/EISA *************************************/ 265 int aic7770_map_registers(struct ahc_softc *ahc, u_int port); 266 int aic7770_map_int(struct ahc_softc *ahc, int irq); 267 268 /********************************* Debug **************************************/ 269 static __inline void ahc_print_path(struct ahc_softc *, struct scb *); 270 static __inline void ahc_platform_dump_card_state(struct ahc_softc *ahc); 271 272 static __inline void 273 ahc_print_path(struct ahc_softc *ahc, struct scb *scb) 274 { 275 xpt_print_path(scb->io_ctx->ccb_h.path); 276 } 277 278 static __inline void 279 ahc_platform_dump_card_state(struct ahc_softc *ahc) 280 { 281 /* Nothing to do here for FreeBSD */ 282 } 283 /**************************** Transfer Settings *******************************/ 284 void ahc_notify_xfer_settings_change(struct ahc_softc *, 285 struct ahc_devinfo *); 286 void ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *, 287 int /*enable*/); 288 289 /************************* Initialization/Teardown ****************************/ 290 int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg); 291 void ahc_platform_free(struct ahc_softc *ahc); 292 int ahc_map_int(struct ahc_softc *ahc); 293 int ahc_attach(struct ahc_softc *); 294 int ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc); 295 int ahc_detach(device_t); 296 297 /****************************** Interrupts ************************************/ 298 void ahc_platform_intr(void *); 299 static __inline void ahc_platform_flushwork(struct ahc_softc *ahc); 300 static __inline void 301 ahc_platform_flushwork(struct ahc_softc *ahc) 302 { 303 } 304 305 /************************ Misc Function Declarations **************************/ 306 void ahc_done(struct ahc_softc *ahc, struct scb *scb); 307 void ahc_send_async(struct ahc_softc *, char /*channel*/, 308 u_int /*target*/, u_int /*lun*/, ac_code, void *arg); 309 #endif /* _AIC7XXX_FREEBSD_H_ */ 310