From e7c0f17c324df4fe3e6494655c0a4b08c0b2d25a Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Sun, 4 Oct 2020 00:42:48 -0700 Subject: [PATCH] Attempt to enable device if not connecting via driver --- utils/mqnic.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/utils/mqnic.c b/utils/mqnic.c index 835c73f7c..43cbddf79 100644 --- a/utils/mqnic.c +++ b/utils/mqnic.c @@ -34,8 +34,10 @@ either expressed or implied, of The Regents of the University of California. #include "mqnic.h" #include +#include #include #include +#include #include #include #include @@ -86,6 +88,31 @@ struct mqnic *mqnic_open(const char *dev_name) goto fail_mmap_regs; } + if (mqnic_reg_read32(dev->regs, MQNIC_REG_FW_ID) == 0xffffffff) + { + // if we were given a PCIe resource, then we may need to enable the device + char path[PATH_MAX+32]; + char *ptr; + + strcpy(path, dev_name); + ptr = strrchr(path, '/'); + if (ptr) + { + strcpy(++ptr, "enable"); + } + + if (access(path, F_OK) != -1) + { + FILE *fp = fopen(path, "w"); + + if (fp) + { + fputc('1', fp); + fclose(fp); + } + } + } + if (mqnic_reg_read32(dev->regs, MQNIC_REG_FW_ID) == 0xffffffff) { fprintf(stderr, "Error: device needs to be reset\n");