1226026Sdelphij/* 2226026Sdelphij * Copyright (c) 2010, LSI Corp. 3226026Sdelphij * All rights reserved. 4226026Sdelphij * Author : Manjunath Ranganathaiah 5226026Sdelphij * Support: freebsdraid@lsi.com 6226026Sdelphij * 7226026Sdelphij * Redistribution and use in source and binary forms, with or without 8226026Sdelphij * modification, are permitted provided that the following conditions 9226026Sdelphij * are met: 10226026Sdelphij * 11226026Sdelphij * 1. Redistributions of source code must retain the above copyright 12226026Sdelphij * notice, this list of conditions and the following disclaimer. 13226026Sdelphij * 2. Redistributions in binary form must reproduce the above copyright 14226026Sdelphij * notice, this list of conditions and the following disclaimer in 15226026Sdelphij * the documentation and/or other materials provided with the 16226026Sdelphij * distribution. 17226026Sdelphij * 3. Neither the name of the <ORGANIZATION> nor the names of its 18226026Sdelphij * contributors may be used to endorse or promote products derived 19226026Sdelphij * from this software without specific prior written permission. 20226026Sdelphij * 21226026Sdelphij * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22226026Sdelphij * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23226026Sdelphij * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24226026Sdelphij * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25226026Sdelphij * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26226026Sdelphij * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27226026Sdelphij * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28226026Sdelphij * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29226026Sdelphij * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30226026Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31226026Sdelphij * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32226026Sdelphij * POSSIBILITY OF SUCH DAMAGE. 33226026Sdelphij * 34226026Sdelphij * $FreeBSD$ 35226026Sdelphij */ 36226026Sdelphij 37226026Sdelphij 38226026Sdelphij/* #define TWS_DEBUG on */ 39226026Sdelphij 40226026Sdelphijvoid tws_trace(const char *file, const char *fun, int linenum, 41226026Sdelphij struct tws_softc *sc, char *desc, u_int64_t val1, u_int64_t val2); 42226026Sdelphijvoid tws_log(struct tws_softc *sc, int index); 43226026Sdelphiju_int32_t tws_read_reg(struct tws_softc *sc, 44226026Sdelphij int offset, int size); 45226026Sdelphijvoid tws_write_reg(struct tws_softc *sc, int offset, 46226026Sdelphij u_int32_t value, int size); 47226026Sdelphij 48226026Sdelphiju_int16_t tws_swap16(u_int16_t val); 49226026Sdelphiju_int32_t tws_swap32(u_int32_t val); 50226026Sdelphiju_int64_t tws_swap64(u_int64_t val); 51226026Sdelphij 52226026Sdelphijvoid tws_init_qs(struct tws_softc *sc); 53226026Sdelphij 54226026Sdelphij 55226026Sdelphij 56226026Sdelphij/* ----------------- trace ----------------- */ 57226026Sdelphij 58226026Sdelphij#define TWS_TRACE_ON on /* Alawys on - use wisely to trace errors */ 59226026Sdelphij 60226026Sdelphij#ifdef TWS_DEBUG 61226026Sdelphij #define TWS_TRACE_DEBUG_ON on 62226026Sdelphij#endif 63226026Sdelphij 64226026Sdelphij#ifdef TWS_TRACE_DEBUG_ON 65226026Sdelphij #define TWS_TRACE_DEBUG(sc, desc, val1, val2) \ 66226026Sdelphij tws_trace(__FILE__, __func__, __LINE__, sc, desc, \ 67226026Sdelphij (u_int64_t)val1, (u_int64_t)val2) 68226026Sdelphij#else 69226026Sdelphij #define TWS_TRACE_DEBUG(sc, desc, val1, val2) 70226026Sdelphij#endif 71226026Sdelphij 72226026Sdelphij#ifdef TWS_TRACE_ON 73226026Sdelphij #define TWS_TRACE(sc, desc, val1, val2) \ 74226026Sdelphij tws_trace(__FILE__, __func__, __LINE__, sc, desc, \ 75226026Sdelphij (u_int64_t)val1, (u_int64_t)val2) 76226026Sdelphij#else 77226026Sdelphij #define TWS_TRACE(sc, desc, val1, val2) 78226026Sdelphij#endif 79226026Sdelphij 80226026Sdelphij/* ---------------- logging ---------------- */ 81226026Sdelphij 82226026Sdelphij 83226026Sdelphij/* ---------------- logging ---------------- */ 84226026Sdelphijenum error_index { 85226026Sdelphij SYSCTL_TREE_NODE_ADD, 86226026Sdelphij PCI_COMMAND_READ, 87226026Sdelphij ALLOC_MEMORY_RES, 88226026Sdelphij ALLOC_IRQ_RES, 89226026Sdelphij SETUP_INTR_RES, 90226026Sdelphij TWS_CAM_ATTACH, 91226026Sdelphij CAM_SIMQ_ALLOC, 92226026Sdelphij CAM_SIM_ALLOC, 93226026Sdelphij TWS_XPT_BUS_REGISTER, 94226026Sdelphij TWS_XPT_CREATE_PATH, 95226026Sdelphij TWS_BUS_SCAN_REQ, 96226026Sdelphij TWS_INIT_FAILURE, 97226026Sdelphij TWS_CTLR_INIT_FAILURE, 98226026Sdelphij}; 99226026Sdelphij 100226026Sdelphijenum severity { 101226026Sdelphij ERROR = 1, 102226026Sdelphij WARNING, 103226026Sdelphij INFO, 104226026Sdelphij#if 0 105226026Sdelphij DEBUG, 106226026Sdelphij#endif 107226026Sdelphij}; 108226026Sdelphij 109226026Sdelphijstruct error_desc { 110226026Sdelphij char desc[256]; 111226026Sdelphij u_int32_t error_code; 112226026Sdelphij int severity_level; 113226026Sdelphij char *fmt; 114226026Sdelphij char *error_str; 115226026Sdelphij}; 116226026Sdelphij 117226026Sdelphij/* ----------- q services ------------- */ 118226026Sdelphij 119226026Sdelphij#define TWS_FREE_Q 0 120226026Sdelphij#define TWS_PENDING_Q 1 121226026Sdelphij#define TWS_BUSY_Q 2 122226026Sdelphij#define TWS_COMPLETE_Q 3 123226026Sdelphij 124226026Sdelphij/* req return codes */ 125226026Sdelphij#define TWS_REQ_RET_SUBMIT_SUCCESS 0 126226026Sdelphij#define TWS_REQ_RET_PEND_NOMFA 1 127226026Sdelphij#define TWS_REQ_RET_RESET 2 128226026Sdelphij#define TWS_REQ_RET_INVALID 0xdead 129226026Sdelphij 130226026Sdelphij 131226026Sdelphij/* ------------------------ */ 132226026Sdelphij#if (__FreeBSD_version >= 700000) 133226026Sdelphij#include <sys/clock.h> 134226026Sdelphij#define TWS_LOCAL_TIME (time_second - utc_offset()) 135226026Sdelphij#else 136226026Sdelphij#include <machine/clock.h> 137226026Sdelphij#define TWS_LOCAL_TIME (time_second - (tz_minuteswest * 60) - \ 138226026Sdelphij (wall_cmos_clock ? adjkerntz : 0)) 139226026Sdelphij#endif 140226026Sdelphij 141