mpt.h revision 207287
1101704Smjacob/* $FreeBSD: head/sys/dev/mpt/mpt.h 207287 2010-04-27 18:41:16Z marius $ */ 2139749Simp/*- 3101704Smjacob * Generic defines for LSI '909 FC adapters. 4101704Smjacob * FreeBSD Version. 5101704Smjacob * 6101704Smjacob * Copyright (c) 2000, 2001 by Greg Ansley 7101704Smjacob * 8101704Smjacob * Redistribution and use in source and binary forms, with or without 9101704Smjacob * modification, are permitted provided that the following conditions 10101704Smjacob * are met: 11101704Smjacob * 1. Redistributions of source code must retain the above copyright 12101704Smjacob * notice immediately at the beginning of the file, without modification, 13101704Smjacob * this list of conditions, and the following disclaimer. 14101704Smjacob * 2. The name of the author may not be used to endorse or promote products 15101704Smjacob * derived from this software without specific prior written permission. 16101704Smjacob * 17101704Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18101704Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19101704Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20101704Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21101704Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22101704Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23101704Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24101704Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25101704Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26101704Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27101704Smjacob * SUCH DAMAGE. 28156000Smjacob */ 29156000Smjacob/*- 30156000Smjacob * Copyright (c) 2002, 2006 by Matthew Jacob 31156000Smjacob * All rights reserved. 32156000Smjacob * 33156000Smjacob * Redistribution and use in source and binary forms, with or without 34156000Smjacob * modification, are permitted provided that the following conditions are 35156000Smjacob * met: 36156000Smjacob * 1. Redistributions of source code must retain the above copyright 37156000Smjacob * notice, this list of conditions and the following disclaimer. 38156000Smjacob * 2. Redistributions in binary form must reproduce at minimum a disclaimer 39156000Smjacob * substantially similar to the "NO WARRANTY" disclaimer below 40156000Smjacob * ("Disclaimer") and any redistribution must be conditioned upon including 41156000Smjacob * a substantially similar Disclaimer requirement for further binary 42156000Smjacob * redistribution. 43156000Smjacob * 3. Neither the names of the above listed copyright holders nor the names 44156000Smjacob * of any contributors may be used to endorse or promote products derived 45156000Smjacob * from this software without specific prior written permission. 46156000Smjacob * 47156000Smjacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48156000Smjacob * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49156000Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50156000Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 51156000Smjacob * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 52156000Smjacob * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 53156000Smjacob * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 54156000Smjacob * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 55156000Smjacob * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 56156000Smjacob * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 57156000Smjacob * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58147883Sscottl * 59156000Smjacob * Support from Chris Ellsworth in order to make SAS adapters work 60156000Smjacob * is gratefully acknowledged. 61159052Smjacob * 62159052Smjacob * 63159052Smjacob * Support from LSI-Logic has also gone a great deal toward making this a 64159052Smjacob * workable subsystem and is gratefully acknowledged. 65101704Smjacob */ 66101704Smjacob/* 67147883Sscottl * Copyright (c) 2004, Avid Technology, Inc. and its contributors. 68147883Sscottl * Copyright (c) 2004, 2005 Justin T. Gibbs 69147883Sscottl * Copyright (c) 2005, WHEEL Sp. z o.o. 70147883Sscottl * All rights reserved. 71147883Sscottl * 72147883Sscottl * Redistribution and use in source and binary forms, with or without 73147883Sscottl * modification, are permitted provided that the following conditions are 74147883Sscottl * met: 75147883Sscottl * 1. Redistributions of source code must retain the above copyright 76147883Sscottl * notice, this list of conditions and the following disclaimer. 77147883Sscottl * 2. Redistributions in binary form must reproduce at minimum a disclaimer 78147883Sscottl * substantially similar to the "NO WARRANTY" disclaimer below 79147883Sscottl * ("Disclaimer") and any redistribution must be conditioned upon including 80147883Sscottl * a substantially similar Disclaimer requirement for further binary 81147883Sscottl * redistribution. 82148679Sgibbs * 3. Neither the names of the above listed copyright holders nor the names 83148679Sgibbs * of any contributors may be used to endorse or promote products derived 84148679Sgibbs * from this software without specific prior written permission. 85147883Sscottl * 86147883Sscottl * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 87147883Sscottl * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 88147883Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 89147883Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 90147883Sscottl * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 91147883Sscottl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 92147883Sscottl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 93147883Sscottl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 94147883Sscottl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 95147883Sscottl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 96147883Sscottl * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 97101704Smjacob */ 98101704Smjacob 99101704Smjacob#ifndef _MPT_H_ 100101704Smjacob#define _MPT_H_ 101147883Sscottl 102147883Sscottl/********************************* OS Includes ********************************/ 103147883Sscottl#include <sys/types.h> 104147883Sscottl#include <sys/param.h> 105147883Sscottl#include <sys/systm.h> 106147883Sscottl#include <sys/endian.h> 107147883Sscottl#include <sys/eventhandler.h> 108147883Sscottl#if __FreeBSD_version < 500000 109147883Sscottl#include <sys/kernel.h> 110147883Sscottl#include <sys/queue.h> 111147883Sscottl#include <sys/malloc.h> 112169293Smjacob#include <sys/devicestat.h> 113147883Sscottl#else 114147883Sscottl#include <sys/lock.h> 115147883Sscottl#include <sys/kernel.h> 116147883Sscottl#include <sys/queue.h> 117147883Sscottl#include <sys/malloc.h> 118147883Sscottl#include <sys/mutex.h> 119147883Sscottl#include <sys/condvar.h> 120147883Sscottl#endif 121147883Sscottl#include <sys/proc.h> 122147883Sscottl#include <sys/bus.h> 123147883Sscottl#include <sys/module.h> 124147883Sscottl 125147883Sscottl#include <machine/cpu.h> 126147883Sscottl#include <machine/resource.h> 127147883Sscottl 128157117Smjacob#if __FreeBSD_version < 500000 129157117Smjacob#include <machine/bus.h> 130159179Smjacob#include <machine/clock.h> 131157117Smjacob#endif 132157117Smjacob 133207287Smarius#ifdef __sparc64__ 134207287Smarius#include <dev/ofw/openfirm.h> 135207287Smarius#include <machine/ofw_machdep.h> 136207287Smarius#endif 137207287Smarius 138147883Sscottl#include <sys/rman.h> 139147883Sscottl 140155521Smjacob#if __FreeBSD_version < 500000 141155521Smjacob#include <pci/pcireg.h> 142155521Smjacob#include <pci/pcivar.h> 143155521Smjacob#else 144155521Smjacob#include <dev/pci/pcireg.h> 145155521Smjacob#include <dev/pci/pcivar.h> 146155521Smjacob#endif 147155521Smjacob 148155521Smjacob#include <machine/bus.h> 149147883Sscottl#include "opt_ddb.h" 150147883Sscottl 151147883Sscottl/**************************** Register Definitions ****************************/ 152147883Sscottl#include <dev/mpt/mpt_reg.h> 153147883Sscottl 154147883Sscottl/******************************* MPI Definitions ******************************/ 155147883Sscottl#include <dev/mpt/mpilib/mpi_type.h> 156147883Sscottl#include <dev/mpt/mpilib/mpi.h> 157147883Sscottl#include <dev/mpt/mpilib/mpi_cnfg.h> 158147883Sscottl#include <dev/mpt/mpilib/mpi_ioc.h> 159147883Sscottl#include <dev/mpt/mpilib/mpi_raid.h> 160147883Sscottl 161147883Sscottl/* XXX For mpt_debug.c */ 162147883Sscottl#include <dev/mpt/mpilib/mpi_init.h> 163147883Sscottl 164164990Smjacob#define MPT_S64_2_SCALAR(y) ((((int64_t)y.High) << 32) | (y.Low)) 165164990Smjacob#define MPT_U64_2_SCALAR(y) ((((uint64_t)y.High) << 32) | (y.Low)) 166164990Smjacob 167147883Sscottl/****************************** Misc Definitions ******************************/ 168165814Smjacob/* #define MPT_TEST_MULTIPATH 1 */ 169101704Smjacob#define MPT_OK (0) 170101704Smjacob#define MPT_FAIL (0x10000) 171101704Smjacob 172147883Sscottl#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array)) 173101704Smjacob 174157117Smjacob#define MPT_ROLE_NONE 0 175157117Smjacob#define MPT_ROLE_INITIATOR 1 176157117Smjacob#define MPT_ROLE_TARGET 2 177157117Smjacob#define MPT_ROLE_BOTH 3 178157117Smjacob#define MPT_ROLE_DEFAULT MPT_ROLE_INITIATOR 179157117Smjacob 180207287Smarius#define MPT_INI_ID_NONE -1 181207287Smarius 182147883Sscottl/**************************** Forward Declarations ****************************/ 183147883Sscottlstruct mpt_softc; 184147883Sscottlstruct mpt_personality; 185147883Sscottltypedef struct req_entry request_t; 186101704Smjacob 187147883Sscottl/************************* Personality Module Support *************************/ 188147883Sscottltypedef int mpt_load_handler_t(struct mpt_personality *); 189147883Sscottltypedef int mpt_probe_handler_t(struct mpt_softc *); 190147883Sscottltypedef int mpt_attach_handler_t(struct mpt_softc *); 191157117Smjacobtypedef int mpt_enable_handler_t(struct mpt_softc *); 192162133Smjacobtypedef void mpt_ready_handler_t(struct mpt_softc *); 193147883Sscottltypedef int mpt_event_handler_t(struct mpt_softc *, request_t *, 194147883Sscottl MSG_EVENT_NOTIFY_REPLY *); 195147883Sscottltypedef void mpt_reset_handler_t(struct mpt_softc *, int /*type*/); 196147883Sscottl/* XXX Add return value and use for veto? */ 197147883Sscottltypedef void mpt_shutdown_handler_t(struct mpt_softc *); 198147883Sscottltypedef void mpt_detach_handler_t(struct mpt_softc *); 199147883Sscottltypedef int mpt_unload_handler_t(struct mpt_personality *); 200147883Sscottl 201147883Sscottlstruct mpt_personality 202147883Sscottl{ 203147883Sscottl const char *name; 204147883Sscottl uint32_t id; /* Assigned identifier. */ 205147883Sscottl u_int use_count; /* Instances using personality*/ 206147883Sscottl mpt_load_handler_t *load; /* configure personailty */ 207147883Sscottl#define MPT_PERS_FIRST_HANDLER(pers) (&(pers)->load) 208147883Sscottl mpt_probe_handler_t *probe; /* configure personailty */ 209147883Sscottl mpt_attach_handler_t *attach; /* initialize device instance */ 210157117Smjacob mpt_enable_handler_t *enable; /* enable device */ 211162133Smjacob mpt_ready_handler_t *ready; /* final open for business */ 212147883Sscottl mpt_event_handler_t *event; /* Handle MPI event. */ 213147883Sscottl mpt_reset_handler_t *reset; /* Re-init after reset. */ 214147883Sscottl mpt_shutdown_handler_t *shutdown; /* Shutdown instance. */ 215147883Sscottl mpt_detach_handler_t *detach; /* release device instance */ 216147883Sscottl mpt_unload_handler_t *unload; /* Shutdown personality */ 217147883Sscottl#define MPT_PERS_LAST_HANDLER(pers) (&(pers)->unload) 218101704Smjacob}; 219101704Smjacob 220147883Sscottlint mpt_modevent(module_t, int, void *); 221101704Smjacob 222147883Sscottl/* Maximum supported number of personalities. */ 223147883Sscottl#define MPT_MAX_PERSONALITIES (15) 224101704Smjacob 225147883Sscottl#define MPT_PERSONALITY_DEPEND(name, dep, vmin, vpref, vmax) \ 226147883Sscottl MODULE_DEPEND(name, dep, vmin, vpref, vmax) 227101704Smjacob 228147883Sscottl#define DECLARE_MPT_PERSONALITY(name, order) \ 229147883Sscottl static moduledata_t name##_mod = { \ 230147883Sscottl #name, mpt_modevent, &name##_personality \ 231147883Sscottl }; \ 232147883Sscottl DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, order); \ 233147883Sscottl MODULE_VERSION(name, 1); \ 234147883Sscottl MPT_PERSONALITY_DEPEND(name, mpt_core, 1, 1, 1) 235147883Sscottl 236147883Sscottl/******************************* Bus DMA Support ******************************/ 237147883Sscottl/* XXX Need to update bus_dmamap_sync to take a range argument. */ 238147883Sscottl#define bus_dmamap_sync_range(dma_tag, dmamap, offset, len, op) \ 239147883Sscottl bus_dmamap_sync(dma_tag, dmamap, op) 240147883Sscottl 241167426Smjacob#if __FreeBSD_version < 600000 242167426Smjacob#define bus_get_dma_tag(x) NULL 243167426Smjacob#endif 244147883Sscottl#if __FreeBSD_version >= 501102 245147883Sscottl#define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary, \ 246147883Sscottl lowaddr, highaddr, filter, filterarg, \ 247147883Sscottl maxsize, nsegments, maxsegsz, flags, \ 248147883Sscottl dma_tagp) \ 249147883Sscottl bus_dma_tag_create(parent_tag, alignment, boundary, \ 250147883Sscottl lowaddr, highaddr, filter, filterarg, \ 251147883Sscottl maxsize, nsegments, maxsegsz, flags, \ 252169293Smjacob busdma_lock_mutex, &(mpt)->mpt_lock, \ 253147883Sscottl dma_tagp) 254147883Sscottl#else 255147883Sscottl#define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary, \ 256147883Sscottl lowaddr, highaddr, filter, filterarg, \ 257147883Sscottl maxsize, nsegments, maxsegsz, flags, \ 258147883Sscottl dma_tagp) \ 259147883Sscottl bus_dma_tag_create(parent_tag, alignment, boundary, \ 260147883Sscottl lowaddr, highaddr, filter, filterarg, \ 261147883Sscottl maxsize, nsegments, maxsegsz, flags, \ 262147883Sscottl dma_tagp) 263147883Sscottl#endif 264147883Sscottl 265147883Sscottlstruct mpt_map_info { 266147883Sscottl struct mpt_softc *mpt; 267147883Sscottl int error; 268147883Sscottl uint32_t phys; 269147883Sscottl}; 270147883Sscottl 271147883Sscottlvoid mpt_map_rquest(void *, bus_dma_segment_t *, int, int); 272166935Smjacob/* **************************** NewBUS interrupt Crock ************************/ 273166935Smjacob#if __FreeBSD_version < 700031 274166935Smjacob#define mpt_setup_intr(d, i, f, U, if, ifa, hp) \ 275166935Smjacob bus_setup_intr(d, i, f, if, ifa, hp) 276166935Smjacob#else 277166935Smjacob#define mpt_setup_intr bus_setup_intr 278166935Smjacob#endif 279147883Sscottl 280178725Sjkim/* **************************** NewBUS CAM Support ****************************/ 281178725Sjkim#if __FreeBSD_version < 700049 282178725Sjkim#define mpt_xpt_bus_register(sim, parent, bus) \ 283178725Sjkim xpt_bus_register(sim, bus) 284178725Sjkim#else 285178725Sjkim#define mpt_xpt_bus_register xpt_bus_register 286178725Sjkim#endif 287178725Sjkim 288147883Sscottl/**************************** Kernel Thread Support ***************************/ 289172842Sjulian#if __FreeBSD_version > 800001 290147883Sscottl#define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 291172836Sjulian kproc_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) 292178725Sjkim#define mpt_kthread_exit(status) \ 293178725Sjkim kproc_exit(status) 294178725Sjkim#elif __FreeBSD_version > 500005 295147883Sscottl#define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 296172842Sjulian kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) 297178725Sjkim#define mpt_kthread_exit(status) \ 298178725Sjkim kthread_exit(status) 299172842Sjulian#else 300172842Sjulian#define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 301172842Sjulian kthread_create(func, farg, proc_ptr, fmtstr, arg) 302178725Sjkim#define mpt_kthread_exit(status) \ 303178725Sjkim kthread_exit(status) 304172842Sjulian#endif 305147883Sscottl 306147883Sscottl/********************************** Endianess *********************************/ 307164990Smjacob#define MPT_2_HOST64(ptr, tag) ptr->tag = le64toh(ptr->tag) 308164990Smjacob#define MPT_2_HOST32(ptr, tag) ptr->tag = le32toh(ptr->tag) 309164990Smjacob#define MPT_2_HOST16(ptr, tag) ptr->tag = le16toh(ptr->tag) 310147883Sscottl 311164990Smjacob#define HOST_2_MPT64(ptr, tag) ptr->tag = htole64(ptr->tag) 312164990Smjacob#define HOST_2_MPT32(ptr, tag) ptr->tag = htole32(ptr->tag) 313164990Smjacob#define HOST_2_MPT16(ptr, tag) ptr->tag = htole16(ptr->tag) 314147883Sscottl 315164998Smjacob#if _BYTE_ORDER == _BIG_ENDIAN 316164998Smjacobvoid mpt2host_sge_simple_union(SGE_SIMPLE_UNION *); 317164998Smjacobvoid mpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *); 318164998Smjacobvoid mpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *); 319164998Smjacobvoid mpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *); 320186878Smariusvoid mpt2host_config_page_ioc3(CONFIG_PAGE_IOC_3 *); 321186878Smariusvoid mpt2host_config_page_scsi_port_0(CONFIG_PAGE_SCSI_PORT_0 *); 322186878Smariusvoid mpt2host_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *); 323186878Smariusvoid host2mpt_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *); 324186878Smariusvoid mpt2host_config_page_scsi_port_2(CONFIG_PAGE_SCSI_PORT_2 *); 325186878Smariusvoid mpt2host_config_page_scsi_device_0(CONFIG_PAGE_SCSI_DEVICE_0 *); 326186878Smariusvoid mpt2host_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *); 327186878Smariusvoid host2mpt_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *); 328186878Smariusvoid mpt2host_config_page_fc_port_0(CONFIG_PAGE_FC_PORT_0 *); 329186878Smariusvoid mpt2host_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *); 330186878Smariusvoid host2mpt_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *); 331164998Smjacobvoid mpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *); 332186878Smariusvoid mpt2host_config_page_raid_phys_disk_0(CONFIG_PAGE_RAID_PHYS_DISK_0 *); 333164998Smjacobvoid mpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *); 334164998Smjacob#else 335164990Smjacob#define mpt2host_sge_simple_union(x) do { ; } while (0) 336164990Smjacob#define mpt2host_iocfacts_reply(x) do { ; } while (0) 337164990Smjacob#define mpt2host_portfacts_reply(x) do { ; } while (0) 338164990Smjacob#define mpt2host_config_page_ioc2(x) do { ; } while (0) 339186878Smarius#define mpt2host_config_page_ioc3(x) do { ; } while (0) 340186878Smarius#define mpt2host_config_page_scsi_port_0(x) do { ; } while (0) 341186878Smarius#define mpt2host_config_page_scsi_port_1(x) do { ; } while (0) 342186878Smarius#define host2mpt_config_page_scsi_port_1(x) do { ; } while (0) 343186878Smarius#define mpt2host_config_page_scsi_port_2(x) do { ; } while (0) 344186878Smarius#define mpt2host_config_page_scsi_device_0(x) do { ; } while (0) 345186878Smarius#define mpt2host_config_page_scsi_device_1(x) do { ; } while (0) 346186878Smarius#define host2mpt_config_page_scsi_device_1(x) do { ; } while (0) 347186878Smarius#define mpt2host_config_page_fc_port_0(x) do { ; } while (0) 348186878Smarius#define mpt2host_config_page_fc_port_1(x) do { ; } while (0) 349186878Smarius#define host2mpt_config_page_fc_port_1(x) do { ; } while (0) 350164990Smjacob#define mpt2host_config_page_raid_vol_0(x) do { ; } while (0) 351186878Smarius#define mpt2host_config_page_raid_phys_disk_0(x) \ 352186878Smarius do { ; } while (0) 353164990Smjacob#define mpt2host_mpi_raid_vol_indicator(x) do { ; } while (0) 354164990Smjacob#endif 355164990Smjacob 356147883Sscottl/**************************** MPI Transaction State ***************************/ 357147883Sscottltypedef enum { 358157354Smjacob REQ_STATE_NIL = 0x00, 359157354Smjacob REQ_STATE_FREE = 0x01, 360157354Smjacob REQ_STATE_ALLOCATED = 0x02, 361157354Smjacob REQ_STATE_QUEUED = 0x04, 362157354Smjacob REQ_STATE_DONE = 0x08, 363157354Smjacob REQ_STATE_TIMEDOUT = 0x10, 364157354Smjacob REQ_STATE_NEED_WAKEUP = 0x20, 365157354Smjacob REQ_STATE_LOCKED = 0x80, /* can't be freed */ 366147883Sscottl REQ_STATE_MASK = 0xFF 367147883Sscottl} mpt_req_state_t; 368147883Sscottl 369147883Sscottlstruct req_entry { 370147883Sscottl TAILQ_ENTRY(req_entry) links; /* Pointer to next in list */ 371147883Sscottl mpt_req_state_t state; /* Request State Information */ 372147883Sscottl uint16_t index; /* Index of this entry */ 373147883Sscottl uint16_t IOCStatus; /* Completion status */ 374157662Smjacob uint16_t ResponseCode; /* TMF Reponse Code */ 375157662Smjacob uint16_t serno; /* serial number */ 376147883Sscottl union ccb *ccb; /* CAM request */ 377147883Sscottl void *req_vbuf; /* Virtual Address of Entry */ 378147883Sscottl void *sense_vbuf; /* Virtual Address of sense data */ 379147883Sscottl bus_addr_t req_pbuf; /* Physical Address of Entry */ 380147883Sscottl bus_addr_t sense_pbuf; /* Physical Address of sense data */ 381159312Smjacob bus_dmamap_t dmap; /* DMA map for data buffers */ 382155521Smjacob struct req_entry *chain; /* for SGE overallocations */ 383169293Smjacob struct callout callout; /* Timeout for the request */ 384147883Sscottl}; 385147883Sscottl 386170252Sscottltypedef struct mpt_config_params { 387170252Sscottl u_int Action; 388170252Sscottl u_int PageVersion; 389170252Sscottl u_int PageLength; 390170252Sscottl u_int PageNumber; 391170252Sscottl u_int PageType; 392170252Sscottl u_int PageAddress; 393170252Sscottl u_int ExtPageLength; 394170252Sscottl u_int ExtPageType; 395170252Sscottl} cfgparms_t; 396170252Sscottl 397157117Smjacob/**************************** MPI Target State Info ***************************/ 398157117Smjacob 399157117Smjacobtypedef struct { 400157117Smjacob uint32_t reply_desc; /* current reply descriptor */ 401157117Smjacob uint32_t resid; /* current data residual */ 402157117Smjacob uint32_t bytes_xfered; /* current relative offset */ 403157117Smjacob union ccb *ccb; /* pointer to currently active ccb */ 404157117Smjacob request_t *req; /* pointer to currently active assist request */ 405160391Smjacob uint32_t 406160391Smjacob is_local : 1, 407160391Smjacob nxfers : 31; 408157354Smjacob uint32_t tag_id; 409157117Smjacob enum { 410157117Smjacob TGT_STATE_NIL, 411157354Smjacob TGT_STATE_LOADING, 412157117Smjacob TGT_STATE_LOADED, 413157117Smjacob TGT_STATE_IN_CAM, 414157117Smjacob TGT_STATE_SETTING_UP_FOR_DATA, 415157117Smjacob TGT_STATE_MOVING_DATA, 416157117Smjacob TGT_STATE_MOVING_DATA_AND_STATUS, 417157117Smjacob TGT_STATE_SENDING_STATUS 418157117Smjacob } state; 419157117Smjacob} mpt_tgt_state_t; 420157117Smjacob 421157117Smjacob/* 422157117Smjacob * When we get an incoming command it has its own tag which is called the 423157117Smjacob * IoIndex. This is the value we gave that particular command buffer when 424157117Smjacob * we originally assigned it. It's just a number, really. The FC card uses 425157117Smjacob * it as an RX_ID. We can use it to index into mpt->tgt_cmd_ptrs, which 426157117Smjacob * contains pointers the request_t structures related to that IoIndex. 427157117Smjacob * 428157117Smjacob * What *we* do is construct a tag out of the index for the target command 429157117Smjacob * which owns the incoming ATIO plus a rolling sequence number. 430157117Smjacob */ 431157117Smjacob#define MPT_MAKE_TAGID(mpt, req, ioindex) \ 432157354Smjacob ((ioindex << 18) | (((mpt->sequence++) & 0x3f) << 12) | (req->index & 0xfff)) 433157117Smjacob 434157117Smjacob#ifdef INVARIANTS 435157117Smjacob#define MPT_TAG_2_REQ(a, b) mpt_tag_2_req(a, (uint32_t) b) 436157117Smjacob#else 437157354Smjacob#define MPT_TAG_2_REQ(mpt, tag) mpt->tgt_cmd_ptrs[tag >> 18] 438157117Smjacob#endif 439157117Smjacob 440157117Smjacob#define MPT_TGT_STATE(mpt, req) ((mpt_tgt_state_t *) \ 441157117Smjacob (&((uint8_t *)req->req_vbuf)[MPT_RQSL(mpt) - sizeof (mpt_tgt_state_t)])) 442157117Smjacob 443157117SmjacobSTAILQ_HEAD(mpt_hdr_stailq, ccb_hdr); 444157117Smjacob#define MPT_MAX_LUNS 256 445157117Smjacobtypedef struct { 446157117Smjacob struct mpt_hdr_stailq atios; 447157117Smjacob struct mpt_hdr_stailq inots; 448157117Smjacob int enabled; 449157117Smjacob} tgt_resource_t; 450157662Smjacob#define MPT_MAX_ELS 64 451157117Smjacob 452147883Sscottl/**************************** Handler Registration ****************************/ 453101704Smjacob/* 454147883Sscottl * Global table of registered reply handlers. The 455147883Sscottl * handler is indicated by byte 3 of the request 456147883Sscottl * index submitted to the IOC. This allows the 457147883Sscottl * driver core to perform generic processing without 458147883Sscottl * any knowledge of per-personality behavior. 459147883Sscottl * 460147883Sscottl * MPT_NUM_REPLY_HANDLERS must be a power of 2 461147883Sscottl * to allow the easy generation of a mask. 462147883Sscottl * 463147883Sscottl * The handler offsets used by the core are hard coded 464147883Sscottl * allowing faster code generation when assigning a handler 465147883Sscottl * to a request. All "personalities" must use the 466147883Sscottl * the handler registration mechanism. 467147883Sscottl * 468147883Sscottl * The IOC handlers that are rarely executed are placed 469147883Sscottl * at the tail of the table to make it more likely that 470147883Sscottl * all commonly executed handlers fit in a single cache 471147883Sscottl * line. 472101704Smjacob */ 473157117Smjacob#define MPT_NUM_REPLY_HANDLERS (32) 474147883Sscottl#define MPT_REPLY_HANDLER_EVENTS MPT_CBI_TO_HID(0) 475147883Sscottl#define MPT_REPLY_HANDLER_CONFIG MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-1) 476147883Sscottl#define MPT_REPLY_HANDLER_HANDSHAKE MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-2) 477147883Sscottltypedef int mpt_reply_handler_t(struct mpt_softc *mpt, request_t *request, 478157117Smjacob uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame); 479147883Sscottltypedef union { 480147883Sscottl mpt_reply_handler_t *reply_handler; 481147883Sscottl} mpt_handler_t; 482101704Smjacob 483147883Sscottltypedef enum { 484147883Sscottl MPT_HANDLER_REPLY, 485147883Sscottl MPT_HANDLER_EVENT, 486147883Sscottl MPT_HANDLER_RESET, 487147883Sscottl MPT_HANDLER_SHUTDOWN 488147883Sscottl} mpt_handler_type; 489101704Smjacob 490147883Sscottlstruct mpt_handler_record 491147883Sscottl{ 492147883Sscottl LIST_ENTRY(mpt_handler_record) links; 493147883Sscottl mpt_handler_t handler; 494101704Smjacob}; 495101704Smjacob 496147883SscottlLIST_HEAD(mpt_handler_list, mpt_handler_record); 497147883Sscottl 498147883Sscottl/* 499147883Sscottl * The handler_id is currently unused but would contain the 500147883Sscottl * handler ID used in the MsgContext field to allow direction 501147883Sscottl * of replies to the handler. Registrations that don't require 502147883Sscottl * a handler id can pass in NULL for the handler_id. 503147883Sscottl * 504147883Sscottl * Deregistrations for handlers without a handler id should 505147883Sscottl * pass in MPT_HANDLER_ID_NONE. 506147883Sscottl */ 507147883Sscottl#define MPT_HANDLER_ID_NONE (0xFFFFFFFF) 508147883Sscottlint mpt_register_handler(struct mpt_softc *, mpt_handler_type, 509147883Sscottl mpt_handler_t, uint32_t *); 510147883Sscottlint mpt_deregister_handler(struct mpt_softc *, mpt_handler_type, 511147883Sscottl mpt_handler_t, uint32_t); 512147883Sscottl 513147883Sscottl/******************* Per-Controller Instance Data Structures ******************/ 514147883SscottlTAILQ_HEAD(req_queue, req_entry); 515147883Sscottl 516147883Sscottl/* Structure for saving proper values for modifyable PCI config registers */ 517147883Sscottlstruct mpt_pci_cfg { 518147883Sscottl uint16_t Command; 519147883Sscottl uint16_t LatencyTimer_LineSize; 520147883Sscottl uint32_t IO_BAR; 521147883Sscottl uint32_t Mem0_BAR[2]; 522147883Sscottl uint32_t Mem1_BAR[2]; 523147883Sscottl uint32_t ROM_BAR; 524147883Sscottl uint8_t IntLine; 525147883Sscottl uint32_t PMCSR; 526101704Smjacob}; 527101704Smjacob 528147883Sscottltypedef enum { 529147883Sscottl MPT_RVF_NONE = 0x0, 530147883Sscottl MPT_RVF_ACTIVE = 0x1, 531147883Sscottl MPT_RVF_ANNOUNCED = 0x2, 532147883Sscottl MPT_RVF_UP2DATE = 0x4, 533147883Sscottl MPT_RVF_REFERENCED = 0x8, 534147883Sscottl MPT_RVF_WCE_CHANGED = 0x10 535147883Sscottl} mpt_raid_volume_flags; 536101704Smjacob 537147883Sscottlstruct mpt_raid_volume { 538147883Sscottl CONFIG_PAGE_RAID_VOL_0 *config_page; 539147883Sscottl MPI_RAID_VOL_INDICATOR sync_progress; 540147883Sscottl mpt_raid_volume_flags flags; 541158933Smjacob u_int quiesced_disks; 542101704Smjacob}; 543101704Smjacob 544147883Sscottltypedef enum { 545147883Sscottl MPT_RDF_NONE = 0x00, 546147883Sscottl MPT_RDF_ACTIVE = 0x01, 547147883Sscottl MPT_RDF_ANNOUNCED = 0x02, 548147883Sscottl MPT_RDF_UP2DATE = 0x04, 549147883Sscottl MPT_RDF_REFERENCED = 0x08, 550147883Sscottl MPT_RDF_QUIESCING = 0x10, 551147883Sscottl MPT_RDF_QUIESCED = 0x20 552147883Sscottl} mpt_raid_disk_flags; 553147883Sscottl 554147883Sscottlstruct mpt_raid_disk { 555147883Sscottl CONFIG_PAGE_RAID_PHYS_DISK_0 config_page; 556147883Sscottl struct mpt_raid_volume *volume; 557147883Sscottl u_int member_number; 558147883Sscottl u_int pass_thru_active; 559147883Sscottl mpt_raid_disk_flags flags; 560101704Smjacob}; 561101704Smjacob 562147883Sscottlstruct mpt_evtf_record { 563147883Sscottl MSG_EVENT_NOTIFY_REPLY reply; 564147883Sscottl uint32_t context; 565147883Sscottl LIST_ENTRY(mpt_evtf_record) links; 566147883Sscottl}; 567101704Smjacob 568147883SscottlLIST_HEAD(mpt_evtf_list, mpt_evtf_record); 569101704Smjacob 570170252Sscottlstruct mptsas_devinfo { 571170252Sscottl uint16_t dev_handle; 572170252Sscottl uint16_t parent_dev_handle; 573170252Sscottl uint16_t enclosure_handle; 574170252Sscottl uint16_t slot; 575170252Sscottl uint8_t phy_num; 576170252Sscottl uint8_t physical_port; 577170252Sscottl uint8_t target_id; 578170252Sscottl uint8_t bus; 579170252Sscottl uint64_t sas_address; 580170252Sscottl uint32_t device_info; 581170252Sscottl}; 582170252Sscottl 583170252Sscottlstruct mptsas_phyinfo { 584170252Sscottl uint16_t handle; 585170252Sscottl uint8_t phy_num; 586170252Sscottl uint8_t port_id; 587170252Sscottl uint8_t negotiated_link_rate; 588170252Sscottl uint8_t hw_link_rate; 589170252Sscottl uint8_t programmed_link_rate; 590170252Sscottl uint8_t sas_port_add_phy; 591170252Sscottl struct mptsas_devinfo identify; 592170252Sscottl struct mptsas_devinfo attached; 593170252Sscottl}; 594170252Sscottl 595170252Sscottlstruct mptsas_portinfo { 596170252Sscottl uint16_t num_phys; 597170252Sscottl struct mptsas_phyinfo *phy_info; 598170252Sscottl}; 599170252Sscottl 600147883Sscottlstruct mpt_softc { 601147883Sscottl device_t dev; 602147883Sscottl#if __FreeBSD_version < 500000 603157662Smjacob uint32_t mpt_islocked; 604147883Sscottl int mpt_splsaved; 605147883Sscottl#else 606147883Sscottl struct mtx mpt_lock; 607157662Smjacob int mpt_locksetup; 608147883Sscottl#endif 609147883Sscottl uint32_t mpt_pers_mask; 610160290Smjacob uint32_t 611164990Smjacob : 8, 612157117Smjacob unit : 8, 613165814Smjacob ready : 1, 614164990Smjacob fw_uploaded : 1, 615164416Smjacob msi_enable : 1, 616157117Smjacob twildcard : 1, 617157117Smjacob tenabled : 1, 618160290Smjacob do_cfg_role : 1, 619158982Smjacob raid_enabled : 1, 620147883Sscottl raid_mwce_set : 1, 621147883Sscottl getreqwaiter : 1, 622147883Sscottl shutdwn_raid : 1, 623147883Sscottl shutdwn_recovery: 1, 624147883Sscottl outofbeer : 1, 625147883Sscottl disabled : 1, 626159178Smjacob is_spi : 1, 627157117Smjacob is_sas : 1, 628157117Smjacob is_fc : 1; 629101704Smjacob 630160290Smjacob u_int cfg_role; 631160290Smjacob u_int role; /* role: none, ini, target, both */ 632160290Smjacob 633147883Sscottl u_int verbose; 634165814Smjacob#ifdef MPT_TEST_MULTIPATH 635165814Smjacob int failure_id; 636165814Smjacob#endif 637101704Smjacob 638147883Sscottl /* 639147883Sscottl * IOC Facts 640147883Sscottl */ 641164990Smjacob MSG_IOC_FACTS_REPLY ioc_facts; 642101704Smjacob 643147883Sscottl /* 644147883Sscottl * Port Facts 645147883Sscottl */ 646164990Smjacob MSG_PORT_FACTS_REPLY * port_facts; 647164990Smjacob#define mpt_max_tgtcmds port_facts[0].MaxPostedCmdBuffers 648102822Smjacob 649147883Sscottl /* 650147883Sscottl * Device Configuration Information 651147883Sscottl */ 652147883Sscottl union { 653147883Sscottl struct mpt_spi_cfg { 654147883Sscottl CONFIG_PAGE_SCSI_PORT_0 _port_page0; 655147883Sscottl CONFIG_PAGE_SCSI_PORT_1 _port_page1; 656147883Sscottl CONFIG_PAGE_SCSI_PORT_2 _port_page2; 657147883Sscottl CONFIG_PAGE_SCSI_DEVICE_0 _dev_page0[16]; 658147883Sscottl CONFIG_PAGE_SCSI_DEVICE_1 _dev_page1[16]; 659207287Smarius int _ini_id; 660147883Sscottl uint16_t _tag_enable; 661147883Sscottl uint16_t _disc_enable; 662147883Sscottl } spi; 663147883Sscottl#define mpt_port_page0 cfg.spi._port_page0 664147883Sscottl#define mpt_port_page1 cfg.spi._port_page1 665147883Sscottl#define mpt_port_page2 cfg.spi._port_page2 666147883Sscottl#define mpt_dev_page0 cfg.spi._dev_page0 667147883Sscottl#define mpt_dev_page1 cfg.spi._dev_page1 668207287Smarius#define mpt_ini_id cfg.spi._ini_id 669147883Sscottl#define mpt_tag_enable cfg.spi._tag_enable 670147883Sscottl#define mpt_disc_enable cfg.spi._disc_enable 671147883Sscottl struct mpi_fc_cfg { 672157117Smjacob CONFIG_PAGE_FC_PORT_0 _port_page0; 673159919Smjacob uint32_t _port_speed; 674157117Smjacob#define mpt_fcport_page0 cfg.fc._port_page0 675159919Smjacob#define mpt_fcport_speed cfg.fc._port_speed 676147883Sscottl } fc; 677147883Sscottl } cfg; 678160397Smjacob#if __FreeBSD_version >= 500000 679160397Smjacob /* 680160397Smjacob * Device config information stored up for sysctl to access 681160397Smjacob */ 682160397Smjacob union { 683160397Smjacob struct { 684160397Smjacob unsigned int initiator_id; 685160397Smjacob } spi; 686160397Smjacob struct { 687160397Smjacob char wwnn[19]; 688160397Smjacob char wwpn[19]; 689160397Smjacob } fc; 690160397Smjacob } scinfo; 691160397Smjacob#endif 692147883Sscottl 693158982Smjacob /* Controller Info for RAID information */ 694147883Sscottl CONFIG_PAGE_IOC_2 * ioc_page2; 695147883Sscottl CONFIG_PAGE_IOC_3 * ioc_page3; 696147883Sscottl 697147883Sscottl /* Raid Data */ 698147883Sscottl struct mpt_raid_volume* raid_volumes; 699147883Sscottl struct mpt_raid_disk* raid_disks; 700147883Sscottl u_int raid_max_volumes; 701147883Sscottl u_int raid_max_disks; 702147883Sscottl u_int raid_page0_len; 703147883Sscottl u_int raid_wakeup; 704147883Sscottl u_int raid_rescan; 705147883Sscottl u_int raid_resync_rate; 706147883Sscottl u_int raid_mwce_setting; 707147883Sscottl u_int raid_queue_depth; 708152444Skan u_int raid_nonopt_volumes; 709147883Sscottl struct proc *raid_thread; 710147883Sscottl struct callout raid_timer; 711147883Sscottl 712147883Sscottl /* 713147883Sscottl * PCI Hardware info 714147883Sscottl */ 715164305Sjhb int pci_msi_count; 716147883Sscottl struct resource * pci_irq; /* Interrupt map for chip */ 717147883Sscottl void * ih; /* Interupt handle */ 718147883Sscottl struct mpt_pci_cfg pci_cfg; /* saved PCI conf registers */ 719147883Sscottl 720147883Sscottl /* 721147883Sscottl * DMA Mapping Stuff 722147883Sscottl */ 723147883Sscottl struct resource * pci_reg; /* Register map for chip */ 724147883Sscottl int pci_mem_rid; /* Resource ID */ 725147883Sscottl bus_space_tag_t pci_st; /* Bus tag for registers */ 726147883Sscottl bus_space_handle_t pci_sh; /* Bus handle for registers */ 727147883Sscottl /* PIO versions of above. */ 728147883Sscottl int pci_pio_rid; 729147883Sscottl struct resource * pci_pio_reg; 730147883Sscottl bus_space_tag_t pci_pio_st; 731147883Sscottl bus_space_handle_t pci_pio_sh; 732147883Sscottl 733147883Sscottl bus_dma_tag_t parent_dmat; /* DMA tag for parent PCI bus */ 734147883Sscottl bus_dma_tag_t reply_dmat; /* DMA tag for reply memory */ 735147883Sscottl bus_dmamap_t reply_dmap; /* DMA map for reply memory */ 736147883Sscottl uint8_t *reply; /* KVA of reply memory */ 737147883Sscottl bus_addr_t reply_phys; /* BusAddr of reply memory */ 738147883Sscottl 739147883Sscottl bus_dma_tag_t buffer_dmat; /* DMA tag for buffers */ 740147883Sscottl bus_dma_tag_t request_dmat; /* DMA tag for request memroy */ 741147883Sscottl bus_dmamap_t request_dmap; /* DMA map for request memroy */ 742147883Sscottl uint8_t *request; /* KVA of Request memory */ 743157117Smjacob bus_addr_t request_phys; /* BusAddr of request memory */ 744147883Sscottl 745155521Smjacob uint32_t max_seg_cnt; /* calculated after IOC facts */ 746155521Smjacob 747155521Smjacob /* 748155521Smjacob * Hardware management 749155521Smjacob */ 750147883Sscottl u_int reset_cnt; 751147883Sscottl 752147883Sscottl /* 753147883Sscottl * CAM && Software Management 754147883Sscottl */ 755147883Sscottl request_t *request_pool; 756147883Sscottl struct req_queue request_free_list; 757147883Sscottl struct req_queue request_pending_list; 758147883Sscottl struct req_queue request_timeout_list; 759147883Sscottl 760147883Sscottl 761147883Sscottl struct cam_sim *sim; 762147883Sscottl struct cam_path *path; 763147883Sscottl 764147883Sscottl struct cam_sim *phydisk_sim; 765147883Sscottl struct cam_path *phydisk_path; 766147883Sscottl 767147883Sscottl struct proc *recovery_thread; 768147883Sscottl request_t *tmf_req; 769147883Sscottl 770157117Smjacob /* 771157354Smjacob * Deferred frame acks due to resource shortage. 772157354Smjacob */ 773157354Smjacob struct mpt_evtf_list ack_frames; 774159312Smjacob 775157354Smjacob /* 776157117Smjacob * Target Mode Support 777157117Smjacob */ 778157117Smjacob uint32_t scsi_tgt_handler_id; 779157117Smjacob request_t ** tgt_cmd_ptrs; 780157662Smjacob request_t ** els_cmd_ptrs; /* FC only */ 781147883Sscottl 782157117Smjacob /* 783157117Smjacob * *snork*- this is chosen to be here *just in case* somebody 784157117Smjacob * forgets to point to it exactly and we index off of trt with 785157117Smjacob * CAM_LUN_WILDCARD. 786157117Smjacob */ 787160391Smjacob tgt_resource_t trt_wildcard; /* wildcard luns */ 788157117Smjacob tgt_resource_t trt[MPT_MAX_LUNS]; 789157117Smjacob uint16_t tgt_cmds_allocated; 790157662Smjacob uint16_t els_cmds_allocated; /* FC only */ 791157117Smjacob 792157117Smjacob uint16_t timeouts; /* timeout count */ 793157117Smjacob uint16_t success; /* successes afer timeout */ 794157662Smjacob uint16_t sequence; /* Sequence Number */ 795157662Smjacob uint16_t pad3; 796157117Smjacob 797157117Smjacob 798159312Smjacob /* Paired port in some dual adapters configurations */ 799147883Sscottl struct mpt_softc * mpt2; 800147883Sscottl 801147883Sscottl /* FW Image management */ 802147883Sscottl uint32_t fw_image_size; 803147883Sscottl uint8_t *fw_image; 804147883Sscottl bus_dma_tag_t fw_dmat; /* DMA tag for firmware image */ 805147883Sscottl bus_dmamap_t fw_dmap; /* DMA map for firmware image */ 806159178Smjacob bus_addr_t fw_phys; /* BusAddr of firmware image */ 807147883Sscottl 808170252Sscottl /* SAS Topology */ 809170252Sscottl struct mptsas_portinfo *sas_portinfo; 810170252Sscottl 811147883Sscottl /* Shutdown Event Handler. */ 812147883Sscottl eventhandler_tag eh; 813147883Sscottl 814178814Sjhb /* Userland management interface. */ 815178814Sjhb struct cdev *cdev; 816178814Sjhb 817147883Sscottl TAILQ_ENTRY(mpt_softc) links; 818147883Sscottl}; 819147883Sscottl 820157662Smjacobstatic __inline void mpt_assign_serno(struct mpt_softc *, request_t *); 821157662Smjacob 822157662Smjacobstatic __inline void 823157662Smjacobmpt_assign_serno(struct mpt_softc *mpt, request_t *req) 824157662Smjacob{ 825157662Smjacob if ((req->serno = mpt->sequence++) == 0) { 826157662Smjacob req->serno = mpt->sequence++; 827157662Smjacob } 828157662Smjacob} 829157662Smjacob 830157117Smjacob/***************************** Locking Primitives *****************************/ 831147883Sscottl#if __FreeBSD_version < 500000 832147883Sscottl#define MPT_IFLAGS INTR_TYPE_CAM 833147883Sscottl#define MPT_LOCK(mpt) mpt_lockspl(mpt) 834147883Sscottl#define MPT_UNLOCK(mpt) mpt_unlockspl(mpt) 835157662Smjacob#define MPT_OWNED(mpt) mpt->mpt_islocked 836169293Smjacob#define MPT_LOCK_ASSERT(mpt) 837147883Sscottl#define MPTLOCK_2_CAMLOCK MPT_UNLOCK 838147883Sscottl#define CAMLOCK_2_MPTLOCK MPT_LOCK 839147883Sscottl#define MPT_LOCK_SETUP(mpt) 840147883Sscottl#define MPT_LOCK_DESTROY(mpt) 841147883Sscottl 842147883Sscottlstatic __inline void mpt_lockspl(struct mpt_softc *mpt); 843147883Sscottlstatic __inline void mpt_unlockspl(struct mpt_softc *mpt); 844147883Sscottl 845147883Sscottlstatic __inline void 846147883Sscottlmpt_lockspl(struct mpt_softc *mpt) 847147883Sscottl{ 848147883Sscottl int s; 849147883Sscottl 850147883Sscottl s = splcam(); 851147883Sscottl if (mpt->mpt_islocked++ == 0) { 852147883Sscottl mpt->mpt_splsaved = s; 853147883Sscottl } else { 854147883Sscottl splx(s); 855147883Sscottl panic("Recursed lock with mask: 0x%x\n", s); 856147883Sscottl } 857147883Sscottl} 858147883Sscottl 859147883Sscottlstatic __inline void 860147883Sscottlmpt_unlockspl(struct mpt_softc *mpt) 861147883Sscottl{ 862147883Sscottl if (mpt->mpt_islocked) { 863147883Sscottl if (--mpt->mpt_islocked == 0) { 864147883Sscottl splx(mpt->mpt_splsaved); 865147883Sscottl } 866147883Sscottl } else 867147883Sscottl panic("Negative lock count\n"); 868147883Sscottl} 869147883Sscottl 870147883Sscottlstatic __inline int 871147883Sscottlmpt_sleep(struct mpt_softc *mpt, void *ident, int priority, 872147883Sscottl const char *wmesg, int timo) 873147883Sscottl{ 874147883Sscottl int saved_cnt; 875147883Sscottl int saved_spl; 876147883Sscottl int error; 877147883Sscottl 878147883Sscottl KASSERT(mpt->mpt_islocked <= 1, ("Invalid lock count on tsleep")); 879147883Sscottl saved_cnt = mpt->mpt_islocked; 880147883Sscottl saved_spl = mpt->mpt_splsaved; 881147883Sscottl mpt->mpt_islocked = 0; 882147883Sscottl error = tsleep(ident, priority, wmesg, timo); 883157117Smjacob KASSERT(mpt->mpt_islocked == 0, ("Invalid lock count on wakeup")); 884147883Sscottl mpt->mpt_islocked = saved_cnt; 885147883Sscottl mpt->mpt_splsaved = saved_spl; 886147883Sscottl return (error); 887147883Sscottl} 888147883Sscottl 889169293Smjacob#define mpt_req_timeout(req, ticks, func, arg) \ 890169293Smjacob callout_reset(&(req)->callout, (ticks), (func), (arg)); 891169293Smjacob#define mpt_req_untimeout(req, func, arg) \ 892169293Smjacob callout_stop(&(req)->callout) 893198262Skan#define mpt_callout_init(mpt, c) \ 894198262Skan callout_init(c) 895198262Skan#define mpt_callout_drain(mpt, c) \ 896198262Skan callout_stop(c) 897169293Smjacob 898147883Sscottl#else 899169293Smjacob#if 1 900147883Sscottl#define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE 901147883Sscottl#define MPT_LOCK_SETUP(mpt) \ 902147883Sscottl mtx_init(&mpt->mpt_lock, "mpt", NULL, MTX_DEF); \ 903147883Sscottl mpt->mpt_locksetup = 1 904147883Sscottl#define MPT_LOCK_DESTROY(mpt) \ 905147883Sscottl if (mpt->mpt_locksetup) { \ 906147883Sscottl mtx_destroy(&mpt->mpt_lock); \ 907147883Sscottl mpt->mpt_locksetup = 0; \ 908147883Sscottl } 909147883Sscottl 910147883Sscottl#define MPT_LOCK(mpt) mtx_lock(&(mpt)->mpt_lock) 911147883Sscottl#define MPT_UNLOCK(mpt) mtx_unlock(&(mpt)->mpt_lock) 912157662Smjacob#define MPT_OWNED(mpt) mtx_owned(&(mpt)->mpt_lock) 913169293Smjacob#define MPT_LOCK_ASSERT(mpt) mtx_assert(&(mpt)->mpt_lock, MA_OWNED) 914169293Smjacob#define MPTLOCK_2_CAMLOCK(mpt) 915169293Smjacob#define CAMLOCK_2_MPTLOCK(mpt) 916147883Sscottl#define mpt_sleep(mpt, ident, priority, wmesg, timo) \ 917147883Sscottl msleep(ident, &(mpt)->mpt_lock, priority, wmesg, timo) 918169293Smjacob#define mpt_req_timeout(req, ticks, func, arg) \ 919198262Skan callout_reset(&(req)->callout, (ticks), (func), (arg)) 920169293Smjacob#define mpt_req_untimeout(req, func, arg) \ 921169293Smjacob callout_stop(&(req)->callout) 922198262Skan#define mpt_callout_init(mpt, c) \ 923198262Skan callout_init_mtx(c, &(mpt)->mpt_lock, 0) 924198262Skan#define mpt_callout_drain(mpt, c) \ 925198262Skan callout_drain(c) 926157662Smjacob 927147883Sscottl#else 928157662Smjacob 929147883Sscottl#define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY 930147883Sscottl#define MPT_LOCK_SETUP(mpt) do { } while (0) 931147883Sscottl#define MPT_LOCK_DESTROY(mpt) do { } while (0) 932169293Smjacob#define MPT_LOCK_ASSERT(mpt) mtx_assert(&Giant, MA_OWNED) 933169293Smjacob#define MPT_LOCK(mpt) mtx_lock(&Giant) 934169293Smjacob#define MPT_UNLOCK(mpt) mtx_unlock(&Giant) 935169293Smjacob#define MPTLOCK_2_CAMLOCK(mpt) 936169293Smjacob#define CAMLOCK_2_MPTLOCK(mpt) 937157662Smjacob 938198262Skan#define mpt_req_timeout(req, ticks, func, arg) \ 939198262Skan callout_reset(&(req)->callout, (ticks), (func), (arg)) 940198262Skan#define mpt_req_untimeout(req, func, arg) \ 941198262Skan callout_stop(&(req)->callout) 942198262Skan#define mpt_callout_init(mpt, c) \ 943198262Skan callout_init(c, 0) 944198262Skan#define mpt_callout_drain(mpt, c) \ 945198262Skan callout_drain(c) 946198262Skan 947157662Smjacobstatic __inline int 948157662Smjacobmpt_sleep(struct mpt_softc *, void *, int, const char *, int); 949157662Smjacob 950157662Smjacobstatic __inline int 951157662Smjacobmpt_sleep(struct mpt_softc *mpt, void *i, int p, const char *w, int t) 952157662Smjacob{ 953157662Smjacob int r; 954157662Smjacob r = tsleep(i, p, w, t); 955157662Smjacob return (r); 956157662Smjacob} 957147883Sscottl#endif 958157662Smjacob#endif 959147883Sscottl 960147883Sscottl/******************************* Register Access ******************************/ 961147883Sscottlstatic __inline void mpt_write(struct mpt_softc *, size_t, uint32_t); 962147883Sscottlstatic __inline uint32_t mpt_read(struct mpt_softc *, int); 963147883Sscottlstatic __inline void mpt_pio_write(struct mpt_softc *, size_t, uint32_t); 964147883Sscottlstatic __inline uint32_t mpt_pio_read(struct mpt_softc *, int); 965147883Sscottl 966147883Sscottlstatic __inline void 967147883Sscottlmpt_write(struct mpt_softc *mpt, size_t offset, uint32_t val) 968147883Sscottl{ 969147883Sscottl bus_space_write_4(mpt->pci_st, mpt->pci_sh, offset, val); 970147883Sscottl} 971147883Sscottl 972147883Sscottlstatic __inline uint32_t 973147883Sscottlmpt_read(struct mpt_softc *mpt, int offset) 974147883Sscottl{ 975147883Sscottl return (bus_space_read_4(mpt->pci_st, mpt->pci_sh, offset)); 976147883Sscottl} 977147883Sscottl 978147883Sscottl/* 979147883Sscottl * Some operations (e.g. diagnostic register writes while the ARM proccessor 980147883Sscottl * is disabled), must be performed using "PCI pio" operations. On non-PCI 981147883Sscottl * busses, these operations likely map to normal register accesses. 982147883Sscottl */ 983147883Sscottlstatic __inline void 984147883Sscottlmpt_pio_write(struct mpt_softc *mpt, size_t offset, uint32_t val) 985147883Sscottl{ 986147883Sscottl bus_space_write_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset, val); 987147883Sscottl} 988147883Sscottl 989147883Sscottlstatic __inline uint32_t 990147883Sscottlmpt_pio_read(struct mpt_softc *mpt, int offset) 991147883Sscottl{ 992147883Sscottl return (bus_space_read_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset)); 993147883Sscottl} 994147883Sscottl/*********************** Reply Frame/Request Management ***********************/ 995147883Sscottl/* Max MPT Reply we are willing to accept (must be power of 2) */ 996155521Smjacob#define MPT_REPLY_SIZE 256 997147883Sscottl 998195534Sscottl/* Max i/o size, based on legacy MAXPHYS. Can be increased. */ 999195534Sscottl#define MPT_MAXPHYS (128 * 1024) 1000195534Sscottl 1001157117Smjacob/* 1002157117Smjacob * Must be less than 16384 in order for target mode to work 1003157117Smjacob */ 1004155521Smjacob#define MPT_MAX_REQUESTS(mpt) 512 1005155521Smjacob#define MPT_REQUEST_AREA 512 1006155521Smjacob#define MPT_SENSE_SIZE 32 /* included in MPT_REQUEST_AREA */ 1007147883Sscottl#define MPT_REQ_MEM_SIZE(mpt) (MPT_MAX_REQUESTS(mpt) * MPT_REQUEST_AREA) 1008147883Sscottl 1009157354Smjacob#define MPT_CONTEXT_CB_SHIFT (16) 1010157117Smjacob#define MPT_CBI(handle) (handle >> MPT_CONTEXT_CB_SHIFT) 1011147883Sscottl#define MPT_CBI_TO_HID(cbi) ((cbi) << MPT_CONTEXT_CB_SHIFT) 1012147883Sscottl#define MPT_CONTEXT_TO_CBI(x) \ 1013147883Sscottl (((x) >> MPT_CONTEXT_CB_SHIFT) & (MPT_NUM_REPLY_HANDLERS - 1)) 1014157354Smjacob#define MPT_CONTEXT_REQI_MASK 0xFFFF 1015157117Smjacob#define MPT_CONTEXT_TO_REQI(x) ((x) & MPT_CONTEXT_REQI_MASK) 1016147883Sscottl 1017147883Sscottl/* 1018147883Sscottl * Convert a 32bit physical address returned from IOC to an 1019147883Sscottl * offset into our reply frame memory or the kvm address needed 1020147883Sscottl * to access the data. The returned address is only the low 1021147883Sscottl * 32 bits, so mask our base physical address accordingly. 1022147883Sscottl */ 1023147883Sscottl#define MPT_REPLY_BADDR(x) \ 1024147883Sscottl (x << 1) 1025147883Sscottl#define MPT_REPLY_OTOV(m, i) \ 1026147883Sscottl ((void *)(&m->reply[i])) 1027147883Sscottl 1028147883Sscottl#define MPT_DUMP_REPLY_FRAME(mpt, reply_frame) \ 1029147883Sscottldo { \ 1030158982Smjacob if (mpt->verbose > MPT_PRT_DEBUG) \ 1031147883Sscottl mpt_dump_reply_frame(mpt, reply_frame); \ 1032147883Sscottl} while(0) 1033147883Sscottl 1034147883Sscottlstatic __inline uint32_t mpt_pop_reply_queue(struct mpt_softc *mpt); 1035147883Sscottlstatic __inline void mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr); 1036147883Sscottl 1037147883Sscottl/* 1038147883Sscottl * Give the reply buffer back to the IOC after we have 1039147883Sscottl * finished processing it. 1040147883Sscottl */ 1041147883Sscottlstatic __inline void 1042147883Sscottlmpt_free_reply(struct mpt_softc *mpt, uint32_t ptr) 1043147883Sscottl{ 1044147883Sscottl mpt_write(mpt, MPT_OFFSET_REPLY_Q, ptr); 1045147883Sscottl} 1046147883Sscottl 1047147883Sscottl/* Get a reply from the IOC */ 1048147883Sscottlstatic __inline uint32_t 1049147883Sscottlmpt_pop_reply_queue(struct mpt_softc *mpt) 1050147883Sscottl{ 1051147883Sscottl return mpt_read(mpt, MPT_OFFSET_REPLY_Q); 1052147883Sscottl} 1053147883Sscottl 1054157354Smjacobvoid 1055157354Smjacobmpt_complete_request_chain(struct mpt_softc *, struct req_queue *, u_int); 1056157354Smjacob 1057147883Sscottl/************************** Scatter Gather Managment **************************/ 1058155521Smjacob/* MPT_RQSL- size of request frame, in bytes */ 1059164990Smjacob#define MPT_RQSL(mpt) (mpt->ioc_facts.RequestFrameSize << 2) 1060155521Smjacob 1061155521Smjacob/* MPT_NSGL- how many SG entries can fit in a request frame size */ 1062155521Smjacob#define MPT_NSGL(mpt) (MPT_RQSL(mpt) / sizeof (SGE_IO_UNION)) 1063155521Smjacob 1064155521Smjacob/* MPT_NRFM- how many request frames can fit in each request alloc we make */ 1065155521Smjacob#define MPT_NRFM(mpt) (MPT_REQUEST_AREA / MPT_RQSL(mpt)) 1066155521Smjacob 1067147883Sscottl/* 1068155521Smjacob * MPT_NSGL_FIRST- # of SG elements that can fit after 1069155521Smjacob * an I/O request but still within the request frame. 1070155521Smjacob * Do this safely based upon SGE_IO_UNION. 1071155521Smjacob * 1072155521Smjacob * Note that the first element is *within* the SCSI request. 1073147883Sscottl */ 1074155521Smjacob#define MPT_NSGL_FIRST(mpt) \ 1075155521Smjacob ((MPT_RQSL(mpt) - sizeof (MSG_SCSI_IO_REQUEST) + sizeof (SGE_IO_UNION)) / \ 1076155521Smjacob sizeof (SGE_IO_UNION)) 1077147883Sscottl 1078147883Sscottl/***************************** IOC Initialization *****************************/ 1079147883Sscottlint mpt_reset(struct mpt_softc *, int /*reinit*/); 1080147883Sscottl 1081157117Smjacob/****************************** Debugging ************************************/ 1082147883Sscottltypedef struct mpt_decode_entry { 1083147883Sscottl char *name; 1084147883Sscottl u_int value; 1085147883Sscottl u_int mask; 1086147883Sscottl} mpt_decode_entry_t; 1087147883Sscottl 1088147883Sscottlint mpt_decode_value(mpt_decode_entry_t *table, u_int num_entries, 1089147883Sscottl const char *name, u_int value, u_int *cur_column, 1090147883Sscottl u_int wrap_point); 1091147883Sscottl 1092160290Smjacobvoid mpt_dump_data(struct mpt_softc *, const char *, void *, int); 1093158933Smjacobvoid mpt_dump_request(struct mpt_softc *, request_t *); 1094158933Smjacob 1095147883Sscottlenum { 1096147883Sscottl MPT_PRT_ALWAYS, 1097147883Sscottl MPT_PRT_FATAL, 1098147883Sscottl MPT_PRT_ERROR, 1099147883Sscottl MPT_PRT_WARN, 1100147883Sscottl MPT_PRT_INFO, 1101159049Smjacob MPT_PRT_NEGOTIATION, 1102147883Sscottl MPT_PRT_DEBUG, 1103157117Smjacob MPT_PRT_DEBUG1, 1104157117Smjacob MPT_PRT_DEBUG2, 1105157117Smjacob MPT_PRT_DEBUG3, 1106155521Smjacob MPT_PRT_TRACE, 1107155521Smjacob MPT_PRT_NONE=100 1108147883Sscottl}; 1109147883Sscottl 1110157117Smjacob#if __FreeBSD_version > 500000 1111147883Sscottl#define mpt_lprt(mpt, level, ...) \ 1112147883Sscottldo { \ 1113147883Sscottl if (level <= (mpt)->verbose) \ 1114147883Sscottl mpt_prt(mpt, __VA_ARGS__); \ 1115147883Sscottl} while (0) 1116147883Sscottl 1117147883Sscottl#define mpt_lprtc(mpt, level, ...) \ 1118147883Sscottldo { \ 1119147883Sscottl if (level <= (mpt)->debug_level) \ 1120147883Sscottl mpt_prtc(mpt, __VA_ARGS__); \ 1121147883Sscottl} while (0) 1122157117Smjacob#else 1123157117Smjacobvoid mpt_lprt(struct mpt_softc *, int, const char *, ...) 1124157117Smjacob __printflike(3, 4); 1125157117Smjacobvoid mpt_lprtc(struct mpt_softc *, int, const char *, ...) 1126157117Smjacob __printflike(3, 4); 1127157117Smjacob#endif 1128157117Smjacobvoid mpt_prt(struct mpt_softc *, const char *, ...) 1129157117Smjacob __printflike(2, 3); 1130157117Smjacobvoid mpt_prtc(struct mpt_softc *, const char *, ...) 1131157117Smjacob __printflike(2, 3); 1132147883Sscottl 1133157117Smjacob/**************************** Target Mode Related ***************************/ 1134157117Smjacobstatic __inline int mpt_cdblen(uint8_t, int); 1135157117Smjacobstatic __inline int 1136157117Smjacobmpt_cdblen(uint8_t cdb0, int maxlen) 1137157117Smjacob{ 1138157117Smjacob int group = cdb0 >> 5; 1139157117Smjacob switch (group) { 1140157117Smjacob case 0: 1141157117Smjacob return (6); 1142157117Smjacob case 1: 1143157117Smjacob return (10); 1144157117Smjacob case 4: 1145157117Smjacob case 5: 1146157117Smjacob return (12); 1147157117Smjacob default: 1148157117Smjacob return (16); 1149157117Smjacob } 1150157117Smjacob} 1151157117Smjacob#ifdef INVARIANTS 1152157117Smjacobstatic __inline request_t * mpt_tag_2_req(struct mpt_softc *, uint32_t); 1153157117Smjacobstatic __inline request_t * 1154157117Smjacobmpt_tag_2_req(struct mpt_softc *mpt, uint32_t tag) 1155157117Smjacob{ 1156157354Smjacob uint16_t rtg = (tag >> 18); 1157157117Smjacob KASSERT(rtg < mpt->tgt_cmds_allocated, ("bad tag %d\n", tag)); 1158157117Smjacob KASSERT(mpt->tgt_cmd_ptrs, ("no cmd backpointer array")); 1159157117Smjacob KASSERT(mpt->tgt_cmd_ptrs[rtg], ("no cmd backpointer")); 1160157117Smjacob return (mpt->tgt_cmd_ptrs[rtg]); 1161157117Smjacob} 1162157662Smjacob 1163157662Smjacob 1164157662Smjacobstatic __inline int 1165157662Smjacobmpt_req_on_free_list(struct mpt_softc *, request_t *); 1166157662Smjacobstatic __inline int 1167157662Smjacobmpt_req_on_pending_list(struct mpt_softc *, request_t *); 1168157662Smjacob 1169157662Smjacobstatic __inline void 1170157662Smjacobmpt_req_spcl(struct mpt_softc *, request_t *, const char *, int); 1171157662Smjacobstatic __inline void 1172157662Smjacobmpt_req_not_spcl(struct mpt_softc *, request_t *, const char *, int); 1173157662Smjacob 1174157662Smjacob 1175157662Smjacob/* 1176157662Smjacob * Is request on freelist? 1177157662Smjacob */ 1178157662Smjacobstatic __inline int 1179157662Smjacobmpt_req_on_free_list(struct mpt_softc *mpt, request_t *req) 1180157662Smjacob{ 1181157662Smjacob request_t *lrq; 1182157662Smjacob 1183157662Smjacob TAILQ_FOREACH(lrq, &mpt->request_free_list, links) { 1184157662Smjacob if (lrq == req) { 1185157662Smjacob return (1); 1186157662Smjacob } 1187157662Smjacob } 1188157662Smjacob return (0); 1189157662Smjacob} 1190157662Smjacob 1191157662Smjacob/* 1192157662Smjacob * Is request on pending list? 1193157662Smjacob */ 1194157662Smjacobstatic __inline int 1195157662Smjacobmpt_req_on_pending_list(struct mpt_softc *mpt, request_t *req) 1196157662Smjacob{ 1197157662Smjacob request_t *lrq; 1198157662Smjacob 1199157662Smjacob TAILQ_FOREACH(lrq, &mpt->request_pending_list, links) { 1200157662Smjacob if (lrq == req) { 1201157662Smjacob return (1); 1202157662Smjacob } 1203157662Smjacob } 1204157662Smjacob return (0); 1205157662Smjacob} 1206157662Smjacob 1207157662Smjacob/* 1208157662Smjacob * Make sure that req *is* part of one of the special lists 1209157662Smjacob */ 1210157662Smjacobstatic __inline void 1211157662Smjacobmpt_req_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line) 1212157662Smjacob{ 1213157662Smjacob int i; 1214157662Smjacob for (i = 0; i < mpt->els_cmds_allocated; i++) { 1215157662Smjacob if (req == mpt->els_cmd_ptrs[i]) { 1216157662Smjacob return; 1217157662Smjacob } 1218157662Smjacob } 1219157662Smjacob for (i = 0; i < mpt->tgt_cmds_allocated; i++) { 1220157662Smjacob if (req == mpt->tgt_cmd_ptrs[i]) { 1221157662Smjacob return; 1222157662Smjacob } 1223157662Smjacob } 1224157662Smjacob panic("%s(%d): req %p:%u function %x not in els or tgt ptrs\n", 1225157662Smjacob s, line, req, req->serno, 1226157662Smjacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function); 1227157662Smjacob} 1228157662Smjacob 1229157662Smjacob/* 1230157662Smjacob * Make sure that req is *not* part of one of the special lists. 1231157662Smjacob */ 1232157662Smjacobstatic __inline void 1233157662Smjacobmpt_req_not_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line) 1234157662Smjacob{ 1235157662Smjacob int i; 1236157662Smjacob for (i = 0; i < mpt->els_cmds_allocated; i++) { 1237157662Smjacob KASSERT(req != mpt->els_cmd_ptrs[i], 1238157662Smjacob ("%s(%d): req %p:%u func %x in els ptrs at ioindex %d\n", 1239157662Smjacob s, line, req, req->serno, 1240157662Smjacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i)); 1241157662Smjacob } 1242157662Smjacob for (i = 0; i < mpt->tgt_cmds_allocated; i++) { 1243157662Smjacob KASSERT(req != mpt->tgt_cmd_ptrs[i], 1244157662Smjacob ("%s(%d): req %p:%u func %x in tgt ptrs at ioindex %d\n", 1245157662Smjacob s, line, req, req->serno, 1246157662Smjacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i)); 1247157662Smjacob } 1248157662Smjacob} 1249157117Smjacob#endif 1250147883Sscottl 1251160391Smjacob/* 1252160391Smjacob * Task Management Types, purely for internal consumption 1253160391Smjacob */ 1254157117Smjacobtypedef enum { 1255157117Smjacob MPT_ABORT_TASK_SET=1234, 1256157117Smjacob MPT_CLEAR_TASK_SET, 1257157117Smjacob MPT_TARGET_RESET, 1258157117Smjacob MPT_CLEAR_ACA, 1259157117Smjacob MPT_TERMINATE_TASK, 1260157117Smjacob MPT_NIL_TMT_VALUE=5678 1261157117Smjacob} mpt_task_mgmt_t; 1262157117Smjacob 1263147883Sscottl/**************************** Unclassified Routines ***************************/ 1264147883Sscottlvoid mpt_send_cmd(struct mpt_softc *mpt, request_t *req); 1265147883Sscottlint mpt_recv_handshake_reply(struct mpt_softc *mpt, 1266147883Sscottl size_t reply_len, void *reply); 1267147883Sscottlint mpt_wait_req(struct mpt_softc *mpt, request_t *req, 1268147883Sscottl mpt_req_state_t state, mpt_req_state_t mask, 1269147883Sscottl int sleep_ok, int time_ms); 1270147883Sscottlvoid mpt_enable_ints(struct mpt_softc *mpt); 1271147883Sscottlvoid mpt_disable_ints(struct mpt_softc *mpt); 1272147883Sscottlint mpt_attach(struct mpt_softc *mpt); 1273147883Sscottlint mpt_shutdown(struct mpt_softc *mpt); 1274147883Sscottlint mpt_detach(struct mpt_softc *mpt); 1275147883Sscottlint mpt_send_handshake_cmd(struct mpt_softc *mpt, 1276147883Sscottl size_t len, void *cmd); 1277147883Sscottlrequest_t * mpt_get_request(struct mpt_softc *mpt, int sleep_ok); 1278147883Sscottlvoid mpt_free_request(struct mpt_softc *mpt, request_t *req); 1279147883Sscottlvoid mpt_intr(void *arg); 1280147883Sscottlvoid mpt_check_doorbell(struct mpt_softc *mpt); 1281147883Sscottlvoid mpt_dump_reply_frame(struct mpt_softc *mpt, 1282147883Sscottl MSG_DEFAULT_REPLY *reply_frame); 1283147883Sscottl 1284147883Sscottlvoid mpt_set_config_regs(struct mpt_softc *); 1285147883Sscottlint mpt_issue_cfg_req(struct mpt_softc */*mpt*/, request_t */*req*/, 1286170252Sscottl cfgparms_t *params, 1287147883Sscottl bus_addr_t /*addr*/, bus_size_t/*len*/, 1288147883Sscottl int /*sleep_ok*/, int /*timeout_ms*/); 1289170252Sscottlint mpt_read_extcfg_header(struct mpt_softc *mpt, int PageVersion, 1290170252Sscottl int PageNumber, uint32_t PageAddress, 1291170252Sscottl int ExtPageType, 1292170252Sscottl CONFIG_EXTENDED_PAGE_HEADER *rslt, 1293170252Sscottl int sleep_ok, int timeout_ms); 1294170252Sscottlint mpt_read_extcfg_page(struct mpt_softc *mpt, int Action, 1295170252Sscottl uint32_t PageAddress, 1296170252Sscottl CONFIG_EXTENDED_PAGE_HEADER *hdr, 1297170252Sscottl void *buf, size_t len, int sleep_ok, 1298170252Sscottl int timeout_ms); 1299147883Sscottlint mpt_read_cfg_header(struct mpt_softc *, int /*PageType*/, 1300147883Sscottl int /*PageNumber*/, 1301147883Sscottl uint32_t /*PageAddress*/, 1302147883Sscottl CONFIG_PAGE_HEADER *, 1303147883Sscottl int /*sleep_ok*/, int /*timeout_ms*/); 1304147883Sscottlint mpt_read_cfg_page(struct mpt_softc *t, int /*Action*/, 1305147883Sscottl uint32_t /*PageAddress*/, 1306147883Sscottl CONFIG_PAGE_HEADER *, size_t /*len*/, 1307147883Sscottl int /*sleep_ok*/, int /*timeout_ms*/); 1308147883Sscottlint mpt_write_cfg_page(struct mpt_softc *, int /*Action*/, 1309147883Sscottl uint32_t /*PageAddress*/, 1310147883Sscottl CONFIG_PAGE_HEADER *, size_t /*len*/, 1311147883Sscottl int /*sleep_ok*/, int /*timeout_ms*/); 1312147883Sscottlstatic __inline int 1313147883Sscottlmpt_read_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress, 1314147883Sscottl CONFIG_PAGE_HEADER *hdr, size_t len, 1315147883Sscottl int sleep_ok, int timeout_ms) 1316147883Sscottl{ 1317147883Sscottl return (mpt_read_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT, 1318147883Sscottl PageAddress, hdr, len, sleep_ok, timeout_ms)); 1319147883Sscottl} 1320147883Sscottl 1321147883Sscottlstatic __inline int 1322147883Sscottlmpt_write_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress, 1323147883Sscottl CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok, 1324147883Sscottl int timeout_ms) 1325147883Sscottl{ 1326147883Sscottl return (mpt_write_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT, 1327147883Sscottl PageAddress, hdr, len, sleep_ok, 1328147883Sscottl timeout_ms)); 1329147883Sscottl} 1330101704Smjacob/* mpt_debug.c functions */ 1331101704Smjacobvoid mpt_print_reply(void *vmsg); 1332147883Sscottlvoid mpt_print_db(uint32_t mb); 1333101704Smjacobvoid mpt_print_config_reply(void *vmsg); 1334147883Sscottlchar *mpt_ioc_diag(uint32_t diag); 1335147883Sscottlvoid mpt_req_state(mpt_req_state_t state); 1336101704Smjacobvoid mpt_print_config_request(void *vmsg); 1337101704Smjacobvoid mpt_print_request(void *vmsg); 1338147883Sscottlvoid mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *msg); 1339155521Smjacobvoid mpt_dump_sgl(SGE_IO_UNION *se, int offset); 1340101704Smjacob#endif /* _MPT_H_ */ 1341