[ofa-general] [PATCH] Encode agent id in request transaction id.

Sasha Khapyorsky sashak at voltaire.com
Sat Nov 1 12:58:07 PDT 2008


For requests agent id will be encoded as bits 32-47 into MAD transaction
id (ibsim will use now higher bits (48-63) for client id encoding). So
response's agent id will be decoded from MAD and not resolved by
management class value. This is in order to simulate kernel's user_mad
layer behavior.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 ibsim/ibsim.c       |    2 +-
 ibsim/sim_mad.c     |    2 +-
 umad2sim/umad2sim.c |   13 ++++++++++++-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/ibsim/ibsim.c b/ibsim/ibsim.c
index c050be1..149b6b9 100644
--- a/ibsim/ibsim.c
+++ b/ibsim/ibsim.c
@@ -668,7 +668,7 @@ int disconnect_client(int id)
 
 static Client *client_by_trid(Port *port, uint64_t trid)
 {
-	unsigned i = (unsigned)(trid >> 32);
+	unsigned i = (unsigned)(trid >> 48);
 	if (i < IBSIM_MAX_CLIENTS && clients[i].pid &&
 	    clients[i].port->portguid == port->portguid)
 		return &clients[i];
diff --git a/ibsim/sim_mad.c b/ibsim/sim_mad.c
index fbe81aa..c49f4cc 100644
--- a/ibsim/sim_mad.c
+++ b/ibsim/sim_mad.c
@@ -108,7 +108,7 @@ static uint64_t update_trid(uint8_t *mad, unsigned response, Client *cl)
 {
 	uint64_t trid = mad_get_field64(mad, 0, IB_MAD_TRID_F);
 	if (!response) {
-		trid = (trid&0xffffffffULL)|(((uint64_t)cl->id)<<32);
+		trid = (trid&0xffffffffffffULL)|(((uint64_t)cl->id)<<48);
 		mad_set_field64(mad, 0, IB_MAD_TRID_F, trid);
 	}
 	return trid;
diff --git a/umad2sim/umad2sim.c b/umad2sim/umad2sim.c
index 2b37a8d..f896540 100644
--- a/umad2sim/umad2sim.c
+++ b/umad2sim/umad2sim.c
@@ -406,7 +406,12 @@ static ssize_t umad2sim_read(struct umad2sim_dev *dev, void *buf, size_t count)
 		mgmt_class = 0;
 	}
 
-	umad->agent_id = dev->agent_idx[mgmt_class];
+	if (mad_get_field(req.mad, 0, IB_MAD_RESPONSE_F)) {
+		uint64_t trid = mad_get_field64(req.mad, 0, IB_MAD_TRID_F);
+		umad->agent_id = (trid >> 32) & 0xffff;
+	} else
+		umad->agent_id = dev->agent_idx[mgmt_class];
+
 	umad->status = ntohl(req.status);
 	umad->timeout_ms = 0;
 	umad->retries = 0;
@@ -476,6 +481,12 @@ static ssize_t umad2sim_write(struct umad2sim_dev *dev,
 
 	req.length = htonll(cnt);
 
+	if (!mad_get_field(req.mad, 0, IB_MAD_RESPONSE_F)) {
+		uint64_t trid = mad_get_field64(req.mad, 0, IB_MAD_TRID_F);
+		trid = (trid&0xffff0000ffffffffULL)|(((uint64_t)umad->agent_id)<<32);
+		mad_set_field64(req.mad, 0, IB_MAD_TRID_F, trid);
+	}
+
 	cnt = write(dev->sim_client.fd_pktout, (void *)&req, sizeof(req));
 	if (cnt < 0) {
 		ERROR("umad2sim_write: cannot write\n");
-- 
1.6.0.3.517.g759a




More information about the general mailing list