2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2007-04-02 15:24:07 +00:00
|
|
|
* Copyright (c) 2004-2007 Voltaire, Inc. All rights reserved.
|
2005-07-27 18:45:37 +00:00
|
|
|
* Copyright (c) 2005 Intel Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved.
|
2009-09-07 15:28:48 +00:00
|
|
|
* Copyright (c) 2009 HNR Consulting. All rights reserved.
|
2015-06-10 20:16:48 +00:00
|
|
|
* Copyright (c) 2014 Intel Corporation. All rights reserved.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* General Public License (GPL) Version 2, available from the file
|
|
|
|
* COPYING in the main directory of this source tree, or the
|
|
|
|
* OpenIB.org BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
2014-08-08 23:00:53 +00:00
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/dma-mapping.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2011-05-27 19:35:46 +00:00
|
|
|
#include <linux/module.h>
|
2006-06-18 03:37:34 +00:00
|
|
|
#include <rdma/ib_cache.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "mad_priv.h"
|
2005-07-27 18:45:37 +00:00
|
|
|
#include "mad_rmpp.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "smi.h"
|
2015-06-10 20:16:48 +00:00
|
|
|
#include "opa_smi.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "agent.h"
|
|
|
|
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
|
|
MODULE_DESCRIPTION("kernel IB MAD API");
|
|
|
|
MODULE_AUTHOR("Hal Rosenstock");
|
|
|
|
MODULE_AUTHOR("Sean Hefty");
|
|
|
|
|
2010-05-24 04:39:31 +00:00
|
|
|
static int mad_sendq_size = IB_MAD_QP_SEND_SIZE;
|
|
|
|
static int mad_recvq_size = IB_MAD_QP_RECV_SIZE;
|
2009-09-07 15:28:48 +00:00
|
|
|
|
|
|
|
module_param_named(send_queue_size, mad_sendq_size, int, 0444);
|
|
|
|
MODULE_PARM_DESC(send_queue_size, "Size of send queue in number of work requests");
|
|
|
|
module_param_named(recv_queue_size, mad_recvq_size, int, 0444);
|
|
|
|
MODULE_PARM_DESC(recv_queue_size, "Size of receive queue in number of work requests");
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static struct list_head ib_mad_port_list;
|
|
|
|
static u32 ib_mad_client_id = 0;
|
|
|
|
|
|
|
|
/* Port list lock */
|
2009-09-06 03:24:23 +00:00
|
|
|
static DEFINE_SPINLOCK(ib_mad_port_list_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Forward declarations */
|
|
|
|
static int method_in_use(struct ib_mad_mgmt_method_table **method,
|
|
|
|
struct ib_mad_reg_req *mad_reg_req);
|
|
|
|
static void remove_mad_reg_req(struct ib_mad_agent_private *priv);
|
|
|
|
static struct ib_mad_agent_private *find_mad_agent(
|
|
|
|
struct ib_mad_port_private *port_priv,
|
2015-06-06 18:38:22 +00:00
|
|
|
const struct ib_mad_hdr *mad);
|
2005-04-16 22:20:36 +00:00
|
|
|
static int ib_mad_post_receive_mads(struct ib_mad_qp_info *qp_info,
|
|
|
|
struct ib_mad_private *mad);
|
|
|
|
static void cancel_mads(struct ib_mad_agent_private *mad_agent_priv);
|
2006-11-22 14:57:56 +00:00
|
|
|
static void timeout_sends(struct work_struct *work);
|
|
|
|
static void local_completions(struct work_struct *work);
|
2005-04-16 22:20:36 +00:00
|
|
|
static int add_nonoui_reg_req(struct ib_mad_reg_req *mad_reg_req,
|
|
|
|
struct ib_mad_agent_private *agent_priv,
|
|
|
|
u8 mgmt_class);
|
|
|
|
static int add_oui_reg_req(struct ib_mad_reg_req *mad_reg_req,
|
|
|
|
struct ib_mad_agent_private *agent_priv);
|
2016-01-06 06:46:12 +00:00
|
|
|
static bool ib_mad_send_error(struct ib_mad_port_private *port_priv,
|
|
|
|
struct ib_wc *wc);
|
|
|
|
static void ib_mad_send_done(struct ib_cq *cq, struct ib_wc *wc);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns a ib_mad_port_private structure or NULL for a device/port
|
|
|
|
* Assumes ib_mad_port_list_lock is being held
|
|
|
|
*/
|
|
|
|
static inline struct ib_mad_port_private *
|
|
|
|
__ib_get_mad_port(struct ib_device *device, int port_num)
|
|
|
|
{
|
|
|
|
struct ib_mad_port_private *entry;
|
|
|
|
|
|
|
|
list_for_each_entry(entry, &ib_mad_port_list, port_list) {
|
|
|
|
if (entry->device == device && entry->port_num == port_num)
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wrapper function to return a ib_mad_port_private structure or NULL
|
|
|
|
* for a device/port
|
|
|
|
*/
|
|
|
|
static inline struct ib_mad_port_private *
|
|
|
|
ib_get_mad_port(struct ib_device *device, int port_num)
|
|
|
|
{
|
|
|
|
struct ib_mad_port_private *entry;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ib_mad_port_list_lock, flags);
|
|
|
|
entry = __ib_get_mad_port(device, port_num);
|
|
|
|
spin_unlock_irqrestore(&ib_mad_port_list_lock, flags);
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u8 convert_mgmt_class(u8 mgmt_class)
|
|
|
|
{
|
|
|
|
/* Alias IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE to 0 */
|
|
|
|
return mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE ?
|
|
|
|
0 : mgmt_class;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_spl_qp_index(enum ib_qp_type qp_type)
|
|
|
|
{
|
|
|
|
switch (qp_type)
|
|
|
|
{
|
|
|
|
case IB_QPT_SMI:
|
|
|
|
return 0;
|
|
|
|
case IB_QPT_GSI:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vendor_class_index(u8 mgmt_class)
|
|
|
|
{
|
|
|
|
return mgmt_class - IB_MGMT_CLASS_VENDOR_RANGE2_START;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int is_vendor_class(u8 mgmt_class)
|
|
|
|
{
|
|
|
|
if ((mgmt_class < IB_MGMT_CLASS_VENDOR_RANGE2_START) ||
|
|
|
|
(mgmt_class > IB_MGMT_CLASS_VENDOR_RANGE2_END))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int is_vendor_oui(char *oui)
|
|
|
|
{
|
|
|
|
if (oui[0] || oui[1] || oui[2])
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int is_vendor_method_in_use(
|
|
|
|
struct ib_mad_mgmt_vendor_class *vendor_class,
|
|
|
|
struct ib_mad_reg_req *mad_reg_req)
|
|
|
|
{
|
|
|
|
struct ib_mad_mgmt_method_table *method;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MGMT_OUI; i++) {
|
|
|
|
if (!memcmp(vendor_class->oui[i], mad_reg_req->oui, 3)) {
|
|
|
|
method = vendor_class->method_table[i];
|
|
|
|
if (method) {
|
|
|
|
if (method_in_use(&method, mad_reg_req))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-08 18:27:22 +00:00
|
|
|
int ib_response_mad(const struct ib_mad_hdr *hdr)
|
2006-07-20 08:25:50 +00:00
|
|
|
{
|
2015-05-08 18:27:22 +00:00
|
|
|
return ((hdr->method & IB_MGMT_METHOD_RESP) ||
|
|
|
|
(hdr->method == IB_MGMT_METHOD_TRAP_REPRESS) ||
|
|
|
|
((hdr->mgmt_class == IB_MGMT_CLASS_BM) &&
|
|
|
|
(hdr->attr_mod & IB_BM_ATTR_MOD_RESP)));
|
2006-07-20 08:25:50 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_response_mad);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* ib_register_mad_agent - Register to send/receive MADs
|
|
|
|
*/
|
|
|
|
struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
|
|
|
|
u8 port_num,
|
|
|
|
enum ib_qp_type qp_type,
|
|
|
|
struct ib_mad_reg_req *mad_reg_req,
|
|
|
|
u8 rmpp_version,
|
|
|
|
ib_mad_send_handler send_handler,
|
|
|
|
ib_mad_recv_handler recv_handler,
|
2014-08-08 23:00:55 +00:00
|
|
|
void *context,
|
|
|
|
u32 registration_flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ib_mad_port_private *port_priv;
|
|
|
|
struct ib_mad_agent *ret = ERR_PTR(-EINVAL);
|
|
|
|
struct ib_mad_agent_private *mad_agent_priv;
|
|
|
|
struct ib_mad_reg_req *reg_req = NULL;
|
|
|
|
struct ib_mad_mgmt_class_table *class;
|
|
|
|
struct ib_mad_mgmt_vendor_class_table *vendor;
|
|
|
|
struct ib_mad_mgmt_vendor_class *vendor_class;
|
|
|
|
struct ib_mad_mgmt_method_table *method;
|
|
|
|
int ret2, qpn;
|
|
|
|
unsigned long flags;
|
|
|
|
u8 mgmt_class, vclass;
|
|
|
|
|
|
|
|
/* Validate parameters */
|
|
|
|
qpn = get_spl_qp_index(qp_type);
|
2014-08-08 23:00:54 +00:00
|
|
|
if (qpn == -1) {
|
|
|
|
dev_notice(&device->dev,
|
|
|
|
"ib_register_mad_agent: invalid QP Type %d\n",
|
|
|
|
qp_type);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error1;
|
2014-08-08 23:00:54 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-08-08 23:00:54 +00:00
|
|
|
if (rmpp_version && rmpp_version != IB_MGMT_RMPP_VERSION) {
|
|
|
|
dev_notice(&device->dev,
|
|
|
|
"ib_register_mad_agent: invalid RMPP Version %u\n",
|
|
|
|
rmpp_version);
|
2005-07-27 18:45:37 +00:00
|
|
|
goto error1;
|
2014-08-08 23:00:54 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Validate MAD registration request if supplied */
|
|
|
|
if (mad_reg_req) {
|
2014-08-08 23:00:54 +00:00
|
|
|
if (mad_reg_req->mgmt_class_version >= MAX_MGMT_VERSION) {
|
|
|
|
dev_notice(&device->dev,
|
|
|
|
"ib_register_mad_agent: invalid Class Version %u\n",
|
|
|
|
mad_reg_req->mgmt_class_version);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error1;
|
2014-08-08 23:00:54 +00:00
|
|
|
}
|
|
|
|
if (!recv_handler) {
|
|
|
|
dev_notice(&device->dev,
|
|
|
|
"ib_register_mad_agent: no recv_handler\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error1;
|
2014-08-08 23:00:54 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
if (mad_reg_req->mgmt_class >= MAX_MGMT_CLASS) {
|
|
|
|
/*
|
|
|
|
* IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE is the only
|
|
|
|
* one in this range currently allowed
|
|
|
|
*/
|
|
|
|
if (mad_reg_req->mgmt_class !=
|
2014-08-08 23:00:54 +00:00
|
|
|
IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
|
|
|
|
dev_notice(&device->dev,
|
|
|
|
"ib_register_mad_agent: Invalid Mgmt Class 0x%x\n",
|
|
|
|
mad_reg_req->mgmt_class);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error1;
|
2014-08-08 23:00:54 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
} else if (mad_reg_req->mgmt_class == 0) {
|
|
|
|
/*
|
|
|
|
* Class 0 is reserved in IBA and is used for
|
|
|
|
* aliasing of IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
|
|
|
|
*/
|
2014-08-08 23:00:54 +00:00
|
|
|
dev_notice(&device->dev,
|
|
|
|
"ib_register_mad_agent: Invalid Mgmt Class 0\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error1;
|
|
|
|
} else if (is_vendor_class(mad_reg_req->mgmt_class)) {
|
|
|
|
/*
|
|
|
|
* If class is in "new" vendor range,
|
|
|
|
* ensure supplied OUI is not zero
|
|
|
|
*/
|
2014-08-08 23:00:54 +00:00
|
|
|
if (!is_vendor_oui(mad_reg_req->oui)) {
|
|
|
|
dev_notice(&device->dev,
|
|
|
|
"ib_register_mad_agent: No OUI specified for class 0x%x\n",
|
|
|
|
mad_reg_req->mgmt_class);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error1;
|
2014-08-08 23:00:54 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-03-29 00:40:04 +00:00
|
|
|
/* Make sure class supplied is consistent with RMPP */
|
2006-04-13 01:29:10 +00:00
|
|
|
if (!ib_is_mad_class_rmpp(mad_reg_req->mgmt_class)) {
|
2014-08-08 23:00:54 +00:00
|
|
|
if (rmpp_version) {
|
|
|
|
dev_notice(&device->dev,
|
|
|
|
"ib_register_mad_agent: RMPP version for non-RMPP class 0x%x\n",
|
|
|
|
mad_reg_req->mgmt_class);
|
2006-03-29 00:40:04 +00:00
|
|
|
goto error1;
|
2014-08-08 23:00:54 +00:00
|
|
|
}
|
2006-03-29 00:40:04 +00:00
|
|
|
}
|
2014-08-08 23:00:56 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Make sure class supplied is consistent with QP type */
|
|
|
|
if (qp_type == IB_QPT_SMI) {
|
|
|
|
if ((mad_reg_req->mgmt_class !=
|
|
|
|
IB_MGMT_CLASS_SUBN_LID_ROUTED) &&
|
|
|
|
(mad_reg_req->mgmt_class !=
|
2014-08-08 23:00:54 +00:00
|
|
|
IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)) {
|
|
|
|
dev_notice(&device->dev,
|
|
|
|
"ib_register_mad_agent: Invalid SM QP type: class 0x%x\n",
|
|
|
|
mad_reg_req->mgmt_class);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error1;
|
2014-08-08 23:00:54 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
if ((mad_reg_req->mgmt_class ==
|
|
|
|
IB_MGMT_CLASS_SUBN_LID_ROUTED) ||
|
|
|
|
(mad_reg_req->mgmt_class ==
|
2014-08-08 23:00:54 +00:00
|
|
|
IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)) {
|
|
|
|
dev_notice(&device->dev,
|
|
|
|
"ib_register_mad_agent: Invalid GS QP type: class 0x%x\n",
|
|
|
|
mad_reg_req->mgmt_class);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error1;
|
2014-08-08 23:00:54 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* No registration request supplied */
|
|
|
|
if (!send_handler)
|
|
|
|
goto error1;
|
2014-08-08 23:00:56 +00:00
|
|
|
if (registration_flags & IB_MAD_USER_RMPP)
|
|
|
|
goto error1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate device and port */
|
|
|
|
port_priv = ib_get_mad_port(device, port_num);
|
|
|
|
if (!port_priv) {
|
2014-08-08 23:00:54 +00:00
|
|
|
dev_notice(&device->dev, "ib_register_mad_agent: Invalid port\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = ERR_PTR(-ENODEV);
|
|
|
|
goto error1;
|
|
|
|
}
|
|
|
|
|
2011-05-20 01:19:28 +00:00
|
|
|
/* Verify the QP requested is supported. For example, Ethernet devices
|
|
|
|
* will not have QP0 */
|
|
|
|
if (!port_priv->qp_info[qpn].qp) {
|
2014-08-08 23:00:54 +00:00
|
|
|
dev_notice(&device->dev,
|
|
|
|
"ib_register_mad_agent: QP %d not supported\n", qpn);
|
2011-05-20 01:19:28 +00:00
|
|
|
ret = ERR_PTR(-EPROTONOSUPPORT);
|
|
|
|
goto error1;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Allocate structures */
|
2005-11-02 15:23:14 +00:00
|
|
|
mad_agent_priv = kzalloc(sizeof *mad_agent_priv, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!mad_agent_priv) {
|
|
|
|
ret = ERR_PTR(-ENOMEM);
|
|
|
|
goto error1;
|
|
|
|
}
|
2005-07-27 18:45:22 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (mad_reg_req) {
|
2010-05-15 21:22:38 +00:00
|
|
|
reg_req = kmemdup(mad_reg_req, sizeof *reg_req, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!reg_req) {
|
|
|
|
ret = ERR_PTR(-ENOMEM);
|
2005-07-27 18:45:22 +00:00
|
|
|
goto error3;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, fill in the various structures */
|
|
|
|
mad_agent_priv->qp_info = &port_priv->qp_info[qpn];
|
|
|
|
mad_agent_priv->reg_req = reg_req;
|
2005-07-27 18:45:37 +00:00
|
|
|
mad_agent_priv->agent.rmpp_version = rmpp_version;
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_agent_priv->agent.device = device;
|
|
|
|
mad_agent_priv->agent.recv_handler = recv_handler;
|
|
|
|
mad_agent_priv->agent.send_handler = send_handler;
|
|
|
|
mad_agent_priv->agent.context = context;
|
|
|
|
mad_agent_priv->agent.qp = port_priv->qp_info[qpn].qp;
|
|
|
|
mad_agent_priv->agent.port_num = port_num;
|
2014-08-08 23:00:55 +00:00
|
|
|
mad_agent_priv->agent.flags = registration_flags;
|
2009-02-27 22:44:32 +00:00
|
|
|
spin_lock_init(&mad_agent_priv->lock);
|
|
|
|
INIT_LIST_HEAD(&mad_agent_priv->send_list);
|
|
|
|
INIT_LIST_HEAD(&mad_agent_priv->wait_list);
|
|
|
|
INIT_LIST_HEAD(&mad_agent_priv->done_list);
|
|
|
|
INIT_LIST_HEAD(&mad_agent_priv->rmpp_list);
|
|
|
|
INIT_DELAYED_WORK(&mad_agent_priv->timed_work, timeout_sends);
|
|
|
|
INIT_LIST_HEAD(&mad_agent_priv->local_list);
|
|
|
|
INIT_WORK(&mad_agent_priv->local_work, local_completions);
|
|
|
|
atomic_set(&mad_agent_priv->refcount, 1);
|
|
|
|
init_completion(&mad_agent_priv->comp);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&port_priv->reg_lock, flags);
|
|
|
|
mad_agent_priv->agent.hi_tid = ++ib_mad_client_id;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure MAD registration (if supplied)
|
|
|
|
* is non overlapping with any existing ones
|
|
|
|
*/
|
|
|
|
if (mad_reg_req) {
|
|
|
|
mgmt_class = convert_mgmt_class(mad_reg_req->mgmt_class);
|
|
|
|
if (!is_vendor_class(mgmt_class)) {
|
|
|
|
class = port_priv->version[mad_reg_req->
|
|
|
|
mgmt_class_version].class;
|
|
|
|
if (class) {
|
|
|
|
method = class->method_table[mgmt_class];
|
|
|
|
if (method) {
|
|
|
|
if (method_in_use(&method,
|
|
|
|
mad_reg_req))
|
2005-07-27 18:45:22 +00:00
|
|
|
goto error4;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ret2 = add_nonoui_reg_req(mad_reg_req, mad_agent_priv,
|
|
|
|
mgmt_class);
|
|
|
|
} else {
|
|
|
|
/* "New" vendor class range */
|
|
|
|
vendor = port_priv->version[mad_reg_req->
|
|
|
|
mgmt_class_version].vendor;
|
|
|
|
if (vendor) {
|
|
|
|
vclass = vendor_class_index(mgmt_class);
|
|
|
|
vendor_class = vendor->vendor_class[vclass];
|
|
|
|
if (vendor_class) {
|
|
|
|
if (is_vendor_method_in_use(
|
|
|
|
vendor_class,
|
|
|
|
mad_reg_req))
|
2005-07-27 18:45:22 +00:00
|
|
|
goto error4;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ret2 = add_oui_reg_req(mad_reg_req, mad_agent_priv);
|
|
|
|
}
|
|
|
|
if (ret2) {
|
|
|
|
ret = ERR_PTR(ret2);
|
2005-07-27 18:45:22 +00:00
|
|
|
goto error4;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add mad agent into port's agent list */
|
|
|
|
list_add_tail(&mad_agent_priv->agent_list, &port_priv->agent_list);
|
|
|
|
spin_unlock_irqrestore(&port_priv->reg_lock, flags);
|
|
|
|
|
|
|
|
return &mad_agent_priv->agent;
|
|
|
|
|
2005-07-27 18:45:22 +00:00
|
|
|
error4:
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&port_priv->reg_lock, flags);
|
|
|
|
kfree(reg_req);
|
2005-07-27 18:45:22 +00:00
|
|
|
error3:
|
2005-11-26 23:37:36 +00:00
|
|
|
kfree(mad_agent_priv);
|
2005-04-16 22:20:36 +00:00
|
|
|
error1:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_register_mad_agent);
|
|
|
|
|
|
|
|
static inline int is_snooping_sends(int mad_snoop_flags)
|
|
|
|
{
|
|
|
|
return (mad_snoop_flags &
|
|
|
|
(/*IB_MAD_SNOOP_POSTED_SENDS |
|
|
|
|
IB_MAD_SNOOP_RMPP_SENDS |*/
|
|
|
|
IB_MAD_SNOOP_SEND_COMPLETIONS /*|
|
|
|
|
IB_MAD_SNOOP_RMPP_SEND_COMPLETIONS*/));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_snooping_recvs(int mad_snoop_flags)
|
|
|
|
{
|
|
|
|
return (mad_snoop_flags &
|
|
|
|
(IB_MAD_SNOOP_RECVS /*|
|
|
|
|
IB_MAD_SNOOP_RMPP_RECVS*/));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int register_snoop_agent(struct ib_mad_qp_info *qp_info,
|
|
|
|
struct ib_mad_snoop_private *mad_snoop_priv)
|
|
|
|
{
|
|
|
|
struct ib_mad_snoop_private **new_snoop_table;
|
|
|
|
unsigned long flags;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&qp_info->snoop_lock, flags);
|
|
|
|
/* Check for empty slot in array. */
|
|
|
|
for (i = 0; i < qp_info->snoop_table_size; i++)
|
|
|
|
if (!qp_info->snoop_table[i])
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == qp_info->snoop_table_size) {
|
|
|
|
/* Grow table. */
|
2008-10-14 21:05:36 +00:00
|
|
|
new_snoop_table = krealloc(qp_info->snoop_table,
|
|
|
|
sizeof mad_snoop_priv *
|
|
|
|
(qp_info->snoop_table_size + 1),
|
|
|
|
GFP_ATOMIC);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!new_snoop_table) {
|
|
|
|
i = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2008-10-14 21:05:36 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
qp_info->snoop_table = new_snoop_table;
|
|
|
|
qp_info->snoop_table_size++;
|
|
|
|
}
|
|
|
|
qp_info->snoop_table[i] = mad_snoop_priv;
|
|
|
|
atomic_inc(&qp_info->snoop_count);
|
|
|
|
out:
|
|
|
|
spin_unlock_irqrestore(&qp_info->snoop_lock, flags);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device,
|
|
|
|
u8 port_num,
|
|
|
|
enum ib_qp_type qp_type,
|
|
|
|
int mad_snoop_flags,
|
|
|
|
ib_mad_snoop_handler snoop_handler,
|
|
|
|
ib_mad_recv_handler recv_handler,
|
|
|
|
void *context)
|
|
|
|
{
|
|
|
|
struct ib_mad_port_private *port_priv;
|
|
|
|
struct ib_mad_agent *ret;
|
|
|
|
struct ib_mad_snoop_private *mad_snoop_priv;
|
|
|
|
int qpn;
|
|
|
|
|
|
|
|
/* Validate parameters */
|
|
|
|
if ((is_snooping_sends(mad_snoop_flags) && !snoop_handler) ||
|
|
|
|
(is_snooping_recvs(mad_snoop_flags) && !recv_handler)) {
|
|
|
|
ret = ERR_PTR(-EINVAL);
|
|
|
|
goto error1;
|
|
|
|
}
|
|
|
|
qpn = get_spl_qp_index(qp_type);
|
|
|
|
if (qpn == -1) {
|
|
|
|
ret = ERR_PTR(-EINVAL);
|
|
|
|
goto error1;
|
|
|
|
}
|
|
|
|
port_priv = ib_get_mad_port(device, port_num);
|
|
|
|
if (!port_priv) {
|
|
|
|
ret = ERR_PTR(-ENODEV);
|
|
|
|
goto error1;
|
|
|
|
}
|
|
|
|
/* Allocate structures */
|
2005-11-02 15:23:14 +00:00
|
|
|
mad_snoop_priv = kzalloc(sizeof *mad_snoop_priv, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!mad_snoop_priv) {
|
|
|
|
ret = ERR_PTR(-ENOMEM);
|
|
|
|
goto error1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, fill in the various structures */
|
|
|
|
mad_snoop_priv->qp_info = &port_priv->qp_info[qpn];
|
|
|
|
mad_snoop_priv->agent.device = device;
|
|
|
|
mad_snoop_priv->agent.recv_handler = recv_handler;
|
|
|
|
mad_snoop_priv->agent.snoop_handler = snoop_handler;
|
|
|
|
mad_snoop_priv->agent.context = context;
|
|
|
|
mad_snoop_priv->agent.qp = port_priv->qp_info[qpn].qp;
|
|
|
|
mad_snoop_priv->agent.port_num = port_num;
|
|
|
|
mad_snoop_priv->mad_snoop_flags = mad_snoop_flags;
|
2006-05-12 21:57:52 +00:00
|
|
|
init_completion(&mad_snoop_priv->comp);
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_snoop_priv->snoop_index = register_snoop_agent(
|
|
|
|
&port_priv->qp_info[qpn],
|
|
|
|
mad_snoop_priv);
|
|
|
|
if (mad_snoop_priv->snoop_index < 0) {
|
|
|
|
ret = ERR_PTR(mad_snoop_priv->snoop_index);
|
|
|
|
goto error2;
|
|
|
|
}
|
|
|
|
|
|
|
|
atomic_set(&mad_snoop_priv->refcount, 1);
|
|
|
|
return &mad_snoop_priv->agent;
|
|
|
|
|
|
|
|
error2:
|
|
|
|
kfree(mad_snoop_priv);
|
|
|
|
error1:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_register_mad_snoop);
|
|
|
|
|
2006-05-12 21:57:52 +00:00
|
|
|
static inline void deref_mad_agent(struct ib_mad_agent_private *mad_agent_priv)
|
|
|
|
{
|
|
|
|
if (atomic_dec_and_test(&mad_agent_priv->refcount))
|
|
|
|
complete(&mad_agent_priv->comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void deref_snoop_agent(struct ib_mad_snoop_private *mad_snoop_priv)
|
|
|
|
{
|
|
|
|
if (atomic_dec_and_test(&mad_snoop_priv->refcount))
|
|
|
|
complete(&mad_snoop_priv->comp);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static void unregister_mad_agent(struct ib_mad_agent_private *mad_agent_priv)
|
|
|
|
{
|
|
|
|
struct ib_mad_port_private *port_priv;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* Note that we could still be handling received MADs */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Canceling all sends results in dropping received response
|
|
|
|
* MADs, preventing us from queuing additional work
|
|
|
|
*/
|
|
|
|
cancel_mads(mad_agent_priv);
|
|
|
|
port_priv = mad_agent_priv->qp_info->port_priv;
|
|
|
|
cancel_delayed_work(&mad_agent_priv->timed_work);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&port_priv->reg_lock, flags);
|
|
|
|
remove_mad_reg_req(mad_agent_priv);
|
|
|
|
list_del(&mad_agent_priv->agent_list);
|
|
|
|
spin_unlock_irqrestore(&port_priv->reg_lock, flags);
|
|
|
|
|
2005-07-27 18:45:22 +00:00
|
|
|
flush_workqueue(port_priv->wq);
|
2005-07-27 18:45:37 +00:00
|
|
|
ib_cancel_rmpp_recvs(mad_agent_priv);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-05-12 21:57:52 +00:00
|
|
|
deref_mad_agent(mad_agent_priv);
|
|
|
|
wait_for_completion(&mad_agent_priv->comp);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-11-07 09:01:32 +00:00
|
|
|
kfree(mad_agent_priv->reg_req);
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(mad_agent_priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unregister_mad_snoop(struct ib_mad_snoop_private *mad_snoop_priv)
|
|
|
|
{
|
|
|
|
struct ib_mad_qp_info *qp_info;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
qp_info = mad_snoop_priv->qp_info;
|
|
|
|
spin_lock_irqsave(&qp_info->snoop_lock, flags);
|
|
|
|
qp_info->snoop_table[mad_snoop_priv->snoop_index] = NULL;
|
|
|
|
atomic_dec(&qp_info->snoop_count);
|
|
|
|
spin_unlock_irqrestore(&qp_info->snoop_lock, flags);
|
|
|
|
|
2006-05-12 21:57:52 +00:00
|
|
|
deref_snoop_agent(mad_snoop_priv);
|
|
|
|
wait_for_completion(&mad_snoop_priv->comp);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
kfree(mad_snoop_priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ib_unregister_mad_agent - Unregisters a client from using MAD services
|
|
|
|
*/
|
|
|
|
int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent)
|
|
|
|
{
|
|
|
|
struct ib_mad_agent_private *mad_agent_priv;
|
|
|
|
struct ib_mad_snoop_private *mad_snoop_priv;
|
|
|
|
|
|
|
|
/* If the TID is zero, the agent can only snoop. */
|
|
|
|
if (mad_agent->hi_tid) {
|
|
|
|
mad_agent_priv = container_of(mad_agent,
|
|
|
|
struct ib_mad_agent_private,
|
|
|
|
agent);
|
|
|
|
unregister_mad_agent(mad_agent_priv);
|
|
|
|
} else {
|
|
|
|
mad_snoop_priv = container_of(mad_agent,
|
|
|
|
struct ib_mad_snoop_private,
|
|
|
|
agent);
|
|
|
|
unregister_mad_snoop(mad_snoop_priv);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_unregister_mad_agent);
|
|
|
|
|
|
|
|
static void dequeue_mad(struct ib_mad_list_head *mad_list)
|
|
|
|
{
|
|
|
|
struct ib_mad_queue *mad_queue;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
BUG_ON(!mad_list->mad_queue);
|
|
|
|
mad_queue = mad_list->mad_queue;
|
|
|
|
spin_lock_irqsave(&mad_queue->lock, flags);
|
|
|
|
list_del(&mad_list->list);
|
|
|
|
mad_queue->count--;
|
|
|
|
spin_unlock_irqrestore(&mad_queue->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void snoop_send(struct ib_mad_qp_info *qp_info,
|
2005-10-25 17:51:39 +00:00
|
|
|
struct ib_mad_send_buf *send_buf,
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ib_mad_send_wc *mad_send_wc,
|
|
|
|
int mad_snoop_flags)
|
|
|
|
{
|
|
|
|
struct ib_mad_snoop_private *mad_snoop_priv;
|
|
|
|
unsigned long flags;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&qp_info->snoop_lock, flags);
|
|
|
|
for (i = 0; i < qp_info->snoop_table_size; i++) {
|
|
|
|
mad_snoop_priv = qp_info->snoop_table[i];
|
|
|
|
if (!mad_snoop_priv ||
|
|
|
|
!(mad_snoop_priv->mad_snoop_flags & mad_snoop_flags))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
atomic_inc(&mad_snoop_priv->refcount);
|
|
|
|
spin_unlock_irqrestore(&qp_info->snoop_lock, flags);
|
|
|
|
mad_snoop_priv->agent.snoop_handler(&mad_snoop_priv->agent,
|
2005-10-25 17:51:39 +00:00
|
|
|
send_buf, mad_send_wc);
|
2006-05-12 21:57:52 +00:00
|
|
|
deref_snoop_agent(mad_snoop_priv);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&qp_info->snoop_lock, flags);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&qp_info->snoop_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void snoop_recv(struct ib_mad_qp_info *qp_info,
|
|
|
|
struct ib_mad_recv_wc *mad_recv_wc,
|
|
|
|
int mad_snoop_flags)
|
|
|
|
{
|
|
|
|
struct ib_mad_snoop_private *mad_snoop_priv;
|
|
|
|
unsigned long flags;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&qp_info->snoop_lock, flags);
|
|
|
|
for (i = 0; i < qp_info->snoop_table_size; i++) {
|
|
|
|
mad_snoop_priv = qp_info->snoop_table[i];
|
|
|
|
if (!mad_snoop_priv ||
|
|
|
|
!(mad_snoop_priv->mad_snoop_flags & mad_snoop_flags))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
atomic_inc(&mad_snoop_priv->refcount);
|
|
|
|
spin_unlock_irqrestore(&qp_info->snoop_lock, flags);
|
2016-01-04 13:15:58 +00:00
|
|
|
mad_snoop_priv->agent.recv_handler(&mad_snoop_priv->agent, NULL,
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_recv_wc);
|
2006-05-12 21:57:52 +00:00
|
|
|
deref_snoop_agent(mad_snoop_priv);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&qp_info->snoop_lock, flags);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&qp_info->snoop_lock, flags);
|
|
|
|
}
|
|
|
|
|
2016-01-06 06:46:12 +00:00
|
|
|
static void build_smp_wc(struct ib_qp *qp, struct ib_cqe *cqe, u16 slid,
|
|
|
|
u16 pkey_index, u8 port_num, struct ib_wc *wc)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
memset(wc, 0, sizeof *wc);
|
2016-01-06 06:46:12 +00:00
|
|
|
wc->wr_cqe = cqe;
|
2005-04-16 22:20:36 +00:00
|
|
|
wc->status = IB_WC_SUCCESS;
|
|
|
|
wc->opcode = IB_WC_RECV;
|
|
|
|
wc->pkey_index = pkey_index;
|
|
|
|
wc->byte_len = sizeof(struct ib_mad) + sizeof(struct ib_grh);
|
|
|
|
wc->src_qp = IB_QP0;
|
2006-12-31 19:09:42 +00:00
|
|
|
wc->qp = qp;
|
2005-04-16 22:20:36 +00:00
|
|
|
wc->slid = slid;
|
|
|
|
wc->sl = 0;
|
|
|
|
wc->dlid_path_bits = 0;
|
|
|
|
wc->port_num = port_num;
|
|
|
|
}
|
|
|
|
|
2015-06-06 18:38:30 +00:00
|
|
|
static size_t mad_priv_size(const struct ib_mad_private *mp)
|
|
|
|
{
|
|
|
|
return sizeof(struct ib_mad_private) + mp->mad_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ib_mad_private *alloc_mad_private(size_t mad_size, gfp_t flags)
|
|
|
|
{
|
|
|
|
size_t size = sizeof(struct ib_mad_private) + mad_size;
|
|
|
|
struct ib_mad_private *ret = kzalloc(size, flags);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
ret->mad_size = mad_size;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t port_mad_size(const struct ib_mad_port_private *port_priv)
|
|
|
|
{
|
|
|
|
return rdma_max_mad_size(port_priv->device, port_priv->port_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t mad_priv_dma_size(const struct ib_mad_private *mp)
|
|
|
|
{
|
|
|
|
return sizeof(struct ib_grh) + mp->mad_size;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Return 0 if SMP is to be sent
|
|
|
|
* Return 1 if SMP was consumed locally (whether or not solicited)
|
|
|
|
* Return < 0 if error
|
|
|
|
*/
|
|
|
|
static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv,
|
2005-10-25 17:51:39 +00:00
|
|
|
struct ib_mad_send_wr_private *mad_send_wr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-04-02 15:24:07 +00:00
|
|
|
int ret = 0;
|
2005-10-25 17:51:39 +00:00
|
|
|
struct ib_smp *smp = mad_send_wr->send_buf.mad;
|
2015-06-10 20:16:48 +00:00
|
|
|
struct opa_smp *opa_smp = (struct opa_smp *)smp;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
struct ib_mad_local_private *local;
|
|
|
|
struct ib_mad_private *mad_priv;
|
|
|
|
struct ib_mad_port_private *port_priv;
|
|
|
|
struct ib_mad_agent_private *recv_mad_agent = NULL;
|
|
|
|
struct ib_device *device = mad_agent_priv->agent.device;
|
2007-05-14 21:21:52 +00:00
|
|
|
u8 port_num;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ib_wc mad_wc;
|
2015-10-08 08:16:33 +00:00
|
|
|
struct ib_ud_wr *send_wr = &mad_send_wr->send_wr;
|
2015-06-06 18:38:30 +00:00
|
|
|
size_t mad_size = port_mad_size(mad_agent_priv->qp_info->port_priv);
|
2015-06-06 18:38:31 +00:00
|
|
|
u16 out_mad_pkey_index = 0;
|
2015-06-10 20:16:48 +00:00
|
|
|
u16 drslid;
|
|
|
|
bool opa = rdma_cap_opa_mad(mad_agent_priv->qp_info->port_priv->device,
|
|
|
|
mad_agent_priv->qp_info->port_priv->port_num);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-29 13:57:00 +00:00
|
|
|
if (rdma_cap_ib_switch(device) &&
|
2007-05-14 21:21:52 +00:00
|
|
|
smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
|
2015-10-08 08:16:33 +00:00
|
|
|
port_num = send_wr->port_num;
|
2007-05-14 21:21:52 +00:00
|
|
|
else
|
|
|
|
port_num = mad_agent_priv->agent.port_num;
|
|
|
|
|
2006-02-03 22:28:48 +00:00
|
|
|
/*
|
|
|
|
* Directed route handling starts if the initial LID routed part of
|
|
|
|
* a request or the ending LID routed part of a response is empty.
|
|
|
|
* If we are at the start of the LID routed part, don't update the
|
|
|
|
* hop_ptr or hop_cnt. See section 14.2.2, Vol 1 IB spec.
|
|
|
|
*/
|
2015-06-10 20:16:48 +00:00
|
|
|
if (opa && smp->class_version == OPA_SMP_CLASS_VERSION) {
|
|
|
|
u32 opa_drslid;
|
|
|
|
|
|
|
|
if ((opa_get_smp_direction(opa_smp)
|
|
|
|
? opa_smp->route.dr.dr_dlid : opa_smp->route.dr.dr_slid) ==
|
|
|
|
OPA_LID_PERMISSIVE &&
|
2015-06-29 13:57:00 +00:00
|
|
|
opa_smi_handle_dr_smp_send(opa_smp,
|
|
|
|
rdma_cap_ib_switch(device),
|
2015-06-10 20:16:48 +00:00
|
|
|
port_num) == IB_SMI_DISCARD) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
dev_err(&device->dev, "OPA Invalid directed route\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
opa_drslid = be32_to_cpu(opa_smp->route.dr.dr_slid);
|
2015-06-25 16:04:49 +00:00
|
|
|
if (opa_drslid != be32_to_cpu(OPA_LID_PERMISSIVE) &&
|
2015-06-10 20:16:48 +00:00
|
|
|
opa_drslid & 0xffff0000) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
dev_err(&device->dev, "OPA Invalid dr_slid 0x%x\n",
|
|
|
|
opa_drslid);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
drslid = (u16)(opa_drslid & 0x0000ffff);
|
2007-04-02 15:24:07 +00:00
|
|
|
|
2015-06-10 20:16:48 +00:00
|
|
|
/* Check to post send on QP or process locally */
|
|
|
|
if (opa_smi_check_local_smp(opa_smp, device) == IB_SMI_DISCARD &&
|
|
|
|
opa_smi_check_local_returning_smp(opa_smp, device) == IB_SMI_DISCARD)
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
if ((ib_get_smp_direction(smp) ? smp->dr_dlid : smp->dr_slid) ==
|
|
|
|
IB_LID_PERMISSIVE &&
|
2015-06-29 13:57:00 +00:00
|
|
|
smi_handle_dr_smp_send(smp, rdma_cap_ib_switch(device), port_num) ==
|
2015-06-10 20:16:48 +00:00
|
|
|
IB_SMI_DISCARD) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
dev_err(&device->dev, "Invalid directed route\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
drslid = be16_to_cpu(smp->dr_slid);
|
|
|
|
|
|
|
|
/* Check to post send on QP or process locally */
|
|
|
|
if (smi_check_local_smp(smp, device) == IB_SMI_DISCARD &&
|
|
|
|
smi_check_local_returning_smp(smp, device) == IB_SMI_DISCARD)
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
local = kmalloc(sizeof *local, GFP_ATOMIC);
|
|
|
|
if (!local) {
|
|
|
|
ret = -ENOMEM;
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev, "No memory for ib_mad_local_private\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
local->mad_priv = NULL;
|
|
|
|
local->recv_mad_agent = NULL;
|
2015-06-06 18:38:30 +00:00
|
|
|
mad_priv = alloc_mad_private(mad_size, GFP_ATOMIC);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!mad_priv) {
|
|
|
|
ret = -ENOMEM;
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev, "No memory for local response MAD\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(local);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2006-12-31 19:09:42 +00:00
|
|
|
build_smp_wc(mad_agent_priv->agent.qp,
|
2016-01-06 06:46:12 +00:00
|
|
|
send_wr->wr.wr_cqe, drslid,
|
2015-10-08 08:16:33 +00:00
|
|
|
send_wr->pkey_index,
|
|
|
|
send_wr->port_num, &mad_wc);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-10 20:16:48 +00:00
|
|
|
if (opa && smp->base_version == OPA_MGMT_BASE_VERSION) {
|
|
|
|
mad_wc.byte_len = mad_send_wr->send_buf.hdr_len
|
|
|
|
+ mad_send_wr->send_buf.data_len
|
|
|
|
+ sizeof(struct ib_grh);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* No GRH for DR SMP */
|
|
|
|
ret = device->process_mad(device, 0, port_num, &mad_wc, NULL,
|
2015-06-06 18:38:31 +00:00
|
|
|
(const struct ib_mad_hdr *)smp, mad_size,
|
|
|
|
(struct ib_mad_hdr *)mad_priv->mad,
|
|
|
|
&mad_size, &out_mad_pkey_index);
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (ret)
|
|
|
|
{
|
|
|
|
case IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY:
|
2015-06-06 18:38:30 +00:00
|
|
|
if (ib_response_mad((const struct ib_mad_hdr *)mad_priv->mad) &&
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_agent_priv->agent.recv_handler) {
|
|
|
|
local->mad_priv = mad_priv;
|
|
|
|
local->recv_mad_agent = mad_agent_priv;
|
|
|
|
/*
|
|
|
|
* Reference MAD agent until receive
|
|
|
|
* side of local completion handled
|
|
|
|
*/
|
|
|
|
atomic_inc(&mad_agent_priv->refcount);
|
|
|
|
} else
|
2015-06-06 18:38:30 +00:00
|
|
|
kfree(mad_priv);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED:
|
2015-06-06 18:38:30 +00:00
|
|
|
kfree(mad_priv);
|
2009-03-03 22:22:17 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
case IB_MAD_RESULT_SUCCESS:
|
|
|
|
/* Treat like an incoming receive MAD */
|
|
|
|
port_priv = ib_get_mad_port(mad_agent_priv->agent.device,
|
|
|
|
mad_agent_priv->agent.port_num);
|
|
|
|
if (port_priv) {
|
2015-06-06 18:38:30 +00:00
|
|
|
memcpy(mad_priv->mad, smp, mad_priv->mad_size);
|
2005-04-16 22:20:36 +00:00
|
|
|
recv_mad_agent = find_mad_agent(port_priv,
|
2015-06-06 18:38:30 +00:00
|
|
|
(const struct ib_mad_hdr *)mad_priv->mad);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (!port_priv || !recv_mad_agent) {
|
2009-03-03 22:22:17 +00:00
|
|
|
/*
|
|
|
|
* No receiving agent so drop packet and
|
|
|
|
* generate send completion.
|
|
|
|
*/
|
2015-06-06 18:38:30 +00:00
|
|
|
kfree(mad_priv);
|
2009-03-03 22:22:17 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
local->mad_priv = mad_priv;
|
|
|
|
local->recv_mad_agent = recv_mad_agent;
|
|
|
|
break;
|
|
|
|
default:
|
2015-06-06 18:38:30 +00:00
|
|
|
kfree(mad_priv);
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(local);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
local->mad_send_wr = mad_send_wr;
|
2015-06-10 20:16:48 +00:00
|
|
|
if (opa) {
|
2015-10-08 08:16:33 +00:00
|
|
|
local->mad_send_wr->send_wr.pkey_index = out_mad_pkey_index;
|
2015-06-10 20:16:48 +00:00
|
|
|
local->return_wc_byte_len = mad_size;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Reference MAD agent until send side of local completion handled */
|
|
|
|
atomic_inc(&mad_agent_priv->refcount);
|
|
|
|
/* Queue local completion to local list */
|
|
|
|
spin_lock_irqsave(&mad_agent_priv->lock, flags);
|
|
|
|
list_add_tail(&local->completion_list, &mad_agent_priv->local_list);
|
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
|
|
|
queue_work(mad_agent_priv->qp_info->port_priv->wq,
|
2005-07-27 18:45:22 +00:00
|
|
|
&mad_agent_priv->local_work);
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = 1;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-06 18:38:33 +00:00
|
|
|
static int get_pad_size(int hdr_len, int data_len, size_t mad_size)
|
2005-07-27 18:45:23 +00:00
|
|
|
{
|
|
|
|
int seg_size, pad;
|
|
|
|
|
2015-06-06 18:38:33 +00:00
|
|
|
seg_size = mad_size - hdr_len;
|
2005-07-27 18:45:23 +00:00
|
|
|
if (data_len && seg_size) {
|
|
|
|
pad = seg_size - data_len % seg_size;
|
2006-03-04 05:54:13 +00:00
|
|
|
return pad == seg_size ? 0 : pad;
|
2005-07-27 18:45:23 +00:00
|
|
|
} else
|
2006-03-04 05:54:13 +00:00
|
|
|
return seg_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_send_rmpp_list(struct ib_mad_send_wr_private *mad_send_wr)
|
|
|
|
{
|
|
|
|
struct ib_rmpp_segment *s, *t;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(s, t, &mad_send_wr->rmpp_list, list) {
|
|
|
|
list_del(&s->list);
|
|
|
|
kfree(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int alloc_send_rmpp_list(struct ib_mad_send_wr_private *send_wr,
|
2015-06-06 18:38:33 +00:00
|
|
|
size_t mad_size, gfp_t gfp_mask)
|
2006-03-04 05:54:13 +00:00
|
|
|
{
|
|
|
|
struct ib_mad_send_buf *send_buf = &send_wr->send_buf;
|
|
|
|
struct ib_rmpp_mad *rmpp_mad = send_buf->mad;
|
|
|
|
struct ib_rmpp_segment *seg = NULL;
|
|
|
|
int left, seg_size, pad;
|
|
|
|
|
2015-06-06 18:38:33 +00:00
|
|
|
send_buf->seg_size = mad_size - send_buf->hdr_len;
|
|
|
|
send_buf->seg_rmpp_size = mad_size - IB_MGMT_RMPP_HDR;
|
2006-03-04 05:54:13 +00:00
|
|
|
seg_size = send_buf->seg_size;
|
|
|
|
pad = send_wr->pad;
|
|
|
|
|
|
|
|
/* Allocate data segments. */
|
|
|
|
for (left = send_buf->data_len + pad; left > 0; left -= seg_size) {
|
|
|
|
seg = kmalloc(sizeof (*seg) + seg_size, gfp_mask);
|
|
|
|
if (!seg) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&send_buf->mad_agent->device->dev,
|
|
|
|
"alloc_send_rmpp_segs: RMPP mem alloc failed for len %zd, gfp %#x\n",
|
|
|
|
sizeof (*seg) + seg_size, gfp_mask);
|
2006-03-04 05:54:13 +00:00
|
|
|
free_send_rmpp_list(send_wr);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
seg->num = ++send_buf->seg_count;
|
|
|
|
list_add_tail(&seg->list, &send_wr->rmpp_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Zero any padding */
|
|
|
|
if (pad)
|
|
|
|
memset(seg->data + seg_size - pad, 0, pad);
|
|
|
|
|
|
|
|
rmpp_mad->rmpp_hdr.rmpp_version = send_wr->mad_agent_priv->
|
|
|
|
agent.rmpp_version;
|
|
|
|
rmpp_mad->rmpp_hdr.rmpp_type = IB_MGMT_RMPP_TYPE_DATA;
|
|
|
|
ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr, IB_MGMT_RMPP_FLAG_ACTIVE);
|
|
|
|
|
|
|
|
send_wr->cur_seg = container_of(send_wr->rmpp_list.next,
|
|
|
|
struct ib_rmpp_segment, list);
|
|
|
|
send_wr->last_ack_seg = send_wr->cur_seg;
|
|
|
|
return 0;
|
2005-07-27 18:45:23 +00:00
|
|
|
}
|
|
|
|
|
2015-05-08 18:27:24 +00:00
|
|
|
int ib_mad_kernel_rmpp_agent(const struct ib_mad_agent *agent)
|
2014-08-08 23:00:56 +00:00
|
|
|
{
|
|
|
|
return agent->rmpp_version && !(agent->flags & IB_MAD_USER_RMPP);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_mad_kernel_rmpp_agent);
|
|
|
|
|
2005-07-27 18:45:23 +00:00
|
|
|
struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
|
|
|
|
u32 remote_qpn, u16 pkey_index,
|
2005-10-25 17:51:39 +00:00
|
|
|
int rmpp_active,
|
2005-07-27 18:45:23 +00:00
|
|
|
int hdr_len, int data_len,
|
2015-06-06 18:38:28 +00:00
|
|
|
gfp_t gfp_mask,
|
|
|
|
u8 base_version)
|
2005-07-27 18:45:23 +00:00
|
|
|
{
|
|
|
|
struct ib_mad_agent_private *mad_agent_priv;
|
2005-10-25 17:51:39 +00:00
|
|
|
struct ib_mad_send_wr_private *mad_send_wr;
|
2006-03-04 05:54:13 +00:00
|
|
|
int pad, message_size, ret, size;
|
2005-07-27 18:45:23 +00:00
|
|
|
void *buf;
|
2015-06-06 18:38:33 +00:00
|
|
|
size_t mad_size;
|
|
|
|
bool opa;
|
2005-07-27 18:45:23 +00:00
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_agent_priv = container_of(mad_agent, struct ib_mad_agent_private,
|
|
|
|
agent);
|
2015-06-06 18:38:33 +00:00
|
|
|
|
|
|
|
opa = rdma_cap_opa_mad(mad_agent->device, mad_agent->port_num);
|
|
|
|
|
|
|
|
if (opa && base_version == OPA_MGMT_BASE_VERSION)
|
|
|
|
mad_size = sizeof(struct opa_mad);
|
|
|
|
else
|
|
|
|
mad_size = sizeof(struct ib_mad);
|
|
|
|
|
|
|
|
pad = get_pad_size(hdr_len, data_len, mad_size);
|
2006-03-04 05:54:13 +00:00
|
|
|
message_size = hdr_len + data_len + pad;
|
2005-07-27 18:45:23 +00:00
|
|
|
|
2014-08-08 23:00:56 +00:00
|
|
|
if (ib_mad_kernel_rmpp_agent(mad_agent)) {
|
2015-06-06 18:38:33 +00:00
|
|
|
if (!rmpp_active && message_size > mad_size)
|
2014-08-08 23:00:56 +00:00
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
} else
|
2015-06-06 18:38:33 +00:00
|
|
|
if (rmpp_active || message_size > mad_size)
|
2014-08-08 23:00:56 +00:00
|
|
|
return ERR_PTR(-EINVAL);
|
2005-07-27 18:45:37 +00:00
|
|
|
|
2015-06-06 18:38:33 +00:00
|
|
|
size = rmpp_active ? hdr_len : mad_size;
|
2006-03-04 05:54:13 +00:00
|
|
|
buf = kzalloc(sizeof *mad_send_wr + size, gfp_mask);
|
2005-07-27 18:45:23 +00:00
|
|
|
if (!buf)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2005-10-25 17:51:39 +00:00
|
|
|
|
2006-03-04 05:54:13 +00:00
|
|
|
mad_send_wr = buf + size;
|
|
|
|
INIT_LIST_HEAD(&mad_send_wr->rmpp_list);
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_send_wr->send_buf.mad = buf;
|
2006-03-04 05:54:13 +00:00
|
|
|
mad_send_wr->send_buf.hdr_len = hdr_len;
|
|
|
|
mad_send_wr->send_buf.data_len = data_len;
|
|
|
|
mad_send_wr->pad = pad;
|
2005-10-25 17:51:39 +00:00
|
|
|
|
|
|
|
mad_send_wr->mad_agent_priv = mad_agent_priv;
|
2006-03-04 05:54:13 +00:00
|
|
|
mad_send_wr->sg_list[0].length = hdr_len;
|
2015-07-30 23:22:16 +00:00
|
|
|
mad_send_wr->sg_list[0].lkey = mad_agent->qp->pd->local_dma_lkey;
|
2015-06-06 18:38:33 +00:00
|
|
|
|
|
|
|
/* OPA MADs don't have to be the full 2048 bytes */
|
|
|
|
if (opa && base_version == OPA_MGMT_BASE_VERSION &&
|
|
|
|
data_len < mad_size - hdr_len)
|
|
|
|
mad_send_wr->sg_list[1].length = data_len;
|
|
|
|
else
|
|
|
|
mad_send_wr->sg_list[1].length = mad_size - hdr_len;
|
|
|
|
|
2015-07-30 23:22:16 +00:00
|
|
|
mad_send_wr->sg_list[1].lkey = mad_agent->qp->pd->local_dma_lkey;
|
2005-10-25 17:51:39 +00:00
|
|
|
|
2016-01-06 06:46:12 +00:00
|
|
|
mad_send_wr->mad_list.cqe.done = ib_mad_send_done;
|
|
|
|
|
|
|
|
mad_send_wr->send_wr.wr.wr_cqe = &mad_send_wr->mad_list.cqe;
|
2015-10-08 08:16:33 +00:00
|
|
|
mad_send_wr->send_wr.wr.sg_list = mad_send_wr->sg_list;
|
|
|
|
mad_send_wr->send_wr.wr.num_sge = 2;
|
|
|
|
mad_send_wr->send_wr.wr.opcode = IB_WR_SEND;
|
|
|
|
mad_send_wr->send_wr.wr.send_flags = IB_SEND_SIGNALED;
|
|
|
|
mad_send_wr->send_wr.remote_qpn = remote_qpn;
|
|
|
|
mad_send_wr->send_wr.remote_qkey = IB_QP_SET_QKEY;
|
|
|
|
mad_send_wr->send_wr.pkey_index = pkey_index;
|
2005-07-27 18:45:37 +00:00
|
|
|
|
|
|
|
if (rmpp_active) {
|
2015-06-06 18:38:33 +00:00
|
|
|
ret = alloc_send_rmpp_list(mad_send_wr, mad_size, gfp_mask);
|
2006-03-04 05:54:13 +00:00
|
|
|
if (ret) {
|
|
|
|
kfree(buf);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
2005-07-27 18:45:37 +00:00
|
|
|
}
|
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_send_wr->send_buf.mad_agent = mad_agent;
|
2005-07-27 18:45:23 +00:00
|
|
|
atomic_inc(&mad_agent_priv->refcount);
|
2005-10-25 17:51:39 +00:00
|
|
|
return &mad_send_wr->send_buf;
|
2005-07-27 18:45:23 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_create_send_mad);
|
|
|
|
|
2006-03-29 00:40:04 +00:00
|
|
|
int ib_get_mad_data_offset(u8 mgmt_class)
|
|
|
|
{
|
|
|
|
if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM)
|
|
|
|
return IB_MGMT_SA_HDR;
|
|
|
|
else if ((mgmt_class == IB_MGMT_CLASS_DEVICE_MGMT) ||
|
|
|
|
(mgmt_class == IB_MGMT_CLASS_DEVICE_ADM) ||
|
|
|
|
(mgmt_class == IB_MGMT_CLASS_BIS))
|
|
|
|
return IB_MGMT_DEVICE_HDR;
|
|
|
|
else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
|
|
|
|
(mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END))
|
|
|
|
return IB_MGMT_VENDOR_HDR;
|
|
|
|
else
|
|
|
|
return IB_MGMT_MAD_HDR;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_get_mad_data_offset);
|
|
|
|
|
|
|
|
int ib_is_mad_class_rmpp(u8 mgmt_class)
|
|
|
|
{
|
|
|
|
if ((mgmt_class == IB_MGMT_CLASS_SUBN_ADM) ||
|
|
|
|
(mgmt_class == IB_MGMT_CLASS_DEVICE_MGMT) ||
|
|
|
|
(mgmt_class == IB_MGMT_CLASS_DEVICE_ADM) ||
|
|
|
|
(mgmt_class == IB_MGMT_CLASS_BIS) ||
|
|
|
|
((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
|
|
|
|
(mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END)))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_is_mad_class_rmpp);
|
|
|
|
|
2006-03-04 05:54:13 +00:00
|
|
|
void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num)
|
|
|
|
{
|
|
|
|
struct ib_mad_send_wr_private *mad_send_wr;
|
|
|
|
struct list_head *list;
|
|
|
|
|
|
|
|
mad_send_wr = container_of(send_buf, struct ib_mad_send_wr_private,
|
|
|
|
send_buf);
|
|
|
|
list = &mad_send_wr->cur_seg->list;
|
|
|
|
|
|
|
|
if (mad_send_wr->cur_seg->num < seg_num) {
|
|
|
|
list_for_each_entry(mad_send_wr->cur_seg, list, list)
|
|
|
|
if (mad_send_wr->cur_seg->num == seg_num)
|
|
|
|
break;
|
|
|
|
} else if (mad_send_wr->cur_seg->num > seg_num) {
|
|
|
|
list_for_each_entry_reverse(mad_send_wr->cur_seg, list, list)
|
|
|
|
if (mad_send_wr->cur_seg->num == seg_num)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return mad_send_wr->cur_seg->data;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_get_rmpp_segment);
|
|
|
|
|
|
|
|
static inline void *ib_get_payload(struct ib_mad_send_wr_private *mad_send_wr)
|
|
|
|
{
|
|
|
|
if (mad_send_wr->send_buf.seg_count)
|
|
|
|
return ib_get_rmpp_segment(&mad_send_wr->send_buf,
|
|
|
|
mad_send_wr->seg_num);
|
|
|
|
else
|
|
|
|
return mad_send_wr->send_buf.mad +
|
|
|
|
mad_send_wr->send_buf.hdr_len;
|
|
|
|
}
|
|
|
|
|
2005-07-27 18:45:23 +00:00
|
|
|
void ib_free_send_mad(struct ib_mad_send_buf *send_buf)
|
|
|
|
{
|
|
|
|
struct ib_mad_agent_private *mad_agent_priv;
|
2006-03-04 05:54:13 +00:00
|
|
|
struct ib_mad_send_wr_private *mad_send_wr;
|
2005-07-27 18:45:23 +00:00
|
|
|
|
|
|
|
mad_agent_priv = container_of(send_buf->mad_agent,
|
|
|
|
struct ib_mad_agent_private, agent);
|
2006-03-04 05:54:13 +00:00
|
|
|
mad_send_wr = container_of(send_buf, struct ib_mad_send_wr_private,
|
|
|
|
send_buf);
|
2005-07-27 18:45:23 +00:00
|
|
|
|
2006-03-04 05:54:13 +00:00
|
|
|
free_send_rmpp_list(mad_send_wr);
|
|
|
|
kfree(send_buf->mad);
|
2006-05-12 21:57:52 +00:00
|
|
|
deref_mad_agent(mad_agent_priv);
|
2005-07-27 18:45:23 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_free_send_mad);
|
|
|
|
|
2005-07-27 18:45:37 +00:00
|
|
|
int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ib_mad_qp_info *qp_info;
|
2005-07-27 18:45:33 +00:00
|
|
|
struct list_head *list;
|
2005-10-25 17:51:39 +00:00
|
|
|
struct ib_send_wr *bad_send_wr;
|
|
|
|
struct ib_mad_agent *mad_agent;
|
|
|
|
struct ib_sge *sge;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
2005-07-27 18:45:24 +00:00
|
|
|
/* Set WR ID to find mad_send_wr upon completion */
|
2005-07-27 18:45:25 +00:00
|
|
|
qp_info = mad_send_wr->mad_agent_priv->qp_info;
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_send_wr->mad_list.mad_queue = &qp_info->send_queue;
|
2016-01-06 06:46:12 +00:00
|
|
|
mad_send_wr->mad_list.cqe.done = ib_mad_send_done;
|
|
|
|
mad_send_wr->send_wr.wr.wr_cqe = &mad_send_wr->mad_list.cqe;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_agent = mad_send_wr->send_buf.mad_agent;
|
|
|
|
sge = mad_send_wr->sg_list;
|
2006-12-12 22:28:30 +00:00
|
|
|
sge[0].addr = ib_dma_map_single(mad_agent->device,
|
|
|
|
mad_send_wr->send_buf.mad,
|
|
|
|
sge[0].length,
|
|
|
|
DMA_TO_DEVICE);
|
2014-03-11 12:41:47 +00:00
|
|
|
if (unlikely(ib_dma_mapping_error(mad_agent->device, sge[0].addr)))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2006-12-12 22:28:30 +00:00
|
|
|
mad_send_wr->header_mapping = sge[0].addr;
|
|
|
|
|
|
|
|
sge[1].addr = ib_dma_map_single(mad_agent->device,
|
|
|
|
ib_get_payload(mad_send_wr),
|
|
|
|
sge[1].length,
|
|
|
|
DMA_TO_DEVICE);
|
2014-03-11 12:41:47 +00:00
|
|
|
if (unlikely(ib_dma_mapping_error(mad_agent->device, sge[1].addr))) {
|
|
|
|
ib_dma_unmap_single(mad_agent->device,
|
|
|
|
mad_send_wr->header_mapping,
|
|
|
|
sge[0].length, DMA_TO_DEVICE);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2006-12-12 22:28:30 +00:00
|
|
|
mad_send_wr->payload_mapping = sge[1].addr;
|
2005-10-25 17:51:39 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&qp_info->send_queue.lock, flags);
|
2005-07-27 18:45:33 +00:00
|
|
|
if (qp_info->send_queue.count < qp_info->send_queue.max_active) {
|
2015-10-08 08:16:33 +00:00
|
|
|
ret = ib_post_send(mad_agent->qp, &mad_send_wr->send_wr.wr,
|
2005-10-25 17:51:39 +00:00
|
|
|
&bad_send_wr);
|
2005-07-27 18:45:33 +00:00
|
|
|
list = &qp_info->send_queue.list;
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
ret = 0;
|
2005-07-27 18:45:33 +00:00
|
|
|
list = &qp_info->overflow_list;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2005-07-27 18:45:33 +00:00
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
qp_info->send_queue.count++;
|
|
|
|
list_add_tail(&mad_send_wr->mad_list.list, list);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&qp_info->send_queue.lock, flags);
|
2006-03-04 05:54:13 +00:00
|
|
|
if (ret) {
|
2006-12-12 22:28:30 +00:00
|
|
|
ib_dma_unmap_single(mad_agent->device,
|
|
|
|
mad_send_wr->header_mapping,
|
|
|
|
sge[0].length, DMA_TO_DEVICE);
|
|
|
|
ib_dma_unmap_single(mad_agent->device,
|
|
|
|
mad_send_wr->payload_mapping,
|
|
|
|
sge[1].length, DMA_TO_DEVICE);
|
2006-03-04 05:54:13 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
|
|
|
|
* with the registered client
|
|
|
|
*/
|
2005-10-25 17:51:39 +00:00
|
|
|
int ib_post_send_mad(struct ib_mad_send_buf *send_buf,
|
|
|
|
struct ib_mad_send_buf **bad_send_buf)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ib_mad_agent_private *mad_agent_priv;
|
2005-10-25 17:51:39 +00:00
|
|
|
struct ib_mad_send_buf *next_send_buf;
|
|
|
|
struct ib_mad_send_wr_private *mad_send_wr;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret = -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Walk list of send WRs and post each on send list */
|
2005-10-25 17:51:39 +00:00
|
|
|
for (; send_buf; send_buf = next_send_buf) {
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_send_wr = container_of(send_buf,
|
|
|
|
struct ib_mad_send_wr_private,
|
|
|
|
send_buf);
|
|
|
|
mad_agent_priv = mad_send_wr->mad_agent_priv;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
if (!send_buf->mad_agent->send_handler ||
|
|
|
|
(send_buf->timeout_ms &&
|
|
|
|
!send_buf->mad_agent->recv_handler)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto error;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-29 00:40:04 +00:00
|
|
|
if (!ib_is_mad_class_rmpp(((struct ib_mad_hdr *) send_buf->mad)->mgmt_class)) {
|
|
|
|
if (mad_agent_priv->agent.rmpp_version) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Save pointer to next work request to post in case the
|
|
|
|
* current one completes, and the user modifies the work
|
|
|
|
* request associated with the completion
|
|
|
|
*/
|
2005-10-25 17:51:39 +00:00
|
|
|
next_send_buf = send_buf->next;
|
2015-10-08 08:16:33 +00:00
|
|
|
mad_send_wr->send_wr.ah = send_buf->ah;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
if (((struct ib_mad_hdr *) send_buf->mad)->mgmt_class ==
|
|
|
|
IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
|
|
|
|
ret = handle_outgoing_dr_smp(mad_agent_priv,
|
|
|
|
mad_send_wr);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ret < 0) /* error */
|
2005-10-25 17:51:39 +00:00
|
|
|
goto error;
|
2005-04-16 22:20:36 +00:00
|
|
|
else if (ret == 1) /* locally consumed */
|
2005-10-25 17:51:39 +00:00
|
|
|
continue;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_send_wr->tid = ((struct ib_mad_hdr *) send_buf->mad)->tid;
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Timeout will be updated after send completes */
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_send_wr->timeout = msecs_to_jiffies(send_buf->timeout_ms);
|
2007-11-27 08:11:04 +00:00
|
|
|
mad_send_wr->max_retries = send_buf->retries;
|
|
|
|
mad_send_wr->retries_left = send_buf->retries;
|
|
|
|
send_buf->retries = 0;
|
2005-10-25 17:51:39 +00:00
|
|
|
/* Reference for work request to QP + response */
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_send_wr->refcount = 1 + (mad_send_wr->timeout > 0);
|
|
|
|
mad_send_wr->status = IB_WC_SUCCESS;
|
|
|
|
|
|
|
|
/* Reference MAD agent until send completes */
|
|
|
|
atomic_inc(&mad_agent_priv->refcount);
|
|
|
|
spin_lock_irqsave(&mad_agent_priv->lock, flags);
|
|
|
|
list_add_tail(&mad_send_wr->agent_list,
|
|
|
|
&mad_agent_priv->send_list);
|
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
|
|
|
|
2014-08-08 23:00:56 +00:00
|
|
|
if (ib_mad_kernel_rmpp_agent(&mad_agent_priv->agent)) {
|
2005-07-27 18:45:37 +00:00
|
|
|
ret = ib_send_rmpp_mad(mad_send_wr);
|
|
|
|
if (ret >= 0 && ret != IB_RMPP_RESULT_CONSUMED)
|
|
|
|
ret = ib_send_mad(mad_send_wr);
|
|
|
|
} else
|
|
|
|
ret = ib_send_mad(mad_send_wr);
|
|
|
|
if (ret < 0) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Fail send request */
|
|
|
|
spin_lock_irqsave(&mad_agent_priv->lock, flags);
|
|
|
|
list_del(&mad_send_wr->agent_list);
|
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
|
|
|
atomic_dec(&mad_agent_priv->refcount);
|
2005-10-25 17:51:39 +00:00
|
|
|
goto error;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2005-10-25 17:51:39 +00:00
|
|
|
error:
|
|
|
|
if (bad_send_buf)
|
|
|
|
*bad_send_buf = send_buf;
|
2005-04-16 22:20:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_post_send_mad);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ib_free_recv_mad - Returns data buffers used to receive
|
|
|
|
* a MAD to the access layer
|
|
|
|
*/
|
|
|
|
void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc)
|
|
|
|
{
|
2005-07-27 18:45:37 +00:00
|
|
|
struct ib_mad_recv_buf *mad_recv_buf, *temp_recv_buf;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ib_mad_private_header *mad_priv_hdr;
|
|
|
|
struct ib_mad_private *priv;
|
2005-07-27 18:45:37 +00:00
|
|
|
struct list_head free_list;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-07-27 18:45:37 +00:00
|
|
|
INIT_LIST_HEAD(&free_list);
|
|
|
|
list_splice_init(&mad_recv_wc->rmpp_list, &free_list);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-07-27 18:45:37 +00:00
|
|
|
list_for_each_entry_safe(mad_recv_buf, temp_recv_buf,
|
|
|
|
&free_list, list) {
|
|
|
|
mad_recv_wc = container_of(mad_recv_buf, struct ib_mad_recv_wc,
|
|
|
|
recv_buf);
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_priv_hdr = container_of(mad_recv_wc,
|
|
|
|
struct ib_mad_private_header,
|
|
|
|
recv_wc);
|
|
|
|
priv = container_of(mad_priv_hdr, struct ib_mad_private,
|
|
|
|
header);
|
2015-06-06 18:38:30 +00:00
|
|
|
kfree(priv);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_free_recv_mad);
|
|
|
|
|
|
|
|
struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp,
|
|
|
|
u8 rmpp_version,
|
|
|
|
ib_mad_send_handler send_handler,
|
|
|
|
ib_mad_recv_handler recv_handler,
|
|
|
|
void *context)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-EINVAL); /* XXX: for now */
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_redirect_mad_qp);
|
|
|
|
|
|
|
|
int ib_process_mad_wc(struct ib_mad_agent *mad_agent,
|
|
|
|
struct ib_wc *wc)
|
|
|
|
{
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&mad_agent->device->dev,
|
|
|
|
"ib_process_mad_wc() not implemented yet\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_process_mad_wc);
|
|
|
|
|
|
|
|
static int method_in_use(struct ib_mad_mgmt_method_table **method,
|
|
|
|
struct ib_mad_reg_req *mad_reg_req)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-03-05 21:41:38 +00:00
|
|
|
for_each_set_bit(i, mad_reg_req->method_mask, IB_MGMT_MAX_METHODS) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if ((*method)->agent[i]) {
|
2014-08-08 23:00:53 +00:00
|
|
|
pr_err("Method %d already in use\n", i);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int allocate_method_table(struct ib_mad_mgmt_method_table **method)
|
|
|
|
{
|
|
|
|
/* Allocate management method table */
|
2005-11-02 15:23:14 +00:00
|
|
|
*method = kzalloc(sizeof **method, GFP_ATOMIC);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!*method) {
|
2014-08-08 23:00:53 +00:00
|
|
|
pr_err("No memory for ib_mad_mgmt_method_table\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if there are any methods still in use
|
|
|
|
*/
|
|
|
|
static int check_method_table(struct ib_mad_mgmt_method_table *method)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < IB_MGMT_MAX_METHODS; i++)
|
|
|
|
if (method->agent[i])
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if there are any method tables for this class still in use
|
|
|
|
*/
|
|
|
|
static int check_class_table(struct ib_mad_mgmt_class_table *class)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MGMT_CLASS; i++)
|
|
|
|
if (class->method_table[i])
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int check_vendor_class(struct ib_mad_mgmt_vendor_class *vendor_class)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MGMT_OUI; i++)
|
|
|
|
if (vendor_class->method_table[i])
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int find_vendor_oui(struct ib_mad_mgmt_vendor_class *vendor_class,
|
2015-06-06 18:38:22 +00:00
|
|
|
const char *oui)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MGMT_OUI; i++)
|
2006-09-22 22:22:46 +00:00
|
|
|
/* Is there matching OUI for this vendor class ? */
|
|
|
|
if (!memcmp(vendor_class->oui[i], oui, 3))
|
2005-04-16 22:20:36 +00:00
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int check_vendor_table(struct ib_mad_mgmt_vendor_class_table *vendor)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MGMT_VENDOR_RANGE2; i++)
|
|
|
|
if (vendor->vendor_class[i])
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_methods_mad_agent(struct ib_mad_mgmt_method_table *method,
|
|
|
|
struct ib_mad_agent_private *agent)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Remove any methods for this mad agent */
|
|
|
|
for (i = 0; i < IB_MGMT_MAX_METHODS; i++) {
|
|
|
|
if (method->agent[i] == agent) {
|
|
|
|
method->agent[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int add_nonoui_reg_req(struct ib_mad_reg_req *mad_reg_req,
|
|
|
|
struct ib_mad_agent_private *agent_priv,
|
|
|
|
u8 mgmt_class)
|
|
|
|
{
|
|
|
|
struct ib_mad_port_private *port_priv;
|
|
|
|
struct ib_mad_mgmt_class_table **class;
|
|
|
|
struct ib_mad_mgmt_method_table **method;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
port_priv = agent_priv->qp_info->port_priv;
|
|
|
|
class = &port_priv->version[mad_reg_req->mgmt_class_version].class;
|
|
|
|
if (!*class) {
|
|
|
|
/* Allocate management class table for "new" class version */
|
2005-11-02 15:23:14 +00:00
|
|
|
*class = kzalloc(sizeof **class, GFP_ATOMIC);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!*class) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&agent_priv->agent.device->dev,
|
|
|
|
"No memory for ib_mad_mgmt_class_table\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto error1;
|
|
|
|
}
|
2005-11-02 15:23:14 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Allocate method table for this management class */
|
|
|
|
method = &(*class)->method_table[mgmt_class];
|
|
|
|
if ((ret = allocate_method_table(method)))
|
|
|
|
goto error2;
|
|
|
|
} else {
|
|
|
|
method = &(*class)->method_table[mgmt_class];
|
|
|
|
if (!*method) {
|
|
|
|
/* Allocate method table for this management class */
|
|
|
|
if ((ret = allocate_method_table(method)))
|
|
|
|
goto error1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, make sure methods are not already in use */
|
|
|
|
if (method_in_use(method, mad_reg_req))
|
|
|
|
goto error3;
|
|
|
|
|
|
|
|
/* Finally, add in methods being registered */
|
2010-03-05 21:41:38 +00:00
|
|
|
for_each_set_bit(i, mad_reg_req->method_mask, IB_MGMT_MAX_METHODS)
|
2005-04-16 22:20:36 +00:00
|
|
|
(*method)->agent[i] = agent_priv;
|
2010-03-05 21:41:38 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error3:
|
|
|
|
/* Remove any methods for this mad agent */
|
|
|
|
remove_methods_mad_agent(*method, agent_priv);
|
|
|
|
/* Now, check to see if there are any methods in use */
|
|
|
|
if (!check_method_table(*method)) {
|
|
|
|
/* If not, release management method table */
|
|
|
|
kfree(*method);
|
|
|
|
*method = NULL;
|
|
|
|
}
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto error1;
|
|
|
|
error2:
|
|
|
|
kfree(*class);
|
|
|
|
*class = NULL;
|
|
|
|
error1:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int add_oui_reg_req(struct ib_mad_reg_req *mad_reg_req,
|
|
|
|
struct ib_mad_agent_private *agent_priv)
|
|
|
|
{
|
|
|
|
struct ib_mad_port_private *port_priv;
|
|
|
|
struct ib_mad_mgmt_vendor_class_table **vendor_table;
|
|
|
|
struct ib_mad_mgmt_vendor_class_table *vendor = NULL;
|
|
|
|
struct ib_mad_mgmt_vendor_class *vendor_class = NULL;
|
|
|
|
struct ib_mad_mgmt_method_table **method;
|
|
|
|
int i, ret = -ENOMEM;
|
|
|
|
u8 vclass;
|
|
|
|
|
|
|
|
/* "New" vendor (with OUI) class */
|
|
|
|
vclass = vendor_class_index(mad_reg_req->mgmt_class);
|
|
|
|
port_priv = agent_priv->qp_info->port_priv;
|
|
|
|
vendor_table = &port_priv->version[
|
|
|
|
mad_reg_req->mgmt_class_version].vendor;
|
|
|
|
if (!*vendor_table) {
|
|
|
|
/* Allocate mgmt vendor class table for "new" class version */
|
2005-11-02 15:23:14 +00:00
|
|
|
vendor = kzalloc(sizeof *vendor, GFP_ATOMIC);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!vendor) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&agent_priv->agent.device->dev,
|
|
|
|
"No memory for ib_mad_mgmt_vendor_class_table\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error1;
|
|
|
|
}
|
2005-11-02 15:23:14 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
*vendor_table = vendor;
|
|
|
|
}
|
|
|
|
if (!(*vendor_table)->vendor_class[vclass]) {
|
|
|
|
/* Allocate table for this management vendor class */
|
2005-11-02 15:23:14 +00:00
|
|
|
vendor_class = kzalloc(sizeof *vendor_class, GFP_ATOMIC);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!vendor_class) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&agent_priv->agent.device->dev,
|
|
|
|
"No memory for ib_mad_mgmt_vendor_class\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error2;
|
|
|
|
}
|
2005-11-02 15:23:14 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
(*vendor_table)->vendor_class[vclass] = vendor_class;
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_MGMT_OUI; i++) {
|
|
|
|
/* Is there matching OUI for this vendor class ? */
|
|
|
|
if (!memcmp((*vendor_table)->vendor_class[vclass]->oui[i],
|
|
|
|
mad_reg_req->oui, 3)) {
|
|
|
|
method = &(*vendor_table)->vendor_class[
|
|
|
|
vclass]->method_table[i];
|
|
|
|
BUG_ON(!*method);
|
|
|
|
goto check_in_use;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_MGMT_OUI; i++) {
|
|
|
|
/* OUI slot available ? */
|
|
|
|
if (!is_vendor_oui((*vendor_table)->vendor_class[
|
|
|
|
vclass]->oui[i])) {
|
|
|
|
method = &(*vendor_table)->vendor_class[
|
|
|
|
vclass]->method_table[i];
|
|
|
|
BUG_ON(*method);
|
|
|
|
/* Allocate method table for this OUI */
|
|
|
|
if ((ret = allocate_method_table(method)))
|
|
|
|
goto error3;
|
|
|
|
memcpy((*vendor_table)->vendor_class[vclass]->oui[i],
|
|
|
|
mad_reg_req->oui, 3);
|
|
|
|
goto check_in_use;
|
|
|
|
}
|
|
|
|
}
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&agent_priv->agent.device->dev, "All OUI slots in use\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error3;
|
|
|
|
|
|
|
|
check_in_use:
|
|
|
|
/* Now, make sure methods are not already in use */
|
|
|
|
if (method_in_use(method, mad_reg_req))
|
|
|
|
goto error4;
|
|
|
|
|
|
|
|
/* Finally, add in methods being registered */
|
2010-03-05 21:41:38 +00:00
|
|
|
for_each_set_bit(i, mad_reg_req->method_mask, IB_MGMT_MAX_METHODS)
|
2005-04-16 22:20:36 +00:00
|
|
|
(*method)->agent[i] = agent_priv;
|
2010-03-05 21:41:38 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error4:
|
|
|
|
/* Remove any methods for this mad agent */
|
|
|
|
remove_methods_mad_agent(*method, agent_priv);
|
|
|
|
/* Now, check to see if there are any methods in use */
|
|
|
|
if (!check_method_table(*method)) {
|
|
|
|
/* If not, release management method table */
|
|
|
|
kfree(*method);
|
|
|
|
*method = NULL;
|
|
|
|
}
|
|
|
|
ret = -EINVAL;
|
|
|
|
error3:
|
|
|
|
if (vendor_class) {
|
|
|
|
(*vendor_table)->vendor_class[vclass] = NULL;
|
|
|
|
kfree(vendor_class);
|
|
|
|
}
|
|
|
|
error2:
|
|
|
|
if (vendor) {
|
|
|
|
*vendor_table = NULL;
|
|
|
|
kfree(vendor);
|
|
|
|
}
|
|
|
|
error1:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_mad_reg_req(struct ib_mad_agent_private *agent_priv)
|
|
|
|
{
|
|
|
|
struct ib_mad_port_private *port_priv;
|
|
|
|
struct ib_mad_mgmt_class_table *class;
|
|
|
|
struct ib_mad_mgmt_method_table *method;
|
|
|
|
struct ib_mad_mgmt_vendor_class_table *vendor;
|
|
|
|
struct ib_mad_mgmt_vendor_class *vendor_class;
|
|
|
|
int index;
|
|
|
|
u8 mgmt_class;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Was MAD registration request supplied
|
|
|
|
* with original registration ?
|
|
|
|
*/
|
|
|
|
if (!agent_priv->reg_req) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
port_priv = agent_priv->qp_info->port_priv;
|
|
|
|
mgmt_class = convert_mgmt_class(agent_priv->reg_req->mgmt_class);
|
|
|
|
class = port_priv->version[
|
|
|
|
agent_priv->reg_req->mgmt_class_version].class;
|
|
|
|
if (!class)
|
|
|
|
goto vendor_check;
|
|
|
|
|
|
|
|
method = class->method_table[mgmt_class];
|
|
|
|
if (method) {
|
|
|
|
/* Remove any methods for this mad agent */
|
|
|
|
remove_methods_mad_agent(method, agent_priv);
|
|
|
|
/* Now, check to see if there are any methods still in use */
|
|
|
|
if (!check_method_table(method)) {
|
|
|
|
/* If not, release management method table */
|
|
|
|
kfree(method);
|
|
|
|
class->method_table[mgmt_class] = NULL;
|
|
|
|
/* Any management classes left ? */
|
|
|
|
if (!check_class_table(class)) {
|
|
|
|
/* If not, release management class table */
|
|
|
|
kfree(class);
|
|
|
|
port_priv->version[
|
|
|
|
agent_priv->reg_req->
|
|
|
|
mgmt_class_version].class = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vendor_check:
|
|
|
|
if (!is_vendor_class(mgmt_class))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* normalize mgmt_class to vendor range 2 */
|
|
|
|
mgmt_class = vendor_class_index(agent_priv->reg_req->mgmt_class);
|
|
|
|
vendor = port_priv->version[
|
|
|
|
agent_priv->reg_req->mgmt_class_version].vendor;
|
|
|
|
|
|
|
|
if (!vendor)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
vendor_class = vendor->vendor_class[mgmt_class];
|
|
|
|
if (vendor_class) {
|
|
|
|
index = find_vendor_oui(vendor_class, agent_priv->reg_req->oui);
|
|
|
|
if (index < 0)
|
|
|
|
goto out;
|
|
|
|
method = vendor_class->method_table[index];
|
|
|
|
if (method) {
|
|
|
|
/* Remove any methods for this mad agent */
|
|
|
|
remove_methods_mad_agent(method, agent_priv);
|
|
|
|
/*
|
|
|
|
* Now, check to see if there are
|
|
|
|
* any methods still in use
|
|
|
|
*/
|
|
|
|
if (!check_method_table(method)) {
|
|
|
|
/* If not, release management method table */
|
|
|
|
kfree(method);
|
|
|
|
vendor_class->method_table[index] = NULL;
|
|
|
|
memset(vendor_class->oui[index], 0, 3);
|
|
|
|
/* Any OUIs left ? */
|
|
|
|
if (!check_vendor_class(vendor_class)) {
|
|
|
|
/* If not, release vendor class table */
|
|
|
|
kfree(vendor_class);
|
|
|
|
vendor->vendor_class[mgmt_class] = NULL;
|
|
|
|
/* Any other vendor classes left ? */
|
|
|
|
if (!check_vendor_table(vendor)) {
|
|
|
|
kfree(vendor);
|
|
|
|
port_priv->version[
|
|
|
|
agent_priv->reg_req->
|
|
|
|
mgmt_class_version].
|
|
|
|
vendor = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ib_mad_agent_private *
|
|
|
|
find_mad_agent(struct ib_mad_port_private *port_priv,
|
2015-06-06 18:38:22 +00:00
|
|
|
const struct ib_mad_hdr *mad_hdr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ib_mad_agent_private *mad_agent = NULL;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&port_priv->reg_lock, flags);
|
2015-06-06 18:38:22 +00:00
|
|
|
if (ib_response_mad(mad_hdr)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
u32 hi_tid;
|
|
|
|
struct ib_mad_agent_private *entry;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routing is based on high 32 bits of transaction ID
|
|
|
|
* of MAD.
|
|
|
|
*/
|
2015-06-06 18:38:22 +00:00
|
|
|
hi_tid = be64_to_cpu(mad_hdr->tid) >> 32;
|
2005-10-25 17:51:39 +00:00
|
|
|
list_for_each_entry(entry, &port_priv->agent_list, agent_list) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (entry->agent.hi_tid == hi_tid) {
|
|
|
|
mad_agent = entry;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct ib_mad_mgmt_class_table *class;
|
|
|
|
struct ib_mad_mgmt_method_table *method;
|
|
|
|
struct ib_mad_mgmt_vendor_class_table *vendor;
|
|
|
|
struct ib_mad_mgmt_vendor_class *vendor_class;
|
2015-06-06 18:38:22 +00:00
|
|
|
const struct ib_vendor_mad *vendor_mad;
|
2005-04-16 22:20:36 +00:00
|
|
|
int index;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routing is based on version, class, and method
|
|
|
|
* For "newer" vendor MADs, also based on OUI
|
|
|
|
*/
|
2015-06-06 18:38:22 +00:00
|
|
|
if (mad_hdr->class_version >= MAX_MGMT_VERSION)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
2015-06-06 18:38:22 +00:00
|
|
|
if (!is_vendor_class(mad_hdr->mgmt_class)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
class = port_priv->version[
|
2015-06-06 18:38:22 +00:00
|
|
|
mad_hdr->class_version].class;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!class)
|
|
|
|
goto out;
|
2015-06-06 18:38:22 +00:00
|
|
|
if (convert_mgmt_class(mad_hdr->mgmt_class) >=
|
2011-10-06 16:33:05 +00:00
|
|
|
IB_MGMT_MAX_METHODS)
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
method = class->method_table[convert_mgmt_class(
|
2015-06-06 18:38:22 +00:00
|
|
|
mad_hdr->mgmt_class)];
|
2005-04-16 22:20:36 +00:00
|
|
|
if (method)
|
2015-06-06 18:38:22 +00:00
|
|
|
mad_agent = method->agent[mad_hdr->method &
|
2005-04-16 22:20:36 +00:00
|
|
|
~IB_MGMT_METHOD_RESP];
|
|
|
|
} else {
|
|
|
|
vendor = port_priv->version[
|
2015-06-06 18:38:22 +00:00
|
|
|
mad_hdr->class_version].vendor;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!vendor)
|
|
|
|
goto out;
|
|
|
|
vendor_class = vendor->vendor_class[vendor_class_index(
|
2015-06-06 18:38:22 +00:00
|
|
|
mad_hdr->mgmt_class)];
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!vendor_class)
|
|
|
|
goto out;
|
|
|
|
/* Find matching OUI */
|
2015-06-06 18:38:22 +00:00
|
|
|
vendor_mad = (const struct ib_vendor_mad *)mad_hdr;
|
2005-04-16 22:20:36 +00:00
|
|
|
index = find_vendor_oui(vendor_class, vendor_mad->oui);
|
|
|
|
if (index == -1)
|
|
|
|
goto out;
|
|
|
|
method = vendor_class->method_table[index];
|
|
|
|
if (method) {
|
2015-06-06 18:38:22 +00:00
|
|
|
mad_agent = method->agent[mad_hdr->method &
|
2005-04-16 22:20:36 +00:00
|
|
|
~IB_MGMT_METHOD_RESP];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mad_agent) {
|
|
|
|
if (mad_agent->agent.recv_handler)
|
|
|
|
atomic_inc(&mad_agent->refcount);
|
|
|
|
else {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_notice(&port_priv->device->dev,
|
|
|
|
"No receive handler for client %p on port %d\n",
|
|
|
|
&mad_agent->agent, port_priv->port_num);
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_agent = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
spin_unlock_irqrestore(&port_priv->reg_lock, flags);
|
|
|
|
|
|
|
|
return mad_agent;
|
|
|
|
}
|
|
|
|
|
2015-06-10 20:16:48 +00:00
|
|
|
static int validate_mad(const struct ib_mad_hdr *mad_hdr,
|
|
|
|
const struct ib_mad_qp_info *qp_info,
|
|
|
|
bool opa)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int valid = 0;
|
2015-06-10 20:16:48 +00:00
|
|
|
u32 qp_num = qp_info->qp->qp_num;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Make sure MAD base version is understood */
|
2015-06-10 20:16:48 +00:00
|
|
|
if (mad_hdr->base_version != IB_MGMT_BASE_VERSION &&
|
|
|
|
(!opa || mad_hdr->base_version != OPA_MGMT_BASE_VERSION)) {
|
|
|
|
pr_err("MAD received with unsupported base version %d %s\n",
|
|
|
|
mad_hdr->base_version, opa ? "(opa)" : "");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Filter SMI packets sent to other than QP0 */
|
2015-05-08 18:27:21 +00:00
|
|
|
if ((mad_hdr->mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED) ||
|
|
|
|
(mad_hdr->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (qp_num == 0)
|
|
|
|
valid = 1;
|
|
|
|
} else {
|
2015-11-13 20:22:22 +00:00
|
|
|
/* CM attributes other than ClassPortInfo only use Send method */
|
|
|
|
if ((mad_hdr->mgmt_class == IB_MGMT_CLASS_CM) &&
|
|
|
|
(mad_hdr->attr_id != IB_MGMT_CLASSPORTINFO_ATTR_ID) &&
|
|
|
|
(mad_hdr->method != IB_MGMT_METHOD_SEND))
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Filter GSI packets sent to QP0 */
|
|
|
|
if (qp_num != 0)
|
|
|
|
valid = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2015-05-08 18:27:24 +00:00
|
|
|
static int is_rmpp_data_mad(const struct ib_mad_agent_private *mad_agent_priv,
|
|
|
|
const struct ib_mad_hdr *mad_hdr)
|
2005-07-27 18:45:37 +00:00
|
|
|
{
|
|
|
|
struct ib_rmpp_mad *rmpp_mad;
|
|
|
|
|
|
|
|
rmpp_mad = (struct ib_rmpp_mad *)mad_hdr;
|
|
|
|
return !mad_agent_priv->agent.rmpp_version ||
|
2014-08-08 23:00:56 +00:00
|
|
|
!ib_mad_kernel_rmpp_agent(&mad_agent_priv->agent) ||
|
2005-07-27 18:45:37 +00:00
|
|
|
!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
|
|
|
|
IB_MGMT_RMPP_FLAG_ACTIVE) ||
|
|
|
|
(rmpp_mad->rmpp_hdr.rmpp_type == IB_MGMT_RMPP_TYPE_DATA);
|
|
|
|
}
|
|
|
|
|
2015-05-08 18:27:23 +00:00
|
|
|
static inline int rcv_has_same_class(const struct ib_mad_send_wr_private *wr,
|
|
|
|
const struct ib_mad_recv_wc *rwc)
|
2006-03-29 00:39:07 +00:00
|
|
|
{
|
2015-05-08 18:27:23 +00:00
|
|
|
return ((struct ib_mad_hdr *)(wr->send_buf.mad))->mgmt_class ==
|
2006-03-29 00:39:07 +00:00
|
|
|
rwc->recv_buf.mad->mad_hdr.mgmt_class;
|
|
|
|
}
|
|
|
|
|
2015-05-08 18:27:24 +00:00
|
|
|
static inline int rcv_has_same_gid(const struct ib_mad_agent_private *mad_agent_priv,
|
|
|
|
const struct ib_mad_send_wr_private *wr,
|
|
|
|
const struct ib_mad_recv_wc *rwc )
|
2006-03-29 00:39:07 +00:00
|
|
|
{
|
|
|
|
struct ib_ah_attr attr;
|
|
|
|
u8 send_resp, rcv_resp;
|
2006-06-18 03:37:34 +00:00
|
|
|
union ib_gid sgid;
|
|
|
|
struct ib_device *device = mad_agent_priv->agent.device;
|
|
|
|
u8 port_num = mad_agent_priv->agent.port_num;
|
|
|
|
u8 lmc;
|
2006-03-29 00:39:07 +00:00
|
|
|
|
2015-05-08 18:27:22 +00:00
|
|
|
send_resp = ib_response_mad((struct ib_mad_hdr *)wr->send_buf.mad);
|
|
|
|
rcv_resp = ib_response_mad(&rwc->recv_buf.mad->mad_hdr);
|
2006-03-29 00:39:07 +00:00
|
|
|
|
|
|
|
if (send_resp == rcv_resp)
|
|
|
|
/* both requests, or both responses. GIDs different */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ib_query_ah(wr->send_buf.ah, &attr))
|
|
|
|
/* Assume not equal, to avoid false positives. */
|
|
|
|
return 0;
|
|
|
|
|
2006-06-18 03:37:34 +00:00
|
|
|
if (!!(attr.ah_flags & IB_AH_GRH) !=
|
|
|
|
!!(rwc->wc->wc_flags & IB_WC_GRH))
|
2006-03-29 00:39:07 +00:00
|
|
|
/* one has GID, other does not. Assume different */
|
|
|
|
return 0;
|
2006-06-18 03:37:34 +00:00
|
|
|
|
|
|
|
if (!send_resp && rcv_resp) {
|
|
|
|
/* is request/response. */
|
|
|
|
if (!(attr.ah_flags & IB_AH_GRH)) {
|
|
|
|
if (ib_get_cached_lmc(device, port_num, &lmc))
|
|
|
|
return 0;
|
|
|
|
return (!lmc || !((attr.src_path_bits ^
|
|
|
|
rwc->wc->dlid_path_bits) &
|
|
|
|
((1 << lmc) - 1)));
|
|
|
|
} else {
|
|
|
|
if (ib_get_cached_gid(device, port_num,
|
2015-10-15 15:38:45 +00:00
|
|
|
attr.grh.sgid_index, &sgid, NULL))
|
2006-06-18 03:37:34 +00:00
|
|
|
return 0;
|
|
|
|
return !memcmp(sgid.raw, rwc->recv_buf.grh->dgid.raw,
|
|
|
|
16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(attr.ah_flags & IB_AH_GRH))
|
|
|
|
return attr.dlid == rwc->wc->slid;
|
|
|
|
else
|
|
|
|
return !memcmp(attr.grh.dgid.raw, rwc->recv_buf.grh->sgid.raw,
|
|
|
|
16);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_direct(u8 class)
|
|
|
|
{
|
|
|
|
return (class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE);
|
2006-03-29 00:39:07 +00:00
|
|
|
}
|
2006-06-18 03:37:34 +00:00
|
|
|
|
2005-07-27 18:45:37 +00:00
|
|
|
struct ib_mad_send_wr_private*
|
2015-05-08 18:27:24 +00:00
|
|
|
ib_find_send_mad(const struct ib_mad_agent_private *mad_agent_priv,
|
|
|
|
const struct ib_mad_recv_wc *wc)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-06-18 03:37:34 +00:00
|
|
|
struct ib_mad_send_wr_private *wr;
|
2015-06-06 18:38:23 +00:00
|
|
|
const struct ib_mad_hdr *mad_hdr;
|
2006-03-29 00:39:07 +00:00
|
|
|
|
2015-06-06 18:38:23 +00:00
|
|
|
mad_hdr = &wc->recv_buf.mad->mad_hdr;
|
2006-06-18 03:37:34 +00:00
|
|
|
|
|
|
|
list_for_each_entry(wr, &mad_agent_priv->wait_list, agent_list) {
|
2015-06-06 18:38:23 +00:00
|
|
|
if ((wr->tid == mad_hdr->tid) &&
|
2006-06-18 03:37:34 +00:00
|
|
|
rcv_has_same_class(wr, wc) &&
|
|
|
|
/*
|
|
|
|
* Don't check GID for direct routed MADs.
|
|
|
|
* These might have permissive LIDs.
|
|
|
|
*/
|
2015-06-06 18:38:23 +00:00
|
|
|
(is_direct(mad_hdr->mgmt_class) ||
|
2006-06-18 03:37:34 +00:00
|
|
|
rcv_has_same_gid(mad_agent_priv, wr, wc)))
|
2006-11-13 17:38:07 +00:00
|
|
|
return (wr->status == IB_WC_SUCCESS) ? wr : NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It's possible to receive the response before we've
|
|
|
|
* been notified that the send has completed
|
|
|
|
*/
|
2006-06-18 03:37:34 +00:00
|
|
|
list_for_each_entry(wr, &mad_agent_priv->send_list, agent_list) {
|
2015-05-08 17:10:03 +00:00
|
|
|
if (is_rmpp_data_mad(mad_agent_priv, wr->send_buf.mad) &&
|
2015-06-06 18:38:23 +00:00
|
|
|
wr->tid == mad_hdr->tid &&
|
2006-06-18 03:37:34 +00:00
|
|
|
wr->timeout &&
|
|
|
|
rcv_has_same_class(wr, wc) &&
|
|
|
|
/*
|
|
|
|
* Don't check GID for direct routed MADs.
|
|
|
|
* These might have permissive LIDs.
|
|
|
|
*/
|
2015-06-06 18:38:23 +00:00
|
|
|
(is_direct(mad_hdr->mgmt_class) ||
|
2006-06-18 03:37:34 +00:00
|
|
|
rcv_has_same_gid(mad_agent_priv, wr, wc)))
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Verify request has not been canceled */
|
2006-06-18 03:37:34 +00:00
|
|
|
return (wr->status == IB_WC_SUCCESS) ? wr : NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-27 18:45:37 +00:00
|
|
|
void ib_mark_mad_done(struct ib_mad_send_wr_private *mad_send_wr)
|
2005-07-27 18:45:26 +00:00
|
|
|
{
|
|
|
|
mad_send_wr->timeout = 0;
|
2006-06-26 07:24:41 +00:00
|
|
|
if (mad_send_wr->refcount == 1)
|
|
|
|
list_move_tail(&mad_send_wr->agent_list,
|
2005-07-27 18:45:26 +00:00
|
|
|
&mad_send_wr->mad_agent_priv->done_list);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,
|
2005-07-27 18:45:24 +00:00
|
|
|
struct ib_mad_recv_wc *mad_recv_wc)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ib_mad_send_wr_private *mad_send_wr;
|
|
|
|
struct ib_mad_send_wc mad_send_wc;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2005-07-27 18:45:37 +00:00
|
|
|
INIT_LIST_HEAD(&mad_recv_wc->rmpp_list);
|
|
|
|
list_add(&mad_recv_wc->recv_buf.list, &mad_recv_wc->rmpp_list);
|
2014-08-08 23:00:56 +00:00
|
|
|
if (ib_mad_kernel_rmpp_agent(&mad_agent_priv->agent)) {
|
2005-07-27 18:45:37 +00:00
|
|
|
mad_recv_wc = ib_process_rmpp_recv_wc(mad_agent_priv,
|
|
|
|
mad_recv_wc);
|
|
|
|
if (!mad_recv_wc) {
|
2006-05-12 21:57:52 +00:00
|
|
|
deref_mad_agent(mad_agent_priv);
|
2005-07-27 18:45:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Complete corresponding request */
|
2015-05-08 18:27:22 +00:00
|
|
|
if (ib_response_mad(&mad_recv_wc->recv_buf.mad->mad_hdr)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&mad_agent_priv->lock, flags);
|
2006-03-29 00:39:07 +00:00
|
|
|
mad_send_wr = ib_find_send_mad(mad_agent_priv, mad_recv_wc);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!mad_send_wr) {
|
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
2014-08-08 23:00:56 +00:00
|
|
|
if (!ib_mad_kernel_rmpp_agent(&mad_agent_priv->agent)
|
|
|
|
&& ib_is_mad_class_rmpp(mad_recv_wc->recv_buf.mad->mad_hdr.mgmt_class)
|
|
|
|
&& (ib_get_rmpp_flags(&((struct ib_rmpp_mad *)mad_recv_wc->recv_buf.mad)->rmpp_hdr)
|
|
|
|
& IB_MGMT_RMPP_FLAG_ACTIVE)) {
|
|
|
|
/* user rmpp is in effect
|
|
|
|
* and this is an active RMPP MAD
|
|
|
|
*/
|
2016-01-04 13:15:58 +00:00
|
|
|
mad_agent_priv->agent.recv_handler(
|
|
|
|
&mad_agent_priv->agent, NULL,
|
|
|
|
mad_recv_wc);
|
2014-08-08 23:00:56 +00:00
|
|
|
atomic_dec(&mad_agent_priv->refcount);
|
|
|
|
} else {
|
|
|
|
/* not user rmpp, revert to normal behavior and
|
|
|
|
* drop the mad */
|
|
|
|
ib_free_recv_mad(mad_recv_wc);
|
|
|
|
deref_mad_agent(mad_agent_priv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ib_mark_mad_done(mad_send_wr);
|
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-08-08 23:00:56 +00:00
|
|
|
/* Defined behavior is to complete response before request */
|
2016-01-04 13:15:58 +00:00
|
|
|
mad_agent_priv->agent.recv_handler(
|
|
|
|
&mad_agent_priv->agent,
|
|
|
|
&mad_send_wr->send_buf,
|
|
|
|
mad_recv_wc);
|
2014-08-08 23:00:56 +00:00
|
|
|
atomic_dec(&mad_agent_priv->refcount);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-08-08 23:00:56 +00:00
|
|
|
mad_send_wc.status = IB_WC_SUCCESS;
|
|
|
|
mad_send_wc.vendor_err = 0;
|
|
|
|
mad_send_wc.send_buf = &mad_send_wr->send_buf;
|
|
|
|
ib_mad_complete_send_wr(mad_send_wr, &mad_send_wc);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2016-01-04 13:15:58 +00:00
|
|
|
mad_agent_priv->agent.recv_handler(&mad_agent_priv->agent, NULL,
|
2005-07-27 18:45:24 +00:00
|
|
|
mad_recv_wc);
|
2006-05-12 21:57:52 +00:00
|
|
|
deref_mad_agent(mad_agent_priv);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 18:38:24 +00:00
|
|
|
static enum smi_action handle_ib_smi(const struct ib_mad_port_private *port_priv,
|
|
|
|
const struct ib_mad_qp_info *qp_info,
|
|
|
|
const struct ib_wc *wc,
|
|
|
|
int port_num,
|
|
|
|
struct ib_mad_private *recv,
|
|
|
|
struct ib_mad_private *response)
|
|
|
|
{
|
|
|
|
enum smi_forward_action retsmi;
|
2015-06-06 18:38:30 +00:00
|
|
|
struct ib_smp *smp = (struct ib_smp *)recv->mad;
|
2015-06-06 18:38:24 +00:00
|
|
|
|
2015-06-06 18:38:30 +00:00
|
|
|
if (smi_handle_dr_smp_recv(smp,
|
2015-06-29 13:57:00 +00:00
|
|
|
rdma_cap_ib_switch(port_priv->device),
|
2015-06-06 18:38:24 +00:00
|
|
|
port_num,
|
|
|
|
port_priv->device->phys_port_cnt) ==
|
|
|
|
IB_SMI_DISCARD)
|
|
|
|
return IB_SMI_DISCARD;
|
|
|
|
|
2015-06-06 18:38:30 +00:00
|
|
|
retsmi = smi_check_forward_dr_smp(smp);
|
2015-06-06 18:38:24 +00:00
|
|
|
if (retsmi == IB_SMI_LOCAL)
|
|
|
|
return IB_SMI_HANDLE;
|
|
|
|
|
|
|
|
if (retsmi == IB_SMI_SEND) { /* don't forward */
|
2015-06-06 18:38:30 +00:00
|
|
|
if (smi_handle_dr_smp_send(smp,
|
2015-06-29 13:57:00 +00:00
|
|
|
rdma_cap_ib_switch(port_priv->device),
|
2015-06-06 18:38:24 +00:00
|
|
|
port_num) == IB_SMI_DISCARD)
|
|
|
|
return IB_SMI_DISCARD;
|
|
|
|
|
2015-06-06 18:38:30 +00:00
|
|
|
if (smi_check_local_smp(smp, port_priv->device) == IB_SMI_DISCARD)
|
2015-06-06 18:38:24 +00:00
|
|
|
return IB_SMI_DISCARD;
|
2015-06-29 13:57:00 +00:00
|
|
|
} else if (rdma_cap_ib_switch(port_priv->device)) {
|
2015-06-06 18:38:24 +00:00
|
|
|
/* forward case for switches */
|
2015-06-06 18:38:30 +00:00
|
|
|
memcpy(response, recv, mad_priv_size(response));
|
2015-06-06 18:38:24 +00:00
|
|
|
response->header.recv_wc.wc = &response->header.wc;
|
2015-06-06 18:38:30 +00:00
|
|
|
response->header.recv_wc.recv_buf.mad = (struct ib_mad *)response->mad;
|
2015-06-06 18:38:24 +00:00
|
|
|
response->header.recv_wc.recv_buf.grh = &response->grh;
|
|
|
|
|
2015-06-06 18:38:30 +00:00
|
|
|
agent_send_response((const struct ib_mad_hdr *)response->mad,
|
2015-06-06 18:38:24 +00:00
|
|
|
&response->grh, wc,
|
|
|
|
port_priv->device,
|
2015-06-06 18:38:30 +00:00
|
|
|
smi_get_fwd_port(smp),
|
|
|
|
qp_info->qp->qp_num,
|
2015-06-10 20:16:48 +00:00
|
|
|
response->mad_size,
|
|
|
|
false);
|
2015-06-06 18:38:24 +00:00
|
|
|
|
|
|
|
return IB_SMI_DISCARD;
|
|
|
|
}
|
|
|
|
return IB_SMI_HANDLE;
|
|
|
|
}
|
|
|
|
|
2015-06-06 18:38:30 +00:00
|
|
|
static bool generate_unmatched_resp(const struct ib_mad_private *recv,
|
2015-06-10 20:16:48 +00:00
|
|
|
struct ib_mad_private *response,
|
|
|
|
size_t *resp_len, bool opa)
|
2012-02-26 01:47:32 +00:00
|
|
|
{
|
2015-06-06 18:38:30 +00:00
|
|
|
const struct ib_mad_hdr *recv_hdr = (const struct ib_mad_hdr *)recv->mad;
|
|
|
|
struct ib_mad_hdr *resp_hdr = (struct ib_mad_hdr *)response->mad;
|
|
|
|
|
|
|
|
if (recv_hdr->method == IB_MGMT_METHOD_GET ||
|
|
|
|
recv_hdr->method == IB_MGMT_METHOD_SET) {
|
|
|
|
memcpy(response, recv, mad_priv_size(response));
|
2012-02-26 01:47:32 +00:00
|
|
|
response->header.recv_wc.wc = &response->header.wc;
|
2015-06-06 18:38:30 +00:00
|
|
|
response->header.recv_wc.recv_buf.mad = (struct ib_mad *)response->mad;
|
2012-02-26 01:47:32 +00:00
|
|
|
response->header.recv_wc.recv_buf.grh = &response->grh;
|
2015-06-06 18:38:30 +00:00
|
|
|
resp_hdr->method = IB_MGMT_METHOD_GET_RESP;
|
|
|
|
resp_hdr->status = cpu_to_be16(IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB);
|
|
|
|
if (recv_hdr->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
|
|
|
|
resp_hdr->status |= IB_SMP_DIRECTION;
|
2012-02-26 01:47:32 +00:00
|
|
|
|
2015-06-10 20:16:48 +00:00
|
|
|
if (opa && recv_hdr->base_version == OPA_MGMT_BASE_VERSION) {
|
|
|
|
if (recv_hdr->mgmt_class ==
|
|
|
|
IB_MGMT_CLASS_SUBN_LID_ROUTED ||
|
|
|
|
recv_hdr->mgmt_class ==
|
|
|
|
IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
|
|
|
|
*resp_len = opa_get_smp_header_size(
|
|
|
|
(struct opa_smp *)recv->mad);
|
|
|
|
else
|
|
|
|
*resp_len = sizeof(struct ib_mad_hdr);
|
|
|
|
}
|
|
|
|
|
2012-02-26 01:47:32 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-06-10 20:16:48 +00:00
|
|
|
|
|
|
|
static enum smi_action
|
|
|
|
handle_opa_smi(struct ib_mad_port_private *port_priv,
|
|
|
|
struct ib_mad_qp_info *qp_info,
|
|
|
|
struct ib_wc *wc,
|
|
|
|
int port_num,
|
|
|
|
struct ib_mad_private *recv,
|
|
|
|
struct ib_mad_private *response)
|
|
|
|
{
|
|
|
|
enum smi_forward_action retsmi;
|
|
|
|
struct opa_smp *smp = (struct opa_smp *)recv->mad;
|
|
|
|
|
|
|
|
if (opa_smi_handle_dr_smp_recv(smp,
|
2015-06-29 13:57:00 +00:00
|
|
|
rdma_cap_ib_switch(port_priv->device),
|
2015-06-10 20:16:48 +00:00
|
|
|
port_num,
|
|
|
|
port_priv->device->phys_port_cnt) ==
|
|
|
|
IB_SMI_DISCARD)
|
|
|
|
return IB_SMI_DISCARD;
|
|
|
|
|
|
|
|
retsmi = opa_smi_check_forward_dr_smp(smp);
|
|
|
|
if (retsmi == IB_SMI_LOCAL)
|
|
|
|
return IB_SMI_HANDLE;
|
|
|
|
|
|
|
|
if (retsmi == IB_SMI_SEND) { /* don't forward */
|
|
|
|
if (opa_smi_handle_dr_smp_send(smp,
|
2015-06-29 13:57:00 +00:00
|
|
|
rdma_cap_ib_switch(port_priv->device),
|
2015-06-10 20:16:48 +00:00
|
|
|
port_num) == IB_SMI_DISCARD)
|
|
|
|
return IB_SMI_DISCARD;
|
|
|
|
|
|
|
|
if (opa_smi_check_local_smp(smp, port_priv->device) ==
|
|
|
|
IB_SMI_DISCARD)
|
|
|
|
return IB_SMI_DISCARD;
|
|
|
|
|
2015-06-29 13:57:00 +00:00
|
|
|
} else if (rdma_cap_ib_switch(port_priv->device)) {
|
2015-06-10 20:16:48 +00:00
|
|
|
/* forward case for switches */
|
|
|
|
memcpy(response, recv, mad_priv_size(response));
|
|
|
|
response->header.recv_wc.wc = &response->header.wc;
|
|
|
|
response->header.recv_wc.recv_buf.opa_mad =
|
|
|
|
(struct opa_mad *)response->mad;
|
|
|
|
response->header.recv_wc.recv_buf.grh = &response->grh;
|
|
|
|
|
|
|
|
agent_send_response((const struct ib_mad_hdr *)response->mad,
|
|
|
|
&response->grh, wc,
|
|
|
|
port_priv->device,
|
|
|
|
opa_smi_get_fwd_port(smp),
|
|
|
|
qp_info->qp->qp_num,
|
|
|
|
recv->header.wc.byte_len,
|
|
|
|
true);
|
|
|
|
|
|
|
|
return IB_SMI_DISCARD;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IB_SMI_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum smi_action
|
|
|
|
handle_smi(struct ib_mad_port_private *port_priv,
|
|
|
|
struct ib_mad_qp_info *qp_info,
|
|
|
|
struct ib_wc *wc,
|
|
|
|
int port_num,
|
|
|
|
struct ib_mad_private *recv,
|
|
|
|
struct ib_mad_private *response,
|
|
|
|
bool opa)
|
|
|
|
{
|
|
|
|
struct ib_mad_hdr *mad_hdr = (struct ib_mad_hdr *)recv->mad;
|
|
|
|
|
|
|
|
if (opa && mad_hdr->base_version == OPA_MGMT_BASE_VERSION &&
|
|
|
|
mad_hdr->class_version == OPA_SMI_CLASS_VERSION)
|
|
|
|
return handle_opa_smi(port_priv, qp_info, wc, port_num, recv,
|
|
|
|
response);
|
|
|
|
|
|
|
|
return handle_ib_smi(port_priv, qp_info, wc, port_num, recv, response);
|
|
|
|
}
|
|
|
|
|
2016-01-06 06:46:12 +00:00
|
|
|
static void ib_mad_recv_done(struct ib_cq *cq, struct ib_wc *wc)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2016-01-06 06:46:12 +00:00
|
|
|
struct ib_mad_port_private *port_priv = cq->cq_context;
|
|
|
|
struct ib_mad_list_head *mad_list =
|
|
|
|
container_of(wc->wr_cqe, struct ib_mad_list_head, cqe);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ib_mad_qp_info *qp_info;
|
|
|
|
struct ib_mad_private_header *mad_priv_hdr;
|
2007-08-03 17:45:17 +00:00
|
|
|
struct ib_mad_private *recv, *response = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ib_mad_agent_private *mad_agent;
|
2007-05-14 21:21:52 +00:00
|
|
|
int port_num;
|
2012-04-24 23:08:57 +00:00
|
|
|
int ret = IB_MAD_RESULT_SUCCESS;
|
2015-06-06 18:38:31 +00:00
|
|
|
size_t mad_size;
|
|
|
|
u16 resp_mad_pkey_index = 0;
|
2015-06-10 20:16:48 +00:00
|
|
|
bool opa;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-01-06 06:46:12 +00:00
|
|
|
if (list_empty_careful(&port_priv->port_list))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wc->status != IB_WC_SUCCESS) {
|
|
|
|
/*
|
|
|
|
* Receive errors indicate that the QP has entered the error
|
|
|
|
* state - error handling/shutdown code will cleanup
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
qp_info = mad_list->mad_queue->qp_info;
|
|
|
|
dequeue_mad(mad_list);
|
|
|
|
|
2015-06-10 20:16:48 +00:00
|
|
|
opa = rdma_cap_opa_mad(qp_info->port_priv->device,
|
|
|
|
qp_info->port_priv->port_num);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_priv_hdr = container_of(mad_list, struct ib_mad_private_header,
|
|
|
|
mad_list);
|
|
|
|
recv = container_of(mad_priv_hdr, struct ib_mad_private, header);
|
2006-12-12 22:28:30 +00:00
|
|
|
ib_dma_unmap_single(port_priv->device,
|
|
|
|
recv->header.mapping,
|
2015-06-06 18:38:30 +00:00
|
|
|
mad_priv_dma_size(recv),
|
2006-12-12 22:28:30 +00:00
|
|
|
DMA_FROM_DEVICE);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Setup MAD receive work completion from "normal" work completion */
|
2005-04-16 22:26:08 +00:00
|
|
|
recv->header.wc = *wc;
|
|
|
|
recv->header.recv_wc.wc = &recv->header.wc;
|
2015-06-10 20:16:48 +00:00
|
|
|
|
|
|
|
if (opa && ((struct ib_mad_hdr *)(recv->mad))->base_version == OPA_MGMT_BASE_VERSION) {
|
|
|
|
recv->header.recv_wc.mad_len = wc->byte_len - sizeof(struct ib_grh);
|
|
|
|
recv->header.recv_wc.mad_seg_size = sizeof(struct opa_mad);
|
|
|
|
} else {
|
|
|
|
recv->header.recv_wc.mad_len = sizeof(struct ib_mad);
|
|
|
|
recv->header.recv_wc.mad_seg_size = sizeof(struct ib_mad);
|
|
|
|
}
|
|
|
|
|
2015-06-06 18:38:30 +00:00
|
|
|
recv->header.recv_wc.recv_buf.mad = (struct ib_mad *)recv->mad;
|
2005-04-16 22:20:36 +00:00
|
|
|
recv->header.recv_wc.recv_buf.grh = &recv->grh;
|
|
|
|
|
|
|
|
if (atomic_read(&qp_info->snoop_count))
|
|
|
|
snoop_recv(qp_info, &recv->header.recv_wc, IB_MAD_SNOOP_RECVS);
|
|
|
|
|
|
|
|
/* Validate MAD */
|
2015-06-10 20:16:48 +00:00
|
|
|
if (!validate_mad((const struct ib_mad_hdr *)recv->mad, qp_info, opa))
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
|
2015-06-06 18:38:31 +00:00
|
|
|
mad_size = recv->mad_size;
|
|
|
|
response = alloc_mad_private(mad_size, GFP_KERNEL);
|
2007-08-03 17:45:17 +00:00
|
|
|
if (!response) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&port_priv->device->dev,
|
2016-01-06 06:46:12 +00:00
|
|
|
"%s: no memory for response buffer\n", __func__);
|
2007-08-03 17:45:17 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-06-29 13:57:00 +00:00
|
|
|
if (rdma_cap_ib_switch(port_priv->device))
|
2007-05-14 21:21:52 +00:00
|
|
|
port_num = wc->port_num;
|
|
|
|
else
|
|
|
|
port_num = port_priv->port_num;
|
|
|
|
|
2015-06-06 18:38:30 +00:00
|
|
|
if (((struct ib_mad_hdr *)recv->mad)->mgmt_class ==
|
2005-04-16 22:20:36 +00:00
|
|
|
IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
|
2015-06-10 20:16:48 +00:00
|
|
|
if (handle_smi(port_priv, qp_info, wc, port_num, recv,
|
|
|
|
response, opa)
|
2015-06-06 18:38:24 +00:00
|
|
|
== IB_SMI_DISCARD)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Give driver "right of first refusal" on incoming MAD */
|
|
|
|
if (port_priv->device->process_mad) {
|
|
|
|
ret = port_priv->device->process_mad(port_priv->device, 0,
|
|
|
|
port_priv->port_num,
|
|
|
|
wc, &recv->grh,
|
2015-06-06 18:38:31 +00:00
|
|
|
(const struct ib_mad_hdr *)recv->mad,
|
|
|
|
recv->mad_size,
|
|
|
|
(struct ib_mad_hdr *)response->mad,
|
|
|
|
&mad_size, &resp_mad_pkey_index);
|
2015-06-10 20:16:48 +00:00
|
|
|
|
|
|
|
if (opa)
|
|
|
|
wc->pkey_index = resp_mad_pkey_index;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ret & IB_MAD_RESULT_SUCCESS) {
|
|
|
|
if (ret & IB_MAD_RESULT_CONSUMED)
|
|
|
|
goto out;
|
|
|
|
if (ret & IB_MAD_RESULT_REPLY) {
|
2015-06-06 18:38:30 +00:00
|
|
|
agent_send_response((const struct ib_mad_hdr *)response->mad,
|
2005-10-25 17:51:39 +00:00
|
|
|
&recv->grh, wc,
|
|
|
|
port_priv->device,
|
2007-05-14 21:21:52 +00:00
|
|
|
port_num,
|
2015-06-06 18:38:30 +00:00
|
|
|
qp_info->qp->qp_num,
|
2015-06-10 20:16:48 +00:00
|
|
|
mad_size, opa);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 18:38:30 +00:00
|
|
|
mad_agent = find_mad_agent(port_priv, (const struct ib_mad_hdr *)recv->mad);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (mad_agent) {
|
2005-07-27 18:45:24 +00:00
|
|
|
ib_mad_complete_recv(mad_agent, &recv->header.recv_wc);
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* recv is freed up in error cases in ib_mad_complete_recv
|
|
|
|
* or via recv_handler in ib_mad_complete_recv()
|
|
|
|
*/
|
|
|
|
recv = NULL;
|
2012-04-24 23:08:57 +00:00
|
|
|
} else if ((ret & IB_MAD_RESULT_SUCCESS) &&
|
2015-06-10 20:16:48 +00:00
|
|
|
generate_unmatched_resp(recv, response, &mad_size, opa)) {
|
2015-06-06 18:38:30 +00:00
|
|
|
agent_send_response((const struct ib_mad_hdr *)response->mad, &recv->grh, wc,
|
|
|
|
port_priv->device, port_num,
|
2015-06-10 20:16:48 +00:00
|
|
|
qp_info->qp->qp_num, mad_size, opa);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* Post another receive request for this QP */
|
|
|
|
if (response) {
|
|
|
|
ib_mad_post_receive_mads(qp_info, response);
|
2015-06-06 18:38:30 +00:00
|
|
|
kfree(recv);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else
|
|
|
|
ib_mad_post_receive_mads(qp_info, recv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void adjust_timeout(struct ib_mad_agent_private *mad_agent_priv)
|
|
|
|
{
|
|
|
|
struct ib_mad_send_wr_private *mad_send_wr;
|
|
|
|
unsigned long delay;
|
|
|
|
|
|
|
|
if (list_empty(&mad_agent_priv->wait_list)) {
|
2012-08-21 20:18:24 +00:00
|
|
|
cancel_delayed_work(&mad_agent_priv->timed_work);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
mad_send_wr = list_entry(mad_agent_priv->wait_list.next,
|
|
|
|
struct ib_mad_send_wr_private,
|
|
|
|
agent_list);
|
|
|
|
|
|
|
|
if (time_after(mad_agent_priv->timeout,
|
|
|
|
mad_send_wr->timeout)) {
|
|
|
|
mad_agent_priv->timeout = mad_send_wr->timeout;
|
|
|
|
delay = mad_send_wr->timeout - jiffies;
|
|
|
|
if ((long)delay <= 0)
|
|
|
|
delay = 1;
|
2012-08-21 20:18:24 +00:00
|
|
|
mod_delayed_work(mad_agent_priv->qp_info->port_priv->wq,
|
|
|
|
&mad_agent_priv->timed_work, delay);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-27 18:45:25 +00:00
|
|
|
static void wait_for_response(struct ib_mad_send_wr_private *mad_send_wr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-07-27 18:45:25 +00:00
|
|
|
struct ib_mad_agent_private *mad_agent_priv;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ib_mad_send_wr_private *temp_mad_send_wr;
|
|
|
|
struct list_head *list_item;
|
|
|
|
unsigned long delay;
|
|
|
|
|
2005-07-27 18:45:25 +00:00
|
|
|
mad_agent_priv = mad_send_wr->mad_agent_priv;
|
2005-04-16 22:20:36 +00:00
|
|
|
list_del(&mad_send_wr->agent_list);
|
|
|
|
|
|
|
|
delay = mad_send_wr->timeout;
|
|
|
|
mad_send_wr->timeout += jiffies;
|
|
|
|
|
2005-07-27 18:45:32 +00:00
|
|
|
if (delay) {
|
|
|
|
list_for_each_prev(list_item, &mad_agent_priv->wait_list) {
|
|
|
|
temp_mad_send_wr = list_entry(list_item,
|
|
|
|
struct ib_mad_send_wr_private,
|
|
|
|
agent_list);
|
|
|
|
if (time_after(mad_send_wr->timeout,
|
|
|
|
temp_mad_send_wr->timeout))
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2005-07-27 18:45:32 +00:00
|
|
|
else
|
|
|
|
list_item = &mad_agent_priv->wait_list;
|
2005-04-16 22:20:36 +00:00
|
|
|
list_add(&mad_send_wr->agent_list, list_item);
|
|
|
|
|
|
|
|
/* Reschedule a work item if we have a shorter timeout */
|
2012-08-21 20:18:24 +00:00
|
|
|
if (mad_agent_priv->wait_list.next == &mad_send_wr->agent_list)
|
|
|
|
mod_delayed_work(mad_agent_priv->qp_info->port_priv->wq,
|
|
|
|
&mad_agent_priv->timed_work, delay);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-07-27 18:45:32 +00:00
|
|
|
void ib_reset_mad_timeout(struct ib_mad_send_wr_private *mad_send_wr,
|
|
|
|
int timeout_ms)
|
|
|
|
{
|
|
|
|
mad_send_wr->timeout = msecs_to_jiffies(timeout_ms);
|
|
|
|
wait_for_response(mad_send_wr);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Process a send work completion
|
|
|
|
*/
|
2005-07-27 18:45:37 +00:00
|
|
|
void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr,
|
|
|
|
struct ib_mad_send_wc *mad_send_wc)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ib_mad_agent_private *mad_agent_priv;
|
|
|
|
unsigned long flags;
|
2005-07-27 18:45:37 +00:00
|
|
|
int ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-07-27 18:45:25 +00:00
|
|
|
mad_agent_priv = mad_send_wr->mad_agent_priv;
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&mad_agent_priv->lock, flags);
|
2014-08-08 23:00:56 +00:00
|
|
|
if (ib_mad_kernel_rmpp_agent(&mad_agent_priv->agent)) {
|
2005-07-27 18:45:37 +00:00
|
|
|
ret = ib_process_rmpp_send_wc(mad_send_wr, mad_send_wc);
|
|
|
|
if (ret == IB_RMPP_RESULT_CONSUMED)
|
|
|
|
goto done;
|
|
|
|
} else
|
|
|
|
ret = IB_RMPP_RESULT_UNHANDLED;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (mad_send_wc->status != IB_WC_SUCCESS &&
|
|
|
|
mad_send_wr->status == IB_WC_SUCCESS) {
|
|
|
|
mad_send_wr->status = mad_send_wc->status;
|
|
|
|
mad_send_wr->refcount -= (mad_send_wr->timeout > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (--mad_send_wr->refcount > 0) {
|
|
|
|
if (mad_send_wr->refcount == 1 && mad_send_wr->timeout &&
|
|
|
|
mad_send_wr->status == IB_WC_SUCCESS) {
|
2005-07-27 18:45:25 +00:00
|
|
|
wait_for_response(mad_send_wr);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2005-07-27 18:45:37 +00:00
|
|
|
goto done;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove send from MAD agent and notify client of completion */
|
|
|
|
list_del(&mad_send_wr->agent_list);
|
|
|
|
adjust_timeout(mad_agent_priv);
|
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
|
|
|
|
|
|
|
if (mad_send_wr->status != IB_WC_SUCCESS )
|
|
|
|
mad_send_wc->status = mad_send_wr->status;
|
2005-10-25 17:51:39 +00:00
|
|
|
if (ret == IB_RMPP_RESULT_INTERNAL)
|
|
|
|
ib_rmpp_send_handler(mad_send_wc);
|
|
|
|
else
|
2005-07-27 18:45:37 +00:00
|
|
|
mad_agent_priv->agent.send_handler(&mad_agent_priv->agent,
|
|
|
|
mad_send_wc);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Release reference on agent taken when sending */
|
2006-05-12 21:57:52 +00:00
|
|
|
deref_mad_agent(mad_agent_priv);
|
2005-07-27 18:45:37 +00:00
|
|
|
return;
|
|
|
|
done:
|
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 06:46:12 +00:00
|
|
|
static void ib_mad_send_done(struct ib_cq *cq, struct ib_wc *wc)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2016-01-06 06:46:12 +00:00
|
|
|
struct ib_mad_port_private *port_priv = cq->cq_context;
|
|
|
|
struct ib_mad_list_head *mad_list =
|
|
|
|
container_of(wc->wr_cqe, struct ib_mad_list_head, cqe);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ib_mad_send_wr_private *mad_send_wr, *queued_send_wr;
|
|
|
|
struct ib_mad_qp_info *qp_info;
|
|
|
|
struct ib_mad_queue *send_queue;
|
|
|
|
struct ib_send_wr *bad_send_wr;
|
2005-10-25 17:51:39 +00:00
|
|
|
struct ib_mad_send_wc mad_send_wc;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
2016-01-06 06:46:12 +00:00
|
|
|
if (list_empty_careful(&port_priv->port_list))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wc->status != IB_WC_SUCCESS) {
|
|
|
|
if (!ib_mad_send_error(port_priv, wc))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_send_wr = container_of(mad_list, struct ib_mad_send_wr_private,
|
|
|
|
mad_list);
|
|
|
|
send_queue = mad_list->mad_queue;
|
|
|
|
qp_info = send_queue->qp_info;
|
|
|
|
|
|
|
|
retry:
|
2006-12-12 22:28:30 +00:00
|
|
|
ib_dma_unmap_single(mad_send_wr->send_buf.mad_agent->device,
|
|
|
|
mad_send_wr->header_mapping,
|
|
|
|
mad_send_wr->sg_list[0].length, DMA_TO_DEVICE);
|
|
|
|
ib_dma_unmap_single(mad_send_wr->send_buf.mad_agent->device,
|
|
|
|
mad_send_wr->payload_mapping,
|
|
|
|
mad_send_wr->sg_list[1].length, DMA_TO_DEVICE);
|
2005-04-16 22:20:36 +00:00
|
|
|
queued_send_wr = NULL;
|
|
|
|
spin_lock_irqsave(&send_queue->lock, flags);
|
|
|
|
list_del(&mad_list->list);
|
|
|
|
|
|
|
|
/* Move queued send to the send queue */
|
|
|
|
if (send_queue->count-- > send_queue->max_active) {
|
|
|
|
mad_list = container_of(qp_info->overflow_list.next,
|
|
|
|
struct ib_mad_list_head, list);
|
|
|
|
queued_send_wr = container_of(mad_list,
|
|
|
|
struct ib_mad_send_wr_private,
|
|
|
|
mad_list);
|
2006-06-26 07:24:41 +00:00
|
|
|
list_move_tail(&mad_list->list, &send_queue->list);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&send_queue->lock, flags);
|
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_send_wc.send_buf = &mad_send_wr->send_buf;
|
|
|
|
mad_send_wc.status = wc->status;
|
|
|
|
mad_send_wc.vendor_err = wc->vendor_err;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (atomic_read(&qp_info->snoop_count))
|
2005-10-25 17:51:39 +00:00
|
|
|
snoop_send(qp_info, &mad_send_wr->send_buf, &mad_send_wc,
|
2005-04-16 22:20:36 +00:00
|
|
|
IB_MAD_SNOOP_SEND_COMPLETIONS);
|
2005-10-25 17:51:39 +00:00
|
|
|
ib_mad_complete_send_wr(mad_send_wr, &mad_send_wc);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (queued_send_wr) {
|
2015-10-08 08:16:33 +00:00
|
|
|
ret = ib_post_send(qp_info->qp, &queued_send_wr->send_wr.wr,
|
2005-10-25 17:51:39 +00:00
|
|
|
&bad_send_wr);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ret) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&port_priv->device->dev,
|
|
|
|
"ib_post_send failed: %d\n", ret);
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_send_wr = queued_send_wr;
|
|
|
|
wc->status = IB_WC_LOC_QP_OP_ERR;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mark_sends_for_retry(struct ib_mad_qp_info *qp_info)
|
|
|
|
{
|
|
|
|
struct ib_mad_send_wr_private *mad_send_wr;
|
|
|
|
struct ib_mad_list_head *mad_list;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&qp_info->send_queue.lock, flags);
|
|
|
|
list_for_each_entry(mad_list, &qp_info->send_queue.list, list) {
|
|
|
|
mad_send_wr = container_of(mad_list,
|
|
|
|
struct ib_mad_send_wr_private,
|
|
|
|
mad_list);
|
|
|
|
mad_send_wr->retry = 1;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&qp_info->send_queue.lock, flags);
|
|
|
|
}
|
|
|
|
|
2016-01-06 06:46:12 +00:00
|
|
|
static bool ib_mad_send_error(struct ib_mad_port_private *port_priv,
|
|
|
|
struct ib_wc *wc)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2016-01-06 06:46:12 +00:00
|
|
|
struct ib_mad_list_head *mad_list =
|
|
|
|
container_of(wc->wr_cqe, struct ib_mad_list_head, cqe);
|
|
|
|
struct ib_mad_qp_info *qp_info = mad_list->mad_queue->qp_info;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ib_mad_send_wr_private *mad_send_wr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send errors will transition the QP to SQE - move
|
|
|
|
* QP to RTS and repost flushed work requests
|
|
|
|
*/
|
|
|
|
mad_send_wr = container_of(mad_list, struct ib_mad_send_wr_private,
|
|
|
|
mad_list);
|
|
|
|
if (wc->status == IB_WC_WR_FLUSH_ERR) {
|
|
|
|
if (mad_send_wr->retry) {
|
|
|
|
/* Repost send */
|
|
|
|
struct ib_send_wr *bad_send_wr;
|
|
|
|
|
|
|
|
mad_send_wr->retry = 0;
|
2015-10-08 08:16:33 +00:00
|
|
|
ret = ib_post_send(qp_info->qp, &mad_send_wr->send_wr.wr,
|
2005-04-16 22:20:36 +00:00
|
|
|
&bad_send_wr);
|
2016-01-06 06:46:12 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
struct ib_qp_attr *attr;
|
|
|
|
|
|
|
|
/* Transition QP to RTS and fail offending send */
|
|
|
|
attr = kmalloc(sizeof *attr, GFP_KERNEL);
|
|
|
|
if (attr) {
|
|
|
|
attr->qp_state = IB_QPS_RTS;
|
|
|
|
attr->cur_qp_state = IB_QPS_SQE;
|
|
|
|
ret = ib_modify_qp(qp_info->qp, attr,
|
|
|
|
IB_QP_STATE | IB_QP_CUR_STATE);
|
|
|
|
kfree(attr);
|
|
|
|
if (ret)
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&port_priv->device->dev,
|
2016-01-06 06:46:12 +00:00
|
|
|
"%s - ib_modify_qp to RTS: %d\n",
|
|
|
|
__func__, ret);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
|
|
|
mark_sends_for_retry(qp_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-06 06:46:12 +00:00
|
|
|
return true;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cancel_mads(struct ib_mad_agent_private *mad_agent_priv)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct ib_mad_send_wr_private *mad_send_wr, *temp_mad_send_wr;
|
|
|
|
struct ib_mad_send_wc mad_send_wc;
|
|
|
|
struct list_head cancel_list;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&cancel_list);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&mad_agent_priv->lock, flags);
|
|
|
|
list_for_each_entry_safe(mad_send_wr, temp_mad_send_wr,
|
|
|
|
&mad_agent_priv->send_list, agent_list) {
|
|
|
|
if (mad_send_wr->status == IB_WC_SUCCESS) {
|
2006-09-22 22:22:46 +00:00
|
|
|
mad_send_wr->status = IB_WC_WR_FLUSH_ERR;
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_send_wr->refcount -= (mad_send_wr->timeout > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Empty wait list to prevent receives from finding a request */
|
|
|
|
list_splice_init(&mad_agent_priv->wait_list, &cancel_list);
|
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
|
|
|
|
|
|
|
/* Report all cancelled requests */
|
|
|
|
mad_send_wc.status = IB_WC_WR_FLUSH_ERR;
|
|
|
|
mad_send_wc.vendor_err = 0;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(mad_send_wr, temp_mad_send_wr,
|
|
|
|
&cancel_list, agent_list) {
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_send_wc.send_buf = &mad_send_wr->send_buf;
|
|
|
|
list_del(&mad_send_wr->agent_list);
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_agent_priv->agent.send_handler(&mad_agent_priv->agent,
|
|
|
|
&mad_send_wc);
|
|
|
|
atomic_dec(&mad_agent_priv->refcount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ib_mad_send_wr_private*
|
2005-10-25 17:51:39 +00:00
|
|
|
find_send_wr(struct ib_mad_agent_private *mad_agent_priv,
|
|
|
|
struct ib_mad_send_buf *send_buf)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ib_mad_send_wr_private *mad_send_wr;
|
|
|
|
|
|
|
|
list_for_each_entry(mad_send_wr, &mad_agent_priv->wait_list,
|
|
|
|
agent_list) {
|
2005-10-25 17:51:39 +00:00
|
|
|
if (&mad_send_wr->send_buf == send_buf)
|
2005-04-16 22:20:36 +00:00
|
|
|
return mad_send_wr;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list,
|
|
|
|
agent_list) {
|
2015-05-08 17:10:03 +00:00
|
|
|
if (is_rmpp_data_mad(mad_agent_priv,
|
|
|
|
mad_send_wr->send_buf.mad) &&
|
2005-10-25 17:51:39 +00:00
|
|
|
&mad_send_wr->send_buf == send_buf)
|
2005-04-16 22:20:36 +00:00
|
|
|
return mad_send_wr;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
int ib_modify_mad(struct ib_mad_agent *mad_agent,
|
|
|
|
struct ib_mad_send_buf *send_buf, u32 timeout_ms)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ib_mad_agent_private *mad_agent_priv;
|
|
|
|
struct ib_mad_send_wr_private *mad_send_wr;
|
|
|
|
unsigned long flags;
|
2005-07-27 18:45:33 +00:00
|
|
|
int active;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
mad_agent_priv = container_of(mad_agent, struct ib_mad_agent_private,
|
|
|
|
agent);
|
|
|
|
spin_lock_irqsave(&mad_agent_priv->lock, flags);
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_send_wr = find_send_wr(mad_agent_priv, send_buf);
|
2005-07-27 18:45:32 +00:00
|
|
|
if (!mad_send_wr || mad_send_wr->status != IB_WC_SUCCESS) {
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
2005-07-27 18:45:32 +00:00
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-07-27 18:45:33 +00:00
|
|
|
active = (!mad_send_wr->timeout || mad_send_wr->refcount > 1);
|
2005-07-27 18:45:32 +00:00
|
|
|
if (!timeout_ms) {
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_send_wr->status = IB_WC_WR_FLUSH_ERR;
|
2005-07-27 18:45:32 +00:00
|
|
|
mad_send_wr->refcount -= (mad_send_wr->timeout > 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_send_wr->send_buf.timeout_ms = timeout_ms;
|
2005-07-27 18:45:33 +00:00
|
|
|
if (active)
|
2005-07-27 18:45:32 +00:00
|
|
|
mad_send_wr->timeout = msecs_to_jiffies(timeout_ms);
|
|
|
|
else
|
|
|
|
ib_reset_mad_timeout(mad_send_wr, timeout_ms);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
2005-07-27 18:45:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_modify_mad);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
void ib_cancel_mad(struct ib_mad_agent *mad_agent,
|
|
|
|
struct ib_mad_send_buf *send_buf)
|
2005-07-27 18:45:32 +00:00
|
|
|
{
|
2005-10-25 17:51:39 +00:00
|
|
|
ib_modify_mad(mad_agent, send_buf, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_cancel_mad);
|
|
|
|
|
2006-11-22 14:57:56 +00:00
|
|
|
static void local_completions(struct work_struct *work)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ib_mad_agent_private *mad_agent_priv;
|
|
|
|
struct ib_mad_local_private *local;
|
|
|
|
struct ib_mad_agent_private *recv_mad_agent;
|
|
|
|
unsigned long flags;
|
2009-02-27 18:34:30 +00:00
|
|
|
int free_mad;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ib_wc wc;
|
|
|
|
struct ib_mad_send_wc mad_send_wc;
|
2015-06-10 20:16:48 +00:00
|
|
|
bool opa;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-11-22 14:57:56 +00:00
|
|
|
mad_agent_priv =
|
|
|
|
container_of(work, struct ib_mad_agent_private, local_work);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-10 20:16:48 +00:00
|
|
|
opa = rdma_cap_opa_mad(mad_agent_priv->qp_info->port_priv->device,
|
|
|
|
mad_agent_priv->qp_info->port_priv->port_num);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&mad_agent_priv->lock, flags);
|
|
|
|
while (!list_empty(&mad_agent_priv->local_list)) {
|
|
|
|
local = list_entry(mad_agent_priv->local_list.next,
|
|
|
|
struct ib_mad_local_private,
|
|
|
|
completion_list);
|
2006-03-30 13:52:54 +00:00
|
|
|
list_del(&local->completion_list);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
2009-02-27 18:34:30 +00:00
|
|
|
free_mad = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (local->mad_priv) {
|
2015-06-10 20:16:48 +00:00
|
|
|
u8 base_version;
|
2005-04-16 22:20:36 +00:00
|
|
|
recv_mad_agent = local->recv_mad_agent;
|
|
|
|
if (!recv_mad_agent) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&mad_agent_priv->agent.device->dev,
|
|
|
|
"No receive MAD agent for local completion\n");
|
2009-02-27 18:34:30 +00:00
|
|
|
free_mad = 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
goto local_send_completion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Defined behavior is to complete response
|
|
|
|
* before request
|
|
|
|
*/
|
2006-12-31 19:09:42 +00:00
|
|
|
build_smp_wc(recv_mad_agent->agent.qp,
|
2016-01-06 06:46:12 +00:00
|
|
|
local->mad_send_wr->send_wr.wr.wr_cqe,
|
2005-08-14 04:05:57 +00:00
|
|
|
be16_to_cpu(IB_LID_PERMISSIVE),
|
2015-10-08 08:16:33 +00:00
|
|
|
local->mad_send_wr->send_wr.pkey_index,
|
2015-06-10 20:16:48 +00:00
|
|
|
recv_mad_agent->agent.port_num, &wc);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
local->mad_priv->header.recv_wc.wc = &wc;
|
2015-06-10 20:16:48 +00:00
|
|
|
|
|
|
|
base_version = ((struct ib_mad_hdr *)(local->mad_priv->mad))->base_version;
|
|
|
|
if (opa && base_version == OPA_MGMT_BASE_VERSION) {
|
|
|
|
local->mad_priv->header.recv_wc.mad_len = local->return_wc_byte_len;
|
|
|
|
local->mad_priv->header.recv_wc.mad_seg_size = sizeof(struct opa_mad);
|
|
|
|
} else {
|
|
|
|
local->mad_priv->header.recv_wc.mad_len = sizeof(struct ib_mad);
|
|
|
|
local->mad_priv->header.recv_wc.mad_seg_size = sizeof(struct ib_mad);
|
|
|
|
}
|
|
|
|
|
2005-07-27 18:45:37 +00:00
|
|
|
INIT_LIST_HEAD(&local->mad_priv->header.recv_wc.rmpp_list);
|
|
|
|
list_add(&local->mad_priv->header.recv_wc.recv_buf.list,
|
|
|
|
&local->mad_priv->header.recv_wc.rmpp_list);
|
2005-04-16 22:20:36 +00:00
|
|
|
local->mad_priv->header.recv_wc.recv_buf.grh = NULL;
|
|
|
|
local->mad_priv->header.recv_wc.recv_buf.mad =
|
2015-06-06 18:38:30 +00:00
|
|
|
(struct ib_mad *)local->mad_priv->mad;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (atomic_read(&recv_mad_agent->qp_info->snoop_count))
|
|
|
|
snoop_recv(recv_mad_agent->qp_info,
|
|
|
|
&local->mad_priv->header.recv_wc,
|
|
|
|
IB_MAD_SNOOP_RECVS);
|
|
|
|
recv_mad_agent->agent.recv_handler(
|
|
|
|
&recv_mad_agent->agent,
|
2016-01-04 13:15:58 +00:00
|
|
|
&local->mad_send_wr->send_buf,
|
2005-04-16 22:20:36 +00:00
|
|
|
&local->mad_priv->header.recv_wc);
|
|
|
|
spin_lock_irqsave(&recv_mad_agent->lock, flags);
|
|
|
|
atomic_dec(&recv_mad_agent->refcount);
|
|
|
|
spin_unlock_irqrestore(&recv_mad_agent->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
local_send_completion:
|
|
|
|
/* Complete send */
|
|
|
|
mad_send_wc.status = IB_WC_SUCCESS;
|
|
|
|
mad_send_wc.vendor_err = 0;
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_send_wc.send_buf = &local->mad_send_wr->send_buf;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (atomic_read(&mad_agent_priv->qp_info->snoop_count))
|
2005-10-25 17:51:39 +00:00
|
|
|
snoop_send(mad_agent_priv->qp_info,
|
|
|
|
&local->mad_send_wr->send_buf,
|
|
|
|
&mad_send_wc, IB_MAD_SNOOP_SEND_COMPLETIONS);
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_agent_priv->agent.send_handler(&mad_agent_priv->agent,
|
|
|
|
&mad_send_wc);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&mad_agent_priv->lock, flags);
|
|
|
|
atomic_dec(&mad_agent_priv->refcount);
|
2009-02-27 18:34:30 +00:00
|
|
|
if (free_mad)
|
2015-06-06 18:38:30 +00:00
|
|
|
kfree(local->mad_priv);
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(local);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
|
|
|
}
|
|
|
|
|
2005-07-27 18:45:29 +00:00
|
|
|
static int retry_send(struct ib_mad_send_wr_private *mad_send_wr)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2007-11-27 08:11:04 +00:00
|
|
|
if (!mad_send_wr->retries_left)
|
2005-07-27 18:45:29 +00:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
|
2007-11-27 08:11:04 +00:00
|
|
|
mad_send_wr->retries_left--;
|
|
|
|
mad_send_wr->send_buf.retries++;
|
|
|
|
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_send_wr->timeout = msecs_to_jiffies(mad_send_wr->send_buf.timeout_ms);
|
2005-07-27 18:45:29 +00:00
|
|
|
|
2014-08-08 23:00:56 +00:00
|
|
|
if (ib_mad_kernel_rmpp_agent(&mad_send_wr->mad_agent_priv->agent)) {
|
2005-07-27 18:45:37 +00:00
|
|
|
ret = ib_retry_rmpp(mad_send_wr);
|
|
|
|
switch (ret) {
|
|
|
|
case IB_RMPP_RESULT_UNHANDLED:
|
|
|
|
ret = ib_send_mad(mad_send_wr);
|
|
|
|
break;
|
|
|
|
case IB_RMPP_RESULT_CONSUMED:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -ECOMM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
ret = ib_send_mad(mad_send_wr);
|
2005-07-27 18:45:29 +00:00
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
mad_send_wr->refcount++;
|
|
|
|
list_add_tail(&mad_send_wr->agent_list,
|
|
|
|
&mad_send_wr->mad_agent_priv->send_list);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-11-22 14:57:56 +00:00
|
|
|
static void timeout_sends(struct work_struct *work)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ib_mad_agent_private *mad_agent_priv;
|
|
|
|
struct ib_mad_send_wr_private *mad_send_wr;
|
|
|
|
struct ib_mad_send_wc mad_send_wc;
|
|
|
|
unsigned long flags, delay;
|
|
|
|
|
2006-11-22 14:57:56 +00:00
|
|
|
mad_agent_priv = container_of(work, struct ib_mad_agent_private,
|
|
|
|
timed_work.work);
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_send_wc.vendor_err = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&mad_agent_priv->lock, flags);
|
|
|
|
while (!list_empty(&mad_agent_priv->wait_list)) {
|
|
|
|
mad_send_wr = list_entry(mad_agent_priv->wait_list.next,
|
|
|
|
struct ib_mad_send_wr_private,
|
|
|
|
agent_list);
|
|
|
|
|
|
|
|
if (time_after(mad_send_wr->timeout, jiffies)) {
|
|
|
|
delay = mad_send_wr->timeout - jiffies;
|
|
|
|
if ((long)delay <= 0)
|
|
|
|
delay = 1;
|
|
|
|
queue_delayed_work(mad_agent_priv->qp_info->
|
|
|
|
port_priv->wq,
|
|
|
|
&mad_agent_priv->timed_work, delay);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-07-27 18:45:30 +00:00
|
|
|
list_del(&mad_send_wr->agent_list);
|
2005-07-27 18:45:32 +00:00
|
|
|
if (mad_send_wr->status == IB_WC_SUCCESS &&
|
|
|
|
!retry_send(mad_send_wr))
|
2005-07-27 18:45:29 +00:00
|
|
|
continue;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
|
|
|
|
2005-07-27 18:45:32 +00:00
|
|
|
if (mad_send_wr->status == IB_WC_SUCCESS)
|
|
|
|
mad_send_wc.status = IB_WC_RESP_TIMEOUT_ERR;
|
|
|
|
else
|
|
|
|
mad_send_wc.status = mad_send_wr->status;
|
2005-10-25 17:51:39 +00:00
|
|
|
mad_send_wc.send_buf = &mad_send_wr->send_buf;
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_agent_priv->agent.send_handler(&mad_agent_priv->agent,
|
|
|
|
&mad_send_wc);
|
|
|
|
|
|
|
|
atomic_dec(&mad_agent_priv->refcount);
|
|
|
|
spin_lock_irqsave(&mad_agent_priv->lock, flags);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate receive MADs and post receive WRs for them
|
|
|
|
*/
|
|
|
|
static int ib_mad_post_receive_mads(struct ib_mad_qp_info *qp_info,
|
|
|
|
struct ib_mad_private *mad)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int post, ret;
|
|
|
|
struct ib_mad_private *mad_priv;
|
|
|
|
struct ib_sge sg_list;
|
|
|
|
struct ib_recv_wr recv_wr, *bad_recv_wr;
|
|
|
|
struct ib_mad_queue *recv_queue = &qp_info->recv_queue;
|
|
|
|
|
|
|
|
/* Initialize common scatter list fields */
|
2015-07-30 23:22:16 +00:00
|
|
|
sg_list.lkey = qp_info->port_priv->pd->local_dma_lkey;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Initialize common receive WR fields */
|
|
|
|
recv_wr.next = NULL;
|
|
|
|
recv_wr.sg_list = &sg_list;
|
|
|
|
recv_wr.num_sge = 1;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* Allocate and map receive buffer */
|
|
|
|
if (mad) {
|
|
|
|
mad_priv = mad;
|
|
|
|
mad = NULL;
|
|
|
|
} else {
|
2015-06-06 18:38:30 +00:00
|
|
|
mad_priv = alloc_mad_private(port_mad_size(qp_info->port_priv),
|
|
|
|
GFP_ATOMIC);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!mad_priv) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&qp_info->port_priv->device->dev,
|
|
|
|
"No memory for receive buffer\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-06-06 18:38:30 +00:00
|
|
|
sg_list.length = mad_priv_dma_size(mad_priv);
|
2006-12-12 22:28:30 +00:00
|
|
|
sg_list.addr = ib_dma_map_single(qp_info->port_priv->device,
|
|
|
|
&mad_priv->grh,
|
2015-06-06 18:38:30 +00:00
|
|
|
mad_priv_dma_size(mad_priv),
|
2006-12-12 22:28:30 +00:00
|
|
|
DMA_FROM_DEVICE);
|
2014-03-11 12:41:47 +00:00
|
|
|
if (unlikely(ib_dma_mapping_error(qp_info->port_priv->device,
|
|
|
|
sg_list.addr))) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2006-12-12 22:28:30 +00:00
|
|
|
mad_priv->header.mapping = sg_list.addr;
|
2005-04-16 22:20:36 +00:00
|
|
|
mad_priv->header.mad_list.mad_queue = recv_queue;
|
2016-01-06 06:46:12 +00:00
|
|
|
mad_priv->header.mad_list.cqe.done = ib_mad_recv_done;
|
|
|
|
recv_wr.wr_cqe = &mad_priv->header.mad_list.cqe;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Post receive WR */
|
|
|
|
spin_lock_irqsave(&recv_queue->lock, flags);
|
|
|
|
post = (++recv_queue->count < recv_queue->max_active);
|
|
|
|
list_add_tail(&mad_priv->header.mad_list.list, &recv_queue->list);
|
|
|
|
spin_unlock_irqrestore(&recv_queue->lock, flags);
|
|
|
|
ret = ib_post_recv(qp_info->qp, &recv_wr, &bad_recv_wr);
|
|
|
|
if (ret) {
|
|
|
|
spin_lock_irqsave(&recv_queue->lock, flags);
|
|
|
|
list_del(&mad_priv->header.mad_list.list);
|
|
|
|
recv_queue->count--;
|
|
|
|
spin_unlock_irqrestore(&recv_queue->lock, flags);
|
2006-12-12 22:28:30 +00:00
|
|
|
ib_dma_unmap_single(qp_info->port_priv->device,
|
|
|
|
mad_priv->header.mapping,
|
2015-06-06 18:38:30 +00:00
|
|
|
mad_priv_dma_size(mad_priv),
|
2006-12-12 22:28:30 +00:00
|
|
|
DMA_FROM_DEVICE);
|
2015-06-06 18:38:30 +00:00
|
|
|
kfree(mad_priv);
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&qp_info->port_priv->device->dev,
|
|
|
|
"ib_post_recv failed: %d\n", ret);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (post);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return all the posted receive MADs
|
|
|
|
*/
|
|
|
|
static void cleanup_recv_queue(struct ib_mad_qp_info *qp_info)
|
|
|
|
{
|
|
|
|
struct ib_mad_private_header *mad_priv_hdr;
|
|
|
|
struct ib_mad_private *recv;
|
|
|
|
struct ib_mad_list_head *mad_list;
|
|
|
|
|
2010-09-28 00:51:11 +00:00
|
|
|
if (!qp_info->qp)
|
|
|
|
return;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
while (!list_empty(&qp_info->recv_queue.list)) {
|
|
|
|
|
|
|
|
mad_list = list_entry(qp_info->recv_queue.list.next,
|
|
|
|
struct ib_mad_list_head, list);
|
|
|
|
mad_priv_hdr = container_of(mad_list,
|
|
|
|
struct ib_mad_private_header,
|
|
|
|
mad_list);
|
|
|
|
recv = container_of(mad_priv_hdr, struct ib_mad_private,
|
|
|
|
header);
|
|
|
|
|
|
|
|
/* Remove from posted receive MAD list */
|
|
|
|
list_del(&mad_list->list);
|
|
|
|
|
2006-12-12 22:28:30 +00:00
|
|
|
ib_dma_unmap_single(qp_info->port_priv->device,
|
|
|
|
recv->header.mapping,
|
2015-06-06 18:38:30 +00:00
|
|
|
mad_priv_dma_size(recv),
|
2006-12-12 22:28:30 +00:00
|
|
|
DMA_FROM_DEVICE);
|
2015-06-06 18:38:30 +00:00
|
|
|
kfree(recv);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qp_info->recv_queue.count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the port
|
|
|
|
*/
|
|
|
|
static int ib_mad_port_start(struct ib_mad_port_private *port_priv)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
struct ib_qp_attr *attr;
|
|
|
|
struct ib_qp *qp;
|
IB/core: Create QP1 using the pkey index which contains the default pkey
Currently, QP1 is created using pkey index 0. This patch simply looks
for the index containing the default pkey, rather than hard-coding
pkey index 0.
This change will have no effect in native mode, since QP0 and QP1 are
created before the SM configures the port, so pkey table will still be
the default table defined by the IB Spec, in C10-123: "If non-volatile
storage is not used to hold P_Key Table contents, then if a PM
(Partition Manager) is not present, and prior to PM initialization of
the P_Key Table, the P_Key Table must act as if it contains a single
valid entry, at P_Key_ix = 0, containing the default partition
key. All other entries in the P_Key Table must be invalid."
Thus, in the native mode case, the driver will find the default pkey
at index 0 (so it will be no different than the hard-coding).
However, in SR-IOV mode, for VFs, the pkey table may be
paravirtualized, so that the VF's pkey index zero may not necessarily
be mapped to the real pkey index 0. For VFs, therefore, it is
important to find the virtual index which maps to the real default
pkey.
This commit does the following for QP1 creation:
1. Find the pkey index containing the default pkey, and use that index
if found. ib_find_pkey() returns the index of the
limited-membership default pkey (0x7FFF) if the full-member default
pkey is not in the table.
2. If neither form of the default pkey is found, use pkey index 0
(previous behavior).
Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Reviewed-by: Sean Hefty <sean.hefty@intel.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2013-07-18 11:02:29 +00:00
|
|
|
u16 pkey_index;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
attr = kmalloc(sizeof *attr, GFP_KERNEL);
|
2006-09-22 22:22:46 +00:00
|
|
|
if (!attr) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&port_priv->device->dev,
|
|
|
|
"Couldn't kmalloc ib_qp_attr\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
IB/core: Create QP1 using the pkey index which contains the default pkey
Currently, QP1 is created using pkey index 0. This patch simply looks
for the index containing the default pkey, rather than hard-coding
pkey index 0.
This change will have no effect in native mode, since QP0 and QP1 are
created before the SM configures the port, so pkey table will still be
the default table defined by the IB Spec, in C10-123: "If non-volatile
storage is not used to hold P_Key Table contents, then if a PM
(Partition Manager) is not present, and prior to PM initialization of
the P_Key Table, the P_Key Table must act as if it contains a single
valid entry, at P_Key_ix = 0, containing the default partition
key. All other entries in the P_Key Table must be invalid."
Thus, in the native mode case, the driver will find the default pkey
at index 0 (so it will be no different than the hard-coding).
However, in SR-IOV mode, for VFs, the pkey table may be
paravirtualized, so that the VF's pkey index zero may not necessarily
be mapped to the real pkey index 0. For VFs, therefore, it is
important to find the virtual index which maps to the real default
pkey.
This commit does the following for QP1 creation:
1. Find the pkey index containing the default pkey, and use that index
if found. ib_find_pkey() returns the index of the
limited-membership default pkey (0x7FFF) if the full-member default
pkey is not in the table.
2. If neither form of the default pkey is found, use pkey index 0
(previous behavior).
Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Reviewed-by: Sean Hefty <sean.hefty@intel.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2013-07-18 11:02:29 +00:00
|
|
|
ret = ib_find_pkey(port_priv->device, port_priv->port_num,
|
|
|
|
IB_DEFAULT_PKEY_FULL, &pkey_index);
|
|
|
|
if (ret)
|
|
|
|
pkey_index = 0;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < IB_MAD_QPS_CORE; i++) {
|
|
|
|
qp = port_priv->qp_info[i].qp;
|
2010-09-28 00:51:11 +00:00
|
|
|
if (!qp)
|
|
|
|
continue;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* PKey index for QP1 is irrelevant but
|
|
|
|
* one is needed for the Reset to Init transition
|
|
|
|
*/
|
|
|
|
attr->qp_state = IB_QPS_INIT;
|
IB/core: Create QP1 using the pkey index which contains the default pkey
Currently, QP1 is created using pkey index 0. This patch simply looks
for the index containing the default pkey, rather than hard-coding
pkey index 0.
This change will have no effect in native mode, since QP0 and QP1 are
created before the SM configures the port, so pkey table will still be
the default table defined by the IB Spec, in C10-123: "If non-volatile
storage is not used to hold P_Key Table contents, then if a PM
(Partition Manager) is not present, and prior to PM initialization of
the P_Key Table, the P_Key Table must act as if it contains a single
valid entry, at P_Key_ix = 0, containing the default partition
key. All other entries in the P_Key Table must be invalid."
Thus, in the native mode case, the driver will find the default pkey
at index 0 (so it will be no different than the hard-coding).
However, in SR-IOV mode, for VFs, the pkey table may be
paravirtualized, so that the VF's pkey index zero may not necessarily
be mapped to the real pkey index 0. For VFs, therefore, it is
important to find the virtual index which maps to the real default
pkey.
This commit does the following for QP1 creation:
1. Find the pkey index containing the default pkey, and use that index
if found. ib_find_pkey() returns the index of the
limited-membership default pkey (0x7FFF) if the full-member default
pkey is not in the table.
2. If neither form of the default pkey is found, use pkey index 0
(previous behavior).
Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Reviewed-by: Sean Hefty <sean.hefty@intel.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2013-07-18 11:02:29 +00:00
|
|
|
attr->pkey_index = pkey_index;
|
2005-04-16 22:20:36 +00:00
|
|
|
attr->qkey = (qp->qp_num == 0) ? 0 : IB_QP1_QKEY;
|
|
|
|
ret = ib_modify_qp(qp, attr, IB_QP_STATE |
|
|
|
|
IB_QP_PKEY_INDEX | IB_QP_QKEY);
|
|
|
|
if (ret) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&port_priv->device->dev,
|
|
|
|
"Couldn't change QP%d state to INIT: %d\n",
|
|
|
|
i, ret);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr->qp_state = IB_QPS_RTR;
|
|
|
|
ret = ib_modify_qp(qp, attr, IB_QP_STATE);
|
|
|
|
if (ret) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&port_priv->device->dev,
|
|
|
|
"Couldn't change QP%d state to RTR: %d\n",
|
|
|
|
i, ret);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr->qp_state = IB_QPS_RTS;
|
|
|
|
attr->sq_psn = IB_MAD_SEND_Q_PSN;
|
|
|
|
ret = ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_SQ_PSN);
|
|
|
|
if (ret) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&port_priv->device->dev,
|
|
|
|
"Couldn't change QP%d state to RTS: %d\n",
|
|
|
|
i, ret);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ib_req_notify_cq(port_priv->cq, IB_CQ_NEXT_COMP);
|
|
|
|
if (ret) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&port_priv->device->dev,
|
|
|
|
"Failed to request completion notification: %d\n",
|
|
|
|
ret);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < IB_MAD_QPS_CORE; i++) {
|
2010-09-28 00:51:11 +00:00
|
|
|
if (!port_priv->qp_info[i].qp)
|
|
|
|
continue;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = ib_mad_post_receive_mads(&port_priv->qp_info[i], NULL);
|
|
|
|
if (ret) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&port_priv->device->dev,
|
|
|
|
"Couldn't post receive WRs\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
kfree(attr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qp_event_handler(struct ib_event *event, void *qp_context)
|
|
|
|
{
|
|
|
|
struct ib_mad_qp_info *qp_info = qp_context;
|
|
|
|
|
|
|
|
/* It's worse than that! He's dead, Jim! */
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&qp_info->port_priv->device->dev,
|
|
|
|
"Fatal error (%d) on MAD QP (%d)\n",
|
2005-04-16 22:20:36 +00:00
|
|
|
event->event, qp_info->qp->qp_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_mad_queue(struct ib_mad_qp_info *qp_info,
|
|
|
|
struct ib_mad_queue *mad_queue)
|
|
|
|
{
|
|
|
|
mad_queue->qp_info = qp_info;
|
|
|
|
mad_queue->count = 0;
|
|
|
|
spin_lock_init(&mad_queue->lock);
|
|
|
|
INIT_LIST_HEAD(&mad_queue->list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_mad_qp(struct ib_mad_port_private *port_priv,
|
|
|
|
struct ib_mad_qp_info *qp_info)
|
|
|
|
{
|
|
|
|
qp_info->port_priv = port_priv;
|
|
|
|
init_mad_queue(qp_info, &qp_info->send_queue);
|
|
|
|
init_mad_queue(qp_info, &qp_info->recv_queue);
|
|
|
|
INIT_LIST_HEAD(&qp_info->overflow_list);
|
|
|
|
spin_lock_init(&qp_info->snoop_lock);
|
|
|
|
qp_info->snoop_table = NULL;
|
|
|
|
qp_info->snoop_table_size = 0;
|
|
|
|
atomic_set(&qp_info->snoop_count, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int create_mad_qp(struct ib_mad_qp_info *qp_info,
|
|
|
|
enum ib_qp_type qp_type)
|
|
|
|
{
|
|
|
|
struct ib_qp_init_attr qp_init_attr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
memset(&qp_init_attr, 0, sizeof qp_init_attr);
|
|
|
|
qp_init_attr.send_cq = qp_info->port_priv->cq;
|
|
|
|
qp_init_attr.recv_cq = qp_info->port_priv->cq;
|
|
|
|
qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR;
|
2009-09-07 15:28:48 +00:00
|
|
|
qp_init_attr.cap.max_send_wr = mad_sendq_size;
|
|
|
|
qp_init_attr.cap.max_recv_wr = mad_recvq_size;
|
2005-04-16 22:20:36 +00:00
|
|
|
qp_init_attr.cap.max_send_sge = IB_MAD_SEND_REQ_MAX_SG;
|
|
|
|
qp_init_attr.cap.max_recv_sge = IB_MAD_RECV_REQ_MAX_SG;
|
|
|
|
qp_init_attr.qp_type = qp_type;
|
|
|
|
qp_init_attr.port_num = qp_info->port_priv->port_num;
|
|
|
|
qp_init_attr.qp_context = qp_info;
|
|
|
|
qp_init_attr.event_handler = qp_event_handler;
|
|
|
|
qp_info->qp = ib_create_qp(qp_info->port_priv->pd, &qp_init_attr);
|
|
|
|
if (IS_ERR(qp_info->qp)) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&qp_info->port_priv->device->dev,
|
|
|
|
"Couldn't create ib_mad QP%d\n",
|
|
|
|
get_spl_qp_index(qp_type));
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = PTR_ERR(qp_info->qp);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
/* Use minimum queue sizes unless the CQ is resized */
|
2009-09-07 15:28:48 +00:00
|
|
|
qp_info->send_queue.max_active = mad_sendq_size;
|
|
|
|
qp_info->recv_queue.max_active = mad_recvq_size;
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy_mad_qp(struct ib_mad_qp_info *qp_info)
|
|
|
|
{
|
2010-09-28 00:51:11 +00:00
|
|
|
if (!qp_info->qp)
|
|
|
|
return;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
ib_destroy_qp(qp_info->qp);
|
2005-11-07 09:01:32 +00:00
|
|
|
kfree(qp_info->snoop_table);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open the port
|
|
|
|
* Create the QP, PD, MR, and CQ if needed
|
|
|
|
*/
|
|
|
|
static int ib_mad_port_open(struct ib_device *device,
|
|
|
|
int port_num)
|
|
|
|
{
|
|
|
|
int ret, cq_size;
|
|
|
|
struct ib_mad_port_private *port_priv;
|
|
|
|
unsigned long flags;
|
|
|
|
char name[sizeof "ib_mad123"];
|
2010-09-28 00:51:11 +00:00
|
|
|
int has_smi;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-06 18:38:29 +00:00
|
|
|
if (WARN_ON(rdma_max_mad_size(device, port_num) < IB_MGMT_MAD_SIZE))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2015-06-06 18:38:33 +00:00
|
|
|
if (WARN_ON(rdma_cap_opa_mad(device, port_num) &&
|
|
|
|
rdma_max_mad_size(device, port_num) < OPA_MGMT_MAD_SIZE))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Create new device info */
|
2005-11-02 15:23:14 +00:00
|
|
|
port_priv = kzalloc(sizeof *port_priv, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!port_priv) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev, "No memory for ib_mad_port_private\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2005-11-02 15:23:14 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
port_priv->device = device;
|
|
|
|
port_priv->port_num = port_num;
|
|
|
|
spin_lock_init(&port_priv->reg_lock);
|
|
|
|
INIT_LIST_HEAD(&port_priv->agent_list);
|
|
|
|
init_mad_qp(port_priv, &port_priv->qp_info[0]);
|
|
|
|
init_mad_qp(port_priv, &port_priv->qp_info[1]);
|
|
|
|
|
2010-09-28 00:51:11 +00:00
|
|
|
cq_size = mad_sendq_size + mad_recvq_size;
|
2015-05-05 12:50:33 +00:00
|
|
|
has_smi = rdma_cap_ib_smi(device, port_num);
|
2010-09-28 00:51:11 +00:00
|
|
|
if (has_smi)
|
|
|
|
cq_size *= 2;
|
|
|
|
|
2016-01-06 06:46:12 +00:00
|
|
|
port_priv->cq = ib_alloc_cq(port_priv->device, port_priv, cq_size, 0,
|
|
|
|
IB_POLL_WORKQUEUE);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (IS_ERR(port_priv->cq)) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev, "Couldn't create ib_mad CQ\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = PTR_ERR(port_priv->cq);
|
|
|
|
goto error3;
|
|
|
|
}
|
|
|
|
|
|
|
|
port_priv->pd = ib_alloc_pd(device);
|
|
|
|
if (IS_ERR(port_priv->pd)) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev, "Couldn't create ib_mad PD\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = PTR_ERR(port_priv->pd);
|
|
|
|
goto error4;
|
|
|
|
}
|
|
|
|
|
2010-09-28 00:51:11 +00:00
|
|
|
if (has_smi) {
|
|
|
|
ret = create_mad_qp(&port_priv->qp_info[0], IB_QPT_SMI);
|
|
|
|
if (ret)
|
|
|
|
goto error6;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = create_mad_qp(&port_priv->qp_info[1], IB_QPT_GSI);
|
|
|
|
if (ret)
|
|
|
|
goto error7;
|
|
|
|
|
|
|
|
snprintf(name, sizeof name, "ib_mad%d", port_num);
|
|
|
|
port_priv->wq = create_singlethread_workqueue(name);
|
|
|
|
if (!port_priv->wq) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto error8;
|
|
|
|
}
|
|
|
|
|
2006-03-20 18:08:25 +00:00
|
|
|
spin_lock_irqsave(&ib_mad_port_list_lock, flags);
|
|
|
|
list_add_tail(&port_priv->port_list, &ib_mad_port_list);
|
|
|
|
spin_unlock_irqrestore(&ib_mad_port_list_lock, flags);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = ib_mad_port_start(port_priv);
|
|
|
|
if (ret) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev, "Couldn't start port\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error9;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error9:
|
2006-03-20 18:08:25 +00:00
|
|
|
spin_lock_irqsave(&ib_mad_port_list_lock, flags);
|
|
|
|
list_del_init(&port_priv->port_list);
|
|
|
|
spin_unlock_irqrestore(&ib_mad_port_list_lock, flags);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
destroy_workqueue(port_priv->wq);
|
|
|
|
error8:
|
|
|
|
destroy_mad_qp(&port_priv->qp_info[1]);
|
|
|
|
error7:
|
|
|
|
destroy_mad_qp(&port_priv->qp_info[0]);
|
|
|
|
error6:
|
|
|
|
ib_dealloc_pd(port_priv->pd);
|
|
|
|
error4:
|
2016-01-06 06:46:12 +00:00
|
|
|
ib_free_cq(port_priv->cq);
|
2005-04-16 22:20:36 +00:00
|
|
|
cleanup_recv_queue(&port_priv->qp_info[1]);
|
|
|
|
cleanup_recv_queue(&port_priv->qp_info[0]);
|
|
|
|
error3:
|
|
|
|
kfree(port_priv);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close the port
|
|
|
|
* If there are no classes using the port, free the port
|
|
|
|
* resources (CQ, MR, PD, QP) and remove the port's info structure
|
|
|
|
*/
|
|
|
|
static int ib_mad_port_close(struct ib_device *device, int port_num)
|
|
|
|
{
|
|
|
|
struct ib_mad_port_private *port_priv;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ib_mad_port_list_lock, flags);
|
|
|
|
port_priv = __ib_get_mad_port(device, port_num);
|
|
|
|
if (port_priv == NULL) {
|
|
|
|
spin_unlock_irqrestore(&ib_mad_port_list_lock, flags);
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev, "Port %d not found\n", port_num);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2006-03-20 18:08:25 +00:00
|
|
|
list_del_init(&port_priv->port_list);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&ib_mad_port_list_lock, flags);
|
|
|
|
|
|
|
|
destroy_workqueue(port_priv->wq);
|
|
|
|
destroy_mad_qp(&port_priv->qp_info[1]);
|
|
|
|
destroy_mad_qp(&port_priv->qp_info[0]);
|
|
|
|
ib_dealloc_pd(port_priv->pd);
|
2016-01-06 06:46:12 +00:00
|
|
|
ib_free_cq(port_priv->cq);
|
2005-04-16 22:20:36 +00:00
|
|
|
cleanup_recv_queue(&port_priv->qp_info[1]);
|
|
|
|
cleanup_recv_queue(&port_priv->qp_info[0]);
|
|
|
|
/* XXX: Handle deallocation of MAD registration tables */
|
|
|
|
|
|
|
|
kfree(port_priv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ib_mad_init_device(struct ib_device *device)
|
|
|
|
{
|
2015-06-29 13:57:00 +00:00
|
|
|
int start, i;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-29 13:57:00 +00:00
|
|
|
start = rdma_start_port(device);
|
2005-10-06 20:28:16 +00:00
|
|
|
|
2015-06-29 13:57:00 +00:00
|
|
|
for (i = start; i <= rdma_end_port(device); i++) {
|
2015-05-05 12:50:32 +00:00
|
|
|
if (!rdma_cap_ib_mad(device, i))
|
2015-05-05 12:50:20 +00:00
|
|
|
continue;
|
|
|
|
|
2005-10-06 20:28:16 +00:00
|
|
|
if (ib_mad_port_open(device, i)) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev, "Couldn't open port %d\n", i);
|
2005-10-06 20:28:16 +00:00
|
|
|
goto error;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2005-10-06 20:28:16 +00:00
|
|
|
if (ib_agent_port_open(device, i)) {
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev,
|
|
|
|
"Couldn't open port %d for agents\n", i);
|
2005-10-06 20:28:16 +00:00
|
|
|
goto error_agent;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-27 18:45:27 +00:00
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-10-06 20:28:16 +00:00
|
|
|
error_agent:
|
|
|
|
if (ib_mad_port_close(device, i))
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev, "Couldn't close port %d\n", i);
|
2005-10-06 20:28:16 +00:00
|
|
|
|
|
|
|
error:
|
2015-05-05 12:50:20 +00:00
|
|
|
while (--i >= start) {
|
2015-05-05 12:50:32 +00:00
|
|
|
if (!rdma_cap_ib_mad(device, i))
|
2015-05-05 12:50:20 +00:00
|
|
|
continue;
|
2005-10-06 20:28:16 +00:00
|
|
|
|
|
|
|
if (ib_agent_port_close(device, i))
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev,
|
|
|
|
"Couldn't close port %d for agents\n", i);
|
2005-10-06 20:28:16 +00:00
|
|
|
if (ib_mad_port_close(device, i))
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev, "Couldn't close port %d\n", i);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-30 14:50:14 +00:00
|
|
|
static void ib_mad_remove_device(struct ib_device *device, void *client_data)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2015-06-29 13:57:00 +00:00
|
|
|
int i;
|
2015-05-05 12:50:20 +00:00
|
|
|
|
2015-06-29 13:57:00 +00:00
|
|
|
for (i = rdma_start_port(device); i <= rdma_end_port(device); i++) {
|
2015-05-05 12:50:32 +00:00
|
|
|
if (!rdma_cap_ib_mad(device, i))
|
2015-05-05 12:50:20 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ib_agent_port_close(device, i))
|
2014-08-08 23:00:53 +00:00
|
|
|
dev_err(&device->dev,
|
2015-05-05 12:50:20 +00:00
|
|
|
"Couldn't close port %d for agents\n", i);
|
|
|
|
if (ib_mad_port_close(device, i))
|
|
|
|
dev_err(&device->dev, "Couldn't close port %d\n", i);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ib_client mad_client = {
|
|
|
|
.name = "mad",
|
|
|
|
.add = ib_mad_init_device,
|
|
|
|
.remove = ib_mad_remove_device
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ib_mad_init_module(void)
|
|
|
|
{
|
2009-09-07 15:28:48 +00:00
|
|
|
mad_recvq_size = min(mad_recvq_size, IB_MAD_QP_MAX_SIZE);
|
|
|
|
mad_recvq_size = max(mad_recvq_size, IB_MAD_QP_MIN_SIZE);
|
|
|
|
|
|
|
|
mad_sendq_size = min(mad_sendq_size, IB_MAD_QP_MAX_SIZE);
|
|
|
|
mad_sendq_size = max(mad_sendq_size, IB_MAD_QP_MIN_SIZE);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
INIT_LIST_HEAD(&ib_mad_port_list);
|
|
|
|
|
|
|
|
if (ib_register_client(&mad_client)) {
|
2014-08-08 23:00:53 +00:00
|
|
|
pr_err("Couldn't register ib_mad client\n");
|
2015-06-06 18:38:30 +00:00
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit ib_mad_cleanup_module(void)
|
|
|
|
{
|
|
|
|
ib_unregister_client(&mad_client);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ib_mad_init_module);
|
|
|
|
module_exit(ib_mad_cleanup_module);
|