blob: 4425cea44750c74c4b4658ac092b22f20bb62748 [file] [log] [blame]
Abhishek Rastogi99714332014-04-02 19:38:12 +05301/*
2 **************************************************************************
3 * Copyright (c) 2014, Qualcomm Atheros, Inc.
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 **************************************************************************
15 */
16
17/*
18 * nss_cmn
19 * Common Message Structure and APIs
20 */
21
22#ifndef __NSS_CMN_H
23#define __NSS_CMN_H
24
25struct nss_ctx_instance;
26
27/*
28 * Common enumerations
29 */
30
31/**
32 * Tx command status
33 */
34typedef enum {
35 NSS_TX_SUCCESS = 0, /**< Success */
36 NSS_TX_FAILURE, /**< Command failure other than descriptor not available */
37 NSS_TX_FAILURE_QUEUE, /**< Command failure due to descriptor not available */
38 NSS_TX_FAILURE_NOT_READY, /**< Command failure due to NSS state uninitialized */
39 NSS_TX_FAILURE_TOO_LARGE, /**< Command is too large to fit in one message */
40 NSS_TX_FAILURE_TOO_SHORT, /**< Command/Packet is shorter than expected size */
41 NSS_TX_FAILURE_NOT_SUPPORTED, /**< Command/Packet not accepted for forwarding */
42 NSS_TX_FAILURE_BAD_PARAM, /**< Command failure due to bad parameters */
43} nss_tx_status_t;
44
45/**
46 * NSS state status
47 */
48typedef enum {
49 NSS_STATE_UNINITIALIZED = 0, /**< NSS state is initailized */
50 NSS_STATE_INITIALIZED /**< NSS state is uninitialized */
51} nss_state_t;
52
53/**
54 * NSS core id
55 */
56typedef enum {
57 NSS_CORE_0 = 0,
58 NSS_CORE_1,
59 NSS_CORE_MAX
60} nss_core_id_t;
61
62/**
63 * Callback register status
64 */
65typedef enum {
66 NSS_CB_REGISTER_SUCCESS = 0, /**< Callback register successful */
67 NSS_CB_REGISTER_FAILED, /**< Callback register failed */
68} nss_cb_register_status_t;
69
70/**
71 * Callback unregister status
72 */
73typedef enum {
74 NSS_CB_UNREGISTER_SUCCESS = 0, /**< Callback unregister successful */
75 NSS_CB_UNREGISTER_FAILED, /**< Callback unregister failed */
76} nss_cb_unregister_status_t;
77
78/*
79 * Common response structure
80 */
81enum nss_cmn_response {
82 NSS_CMN_RESPONSE_ACK, /**< Message Acknowledge */
83 NSS_CMN_RESPONSE_EVERSION, /**< Message Version Error */
84 NSS_CMN_RESPONSE_EINTERFACE, /**< Message Interface Error */
85 NSS_CMN_RESPONSE_ELENGTH, /**< Message Length Error */
86 NSS_CMN_RESPONSE_EMSG, /**< Message Error */
87 NSS_CMM_RESPONSE_NOTIFY, /**< Message Independant of Request */
88 NSS_CMN_RESPONSE_LAST
89};
90
91/*
92 * Common structures
93 */
94
95/*
96 * Common message structure
97 */
98struct nss_cmn_msg {
99 uint16_t version; /* Version id for main message format */
100 uint16_t interface; /* Primary Key for all messages */
101 enum nss_cmn_response response; /* Primary response */
102 uint32_t type; /* Decetralized request #, to be used to match response # */
103 uint32_t error; /* Decentralized specific error message, response == EMSG */
104 uint32_t cb; /* Place for callback pointer */
105 uint32_t app_data; /* Place for app data */
106 uint32_t len; /* What is the length of the message excluding this header */
107};
108
109/*
110 * Common per node stats structure
111 */
112struct nss_cmn_node_stats {
113 uint32_t rx_packets; /* Number of packets received */
114 uint32_t rx_bytes; /* Number of bytes received */
115 uint32_t rx_dropped; /* Number of receive drops due to queue full */
116 uint32_t tx_packets; /* Number of packets transmitted */
117 uint32_t tx_bytes; /* Number of bytes transmitted */
118};
119
120/**
121 * @brief Initialize common area of Host to NSS message
122 *
123 * @param ncm Common message
124 * @param if_num Interface number
125 * @param type Message type
126 * @param len Size of payload
127 * @param cb Callback function
128 * @param app_data Application context for this message
129 *
130 * @return none
131 */
132extern void nss_cmn_msg_init(struct nss_cmn_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len,
133 void *cb, void *app_data);
134
135/**
136 * @brief Obtain interface number
137 *
138 * @param nss_ctx NSS context
139 * @param dev OS network device pointer
140 *
141 * @return int32_t Interface number
142 */
143extern int32_t nss_cmn_get_interface_number(struct nss_ctx_instance *nss_ctx, struct net_device *dev);
144
145/**
146 * @brief Determine if the interface number is a represented as a virtual interface in the NSS
147 *
148 * @param nss_ctx NSS context
149 * @param int32_t The NSS interface number
150 *
151 * @return bool true if it is a virtual.
152 */
153extern bool nss_cmn_interface_is_virtual(void *nss_ctx, int32_t interface_num);
154
155/**
156 * @brief Obtain interface device pointer
157 *
158 * @param nss_ctx NSS context
159 * @param uint32_t Interface number
160 *
161 * @return void* Interface device pointer
162 */
163extern struct net_device *nss_cmn_get_interface_dev(struct nss_ctx_instance *nss_ctx, uint32_t if_num);
164
165/**
166 * @brief Obtain the NSS state
167 *
168 * @param nss_ctx NSS context
169 *
170 * @return nss_state_t NSS state
171 */
172extern nss_state_t nss_cmn_get_state(struct nss_ctx_instance *nss_ctx);
173
174/**
175 * Callback for queue decongestion message
176 */
177typedef void (*nss_cmn_queue_decongestion_callback_t)(void *app_data);
178
179/**
180 * @brief Register for queue decongestion event
181 *
182 * @param nss_ctx NSS context
183 * @param event_callback Event callback
184 * @param ctx Callee context to be returned in callback
185 *
186 * @note Callback function will be called with spinlock taken
187 */
188extern nss_cb_register_status_t nss_cmn_register_queue_decongestion(struct nss_ctx_instance *nss_ctx, nss_cmn_queue_decongestion_callback_t event_callback, void *app_data);
189
190/**
191 * @brief Unregister for queue decongestion event
192 *
193 * @param event_callback
194 */
195extern nss_cb_unregister_status_t nss_cmn_unregister_queue_decongestion(struct nss_ctx_instance *nss_ctx, nss_cmn_queue_decongestion_callback_t event_callback);
196
197#endif /* __NSS_CMN_MSG_H */