• Home
  • Raw
  • Download

Lines Matching full:qp

120 	struct ntb_transport_qp *qp;  member
142 u8 qp_num; /* Only 64 QP's are allowed. 0-63 */
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,
466 struct ntb_transport_qp *qp; in debugfs_read() local
470 qp = filp->private_data; in debugfs_read()
472 if (!qp || !qp->link_is_up) in debugfs_read()
483 "\nNTB QP stats:\n\n"); in debugfs_read()
485 "rx_bytes - \t%llu\n", qp->rx_bytes); in debugfs_read()
487 "rx_pkts - \t%llu\n", qp->rx_pkts); in debugfs_read()
489 "rx_memcpy - \t%llu\n", qp->rx_memcpy); in debugfs_read()
491 "rx_async - \t%llu\n", qp->rx_async); in debugfs_read()
493 "rx_ring_empty - %llu\n", qp->rx_ring_empty); in debugfs_read()
495 "rx_err_no_buf - %llu\n", qp->rx_err_no_buf); in debugfs_read()
497 "rx_err_oflow - \t%llu\n", qp->rx_err_oflow); in debugfs_read()
499 "rx_err_ver - \t%llu\n", qp->rx_err_ver); in debugfs_read()
501 "rx_buff - \t0x%p\n", qp->rx_buff); in debugfs_read()
503 "rx_index - \t%u\n", qp->rx_index); in debugfs_read()
505 "rx_max_entry - \t%u\n", qp->rx_max_entry); in debugfs_read()
507 "rx_alloc_entry - \t%u\n\n", qp->rx_alloc_entry); in debugfs_read()
510 "tx_bytes - \t%llu\n", qp->tx_bytes); in debugfs_read()
512 "tx_pkts - \t%llu\n", qp->tx_pkts); in debugfs_read()
514 "tx_memcpy - \t%llu\n", qp->tx_memcpy); in debugfs_read()
516 "tx_async - \t%llu\n", qp->tx_async); in debugfs_read()
518 "tx_ring_full - \t%llu\n", qp->tx_ring_full); in debugfs_read()
520 "tx_err_no_buf - %llu\n", qp->tx_err_no_buf); in debugfs_read()
522 "tx_mw - \t0x%p\n", qp->tx_mw); in debugfs_read()
524 "tx_index (H) - \t%u\n", qp->tx_index); in debugfs_read()
527 qp->remote_rx_info->entry); in debugfs_read()
529 "tx_max_entry - \t%u\n", qp->tx_max_entry); in debugfs_read()
532 ntb_transport_tx_free_entry(qp)); in debugfs_read()
538 qp->tx_dma_chan ? "Yes" : "No"); in debugfs_read()
541 qp->rx_dma_chan ? "Yes" : "No"); in debugfs_read()
543 "QP Link - \t%s\n", in debugfs_read()
544 qp->link_is_up ? "Up" : "Down"); in debugfs_read()
616 struct ntb_transport_qp *qp = &nt->qp_vec[qp_num]; in ntb_transport_setup_qp_mw() local
640 qp->rx_buff = mw->virt_addr + rx_size * (qp_num / mw_count); in ntb_transport_setup_qp_mw()
643 qp->remote_rx_info = qp->rx_buff + rx_size; in ntb_transport_setup_qp_mw()
646 qp->rx_max_frame = min(transport_mtu, rx_size / 2); in ntb_transport_setup_qp_mw()
647 qp->rx_max_entry = rx_size / qp->rx_max_frame; in ntb_transport_setup_qp_mw()
648 qp->rx_index = 0; in ntb_transport_setup_qp_mw()
656 for (i = qp->rx_alloc_entry; i < qp->rx_max_entry; i++) { in ntb_transport_setup_qp_mw()
661 entry->qp = qp; in ntb_transport_setup_qp_mw()
662 ntb_list_add(&qp->ntb_rx_q_lock, &entry->entry, in ntb_transport_setup_qp_mw()
663 &qp->rx_free_q); in ntb_transport_setup_qp_mw()
664 qp->rx_alloc_entry++; in ntb_transport_setup_qp_mw()
667 qp->remote_rx_info->entry = qp->rx_max_entry - 1; in ntb_transport_setup_qp_mw()
670 for (i = 0; i < qp->rx_max_entry; i++) { in ntb_transport_setup_qp_mw()
671 void *offset = (qp->rx_buff + qp->rx_max_frame * (i + 1) - in ntb_transport_setup_qp_mw()
676 qp->rx_pkts = 0; in ntb_transport_setup_qp_mw()
677 qp->tx_pkts = 0; in ntb_transport_setup_qp_mw()
678 qp->tx_index = 0; in ntb_transport_setup_qp_mw()
685 struct ntb_transport_qp *qp = dev; in ntb_transport_isr() local
687 tasklet_schedule(&qp->rxc_db_work); in ntb_transport_isr()
695 struct ntb_transport_qp *qp = &nt->qp_vec[qp_num]; in ntb_transport_setup_qp_peer_msi() local
704 qp->peer_msi_desc.addr_offset = in ntb_transport_setup_qp_peer_msi()
705 ntb_peer_spad_read(qp->ndev, PIDX, spad); in ntb_transport_setup_qp_peer_msi()
706 qp->peer_msi_desc.data = in ntb_transport_setup_qp_peer_msi()
707 ntb_peer_spad_read(qp->ndev, PIDX, spad + 1); in ntb_transport_setup_qp_peer_msi()
709 dev_dbg(&qp->ndev->pdev->dev, "QP%d Peer MSI addr=%x data=%x\n", in ntb_transport_setup_qp_peer_msi()
710 qp_num, qp->peer_msi_desc.addr_offset, qp->peer_msi_desc.data); in ntb_transport_setup_qp_peer_msi()
712 if (qp->peer_msi_desc.addr_offset) { in ntb_transport_setup_qp_peer_msi()
713 qp->use_msi = true; in ntb_transport_setup_qp_peer_msi()
714 dev_info(&qp->ndev->pdev->dev, in ntb_transport_setup_qp_peer_msi()
715 "Using MSI interrupts for QP%d\n", qp_num); in ntb_transport_setup_qp_peer_msi()
722 struct ntb_transport_qp *qp = &nt->qp_vec[qp_num]; in ntb_transport_setup_qp_msi() local
730 dev_warn_once(&qp->ndev->pdev->dev, in ntb_transport_setup_qp_msi()
735 ntb_spad_write(qp->ndev, spad, 0); in ntb_transport_setup_qp_msi()
736 ntb_spad_write(qp->ndev, spad + 1, 0); in ntb_transport_setup_qp_msi()
738 if (!qp->msi_irq) { in ntb_transport_setup_qp_msi()
739 qp->msi_irq = ntbm_msi_request_irq(qp->ndev, ntb_transport_isr, in ntb_transport_setup_qp_msi()
740 KBUILD_MODNAME, qp, in ntb_transport_setup_qp_msi()
741 &qp->msi_desc); in ntb_transport_setup_qp_msi()
742 if (qp->msi_irq < 0) { in ntb_transport_setup_qp_msi()
743 dev_warn(&qp->ndev->pdev->dev, in ntb_transport_setup_qp_msi()
744 "Unable to allocate MSI interrupt for qp%d\n", in ntb_transport_setup_qp_msi()
750 rc = ntb_spad_write(qp->ndev, spad, qp->msi_desc.addr_offset); in ntb_transport_setup_qp_msi()
754 rc = ntb_spad_write(qp->ndev, spad + 1, qp->msi_desc.data); in ntb_transport_setup_qp_msi()
758 dev_dbg(&qp->ndev->pdev->dev, "QP%d MSI %d addr=%x data=%x\n", in ntb_transport_setup_qp_msi()
759 qp_num, qp->msi_irq, qp->msi_desc.addr_offset, in ntb_transport_setup_qp_msi()
760 qp->msi_desc.data); in ntb_transport_setup_qp_msi()
765 devm_free_irq(&nt->ndev->dev, qp->msi_irq, qp); in ntb_transport_setup_qp_msi()
912 static void ntb_qp_link_context_reset(struct ntb_transport_qp *qp) in ntb_qp_link_context_reset() argument
914 qp->link_is_up = false; in ntb_qp_link_context_reset()
915 qp->active = false; in ntb_qp_link_context_reset()
917 qp->tx_index = 0; in ntb_qp_link_context_reset()
918 qp->rx_index = 0; in ntb_qp_link_context_reset()
919 qp->rx_bytes = 0; in ntb_qp_link_context_reset()
920 qp->rx_pkts = 0; in ntb_qp_link_context_reset()
921 qp->rx_ring_empty = 0; in ntb_qp_link_context_reset()
922 qp->rx_err_no_buf = 0; in ntb_qp_link_context_reset()
923 qp->rx_err_oflow = 0; in ntb_qp_link_context_reset()
924 qp->rx_err_ver = 0; in ntb_qp_link_context_reset()
925 qp->rx_memcpy = 0; in ntb_qp_link_context_reset()
926 qp->rx_async = 0; in ntb_qp_link_context_reset()
927 qp->tx_bytes = 0; in ntb_qp_link_context_reset()
928 qp->tx_pkts = 0; in ntb_qp_link_context_reset()
929 qp->tx_ring_full = 0; in ntb_qp_link_context_reset()
930 qp->tx_err_no_buf = 0; in ntb_qp_link_context_reset()
931 qp->tx_memcpy = 0; in ntb_qp_link_context_reset()
932 qp->tx_async = 0; in ntb_qp_link_context_reset()
935 static void ntb_qp_link_down_reset(struct ntb_transport_qp *qp) in ntb_qp_link_down_reset() argument
937 ntb_qp_link_context_reset(qp); in ntb_qp_link_down_reset()
938 if (qp->remote_rx_info) in ntb_qp_link_down_reset()
939 qp->remote_rx_info->entry = qp->rx_max_entry - 1; in ntb_qp_link_down_reset()
942 static void ntb_qp_link_cleanup(struct ntb_transport_qp *qp) in ntb_qp_link_cleanup() argument
944 struct ntb_transport_ctx *nt = qp->transport; in ntb_qp_link_cleanup()
947 dev_info(&pdev->dev, "qp %d: Link Cleanup\n", qp->qp_num); in ntb_qp_link_cleanup()
949 cancel_delayed_work_sync(&qp->link_work); in ntb_qp_link_cleanup()
950 ntb_qp_link_down_reset(qp); in ntb_qp_link_cleanup()
952 if (qp->event_handler) in ntb_qp_link_cleanup()
953 qp->event_handler(qp->cb_data, qp->link_is_up); in ntb_qp_link_cleanup()
958 struct ntb_transport_qp *qp = container_of(work, in ntb_qp_link_cleanup_work() local
961 struct ntb_transport_ctx *nt = qp->transport; in ntb_qp_link_cleanup_work()
963 ntb_qp_link_cleanup(qp); in ntb_qp_link_cleanup_work()
966 schedule_delayed_work(&qp->link_work, in ntb_qp_link_cleanup_work()
970 static void ntb_qp_link_down(struct ntb_transport_qp *qp) in ntb_qp_link_down() argument
972 schedule_work(&qp->link_cleanup); in ntb_qp_link_down()
977 struct ntb_transport_qp *qp; in ntb_transport_link_cleanup() local
986 qp = &nt->qp_vec[i]; in ntb_transport_link_cleanup()
987 ntb_qp_link_cleanup(qp); in ntb_transport_link_cleanup()
988 cancel_work_sync(&qp->link_cleanup); in ntb_transport_link_cleanup()
989 cancel_delayed_work_sync(&qp->link_work); in ntb_transport_link_cleanup()
1104 struct ntb_transport_qp *qp = &nt->qp_vec[i]; in ntb_transport_link_work() local
1109 if (qp->client_ready) in ntb_transport_link_work()
1110 schedule_delayed_work(&qp->link_work, 0); in ntb_transport_link_work()
1131 struct ntb_transport_qp *qp = container_of(work, in ntb_qp_link_work() local
1134 struct pci_dev *pdev = qp->ndev->pdev; in ntb_qp_link_work()
1135 struct ntb_transport_ctx *nt = qp->transport; in ntb_qp_link_work()
1142 ntb_peer_spad_write(nt->ndev, PIDX, QP_LINKS, val | BIT(qp->qp_num)); in ntb_qp_link_work()
1144 /* query remote spad for qp ready bits */ in ntb_qp_link_work()
1145 dev_dbg_ratelimited(&pdev->dev, "Remote QP link status = %x\n", val); in ntb_qp_link_work()
1148 if (val & BIT(qp->qp_num)) { in ntb_qp_link_work()
1149 dev_info(&pdev->dev, "qp %d: Link Up\n", qp->qp_num); in ntb_qp_link_work()
1150 qp->link_is_up = true; in ntb_qp_link_work()
1151 qp->active = true; in ntb_qp_link_work()
1153 if (qp->event_handler) in ntb_qp_link_work()
1154 qp->event_handler(qp->cb_data, qp->link_is_up); in ntb_qp_link_work()
1156 if (qp->active) in ntb_qp_link_work()
1157 tasklet_schedule(&qp->rxc_db_work); in ntb_qp_link_work()
1159 schedule_delayed_work(&qp->link_work, in ntb_qp_link_work()
1166 struct ntb_transport_qp *qp; in ntb_transport_init_queue() local
1178 qp = &nt->qp_vec[qp_num]; in ntb_transport_init_queue()
1179 qp->qp_num = qp_num; in ntb_transport_init_queue()
1180 qp->transport = nt; in ntb_transport_init_queue()
1181 qp->ndev = nt->ndev; in ntb_transport_init_queue()
1182 qp->client_ready = false; in ntb_transport_init_queue()
1183 qp->event_handler = NULL; in ntb_transport_init_queue()
1184 ntb_qp_link_context_reset(qp); in ntb_transport_init_queue()
1200 qp->tx_mw_size = tx_size; in ntb_transport_init_queue()
1201 qp->tx_mw = nt->mw_vec[mw_num].vbase + qp_offset; in ntb_transport_init_queue()
1202 if (!qp->tx_mw) in ntb_transport_init_queue()
1205 qp->tx_mw_phys = mw_base + qp_offset; in ntb_transport_init_queue()
1206 if (!qp->tx_mw_phys) in ntb_transport_init_queue()
1210 qp->rx_info = qp->tx_mw + tx_size; in ntb_transport_init_queue()
1213 qp->tx_max_frame = min(transport_mtu, tx_size / 2); in ntb_transport_init_queue()
1214 qp->tx_max_entry = tx_size / qp->tx_max_frame; in ntb_transport_init_queue()
1219 snprintf(debugfs_name, 4, "qp%d", qp_num); in ntb_transport_init_queue()
1220 qp->debugfs_dir = debugfs_create_dir(debugfs_name, in ntb_transport_init_queue()
1223 qp->debugfs_stats = debugfs_create_file("stats", S_IRUSR, in ntb_transport_init_queue()
1224 qp->debugfs_dir, qp, in ntb_transport_init_queue()
1227 qp->debugfs_dir = NULL; in ntb_transport_init_queue()
1228 qp->debugfs_stats = NULL; in ntb_transport_init_queue()
1231 INIT_DELAYED_WORK(&qp->link_work, ntb_qp_link_work); in ntb_transport_init_queue()
1232 INIT_WORK(&qp->link_cleanup, ntb_qp_link_cleanup_work); in ntb_transport_init_queue()
1234 spin_lock_init(&qp->ntb_rx_q_lock); in ntb_transport_init_queue()
1235 spin_lock_init(&qp->ntb_tx_free_q_lock); in ntb_transport_init_queue()
1237 INIT_LIST_HEAD(&qp->rx_post_q); in ntb_transport_init_queue()
1238 INIT_LIST_HEAD(&qp->rx_pend_q); in ntb_transport_init_queue()
1239 INIT_LIST_HEAD(&qp->rx_free_q); in ntb_transport_init_queue()
1240 INIT_LIST_HEAD(&qp->tx_free_q); in ntb_transport_init_queue()
1242 tasklet_init(&qp->rxc_db_work, ntb_transport_rxc_db, in ntb_transport_init_queue()
1243 (unsigned long)qp); in ntb_transport_init_queue()
1411 struct ntb_transport_qp *qp; in ntb_transport_free() local
1421 /* verify that all the qp's are freed */ in ntb_transport_free()
1423 qp = &nt->qp_vec[i]; in ntb_transport_free()
1425 ntb_transport_free_queue(qp); in ntb_transport_free()
1426 debugfs_remove_recursive(qp->debugfs_dir); in ntb_transport_free()
1444 static void ntb_complete_rxc(struct ntb_transport_qp *qp) in ntb_complete_rxc() argument
1451 spin_lock_irqsave(&qp->ntb_rx_q_lock, irqflags); in ntb_complete_rxc()
1453 while (!list_empty(&qp->rx_post_q)) { in ntb_complete_rxc()
1454 entry = list_first_entry(&qp->rx_post_q, in ntb_complete_rxc()
1460 iowrite32(entry->rx_index, &qp->rx_info->entry); in ntb_complete_rxc()
1465 list_move_tail(&entry->entry, &qp->rx_free_q); in ntb_complete_rxc()
1467 spin_unlock_irqrestore(&qp->ntb_rx_q_lock, irqflags); in ntb_complete_rxc()
1469 if (qp->rx_handler && qp->client_ready) in ntb_complete_rxc()
1470 qp->rx_handler(qp, qp->cb_data, cb_data, len); in ntb_complete_rxc()
1472 spin_lock_irqsave(&qp->ntb_rx_q_lock, irqflags); in ntb_complete_rxc()
1475 spin_unlock_irqrestore(&qp->ntb_rx_q_lock, irqflags); in ntb_complete_rxc()
1494 struct ntb_transport_qp *qp = entry->qp; in ntb_rx_copy_callback() local
1495 void *offset = qp->rx_buff + qp->rx_max_frame * in ntb_rx_copy_callback()
1496 qp->rx_index; in ntb_rx_copy_callback()
1499 qp->rx_memcpy++; in ntb_rx_copy_callback()
1511 ntb_complete_rxc(entry->qp); in ntb_rx_copy_callback()
1530 struct ntb_transport_qp *qp = entry->qp; in ntb_async_rx_submit() local
1531 struct dma_chan *chan = qp->rx_dma_chan; in ntb_async_rx_submit()
1581 qp->last_cookie = cookie; in ntb_async_rx_submit()
1583 qp->rx_async++; in ntb_async_rx_submit()
1597 struct ntb_transport_qp *qp = entry->qp; in ntb_async_rx() local
1598 struct dma_chan *chan = qp->rx_dma_chan; in ntb_async_rx()
1612 qp->rx_async++; in ntb_async_rx()
1618 qp->rx_memcpy++; in ntb_async_rx()
1621 static int ntb_process_rxc(struct ntb_transport_qp *qp) in ntb_process_rxc() argument
1627 offset = qp->rx_buff + qp->rx_max_frame * qp->rx_index; in ntb_process_rxc()
1628 hdr = offset + qp->rx_max_frame - sizeof(struct ntb_payload_header); in ntb_process_rxc()
1630 dev_dbg(&qp->ndev->pdev->dev, "qp %d: RX ver %u len %d flags %x\n", in ntb_process_rxc()
1631 qp->qp_num, hdr->ver, hdr->len, hdr->flags); in ntb_process_rxc()
1634 dev_dbg(&qp->ndev->pdev->dev, "done flag not set\n"); in ntb_process_rxc()
1635 qp->rx_ring_empty++; in ntb_process_rxc()
1640 dev_dbg(&qp->ndev->pdev->dev, "link down flag set\n"); in ntb_process_rxc()
1641 ntb_qp_link_down(qp); in ntb_process_rxc()
1646 if (hdr->ver != (u32)qp->rx_pkts) { in ntb_process_rxc()
1647 dev_dbg(&qp->ndev->pdev->dev, in ntb_process_rxc()
1649 qp->rx_pkts, hdr->ver); in ntb_process_rxc()
1650 qp->rx_err_ver++; in ntb_process_rxc()
1654 entry = ntb_list_mv(&qp->ntb_rx_q_lock, &qp->rx_pend_q, &qp->rx_post_q); in ntb_process_rxc()
1656 dev_dbg(&qp->ndev->pdev->dev, "no receive buffer\n"); in ntb_process_rxc()
1657 qp->rx_err_no_buf++; in ntb_process_rxc()
1662 entry->rx_index = qp->rx_index; in ntb_process_rxc()
1665 dev_dbg(&qp->ndev->pdev->dev, in ntb_process_rxc()
1668 qp->rx_err_oflow++; in ntb_process_rxc()
1673 ntb_complete_rxc(qp); in ntb_process_rxc()
1675 dev_dbg(&qp->ndev->pdev->dev, in ntb_process_rxc()
1677 qp->rx_index, hdr->ver, hdr->len, entry->len); in ntb_process_rxc()
1679 qp->rx_bytes += hdr->len; in ntb_process_rxc()
1680 qp->rx_pkts++; in ntb_process_rxc()
1687 qp->rx_index++; in ntb_process_rxc()
1688 qp->rx_index %= qp->rx_max_entry; in ntb_process_rxc()
1695 struct ntb_transport_qp *qp = (void *)data; in ntb_transport_rxc_db() local
1698 dev_dbg(&qp->ndev->pdev->dev, "%s: doorbell %d received\n", in ntb_transport_rxc_db()
1699 __func__, qp->qp_num); in ntb_transport_rxc_db()
1704 for (i = 0; i < qp->rx_max_entry; i++) { in ntb_transport_rxc_db()
1705 rc = ntb_process_rxc(qp); in ntb_transport_rxc_db()
1710 if (i && qp->rx_dma_chan) in ntb_transport_rxc_db()
1711 dma_async_issue_pending(qp->rx_dma_chan); in ntb_transport_rxc_db()
1713 if (i == qp->rx_max_entry) { in ntb_transport_rxc_db()
1715 if (qp->active) in ntb_transport_rxc_db()
1716 tasklet_schedule(&qp->rxc_db_work); in ntb_transport_rxc_db()
1717 } else if (ntb_db_read(qp->ndev) & BIT_ULL(qp->qp_num)) { in ntb_transport_rxc_db()
1719 ntb_db_clear(qp->ndev, BIT_ULL(qp->qp_num)); in ntb_transport_rxc_db()
1721 ntb_db_read(qp->ndev); in ntb_transport_rxc_db()
1727 if (qp->active) in ntb_transport_rxc_db()
1728 tasklet_schedule(&qp->rxc_db_work); in ntb_transport_rxc_db()
1736 struct ntb_transport_qp *qp = entry->qp; in ntb_tx_copy_callback() local
1751 qp->tx_mw + qp->tx_max_frame * in ntb_tx_copy_callback()
1756 qp->tx_memcpy++; in ntb_tx_copy_callback()
1768 if (qp->use_msi) in ntb_tx_copy_callback()
1769 ntb_msi_peer_trigger(qp->ndev, PIDX, &qp->peer_msi_desc); in ntb_tx_copy_callback()
1771 ntb_peer_db_set(qp->ndev, BIT_ULL(qp->qp_num)); in ntb_tx_copy_callback()
1778 qp->tx_bytes += entry->len; in ntb_tx_copy_callback()
1780 if (qp->tx_handler) in ntb_tx_copy_callback()
1781 qp->tx_handler(qp, qp->cb_data, entry->cb_data, in ntb_tx_copy_callback()
1785 ntb_list_add(&qp->ntb_tx_free_q_lock, &entry->entry, &qp->tx_free_q); in ntb_tx_copy_callback()
1806 static int ntb_async_tx_submit(struct ntb_transport_qp *qp, in ntb_async_tx_submit() argument
1810 struct dma_chan *chan = qp->tx_dma_chan; in ntb_async_tx_submit()
1820 dest = qp->tx_mw_dma_addr + qp->tx_max_frame * entry->tx_index; in ntb_async_tx_submit()
1865 static void ntb_async_tx(struct ntb_transport_qp *qp, in ntb_async_tx() argument
1869 struct dma_chan *chan = qp->tx_dma_chan; in ntb_async_tx()
1873 entry->tx_index = qp->tx_index; in ntb_async_tx()
1874 offset = qp->tx_mw + qp->tx_max_frame * entry->tx_index; in ntb_async_tx()
1875 hdr = offset + qp->tx_max_frame - sizeof(struct ntb_payload_header); in ntb_async_tx()
1879 iowrite32((u32)qp->tx_pkts, &hdr->ver); in ntb_async_tx()
1887 res = ntb_async_tx_submit(qp, entry); in ntb_async_tx()
1892 qp->tx_async++; in ntb_async_tx()
1898 qp->tx_memcpy++; in ntb_async_tx()
1901 static int ntb_process_tx(struct ntb_transport_qp *qp, in ntb_process_tx() argument
1904 if (!ntb_transport_tx_free_entry(qp)) { in ntb_process_tx()
1905 qp->tx_ring_full++; in ntb_process_tx()
1909 if (entry->len > qp->tx_max_frame - sizeof(struct ntb_payload_header)) { in ntb_process_tx()
1910 if (qp->tx_handler) in ntb_process_tx()
1911 qp->tx_handler(qp, qp->cb_data, NULL, -EIO); in ntb_process_tx()
1913 ntb_list_add(&qp->ntb_tx_free_q_lock, &entry->entry, in ntb_process_tx()
1914 &qp->tx_free_q); in ntb_process_tx()
1918 ntb_async_tx(qp, entry); in ntb_process_tx()
1920 qp->tx_index++; in ntb_process_tx()
1921 qp->tx_index %= qp->tx_max_entry; in ntb_process_tx()
1923 qp->tx_pkts++; in ntb_process_tx()
1928 static void ntb_send_link_down(struct ntb_transport_qp *qp) in ntb_send_link_down() argument
1930 struct pci_dev *pdev = qp->ndev->pdev; in ntb_send_link_down()
1934 if (!qp->link_is_up) in ntb_send_link_down()
1937 dev_info(&pdev->dev, "qp %d: Send Link Down\n", qp->qp_num); in ntb_send_link_down()
1940 entry = ntb_list_rm(&qp->ntb_tx_free_q_lock, &qp->tx_free_q); in ntb_send_link_down()
1954 rc = ntb_process_tx(qp, entry); in ntb_send_link_down()
1956 dev_err(&pdev->dev, "ntb: QP%d unable to send linkdown msg\n", in ntb_send_link_down()
1957 qp->qp_num); in ntb_send_link_down()
1959 ntb_qp_link_down_reset(qp); in ntb_send_link_down()
1989 struct ntb_transport_qp *qp; in ntb_transport_create_queue() local
2009 qp = &nt->qp_vec[free_queue]; in ntb_transport_create_queue()
2010 qp_bit = BIT_ULL(qp->qp_num); in ntb_transport_create_queue()
2014 qp->cb_data = data; in ntb_transport_create_queue()
2015 qp->rx_handler = handlers->rx_handler; in ntb_transport_create_queue()
2016 qp->tx_handler = handlers->tx_handler; in ntb_transport_create_queue()
2017 qp->event_handler = handlers->event_handler; in ntb_transport_create_queue()
2023 qp->tx_dma_chan = in ntb_transport_create_queue()
2026 if (!qp->tx_dma_chan) in ntb_transport_create_queue()
2029 qp->rx_dma_chan = in ntb_transport_create_queue()
2032 if (!qp->rx_dma_chan) in ntb_transport_create_queue()
2035 qp->tx_dma_chan = NULL; in ntb_transport_create_queue()
2036 qp->rx_dma_chan = NULL; in ntb_transport_create_queue()
2039 qp->tx_mw_dma_addr = 0; in ntb_transport_create_queue()
2040 if (qp->tx_dma_chan) { in ntb_transport_create_queue()
2041 qp->tx_mw_dma_addr = in ntb_transport_create_queue()
2042 dma_map_resource(qp->tx_dma_chan->device->dev, in ntb_transport_create_queue()
2043 qp->tx_mw_phys, qp->tx_mw_size, in ntb_transport_create_queue()
2045 if (dma_mapping_error(qp->tx_dma_chan->device->dev, in ntb_transport_create_queue()
2046 qp->tx_mw_dma_addr)) { in ntb_transport_create_queue()
2047 qp->tx_mw_dma_addr = 0; in ntb_transport_create_queue()
2053 qp->tx_dma_chan ? "DMA" : "CPU"); in ntb_transport_create_queue()
2056 qp->rx_dma_chan ? "DMA" : "CPU"); in ntb_transport_create_queue()
2063 entry->qp = qp; in ntb_transport_create_queue()
2064 ntb_list_add(&qp->ntb_rx_q_lock, &entry->entry, in ntb_transport_create_queue()
2065 &qp->rx_free_q); in ntb_transport_create_queue()
2067 qp->rx_alloc_entry = NTB_QP_DEF_NUM_ENTRIES; in ntb_transport_create_queue()
2069 for (i = 0; i < qp->tx_max_entry; i++) { in ntb_transport_create_queue()
2074 entry->qp = qp; in ntb_transport_create_queue()
2075 ntb_list_add(&qp->ntb_tx_free_q_lock, &entry->entry, in ntb_transport_create_queue()
2076 &qp->tx_free_q); in ntb_transport_create_queue()
2079 ntb_db_clear(qp->ndev, qp_bit); in ntb_transport_create_queue()
2080 ntb_db_clear_mask(qp->ndev, qp_bit); in ntb_transport_create_queue()
2082 dev_info(&pdev->dev, "NTB Transport QP %d created\n", qp->qp_num); in ntb_transport_create_queue()
2084 return qp; in ntb_transport_create_queue()
2087 while ((entry = ntb_list_rm(&qp->ntb_tx_free_q_lock, &qp->tx_free_q))) in ntb_transport_create_queue()
2090 qp->rx_alloc_entry = 0; in ntb_transport_create_queue()
2091 while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_free_q))) in ntb_transport_create_queue()
2093 if (qp->tx_mw_dma_addr) in ntb_transport_create_queue()
2094 dma_unmap_resource(qp->tx_dma_chan->device->dev, in ntb_transport_create_queue()
2095 qp->tx_mw_dma_addr, qp->tx_mw_size, in ntb_transport_create_queue()
2097 if (qp->tx_dma_chan) in ntb_transport_create_queue()
2098 dma_release_channel(qp->tx_dma_chan); in ntb_transport_create_queue()
2099 if (qp->rx_dma_chan) in ntb_transport_create_queue()
2100 dma_release_channel(qp->rx_dma_chan); in ntb_transport_create_queue()
2109 * @qp: NTB queue to be freed
2113 void ntb_transport_free_queue(struct ntb_transport_qp *qp) in ntb_transport_free_queue() argument
2119 if (!qp) in ntb_transport_free_queue()
2122 pdev = qp->ndev->pdev; in ntb_transport_free_queue()
2124 qp->active = false; in ntb_transport_free_queue()
2126 if (qp->tx_dma_chan) { in ntb_transport_free_queue()
2127 struct dma_chan *chan = qp->tx_dma_chan; in ntb_transport_free_queue()
2131 qp->tx_dma_chan = NULL; in ntb_transport_free_queue()
2136 dma_sync_wait(chan, qp->last_cookie); in ntb_transport_free_queue()
2140 qp->tx_mw_dma_addr, qp->tx_mw_size, in ntb_transport_free_queue()
2146 if (qp->rx_dma_chan) { in ntb_transport_free_queue()
2147 struct dma_chan *chan = qp->rx_dma_chan; in ntb_transport_free_queue()
2151 qp->rx_dma_chan = NULL; in ntb_transport_free_queue()
2156 dma_sync_wait(chan, qp->last_cookie); in ntb_transport_free_queue()
2161 qp_bit = BIT_ULL(qp->qp_num); in ntb_transport_free_queue()
2163 ntb_db_set_mask(qp->ndev, qp_bit); in ntb_transport_free_queue()
2164 tasklet_kill(&qp->rxc_db_work); in ntb_transport_free_queue()
2166 cancel_delayed_work_sync(&qp->link_work); in ntb_transport_free_queue()
2168 qp->cb_data = NULL; in ntb_transport_free_queue()
2169 qp->rx_handler = NULL; in ntb_transport_free_queue()
2170 qp->tx_handler = NULL; in ntb_transport_free_queue()
2171 qp->event_handler = NULL; in ntb_transport_free_queue()
2173 while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_free_q))) in ntb_transport_free_queue()
2176 while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_pend_q))) { in ntb_transport_free_queue()
2181 while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_post_q))) { in ntb_transport_free_queue()
2186 while ((entry = ntb_list_rm(&qp->ntb_tx_free_q_lock, &qp->tx_free_q))) in ntb_transport_free_queue()
2189 qp->transport->qp_bitmap_free |= qp_bit; in ntb_transport_free_queue()
2191 dev_info(&pdev->dev, "NTB Transport QP %d freed\n", qp->qp_num); in ntb_transport_free_queue()
2197 * @qp: NTB queue to be freed
2201 * shutdown of qp.
2205 void *ntb_transport_rx_remove(struct ntb_transport_qp *qp, unsigned int *len) in ntb_transport_rx_remove() argument
2210 if (!qp || qp->client_ready) in ntb_transport_rx_remove()
2213 entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_pend_q); in ntb_transport_rx_remove()
2220 ntb_list_add(&qp->ntb_rx_q_lock, &entry->entry, &qp->rx_free_q); in ntb_transport_rx_remove()
2228 * @qp: NTB transport layer queue the entry is to be enqueued on
2238 int ntb_transport_rx_enqueue(struct ntb_transport_qp *qp, void *cb, void *data, in ntb_transport_rx_enqueue() argument
2243 if (!qp) in ntb_transport_rx_enqueue()
2246 entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_free_q); in ntb_transport_rx_enqueue()
2258 ntb_list_add(&qp->ntb_rx_q_lock, &entry->entry, &qp->rx_pend_q); in ntb_transport_rx_enqueue()
2260 if (qp->active) in ntb_transport_rx_enqueue()
2261 tasklet_schedule(&qp->rxc_db_work); in ntb_transport_rx_enqueue()
2269 * @qp: NTB transport layer queue the entry is to be enqueued on
2276 * serialize access to the qp.
2280 int ntb_transport_tx_enqueue(struct ntb_transport_qp *qp, void *cb, void *data, in ntb_transport_tx_enqueue() argument
2286 if (!qp || !len) in ntb_transport_tx_enqueue()
2289 /* If the qp link is down already, just ignore. */ in ntb_transport_tx_enqueue()
2290 if (!qp->link_is_up) in ntb_transport_tx_enqueue()
2293 entry = ntb_list_rm(&qp->ntb_tx_free_q_lock, &qp->tx_free_q); in ntb_transport_tx_enqueue()
2295 qp->tx_err_no_buf++; in ntb_transport_tx_enqueue()
2307 rc = ntb_process_tx(qp, entry); in ntb_transport_tx_enqueue()
2309 ntb_list_add(&qp->ntb_tx_free_q_lock, &entry->entry, in ntb_transport_tx_enqueue()
2310 &qp->tx_free_q); in ntb_transport_tx_enqueue()
2318 * @qp: NTB transport layer queue to be enabled
2322 void ntb_transport_link_up(struct ntb_transport_qp *qp) in ntb_transport_link_up() argument
2324 if (!qp) in ntb_transport_link_up()
2327 qp->client_ready = true; in ntb_transport_link_up()
2329 if (qp->transport->link_is_up) in ntb_transport_link_up()
2330 schedule_delayed_work(&qp->link_work, 0); in ntb_transport_link_up()
2336 * @qp: NTB transport layer queue to be disabled
2342 void ntb_transport_link_down(struct ntb_transport_qp *qp) in ntb_transport_link_down() argument
2346 if (!qp) in ntb_transport_link_down()
2349 qp->client_ready = false; in ntb_transport_link_down()
2351 val = ntb_spad_read(qp->ndev, QP_LINKS); in ntb_transport_link_down()
2353 ntb_peer_spad_write(qp->ndev, PIDX, QP_LINKS, val & ~BIT(qp->qp_num)); in ntb_transport_link_down()
2355 if (qp->link_is_up) in ntb_transport_link_down()
2356 ntb_send_link_down(qp); in ntb_transport_link_down()
2358 cancel_delayed_work_sync(&qp->link_work); in ntb_transport_link_down()
2364 * @qp: NTB transport layer queue to be queried
2370 bool ntb_transport_link_query(struct ntb_transport_qp *qp) in ntb_transport_link_query() argument
2372 if (!qp) in ntb_transport_link_query()
2375 return qp->link_is_up; in ntb_transport_link_query()
2380 * ntb_transport_qp_num - Query the qp number
2381 * @qp: NTB transport layer queue to be queried
2383 * Query qp number of the NTB transport queue
2385 * RETURNS: a zero based number specifying the qp number
2387 unsigned char ntb_transport_qp_num(struct ntb_transport_qp *qp) in ntb_transport_qp_num() argument
2389 if (!qp) in ntb_transport_qp_num()
2392 return qp->qp_num; in ntb_transport_qp_num()
2397 * ntb_transport_max_size - Query the max payload size of a qp
2398 * @qp: NTB transport layer queue to be queried
2400 * Query the maximum payload size permissible on the given qp
2402 * RETURNS: the max payload size of a qp
2404 unsigned int ntb_transport_max_size(struct ntb_transport_qp *qp) in ntb_transport_max_size() argument
2410 if (!qp) in ntb_transport_max_size()
2413 rx_chan = qp->rx_dma_chan; in ntb_transport_max_size()
2414 tx_chan = qp->tx_dma_chan; in ntb_transport_max_size()
2420 max_size = qp->tx_max_frame - sizeof(struct ntb_payload_header); in ntb_transport_max_size()
2427 unsigned int ntb_transport_tx_free_entry(struct ntb_transport_qp *qp) in ntb_transport_tx_free_entry() argument
2429 unsigned int head = qp->tx_index; in ntb_transport_tx_free_entry()
2430 unsigned int tail = qp->remote_rx_info->entry; in ntb_transport_tx_free_entry()
2432 return tail >= head ? tail - head : qp->tx_max_entry + tail - head; in ntb_transport_tx_free_entry()
2439 struct ntb_transport_qp *qp; in ntb_transport_doorbell_callback() local
2453 qp = &nt->qp_vec[qp_num]; in ntb_transport_doorbell_callback()
2455 if (qp->active) in ntb_transport_doorbell_callback()
2456 tasklet_schedule(&qp->rxc_db_work); in ntb_transport_doorbell_callback()