int hfi_context_open(int unit, int port, uint64_t open_timeout) { int fd; char dev_name[MAXPATHLEN]; if (unit != HFI_UNIT_ID_ANY && unit >= 0) snprintf(dev_name, sizeof(dev_name), "%s_%u", HFI_DEVICE_PATH, unit); else snprintf(dev_name, sizeof(dev_name), "%s", HFI_DEVICE_PATH); if (hfi_wait_for_device(dev_name, (long)open_timeout) == -1) { _HFI_DBG("Could not find an HFI Unit on device " "%s (%lds elapsed)", dev_name, (long)open_timeout / 1000); return -1; } #ifdef PSM2_SUPPORT_IW_CMD_API { int major = -1; struct stat sbuf; if ((!hfi_sysfs_stat("user_sw_version", &sbuf)) && S_ISREG(sbuf.st_mode)) { int64_t user_major_minor; if (hfi_sysfs_read_s64("user_sw_version", &user_major_minor, 0) >= 0) { /* unpack the major version stored in user_major_minor into major:; */ major = (user_major_minor >> HFI1_SWMAJOR_SHIFT) & ((1 << HFI1_SWMAJOR_SHIFT)-1); } }
int hfi_context_open(int unit, int port, uint64_t open_timeout) { int fd; char dev_name[MAXPATHLEN]; if (unit != HFI_UNIT_ID_ANY && unit >= 0) snprintf(dev_name, sizeof(dev_name), "%s_%u", HFI_DEVICE_PATH, unit); else snprintf(dev_name, sizeof(dev_name), "%s", HFI_DEVICE_PATH); if (hfi_wait_for_device(dev_name, (long)open_timeout) == -1) { _HFI_DBG("Could not find an HFI Unit on device " "%s (%lds elapsed)", dev_name, (long)open_timeout / 1000); return -1; } if ((fd = open(dev_name, O_RDWR)) == -1) { _HFI_DBG("(host:Can't open %s for reading and writing", dev_name); return -1; } if (fcntl(fd, F_SETFD, FD_CLOEXEC)) _HFI_INFO("Failed to set close on exec for device: %s\n", strerror(errno)); return fd; }