1325618Ssbruno/*
2325618Ssbruno *   BSD LICENSE
3325618Ssbruno *
4325618Ssbruno *   Copyright(c) 2017 Cavium, Inc.. All rights reserved.
5325618Ssbruno *   All rights reserved.
6325618Ssbruno *
7325618Ssbruno *   Redistribution and use in source and binary forms, with or without
8325618Ssbruno *   modification, are permitted provided that the following conditions
9325618Ssbruno *   are met:
10325618Ssbruno *
11325618Ssbruno *     * Redistributions of source code must retain the above copyright
12325618Ssbruno *       notice, this list of conditions and the following disclaimer.
13325618Ssbruno *     * Redistributions in binary form must reproduce the above copyright
14325618Ssbruno *       notice, this list of conditions and the following disclaimer in
15325618Ssbruno *       the documentation and/or other materials provided with the
16325618Ssbruno *       distribution.
17325618Ssbruno *     * Neither the name of Cavium, Inc. nor the names of its
18325618Ssbruno *       contributors may be used to endorse or promote products derived
19325618Ssbruno *       from this software without specific prior written permission.
20325618Ssbruno *
21325618Ssbruno *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22325618Ssbruno *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23325618Ssbruno *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24325618Ssbruno *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25325618Ssbruno *   OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26325618Ssbruno *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27325618Ssbruno *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28325618Ssbruno *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29325618Ssbruno *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30325618Ssbruno *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31325618Ssbruno *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32325618Ssbruno */
33325618Ssbruno/*$FreeBSD: stable/11/sys/dev/liquidio/base/lio_response_manager.h 325618 2017-11-09 19:52:56Z sbruno $*/
34325618Ssbruno
35325618Ssbruno/*
36325618Ssbruno * ! \file lio_response_manager.h
37325618Ssbruno *  \brief Host Driver:  Response queues for host instructions.
38325618Ssbruno */
39325618Ssbruno
40325618Ssbruno#ifndef __LIO_RESPONSE_MANAGER_H__
41325618Ssbruno#define __LIO_RESPONSE_MANAGER_H__
42325618Ssbruno
43325618Ssbruno/*
44325618Ssbruno * Maximum ordered requests to process in every invocation of
45325618Ssbruno * lio_process_ordered_list(). The function will continue to process requests
46325618Ssbruno * as long as it can find one that has finished processing. If it keeps
47325618Ssbruno * finding requests that have completed, the function can run for ever. The
48325618Ssbruno * value defined here sets an upper limit on the number of requests it can
49325618Ssbruno * process before it returns control to the poll thread.
50325618Ssbruno */
51325618Ssbruno#define LIO_MAX_ORD_REQS_TO_PROCESS   4096
52325618Ssbruno
53325618Ssbruno/*
54325618Ssbruno * Head of a response list. There are several response lists in the
55325618Ssbruno * system. One for each response order- Unordered, ordered
56325618Ssbruno * and 1 for noresponse entries on each instruction queue.
57325618Ssbruno */
58325618Ssbruno
59325618Ssbrunostruct lio_response_list {
60325618Ssbruno	/* List structure to add delete pending entries to */
61325618Ssbruno	struct lio_stailq_head	head;
62325618Ssbruno
63325618Ssbruno	/* A lock for this response list */
64325618Ssbruno	struct mtx		lock;
65325618Ssbruno
66325618Ssbruno	volatile int		pending_req_count;
67325618Ssbruno};
68325618Ssbruno
69325618Ssbruno/* The type of response list. */
70325618Ssbrunoenum {
71325618Ssbruno	LIO_ORDERED_LIST		= 0,
72325618Ssbruno	LIO_UNORDERED_NONBLOCKING_LIST	= 1,
73325618Ssbruno	LIO_UNORDERED_BLOCKING_LIST	= 2,
74325618Ssbruno	LIO_ORDERED_SC_LIST		= 3
75325618Ssbruno};
76325618Ssbruno
77325618Ssbruno/*
78325618Ssbruno * Error codes  used in Octeon Host-Core communication.
79325618Ssbruno *
80325618Ssbruno *   31            16 15            0
81325618Ssbruno *   ---------------------------------
82325618Ssbruno *   |               |               |
83325618Ssbruno *   ---------------------------------
84325618Ssbruno *   Error codes are 32-bit wide. The upper 16-bits, called Major Error Number,
85325618Ssbruno *   are reserved to identify the group to which the error code belongs. The
86325618Ssbruno *   lower 16-bits, called Minor Error Number, carry the actual code.
87325618Ssbruno *
88325618Ssbruno *   So error codes are (MAJOR NUMBER << 16)| MINOR_NUMBER.
89325618Ssbruno */
90325618Ssbruno
91325618Ssbruno/*------   Error codes used by firmware (bits 15..0 set by firmware */
92325618Ssbruno#define LIO_FW_MAJOR_ERROR_CODE         0x0001
93325618Ssbruno
94325618Ssbruno/* A value of 0x00000000 indicates no error i.e. success */
95325618Ssbruno#define LIO_DRIVER_ERROR_NONE                 0x00000000
96325618Ssbruno
97325618Ssbruno#define LIO_DRIVER_ERROR_REQ_PENDING          0x00000001
98325618Ssbruno#define LIO_DRIVER_ERROR_REQ_TIMEOUT          0x00000003
99325618Ssbruno#define LIO_DRIVER_ERROR_REQ_EINTR            0x00000004
100325618Ssbruno
101325618Ssbruno/*
102325618Ssbruno * Status for a request.
103325618Ssbruno * If a request is not queued to Octeon by the driver, the driver returns
104325618Ssbruno * an error condition that's describe by one of the OCTEON_REQ_ERR_* value
105325618Ssbruno * below. If the request is successfully queued, the driver will return
106325618Ssbruno * a LIO_REQUEST_PENDING status. LIO_REQUEST_TIMEOUT and
107325618Ssbruno * LIO_REQUEST_INTERRUPTED are only returned by the driver if the
108325618Ssbruno * response for request failed to arrive before a time-out period or if
109325618Ssbruno * the request processing * got interrupted due to a signal respectively.
110325618Ssbruno */
111325618Ssbrunoenum {
112325618Ssbruno	LIO_REQUEST_DONE	= (LIO_DRIVER_ERROR_NONE),
113325618Ssbruno	LIO_REQUEST_PENDING	= (LIO_DRIVER_ERROR_REQ_PENDING),
114325618Ssbruno	LIO_REQUEST_TIMEOUT	= (LIO_DRIVER_ERROR_REQ_TIMEOUT),
115325618Ssbruno	LIO_REQUEST_INTERRUPTED	= (LIO_DRIVER_ERROR_REQ_EINTR),
116325618Ssbruno	LIO_REQUEST_NO_DEVICE	= (0x00000021),
117325618Ssbruno	LIO_REQUEST_NOT_RUNNING,
118325618Ssbruno	LIO_REQUEST_INVALID_IQ,
119325618Ssbruno	LIO_REQUEST_INVALID_BUFCNT,
120325618Ssbruno	LIO_REQUEST_INVALID_RESP_ORDER,
121325618Ssbruno	LIO_REQUEST_NO_MEMORY,
122325618Ssbruno	LIO_REQUEST_INVALID_BUFSIZE,
123325618Ssbruno	LIO_REQUEST_NO_PENDING_ENTRY,
124325618Ssbruno	LIO_REQUEST_NO_IQ_SPACE	= (0x7FFFFFFF)
125325618Ssbruno};
126325618Ssbruno
127325618Ssbruno#define LIO_STAILQ_FIRST_ENTRY(ptr, type, elem)	\
128325618Ssbruno		(type *)((char *)((ptr)->stqh_first) - offsetof(type, elem))
129325618Ssbruno
130325618Ssbruno#define LIO_FW_STATUS_CODE(status)		\
131325618Ssbruno		((LIO_FW_MAJOR_ERROR_CODE << 16) | (status))
132325618Ssbruno
133325618Ssbruno/*
134325618Ssbruno * Initialize the response lists. The number of response lists to create is
135325618Ssbruno * given by count.
136325618Ssbruno * @param octeon_dev      - the octeon device structure.
137325618Ssbruno */
138325618Ssbrunoint	lio_setup_response_list(struct octeon_device *octeon_dev);
139325618Ssbrunovoid	lio_delete_response_list(struct octeon_device *octeon_dev);
140325618Ssbruno
141325618Ssbruno/*
142325618Ssbruno * Check the status of first entry in the ordered list. If the instruction at
143325618Ssbruno * that entry finished processing or has timed-out, the entry is cleaned.
144325618Ssbruno * @param octeon_dev  - the octeon device structure.
145325618Ssbruno * @param force_quit - the request is forced to timeout if this is 1
146325618Ssbruno * @return 1 if the ordered list is empty, 0 otherwise.
147325618Ssbruno */
148325618Ssbrunoint	lio_process_ordered_list(struct octeon_device *octeon_dev,
149325618Ssbruno				 uint32_t force_quit);
150325618Ssbruno
151325618Ssbruno#endif	/* __LIO_RESPONSE_MANAGER_H__ */
152