2007-05-09 09:00:38 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Cisco Systems, 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.
|
|
|
|
*/
|
|
|
|
|
2010-10-25 12:08:52 +08:00
|
|
|
#include <rdma/ib_addr.h>
|
2010-08-26 22:19:22 +08:00
|
|
|
#include <rdma/ib_cache.h>
|
2010-10-25 12:08:52 +08:00
|
|
|
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2010-10-25 12:08:52 +08:00
|
|
|
#include <linux/inet.h>
|
|
|
|
#include <linux/string.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
|
2007-05-09 09:00:38 +08:00
|
|
|
#include "mlx4_ib.h"
|
|
|
|
|
2010-10-25 12:08:52 +08:00
|
|
|
int mlx4_ib_resolve_grh(struct mlx4_ib_dev *dev, const struct ib_ah_attr *ah_attr,
|
|
|
|
u8 *mac, int *is_mcast, u8 port)
|
2007-05-09 09:00:38 +08:00
|
|
|
{
|
2010-10-25 12:08:52 +08:00
|
|
|
struct in6_addr in6;
|
2007-05-09 09:00:38 +08:00
|
|
|
|
2010-10-25 12:08:52 +08:00
|
|
|
*is_mcast = 0;
|
2007-05-09 09:00:38 +08:00
|
|
|
|
2010-10-25 12:08:52 +08:00
|
|
|
memcpy(&in6, ah_attr->grh.dgid.raw, sizeof in6);
|
|
|
|
if (rdma_link_local_addr(&in6))
|
|
|
|
rdma_get_ll_mac(&in6, mac);
|
|
|
|
else if (rdma_is_multicast_addr(&in6)) {
|
|
|
|
rdma_get_mcast_mac(&in6, mac);
|
|
|
|
*is_mcast = 1;
|
|
|
|
} else
|
|
|
|
return -EINVAL;
|
2007-05-09 09:00:38 +08:00
|
|
|
|
2010-10-25 12:08:52 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ib_ah *create_ib_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr,
|
|
|
|
struct mlx4_ib_ah *ah)
|
|
|
|
{
|
|
|
|
struct mlx4_dev *dev = to_mdev(pd->device)->dev;
|
|
|
|
|
|
|
|
ah->av.ib.port_pd = cpu_to_be32(to_mpd(pd)->pdn | (ah_attr->port_num << 24));
|
|
|
|
ah->av.ib.g_slid = ah_attr->src_path_bits;
|
2007-05-09 09:00:38 +08:00
|
|
|
if (ah_attr->ah_flags & IB_AH_GRH) {
|
2010-10-25 12:08:52 +08:00
|
|
|
ah->av.ib.g_slid |= 0x80;
|
|
|
|
ah->av.ib.gid_index = ah_attr->grh.sgid_index;
|
|
|
|
ah->av.ib.hop_limit = ah_attr->grh.hop_limit;
|
|
|
|
ah->av.ib.sl_tclass_flowlabel |=
|
2007-05-09 09:00:38 +08:00
|
|
|
cpu_to_be32((ah_attr->grh.traffic_class << 20) |
|
|
|
|
ah_attr->grh.flow_label);
|
2010-10-25 12:08:52 +08:00
|
|
|
memcpy(ah->av.ib.dgid, ah_attr->grh.dgid.raw, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
ah->av.ib.dlid = cpu_to_be16(ah_attr->dlid);
|
|
|
|
if (ah_attr->static_rate) {
|
|
|
|
ah->av.ib.stat_rate = ah_attr->static_rate + MLX4_STAT_RATE_OFFSET;
|
|
|
|
while (ah->av.ib.stat_rate > IB_RATE_2_5_GBPS + MLX4_STAT_RATE_OFFSET &&
|
|
|
|
!(1 << ah->av.ib.stat_rate & dev->caps.stat_rate_support))
|
|
|
|
--ah->av.ib.stat_rate;
|
2007-05-09 09:00:38 +08:00
|
|
|
}
|
2010-10-25 12:08:52 +08:00
|
|
|
ah->av.ib.sl_tclass_flowlabel = cpu_to_be32(ah_attr->sl << 28);
|
2007-05-09 09:00:38 +08:00
|
|
|
|
|
|
|
return &ah->ibah;
|
|
|
|
}
|
|
|
|
|
2010-10-25 12:08:52 +08:00
|
|
|
static struct ib_ah *create_iboe_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr,
|
|
|
|
struct mlx4_ib_ah *ah)
|
|
|
|
{
|
|
|
|
struct mlx4_ib_dev *ibdev = to_mdev(pd->device);
|
|
|
|
struct mlx4_dev *dev = ibdev->dev;
|
2010-08-26 22:19:22 +08:00
|
|
|
union ib_gid sgid;
|
2010-10-25 12:08:52 +08:00
|
|
|
u8 mac[6];
|
|
|
|
int err;
|
|
|
|
int is_mcast;
|
2010-08-26 22:19:22 +08:00
|
|
|
u16 vlan_tag;
|
2010-10-25 12:08:52 +08:00
|
|
|
|
|
|
|
err = mlx4_ib_resolve_grh(ibdev, ah_attr, mac, &is_mcast, ah_attr->port_num);
|
|
|
|
if (err)
|
|
|
|
return ERR_PTR(err);
|
|
|
|
|
|
|
|
memcpy(ah->av.eth.mac, mac, 6);
|
2010-08-26 22:19:22 +08:00
|
|
|
err = ib_get_cached_gid(pd->device, ah_attr->port_num, ah_attr->grh.sgid_index, &sgid);
|
|
|
|
if (err)
|
|
|
|
return ERR_PTR(err);
|
|
|
|
vlan_tag = rdma_get_vlan_id(&sgid);
|
|
|
|
if (vlan_tag < 0x1000)
|
|
|
|
vlan_tag |= (ah_attr->sl & 7) << 13;
|
2010-10-25 12:08:52 +08:00
|
|
|
ah->av.eth.port_pd = cpu_to_be32(to_mpd(pd)->pdn | (ah_attr->port_num << 24));
|
|
|
|
ah->av.eth.gid_index = ah_attr->grh.sgid_index;
|
2010-08-26 22:19:22 +08:00
|
|
|
ah->av.eth.vlan = cpu_to_be16(vlan_tag);
|
2010-10-25 12:08:52 +08:00
|
|
|
if (ah_attr->static_rate) {
|
|
|
|
ah->av.eth.stat_rate = ah_attr->static_rate + MLX4_STAT_RATE_OFFSET;
|
|
|
|
while (ah->av.eth.stat_rate > IB_RATE_2_5_GBPS + MLX4_STAT_RATE_OFFSET &&
|
|
|
|
!(1 << ah->av.eth.stat_rate & dev->caps.stat_rate_support))
|
|
|
|
--ah->av.eth.stat_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HW requires multicast LID so we just choose one.
|
|
|
|
*/
|
|
|
|
if (is_mcast)
|
|
|
|
ah->av.ib.dlid = cpu_to_be16(0xc000);
|
|
|
|
|
|
|
|
memcpy(ah->av.eth.dgid, ah_attr->grh.dgid.raw, 16);
|
2011-12-11 22:40:05 +08:00
|
|
|
ah->av.eth.sl_tclass_flowlabel = cpu_to_be32(ah_attr->sl << 29);
|
2010-10-25 12:08:52 +08:00
|
|
|
|
|
|
|
return &ah->ibah;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ib_ah *mlx4_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr)
|
|
|
|
{
|
|
|
|
struct mlx4_ib_ah *ah;
|
|
|
|
struct ib_ah *ret;
|
|
|
|
|
|
|
|
ah = kzalloc(sizeof *ah, GFP_ATOMIC);
|
|
|
|
if (!ah)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
if (rdma_port_get_link_layer(pd->device, ah_attr->port_num) == IB_LINK_LAYER_ETHERNET) {
|
|
|
|
if (!(ah_attr->ah_flags & IB_AH_GRH)) {
|
|
|
|
ret = ERR_PTR(-EINVAL);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* TBD: need to handle the case when we get
|
|
|
|
* called in an atomic context and there we
|
|
|
|
* might sleep. We don't expect this
|
|
|
|
* currently since we're working with link
|
|
|
|
* local addresses which we can translate
|
|
|
|
* without going to sleep.
|
|
|
|
*/
|
|
|
|
ret = create_iboe_ah(pd, ah_attr, ah);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ERR(ret))
|
|
|
|
kfree(ah);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
} else
|
|
|
|
return create_ib_ah(pd, ah_attr, ah); /* never fails */
|
|
|
|
}
|
|
|
|
|
2007-05-09 09:00:38 +08:00
|
|
|
int mlx4_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
|
|
|
|
{
|
|
|
|
struct mlx4_ib_ah *ah = to_mah(ibah);
|
2010-10-25 12:08:52 +08:00
|
|
|
enum rdma_link_layer ll;
|
2007-05-09 09:00:38 +08:00
|
|
|
|
|
|
|
memset(ah_attr, 0, sizeof *ah_attr);
|
2010-10-25 12:08:52 +08:00
|
|
|
ah_attr->sl = be32_to_cpu(ah->av.ib.sl_tclass_flowlabel) >> 28;
|
|
|
|
ah_attr->port_num = be32_to_cpu(ah->av.ib.port_pd) >> 24;
|
|
|
|
ll = rdma_port_get_link_layer(ibah->device, ah_attr->port_num);
|
|
|
|
ah_attr->dlid = ll == IB_LINK_LAYER_INFINIBAND ? be16_to_cpu(ah->av.ib.dlid) : 0;
|
|
|
|
if (ah->av.ib.stat_rate)
|
|
|
|
ah_attr->static_rate = ah->av.ib.stat_rate - MLX4_STAT_RATE_OFFSET;
|
|
|
|
ah_attr->src_path_bits = ah->av.ib.g_slid & 0x7F;
|
2007-05-09 09:00:38 +08:00
|
|
|
|
|
|
|
if (mlx4_ib_ah_grh_present(ah)) {
|
|
|
|
ah_attr->ah_flags = IB_AH_GRH;
|
|
|
|
|
|
|
|
ah_attr->grh.traffic_class =
|
2010-10-25 12:08:52 +08:00
|
|
|
be32_to_cpu(ah->av.ib.sl_tclass_flowlabel) >> 20;
|
2007-05-09 09:00:38 +08:00
|
|
|
ah_attr->grh.flow_label =
|
2010-10-25 12:08:52 +08:00
|
|
|
be32_to_cpu(ah->av.ib.sl_tclass_flowlabel) & 0xfffff;
|
|
|
|
ah_attr->grh.hop_limit = ah->av.ib.hop_limit;
|
|
|
|
ah_attr->grh.sgid_index = ah->av.ib.gid_index;
|
|
|
|
memcpy(ah_attr->grh.dgid.raw, ah->av.ib.dgid, 16);
|
2007-05-09 09:00:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mlx4_ib_destroy_ah(struct ib_ah *ah)
|
|
|
|
{
|
|
|
|
kfree(to_mah(ah));
|
|
|
|
return 0;
|
|
|
|
}
|