19b631363SMatt Jacob /* $FreeBSD$ */ 2098ca2bdSWarner Losh /*- 39b631363SMatt Jacob * Generic defines for LSI '909 FC adapters. 49b631363SMatt Jacob * FreeBSD Version. 59b631363SMatt Jacob * 69b631363SMatt Jacob * Copyright (c) 2000, 2001 by Greg Ansley 79b631363SMatt Jacob * 89b631363SMatt Jacob * Redistribution and use in source and binary forms, with or without 99b631363SMatt Jacob * modification, are permitted provided that the following conditions 109b631363SMatt Jacob * are met: 119b631363SMatt Jacob * 1. Redistributions of source code must retain the above copyright 129b631363SMatt Jacob * notice immediately at the beginning of the file, without modification, 139b631363SMatt Jacob * this list of conditions, and the following disclaimer. 149b631363SMatt Jacob * 2. The name of the author may not be used to endorse or promote products 159b631363SMatt Jacob * derived from this software without specific prior written permission. 169b631363SMatt Jacob * 179b631363SMatt Jacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 189b631363SMatt Jacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 199b631363SMatt Jacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 209b631363SMatt Jacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 219b631363SMatt Jacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 229b631363SMatt Jacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 239b631363SMatt Jacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 249b631363SMatt Jacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 259b631363SMatt Jacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 269b631363SMatt Jacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 279b631363SMatt Jacob * SUCH DAMAGE. 280b80d21bSMatt Jacob */ 290b80d21bSMatt Jacob /*- 300b80d21bSMatt Jacob * Copyright (c) 2002, 2006 by Matthew Jacob 310b80d21bSMatt Jacob * All rights reserved. 32b0a2fdeeSScott Long * 330b80d21bSMatt Jacob * Redistribution and use in source and binary forms, with or without 340b80d21bSMatt Jacob * modification, are permitted provided that the following conditions are 350b80d21bSMatt Jacob * met: 360b80d21bSMatt Jacob * 1. Redistributions of source code must retain the above copyright 370b80d21bSMatt Jacob * notice, this list of conditions and the following disclaimer. 380b80d21bSMatt Jacob * 2. Redistributions in binary form must reproduce at minimum a disclaimer 390b80d21bSMatt Jacob * substantially similar to the "NO WARRANTY" disclaimer below 400b80d21bSMatt Jacob * ("Disclaimer") and any redistribution must be conditioned upon including 410b80d21bSMatt Jacob * a substantially similar Disclaimer requirement for further binary 420b80d21bSMatt Jacob * redistribution. 430b80d21bSMatt Jacob * 3. Neither the names of the above listed copyright holders nor the names 440b80d21bSMatt Jacob * of any contributors may be used to endorse or promote products derived 450b80d21bSMatt Jacob * from this software without specific prior written permission. 460b80d21bSMatt Jacob * 470b80d21bSMatt Jacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 480b80d21bSMatt Jacob * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 490b80d21bSMatt Jacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 500b80d21bSMatt Jacob * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 510b80d21bSMatt Jacob * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 520b80d21bSMatt Jacob * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 530b80d21bSMatt Jacob * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 540b80d21bSMatt Jacob * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 550b80d21bSMatt Jacob * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 560b80d21bSMatt Jacob * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 570b80d21bSMatt Jacob * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 580b80d21bSMatt Jacob * 590b80d21bSMatt Jacob * Support from Chris Ellsworth in order to make SAS adapters work 600b80d21bSMatt Jacob * is gratefully acknowledged. 61ec5fe39dSMatt Jacob * 62ec5fe39dSMatt Jacob * 63ec5fe39dSMatt Jacob * Support from LSI-Logic has also gone a great deal toward making this a 64ec5fe39dSMatt Jacob * workable subsystem and is gratefully acknowledged. 659b631363SMatt Jacob */ 669b631363SMatt Jacob /* 67b0a2fdeeSScott Long * Copyright (c) 2004, Avid Technology, Inc. and its contributors. 68b0a2fdeeSScott Long * Copyright (c) 2004, 2005 Justin T. Gibbs 69b0a2fdeeSScott Long * Copyright (c) 2005, WHEEL Sp. z o.o. 70b0a2fdeeSScott Long * All rights reserved. 71b0a2fdeeSScott Long * 72b0a2fdeeSScott Long * Redistribution and use in source and binary forms, with or without 73b0a2fdeeSScott Long * modification, are permitted provided that the following conditions are 74b0a2fdeeSScott Long * met: 75b0a2fdeeSScott Long * 1. Redistributions of source code must retain the above copyright 76b0a2fdeeSScott Long * notice, this list of conditions and the following disclaimer. 77b0a2fdeeSScott Long * 2. Redistributions in binary form must reproduce at minimum a disclaimer 78b0a2fdeeSScott Long * substantially similar to the "NO WARRANTY" disclaimer below 79b0a2fdeeSScott Long * ("Disclaimer") and any redistribution must be conditioned upon including 80b0a2fdeeSScott Long * a substantially similar Disclaimer requirement for further binary 81b0a2fdeeSScott Long * redistribution. 82286e947fSJustin T. Gibbs * 3. Neither the names of the above listed copyright holders nor the names 83286e947fSJustin T. Gibbs * of any contributors may be used to endorse or promote products derived 84286e947fSJustin T. Gibbs * from this software without specific prior written permission. 85b0a2fdeeSScott Long * 86b0a2fdeeSScott Long * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 87b0a2fdeeSScott Long * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 88b0a2fdeeSScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 89b0a2fdeeSScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 90b0a2fdeeSScott Long * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 91b0a2fdeeSScott Long * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 92b0a2fdeeSScott Long * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 93b0a2fdeeSScott Long * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 94b0a2fdeeSScott Long * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 95b0a2fdeeSScott Long * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 96b0a2fdeeSScott Long * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 979b631363SMatt Jacob */ 989b631363SMatt Jacob 999b631363SMatt Jacob #ifndef _MPT_H_ 1009b631363SMatt Jacob #define _MPT_H_ 101b0a2fdeeSScott Long 102b0a2fdeeSScott Long /********************************* OS Includes ********************************/ 103b0a2fdeeSScott Long #include <sys/param.h> 104b0a2fdeeSScott Long #include <sys/systm.h> 105*4b847ffaSMarius Strobl #include <sys/bus.h> 106*4b847ffaSMarius Strobl #include <sys/condvar.h> 107b0a2fdeeSScott Long #include <sys/endian.h> 108b0a2fdeeSScott Long #include <sys/eventhandler.h> 109b0a2fdeeSScott Long #include <sys/kernel.h> 110b0a2fdeeSScott Long #include <sys/lock.h> 111b0a2fdeeSScott Long #include <sys/malloc.h> 112b0a2fdeeSScott Long #include <sys/module.h> 113*4b847ffaSMarius Strobl #include <sys/mutex.h> 114*4b847ffaSMarius Strobl #include <sys/proc.h> 115*4b847ffaSMarius Strobl #include <sys/queue.h> 116*4b847ffaSMarius Strobl #include <sys/rman.h> 117*4b847ffaSMarius Strobl #include <sys/types.h> 118b0a2fdeeSScott Long 119*4b847ffaSMarius Strobl #include <machine/bus.h> 120b0a2fdeeSScott Long #include <machine/cpu.h> 121b0a2fdeeSScott Long #include <machine/resource.h> 122b0a2fdeeSScott Long 1238ba5efbdSMarius Strobl #ifdef __sparc64__ 1248ba5efbdSMarius Strobl #include <dev/ofw/openfirm.h> 1258ba5efbdSMarius Strobl #include <machine/ofw_machdep.h> 1268ba5efbdSMarius Strobl #endif 1278ba5efbdSMarius Strobl 128444dd2b6SMatt Jacob #include <dev/pci/pcireg.h> 129444dd2b6SMatt Jacob #include <dev/pci/pcivar.h> 130444dd2b6SMatt Jacob 131b0a2fdeeSScott Long #include "opt_ddb.h" 132b0a2fdeeSScott Long 133b0a2fdeeSScott Long /**************************** Register Definitions ****************************/ 134b0a2fdeeSScott Long #include <dev/mpt/mpt_reg.h> 135b0a2fdeeSScott Long 136b0a2fdeeSScott Long /******************************* MPI Definitions ******************************/ 137b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_type.h> 138b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi.h> 139b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_cnfg.h> 140b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_ioc.h> 141b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_raid.h> 142b0a2fdeeSScott Long 143b0a2fdeeSScott Long /* XXX For mpt_debug.c */ 144b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_init.h> 145b0a2fdeeSScott Long 1460e0521a1SMatt Jacob #define MPT_S64_2_SCALAR(y) ((((int64_t)y.High) << 32) | (y.Low)) 1470e0521a1SMatt Jacob #define MPT_U64_2_SCALAR(y) ((((uint64_t)y.High) << 32) | (y.Low)) 1480e0521a1SMatt Jacob 149b0a2fdeeSScott Long /****************************** Misc Definitions ******************************/ 150a2baed97SMatt Jacob /* #define MPT_TEST_MULTIPATH 1 */ 1519b631363SMatt Jacob #define MPT_OK (0) 1529b631363SMatt Jacob #define MPT_FAIL (0x10000) 1539b631363SMatt Jacob 154b0a2fdeeSScott Long #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array)) 1559b631363SMatt Jacob 156c87e3f83SMatt Jacob #define MPT_ROLE_NONE 0 157c87e3f83SMatt Jacob #define MPT_ROLE_INITIATOR 1 158c87e3f83SMatt Jacob #define MPT_ROLE_TARGET 2 159c87e3f83SMatt Jacob #define MPT_ROLE_BOTH 3 160c87e3f83SMatt Jacob #define MPT_ROLE_DEFAULT MPT_ROLE_INITIATOR 161c87e3f83SMatt Jacob 1628ba5efbdSMarius Strobl #define MPT_INI_ID_NONE -1 1638ba5efbdSMarius Strobl 164b0a2fdeeSScott Long /**************************** Forward Declarations ****************************/ 165b0a2fdeeSScott Long struct mpt_softc; 166b0a2fdeeSScott Long struct mpt_personality; 167b0a2fdeeSScott Long typedef struct req_entry request_t; 1689b631363SMatt Jacob 169b0a2fdeeSScott Long /************************* Personality Module Support *************************/ 170b0a2fdeeSScott Long typedef int mpt_load_handler_t(struct mpt_personality *); 171b0a2fdeeSScott Long typedef int mpt_probe_handler_t(struct mpt_softc *); 172b0a2fdeeSScott Long typedef int mpt_attach_handler_t(struct mpt_softc *); 173c87e3f83SMatt Jacob typedef int mpt_enable_handler_t(struct mpt_softc *); 174a7303be1SMatt Jacob typedef void mpt_ready_handler_t(struct mpt_softc *); 175b0a2fdeeSScott Long typedef int mpt_event_handler_t(struct mpt_softc *, request_t *, 176b0a2fdeeSScott Long MSG_EVENT_NOTIFY_REPLY *); 177b0a2fdeeSScott Long typedef void mpt_reset_handler_t(struct mpt_softc *, int /*type*/); 178b0a2fdeeSScott Long /* XXX Add return value and use for veto? */ 179b0a2fdeeSScott Long typedef void mpt_shutdown_handler_t(struct mpt_softc *); 180b0a2fdeeSScott Long typedef void mpt_detach_handler_t(struct mpt_softc *); 181b0a2fdeeSScott Long typedef int mpt_unload_handler_t(struct mpt_personality *); 182b0a2fdeeSScott Long 183b0a2fdeeSScott Long struct mpt_personality 184b0a2fdeeSScott Long { 185b0a2fdeeSScott Long const char *name; 186b0a2fdeeSScott Long uint32_t id; /* Assigned identifier. */ 187b0a2fdeeSScott Long u_int use_count; /* Instances using personality*/ 188b0a2fdeeSScott Long mpt_load_handler_t *load; /* configure personailty */ 189b0a2fdeeSScott Long #define MPT_PERS_FIRST_HANDLER(pers) (&(pers)->load) 190b0a2fdeeSScott Long mpt_probe_handler_t *probe; /* configure personailty */ 191b0a2fdeeSScott Long mpt_attach_handler_t *attach; /* initialize device instance */ 192c87e3f83SMatt Jacob mpt_enable_handler_t *enable; /* enable device */ 193a7303be1SMatt Jacob mpt_ready_handler_t *ready; /* final open for business */ 194b0a2fdeeSScott Long mpt_event_handler_t *event; /* Handle MPI event. */ 195b0a2fdeeSScott Long mpt_reset_handler_t *reset; /* Re-init after reset. */ 196b0a2fdeeSScott Long mpt_shutdown_handler_t *shutdown; /* Shutdown instance. */ 197b0a2fdeeSScott Long mpt_detach_handler_t *detach; /* release device instance */ 198b0a2fdeeSScott Long mpt_unload_handler_t *unload; /* Shutdown personality */ 199b0a2fdeeSScott Long #define MPT_PERS_LAST_HANDLER(pers) (&(pers)->unload) 2009b631363SMatt Jacob }; 2019b631363SMatt Jacob 202b0a2fdeeSScott Long int mpt_modevent(module_t, int, void *); 2039b631363SMatt Jacob 204b0a2fdeeSScott Long /* Maximum supported number of personalities. */ 205b0a2fdeeSScott Long #define MPT_MAX_PERSONALITIES (15) 2069b631363SMatt Jacob 207b0a2fdeeSScott Long #define MPT_PERSONALITY_DEPEND(name, dep, vmin, vpref, vmax) \ 208b0a2fdeeSScott Long MODULE_DEPEND(name, dep, vmin, vpref, vmax) 209b0a2fdeeSScott Long 210b0a2fdeeSScott Long #define DECLARE_MPT_PERSONALITY(name, order) \ 211b0a2fdeeSScott Long static moduledata_t name##_mod = { \ 212b0a2fdeeSScott Long #name, mpt_modevent, &name##_personality \ 213b0a2fdeeSScott Long }; \ 214b0a2fdeeSScott Long DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, order); \ 215b0a2fdeeSScott Long MODULE_VERSION(name, 1); \ 216b0a2fdeeSScott Long MPT_PERSONALITY_DEPEND(name, mpt_core, 1, 1, 1) 217b0a2fdeeSScott Long 218b0a2fdeeSScott Long /******************************* Bus DMA Support ******************************/ 219b0a2fdeeSScott Long /* XXX Need to update bus_dmamap_sync to take a range argument. */ 220b0a2fdeeSScott Long #define bus_dmamap_sync_range(dma_tag, dmamap, offset, len, op) \ 221b0a2fdeeSScott Long bus_dmamap_sync(dma_tag, dmamap, op) 222b0a2fdeeSScott Long 223fa80feeeSMatt Jacob #if __FreeBSD_version < 600000 224fa80feeeSMatt Jacob #define bus_get_dma_tag(x) NULL 225fa80feeeSMatt Jacob #endif 226b0a2fdeeSScott Long #define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary, \ 227b0a2fdeeSScott Long lowaddr, highaddr, filter, filterarg, \ 228b0a2fdeeSScott Long maxsize, nsegments, maxsegsz, flags, \ 229b0a2fdeeSScott Long dma_tagp) \ 230b0a2fdeeSScott Long bus_dma_tag_create(parent_tag, alignment, boundary, \ 231b0a2fdeeSScott Long lowaddr, highaddr, filter, filterarg, \ 232b0a2fdeeSScott Long maxsize, nsegments, maxsegsz, flags, \ 233d0a68c27SMatt Jacob busdma_lock_mutex, &(mpt)->mpt_lock, \ 234b0a2fdeeSScott Long dma_tagp) 235b0a2fdeeSScott Long struct mpt_map_info { 236b0a2fdeeSScott Long struct mpt_softc *mpt; 237b0a2fdeeSScott Long int error; 238b0a2fdeeSScott Long uint32_t phys; 239b0a2fdeeSScott Long }; 240b0a2fdeeSScott Long 241b0a2fdeeSScott Long void mpt_map_rquest(void *, bus_dma_segment_t *, int, int); 2425f538376SMatt Jacob /* **************************** NewBUS interrupt Crock ************************/ 2435f538376SMatt Jacob #if __FreeBSD_version < 700031 2445f538376SMatt Jacob #define mpt_setup_intr(d, i, f, U, if, ifa, hp) \ 2455f538376SMatt Jacob bus_setup_intr(d, i, f, if, ifa, hp) 2465f538376SMatt Jacob #else 2475f538376SMatt Jacob #define mpt_setup_intr bus_setup_intr 2485f538376SMatt Jacob #endif 249b0a2fdeeSScott Long 250a41aabe2SJung-uk Kim /* **************************** NewBUS CAM Support ****************************/ 251a41aabe2SJung-uk Kim #if __FreeBSD_version < 700049 252a41aabe2SJung-uk Kim #define mpt_xpt_bus_register(sim, parent, bus) \ 253a41aabe2SJung-uk Kim xpt_bus_register(sim, bus) 254a41aabe2SJung-uk Kim #else 255a41aabe2SJung-uk Kim #define mpt_xpt_bus_register xpt_bus_register 256a41aabe2SJung-uk Kim #endif 257a41aabe2SJung-uk Kim 258b0a2fdeeSScott Long /**************************** Kernel Thread Support ***************************/ 259e1ff3d50SJulian Elischer #if __FreeBSD_version > 800001 260b0a2fdeeSScott Long #define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 2613745c395SJulian Elischer kproc_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) 262a41aabe2SJung-uk Kim #define mpt_kthread_exit(status) \ 263a41aabe2SJung-uk Kim kproc_exit(status) 264e1ff3d50SJulian Elischer #else 265e1ff3d50SJulian Elischer #define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 266*4b847ffaSMarius Strobl kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) 267a41aabe2SJung-uk Kim #define mpt_kthread_exit(status) \ 268a41aabe2SJung-uk Kim kthread_exit(status) 269b0a2fdeeSScott Long #endif 270b0a2fdeeSScott Long 271b0a2fdeeSScott Long /********************************** Endianess *********************************/ 2720e0521a1SMatt Jacob #define MPT_2_HOST64(ptr, tag) ptr->tag = le64toh(ptr->tag) 2730e0521a1SMatt Jacob #define MPT_2_HOST32(ptr, tag) ptr->tag = le32toh(ptr->tag) 2740e0521a1SMatt Jacob #define MPT_2_HOST16(ptr, tag) ptr->tag = le16toh(ptr->tag) 275b0a2fdeeSScott Long 2760e0521a1SMatt Jacob #define HOST_2_MPT64(ptr, tag) ptr->tag = htole64(ptr->tag) 2770e0521a1SMatt Jacob #define HOST_2_MPT32(ptr, tag) ptr->tag = htole32(ptr->tag) 2780e0521a1SMatt Jacob #define HOST_2_MPT16(ptr, tag) ptr->tag = htole16(ptr->tag) 2790e0521a1SMatt Jacob 2807185cd36SMatt Jacob #if _BYTE_ORDER == _BIG_ENDIAN 2810e0521a1SMatt Jacob void mpt2host_sge_simple_union(SGE_SIMPLE_UNION *); 2820e0521a1SMatt Jacob void mpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *); 2830e0521a1SMatt Jacob void mpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *); 2840e0521a1SMatt Jacob void mpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *); 2857ee37807SMarius Strobl void mpt2host_config_page_ioc3(CONFIG_PAGE_IOC_3 *); 2867ee37807SMarius Strobl void mpt2host_config_page_scsi_port_0(CONFIG_PAGE_SCSI_PORT_0 *); 2877ee37807SMarius Strobl void mpt2host_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *); 2887ee37807SMarius Strobl void host2mpt_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *); 2897ee37807SMarius Strobl void mpt2host_config_page_scsi_port_2(CONFIG_PAGE_SCSI_PORT_2 *); 2907ee37807SMarius Strobl void mpt2host_config_page_scsi_device_0(CONFIG_PAGE_SCSI_DEVICE_0 *); 2917ee37807SMarius Strobl void mpt2host_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *); 2927ee37807SMarius Strobl void host2mpt_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *); 2937ee37807SMarius Strobl void mpt2host_config_page_fc_port_0(CONFIG_PAGE_FC_PORT_0 *); 2947ee37807SMarius Strobl void mpt2host_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *); 2957ee37807SMarius Strobl void host2mpt_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *); 2960e0521a1SMatt Jacob void mpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *); 2977ee37807SMarius Strobl void mpt2host_config_page_raid_phys_disk_0(CONFIG_PAGE_RAID_PHYS_DISK_0 *); 2980e0521a1SMatt Jacob void mpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *); 2997185cd36SMatt Jacob #else 3007185cd36SMatt Jacob #define mpt2host_sge_simple_union(x) do { ; } while (0) 3017185cd36SMatt Jacob #define mpt2host_iocfacts_reply(x) do { ; } while (0) 3027185cd36SMatt Jacob #define mpt2host_portfacts_reply(x) do { ; } while (0) 3037185cd36SMatt Jacob #define mpt2host_config_page_ioc2(x) do { ; } while (0) 3047ee37807SMarius Strobl #define mpt2host_config_page_ioc3(x) do { ; } while (0) 3057ee37807SMarius Strobl #define mpt2host_config_page_scsi_port_0(x) do { ; } while (0) 3067ee37807SMarius Strobl #define mpt2host_config_page_scsi_port_1(x) do { ; } while (0) 3077ee37807SMarius Strobl #define host2mpt_config_page_scsi_port_1(x) do { ; } while (0) 3087ee37807SMarius Strobl #define mpt2host_config_page_scsi_port_2(x) do { ; } while (0) 3097ee37807SMarius Strobl #define mpt2host_config_page_scsi_device_0(x) do { ; } while (0) 3107ee37807SMarius Strobl #define mpt2host_config_page_scsi_device_1(x) do { ; } while (0) 3117ee37807SMarius Strobl #define host2mpt_config_page_scsi_device_1(x) do { ; } while (0) 3127ee37807SMarius Strobl #define mpt2host_config_page_fc_port_0(x) do { ; } while (0) 3137ee37807SMarius Strobl #define mpt2host_config_page_fc_port_1(x) do { ; } while (0) 3147ee37807SMarius Strobl #define host2mpt_config_page_fc_port_1(x) do { ; } while (0) 3157185cd36SMatt Jacob #define mpt2host_config_page_raid_vol_0(x) do { ; } while (0) 3167ee37807SMarius Strobl #define mpt2host_config_page_raid_phys_disk_0(x) \ 3177ee37807SMarius Strobl do { ; } while (0) 3187185cd36SMatt Jacob #define mpt2host_mpi_raid_vol_indicator(x) do { ; } while (0) 3190e0521a1SMatt Jacob #endif 320b0a2fdeeSScott Long 321b0a2fdeeSScott Long /**************************** MPI Transaction State ***************************/ 322b0a2fdeeSScott Long typedef enum { 3235e073106SMatt Jacob REQ_STATE_NIL = 0x00, 3245e073106SMatt Jacob REQ_STATE_FREE = 0x01, 3255e073106SMatt Jacob REQ_STATE_ALLOCATED = 0x02, 3265e073106SMatt Jacob REQ_STATE_QUEUED = 0x04, 3275e073106SMatt Jacob REQ_STATE_DONE = 0x08, 3285e073106SMatt Jacob REQ_STATE_TIMEDOUT = 0x10, 3295e073106SMatt Jacob REQ_STATE_NEED_WAKEUP = 0x20, 3305e073106SMatt Jacob REQ_STATE_LOCKED = 0x80, /* can't be freed */ 331b0a2fdeeSScott Long REQ_STATE_MASK = 0xFF 332b0a2fdeeSScott Long } mpt_req_state_t; 333b0a2fdeeSScott Long 334b0a2fdeeSScott Long struct req_entry { 335b0a2fdeeSScott Long TAILQ_ENTRY(req_entry) links; /* Pointer to next in list */ 336b0a2fdeeSScott Long mpt_req_state_t state; /* Request State Information */ 337b0a2fdeeSScott Long uint16_t index; /* Index of this entry */ 338b0a2fdeeSScott Long uint16_t IOCStatus; /* Completion status */ 3395ab13afcSMarius Strobl uint16_t ResponseCode; /* TMF Response Code */ 3405089bd63SMatt Jacob uint16_t serno; /* serial number */ 341b0a2fdeeSScott Long union ccb *ccb; /* CAM request */ 342b0a2fdeeSScott Long void *req_vbuf; /* Virtual Address of Entry */ 343b0a2fdeeSScott Long void *sense_vbuf; /* Virtual Address of sense data */ 344b0a2fdeeSScott Long bus_addr_t req_pbuf; /* Physical Address of Entry */ 345b0a2fdeeSScott Long bus_addr_t sense_pbuf; /* Physical Address of sense data */ 346fcd9a16bSMatt Jacob bus_dmamap_t dmap; /* DMA map for data buffers */ 347444dd2b6SMatt Jacob struct req_entry *chain; /* for SGE overallocations */ 348d0a68c27SMatt Jacob struct callout callout; /* Timeout for the request */ 349b0a2fdeeSScott Long }; 350b0a2fdeeSScott Long 3511d558d6aSScott Long typedef struct mpt_config_params { 3521d558d6aSScott Long u_int Action; 3531d558d6aSScott Long u_int PageVersion; 3541d558d6aSScott Long u_int PageLength; 3551d558d6aSScott Long u_int PageNumber; 3561d558d6aSScott Long u_int PageType; 3571d558d6aSScott Long u_int PageAddress; 3581d558d6aSScott Long u_int ExtPageLength; 3591d558d6aSScott Long u_int ExtPageType; 3601d558d6aSScott Long } cfgparms_t; 3611d558d6aSScott Long 362c87e3f83SMatt Jacob /**************************** MPI Target State Info ***************************/ 363c87e3f83SMatt Jacob 364c87e3f83SMatt Jacob typedef struct { 365c87e3f83SMatt Jacob uint32_t reply_desc; /* current reply descriptor */ 366c87e3f83SMatt Jacob uint32_t resid; /* current data residual */ 367c87e3f83SMatt Jacob uint32_t bytes_xfered; /* current relative offset */ 368c87e3f83SMatt Jacob union ccb *ccb; /* pointer to currently active ccb */ 369c87e3f83SMatt Jacob request_t *req; /* pointer to currently active assist request */ 37073651fd1SMatt Jacob uint32_t 37173651fd1SMatt Jacob is_local : 1, 37273651fd1SMatt Jacob nxfers : 31; 3735e073106SMatt Jacob uint32_t tag_id; 374c87e3f83SMatt Jacob enum { 375c87e3f83SMatt Jacob TGT_STATE_NIL, 3765e073106SMatt Jacob TGT_STATE_LOADING, 377c87e3f83SMatt Jacob TGT_STATE_LOADED, 378c87e3f83SMatt Jacob TGT_STATE_IN_CAM, 379c87e3f83SMatt Jacob TGT_STATE_SETTING_UP_FOR_DATA, 380c87e3f83SMatt Jacob TGT_STATE_MOVING_DATA, 381c87e3f83SMatt Jacob TGT_STATE_MOVING_DATA_AND_STATUS, 382c87e3f83SMatt Jacob TGT_STATE_SENDING_STATUS 383c87e3f83SMatt Jacob } state; 384c87e3f83SMatt Jacob } mpt_tgt_state_t; 385c87e3f83SMatt Jacob 386c87e3f83SMatt Jacob /* 387c87e3f83SMatt Jacob * When we get an incoming command it has its own tag which is called the 388c87e3f83SMatt Jacob * IoIndex. This is the value we gave that particular command buffer when 389c87e3f83SMatt Jacob * we originally assigned it. It's just a number, really. The FC card uses 390c87e3f83SMatt Jacob * it as an RX_ID. We can use it to index into mpt->tgt_cmd_ptrs, which 391c87e3f83SMatt Jacob * contains pointers the request_t structures related to that IoIndex. 392c87e3f83SMatt Jacob * 393c87e3f83SMatt Jacob * What *we* do is construct a tag out of the index for the target command 394c87e3f83SMatt Jacob * which owns the incoming ATIO plus a rolling sequence number. 395c87e3f83SMatt Jacob */ 396c87e3f83SMatt Jacob #define MPT_MAKE_TAGID(mpt, req, ioindex) \ 3975e073106SMatt Jacob ((ioindex << 18) | (((mpt->sequence++) & 0x3f) << 12) | (req->index & 0xfff)) 398c87e3f83SMatt Jacob 399c87e3f83SMatt Jacob #ifdef INVARIANTS 400c87e3f83SMatt Jacob #define MPT_TAG_2_REQ(a, b) mpt_tag_2_req(a, (uint32_t) b) 401c87e3f83SMatt Jacob #else 4025e073106SMatt Jacob #define MPT_TAG_2_REQ(mpt, tag) mpt->tgt_cmd_ptrs[tag >> 18] 403c87e3f83SMatt Jacob #endif 404c87e3f83SMatt Jacob 405c87e3f83SMatt Jacob #define MPT_TGT_STATE(mpt, req) ((mpt_tgt_state_t *) \ 406c87e3f83SMatt Jacob (&((uint8_t *)req->req_vbuf)[MPT_RQSL(mpt) - sizeof (mpt_tgt_state_t)])) 407c87e3f83SMatt Jacob 408c87e3f83SMatt Jacob STAILQ_HEAD(mpt_hdr_stailq, ccb_hdr); 409c87e3f83SMatt Jacob #define MPT_MAX_LUNS 256 410c87e3f83SMatt Jacob typedef struct { 411c87e3f83SMatt Jacob struct mpt_hdr_stailq atios; 412c87e3f83SMatt Jacob struct mpt_hdr_stailq inots; 413c87e3f83SMatt Jacob int enabled; 414c87e3f83SMatt Jacob } tgt_resource_t; 4155089bd63SMatt Jacob #define MPT_MAX_ELS 64 416c87e3f83SMatt Jacob 417b0a2fdeeSScott Long /**************************** Handler Registration ****************************/ 418b0a2fdeeSScott Long /* 419b0a2fdeeSScott Long * Global table of registered reply handlers. The 420b0a2fdeeSScott Long * handler is indicated by byte 3 of the request 421b0a2fdeeSScott Long * index submitted to the IOC. This allows the 422b0a2fdeeSScott Long * driver core to perform generic processing without 423b0a2fdeeSScott Long * any knowledge of per-personality behavior. 424b0a2fdeeSScott Long * 425b0a2fdeeSScott Long * MPT_NUM_REPLY_HANDLERS must be a power of 2 426b0a2fdeeSScott Long * to allow the easy generation of a mask. 427b0a2fdeeSScott Long * 428b0a2fdeeSScott Long * The handler offsets used by the core are hard coded 429b0a2fdeeSScott Long * allowing faster code generation when assigning a handler 430b0a2fdeeSScott Long * to a request. All "personalities" must use the 431b0a2fdeeSScott Long * the handler registration mechanism. 432b0a2fdeeSScott Long * 433b0a2fdeeSScott Long * The IOC handlers that are rarely executed are placed 434b0a2fdeeSScott Long * at the tail of the table to make it more likely that 435b0a2fdeeSScott Long * all commonly executed handlers fit in a single cache 436b0a2fdeeSScott Long * line. 437b0a2fdeeSScott Long */ 438c87e3f83SMatt Jacob #define MPT_NUM_REPLY_HANDLERS (32) 439b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_EVENTS MPT_CBI_TO_HID(0) 440b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_CONFIG MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-1) 441b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_HANDSHAKE MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-2) 442b0a2fdeeSScott Long typedef int mpt_reply_handler_t(struct mpt_softc *mpt, request_t *request, 443c87e3f83SMatt Jacob uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame); 444b0a2fdeeSScott Long typedef union { 445b0a2fdeeSScott Long mpt_reply_handler_t *reply_handler; 446b0a2fdeeSScott Long } mpt_handler_t; 447b0a2fdeeSScott Long 448b0a2fdeeSScott Long typedef enum { 449b0a2fdeeSScott Long MPT_HANDLER_REPLY, 450b0a2fdeeSScott Long MPT_HANDLER_EVENT, 451b0a2fdeeSScott Long MPT_HANDLER_RESET, 452b0a2fdeeSScott Long MPT_HANDLER_SHUTDOWN 453b0a2fdeeSScott Long } mpt_handler_type; 454b0a2fdeeSScott Long 455b0a2fdeeSScott Long struct mpt_handler_record 456b0a2fdeeSScott Long { 457b0a2fdeeSScott Long LIST_ENTRY(mpt_handler_record) links; 458b0a2fdeeSScott Long mpt_handler_t handler; 459b0a2fdeeSScott Long }; 460b0a2fdeeSScott Long 461b0a2fdeeSScott Long LIST_HEAD(mpt_handler_list, mpt_handler_record); 4629b631363SMatt Jacob 4639b631363SMatt Jacob /* 464b0a2fdeeSScott Long * The handler_id is currently unused but would contain the 465b0a2fdeeSScott Long * handler ID used in the MsgContext field to allow direction 466b0a2fdeeSScott Long * of replies to the handler. Registrations that don't require 467b0a2fdeeSScott Long * a handler id can pass in NULL for the handler_id. 468b0a2fdeeSScott Long * 469b0a2fdeeSScott Long * Deregistrations for handlers without a handler id should 470b0a2fdeeSScott Long * pass in MPT_HANDLER_ID_NONE. 4719b631363SMatt Jacob */ 472b0a2fdeeSScott Long #define MPT_HANDLER_ID_NONE (0xFFFFFFFF) 473b0a2fdeeSScott Long int mpt_register_handler(struct mpt_softc *, mpt_handler_type, 474b0a2fdeeSScott Long mpt_handler_t, uint32_t *); 475b0a2fdeeSScott Long int mpt_deregister_handler(struct mpt_softc *, mpt_handler_type, 476b0a2fdeeSScott Long mpt_handler_t, uint32_t); 4779b631363SMatt Jacob 478b0a2fdeeSScott Long /******************* Per-Controller Instance Data Structures ******************/ 479b0a2fdeeSScott Long TAILQ_HEAD(req_queue, req_entry); 4809b631363SMatt Jacob 481b0a2fdeeSScott Long /* Structure for saving proper values for modifyable PCI config registers */ 482b0a2fdeeSScott Long struct mpt_pci_cfg { 483b0a2fdeeSScott Long uint16_t Command; 484b0a2fdeeSScott Long uint16_t LatencyTimer_LineSize; 485b0a2fdeeSScott Long uint32_t IO_BAR; 486b0a2fdeeSScott Long uint32_t Mem0_BAR[2]; 487b0a2fdeeSScott Long uint32_t Mem1_BAR[2]; 488b0a2fdeeSScott Long uint32_t ROM_BAR; 489b0a2fdeeSScott Long uint8_t IntLine; 490b0a2fdeeSScott Long uint32_t PMCSR; 4919b631363SMatt Jacob }; 4929b631363SMatt Jacob 493b0a2fdeeSScott Long typedef enum { 494b0a2fdeeSScott Long MPT_RVF_NONE = 0x0, 495b0a2fdeeSScott Long MPT_RVF_ACTIVE = 0x1, 496b0a2fdeeSScott Long MPT_RVF_ANNOUNCED = 0x2, 497b0a2fdeeSScott Long MPT_RVF_UP2DATE = 0x4, 498b0a2fdeeSScott Long MPT_RVF_REFERENCED = 0x8, 499b0a2fdeeSScott Long MPT_RVF_WCE_CHANGED = 0x10 500b0a2fdeeSScott Long } mpt_raid_volume_flags; 501b0a2fdeeSScott Long 502b0a2fdeeSScott Long struct mpt_raid_volume { 503b0a2fdeeSScott Long CONFIG_PAGE_RAID_VOL_0 *config_page; 504b0a2fdeeSScott Long MPI_RAID_VOL_INDICATOR sync_progress; 505b0a2fdeeSScott Long mpt_raid_volume_flags flags; 5060e3b145eSMatt Jacob u_int quiesced_disks; 5079b631363SMatt Jacob }; 5089b631363SMatt Jacob 509b0a2fdeeSScott Long typedef enum { 510b0a2fdeeSScott Long MPT_RDF_NONE = 0x00, 511b0a2fdeeSScott Long MPT_RDF_ACTIVE = 0x01, 512b0a2fdeeSScott Long MPT_RDF_ANNOUNCED = 0x02, 513b0a2fdeeSScott Long MPT_RDF_UP2DATE = 0x04, 514b0a2fdeeSScott Long MPT_RDF_REFERENCED = 0x08, 515b0a2fdeeSScott Long MPT_RDF_QUIESCING = 0x10, 516b0a2fdeeSScott Long MPT_RDF_QUIESCED = 0x20 517b0a2fdeeSScott Long } mpt_raid_disk_flags; 5189b631363SMatt Jacob 519b0a2fdeeSScott Long struct mpt_raid_disk { 520b0a2fdeeSScott Long CONFIG_PAGE_RAID_PHYS_DISK_0 config_page; 521b0a2fdeeSScott Long struct mpt_raid_volume *volume; 522b0a2fdeeSScott Long u_int member_number; 523b0a2fdeeSScott Long u_int pass_thru_active; 524b0a2fdeeSScott Long mpt_raid_disk_flags flags; 5259b631363SMatt Jacob }; 5269b631363SMatt Jacob 527b0a2fdeeSScott Long struct mpt_evtf_record { 528b0a2fdeeSScott Long MSG_EVENT_NOTIFY_REPLY reply; 529b0a2fdeeSScott Long uint32_t context; 530b0a2fdeeSScott Long LIST_ENTRY(mpt_evtf_record) links; 5319b631363SMatt Jacob }; 5329b631363SMatt Jacob 533b0a2fdeeSScott Long LIST_HEAD(mpt_evtf_list, mpt_evtf_record); 5349b631363SMatt Jacob 5351d558d6aSScott Long struct mptsas_devinfo { 5361d558d6aSScott Long uint16_t dev_handle; 5371d558d6aSScott Long uint16_t parent_dev_handle; 5381d558d6aSScott Long uint16_t enclosure_handle; 5391d558d6aSScott Long uint16_t slot; 5401d558d6aSScott Long uint8_t phy_num; 5411d558d6aSScott Long uint8_t physical_port; 5421d558d6aSScott Long uint8_t target_id; 5431d558d6aSScott Long uint8_t bus; 5441d558d6aSScott Long uint64_t sas_address; 5451d558d6aSScott Long uint32_t device_info; 5461d558d6aSScott Long }; 5471d558d6aSScott Long 5481d558d6aSScott Long struct mptsas_phyinfo { 5491d558d6aSScott Long uint16_t handle; 5501d558d6aSScott Long uint8_t phy_num; 5511d558d6aSScott Long uint8_t port_id; 5521d558d6aSScott Long uint8_t negotiated_link_rate; 5531d558d6aSScott Long uint8_t hw_link_rate; 5541d558d6aSScott Long uint8_t programmed_link_rate; 5551d558d6aSScott Long uint8_t sas_port_add_phy; 5561d558d6aSScott Long struct mptsas_devinfo identify; 5571d558d6aSScott Long struct mptsas_devinfo attached; 5581d558d6aSScott Long }; 5591d558d6aSScott Long 5601d558d6aSScott Long struct mptsas_portinfo { 5611d558d6aSScott Long uint16_t num_phys; 5621d558d6aSScott Long struct mptsas_phyinfo *phy_info; 5631d558d6aSScott Long }; 5641d558d6aSScott Long 565b0a2fdeeSScott Long struct mpt_softc { 566b0a2fdeeSScott Long device_t dev; 567b0a2fdeeSScott Long struct mtx mpt_lock; 5685089bd63SMatt Jacob int mpt_locksetup; 569b0a2fdeeSScott Long uint32_t mpt_pers_mask; 570b4c618c0SMatt Jacob uint32_t 57104016bcfSMarius Strobl : 7, 572c87e3f83SMatt Jacob unit : 8, 573a2baed97SMatt Jacob ready : 1, 5740e0521a1SMatt Jacob fw_uploaded : 1, 575804625eeSMatt Jacob msi_enable : 1, 576c87e3f83SMatt Jacob twildcard : 1, 577c87e3f83SMatt Jacob tenabled : 1, 578b4c618c0SMatt Jacob do_cfg_role : 1, 5791d79ca0eSMatt Jacob raid_enabled : 1, 580b0a2fdeeSScott Long raid_mwce_set : 1, 581b0a2fdeeSScott Long getreqwaiter : 1, 582b0a2fdeeSScott Long shutdwn_raid : 1, 583b0a2fdeeSScott Long shutdwn_recovery: 1, 584b0a2fdeeSScott Long outofbeer : 1, 585b0a2fdeeSScott Long disabled : 1, 5865580ce96SMatt Jacob is_spi : 1, 587c87e3f83SMatt Jacob is_sas : 1, 58804016bcfSMarius Strobl is_fc : 1, 58904016bcfSMarius Strobl is_1078 : 1; 5909b631363SMatt Jacob 591b4c618c0SMatt Jacob u_int cfg_role; 592b4c618c0SMatt Jacob u_int role; /* role: none, ini, target, both */ 593b4c618c0SMatt Jacob 594b0a2fdeeSScott Long u_int verbose; 595a2baed97SMatt Jacob #ifdef MPT_TEST_MULTIPATH 596a2baed97SMatt Jacob int failure_id; 597a2baed97SMatt Jacob #endif 5989b631363SMatt Jacob 599b0a2fdeeSScott Long /* 600b0a2fdeeSScott Long * IOC Facts 601b0a2fdeeSScott Long */ 6020e0521a1SMatt Jacob MSG_IOC_FACTS_REPLY ioc_facts; 6039b631363SMatt Jacob 604b0a2fdeeSScott Long /* 605b0a2fdeeSScott Long * Port Facts 606b0a2fdeeSScott Long */ 6070e0521a1SMatt Jacob MSG_PORT_FACTS_REPLY * port_facts; 6080e0521a1SMatt Jacob #define mpt_max_tgtcmds port_facts[0].MaxPostedCmdBuffers 6099b631363SMatt Jacob 610b0a2fdeeSScott Long /* 611b0a2fdeeSScott Long * Device Configuration Information 612b0a2fdeeSScott Long */ 613b0a2fdeeSScott Long union { 614b0a2fdeeSScott Long struct mpt_spi_cfg { 615b0a2fdeeSScott Long CONFIG_PAGE_SCSI_PORT_0 _port_page0; 616b0a2fdeeSScott Long CONFIG_PAGE_SCSI_PORT_1 _port_page1; 617b0a2fdeeSScott Long CONFIG_PAGE_SCSI_PORT_2 _port_page2; 618b0a2fdeeSScott Long CONFIG_PAGE_SCSI_DEVICE_0 _dev_page0[16]; 619b0a2fdeeSScott Long CONFIG_PAGE_SCSI_DEVICE_1 _dev_page1[16]; 6208ba5efbdSMarius Strobl int _ini_id; 621b0a2fdeeSScott Long uint16_t _tag_enable; 622b0a2fdeeSScott Long uint16_t _disc_enable; 623b0a2fdeeSScott Long } spi; 624b0a2fdeeSScott Long #define mpt_port_page0 cfg.spi._port_page0 625b0a2fdeeSScott Long #define mpt_port_page1 cfg.spi._port_page1 626b0a2fdeeSScott Long #define mpt_port_page2 cfg.spi._port_page2 627b0a2fdeeSScott Long #define mpt_dev_page0 cfg.spi._dev_page0 628b0a2fdeeSScott Long #define mpt_dev_page1 cfg.spi._dev_page1 6298ba5efbdSMarius Strobl #define mpt_ini_id cfg.spi._ini_id 630b0a2fdeeSScott Long #define mpt_tag_enable cfg.spi._tag_enable 631b0a2fdeeSScott Long #define mpt_disc_enable cfg.spi._disc_enable 632b0a2fdeeSScott Long struct mpi_fc_cfg { 633c87e3f83SMatt Jacob CONFIG_PAGE_FC_PORT_0 _port_page0; 6349fe6d254SMatt Jacob uint32_t _port_speed; 635c87e3f83SMatt Jacob #define mpt_fcport_page0 cfg.fc._port_page0 6369fe6d254SMatt Jacob #define mpt_fcport_speed cfg.fc._port_speed 637b0a2fdeeSScott Long } fc; 638b0a2fdeeSScott Long } cfg; 639970043d7SMatt Jacob /* 640970043d7SMatt Jacob * Device config information stored up for sysctl to access 641970043d7SMatt Jacob */ 642970043d7SMatt Jacob union { 643970043d7SMatt Jacob struct { 644970043d7SMatt Jacob unsigned int initiator_id; 645970043d7SMatt Jacob } spi; 646970043d7SMatt Jacob struct { 647970043d7SMatt Jacob char wwnn[19]; 648970043d7SMatt Jacob char wwpn[19]; 649970043d7SMatt Jacob } fc; 650970043d7SMatt Jacob } scinfo; 651b0a2fdeeSScott Long 6521d79ca0eSMatt Jacob /* Controller Info for RAID information */ 653b0a2fdeeSScott Long CONFIG_PAGE_IOC_2 * ioc_page2; 654b0a2fdeeSScott Long CONFIG_PAGE_IOC_3 * ioc_page3; 655b0a2fdeeSScott Long 656b0a2fdeeSScott Long /* Raid Data */ 657b0a2fdeeSScott Long struct mpt_raid_volume* raid_volumes; 658b0a2fdeeSScott Long struct mpt_raid_disk* raid_disks; 659b0a2fdeeSScott Long u_int raid_max_volumes; 660b0a2fdeeSScott Long u_int raid_max_disks; 661b0a2fdeeSScott Long u_int raid_page0_len; 662b0a2fdeeSScott Long u_int raid_wakeup; 663b0a2fdeeSScott Long u_int raid_rescan; 664b0a2fdeeSScott Long u_int raid_resync_rate; 665b0a2fdeeSScott Long u_int raid_mwce_setting; 666b0a2fdeeSScott Long u_int raid_queue_depth; 6675cc0208aSAlexander Kabaev u_int raid_nonopt_volumes; 668b0a2fdeeSScott Long struct proc *raid_thread; 669b0a2fdeeSScott Long struct callout raid_timer; 670b0a2fdeeSScott Long 671b0a2fdeeSScott Long /* 672b0a2fdeeSScott Long * PCI Hardware info 673b0a2fdeeSScott Long */ 674280388afSJohn Baldwin int pci_msi_count; 675b0a2fdeeSScott Long struct resource * pci_irq; /* Interrupt map for chip */ 6765ab13afcSMarius Strobl void * ih; /* Interrupt handle */ 677fd61f421SMarius Strobl #if 0 678b0a2fdeeSScott Long struct mpt_pci_cfg pci_cfg; /* saved PCI conf registers */ 679fd61f421SMarius Strobl #endif 680b0a2fdeeSScott Long 681b0a2fdeeSScott Long /* 682b0a2fdeeSScott Long * DMA Mapping Stuff 683b0a2fdeeSScott Long */ 684b0a2fdeeSScott Long struct resource * pci_reg; /* Register map for chip */ 685b0a2fdeeSScott Long bus_space_tag_t pci_st; /* Bus tag for registers */ 686b0a2fdeeSScott Long bus_space_handle_t pci_sh; /* Bus handle for registers */ 687b0a2fdeeSScott Long /* PIO versions of above. */ 688b0a2fdeeSScott Long struct resource * pci_pio_reg; 689b0a2fdeeSScott Long bus_space_tag_t pci_pio_st; 690b0a2fdeeSScott Long bus_space_handle_t pci_pio_sh; 691b0a2fdeeSScott Long 692b0a2fdeeSScott Long bus_dma_tag_t parent_dmat; /* DMA tag for parent PCI bus */ 693b0a2fdeeSScott Long bus_dma_tag_t reply_dmat; /* DMA tag for reply memory */ 694b0a2fdeeSScott Long bus_dmamap_t reply_dmap; /* DMA map for reply memory */ 695b0a2fdeeSScott Long uint8_t *reply; /* KVA of reply memory */ 696b0a2fdeeSScott Long bus_addr_t reply_phys; /* BusAddr of reply memory */ 697b0a2fdeeSScott Long 698b0a2fdeeSScott Long bus_dma_tag_t buffer_dmat; /* DMA tag for buffers */ 699b0a2fdeeSScott Long bus_dma_tag_t request_dmat; /* DMA tag for request memroy */ 700b0a2fdeeSScott Long bus_dmamap_t request_dmap; /* DMA map for request memroy */ 701b0a2fdeeSScott Long uint8_t *request; /* KVA of Request memory */ 702c87e3f83SMatt Jacob bus_addr_t request_phys; /* BusAddr of request memory */ 703b0a2fdeeSScott Long 704444dd2b6SMatt Jacob uint32_t max_seg_cnt; /* calculated after IOC facts */ 7054201341fSKenneth D. Merry uint32_t max_cam_seg_cnt;/* calculated from MAXPHYS*/ 706444dd2b6SMatt Jacob 707444dd2b6SMatt Jacob /* 708444dd2b6SMatt Jacob * Hardware management 709444dd2b6SMatt Jacob */ 710b0a2fdeeSScott Long u_int reset_cnt; 711b0a2fdeeSScott Long 712b0a2fdeeSScott Long /* 713b0a2fdeeSScott Long * CAM && Software Management 714b0a2fdeeSScott Long */ 715b0a2fdeeSScott Long request_t *request_pool; 716b0a2fdeeSScott Long struct req_queue request_free_list; 717b0a2fdeeSScott Long struct req_queue request_pending_list; 718b0a2fdeeSScott Long struct req_queue request_timeout_list; 719b0a2fdeeSScott Long 720b0a2fdeeSScott Long 721b0a2fdeeSScott Long struct cam_sim *sim; 722b0a2fdeeSScott Long struct cam_path *path; 723b0a2fdeeSScott Long 724b0a2fdeeSScott Long struct cam_sim *phydisk_sim; 725b0a2fdeeSScott Long struct cam_path *phydisk_path; 726b0a2fdeeSScott Long 727b0a2fdeeSScott Long struct proc *recovery_thread; 728b0a2fdeeSScott Long request_t *tmf_req; 729b0a2fdeeSScott Long 730c87e3f83SMatt Jacob /* 7315e073106SMatt Jacob * Deferred frame acks due to resource shortage. 7325e073106SMatt Jacob */ 7335e073106SMatt Jacob struct mpt_evtf_list ack_frames; 734fcd9a16bSMatt Jacob 7355e073106SMatt Jacob /* 736c87e3f83SMatt Jacob * Target Mode Support 737c87e3f83SMatt Jacob */ 738c87e3f83SMatt Jacob uint32_t scsi_tgt_handler_id; 739c87e3f83SMatt Jacob request_t ** tgt_cmd_ptrs; 7405089bd63SMatt Jacob request_t ** els_cmd_ptrs; /* FC only */ 741c87e3f83SMatt Jacob 742c87e3f83SMatt Jacob /* 743c87e3f83SMatt Jacob * *snork*- this is chosen to be here *just in case* somebody 744c87e3f83SMatt Jacob * forgets to point to it exactly and we index off of trt with 745c87e3f83SMatt Jacob * CAM_LUN_WILDCARD. 746c87e3f83SMatt Jacob */ 747c87e3f83SMatt Jacob tgt_resource_t trt_wildcard; /* wildcard luns */ 748c87e3f83SMatt Jacob tgt_resource_t trt[MPT_MAX_LUNS]; 749c87e3f83SMatt Jacob uint16_t tgt_cmds_allocated; 7505089bd63SMatt Jacob uint16_t els_cmds_allocated; /* FC only */ 751c87e3f83SMatt Jacob 752c87e3f83SMatt Jacob uint16_t timeouts; /* timeout count */ 753c87e3f83SMatt Jacob uint16_t success; /* successes afer timeout */ 7545089bd63SMatt Jacob uint16_t sequence; /* Sequence Number */ 7555089bd63SMatt Jacob uint16_t pad3; 756c87e3f83SMatt Jacob 757b0a2fdeeSScott Long 758fcd9a16bSMatt Jacob /* Paired port in some dual adapters configurations */ 759b0a2fdeeSScott Long struct mpt_softc * mpt2; 760b0a2fdeeSScott Long 761b0a2fdeeSScott Long /* FW Image management */ 762b0a2fdeeSScott Long uint32_t fw_image_size; 763b0a2fdeeSScott Long uint8_t *fw_image; 764b0a2fdeeSScott Long bus_dma_tag_t fw_dmat; /* DMA tag for firmware image */ 765b0a2fdeeSScott Long bus_dmamap_t fw_dmap; /* DMA map for firmware image */ 7665580ce96SMatt Jacob bus_addr_t fw_phys; /* BusAddr of firmware image */ 767b0a2fdeeSScott Long 7681d558d6aSScott Long /* SAS Topology */ 7691d558d6aSScott Long struct mptsas_portinfo *sas_portinfo; 7701d558d6aSScott Long 771b0a2fdeeSScott Long /* Shutdown Event Handler. */ 772b0a2fdeeSScott Long eventhandler_tag eh; 773b0a2fdeeSScott Long 774ee98c4a5SJohn Baldwin /* Userland management interface. */ 775ee98c4a5SJohn Baldwin struct cdev *cdev; 776ee98c4a5SJohn Baldwin 777b0a2fdeeSScott Long TAILQ_ENTRY(mpt_softc) links; 778b0a2fdeeSScott Long }; 779b0a2fdeeSScott Long 7805089bd63SMatt Jacob static __inline void mpt_assign_serno(struct mpt_softc *, request_t *); 7815089bd63SMatt Jacob 7825089bd63SMatt Jacob static __inline void 7835089bd63SMatt Jacob mpt_assign_serno(struct mpt_softc *mpt, request_t *req) 7845089bd63SMatt Jacob { 7855089bd63SMatt Jacob if ((req->serno = mpt->sequence++) == 0) { 7865089bd63SMatt Jacob req->serno = mpt->sequence++; 7875089bd63SMatt Jacob } 7885089bd63SMatt Jacob } 7895089bd63SMatt Jacob 790c87e3f83SMatt Jacob /***************************** Locking Primitives *****************************/ 791d0a68c27SMatt Jacob #if 1 792b0a2fdeeSScott Long #define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE 793b0a2fdeeSScott Long #define MPT_LOCK_SETUP(mpt) \ 794b0a2fdeeSScott Long mtx_init(&mpt->mpt_lock, "mpt", NULL, MTX_DEF); \ 795b0a2fdeeSScott Long mpt->mpt_locksetup = 1 796b0a2fdeeSScott Long #define MPT_LOCK_DESTROY(mpt) \ 797b0a2fdeeSScott Long if (mpt->mpt_locksetup) { \ 798b0a2fdeeSScott Long mtx_destroy(&mpt->mpt_lock); \ 799b0a2fdeeSScott Long mpt->mpt_locksetup = 0; \ 800b0a2fdeeSScott Long } 801b0a2fdeeSScott Long 802b0a2fdeeSScott Long #define MPT_LOCK(mpt) mtx_lock(&(mpt)->mpt_lock) 803b0a2fdeeSScott Long #define MPT_UNLOCK(mpt) mtx_unlock(&(mpt)->mpt_lock) 8045089bd63SMatt Jacob #define MPT_OWNED(mpt) mtx_owned(&(mpt)->mpt_lock) 805d0a68c27SMatt Jacob #define MPT_LOCK_ASSERT(mpt) mtx_assert(&(mpt)->mpt_lock, MA_OWNED) 806d0a68c27SMatt Jacob #define MPTLOCK_2_CAMLOCK(mpt) 807d0a68c27SMatt Jacob #define CAMLOCK_2_MPTLOCK(mpt) 808b0a2fdeeSScott Long #define mpt_sleep(mpt, ident, priority, wmesg, timo) \ 809b0a2fdeeSScott Long msleep(ident, &(mpt)->mpt_lock, priority, wmesg, timo) 810d0a68c27SMatt Jacob #define mpt_req_timeout(req, ticks, func, arg) \ 811363b8ed7SAlexander Kabaev callout_reset(&(req)->callout, (ticks), (func), (arg)) 812d0a68c27SMatt Jacob #define mpt_req_untimeout(req, func, arg) \ 813d0a68c27SMatt Jacob callout_stop(&(req)->callout) 814363b8ed7SAlexander Kabaev #define mpt_callout_init(mpt, c) \ 815363b8ed7SAlexander Kabaev callout_init_mtx(c, &(mpt)->mpt_lock, 0) 816363b8ed7SAlexander Kabaev #define mpt_callout_drain(mpt, c) \ 817363b8ed7SAlexander Kabaev callout_drain(c) 8185089bd63SMatt Jacob 819b0a2fdeeSScott Long #else 8205089bd63SMatt Jacob 821b0a2fdeeSScott Long #define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY 822b0a2fdeeSScott Long #define MPT_LOCK_SETUP(mpt) do { } while (0) 823b0a2fdeeSScott Long #define MPT_LOCK_DESTROY(mpt) do { } while (0) 824d0a68c27SMatt Jacob #define MPT_LOCK_ASSERT(mpt) mtx_assert(&Giant, MA_OWNED) 825d0a68c27SMatt Jacob #define MPT_LOCK(mpt) mtx_lock(&Giant) 826d0a68c27SMatt Jacob #define MPT_UNLOCK(mpt) mtx_unlock(&Giant) 827d0a68c27SMatt Jacob #define MPTLOCK_2_CAMLOCK(mpt) 828d0a68c27SMatt Jacob #define CAMLOCK_2_MPTLOCK(mpt) 8295089bd63SMatt Jacob 830363b8ed7SAlexander Kabaev #define mpt_req_timeout(req, ticks, func, arg) \ 831363b8ed7SAlexander Kabaev callout_reset(&(req)->callout, (ticks), (func), (arg)) 832363b8ed7SAlexander Kabaev #define mpt_req_untimeout(req, func, arg) \ 833363b8ed7SAlexander Kabaev callout_stop(&(req)->callout) 834363b8ed7SAlexander Kabaev #define mpt_callout_init(mpt, c) \ 835363b8ed7SAlexander Kabaev callout_init(c, 0) 836363b8ed7SAlexander Kabaev #define mpt_callout_drain(mpt, c) \ 837363b8ed7SAlexander Kabaev callout_drain(c) 838363b8ed7SAlexander Kabaev 8395089bd63SMatt Jacob static __inline int 8405089bd63SMatt Jacob mpt_sleep(struct mpt_softc *, void *, int, const char *, int); 8415089bd63SMatt Jacob 8425089bd63SMatt Jacob static __inline int 8435089bd63SMatt Jacob mpt_sleep(struct mpt_softc *mpt, void *i, int p, const char *w, int t) 8445089bd63SMatt Jacob { 8455089bd63SMatt Jacob int r; 8465089bd63SMatt Jacob r = tsleep(i, p, w, t); 8475089bd63SMatt Jacob return (r); 8485089bd63SMatt Jacob } 849b0a2fdeeSScott Long #endif 850b0a2fdeeSScott Long 851b0a2fdeeSScott Long /******************************* Register Access ******************************/ 852b0a2fdeeSScott Long static __inline void mpt_write(struct mpt_softc *, size_t, uint32_t); 853b0a2fdeeSScott Long static __inline uint32_t mpt_read(struct mpt_softc *, int); 854b0a2fdeeSScott Long static __inline void mpt_pio_write(struct mpt_softc *, size_t, uint32_t); 855b0a2fdeeSScott Long static __inline uint32_t mpt_pio_read(struct mpt_softc *, int); 856b0a2fdeeSScott Long 857b0a2fdeeSScott Long static __inline void 858b0a2fdeeSScott Long mpt_write(struct mpt_softc *mpt, size_t offset, uint32_t val) 859b0a2fdeeSScott Long { 860b0a2fdeeSScott Long bus_space_write_4(mpt->pci_st, mpt->pci_sh, offset, val); 861b0a2fdeeSScott Long } 862b0a2fdeeSScott Long 863b0a2fdeeSScott Long static __inline uint32_t 864b0a2fdeeSScott Long mpt_read(struct mpt_softc *mpt, int offset) 865b0a2fdeeSScott Long { 866b0a2fdeeSScott Long return (bus_space_read_4(mpt->pci_st, mpt->pci_sh, offset)); 867b0a2fdeeSScott Long } 868b0a2fdeeSScott Long 869b0a2fdeeSScott Long /* 870b0a2fdeeSScott Long * Some operations (e.g. diagnostic register writes while the ARM proccessor 871b0a2fdeeSScott Long * is disabled), must be performed using "PCI pio" operations. On non-PCI 872b0a2fdeeSScott Long * busses, these operations likely map to normal register accesses. 873b0a2fdeeSScott Long */ 874b0a2fdeeSScott Long static __inline void 875b0a2fdeeSScott Long mpt_pio_write(struct mpt_softc *mpt, size_t offset, uint32_t val) 876b0a2fdeeSScott Long { 87704016bcfSMarius Strobl KASSERT(mpt->pci_pio_reg != NULL, ("no PIO resource")); 878b0a2fdeeSScott Long bus_space_write_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset, val); 879b0a2fdeeSScott Long } 880b0a2fdeeSScott Long 881b0a2fdeeSScott Long static __inline uint32_t 882b0a2fdeeSScott Long mpt_pio_read(struct mpt_softc *mpt, int offset) 883b0a2fdeeSScott Long { 88404016bcfSMarius Strobl KASSERT(mpt->pci_pio_reg != NULL, ("no PIO resource")); 885b0a2fdeeSScott Long return (bus_space_read_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset)); 886b0a2fdeeSScott Long } 887b0a2fdeeSScott Long /*********************** Reply Frame/Request Management ***********************/ 888b0a2fdeeSScott Long /* Max MPT Reply we are willing to accept (must be power of 2) */ 889444dd2b6SMatt Jacob #define MPT_REPLY_SIZE 256 890b0a2fdeeSScott Long 891c87e3f83SMatt Jacob /* 892c87e3f83SMatt Jacob * Must be less than 16384 in order for target mode to work 893c87e3f83SMatt Jacob */ 894444dd2b6SMatt Jacob #define MPT_MAX_REQUESTS(mpt) 512 895b0a2fdeeSScott Long #define MPT_REQUEST_AREA 512 896444dd2b6SMatt Jacob #define MPT_SENSE_SIZE 32 /* included in MPT_REQUEST_AREA */ 897b0a2fdeeSScott Long #define MPT_REQ_MEM_SIZE(mpt) (MPT_MAX_REQUESTS(mpt) * MPT_REQUEST_AREA) 898b0a2fdeeSScott Long 8995e073106SMatt Jacob #define MPT_CONTEXT_CB_SHIFT (16) 900b0a2fdeeSScott Long #define MPT_CBI(handle) (handle >> MPT_CONTEXT_CB_SHIFT) 901b0a2fdeeSScott Long #define MPT_CBI_TO_HID(cbi) ((cbi) << MPT_CONTEXT_CB_SHIFT) 902b0a2fdeeSScott Long #define MPT_CONTEXT_TO_CBI(x) \ 903b0a2fdeeSScott Long (((x) >> MPT_CONTEXT_CB_SHIFT) & (MPT_NUM_REPLY_HANDLERS - 1)) 9045e073106SMatt Jacob #define MPT_CONTEXT_REQI_MASK 0xFFFF 905c87e3f83SMatt Jacob #define MPT_CONTEXT_TO_REQI(x) ((x) & MPT_CONTEXT_REQI_MASK) 906b0a2fdeeSScott Long 907b0a2fdeeSScott Long /* 908b0a2fdeeSScott Long * Convert a 32bit physical address returned from IOC to an 909b0a2fdeeSScott Long * offset into our reply frame memory or the kvm address needed 910b0a2fdeeSScott Long * to access the data. The returned address is only the low 911b0a2fdeeSScott Long * 32 bits, so mask our base physical address accordingly. 912b0a2fdeeSScott Long */ 913b0a2fdeeSScott Long #define MPT_REPLY_BADDR(x) \ 914b0a2fdeeSScott Long (x << 1) 915b0a2fdeeSScott Long #define MPT_REPLY_OTOV(m, i) \ 916b0a2fdeeSScott Long ((void *)(&m->reply[i])) 917b0a2fdeeSScott Long 918b0a2fdeeSScott Long #define MPT_DUMP_REPLY_FRAME(mpt, reply_frame) \ 919b0a2fdeeSScott Long do { \ 9201d79ca0eSMatt Jacob if (mpt->verbose > MPT_PRT_DEBUG) \ 921b0a2fdeeSScott Long mpt_dump_reply_frame(mpt, reply_frame); \ 922b0a2fdeeSScott Long } while(0) 923b0a2fdeeSScott Long 924b0a2fdeeSScott Long static __inline uint32_t mpt_pop_reply_queue(struct mpt_softc *mpt); 925b0a2fdeeSScott Long static __inline void mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr); 926b0a2fdeeSScott Long 927b0a2fdeeSScott Long /* 928b0a2fdeeSScott Long * Give the reply buffer back to the IOC after we have 929b0a2fdeeSScott Long * finished processing it. 930b0a2fdeeSScott Long */ 931b0a2fdeeSScott Long static __inline void 932b0a2fdeeSScott Long mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr) 933b0a2fdeeSScott Long { 934b0a2fdeeSScott Long mpt_write(mpt, MPT_OFFSET_REPLY_Q, ptr); 935b0a2fdeeSScott Long } 936b0a2fdeeSScott Long 937b0a2fdeeSScott Long /* Get a reply from the IOC */ 938b0a2fdeeSScott Long static __inline uint32_t 939b0a2fdeeSScott Long mpt_pop_reply_queue(struct mpt_softc *mpt) 940b0a2fdeeSScott Long { 941b0a2fdeeSScott Long return mpt_read(mpt, MPT_OFFSET_REPLY_Q); 942b0a2fdeeSScott Long } 943b0a2fdeeSScott Long 9445e073106SMatt Jacob void 9455e073106SMatt Jacob mpt_complete_request_chain(struct mpt_softc *, struct req_queue *, u_int); 9465e073106SMatt Jacob 9475ab13afcSMarius Strobl /************************** Scatter Gather Management **************************/ 948444dd2b6SMatt Jacob /* MPT_RQSL- size of request frame, in bytes */ 9490e0521a1SMatt Jacob #define MPT_RQSL(mpt) (mpt->ioc_facts.RequestFrameSize << 2) 950b0a2fdeeSScott Long 951444dd2b6SMatt Jacob /* MPT_NSGL- how many SG entries can fit in a request frame size */ 952444dd2b6SMatt Jacob #define MPT_NSGL(mpt) (MPT_RQSL(mpt) / sizeof (SGE_IO_UNION)) 953444dd2b6SMatt Jacob 954444dd2b6SMatt Jacob /* MPT_NRFM- how many request frames can fit in each request alloc we make */ 955444dd2b6SMatt Jacob #define MPT_NRFM(mpt) (MPT_REQUEST_AREA / MPT_RQSL(mpt)) 956444dd2b6SMatt Jacob 957444dd2b6SMatt Jacob /* 958444dd2b6SMatt Jacob * MPT_NSGL_FIRST- # of SG elements that can fit after 959444dd2b6SMatt Jacob * an I/O request but still within the request frame. 960444dd2b6SMatt Jacob * Do this safely based upon SGE_IO_UNION. 961444dd2b6SMatt Jacob * 962444dd2b6SMatt Jacob * Note that the first element is *within* the SCSI request. 963444dd2b6SMatt Jacob */ 964b0a2fdeeSScott Long #define MPT_NSGL_FIRST(mpt) \ 965444dd2b6SMatt Jacob ((MPT_RQSL(mpt) - sizeof (MSG_SCSI_IO_REQUEST) + sizeof (SGE_IO_UNION)) / \ 966444dd2b6SMatt Jacob sizeof (SGE_IO_UNION)) 967b0a2fdeeSScott Long 968b0a2fdeeSScott Long /***************************** IOC Initialization *****************************/ 969b0a2fdeeSScott Long int mpt_reset(struct mpt_softc *, int /*reinit*/); 970b0a2fdeeSScott Long 971c87e3f83SMatt Jacob /****************************** Debugging ************************************/ 972b4c618c0SMatt Jacob void mpt_dump_data(struct mpt_softc *, const char *, void *, int); 9730e3b145eSMatt Jacob void mpt_dump_request(struct mpt_softc *, request_t *); 9740e3b145eSMatt Jacob 975b0a2fdeeSScott Long enum { 976b0a2fdeeSScott Long MPT_PRT_ALWAYS, 977b0a2fdeeSScott Long MPT_PRT_FATAL, 978b0a2fdeeSScott Long MPT_PRT_ERROR, 979b0a2fdeeSScott Long MPT_PRT_WARN, 980b0a2fdeeSScott Long MPT_PRT_INFO, 981ac219b98SMatt Jacob MPT_PRT_NEGOTIATION, 982b0a2fdeeSScott Long MPT_PRT_DEBUG, 983c87e3f83SMatt Jacob MPT_PRT_DEBUG1, 984c87e3f83SMatt Jacob MPT_PRT_DEBUG2, 985c87e3f83SMatt Jacob MPT_PRT_DEBUG3, 986444dd2b6SMatt Jacob MPT_PRT_TRACE, 987444dd2b6SMatt Jacob MPT_PRT_NONE=100 988b0a2fdeeSScott Long }; 989b0a2fdeeSScott Long 990b0a2fdeeSScott Long #define mpt_lprt(mpt, level, ...) \ 991b0a2fdeeSScott Long do { \ 992b0a2fdeeSScott Long if (level <= (mpt)->verbose) \ 993b0a2fdeeSScott Long mpt_prt(mpt, __VA_ARGS__); \ 994b0a2fdeeSScott Long } while (0) 995b0a2fdeeSScott Long 99687e255acSMarius Strobl #if 0 997b0a2fdeeSScott Long #define mpt_lprtc(mpt, level, ...) \ 998b0a2fdeeSScott Long do { \ 999d6a4eec4SMarius Strobl if (level <= (mpt)->verbose) \ 1000b0a2fdeeSScott Long mpt_prtc(mpt, __VA_ARGS__); \ 1001b0a2fdeeSScott Long } while (0) 100287e255acSMarius Strobl #endif 1003*4b847ffaSMarius Strobl 1004c87e3f83SMatt Jacob void mpt_prt(struct mpt_softc *, const char *, ...) 1005c87e3f83SMatt Jacob __printflike(2, 3); 1006c87e3f83SMatt Jacob void mpt_prtc(struct mpt_softc *, const char *, ...) 1007c87e3f83SMatt Jacob __printflike(2, 3); 1008b0a2fdeeSScott Long 1009c87e3f83SMatt Jacob /**************************** Target Mode Related ***************************/ 1010c87e3f83SMatt Jacob static __inline int mpt_cdblen(uint8_t, int); 1011c87e3f83SMatt Jacob static __inline int 1012c87e3f83SMatt Jacob mpt_cdblen(uint8_t cdb0, int maxlen) 1013c87e3f83SMatt Jacob { 1014c87e3f83SMatt Jacob int group = cdb0 >> 5; 1015c87e3f83SMatt Jacob switch (group) { 1016c87e3f83SMatt Jacob case 0: 1017c87e3f83SMatt Jacob return (6); 1018c87e3f83SMatt Jacob case 1: 1019c87e3f83SMatt Jacob return (10); 1020c87e3f83SMatt Jacob case 4: 1021c87e3f83SMatt Jacob case 5: 1022c87e3f83SMatt Jacob return (12); 1023c87e3f83SMatt Jacob default: 1024c87e3f83SMatt Jacob return (16); 1025c87e3f83SMatt Jacob } 1026c87e3f83SMatt Jacob } 1027c87e3f83SMatt Jacob #ifdef INVARIANTS 1028c87e3f83SMatt Jacob static __inline request_t * mpt_tag_2_req(struct mpt_softc *, uint32_t); 1029c87e3f83SMatt Jacob static __inline request_t * 1030c87e3f83SMatt Jacob mpt_tag_2_req(struct mpt_softc *mpt, uint32_t tag) 1031c87e3f83SMatt Jacob { 10325e073106SMatt Jacob uint16_t rtg = (tag >> 18); 10334349d278SMarius Strobl KASSERT(rtg < mpt->tgt_cmds_allocated, ("bad tag %d", tag)); 1034c87e3f83SMatt Jacob KASSERT(mpt->tgt_cmd_ptrs, ("no cmd backpointer array")); 1035c87e3f83SMatt Jacob KASSERT(mpt->tgt_cmd_ptrs[rtg], ("no cmd backpointer")); 1036c87e3f83SMatt Jacob return (mpt->tgt_cmd_ptrs[rtg]); 1037c87e3f83SMatt Jacob } 1038cd23a6e0SMarius Strobl #endif 10395089bd63SMatt Jacob 10405089bd63SMatt Jacob static __inline int 10415089bd63SMatt Jacob mpt_req_on_free_list(struct mpt_softc *, request_t *); 10425089bd63SMatt Jacob static __inline int 10435089bd63SMatt Jacob mpt_req_on_pending_list(struct mpt_softc *, request_t *); 10445089bd63SMatt Jacob 10455089bd63SMatt Jacob /* 10465089bd63SMatt Jacob * Is request on freelist? 10475089bd63SMatt Jacob */ 10485089bd63SMatt Jacob static __inline int 10495089bd63SMatt Jacob mpt_req_on_free_list(struct mpt_softc *mpt, request_t *req) 10505089bd63SMatt Jacob { 10515089bd63SMatt Jacob request_t *lrq; 10525089bd63SMatt Jacob 10535089bd63SMatt Jacob TAILQ_FOREACH(lrq, &mpt->request_free_list, links) { 10545089bd63SMatt Jacob if (lrq == req) { 10555089bd63SMatt Jacob return (1); 10565089bd63SMatt Jacob } 10575089bd63SMatt Jacob } 10585089bd63SMatt Jacob return (0); 10595089bd63SMatt Jacob } 10605089bd63SMatt Jacob 10615089bd63SMatt Jacob /* 10625089bd63SMatt Jacob * Is request on pending list? 10635089bd63SMatt Jacob */ 10645089bd63SMatt Jacob static __inline int 10655089bd63SMatt Jacob mpt_req_on_pending_list(struct mpt_softc *mpt, request_t *req) 10665089bd63SMatt Jacob { 10675089bd63SMatt Jacob request_t *lrq; 10685089bd63SMatt Jacob 10695089bd63SMatt Jacob TAILQ_FOREACH(lrq, &mpt->request_pending_list, links) { 10705089bd63SMatt Jacob if (lrq == req) { 10715089bd63SMatt Jacob return (1); 10725089bd63SMatt Jacob } 10735089bd63SMatt Jacob } 10745089bd63SMatt Jacob return (0); 10755089bd63SMatt Jacob } 10765089bd63SMatt Jacob 1077cd23a6e0SMarius Strobl #ifdef INVARIANTS 1078cd23a6e0SMarius Strobl static __inline void 1079cd23a6e0SMarius Strobl mpt_req_spcl(struct mpt_softc *, request_t *, const char *, int); 1080cd23a6e0SMarius Strobl static __inline void 1081cd23a6e0SMarius Strobl mpt_req_not_spcl(struct mpt_softc *, request_t *, const char *, int); 1082cd23a6e0SMarius Strobl 10835089bd63SMatt Jacob /* 10845089bd63SMatt Jacob * Make sure that req *is* part of one of the special lists 10855089bd63SMatt Jacob */ 10865089bd63SMatt Jacob static __inline void 10875089bd63SMatt Jacob mpt_req_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line) 10885089bd63SMatt Jacob { 10895089bd63SMatt Jacob int i; 10905089bd63SMatt Jacob for (i = 0; i < mpt->els_cmds_allocated; i++) { 10915089bd63SMatt Jacob if (req == mpt->els_cmd_ptrs[i]) { 10925089bd63SMatt Jacob return; 10935089bd63SMatt Jacob } 10945089bd63SMatt Jacob } 10955089bd63SMatt Jacob for (i = 0; i < mpt->tgt_cmds_allocated; i++) { 10965089bd63SMatt Jacob if (req == mpt->tgt_cmd_ptrs[i]) { 10975089bd63SMatt Jacob return; 10985089bd63SMatt Jacob } 10995089bd63SMatt Jacob } 11004349d278SMarius Strobl panic("%s(%d): req %p:%u function %x not in els or tgt ptrs", 11015089bd63SMatt Jacob s, line, req, req->serno, 11025089bd63SMatt Jacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function); 11035089bd63SMatt Jacob } 11045089bd63SMatt Jacob 11055089bd63SMatt Jacob /* 11065089bd63SMatt Jacob * Make sure that req is *not* part of one of the special lists. 11075089bd63SMatt Jacob */ 11085089bd63SMatt Jacob static __inline void 11095089bd63SMatt Jacob mpt_req_not_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line) 11105089bd63SMatt Jacob { 11115089bd63SMatt Jacob int i; 11125089bd63SMatt Jacob for (i = 0; i < mpt->els_cmds_allocated; i++) { 11135089bd63SMatt Jacob KASSERT(req != mpt->els_cmd_ptrs[i], 11144349d278SMarius Strobl ("%s(%d): req %p:%u func %x in els ptrs at ioindex %d", 11155089bd63SMatt Jacob s, line, req, req->serno, 11165089bd63SMatt Jacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i)); 11175089bd63SMatt Jacob } 11185089bd63SMatt Jacob for (i = 0; i < mpt->tgt_cmds_allocated; i++) { 11195089bd63SMatt Jacob KASSERT(req != mpt->tgt_cmd_ptrs[i], 11204349d278SMarius Strobl ("%s(%d): req %p:%u func %x in tgt ptrs at ioindex %d", 11215089bd63SMatt Jacob s, line, req, req->serno, 11225089bd63SMatt Jacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i)); 11235089bd63SMatt Jacob } 11245089bd63SMatt Jacob } 1125c87e3f83SMatt Jacob #endif 1126c87e3f83SMatt Jacob 112773651fd1SMatt Jacob /* 112873651fd1SMatt Jacob * Task Management Types, purely for internal consumption 112973651fd1SMatt Jacob */ 1130c87e3f83SMatt Jacob typedef enum { 1131c87e3f83SMatt Jacob MPT_ABORT_TASK_SET=1234, 1132c87e3f83SMatt Jacob MPT_CLEAR_TASK_SET, 1133c87e3f83SMatt Jacob MPT_TARGET_RESET, 1134c87e3f83SMatt Jacob MPT_CLEAR_ACA, 1135c87e3f83SMatt Jacob MPT_TERMINATE_TASK, 1136c87e3f83SMatt Jacob MPT_NIL_TMT_VALUE=5678 1137c87e3f83SMatt Jacob } mpt_task_mgmt_t; 1138b0a2fdeeSScott Long 1139b0a2fdeeSScott Long /**************************** Unclassified Routines ***************************/ 1140b0a2fdeeSScott Long void mpt_send_cmd(struct mpt_softc *mpt, request_t *req); 1141b0a2fdeeSScott Long int mpt_recv_handshake_reply(struct mpt_softc *mpt, 1142b0a2fdeeSScott Long size_t reply_len, void *reply); 1143b0a2fdeeSScott Long int mpt_wait_req(struct mpt_softc *mpt, request_t *req, 1144b0a2fdeeSScott Long mpt_req_state_t state, mpt_req_state_t mask, 1145b0a2fdeeSScott Long int sleep_ok, int time_ms); 1146b0a2fdeeSScott Long void mpt_enable_ints(struct mpt_softc *mpt); 1147b0a2fdeeSScott Long void mpt_disable_ints(struct mpt_softc *mpt); 1148b0a2fdeeSScott Long int mpt_attach(struct mpt_softc *mpt); 1149b0a2fdeeSScott Long int mpt_shutdown(struct mpt_softc *mpt); 1150b0a2fdeeSScott Long int mpt_detach(struct mpt_softc *mpt); 1151b0a2fdeeSScott Long int mpt_send_handshake_cmd(struct mpt_softc *mpt, 1152b0a2fdeeSScott Long size_t len, void *cmd); 1153b0a2fdeeSScott Long request_t * mpt_get_request(struct mpt_softc *mpt, int sleep_ok); 1154b0a2fdeeSScott Long void mpt_free_request(struct mpt_softc *mpt, request_t *req); 1155b0a2fdeeSScott Long void mpt_intr(void *arg); 1156b0a2fdeeSScott Long void mpt_check_doorbell(struct mpt_softc *mpt); 1157b0a2fdeeSScott Long void mpt_dump_reply_frame(struct mpt_softc *mpt, 1158b0a2fdeeSScott Long MSG_DEFAULT_REPLY *reply_frame); 1159b0a2fdeeSScott Long 1160b0a2fdeeSScott Long int mpt_issue_cfg_req(struct mpt_softc */*mpt*/, request_t */*req*/, 11611d558d6aSScott Long cfgparms_t *params, 1162b0a2fdeeSScott Long bus_addr_t /*addr*/, bus_size_t/*len*/, 1163b0a2fdeeSScott Long int /*sleep_ok*/, int /*timeout_ms*/); 11641d558d6aSScott Long int mpt_read_extcfg_header(struct mpt_softc *mpt, int PageVersion, 11651d558d6aSScott Long int PageNumber, uint32_t PageAddress, 11661d558d6aSScott Long int ExtPageType, 11671d558d6aSScott Long CONFIG_EXTENDED_PAGE_HEADER *rslt, 11681d558d6aSScott Long int sleep_ok, int timeout_ms); 11691d558d6aSScott Long int mpt_read_extcfg_page(struct mpt_softc *mpt, int Action, 11701d558d6aSScott Long uint32_t PageAddress, 11711d558d6aSScott Long CONFIG_EXTENDED_PAGE_HEADER *hdr, 11721d558d6aSScott Long void *buf, size_t len, int sleep_ok, 11731d558d6aSScott Long int timeout_ms); 1174b0a2fdeeSScott Long int mpt_read_cfg_header(struct mpt_softc *, int /*PageType*/, 1175b0a2fdeeSScott Long int /*PageNumber*/, 1176b0a2fdeeSScott Long uint32_t /*PageAddress*/, 1177b0a2fdeeSScott Long CONFIG_PAGE_HEADER *, 1178b0a2fdeeSScott Long int /*sleep_ok*/, int /*timeout_ms*/); 1179b0a2fdeeSScott Long int mpt_read_cfg_page(struct mpt_softc *t, int /*Action*/, 1180b0a2fdeeSScott Long uint32_t /*PageAddress*/, 1181b0a2fdeeSScott Long CONFIG_PAGE_HEADER *, size_t /*len*/, 1182b0a2fdeeSScott Long int /*sleep_ok*/, int /*timeout_ms*/); 1183b0a2fdeeSScott Long int mpt_write_cfg_page(struct mpt_softc *, int /*Action*/, 1184b0a2fdeeSScott Long uint32_t /*PageAddress*/, 1185b0a2fdeeSScott Long CONFIG_PAGE_HEADER *, size_t /*len*/, 1186b0a2fdeeSScott Long int /*sleep_ok*/, int /*timeout_ms*/); 1187b0a2fdeeSScott Long static __inline int 1188b0a2fdeeSScott Long mpt_read_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress, 1189b0a2fdeeSScott Long CONFIG_PAGE_HEADER *hdr, size_t len, 1190b0a2fdeeSScott Long int sleep_ok, int timeout_ms) 1191b0a2fdeeSScott Long { 1192b0a2fdeeSScott Long return (mpt_read_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT, 1193b0a2fdeeSScott Long PageAddress, hdr, len, sleep_ok, timeout_ms)); 1194b0a2fdeeSScott Long } 1195b0a2fdeeSScott Long 1196b0a2fdeeSScott Long static __inline int 1197b0a2fdeeSScott Long mpt_write_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress, 1198b0a2fdeeSScott Long CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok, 1199b0a2fdeeSScott Long int timeout_ms) 1200b0a2fdeeSScott Long { 1201b0a2fdeeSScott Long return (mpt_write_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT, 1202b0a2fdeeSScott Long PageAddress, hdr, len, sleep_ok, 1203b0a2fdeeSScott Long timeout_ms)); 1204b0a2fdeeSScott Long } 12059b631363SMatt Jacob /* mpt_debug.c functions */ 12069b631363SMatt Jacob void mpt_print_reply(void *vmsg); 1207b0a2fdeeSScott Long void mpt_print_db(uint32_t mb); 12089b631363SMatt Jacob void mpt_print_config_reply(void *vmsg); 1209b0a2fdeeSScott Long char *mpt_ioc_diag(uint32_t diag); 1210b0a2fdeeSScott Long void mpt_req_state(mpt_req_state_t state); 12119b631363SMatt Jacob void mpt_print_config_request(void *vmsg); 12129b631363SMatt Jacob void mpt_print_request(void *vmsg); 1213444dd2b6SMatt Jacob void mpt_dump_sgl(SGE_IO_UNION *se, int offset); 12149b631363SMatt Jacob #endif /* _MPT_H_ */ 1215