static int usdf_usnic_getinfo(uint32_t version, struct fid_fabric *fabric, struct fi_usnic_info *uip) { struct usdf_fabric *fp; struct usd_device_attrs *dap; USDF_TRACE("\n"); fp = fab_ftou(fabric); dap = fp->fab_dev_attrs; if (version > FI_EXT_USNIC_INFO_VERSION) { return -FI_EINVAL; } /* this assignment was missing in libfabric v1.1.1 and earlier */ uip->ui_version = FI_EXT_USNIC_INFO_VERSION; uip->ui.v1.ui_link_speed = dap->uda_bandwidth; uip->ui.v1.ui_netmask_be = dap->uda_netmask_be; strcpy(uip->ui.v1.ui_ifname, dap->uda_ifname); uip->ui.v1.ui_num_vf = dap->uda_num_vf; uip->ui.v1.ui_qp_per_vf = dap->uda_qp_per_vf; uip->ui.v1.ui_cq_per_vf = dap->uda_cq_per_vf; return 0; }
static int usdf_fabric_ops_open(struct fid *fid, const char *ops_name, uint64_t flags, void **ops, void *context) { USDF_TRACE("\n"); if (strcmp(ops_name, FI_USNIC_FABRIC_OPS_1) == 0) { *ops = &usdf_usnic_ops_fabric; } else { return -FI_EINVAL; } return 0; }
static int usdf_fabric_close(fid_t fid) { struct usdf_fabric *fp; int ret; void *rv; USDF_TRACE("\n"); fp = fab_fidtou(fid); if (ofi_atomic_get32(&fp->fab_refcnt) > 0) { return -FI_EBUSY; } /* Tell progression thread to exit */ fp->fab_exit = 1; free(fp->fab_attr.name); free(fp->fab_attr.prov_name); if (fp->fab_thread) { ret = usdf_fabric_wake_thread(fp); if (ret != 0) { return ret; } pthread_join(fp->fab_thread, &rv); } usdf_timer_deinit(fp); if (fp->fab_epollfd != -1) { close(fp->fab_epollfd); } if (fp->fab_eventfd != -1) { close(fp->fab_eventfd); } if (fp->fab_arp_sockfd != -1) { close(fp->fab_arp_sockfd); } free(fp); return 0; }
static int usdf_get_distance( struct usd_device_attrs *dap, uint32_t daddr_be, int *metric_o) { uint32_t nh_ip_addr; int ret; USDF_TRACE("\n"); ret = usnic_nl_rt_lookup(dap->uda_ipaddr_be, daddr_be, dap->uda_ifindex, &nh_ip_addr); if (ret != 0) { *metric_o = -1; ret = 0; } else if (nh_ip_addr == 0) { *metric_o = 0; } else { *metric_o = 1; } return ret; }
static void usdf_fini(void) { USDF_TRACE("\n"); }
static int usdf_fabric_open(struct fi_fabric_attr *fattrp, struct fid_fabric **fabric, void *context) { struct fid_fabric *ff; struct usdf_fabric *fp; struct usdf_usnic_info *dp; struct usdf_dev_entry *dep; struct epoll_event ev; struct sockaddr_in sin; int ret; int d; USDF_TRACE("\n"); /* Make sure this fabric exists */ dp = __usdf_devinfo; for (d = 0; d < dp->uu_num_devs; ++d) { dep = &dp->uu_info[d]; if (dep->ue_dev_ok && strcmp(fattrp->name, dep->ue_dattr.uda_devname) == 0) { break; } } if (d >= dp->uu_num_devs) { USDF_INFO("device \"%s\" does not exit, returning -FI_ENODEV\n", fattrp->name); return -FI_ENODEV; } fp = calloc(1, sizeof(*fp)); if (fp == NULL) { USDF_INFO("unable to allocate memory for fabric\n"); return -FI_ENOMEM; } fp->fab_epollfd = -1; fp->fab_arp_sockfd = -1; LIST_INIT(&fp->fab_domain_list); fp->fab_attr.fabric = fab_utof(fp); fp->fab_attr.name = strdup(fattrp->name); fp->fab_attr.prov_name = strdup(USDF_PROV_NAME); fp->fab_attr.prov_version = USDF_PROV_VERSION; if (fp->fab_attr.name == NULL || fp->fab_attr.prov_name == NULL) { ret = -FI_ENOMEM; goto fail; } fp->fab_fid.fid.fclass = FI_CLASS_FABRIC; fp->fab_fid.fid.context = context; fp->fab_fid.fid.ops = &usdf_fi_ops; fp->fab_fid.ops = &usdf_ops_fabric; fp->fab_dev_attrs = &dep->ue_dattr; fp->fab_epollfd = epoll_create(1024); if (fp->fab_epollfd == -1) { ret = -errno; USDF_INFO("unable to allocate epoll fd\n"); goto fail; } fp->fab_eventfd = eventfd(0, EFD_NONBLOCK | EFD_SEMAPHORE); if (fp->fab_eventfd == -1) { ret = -errno; USDF_INFO("unable to allocate event fd\n"); goto fail; } fp->fab_poll_item.pi_rtn = usdf_fabric_progression_cb; fp->fab_poll_item.pi_context = fp; ev.events = EPOLLIN; ev.data.ptr = &fp->fab_poll_item; ret = epoll_ctl(fp->fab_epollfd, EPOLL_CTL_ADD, fp->fab_eventfd, &ev); if (ret == -1) { ret = -errno; USDF_INFO("unable to EPOLL_CTL_ADD\n"); goto fail; } /* initialize timer subsystem */ ret = usdf_timer_init(fp); if (ret != 0) { USDF_INFO("unable to initialize timer\n"); goto fail; } ret = pthread_create(&fp->fab_thread, NULL, usdf_fabric_progression_thread, fp); if (ret != 0) { ret = -ret; USDF_INFO("unable to create progress thread\n"); goto fail; } /* create and bind socket for ARP resolution */ memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = fp->fab_dev_attrs->uda_ipaddr_be; fp->fab_arp_sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (fp->fab_arp_sockfd == -1) { USDF_INFO("unable to create socket\n"); goto fail; } ret = bind(fp->fab_arp_sockfd, (struct sockaddr *) &sin, sizeof(sin)); if (ret == -1) { ret = -errno; goto fail; } atomic_initialize(&fp->fab_refcnt, 0); fattrp->fabric = fab_utof(fp); fattrp->prov_version = USDF_PROV_VERSION; *fabric = fab_utof(fp); USDF_INFO("successfully opened %s/%s\n", fattrp->name, fp->fab_dev_attrs->uda_ifname); return 0; fail: ff = fab_utof(fp); usdf_fabric_close(&ff->fid); USDF_DBG("returning %d (%s)\n", ret, fi_strerror(-ret)); return ret; }
static int usdf_getinfo(uint32_t version, const char *node, const char *service, uint64_t flags, struct fi_info *hints, struct fi_info **info) { struct usdf_usnic_info *dp; struct usdf_dev_entry *dep; struct usd_device_attrs *dap; struct fi_info *fi_first; struct fi_info *fi_last; struct addrinfo *ai; struct sockaddr_in *src; struct sockaddr_in *dest; enum fi_ep_type ep_type; int metric; int d; int ret; USDF_TRACE("\n"); fi_first = NULL; fi_last = NULL; ai = NULL; src = NULL; dest = NULL; /* * Get and cache usNIC device info */ if (__usdf_devinfo == NULL) { ret = usdf_get_devinfo(); if (ret != 0) { USDF_WARN("failed to usdf_get_devinfo, ret=%d (%s)\n", ret, fi_strerror(-ret)); if (ret == -FI_ENODEV) ret = -FI_ENODATA; goto fail; } } dp = __usdf_devinfo; if (node != NULL || service != NULL) { ret = getaddrinfo(node, service, NULL, &ai); if (ret != 0) { USDF_DBG("getaddrinfo failed, likely bad node/service specified (%s:%s)\n", node, service); ret = -errno; goto fail; } if (flags & FI_SOURCE) { src = (struct sockaddr_in *)ai->ai_addr; } else { dest = (struct sockaddr_in *)ai->ai_addr; } } if (hints != NULL) { if (dest == NULL && hints->dest_addr != NULL) { dest = hints->dest_addr; } if (src == NULL && hints->src_addr != NULL) { src = hints->src_addr; } } for (d = 0; d < dp->uu_num_devs; ++d) { dep = &dp->uu_info[d]; dap = &dep->ue_dattr; /* skip this device if it has some problem */ if (!dep->ue_dev_ok) { USDF_DBG("skipping %s/%s\n", dap->uda_devname, dap->uda_ifname); continue; } /* See if dest is reachable from this device */ if (dest != NULL && dest->sin_addr.s_addr != INADDR_ANY) { ret = usdf_get_distance(dap, dest->sin_addr.s_addr, &metric); if (ret != 0) { goto fail; } if (metric == -1) { USDF_DBG("dest %s unreachable from %s/%s, skipping\n", inet_ntoa(dest->sin_addr), dap->uda_devname, dap->uda_ifname); continue; } } /* Does this device match requested attributes? */ if (hints != NULL) { ret = usdf_validate_hints(hints, dap); if (ret != 0) { USDF_DBG("hints do not match for %s/%s, skipping\n", dap->uda_devname, dap->uda_ifname); continue; } ep_type = hints->ep_attr ? hints->ep_attr->type : FI_EP_UNSPEC; } else { ep_type = FI_EP_UNSPEC; } if (ep_type == FI_EP_DGRAM || ep_type == FI_EP_UNSPEC) { ret = usdf_fill_info_dgram(version, hints, src, dest, dap, &fi_first, &fi_last); if (ret != 0 && ret != -FI_ENODATA) { goto fail; } } if (ep_type == FI_EP_MSG || ep_type == FI_EP_UNSPEC) { ret = usdf_fill_info_msg(hints, src, dest, dap, &fi_first, &fi_last); if (ret != 0 && ret != -FI_ENODATA) { goto fail; } } if (ep_type == FI_EP_RDM || ep_type == FI_EP_UNSPEC) { ret = usdf_fill_info_rdm(hints, src, dest, dap, &fi_first, &fi_last); if (ret != 0 && ret != -FI_ENODATA) { goto fail; } } } if (fi_first != NULL) { *info = fi_first; ret = 0; } else { ret = -FI_ENODATA; } fail: if (ret != 0) { fi_freeinfo(fi_first); } if (ai != NULL) { freeaddrinfo(ai); } if (ret != 0) { USDF_INFO("returning %d (%s)\n", ret, fi_strerror(-ret)); } return ret; }
static int usdf_getinfo(uint32_t version, const char *node, const char *service, uint64_t flags, const struct fi_info *hints, struct fi_info **info) { struct usdf_usnic_info *dp; struct usdf_dev_entry *dep; struct usd_device_attrs *dap; struct fi_info *fi_first; struct fi_info *fi_last; struct addrinfo *ai; void *src; void *dest; enum fi_ep_type ep_type; int d; int ret; USDF_TRACE("\n"); fi_first = NULL; fi_last = NULL; ai = NULL; src = NULL; dest = NULL; /* * Get and cache usNIC device info */ if (__usdf_devinfo == NULL) { ret = usdf_get_devinfo(); if (ret != 0) { USDF_WARN("failed to usdf_get_devinfo, ret=%d (%s)\n", ret, fi_strerror(-ret)); if (ret == -FI_ENODEV) ret = -FI_ENODATA; goto fail; } } dp = __usdf_devinfo; /* Check the hints up front and fail if they're invalid. */ if (hints) { ret = usdf_validate_hints(version, hints); if (ret) { USDF_WARN_SYS(FABRIC, "hints failed to validate\n"); goto fail; } } /* Get the src and dest if user specified. */ ret = usdf_handle_node_and_service(node, service, flags, &src, &dest, hints, &ai); if (ret) { USDF_WARN_SYS(FABRIC, "failed to handle node and service.\n"); goto fail; } if (hints != NULL) { if (dest == NULL && hints->dest_addr != NULL) dest = hints->dest_addr; if (src == NULL && hints->src_addr != NULL) src = hints->src_addr; } for (d = 0; d < dp->uu_num_devs; ++d) { dep = &dp->uu_info[d]; dap = &dep->ue_dattr; /* If the device has an issue or the hints don't match the * device information, then skip. */ if (!usdf_check_device(version, hints, src, dest, dep)) continue; if (hints && hints->ep_attr) ep_type = hints->ep_attr->type; else ep_type = FI_EP_UNSPEC; if (ep_type == FI_EP_DGRAM || ep_type == FI_EP_UNSPEC) { ret = usdf_fill_info_dgram(version, hints, src, dest, dap, &fi_first, &fi_last); if (ret != 0 && ret != -FI_ENODATA) { goto fail; } } if (ep_type == FI_EP_MSG || ep_type == FI_EP_UNSPEC) { ret = usdf_fill_info_msg(version, hints, src, dest, dap, &fi_first, &fi_last); if (ret != 0 && ret != -FI_ENODATA) { goto fail; } } if (ep_type == FI_EP_RDM || ep_type == FI_EP_UNSPEC) { ret = usdf_fill_info_rdm(version, hints, src, dest, dap, &fi_first, &fi_last); if (ret != 0 && ret != -FI_ENODATA) { goto fail; } } } if (fi_first != NULL) { *info = fi_first; ret = 0; } else { ret = -FI_ENODATA; } fail: if (ai) freeaddrinfo(ai); if (ret != 0) { fi_freeinfo(fi_first); USDF_INFO("returning %d (%s)\n", ret, fi_strerror(-ret)); } return ret; }