Revert "Add netlink and gen netlink library loader."

This reverts commit 864f069b8f.
This commit is contained in:
wpjordan
2020-12-08 10:21:06 -05:00
committed by Compute-Runtime-Automation
parent 29254cb683
commit ab14df5aa6
6 changed files with 1 additions and 718 deletions

View File

@@ -1,22 +0,0 @@
#
# Copyright (C) 2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(LIBGENL_FOUND)
set(L0_SRCS_TOOLS_SYSMAN_LINUX_NL_API
${CMAKE_CURRENT_SOURCE_DIR}/nl_api.h
${CMAKE_CURRENT_SOURCE_DIR}/nl_api.cpp
)
endif()
if(UNIX)
target_sources(${L0_STATIC_LIB_NAME}
PRIVATE
${L0_SRCS_TOOLS_SYSMAN_LINUX_NL_API}
)
endif()
# Make our source files visible to parent
set_property(GLOBAL PROPERTY L0_SRCS_TOOLS_SYSMAN_LINUX_NL_API ${L0_SRCS_TOOLS_SYSMAN_LINUX_NL_API})

View File

@@ -1,268 +0,0 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "nl_api.h"
namespace L0 {
static const std::string libgenlFile = "libnl-genl-3.so.200";
static const std::string genlConnectRoutine = "genl_connect";
static const std::string genlCtrlResolveRoutine = "genl_ctrl_resolve";
static const std::string genlHandleMsgRoutine = "genl_handle_msg";
static const std::string genlmsgPutRoutine = "genlmsg_put";
static const std::string genlOpsResolveRoutine = "genl_ops_resolve";
static const std::string genlRegisterFamilyRoutine = "genl_register_family";
static const std::string genlUnregisterFamilyRoutine = "genl_unregister_family";
static const std::string nlaDataRoutine = "nla_data";
static const std::string nlaGetU32Routine = "nla_get_u32";
static const std::string nlaGetU64Routine = "nla_get_u64";
static const std::string nlaGetU8Routine = "nla_get_u8";
static const std::string nlaIsNestedRoutine = "nla_is_nested";
static const std::string nlaLenRoutine = "nla_len";
static const std::string nlaNextRoutine = "nla_next";
static const std::string nlaOkRoutine = "nla_ok";
static const std::string nlaPutU16Routine = "nla_put_u16";
static const std::string nlaPutU32Routine = "nla_put_u32";
static const std::string nlaPutU64Routine = "nla_put_u64";
static const std::string nlaPutU8Routine = "nla_put_u8";
static const std::string nlaTypeRoutine = "nla_type";
static const std::string nlmsgAllocRoutine = "nlmsg_alloc";
static const std::string nlmsgHdrRoutine = "nlmsg_hdr";
static const std::string nlmsgAttrdataRoutine = "nlmsg_attrdata";
static const std::string nlmsgAttrlenRoutine = "nlmsg_attrlen";
static const std::string nlmsgFreeRoutine = "nlmsg_free";
static const std::string nlRecvmsgsDefaultRoutine = "nl_recvmsgs_default";
static const std::string nlSendAutoRoutine = "nl_send_auto";
static const std::string nlSocketAllocRoutine = "nl_socket_alloc";
static const std::string nlSocketDisableSeqCheckRoutine = "nl_socket_disable_seq_check";
static const std::string nlSocketFreeRoutine = "nl_socket_free";
static const std::string nlSocketModifyCbRoutine = "nl_socket_modify_cb";
template <class T>
bool NlApi::getProcAddr(NEO::OsLibrary *lh, const std::string name, T &proc) {
proc = reinterpret_cast<T>(lh->getProcAddress(name));
return nullptr != proc;
}
bool NlApi::loadEntryPoints() {
bool ok = true;
ok = ok && getProcAddr(genlLibraryHandle, genlConnectRoutine, genlConnectEntry);
ok = ok && getProcAddr(genlLibraryHandle, genlCtrlResolveRoutine, genlCtrlResolveEntry);
ok = ok && getProcAddr(genlLibraryHandle, genlHandleMsgRoutine, genlHandleMsgEntry);
ok = ok && getProcAddr(genlLibraryHandle, genlmsgPutRoutine, genlmsgPutEntry);
ok = ok && getProcAddr(genlLibraryHandle, genlOpsResolveRoutine, genlOpsResolveEntry);
ok = ok && getProcAddr(genlLibraryHandle, genlRegisterFamilyRoutine, genlRegisterFamilyEntry);
ok = ok && getProcAddr(genlLibraryHandle, genlUnregisterFamilyRoutine, genlUnregisterFamilyEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlaDataRoutine, nlaDataEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlaGetU32Routine, nlaGetU32Entry);
ok = ok && getProcAddr(genlLibraryHandle, nlaGetU64Routine, nlaGetU64Entry);
ok = ok && getProcAddr(genlLibraryHandle, nlaGetU8Routine, nlaGetU8Entry);
ok = ok && getProcAddr(genlLibraryHandle, nlaIsNestedRoutine, nlaIsNestedEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlaLenRoutine, nlaLenEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlaNextRoutine, nlaNextEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlaOkRoutine, nlaOkEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlaPutU16Routine, nlaPutU16Entry);
ok = ok && getProcAddr(genlLibraryHandle, nlaPutU32Routine, nlaPutU32Entry);
ok = ok && getProcAddr(genlLibraryHandle, nlaPutU64Routine, nlaPutU64Entry);
ok = ok && getProcAddr(genlLibraryHandle, nlaPutU8Routine, nlaPutU8Entry);
ok = ok && getProcAddr(genlLibraryHandle, nlaTypeRoutine, nlaTypeEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlmsgAllocRoutine, nlmsgAllocEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlmsgHdrRoutine, nlmsgHdrEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlmsgAttrdataRoutine, nlmsgAttrdataEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlmsgAttrlenRoutine, nlmsgAttrlenEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlmsgFreeRoutine, nlmsgFreeEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlRecvmsgsDefaultRoutine, nlRecvmsgsDefaultEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlSendAutoRoutine, nlSendAutoEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlSocketAllocRoutine, nlSocketAllocEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlSocketDisableSeqCheckRoutine, nlSocketDisableSeqCheckEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlSocketFreeRoutine, nlSocketFreeEntry);
ok = ok && getProcAddr(genlLibraryHandle, nlSocketModifyCbRoutine, nlSocketModifyCbEntry);
return ok;
}
int NlApi::genlConnect(struct nl_sock *sock) {
UNRECOVERABLE_IF(nullptr == genlConnectEntry);
return (*genlConnectEntry)(sock);
}
int NlApi::genlCtrlResolve(struct nl_sock *sock, const char *name) {
UNRECOVERABLE_IF(nullptr == genlCtrlResolveEntry);
return (*genlCtrlResolveEntry)(sock, name);
}
int NlApi::genlHandleMsg(struct nl_msg *msg, void *arg) {
UNRECOVERABLE_IF(nullptr == genlHandleMsgEntry);
return (*genlHandleMsgEntry)(msg, arg);
}
void *NlApi::genlmsgPut(struct nl_msg *msg, uint32_t port, uint32_t seq, int family, int hdrlen, int flags, uint8_t cmd, uint8_t version) {
UNRECOVERABLE_IF(nullptr == genlmsgPutEntry);
return (*genlmsgPutEntry)(msg, port, seq, family, hdrlen, flags, cmd, version);
}
int NlApi::genlOpsResolve(struct nl_sock *sock, struct genl_ops *ops) {
UNRECOVERABLE_IF(nullptr == genlOpsResolveEntry);
return (*genlOpsResolveEntry)(sock, ops);
}
int NlApi::genlRegisterFamily(struct genl_ops *ops) {
UNRECOVERABLE_IF(nullptr == genlRegisterFamilyEntry);
return (*genlRegisterFamilyEntry)(ops);
}
int NlApi::genlUnregisterFamily(struct genl_ops *ops) {
UNRECOVERABLE_IF(nullptr == genlUnregisterFamilyEntry);
return (*genlUnregisterFamilyEntry)(ops);
}
void *NlApi::nlaData(const struct nlattr *attr) {
UNRECOVERABLE_IF(nullptr == nlaDataEntry);
return (*nlaDataEntry)(attr);
}
uint32_t NlApi::nlaGetU32(const struct nlattr *attr) {
UNRECOVERABLE_IF(nullptr == nlaGetU32Entry);
return (*nlaGetU32Entry)(attr);
}
uint64_t NlApi::nlaGetU64(const struct nlattr *attr) {
UNRECOVERABLE_IF(nullptr == nlaGetU64Entry);
return (*nlaGetU64Entry)(attr);
}
uint8_t NlApi::nlaGetU8(const struct nlattr *attr) {
UNRECOVERABLE_IF(nullptr == nlaGetU8Entry);
return (*nlaGetU8Entry)(attr);
}
int NlApi::nlaIsNested(const struct nlattr *attr) {
UNRECOVERABLE_IF(nullptr == nlaIsNestedEntry);
return (*nlaIsNestedEntry)(attr);
}
int NlApi::nlaLen(const struct nlattr *attr) {
UNRECOVERABLE_IF(nullptr == nlaLenEntry);
return (*nlaLenEntry)(attr);
}
struct nlattr *NlApi::nlaNext(const struct nlattr *attr, int *remaining) {
UNRECOVERABLE_IF(nullptr == nlaNextEntry);
return (*nlaNextEntry)(attr, remaining);
}
int NlApi::nlaOk(const struct nlattr *attr, int remaining) {
UNRECOVERABLE_IF(nullptr == nlaOkEntry);
return (*nlaOkEntry)(attr, remaining);
}
int NlApi::nlaPutU16(struct nl_msg *msg, int id, uint16_t data) {
UNRECOVERABLE_IF(nullptr == nlaPutU16Entry);
return (*nlaPutU16Entry)(msg, id, data);
}
int NlApi::nlaPutU32(struct nl_msg *msg, int id, uint32_t data) {
UNRECOVERABLE_IF(nullptr == nlaPutU32Entry);
return (*nlaPutU32Entry)(msg, id, data);
}
int NlApi::nlaPutU64(struct nl_msg *msg, int id, uint64_t data) {
UNRECOVERABLE_IF(nullptr == nlaPutU64Entry);
return (*nlaPutU64Entry)(msg, id, data);
}
int NlApi::nlaPutU8(struct nl_msg *msg, int id, uint8_t data) {
UNRECOVERABLE_IF(nullptr == nlaPutU8Entry);
return (*nlaPutU8Entry)(msg, id, data);
}
int NlApi::nlaType(const struct nlattr *attr) {
UNRECOVERABLE_IF(nullptr == nlaTypeEntry);
return (*nlaTypeEntry)(attr);
}
struct nl_msg *NlApi::nlmsgAlloc() {
UNRECOVERABLE_IF(nullptr == nlmsgAllocEntry);
return (*nlmsgAllocEntry)();
}
struct nlmsghdr *NlApi::nlmsgHdr(struct nl_msg *msg) {
UNRECOVERABLE_IF(nullptr == nlmsgHdrEntry);
return (*nlmsgHdrEntry)(msg);
}
struct nlattr *NlApi::nlmsgAttrdata(const struct nlmsghdr *hdr, int attr) {
UNRECOVERABLE_IF(nullptr == nlmsgAttrdataEntry);
return (*nlmsgAttrdataEntry)(hdr, attr);
}
int NlApi::nlmsgAttrlen(const struct nlmsghdr *hdr, int attr) {
UNRECOVERABLE_IF(nullptr == nlmsgAttrlenEntry);
return (*nlmsgAttrlenEntry)(hdr, attr);
}
void NlApi::nlmsgFree(struct nl_msg *msg) {
UNRECOVERABLE_IF(nullptr == nlmsgFreeEntry);
(*nlmsgFreeEntry)(msg);
return;
}
int NlApi::nlRecvmsgsDefault(struct nl_sock *sock) {
UNRECOVERABLE_IF(nullptr == nlRecvmsgsDefaultEntry);
return (*nlRecvmsgsDefaultEntry)(sock);
}
int NlApi::nlSendAuto(struct nl_sock *sock, struct nl_msg *msg) {
UNRECOVERABLE_IF(nullptr == nlSendAutoEntry);
return (*nlSendAutoEntry)(sock, msg);
}
struct nl_sock *NlApi::nlSocketAlloc() {
UNRECOVERABLE_IF(nullptr == nlSocketAllocEntry);
return (*nlSocketAllocEntry)();
}
void NlApi::nlSocketDisableSeqCheck(struct nl_sock *sock) {
UNRECOVERABLE_IF(nullptr == nlSocketDisableSeqCheckEntry);
(*nlSocketDisableSeqCheckEntry)(sock);
return;
}
void NlApi::nlSocketFree(struct nl_sock *sock) {
UNRECOVERABLE_IF(nullptr == nlSocketFreeEntry);
(*nlSocketFreeEntry)(sock);
return;
}
int NlApi::nlSocketModifyCb(struct nl_sock *sock, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t cb, void *arg) {
UNRECOVERABLE_IF(nullptr == nlSocketModifyCbEntry);
return (*nlSocketModifyCbEntry)(sock, type, kind, cb, arg);
}
NlApi *NlApi::create() {
NlApi *pNlApi = new NlApi;
UNRECOVERABLE_IF(nullptr == pNlApi);
pNlApi->genlLibraryHandle = NEO::OsLibrary::load(libgenlFile);
if (nullptr == pNlApi->genlLibraryHandle) {
delete pNlApi;
return nullptr;
}
if (!pNlApi->loadEntryPoints()) {
delete pNlApi;
return nullptr;
}
return pNlApi;
}
NlApi::~NlApi() {
if (nullptr != genlLibraryHandle) {
delete genlLibraryHandle;
genlLibraryHandle = nullptr;
}
}
} // namespace L0

View File

@@ -1,134 +0,0 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "level_zero/core/source/device/device.h"
#include <netlink/attr.h>
#include <netlink/genl/ctrl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/mngt.h>
#include <string>
#include <sys/socket.h>
namespace L0 {
typedef int (*pGenlConnect)(struct nl_sock *);
typedef int (*pGenlCtrlResolve)(struct nl_sock *, const char *);
typedef int (*pGenlHandleMsg)(struct nl_msg *, void *);
typedef void *(*pGenlmsgPut)(struct nl_msg *, uint32_t, uint32_t, int, int, int, uint8_t, uint8_t);
typedef int (*pGenlOpsResolve)(struct nl_sock *, struct genl_ops *);
typedef int (*pGenlRegisterFamily)(struct genl_ops *);
typedef int (*pGenlUnregisterFamily)(struct genl_ops *);
typedef void *(*pNlaData)(const struct nlattr *nla);
typedef uint32_t (*pNlaGetU32)(const struct nlattr *);
typedef uint64_t (*pNlaGetU64)(const struct nlattr *);
typedef uint8_t (*pNlaGetU8)(const struct nlattr *);
typedef int (*pNlaIsNested)(const struct nlattr *);
typedef int (*pNlaLen)(const struct nlattr *);
typedef struct nlattr *(*pNlaNext)(const struct nlattr *, int *);
typedef int (*pNlaOk)(const struct nlattr *, int);
typedef int (*pNlaPutU16)(struct nl_msg *, int, uint16_t);
typedef int (*pNlaPutU32)(struct nl_msg *, int, uint32_t);
typedef int (*pNlaPutU64)(struct nl_msg *, int, uint64_t);
typedef int (*pNlaPutU8)(struct nl_msg *, int, uint8_t);
typedef int (*pNlaType)(const struct nlattr *);
typedef struct nl_msg *(*pNlmsgAlloc)();
typedef void (*pNlmsgFree)(struct nl_msg *);
typedef int (*pNlRecvmsgsDefault)(struct nl_sock *);
typedef int (*pNlSendAuto)(struct nl_sock *, struct nl_msg *);
typedef struct nl_sock *(*pNlSocketAlloc)();
typedef void (*pNlSocketDisableSeqCheck)(struct nl_sock *);
typedef struct nlattr *(*pNlmsgAttrdata)(const struct nlmsghdr *, int);
typedef struct nlmsghdr *(*pNlmsgHdr)(struct nl_msg *);
typedef int (*pNlmsgAttrlen)(const struct nlmsghdr *, int);
typedef void (*pNlSocketFree)(struct nl_sock *);
typedef int (*pNlSocketModifyCb)(struct nl_sock *, enum nl_cb_type, enum nl_cb_kind, nl_recvmsg_msg_cb_t, void *);
class NlApi : public NEO::NonCopyableOrMovableClass {
public:
int genlConnect(struct nl_sock *sock);
int genlCtrlResolve(struct nl_sock *sock, const char *name);
int genlHandleMsg(struct nl_msg *msg, void *arg);
void *genlmsgPut(struct nl_msg *msg, uint32_t port, uint32_t seq, int family, int hdrlen, int flags, uint8_t cmd, uint8_t version);
int genlOpsResolve(struct nl_sock *sock, struct genl_ops *ops);
int genlRegisterFamily(struct genl_ops *ops);
int genlUnregisterFamily(struct genl_ops *ops);
void *nlaData(const struct nlattr *attr);
uint32_t nlaGetU32(const struct nlattr *attr);
uint64_t nlaGetU64(const struct nlattr *attr);
uint8_t nlaGetU8(const struct nlattr *attr);
int nlaIsNested(const struct nlattr *attr);
int nlaLen(const struct nlattr *attr);
struct nlattr *nlaNext(const struct nlattr *attr, int *remaining);
int nlaOk(const struct nlattr *attr, int remaining);
int nlaPutU16(struct nl_msg *msg, int id, uint16_t data);
int nlaPutU32(struct nl_msg *msg, int id, uint32_t data);
int nlaPutU64(struct nl_msg *msg, int id, uint64_t data);
int nlaPutU8(struct nl_msg *msg, int id, uint8_t data);
int nlaType(const struct nlattr *attr);
struct nl_msg *nlmsgAlloc();
struct nlmsghdr *nlmsgHdr(struct nl_msg *msg);
struct nlattr *nlmsgAttrdata(const struct nlmsghdr *hdr, int attr);
int nlmsgAttrlen(const struct nlmsghdr *hdr, int attr);
void nlmsgFree(struct nl_msg *msg);
int nlRecvmsgsDefault(struct nl_sock *sock);
int nlSendAuto(struct nl_sock *sock, struct nl_msg *msg);
struct nl_sock *nlSocketAlloc();
void nlSocketDisableSeqCheck(struct nl_sock *sock);
void nlSocketFree(struct nl_sock *sock);
int nlSocketModifyCb(struct nl_sock *sock, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t cb, void *arg);
~NlApi();
static NlApi *create();
protected:
template <class T>
bool getProcAddr(NEO::OsLibrary *lh, const std::string name, T &proc);
NlApi() = default;
bool loadEntryPoints();
NEO::OsLibrary *genlLibraryHandle = nullptr;
pGenlConnect genlConnectEntry = nullptr;
pGenlCtrlResolve genlCtrlResolveEntry = nullptr;
pGenlHandleMsg genlHandleMsgEntry = nullptr;
pGenlmsgPut genlmsgPutEntry = nullptr;
pGenlOpsResolve genlOpsResolveEntry = nullptr;
pGenlRegisterFamily genlRegisterFamilyEntry = nullptr;
pGenlUnregisterFamily genlUnregisterFamilyEntry = nullptr;
pNlaData nlaDataEntry = nullptr;
pNlaGetU32 nlaGetU32Entry = nullptr;
pNlaGetU64 nlaGetU64Entry = nullptr;
pNlaGetU8 nlaGetU8Entry = nullptr;
pNlaIsNested nlaIsNestedEntry = nullptr;
pNlaLen nlaLenEntry = nullptr;
pNlaNext nlaNextEntry = nullptr;
pNlaOk nlaOkEntry = nullptr;
pNlaPutU16 nlaPutU16Entry = nullptr;
pNlaPutU32 nlaPutU32Entry = nullptr;
pNlaPutU64 nlaPutU64Entry = nullptr;
pNlaPutU8 nlaPutU8Entry = nullptr;
pNlaType nlaTypeEntry = nullptr;
pNlmsgAlloc nlmsgAllocEntry = nullptr;
pNlmsgHdr nlmsgHdrEntry = nullptr;
pNlmsgAttrdata nlmsgAttrdataEntry = nullptr;
pNlmsgAttrlen nlmsgAttrlenEntry = nullptr;
pNlmsgFree nlmsgFreeEntry = nullptr;
pNlRecvmsgsDefault nlRecvmsgsDefaultEntry = nullptr;
pNlSendAuto nlSendAutoEntry = nullptr;
pNlSocketAlloc nlSocketAllocEntry = nullptr;
pNlSocketDisableSeqCheck nlSocketDisableSeqCheckEntry = nullptr;
pNlSocketFree nlSocketFreeEntry = nullptr;
pNlSocketModifyCb nlSocketModifyCbEntry = nullptr;
};
} // namespace L0