mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-23 04:34:11 +08:00
IB/core: Add inline function to validate port
Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com> Reviewed-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
This commit is contained in:
parent
2bce1a6d22
commit
24dc831b77
@ -504,8 +504,7 @@ int ib_find_cached_gid_by_port(struct ib_device *ib_dev,
|
|||||||
struct ib_gid_attr val = {.ndev = ndev, .gid_type = gid_type};
|
struct ib_gid_attr val = {.ndev = ndev, .gid_type = gid_type};
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
if (port < rdma_start_port(ib_dev) ||
|
if (!rdma_is_port_valid(ib_dev, port))
|
||||||
port > rdma_end_port(ib_dev))
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid;
|
table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid;
|
||||||
@ -562,8 +561,7 @@ static int ib_cache_gid_find_by_filter(struct ib_device *ib_dev,
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
|
|
||||||
if (port < rdma_start_port(ib_dev) ||
|
if (!rdma_is_port_valid(ib_dev, port) ||
|
||||||
port > rdma_end_port(ib_dev) ||
|
|
||||||
!rdma_protocol_roce(ib_dev, port))
|
!rdma_protocol_roce(ib_dev, port))
|
||||||
return -EPROTONOSUPPORT;
|
return -EPROTONOSUPPORT;
|
||||||
|
|
||||||
@ -845,7 +843,7 @@ int ib_get_cached_gid(struct ib_device *device,
|
|||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct ib_gid_table *table;
|
struct ib_gid_table *table;
|
||||||
|
|
||||||
if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device))
|
if (!rdma_is_port_valid(device, port_num))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
table = device->cache.ports[port_num - rdma_start_port(device)].gid;
|
table = device->cache.ports[port_num - rdma_start_port(device)].gid;
|
||||||
@ -895,7 +893,7 @@ int ib_get_cached_pkey(struct ib_device *device,
|
|||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device))
|
if (!rdma_is_port_valid(device, port_num))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
read_lock_irqsave(&device->cache.lock, flags);
|
read_lock_irqsave(&device->cache.lock, flags);
|
||||||
@ -924,7 +922,7 @@ int ib_find_cached_pkey(struct ib_device *device,
|
|||||||
int ret = -ENOENT;
|
int ret = -ENOENT;
|
||||||
int partial_ix = -1;
|
int partial_ix = -1;
|
||||||
|
|
||||||
if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device))
|
if (!rdma_is_port_valid(device, port_num))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
read_lock_irqsave(&device->cache.lock, flags);
|
read_lock_irqsave(&device->cache.lock, flags);
|
||||||
@ -964,7 +962,7 @@ int ib_find_exact_cached_pkey(struct ib_device *device,
|
|||||||
int i;
|
int i;
|
||||||
int ret = -ENOENT;
|
int ret = -ENOENT;
|
||||||
|
|
||||||
if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device))
|
if (!rdma_is_port_valid(device, port_num))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
read_lock_irqsave(&device->cache.lock, flags);
|
read_lock_irqsave(&device->cache.lock, flags);
|
||||||
@ -993,7 +991,7 @@ int ib_get_cached_lmc(struct ib_device *device,
|
|||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device))
|
if (!rdma_is_port_valid(device, port_num))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
read_lock_irqsave(&device->cache.lock, flags);
|
read_lock_irqsave(&device->cache.lock, flags);
|
||||||
@ -1038,7 +1036,7 @@ static void ib_cache_update(struct ib_device *device,
|
|||||||
bool use_roce_gid_table =
|
bool use_roce_gid_table =
|
||||||
rdma_cap_roce_gid_table(device, port);
|
rdma_cap_roce_gid_table(device, port);
|
||||||
|
|
||||||
if (port < rdma_start_port(device) || port > rdma_end_port(device))
|
if (!rdma_is_port_valid(device, port))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
table = device->cache.ports[port - rdma_start_port(device)].gid;
|
table = device->cache.ports[port - rdma_start_port(device)].gid;
|
||||||
|
@ -269,8 +269,7 @@ struct cma_device *cma_enum_devices_by_ibdev(cma_device_filter filter,
|
|||||||
int cma_get_default_gid_type(struct cma_device *cma_dev,
|
int cma_get_default_gid_type(struct cma_device *cma_dev,
|
||||||
unsigned int port)
|
unsigned int port)
|
||||||
{
|
{
|
||||||
if (port < rdma_start_port(cma_dev->device) ||
|
if (!rdma_is_port_valid(cma_dev->device, port))
|
||||||
port > rdma_end_port(cma_dev->device))
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
return cma_dev->default_gid_type[port - rdma_start_port(cma_dev->device)];
|
return cma_dev->default_gid_type[port - rdma_start_port(cma_dev->device)];
|
||||||
@ -282,8 +281,7 @@ int cma_set_default_gid_type(struct cma_device *cma_dev,
|
|||||||
{
|
{
|
||||||
unsigned long supported_gids;
|
unsigned long supported_gids;
|
||||||
|
|
||||||
if (port < rdma_start_port(cma_dev->device) ||
|
if (!rdma_is_port_valid(cma_dev->device, port))
|
||||||
port > rdma_end_port(cma_dev->device))
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
supported_gids = roce_gid_type_mask_support(cma_dev->device, port);
|
supported_gids = roce_gid_type_mask_support(cma_dev->device, port);
|
||||||
|
@ -659,7 +659,7 @@ int ib_query_port(struct ib_device *device,
|
|||||||
union ib_gid gid;
|
union ib_gid gid;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device))
|
if (!rdma_is_port_valid(device, port_num))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
memset(port_attr, 0, sizeof(*port_attr));
|
memset(port_attr, 0, sizeof(*port_attr));
|
||||||
@ -825,7 +825,7 @@ int ib_modify_port(struct ib_device *device,
|
|||||||
if (!device->modify_port)
|
if (!device->modify_port)
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
|
|
||||||
if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device))
|
if (!rdma_is_port_valid(device, port_num))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
return device->modify_port(device, port_num, port_modify_mask,
|
return device->modify_port(device, port_num, port_modify_mask,
|
||||||
|
@ -1205,8 +1205,7 @@ int ib_resolve_eth_dmac(struct ib_device *device,
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (ah_attr->port_num < rdma_start_port(device) ||
|
if (!rdma_is_port_valid(device, ah_attr->port_num))
|
||||||
ah_attr->port_num > rdma_end_port(device))
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (!rdma_cap_eth_ah(device, ah_attr->port_num))
|
if (!rdma_cap_eth_ah(device, ah_attr->port_num))
|
||||||
|
@ -2280,6 +2280,13 @@ static inline u8 rdma_end_port(const struct ib_device *device)
|
|||||||
return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
|
return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int rdma_is_port_valid(const struct ib_device *device,
|
||||||
|
unsigned int port)
|
||||||
|
{
|
||||||
|
return (port >= rdma_start_port(device) &&
|
||||||
|
port <= rdma_end_port(device));
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
|
static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
|
||||||
{
|
{
|
||||||
return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB;
|
return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB;
|
||||||
|
Loading…
Reference in New Issue
Block a user