Skip to content

Commit 618a3c0

Browse files
Hal RosenstockRoland Dreier
authored andcommitted
IB/mad: RMPP support for additional classes
Add RMPP support for additional management classes that support it. Also, validate RMPP is consistent with management class specified. Signed-off-by: Hal Rosenstock <halr@voltaire.com> Signed-off-by: Sean Hefty <sean.hefty@intel.com> Signed-off-by: Roland Dreier <rolandd@cisco.com>
1 parent fa9656b commit 618a3c0

File tree

4 files changed

+85
-45
lines changed

4 files changed

+85
-45
lines changed

drivers/infiniband/core/mad.c

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
227227
if (!is_vendor_oui(mad_reg_req->oui))
228228
goto error1;
229229
}
230+
/* Make sure class supplied is consistent with RMPP */
231+
if (ib_is_mad_class_rmpp(mad_reg_req->mgmt_class)) {
232+
if (!rmpp_version)
233+
goto error1;
234+
} else {
235+
if (rmpp_version)
236+
goto error1;
237+
}
230238
/* Make sure class supplied is consistent with QP type */
231239
if (qp_type == IB_QPT_SMI) {
232240
if ((mad_reg_req->mgmt_class !=
@@ -890,6 +898,35 @@ struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
890898
}
891899
EXPORT_SYMBOL(ib_create_send_mad);
892900

901+
int ib_get_mad_data_offset(u8 mgmt_class)
902+
{
903+
if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM)
904+
return IB_MGMT_SA_HDR;
905+
else if ((mgmt_class == IB_MGMT_CLASS_DEVICE_MGMT) ||
906+
(mgmt_class == IB_MGMT_CLASS_DEVICE_ADM) ||
907+
(mgmt_class == IB_MGMT_CLASS_BIS))
908+
return IB_MGMT_DEVICE_HDR;
909+
else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
910+
(mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END))
911+
return IB_MGMT_VENDOR_HDR;
912+
else
913+
return IB_MGMT_MAD_HDR;
914+
}
915+
EXPORT_SYMBOL(ib_get_mad_data_offset);
916+
917+
int ib_is_mad_class_rmpp(u8 mgmt_class)
918+
{
919+
if ((mgmt_class == IB_MGMT_CLASS_SUBN_ADM) ||
920+
(mgmt_class == IB_MGMT_CLASS_DEVICE_MGMT) ||
921+
(mgmt_class == IB_MGMT_CLASS_DEVICE_ADM) ||
922+
(mgmt_class == IB_MGMT_CLASS_BIS) ||
923+
((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
924+
(mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END)))
925+
return 1;
926+
return 0;
927+
}
928+
EXPORT_SYMBOL(ib_is_mad_class_rmpp);
929+
893930
void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num)
894931
{
895932
struct ib_mad_send_wr_private *mad_send_wr;
@@ -1022,6 +1059,13 @@ int ib_post_send_mad(struct ib_mad_send_buf *send_buf,
10221059
goto error;
10231060
}
10241061

1062+
if (!ib_is_mad_class_rmpp(((struct ib_mad_hdr *) send_buf->mad)->mgmt_class)) {
1063+
if (mad_agent_priv->agent.rmpp_version) {
1064+
ret = -EINVAL;
1065+
goto error;
1066+
}
1067+
}
1068+
10251069
/*
10261070
* Save pointer to next work request to post in case the
10271071
* current one completes, and the user modifies the work
@@ -2454,11 +2498,11 @@ static int ib_mad_post_receive_mads(struct ib_mad_qp_info *qp_info,
24542498
}
24552499
}
24562500
sg_list.addr = dma_map_single(qp_info->port_priv->
2457-
device->dma_device,
2458-
&mad_priv->grh,
2459-
sizeof *mad_priv -
2460-
sizeof mad_priv->header,
2461-
DMA_FROM_DEVICE);
2501+
device->dma_device,
2502+
&mad_priv->grh,
2503+
sizeof *mad_priv -
2504+
sizeof mad_priv->header,
2505+
DMA_FROM_DEVICE);
24622506
pci_unmap_addr_set(&mad_priv->header, mapping, sg_list.addr);
24632507
recv_wr.wr_id = (unsigned long)&mad_priv->header.mad_list;
24642508
mad_priv->header.mad_list.mad_queue = recv_queue;

drivers/infiniband/core/mad_rmpp.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2005 Intel Inc. All rights reserved.
3-
* Copyright (c) 2005 Voltaire, Inc. All rights reserved.
3+
* Copyright (c) 2005-2006 Voltaire, Inc. All rights reserved.
44
*
55
* This software is available to you under a choice of one of two
66
* licenses. You may choose to be licensed under the terms of the GNU
@@ -100,17 +100,6 @@ void ib_cancel_rmpp_recvs(struct ib_mad_agent_private *agent)
100100
}
101101
}
102102

103-
static int data_offset(u8 mgmt_class)
104-
{
105-
if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM)
106-
return IB_MGMT_SA_HDR;
107-
else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
108-
(mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END))
109-
return IB_MGMT_VENDOR_HDR;
110-
else
111-
return IB_MGMT_RMPP_HDR;
112-
}
113-
114103
static void format_ack(struct ib_mad_send_buf *msg,
115104
struct ib_rmpp_mad *data,
116105
struct mad_rmpp_recv *rmpp_recv)
@@ -137,7 +126,7 @@ static void ack_recv(struct mad_rmpp_recv *rmpp_recv,
137126
struct ib_mad_send_buf *msg;
138127
int ret, hdr_len;
139128

140-
hdr_len = data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class);
129+
hdr_len = ib_get_mad_data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class);
141130
msg = ib_create_send_mad(&rmpp_recv->agent->agent, recv_wc->wc->src_qp,
142131
recv_wc->wc->pkey_index, 1, hdr_len,
143132
0, GFP_KERNEL);
@@ -163,7 +152,7 @@ static struct ib_mad_send_buf *alloc_response_msg(struct ib_mad_agent *agent,
163152
if (IS_ERR(ah))
164153
return (void *) ah;
165154

166-
hdr_len = data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class);
155+
hdr_len = ib_get_mad_data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class);
167156
msg = ib_create_send_mad(agent, recv_wc->wc->src_qp,
168157
recv_wc->wc->pkey_index, 1,
169158
hdr_len, 0, GFP_KERNEL);
@@ -408,7 +397,7 @@ static inline int get_mad_len(struct mad_rmpp_recv *rmpp_recv)
408397

409398
rmpp_mad = (struct ib_rmpp_mad *)rmpp_recv->cur_seg_buf->mad;
410399

411-
hdr_size = data_offset(rmpp_mad->mad_hdr.mgmt_class);
400+
hdr_size = ib_get_mad_data_offset(rmpp_mad->mad_hdr.mgmt_class);
412401
data_size = sizeof(struct ib_rmpp_mad) - hdr_size;
413402
pad = IB_MGMT_RMPP_DATA - be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin);
414403
if (pad > IB_MGMT_RMPP_DATA || pad < 0)

drivers/infiniband/core/user_mad.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,6 @@ static int queue_packet(struct ib_umad_file *file,
177177
return ret;
178178
}
179179

180-
static int data_offset(u8 mgmt_class)
181-
{
182-
if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM)
183-
return IB_MGMT_SA_HDR;
184-
else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
185-
(mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END))
186-
return IB_MGMT_VENDOR_HDR;
187-
else
188-
return IB_MGMT_RMPP_HDR;
189-
}
190-
191180
static void send_handler(struct ib_mad_agent *agent,
192181
struct ib_mad_send_wc *send_wc)
193182
{
@@ -283,7 +272,7 @@ static ssize_t copy_recv_mad(char __user *buf, struct ib_umad_packet *packet,
283272
*/
284273
return -ENOSPC;
285274
}
286-
offset = data_offset(recv_buf->mad->mad_hdr.mgmt_class);
275+
offset = ib_get_mad_data_offset(recv_buf->mad->mad_hdr.mgmt_class);
287276
max_seg_payload = sizeof (struct ib_mad) - offset;
288277

289278
for (left = packet->length - seg_payload, buf += seg_payload;
@@ -441,21 +430,14 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
441430
}
442431

443432
rmpp_mad = (struct ib_rmpp_mad *) packet->mad.data;
444-
if (rmpp_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_ADM) {
445-
hdr_len = IB_MGMT_SA_HDR;
446-
copy_offset = IB_MGMT_RMPP_HDR;
447-
rmpp_active = ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
448-
IB_MGMT_RMPP_FLAG_ACTIVE;
449-
} else if (rmpp_mad->mad_hdr.mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START &&
450-
rmpp_mad->mad_hdr.mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END) {
451-
hdr_len = IB_MGMT_VENDOR_HDR;
433+
hdr_len = ib_get_mad_data_offset(rmpp_mad->mad_hdr.mgmt_class);
434+
if (!ib_is_mad_class_rmpp(rmpp_mad->mad_hdr.mgmt_class)) {
435+
copy_offset = IB_MGMT_MAD_HDR;
436+
rmpp_active = 0;
437+
} else {
452438
copy_offset = IB_MGMT_RMPP_HDR;
453439
rmpp_active = ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
454440
IB_MGMT_RMPP_FLAG_ACTIVE;
455-
} else {
456-
hdr_len = IB_MGMT_MAD_HDR;
457-
copy_offset = IB_MGMT_MAD_HDR;
458-
rmpp_active = 0;
459441
}
460442

461443
data_len = count - sizeof (struct ib_user_mad) - hdr_len;

include/rdma/ib_mad.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004 Infinicon Corporation. All rights reserved.
44
* Copyright (c) 2004 Intel Corporation. All rights reserved.
55
* Copyright (c) 2004 Topspin Corporation. All rights reserved.
6-
* Copyright (c) 2004 Voltaire Corporation. All rights reserved.
6+
* Copyright (c) 2004-2006 Voltaire Corporation. All rights reserved.
77
*
88
* This software is available to you under a choice of one of two
99
* licenses. You may choose to be licensed under the terms of the GNU
@@ -55,6 +55,10 @@
5555
#define IB_MGMT_CLASS_DEVICE_MGMT 0x06
5656
#define IB_MGMT_CLASS_CM 0x07
5757
#define IB_MGMT_CLASS_SNMP 0x08
58+
#define IB_MGMT_CLASS_DEVICE_ADM 0x10
59+
#define IB_MGMT_CLASS_BOOT_MGMT 0x11
60+
#define IB_MGMT_CLASS_BIS 0x12
61+
#define IB_MGMT_CLASS_CONG_MGMT 0x21
5862
#define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x30
5963
#define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F
6064

@@ -117,6 +121,8 @@ enum {
117121
IB_MGMT_VENDOR_DATA = 216,
118122
IB_MGMT_SA_HDR = 56,
119123
IB_MGMT_SA_DATA = 200,
124+
IB_MGMT_DEVICE_HDR = 64,
125+
IB_MGMT_DEVICE_DATA = 192,
120126
};
121127

122128
struct ib_mad_hdr {
@@ -602,6 +608,25 @@ struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
602608
int hdr_len, int data_len,
603609
gfp_t gfp_mask);
604610

611+
/**
612+
* ib_is_mad_class_rmpp - returns whether given management class
613+
* supports RMPP.
614+
* @mgmt_class: management class
615+
*
616+
* This routine returns whether the management class supports RMPP.
617+
*/
618+
int ib_is_mad_class_rmpp(u8 mgmt_class);
619+
620+
/**
621+
* ib_get_mad_data_offset - returns the data offset for a given
622+
* management class.
623+
* @mgmt_class: management class
624+
*
625+
* This routine returns the data offset in the MAD for the management
626+
* class requested.
627+
*/
628+
int ib_get_mad_data_offset(u8 mgmt_class);
629+
605630
/**
606631
* ib_get_rmpp_segment - returns the data buffer for a given RMPP segment.
607632
* @send_buf: Previously allocated send data buffer.

0 commit comments

Comments
 (0)