Lines Matching refs:qp
120 struct ntb_transport_qp *qp; member
148 void (*tx_handler)(struct ntb_transport_qp *qp, void *qp_data,
160 void (*rx_handler)(struct ntb_transport_qp *qp, void *qp_data,
272 #define QP_TO_MW(nt, qp) ((qp) % nt->mw_count) argument
279 static int ntb_async_tx_submit(struct ntb_transport_qp *qp,
468 struct ntb_transport_qp *qp; in debugfs_read() local
472 qp = filp->private_data; in debugfs_read()
474 if (!qp || !qp->link_is_up) in debugfs_read()
487 "rx_bytes - \t%llu\n", qp->rx_bytes); in debugfs_read()
489 "rx_pkts - \t%llu\n", qp->rx_pkts); in debugfs_read()
491 "rx_memcpy - \t%llu\n", qp->rx_memcpy); in debugfs_read()
493 "rx_async - \t%llu\n", qp->rx_async); in debugfs_read()
495 "rx_ring_empty - %llu\n", qp->rx_ring_empty); in debugfs_read()
497 "rx_err_no_buf - %llu\n", qp->rx_err_no_buf); in debugfs_read()
499 "rx_err_oflow - \t%llu\n", qp->rx_err_oflow); in debugfs_read()
501 "rx_err_ver - \t%llu\n", qp->rx_err_ver); in debugfs_read()
503 "rx_buff - \t0x%p\n", qp->rx_buff); in debugfs_read()
505 "rx_index - \t%u\n", qp->rx_index); in debugfs_read()
507 "rx_max_entry - \t%u\n", qp->rx_max_entry); in debugfs_read()
509 "rx_alloc_entry - \t%u\n\n", qp->rx_alloc_entry); in debugfs_read()
512 "tx_bytes - \t%llu\n", qp->tx_bytes); in debugfs_read()
514 "tx_pkts - \t%llu\n", qp->tx_pkts); in debugfs_read()
516 "tx_memcpy - \t%llu\n", qp->tx_memcpy); in debugfs_read()
518 "tx_async - \t%llu\n", qp->tx_async); in debugfs_read()
520 "tx_ring_full - \t%llu\n", qp->tx_ring_full); in debugfs_read()
522 "tx_err_no_buf - %llu\n", qp->tx_err_no_buf); in debugfs_read()
524 "tx_mw - \t0x%p\n", qp->tx_mw); in debugfs_read()
526 "tx_index (H) - \t%u\n", qp->tx_index); in debugfs_read()
529 qp->remote_rx_info->entry); in debugfs_read()
531 "tx_max_entry - \t%u\n", qp->tx_max_entry); in debugfs_read()
534 ntb_transport_tx_free_entry(qp)); in debugfs_read()
540 qp->tx_dma_chan ? "Yes" : "No"); in debugfs_read()
543 qp->rx_dma_chan ? "Yes" : "No"); in debugfs_read()
546 qp->link_is_up ? "Up" : "Down"); in debugfs_read()
618 struct ntb_transport_qp *qp = &nt->qp_vec[qp_num]; in ntb_transport_setup_qp_mw() local
642 qp->rx_buff = mw->virt_addr + rx_size * (qp_num / mw_count); in ntb_transport_setup_qp_mw()
645 qp->remote_rx_info = qp->rx_buff + rx_size; in ntb_transport_setup_qp_mw()
648 qp->rx_max_frame = min(transport_mtu, rx_size / 2); in ntb_transport_setup_qp_mw()
649 qp->rx_max_entry = rx_size / qp->rx_max_frame; in ntb_transport_setup_qp_mw()
650 qp->rx_index = 0; in ntb_transport_setup_qp_mw()
658 for (i = qp->rx_alloc_entry; i < qp->rx_max_entry; i++) { in ntb_transport_setup_qp_mw()
663 entry->qp = qp; in ntb_transport_setup_qp_mw()
664 ntb_list_add(&qp->ntb_rx_q_lock, &entry->entry, in ntb_transport_setup_qp_mw()
665 &qp->rx_free_q); in ntb_transport_setup_qp_mw()
666 qp->rx_alloc_entry++; in ntb_transport_setup_qp_mw()
669 qp->remote_rx_info->entry = qp->rx_max_entry - 1; in ntb_transport_setup_qp_mw()
672 for (i = 0; i < qp->rx_max_entry; i++) { in ntb_transport_setup_qp_mw()
673 void *offset = (qp->rx_buff + qp->rx_max_frame * (i + 1) - in ntb_transport_setup_qp_mw()
678 qp->rx_pkts = 0; in ntb_transport_setup_qp_mw()
679 qp->tx_pkts = 0; in ntb_transport_setup_qp_mw()
680 qp->tx_index = 0; in ntb_transport_setup_qp_mw()
687 struct ntb_transport_qp *qp = dev; in ntb_transport_isr() local
689 tasklet_schedule(&qp->rxc_db_work); in ntb_transport_isr()
697 struct ntb_transport_qp *qp = &nt->qp_vec[qp_num]; in ntb_transport_setup_qp_peer_msi() local
706 qp->peer_msi_desc.addr_offset = in ntb_transport_setup_qp_peer_msi()
707 ntb_peer_spad_read(qp->ndev, PIDX, spad); in ntb_transport_setup_qp_peer_msi()
708 qp->peer_msi_desc.data = in ntb_transport_setup_qp_peer_msi()
709 ntb_peer_spad_read(qp->ndev, PIDX, spad + 1); in ntb_transport_setup_qp_peer_msi()
711 dev_dbg(&qp->ndev->pdev->dev, "QP%d Peer MSI addr=%x data=%x\n", in ntb_transport_setup_qp_peer_msi()
712 qp_num, qp->peer_msi_desc.addr_offset, qp->peer_msi_desc.data); in ntb_transport_setup_qp_peer_msi()
714 if (qp->peer_msi_desc.addr_offset) { in ntb_transport_setup_qp_peer_msi()
715 qp->use_msi = true; in ntb_transport_setup_qp_peer_msi()
716 dev_info(&qp->ndev->pdev->dev, in ntb_transport_setup_qp_peer_msi()
724 struct ntb_transport_qp *qp = &nt->qp_vec[qp_num]; in ntb_transport_setup_qp_msi() local
732 dev_warn_once(&qp->ndev->pdev->dev, in ntb_transport_setup_qp_msi()
737 ntb_spad_write(qp->ndev, spad, 0); in ntb_transport_setup_qp_msi()
738 ntb_spad_write(qp->ndev, spad + 1, 0); in ntb_transport_setup_qp_msi()
740 if (!qp->msi_irq) { in ntb_transport_setup_qp_msi()
741 qp->msi_irq = ntbm_msi_request_irq(qp->ndev, ntb_transport_isr, in ntb_transport_setup_qp_msi()
742 KBUILD_MODNAME, qp, in ntb_transport_setup_qp_msi()
743 &qp->msi_desc); in ntb_transport_setup_qp_msi()
744 if (qp->msi_irq < 0) { in ntb_transport_setup_qp_msi()
745 dev_warn(&qp->ndev->pdev->dev, in ntb_transport_setup_qp_msi()
752 rc = ntb_spad_write(qp->ndev, spad, qp->msi_desc.addr_offset); in ntb_transport_setup_qp_msi()
756 rc = ntb_spad_write(qp->ndev, spad + 1, qp->msi_desc.data); in ntb_transport_setup_qp_msi()
760 dev_dbg(&qp->ndev->pdev->dev, "QP%d MSI %d addr=%x data=%x\n", in ntb_transport_setup_qp_msi()
761 qp_num, qp->msi_irq, qp->msi_desc.addr_offset, in ntb_transport_setup_qp_msi()
762 qp->msi_desc.data); in ntb_transport_setup_qp_msi()
767 devm_free_irq(&nt->ndev->dev, qp->msi_irq, qp); in ntb_transport_setup_qp_msi()
914 static void ntb_qp_link_context_reset(struct ntb_transport_qp *qp) in ntb_qp_link_context_reset() argument
916 qp->link_is_up = false; in ntb_qp_link_context_reset()
917 qp->active = false; in ntb_qp_link_context_reset()
919 qp->tx_index = 0; in ntb_qp_link_context_reset()
920 qp->rx_index = 0; in ntb_qp_link_context_reset()
921 qp->rx_bytes = 0; in ntb_qp_link_context_reset()
922 qp->rx_pkts = 0; in ntb_qp_link_context_reset()
923 qp->rx_ring_empty = 0; in ntb_qp_link_context_reset()
924 qp->rx_err_no_buf = 0; in ntb_qp_link_context_reset()
925 qp->rx_err_oflow = 0; in ntb_qp_link_context_reset()
926 qp->rx_err_ver = 0; in ntb_qp_link_context_reset()
927 qp->rx_memcpy = 0; in ntb_qp_link_context_reset()
928 qp->rx_async = 0; in ntb_qp_link_context_reset()
929 qp->tx_bytes = 0; in ntb_qp_link_context_reset()
930 qp->tx_pkts = 0; in ntb_qp_link_context_reset()
931 qp->tx_ring_full = 0; in ntb_qp_link_context_reset()
932 qp->tx_err_no_buf = 0; in ntb_qp_link_context_reset()
933 qp->tx_memcpy = 0; in ntb_qp_link_context_reset()
934 qp->tx_async = 0; in ntb_qp_link_context_reset()
937 static void ntb_qp_link_down_reset(struct ntb_transport_qp *qp) in ntb_qp_link_down_reset() argument
939 ntb_qp_link_context_reset(qp); in ntb_qp_link_down_reset()
940 if (qp->remote_rx_info) in ntb_qp_link_down_reset()
941 qp->remote_rx_info->entry = qp->rx_max_entry - 1; in ntb_qp_link_down_reset()
944 static void ntb_qp_link_cleanup(struct ntb_transport_qp *qp) in ntb_qp_link_cleanup() argument
946 struct ntb_transport_ctx *nt = qp->transport; in ntb_qp_link_cleanup()
949 dev_info(&pdev->dev, "qp %d: Link Cleanup\n", qp->qp_num); in ntb_qp_link_cleanup()
951 cancel_delayed_work_sync(&qp->link_work); in ntb_qp_link_cleanup()
952 ntb_qp_link_down_reset(qp); in ntb_qp_link_cleanup()
954 if (qp->event_handler) in ntb_qp_link_cleanup()
955 qp->event_handler(qp->cb_data, qp->link_is_up); in ntb_qp_link_cleanup()
960 struct ntb_transport_qp *qp = container_of(work, in ntb_qp_link_cleanup_work() local
963 struct ntb_transport_ctx *nt = qp->transport; in ntb_qp_link_cleanup_work()
965 ntb_qp_link_cleanup(qp); in ntb_qp_link_cleanup_work()
968 schedule_delayed_work(&qp->link_work, in ntb_qp_link_cleanup_work()
972 static void ntb_qp_link_down(struct ntb_transport_qp *qp) in ntb_qp_link_down() argument
974 schedule_work(&qp->link_cleanup); in ntb_qp_link_down()
979 struct ntb_transport_qp *qp; in ntb_transport_link_cleanup() local
988 qp = &nt->qp_vec[i]; in ntb_transport_link_cleanup()
989 ntb_qp_link_cleanup(qp); in ntb_transport_link_cleanup()
990 cancel_work_sync(&qp->link_cleanup); in ntb_transport_link_cleanup()
991 cancel_delayed_work_sync(&qp->link_work); in ntb_transport_link_cleanup()
1106 struct ntb_transport_qp *qp = &nt->qp_vec[i]; in ntb_transport_link_work() local
1111 if (qp->client_ready) in ntb_transport_link_work()
1112 schedule_delayed_work(&qp->link_work, 0); in ntb_transport_link_work()
1133 struct ntb_transport_qp *qp = container_of(work, in ntb_qp_link_work() local
1136 struct pci_dev *pdev = qp->ndev->pdev; in ntb_qp_link_work()
1137 struct ntb_transport_ctx *nt = qp->transport; in ntb_qp_link_work()
1144 ntb_peer_spad_write(nt->ndev, PIDX, QP_LINKS, val | BIT(qp->qp_num)); in ntb_qp_link_work()
1150 if (val & BIT(qp->qp_num)) { in ntb_qp_link_work()
1151 dev_info(&pdev->dev, "qp %d: Link Up\n", qp->qp_num); in ntb_qp_link_work()
1152 qp->link_is_up = true; in ntb_qp_link_work()
1153 qp->active = true; in ntb_qp_link_work()
1155 if (qp->event_handler) in ntb_qp_link_work()
1156 qp->event_handler(qp->cb_data, qp->link_is_up); in ntb_qp_link_work()
1158 if (qp->active) in ntb_qp_link_work()
1159 tasklet_schedule(&qp->rxc_db_work); in ntb_qp_link_work()
1161 schedule_delayed_work(&qp->link_work, in ntb_qp_link_work()
1168 struct ntb_transport_qp *qp; in ntb_transport_init_queue() local
1180 qp = &nt->qp_vec[qp_num]; in ntb_transport_init_queue()
1181 qp->qp_num = qp_num; in ntb_transport_init_queue()
1182 qp->transport = nt; in ntb_transport_init_queue()
1183 qp->ndev = nt->ndev; in ntb_transport_init_queue()
1184 qp->client_ready = false; in ntb_transport_init_queue()
1185 qp->event_handler = NULL; in ntb_transport_init_queue()
1186 ntb_qp_link_context_reset(qp); in ntb_transport_init_queue()
1202 qp->tx_mw_size = tx_size; in ntb_transport_init_queue()
1203 qp->tx_mw = nt->mw_vec[mw_num].vbase + qp_offset; in ntb_transport_init_queue()
1204 if (!qp->tx_mw) in ntb_transport_init_queue()
1207 qp->tx_mw_phys = mw_base + qp_offset; in ntb_transport_init_queue()
1208 if (!qp->tx_mw_phys) in ntb_transport_init_queue()
1212 qp->rx_info = qp->tx_mw + tx_size; in ntb_transport_init_queue()
1215 qp->tx_max_frame = min(transport_mtu, tx_size / 2); in ntb_transport_init_queue()
1216 qp->tx_max_entry = tx_size / qp->tx_max_frame; in ntb_transport_init_queue()
1222 qp->debugfs_dir = debugfs_create_dir(debugfs_name, in ntb_transport_init_queue()
1225 qp->debugfs_stats = debugfs_create_file("stats", S_IRUSR, in ntb_transport_init_queue()
1226 qp->debugfs_dir, qp, in ntb_transport_init_queue()
1229 qp->debugfs_dir = NULL; in ntb_transport_init_queue()
1230 qp->debugfs_stats = NULL; in ntb_transport_init_queue()
1233 INIT_DELAYED_WORK(&qp->link_work, ntb_qp_link_work); in ntb_transport_init_queue()
1234 INIT_WORK(&qp->link_cleanup, ntb_qp_link_cleanup_work); in ntb_transport_init_queue()
1236 spin_lock_init(&qp->ntb_rx_q_lock); in ntb_transport_init_queue()
1237 spin_lock_init(&qp->ntb_tx_free_q_lock); in ntb_transport_init_queue()
1239 INIT_LIST_HEAD(&qp->rx_post_q); in ntb_transport_init_queue()
1240 INIT_LIST_HEAD(&qp->rx_pend_q); in ntb_transport_init_queue()
1241 INIT_LIST_HEAD(&qp->rx_free_q); in ntb_transport_init_queue()
1242 INIT_LIST_HEAD(&qp->tx_free_q); in ntb_transport_init_queue()
1244 tasklet_init(&qp->rxc_db_work, ntb_transport_rxc_db, in ntb_transport_init_queue()
1245 (unsigned long)qp); in ntb_transport_init_queue()
1413 struct ntb_transport_qp *qp; in ntb_transport_free() local
1425 qp = &nt->qp_vec[i]; in ntb_transport_free()
1427 ntb_transport_free_queue(qp); in ntb_transport_free()
1428 debugfs_remove_recursive(qp->debugfs_dir); in ntb_transport_free()
1446 static void ntb_complete_rxc(struct ntb_transport_qp *qp) in ntb_complete_rxc() argument
1453 spin_lock_irqsave(&qp->ntb_rx_q_lock, irqflags); in ntb_complete_rxc()
1455 while (!list_empty(&qp->rx_post_q)) { in ntb_complete_rxc()
1456 entry = list_first_entry(&qp->rx_post_q, in ntb_complete_rxc()
1462 iowrite32(entry->rx_index, &qp->rx_info->entry); in ntb_complete_rxc()
1467 list_move_tail(&entry->entry, &qp->rx_free_q); in ntb_complete_rxc()
1469 spin_unlock_irqrestore(&qp->ntb_rx_q_lock, irqflags); in ntb_complete_rxc()
1471 if (qp->rx_handler && qp->client_ready) in ntb_complete_rxc()
1472 qp->rx_handler(qp, qp->cb_data, cb_data, len); in ntb_complete_rxc()
1474 spin_lock_irqsave(&qp->ntb_rx_q_lock, irqflags); in ntb_complete_rxc()
1477 spin_unlock_irqrestore(&qp->ntb_rx_q_lock, irqflags); in ntb_complete_rxc()
1496 struct ntb_transport_qp *qp = entry->qp; in ntb_rx_copy_callback() local
1497 void *offset = qp->rx_buff + qp->rx_max_frame * in ntb_rx_copy_callback()
1498 qp->rx_index; in ntb_rx_copy_callback()
1501 qp->rx_memcpy++; in ntb_rx_copy_callback()
1513 ntb_complete_rxc(entry->qp); in ntb_rx_copy_callback()
1532 struct ntb_transport_qp *qp = entry->qp; in ntb_async_rx_submit() local
1533 struct dma_chan *chan = qp->rx_dma_chan; in ntb_async_rx_submit()
1583 qp->last_cookie = cookie; in ntb_async_rx_submit()
1585 qp->rx_async++; in ntb_async_rx_submit()
1599 struct ntb_transport_qp *qp = entry->qp; in ntb_async_rx() local
1600 struct dma_chan *chan = qp->rx_dma_chan; in ntb_async_rx()
1614 qp->rx_async++; in ntb_async_rx()
1620 qp->rx_memcpy++; in ntb_async_rx()
1623 static int ntb_process_rxc(struct ntb_transport_qp *qp) in ntb_process_rxc() argument
1629 offset = qp->rx_buff + qp->rx_max_frame * qp->rx_index; in ntb_process_rxc()
1630 hdr = offset + qp->rx_max_frame - sizeof(struct ntb_payload_header); in ntb_process_rxc()
1632 dev_dbg(&qp->ndev->pdev->dev, "qp %d: RX ver %u len %d flags %x\n", in ntb_process_rxc()
1633 qp->qp_num, hdr->ver, hdr->len, hdr->flags); in ntb_process_rxc()
1636 dev_dbg(&qp->ndev->pdev->dev, "done flag not set\n"); in ntb_process_rxc()
1637 qp->rx_ring_empty++; in ntb_process_rxc()
1642 dev_dbg(&qp->ndev->pdev->dev, "link down flag set\n"); in ntb_process_rxc()
1643 ntb_qp_link_down(qp); in ntb_process_rxc()
1648 if (hdr->ver != (u32)qp->rx_pkts) { in ntb_process_rxc()
1649 dev_dbg(&qp->ndev->pdev->dev, in ntb_process_rxc()
1651 qp->rx_pkts, hdr->ver); in ntb_process_rxc()
1652 qp->rx_err_ver++; in ntb_process_rxc()
1656 entry = ntb_list_mv(&qp->ntb_rx_q_lock, &qp->rx_pend_q, &qp->rx_post_q); in ntb_process_rxc()
1658 dev_dbg(&qp->ndev->pdev->dev, "no receive buffer\n"); in ntb_process_rxc()
1659 qp->rx_err_no_buf++; in ntb_process_rxc()
1664 entry->rx_index = qp->rx_index; in ntb_process_rxc()
1667 dev_dbg(&qp->ndev->pdev->dev, in ntb_process_rxc()
1670 qp->rx_err_oflow++; in ntb_process_rxc()
1675 ntb_complete_rxc(qp); in ntb_process_rxc()
1677 dev_dbg(&qp->ndev->pdev->dev, in ntb_process_rxc()
1679 qp->rx_index, hdr->ver, hdr->len, entry->len); in ntb_process_rxc()
1681 qp->rx_bytes += hdr->len; in ntb_process_rxc()
1682 qp->rx_pkts++; in ntb_process_rxc()
1689 qp->rx_index++; in ntb_process_rxc()
1690 qp->rx_index %= qp->rx_max_entry; in ntb_process_rxc()
1697 struct ntb_transport_qp *qp = (void *)data; in ntb_transport_rxc_db() local
1700 dev_dbg(&qp->ndev->pdev->dev, "%s: doorbell %d received\n", in ntb_transport_rxc_db()
1701 __func__, qp->qp_num); in ntb_transport_rxc_db()
1706 for (i = 0; i < qp->rx_max_entry; i++) { in ntb_transport_rxc_db()
1707 rc = ntb_process_rxc(qp); in ntb_transport_rxc_db()
1712 if (i && qp->rx_dma_chan) in ntb_transport_rxc_db()
1713 dma_async_issue_pending(qp->rx_dma_chan); in ntb_transport_rxc_db()
1715 if (i == qp->rx_max_entry) { in ntb_transport_rxc_db()
1717 if (qp->active) in ntb_transport_rxc_db()
1718 tasklet_schedule(&qp->rxc_db_work); in ntb_transport_rxc_db()
1719 } else if (ntb_db_read(qp->ndev) & BIT_ULL(qp->qp_num)) { in ntb_transport_rxc_db()
1721 ntb_db_clear(qp->ndev, BIT_ULL(qp->qp_num)); in ntb_transport_rxc_db()
1723 ntb_db_read(qp->ndev); in ntb_transport_rxc_db()
1729 if (qp->active) in ntb_transport_rxc_db()
1730 tasklet_schedule(&qp->rxc_db_work); in ntb_transport_rxc_db()
1738 struct ntb_transport_qp *qp = entry->qp; in ntb_tx_copy_callback() local
1753 qp->tx_mw + qp->tx_max_frame * in ntb_tx_copy_callback()
1758 qp->tx_memcpy++; in ntb_tx_copy_callback()
1770 if (qp->use_msi) in ntb_tx_copy_callback()
1771 ntb_msi_peer_trigger(qp->ndev, PIDX, &qp->peer_msi_desc); in ntb_tx_copy_callback()
1773 ntb_peer_db_set(qp->ndev, BIT_ULL(qp->qp_num)); in ntb_tx_copy_callback()
1780 qp->tx_bytes += entry->len; in ntb_tx_copy_callback()
1782 if (qp->tx_handler) in ntb_tx_copy_callback()
1783 qp->tx_handler(qp, qp->cb_data, entry->cb_data, in ntb_tx_copy_callback()
1787 ntb_list_add(&qp->ntb_tx_free_q_lock, &entry->entry, &qp->tx_free_q); in ntb_tx_copy_callback()
1808 static int ntb_async_tx_submit(struct ntb_transport_qp *qp, in ntb_async_tx_submit() argument
1812 struct dma_chan *chan = qp->tx_dma_chan; in ntb_async_tx_submit()
1822 dest = qp->tx_mw_dma_addr + qp->tx_max_frame * entry->tx_index; in ntb_async_tx_submit()
1867 static void ntb_async_tx(struct ntb_transport_qp *qp, in ntb_async_tx() argument
1871 struct dma_chan *chan = qp->tx_dma_chan; in ntb_async_tx()
1875 entry->tx_index = qp->tx_index; in ntb_async_tx()
1876 offset = qp->tx_mw + qp->tx_max_frame * entry->tx_index; in ntb_async_tx()
1877 hdr = offset + qp->tx_max_frame - sizeof(struct ntb_payload_header); in ntb_async_tx()
1881 iowrite32((u32)qp->tx_pkts, &hdr->ver); in ntb_async_tx()
1889 res = ntb_async_tx_submit(qp, entry); in ntb_async_tx()
1894 qp->tx_async++; in ntb_async_tx()
1900 qp->tx_memcpy++; in ntb_async_tx()
1903 static int ntb_process_tx(struct ntb_transport_qp *qp, in ntb_process_tx() argument
1906 if (qp->tx_index == qp->remote_rx_info->entry) { in ntb_process_tx()
1907 qp->tx_ring_full++; in ntb_process_tx()
1911 if (entry->len > qp->tx_max_frame - sizeof(struct ntb_payload_header)) { in ntb_process_tx()
1912 if (qp->tx_handler) in ntb_process_tx()
1913 qp->tx_handler(qp, qp->cb_data, NULL, -EIO); in ntb_process_tx()
1915 ntb_list_add(&qp->ntb_tx_free_q_lock, &entry->entry, in ntb_process_tx()
1916 &qp->tx_free_q); in ntb_process_tx()
1920 ntb_async_tx(qp, entry); in ntb_process_tx()
1922 qp->tx_index++; in ntb_process_tx()
1923 qp->tx_index %= qp->tx_max_entry; in ntb_process_tx()
1925 qp->tx_pkts++; in ntb_process_tx()
1930 static void ntb_send_link_down(struct ntb_transport_qp *qp) in ntb_send_link_down() argument
1932 struct pci_dev *pdev = qp->ndev->pdev; in ntb_send_link_down()
1936 if (!qp->link_is_up) in ntb_send_link_down()
1939 dev_info(&pdev->dev, "qp %d: Send Link Down\n", qp->qp_num); in ntb_send_link_down()
1942 entry = ntb_list_rm(&qp->ntb_tx_free_q_lock, &qp->tx_free_q); in ntb_send_link_down()
1956 rc = ntb_process_tx(qp, entry); in ntb_send_link_down()
1959 qp->qp_num); in ntb_send_link_down()
1961 ntb_qp_link_down_reset(qp); in ntb_send_link_down()
1991 struct ntb_transport_qp *qp; in ntb_transport_create_queue() local
2011 qp = &nt->qp_vec[free_queue]; in ntb_transport_create_queue()
2012 qp_bit = BIT_ULL(qp->qp_num); in ntb_transport_create_queue()
2016 qp->cb_data = data; in ntb_transport_create_queue()
2017 qp->rx_handler = handlers->rx_handler; in ntb_transport_create_queue()
2018 qp->tx_handler = handlers->tx_handler; in ntb_transport_create_queue()
2019 qp->event_handler = handlers->event_handler; in ntb_transport_create_queue()
2025 qp->tx_dma_chan = in ntb_transport_create_queue()
2028 if (!qp->tx_dma_chan) in ntb_transport_create_queue()
2031 qp->rx_dma_chan = in ntb_transport_create_queue()
2034 if (!qp->rx_dma_chan) in ntb_transport_create_queue()
2037 qp->tx_dma_chan = NULL; in ntb_transport_create_queue()
2038 qp->rx_dma_chan = NULL; in ntb_transport_create_queue()
2041 qp->tx_mw_dma_addr = 0; in ntb_transport_create_queue()
2042 if (qp->tx_dma_chan) { in ntb_transport_create_queue()
2043 qp->tx_mw_dma_addr = in ntb_transport_create_queue()
2044 dma_map_resource(qp->tx_dma_chan->device->dev, in ntb_transport_create_queue()
2045 qp->tx_mw_phys, qp->tx_mw_size, in ntb_transport_create_queue()
2047 if (dma_mapping_error(qp->tx_dma_chan->device->dev, in ntb_transport_create_queue()
2048 qp->tx_mw_dma_addr)) { in ntb_transport_create_queue()
2049 qp->tx_mw_dma_addr = 0; in ntb_transport_create_queue()
2055 qp->tx_dma_chan ? "DMA" : "CPU"); in ntb_transport_create_queue()
2058 qp->rx_dma_chan ? "DMA" : "CPU"); in ntb_transport_create_queue()
2065 entry->qp = qp; in ntb_transport_create_queue()
2066 ntb_list_add(&qp->ntb_rx_q_lock, &entry->entry, in ntb_transport_create_queue()
2067 &qp->rx_free_q); in ntb_transport_create_queue()
2069 qp->rx_alloc_entry = NTB_QP_DEF_NUM_ENTRIES; in ntb_transport_create_queue()
2071 for (i = 0; i < qp->tx_max_entry; i++) { in ntb_transport_create_queue()
2076 entry->qp = qp; in ntb_transport_create_queue()
2077 ntb_list_add(&qp->ntb_tx_free_q_lock, &entry->entry, in ntb_transport_create_queue()
2078 &qp->tx_free_q); in ntb_transport_create_queue()
2081 ntb_db_clear(qp->ndev, qp_bit); in ntb_transport_create_queue()
2082 ntb_db_clear_mask(qp->ndev, qp_bit); in ntb_transport_create_queue()
2084 dev_info(&pdev->dev, "NTB Transport QP %d created\n", qp->qp_num); in ntb_transport_create_queue()
2086 return qp; in ntb_transport_create_queue()
2089 while ((entry = ntb_list_rm(&qp->ntb_tx_free_q_lock, &qp->tx_free_q))) in ntb_transport_create_queue()
2092 qp->rx_alloc_entry = 0; in ntb_transport_create_queue()
2093 while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_free_q))) in ntb_transport_create_queue()
2095 if (qp->tx_mw_dma_addr) in ntb_transport_create_queue()
2096 dma_unmap_resource(qp->tx_dma_chan->device->dev, in ntb_transport_create_queue()
2097 qp->tx_mw_dma_addr, qp->tx_mw_size, in ntb_transport_create_queue()
2099 if (qp->tx_dma_chan) in ntb_transport_create_queue()
2100 dma_release_channel(qp->tx_dma_chan); in ntb_transport_create_queue()
2101 if (qp->rx_dma_chan) in ntb_transport_create_queue()
2102 dma_release_channel(qp->rx_dma_chan); in ntb_transport_create_queue()
2115 void ntb_transport_free_queue(struct ntb_transport_qp *qp) in ntb_transport_free_queue() argument
2121 if (!qp) in ntb_transport_free_queue()
2124 pdev = qp->ndev->pdev; in ntb_transport_free_queue()
2126 qp->active = false; in ntb_transport_free_queue()
2128 if (qp->tx_dma_chan) { in ntb_transport_free_queue()
2129 struct dma_chan *chan = qp->tx_dma_chan; in ntb_transport_free_queue()
2133 qp->tx_dma_chan = NULL; in ntb_transport_free_queue()
2138 dma_sync_wait(chan, qp->last_cookie); in ntb_transport_free_queue()
2142 qp->tx_mw_dma_addr, qp->tx_mw_size, in ntb_transport_free_queue()
2148 if (qp->rx_dma_chan) { in ntb_transport_free_queue()
2149 struct dma_chan *chan = qp->rx_dma_chan; in ntb_transport_free_queue()
2153 qp->rx_dma_chan = NULL; in ntb_transport_free_queue()
2158 dma_sync_wait(chan, qp->last_cookie); in ntb_transport_free_queue()
2163 qp_bit = BIT_ULL(qp->qp_num); in ntb_transport_free_queue()
2165 ntb_db_set_mask(qp->ndev, qp_bit); in ntb_transport_free_queue()
2166 tasklet_kill(&qp->rxc_db_work); in ntb_transport_free_queue()
2168 cancel_delayed_work_sync(&qp->link_work); in ntb_transport_free_queue()
2170 qp->cb_data = NULL; in ntb_transport_free_queue()
2171 qp->rx_handler = NULL; in ntb_transport_free_queue()
2172 qp->tx_handler = NULL; in ntb_transport_free_queue()
2173 qp->event_handler = NULL; in ntb_transport_free_queue()
2175 while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_free_q))) in ntb_transport_free_queue()
2178 while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_pend_q))) { in ntb_transport_free_queue()
2183 while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_post_q))) { in ntb_transport_free_queue()
2188 while ((entry = ntb_list_rm(&qp->ntb_tx_free_q_lock, &qp->tx_free_q))) in ntb_transport_free_queue()
2191 qp->transport->qp_bitmap_free |= qp_bit; in ntb_transport_free_queue()
2193 dev_info(&pdev->dev, "NTB Transport QP %d freed\n", qp->qp_num); in ntb_transport_free_queue()
2207 void *ntb_transport_rx_remove(struct ntb_transport_qp *qp, unsigned int *len) in ntb_transport_rx_remove() argument
2212 if (!qp || qp->client_ready) in ntb_transport_rx_remove()
2215 entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_pend_q); in ntb_transport_rx_remove()
2222 ntb_list_add(&qp->ntb_rx_q_lock, &entry->entry, &qp->rx_free_q); in ntb_transport_rx_remove()
2240 int ntb_transport_rx_enqueue(struct ntb_transport_qp *qp, void *cb, void *data, in ntb_transport_rx_enqueue() argument
2245 if (!qp) in ntb_transport_rx_enqueue()
2248 entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_free_q); in ntb_transport_rx_enqueue()
2260 ntb_list_add(&qp->ntb_rx_q_lock, &entry->entry, &qp->rx_pend_q); in ntb_transport_rx_enqueue()
2262 if (qp->active) in ntb_transport_rx_enqueue()
2263 tasklet_schedule(&qp->rxc_db_work); in ntb_transport_rx_enqueue()
2282 int ntb_transport_tx_enqueue(struct ntb_transport_qp *qp, void *cb, void *data, in ntb_transport_tx_enqueue() argument
2288 if (!qp || !len) in ntb_transport_tx_enqueue()
2292 if (!qp->link_is_up) in ntb_transport_tx_enqueue()
2295 entry = ntb_list_rm(&qp->ntb_tx_free_q_lock, &qp->tx_free_q); in ntb_transport_tx_enqueue()
2297 qp->tx_err_no_buf++; in ntb_transport_tx_enqueue()
2309 rc = ntb_process_tx(qp, entry); in ntb_transport_tx_enqueue()
2311 ntb_list_add(&qp->ntb_tx_free_q_lock, &entry->entry, in ntb_transport_tx_enqueue()
2312 &qp->tx_free_q); in ntb_transport_tx_enqueue()
2324 void ntb_transport_link_up(struct ntb_transport_qp *qp) in ntb_transport_link_up() argument
2326 if (!qp) in ntb_transport_link_up()
2329 qp->client_ready = true; in ntb_transport_link_up()
2331 if (qp->transport->link_is_up) in ntb_transport_link_up()
2332 schedule_delayed_work(&qp->link_work, 0); in ntb_transport_link_up()
2344 void ntb_transport_link_down(struct ntb_transport_qp *qp) in ntb_transport_link_down() argument
2348 if (!qp) in ntb_transport_link_down()
2351 qp->client_ready = false; in ntb_transport_link_down()
2353 val = ntb_spad_read(qp->ndev, QP_LINKS); in ntb_transport_link_down()
2355 ntb_peer_spad_write(qp->ndev, PIDX, QP_LINKS, val & ~BIT(qp->qp_num)); in ntb_transport_link_down()
2357 if (qp->link_is_up) in ntb_transport_link_down()
2358 ntb_send_link_down(qp); in ntb_transport_link_down()
2360 cancel_delayed_work_sync(&qp->link_work); in ntb_transport_link_down()
2372 bool ntb_transport_link_query(struct ntb_transport_qp *qp) in ntb_transport_link_query() argument
2374 if (!qp) in ntb_transport_link_query()
2377 return qp->link_is_up; in ntb_transport_link_query()
2389 unsigned char ntb_transport_qp_num(struct ntb_transport_qp *qp) in ntb_transport_qp_num() argument
2391 if (!qp) in ntb_transport_qp_num()
2394 return qp->qp_num; in ntb_transport_qp_num()
2406 unsigned int ntb_transport_max_size(struct ntb_transport_qp *qp) in ntb_transport_max_size() argument
2412 if (!qp) in ntb_transport_max_size()
2415 rx_chan = qp->rx_dma_chan; in ntb_transport_max_size()
2416 tx_chan = qp->tx_dma_chan; in ntb_transport_max_size()
2422 max_size = qp->tx_max_frame - sizeof(struct ntb_payload_header); in ntb_transport_max_size()
2429 unsigned int ntb_transport_tx_free_entry(struct ntb_transport_qp *qp) in ntb_transport_tx_free_entry() argument
2431 unsigned int head = qp->tx_index; in ntb_transport_tx_free_entry()
2432 unsigned int tail = qp->remote_rx_info->entry; in ntb_transport_tx_free_entry()
2434 return tail >= head ? tail - head : qp->tx_max_entry + tail - head; in ntb_transport_tx_free_entry()
2441 struct ntb_transport_qp *qp; in ntb_transport_doorbell_callback() local
2455 qp = &nt->qp_vec[qp_num]; in ntb_transport_doorbell_callback()
2457 if (qp->active) in ntb_transport_doorbell_callback()
2458 tasklet_schedule(&qp->rxc_db_work); in ntb_transport_doorbell_callback()