2021-02-17 04:09:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
/* Copyright(c) 2020 Intel Corporation. All rights reserved. */
|
2023-12-21 00:17:36 +00:00
|
|
|
#include <asm-generic/unaligned.h>
|
2021-09-09 05:12:32 +00:00
|
|
|
#include <linux/io-64-nonatomic-lo-hi.h>
|
2022-01-31 23:51:45 +00:00
|
|
|
#include <linux/moduleparam.h>
|
2021-02-17 04:09:50 +00:00
|
|
|
#include <linux/module.h>
|
2022-01-31 23:51:45 +00:00
|
|
|
#include <linux/delay.h>
|
2021-04-17 00:43:30 +00:00
|
|
|
#include <linux/sizes.h>
|
2021-02-17 04:09:52 +00:00
|
|
|
#include <linux/mutex.h>
|
2021-06-04 00:50:36 +00:00
|
|
|
#include <linux/list.h>
|
2021-02-17 04:09:50 +00:00
|
|
|
#include <linux/pci.h>
|
2022-11-29 17:48:59 +00:00
|
|
|
#include <linux/aer.h>
|
2021-02-17 04:09:50 +00:00
|
|
|
#include <linux/io.h>
|
2021-08-02 17:29:38 +00:00
|
|
|
#include "cxlmem.h"
|
2022-01-24 00:30:25 +00:00
|
|
|
#include "cxlpci.h"
|
2021-02-17 04:09:51 +00:00
|
|
|
#include "cxl.h"
|
2023-05-26 09:58:22 +00:00
|
|
|
#include "pmu.h"
|
2021-02-17 04:09:51 +00:00
|
|
|
|
|
|
|
/**
|
cxl: Rename mem to pci
As the driver has undergone development, it's become clear that the
majority [entirety?] of the current functionality in mem.c is actually a
layer encapsulating functionality exposed through PCI based
interactions. This layer can be used either in isolation or to provide
functionality for higher level functionality.
CXL capabilities exist in a parallel domain to PCIe. CXL devices are
enumerable and controllable via "legacy" PCIe mechanisms; however, their
CXL capabilities are a superset of PCIe. For example, a CXL device may
be connected to a non-CXL capable PCIe root port, and therefore will not
be able to participate in CXL.mem or CXL.cache operations, but can still
be accessed through PCIe mechanisms for CXL.io operations.
To properly represent the PCI nature of this driver, and in preparation for
introducing a new driver for the CXL.mem / HDM decoder (Host-managed Device
Memory) capabilities of a CXL memory expander, rename mem.c to pci.c so that
mem.c is available for this new driver.
The result of the change is that there is a clear layering distinction
in the driver, and a systems administrator may load only the cxl_pci
module and gain access to such operations as, firmware update, offline
provisioning of devices, and error collection. In addition to freeing up
the file name for another purpose, there are two primary reasons this is
useful,
1. Acting upon devices which don't have full CXL capabilities. This
may happen for instance if the CXL device is connected in a CXL
unaware part of the platform topology.
2. Userspace-first provisioning for devices without kernel driver
interference. This may be useful when provisioning a new device
in a specific manner that might otherwise be blocked or prevented
by the real CXL mem driver.
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
Link: https://lore.kernel.org/r/20210526174413.802913-1-ben.widawsky@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2021-05-26 17:44:13 +00:00
|
|
|
* DOC: cxl pci
|
2021-02-17 04:09:51 +00:00
|
|
|
*
|
cxl: Rename mem to pci
As the driver has undergone development, it's become clear that the
majority [entirety?] of the current functionality in mem.c is actually a
layer encapsulating functionality exposed through PCI based
interactions. This layer can be used either in isolation or to provide
functionality for higher level functionality.
CXL capabilities exist in a parallel domain to PCIe. CXL devices are
enumerable and controllable via "legacy" PCIe mechanisms; however, their
CXL capabilities are a superset of PCIe. For example, a CXL device may
be connected to a non-CXL capable PCIe root port, and therefore will not
be able to participate in CXL.mem or CXL.cache operations, but can still
be accessed through PCIe mechanisms for CXL.io operations.
To properly represent the PCI nature of this driver, and in preparation for
introducing a new driver for the CXL.mem / HDM decoder (Host-managed Device
Memory) capabilities of a CXL memory expander, rename mem.c to pci.c so that
mem.c is available for this new driver.
The result of the change is that there is a clear layering distinction
in the driver, and a systems administrator may load only the cxl_pci
module and gain access to such operations as, firmware update, offline
provisioning of devices, and error collection. In addition to freeing up
the file name for another purpose, there are two primary reasons this is
useful,
1. Acting upon devices which don't have full CXL capabilities. This
may happen for instance if the CXL device is connected in a CXL
unaware part of the platform topology.
2. Userspace-first provisioning for devices without kernel driver
interference. This may be useful when provisioning a new device
in a specific manner that might otherwise be blocked or prevented
by the real CXL mem driver.
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
Link: https://lore.kernel.org/r/20210526174413.802913-1-ben.widawsky@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2021-05-26 17:44:13 +00:00
|
|
|
* This implements the PCI exclusive functionality for a CXL device as it is
|
|
|
|
* defined by the Compute Express Link specification. CXL devices may surface
|
2021-09-13 16:33:24 +00:00
|
|
|
* certain functionality even if it isn't CXL enabled. While this driver is
|
|
|
|
* focused around the PCI specific aspects of a CXL device, it binds to the
|
|
|
|
* specific CXL memory device class code, and therefore the implementation of
|
|
|
|
* cxl_pci is focused around CXL memory devices.
|
2021-02-17 04:09:51 +00:00
|
|
|
*
|
|
|
|
* The driver has several responsibilities, mainly:
|
|
|
|
* - Create the memX device and register on the CXL bus.
|
|
|
|
* - Enumerate device's register interface and map them.
|
2021-09-13 16:33:24 +00:00
|
|
|
* - Registers nvdimm bridge device with cxl_core.
|
|
|
|
* - Registers a CXL mailbox with cxl_core.
|
2021-02-17 04:09:51 +00:00
|
|
|
*/
|
|
|
|
|
2021-11-02 20:29:01 +00:00
|
|
|
#define cxl_doorbell_busy(cxlds) \
|
|
|
|
(readl((cxlds)->regs.mbox + CXLDEV_MBOX_CTRL_OFFSET) & \
|
2021-02-17 04:09:51 +00:00
|
|
|
CXLDEV_MBOX_CTRL_DOORBELL)
|
|
|
|
|
|
|
|
/* CXL 2.0 - 8.2.8.4 */
|
|
|
|
#define CXL_MAILBOX_TIMEOUT_MS (2 * HZ)
|
|
|
|
|
2022-01-31 23:51:45 +00:00
|
|
|
/*
|
|
|
|
* CXL 2.0 ECN "Add Mailbox Ready Time" defines a capability field to
|
|
|
|
* dictate how long to wait for the mailbox to become ready. The new
|
|
|
|
* field allows the device to tell software the amount of time to wait
|
|
|
|
* before mailbox ready. This field per the spec theoretically allows
|
|
|
|
* for up to 255 seconds. 255 seconds is unreasonably long, its longer
|
|
|
|
* than the maximum SATA port link recovery wait. Default to 60 seconds
|
|
|
|
* until someone builds a CXL device that needs more time in practice.
|
|
|
|
*/
|
|
|
|
static unsigned short mbox_ready_timeout = 60;
|
|
|
|
module_param(mbox_ready_timeout, ushort, 0644);
|
2022-05-18 23:34:43 +00:00
|
|
|
MODULE_PARM_DESC(mbox_ready_timeout, "seconds to wait for mailbox ready");
|
2022-01-31 23:51:45 +00:00
|
|
|
|
2021-11-02 20:29:01 +00:00
|
|
|
static int cxl_pci_mbox_wait_for_doorbell(struct cxl_dev_state *cxlds)
|
2021-02-17 04:09:51 +00:00
|
|
|
{
|
|
|
|
const unsigned long start = jiffies;
|
|
|
|
unsigned long end = start;
|
|
|
|
|
2021-11-02 20:29:01 +00:00
|
|
|
while (cxl_doorbell_busy(cxlds)) {
|
2021-02-17 04:09:51 +00:00
|
|
|
end = jiffies;
|
|
|
|
|
|
|
|
if (time_after(end, start + CXL_MAILBOX_TIMEOUT_MS)) {
|
|
|
|
/* Check again in case preempted before timeout test */
|
2021-11-02 20:29:01 +00:00
|
|
|
if (!cxl_doorbell_busy(cxlds))
|
2021-02-17 04:09:51 +00:00
|
|
|
break;
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
|
2021-11-02 20:29:01 +00:00
|
|
|
dev_dbg(cxlds->dev, "Doorbell wait took %dms",
|
2021-02-17 04:09:51 +00:00
|
|
|
jiffies_to_msecs(end) - jiffies_to_msecs(start));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-24 00:28:54 +00:00
|
|
|
#define cxl_err(dev, status, msg) \
|
|
|
|
dev_err_ratelimited(dev, msg ", device state %s%s\n", \
|
|
|
|
status & CXLMDEV_DEV_FATAL ? " fatal" : "", \
|
|
|
|
status & CXLMDEV_FW_HALT ? " firmware-halt" : "")
|
2021-02-17 04:09:51 +00:00
|
|
|
|
2022-01-24 00:28:54 +00:00
|
|
|
#define cxl_cmd_err(dev, cmd, status, msg) \
|
|
|
|
dev_err_ratelimited(dev, msg " (opcode: %#x), device state %s%s\n", \
|
|
|
|
(cmd)->opcode, \
|
|
|
|
status & CXLMDEV_DEV_FATAL ? " fatal" : "", \
|
|
|
|
status & CXLMDEV_FW_HALT ? " firmware-halt" : "")
|
2021-02-17 04:09:51 +00:00
|
|
|
|
2023-05-17 21:28:11 +00:00
|
|
|
/*
|
|
|
|
* Threaded irq dev_id's must be globally unique. cxl_dev_id provides a unique
|
|
|
|
* wrapper object for each irq within the same cxlds.
|
|
|
|
*/
|
2023-05-23 17:09:26 +00:00
|
|
|
struct cxl_dev_id {
|
|
|
|
struct cxl_dev_state *cxlds;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int cxl_request_irq(struct cxl_dev_state *cxlds, int irq,
|
2023-10-04 03:12:12 +00:00
|
|
|
irq_handler_t thread_fn)
|
2023-05-23 17:09:26 +00:00
|
|
|
{
|
|
|
|
struct device *dev = cxlds->dev;
|
|
|
|
struct cxl_dev_id *dev_id;
|
|
|
|
|
|
|
|
dev_id = devm_kzalloc(dev, sizeof(*dev_id), GFP_KERNEL);
|
|
|
|
if (!dev_id)
|
|
|
|
return -ENOMEM;
|
|
|
|
dev_id->cxlds = cxlds;
|
|
|
|
|
2023-10-04 03:12:12 +00:00
|
|
|
return devm_request_threaded_irq(dev, irq, NULL, thread_fn,
|
|
|
|
IRQF_SHARED | IRQF_ONESHOT, NULL,
|
|
|
|
dev_id);
|
2023-05-23 17:09:26 +00:00
|
|
|
}
|
|
|
|
|
2023-05-23 17:09:27 +00:00
|
|
|
static bool cxl_mbox_background_complete(struct cxl_dev_state *cxlds)
|
|
|
|
{
|
|
|
|
u64 reg;
|
|
|
|
|
|
|
|
reg = readq(cxlds->regs.mbox + CXLDEV_MBOX_BG_CMD_STATUS_OFFSET);
|
|
|
|
return FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_PCT_MASK, reg) == 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t cxl_pci_mbox_irq(int irq, void *id)
|
|
|
|
{
|
2023-06-12 18:10:34 +00:00
|
|
|
u64 reg;
|
|
|
|
u16 opcode;
|
2023-05-23 17:09:27 +00:00
|
|
|
struct cxl_dev_id *dev_id = id;
|
|
|
|
struct cxl_dev_state *cxlds = dev_id->cxlds;
|
2023-06-26 00:16:51 +00:00
|
|
|
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
|
2023-05-23 17:09:27 +00:00
|
|
|
|
2023-06-12 18:10:32 +00:00
|
|
|
if (!cxl_mbox_background_complete(cxlds))
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
2023-06-12 18:10:34 +00:00
|
|
|
reg = readq(cxlds->regs.mbox + CXLDEV_MBOX_BG_CMD_STATUS_OFFSET);
|
|
|
|
opcode = FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_OPCODE_MASK, reg);
|
|
|
|
if (opcode == CXL_MBOX_OP_SANITIZE) {
|
2023-09-29 19:44:20 +00:00
|
|
|
mutex_lock(&mds->mbox_mutex);
|
2023-06-26 00:16:51 +00:00
|
|
|
if (mds->security.sanitize_node)
|
2023-09-29 19:44:20 +00:00
|
|
|
mod_delayed_work(system_wq, &mds->security.poll_dwork, 0);
|
|
|
|
mutex_unlock(&mds->mbox_mutex);
|
2023-06-12 18:10:34 +00:00
|
|
|
} else {
|
|
|
|
/* short-circuit the wait in __cxl_pci_mbox_send_cmd() */
|
2023-06-26 00:16:51 +00:00
|
|
|
rcuwait_wake_up(&mds->mbox_wait);
|
2023-06-12 18:10:34 +00:00
|
|
|
}
|
2023-05-23 17:09:27 +00:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2023-06-12 18:10:34 +00:00
|
|
|
/*
|
|
|
|
* Sanitization operation polling mode.
|
|
|
|
*/
|
|
|
|
static void cxl_mbox_sanitize_work(struct work_struct *work)
|
|
|
|
{
|
2023-06-26 00:16:51 +00:00
|
|
|
struct cxl_memdev_state *mds =
|
|
|
|
container_of(work, typeof(*mds), security.poll_dwork.work);
|
|
|
|
struct cxl_dev_state *cxlds = &mds->cxlds;
|
2023-06-12 18:10:34 +00:00
|
|
|
|
2023-06-26 00:16:51 +00:00
|
|
|
mutex_lock(&mds->mbox_mutex);
|
2023-06-12 18:10:34 +00:00
|
|
|
if (cxl_mbox_background_complete(cxlds)) {
|
2023-06-26 00:16:51 +00:00
|
|
|
mds->security.poll_tmo_secs = 0;
|
|
|
|
if (mds->security.sanitize_node)
|
|
|
|
sysfs_notify_dirent(mds->security.sanitize_node);
|
2023-10-05 01:35:01 +00:00
|
|
|
mds->security.sanitize_active = false;
|
2023-06-12 18:10:35 +00:00
|
|
|
|
2023-06-12 18:10:34 +00:00
|
|
|
dev_dbg(cxlds->dev, "Sanitization operation ended\n");
|
|
|
|
} else {
|
2023-06-26 00:16:51 +00:00
|
|
|
int timeout = mds->security.poll_tmo_secs + 10;
|
2023-06-12 18:10:34 +00:00
|
|
|
|
2023-06-26 00:16:51 +00:00
|
|
|
mds->security.poll_tmo_secs = min(15 * 60, timeout);
|
2023-09-29 19:44:20 +00:00
|
|
|
schedule_delayed_work(&mds->security.poll_dwork, timeout * HZ);
|
2023-06-12 18:10:34 +00:00
|
|
|
}
|
2023-06-26 00:16:51 +00:00
|
|
|
mutex_unlock(&mds->mbox_mutex);
|
2023-06-12 18:10:34 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 04:09:51 +00:00
|
|
|
/**
|
2021-09-13 16:33:24 +00:00
|
|
|
* __cxl_pci_mbox_send_cmd() - Execute a mailbox command
|
2023-06-15 01:30:02 +00:00
|
|
|
* @mds: The memory device driver data
|
2021-02-17 04:09:51 +00:00
|
|
|
* @mbox_cmd: Command to send to the memory device.
|
|
|
|
*
|
|
|
|
* Context: Any context. Expects mbox_mutex to be held.
|
|
|
|
* Return: -ETIMEDOUT if timeout occurred waiting for completion. 0 on success.
|
|
|
|
* Caller should check the return code in @mbox_cmd to make sure it
|
|
|
|
* succeeded.
|
|
|
|
*
|
|
|
|
* This is a generic form of the CXL mailbox send command thus only using the
|
|
|
|
* registers defined by the mailbox capability ID - CXL 2.0 8.2.8.4. Memory
|
|
|
|
* devices, and perhaps other types of CXL devices may have further information
|
|
|
|
* available upon error conditions. Driver facilities wishing to send mailbox
|
|
|
|
* commands should use the wrapper command.
|
|
|
|
*
|
|
|
|
* The CXL spec allows for up to two mailboxes. The intention is for the primary
|
|
|
|
* mailbox to be OS controlled and the secondary mailbox to be used by system
|
|
|
|
* firmware. This allows the OS and firmware to communicate with the device and
|
|
|
|
* not need to coordinate with each other. The driver only uses the primary
|
|
|
|
* mailbox.
|
|
|
|
*/
|
2023-06-15 01:30:02 +00:00
|
|
|
static int __cxl_pci_mbox_send_cmd(struct cxl_memdev_state *mds,
|
2021-09-09 05:12:21 +00:00
|
|
|
struct cxl_mbox_cmd *mbox_cmd)
|
2021-02-17 04:09:51 +00:00
|
|
|
{
|
2023-06-15 01:30:02 +00:00
|
|
|
struct cxl_dev_state *cxlds = &mds->cxlds;
|
2021-11-02 20:29:01 +00:00
|
|
|
void __iomem *payload = cxlds->regs.mbox + CXLDEV_MBOX_PAYLOAD_OFFSET;
|
|
|
|
struct device *dev = cxlds->dev;
|
2021-02-17 04:09:51 +00:00
|
|
|
u64 cmd_reg, status_reg;
|
|
|
|
size_t out_len;
|
|
|
|
int rc;
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
lockdep_assert_held(&mds->mbox_mutex);
|
2021-02-17 04:09:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Here are the steps from 8.2.8.4 of the CXL 2.0 spec.
|
|
|
|
* 1. Caller reads MB Control Register to verify doorbell is clear
|
|
|
|
* 2. Caller writes Command Register
|
|
|
|
* 3. Caller writes Command Payload Registers if input payload is non-empty
|
|
|
|
* 4. Caller writes MB Control Register to set doorbell
|
|
|
|
* 5. Caller either polls for doorbell to be clear or waits for interrupt if configured
|
|
|
|
* 6. Caller reads MB Status Register to fetch Return code
|
|
|
|
* 7. If command successful, Caller reads Command Register to get Payload Length
|
|
|
|
* 8. If output payload is non-empty, host reads Command Payload Registers
|
|
|
|
*
|
|
|
|
* Hardware is free to do whatever it wants before the doorbell is rung,
|
|
|
|
* and isn't allowed to change anything after it clears the doorbell. As
|
|
|
|
* such, steps 2 and 3 can happen in any order, and steps 6, 7, 8 can
|
|
|
|
* also happen in any order (though some orders might not make sense).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* #1 */
|
2021-11-02 20:29:01 +00:00
|
|
|
if (cxl_doorbell_busy(cxlds)) {
|
2022-01-24 00:28:54 +00:00
|
|
|
u64 md_status =
|
|
|
|
readq(cxlds->regs.memdev + CXLMDEV_STATUS_OFFSET);
|
|
|
|
|
|
|
|
cxl_cmd_err(cxlds->dev, mbox_cmd, md_status,
|
|
|
|
"mailbox queue busy");
|
2021-02-17 04:09:51 +00:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2023-06-12 18:10:34 +00:00
|
|
|
/*
|
|
|
|
* With sanitize polling, hardware might be done and the poller still
|
|
|
|
* not be in sync. Ensure no new command comes in until so. Keep the
|
|
|
|
* hardware semantics and only allow device health status.
|
|
|
|
*/
|
2023-06-26 00:16:51 +00:00
|
|
|
if (mds->security.poll_tmo_secs > 0) {
|
2023-06-12 18:10:34 +00:00
|
|
|
if (mbox_cmd->opcode != CXL_MBOX_OP_GET_HEALTH_INFO)
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2021-02-17 04:09:51 +00:00
|
|
|
cmd_reg = FIELD_PREP(CXLDEV_MBOX_CMD_COMMAND_OPCODE_MASK,
|
|
|
|
mbox_cmd->opcode);
|
|
|
|
if (mbox_cmd->size_in) {
|
|
|
|
if (WARN_ON(!mbox_cmd->payload_in))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
cmd_reg |= FIELD_PREP(CXLDEV_MBOX_CMD_PAYLOAD_LENGTH_MASK,
|
|
|
|
mbox_cmd->size_in);
|
|
|
|
memcpy_toio(payload, mbox_cmd->payload_in, mbox_cmd->size_in);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* #2, #3 */
|
2021-11-02 20:29:01 +00:00
|
|
|
writeq(cmd_reg, cxlds->regs.mbox + CXLDEV_MBOX_CMD_OFFSET);
|
2021-02-17 04:09:51 +00:00
|
|
|
|
|
|
|
/* #4 */
|
2023-01-03 21:01:50 +00:00
|
|
|
dev_dbg(dev, "Sending command: 0x%04x\n", mbox_cmd->opcode);
|
2021-02-17 04:09:51 +00:00
|
|
|
writel(CXLDEV_MBOX_CTRL_DOORBELL,
|
2021-11-02 20:29:01 +00:00
|
|
|
cxlds->regs.mbox + CXLDEV_MBOX_CTRL_OFFSET);
|
2021-02-17 04:09:51 +00:00
|
|
|
|
|
|
|
/* #5 */
|
2021-11-02 20:29:01 +00:00
|
|
|
rc = cxl_pci_mbox_wait_for_doorbell(cxlds);
|
2021-02-17 04:09:51 +00:00
|
|
|
if (rc == -ETIMEDOUT) {
|
2022-01-24 00:28:54 +00:00
|
|
|
u64 md_status = readq(cxlds->regs.memdev + CXLMDEV_STATUS_OFFSET);
|
|
|
|
|
|
|
|
cxl_cmd_err(cxlds->dev, mbox_cmd, md_status, "mailbox timeout");
|
2021-02-17 04:09:51 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* #6 */
|
2021-11-02 20:29:01 +00:00
|
|
|
status_reg = readq(cxlds->regs.mbox + CXLDEV_MBOX_STATUS_OFFSET);
|
2021-02-17 04:09:51 +00:00
|
|
|
mbox_cmd->return_code =
|
|
|
|
FIELD_GET(CXLDEV_MBOX_STATUS_RET_CODE_MASK, status_reg);
|
|
|
|
|
2023-05-23 17:09:27 +00:00
|
|
|
/*
|
|
|
|
* Handle the background command in a synchronous manner.
|
|
|
|
*
|
|
|
|
* All other mailbox commands will serialize/queue on the mbox_mutex,
|
|
|
|
* which we currently hold. Furthermore this also guarantees that
|
|
|
|
* cxl_mbox_background_complete() checks are safe amongst each other,
|
|
|
|
* in that no new bg operation can occur in between.
|
|
|
|
*
|
|
|
|
* Background operations are timesliced in accordance with the nature
|
|
|
|
* of the command. In the event of timeout, the mailbox state is
|
|
|
|
* indeterminate until the next successful command submission and the
|
|
|
|
* driver can get back in sync with the hardware state.
|
|
|
|
*/
|
|
|
|
if (mbox_cmd->return_code == CXL_MBOX_CMD_RC_BACKGROUND) {
|
|
|
|
u64 bg_status_reg;
|
2023-06-12 18:10:34 +00:00
|
|
|
int i, timeout;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanitization is a special case which monopolizes the device
|
|
|
|
* and cannot be timesliced. Handle asynchronously instead,
|
|
|
|
* and allow userspace to poll(2) for completion.
|
|
|
|
*/
|
|
|
|
if (mbox_cmd->opcode == CXL_MBOX_OP_SANITIZE) {
|
2023-10-05 01:35:01 +00:00
|
|
|
if (mds->security.sanitize_active)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2023-09-29 19:44:20 +00:00
|
|
|
/* give first timeout a second */
|
|
|
|
timeout = 1;
|
|
|
|
mds->security.poll_tmo_secs = timeout;
|
2023-10-05 01:35:01 +00:00
|
|
|
mds->security.sanitize_active = true;
|
2023-09-29 19:44:20 +00:00
|
|
|
schedule_delayed_work(&mds->security.poll_dwork,
|
|
|
|
timeout * HZ);
|
2023-06-12 18:10:34 +00:00
|
|
|
dev_dbg(dev, "Sanitization operation started\n");
|
|
|
|
goto success;
|
|
|
|
}
|
2023-05-23 17:09:27 +00:00
|
|
|
|
|
|
|
dev_dbg(dev, "Mailbox background operation (0x%04x) started\n",
|
|
|
|
mbox_cmd->opcode);
|
|
|
|
|
2023-06-12 18:10:34 +00:00
|
|
|
timeout = mbox_cmd->poll_interval_ms;
|
2023-05-23 17:09:27 +00:00
|
|
|
for (i = 0; i < mbox_cmd->poll_count; i++) {
|
2023-06-26 00:16:51 +00:00
|
|
|
if (rcuwait_wait_event_timeout(&mds->mbox_wait,
|
2023-05-23 17:09:27 +00:00
|
|
|
cxl_mbox_background_complete(cxlds),
|
|
|
|
TASK_UNINTERRUPTIBLE,
|
|
|
|
msecs_to_jiffies(timeout)) > 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cxl_mbox_background_complete(cxlds)) {
|
|
|
|
dev_err(dev, "timeout waiting for background (%d ms)\n",
|
|
|
|
timeout * mbox_cmd->poll_count);
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
bg_status_reg = readq(cxlds->regs.mbox +
|
|
|
|
CXLDEV_MBOX_BG_CMD_STATUS_OFFSET);
|
|
|
|
mbox_cmd->return_code =
|
|
|
|
FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_RC_MASK,
|
|
|
|
bg_status_reg);
|
|
|
|
dev_dbg(dev,
|
|
|
|
"Mailbox background operation (0x%04x) completed\n",
|
|
|
|
mbox_cmd->opcode);
|
|
|
|
}
|
|
|
|
|
2022-04-04 02:12:15 +00:00
|
|
|
if (mbox_cmd->return_code != CXL_MBOX_CMD_RC_SUCCESS) {
|
2022-04-04 02:12:16 +00:00
|
|
|
dev_dbg(dev, "Mailbox operation had an error: %s\n",
|
|
|
|
cxl_mbox_cmd_rc2str(mbox_cmd));
|
2022-04-04 02:12:14 +00:00
|
|
|
return 0; /* completed but caller must check return_code */
|
2021-02-17 04:09:51 +00:00
|
|
|
}
|
|
|
|
|
2023-06-12 18:10:34 +00:00
|
|
|
success:
|
2021-02-17 04:09:51 +00:00
|
|
|
/* #7 */
|
2021-11-02 20:29:01 +00:00
|
|
|
cmd_reg = readq(cxlds->regs.mbox + CXLDEV_MBOX_CMD_OFFSET);
|
2021-02-17 04:09:51 +00:00
|
|
|
out_len = FIELD_GET(CXLDEV_MBOX_CMD_PAYLOAD_LENGTH_MASK, cmd_reg);
|
|
|
|
|
|
|
|
/* #8 */
|
|
|
|
if (out_len && mbox_cmd->payload_out) {
|
|
|
|
/*
|
|
|
|
* Sanitize the copy. If hardware misbehaves, out_len per the
|
|
|
|
* spec can actually be greater than the max allowed size (21
|
|
|
|
* bits available but spec defined 1M max). The caller also may
|
|
|
|
* have requested less data than the hardware supplied even
|
|
|
|
* within spec.
|
|
|
|
*/
|
2023-06-15 01:30:02 +00:00
|
|
|
size_t n;
|
2021-02-17 04:09:51 +00:00
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
n = min3(mbox_cmd->size_out, mds->payload_size, out_len);
|
2021-02-17 04:09:51 +00:00
|
|
|
memcpy_fromio(mbox_cmd->payload_out, payload, n);
|
|
|
|
mbox_cmd->size_out = n;
|
|
|
|
} else {
|
|
|
|
mbox_cmd->size_out = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
static int cxl_pci_mbox_send(struct cxl_memdev_state *mds,
|
|
|
|
struct cxl_mbox_cmd *cmd)
|
2021-09-09 05:12:21 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
mutex_lock_io(&mds->mbox_mutex);
|
|
|
|
rc = __cxl_pci_mbox_send_cmd(mds, cmd);
|
|
|
|
mutex_unlock(&mds->mbox_mutex);
|
2021-09-09 05:12:21 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2024-01-18 01:24:01 +00:00
|
|
|
static int cxl_pci_setup_mailbox(struct cxl_memdev_state *mds, bool irq_avail)
|
2021-02-17 04:09:51 +00:00
|
|
|
{
|
2023-06-15 01:30:02 +00:00
|
|
|
struct cxl_dev_state *cxlds = &mds->cxlds;
|
2021-11-02 20:29:01 +00:00
|
|
|
const int cap = readl(cxlds->regs.mbox + CXLDEV_MBOX_CAPS_OFFSET);
|
2023-06-15 01:30:02 +00:00
|
|
|
struct device *dev = cxlds->dev;
|
2022-01-31 23:51:45 +00:00
|
|
|
unsigned long timeout;
|
2023-09-29 19:44:20 +00:00
|
|
|
int irq, msgnum;
|
2022-01-31 23:51:45 +00:00
|
|
|
u64 md_status;
|
2023-09-29 19:44:20 +00:00
|
|
|
u32 ctrl;
|
2022-01-31 23:51:45 +00:00
|
|
|
|
|
|
|
timeout = jiffies + mbox_ready_timeout * HZ;
|
|
|
|
do {
|
|
|
|
md_status = readq(cxlds->regs.memdev + CXLMDEV_STATUS_OFFSET);
|
|
|
|
if (md_status & CXLMDEV_MBOX_IF_READY)
|
|
|
|
break;
|
|
|
|
if (msleep_interruptible(100))
|
|
|
|
break;
|
|
|
|
} while (!time_after(jiffies, timeout));
|
|
|
|
|
|
|
|
if (!(md_status & CXLMDEV_MBOX_IF_READY)) {
|
2023-06-15 01:30:02 +00:00
|
|
|
cxl_err(dev, md_status, "timeout awaiting mailbox ready");
|
2022-01-24 00:28:54 +00:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A command may be in flight from a previous driver instance,
|
|
|
|
* think kexec, do one doorbell wait so that
|
|
|
|
* __cxl_pci_mbox_send_cmd() can assume that it is the only
|
|
|
|
* source for future doorbell busy events.
|
|
|
|
*/
|
|
|
|
if (cxl_pci_mbox_wait_for_doorbell(cxlds) != 0) {
|
2023-06-15 01:30:02 +00:00
|
|
|
cxl_err(dev, md_status, "timeout awaiting mailbox idle");
|
2022-01-24 00:28:54 +00:00
|
|
|
return -ETIMEDOUT;
|
2022-01-31 23:51:45 +00:00
|
|
|
}
|
2021-02-17 04:09:51 +00:00
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
mds->mbox_send = cxl_pci_mbox_send;
|
|
|
|
mds->payload_size =
|
2021-02-17 04:09:51 +00:00
|
|
|
1 << FIELD_GET(CXLDEV_MBOX_CAP_PAYLOAD_SIZE_MASK, cap);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register
|
|
|
|
*
|
|
|
|
* If the size is too small, mandatory commands will not work and so
|
|
|
|
* there's no point in going forward. If the size is too large, there's
|
|
|
|
* no harm is soft limiting it.
|
|
|
|
*/
|
2023-06-15 01:30:02 +00:00
|
|
|
mds->payload_size = min_t(size_t, mds->payload_size, SZ_1M);
|
|
|
|
if (mds->payload_size < 256) {
|
|
|
|
dev_err(dev, "Mailbox is too small (%zub)",
|
|
|
|
mds->payload_size);
|
2021-02-17 04:09:51 +00:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
dev_dbg(dev, "Mailbox payload sized %zu", mds->payload_size);
|
2021-02-17 04:09:51 +00:00
|
|
|
|
2023-06-26 00:16:51 +00:00
|
|
|
rcuwait_init(&mds->mbox_wait);
|
2023-09-29 19:44:20 +00:00
|
|
|
INIT_DELAYED_WORK(&mds->security.poll_dwork, cxl_mbox_sanitize_work);
|
2023-05-23 17:09:27 +00:00
|
|
|
|
2023-09-29 19:44:20 +00:00
|
|
|
/* background command interrupts are optional */
|
2024-01-18 01:24:01 +00:00
|
|
|
if (!(cap & CXLDEV_MBOX_CAP_BG_CMD_IRQ) || !irq_avail)
|
2023-09-29 19:44:20 +00:00
|
|
|
return 0;
|
2023-05-23 17:09:27 +00:00
|
|
|
|
2023-09-29 19:44:20 +00:00
|
|
|
msgnum = FIELD_GET(CXLDEV_MBOX_CAP_IRQ_MSGNUM_MASK, cap);
|
|
|
|
irq = pci_irq_vector(to_pci_dev(cxlds->dev), msgnum);
|
|
|
|
if (irq < 0)
|
|
|
|
return 0;
|
2023-05-23 17:09:27 +00:00
|
|
|
|
2023-10-04 03:12:12 +00:00
|
|
|
if (cxl_request_irq(cxlds, irq, cxl_pci_mbox_irq))
|
2023-05-23 17:09:27 +00:00
|
|
|
return 0;
|
|
|
|
|
2023-09-29 19:44:20 +00:00
|
|
|
dev_dbg(cxlds->dev, "Mailbox interrupts enabled\n");
|
|
|
|
/* enable background command mbox irq support */
|
|
|
|
ctrl = readl(cxlds->regs.mbox + CXLDEV_MBOX_CTRL_OFFSET);
|
|
|
|
ctrl |= CXLDEV_MBOX_CTRL_BG_CMD_IRQ;
|
|
|
|
writel(ctrl, cxlds->regs.mbox + CXLDEV_MBOX_CTRL_OFFSET);
|
2023-06-12 18:10:34 +00:00
|
|
|
|
2021-02-17 04:09:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-06-22 20:55:09 +00:00
|
|
|
/*
|
|
|
|
* Assume that any RCIEP that emits the CXL memory expander class code
|
|
|
|
* is an RCD
|
|
|
|
*/
|
|
|
|
static bool is_cxl_restricted(struct pci_dev *pdev)
|
2021-04-07 22:26:20 +00:00
|
|
|
{
|
2023-06-22 20:55:09 +00:00
|
|
|
return pci_pcie_type(pdev) == PCI_EXP_TYPE_RC_END;
|
2021-06-04 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-22 20:55:09 +00:00
|
|
|
static int cxl_rcrb_get_comp_regs(struct pci_dev *pdev,
|
|
|
|
struct cxl_register_map *map)
|
2021-06-04 00:50:36 +00:00
|
|
|
{
|
2023-06-22 20:55:09 +00:00
|
|
|
struct cxl_port *port;
|
|
|
|
struct cxl_dport *dport;
|
|
|
|
resource_size_t component_reg_phys;
|
2021-02-17 04:09:50 +00:00
|
|
|
|
2023-06-22 20:55:09 +00:00
|
|
|
*map = (struct cxl_register_map) {
|
2023-10-18 17:16:55 +00:00
|
|
|
.host = &pdev->dev,
|
2023-06-22 20:55:09 +00:00
|
|
|
.resource = CXL_RESOURCE_NONE,
|
|
|
|
};
|
2021-05-28 00:49:22 +00:00
|
|
|
|
2023-06-22 20:55:09 +00:00
|
|
|
port = cxl_pci_find_port(pdev, &dport);
|
|
|
|
if (!port)
|
|
|
|
return -EPROBE_DEFER;
|
2021-06-04 00:50:36 +00:00
|
|
|
|
2023-06-22 20:55:09 +00:00
|
|
|
component_reg_phys = cxl_rcd_component_reg_phys(&pdev->dev, dport);
|
|
|
|
|
|
|
|
put_device(&port->dev);
|
|
|
|
|
|
|
|
if (component_reg_phys == CXL_RESOURCE_NONE)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
map->resource = component_reg_phys;
|
|
|
|
map->reg_type = CXL_REGLOC_RBI_COMPONENT;
|
|
|
|
map->max_size = CXL_COMPONENT_REG_BLOCK_SIZE;
|
2021-06-04 00:50:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-06-22 20:55:03 +00:00
|
|
|
static int cxl_pci_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type,
|
|
|
|
struct cxl_register_map *map)
|
2021-10-15 23:30:42 +00:00
|
|
|
{
|
|
|
|
int rc;
|
2021-07-16 23:15:47 +00:00
|
|
|
|
2021-10-15 23:30:42 +00:00
|
|
|
rc = cxl_find_regblock(pdev, type, map);
|
2021-04-07 22:26:21 +00:00
|
|
|
|
2023-06-22 20:55:09 +00:00
|
|
|
/*
|
|
|
|
* If the Register Locator DVSEC does not exist, check if it
|
|
|
|
* is an RCH and try to extract the Component Registers from
|
|
|
|
* an RCRB.
|
|
|
|
*/
|
|
|
|
if (rc && type == CXL_REGLOC_RBI_COMPONENT && is_cxl_restricted(pdev))
|
|
|
|
rc = cxl_rcrb_get_comp_regs(pdev, map);
|
|
|
|
|
2021-10-15 23:30:42 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2023-06-22 20:55:03 +00:00
|
|
|
return cxl_setup_regs(map);
|
2022-12-01 21:34:16 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 17:00:24 +00:00
|
|
|
static int cxl_pci_ras_unmask(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
|
|
|
|
void __iomem *addr;
|
|
|
|
u32 orig_val, val, mask;
|
|
|
|
u16 cap;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!cxlds->regs.ras) {
|
|
|
|
dev_dbg(&pdev->dev, "No RAS registers.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-08-23 23:43:03 +00:00
|
|
|
/* BIOS has PCIe AER error control */
|
2023-08-23 23:43:05 +00:00
|
|
|
if (!pcie_aer_is_native(pdev))
|
2023-08-23 23:43:03 +00:00
|
|
|
return 0;
|
2023-02-14 17:00:24 +00:00
|
|
|
|
|
|
|
rc = pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &cap);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (cap & PCI_EXP_DEVCTL_URRE) {
|
|
|
|
addr = cxlds->regs.ras + CXL_RAS_UNCORRECTABLE_MASK_OFFSET;
|
|
|
|
orig_val = readl(addr);
|
|
|
|
|
2023-06-15 01:30:31 +00:00
|
|
|
mask = CXL_RAS_UNCORRECTABLE_MASK_MASK |
|
|
|
|
CXL_RAS_UNCORRECTABLE_MASK_F256B_MASK;
|
2023-02-14 17:00:24 +00:00
|
|
|
val = orig_val & ~mask;
|
|
|
|
writel(val, addr);
|
|
|
|
dev_dbg(&pdev->dev,
|
|
|
|
"Uncorrectable RAS Errors Mask: %#x -> %#x\n",
|
|
|
|
orig_val, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cap & PCI_EXP_DEVCTL_CERE) {
|
|
|
|
addr = cxlds->regs.ras + CXL_RAS_CORRECTABLE_MASK_OFFSET;
|
|
|
|
orig_val = readl(addr);
|
|
|
|
val = orig_val & ~CXL_RAS_CORRECTABLE_MASK_MASK;
|
|
|
|
writel(val, addr);
|
|
|
|
dev_dbg(&pdev->dev, "Correctable RAS Errors Mask: %#x -> %#x\n",
|
|
|
|
orig_val, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2022-11-29 17:48:59 +00:00
|
|
|
}
|
|
|
|
|
2023-01-18 05:53:36 +00:00
|
|
|
static void free_event_buf(void *buf)
|
|
|
|
{
|
|
|
|
kvfree(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There is a single buffer for reading event logs from the mailbox. All logs
|
2023-06-15 01:30:02 +00:00
|
|
|
* share this buffer protected by the mds->event_log_lock.
|
2023-01-18 05:53:36 +00:00
|
|
|
*/
|
2023-06-15 01:30:02 +00:00
|
|
|
static int cxl_mem_alloc_event_buf(struct cxl_memdev_state *mds)
|
2023-01-18 05:53:36 +00:00
|
|
|
{
|
|
|
|
struct cxl_get_event_payload *buf;
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
buf = kvmalloc(mds->payload_size, GFP_KERNEL);
|
2023-01-18 05:53:36 +00:00
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
2023-06-15 01:30:02 +00:00
|
|
|
mds->event.buf = buf;
|
2023-01-18 05:53:36 +00:00
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
return devm_add_action_or_reset(mds->cxlds.dev, free_event_buf, buf);
|
2023-01-18 05:53:36 +00:00
|
|
|
}
|
|
|
|
|
2024-01-18 01:24:01 +00:00
|
|
|
static bool cxl_alloc_irq_vectors(struct pci_dev *pdev)
|
2023-01-18 05:53:37 +00:00
|
|
|
{
|
|
|
|
int nvecs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Per CXL 3.0 3.1.1 CXL.io Endpoint a function on a CXL device must
|
|
|
|
* not generate INTx messages if that function participates in
|
|
|
|
* CXL.cache or CXL.mem.
|
|
|
|
*
|
|
|
|
* Additionally pci_alloc_irq_vectors() handles calling
|
|
|
|
* pci_free_irq_vectors() automatically despite not being called
|
|
|
|
* pcim_*. See pci_setup_msi_context().
|
|
|
|
*/
|
|
|
|
nvecs = pci_alloc_irq_vectors(pdev, 1, CXL_PCI_DEFAULT_MAX_VECTORS,
|
|
|
|
PCI_IRQ_MSIX | PCI_IRQ_MSI);
|
|
|
|
if (nvecs < 1) {
|
|
|
|
dev_dbg(&pdev->dev, "Failed to alloc irq vectors: %d\n", nvecs);
|
2024-01-18 01:24:01 +00:00
|
|
|
return false;
|
2023-01-18 05:53:37 +00:00
|
|
|
}
|
2024-01-18 01:24:01 +00:00
|
|
|
return true;
|
2023-01-18 05:53:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t cxl_event_thread(int irq, void *id)
|
|
|
|
{
|
|
|
|
struct cxl_dev_id *dev_id = id;
|
|
|
|
struct cxl_dev_state *cxlds = dev_id->cxlds;
|
2023-06-15 01:30:02 +00:00
|
|
|
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
|
2023-01-18 05:53:37 +00:00
|
|
|
u32 status;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* CXL 3.0 8.2.8.3.1: The lower 32 bits are the status;
|
|
|
|
* ignore the reserved upper 32 bits
|
|
|
|
*/
|
|
|
|
status = readl(cxlds->regs.status + CXLDEV_DEV_EVENT_STATUS_OFFSET);
|
|
|
|
/* Ignore logs unknown to the driver */
|
|
|
|
status &= CXLDEV_EVENT_STATUS_ALL;
|
|
|
|
if (!status)
|
|
|
|
break;
|
2023-06-15 01:30:02 +00:00
|
|
|
cxl_mem_get_event_records(mds, status);
|
2023-01-18 05:53:37 +00:00
|
|
|
cond_resched();
|
|
|
|
} while (status);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cxl_event_req_irq(struct cxl_dev_state *cxlds, u8 setting)
|
|
|
|
{
|
2023-05-23 17:09:26 +00:00
|
|
|
struct pci_dev *pdev = to_pci_dev(cxlds->dev);
|
2023-01-18 05:53:37 +00:00
|
|
|
int irq;
|
|
|
|
|
|
|
|
if (FIELD_GET(CXLDEV_EVENT_INT_MODE_MASK, setting) != CXL_INT_MSI_MSIX)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
irq = pci_irq_vector(pdev,
|
|
|
|
FIELD_GET(CXLDEV_EVENT_INT_MSGNUM_MASK, setting));
|
|
|
|
if (irq < 0)
|
|
|
|
return irq;
|
|
|
|
|
2023-10-04 03:12:12 +00:00
|
|
|
return cxl_request_irq(cxlds, irq, cxl_event_thread);
|
2023-01-18 05:53:37 +00:00
|
|
|
}
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
static int cxl_event_get_int_policy(struct cxl_memdev_state *mds,
|
2023-01-18 05:53:37 +00:00
|
|
|
struct cxl_event_interrupt_policy *policy)
|
|
|
|
{
|
|
|
|
struct cxl_mbox_cmd mbox_cmd = {
|
|
|
|
.opcode = CXL_MBOX_OP_GET_EVT_INT_POLICY,
|
|
|
|
.payload_out = policy,
|
|
|
|
.size_out = sizeof(*policy),
|
|
|
|
};
|
|
|
|
int rc;
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
rc = cxl_internal_send_cmd(mds, &mbox_cmd);
|
2023-01-18 05:53:37 +00:00
|
|
|
if (rc < 0)
|
2023-06-15 01:30:02 +00:00
|
|
|
dev_err(mds->cxlds.dev,
|
|
|
|
"Failed to get event interrupt policy : %d", rc);
|
2023-01-18 05:53:37 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
static int cxl_event_config_msgnums(struct cxl_memdev_state *mds,
|
2023-01-18 05:53:37 +00:00
|
|
|
struct cxl_event_interrupt_policy *policy)
|
|
|
|
{
|
|
|
|
struct cxl_mbox_cmd mbox_cmd;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
*policy = (struct cxl_event_interrupt_policy) {
|
|
|
|
.info_settings = CXL_INT_MSI_MSIX,
|
|
|
|
.warn_settings = CXL_INT_MSI_MSIX,
|
|
|
|
.failure_settings = CXL_INT_MSI_MSIX,
|
|
|
|
.fatal_settings = CXL_INT_MSI_MSIX,
|
|
|
|
};
|
|
|
|
|
|
|
|
mbox_cmd = (struct cxl_mbox_cmd) {
|
|
|
|
.opcode = CXL_MBOX_OP_SET_EVT_INT_POLICY,
|
|
|
|
.payload_in = policy,
|
|
|
|
.size_in = sizeof(*policy),
|
|
|
|
};
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
rc = cxl_internal_send_cmd(mds, &mbox_cmd);
|
2023-01-18 05:53:37 +00:00
|
|
|
if (rc < 0) {
|
2023-06-15 01:30:02 +00:00
|
|
|
dev_err(mds->cxlds.dev, "Failed to set event interrupt policy : %d",
|
2023-01-18 05:53:37 +00:00
|
|
|
rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve final interrupt settings */
|
2023-06-15 01:30:02 +00:00
|
|
|
return cxl_event_get_int_policy(mds, policy);
|
2023-01-18 05:53:37 +00:00
|
|
|
}
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
static int cxl_event_irqsetup(struct cxl_memdev_state *mds)
|
2023-01-18 05:53:37 +00:00
|
|
|
{
|
2023-06-15 01:30:02 +00:00
|
|
|
struct cxl_dev_state *cxlds = &mds->cxlds;
|
2023-01-18 05:53:37 +00:00
|
|
|
struct cxl_event_interrupt_policy policy;
|
|
|
|
int rc;
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
rc = cxl_event_config_msgnums(mds, &policy);
|
2023-01-18 05:53:37 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = cxl_event_req_irq(cxlds, policy.info_settings);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(cxlds->dev, "Failed to get interrupt for event Info log\n");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = cxl_event_req_irq(cxlds, policy.warn_settings);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(cxlds->dev, "Failed to get interrupt for event Warn log\n");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = cxl_event_req_irq(cxlds, policy.failure_settings);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(cxlds->dev, "Failed to get interrupt for event Failure log\n");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = cxl_event_req_irq(cxlds, policy.fatal_settings);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(cxlds->dev, "Failed to get interrupt for event Fatal log\n");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool cxl_event_int_is_fw(u8 setting)
|
|
|
|
{
|
|
|
|
u8 mode = FIELD_GET(CXLDEV_EVENT_INT_MODE_MASK, setting);
|
|
|
|
|
|
|
|
return mode == CXL_INT_FW;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cxl_event_config(struct pci_host_bridge *host_bridge,
|
2024-01-18 01:24:01 +00:00
|
|
|
struct cxl_memdev_state *mds, bool irq_avail)
|
2023-01-18 05:53:37 +00:00
|
|
|
{
|
|
|
|
struct cxl_event_interrupt_policy policy;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When BIOS maintains CXL error reporting control, it will process
|
|
|
|
* event records. Only one agent can do so.
|
|
|
|
*/
|
|
|
|
if (!host_bridge->native_cxl_error)
|
|
|
|
return 0;
|
|
|
|
|
2024-01-18 01:24:01 +00:00
|
|
|
if (!irq_avail) {
|
|
|
|
dev_info(mds->cxlds.dev, "No interrupt support, disable event processing.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
rc = cxl_mem_alloc_event_buf(mds);
|
2023-01-18 05:53:37 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
rc = cxl_event_get_int_policy(mds, &policy);
|
2023-01-18 05:53:37 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (cxl_event_int_is_fw(policy.info_settings) ||
|
|
|
|
cxl_event_int_is_fw(policy.warn_settings) ||
|
|
|
|
cxl_event_int_is_fw(policy.failure_settings) ||
|
|
|
|
cxl_event_int_is_fw(policy.fatal_settings)) {
|
2023-06-15 01:30:02 +00:00
|
|
|
dev_err(mds->cxlds.dev,
|
|
|
|
"FW still in control of Event Logs despite _OSC settings\n");
|
2023-01-18 05:53:37 +00:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
rc = cxl_event_irqsetup(mds);
|
2023-01-18 05:53:37 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
cxl_mem_get_event_records(mds, CXLDEV_EVENT_STATUS_ALL);
|
2023-01-18 05:53:37 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-09-13 16:33:24 +00:00
|
|
|
static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
2021-02-17 04:09:50 +00:00
|
|
|
{
|
2023-01-18 05:53:36 +00:00
|
|
|
struct pci_host_bridge *host_bridge = pci_find_host_bridge(pdev->bus);
|
2023-06-15 01:30:02 +00:00
|
|
|
struct cxl_memdev_state *mds;
|
|
|
|
struct cxl_dev_state *cxlds;
|
2021-10-15 23:30:42 +00:00
|
|
|
struct cxl_register_map map;
|
2021-06-15 23:36:31 +00:00
|
|
|
struct cxl_memdev *cxlmd;
|
2023-05-26 09:58:22 +00:00
|
|
|
int i, rc, pmu_count;
|
2024-01-18 01:24:01 +00:00
|
|
|
bool irq_avail;
|
2021-02-17 04:09:51 +00:00
|
|
|
|
2021-09-09 05:12:38 +00:00
|
|
|
/*
|
|
|
|
* Double check the anonymous union trickery in struct cxl_regs
|
|
|
|
* FIXME switch to struct_group()
|
|
|
|
*/
|
|
|
|
BUILD_BUG_ON(offsetof(struct cxl_regs, memdev) !=
|
|
|
|
offsetof(struct cxl_regs, device_regs.memdev));
|
|
|
|
|
2021-02-17 04:09:51 +00:00
|
|
|
rc = pcim_enable_device(pdev);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2023-01-18 05:53:37 +00:00
|
|
|
pci_set_master(pdev);
|
2021-02-17 04:09:50 +00:00
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
mds = cxl_memdev_state_create(&pdev->dev);
|
|
|
|
if (IS_ERR(mds))
|
|
|
|
return PTR_ERR(mds);
|
|
|
|
cxlds = &mds->cxlds;
|
2022-11-29 17:48:59 +00:00
|
|
|
pci_set_drvdata(pdev, cxlds);
|
2021-04-07 22:26:20 +00:00
|
|
|
|
2022-12-01 21:34:16 +00:00
|
|
|
cxlds->rcd = is_cxl_restricted(pdev);
|
2022-01-31 21:56:11 +00:00
|
|
|
cxlds->serial = pci_get_dsn(pdev);
|
2022-02-01 22:06:32 +00:00
|
|
|
cxlds->cxl_dvsec = pci_find_dvsec_capability(
|
2024-05-02 16:57:30 +00:00
|
|
|
pdev, PCI_VENDOR_ID_CXL, CXL_DVSEC_PCIE_DEVICE);
|
2022-02-01 22:06:32 +00:00
|
|
|
if (!cxlds->cxl_dvsec)
|
|
|
|
dev_warn(&pdev->dev,
|
|
|
|
"Device DVSEC not present, skip CXL.mem init\n");
|
|
|
|
|
2023-06-22 20:55:03 +00:00
|
|
|
rc = cxl_pci_setup_regs(pdev, CXL_REGLOC_RBI_MEMDEV, &map);
|
2021-10-15 23:30:42 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2023-06-22 20:55:02 +00:00
|
|
|
rc = cxl_map_device_regs(&map, &cxlds->regs.device_regs);
|
2021-02-17 04:09:51 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2022-02-01 21:28:53 +00:00
|
|
|
/*
|
|
|
|
* If the component registers can't be found, the cxl_pci driver may
|
|
|
|
* still be useful for management functions so don't return an error.
|
|
|
|
*/
|
2023-10-18 17:16:59 +00:00
|
|
|
rc = cxl_pci_setup_regs(pdev, CXL_REGLOC_RBI_COMPONENT,
|
|
|
|
&cxlds->reg_map);
|
2022-02-01 21:28:53 +00:00
|
|
|
if (rc)
|
|
|
|
dev_warn(&pdev->dev, "No component registers (%d)\n", rc);
|
2023-10-18 17:16:59 +00:00
|
|
|
else if (!cxlds->reg_map.component_map.ras.valid)
|
2023-06-22 20:55:07 +00:00
|
|
|
dev_dbg(&pdev->dev, "RAS registers not found\n");
|
2022-02-01 21:28:53 +00:00
|
|
|
|
2023-10-18 17:16:59 +00:00
|
|
|
rc = cxl_map_component_regs(&cxlds->reg_map, &cxlds->regs.component,
|
2023-06-22 20:55:02 +00:00
|
|
|
BIT(CXL_CM_CAP_CAP_ID_RAS));
|
2022-11-29 17:48:48 +00:00
|
|
|
if (rc)
|
|
|
|
dev_dbg(&pdev->dev, "Failed to map RAS capability.\n");
|
|
|
|
|
2023-05-18 23:38:20 +00:00
|
|
|
rc = cxl_await_media_ready(cxlds);
|
|
|
|
if (rc == 0)
|
|
|
|
cxlds->media_ready = true;
|
|
|
|
else
|
|
|
|
dev_warn(&pdev->dev, "Media not active (%d)\n", rc);
|
|
|
|
|
2024-01-18 01:24:01 +00:00
|
|
|
irq_avail = cxl_alloc_irq_vectors(pdev);
|
2023-05-23 17:09:25 +00:00
|
|
|
|
2024-01-18 01:24:01 +00:00
|
|
|
rc = cxl_pci_setup_mailbox(mds, irq_avail);
|
2021-02-17 04:09:51 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
rc = cxl_enumerate_cmds(mds);
|
2021-02-17 04:09:55 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
rc = cxl_set_timestamp(mds);
|
2023-01-30 15:13:27 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
rc = cxl_poison_state_init(mds);
|
2023-04-18 17:39:03 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
rc = cxl_dev_state_identify(mds);
|
2021-02-17 04:09:52 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2023-06-15 01:30:02 +00:00
|
|
|
rc = cxl_mem_create_range_info(mds);
|
2021-08-10 18:57:59 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2023-10-04 23:04:49 +00:00
|
|
|
cxlmd = devm_cxl_add_memdev(&pdev->dev, cxlds);
|
2021-06-15 23:36:31 +00:00
|
|
|
if (IS_ERR(cxlmd))
|
|
|
|
return PTR_ERR(cxlmd);
|
|
|
|
|
2023-10-04 23:04:49 +00:00
|
|
|
rc = devm_cxl_setup_fw_upload(&pdev->dev, mds);
|
cxl: add a firmware update mechanism using the sysfs firmware loader
The sysfs based firmware loader mechanism was created to easily allow
userspace to upload firmware images to FPGA cards. This also happens to
be pretty suitable to create a user-initiated but kernel-controlled
firmware update mechanism for CXL devices, using the CXL specified
mailbox commands.
Since firmware update commands can be long-running, and can be processed
in the background by the endpoint device, it is desirable to have the
ability to chunk the firmware transfer down to smaller pieces, so that
one operation does not monopolize the mailbox, locking out any other
long running background commands entirely - e.g. security commands like
'sanitize' or poison scanning operations.
The firmware loader mechanism allows a natural way to perform this
chunking, as after each mailbox command, that is restricted to the
maximum mailbox payload size, the cxl memdev driver relinquishes control
back to the fw_loader system and awaits the next chunk of data to
transfer. This opens opportunities for other background commands to
access the mailbox and send their own slices of background commands.
Add the necessary helpers and state tracking to be able to perform the
'Get FW Info', 'Transfer FW', and 'Activate FW' mailbox commands as
described in the CXL spec. Wire these up to the firmware loader
callbacks, and register with that system to create the memX/firmware/
sysfs ABI.
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Cc: Russ Weight <russell.h.weight@intel.com>
Cc: Alison Schofield <alison.schofield@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ben Widawsky <bwidawsk@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Link: https://lore.kernel.org/r/20230602-vv-fw_update-v4-1-c6265bd7343b@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2023-06-14 17:17:40 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2023-10-04 23:49:36 +00:00
|
|
|
rc = devm_cxl_sanitize_setup_notifier(&pdev->dev, cxlmd);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2023-05-26 09:58:22 +00:00
|
|
|
pmu_count = cxl_count_regblock(pdev, CXL_REGLOC_RBI_PMU);
|
|
|
|
for (i = 0; i < pmu_count; i++) {
|
|
|
|
struct cxl_pmu_regs pmu_regs;
|
|
|
|
|
|
|
|
rc = cxl_find_regblock_instance(pdev, CXL_REGLOC_RBI_PMU, &map, i);
|
|
|
|
if (rc) {
|
|
|
|
dev_dbg(&pdev->dev, "Could not find PMU regblock\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-10-18 17:17:13 +00:00
|
|
|
rc = cxl_map_pmu_regs(&map, &pmu_regs);
|
2023-05-26 09:58:22 +00:00
|
|
|
if (rc) {
|
|
|
|
dev_dbg(&pdev->dev, "Could not map PMU regs\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = devm_cxl_pmu_add(cxlds->dev, &pmu_regs, cxlmd->id, i, CXL_PMU_MEMDEV);
|
|
|
|
if (rc) {
|
|
|
|
dev_dbg(&pdev->dev, "Could not add PMU instance\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-18 01:24:01 +00:00
|
|
|
rc = cxl_event_config(host_bridge, mds, irq_avail);
|
2023-01-18 05:53:37 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2023-01-18 05:53:36 +00:00
|
|
|
|
2023-02-14 17:00:24 +00:00
|
|
|
rc = cxl_pci_ras_unmask(pdev);
|
|
|
|
if (rc)
|
|
|
|
dev_dbg(&pdev->dev, "No RAS reporting unmasked\n");
|
|
|
|
|
2022-11-29 17:48:59 +00:00
|
|
|
pci_save_state(pdev);
|
|
|
|
|
2021-06-15 23:36:31 +00:00
|
|
|
return rc;
|
2021-02-17 04:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct pci_device_id cxl_mem_pci_tbl[] = {
|
|
|
|
/* PCI class code for CXL.mem Type-3 Devices */
|
|
|
|
{ PCI_DEVICE_CLASS((PCI_CLASS_MEMORY_CXL << 8 | CXL_MEMORY_PROGIF), ~0)},
|
|
|
|
{ /* terminate list */ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, cxl_mem_pci_tbl);
|
|
|
|
|
2022-11-29 17:48:59 +00:00
|
|
|
static pci_ers_result_t cxl_slot_reset(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
|
|
|
|
struct cxl_memdev *cxlmd = cxlds->cxlmd;
|
|
|
|
struct device *dev = &cxlmd->dev;
|
|
|
|
|
|
|
|
dev_info(&pdev->dev, "%s: restart CXL.mem after slot reset\n",
|
|
|
|
dev_name(dev));
|
|
|
|
pci_restore_state(pdev);
|
|
|
|
if (device_attach(dev) <= 0)
|
|
|
|
return PCI_ERS_RESULT_DISCONNECT;
|
|
|
|
return PCI_ERS_RESULT_RECOVERED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cxl_error_resume(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
|
|
|
|
struct cxl_memdev *cxlmd = cxlds->cxlmd;
|
|
|
|
struct device *dev = &cxlmd->dev;
|
|
|
|
|
|
|
|
dev_info(&pdev->dev, "%s: error resume %s\n", dev_name(dev),
|
|
|
|
dev->driver ? "successful" : "failed");
|
|
|
|
}
|
|
|
|
|
2024-05-02 16:57:34 +00:00
|
|
|
static void cxl_reset_done(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
|
|
|
|
struct cxl_memdev *cxlmd = cxlds->cxlmd;
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FLR does not expect to touch the HDM decoders and related
|
|
|
|
* registers. SBR, however, will wipe all device configurations.
|
|
|
|
* Issue a warning if there was an active decoder before the reset
|
|
|
|
* that no longer exists.
|
|
|
|
*/
|
|
|
|
guard(device)(&cxlmd->dev);
|
|
|
|
if (cxlmd->endpoint &&
|
|
|
|
cxl_endpoint_decoder_reset_detected(cxlmd->endpoint)) {
|
|
|
|
dev_crit(dev, "SBR happened without memory regions removal.\n");
|
|
|
|
dev_crit(dev, "System may be unstable if regions hosted system memory.\n");
|
|
|
|
add_taint(TAINT_USER, LOCKDEP_STILL_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-29 17:48:59 +00:00
|
|
|
static const struct pci_error_handlers cxl_error_handlers = {
|
|
|
|
.error_detected = cxl_error_detected,
|
|
|
|
.slot_reset = cxl_slot_reset,
|
|
|
|
.resume = cxl_error_resume,
|
2022-12-01 00:02:25 +00:00
|
|
|
.cor_error_detected = cxl_cor_error_detected,
|
2024-05-02 16:57:34 +00:00
|
|
|
.reset_done = cxl_reset_done,
|
2022-11-29 17:48:59 +00:00
|
|
|
};
|
|
|
|
|
2021-09-13 16:33:24 +00:00
|
|
|
static struct pci_driver cxl_pci_driver = {
|
2021-02-17 04:09:50 +00:00
|
|
|
.name = KBUILD_MODNAME,
|
|
|
|
.id_table = cxl_mem_pci_tbl,
|
2021-09-13 16:33:24 +00:00
|
|
|
.probe = cxl_pci_probe,
|
2022-11-29 17:48:59 +00:00
|
|
|
.err_handler = &cxl_error_handlers,
|
2021-02-17 04:09:50 +00:00
|
|
|
.driver = {
|
|
|
|
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-04-27 03:34:01 +00:00
|
|
|
#define CXL_EVENT_HDR_FLAGS_REC_SEVERITY GENMASK(1, 0)
|
|
|
|
static void cxl_handle_cper_event(enum cxl_event_type ev_type,
|
|
|
|
struct cxl_cper_event_rec *rec)
|
|
|
|
{
|
|
|
|
struct cper_cxl_event_devid *device_id = &rec->hdr.device_id;
|
|
|
|
struct pci_dev *pdev __free(pci_dev_put) = NULL;
|
|
|
|
enum cxl_event_log_type log_type;
|
|
|
|
struct cxl_dev_state *cxlds;
|
|
|
|
unsigned int devfn;
|
|
|
|
u32 hdr_flags;
|
|
|
|
|
|
|
|
pr_debug("CPER event %d for device %u:%u:%u.%u\n", ev_type,
|
|
|
|
device_id->segment_num, device_id->bus_num,
|
|
|
|
device_id->device_num, device_id->func_num);
|
|
|
|
|
|
|
|
devfn = PCI_DEVFN(device_id->device_num, device_id->func_num);
|
|
|
|
pdev = pci_get_domain_bus_and_slot(device_id->segment_num,
|
|
|
|
device_id->bus_num, devfn);
|
|
|
|
if (!pdev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
guard(device)(&pdev->dev);
|
|
|
|
if (pdev->driver != &cxl_pci_driver)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cxlds = pci_get_drvdata(pdev);
|
|
|
|
if (!cxlds)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Fabricate a log type */
|
|
|
|
hdr_flags = get_unaligned_le24(rec->event.generic.hdr.flags);
|
|
|
|
log_type = FIELD_GET(CXL_EVENT_HDR_FLAGS_REC_SEVERITY, hdr_flags);
|
|
|
|
|
|
|
|
cxl_event_trace_record(cxlds->cxlmd, log_type, ev_type,
|
|
|
|
&uuid_null, &rec->event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cxl_cper_work_fn(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct cxl_cper_work_data wd;
|
|
|
|
|
|
|
|
while (cxl_cper_kfifo_get(&wd))
|
|
|
|
cxl_handle_cper_event(wd.event_type, &wd.rec);
|
|
|
|
}
|
|
|
|
static DECLARE_WORK(cxl_cper_work, cxl_cper_work_fn);
|
|
|
|
|
|
|
|
static int __init cxl_pci_driver_init(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = pci_register_driver(&cxl_pci_driver);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = cxl_cper_register_work(&cxl_cper_work);
|
|
|
|
if (rc)
|
|
|
|
pci_unregister_driver(&cxl_pci_driver);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit cxl_pci_driver_exit(void)
|
|
|
|
{
|
|
|
|
cxl_cper_unregister_work(&cxl_cper_work);
|
|
|
|
cancel_work_sync(&cxl_cper_work);
|
|
|
|
pci_unregister_driver(&cxl_pci_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(cxl_pci_driver_init);
|
|
|
|
module_exit(cxl_pci_driver_exit);
|
2024-06-07 13:57:15 +00:00
|
|
|
MODULE_DESCRIPTION("CXL: PCI manageability");
|
2021-02-17 04:09:50 +00:00
|
|
|
MODULE_LICENSE("GPL v2");
|
2021-02-17 04:09:52 +00:00
|
|
|
MODULE_IMPORT_NS(CXL);
|