1 1.25 chs /* $NetBSD: bhavar.h,v 1.25 2012/10/27 17:18:19 chs Exp $ */ 2 1.10 thorpej 3 1.10 thorpej /*- 4 1.20 bouyer * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. 5 1.10 thorpej * All rights reserved. 6 1.10 thorpej * 7 1.10 thorpej * This code is derived from software contributed to The NetBSD Foundation 8 1.11 mycroft * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace 9 1.11 mycroft * Simulation Facility, NASA Ames Research Center. 10 1.10 thorpej * 11 1.10 thorpej * Redistribution and use in source and binary forms, with or without 12 1.10 thorpej * modification, are permitted provided that the following conditions 13 1.10 thorpej * are met: 14 1.10 thorpej * 1. Redistributions of source code must retain the above copyright 15 1.10 thorpej * notice, this list of conditions and the following disclaimer. 16 1.10 thorpej * 2. Redistributions in binary form must reproduce the above copyright 17 1.10 thorpej * notice, this list of conditions and the following disclaimer in the 18 1.10 thorpej * documentation and/or other materials provided with the distribution. 19 1.10 thorpej * 20 1.10 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 1.10 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 1.10 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 1.10 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 1.10 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 1.10 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 1.10 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 1.10 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 1.10 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 1.10 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 1.10 thorpej * POSSIBILITY OF SUCH DAMAGE. 31 1.2 mycroft */ 32 1.2 mycroft 33 1.22 thorpej #ifndef _DEV_IC_BHAVAR_H_ 34 1.22 thorpej #define _DEV_IC_BHAVAR_H_ 35 1.22 thorpej 36 1.9 thorpej #include <sys/queue.h> 37 1.9 thorpej 38 1.20 bouyer /* XXX adjust hash for large numbers of CCBs */ 39 1.1 mycroft #define CCB_HASH_SIZE 32 /* hash table size for phystokv */ 40 1.1 mycroft #define CCB_HASH_SHIFT 9 41 1.1 mycroft #define CCB_HASH(x) ((((long)(x))>>CCB_HASH_SHIFT) & (CCB_HASH_SIZE - 1)) 42 1.1 mycroft 43 1.20 bouyer /* 44 1.20 bouyer * A CCB allocation group. Each group is a page size. We can find 45 1.20 bouyer * the allocation group for a CCB by truncating the CCB address to 46 1.20 bouyer * a page boundary, and the offset from the group's DMA mapping 47 1.20 bouyer * by taking the offset of the CCB into the page. 48 1.20 bouyer */ 49 1.20 bouyer #define BHA_CCBS_PER_GROUP ((PAGE_SIZE - sizeof(bus_dmamap_t)) / \ 50 1.20 bouyer sizeof(struct bha_ccb)) 51 1.20 bouyer struct bha_ccb_group { 52 1.20 bouyer bus_dmamap_t bcg_dmamap; 53 1.20 bouyer struct bha_ccb bcg_ccbs[1]; /* determined at run-time */ 54 1.1 mycroft }; 55 1.1 mycroft 56 1.20 bouyer #define BHA_CCB_GROUP(ccb) \ 57 1.20 bouyer (struct bha_ccb_group *)(trunc_page((vaddr_t)ccb)) 58 1.20 bouyer #define BHA_CCB_OFFSET(ccb) ((vaddr_t)(ccb) & PAGE_MASK) 59 1.20 bouyer 60 1.20 bouyer #define BHA_CCB_SYNC(sc, ccb, ops) \ 61 1.20 bouyer do { \ 62 1.20 bouyer struct bha_ccb_group *bcg = BHA_CCB_GROUP((ccb)); \ 63 1.20 bouyer \ 64 1.20 bouyer bus_dmamap_sync((sc)->sc_dmat, bcg->bcg_dmamap, \ 65 1.20 bouyer BHA_CCB_OFFSET(ccb), sizeof(struct bha_ccb), (ops)); \ 66 1.20 bouyer } while (0) 67 1.20 bouyer 68 1.20 bouyer /* 69 1.20 bouyer * Offset in the DMA mapping for mailboxes. 70 1.20 bouyer * Since all mailboxes are allocated on a single DMA'able memory 71 1.20 bouyer * due to the hardware limitation, an offset of any mailboxes can be 72 1.20 bouyer * calculated using same expression. 73 1.20 bouyer */ 74 1.20 bouyer #define BHA_MBX_OFFSET(sc, mbx) ((u_long)(mbx) - (u_long)(sc)->sc_mbo) 75 1.20 bouyer 76 1.20 bouyer #define BHA_MBI_SYNC(sc, mbi, ops) \ 77 1.20 bouyer do { \ 78 1.20 bouyer bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap_mbox, \ 79 1.20 bouyer BHA_MBX_OFFSET((sc), (mbi)), sizeof(struct bha_mbx_in), (ops)); \ 80 1.20 bouyer } while (0) 81 1.20 bouyer 82 1.20 bouyer #define BHA_MBO_SYNC(sc, mbo, ops) \ 83 1.20 bouyer do { \ 84 1.20 bouyer bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap_mbox, \ 85 1.20 bouyer BHA_MBX_OFFSET((sc), (mbo)), sizeof(struct bha_mbx_out), (ops)); \ 86 1.20 bouyer } while (0) 87 1.10 thorpej 88 1.1 mycroft struct bha_softc { 89 1.25 chs device_t sc_dev; 90 1.6 mycroft 91 1.3 thorpej bus_space_tag_t sc_iot; 92 1.3 thorpej bus_space_handle_t sc_ioh; 93 1.7 thorpej bus_dma_tag_t sc_dmat; 94 1.20 bouyer bus_dmamap_t sc_dmamap_mbox; /* maps the mailboxes */ 95 1.7 thorpej int sc_dmaflags; /* bus-specific dma map flags */ 96 1.1 mycroft void *sc_ih; 97 1.1 mycroft 98 1.20 bouyer int sc_scsi_id; /* host adapter SCSI ID */ 99 1.20 bouyer 100 1.20 bouyer int sc_flags; 101 1.20 bouyer #define BHAF_WIDE 0x01 /* device is wide */ 102 1.20 bouyer #define BHAF_DIFFERENTIAL 0x02 /* device is differential */ 103 1.20 bouyer #define BHAF_ULTRA 0x04 /* device is ultra-scsi */ 104 1.20 bouyer #define BHAF_TAGGED_QUEUEING 0x08 /* device supports tagged queueing */ 105 1.20 bouyer #define BHAF_WIDE_LUN 0x10 /* device supported wide lun CCBs */ 106 1.20 bouyer #define BHAF_STRICT_ROUND_ROBIN 0x20 /* device supports strict RR mode */ 107 1.20 bouyer 108 1.20 bouyer int sc_max_dmaseg; /* maximum number of DMA segments */ 109 1.20 bouyer int sc_max_ccbs; /* maximum number of CCBs (HW) */ 110 1.20 bouyer int sc_cur_ccbs; /* current number of CCBs */ 111 1.20 bouyer 112 1.20 bouyer int sc_disc_mask; /* mask of targets allowing discnnct */ 113 1.20 bouyer int sc_ultra_mask; /* mask of targets allowing ultra */ 114 1.20 bouyer int sc_fast_mask; /* mask of targets allowing fast */ 115 1.20 bouyer int sc_sync_mask; /* mask of targets allowing sync */ 116 1.20 bouyer int sc_wide_mask; /* mask of targets allowing wide */ 117 1.20 bouyer int sc_tag_mask; /* mask of targets allowing t/q'ing */ 118 1.20 bouyer 119 1.20 bouyer /* 120 1.20 bouyer * In and Out mailboxes. 121 1.20 bouyer */ 122 1.20 bouyer struct bha_mbx_out *sc_mbo; 123 1.20 bouyer struct bha_mbx_in *sc_mbi; 124 1.20 bouyer 125 1.20 bouyer struct bha_mbx_out *sc_cmbo; /* Collection Mail Box out */ 126 1.20 bouyer struct bha_mbx_out *sc_tmbo; /* Target Mail Box out */ 127 1.20 bouyer 128 1.20 bouyer int sc_mbox_count; /* number of mailboxes */ 129 1.20 bouyer int sc_mbofull; /* number of full Mail Box Out */ 130 1.10 thorpej 131 1.20 bouyer struct bha_mbx_in *sc_tmbi; /* Target Mail Box in */ 132 1.10 thorpej 133 1.1 mycroft struct bha_ccb *sc_ccbhash[CCB_HASH_SIZE]; 134 1.20 bouyer TAILQ_HEAD(, bha_ccb) sc_free_ccb, 135 1.20 bouyer sc_waiting_ccb, 136 1.20 bouyer sc_allocating_ccbs; 137 1.20 bouyer 138 1.12 thorpej struct scsipi_adapter sc_adapter; 139 1.20 bouyer struct scsipi_channel sc_channel; 140 1.6 mycroft 141 1.6 mycroft char sc_model[7], 142 1.6 mycroft sc_firmware[6]; 143 1.6 mycroft }; 144 1.10 thorpej 145 1.6 mycroft struct bha_probe_data { 146 1.6 mycroft int sc_irq, sc_drq; 147 1.1 mycroft }; 148 1.1 mycroft 149 1.22 thorpej int bha_find(bus_space_tag_t, bus_space_handle_t); 150 1.22 thorpej int bha_inquire_config(bus_space_tag_t, bus_space_handle_t, 151 1.22 thorpej struct bha_probe_data *); 152 1.22 thorpej void bha_attach(struct bha_softc *); 153 1.22 thorpej int bha_info(struct bha_softc *); 154 1.22 thorpej int bha_intr(void *); 155 1.22 thorpej 156 1.22 thorpej int bha_disable_isacompat(struct bha_softc *); 157 1.22 thorpej int bha_probe_inquiry(bus_space_tag_t, bus_space_handle_t, 158 1.22 thorpej struct bha_probe_data *); 159 1.22 thorpej 160 1.22 thorpej #endif /* _DEV_IC_BHAVAR_H_ */ 161