19b631363SMatt Jacob /* $FreeBSD$ */ 2098ca2bdSWarner Losh /*- 39b631363SMatt Jacob * Generic defines for LSI '909 FC adapters. 49b631363SMatt Jacob * FreeBSD Version. 59b631363SMatt Jacob * 6718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD AND BSD-3-Clause 7718cf2ccSPedro F. Giffuni * 89b631363SMatt Jacob * Copyright (c) 2000, 2001 by Greg Ansley 99b631363SMatt Jacob * 109b631363SMatt Jacob * Redistribution and use in source and binary forms, with or without 119b631363SMatt Jacob * modification, are permitted provided that the following conditions 129b631363SMatt Jacob * are met: 139b631363SMatt Jacob * 1. Redistributions of source code must retain the above copyright 149b631363SMatt Jacob * notice immediately at the beginning of the file, without modification, 159b631363SMatt Jacob * this list of conditions, and the following disclaimer. 169b631363SMatt Jacob * 2. The name of the author may not be used to endorse or promote products 179b631363SMatt Jacob * derived from this software without specific prior written permission. 189b631363SMatt Jacob * 199b631363SMatt Jacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 209b631363SMatt Jacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 219b631363SMatt Jacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 229b631363SMatt Jacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 239b631363SMatt Jacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 249b631363SMatt Jacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 259b631363SMatt Jacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 269b631363SMatt Jacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 279b631363SMatt Jacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 289b631363SMatt Jacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 299b631363SMatt Jacob * SUCH DAMAGE. 300b80d21bSMatt Jacob */ 310b80d21bSMatt Jacob /*- 320b80d21bSMatt Jacob * Copyright (c) 2002, 2006 by Matthew Jacob 330b80d21bSMatt Jacob * All rights reserved. 34b0a2fdeeSScott Long * 350b80d21bSMatt Jacob * Redistribution and use in source and binary forms, with or without 360b80d21bSMatt Jacob * modification, are permitted provided that the following conditions are 370b80d21bSMatt Jacob * met: 380b80d21bSMatt Jacob * 1. Redistributions of source code must retain the above copyright 390b80d21bSMatt Jacob * notice, this list of conditions and the following disclaimer. 400b80d21bSMatt Jacob * 2. Redistributions in binary form must reproduce at minimum a disclaimer 410b80d21bSMatt Jacob * substantially similar to the "NO WARRANTY" disclaimer below 420b80d21bSMatt Jacob * ("Disclaimer") and any redistribution must be conditioned upon including 430b80d21bSMatt Jacob * a substantially similar Disclaimer requirement for further binary 440b80d21bSMatt Jacob * redistribution. 450b80d21bSMatt Jacob * 3. Neither the names of the above listed copyright holders nor the names 460b80d21bSMatt Jacob * of any contributors may be used to endorse or promote products derived 470b80d21bSMatt Jacob * from this software without specific prior written permission. 480b80d21bSMatt Jacob * 490b80d21bSMatt Jacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 500b80d21bSMatt Jacob * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 510b80d21bSMatt Jacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 520b80d21bSMatt Jacob * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 530b80d21bSMatt Jacob * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 540b80d21bSMatt Jacob * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 550b80d21bSMatt Jacob * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 560b80d21bSMatt Jacob * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 570b80d21bSMatt Jacob * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 580b80d21bSMatt Jacob * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 590b80d21bSMatt Jacob * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 600b80d21bSMatt Jacob * 610b80d21bSMatt Jacob * Support from Chris Ellsworth in order to make SAS adapters work 620b80d21bSMatt Jacob * is gratefully acknowledged. 63ec5fe39dSMatt Jacob * 64ec5fe39dSMatt Jacob * 65ec5fe39dSMatt Jacob * Support from LSI-Logic has also gone a great deal toward making this a 66ec5fe39dSMatt Jacob * workable subsystem and is gratefully acknowledged. 679b631363SMatt Jacob */ 689b631363SMatt Jacob /* 69b0a2fdeeSScott Long * Copyright (c) 2004, Avid Technology, Inc. and its contributors. 70b0a2fdeeSScott Long * Copyright (c) 2004, 2005 Justin T. Gibbs 71b0a2fdeeSScott Long * Copyright (c) 2005, WHEEL Sp. z o.o. 72b0a2fdeeSScott Long * All rights reserved. 73b0a2fdeeSScott Long * 74b0a2fdeeSScott Long * Redistribution and use in source and binary forms, with or without 75b0a2fdeeSScott Long * modification, are permitted provided that the following conditions are 76b0a2fdeeSScott Long * met: 77b0a2fdeeSScott Long * 1. Redistributions of source code must retain the above copyright 78b0a2fdeeSScott Long * notice, this list of conditions and the following disclaimer. 79b0a2fdeeSScott Long * 2. Redistributions in binary form must reproduce at minimum a disclaimer 80b0a2fdeeSScott Long * substantially similar to the "NO WARRANTY" disclaimer below 81b0a2fdeeSScott Long * ("Disclaimer") and any redistribution must be conditioned upon including 82b0a2fdeeSScott Long * a substantially similar Disclaimer requirement for further binary 83b0a2fdeeSScott Long * redistribution. 84286e947fSJustin T. Gibbs * 3. Neither the names of the above listed copyright holders nor the names 85286e947fSJustin T. Gibbs * of any contributors may be used to endorse or promote products derived 86286e947fSJustin T. Gibbs * from this software without specific prior written permission. 87b0a2fdeeSScott Long * 88b0a2fdeeSScott Long * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 89b0a2fdeeSScott Long * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 90b0a2fdeeSScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 91b0a2fdeeSScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 92b0a2fdeeSScott Long * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 93b0a2fdeeSScott Long * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 94b0a2fdeeSScott Long * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 95b0a2fdeeSScott Long * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 96b0a2fdeeSScott Long * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 97b0a2fdeeSScott Long * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 98b0a2fdeeSScott Long * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 999b631363SMatt Jacob */ 1009b631363SMatt Jacob 1019b631363SMatt Jacob #ifndef _MPT_H_ 1029b631363SMatt Jacob #define _MPT_H_ 103b0a2fdeeSScott Long 104b0a2fdeeSScott Long /********************************* OS Includes ********************************/ 105b0a2fdeeSScott Long #include <sys/param.h> 106b0a2fdeeSScott Long #include <sys/systm.h> 1074b847ffaSMarius Strobl #include <sys/bus.h> 1084b847ffaSMarius Strobl #include <sys/condvar.h> 109b0a2fdeeSScott Long #include <sys/endian.h> 110b0a2fdeeSScott Long #include <sys/eventhandler.h> 111b0a2fdeeSScott Long #include <sys/kernel.h> 112b0a2fdeeSScott Long #include <sys/lock.h> 113b0a2fdeeSScott Long #include <sys/malloc.h> 114b0a2fdeeSScott Long #include <sys/module.h> 1154b847ffaSMarius Strobl #include <sys/mutex.h> 1164b847ffaSMarius Strobl #include <sys/proc.h> 1174b847ffaSMarius Strobl #include <sys/queue.h> 1184b847ffaSMarius Strobl #include <sys/rman.h> 1194b847ffaSMarius Strobl #include <sys/types.h> 120b0a2fdeeSScott Long 1214b847ffaSMarius Strobl #include <machine/bus.h> 122b0a2fdeeSScott Long #include <machine/cpu.h> 123b0a2fdeeSScott Long #include <machine/resource.h> 124b0a2fdeeSScott Long 125444dd2b6SMatt Jacob #include <dev/pci/pcireg.h> 126444dd2b6SMatt Jacob #include <dev/pci/pcivar.h> 127444dd2b6SMatt Jacob 128b0a2fdeeSScott Long #include "opt_ddb.h" 129b0a2fdeeSScott Long 130b0a2fdeeSScott Long /**************************** Register Definitions ****************************/ 131b0a2fdeeSScott Long #include <dev/mpt/mpt_reg.h> 132b0a2fdeeSScott Long 133b0a2fdeeSScott Long /******************************* MPI Definitions ******************************/ 134b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_type.h> 135b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi.h> 136b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_cnfg.h> 137b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_ioc.h> 138b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_raid.h> 139b0a2fdeeSScott Long 140b0a2fdeeSScott Long /* XXX For mpt_debug.c */ 141b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_init.h> 142b0a2fdeeSScott Long 1430e0521a1SMatt Jacob #define MPT_S64_2_SCALAR(y) ((((int64_t)y.High) << 32) | (y.Low)) 1440e0521a1SMatt Jacob #define MPT_U64_2_SCALAR(y) ((((uint64_t)y.High) << 32) | (y.Low)) 1450e0521a1SMatt Jacob 146b0a2fdeeSScott Long /****************************** Misc Definitions ******************************/ 147a2baed97SMatt Jacob /* #define MPT_TEST_MULTIPATH 1 */ 1489b631363SMatt Jacob #define MPT_OK (0) 1499b631363SMatt Jacob #define MPT_FAIL (0x10000) 1509b631363SMatt Jacob 151b0a2fdeeSScott Long #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array)) 1529b631363SMatt Jacob 153c87e3f83SMatt Jacob #define MPT_ROLE_NONE 0 154c87e3f83SMatt Jacob #define MPT_ROLE_INITIATOR 1 155c87e3f83SMatt Jacob #define MPT_ROLE_TARGET 2 156c87e3f83SMatt Jacob #define MPT_ROLE_BOTH 3 157c87e3f83SMatt Jacob #define MPT_ROLE_DEFAULT MPT_ROLE_INITIATOR 158c87e3f83SMatt Jacob 1598ba5efbdSMarius Strobl #define MPT_INI_ID_NONE -1 1608ba5efbdSMarius Strobl 161b0a2fdeeSScott Long /**************************** Forward Declarations ****************************/ 162b0a2fdeeSScott Long struct mpt_softc; 163b0a2fdeeSScott Long struct mpt_personality; 164b0a2fdeeSScott Long typedef struct req_entry request_t; 1659b631363SMatt Jacob 166b0a2fdeeSScott Long /************************* Personality Module Support *************************/ 167b0a2fdeeSScott Long typedef int mpt_load_handler_t(struct mpt_personality *); 168b0a2fdeeSScott Long typedef int mpt_probe_handler_t(struct mpt_softc *); 169b0a2fdeeSScott Long typedef int mpt_attach_handler_t(struct mpt_softc *); 170c87e3f83SMatt Jacob typedef int mpt_enable_handler_t(struct mpt_softc *); 171a7303be1SMatt Jacob typedef void mpt_ready_handler_t(struct mpt_softc *); 172b0a2fdeeSScott Long typedef int mpt_event_handler_t(struct mpt_softc *, request_t *, 173b0a2fdeeSScott Long MSG_EVENT_NOTIFY_REPLY *); 174b0a2fdeeSScott Long typedef void mpt_reset_handler_t(struct mpt_softc *, int /*type*/); 175b0a2fdeeSScott Long /* XXX Add return value and use for veto? */ 176b0a2fdeeSScott Long typedef void mpt_shutdown_handler_t(struct mpt_softc *); 177b0a2fdeeSScott Long typedef void mpt_detach_handler_t(struct mpt_softc *); 178b0a2fdeeSScott Long typedef int mpt_unload_handler_t(struct mpt_personality *); 179b0a2fdeeSScott Long 180b0a2fdeeSScott Long struct mpt_personality 181b0a2fdeeSScott Long { 182b0a2fdeeSScott Long const char *name; 183b0a2fdeeSScott Long uint32_t id; /* Assigned identifier. */ 184b0a2fdeeSScott Long u_int use_count; /* Instances using personality*/ 185b0a2fdeeSScott Long mpt_load_handler_t *load; /* configure personailty */ 186b0a2fdeeSScott Long #define MPT_PERS_FIRST_HANDLER(pers) (&(pers)->load) 187b0a2fdeeSScott Long mpt_probe_handler_t *probe; /* configure personailty */ 188b0a2fdeeSScott Long mpt_attach_handler_t *attach; /* initialize device instance */ 189c87e3f83SMatt Jacob mpt_enable_handler_t *enable; /* enable device */ 190a7303be1SMatt Jacob mpt_ready_handler_t *ready; /* final open for business */ 191b0a2fdeeSScott Long mpt_event_handler_t *event; /* Handle MPI event. */ 192b0a2fdeeSScott Long mpt_reset_handler_t *reset; /* Re-init after reset. */ 193b0a2fdeeSScott Long mpt_shutdown_handler_t *shutdown; /* Shutdown instance. */ 194b0a2fdeeSScott Long mpt_detach_handler_t *detach; /* release device instance */ 195b0a2fdeeSScott Long mpt_unload_handler_t *unload; /* Shutdown personality */ 196b0a2fdeeSScott Long #define MPT_PERS_LAST_HANDLER(pers) (&(pers)->unload) 1979b631363SMatt Jacob }; 1989b631363SMatt Jacob 199b0a2fdeeSScott Long int mpt_modevent(module_t, int, void *); 2009b631363SMatt Jacob 201b0a2fdeeSScott Long /* Maximum supported number of personalities. */ 202b0a2fdeeSScott Long #define MPT_MAX_PERSONALITIES (15) 2039b631363SMatt Jacob 204b0a2fdeeSScott Long #define MPT_PERSONALITY_DEPEND(name, dep, vmin, vpref, vmax) \ 205b0a2fdeeSScott Long MODULE_DEPEND(name, dep, vmin, vpref, vmax) 206b0a2fdeeSScott Long 207b0a2fdeeSScott Long #define DECLARE_MPT_PERSONALITY(name, order) \ 208b0a2fdeeSScott Long static moduledata_t name##_mod = { \ 209b0a2fdeeSScott Long #name, mpt_modevent, &name##_personality \ 210b0a2fdeeSScott Long }; \ 211b0a2fdeeSScott Long DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, order); \ 212b0a2fdeeSScott Long MODULE_VERSION(name, 1); \ 213b0a2fdeeSScott Long MPT_PERSONALITY_DEPEND(name, mpt_core, 1, 1, 1) 214b0a2fdeeSScott Long 215b0a2fdeeSScott Long /******************************* Bus DMA Support ******************************/ 216b0a2fdeeSScott Long /* XXX Need to update bus_dmamap_sync to take a range argument. */ 217b0a2fdeeSScott Long #define bus_dmamap_sync_range(dma_tag, dmamap, offset, len, op) \ 218b0a2fdeeSScott Long bus_dmamap_sync(dma_tag, dmamap, op) 219b0a2fdeeSScott Long 220b0a2fdeeSScott Long #define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary, \ 221b0a2fdeeSScott Long lowaddr, highaddr, filter, filterarg, \ 222b0a2fdeeSScott Long maxsize, nsegments, maxsegsz, flags, \ 223b0a2fdeeSScott Long dma_tagp) \ 224b0a2fdeeSScott Long bus_dma_tag_create(parent_tag, alignment, boundary, \ 225b0a2fdeeSScott Long lowaddr, highaddr, filter, filterarg, \ 226b0a2fdeeSScott Long maxsize, nsegments, maxsegsz, flags, \ 227d0a68c27SMatt Jacob busdma_lock_mutex, &(mpt)->mpt_lock, \ 228b0a2fdeeSScott Long dma_tagp) 229b0a2fdeeSScott Long struct mpt_map_info { 230b0a2fdeeSScott Long struct mpt_softc *mpt; 231b0a2fdeeSScott Long int error; 232b0a2fdeeSScott Long uint32_t phys; 233b0a2fdeeSScott Long }; 234b0a2fdeeSScott Long 235b0a2fdeeSScott Long void mpt_map_rquest(void *, bus_dma_segment_t *, int, int); 236b0a2fdeeSScott Long 237453130d9SPedro F. Giffuni /********************************* Endianness *********************************/ 2380e0521a1SMatt Jacob #define MPT_2_HOST64(ptr, tag) ptr->tag = le64toh(ptr->tag) 2390e0521a1SMatt Jacob #define MPT_2_HOST32(ptr, tag) ptr->tag = le32toh(ptr->tag) 2400e0521a1SMatt Jacob #define MPT_2_HOST16(ptr, tag) ptr->tag = le16toh(ptr->tag) 241b0a2fdeeSScott Long 2420e0521a1SMatt Jacob #define HOST_2_MPT64(ptr, tag) ptr->tag = htole64(ptr->tag) 2430e0521a1SMatt Jacob #define HOST_2_MPT32(ptr, tag) ptr->tag = htole32(ptr->tag) 2440e0521a1SMatt Jacob #define HOST_2_MPT16(ptr, tag) ptr->tag = htole16(ptr->tag) 2450e0521a1SMatt Jacob 2467185cd36SMatt Jacob #if _BYTE_ORDER == _BIG_ENDIAN 2470e0521a1SMatt Jacob void mpt2host_sge_simple_union(SGE_SIMPLE_UNION *); 2480e0521a1SMatt Jacob void mpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *); 2490e0521a1SMatt Jacob void mpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *); 2500e0521a1SMatt Jacob void mpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *); 2517ee37807SMarius Strobl void mpt2host_config_page_ioc3(CONFIG_PAGE_IOC_3 *); 2527ee37807SMarius Strobl void mpt2host_config_page_scsi_port_0(CONFIG_PAGE_SCSI_PORT_0 *); 2537ee37807SMarius Strobl void mpt2host_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *); 2547ee37807SMarius Strobl void host2mpt_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *); 2557ee37807SMarius Strobl void mpt2host_config_page_scsi_port_2(CONFIG_PAGE_SCSI_PORT_2 *); 2567ee37807SMarius Strobl void mpt2host_config_page_scsi_device_0(CONFIG_PAGE_SCSI_DEVICE_0 *); 2577ee37807SMarius Strobl void mpt2host_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *); 2587ee37807SMarius Strobl void host2mpt_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *); 2597ee37807SMarius Strobl void mpt2host_config_page_fc_port_0(CONFIG_PAGE_FC_PORT_0 *); 2607ee37807SMarius Strobl void mpt2host_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *); 2617ee37807SMarius Strobl void host2mpt_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *); 2620e0521a1SMatt Jacob void mpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *); 2637ee37807SMarius Strobl void mpt2host_config_page_raid_phys_disk_0(CONFIG_PAGE_RAID_PHYS_DISK_0 *); 2640e0521a1SMatt Jacob void mpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *); 2657185cd36SMatt Jacob #else 2667185cd36SMatt Jacob #define mpt2host_sge_simple_union(x) do { ; } while (0) 2677185cd36SMatt Jacob #define mpt2host_iocfacts_reply(x) do { ; } while (0) 2687185cd36SMatt Jacob #define mpt2host_portfacts_reply(x) do { ; } while (0) 2697185cd36SMatt Jacob #define mpt2host_config_page_ioc2(x) do { ; } while (0) 2707ee37807SMarius Strobl #define mpt2host_config_page_ioc3(x) do { ; } while (0) 2717ee37807SMarius Strobl #define mpt2host_config_page_scsi_port_0(x) do { ; } while (0) 2727ee37807SMarius Strobl #define mpt2host_config_page_scsi_port_1(x) do { ; } while (0) 2737ee37807SMarius Strobl #define host2mpt_config_page_scsi_port_1(x) do { ; } while (0) 2747ee37807SMarius Strobl #define mpt2host_config_page_scsi_port_2(x) do { ; } while (0) 2757ee37807SMarius Strobl #define mpt2host_config_page_scsi_device_0(x) do { ; } while (0) 2767ee37807SMarius Strobl #define mpt2host_config_page_scsi_device_1(x) do { ; } while (0) 2777ee37807SMarius Strobl #define host2mpt_config_page_scsi_device_1(x) do { ; } while (0) 2787ee37807SMarius Strobl #define mpt2host_config_page_fc_port_0(x) do { ; } while (0) 2797ee37807SMarius Strobl #define mpt2host_config_page_fc_port_1(x) do { ; } while (0) 2807ee37807SMarius Strobl #define host2mpt_config_page_fc_port_1(x) do { ; } while (0) 2817185cd36SMatt Jacob #define mpt2host_config_page_raid_vol_0(x) do { ; } while (0) 2827ee37807SMarius Strobl #define mpt2host_config_page_raid_phys_disk_0(x) \ 2837ee37807SMarius Strobl do { ; } while (0) 2847185cd36SMatt Jacob #define mpt2host_mpi_raid_vol_indicator(x) do { ; } while (0) 2850e0521a1SMatt Jacob #endif 286b0a2fdeeSScott Long 287b0a2fdeeSScott Long /**************************** MPI Transaction State ***************************/ 288b0a2fdeeSScott Long typedef enum { 2895e073106SMatt Jacob REQ_STATE_NIL = 0x00, 2905e073106SMatt Jacob REQ_STATE_FREE = 0x01, 2915e073106SMatt Jacob REQ_STATE_ALLOCATED = 0x02, 2925e073106SMatt Jacob REQ_STATE_QUEUED = 0x04, 2935e073106SMatt Jacob REQ_STATE_DONE = 0x08, 2945e073106SMatt Jacob REQ_STATE_TIMEDOUT = 0x10, 2955e073106SMatt Jacob REQ_STATE_NEED_WAKEUP = 0x20, 2965e073106SMatt Jacob REQ_STATE_LOCKED = 0x80, /* can't be freed */ 297b0a2fdeeSScott Long REQ_STATE_MASK = 0xFF 298b0a2fdeeSScott Long } mpt_req_state_t; 299b0a2fdeeSScott Long 300b0a2fdeeSScott Long struct req_entry { 301b0a2fdeeSScott Long TAILQ_ENTRY(req_entry) links; /* Pointer to next in list */ 302b0a2fdeeSScott Long mpt_req_state_t state; /* Request State Information */ 303b0a2fdeeSScott Long uint16_t index; /* Index of this entry */ 304b0a2fdeeSScott Long uint16_t IOCStatus; /* Completion status */ 3055ab13afcSMarius Strobl uint16_t ResponseCode; /* TMF Response Code */ 3065089bd63SMatt Jacob uint16_t serno; /* serial number */ 307b0a2fdeeSScott Long union ccb *ccb; /* CAM request */ 308b0a2fdeeSScott Long void *req_vbuf; /* Virtual Address of Entry */ 309b0a2fdeeSScott Long void *sense_vbuf; /* Virtual Address of sense data */ 310b0a2fdeeSScott Long bus_addr_t req_pbuf; /* Physical Address of Entry */ 311b0a2fdeeSScott Long bus_addr_t sense_pbuf; /* Physical Address of sense data */ 312fcd9a16bSMatt Jacob bus_dmamap_t dmap; /* DMA map for data buffers */ 313444dd2b6SMatt Jacob struct req_entry *chain; /* for SGE overallocations */ 314d0a68c27SMatt Jacob struct callout callout; /* Timeout for the request */ 315b0a2fdeeSScott Long }; 316b0a2fdeeSScott Long 3171d558d6aSScott Long typedef struct mpt_config_params { 3181d558d6aSScott Long u_int Action; 3191d558d6aSScott Long u_int PageVersion; 3201d558d6aSScott Long u_int PageLength; 3211d558d6aSScott Long u_int PageNumber; 3221d558d6aSScott Long u_int PageType; 3231d558d6aSScott Long u_int PageAddress; 3241d558d6aSScott Long u_int ExtPageLength; 3251d558d6aSScott Long u_int ExtPageType; 3261d558d6aSScott Long } cfgparms_t; 3271d558d6aSScott Long 328c87e3f83SMatt Jacob /**************************** MPI Target State Info ***************************/ 329c87e3f83SMatt Jacob typedef struct { 330c87e3f83SMatt Jacob uint32_t reply_desc; /* current reply descriptor */ 331c87e3f83SMatt Jacob uint32_t bytes_xfered; /* current relative offset */ 332501b1685SAlexander Motin int resid; /* current data residual */ 333c87e3f83SMatt Jacob union ccb *ccb; /* pointer to currently active ccb */ 334c87e3f83SMatt Jacob request_t *req; /* pointer to currently active assist request */ 33573651fd1SMatt Jacob uint32_t 33673651fd1SMatt Jacob is_local : 1, 33773651fd1SMatt Jacob nxfers : 31; 33867445003SAlexander Motin uint32_t tag_id; /* Our local tag. */ 33967445003SAlexander Motin uint16_t itag; /* Initiator tag. */ 340c87e3f83SMatt Jacob enum { 341c87e3f83SMatt Jacob TGT_STATE_NIL, 3425e073106SMatt Jacob TGT_STATE_LOADING, 343c87e3f83SMatt Jacob TGT_STATE_LOADED, 344c87e3f83SMatt Jacob TGT_STATE_IN_CAM, 345c87e3f83SMatt Jacob TGT_STATE_SETTING_UP_FOR_DATA, 346c87e3f83SMatt Jacob TGT_STATE_MOVING_DATA, 347c87e3f83SMatt Jacob TGT_STATE_MOVING_DATA_AND_STATUS, 348c87e3f83SMatt Jacob TGT_STATE_SENDING_STATUS 349c87e3f83SMatt Jacob } state; 350c87e3f83SMatt Jacob } mpt_tgt_state_t; 351c87e3f83SMatt Jacob 352c87e3f83SMatt Jacob /* 353c87e3f83SMatt Jacob * When we get an incoming command it has its own tag which is called the 354c87e3f83SMatt Jacob * IoIndex. This is the value we gave that particular command buffer when 355c87e3f83SMatt Jacob * we originally assigned it. It's just a number, really. The FC card uses 356c87e3f83SMatt Jacob * it as an RX_ID. We can use it to index into mpt->tgt_cmd_ptrs, which 357c87e3f83SMatt Jacob * contains pointers the request_t structures related to that IoIndex. 358c87e3f83SMatt Jacob * 359c87e3f83SMatt Jacob * What *we* do is construct a tag out of the index for the target command 360c87e3f83SMatt Jacob * which owns the incoming ATIO plus a rolling sequence number. 361c87e3f83SMatt Jacob */ 362c87e3f83SMatt Jacob #define MPT_MAKE_TAGID(mpt, req, ioindex) \ 3635e073106SMatt Jacob ((ioindex << 18) | (((mpt->sequence++) & 0x3f) << 12) | (req->index & 0xfff)) 364c87e3f83SMatt Jacob 365c87e3f83SMatt Jacob #ifdef INVARIANTS 366c87e3f83SMatt Jacob #define MPT_TAG_2_REQ(a, b) mpt_tag_2_req(a, (uint32_t) b) 367c87e3f83SMatt Jacob #else 3685e073106SMatt Jacob #define MPT_TAG_2_REQ(mpt, tag) mpt->tgt_cmd_ptrs[tag >> 18] 369c87e3f83SMatt Jacob #endif 370c87e3f83SMatt Jacob 371c87e3f83SMatt Jacob #define MPT_TGT_STATE(mpt, req) ((mpt_tgt_state_t *) \ 372c87e3f83SMatt Jacob (&((uint8_t *)req->req_vbuf)[MPT_RQSL(mpt) - sizeof (mpt_tgt_state_t)])) 373c87e3f83SMatt Jacob 374c87e3f83SMatt Jacob STAILQ_HEAD(mpt_hdr_stailq, ccb_hdr); 375c87e3f83SMatt Jacob #define MPT_MAX_LUNS 256 376c87e3f83SMatt Jacob typedef struct { 377c87e3f83SMatt Jacob struct mpt_hdr_stailq atios; 378c87e3f83SMatt Jacob struct mpt_hdr_stailq inots; 379c87e3f83SMatt Jacob int enabled; 380c87e3f83SMatt Jacob } tgt_resource_t; 3815089bd63SMatt Jacob #define MPT_MAX_ELS 64 382c87e3f83SMatt Jacob 383b0a2fdeeSScott Long /**************************** Handler Registration ****************************/ 384b0a2fdeeSScott Long /* 385b0a2fdeeSScott Long * Global table of registered reply handlers. The 386b0a2fdeeSScott Long * handler is indicated by byte 3 of the request 387b0a2fdeeSScott Long * index submitted to the IOC. This allows the 388b0a2fdeeSScott Long * driver core to perform generic processing without 389b0a2fdeeSScott Long * any knowledge of per-personality behavior. 390b0a2fdeeSScott Long * 391b0a2fdeeSScott Long * MPT_NUM_REPLY_HANDLERS must be a power of 2 392b0a2fdeeSScott Long * to allow the easy generation of a mask. 393b0a2fdeeSScott Long * 394b0a2fdeeSScott Long * The handler offsets used by the core are hard coded 395b0a2fdeeSScott Long * allowing faster code generation when assigning a handler 396b0a2fdeeSScott Long * to a request. All "personalities" must use the 397b0a2fdeeSScott Long * the handler registration mechanism. 398b0a2fdeeSScott Long * 399b0a2fdeeSScott Long * The IOC handlers that are rarely executed are placed 400b0a2fdeeSScott Long * at the tail of the table to make it more likely that 401b0a2fdeeSScott Long * all commonly executed handlers fit in a single cache 402b0a2fdeeSScott Long * line. 403b0a2fdeeSScott Long */ 404c87e3f83SMatt Jacob #define MPT_NUM_REPLY_HANDLERS (32) 405b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_EVENTS MPT_CBI_TO_HID(0) 406b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_CONFIG MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-1) 407b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_HANDSHAKE MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-2) 408b0a2fdeeSScott Long typedef int mpt_reply_handler_t(struct mpt_softc *mpt, request_t *request, 409c87e3f83SMatt Jacob uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame); 410b0a2fdeeSScott Long typedef union { 411b0a2fdeeSScott Long mpt_reply_handler_t *reply_handler; 412b0a2fdeeSScott Long } mpt_handler_t; 413b0a2fdeeSScott Long 414b0a2fdeeSScott Long typedef enum { 415b0a2fdeeSScott Long MPT_HANDLER_REPLY, 416b0a2fdeeSScott Long MPT_HANDLER_EVENT, 417b0a2fdeeSScott Long MPT_HANDLER_RESET, 418b0a2fdeeSScott Long MPT_HANDLER_SHUTDOWN 419b0a2fdeeSScott Long } mpt_handler_type; 420b0a2fdeeSScott Long 421b0a2fdeeSScott Long struct mpt_handler_record 422b0a2fdeeSScott Long { 423b0a2fdeeSScott Long LIST_ENTRY(mpt_handler_record) links; 424b0a2fdeeSScott Long mpt_handler_t handler; 425b0a2fdeeSScott Long }; 426b0a2fdeeSScott Long 427b0a2fdeeSScott Long LIST_HEAD(mpt_handler_list, mpt_handler_record); 4289b631363SMatt Jacob 4299b631363SMatt Jacob /* 430b0a2fdeeSScott Long * The handler_id is currently unused but would contain the 431b0a2fdeeSScott Long * handler ID used in the MsgContext field to allow direction 432b0a2fdeeSScott Long * of replies to the handler. Registrations that don't require 433b0a2fdeeSScott Long * a handler id can pass in NULL for the handler_id. 434b0a2fdeeSScott Long * 435b0a2fdeeSScott Long * Deregistrations for handlers without a handler id should 436b0a2fdeeSScott Long * pass in MPT_HANDLER_ID_NONE. 4379b631363SMatt Jacob */ 438b0a2fdeeSScott Long #define MPT_HANDLER_ID_NONE (0xFFFFFFFF) 439b0a2fdeeSScott Long int mpt_register_handler(struct mpt_softc *, mpt_handler_type, 440b0a2fdeeSScott Long mpt_handler_t, uint32_t *); 441b0a2fdeeSScott Long int mpt_deregister_handler(struct mpt_softc *, mpt_handler_type, 442b0a2fdeeSScott Long mpt_handler_t, uint32_t); 4439b631363SMatt Jacob 444b0a2fdeeSScott Long /******************* Per-Controller Instance Data Structures ******************/ 445b0a2fdeeSScott Long TAILQ_HEAD(req_queue, req_entry); 4469b631363SMatt Jacob 447b0a2fdeeSScott Long /* Structure for saving proper values for modifyable PCI config registers */ 448b0a2fdeeSScott Long struct mpt_pci_cfg { 449b0a2fdeeSScott Long uint16_t Command; 450b0a2fdeeSScott Long uint16_t LatencyTimer_LineSize; 451b0a2fdeeSScott Long uint32_t IO_BAR; 452b0a2fdeeSScott Long uint32_t Mem0_BAR[2]; 453b0a2fdeeSScott Long uint32_t Mem1_BAR[2]; 454b0a2fdeeSScott Long uint32_t ROM_BAR; 455b0a2fdeeSScott Long uint8_t IntLine; 456b0a2fdeeSScott Long uint32_t PMCSR; 4579b631363SMatt Jacob }; 4589b631363SMatt Jacob 459b0a2fdeeSScott Long typedef enum { 460b0a2fdeeSScott Long MPT_RVF_NONE = 0x0, 461b0a2fdeeSScott Long MPT_RVF_ACTIVE = 0x1, 462b0a2fdeeSScott Long MPT_RVF_ANNOUNCED = 0x2, 463b0a2fdeeSScott Long MPT_RVF_UP2DATE = 0x4, 464b0a2fdeeSScott Long MPT_RVF_REFERENCED = 0x8, 465b0a2fdeeSScott Long MPT_RVF_WCE_CHANGED = 0x10 466b0a2fdeeSScott Long } mpt_raid_volume_flags; 467b0a2fdeeSScott Long 468b0a2fdeeSScott Long struct mpt_raid_volume { 469b0a2fdeeSScott Long CONFIG_PAGE_RAID_VOL_0 *config_page; 470b0a2fdeeSScott Long MPI_RAID_VOL_INDICATOR sync_progress; 471b0a2fdeeSScott Long mpt_raid_volume_flags flags; 4720e3b145eSMatt Jacob u_int quiesced_disks; 4739b631363SMatt Jacob }; 4749b631363SMatt Jacob 475b0a2fdeeSScott Long typedef enum { 476b0a2fdeeSScott Long MPT_RDF_NONE = 0x00, 477b0a2fdeeSScott Long MPT_RDF_ACTIVE = 0x01, 478b0a2fdeeSScott Long MPT_RDF_ANNOUNCED = 0x02, 479b0a2fdeeSScott Long MPT_RDF_UP2DATE = 0x04, 480b0a2fdeeSScott Long MPT_RDF_REFERENCED = 0x08, 481b0a2fdeeSScott Long MPT_RDF_QUIESCING = 0x10, 482b0a2fdeeSScott Long MPT_RDF_QUIESCED = 0x20 483b0a2fdeeSScott Long } mpt_raid_disk_flags; 4849b631363SMatt Jacob 485b0a2fdeeSScott Long struct mpt_raid_disk { 486b0a2fdeeSScott Long CONFIG_PAGE_RAID_PHYS_DISK_0 config_page; 487b0a2fdeeSScott Long struct mpt_raid_volume *volume; 488b0a2fdeeSScott Long u_int member_number; 489b0a2fdeeSScott Long u_int pass_thru_active; 490b0a2fdeeSScott Long mpt_raid_disk_flags flags; 4919b631363SMatt Jacob }; 4929b631363SMatt Jacob 493b0a2fdeeSScott Long struct mpt_evtf_record { 494b0a2fdeeSScott Long MSG_EVENT_NOTIFY_REPLY reply; 495b0a2fdeeSScott Long uint32_t context; 496b0a2fdeeSScott Long LIST_ENTRY(mpt_evtf_record) links; 4979b631363SMatt Jacob }; 4989b631363SMatt Jacob 499b0a2fdeeSScott Long LIST_HEAD(mpt_evtf_list, mpt_evtf_record); 5009b631363SMatt Jacob 5011d558d6aSScott Long struct mptsas_devinfo { 5021d558d6aSScott Long uint16_t dev_handle; 5031d558d6aSScott Long uint16_t parent_dev_handle; 5041d558d6aSScott Long uint16_t enclosure_handle; 5051d558d6aSScott Long uint16_t slot; 5061d558d6aSScott Long uint8_t phy_num; 5071d558d6aSScott Long uint8_t physical_port; 5081d558d6aSScott Long uint8_t target_id; 5091d558d6aSScott Long uint8_t bus; 5101d558d6aSScott Long uint64_t sas_address; 5111d558d6aSScott Long uint32_t device_info; 5121d558d6aSScott Long }; 5131d558d6aSScott Long 5141d558d6aSScott Long struct mptsas_phyinfo { 5151d558d6aSScott Long uint16_t handle; 5161d558d6aSScott Long uint8_t phy_num; 5171d558d6aSScott Long uint8_t port_id; 5181d558d6aSScott Long uint8_t negotiated_link_rate; 5191d558d6aSScott Long uint8_t hw_link_rate; 5201d558d6aSScott Long uint8_t programmed_link_rate; 5211d558d6aSScott Long uint8_t sas_port_add_phy; 5221d558d6aSScott Long struct mptsas_devinfo identify; 5231d558d6aSScott Long struct mptsas_devinfo attached; 5241d558d6aSScott Long }; 5251d558d6aSScott Long 5261d558d6aSScott Long struct mptsas_portinfo { 5271d558d6aSScott Long uint16_t num_phys; 5281d558d6aSScott Long struct mptsas_phyinfo *phy_info; 5291d558d6aSScott Long }; 5301d558d6aSScott Long 531b0a2fdeeSScott Long struct mpt_softc { 532b0a2fdeeSScott Long device_t dev; 533b0a2fdeeSScott Long struct mtx mpt_lock; 5345089bd63SMatt Jacob int mpt_locksetup; 535b0a2fdeeSScott Long uint32_t mpt_pers_mask; 536b4c618c0SMatt Jacob uint32_t 53704016bcfSMarius Strobl : 7, 538c87e3f83SMatt Jacob unit : 8, 539a2baed97SMatt Jacob ready : 1, 5400e0521a1SMatt Jacob fw_uploaded : 1, 541804625eeSMatt Jacob msi_enable : 1, 542c87e3f83SMatt Jacob twildcard : 1, 543c87e3f83SMatt Jacob tenabled : 1, 544b4c618c0SMatt Jacob do_cfg_role : 1, 5451d79ca0eSMatt Jacob raid_enabled : 1, 546b0a2fdeeSScott Long raid_mwce_set : 1, 547b0a2fdeeSScott Long getreqwaiter : 1, 548b0a2fdeeSScott Long shutdwn_raid : 1, 549b0a2fdeeSScott Long shutdwn_recovery: 1, 550b0a2fdeeSScott Long outofbeer : 1, 551b0a2fdeeSScott Long disabled : 1, 5525580ce96SMatt Jacob is_spi : 1, 553c87e3f83SMatt Jacob is_sas : 1, 55404016bcfSMarius Strobl is_fc : 1, 55504016bcfSMarius Strobl is_1078 : 1; 5569b631363SMatt Jacob 557b4c618c0SMatt Jacob u_int cfg_role; 558b4c618c0SMatt Jacob u_int role; /* role: none, ini, target, both */ 559b4c618c0SMatt Jacob 560b0a2fdeeSScott Long u_int verbose; 561a2baed97SMatt Jacob #ifdef MPT_TEST_MULTIPATH 562a2baed97SMatt Jacob int failure_id; 563a2baed97SMatt Jacob #endif 5649b631363SMatt Jacob 565b0a2fdeeSScott Long /* 566b0a2fdeeSScott Long * IOC Facts 567b0a2fdeeSScott Long */ 5680e0521a1SMatt Jacob MSG_IOC_FACTS_REPLY ioc_facts; 5699b631363SMatt Jacob 570b0a2fdeeSScott Long /* 571b0a2fdeeSScott Long * Port Facts 572b0a2fdeeSScott Long */ 5730e0521a1SMatt Jacob MSG_PORT_FACTS_REPLY * port_facts; 5740e0521a1SMatt Jacob #define mpt_max_tgtcmds port_facts[0].MaxPostedCmdBuffers 5759b631363SMatt Jacob 576b0a2fdeeSScott Long /* 577b0a2fdeeSScott Long * Device Configuration Information 578b0a2fdeeSScott Long */ 579b0a2fdeeSScott Long union { 580b0a2fdeeSScott Long struct mpt_spi_cfg { 581b0a2fdeeSScott Long CONFIG_PAGE_SCSI_PORT_0 _port_page0; 582b0a2fdeeSScott Long CONFIG_PAGE_SCSI_PORT_1 _port_page1; 583b0a2fdeeSScott Long CONFIG_PAGE_SCSI_PORT_2 _port_page2; 584b0a2fdeeSScott Long CONFIG_PAGE_SCSI_DEVICE_0 _dev_page0[16]; 585b0a2fdeeSScott Long CONFIG_PAGE_SCSI_DEVICE_1 _dev_page1[16]; 5868ba5efbdSMarius Strobl int _ini_id; 587b0a2fdeeSScott Long uint16_t _tag_enable; 588b0a2fdeeSScott Long uint16_t _disc_enable; 589b0a2fdeeSScott Long } spi; 590b0a2fdeeSScott Long #define mpt_port_page0 cfg.spi._port_page0 591b0a2fdeeSScott Long #define mpt_port_page1 cfg.spi._port_page1 592b0a2fdeeSScott Long #define mpt_port_page2 cfg.spi._port_page2 593b0a2fdeeSScott Long #define mpt_dev_page0 cfg.spi._dev_page0 594b0a2fdeeSScott Long #define mpt_dev_page1 cfg.spi._dev_page1 5958ba5efbdSMarius Strobl #define mpt_ini_id cfg.spi._ini_id 596b0a2fdeeSScott Long #define mpt_tag_enable cfg.spi._tag_enable 597b0a2fdeeSScott Long #define mpt_disc_enable cfg.spi._disc_enable 598b0a2fdeeSScott Long struct mpi_fc_cfg { 599c87e3f83SMatt Jacob CONFIG_PAGE_FC_PORT_0 _port_page0; 6009fe6d254SMatt Jacob uint32_t _port_speed; 601c87e3f83SMatt Jacob #define mpt_fcport_page0 cfg.fc._port_page0 6029fe6d254SMatt Jacob #define mpt_fcport_speed cfg.fc._port_speed 603b0a2fdeeSScott Long } fc; 604b0a2fdeeSScott Long } cfg; 605970043d7SMatt Jacob /* 606970043d7SMatt Jacob * Device config information stored up for sysctl to access 607970043d7SMatt Jacob */ 608970043d7SMatt Jacob union { 609970043d7SMatt Jacob struct { 610970043d7SMatt Jacob unsigned int initiator_id; 611970043d7SMatt Jacob } spi; 612970043d7SMatt Jacob struct { 613555dbebfSAlexander Motin uint64_t wwnn; 614555dbebfSAlexander Motin uint64_t wwpn; 615471f963dSAlexander Motin uint32_t portid; 616970043d7SMatt Jacob } fc; 617970043d7SMatt Jacob } scinfo; 618b0a2fdeeSScott Long 6191d79ca0eSMatt Jacob /* Controller Info for RAID information */ 620b0a2fdeeSScott Long CONFIG_PAGE_IOC_2 * ioc_page2; 621b0a2fdeeSScott Long CONFIG_PAGE_IOC_3 * ioc_page3; 622b0a2fdeeSScott Long 623b0a2fdeeSScott Long /* Raid Data */ 624b0a2fdeeSScott Long struct mpt_raid_volume* raid_volumes; 625b0a2fdeeSScott Long struct mpt_raid_disk* raid_disks; 626b0a2fdeeSScott Long u_int raid_max_volumes; 627b0a2fdeeSScott Long u_int raid_max_disks; 628b0a2fdeeSScott Long u_int raid_page0_len; 629b0a2fdeeSScott Long u_int raid_wakeup; 630b0a2fdeeSScott Long u_int raid_rescan; 631b0a2fdeeSScott Long u_int raid_resync_rate; 632b0a2fdeeSScott Long u_int raid_mwce_setting; 633b0a2fdeeSScott Long u_int raid_queue_depth; 6345cc0208aSAlexander Kabaev u_int raid_nonopt_volumes; 635b0a2fdeeSScott Long struct proc *raid_thread; 636b0a2fdeeSScott Long struct callout raid_timer; 637b0a2fdeeSScott Long 638b0a2fdeeSScott Long /* 639b0a2fdeeSScott Long * PCI Hardware info 640b0a2fdeeSScott Long */ 641b0a2fdeeSScott Long struct resource * pci_irq; /* Interrupt map for chip */ 6425ab13afcSMarius Strobl void * ih; /* Interrupt handle */ 643fd61f421SMarius Strobl #if 0 644b0a2fdeeSScott Long struct mpt_pci_cfg pci_cfg; /* saved PCI conf registers */ 645fd61f421SMarius Strobl #endif 646b0a2fdeeSScott Long 647b0a2fdeeSScott Long /* 648b0a2fdeeSScott Long * DMA Mapping Stuff 649b0a2fdeeSScott Long */ 650b0a2fdeeSScott Long struct resource * pci_reg; /* Register map for chip */ 651b0a2fdeeSScott Long bus_space_tag_t pci_st; /* Bus tag for registers */ 652b0a2fdeeSScott Long bus_space_handle_t pci_sh; /* Bus handle for registers */ 653b0a2fdeeSScott Long /* PIO versions of above. */ 654b0a2fdeeSScott Long struct resource * pci_pio_reg; 655b0a2fdeeSScott Long bus_space_tag_t pci_pio_st; 656b0a2fdeeSScott Long bus_space_handle_t pci_pio_sh; 657b0a2fdeeSScott Long 658b0a2fdeeSScott Long bus_dma_tag_t parent_dmat; /* DMA tag for parent PCI bus */ 659b0a2fdeeSScott Long bus_dma_tag_t reply_dmat; /* DMA tag for reply memory */ 660b0a2fdeeSScott Long bus_dmamap_t reply_dmap; /* DMA map for reply memory */ 661b0a2fdeeSScott Long uint8_t *reply; /* KVA of reply memory */ 662b0a2fdeeSScott Long bus_addr_t reply_phys; /* BusAddr of reply memory */ 663b0a2fdeeSScott Long 664b0a2fdeeSScott Long bus_dma_tag_t buffer_dmat; /* DMA tag for buffers */ 665453130d9SPedro F. Giffuni bus_dma_tag_t request_dmat; /* DMA tag for request memory */ 666453130d9SPedro F. Giffuni bus_dmamap_t request_dmap; /* DMA map for request memory */ 667b0a2fdeeSScott Long uint8_t *request; /* KVA of Request memory */ 668c87e3f83SMatt Jacob bus_addr_t request_phys; /* BusAddr of request memory */ 669b0a2fdeeSScott Long 670444dd2b6SMatt Jacob uint32_t max_seg_cnt; /* calculated after IOC facts */ 671*cd853791SKonstantin Belousov uint32_t max_cam_seg_cnt;/* calculated from maxphys */ 672444dd2b6SMatt Jacob 673444dd2b6SMatt Jacob /* 674444dd2b6SMatt Jacob * Hardware management 675444dd2b6SMatt Jacob */ 676b0a2fdeeSScott Long u_int reset_cnt; 677b0a2fdeeSScott Long 678b0a2fdeeSScott Long /* 679b0a2fdeeSScott Long * CAM && Software Management 680b0a2fdeeSScott Long */ 681b0a2fdeeSScott Long request_t *request_pool; 682b0a2fdeeSScott Long struct req_queue request_free_list; 683b0a2fdeeSScott Long struct req_queue request_pending_list; 684b0a2fdeeSScott Long struct req_queue request_timeout_list; 685b0a2fdeeSScott Long 686b0a2fdeeSScott Long struct cam_sim *sim; 687b0a2fdeeSScott Long struct cam_path *path; 688b0a2fdeeSScott Long 689b0a2fdeeSScott Long struct cam_sim *phydisk_sim; 690b0a2fdeeSScott Long struct cam_path *phydisk_path; 691b0a2fdeeSScott Long 692b0a2fdeeSScott Long struct proc *recovery_thread; 693b0a2fdeeSScott Long request_t *tmf_req; 694b0a2fdeeSScott Long 695c87e3f83SMatt Jacob /* 6965e073106SMatt Jacob * Deferred frame acks due to resource shortage. 6975e073106SMatt Jacob */ 6985e073106SMatt Jacob struct mpt_evtf_list ack_frames; 699fcd9a16bSMatt Jacob 7005e073106SMatt Jacob /* 701c87e3f83SMatt Jacob * Target Mode Support 702c87e3f83SMatt Jacob */ 703c87e3f83SMatt Jacob uint32_t scsi_tgt_handler_id; 704c87e3f83SMatt Jacob request_t ** tgt_cmd_ptrs; 7055089bd63SMatt Jacob request_t ** els_cmd_ptrs; /* FC only */ 706c87e3f83SMatt Jacob 707c87e3f83SMatt Jacob /* 708c87e3f83SMatt Jacob * *snork*- this is chosen to be here *just in case* somebody 709c87e3f83SMatt Jacob * forgets to point to it exactly and we index off of trt with 710c87e3f83SMatt Jacob * CAM_LUN_WILDCARD. 711c87e3f83SMatt Jacob */ 712c87e3f83SMatt Jacob tgt_resource_t trt_wildcard; /* wildcard luns */ 713c87e3f83SMatt Jacob tgt_resource_t trt[MPT_MAX_LUNS]; 714c87e3f83SMatt Jacob uint16_t tgt_cmds_allocated; 7155089bd63SMatt Jacob uint16_t els_cmds_allocated; /* FC only */ 716c87e3f83SMatt Jacob 717c87e3f83SMatt Jacob uint16_t timeouts; /* timeout count */ 718c87e3f83SMatt Jacob uint16_t success; /* successes afer timeout */ 7195089bd63SMatt Jacob uint16_t sequence; /* Sequence Number */ 7205089bd63SMatt Jacob uint16_t pad3; 721c87e3f83SMatt Jacob 722e6ebfc7cSMarius Strobl #if 0 723fcd9a16bSMatt Jacob /* Paired port in some dual adapters configurations */ 724b0a2fdeeSScott Long struct mpt_softc * mpt2; 725e6ebfc7cSMarius Strobl #endif 726b0a2fdeeSScott Long 727b0a2fdeeSScott Long /* FW Image management */ 728b0a2fdeeSScott Long uint32_t fw_image_size; 729b0a2fdeeSScott Long uint8_t *fw_image; 730b0a2fdeeSScott Long bus_dma_tag_t fw_dmat; /* DMA tag for firmware image */ 731b0a2fdeeSScott Long bus_dmamap_t fw_dmap; /* DMA map for firmware image */ 7325580ce96SMatt Jacob bus_addr_t fw_phys; /* BusAddr of firmware image */ 733b0a2fdeeSScott Long 7341d558d6aSScott Long /* SAS Topology */ 7351d558d6aSScott Long struct mptsas_portinfo *sas_portinfo; 7361d558d6aSScott Long 737b0a2fdeeSScott Long /* Shutdown Event Handler. */ 738b0a2fdeeSScott Long eventhandler_tag eh; 739b0a2fdeeSScott Long 740ee98c4a5SJohn Baldwin /* Userland management interface. */ 741ee98c4a5SJohn Baldwin struct cdev *cdev; 742ee98c4a5SJohn Baldwin 743b0a2fdeeSScott Long TAILQ_ENTRY(mpt_softc) links; 744b0a2fdeeSScott Long }; 745b0a2fdeeSScott Long 7465089bd63SMatt Jacob static __inline void mpt_assign_serno(struct mpt_softc *, request_t *); 7475089bd63SMatt Jacob 7485089bd63SMatt Jacob static __inline void 7495089bd63SMatt Jacob mpt_assign_serno(struct mpt_softc *mpt, request_t *req) 7505089bd63SMatt Jacob { 7515089bd63SMatt Jacob if ((req->serno = mpt->sequence++) == 0) { 7525089bd63SMatt Jacob req->serno = mpt->sequence++; 7535089bd63SMatt Jacob } 7545089bd63SMatt Jacob } 7555089bd63SMatt Jacob 756c87e3f83SMatt Jacob /***************************** Locking Primitives *****************************/ 757b0a2fdeeSScott Long #define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE 758b0a2fdeeSScott Long #define MPT_LOCK_SETUP(mpt) \ 759b0a2fdeeSScott Long mtx_init(&mpt->mpt_lock, "mpt", NULL, MTX_DEF); \ 760b0a2fdeeSScott Long mpt->mpt_locksetup = 1 761b0a2fdeeSScott Long #define MPT_LOCK_DESTROY(mpt) \ 762b0a2fdeeSScott Long if (mpt->mpt_locksetup) { \ 763b0a2fdeeSScott Long mtx_destroy(&mpt->mpt_lock); \ 764b0a2fdeeSScott Long mpt->mpt_locksetup = 0; \ 765b0a2fdeeSScott Long } 766b0a2fdeeSScott Long 767b0a2fdeeSScott Long #define MPT_LOCK(mpt) mtx_lock(&(mpt)->mpt_lock) 768b0a2fdeeSScott Long #define MPT_UNLOCK(mpt) mtx_unlock(&(mpt)->mpt_lock) 7695089bd63SMatt Jacob #define MPT_OWNED(mpt) mtx_owned(&(mpt)->mpt_lock) 770d0a68c27SMatt Jacob #define MPT_LOCK_ASSERT(mpt) mtx_assert(&(mpt)->mpt_lock, MA_OWNED) 77185c9dd9dSSteven Hartland #define mpt_sleep(mpt, ident, priority, wmesg, sbt) \ 77285c9dd9dSSteven Hartland msleep_sbt(ident, &(mpt)->mpt_lock, priority, wmesg, sbt, 0, 0) 77385c9dd9dSSteven Hartland #define mpt_req_timeout(req, sbt, func, arg) \ 77485c9dd9dSSteven Hartland callout_reset_sbt(&(req)->callout, (sbt), 0, (func), (arg), 0) 775d0a68c27SMatt Jacob #define mpt_req_untimeout(req, func, arg) \ 776d0a68c27SMatt Jacob callout_stop(&(req)->callout) 777363b8ed7SAlexander Kabaev #define mpt_callout_init(mpt, c) \ 778363b8ed7SAlexander Kabaev callout_init_mtx(c, &(mpt)->mpt_lock, 0) 779363b8ed7SAlexander Kabaev #define mpt_callout_drain(mpt, c) \ 780363b8ed7SAlexander Kabaev callout_drain(c) 7815089bd63SMatt Jacob 782b0a2fdeeSScott Long /******************************* Register Access ******************************/ 783b0a2fdeeSScott Long static __inline void mpt_write(struct mpt_softc *, size_t, uint32_t); 784e18e2adaSMarius Strobl static __inline void mpt_write_stream(struct mpt_softc *, size_t, uint32_t); 785b0a2fdeeSScott Long static __inline uint32_t mpt_read(struct mpt_softc *, int); 786b0a2fdeeSScott Long static __inline void mpt_pio_write(struct mpt_softc *, size_t, uint32_t); 787b0a2fdeeSScott Long static __inline uint32_t mpt_pio_read(struct mpt_softc *, int); 788b0a2fdeeSScott Long 789b0a2fdeeSScott Long static __inline void 790b0a2fdeeSScott Long mpt_write(struct mpt_softc *mpt, size_t offset, uint32_t val) 791b0a2fdeeSScott Long { 792b0a2fdeeSScott Long bus_space_write_4(mpt->pci_st, mpt->pci_sh, offset, val); 793b0a2fdeeSScott Long } 794b0a2fdeeSScott Long 795e18e2adaSMarius Strobl static __inline void 796e18e2adaSMarius Strobl mpt_write_stream(struct mpt_softc *mpt, size_t offset, uint32_t val) 797e18e2adaSMarius Strobl { 798e18e2adaSMarius Strobl bus_space_write_stream_4(mpt->pci_st, mpt->pci_sh, offset, val); 799e18e2adaSMarius Strobl } 800e18e2adaSMarius Strobl 801b0a2fdeeSScott Long static __inline uint32_t 802b0a2fdeeSScott Long mpt_read(struct mpt_softc *mpt, int offset) 803b0a2fdeeSScott Long { 804b0a2fdeeSScott Long return (bus_space_read_4(mpt->pci_st, mpt->pci_sh, offset)); 805b0a2fdeeSScott Long } 806b0a2fdeeSScott Long 807b0a2fdeeSScott Long /* 808b0a2fdeeSScott Long * Some operations (e.g. diagnostic register writes while the ARM proccessor 809b0a2fdeeSScott Long * is disabled), must be performed using "PCI pio" operations. On non-PCI 810db4fcadfSConrad Meyer * buses, these operations likely map to normal register accesses. 811b0a2fdeeSScott Long */ 812b0a2fdeeSScott Long static __inline void 813b0a2fdeeSScott Long mpt_pio_write(struct mpt_softc *mpt, size_t offset, uint32_t val) 814b0a2fdeeSScott Long { 81504016bcfSMarius Strobl KASSERT(mpt->pci_pio_reg != NULL, ("no PIO resource")); 816b0a2fdeeSScott Long bus_space_write_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset, val); 817b0a2fdeeSScott Long } 818b0a2fdeeSScott Long 819b0a2fdeeSScott Long static __inline uint32_t 820b0a2fdeeSScott Long mpt_pio_read(struct mpt_softc *mpt, int offset) 821b0a2fdeeSScott Long { 82204016bcfSMarius Strobl KASSERT(mpt->pci_pio_reg != NULL, ("no PIO resource")); 823b0a2fdeeSScott Long return (bus_space_read_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset)); 824b0a2fdeeSScott Long } 825e18e2adaSMarius Strobl 826b0a2fdeeSScott Long /*********************** Reply Frame/Request Management ***********************/ 827b0a2fdeeSScott Long /* Max MPT Reply we are willing to accept (must be power of 2) */ 828444dd2b6SMatt Jacob #define MPT_REPLY_SIZE 256 829b0a2fdeeSScott Long 830c87e3f83SMatt Jacob /* 831c87e3f83SMatt Jacob * Must be less than 16384 in order for target mode to work 832c87e3f83SMatt Jacob */ 833444dd2b6SMatt Jacob #define MPT_MAX_REQUESTS(mpt) 512 834b0a2fdeeSScott Long #define MPT_REQUEST_AREA 512 835444dd2b6SMatt Jacob #define MPT_SENSE_SIZE 32 /* included in MPT_REQUEST_AREA */ 836b0a2fdeeSScott Long #define MPT_REQ_MEM_SIZE(mpt) (MPT_MAX_REQUESTS(mpt) * MPT_REQUEST_AREA) 837b0a2fdeeSScott Long 8385e073106SMatt Jacob #define MPT_CONTEXT_CB_SHIFT (16) 839b0a2fdeeSScott Long #define MPT_CBI(handle) (handle >> MPT_CONTEXT_CB_SHIFT) 840b0a2fdeeSScott Long #define MPT_CBI_TO_HID(cbi) ((cbi) << MPT_CONTEXT_CB_SHIFT) 841b0a2fdeeSScott Long #define MPT_CONTEXT_TO_CBI(x) \ 842b0a2fdeeSScott Long (((x) >> MPT_CONTEXT_CB_SHIFT) & (MPT_NUM_REPLY_HANDLERS - 1)) 8435e073106SMatt Jacob #define MPT_CONTEXT_REQI_MASK 0xFFFF 844c87e3f83SMatt Jacob #define MPT_CONTEXT_TO_REQI(x) ((x) & MPT_CONTEXT_REQI_MASK) 845b0a2fdeeSScott Long 846b0a2fdeeSScott Long /* 847b0a2fdeeSScott Long * Convert a 32bit physical address returned from IOC to an 848b0a2fdeeSScott Long * offset into our reply frame memory or the kvm address needed 849b0a2fdeeSScott Long * to access the data. The returned address is only the low 850b0a2fdeeSScott Long * 32 bits, so mask our base physical address accordingly. 851b0a2fdeeSScott Long */ 852b0a2fdeeSScott Long #define MPT_REPLY_BADDR(x) \ 853b0a2fdeeSScott Long (x << 1) 854b0a2fdeeSScott Long #define MPT_REPLY_OTOV(m, i) \ 855b0a2fdeeSScott Long ((void *)(&m->reply[i])) 856b0a2fdeeSScott Long 857b0a2fdeeSScott Long #define MPT_DUMP_REPLY_FRAME(mpt, reply_frame) \ 858b0a2fdeeSScott Long do { \ 8591d79ca0eSMatt Jacob if (mpt->verbose > MPT_PRT_DEBUG) \ 860b0a2fdeeSScott Long mpt_dump_reply_frame(mpt, reply_frame); \ 861b0a2fdeeSScott Long } while(0) 862b0a2fdeeSScott Long 863b0a2fdeeSScott Long static __inline uint32_t mpt_pop_reply_queue(struct mpt_softc *mpt); 864b0a2fdeeSScott Long static __inline void mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr); 865b0a2fdeeSScott Long 866b0a2fdeeSScott Long /* 867b0a2fdeeSScott Long * Give the reply buffer back to the IOC after we have 868b0a2fdeeSScott Long * finished processing it. 869b0a2fdeeSScott Long */ 870b0a2fdeeSScott Long static __inline void 871b0a2fdeeSScott Long mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr) 872b0a2fdeeSScott Long { 873b0a2fdeeSScott Long mpt_write(mpt, MPT_OFFSET_REPLY_Q, ptr); 874b0a2fdeeSScott Long } 875b0a2fdeeSScott Long 876b0a2fdeeSScott Long /* Get a reply from the IOC */ 877b0a2fdeeSScott Long static __inline uint32_t 878b0a2fdeeSScott Long mpt_pop_reply_queue(struct mpt_softc *mpt) 879b0a2fdeeSScott Long { 880b0a2fdeeSScott Long return mpt_read(mpt, MPT_OFFSET_REPLY_Q); 881b0a2fdeeSScott Long } 882b0a2fdeeSScott Long 8835e073106SMatt Jacob void 8845e073106SMatt Jacob mpt_complete_request_chain(struct mpt_softc *, struct req_queue *, u_int); 8855e073106SMatt Jacob 8865ab13afcSMarius Strobl /************************** Scatter Gather Management **************************/ 887444dd2b6SMatt Jacob /* MPT_RQSL- size of request frame, in bytes */ 8880e0521a1SMatt Jacob #define MPT_RQSL(mpt) (mpt->ioc_facts.RequestFrameSize << 2) 889b0a2fdeeSScott Long 890444dd2b6SMatt Jacob /* MPT_NSGL- how many SG entries can fit in a request frame size */ 891444dd2b6SMatt Jacob #define MPT_NSGL(mpt) (MPT_RQSL(mpt) / sizeof (SGE_IO_UNION)) 892444dd2b6SMatt Jacob 893444dd2b6SMatt Jacob /* MPT_NRFM- how many request frames can fit in each request alloc we make */ 894444dd2b6SMatt Jacob #define MPT_NRFM(mpt) (MPT_REQUEST_AREA / MPT_RQSL(mpt)) 895444dd2b6SMatt Jacob 896444dd2b6SMatt Jacob /* 897444dd2b6SMatt Jacob * MPT_NSGL_FIRST- # of SG elements that can fit after 898444dd2b6SMatt Jacob * an I/O request but still within the request frame. 899444dd2b6SMatt Jacob * Do this safely based upon SGE_IO_UNION. 900444dd2b6SMatt Jacob * 901444dd2b6SMatt Jacob * Note that the first element is *within* the SCSI request. 902444dd2b6SMatt Jacob */ 903b0a2fdeeSScott Long #define MPT_NSGL_FIRST(mpt) \ 904444dd2b6SMatt Jacob ((MPT_RQSL(mpt) - sizeof (MSG_SCSI_IO_REQUEST) + sizeof (SGE_IO_UNION)) / \ 905444dd2b6SMatt Jacob sizeof (SGE_IO_UNION)) 906b0a2fdeeSScott Long 907b0a2fdeeSScott Long /***************************** IOC Initialization *****************************/ 908b0a2fdeeSScott Long int mpt_reset(struct mpt_softc *, int /*reinit*/); 909b0a2fdeeSScott Long 910c87e3f83SMatt Jacob /****************************** Debugging ************************************/ 911b4c618c0SMatt Jacob void mpt_dump_data(struct mpt_softc *, const char *, void *, int); 9120e3b145eSMatt Jacob void mpt_dump_request(struct mpt_softc *, request_t *); 9130e3b145eSMatt Jacob 914b0a2fdeeSScott Long enum { 915b0a2fdeeSScott Long MPT_PRT_ALWAYS, 916b0a2fdeeSScott Long MPT_PRT_FATAL, 917b0a2fdeeSScott Long MPT_PRT_ERROR, 918b0a2fdeeSScott Long MPT_PRT_WARN, 919b0a2fdeeSScott Long MPT_PRT_INFO, 920ac219b98SMatt Jacob MPT_PRT_NEGOTIATION, 921b0a2fdeeSScott Long MPT_PRT_DEBUG, 922c87e3f83SMatt Jacob MPT_PRT_DEBUG1, 923c87e3f83SMatt Jacob MPT_PRT_DEBUG2, 924c87e3f83SMatt Jacob MPT_PRT_DEBUG3, 925444dd2b6SMatt Jacob MPT_PRT_TRACE, 926444dd2b6SMatt Jacob MPT_PRT_NONE=100 927b0a2fdeeSScott Long }; 928b0a2fdeeSScott Long 929b0a2fdeeSScott Long #define mpt_lprt(mpt, level, ...) \ 930b0a2fdeeSScott Long do { \ 9315a62cbcaSRyan Libby if ((level) <= (mpt)->verbose) \ 932b0a2fdeeSScott Long mpt_prt(mpt, __VA_ARGS__); \ 933b0a2fdeeSScott Long } while (0) 934b0a2fdeeSScott Long 93587e255acSMarius Strobl #if 0 936b0a2fdeeSScott Long #define mpt_lprtc(mpt, level, ...) \ 937b0a2fdeeSScott Long do { \ 9385a62cbcaSRyan Libby if ((level) <= (mpt)->verbose) \ 939b0a2fdeeSScott Long mpt_prtc(mpt, __VA_ARGS__); \ 940b0a2fdeeSScott Long } while (0) 94187e255acSMarius Strobl #endif 9424b847ffaSMarius Strobl 943c87e3f83SMatt Jacob void mpt_prt(struct mpt_softc *, const char *, ...) 944c87e3f83SMatt Jacob __printflike(2, 3); 945c87e3f83SMatt Jacob void mpt_prtc(struct mpt_softc *, const char *, ...) 946c87e3f83SMatt Jacob __printflike(2, 3); 947b0a2fdeeSScott Long 948c87e3f83SMatt Jacob /**************************** Target Mode Related ***************************/ 949c87e3f83SMatt Jacob #ifdef INVARIANTS 950c87e3f83SMatt Jacob static __inline request_t * mpt_tag_2_req(struct mpt_softc *, uint32_t); 951c87e3f83SMatt Jacob static __inline request_t * 952c87e3f83SMatt Jacob mpt_tag_2_req(struct mpt_softc *mpt, uint32_t tag) 953c87e3f83SMatt Jacob { 9545e073106SMatt Jacob uint16_t rtg = (tag >> 18); 9554349d278SMarius Strobl KASSERT(rtg < mpt->tgt_cmds_allocated, ("bad tag %d", tag)); 956c87e3f83SMatt Jacob KASSERT(mpt->tgt_cmd_ptrs, ("no cmd backpointer array")); 957c87e3f83SMatt Jacob KASSERT(mpt->tgt_cmd_ptrs[rtg], ("no cmd backpointer")); 958c87e3f83SMatt Jacob return (mpt->tgt_cmd_ptrs[rtg]); 959c87e3f83SMatt Jacob } 960cd23a6e0SMarius Strobl #endif 9615089bd63SMatt Jacob 9625089bd63SMatt Jacob static __inline int 9635089bd63SMatt Jacob mpt_req_on_free_list(struct mpt_softc *, request_t *); 9645089bd63SMatt Jacob static __inline int 9655089bd63SMatt Jacob mpt_req_on_pending_list(struct mpt_softc *, request_t *); 9665089bd63SMatt Jacob 9675089bd63SMatt Jacob /* 9685089bd63SMatt Jacob * Is request on freelist? 9695089bd63SMatt Jacob */ 9705089bd63SMatt Jacob static __inline int 9715089bd63SMatt Jacob mpt_req_on_free_list(struct mpt_softc *mpt, request_t *req) 9725089bd63SMatt Jacob { 9735089bd63SMatt Jacob request_t *lrq; 9745089bd63SMatt Jacob 9755089bd63SMatt Jacob TAILQ_FOREACH(lrq, &mpt->request_free_list, links) { 9765089bd63SMatt Jacob if (lrq == req) { 9775089bd63SMatt Jacob return (1); 9785089bd63SMatt Jacob } 9795089bd63SMatt Jacob } 9805089bd63SMatt Jacob return (0); 9815089bd63SMatt Jacob } 9825089bd63SMatt Jacob 9835089bd63SMatt Jacob /* 9845089bd63SMatt Jacob * Is request on pending list? 9855089bd63SMatt Jacob */ 9865089bd63SMatt Jacob static __inline int 9875089bd63SMatt Jacob mpt_req_on_pending_list(struct mpt_softc *mpt, request_t *req) 9885089bd63SMatt Jacob { 9895089bd63SMatt Jacob request_t *lrq; 9905089bd63SMatt Jacob 9915089bd63SMatt Jacob TAILQ_FOREACH(lrq, &mpt->request_pending_list, links) { 9925089bd63SMatt Jacob if (lrq == req) { 9935089bd63SMatt Jacob return (1); 9945089bd63SMatt Jacob } 9955089bd63SMatt Jacob } 9965089bd63SMatt Jacob return (0); 9975089bd63SMatt Jacob } 9985089bd63SMatt Jacob 999cd23a6e0SMarius Strobl #ifdef INVARIANTS 1000cd23a6e0SMarius Strobl static __inline void 1001cd23a6e0SMarius Strobl mpt_req_spcl(struct mpt_softc *, request_t *, const char *, int); 1002cd23a6e0SMarius Strobl static __inline void 1003cd23a6e0SMarius Strobl mpt_req_not_spcl(struct mpt_softc *, request_t *, const char *, int); 1004cd23a6e0SMarius Strobl 10055089bd63SMatt Jacob /* 10065089bd63SMatt Jacob * Make sure that req *is* part of one of the special lists 10075089bd63SMatt Jacob */ 10085089bd63SMatt Jacob static __inline void 10095089bd63SMatt Jacob mpt_req_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line) 10105089bd63SMatt Jacob { 10115089bd63SMatt Jacob int i; 10125089bd63SMatt Jacob for (i = 0; i < mpt->els_cmds_allocated; i++) { 10135089bd63SMatt Jacob if (req == mpt->els_cmd_ptrs[i]) { 10145089bd63SMatt Jacob return; 10155089bd63SMatt Jacob } 10165089bd63SMatt Jacob } 10175089bd63SMatt Jacob for (i = 0; i < mpt->tgt_cmds_allocated; i++) { 10185089bd63SMatt Jacob if (req == mpt->tgt_cmd_ptrs[i]) { 10195089bd63SMatt Jacob return; 10205089bd63SMatt Jacob } 10215089bd63SMatt Jacob } 10224349d278SMarius Strobl panic("%s(%d): req %p:%u function %x not in els or tgt ptrs", 10235089bd63SMatt Jacob s, line, req, req->serno, 10245089bd63SMatt Jacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function); 10255089bd63SMatt Jacob } 10265089bd63SMatt Jacob 10275089bd63SMatt Jacob /* 10285089bd63SMatt Jacob * Make sure that req is *not* part of one of the special lists. 10295089bd63SMatt Jacob */ 10305089bd63SMatt Jacob static __inline void 10315089bd63SMatt Jacob mpt_req_not_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line) 10325089bd63SMatt Jacob { 10335089bd63SMatt Jacob int i; 10345089bd63SMatt Jacob for (i = 0; i < mpt->els_cmds_allocated; i++) { 10355089bd63SMatt Jacob KASSERT(req != mpt->els_cmd_ptrs[i], 10364349d278SMarius Strobl ("%s(%d): req %p:%u func %x in els ptrs at ioindex %d", 10375089bd63SMatt Jacob s, line, req, req->serno, 10385089bd63SMatt Jacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i)); 10395089bd63SMatt Jacob } 10405089bd63SMatt Jacob for (i = 0; i < mpt->tgt_cmds_allocated; i++) { 10415089bd63SMatt Jacob KASSERT(req != mpt->tgt_cmd_ptrs[i], 10424349d278SMarius Strobl ("%s(%d): req %p:%u func %x in tgt ptrs at ioindex %d", 10435089bd63SMatt Jacob s, line, req, req->serno, 10445089bd63SMatt Jacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i)); 10455089bd63SMatt Jacob } 10465089bd63SMatt Jacob } 1047c87e3f83SMatt Jacob #endif 1048c87e3f83SMatt Jacob 104973651fd1SMatt Jacob /* 105073651fd1SMatt Jacob * Task Management Types, purely for internal consumption 105173651fd1SMatt Jacob */ 1052c87e3f83SMatt Jacob typedef enum { 105367445003SAlexander Motin MPT_QUERY_TASK_SET=1234, 105467445003SAlexander Motin MPT_ABORT_TASK_SET, 1055c87e3f83SMatt Jacob MPT_CLEAR_TASK_SET, 105667445003SAlexander Motin MPT_QUERY_ASYNC_EVENT, 105767445003SAlexander Motin MPT_LOGICAL_UNIT_RESET, 1058c87e3f83SMatt Jacob MPT_TARGET_RESET, 1059c87e3f83SMatt Jacob MPT_CLEAR_ACA, 1060c87e3f83SMatt Jacob MPT_NIL_TMT_VALUE=5678 1061c87e3f83SMatt Jacob } mpt_task_mgmt_t; 1062b0a2fdeeSScott Long 1063b0a2fdeeSScott Long /**************************** Unclassified Routines ***************************/ 1064b0a2fdeeSScott Long void mpt_send_cmd(struct mpt_softc *mpt, request_t *req); 1065b0a2fdeeSScott Long int mpt_recv_handshake_reply(struct mpt_softc *mpt, 1066b0a2fdeeSScott Long size_t reply_len, void *reply); 1067b0a2fdeeSScott Long int mpt_wait_req(struct mpt_softc *mpt, request_t *req, 1068b0a2fdeeSScott Long mpt_req_state_t state, mpt_req_state_t mask, 1069b0a2fdeeSScott Long int sleep_ok, int time_ms); 1070b0a2fdeeSScott Long void mpt_enable_ints(struct mpt_softc *mpt); 1071b0a2fdeeSScott Long void mpt_disable_ints(struct mpt_softc *mpt); 1072b0a2fdeeSScott Long int mpt_attach(struct mpt_softc *mpt); 1073b0a2fdeeSScott Long int mpt_shutdown(struct mpt_softc *mpt); 1074b0a2fdeeSScott Long int mpt_detach(struct mpt_softc *mpt); 1075b0a2fdeeSScott Long int mpt_send_handshake_cmd(struct mpt_softc *mpt, 1076b0a2fdeeSScott Long size_t len, void *cmd); 1077b0a2fdeeSScott Long request_t * mpt_get_request(struct mpt_softc *mpt, int sleep_ok); 1078b0a2fdeeSScott Long void mpt_free_request(struct mpt_softc *mpt, request_t *req); 1079b0a2fdeeSScott Long void mpt_intr(void *arg); 1080b0a2fdeeSScott Long void mpt_check_doorbell(struct mpt_softc *mpt); 1081b0a2fdeeSScott Long void mpt_dump_reply_frame(struct mpt_softc *mpt, 1082b0a2fdeeSScott Long MSG_DEFAULT_REPLY *reply_frame); 1083b0a2fdeeSScott Long 1084b0a2fdeeSScott Long int mpt_issue_cfg_req(struct mpt_softc */*mpt*/, request_t */*req*/, 10851d558d6aSScott Long cfgparms_t *params, 1086b0a2fdeeSScott Long bus_addr_t /*addr*/, bus_size_t/*len*/, 1087b0a2fdeeSScott Long int /*sleep_ok*/, int /*timeout_ms*/); 10881d558d6aSScott Long int mpt_read_extcfg_header(struct mpt_softc *mpt, int PageVersion, 10891d558d6aSScott Long int PageNumber, uint32_t PageAddress, 10901d558d6aSScott Long int ExtPageType, 10911d558d6aSScott Long CONFIG_EXTENDED_PAGE_HEADER *rslt, 10921d558d6aSScott Long int sleep_ok, int timeout_ms); 10931d558d6aSScott Long int mpt_read_extcfg_page(struct mpt_softc *mpt, int Action, 10941d558d6aSScott Long uint32_t PageAddress, 10951d558d6aSScott Long CONFIG_EXTENDED_PAGE_HEADER *hdr, 10961d558d6aSScott Long void *buf, size_t len, int sleep_ok, 10971d558d6aSScott Long int timeout_ms); 1098b0a2fdeeSScott Long int mpt_read_cfg_header(struct mpt_softc *, int /*PageType*/, 1099b0a2fdeeSScott Long int /*PageNumber*/, 1100b0a2fdeeSScott Long uint32_t /*PageAddress*/, 1101b0a2fdeeSScott Long CONFIG_PAGE_HEADER *, 1102b0a2fdeeSScott Long int /*sleep_ok*/, int /*timeout_ms*/); 1103b0a2fdeeSScott Long int mpt_read_cfg_page(struct mpt_softc *t, int /*Action*/, 1104b0a2fdeeSScott Long uint32_t /*PageAddress*/, 1105b0a2fdeeSScott Long CONFIG_PAGE_HEADER *, size_t /*len*/, 1106b0a2fdeeSScott Long int /*sleep_ok*/, int /*timeout_ms*/); 1107b0a2fdeeSScott Long int mpt_write_cfg_page(struct mpt_softc *, int /*Action*/, 1108b0a2fdeeSScott Long uint32_t /*PageAddress*/, 1109b0a2fdeeSScott Long CONFIG_PAGE_HEADER *, size_t /*len*/, 1110b0a2fdeeSScott Long int /*sleep_ok*/, int /*timeout_ms*/); 1111b0a2fdeeSScott Long static __inline int 1112b0a2fdeeSScott Long mpt_read_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress, 1113b0a2fdeeSScott Long CONFIG_PAGE_HEADER *hdr, size_t len, 1114b0a2fdeeSScott Long int sleep_ok, int timeout_ms) 1115b0a2fdeeSScott Long { 1116b0a2fdeeSScott Long return (mpt_read_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT, 1117b0a2fdeeSScott Long PageAddress, hdr, len, sleep_ok, timeout_ms)); 1118b0a2fdeeSScott Long } 1119b0a2fdeeSScott Long 1120b0a2fdeeSScott Long static __inline int 1121b0a2fdeeSScott Long mpt_write_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress, 1122b0a2fdeeSScott Long CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok, 1123b0a2fdeeSScott Long int timeout_ms) 1124b0a2fdeeSScott Long { 1125b0a2fdeeSScott Long return (mpt_write_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT, 1126b0a2fdeeSScott Long PageAddress, hdr, len, sleep_ok, 1127b0a2fdeeSScott Long timeout_ms)); 1128b0a2fdeeSScott Long } 1129e18e2adaSMarius Strobl 11309b631363SMatt Jacob /* mpt_debug.c functions */ 11319b631363SMatt Jacob void mpt_print_reply(void *vmsg); 1132b0a2fdeeSScott Long void mpt_print_db(uint32_t mb); 11339b631363SMatt Jacob void mpt_print_config_reply(void *vmsg); 1134b0a2fdeeSScott Long char *mpt_ioc_diag(uint32_t diag); 1135b0a2fdeeSScott Long void mpt_req_state(mpt_req_state_t state); 11369b631363SMatt Jacob void mpt_print_config_request(void *vmsg); 11379b631363SMatt Jacob void mpt_print_request(void *vmsg); 1138444dd2b6SMatt Jacob void mpt_dump_sgl(SGE_IO_UNION *se, int offset); 1139e18e2adaSMarius Strobl 11409b631363SMatt Jacob #endif /* _MPT_H_ */ 1141