IB/mad: Add final OPA MAD processing
PATCH RESEND v3 14/14 IB/mad: Add final OPA MAD processing
From: Ira Weiny <[email protected]>
For devices which support OPA MADs
1) Use previously defined SMP support functions.
2) Pass correct base version to ib_create_send_mad when processing OPA MADs.
3) Process out_mad_key_index returned by agents for a response. This is necessary because OPA SMP packets must carry a valid pkey.
4) Carry the correct segment size (OPA vs IBTA) of RMPP messages within
ib_mad_recv_wc.
5) Handle variable length OPA MADs by:
* Adjusting the 'fake' WC for locally routed SMP's to represent the proper incoming byte_len
* out_mad_size is used from the local HCA agents
1) when sending agent responses on the wire
2) when passing responses through the local_completions function
NOTE: wc.byte_len includes the GRH length and therefore is different
from the in_mad_size specified to the local HCA agents. out_mad_size should _not_ include the GRH length as it is added
---
Resent because the patch did not seem to get to the list.
Changes from V2:
Fix out_mad_pkey_index handling in ib_mad_recv_done_handler.
Previously the WC was automatically passed in to the agent_send_response. Update the WC to be used.
Changes from V1:
Use out_mad_pkey_index rather than the wc.pkey_index from the agents
This is a much cleaner interface than returning data in the in_wc which can now remain const.
Correct all opa variables to be bool type
Adjust for ib_mad_private being a flex array
drivers/infiniband/core/agent.c | 7 +- drivers/infiniband/core/agent.h | 2 +- drivers/infiniband/core/mad.c | 224 +++++++++++++++++++++++++++++++----- drivers/infiniband/core/mad_priv.h | 1 + drivers/infiniband/core/mad_rmpp.c | 20 +++- drivers/infiniband/core/user_mad.c | 19 ++- include/rdma/ib_mad.h | 8 ++ 7 files changed, 238 insertions(+), 43 deletions(-)
drivers/infiniband/core/agent.c +5 -2
@@ -80,7 +80,7 @@ ib_get_agent_port(const struct ib_device *device, int port_num)void agent_send_response (const struct ib_mad_hdr *mad_hdr,const struct ib_grh *grh,const struct ib_wc *wc,const struct ib_device *device, -int port_num,int qpn,size_t resp_mad_len) +int port_num,int qpn,size_t resp_mad_len,bool opa) {struct ib_agent_port_private *port_priv;struct ib_mad_agent *agent;
@@ -106,11 +106,14 @@ void agent_send_response(const struct ib_mad_hdr *mad_hdr, const struct ib_grh *return ; } +if (opa && mad_hdr->base_version !=OPA_MGMT_BASE_VERSION ) + resp_mad_len =IB_MGMT_MAD_SIZE ; + send_buf =ib_create_send_mad (agent, wc->src_qp, wc->pkey_index,0 ,IB_MGMT_MAD_HDR , resp_mad_len -IB_MGMT_MAD_HDR ,GFP_KERNEL , -IB_MGMT_BASE_VERSION ); + mad_hdr->base_version);if (IS_ERR (send_buf)) {dev_err (&device->dev,"ib_create_send_mad error\n" ); goto err1;
drivers/infiniband/core/agent.h +1 -1
@@ -46,6 +46,6 @@ extern int ib_agent_port_close(struct ib_device *device, int port_num);extern void agent_send_response (const struct ib_mad_hdr *mad_hdr,const struct ib_grh *grh,const struct ib_wc *wc,const struct ib_device *device, -int port_num,int qpn,size_t resp_mad_len); +int port_num,int qpn,size_t resp_mad_len,bool opa);#endif /* __AGENT_H_ */
drivers/infiniband/core/mad.c +195 -29
376 lines not on this page · raw message
drivers/infiniband/core/mad_priv.h +1 -0
@@ -148,6 +148,7 @@ struct ib_mad_local_private {struct ib_mad_private *mad_priv;struct ib_mad_agent_private *recv_mad_agent;struct ib_mad_send_wr_private *mad_send_wr; +size_t return_wc_byte_len; };struct ib_mad_mgmt_method_table {
drivers/infiniband/core/mad_rmpp.c +16 -4
@@ -1,6 +1,7 @@/* * Copyright (c) 2005 Intel Inc. All rights reserved. * Copyright (c) 2005-2006 Voltaire, Inc. All rights reserved. +* Copyright (c) 2014 Intel Corporation. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU
@@ -67,6 +68,7 @@ struct mad_rmpp_recv {u8 mgmt_class;u8 class_version;u8 method; +u8 base_version; };static inline void deref_rmpp_recv (struct mad_rmpp_recv *rmpp_recv)
@@ -318,6 +320,7 @@ create_rmpp_recv(struct ib_mad_agent_private *agent, rmpp_recv->mgmt_class = mad_hdr->mgmt_class; rmpp_recv->class_version = mad_hdr->class_version; rmpp_recv->method = mad_hdr->method; + rmpp_recv->base_version = mad_hdr->base_version;return rmpp_recv; error:kfree (rmpp_recv);
@@ -433,14 +436,23 @@ static inline int get_mad_len(struct mad_rmpp_recv *rmpp_recv) {struct ib_rmpp_mad *rmpp_mad;int hdr_size, data_size, pad; +bool opa =rdma_cap_opa_mad (rmpp_recv->agent->qp_info->port_priv->device, + rmpp_recv->agent->qp_info->port_priv->port_num); rmpp_mad = (struct ib_rmpp_mad *)rmpp_recv->cur_seg_buf->mad; hdr_size =ib_get_mad_data_offset (rmpp_mad->mad_hdr.mgmt_class); - data_size =sizeof (struct ib_rmpp_mad ) - hdr_size; - pad =IB_MGMT_RMPP_DATA -be32_to_cpu (rmpp_mad->rmpp_hdr.paylen_newwin); -if (pad >IB_MGMT_RMPP_DATA || pad <0 ) - pad =0 ; +if (opa && rmpp_recv->base_version ==OPA_MGMT_BASE_VERSION ) { + data_size =sizeof (struct opa_rmpp_mad ) - hdr_size; + pad =OPA_MGMT_RMPP_DATA -be32_to_cpu (rmpp_mad->rmpp_hdr.paylen_newwin); +if (pad >OPA_MGMT_RMPP_DATA || pad <0 ) + pad =0 ; + }else { + data_size =sizeof (struct ib_rmpp_mad ) - hdr_size; + pad =IB_MGMT_RMPP_DATA -be32_to_cpu (rmpp_mad->rmpp_hdr.paylen_newwin); +if (pad >IB_MGMT_RMPP_DATA || pad <0 ) + pad =0 ; + }return hdr_size + rmpp_recv->seg_num * data_size - pad; }
drivers/infiniband/core/user_mad.c +12 -7
@@ -262,20 +262,23 @@ static ssize_t copy_recv_mad(struct ib_umad_file *file, char __user *buf, {struct ib_mad_recv_buf *recv_buf;int left, seg_payload, offset, max_seg_payload; +size_t seg_size; -/* We need enough room to copy the first (or only) MAD segment. */ recv_buf = &packet->recv_wc->recv_buf; -if ((packet->length <=sizeof (*recv_buf->mad) && + seg_size = packet->recv_wc->mad_seg_size; + +/* We need enough room to copy the first (or only) MAD segment. */ +if ((packet->length <= seg_size && count <hdr_size (file) + packet->length) || - (packet->length >sizeof (*recv_buf->mad) && - count <hdr_size (file) +sizeof (*recv_buf->mad))) + (packet->length > seg_size && + count <hdr_size (file) + seg_size))return -EINVAL ;if (copy_to_user (buf, &packet->mad,hdr_size (file)))return -EFAULT ; buf +=hdr_size (file); - seg_payload =min_t (int, packet->length,sizeof (*recv_buf->mad)); + seg_payload =min_t (int, packet->length, seg_size);if (copy_to_user (buf, recv_buf->mad, seg_payload))return -EFAULT ;
@@ -292,7 +295,7 @@ static ssize_t copy_recv_mad(struct ib_umad_file *file, char __user *buf,return -ENOSPC ; } offset =ib_get_mad_data_offset (recv_buf->mad->mad_hdr.mgmt_class); - max_seg_payload =sizeof (struct ib_mad ) - offset; + max_seg_payload = seg_size - offset;for (left = packet->length - seg_payload, buf += seg_payload; left; left -= seg_payload, buf += seg_payload) {
@@ -450,6 +453,7 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,struct ib_rmpp_mad *rmpp_mad;__be64 *tid;int ret, data_len, hdr_len, copy_offset, rmpp_active; +u8 base_version;if (count <hdr_size (file) +IB_MGMT_RMPP_HDR )return -EINVAL ;
@@ -516,12 +520,13 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf, rmpp_active =0 ; } + base_version = ((struct ib_mad_hdr *)&packet->mad.data)->base_version; data_len = count -hdr_size (file) - hdr_len; packet->msg =ib_create_send_mad (agent,be32_to_cpu (packet->mad.hdr.qpn), packet->mad.hdr.pkey_index, rmpp_active, hdr_len, data_len,GFP_KERNEL , -IB_MGMT_BASE_VERSION ); + base_version);if (IS_ERR (packet->msg)) { ret =PTR_ERR (packet->msg); goto err_ah;
include/rdma/ib_mad.h +8 -0
@@ -199,6 +199,12 @@ struct ib_rmpp_mad {u8 data[IB_MGMT_RMPP_DATA ]; }; +struct opa_rmpp_mad { +struct ib_mad_hdr mad_hdr; +struct ib_rmpp_hdr rmpp_hdr; +u8 data[OPA_MGMT_RMPP_DATA ]; +}; +struct ib_sa_mad {struct ib_mad_hdr mad_hdr;struct ib_rmpp_hdr rmpp_hdr;
@@ -429,6 +435,7 @@ struct ib_mad_recv_buf {* @recv_buf: Specifies the location of the received data buffer(s). * @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers. * @mad_len: The length of the received MAD, without duplicated headers. +* @mad_seg_size: The size of individual MAD segments * * For received response, the wr_id contains a pointer to the ib_mad_send_buf * for the corresponding send request.
@@ -438,6 +445,7 @@ struct ib_mad_recv_wc {struct ib_mad_recv_buf recv_buf;struct list_head rmpp_list;int mad_len; +size_t mad_seg_size; };/**
Signature · 6 lines
1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html