2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
|
|
|
|
* Copyright (c) 2004 Infinicon Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004 Intel Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004 Topspin Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004 Voltaire Corporation. All rights reserved.
|
2005-08-11 14:03:10 +08:00
|
|
|
* Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
|
2006-01-31 06:29:21 +08:00
|
|
|
* Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
|
2005-04-17 06:20:36 +08: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/err.h>
|
2011-05-28 03:29:33 +08:00
|
|
|
#include <linux/export.h>
|
2005-11-07 16:59:43 +08:00
|
|
|
#include <linux/string.h>
|
2011-08-09 06:31:51 +08:00
|
|
|
#include <linux/slab.h>
|
2015-10-15 23:38:51 +08:00
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/in6.h>
|
|
|
|
#include <net/addrconf.h>
|
IB/core: Enforce PKey security on QPs
Add new LSM hooks to allocate and free security contexts and check for
permission to access a PKey.
Allocate and free a security context when creating and destroying a QP.
This context is used for controlling access to PKeys.
When a request is made to modify a QP that changes the port, PKey index,
or alternate path, check that the QP has permission for the PKey in the
PKey table index on the subnet prefix of the port. If the QP is shared
make sure all handles to the QP also have access.
Store which port and PKey index a QP is using. After the reset to init
transition the user can modify the port, PKey index and alternate path
independently. So port and PKey settings changes can be a merge of the
previous settings and the new ones.
In order to maintain access control if there are PKey table or subnet
prefix change keep a list of all QPs are using each PKey index on
each port. If a change occurs all QPs using that device and port must
have access enforced for the new cache settings.
These changes add a transaction to the QP modify process. Association
with the old port and PKey index must be maintained if the modify fails,
and must be removed if it succeeds. Association with the new port and
PKey index must be established prior to the modify and removed if the
modify fails.
1. When a QP is modified to a particular Port, PKey index or alternate
path insert that QP into the appropriate lists.
2. Check permission to access the new settings.
3. If step 2 grants access attempt to modify the QP.
4a. If steps 2 and 3 succeed remove any prior associations.
4b. If ether fails remove the new setting associations.
If a PKey table or subnet prefix changes walk the list of QPs and
check that they have permission. If not send the QP to the error state
and raise a fatal error event. If it's a shared QP make sure all the
QPs that share the real_qp have permission as well. If the QP that
owns a security structure is denied access the security structure is
marked as such and the QP is added to an error_list. Once the moving
the QP to error is complete the security structure mark is cleared.
Maintaining the lists correctly turns QP destroy into a transaction.
The hardware driver for the device frees the ib_qp structure, so while
the destroy is in progress the ib_qp pointer in the ib_qp_security
struct is undefined. When the destroy process begins the ib_qp_security
structure is marked as destroying. This prevents any action from being
taken on the QP pointer. After the QP is destroyed successfully it
could still listed on an error_list wait for it to be processed by that
flow before cleaning up the structure.
If the destroy fails the QPs port and PKey settings are reinserted into
the appropriate lists, the destroying flag is cleared, and access control
is enforced, in case there were any cache changes during the destroy
flow.
To keep the security changes isolated a new file is used to hold security
related functionality.
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Acked-by: Doug Ledford <dledford@redhat.com>
[PM: merge fixup in ib_verbs.h and uverbs_cmd.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2017-05-19 20:48:52 +08:00
|
|
|
#include <linux/security.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-08-26 04:40:04 +08:00
|
|
|
#include <rdma/ib_verbs.h>
|
|
|
|
#include <rdma/ib_cache.h>
|
IB/core: Ethernet L2 attributes in verbs/cm structures
This patch add the support for Ethernet L2 attributes in the
verbs/cm/cma structures.
When dealing with L2 Ethernet, we should use smac, dmac, vlan ID and priority
in a similar manner that the IB L2 (and the L4 PKEY) attributes are used.
Thus, those attributes were added to the following structures:
* ib_ah_attr - added dmac
* ib_qp_attr - added smac and vlan_id, (sl remains vlan priority)
* ib_wc - added smac, vlan_id
* ib_sa_path_rec - added smac, dmac, vlan_id
* cm_av - added smac and vlan_id
For the path record structure, extra care was taken to avoid the new
fields when packing it into wire format, so we don't break the IB CM
and SA wire protocol.
On the active side, the CM fills. its internal structures from the
path provided by the ULP. We add there taking the ETH L2 attributes
and placing them into the CM Address Handle (struct cm_av).
On the passive side, the CM fills its internal structures from the WC
associated with the REQ message. We add there taking the ETH L2
attributes from the WC.
When the HW driver provides the required ETH L2 attributes in the WC,
they set the IB_WC_WITH_SMAC and IB_WC_WITH_VLAN flags. The IB core
code checks for the presence of these flags, and in their absence does
address resolution from the ib_init_ah_from_wc() helper function.
ib_modify_qp_is_ok is also updated to consider the link layer. Some
parameters are mandatory for Ethernet link layer, while they are
irrelevant for IB. Vendor drivers are modified to support the new
function signature.
Signed-off-by: Matan Barak <matanb@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2013-12-13 00:03:11 +08:00
|
|
|
#include <rdma/ib_addr.h>
|
2016-05-04 00:01:09 +08:00
|
|
|
#include <rdma/rw.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-13 00:03:17 +08:00
|
|
|
#include "core_priv.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-10-16 13:45:13 +08:00
|
|
|
static int ib_resolve_eth_dmac(struct ib_device *device,
|
|
|
|
struct rdma_ah_attr *ah_attr);
|
|
|
|
|
2015-05-18 18:40:28 +08:00
|
|
|
static const char * const ib_events[] = {
|
|
|
|
[IB_EVENT_CQ_ERR] = "CQ error",
|
|
|
|
[IB_EVENT_QP_FATAL] = "QP fatal error",
|
|
|
|
[IB_EVENT_QP_REQ_ERR] = "QP request error",
|
|
|
|
[IB_EVENT_QP_ACCESS_ERR] = "QP access error",
|
|
|
|
[IB_EVENT_COMM_EST] = "communication established",
|
|
|
|
[IB_EVENT_SQ_DRAINED] = "send queue drained",
|
|
|
|
[IB_EVENT_PATH_MIG] = "path migration successful",
|
|
|
|
[IB_EVENT_PATH_MIG_ERR] = "path migration error",
|
|
|
|
[IB_EVENT_DEVICE_FATAL] = "device fatal error",
|
|
|
|
[IB_EVENT_PORT_ACTIVE] = "port active",
|
|
|
|
[IB_EVENT_PORT_ERR] = "port error",
|
|
|
|
[IB_EVENT_LID_CHANGE] = "LID change",
|
|
|
|
[IB_EVENT_PKEY_CHANGE] = "P_key change",
|
|
|
|
[IB_EVENT_SM_CHANGE] = "SM change",
|
|
|
|
[IB_EVENT_SRQ_ERR] = "SRQ error",
|
|
|
|
[IB_EVENT_SRQ_LIMIT_REACHED] = "SRQ limit reached",
|
|
|
|
[IB_EVENT_QP_LAST_WQE_REACHED] = "last WQE reached",
|
|
|
|
[IB_EVENT_CLIENT_REREGISTER] = "client reregister",
|
|
|
|
[IB_EVENT_GID_CHANGE] = "GID changed",
|
|
|
|
};
|
|
|
|
|
2015-08-04 01:01:52 +08:00
|
|
|
const char *__attribute_const__ ib_event_msg(enum ib_event_type event)
|
2015-05-18 18:40:28 +08:00
|
|
|
{
|
|
|
|
size_t index = event;
|
|
|
|
|
|
|
|
return (index < ARRAY_SIZE(ib_events) && ib_events[index]) ?
|
|
|
|
ib_events[index] : "unrecognized event";
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_event_msg);
|
|
|
|
|
|
|
|
static const char * const wc_statuses[] = {
|
|
|
|
[IB_WC_SUCCESS] = "success",
|
|
|
|
[IB_WC_LOC_LEN_ERR] = "local length error",
|
|
|
|
[IB_WC_LOC_QP_OP_ERR] = "local QP operation error",
|
|
|
|
[IB_WC_LOC_EEC_OP_ERR] = "local EE context operation error",
|
|
|
|
[IB_WC_LOC_PROT_ERR] = "local protection error",
|
|
|
|
[IB_WC_WR_FLUSH_ERR] = "WR flushed",
|
|
|
|
[IB_WC_MW_BIND_ERR] = "memory management operation error",
|
|
|
|
[IB_WC_BAD_RESP_ERR] = "bad response error",
|
|
|
|
[IB_WC_LOC_ACCESS_ERR] = "local access error",
|
|
|
|
[IB_WC_REM_INV_REQ_ERR] = "invalid request error",
|
|
|
|
[IB_WC_REM_ACCESS_ERR] = "remote access error",
|
|
|
|
[IB_WC_REM_OP_ERR] = "remote operation error",
|
|
|
|
[IB_WC_RETRY_EXC_ERR] = "transport retry counter exceeded",
|
|
|
|
[IB_WC_RNR_RETRY_EXC_ERR] = "RNR retry counter exceeded",
|
|
|
|
[IB_WC_LOC_RDD_VIOL_ERR] = "local RDD violation error",
|
|
|
|
[IB_WC_REM_INV_RD_REQ_ERR] = "remote invalid RD request",
|
|
|
|
[IB_WC_REM_ABORT_ERR] = "operation aborted",
|
|
|
|
[IB_WC_INV_EECN_ERR] = "invalid EE context number",
|
|
|
|
[IB_WC_INV_EEC_STATE_ERR] = "invalid EE context state",
|
|
|
|
[IB_WC_FATAL_ERR] = "fatal error",
|
|
|
|
[IB_WC_RESP_TIMEOUT_ERR] = "response timeout error",
|
|
|
|
[IB_WC_GENERAL_ERR] = "general error",
|
|
|
|
};
|
|
|
|
|
2015-08-04 01:01:52 +08:00
|
|
|
const char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status)
|
2015-05-18 18:40:28 +08:00
|
|
|
{
|
|
|
|
size_t index = status;
|
|
|
|
|
|
|
|
return (index < ARRAY_SIZE(wc_statuses) && wc_statuses[index]) ?
|
|
|
|
wc_statuses[index] : "unrecognized status";
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_wc_status_msg);
|
|
|
|
|
2014-06-05 01:00:16 +08:00
|
|
|
__attribute_const__ int ib_rate_to_mult(enum ib_rate rate)
|
2006-04-11 00:43:47 +08:00
|
|
|
{
|
|
|
|
switch (rate) {
|
2018-01-02 21:50:40 +08:00
|
|
|
case IB_RATE_2_5_GBPS: return 1;
|
|
|
|
case IB_RATE_5_GBPS: return 2;
|
|
|
|
case IB_RATE_10_GBPS: return 4;
|
|
|
|
case IB_RATE_20_GBPS: return 8;
|
|
|
|
case IB_RATE_30_GBPS: return 12;
|
|
|
|
case IB_RATE_40_GBPS: return 16;
|
|
|
|
case IB_RATE_60_GBPS: return 24;
|
|
|
|
case IB_RATE_80_GBPS: return 32;
|
|
|
|
case IB_RATE_120_GBPS: return 48;
|
|
|
|
case IB_RATE_14_GBPS: return 6;
|
|
|
|
case IB_RATE_56_GBPS: return 22;
|
|
|
|
case IB_RATE_112_GBPS: return 45;
|
|
|
|
case IB_RATE_168_GBPS: return 67;
|
|
|
|
case IB_RATE_25_GBPS: return 10;
|
|
|
|
case IB_RATE_100_GBPS: return 40;
|
|
|
|
case IB_RATE_200_GBPS: return 80;
|
|
|
|
case IB_RATE_300_GBPS: return 120;
|
2018-12-09 17:49:50 +08:00
|
|
|
case IB_RATE_28_GBPS: return 11;
|
|
|
|
case IB_RATE_50_GBPS: return 20;
|
|
|
|
case IB_RATE_400_GBPS: return 160;
|
|
|
|
case IB_RATE_600_GBPS: return 240;
|
2018-01-02 21:50:40 +08:00
|
|
|
default: return -1;
|
2006-04-11 00:43:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_rate_to_mult);
|
|
|
|
|
2014-06-05 01:00:16 +08:00
|
|
|
__attribute_const__ enum ib_rate mult_to_ib_rate(int mult)
|
2006-04-11 00:43:47 +08:00
|
|
|
{
|
|
|
|
switch (mult) {
|
2018-01-02 21:50:40 +08:00
|
|
|
case 1: return IB_RATE_2_5_GBPS;
|
|
|
|
case 2: return IB_RATE_5_GBPS;
|
|
|
|
case 4: return IB_RATE_10_GBPS;
|
|
|
|
case 8: return IB_RATE_20_GBPS;
|
|
|
|
case 12: return IB_RATE_30_GBPS;
|
|
|
|
case 16: return IB_RATE_40_GBPS;
|
|
|
|
case 24: return IB_RATE_60_GBPS;
|
|
|
|
case 32: return IB_RATE_80_GBPS;
|
|
|
|
case 48: return IB_RATE_120_GBPS;
|
|
|
|
case 6: return IB_RATE_14_GBPS;
|
|
|
|
case 22: return IB_RATE_56_GBPS;
|
|
|
|
case 45: return IB_RATE_112_GBPS;
|
|
|
|
case 67: return IB_RATE_168_GBPS;
|
|
|
|
case 10: return IB_RATE_25_GBPS;
|
|
|
|
case 40: return IB_RATE_100_GBPS;
|
|
|
|
case 80: return IB_RATE_200_GBPS;
|
|
|
|
case 120: return IB_RATE_300_GBPS;
|
2018-12-09 17:49:50 +08:00
|
|
|
case 11: return IB_RATE_28_GBPS;
|
|
|
|
case 20: return IB_RATE_50_GBPS;
|
|
|
|
case 160: return IB_RATE_400_GBPS;
|
|
|
|
case 240: return IB_RATE_600_GBPS;
|
2018-01-02 21:50:40 +08:00
|
|
|
default: return IB_RATE_PORT_CURRENT;
|
2006-04-11 00:43:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(mult_to_ib_rate);
|
|
|
|
|
2014-06-05 01:00:16 +08:00
|
|
|
__attribute_const__ int ib_rate_to_mbps(enum ib_rate rate)
|
2011-10-05 19:21:47 +08:00
|
|
|
{
|
|
|
|
switch (rate) {
|
|
|
|
case IB_RATE_2_5_GBPS: return 2500;
|
|
|
|
case IB_RATE_5_GBPS: return 5000;
|
|
|
|
case IB_RATE_10_GBPS: return 10000;
|
|
|
|
case IB_RATE_20_GBPS: return 20000;
|
|
|
|
case IB_RATE_30_GBPS: return 30000;
|
|
|
|
case IB_RATE_40_GBPS: return 40000;
|
|
|
|
case IB_RATE_60_GBPS: return 60000;
|
|
|
|
case IB_RATE_80_GBPS: return 80000;
|
|
|
|
case IB_RATE_120_GBPS: return 120000;
|
|
|
|
case IB_RATE_14_GBPS: return 14062;
|
|
|
|
case IB_RATE_56_GBPS: return 56250;
|
|
|
|
case IB_RATE_112_GBPS: return 112500;
|
|
|
|
case IB_RATE_168_GBPS: return 168750;
|
|
|
|
case IB_RATE_25_GBPS: return 25781;
|
|
|
|
case IB_RATE_100_GBPS: return 103125;
|
|
|
|
case IB_RATE_200_GBPS: return 206250;
|
|
|
|
case IB_RATE_300_GBPS: return 309375;
|
2018-12-09 17:49:50 +08:00
|
|
|
case IB_RATE_28_GBPS: return 28125;
|
|
|
|
case IB_RATE_50_GBPS: return 53125;
|
|
|
|
case IB_RATE_400_GBPS: return 425000;
|
|
|
|
case IB_RATE_600_GBPS: return 637500;
|
2011-10-05 19:21:47 +08:00
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_rate_to_mbps);
|
|
|
|
|
2014-06-05 01:00:16 +08:00
|
|
|
__attribute_const__ enum rdma_transport_type
|
2019-06-14 08:38:17 +08:00
|
|
|
rdma_node_get_transport(unsigned int node_type)
|
2006-08-04 05:02:42 +08:00
|
|
|
{
|
2017-08-17 20:50:38 +08:00
|
|
|
|
|
|
|
if (node_type == RDMA_NODE_USNIC)
|
2014-01-16 09:02:36 +08:00
|
|
|
return RDMA_TRANSPORT_USNIC;
|
2017-08-17 20:50:38 +08:00
|
|
|
if (node_type == RDMA_NODE_USNIC_UDP)
|
2014-01-10 06:48:19 +08:00
|
|
|
return RDMA_TRANSPORT_USNIC_UDP;
|
2017-08-17 20:50:38 +08:00
|
|
|
if (node_type == RDMA_NODE_RNIC)
|
|
|
|
return RDMA_TRANSPORT_IWARP;
|
2019-05-06 01:59:21 +08:00
|
|
|
if (node_type == RDMA_NODE_UNSPECIFIED)
|
|
|
|
return RDMA_TRANSPORT_UNSPECIFIED;
|
2017-08-17 20:50:38 +08:00
|
|
|
|
|
|
|
return RDMA_TRANSPORT_IB;
|
2006-08-04 05:02:42 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(rdma_node_get_transport);
|
|
|
|
|
2010-09-28 08:51:10 +08:00
|
|
|
enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device, u8 port_num)
|
|
|
|
{
|
2017-08-17 20:50:39 +08:00
|
|
|
enum rdma_transport_type lt;
|
2018-12-11 03:09:48 +08:00
|
|
|
if (device->ops.get_link_layer)
|
|
|
|
return device->ops.get_link_layer(device, port_num);
|
2010-09-28 08:51:10 +08:00
|
|
|
|
2017-08-17 20:50:39 +08:00
|
|
|
lt = rdma_node_get_transport(device->node_type);
|
|
|
|
if (lt == RDMA_TRANSPORT_IB)
|
2010-09-28 08:51:10 +08:00
|
|
|
return IB_LINK_LAYER_INFINIBAND;
|
2017-08-17 20:50:39 +08:00
|
|
|
|
|
|
|
return IB_LINK_LAYER_ETHERNET;
|
2010-09-28 08:51:10 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(rdma_port_get_link_layer);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Protection domains */
|
|
|
|
|
2015-08-06 04:14:45 +08:00
|
|
|
/**
|
|
|
|
* ib_alloc_pd - Allocates an unused protection domain.
|
|
|
|
* @device: The device on which to allocate the protection domain.
|
2019-10-10 11:52:46 +08:00
|
|
|
* @flags: protection domain flags
|
|
|
|
* @caller: caller's build-time module name
|
2015-08-06 04:14:45 +08:00
|
|
|
*
|
|
|
|
* A protection domain object provides an association between QPs, shared
|
|
|
|
* receive queues, address handles, memory regions, and memory windows.
|
|
|
|
*
|
|
|
|
* Every PD has a local_dma_lkey which can be used as the lkey value for local
|
|
|
|
* memory operations.
|
|
|
|
*/
|
2016-09-05 18:56:17 +08:00
|
|
|
struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
|
|
|
|
const char *caller)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ib_pd *pd;
|
2016-09-05 18:56:17 +08:00
|
|
|
int mr_access_flags = 0;
|
2019-02-03 20:55:51 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-02-03 20:55:51 +08:00
|
|
|
pd = rdma_zalloc_drv_obj(device, ib_pd);
|
|
|
|
if (!pd)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-08-06 04:14:45 +08:00
|
|
|
pd->device = device;
|
|
|
|
pd->uobject = NULL;
|
2016-09-05 18:56:16 +08:00
|
|
|
pd->__internal_mr = NULL;
|
2015-08-06 04:14:45 +08:00
|
|
|
atomic_set(&pd->usecnt, 0);
|
2016-09-05 18:56:17 +08:00
|
|
|
pd->flags = flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-02-03 20:55:51 +08:00
|
|
|
pd->res.type = RDMA_RESTRACK_PD;
|
|
|
|
rdma_restrack_set_task(&pd->res, caller);
|
|
|
|
|
2019-04-01 00:10:07 +08:00
|
|
|
ret = device->ops.alloc_pd(pd, NULL);
|
2019-02-03 20:55:51 +08:00
|
|
|
if (ret) {
|
|
|
|
kfree(pd);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
rdma_restrack_kadd(&pd->res);
|
|
|
|
|
2015-12-18 16:59:45 +08:00
|
|
|
if (device->attrs.device_cap_flags & IB_DEVICE_LOCAL_DMA_LKEY)
|
2015-08-06 04:14:45 +08:00
|
|
|
pd->local_dma_lkey = device->local_dma_lkey;
|
2016-09-05 18:56:17 +08:00
|
|
|
else
|
|
|
|
mr_access_flags |= IB_ACCESS_LOCAL_WRITE;
|
|
|
|
|
|
|
|
if (flags & IB_PD_UNSAFE_GLOBAL_RKEY) {
|
|
|
|
pr_warn("%s: enabling unsafe global rkey\n", caller);
|
|
|
|
mr_access_flags |= IB_ACCESS_REMOTE_READ | IB_ACCESS_REMOTE_WRITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mr_access_flags) {
|
2015-08-06 04:14:45 +08:00
|
|
|
struct ib_mr *mr;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
mr = pd->device->ops.get_dma_mr(pd, mr_access_flags);
|
2015-08-06 04:14:45 +08:00
|
|
|
if (IS_ERR(mr)) {
|
|
|
|
ib_dealloc_pd(pd);
|
2016-09-05 18:56:21 +08:00
|
|
|
return ERR_CAST(mr);
|
2015-08-06 04:14:45 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-09-05 18:56:21 +08:00
|
|
|
mr->device = pd->device;
|
|
|
|
mr->pd = pd;
|
2019-06-11 23:52:38 +08:00
|
|
|
mr->type = IB_MR_TYPE_DMA;
|
2016-09-05 18:56:21 +08:00
|
|
|
mr->uobject = NULL;
|
|
|
|
mr->need_inval = false;
|
|
|
|
|
2016-09-05 18:56:16 +08:00
|
|
|
pd->__internal_mr = mr;
|
2016-09-05 18:56:17 +08:00
|
|
|
|
|
|
|
if (!(device->attrs.device_cap_flags & IB_DEVICE_LOCAL_DMA_LKEY))
|
|
|
|
pd->local_dma_lkey = pd->__internal_mr->lkey;
|
|
|
|
|
|
|
|
if (flags & IB_PD_UNSAFE_GLOBAL_RKEY)
|
|
|
|
pd->unsafe_global_rkey = pd->__internal_mr->rkey;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2016-09-05 18:56:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return pd;
|
|
|
|
}
|
2016-09-05 18:56:17 +08:00
|
|
|
EXPORT_SYMBOL(__ib_alloc_pd);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-08-06 04:34:31 +08:00
|
|
|
/**
|
2019-05-15 18:49:31 +08:00
|
|
|
* ib_dealloc_pd_user - Deallocates a protection domain.
|
2015-08-06 04:34:31 +08:00
|
|
|
* @pd: The protection domain to deallocate.
|
2019-04-01 00:10:05 +08:00
|
|
|
* @udata: Valid user data or NULL for kernel object
|
2015-08-06 04:34:31 +08:00
|
|
|
*
|
|
|
|
* It is an error to call this function while any resources in the pd still
|
|
|
|
* exist. The caller is responsible to synchronously destroy them and
|
|
|
|
* guarantee no new allocations will happen.
|
|
|
|
*/
|
2019-04-01 00:10:05 +08:00
|
|
|
void ib_dealloc_pd_user(struct ib_pd *pd, struct ib_udata *udata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2015-08-06 04:34:31 +08:00
|
|
|
int ret;
|
|
|
|
|
2016-09-05 18:56:16 +08:00
|
|
|
if (pd->__internal_mr) {
|
2019-04-01 00:10:05 +08:00
|
|
|
ret = pd->device->ops.dereg_mr(pd->__internal_mr, NULL);
|
2015-08-06 04:34:31 +08:00
|
|
|
WARN_ON(ret);
|
2016-09-05 18:56:16 +08:00
|
|
|
pd->__internal_mr = NULL;
|
2015-08-06 04:14:45 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-08-06 04:34:31 +08:00
|
|
|
/* uverbs manipulates usecnt with proper locking, while the kabi
|
|
|
|
requires the caller to guarantee we can't race here. */
|
|
|
|
WARN_ON(atomic_read(&pd->usecnt));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-01-28 17:17:23 +08:00
|
|
|
rdma_restrack_del(&pd->res);
|
2019-04-01 00:10:05 +08:00
|
|
|
pd->device->ops.dealloc_pd(pd, udata);
|
2019-02-03 20:55:51 +08:00
|
|
|
kfree(pd);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2019-04-01 00:10:05 +08:00
|
|
|
EXPORT_SYMBOL(ib_dealloc_pd_user);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Address handles */
|
|
|
|
|
2018-06-13 15:22:05 +08:00
|
|
|
/**
|
|
|
|
* rdma_copy_ah_attr - Copy rdma ah attribute from source to destination.
|
|
|
|
* @dest: Pointer to destination ah_attr. Contents of the destination
|
|
|
|
* pointer is assumed to be invalid and attribute are overwritten.
|
|
|
|
* @src: Pointer to source ah_attr.
|
|
|
|
*/
|
|
|
|
void rdma_copy_ah_attr(struct rdma_ah_attr *dest,
|
|
|
|
const struct rdma_ah_attr *src)
|
|
|
|
{
|
|
|
|
*dest = *src;
|
|
|
|
if (dest->grh.sgid_attr)
|
|
|
|
rdma_hold_gid_attr(dest->grh.sgid_attr);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(rdma_copy_ah_attr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* rdma_replace_ah_attr - Replace valid ah_attr with new new one.
|
|
|
|
* @old: Pointer to existing ah_attr which needs to be replaced.
|
|
|
|
* old is assumed to be valid or zero'd
|
|
|
|
* @new: Pointer to the new ah_attr.
|
|
|
|
*
|
|
|
|
* rdma_replace_ah_attr() first releases any reference in the old ah_attr if
|
|
|
|
* old the ah_attr is valid; after that it copies the new attribute and holds
|
|
|
|
* the reference to the replaced ah_attr.
|
|
|
|
*/
|
|
|
|
void rdma_replace_ah_attr(struct rdma_ah_attr *old,
|
|
|
|
const struct rdma_ah_attr *new)
|
|
|
|
{
|
|
|
|
rdma_destroy_ah_attr(old);
|
|
|
|
*old = *new;
|
|
|
|
if (old->grh.sgid_attr)
|
|
|
|
rdma_hold_gid_attr(old->grh.sgid_attr);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(rdma_replace_ah_attr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* rdma_move_ah_attr - Move ah_attr pointed by source to destination.
|
|
|
|
* @dest: Pointer to destination ah_attr to copy to.
|
|
|
|
* dest is assumed to be valid or zero'd
|
|
|
|
* @src: Pointer to the new ah_attr.
|
|
|
|
*
|
|
|
|
* rdma_move_ah_attr() first releases any reference in the destination ah_attr
|
|
|
|
* if it is valid. This also transfers ownership of internal references from
|
|
|
|
* src to dest, making src invalid in the process. No new reference of the src
|
|
|
|
* ah_attr is taken.
|
|
|
|
*/
|
|
|
|
void rdma_move_ah_attr(struct rdma_ah_attr *dest, struct rdma_ah_attr *src)
|
|
|
|
{
|
|
|
|
rdma_destroy_ah_attr(dest);
|
|
|
|
*dest = *src;
|
|
|
|
src->grh.sgid_attr = NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(rdma_move_ah_attr);
|
|
|
|
|
2018-06-13 15:22:03 +08:00
|
|
|
/*
|
|
|
|
* Validate that the rdma_ah_attr is valid for the device before passing it
|
|
|
|
* off to the driver.
|
|
|
|
*/
|
|
|
|
static int rdma_check_ah_attr(struct ib_device *device,
|
|
|
|
struct rdma_ah_attr *ah_attr)
|
|
|
|
{
|
|
|
|
if (!rdma_is_port_valid(device, ah_attr->port_num))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-07-04 20:57:50 +08:00
|
|
|
if ((rdma_is_grh_required(device, ah_attr->port_num) ||
|
|
|
|
ah_attr->type == RDMA_AH_ATTR_TYPE_ROCE) &&
|
2018-06-13 15:22:03 +08:00
|
|
|
!(ah_attr->ah_flags & IB_AH_GRH))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (ah_attr->grh.sgid_attr) {
|
|
|
|
/*
|
|
|
|
* Make sure the passed sgid_attr is consistent with the
|
|
|
|
* parameters
|
|
|
|
*/
|
|
|
|
if (ah_attr->grh.sgid_attr->index != ah_attr->grh.sgid_index ||
|
|
|
|
ah_attr->grh.sgid_attr->port_num != ah_attr->port_num)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the ah requires a GRH then ensure that sgid_attr pointer is filled in.
|
|
|
|
* On success the caller is responsible to call rdma_unfill_sgid_attr().
|
|
|
|
*/
|
|
|
|
static int rdma_fill_sgid_attr(struct ib_device *device,
|
|
|
|
struct rdma_ah_attr *ah_attr,
|
|
|
|
const struct ib_gid_attr **old_sgid_attr)
|
|
|
|
{
|
|
|
|
const struct ib_gid_attr *sgid_attr;
|
|
|
|
struct ib_global_route *grh;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
*old_sgid_attr = ah_attr->grh.sgid_attr;
|
|
|
|
|
|
|
|
ret = rdma_check_ah_attr(device, ah_attr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!(ah_attr->ah_flags & IB_AH_GRH))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
grh = rdma_ah_retrieve_grh(ah_attr);
|
|
|
|
if (grh->sgid_attr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sgid_attr =
|
|
|
|
rdma_get_gid_attr(device, ah_attr->port_num, grh->sgid_index);
|
|
|
|
if (IS_ERR(sgid_attr))
|
|
|
|
return PTR_ERR(sgid_attr);
|
|
|
|
|
|
|
|
/* Move ownerhip of the kref into the ah_attr */
|
|
|
|
grh->sgid_attr = sgid_attr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rdma_unfill_sgid_attr(struct rdma_ah_attr *ah_attr,
|
|
|
|
const struct ib_gid_attr *old_sgid_attr)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Fill didn't change anything, the caller retains ownership of
|
|
|
|
* whatever it passed
|
|
|
|
*/
|
|
|
|
if (ah_attr->grh.sgid_attr == old_sgid_attr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Otherwise, we need to undo what rdma_fill_sgid_attr so the caller
|
|
|
|
* doesn't see any change in the rdma_ah_attr. If we get here
|
|
|
|
* old_sgid_attr is NULL.
|
|
|
|
*/
|
|
|
|
rdma_destroy_ah_attr(ah_attr);
|
|
|
|
}
|
|
|
|
|
2018-06-13 15:22:08 +08:00
|
|
|
static const struct ib_gid_attr *
|
|
|
|
rdma_update_sgid_attr(struct rdma_ah_attr *ah_attr,
|
|
|
|
const struct ib_gid_attr *old_attr)
|
|
|
|
{
|
|
|
|
if (old_attr)
|
|
|
|
rdma_put_gid_attr(old_attr);
|
|
|
|
if (ah_attr->ah_flags & IB_AH_GRH) {
|
|
|
|
rdma_hold_gid_attr(ah_attr->grh.sgid_attr);
|
|
|
|
return ah_attr->grh.sgid_attr;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-16 13:45:12 +08:00
|
|
|
static struct ib_ah *_rdma_create_ah(struct ib_pd *pd,
|
|
|
|
struct rdma_ah_attr *ah_attr,
|
2018-12-12 17:09:05 +08:00
|
|
|
u32 flags,
|
2017-10-16 13:45:12 +08:00
|
|
|
struct ib_udata *udata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-04-03 21:42:42 +08:00
|
|
|
struct ib_device *device = pd->device;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ib_ah *ah;
|
2019-04-03 21:42:42 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-12-12 17:09:05 +08:00
|
|
|
might_sleep_if(flags & RDMA_CREATE_AH_SLEEPABLE);
|
|
|
|
|
2019-04-03 21:42:42 +08:00
|
|
|
if (!device->ops.create_ah)
|
2018-07-28 02:23:05 +08:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
|
|
|
|
2019-04-03 21:42:42 +08:00
|
|
|
ah = rdma_zalloc_drv_obj_gfp(
|
|
|
|
device, ib_ah,
|
|
|
|
(flags & RDMA_CREATE_AH_SLEEPABLE) ? GFP_KERNEL : GFP_ATOMIC);
|
|
|
|
if (!ah)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-04-03 21:42:42 +08:00
|
|
|
ah->device = device;
|
|
|
|
ah->pd = pd;
|
|
|
|
ah->type = ah_attr->type;
|
|
|
|
ah->sgid_attr = rdma_update_sgid_attr(ah_attr, NULL);
|
2018-06-13 15:22:08 +08:00
|
|
|
|
2019-04-03 21:42:42 +08:00
|
|
|
ret = device->ops.create_ah(ah, ah_attr, flags, udata);
|
|
|
|
if (ret) {
|
|
|
|
kfree(ah);
|
|
|
|
return ERR_PTR(ret);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2019-04-03 21:42:42 +08:00
|
|
|
atomic_inc(&pd->usecnt);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ah;
|
|
|
|
}
|
2017-10-16 13:45:12 +08:00
|
|
|
|
2018-06-13 15:22:03 +08:00
|
|
|
/**
|
|
|
|
* rdma_create_ah - Creates an address handle for the
|
|
|
|
* given address vector.
|
|
|
|
* @pd: The protection domain associated with the address handle.
|
|
|
|
* @ah_attr: The attributes of the address vector.
|
2018-12-12 17:09:05 +08:00
|
|
|
* @flags: Create address handle flags (see enum rdma_create_ah_flags).
|
2018-06-13 15:22:03 +08:00
|
|
|
*
|
|
|
|
* It returns 0 on success and returns appropriate error code on error.
|
|
|
|
* The address handle is used to reference a local or global destination
|
|
|
|
* in all UD QP post sends.
|
|
|
|
*/
|
2018-12-12 17:09:05 +08:00
|
|
|
struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
|
|
|
|
u32 flags)
|
2017-10-16 13:45:12 +08:00
|
|
|
{
|
2018-06-13 15:22:03 +08:00
|
|
|
const struct ib_gid_attr *old_sgid_attr;
|
|
|
|
struct ib_ah *ah;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = rdma_fill_sgid_attr(pd->device, ah_attr, &old_sgid_attr);
|
|
|
|
if (ret)
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
|
2018-12-12 17:09:05 +08:00
|
|
|
ah = _rdma_create_ah(pd, ah_attr, flags, NULL);
|
2018-06-13 15:22:03 +08:00
|
|
|
|
|
|
|
rdma_unfill_sgid_attr(ah_attr, old_sgid_attr);
|
|
|
|
return ah;
|
2017-10-16 13:45:12 +08:00
|
|
|
}
|
2017-04-30 02:41:19 +08:00
|
|
|
EXPORT_SYMBOL(rdma_create_ah);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-10-16 13:45:12 +08:00
|
|
|
/**
|
|
|
|
* rdma_create_user_ah - Creates an address handle for the
|
|
|
|
* given address vector.
|
|
|
|
* It resolves destination mac address for ah attribute of RoCE type.
|
|
|
|
* @pd: The protection domain associated with the address handle.
|
|
|
|
* @ah_attr: The attributes of the address vector.
|
|
|
|
* @udata: pointer to user's input output buffer information need by
|
|
|
|
* provider driver.
|
|
|
|
*
|
|
|
|
* It returns 0 on success and returns appropriate error code on error.
|
|
|
|
* The address handle is used to reference a local or global destination
|
|
|
|
* in all UD QP post sends.
|
|
|
|
*/
|
|
|
|
struct ib_ah *rdma_create_user_ah(struct ib_pd *pd,
|
|
|
|
struct rdma_ah_attr *ah_attr,
|
|
|
|
struct ib_udata *udata)
|
|
|
|
{
|
2018-06-13 15:22:03 +08:00
|
|
|
const struct ib_gid_attr *old_sgid_attr;
|
|
|
|
struct ib_ah *ah;
|
2017-10-16 13:45:12 +08:00
|
|
|
int err;
|
|
|
|
|
2018-06-13 15:22:03 +08:00
|
|
|
err = rdma_fill_sgid_attr(pd->device, ah_attr, &old_sgid_attr);
|
|
|
|
if (err)
|
|
|
|
return ERR_PTR(err);
|
|
|
|
|
2017-10-16 13:45:12 +08:00
|
|
|
if (ah_attr->type == RDMA_AH_ATTR_TYPE_ROCE) {
|
|
|
|
err = ib_resolve_eth_dmac(pd->device, ah_attr);
|
2018-06-13 15:22:03 +08:00
|
|
|
if (err) {
|
|
|
|
ah = ERR_PTR(err);
|
|
|
|
goto out;
|
|
|
|
}
|
2017-10-16 13:45:12 +08:00
|
|
|
}
|
|
|
|
|
2018-12-12 17:09:05 +08:00
|
|
|
ah = _rdma_create_ah(pd, ah_attr, RDMA_CREATE_AH_SLEEPABLE, udata);
|
2018-06-13 15:22:03 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
rdma_unfill_sgid_attr(ah_attr, old_sgid_attr);
|
|
|
|
return ah;
|
2017-10-16 13:45:12 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(rdma_create_user_ah);
|
|
|
|
|
2016-11-10 17:30:56 +08:00
|
|
|
int ib_get_rdma_header_version(const union rdma_network_hdr *hdr)
|
2015-12-23 20:56:51 +08:00
|
|
|
{
|
|
|
|
const struct iphdr *ip4h = (struct iphdr *)&hdr->roce4grh;
|
|
|
|
struct iphdr ip4h_checked;
|
|
|
|
const struct ipv6hdr *ip6h = (struct ipv6hdr *)&hdr->ibgrh;
|
|
|
|
|
|
|
|
/* If it's IPv6, the version must be 6, otherwise, the first
|
|
|
|
* 20 bytes (before the IPv4 header) are garbled.
|
|
|
|
*/
|
|
|
|
if (ip6h->version != 6)
|
|
|
|
return (ip4h->version == 4) ? 4 : 0;
|
|
|
|
/* version may be 6 or 4 because the first 20 bytes could be garbled */
|
|
|
|
|
|
|
|
/* RoCE v2 requires no options, thus header length
|
|
|
|
* must be 5 words
|
|
|
|
*/
|
|
|
|
if (ip4h->ihl != 5)
|
|
|
|
return 6;
|
|
|
|
|
|
|
|
/* Verify checksum.
|
|
|
|
* We can't write on scattered buffers so we need to copy to
|
|
|
|
* temp buffer.
|
|
|
|
*/
|
|
|
|
memcpy(&ip4h_checked, ip4h, sizeof(ip4h_checked));
|
|
|
|
ip4h_checked.check = 0;
|
|
|
|
ip4h_checked.check = ip_fast_csum((u8 *)&ip4h_checked, 5);
|
|
|
|
/* if IPv4 header checksum is OK, believe it */
|
|
|
|
if (ip4h->check == ip4h_checked.check)
|
|
|
|
return 4;
|
|
|
|
return 6;
|
|
|
|
}
|
2016-11-10 17:30:56 +08:00
|
|
|
EXPORT_SYMBOL(ib_get_rdma_header_version);
|
2015-12-23 20:56:51 +08:00
|
|
|
|
|
|
|
static enum rdma_network_type ib_get_net_type_by_grh(struct ib_device *device,
|
|
|
|
u8 port_num,
|
|
|
|
const struct ib_grh *grh)
|
|
|
|
{
|
|
|
|
int grh_version;
|
|
|
|
|
|
|
|
if (rdma_protocol_ib(device, port_num))
|
|
|
|
return RDMA_NETWORK_IB;
|
|
|
|
|
2016-11-10 17:30:56 +08:00
|
|
|
grh_version = ib_get_rdma_header_version((union rdma_network_hdr *)grh);
|
2015-12-23 20:56:51 +08:00
|
|
|
|
|
|
|
if (grh_version == 4)
|
|
|
|
return RDMA_NETWORK_IPV4;
|
|
|
|
|
|
|
|
if (grh->next_hdr == IPPROTO_UDP)
|
|
|
|
return RDMA_NETWORK_IPV6;
|
|
|
|
|
|
|
|
return RDMA_NETWORK_ROCE_V1;
|
|
|
|
}
|
|
|
|
|
2015-10-15 23:38:51 +08:00
|
|
|
struct find_gid_index_context {
|
|
|
|
u16 vlan_id;
|
2015-12-23 20:56:51 +08:00
|
|
|
enum ib_gid_type gid_type;
|
2015-10-15 23:38:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool find_gid_index(const union ib_gid *gid,
|
|
|
|
const struct ib_gid_attr *gid_attr,
|
|
|
|
void *context)
|
|
|
|
{
|
2017-11-14 20:52:04 +08:00
|
|
|
struct find_gid_index_context *ctx = context;
|
2019-10-02 20:17:50 +08:00
|
|
|
u16 vlan_id = 0xffff;
|
|
|
|
int ret;
|
2015-10-15 23:38:51 +08:00
|
|
|
|
2015-12-23 20:56:51 +08:00
|
|
|
if (ctx->gid_type != gid_attr->gid_type)
|
|
|
|
return false;
|
|
|
|
|
2019-10-02 20:17:50 +08:00
|
|
|
ret = rdma_read_gid_l2_fields(gid_attr, &vlan_id, NULL);
|
|
|
|
if (ret)
|
2015-10-15 23:38:51 +08:00
|
|
|
return false;
|
|
|
|
|
2019-10-02 20:17:50 +08:00
|
|
|
return ctx->vlan_id == vlan_id;
|
2015-10-15 23:38:51 +08:00
|
|
|
}
|
|
|
|
|
2018-06-19 15:59:14 +08:00
|
|
|
static const struct ib_gid_attr *
|
|
|
|
get_sgid_attr_from_eth(struct ib_device *device, u8 port_num,
|
|
|
|
u16 vlan_id, const union ib_gid *sgid,
|
|
|
|
enum ib_gid_type gid_type)
|
2015-10-15 23:38:51 +08:00
|
|
|
{
|
2015-12-23 20:56:51 +08:00
|
|
|
struct find_gid_index_context context = {.vlan_id = vlan_id,
|
|
|
|
.gid_type = gid_type};
|
2015-10-15 23:38:51 +08:00
|
|
|
|
2018-06-19 15:59:14 +08:00
|
|
|
return rdma_find_gid_by_filter(device, sgid, port_num, find_gid_index,
|
|
|
|
&context);
|
2015-10-15 23:38:51 +08:00
|
|
|
}
|
|
|
|
|
2016-11-10 17:30:56 +08:00
|
|
|
int ib_get_gids_from_rdma_hdr(const union rdma_network_hdr *hdr,
|
|
|
|
enum rdma_network_type net_type,
|
|
|
|
union ib_gid *sgid, union ib_gid *dgid)
|
2015-12-23 20:56:51 +08:00
|
|
|
{
|
|
|
|
struct sockaddr_in src_in;
|
|
|
|
struct sockaddr_in dst_in;
|
|
|
|
__be32 src_saddr, dst_saddr;
|
|
|
|
|
|
|
|
if (!sgid || !dgid)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (net_type == RDMA_NETWORK_IPV4) {
|
|
|
|
memcpy(&src_in.sin_addr.s_addr,
|
|
|
|
&hdr->roce4grh.saddr, 4);
|
|
|
|
memcpy(&dst_in.sin_addr.s_addr,
|
|
|
|
&hdr->roce4grh.daddr, 4);
|
|
|
|
src_saddr = src_in.sin_addr.s_addr;
|
|
|
|
dst_saddr = dst_in.sin_addr.s_addr;
|
|
|
|
ipv6_addr_set_v4mapped(src_saddr,
|
|
|
|
(struct in6_addr *)sgid);
|
|
|
|
ipv6_addr_set_v4mapped(dst_saddr,
|
|
|
|
(struct in6_addr *)dgid);
|
|
|
|
return 0;
|
|
|
|
} else if (net_type == RDMA_NETWORK_IPV6 ||
|
|
|
|
net_type == RDMA_NETWORK_IB) {
|
|
|
|
*dgid = hdr->ibgrh.dgid;
|
|
|
|
*sgid = hdr->ibgrh.sgid;
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2016-11-10 17:30:56 +08:00
|
|
|
EXPORT_SYMBOL(ib_get_gids_from_rdma_hdr);
|
2015-12-23 20:56:51 +08:00
|
|
|
|
2017-11-14 20:51:49 +08:00
|
|
|
/* Resolve destination mac address and hop limit for unicast destination
|
|
|
|
* GID entry, considering the source GID entry as well.
|
|
|
|
* ah_attribute must have have valid port_num, sgid_index.
|
|
|
|
*/
|
|
|
|
static int ib_resolve_unicast_gid_dmac(struct ib_device *device,
|
|
|
|
struct rdma_ah_attr *ah_attr)
|
|
|
|
{
|
2018-06-19 15:59:14 +08:00
|
|
|
struct ib_global_route *grh = rdma_ah_retrieve_grh(ah_attr);
|
|
|
|
const struct ib_gid_attr *sgid_attr = grh->sgid_attr;
|
2017-11-14 20:51:49 +08:00
|
|
|
int hop_limit = 0xff;
|
2018-06-19 15:59:14 +08:00
|
|
|
int ret = 0;
|
2017-11-14 20:51:49 +08:00
|
|
|
|
2017-11-14 20:51:50 +08:00
|
|
|
/* If destination is link local and source GID is RoCEv1,
|
|
|
|
* IP stack is not used.
|
|
|
|
*/
|
|
|
|
if (rdma_link_local_addr((struct in6_addr *)grh->dgid.raw) &&
|
2018-06-19 15:59:14 +08:00
|
|
|
sgid_attr->gid_type == IB_GID_TYPE_ROCE) {
|
2017-11-14 20:51:50 +08:00
|
|
|
rdma_get_ll_mac((struct in6_addr *)grh->dgid.raw,
|
|
|
|
ah_attr->roce.dmac);
|
2018-06-19 15:59:14 +08:00
|
|
|
return ret;
|
2017-11-14 20:51:50 +08:00
|
|
|
}
|
|
|
|
|
2018-06-19 15:59:14 +08:00
|
|
|
ret = rdma_addr_find_l2_eth_by_grh(&sgid_attr->gid, &grh->dgid,
|
2017-11-14 20:51:49 +08:00
|
|
|
ah_attr->roce.dmac,
|
2018-09-05 17:54:26 +08:00
|
|
|
sgid_attr, &hop_limit);
|
2017-11-14 20:51:49 +08:00
|
|
|
|
|
|
|
grh->hop_limit = hop_limit;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
RDMA/core: Document confusing code
While looking into Coverity ID 1351047 I ran into the following
piece of code at
drivers/infiniband/core/verbs.c:496:
ret = rdma_addr_find_l2_eth_by_grh(&dgid, &sgid,
ah_attr->dmac,
wc->wc_flags & IB_WC_WITH_VLAN ?
NULL : &vlan_id,
&if_index, &hoplimit);
The issue here is that the position of arguments in the call to
rdma_addr_find_l2_eth_by_grh() function do not match the order of
the parameters:
&dgid is passed to sgid
&sgid is passed to dgid
This is the function prototype:
int rdma_addr_find_l2_eth_by_grh(const union ib_gid *sgid,
const union ib_gid *dgid,
u8 *dmac, u16 *vlan_id, int *if_index,
int *hoplimit)
My question here is if this is intentional?
Answer:
Yes. ib_init_ah_from_wc() creates ah from the incoming packet.
Incoming packet has dgid of the receiver node on which this code is
getting executed and sgid contains the GID of the sender.
When resolving mac address of destination, you use arrived dgid as
sgid and use sgid as dgid because sgid contains destinations GID whom to
respond to.
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2017-05-05 09:38:20 +08:00
|
|
|
/*
|
2017-11-14 20:52:17 +08:00
|
|
|
* This function initializes address handle attributes from the incoming packet.
|
RDMA/core: Document confusing code
While looking into Coverity ID 1351047 I ran into the following
piece of code at
drivers/infiniband/core/verbs.c:496:
ret = rdma_addr_find_l2_eth_by_grh(&dgid, &sgid,
ah_attr->dmac,
wc->wc_flags & IB_WC_WITH_VLAN ?
NULL : &vlan_id,
&if_index, &hoplimit);
The issue here is that the position of arguments in the call to
rdma_addr_find_l2_eth_by_grh() function do not match the order of
the parameters:
&dgid is passed to sgid
&sgid is passed to dgid
This is the function prototype:
int rdma_addr_find_l2_eth_by_grh(const union ib_gid *sgid,
const union ib_gid *dgid,
u8 *dmac, u16 *vlan_id, int *if_index,
int *hoplimit)
My question here is if this is intentional?
Answer:
Yes. ib_init_ah_from_wc() creates ah from the incoming packet.
Incoming packet has dgid of the receiver node on which this code is
getting executed and sgid contains the GID of the sender.
When resolving mac address of destination, you use arrived dgid as
sgid and use sgid as dgid because sgid contains destinations GID whom to
respond to.
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2017-05-05 09:38:20 +08:00
|
|
|
* Incoming packet has dgid of the receiver node on which this code is
|
|
|
|
* getting executed and, sgid contains the GID of the sender.
|
|
|
|
*
|
|
|
|
* When resolving mac address of destination, the arrived dgid is used
|
|
|
|
* as sgid and, sgid is used as dgid because sgid contains destinations
|
|
|
|
* GID whom to respond to.
|
|
|
|
*
|
2018-06-19 15:59:14 +08:00
|
|
|
* On success the caller is responsible to call rdma_destroy_ah_attr on the
|
|
|
|
* attr.
|
RDMA/core: Document confusing code
While looking into Coverity ID 1351047 I ran into the following
piece of code at
drivers/infiniband/core/verbs.c:496:
ret = rdma_addr_find_l2_eth_by_grh(&dgid, &sgid,
ah_attr->dmac,
wc->wc_flags & IB_WC_WITH_VLAN ?
NULL : &vlan_id,
&if_index, &hoplimit);
The issue here is that the position of arguments in the call to
rdma_addr_find_l2_eth_by_grh() function do not match the order of
the parameters:
&dgid is passed to sgid
&sgid is passed to dgid
This is the function prototype:
int rdma_addr_find_l2_eth_by_grh(const union ib_gid *sgid,
const union ib_gid *dgid,
u8 *dmac, u16 *vlan_id, int *if_index,
int *hoplimit)
My question here is if this is intentional?
Answer:
Yes. ib_init_ah_from_wc() creates ah from the incoming packet.
Incoming packet has dgid of the receiver node on which this code is
getting executed and sgid contains the GID of the sender.
When resolving mac address of destination, you use arrived dgid as
sgid and use sgid as dgid because sgid contains destinations GID whom to
respond to.
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2017-05-05 09:38:20 +08:00
|
|
|
*/
|
2017-11-14 20:52:17 +08:00
|
|
|
int ib_init_ah_attr_from_wc(struct ib_device *device, u8 port_num,
|
|
|
|
const struct ib_wc *wc, const struct ib_grh *grh,
|
|
|
|
struct rdma_ah_attr *ah_attr)
|
2005-07-28 02:45:34 +08:00
|
|
|
{
|
|
|
|
u32 flow_class;
|
|
|
|
int ret;
|
2015-12-23 20:56:51 +08:00
|
|
|
enum rdma_network_type net_type = RDMA_NETWORK_IB;
|
|
|
|
enum ib_gid_type gid_type = IB_GID_TYPE_IB;
|
2018-06-19 15:59:14 +08:00
|
|
|
const struct ib_gid_attr *sgid_attr;
|
2016-01-04 16:49:54 +08:00
|
|
|
int hoplimit = 0xff;
|
2015-12-23 20:56:51 +08:00
|
|
|
union ib_gid dgid;
|
|
|
|
union ib_gid sgid;
|
2005-07-28 02:45:34 +08:00
|
|
|
|
2017-08-30 01:34:44 +08:00
|
|
|
might_sleep();
|
|
|
|
|
2006-06-18 11:37:39 +08:00
|
|
|
memset(ah_attr, 0, sizeof *ah_attr);
|
2017-04-30 02:41:29 +08:00
|
|
|
ah_attr->type = rdma_ah_find_type(device, port_num);
|
2015-05-05 20:50:40 +08:00
|
|
|
if (rdma_cap_eth_ah(device, port_num)) {
|
2015-12-23 20:56:51 +08:00
|
|
|
if (wc->wc_flags & IB_WC_WITH_NETWORK_HDR_TYPE)
|
|
|
|
net_type = wc->network_hdr_type;
|
|
|
|
else
|
|
|
|
net_type = ib_get_net_type_by_grh(device, port_num, grh);
|
|
|
|
gid_type = ib_network_to_gid_type(net_type);
|
|
|
|
}
|
2016-11-10 17:30:56 +08:00
|
|
|
ret = ib_get_gids_from_rdma_hdr((union rdma_network_hdr *)grh, net_type,
|
|
|
|
&sgid, &dgid);
|
2015-12-23 20:56:51 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-11-14 20:51:49 +08:00
|
|
|
rdma_ah_set_sl(ah_attr, wc->sl);
|
|
|
|
rdma_ah_set_port_num(ah_attr, port_num);
|
|
|
|
|
2015-12-23 20:56:51 +08:00
|
|
|
if (rdma_protocol_roce(device, port_num)) {
|
2015-10-15 23:38:51 +08:00
|
|
|
u16 vlan_id = wc->wc_flags & IB_WC_WITH_VLAN ?
|
|
|
|
wc->vlan_id : 0xffff;
|
|
|
|
|
IB/core: Ethernet L2 attributes in verbs/cm structures
This patch add the support for Ethernet L2 attributes in the
verbs/cm/cma structures.
When dealing with L2 Ethernet, we should use smac, dmac, vlan ID and priority
in a similar manner that the IB L2 (and the L4 PKEY) attributes are used.
Thus, those attributes were added to the following structures:
* ib_ah_attr - added dmac
* ib_qp_attr - added smac and vlan_id, (sl remains vlan priority)
* ib_wc - added smac, vlan_id
* ib_sa_path_rec - added smac, dmac, vlan_id
* cm_av - added smac and vlan_id
For the path record structure, extra care was taken to avoid the new
fields when packing it into wire format, so we don't break the IB CM
and SA wire protocol.
On the active side, the CM fills. its internal structures from the
path provided by the ULP. We add there taking the ETH L2 attributes
and placing them into the CM Address Handle (struct cm_av).
On the passive side, the CM fills its internal structures from the WC
associated with the REQ message. We add there taking the ETH L2
attributes from the WC.
When the HW driver provides the required ETH L2 attributes in the WC,
they set the IB_WC_WITH_SMAC and IB_WC_WITH_VLAN flags. The IB core
code checks for the presence of these flags, and in their absence does
address resolution from the ib_init_ah_from_wc() helper function.
ib_modify_qp_is_ok is also updated to consider the link layer. Some
parameters are mandatory for Ethernet link layer, while they are
irrelevant for IB. Vendor drivers are modified to support the new
function signature.
Signed-off-by: Matan Barak <matanb@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2013-12-13 00:03:11 +08:00
|
|
|
if (!(wc->wc_flags & IB_WC_GRH))
|
|
|
|
return -EPROTOTYPE;
|
|
|
|
|
2018-06-19 15:59:14 +08:00
|
|
|
sgid_attr = get_sgid_attr_from_eth(device, port_num,
|
|
|
|
vlan_id, &dgid,
|
|
|
|
gid_type);
|
|
|
|
if (IS_ERR(sgid_attr))
|
|
|
|
return PTR_ERR(sgid_attr);
|
IB/core: Ethernet L2 attributes in verbs/cm structures
This patch add the support for Ethernet L2 attributes in the
verbs/cm/cma structures.
When dealing with L2 Ethernet, we should use smac, dmac, vlan ID and priority
in a similar manner that the IB L2 (and the L4 PKEY) attributes are used.
Thus, those attributes were added to the following structures:
* ib_ah_attr - added dmac
* ib_qp_attr - added smac and vlan_id, (sl remains vlan priority)
* ib_wc - added smac, vlan_id
* ib_sa_path_rec - added smac, dmac, vlan_id
* cm_av - added smac and vlan_id
For the path record structure, extra care was taken to avoid the new
fields when packing it into wire format, so we don't break the IB CM
and SA wire protocol.
On the active side, the CM fills. its internal structures from the
path provided by the ULP. We add there taking the ETH L2 attributes
and placing them into the CM Address Handle (struct cm_av).
On the passive side, the CM fills its internal structures from the WC
associated with the REQ message. We add there taking the ETH L2
attributes from the WC.
When the HW driver provides the required ETH L2 attributes in the WC,
they set the IB_WC_WITH_SMAC and IB_WC_WITH_VLAN flags. The IB core
code checks for the presence of these flags, and in their absence does
address resolution from the ib_init_ah_from_wc() helper function.
ib_modify_qp_is_ok is also updated to consider the link layer. Some
parameters are mandatory for Ethernet link layer, while they are
irrelevant for IB. Vendor drivers are modified to support the new
function signature.
Signed-off-by: Matan Barak <matanb@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2013-12-13 00:03:11 +08:00
|
|
|
|
2017-11-14 20:51:49 +08:00
|
|
|
flow_class = be32_to_cpu(grh->version_tclass_flow);
|
2018-06-19 15:59:14 +08:00
|
|
|
rdma_move_grh_sgid_attr(ah_attr,
|
|
|
|
&sgid,
|
|
|
|
flow_class & 0xFFFFF,
|
|
|
|
hoplimit,
|
|
|
|
(flow_class >> 20) & 0xFF,
|
|
|
|
sgid_attr);
|
|
|
|
|
|
|
|
ret = ib_resolve_unicast_gid_dmac(device, ah_attr);
|
|
|
|
if (ret)
|
|
|
|
rdma_destroy_ah_attr(ah_attr);
|
|
|
|
|
|
|
|
return ret;
|
2017-11-14 20:51:49 +08:00
|
|
|
} else {
|
|
|
|
rdma_ah_set_dlid(ah_attr, wc->slid);
|
|
|
|
rdma_ah_set_path_bits(ah_attr, wc->dlid_path_bits);
|
2005-07-28 02:45:34 +08:00
|
|
|
|
2018-06-19 15:59:14 +08:00
|
|
|
if ((wc->wc_flags & IB_WC_GRH) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (dgid.global.interface_id !=
|
|
|
|
cpu_to_be64(IB_SA_WELL_KNOWN_GUID)) {
|
|
|
|
sgid_attr = rdma_find_gid_by_port(
|
|
|
|
device, &dgid, IB_GID_TYPE_IB, port_num, NULL);
|
|
|
|
} else
|
|
|
|
sgid_attr = rdma_get_gid_attr(device, port_num, 0);
|
|
|
|
|
|
|
|
if (IS_ERR(sgid_attr))
|
|
|
|
return PTR_ERR(sgid_attr);
|
|
|
|
flow_class = be32_to_cpu(grh->version_tclass_flow);
|
|
|
|
rdma_move_grh_sgid_attr(ah_attr,
|
|
|
|
&sgid,
|
2017-11-14 20:51:49 +08:00
|
|
|
flow_class & 0xFFFFF,
|
2018-06-19 15:59:14 +08:00
|
|
|
hoplimit,
|
|
|
|
(flow_class >> 20) & 0xFF,
|
|
|
|
sgid_attr);
|
|
|
|
|
2017-11-14 20:51:49 +08:00
|
|
|
return 0;
|
2005-07-28 02:45:34 +08:00
|
|
|
}
|
2006-06-18 11:37:39 +08:00
|
|
|
}
|
2017-11-14 20:52:17 +08:00
|
|
|
EXPORT_SYMBOL(ib_init_ah_attr_from_wc);
|
2006-06-18 11:37:39 +08:00
|
|
|
|
2018-06-13 15:22:03 +08:00
|
|
|
/**
|
|
|
|
* rdma_move_grh_sgid_attr - Sets the sgid attribute of GRH, taking ownership
|
|
|
|
* of the reference
|
|
|
|
*
|
|
|
|
* @attr: Pointer to AH attribute structure
|
|
|
|
* @dgid: Destination GID
|
|
|
|
* @flow_label: Flow label
|
|
|
|
* @hop_limit: Hop limit
|
|
|
|
* @traffic_class: traffic class
|
|
|
|
* @sgid_attr: Pointer to SGID attribute
|
|
|
|
*
|
|
|
|
* This takes ownership of the sgid_attr reference. The caller must ensure
|
|
|
|
* rdma_destroy_ah_attr() is called before destroying the rdma_ah_attr after
|
|
|
|
* calling this function.
|
|
|
|
*/
|
|
|
|
void rdma_move_grh_sgid_attr(struct rdma_ah_attr *attr, union ib_gid *dgid,
|
|
|
|
u32 flow_label, u8 hop_limit, u8 traffic_class,
|
|
|
|
const struct ib_gid_attr *sgid_attr)
|
|
|
|
{
|
|
|
|
rdma_ah_set_grh(attr, dgid, flow_label, sgid_attr->index, hop_limit,
|
|
|
|
traffic_class);
|
|
|
|
attr->grh.sgid_attr = sgid_attr;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(rdma_move_grh_sgid_attr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* rdma_destroy_ah_attr - Release reference to SGID attribute of
|
|
|
|
* ah attribute.
|
|
|
|
* @ah_attr: Pointer to ah attribute
|
|
|
|
*
|
|
|
|
* Release reference to the SGID attribute of the ah attribute if it is
|
|
|
|
* non NULL. It is safe to call this multiple times, and safe to call it on
|
|
|
|
* a zero initialized ah_attr.
|
|
|
|
*/
|
|
|
|
void rdma_destroy_ah_attr(struct rdma_ah_attr *ah_attr)
|
|
|
|
{
|
|
|
|
if (ah_attr->grh.sgid_attr) {
|
|
|
|
rdma_put_gid_attr(ah_attr->grh.sgid_attr);
|
|
|
|
ah_attr->grh.sgid_attr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(rdma_destroy_ah_attr);
|
|
|
|
|
2015-06-01 05:15:31 +08:00
|
|
|
struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
|
|
|
|
const struct ib_grh *grh, u8 port_num)
|
2006-06-18 11:37:39 +08:00
|
|
|
{
|
2017-04-30 02:41:18 +08:00
|
|
|
struct rdma_ah_attr ah_attr;
|
2018-06-19 15:59:14 +08:00
|
|
|
struct ib_ah *ah;
|
2006-06-18 11:37:39 +08:00
|
|
|
int ret;
|
|
|
|
|
2017-11-14 20:52:17 +08:00
|
|
|
ret = ib_init_ah_attr_from_wc(pd->device, port_num, wc, grh, &ah_attr);
|
2006-06-18 11:37:39 +08:00
|
|
|
if (ret)
|
|
|
|
return ERR_PTR(ret);
|
2005-07-28 02:45:34 +08:00
|
|
|
|
2018-12-12 17:09:05 +08:00
|
|
|
ah = rdma_create_ah(pd, &ah_attr, RDMA_CREATE_AH_SLEEPABLE);
|
2018-06-19 15:59:14 +08:00
|
|
|
|
|
|
|
rdma_destroy_ah_attr(&ah_attr);
|
|
|
|
return ah;
|
2005-07-28 02:45:34 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_create_ah_from_wc);
|
|
|
|
|
2017-04-30 02:41:20 +08:00
|
|
|
int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-06-13 15:22:03 +08:00
|
|
|
const struct ib_gid_attr *old_sgid_attr;
|
|
|
|
int ret;
|
|
|
|
|
2017-04-30 02:41:29 +08:00
|
|
|
if (ah->type != ah_attr->type)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-06-13 15:22:03 +08:00
|
|
|
ret = rdma_fill_sgid_attr(ah->device, ah_attr, &old_sgid_attr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
ret = ah->device->ops.modify_ah ?
|
|
|
|
ah->device->ops.modify_ah(ah, ah_attr) :
|
2018-02-22 00:12:44 +08:00
|
|
|
-EOPNOTSUPP;
|
2018-06-13 15:22:03 +08:00
|
|
|
|
2018-06-13 15:22:08 +08:00
|
|
|
ah->sgid_attr = rdma_update_sgid_attr(ah_attr, ah->sgid_attr);
|
2018-06-13 15:22:03 +08:00
|
|
|
rdma_unfill_sgid_attr(ah_attr, old_sgid_attr);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2017-04-30 02:41:20 +08:00
|
|
|
EXPORT_SYMBOL(rdma_modify_ah);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-30 02:41:21 +08:00
|
|
|
int rdma_query_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-06-13 15:22:03 +08:00
|
|
|
ah_attr->grh.sgid_attr = NULL;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
return ah->device->ops.query_ah ?
|
|
|
|
ah->device->ops.query_ah(ah, ah_attr) :
|
2018-02-22 00:12:44 +08:00
|
|
|
-EOPNOTSUPP;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2017-04-30 02:41:21 +08:00
|
|
|
EXPORT_SYMBOL(rdma_query_ah);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-04-01 00:10:05 +08:00
|
|
|
int rdma_destroy_ah_user(struct ib_ah *ah, u32 flags, struct ib_udata *udata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-06-13 15:22:08 +08:00
|
|
|
const struct ib_gid_attr *sgid_attr = ah->sgid_attr;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ib_pd *pd;
|
|
|
|
|
2018-12-12 17:09:06 +08:00
|
|
|
might_sleep_if(flags & RDMA_DESTROY_AH_SLEEPABLE);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
pd = ah->pd;
|
|
|
|
|
2019-04-03 21:42:42 +08:00
|
|
|
ah->device->ops.destroy_ah(ah, flags);
|
|
|
|
atomic_dec(&pd->usecnt);
|
|
|
|
if (sgid_attr)
|
|
|
|
rdma_put_gid_attr(sgid_attr);
|
|
|
|
|
|
|
|
kfree(ah);
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2019-04-01 00:10:05 +08:00
|
|
|
EXPORT_SYMBOL(rdma_destroy_ah_user);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-08-19 03:23:08 +08:00
|
|
|
/* Shared receive queues */
|
|
|
|
|
|
|
|
struct ib_srq *ib_create_srq(struct ib_pd *pd,
|
|
|
|
struct ib_srq_init_attr *srq_init_attr)
|
|
|
|
{
|
|
|
|
struct ib_srq *srq;
|
2019-04-03 21:42:43 +08:00
|
|
|
int ret;
|
2005-08-19 03:23:08 +08:00
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!pd->device->ops.create_srq)
|
2018-02-22 00:12:44 +08:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
2005-08-19 03:23:08 +08:00
|
|
|
|
2019-04-03 21:42:43 +08:00
|
|
|
srq = rdma_zalloc_drv_obj(pd->device, ib_srq);
|
|
|
|
if (!srq)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
srq->device = pd->device;
|
|
|
|
srq->pd = pd;
|
|
|
|
srq->event_handler = srq_init_attr->event_handler;
|
|
|
|
srq->srq_context = srq_init_attr->srq_context;
|
|
|
|
srq->srq_type = srq_init_attr->srq_type;
|
|
|
|
|
|
|
|
if (ib_srq_has_cq(srq->srq_type)) {
|
|
|
|
srq->ext.cq = srq_init_attr->ext.cq;
|
|
|
|
atomic_inc(&srq->ext.cq->usecnt);
|
|
|
|
}
|
|
|
|
if (srq->srq_type == IB_SRQT_XRC) {
|
|
|
|
srq->ext.xrc.xrcd = srq_init_attr->ext.xrc.xrcd;
|
|
|
|
atomic_inc(&srq->ext.xrc.xrcd->usecnt);
|
|
|
|
}
|
|
|
|
atomic_inc(&pd->usecnt);
|
|
|
|
|
|
|
|
ret = pd->device->ops.create_srq(srq, srq_init_attr, NULL);
|
|
|
|
if (ret) {
|
|
|
|
atomic_dec(&srq->pd->usecnt);
|
|
|
|
if (srq->srq_type == IB_SRQT_XRC)
|
|
|
|
atomic_dec(&srq->ext.xrc.xrcd->usecnt);
|
|
|
|
if (ib_srq_has_cq(srq->srq_type))
|
|
|
|
atomic_dec(&srq->ext.cq->usecnt);
|
|
|
|
kfree(srq);
|
|
|
|
return ERR_PTR(ret);
|
2005-08-19 03:23:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return srq;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_create_srq);
|
|
|
|
|
|
|
|
int ib_modify_srq(struct ib_srq *srq,
|
|
|
|
struct ib_srq_attr *srq_attr,
|
|
|
|
enum ib_srq_attr_mask srq_attr_mask)
|
|
|
|
{
|
2018-12-11 03:09:48 +08:00
|
|
|
return srq->device->ops.modify_srq ?
|
|
|
|
srq->device->ops.modify_srq(srq, srq_attr, srq_attr_mask,
|
|
|
|
NULL) : -EOPNOTSUPP;
|
2005-08-19 03:23:08 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_modify_srq);
|
|
|
|
|
|
|
|
int ib_query_srq(struct ib_srq *srq,
|
|
|
|
struct ib_srq_attr *srq_attr)
|
|
|
|
{
|
2018-12-11 03:09:48 +08:00
|
|
|
return srq->device->ops.query_srq ?
|
|
|
|
srq->device->ops.query_srq(srq, srq_attr) : -EOPNOTSUPP;
|
2005-08-19 03:23:08 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_query_srq);
|
|
|
|
|
2019-04-01 00:10:05 +08:00
|
|
|
int ib_destroy_srq_user(struct ib_srq *srq, struct ib_udata *udata)
|
2005-08-19 03:23:08 +08:00
|
|
|
{
|
|
|
|
if (atomic_read(&srq->usecnt))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2019-04-03 21:42:43 +08:00
|
|
|
srq->device->ops.destroy_srq(srq, udata);
|
2005-08-19 03:23:08 +08:00
|
|
|
|
2019-04-03 21:42:43 +08:00
|
|
|
atomic_dec(&srq->pd->usecnt);
|
|
|
|
if (srq->srq_type == IB_SRQT_XRC)
|
|
|
|
atomic_dec(&srq->ext.xrc.xrcd->usecnt);
|
|
|
|
if (ib_srq_has_cq(srq->srq_type))
|
|
|
|
atomic_dec(&srq->ext.cq->usecnt);
|
|
|
|
kfree(srq);
|
|
|
|
|
|
|
|
return 0;
|
2005-08-19 03:23:08 +08:00
|
|
|
}
|
2019-04-01 00:10:05 +08:00
|
|
|
EXPORT_SYMBOL(ib_destroy_srq_user);
|
2005-08-19 03:23:08 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Queue pairs */
|
|
|
|
|
2011-08-09 06:31:51 +08:00
|
|
|
static void __ib_shared_qp_event_handler(struct ib_event *event, void *context)
|
|
|
|
{
|
|
|
|
struct ib_qp *qp = context;
|
2013-08-01 23:49:53 +08:00
|
|
|
unsigned long flags;
|
2011-08-09 06:31:51 +08:00
|
|
|
|
2013-08-01 23:49:53 +08:00
|
|
|
spin_lock_irqsave(&qp->device->event_handler_lock, flags);
|
2011-08-09 06:31:51 +08:00
|
|
|
list_for_each_entry(event->element.qp, &qp->open_list, open_list)
|
2013-04-10 22:26:46 +08:00
|
|
|
if (event->element.qp->event_handler)
|
|
|
|
event->element.qp->event_handler(event, event->element.qp->qp_context);
|
2013-08-01 23:49:53 +08:00
|
|
|
spin_unlock_irqrestore(&qp->device->event_handler_lock, flags);
|
2011-08-09 06:31:51 +08:00
|
|
|
}
|
|
|
|
|
2011-05-27 14:06:44 +08:00
|
|
|
static void __ib_insert_xrcd_qp(struct ib_xrcd *xrcd, struct ib_qp *qp)
|
|
|
|
{
|
|
|
|
mutex_lock(&xrcd->tgt_qp_mutex);
|
|
|
|
list_add(&qp->xrcd_list, &xrcd->tgt_qp_list);
|
|
|
|
mutex_unlock(&xrcd->tgt_qp_mutex);
|
|
|
|
}
|
|
|
|
|
2011-08-09 06:31:51 +08:00
|
|
|
static struct ib_qp *__ib_open_qp(struct ib_qp *real_qp,
|
|
|
|
void (*event_handler)(struct ib_event *, void *),
|
|
|
|
void *qp_context)
|
2011-05-27 14:06:44 +08:00
|
|
|
{
|
2011-08-09 06:31:51 +08:00
|
|
|
struct ib_qp *qp;
|
|
|
|
unsigned long flags;
|
IB/core: Enforce PKey security on QPs
Add new LSM hooks to allocate and free security contexts and check for
permission to access a PKey.
Allocate and free a security context when creating and destroying a QP.
This context is used for controlling access to PKeys.
When a request is made to modify a QP that changes the port, PKey index,
or alternate path, check that the QP has permission for the PKey in the
PKey table index on the subnet prefix of the port. If the QP is shared
make sure all handles to the QP also have access.
Store which port and PKey index a QP is using. After the reset to init
transition the user can modify the port, PKey index and alternate path
independently. So port and PKey settings changes can be a merge of the
previous settings and the new ones.
In order to maintain access control if there are PKey table or subnet
prefix change keep a list of all QPs are using each PKey index on
each port. If a change occurs all QPs using that device and port must
have access enforced for the new cache settings.
These changes add a transaction to the QP modify process. Association
with the old port and PKey index must be maintained if the modify fails,
and must be removed if it succeeds. Association with the new port and
PKey index must be established prior to the modify and removed if the
modify fails.
1. When a QP is modified to a particular Port, PKey index or alternate
path insert that QP into the appropriate lists.
2. Check permission to access the new settings.
3. If step 2 grants access attempt to modify the QP.
4a. If steps 2 and 3 succeed remove any prior associations.
4b. If ether fails remove the new setting associations.
If a PKey table or subnet prefix changes walk the list of QPs and
check that they have permission. If not send the QP to the error state
and raise a fatal error event. If it's a shared QP make sure all the
QPs that share the real_qp have permission as well. If the QP that
owns a security structure is denied access the security structure is
marked as such and the QP is added to an error_list. Once the moving
the QP to error is complete the security structure mark is cleared.
Maintaining the lists correctly turns QP destroy into a transaction.
The hardware driver for the device frees the ib_qp structure, so while
the destroy is in progress the ib_qp pointer in the ib_qp_security
struct is undefined. When the destroy process begins the ib_qp_security
structure is marked as destroying. This prevents any action from being
taken on the QP pointer. After the QP is destroyed successfully it
could still listed on an error_list wait for it to be processed by that
flow before cleaning up the structure.
If the destroy fails the QPs port and PKey settings are reinserted into
the appropriate lists, the destroying flag is cleared, and access control
is enforced, in case there were any cache changes during the destroy
flow.
To keep the security changes isolated a new file is used to hold security
related functionality.
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Acked-by: Doug Ledford <dledford@redhat.com>
[PM: merge fixup in ib_verbs.h and uverbs_cmd.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2017-05-19 20:48:52 +08:00
|
|
|
int err;
|
2011-08-09 06:31:51 +08:00
|
|
|
|
|
|
|
qp = kzalloc(sizeof *qp, GFP_KERNEL);
|
|
|
|
if (!qp)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
IB/core: Enforce PKey security on QPs
Add new LSM hooks to allocate and free security contexts and check for
permission to access a PKey.
Allocate and free a security context when creating and destroying a QP.
This context is used for controlling access to PKeys.
When a request is made to modify a QP that changes the port, PKey index,
or alternate path, check that the QP has permission for the PKey in the
PKey table index on the subnet prefix of the port. If the QP is shared
make sure all handles to the QP also have access.
Store which port and PKey index a QP is using. After the reset to init
transition the user can modify the port, PKey index and alternate path
independently. So port and PKey settings changes can be a merge of the
previous settings and the new ones.
In order to maintain access control if there are PKey table or subnet
prefix change keep a list of all QPs are using each PKey index on
each port. If a change occurs all QPs using that device and port must
have access enforced for the new cache settings.
These changes add a transaction to the QP modify process. Association
with the old port and PKey index must be maintained if the modify fails,
and must be removed if it succeeds. Association with the new port and
PKey index must be established prior to the modify and removed if the
modify fails.
1. When a QP is modified to a particular Port, PKey index or alternate
path insert that QP into the appropriate lists.
2. Check permission to access the new settings.
3. If step 2 grants access attempt to modify the QP.
4a. If steps 2 and 3 succeed remove any prior associations.
4b. If ether fails remove the new setting associations.
If a PKey table or subnet prefix changes walk the list of QPs and
check that they have permission. If not send the QP to the error state
and raise a fatal error event. If it's a shared QP make sure all the
QPs that share the real_qp have permission as well. If the QP that
owns a security structure is denied access the security structure is
marked as such and the QP is added to an error_list. Once the moving
the QP to error is complete the security structure mark is cleared.
Maintaining the lists correctly turns QP destroy into a transaction.
The hardware driver for the device frees the ib_qp structure, so while
the destroy is in progress the ib_qp pointer in the ib_qp_security
struct is undefined. When the destroy process begins the ib_qp_security
structure is marked as destroying. This prevents any action from being
taken on the QP pointer. After the QP is destroyed successfully it
could still listed on an error_list wait for it to be processed by that
flow before cleaning up the structure.
If the destroy fails the QPs port and PKey settings are reinserted into
the appropriate lists, the destroying flag is cleared, and access control
is enforced, in case there were any cache changes during the destroy
flow.
To keep the security changes isolated a new file is used to hold security
related functionality.
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Acked-by: Doug Ledford <dledford@redhat.com>
[PM: merge fixup in ib_verbs.h and uverbs_cmd.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2017-05-19 20:48:52 +08:00
|
|
|
qp->real_qp = real_qp;
|
|
|
|
err = ib_open_shared_qp_security(qp, real_qp->device);
|
|
|
|
if (err) {
|
|
|
|
kfree(qp);
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
2011-08-09 06:31:51 +08:00
|
|
|
qp->real_qp = real_qp;
|
|
|
|
atomic_inc(&real_qp->usecnt);
|
|
|
|
qp->device = real_qp->device;
|
|
|
|
qp->event_handler = event_handler;
|
|
|
|
qp->qp_context = qp_context;
|
|
|
|
qp->qp_num = real_qp->qp_num;
|
|
|
|
qp->qp_type = real_qp->qp_type;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&real_qp->device->event_handler_lock, flags);
|
|
|
|
list_add(&qp->open_list, &real_qp->open_list);
|
|
|
|
spin_unlock_irqrestore(&real_qp->device->event_handler_lock, flags);
|
|
|
|
|
|
|
|
return qp;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
|
|
|
|
struct ib_qp_open_attr *qp_open_attr)
|
|
|
|
{
|
|
|
|
struct ib_qp *qp, *real_qp;
|
|
|
|
|
|
|
|
if (qp_open_attr->qp_type != IB_QPT_XRC_TGT)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
qp = ERR_PTR(-EINVAL);
|
2011-05-27 14:06:44 +08:00
|
|
|
mutex_lock(&xrcd->tgt_qp_mutex);
|
2011-08-09 06:31:51 +08:00
|
|
|
list_for_each_entry(real_qp, &xrcd->tgt_qp_list, xrcd_list) {
|
|
|
|
if (real_qp->qp_num == qp_open_attr->qp_num) {
|
|
|
|
qp = __ib_open_qp(real_qp, qp_open_attr->event_handler,
|
|
|
|
qp_open_attr->qp_context);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-05-27 14:06:44 +08:00
|
|
|
mutex_unlock(&xrcd->tgt_qp_mutex);
|
2011-08-09 06:31:51 +08:00
|
|
|
return qp;
|
2011-05-27 14:06:44 +08:00
|
|
|
}
|
2011-08-09 06:31:51 +08:00
|
|
|
EXPORT_SYMBOL(ib_open_qp);
|
2011-05-27 14:06:44 +08:00
|
|
|
|
2019-04-01 00:10:05 +08:00
|
|
|
static struct ib_qp *create_xrc_qp_user(struct ib_qp *qp,
|
|
|
|
struct ib_qp_init_attr *qp_init_attr,
|
|
|
|
struct ib_udata *udata)
|
2016-05-04 00:01:06 +08:00
|
|
|
{
|
|
|
|
struct ib_qp *real_qp = qp;
|
|
|
|
|
|
|
|
qp->event_handler = __ib_shared_qp_event_handler;
|
|
|
|
qp->qp_context = qp;
|
|
|
|
qp->pd = NULL;
|
|
|
|
qp->send_cq = qp->recv_cq = NULL;
|
|
|
|
qp->srq = NULL;
|
|
|
|
qp->xrcd = qp_init_attr->xrcd;
|
|
|
|
atomic_inc(&qp_init_attr->xrcd->usecnt);
|
|
|
|
INIT_LIST_HEAD(&qp->open_list);
|
|
|
|
|
|
|
|
qp = __ib_open_qp(real_qp, qp_init_attr->event_handler,
|
|
|
|
qp_init_attr->qp_context);
|
2019-01-22 15:02:05 +08:00
|
|
|
if (IS_ERR(qp))
|
|
|
|
return qp;
|
|
|
|
|
|
|
|
__ib_insert_xrcd_qp(qp_init_attr->xrcd, real_qp);
|
2016-05-04 00:01:06 +08:00
|
|
|
return qp;
|
|
|
|
}
|
|
|
|
|
2019-04-01 00:10:05 +08:00
|
|
|
struct ib_qp *ib_create_qp_user(struct ib_pd *pd,
|
|
|
|
struct ib_qp_init_attr *qp_init_attr,
|
|
|
|
struct ib_udata *udata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2016-05-04 00:01:06 +08:00
|
|
|
struct ib_device *device = pd ? pd->device : qp_init_attr->xrcd->device;
|
|
|
|
struct ib_qp *qp;
|
2016-05-04 00:01:09 +08:00
|
|
|
int ret;
|
|
|
|
|
2016-05-23 20:20:54 +08:00
|
|
|
if (qp_init_attr->rwq_ind_tbl &&
|
|
|
|
(qp_init_attr->recv_cq ||
|
|
|
|
qp_init_attr->srq || qp_init_attr->cap.max_recv_wr ||
|
|
|
|
qp_init_attr->cap.max_recv_sge))
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2019-06-11 23:52:51 +08:00
|
|
|
if ((qp_init_attr->create_flags & IB_QP_CREATE_INTEGRITY_EN) &&
|
|
|
|
!(device->attrs.device_cap_flags & IB_DEVICE_INTEGRITY_HANDOVER))
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2016-05-04 00:01:09 +08:00
|
|
|
/*
|
|
|
|
* If the callers is using the RDMA API calculate the resources
|
|
|
|
* needed for the RDMA READ/WRITE operations.
|
|
|
|
*
|
|
|
|
* Note that these callers need to pass in a port number.
|
|
|
|
*/
|
|
|
|
if (qp_init_attr->cap.max_rdma_ctxs)
|
|
|
|
rdma_rw_init_qp(device, qp_init_attr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-02-15 10:43:36 +08:00
|
|
|
qp = _ib_create_qp(device, pd, qp_init_attr, NULL, NULL);
|
2016-05-04 00:01:06 +08:00
|
|
|
if (IS_ERR(qp))
|
|
|
|
return qp;
|
|
|
|
|
IB/core: Enforce PKey security on QPs
Add new LSM hooks to allocate and free security contexts and check for
permission to access a PKey.
Allocate and free a security context when creating and destroying a QP.
This context is used for controlling access to PKeys.
When a request is made to modify a QP that changes the port, PKey index,
or alternate path, check that the QP has permission for the PKey in the
PKey table index on the subnet prefix of the port. If the QP is shared
make sure all handles to the QP also have access.
Store which port and PKey index a QP is using. After the reset to init
transition the user can modify the port, PKey index and alternate path
independently. So port and PKey settings changes can be a merge of the
previous settings and the new ones.
In order to maintain access control if there are PKey table or subnet
prefix change keep a list of all QPs are using each PKey index on
each port. If a change occurs all QPs using that device and port must
have access enforced for the new cache settings.
These changes add a transaction to the QP modify process. Association
with the old port and PKey index must be maintained if the modify fails,
and must be removed if it succeeds. Association with the new port and
PKey index must be established prior to the modify and removed if the
modify fails.
1. When a QP is modified to a particular Port, PKey index or alternate
path insert that QP into the appropriate lists.
2. Check permission to access the new settings.
3. If step 2 grants access attempt to modify the QP.
4a. If steps 2 and 3 succeed remove any prior associations.
4b. If ether fails remove the new setting associations.
If a PKey table or subnet prefix changes walk the list of QPs and
check that they have permission. If not send the QP to the error state
and raise a fatal error event. If it's a shared QP make sure all the
QPs that share the real_qp have permission as well. If the QP that
owns a security structure is denied access the security structure is
marked as such and the QP is added to an error_list. Once the moving
the QP to error is complete the security structure mark is cleared.
Maintaining the lists correctly turns QP destroy into a transaction.
The hardware driver for the device frees the ib_qp structure, so while
the destroy is in progress the ib_qp pointer in the ib_qp_security
struct is undefined. When the destroy process begins the ib_qp_security
structure is marked as destroying. This prevents any action from being
taken on the QP pointer. After the QP is destroyed successfully it
could still listed on an error_list wait for it to be processed by that
flow before cleaning up the structure.
If the destroy fails the QPs port and PKey settings are reinserted into
the appropriate lists, the destroying flag is cleared, and access control
is enforced, in case there were any cache changes during the destroy
flow.
To keep the security changes isolated a new file is used to hold security
related functionality.
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Acked-by: Doug Ledford <dledford@redhat.com>
[PM: merge fixup in ib_verbs.h and uverbs_cmd.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2017-05-19 20:48:52 +08:00
|
|
|
ret = ib_create_qp_security(qp, device);
|
2019-01-22 15:02:05 +08:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
IB/core: Enforce PKey security on QPs
Add new LSM hooks to allocate and free security contexts and check for
permission to access a PKey.
Allocate and free a security context when creating and destroying a QP.
This context is used for controlling access to PKeys.
When a request is made to modify a QP that changes the port, PKey index,
or alternate path, check that the QP has permission for the PKey in the
PKey table index on the subnet prefix of the port. If the QP is shared
make sure all handles to the QP also have access.
Store which port and PKey index a QP is using. After the reset to init
transition the user can modify the port, PKey index and alternate path
independently. So port and PKey settings changes can be a merge of the
previous settings and the new ones.
In order to maintain access control if there are PKey table or subnet
prefix change keep a list of all QPs are using each PKey index on
each port. If a change occurs all QPs using that device and port must
have access enforced for the new cache settings.
These changes add a transaction to the QP modify process. Association
with the old port and PKey index must be maintained if the modify fails,
and must be removed if it succeeds. Association with the new port and
PKey index must be established prior to the modify and removed if the
modify fails.
1. When a QP is modified to a particular Port, PKey index or alternate
path insert that QP into the appropriate lists.
2. Check permission to access the new settings.
3. If step 2 grants access attempt to modify the QP.
4a. If steps 2 and 3 succeed remove any prior associations.
4b. If ether fails remove the new setting associations.
If a PKey table or subnet prefix changes walk the list of QPs and
check that they have permission. If not send the QP to the error state
and raise a fatal error event. If it's a shared QP make sure all the
QPs that share the real_qp have permission as well. If the QP that
owns a security structure is denied access the security structure is
marked as such and the QP is added to an error_list. Once the moving
the QP to error is complete the security structure mark is cleared.
Maintaining the lists correctly turns QP destroy into a transaction.
The hardware driver for the device frees the ib_qp structure, so while
the destroy is in progress the ib_qp pointer in the ib_qp_security
struct is undefined. When the destroy process begins the ib_qp_security
structure is marked as destroying. This prevents any action from being
taken on the QP pointer. After the QP is destroyed successfully it
could still listed on an error_list wait for it to be processed by that
flow before cleaning up the structure.
If the destroy fails the QPs port and PKey settings are reinserted into
the appropriate lists, the destroying flag is cleared, and access control
is enforced, in case there were any cache changes during the destroy
flow.
To keep the security changes isolated a new file is used to hold security
related functionality.
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Acked-by: Doug Ledford <dledford@redhat.com>
[PM: merge fixup in ib_verbs.h and uverbs_cmd.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2017-05-19 20:48:52 +08:00
|
|
|
|
2016-05-04 00:01:06 +08:00
|
|
|
qp->qp_type = qp_init_attr->qp_type;
|
2016-05-23 20:20:54 +08:00
|
|
|
qp->rwq_ind_tbl = qp_init_attr->rwq_ind_tbl;
|
2016-05-04 00:01:06 +08:00
|
|
|
|
|
|
|
atomic_set(&qp->usecnt, 0);
|
2016-05-04 00:01:07 +08:00
|
|
|
qp->mrs_used = 0;
|
|
|
|
spin_lock_init(&qp->mr_lock);
|
2016-05-04 00:01:09 +08:00
|
|
|
INIT_LIST_HEAD(&qp->rdma_mrs);
|
2016-05-04 00:01:12 +08:00
|
|
|
INIT_LIST_HEAD(&qp->sig_mrs);
|
2017-08-23 13:35:40 +08:00
|
|
|
qp->port = 0;
|
2016-05-04 00:01:07 +08:00
|
|
|
|
2019-01-22 15:02:05 +08:00
|
|
|
if (qp_init_attr->qp_type == IB_QPT_XRC_TGT) {
|
2019-04-01 00:10:05 +08:00
|
|
|
struct ib_qp *xrc_qp =
|
|
|
|
create_xrc_qp_user(qp, qp_init_attr, udata);
|
2019-01-22 15:02:05 +08:00
|
|
|
|
|
|
|
if (IS_ERR(xrc_qp)) {
|
|
|
|
ret = PTR_ERR(xrc_qp);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
return xrc_qp;
|
|
|
|
}
|
2016-05-04 00:01:06 +08:00
|
|
|
|
|
|
|
qp->event_handler = qp_init_attr->event_handler;
|
|
|
|
qp->qp_context = qp_init_attr->qp_context;
|
|
|
|
if (qp_init_attr->qp_type == IB_QPT_XRC_INI) {
|
|
|
|
qp->recv_cq = NULL;
|
|
|
|
qp->srq = NULL;
|
|
|
|
} else {
|
|
|
|
qp->recv_cq = qp_init_attr->recv_cq;
|
2016-05-23 20:20:54 +08:00
|
|
|
if (qp_init_attr->recv_cq)
|
|
|
|
atomic_inc(&qp_init_attr->recv_cq->usecnt);
|
2016-05-04 00:01:06 +08:00
|
|
|
qp->srq = qp_init_attr->srq;
|
|
|
|
if (qp->srq)
|
|
|
|
atomic_inc(&qp_init_attr->srq->usecnt);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 00:01:06 +08:00
|
|
|
qp->send_cq = qp_init_attr->send_cq;
|
|
|
|
qp->xrcd = NULL;
|
|
|
|
|
|
|
|
atomic_inc(&pd->usecnt);
|
2016-05-23 20:20:54 +08:00
|
|
|
if (qp_init_attr->send_cq)
|
|
|
|
atomic_inc(&qp_init_attr->send_cq->usecnt);
|
|
|
|
if (qp_init_attr->rwq_ind_tbl)
|
|
|
|
atomic_inc(&qp->rwq_ind_tbl->usecnt);
|
2016-05-04 00:01:09 +08:00
|
|
|
|
|
|
|
if (qp_init_attr->cap.max_rdma_ctxs) {
|
|
|
|
ret = rdma_rw_init_mrs(qp, qp_init_attr);
|
2019-01-22 15:02:05 +08:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
2016-05-04 00:01:09 +08:00
|
|
|
}
|
|
|
|
|
2016-07-22 04:03:30 +08:00
|
|
|
/*
|
|
|
|
* Note: all hw drivers guarantee that max_send_sge is lower than
|
|
|
|
* the device RDMA WRITE SGE limit but not all hw drivers ensure that
|
|
|
|
* max_send_sge <= max_sge_rd.
|
|
|
|
*/
|
|
|
|
qp->max_write_sge = qp_init_attr->cap.max_send_sge;
|
|
|
|
qp->max_read_sge = min_t(u32, qp_init_attr->cap.max_send_sge,
|
|
|
|
device->attrs.max_sge_rd);
|
2019-06-11 23:52:51 +08:00
|
|
|
if (qp_init_attr->create_flags & IB_QP_CREATE_INTEGRITY_EN)
|
|
|
|
qp->integrity_en = true;
|
2016-07-22 04:03:30 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return qp;
|
2019-01-22 15:02:05 +08:00
|
|
|
|
|
|
|
err:
|
|
|
|
ib_destroy_qp(qp);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2019-04-01 00:10:05 +08:00
|
|
|
EXPORT_SYMBOL(ib_create_qp_user);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-02-14 04:48:12 +08:00
|
|
|
static const struct {
|
|
|
|
int valid;
|
2011-05-24 10:59:25 +08:00
|
|
|
enum ib_qp_attr_mask req_param[IB_QPT_MAX];
|
|
|
|
enum ib_qp_attr_mask opt_param[IB_QPT_MAX];
|
2006-02-14 04:48:12 +08:00
|
|
|
} qp_state_table[IB_QPS_ERR + 1][IB_QPS_ERR + 1] = {
|
|
|
|
[IB_QPS_RESET] = {
|
|
|
|
[IB_QPS_RESET] = { .valid = 1 },
|
|
|
|
[IB_QPS_INIT] = {
|
|
|
|
.valid = 1,
|
|
|
|
.req_param = {
|
|
|
|
[IB_QPT_UD] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_PORT |
|
|
|
|
IB_QP_QKEY),
|
2012-03-01 18:17:51 +08:00
|
|
|
[IB_QPT_RAW_PACKET] = IB_QP_PORT,
|
2006-02-14 04:48:12 +08:00
|
|
|
[IB_QPT_UC] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_PORT |
|
|
|
|
IB_QP_ACCESS_FLAGS),
|
|
|
|
[IB_QPT_RC] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_PORT |
|
|
|
|
IB_QP_ACCESS_FLAGS),
|
2011-05-24 10:59:25 +08:00
|
|
|
[IB_QPT_XRC_INI] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_PORT |
|
|
|
|
IB_QP_ACCESS_FLAGS),
|
|
|
|
[IB_QPT_XRC_TGT] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_PORT |
|
|
|
|
IB_QP_ACCESS_FLAGS),
|
2006-02-14 04:48:12 +08:00
|
|
|
[IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[IB_QPS_INIT] = {
|
|
|
|
[IB_QPS_RESET] = { .valid = 1 },
|
|
|
|
[IB_QPS_ERR] = { .valid = 1 },
|
|
|
|
[IB_QPS_INIT] = {
|
|
|
|
.valid = 1,
|
|
|
|
.opt_param = {
|
|
|
|
[IB_QPT_UD] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_PORT |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_UC] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_PORT |
|
|
|
|
IB_QP_ACCESS_FLAGS),
|
|
|
|
[IB_QPT_RC] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_PORT |
|
|
|
|
IB_QP_ACCESS_FLAGS),
|
2011-05-24 10:59:25 +08:00
|
|
|
[IB_QPT_XRC_INI] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_PORT |
|
|
|
|
IB_QP_ACCESS_FLAGS),
|
|
|
|
[IB_QPT_XRC_TGT] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_PORT |
|
|
|
|
IB_QP_ACCESS_FLAGS),
|
2006-02-14 04:48:12 +08:00
|
|
|
[IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[IB_QPS_RTR] = {
|
|
|
|
.valid = 1,
|
|
|
|
.req_param = {
|
|
|
|
[IB_QPT_UC] = (IB_QP_AV |
|
|
|
|
IB_QP_PATH_MTU |
|
|
|
|
IB_QP_DEST_QPN |
|
|
|
|
IB_QP_RQ_PSN),
|
|
|
|
[IB_QPT_RC] = (IB_QP_AV |
|
|
|
|
IB_QP_PATH_MTU |
|
|
|
|
IB_QP_DEST_QPN |
|
|
|
|
IB_QP_RQ_PSN |
|
|
|
|
IB_QP_MAX_DEST_RD_ATOMIC |
|
|
|
|
IB_QP_MIN_RNR_TIMER),
|
2011-05-24 10:59:25 +08:00
|
|
|
[IB_QPT_XRC_INI] = (IB_QP_AV |
|
|
|
|
IB_QP_PATH_MTU |
|
|
|
|
IB_QP_DEST_QPN |
|
|
|
|
IB_QP_RQ_PSN),
|
|
|
|
[IB_QPT_XRC_TGT] = (IB_QP_AV |
|
|
|
|
IB_QP_PATH_MTU |
|
|
|
|
IB_QP_DEST_QPN |
|
|
|
|
IB_QP_RQ_PSN |
|
|
|
|
IB_QP_MAX_DEST_RD_ATOMIC |
|
|
|
|
IB_QP_MIN_RNR_TIMER),
|
2006-02-14 04:48:12 +08:00
|
|
|
},
|
|
|
|
.opt_param = {
|
|
|
|
[IB_QPT_UD] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_UC] = (IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_PKEY_INDEX),
|
|
|
|
[IB_QPT_RC] = (IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_PKEY_INDEX),
|
2011-05-24 10:59:25 +08:00
|
|
|
[IB_QPT_XRC_INI] = (IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_PKEY_INDEX),
|
|
|
|
[IB_QPT_XRC_TGT] = (IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_PKEY_INDEX),
|
2006-02-14 04:48:12 +08:00
|
|
|
[IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_QKEY),
|
IB/core: Ethernet L2 attributes in verbs/cm structures
This patch add the support for Ethernet L2 attributes in the
verbs/cm/cma structures.
When dealing with L2 Ethernet, we should use smac, dmac, vlan ID and priority
in a similar manner that the IB L2 (and the L4 PKEY) attributes are used.
Thus, those attributes were added to the following structures:
* ib_ah_attr - added dmac
* ib_qp_attr - added smac and vlan_id, (sl remains vlan priority)
* ib_wc - added smac, vlan_id
* ib_sa_path_rec - added smac, dmac, vlan_id
* cm_av - added smac and vlan_id
For the path record structure, extra care was taken to avoid the new
fields when packing it into wire format, so we don't break the IB CM
and SA wire protocol.
On the active side, the CM fills. its internal structures from the
path provided by the ULP. We add there taking the ETH L2 attributes
and placing them into the CM Address Handle (struct cm_av).
On the passive side, the CM fills its internal structures from the WC
associated with the REQ message. We add there taking the ETH L2
attributes from the WC.
When the HW driver provides the required ETH L2 attributes in the WC,
they set the IB_WC_WITH_SMAC and IB_WC_WITH_VLAN flags. The IB core
code checks for the presence of these flags, and in their absence does
address resolution from the ib_init_ah_from_wc() helper function.
ib_modify_qp_is_ok is also updated to consider the link layer. Some
parameters are mandatory for Ethernet link layer, while they are
irrelevant for IB. Vendor drivers are modified to support the new
function signature.
Signed-off-by: Matan Barak <matanb@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2013-12-13 00:03:11 +08:00
|
|
|
},
|
2015-10-15 23:38:51 +08:00
|
|
|
},
|
2006-02-14 04:48:12 +08:00
|
|
|
},
|
|
|
|
[IB_QPS_RTR] = {
|
|
|
|
[IB_QPS_RESET] = { .valid = 1 },
|
|
|
|
[IB_QPS_ERR] = { .valid = 1 },
|
|
|
|
[IB_QPS_RTS] = {
|
|
|
|
.valid = 1,
|
|
|
|
.req_param = {
|
|
|
|
[IB_QPT_UD] = IB_QP_SQ_PSN,
|
|
|
|
[IB_QPT_UC] = IB_QP_SQ_PSN,
|
|
|
|
[IB_QPT_RC] = (IB_QP_TIMEOUT |
|
|
|
|
IB_QP_RETRY_CNT |
|
|
|
|
IB_QP_RNR_RETRY |
|
|
|
|
IB_QP_SQ_PSN |
|
|
|
|
IB_QP_MAX_QP_RD_ATOMIC),
|
2011-05-24 10:59:25 +08:00
|
|
|
[IB_QPT_XRC_INI] = (IB_QP_TIMEOUT |
|
|
|
|
IB_QP_RETRY_CNT |
|
|
|
|
IB_QP_RNR_RETRY |
|
|
|
|
IB_QP_SQ_PSN |
|
|
|
|
IB_QP_MAX_QP_RD_ATOMIC),
|
|
|
|
[IB_QPT_XRC_TGT] = (IB_QP_TIMEOUT |
|
|
|
|
IB_QP_SQ_PSN),
|
2006-02-14 04:48:12 +08:00
|
|
|
[IB_QPT_SMI] = IB_QP_SQ_PSN,
|
|
|
|
[IB_QPT_GSI] = IB_QP_SQ_PSN,
|
|
|
|
},
|
|
|
|
.opt_param = {
|
|
|
|
[IB_QPT_UD] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_UC] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
|
|
|
[IB_QPT_RC] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_MIN_RNR_TIMER |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
2011-05-24 10:59:25 +08:00
|
|
|
[IB_QPT_XRC_INI] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
|
|
|
[IB_QPT_XRC_TGT] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_MIN_RNR_TIMER |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
2006-02-14 04:48:12 +08:00
|
|
|
[IB_QPT_SMI] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_GSI] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_QKEY),
|
2016-12-01 19:43:14 +08:00
|
|
|
[IB_QPT_RAW_PACKET] = IB_QP_RATE_LIMIT,
|
2006-02-14 04:48:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[IB_QPS_RTS] = {
|
|
|
|
[IB_QPS_RESET] = { .valid = 1 },
|
|
|
|
[IB_QPS_ERR] = { .valid = 1 },
|
|
|
|
[IB_QPS_RTS] = {
|
|
|
|
.valid = 1,
|
|
|
|
.opt_param = {
|
|
|
|
[IB_QPT_UD] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_QKEY),
|
2006-03-03 03:22:28 +08:00
|
|
|
[IB_QPT_UC] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
2006-02-14 04:48:12 +08:00
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
2006-03-03 03:22:28 +08:00
|
|
|
[IB_QPT_RC] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
2006-02-14 04:48:12 +08:00
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_PATH_MIG_STATE |
|
|
|
|
IB_QP_MIN_RNR_TIMER),
|
2011-05-24 10:59:25 +08:00
|
|
|
[IB_QPT_XRC_INI] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
|
|
|
[IB_QPT_XRC_TGT] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_PATH_MIG_STATE |
|
|
|
|
IB_QP_MIN_RNR_TIMER),
|
2006-02-14 04:48:12 +08:00
|
|
|
[IB_QPT_SMI] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_GSI] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_QKEY),
|
2016-12-01 19:43:14 +08:00
|
|
|
[IB_QPT_RAW_PACKET] = IB_QP_RATE_LIMIT,
|
2006-02-14 04:48:12 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[IB_QPS_SQD] = {
|
|
|
|
.valid = 1,
|
|
|
|
.opt_param = {
|
|
|
|
[IB_QPT_UD] = IB_QP_EN_SQD_ASYNC_NOTIFY,
|
|
|
|
[IB_QPT_UC] = IB_QP_EN_SQD_ASYNC_NOTIFY,
|
|
|
|
[IB_QPT_RC] = IB_QP_EN_SQD_ASYNC_NOTIFY,
|
2011-05-24 10:59:25 +08:00
|
|
|
[IB_QPT_XRC_INI] = IB_QP_EN_SQD_ASYNC_NOTIFY,
|
|
|
|
[IB_QPT_XRC_TGT] = IB_QP_EN_SQD_ASYNC_NOTIFY, /* ??? */
|
2006-02-14 04:48:12 +08:00
|
|
|
[IB_QPT_SMI] = IB_QP_EN_SQD_ASYNC_NOTIFY,
|
|
|
|
[IB_QPT_GSI] = IB_QP_EN_SQD_ASYNC_NOTIFY
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[IB_QPS_SQD] = {
|
|
|
|
[IB_QPS_RESET] = { .valid = 1 },
|
|
|
|
[IB_QPS_ERR] = { .valid = 1 },
|
|
|
|
[IB_QPS_RTS] = {
|
|
|
|
.valid = 1,
|
|
|
|
.opt_param = {
|
|
|
|
[IB_QPT_UD] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_UC] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
|
|
|
[IB_QPT_RC] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_MIN_RNR_TIMER |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
2011-05-24 10:59:25 +08:00
|
|
|
[IB_QPT_XRC_INI] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
|
|
|
[IB_QPT_XRC_TGT] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_MIN_RNR_TIMER |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
2006-02-14 04:48:12 +08:00
|
|
|
[IB_QPT_SMI] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_GSI] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[IB_QPS_SQD] = {
|
|
|
|
.valid = 1,
|
|
|
|
.opt_param = {
|
|
|
|
[IB_QPT_UD] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_UC] = (IB_QP_AV |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
|
|
|
[IB_QPT_RC] = (IB_QP_PORT |
|
|
|
|
IB_QP_AV |
|
|
|
|
IB_QP_TIMEOUT |
|
|
|
|
IB_QP_RETRY_CNT |
|
|
|
|
IB_QP_RNR_RETRY |
|
|
|
|
IB_QP_MAX_QP_RD_ATOMIC |
|
|
|
|
IB_QP_MAX_DEST_RD_ATOMIC |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_MIN_RNR_TIMER |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
2011-05-24 10:59:25 +08:00
|
|
|
[IB_QPT_XRC_INI] = (IB_QP_PORT |
|
|
|
|
IB_QP_AV |
|
|
|
|
IB_QP_TIMEOUT |
|
|
|
|
IB_QP_RETRY_CNT |
|
|
|
|
IB_QP_RNR_RETRY |
|
|
|
|
IB_QP_MAX_QP_RD_ATOMIC |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
|
|
|
[IB_QPT_XRC_TGT] = (IB_QP_PORT |
|
|
|
|
IB_QP_AV |
|
|
|
|
IB_QP_TIMEOUT |
|
|
|
|
IB_QP_MAX_DEST_RD_ATOMIC |
|
|
|
|
IB_QP_ALT_PATH |
|
|
|
|
IB_QP_ACCESS_FLAGS |
|
|
|
|
IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_MIN_RNR_TIMER |
|
|
|
|
IB_QP_PATH_MIG_STATE),
|
2006-02-14 04:48:12 +08:00
|
|
|
[IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[IB_QPS_SQE] = {
|
|
|
|
[IB_QPS_RESET] = { .valid = 1 },
|
|
|
|
[IB_QPS_ERR] = { .valid = 1 },
|
|
|
|
[IB_QPS_RTS] = {
|
|
|
|
.valid = 1,
|
|
|
|
.opt_param = {
|
|
|
|
[IB_QPT_UD] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_UC] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_ACCESS_FLAGS),
|
|
|
|
[IB_QPT_SMI] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
[IB_QPT_GSI] = (IB_QP_CUR_STATE |
|
|
|
|
IB_QP_QKEY),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[IB_QPS_ERR] = {
|
|
|
|
[IB_QPS_RESET] = { .valid = 1 },
|
|
|
|
[IB_QPS_ERR] = { .valid = 1 }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-11 19:51:35 +08:00
|
|
|
bool ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
|
2018-10-02 21:11:21 +08:00
|
|
|
enum ib_qp_type type, enum ib_qp_attr_mask mask)
|
2006-02-14 04:48:12 +08:00
|
|
|
{
|
|
|
|
enum ib_qp_attr_mask req_param, opt_param;
|
|
|
|
|
|
|
|
if (mask & IB_QP_CUR_STATE &&
|
|
|
|
cur_state != IB_QPS_RTR && cur_state != IB_QPS_RTS &&
|
|
|
|
cur_state != IB_QPS_SQD && cur_state != IB_QPS_SQE)
|
2018-03-11 19:51:35 +08:00
|
|
|
return false;
|
2006-02-14 04:48:12 +08:00
|
|
|
|
|
|
|
if (!qp_state_table[cur_state][next_state].valid)
|
2018-03-11 19:51:35 +08:00
|
|
|
return false;
|
2006-02-14 04:48:12 +08:00
|
|
|
|
|
|
|
req_param = qp_state_table[cur_state][next_state].req_param[type];
|
|
|
|
opt_param = qp_state_table[cur_state][next_state].opt_param[type];
|
|
|
|
|
|
|
|
if ((mask & req_param) != req_param)
|
2018-03-11 19:51:35 +08:00
|
|
|
return false;
|
2006-02-14 04:48:12 +08:00
|
|
|
|
|
|
|
if (mask & ~(req_param | opt_param | IB_QP_STATE))
|
2018-03-11 19:51:35 +08:00
|
|
|
return false;
|
2006-02-14 04:48:12 +08:00
|
|
|
|
2018-03-11 19:51:35 +08:00
|
|
|
return true;
|
2006-02-14 04:48:12 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_modify_qp_is_ok);
|
|
|
|
|
2018-06-13 15:22:04 +08:00
|
|
|
/**
|
|
|
|
* ib_resolve_eth_dmac - Resolve destination mac address
|
|
|
|
* @device: Device to consider
|
|
|
|
* @ah_attr: address handle attribute which describes the
|
|
|
|
* source and destination parameters
|
|
|
|
* ib_resolve_eth_dmac() resolves destination mac address and L3 hop limit It
|
|
|
|
* returns 0 on success or appropriate error code. It initializes the
|
|
|
|
* necessary ah_attr fields when call is successful.
|
|
|
|
*/
|
2017-10-16 13:45:13 +08:00
|
|
|
static int ib_resolve_eth_dmac(struct ib_device *device,
|
|
|
|
struct rdma_ah_attr *ah_attr)
|
2013-12-13 00:03:17 +08:00
|
|
|
{
|
2018-06-13 15:22:04 +08:00
|
|
|
int ret = 0;
|
2017-04-30 02:41:28 +08:00
|
|
|
|
2017-06-12 16:14:04 +08:00
|
|
|
if (rdma_is_multicast_addr((struct in6_addr *)ah_attr->grh.dgid.raw)) {
|
|
|
|
if (ipv6_addr_v4mapped((struct in6_addr *)ah_attr->grh.dgid.raw)) {
|
|
|
|
__be32 addr = 0;
|
|
|
|
|
|
|
|
memcpy(&addr, ah_attr->grh.dgid.raw + 12, 4);
|
|
|
|
ip_eth_mc_map(addr, (char *)ah_attr->roce.dmac);
|
|
|
|
} else {
|
|
|
|
ipv6_eth_mc_map((struct in6_addr *)ah_attr->grh.dgid.raw,
|
|
|
|
(char *)ah_attr->roce.dmac);
|
|
|
|
}
|
2016-11-23 14:23:22 +08:00
|
|
|
} else {
|
2017-11-14 20:51:49 +08:00
|
|
|
ret = ib_resolve_unicast_gid_dmac(device, ah_attr);
|
2013-12-13 00:03:17 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-06-13 15:22:03 +08:00
|
|
|
static bool is_qp_type_connected(const struct ib_qp *qp)
|
|
|
|
{
|
|
|
|
return (qp->qp_type == IB_QPT_UC ||
|
|
|
|
qp->qp_type == IB_QPT_RC ||
|
|
|
|
qp->qp_type == IB_QPT_XRC_INI ||
|
|
|
|
qp->qp_type == IB_QPT_XRC_TGT);
|
|
|
|
}
|
|
|
|
|
2017-05-23 16:26:08 +08:00
|
|
|
/**
|
2018-01-09 21:24:51 +08:00
|
|
|
* IB core internal function to perform QP attributes modification.
|
2017-05-23 16:26:08 +08:00
|
|
|
*/
|
2018-01-09 21:24:51 +08:00
|
|
|
static int _ib_modify_qp(struct ib_qp *qp, struct ib_qp_attr *attr,
|
|
|
|
int attr_mask, struct ib_udata *udata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-11-14 20:51:56 +08:00
|
|
|
u8 port = attr_mask & IB_QP_PORT ? attr->port_num : qp->port;
|
2018-06-13 15:22:03 +08:00
|
|
|
const struct ib_gid_attr *old_sgid_attr_av;
|
|
|
|
const struct ib_gid_attr *old_sgid_attr_alt_av;
|
2017-05-23 16:26:08 +08:00
|
|
|
int ret;
|
2013-12-13 00:03:17 +08:00
|
|
|
|
2018-06-13 15:22:03 +08:00
|
|
|
if (attr_mask & IB_QP_AV) {
|
|
|
|
ret = rdma_fill_sgid_attr(qp->device, &attr->ah_attr,
|
|
|
|
&old_sgid_attr_av);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (attr_mask & IB_QP_ALT_PATH) {
|
2018-06-13 15:22:08 +08:00
|
|
|
/*
|
|
|
|
* FIXME: This does not track the migration state, so if the
|
|
|
|
* user loads a new alternate path after the HW has migrated
|
|
|
|
* from primary->alternate we will keep the wrong
|
|
|
|
* references. This is OK for IB because the reference
|
|
|
|
* counting does not serve any functional purpose.
|
|
|
|
*/
|
2018-06-13 15:22:03 +08:00
|
|
|
ret = rdma_fill_sgid_attr(qp->device, &attr->alt_ah_attr,
|
|
|
|
&old_sgid_attr_alt_av);
|
|
|
|
if (ret)
|
|
|
|
goto out_av;
|
2018-06-26 06:03:41 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Today the core code can only handle alternate paths and APM
|
|
|
|
* for IB. Ban them in roce mode.
|
|
|
|
*/
|
|
|
|
if (!(rdma_protocol_ib(qp->device,
|
|
|
|
attr->alt_ah_attr.port_num) &&
|
|
|
|
rdma_protocol_ib(qp->device, port))) {
|
|
|
|
ret = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-06-13 15:22:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user provided the qp_attr then we have to resolve it. Kernel
|
|
|
|
* users have to provide already resolved rdma_ah_attr's
|
|
|
|
*/
|
|
|
|
if (udata && (attr_mask & IB_QP_AV) &&
|
|
|
|
attr->ah_attr.type == RDMA_AH_ATTR_TYPE_ROCE &&
|
|
|
|
is_qp_type_connected(qp)) {
|
|
|
|
ret = ib_resolve_eth_dmac(qp->device, &attr->ah_attr);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-11-14 20:51:56 +08:00
|
|
|
if (rdma_ib_or_roce(qp->device, port)) {
|
|
|
|
if (attr_mask & IB_QP_RQ_PSN && attr->rq_psn & ~0xffffff) {
|
2018-09-21 06:42:23 +08:00
|
|
|
dev_warn(&qp->device->dev,
|
|
|
|
"%s rq_psn overflow, masking to 24 bits\n",
|
|
|
|
__func__);
|
2017-11-14 20:51:56 +08:00
|
|
|
attr->rq_psn &= 0xffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr_mask & IB_QP_SQ_PSN && attr->sq_psn & ~0xffffff) {
|
2018-09-21 06:42:23 +08:00
|
|
|
dev_warn(&qp->device->dev,
|
|
|
|
" %s sq_psn overflow, masking to 24 bits\n",
|
|
|
|
__func__);
|
2017-11-14 20:51:56 +08:00
|
|
|
attr->sq_psn &= 0xffffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 18:02:35 +08:00
|
|
|
/*
|
|
|
|
* Bind this qp to a counter automatically based on the rdma counter
|
|
|
|
* rules. This only set in RST2INIT with port specified
|
|
|
|
*/
|
|
|
|
if (!qp->counter && (attr_mask & IB_QP_PORT) &&
|
|
|
|
((attr_mask & IB_QP_STATE) && attr->qp_state == IB_QPS_INIT))
|
|
|
|
rdma_counter_bind_qp_auto(qp, attr->port_num);
|
|
|
|
|
2017-08-23 13:35:40 +08:00
|
|
|
ret = ib_security_modify_qp(qp, attr, attr_mask, udata);
|
2018-06-13 15:22:08 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (attr_mask & IB_QP_PORT)
|
2017-08-23 13:35:40 +08:00
|
|
|
qp->port = attr->port_num;
|
2018-06-13 15:22:08 +08:00
|
|
|
if (attr_mask & IB_QP_AV)
|
|
|
|
qp->av_sgid_attr =
|
|
|
|
rdma_update_sgid_attr(&attr->ah_attr, qp->av_sgid_attr);
|
|
|
|
if (attr_mask & IB_QP_ALT_PATH)
|
|
|
|
qp->alt_path_sgid_attr = rdma_update_sgid_attr(
|
|
|
|
&attr->alt_ah_attr, qp->alt_path_sgid_attr);
|
2017-08-23 13:35:40 +08:00
|
|
|
|
2018-06-13 15:22:03 +08:00
|
|
|
out:
|
|
|
|
if (attr_mask & IB_QP_ALT_PATH)
|
|
|
|
rdma_unfill_sgid_attr(&attr->alt_ah_attr, old_sgid_attr_alt_av);
|
|
|
|
out_av:
|
|
|
|
if (attr_mask & IB_QP_AV)
|
|
|
|
rdma_unfill_sgid_attr(&attr->ah_attr, old_sgid_attr_av);
|
2017-08-23 13:35:40 +08:00
|
|
|
return ret;
|
2017-05-23 16:26:08 +08:00
|
|
|
}
|
2018-01-09 21:24:51 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ib_modify_qp_with_udata - Modifies the attributes for the specified QP.
|
|
|
|
* @ib_qp: The QP to modify.
|
|
|
|
* @attr: On input, specifies the QP attributes to modify. On output,
|
|
|
|
* the current values of selected QP attributes are returned.
|
|
|
|
* @attr_mask: A bit-mask used to specify which attributes of the QP
|
|
|
|
* are being modified.
|
|
|
|
* @udata: pointer to user's input output buffer information
|
|
|
|
* are being modified.
|
|
|
|
* It returns 0 on success and returns appropriate error code on error.
|
|
|
|
*/
|
|
|
|
int ib_modify_qp_with_udata(struct ib_qp *ib_qp, struct ib_qp_attr *attr,
|
|
|
|
int attr_mask, struct ib_udata *udata)
|
|
|
|
{
|
2018-06-13 15:22:03 +08:00
|
|
|
return _ib_modify_qp(ib_qp->real_qp, attr, attr_mask, udata);
|
2018-01-09 21:24:51 +08:00
|
|
|
}
|
2017-05-23 16:26:08 +08:00
|
|
|
EXPORT_SYMBOL(ib_modify_qp_with_udata);
|
2013-12-13 00:03:17 +08:00
|
|
|
|
2017-06-15 04:13:34 +08:00
|
|
|
int ib_get_eth_speed(struct ib_device *dev, u8 port_num, u8 *speed, u8 *width)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
u32 netdev_speed;
|
|
|
|
struct net_device *netdev;
|
|
|
|
struct ethtool_link_ksettings lksettings;
|
|
|
|
|
|
|
|
if (rdma_port_get_link_layer(dev, port_num) != IB_LINK_LAYER_ETHERNET)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2019-02-13 12:12:50 +08:00
|
|
|
netdev = ib_device_get_netdev(dev, port_num);
|
2017-06-15 04:13:34 +08:00
|
|
|
if (!netdev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
rc = __ethtool_get_link_ksettings(netdev, &lksettings);
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
dev_put(netdev);
|
|
|
|
|
|
|
|
if (!rc) {
|
|
|
|
netdev_speed = lksettings.base.speed;
|
|
|
|
} else {
|
|
|
|
netdev_speed = SPEED_1000;
|
|
|
|
pr_warn("%s speed is unknown, defaulting to %d\n", netdev->name,
|
|
|
|
netdev_speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netdev_speed <= SPEED_1000) {
|
|
|
|
*width = IB_WIDTH_1X;
|
|
|
|
*speed = IB_SPEED_SDR;
|
|
|
|
} else if (netdev_speed <= SPEED_10000) {
|
|
|
|
*width = IB_WIDTH_1X;
|
|
|
|
*speed = IB_SPEED_FDR10;
|
|
|
|
} else if (netdev_speed <= SPEED_20000) {
|
|
|
|
*width = IB_WIDTH_4X;
|
|
|
|
*speed = IB_SPEED_DDR;
|
|
|
|
} else if (netdev_speed <= SPEED_25000) {
|
|
|
|
*width = IB_WIDTH_1X;
|
|
|
|
*speed = IB_SPEED_EDR;
|
|
|
|
} else if (netdev_speed <= SPEED_40000) {
|
|
|
|
*width = IB_WIDTH_4X;
|
|
|
|
*speed = IB_SPEED_FDR10;
|
|
|
|
} else {
|
|
|
|
*width = IB_WIDTH_4X;
|
|
|
|
*speed = IB_SPEED_EDR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_get_eth_speed);
|
|
|
|
|
2017-05-23 16:26:08 +08:00
|
|
|
int ib_modify_qp(struct ib_qp *qp,
|
|
|
|
struct ib_qp_attr *qp_attr,
|
|
|
|
int qp_attr_mask)
|
|
|
|
{
|
2018-01-09 21:24:51 +08:00
|
|
|
return _ib_modify_qp(qp->real_qp, qp_attr, qp_attr_mask, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_modify_qp);
|
|
|
|
|
|
|
|
int ib_query_qp(struct ib_qp *qp,
|
|
|
|
struct ib_qp_attr *qp_attr,
|
|
|
|
int qp_attr_mask,
|
|
|
|
struct ib_qp_init_attr *qp_init_attr)
|
|
|
|
{
|
2018-06-13 15:22:03 +08:00
|
|
|
qp_attr->ah_attr.grh.sgid_attr = NULL;
|
|
|
|
qp_attr->alt_ah_attr.grh.sgid_attr = NULL;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
return qp->device->ops.query_qp ?
|
|
|
|
qp->device->ops.query_qp(qp->real_qp, qp_attr, qp_attr_mask,
|
|
|
|
qp_init_attr) : -EOPNOTSUPP;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_query_qp);
|
|
|
|
|
2011-08-09 06:31:51 +08:00
|
|
|
int ib_close_qp(struct ib_qp *qp)
|
|
|
|
{
|
|
|
|
struct ib_qp *real_qp;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
real_qp = qp->real_qp;
|
|
|
|
if (real_qp == qp)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&real_qp->device->event_handler_lock, flags);
|
|
|
|
list_del(&qp->open_list);
|
|
|
|
spin_unlock_irqrestore(&real_qp->device->event_handler_lock, flags);
|
|
|
|
|
|
|
|
atomic_dec(&real_qp->usecnt);
|
2017-12-24 19:54:58 +08:00
|
|
|
if (qp->qp_sec)
|
|
|
|
ib_close_shared_qp_security(qp->qp_sec);
|
2011-08-09 06:31:51 +08:00
|
|
|
kfree(qp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_close_qp);
|
|
|
|
|
|
|
|
static int __ib_destroy_shared_qp(struct ib_qp *qp)
|
|
|
|
{
|
|
|
|
struct ib_xrcd *xrcd;
|
|
|
|
struct ib_qp *real_qp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
real_qp = qp->real_qp;
|
|
|
|
xrcd = real_qp->xrcd;
|
|
|
|
|
|
|
|
mutex_lock(&xrcd->tgt_qp_mutex);
|
|
|
|
ib_close_qp(qp);
|
|
|
|
if (atomic_read(&real_qp->usecnt) == 0)
|
|
|
|
list_del(&real_qp->xrcd_list);
|
|
|
|
else
|
|
|
|
real_qp = NULL;
|
|
|
|
mutex_unlock(&xrcd->tgt_qp_mutex);
|
|
|
|
|
|
|
|
if (real_qp) {
|
|
|
|
ret = ib_destroy_qp(real_qp);
|
|
|
|
if (!ret)
|
|
|
|
atomic_dec(&xrcd->usecnt);
|
|
|
|
else
|
|
|
|
__ib_insert_xrcd_qp(xrcd, real_qp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-01 00:10:05 +08:00
|
|
|
int ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-06-13 15:22:08 +08:00
|
|
|
const struct ib_gid_attr *alt_path_sgid_attr = qp->alt_path_sgid_attr;
|
|
|
|
const struct ib_gid_attr *av_sgid_attr = qp->av_sgid_attr;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ib_pd *pd;
|
|
|
|
struct ib_cq *scq, *rcq;
|
|
|
|
struct ib_srq *srq;
|
2016-05-23 20:20:54 +08:00
|
|
|
struct ib_rwq_ind_table *ind_tbl;
|
IB/core: Enforce PKey security on QPs
Add new LSM hooks to allocate and free security contexts and check for
permission to access a PKey.
Allocate and free a security context when creating and destroying a QP.
This context is used for controlling access to PKeys.
When a request is made to modify a QP that changes the port, PKey index,
or alternate path, check that the QP has permission for the PKey in the
PKey table index on the subnet prefix of the port. If the QP is shared
make sure all handles to the QP also have access.
Store which port and PKey index a QP is using. After the reset to init
transition the user can modify the port, PKey index and alternate path
independently. So port and PKey settings changes can be a merge of the
previous settings and the new ones.
In order to maintain access control if there are PKey table or subnet
prefix change keep a list of all QPs are using each PKey index on
each port. If a change occurs all QPs using that device and port must
have access enforced for the new cache settings.
These changes add a transaction to the QP modify process. Association
with the old port and PKey index must be maintained if the modify fails,
and must be removed if it succeeds. Association with the new port and
PKey index must be established prior to the modify and removed if the
modify fails.
1. When a QP is modified to a particular Port, PKey index or alternate
path insert that QP into the appropriate lists.
2. Check permission to access the new settings.
3. If step 2 grants access attempt to modify the QP.
4a. If steps 2 and 3 succeed remove any prior associations.
4b. If ether fails remove the new setting associations.
If a PKey table or subnet prefix changes walk the list of QPs and
check that they have permission. If not send the QP to the error state
and raise a fatal error event. If it's a shared QP make sure all the
QPs that share the real_qp have permission as well. If the QP that
owns a security structure is denied access the security structure is
marked as such and the QP is added to an error_list. Once the moving
the QP to error is complete the security structure mark is cleared.
Maintaining the lists correctly turns QP destroy into a transaction.
The hardware driver for the device frees the ib_qp structure, so while
the destroy is in progress the ib_qp pointer in the ib_qp_security
struct is undefined. When the destroy process begins the ib_qp_security
structure is marked as destroying. This prevents any action from being
taken on the QP pointer. After the QP is destroyed successfully it
could still listed on an error_list wait for it to be processed by that
flow before cleaning up the structure.
If the destroy fails the QPs port and PKey settings are reinserted into
the appropriate lists, the destroying flag is cleared, and access control
is enforced, in case there were any cache changes during the destroy
flow.
To keep the security changes isolated a new file is used to hold security
related functionality.
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Acked-by: Doug Ledford <dledford@redhat.com>
[PM: merge fixup in ib_verbs.h and uverbs_cmd.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2017-05-19 20:48:52 +08:00
|
|
|
struct ib_qp_security *sec;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret;
|
|
|
|
|
2016-05-04 00:01:07 +08:00
|
|
|
WARN_ON_ONCE(qp->mrs_used > 0);
|
|
|
|
|
2011-08-09 06:31:51 +08:00
|
|
|
if (atomic_read(&qp->usecnt))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
if (qp->real_qp != qp)
|
|
|
|
return __ib_destroy_shared_qp(qp);
|
|
|
|
|
2011-05-24 10:59:25 +08:00
|
|
|
pd = qp->pd;
|
|
|
|
scq = qp->send_cq;
|
|
|
|
rcq = qp->recv_cq;
|
|
|
|
srq = qp->srq;
|
2016-05-23 20:20:54 +08:00
|
|
|
ind_tbl = qp->rwq_ind_tbl;
|
IB/core: Enforce PKey security on QPs
Add new LSM hooks to allocate and free security contexts and check for
permission to access a PKey.
Allocate and free a security context when creating and destroying a QP.
This context is used for controlling access to PKeys.
When a request is made to modify a QP that changes the port, PKey index,
or alternate path, check that the QP has permission for the PKey in the
PKey table index on the subnet prefix of the port. If the QP is shared
make sure all handles to the QP also have access.
Store which port and PKey index a QP is using. After the reset to init
transition the user can modify the port, PKey index and alternate path
independently. So port and PKey settings changes can be a merge of the
previous settings and the new ones.
In order to maintain access control if there are PKey table or subnet
prefix change keep a list of all QPs are using each PKey index on
each port. If a change occurs all QPs using that device and port must
have access enforced for the new cache settings.
These changes add a transaction to the QP modify process. Association
with the old port and PKey index must be maintained if the modify fails,
and must be removed if it succeeds. Association with the new port and
PKey index must be established prior to the modify and removed if the
modify fails.
1. When a QP is modified to a particular Port, PKey index or alternate
path insert that QP into the appropriate lists.
2. Check permission to access the new settings.
3. If step 2 grants access attempt to modify the QP.
4a. If steps 2 and 3 succeed remove any prior associations.
4b. If ether fails remove the new setting associations.
If a PKey table or subnet prefix changes walk the list of QPs and
check that they have permission. If not send the QP to the error state
and raise a fatal error event. If it's a shared QP make sure all the
QPs that share the real_qp have permission as well. If the QP that
owns a security structure is denied access the security structure is
marked as such and the QP is added to an error_list. Once the moving
the QP to error is complete the security structure mark is cleared.
Maintaining the lists correctly turns QP destroy into a transaction.
The hardware driver for the device frees the ib_qp structure, so while
the destroy is in progress the ib_qp pointer in the ib_qp_security
struct is undefined. When the destroy process begins the ib_qp_security
structure is marked as destroying. This prevents any action from being
taken on the QP pointer. After the QP is destroyed successfully it
could still listed on an error_list wait for it to be processed by that
flow before cleaning up the structure.
If the destroy fails the QPs port and PKey settings are reinserted into
the appropriate lists, the destroying flag is cleared, and access control
is enforced, in case there were any cache changes during the destroy
flow.
To keep the security changes isolated a new file is used to hold security
related functionality.
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Acked-by: Doug Ledford <dledford@redhat.com>
[PM: merge fixup in ib_verbs.h and uverbs_cmd.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2017-05-19 20:48:52 +08:00
|
|
|
sec = qp->qp_sec;
|
|
|
|
if (sec)
|
|
|
|
ib_destroy_qp_security_begin(sec);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-05-04 00:01:09 +08:00
|
|
|
if (!qp->uobject)
|
|
|
|
rdma_rw_cleanup_mrs(qp);
|
|
|
|
|
2019-07-02 18:02:35 +08:00
|
|
|
rdma_counter_unbind_qp(qp, true);
|
2018-01-28 17:17:21 +08:00
|
|
|
rdma_restrack_del(&qp->res);
|
2019-04-01 00:10:05 +08:00
|
|
|
ret = qp->device->ops.destroy_qp(qp, udata);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ret) {
|
2018-06-13 15:22:08 +08:00
|
|
|
if (alt_path_sgid_attr)
|
|
|
|
rdma_put_gid_attr(alt_path_sgid_attr);
|
|
|
|
if (av_sgid_attr)
|
|
|
|
rdma_put_gid_attr(av_sgid_attr);
|
2011-05-24 10:59:25 +08:00
|
|
|
if (pd)
|
|
|
|
atomic_dec(&pd->usecnt);
|
|
|
|
if (scq)
|
|
|
|
atomic_dec(&scq->usecnt);
|
|
|
|
if (rcq)
|
|
|
|
atomic_dec(&rcq->usecnt);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (srq)
|
|
|
|
atomic_dec(&srq->usecnt);
|
2016-05-23 20:20:54 +08:00
|
|
|
if (ind_tbl)
|
|
|
|
atomic_dec(&ind_tbl->usecnt);
|
IB/core: Enforce PKey security on QPs
Add new LSM hooks to allocate and free security contexts and check for
permission to access a PKey.
Allocate and free a security context when creating and destroying a QP.
This context is used for controlling access to PKeys.
When a request is made to modify a QP that changes the port, PKey index,
or alternate path, check that the QP has permission for the PKey in the
PKey table index on the subnet prefix of the port. If the QP is shared
make sure all handles to the QP also have access.
Store which port and PKey index a QP is using. After the reset to init
transition the user can modify the port, PKey index and alternate path
independently. So port and PKey settings changes can be a merge of the
previous settings and the new ones.
In order to maintain access control if there are PKey table or subnet
prefix change keep a list of all QPs are using each PKey index on
each port. If a change occurs all QPs using that device and port must
have access enforced for the new cache settings.
These changes add a transaction to the QP modify process. Association
with the old port and PKey index must be maintained if the modify fails,
and must be removed if it succeeds. Association with the new port and
PKey index must be established prior to the modify and removed if the
modify fails.
1. When a QP is modified to a particular Port, PKey index or alternate
path insert that QP into the appropriate lists.
2. Check permission to access the new settings.
3. If step 2 grants access attempt to modify the QP.
4a. If steps 2 and 3 succeed remove any prior associations.
4b. If ether fails remove the new setting associations.
If a PKey table or subnet prefix changes walk the list of QPs and
check that they have permission. If not send the QP to the error state
and raise a fatal error event. If it's a shared QP make sure all the
QPs that share the real_qp have permission as well. If the QP that
owns a security structure is denied access the security structure is
marked as such and the QP is added to an error_list. Once the moving
the QP to error is complete the security structure mark is cleared.
Maintaining the lists correctly turns QP destroy into a transaction.
The hardware driver for the device frees the ib_qp structure, so while
the destroy is in progress the ib_qp pointer in the ib_qp_security
struct is undefined. When the destroy process begins the ib_qp_security
structure is marked as destroying. This prevents any action from being
taken on the QP pointer. After the QP is destroyed successfully it
could still listed on an error_list wait for it to be processed by that
flow before cleaning up the structure.
If the destroy fails the QPs port and PKey settings are reinserted into
the appropriate lists, the destroying flag is cleared, and access control
is enforced, in case there were any cache changes during the destroy
flow.
To keep the security changes isolated a new file is used to hold security
related functionality.
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Acked-by: Doug Ledford <dledford@redhat.com>
[PM: merge fixup in ib_verbs.h and uverbs_cmd.c]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2017-05-19 20:48:52 +08:00
|
|
|
if (sec)
|
|
|
|
ib_destroy_qp_security_end(sec);
|
|
|
|
} else {
|
|
|
|
if (sec)
|
|
|
|
ib_destroy_qp_security_abort(sec);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2019-04-01 00:10:05 +08:00
|
|
|
EXPORT_SYMBOL(ib_destroy_qp_user);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Completion queues */
|
|
|
|
|
2018-06-15 23:22:33 +08:00
|
|
|
struct ib_cq *__ib_create_cq(struct ib_device *device,
|
|
|
|
ib_comp_handler comp_handler,
|
|
|
|
void (*event_handler)(struct ib_event *, void *),
|
|
|
|
void *cq_context,
|
|
|
|
const struct ib_cq_init_attr *cq_attr,
|
|
|
|
const char *caller)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ib_cq *cq;
|
2019-05-28 19:37:29 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
cq = rdma_zalloc_drv_obj(device, ib_cq);
|
|
|
|
if (!cq)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-05-28 19:37:29 +08:00
|
|
|
cq->device = device;
|
|
|
|
cq->uobject = NULL;
|
|
|
|
cq->comp_handler = comp_handler;
|
|
|
|
cq->event_handler = event_handler;
|
|
|
|
cq->cq_context = cq_context;
|
|
|
|
atomic_set(&cq->usecnt, 0);
|
|
|
|
cq->res.type = RDMA_RESTRACK_CQ;
|
|
|
|
rdma_restrack_set_task(&cq->res, caller);
|
|
|
|
|
|
|
|
ret = device->ops.create_cq(cq, cq_attr, NULL);
|
|
|
|
if (ret) {
|
|
|
|
kfree(cq);
|
|
|
|
return ERR_PTR(ret);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2019-05-28 19:37:29 +08:00
|
|
|
rdma_restrack_kadd(&cq->res);
|
2005-04-17 06:20:36 +08:00
|
|
|
return cq;
|
|
|
|
}
|
2018-06-15 23:22:33 +08:00
|
|
|
EXPORT_SYMBOL(__ib_create_cq);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-11-13 16:51:19 +08:00
|
|
|
int rdma_set_cq_moderation(struct ib_cq *cq, u16 cq_count, u16 cq_period)
|
2008-04-17 12:09:33 +08:00
|
|
|
{
|
2018-12-11 03:09:48 +08:00
|
|
|
return cq->device->ops.modify_cq ?
|
|
|
|
cq->device->ops.modify_cq(cq, cq_count,
|
|
|
|
cq_period) : -EOPNOTSUPP;
|
2008-04-17 12:09:33 +08:00
|
|
|
}
|
2017-11-13 16:51:19 +08:00
|
|
|
EXPORT_SYMBOL(rdma_set_cq_moderation);
|
2008-04-17 12:09:33 +08:00
|
|
|
|
2019-04-01 00:10:05 +08:00
|
|
|
int ib_destroy_cq_user(struct ib_cq *cq, struct ib_udata *udata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (atomic_read(&cq->usecnt))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2018-01-28 17:17:22 +08:00
|
|
|
rdma_restrack_del(&cq->res);
|
2019-05-28 19:37:28 +08:00
|
|
|
cq->device->ops.destroy_cq(cq, udata);
|
2019-05-28 19:37:29 +08:00
|
|
|
kfree(cq);
|
2019-05-28 19:37:28 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2019-04-01 00:10:05 +08:00
|
|
|
EXPORT_SYMBOL(ib_destroy_cq_user);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-02-14 08:30:49 +08:00
|
|
|
int ib_resize_cq(struct ib_cq *cq, int cqe)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-12-11 03:09:48 +08:00
|
|
|
return cq->device->ops.resize_cq ?
|
|
|
|
cq->device->ops.resize_cq(cq, cqe, NULL) : -EOPNOTSUPP;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_resize_cq);
|
|
|
|
|
|
|
|
/* Memory regions */
|
|
|
|
|
2019-04-01 00:10:05 +08:00
|
|
|
int ib_dereg_mr_user(struct ib_mr *mr, struct ib_udata *udata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2015-12-24 02:12:54 +08:00
|
|
|
struct ib_pd *pd = mr->pd;
|
2018-04-05 23:53:25 +08:00
|
|
|
struct ib_dm *dm = mr->dm;
|
2019-06-11 23:52:41 +08:00
|
|
|
struct ib_sig_attrs *sig_attrs = mr->sig_attrs;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-03-02 05:58:13 +08:00
|
|
|
rdma_restrack_del(&mr->res);
|
2019-04-01 00:10:05 +08:00
|
|
|
ret = mr->device->ops.dereg_mr(mr, udata);
|
2018-04-05 23:53:25 +08:00
|
|
|
if (!ret) {
|
2005-04-17 06:20:36 +08:00
|
|
|
atomic_dec(&pd->usecnt);
|
2018-04-05 23:53:25 +08:00
|
|
|
if (dm)
|
|
|
|
atomic_dec(&dm->usecnt);
|
2019-06-11 23:52:41 +08:00
|
|
|
kfree(sig_attrs);
|
2018-04-05 23:53:25 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2019-04-01 00:10:05 +08:00
|
|
|
EXPORT_SYMBOL(ib_dereg_mr_user);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-07-30 15:32:35 +08:00
|
|
|
/**
|
2019-05-15 18:49:31 +08:00
|
|
|
* ib_alloc_mr_user() - Allocates a memory region
|
2015-07-30 15:32:35 +08:00
|
|
|
* @pd: protection domain associated with the region
|
|
|
|
* @mr_type: memory region type
|
|
|
|
* @max_num_sg: maximum sg entries available for registration.
|
2019-04-01 00:10:05 +08:00
|
|
|
* @udata: user data or null for kernel objects
|
2015-07-30 15:32:35 +08:00
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* Memory registeration page/sg lists must not exceed max_num_sg.
|
|
|
|
* For mr_type IB_MR_TYPE_MEM_REG, the total length cannot exceed
|
|
|
|
* max_num_sg * used_page_size.
|
|
|
|
*
|
|
|
|
*/
|
2019-04-01 00:10:05 +08:00
|
|
|
struct ib_mr *ib_alloc_mr_user(struct ib_pd *pd, enum ib_mr_type mr_type,
|
|
|
|
u32 max_num_sg, struct ib_udata *udata)
|
2008-07-15 14:48:45 +08:00
|
|
|
{
|
|
|
|
struct ib_mr *mr;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!pd->device->ops.alloc_mr)
|
2018-02-22 00:12:44 +08:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
2008-07-15 14:48:45 +08:00
|
|
|
|
2019-06-11 23:52:39 +08:00
|
|
|
if (WARN_ON_ONCE(mr_type == IB_MR_TYPE_INTEGRITY))
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2019-04-01 00:10:05 +08:00
|
|
|
mr = pd->device->ops.alloc_mr(pd, mr_type, max_num_sg, udata);
|
2008-07-15 14:48:45 +08:00
|
|
|
if (!IS_ERR(mr)) {
|
|
|
|
mr->device = pd->device;
|
|
|
|
mr->pd = pd;
|
2018-04-26 20:42:55 +08:00
|
|
|
mr->dm = NULL;
|
2008-07-15 14:48:45 +08:00
|
|
|
mr->uobject = NULL;
|
|
|
|
atomic_inc(&pd->usecnt);
|
2016-05-04 00:01:08 +08:00
|
|
|
mr->need_inval = false;
|
2018-03-02 05:58:13 +08:00
|
|
|
mr->res.type = RDMA_RESTRACK_MR;
|
2018-12-17 23:15:16 +08:00
|
|
|
rdma_restrack_kadd(&mr->res);
|
2019-06-11 23:52:38 +08:00
|
|
|
mr->type = mr_type;
|
2019-06-11 23:52:41 +08:00
|
|
|
mr->sig_attrs = NULL;
|
2008-07-15 14:48:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return mr;
|
|
|
|
}
|
2019-04-01 00:10:05 +08:00
|
|
|
EXPORT_SYMBOL(ib_alloc_mr_user);
|
2008-07-15 14:48:45 +08:00
|
|
|
|
2019-06-11 23:52:39 +08:00
|
|
|
/**
|
|
|
|
* ib_alloc_mr_integrity() - Allocates an integrity memory region
|
|
|
|
* @pd: protection domain associated with the region
|
|
|
|
* @max_num_data_sg: maximum data sg entries available for registration
|
|
|
|
* @max_num_meta_sg: maximum metadata sg entries available for
|
|
|
|
* registration
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* Memory registration page/sg lists must not exceed max_num_sg,
|
|
|
|
* also the integrity page/sg lists must not exceed max_num_meta_sg.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd,
|
|
|
|
u32 max_num_data_sg,
|
|
|
|
u32 max_num_meta_sg)
|
|
|
|
{
|
|
|
|
struct ib_mr *mr;
|
2019-06-11 23:52:41 +08:00
|
|
|
struct ib_sig_attrs *sig_attrs;
|
2019-06-11 23:52:39 +08:00
|
|
|
|
2019-06-11 23:52:40 +08:00
|
|
|
if (!pd->device->ops.alloc_mr_integrity ||
|
|
|
|
!pd->device->ops.map_mr_sg_pi)
|
2019-06-11 23:52:39 +08:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
|
|
|
|
|
|
|
if (!max_num_meta_sg)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2019-06-11 23:52:41 +08:00
|
|
|
sig_attrs = kzalloc(sizeof(struct ib_sig_attrs), GFP_KERNEL);
|
|
|
|
if (!sig_attrs)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2019-06-11 23:52:39 +08:00
|
|
|
mr = pd->device->ops.alloc_mr_integrity(pd, max_num_data_sg,
|
|
|
|
max_num_meta_sg);
|
2019-06-11 23:52:41 +08:00
|
|
|
if (IS_ERR(mr)) {
|
|
|
|
kfree(sig_attrs);
|
2019-06-11 23:52:39 +08:00
|
|
|
return mr;
|
2019-06-11 23:52:41 +08:00
|
|
|
}
|
2019-06-11 23:52:39 +08:00
|
|
|
|
|
|
|
mr->device = pd->device;
|
|
|
|
mr->pd = pd;
|
|
|
|
mr->dm = NULL;
|
|
|
|
mr->uobject = NULL;
|
|
|
|
atomic_inc(&pd->usecnt);
|
|
|
|
mr->need_inval = false;
|
|
|
|
mr->res.type = RDMA_RESTRACK_MR;
|
|
|
|
rdma_restrack_kadd(&mr->res);
|
|
|
|
mr->type = IB_MR_TYPE_INTEGRITY;
|
2019-06-11 23:52:41 +08:00
|
|
|
mr->sig_attrs = sig_attrs;
|
2019-06-11 23:52:39 +08:00
|
|
|
|
|
|
|
return mr;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_alloc_mr_integrity);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* "Fast" memory regions */
|
|
|
|
|
|
|
|
struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
|
|
|
|
int mr_access_flags,
|
|
|
|
struct ib_fmr_attr *fmr_attr)
|
|
|
|
{
|
|
|
|
struct ib_fmr *fmr;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!pd->device->ops.alloc_fmr)
|
2018-02-22 00:12:44 +08:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
fmr = pd->device->ops.alloc_fmr(pd, mr_access_flags, fmr_attr);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!IS_ERR(fmr)) {
|
|
|
|
fmr->device = pd->device;
|
|
|
|
fmr->pd = pd;
|
|
|
|
atomic_inc(&pd->usecnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmr;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_alloc_fmr);
|
|
|
|
|
|
|
|
int ib_unmap_fmr(struct list_head *fmr_list)
|
|
|
|
{
|
|
|
|
struct ib_fmr *fmr;
|
|
|
|
|
|
|
|
if (list_empty(fmr_list))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fmr = list_entry(fmr_list->next, struct ib_fmr, list);
|
2018-12-11 03:09:48 +08:00
|
|
|
return fmr->device->ops.unmap_fmr(fmr_list);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_unmap_fmr);
|
|
|
|
|
|
|
|
int ib_dealloc_fmr(struct ib_fmr *fmr)
|
|
|
|
{
|
|
|
|
struct ib_pd *pd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
pd = fmr->pd;
|
2018-12-11 03:09:48 +08:00
|
|
|
ret = fmr->device->ops.dealloc_fmr(fmr);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ret)
|
|
|
|
atomic_dec(&pd->usecnt);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_dealloc_fmr);
|
|
|
|
|
|
|
|
/* Multicast groups */
|
|
|
|
|
2017-06-12 16:14:02 +08:00
|
|
|
static bool is_valid_mcast_lid(struct ib_qp *qp, u16 lid)
|
|
|
|
{
|
|
|
|
struct ib_qp_init_attr init_attr = {};
|
|
|
|
struct ib_qp_attr attr = {};
|
|
|
|
int num_eth_ports = 0;
|
|
|
|
int port;
|
|
|
|
|
|
|
|
/* If QP state >= init, it is assigned to a port and we can check this
|
|
|
|
* port only.
|
|
|
|
*/
|
|
|
|
if (!ib_query_qp(qp, &attr, IB_QP_STATE | IB_QP_PORT, &init_attr)) {
|
|
|
|
if (attr.qp_state >= IB_QPS_INIT) {
|
2017-09-01 00:30:34 +08:00
|
|
|
if (rdma_port_get_link_layer(qp->device, attr.port_num) !=
|
2017-06-12 16:14:02 +08:00
|
|
|
IB_LINK_LAYER_INFINIBAND)
|
|
|
|
return true;
|
|
|
|
goto lid_check;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Can't get a quick answer, iterate over all ports */
|
|
|
|
for (port = 0; port < qp->device->phys_port_cnt; port++)
|
2017-09-01 00:30:34 +08:00
|
|
|
if (rdma_port_get_link_layer(qp->device, port) !=
|
2017-06-12 16:14:02 +08:00
|
|
|
IB_LINK_LAYER_INFINIBAND)
|
|
|
|
num_eth_ports++;
|
|
|
|
|
|
|
|
/* If we have at lease one Ethernet port, RoCE annex declares that
|
|
|
|
* multicast LID should be ignored. We can't tell at this step if the
|
|
|
|
* QP belongs to an IB or Ethernet port.
|
|
|
|
*/
|
|
|
|
if (num_eth_ports)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* If all the ports are IB, we can check according to IB spec. */
|
|
|
|
lid_check:
|
|
|
|
return !(lid < be16_to_cpu(IB_MULTICAST_LID_BASE) ||
|
|
|
|
lid == be16_to_cpu(IB_LID_PERMISSIVE));
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid)
|
|
|
|
{
|
2012-04-29 22:04:22 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!qp->device->ops.attach_mcast)
|
2018-02-22 00:12:44 +08:00
|
|
|
return -EOPNOTSUPP;
|
2017-06-12 16:14:03 +08:00
|
|
|
|
|
|
|
if (!rdma_is_multicast_addr((struct in6_addr *)gid->raw) ||
|
|
|
|
qp->qp_type != IB_QPT_UD || !is_valid_mcast_lid(qp, lid))
|
2005-09-27 02:47:53 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
ret = qp->device->ops.attach_mcast(qp, gid, lid);
|
2012-04-29 22:04:22 +08:00
|
|
|
if (!ret)
|
|
|
|
atomic_inc(&qp->usecnt);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_attach_mcast);
|
|
|
|
|
|
|
|
int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid)
|
|
|
|
{
|
2012-04-29 22:04:22 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!qp->device->ops.detach_mcast)
|
2018-02-22 00:12:44 +08:00
|
|
|
return -EOPNOTSUPP;
|
2017-06-12 16:14:03 +08:00
|
|
|
|
|
|
|
if (!rdma_is_multicast_addr((struct in6_addr *)gid->raw) ||
|
|
|
|
qp->qp_type != IB_QPT_UD || !is_valid_mcast_lid(qp, lid))
|
2005-09-27 02:47:53 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
ret = qp->device->ops.detach_mcast(qp, gid, lid);
|
2012-04-29 22:04:22 +08:00
|
|
|
if (!ret)
|
|
|
|
atomic_dec(&qp->usecnt);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_detach_mcast);
|
2011-05-24 08:52:46 +08:00
|
|
|
|
2018-01-28 17:17:19 +08:00
|
|
|
struct ib_xrcd *__ib_alloc_xrcd(struct ib_device *device, const char *caller)
|
2011-05-24 08:52:46 +08:00
|
|
|
{
|
|
|
|
struct ib_xrcd *xrcd;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!device->ops.alloc_xrcd)
|
2018-02-22 00:12:44 +08:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
2011-05-24 08:52:46 +08:00
|
|
|
|
2019-04-01 00:10:07 +08:00
|
|
|
xrcd = device->ops.alloc_xrcd(device, NULL);
|
2011-05-24 08:52:46 +08:00
|
|
|
if (!IS_ERR(xrcd)) {
|
|
|
|
xrcd->device = device;
|
2011-05-24 23:33:46 +08:00
|
|
|
xrcd->inode = NULL;
|
2011-05-24 08:52:46 +08:00
|
|
|
atomic_set(&xrcd->usecnt, 0);
|
2011-05-27 14:06:44 +08:00
|
|
|
mutex_init(&xrcd->tgt_qp_mutex);
|
|
|
|
INIT_LIST_HEAD(&xrcd->tgt_qp_list);
|
2011-05-24 08:52:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return xrcd;
|
|
|
|
}
|
2018-01-28 17:17:19 +08:00
|
|
|
EXPORT_SYMBOL(__ib_alloc_xrcd);
|
2011-05-24 08:52:46 +08:00
|
|
|
|
2019-04-01 00:10:05 +08:00
|
|
|
int ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata)
|
2011-05-24 08:52:46 +08:00
|
|
|
{
|
2011-05-27 14:06:44 +08:00
|
|
|
struct ib_qp *qp;
|
|
|
|
int ret;
|
|
|
|
|
2011-05-24 08:52:46 +08:00
|
|
|
if (atomic_read(&xrcd->usecnt))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2011-05-27 14:06:44 +08:00
|
|
|
while (!list_empty(&xrcd->tgt_qp_list)) {
|
|
|
|
qp = list_entry(xrcd->tgt_qp_list.next, struct ib_qp, xrcd_list);
|
|
|
|
ret = ib_destroy_qp(qp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2019-07-23 14:57:24 +08:00
|
|
|
mutex_destroy(&xrcd->tgt_qp_mutex);
|
2011-05-27 14:06:44 +08:00
|
|
|
|
2019-04-01 00:10:05 +08:00
|
|
|
return xrcd->device->ops.dealloc_xrcd(xrcd, udata);
|
2011-05-24 08:52:46 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_dealloc_xrcd);
|
IB/core: Add receive flow steering support
The RDMA stack allows for applications to create IB_QPT_RAW_PACKET
QPs, which receive plain Ethernet packets, specifically packets that
don't carry any QPN to be matched by the receiving side. Applications
using these QPs must be provided with a method to program some
steering rule with the HW so packets arriving at the local port can be
routed to them.
This patch adds ib_create_flow(), which allow providing a flow
specification for a QP. When there's a match between the
specification and a received packet, the packet is forwarded to that
QP, in a the same way one uses ib_attach_multicast() for IB UD
multicast handling.
Flow specifications are provided as instances of struct ib_flow_spec_yyy,
which describe L2, L3 and L4 headers. Currently specs for Ethernet, IPv4,
TCP and UDP are defined. Flow specs are made of values and masks.
The input to ib_create_flow() is a struct ib_flow_attr, which contains
a few mandatory control elements and optional flow specs.
struct ib_flow_attr {
enum ib_flow_attr_type type;
u16 size;
u16 priority;
u32 flags;
u8 num_of_specs;
u8 port;
/* Following are the optional layers according to user request
* struct ib_flow_spec_yyy
* struct ib_flow_spec_zzz
*/
};
As these specs are eventually coming from user space, they are defined and
used in a way which allows adding new spec types without kernel/user ABI
change, just with a little API enhancement which defines the newly added spec.
The flow spec structures are defined with TLV (Type-Length-Value)
entries, which allows calling ib_create_flow() with a list of variable
length of optional specs.
For the actual processing of ib_flow_attr the driver uses the number
of specs and the size mandatory fields along with the TLV nature of
the specs.
Steering rules processing order is according to the domain over which
the rule is set and the rule priority. All rules set by user space
applicatations fall into the IB_FLOW_DOMAIN_USER domain, other domains
could be used by future IPoIB RFS and Ethetool flow-steering interface
implementation. Lower numerical value for the priority field means
higher priority.
The returned value from ib_create_flow() is a struct ib_flow, which
contains a database pointer (handle) provided by the HW driver to be
used when calling ib_destroy_flow().
Applications that offload TCP/IP traffic can also be written over IB
UD QPs. The ib_create_flow() / ib_destroy_flow() API is designed to
support UD QPs too. A HW driver can set IB_DEVICE_MANAGED_FLOW_STEERING
to denote support for flow steering.
The ib_flow_attr enum type supports usage of flow steering for promiscuous
and sniffer purposes:
IB_FLOW_ATTR_NORMAL - "regular" rule, steering according to rule specification
IB_FLOW_ATTR_ALL_DEFAULT - default unicast and multicast rule, receive
all Ethernet traffic which isn't steered to any QP
IB_FLOW_ATTR_MC_DEFAULT - same as IB_FLOW_ATTR_ALL_DEFAULT but only for multicast
IB_FLOW_ATTR_SNIFFER - sniffer rule, receive all port traffic
ALL_DEFAULT and MC_DEFAULT rules options are valid only for Ethernet link type.
Signed-off-by: Hadar Hen Zion <hadarh@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2013-08-07 19:01:59 +08:00
|
|
|
|
IB/core: Introduce Work Queue object and its verbs
Introduce Work Queue object and its create/destroy/modify verbs.
QP can be created without internal WQs "packaged" inside it,
this QP can be configured to use "external" WQ object as its
receive/send queue.
WQ is a necessary component for RSS technology since RSS mechanism
is supposed to distribute the traffic between multiple
Receive Work Queues.
WQ associated (many to one) with Completion Queue and it owns WQ
properties (PD, WQ size, etc.).
WQ has a type, this patch introduces the IB_WQT_RQ (i.e.receive queue),
it may be extend to others such as IB_WQT_SQ. (send queue).
WQ from type IB_WQT_RQ contains receive work requests.
PD is an attribute of a work queue (i.e. send/receive queue), it's used
by the hardware for security validation before scattering to a memory
region which is pointed by the WQ. For that, an external WQ object
needs a PD, letting the hardware makes that validation.
When accessing a memory region that is pointed by the WQ its PD
is used and not the QP's PD, this behavior is similar
to a SRQ and a QP.
WQ context is subject to a well-defined state transitions done by
the modify_wq verb.
When WQ is created its initial state becomes IB_WQS_RESET.
>From IB_WQS_RESET it can be modified to itself or to IB_WQS_RDY.
>From IB_WQS_RDY it can be modified to itself, to IB_WQS_RESET
or to IB_WQS_ERR.
>From IB_WQS_ERR it can be modified to IB_WQS_RESET.
Note: transition to IB_WQS_ERR might occur implicitly in case there
was some HW error.
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-05-23 20:20:48 +08:00
|
|
|
/**
|
|
|
|
* ib_create_wq - Creates a WQ associated with the specified protection
|
|
|
|
* domain.
|
|
|
|
* @pd: The protection domain associated with the WQ.
|
2018-01-06 08:21:40 +08:00
|
|
|
* @wq_attr: A list of initial attributes required to create the
|
IB/core: Introduce Work Queue object and its verbs
Introduce Work Queue object and its create/destroy/modify verbs.
QP can be created without internal WQs "packaged" inside it,
this QP can be configured to use "external" WQ object as its
receive/send queue.
WQ is a necessary component for RSS technology since RSS mechanism
is supposed to distribute the traffic between multiple
Receive Work Queues.
WQ associated (many to one) with Completion Queue and it owns WQ
properties (PD, WQ size, etc.).
WQ has a type, this patch introduces the IB_WQT_RQ (i.e.receive queue),
it may be extend to others such as IB_WQT_SQ. (send queue).
WQ from type IB_WQT_RQ contains receive work requests.
PD is an attribute of a work queue (i.e. send/receive queue), it's used
by the hardware for security validation before scattering to a memory
region which is pointed by the WQ. For that, an external WQ object
needs a PD, letting the hardware makes that validation.
When accessing a memory region that is pointed by the WQ its PD
is used and not the QP's PD, this behavior is similar
to a SRQ and a QP.
WQ context is subject to a well-defined state transitions done by
the modify_wq verb.
When WQ is created its initial state becomes IB_WQS_RESET.
>From IB_WQS_RESET it can be modified to itself or to IB_WQS_RDY.
>From IB_WQS_RDY it can be modified to itself, to IB_WQS_RESET
or to IB_WQS_ERR.
>From IB_WQS_ERR it can be modified to IB_WQS_RESET.
Note: transition to IB_WQS_ERR might occur implicitly in case there
was some HW error.
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-05-23 20:20:48 +08:00
|
|
|
* WQ. If WQ creation succeeds, then the attributes are updated to
|
|
|
|
* the actual capabilities of the created WQ.
|
|
|
|
*
|
2018-01-06 08:21:40 +08:00
|
|
|
* wq_attr->max_wr and wq_attr->max_sge determine
|
IB/core: Introduce Work Queue object and its verbs
Introduce Work Queue object and its create/destroy/modify verbs.
QP can be created without internal WQs "packaged" inside it,
this QP can be configured to use "external" WQ object as its
receive/send queue.
WQ is a necessary component for RSS technology since RSS mechanism
is supposed to distribute the traffic between multiple
Receive Work Queues.
WQ associated (many to one) with Completion Queue and it owns WQ
properties (PD, WQ size, etc.).
WQ has a type, this patch introduces the IB_WQT_RQ (i.e.receive queue),
it may be extend to others such as IB_WQT_SQ. (send queue).
WQ from type IB_WQT_RQ contains receive work requests.
PD is an attribute of a work queue (i.e. send/receive queue), it's used
by the hardware for security validation before scattering to a memory
region which is pointed by the WQ. For that, an external WQ object
needs a PD, letting the hardware makes that validation.
When accessing a memory region that is pointed by the WQ its PD
is used and not the QP's PD, this behavior is similar
to a SRQ and a QP.
WQ context is subject to a well-defined state transitions done by
the modify_wq verb.
When WQ is created its initial state becomes IB_WQS_RESET.
>From IB_WQS_RESET it can be modified to itself or to IB_WQS_RDY.
>From IB_WQS_RDY it can be modified to itself, to IB_WQS_RESET
or to IB_WQS_ERR.
>From IB_WQS_ERR it can be modified to IB_WQS_RESET.
Note: transition to IB_WQS_ERR might occur implicitly in case there
was some HW error.
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-05-23 20:20:48 +08:00
|
|
|
* the requested size of the WQ, and set to the actual values allocated
|
|
|
|
* on return.
|
|
|
|
* If ib_create_wq() succeeds, then max_wr and max_sge will always be
|
|
|
|
* at least as large as the requested values.
|
|
|
|
*/
|
|
|
|
struct ib_wq *ib_create_wq(struct ib_pd *pd,
|
|
|
|
struct ib_wq_init_attr *wq_attr)
|
|
|
|
{
|
|
|
|
struct ib_wq *wq;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!pd->device->ops.create_wq)
|
2018-02-22 00:12:44 +08:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
IB/core: Introduce Work Queue object and its verbs
Introduce Work Queue object and its create/destroy/modify verbs.
QP can be created without internal WQs "packaged" inside it,
this QP can be configured to use "external" WQ object as its
receive/send queue.
WQ is a necessary component for RSS technology since RSS mechanism
is supposed to distribute the traffic between multiple
Receive Work Queues.
WQ associated (many to one) with Completion Queue and it owns WQ
properties (PD, WQ size, etc.).
WQ has a type, this patch introduces the IB_WQT_RQ (i.e.receive queue),
it may be extend to others such as IB_WQT_SQ. (send queue).
WQ from type IB_WQT_RQ contains receive work requests.
PD is an attribute of a work queue (i.e. send/receive queue), it's used
by the hardware for security validation before scattering to a memory
region which is pointed by the WQ. For that, an external WQ object
needs a PD, letting the hardware makes that validation.
When accessing a memory region that is pointed by the WQ its PD
is used and not the QP's PD, this behavior is similar
to a SRQ and a QP.
WQ context is subject to a well-defined state transitions done by
the modify_wq verb.
When WQ is created its initial state becomes IB_WQS_RESET.
>From IB_WQS_RESET it can be modified to itself or to IB_WQS_RDY.
>From IB_WQS_RDY it can be modified to itself, to IB_WQS_RESET
or to IB_WQS_ERR.
>From IB_WQS_ERR it can be modified to IB_WQS_RESET.
Note: transition to IB_WQS_ERR might occur implicitly in case there
was some HW error.
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-05-23 20:20:48 +08:00
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
wq = pd->device->ops.create_wq(pd, wq_attr, NULL);
|
IB/core: Introduce Work Queue object and its verbs
Introduce Work Queue object and its create/destroy/modify verbs.
QP can be created without internal WQs "packaged" inside it,
this QP can be configured to use "external" WQ object as its
receive/send queue.
WQ is a necessary component for RSS technology since RSS mechanism
is supposed to distribute the traffic between multiple
Receive Work Queues.
WQ associated (many to one) with Completion Queue and it owns WQ
properties (PD, WQ size, etc.).
WQ has a type, this patch introduces the IB_WQT_RQ (i.e.receive queue),
it may be extend to others such as IB_WQT_SQ. (send queue).
WQ from type IB_WQT_RQ contains receive work requests.
PD is an attribute of a work queue (i.e. send/receive queue), it's used
by the hardware for security validation before scattering to a memory
region which is pointed by the WQ. For that, an external WQ object
needs a PD, letting the hardware makes that validation.
When accessing a memory region that is pointed by the WQ its PD
is used and not the QP's PD, this behavior is similar
to a SRQ and a QP.
WQ context is subject to a well-defined state transitions done by
the modify_wq verb.
When WQ is created its initial state becomes IB_WQS_RESET.
>From IB_WQS_RESET it can be modified to itself or to IB_WQS_RDY.
>From IB_WQS_RDY it can be modified to itself, to IB_WQS_RESET
or to IB_WQS_ERR.
>From IB_WQS_ERR it can be modified to IB_WQS_RESET.
Note: transition to IB_WQS_ERR might occur implicitly in case there
was some HW error.
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-05-23 20:20:48 +08:00
|
|
|
if (!IS_ERR(wq)) {
|
|
|
|
wq->event_handler = wq_attr->event_handler;
|
|
|
|
wq->wq_context = wq_attr->wq_context;
|
|
|
|
wq->wq_type = wq_attr->wq_type;
|
|
|
|
wq->cq = wq_attr->cq;
|
|
|
|
wq->device = pd->device;
|
|
|
|
wq->pd = pd;
|
|
|
|
wq->uobject = NULL;
|
|
|
|
atomic_inc(&pd->usecnt);
|
|
|
|
atomic_inc(&wq_attr->cq->usecnt);
|
|
|
|
atomic_set(&wq->usecnt, 0);
|
|
|
|
}
|
|
|
|
return wq;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_create_wq);
|
|
|
|
|
|
|
|
/**
|
2019-04-01 00:10:05 +08:00
|
|
|
* ib_destroy_wq - Destroys the specified user WQ.
|
IB/core: Introduce Work Queue object and its verbs
Introduce Work Queue object and its create/destroy/modify verbs.
QP can be created without internal WQs "packaged" inside it,
this QP can be configured to use "external" WQ object as its
receive/send queue.
WQ is a necessary component for RSS technology since RSS mechanism
is supposed to distribute the traffic between multiple
Receive Work Queues.
WQ associated (many to one) with Completion Queue and it owns WQ
properties (PD, WQ size, etc.).
WQ has a type, this patch introduces the IB_WQT_RQ (i.e.receive queue),
it may be extend to others such as IB_WQT_SQ. (send queue).
WQ from type IB_WQT_RQ contains receive work requests.
PD is an attribute of a work queue (i.e. send/receive queue), it's used
by the hardware for security validation before scattering to a memory
region which is pointed by the WQ. For that, an external WQ object
needs a PD, letting the hardware makes that validation.
When accessing a memory region that is pointed by the WQ its PD
is used and not the QP's PD, this behavior is similar
to a SRQ and a QP.
WQ context is subject to a well-defined state transitions done by
the modify_wq verb.
When WQ is created its initial state becomes IB_WQS_RESET.
>From IB_WQS_RESET it can be modified to itself or to IB_WQS_RDY.
>From IB_WQS_RDY it can be modified to itself, to IB_WQS_RESET
or to IB_WQS_ERR.
>From IB_WQS_ERR it can be modified to IB_WQS_RESET.
Note: transition to IB_WQS_ERR might occur implicitly in case there
was some HW error.
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-05-23 20:20:48 +08:00
|
|
|
* @wq: The WQ to destroy.
|
2019-04-01 00:10:05 +08:00
|
|
|
* @udata: Valid user data
|
IB/core: Introduce Work Queue object and its verbs
Introduce Work Queue object and its create/destroy/modify verbs.
QP can be created without internal WQs "packaged" inside it,
this QP can be configured to use "external" WQ object as its
receive/send queue.
WQ is a necessary component for RSS technology since RSS mechanism
is supposed to distribute the traffic between multiple
Receive Work Queues.
WQ associated (many to one) with Completion Queue and it owns WQ
properties (PD, WQ size, etc.).
WQ has a type, this patch introduces the IB_WQT_RQ (i.e.receive queue),
it may be extend to others such as IB_WQT_SQ. (send queue).
WQ from type IB_WQT_RQ contains receive work requests.
PD is an attribute of a work queue (i.e. send/receive queue), it's used
by the hardware for security validation before scattering to a memory
region which is pointed by the WQ. For that, an external WQ object
needs a PD, letting the hardware makes that validation.
When accessing a memory region that is pointed by the WQ its PD
is used and not the QP's PD, this behavior is similar
to a SRQ and a QP.
WQ context is subject to a well-defined state transitions done by
the modify_wq verb.
When WQ is created its initial state becomes IB_WQS_RESET.
>From IB_WQS_RESET it can be modified to itself or to IB_WQS_RDY.
>From IB_WQS_RDY it can be modified to itself, to IB_WQS_RESET
or to IB_WQS_ERR.
>From IB_WQS_ERR it can be modified to IB_WQS_RESET.
Note: transition to IB_WQS_ERR might occur implicitly in case there
was some HW error.
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-05-23 20:20:48 +08:00
|
|
|
*/
|
2019-04-01 00:10:05 +08:00
|
|
|
int ib_destroy_wq(struct ib_wq *wq, struct ib_udata *udata)
|
IB/core: Introduce Work Queue object and its verbs
Introduce Work Queue object and its create/destroy/modify verbs.
QP can be created without internal WQs "packaged" inside it,
this QP can be configured to use "external" WQ object as its
receive/send queue.
WQ is a necessary component for RSS technology since RSS mechanism
is supposed to distribute the traffic between multiple
Receive Work Queues.
WQ associated (many to one) with Completion Queue and it owns WQ
properties (PD, WQ size, etc.).
WQ has a type, this patch introduces the IB_WQT_RQ (i.e.receive queue),
it may be extend to others such as IB_WQT_SQ. (send queue).
WQ from type IB_WQT_RQ contains receive work requests.
PD is an attribute of a work queue (i.e. send/receive queue), it's used
by the hardware for security validation before scattering to a memory
region which is pointed by the WQ. For that, an external WQ object
needs a PD, letting the hardware makes that validation.
When accessing a memory region that is pointed by the WQ its PD
is used and not the QP's PD, this behavior is similar
to a SRQ and a QP.
WQ context is subject to a well-defined state transitions done by
the modify_wq verb.
When WQ is created its initial state becomes IB_WQS_RESET.
>From IB_WQS_RESET it can be modified to itself or to IB_WQS_RDY.
>From IB_WQS_RDY it can be modified to itself, to IB_WQS_RESET
or to IB_WQS_ERR.
>From IB_WQS_ERR it can be modified to IB_WQS_RESET.
Note: transition to IB_WQS_ERR might occur implicitly in case there
was some HW error.
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-05-23 20:20:48 +08:00
|
|
|
{
|
|
|
|
struct ib_cq *cq = wq->cq;
|
|
|
|
struct ib_pd *pd = wq->pd;
|
|
|
|
|
|
|
|
if (atomic_read(&wq->usecnt))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2019-06-12 20:27:41 +08:00
|
|
|
wq->device->ops.destroy_wq(wq, udata);
|
|
|
|
atomic_dec(&pd->usecnt);
|
|
|
|
atomic_dec(&cq->usecnt);
|
|
|
|
|
|
|
|
return 0;
|
IB/core: Introduce Work Queue object and its verbs
Introduce Work Queue object and its create/destroy/modify verbs.
QP can be created without internal WQs "packaged" inside it,
this QP can be configured to use "external" WQ object as its
receive/send queue.
WQ is a necessary component for RSS technology since RSS mechanism
is supposed to distribute the traffic between multiple
Receive Work Queues.
WQ associated (many to one) with Completion Queue and it owns WQ
properties (PD, WQ size, etc.).
WQ has a type, this patch introduces the IB_WQT_RQ (i.e.receive queue),
it may be extend to others such as IB_WQT_SQ. (send queue).
WQ from type IB_WQT_RQ contains receive work requests.
PD is an attribute of a work queue (i.e. send/receive queue), it's used
by the hardware for security validation before scattering to a memory
region which is pointed by the WQ. For that, an external WQ object
needs a PD, letting the hardware makes that validation.
When accessing a memory region that is pointed by the WQ its PD
is used and not the QP's PD, this behavior is similar
to a SRQ and a QP.
WQ context is subject to a well-defined state transitions done by
the modify_wq verb.
When WQ is created its initial state becomes IB_WQS_RESET.
>From IB_WQS_RESET it can be modified to itself or to IB_WQS_RDY.
>From IB_WQS_RDY it can be modified to itself, to IB_WQS_RESET
or to IB_WQS_ERR.
>From IB_WQS_ERR it can be modified to IB_WQS_RESET.
Note: transition to IB_WQS_ERR might occur implicitly in case there
was some HW error.
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-05-23 20:20:48 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_destroy_wq);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ib_modify_wq - Modifies the specified WQ.
|
|
|
|
* @wq: The WQ to modify.
|
|
|
|
* @wq_attr: On input, specifies the WQ attributes to modify.
|
|
|
|
* @wq_attr_mask: A bit-mask used to specify which attributes of the WQ
|
|
|
|
* are being modified.
|
|
|
|
* On output, the current values of selected WQ attributes are returned.
|
|
|
|
*/
|
|
|
|
int ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr,
|
|
|
|
u32 wq_attr_mask)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!wq->device->ops.modify_wq)
|
2018-02-22 00:12:44 +08:00
|
|
|
return -EOPNOTSUPP;
|
IB/core: Introduce Work Queue object and its verbs
Introduce Work Queue object and its create/destroy/modify verbs.
QP can be created without internal WQs "packaged" inside it,
this QP can be configured to use "external" WQ object as its
receive/send queue.
WQ is a necessary component for RSS technology since RSS mechanism
is supposed to distribute the traffic between multiple
Receive Work Queues.
WQ associated (many to one) with Completion Queue and it owns WQ
properties (PD, WQ size, etc.).
WQ has a type, this patch introduces the IB_WQT_RQ (i.e.receive queue),
it may be extend to others such as IB_WQT_SQ. (send queue).
WQ from type IB_WQT_RQ contains receive work requests.
PD is an attribute of a work queue (i.e. send/receive queue), it's used
by the hardware for security validation before scattering to a memory
region which is pointed by the WQ. For that, an external WQ object
needs a PD, letting the hardware makes that validation.
When accessing a memory region that is pointed by the WQ its PD
is used and not the QP's PD, this behavior is similar
to a SRQ and a QP.
WQ context is subject to a well-defined state transitions done by
the modify_wq verb.
When WQ is created its initial state becomes IB_WQS_RESET.
>From IB_WQS_RESET it can be modified to itself or to IB_WQS_RDY.
>From IB_WQS_RDY it can be modified to itself, to IB_WQS_RESET
or to IB_WQS_ERR.
>From IB_WQS_ERR it can be modified to IB_WQS_RESET.
Note: transition to IB_WQS_ERR might occur implicitly in case there
was some HW error.
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-05-23 20:20:48 +08:00
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
err = wq->device->ops.modify_wq(wq, wq_attr, wq_attr_mask, NULL);
|
IB/core: Introduce Work Queue object and its verbs
Introduce Work Queue object and its create/destroy/modify verbs.
QP can be created without internal WQs "packaged" inside it,
this QP can be configured to use "external" WQ object as its
receive/send queue.
WQ is a necessary component for RSS technology since RSS mechanism
is supposed to distribute the traffic between multiple
Receive Work Queues.
WQ associated (many to one) with Completion Queue and it owns WQ
properties (PD, WQ size, etc.).
WQ has a type, this patch introduces the IB_WQT_RQ (i.e.receive queue),
it may be extend to others such as IB_WQT_SQ. (send queue).
WQ from type IB_WQT_RQ contains receive work requests.
PD is an attribute of a work queue (i.e. send/receive queue), it's used
by the hardware for security validation before scattering to a memory
region which is pointed by the WQ. For that, an external WQ object
needs a PD, letting the hardware makes that validation.
When accessing a memory region that is pointed by the WQ its PD
is used and not the QP's PD, this behavior is similar
to a SRQ and a QP.
WQ context is subject to a well-defined state transitions done by
the modify_wq verb.
When WQ is created its initial state becomes IB_WQS_RESET.
>From IB_WQS_RESET it can be modified to itself or to IB_WQS_RDY.
>From IB_WQS_RDY it can be modified to itself, to IB_WQS_RESET
or to IB_WQS_ERR.
>From IB_WQS_ERR it can be modified to IB_WQS_RESET.
Note: transition to IB_WQS_ERR might occur implicitly in case there
was some HW error.
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-05-23 20:20:48 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_modify_wq);
|
|
|
|
|
2016-05-23 20:20:51 +08:00
|
|
|
/*
|
|
|
|
* ib_create_rwq_ind_table - Creates a RQ Indirection Table.
|
|
|
|
* @device: The device on which to create the rwq indirection table.
|
|
|
|
* @ib_rwq_ind_table_init_attr: A list of initial attributes required to
|
|
|
|
* create the Indirection Table.
|
|
|
|
*
|
|
|
|
* Note: The life time of ib_rwq_ind_table_init_attr->ind_tbl is not less
|
|
|
|
* than the created ib_rwq_ind_table object and the caller is responsible
|
|
|
|
* for its memory allocation/free.
|
|
|
|
*/
|
|
|
|
struct ib_rwq_ind_table *ib_create_rwq_ind_table(struct ib_device *device,
|
|
|
|
struct ib_rwq_ind_table_init_attr *init_attr)
|
|
|
|
{
|
|
|
|
struct ib_rwq_ind_table *rwq_ind_table;
|
|
|
|
int i;
|
|
|
|
u32 table_size;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!device->ops.create_rwq_ind_table)
|
2018-02-22 00:12:44 +08:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
2016-05-23 20:20:51 +08:00
|
|
|
|
|
|
|
table_size = (1 << init_attr->log_ind_tbl_size);
|
2018-12-11 03:09:48 +08:00
|
|
|
rwq_ind_table = device->ops.create_rwq_ind_table(device,
|
|
|
|
init_attr, NULL);
|
2016-05-23 20:20:51 +08:00
|
|
|
if (IS_ERR(rwq_ind_table))
|
|
|
|
return rwq_ind_table;
|
|
|
|
|
|
|
|
rwq_ind_table->ind_tbl = init_attr->ind_tbl;
|
|
|
|
rwq_ind_table->log_ind_tbl_size = init_attr->log_ind_tbl_size;
|
|
|
|
rwq_ind_table->device = device;
|
|
|
|
rwq_ind_table->uobject = NULL;
|
|
|
|
atomic_set(&rwq_ind_table->usecnt, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < table_size; i++)
|
|
|
|
atomic_inc(&rwq_ind_table->ind_tbl[i]->usecnt);
|
|
|
|
|
|
|
|
return rwq_ind_table;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_create_rwq_ind_table);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ib_destroy_rwq_ind_table - Destroys the specified Indirection Table.
|
|
|
|
* @wq_ind_table: The Indirection Table to destroy.
|
|
|
|
*/
|
|
|
|
int ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *rwq_ind_table)
|
|
|
|
{
|
|
|
|
int err, i;
|
|
|
|
u32 table_size = (1 << rwq_ind_table->log_ind_tbl_size);
|
|
|
|
struct ib_wq **ind_tbl = rwq_ind_table->ind_tbl;
|
|
|
|
|
|
|
|
if (atomic_read(&rwq_ind_table->usecnt))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
err = rwq_ind_table->device->ops.destroy_rwq_ind_table(rwq_ind_table);
|
2016-05-23 20:20:51 +08:00
|
|
|
if (!err) {
|
|
|
|
for (i = 0; i < table_size; i++)
|
|
|
|
atomic_dec(&ind_tbl[i]->usecnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_destroy_rwq_ind_table);
|
|
|
|
|
2014-02-23 20:19:05 +08:00
|
|
|
int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
|
|
|
|
struct ib_mr_status *mr_status)
|
|
|
|
{
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!mr->device->ops.check_mr_status)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
return mr->device->ops.check_mr_status(mr, check_mask, mr_status);
|
2014-02-23 20:19:05 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_check_mr_status);
|
2015-10-14 00:11:24 +08:00
|
|
|
|
2016-03-12 04:58:38 +08:00
|
|
|
int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
|
|
|
|
int state)
|
|
|
|
{
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!device->ops.set_vf_link_state)
|
2018-02-22 00:12:44 +08:00
|
|
|
return -EOPNOTSUPP;
|
2016-03-12 04:58:38 +08:00
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
return device->ops.set_vf_link_state(device, vf, port, state);
|
2016-03-12 04:58:38 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_set_vf_link_state);
|
|
|
|
|
|
|
|
int ib_get_vf_config(struct ib_device *device, int vf, u8 port,
|
|
|
|
struct ifla_vf_info *info)
|
|
|
|
{
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!device->ops.get_vf_config)
|
2018-02-22 00:12:44 +08:00
|
|
|
return -EOPNOTSUPP;
|
2016-03-12 04:58:38 +08:00
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
return device->ops.get_vf_config(device, vf, port, info);
|
2016-03-12 04:58:38 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_get_vf_config);
|
|
|
|
|
|
|
|
int ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
|
|
|
|
struct ifla_vf_stats *stats)
|
|
|
|
{
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!device->ops.get_vf_stats)
|
2018-02-22 00:12:44 +08:00
|
|
|
return -EOPNOTSUPP;
|
2016-03-12 04:58:38 +08:00
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
return device->ops.get_vf_stats(device, vf, port, stats);
|
2016-03-12 04:58:38 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_get_vf_stats);
|
|
|
|
|
|
|
|
int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
|
|
|
|
int type)
|
|
|
|
{
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!device->ops.set_vf_guid)
|
2018-02-22 00:12:44 +08:00
|
|
|
return -EOPNOTSUPP;
|
2016-03-12 04:58:38 +08:00
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
return device->ops.set_vf_guid(device, vf, port, guid, type);
|
2016-03-12 04:58:38 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_set_vf_guid);
|
|
|
|
|
2019-11-06 21:08:32 +08:00
|
|
|
int ib_get_vf_guid(struct ib_device *device, int vf, u8 port,
|
|
|
|
struct ifla_vf_guid *node_guid,
|
|
|
|
struct ifla_vf_guid *port_guid)
|
|
|
|
{
|
|
|
|
if (!device->ops.get_vf_guid)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
return device->ops.get_vf_guid(device, vf, port, node_guid, port_guid);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_get_vf_guid);
|
2019-06-11 23:52:40 +08:00
|
|
|
/**
|
|
|
|
* ib_map_mr_sg_pi() - Map the dma mapped SG lists for PI (protection
|
|
|
|
* information) and set an appropriate memory region for registration.
|
|
|
|
* @mr: memory region
|
|
|
|
* @data_sg: dma mapped scatterlist for data
|
|
|
|
* @data_sg_nents: number of entries in data_sg
|
|
|
|
* @data_sg_offset: offset in bytes into data_sg
|
|
|
|
* @meta_sg: dma mapped scatterlist for metadata
|
|
|
|
* @meta_sg_nents: number of entries in meta_sg
|
|
|
|
* @meta_sg_offset: offset in bytes into meta_sg
|
|
|
|
* @page_size: page vector desired page size
|
|
|
|
*
|
|
|
|
* Constraints:
|
|
|
|
* - The MR must be allocated with type IB_MR_TYPE_INTEGRITY.
|
|
|
|
*
|
|
|
|
* Return: 0 on success.
|
|
|
|
*
|
|
|
|
* After this completes successfully, the memory region
|
|
|
|
* is ready for registration.
|
|
|
|
*/
|
|
|
|
int ib_map_mr_sg_pi(struct ib_mr *mr, struct scatterlist *data_sg,
|
|
|
|
int data_sg_nents, unsigned int *data_sg_offset,
|
|
|
|
struct scatterlist *meta_sg, int meta_sg_nents,
|
|
|
|
unsigned int *meta_sg_offset, unsigned int page_size)
|
|
|
|
{
|
|
|
|
if (unlikely(!mr->device->ops.map_mr_sg_pi ||
|
|
|
|
WARN_ON_ONCE(mr->type != IB_MR_TYPE_INTEGRITY)))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
mr->page_size = page_size;
|
|
|
|
|
|
|
|
return mr->device->ops.map_mr_sg_pi(mr, data_sg, data_sg_nents,
|
|
|
|
data_sg_offset, meta_sg,
|
|
|
|
meta_sg_nents, meta_sg_offset);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_map_mr_sg_pi);
|
|
|
|
|
2015-10-14 00:11:24 +08:00
|
|
|
/**
|
|
|
|
* ib_map_mr_sg() - Map the largest prefix of a dma mapped SG list
|
|
|
|
* and set it the memory region.
|
|
|
|
* @mr: memory region
|
|
|
|
* @sg: dma mapped scatterlist
|
|
|
|
* @sg_nents: number of entries in sg
|
2016-05-04 00:01:04 +08:00
|
|
|
* @sg_offset: offset in bytes into sg
|
2015-10-14 00:11:24 +08:00
|
|
|
* @page_size: page vector desired page size
|
|
|
|
*
|
|
|
|
* Constraints:
|
|
|
|
* - The first sg element is allowed to have an offset.
|
2016-09-27 00:09:42 +08:00
|
|
|
* - Each sg element must either be aligned to page_size or virtually
|
|
|
|
* contiguous to the previous element. In case an sg element has a
|
|
|
|
* non-contiguous offset, the mapping prefix will not include it.
|
2015-10-14 00:11:24 +08:00
|
|
|
* - The last sg element is allowed to have length less than page_size.
|
|
|
|
* - If sg_nents total byte length exceeds the mr max_num_sge * page_size
|
|
|
|
* then only max_num_sg entries will be mapped.
|
2016-09-27 00:09:42 +08:00
|
|
|
* - If the MR was allocated with type IB_MR_TYPE_SG_GAPS, none of these
|
2016-03-01 01:07:32 +08:00
|
|
|
* constraints holds and the page_size argument is ignored.
|
2015-10-14 00:11:24 +08:00
|
|
|
*
|
|
|
|
* Returns the number of sg elements that were mapped to the memory region.
|
|
|
|
*
|
|
|
|
* After this completes successfully, the memory region
|
|
|
|
* is ready for registration.
|
|
|
|
*/
|
2016-05-04 00:01:04 +08:00
|
|
|
int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
|
2016-05-13 01:49:15 +08:00
|
|
|
unsigned int *sg_offset, unsigned int page_size)
|
2015-10-14 00:11:24 +08:00
|
|
|
{
|
2018-12-11 03:09:48 +08:00
|
|
|
if (unlikely(!mr->device->ops.map_mr_sg))
|
2018-02-22 00:12:44 +08:00
|
|
|
return -EOPNOTSUPP;
|
2015-10-14 00:11:24 +08:00
|
|
|
|
|
|
|
mr->page_size = page_size;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
return mr->device->ops.map_mr_sg(mr, sg, sg_nents, sg_offset);
|
2015-10-14 00:11:24 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_map_mr_sg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ib_sg_to_pages() - Convert the largest prefix of a sg list
|
|
|
|
* to a page vector
|
|
|
|
* @mr: memory region
|
|
|
|
* @sgl: dma mapped scatterlist
|
|
|
|
* @sg_nents: number of entries in sg
|
2016-05-13 01:49:15 +08:00
|
|
|
* @sg_offset_p: IN: start offset in bytes into sg
|
|
|
|
* OUT: offset in bytes for element n of the sg of the first
|
|
|
|
* byte that has not been processed where n is the return
|
|
|
|
* value of this function.
|
2015-10-14 00:11:24 +08:00
|
|
|
* @set_page: driver page assignment function pointer
|
|
|
|
*
|
2015-12-04 08:04:17 +08:00
|
|
|
* Core service helper for drivers to convert the largest
|
2015-10-14 00:11:24 +08:00
|
|
|
* prefix of given sg list to a page vector. The sg list
|
|
|
|
* prefix converted is the prefix that meet the requirements
|
|
|
|
* of ib_map_mr_sg.
|
|
|
|
*
|
|
|
|
* Returns the number of sg elements that were assigned to
|
|
|
|
* a page vector.
|
|
|
|
*/
|
2016-05-04 00:01:04 +08:00
|
|
|
int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents,
|
2016-05-13 01:49:15 +08:00
|
|
|
unsigned int *sg_offset_p, int (*set_page)(struct ib_mr *, u64))
|
2015-10-14 00:11:24 +08:00
|
|
|
{
|
|
|
|
struct scatterlist *sg;
|
2015-12-29 17:45:03 +08:00
|
|
|
u64 last_end_dma_addr = 0;
|
2016-05-13 01:49:15 +08:00
|
|
|
unsigned int sg_offset = sg_offset_p ? *sg_offset_p : 0;
|
2015-10-14 00:11:24 +08:00
|
|
|
unsigned int last_page_off = 0;
|
|
|
|
u64 page_mask = ~((u64)mr->page_size - 1);
|
2015-12-04 08:04:17 +08:00
|
|
|
int i, ret;
|
2015-10-14 00:11:24 +08:00
|
|
|
|
2016-05-13 01:49:15 +08:00
|
|
|
if (unlikely(sg_nents <= 0 || sg_offset > sg_dma_len(&sgl[0])))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-05-04 00:01:04 +08:00
|
|
|
mr->iova = sg_dma_address(&sgl[0]) + sg_offset;
|
2015-10-14 00:11:24 +08:00
|
|
|
mr->length = 0;
|
|
|
|
|
|
|
|
for_each_sg(sgl, sg, sg_nents, i) {
|
2016-05-04 00:01:04 +08:00
|
|
|
u64 dma_addr = sg_dma_address(sg) + sg_offset;
|
2016-05-13 01:49:15 +08:00
|
|
|
u64 prev_addr = dma_addr;
|
2016-05-04 00:01:04 +08:00
|
|
|
unsigned int dma_len = sg_dma_len(sg) - sg_offset;
|
2015-10-14 00:11:24 +08:00
|
|
|
u64 end_dma_addr = dma_addr + dma_len;
|
|
|
|
u64 page_addr = dma_addr & page_mask;
|
|
|
|
|
2015-12-04 08:04:17 +08:00
|
|
|
/*
|
|
|
|
* For the second and later elements, check whether either the
|
|
|
|
* end of element i-1 or the start of element i is not aligned
|
|
|
|
* on a page boundary.
|
|
|
|
*/
|
|
|
|
if (i && (last_page_off != 0 || page_addr != dma_addr)) {
|
|
|
|
/* Stop mapping if there is a gap. */
|
|
|
|
if (last_end_dma_addr != dma_addr)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Coalesce this element with the last. If it is small
|
|
|
|
* enough just update mr->length. Otherwise start
|
|
|
|
* mapping from the next page.
|
|
|
|
*/
|
|
|
|
goto next_page;
|
2015-10-14 00:11:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2015-12-04 08:04:17 +08:00
|
|
|
ret = set_page(mr, page_addr);
|
2016-05-13 01:49:15 +08:00
|
|
|
if (unlikely(ret < 0)) {
|
|
|
|
sg_offset = prev_addr - sg_dma_address(sg);
|
|
|
|
mr->length += prev_addr - dma_addr;
|
|
|
|
if (sg_offset_p)
|
|
|
|
*sg_offset_p = sg_offset;
|
|
|
|
return i || sg_offset ? i : ret;
|
|
|
|
}
|
|
|
|
prev_addr = page_addr;
|
2015-12-04 08:04:17 +08:00
|
|
|
next_page:
|
2015-10-14 00:11:24 +08:00
|
|
|
page_addr += mr->page_size;
|
|
|
|
} while (page_addr < end_dma_addr);
|
|
|
|
|
|
|
|
mr->length += dma_len;
|
|
|
|
last_end_dma_addr = end_dma_addr;
|
|
|
|
last_page_off = end_dma_addr & ~page_mask;
|
2016-05-04 00:01:04 +08:00
|
|
|
|
|
|
|
sg_offset = 0;
|
2015-10-14 00:11:24 +08:00
|
|
|
}
|
|
|
|
|
2016-05-13 01:49:15 +08:00
|
|
|
if (sg_offset_p)
|
|
|
|
*sg_offset_p = 0;
|
2015-10-14 00:11:24 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_sg_to_pages);
|
2016-02-18 00:15:41 +08:00
|
|
|
|
|
|
|
struct ib_drain_cqe {
|
|
|
|
struct ib_cqe cqe;
|
|
|
|
struct completion done;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ib_drain_qp_done(struct ib_cq *cq, struct ib_wc *wc)
|
|
|
|
{
|
|
|
|
struct ib_drain_cqe *cqe = container_of(wc->wr_cqe, struct ib_drain_cqe,
|
|
|
|
cqe);
|
|
|
|
|
|
|
|
complete(&cqe->done);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Post a WR and block until its completion is reaped for the SQ.
|
|
|
|
*/
|
|
|
|
static void __ib_drain_sq(struct ib_qp *qp)
|
|
|
|
{
|
2017-02-15 02:56:35 +08:00
|
|
|
struct ib_cq *cq = qp->send_cq;
|
2016-02-18 00:15:41 +08:00
|
|
|
struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR };
|
|
|
|
struct ib_drain_cqe sdrain;
|
2018-03-02 06:00:28 +08:00
|
|
|
struct ib_rdma_wr swr = {
|
|
|
|
.wr = {
|
2018-03-14 05:51:57 +08:00
|
|
|
.next = NULL,
|
|
|
|
{ .wr_cqe = &sdrain.cqe, },
|
2018-03-02 06:00:28 +08:00
|
|
|
.opcode = IB_WR_RDMA_WRITE,
|
|
|
|
},
|
|
|
|
};
|
2016-02-18 00:15:41 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ib_modify_qp(qp, &attr, IB_QP_STATE);
|
|
|
|
if (ret) {
|
|
|
|
WARN_ONCE(ret, "failed to drain send queue: %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-14 23:07:48 +08:00
|
|
|
sdrain.cqe.done = ib_drain_qp_done;
|
|
|
|
init_completion(&sdrain.done);
|
|
|
|
|
2018-07-19 00:25:17 +08:00
|
|
|
ret = ib_post_send(qp, &swr.wr, NULL);
|
2016-02-18 00:15:41 +08:00
|
|
|
if (ret) {
|
|
|
|
WARN_ONCE(ret, "failed to drain send queue: %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-15 02:56:35 +08:00
|
|
|
if (cq->poll_ctx == IB_POLL_DIRECT)
|
|
|
|
while (wait_for_completion_timeout(&sdrain.done, HZ / 10) <= 0)
|
|
|
|
ib_process_cq_direct(cq, -1);
|
|
|
|
else
|
|
|
|
wait_for_completion(&sdrain.done);
|
2016-02-18 00:15:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Post a WR and block until its completion is reaped for the RQ.
|
|
|
|
*/
|
|
|
|
static void __ib_drain_rq(struct ib_qp *qp)
|
|
|
|
{
|
2017-02-15 02:56:35 +08:00
|
|
|
struct ib_cq *cq = qp->recv_cq;
|
2016-02-18 00:15:41 +08:00
|
|
|
struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR };
|
|
|
|
struct ib_drain_cqe rdrain;
|
2018-07-19 00:25:17 +08:00
|
|
|
struct ib_recv_wr rwr = {};
|
2016-02-18 00:15:41 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ib_modify_qp(qp, &attr, IB_QP_STATE);
|
|
|
|
if (ret) {
|
|
|
|
WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-14 23:07:48 +08:00
|
|
|
rwr.wr_cqe = &rdrain.cqe;
|
|
|
|
rdrain.cqe.done = ib_drain_qp_done;
|
|
|
|
init_completion(&rdrain.done);
|
|
|
|
|
2018-07-19 00:25:17 +08:00
|
|
|
ret = ib_post_recv(qp, &rwr, NULL);
|
2016-02-18 00:15:41 +08:00
|
|
|
if (ret) {
|
|
|
|
WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-15 02:56:35 +08:00
|
|
|
if (cq->poll_ctx == IB_POLL_DIRECT)
|
|
|
|
while (wait_for_completion_timeout(&rdrain.done, HZ / 10) <= 0)
|
|
|
|
ib_process_cq_direct(cq, -1);
|
|
|
|
else
|
|
|
|
wait_for_completion(&rdrain.done);
|
2016-02-18 00:15:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ib_drain_sq() - Block until all SQ CQEs have been consumed by the
|
|
|
|
* application.
|
|
|
|
* @qp: queue pair to drain
|
|
|
|
*
|
|
|
|
* If the device has a provider-specific drain function, then
|
|
|
|
* call that. Otherwise call the generic drain function
|
|
|
|
* __ib_drain_sq().
|
|
|
|
*
|
|
|
|
* The caller must:
|
|
|
|
*
|
|
|
|
* ensure there is room in the CQ and SQ for the drain work request and
|
|
|
|
* completion.
|
|
|
|
*
|
2017-02-15 02:56:35 +08:00
|
|
|
* allocate the CQ using ib_alloc_cq().
|
2016-02-18 00:15:41 +08:00
|
|
|
*
|
|
|
|
* ensure that there are no other contexts that are posting WRs concurrently.
|
|
|
|
* Otherwise the drain is not guaranteed.
|
|
|
|
*/
|
|
|
|
void ib_drain_sq(struct ib_qp *qp)
|
|
|
|
{
|
2018-12-11 03:09:48 +08:00
|
|
|
if (qp->device->ops.drain_sq)
|
|
|
|
qp->device->ops.drain_sq(qp);
|
2016-02-18 00:15:41 +08:00
|
|
|
else
|
|
|
|
__ib_drain_sq(qp);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_drain_sq);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ib_drain_rq() - Block until all RQ CQEs have been consumed by the
|
|
|
|
* application.
|
|
|
|
* @qp: queue pair to drain
|
|
|
|
*
|
|
|
|
* If the device has a provider-specific drain function, then
|
|
|
|
* call that. Otherwise call the generic drain function
|
|
|
|
* __ib_drain_rq().
|
|
|
|
*
|
|
|
|
* The caller must:
|
|
|
|
*
|
|
|
|
* ensure there is room in the CQ and RQ for the drain work request and
|
|
|
|
* completion.
|
|
|
|
*
|
2017-02-15 02:56:35 +08:00
|
|
|
* allocate the CQ using ib_alloc_cq().
|
2016-02-18 00:15:41 +08:00
|
|
|
*
|
|
|
|
* ensure that there are no other contexts that are posting WRs concurrently.
|
|
|
|
* Otherwise the drain is not guaranteed.
|
|
|
|
*/
|
|
|
|
void ib_drain_rq(struct ib_qp *qp)
|
|
|
|
{
|
2018-12-11 03:09:48 +08:00
|
|
|
if (qp->device->ops.drain_rq)
|
|
|
|
qp->device->ops.drain_rq(qp);
|
2016-02-18 00:15:41 +08:00
|
|
|
else
|
|
|
|
__ib_drain_rq(qp);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_drain_rq);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ib_drain_qp() - Block until all CQEs have been consumed by the
|
|
|
|
* application on both the RQ and SQ.
|
|
|
|
* @qp: queue pair to drain
|
|
|
|
*
|
|
|
|
* The caller must:
|
|
|
|
*
|
|
|
|
* ensure there is room in the CQ(s), SQ, and RQ for drain work requests
|
|
|
|
* and completions.
|
|
|
|
*
|
2017-02-15 02:56:35 +08:00
|
|
|
* allocate the CQs using ib_alloc_cq().
|
2016-02-18 00:15:41 +08:00
|
|
|
*
|
|
|
|
* ensure that there are no other contexts that are posting WRs concurrently.
|
|
|
|
* Otherwise the drain is not guaranteed.
|
|
|
|
*/
|
|
|
|
void ib_drain_qp(struct ib_qp *qp)
|
|
|
|
{
|
|
|
|
ib_drain_sq(qp);
|
2016-04-26 22:55:38 +08:00
|
|
|
if (!qp->srq)
|
|
|
|
ib_drain_rq(qp);
|
2016-02-18 00:15:41 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_drain_qp);
|
2018-08-14 19:08:51 +08:00
|
|
|
|
|
|
|
struct net_device *rdma_alloc_netdev(struct ib_device *device, u8 port_num,
|
|
|
|
enum rdma_netdev_t type, const char *name,
|
|
|
|
unsigned char name_assign_type,
|
|
|
|
void (*setup)(struct net_device *))
|
|
|
|
{
|
|
|
|
struct rdma_netdev_alloc_params params;
|
|
|
|
struct net_device *netdev;
|
|
|
|
int rc;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!device->ops.rdma_netdev_get_params)
|
2018-08-14 19:08:51 +08:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
rc = device->ops.rdma_netdev_get_params(device, port_num, type,
|
|
|
|
¶ms);
|
2018-08-14 19:08:51 +08:00
|
|
|
if (rc)
|
|
|
|
return ERR_PTR(rc);
|
|
|
|
|
|
|
|
netdev = alloc_netdev_mqs(params.sizeof_priv, name, name_assign_type,
|
|
|
|
setup, params.txqs, params.rxqs);
|
|
|
|
if (!netdev)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
return netdev;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(rdma_alloc_netdev);
|
2018-08-14 19:22:35 +08:00
|
|
|
|
|
|
|
int rdma_init_netdev(struct ib_device *device, u8 port_num,
|
|
|
|
enum rdma_netdev_t type, const char *name,
|
|
|
|
unsigned char name_assign_type,
|
|
|
|
void (*setup)(struct net_device *),
|
|
|
|
struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct rdma_netdev_alloc_params params;
|
|
|
|
int rc;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
if (!device->ops.rdma_netdev_get_params)
|
2018-08-14 19:22:35 +08:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2018-12-11 03:09:48 +08:00
|
|
|
rc = device->ops.rdma_netdev_get_params(device, port_num, type,
|
|
|
|
¶ms);
|
2018-08-14 19:22:35 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
return params.initialize_rdma_netdev(device, port_num,
|
|
|
|
netdev, params.param);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(rdma_init_netdev);
|
2019-05-06 21:53:33 +08:00
|
|
|
|
|
|
|
void __rdma_block_iter_start(struct ib_block_iter *biter,
|
|
|
|
struct scatterlist *sglist, unsigned int nents,
|
|
|
|
unsigned long pgsz)
|
|
|
|
{
|
|
|
|
memset(biter, 0, sizeof(struct ib_block_iter));
|
|
|
|
biter->__sg = sglist;
|
|
|
|
biter->__sg_nents = nents;
|
|
|
|
|
|
|
|
/* Driver provides best block size to use */
|
|
|
|
biter->__pg_bit = __fls(pgsz);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__rdma_block_iter_start);
|
|
|
|
|
|
|
|
bool __rdma_block_iter_next(struct ib_block_iter *biter)
|
|
|
|
{
|
|
|
|
unsigned int block_offset;
|
|
|
|
|
|
|
|
if (!biter->__sg_nents || !biter->__sg)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
biter->__dma_addr = sg_dma_address(biter->__sg) + biter->__sg_advance;
|
|
|
|
block_offset = biter->__dma_addr & (BIT_ULL(biter->__pg_bit) - 1);
|
|
|
|
biter->__sg_advance += BIT_ULL(biter->__pg_bit) - block_offset;
|
|
|
|
|
|
|
|
if (biter->__sg_advance >= sg_dma_len(biter->__sg)) {
|
|
|
|
biter->__sg_advance = 0;
|
|
|
|
biter->__sg = sg_next(biter->__sg);
|
|
|
|
biter->__sg_nents--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__rdma_block_iter_next);
|