// SPDX-License-Identifier: GPL-2.0-only // SPDX-FileCopyrightText: Copyright Red Hat #include <linux/bitfield.h> #include <linux/cleanup.h> #include <linux/mutex.h> #include <linux/pci.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/xarray.h> #include "ice_adapter.h" static DEFINE_XARRAY(ice_adapters); static DEFINE_MUTEX(ice_adapters_mutex); /* PCI bus number is 8 bits. Slot is 5 bits. Domain can have the rest. */ #define INDEX_FIELD_DOMAIN … #define INDEX_FIELD_BUS … #define INDEX_FIELD_SLOT … static unsigned long ice_adapter_index(const struct pci_dev *pdev) { … } static struct ice_adapter *ice_adapter_new(void) { … } static void ice_adapter_free(struct ice_adapter *adapter) { … } /** * ice_adapter_get - Get a shared ice_adapter structure. * @pdev: Pointer to the pci_dev whose driver is getting the ice_adapter. * * Gets a pointer to a shared ice_adapter structure. Physical functions (PFs) * of the same multi-function PCI device share one ice_adapter structure. * The ice_adapter is reference-counted. The PF driver must use ice_adapter_put * to release its reference. * * Context: Process, may sleep. * Return: Pointer to ice_adapter on success. * ERR_PTR() on error. -ENOMEM is the only possible error. */ struct ice_adapter *ice_adapter_get(const struct pci_dev *pdev) { … } /** * ice_adapter_put - Release a reference to the shared ice_adapter structure. * @pdev: Pointer to the pci_dev whose driver is releasing the ice_adapter. * * Releases the reference to ice_adapter previously obtained with * ice_adapter_get. * * Context: Process, may sleep. */ void ice_adapter_put(const struct pci_dev *pdev) { … }