aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLogan Gunthorpe <logang@deltatee.com>2019-01-18 19:10:01 -0500
committerJon Mason <jdmason@kudzu.us>2019-02-11 09:26:30 -0500
commitc59666bb32b91da84b1d3df0e88789de9e827f61 (patch)
tree1899a86e550686291f178fca9ebccafbc70d99c5
parent9143595a7e05a848384c240d34abcc4740a65897 (diff)
NTB: ntb_transport: Ensure the destination buffer is mapped for TX DMA
Presently, when ntb_transport is used with DMA and the IOMMU turned on, it fails with errors from the IOMMU such as: DMAR: DRHD: handling fault status reg 202 DMAR: [DMA Write] Request device [00:04.0] fault addr 381fc0340000 [fault reason 05] PTE Write access is not set This is because ntb_transport does not map the BAR space with the IOMMU. To fix this, we map the entire MW region for each QP after we assign the DMA channel. This prevents needing an extra DMA map in the fast path. Link: https://lore.kernel.org/linux-pci/499934e7-3734-1aee-37dd-b42a5d2a2608@intel.com/ Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
-rw-r--r--drivers/ntb/ntb_transport.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 6e8902d03a69..d4f39ba1d976 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -144,7 +144,9 @@ struct ntb_transport_qp {
144 struct list_head tx_free_q; 144 struct list_head tx_free_q;
145 spinlock_t ntb_tx_free_q_lock; 145 spinlock_t ntb_tx_free_q_lock;
146 void __iomem *tx_mw; 146 void __iomem *tx_mw;
147 dma_addr_t tx_mw_phys; 147 phys_addr_t tx_mw_phys;
148 size_t tx_mw_size;
149 dma_addr_t tx_mw_dma_addr;
148 unsigned int tx_index; 150 unsigned int tx_index;
149 unsigned int tx_max_entry; 151 unsigned int tx_max_entry;
150 unsigned int tx_max_frame; 152 unsigned int tx_max_frame;
@@ -1052,6 +1054,7 @@ static int ntb_transport_init_queue(struct ntb_transport_ctx *nt,
1052 tx_size = (unsigned int)mw_size / num_qps_mw; 1054 tx_size = (unsigned int)mw_size / num_qps_mw;
1053 qp_offset = tx_size * (qp_num / mw_count); 1055 qp_offset = tx_size * (qp_num / mw_count);
1054 1056
1057 qp->tx_mw_size = tx_size;
1055 qp->tx_mw = nt->mw_vec[mw_num].vbase + qp_offset; 1058 qp->tx_mw = nt->mw_vec[mw_num].vbase + qp_offset;
1056 if (!qp->tx_mw) 1059 if (!qp->tx_mw)
1057 return -EINVAL; 1060 return -EINVAL;
@@ -1647,7 +1650,7 @@ static int ntb_async_tx_submit(struct ntb_transport_qp *qp,
1647 dma_cookie_t cookie; 1650 dma_cookie_t cookie;
1648 1651
1649 device = chan->device; 1652 device = chan->device;
1650 dest = qp->tx_mw_phys + qp->tx_max_frame * entry->tx_index; 1653 dest = qp->tx_mw_dma_addr + qp->tx_max_frame * entry->tx_index;
1651 buff_off = (size_t)buf & ~PAGE_MASK; 1654 buff_off = (size_t)buf & ~PAGE_MASK;
1652 dest_off = (size_t)dest & ~PAGE_MASK; 1655 dest_off = (size_t)dest & ~PAGE_MASK;
1653 1656
@@ -1866,6 +1869,18 @@ ntb_transport_create_queue(void *data, struct device *client_dev,
1866 qp->rx_dma_chan = NULL; 1869 qp->rx_dma_chan = NULL;
1867 } 1870 }
1868 1871
1872 if (qp->tx_dma_chan) {
1873 qp->tx_mw_dma_addr =
1874 dma_map_resource(qp->tx_dma_chan->device->dev,
1875 qp->tx_mw_phys, qp->tx_mw_size,
1876 DMA_FROM_DEVICE, 0);
1877 if (dma_mapping_error(qp->tx_dma_chan->device->dev,
1878 qp->tx_mw_dma_addr)) {
1879 qp->tx_mw_dma_addr = 0;
1880 goto err1;
1881 }
1882 }
1883
1869 dev_dbg(&pdev->dev, "Using %s memcpy for TX\n", 1884 dev_dbg(&pdev->dev, "Using %s memcpy for TX\n",
1870 qp->tx_dma_chan ? "DMA" : "CPU"); 1885 qp->tx_dma_chan ? "DMA" : "CPU");
1871 1886
@@ -1907,6 +1922,10 @@ err1:
1907 qp->rx_alloc_entry = 0; 1922 qp->rx_alloc_entry = 0;
1908 while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_free_q))) 1923 while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_free_q)))
1909 kfree(entry); 1924 kfree(entry);
1925 if (qp->tx_mw_dma_addr)
1926 dma_unmap_resource(qp->tx_dma_chan->device->dev,
1927 qp->tx_mw_dma_addr, qp->tx_mw_size,
1928 DMA_FROM_DEVICE, 0);
1910 if (qp->tx_dma_chan) 1929 if (qp->tx_dma_chan)
1911 dma_release_channel(qp->tx_dma_chan); 1930 dma_release_channel(qp->tx_dma_chan);
1912 if (qp->rx_dma_chan) 1931 if (qp->rx_dma_chan)
@@ -1948,6 +1967,11 @@ void ntb_transport_free_queue(struct ntb_transport_qp *qp)
1948 */ 1967 */
1949 dma_sync_wait(chan, qp->last_cookie); 1968 dma_sync_wait(chan, qp->last_cookie);
1950 dmaengine_terminate_all(chan); 1969 dmaengine_terminate_all(chan);
1970
1971 dma_unmap_resource(chan->device->dev,
1972 qp->tx_mw_dma_addr, qp->tx_mw_size,
1973 DMA_FROM_DEVICE, 0);
1974
1951 dma_release_channel(chan); 1975 dma_release_channel(chan);
1952 } 1976 }
1953 1977