From e6c18cfb6884bc4a978e97ac39f2c986dada9ee2 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Tue, 19 Apr 2022 13:36:02 -0700 Subject: [PATCH] Move fpga_id into library Signed-off-by: Alex Forencich --- lib/mqnic/Makefile | 4 ++-- {utils => lib/mqnic}/fpga_id.c | 2 +- {utils => lib/mqnic}/fpga_id.h | 2 +- lib/mqnic/mqnic.c | 3 +++ lib/mqnic/mqnic.h | 1 + utils/Makefile | 2 +- utils/mqnic-fw.c | 8 +++----- 7 files changed, 12 insertions(+), 10 deletions(-) rename {utils => lib/mqnic}/fpga_id.c (99%) rename {utils => lib/mqnic}/fpga_id.h (99%) diff --git a/lib/mqnic/Makefile b/lib/mqnic/Makefile index aba9d40e1..b1a139757 100644 --- a/lib/mqnic/Makefile +++ b/lib/mqnic/Makefile @@ -11,7 +11,7 @@ CFLAGS += -Wall CPPFLAGS += LIB = libmqnic.a -INCLUDES = mqnic.h mqnic_hw.h mqnic_ioctl.h reg_block.h +INCLUDES = mqnic.h mqnic_hw.h mqnic_ioctl.h reg_block.h fpga_id.h GENDEPFLAGS = -MD -MP -MF .$(@F).d @@ -22,7 +22,7 @@ all: $(LIB) %.o: %.c $(CC) $(ALL_CFLAGS) -c -o $@ $< -libmqnic.a: mqnic.o mqnic_if.o mqnic_sched_block.o mqnic_scheduler.o reg_block.o +libmqnic.a: mqnic.o mqnic_if.o mqnic_sched_block.o mqnic_scheduler.o reg_block.o fpga_id.o ar rcs $@ $^ install: diff --git a/utils/fpga_id.c b/lib/mqnic/fpga_id.c similarity index 99% rename from utils/fpga_id.c rename to lib/mqnic/fpga_id.c index f3b1b459d..058a464ae 100644 --- a/utils/fpga_id.c +++ b/lib/mqnic/fpga_id.c @@ -1,6 +1,6 @@ /* -Copyright 2020, The Regents of the University of California. +Copyright 2020-2022, The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/utils/fpga_id.h b/lib/mqnic/fpga_id.h similarity index 99% rename from utils/fpga_id.h rename to lib/mqnic/fpga_id.h index 997ed5440..8dc923b4b 100644 --- a/utils/fpga_id.h +++ b/lib/mqnic/fpga_id.h @@ -1,6 +1,6 @@ /* -Copyright 2020, The Regents of the University of California. +Copyright 2020-2022, The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/lib/mqnic/mqnic.c b/lib/mqnic/mqnic.c index 3019da0b5..2991cab58 100644 --- a/lib/mqnic/mqnic.c +++ b/lib/mqnic/mqnic.c @@ -33,6 +33,7 @@ either expressed or implied, of The Regents of the University of California. #include "mqnic.h" #include "mqnic_ioctl.h" +#include "fpga_id.h" #include #include @@ -406,6 +407,8 @@ open: dev->git_hash = mqnic_reg_read32(dev->fw_id_rb->regs, MQNIC_RB_FW_ID_REG_GIT_HASH); dev->rel_info = mqnic_reg_read32(dev->fw_id_rb->regs, MQNIC_RB_FW_ID_REG_REL_INFO); + dev->fpga_part = get_fpga_part(dev->fpga_id); + time_t build_date = dev->build_date; struct tm *tm_info = gmtime(&build_date); strftime(dev->build_date_str, sizeof(dev->build_date_str), "%F %T", tm_info); diff --git a/lib/mqnic/mqnic.h b/lib/mqnic/mqnic.h index 46692de65..7c0308ad1 100644 --- a/lib/mqnic/mqnic.h +++ b/lib/mqnic/mqnic.h @@ -142,6 +142,7 @@ struct mqnic { struct reg_block *phc_rb; uint32_t fpga_id; + const char *fpga_part; uint32_t fw_id; uint32_t fw_ver; uint32_t board_id; diff --git a/utils/Makefile b/utils/Makefile index b49999ee6..978815183 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -38,7 +38,7 @@ mqnic-config: mqnic-config.o timespec.o $(LIBMQNIC) mqnic-dump: mqnic-dump.o $(LIBMQNIC) $(CC) $(ALL_CFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS) -mqnic-fw: mqnic-fw.o flash.o flash_spi.o flash_bpi.o fpga_id.o bitfile.o $(LIBMQNIC) +mqnic-fw: mqnic-fw.o flash.o flash_spi.o flash_bpi.o bitfile.o $(LIBMQNIC) $(CC) $(ALL_CFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS) mqnic-bmc: mqnic-bmc.o $(LIBMQNIC) diff --git a/utils/mqnic-fw.c b/utils/mqnic-fw.c index 37e462aa0..c6a9c927f 100644 --- a/utils/mqnic-fw.c +++ b/utils/mqnic-fw.c @@ -45,7 +45,6 @@ either expressed or implied, of The Regents of the University of California. #include #include "bitfile.h" #include "flash.h" -#include "fpga_id.h" #define MAX_SEGMENTS 8 @@ -655,7 +654,6 @@ int main(int argc, char *argv[]) printf("PCIe ID (upstream port): %s\n", strrchr(pci_port_path, '/')+1); uint32_t flash_format = 0; - const char *fpga_part = get_fpga_part(dev->fpga_id); uint8_t flash_configuration = 0; uint8_t flash_data_width = 0; @@ -664,7 +662,7 @@ int main(int argc, char *argv[]) uint32_t flash_segment0_length = 0; printf("FPGA ID: 0x%08x\n", dev->fpga_id); - printf("FPGA part: %s\n", fpga_part); + printf("FPGA part: %s\n", dev->fpga_part); printf("FW ID: 0x%08x\n", dev->fw_id); printf("FW version: %d.%d.%d.%d\n", dev->fw_ver >> 24, (dev->fw_ver >> 16) & 0xff, @@ -1053,9 +1051,9 @@ int main(int argc, char *argv[]) goto err; } - if (stristr(bf->part, fpga_part) != bf->part) + if (stristr(bf->part, dev->fpga_part) != bf->part) { - fprintf(stderr, "Device mismatch (target is %s, file is %s)\n", fpga_part, bf->part); + fprintf(stderr, "Device mismatch (target is %s, file is %s)\n", dev->fpga_part, bf->part); bitfile_close(bf); free(segment); ret = -1;