drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/sh_devlink.c- Extension
.c- Size
- 1476 bytes
- Lines
- 62
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mlx5/driver.hnet/devlink.hsh_devlink.h
Detected Declarations
function mlx5_shd_initfunction mlx5_shd_uninit
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
/* Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
#include <linux/mlx5/driver.h>
#include <net/devlink.h>
#include "sh_devlink.h"
static const struct devlink_ops mlx5_shd_ops = {
};
int mlx5_shd_init(struct mlx5_core_dev *dev)
{
u8 *vpd_data __free(kfree) = NULL;
struct pci_dev *pdev = dev->pdev;
unsigned int vpd_size, kw_len;
struct devlink *devlink;
char *sn, *end;
int start;
int err;
if (!mlx5_core_is_pf(dev))
return 0;
vpd_data = pci_vpd_alloc(pdev, &vpd_size);
if (IS_ERR(vpd_data)) {
err = PTR_ERR(vpd_data);
return err == -ENODEV ? 0 : err;
}
start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, "V3", &kw_len);
if (start < 0) {
/* Fall-back to SN for older devices. */
start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size,
PCI_VPD_RO_KEYWORD_SERIALNO, &kw_len);
if (start < 0)
return 0; /* No usable serial number found, ignore. */
}
sn = kstrndup(vpd_data + start, kw_len, GFP_KERNEL);
if (!sn)
return -ENOMEM;
/* Firmware may return spaces at the end of the string, strip it. */
end = strchrnul(sn, ' ');
*end = '\0';
/* Get or create shared devlink instance */
devlink = devlink_shd_get(sn, &mlx5_shd_ops, 0, pdev->dev.driver);
kfree(sn);
if (!devlink)
return -ENOMEM;
dev->shd = devlink;
return 0;
}
void mlx5_shd_uninit(struct mlx5_core_dev *dev)
{
if (!dev->shd)
return;
devlink_shd_put(dev->shd);
}
Annotation
- Immediate include surface: `linux/mlx5/driver.h`, `net/devlink.h`, `sh_devlink.h`.
- Detected declarations: `function mlx5_shd_init`, `function mlx5_shd_uninit`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.