Merge branch 'nvme-4.18' of git://git.infradead.org/nvme into for-linus
[sfrench/cifs-2.6.git] / drivers / staging / vc04_services / interface / vchi / vchi_common.h
1 /**
2  * Copyright (c) 2010-2012 Broadcom. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions, and the following disclaimer,
9  *    without modification.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The names of the above-listed copyright holders may not be used
14  *    to endorse or promote products derived from this software without
15  *    specific prior written permission.
16  *
17  * ALTERNATIVELY, this software may be distributed under the terms of the
18  * GNU General Public License ("GPL") version 2, as published by the Free
19  * Software Foundation.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef VCHI_COMMON_H_
35 #define VCHI_COMMON_H_
36
37 //flags used when sending messages (must be bitmapped)
38 typedef enum {
39    VCHI_FLAGS_NONE                      = 0x0,
40    VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE   = 0x1,   // waits for message to be received, or sent (NB. not the same as being seen on other side)
41    VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2,   // run a callback when message sent
42    VCHI_FLAGS_BLOCK_UNTIL_QUEUED        = 0x4,   // return once the transfer is in a queue ready to go
43    VCHI_FLAGS_ALLOW_PARTIAL             = 0x8,
44    VCHI_FLAGS_BLOCK_UNTIL_DATA_READ     = 0x10,
45    VCHI_FLAGS_CALLBACK_WHEN_DATA_READ   = 0x20,
46
47    VCHI_FLAGS_ALIGN_SLOT            = 0x000080,  // internal use only
48    VCHI_FLAGS_BULK_AUX_QUEUED       = 0x010000,  // internal use only
49    VCHI_FLAGS_BULK_AUX_COMPLETE     = 0x020000,  // internal use only
50    VCHI_FLAGS_BULK_DATA_QUEUED      = 0x040000,  // internal use only
51    VCHI_FLAGS_BULK_DATA_COMPLETE    = 0x080000,  // internal use only
52    VCHI_FLAGS_INTERNAL              = 0xFF0000
53 } VCHI_FLAGS_T;
54
55 // constants for vchi_crc_control()
56 typedef enum {
57    VCHI_CRC_NOTHING = -1,
58    VCHI_CRC_PER_SERVICE = 0,
59    VCHI_CRC_EVERYTHING = 1,
60 } VCHI_CRC_CONTROL_T;
61
62 //callback reasons when an event occurs on a service
63 typedef enum {
64    VCHI_CALLBACK_REASON_MIN,
65
66    //This indicates that there is data available
67    //handle is the msg id that was transmitted with the data
68    //    When a message is received and there was no FULL message available previously, send callback
69    //    Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
70    VCHI_CALLBACK_MSG_AVAILABLE,
71    VCHI_CALLBACK_MSG_SENT,
72    VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
73
74    // This indicates that a transfer from the other side has completed
75    VCHI_CALLBACK_BULK_RECEIVED,
76    //This indicates that data queued up to be sent has now gone
77    //handle is the msg id that was used when sending the data
78    VCHI_CALLBACK_BULK_SENT,
79    VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
80    VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
81
82    VCHI_CALLBACK_SERVICE_CLOSED,
83
84    // this side has sent XOFF to peer due to lack of data consumption by service
85    // (suggests the service may need to take some recovery action if it has
86    // been deliberately holding off consuming data)
87    VCHI_CALLBACK_SENT_XOFF,
88    VCHI_CALLBACK_SENT_XON,
89
90    // indicates that a bulk transfer has finished reading the source buffer
91    VCHI_CALLBACK_BULK_DATA_READ,
92
93    // power notification events (currently host side only)
94    VCHI_CALLBACK_PEER_OFF,
95    VCHI_CALLBACK_PEER_SUSPENDED,
96    VCHI_CALLBACK_PEER_ON,
97    VCHI_CALLBACK_PEER_RESUMED,
98    VCHI_CALLBACK_FORCED_POWER_OFF,
99
100    // some extra notifications provided by vchiq_arm
101    VCHI_CALLBACK_SERVICE_OPENED,
102    VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
103    VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
104
105    VCHI_CALLBACK_REASON_MAX
106 } VCHI_CALLBACK_REASON_T;
107
108 // service control options
109 typedef enum {
110    VCHI_SERVICE_OPTION_MIN,
111
112    VCHI_SERVICE_OPTION_TRACE,
113    VCHI_SERVICE_OPTION_SYNCHRONOUS,
114
115    VCHI_SERVICE_OPTION_MAX
116 } VCHI_SERVICE_OPTION_T;
117
118 //Callback used by all services / bulk transfers
119 typedef void (*VCHI_CALLBACK_T)(void *callback_param, //my service local param
120                                  VCHI_CALLBACK_REASON_T reason,
121                                  void *handle); //for transmitting msg's only
122
123 /*
124  * Define vector struct for scatter-gather (vector) operations
125  * Vectors can be nested - if a vector element has negative length, then
126  * the data pointer is treated as pointing to another vector array, with
127  * '-vec_len' elements. Thus to append a header onto an existing vector,
128  * you can do this:
129  *
130  * void foo(const VCHI_MSG_VECTOR_T *v, int n)
131  * {
132  *    VCHI_MSG_VECTOR_T nv[2];
133  *    nv[0].vec_base = my_header;
134  *    nv[0].vec_len = sizeof my_header;
135  *    nv[1].vec_base = v;
136  *    nv[1].vec_len = -n;
137  *    ...
138  *
139  */
140 typedef struct vchi_msg_vector {
141    const void *vec_base;
142    int32_t vec_len;
143 } VCHI_MSG_VECTOR_T;
144
145 // Opaque type for a connection API
146 typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
147
148 // Opaque type for a message driver
149 typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
150
151 // Iterator structure for reading ahead through received message queue. Allocated by client,
152 // initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
153 // Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
154 // will not proceed to messages received since. Behaviour is undefined if an iterator
155 // is used again after messages for that service are removed/dequeued by any
156 // means other than vchi_msg_iter_... calls on the iterator itself.
157 typedef struct {
158    struct opaque_vchi_service_t *service;
159    void *last;
160    void *next;
161    void *remove;
162 } VCHI_MSG_ITER_T;
163
164 #endif // VCHI_COMMON_H_