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