Skip to content

Commit 94d91e9

Browse files
author
Razi Shahbari
committed
[mstresourcedump] Removing pyverbs and scapy dependencies
Description: Tested OS: all Tested devices: n/a Tested flows: checked compilation Known gaps (with RM ticket): n/a Issue: 3178595 Please enter the commit message for your changes. Lines starting
1 parent bb5ef42 commit 94d91e9

File tree

7 files changed

+639
-275
lines changed

7 files changed

+639
-275
lines changed

configure.ac

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,11 @@ else
431431
AC_CONFIG_FILES(mtcr_ul/Makefile)
432432
fi
433433

434+
AM_CONDITIONAL(LINUX_BUILD, [test "x$OS" = "xLinux"])
435+
AC_SUBST(LINUX_BUILD)
434436

435437
AC_OUTPUT( Makefile common/Makefile mft_utils/Makefile mft_utils/hsmclient/Makefile mtcr_py/Makefile ext_libs/Makefile ext_libs/sqlite/Makefile ext_libs/muparser/Makefile ext_libs/json/Makefile ext_libs/minixz/Makefile dev_mgt/Makefile \
436438
tools_layouts/Makefile reg_access/Makefile cmdif/Makefile libmfa/Makefile pldmlib/Makefile tools_res_mgmt/Makefile mlxconfig/Makefile mlxconfig/mlxconfig_dbs/Makefile mflash/Makefile mlxfwops/Makefile mlxfwops/lib/Makefile cmdparser/Makefile \
437439
flint/Makefile small_utils/Makefile small_utils/mlxfwresetlib/Makefile mstdump/Makefile mstdump/crd_lib/Makefile mstdump/crd_main/Makefile mstdump/mstdump_dbs/Makefile mvpd/Makefile \
438-
fw_comps_mgr/Makefile mad_ifc/Makefile tracers/Makefile tracers/fwtrace/Makefile resourcedump/Makefile resourceparse/Makefile )
440+
fw_comps_mgr/Makefile mad_ifc/Makefile tracers/Makefile tracers/fwtrace/Makefile resourcedump/Makefile resourcedump/resourcedump_lib/Makefile resourceparse/Makefile )
439441

mstflint.spec.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ rm -rf $RPM_BUILD_ROOT
205205
%{mstflint_python_tools}/mstresourcedump/filters/*.py
206206
%{mstflint_python_tools}/mstresourcedump/fetchers/*.py
207207
%{mstflint_python_tools}/mstresourcedump/commands/*.py
208+
%{mstflint_python_tools}/mstresourcedump/resourcedump_lib/cresourcedump.so
208209
%{mstflint_python_tools}/mstresourceparse/*.py
209210
%{mstflint_python_tools}/mstresourceparse/parsers/*.py
210211
%{mstflint_python_tools}/mstresourceparse/utils/*.py

resourcedump/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
# Makefile.am -- Process this file with automake to produce Makefile.in
3333

34+
if LINUX_BUILD
35+
SUBDIRS=resourcedump_lib
36+
endif
37+
3438
USER_DIR = $(top_srcdir)
3539
bin_SCRIPTS=mstresourcedump
3640

resourcedump/fetchers/ResourceDumpFetcher.py

Lines changed: 61 additions & 274 deletions
Large diffs are not rendered by default.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# Copyright © 2013-2021 NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
3+
#
4+
# This software product is a proprietary product of Nvidia Corporation and its affiliates
5+
# (the "Company") and all right, title, and interest in and to the software
6+
# product, including all associated intellectual property rights, are and
7+
# shall remain exclusively with the Company.
8+
#
9+
# This software product is governed by the End User License Agreement
10+
# provided with the software product.
11+
#
12+
13+
# Makefile.am -- Process this file with automake to produce Makefile.in
14+
15+
if LINUX_BUILD
16+
USER_DIR = $(top_srcdir)
17+
COMMON_DIR = $(top_srcdir)/common
18+
MTCR_DIR = $(top_srcdir)/${MTCR_CONF_DIR}
19+
MTCR_INC_DIR = $(top_srcdir)/include/mtcr_ul
20+
UTILS_DIR = $(top_srcdir)/mft_utils
21+
LAYOUTS_DIR = $(top_srcdir)/tools_layouts
22+
LAYOUTS_LIB = $(LAYOUTS_DIR)/libtools_layouts.la
23+
REG_ACCESS_DIR = $(top_srcdir)/reg_access
24+
RES_MGMT_DIR = $(top_srcdir)/tools_res_mgmt
25+
DEV_MGT_DIR = $(top_srcdir)/dev_mgt
26+
TOOLS_CRYPTO_DIR = $(top_srcdir)/tools_crypto
27+
RES_DUMP_DIR= $(top_srcdir)/resourcedump/resourcedump_lib
28+
INFINIBAND_INCLUDE = -isystem /auto/mswg/projects/mft/mft_build/external_libs/mft_ext_libs_inc/libibmad/linux/infiniband_new
29+
INCLUDES = -I$(top_srcdir) -I$(COMMON_DIR) -I$(REG_ACCESS_DIR) -I$(LAYOUTS_DIR) -I$(MTCR_DIR) $(INFINIBAND_INCLUDE) -I$(MTCR_INC_DIR)
30+
31+
AM_CXXFLAGS = -Wall -W -MP -H -MD -pipe -DMST_UL -g -std=c++11 $(COMPILER_FPIC)
32+
AM_CPPFLAGS = $(AM_CXXFLAGS)
33+
34+
lib_LTLIBRARIES = libresourcedump.la
35+
36+
37+
libresourcedump_la_SOURCES = resource_dump.c resource_dump.h
38+
libresourcedump_la_LIBADD = $(MTCR_DIR)/libmtcr_ul.a $(USER_DIR)/reg_access/libreg_access.a \
39+
$(DEV_MGT_DIR)/libdev_mgt.a -L$(USER_DIR)/tools_layouts/.libs -ltools_layouts
40+
41+
42+
resourcedump_pylibdir = $(libdir)/mft/python_tools/resourcedump/resourcedump_lib/
43+
dist_resourcedump_pylib_DATA = cresourcedump.so
44+
45+
cresourcedump.so: libresourcedump.la
46+
$(CC) -Wall -pthread -fpic -shared ${CFLAGS} resource_dump.o -o cresourcedump.so $(MFT_CORE_LIB_LINK) \
47+
-L$(USER_DIR)/reg_access/.libs -lreg_access -L$(DEV_MGT_DIR)/.libs -ldev_mgt \
48+
-L$(MTCR_DIR)/.libs/ -lmtcr -L$(USER_DIR)/tools_layouts/.libs -ltools_layouts \
49+
$(MFT_CORE_LIB_LINK)
50+
51+
endif
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
#include <stdio.h>
2+
#include <unistd.h>
3+
#include <malloc.h>
4+
#include <stdlib.h>
5+
#include <inttypes.h>
6+
#include <netinet/in.h>
7+
#include <arpa/inet.h>
8+
#include <infiniband/verbs.h>
9+
#include <infiniband/mlx5dv.h>
10+
#include <reg_access/reg_access.h>
11+
#include <dlfcn.h>
12+
#include <linux/swab.h>
13+
#include "resource_dump.h"
14+
15+
/* to_mpd always returns the real mlx5_pd object ie the protection domain. */
16+
static inline struct mlx5_pd* to_mpd(struct ibv_pd* ibpd)
17+
{
18+
struct mlx5_pd* mpd = to_mxxx(pd, pd);
19+
20+
if (mpd->mprotection_domain)
21+
return mpd->mprotection_domain;
22+
23+
return mpd;
24+
}
25+
26+
struct ibv_context* init_my_device_c(char device_name[], void* handler, void* handler_2)
27+
{
28+
struct ibv_device** d_list = NULL;
29+
int n = 0;
30+
int i = 0;
31+
struct ibv_context* context;
32+
struct mlx5dv_context_attr* my_context_attr;
33+
my_context_attr = (struct mlx5dv_context_attr*)malloc(sizeof(struct mlx5dv_context_attr));
34+
memset(my_context_attr, 0, sizeof(struct mlx5dv_context_attr));
35+
36+
my_context_attr->flags = MLX5DV_CONTEXT_FLAGS_DEVX;
37+
my_context_attr->comp_mask = 0;
38+
f_ibv_get_device_list ibv_get_device_list_func = (f_ibv_get_device_list)dlsym(handler, GET_DEVICE_LIST_FUNC);
39+
d_list = ibv_get_device_list_func(&n);
40+
f_ibv_get_device_name ibv_get_device_name_func = (f_ibv_get_device_name)dlsym(handler, GET_DEVICE_NAME_FUNC);
41+
f_mlx5dv_open_device mlx5dv_open_device_func = (f_mlx5dv_open_device)dlsym(handler_2, OPEN_DEVICE_FUNC);
42+
43+
if (d_list)
44+
{
45+
for (i = 0; i < n; i++)
46+
{
47+
if (d_list[i] != NULL && strcmp(ibv_get_device_name_func(d_list[i]), device_name) == 0)
48+
{
49+
context = mlx5dv_open_device_func(d_list[i], my_context_attr);
50+
if (!context)
51+
{
52+
ibv_get_device_name_func(d_list[i]);
53+
return NULL;
54+
}
55+
return context;
56+
}
57+
}
58+
}
59+
else
60+
{
61+
printf("ibv_get_device_list failed\n");
62+
return NULL;
63+
}
64+
65+
f_ibv_free_device_list ibv_free_device_list_func = (f_ibv_free_device_list)dlsym(handler, FREE_DEVICE_LIST);
66+
ibv_free_device_list_func(d_list);
67+
free(my_context_attr);
68+
69+
return NULL;
70+
}
71+
72+
struct mlx5dv_mkey* create_mkey_c(struct mlx5_mkey* mkey,
73+
struct ibv_context* context,
74+
uint32_t pdn,
75+
uint32_t umem_id,
76+
uint64_t addr,
77+
uint32_t buff_size,
78+
void* handler)
79+
{
80+
uint32_t out[DEVX_ST_SZ_DW(create_mkey_out)] = {};
81+
uint32_t in[DEVX_ST_SZ_DW(create_mkey_in)] = {};
82+
void* mkc;
83+
84+
DEVX_SET(create_mkey_in, in, opcode, MLX5_CMD_OP_CREATE_MKEY);
85+
mkc = DEVX_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry);
86+
DEVX_SET(mkc, mkc, access_mode_1_0, 0x1);
87+
DEVX_SET(mkc, mkc, umr_en, 0);
88+
DEVX_SET(mkc, mkc, pd, pdn);
89+
DEVX_SET(mkc, mkc, lr, 1);
90+
DEVX_SET(mkc, mkc, lw, 1);
91+
DEVX_SET(mkc, mkc, qpn, 0xffffff);
92+
DEVX_SET64(mkc, mkc, start_addr, addr);
93+
DEVX_SET64(mkc, mkc, len, buff_size);
94+
95+
DEVX_SET(create_mkey_in, in, mkey_umem_valid, 1);
96+
DEVX_SET(create_mkey_in, in, mkey_umem_id, umem_id);
97+
98+
f_mlx5dv_devx_obj_create mlx5dv_devx_obj_create_func =
99+
(f_mlx5dv_devx_obj_create)dlsym(handler, OBJECT_CREATE);
100+
mkey->devx_obj = mlx5dv_devx_obj_create_func(context, in, sizeof(in), out, sizeof(out));
101+
102+
if (!mkey->devx_obj)
103+
{
104+
printf("mlx5dv_devx_obj_create failed\n");
105+
printf("status: %u\n", DEVX_GET(create_mkey_out, out, status));
106+
printf("syndrome: %u\n", DEVX_GET(create_mkey_out, out, syndrome));
107+
return NULL;
108+
}
109+
110+
// printf("MKEY_INDEX: %x\n", DEVX_GET(create_mkey_out, out, mkey_index));
111+
mkey->dv_mkey.lkey = (DEVX_GET(create_mkey_out, out, mkey_index) << 8) | 0;
112+
mkey->dv_mkey.rkey = mkey->dv_mkey.lkey;
113+
114+
return &mkey->dv_mkey;
115+
}
116+
117+
struct ibv_pd* ibv_allocate_pd(struct ibv_context* ctx, void* handler)
118+
{
119+
f_ibv_alloc_pd ibv_alloc_pd_func = (f_ibv_alloc_pd)dlsym(handler, ALLOCATE_PD);
120+
struct ibv_pd* st = ibv_alloc_pd_func(ctx);
121+
122+
return st;
123+
}
124+
125+
struct mlx5dv_devx_umem* mlx5dv_devx_umem_register_ex(struct ibv_context* ctx,
126+
void* buff,
127+
uint32_t buff_al_size,
128+
struct mlx5dv_devx_umem_in* umem_in,
129+
void* handler)
130+
{
131+
umem_in->addr = buff;
132+
umem_in->size = buff_al_size;
133+
umem_in->access = IBV_ACCESS_LOCAL_WRITE;
134+
umem_in->pgsz_bitmap = sysconf(_SC_PAGESIZE);
135+
f_mlx5dv_devx_umem_reg_ex mlx5dv_devx_umem_reg_ex_func =
136+
(f_mlx5dv_devx_umem_reg_ex)dlsym(handler, UMEM_REG);
137+
struct mlx5dv_devx_umem* umem = mlx5dv_devx_umem_reg_ex_func(ctx, umem_in);
138+
139+
return umem;
140+
}
141+
142+
int generate_lkey(char device_name[], struct result* res)
143+
{
144+
void* buff;
145+
struct mlx5dv_mkey* mkey;
146+
struct mlx5dv_devx_umem_in* umem_in;
147+
umem_in = (struct mlx5dv_devx_umem_in*)malloc(sizeof(struct mlx5dv_devx_umem_in));
148+
memset(umem_in, 0, sizeof(struct mlx5dv_devx_umem_in));
149+
150+
int ret = -1;
151+
void* handler = dlopen(LIB_VERBS_LINUX_PATH, RTLD_LOCAL | RTLD_LAZY);
152+
if (!handler)
153+
{
154+
handler = dlopen(LIB_VERBS_UBUNTU_PATH, RTLD_LOCAL | RTLD_LAZY);
155+
if (!handler)
156+
{
157+
printf("Failed to load the libibverbs shared library");
158+
return ret;
159+
}
160+
}
161+
162+
void* handler_2 = dlopen(LIB_MLX5_LINUX_PATH, RTLD_LOCAL | RTLD_LAZY);
163+
if (!handler_2)
164+
{
165+
handler_2 = dlopen(LIB_MLX5_UBUNTU_PATH, RTLD_LOCAL | RTLD_LAZY);
166+
if (!handler_2)
167+
{
168+
printf("Failed to load the libmlx5 shared library");
169+
dlclose(handler);
170+
return ret;
171+
}
172+
}
173+
174+
struct ibv_context* context = init_my_device_c(device_name, handler, handler_2);
175+
if (!context)
176+
{
177+
printf("init_my_device_c failed\n");
178+
dlclose(handler);
179+
dlclose(handler_2);
180+
return ret;
181+
}
182+
183+
f_ibv_close_device ibv_close_device_func = (f_ibv_close_device)dlsym(handler, CLOSE_DEVICE);
184+
struct ibv_pd* pd = ibv_allocate_pd(context, handler);
185+
if (!pd)
186+
{
187+
printf("ibv_alloc_pd failed\n");
188+
ibv_close_device_func(context);
189+
dlclose(handler);
190+
return ret;
191+
}
192+
193+
f_ibv_dealloc_pd ibv_dealloc_pd_func = (f_ibv_dealloc_pd)dlsym(handler, DEALLOCATE_PD);
194+
uint32_t buff_al_size = align(BUFF_SIZE, sysconf(_SC_PAGESIZE));
195+
if (posix_memalign(&buff, sysconf(_SC_PAGESIZE), buff_al_size))
196+
{
197+
printf("posix_memalign failed\n");
198+
ibv_dealloc_pd_func(pd);
199+
dlclose(handler);
200+
return ret;
201+
}
202+
203+
memset(buff, 0, buff_al_size);
204+
205+
struct mlx5dv_devx_umem* umem = mlx5dv_devx_umem_register_ex(context, buff, buff_al_size, umem_in, handler_2);
206+
if (!umem)
207+
{
208+
printf("mlx5dv_devx_umem_reg failed\n");
209+
free(buff);
210+
dlclose(handler);
211+
return ret;
212+
}
213+
214+
f_mlx5dv_devx_umem_dereg mlx5dv_devx_umem_dereg_func =
215+
(f_mlx5dv_devx_umem_dereg)dlsym(handler, UMEM_DEREG);
216+
struct mlx5_mkey* mmkey = calloc(1, sizeof(*mkey));
217+
if (!mmkey)
218+
{
219+
printf("calloc Failed\n");
220+
mlx5dv_devx_umem_dereg_func(umem);
221+
dlclose(handler);
222+
return ret;
223+
}
224+
225+
mkey = create_mkey_c(mmkey, context, to_mpd(pd)->pdn, umem->umem_id, (uint64_t)buff, buff_al_size, handler_2);
226+
if (!mkey)
227+
{
228+
printf("create_mkey failed\n");
229+
free(mmkey);
230+
dlclose(handler);
231+
return ret;
232+
}
233+
else
234+
{
235+
// printf("Mkey: lkey: %u, rkey: %u\n", mkey->lkey, mkey->rkey);
236+
// printf("%" PRIu64 "buff2-\n", (uint64_t)buff);
237+
res->lkey = mkey->lkey;
238+
res->umem_addr = (uint64_t)buff;
239+
// printf("%d",res->lkey);
240+
// printf("%" PRIu64 "\n", res->umem_addr);
241+
242+
dlclose(handler);
243+
}
244+
245+
ret = 0;
246+
free(umem_in);
247+
return ret;
248+
}
249+
250+
int bit_extracted_32(uint64_t add, int offset, struct extract* ex)
251+
{
252+
// FILE *fp;
253+
// fp = fopen("/tmp/test.log", "w+");
254+
// fprintf(fp,"0x%llX\n", (long long unsigned int)add);
255+
// fprintf(fp, "offset-%d\n",offset);
256+
// fclose(fp);
257+
258+
uint64_t* p;
259+
p = (uint64_t*)add;
260+
// printf("p=%zu\n", (size_t)p);
261+
262+
p += offset / 2;
263+
264+
u_int32_t* data = (u_int32_t*)p;
265+
// printf("val=0x%016x\n",*p);
266+
267+
// printf("1st-32: 0x%08x\n", __swab32(data[0]));
268+
// printf("2nd-32: 0x%08x\n", __swab32(data[1]));
269+
270+
uint32_t idx = (offset + 1) % 2 == 0 ? 1 : 0;
271+
ex->val = __swab32(data[idx]);
272+
273+
return 0;
274+
}
275+
276+
int extrac_all(uint64_t add, int size, char* list)
277+
{
278+
// int i = 0;
279+
// u_int8_t *p;
280+
// p = (u_int8_t*)add;
281+
282+
memcpy(list, (void*)add, sizeof(char) * size);
283+
284+
// for( ; i < size; i++)
285+
// {
286+
// memcpy(list + i, p + i, sizeof(char));
287+
// }
288+
289+
return 0;
290+
}
291+

0 commit comments

Comments
 (0)