xref: /freebsd/sys/dev/tws/tws_services.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
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 
37 /* #define TWS_DEBUG on */
38 
39 void tws_trace(const char *file, const char *fun, int linenum,
40          struct tws_softc *sc,  char *desc, u_int64_t val1, u_int64_t val2);
41 void tws_log(struct tws_softc *sc, int index);
42 u_int32_t tws_read_reg(struct tws_softc *sc,
43                   int offset, int size);
44 void tws_write_reg(struct tws_softc *sc, int offset,
45                   u_int32_t value, int size);
46 
47 u_int16_t tws_swap16(u_int16_t val);
48 u_int32_t tws_swap32(u_int32_t val);
49 u_int64_t tws_swap64(u_int64_t val);
50 
51 void tws_init_qs(struct tws_softc *sc);
52 
53 /* ----------------- trace ----------------- */
54 
55 #define TWS_TRACE_ON on /* Alawys on - use wisely to trace errors */
56 
57 #ifdef TWS_DEBUG
58     #define TWS_TRACE_DEBUG_ON on
59 #endif
60 
61 #ifdef TWS_TRACE_DEBUG_ON
62     #define __tws_debug
63     #define TWS_TRACE_DEBUG(sc, desc, val1, val2) \
64             tws_trace(__FILE__, __func__, __LINE__, sc, desc, \
65                                    (u_int64_t)val1, (u_int64_t)val2)
66 #else
67     #define __tws_debug __unused
68     #define TWS_TRACE_DEBUG(sc, desc, val1, val2)
69 #endif
70 
71 #ifdef TWS_TRACE_ON
72     #define TWS_TRACE(sc, desc, val1, val2) \
73             tws_trace(__FILE__, __func__, __LINE__, sc, desc, \
74                                    (u_int64_t)val1, (u_int64_t)val2)
75 #else
76     #define TWS_TRACE(sc, desc, val1, val2)
77 #endif
78 
79 /* ---------------- logging ---------------- */
80 
81 /* ---------------- logging ---------------- */
82 enum error_index {
83     SYSCTL_TREE_NODE_ADD,
84     PCI_COMMAND_READ,
85     ALLOC_MEMORY_RES,
86     ALLOC_IRQ_RES,
87     SETUP_INTR_RES,
88     TWS_CAM_ATTACH,
89     CAM_SIMQ_ALLOC,
90     CAM_SIM_ALLOC,
91     TWS_XPT_BUS_REGISTER,
92     TWS_XPT_CREATE_PATH,
93     TWS_BUS_SCAN_REQ,
94     TWS_INIT_FAILURE,
95     TWS_CTLR_INIT_FAILURE,
96 };
97 
98 enum severity {
99     ERROR = 1,
100     WARNING,
101     INFO,
102 #if 0
103     DEBUG,
104 #endif
105 };
106 
107 struct error_desc {
108     char desc[256];
109     u_int32_t error_code;
110     int severity_level;
111     char *fmt;
112     char *error_str;
113 };
114 
115 /* ----------- q services ------------- */
116 
117 #define TWS_FREE_Q        0
118 #define TWS_PENDING_Q     1
119 #define TWS_BUSY_Q        2
120 #define TWS_COMPLETE_Q    3
121 
122 /* req return codes */
123 #define TWS_REQ_RET_SUBMIT_SUCCESS 0
124 #define TWS_REQ_RET_PEND_NOMFA     1
125 #define TWS_REQ_RET_RESET          2
126 #define TWS_REQ_RET_INVALID   0xdead
127 
128 /* ------------------------ */
129 #include <sys/clock.h>
130 #define TWS_LOCAL_TIME (time_second - utc_offset())
131