1101704Smjacob/* $FreeBSD$ */ 2139749Simp/*- 3101704Smjacob * Generic defines for LSI '909 FC adapters. 4101704Smjacob * FreeBSD Version. 5101704Smjacob * 6101704Smjacob * Copyright (c) 2000, 2001 by Greg Ansley 7101704Smjacob * 8101704Smjacob * Redistribution and use in source and binary forms, with or without 9101704Smjacob * modification, are permitted provided that the following conditions 10101704Smjacob * are met: 11101704Smjacob * 1. Redistributions of source code must retain the above copyright 12101704Smjacob * notice immediately at the beginning of the file, without modification, 13101704Smjacob * this list of conditions, and the following disclaimer. 14101704Smjacob * 2. The name of the author may not be used to endorse or promote products 15101704Smjacob * derived from this software without specific prior written permission. 16101704Smjacob * 17101704Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18101704Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19101704Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20101704Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21101704Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22101704Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23101704Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24101704Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25101704Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26101704Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27101704Smjacob * SUCH DAMAGE. 28156000Smjacob */ 29156000Smjacob/*- 30156000Smjacob * Copyright (c) 2002, 2006 by Matthew Jacob 31156000Smjacob * All rights reserved. 32156000Smjacob * 33156000Smjacob * Redistribution and use in source and binary forms, with or without 34156000Smjacob * modification, are permitted provided that the following conditions are 35156000Smjacob * met: 36156000Smjacob * 1. Redistributions of source code must retain the above copyright 37156000Smjacob * notice, this list of conditions and the following disclaimer. 38156000Smjacob * 2. Redistributions in binary form must reproduce at minimum a disclaimer 39156000Smjacob * substantially similar to the "NO WARRANTY" disclaimer below 40156000Smjacob * ("Disclaimer") and any redistribution must be conditioned upon including 41156000Smjacob * a substantially similar Disclaimer requirement for further binary 42156000Smjacob * redistribution. 43156000Smjacob * 3. Neither the names of the above listed copyright holders nor the names 44156000Smjacob * of any contributors may be used to endorse or promote products derived 45156000Smjacob * from this software without specific prior written permission. 46156000Smjacob * 47156000Smjacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48156000Smjacob * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49156000Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50156000Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 51156000Smjacob * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 52156000Smjacob * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 53156000Smjacob * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 54156000Smjacob * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 55156000Smjacob * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 56156000Smjacob * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 57156000Smjacob * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58147883Sscottl * 59156000Smjacob * Support from Chris Ellsworth in order to make SAS adapters work 60156000Smjacob * is gratefully acknowledged. 61159052Smjacob * 62159052Smjacob * 63159052Smjacob * Support from LSI-Logic has also gone a great deal toward making this a 64159052Smjacob * workable subsystem and is gratefully acknowledged. 65101704Smjacob */ 66101704Smjacob/* 67147883Sscottl * Copyright (c) 2004, Avid Technology, Inc. and its contributors. 68147883Sscottl * Copyright (c) 2004, 2005 Justin T. Gibbs 69147883Sscottl * Copyright (c) 2005, WHEEL Sp. z o.o. 70147883Sscottl * All rights reserved. 71147883Sscottl * 72147883Sscottl * Redistribution and use in source and binary forms, with or without 73147883Sscottl * modification, are permitted provided that the following conditions are 74147883Sscottl * met: 75147883Sscottl * 1. Redistributions of source code must retain the above copyright 76147883Sscottl * notice, this list of conditions and the following disclaimer. 77147883Sscottl * 2. Redistributions in binary form must reproduce at minimum a disclaimer 78147883Sscottl * substantially similar to the "NO WARRANTY" disclaimer below 79147883Sscottl * ("Disclaimer") and any redistribution must be conditioned upon including 80147883Sscottl * a substantially similar Disclaimer requirement for further binary 81147883Sscottl * redistribution. 82148679Sgibbs * 3. Neither the names of the above listed copyright holders nor the names 83148679Sgibbs * of any contributors may be used to endorse or promote products derived 84148679Sgibbs * from this software without specific prior written permission. 85147883Sscottl * 86147883Sscottl * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 87147883Sscottl * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 88147883Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 89147883Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 90147883Sscottl * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 91147883Sscottl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 92147883Sscottl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 93147883Sscottl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 94147883Sscottl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 95147883Sscottl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 96147883Sscottl * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 97101704Smjacob */ 98101704Smjacob 99101704Smjacob#ifndef _MPT_H_ 100101704Smjacob#define _MPT_H_ 101147883Sscottl 102147883Sscottl/********************************* OS Includes ********************************/ 103147883Sscottl#include <sys/param.h> 104147883Sscottl#include <sys/systm.h> 105241874Smarius#include <sys/bus.h> 106241874Smarius#include <sys/condvar.h> 107147883Sscottl#include <sys/endian.h> 108147883Sscottl#include <sys/eventhandler.h> 109147883Sscottl#include <sys/kernel.h> 110147883Sscottl#include <sys/lock.h> 111147883Sscottl#include <sys/malloc.h> 112241874Smarius#include <sys/module.h> 113147883Sscottl#include <sys/mutex.h> 114147883Sscottl#include <sys/proc.h> 115241874Smarius#include <sys/queue.h> 116241874Smarius#include <sys/rman.h> 117241874Smarius#include <sys/types.h> 118147883Sscottl 119241874Smarius#include <machine/bus.h> 120147883Sscottl#include <machine/cpu.h> 121147883Sscottl#include <machine/resource.h> 122147883Sscottl 123207287Smarius#ifdef __sparc64__ 124207287Smarius#include <dev/ofw/openfirm.h> 125207287Smarius#include <machine/ofw_machdep.h> 126207287Smarius#endif 127207287Smarius 128155521Smjacob#include <dev/pci/pcireg.h> 129155521Smjacob#include <dev/pci/pcivar.h> 130155521Smjacob 131147883Sscottl#include "opt_ddb.h" 132147883Sscottl 133147883Sscottl/**************************** Register Definitions ****************************/ 134147883Sscottl#include <dev/mpt/mpt_reg.h> 135147883Sscottl 136147883Sscottl/******************************* MPI Definitions ******************************/ 137147883Sscottl#include <dev/mpt/mpilib/mpi_type.h> 138147883Sscottl#include <dev/mpt/mpilib/mpi.h> 139147883Sscottl#include <dev/mpt/mpilib/mpi_cnfg.h> 140147883Sscottl#include <dev/mpt/mpilib/mpi_ioc.h> 141147883Sscottl#include <dev/mpt/mpilib/mpi_raid.h> 142147883Sscottl 143147883Sscottl/* XXX For mpt_debug.c */ 144147883Sscottl#include <dev/mpt/mpilib/mpi_init.h> 145147883Sscottl 146164990Smjacob#define MPT_S64_2_SCALAR(y) ((((int64_t)y.High) << 32) | (y.Low)) 147164990Smjacob#define MPT_U64_2_SCALAR(y) ((((uint64_t)y.High) << 32) | (y.Low)) 148164990Smjacob 149147883Sscottl/****************************** Misc Definitions ******************************/ 150165814Smjacob/* #define MPT_TEST_MULTIPATH 1 */ 151101704Smjacob#define MPT_OK (0) 152101704Smjacob#define MPT_FAIL (0x10000) 153101704Smjacob 154147883Sscottl#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array)) 155101704Smjacob 156157117Smjacob#define MPT_ROLE_NONE 0 157157117Smjacob#define MPT_ROLE_INITIATOR 1 158157117Smjacob#define MPT_ROLE_TARGET 2 159157117Smjacob#define MPT_ROLE_BOTH 3 160157117Smjacob#define MPT_ROLE_DEFAULT MPT_ROLE_INITIATOR 161157117Smjacob 162207287Smarius#define MPT_INI_ID_NONE -1 163207287Smarius 164147883Sscottl/**************************** Forward Declarations ****************************/ 165147883Sscottlstruct mpt_softc; 166147883Sscottlstruct mpt_personality; 167147883Sscottltypedef struct req_entry request_t; 168101704Smjacob 169147883Sscottl/************************* Personality Module Support *************************/ 170147883Sscottltypedef int mpt_load_handler_t(struct mpt_personality *); 171147883Sscottltypedef int mpt_probe_handler_t(struct mpt_softc *); 172147883Sscottltypedef int mpt_attach_handler_t(struct mpt_softc *); 173157117Smjacobtypedef int mpt_enable_handler_t(struct mpt_softc *); 174162133Smjacobtypedef void mpt_ready_handler_t(struct mpt_softc *); 175147883Sscottltypedef int mpt_event_handler_t(struct mpt_softc *, request_t *, 176147883Sscottl MSG_EVENT_NOTIFY_REPLY *); 177147883Sscottltypedef void mpt_reset_handler_t(struct mpt_softc *, int /*type*/); 178147883Sscottl/* XXX Add return value and use for veto? */ 179147883Sscottltypedef void mpt_shutdown_handler_t(struct mpt_softc *); 180147883Sscottltypedef void mpt_detach_handler_t(struct mpt_softc *); 181147883Sscottltypedef int mpt_unload_handler_t(struct mpt_personality *); 182147883Sscottl 183147883Sscottlstruct mpt_personality 184147883Sscottl{ 185147883Sscottl const char *name; 186147883Sscottl uint32_t id; /* Assigned identifier. */ 187147883Sscottl u_int use_count; /* Instances using personality*/ 188147883Sscottl mpt_load_handler_t *load; /* configure personailty */ 189147883Sscottl#define MPT_PERS_FIRST_HANDLER(pers) (&(pers)->load) 190147883Sscottl mpt_probe_handler_t *probe; /* configure personailty */ 191147883Sscottl mpt_attach_handler_t *attach; /* initialize device instance */ 192157117Smjacob mpt_enable_handler_t *enable; /* enable device */ 193162133Smjacob mpt_ready_handler_t *ready; /* final open for business */ 194147883Sscottl mpt_event_handler_t *event; /* Handle MPI event. */ 195147883Sscottl mpt_reset_handler_t *reset; /* Re-init after reset. */ 196147883Sscottl mpt_shutdown_handler_t *shutdown; /* Shutdown instance. */ 197147883Sscottl mpt_detach_handler_t *detach; /* release device instance */ 198147883Sscottl mpt_unload_handler_t *unload; /* Shutdown personality */ 199147883Sscottl#define MPT_PERS_LAST_HANDLER(pers) (&(pers)->unload) 200101704Smjacob}; 201101704Smjacob 202147883Sscottlint mpt_modevent(module_t, int, void *); 203101704Smjacob 204147883Sscottl/* Maximum supported number of personalities. */ 205147883Sscottl#define MPT_MAX_PERSONALITIES (15) 206101704Smjacob 207147883Sscottl#define MPT_PERSONALITY_DEPEND(name, dep, vmin, vpref, vmax) \ 208147883Sscottl MODULE_DEPEND(name, dep, vmin, vpref, vmax) 209101704Smjacob 210147883Sscottl#define DECLARE_MPT_PERSONALITY(name, order) \ 211147883Sscottl static moduledata_t name##_mod = { \ 212147883Sscottl #name, mpt_modevent, &name##_personality \ 213147883Sscottl }; \ 214147883Sscottl DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, order); \ 215147883Sscottl MODULE_VERSION(name, 1); \ 216147883Sscottl MPT_PERSONALITY_DEPEND(name, mpt_core, 1, 1, 1) 217147883Sscottl 218147883Sscottl/******************************* Bus DMA Support ******************************/ 219147883Sscottl/* XXX Need to update bus_dmamap_sync to take a range argument. */ 220147883Sscottl#define bus_dmamap_sync_range(dma_tag, dmamap, offset, len, op) \ 221147883Sscottl bus_dmamap_sync(dma_tag, dmamap, op) 222147883Sscottl 223167426Smjacob#if __FreeBSD_version < 600000 224167426Smjacob#define bus_get_dma_tag(x) NULL 225167426Smjacob#endif 226147883Sscottl#define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary, \ 227147883Sscottl lowaddr, highaddr, filter, filterarg, \ 228147883Sscottl maxsize, nsegments, maxsegsz, flags, \ 229147883Sscottl dma_tagp) \ 230147883Sscottl bus_dma_tag_create(parent_tag, alignment, boundary, \ 231147883Sscottl lowaddr, highaddr, filter, filterarg, \ 232147883Sscottl maxsize, nsegments, maxsegsz, flags, \ 233169293Smjacob busdma_lock_mutex, &(mpt)->mpt_lock, \ 234147883Sscottl dma_tagp) 235147883Sscottlstruct mpt_map_info { 236147883Sscottl struct mpt_softc *mpt; 237147883Sscottl int error; 238147883Sscottl uint32_t phys; 239147883Sscottl}; 240147883Sscottl 241147883Sscottlvoid mpt_map_rquest(void *, bus_dma_segment_t *, int, int); 242166935Smjacob/* **************************** NewBUS interrupt Crock ************************/ 243166935Smjacob#if __FreeBSD_version < 700031 244166935Smjacob#define mpt_setup_intr(d, i, f, U, if, ifa, hp) \ 245166935Smjacob bus_setup_intr(d, i, f, if, ifa, hp) 246166935Smjacob#else 247166935Smjacob#define mpt_setup_intr bus_setup_intr 248166935Smjacob#endif 249147883Sscottl 250178725Sjkim/* **************************** NewBUS CAM Support ****************************/ 251178725Sjkim#if __FreeBSD_version < 700049 252178725Sjkim#define mpt_xpt_bus_register(sim, parent, bus) \ 253178725Sjkim xpt_bus_register(sim, bus) 254178725Sjkim#else 255178725Sjkim#define mpt_xpt_bus_register xpt_bus_register 256178725Sjkim#endif 257178725Sjkim 258147883Sscottl/**************************** Kernel Thread Support ***************************/ 259172842Sjulian#if __FreeBSD_version > 800001 260147883Sscottl#define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 261172836Sjulian kproc_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) 262178725Sjkim#define mpt_kthread_exit(status) \ 263178725Sjkim kproc_exit(status) 264241874Smarius#else 265147883Sscottl#define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 266172842Sjulian kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) 267178725Sjkim#define mpt_kthread_exit(status) \ 268178725Sjkim kthread_exit(status) 269172842Sjulian#endif 270147883Sscottl 271147883Sscottl/********************************** Endianess *********************************/ 272164990Smjacob#define MPT_2_HOST64(ptr, tag) ptr->tag = le64toh(ptr->tag) 273164990Smjacob#define MPT_2_HOST32(ptr, tag) ptr->tag = le32toh(ptr->tag) 274164990Smjacob#define MPT_2_HOST16(ptr, tag) ptr->tag = le16toh(ptr->tag) 275147883Sscottl 276164990Smjacob#define HOST_2_MPT64(ptr, tag) ptr->tag = htole64(ptr->tag) 277164990Smjacob#define HOST_2_MPT32(ptr, tag) ptr->tag = htole32(ptr->tag) 278164990Smjacob#define HOST_2_MPT16(ptr, tag) ptr->tag = htole16(ptr->tag) 279147883Sscottl 280164998Smjacob#if _BYTE_ORDER == _BIG_ENDIAN 281164998Smjacobvoid mpt2host_sge_simple_union(SGE_SIMPLE_UNION *); 282164998Smjacobvoid mpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *); 283164998Smjacobvoid mpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *); 284164998Smjacobvoid mpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *); 285186878Smariusvoid mpt2host_config_page_ioc3(CONFIG_PAGE_IOC_3 *); 286186878Smariusvoid mpt2host_config_page_scsi_port_0(CONFIG_PAGE_SCSI_PORT_0 *); 287186878Smariusvoid mpt2host_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *); 288186878Smariusvoid host2mpt_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *); 289186878Smariusvoid mpt2host_config_page_scsi_port_2(CONFIG_PAGE_SCSI_PORT_2 *); 290186878Smariusvoid mpt2host_config_page_scsi_device_0(CONFIG_PAGE_SCSI_DEVICE_0 *); 291186878Smariusvoid mpt2host_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *); 292186878Smariusvoid host2mpt_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *); 293186878Smariusvoid mpt2host_config_page_fc_port_0(CONFIG_PAGE_FC_PORT_0 *); 294186878Smariusvoid mpt2host_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *); 295186878Smariusvoid host2mpt_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *); 296164998Smjacobvoid mpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *); 297186878Smariusvoid mpt2host_config_page_raid_phys_disk_0(CONFIG_PAGE_RAID_PHYS_DISK_0 *); 298164998Smjacobvoid mpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *); 299164998Smjacob#else 300164990Smjacob#define mpt2host_sge_simple_union(x) do { ; } while (0) 301164990Smjacob#define mpt2host_iocfacts_reply(x) do { ; } while (0) 302164990Smjacob#define mpt2host_portfacts_reply(x) do { ; } while (0) 303164990Smjacob#define mpt2host_config_page_ioc2(x) do { ; } while (0) 304186878Smarius#define mpt2host_config_page_ioc3(x) do { ; } while (0) 305186878Smarius#define mpt2host_config_page_scsi_port_0(x) do { ; } while (0) 306186878Smarius#define mpt2host_config_page_scsi_port_1(x) do { ; } while (0) 307186878Smarius#define host2mpt_config_page_scsi_port_1(x) do { ; } while (0) 308186878Smarius#define mpt2host_config_page_scsi_port_2(x) do { ; } while (0) 309186878Smarius#define mpt2host_config_page_scsi_device_0(x) do { ; } while (0) 310186878Smarius#define mpt2host_config_page_scsi_device_1(x) do { ; } while (0) 311186878Smarius#define host2mpt_config_page_scsi_device_1(x) do { ; } while (0) 312186878Smarius#define mpt2host_config_page_fc_port_0(x) do { ; } while (0) 313186878Smarius#define mpt2host_config_page_fc_port_1(x) do { ; } while (0) 314186878Smarius#define host2mpt_config_page_fc_port_1(x) do { ; } while (0) 315164990Smjacob#define mpt2host_config_page_raid_vol_0(x) do { ; } while (0) 316186878Smarius#define mpt2host_config_page_raid_phys_disk_0(x) \ 317186878Smarius do { ; } while (0) 318164990Smjacob#define mpt2host_mpi_raid_vol_indicator(x) do { ; } while (0) 319164990Smjacob#endif 320164990Smjacob 321147883Sscottl/**************************** MPI Transaction State ***************************/ 322147883Sscottltypedef enum { 323157354Smjacob REQ_STATE_NIL = 0x00, 324157354Smjacob REQ_STATE_FREE = 0x01, 325157354Smjacob REQ_STATE_ALLOCATED = 0x02, 326157354Smjacob REQ_STATE_QUEUED = 0x04, 327157354Smjacob REQ_STATE_DONE = 0x08, 328157354Smjacob REQ_STATE_TIMEDOUT = 0x10, 329157354Smjacob REQ_STATE_NEED_WAKEUP = 0x20, 330157354Smjacob REQ_STATE_LOCKED = 0x80, /* can't be freed */ 331147883Sscottl REQ_STATE_MASK = 0xFF 332147883Sscottl} mpt_req_state_t; 333147883Sscottl 334147883Sscottlstruct req_entry { 335147883Sscottl TAILQ_ENTRY(req_entry) links; /* Pointer to next in list */ 336147883Sscottl mpt_req_state_t state; /* Request State Information */ 337147883Sscottl uint16_t index; /* Index of this entry */ 338147883Sscottl uint16_t IOCStatus; /* Completion status */ 339220945Smarius uint16_t ResponseCode; /* TMF Response Code */ 340157662Smjacob uint16_t serno; /* serial number */ 341147883Sscottl union ccb *ccb; /* CAM request */ 342147883Sscottl void *req_vbuf; /* Virtual Address of Entry */ 343147883Sscottl void *sense_vbuf; /* Virtual Address of sense data */ 344147883Sscottl bus_addr_t req_pbuf; /* Physical Address of Entry */ 345147883Sscottl bus_addr_t sense_pbuf; /* Physical Address of sense data */ 346159312Smjacob bus_dmamap_t dmap; /* DMA map for data buffers */ 347155521Smjacob struct req_entry *chain; /* for SGE overallocations */ 348169293Smjacob struct callout callout; /* Timeout for the request */ 349147883Sscottl}; 350147883Sscottl 351170252Sscottltypedef struct mpt_config_params { 352170252Sscottl u_int Action; 353170252Sscottl u_int PageVersion; 354170252Sscottl u_int PageLength; 355170252Sscottl u_int PageNumber; 356170252Sscottl u_int PageType; 357170252Sscottl u_int PageAddress; 358170252Sscottl u_int ExtPageLength; 359170252Sscottl u_int ExtPageType; 360170252Sscottl} cfgparms_t; 361170252Sscottl 362157117Smjacob/**************************** MPI Target State Info ***************************/ 363157117Smjacob 364157117Smjacobtypedef struct { 365157117Smjacob uint32_t reply_desc; /* current reply descriptor */ 366157117Smjacob uint32_t resid; /* current data residual */ 367157117Smjacob uint32_t bytes_xfered; /* current relative offset */ 368157117Smjacob union ccb *ccb; /* pointer to currently active ccb */ 369157117Smjacob request_t *req; /* pointer to currently active assist request */ 370160391Smjacob uint32_t 371160391Smjacob is_local : 1, 372160391Smjacob nxfers : 31; 373157354Smjacob uint32_t tag_id; 374157117Smjacob enum { 375157117Smjacob TGT_STATE_NIL, 376157354Smjacob TGT_STATE_LOADING, 377157117Smjacob TGT_STATE_LOADED, 378157117Smjacob TGT_STATE_IN_CAM, 379157117Smjacob TGT_STATE_SETTING_UP_FOR_DATA, 380157117Smjacob TGT_STATE_MOVING_DATA, 381157117Smjacob TGT_STATE_MOVING_DATA_AND_STATUS, 382157117Smjacob TGT_STATE_SENDING_STATUS 383157117Smjacob } state; 384157117Smjacob} mpt_tgt_state_t; 385157117Smjacob 386157117Smjacob/* 387157117Smjacob * When we get an incoming command it has its own tag which is called the 388157117Smjacob * IoIndex. This is the value we gave that particular command buffer when 389157117Smjacob * we originally assigned it. It's just a number, really. The FC card uses 390157117Smjacob * it as an RX_ID. We can use it to index into mpt->tgt_cmd_ptrs, which 391157117Smjacob * contains pointers the request_t structures related to that IoIndex. 392157117Smjacob * 393157117Smjacob * What *we* do is construct a tag out of the index for the target command 394157117Smjacob * which owns the incoming ATIO plus a rolling sequence number. 395157117Smjacob */ 396157117Smjacob#define MPT_MAKE_TAGID(mpt, req, ioindex) \ 397157354Smjacob ((ioindex << 18) | (((mpt->sequence++) & 0x3f) << 12) | (req->index & 0xfff)) 398157117Smjacob 399157117Smjacob#ifdef INVARIANTS 400157117Smjacob#define MPT_TAG_2_REQ(a, b) mpt_tag_2_req(a, (uint32_t) b) 401157117Smjacob#else 402157354Smjacob#define MPT_TAG_2_REQ(mpt, tag) mpt->tgt_cmd_ptrs[tag >> 18] 403157117Smjacob#endif 404157117Smjacob 405157117Smjacob#define MPT_TGT_STATE(mpt, req) ((mpt_tgt_state_t *) \ 406157117Smjacob (&((uint8_t *)req->req_vbuf)[MPT_RQSL(mpt) - sizeof (mpt_tgt_state_t)])) 407157117Smjacob 408157117SmjacobSTAILQ_HEAD(mpt_hdr_stailq, ccb_hdr); 409157117Smjacob#define MPT_MAX_LUNS 256 410157117Smjacobtypedef struct { 411157117Smjacob struct mpt_hdr_stailq atios; 412157117Smjacob struct mpt_hdr_stailq inots; 413157117Smjacob int enabled; 414157117Smjacob} tgt_resource_t; 415157662Smjacob#define MPT_MAX_ELS 64 416157117Smjacob 417147883Sscottl/**************************** Handler Registration ****************************/ 418101704Smjacob/* 419147883Sscottl * Global table of registered reply handlers. The 420147883Sscottl * handler is indicated by byte 3 of the request 421147883Sscottl * index submitted to the IOC. This allows the 422147883Sscottl * driver core to perform generic processing without 423147883Sscottl * any knowledge of per-personality behavior. 424147883Sscottl * 425147883Sscottl * MPT_NUM_REPLY_HANDLERS must be a power of 2 426147883Sscottl * to allow the easy generation of a mask. 427147883Sscottl * 428147883Sscottl * The handler offsets used by the core are hard coded 429147883Sscottl * allowing faster code generation when assigning a handler 430147883Sscottl * to a request. All "personalities" must use the 431147883Sscottl * the handler registration mechanism. 432147883Sscottl * 433147883Sscottl * The IOC handlers that are rarely executed are placed 434147883Sscottl * at the tail of the table to make it more likely that 435147883Sscottl * all commonly executed handlers fit in a single cache 436147883Sscottl * line. 437101704Smjacob */ 438157117Smjacob#define MPT_NUM_REPLY_HANDLERS (32) 439147883Sscottl#define MPT_REPLY_HANDLER_EVENTS MPT_CBI_TO_HID(0) 440147883Sscottl#define MPT_REPLY_HANDLER_CONFIG MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-1) 441147883Sscottl#define MPT_REPLY_HANDLER_HANDSHAKE MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-2) 442147883Sscottltypedef int mpt_reply_handler_t(struct mpt_softc *mpt, request_t *request, 443157117Smjacob uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame); 444147883Sscottltypedef union { 445147883Sscottl mpt_reply_handler_t *reply_handler; 446147883Sscottl} mpt_handler_t; 447101704Smjacob 448147883Sscottltypedef enum { 449147883Sscottl MPT_HANDLER_REPLY, 450147883Sscottl MPT_HANDLER_EVENT, 451147883Sscottl MPT_HANDLER_RESET, 452147883Sscottl MPT_HANDLER_SHUTDOWN 453147883Sscottl} mpt_handler_type; 454101704Smjacob 455147883Sscottlstruct mpt_handler_record 456147883Sscottl{ 457147883Sscottl LIST_ENTRY(mpt_handler_record) links; 458147883Sscottl mpt_handler_t handler; 459101704Smjacob}; 460101704Smjacob 461147883SscottlLIST_HEAD(mpt_handler_list, mpt_handler_record); 462147883Sscottl 463147883Sscottl/* 464147883Sscottl * The handler_id is currently unused but would contain the 465147883Sscottl * handler ID used in the MsgContext field to allow direction 466147883Sscottl * of replies to the handler. Registrations that don't require 467147883Sscottl * a handler id can pass in NULL for the handler_id. 468147883Sscottl * 469147883Sscottl * Deregistrations for handlers without a handler id should 470147883Sscottl * pass in MPT_HANDLER_ID_NONE. 471147883Sscottl */ 472147883Sscottl#define MPT_HANDLER_ID_NONE (0xFFFFFFFF) 473147883Sscottlint mpt_register_handler(struct mpt_softc *, mpt_handler_type, 474147883Sscottl mpt_handler_t, uint32_t *); 475147883Sscottlint mpt_deregister_handler(struct mpt_softc *, mpt_handler_type, 476147883Sscottl mpt_handler_t, uint32_t); 477147883Sscottl 478147883Sscottl/******************* Per-Controller Instance Data Structures ******************/ 479147883SscottlTAILQ_HEAD(req_queue, req_entry); 480147883Sscottl 481147883Sscottl/* Structure for saving proper values for modifyable PCI config registers */ 482147883Sscottlstruct mpt_pci_cfg { 483147883Sscottl uint16_t Command; 484147883Sscottl uint16_t LatencyTimer_LineSize; 485147883Sscottl uint32_t IO_BAR; 486147883Sscottl uint32_t Mem0_BAR[2]; 487147883Sscottl uint32_t Mem1_BAR[2]; 488147883Sscottl uint32_t ROM_BAR; 489147883Sscottl uint8_t IntLine; 490147883Sscottl uint32_t PMCSR; 491101704Smjacob}; 492101704Smjacob 493147883Sscottltypedef enum { 494147883Sscottl MPT_RVF_NONE = 0x0, 495147883Sscottl MPT_RVF_ACTIVE = 0x1, 496147883Sscottl MPT_RVF_ANNOUNCED = 0x2, 497147883Sscottl MPT_RVF_UP2DATE = 0x4, 498147883Sscottl MPT_RVF_REFERENCED = 0x8, 499147883Sscottl MPT_RVF_WCE_CHANGED = 0x10 500147883Sscottl} mpt_raid_volume_flags; 501101704Smjacob 502147883Sscottlstruct mpt_raid_volume { 503147883Sscottl CONFIG_PAGE_RAID_VOL_0 *config_page; 504147883Sscottl MPI_RAID_VOL_INDICATOR sync_progress; 505147883Sscottl mpt_raid_volume_flags flags; 506158933Smjacob u_int quiesced_disks; 507101704Smjacob}; 508101704Smjacob 509147883Sscottltypedef enum { 510147883Sscottl MPT_RDF_NONE = 0x00, 511147883Sscottl MPT_RDF_ACTIVE = 0x01, 512147883Sscottl MPT_RDF_ANNOUNCED = 0x02, 513147883Sscottl MPT_RDF_UP2DATE = 0x04, 514147883Sscottl MPT_RDF_REFERENCED = 0x08, 515147883Sscottl MPT_RDF_QUIESCING = 0x10, 516147883Sscottl MPT_RDF_QUIESCED = 0x20 517147883Sscottl} mpt_raid_disk_flags; 518147883Sscottl 519147883Sscottlstruct mpt_raid_disk { 520147883Sscottl CONFIG_PAGE_RAID_PHYS_DISK_0 config_page; 521147883Sscottl struct mpt_raid_volume *volume; 522147883Sscottl u_int member_number; 523147883Sscottl u_int pass_thru_active; 524147883Sscottl mpt_raid_disk_flags flags; 525101704Smjacob}; 526101704Smjacob 527147883Sscottlstruct mpt_evtf_record { 528147883Sscottl MSG_EVENT_NOTIFY_REPLY reply; 529147883Sscottl uint32_t context; 530147883Sscottl LIST_ENTRY(mpt_evtf_record) links; 531147883Sscottl}; 532101704Smjacob 533147883SscottlLIST_HEAD(mpt_evtf_list, mpt_evtf_record); 534101704Smjacob 535170252Sscottlstruct mptsas_devinfo { 536170252Sscottl uint16_t dev_handle; 537170252Sscottl uint16_t parent_dev_handle; 538170252Sscottl uint16_t enclosure_handle; 539170252Sscottl uint16_t slot; 540170252Sscottl uint8_t phy_num; 541170252Sscottl uint8_t physical_port; 542170252Sscottl uint8_t target_id; 543170252Sscottl uint8_t bus; 544170252Sscottl uint64_t sas_address; 545170252Sscottl uint32_t device_info; 546170252Sscottl}; 547170252Sscottl 548170252Sscottlstruct mptsas_phyinfo { 549170252Sscottl uint16_t handle; 550170252Sscottl uint8_t phy_num; 551170252Sscottl uint8_t port_id; 552170252Sscottl uint8_t negotiated_link_rate; 553170252Sscottl uint8_t hw_link_rate; 554170252Sscottl uint8_t programmed_link_rate; 555170252Sscottl uint8_t sas_port_add_phy; 556170252Sscottl struct mptsas_devinfo identify; 557170252Sscottl struct mptsas_devinfo attached; 558170252Sscottl}; 559170252Sscottl 560170252Sscottlstruct mptsas_portinfo { 561170252Sscottl uint16_t num_phys; 562170252Sscottl struct mptsas_phyinfo *phy_info; 563170252Sscottl}; 564170252Sscottl 565147883Sscottlstruct mpt_softc { 566147883Sscottl device_t dev; 567147883Sscottl struct mtx mpt_lock; 568157662Smjacob int mpt_locksetup; 569147883Sscottl uint32_t mpt_pers_mask; 570160290Smjacob uint32_t 571231518Smarius : 7, 572157117Smjacob unit : 8, 573165814Smjacob ready : 1, 574164990Smjacob fw_uploaded : 1, 575164416Smjacob msi_enable : 1, 576157117Smjacob twildcard : 1, 577157117Smjacob tenabled : 1, 578160290Smjacob do_cfg_role : 1, 579158982Smjacob raid_enabled : 1, 580147883Sscottl raid_mwce_set : 1, 581147883Sscottl getreqwaiter : 1, 582147883Sscottl shutdwn_raid : 1, 583147883Sscottl shutdwn_recovery: 1, 584147883Sscottl outofbeer : 1, 585147883Sscottl disabled : 1, 586159178Smjacob is_spi : 1, 587157117Smjacob is_sas : 1, 588231518Smarius is_fc : 1, 589231518Smarius is_1078 : 1; 590101704Smjacob 591160290Smjacob u_int cfg_role; 592160290Smjacob u_int role; /* role: none, ini, target, both */ 593160290Smjacob 594147883Sscottl u_int verbose; 595165814Smjacob#ifdef MPT_TEST_MULTIPATH 596165814Smjacob int failure_id; 597165814Smjacob#endif 598101704Smjacob 599147883Sscottl /* 600147883Sscottl * IOC Facts 601147883Sscottl */ 602164990Smjacob MSG_IOC_FACTS_REPLY ioc_facts; 603101704Smjacob 604147883Sscottl /* 605147883Sscottl * Port Facts 606147883Sscottl */ 607164990Smjacob MSG_PORT_FACTS_REPLY * port_facts; 608164990Smjacob#define mpt_max_tgtcmds port_facts[0].MaxPostedCmdBuffers 609102822Smjacob 610147883Sscottl /* 611147883Sscottl * Device Configuration Information 612147883Sscottl */ 613147883Sscottl union { 614147883Sscottl struct mpt_spi_cfg { 615147883Sscottl CONFIG_PAGE_SCSI_PORT_0 _port_page0; 616147883Sscottl CONFIG_PAGE_SCSI_PORT_1 _port_page1; 617147883Sscottl CONFIG_PAGE_SCSI_PORT_2 _port_page2; 618147883Sscottl CONFIG_PAGE_SCSI_DEVICE_0 _dev_page0[16]; 619147883Sscottl CONFIG_PAGE_SCSI_DEVICE_1 _dev_page1[16]; 620207287Smarius int _ini_id; 621147883Sscottl uint16_t _tag_enable; 622147883Sscottl uint16_t _disc_enable; 623147883Sscottl } spi; 624147883Sscottl#define mpt_port_page0 cfg.spi._port_page0 625147883Sscottl#define mpt_port_page1 cfg.spi._port_page1 626147883Sscottl#define mpt_port_page2 cfg.spi._port_page2 627147883Sscottl#define mpt_dev_page0 cfg.spi._dev_page0 628147883Sscottl#define mpt_dev_page1 cfg.spi._dev_page1 629207287Smarius#define mpt_ini_id cfg.spi._ini_id 630147883Sscottl#define mpt_tag_enable cfg.spi._tag_enable 631147883Sscottl#define mpt_disc_enable cfg.spi._disc_enable 632147883Sscottl struct mpi_fc_cfg { 633157117Smjacob CONFIG_PAGE_FC_PORT_0 _port_page0; 634159919Smjacob uint32_t _port_speed; 635157117Smjacob#define mpt_fcport_page0 cfg.fc._port_page0 636159919Smjacob#define mpt_fcport_speed cfg.fc._port_speed 637147883Sscottl } fc; 638147883Sscottl } cfg; 639160397Smjacob /* 640160397Smjacob * Device config information stored up for sysctl to access 641160397Smjacob */ 642160397Smjacob union { 643160397Smjacob struct { 644160397Smjacob unsigned int initiator_id; 645160397Smjacob } spi; 646160397Smjacob struct { 647160397Smjacob char wwnn[19]; 648160397Smjacob char wwpn[19]; 649160397Smjacob } fc; 650160397Smjacob } scinfo; 651147883Sscottl 652158982Smjacob /* Controller Info for RAID information */ 653147883Sscottl CONFIG_PAGE_IOC_2 * ioc_page2; 654147883Sscottl CONFIG_PAGE_IOC_3 * ioc_page3; 655147883Sscottl 656147883Sscottl /* Raid Data */ 657147883Sscottl struct mpt_raid_volume* raid_volumes; 658147883Sscottl struct mpt_raid_disk* raid_disks; 659147883Sscottl u_int raid_max_volumes; 660147883Sscottl u_int raid_max_disks; 661147883Sscottl u_int raid_page0_len; 662147883Sscottl u_int raid_wakeup; 663147883Sscottl u_int raid_rescan; 664147883Sscottl u_int raid_resync_rate; 665147883Sscottl u_int raid_mwce_setting; 666147883Sscottl u_int raid_queue_depth; 667152444Skan u_int raid_nonopt_volumes; 668147883Sscottl struct proc *raid_thread; 669147883Sscottl struct callout raid_timer; 670147883Sscottl 671147883Sscottl /* 672147883Sscottl * PCI Hardware info 673147883Sscottl */ 674164305Sjhb int pci_msi_count; 675147883Sscottl struct resource * pci_irq; /* Interrupt map for chip */ 676220945Smarius void * ih; /* Interrupt handle */ 677233403Smarius#if 0 678147883Sscottl struct mpt_pci_cfg pci_cfg; /* saved PCI conf registers */ 679233403Smarius#endif 680147883Sscottl 681147883Sscottl /* 682147883Sscottl * DMA Mapping Stuff 683147883Sscottl */ 684147883Sscottl struct resource * pci_reg; /* Register map for chip */ 685147883Sscottl bus_space_tag_t pci_st; /* Bus tag for registers */ 686147883Sscottl bus_space_handle_t pci_sh; /* Bus handle for registers */ 687147883Sscottl /* PIO versions of above. */ 688147883Sscottl struct resource * pci_pio_reg; 689147883Sscottl bus_space_tag_t pci_pio_st; 690147883Sscottl bus_space_handle_t pci_pio_sh; 691147883Sscottl 692147883Sscottl bus_dma_tag_t parent_dmat; /* DMA tag for parent PCI bus */ 693147883Sscottl bus_dma_tag_t reply_dmat; /* DMA tag for reply memory */ 694147883Sscottl bus_dmamap_t reply_dmap; /* DMA map for reply memory */ 695147883Sscottl uint8_t *reply; /* KVA of reply memory */ 696147883Sscottl bus_addr_t reply_phys; /* BusAddr of reply memory */ 697147883Sscottl 698147883Sscottl bus_dma_tag_t buffer_dmat; /* DMA tag for buffers */ 699147883Sscottl bus_dma_tag_t request_dmat; /* DMA tag for request memroy */ 700147883Sscottl bus_dmamap_t request_dmap; /* DMA map for request memroy */ 701147883Sscottl uint8_t *request; /* KVA of Request memory */ 702157117Smjacob bus_addr_t request_phys; /* BusAddr of request memory */ 703147883Sscottl 704155521Smjacob uint32_t max_seg_cnt; /* calculated after IOC facts */ 705209599Sken uint32_t max_cam_seg_cnt;/* calculated from MAXPHYS*/ 706155521Smjacob 707155521Smjacob /* 708155521Smjacob * Hardware management 709155521Smjacob */ 710147883Sscottl u_int reset_cnt; 711147883Sscottl 712147883Sscottl /* 713147883Sscottl * CAM && Software Management 714147883Sscottl */ 715147883Sscottl request_t *request_pool; 716147883Sscottl struct req_queue request_free_list; 717147883Sscottl struct req_queue request_pending_list; 718147883Sscottl struct req_queue request_timeout_list; 719147883Sscottl 720147883Sscottl 721147883Sscottl struct cam_sim *sim; 722147883Sscottl struct cam_path *path; 723147883Sscottl 724147883Sscottl struct cam_sim *phydisk_sim; 725147883Sscottl struct cam_path *phydisk_path; 726147883Sscottl 727147883Sscottl struct proc *recovery_thread; 728147883Sscottl request_t *tmf_req; 729147883Sscottl 730157117Smjacob /* 731157354Smjacob * Deferred frame acks due to resource shortage. 732157354Smjacob */ 733157354Smjacob struct mpt_evtf_list ack_frames; 734159312Smjacob 735157354Smjacob /* 736157117Smjacob * Target Mode Support 737157117Smjacob */ 738157117Smjacob uint32_t scsi_tgt_handler_id; 739157117Smjacob request_t ** tgt_cmd_ptrs; 740157662Smjacob request_t ** els_cmd_ptrs; /* FC only */ 741147883Sscottl 742157117Smjacob /* 743157117Smjacob * *snork*- this is chosen to be here *just in case* somebody 744157117Smjacob * forgets to point to it exactly and we index off of trt with 745157117Smjacob * CAM_LUN_WILDCARD. 746157117Smjacob */ 747160391Smjacob tgt_resource_t trt_wildcard; /* wildcard luns */ 748157117Smjacob tgt_resource_t trt[MPT_MAX_LUNS]; 749157117Smjacob uint16_t tgt_cmds_allocated; 750157662Smjacob uint16_t els_cmds_allocated; /* FC only */ 751157117Smjacob 752157117Smjacob uint16_t timeouts; /* timeout count */ 753157117Smjacob uint16_t success; /* successes afer timeout */ 754157662Smjacob uint16_t sequence; /* Sequence Number */ 755157662Smjacob uint16_t pad3; 756157117Smjacob 757157117Smjacob 758159312Smjacob /* Paired port in some dual adapters configurations */ 759147883Sscottl struct mpt_softc * mpt2; 760147883Sscottl 761147883Sscottl /* FW Image management */ 762147883Sscottl uint32_t fw_image_size; 763147883Sscottl uint8_t *fw_image; 764147883Sscottl bus_dma_tag_t fw_dmat; /* DMA tag for firmware image */ 765147883Sscottl bus_dmamap_t fw_dmap; /* DMA map for firmware image */ 766159178Smjacob bus_addr_t fw_phys; /* BusAddr of firmware image */ 767147883Sscottl 768170252Sscottl /* SAS Topology */ 769170252Sscottl struct mptsas_portinfo *sas_portinfo; 770170252Sscottl 771147883Sscottl /* Shutdown Event Handler. */ 772147883Sscottl eventhandler_tag eh; 773147883Sscottl 774178814Sjhb /* Userland management interface. */ 775178814Sjhb struct cdev *cdev; 776178814Sjhb 777147883Sscottl TAILQ_ENTRY(mpt_softc) links; 778147883Sscottl}; 779147883Sscottl 780157662Smjacobstatic __inline void mpt_assign_serno(struct mpt_softc *, request_t *); 781157662Smjacob 782157662Smjacobstatic __inline void 783157662Smjacobmpt_assign_serno(struct mpt_softc *mpt, request_t *req) 784157662Smjacob{ 785157662Smjacob if ((req->serno = mpt->sequence++) == 0) { 786157662Smjacob req->serno = mpt->sequence++; 787157662Smjacob } 788157662Smjacob} 789157662Smjacob 790157117Smjacob/***************************** Locking Primitives *****************************/ 791147883Sscottl#define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE 792147883Sscottl#define MPT_LOCK_SETUP(mpt) \ 793147883Sscottl mtx_init(&mpt->mpt_lock, "mpt", NULL, MTX_DEF); \ 794147883Sscottl mpt->mpt_locksetup = 1 795147883Sscottl#define MPT_LOCK_DESTROY(mpt) \ 796147883Sscottl if (mpt->mpt_locksetup) { \ 797147883Sscottl mtx_destroy(&mpt->mpt_lock); \ 798147883Sscottl mpt->mpt_locksetup = 0; \ 799147883Sscottl } 800147883Sscottl 801147883Sscottl#define MPT_LOCK(mpt) mtx_lock(&(mpt)->mpt_lock) 802147883Sscottl#define MPT_UNLOCK(mpt) mtx_unlock(&(mpt)->mpt_lock) 803157662Smjacob#define MPT_OWNED(mpt) mtx_owned(&(mpt)->mpt_lock) 804169293Smjacob#define MPT_LOCK_ASSERT(mpt) mtx_assert(&(mpt)->mpt_lock, MA_OWNED) 805147883Sscottl#define mpt_sleep(mpt, ident, priority, wmesg, timo) \ 806147883Sscottl msleep(ident, &(mpt)->mpt_lock, priority, wmesg, timo) 807169293Smjacob#define mpt_req_timeout(req, ticks, func, arg) \ 808198262Skan callout_reset(&(req)->callout, (ticks), (func), (arg)) 809169293Smjacob#define mpt_req_untimeout(req, func, arg) \ 810169293Smjacob callout_stop(&(req)->callout) 811198262Skan#define mpt_callout_init(mpt, c) \ 812198262Skan callout_init_mtx(c, &(mpt)->mpt_lock, 0) 813198262Skan#define mpt_callout_drain(mpt, c) \ 814198262Skan callout_drain(c) 815157662Smjacob 816147883Sscottl/******************************* Register Access ******************************/ 817147883Sscottlstatic __inline void mpt_write(struct mpt_softc *, size_t, uint32_t); 818147883Sscottlstatic __inline uint32_t mpt_read(struct mpt_softc *, int); 819147883Sscottlstatic __inline void mpt_pio_write(struct mpt_softc *, size_t, uint32_t); 820147883Sscottlstatic __inline uint32_t mpt_pio_read(struct mpt_softc *, int); 821147883Sscottl 822147883Sscottlstatic __inline void 823147883Sscottlmpt_write(struct mpt_softc *mpt, size_t offset, uint32_t val) 824147883Sscottl{ 825147883Sscottl bus_space_write_4(mpt->pci_st, mpt->pci_sh, offset, val); 826147883Sscottl} 827147883Sscottl 828147883Sscottlstatic __inline uint32_t 829147883Sscottlmpt_read(struct mpt_softc *mpt, int offset) 830147883Sscottl{ 831147883Sscottl return (bus_space_read_4(mpt->pci_st, mpt->pci_sh, offset)); 832147883Sscottl} 833147883Sscottl 834147883Sscottl/* 835147883Sscottl * Some operations (e.g. diagnostic register writes while the ARM proccessor 836147883Sscottl * is disabled), must be performed using "PCI pio" operations. On non-PCI 837147883Sscottl * busses, these operations likely map to normal register accesses. 838147883Sscottl */ 839147883Sscottlstatic __inline void 840147883Sscottlmpt_pio_write(struct mpt_softc *mpt, size_t offset, uint32_t val) 841147883Sscottl{ 842231518Smarius KASSERT(mpt->pci_pio_reg != NULL, ("no PIO resource")); 843147883Sscottl bus_space_write_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset, val); 844147883Sscottl} 845147883Sscottl 846147883Sscottlstatic __inline uint32_t 847147883Sscottlmpt_pio_read(struct mpt_softc *mpt, int offset) 848147883Sscottl{ 849231518Smarius KASSERT(mpt->pci_pio_reg != NULL, ("no PIO resource")); 850147883Sscottl return (bus_space_read_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset)); 851147883Sscottl} 852147883Sscottl/*********************** Reply Frame/Request Management ***********************/ 853147883Sscottl/* Max MPT Reply we are willing to accept (must be power of 2) */ 854155521Smjacob#define MPT_REPLY_SIZE 256 855147883Sscottl 856157117Smjacob/* 857157117Smjacob * Must be less than 16384 in order for target mode to work 858157117Smjacob */ 859155521Smjacob#define MPT_MAX_REQUESTS(mpt) 512 860155521Smjacob#define MPT_REQUEST_AREA 512 861155521Smjacob#define MPT_SENSE_SIZE 32 /* included in MPT_REQUEST_AREA */ 862147883Sscottl#define MPT_REQ_MEM_SIZE(mpt) (MPT_MAX_REQUESTS(mpt) * MPT_REQUEST_AREA) 863147883Sscottl 864157354Smjacob#define MPT_CONTEXT_CB_SHIFT (16) 865157117Smjacob#define MPT_CBI(handle) (handle >> MPT_CONTEXT_CB_SHIFT) 866147883Sscottl#define MPT_CBI_TO_HID(cbi) ((cbi) << MPT_CONTEXT_CB_SHIFT) 867147883Sscottl#define MPT_CONTEXT_TO_CBI(x) \ 868147883Sscottl (((x) >> MPT_CONTEXT_CB_SHIFT) & (MPT_NUM_REPLY_HANDLERS - 1)) 869157354Smjacob#define MPT_CONTEXT_REQI_MASK 0xFFFF 870157117Smjacob#define MPT_CONTEXT_TO_REQI(x) ((x) & MPT_CONTEXT_REQI_MASK) 871147883Sscottl 872147883Sscottl/* 873147883Sscottl * Convert a 32bit physical address returned from IOC to an 874147883Sscottl * offset into our reply frame memory or the kvm address needed 875147883Sscottl * to access the data. The returned address is only the low 876147883Sscottl * 32 bits, so mask our base physical address accordingly. 877147883Sscottl */ 878147883Sscottl#define MPT_REPLY_BADDR(x) \ 879147883Sscottl (x << 1) 880147883Sscottl#define MPT_REPLY_OTOV(m, i) \ 881147883Sscottl ((void *)(&m->reply[i])) 882147883Sscottl 883147883Sscottl#define MPT_DUMP_REPLY_FRAME(mpt, reply_frame) \ 884147883Sscottldo { \ 885158982Smjacob if (mpt->verbose > MPT_PRT_DEBUG) \ 886147883Sscottl mpt_dump_reply_frame(mpt, reply_frame); \ 887147883Sscottl} while(0) 888147883Sscottl 889147883Sscottlstatic __inline uint32_t mpt_pop_reply_queue(struct mpt_softc *mpt); 890147883Sscottlstatic __inline void mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr); 891147883Sscottl 892147883Sscottl/* 893147883Sscottl * Give the reply buffer back to the IOC after we have 894147883Sscottl * finished processing it. 895147883Sscottl */ 896147883Sscottlstatic __inline void 897147883Sscottlmpt_free_reply(struct mpt_softc *mpt, uint32_t ptr) 898147883Sscottl{ 899147883Sscottl mpt_write(mpt, MPT_OFFSET_REPLY_Q, ptr); 900147883Sscottl} 901147883Sscottl 902147883Sscottl/* Get a reply from the IOC */ 903147883Sscottlstatic __inline uint32_t 904147883Sscottlmpt_pop_reply_queue(struct mpt_softc *mpt) 905147883Sscottl{ 906147883Sscottl return mpt_read(mpt, MPT_OFFSET_REPLY_Q); 907147883Sscottl} 908147883Sscottl 909157354Smjacobvoid 910157354Smjacobmpt_complete_request_chain(struct mpt_softc *, struct req_queue *, u_int); 911157354Smjacob 912220945Smarius/************************** Scatter Gather Management **************************/ 913155521Smjacob/* MPT_RQSL- size of request frame, in bytes */ 914164990Smjacob#define MPT_RQSL(mpt) (mpt->ioc_facts.RequestFrameSize << 2) 915155521Smjacob 916155521Smjacob/* MPT_NSGL- how many SG entries can fit in a request frame size */ 917155521Smjacob#define MPT_NSGL(mpt) (MPT_RQSL(mpt) / sizeof (SGE_IO_UNION)) 918155521Smjacob 919155521Smjacob/* MPT_NRFM- how many request frames can fit in each request alloc we make */ 920155521Smjacob#define MPT_NRFM(mpt) (MPT_REQUEST_AREA / MPT_RQSL(mpt)) 921155521Smjacob 922147883Sscottl/* 923155521Smjacob * MPT_NSGL_FIRST- # of SG elements that can fit after 924155521Smjacob * an I/O request but still within the request frame. 925155521Smjacob * Do this safely based upon SGE_IO_UNION. 926155521Smjacob * 927155521Smjacob * Note that the first element is *within* the SCSI request. 928147883Sscottl */ 929155521Smjacob#define MPT_NSGL_FIRST(mpt) \ 930155521Smjacob ((MPT_RQSL(mpt) - sizeof (MSG_SCSI_IO_REQUEST) + sizeof (SGE_IO_UNION)) / \ 931155521Smjacob sizeof (SGE_IO_UNION)) 932147883Sscottl 933147883Sscottl/***************************** IOC Initialization *****************************/ 934147883Sscottlint mpt_reset(struct mpt_softc *, int /*reinit*/); 935147883Sscottl 936157117Smjacob/****************************** Debugging ************************************/ 937160290Smjacobvoid mpt_dump_data(struct mpt_softc *, const char *, void *, int); 938158933Smjacobvoid mpt_dump_request(struct mpt_softc *, request_t *); 939158933Smjacob 940147883Sscottlenum { 941147883Sscottl MPT_PRT_ALWAYS, 942147883Sscottl MPT_PRT_FATAL, 943147883Sscottl MPT_PRT_ERROR, 944147883Sscottl MPT_PRT_WARN, 945147883Sscottl MPT_PRT_INFO, 946159049Smjacob MPT_PRT_NEGOTIATION, 947147883Sscottl MPT_PRT_DEBUG, 948157117Smjacob MPT_PRT_DEBUG1, 949157117Smjacob MPT_PRT_DEBUG2, 950157117Smjacob MPT_PRT_DEBUG3, 951155521Smjacob MPT_PRT_TRACE, 952155521Smjacob MPT_PRT_NONE=100 953147883Sscottl}; 954147883Sscottl 955147883Sscottl#define mpt_lprt(mpt, level, ...) \ 956147883Sscottldo { \ 957147883Sscottl if (level <= (mpt)->verbose) \ 958147883Sscottl mpt_prt(mpt, __VA_ARGS__); \ 959147883Sscottl} while (0) 960147883Sscottl 961224493Smarius#if 0 962215325Smarius#define mpt_lprtc(mpt, level, ...) \ 963215325Smariusdo { \ 964215325Smarius if (level <= (mpt)->verbose) \ 965215325Smarius mpt_prtc(mpt, __VA_ARGS__); \ 966147883Sscottl} while (0) 967224493Smarius#endif 968241874Smarius 969157117Smjacobvoid mpt_prt(struct mpt_softc *, const char *, ...) 970157117Smjacob __printflike(2, 3); 971157117Smjacobvoid mpt_prtc(struct mpt_softc *, const char *, ...) 972157117Smjacob __printflike(2, 3); 973147883Sscottl 974157117Smjacob/**************************** Target Mode Related ***************************/ 975157117Smjacobstatic __inline int mpt_cdblen(uint8_t, int); 976157117Smjacobstatic __inline int 977157117Smjacobmpt_cdblen(uint8_t cdb0, int maxlen) 978157117Smjacob{ 979157117Smjacob int group = cdb0 >> 5; 980157117Smjacob switch (group) { 981157117Smjacob case 0: 982157117Smjacob return (6); 983157117Smjacob case 1: 984157117Smjacob return (10); 985157117Smjacob case 4: 986157117Smjacob case 5: 987157117Smjacob return (12); 988157117Smjacob default: 989157117Smjacob return (16); 990157117Smjacob } 991157117Smjacob} 992157117Smjacob#ifdef INVARIANTS 993157117Smjacobstatic __inline request_t * mpt_tag_2_req(struct mpt_softc *, uint32_t); 994157117Smjacobstatic __inline request_t * 995157117Smjacobmpt_tag_2_req(struct mpt_softc *mpt, uint32_t tag) 996157117Smjacob{ 997157354Smjacob uint16_t rtg = (tag >> 18); 998231228Smarius KASSERT(rtg < mpt->tgt_cmds_allocated, ("bad tag %d", tag)); 999157117Smjacob KASSERT(mpt->tgt_cmd_ptrs, ("no cmd backpointer array")); 1000157117Smjacob KASSERT(mpt->tgt_cmd_ptrs[rtg], ("no cmd backpointer")); 1001157117Smjacob return (mpt->tgt_cmd_ptrs[rtg]); 1002157117Smjacob} 1003213147Smarius#endif 1004157662Smjacob 1005157662Smjacobstatic __inline int 1006157662Smjacobmpt_req_on_free_list(struct mpt_softc *, request_t *); 1007157662Smjacobstatic __inline int 1008157662Smjacobmpt_req_on_pending_list(struct mpt_softc *, request_t *); 1009157662Smjacob 1010157662Smjacob/* 1011157662Smjacob * Is request on freelist? 1012157662Smjacob */ 1013157662Smjacobstatic __inline int 1014157662Smjacobmpt_req_on_free_list(struct mpt_softc *mpt, request_t *req) 1015157662Smjacob{ 1016157662Smjacob request_t *lrq; 1017157662Smjacob 1018157662Smjacob TAILQ_FOREACH(lrq, &mpt->request_free_list, links) { 1019157662Smjacob if (lrq == req) { 1020157662Smjacob return (1); 1021157662Smjacob } 1022157662Smjacob } 1023157662Smjacob return (0); 1024157662Smjacob} 1025157662Smjacob 1026157662Smjacob/* 1027157662Smjacob * Is request on pending list? 1028157662Smjacob */ 1029157662Smjacobstatic __inline int 1030157662Smjacobmpt_req_on_pending_list(struct mpt_softc *mpt, request_t *req) 1031157662Smjacob{ 1032157662Smjacob request_t *lrq; 1033157662Smjacob 1034157662Smjacob TAILQ_FOREACH(lrq, &mpt->request_pending_list, links) { 1035157662Smjacob if (lrq == req) { 1036157662Smjacob return (1); 1037157662Smjacob } 1038157662Smjacob } 1039157662Smjacob return (0); 1040157662Smjacob} 1041157662Smjacob 1042213147Smarius#ifdef INVARIANTS 1043213147Smariusstatic __inline void 1044213147Smariusmpt_req_spcl(struct mpt_softc *, request_t *, const char *, int); 1045213147Smariusstatic __inline void 1046213147Smariusmpt_req_not_spcl(struct mpt_softc *, request_t *, const char *, int); 1047213147Smarius 1048157662Smjacob/* 1049157662Smjacob * Make sure that req *is* part of one of the special lists 1050157662Smjacob */ 1051157662Smjacobstatic __inline void 1052157662Smjacobmpt_req_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line) 1053157662Smjacob{ 1054157662Smjacob int i; 1055157662Smjacob for (i = 0; i < mpt->els_cmds_allocated; i++) { 1056157662Smjacob if (req == mpt->els_cmd_ptrs[i]) { 1057157662Smjacob return; 1058157662Smjacob } 1059157662Smjacob } 1060157662Smjacob for (i = 0; i < mpt->tgt_cmds_allocated; i++) { 1061157662Smjacob if (req == mpt->tgt_cmd_ptrs[i]) { 1062157662Smjacob return; 1063157662Smjacob } 1064157662Smjacob } 1065231228Smarius panic("%s(%d): req %p:%u function %x not in els or tgt ptrs", 1066157662Smjacob s, line, req, req->serno, 1067157662Smjacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function); 1068157662Smjacob} 1069157662Smjacob 1070157662Smjacob/* 1071157662Smjacob * Make sure that req is *not* part of one of the special lists. 1072157662Smjacob */ 1073157662Smjacobstatic __inline void 1074157662Smjacobmpt_req_not_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line) 1075157662Smjacob{ 1076157662Smjacob int i; 1077157662Smjacob for (i = 0; i < mpt->els_cmds_allocated; i++) { 1078157662Smjacob KASSERT(req != mpt->els_cmd_ptrs[i], 1079231228Smarius ("%s(%d): req %p:%u func %x in els ptrs at ioindex %d", 1080157662Smjacob s, line, req, req->serno, 1081157662Smjacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i)); 1082157662Smjacob } 1083157662Smjacob for (i = 0; i < mpt->tgt_cmds_allocated; i++) { 1084157662Smjacob KASSERT(req != mpt->tgt_cmd_ptrs[i], 1085231228Smarius ("%s(%d): req %p:%u func %x in tgt ptrs at ioindex %d", 1086157662Smjacob s, line, req, req->serno, 1087157662Smjacob ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i)); 1088157662Smjacob } 1089157662Smjacob} 1090157117Smjacob#endif 1091147883Sscottl 1092160391Smjacob/* 1093160391Smjacob * Task Management Types, purely for internal consumption 1094160391Smjacob */ 1095157117Smjacobtypedef enum { 1096157117Smjacob MPT_ABORT_TASK_SET=1234, 1097157117Smjacob MPT_CLEAR_TASK_SET, 1098157117Smjacob MPT_TARGET_RESET, 1099157117Smjacob MPT_CLEAR_ACA, 1100157117Smjacob MPT_TERMINATE_TASK, 1101157117Smjacob MPT_NIL_TMT_VALUE=5678 1102157117Smjacob} mpt_task_mgmt_t; 1103157117Smjacob 1104147883Sscottl/**************************** Unclassified Routines ***************************/ 1105147883Sscottlvoid mpt_send_cmd(struct mpt_softc *mpt, request_t *req); 1106147883Sscottlint mpt_recv_handshake_reply(struct mpt_softc *mpt, 1107147883Sscottl size_t reply_len, void *reply); 1108147883Sscottlint mpt_wait_req(struct mpt_softc *mpt, request_t *req, 1109147883Sscottl mpt_req_state_t state, mpt_req_state_t mask, 1110147883Sscottl int sleep_ok, int time_ms); 1111147883Sscottlvoid mpt_enable_ints(struct mpt_softc *mpt); 1112147883Sscottlvoid mpt_disable_ints(struct mpt_softc *mpt); 1113147883Sscottlint mpt_attach(struct mpt_softc *mpt); 1114147883Sscottlint mpt_shutdown(struct mpt_softc *mpt); 1115147883Sscottlint mpt_detach(struct mpt_softc *mpt); 1116147883Sscottlint mpt_send_handshake_cmd(struct mpt_softc *mpt, 1117147883Sscottl size_t len, void *cmd); 1118147883Sscottlrequest_t * mpt_get_request(struct mpt_softc *mpt, int sleep_ok); 1119147883Sscottlvoid mpt_free_request(struct mpt_softc *mpt, request_t *req); 1120147883Sscottlvoid mpt_intr(void *arg); 1121147883Sscottlvoid mpt_check_doorbell(struct mpt_softc *mpt); 1122147883Sscottlvoid mpt_dump_reply_frame(struct mpt_softc *mpt, 1123147883Sscottl MSG_DEFAULT_REPLY *reply_frame); 1124147883Sscottl 1125147883Sscottlint mpt_issue_cfg_req(struct mpt_softc */*mpt*/, request_t */*req*/, 1126170252Sscottl cfgparms_t *params, 1127147883Sscottl bus_addr_t /*addr*/, bus_size_t/*len*/, 1128147883Sscottl int /*sleep_ok*/, int /*timeout_ms*/); 1129170252Sscottlint mpt_read_extcfg_header(struct mpt_softc *mpt, int PageVersion, 1130170252Sscottl int PageNumber, uint32_t PageAddress, 1131170252Sscottl int ExtPageType, 1132170252Sscottl CONFIG_EXTENDED_PAGE_HEADER *rslt, 1133170252Sscottl int sleep_ok, int timeout_ms); 1134170252Sscottlint mpt_read_extcfg_page(struct mpt_softc *mpt, int Action, 1135170252Sscottl uint32_t PageAddress, 1136170252Sscottl CONFIG_EXTENDED_PAGE_HEADER *hdr, 1137170252Sscottl void *buf, size_t len, int sleep_ok, 1138170252Sscottl int timeout_ms); 1139147883Sscottlint mpt_read_cfg_header(struct mpt_softc *, int /*PageType*/, 1140147883Sscottl int /*PageNumber*/, 1141147883Sscottl uint32_t /*PageAddress*/, 1142147883Sscottl CONFIG_PAGE_HEADER *, 1143147883Sscottl int /*sleep_ok*/, int /*timeout_ms*/); 1144147883Sscottlint mpt_read_cfg_page(struct mpt_softc *t, int /*Action*/, 1145147883Sscottl uint32_t /*PageAddress*/, 1146147883Sscottl CONFIG_PAGE_HEADER *, size_t /*len*/, 1147147883Sscottl int /*sleep_ok*/, int /*timeout_ms*/); 1148147883Sscottlint mpt_write_cfg_page(struct mpt_softc *, int /*Action*/, 1149147883Sscottl uint32_t /*PageAddress*/, 1150147883Sscottl CONFIG_PAGE_HEADER *, size_t /*len*/, 1151147883Sscottl int /*sleep_ok*/, int /*timeout_ms*/); 1152147883Sscottlstatic __inline int 1153147883Sscottlmpt_read_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress, 1154147883Sscottl CONFIG_PAGE_HEADER *hdr, size_t len, 1155147883Sscottl int sleep_ok, int timeout_ms) 1156147883Sscottl{ 1157147883Sscottl return (mpt_read_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT, 1158147883Sscottl PageAddress, hdr, len, sleep_ok, timeout_ms)); 1159147883Sscottl} 1160147883Sscottl 1161147883Sscottlstatic __inline int 1162147883Sscottlmpt_write_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress, 1163147883Sscottl CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok, 1164147883Sscottl int timeout_ms) 1165147883Sscottl{ 1166147883Sscottl return (mpt_write_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT, 1167147883Sscottl PageAddress, hdr, len, sleep_ok, 1168147883Sscottl timeout_ms)); 1169147883Sscottl} 1170101704Smjacob/* mpt_debug.c functions */ 1171101704Smjacobvoid mpt_print_reply(void *vmsg); 1172147883Sscottlvoid mpt_print_db(uint32_t mb); 1173101704Smjacobvoid mpt_print_config_reply(void *vmsg); 1174147883Sscottlchar *mpt_ioc_diag(uint32_t diag); 1175147883Sscottlvoid mpt_req_state(mpt_req_state_t state); 1176101704Smjacobvoid mpt_print_config_request(void *vmsg); 1177101704Smjacobvoid mpt_print_request(void *vmsg); 1178155521Smjacobvoid mpt_dump_sgl(SGE_IO_UNION *se, int offset); 1179101704Smjacob#endif /* _MPT_H_ */ 1180