mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-22 15:22:57 +07:00
cdb73db0b6
Instead of having firmware command functions return an error and also a status, leading to code like: err = mthca_FW_COMMAND(..., &status); if (err) goto out; if (status) { err = -E...; goto out; } all over the place, just handle the FW status inside the FW command handling code (the way mlx4 does it), so we can simply write: err = mthca_FW_COMMAND(...); if (err) goto out; In addition to simplifying the source code, this also saves a healthy chunk of text: add/remove: 0/0 grow/shrink: 10/88 up/down: 510/-3357 (-2847) function old new delta static.trans_table 324 584 +260 mthca_cmd_poll 352 477 +125 mthca_cmd_wait 511 567 +56 mthca_table_put 213 240 +27 mthca_cleanup_db_tab 372 387 +15 __mthca_remove_one 314 323 +9 mthca_cleanup_user_db_tab 275 283 +8 __mthca_init_one 1738 1746 +8 mthca_cleanup 20 21 +1 mthca_MAD_IFC 1081 1082 +1 mthca_MGID_HASH 43 40 -3 mthca_MAP_ICM_AUX 23 20 -3 mthca_MAP_ICM 19 16 -3 mthca_MAP_FA 23 20 -3 mthca_READ_MGM 43 38 -5 mthca_QUERY_SRQ 43 38 -5 mthca_QUERY_QP 59 54 -5 mthca_HW2SW_SRQ 43 38 -5 mthca_HW2SW_MPT 60 55 -5 mthca_HW2SW_EQ 43 38 -5 mthca_HW2SW_CQ 43 38 -5 mthca_free_icm_table 120 114 -6 mthca_query_srq 214 206 -8 mthca_free_qp 662 654 -8 mthca_cmd 38 28 -10 mthca_alloc_db 1321 1311 -10 mthca_setup_hca 1067 1055 -12 mthca_WRITE_MTT 35 22 -13 mthca_WRITE_MGM 40 27 -13 mthca_UNMAP_ICM_AUX 36 23 -13 mthca_UNMAP_FA 36 23 -13 mthca_SYS_DIS 36 23 -13 mthca_SYNC_TPT 36 23 -13 mthca_SW2HW_SRQ 35 22 -13 mthca_SW2HW_MPT 35 22 -13 mthca_SW2HW_EQ 35 22 -13 mthca_SW2HW_CQ 35 22 -13 mthca_RUN_FW 36 23 -13 mthca_DISABLE_LAM 36 23 -13 mthca_CLOSE_IB 36 23 -13 mthca_CLOSE_HCA 38 25 -13 mthca_ARM_SRQ 39 26 -13 mthca_free_icms 178 164 -14 mthca_QUERY_DDR 389 375 -14 mthca_resize_cq 1063 1048 -15 mthca_unmap_eq_icm 123 107 -16 mthca_map_eq_icm 396 380 -16 mthca_cmd_box 90 74 -16 mthca_SET_IB 433 417 -16 mthca_RESIZE_CQ 369 353 -16 mthca_MAP_ICM_page 240 224 -16 mthca_MAP_EQ 183 167 -16 mthca_INIT_IB 473 457 -16 mthca_INIT_HCA 745 729 -16 mthca_map_user_db 816 798 -18 mthca_SYS_EN 157 139 -18 mthca_cleanup_qp_table 78 59 -19 mthca_cleanup_eq_table 168 149 -19 mthca_UNMAP_ICM 143 121 -22 mthca_modify_srq 172 149 -23 mthca_unmap_fmr 198 174 -24 mthca_query_qp 814 790 -24 mthca_query_pkey 343 319 -24 mthca_SET_ICM_SIZE 34 10 -24 mthca_QUERY_DEV_LIM 1870 1846 -24 mthca_map_cmd 1130 1105 -25 mthca_ENABLE_LAM 401 375 -26 mthca_modify_port 247 220 -27 mthca_query_device 884 850 -34 mthca_NOP 75 41 -34 mthca_table_get 287 249 -38 mthca_init_qp_table 333 293 -40 mthca_MODIFY_QP 348 308 -40 mthca_close_hca 131 89 -42 mthca_free_eq 435 390 -45 mthca_query_port 755 705 -50 mthca_free_cq 581 528 -53 mthca_alloc_icm_table 578 524 -54 mthca_multicast_attach 1041 986 -55 mthca_init_hca 326 271 -55 mthca_query_gid 487 431 -56 mthca_free_srq 524 468 -56 mthca_free_mr 168 111 -57 mthca_create_eq 1560 1501 -59 mthca_multicast_detach 790 728 -62 mthca_write_mtt 918 854 -64 mthca_register_device 1406 1342 -64 mthca_fmr_alloc 947 883 -64 mthca_mr_alloc 652 582 -70 mthca_process_mad 1242 1164 -78 mthca_dev_lim 910 830 -80 find_mgm 482 400 -82 mthca_modify_qp 3852 3753 -99 mthca_init_cq 1281 1181 -100 mthca_alloc_srq 1719 1610 -109 mthca_init_eq_table 1807 1679 -128 mthca_init_tavor 761 491 -270 mthca_init_arbel 2617 2098 -519 Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.de>
342 lines
9.8 KiB
C
342 lines
9.8 KiB
C
/*
|
|
* Copyright (c) 2004 Topspin Communications. All rights reserved.
|
|
* Copyright (c) 2005 Mellanox Technologies. All rights reserved.
|
|
* Copyright (c) 2004 Voltaire, Inc. All rights reserved.
|
|
*
|
|
* This software is available to you under a choice of one of two
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
* 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/string.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <rdma/ib_verbs.h>
|
|
#include <rdma/ib_mad.h>
|
|
#include <rdma/ib_smi.h>
|
|
|
|
#include "mthca_dev.h"
|
|
#include "mthca_cmd.h"
|
|
|
|
enum {
|
|
MTHCA_VENDOR_CLASS1 = 0x9,
|
|
MTHCA_VENDOR_CLASS2 = 0xa
|
|
};
|
|
|
|
static int mthca_update_rate(struct mthca_dev *dev, u8 port_num)
|
|
{
|
|
struct ib_port_attr *tprops = NULL;
|
|
int ret;
|
|
|
|
tprops = kmalloc(sizeof *tprops, GFP_KERNEL);
|
|
if (!tprops)
|
|
return -ENOMEM;
|
|
|
|
ret = ib_query_port(&dev->ib_dev, port_num, tprops);
|
|
if (ret) {
|
|
printk(KERN_WARNING "ib_query_port failed (%d) for %s port %d\n",
|
|
ret, dev->ib_dev.name, port_num);
|
|
goto out;
|
|
}
|
|
|
|
dev->rate[port_num - 1] = tprops->active_speed *
|
|
ib_width_enum_to_int(tprops->active_width);
|
|
|
|
out:
|
|
kfree(tprops);
|
|
return ret;
|
|
}
|
|
|
|
static void update_sm_ah(struct mthca_dev *dev,
|
|
u8 port_num, u16 lid, u8 sl)
|
|
{
|
|
struct ib_ah *new_ah;
|
|
struct ib_ah_attr ah_attr;
|
|
unsigned long flags;
|
|
|
|
if (!dev->send_agent[port_num - 1][0])
|
|
return;
|
|
|
|
memset(&ah_attr, 0, sizeof ah_attr);
|
|
ah_attr.dlid = lid;
|
|
ah_attr.sl = sl;
|
|
ah_attr.port_num = port_num;
|
|
|
|
new_ah = ib_create_ah(dev->send_agent[port_num - 1][0]->qp->pd,
|
|
&ah_attr);
|
|
if (IS_ERR(new_ah))
|
|
return;
|
|
|
|
spin_lock_irqsave(&dev->sm_lock, flags);
|
|
if (dev->sm_ah[port_num - 1])
|
|
ib_destroy_ah(dev->sm_ah[port_num - 1]);
|
|
dev->sm_ah[port_num - 1] = new_ah;
|
|
spin_unlock_irqrestore(&dev->sm_lock, flags);
|
|
}
|
|
|
|
/*
|
|
* Snoop SM MADs for port info and P_Key table sets, so we can
|
|
* synthesize LID change and P_Key change events.
|
|
*/
|
|
static void smp_snoop(struct ib_device *ibdev,
|
|
u8 port_num,
|
|
struct ib_mad *mad,
|
|
u16 prev_lid)
|
|
{
|
|
struct ib_event event;
|
|
|
|
if ((mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED ||
|
|
mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) &&
|
|
mad->mad_hdr.method == IB_MGMT_METHOD_SET) {
|
|
if (mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO) {
|
|
struct ib_port_info *pinfo =
|
|
(struct ib_port_info *) ((struct ib_smp *) mad)->data;
|
|
u16 lid = be16_to_cpu(pinfo->lid);
|
|
|
|
mthca_update_rate(to_mdev(ibdev), port_num);
|
|
update_sm_ah(to_mdev(ibdev), port_num,
|
|
be16_to_cpu(pinfo->sm_lid),
|
|
pinfo->neighbormtu_mastersmsl & 0xf);
|
|
|
|
event.device = ibdev;
|
|
event.element.port_num = port_num;
|
|
|
|
if (pinfo->clientrereg_resv_subnetto & 0x80) {
|
|
event.event = IB_EVENT_CLIENT_REREGISTER;
|
|
ib_dispatch_event(&event);
|
|
}
|
|
|
|
if (prev_lid != lid) {
|
|
event.event = IB_EVENT_LID_CHANGE;
|
|
ib_dispatch_event(&event);
|
|
}
|
|
}
|
|
|
|
if (mad->mad_hdr.attr_id == IB_SMP_ATTR_PKEY_TABLE) {
|
|
event.device = ibdev;
|
|
event.event = IB_EVENT_PKEY_CHANGE;
|
|
event.element.port_num = port_num;
|
|
ib_dispatch_event(&event);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void node_desc_override(struct ib_device *dev,
|
|
struct ib_mad *mad)
|
|
{
|
|
if ((mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED ||
|
|
mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) &&
|
|
mad->mad_hdr.method == IB_MGMT_METHOD_GET_RESP &&
|
|
mad->mad_hdr.attr_id == IB_SMP_ATTR_NODE_DESC) {
|
|
mutex_lock(&to_mdev(dev)->cap_mask_mutex);
|
|
memcpy(((struct ib_smp *) mad)->data, dev->node_desc, 64);
|
|
mutex_unlock(&to_mdev(dev)->cap_mask_mutex);
|
|
}
|
|
}
|
|
|
|
static void forward_trap(struct mthca_dev *dev,
|
|
u8 port_num,
|
|
struct ib_mad *mad)
|
|
{
|
|
int qpn = mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED;
|
|
struct ib_mad_send_buf *send_buf;
|
|
struct ib_mad_agent *agent = dev->send_agent[port_num - 1][qpn];
|
|
int ret;
|
|
unsigned long flags;
|
|
|
|
if (agent) {
|
|
send_buf = ib_create_send_mad(agent, qpn, 0, 0, IB_MGMT_MAD_HDR,
|
|
IB_MGMT_MAD_DATA, GFP_ATOMIC);
|
|
if (IS_ERR(send_buf))
|
|
return;
|
|
/*
|
|
* We rely here on the fact that MLX QPs don't use the
|
|
* address handle after the send is posted (this is
|
|
* wrong following the IB spec strictly, but we know
|
|
* it's OK for our devices).
|
|
*/
|
|
spin_lock_irqsave(&dev->sm_lock, flags);
|
|
memcpy(send_buf->mad, mad, sizeof *mad);
|
|
if ((send_buf->ah = dev->sm_ah[port_num - 1]))
|
|
ret = ib_post_send_mad(send_buf, NULL);
|
|
else
|
|
ret = -EINVAL;
|
|
spin_unlock_irqrestore(&dev->sm_lock, flags);
|
|
|
|
if (ret)
|
|
ib_free_send_mad(send_buf);
|
|
}
|
|
}
|
|
|
|
int mthca_process_mad(struct ib_device *ibdev,
|
|
int mad_flags,
|
|
u8 port_num,
|
|
struct ib_wc *in_wc,
|
|
struct ib_grh *in_grh,
|
|
struct ib_mad *in_mad,
|
|
struct ib_mad *out_mad)
|
|
{
|
|
int err;
|
|
u16 slid = in_wc ? in_wc->slid : be16_to_cpu(IB_LID_PERMISSIVE);
|
|
u16 prev_lid = 0;
|
|
struct ib_port_attr pattr;
|
|
|
|
/* Forward locally generated traps to the SM */
|
|
if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP &&
|
|
slid == 0) {
|
|
forward_trap(to_mdev(ibdev), port_num, in_mad);
|
|
return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
|
|
}
|
|
|
|
/*
|
|
* Only handle SM gets, sets and trap represses for SM class
|
|
*
|
|
* Only handle PMA and Mellanox vendor-specific class gets and
|
|
* sets for other classes.
|
|
*/
|
|
if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED ||
|
|
in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
|
|
if (in_mad->mad_hdr.method != IB_MGMT_METHOD_GET &&
|
|
in_mad->mad_hdr.method != IB_MGMT_METHOD_SET &&
|
|
in_mad->mad_hdr.method != IB_MGMT_METHOD_TRAP_REPRESS)
|
|
return IB_MAD_RESULT_SUCCESS;
|
|
|
|
/*
|
|
* Don't process SMInfo queries or vendor-specific
|
|
* MADs -- the SMA can't handle them.
|
|
*/
|
|
if (in_mad->mad_hdr.attr_id == IB_SMP_ATTR_SM_INFO ||
|
|
((in_mad->mad_hdr.attr_id & IB_SMP_ATTR_VENDOR_MASK) ==
|
|
IB_SMP_ATTR_VENDOR_MASK))
|
|
return IB_MAD_RESULT_SUCCESS;
|
|
} else if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT ||
|
|
in_mad->mad_hdr.mgmt_class == MTHCA_VENDOR_CLASS1 ||
|
|
in_mad->mad_hdr.mgmt_class == MTHCA_VENDOR_CLASS2) {
|
|
if (in_mad->mad_hdr.method != IB_MGMT_METHOD_GET &&
|
|
in_mad->mad_hdr.method != IB_MGMT_METHOD_SET)
|
|
return IB_MAD_RESULT_SUCCESS;
|
|
} else
|
|
return IB_MAD_RESULT_SUCCESS;
|
|
if ((in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED ||
|
|
in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) &&
|
|
in_mad->mad_hdr.method == IB_MGMT_METHOD_SET &&
|
|
in_mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO &&
|
|
!ib_query_port(ibdev, port_num, &pattr))
|
|
prev_lid = pattr.lid;
|
|
|
|
err = mthca_MAD_IFC(to_mdev(ibdev),
|
|
mad_flags & IB_MAD_IGNORE_MKEY,
|
|
mad_flags & IB_MAD_IGNORE_BKEY,
|
|
port_num, in_wc, in_grh, in_mad, out_mad);
|
|
if (err == -EBADMSG)
|
|
return IB_MAD_RESULT_SUCCESS;
|
|
else if (err) {
|
|
mthca_err(to_mdev(ibdev), "MAD_IFC returned %d\n", err);
|
|
return IB_MAD_RESULT_FAILURE;
|
|
}
|
|
|
|
if (!out_mad->mad_hdr.status) {
|
|
smp_snoop(ibdev, port_num, in_mad, prev_lid);
|
|
node_desc_override(ibdev, out_mad);
|
|
}
|
|
|
|
/* set return bit in status of directed route responses */
|
|
if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
|
|
out_mad->mad_hdr.status |= cpu_to_be16(1 << 15);
|
|
|
|
if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP_REPRESS)
|
|
/* no response for trap repress */
|
|
return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
|
|
|
|
return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
|
|
}
|
|
|
|
static void send_handler(struct ib_mad_agent *agent,
|
|
struct ib_mad_send_wc *mad_send_wc)
|
|
{
|
|
ib_free_send_mad(mad_send_wc->send_buf);
|
|
}
|
|
|
|
int mthca_create_agents(struct mthca_dev *dev)
|
|
{
|
|
struct ib_mad_agent *agent;
|
|
int p, q;
|
|
int ret;
|
|
|
|
spin_lock_init(&dev->sm_lock);
|
|
|
|
for (p = 0; p < dev->limits.num_ports; ++p)
|
|
for (q = 0; q <= 1; ++q) {
|
|
agent = ib_register_mad_agent(&dev->ib_dev, p + 1,
|
|
q ? IB_QPT_GSI : IB_QPT_SMI,
|
|
NULL, 0, send_handler,
|
|
NULL, NULL);
|
|
if (IS_ERR(agent)) {
|
|
ret = PTR_ERR(agent);
|
|
goto err;
|
|
}
|
|
dev->send_agent[p][q] = agent;
|
|
}
|
|
|
|
|
|
for (p = 1; p <= dev->limits.num_ports; ++p) {
|
|
ret = mthca_update_rate(dev, p);
|
|
if (ret) {
|
|
mthca_err(dev, "Failed to obtain port %d rate."
|
|
" aborting.\n", p);
|
|
goto err;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
|
|
err:
|
|
for (p = 0; p < dev->limits.num_ports; ++p)
|
|
for (q = 0; q <= 1; ++q)
|
|
if (dev->send_agent[p][q])
|
|
ib_unregister_mad_agent(dev->send_agent[p][q]);
|
|
|
|
return ret;
|
|
}
|
|
|
|
void mthca_free_agents(struct mthca_dev *dev)
|
|
{
|
|
struct ib_mad_agent *agent;
|
|
int p, q;
|
|
|
|
for (p = 0; p < dev->limits.num_ports; ++p) {
|
|
for (q = 0; q <= 1; ++q) {
|
|
agent = dev->send_agent[p][q];
|
|
dev->send_agent[p][q] = NULL;
|
|
ib_unregister_mad_agent(agent);
|
|
}
|
|
|
|
if (dev->sm_ah[p])
|
|
ib_destroy_ah(dev->sm_ah[p]);
|
|
}
|
|
}
|