162306a36Sopenharmony_ci/**********************************************************************
262306a36Sopenharmony_ci * Author: Cavium, Inc.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Contact: support@cavium.com
562306a36Sopenharmony_ci *          Please include "LiquidIO" in the subject.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (c) 2003-2016 Cavium, Inc.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * This file is free software; you can redistribute it and/or modify
1062306a36Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as
1162306a36Sopenharmony_ci * published by the Free Software Foundation.
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * This file is distributed in the hope that it will be useful, but
1462306a36Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
1562306a36Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
1662306a36Sopenharmony_ci * NONINFRINGEMENT.  See the GNU General Public License for more
1762306a36Sopenharmony_ci * details.
1862306a36Sopenharmony_ci **********************************************************************/
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/*! \file response_manager.h
2162306a36Sopenharmony_ci *  \brief Host Driver:  Response queues for host instructions.
2262306a36Sopenharmony_ci */
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#ifndef __RESPONSE_MANAGER_H__
2562306a36Sopenharmony_ci#define __RESPONSE_MANAGER_H__
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/** Maximum ordered requests to process in every invocation of
2862306a36Sopenharmony_ci * lio_process_ordered_list(). The function will continue to process requests
2962306a36Sopenharmony_ci * as long as it can find one that has finished processing. If it keeps
3062306a36Sopenharmony_ci * finding requests that have completed, the function can run for ever. The
3162306a36Sopenharmony_ci * value defined here sets an upper limit on the number of requests it can
3262306a36Sopenharmony_ci * process before it returns control to the poll thread.
3362306a36Sopenharmony_ci */
3462306a36Sopenharmony_ci#define  MAX_ORD_REQS_TO_PROCESS   4096
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci/** Head of a response list. There are several response lists in the
3762306a36Sopenharmony_ci *  system. One for each response order- Unordered, ordered
3862306a36Sopenharmony_ci *  and 1 for noresponse entries on each instruction queue.
3962306a36Sopenharmony_ci */
4062306a36Sopenharmony_cistruct octeon_response_list {
4162306a36Sopenharmony_ci	/** List structure to add delete pending entries to */
4262306a36Sopenharmony_ci	struct list_head head;
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci	/** A lock for this response list */
4562306a36Sopenharmony_ci	spinlock_t lock;
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci	atomic_t pending_req_count;
4862306a36Sopenharmony_ci};
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/** The type of response list.
5162306a36Sopenharmony_ci */
5262306a36Sopenharmony_cienum {
5362306a36Sopenharmony_ci	OCTEON_ORDERED_LIST = 0,
5462306a36Sopenharmony_ci	OCTEON_UNORDERED_NONBLOCKING_LIST = 1,
5562306a36Sopenharmony_ci	OCTEON_UNORDERED_BLOCKING_LIST = 2,
5662306a36Sopenharmony_ci	OCTEON_ORDERED_SC_LIST = 3,
5762306a36Sopenharmony_ci	OCTEON_DONE_SC_LIST = 4,
5862306a36Sopenharmony_ci	OCTEON_ZOMBIE_SC_LIST = 5
5962306a36Sopenharmony_ci};
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci/** Response Order values for a Octeon Request. */
6262306a36Sopenharmony_cienum {
6362306a36Sopenharmony_ci	OCTEON_RESP_ORDERED = 0,
6462306a36Sopenharmony_ci	OCTEON_RESP_UNORDERED = 1,
6562306a36Sopenharmony_ci	OCTEON_RESP_NORESPONSE = 2
6662306a36Sopenharmony_ci};
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/** Error codes  used in Octeon Host-Core communication.
6962306a36Sopenharmony_ci *
7062306a36Sopenharmony_ci *   31            16 15            0
7162306a36Sopenharmony_ci *   ---------------------------------
7262306a36Sopenharmony_ci *   |               |               |
7362306a36Sopenharmony_ci *   ---------------------------------
7462306a36Sopenharmony_ci *   Error codes are 32-bit wide. The upper 16-bits, called Major Error Number,
7562306a36Sopenharmony_ci *   are reserved to identify the group to which the error code belongs. The
7662306a36Sopenharmony_ci *   lower 16-bits, called Minor Error Number, carry the actual code.
7762306a36Sopenharmony_ci *
7862306a36Sopenharmony_ci *   So error codes are (MAJOR NUMBER << 16)| MINOR_NUMBER.
7962306a36Sopenharmony_ci */
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci/*------------   Error codes used by host driver   -----------------*/
8262306a36Sopenharmony_ci#define DRIVER_MAJOR_ERROR_CODE           0x0000
8362306a36Sopenharmony_ci/*------   Error codes used by firmware (bits 15..0 set by firmware */
8462306a36Sopenharmony_ci#define FIRMWARE_MAJOR_ERROR_CODE         0x0001
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci/**  A value of 0x00000000 indicates no error i.e. success */
8762306a36Sopenharmony_ci#define DRIVER_ERROR_NONE                 0x00000000
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#define DRIVER_ERROR_REQ_PENDING          0x00000001
9062306a36Sopenharmony_ci#define DRIVER_ERROR_REQ_TIMEOUT          0x00000003
9162306a36Sopenharmony_ci#define DRIVER_ERROR_REQ_EINTR            0x00000004
9262306a36Sopenharmony_ci#define DRIVER_ERROR_REQ_ENXIO            0x00000006
9362306a36Sopenharmony_ci#define DRIVER_ERROR_REQ_ENOMEM           0x0000000C
9462306a36Sopenharmony_ci#define DRIVER_ERROR_REQ_EINVAL           0x00000016
9562306a36Sopenharmony_ci#define DRIVER_ERROR_REQ_FAILED           0x000000ff
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci/** Status for a request.
9862306a36Sopenharmony_ci * If a request is not queued to Octeon by the driver, the driver returns
9962306a36Sopenharmony_ci * an error condition that's describe by one of the OCTEON_REQ_ERR_* value
10062306a36Sopenharmony_ci * below. If the request is successfully queued, the driver will return
10162306a36Sopenharmony_ci * a OCTEON_REQUEST_PENDING status. OCTEON_REQUEST_TIMEOUT and
10262306a36Sopenharmony_ci * OCTEON_REQUEST_INTERRUPTED are only returned by the driver if the
10362306a36Sopenharmony_ci * response for request failed to arrive before a time-out period or if
10462306a36Sopenharmony_ci * the request processing * got interrupted due to a signal respectively.
10562306a36Sopenharmony_ci */
10662306a36Sopenharmony_cienum {
10762306a36Sopenharmony_ci	OCTEON_REQUEST_DONE = (DRIVER_ERROR_NONE),
10862306a36Sopenharmony_ci	OCTEON_REQUEST_PENDING = (DRIVER_ERROR_REQ_PENDING),
10962306a36Sopenharmony_ci	OCTEON_REQUEST_TIMEOUT = (DRIVER_ERROR_REQ_TIMEOUT),
11062306a36Sopenharmony_ci	OCTEON_REQUEST_INTERRUPTED = (DRIVER_ERROR_REQ_EINTR),
11162306a36Sopenharmony_ci	OCTEON_REQUEST_NO_DEVICE = (0x00000021),
11262306a36Sopenharmony_ci	OCTEON_REQUEST_NOT_RUNNING,
11362306a36Sopenharmony_ci	OCTEON_REQUEST_INVALID_IQ,
11462306a36Sopenharmony_ci	OCTEON_REQUEST_INVALID_BUFCNT,
11562306a36Sopenharmony_ci	OCTEON_REQUEST_INVALID_RESP_ORDER,
11662306a36Sopenharmony_ci	OCTEON_REQUEST_NO_MEMORY,
11762306a36Sopenharmony_ci	OCTEON_REQUEST_INVALID_BUFSIZE,
11862306a36Sopenharmony_ci	OCTEON_REQUEST_NO_PENDING_ENTRY,
11962306a36Sopenharmony_ci	OCTEON_REQUEST_NO_IQ_SPACE = (0x7FFFFFFF)
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci};
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci#define FIRMWARE_STATUS_CODE(status) \
12462306a36Sopenharmony_ci	((FIRMWARE_MAJOR_ERROR_CODE << 16) | (status))
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci/** Initialize the response lists. The number of response lists to create is
12762306a36Sopenharmony_ci * given by count.
12862306a36Sopenharmony_ci * @param octeon_dev      - the octeon device structure.
12962306a36Sopenharmony_ci */
13062306a36Sopenharmony_ciint octeon_setup_response_list(struct octeon_device *octeon_dev);
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_civoid octeon_delete_response_list(struct octeon_device *octeon_dev);
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci/** Check the status of first entry in the ordered list. If the instruction at
13562306a36Sopenharmony_ci * that entry finished processing or has timed-out, the entry is cleaned.
13662306a36Sopenharmony_ci * @param octeon_dev  - the octeon device structure.
13762306a36Sopenharmony_ci * @param force_quit - the request is forced to timeout if this is 1
13862306a36Sopenharmony_ci * @return 1 if the ordered list is empty, 0 otherwise.
13962306a36Sopenharmony_ci */
14062306a36Sopenharmony_ciint lio_process_ordered_list(struct octeon_device *octeon_dev,
14162306a36Sopenharmony_ci			     u32 force_quit);
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci#endif
144