Lines Matching refs:cxlm

31 #define cxl_doorbell_busy(cxlm)                                                \  argument
32 (readl((cxlm)->regs.mbox + CXLDEV_MBOX_CTRL_OFFSET) & \
38 static int cxl_pci_mbox_wait_for_doorbell(struct cxl_mem *cxlm) in cxl_pci_mbox_wait_for_doorbell() argument
43 while (cxl_doorbell_busy(cxlm)) { in cxl_pci_mbox_wait_for_doorbell()
48 if (!cxl_doorbell_busy(cxlm)) in cxl_pci_mbox_wait_for_doorbell()
55 dev_dbg(cxlm->dev, "Doorbell wait took %dms", in cxl_pci_mbox_wait_for_doorbell()
60 static void cxl_pci_mbox_timeout(struct cxl_mem *cxlm, in cxl_pci_mbox_timeout() argument
63 struct device *dev = cxlm->dev; in cxl_pci_mbox_timeout()
91 static int __cxl_pci_mbox_send_cmd(struct cxl_mem *cxlm, in __cxl_pci_mbox_send_cmd() argument
94 void __iomem *payload = cxlm->regs.mbox + CXLDEV_MBOX_PAYLOAD_OFFSET; in __cxl_pci_mbox_send_cmd()
95 struct device *dev = cxlm->dev; in __cxl_pci_mbox_send_cmd()
100 lockdep_assert_held(&cxlm->mbox_mutex); in __cxl_pci_mbox_send_cmd()
120 if (cxl_doorbell_busy(cxlm)) { in __cxl_pci_mbox_send_cmd()
137 writeq(cmd_reg, cxlm->regs.mbox + CXLDEV_MBOX_CMD_OFFSET); in __cxl_pci_mbox_send_cmd()
142 cxlm->regs.mbox + CXLDEV_MBOX_CTRL_OFFSET); in __cxl_pci_mbox_send_cmd()
145 rc = cxl_pci_mbox_wait_for_doorbell(cxlm); in __cxl_pci_mbox_send_cmd()
147 cxl_pci_mbox_timeout(cxlm, mbox_cmd); in __cxl_pci_mbox_send_cmd()
152 status_reg = readq(cxlm->regs.mbox + CXLDEV_MBOX_STATUS_OFFSET); in __cxl_pci_mbox_send_cmd()
162 cmd_reg = readq(cxlm->regs.mbox + CXLDEV_MBOX_CMD_OFFSET); in __cxl_pci_mbox_send_cmd()
174 size_t n = min3(mbox_cmd->size_out, cxlm->payload_size, out_len); in __cxl_pci_mbox_send_cmd()
192 static int cxl_pci_mbox_get(struct cxl_mem *cxlm) in cxl_pci_mbox_get() argument
194 struct device *dev = cxlm->dev; in cxl_pci_mbox_get()
198 mutex_lock_io(&cxlm->mbox_mutex); in cxl_pci_mbox_get()
217 rc = cxl_pci_mbox_wait_for_doorbell(cxlm); in cxl_pci_mbox_get()
223 md_status = readq(cxlm->regs.memdev + CXLMDEV_STATUS_OFFSET); in cxl_pci_mbox_get()
252 mutex_unlock(&cxlm->mbox_mutex); in cxl_pci_mbox_get()
262 static void cxl_pci_mbox_put(struct cxl_mem *cxlm) in cxl_pci_mbox_put() argument
264 mutex_unlock(&cxlm->mbox_mutex); in cxl_pci_mbox_put()
267 static int cxl_pci_mbox_send(struct cxl_mem *cxlm, struct cxl_mbox_cmd *cmd) in cxl_pci_mbox_send() argument
271 rc = cxl_pci_mbox_get(cxlm); in cxl_pci_mbox_send()
275 rc = __cxl_pci_mbox_send_cmd(cxlm, cmd); in cxl_pci_mbox_send()
276 cxl_pci_mbox_put(cxlm); in cxl_pci_mbox_send()
281 static int cxl_pci_setup_mailbox(struct cxl_mem *cxlm) in cxl_pci_setup_mailbox() argument
283 const int cap = readl(cxlm->regs.mbox + CXLDEV_MBOX_CAPS_OFFSET); in cxl_pci_setup_mailbox()
285 cxlm->mbox_send = cxl_pci_mbox_send; in cxl_pci_setup_mailbox()
286 cxlm->payload_size = in cxl_pci_setup_mailbox()
296 cxlm->payload_size = min_t(size_t, cxlm->payload_size, SZ_1M); in cxl_pci_setup_mailbox()
297 if (cxlm->payload_size < 256) { in cxl_pci_setup_mailbox()
298 dev_err(cxlm->dev, "Mailbox is too small (%zub)", in cxl_pci_setup_mailbox()
299 cxlm->payload_size); in cxl_pci_setup_mailbox()
303 dev_dbg(cxlm->dev, "Mailbox payload sized %zu", in cxl_pci_setup_mailbox()
304 cxlm->payload_size); in cxl_pci_setup_mailbox()
382 static int cxl_map_regs(struct cxl_mem *cxlm, struct cxl_register_map *map) in cxl_map_regs() argument
384 struct device *dev = cxlm->dev; in cxl_map_regs()
389 cxl_map_component_regs(pdev, &cxlm->regs.component, map); in cxl_map_regs()
393 cxl_map_device_regs(pdev, &cxlm->regs.device_regs, map); in cxl_map_regs()
478 struct cxl_mem *cxlm; in cxl_pci_probe() local
492 cxlm = cxl_mem_create(&pdev->dev); in cxl_pci_probe()
493 if (IS_ERR(cxlm)) in cxl_pci_probe()
494 return PTR_ERR(cxlm); in cxl_pci_probe()
500 rc = cxl_map_regs(cxlm, &map); in cxl_pci_probe()
504 rc = cxl_pci_setup_mailbox(cxlm); in cxl_pci_probe()
508 rc = cxl_mem_enumerate_cmds(cxlm); in cxl_pci_probe()
512 rc = cxl_mem_identify(cxlm); in cxl_pci_probe()
516 rc = cxl_mem_create_range_info(cxlm); in cxl_pci_probe()
520 cxlmd = devm_cxl_add_memdev(cxlm); in cxl_pci_probe()
524 if (range_len(&cxlm->pmem_range) && IS_ENABLED(CONFIG_CXL_PMEM)) in cxl_pci_probe()