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