Lines Matching full:ndev

99 static int ntb_epf_send_command(struct ntb_epf_dev *ndev, u32 command,  in ntb_epf_send_command()  argument
107 mutex_lock(&ndev->cmd_lock); in ntb_epf_send_command()
108 writel(argument, ndev->ctrl_reg + NTB_EPF_ARGUMENT); in ntb_epf_send_command()
109 writel(command, ndev->ctrl_reg + NTB_EPF_COMMAND); in ntb_epf_send_command()
114 status = readw(ndev->ctrl_reg + NTB_EPF_CMD_STATUS); in ntb_epf_send_command()
132 writew(0, ndev->ctrl_reg + NTB_EPF_CMD_STATUS); in ntb_epf_send_command()
133 mutex_unlock(&ndev->cmd_lock); in ntb_epf_send_command()
138 static int ntb_epf_mw_to_bar(struct ntb_epf_dev *ndev, int idx) in ntb_epf_mw_to_bar() argument
140 struct device *dev = ndev->dev; in ntb_epf_mw_to_bar()
142 if (idx < 0 || idx > ndev->mw_count) { in ntb_epf_mw_to_bar()
152 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_mw_count() local
153 struct device *dev = ndev->dev; in ntb_epf_mw_count()
160 return ndev->mw_count; in ntb_epf_mw_count()
168 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_mw_get_align() local
169 struct device *dev = ndev->dev; in ntb_epf_mw_get_align()
177 bar = ntb_epf_mw_to_bar(ndev, idx); in ntb_epf_mw_get_align()
188 *size_max = pci_resource_len(ndev->ntb.pdev, bar); in ntb_epf_mw_get_align()
197 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_link_is_up() local
200 status = readw(ndev->ctrl_reg + NTB_EPF_LINK_STATUS); in ntb_epf_link_is_up()
207 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_spad_read() local
208 struct device *dev = ndev->dev; in ntb_epf_spad_read()
211 if (idx < 0 || idx >= ndev->spad_count) { in ntb_epf_spad_read()
216 offset = readl(ndev->ctrl_reg + NTB_EPF_SPAD_OFFSET); in ntb_epf_spad_read()
219 return readl(ndev->ctrl_reg + offset); in ntb_epf_spad_read()
225 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_spad_write() local
226 struct device *dev = ndev->dev; in ntb_epf_spad_write()
229 if (idx < 0 || idx >= ndev->spad_count) { in ntb_epf_spad_write()
234 offset = readl(ndev->ctrl_reg + NTB_EPF_SPAD_OFFSET); in ntb_epf_spad_write()
236 writel(val, ndev->ctrl_reg + offset); in ntb_epf_spad_write()
243 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_peer_spad_read() local
244 struct device *dev = ndev->dev; in ntb_epf_peer_spad_read()
252 if (idx < 0 || idx >= ndev->spad_count) { in ntb_epf_peer_spad_read()
258 return readl(ndev->peer_spad_reg + offset); in ntb_epf_peer_spad_read()
264 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_peer_spad_write() local
265 struct device *dev = ndev->dev; in ntb_epf_peer_spad_write()
273 if (idx < 0 || idx >= ndev->spad_count) { in ntb_epf_peer_spad_write()
279 writel(val, ndev->peer_spad_reg + offset); in ntb_epf_peer_spad_write()
288 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_link_enable() local
289 struct device *dev = ndev->dev; in ntb_epf_link_enable()
292 ret = ntb_epf_send_command(ndev, CMD_LINK_UP, 0); in ntb_epf_link_enable()
303 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_link_disable() local
304 struct device *dev = ndev->dev; in ntb_epf_link_disable()
307 ret = ntb_epf_send_command(ndev, CMD_LINK_DOWN, 0); in ntb_epf_link_disable()
318 struct ntb_epf_dev *ndev = dev; in ntb_epf_vec_isr() local
321 irq_no = irq - pci_irq_vector(ndev->ntb.pdev, 0); in ntb_epf_vec_isr()
322 ndev->db_val = irq_no + 1; in ntb_epf_vec_isr()
325 ntb_link_event(&ndev->ntb); in ntb_epf_vec_isr()
327 ntb_db_event(&ndev->ntb, irq_no); in ntb_epf_vec_isr()
332 static int ntb_epf_init_isr(struct ntb_epf_dev *ndev, int msi_min, int msi_max) in ntb_epf_init_isr() argument
334 struct pci_dev *pdev = ndev->ntb.pdev; in ntb_epf_init_isr()
335 struct device *dev = ndev->dev; in ntb_epf_init_isr()
355 0, "ntb_epf", ndev); in ntb_epf_init_isr()
362 ndev->db_count = irq - 1; in ntb_epf_init_isr()
364 ret = ntb_epf_send_command(ndev, CMD_CONFIGURE_DOORBELL, in ntb_epf_init_isr()
374 for (i = 0; i < ndev->db_count + 1; i++) in ntb_epf_init_isr()
375 free_irq(pci_irq_vector(pdev, i), ndev); in ntb_epf_init_isr()
406 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_mw_set_trans() local
407 struct device *dev = ndev->dev; in ntb_epf_mw_set_trans()
416 bar = idx + ndev->mw_bar; in ntb_epf_mw_set_trans()
426 writel(lower_32_bits(addr), ndev->ctrl_reg + NTB_EPF_LOWER_ADDR); in ntb_epf_mw_set_trans()
427 writel(upper_32_bits(addr), ndev->ctrl_reg + NTB_EPF_UPPER_ADDR); in ntb_epf_mw_set_trans()
428 writel(lower_32_bits(size), ndev->ctrl_reg + NTB_EPF_LOWER_SIZE); in ntb_epf_mw_set_trans()
429 writel(upper_32_bits(size), ndev->ctrl_reg + NTB_EPF_UPPER_SIZE); in ntb_epf_mw_set_trans()
430 ntb_epf_send_command(ndev, CMD_CONFIGURE_MW, idx); in ntb_epf_mw_set_trans()
437 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_mw_clear_trans() local
438 struct device *dev = ndev->dev; in ntb_epf_mw_clear_trans()
441 ntb_epf_send_command(ndev, CMD_TEARDOWN_MW, idx); in ntb_epf_mw_clear_trans()
451 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_peer_mw_get_addr() local
456 offset = readl(ndev->ctrl_reg + NTB_EPF_MW1_OFFSET); in ntb_epf_peer_mw_get_addr()
458 bar = idx + ndev->mw_bar; in ntb_epf_peer_mw_get_addr()
461 *base = pci_resource_start(ndev->ntb.pdev, bar) + offset; in ntb_epf_peer_mw_get_addr()
464 *size = pci_resource_len(ndev->ntb.pdev, bar) - offset; in ntb_epf_peer_mw_get_addr()
471 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_peer_db_set() local
473 struct device *dev = ndev->dev; in ntb_epf_peer_db_set()
478 if (interrupt_num > ndev->db_count) { in ntb_epf_peer_db_set()
480 interrupt_num, ndev->db_count); in ntb_epf_peer_db_set()
484 db_entry_size = readl(ndev->ctrl_reg + NTB_EPF_DB_ENTRY_SIZE); in ntb_epf_peer_db_set()
486 db_data = readl(ndev->ctrl_reg + NTB_EPF_DB_DATA(interrupt_num)); in ntb_epf_peer_db_set()
487 db_offset = readl(ndev->ctrl_reg + NTB_EPF_DB_OFFSET(interrupt_num)); in ntb_epf_peer_db_set()
488 writel(db_data, ndev->db_reg + (db_entry_size * interrupt_num) + in ntb_epf_peer_db_set()
496 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_db_read() local
498 return ndev->db_val; in ntb_epf_db_read()
508 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_db_clear() local
510 ndev->db_val = 0; in ntb_epf_db_clear()
538 static inline void ntb_epf_init_struct(struct ntb_epf_dev *ndev, in ntb_epf_init_struct() argument
541 ndev->ntb.pdev = pdev; in ntb_epf_init_struct()
542 ndev->ntb.topo = NTB_TOPO_NONE; in ntb_epf_init_struct()
543 ndev->ntb.ops = &ntb_epf_ops; in ntb_epf_init_struct()
546 static int ntb_epf_init_dev(struct ntb_epf_dev *ndev) in ntb_epf_init_dev() argument
548 struct device *dev = ndev->dev; in ntb_epf_init_dev()
552 ret = ntb_epf_init_isr(ndev, NTB_EPF_MIN_DB_COUNT + 1, in ntb_epf_init_dev()
559 ndev->db_valid_mask = BIT_ULL(ndev->db_count) - 1; in ntb_epf_init_dev()
560 ndev->mw_count = readl(ndev->ctrl_reg + NTB_EPF_MW_COUNT); in ntb_epf_init_dev()
561 ndev->spad_count = readl(ndev->ctrl_reg + NTB_EPF_SPAD_COUNT); in ntb_epf_init_dev()
566 static int ntb_epf_init_pci(struct ntb_epf_dev *ndev, in ntb_epf_init_pci() argument
569 struct device *dev = ndev->dev; in ntb_epf_init_pci()
573 pci_set_drvdata(pdev, ndev); in ntb_epf_init_pci()
599 ndev->ctrl_reg = pci_iomap(pdev, ndev->ctrl_reg_bar, 0); in ntb_epf_init_pci()
600 if (!ndev->ctrl_reg) { in ntb_epf_init_pci()
605 if (ndev->peer_spad_reg_bar) { in ntb_epf_init_pci()
606 ndev->peer_spad_reg = pci_iomap(pdev, ndev->peer_spad_reg_bar, 0); in ntb_epf_init_pci()
607 if (!ndev->peer_spad_reg) { in ntb_epf_init_pci()
612 spad_sz = 4 * readl(ndev->ctrl_reg + NTB_EPF_SPAD_COUNT); in ntb_epf_init_pci()
613 spad_off = readl(ndev->ctrl_reg + NTB_EPF_SPAD_OFFSET); in ntb_epf_init_pci()
614 ndev->peer_spad_reg = ndev->ctrl_reg + spad_off + spad_sz; in ntb_epf_init_pci()
617 ndev->db_reg = pci_iomap(pdev, ndev->db_reg_bar, 0); in ntb_epf_init_pci()
618 if (!ndev->db_reg) { in ntb_epf_init_pci()
634 static void ntb_epf_deinit_pci(struct ntb_epf_dev *ndev) in ntb_epf_deinit_pci() argument
636 struct pci_dev *pdev = ndev->ntb.pdev; in ntb_epf_deinit_pci()
638 pci_iounmap(pdev, ndev->ctrl_reg); in ntb_epf_deinit_pci()
639 pci_iounmap(pdev, ndev->peer_spad_reg); in ntb_epf_deinit_pci()
640 pci_iounmap(pdev, ndev->db_reg); in ntb_epf_deinit_pci()
647 static void ntb_epf_cleanup_isr(struct ntb_epf_dev *ndev) in ntb_epf_cleanup_isr() argument
649 struct pci_dev *pdev = ndev->ntb.pdev; in ntb_epf_cleanup_isr()
652 ntb_epf_send_command(ndev, CMD_TEARDOWN_DOORBELL, ndev->db_count + 1); in ntb_epf_cleanup_isr()
654 for (i = 0; i < ndev->db_count + 1; i++) in ntb_epf_cleanup_isr()
655 free_irq(pci_irq_vector(pdev, i), ndev); in ntb_epf_cleanup_isr()
668 struct ntb_epf_dev *ndev; in ntb_epf_pci_probe() local
674 ndev = devm_kzalloc(dev, sizeof(*ndev), GFP_KERNEL); in ntb_epf_pci_probe()
675 if (!ndev) in ntb_epf_pci_probe()
686 ndev->peer_spad_reg_bar = peer_spad_reg_bar; in ntb_epf_pci_probe()
687 ndev->ctrl_reg_bar = ctrl_reg_bar; in ntb_epf_pci_probe()
688 ndev->db_reg_bar = db_reg_bar; in ntb_epf_pci_probe()
689 ndev->mw_bar = mw_bar; in ntb_epf_pci_probe()
690 ndev->dev = dev; in ntb_epf_pci_probe()
692 ntb_epf_init_struct(ndev, pdev); in ntb_epf_pci_probe()
693 mutex_init(&ndev->cmd_lock); in ntb_epf_pci_probe()
695 ret = ntb_epf_init_pci(ndev, pdev); in ntb_epf_pci_probe()
701 ret = ntb_epf_init_dev(ndev); in ntb_epf_pci_probe()
707 ret = ntb_register_device(&ndev->ntb); in ntb_epf_pci_probe()
716 ntb_epf_cleanup_isr(ndev); in ntb_epf_pci_probe()
719 ntb_epf_deinit_pci(ndev); in ntb_epf_pci_probe()
726 struct ntb_epf_dev *ndev = pci_get_drvdata(pdev); in ntb_epf_pci_remove() local
728 ntb_unregister_device(&ndev->ntb); in ntb_epf_pci_remove()
729 ntb_epf_cleanup_isr(ndev); in ntb_epf_pci_remove()
730 ntb_epf_deinit_pci(ndev); in ntb_epf_pci_remove()