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()
147 return ndev->barno_map[BAR_MW1 + idx]; 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 = ntb_epf_mw_to_bar(ndev, idx); in ntb_epf_mw_set_trans()
428 writel(lower_32_bits(addr), ndev->ctrl_reg + NTB_EPF_LOWER_ADDR); in ntb_epf_mw_set_trans()
429 writel(upper_32_bits(addr), ndev->ctrl_reg + NTB_EPF_UPPER_ADDR); in ntb_epf_mw_set_trans()
430 writel(lower_32_bits(size), ndev->ctrl_reg + NTB_EPF_LOWER_SIZE); in ntb_epf_mw_set_trans()
431 writel(upper_32_bits(size), ndev->ctrl_reg + NTB_EPF_UPPER_SIZE); in ntb_epf_mw_set_trans()
432 ntb_epf_send_command(ndev, CMD_CONFIGURE_MW, idx); in ntb_epf_mw_set_trans()
439 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_mw_clear_trans() local
440 struct device *dev = ndev->dev; in ntb_epf_mw_clear_trans()
443 ntb_epf_send_command(ndev, CMD_TEARDOWN_MW, idx); in ntb_epf_mw_clear_trans()
453 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_peer_mw_get_addr() local
458 offset = readl(ndev->ctrl_reg + NTB_EPF_MW1_OFFSET); in ntb_epf_peer_mw_get_addr()
460 bar = ntb_epf_mw_to_bar(ndev, idx); in ntb_epf_peer_mw_get_addr()
465 *base = pci_resource_start(ndev->ntb.pdev, bar) + offset; in ntb_epf_peer_mw_get_addr()
468 *size = pci_resource_len(ndev->ntb.pdev, bar) - offset; in ntb_epf_peer_mw_get_addr()
475 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_peer_db_set() local
477 struct device *dev = ndev->dev; in ntb_epf_peer_db_set()
482 if (interrupt_num > ndev->db_count) { in ntb_epf_peer_db_set()
484 interrupt_num, ndev->db_count); in ntb_epf_peer_db_set()
488 db_entry_size = readl(ndev->ctrl_reg + NTB_EPF_DB_ENTRY_SIZE); in ntb_epf_peer_db_set()
490 db_data = readl(ndev->ctrl_reg + NTB_EPF_DB_DATA(interrupt_num)); in ntb_epf_peer_db_set()
491 db_offset = readl(ndev->ctrl_reg + NTB_EPF_DB_OFFSET(interrupt_num)); in ntb_epf_peer_db_set()
492 writel(db_data, ndev->db_reg + (db_entry_size * interrupt_num) + in ntb_epf_peer_db_set()
500 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_db_read() local
502 return ndev->db_val; in ntb_epf_db_read()
512 struct ntb_epf_dev *ndev = ntb_ndev(ntb); in ntb_epf_db_clear() local
514 ndev->db_val = 0; in ntb_epf_db_clear()
542 static inline void ntb_epf_init_struct(struct ntb_epf_dev *ndev, in ntb_epf_init_struct() argument
545 ndev->ntb.pdev = pdev; in ntb_epf_init_struct()
546 ndev->ntb.topo = NTB_TOPO_NONE; in ntb_epf_init_struct()
547 ndev->ntb.ops = &ntb_epf_ops; in ntb_epf_init_struct()
550 static int ntb_epf_init_dev(struct ntb_epf_dev *ndev) in ntb_epf_init_dev() argument
552 struct device *dev = ndev->dev; in ntb_epf_init_dev()
556 ret = ntb_epf_init_isr(ndev, NTB_EPF_MIN_DB_COUNT + 1, in ntb_epf_init_dev()
563 ndev->db_valid_mask = BIT_ULL(ndev->db_count) - 1; in ntb_epf_init_dev()
564 ndev->mw_count = readl(ndev->ctrl_reg + NTB_EPF_MW_COUNT); in ntb_epf_init_dev()
565 ndev->spad_count = readl(ndev->ctrl_reg + NTB_EPF_SPAD_COUNT); in ntb_epf_init_dev()
567 if (ndev->mw_count > NTB_EPF_MAX_MW_COUNT) { in ntb_epf_init_dev()
568 dev_err(dev, "Unsupported MW count: %u\n", ndev->mw_count); in ntb_epf_init_dev()
575 static int ntb_epf_init_pci(struct ntb_epf_dev *ndev, in ntb_epf_init_pci() argument
578 struct device *dev = ndev->dev; in ntb_epf_init_pci()
582 pci_set_drvdata(pdev, ndev); in ntb_epf_init_pci()
608 ndev->ctrl_reg = pci_iomap(pdev, ndev->barno_map[BAR_CONFIG], 0); in ntb_epf_init_pci()
609 if (!ndev->ctrl_reg) { in ntb_epf_init_pci()
614 if (ndev->barno_map[BAR_PEER_SPAD] != ndev->barno_map[BAR_CONFIG]) { in ntb_epf_init_pci()
615 ndev->peer_spad_reg = pci_iomap(pdev, in ntb_epf_init_pci()
616 ndev->barno_map[BAR_PEER_SPAD], 0); in ntb_epf_init_pci()
617 if (!ndev->peer_spad_reg) { in ntb_epf_init_pci()
622 spad_sz = 4 * readl(ndev->ctrl_reg + NTB_EPF_SPAD_COUNT); in ntb_epf_init_pci()
623 spad_off = readl(ndev->ctrl_reg + NTB_EPF_SPAD_OFFSET); in ntb_epf_init_pci()
624 ndev->peer_spad_reg = ndev->ctrl_reg + spad_off + spad_sz; in ntb_epf_init_pci()
627 ndev->db_reg = pci_iomap(pdev, ndev->barno_map[BAR_DB], 0); in ntb_epf_init_pci()
628 if (!ndev->db_reg) { in ntb_epf_init_pci()
644 static void ntb_epf_deinit_pci(struct ntb_epf_dev *ndev) in ntb_epf_deinit_pci() argument
646 struct pci_dev *pdev = ndev->ntb.pdev; in ntb_epf_deinit_pci()
648 pci_iounmap(pdev, ndev->ctrl_reg); in ntb_epf_deinit_pci()
649 pci_iounmap(pdev, ndev->peer_spad_reg); in ntb_epf_deinit_pci()
650 pci_iounmap(pdev, ndev->db_reg); in ntb_epf_deinit_pci()
657 static void ntb_epf_cleanup_isr(struct ntb_epf_dev *ndev) in ntb_epf_cleanup_isr() argument
659 struct pci_dev *pdev = ndev->ntb.pdev; in ntb_epf_cleanup_isr()
662 ntb_epf_send_command(ndev, CMD_TEARDOWN_DOORBELL, ndev->db_count + 1); in ntb_epf_cleanup_isr()
664 for (i = 0; i < ndev->db_count + 1; i++) in ntb_epf_cleanup_isr()
665 free_irq(pci_irq_vector(pdev, i), ndev); in ntb_epf_cleanup_isr()
673 struct ntb_epf_dev *ndev; in ntb_epf_pci_probe() local
679 ndev = devm_kzalloc(dev, sizeof(*ndev), GFP_KERNEL); in ntb_epf_pci_probe()
680 if (!ndev) in ntb_epf_pci_probe()
683 ndev->barno_map = (const enum pci_barno *)id->driver_data; in ntb_epf_pci_probe()
684 if (!ndev->barno_map) in ntb_epf_pci_probe()
687 ndev->dev = dev; in ntb_epf_pci_probe()
689 ntb_epf_init_struct(ndev, pdev); in ntb_epf_pci_probe()
690 mutex_init(&ndev->cmd_lock); in ntb_epf_pci_probe()
692 ret = ntb_epf_init_pci(ndev, pdev); in ntb_epf_pci_probe()
698 ret = ntb_epf_init_dev(ndev); in ntb_epf_pci_probe()
704 ret = ntb_register_device(&ndev->ntb); in ntb_epf_pci_probe()
713 ntb_epf_cleanup_isr(ndev); in ntb_epf_pci_probe()
716 ntb_epf_deinit_pci(ndev); in ntb_epf_pci_probe()
723 struct ntb_epf_dev *ndev = pci_get_drvdata(pdev); in ntb_epf_pci_remove() local
725 ntb_unregister_device(&ndev->ntb); in ntb_epf_pci_remove()
726 ntb_epf_cleanup_isr(ndev); in ntb_epf_pci_remove()
727 ntb_epf_deinit_pci(ndev); in ntb_epf_pci_remove()