Lines Matching +full:port +full:- +full:id
2 * Copyright (c) 2004-2009 Voltaire Inc. All rights reserved.
15 * - Redistributions of source code must retain the above
19 * - Redistributions in binary form must reproduce the above
58 uint32_t id; member
71 uint32_t id; member
102 * Port
114 static int release_port(umad_port_t * port) in release_port() argument
116 free(port->pkeys); in release_port()
117 port->pkeys = NULL; in release_port()
118 port->pkeys_size = 0; in release_port()
124 const char *p = dent->d_name; in check_for_digit_name()
130 static int get_port(const char *ca_name, const char *dir, int portnum, umad_port_t * port) in get_port() argument
138 strncpy(port->ca_name, ca_name, sizeof port->ca_name - 1); in get_port()
139 port->portnum = portnum; in get_port()
140 port->pkeys = NULL; in get_port()
141 port->rate = 0; in get_port()
147 if (sys_read_uint(port_dir, SYS_PORT_LMC, &port->lmc) < 0) in get_port()
149 if (sys_read_uint(port_dir, SYS_PORT_SMLID, &port->sm_lid) < 0) in get_port()
151 if (sys_read_uint(port_dir, SYS_PORT_SMSL, &port->sm_sl) < 0) in get_port()
153 if (sys_read_uint(port_dir, SYS_PORT_LID, &port->base_lid) < 0) in get_port()
155 if (sys_read_uint(port_dir, SYS_PORT_STATE, &port->state) < 0) in get_port()
157 if (sys_read_uint(port_dir, SYS_PORT_PHY_STATE, &port->phys_state) < 0) in get_port()
164 sys_read_uint(port_dir, SYS_PORT_RATE, &port->rate); in get_port()
169 port->link_layer, UMAD_CA_NAME_LEN) < 0) in get_port()
171 sprintf(port->link_layer, "IB"); in get_port()
173 port->capmask = htobe32(capmask); in get_port()
178 port->gid_prefix = gid.global.subnet_prefix; in get_port()
179 port->port_guid = gid.global.interface_id; in get_port()
181 snprintf(port_dir + len, sizeof(port_dir) - len, "/pkeys"); in get_port()
185 port->ca_name, port->portnum, port_dir); in get_port()
188 port->pkeys = calloc(num_pkeys, sizeof(port->pkeys[0])); in get_port()
189 if (!port->pkeys) { in get_port()
195 idx = strtoul(namelist[i]->d_name, NULL, 0); in get_port()
196 sys_read_uint(port_dir, namelist[i]->d_name, &val); in get_port()
197 port->pkeys[idx] = val; in get_port()
200 port->pkeys_size = num_pkeys; in get_port()
215 if (port->pkeys) in get_port()
216 free(port->pkeys); in get_port()
217 return -EIO; in get_port()
224 for (i = 0; i <= ca->numports; i++) { in release_ca()
225 if (!ca->ports[i]) in release_ca()
227 release_port(ca->ports[i]); in release_ca()
228 free(ca->ports[i]); in release_ca()
229 ca->ports[i] = NULL; in release_ca()
235 * if *port > 0, check ca[port] state. Otherwise set *port to
236 * the first port that is active, and if such is not found, to
237 * the first port that is link up and if none are linkup, then
238 * the first port that is not disabled. Otherwise return -1.
240 static int resolve_ca_port(const char *ca_name, int *port) in resolve_ca_port() argument
243 int active = -1, up = -1; in resolve_ca_port()
249 return -1; in resolve_ca_port()
252 *port = 0; /* switch sma port 0 */ in resolve_ca_port()
257 if (*port > 0) { /* check only the port the user wants */ in resolve_ca_port()
258 if (*port > ca.numports) { in resolve_ca_port()
259 ret = -1; in resolve_ca_port()
262 if (!ca.ports[*port]) { in resolve_ca_port()
263 ret = -1; in resolve_ca_port()
266 if (strcmp(ca.ports[*port]->link_layer, "InfiniBand") && in resolve_ca_port()
267 strcmp(ca.ports[*port]->link_layer, "IB")) { in resolve_ca_port()
268 ret = -1; in resolve_ca_port()
271 if (ca.ports[*port]->state == 4) { in resolve_ca_port()
275 if (ca.ports[*port]->phys_state != 3) in resolve_ca_port()
277 ret = -1; in resolve_ca_port()
282 DEBUG("checking port %d", i); in resolve_ca_port()
285 if (strcmp(ca.ports[i]->link_layer, "InfiniBand") && in resolve_ca_port()
286 strcmp(ca.ports[i]->link_layer, "IB")) in resolve_ca_port()
288 if (up < 0 && ca.ports[i]->phys_state == 5) in resolve_ca_port()
289 up = *port = i; in resolve_ca_port()
290 if (ca.ports[i]->state == 4) { in resolve_ca_port()
291 active = *port = i; in resolve_ca_port()
292 DEBUG("found active port %d", i); in resolve_ca_port()
297 if (active == -1 && up == -1) { /* no active or linkup port found */ in resolve_ca_port()
299 DEBUG("checking port %d", i); in resolve_ca_port()
302 if (ca.ports[i]->phys_state != 3) { in resolve_ca_port()
303 up = *port = i; in resolve_ca_port()
317 ret = -1; in resolve_ca_port()
326 int phys_found = -1, port_found = 0, port, port_type; in resolve_ca_name() local
342 /* Find the first existing CA with an active port */ in resolve_ca_name()
346 port = best_port ? *best_port : 0; in resolve_ca_name()
347 if ((port_type = resolve_ca_port(names[caidx], &port)) < 0) in resolve_ca_name()
350 DEBUG("found ca %s with port %d type %d", in resolve_ca_name()
351 names[caidx], port, port_type); in resolve_ca_name()
355 *best_port = port; in resolve_ca_name()
356 DEBUG("found ca %s with active port %d", in resolve_ca_name()
357 names[caidx], port); in resolve_ca_name()
361 if (phys_found == -1) { in resolve_ca_name()
363 port_found = port; in resolve_ca_name()
367 DEBUG("phys found %d on %s port %d", in resolve_ca_name()
388 ca->numports = 0; in get_ca()
389 memset(ca->ports, 0, sizeof ca->ports); in get_ca()
390 strncpy(ca->ca_name, ca_name, sizeof(ca->ca_name) - 1); in get_ca()
393 ca->ca_name); in get_ca()
395 if ((r = sys_read_uint(dir_name, SYS_NODE_TYPE, &ca->node_type)) < 0) in get_ca()
397 if (sys_read_string(dir_name, SYS_CA_FW_VERS, ca->fw_ver, in get_ca()
398 sizeof ca->fw_ver) < 0) in get_ca()
399 ca->fw_ver[0] = '\0'; in get_ca()
400 if (sys_read_string(dir_name, SYS_CA_HW_VERS, ca->hw_ver, in get_ca()
401 sizeof ca->hw_ver) < 0) in get_ca()
402 ca->hw_ver[0] = '\0'; in get_ca()
403 if ((r = sys_read_string(dir_name, SYS_CA_TYPE, ca->ca_type, in get_ca()
404 sizeof ca->ca_type)) < 0) in get_ca()
405 ca->ca_type[0] = '\0'; in get_ca()
406 if ((r = sys_read_guid(dir_name, SYS_CA_NODE_GUID, &ca->node_guid)) < 0) in get_ca()
409 sys_read_guid(dir_name, SYS_CA_SYS_GUID, &ca->system_guid)) < 0) in get_ca()
413 SYS_INFINIBAND, ca->ca_name, SYS_CA_PORTS_DIR); in get_ca()
416 ret = errno < 0 ? errno : -EIO; in get_ca()
423 if (!strcmp(".", namelist[i]->d_name) || in get_ca()
424 !strcmp("..", namelist[i]->d_name)) in get_ca()
426 if (strcmp("0", namelist[i]->d_name) && in get_ca()
427 ((portnum = atoi(namelist[i]->d_name)) <= 0 || in get_ca()
429 ret = -EIO; in get_ca()
432 if (!(ca->ports[portnum] = in get_ca()
433 calloc(1, sizeof(*ca->ports[portnum])))) { in get_ca()
434 ret = -ENOMEM; in get_ca()
437 if (get_port(ca_name, dir_name, portnum, ca->ports[portnum]) < in get_ca()
439 free(ca->ports[portnum]); in get_ca()
440 ca->ports[portnum] = NULL; in get_ca()
441 ret = -EIO; in get_ca()
444 if (ca->numports < portnum) in get_ca()
445 ca->numports = portnum; in get_ca()
465 static int umad_id_to_dev(int umad_id, char *dev, unsigned *port) in umad_id_to_dev() argument
476 if ((r = sys_read_uint(path, SYS_IB_MAD_PORT, port)) < 0) in umad_id_to_dev()
482 static int dev_to_umad_id(const char *dev, unsigned port) in dev_to_umad_id() argument
486 int id; in dev_to_umad_id() local
488 for (id = 0; id < UMAD_MAX_PORTS; id++) { in dev_to_umad_id()
489 if (umad_id_to_dev(id, umad_dev, &umad_port) < 0) in dev_to_umad_id()
493 if (port != umad_port) in dev_to_umad_id()
496 DEBUG("mapped %s %d to %d", dev, port, id); in dev_to_umad_id()
497 return id; in dev_to_umad_id()
500 return -1; /* not found */ in dev_to_umad_id()
514 return -1; in umad_init()
521 return -1; in umad_init()
529 /* FIXME - verify that all ports are closed */ in umad_done()
556 if (strcmp(namelist[i]->d_name, ".") && in umad_get_cas_names()
557 strcmp(namelist[i]->d_name, "..")) { in umad_get_cas_names()
558 if (j < max && is_ib_type(namelist[i]->d_name)) in umad_get_cas_names()
559 strncpy(cas[j++], namelist[i]->d_name, in umad_get_cas_names()
581 TRACE("ca name %s max port guids %d", ca_name, max); in umad_get_ca_portguids()
583 return -ENODEV; in umad_get_ca_portguids()
586 return -1; in umad_get_ca_portguids()
591 return -ENOMEM; in umad_get_ca_portguids()
596 ca.ports[i]->port_guid : htobe64(0); in umad_get_ca_portguids()
609 TRACE("ca %s port %d", ca_name, portnum); in umad_get_issm_path()
612 return -ENODEV; in umad_get_issm_path()
615 return -EINVAL; in umad_get_issm_path()
627 TRACE("ca %s port %d", ca_name, portnum); in umad_open_port()
630 return -ENODEV; in umad_open_port()
632 DEBUG("opening %s port %d", ca_name, portnum); in umad_open_port()
635 return -EINVAL; in umad_open_port()
642 return -EIO; in umad_open_port()
660 return -ENODEV; in umad_get_ca()
676 TRACE("ca_name %s", ca->ca_name); in umad_release_ca()
678 return -ENODEV; in umad_release_ca()
683 DEBUG("releasing %s", ca->ca_name); in umad_release_ca()
687 int umad_get_port(const char *ca_name, int portnum, umad_port_t * port) in umad_get_port() argument
694 return -ENODEV; in umad_get_port()
699 return get_port(ca_name, dir_name, portnum, port); in umad_get_port()
702 int umad_release_port(umad_port_t * port) in umad_release_port() argument
706 TRACE("port %s:%d", port->ca_name, port->portnum); in umad_release_port()
707 if (!port) in umad_release_port()
708 return -ENODEV; in umad_release_port()
710 if ((r = release_port(port)) < 0) in umad_release_port()
713 DEBUG("releasing %s:%d", port->ca_name, port->portnum); in umad_release_port()
726 return new_user_mad_api ? ((struct ib_user_mad *)umad)->data : in umad_get_mad()
727 (void *)&((struct ib_user_mad *)umad)->addr.pkey_index; in umad_get_mad()
733 sizeof(struct ib_user_mad) - 8; in umad_size()
742 mad->addr.grh_present = 1; in umad_set_grh()
743 mad->addr.ib_gid = addr->ib_gid; in umad_set_grh()
746 mad->addr.flow_label = htobe32((uint32_t)addr->flow_label); in umad_set_grh()
747 mad->addr.hop_limit = addr->hop_limit; in umad_set_grh()
748 mad->addr.traffic_class = addr->traffic_class; in umad_set_grh()
750 mad->addr.grh_present = 0; in umad_set_grh()
759 mad->addr.pkey_index = pkey_index; in umad_set_pkey()
769 return mad->addr.pkey_index; in umad_get_pkey()
780 mad->addr.qpn = htobe32(dqp); in umad_set_addr()
781 mad->addr.lid = htobe16(dlid); in umad_set_addr()
782 mad->addr.qkey = htobe32(qkey); in umad_set_addr()
783 mad->addr.sl = sl; in umad_set_addr()
794 mad->addr.qpn = dqp; in umad_set_addr_net()
795 mad->addr.lid = dlid; in umad_set_addr_net()
796 mad->addr.qkey = qkey; in umad_set_addr_net()
797 mad->addr.sl = sl; in umad_set_addr_net()
812 mad->timeout_ms = timeout_ms; in umad_send()
813 mad->retries = retries; in umad_send()
814 mad->agent_id = agentid; in umad_send()
827 return -EIO; in umad_send()
842 return -ETIMEDOUT; in dev_poll()
844 return -EIO; in dev_poll()
857 return -EINVAL; in umad_recv()
862 errno = -n; in umad_recv()
871 DEBUG("mad received by agent %d length %d", mad->agent_id, n); in umad_recv()
873 *length = n - umad_size(); in umad_recv()
876 return mad->agent_id; in umad_recv()
879 if (n == -EWOULDBLOCK) { in umad_recv()
886 mad->length - umad_size(), umad_size(), *length); in umad_recv()
888 *length = mad->length - umad_size(); in umad_recv()
891 return -errno; in umad_recv()
917 return -EINVAL; in umad_register_oui()
936 fd, req.id, req.qpn, req.mgmt_class, oui); in umad_register_oui()
937 return req.id; /* return agentid */ in umad_register_oui()
942 return -EPERM; in umad_register_oui()
971 DEBUG("fd %d registered to use agent %d qp %d", fd, req.id, qp); in umad_register()
972 return req.id; /* return agentid */ in umad_register()
977 return -EPERM; in umad_register()
991 port_fd, attr->mgmt_class, attr->mgmt_class_version, in umad_register2()
992 attr->flags, attr->method_mask[0], attr->method_mask[1], in umad_register2()
993 attr->oui, attr->rmpp_version); in umad_register2()
995 if (attr->mgmt_class >= 0x30 && attr->mgmt_class <= 0x4f && in umad_register2()
996 ((attr->oui & 0x00ffffff) == 0 || (attr->oui & 0xff000000) != 0)) { in umad_register2()
998 attr->mgmt_class, attr->oui); in umad_register2()
1004 req.mgmt_class = attr->mgmt_class; in umad_register2()
1005 req.mgmt_class_version = attr->mgmt_class_version; in umad_register2()
1006 req.qpn = (attr->mgmt_class == 0x1 || attr->mgmt_class == 0x81) ? 0 : 1; in umad_register2()
1007 req.flags = attr->flags; in umad_register2()
1008 memcpy(req.method_mask, attr->method_mask, sizeof req.method_mask); in umad_register2()
1009 req.oui = attr->oui; in umad_register2()
1010 req.rmpp_version = attr->rmpp_version; in umad_register2()
1016 port_fd, req.id, req.qpn, req.mgmt_class, attr->oui); in umad_register2()
1017 *agent_id = req.id; in umad_register2()
1026 if (attr->flags == 0) { in umad_register2()
1045 port_fd, req_v1.id, req_v1.qpn, req_v1.mgmt_class, attr->oui); in umad_register2()
1046 *agent_id = req_v1.id; in umad_register2()
1053 attr->flags = req.flags; in umad_register2()
1058 attr->oui, req.flags); in umad_register2()
1073 return mad->status; in umad_status()
1080 return &mad->addr; in umad_get_mad_addr()
1092 #define HEX(x) ((x) < 10 ? '0' + (x) : 'a' + ((x) -10)) in umad_addr_dump()
1096 for (i = 0; i < sizeof addr->gid; i++) { in umad_addr_dump()
1097 gid_str[i * 2] = HEX(addr->gid[i] >> 4); in umad_addr_dump()
1098 gid_str[i * 2 + 1] = HEX(addr->gid[i] & 0xf); in umad_addr_dump()
1104 be32toh(addr->qpn), be32toh(addr->qkey), be16toh(addr->lid), addr->sl, in umad_addr_dump()
1105 addr->grh_present, (int)addr->gid_index, (int)addr->hop_limit, in umad_addr_dump()
1106 (int)addr->traffic_class, addr->flow_label, addr->pkey_index, in umad_addr_dump()
1114 IBWARN("agent id %d status %x timeout %d", in umad_dump()
1115 mad->agent_id, mad->status, mad->timeout_ms); in umad_dump()
1116 umad_addr_dump(&mad->addr); in umad_dump()