xref: /openbmc/linux/drivers/net/ethernet/cavium/liquidio/response_manager.h (revision 3eb66e91a25497065c5322b1268cbc3953642227)
1f21fb3edSRaghu Vatsavayi /**********************************************************************
2f21fb3edSRaghu Vatsavayi  * Author: Cavium, Inc.
3f21fb3edSRaghu Vatsavayi  *
4f21fb3edSRaghu Vatsavayi  * Contact: support@cavium.com
5f21fb3edSRaghu Vatsavayi  *          Please include "LiquidIO" in the subject.
6f21fb3edSRaghu Vatsavayi  *
750579d3dSRaghu Vatsavayi  * Copyright (c) 2003-2016 Cavium, Inc.
8f21fb3edSRaghu Vatsavayi  *
9f21fb3edSRaghu Vatsavayi  * This file is free software; you can redistribute it and/or modify
10f21fb3edSRaghu Vatsavayi  * it under the terms of the GNU General Public License, Version 2, as
11f21fb3edSRaghu Vatsavayi  * published by the Free Software Foundation.
12f21fb3edSRaghu Vatsavayi  *
13f21fb3edSRaghu Vatsavayi  * This file is distributed in the hope that it will be useful, but
14f21fb3edSRaghu Vatsavayi  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15f21fb3edSRaghu Vatsavayi  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16f21fb3edSRaghu Vatsavayi  * NONINFRINGEMENT.  See the GNU General Public License for more
17f21fb3edSRaghu Vatsavayi  * details.
18f21fb3edSRaghu Vatsavayi  **********************************************************************/
19f21fb3edSRaghu Vatsavayi 
20f21fb3edSRaghu Vatsavayi /*! \file response_manager.h
21f21fb3edSRaghu Vatsavayi  *  \brief Host Driver:  Response queues for host instructions.
22f21fb3edSRaghu Vatsavayi  */
23f21fb3edSRaghu Vatsavayi 
24f21fb3edSRaghu Vatsavayi #ifndef __RESPONSE_MANAGER_H__
25f21fb3edSRaghu Vatsavayi #define __RESPONSE_MANAGER_H__
26f21fb3edSRaghu Vatsavayi 
27f21fb3edSRaghu Vatsavayi /** Maximum ordered requests to process in every invocation of
28f21fb3edSRaghu Vatsavayi  * lio_process_ordered_list(). The function will continue to process requests
29f21fb3edSRaghu Vatsavayi  * as long as it can find one that has finished processing. If it keeps
30f21fb3edSRaghu Vatsavayi  * finding requests that have completed, the function can run for ever. The
31f21fb3edSRaghu Vatsavayi  * value defined here sets an upper limit on the number of requests it can
32f21fb3edSRaghu Vatsavayi  * process before it returns control to the poll thread.
33f21fb3edSRaghu Vatsavayi  */
34f21fb3edSRaghu Vatsavayi #define  MAX_ORD_REQS_TO_PROCESS   4096
35f21fb3edSRaghu Vatsavayi 
36f21fb3edSRaghu Vatsavayi /** Head of a response list. There are several response lists in the
37f21fb3edSRaghu Vatsavayi  *  system. One for each response order- Unordered, ordered
38f21fb3edSRaghu Vatsavayi  *  and 1 for noresponse entries on each instruction queue.
39f21fb3edSRaghu Vatsavayi  */
40f21fb3edSRaghu Vatsavayi struct octeon_response_list {
41f21fb3edSRaghu Vatsavayi 	/** List structure to add delete pending entries to */
42f21fb3edSRaghu Vatsavayi 	struct list_head head;
43f21fb3edSRaghu Vatsavayi 
44f21fb3edSRaghu Vatsavayi 	/** A lock for this response list */
45f21fb3edSRaghu Vatsavayi 	spinlock_t lock;
46f21fb3edSRaghu Vatsavayi 
47f21fb3edSRaghu Vatsavayi 	atomic_t pending_req_count;
48f21fb3edSRaghu Vatsavayi };
49f21fb3edSRaghu Vatsavayi 
50f21fb3edSRaghu Vatsavayi /** The type of response list.
51f21fb3edSRaghu Vatsavayi  */
52f21fb3edSRaghu Vatsavayi enum {
53f21fb3edSRaghu Vatsavayi 	OCTEON_ORDERED_LIST = 0,
54f21fb3edSRaghu Vatsavayi 	OCTEON_UNORDERED_NONBLOCKING_LIST = 1,
55f21fb3edSRaghu Vatsavayi 	OCTEON_UNORDERED_BLOCKING_LIST = 2,
56*c9aec052SFelix Manlunas 	OCTEON_ORDERED_SC_LIST = 3,
57*c9aec052SFelix Manlunas 	OCTEON_DONE_SC_LIST = 4,
58*c9aec052SFelix Manlunas 	OCTEON_ZOMBIE_SC_LIST = 5
59f21fb3edSRaghu Vatsavayi };
60f21fb3edSRaghu Vatsavayi 
61f21fb3edSRaghu Vatsavayi /** Response Order values for a Octeon Request. */
62f21fb3edSRaghu Vatsavayi enum {
63f21fb3edSRaghu Vatsavayi 	OCTEON_RESP_ORDERED = 0,
64f21fb3edSRaghu Vatsavayi 	OCTEON_RESP_UNORDERED = 1,
65f21fb3edSRaghu Vatsavayi 	OCTEON_RESP_NORESPONSE = 2
66f21fb3edSRaghu Vatsavayi };
67f21fb3edSRaghu Vatsavayi 
68f21fb3edSRaghu Vatsavayi /** Error codes  used in Octeon Host-Core communication.
69f21fb3edSRaghu Vatsavayi  *
70f21fb3edSRaghu Vatsavayi  *   31            16 15            0
71f21fb3edSRaghu Vatsavayi  *   ---------------------------------
72f21fb3edSRaghu Vatsavayi  *   |               |               |
73f21fb3edSRaghu Vatsavayi  *   ---------------------------------
74f21fb3edSRaghu Vatsavayi  *   Error codes are 32-bit wide. The upper 16-bits, called Major Error Number,
75f21fb3edSRaghu Vatsavayi  *   are reserved to identify the group to which the error code belongs. The
76f21fb3edSRaghu Vatsavayi  *   lower 16-bits, called Minor Error Number, carry the actual code.
77f21fb3edSRaghu Vatsavayi  *
78f21fb3edSRaghu Vatsavayi  *   So error codes are (MAJOR NUMBER << 16)| MINOR_NUMBER.
79f21fb3edSRaghu Vatsavayi  */
80f21fb3edSRaghu Vatsavayi 
81f21fb3edSRaghu Vatsavayi /*------------   Error codes used by host driver   -----------------*/
82f21fb3edSRaghu Vatsavayi #define DRIVER_MAJOR_ERROR_CODE           0x0000
839549c6c8SRick Farrington /*------   Error codes used by firmware (bits 15..0 set by firmware */
849549c6c8SRick Farrington #define FIRMWARE_MAJOR_ERROR_CODE         0x0001
85f21fb3edSRaghu Vatsavayi 
86f21fb3edSRaghu Vatsavayi /**  A value of 0x00000000 indicates no error i.e. success */
87f21fb3edSRaghu Vatsavayi #define DRIVER_ERROR_NONE                 0x00000000
88f21fb3edSRaghu Vatsavayi 
89f21fb3edSRaghu Vatsavayi #define DRIVER_ERROR_REQ_PENDING          0x00000001
90f21fb3edSRaghu Vatsavayi #define DRIVER_ERROR_REQ_TIMEOUT          0x00000003
91f21fb3edSRaghu Vatsavayi #define DRIVER_ERROR_REQ_EINTR            0x00000004
92f21fb3edSRaghu Vatsavayi #define DRIVER_ERROR_REQ_ENXIO            0x00000006
93f21fb3edSRaghu Vatsavayi #define DRIVER_ERROR_REQ_ENOMEM           0x0000000C
94f21fb3edSRaghu Vatsavayi #define DRIVER_ERROR_REQ_EINVAL           0x00000016
95f21fb3edSRaghu Vatsavayi #define DRIVER_ERROR_REQ_FAILED           0x000000ff
96f21fb3edSRaghu Vatsavayi 
97f21fb3edSRaghu Vatsavayi /** Status for a request.
98f21fb3edSRaghu Vatsavayi  * If a request is not queued to Octeon by the driver, the driver returns
99f21fb3edSRaghu Vatsavayi  * an error condition that's describe by one of the OCTEON_REQ_ERR_* value
100f21fb3edSRaghu Vatsavayi  * below. If the request is successfully queued, the driver will return
101f21fb3edSRaghu Vatsavayi  * a OCTEON_REQUEST_PENDING status. OCTEON_REQUEST_TIMEOUT and
102f21fb3edSRaghu Vatsavayi  * OCTEON_REQUEST_INTERRUPTED are only returned by the driver if the
103f21fb3edSRaghu Vatsavayi  * response for request failed to arrive before a time-out period or if
104f21fb3edSRaghu Vatsavayi  * the request processing * got interrupted due to a signal respectively.
105f21fb3edSRaghu Vatsavayi  */
106f21fb3edSRaghu Vatsavayi enum {
107f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_DONE = (DRIVER_ERROR_NONE),
108f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_PENDING = (DRIVER_ERROR_REQ_PENDING),
109f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_TIMEOUT = (DRIVER_ERROR_REQ_TIMEOUT),
110f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_INTERRUPTED = (DRIVER_ERROR_REQ_EINTR),
111f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_NO_DEVICE = (0x00000021),
112f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_NOT_RUNNING,
113f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_INVALID_IQ,
114f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_INVALID_BUFCNT,
115f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_INVALID_RESP_ORDER,
116f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_NO_MEMORY,
117f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_INVALID_BUFSIZE,
118f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_NO_PENDING_ENTRY,
119f21fb3edSRaghu Vatsavayi 	OCTEON_REQUEST_NO_IQ_SPACE = (0x7FFFFFFF)
120f21fb3edSRaghu Vatsavayi 
121f21fb3edSRaghu Vatsavayi };
122f21fb3edSRaghu Vatsavayi 
1239549c6c8SRick Farrington #define FIRMWARE_STATUS_CODE(status) \
1249549c6c8SRick Farrington 	((FIRMWARE_MAJOR_ERROR_CODE << 16) | (status))
1259549c6c8SRick Farrington 
126f21fb3edSRaghu Vatsavayi /** Initialize the response lists. The number of response lists to create is
127f21fb3edSRaghu Vatsavayi  * given by count.
128f21fb3edSRaghu Vatsavayi  * @param octeon_dev      - the octeon device structure.
129f21fb3edSRaghu Vatsavayi  */
130f21fb3edSRaghu Vatsavayi int octeon_setup_response_list(struct octeon_device *octeon_dev);
131f21fb3edSRaghu Vatsavayi 
132f21fb3edSRaghu Vatsavayi void octeon_delete_response_list(struct octeon_device *octeon_dev);
133f21fb3edSRaghu Vatsavayi 
134f21fb3edSRaghu Vatsavayi /** Check the status of first entry in the ordered list. If the instruction at
135f21fb3edSRaghu Vatsavayi  * that entry finished processing or has timed-out, the entry is cleaned.
136f21fb3edSRaghu Vatsavayi  * @param octeon_dev  - the octeon device structure.
137f21fb3edSRaghu Vatsavayi  * @param force_quit - the request is forced to timeout if this is 1
138f21fb3edSRaghu Vatsavayi  * @return 1 if the ordered list is empty, 0 otherwise.
139f21fb3edSRaghu Vatsavayi  */
140f21fb3edSRaghu Vatsavayi int lio_process_ordered_list(struct octeon_device *octeon_dev,
141f21fb3edSRaghu Vatsavayi 			     u32 force_quit);
142f21fb3edSRaghu Vatsavayi 
143f21fb3edSRaghu Vatsavayi #endif
144