1*982bad25Sbouyer /* $NetBSD: mfivar.h,v 1.4 2007/05/01 17:18:55 bouyer Exp $ */ 2462dc620Sbouyer /* $OpenBSD: mfivar.h,v 1.28 2006/08/31 18:18:46 marco Exp $ */ 3462dc620Sbouyer /* 4462dc620Sbouyer * Copyright (c) 2006 Marco Peereboom <marco@peereboom.us> 5462dc620Sbouyer * 6462dc620Sbouyer * Permission to use, copy, modify, and distribute this software for any 7462dc620Sbouyer * purpose with or without fee is hereby granted, provided that the above 8462dc620Sbouyer * copyright notice and this permission notice appear in all copies. 9462dc620Sbouyer * 10462dc620Sbouyer * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11462dc620Sbouyer * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12462dc620Sbouyer * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13462dc620Sbouyer * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14462dc620Sbouyer * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15462dc620Sbouyer * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16462dc620Sbouyer * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17462dc620Sbouyer */ 18462dc620Sbouyer 19*982bad25Sbouyer #include <dev/sysmon/sysmonvar.h> 20*982bad25Sbouyer #include <sys/envsys.h> 21*982bad25Sbouyer 22462dc620Sbouyer #define DEVNAME(_s) ((_s)->sc_dev.dv_xname) 23462dc620Sbouyer 24*982bad25Sbouyer // #define MFI_DEBUG 25462dc620Sbouyer #ifdef MFI_DEBUG 26462dc620Sbouyer extern uint32_t mfi_debug; 27462dc620Sbouyer #define DPRINTF(x...) do { if (mfi_debug) printf(x); } while(0) 28462dc620Sbouyer #define DNPRINTF(n,x...) do { if (mfi_debug & n) printf(x); } while(0) 29462dc620Sbouyer #define MFI_D_CMD 0x0001 30462dc620Sbouyer #define MFI_D_INTR 0x0002 31462dc620Sbouyer #define MFI_D_MISC 0x0004 32462dc620Sbouyer #define MFI_D_DMA 0x0008 33462dc620Sbouyer #define MFI_D_IOCTL 0x0010 34462dc620Sbouyer #define MFI_D_RW 0x0020 35462dc620Sbouyer #define MFI_D_MEM 0x0040 36462dc620Sbouyer #define MFI_D_CCB 0x0080 37462dc620Sbouyer #else 38462dc620Sbouyer #define DPRINTF(x...) 39462dc620Sbouyer #define DNPRINTF(n,x...) 40462dc620Sbouyer #endif 41462dc620Sbouyer 42462dc620Sbouyer struct mfi_mem { 43462dc620Sbouyer bus_dmamap_t am_map; 44462dc620Sbouyer bus_dma_segment_t am_seg; 45462dc620Sbouyer size_t am_size; 4653524e44Schristos void * am_kva; 47462dc620Sbouyer }; 48462dc620Sbouyer 49462dc620Sbouyer #define MFIMEM_MAP(_am) ((_am)->am_map) 50462dc620Sbouyer #define MFIMEM_DVA(_am) ((_am)->am_map->dm_segs[0].ds_addr) 51462dc620Sbouyer #define MFIMEM_KVA(_am) ((void *)(_am)->am_kva) 52462dc620Sbouyer 53462dc620Sbouyer struct mfi_prod_cons { 54462dc620Sbouyer uint32_t mpc_producer; 55462dc620Sbouyer uint32_t mpc_consumer; 56462dc620Sbouyer uint32_t mpc_reply_q[1]; /* compensate for 1 extra reply per spec */ 57462dc620Sbouyer }; 58462dc620Sbouyer 59462dc620Sbouyer struct mfi_ccb { 60462dc620Sbouyer struct mfi_softc *ccb_sc; 61462dc620Sbouyer 62462dc620Sbouyer union mfi_frame *ccb_frame; 63462dc620Sbouyer paddr_t ccb_pframe; 64462dc620Sbouyer uint32_t ccb_frame_size; 65462dc620Sbouyer uint32_t ccb_extra_frames; 66462dc620Sbouyer 67462dc620Sbouyer struct mfi_sense *ccb_sense; 68462dc620Sbouyer paddr_t ccb_psense; 69462dc620Sbouyer 70462dc620Sbouyer bus_dmamap_t ccb_dmamap; 71462dc620Sbouyer 72462dc620Sbouyer union mfi_sgl *ccb_sgl; 73462dc620Sbouyer 74462dc620Sbouyer /* data for sgl */ 75462dc620Sbouyer void *ccb_data; 76462dc620Sbouyer uint32_t ccb_len; 77462dc620Sbouyer 78462dc620Sbouyer uint32_t ccb_direction; 79462dc620Sbouyer #define MFI_DATA_NONE 0 80462dc620Sbouyer #define MFI_DATA_IN 1 81462dc620Sbouyer #define MFI_DATA_OUT 2 82462dc620Sbouyer 83462dc620Sbouyer struct scsipi_xfer *ccb_xs; 84462dc620Sbouyer 85462dc620Sbouyer void (*ccb_done)(struct mfi_ccb *); 86462dc620Sbouyer 87462dc620Sbouyer volatile enum { 88462dc620Sbouyer MFI_CCB_FREE, 89462dc620Sbouyer MFI_CCB_READY, 90462dc620Sbouyer MFI_CCB_DONE 91462dc620Sbouyer } ccb_state; 92462dc620Sbouyer uint32_t ccb_flags; 93462dc620Sbouyer #define MFI_CCB_F_ERR (1<<0) 94462dc620Sbouyer TAILQ_ENTRY(mfi_ccb) ccb_link; 95462dc620Sbouyer }; 96462dc620Sbouyer 97462dc620Sbouyer TAILQ_HEAD(mfi_ccb_list, mfi_ccb); 98462dc620Sbouyer 99462dc620Sbouyer struct mfi_softc { 100462dc620Sbouyer struct device sc_dev; 101462dc620Sbouyer struct scsipi_channel sc_chan; 102462dc620Sbouyer struct scsipi_adapter sc_adapt; 103462dc620Sbouyer 104462dc620Sbouyer void *sc_ih; 105462dc620Sbouyer 106462dc620Sbouyer u_int32_t sc_flags; 107462dc620Sbouyer 108462dc620Sbouyer bus_space_tag_t sc_iot; 109462dc620Sbouyer bus_space_handle_t sc_ioh; 110462dc620Sbouyer bus_dma_tag_t sc_dmat; 111462dc620Sbouyer 112462dc620Sbouyer /* save some useful information for logical drives that is missing 113462dc620Sbouyer * in sc_ld_list 114462dc620Sbouyer */ 115462dc620Sbouyer struct { 116462dc620Sbouyer uint32_t ld_present; 117462dc620Sbouyer char ld_dev[16]; /* device name sd? */ 118462dc620Sbouyer } sc_ld[MFI_MAX_LD]; 119462dc620Sbouyer 120462dc620Sbouyer /* scsi ioctl from sd device */ 12153524e44Schristos int (*sc_ioctl)(struct device *, u_long, void *); 122462dc620Sbouyer 123462dc620Sbouyer /* firmware determined max, totals and other information*/ 124462dc620Sbouyer uint32_t sc_max_cmds; 125462dc620Sbouyer uint32_t sc_max_sgl; 126462dc620Sbouyer uint32_t sc_max_ld; 127462dc620Sbouyer uint32_t sc_ld_cnt; 128462dc620Sbouyer /* XXX these struct should be local to mgmt function */ 129462dc620Sbouyer struct mfi_ctrl_info sc_info; 130462dc620Sbouyer struct mfi_ld_list sc_ld_list; 131462dc620Sbouyer struct mfi_ld_details sc_ld_details; 132462dc620Sbouyer 133462dc620Sbouyer /* all commands */ 134462dc620Sbouyer struct mfi_ccb *sc_ccb; 135462dc620Sbouyer 136462dc620Sbouyer /* producer/consumer pointers and reply queue */ 137462dc620Sbouyer struct mfi_mem *sc_pcq; 138462dc620Sbouyer 139462dc620Sbouyer /* frame memory */ 140462dc620Sbouyer struct mfi_mem *sc_frames; 141462dc620Sbouyer uint32_t sc_frames_size; 142462dc620Sbouyer 143462dc620Sbouyer /* sense memory */ 144462dc620Sbouyer struct mfi_mem *sc_sense; 145462dc620Sbouyer 146462dc620Sbouyer struct mfi_ccb_list sc_ccb_freeq; 147462dc620Sbouyer 148*982bad25Sbouyer struct sysmon_envsys sc_envsys; 149*982bad25Sbouyer #define sc_ranges sc_envsys.sme_ranges 150*982bad25Sbouyer #define sc_sensor_info sc_envsys.sme_sensor_info 151*982bad25Sbouyer #define sc_sensor_data sc_envsys.sme_sensor_data 152*982bad25Sbouyer 153462dc620Sbouyer }; 154462dc620Sbouyer 155462dc620Sbouyer int mfi_attach(struct mfi_softc *sc); 156462dc620Sbouyer int mfi_intr(void *); 157