19b631363SMatt Jacob /* $FreeBSD$ */ 2098ca2bdSWarner Losh /*- 39b631363SMatt Jacob * Generic defines for LSI '909 FC adapters. 49b631363SMatt Jacob * FreeBSD Version. 59b631363SMatt Jacob * 69b631363SMatt Jacob * Copyright (c) 2000, 2001 by Greg Ansley 79b631363SMatt Jacob * 89b631363SMatt Jacob * Redistribution and use in source and binary forms, with or without 99b631363SMatt Jacob * modification, are permitted provided that the following conditions 109b631363SMatt Jacob * are met: 119b631363SMatt Jacob * 1. Redistributions of source code must retain the above copyright 129b631363SMatt Jacob * notice immediately at the beginning of the file, without modification, 139b631363SMatt Jacob * this list of conditions, and the following disclaimer. 149b631363SMatt Jacob * 2. The name of the author may not be used to endorse or promote products 159b631363SMatt Jacob * derived from this software without specific prior written permission. 169b631363SMatt Jacob * 179b631363SMatt Jacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 189b631363SMatt Jacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 199b631363SMatt Jacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 209b631363SMatt Jacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 219b631363SMatt Jacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 229b631363SMatt Jacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 239b631363SMatt Jacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 249b631363SMatt Jacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 259b631363SMatt Jacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 269b631363SMatt Jacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 279b631363SMatt Jacob * SUCH DAMAGE. 280b80d21bSMatt Jacob */ 290b80d21bSMatt Jacob /*- 300b80d21bSMatt Jacob * Copyright (c) 2002, 2006 by Matthew Jacob 310b80d21bSMatt Jacob * All rights reserved. 32b0a2fdeeSScott Long * 330b80d21bSMatt Jacob * Redistribution and use in source and binary forms, with or without 340b80d21bSMatt Jacob * modification, are permitted provided that the following conditions are 350b80d21bSMatt Jacob * met: 360b80d21bSMatt Jacob * 1. Redistributions of source code must retain the above copyright 370b80d21bSMatt Jacob * notice, this list of conditions and the following disclaimer. 380b80d21bSMatt Jacob * 2. Redistributions in binary form must reproduce at minimum a disclaimer 390b80d21bSMatt Jacob * substantially similar to the "NO WARRANTY" disclaimer below 400b80d21bSMatt Jacob * ("Disclaimer") and any redistribution must be conditioned upon including 410b80d21bSMatt Jacob * a substantially similar Disclaimer requirement for further binary 420b80d21bSMatt Jacob * redistribution. 430b80d21bSMatt Jacob * 3. Neither the names of the above listed copyright holders nor the names 440b80d21bSMatt Jacob * of any contributors may be used to endorse or promote products derived 450b80d21bSMatt Jacob * from this software without specific prior written permission. 460b80d21bSMatt Jacob * 470b80d21bSMatt Jacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 480b80d21bSMatt Jacob * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 490b80d21bSMatt Jacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 500b80d21bSMatt Jacob * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 510b80d21bSMatt Jacob * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 520b80d21bSMatt Jacob * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 530b80d21bSMatt Jacob * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 540b80d21bSMatt Jacob * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 550b80d21bSMatt Jacob * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 560b80d21bSMatt Jacob * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 570b80d21bSMatt Jacob * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 580b80d21bSMatt Jacob * 590b80d21bSMatt Jacob * Support from Chris Ellsworth in order to make SAS adapters work 600b80d21bSMatt Jacob * is gratefully acknowledged. 61ec5fe39dSMatt Jacob * 62ec5fe39dSMatt Jacob * 63ec5fe39dSMatt Jacob * Support from LSI-Logic has also gone a great deal toward making this a 64ec5fe39dSMatt Jacob * workable subsystem and is gratefully acknowledged. 659b631363SMatt Jacob */ 669b631363SMatt Jacob /* 67b0a2fdeeSScott Long * Copyright (c) 2004, Avid Technology, Inc. and its contributors. 68b0a2fdeeSScott Long * Copyright (c) 2004, 2005 Justin T. Gibbs 69b0a2fdeeSScott Long * Copyright (c) 2005, WHEEL Sp. z o.o. 70b0a2fdeeSScott Long * All rights reserved. 71b0a2fdeeSScott Long * 72b0a2fdeeSScott Long * Redistribution and use in source and binary forms, with or without 73b0a2fdeeSScott Long * modification, are permitted provided that the following conditions are 74b0a2fdeeSScott Long * met: 75b0a2fdeeSScott Long * 1. Redistributions of source code must retain the above copyright 76b0a2fdeeSScott Long * notice, this list of conditions and the following disclaimer. 77b0a2fdeeSScott Long * 2. Redistributions in binary form must reproduce at minimum a disclaimer 78b0a2fdeeSScott Long * substantially similar to the "NO WARRANTY" disclaimer below 79b0a2fdeeSScott Long * ("Disclaimer") and any redistribution must be conditioned upon including 80b0a2fdeeSScott Long * a substantially similar Disclaimer requirement for further binary 81b0a2fdeeSScott Long * redistribution. 82286e947fSJustin T. Gibbs * 3. Neither the names of the above listed copyright holders nor the names 83286e947fSJustin T. Gibbs * of any contributors may be used to endorse or promote products derived 84286e947fSJustin T. Gibbs * from this software without specific prior written permission. 85b0a2fdeeSScott Long * 86b0a2fdeeSScott Long * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 87b0a2fdeeSScott Long * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 88b0a2fdeeSScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 89b0a2fdeeSScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 90b0a2fdeeSScott Long * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 91b0a2fdeeSScott Long * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 92b0a2fdeeSScott Long * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 93b0a2fdeeSScott Long * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 94b0a2fdeeSScott Long * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 95b0a2fdeeSScott Long * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 96b0a2fdeeSScott Long * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 979b631363SMatt Jacob */ 989b631363SMatt Jacob 999b631363SMatt Jacob #ifndef _MPT_H_ 1009b631363SMatt Jacob #define _MPT_H_ 101b0a2fdeeSScott Long 102b0a2fdeeSScott Long /********************************* OS Includes ********************************/ 103b0a2fdeeSScott Long #include <sys/types.h> 104b0a2fdeeSScott Long #include <sys/param.h> 105b0a2fdeeSScott Long #include <sys/systm.h> 106b0a2fdeeSScott Long #include <sys/endian.h> 107b0a2fdeeSScott Long #include <sys/eventhandler.h> 108b0a2fdeeSScott Long #if __FreeBSD_version < 500000 109b0a2fdeeSScott Long #include <sys/kernel.h> 110b0a2fdeeSScott Long #include <sys/queue.h> 111b0a2fdeeSScott Long #include <sys/malloc.h> 112b0a2fdeeSScott Long #else 113b0a2fdeeSScott Long #include <sys/lock.h> 114b0a2fdeeSScott Long #include <sys/kernel.h> 115b0a2fdeeSScott Long #include <sys/queue.h> 116b0a2fdeeSScott Long #include <sys/malloc.h> 117b0a2fdeeSScott Long #include <sys/mutex.h> 118b0a2fdeeSScott Long #include <sys/condvar.h> 119b0a2fdeeSScott Long #endif 120b0a2fdeeSScott Long #include <sys/proc.h> 121b0a2fdeeSScott Long #include <sys/bus.h> 122b0a2fdeeSScott Long #include <sys/module.h> 123b0a2fdeeSScott Long 124b0a2fdeeSScott Long #include <machine/cpu.h> 125b0a2fdeeSScott Long #include <machine/resource.h> 126b0a2fdeeSScott Long 127c87e3f83SMatt Jacob #if __FreeBSD_version < 500000 128c87e3f83SMatt Jacob #include <machine/bus.h> 1296dea56baSMatt Jacob #include <machine/clock.h> 130c87e3f83SMatt Jacob #endif 131c87e3f83SMatt Jacob 132b0a2fdeeSScott Long #include <sys/rman.h> 133b0a2fdeeSScott Long 134444dd2b6SMatt Jacob #if __FreeBSD_version < 500000 135444dd2b6SMatt Jacob #include <pci/pcireg.h> 136444dd2b6SMatt Jacob #include <pci/pcivar.h> 137444dd2b6SMatt Jacob #else 138444dd2b6SMatt Jacob #include <dev/pci/pcireg.h> 139444dd2b6SMatt Jacob #include <dev/pci/pcivar.h> 140444dd2b6SMatt Jacob #endif 141444dd2b6SMatt Jacob 142444dd2b6SMatt Jacob #include <machine/bus.h> 143b0a2fdeeSScott Long #include "opt_ddb.h" 144b0a2fdeeSScott Long 145b0a2fdeeSScott Long /**************************** Register Definitions ****************************/ 146b0a2fdeeSScott Long #include <dev/mpt/mpt_reg.h> 147b0a2fdeeSScott Long 148b0a2fdeeSScott Long /******************************* MPI Definitions ******************************/ 149b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_type.h> 150b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi.h> 151b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_cnfg.h> 152b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_ioc.h> 153b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_raid.h> 154b0a2fdeeSScott Long 155b0a2fdeeSScott Long /* XXX For mpt_debug.c */ 156b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_init.h> 157b0a2fdeeSScott Long 1580e0521a1SMatt Jacob #define MPT_S64_2_SCALAR(y) ((((int64_t)y.High) << 32) | (y.Low)) 1590e0521a1SMatt Jacob #define MPT_U64_2_SCALAR(y) ((((uint64_t)y.High) << 32) | (y.Low)) 1600e0521a1SMatt Jacob 161b0a2fdeeSScott Long /****************************** Misc Definitions ******************************/ 1629b631363SMatt Jacob #define MPT_OK (0) 1639b631363SMatt Jacob #define MPT_FAIL (0x10000) 1649b631363SMatt Jacob 165b0a2fdeeSScott Long #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array)) 1669b631363SMatt Jacob 167c87e3f83SMatt Jacob #define MPT_ROLE_NONE 0 168c87e3f83SMatt Jacob #define MPT_ROLE_INITIATOR 1 169c87e3f83SMatt Jacob #define MPT_ROLE_TARGET 2 170c87e3f83SMatt Jacob #define MPT_ROLE_BOTH 3 171c87e3f83SMatt Jacob #define MPT_ROLE_DEFAULT MPT_ROLE_INITIATOR 172c87e3f83SMatt Jacob 173b0a2fdeeSScott Long /**************************** Forward Declarations ****************************/ 174b0a2fdeeSScott Long struct mpt_softc; 175b0a2fdeeSScott Long struct mpt_personality; 176b0a2fdeeSScott Long typedef struct req_entry request_t; 1779b631363SMatt Jacob 178b0a2fdeeSScott Long /************************* Personality Module Support *************************/ 179b0a2fdeeSScott Long typedef int mpt_load_handler_t(struct mpt_personality *); 180b0a2fdeeSScott Long typedef int mpt_probe_handler_t(struct mpt_softc *); 181b0a2fdeeSScott Long typedef int mpt_attach_handler_t(struct mpt_softc *); 182c87e3f83SMatt Jacob typedef int mpt_enable_handler_t(struct mpt_softc *); 183a7303be1SMatt Jacob typedef void mpt_ready_handler_t(struct mpt_softc *); 184b0a2fdeeSScott Long typedef int mpt_event_handler_t(struct mpt_softc *, request_t *, 185b0a2fdeeSScott Long MSG_EVENT_NOTIFY_REPLY *); 186b0a2fdeeSScott Long typedef void mpt_reset_handler_t(struct mpt_softc *, int /*type*/); 187b0a2fdeeSScott Long /* XXX Add return value and use for veto? */ 188b0a2fdeeSScott Long typedef void mpt_shutdown_handler_t(struct mpt_softc *); 189b0a2fdeeSScott Long typedef void mpt_detach_handler_t(struct mpt_softc *); 190b0a2fdeeSScott Long typedef int mpt_unload_handler_t(struct mpt_personality *); 191b0a2fdeeSScott Long 192b0a2fdeeSScott Long struct mpt_personality 193b0a2fdeeSScott Long { 194b0a2fdeeSScott Long const char *name; 195b0a2fdeeSScott Long uint32_t id; /* Assigned identifier. */ 196b0a2fdeeSScott Long u_int use_count; /* Instances using personality*/ 197b0a2fdeeSScott Long mpt_load_handler_t *load; /* configure personailty */ 198b0a2fdeeSScott Long #define MPT_PERS_FIRST_HANDLER(pers) (&(pers)->load) 199b0a2fdeeSScott Long mpt_probe_handler_t *probe; /* configure personailty */ 200b0a2fdeeSScott Long mpt_attach_handler_t *attach; /* initialize device instance */ 201c87e3f83SMatt Jacob mpt_enable_handler_t *enable; /* enable device */ 202a7303be1SMatt Jacob mpt_ready_handler_t *ready; /* final open for business */ 203b0a2fdeeSScott Long mpt_event_handler_t *event; /* Handle MPI event. */ 204b0a2fdeeSScott Long mpt_reset_handler_t *reset; /* Re-init after reset. */ 205b0a2fdeeSScott Long mpt_shutdown_handler_t *shutdown; /* Shutdown instance. */ 206b0a2fdeeSScott Long mpt_detach_handler_t *detach; /* release device instance */ 207b0a2fdeeSScott Long mpt_unload_handler_t *unload; /* Shutdown personality */ 208b0a2fdeeSScott Long #define MPT_PERS_LAST_HANDLER(pers) (&(pers)->unload) 2099b631363SMatt Jacob }; 2109b631363SMatt Jacob 211b0a2fdeeSScott Long int mpt_modevent(module_t, int, void *); 2129b631363SMatt Jacob 213b0a2fdeeSScott Long /* Maximum supported number of personalities. */ 214b0a2fdeeSScott Long #define MPT_MAX_PERSONALITIES (15) 2159b631363SMatt Jacob 216b0a2fdeeSScott Long #define MPT_PERSONALITY_DEPEND(name, dep, vmin, vpref, vmax) \ 217b0a2fdeeSScott Long MODULE_DEPEND(name, dep, vmin, vpref, vmax) 218b0a2fdeeSScott Long 219b0a2fdeeSScott Long #define DECLARE_MPT_PERSONALITY(name, order) \ 220b0a2fdeeSScott Long static moduledata_t name##_mod = { \ 221b0a2fdeeSScott Long #name, mpt_modevent, &name##_personality \ 222b0a2fdeeSScott Long }; \ 223b0a2fdeeSScott Long DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, order); \ 224b0a2fdeeSScott Long MODULE_VERSION(name, 1); \ 225b0a2fdeeSScott Long MPT_PERSONALITY_DEPEND(name, mpt_core, 1, 1, 1) 226b0a2fdeeSScott Long 227b0a2fdeeSScott Long /******************************* Bus DMA Support ******************************/ 228b0a2fdeeSScott Long /* XXX Need to update bus_dmamap_sync to take a range argument. */ 229b0a2fdeeSScott Long #define bus_dmamap_sync_range(dma_tag, dmamap, offset, len, op) \ 230b0a2fdeeSScott Long bus_dmamap_sync(dma_tag, dmamap, op) 231b0a2fdeeSScott Long 232b0a2fdeeSScott Long #if __FreeBSD_version >= 501102 233b0a2fdeeSScott Long #define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary, \ 234b0a2fdeeSScott Long lowaddr, highaddr, filter, filterarg, \ 235b0a2fdeeSScott Long maxsize, nsegments, maxsegsz, flags, \ 236b0a2fdeeSScott Long dma_tagp) \ 237b0a2fdeeSScott Long bus_dma_tag_create(parent_tag, alignment, boundary, \ 238b0a2fdeeSScott Long lowaddr, highaddr, filter, filterarg, \ 239b0a2fdeeSScott Long maxsize, nsegments, maxsegsz, flags, \ 240b0a2fdeeSScott Long busdma_lock_mutex, &Giant, \ 241b0a2fdeeSScott Long dma_tagp) 242b0a2fdeeSScott Long #else 243b0a2fdeeSScott Long #define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary, \ 244b0a2fdeeSScott Long lowaddr, highaddr, filter, filterarg, \ 245b0a2fdeeSScott Long maxsize, nsegments, maxsegsz, flags, \ 246b0a2fdeeSScott Long dma_tagp) \ 247b0a2fdeeSScott Long bus_dma_tag_create(parent_tag, alignment, boundary, \ 248b0a2fdeeSScott Long lowaddr, highaddr, filter, filterarg, \ 249b0a2fdeeSScott Long maxsize, nsegments, maxsegsz, flags, \ 250b0a2fdeeSScott Long dma_tagp) 251b0a2fdeeSScott Long #endif 252b0a2fdeeSScott Long 253b0a2fdeeSScott Long struct mpt_map_info { 254b0a2fdeeSScott Long struct mpt_softc *mpt; 255b0a2fdeeSScott Long int error; 256b0a2fdeeSScott Long uint32_t phys; 257b0a2fdeeSScott Long }; 258b0a2fdeeSScott Long 259b0a2fdeeSScott Long void mpt_map_rquest(void *, bus_dma_segment_t *, int, int); 260b0a2fdeeSScott Long 261b0a2fdeeSScott Long /**************************** Kernel Thread Support ***************************/ 262b0a2fdeeSScott Long #if __FreeBSD_version > 500005 263b0a2fdeeSScott Long #define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 264b0a2fdeeSScott Long kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) 265b0a2fdeeSScott Long #else 266b0a2fdeeSScott Long #define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 267b0a2fdeeSScott Long kthread_create(func, farg, proc_ptr, fmtstr, arg) 268b0a2fdeeSScott Long #endif 269b0a2fdeeSScott Long 270b0a2fdeeSScott Long /****************************** Timer Facilities ******************************/ 271b0a2fdeeSScott Long #if __FreeBSD_version > 500000 272b0a2fdeeSScott Long #define mpt_callout_init(c) callout_init(c, /*mpsafe*/0); 273b0a2fdeeSScott Long #else 274b0a2fdeeSScott Long #define mpt_callout_init(c) callout_init(c); 275b0a2fdeeSScott Long #endif 276b0a2fdeeSScott Long 277b0a2fdeeSScott Long /********************************** Endianess *********************************/ 2780e0521a1SMatt Jacob #define MPT_2_HOST64(ptr, tag) ptr->tag = le64toh(ptr->tag) 2790e0521a1SMatt Jacob #define MPT_2_HOST32(ptr, tag) ptr->tag = le32toh(ptr->tag) 2800e0521a1SMatt Jacob #define MPT_2_HOST16(ptr, tag) ptr->tag = le16toh(ptr->tag) 281b0a2fdeeSScott Long 2820e0521a1SMatt Jacob #define HOST_2_MPT64(ptr, tag) ptr->tag = htole64(ptr->tag) 2830e0521a1SMatt Jacob #define HOST_2_MPT32(ptr, tag) ptr->tag = htole32(ptr->tag) 2840e0521a1SMatt Jacob #define HOST_2_MPT16(ptr, tag) ptr->tag = htole16(ptr->tag) 2850e0521a1SMatt Jacob 2860e0521a1SMatt Jacob #if _BYTE_ORDER == _LITTLE_ENDIAN 2870e0521a1SMatt Jacob #define mpt2host_sge_simple_union(x) do { ; } while (0) 2880e0521a1SMatt Jacob #define mpt2host_iocfacts_reply(x) do { ; } while (0) 2890e0521a1SMatt Jacob #define mpt2host_portfacts_reply(x) do { ; } while (0) 2900e0521a1SMatt Jacob #define mpt2host_config_page_ioc2(x) do { ; } while (0) 2910e0521a1SMatt Jacob #define mpt2host_config_page_raid_vol_0(x) do { ; } while (0) 2920e0521a1SMatt Jacob #define mpt2host_mpi_raid_vol_indicator(x) do { ; } while (0) 2930e0521a1SMatt Jacob #else 2940e0521a1SMatt Jacob void mpt2host_sge_simple_union(SGE_SIMPLE_UNION *); 2950e0521a1SMatt Jacob void mpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *); 2960e0521a1SMatt Jacob void mpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *); 2970e0521a1SMatt Jacob void mpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *); 2980e0521a1SMatt Jacob void mpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *); 2990e0521a1SMatt Jacob void mpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *); 3000e0521a1SMatt Jacob #endif 301b0a2fdeeSScott Long 302b0a2fdeeSScott Long /**************************** MPI Transaction State ***************************/ 303b0a2fdeeSScott Long typedef enum { 3045e073106SMatt Jacob REQ_STATE_NIL = 0x00, 3055e073106SMatt Jacob REQ_STATE_FREE = 0x01, 3065e073106SMatt Jacob REQ_STATE_ALLOCATED = 0x02, 3075e073106SMatt Jacob REQ_STATE_QUEUED = 0x04, 3085e073106SMatt Jacob REQ_STATE_DONE = 0x08, 3095e073106SMatt Jacob REQ_STATE_TIMEDOUT = 0x10, 3105e073106SMatt Jacob REQ_STATE_NEED_WAKEUP = 0x20, 3115e073106SMatt Jacob REQ_STATE_LOCKED = 0x80, /* can't be freed */ 312b0a2fdeeSScott Long REQ_STATE_MASK = 0xFF 313b0a2fdeeSScott Long } mpt_req_state_t; 314b0a2fdeeSScott Long 315b0a2fdeeSScott Long struct req_entry { 316b0a2fdeeSScott Long TAILQ_ENTRY(req_entry) links; /* Pointer to next in list */ 317b0a2fdeeSScott Long mpt_req_state_t state; /* Request State Information */ 318b0a2fdeeSScott Long uint16_t index; /* Index of this entry */ 319b0a2fdeeSScott Long uint16_t IOCStatus; /* Completion status */ 3205089bd63SMatt Jacob uint16_t ResponseCode; /* TMF Reponse Code */ 3215089bd63SMatt Jacob uint16_t serno; /* serial number */ 322b0a2fdeeSScott Long union ccb *ccb; /* CAM request */ 323b0a2fdeeSScott Long void *req_vbuf; /* Virtual Address of Entry */ 324b0a2fdeeSScott Long void *sense_vbuf; /* Virtual Address of sense data */ 325b0a2fdeeSScott Long bus_addr_t req_pbuf; /* Physical Address of Entry */ 326b0a2fdeeSScott Long bus_addr_t sense_pbuf; /* Physical Address of sense data */ 327fcd9a16bSMatt Jacob bus_dmamap_t dmap; /* DMA map for data buffers */ 328444dd2b6SMatt Jacob struct req_entry *chain; /* for SGE overallocations */ 329b0a2fdeeSScott Long }; 330b0a2fdeeSScott Long 331c87e3f83SMatt Jacob /**************************** MPI Target State Info ***************************/ 332c87e3f83SMatt Jacob 333c87e3f83SMatt Jacob typedef struct { 334c87e3f83SMatt Jacob uint32_t reply_desc; /* current reply descriptor */ 335c87e3f83SMatt Jacob uint32_t resid; /* current data residual */ 336c87e3f83SMatt Jacob uint32_t bytes_xfered; /* current relative offset */ 337c87e3f83SMatt Jacob union ccb *ccb; /* pointer to currently active ccb */ 338c87e3f83SMatt Jacob request_t *req; /* pointer to currently active assist request */ 33973651fd1SMatt Jacob uint32_t 34073651fd1SMatt Jacob is_local : 1, 34173651fd1SMatt Jacob nxfers : 31; 3425e073106SMatt Jacob uint32_t tag_id; 343c87e3f83SMatt Jacob enum { 344c87e3f83SMatt Jacob TGT_STATE_NIL, 3455e073106SMatt Jacob TGT_STATE_LOADING, 346c87e3f83SMatt Jacob TGT_STATE_LOADED, 347c87e3f83SMatt Jacob TGT_STATE_IN_CAM, 348c87e3f83SMatt Jacob TGT_STATE_SETTING_UP_FOR_DATA, 349c87e3f83SMatt Jacob TGT_STATE_MOVING_DATA, 350c87e3f83SMatt Jacob TGT_STATE_MOVING_DATA_AND_STATUS, 351c87e3f83SMatt Jacob TGT_STATE_SENDING_STATUS 352c87e3f83SMatt Jacob } state; 353c87e3f83SMatt Jacob } mpt_tgt_state_t; 354c87e3f83SMatt Jacob 355c87e3f83SMatt Jacob /* 356c87e3f83SMatt Jacob * When we get an incoming command it has its own tag which is called the 357c87e3f83SMatt Jacob * IoIndex. This is the value we gave that particular command buffer when 358c87e3f83SMatt Jacob * we originally assigned it. It's just a number, really. The FC card uses 359c87e3f83SMatt Jacob * it as an RX_ID. We can use it to index into mpt->tgt_cmd_ptrs, which 360c87e3f83SMatt Jacob * contains pointers the request_t structures related to that IoIndex. 361c87e3f83SMatt Jacob * 362c87e3f83SMatt Jacob * What *we* do is construct a tag out of the index for the target command 363c87e3f83SMatt Jacob * which owns the incoming ATIO plus a rolling sequence number. 364c87e3f83SMatt Jacob */ 365c87e3f83SMatt Jacob #define MPT_MAKE_TAGID(mpt, req, ioindex) \ 3665e073106SMatt Jacob ((ioindex << 18) | (((mpt->sequence++) & 0x3f) << 12) | (req->index & 0xfff)) 367c87e3f83SMatt Jacob 368c87e3f83SMatt Jacob #ifdef INVARIANTS 369c87e3f83SMatt Jacob #define MPT_TAG_2_REQ(a, b) mpt_tag_2_req(a, (uint32_t) b) 370c87e3f83SMatt Jacob #else 3715e073106SMatt Jacob #define MPT_TAG_2_REQ(mpt, tag) mpt->tgt_cmd_ptrs[tag >> 18] 372c87e3f83SMatt Jacob #endif 373c87e3f83SMatt Jacob 374c87e3f83SMatt Jacob #define MPT_TGT_STATE(mpt, req) ((mpt_tgt_state_t *) \ 375c87e3f83SMatt Jacob (&((uint8_t *)req->req_vbuf)[MPT_RQSL(mpt) - sizeof (mpt_tgt_state_t)])) 376c87e3f83SMatt Jacob 377c87e3f83SMatt Jacob STAILQ_HEAD(mpt_hdr_stailq, ccb_hdr); 378c87e3f83SMatt Jacob #define MPT_MAX_LUNS 256 379c87e3f83SMatt Jacob typedef struct { 380c87e3f83SMatt Jacob struct mpt_hdr_stailq atios; 381c87e3f83SMatt Jacob struct mpt_hdr_stailq inots; 382c87e3f83SMatt Jacob int enabled; 383c87e3f83SMatt Jacob } tgt_resource_t; 3845089bd63SMatt Jacob #define MPT_MAX_ELS 64 385c87e3f83SMatt Jacob 386b0a2fdeeSScott Long /**************************** Handler Registration ****************************/ 387b0a2fdeeSScott Long /* 388b0a2fdeeSScott Long * Global table of registered reply handlers. The 389b0a2fdeeSScott Long * handler is indicated by byte 3 of the request 390b0a2fdeeSScott Long * index submitted to the IOC. This allows the 391b0a2fdeeSScott Long * driver core to perform generic processing without 392b0a2fdeeSScott Long * any knowledge of per-personality behavior. 393b0a2fdeeSScott Long * 394b0a2fdeeSScott Long * MPT_NUM_REPLY_HANDLERS must be a power of 2 395b0a2fdeeSScott Long * to allow the easy generation of a mask. 396b0a2fdeeSScott Long * 397b0a2fdeeSScott Long * The handler offsets used by the core are hard coded 398b0a2fdeeSScott Long * allowing faster code generation when assigning a handler 399b0a2fdeeSScott Long * to a request. All "personalities" must use the 400b0a2fdeeSScott Long * the handler registration mechanism. 401b0a2fdeeSScott Long * 402b0a2fdeeSScott Long * The IOC handlers that are rarely executed are placed 403b0a2fdeeSScott Long * at the tail of the table to make it more likely that 404b0a2fdeeSScott Long * all commonly executed handlers fit in a single cache 405b0a2fdeeSScott Long * line. 406b0a2fdeeSScott Long */ 407c87e3f83SMatt Jacob #define MPT_NUM_REPLY_HANDLERS (32) 408b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_EVENTS MPT_CBI_TO_HID(0) 409b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_CONFIG MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-1) 410b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_HANDSHAKE MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-2) 411b0a2fdeeSScott Long typedef int mpt_reply_handler_t(struct mpt_softc *mpt, request_t *request, 412c87e3f83SMatt Jacob uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame); 413b0a2fdeeSScott Long typedef union { 414b0a2fdeeSScott Long mpt_reply_handler_t *reply_handler; 415b0a2fdeeSScott Long } mpt_handler_t; 416b0a2fdeeSScott Long 417b0a2fdeeSScott Long typedef enum { 418b0a2fdeeSScott Long MPT_HANDLER_REPLY, 419b0a2fdeeSScott Long MPT_HANDLER_EVENT, 420b0a2fdeeSScott Long MPT_HANDLER_RESET, 421b0a2fdeeSScott Long MPT_HANDLER_SHUTDOWN 422b0a2fdeeSScott Long } mpt_handler_type; 423b0a2fdeeSScott Long 424b0a2fdeeSScott Long struct mpt_handler_record 425b0a2fdeeSScott Long { 426b0a2fdeeSScott Long LIST_ENTRY(mpt_handler_record) links; 427b0a2fdeeSScott Long mpt_handler_t handler; 428b0a2fdeeSScott Long }; 429b0a2fdeeSScott Long 430b0a2fdeeSScott Long LIST_HEAD(mpt_handler_list, mpt_handler_record); 4319b631363SMatt Jacob 4329b631363SMatt Jacob /* 433b0a2fdeeSScott Long * The handler_id is currently unused but would contain the 434b0a2fdeeSScott Long * handler ID used in the MsgContext field to allow direction 435b0a2fdeeSScott Long * of replies to the handler. Registrations that don't require 436b0a2fdeeSScott Long * a handler id can pass in NULL for the handler_id. 437b0a2fdeeSScott Long * 438b0a2fdeeSScott Long * Deregistrations for handlers without a handler id should 439b0a2fdeeSScott Long * pass in MPT_HANDLER_ID_NONE. 4409b631363SMatt Jacob */ 441b0a2fdeeSScott Long #define MPT_HANDLER_ID_NONE (0xFFFFFFFF) 442b0a2fdeeSScott Long int mpt_register_handler(struct mpt_softc *, mpt_handler_type, 443b0a2fdeeSScott Long mpt_handler_t, uint32_t *); 444b0a2fdeeSScott Long int mpt_deregister_handler(struct mpt_softc *, mpt_handler_type, 445b0a2fdeeSScott Long mpt_handler_t, uint32_t); 4469b631363SMatt Jacob 447b0a2fdeeSScott Long /******************* Per-Controller Instance Data Structures ******************/ 448b0a2fdeeSScott Long TAILQ_HEAD(req_queue, req_entry); 4499b631363SMatt Jacob 450b0a2fdeeSScott Long /* Structure for saving proper values for modifyable PCI config registers */ 451b0a2fdeeSScott Long struct mpt_pci_cfg { 452b0a2fdeeSScott Long uint16_t Command; 453b0a2fdeeSScott Long uint16_t LatencyTimer_LineSize; 454b0a2fdeeSScott Long uint32_t IO_BAR; 455b0a2fdeeSScott Long uint32_t Mem0_BAR[2]; 456b0a2fdeeSScott Long uint32_t Mem1_BAR[2]; 457b0a2fdeeSScott Long uint32_t ROM_BAR; 458b0a2fdeeSScott Long uint8_t IntLine; 459b0a2fdeeSScott Long uint32_t PMCSR; 4609b631363SMatt Jacob }; 4619b631363SMatt Jacob 462b0a2fdeeSScott Long typedef enum { 463b0a2fdeeSScott Long MPT_RVF_NONE = 0x0, 464b0a2fdeeSScott Long MPT_RVF_ACTIVE = 0x1, 465b0a2fdeeSScott Long MPT_RVF_ANNOUNCED = 0x2, 466b0a2fdeeSScott Long MPT_RVF_UP2DATE = 0x4, 467b0a2fdeeSScott Long MPT_RVF_REFERENCED = 0x8, 468b0a2fdeeSScott Long MPT_RVF_WCE_CHANGED = 0x10 469b0a2fdeeSScott Long } mpt_raid_volume_flags; 470b0a2fdeeSScott Long 471b0a2fdeeSScott Long struct mpt_raid_volume { 472b0a2fdeeSScott Long CONFIG_PAGE_RAID_VOL_0 *config_page; 473b0a2fdeeSScott Long MPI_RAID_VOL_INDICATOR sync_progress; 474b0a2fdeeSScott Long mpt_raid_volume_flags flags; 4750e3b145eSMatt Jacob u_int quiesced_disks; 4769b631363SMatt Jacob }; 4779b631363SMatt Jacob 478b0a2fdeeSScott Long typedef enum { 479b0a2fdeeSScott Long MPT_RDF_NONE = 0x00, 480b0a2fdeeSScott Long MPT_RDF_ACTIVE = 0x01, 481b0a2fdeeSScott Long MPT_RDF_ANNOUNCED = 0x02, 482b0a2fdeeSScott Long MPT_RDF_UP2DATE = 0x04, 483b0a2fdeeSScott Long MPT_RDF_REFERENCED = 0x08, 484b0a2fdeeSScott Long MPT_RDF_QUIESCING = 0x10, 485b0a2fdeeSScott Long MPT_RDF_QUIESCED = 0x20 486b0a2fdeeSScott Long } mpt_raid_disk_flags; 4879b631363SMatt Jacob 488b0a2fdeeSScott Long struct mpt_raid_disk { 489b0a2fdeeSScott Long CONFIG_PAGE_RAID_PHYS_DISK_0 config_page; 490b0a2fdeeSScott Long struct mpt_raid_volume *volume; 491b0a2fdeeSScott Long u_int member_number; 492b0a2fdeeSScott Long u_int pass_thru_active; 493b0a2fdeeSScott Long mpt_raid_disk_flags flags; 4949b631363SMatt Jacob }; 4959b631363SMatt Jacob 496b0a2fdeeSScott Long struct mpt_evtf_record { 497b0a2fdeeSScott Long MSG_EVENT_NOTIFY_REPLY reply; 498b0a2fdeeSScott Long uint32_t context; 499b0a2fdeeSScott Long LIST_ENTRY(mpt_evtf_record) links; 5009b631363SMatt Jacob }; 5019b631363SMatt Jacob 502b0a2fdeeSScott Long LIST_HEAD(mpt_evtf_list, mpt_evtf_record); 5039b631363SMatt Jacob 504b0a2fdeeSScott Long struct mpt_softc { 505b0a2fdeeSScott Long device_t dev; 506b0a2fdeeSScott Long #if __FreeBSD_version < 500000 507b0a2fdeeSScott Long uint32_t mpt_islocked; 5085089bd63SMatt Jacob int mpt_splsaved; 509b0a2fdeeSScott Long #else 510b0a2fdeeSScott Long struct mtx mpt_lock; 5115089bd63SMatt Jacob int mpt_locksetup; 512b0a2fdeeSScott Long #endif 513b0a2fdeeSScott Long uint32_t mpt_pers_mask; 514b4c618c0SMatt Jacob uint32_t 5150e0521a1SMatt Jacob : 8, 516c87e3f83SMatt Jacob unit : 8, 5170e0521a1SMatt Jacob : 1, 5180e0521a1SMatt Jacob fw_uploaded : 1, 519804625eeSMatt Jacob msi_enable : 1, 520c87e3f83SMatt Jacob twildcard : 1, 521c87e3f83SMatt Jacob tenabled : 1, 522b4c618c0SMatt Jacob do_cfg_role : 1, 5231d79ca0eSMatt Jacob raid_enabled : 1, 524b0a2fdeeSScott Long raid_mwce_set : 1, 525b0a2fdeeSScott Long getreqwaiter : 1, 526b0a2fdeeSScott Long shutdwn_raid : 1, 527b0a2fdeeSScott Long shutdwn_recovery: 1, 528b0a2fdeeSScott Long outofbeer : 1, 529b0a2fdeeSScott Long disabled : 1, 5305580ce96SMatt Jacob is_spi : 1, 531c87e3f83SMatt Jacob is_sas : 1, 532c87e3f83SMatt Jacob is_fc : 1; 5339b631363SMatt Jacob 534b4c618c0SMatt Jacob u_int cfg_role; 535b4c618c0SMatt Jacob u_int role; /* role: none, ini, target, both */ 536b4c618c0SMatt Jacob 537b0a2fdeeSScott Long u_int verbose; 5389b631363SMatt Jacob 539b0a2fdeeSScott Long /* 540b0a2fdeeSScott Long * IOC Facts 541b0a2fdeeSScott Long */ 5420e0521a1SMatt Jacob MSG_IOC_FACTS_REPLY ioc_facts; 5439b631363SMatt Jacob 544b0a2fdeeSScott Long /* 545b0a2fdeeSScott Long * Port Facts 546b0a2fdeeSScott Long */ 5470e0521a1SMatt Jacob MSG_PORT_FACTS_REPLY * port_facts; 5480e0521a1SMatt Jacob #define mpt_ini_id port_facts[0].PortSCSIID 5490e0521a1SMatt Jacob #define mpt_max_tgtcmds port_facts[0].MaxPostedCmdBuffers 5509b631363SMatt Jacob 551b0a2fdeeSScott Long /* 552b0a2fdeeSScott Long * Device Configuration Information 553b0a2fdeeSScott Long */ 554b0a2fdeeSScott Long union { 555b0a2fdeeSScott Long struct mpt_spi_cfg { 556b0a2fdeeSScott Long CONFIG_PAGE_SCSI_PORT_0 _port_page0; 557b0a2fdeeSScott Long CONFIG_PAGE_SCSI_PORT_1 _port_page1; 558b0a2fdeeSScott Long CONFIG_PAGE_SCSI_PORT_2 _port_page2; 559b0a2fdeeSScott Long CONFIG_PAGE_SCSI_DEVICE_0 _dev_page0[16]; 560b0a2fdeeSScott Long CONFIG_PAGE_SCSI_DEVICE_1 _dev_page1[16]; 561b0a2fdeeSScott Long uint16_t _tag_enable; 562b0a2fdeeSScott Long uint16_t _disc_enable; 563b0a2fdeeSScott Long } spi; 564b0a2fdeeSScott Long #define mpt_port_page0 cfg.spi._port_page0 565b0a2fdeeSScott Long #define mpt_port_page1 cfg.spi._port_page1 566b0a2fdeeSScott Long #define mpt_port_page2 cfg.spi._port_page2 567b0a2fdeeSScott Long #define mpt_dev_page0 cfg.spi._dev_page0 568b0a2fdeeSScott Long #define mpt_dev_page1 cfg.spi._dev_page1 569b0a2fdeeSScott Long #define mpt_tag_enable cfg.spi._tag_enable 570b0a2fdeeSScott Long #define mpt_disc_enable cfg.spi._disc_enable 571b0a2fdeeSScott Long struct mpi_fc_cfg { 572c87e3f83SMatt Jacob CONFIG_PAGE_FC_PORT_0 _port_page0; 5739fe6d254SMatt Jacob uint32_t _port_speed; 574c87e3f83SMatt Jacob #define mpt_fcport_page0 cfg.fc._port_page0 5759fe6d254SMatt Jacob #define mpt_fcport_speed cfg.fc._port_speed 576b0a2fdeeSScott Long } fc; 577b0a2fdeeSScott Long } cfg; 578970043d7SMatt Jacob #if __FreeBSD_version >= 500000 579970043d7SMatt Jacob /* 580970043d7SMatt Jacob * Device config information stored up for sysctl to access 581970043d7SMatt Jacob */ 582970043d7SMatt Jacob union { 583970043d7SMatt Jacob struct { 584970043d7SMatt Jacob unsigned int initiator_id; 585970043d7SMatt Jacob } spi; 586970043d7SMatt Jacob struct { 587970043d7SMatt Jacob char wwnn[19]; 588970043d7SMatt Jacob char wwpn[19]; 589970043d7SMatt Jacob } fc; 590970043d7SMatt Jacob } scinfo; 591970043d7SMatt Jacob #endif 592b0a2fdeeSScott Long 5931d79ca0eSMatt Jacob /* Controller Info for RAID information */ 594b0a2fdeeSScott Long CONFIG_PAGE_IOC_2 * ioc_page2; 595b0a2fdeeSScott Long CONFIG_PAGE_IOC_3 * ioc_page3; 596b0a2fdeeSScott Long 597b0a2fdeeSScott Long /* Raid Data */ 598b0a2fdeeSScott Long struct mpt_raid_volume* raid_volumes; 599b0a2fdeeSScott Long struct mpt_raid_disk* raid_disks; 600b0a2fdeeSScott Long u_int raid_max_volumes; 601b0a2fdeeSScott Long u_int raid_max_disks; 602b0a2fdeeSScott Long u_int raid_page0_len; 603b0a2fdeeSScott Long u_int raid_wakeup; 604b0a2fdeeSScott Long u_int raid_rescan; 605b0a2fdeeSScott Long u_int raid_resync_rate; 606b0a2fdeeSScott Long u_int raid_mwce_setting; 607b0a2fdeeSScott Long u_int raid_queue_depth; 6085cc0208aSAlexander Kabaev u_int raid_nonopt_volumes; 609b0a2fdeeSScott Long struct proc *raid_thread; 610b0a2fdeeSScott Long struct callout raid_timer; 611b0a2fdeeSScott Long 612b0a2fdeeSScott Long /* 613b0a2fdeeSScott Long * PCI Hardware info 614b0a2fdeeSScott Long */ 615280388afSJohn Baldwin int pci_msi_count; 616b0a2fdeeSScott Long struct resource * pci_irq; /* Interrupt map for chip */ 617b0a2fdeeSScott Long void * ih; /* Interupt handle */ 618b0a2fdeeSScott Long struct mpt_pci_cfg pci_cfg; /* saved PCI conf registers */ 619b0a2fdeeSScott Long 620b0a2fdeeSScott Long /* 621b0a2fdeeSScott Long * DMA Mapping Stuff 622b0a2fdeeSScott Long */ 623b0a2fdeeSScott Long struct resource * pci_reg; /* Register map for chip */ 624b0a2fdeeSScott Long int pci_mem_rid; /* Resource ID */ 625b0a2fdeeSScott Long bus_space_tag_t pci_st; /* Bus tag for registers */ 626b0a2fdeeSScott Long bus_space_handle_t pci_sh; /* Bus handle for registers */ 627b0a2fdeeSScott Long /* PIO versions of above. */ 628b0a2fdeeSScott Long int pci_pio_rid; 629b0a2fdeeSScott Long struct resource * pci_pio_reg; 630b0a2fdeeSScott Long bus_space_tag_t pci_pio_st; 631b0a2fdeeSScott Long bus_space_handle_t pci_pio_sh; 632b0a2fdeeSScott Long 633b0a2fdeeSScott Long bus_dma_tag_t parent_dmat; /* DMA tag for parent PCI bus */ 634b0a2fdeeSScott Long bus_dma_tag_t reply_dmat; /* DMA tag for reply memory */ 635b0a2fdeeSScott Long bus_dmamap_t reply_dmap; /* DMA map for reply memory */ 636b0a2fdeeSScott Long uint8_t *reply; /* KVA of reply memory */ 637b0a2fdeeSScott Long bus_addr_t reply_phys; /* BusAddr of reply memory */ 638b0a2fdeeSScott Long 639b0a2fdeeSScott Long bus_dma_tag_t buffer_dmat; /* DMA tag for buffers */ 640b0a2fdeeSScott Long bus_dma_tag_t request_dmat; /* DMA tag for request memroy */ 641b0a2fdeeSScott Long bus_dmamap_t request_dmap; /* DMA map for request memroy */ 642b0a2fdeeSScott Long uint8_t *request; /* KVA of Request memory */ 643c87e3f83SMatt Jacob bus_addr_t request_phys; /* BusAddr of request memory */ 644b0a2fdeeSScott Long 645444dd2b6SMatt Jacob uint32_t max_seg_cnt; /* calculated after IOC facts */ 646444dd2b6SMatt Jacob 647444dd2b6SMatt Jacob /* 648444dd2b6SMatt Jacob * Hardware management 649444dd2b6SMatt Jacob */ 650b0a2fdeeSScott Long u_int reset_cnt; 651b0a2fdeeSScott Long 652b0a2fdeeSScott Long /* 653b0a2fdeeSScott Long * CAM && Software Management 654b0a2fdeeSScott Long */ 655b0a2fdeeSScott Long request_t *request_pool; 656b0a2fdeeSScott Long struct req_queue request_free_list; 657b0a2fdeeSScott Long struct req_queue request_pending_list; 658b0a2fdeeSScott Long struct req_queue request_timeout_list; 659b0a2fdeeSScott Long 660b0a2fdeeSScott Long 661b0a2fdeeSScott Long struct cam_sim *sim; 662b0a2fdeeSScott Long struct cam_path *path; 663b0a2fdeeSScott Long 664b0a2fdeeSScott Long struct cam_sim *phydisk_sim; 665b0a2fdeeSScott Long struct cam_path *phydisk_path; 666b0a2fdeeSScott Long 667b0a2fdeeSScott Long struct proc *recovery_thread; 668b0a2fdeeSScott Long request_t *tmf_req; 669b0a2fdeeSScott Long 670c87e3f83SMatt Jacob /* 6715e073106SMatt Jacob * Deferred frame acks due to resource shortage. 6725e073106SMatt Jacob */ 6735e073106SMatt Jacob struct mpt_evtf_list ack_frames; 674fcd9a16bSMatt Jacob 6755e073106SMatt Jacob /* 676c87e3f83SMatt Jacob * Target Mode Support 677c87e3f83SMatt Jacob */ 678c87e3f83SMatt Jacob uint32_t scsi_tgt_handler_id; 679c87e3f83SMatt Jacob request_t ** tgt_cmd_ptrs; 6805089bd63SMatt Jacob request_t ** els_cmd_ptrs; /* FC only */ 681c87e3f83SMatt Jacob 682c87e3f83SMatt Jacob /* 683c87e3f83SMatt Jacob * *snork*- this is chosen to be here *just in case* somebody 684c87e3f83SMatt Jacob * forgets to point to it exactly and we index off of trt with 685c87e3f83SMatt Jacob * CAM_LUN_WILDCARD. 686c87e3f83SMatt Jacob */ 687c87e3f83SMatt Jacob tgt_resource_t trt_wildcard; /* wildcard luns */ 688c87e3f83SMatt Jacob tgt_resource_t trt[MPT_MAX_LUNS]; 689c87e3f83SMatt Jacob uint16_t tgt_cmds_allocated; 6905089bd63SMatt Jacob uint16_t els_cmds_allocated; /* FC only */ 691c87e3f83SMatt Jacob 692c87e3f83SMatt Jacob uint16_t timeouts; /* timeout count */ 693c87e3f83SMatt Jacob uint16_t success; /* successes afer timeout */ 6945089bd63SMatt Jacob uint16_t sequence; /* Sequence Number */ 6955089bd63SMatt Jacob uint16_t pad3; 696c87e3f83SMatt Jacob 697b0a2fdeeSScott Long 698fcd9a16bSMatt Jacob /* Paired port in some dual adapters configurations */ 699b0a2fdeeSScott Long struct mpt_softc * mpt2; 700b0a2fdeeSScott Long 701b0a2fdeeSScott Long /* FW Image management */ 702b0a2fdeeSScott Long uint32_t fw_image_size; 703b0a2fdeeSScott Long uint8_t *fw_image; 704b0a2fdeeSScott Long bus_dma_tag_t fw_dmat; /* DMA tag for firmware image */ 705b0a2fdeeSScott Long bus_dmamap_t fw_dmap; /* DMA map for firmware image */ 7065580ce96SMatt Jacob bus_addr_t fw_phys; /* BusAddr of firmware image */ 707b0a2fdeeSScott Long 708b0a2fdeeSScott Long /* Shutdown Event Handler. */ 709b0a2fdeeSScott Long eventhandler_tag eh; 710b0a2fdeeSScott Long 711b0a2fdeeSScott Long TAILQ_ENTRY(mpt_softc) links; 712b0a2fdeeSScott Long }; 713b0a2fdeeSScott Long 7145089bd63SMatt Jacob static __inline void mpt_assign_serno(struct mpt_softc *, request_t *); 7155089bd63SMatt Jacob 7165089bd63SMatt Jacob static __inline void 7175089bd63SMatt Jacob mpt_assign_serno(struct mpt_softc *mpt, request_t *req) 7185089bd63SMatt Jacob { 7195089bd63SMatt Jacob if ((req->serno = mpt->sequence++) == 0) { 7205089bd63SMatt Jacob req->serno = mpt->sequence++; 7215089bd63SMatt Jacob } 7225089bd63SMatt Jacob } 7235089bd63SMatt Jacob 724c87e3f83SMatt Jacob /***************************** Locking Primitives *****************************/ 725b0a2fdeeSScott Long #if __FreeBSD_version < 500000 726b0a2fdeeSScott Long #define MPT_IFLAGS INTR_TYPE_CAM 727b0a2fdeeSScott Long #define MPT_LOCK(mpt) mpt_lockspl(mpt) 728b0a2fdeeSScott Long #define MPT_UNLOCK(mpt) mpt_unlockspl(mpt) 7295089bd63SMatt Jacob #define MPT_OWNED(mpt) mpt->mpt_islocked 730b0a2fdeeSScott Long #define MPTLOCK_2_CAMLOCK MPT_UNLOCK 731b0a2fdeeSScott Long #define CAMLOCK_2_MPTLOCK MPT_LOCK 732b0a2fdeeSScott Long #define MPT_LOCK_SETUP(mpt) 733b0a2fdeeSScott Long #define MPT_LOCK_DESTROY(mpt) 734b0a2fdeeSScott Long 735b0a2fdeeSScott Long static __inline void mpt_lockspl(struct mpt_softc *mpt); 736b0a2fdeeSScott Long static __inline void mpt_unlockspl(struct mpt_softc *mpt); 737b0a2fdeeSScott Long 738b0a2fdeeSScott Long static __inline void 739b0a2fdeeSScott Long mpt_lockspl(struct mpt_softc *mpt) 740b0a2fdeeSScott Long { 741b0a2fdeeSScott Long int s; 742b0a2fdeeSScott Long 743b0a2fdeeSScott Long s = splcam(); 744b0a2fdeeSScott Long if (mpt->mpt_islocked++ == 0) { 745b0a2fdeeSScott Long mpt->mpt_splsaved = s; 746b0a2fdeeSScott Long } else { 747b0a2fdeeSScott Long splx(s); 748b0a2fdeeSScott Long panic("Recursed lock with mask: 0x%x\n", s); 749b0a2fdeeSScott Long } 750b0a2fdeeSScott Long } 751b0a2fdeeSScott Long 752b0a2fdeeSScott Long static __inline void 753b0a2fdeeSScott Long mpt_unlockspl(struct mpt_softc *mpt) 754b0a2fdeeSScott Long { 755b0a2fdeeSScott Long if (mpt->mpt_islocked) { 756b0a2fdeeSScott Long if (--mpt->mpt_islocked == 0) { 757b0a2fdeeSScott Long splx(mpt->mpt_splsaved); 758b0a2fdeeSScott Long } 759b0a2fdeeSScott Long } else 760b0a2fdeeSScott Long panic("Negative lock count\n"); 761b0a2fdeeSScott Long } 762b0a2fdeeSScott Long 763b0a2fdeeSScott Long static __inline int 764b0a2fdeeSScott Long mpt_sleep(struct mpt_softc *mpt, void *ident, int priority, 765b0a2fdeeSScott Long const char *wmesg, int timo) 766b0a2fdeeSScott Long { 767b0a2fdeeSScott Long int saved_cnt; 768b0a2fdeeSScott Long int saved_spl; 769b0a2fdeeSScott Long int error; 770b0a2fdeeSScott Long 771b0a2fdeeSScott Long KASSERT(mpt->mpt_islocked <= 1, ("Invalid lock count on tsleep")); 772b0a2fdeeSScott Long saved_cnt = mpt->mpt_islocked; 773b0a2fdeeSScott Long saved_spl = mpt->mpt_splsaved; 774b0a2fdeeSScott Long mpt->mpt_islocked = 0; 775b0a2fdeeSScott Long error = tsleep(ident, priority, wmesg, timo); 776c87e3f83SMatt Jacob KASSERT(mpt->mpt_islocked == 0, ("Invalid lock count on wakeup")); 777b0a2fdeeSScott Long mpt->mpt_islocked = saved_cnt; 778b0a2fdeeSScott Long mpt->mpt_splsaved = saved_spl; 779b0a2fdeeSScott Long return (error); 780b0a2fdeeSScott Long } 781b0a2fdeeSScott Long 782b0a2fdeeSScott Long #else 783f4e98881SRuslan Ermilov #ifdef LOCKING_WORKED_AS_IT_SHOULD 784b0a2fdeeSScott Long #error "Shouldn't Be Here!" 785b0a2fdeeSScott Long #define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE 786b0a2fdeeSScott Long #define MPT_LOCK_SETUP(mpt) \ 787b0a2fdeeSScott Long mtx_init(&mpt->mpt_lock, "mpt", NULL, MTX_DEF); \ 788b0a2fdeeSScott Long mpt->mpt_locksetup = 1 789b0a2fdeeSScott Long #define MPT_LOCK_DESTROY(mpt) \ 790b0a2fdeeSScott Long if (mpt->mpt_locksetup) { \ 791b0a2fdeeSScott Long mtx_destroy(&mpt->mpt_lock); \ 792b0a2fdeeSScott Long mpt->mpt_locksetup = 0; \ 793b0a2fdeeSScott Long } 794b0a2fdeeSScott Long 795b0a2fdeeSScott Long #define MPT_LOCK(mpt) mtx_lock(&(mpt)->mpt_lock) 796b0a2fdeeSScott Long #define MPT_UNLOCK(mpt) mtx_unlock(&(mpt)->mpt_lock) 7975089bd63SMatt Jacob #define MPT_OWNED(mpt) mtx_owned(&(mpt)->mpt_lock) 798b0a2fdeeSScott Long #define MPTLOCK_2_CAMLOCK(mpt) \ 799b0a2fdeeSScott Long mtx_unlock(&(mpt)->mpt_lock); mtx_lock(&Giant) 800b0a2fdeeSScott Long #define CAMLOCK_2_MPTLOCK(mpt) \ 801b0a2fdeeSScott Long mtx_unlock(&Giant); mtx_lock(&(mpt)->mpt_lock) 802b0a2fdeeSScott Long #define mpt_sleep(mpt, ident, priority, wmesg, timo) \ 803b0a2fdeeSScott Long msleep(ident, &(mpt)->mpt_lock, priority, wmesg, timo) 8045089bd63SMatt Jacob 805b0a2fdeeSScott Long #else 8065089bd63SMatt Jacob 807b0a2fdeeSScott Long #define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY 808b0a2fdeeSScott Long #define MPT_LOCK_SETUP(mpt) do { } while (0) 809b0a2fdeeSScott Long #define MPT_LOCK_DESTROY(mpt) do { } while (0) 8105089bd63SMatt Jacob #if 0 8115089bd63SMatt Jacob #define MPT_LOCK(mpt) \ 8125089bd63SMatt Jacob device_printf(mpt->dev, "LOCK %s:%d\n", __FILE__, __LINE__); \ 8135089bd63SMatt Jacob KASSERT(mpt->mpt_locksetup == 0, \ 8145089bd63SMatt Jacob ("recursive lock acquire at %s:%d", __FILE__, __LINE__)); \ 8155089bd63SMatt Jacob mpt->mpt_locksetup = 1 8165089bd63SMatt Jacob #define MPT_UNLOCK(mpt) \ 8175089bd63SMatt Jacob device_printf(mpt->dev, "UNLK %s:%d\n", __FILE__, __LINE__); \ 8185089bd63SMatt Jacob KASSERT(mpt->mpt_locksetup == 1, \ 8195089bd63SMatt Jacob ("release unowned lock at %s:%d", __FILE__, __LINE__)); \ 8205089bd63SMatt Jacob mpt->mpt_locksetup = 0 8215089bd63SMatt Jacob #else 8225089bd63SMatt Jacob #define MPT_LOCK(mpt) \ 8235089bd63SMatt Jacob KASSERT(mpt->mpt_locksetup == 0, \ 8245089bd63SMatt Jacob ("recursive lock acquire at %s:%d", __FILE__, __LINE__)); \ 8255089bd63SMatt Jacob mpt->mpt_locksetup = 1 8265089bd63SMatt Jacob #define MPT_UNLOCK(mpt) \ 8275089bd63SMatt Jacob KASSERT(mpt->mpt_locksetup == 1, \ 8285089bd63SMatt Jacob ("release unowned lock at %s:%d", __FILE__, __LINE__)); \ 8295089bd63SMatt Jacob mpt->mpt_locksetup = 0 8305089bd63SMatt Jacob #endif 8315089bd63SMatt Jacob #define MPT_OWNED(mpt) mpt->mpt_locksetup 8325089bd63SMatt Jacob #define MPTLOCK_2_CAMLOCK(mpt) MPT_UNLOCK(mpt) 8335089bd63SMatt Jacob #define CAMLOCK_2_MPTLOCK(mpt) MPT_LOCK(mpt) 8345089bd63SMatt Jacob 8355089bd63SMatt Jacob static __inline int 8365089bd63SMatt Jacob mpt_sleep(struct mpt_softc *, void *, int, const char *, int); 8375089bd63SMatt Jacob 8385089bd63SMatt Jacob static __inline int 8395089bd63SMatt Jacob mpt_sleep(struct mpt_softc *mpt, void *i, int p, const char *w, int t) 8405089bd63SMatt Jacob { 8415089bd63SMatt Jacob int r; 8425089bd63SMatt Jacob MPT_UNLOCK(mpt); 8435089bd63SMatt Jacob r = tsleep(i, p, w, t); 8445089bd63SMatt Jacob MPT_LOCK(mpt); 8455089bd63SMatt Jacob return (r); 8465089bd63SMatt Jacob } 847b0a2fdeeSScott Long #endif 848b0a2fdeeSScott Long #endif 849b0a2fdeeSScott Long 850b0a2fdeeSScott Long /******************************* Register Access ******************************/ 851b0a2fdeeSScott Long static __inline void mpt_write(struct mpt_softc *, size_t, uint32_t); 852b0a2fdeeSScott Long static __inline uint32_t mpt_read(struct mpt_softc *, int); 853b0a2fdeeSScott Long static __inline void mpt_pio_write(struct mpt_softc *, size_t, uint32_t); 854b0a2fdeeSScott Long static __inline uint32_t mpt_pio_read(struct mpt_softc *, int); 855b0a2fdeeSScott Long 856b0a2fdeeSScott Long static __inline void 857b0a2fdeeSScott Long mpt_write(struct mpt_softc *mpt, size_t offset, uint32_t val) 858b0a2fdeeSScott Long { 859b0a2fdeeSScott Long bus_space_write_4(mpt->pci_st, mpt->pci_sh, offset, val); 860b0a2fdeeSScott Long } 861b0a2fdeeSScott Long 862b0a2fdeeSScott Long static __inline uint32_t 863b0a2fdeeSScott Long mpt_read(struct mpt_softc *mpt, int offset) 864b0a2fdeeSScott Long { 865b0a2fdeeSScott Long return (bus_space_read_4(mpt->pci_st, mpt->pci_sh, offset)); 866b0a2fdeeSScott Long } 867b0a2fdeeSScott Long 868b0a2fdeeSScott Long /* 869b0a2fdeeSScott Long * Some operations (e.g. diagnostic register writes while the ARM proccessor 870b0a2fdeeSScott Long * is disabled), must be performed using "PCI pio" operations. On non-PCI 871b0a2fdeeSScott Long * busses, these operations likely map to normal register accesses. 872b0a2fdeeSScott Long */ 873b0a2fdeeSScott Long static __inline void 874b0a2fdeeSScott Long mpt_pio_write(struct mpt_softc *mpt, size_t offset, uint32_t val) 875b0a2fdeeSScott Long { 876b0a2fdeeSScott Long bus_space_write_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset, val); 877b0a2fdeeSScott Long } 878b0a2fdeeSScott Long 879b0a2fdeeSScott Long static __inline uint32_t 880b0a2fdeeSScott Long mpt_pio_read(struct mpt_softc *mpt, int offset) 881b0a2fdeeSScott Long { 882b0a2fdeeSScott Long return (bus_space_read_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset)); 883b0a2fdeeSScott Long } 884b0a2fdeeSScott Long /*********************** Reply Frame/Request Management ***********************/ 885b0a2fdeeSScott Long /* Max MPT Reply we are willing to accept (must be power of 2) */ 886444dd2b6SMatt Jacob #define MPT_REPLY_SIZE 256 887b0a2fdeeSScott Long 888c87e3f83SMatt Jacob /* 889c87e3f83SMatt Jacob * Must be less than 16384 in order for target mode to work 890c87e3f83SMatt Jacob */ 891444dd2b6SMatt Jacob #define MPT_MAX_REQUESTS(mpt) 512 892b0a2fdeeSScott Long #define MPT_REQUEST_AREA 512 893444dd2b6SMatt Jacob #define MPT_SENSE_SIZE 32 /* included in MPT_REQUEST_AREA */ 894b0a2fdeeSScott Long #define MPT_REQ_MEM_SIZE(mpt) (MPT_MAX_REQUESTS(mpt) * MPT_REQUEST_AREA) 895b0a2fdeeSScott Long 8965e073106SMatt Jacob #define MPT_CONTEXT_CB_SHIFT (16) 897b0a2fdeeSScott Long #define MPT_CBI(handle) (handle >> MPT_CONTEXT_CB_SHIFT) 898b0a2fdeeSScott Long #define MPT_CBI_TO_HID(cbi) ((cbi) << MPT_CONTEXT_CB_SHIFT) 899b0a2fdeeSScott Long #define MPT_CONTEXT_TO_CBI(x) \ 900b0a2fdeeSScott Long (((x) >> MPT_CONTEXT_CB_SHIFT) & (MPT_NUM_REPLY_HANDLERS - 1)) 9015e073106SMatt Jacob #define MPT_CONTEXT_REQI_MASK 0xFFFF 902c87e3f83SMatt Jacob #define MPT_CONTEXT_TO_REQI(x) ((x) & MPT_CONTEXT_REQI_MASK) 903b0a2fdeeSScott Long 904b0a2fdeeSScott Long /* 905b0a2fdeeSScott Long * Convert a 32bit physical address returned from IOC to an 906b0a2fdeeSScott Long * offset into our reply frame memory or the kvm address needed 907b0a2fdeeSScott Long * to access the data. The returned address is only the low 908b0a2fdeeSScott Long * 32 bits, so mask our base physical address accordingly. 909b0a2fdeeSScott Long */ 910b0a2fdeeSScott Long #define MPT_REPLY_BADDR(x) \ 911b0a2fdeeSScott Long (x << 1) 912b0a2fdeeSScott Long #define MPT_REPLY_OTOV(m, i) \ 913b0a2fdeeSScott Long ((void *)(&m->reply[i])) 914b0a2fdeeSScott Long 915b0a2fdeeSScott Long #define MPT_DUMP_REPLY_FRAME(mpt, reply_frame) \ 916b0a2fdeeSScott Long do { \ 9171d79ca0eSMatt Jacob if (mpt->verbose > MPT_PRT_DEBUG) \ 918b0a2fdeeSScott Long mpt_dump_reply_frame(mpt, reply_frame); \ 919b0a2fdeeSScott Long } while(0) 920b0a2fdeeSScott Long 921b0a2fdeeSScott Long static __inline uint32_t mpt_pop_reply_queue(struct mpt_softc *mpt); 922b0a2fdeeSScott Long static __inline void mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr); 923b0a2fdeeSScott Long 924b0a2fdeeSScott Long /* 925b0a2fdeeSScott Long * Give the reply buffer back to the IOC after we have 926b0a2fdeeSScott Long * finished processing it. 927b0a2fdeeSScott Long */ 928b0a2fdeeSScott Long static __inline void 929b0a2fdeeSScott Long mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr) 930b0a2fdeeSScott Long { 931b0a2fdeeSScott Long mpt_write(mpt, MPT_OFFSET_REPLY_Q, ptr); 932b0a2fdeeSScott Long } 933b0a2fdeeSScott Long 934b0a2fdeeSScott Long /* Get a reply from the IOC */ 935b0a2fdeeSScott Long static __inline uint32_t 936b0a2fdeeSScott Long mpt_pop_reply_queue(struct mpt_softc *mpt) 937b0a2fdeeSScott Long { 938b0a2fdeeSScott Long return mpt_read(mpt, MPT_OFFSET_REPLY_Q); 939b0a2fdeeSScott Long } 940b0a2fdeeSScott Long 9415e073106SMatt Jacob void 9425e073106SMatt Jacob mpt_complete_request_chain(struct mpt_softc *, struct req_queue *, u_int); 9435e073106SMatt Jacob 944b0a2fdeeSScott Long /************************** Scatter Gather Managment **************************/ 945444dd2b6SMatt Jacob /* MPT_RQSL- size of request frame, in bytes */ 9460e0521a1SMatt Jacob #define MPT_RQSL(mpt) (mpt->ioc_facts.RequestFrameSize << 2) 947b0a2fdeeSScott Long 948444dd2b6SMatt Jacob /* MPT_NSGL- how many SG entries can fit in a request frame size */ 949444dd2b6SMatt Jacob #define MPT_NSGL(mpt) (MPT_RQSL(mpt) / sizeof (SGE_IO_UNION)) 950444dd2b6SMatt Jacob 951444dd2b6SMatt Jacob /* MPT_NRFM- how many request frames can fit in each request alloc we make */ 952444dd2b6SMatt Jacob #define MPT_NRFM(mpt) (MPT_REQUEST_AREA / MPT_RQSL(mpt)) 953444dd2b6SMatt Jacob 954444dd2b6SMatt Jacob /* 955444dd2b6SMatt Jacob * MPT_NSGL_FIRST- # of SG elements that can fit after 956444dd2b6SMatt Jacob * an I/O request but still within the request frame. 957444dd2b6SMatt Jacob * Do this safely based upon SGE_IO_UNION. 958444dd2b6SMatt Jacob * 959444dd2b6SMatt Jacob * Note that the first element is *within* the SCSI request. 960444dd2b6SMatt Jacob */ 961b0a2fdeeSScott Long #define MPT_NSGL_FIRST(mpt) \ 962444dd2b6SMatt Jacob ((MPT_RQSL(mpt) - sizeof (MSG_SCSI_IO_REQUEST) + sizeof (SGE_IO_UNION)) / \ 963444dd2b6SMatt Jacob sizeof (SGE_IO_UNION)) 964b0a2fdeeSScott Long 965b0a2fdeeSScott Long /***************************** IOC Initialization *****************************/ 966b0a2fdeeSScott Long int mpt_reset(struct mpt_softc *, int /*reinit*/); 967b0a2fdeeSScott Long 968c87e3f83SMatt Jacob /****************************** Debugging ************************************/ 969b0a2fdeeSScott Long typedef struct mpt_decode_entry { 970b0a2fdeeSScott Long char *name; 971b0a2fdeeSScott Long u_int value; 972b0a2fdeeSScott Long u_int mask; 973b0a2fdeeSScott Long } mpt_decode_entry_t; 974b0a2fdeeSScott Long 975b0a2fdeeSScott Long int mpt_decode_value(mpt_decode_entry_t *table, u_int num_entries, 976b0a2fdeeSScott Long const char *name, u_int value, u_int *cur_column, 977b0a2fdeeSScott Long u_int wrap_point); 978b0a2fdeeSScott Long 979b4c618c0SMatt Jacob void mpt_dump_data(struct mpt_softc *, const char *, void *, int); 9800e3b145eSMatt Jacob void mpt_dump_request(struct mpt_softc *, request_t *); 9810e3b145eSMatt Jacob 982b0a2fdeeSScott Long enum { 983b0a2fdeeSScott Long MPT_PRT_ALWAYS, 984b0a2fdeeSScott Long MPT_PRT_FATAL, 985b0a2fdeeSScott Long MPT_PRT_ERROR, 986b0a2fdeeSScott Long MPT_PRT_WARN, 987b0a2fdeeSScott Long MPT_PRT_INFO, 988ac219b98SMatt Jacob MPT_PRT_NEGOTIATION, 989b0a2fdeeSScott Long MPT_PRT_DEBUG, 990c87e3f83SMatt Jacob MPT_PRT_DEBUG1, 991c87e3f83SMatt Jacob MPT_PRT_DEBUG2, 992c87e3f83SMatt Jacob MPT_PRT_DEBUG3, 993444dd2b6SMatt Jacob MPT_PRT_TRACE, 994444dd2b6SMatt Jacob MPT_PRT_NONE=100 995b0a2fdeeSScott Long }; 996b0a2fdeeSScott Long 997c87e3f83SMatt Jacob #if __FreeBSD_version > 500000 998b0a2fdeeSScott Long #define mpt_lprt(mpt, level, ...) \ 999b0a2fdeeSScott Long do { \ 1000b0a2fdeeSScott Long if (level <= (mpt)->verbose) \ 1001b0a2fdeeSScott Long mpt_prt(mpt, __VA_ARGS__); \ 1002b0a2fdeeSScott Long } while (0) 1003b0a2fdeeSScott Long 1004b0a2fdeeSScott Long #define mpt_lprtc(mpt, level, ...) \ 1005b0a2fdeeSScott Long do { \ 1006b0a2fdeeSScott Long if (level <= (mpt)->debug_level) \ 1007b0a2fdeeSScott Long mpt_prtc(mpt, __VA_ARGS__); \ 1008b0a2fdeeSScott Long } while (0) 1009c87e3f83SMatt Jacob #else 1010c87e3f83SMatt Jacob void mpt_lprt(struct mpt_softc *, int, const char *, ...) 1011c87e3f83SMatt Jacob __printflike(3, 4); 1012c87e3f83SMatt Jacob void mpt_lprtc(struct mpt_softc *, int, const char *, ...) 1013c87e3f83SMatt Jacob __printflike(3, 4); 1014c87e3f83SMatt Jacob #endif 1015c87e3f83SMatt Jacob void mpt_prt(struct mpt_softc *, const char *, ...) 1016c87e3f83SMatt Jacob __printflike(2, 3); 1017c87e3f83SMatt Jacob void mpt_prtc(struct mpt_softc *, const char *, ...) 1018c87e3f83SMatt Jacob __printflike(2, 3); 1019b0a2fdeeSScott Long 1020c87e3f83SMatt Jacob /**************************** Target Mode Related ***************************/ 1021c87e3f83SMatt Jacob static __inline int mpt_cdblen(uint8_t, int); 1022c87e3f83SMatt Jacob static __inline int 1023c87e3f83SMatt Jacob mpt_cdblen(uint8_t cdb0, int maxlen) 1024c87e3f83SMatt Jacob { 1025c87e3f83SMatt Jacob int group = cdb0 >> 5; 1026c87e3f83SMatt Jacob switch (group) { 1027c87e3f83SMatt Jacob case 0: 1028c87e3f83SMatt Jacob return (6); 1029c87e3f83SMatt Jacob case 1: 1030c87e3f83SMatt Jacob return (10); 1031c87e3f83SMatt Jacob case 4: 1032c87e3f83SMatt Jacob case 5: 1033c87e3f83SMatt Jacob return (12); 1034c87e3f83SMatt Jacob default: 1035c87e3f83SMatt Jacob return (16); 1036c87e3f83SMatt Jacob } 1037c87e3f83SMatt Jacob } 1038c87e3f83SMatt Jacob #ifdef INVARIANTS 1039c87e3f83SMatt Jacob static __inline request_t * mpt_tag_2_req(struct mpt_softc *, uint32_t); 1040c87e3f83SMatt Jacob static __inline request_t * 1041c87e3f83SMatt Jacob mpt_tag_2_req(struct mpt_softc *mpt, uint32_t tag) 1042c87e3f83SMatt Jacob { 10435e073106SMatt Jacob uint16_t rtg = (tag >> 18); 1044c87e3f83SMatt Jacob KASSERT(rtg < mpt->tgt_cmds_allocated, ("bad tag %d\n", tag)); 1045c87e3f83SMatt Jacob KASSERT(mpt->tgt_cmd_ptrs, ("no cmd backpointer array")); 1046c87e3f83SMatt Jacob KASSERT(mpt->tgt_cmd_ptrs[rtg], ("no cmd backpointer")); 1047c87e3f83SMatt Jacob return (mpt->tgt_cmd_ptrs[rtg]); 1048c87e3f83SMatt Jacob } 10495089bd63SMatt Jacob 10505089bd63SMatt Jacob 10515089bd63SMatt Jacob static __inline int 10525089bd63SMatt Jacob mpt_req_on_free_list(struct mpt_softc *, request_t *); 10535089bd63SMatt Jacob static __inline int 10545089bd63SMatt Jacob mpt_req_on_pending_list(struct mpt_softc *, request_t *); 10555089bd63SMatt Jacob 10565089bd63SMatt Jacob static __inline void 10575089bd63SMatt Jacob mpt_req_spcl(struct mpt_softc *, request_t *, const char *, int); 10585089bd63SMatt Jacob static __inline void 10595089bd63SMatt Jacob mpt_req_not_spcl(struct mpt_softc *, request_t *, const char *, int); 10605089bd63SMatt Jacob 10615089bd63SMatt Jacob 10625089bd63SMatt Jacob /* 10635089bd63SMatt Jacob * Is request on freelist? 10645089bd63SMatt Jacob */ 10655089bd63SMatt Jacob static __inline int 10665089bd63SMatt Jacob mpt_req_on_free_list(struct mpt_softc *mpt, request_t *req) 10675089bd63SMatt Jacob { 10685089bd63SMatt Jacob request_t *lrq; 10695089bd63SMatt Jacob 10705089bd63SMatt Jacob TAILQ_FOREACH(lrq, &mpt->request_free_list, links) { 10715089bd63SMatt Jacob if (lrq == req) { 10725089bd63SMatt Jacob return (1); 10735089bd63SMatt Jacob } 10745089bd63SMatt Jacob } 10755089bd63SMatt Jacob return (0); 10765089bd63SMatt Jacob } 10775089bd63SMatt Jacob 10785089bd63SMatt Jacob /* 10795089bd63SMatt Jacob * Is request on pending list? 10805089bd63SMatt Jacob */ 10815089bd63SMatt Jacob static __inline int 10825089bd63SMatt Jacob mpt_req_on_pending_list(struct mpt_softc *mpt, request_t *req) 10835089bd63SMatt Jacob { 10845089bd63SMatt Jacob request_t *lrq; 10855089bd63SMatt Jacob 10865089bd63SMatt Jacob TAILQ_FOREACH(lrq, &mpt->request_pending_list, links) { 10875089bd63SMatt Jacob if (lrq == req) { 10885089bd63SMatt Jacob return (1); 10895089bd63SMatt Jacob } 10905089bd63SMatt Jacob } 10915089bd63SMatt Jacob return (0); 10925089bd63SMatt Jacob } 10935089bd63SMatt Jacob 10945089bd63SMatt Jacob /* 10955089bd63SMatt Jacob * Make sure that req *is* part of one of the special lists 10965089bd63SMatt Jacob */ 10975089bd63SMatt Jacob static __inline void 10985089bd63SMatt Jacob mpt_req_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line) 10995089bd63SMatt Jacob { 11005089bd63SMatt Jacob int i; 11015089bd63SMatt Jacob for (i = 0; i < mpt->els_cmds_allocated; i++) { 11025089bd63SMatt Jacob if (req == mpt->els_cmd_ptrs[i]) { 11035089bd63SMatt Jacob return; 11045089bd63SMatt Jacob } 11055089bd63SMatt Jacob } 11065089bd63SMatt Jacob for (i = 0; i < mpt->tgt_cmds_allocated; i++) { 11075089bd63SMatt Jacob if (req == mpt->tgt_cmd_ptrs[i]) { 11085089bd63SMatt Jacob return; 11095089bd63SMatt Jacob } 11105089bd63SMatt Jacob } 11115089bd63SMatt Jacob panic("%s(%d): req %p:%u function %x not in els or tgt ptrs\n", 11125089bd63SMatt Jacob s, line, req, req->serno, 11135089bd63SMatt Jacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function); 11145089bd63SMatt Jacob } 11155089bd63SMatt Jacob 11165089bd63SMatt Jacob /* 11175089bd63SMatt Jacob * Make sure that req is *not* part of one of the special lists. 11185089bd63SMatt Jacob */ 11195089bd63SMatt Jacob static __inline void 11205089bd63SMatt Jacob mpt_req_not_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line) 11215089bd63SMatt Jacob { 11225089bd63SMatt Jacob int i; 11235089bd63SMatt Jacob for (i = 0; i < mpt->els_cmds_allocated; i++) { 11245089bd63SMatt Jacob KASSERT(req != mpt->els_cmd_ptrs[i], 11255089bd63SMatt Jacob ("%s(%d): req %p:%u func %x in els ptrs at ioindex %d\n", 11265089bd63SMatt Jacob s, line, req, req->serno, 11275089bd63SMatt Jacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i)); 11285089bd63SMatt Jacob } 11295089bd63SMatt Jacob for (i = 0; i < mpt->tgt_cmds_allocated; i++) { 11305089bd63SMatt Jacob KASSERT(req != mpt->tgt_cmd_ptrs[i], 11315089bd63SMatt Jacob ("%s(%d): req %p:%u func %x in tgt ptrs at ioindex %d\n", 11325089bd63SMatt Jacob s, line, req, req->serno, 11335089bd63SMatt Jacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i)); 11345089bd63SMatt Jacob } 11355089bd63SMatt Jacob } 1136c87e3f83SMatt Jacob #endif 1137c87e3f83SMatt Jacob 113873651fd1SMatt Jacob /* 113973651fd1SMatt Jacob * Task Management Types, purely for internal consumption 114073651fd1SMatt Jacob */ 1141c87e3f83SMatt Jacob typedef enum { 1142c87e3f83SMatt Jacob MPT_ABORT_TASK_SET=1234, 1143c87e3f83SMatt Jacob MPT_CLEAR_TASK_SET, 1144c87e3f83SMatt Jacob MPT_TARGET_RESET, 1145c87e3f83SMatt Jacob MPT_CLEAR_ACA, 1146c87e3f83SMatt Jacob MPT_TERMINATE_TASK, 1147c87e3f83SMatt Jacob MPT_NIL_TMT_VALUE=5678 1148c87e3f83SMatt Jacob } mpt_task_mgmt_t; 1149b0a2fdeeSScott Long 1150b0a2fdeeSScott Long /**************************** Unclassified Routines ***************************/ 1151b0a2fdeeSScott Long void mpt_send_cmd(struct mpt_softc *mpt, request_t *req); 1152b0a2fdeeSScott Long int mpt_recv_handshake_reply(struct mpt_softc *mpt, 1153b0a2fdeeSScott Long size_t reply_len, void *reply); 1154b0a2fdeeSScott Long int mpt_wait_req(struct mpt_softc *mpt, request_t *req, 1155b0a2fdeeSScott Long mpt_req_state_t state, mpt_req_state_t mask, 1156b0a2fdeeSScott Long int sleep_ok, int time_ms); 1157b0a2fdeeSScott Long void mpt_enable_ints(struct mpt_softc *mpt); 1158b0a2fdeeSScott Long void mpt_disable_ints(struct mpt_softc *mpt); 1159b0a2fdeeSScott Long int mpt_attach(struct mpt_softc *mpt); 1160b0a2fdeeSScott Long int mpt_shutdown(struct mpt_softc *mpt); 1161b0a2fdeeSScott Long int mpt_detach(struct mpt_softc *mpt); 1162b0a2fdeeSScott Long int mpt_send_handshake_cmd(struct mpt_softc *mpt, 1163b0a2fdeeSScott Long size_t len, void *cmd); 1164b0a2fdeeSScott Long request_t * mpt_get_request(struct mpt_softc *mpt, int sleep_ok); 1165b0a2fdeeSScott Long void mpt_free_request(struct mpt_softc *mpt, request_t *req); 1166b0a2fdeeSScott Long void mpt_intr(void *arg); 1167b0a2fdeeSScott Long void mpt_check_doorbell(struct mpt_softc *mpt); 1168b0a2fdeeSScott Long void mpt_dump_reply_frame(struct mpt_softc *mpt, 1169b0a2fdeeSScott Long MSG_DEFAULT_REPLY *reply_frame); 1170b0a2fdeeSScott Long 1171b0a2fdeeSScott Long void mpt_set_config_regs(struct mpt_softc *); 1172b0a2fdeeSScott Long int mpt_issue_cfg_req(struct mpt_softc */*mpt*/, request_t */*req*/, 1173b0a2fdeeSScott Long u_int /*Action*/, u_int /*PageVersion*/, 1174b0a2fdeeSScott Long u_int /*PageLength*/, u_int /*PageNumber*/, 1175b0a2fdeeSScott Long u_int /*PageType*/, uint32_t /*PageAddress*/, 1176b0a2fdeeSScott Long bus_addr_t /*addr*/, bus_size_t/*len*/, 1177b0a2fdeeSScott Long int /*sleep_ok*/, int /*timeout_ms*/); 1178b0a2fdeeSScott Long int mpt_read_cfg_header(struct mpt_softc *, int /*PageType*/, 1179b0a2fdeeSScott Long int /*PageNumber*/, 1180b0a2fdeeSScott Long uint32_t /*PageAddress*/, 1181b0a2fdeeSScott Long CONFIG_PAGE_HEADER *, 1182b0a2fdeeSScott Long int /*sleep_ok*/, int /*timeout_ms*/); 1183b0a2fdeeSScott Long int mpt_read_cfg_page(struct mpt_softc *t, int /*Action*/, 1184b0a2fdeeSScott Long uint32_t /*PageAddress*/, 1185b0a2fdeeSScott Long CONFIG_PAGE_HEADER *, size_t /*len*/, 1186b0a2fdeeSScott Long int /*sleep_ok*/, int /*timeout_ms*/); 1187b0a2fdeeSScott Long int mpt_write_cfg_page(struct mpt_softc *, int /*Action*/, 1188b0a2fdeeSScott Long uint32_t /*PageAddress*/, 1189b0a2fdeeSScott Long CONFIG_PAGE_HEADER *, size_t /*len*/, 1190b0a2fdeeSScott Long int /*sleep_ok*/, int /*timeout_ms*/); 1191b0a2fdeeSScott Long static __inline int 1192b0a2fdeeSScott Long mpt_read_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress, 1193b0a2fdeeSScott Long CONFIG_PAGE_HEADER *hdr, size_t len, 1194b0a2fdeeSScott Long int sleep_ok, int timeout_ms) 1195b0a2fdeeSScott Long { 1196b0a2fdeeSScott Long return (mpt_read_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT, 1197b0a2fdeeSScott Long PageAddress, hdr, len, sleep_ok, timeout_ms)); 1198b0a2fdeeSScott Long } 1199b0a2fdeeSScott Long 1200b0a2fdeeSScott Long static __inline int 1201b0a2fdeeSScott Long mpt_write_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress, 1202b0a2fdeeSScott Long CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok, 1203b0a2fdeeSScott Long int timeout_ms) 1204b0a2fdeeSScott Long { 1205b0a2fdeeSScott Long return (mpt_write_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT, 1206b0a2fdeeSScott Long PageAddress, hdr, len, sleep_ok, 1207b0a2fdeeSScott Long timeout_ms)); 1208b0a2fdeeSScott Long } 12099b631363SMatt Jacob /* mpt_debug.c functions */ 12109b631363SMatt Jacob void mpt_print_reply(void *vmsg); 1211b0a2fdeeSScott Long void mpt_print_db(uint32_t mb); 12129b631363SMatt Jacob void mpt_print_config_reply(void *vmsg); 1213b0a2fdeeSScott Long char *mpt_ioc_diag(uint32_t diag); 1214b0a2fdeeSScott Long void mpt_req_state(mpt_req_state_t state); 12159b631363SMatt Jacob void mpt_print_config_request(void *vmsg); 12169b631363SMatt Jacob void mpt_print_request(void *vmsg); 1217b0a2fdeeSScott Long void mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *msg); 1218444dd2b6SMatt Jacob void mpt_dump_sgl(SGE_IO_UNION *se, int offset); 12199b631363SMatt Jacob #endif /* _MPT_H_ */ 1220