From 987e11f6c083e5aedda97a0fee1fcf82694877a5 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Tue, 23 Jul 2019 18:43:58 -0700 Subject: [PATCH] Query regs size via info ioctl --- utils/mqnic.c | 11 ++++++++++- utils/mqnic.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/utils/mqnic.c b/utils/mqnic.c index cda1fa91a..777960df8 100644 --- a/utils/mqnic.c +++ b/utils/mqnic.c @@ -36,6 +36,7 @@ either expressed or implied, of The Regents of the University of California. #include #include #include +#include #include struct mqnic *mqnic_open(const char *dev_name) @@ -56,7 +57,14 @@ struct mqnic *mqnic_open(const char *dev_name) goto fail_open; } - dev->regs_size = 0x1000000; + struct mqnic_ioctl_info info; + if (ioctl(dev->fd, MQNIC_IOCTL_INFO, &info) != 0) + { + perror("MQNICCTL_INFO ioctl failed"); + goto fail_ioctl; + } + + dev->regs_size = info.regs_size; dev->regs = (volatile uint8_t *)mmap(NULL, dev->regs_size, PROT_READ | PROT_WRITE, MAP_SHARED, dev->fd, 0); if (dev->regs == MAP_FAILED) { @@ -122,6 +130,7 @@ struct mqnic *mqnic_open(const char *dev_name) return dev; fail_mmap_regs: +fail_ioctl: close(dev->fd); fail_open: free(dev); diff --git a/utils/mqnic.h b/utils/mqnic.h index 9bc8edb42..1b7c54a55 100644 --- a/utils/mqnic.h +++ b/utils/mqnic.h @@ -38,6 +38,7 @@ either expressed or implied, of The Regents of the University of California. #include #include "mqnic_hw.h" +#include "mqnic_ioctl.h" #define mqnic_reg_read32(base, reg) (((volatile uint32_t *)(base))[(reg)/4]) #define mqnic_reg_write32(base, reg, val) (((volatile uint32_t *)(base))[(reg)/4]) = val