Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177949265
D61983.1795627673.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
D61983.1795627673.diff
View Options
diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h
--- a/sys/compat/linuxkpi/common/include/linux/pci.h
+++ b/sys/compat/linuxkpi/common/include/linux/pci.h
@@ -144,6 +144,8 @@
#define PCI_EXP_DEVCTL2 PCIER_DEVICE_CTL2 /* Device Control 2 */
#define PCI_EXP_DEVCTL2_LTR_EN PCIEM_CTL2_LTR_ENABLE
#define PCI_EXP_DEVCTL2_COMP_TMOUT_DIS PCIEM_CTL2_COMP_TIMO_DISABLE
+#define PCI_EXP_DEVCTL2_ATOMIC_REQ PCIEM_CTL2_ATOMIC_REQ_ENABLE
+#define PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK PCIEM_CTL2_ATOMIC_EGR_BLOCK
#define PCI_EXP_LNKCAP2 PCIER_LINK_CAP2 /* Link Capabilities 2 */
#define PCI_EXP_LNKCTL2 PCIER_LINK_CTL2 /* Link Control 2 */
#define PCI_EXP_LNKSTA2 PCIER_LINK_STA2 /* Link Status 2 */
@@ -386,6 +388,8 @@
void linuxkpi_pci_release_regions(struct pci_dev *pdev);
int linuxkpi_pci_enable_msix(struct pci_dev *pdev, struct msix_entry *entries,
int nreq);
+int linuxkpi_pci_enable_atomic_ops_to_root(struct pci_dev *pdev,
+ uint32_t cap_mask);
/* Internal helper function(s). */
struct pci_dev *lkpinew_pci_dev(device_t);
@@ -622,6 +626,8 @@
linuxkpi_pci_release_regions(pdev)
#define pcim_request_all_regions(pdev, name) \
linuxkpi_pcim_request_all_regions(pdev, name)
+#define pci_enable_atomic_ops_to_root(pdev, cap_mask) \
+ linuxkpi_pci_enable_atomic_ops_to_root(pdev, cap_mask)
static inline void
lkpi_pci_disable_msix(struct pci_dev *pdev)
diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c
--- a/sys/compat/linuxkpi/common/src/linux_pci.c
+++ b/sys/compat/linuxkpi/common/src/linux_pci.c
@@ -1253,6 +1253,91 @@
return (0);
}
+/*
+ * Enable AtomicOp requests from an endpoint towards its root port.
+ * Modelled after Linux drivers/pci/pci.c:pci_enable_atomic_ops_to_root().
+ *
+ * Returns 0 if all upstream switch ports route AtomicOps, no upstream
+ * switch port blocks AtomicOp egress, and the root port can complete all
+ * sizes in cap_mask (PCI_EXP_DEVCAP2_ATOMIC_COMP{32,64,128}); in that case
+ * AtomicOp Requester Enable is set on the device. Negative errno otherwise.
+ *
+ * Differences from Linux:
+ * - There is no is_virtfn check as LinuxKPI does not expose SR-IOV VFs.
+ * - LinuxKPI may hand out multiple struct pci_dev for the same bridge
+ * (pcie_find_root_port() and pci_upstream_bridge() each allocate their
+ * own via lkpinew_pci_dev()), and a root port's pci_upstream_bridge()
+ * is NULL. Compare the underlying device_t, not pci_dev pointers, and
+ * stop on NULL instead of dereferencing it.
+ */
+int
+linuxkpi_pci_enable_atomic_ops_to_root(struct pci_dev *pdev, uint32_t cap_mask)
+{
+ struct pci_dev *root, *bridge;
+ uint32_t cap, ctl2;
+
+ if (!pci_is_pcie(pdev))
+ return (-EINVAL);
+
+ /*
+ * Per PCIe r7.0, sec 6.15, endpoints and root ports may be
+ * AtomicOp requesters. Like Linux, only support (legacy) endpoints
+ * as requesters and root ports as completers.
+ */
+ switch (pci_pcie_type(pdev)) {
+ case PCI_EXP_TYPE_ENDPOINT:
+ case PCI_EXP_TYPE_LEG_END:
+ break;
+ default:
+ return (-EINVAL);
+ }
+
+ root = pcie_find_root_port(pdev);
+ if (root == NULL) {
+ /*
+ * Root port not visible (e.g., hypervisor). If AtomicOp
+ * Requester Enable is already set, assume whoever set it
+ * verified the path.
+ */
+ pcie_capability_read_dword(pdev, PCI_EXP_DEVCTL2, &ctl2);
+ if ((ctl2 & PCI_EXP_DEVCTL2_ATOMIC_REQ) != 0)
+ return (0);
+ return (-EINVAL);
+ }
+
+ pcie_capability_read_dword(root, PCI_EXP_DEVCAP2, &cap);
+ if ((cap & cap_mask) != cap_mask)
+ return (-EINVAL);
+
+ for (bridge = pci_upstream_bridge(pdev);
+ bridge != NULL && bridge->dev.bsddev != root->dev.bsddev;
+ bridge = pci_upstream_bridge(bridge)) {
+ switch (pci_pcie_type(bridge)) {
+ case PCI_EXP_TYPE_UPSTREAM:
+ /* Upstream ports must not block AtomicOps on egress. */
+ pcie_capability_read_dword(bridge, PCI_EXP_DEVCTL2,
+ &ctl2);
+ if ((ctl2 & PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK) != 0)
+ return (-EINVAL);
+ /* FALLTHROUGH */
+ case PCI_EXP_TYPE_DOWNSTREAM:
+ /* All switch ports need to route AtomicOps. */
+ pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2,
+ &cap);
+ if ((cap & PCI_EXP_DEVCAP2_ATOMIC_ROUTE) == 0)
+ return (-EINVAL);
+ break;
+ }
+ }
+ /* Ran off the top without meeting the root port. */
+ if (bridge == NULL)
+ return (-EINVAL);
+
+ pcie_capability_set_word(pdev, PCI_EXP_DEVCTL2,
+ PCI_EXP_DEVCTL2_ATOMIC_REQ);
+ return (0);
+}
+
int
linuxkpi_pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
{
diff --git a/sys/dev/bnxt/bnxt_re/qplib_res.h b/sys/dev/bnxt/bnxt_re/qplib_res.h
--- a/sys/dev/bnxt/bnxt_re/qplib_res.h
+++ b/sys/dev/bnxt/bnxt_re/qplib_res.h
@@ -71,11 +71,6 @@
(mode) == BNXT_RE_PUSH_MODE_PPP)
#define BNXT_RE_PPP_ENABLED(cctx) ((cctx)->modes.db_push_mode ==\
BNXT_RE_PUSH_MODE_PPP)
-#define PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK 0x0080 /* Block atomic egress */
-#define PCI_EXP_DEVCTL2_ATOMIC_REQ 0x0040 /* Set Atomic requests */
-
-int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask);
-
struct bnxt_qplib_drv_modes {
u8 wqe_mode;
u8 te_bypass;
diff --git a/sys/dev/bnxt/bnxt_re/qplib_res.c b/sys/dev/bnxt/bnxt_re/qplib_res.c
--- a/sys/dev/bnxt/bnxt_re/qplib_res.c
+++ b/sys/dev/bnxt/bnxt_re/qplib_res.c
@@ -1158,62 +1158,6 @@
return 0;
}
-/**
- * pci_enable_atomic_ops_to_root - enable AtomicOp requests to root port
- * @dev: the PCI device
- * @cap_mask: mask of desired AtomicOp sizes, including one or more of:
- * PCI_EXP_DEVCAP2_ATOMIC_COMP32
- * PCI_EXP_DEVCAP2_ATOMIC_COMP64
- * PCI_EXP_DEVCAP2_ATOMIC_COMP128
- *
- * Return 0 if all upstream bridges support AtomicOp routing, egress
- * blocking is disabled on all upstream ports, and the root port supports
- * the requested completion capabilities (32-bit, 64-bit and/or 128-bit
- * AtomicOp completion), or negative otherwise.
- */
-int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)
-{
- struct pci_bus *bus = dev->bus;
- struct pci_dev *bridge;
- u32 cap;
-
- if (!pci_is_pcie(dev))
- return -EINVAL;
-
- /*
- * Per PCIe r4.0, sec 6.15, endpoints and root ports may be
- * AtomicOp requesters. For now, we only support endpoints as
- * requesters and root ports as completers. No endpoints as
- * completers, and no peer-to-peer.
- */
-
- switch (pci_pcie_type(dev)) {
- case PCI_EXP_TYPE_ENDPOINT:
- case PCI_EXP_TYPE_LEG_END:
- break;
- default:
- return -EINVAL;
- }
-
- bridge = bus->self;
-
- pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap);
-
- switch (pci_pcie_type(bridge)) {
- case PCI_EXP_TYPE_DOWNSTREAM:
- if (!(cap & PCI_EXP_DEVCAP2_ATOMIC_ROUTE))
- return -EINVAL;
- break;
-
- /* Ensure root port supports all the sizes we care about */
- case PCI_EXP_TYPE_ROOT_PORT:
- if ((cap & cap_mask) != cap_mask)
- return -EINVAL;
- break;
- }
- return 0;
-}
-
int bnxt_qplib_enable_atomic_ops_to_root(struct pci_dev *dev)
{
u16 ctl2;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 25, 5:27 PM (23 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41995346
Default Alt Text
D61983.1795627673.diff (6 KB)
Attached To
Mode
D61983: linuxkpi: Add pci_enable_atomic_ops_to_root()
Attached
Detach File
Event Timeline