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/*$FreeBSD: stable/11/sys/dev/liquidio/base/lio_response_manager.h 325618 2017-11-09 19:52:56Z sbruno $*/
34
35/*
36 * ! \file lio_response_manager.h
37 *  \brief Host Driver:  Response queues for host instructions.
38 */
39
40#ifndef __LIO_RESPONSE_MANAGER_H__
41#define __LIO_RESPONSE_MANAGER_H__
42
43/*
44 * Maximum ordered requests to process in every invocation of
45 * lio_process_ordered_list(). The function will continue to process requests
46 * as long as it can find one that has finished processing. If it keeps
47 * finding requests that have completed, the function can run for ever. The
48 * value defined here sets an upper limit on the number of requests it can
49 * process before it returns control to the poll thread.
50 */
51#define LIO_MAX_ORD_REQS_TO_PROCESS   4096
52
53/*
54 * Head of a response list. There are several response lists in the
55 * system. One for each response order- Unordered, ordered
56 * and 1 for noresponse entries on each instruction queue.
57 */
58
59struct lio_response_list {
60	/* List structure to add delete pending entries to */
61	struct lio_stailq_head	head;
62
63	/* A lock for this response list */
64	struct mtx		lock;
65
66	volatile int		pending_req_count;
67};
68
69/* The type of response list. */
70enum {
71	LIO_ORDERED_LIST		= 0,
72	LIO_UNORDERED_NONBLOCKING_LIST	= 1,
73	LIO_UNORDERED_BLOCKING_LIST	= 2,
74	LIO_ORDERED_SC_LIST		= 3
75};
76
77/*
78 * Error codes  used in Octeon Host-Core communication.
79 *
80 *   31            16 15            0
81 *   ---------------------------------
82 *   |               |               |
83 *   ---------------------------------
84 *   Error codes are 32-bit wide. The upper 16-bits, called Major Error Number,
85 *   are reserved to identify the group to which the error code belongs. The
86 *   lower 16-bits, called Minor Error Number, carry the actual code.
87 *
88 *   So error codes are (MAJOR NUMBER << 16)| MINOR_NUMBER.
89 */
90
91/*------   Error codes used by firmware (bits 15..0 set by firmware */
92#define LIO_FW_MAJOR_ERROR_CODE         0x0001
93
94/* A value of 0x00000000 indicates no error i.e. success */
95#define LIO_DRIVER_ERROR_NONE                 0x00000000
96
97#define LIO_DRIVER_ERROR_REQ_PENDING          0x00000001
98#define LIO_DRIVER_ERROR_REQ_TIMEOUT          0x00000003
99#define LIO_DRIVER_ERROR_REQ_EINTR            0x00000004
100
101/*
102 * Status for a request.
103 * If a request is not queued to Octeon by the driver, the driver returns
104 * an error condition that's describe by one of the OCTEON_REQ_ERR_* value
105 * below. If the request is successfully queued, the driver will return
106 * a LIO_REQUEST_PENDING status. LIO_REQUEST_TIMEOUT and
107 * LIO_REQUEST_INTERRUPTED are only returned by the driver if the
108 * response for request failed to arrive before a time-out period or if
109 * the request processing * got interrupted due to a signal respectively.
110 */
111enum {
112	LIO_REQUEST_DONE	= (LIO_DRIVER_ERROR_NONE),
113	LIO_REQUEST_PENDING	= (LIO_DRIVER_ERROR_REQ_PENDING),
114	LIO_REQUEST_TIMEOUT	= (LIO_DRIVER_ERROR_REQ_TIMEOUT),
115	LIO_REQUEST_INTERRUPTED	= (LIO_DRIVER_ERROR_REQ_EINTR),
116	LIO_REQUEST_NO_DEVICE	= (0x00000021),
117	LIO_REQUEST_NOT_RUNNING,
118	LIO_REQUEST_INVALID_IQ,
119	LIO_REQUEST_INVALID_BUFCNT,
120	LIO_REQUEST_INVALID_RESP_ORDER,
121	LIO_REQUEST_NO_MEMORY,
122	LIO_REQUEST_INVALID_BUFSIZE,
123	LIO_REQUEST_NO_PENDING_ENTRY,
124	LIO_REQUEST_NO_IQ_SPACE	= (0x7FFFFFFF)
125};
126
127#define LIO_STAILQ_FIRST_ENTRY(ptr, type, elem)	\
128		(type *)((char *)((ptr)->stqh_first) - offsetof(type, elem))
129
130#define LIO_FW_STATUS_CODE(status)		\
131		((LIO_FW_MAJOR_ERROR_CODE << 16) | (status))
132
133/*
134 * Initialize the response lists. The number of response lists to create is
135 * given by count.
136 * @param octeon_dev      - the octeon device structure.
137 */
138int	lio_setup_response_list(struct octeon_device *octeon_dev);
139void	lio_delete_response_list(struct octeon_device *octeon_dev);
140
141/*
142 * Check the status of first entry in the ordered list. If the instruction at
143 * that entry finished processing or has timed-out, the entry is cleaned.
144 * @param octeon_dev  - the octeon device structure.
145 * @param force_quit - the request is forced to timeout if this is 1
146 * @return 1 if the ordered list is empty, 0 otherwise.
147 */
148int	lio_process_ordered_list(struct octeon_device *octeon_dev,
149				 uint32_t force_quit);
150
151#endif	/* __LIO_RESPONSE_MANAGER_H__ */
152