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