mpt.h revision 209599
16059Samurai/* $FreeBSD: head/sys/dev/mpt/mpt.h 209599 2010-06-29 22:07:53Z ken $ */ 26059Samurai/*- 36059Samurai * Generic defines for LSI '909 FC adapters. 46059Samurai * FreeBSD Version. 56059Samurai * 66059Samurai * Copyright (c) 2000, 2001 by Greg Ansley 76059Samurai * 86059Samurai * Redistribution and use in source and binary forms, with or without 96059Samurai * modification, are permitted provided that the following conditions 106059Samurai * are met: 116059Samurai * 1. Redistributions of source code must retain the above copyright 126059Samurai * notice immediately at the beginning of the file, without modification, 136059Samurai * this list of conditions, and the following disclaimer. 146059Samurai * 2. The name of the author may not be used to endorse or promote products 156059Samurai * derived from this software without specific prior written permission. 166059Samurai * 176059Samurai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 186059Samurai * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 198857Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2026142Sbrian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 218857Srgrimes * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 226059Samurai * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 236059Samurai * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 246059Samurai * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 256059Samurai * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 266059Samurai * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 276059Samurai * SUCH DAMAGE. 286059Samurai */ 2926142Sbrian/*- 306735Samurai * Copyright (c) 2002, 2006 by Matthew Jacob 3113389Sphk * All rights reserved. 3213389Sphk * 3313389Sphk * Redistribution and use in source and binary forms, with or without 346059Samurai * modification, are permitted provided that the following conditions are 356059Samurai * met: 366059Samurai * 1. Redistributions of source code must retain the above copyright 376059Samurai * notice, this list of conditions and the following disclaimer. 386059Samurai * 2. Redistributions in binary form must reproduce at minimum a disclaimer 396059Samurai * substantially similar to the "NO WARRANTY" disclaimer below 406059Samurai * ("Disclaimer") and any redistribution must be conditioned upon including 416059Samurai * a substantially similar Disclaimer requirement for further binary 426059Samurai * redistribution. 436059Samurai * 3. Neither the names of the above listed copyright holders nor the names 446059Samurai * of any contributors may be used to endorse or promote products derived 456059Samurai * from this software without specific prior written permission. 466059Samurai * 476059Samurai * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 486059Samurai * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 496059Samurai * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 506059Samurai * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 516059Samurai * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 526059Samurai * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 536059Samurai * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 546059Samurai * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 556059Samurai * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 566059Samurai * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 576059Samurai * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 586059Samurai * 596059Samurai * Support from Chris Ellsworth in order to make SAS adapters work 606059Samurai * is gratefully acknowledged. 616059Samurai * 626059Samurai * 636059Samurai * Support from LSI-Logic has also gone a great deal toward making this a 6413760Sphk * workable subsystem and is gratefully acknowledged. 656059Samurai */ 666059Samurai/* 676059Samurai * Copyright (c) 2004, Avid Technology, Inc. and its contributors. 686059Samurai * Copyright (c) 2004, 2005 Justin T. Gibbs 696059Samurai * Copyright (c) 2005, WHEEL Sp. z o.o. 706059Samurai * All rights reserved. 716059Samurai * 726059Samurai * Redistribution and use in source and binary forms, with or without 736059Samurai * modification, are permitted provided that the following conditions are 746059Samurai * met: 756059Samurai * 1. Redistributions of source code must retain the above copyright 766059Samurai * notice, this list of conditions and the following disclaimer. 776059Samurai * 2. Redistributions in binary form must reproduce at minimum a disclaimer 786059Samurai * substantially similar to the "NO WARRANTY" disclaimer below 796059Samurai * ("Disclaimer") and any redistribution must be conditioned upon including 806059Samurai * a substantially similar Disclaimer requirement for further binary 816059Samurai * redistribution. 826059Samurai * 3. Neither the names of the above listed copyright holders nor the names 836059Samurai * of any contributors may be used to endorse or promote products derived 846059Samurai * from this software without specific prior written permission. 856059Samurai * 866059Samurai * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 876059Samurai * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 886059Samurai * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 896059Samurai * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 906059Samurai * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 916059Samurai * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 926059Samurai * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 936059Samurai * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 946059Samurai * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 956059Samurai * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 966059Samurai * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 976059Samurai */ 986059Samurai 996059Samurai#ifndef _MPT_H_ 1006059Samurai#define _MPT_H_ 1016059Samurai 1026059Samurai/********************************* OS Includes ********************************/ 1036059Samurai#include <sys/types.h> 1046059Samurai#include <sys/param.h> 1056059Samurai#include <sys/systm.h> 1066059Samurai#include <sys/endian.h> 1076059Samurai#include <sys/eventhandler.h> 1086059Samurai#if __FreeBSD_version < 500000 1096059Samurai#include <sys/kernel.h> 1106059Samurai#include <sys/queue.h> 11113760Sphk#include <sys/malloc.h> 11225630Sbrian#include <sys/devicestat.h> 1136059Samurai#else 1146059Samurai#include <sys/lock.h> 1156059Samurai#include <sys/kernel.h> 1166059Samurai#include <sys/queue.h> 1176059Samurai#include <sys/malloc.h> 1186059Samurai#include <sys/mutex.h> 1196059Samurai#include <sys/condvar.h> 1206059Samurai#endif 1216059Samurai#include <sys/proc.h> 1226059Samurai#include <sys/bus.h> 1236059Samurai#include <sys/module.h> 1246059Samurai 1256059Samurai#include <machine/cpu.h> 1266059Samurai#include <machine/resource.h> 1276059Samurai 1286059Samurai#if __FreeBSD_version < 500000 1296059Samurai#include <machine/bus.h> 1306059Samurai#include <machine/clock.h> 1316059Samurai#endif 1326059Samurai 1336059Samurai#ifdef __sparc64__ 1346735Samurai#include <dev/ofw/openfirm.h> 1356735Samurai#include <machine/ofw_machdep.h> 1366735Samurai#endif 1376735Samurai 1386059Samurai#include <sys/rman.h> 1396059Samurai 1406059Samurai#if __FreeBSD_version < 500000 1416059Samurai#include <pci/pcireg.h> 1426059Samurai#include <pci/pcivar.h> 1436059Samurai#else 1446059Samurai#include <dev/pci/pcireg.h> 1456059Samurai#include <dev/pci/pcivar.h> 1466059Samurai#endif 1476059Samurai 1486059Samurai#include <machine/bus.h> 1496059Samurai#include "opt_ddb.h" 1506059Samurai 1516059Samurai/**************************** Register Definitions ****************************/ 1526059Samurai#include <dev/mpt/mpt_reg.h> 1536059Samurai 1546059Samurai/******************************* MPI Definitions ******************************/ 1556059Samurai#include <dev/mpt/mpilib/mpi_type.h> 1566059Samurai#include <dev/mpt/mpilib/mpi.h> 1576059Samurai#include <dev/mpt/mpilib/mpi_cnfg.h> 1586059Samurai#include <dev/mpt/mpilib/mpi_ioc.h> 1596059Samurai#include <dev/mpt/mpilib/mpi_raid.h> 1606059Samurai 1616059Samurai/* XXX For mpt_debug.c */ 1626059Samurai#include <dev/mpt/mpilib/mpi_init.h> 1636059Samurai 1646059Samurai#define MPT_S64_2_SCALAR(y) ((((int64_t)y.High) << 32) | (y.Low)) 1656059Samurai#define MPT_U64_2_SCALAR(y) ((((uint64_t)y.High) << 32) | (y.Low)) 1666059Samurai 1676059Samurai/****************************** Misc Definitions ******************************/ 1686059Samurai/* #define MPT_TEST_MULTIPATH 1 */ 1696059Samurai#define MPT_OK (0) 1706059Samurai#define MPT_FAIL (0x10000) 1716059Samurai 1726059Samurai#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array)) 1736059Samurai 1746059Samurai#define MPT_ROLE_NONE 0 1756059Samurai#define MPT_ROLE_INITIATOR 1 1766059Samurai#define MPT_ROLE_TARGET 2 1776059Samurai#define MPT_ROLE_BOTH 3 1786059Samurai#define MPT_ROLE_DEFAULT MPT_ROLE_INITIATOR 1796059Samurai 1806735Samurai#define MPT_INI_ID_NONE -1 1816735Samurai 1826735Samurai/**************************** Forward Declarations ****************************/ 1836735Samuraistruct mpt_softc; 1846735Samuraistruct mpt_personality; 1856735Samuraitypedef struct req_entry request_t; 1866735Samurai 1876735Samurai/************************* Personality Module Support *************************/ 1886059Samuraitypedef int mpt_load_handler_t(struct mpt_personality *); 1896059Samuraitypedef int mpt_probe_handler_t(struct mpt_softc *); 1906059Samuraitypedef int mpt_attach_handler_t(struct mpt_softc *); 1916059Samuraitypedef int mpt_enable_handler_t(struct mpt_softc *); 1926059Samuraitypedef void mpt_ready_handler_t(struct mpt_softc *); 1936059Samuraitypedef int mpt_event_handler_t(struct mpt_softc *, request_t *, 1946735Samurai MSG_EVENT_NOTIFY_REPLY *); 1956735Samuraitypedef void mpt_reset_handler_t(struct mpt_softc *, int /*type*/); 1966735Samurai/* XXX Add return value and use for veto? */ 1976735Samuraitypedef void mpt_shutdown_handler_t(struct mpt_softc *); 1986059Samuraitypedef void mpt_detach_handler_t(struct mpt_softc *); 1996059Samuraitypedef int mpt_unload_handler_t(struct mpt_personality *); 20013379Sphk 20125630Sbrianstruct mpt_personality 2026059Samurai{ 2036059Samurai const char *name; 2046059Samurai uint32_t id; /* Assigned identifier. */ 2056059Samurai u_int use_count; /* Instances using personality*/ 2069448Samurai mpt_load_handler_t *load; /* configure personailty */ 2079448Samurai#define MPT_PERS_FIRST_HANDLER(pers) (&(pers)->load) 2086059Samurai mpt_probe_handler_t *probe; /* configure personailty */ 2096059Samurai mpt_attach_handler_t *attach; /* initialize device instance */ 2106059Samurai mpt_enable_handler_t *enable; /* enable device */ 2116059Samurai mpt_ready_handler_t *ready; /* final open for business */ 2126059Samurai mpt_event_handler_t *event; /* Handle MPI event. */ 2136059Samurai mpt_reset_handler_t *reset; /* Re-init after reset. */ 2146059Samurai mpt_shutdown_handler_t *shutdown; /* Shutdown instance. */ 2156059Samurai mpt_detach_handler_t *detach; /* release device instance */ 2166059Samurai mpt_unload_handler_t *unload; /* Shutdown personality */ 2176059Samurai#define MPT_PERS_LAST_HANDLER(pers) (&(pers)->unload) 2186059Samurai}; 2196059Samurai 2206059Samuraiint mpt_modevent(module_t, int, void *); 2216059Samurai 2226059Samurai/* Maximum supported number of personalities. */ 2236059Samurai#define MPT_MAX_PERSONALITIES (15) 2246059Samurai 2256735Samurai#define MPT_PERSONALITY_DEPEND(name, dep, vmin, vpref, vmax) \ 2266735Samurai MODULE_DEPEND(name, dep, vmin, vpref, vmax) 2276735Samurai 2286059Samurai#define DECLARE_MPT_PERSONALITY(name, order) \ 2296059Samurai static moduledata_t name##_mod = { \ 2306059Samurai #name, mpt_modevent, &name##_personality \ 2316059Samurai }; \ 2326059Samurai DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, order); \ 2336059Samurai MODULE_VERSION(name, 1); \ 2346059Samurai MPT_PERSONALITY_DEPEND(name, mpt_core, 1, 1, 1) 2356059Samurai 2366059Samurai/******************************* Bus DMA Support ******************************/ 2376059Samurai/* XXX Need to update bus_dmamap_sync to take a range argument. */ 2386059Samurai#define bus_dmamap_sync_range(dma_tag, dmamap, offset, len, op) \ 2396059Samurai bus_dmamap_sync(dma_tag, dmamap, op) 2406059Samurai 2416059Samurai#if __FreeBSD_version < 600000 24215738Sphk#define bus_get_dma_tag(x) NULL 2439448Samurai#endif 2449448Samurai#if __FreeBSD_version >= 501102 2459448Samurai#define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary, \ 2469448Samurai lowaddr, highaddr, filter, filterarg, \ 2476059Samurai maxsize, nsegments, maxsegsz, flags, \ 2486059Samurai dma_tagp) \ 2496059Samurai bus_dma_tag_create(parent_tag, alignment, boundary, \ 2506059Samurai lowaddr, highaddr, filter, filterarg, \ 2516059Samurai maxsize, nsegments, maxsegsz, flags, \ 2526059Samurai busdma_lock_mutex, &(mpt)->mpt_lock, \ 2536059Samurai dma_tagp) 2546059Samurai#else 2556059Samurai#define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary, \ 2566059Samurai lowaddr, highaddr, filter, filterarg, \ 2576059Samurai maxsize, nsegments, maxsegsz, flags, \ 2586059Samurai dma_tagp) \ 2596059Samurai bus_dma_tag_create(parent_tag, alignment, boundary, \ 2606059Samurai lowaddr, highaddr, filter, filterarg, \ 2616059Samurai maxsize, nsegments, maxsegsz, flags, \ 2626059Samurai dma_tagp) 2636059Samurai#endif 2646059Samurai 2656059Samuraistruct mpt_map_info { 26613389Sphk struct mpt_softc *mpt; 2676059Samurai int error; 2686059Samurai uint32_t phys; 2696059Samurai}; 2706059Samurai 2716059Samuraivoid mpt_map_rquest(void *, bus_dma_segment_t *, int, int); 2726059Samurai/* **************************** NewBUS interrupt Crock ************************/ 2736059Samurai#if __FreeBSD_version < 700031 2746059Samurai#define mpt_setup_intr(d, i, f, U, if, ifa, hp) \ 2756059Samurai bus_setup_intr(d, i, f, if, ifa, hp) 2766059Samurai#else 2776059Samurai#define mpt_setup_intr bus_setup_intr 2786059Samurai#endif 2796059Samurai 2806059Samurai/* **************************** NewBUS CAM Support ****************************/ 2816059Samurai#if __FreeBSD_version < 700049 2826059Samurai#define mpt_xpt_bus_register(sim, parent, bus) \ 2836059Samurai xpt_bus_register(sim, bus) 2846059Samurai#else 2856059Samurai#define mpt_xpt_bus_register xpt_bus_register 2866059Samurai#endif 2876059Samurai 2886059Samurai/**************************** Kernel Thread Support ***************************/ 2896059Samurai#if __FreeBSD_version > 800001 2906059Samurai#define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 2916059Samurai kproc_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) 2926059Samurai#define mpt_kthread_exit(status) \ 2936059Samurai kproc_exit(status) 2946059Samurai#elif __FreeBSD_version > 500005 2956059Samurai#define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 2966059Samurai kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) 2976059Samurai#define mpt_kthread_exit(status) \ 29815738Sphk kthread_exit(status) 2996059Samurai#else 3006059Samurai#define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 3016059Samurai kthread_create(func, farg, proc_ptr, fmtstr, arg) 3026059Samurai#define mpt_kthread_exit(status) \ 3036059Samurai kthread_exit(status) 3046059Samurai#endif 3056059Samurai 3066059Samurai/********************************** Endianess *********************************/ 3076059Samurai#define MPT_2_HOST64(ptr, tag) ptr->tag = le64toh(ptr->tag) 3086059Samurai#define MPT_2_HOST32(ptr, tag) ptr->tag = le32toh(ptr->tag) 3096059Samurai#define MPT_2_HOST16(ptr, tag) ptr->tag = le16toh(ptr->tag) 3106059Samurai 3116059Samurai#define HOST_2_MPT64(ptr, tag) ptr->tag = htole64(ptr->tag) 3126059Samurai#define HOST_2_MPT32(ptr, tag) ptr->tag = htole32(ptr->tag) 3136735Samurai#define HOST_2_MPT16(ptr, tag) ptr->tag = htole16(ptr->tag) 3146735Samurai 3156735Samurai#if _BYTE_ORDER == _BIG_ENDIAN 3166735Samuraivoid mpt2host_sge_simple_union(SGE_SIMPLE_UNION *); 3176059Samuraivoid mpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *); 3186059Samuraivoid mpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *); 3196059Samuraivoid mpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *); 3206059Samuraivoid mpt2host_config_page_ioc3(CONFIG_PAGE_IOC_3 *); 3216059Samuraivoid mpt2host_config_page_scsi_port_0(CONFIG_PAGE_SCSI_PORT_0 *); 3226059Samuraivoid mpt2host_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *); 3236059Samuraivoid host2mpt_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *); 3246059Samuraivoid mpt2host_config_page_scsi_port_2(CONFIG_PAGE_SCSI_PORT_2 *); 3256059Samuraivoid mpt2host_config_page_scsi_device_0(CONFIG_PAGE_SCSI_DEVICE_0 *); 3266059Samuraivoid mpt2host_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *); 3276059Samuraivoid host2mpt_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *); 3286059Samuraivoid mpt2host_config_page_fc_port_0(CONFIG_PAGE_FC_PORT_0 *); 3296059Samuraivoid mpt2host_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *); 3306059Samuraivoid host2mpt_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *); 3316735Samuraivoid mpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *); 3326735Samuraivoid mpt2host_config_page_raid_phys_disk_0(CONFIG_PAGE_RAID_PHYS_DISK_0 *); 33325019Sphkvoid mpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *); 33425019Sphk#else 33525021Sache#define mpt2host_sge_simple_union(x) do { ; } while (0) 33625019Sphk#define mpt2host_iocfacts_reply(x) do { ; } while (0) 33725019Sphk#define mpt2host_portfacts_reply(x) do { ; } while (0) 33825019Sphk#define mpt2host_config_page_ioc2(x) do { ; } while (0) 3396059Samurai#define mpt2host_config_page_ioc3(x) do { ; } while (0) 3406059Samurai#define mpt2host_config_page_scsi_port_0(x) do { ; } while (0) 3416059Samurai#define mpt2host_config_page_scsi_port_1(x) do { ; } while (0) 3426059Samurai#define host2mpt_config_page_scsi_port_1(x) do { ; } while (0) 3436059Samurai#define mpt2host_config_page_scsi_port_2(x) do { ; } while (0) 3446059Samurai#define mpt2host_config_page_scsi_device_0(x) do { ; } while (0) 3456059Samurai#define mpt2host_config_page_scsi_device_1(x) do { ; } while (0) 3466059Samurai#define host2mpt_config_page_scsi_device_1(x) do { ; } while (0) 3476059Samurai#define mpt2host_config_page_fc_port_0(x) do { ; } while (0) 3486059Samurai#define mpt2host_config_page_fc_port_1(x) do { ; } while (0) 3496059Samurai#define host2mpt_config_page_fc_port_1(x) do { ; } while (0) 3506059Samurai#define mpt2host_config_page_raid_vol_0(x) do { ; } while (0) 3516059Samurai#define mpt2host_config_page_raid_phys_disk_0(x) \ 3526059Samurai do { ; } while (0) 3536059Samurai#define mpt2host_mpi_raid_vol_indicator(x) do { ; } while (0) 3546059Samurai#endif 3556059Samurai 3566059Samurai/**************************** MPI Transaction State ***************************/ 3576059Samuraitypedef enum { 3586059Samurai REQ_STATE_NIL = 0x00, 3596059Samurai REQ_STATE_FREE = 0x01, 3606059Samurai REQ_STATE_ALLOCATED = 0x02, 3616059Samurai REQ_STATE_QUEUED = 0x04, 3626059Samurai REQ_STATE_DONE = 0x08, 3636059Samurai REQ_STATE_TIMEDOUT = 0x10, 3646059Samurai REQ_STATE_NEED_WAKEUP = 0x20, 3656059Samurai REQ_STATE_LOCKED = 0x80, /* can't be freed */ 3666059Samurai REQ_STATE_MASK = 0xFF 3676059Samurai} mpt_req_state_t; 3686059Samurai 3696059Samuraistruct req_entry { 3706059Samurai TAILQ_ENTRY(req_entry) links; /* Pointer to next in list */ 3716059Samurai mpt_req_state_t state; /* Request State Information */ 3726059Samurai uint16_t index; /* Index of this entry */ 3736059Samurai uint16_t IOCStatus; /* Completion status */ 3746059Samurai uint16_t ResponseCode; /* TMF Reponse Code */ 3756059Samurai uint16_t serno; /* serial number */ 3766059Samurai union ccb *ccb; /* CAM request */ 3776059Samurai void *req_vbuf; /* Virtual Address of Entry */ 3786059Samurai void *sense_vbuf; /* Virtual Address of sense data */ 3796059Samurai bus_addr_t req_pbuf; /* Physical Address of Entry */ 3806059Samurai bus_addr_t sense_pbuf; /* Physical Address of sense data */ 3816059Samurai bus_dmamap_t dmap; /* DMA map for data buffers */ 3826059Samurai struct req_entry *chain; /* for SGE overallocations */ 3836059Samurai struct callout callout; /* Timeout for the request */ 3846059Samurai}; 3856059Samurai 3866059Samuraitypedef struct mpt_config_params { 3876059Samurai u_int Action; 3886059Samurai u_int PageVersion; 3896059Samurai u_int PageLength; 3906059Samurai u_int PageNumber; 3916059Samurai u_int PageType; 3926059Samurai u_int PageAddress; 3936059Samurai u_int ExtPageLength; 3946059Samurai u_int ExtPageType; 3956059Samurai} cfgparms_t; 3966059Samurai 3976059Samurai/**************************** MPI Target State Info ***************************/ 3986059Samurai 3996059Samuraitypedef struct { 4006059Samurai uint32_t reply_desc; /* current reply descriptor */ 4016059Samurai uint32_t resid; /* current data residual */ 4026059Samurai uint32_t bytes_xfered; /* current relative offset */ 4036059Samurai union ccb *ccb; /* pointer to currently active ccb */ 404 request_t *req; /* pointer to currently active assist request */ 405 uint32_t 406 is_local : 1, 407 nxfers : 31; 408 uint32_t tag_id; 409 enum { 410 TGT_STATE_NIL, 411 TGT_STATE_LOADING, 412 TGT_STATE_LOADED, 413 TGT_STATE_IN_CAM, 414 TGT_STATE_SETTING_UP_FOR_DATA, 415 TGT_STATE_MOVING_DATA, 416 TGT_STATE_MOVING_DATA_AND_STATUS, 417 TGT_STATE_SENDING_STATUS 418 } state; 419} mpt_tgt_state_t; 420 421/* 422 * When we get an incoming command it has its own tag which is called the 423 * IoIndex. This is the value we gave that particular command buffer when 424 * we originally assigned it. It's just a number, really. The FC card uses 425 * it as an RX_ID. We can use it to index into mpt->tgt_cmd_ptrs, which 426 * contains pointers the request_t structures related to that IoIndex. 427 * 428 * What *we* do is construct a tag out of the index for the target command 429 * which owns the incoming ATIO plus a rolling sequence number. 430 */ 431#define MPT_MAKE_TAGID(mpt, req, ioindex) \ 432 ((ioindex << 18) | (((mpt->sequence++) & 0x3f) << 12) | (req->index & 0xfff)) 433 434#ifdef INVARIANTS 435#define MPT_TAG_2_REQ(a, b) mpt_tag_2_req(a, (uint32_t) b) 436#else 437#define MPT_TAG_2_REQ(mpt, tag) mpt->tgt_cmd_ptrs[tag >> 18] 438#endif 439 440#define MPT_TGT_STATE(mpt, req) ((mpt_tgt_state_t *) \ 441 (&((uint8_t *)req->req_vbuf)[MPT_RQSL(mpt) - sizeof (mpt_tgt_state_t)])) 442 443STAILQ_HEAD(mpt_hdr_stailq, ccb_hdr); 444#define MPT_MAX_LUNS 256 445typedef struct { 446 struct mpt_hdr_stailq atios; 447 struct mpt_hdr_stailq inots; 448 int enabled; 449} tgt_resource_t; 450#define MPT_MAX_ELS 64 451 452/**************************** Handler Registration ****************************/ 453/* 454 * Global table of registered reply handlers. The 455 * handler is indicated by byte 3 of the request 456 * index submitted to the IOC. This allows the 457 * driver core to perform generic processing without 458 * any knowledge of per-personality behavior. 459 * 460 * MPT_NUM_REPLY_HANDLERS must be a power of 2 461 * to allow the easy generation of a mask. 462 * 463 * The handler offsets used by the core are hard coded 464 * allowing faster code generation when assigning a handler 465 * to a request. All "personalities" must use the 466 * the handler registration mechanism. 467 * 468 * The IOC handlers that are rarely executed are placed 469 * at the tail of the table to make it more likely that 470 * all commonly executed handlers fit in a single cache 471 * line. 472 */ 473#define MPT_NUM_REPLY_HANDLERS (32) 474#define MPT_REPLY_HANDLER_EVENTS MPT_CBI_TO_HID(0) 475#define MPT_REPLY_HANDLER_CONFIG MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-1) 476#define MPT_REPLY_HANDLER_HANDSHAKE MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-2) 477typedef int mpt_reply_handler_t(struct mpt_softc *mpt, request_t *request, 478 uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame); 479typedef union { 480 mpt_reply_handler_t *reply_handler; 481} mpt_handler_t; 482 483typedef enum { 484 MPT_HANDLER_REPLY, 485 MPT_HANDLER_EVENT, 486 MPT_HANDLER_RESET, 487 MPT_HANDLER_SHUTDOWN 488} mpt_handler_type; 489 490struct mpt_handler_record 491{ 492 LIST_ENTRY(mpt_handler_record) links; 493 mpt_handler_t handler; 494}; 495 496LIST_HEAD(mpt_handler_list, mpt_handler_record); 497 498/* 499 * The handler_id is currently unused but would contain the 500 * handler ID used in the MsgContext field to allow direction 501 * of replies to the handler. Registrations that don't require 502 * a handler id can pass in NULL for the handler_id. 503 * 504 * Deregistrations for handlers without a handler id should 505 * pass in MPT_HANDLER_ID_NONE. 506 */ 507#define MPT_HANDLER_ID_NONE (0xFFFFFFFF) 508int mpt_register_handler(struct mpt_softc *, mpt_handler_type, 509 mpt_handler_t, uint32_t *); 510int mpt_deregister_handler(struct mpt_softc *, mpt_handler_type, 511 mpt_handler_t, uint32_t); 512 513/******************* Per-Controller Instance Data Structures ******************/ 514TAILQ_HEAD(req_queue, req_entry); 515 516/* Structure for saving proper values for modifyable PCI config registers */ 517struct mpt_pci_cfg { 518 uint16_t Command; 519 uint16_t LatencyTimer_LineSize; 520 uint32_t IO_BAR; 521 uint32_t Mem0_BAR[2]; 522 uint32_t Mem1_BAR[2]; 523 uint32_t ROM_BAR; 524 uint8_t IntLine; 525 uint32_t PMCSR; 526}; 527 528typedef enum { 529 MPT_RVF_NONE = 0x0, 530 MPT_RVF_ACTIVE = 0x1, 531 MPT_RVF_ANNOUNCED = 0x2, 532 MPT_RVF_UP2DATE = 0x4, 533 MPT_RVF_REFERENCED = 0x8, 534 MPT_RVF_WCE_CHANGED = 0x10 535} mpt_raid_volume_flags; 536 537struct mpt_raid_volume { 538 CONFIG_PAGE_RAID_VOL_0 *config_page; 539 MPI_RAID_VOL_INDICATOR sync_progress; 540 mpt_raid_volume_flags flags; 541 u_int quiesced_disks; 542}; 543 544typedef enum { 545 MPT_RDF_NONE = 0x00, 546 MPT_RDF_ACTIVE = 0x01, 547 MPT_RDF_ANNOUNCED = 0x02, 548 MPT_RDF_UP2DATE = 0x04, 549 MPT_RDF_REFERENCED = 0x08, 550 MPT_RDF_QUIESCING = 0x10, 551 MPT_RDF_QUIESCED = 0x20 552} mpt_raid_disk_flags; 553 554struct mpt_raid_disk { 555 CONFIG_PAGE_RAID_PHYS_DISK_0 config_page; 556 struct mpt_raid_volume *volume; 557 u_int member_number; 558 u_int pass_thru_active; 559 mpt_raid_disk_flags flags; 560}; 561 562struct mpt_evtf_record { 563 MSG_EVENT_NOTIFY_REPLY reply; 564 uint32_t context; 565 LIST_ENTRY(mpt_evtf_record) links; 566}; 567 568LIST_HEAD(mpt_evtf_list, mpt_evtf_record); 569 570struct mptsas_devinfo { 571 uint16_t dev_handle; 572 uint16_t parent_dev_handle; 573 uint16_t enclosure_handle; 574 uint16_t slot; 575 uint8_t phy_num; 576 uint8_t physical_port; 577 uint8_t target_id; 578 uint8_t bus; 579 uint64_t sas_address; 580 uint32_t device_info; 581}; 582 583struct mptsas_phyinfo { 584 uint16_t handle; 585 uint8_t phy_num; 586 uint8_t port_id; 587 uint8_t negotiated_link_rate; 588 uint8_t hw_link_rate; 589 uint8_t programmed_link_rate; 590 uint8_t sas_port_add_phy; 591 struct mptsas_devinfo identify; 592 struct mptsas_devinfo attached; 593}; 594 595struct mptsas_portinfo { 596 uint16_t num_phys; 597 struct mptsas_phyinfo *phy_info; 598}; 599 600struct mpt_softc { 601 device_t dev; 602#if __FreeBSD_version < 500000 603 uint32_t mpt_islocked; 604 int mpt_splsaved; 605#else 606 struct mtx mpt_lock; 607 int mpt_locksetup; 608#endif 609 uint32_t mpt_pers_mask; 610 uint32_t 611 : 8, 612 unit : 8, 613 ready : 1, 614 fw_uploaded : 1, 615 msi_enable : 1, 616 twildcard : 1, 617 tenabled : 1, 618 do_cfg_role : 1, 619 raid_enabled : 1, 620 raid_mwce_set : 1, 621 getreqwaiter : 1, 622 shutdwn_raid : 1, 623 shutdwn_recovery: 1, 624 outofbeer : 1, 625 disabled : 1, 626 is_spi : 1, 627 is_sas : 1, 628 is_fc : 1; 629 630 u_int cfg_role; 631 u_int role; /* role: none, ini, target, both */ 632 633 u_int verbose; 634#ifdef MPT_TEST_MULTIPATH 635 int failure_id; 636#endif 637 638 /* 639 * IOC Facts 640 */ 641 MSG_IOC_FACTS_REPLY ioc_facts; 642 643 /* 644 * Port Facts 645 */ 646 MSG_PORT_FACTS_REPLY * port_facts; 647#define mpt_max_tgtcmds port_facts[0].MaxPostedCmdBuffers 648 649 /* 650 * Device Configuration Information 651 */ 652 union { 653 struct mpt_spi_cfg { 654 CONFIG_PAGE_SCSI_PORT_0 _port_page0; 655 CONFIG_PAGE_SCSI_PORT_1 _port_page1; 656 CONFIG_PAGE_SCSI_PORT_2 _port_page2; 657 CONFIG_PAGE_SCSI_DEVICE_0 _dev_page0[16]; 658 CONFIG_PAGE_SCSI_DEVICE_1 _dev_page1[16]; 659 int _ini_id; 660 uint16_t _tag_enable; 661 uint16_t _disc_enable; 662 } spi; 663#define mpt_port_page0 cfg.spi._port_page0 664#define mpt_port_page1 cfg.spi._port_page1 665#define mpt_port_page2 cfg.spi._port_page2 666#define mpt_dev_page0 cfg.spi._dev_page0 667#define mpt_dev_page1 cfg.spi._dev_page1 668#define mpt_ini_id cfg.spi._ini_id 669#define mpt_tag_enable cfg.spi._tag_enable 670#define mpt_disc_enable cfg.spi._disc_enable 671 struct mpi_fc_cfg { 672 CONFIG_PAGE_FC_PORT_0 _port_page0; 673 uint32_t _port_speed; 674#define mpt_fcport_page0 cfg.fc._port_page0 675#define mpt_fcport_speed cfg.fc._port_speed 676 } fc; 677 } cfg; 678#if __FreeBSD_version >= 500000 679 /* 680 * Device config information stored up for sysctl to access 681 */ 682 union { 683 struct { 684 unsigned int initiator_id; 685 } spi; 686 struct { 687 char wwnn[19]; 688 char wwpn[19]; 689 } fc; 690 } scinfo; 691#endif 692 693 /* Controller Info for RAID information */ 694 CONFIG_PAGE_IOC_2 * ioc_page2; 695 CONFIG_PAGE_IOC_3 * ioc_page3; 696 697 /* Raid Data */ 698 struct mpt_raid_volume* raid_volumes; 699 struct mpt_raid_disk* raid_disks; 700 u_int raid_max_volumes; 701 u_int raid_max_disks; 702 u_int raid_page0_len; 703 u_int raid_wakeup; 704 u_int raid_rescan; 705 u_int raid_resync_rate; 706 u_int raid_mwce_setting; 707 u_int raid_queue_depth; 708 u_int raid_nonopt_volumes; 709 struct proc *raid_thread; 710 struct callout raid_timer; 711 712 /* 713 * PCI Hardware info 714 */ 715 int pci_msi_count; 716 struct resource * pci_irq; /* Interrupt map for chip */ 717 void * ih; /* Interupt handle */ 718 struct mpt_pci_cfg pci_cfg; /* saved PCI conf registers */ 719 720 /* 721 * DMA Mapping Stuff 722 */ 723 struct resource * pci_reg; /* Register map for chip */ 724 int pci_mem_rid; /* Resource ID */ 725 bus_space_tag_t pci_st; /* Bus tag for registers */ 726 bus_space_handle_t pci_sh; /* Bus handle for registers */ 727 /* PIO versions of above. */ 728 int pci_pio_rid; 729 struct resource * pci_pio_reg; 730 bus_space_tag_t pci_pio_st; 731 bus_space_handle_t pci_pio_sh; 732 733 bus_dma_tag_t parent_dmat; /* DMA tag for parent PCI bus */ 734 bus_dma_tag_t reply_dmat; /* DMA tag for reply memory */ 735 bus_dmamap_t reply_dmap; /* DMA map for reply memory */ 736 uint8_t *reply; /* KVA of reply memory */ 737 bus_addr_t reply_phys; /* BusAddr of reply memory */ 738 739 bus_dma_tag_t buffer_dmat; /* DMA tag for buffers */ 740 bus_dma_tag_t request_dmat; /* DMA tag for request memroy */ 741 bus_dmamap_t request_dmap; /* DMA map for request memroy */ 742 uint8_t *request; /* KVA of Request memory */ 743 bus_addr_t request_phys; /* BusAddr of request memory */ 744 745 uint32_t max_seg_cnt; /* calculated after IOC facts */ 746 uint32_t max_cam_seg_cnt;/* calculated from MAXPHYS*/ 747 748 /* 749 * Hardware management 750 */ 751 u_int reset_cnt; 752 753 /* 754 * CAM && Software Management 755 */ 756 request_t *request_pool; 757 struct req_queue request_free_list; 758 struct req_queue request_pending_list; 759 struct req_queue request_timeout_list; 760 761 762 struct cam_sim *sim; 763 struct cam_path *path; 764 765 struct cam_sim *phydisk_sim; 766 struct cam_path *phydisk_path; 767 768 struct proc *recovery_thread; 769 request_t *tmf_req; 770 771 /* 772 * Deferred frame acks due to resource shortage. 773 */ 774 struct mpt_evtf_list ack_frames; 775 776 /* 777 * Target Mode Support 778 */ 779 uint32_t scsi_tgt_handler_id; 780 request_t ** tgt_cmd_ptrs; 781 request_t ** els_cmd_ptrs; /* FC only */ 782 783 /* 784 * *snork*- this is chosen to be here *just in case* somebody 785 * forgets to point to it exactly and we index off of trt with 786 * CAM_LUN_WILDCARD. 787 */ 788 tgt_resource_t trt_wildcard; /* wildcard luns */ 789 tgt_resource_t trt[MPT_MAX_LUNS]; 790 uint16_t tgt_cmds_allocated; 791 uint16_t els_cmds_allocated; /* FC only */ 792 793 uint16_t timeouts; /* timeout count */ 794 uint16_t success; /* successes afer timeout */ 795 uint16_t sequence; /* Sequence Number */ 796 uint16_t pad3; 797 798 799 /* Paired port in some dual adapters configurations */ 800 struct mpt_softc * mpt2; 801 802 /* FW Image management */ 803 uint32_t fw_image_size; 804 uint8_t *fw_image; 805 bus_dma_tag_t fw_dmat; /* DMA tag for firmware image */ 806 bus_dmamap_t fw_dmap; /* DMA map for firmware image */ 807 bus_addr_t fw_phys; /* BusAddr of firmware image */ 808 809 /* SAS Topology */ 810 struct mptsas_portinfo *sas_portinfo; 811 812 /* Shutdown Event Handler. */ 813 eventhandler_tag eh; 814 815 /* Userland management interface. */ 816 struct cdev *cdev; 817 818 TAILQ_ENTRY(mpt_softc) links; 819}; 820 821static __inline void mpt_assign_serno(struct mpt_softc *, request_t *); 822 823static __inline void 824mpt_assign_serno(struct mpt_softc *mpt, request_t *req) 825{ 826 if ((req->serno = mpt->sequence++) == 0) { 827 req->serno = mpt->sequence++; 828 } 829} 830 831/***************************** Locking Primitives *****************************/ 832#if __FreeBSD_version < 500000 833#define MPT_IFLAGS INTR_TYPE_CAM 834#define MPT_LOCK(mpt) mpt_lockspl(mpt) 835#define MPT_UNLOCK(mpt) mpt_unlockspl(mpt) 836#define MPT_OWNED(mpt) mpt->mpt_islocked 837#define MPT_LOCK_ASSERT(mpt) 838#define MPTLOCK_2_CAMLOCK MPT_UNLOCK 839#define CAMLOCK_2_MPTLOCK MPT_LOCK 840#define MPT_LOCK_SETUP(mpt) 841#define MPT_LOCK_DESTROY(mpt) 842 843static __inline void mpt_lockspl(struct mpt_softc *mpt); 844static __inline void mpt_unlockspl(struct mpt_softc *mpt); 845 846static __inline void 847mpt_lockspl(struct mpt_softc *mpt) 848{ 849 int s; 850 851 s = splcam(); 852 if (mpt->mpt_islocked++ == 0) { 853 mpt->mpt_splsaved = s; 854 } else { 855 splx(s); 856 panic("Recursed lock with mask: 0x%x\n", s); 857 } 858} 859 860static __inline void 861mpt_unlockspl(struct mpt_softc *mpt) 862{ 863 if (mpt->mpt_islocked) { 864 if (--mpt->mpt_islocked == 0) { 865 splx(mpt->mpt_splsaved); 866 } 867 } else 868 panic("Negative lock count\n"); 869} 870 871static __inline int 872mpt_sleep(struct mpt_softc *mpt, void *ident, int priority, 873 const char *wmesg, int timo) 874{ 875 int saved_cnt; 876 int saved_spl; 877 int error; 878 879 KASSERT(mpt->mpt_islocked <= 1, ("Invalid lock count on tsleep")); 880 saved_cnt = mpt->mpt_islocked; 881 saved_spl = mpt->mpt_splsaved; 882 mpt->mpt_islocked = 0; 883 error = tsleep(ident, priority, wmesg, timo); 884 KASSERT(mpt->mpt_islocked == 0, ("Invalid lock count on wakeup")); 885 mpt->mpt_islocked = saved_cnt; 886 mpt->mpt_splsaved = saved_spl; 887 return (error); 888} 889 890#define mpt_req_timeout(req, ticks, func, arg) \ 891 callout_reset(&(req)->callout, (ticks), (func), (arg)); 892#define mpt_req_untimeout(req, func, arg) \ 893 callout_stop(&(req)->callout) 894#define mpt_callout_init(mpt, c) \ 895 callout_init(c) 896#define mpt_callout_drain(mpt, c) \ 897 callout_stop(c) 898 899#else 900#if 1 901#define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE 902#define MPT_LOCK_SETUP(mpt) \ 903 mtx_init(&mpt->mpt_lock, "mpt", NULL, MTX_DEF); \ 904 mpt->mpt_locksetup = 1 905#define MPT_LOCK_DESTROY(mpt) \ 906 if (mpt->mpt_locksetup) { \ 907 mtx_destroy(&mpt->mpt_lock); \ 908 mpt->mpt_locksetup = 0; \ 909 } 910 911#define MPT_LOCK(mpt) mtx_lock(&(mpt)->mpt_lock) 912#define MPT_UNLOCK(mpt) mtx_unlock(&(mpt)->mpt_lock) 913#define MPT_OWNED(mpt) mtx_owned(&(mpt)->mpt_lock) 914#define MPT_LOCK_ASSERT(mpt) mtx_assert(&(mpt)->mpt_lock, MA_OWNED) 915#define MPTLOCK_2_CAMLOCK(mpt) 916#define CAMLOCK_2_MPTLOCK(mpt) 917#define mpt_sleep(mpt, ident, priority, wmesg, timo) \ 918 msleep(ident, &(mpt)->mpt_lock, priority, wmesg, timo) 919#define mpt_req_timeout(req, ticks, func, arg) \ 920 callout_reset(&(req)->callout, (ticks), (func), (arg)) 921#define mpt_req_untimeout(req, func, arg) \ 922 callout_stop(&(req)->callout) 923#define mpt_callout_init(mpt, c) \ 924 callout_init_mtx(c, &(mpt)->mpt_lock, 0) 925#define mpt_callout_drain(mpt, c) \ 926 callout_drain(c) 927 928#else 929 930#define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY 931#define MPT_LOCK_SETUP(mpt) do { } while (0) 932#define MPT_LOCK_DESTROY(mpt) do { } while (0) 933#define MPT_LOCK_ASSERT(mpt) mtx_assert(&Giant, MA_OWNED) 934#define MPT_LOCK(mpt) mtx_lock(&Giant) 935#define MPT_UNLOCK(mpt) mtx_unlock(&Giant) 936#define MPTLOCK_2_CAMLOCK(mpt) 937#define CAMLOCK_2_MPTLOCK(mpt) 938 939#define mpt_req_timeout(req, ticks, func, arg) \ 940 callout_reset(&(req)->callout, (ticks), (func), (arg)) 941#define mpt_req_untimeout(req, func, arg) \ 942 callout_stop(&(req)->callout) 943#define mpt_callout_init(mpt, c) \ 944 callout_init(c, 0) 945#define mpt_callout_drain(mpt, c) \ 946 callout_drain(c) 947 948static __inline int 949mpt_sleep(struct mpt_softc *, void *, int, const char *, int); 950 951static __inline int 952mpt_sleep(struct mpt_softc *mpt, void *i, int p, const char *w, int t) 953{ 954 int r; 955 r = tsleep(i, p, w, t); 956 return (r); 957} 958#endif 959#endif 960 961/******************************* Register Access ******************************/ 962static __inline void mpt_write(struct mpt_softc *, size_t, uint32_t); 963static __inline uint32_t mpt_read(struct mpt_softc *, int); 964static __inline void mpt_pio_write(struct mpt_softc *, size_t, uint32_t); 965static __inline uint32_t mpt_pio_read(struct mpt_softc *, int); 966 967static __inline void 968mpt_write(struct mpt_softc *mpt, size_t offset, uint32_t val) 969{ 970 bus_space_write_4(mpt->pci_st, mpt->pci_sh, offset, val); 971} 972 973static __inline uint32_t 974mpt_read(struct mpt_softc *mpt, int offset) 975{ 976 return (bus_space_read_4(mpt->pci_st, mpt->pci_sh, offset)); 977} 978 979/* 980 * Some operations (e.g. diagnostic register writes while the ARM proccessor 981 * is disabled), must be performed using "PCI pio" operations. On non-PCI 982 * busses, these operations likely map to normal register accesses. 983 */ 984static __inline void 985mpt_pio_write(struct mpt_softc *mpt, size_t offset, uint32_t val) 986{ 987 bus_space_write_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset, val); 988} 989 990static __inline uint32_t 991mpt_pio_read(struct mpt_softc *mpt, int offset) 992{ 993 return (bus_space_read_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset)); 994} 995/*********************** Reply Frame/Request Management ***********************/ 996/* Max MPT Reply we are willing to accept (must be power of 2) */ 997#define MPT_REPLY_SIZE 256 998 999/* 1000 * Must be less than 16384 in order for target mode to work 1001 */ 1002#define MPT_MAX_REQUESTS(mpt) 512 1003#define MPT_REQUEST_AREA 512 1004#define MPT_SENSE_SIZE 32 /* included in MPT_REQUEST_AREA */ 1005#define MPT_REQ_MEM_SIZE(mpt) (MPT_MAX_REQUESTS(mpt) * MPT_REQUEST_AREA) 1006 1007#define MPT_CONTEXT_CB_SHIFT (16) 1008#define MPT_CBI(handle) (handle >> MPT_CONTEXT_CB_SHIFT) 1009#define MPT_CBI_TO_HID(cbi) ((cbi) << MPT_CONTEXT_CB_SHIFT) 1010#define MPT_CONTEXT_TO_CBI(x) \ 1011 (((x) >> MPT_CONTEXT_CB_SHIFT) & (MPT_NUM_REPLY_HANDLERS - 1)) 1012#define MPT_CONTEXT_REQI_MASK 0xFFFF 1013#define MPT_CONTEXT_TO_REQI(x) ((x) & MPT_CONTEXT_REQI_MASK) 1014 1015/* 1016 * Convert a 32bit physical address returned from IOC to an 1017 * offset into our reply frame memory or the kvm address needed 1018 * to access the data. The returned address is only the low 1019 * 32 bits, so mask our base physical address accordingly. 1020 */ 1021#define MPT_REPLY_BADDR(x) \ 1022 (x << 1) 1023#define MPT_REPLY_OTOV(m, i) \ 1024 ((void *)(&m->reply[i])) 1025 1026#define MPT_DUMP_REPLY_FRAME(mpt, reply_frame) \ 1027do { \ 1028 if (mpt->verbose > MPT_PRT_DEBUG) \ 1029 mpt_dump_reply_frame(mpt, reply_frame); \ 1030} while(0) 1031 1032static __inline uint32_t mpt_pop_reply_queue(struct mpt_softc *mpt); 1033static __inline void mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr); 1034 1035/* 1036 * Give the reply buffer back to the IOC after we have 1037 * finished processing it. 1038 */ 1039static __inline void 1040mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr) 1041{ 1042 mpt_write(mpt, MPT_OFFSET_REPLY_Q, ptr); 1043} 1044 1045/* Get a reply from the IOC */ 1046static __inline uint32_t 1047mpt_pop_reply_queue(struct mpt_softc *mpt) 1048{ 1049 return mpt_read(mpt, MPT_OFFSET_REPLY_Q); 1050} 1051 1052void 1053mpt_complete_request_chain(struct mpt_softc *, struct req_queue *, u_int); 1054 1055/************************** Scatter Gather Managment **************************/ 1056/* MPT_RQSL- size of request frame, in bytes */ 1057#define MPT_RQSL(mpt) (mpt->ioc_facts.RequestFrameSize << 2) 1058 1059/* MPT_NSGL- how many SG entries can fit in a request frame size */ 1060#define MPT_NSGL(mpt) (MPT_RQSL(mpt) / sizeof (SGE_IO_UNION)) 1061 1062/* MPT_NRFM- how many request frames can fit in each request alloc we make */ 1063#define MPT_NRFM(mpt) (MPT_REQUEST_AREA / MPT_RQSL(mpt)) 1064 1065/* 1066 * MPT_NSGL_FIRST- # of SG elements that can fit after 1067 * an I/O request but still within the request frame. 1068 * Do this safely based upon SGE_IO_UNION. 1069 * 1070 * Note that the first element is *within* the SCSI request. 1071 */ 1072#define MPT_NSGL_FIRST(mpt) \ 1073 ((MPT_RQSL(mpt) - sizeof (MSG_SCSI_IO_REQUEST) + sizeof (SGE_IO_UNION)) / \ 1074 sizeof (SGE_IO_UNION)) 1075 1076/***************************** IOC Initialization *****************************/ 1077int mpt_reset(struct mpt_softc *, int /*reinit*/); 1078 1079/****************************** Debugging ************************************/ 1080typedef struct mpt_decode_entry { 1081 char *name; 1082 u_int value; 1083 u_int mask; 1084} mpt_decode_entry_t; 1085 1086int mpt_decode_value(mpt_decode_entry_t *table, u_int num_entries, 1087 const char *name, u_int value, u_int *cur_column, 1088 u_int wrap_point); 1089 1090void mpt_dump_data(struct mpt_softc *, const char *, void *, int); 1091void mpt_dump_request(struct mpt_softc *, request_t *); 1092 1093enum { 1094 MPT_PRT_ALWAYS, 1095 MPT_PRT_FATAL, 1096 MPT_PRT_ERROR, 1097 MPT_PRT_WARN, 1098 MPT_PRT_INFO, 1099 MPT_PRT_NEGOTIATION, 1100 MPT_PRT_DEBUG, 1101 MPT_PRT_DEBUG1, 1102 MPT_PRT_DEBUG2, 1103 MPT_PRT_DEBUG3, 1104 MPT_PRT_TRACE, 1105 MPT_PRT_NONE=100 1106}; 1107 1108#if __FreeBSD_version > 500000 1109#define mpt_lprt(mpt, level, ...) \ 1110do { \ 1111 if (level <= (mpt)->verbose) \ 1112 mpt_prt(mpt, __VA_ARGS__); \ 1113} while (0) 1114 1115#define mpt_lprtc(mpt, level, ...) \ 1116do { \ 1117 if (level <= (mpt)->debug_level) \ 1118 mpt_prtc(mpt, __VA_ARGS__); \ 1119} while (0) 1120#else 1121void mpt_lprt(struct mpt_softc *, int, const char *, ...) 1122 __printflike(3, 4); 1123void mpt_lprtc(struct mpt_softc *, int, const char *, ...) 1124 __printflike(3, 4); 1125#endif 1126void mpt_prt(struct mpt_softc *, const char *, ...) 1127 __printflike(2, 3); 1128void mpt_prtc(struct mpt_softc *, const char *, ...) 1129 __printflike(2, 3); 1130 1131/**************************** Target Mode Related ***************************/ 1132static __inline int mpt_cdblen(uint8_t, int); 1133static __inline int 1134mpt_cdblen(uint8_t cdb0, int maxlen) 1135{ 1136 int group = cdb0 >> 5; 1137 switch (group) { 1138 case 0: 1139 return (6); 1140 case 1: 1141 return (10); 1142 case 4: 1143 case 5: 1144 return (12); 1145 default: 1146 return (16); 1147 } 1148} 1149#ifdef INVARIANTS 1150static __inline request_t * mpt_tag_2_req(struct mpt_softc *, uint32_t); 1151static __inline request_t * 1152mpt_tag_2_req(struct mpt_softc *mpt, uint32_t tag) 1153{ 1154 uint16_t rtg = (tag >> 18); 1155 KASSERT(rtg < mpt->tgt_cmds_allocated, ("bad tag %d\n", tag)); 1156 KASSERT(mpt->tgt_cmd_ptrs, ("no cmd backpointer array")); 1157 KASSERT(mpt->tgt_cmd_ptrs[rtg], ("no cmd backpointer")); 1158 return (mpt->tgt_cmd_ptrs[rtg]); 1159} 1160 1161 1162static __inline int 1163mpt_req_on_free_list(struct mpt_softc *, request_t *); 1164static __inline int 1165mpt_req_on_pending_list(struct mpt_softc *, request_t *); 1166 1167static __inline void 1168mpt_req_spcl(struct mpt_softc *, request_t *, const char *, int); 1169static __inline void 1170mpt_req_not_spcl(struct mpt_softc *, request_t *, const char *, int); 1171 1172 1173/* 1174 * Is request on freelist? 1175 */ 1176static __inline int 1177mpt_req_on_free_list(struct mpt_softc *mpt, request_t *req) 1178{ 1179 request_t *lrq; 1180 1181 TAILQ_FOREACH(lrq, &mpt->request_free_list, links) { 1182 if (lrq == req) { 1183 return (1); 1184 } 1185 } 1186 return (0); 1187} 1188 1189/* 1190 * Is request on pending list? 1191 */ 1192static __inline int 1193mpt_req_on_pending_list(struct mpt_softc *mpt, request_t *req) 1194{ 1195 request_t *lrq; 1196 1197 TAILQ_FOREACH(lrq, &mpt->request_pending_list, links) { 1198 if (lrq == req) { 1199 return (1); 1200 } 1201 } 1202 return (0); 1203} 1204 1205/* 1206 * Make sure that req *is* part of one of the special lists 1207 */ 1208static __inline void 1209mpt_req_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line) 1210{ 1211 int i; 1212 for (i = 0; i < mpt->els_cmds_allocated; i++) { 1213 if (req == mpt->els_cmd_ptrs[i]) { 1214 return; 1215 } 1216 } 1217 for (i = 0; i < mpt->tgt_cmds_allocated; i++) { 1218 if (req == mpt->tgt_cmd_ptrs[i]) { 1219 return; 1220 } 1221 } 1222 panic("%s(%d): req %p:%u function %x not in els or tgt ptrs\n", 1223 s, line, req, req->serno, 1224 ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function); 1225} 1226 1227/* 1228 * Make sure that req is *not* part of one of the special lists. 1229 */ 1230static __inline void 1231mpt_req_not_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line) 1232{ 1233 int i; 1234 for (i = 0; i < mpt->els_cmds_allocated; i++) { 1235 KASSERT(req != mpt->els_cmd_ptrs[i], 1236 ("%s(%d): req %p:%u func %x in els ptrs at ioindex %d\n", 1237 s, line, req, req->serno, 1238 ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i)); 1239 } 1240 for (i = 0; i < mpt->tgt_cmds_allocated; i++) { 1241 KASSERT(req != mpt->tgt_cmd_ptrs[i], 1242 ("%s(%d): req %p:%u func %x in tgt ptrs at ioindex %d\n", 1243 s, line, req, req->serno, 1244 ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i)); 1245 } 1246} 1247#endif 1248 1249/* 1250 * Task Management Types, purely for internal consumption 1251 */ 1252typedef enum { 1253 MPT_ABORT_TASK_SET=1234, 1254 MPT_CLEAR_TASK_SET, 1255 MPT_TARGET_RESET, 1256 MPT_CLEAR_ACA, 1257 MPT_TERMINATE_TASK, 1258 MPT_NIL_TMT_VALUE=5678 1259} mpt_task_mgmt_t; 1260 1261/**************************** Unclassified Routines ***************************/ 1262void mpt_send_cmd(struct mpt_softc *mpt, request_t *req); 1263int mpt_recv_handshake_reply(struct mpt_softc *mpt, 1264 size_t reply_len, void *reply); 1265int mpt_wait_req(struct mpt_softc *mpt, request_t *req, 1266 mpt_req_state_t state, mpt_req_state_t mask, 1267 int sleep_ok, int time_ms); 1268void mpt_enable_ints(struct mpt_softc *mpt); 1269void mpt_disable_ints(struct mpt_softc *mpt); 1270int mpt_attach(struct mpt_softc *mpt); 1271int mpt_shutdown(struct mpt_softc *mpt); 1272int mpt_detach(struct mpt_softc *mpt); 1273int mpt_send_handshake_cmd(struct mpt_softc *mpt, 1274 size_t len, void *cmd); 1275request_t * mpt_get_request(struct mpt_softc *mpt, int sleep_ok); 1276void mpt_free_request(struct mpt_softc *mpt, request_t *req); 1277void mpt_intr(void *arg); 1278void mpt_check_doorbell(struct mpt_softc *mpt); 1279void mpt_dump_reply_frame(struct mpt_softc *mpt, 1280 MSG_DEFAULT_REPLY *reply_frame); 1281 1282int mpt_dma_buf_alloc(struct mpt_softc *mpt); 1283void mpt_set_config_regs(struct mpt_softc *); 1284int mpt_issue_cfg_req(struct mpt_softc */*mpt*/, request_t */*req*/, 1285 cfgparms_t *params, 1286 bus_addr_t /*addr*/, bus_size_t/*len*/, 1287 int /*sleep_ok*/, int /*timeout_ms*/); 1288int mpt_read_extcfg_header(struct mpt_softc *mpt, int PageVersion, 1289 int PageNumber, uint32_t PageAddress, 1290 int ExtPageType, 1291 CONFIG_EXTENDED_PAGE_HEADER *rslt, 1292 int sleep_ok, int timeout_ms); 1293int mpt_read_extcfg_page(struct mpt_softc *mpt, int Action, 1294 uint32_t PageAddress, 1295 CONFIG_EXTENDED_PAGE_HEADER *hdr, 1296 void *buf, size_t len, int sleep_ok, 1297 int timeout_ms); 1298int mpt_read_cfg_header(struct mpt_softc *, int /*PageType*/, 1299 int /*PageNumber*/, 1300 uint32_t /*PageAddress*/, 1301 CONFIG_PAGE_HEADER *, 1302 int /*sleep_ok*/, int /*timeout_ms*/); 1303int mpt_read_cfg_page(struct mpt_softc *t, int /*Action*/, 1304 uint32_t /*PageAddress*/, 1305 CONFIG_PAGE_HEADER *, size_t /*len*/, 1306 int /*sleep_ok*/, int /*timeout_ms*/); 1307int mpt_write_cfg_page(struct mpt_softc *, int /*Action*/, 1308 uint32_t /*PageAddress*/, 1309 CONFIG_PAGE_HEADER *, size_t /*len*/, 1310 int /*sleep_ok*/, int /*timeout_ms*/); 1311static __inline int 1312mpt_read_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress, 1313 CONFIG_PAGE_HEADER *hdr, size_t len, 1314 int sleep_ok, int timeout_ms) 1315{ 1316 return (mpt_read_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT, 1317 PageAddress, hdr, len, sleep_ok, timeout_ms)); 1318} 1319 1320static __inline int 1321mpt_write_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress, 1322 CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok, 1323 int timeout_ms) 1324{ 1325 return (mpt_write_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT, 1326 PageAddress, hdr, len, sleep_ok, 1327 timeout_ms)); 1328} 1329/* mpt_debug.c functions */ 1330void mpt_print_reply(void *vmsg); 1331void mpt_print_db(uint32_t mb); 1332void mpt_print_config_reply(void *vmsg); 1333char *mpt_ioc_diag(uint32_t diag); 1334void mpt_req_state(mpt_req_state_t state); 1335void mpt_print_config_request(void *vmsg); 1336void mpt_print_request(void *vmsg); 1337void mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *msg); 1338void mpt_dump_sgl(SGE_IO_UNION *se, int offset); 1339#endif /* _MPT_H_ */ 1340