1*cbab9cadSchs /* $NetBSD: bhavar.h,v 1.25 2012/10/27 17:18:19 chs Exp $ */ 2e08a44b1Sthorpej 3e08a44b1Sthorpej /*- 4937a7a3eSbouyer * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. 5e08a44b1Sthorpej * All rights reserved. 6e08a44b1Sthorpej * 7e08a44b1Sthorpej * This code is derived from software contributed to The NetBSD Foundation 862b1bf3eSmycroft * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace 962b1bf3eSmycroft * Simulation Facility, NASA Ames Research Center. 10e08a44b1Sthorpej * 11e08a44b1Sthorpej * Redistribution and use in source and binary forms, with or without 12e08a44b1Sthorpej * modification, are permitted provided that the following conditions 13e08a44b1Sthorpej * are met: 14e08a44b1Sthorpej * 1. Redistributions of source code must retain the above copyright 15e08a44b1Sthorpej * notice, this list of conditions and the following disclaimer. 16e08a44b1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 17e08a44b1Sthorpej * notice, this list of conditions and the following disclaimer in the 18e08a44b1Sthorpej * documentation and/or other materials provided with the distribution. 19e08a44b1Sthorpej * 20e08a44b1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21e08a44b1Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22e08a44b1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23e08a44b1Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24e08a44b1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25e08a44b1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26e08a44b1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27e08a44b1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28e08a44b1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29e08a44b1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30e08a44b1Sthorpej * POSSIBILITY OF SUCH DAMAGE. 31e08a44b1Sthorpej */ 3280110252Smycroft 338b2ffcedSthorpej #ifndef _DEV_IC_BHAVAR_H_ 348b2ffcedSthorpej #define _DEV_IC_BHAVAR_H_ 358b2ffcedSthorpej 3603a0c2d9Sthorpej #include <sys/queue.h> 3703a0c2d9Sthorpej 38937a7a3eSbouyer /* XXX adjust hash for large numbers of CCBs */ 3906fdef11Smycroft #define CCB_HASH_SIZE 32 /* hash table size for phystokv */ 4006fdef11Smycroft #define CCB_HASH_SHIFT 9 4106fdef11Smycroft #define CCB_HASH(x) ((((long)(x))>>CCB_HASH_SHIFT) & (CCB_HASH_SIZE - 1)) 4206fdef11Smycroft 43937a7a3eSbouyer /* 44937a7a3eSbouyer * A CCB allocation group. Each group is a page size. We can find 45937a7a3eSbouyer * the allocation group for a CCB by truncating the CCB address to 46937a7a3eSbouyer * a page boundary, and the offset from the group's DMA mapping 47937a7a3eSbouyer * by taking the offset of the CCB into the page. 48937a7a3eSbouyer */ 49937a7a3eSbouyer #define BHA_CCBS_PER_GROUP ((PAGE_SIZE - sizeof(bus_dmamap_t)) / \ 50937a7a3eSbouyer sizeof(struct bha_ccb)) 51937a7a3eSbouyer struct bha_ccb_group { 52937a7a3eSbouyer bus_dmamap_t bcg_dmamap; 53937a7a3eSbouyer struct bha_ccb bcg_ccbs[1]; /* determined at run-time */ 5406fdef11Smycroft }; 5506fdef11Smycroft 56937a7a3eSbouyer #define BHA_CCB_GROUP(ccb) \ 57937a7a3eSbouyer (struct bha_ccb_group *)(trunc_page((vaddr_t)ccb)) 58937a7a3eSbouyer #define BHA_CCB_OFFSET(ccb) ((vaddr_t)(ccb) & PAGE_MASK) 59937a7a3eSbouyer 60937a7a3eSbouyer #define BHA_CCB_SYNC(sc, ccb, ops) \ 61937a7a3eSbouyer do { \ 62937a7a3eSbouyer struct bha_ccb_group *bcg = BHA_CCB_GROUP((ccb)); \ 63937a7a3eSbouyer \ 64937a7a3eSbouyer bus_dmamap_sync((sc)->sc_dmat, bcg->bcg_dmamap, \ 65937a7a3eSbouyer BHA_CCB_OFFSET(ccb), sizeof(struct bha_ccb), (ops)); \ 66937a7a3eSbouyer } while (0) 67937a7a3eSbouyer 68937a7a3eSbouyer /* 69937a7a3eSbouyer * Offset in the DMA mapping for mailboxes. 70937a7a3eSbouyer * Since all mailboxes are allocated on a single DMA'able memory 71937a7a3eSbouyer * due to the hardware limitation, an offset of any mailboxes can be 72937a7a3eSbouyer * calculated using same expression. 73937a7a3eSbouyer */ 74937a7a3eSbouyer #define BHA_MBX_OFFSET(sc, mbx) ((u_long)(mbx) - (u_long)(sc)->sc_mbo) 75937a7a3eSbouyer 76937a7a3eSbouyer #define BHA_MBI_SYNC(sc, mbi, ops) \ 77937a7a3eSbouyer do { \ 78937a7a3eSbouyer bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap_mbox, \ 79937a7a3eSbouyer BHA_MBX_OFFSET((sc), (mbi)), sizeof(struct bha_mbx_in), (ops)); \ 80937a7a3eSbouyer } while (0) 81937a7a3eSbouyer 82937a7a3eSbouyer #define BHA_MBO_SYNC(sc, mbo, ops) \ 83937a7a3eSbouyer do { \ 84937a7a3eSbouyer bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap_mbox, \ 85937a7a3eSbouyer BHA_MBX_OFFSET((sc), (mbo)), sizeof(struct bha_mbx_out), (ops)); \ 86937a7a3eSbouyer } while (0) 87e08a44b1Sthorpej 8806fdef11Smycroft struct bha_softc { 89*cbab9cadSchs device_t sc_dev; 90080350dcSmycroft 9116c4c5afSthorpej bus_space_tag_t sc_iot; 9216c4c5afSthorpej bus_space_handle_t sc_ioh; 93fbc0df0aSthorpej bus_dma_tag_t sc_dmat; 94937a7a3eSbouyer bus_dmamap_t sc_dmamap_mbox; /* maps the mailboxes */ 95fbc0df0aSthorpej int sc_dmaflags; /* bus-specific dma map flags */ 9606fdef11Smycroft void *sc_ih; 9706fdef11Smycroft 98937a7a3eSbouyer int sc_scsi_id; /* host adapter SCSI ID */ 99e08a44b1Sthorpej 100937a7a3eSbouyer int sc_flags; 101937a7a3eSbouyer #define BHAF_WIDE 0x01 /* device is wide */ 102937a7a3eSbouyer #define BHAF_DIFFERENTIAL 0x02 /* device is differential */ 103937a7a3eSbouyer #define BHAF_ULTRA 0x04 /* device is ultra-scsi */ 104937a7a3eSbouyer #define BHAF_TAGGED_QUEUEING 0x08 /* device supports tagged queueing */ 105937a7a3eSbouyer #define BHAF_WIDE_LUN 0x10 /* device supported wide lun CCBs */ 106937a7a3eSbouyer #define BHAF_STRICT_ROUND_ROBIN 0x20 /* device supports strict RR mode */ 107937a7a3eSbouyer 108937a7a3eSbouyer int sc_max_dmaseg; /* maximum number of DMA segments */ 109937a7a3eSbouyer int sc_max_ccbs; /* maximum number of CCBs (HW) */ 110937a7a3eSbouyer int sc_cur_ccbs; /* current number of CCBs */ 111937a7a3eSbouyer 112937a7a3eSbouyer int sc_disc_mask; /* mask of targets allowing discnnct */ 113937a7a3eSbouyer int sc_ultra_mask; /* mask of targets allowing ultra */ 114937a7a3eSbouyer int sc_fast_mask; /* mask of targets allowing fast */ 115937a7a3eSbouyer int sc_sync_mask; /* mask of targets allowing sync */ 116937a7a3eSbouyer int sc_wide_mask; /* mask of targets allowing wide */ 117937a7a3eSbouyer int sc_tag_mask; /* mask of targets allowing t/q'ing */ 118937a7a3eSbouyer 119937a7a3eSbouyer /* 120937a7a3eSbouyer * In and Out mailboxes. 121937a7a3eSbouyer */ 122937a7a3eSbouyer struct bha_mbx_out *sc_mbo; 123937a7a3eSbouyer struct bha_mbx_in *sc_mbi; 124937a7a3eSbouyer 125937a7a3eSbouyer struct bha_mbx_out *sc_cmbo; /* Collection Mail Box out */ 126937a7a3eSbouyer struct bha_mbx_out *sc_tmbo; /* Target Mail Box out */ 127937a7a3eSbouyer 128937a7a3eSbouyer int sc_mbox_count; /* number of mailboxes */ 129937a7a3eSbouyer int sc_mbofull; /* number of full Mail Box Out */ 130937a7a3eSbouyer 131937a7a3eSbouyer struct bha_mbx_in *sc_tmbi; /* Target Mail Box in */ 132e08a44b1Sthorpej 13306fdef11Smycroft struct bha_ccb *sc_ccbhash[CCB_HASH_SIZE]; 134937a7a3eSbouyer TAILQ_HEAD(, bha_ccb) sc_free_ccb, 135937a7a3eSbouyer sc_waiting_ccb, 136937a7a3eSbouyer sc_allocating_ccbs; 137080350dcSmycroft 138937a7a3eSbouyer struct scsipi_adapter sc_adapter; 139937a7a3eSbouyer struct scsipi_channel sc_channel; 14003a0c2d9Sthorpej 141080350dcSmycroft char sc_model[7], 142080350dcSmycroft sc_firmware[6]; 143080350dcSmycroft }; 144080350dcSmycroft 145080350dcSmycroft struct bha_probe_data { 146080350dcSmycroft int sc_irq, sc_drq; 14706fdef11Smycroft }; 14806fdef11Smycroft 1498b2ffcedSthorpej int bha_find(bus_space_tag_t, bus_space_handle_t); 1508b2ffcedSthorpej int bha_inquire_config(bus_space_tag_t, bus_space_handle_t, 1518b2ffcedSthorpej struct bha_probe_data *); 1528b2ffcedSthorpej void bha_attach(struct bha_softc *); 1538b2ffcedSthorpej int bha_info(struct bha_softc *); 1548b2ffcedSthorpej int bha_intr(void *); 15579b026a8Sjonathan 1568b2ffcedSthorpej int bha_disable_isacompat(struct bha_softc *); 1578b2ffcedSthorpej int bha_probe_inquiry(bus_space_tag_t, bus_space_handle_t, 1588b2ffcedSthorpej struct bha_probe_data *); 1598b2ffcedSthorpej 1608b2ffcedSthorpej #endif /* _DEV_IC_BHAVAR_H_ */ 161