blob: f8373751c3a2c39f5df76d668c546a76845bff92 [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001/*
2<:copyright-BRCM:2016:DUAL/GPL:standard
3
4 Broadcom Proprietary and Confidential.(c) 2016 Broadcom
5 All Rights Reserved
6
7Unless you and Broadcom execute a separate written software license
8agreement governing use of this software, this software is licensed
9to you under the terms of the GNU General Public License version 2
10(the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
11with the following added to such license:
12
13 As a special exception, the copyright holders of this software give
14 you permission to link this software with independent modules, and
15 to copy and distribute the resulting executable under terms of your
16 choice, provided that you also meet, for each linked independent
17 module, the terms and conditions of the license of that module.
18 An independent module is a module which is not derived from this
19 software. The special exception does not apply to any modifications
20 of the software.
21
22Not withstanding the above, under no circumstances may you combine
23this software in any way with any other Broadcom software provided
24under a license other than the GPL, without Broadcom's express prior
25written consent.
26
27:>
28 */
29
30#ifndef BCMOLT_TR_MUX_H_
31#define BCMOLT_TR_MUX_H_
32
33/** \defgroup tr_mux Transport Multiplexer
34 * - PCIe channel multiplexer
35 * - locally/remotely - terminated message multiplexer
36 * - autonomous messages de-multiplexer
37 * @{
38 */
39
40#include <bcmolt_msg.h>
41#ifndef IN_BAND
42#include <bcmtr_pcie_sw_queue.h>
43#endif
44
45
46/* Message destination: local or remote */
47typedef enum
48{
49 BCMTRMUX_DEST_LOCAL,
50 BCMTRMUX_DEST_REMOTE,
51} bcmtrmux_msg_dest;
52
53typedef bcmtrmux_msg_dest (*bcmtrmux_msg_filter_cb_t)(bcmolt_devid, bcmolt_obj_id obj, bcmolt_mgt_group group, uint16_t subgroup);
54
55/** Initialize mux service
56 * \returns: 0 in case of success or error code < 0
57 */
58bcmos_errno bcmtrmux_init(bcmtrmux_msg_filter_cb_t msg_filter_cb);
59
60/** Notify mux driver that low-level transport connection is ready
61 * \returns: 0 in case of success or error code < 0
62 */
63#ifdef IN_BAND
64bcmos_errno bcmtrmux_connect(bcmolt_devid device, bcmos_ipv4_address ip_address, uint16_t udp_port);
65#else
66bcmos_errno bcmtrmux_connect(bcmolt_devid device, uint32_t txq_size, uint32_t rxq_size);
67#endif
68
69/** Notify mux driver that low-level transport connection is disconnected
70 * \returns: 0 in case of success or error code < 0
71 */
72bcmos_errno bcmtrmux_disconnect(bcmolt_devid device);
73
74/** Cleanup and exit
75 */
76void bcmtrmux_exit(void);
77
78/*
79 * PCIe channel multiplexer
80 */
81
82/** Logical channel id */
83typedef int bcmtrmux_channel;
84
85/** Mux statistics */
86typedef struct bcmtrmux_stat
87{
88 uint32_t tx_remote; /**< Attempted transmit to device (incuding discards) */
89 uint32_t tx_local; /**< Attempted "transmit" to device control */
90 uint32_t tx_disc_remote; /**< Discarded when transmitting to remote device (not ready or queue overflow) */
91 uint32_t tx_disc_local; /**< Couldn't deliver to device control. No handler */
92 uint32_t rx_remote; /**< Received from device */
93 uint32_t rx_local; /**< Message from the line intercepted by device control */
94 uint32_t rx_auto; /**< Received autonomous messages */
95 uint32_t control_to_host; /**< Sent by device control to the host */
96 uint32_t control_to_line; /**< Sent by device control to line */
97 uint32_t rx_disc_remote; /**< Discarded packets received from device. Can't demux channel */
98 uint32_t rx_disc_auto; /**< Discarded autonomous messages. Can't demux auto message */
99 uint32_t rx_disc_local; /**< Discarded packets received from device control. Can't demux channel */
100 uint32_t rx_disc_inv_ch; /**< Discarded because channel is invalid */
101 uint32_t rx_poll_urgent; /**< Urgent buffers counted by bcmtr_sw_queue_rx_poll() */
102 uint32_t rx_poll_normal; /**< Normal buffers counted by bcmtr_sw_queue_rx_poll() */
103} bcmtrmux_stat;
104
105
106/** Max number of channels per device */
107#define BCMTRMUX_MAX_CHANNELS 32
108
109/** First urgent channel */
110#ifndef IN_BAND
111#define BCMTRMUX_FIRST_URGENT_CHANNEL BCMTR_SWQ_FIRST_URGENT_CHANNEL
112#if BCMTRMUX_FIRST_URGENT_CHANNEL >= BCMTRMUX_MAX_CHANNELS
113 #error BCMTRMUX_FIRST_URGENT_CHANNEL and BCMTRMUX_MAX_CHANNELS settings are inconsistent
114#endif
115
116#else
117
118#define BCMTRMUX_FIRST_URGENT_CHANNEL (BCMTRMUX_MAX_CHANNELS - 1) /* Urgent channel is not supported for INBAND. */
119
120#endif
121
122
123/** Auto-assign channel */
124#define BCMTRMUX_CHANNEL_AUTO_ASSIGN (-1)
125
126/** Channel id reserved for autonomous/proxy messages */
127#define BCMTRMUX_CHANNEL_AUTO_PROXY 0
128
129/** Channel id reserved for device control */
130#define BCMTRMUX_CHANNEL_DEV_CONTROL 1
131
132/** First channel id that is not reserved */
133#define BCMTRMUX_CHANNEL_FIRST_FREE (BCMTRMUX_CHANNEL_DEV_CONTROL + 1)
134
135/** Receive message handler */
136typedef void (*f_bcmtr_rx_handler)(bcmolt_devid device, bcmos_buf *buf, bcmtrmux_channel channel, void *data);
137
138/** Local receive message handler */
139typedef void (*f_bcmtr_local_rx_handler)(bcmolt_devid device, bcmolt_msg *msg, void *data);
140
141/** Register PCIe channel owner
142 *
143 * \param[in] device Maple device index
144 * \param[in,out] channel Logical PCIe channel id.
145 * If BCMTRMUX_CHANNEL_AUTO_ASSIGN, unused channel is allocated internally.
146 * \param[in] rx Receive callback that should be used for packets received over channel
147 * \param[in] data Data to be passed to receive callback
148 * \returns: 0 in case of success or error code < 0
149 */
150bcmos_errno bcmtrmux_channel_register(bcmolt_devid device, bcmtrmux_channel *channel,
151 f_bcmtr_rx_handler rx, void *data);
152
153
154/** Release PCIe channel allocated by bcmtrmux_channel_register()
155 *
156 * \param[in] device Maple device index
157 * \param[in] channel
158 * \returns: 0 in case of success or error code < 0
159 */
160bcmos_errno bcmtrmux_channel_unregister(bcmolt_devid device, bcmtrmux_channel channel);
161
162
163/** Receive message from host application
164 *
165 * This function is called for messages transmitted from the host.
166 * Message can be locally or remotely terminated
167 * \param[in] device Maple device index
168 * \param[in] channel Logical channel
169 * \param[in] buf Buffer to be transmitted
170 */
171void bcmtrmux_rx_from_host(bcmolt_devid device, bcmtrmux_channel channel, bcmos_buf *buf);
172
173/** Receive packet from PCIe interface
174 *
175 * \param[in] device Maple device index
176 * \param[in] channel Logical channel
177 * \param[in] buf Buffer to be forwarded to application.
178 * It is de-allocated automatically
179 */
180void bcmtrmux_rx_from_line(bcmolt_devid device, bcmtrmux_channel channel, bcmos_buf *buf);
181
182/** Send packet from local control process to the host application
183 *
184 * \param[in] device Maple device index
185 * \param[in] msg Message to be sent to host application.
186 * Attention! It is responsibility of the caller to release the message
187 * after return from this function - if necessary.
188 * The reason for this is that it is expected that often msg will be allocated on stack.
189 * It is also responsibility of the caller to make sure that msg->subch is set correctly
190 * - preserved for request/response exchange
191 * - set = BCMTRMUX_CHANNEL_AUTO_PROXY for autonomous indications
192 * \returns: 0 in case of success or error code < 0
193 */
194bcmos_errno bcmtrmux_control_to_host(bcmolt_devid device, bcmolt_msg *msg);
195
196/** Send packet from local control process to the embedded system
197 *
198 * \param[in] device Maple device index
199 * \param[in] msg Message to be sent to the embedded system.
200 * Attention! It is responsibility of the caller to release the message
201 * after return from this function - if necessary.
202 * The reason for this is that it is expected that often msg will be allocated on stack.
203 * \returns: 0 in case of success or error code < 0
204 */
205bcmos_errno bcmtrmux_control_to_line(bcmolt_devid device, bcmolt_msg *msg);
206
207/** Register message for intercept by dev_ctrl
208 *
209 * Matched message receive from the line will be intercepted and
210 * delivered to callback registered using bcmtrmux_local_handler_register()
211 *
212 * \param[in] device Maple device index
213 * \param[in] object Object for which message is to be intercepted
214 * \param[in] subgroup Message subgroup
215 * \returns: 0 in case of success or error code < 0
216 */
217bcmos_errno bcmtrmux_control_auto_intercept_filter(bcmolt_devid device, bcmolt_obj_id object, uint16_t subgroup);
218
219/*
220 * Local termination handler
221 */
222
223/** Register local termination handler.
224 *
225 * This handler is called for messages transmitted by host application
226 * that should be terminated locally by device control driver and
227 * for messages received from the line that match bcmtrmux_control_auto_intercept_filter()
228 *
229 * \param[in] device Maple device index
230 * \param[in] rx Receive callback that should be used for locally-terminated packets.
231 * It must release the buffer when no longer needed
232 * \param[in] data Data to be passed to receive callback
233 * \returns: 0 in case of success or error code < 0
234 */
235bcmos_errno bcmtrmux_local_handler_register(bcmolt_devid device, f_bcmtr_local_rx_handler rx, void *data);
236
237/** Unregister local termination handler registered by bcmtrmux_local_handler_register()
238 *
239 * \param[in] device Maple device index
240 * \returns: 0 in case of success or error code < 0
241 */
242bcmos_errno bcmtrmux_local_handler_unregister(bcmolt_devid device);
243
244/** Get transport mux statistics.
245 *
246 * \param[in] device Maple device index
247 * \param[out] stat Statistics
248 * \returns: 0 in case of success or error code < 0
249 */
250bcmos_errno bcmtrmux_stat_get(bcmolt_devid device, bcmtrmux_stat *stat);
251
252#endif