18c2ecf20Sopenharmony_ci/**********************************************************************
28c2ecf20Sopenharmony_ci * Author: Cavium, Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Contact: support@cavium.com
58c2ecf20Sopenharmony_ci *          Please include "LiquidIO" in the subject.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (c) 2003-2016 Cavium, Inc.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * This file is free software; you can redistribute it and/or modify
108c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as
118c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * This file is distributed in the hope that it will be useful, but
148c2ecf20Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
158c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
168c2ecf20Sopenharmony_ci * NONINFRINGEMENT.  See the GNU General Public License for more
178c2ecf20Sopenharmony_ci * details.
188c2ecf20Sopenharmony_ci **********************************************************************/
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/*! \file response_manager.h
218c2ecf20Sopenharmony_ci *  \brief Host Driver:  Response queues for host instructions.
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#ifndef __RESPONSE_MANAGER_H__
258c2ecf20Sopenharmony_ci#define __RESPONSE_MANAGER_H__
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/** Maximum ordered requests to process in every invocation of
288c2ecf20Sopenharmony_ci * lio_process_ordered_list(). The function will continue to process requests
298c2ecf20Sopenharmony_ci * as long as it can find one that has finished processing. If it keeps
308c2ecf20Sopenharmony_ci * finding requests that have completed, the function can run for ever. The
318c2ecf20Sopenharmony_ci * value defined here sets an upper limit on the number of requests it can
328c2ecf20Sopenharmony_ci * process before it returns control to the poll thread.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci#define  MAX_ORD_REQS_TO_PROCESS   4096
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/** Head of a response list. There are several response lists in the
378c2ecf20Sopenharmony_ci *  system. One for each response order- Unordered, ordered
388c2ecf20Sopenharmony_ci *  and 1 for noresponse entries on each instruction queue.
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_cistruct octeon_response_list {
418c2ecf20Sopenharmony_ci	/** List structure to add delete pending entries to */
428c2ecf20Sopenharmony_ci	struct list_head head;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	/** A lock for this response list */
458c2ecf20Sopenharmony_ci	spinlock_t lock;
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	atomic_t pending_req_count;
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/** The type of response list.
518c2ecf20Sopenharmony_ci */
528c2ecf20Sopenharmony_cienum {
538c2ecf20Sopenharmony_ci	OCTEON_ORDERED_LIST = 0,
548c2ecf20Sopenharmony_ci	OCTEON_UNORDERED_NONBLOCKING_LIST = 1,
558c2ecf20Sopenharmony_ci	OCTEON_UNORDERED_BLOCKING_LIST = 2,
568c2ecf20Sopenharmony_ci	OCTEON_ORDERED_SC_LIST = 3,
578c2ecf20Sopenharmony_ci	OCTEON_DONE_SC_LIST = 4,
588c2ecf20Sopenharmony_ci	OCTEON_ZOMBIE_SC_LIST = 5
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci/** Response Order values for a Octeon Request. */
628c2ecf20Sopenharmony_cienum {
638c2ecf20Sopenharmony_ci	OCTEON_RESP_ORDERED = 0,
648c2ecf20Sopenharmony_ci	OCTEON_RESP_UNORDERED = 1,
658c2ecf20Sopenharmony_ci	OCTEON_RESP_NORESPONSE = 2
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/** Error codes  used in Octeon Host-Core communication.
698c2ecf20Sopenharmony_ci *
708c2ecf20Sopenharmony_ci *   31            16 15            0
718c2ecf20Sopenharmony_ci *   ---------------------------------
728c2ecf20Sopenharmony_ci *   |               |               |
738c2ecf20Sopenharmony_ci *   ---------------------------------
748c2ecf20Sopenharmony_ci *   Error codes are 32-bit wide. The upper 16-bits, called Major Error Number,
758c2ecf20Sopenharmony_ci *   are reserved to identify the group to which the error code belongs. The
768c2ecf20Sopenharmony_ci *   lower 16-bits, called Minor Error Number, carry the actual code.
778c2ecf20Sopenharmony_ci *
788c2ecf20Sopenharmony_ci *   So error codes are (MAJOR NUMBER << 16)| MINOR_NUMBER.
798c2ecf20Sopenharmony_ci */
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/*------------   Error codes used by host driver   -----------------*/
828c2ecf20Sopenharmony_ci#define DRIVER_MAJOR_ERROR_CODE           0x0000
838c2ecf20Sopenharmony_ci/*------   Error codes used by firmware (bits 15..0 set by firmware */
848c2ecf20Sopenharmony_ci#define FIRMWARE_MAJOR_ERROR_CODE         0x0001
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci/**  A value of 0x00000000 indicates no error i.e. success */
878c2ecf20Sopenharmony_ci#define DRIVER_ERROR_NONE                 0x00000000
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define DRIVER_ERROR_REQ_PENDING          0x00000001
908c2ecf20Sopenharmony_ci#define DRIVER_ERROR_REQ_TIMEOUT          0x00000003
918c2ecf20Sopenharmony_ci#define DRIVER_ERROR_REQ_EINTR            0x00000004
928c2ecf20Sopenharmony_ci#define DRIVER_ERROR_REQ_ENXIO            0x00000006
938c2ecf20Sopenharmony_ci#define DRIVER_ERROR_REQ_ENOMEM           0x0000000C
948c2ecf20Sopenharmony_ci#define DRIVER_ERROR_REQ_EINVAL           0x00000016
958c2ecf20Sopenharmony_ci#define DRIVER_ERROR_REQ_FAILED           0x000000ff
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/** Status for a request.
988c2ecf20Sopenharmony_ci * If a request is not queued to Octeon by the driver, the driver returns
998c2ecf20Sopenharmony_ci * an error condition that's describe by one of the OCTEON_REQ_ERR_* value
1008c2ecf20Sopenharmony_ci * below. If the request is successfully queued, the driver will return
1018c2ecf20Sopenharmony_ci * a OCTEON_REQUEST_PENDING status. OCTEON_REQUEST_TIMEOUT and
1028c2ecf20Sopenharmony_ci * OCTEON_REQUEST_INTERRUPTED are only returned by the driver if the
1038c2ecf20Sopenharmony_ci * response for request failed to arrive before a time-out period or if
1048c2ecf20Sopenharmony_ci * the request processing * got interrupted due to a signal respectively.
1058c2ecf20Sopenharmony_ci */
1068c2ecf20Sopenharmony_cienum {
1078c2ecf20Sopenharmony_ci	OCTEON_REQUEST_DONE = (DRIVER_ERROR_NONE),
1088c2ecf20Sopenharmony_ci	OCTEON_REQUEST_PENDING = (DRIVER_ERROR_REQ_PENDING),
1098c2ecf20Sopenharmony_ci	OCTEON_REQUEST_TIMEOUT = (DRIVER_ERROR_REQ_TIMEOUT),
1108c2ecf20Sopenharmony_ci	OCTEON_REQUEST_INTERRUPTED = (DRIVER_ERROR_REQ_EINTR),
1118c2ecf20Sopenharmony_ci	OCTEON_REQUEST_NO_DEVICE = (0x00000021),
1128c2ecf20Sopenharmony_ci	OCTEON_REQUEST_NOT_RUNNING,
1138c2ecf20Sopenharmony_ci	OCTEON_REQUEST_INVALID_IQ,
1148c2ecf20Sopenharmony_ci	OCTEON_REQUEST_INVALID_BUFCNT,
1158c2ecf20Sopenharmony_ci	OCTEON_REQUEST_INVALID_RESP_ORDER,
1168c2ecf20Sopenharmony_ci	OCTEON_REQUEST_NO_MEMORY,
1178c2ecf20Sopenharmony_ci	OCTEON_REQUEST_INVALID_BUFSIZE,
1188c2ecf20Sopenharmony_ci	OCTEON_REQUEST_NO_PENDING_ENTRY,
1198c2ecf20Sopenharmony_ci	OCTEON_REQUEST_NO_IQ_SPACE = (0x7FFFFFFF)
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci};
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define FIRMWARE_STATUS_CODE(status) \
1248c2ecf20Sopenharmony_ci	((FIRMWARE_MAJOR_ERROR_CODE << 16) | (status))
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci/** Initialize the response lists. The number of response lists to create is
1278c2ecf20Sopenharmony_ci * given by count.
1288c2ecf20Sopenharmony_ci * @param octeon_dev      - the octeon device structure.
1298c2ecf20Sopenharmony_ci */
1308c2ecf20Sopenharmony_ciint octeon_setup_response_list(struct octeon_device *octeon_dev);
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_civoid octeon_delete_response_list(struct octeon_device *octeon_dev);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci/** Check the status of first entry in the ordered list. If the instruction at
1358c2ecf20Sopenharmony_ci * that entry finished processing or has timed-out, the entry is cleaned.
1368c2ecf20Sopenharmony_ci * @param octeon_dev  - the octeon device structure.
1378c2ecf20Sopenharmony_ci * @param force_quit - the request is forced to timeout if this is 1
1388c2ecf20Sopenharmony_ci * @return 1 if the ordered list is empty, 0 otherwise.
1398c2ecf20Sopenharmony_ci */
1408c2ecf20Sopenharmony_ciint lio_process_ordered_list(struct octeon_device *octeon_dev,
1418c2ecf20Sopenharmony_ci			     u32 force_quit);
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci#endif
144