Commit 4b5f4d3f authored by Jason Gunthorpe's avatar Jason Gunthorpe
Browse files

RDMA: Split the alloc_hw_stats() ops to port and device variants

This is being used to implement both the port and device global stats,
which is causing some confusion in the drivers. For instance EFA and i40iw
both seem to be misusing the device stats.

Split it into two ops so drivers that don't support one or the other can
leave the op NULL'd, making the calling code a little simpler to
understand.

Link: https://lore.kernel.org/r/1955c154197b2a159adc2dc97266ddc74afe420c.1623427137.git.leonro@nvidia.com


Tested-by: default avatarGal Pressman <galpress@amazon.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@nvidia.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 570d2b99
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -605,10 +605,10 @@ void rdma_counter_init(struct ib_device *dev)
		port_counter->mode.mode = RDMA_COUNTER_MODE_NONE;
		mutex_init(&port_counter->lock);

		if (!dev->ops.alloc_hw_stats)
		if (!dev->ops.alloc_hw_port_stats)
			continue;

		port_counter->hstats = dev->ops.alloc_hw_stats(dev, port);
		port_counter->hstats = dev->ops.alloc_hw_port_stats(dev, port);
		if (!port_counter->hstats)
			goto fail;
	}
+2 −1
Original line number Diff line number Diff line
@@ -2595,7 +2595,8 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
	SET_DEVICE_OP(dev_ops, add_gid);
	SET_DEVICE_OP(dev_ops, advise_mr);
	SET_DEVICE_OP(dev_ops, alloc_dm);
	SET_DEVICE_OP(dev_ops, alloc_hw_stats);
	SET_DEVICE_OP(dev_ops, alloc_hw_device_stats);
	SET_DEVICE_OP(dev_ops, alloc_hw_port_stats);
	SET_DEVICE_OP(dev_ops, alloc_mr);
	SET_DEVICE_OP(dev_ops, alloc_mr_integrity);
	SET_DEVICE_OP(dev_ops, alloc_mw);
+1 −1
Original line number Diff line number Diff line
@@ -2060,7 +2060,7 @@ static int stat_get_doit_default_counter(struct sk_buff *skb,
	if (!device)
		return -EINVAL;

	if (!device->ops.alloc_hw_stats || !device->ops.get_hw_stats) {
	if (!device->ops.alloc_hw_port_stats || !device->ops.get_hw_stats) {
		ret = -EINVAL;
		goto err;
	}
+6 −4
Original line number Diff line number Diff line
@@ -981,8 +981,10 @@ static void setup_hw_stats(struct ib_device *device, struct ib_port *port,
	struct rdma_hw_stats *stats;
	int i, ret;

	stats = device->ops.alloc_hw_stats(device, port_num);

	if (port_num)
		stats = device->ops.alloc_hw_port_stats(device, port_num);
	else
		stats = device->ops.alloc_hw_device_stats(device);
	if (!stats)
		return;

@@ -1165,7 +1167,7 @@ static int add_port(struct ib_core_device *coredev, int port_num)
	 * port, so holder should be device. Therefore skip per port conunter
	 * initialization.
	 */
	if (device->ops.alloc_hw_stats && port_num && is_full_dev)
	if (device->ops.alloc_hw_port_stats && port_num && is_full_dev)
		setup_hw_stats(device, p, port_num);

	list_add_tail(&p->kobj.entry, &coredev->port_list);
@@ -1409,7 +1411,7 @@ int ib_device_register_sysfs(struct ib_device *device)
	if (ret)
		return ret;

	if (device->ops.alloc_hw_stats)
	if (device->ops.alloc_hw_device_stats)
		setup_hw_stats(device, NULL, 0);

	return 0;
+2 −5
Original line number Diff line number Diff line
@@ -234,13 +234,10 @@ int bnxt_re_ib_get_hw_stats(struct ib_device *ibdev,
	return ARRAY_SIZE(bnxt_re_stat_name);
}

struct rdma_hw_stats *bnxt_re_ib_alloc_hw_stats(struct ib_device *ibdev,
struct rdma_hw_stats *bnxt_re_ib_alloc_hw_port_stats(struct ib_device *ibdev,
						     u32 port_num)
{
	BUILD_BUG_ON(ARRAY_SIZE(bnxt_re_stat_name) != BNXT_RE_NUM_COUNTERS);
	/* We support only per port stats */
	if (!port_num)
		return NULL;

	return rdma_alloc_hw_stats_struct(bnxt_re_stat_name,
					  ARRAY_SIZE(bnxt_re_stat_name),
Loading