Commit 414448d2 authored by Parav Pandit's avatar Parav Pandit Committed by Jason Gunthorpe

RDMA: Use ib_gid_attr during GID modification

Now that ib_gid_attr contains device, port and index, simplify the
provider APIs add_gid() and del_gid() to use device, port and index
fields from the ib_gid_attr attributes structure.
Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 3e44e0ee
...@@ -157,7 +157,7 @@ static void del_roce_gid(struct ib_device *device, u8 port_num, ...@@ -157,7 +157,7 @@ static void del_roce_gid(struct ib_device *device, u8 port_num,
table->data_vec[ix].gid.raw); table->data_vec[ix].gid.raw);
if (rdma_cap_roce_gid_table(device, port_num)) if (rdma_cap_roce_gid_table(device, port_num))
device->del_gid(device, port_num, ix, device->del_gid(&table->data_vec[ix].attr,
&table->data_vec[ix].context); &table->data_vec[ix].context);
dev_put(table->data_vec[ix].attr.ndev); dev_put(table->data_vec[ix].attr.ndev);
} }
...@@ -186,8 +186,7 @@ static int add_roce_gid(struct ib_gid_table *table, ...@@ -186,8 +186,7 @@ static int add_roce_gid(struct ib_gid_table *table,
} }
if (rdma_cap_roce_gid_table(attr->device, attr->port_num)) { if (rdma_cap_roce_gid_table(attr->device, attr->port_num)) {
ret = attr->device->add_gid(attr->device, attr->port_num, ret = attr->device->add_gid(gid, attr, &entry->context);
ix, gid, attr, &entry->context);
if (ret) { if (ret) {
pr_err("%s GID add failed device=%s port=%d index=%d\n", pr_err("%s GID add failed device=%s port=%d index=%d\n",
__func__, attr->device->name, attr->port_num, __func__, attr->device->name, attr->port_num,
......
...@@ -314,12 +314,11 @@ int bnxt_re_query_gid(struct ib_device *ibdev, u8 port_num, ...@@ -314,12 +314,11 @@ int bnxt_re_query_gid(struct ib_device *ibdev, u8 port_num,
return rc; return rc;
} }
int bnxt_re_del_gid(struct ib_device *ibdev, u8 port_num, int bnxt_re_del_gid(const struct ib_gid_attr *attr, void **context)
unsigned int index, void **context)
{ {
int rc = 0; int rc = 0;
struct bnxt_re_gid_ctx *ctx, **ctx_tbl; struct bnxt_re_gid_ctx *ctx, **ctx_tbl;
struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev); struct bnxt_re_dev *rdev = to_bnxt_re_dev(attr->device, ibdev);
struct bnxt_qplib_sgid_tbl *sgid_tbl = &rdev->qplib_res.sgid_tbl; struct bnxt_qplib_sgid_tbl *sgid_tbl = &rdev->qplib_res.sgid_tbl;
struct bnxt_qplib_gid *gid_to_del; struct bnxt_qplib_gid *gid_to_del;
...@@ -365,15 +364,14 @@ int bnxt_re_del_gid(struct ib_device *ibdev, u8 port_num, ...@@ -365,15 +364,14 @@ int bnxt_re_del_gid(struct ib_device *ibdev, u8 port_num,
return rc; return rc;
} }
int bnxt_re_add_gid(struct ib_device *ibdev, u8 port_num, int bnxt_re_add_gid(const union ib_gid *gid,
unsigned int index, const union ib_gid *gid,
const struct ib_gid_attr *attr, void **context) const struct ib_gid_attr *attr, void **context)
{ {
int rc; int rc;
u32 tbl_idx = 0; u32 tbl_idx = 0;
u16 vlan_id = 0xFFFF; u16 vlan_id = 0xFFFF;
struct bnxt_re_gid_ctx *ctx, **ctx_tbl; struct bnxt_re_gid_ctx *ctx, **ctx_tbl;
struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev); struct bnxt_re_dev *rdev = to_bnxt_re_dev(attr->device, ibdev);
struct bnxt_qplib_sgid_tbl *sgid_tbl = &rdev->qplib_res.sgid_tbl; struct bnxt_qplib_sgid_tbl *sgid_tbl = &rdev->qplib_res.sgid_tbl;
if ((attr->ndev) && is_vlan_dev(attr->ndev)) if ((attr->ndev) && is_vlan_dev(attr->ndev))
......
...@@ -157,10 +157,8 @@ int bnxt_re_get_port_immutable(struct ib_device *ibdev, u8 port_num, ...@@ -157,10 +157,8 @@ int bnxt_re_get_port_immutable(struct ib_device *ibdev, u8 port_num,
void bnxt_re_query_fw_str(struct ib_device *ibdev, char *str); void bnxt_re_query_fw_str(struct ib_device *ibdev, char *str);
int bnxt_re_query_pkey(struct ib_device *ibdev, u8 port_num, int bnxt_re_query_pkey(struct ib_device *ibdev, u8 port_num,
u16 index, u16 *pkey); u16 index, u16 *pkey);
int bnxt_re_del_gid(struct ib_device *ibdev, u8 port_num, int bnxt_re_del_gid(const struct ib_gid_attr *attr, void **context);
unsigned int index, void **context); int bnxt_re_add_gid(const union ib_gid *gid,
int bnxt_re_add_gid(struct ib_device *ibdev, u8 port_num,
unsigned int index, const union ib_gid *gid,
const struct ib_gid_attr *attr, void **context); const struct ib_gid_attr *attr, void **context);
int bnxt_re_query_gid(struct ib_device *ibdev, u8 port_num, int bnxt_re_query_gid(struct ib_device *ibdev, u8 port_num,
int index, union ib_gid *gid); int index, union ib_gid *gid);
......
...@@ -74,12 +74,11 @@ static int hns_roce_set_mac(struct hns_roce_dev *hr_dev, u8 port, u8 *addr) ...@@ -74,12 +74,11 @@ static int hns_roce_set_mac(struct hns_roce_dev *hr_dev, u8 port, u8 *addr)
return hr_dev->hw->set_mac(hr_dev, phy_port, addr); return hr_dev->hw->set_mac(hr_dev, phy_port, addr);
} }
static int hns_roce_add_gid(struct ib_device *device, u8 port_num, static int hns_roce_add_gid(const union ib_gid *gid,
unsigned int index, const union ib_gid *gid,
const struct ib_gid_attr *attr, void **context) const struct ib_gid_attr *attr, void **context)
{ {
struct hns_roce_dev *hr_dev = to_hr_dev(device); struct hns_roce_dev *hr_dev = to_hr_dev(attr->device);
u8 port = port_num - 1; u8 port = attr->port_num - 1;
unsigned long flags; unsigned long flags;
int ret; int ret;
...@@ -88,21 +87,20 @@ static int hns_roce_add_gid(struct ib_device *device, u8 port_num, ...@@ -88,21 +87,20 @@ static int hns_roce_add_gid(struct ib_device *device, u8 port_num,
spin_lock_irqsave(&hr_dev->iboe.lock, flags); spin_lock_irqsave(&hr_dev->iboe.lock, flags);
ret = hr_dev->hw->set_gid(hr_dev, port, index, (union ib_gid *)gid, ret = hr_dev->hw->set_gid(hr_dev, port, attr->index,
attr); (union ib_gid *)gid, attr);
spin_unlock_irqrestore(&hr_dev->iboe.lock, flags); spin_unlock_irqrestore(&hr_dev->iboe.lock, flags);
return ret; return ret;
} }
static int hns_roce_del_gid(struct ib_device *device, u8 port_num, static int hns_roce_del_gid(const struct ib_gid_attr *attr, void **context)
unsigned int index, void **context)
{ {
struct hns_roce_dev *hr_dev = to_hr_dev(device); struct hns_roce_dev *hr_dev = to_hr_dev(attr->device);
struct ib_gid_attr zattr = { }; struct ib_gid_attr zattr = { };
union ib_gid zgid = { {0} }; union ib_gid zgid = { {0} };
u8 port = port_num - 1; u8 port = attr->port_num - 1;
unsigned long flags; unsigned long flags;
int ret; int ret;
...@@ -111,7 +109,7 @@ static int hns_roce_del_gid(struct ib_device *device, u8 port_num, ...@@ -111,7 +109,7 @@ static int hns_roce_del_gid(struct ib_device *device, u8 port_num,
spin_lock_irqsave(&hr_dev->iboe.lock, flags); spin_lock_irqsave(&hr_dev->iboe.lock, flags);
ret = hr_dev->hw->set_gid(hr_dev, port, index, &zgid, &zattr); ret = hr_dev->hw->set_gid(hr_dev, port, attr->index, &zgid, &zattr);
spin_unlock_irqrestore(&hr_dev->iboe.lock, flags); spin_unlock_irqrestore(&hr_dev->iboe.lock, flags);
......
...@@ -246,14 +246,11 @@ static int mlx4_ib_update_gids(struct gid_entry *gids, ...@@ -246,14 +246,11 @@ static int mlx4_ib_update_gids(struct gid_entry *gids,
return mlx4_ib_update_gids_v1(gids, ibdev, port_num); return mlx4_ib_update_gids_v1(gids, ibdev, port_num);
} }
static int mlx4_ib_add_gid(struct ib_device *device, static int mlx4_ib_add_gid(const union ib_gid *gid,
u8 port_num,
unsigned int index,
const union ib_gid *gid,
const struct ib_gid_attr *attr, const struct ib_gid_attr *attr,
void **context) void **context)
{ {
struct mlx4_ib_dev *ibdev = to_mdev(device); struct mlx4_ib_dev *ibdev = to_mdev(attr->device);
struct mlx4_ib_iboe *iboe = &ibdev->iboe; struct mlx4_ib_iboe *iboe = &ibdev->iboe;
struct mlx4_port_gid_table *port_gid_table; struct mlx4_port_gid_table *port_gid_table;
int free = -1, found = -1; int free = -1, found = -1;
...@@ -262,16 +259,16 @@ static int mlx4_ib_add_gid(struct ib_device *device, ...@@ -262,16 +259,16 @@ static int mlx4_ib_add_gid(struct ib_device *device,
int i; int i;
struct gid_entry *gids = NULL; struct gid_entry *gids = NULL;
if (!rdma_cap_roce_gid_table(device, port_num)) if (!rdma_cap_roce_gid_table(attr->device, attr->port_num))
return -EINVAL; return -EINVAL;
if (port_num > MLX4_MAX_PORTS) if (attr->port_num > MLX4_MAX_PORTS)
return -EINVAL; return -EINVAL;
if (!context) if (!context)
return -EINVAL; return -EINVAL;
port_gid_table = &iboe->gids[port_num - 1]; port_gid_table = &iboe->gids[attr->port_num - 1];
spin_lock_bh(&iboe->lock); spin_lock_bh(&iboe->lock);
for (i = 0; i < MLX4_MAX_PORT_GIDS; ++i) { for (i = 0; i < MLX4_MAX_PORT_GIDS; ++i) {
if (!memcmp(&port_gid_table->gids[i].gid, gid, sizeof(*gid)) && if (!memcmp(&port_gid_table->gids[i].gid, gid, sizeof(*gid)) &&
...@@ -318,33 +315,30 @@ static int mlx4_ib_add_gid(struct ib_device *device, ...@@ -318,33 +315,30 @@ static int mlx4_ib_add_gid(struct ib_device *device,
spin_unlock_bh(&iboe->lock); spin_unlock_bh(&iboe->lock);
if (!ret && hw_update) { if (!ret && hw_update) {
ret = mlx4_ib_update_gids(gids, ibdev, port_num); ret = mlx4_ib_update_gids(gids, ibdev, attr->port_num);
kfree(gids); kfree(gids);
} }
return ret; return ret;
} }
static int mlx4_ib_del_gid(struct ib_device *device, static int mlx4_ib_del_gid(const struct ib_gid_attr *attr, void **context)
u8 port_num,
unsigned int index,
void **context)
{ {
struct gid_cache_context *ctx = *context; struct gid_cache_context *ctx = *context;
struct mlx4_ib_dev *ibdev = to_mdev(device); struct mlx4_ib_dev *ibdev = to_mdev(attr->device);
struct mlx4_ib_iboe *iboe = &ibdev->iboe; struct mlx4_ib_iboe *iboe = &ibdev->iboe;
struct mlx4_port_gid_table *port_gid_table; struct mlx4_port_gid_table *port_gid_table;
int ret = 0; int ret = 0;
int hw_update = 0; int hw_update = 0;
struct gid_entry *gids = NULL; struct gid_entry *gids = NULL;
if (!rdma_cap_roce_gid_table(device, port_num)) if (!rdma_cap_roce_gid_table(attr->device, attr->port_num))
return -EINVAL; return -EINVAL;
if (port_num > MLX4_MAX_PORTS) if (attr->port_num > MLX4_MAX_PORTS)
return -EINVAL; return -EINVAL;
port_gid_table = &iboe->gids[port_num - 1]; port_gid_table = &iboe->gids[attr->port_num - 1];
spin_lock_bh(&iboe->lock); spin_lock_bh(&iboe->lock);
if (ctx) { if (ctx) {
ctx->refcount--; ctx->refcount--;
...@@ -376,7 +370,7 @@ static int mlx4_ib_del_gid(struct ib_device *device, ...@@ -376,7 +370,7 @@ static int mlx4_ib_del_gid(struct ib_device *device,
spin_unlock_bh(&iboe->lock); spin_unlock_bh(&iboe->lock);
if (!ret && hw_update) { if (!ret && hw_update) {
ret = mlx4_ib_update_gids(gids, ibdev, port_num); ret = mlx4_ib_update_gids(gids, ibdev, attr->port_num);
kfree(gids); kfree(gids);
} }
return ret; return ret;
......
...@@ -502,18 +502,19 @@ static int set_roce_addr(struct mlx5_ib_dev *dev, u8 port_num, ...@@ -502,18 +502,19 @@ static int set_roce_addr(struct mlx5_ib_dev *dev, u8 port_num,
vlan_id, port_num); vlan_id, port_num);
} }
static int mlx5_ib_add_gid(struct ib_device *device, u8 port_num, static int mlx5_ib_add_gid(const union ib_gid *gid,
unsigned int index, const union ib_gid *gid,
const struct ib_gid_attr *attr, const struct ib_gid_attr *attr,
__always_unused void **context) __always_unused void **context)
{ {
return set_roce_addr(to_mdev(device), port_num, index, gid, attr); return set_roce_addr(to_mdev(attr->device), attr->port_num,
attr->index, gid, attr);
} }
static int mlx5_ib_del_gid(struct ib_device *device, u8 port_num, static int mlx5_ib_del_gid(const struct ib_gid_attr *attr,
unsigned int index, __always_unused void **context) __always_unused void **context)
{ {
return set_roce_addr(to_mdev(device), port_num, index, NULL, NULL); return set_roce_addr(to_mdev(attr->device), attr->port_num,
attr->index, NULL, NULL);
} }
__be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num, __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num,
......
...@@ -62,17 +62,10 @@ static DEFINE_MUTEX(pvrdma_device_list_lock); ...@@ -62,17 +62,10 @@ static DEFINE_MUTEX(pvrdma_device_list_lock);
static LIST_HEAD(pvrdma_device_list); static LIST_HEAD(pvrdma_device_list);
static struct workqueue_struct *event_wq; static struct workqueue_struct *event_wq;
static int pvrdma_add_gid(struct ib_device *ibdev, static int pvrdma_add_gid(const union ib_gid *gid,
u8 port_num,
unsigned int index,
const union ib_gid *gid,
const struct ib_gid_attr *attr, const struct ib_gid_attr *attr,
void **context); void **context);
static int pvrdma_del_gid(struct ib_device *ibdev, static int pvrdma_del_gid(const struct ib_gid_attr *attr, void **context);
u8 port_num,
unsigned int index,
void **context);
static ssize_t show_hca(struct device *device, struct device_attribute *attr, static ssize_t show_hca(struct device *device, struct device_attribute *attr,
char *buf) char *buf)
...@@ -657,18 +650,15 @@ static int pvrdma_add_gid_at_index(struct pvrdma_dev *dev, ...@@ -657,18 +650,15 @@ static int pvrdma_add_gid_at_index(struct pvrdma_dev *dev,
return 0; return 0;
} }
static int pvrdma_add_gid(struct ib_device *ibdev, static int pvrdma_add_gid(const union ib_gid *gid,
u8 port_num,
unsigned int index,
const union ib_gid *gid,
const struct ib_gid_attr *attr, const struct ib_gid_attr *attr,
void **context) void **context)
{ {
struct pvrdma_dev *dev = to_vdev(ibdev); struct pvrdma_dev *dev = to_vdev(attr->device);
return pvrdma_add_gid_at_index(dev, gid, return pvrdma_add_gid_at_index(dev, gid,
ib_gid_type_to_pvrdma(attr->gid_type), ib_gid_type_to_pvrdma(attr->gid_type),
index); attr->index);
} }
static int pvrdma_del_gid_at_index(struct pvrdma_dev *dev, int index) static int pvrdma_del_gid_at_index(struct pvrdma_dev *dev, int index)
...@@ -698,17 +688,14 @@ static int pvrdma_del_gid_at_index(struct pvrdma_dev *dev, int index) ...@@ -698,17 +688,14 @@ static int pvrdma_del_gid_at_index(struct pvrdma_dev *dev, int index)
return 0; return 0;
} }
static int pvrdma_del_gid(struct ib_device *ibdev, static int pvrdma_del_gid(const struct ib_gid_attr *attr, void **context)
u8 port_num,
unsigned int index,
void **context)
{ {
struct pvrdma_dev *dev = to_vdev(ibdev); struct pvrdma_dev *dev = to_vdev(attr->device);
dev_dbg(&dev->pdev->dev, "removing gid at index %u from %s", dev_dbg(&dev->pdev->dev, "removing gid at index %u from %s",
index, dev->netdev->name); attr->index, dev->netdev->name);
return pvrdma_del_gid_at_index(dev, index); return pvrdma_del_gid_at_index(dev, attr->index);
} }
static void pvrdma_netdevice_event_handle(struct pvrdma_dev *dev, static void pvrdma_netdevice_event_handle(struct pvrdma_dev *dev,
......
...@@ -77,19 +77,17 @@ static int rxe_query_port(struct ib_device *dev, ...@@ -77,19 +77,17 @@ static int rxe_query_port(struct ib_device *dev,
return rc; return rc;
} }
static int rxe_add_gid(struct ib_device *device, u8 port_num, unsigned int static int rxe_add_gid(const union ib_gid *gid,
index, const union ib_gid *gid,
const struct ib_gid_attr *attr, void **context) const struct ib_gid_attr *attr, void **context)
{ {
if (index >= RXE_PORT_GID_TBL_LEN) if (attr->index >= RXE_PORT_GID_TBL_LEN)
return -EINVAL; return -EINVAL;
return 0; return 0;
} }
static int rxe_del_gid(struct ib_device *device, u8 port_num, unsigned int static int rxe_del_gid(const struct ib_gid_attr *attr, void **context)
index, void **context)
{ {
if (index >= RXE_PORT_GID_TBL_LEN) if (attr->index >= RXE_PORT_GID_TBL_LEN)
return -EINVAL; return -EINVAL;
return 0; return 0;
} }
......
...@@ -2151,34 +2151,29 @@ struct ib_device { ...@@ -2151,34 +2151,29 @@ struct ib_device {
int (*query_gid)(struct ib_device *device, int (*query_gid)(struct ib_device *device,
u8 port_num, int index, u8 port_num, int index,
union ib_gid *gid); union ib_gid *gid);
/* When calling add_gid, the HW vendor's driver should /* When calling add_gid, the HW vendor's driver should add the gid
* add the gid of device @device at gid index @index of * of device of port at gid index available at @attr. Meta-info of
* port @port_num to be @gid. Meta-info of that gid (for example, * that gid (for example, the network device related to this gid) is
* the network device related to this gid is available * available at @attr. @context allows the HW vendor driver to store
* at @attr. @context allows the HW vendor driver to store extra * extra information together with a GID entry. The HW vendor driver may
* information together with a GID entry. The HW vendor may allocate * allocate memory to contain this information and store it in @context
* memory to contain this information and store it in @context when a * when a new GID entry is written to. Params are consistent until the
* new GID entry is written to. Params are consistent until the next * next call of add_gid or delete_gid. The function should return 0 on
* call of add_gid or delete_gid. The function should return 0 on
* success or error otherwise. The function could be called * success or error otherwise. The function could be called
* concurrently for different ports. This function is only called * concurrently for different ports. This function is only called when
* when roce_gid_table is used. * roce_gid_table is used.
*/ */
int (*add_gid)(struct ib_device *device, int (*add_gid)(const union ib_gid *gid,
u8 port_num,
unsigned int index,
const union ib_gid *gid,
const struct ib_gid_attr *attr, const struct ib_gid_attr *attr,
void **context); void **context);
/* When calling del_gid, the HW vendor's driver should delete the /* When calling del_gid, the HW vendor's driver should delete the
* gid of device @device at gid index @index of port @port_num. * gid of device @device at gid index gid_index of port port_num
* available in @attr.
* Upon the deletion of a GID entry, the HW vendor must free any * Upon the deletion of a GID entry, the HW vendor must free any
* allocated memory. The caller will clear @context afterwards. * allocated memory. The caller will clear @context afterwards.
* This function is only called when roce_gid_table is used. * This function is only called when roce_gid_table is used.
*/ */
int (*del_gid)(struct ib_device *device, int (*del_gid)(const struct ib_gid_attr *attr,
u8 port_num,
unsigned int index,
void **context); void **context);
int (*query_pkey)(struct ib_device *device, int (*query_pkey)(struct ib_device *device,
u8 port_num, u16 index, u16 *pkey); u8 port_num, u16 index, u16 *pkey);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment