Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/mlx5/mlx5_ib/mlx5_ib_ah.c
/*- | /*- | ||||
* Copyright (c) 2013-2015, Mellanox Technologies, Ltd. All rights reserved. | * Copyright (c) 2013-2020, Mellanox Technologies, Ltd. All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
* notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | ||||
Show All 11 Lines | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#include "mlx5_ib.h" | #include "mlx5_ib.h" | ||||
static struct ib_ah *create_ib_ah(struct mlx5_ib_dev *dev, | static void create_ib_ah(struct mlx5_ib_dev *dev, | ||||
struct mlx5_ib_ah *ah, | struct mlx5_ib_ah *ah, | ||||
struct ib_ah_attr *ah_attr, | struct ib_ah_attr *ah_attr, | ||||
enum rdma_link_layer ll) | enum rdma_link_layer ll) | ||||
{ | { | ||||
if (ah_attr->ah_flags & IB_AH_GRH) { | if (ah_attr->ah_flags & IB_AH_GRH) { | ||||
memcpy(ah->av.rgid, &ah_attr->grh.dgid, 16); | memcpy(ah->av.rgid, &ah_attr->grh.dgid, 16); | ||||
ah->av.grh_gid_fl = cpu_to_be32(ah_attr->grh.flow_label | | ah->av.grh_gid_fl = cpu_to_be32(ah_attr->grh.flow_label | | ||||
(1 << 30) | | (1 << 30) | | ||||
Show All 11 Lines | ah->av.udp_sport = | ||||
ah_attr->port_num, | ah_attr->port_num, | ||||
ah_attr->grh.sgid_index); | ah_attr->grh.sgid_index); | ||||
ah->av.stat_rate_sl |= (ah_attr->sl & 0x7) << 1; | ah->av.stat_rate_sl |= (ah_attr->sl & 0x7) << 1; | ||||
} else { | } else { | ||||
ah->av.rlid = cpu_to_be16(ah_attr->dlid); | ah->av.rlid = cpu_to_be16(ah_attr->dlid); | ||||
ah->av.fl_mlid = ah_attr->src_path_bits & 0x7f; | ah->av.fl_mlid = ah_attr->src_path_bits & 0x7f; | ||||
ah->av.stat_rate_sl |= (ah_attr->sl & 0xf); | ah->av.stat_rate_sl |= (ah_attr->sl & 0xf); | ||||
} | } | ||||
return &ah->ibah; | |||||
} | } | ||||
struct ib_ah *mlx5_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr, | int mlx5_ib_create_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr, | ||||
struct ib_udata *udata) | u32 flags, struct ib_udata *udata) | ||||
{ | { | ||||
struct mlx5_ib_ah *ah; | struct mlx5_ib_ah *ah = to_mah(ibah); | ||||
struct mlx5_ib_dev *dev = to_mdev(pd->device); | struct mlx5_ib_dev *dev = to_mdev(ibah->device); | ||||
enum rdma_link_layer ll; | enum rdma_link_layer ll; | ||||
ll = pd->device->get_link_layer(pd->device, ah_attr->port_num); | ll = dev->ib_dev.get_link_layer(&dev->ib_dev, ah_attr->port_num); | ||||
if (ll == IB_LINK_LAYER_ETHERNET && !(ah_attr->ah_flags & IB_AH_GRH)) | if (ll == IB_LINK_LAYER_ETHERNET && !(ah_attr->ah_flags & IB_AH_GRH)) | ||||
return ERR_PTR(-EINVAL); | return -EINVAL; | ||||
if (ll == IB_LINK_LAYER_ETHERNET && udata) { | if (ll == IB_LINK_LAYER_ETHERNET && udata) { | ||||
int err; | int err; | ||||
struct mlx5_ib_create_ah_resp resp = {}; | struct mlx5_ib_create_ah_resp resp = {}; | ||||
u32 min_resp_len = offsetof(typeof(resp), dmac) + | u32 min_resp_len = offsetof(typeof(resp), dmac) + | ||||
sizeof(resp.dmac); | sizeof(resp.dmac); | ||||
if (udata->outlen < min_resp_len) | if (udata->outlen < min_resp_len) | ||||
return ERR_PTR(-EINVAL); | return -EINVAL; | ||||
resp.response_length = min_resp_len; | resp.response_length = min_resp_len; | ||||
err = ib_resolve_eth_dmac(pd->device, ah_attr); | err = ib_resolve_eth_dmac(&dev->ib_dev, ah_attr); | ||||
if (err) | if (err) | ||||
return ERR_PTR(err); | return err; | ||||
memcpy(resp.dmac, ah_attr->dmac, ETH_ALEN); | memcpy(resp.dmac, ah_attr->dmac, ETH_ALEN); | ||||
err = ib_copy_to_udata(udata, &resp, resp.response_length); | err = ib_copy_to_udata(udata, &resp, resp.response_length); | ||||
if (err) | if (err) | ||||
return ERR_PTR(err); | return err; | ||||
} | } | ||||
ah = kzalloc(sizeof(*ah), GFP_ATOMIC); | create_ib_ah(dev, ah, ah_attr, ll); | ||||
if (!ah) | return 0; | ||||
return ERR_PTR(-ENOMEM); | |||||
return create_ib_ah(dev, ah, ah_attr, ll); /* never fails */ | |||||
} | } | ||||
int mlx5_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr) | int mlx5_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr) | ||||
{ | { | ||||
struct mlx5_ib_ah *ah = to_mah(ibah); | struct mlx5_ib_ah *ah = to_mah(ibah); | ||||
u32 tmp; | u32 tmp; | ||||
memset(ah_attr, 0, sizeof(*ah_attr)); | memset(ah_attr, 0, sizeof(*ah_attr)); | ||||
Show All 9 Lines | int mlx5_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr) | ||||
} | } | ||||
ah_attr->dlid = be16_to_cpu(ah->av.rlid); | ah_attr->dlid = be16_to_cpu(ah->av.rlid); | ||||
ah_attr->static_rate = ah->av.stat_rate_sl >> 4; | ah_attr->static_rate = ah->av.stat_rate_sl >> 4; | ||||
ah_attr->sl = ah->av.stat_rate_sl & 0xf; | ah_attr->sl = ah->av.stat_rate_sl & 0xf; | ||||
return 0; | return 0; | ||||
} | } | ||||
int mlx5_ib_destroy_ah(struct ib_ah *ah) | void mlx5_ib_destroy_ah(struct ib_ah *ah, u32 flags) | ||||
{ | { | ||||
kfree(to_mah(ah)); | return; | ||||
return 0; | |||||
} | } |