All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] bug fixes and supporting new functionalities
@ 2010-03-21 15:19 Doron Shoham
       [not found] ` <4BA6391A.7020608-smomgflXvOZWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Doron Shoham @ 2010-03-21 15:19 UTC (permalink / raw)
  To: sashak-smomgflXvOZWk0Htik3J/w; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] sim_ctl_get_portinfo:
       [not found] ` <4BA6391A.7020608-smomgflXvOZWk0Htik3J/w@public.gmane.org>
@ 2010-03-21 15:20   ` Doron Shoham
  2010-03-21 15:21   ` [PATCH 2/4] sim_ctl_get_pkeys Doron Shoham
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Doron Shoham @ 2010-03-21 15:20 UTC (permalink / raw)
  To: sashak-smomgflXvOZWk0Htik3J/w; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA

do not decrease port number.
for hca port number can  be 1 or 2 and
for switch its always 0.
node_get_port() already handles by type.

Signed-off-by: Doron Shoham <dorons-smomgflXvOZWk0Htik3J/w@public.gmane.org>
---
 ibsim/ibsim.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/ibsim/ibsim.c b/ibsim/ibsim.c
index e720f0d..9326d37 100644
--- a/ibsim/ibsim.c
+++ b/ibsim/ibsim.c
@@ -318,10 +318,8 @@ static int sim_ctl_get_portinfo(Client * cl, struct sim_ctl * ctl)
 	uint8_t port_num = ctl->data[0];
 	if (port_num == 0 || port_num > cl->port->node->numports)
 		p = cl->port;
-	else if (cl->port->node->type == SWITCH_NODE)
-		p = node_get_port(cl->port->node, port_num);
 	else
-		p = node_get_port(cl->port->node, port_num - 1);
+		p = node_get_port(cl->port->node, port_num);
 	update_portinfo(p);
 	memcpy(ctl->data, p->portinfo, sizeof(ctl->data));
 	return 0;
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] sim_ctl_get_pkeys
       [not found] ` <4BA6391A.7020608-smomgflXvOZWk0Htik3J/w@public.gmane.org>
  2010-03-21 15:20   ` [PATCH 1/4] sim_ctl_get_portinfo: Doron Shoham
@ 2010-03-21 15:21   ` Doron Shoham
  2010-03-21 15:23   ` [PATCH 3/4] set PartitionCap and PartitionEnforcementCap to be 32 Doron Shoham
  2010-03-21 15:24   ` [PATCH 4/4] add support for end port selection Doron Shoham
  3 siblings, 0 replies; 5+ messages in thread
From: Doron Shoham @ 2010-03-21 15:21 UTC (permalink / raw)
  To: sashak-smomgflXvOZWk0Htik3J/w; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA

similar to sim_ctl_get_portinfo, return the correct
port's pkey tables according to the port number.

Signed-off-by: Doron Shoham <dorons-smomgflXvOZWk0Htik3J/w@public.gmane.org>
---
 ibsim/ibsim.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/ibsim/ibsim.c b/ibsim/ibsim.c
index 9326d37..3cb97e4 100644
--- a/ibsim/ibsim.c
+++ b/ibsim/ibsim.c
@@ -354,11 +354,18 @@ static int sim_ctl_set_issm(Client * cl, struct sim_ctl * ctl)
 
 static int sim_ctl_get_pkeys(Client * cl, struct sim_ctl * ctl)
 {
-	Port *port = cl->port;
-	unsigned size = (port->node->sw && port->portnum) ?
-	    mad_get_field(port->node->sw->switchinfo, 0,
-			  IB_SW_PARTITION_ENFORCE_CAP_F) :
-	    mad_get_field(port->node->nodeinfo, 0, IB_NODE_PARTITION_CAP_F);
+	Port *port;
+	uint8_t port_num = ctl->data[0];
+	unsigned size;
+
+	if (port_num == 0 || port_num > cl->port->node->numports)
+		port = cl->port;
+	else
+		port = node_get_port(cl->port->node, port_num);
+	size = (port->node->sw && port->portnum) ?
+			mad_get_field(port->node->sw->switchinfo, 0,
+					IB_SW_PARTITION_ENFORCE_CAP_F) :
+			mad_get_field(port->node->nodeinfo, 0, IB_NODE_PARTITION_CAP_F);
 
 	size *= sizeof(port->pkey_tbl[0]);
 	if (size > sizeof(ctl->data))
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] set PartitionCap and PartitionEnforcementCap to be 32.
       [not found] ` <4BA6391A.7020608-smomgflXvOZWk0Htik3J/w@public.gmane.org>
  2010-03-21 15:20   ` [PATCH 1/4] sim_ctl_get_portinfo: Doron Shoham
  2010-03-21 15:21   ` [PATCH 2/4] sim_ctl_get_pkeys Doron Shoham
@ 2010-03-21 15:23   ` Doron Shoham
  2010-03-21 15:24   ` [PATCH 4/4] add support for end port selection Doron Shoham
  3 siblings, 0 replies; 5+ messages in thread
From: Doron Shoham @ 2010-03-21 15:23 UTC (permalink / raw)
  To: sashak-smomgflXvOZWk0Htik3J/w; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA

This is maximum number of pkeys that can be sent
in one CTL message.
This number is calculated from:
SIM_CTL_MAX_DATA/sizeof(uint16_t)


Signed-off-by: Doron Shoham <dorons-smomgflXvOZWk0Htik3J/w@public.gmane.org>
---
 ibsim/sim_net.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/ibsim/sim_net.c b/ibsim/sim_net.c
index 13c3b8c..6cdd40a 100644
--- a/ibsim/sim_net.c
+++ b/ibsim/sim_net.c
@@ -121,7 +121,7 @@ static const uint8_t hcaport_down[] = {
 
 static const uint8_t switchinfo[] = {
 	0xC0, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04,
-	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
 	0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -134,7 +134,7 @@ static const uint8_t swnodeinfo[] = {
 	0x01, 0x01, 0x02, 0x08, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
 	0xF1, 0x04, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x08,
-	0xF1, 0x04, 0x00, 0x0D, 0x00, 0x08, 0xA8, 0x7C,
+	0xF1, 0x04, 0x00, 0x0D, 0x00, 0x20, 0xA8, 0x7C,
 	0x00, 0x00, 0x00, 0xA1, 0x00, 0x00, 0x08, 0xF1,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -145,7 +145,7 @@ static const uint8_t hcanodeinfo[] = {
 	0x01, 0x01, 0x01, 0x02, 0x00, 0x02, 0xC9, 0x00,
 	0x01, 0x13, 0x6E, 0x40, 0x00, 0x02, 0xC9, 0x00,
 	0x01, 0x13, 0x6E, 0x40, 0x00, 0x02, 0xC9, 0x00,
-	0x01, 0x13, 0x6E, 0x41, 0x00, 0x40, 0x5A, 0x44,
+	0x01, 0x13, 0x6E, 0x41, 0x00, 0x20, 0x5A, 0x44,
 	0x00, 0x00, 0x00, 0xA1, 0x01, 0x00, 0x02, 0xC9,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] add support for end port selection
       [not found] ` <4BA6391A.7020608-smomgflXvOZWk0Htik3J/w@public.gmane.org>
                     ` (2 preceding siblings ...)
  2010-03-21 15:23   ` [PATCH 3/4] set PartitionCap and PartitionEnforcementCap to be 32 Doron Shoham
@ 2010-03-21 15:24   ` Doron Shoham
  3 siblings, 0 replies; 5+ messages in thread
From: Doron Shoham @ 2010-03-21 15:24 UTC (permalink / raw)
  To: sashak-smomgflXvOZWk0Htik3J/w; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA

add support for end port selection instead
of using only the first port.

Signed-off-by: Doron Shoham <dorons-smomgflXvOZWk0Htik3J/w@public.gmane.org>
---
 ibsim/ibsim.c         |   29 +++++
 umad2sim/sim_client.c |   49 +++++++-
 umad2sim/sim_client.h |    6 +-
 umad2sim/umad2sim.c   |  332 +++++++++++++++++++++++++++----------------------
 4 files changed, 259 insertions(+), 157 deletions(-)

diff --git a/ibsim/ibsim.c b/ibsim/ibsim.c
index 3cb97e4..f59257d 100644
--- a/ibsim/ibsim.c
+++ b/ibsim/ibsim.c
@@ -289,6 +289,31 @@ static int sim_ctl_get_port(Client * cl, struct sim_ctl * ctl)
 	return 0;
 }
 
+static int sim_ctl_set_port(Client *cl, struct sim_ctl *ctl)
+{
+	int portnum = ctl->data[0];
+	Node *node;
+
+	if (!(node = find_node(cl->nodeid)) &&
+			!(node = find_node_by_desc(cl->nodeid))) {
+		IBWARN("client %d attempt to set port to unknown host"
+				" \"%s\"", cl->id, cl->nodeid);
+		ctl->type = SIM_CTL_ERROR;
+		return -1;
+	}
+	if (portnum < 0 || portnum > node->numports) {
+		IBWARN("client %d attempt to set invalid port number %d",
+				cl->id, portnum);
+		ctl->type = SIM_CTL_ERROR;
+		return -1;
+	}
+	cl->port = node_get_port(node, portnum);
+	VERB("Setting port %d to client %d at node \"%s\" port 0x%" PRIx64,
+			portnum, cl->id, node->nodeid, cl->port->portguid);
+	return 0;
+}
+
+
 static int sim_ctl_get_gid(Client * cl, struct sim_ctl * ctl)
 {
 	char *gid = (void *)ctl->data;
@@ -458,6 +483,10 @@ static int sim_ctl(int fd)
 		sim_ctl_get_pkeys(cl, &ctl);
 		break;
 
+	case SIM_CTL_SET_PORT:
+		sim_ctl_set_port(cl, &ctl);
+		break;
+
 	default:
 	case SIM_CTL_ERROR:
 		IBWARN("bad ctl pkt type %d", ctl.type);
diff --git a/umad2sim/sim_client.c b/umad2sim/sim_client.c
index eb42a7c..ac8526c 100644
--- a/umad2sim/sim_client.c
+++ b/umad2sim/sim_client.c
@@ -61,7 +61,7 @@
 static unsigned int remote_mode = 0;
 static char* socket_basename;
 
-static int sim_ctl(struct sim_client *sc, int type, void *data, int len)
+int sim_ctl(struct sim_client *sc, int type, void *data, int len)
 {
 	struct sim_ctl ctl;
 
@@ -284,6 +284,10 @@ int sim_client_set_sm(struct sim_client *sc, unsigned issm)
 int sim_client_init(struct sim_client *sc)
 {
 	char *nodeid;
+	int i, startport, endport;
+	uint8_t numports = 1, nodetype;
+	uint8_t *portinfo;
+	uint16_t *pkeys;
 
 	nodeid = getenv("SIM_HOST");
 	if (sim_init(sc, nodeid) < 0)
@@ -295,12 +299,43 @@ int sim_client_init(struct sim_client *sc)
 		    sizeof(sc->nodeinfo)) < 0)
 		goto _exit;
 
-	sc->portinfo[0] = 0;	// portno requested
-	if (sim_ctl(sc, SIM_CTL_GET_PORTINFO, sc->portinfo,
-		    sizeof(sc->portinfo)) < 0)
-		goto _exit;
-	if (sim_ctl(sc, SIM_CTL_GET_PKEYS, sc->pkeys, sizeof(sc->pkeys)) < 0)
+	nodetype = mad_get_field(sc->nodeinfo, 0, IB_NODE_TYPE_F);
+
+	if (nodetype == IB_NODE_SWITCH) {
+		startport = 0;
+		endport = 0;
+	} else {
+		numports = mad_get_field(sc->nodeinfo, 0, IB_NODE_NPORTS_F);
+		startport = 1;
+		endport = numports;
+	}
+
+	/*
+	 * portinfo and pkeys size x number of ports starting at 0
+	 * for Ca we allocate entry 0 just for compatibility with Switch node
+	 */
+	if (nodetype == IB_NODE_SWITCH) {
+		sc->portinfo = malloc(64);
+		sc->pkeys = malloc(64);
+	} else {
+		sc->portinfo = malloc(64 * (numports + 1));
+		sc->pkeys = malloc(64 * (numports + 1));
+	}
+
+	if (!sc->portinfo || !sc->pkeys)
 		goto _exit;
+	/* loop through end ports */
+	for (i = startport; i <= endport ; i++) {
+		portinfo = sc->portinfo + 64 * i;
+		*portinfo = i;
+		if (sim_ctl(sc, SIM_CTL_GET_PORTINFO, portinfo, 64) < 0)
+			goto _exit;
+		pkeys = sc->pkeys + 64 * i;
+		*pkeys = i;
+		if (sim_ctl(sc, SIM_CTL_GET_PKEYS, pkeys, 64) < 0)
+			goto _exit;
+	}
+
 	if (getenv("SIM_SET_ISSM"))
 		sim_client_set_sm(sc, 1);
 	return 0;
@@ -314,4 +349,6 @@ void sim_client_exit(struct sim_client *sc)
 {
 	sim_disconnect(sc);
 	sc->fd_ctl = sc->fd_pktin = sc->fd_pktout = -1;
+	free(sc->portinfo);
+	free(sc->pkeys);
 }
diff --git a/umad2sim/sim_client.h b/umad2sim/sim_client.h
index 80ed442..01d0939 100644
--- a/umad2sim/sim_client.h
+++ b/umad2sim/sim_client.h
@@ -37,13 +37,15 @@
 
 #include <ibsim.h>
 
+#define MAX_PORTS 8
+
 struct sim_client {
 	int clientid;
 	int fd_pktin, fd_pktout, fd_ctl;
 	struct sim_vendor vendor;
 	uint8_t nodeinfo[64];
-	uint8_t portinfo[64];
-	uint16_t pkeys[SIM_CTL_MAX_DATA/sizeof(uint16_t)];
+	uint8_t *portinfo;
+	uint16_t *pkeys;
 };
 
 extern int sim_client_set_sm(struct sim_client *sc, unsigned issm);
diff --git a/umad2sim/umad2sim.c b/umad2sim/umad2sim.c
index 55440ec..8c1050e 100644
--- a/umad2sim/umad2sim.c
+++ b/umad2sim/umad2sim.c
@@ -64,6 +64,7 @@
 #define ERROR(fmt...) fprintf(stderr, "ERR: " fmt)
 
 #define arrsize(a) (sizeof(a)/sizeof(a[0]))
+extern int sim_ctl(struct sim_client *, int, void *, int);
 
 struct ib_user_mad_reg_req {
 	uint32_t id;
@@ -79,7 +80,7 @@ struct umad2sim_dev {
 	int fd;
 	unsigned num;
 	char name[32];
-	uint8_t port;
+	int umadport[MAX_PORTS];
 	struct sim_client sim_client;
 	unsigned agent_idx[256];
 	struct ib_user_mad_reg_req agents[32];
@@ -186,7 +187,13 @@ static int dev_sysfs_create(struct umad2sim_dev *dev)
 	struct sim_client *sc = &dev->sim_client;
 	char *str;
 	uint8_t *portinfo;
-	int i;
+	uint16_t *pkeys;
+	int i, p;
+	char *ports_path_end;
+	int startport = 0, endport = 0, offset = 0;
+	int portnum;
+	uint8_t numports, nodetype;
+	char name[8];
 
 	/* /sys/class/infiniband_mad/abi_version */
 	snprintf(path, sizeof(path), "%s", sysfs_infiniband_mad_dir);
@@ -211,7 +218,6 @@ static int dev_sysfs_create(struct umad2sim_dev *dev)
 
 	/* /sys/class/infiniband/mthca0/fw_ver */
 	file_printf(path, SYS_CA_FW_VERS, "%llx\n", sc->vendor.fw_ver);
-	//file_printf(path, SYS_CA_FW_VERS, "3.2.2\n");
 
 	/* /sys/class/infiniband/mthca0/hw_rev */
 	file_printf(path, SYS_CA_HW_VERS, "%x\n", sc->vendor.hw_ver);
@@ -239,137 +245,154 @@ static int dev_sysfs_create(struct umad2sim_dev *dev)
 	strncat(path, "/ports", sizeof(path) - 1);
 	make_path(path);
 
-	portinfo = sc->portinfo;
-
-	/* /sys/class/infiniband/mthca0/ports/1/ */
-	val = mad_get_field(portinfo, 0, IB_PORT_LOCAL_PORT_F);
-	snprintf(path + strlen(path), sizeof(path) - strlen(path), "/%u", val);
-	make_path(path);
-
-	/* /sys/class/infiniband/mthca0/ports/1/lid_mask_count */
-	val = mad_get_field(portinfo, 0, IB_PORT_LMC_F);
-	file_printf(path, SYS_PORT_LMC, "%d", val);
-
-	/* /sys/class/infiniband/mthca0/ports/1/sm_lid */
-	val = mad_get_field(portinfo, 0, IB_PORT_SMLID_F);
-	file_printf(path, SYS_PORT_SMLID, "0x%x", val);
-
-	/* /sys/class/infiniband/mthca0/ports/1/sm_sl */
-	val = mad_get_field(portinfo, 0, IB_PORT_SMSL_F);
-	file_printf(path, SYS_PORT_SMSL, "%d", val);
-
-	/* /sys/class/infiniband/mthca0/ports/1/lid */
-	val = mad_get_field(portinfo, 0, IB_PORT_LID_F);
-	file_printf(path, SYS_PORT_LID, "0x%x", val);
-
-	/* /sys/class/infiniband/mthca0/ports/1/state */
-	val = mad_get_field(portinfo, 0, IB_PORT_STATE_F);
-	if (val == 0)
-		str = "NOP";
-	else if (val == 1)
-		str = "DOWN";
-	else if (val == 2)
-		str = "INIT";
-	else if (val == 3)
-		str = "ARMED";
-	else if (val == 4)
-		str = "ACTIVE";
-	else if (val == 5)
-		str = "ACTIVE_DEFER";
-	else
-		str = "<unknown>";
-	file_printf(path, SYS_PORT_STATE, "%d: %s\n", val, str);
-
-	/* /sys/class/infiniband/mthca0/ports/1/phys_state */
-	val = mad_get_field(portinfo, 0, IB_PORT_PHYS_STATE_F);
-	if (val == 1)
-		str = "Sleep";
-	else if (val == 2)
-		str = "Polling";
-	else if (val == 3)
-		str = "Disabled";
-	else if (val == 4)
-		str = "PortConfigurationTraining";
-	else if (val == 5)
-		str = "LinkUp";
-	else if (val == 6)
-		str = "LinkErrorRecovery";
-	else if (val == 7)
-		str = "Phy Test";
-	else
-		str = "<unknown>";
-	file_printf(path, SYS_PORT_PHY_STATE, "%d: %s\n", val, str);
-
-	/* /sys/class/infiniband/mthca0/ports/1/rate */
-	val = mad_get_field(portinfo, 0, IB_PORT_LINK_WIDTH_ACTIVE_F);
-	speed = mad_get_field(portinfo, 0, IB_PORT_LINK_SPEED_ACTIVE_F);
-	if (val == 1)
-		val = 1;
-	else if (val == 2)
-		val = 4;
-	else if (val == 4)
-		val = 8;
-	else if (val == 8)
-		val = 12;
-	else
-		val = 0;
-	if (speed == 2)
-		str = " DDR";
-	else if (speed == 4)
-		str = " QDR";
-	else
-		str = "";
-	file_printf(path, SYS_PORT_RATE, "%d%s Gb/sec (%dX%s)\n",
-		    (val * speed * 25) / 10,
-		    (val * speed * 25) % 10 ? ".5" : "", val, str);
-
-	/* /sys/class/infiniband/mthca0/ports/1/cap_mask */
-	val = mad_get_field(portinfo, 0, IB_PORT_CAPMASK_F);
-	file_printf(path, SYS_PORT_CAPMASK, "0x%08x", val);
-
-	/* /sys/class/infiniband/mthca0/ports/1/gids/0 */
-	str = path + strlen(path);
-	strncat(path, "/gids", sizeof(path) - 1);
-	make_path(path);
-	*str = '\0';
-	gid = mad_get_field64(portinfo, 0, IB_PORT_GID_PREFIX_F);
-	guid = mad_get_field64(sc->nodeinfo, 0, IB_NODE_GUID_F) +
-	    mad_get_field(portinfo, 0, IB_PORT_LOCAL_PORT_F);
-	file_printf(path, SYS_PORT_GID,
-		    "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
-		    (uint16_t) ((gid >> 48) & 0xffff),
-		    (uint16_t) ((gid >> 32) & 0xffff),
-		    (uint16_t) ((gid >> 16) & 0xffff),
-		    (uint16_t) ((gid >> 0) & 0xffff),
-		    (uint16_t) ((guid >> 48) & 0xffff),
-		    (uint16_t) ((guid >> 32) & 0xffff),
-		    (uint16_t) ((guid >> 16) & 0xffff),
-		    (uint16_t) ((guid >> 0) & 0xffff));
-
-	/* /sys/class/infiniband/mthca0/ports/1/pkeys/0 */
-	str = path + strlen(path);
-	strncat(path, "/pkeys", sizeof(path) - 1);
-	make_path(path);
-	for (i = 0; i < sizeof(sc->pkeys)/sizeof(sc->pkeys[0]); i++) {
-		char name[8];
-		snprintf(name, sizeof(name), "%u", i);
-		file_printf(path, name, "0x%04x\n", ntohs(sc->pkeys[i]));
+	numports = mad_get_field(sc->nodeinfo, 0, IB_NODE_NPORTS_F);
+	nodetype = mad_get_field(sc->nodeinfo, 0, IB_NODE_TYPE_F);
+	if (nodetype != IB_NODE_SWITCH) {
+		offset = 1;
+		endport = numports - 1;
+		if (endport > MAX_PORTS)
+			endport = MAX_PORTS;
 	}
-	*str = '\0';
 
-	/* /sys/class/infiniband_mad/umad0/ */
-	snprintf(path, sizeof(path), "%s/umad%u", sysfs_infiniband_mad_dir,
-		 dev->num);
-	make_path(path);
-	file_printf(path, SYS_IB_MAD_DEV, "%s\n", dev->name);
-	file_printf(path, SYS_IB_MAD_PORT, "%d\n", dev->port);
+	ports_path_end = path + strlen(path);
+	/* loop through end ports */
+	for (p = startport; p <= endport; p++) {
+		portnum = p + offset;
+		portinfo = sc->portinfo + 64 * portnum;
+
+		/* /sys/class/infiniband/mthca0/ports/<n>/ */
+		snprintf(path + strlen(path), sizeof(path) - strlen(path), "/%u", portnum);
+		make_path(path);
+
+		/* /sys/class/infiniband/mthca0/ports/<n>/lid_mask_count */
+		val = mad_get_field(portinfo, 0, IB_PORT_LMC_F);
+		file_printf(path, SYS_PORT_LMC, "%d", val);
+
+		/* /sys/class/infiniband/mthca0/ports/<n>/sm_lid */
+		val = mad_get_field(portinfo, 0, IB_PORT_SMLID_F);
+		file_printf(path, SYS_PORT_SMLID, "0x%x", val);
+
+		/* /sys/class/infiniband/mthca0/ports/<n>/sm_sl */
+		val = mad_get_field(portinfo, 0, IB_PORT_SMSL_F);
+		file_printf(path, SYS_PORT_SMSL, "%d", val);
+
+		/* /sys/class/infiniband/mthca0/ports/<n>/lid */
+		val = mad_get_field(portinfo, 0, IB_PORT_LID_F);
+		file_printf(path, SYS_PORT_LID, "0x%x", val);
+
+		/* /sys/class/infiniband/mthca0/ports/<n>/state */
+		val = mad_get_field(portinfo, 0, IB_PORT_STATE_F);
+		if (val == 0)
+			str = "NOP";
+		else if (val == 1)
+			str = "DOWN";
+		else if (val == 2)
+			str = "INIT";
+		else if (val == 3)
+			str = "ARMED";
+		else if (val == 4)
+			str = "ACTIVE";
+		else if (val == 5)
+			str = "ACTIVE_DEFER";
+		else
+			str = "<unknown>";
+		file_printf(path, SYS_PORT_STATE, "%d: %s\n", val, str);
+
+		/* /sys/class/infiniband/mthca0/ports/<n>/phys_state */
+		val = mad_get_field(portinfo, 0, IB_PORT_PHYS_STATE_F);
+		if (val == 1)
+			str = "Sleep";
+		else if (val == 2)
+			str = "Polling";
+		else if (val == 3)
+			str = "Disabled";
+		else if (val == 4)
+			str = "PortConfigurationTraining";
+		else if (val == 5)
+			str = "LinkUp";
+		else if (val == 6)
+			str = "LinkErrorRecovery";
+		else if (val == 7)
+			str = "Phy Test";
+		else
+			str = "<unknown>";
+		file_printf(path, SYS_PORT_PHY_STATE, "%d: %s\n", val, str);
+
+		/* /sys/class/infiniband/mthca0/ports/<n>/rate */
+		val = mad_get_field(portinfo, 0, IB_PORT_LINK_WIDTH_ACTIVE_F);
+		speed = mad_get_field(portinfo, 0, IB_PORT_LINK_SPEED_ACTIVE_F);
+		if (val == 1)
+			val = 1;
+		else if (val == 2)
+			val = 4;
+		else if (val == 4)
+			val = 8;
+		else if (val == 8)
+			val = 12;
+		else
+			val = 0;
+		if (speed == 2)
+			str = " DDR";
+		else if (speed == 4)
+			str = " QDR";
+		else
+			str = "";
+		file_printf(path, SYS_PORT_RATE, "%d%s Gb/sec (%dX%s)\n",
+				(val * speed * 25) / 10,
+				(val * speed * 25) % 10 ? ".5" : "", val, str);
+
+		/* /sys/class/infiniband/mthca0/ports/<n>/cap_mask */
+		val = mad_get_field(portinfo, 0, IB_PORT_CAPMASK_F);
+		file_printf(path, SYS_PORT_CAPMASK, "0x%08x", val);
+
+		/* /sys/class/infiniband/mthca0/ports/<n>/gids/0 */
+		str = path + strlen(path);
+		strncat(path, "/gids", sizeof(path) - 1);
+		make_path(path);
+		*str = '\0';
+		gid = mad_get_field64(portinfo, 0, IB_PORT_GID_PREFIX_F);
+		guid = mad_get_field64(sc->nodeinfo, 0, IB_NODE_GUID_F) + portnum;
+		file_printf(path, SYS_PORT_GID,
+				"%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
+				(uint16_t) ((gid >> 48) & 0xffff),
+				(uint16_t) ((gid >> 32) & 0xffff),
+				(uint16_t) ((gid >> 16) & 0xffff),
+				(uint16_t) ((gid >> 0) & 0xffff),
+				(uint16_t) ((guid >> 48) & 0xffff),
+				(uint16_t) ((guid >> 32) & 0xffff),
+				(uint16_t) ((guid >> 16) & 0xffff),
+				(uint16_t) ((guid >> 0) & 0xffff));
+
+		/* /sys/class/infiniband/mthca0/ports/<n>/pkeys/0 */
+		str = path + strlen(path);
+		strncat(path, "/pkeys", sizeof(path) - 1);
+		make_path(path);
+		pkeys = sc->pkeys + 64 * portnum;
+		for (i = 0; i < 32; i++) {
+			snprintf(name, sizeof(name), "%u", i);
+			file_printf(path, name, "0x%04x\n", ntohs(pkeys[i]));
+		}
+		*str = '\0';
+		*ports_path_end = '\0';
+	}
 
-	/* /sys/class/infiniband_mad/issm0/ */
-	snprintf(path, sizeof(path), "%s/issm%u", sysfs_infiniband_mad_dir,
-		 dev->num);
-	make_path(path);
-	file_printf(path, SYS_IB_MAD_DEV, "%s\n", dev->name);
-	file_printf(path, SYS_IB_MAD_PORT, "%d\n", dev->port);
+	for (p = startport; p <= endport; p++) {
+		portnum = p + offset;
+		/* /sys/class/infiniband_mad/umad<n>/ */
+		snprintf(path, sizeof(path), "%s/umad%u",
+				sysfs_infiniband_mad_dir, p);
+		make_path(path);
+		file_printf(path, SYS_IB_MAD_DEV, "%s\n", dev->name);
+		file_printf(path, SYS_IB_MAD_PORT, "%d\n", portnum);
+		dev->umadport[p] = portnum;
+
+		/* /sys/class/infiniband_mad/issm<n>/ */
+		snprintf(path, sizeof(path), "%s/issm%u",
+				sysfs_infiniband_mad_dir, p);
+		make_path(path);
+		file_printf(path, SYS_IB_MAD_DEV, "%s\n", dev->name);
+		file_printf(path, SYS_IB_MAD_PORT, "%d\n", portnum);
+	}
 
 	return 0;
 }
@@ -571,8 +594,6 @@ static struct umad2sim_dev *umad2sim_dev_create(unsigned num, const char *name)
 	if (sim_client_init(&dev->sim_client) < 0)
 		goto _error;
 
-	dev->port = mad_get_field(&dev->sim_client.portinfo, 0,
-				  IB_PORT_LOCAL_PORT_F);
 	for (i = 0; i < arrsize(dev->agents); i++)
 		dev->agents[i].id = (uint32_t)(-1);
 	for (i = 0; i < arrsize(dev->agent_idx); i++)
@@ -724,20 +745,24 @@ int scandir(const char *path, struct dirent ***namelist,
 	return real_scandir(path, namelist, filter, compar);
 }
 
+void __attribute__ ((constructor)) my_init(void)
+{
+	umad2sim_init();
+}
+
 int open(const char *path, int flags, ...)
 {
 	struct umad2sim_dev *dev;
 	va_list args;
 	mode_t mode = 0;
-	unsigned i;
+	char portno;
+	int offset;
+	int umadnum;
+	int portnum;
+	static char umad_dir[] = UMAD_DEV_DIR"/umad";
 
 	CHECK_INIT();
 
-	if (!umad2sim_initialized && (is_sysfs_file(path) ||
-				      !strncmp(path, umad_dev_dir,
-					       strlen(umad_dev_dir))))
-		umad2sim_init();
-
 	DEBUG("libs_wrap: open: %s...\n", path);
 
 	if (flags & O_CREAT) {
@@ -752,16 +777,25 @@ int open(const char *path, int flags, ...)
 		return real_open(new_path, flags, mode);
 	}
 
-	for (i = 0; i < arrsize(devices); i++) {
-		if (!(dev = devices[i]))
-			continue;
-		if (!strncmp(path, dev->umad_path, sizeof(dev->umad_path))) {
-			return 1024 + i;
-		}
-		if (!strncmp(path, dev->issm_path, sizeof(dev->issm_path))) {
-			sim_client_set_sm(&dev->sim_client, 1);
-			return 2048 + i;
-		}
+	dev = devices[0];
+	offset = strlen(umad_dir);
+	if (!strncmp(path, umad_dir, offset)) {
+		strcpy(&portno, path + offset);
+		/* update portnum */
+		umadnum = atoi(&portno);
+		portnum = dev->umadport[umadnum];
+		sim_ctl(&dev->sim_client, SIM_CTL_SET_PORT, &portnum, sizeof(portnum));
+
+		snprintf(dev->umad_path, sizeof(dev->umad_path), "%s/%s%u",
+				 umad_dev_dir, "umad", umadnum);
+		snprintf(dev->issm_path, sizeof(dev->issm_path), "%s/%s%u",
+			 umad_dev_dir, "issm", umadnum);
+	}
+	if (!strncmp(path, dev->umad_path, sizeof(dev->umad_path)))
+		return 1024;
+	if (!strncmp(path, dev->issm_path, sizeof(dev->issm_path))) {
+		sim_client_set_sm(&dev->sim_client, 1);
+		return 2048;
 	}
 
 	return real_open(path, flags, mode);
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-03-21 15:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-21 15:19 [PATCH 0/4] bug fixes and supporting new functionalities Doron Shoham
     [not found] ` <4BA6391A.7020608-smomgflXvOZWk0Htik3J/w@public.gmane.org>
2010-03-21 15:20   ` [PATCH 1/4] sim_ctl_get_portinfo: Doron Shoham
2010-03-21 15:21   ` [PATCH 2/4] sim_ctl_get_pkeys Doron Shoham
2010-03-21 15:23   ` [PATCH 3/4] set PartitionCap and PartitionEnforcementCap to be 32 Doron Shoham
2010-03-21 15:24   ` [PATCH 4/4] add support for end port selection Doron Shoham

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.