Esempio n. 1
0
func newInterfaces(ctx *C.struct_ibv_context) {
	var deviceAttr C.struct_ibv_device_attr
	errno := C.ibv_query_device(ctx, &deviceAttr)
	if errno != 0 {
		return
	}

	pd := C.ibv_alloc_pd(ctx)
	if pd == nil {
		panic(newError("ibv_alloc_pd", -1))
	}
	pds[pd] = true

	for port := C.uint8_t(1); port <= deviceAttr.phys_port_cnt; port++ {
		var portAttr C.struct_ibv_port_attr
		errno := C.ibv_query_port(ctx, port, &portAttr)
		if errno != 0 {
			continue
		}

		var gid C.union_ibv_gid
		errno = C.ibv_query_gid(ctx, port, 0, &gid)
		if errno != 0 {
			continue
		}
		// last 8 bytes of GID is the GUID
		guid := net.HardwareAddr(gid[8:])
		iface := &Interface{ctx, pd, uint8(port), &deviceAttr, guid}
		interfaces = append(interfaces, iface)
		guidToInterface[string([]byte(guid))] = iface
	}
}
Esempio n. 2
0
func (iface *Interface) Active() bool {
	var portAttr C.struct_ibv_port_attr
	errno := C.ibv_query_port(iface.ctx, C.uint8_t(iface.port), &portAttr)
	if errno != 0 {
		return false
	}
	return portAttr.state == C.IBV_PORT_ACTIVE
}
Esempio n. 3
0
func (iface *Interface) Lid() uint16 {
	var portAttr C.struct_ibv_port_attr
	errno := C.ibv_query_port(iface.ctx, C.uint8_t(iface.port), &portAttr)
	if errno != 0 {
		return 0
	}
	return uint16(portAttr.lid)
}