File Index
Files and directories
Sign in
FILE

driver.c

File preview with syntax highlighting.

linux-6.19.14/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c C
  1// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
  2/* Copyright (c) 2020 Mellanox Technologies Ltd */
  3
  4#include <linux/mlx5/driver.h>
  5#include <linux/mlx5/device.h>
  6#include <linux/mlx5/eswitch.h>
  7#include "mlx5_core.h"
  8#include "dev.h"
  9#include "devlink.h"
 10
 11static int mlx5_core_peer_devlink_set(struct mlx5_sf_dev *sf_dev, struct devlink *devlink)
 12{
 13	struct mlx5_sf_peer_devlink_event_ctx event_ctx = {
 14		.fn_id = sf_dev->fn_id,
 15		.devlink = devlink,
 16	};
 17	int ret;
 18
 19	ret = mlx5_blocking_notifier_call_chain(sf_dev->parent_mdev,
 20						MLX5_DRIVER_EVENT_SF_PEER_DEVLINK,
 21						&event_ctx);
 22	return ret == NOTIFY_OK ? event_ctx.err : 0;
 23}
 24
 25static int mlx5_sf_dev_probe(struct auxiliary_device *adev, const struct auxiliary_device_id *id)
 26{
 27	struct mlx5_sf_dev *sf_dev = container_of(adev, struct mlx5_sf_dev, adev);
 28	struct mlx5_core_dev *mdev;
 29	struct devlink *devlink;
 30	int err;
 31
 32	devlink = mlx5_devlink_alloc(&adev->dev);
 33	if (!devlink)
 34		return -ENOMEM;
 35
 36	mdev = devlink_priv(devlink);
 37	mdev->device = &adev->dev;
 38	mdev->pdev = sf_dev->parent_mdev->pdev;
 39	mdev->bar_addr = sf_dev->bar_base_addr;
 40	mdev->iseg_base = sf_dev->bar_base_addr;
 41	mdev->coredev_type = MLX5_COREDEV_SF;
 42	mdev->priv.parent_mdev = sf_dev->parent_mdev;
 43	mdev->priv.adev_idx = adev->id;
 44	sf_dev->mdev = mdev;
 45
 46	/* Only local SFs do light probe */
 47	if (MLX5_ESWITCH_MANAGER(sf_dev->parent_mdev))
 48		mlx5_dev_set_lightweight(mdev);
 49
 50	err = mlx5_mdev_init(mdev, MLX5_SF_PROF);
 51	if (err) {
 52		mlx5_core_warn(mdev, "mlx5_mdev_init on err=%d\n", err);
 53		goto mdev_err;
 54	}
 55
 56	mdev->iseg = ioremap(mdev->iseg_base, sizeof(*mdev->iseg));
 57	if (!mdev->iseg) {
 58		mlx5_core_warn(mdev, "remap error\n");
 59		err = -ENOMEM;
 60		goto remap_err;
 61	}
 62
 63	/* Peer devlink logic expects to work on unregistered devlink instance. */
 64	err = mlx5_core_peer_devlink_set(sf_dev, devlink);
 65	if (err) {
 66		mlx5_core_warn(mdev, "mlx5_core_peer_devlink_set err=%d\n", err);
 67		goto peer_devlink_set_err;
 68	}
 69
 70	if (MLX5_ESWITCH_MANAGER(sf_dev->parent_mdev))
 71		err = mlx5_init_one_light(mdev);
 72	else
 73		err = mlx5_init_one(mdev);
 74	if (err) {
 75		mlx5_core_warn(mdev, "mlx5_init_one err=%d\n", err);
 76		goto init_one_err;
 77	}
 78
 79	mlx5_vhca_debugfs_init(mdev);
 80	return 0;
 81
 82init_one_err:
 83peer_devlink_set_err:
 84	iounmap(mdev->iseg);
 85remap_err:
 86	mlx5_mdev_uninit(mdev);
 87mdev_err:
 88	mlx5_devlink_free(devlink);
 89	return err;
 90}
 91
 92static void mlx5_sf_dev_remove(struct auxiliary_device *adev)
 93{
 94	struct mlx5_sf_dev *sf_dev = container_of(adev, struct mlx5_sf_dev, adev);
 95	struct mlx5_core_dev *mdev = sf_dev->mdev;
 96	struct devlink *devlink;
 97
 98	devlink = priv_to_devlink(mdev);
 99	set_bit(MLX5_BREAK_FW_WAIT, &mdev->intf_state);
100	mlx5_drain_health_wq(mdev);
101	if (mlx5_dev_is_lightweight(mdev))
102		mlx5_uninit_one_light(mdev);
103	else
104		mlx5_uninit_one(mdev);
105	iounmap(mdev->iseg);
106	mlx5_mdev_uninit(mdev);
107	mlx5_devlink_free(devlink);
108}
109
110static void mlx5_sf_dev_shutdown(struct auxiliary_device *adev)
111{
112	struct mlx5_sf_dev *sf_dev = container_of(adev, struct mlx5_sf_dev, adev);
113	struct mlx5_core_dev *mdev = sf_dev->mdev;
114
115	set_bit(MLX5_BREAK_FW_WAIT, &mdev->intf_state);
116	mlx5_drain_health_wq(mdev);
117	mlx5_unload_one(mdev, false);
118}
119
120static const struct auxiliary_device_id mlx5_sf_dev_id_table[] = {
121	{ .name = MLX5_ADEV_NAME "." MLX5_SF_DEV_ID_NAME, },
122	{ },
123};
124
125MODULE_DEVICE_TABLE(auxiliary, mlx5_sf_dev_id_table);
126
127static struct auxiliary_driver mlx5_sf_driver = {
128	.name = MLX5_SF_DEV_ID_NAME,
129	.probe = mlx5_sf_dev_probe,
130	.remove = mlx5_sf_dev_remove,
131	.shutdown = mlx5_sf_dev_shutdown,
132	.id_table = mlx5_sf_dev_id_table,
133};
134
135int mlx5_sf_driver_register(void)
136{
137	return auxiliary_driver_register(&mlx5_sf_driver);
138}
139
140void mlx5_sf_driver_unregister(void)
141{
142	auxiliary_driver_unregister(&mlx5_sf_driver);
143}
~/ Read-only file preview.