|
Packit |
534379 |
// Copyright(c) 2019-2020, Intel Corporation
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
534379 |
// modification, are permitted provided that the following conditions are met:
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// * Redistributions of source code must retain the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer.
|
|
Packit |
534379 |
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer in the documentation
|
|
Packit |
534379 |
// and/or other materials provided with the distribution.
|
|
Packit |
534379 |
// * Neither the name of Intel Corporation nor the names of its contributors
|
|
Packit |
534379 |
// may be used to endorse or promote products derived from this software
|
|
Packit |
534379 |
// without specific prior written permission.
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
534379 |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
534379 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
534379 |
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
534379 |
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
534379 |
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
534379 |
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
534379 |
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
534379 |
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
534379 |
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
534379 |
// POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
534379 |
#include <config.h>
|
|
Packit |
534379 |
#endif // HAVE_CONFIG_H
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#ifndef __USE_GNU
|
|
Packit |
534379 |
#define __USE_GNU
|
|
Packit |
534379 |
#endif
|
|
Packit |
534379 |
#ifndef _GNU_SOURCE
|
|
Packit |
534379 |
#define _GNU_SOURCE
|
|
Packit |
534379 |
#endif
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include <getopt.h>
|
|
Packit |
534379 |
#include "fpgainfo.h"
|
|
Packit |
534379 |
#include <opae/fpga.h>
|
|
Packit |
534379 |
#include <wchar.h>
|
|
Packit |
534379 |
#include <dirent.h>
|
|
Packit |
534379 |
#include <string.h>
|
|
Packit |
534379 |
#include <unistd.h>
|
|
Packit |
534379 |
#include <fcntl.h>
|
|
Packit |
534379 |
#include <sys/types.h>
|
|
Packit |
534379 |
#include <sys/stat.h>
|
|
Packit |
534379 |
#include <sys/ioctl.h>
|
|
Packit |
534379 |
#include <dlfcn.h>
|
|
Packit |
534379 |
#include <pthread.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include "board.h"
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
static pthread_mutex_t board_plugin_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Board plug-in table
|
|
Packit |
534379 |
static platform_data platform_data_table[] = {
|
|
Packit |
534379 |
{ 0x8086, 0x09c4, "libboard_rc.so", NULL },
|
|
Packit |
534379 |
{ 0x8086, 0x09c5, "libboard_rc.so", NULL },
|
|
Packit |
534379 |
{ 0x8086, 0x0b30, "libboard_vc.so", NULL },
|
|
Packit |
534379 |
{ 0x8086, 0x0b31, "libboard_vc.so", NULL },
|
|
Packit |
534379 |
{ 0x8086, 0x0b2b, "libboard_dc.so", NULL },
|
|
Packit |
534379 |
{ 0x8086, 0x0b2c, "libboard_dc.so", NULL },
|
|
Packit |
534379 |
{ 0, 0, NULL, NULL },
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
void *find_plugin(const char *libpath)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
char plugin_path[PATH_MAX];
|
|
Packit |
534379 |
const char *search_paths[] = { OPAE_MODULE_SEARCH_PATHS };
|
|
Packit |
534379 |
unsigned i;
|
|
Packit |
534379 |
void *dl_handle;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
for (i = 0 ;
|
|
Packit |
534379 |
i < sizeof(search_paths) / sizeof(search_paths[0]) ;
|
|
Packit |
534379 |
++i) {
|
|
Packit |
534379 |
snprintf(plugin_path, sizeof(plugin_path),
|
|
Packit |
534379 |
"%s%s", search_paths[i], libpath);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
dl_handle = dlopen(plugin_path, RTLD_LAZY | RTLD_LOCAL);
|
|
Packit |
534379 |
if (dl_handle)
|
|
Packit |
534379 |
return dl_handle;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return NULL;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpga_result load_board_plugin(fpga_token token, void **dl_handle)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
fpga_result res = FPGA_OK;
|
|
Packit |
534379 |
fpga_result resval = FPGA_OK;
|
|
Packit |
534379 |
fpga_properties props = NULL;
|
|
Packit |
534379 |
uint16_t vendor_id = 0;
|
|
Packit |
534379 |
uint16_t device_id = 0;
|
|
Packit |
534379 |
int i = 0;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (token == NULL || dl_handle == NULL) {
|
|
Packit |
534379 |
OPAE_ERR("Invalid input parameter");
|
|
Packit |
534379 |
return FPGA_INVALID_PARAM;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = fpgaGetProperties(token, &props;;
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
OPAE_ERR("Failed to get properties\n");
|
|
Packit |
534379 |
return FPGA_INVALID_PARAM;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = fpgaPropertiesGetDeviceID(props, &device_id);
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
OPAE_ERR("Failed to get device ID\n");
|
|
Packit |
534379 |
resval = res;
|
|
Packit |
534379 |
goto destroy;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = fpgaPropertiesGetVendorID(props, &vendor_id);
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
OPAE_ERR("Failed to get vendor ID\n");
|
|
Packit |
534379 |
resval = res;
|
|
Packit |
534379 |
goto destroy;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (pthread_mutex_lock(&board_plugin_lock) != 0) {
|
|
Packit |
534379 |
OPAE_ERR("pthread mutex lock failed \n");
|
|
Packit |
534379 |
resval = FPGA_EXCEPTION;
|
|
Packit |
534379 |
goto destroy;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
for (i = 0; platform_data_table[i].board_plugin; ++i) {
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (platform_data_table[i].device_id == device_id &&
|
|
Packit |
534379 |
platform_data_table[i].vendor_id == vendor_id) {
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Loaded lib or found
|
|
Packit |
534379 |
if (platform_data_table[i].dl_handle) {
|
|
Packit |
534379 |
*dl_handle = platform_data_table[i].dl_handle;
|
|
Packit |
534379 |
resval = FPGA_OK;
|
|
Packit |
534379 |
goto unlock_destroy;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
platform_data_table[i].dl_handle = find_plugin(platform_data_table[i].board_plugin);
|
|
Packit |
534379 |
if (!platform_data_table[i].dl_handle) {
|
|
Packit |
534379 |
char *err = dlerror();
|
|
Packit |
534379 |
OPAE_ERR("Failed to load \"%s\" %s", platform_data_table[i].board_plugin, err ? err : "");
|
|
Packit |
534379 |
resval = FPGA_EXCEPTION;
|
|
Packit |
534379 |
goto unlock_destroy;
|
|
Packit |
534379 |
} else {
|
|
Packit |
534379 |
// Dynamically loaded board module
|
|
Packit |
534379 |
*dl_handle = platform_data_table[i].dl_handle;
|
|
Packit |
534379 |
resval = FPGA_OK;
|
|
Packit |
534379 |
goto unlock_destroy;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
} //end if
|
|
Packit |
534379 |
|
|
Packit |
534379 |
} // end for
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
unlock_destroy:
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (pthread_mutex_unlock(&board_plugin_lock) != 0) {
|
|
Packit |
534379 |
OPAE_ERR("pthread mutex unlock failed \n");
|
|
Packit |
534379 |
resval = FPGA_EXCEPTION;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
destroy:
|
|
Packit |
534379 |
res = fpgaDestroyProperties(&props;;
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
OPAE_ERR("Failed to Destroy Object");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (*dl_handle == NULL) {
|
|
Packit |
534379 |
OPAE_MSG("Failed to load board module");
|
|
Packit |
534379 |
resval = FPGA_EXCEPTION;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return resval;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
int unload_board_plugin(void)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
int i = 0;
|
|
Packit |
534379 |
fpga_result res = FPGA_OK;
|
|
Packit |
534379 |
fpga_result resval = FPGA_OK;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (pthread_mutex_lock(&board_plugin_lock) != 0) {
|
|
Packit |
534379 |
OPAE_ERR("pthread mutex lock failed \n");
|
|
Packit |
534379 |
return FPGA_EXCEPTION;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
for (i = 0; platform_data_table[i].board_plugin; ++i) {
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (platform_data_table[i].dl_handle) {
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = dlclose(platform_data_table[i].dl_handle);
|
|
Packit |
534379 |
if (res) {
|
|
Packit |
534379 |
char *err = dlerror();
|
|
Packit |
534379 |
OPAE_ERR("dlclose failed with %d %s", res, err ? err : "");
|
|
Packit |
534379 |
resval = FPGA_EXCEPTION;
|
|
Packit |
534379 |
} else {
|
|
Packit |
534379 |
platform_data_table[i].dl_handle = NULL;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
} //end if
|
|
Packit |
534379 |
|
|
Packit |
534379 |
} // end for
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (pthread_mutex_unlock(&board_plugin_lock) != 0) {
|
|
Packit |
534379 |
OPAE_ERR("pthread mutex unlock failed \n");
|
|
Packit |
534379 |
resval = FPGA_EXCEPTION;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return resval;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/*
|
|
Packit |
534379 |
* Print help
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
void mac_help(void)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
printf("\nPrint MAC information\n"
|
|
Packit |
534379 |
" fpgainfo mac [-h]\n"
|
|
Packit |
534379 |
" -h,--help Print this help\n"
|
|
Packit |
534379 |
"\n");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define MAC_GETOPT_STRING ":h"
|
|
Packit |
534379 |
int parse_mac_args(int argc, char *argv[])
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
struct option longopts[] = {
|
|
Packit |
534379 |
{"help", no_argument, NULL, 'h'},
|
|
Packit |
534379 |
{0, 0, 0, 0},
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
int getopt_ret;
|
|
Packit |
534379 |
int option_index;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
optind = 0;
|
|
Packit |
534379 |
while (-1 != (getopt_ret = getopt_long(argc, argv, MAC_GETOPT_STRING,
|
|
Packit |
534379 |
longopts, &option_index))) {
|
|
Packit |
534379 |
const char *tmp_optarg = optarg;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (optarg && ('=' == *tmp_optarg)) {
|
|
Packit |
534379 |
++tmp_optarg;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
switch (getopt_ret) {
|
|
Packit |
534379 |
case 'h': /* help */
|
|
Packit |
534379 |
mac_help();
|
|
Packit |
534379 |
return -1;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
case ':': /* missing option argument */
|
|
Packit |
534379 |
fprintf(stderr, "Missing option argument\n");
|
|
Packit |
534379 |
mac_help();
|
|
Packit |
534379 |
return -1;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
case '?':
|
|
Packit |
534379 |
default: /* invalid option */
|
|
Packit |
534379 |
fprintf(stderr, "Invalid cmdline options\n");
|
|
Packit |
534379 |
mac_help();
|
|
Packit |
534379 |
return -1;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return 0;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpga_result mac_filter(fpga_properties *filter, int argc, char *argv[])
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
fpga_result res = FPGA_INVALID_PARAM;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (0 == parse_mac_args(argc, argv)) {
|
|
Packit |
534379 |
res = fpgaPropertiesSetObjectType(*filter, FPGA_DEVICE);
|
|
Packit |
534379 |
fpgainfo_print_err("Setting type to FPGA_DEVICE", res);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
return res;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpga_result mac_command(fpga_token *tokens, int num_tokens, int argc,
|
|
Packit |
534379 |
char *argv[])
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
(void)argc;
|
|
Packit |
534379 |
(void)argv;
|
|
Packit |
534379 |
fpga_result res = FPGA_OK;
|
|
Packit |
534379 |
fpga_properties props;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
int i = 0;
|
|
Packit |
534379 |
for (i = 0; i < num_tokens; ++i) {
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = fpgaGetProperties(tokens[i], &props;;
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
OPAE_ERR("Failed to get properties\n");
|
|
Packit |
534379 |
continue;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpgainfo_board_info(tokens[i]);
|
|
Packit |
534379 |
fpgainfo_print_common("//****** MAC ******//", props);
|
|
Packit |
534379 |
res = mac_info(tokens[i]);
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
printf("mac info is not supported\n");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return FPGA_OK;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
//phy
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/*
|
|
Packit |
534379 |
* Print help
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
void phy_help(void)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
printf("\nPrint PHY information\n"
|
|
Packit |
534379 |
" fpgainfo phy [-h] [-G <group-number>]\n"
|
|
Packit |
534379 |
" -h,--help Print this help\n"
|
|
Packit |
534379 |
" -G,--group Select PHY group {0,1,all}\n"
|
|
Packit |
534379 |
"\n");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define PHY_GETOPT_STRING ":G:h"
|
|
Packit |
534379 |
int group_num;
|
|
Packit |
534379 |
int parse_phy_args(int argc, char *argv[])
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
struct option longopts[] = {
|
|
Packit |
534379 |
{"group", required_argument, NULL, 'G'},
|
|
Packit |
534379 |
{"help", no_argument, NULL, 'h'},
|
|
Packit |
534379 |
{0, 0, 0, 0},
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
int getopt_ret;
|
|
Packit |
534379 |
int option_index;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/* default configuration */
|
|
Packit |
534379 |
group_num = -1;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
optind = 0;
|
|
Packit |
534379 |
while (-1 != (getopt_ret = getopt_long(argc, argv, PHY_GETOPT_STRING,
|
|
Packit |
534379 |
longopts, &option_index))) {
|
|
Packit |
534379 |
const char *tmp_optarg = optarg;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (optarg && ('=' == *tmp_optarg)) {
|
|
Packit |
534379 |
++tmp_optarg;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
switch (getopt_ret) {
|
|
Packit |
534379 |
case 'G':
|
|
Packit |
534379 |
if (NULL == tmp_optarg) {
|
|
Packit |
534379 |
fprintf(stderr, "Invalid argument group\n");
|
|
Packit |
534379 |
return -1;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
if (!strcmp("0", tmp_optarg)) {
|
|
Packit |
534379 |
group_num = 0;
|
|
Packit |
534379 |
} else if (!strcmp("1", tmp_optarg)) {
|
|
Packit |
534379 |
group_num = 1;
|
|
Packit |
534379 |
} else if (!strcmp("all", tmp_optarg)) {
|
|
Packit |
534379 |
group_num = -1;
|
|
Packit |
534379 |
} else {
|
|
Packit |
534379 |
fprintf(stderr, "Invalid argument '%s' of option group\n",
|
|
Packit |
534379 |
tmp_optarg);
|
|
Packit |
534379 |
return -1;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
break;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
case 'h': /* help */
|
|
Packit |
534379 |
phy_help();
|
|
Packit |
534379 |
return -1;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
case ':': /* missing option argument */
|
|
Packit |
534379 |
fprintf(stderr, "Missing option argument\n");
|
|
Packit |
534379 |
phy_help();
|
|
Packit |
534379 |
return -1;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
case '?':
|
|
Packit |
534379 |
default: /* invalid option */
|
|
Packit |
534379 |
fprintf(stderr, "Invalid cmdline options\n");
|
|
Packit |
534379 |
phy_help();
|
|
Packit |
534379 |
return -1;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return 0;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpga_result phy_filter(fpga_properties *filter, int argc, char *argv[])
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
fpga_result res = FPGA_INVALID_PARAM;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (0 == parse_phy_args(argc, argv)) {
|
|
Packit |
534379 |
res = fpgaPropertiesSetObjectType(*filter, FPGA_DEVICE);
|
|
Packit |
534379 |
fpgainfo_print_err("setting type to FPGA_DEVICE", res);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
return res;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpga_result phy_command(fpga_token *tokens, int num_tokens, int argc,
|
|
Packit |
534379 |
char *argv[])
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
(void)argc;
|
|
Packit |
534379 |
(void)argv;
|
|
Packit |
534379 |
fpga_result res = FPGA_OK;
|
|
Packit |
534379 |
fpga_properties props;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
int i = 0;
|
|
Packit |
534379 |
for (i = 0; i < num_tokens; ++i) {
|
|
Packit |
534379 |
res = fpgaGetProperties(tokens[i], &props;;
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
OPAE_ERR("Failed to get properties\n");
|
|
Packit |
534379 |
continue;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpgainfo_board_info(tokens[i]);
|
|
Packit |
534379 |
fpgainfo_print_common("//****** PHY ******//", props);
|
|
Packit |
534379 |
res = phy_group_info(tokens[i]);
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
printf("phy group info is not supported\n");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return FPGA_OK;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// prints board version info
|
|
Packit |
534379 |
fpga_result fpgainfo_board_info(fpga_token token)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
fpga_result res = FPGA_OK;
|
|
Packit |
534379 |
void *dl_handle = NULL;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Board version
|
|
Packit |
534379 |
fpga_result(*print_board_info)(fpga_token token);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = load_board_plugin(token, &dl_handle);
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
OPAE_MSG("Failed to load board plugin\n");
|
|
Packit |
534379 |
goto out;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
print_board_info = dlsym(dl_handle, "print_board_info");
|
|
Packit |
534379 |
if (print_board_info) {
|
|
Packit |
534379 |
res = print_board_info(token);
|
|
Packit |
534379 |
} else {
|
|
Packit |
534379 |
OPAE_ERR("No print_board_info entry point:%s\n", dlerror());
|
|
Packit |
534379 |
res = FPGA_NOT_FOUND;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
out:
|
|
Packit |
534379 |
return res;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Prints mac info
|
|
Packit |
534379 |
fpga_result mac_info(fpga_token token)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
fpga_result res = FPGA_OK;
|
|
Packit |
534379 |
void *dl_handle = NULL;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// mac information
|
|
Packit |
534379 |
fpga_result(*print_mac_info)(fpga_token token);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = load_board_plugin(token, &dl_handle);
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
OPAE_MSG("Failed to load board plugin\n");
|
|
Packit |
534379 |
goto out;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
print_mac_info = dlsym(dl_handle, "print_mac_info");
|
|
Packit |
534379 |
if (print_mac_info) {
|
|
Packit |
534379 |
res = print_mac_info(token);
|
|
Packit |
534379 |
} else {
|
|
Packit |
534379 |
OPAE_MSG("No print_mac_info entry point:%s\n", dlerror());
|
|
Packit |
534379 |
res = FPGA_NOT_FOUND;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
out:
|
|
Packit |
534379 |
return res;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// prints PHY group info
|
|
Packit |
534379 |
fpga_result phy_group_info(fpga_token token)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
fpga_result res = FPGA_OK;
|
|
Packit |
534379 |
void *dl_handle = NULL;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// phy group info
|
|
Packit |
534379 |
fpga_result(*print_phy_info)(fpga_token token);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = load_board_plugin(token, &dl_handle);
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
OPAE_MSG("Failed to load board plugin\n");
|
|
Packit |
534379 |
goto out;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
print_phy_info = dlsym(dl_handle, "print_phy_info");
|
|
Packit |
534379 |
if (print_phy_info) {
|
|
Packit |
534379 |
res = print_phy_info(token);
|
|
Packit |
534379 |
} else {
|
|
Packit |
534379 |
OPAE_MSG("No print_phy_info entry point:%s\n", dlerror());
|
|
Packit |
534379 |
res = FPGA_NOT_FOUND;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
out:
|
|
Packit |
534379 |
return res;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
void sec_help(void)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
printf("\nPrint security information\n"
|
|
Packit |
534379 |
" fpgainfo security [-h]\n"
|
|
Packit |
534379 |
" -h,--help Print this help\n"
|
|
Packit |
534379 |
"\n");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define SEC_GETOPT_STRING ":h"
|
|
Packit |
534379 |
int parse_sec_args(int argc, char *argv[])
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
struct option longopts[] = {
|
|
Packit |
534379 |
{"help", no_argument, NULL, 'h'},
|
|
Packit |
534379 |
{0, 0, 0, 0},
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
int getopt_ret;
|
|
Packit |
534379 |
int option_index;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
optind = 0;
|
|
Packit |
534379 |
while (-1 != (getopt_ret = getopt_long(argc, argv, SEC_GETOPT_STRING,
|
|
Packit |
534379 |
longopts, &option_index))) {
|
|
Packit |
534379 |
const char *tmp_optarg = optarg;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (optarg && ('=' == *tmp_optarg)) {
|
|
Packit |
534379 |
++tmp_optarg;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
switch (getopt_ret) {
|
|
Packit |
534379 |
case 'h': /* help */
|
|
Packit |
534379 |
mac_help();
|
|
Packit |
534379 |
return -1;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
case ':': /* missing option argument */
|
|
Packit |
534379 |
fprintf(stderr, "Missing option argument\n");
|
|
Packit |
534379 |
mac_help();
|
|
Packit |
534379 |
return -1;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
case '?':
|
|
Packit |
534379 |
default: /* invalid option */
|
|
Packit |
534379 |
fprintf(stderr, "Invalid cmdline options\n");
|
|
Packit |
534379 |
mac_help();
|
|
Packit |
534379 |
return -1;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return 0;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpga_result sec_filter(fpga_properties *filter, int argc, char *argv[])
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
fpga_result res = FPGA_INVALID_PARAM;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (0 == parse_sec_args(argc, argv)) {
|
|
Packit |
534379 |
res = fpgaPropertiesSetObjectType(*filter, FPGA_DEVICE);
|
|
Packit |
534379 |
fpgainfo_print_err("Setting type to FPGA_DEVICE", res);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
return res;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpga_result sec_command(fpga_token *tokens, int num_tokens, int argc,
|
|
Packit |
534379 |
char *argv[])
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
(void)argc;
|
|
Packit |
534379 |
(void)argv;
|
|
Packit |
534379 |
fpga_result res = FPGA_OK;
|
|
Packit |
534379 |
fpga_properties props;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
int i = 0;
|
|
Packit |
534379 |
for (i = 0; i < num_tokens; ++i) {
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = fpgaGetProperties(tokens[i], &props;;
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
OPAE_ERR("Failed to get properties\n");
|
|
Packit |
534379 |
continue;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpgainfo_board_info(tokens[i]);
|
|
Packit |
534379 |
fpgainfo_print_common("//****** MAC ******//", props);
|
|
Packit |
534379 |
res = sec_info(tokens[i]);
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
printf("mac info is not supported\n");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return FPGA_OK;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Prints Sec info
|
|
Packit |
534379 |
fpga_result sec_info(fpga_token token)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
fpga_result res = FPGA_OK;
|
|
Packit |
534379 |
void *dl_handle = NULL;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Sec information
|
|
Packit |
534379 |
fpga_result(*print_sec_info)(fpga_token token);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = load_board_plugin(token, &dl_handle);
|
|
Packit |
534379 |
if (res != FPGA_OK) {
|
|
Packit |
534379 |
OPAE_MSG("Failed to load board plugin\n");
|
|
Packit |
534379 |
goto out;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
print_sec_info = dlsym(dl_handle, "print_sec_info");
|
|
Packit |
534379 |
if (print_sec_info) {
|
|
Packit |
534379 |
res = print_sec_info(token);
|
|
Packit |
534379 |
} else {
|
|
Packit |
534379 |
OPAE_MSG("No print_sec_info entry point:%s\n", dlerror());
|
|
Packit |
534379 |
res = FPGA_NOT_FOUND;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
out:
|
|
Packit |
534379 |
return res;
|
|
Packit |
534379 |
}
|