blob: 4a1573c654489dcdfb87320070e7fa1ed980b840 [file] [log] [blame]
Florin Corase86a8ed2018-01-05 03:20:25 -08001/*
2 *------------------------------------------------------------------
3 * Copyright (c) 2018 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
16 */
17
18#ifndef SRC_VLIBMEMORY_MEMORY_API_H_
19#define SRC_VLIBMEMORY_MEMORY_API_H_
20
21#include <svm/svm.h>
Florin Coras4d9b9d82018-01-14 12:25:50 -080022#include <svm/ssvm.h>
Florin Corase86a8ed2018-01-05 03:20:25 -080023#include <svm/queue.h>
24#include <vlib/vlib.h>
25#include <vlibapi/api.h>
Damjan Marionb7049712022-05-20 13:05:38 +020026#include <vlibapi/memory_shared.h>
Florin Corase86a8ed2018-01-05 03:20:25 -080027
28svm_queue_t *vl_api_client_index_to_input_queue (u32 index);
29int vl_mem_api_init (const char *region_name);
30void vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm,
31 f64 now);
32int vl_mem_api_handle_msg_main (vlib_main_t * vm, vlib_node_runtime_t * node);
33int vl_mem_api_handle_msg_private (vlib_main_t * vm,
34 vlib_node_runtime_t * node, u32 reg_index);
Dave Barachf6c68d72018-11-01 08:12:52 -040035int vl_mem_api_handle_rpc (vlib_main_t * vm, vlib_node_runtime_t * node);
36
Florin Corase86a8ed2018-01-05 03:20:25 -080037vl_api_registration_t *vl_mem_api_client_index_to_registration (u32 handle);
38void vl_mem_api_enable_disable (vlib_main_t * vm, int yesno);
39u32 vl_api_memclnt_create_internal (char *, svm_queue_t *);
40
41static inline u32
42vl_msg_api_handle_get_epoch (u32 index)
43{
44 return (index & VL_API_EPOCH_MASK);
45}
46
47static inline u32
48vl_msg_api_handle_get_index (u32 index)
49{
50 return (index >> VL_API_EPOCH_SHIFT);
51}
52
53static inline u32
54vl_msg_api_handle_from_index_and_epoch (u32 index, u32 epoch)
55{
56 u32 handle;
57 ASSERT (index < 0x00FFFFFF);
58
59 handle = (index << VL_API_EPOCH_SHIFT) | (epoch & VL_API_EPOCH_MASK);
60 return handle;
61}
62
Florin Corasb384b542018-01-15 01:08:33 -080063static inline u8
64vl_msg_api_handle_is_valid (u32 handle, u32 restarts)
65{
66 u32 epoch = vl_msg_api_handle_get_epoch (handle);
67 return ((restarts & VL_API_EPOCH_MASK) == epoch);
68}
69
Damjan Marionf553a2c2021-03-26 13:45:37 +010070#define VL_MEM_API_LOG_Q_LEN(fmt, qlen) \
71 if (TRACE_VLIB_MEMORY_QUEUE) \
72 do \
73 { \
74 ELOG_TYPE_DECLARE (e) = { \
75 .format = fmt, \
76 .format_args = "i4", \
77 }; \
78 struct \
79 { \
80 u32 len; \
81 } * ed; \
82 ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
83 ed->len = qlen; \
84 } \
85 while (0)
Florin Corase86a8ed2018-01-05 03:20:25 -080086
87#endif /* SRC_VLIBMEMORY_MEMORY_API_H_ */
88
89/*
90 * fd.io coding-style-patch-verification: ON
91 *
92 * Local Variables:
93 * eval: (c-set-style "gnu")
94 * End:
95 */