hssi: support new glob format for upstreamed drivers
The glob path used to discover the ethernet interface name
was updated by recent driver changes. Support both the old
and the new formats.
@@ -57,39 +57,64 @@ public:
: test_afu("hssi")
{}
- std::string ethernet_interface()
+ bool glob_ethernet_interface(const std::string &glob_pattern, std::string &eth_ifc)
{
- auto props = properties::get(handle_);
+ glob_t gl;
- std::ostringstream oss;
- oss << "/sys/bus/pci/devices/" <<
- std::setw(4) << std::setfill('0') << std::hex << props->segment << ":" <<
- std::setw(2) << std::setfill('0') << std::hex << props->bus << ":" <<
- std::setw(2) << std::setfill('0') << std::hex << props->device << "." <<
- std::setw(1) << std::setfill('0') << std::hex << props->function <<
- "/fpga_region/region*/dfl-fme.*/dfl-fme.*.*/net/*";
+ if (glob(glob_pattern.c_str(), 0, nullptr, &gl)) {
+ if (gl.gl_pathv)
+ globfree(&gl);
+ return false;
+ }
- glob_t gl;
- if (glob(oss.str().c_str(), 0, nullptr, &gl)) {
+ if (!gl.gl_pathc) {
if (gl.gl_pathv)
globfree(&gl);
- return std::string("");
+ return false;
}
if (gl.gl_pathc > 1)
std::cerr << "Warning: more than one ethernet interface found." << std::endl;
- std::string ifc;
- if (gl.gl_pathc) {
- ifc = gl.gl_pathv[0];
+ std::string ifc(gl.gl_pathv[0]);
size_t pos = ifc.rfind("/") + 1;
- ifc = ifc.substr(pos);
- }
+ eth_ifc = ifc.substr(pos);
if (gl.gl_pathv)
globfree(&gl);
+ return true;
+ }
+
+ std::string ethernet_interface()
+ {
+ auto props = properties::get(handle_);
+
+ std::ostringstream oss;
+ oss << "/sys/bus/pci/devices/" <<
+ std::setw(4) << std::setfill('0') << std::hex << props->segment << ":" <<
+ std::setw(2) << std::setfill('0') << std::hex << props->bus << ":" <<
+ std::setw(2) << std::setfill('0') << std::hex << props->device << "." <<
+ std::setw(1) << std::setfill('0') << std::hex << props->function <<
+ "/fpga_region/region*/dfl-fme.*/dfl-fme.*.*/net/*";
+
+ std::string ifc;
+
+ if (glob_ethernet_interface(oss.str(), ifc))
+ return ifc;
+
+ std::ostringstream oss2;
+ oss2 << "/sys/bus/pci/devices/" <<
+ std::setw(4) << std::setfill('0') << std::hex << props->segment << ":" <<
+ std::setw(2) << std::setfill('0') << std::hex << props->bus << ":" <<
+ std::setw(2) << std::setfill('0') << std::hex << props->device << "." <<
+ std::setw(1) << std::setfill('0') << std::hex << props->function <<
+ "/fpga_region/region*/dfl-fme.*/dfl_dev.*/net/*";
+
+ if (glob_ethernet_interface(oss2.str(), ifc))
return ifc;
+
+ return std::string("");
}
void mbox_write(uint16_t offset, uint32_t data)
