Lines Matching refs:nt
218 struct ntb_transport_ctx *nt; member
272 #define QP_TO_MW(nt, qp) ((qp) % nt->mw_count) argument
326 static int ntb_bus_init(struct ntb_transport_ctx *nt) in ntb_bus_init() argument
328 list_add_tail(&nt->entry, &ntb_transport_list); in ntb_bus_init()
332 static void ntb_bus_remove(struct ntb_transport_ctx *nt) in ntb_bus_remove() argument
336 list_for_each_entry_safe(client_dev, cd, &nt->client_devs, entry) { in ntb_bus_remove()
343 list_del(&nt->entry); in ntb_bus_remove()
363 struct ntb_transport_ctx *nt; in ntb_transport_unregister_client_dev() local
365 list_for_each_entry(nt, &ntb_transport_list, entry) in ntb_transport_unregister_client_dev()
366 list_for_each_entry_safe(client, cd, &nt->client_devs, entry) in ntb_transport_unregister_client_dev()
386 struct ntb_transport_ctx *nt; in ntb_transport_register_client_dev() local
393 list_for_each_entry(nt, &ntb_transport_list, entry) { in ntb_transport_register_client_dev()
396 node = dev_to_node(&nt->ndev->dev); in ntb_transport_register_client_dev()
411 dev->parent = &nt->ndev->dev; in ntb_transport_register_client_dev()
419 list_add_tail(&client_dev->entry, &nt->client_devs); in ntb_transport_register_client_dev()
615 static int ntb_transport_setup_qp_mw(struct ntb_transport_ctx *nt, in ntb_transport_setup_qp_mw() argument
618 struct ntb_transport_qp *qp = &nt->qp_vec[qp_num]; in ntb_transport_setup_qp_mw()
620 struct ntb_dev *ndev = nt->ndev; in ntb_transport_setup_qp_mw()
627 mw_count = nt->mw_count; in ntb_transport_setup_qp_mw()
628 qp_count = nt->qp_count; in ntb_transport_setup_qp_mw()
630 mw_num = QP_TO_MW(nt, qp_num); in ntb_transport_setup_qp_mw()
631 mw = &nt->mw_vec[mw_num]; in ntb_transport_setup_qp_mw()
694 static void ntb_transport_setup_qp_peer_msi(struct ntb_transport_ctx *nt, in ntb_transport_setup_qp_peer_msi() argument
697 struct ntb_transport_qp *qp = &nt->qp_vec[qp_num]; in ntb_transport_setup_qp_peer_msi()
698 int spad = qp_num * 2 + nt->msi_spad_offset; in ntb_transport_setup_qp_peer_msi()
700 if (!nt->use_msi) in ntb_transport_setup_qp_peer_msi()
703 if (spad >= ntb_spad_count(nt->ndev)) in ntb_transport_setup_qp_peer_msi()
721 static void ntb_transport_setup_qp_msi(struct ntb_transport_ctx *nt, in ntb_transport_setup_qp_msi() argument
724 struct ntb_transport_qp *qp = &nt->qp_vec[qp_num]; in ntb_transport_setup_qp_msi()
725 int spad = qp_num * 2 + nt->msi_spad_offset; in ntb_transport_setup_qp_msi()
728 if (!nt->use_msi) in ntb_transport_setup_qp_msi()
731 if (spad >= ntb_spad_count(nt->ndev)) { in ntb_transport_setup_qp_msi()
767 devm_free_irq(&nt->ndev->dev, qp->msi_irq, qp); in ntb_transport_setup_qp_msi()
770 static void ntb_transport_msi_peer_desc_changed(struct ntb_transport_ctx *nt) in ntb_transport_msi_peer_desc_changed() argument
774 dev_dbg(&nt->ndev->pdev->dev, "Peer MSI descriptors changed"); in ntb_transport_msi_peer_desc_changed()
776 for (i = 0; i < nt->qp_count; i++) in ntb_transport_msi_peer_desc_changed()
777 ntb_transport_setup_qp_peer_msi(nt, i); in ntb_transport_msi_peer_desc_changed()
782 struct ntb_transport_ctx *nt = data; in ntb_transport_msi_desc_changed() local
785 dev_dbg(&nt->ndev->pdev->dev, "MSI descriptors changed"); in ntb_transport_msi_desc_changed()
787 for (i = 0; i < nt->qp_count; i++) in ntb_transport_msi_desc_changed()
788 ntb_transport_setup_qp_msi(nt, i); in ntb_transport_msi_desc_changed()
790 ntb_peer_db_set(nt->ndev, nt->msi_db_mask); in ntb_transport_msi_desc_changed()
793 static void ntb_free_mw(struct ntb_transport_ctx *nt, int num_mw) in ntb_free_mw() argument
795 struct ntb_transport_mw *mw = &nt->mw_vec[num_mw]; in ntb_free_mw()
796 struct pci_dev *pdev = nt->ndev->pdev; in ntb_free_mw()
801 ntb_mw_clear_trans(nt->ndev, PIDX, num_mw); in ntb_free_mw()
868 static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, in ntb_set_mw() argument
871 struct ntb_transport_mw *mw = &nt->mw_vec[num_mw]; in ntb_set_mw()
872 struct pci_dev *pdev = nt->ndev->pdev; in ntb_set_mw()
881 rc = ntb_mw_get_align(nt->ndev, PIDX, num_mw, &xlat_align, in ntb_set_mw()
894 ntb_free_mw(nt, num_mw); in ntb_set_mw()
916 rc = ntb_mw_set_trans(nt->ndev, PIDX, num_mw, mw->dma_addr, in ntb_set_mw()
920 ntb_free_mw(nt, num_mw); in ntb_set_mw()
959 struct ntb_transport_ctx *nt = qp->transport; in ntb_qp_link_cleanup() local
960 struct pci_dev *pdev = nt->ndev->pdev; in ntb_qp_link_cleanup()
976 struct ntb_transport_ctx *nt = qp->transport; in ntb_qp_link_cleanup_work() local
980 if (nt->link_is_up) in ntb_qp_link_cleanup_work()
990 static void ntb_transport_link_cleanup(struct ntb_transport_ctx *nt) in ntb_transport_link_cleanup() argument
996 qp_bitmap_alloc = nt->qp_bitmap & ~nt->qp_bitmap_free; in ntb_transport_link_cleanup()
999 for (i = 0; i < nt->qp_count; i++) in ntb_transport_link_cleanup()
1001 qp = &nt->qp_vec[i]; in ntb_transport_link_cleanup()
1007 if (!nt->link_is_up) in ntb_transport_link_cleanup()
1008 cancel_delayed_work_sync(&nt->link_work); in ntb_transport_link_cleanup()
1010 for (i = 0; i < nt->mw_count; i++) in ntb_transport_link_cleanup()
1011 ntb_free_mw(nt, i); in ntb_transport_link_cleanup()
1017 count = ntb_spad_count(nt->ndev); in ntb_transport_link_cleanup()
1019 ntb_spad_write(nt->ndev, i, 0); in ntb_transport_link_cleanup()
1024 struct ntb_transport_ctx *nt = in ntb_transport_link_cleanup_work() local
1027 ntb_transport_link_cleanup(nt); in ntb_transport_link_cleanup_work()
1032 struct ntb_transport_ctx *nt = data; in ntb_transport_event_callback() local
1034 if (ntb_link_is_up(nt->ndev, NULL, NULL) == 1) in ntb_transport_event_callback()
1035 schedule_delayed_work(&nt->link_work, 0); in ntb_transport_event_callback()
1037 schedule_work(&nt->link_cleanup); in ntb_transport_event_callback()
1042 struct ntb_transport_ctx *nt = in ntb_transport_link_work() local
1044 struct ntb_dev *ndev = nt->ndev; in ntb_transport_link_work()
1052 if (nt->use_msi) { in ntb_transport_link_work()
1058 nt->use_msi = false; in ntb_transport_link_work()
1062 for (i = 0; i < nt->qp_count; i++) in ntb_transport_link_work()
1063 ntb_transport_setup_qp_msi(nt, i); in ntb_transport_link_work()
1065 for (i = 0; i < nt->mw_count; i++) { in ntb_transport_link_work()
1066 size = nt->mw_vec[i].phys_size; in ntb_transport_link_work()
1078 ntb_peer_spad_write(ndev, PIDX, NUM_MWS, nt->mw_count); in ntb_transport_link_work()
1080 ntb_peer_spad_write(ndev, PIDX, NUM_QPS, nt->qp_count); in ntb_transport_link_work()
1092 if (val != nt->qp_count) in ntb_transport_link_work()
1097 if (val != nt->mw_count) in ntb_transport_link_work()
1100 for (i = 0; i < nt->mw_count; i++) { in ntb_transport_link_work()
1111 rc = ntb_set_mw(nt, i, val64); in ntb_transport_link_work()
1116 nt->link_is_up = true; in ntb_transport_link_work()
1118 for (i = 0; i < nt->qp_count; i++) { in ntb_transport_link_work()
1119 struct ntb_transport_qp *qp = &nt->qp_vec[i]; in ntb_transport_link_work()
1121 ntb_transport_setup_qp_mw(nt, i); in ntb_transport_link_work()
1122 ntb_transport_setup_qp_peer_msi(nt, i); in ntb_transport_link_work()
1131 for (i = 0; i < nt->mw_count; i++) in ntb_transport_link_work()
1132 ntb_free_mw(nt, i); in ntb_transport_link_work()
1140 schedule_delayed_work(&nt->link_work, in ntb_transport_link_work()
1150 struct ntb_transport_ctx *nt = qp->transport; in ntb_qp_link_work() local
1153 WARN_ON(!nt->link_is_up); in ntb_qp_link_work()
1155 val = ntb_spad_read(nt->ndev, QP_LINKS); in ntb_qp_link_work()
1157 ntb_peer_spad_write(nt->ndev, PIDX, QP_LINKS, val | BIT(qp->qp_num)); in ntb_qp_link_work()
1173 } else if (nt->link_is_up) in ntb_qp_link_work()
1178 static int ntb_transport_init_queue(struct ntb_transport_ctx *nt, in ntb_transport_init_queue() argument
1188 mw_count = nt->mw_count; in ntb_transport_init_queue()
1189 qp_count = nt->qp_count; in ntb_transport_init_queue()
1191 mw_num = QP_TO_MW(nt, qp_num); in ntb_transport_init_queue()
1193 qp = &nt->qp_vec[qp_num]; in ntb_transport_init_queue()
1195 qp->transport = nt; in ntb_transport_init_queue()
1196 qp->ndev = nt->ndev; in ntb_transport_init_queue()
1206 mw_base = nt->mw_vec[mw_num].phys_addr; in ntb_transport_init_queue()
1207 mw_size = nt->mw_vec[mw_num].phys_size; in ntb_transport_init_queue()
1216 qp->tx_mw = nt->mw_vec[mw_num].vbase + qp_offset; in ntb_transport_init_queue()
1231 if (nt->debugfs_node_dir) { in ntb_transport_init_queue()
1236 nt->debugfs_node_dir); in ntb_transport_init_queue()
1265 struct ntb_transport_ctx *nt; in ntb_transport_probe() local
1291 nt = kzalloc_node(sizeof(*nt), GFP_KERNEL, node); in ntb_transport_probe()
1292 if (!nt) in ntb_transport_probe()
1295 nt->ndev = ndev; in ntb_transport_probe()
1305 nt->use_msi = true; in ntb_transport_probe()
1314 nt->mw_count = 0; in ntb_transport_probe()
1320 nt->mw_count = min(mw_count, max_mw_count_for_spads); in ntb_transport_probe()
1322 nt->msi_spad_offset = nt->mw_count * 2 + MW0_SZ_HIGH; in ntb_transport_probe()
1324 nt->mw_vec = kcalloc_node(mw_count, sizeof(*nt->mw_vec), in ntb_transport_probe()
1326 if (!nt->mw_vec) { in ntb_transport_probe()
1332 mw = &nt->mw_vec[i]; in ntb_transport_probe()
1354 if (nt->use_msi) { in ntb_transport_probe()
1356 nt->msi_db_mask = 1 << qp_count; in ntb_transport_probe()
1357 ntb_db_clear_mask(ndev, nt->msi_db_mask); in ntb_transport_probe()
1362 else if (nt->mw_count < qp_count) in ntb_transport_probe()
1363 qp_count = nt->mw_count; in ntb_transport_probe()
1367 nt->qp_count = qp_count; in ntb_transport_probe()
1368 nt->qp_bitmap = qp_bitmap; in ntb_transport_probe()
1369 nt->qp_bitmap_free = qp_bitmap; in ntb_transport_probe()
1371 nt->qp_vec = kcalloc_node(qp_count, sizeof(*nt->qp_vec), in ntb_transport_probe()
1373 if (!nt->qp_vec) { in ntb_transport_probe()
1379 nt->debugfs_node_dir = in ntb_transport_probe()
1385 rc = ntb_transport_init_queue(nt, i); in ntb_transport_probe()
1390 INIT_DELAYED_WORK(&nt->link_work, ntb_transport_link_work); in ntb_transport_probe()
1391 INIT_WORK(&nt->link_cleanup, ntb_transport_link_cleanup_work); in ntb_transport_probe()
1393 rc = ntb_set_ctx(ndev, nt, &ntb_transport_ops); in ntb_transport_probe()
1397 INIT_LIST_HEAD(&nt->client_devs); in ntb_transport_probe()
1398 rc = ntb_bus_init(nt); in ntb_transport_probe()
1402 nt->link_is_up = false; in ntb_transport_probe()
1411 kfree(nt->qp_vec); in ntb_transport_probe()
1414 mw = &nt->mw_vec[i]; in ntb_transport_probe()
1417 kfree(nt->mw_vec); in ntb_transport_probe()
1419 kfree(nt); in ntb_transport_probe()
1425 struct ntb_transport_ctx *nt = ndev->ctx; in ntb_transport_free() local
1430 ntb_transport_link_cleanup(nt); in ntb_transport_free()
1431 cancel_work_sync(&nt->link_cleanup); in ntb_transport_free()
1432 cancel_delayed_work_sync(&nt->link_work); in ntb_transport_free()
1434 qp_bitmap_alloc = nt->qp_bitmap & ~nt->qp_bitmap_free; in ntb_transport_free()
1437 for (i = 0; i < nt->qp_count; i++) { in ntb_transport_free()
1438 qp = &nt->qp_vec[i]; in ntb_transport_free()
1447 ntb_bus_remove(nt); in ntb_transport_free()
1449 for (i = nt->mw_count; i--; ) { in ntb_transport_free()
1450 ntb_free_mw(nt, i); in ntb_transport_free()
1451 iounmap(nt->mw_vec[i].vbase); in ntb_transport_free()
1454 kfree(nt->qp_vec); in ntb_transport_free()
1455 kfree(nt->mw_vec); in ntb_transport_free()
1456 kfree(nt); in ntb_transport_free()
2002 struct ntb_transport_ctx *nt; in ntb_transport_create_queue() local
2013 nt = ndev->ctx; in ntb_transport_create_queue()
2017 free_queue = ffs(nt->qp_bitmap_free); in ntb_transport_create_queue()
2024 qp = &nt->qp_vec[free_queue]; in ntb_transport_create_queue()
2027 nt->qp_bitmap_free &= ~qp_bit; in ntb_transport_create_queue()
2116 nt->qp_bitmap_free |= qp_bit; in ntb_transport_create_queue()
2453 struct ntb_transport_ctx *nt = data; in ntb_transport_doorbell_callback() local
2458 if (ntb_db_read(nt->ndev) & nt->msi_db_mask) { in ntb_transport_doorbell_callback()
2459 ntb_transport_msi_peer_desc_changed(nt); in ntb_transport_doorbell_callback()
2460 ntb_db_clear(nt->ndev, nt->msi_db_mask); in ntb_transport_doorbell_callback()
2463 db_bits = (nt->qp_bitmap & ~nt->qp_bitmap_free & in ntb_transport_doorbell_callback()
2464 ntb_db_vector_mask(nt->ndev, vector)); in ntb_transport_doorbell_callback()
2468 qp = &nt->qp_vec[qp_num]; in ntb_transport_doorbell_callback()