xref: /freebsd/sys/dev/tws/tws_services.h (revision f1951fd745b894fe6586c298874af98544a5e272)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2010, LSI Corp.
5  * All rights reserved.
6  * Author : Manjunath Ranganathaiah
7  * Support: freebsdraid@lsi.com
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  * 3. Neither the name of the <ORGANIZATION> nor the names of its
20  *    contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $FreeBSD$
37  */
38 
39 
40 /* #define TWS_DEBUG on */
41 
42 void tws_trace(const char *file, const char *fun, int linenum,
43          struct tws_softc *sc,  char *desc, u_int64_t val1, u_int64_t val2);
44 void tws_log(struct tws_softc *sc, int index);
45 u_int32_t tws_read_reg(struct tws_softc *sc,
46                   int offset, int size);
47 void tws_write_reg(struct tws_softc *sc, int offset,
48                   u_int32_t value, int size);
49 
50 u_int16_t tws_swap16(u_int16_t val);
51 u_int32_t tws_swap32(u_int32_t val);
52 u_int64_t tws_swap64(u_int64_t val);
53 
54 void tws_init_qs(struct tws_softc *sc);
55 
56 
57 
58 /* ----------------- trace ----------------- */
59 
60 #define TWS_TRACE_ON on /* Alawys on - use wisely to trace errors */
61 
62 #ifdef TWS_DEBUG
63     #define TWS_TRACE_DEBUG_ON on
64 #endif
65 
66 #ifdef TWS_TRACE_DEBUG_ON
67     #define TWS_TRACE_DEBUG(sc, desc, val1, val2) \
68             tws_trace(__FILE__, __func__, __LINE__, sc, desc, \
69                                    (u_int64_t)val1, (u_int64_t)val2)
70 #else
71     #define TWS_TRACE_DEBUG(sc, desc, val1, val2)
72 #endif
73 
74 #ifdef TWS_TRACE_ON
75     #define TWS_TRACE(sc, desc, val1, val2) \
76             tws_trace(__FILE__, __func__, __LINE__, sc, desc, \
77                                    (u_int64_t)val1, (u_int64_t)val2)
78 #else
79     #define TWS_TRACE(sc, desc, val1, val2)
80 #endif
81 
82 /* ---------------- logging ---------------- */
83 
84 
85 /* ---------------- logging ---------------- */
86 enum error_index {
87     SYSCTL_TREE_NODE_ADD,
88     PCI_COMMAND_READ,
89     ALLOC_MEMORY_RES,
90     ALLOC_IRQ_RES,
91     SETUP_INTR_RES,
92     TWS_CAM_ATTACH,
93     CAM_SIMQ_ALLOC,
94     CAM_SIM_ALLOC,
95     TWS_XPT_BUS_REGISTER,
96     TWS_XPT_CREATE_PATH,
97     TWS_BUS_SCAN_REQ,
98     TWS_INIT_FAILURE,
99     TWS_CTLR_INIT_FAILURE,
100 };
101 
102 enum severity {
103     ERROR = 1,
104     WARNING,
105     INFO,
106 #if 0
107     DEBUG,
108 #endif
109 };
110 
111 struct error_desc {
112     char desc[256];
113     u_int32_t error_code;
114     int severity_level;
115     char *fmt;
116     char *error_str;
117 };
118 
119 /* ----------- q services ------------- */
120 
121 #define TWS_FREE_Q        0
122 #define TWS_PENDING_Q     1
123 #define TWS_BUSY_Q        2
124 #define TWS_COMPLETE_Q    3
125 
126 /* req return codes */
127 #define TWS_REQ_RET_SUBMIT_SUCCESS 0
128 #define TWS_REQ_RET_PEND_NOMFA     1
129 #define TWS_REQ_RET_RESET          2
130 #define TWS_REQ_RET_INVALID   0xdead
131 
132 
133 /* ------------------------ */
134 #if (__FreeBSD_version >= 700000)
135 #include <sys/clock.h>
136 #define TWS_LOCAL_TIME (time_second - utc_offset())
137 #else
138 #include <machine/clock.h>
139 #define TWS_LOCAL_TIME (time_second - (tz_minuteswest * 60) -   \
140                   (wall_cmos_clock ? adjkerntz : 0))
141 #endif
142 
143