Skip to content

Commit 9f7a320

Browse files
Davidlohr Buesodjbw
authored andcommitted
cxl/pci: Introduce cxl_request_irq()
Factor out common functionality/semantics for cxl shared interrupts into a new helper on top of devm_request_irq(). Suggested-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net> Link: https://lore.kernel.org/r/20230523170927.20685-4-dave@stgolabs.net Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent f279d0b commit 9f7a320

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

drivers/cxl/pci.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,27 @@ static int cxl_pci_mbox_wait_for_doorbell(struct cxl_dev_state *cxlds)
8484
status & CXLMDEV_DEV_FATAL ? " fatal" : "", \
8585
status & CXLMDEV_FW_HALT ? " firmware-halt" : "")
8686

87+
struct cxl_dev_id {
88+
struct cxl_dev_state *cxlds;
89+
};
90+
91+
static int cxl_request_irq(struct cxl_dev_state *cxlds, int irq,
92+
irq_handler_t handler, irq_handler_t thread_fn)
93+
{
94+
struct device *dev = cxlds->dev;
95+
struct cxl_dev_id *dev_id;
96+
97+
/* dev_id must be globally unique and must contain the cxlds */
98+
dev_id = devm_kzalloc(dev, sizeof(*dev_id), GFP_KERNEL);
99+
if (!dev_id)
100+
return -ENOMEM;
101+
dev_id->cxlds = cxlds;
102+
103+
return devm_request_threaded_irq(dev, irq, handler, thread_fn,
104+
IRQF_SHARED | IRQF_ONESHOT,
105+
NULL, dev_id);
106+
}
107+
87108
/**
88109
* __cxl_pci_mbox_send_cmd() - Execute a mailbox command
89110
* @cxlds: The device state to communicate with.
@@ -469,10 +490,6 @@ static int cxl_alloc_irq_vectors(struct pci_dev *pdev)
469490
return 0;
470491
}
471492

472-
struct cxl_dev_id {
473-
struct cxl_dev_state *cxlds;
474-
};
475-
476493
static irqreturn_t cxl_event_thread(int irq, void *id)
477494
{
478495
struct cxl_dev_id *dev_id = id;
@@ -498,28 +515,18 @@ static irqreturn_t cxl_event_thread(int irq, void *id)
498515

499516
static int cxl_event_req_irq(struct cxl_dev_state *cxlds, u8 setting)
500517
{
501-
struct device *dev = cxlds->dev;
502-
struct pci_dev *pdev = to_pci_dev(dev);
503-
struct cxl_dev_id *dev_id;
518+
struct pci_dev *pdev = to_pci_dev(cxlds->dev);
504519
int irq;
505520

506521
if (FIELD_GET(CXLDEV_EVENT_INT_MODE_MASK, setting) != CXL_INT_MSI_MSIX)
507522
return -ENXIO;
508523

509-
/* dev_id must be globally unique and must contain the cxlds */
510-
dev_id = devm_kzalloc(dev, sizeof(*dev_id), GFP_KERNEL);
511-
if (!dev_id)
512-
return -ENOMEM;
513-
dev_id->cxlds = cxlds;
514-
515524
irq = pci_irq_vector(pdev,
516525
FIELD_GET(CXLDEV_EVENT_INT_MSGNUM_MASK, setting));
517526
if (irq < 0)
518527
return irq;
519528

520-
return devm_request_threaded_irq(dev, irq, NULL, cxl_event_thread,
521-
IRQF_SHARED | IRQF_ONESHOT, NULL,
522-
dev_id);
529+
return cxl_request_irq(cxlds, irq, NULL, cxl_event_thread);
523530
}
524531

525532
static int cxl_event_get_int_policy(struct cxl_dev_state *cxlds,

0 commit comments

Comments
 (0)