// SPDX-License-Identifier: GPL-2.0-only/* * Thunderbolt driver - NHI driver * * The NHI (native host interface) is the pci device that allows us to send and * receive frames from the thunderbolt bus. * * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com> * Copyright (C) 2018, Intel Corporation */#include<linux/pm_runtime.h>#include<linux/slab.h>#include<linux/errno.h>#include<linux/pci.h>#include<linux/dma-mapping.h>#include<linux/interrupt.h>#include<linux/iommu.h>#include<linux/module.h>#include<linux/delay.h>#include<linux/property.h>#include<linux/string_helpers.h>#include"nhi.h"#include"nhi_regs.h"#include"tb.h"#define RING_TYPE(ring) ((ring)->is_tx ? "TX ring" : "RX ring")#define RING_FIRST_USABLE_HOPID 1/* * Used with QUIRK_E2E to specify an unused HopID the Rx credits are * transferred. */#define RING_E2E_RESERVED_HOPID RING_FIRST_USABLE_HOPID/* * Minimal number of vectors when we use MSI-X. Two for control channel * Rx/Tx and the rest four are for cross domain DMA paths. */#define MSIX_MIN_VECS 6#define MSIX_MAX_VECS 16#define NHI_MAILBOX_TIMEOUT 500 /* ms *//* Host interface quirks */#define QUIRK_AUTO_CLEAR_INT BIT(0)#define QUIRK_E2E BIT(1)staticintring_interrupt_index(conststructtb_ring*ring){intbit=ring->hop;if(!ring->is_tx)bit+=ring->nhi