[openib-general] ib_smi: More changes for better code clarity
Hal Rosenstock
Mon Oct 18 08:27:02 PDT 2004
ib_smi: More changes for better code clarity
Index: ib_smi.c
===================================================================
--- ib_smi.c (revision 1012)
+++ ib_smi.c (working copy)
@@ -126,7 +126,7 @@
{
case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
return smi_handle_dr_smp_send(mad_agent, smp, port_num);
- default: /* LR SM or PerfMgmt classes */
+ default: /* LR SM class */
return 1;
}
}
@@ -238,7 +238,7 @@
case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
return smi_handle_dr_smp_recv(mad_agent, smp,
port_num, phys_port_cnt);
- default: /* LR SM or PerfMgmt classes */
+ default: /* LR SM class */
return 1;
}
}
@@ -290,7 +290,7 @@
{
case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
return smi_check_forward_dr_smp(mad_agent, smp);
- default: /* LR SM or PerfMgmt classes */
+ default: /* LR SM class */
return 1;
}
}
@@ -305,9 +305,9 @@
slid, mad, mad_response);
}
-void mad_send(struct ib_mad_agent *mad_agent,
- struct ib_mad *mad,
- struct ib_mad_recv_wc *mad_recv_wc)
+void agent_mad_send(struct ib_mad_agent *mad_agent,
+ struct ib_mad *mad,
+ struct ib_mad_recv_wc *mad_recv_wc)
{
struct ib_agent_port_private *entry, *port_priv = NULL;
struct ib_agent_send_wr *agent_send_wr;
@@ -330,7 +330,7 @@
}
spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
if (!port_priv) {
- printk(KERN_ERR SPFX "mad_send: no matching MAD agent 0x%x\n",
+ printk(KERN_ERR SPFX "agent_mad_send: no matching MAD agent 0x%x\n",
(unsigned int)mad_agent);
return;
}
@@ -428,7 +428,7 @@
kfree(smp_response);
return 0;
}
- mad_send(mad_agent, smp_response, mad_recv_wc);
+ agent_mad_send(mad_agent, smp_response, mad_recv_wc);
} else
kfree(smp_response);
return 1;
@@ -438,23 +438,59 @@
return 1;
}
-int smi_recv_smp(struct ib_mad_agent *mad_agent,
- struct ib_smp *smp,
+int mad_response(struct ib_mad_agent *mad_agent,
+ struct ib_mad *mad,
struct ib_mad_recv_wc *mad_recv_wc,
- int phys_port_cnt)
+ u16 slid)
{
- if (!smi_handle_smp_recv(mad_agent, smp,
- mad_agent->port_num, phys_port_cnt)) {
- /* SMI failed receive */
+ struct ib_mad *response;
+ int ret;
+
+ response = kmalloc(sizeof(struct ib_mad), GFP_KERNEL);
+ if (!response)
return 0;
- }
- if (smi_check_forward_smp(mad_agent, smp)) {
- smi_send_smp(mad_agent, smp, mad_recv_wc,
- mad_recv_wc->wc->slid, phys_port_cnt);
+ ret = mad_process_local(mad_agent, mad, response, slid);
+ if (ret & IB_MAD_RESULT_SUCCESS) {
+ agent_mad_send(mad_agent, response, mad_recv_wc);
+ } else
+ kfree(response);
+ return 1;
+}
+
+int agent_recv_mad(struct ib_mad_agent *mad_agent,
+ struct ib_mad *mad,
+ struct ib_mad_recv_wc *mad_recv_wc,
+ int phys_port_cnt)
+{
+ /* SM Directed Route or LID Routed class */
+ if (mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE ||
+ mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED) {
+ if (!smi_handle_smp_recv(mad_agent, (struct ib_smp *)mad,
+ mad_agent->port_num, phys_port_cnt)) {
+ /* SMI failed receive */
+ return 0;
+ }
+
+ if (smi_check_forward_smp(mad_agent, (struct ib_smp *)mad)) {
+ smi_send_smp(mad_agent, (struct ib_smp *)mad,
+ mad_recv_wc,
+ mad_recv_wc->wc->slid,
+ phys_port_cnt);
+ return 0;
+ }
+
+ } else {
+ /* PerfMgmt class */
+ if (mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT) {
+ mad_response(mad_agent, mad, mad_recv_wc,
+ mad_recv_wc->wc->slid);
+ } else {
+ printk(KERN_ERR "agent_recv_mad: Unexpected mgmt class 0x%x
received\n", mad->mad_hdr.mgmt_class);
+ }
return 0;
}
-
+
/* Complete receive up stack */
return 1;
}
@@ -538,9 +574,9 @@
(unsigned int)mad_agent);
} else {
- smi_recv_smp(mad_agent,
- (struct ib_smp *)mad_recv_wc->recv_buf->mad,
- mad_recv_wc, port_priv->phys_port_cnt);
+ agent_recv_mad(mad_agent,
+ mad_recv_wc->recv_buf->mad,
+ mad_recv_wc, port_priv->phys_port_cnt);
}
/* Free received MAD */
More information about the openib-general mailing list