xref: /freebsd/sys/dev/liquidio/base/lio_response_manager.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Cavium, Inc.. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Cavium, Inc. nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * ! \file lio_response_manager.h
36  *  \brief Host Driver:  Response queues for host instructions.
37  */
38 
39 #ifndef __LIO_RESPONSE_MANAGER_H__
40 #define __LIO_RESPONSE_MANAGER_H__
41 
42 /*
43  * Maximum ordered requests to process in every invocation of
44  * lio_process_ordered_list(). The function will continue to process requests
45  * as long as it can find one that has finished processing. If it keeps
46  * finding requests that have completed, the function can run for ever. The
47  * value defined here sets an upper limit on the number of requests it can
48  * process before it returns control to the poll thread.
49  */
50 #define LIO_MAX_ORD_REQS_TO_PROCESS   4096
51 
52 /*
53  * Head of a response list. There are several response lists in the
54  * system. One for each response order- Unordered, ordered
55  * and 1 for noresponse entries on each instruction queue.
56  */
57 
58 struct lio_response_list {
59 	/* List structure to add delete pending entries to */
60 	struct lio_stailq_head	head;
61 
62 	/* A lock for this response list */
63 	struct mtx		lock;
64 
65 	volatile int		pending_req_count;
66 };
67 
68 /* The type of response list. */
69 enum {
70 	LIO_ORDERED_LIST		= 0,
71 	LIO_UNORDERED_NONBLOCKING_LIST	= 1,
72 	LIO_UNORDERED_BLOCKING_LIST	= 2,
73 	LIO_ORDERED_SC_LIST		= 3
74 };
75 
76 /*
77  * Error codes  used in Octeon Host-Core communication.
78  *
79  *   31            16 15            0
80  *   ---------------------------------
81  *   |               |               |
82  *   ---------------------------------
83  *   Error codes are 32-bit wide. The upper 16-bits, called Major Error Number,
84  *   are reserved to identify the group to which the error code belongs. The
85  *   lower 16-bits, called Minor Error Number, carry the actual code.
86  *
87  *   So error codes are (MAJOR NUMBER << 16)| MINOR_NUMBER.
88  */
89 
90 /*------   Error codes used by firmware (bits 15..0 set by firmware */
91 #define LIO_FW_MAJOR_ERROR_CODE         0x0001
92 
93 /* A value of 0x00000000 indicates no error i.e. success */
94 #define LIO_DRIVER_ERROR_NONE                 0x00000000
95 
96 #define LIO_DRIVER_ERROR_REQ_PENDING          0x00000001
97 #define LIO_DRIVER_ERROR_REQ_TIMEOUT          0x00000003
98 #define LIO_DRIVER_ERROR_REQ_EINTR            0x00000004
99 
100 /*
101  * Status for a request.
102  * If a request is not queued to Octeon by the driver, the driver returns
103  * an error condition that's describe by one of the OCTEON_REQ_ERR_* value
104  * below. If the request is successfully queued, the driver will return
105  * a LIO_REQUEST_PENDING status. LIO_REQUEST_TIMEOUT and
106  * LIO_REQUEST_INTERRUPTED are only returned by the driver if the
107  * response for request failed to arrive before a time-out period or if
108  * the request processing * got interrupted due to a signal respectively.
109  */
110 enum {
111 	LIO_REQUEST_DONE	= (LIO_DRIVER_ERROR_NONE),
112 	LIO_REQUEST_PENDING	= (LIO_DRIVER_ERROR_REQ_PENDING),
113 	LIO_REQUEST_TIMEOUT	= (LIO_DRIVER_ERROR_REQ_TIMEOUT),
114 	LIO_REQUEST_INTERRUPTED	= (LIO_DRIVER_ERROR_REQ_EINTR),
115 	LIO_REQUEST_NO_DEVICE	= (0x00000021),
116 	LIO_REQUEST_NOT_RUNNING,
117 	LIO_REQUEST_INVALID_IQ,
118 	LIO_REQUEST_INVALID_BUFCNT,
119 	LIO_REQUEST_INVALID_RESP_ORDER,
120 	LIO_REQUEST_NO_MEMORY,
121 	LIO_REQUEST_INVALID_BUFSIZE,
122 	LIO_REQUEST_NO_PENDING_ENTRY,
123 	LIO_REQUEST_NO_IQ_SPACE	= (0x7FFFFFFF)
124 };
125 
126 #define LIO_STAILQ_FIRST_ENTRY(ptr, type, elem)	\
127 		(type *)((char *)((ptr)->stqh_first) - offsetof(type, elem))
128 
129 #define LIO_FW_STATUS_CODE(status)		\
130 		((LIO_FW_MAJOR_ERROR_CODE << 16) | (status))
131 
132 /*
133  * Initialize the response lists. The number of response lists to create is
134  * given by count.
135  * @param octeon_dev      - the octeon device structure.
136  */
137 int	lio_setup_response_list(struct octeon_device *octeon_dev);
138 void	lio_delete_response_list(struct octeon_device *octeon_dev);
139 
140 /*
141  * Check the status of first entry in the ordered list. If the instruction at
142  * that entry finished processing or has timed-out, the entry is cleaned.
143  * @param octeon_dev  - the octeon device structure.
144  * @param force_quit - the request is forced to timeout if this is 1
145  * @return 1 if the ordered list is empty, 0 otherwise.
146  */
147 int	lio_process_ordered_list(struct octeon_device *octeon_dev,
148 				 uint32_t force_quit);
149 
150 #endif	/* __LIO_RESPONSE_MANAGER_H__ */
151